Completed
Push — master ( 6ed852...137dab )
by cam
01:45
created
ecrire/inc/bandeau.php 1 patch
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  **/
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 include_spip('inc/boutons');
@@ -39,33 +39,33 @@  discard block
 block discarded – undo
39 39
  *     contexte
40 40
  **/
41 41
 function definir_barre_contexte($contexte = null) {
42
-	if (is_null($contexte)) {
43
-		$contexte = $_GET;
44
-	} elseif (is_string($contexte)) {
45
-		$contexte = unserialize($contexte);
46
-	}
47
-	if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) {
48
-		if (!function_exists('trouver_objet_exec')) {
49
-			include_spip('inc/pipelines_ecrire');
50
-		}
51
-		if ($e = trouver_objet_exec($contexte['exec'])) {
52
-			$_id = $e['id_table_objet'];
53
-			if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) {
54
-				$table = $e['table_objet_sql'];
55
-				$row = sql_fetsel('*', $table, "$_id=" . intval($id));
56
-				if (isset($row['id_rubrique'])) {
57
-					$contexte['id_rubrique'] = $row['id_rubrique'];
58
-					if (isset($row['id_secteur'])) {
59
-						$contexte['id_secteur'] = $row['id_secteur'];
60
-					}
61
-				} elseif (isset($row['id_groupe'])) {
62
-					// TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé
63
-					$contexte['id_groupe'] = $row['id_groupe'];
64
-				}
65
-			}
66
-		}
67
-	}
68
-	return $contexte;
42
+    if (is_null($contexte)) {
43
+        $contexte = $_GET;
44
+    } elseif (is_string($contexte)) {
45
+        $contexte = unserialize($contexte);
46
+    }
47
+    if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) {
48
+        if (!function_exists('trouver_objet_exec')) {
49
+            include_spip('inc/pipelines_ecrire');
50
+        }
51
+        if ($e = trouver_objet_exec($contexte['exec'])) {
52
+            $_id = $e['id_table_objet'];
53
+            if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) {
54
+                $table = $e['table_objet_sql'];
55
+                $row = sql_fetsel('*', $table, "$_id=" . intval($id));
56
+                if (isset($row['id_rubrique'])) {
57
+                    $contexte['id_rubrique'] = $row['id_rubrique'];
58
+                    if (isset($row['id_secteur'])) {
59
+                        $contexte['id_secteur'] = $row['id_secteur'];
60
+                    }
61
+                } elseif (isset($row['id_groupe'])) {
62
+                    // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé
63
+                    $contexte['id_groupe'] = $row['id_groupe'];
64
+                }
65
+            }
66
+        }
67
+    }
68
+    return $contexte;
69 69
 }
70 70
 
71 71
 /**
@@ -81,89 +81,89 @@  discard block
 block discarded – undo
81 81
  * @return array
82 82
  */
83 83
 function definir_barre_boutons($contexte = [], $icones = true, $autorise = true) {
84
-	include_spip('inc/autoriser');
85
-	$boutons_admin = [];
84
+    include_spip('inc/autoriser');
85
+    $boutons_admin = [];
86 86
 
87
-	// les boutons du core, issus de ecrire/paquet.xml
88
-	$liste_boutons = [];
87
+    // les boutons du core, issus de ecrire/paquet.xml
88
+    $liste_boutons = [];
89 89
 
90
-	// ajouter les boutons issus des plugin via paquet.xml
91
-	if (
92
-		function_exists('boutons_plugins')
93
-		and is_array($liste_boutons_plugins = boutons_plugins())
94
-	) {
95
-		$liste_boutons = &$liste_boutons_plugins;
96
-	}
90
+    // ajouter les boutons issus des plugin via paquet.xml
91
+    if (
92
+        function_exists('boutons_plugins')
93
+        and is_array($liste_boutons_plugins = boutons_plugins())
94
+    ) {
95
+        $liste_boutons = &$liste_boutons_plugins;
96
+    }
97 97
 
98
-	foreach ($liste_boutons as $id => $infos) {
99
-		$parent = '';
100
-		// les boutons principaux ne sont pas soumis a autorisation
101
-		if (
102
-			!isset($infos['parent'])
103
-			or !($parent = $infos['parent'])
104
-			or !$autorise
105
-			or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte])
106
-		) {
107
-			if (
108
-				$parent
109
-				and $parent = preg_replace(',^bando_,', 'menu_', $parent)
110
-				and isset($boutons_admin[$parent])
111
-			) {
112
-				$position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu);
113
-				if ($position < 0) {
114
-					$position = count($boutons_admin[$parent]->sousmenu) + 1 + $position;
115
-				}
116
-				$boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position)
117
-					+ [
118
-						$id => new Bouton(
119
-							($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '',  // icone
120
-							$infos['titre'],  // titre
121
-							(isset($infos['action']) and $infos['action']) ? $infos['action'] : null,
122
-							(isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null
123
-						)
124
-					]
125
-					+ array_slice($boutons_admin[$parent]->sousmenu, $position, 100);
126
-			}
127
-			if (
128
-				!$parent
129
-				// provisoire, eviter les vieux boutons
130
-				and (!in_array($id, ['forum', 'statistiques_visites']))
131
-				and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte]))
132
-			) {
133
-				$position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin);
134
-				$boutons_admin = array_slice($boutons_admin, 0, $position)
135
-					+ [
136
-						$id => new Bouton(
137
-							($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
138
-							$infos['titre'],  // titre
139
-							(isset($infos['action']) and $infos['action']) ? $infos['action'] : null,
140
-							(isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null
141
-						)
142
-					]
143
-					+ array_slice($boutons_admin, $position, 100);
144
-			}
145
-		}
146
-	}
147
-	$boutons_admin = pipeline('ajouter_menus', $boutons_admin);
98
+    foreach ($liste_boutons as $id => $infos) {
99
+        $parent = '';
100
+        // les boutons principaux ne sont pas soumis a autorisation
101
+        if (
102
+            !isset($infos['parent'])
103
+            or !($parent = $infos['parent'])
104
+            or !$autorise
105
+            or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte])
106
+        ) {
107
+            if (
108
+                $parent
109
+                and $parent = preg_replace(',^bando_,', 'menu_', $parent)
110
+                and isset($boutons_admin[$parent])
111
+            ) {
112
+                $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu);
113
+                if ($position < 0) {
114
+                    $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position;
115
+                }
116
+                $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position)
117
+                    + [
118
+                        $id => new Bouton(
119
+                            ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '',  // icone
120
+                            $infos['titre'],  // titre
121
+                            (isset($infos['action']) and $infos['action']) ? $infos['action'] : null,
122
+                            (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null
123
+                        )
124
+                    ]
125
+                    + array_slice($boutons_admin[$parent]->sousmenu, $position, 100);
126
+            }
127
+            if (
128
+                !$parent
129
+                // provisoire, eviter les vieux boutons
130
+                and (!in_array($id, ['forum', 'statistiques_visites']))
131
+                and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte]))
132
+            ) {
133
+                $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin);
134
+                $boutons_admin = array_slice($boutons_admin, 0, $position)
135
+                    + [
136
+                        $id => new Bouton(
137
+                            ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
138
+                            $infos['titre'],  // titre
139
+                            (isset($infos['action']) and $infos['action']) ? $infos['action'] : null,
140
+                            (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null
141
+                        )
142
+                    ]
143
+                    + array_slice($boutons_admin, $position, 100);
144
+            }
145
+        }
146
+    }
147
+    $boutons_admin = pipeline('ajouter_menus', $boutons_admin);
148 148
 
149
-	// définir les favoris et positions d’origine
150
-	if ($boutons_admin) {
151
-		$menus_favoris = obtenir_menus_favoris();
152
-		$i = 1;
153
-		foreach ($boutons_admin as $key => $menu) {
154
-			$menu->favori = (int) table_valeur($menus_favoris, $key, false);
155
-			$menu->position = $i++;
156
-			if ($menu->sousmenu) {
157
-				$j = 1;
158
-				foreach ($menu->sousmenu as $key => $bouton) {
159
-					$bouton->favori = (int) table_valeur($menus_favoris, $key, false);
160
-					$bouton->position = $j++;
161
-				}
162
-			}
163
-		}
164
-	}
149
+    // définir les favoris et positions d’origine
150
+    if ($boutons_admin) {
151
+        $menus_favoris = obtenir_menus_favoris();
152
+        $i = 1;
153
+        foreach ($boutons_admin as $key => $menu) {
154
+            $menu->favori = (int) table_valeur($menus_favoris, $key, false);
155
+            $menu->position = $i++;
156
+            if ($menu->sousmenu) {
157
+                $j = 1;
158
+                foreach ($menu->sousmenu as $key => $bouton) {
159
+                    $bouton->favori = (int) table_valeur($menus_favoris, $key, false);
160
+                    $bouton->position = $j++;
161
+                }
162
+            }
163
+        }
164
+    }
165 165
 
166
-	return $boutons_admin;
166
+    return $boutons_admin;
167 167
 }
168 168
 
169 169
 /**
@@ -175,22 +175,22 @@  discard block
 block discarded – undo
175 175
  * @return Bouton[]
176 176
  */
177 177
 function trier_boutons_enfants_par_alpha($menus, $avec_favoris = false) {
178
-	foreach ($menus as $menu) {
179
-		if ($menu->sousmenu) {
180
-			$libelles = $isfavoris = $favoris = [];
181
-			foreach ($menu->sousmenu as $key => $item) {
182
-				$libelles[$key] = strtolower(translitteration(_T($item->libelle)));
183
-				$isfavoris[$key] = (bool) $item->favori;
184
-				$favoris[$key] = $item->favori;
185
-			}
186
-			if ($avec_favoris) {
187
-				array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu);
188
-			} else {
189
-				array_multisort($libelles, SORT_ASC, $menu->sousmenu);
190
-			}
191
-		}
192
-	}
193
-	return $menus;
178
+    foreach ($menus as $menu) {
179
+        if ($menu->sousmenu) {
180
+            $libelles = $isfavoris = $favoris = [];
181
+            foreach ($menu->sousmenu as $key => $item) {
182
+                $libelles[$key] = strtolower(translitteration(_T($item->libelle)));
183
+                $isfavoris[$key] = (bool) $item->favori;
184
+                $favoris[$key] = $item->favori;
185
+            }
186
+            if ($avec_favoris) {
187
+                array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu);
188
+            } else {
189
+                array_multisort($libelles, SORT_ASC, $menu->sousmenu);
190
+            }
191
+        }
192
+    }
193
+    return $menus;
194 194
 }
195 195
 
196 196
 /**
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
  * @return Bouton[]
202 202
  */
203 203
 function trier_boutons_enfants_par_favoris_alpha($menus) {
204
-	return trier_boutons_enfants_par_alpha($menus, true);
204
+    return trier_boutons_enfants_par_alpha($menus, true);
205 205
 }
206 206
 
207 207
 
@@ -214,23 +214,23 @@  discard block
 block discarded – undo
214 214
  * @return string
215 215
  */
216 216
 function bandeau_creer_url($url, $args = '', $contexte = null) {
217
-	if (!preg_match(',[\/\?],', $url)) {
218
-		$url = generer_url_ecrire($url, $args, true);
219
-		// recuperer les parametres du contexte demande par l'url sous la forme
220
-		// &truc=@machin@
221
-		// @machin@ etant remplace par _request('machin')
222
-		$url = str_replace('&amp;', '&', $url);
223
-		while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) {
224
-			if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) {
225
-				$contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique']));
226
-			}
227
-			$val = _request($matches[2], $contexte);
228
-			$url = parametre_url($url, $matches[1], $val ?: '', '&');
229
-		}
230
-		$url = str_replace('&', '&amp;', $url);
231
-	}
217
+    if (!preg_match(',[\/\?],', $url)) {
218
+        $url = generer_url_ecrire($url, $args, true);
219
+        // recuperer les parametres du contexte demande par l'url sous la forme
220
+        // &truc=@machin@
221
+        // @machin@ etant remplace par _request('machin')
222
+        $url = str_replace('&amp;', '&', $url);
223
+        while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) {
224
+            if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) {
225
+                $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique']));
226
+            }
227
+            $val = _request($matches[2], $contexte);
228
+            $url = parametre_url($url, $matches[1], $val ?: '', '&');
229
+        }
230
+        $url = str_replace('&', '&amp;', $url);
231
+    }
232 232
 
233
-	return $url;
233
+    return $url;
234 234
 }
235 235
 
236 236
 /**
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
  *     Code HTML du bandeau
241 241
  */
242 242
 function inc_bandeau_dist() {
243
-	return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET);
243
+    return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET);
244 244
 }
245 245
 
246 246
 
@@ -249,13 +249,13 @@  discard block
 block discarded – undo
249 249
  * @return array
250 250
  */
251 251
 function obtenir_menus_favoris() {
252
-	if (
253
-		isset($GLOBALS['visiteur_session']['prefs']['menus_favoris'])
254
-		and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris'])
255
-		and $GLOBALS['visiteur_session']['prefs']['menus_favoris']
256
-	) {
257
-		return $GLOBALS['visiteur_session']['prefs']['menus_favoris'];
258
-	}
259
-	$definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc');
260
-	return $definir_menus_favoris();
252
+    if (
253
+        isset($GLOBALS['visiteur_session']['prefs']['menus_favoris'])
254
+        and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris'])
255
+        and $GLOBALS['visiteur_session']['prefs']['menus_favoris']
256
+    ) {
257
+        return $GLOBALS['visiteur_session']['prefs']['menus_favoris'];
258
+    }
259
+    $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc');
260
+    return $definir_menus_favoris();
261 261
 }
Please login to merge, or discard this patch.
ecrire/inc/traduire.php 2 patches
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  **/
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 /**
@@ -40,20 +40,20 @@  discard block
 block discarded – undo
40 40
  *     Liste des fichiers de langue trouvés, dans l'ordre des chemins
41 41
  */
42 42
 function find_langs_in_path($file, $dirname = 'lang') {
43
-	static $dirs = [];
44
-	$liste = [];
45
-	foreach (creer_chemin() as $dir) {
46
-		if (!isset($dirs[$a = $dir . $dirname])) {
47
-			$dirs[$a] = (is_dir($a) || !$a);
48
-		}
49
-		if ($dirs[$a]) {
50
-			if (is_readable($a .= $file)) {
51
-				$liste[] = $a;
52
-			}
53
-		}
54
-	}
43
+    static $dirs = [];
44
+    $liste = [];
45
+    foreach (creer_chemin() as $dir) {
46
+        if (!isset($dirs[$a = $dir . $dirname])) {
47
+            $dirs[$a] = (is_dir($a) || !$a);
48
+        }
49
+        if ($dirs[$a]) {
50
+            if (is_readable($a .= $file)) {
51
+                $liste[] = $a;
52
+            }
53
+        }
54
+    }
55 55
 
56
-	return array_reverse($liste);
56
+    return array_reverse($liste);
57 57
 }
58 58
 
59 59
 /**
@@ -68,23 +68,23 @@  discard block
 block discarded – undo
68 68
  *     Liste des fichiers touvés pour ce module et cette langue.
69 69
  **/
70 70
 function chercher_module_lang($module, $lang = '') {
71
-	if ($lang) {
72
-		$lang = '_' . $lang;
73
-	}
71
+    if ($lang) {
72
+        $lang = '_' . $lang;
73
+    }
74 74
 
75
-	// 1) dans un repertoire nomme lang/ se trouvant sur le chemin
76
-	if (
77
-		$f = ($module == 'local'
78
-		? find_in_path($module . $lang . '.php', 'lang/')
79
-		: find_langs_in_path($module . $lang . '.php', 'lang/'))
80
-	) {
81
-		return is_array($f) ? $f : [$f];
82
-	}
75
+    // 1) dans un repertoire nomme lang/ se trouvant sur le chemin
76
+    if (
77
+        $f = ($module == 'local'
78
+        ? find_in_path($module . $lang . '.php', 'lang/')
79
+        : find_langs_in_path($module . $lang . '.php', 'lang/'))
80
+    ) {
81
+        return is_array($f) ? $f : [$f];
82
+    }
83 83
 
84
-	// 2) directement dans le chemin (old style, uniquement pour local)
85
-	return (($module == 'local') or strpos($module, '/'))
86
-		? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false)
87
-		: false;
84
+    // 2) directement dans le chemin (old style, uniquement pour local)
85
+    return (($module == 'local') or strpos($module, '/'))
86
+        ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false)
87
+        : false;
88 88
 }
89 89
 
90 90
 /**
@@ -106,33 +106,33 @@  discard block
 block discarded – undo
106 106
  * @return void
107 107
  **/
108 108
 function charger_langue($lang, $module = 'spip') {
109
-	static $langs = [];
110
-	$var = 'i18n_' . $module . '_' . $lang;
111
-	if (!isset($langs[$lang])) {
112
-		$langs[$lang] = [];
113
-		if ($lang) {
114
-			$langs[$lang][] = $lang;
115
-			if (strpos($lang, '_') !== false) {
116
-				$l = explode('_', $lang);
117
-				$langs[$lang][] = reset($l);
118
-			}
119
-		}
120
-		$langs[$lang][] = $GLOBALS['meta']['langue_site'];
121
-		$langs[$lang][] = _LANGUE_PAR_DEFAUT;
122
-	}
123
-	foreach ($langs[$lang] as $l) {
124
-		if ($fichiers_lang = chercher_module_lang($module, $l)) {
125
-			$GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l;
126
-			$GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang));
127
-			surcharger_langue($fichiers_lang);
128
-			if ($l !== $lang) {
129
-				$GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l];
130
-			}
131
-			$GLOBALS['lang_' . $var] = $l;
132
-			#spip_log("module de langue : {$module}_$l.php", 'traduire');
133
-			break;
134
-		}
135
-	}
109
+    static $langs = [];
110
+    $var = 'i18n_' . $module . '_' . $lang;
111
+    if (!isset($langs[$lang])) {
112
+        $langs[$lang] = [];
113
+        if ($lang) {
114
+            $langs[$lang][] = $lang;
115
+            if (strpos($lang, '_') !== false) {
116
+                $l = explode('_', $lang);
117
+                $langs[$lang][] = reset($l);
118
+            }
119
+        }
120
+        $langs[$lang][] = $GLOBALS['meta']['langue_site'];
121
+        $langs[$lang][] = _LANGUE_PAR_DEFAUT;
122
+    }
123
+    foreach ($langs[$lang] as $l) {
124
+        if ($fichiers_lang = chercher_module_lang($module, $l)) {
125
+            $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l;
126
+            $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang));
127
+            surcharger_langue($fichiers_lang);
128
+            if ($l !== $lang) {
129
+                $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l];
130
+            }
131
+            $GLOBALS['lang_' . $var] = $l;
132
+            #spip_log("module de langue : {$module}_$l.php", 'traduire');
133
+            break;
134
+        }
135
+    }
136 136
 }
137 137
 
138 138
 /**
@@ -145,21 +145,21 @@  discard block
 block discarded – undo
145 145
  * @return array<string, string>
146 146
  */
147 147
 function lire_fichier_langue(string $fichier): array {
148
-	$idx_lang_before = $GLOBALS['idx_lang'] ?? null;
149
-	$idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire';
150
-	$GLOBALS['idx_lang'] = $idx_lang_tmp;
151
-	$idx_lang = include $fichier;
152
-	$GLOBALS['idx_lang'] = $idx_lang_before;
153
-	if (!is_array($idx_lang)) {
154
-		if (isset($GLOBALS[$idx_lang_tmp]) and is_array($GLOBALS[$idx_lang_tmp])) {
155
-			$idx_lang = $GLOBALS[$idx_lang_tmp];
156
-		} else {
157
-			$idx_lang = [];
158
-			spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR);
159
-		}
160
-		unset($GLOBALS[$idx_lang_tmp]);
161
-	}
162
-	return $idx_lang;
148
+    $idx_lang_before = $GLOBALS['idx_lang'] ?? null;
149
+    $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire';
150
+    $GLOBALS['idx_lang'] = $idx_lang_tmp;
151
+    $idx_lang = include $fichier;
152
+    $GLOBALS['idx_lang'] = $idx_lang_before;
153
+    if (!is_array($idx_lang)) {
154
+        if (isset($GLOBALS[$idx_lang_tmp]) and is_array($GLOBALS[$idx_lang_tmp])) {
155
+            $idx_lang = $GLOBALS[$idx_lang_tmp];
156
+        } else {
157
+            $idx_lang = [];
158
+            spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR);
159
+        }
160
+        unset($GLOBALS[$idx_lang_tmp]);
161
+    }
162
+    return $idx_lang;
163 163
 }
164 164
 
165 165
 /**
@@ -179,29 +179,29 @@  discard block
 block discarded – undo
179 179
  *    Liste des chemins de fichiers de langue à surcharger.
180 180
  **/
181 181
 function surcharger_langue($fichiers) {
182
-	static $surcharges = [];
183
-	if (!isset($GLOBALS['idx_lang'])) {
184
-		return;
185
-	}
182
+    static $surcharges = [];
183
+    if (!isset($GLOBALS['idx_lang'])) {
184
+        return;
185
+    }
186 186
 
187
-	if (!is_array($fichiers)) {
188
-		$fichiers = [$fichiers];
189
-	}
190
-	if (!count($fichiers)) {
191
-		return;
192
-	}
193
-	foreach ($fichiers as $fichier) {
194
-		if (!isset($surcharges[$fichier])) {
195
-			$surcharges[$fichier] = lire_fichier_langue($fichier);
196
-		}
197
-		if (is_array($surcharges[$fichier])) {
198
-			$GLOBALS[$GLOBALS['idx_lang']] ??= [];
199
-			$GLOBALS[$GLOBALS['idx_lang']] = array_merge(
200
-				$GLOBALS[$GLOBALS['idx_lang']],
201
-				$surcharges[$fichier]
202
-			);
203
-		}
204
-	}
187
+    if (!is_array($fichiers)) {
188
+        $fichiers = [$fichiers];
189
+    }
190
+    if (!count($fichiers)) {
191
+        return;
192
+    }
193
+    foreach ($fichiers as $fichier) {
194
+        if (!isset($surcharges[$fichier])) {
195
+            $surcharges[$fichier] = lire_fichier_langue($fichier);
196
+        }
197
+        if (is_array($surcharges[$fichier])) {
198
+            $GLOBALS[$GLOBALS['idx_lang']] ??= [];
199
+            $GLOBALS[$GLOBALS['idx_lang']] = array_merge(
200
+                $GLOBALS[$GLOBALS['idx_lang']],
201
+                $surcharges[$fichier]
202
+            );
203
+        }
204
+    }
205 205
 }
206 206
 
207 207
 /**
@@ -242,99 +242,99 @@  discard block
 block discarded – undo
242 242
  *     - Description : traduction et description (texte, module, langue)
243 243
  **/
244 244
 function inc_traduire_dist($ori, $lang, $raw = false) {
245
-	static $deja_vu = [];
246
-	static $local = [];
245
+    static $deja_vu = [];
246
+    static $local = [];
247 247
 
248
-	if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) {
249
-		return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte;
250
-	}
248
+    if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) {
249
+        return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte;
250
+    }
251 251
 
252
-	// modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES
253
-	if (strpos($ori, ':')) {
254
-		[$modules, $code] = explode(':', $ori, 2);
255
-		$modules = explode('|', $modules);
256
-		$ori_complet = $ori;
257
-	} else {
258
-		$modules = ['spip', 'ecrire'];
259
-		$code = $ori;
260
-		$ori_complet = implode('|', $modules) . ':' . $ori;
261
-	}
252
+    // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES
253
+    if (strpos($ori, ':')) {
254
+        [$modules, $code] = explode(':', $ori, 2);
255
+        $modules = explode('|', $modules);
256
+        $ori_complet = $ori;
257
+    } else {
258
+        $modules = ['spip', 'ecrire'];
259
+        $code = $ori;
260
+        $ori_complet = implode('|', $modules) . ':' . $ori;
261
+    }
262 262
 
263
-	$desc = new Description();
263
+    $desc = new Description();
264 264
 
265
-	// parcourir tous les modules jusqu'a ce qu'on trouve
266
-	foreach ($modules as $module) {
267
-		$var = 'i18n_' . $module . '_' . $lang;
265
+    // parcourir tous les modules jusqu'a ce qu'on trouve
266
+    foreach ($modules as $module) {
267
+        $var = 'i18n_' . $module . '_' . $lang;
268 268
 
269
-		if (empty($GLOBALS[$var])) {
270
-			charger_langue($lang, $module);
271
-			// surcharges persos -- on cherche
272
-			// (lang/)local_xx.php et/ou (lang/)local.php ...
273
-			if (!isset($local['local_' . $lang])) {
274
-				// redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer)
275
-				$GLOBALS['idx_lang'] = $var;
276
-				// ... (lang/)local_xx.php
277
-				$local['local_' . $lang] = chercher_module_lang('local', $lang);
278
-			}
279
-			if ($local['local_' . $lang]) {
280
-				surcharger_langue($local['local_' . $lang]);
281
-			}
282
-			// ... puis (lang/)local.php
283
-			if (!isset($local['local'])) {
284
-				$local['local'] = chercher_module_lang('local');
285
-			}
286
-			if ($local['local']) {
287
-				surcharger_langue($local['local']);
288
-			}
289
-		}
269
+        if (empty($GLOBALS[$var])) {
270
+            charger_langue($lang, $module);
271
+            // surcharges persos -- on cherche
272
+            // (lang/)local_xx.php et/ou (lang/)local.php ...
273
+            if (!isset($local['local_' . $lang])) {
274
+                // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer)
275
+                $GLOBALS['idx_lang'] = $var;
276
+                // ... (lang/)local_xx.php
277
+                $local['local_' . $lang] = chercher_module_lang('local', $lang);
278
+            }
279
+            if ($local['local_' . $lang]) {
280
+                surcharger_langue($local['local_' . $lang]);
281
+            }
282
+            // ... puis (lang/)local.php
283
+            if (!isset($local['local'])) {
284
+                $local['local'] = chercher_module_lang('local');
285
+            }
286
+            if ($local['local']) {
287
+                surcharger_langue($local['local']);
288
+            }
289
+        }
290 290
 
291
-		if (isset($GLOBALS[$var][$code])) {
292
-			$desc->code = $code;
293
-			$desc->module = $module;
294
-			$desc->langue = $GLOBALS['lang_' . $var] ?? $lang;
295
-			$desc->texte = $GLOBALS[$var][$code];
296
-			break;
297
-		}
298
-	}
291
+        if (isset($GLOBALS[$var][$code])) {
292
+            $desc->code = $code;
293
+            $desc->module = $module;
294
+            $desc->langue = $GLOBALS['lang_' . $var] ?? $lang;
295
+            $desc->texte = $GLOBALS[$var][$code];
296
+            break;
297
+        }
298
+    }
299 299
 
300
-	if (!$desc->corrections) {
301
-		$desc->corrections = true;
302
-		// Retour aux sources si la chaine est absente dans la langue cible ;
303
-		// on essaie d'abord la langue du site, puis a defaut la langue fr
304
-		if (
305
-			($desc->texte === null || !strlen($desc->texte))
306
-			and $lang !== _LANGUE_PAR_DEFAUT
307
-		) {
308
-			if ($lang !== $GLOBALS['meta']['langue_site']) {
309
-				$desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true);
310
-			} else {
311
-				$desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true);
312
-			}
313
-		}
300
+    if (!$desc->corrections) {
301
+        $desc->corrections = true;
302
+        // Retour aux sources si la chaine est absente dans la langue cible ;
303
+        // on essaie d'abord la langue du site, puis a defaut la langue fr
304
+        if (
305
+            ($desc->texte === null || !strlen($desc->texte))
306
+            and $lang !== _LANGUE_PAR_DEFAUT
307
+        ) {
308
+            if ($lang !== $GLOBALS['meta']['langue_site']) {
309
+                $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true);
310
+            } else {
311
+                $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true);
312
+            }
313
+        }
314 314
 
315
-		// Supprimer la mention <NEW> ou <MODIF>
316
-		if ($desc->texte && substr($desc->texte, 0, 1) === '<') {
317
-			$desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte);
318
-		}
315
+        // Supprimer la mention <NEW> ou <MODIF>
316
+        if ($desc->texte && substr($desc->texte, 0, 1) === '<') {
317
+            $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte);
318
+        }
319 319
 
320
-		// Si on n'est pas en utf-8, la chaine peut l'etre...
321
-		// le cas echeant on la convertit en entites html &#xxx;
322
-		if (
323
-			(!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8')
324
-			and preg_match(',[\x7f-\xff],S', $desc->texte)
325
-		) {
326
-			include_spip('inc/charsets');
327
-			$desc->texte = charset2unicode($desc->texte, 'utf-8');
328
-		}
329
-	}
320
+        // Si on n'est pas en utf-8, la chaine peut l'etre...
321
+        // le cas echeant on la convertit en entites html &#xxx;
322
+        if (
323
+            (!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8')
324
+            and preg_match(',[\x7f-\xff],S', $desc->texte)
325
+        ) {
326
+            include_spip('inc/charsets');
327
+            $desc->texte = charset2unicode($desc->texte, 'utf-8');
328
+        }
329
+    }
330 330
 
331
-	if (_request('var_mode') == 'traduction') {
332
-		$desc = definir_details_traduction($desc, $ori_complet);
333
-	} else {
334
-		$deja_vu[$lang][$ori] = $desc;
335
-	}
331
+    if (_request('var_mode') == 'traduction') {
332
+        $desc = definir_details_traduction($desc, $ori_complet);
333
+    } else {
334
+        $deja_vu[$lang][$ori] = $desc;
335
+    }
336 336
 
337
-	return $raw ? $desc : $desc->texte;
337
+    return $raw ? $desc : $desc->texte;
338 338
 }
339 339
 
340 340
 /**
@@ -346,23 +346,23 @@  discard block
 block discarded – undo
346 346
  * @return Description
347 347
  */
348 348
 function definir_details_traduction($desc, $modules) {
349
-	if (!$desc->mode and $desc->texte) {
350
-		// ne pas modifier 2 fois l'affichage
351
-		$desc->mode = 'traduction';
352
-		$classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : '');
353
-		$desc->texte = '<span '
354
-			. 'lang=' . $desc->langue
355
-			. ' class=' . $classe
356
-			. ' data-module=' . $desc->module
357
-			. ' data-code=' . $desc->code
358
-			. ' title=' . $modules . '(' . $desc->langue . ')>'
359
-			. $desc->texte
360
-			. '</span>';
361
-		$desc->texte = str_replace(
362
-			["$desc->module:", "$desc->module|"],
363
-			["*$desc->module*:", "*$desc->module*|"],
364
-			$desc->texte
365
-		);
366
-	}
367
-	return $desc;
349
+    if (!$desc->mode and $desc->texte) {
350
+        // ne pas modifier 2 fois l'affichage
351
+        $desc->mode = 'traduction';
352
+        $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : '');
353
+        $desc->texte = '<span '
354
+            . 'lang=' . $desc->langue
355
+            . ' class=' . $classe
356
+            . ' data-module=' . $desc->module
357
+            . ' data-code=' . $desc->code
358
+            . ' title=' . $modules . '(' . $desc->langue . ')>'
359
+            . $desc->texte
360
+            . '</span>';
361
+        $desc->texte = str_replace(
362
+            ["$desc->module:", "$desc->module|"],
363
+            ["*$desc->module*:", "*$desc->module*|"],
364
+            $desc->texte
365
+        );
366
+    }
367
+    return $desc;
368 368
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	static $dirs = [];
44 44
 	$liste = [];
45 45
 	foreach (creer_chemin() as $dir) {
46
-		if (!isset($dirs[$a = $dir . $dirname])) {
46
+		if (!isset($dirs[$a = $dir.$dirname])) {
47 47
 			$dirs[$a] = (is_dir($a) || !$a);
48 48
 		}
49 49
 		if ($dirs[$a]) {
@@ -69,21 +69,21 @@  discard block
 block discarded – undo
69 69
  **/
70 70
 function chercher_module_lang($module, $lang = '') {
71 71
 	if ($lang) {
72
-		$lang = '_' . $lang;
72
+		$lang = '_'.$lang;
73 73
 	}
74 74
 
75 75
 	// 1) dans un repertoire nomme lang/ se trouvant sur le chemin
76 76
 	if (
77 77
 		$f = ($module == 'local'
78
-		? find_in_path($module . $lang . '.php', 'lang/')
79
-		: find_langs_in_path($module . $lang . '.php', 'lang/'))
78
+		? find_in_path($module.$lang.'.php', 'lang/')
79
+		: find_langs_in_path($module.$lang.'.php', 'lang/'))
80 80
 	) {
81 81
 		return is_array($f) ? $f : [$f];
82 82
 	}
83 83
 
84 84
 	// 2) directement dans le chemin (old style, uniquement pour local)
85 85
 	return (($module == 'local') or strpos($module, '/'))
86
-		? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false)
86
+		? (($f = find_in_path($module.$lang.'.php')) ? [$f] : false)
87 87
 		: false;
88 88
 }
89 89
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
  **/
108 108
 function charger_langue($lang, $module = 'spip') {
109 109
 	static $langs = [];
110
-	$var = 'i18n_' . $module . '_' . $lang;
110
+	$var = 'i18n_'.$module.'_'.$lang;
111 111
 	if (!isset($langs[$lang])) {
112 112
 		$langs[$lang] = [];
113 113
 		if ($lang) {
@@ -122,13 +122,13 @@  discard block
 block discarded – undo
122 122
 	}
123 123
 	foreach ($langs[$lang] as $l) {
124 124
 		if ($fichiers_lang = chercher_module_lang($module, $l)) {
125
-			$GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l;
125
+			$GLOBALS['idx_lang'] = 'i18n_'.$module.'_'.$l;
126 126
 			$GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang));
127 127
 			surcharger_langue($fichiers_lang);
128 128
 			if ($l !== $lang) {
129
-				$GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l];
129
+				$GLOBALS[$var] = &$GLOBALS['i18n_'.$module.'_'.$l];
130 130
 			}
131
-			$GLOBALS['lang_' . $var] = $l;
131
+			$GLOBALS['lang_'.$var] = $l;
132 132
 			#spip_log("module de langue : {$module}_$l.php", 'traduire');
133 133
 			break;
134 134
 		}
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
  */
147 147
 function lire_fichier_langue(string $fichier): array {
148 148
 	$idx_lang_before = $GLOBALS['idx_lang'] ?? null;
149
-	$idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire';
149
+	$idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang').'@temporaire';
150 150
 	$GLOBALS['idx_lang'] = $idx_lang_tmp;
151 151
 	$idx_lang = include $fichier;
152 152
 	$GLOBALS['idx_lang'] = $idx_lang_before;
@@ -257,27 +257,27 @@  discard block
 block discarded – undo
257 257
 	} else {
258 258
 		$modules = ['spip', 'ecrire'];
259 259
 		$code = $ori;
260
-		$ori_complet = implode('|', $modules) . ':' . $ori;
260
+		$ori_complet = implode('|', $modules).':'.$ori;
261 261
 	}
262 262
 
263 263
 	$desc = new Description();
264 264
 
265 265
 	// parcourir tous les modules jusqu'a ce qu'on trouve
266 266
 	foreach ($modules as $module) {
267
-		$var = 'i18n_' . $module . '_' . $lang;
267
+		$var = 'i18n_'.$module.'_'.$lang;
268 268
 
269 269
 		if (empty($GLOBALS[$var])) {
270 270
 			charger_langue($lang, $module);
271 271
 			// surcharges persos -- on cherche
272 272
 			// (lang/)local_xx.php et/ou (lang/)local.php ...
273
-			if (!isset($local['local_' . $lang])) {
273
+			if (!isset($local['local_'.$lang])) {
274 274
 				// redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer)
275 275
 				$GLOBALS['idx_lang'] = $var;
276 276
 				// ... (lang/)local_xx.php
277
-				$local['local_' . $lang] = chercher_module_lang('local', $lang);
277
+				$local['local_'.$lang] = chercher_module_lang('local', $lang);
278 278
 			}
279
-			if ($local['local_' . $lang]) {
280
-				surcharger_langue($local['local_' . $lang]);
279
+			if ($local['local_'.$lang]) {
280
+				surcharger_langue($local['local_'.$lang]);
281 281
 			}
282 282
 			// ... puis (lang/)local.php
283 283
 			if (!isset($local['local'])) {
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 		if (isset($GLOBALS[$var][$code])) {
292 292
 			$desc->code = $code;
293 293
 			$desc->module = $module;
294
-			$desc->langue = $GLOBALS['lang_' . $var] ?? $lang;
294
+			$desc->langue = $GLOBALS['lang_'.$var] ?? $lang;
295 295
 			$desc->texte = $GLOBALS[$var][$code];
296 296
 			break;
297 297
 		}
@@ -349,13 +349,13 @@  discard block
 block discarded – undo
349 349
 	if (!$desc->mode and $desc->texte) {
350 350
 		// ne pas modifier 2 fois l'affichage
351 351
 		$desc->mode = 'traduction';
352
-		$classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : '');
352
+		$classe = 'debug-traduction'.($desc->module == 'ecrire' ? '-prive' : '');
353 353
 		$desc->texte = '<span '
354
-			. 'lang=' . $desc->langue
355
-			. ' class=' . $classe
356
-			. ' data-module=' . $desc->module
357
-			. ' data-code=' . $desc->code
358
-			. ' title=' . $modules . '(' . $desc->langue . ')>'
354
+			. 'lang='.$desc->langue
355
+			. ' class='.$classe
356
+			. ' data-module='.$desc->module
357
+			. ' data-code='.$desc->code
358
+			. ' title='.$modules.'('.$desc->langue.')>'
359 359
 			. $desc->texte
360 360
 			. '</span>';
361 361
 		$desc->texte = str_replace(
Please login to merge, or discard this patch.
ecrire/inc/filtres.php 2 patches
Indentation   +2400 added lines, -2400 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Filtres
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/charsets');
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
  * @return string Fonction PHP correspondante du filtre
43 43
  */
44 44
 function charger_filtre($fonc, $default = 'filtre_identite_dist') {
45
-	include_fichiers_fonctions(); // inclure les fichiers fonctions
46
-	return chercher_filtre($fonc, $default);
45
+    include_fichiers_fonctions(); // inclure les fichiers fonctions
46
+    return chercher_filtre($fonc, $default);
47 47
 }
48 48
 
49 49
 /**
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
  * @return string texte
54 54
  **/
55 55
 function filtre_identite_dist($texte) {
56
- return $texte;
56
+    return $texte;
57 57
 }
58 58
 
59 59
 /**
@@ -77,33 +77,33 @@  discard block
 block discarded – undo
77 77
  *     Fonction PHP correspondante du filtre demandé
78 78
  */
79 79
 function chercher_filtre($fonc, $default = null) {
80
-	if (!$fonc) {
81
-		return $default;
82
-	}
83
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
84
-	// Foo::Bar
85
-	// qui peuvent etre avec un namespace : space\Foo::Bar
86
-	if (preg_match(',^[\w]+/,', $fonc)) {
87
-		$nom = preg_replace(',\W,', '_', $fonc);
88
-		$f = chercher_filtre($nom);
89
-		// cas du sous-type MIME sans filtre associe, passer au type:
90
-		// si filtre_text_plain pas defini, passe a filtre_text
91
-		if (!$f and $nom !== $fonc) {
92
-			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
93
-		}
94
-
95
-		return $f;
96
-	}
97
-
98
-	include_fichiers_fonctions();
99
-	foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
100
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101
-		if (is_callable($f)) {
102
-			return $f;
103
-		}
104
-	}
105
-
106
-	return $default;
80
+    if (!$fonc) {
81
+        return $default;
82
+    }
83
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
84
+    // Foo::Bar
85
+    // qui peuvent etre avec un namespace : space\Foo::Bar
86
+    if (preg_match(',^[\w]+/,', $fonc)) {
87
+        $nom = preg_replace(',\W,', '_', $fonc);
88
+        $f = chercher_filtre($nom);
89
+        // cas du sous-type MIME sans filtre associe, passer au type:
90
+        // si filtre_text_plain pas defini, passe a filtre_text
91
+        if (!$f and $nom !== $fonc) {
92
+            $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
93
+        }
94
+
95
+        return $f;
96
+    }
97
+
98
+    include_fichiers_fonctions();
99
+    foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
100
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101
+        if (is_callable($f)) {
102
+            return $f;
103
+        }
104
+    }
105
+
106
+    return $default;
107 107
 }
108 108
 
109 109
 /**
@@ -147,8 +147,8 @@  discard block
 block discarded – undo
147 147
  *     Chaîne vide sinon.
148 148
  **/
149 149
 function appliquer_filtre($arg, $filtre) {
150
-	$args = func_get_args();
151
-	return appliquer_filtre_sinon($arg, $filtre, $args, '');
150
+    $args = func_get_args();
151
+    return appliquer_filtre_sinon($arg, $filtre, $args, '');
152 152
 }
153 153
 
154 154
 /**
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
  *     texte d'origine sinon
174 174
  **/
175 175
 function appliquer_si_filtre($arg, $filtre) {
176
-	$args = func_get_args();
177
-	return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
176
+    $args = func_get_args();
177
+    return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
178 178
 }
179 179
 
180 180
 /**
@@ -190,12 +190,12 @@  discard block
 block discarded – undo
190 190
  *     Version de SPIP
191 191
  **/
192 192
 function spip_version() {
193
-	$version = $GLOBALS['spip_version_affichee'];
194
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
195
-		$version .= " $vcs_version";
196
-	}
193
+    $version = $GLOBALS['spip_version_affichee'];
194
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
195
+        $version .= " $vcs_version";
196
+    }
197 197
 
198
-	return $version;
198
+    return $version;
199 199
 }
200 200
 
201 201
 /**
@@ -207,11 +207,11 @@  discard block
 block discarded – undo
207 207
  * @return string
208 208
  */
209 209
 function header_silencieux($version): string {
210
-	if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) {
211
-		$version = '';
212
-	}
210
+    if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) {
211
+        $version = '';
212
+    }
213 213
 
214
-	return (string) $version;
214
+    return (string) $version;
215 215
 }
216 216
 
217 217
 /**
@@ -224,16 +224,16 @@  discard block
 block discarded – undo
224 224
  *    - string|null si $raw = false
225 225
  */
226 226
 function version_vcs_courante($dir, $raw = false) {
227
-	$desc = decrire_version_git($dir);
228
-	if ($desc === null or $raw) {
229
-		return $desc;
230
-	}
231
-	// affichage "GIT [master: abcdef]"
232
-	$commit = $desc['commit_short'] ?? $desc['commit'];
233
-	if ($desc['branch']) {
234
-		$commit = $desc['branch'] . ': ' . $commit;
235
-	}
236
-	return "{$desc['vcs']} [$commit]";
227
+    $desc = decrire_version_git($dir);
228
+    if ($desc === null or $raw) {
229
+        return $desc;
230
+    }
231
+    // affichage "GIT [master: abcdef]"
232
+    $commit = $desc['commit_short'] ?? $desc['commit'];
233
+    if ($desc['branch']) {
234
+        $commit = $desc['branch'] . ': ' . $commit;
235
+    }
236
+    return "{$desc['vcs']} [$commit]";
237 237
 }
238 238
 
239 239
 /**
@@ -245,24 +245,24 @@  discard block
 block discarded – undo
245 245
  *      array ['branch' => xx, 'commit' => yy] sinon.
246 246
  **/
247 247
 function decrire_version_git($dir) {
248
-	if (!$dir) {
249
-		$dir = '.';
250
-	}
251
-
252
-	// version installee par GIT
253
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
254
-		$currentHead = trim(substr($c, 4));
255
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
256
-			return [
257
-				'vcs' => 'GIT',
258
-				'branch' => basename($currentHead),
259
-				'commit' => trim($hash),
260
-				'commit_short' => substr(trim($hash), 0, 8),
261
-			];
262
-		}
263
-	}
264
-
265
-	return null;
248
+    if (!$dir) {
249
+        $dir = '.';
250
+    }
251
+
252
+    // version installee par GIT
253
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
254
+        $currentHead = trim(substr($c, 4));
255
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
256
+            return [
257
+                'vcs' => 'GIT',
258
+                'branch' => basename($currentHead),
259
+                'commit' => trim($hash),
260
+                'commit_short' => substr(trim($hash), 0, 8),
261
+            ];
262
+        }
263
+    }
264
+
265
+    return null;
266 266
 }
267 267
 
268 268
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -309,18 +309,18 @@  discard block
 block discarded – undo
309 309
  *     Code HTML retourné par le filtre
310 310
  **/
311 311
 function filtrer($filtre) {
312
-	$tous = func_get_args();
313
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
314
-		return image_filtrer($tous);
315
-	} elseif ($f = chercher_filtre($filtre)) {
316
-		array_shift($tous);
317
-		return $f(...$tous);
318
-	} else {
319
-		// le filtre n'existe pas, on provoque une erreur
320
-		$msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
321
-		erreur_squelette($msg);
322
-		return '';
323
-	}
312
+    $tous = func_get_args();
313
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
314
+        return image_filtrer($tous);
315
+    } elseif ($f = chercher_filtre($filtre)) {
316
+        array_shift($tous);
317
+        return $f(...$tous);
318
+    } else {
319
+        // le filtre n'existe pas, on provoque une erreur
320
+        $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
321
+        erreur_squelette($msg);
322
+        return '';
323
+    }
324 324
 }
325 325
 
326 326
 /**
@@ -337,11 +337,11 @@  discard block
 block discarded – undo
337 337
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
338 338
  */
339 339
 function trouver_filtre_matrice($filtre) {
340
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
341
-		find_in_path($f, '', true);
342
-		$GLOBALS['spip_matrice'][$filtre] = true;
343
-	}
344
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
340
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
341
+        find_in_path($f, '', true);
342
+        $GLOBALS['spip_matrice'][$filtre] = true;
343
+    }
344
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
345 345
 }
346 346
 
347 347
 
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
  * @return mixed
370 370
  */
371 371
 function filtre_set(&$Pile, $val, $key, $continue = null) {
372
-	$Pile['vars'][$key] = $val;
373
-	return $continue ? $val : '';
372
+    $Pile['vars'][$key] = $val;
373
+    return $continue ? $val : '';
374 374
 }
375 375
 
376 376
 /**
@@ -396,8 +396,8 @@  discard block
 block discarded – undo
396 396
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
397 397
  */
398 398
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
399
-	$Pile[0][$key] = $val;
400
-	return $continue ? $val : '';
399
+    $Pile[0][$key] = $val;
400
+    return $continue ? $val : '';
401 401
 }
402 402
 
403 403
 /**
@@ -406,8 +406,8 @@  discard block
 block discarded – undo
406 406
  * @return string
407 407
  */
408 408
 function filtre_sanitize_env(&$Pile, $keys) {
409
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
410
-	return '';
409
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
410
+    return '';
411 411
 }
412 412
 
413 413
 
@@ -430,18 +430,18 @@  discard block
 block discarded – undo
430 430
  * @return mixed Retourne la valeur (sans la modifier).
431 431
  */
432 432
 function filtre_debug($val, $key = null) {
433
-	$debug = (
434
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
435
-		) . var_export($val, true);
433
+    $debug = (
434
+        is_null($key) ? '' : (var_export($key, true) . ' = ')
435
+        ) . var_export($val, true);
436 436
 
437
-	include_spip('inc/autoriser');
438
-	if (autoriser('webmestre')) {
439
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
440
-	}
437
+    include_spip('inc/autoriser');
438
+    if (autoriser('webmestre')) {
439
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
440
+    }
441 441
 
442
-	spip_log($debug, 'debug');
442
+    spip_log($debug, 'debug');
443 443
 
444
-	return $val;
444
+    return $val;
445 445
 }
446 446
 
447 447
 
@@ -471,84 +471,84 @@  discard block
 block discarded – undo
471 471
  *     texte qui a reçu les filtres
472 472
  **/
473 473
 function image_filtrer($args) {
474
-	$filtre = array_shift($args); # enlever $filtre
475
-	$texte = array_shift($args);
476
-	if ($texte === null || !strlen($texte)) {
477
-		return '';
478
-	}
479
-	find_in_path('filtres_images_mini.php', 'inc/', true);
480
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
481
-	// Cas du nom de fichier local
482
-	$is_file = trim($texte);
483
-	if (
484
-		strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
485
-		  or strpbrk($is_file, "<>\n\r\t") !== false
486
-		  or strpos($is_file, '/') === 0
487
-	) {
488
-		$is_file = false;
489
-	}
490
-	if ($is_file) {
491
-		$is_local_file = function ($path) {
492
-			if (strpos($path, '?') !== false) {
493
-				$path = supprimer_timestamp($path);
494
-				// remove ?24px added by find_in_theme on .svg files
495
-				$path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
496
-			}
497
-			return file_exists($path);
498
-		};
499
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
500
-			$res = $filtre("<img src='$is_file' />", ...$args);
501
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
502
-			return $res;
503
-		}
504
-	}
505
-
506
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
507
-	if (
508
-		preg_match_all(
509
-			',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
510
-			$texte,
511
-			$tags,
512
-			PREG_SET_ORDER
513
-		)
514
-	) {
515
-		foreach ($tags as $tag) {
516
-			$class = extraire_attribut($tag[3], 'class');
517
-			if (
518
-				!$class or
519
-				(strpos($class, 'filtre_inactif') === false
520
-					// compat historique a virer en 3.2
521
-					and !str_contains($class, 'no_image_filtrer'))
522
-			) {
523
-				if ($reduit = $filtre($tag[3], ...$args)) {
524
-					// En cas de span spip_documents, modifier le style=...width:
525
-					if ($tag[1]) {
526
-						$w = extraire_attribut($reduit, 'width');
527
-						if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
528
-							$w = $regs[1];
529
-						}
530
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
531
-							$style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style);
532
-							$replace = inserer_attribut($tag[1], 'style', $style);
533
-							$texte = str_replace($tag[1], $replace, $texte);
534
-						}
535
-					}
536
-					// traiter aussi un eventuel mouseover
537
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
538
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
539
-							$srcover = $match[1];
540
-							$srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
541
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
542
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
543
-						}
544
-					}
545
-					$texte = str_replace($tag[3], $reduit, $texte);
546
-				}
547
-			}
548
-		}
549
-	}
550
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
551
-	return $texte;
474
+    $filtre = array_shift($args); # enlever $filtre
475
+    $texte = array_shift($args);
476
+    if ($texte === null || !strlen($texte)) {
477
+        return '';
478
+    }
479
+    find_in_path('filtres_images_mini.php', 'inc/', true);
480
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
481
+    // Cas du nom de fichier local
482
+    $is_file = trim($texte);
483
+    if (
484
+        strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
485
+          or strpbrk($is_file, "<>\n\r\t") !== false
486
+          or strpos($is_file, '/') === 0
487
+    ) {
488
+        $is_file = false;
489
+    }
490
+    if ($is_file) {
491
+        $is_local_file = function ($path) {
492
+            if (strpos($path, '?') !== false) {
493
+                $path = supprimer_timestamp($path);
494
+                // remove ?24px added by find_in_theme on .svg files
495
+                $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
496
+            }
497
+            return file_exists($path);
498
+        };
499
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
500
+            $res = $filtre("<img src='$is_file' />", ...$args);
501
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
502
+            return $res;
503
+        }
504
+    }
505
+
506
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
507
+    if (
508
+        preg_match_all(
509
+            ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
510
+            $texte,
511
+            $tags,
512
+            PREG_SET_ORDER
513
+        )
514
+    ) {
515
+        foreach ($tags as $tag) {
516
+            $class = extraire_attribut($tag[3], 'class');
517
+            if (
518
+                !$class or
519
+                (strpos($class, 'filtre_inactif') === false
520
+                    // compat historique a virer en 3.2
521
+                    and !str_contains($class, 'no_image_filtrer'))
522
+            ) {
523
+                if ($reduit = $filtre($tag[3], ...$args)) {
524
+                    // En cas de span spip_documents, modifier le style=...width:
525
+                    if ($tag[1]) {
526
+                        $w = extraire_attribut($reduit, 'width');
527
+                        if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
528
+                            $w = $regs[1];
529
+                        }
530
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
531
+                            $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style);
532
+                            $replace = inserer_attribut($tag[1], 'style', $style);
533
+                            $texte = str_replace($tag[1], $replace, $texte);
534
+                        }
535
+                    }
536
+                    // traiter aussi un eventuel mouseover
537
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
538
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
539
+                            $srcover = $match[1];
540
+                            $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
541
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
542
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
543
+                        }
544
+                    }
545
+                    $texte = str_replace($tag[3], $reduit, $texte);
546
+                }
547
+            }
548
+        }
549
+    }
550
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
551
+    return $texte;
552 552
 }
553 553
 
554 554
 /**
@@ -565,91 +565,91 @@  discard block
 block discarded – undo
565 565
  **/
566 566
 function infos_image($img, $force_refresh = false) {
567 567
 
568
-	static $largeur_img = [], $hauteur_img = [], $poids_img = [];
569
-	$srcWidth = 0;
570
-	$srcHeight = 0;
571
-	$srcSize = null;
572
-
573
-	$src = extraire_attribut($img, 'src');
574
-
575
-	if (!$src) {
576
-		$src = $img;
577
-	} else {
578
-		$srcWidth = extraire_attribut($img, 'width');
579
-		$srcHeight = extraire_attribut($img, 'height');
580
-	}
581
-
582
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
583
-	// la copie locale a toutes les chances d'etre la ou de resservir
584
-	if (tester_url_absolue($src)) {
585
-		include_spip('inc/distant');
586
-		$fichier = copie_locale($src);
587
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
588
-	}
589
-	if (($p = strpos($src, '?')) !== false) {
590
-		$src = substr($src, 0, $p);
591
-	}
592
-
593
-	$imagesize = false;
594
-	if (isset($largeur_img[$src]) and !$force_refresh) {
595
-		$srcWidth = $largeur_img[$src];
596
-	}
597
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
598
-		$srcHeight = $hauteur_img[$src];
599
-	}
600
-	if (isset($poids_img[$src]) and !$force_refresh) {
601
-		$srcSize = $poids_img[$src];
602
-	}
603
-	if (!$srcWidth or !$srcHeight or is_null($srcSize)) {
604
-		if (
605
-			file_exists($src)
606
-			and $imagesize = spip_getimagesize($src)
607
-		) {
608
-			if (!$srcWidth) {
609
-				$largeur_img[$src] = $srcWidth = $imagesize[0];
610
-			}
611
-			if (!$srcHeight) {
612
-				$hauteur_img[$src] = $srcHeight = $imagesize[1];
613
-			}
614
-			if (!$srcSize) {
615
-				$poids_img[$src] = filesize($src);
616
-			}
617
-		}
618
-		elseif (strpos($src, '<svg') !== false) {
619
-			include_spip('inc/svg');
620
-			if ($attrs = svg_lire_attributs($src)) {
621
-				[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
622
-				if (!$srcWidth) {
623
-					$largeur_img[$src] = $srcWidth = $width;
624
-				}
625
-				if (!$srcHeight) {
626
-					$hauteur_img[$src] = $srcHeight = $height;
627
-				}
628
-				if (!$srcSize) {
629
-					$poids_img[$src] = $srcSize = strlen($src);
630
-				}
631
-			}
632
-		}
633
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
634
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
635
-		elseif (
636
-			@file_exists($f = "$src.src")
637
-			and lire_fichier($f, $valeurs)
638
-			and $valeurs = unserialize($valeurs)
639
-		) {
640
-			if (!$srcWidth) {
641
-				$largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
642
-			}
643
-			if (!$srcHeight) {
644
-				$hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
645
-			}
646
-			if (!$srcSize) {
647
-				$poids_img[$src] = $srcSize = 0;
648
-			}
649
-		}
650
-	}
651
-
652
-	return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
568
+    static $largeur_img = [], $hauteur_img = [], $poids_img = [];
569
+    $srcWidth = 0;
570
+    $srcHeight = 0;
571
+    $srcSize = null;
572
+
573
+    $src = extraire_attribut($img, 'src');
574
+
575
+    if (!$src) {
576
+        $src = $img;
577
+    } else {
578
+        $srcWidth = extraire_attribut($img, 'width');
579
+        $srcHeight = extraire_attribut($img, 'height');
580
+    }
581
+
582
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
583
+    // la copie locale a toutes les chances d'etre la ou de resservir
584
+    if (tester_url_absolue($src)) {
585
+        include_spip('inc/distant');
586
+        $fichier = copie_locale($src);
587
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
588
+    }
589
+    if (($p = strpos($src, '?')) !== false) {
590
+        $src = substr($src, 0, $p);
591
+    }
592
+
593
+    $imagesize = false;
594
+    if (isset($largeur_img[$src]) and !$force_refresh) {
595
+        $srcWidth = $largeur_img[$src];
596
+    }
597
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
598
+        $srcHeight = $hauteur_img[$src];
599
+    }
600
+    if (isset($poids_img[$src]) and !$force_refresh) {
601
+        $srcSize = $poids_img[$src];
602
+    }
603
+    if (!$srcWidth or !$srcHeight or is_null($srcSize)) {
604
+        if (
605
+            file_exists($src)
606
+            and $imagesize = spip_getimagesize($src)
607
+        ) {
608
+            if (!$srcWidth) {
609
+                $largeur_img[$src] = $srcWidth = $imagesize[0];
610
+            }
611
+            if (!$srcHeight) {
612
+                $hauteur_img[$src] = $srcHeight = $imagesize[1];
613
+            }
614
+            if (!$srcSize) {
615
+                $poids_img[$src] = filesize($src);
616
+            }
617
+        }
618
+        elseif (strpos($src, '<svg') !== false) {
619
+            include_spip('inc/svg');
620
+            if ($attrs = svg_lire_attributs($src)) {
621
+                [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
622
+                if (!$srcWidth) {
623
+                    $largeur_img[$src] = $srcWidth = $width;
624
+                }
625
+                if (!$srcHeight) {
626
+                    $hauteur_img[$src] = $srcHeight = $height;
627
+                }
628
+                if (!$srcSize) {
629
+                    $poids_img[$src] = $srcSize = strlen($src);
630
+                }
631
+            }
632
+        }
633
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
634
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
635
+        elseif (
636
+            @file_exists($f = "$src.src")
637
+            and lire_fichier($f, $valeurs)
638
+            and $valeurs = unserialize($valeurs)
639
+        ) {
640
+            if (!$srcWidth) {
641
+                $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
642
+            }
643
+            if (!$srcHeight) {
644
+                $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
645
+            }
646
+            if (!$srcSize) {
647
+                $poids_img[$src] = $srcSize = 0;
648
+            }
649
+        }
650
+    }
651
+
652
+    return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
653 653
 }
654 654
 
655 655
 /**
@@ -665,13 +665,13 @@  discard block
 block discarded – undo
665 665
  *     poids
666 666
  **/
667 667
 function poids_image($img, $force_refresh = false) {
668
-	$infos = infos_image($img, $force_refresh);
669
-	return $infos['poids'];
668
+    $infos = infos_image($img, $force_refresh);
669
+    return $infos['poids'];
670 670
 }
671 671
 
672 672
 function taille_image($img, $force_refresh = false) {
673
-	$infos = infos_image($img, $force_refresh);
674
-	return [$infos['hauteur'], $infos['largeur']];
673
+    $infos = infos_image($img, $force_refresh);
674
+    return [$infos['hauteur'], $infos['largeur']];
675 675
 }
676 676
 
677 677
 /**
@@ -688,12 +688,12 @@  discard block
 block discarded – undo
688 688
  *     Largeur en pixels, NULL ou 0 si aucune image.
689 689
  **/
690 690
 function largeur($img) {
691
-	if (!$img) {
692
-		return;
693
-	}
694
-	[$h, $l] = taille_image($img);
691
+    if (!$img) {
692
+        return;
693
+    }
694
+    [$h, $l] = taille_image($img);
695 695
 
696
-	return $l;
696
+    return $l;
697 697
 }
698 698
 
699 699
 /**
@@ -710,12 +710,12 @@  discard block
 block discarded – undo
710 710
  *     Hauteur en pixels, NULL ou 0 si aucune image.
711 711
  **/
712 712
 function hauteur($img) {
713
-	if (!$img) {
714
-		return;
715
-	}
716
-	[$h, $l] = taille_image($img);
713
+    if (!$img) {
714
+        return;
715
+    }
716
+    [$h, $l] = taille_image($img);
717 717
 
718
-	return $h;
718
+    return $h;
719 719
 }
720 720
 
721 721
 
@@ -735,11 +735,11 @@  discard block
 block discarded – undo
735 735
  * @return string
736 736
  **/
737 737
 function corriger_entites_html($texte) {
738
-	if (strpos($texte, '&amp;') === false) {
739
-		return $texte;
740
-	}
738
+    if (strpos($texte, '&amp;') === false) {
739
+        return $texte;
740
+    }
741 741
 
742
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
742
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
743 743
 }
744 744
 
745 745
 /**
@@ -754,11 +754,11 @@  discard block
 block discarded – undo
754 754
  * @return string
755 755
  **/
756 756
 function corriger_toutes_entites_html($texte) {
757
-	if (strpos($texte, '&amp;') === false) {
758
-		return $texte;
759
-	}
757
+    if (strpos($texte, '&amp;') === false) {
758
+        return $texte;
759
+    }
760 760
 
761
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
761
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
762 762
 }
763 763
 
764 764
 /**
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
  * @return string
769 769
  **/
770 770
 function proteger_amp($texte) {
771
-	return str_replace('&', '&amp;', $texte);
771
+    return str_replace('&', '&amp;', $texte);
772 772
 }
773 773
 
774 774
 
@@ -799,21 +799,21 @@  discard block
 block discarded – undo
799 799
  * @return mixed|string
800 800
  */
801 801
 function entites_html($texte, $tout = false, $quote = true) {
802
-	if (
803
-		!is_string($texte) or !$texte
804
-		or strpbrk($texte, "&\"'<>") == false
805
-	) {
806
-		return $texte;
807
-	}
808
-	include_spip('inc/texte');
809
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
810
-	$flags |= ENT_HTML401;
811
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
812
-	if ($tout) {
813
-		return corriger_toutes_entites_html($texte);
814
-	} else {
815
-		return corriger_entites_html($texte);
816
-	}
802
+    if (
803
+        !is_string($texte) or !$texte
804
+        or strpbrk($texte, "&\"'<>") == false
805
+    ) {
806
+        return $texte;
807
+    }
808
+    include_spip('inc/texte');
809
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
810
+    $flags |= ENT_HTML401;
811
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
812
+    if ($tout) {
813
+        return corriger_toutes_entites_html($texte);
814
+    } else {
815
+        return corriger_entites_html($texte);
816
+    }
817 817
 }
818 818
 
819 819
 /**
@@ -832,38 +832,38 @@  discard block
 block discarded – undo
832 832
  *     texte converti
833 833
  **/
834 834
 function filtrer_entites(?string $texte): string {
835
-	$texte ??= '';
836
-	if (strpos($texte, '&') === false) {
837
-		return $texte;
838
-	}
839
-	// filtrer
840
-	$texte = html2unicode($texte);
841
-	// remettre le tout dans le charset cible
842
-	$texte = unicode2charset($texte);
843
-	// cas particulier des " et ' qu'il faut filtrer aussi
844
-	// (on le faisait deja avec un &quot;)
845
-	if (strpos($texte, '&#') !== false) {
846
-		$texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
847
-	}
835
+    $texte ??= '';
836
+    if (strpos($texte, '&') === false) {
837
+        return $texte;
838
+    }
839
+    // filtrer
840
+    $texte = html2unicode($texte);
841
+    // remettre le tout dans le charset cible
842
+    $texte = unicode2charset($texte);
843
+    // cas particulier des " et ' qu'il faut filtrer aussi
844
+    // (on le faisait deja avec un &quot;)
845
+    if (strpos($texte, '&#') !== false) {
846
+        $texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
847
+    }
848 848
 
849
-	return $texte;
849
+    return $texte;
850 850
 }
851 851
 
852 852
 
853 853
 if (!function_exists('filtre_filtrer_entites_dist')) {
854
-	/**
855
-	 * Version sécurisée de filtrer_entites
856
-	 *
857
-	 * @uses interdire_scripts()
858
-	 * @uses filtrer_entites()
859
-	 *
860
-	 * @param string $t
861
-	 * @return string
862
-	 */
863
-	function filtre_filtrer_entites_dist($t) {
864
-		include_spip('inc/texte');
865
-		return interdire_scripts(filtrer_entites($t));
866
-	}
854
+    /**
855
+     * Version sécurisée de filtrer_entites
856
+     *
857
+     * @uses interdire_scripts()
858
+     * @uses filtrer_entites()
859
+     *
860
+     * @param string $t
861
+     * @return string
862
+     */
863
+    function filtre_filtrer_entites_dist($t) {
864
+        include_spip('inc/texte');
865
+        return interdire_scripts(filtrer_entites($t));
866
+    }
867 867
 }
868 868
 
869 869
 
@@ -878,18 +878,18 @@  discard block
 block discarded – undo
878 878
  * @return string|array
879 879
  **/
880 880
 function supprimer_caracteres_illegaux($texte) {
881
-	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";
882
-	static $to = null;
881
+    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";
882
+    static $to = null;
883 883
 
884
-	if (is_array($texte)) {
885
-		return array_map('supprimer_caracteres_illegaux', $texte);
886
-	}
884
+    if (is_array($texte)) {
885
+        return array_map('supprimer_caracteres_illegaux', $texte);
886
+    }
887 887
 
888
-	if (!$to) {
889
-		$to = str_repeat('-', strlen($from));
890
-	}
888
+    if (!$to) {
889
+        $to = str_repeat('-', strlen($from));
890
+    }
891 891
 
892
-	return strtr($texte, $from, $to);
892
+    return strtr($texte, $from, $to);
893 893
 }
894 894
 
895 895
 /**
@@ -901,10 +901,10 @@  discard block
 block discarded – undo
901 901
  * @return string|array
902 902
  **/
903 903
 function corriger_caracteres($texte) {
904
-	$texte = corriger_caracteres_windows($texte);
905
-	$texte = supprimer_caracteres_illegaux($texte);
904
+    $texte = corriger_caracteres_windows($texte);
905
+    $texte = supprimer_caracteres_illegaux($texte);
906 906
 
907
-	return $texte;
907
+    return $texte;
908 908
 }
909 909
 
910 910
 /**
@@ -921,44 +921,44 @@  discard block
 block discarded – undo
921 921
  *     texte encodé pour XML
922 922
  */
923 923
 function texte_backend(string $texte): string {
924
-	if ($texte === '') {
925
-		return '';
926
-	}
924
+    if ($texte === '') {
925
+        return '';
926
+    }
927 927
 
928
-	static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
928
+    static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
929 929
 
930
-	// si on a des liens ou des images, les passer en absolu
931
-	$texte = liens_absolus($texte);
930
+    // si on a des liens ou des images, les passer en absolu
931
+    $texte = liens_absolus($texte);
932 932
 
933
-	// echapper les tags &gt; &lt;
934
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
933
+    // echapper les tags &gt; &lt;
934
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
935 935
 
936
-	// importer les &eacute;
937
-	$texte = filtrer_entites($texte);
936
+    // importer les &eacute;
937
+    $texte = filtrer_entites($texte);
938 938
 
939
-	// " -> &quot; et tout ce genre de choses
940
-	$u = $GLOBALS['meta']['pcre_u'];
941
-	$texte = str_replace('&nbsp;', ' ', $texte);
942
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
943
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
944
-	$texte = entites_html($texte, false, false);
945
-	// mais bien echapper les double quotes !
946
-	$texte = str_replace('"', '&#034;', $texte);
939
+    // " -> &quot; et tout ce genre de choses
940
+    $u = $GLOBALS['meta']['pcre_u'];
941
+    $texte = str_replace('&nbsp;', ' ', $texte);
942
+    $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
943
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
944
+    $texte = entites_html($texte, false, false);
945
+    // mais bien echapper les double quotes !
946
+    $texte = str_replace('"', '&#034;', $texte);
947 947
 
948
-	// verifier le charset
949
-	$texte = charset2unicode($texte);
948
+    // verifier le charset
949
+    $texte = charset2unicode($texte);
950 950
 
951
-	// Caracteres problematiques en iso-latin 1
952
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
953
-		$texte = str_replace(chr(156), '&#156;', $texte);
954
-		$texte = str_replace(chr(140), '&#140;', $texte);
955
-		$texte = str_replace(chr(159), '&#159;', $texte);
956
-	}
951
+    // Caracteres problematiques en iso-latin 1
952
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
953
+        $texte = str_replace(chr(156), '&#156;', $texte);
954
+        $texte = str_replace(chr(140), '&#140;', $texte);
955
+        $texte = str_replace(chr(159), '&#159;', $texte);
956
+    }
957 957
 
958
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
959
-	// et le caractere apostrophe alourdit les squelettes avec PHP
960
-	// ==> on les remplace par l'entite HTML
961
-	return str_replace($apostrophe, "'", $texte);
958
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
959
+    // et le caractere apostrophe alourdit les squelettes avec PHP
960
+    // ==> on les remplace par l'entite HTML
961
+    return str_replace($apostrophe, "'", $texte);
962 962
 }
963 963
 
964 964
 /**
@@ -975,7 +975,7 @@  discard block
 block discarded – undo
975 975
  *     texte encodé et quote pour XML
976 976
  */
977 977
 function texte_backendq(string $texte): string {
978
-	return addslashes(texte_backend($texte));
978
+    return addslashes(texte_backend($texte));
979 979
 }
980 980
 
981 981
 
@@ -997,14 +997,14 @@  discard block
 block discarded – undo
997 997
  *     Texte sans son numéro éventuel
998 998
  **/
999 999
 function supprimer_numero(?string $texte): string {
1000
-	if ($texte === null) {
1001
-		return '';
1002
-	}
1003
-	return preg_replace(
1004
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1005
-		'',
1006
-		$texte
1007
-	);
1000
+    if ($texte === null) {
1001
+        return '';
1002
+    }
1003
+    return preg_replace(
1004
+        ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1005
+        '',
1006
+        $texte
1007
+    );
1008 1008
 }
1009 1009
 
1010 1010
 /**
@@ -1027,18 +1027,18 @@  discard block
 block discarded – undo
1027 1027
  *     Numéro de titre, sinon chaîne vide
1028 1028
  **/
1029 1029
 function recuperer_numero(?string $texte): string {
1030
-	if (
1031
-		$texte and
1032
-		preg_match(
1033
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1034
-			$texte,
1035
-			$regs
1036
-		)
1037
-	) {
1038
-		return strval($regs[1]);
1039
-	} else {
1040
-		return '';
1041
-	}
1030
+    if (
1031
+        $texte and
1032
+        preg_match(
1033
+            ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1034
+            $texte,
1035
+            $regs
1036
+        )
1037
+    ) {
1038
+        return strval($regs[1]);
1039
+    } else {
1040
+        return '';
1041
+    }
1042 1042
 }
1043 1043
 
1044 1044
 /**
@@ -1065,16 +1065,16 @@  discard block
 block discarded – undo
1065 1065
  *     texte ou tableau de textes converti
1066 1066
  **/
1067 1067
 function supprimer_tags($texte, $rempl = '') {
1068
-	if ($texte === null) {
1069
-		return '';
1070
-	}
1071
-	$texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1072
-	// ne pas oublier un < final non ferme car coupe
1073
-	$texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1074
-	// mais qui peut aussi etre un simple signe plus petit que
1075
-	$texte = str_replace('<', '&lt;', $texte);
1068
+    if ($texte === null) {
1069
+        return '';
1070
+    }
1071
+    $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1072
+    // ne pas oublier un < final non ferme car coupe
1073
+    $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1074
+    // mais qui peut aussi etre un simple signe plus petit que
1075
+    $texte = str_replace('<', '&lt;', $texte);
1076 1076
 
1077
-	return $texte;
1077
+    return $texte;
1078 1078
 }
1079 1079
 
1080 1080
 /**
@@ -1097,9 +1097,9 @@  discard block
 block discarded – undo
1097 1097
  *     texte converti
1098 1098
  **/
1099 1099
 function echapper_tags($texte, $rempl = '') {
1100
-	$texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1100
+    $texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1101 1101
 
1102
-	return $texte;
1102
+    return $texte;
1103 1103
 }
1104 1104
 
1105 1105
 /**
@@ -1120,18 +1120,18 @@  discard block
 block discarded – undo
1120 1120
  *     texte converti
1121 1121
  **/
1122 1122
 function textebrut($texte) {
1123
-	$u = $GLOBALS['meta']['pcre_u'];
1124
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1125
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1126
-	$texte = preg_replace("/^\n+/", '', $texte);
1127
-	$texte = preg_replace("/\n+$/", '', $texte);
1128
-	$texte = preg_replace("/\n +/", "\n", $texte);
1129
-	$texte = supprimer_tags($texte);
1130
-	$texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1131
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1132
-	$texte = str_replace('&#8217;', "'", $texte);
1123
+    $u = $GLOBALS['meta']['pcre_u'];
1124
+    $texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1125
+    $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1126
+    $texte = preg_replace("/^\n+/", '', $texte);
1127
+    $texte = preg_replace("/\n+$/", '', $texte);
1128
+    $texte = preg_replace("/\n +/", "\n", $texte);
1129
+    $texte = supprimer_tags($texte);
1130
+    $texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1131
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1132
+    $texte = str_replace('&#8217;', "'", $texte);
1133 1133
 
1134
-	return $texte;
1134
+    return $texte;
1135 1135
 }
1136 1136
 
1137 1137
 
@@ -1147,23 +1147,23 @@  discard block
 block discarded – undo
1147 1147
  *     texte avec liens ouvrants
1148 1148
  **/
1149 1149
 function liens_ouvrants($texte) {
1150
-	if (
1151
-		preg_match_all(
1152
-			",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1153
-			$texte,
1154
-			$liens,
1155
-			PREG_PATTERN_ORDER
1156
-		)
1157
-	) {
1158
-		foreach ($liens[0] as $a) {
1159
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1160
-			$ablank = inserer_attribut($a, 'rel', $rel);
1161
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1162
-			$texte = str_replace($a, $ablank, $texte);
1163
-		}
1164
-	}
1165
-
1166
-	return $texte;
1150
+    if (
1151
+        preg_match_all(
1152
+            ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1153
+            $texte,
1154
+            $liens,
1155
+            PREG_PATTERN_ORDER
1156
+        )
1157
+    ) {
1158
+        foreach ($liens[0] as $a) {
1159
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1160
+            $ablank = inserer_attribut($a, 'rel', $rel);
1161
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1162
+            $texte = str_replace($a, $ablank, $texte);
1163
+        }
1164
+    }
1165
+
1166
+    return $texte;
1167 1167
 }
1168 1168
 
1169 1169
 /**
@@ -1173,22 +1173,22 @@  discard block
 block discarded – undo
1173 1173
  * @return string
1174 1174
  */
1175 1175
 function liens_nofollow($texte) {
1176
-	if (stripos($texte, '<a') === false) {
1177
-		return $texte;
1178
-	}
1176
+    if (stripos($texte, '<a') === false) {
1177
+        return $texte;
1178
+    }
1179 1179
 
1180
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1181
-		foreach ($regs[0] as $a) {
1182
-			$rel = extraire_attribut($a, 'rel') ?? '';
1183
-			if (strpos($rel, 'nofollow') === false) {
1184
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1185
-				$anofollow = inserer_attribut($a, 'rel', $rel);
1186
-				$texte = str_replace($a, $anofollow, $texte);
1187
-			}
1188
-		}
1189
-	}
1180
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1181
+        foreach ($regs[0] as $a) {
1182
+            $rel = extraire_attribut($a, 'rel') ?? '';
1183
+            if (strpos($rel, 'nofollow') === false) {
1184
+                $rel = 'nofollow' . ($rel ? " $rel" : '');
1185
+                $anofollow = inserer_attribut($a, 'rel', $rel);
1186
+                $texte = str_replace($a, $anofollow, $texte);
1187
+            }
1188
+        }
1189
+    }
1190 1190
 
1191
-	return $texte;
1191
+    return $texte;
1192 1192
 }
1193 1193
 
1194 1194
 /**
@@ -1207,12 +1207,12 @@  discard block
 block discarded – undo
1207 1207
  *     texte sans paraghaphes
1208 1208
  **/
1209 1209
 function PtoBR($texte) {
1210
-	$u = $GLOBALS['meta']['pcre_u'];
1211
-	$texte = preg_replace('@</p>@iS', "\n", $texte);
1212
-	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1213
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1210
+    $u = $GLOBALS['meta']['pcre_u'];
1211
+    $texte = preg_replace('@</p>@iS', "\n", $texte);
1212
+    $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1213
+    $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1214 1214
 
1215
-	return $texte;
1215
+    return $texte;
1216 1216
 }
1217 1217
 
1218 1218
 
@@ -1237,14 +1237,14 @@  discard block
 block discarded – undo
1237 1237
  * @return string texte encadré du style CSS
1238 1238
  */
1239 1239
 function lignes_longues($texte) {
1240
-	if (!strlen(trim($texte))) {
1241
-		return $texte;
1242
-	}
1243
-	include_spip('inc/texte');
1244
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1245
-		'div' : 'span';
1240
+    if (!strlen(trim($texte))) {
1241
+        return $texte;
1242
+    }
1243
+    include_spip('inc/texte');
1244
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1245
+        'div' : 'span';
1246 1246
 
1247
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1247
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1248 1248
 }
1249 1249
 
1250 1250
 /**
@@ -1263,30 +1263,30 @@  discard block
 block discarded – undo
1263 1263
  * @return string texte en majuscule
1264 1264
  */
1265 1265
 function majuscules($texte) {
1266
-	if (!strlen($texte)) {
1267
-		return '';
1268
-	}
1266
+    if (!strlen($texte)) {
1267
+        return '';
1268
+    }
1269 1269
 
1270
-	// Cas du turc
1271
-	if ($GLOBALS['spip_lang'] == 'tr') {
1272
-		# remplacer hors des tags et des entites
1273
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1274
-			foreach ($regs as $n => $match) {
1275
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1276
-			}
1277
-		}
1270
+    // Cas du turc
1271
+    if ($GLOBALS['spip_lang'] == 'tr') {
1272
+        # remplacer hors des tags et des entites
1273
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1274
+            foreach ($regs as $n => $match) {
1275
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1276
+            }
1277
+        }
1278 1278
 
1279
-		$texte = str_replace('i', '&#304;', $texte);
1279
+        $texte = str_replace('i', '&#304;', $texte);
1280 1280
 
1281
-		if ($regs) {
1282
-			foreach ($regs as $n => $match) {
1283
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1284
-			}
1285
-		}
1286
-	}
1281
+        if ($regs) {
1282
+            foreach ($regs as $n => $match) {
1283
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1284
+            }
1285
+        }
1286
+    }
1287 1287
 
1288
-	// Cas general
1289
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1288
+    // Cas general
1289
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1290 1290
 }
1291 1291
 
1292 1292
 /**
@@ -1304,29 +1304,29 @@  discard block
 block discarded – undo
1304 1304
  * @return string
1305 1305
  **/
1306 1306
 function taille_en_octets($taille) {
1307
-	if (!defined('_KILOBYTE')) {
1308
-		/**
1309
-		 * Définit le nombre d'octets dans un Kilobyte
1310
-		 *
1311
-		 * @var int
1312
-		 **/
1313
-		define('_KILOBYTE', 1024);
1314
-	}
1307
+    if (!defined('_KILOBYTE')) {
1308
+        /**
1309
+         * Définit le nombre d'octets dans un Kilobyte
1310
+         *
1311
+         * @var int
1312
+         **/
1313
+        define('_KILOBYTE', 1024);
1314
+    }
1315 1315
 
1316
-	if ($taille < 1) {
1317
-		return '';
1318
-	}
1319
-	if ($taille < _KILOBYTE) {
1320
-		$taille = _T('taille_octets', ['taille' => $taille]);
1321
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1322
-		$taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1323
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1324
-		$taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1325
-	} else {
1326
-		$taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1327
-	}
1316
+    if ($taille < 1) {
1317
+        return '';
1318
+    }
1319
+    if ($taille < _KILOBYTE) {
1320
+        $taille = _T('taille_octets', ['taille' => $taille]);
1321
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1322
+        $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1323
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1324
+        $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1325
+    } else {
1326
+        $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1327
+    }
1328 1328
 
1329
-	return $taille;
1329
+    return $taille;
1330 1330
 }
1331 1331
 
1332 1332
 
@@ -1348,21 +1348,21 @@  discard block
 block discarded – undo
1348 1348
  *     texte prêt pour être utilisé en attribut HTML
1349 1349
  **/
1350 1350
 function attribut_html(?string $texte, $textebrut = true): string {
1351
-	if ($texte === null) {
1352
-		return '';
1353
-	}
1354
-	$u = $GLOBALS['meta']['pcre_u'];
1355
-	if ($textebrut) {
1356
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1357
-	}
1358
-	$texte = texte_backend($texte);
1359
-	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1351
+    if ($texte === null) {
1352
+        return '';
1353
+    }
1354
+    $u = $GLOBALS['meta']['pcre_u'];
1355
+    if ($textebrut) {
1356
+        $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1357
+    }
1358
+    $texte = texte_backend($texte);
1359
+    $texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1360 1360
 
1361
-	return preg_replace(
1362
-		['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1363
-		['&', '&#38;'],
1364
-		$texte
1365
-	);
1361
+    return preg_replace(
1362
+        ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1363
+        ['&', '&#38;'],
1364
+        $texte
1365
+    );
1366 1366
 }
1367 1367
 
1368 1368
 
@@ -1382,15 +1382,15 @@  discard block
 block discarded – undo
1382 1382
  *     URL ou chaîne vide
1383 1383
  **/
1384 1384
 function vider_url(?string $url, $entites = true): string {
1385
-	if ($url === null) {
1386
-		return '';
1387
-	}
1388
-	# un message pour abs_url
1389
-	$GLOBALS['mode_abs_url'] = 'url';
1390
-	$url = trim($url);
1391
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1385
+    if ($url === null) {
1386
+        return '';
1387
+    }
1388
+    # un message pour abs_url
1389
+    $GLOBALS['mode_abs_url'] = 'url';
1390
+    $url = trim($url);
1391
+    $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1392 1392
 
1393
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1393
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1394 1394
 }
1395 1395
 
1396 1396
 
@@ -1405,10 +1405,10 @@  discard block
 block discarded – undo
1405 1405
  * @return string Adresse email maquillée
1406 1406
  **/
1407 1407
 function antispam($texte) {
1408
-	include_spip('inc/acces');
1409
-	$masque = creer_pass_aleatoire(3);
1408
+    include_spip('inc/acces');
1409
+    $masque = creer_pass_aleatoire(3);
1410 1410
 
1411
-	return preg_replace('/@/', " $masque ", $texte);
1411
+    return preg_replace('/@/', " $masque ", $texte);
1412 1412
 }
1413 1413
 
1414 1414
 /**
@@ -1440,8 +1440,8 @@  discard block
 block discarded – undo
1440 1440
  *     True si on a le droit d'accès, false sinon.
1441 1441
  **/
1442 1442
 function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') {
1443
-	include_spip('inc/acces');
1444
-	return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1443
+    include_spip('inc/acces');
1444
+    return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1445 1445
 }
1446 1446
 
1447 1447
 /**
@@ -1466,13 +1466,13 @@  discard block
 block discarded – undo
1466 1466
  *     Retourne $texte, sinon $sinon.
1467 1467
  **/
1468 1468
 function sinon($texte, $sinon = '') {
1469
-	if ($texte) {
1470
-		return $texte;
1471
-	} elseif (is_scalar($texte) and strlen($texte)) {
1472
-		return $texte;
1473
-	} else {
1474
-		return $sinon;
1475
-	}
1469
+    if ($texte) {
1470
+        return $texte;
1471
+    } elseif (is_scalar($texte) and strlen($texte)) {
1472
+        return $texte;
1473
+    } else {
1474
+        return $sinon;
1475
+    }
1476 1476
 }
1477 1477
 
1478 1478
 /**
@@ -1496,7 +1496,7 @@  discard block
 block discarded – undo
1496 1496
  * @return mixed
1497 1497
  **/
1498 1498
 function choixsivide($a, $vide, $pasvide) {
1499
-	return $a ? $pasvide : $vide;
1499
+    return $a ? $pasvide : $vide;
1500 1500
 }
1501 1501
 
1502 1502
 /**
@@ -1520,7 +1520,7 @@  discard block
 block discarded – undo
1520 1520
  * @return mixed
1521 1521
  **/
1522 1522
 function choixsiegal($a1, $a2, $v, $f) {
1523
-	return ($a1 == $a2) ? $v : $f;
1523
+    return ($a1 == $a2) ? $v : $f;
1524 1524
 }
1525 1525
 
1526 1526
 //
@@ -1539,13 +1539,13 @@  discard block
 block discarded – undo
1539 1539
  * @return string
1540 1540
  **/
1541 1541
 function filtrer_ical($texte) {
1542
-	#include_spip('inc/charsets');
1543
-	$texte = html2unicode($texte);
1544
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1545
-	$texte = preg_replace("/\n/", ' ', $texte);
1546
-	$texte = preg_replace('/,/', '\,', $texte);
1542
+    #include_spip('inc/charsets');
1543
+    $texte = html2unicode($texte);
1544
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1545
+    $texte = preg_replace("/\n/", ' ', $texte);
1546
+    $texte = preg_replace('/,/', '\,', $texte);
1547 1547
 
1548
-	return $texte;
1548
+    return $texte;
1549 1549
 }
1550 1550
 
1551 1551
 
@@ -1570,58 +1570,58 @@  discard block
 block discarded – undo
1570 1570
  * @return string
1571 1571
  **/
1572 1572
 function post_autobr($texte, $delim = "\n_ ") {
1573
-	if (!function_exists('echappe_html')) {
1574
-		include_spip('inc/texte_mini');
1575
-	}
1576
-	$texte = str_replace("\r\n", "\r", $texte);
1577
-	$texte = str_replace("\r", "\n", $texte);
1578
-
1579
-	if (preg_match(",\n+$,", $texte, $fin)) {
1580
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1581
-	} else {
1582
-		$fin = '';
1583
-	}
1584
-
1585
-	$texte = echappe_html($texte, '', true);
1586
-
1587
-	// echapper les modeles
1588
-	$collecteurModeles = null;
1589
-	if (strpos($texte, '<') !== false) {
1590
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
1591
-		include_spip("src/Texte/Collecteur/Modeles");
1592
-		$collecteurModeles = new Spip\Texte\Collecteur\Modeles();
1593
-		$texte = $collecteurModeles->echapper($texte);
1594
-	}
1595
-
1596
-	$debut = '';
1597
-	$suite = $texte;
1598
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1599
-		$debut .= substr($suite, 0, $t - 1);
1600
-		$suite = substr($suite, $t);
1601
-		$car = substr($suite, 0, 1);
1602
-		if (
1603
-			($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1604
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1605
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1606
-		) {
1607
-			$debut .= $delim;
1608
-		} else {
1609
-			$debut .= "\n";
1610
-		}
1611
-		if (preg_match(",^\n+,", $suite, $regs)) {
1612
-			$debut .= $regs[0];
1613
-			$suite = substr($suite, strlen($regs[0]));
1614
-		}
1615
-	}
1616
-	$texte = $debut . $suite;
1617
-
1618
-	if ($collecteurModeles) {
1619
-		$texte = $collecteurModeles->retablir($texte);
1620
-	}
1621
-
1622
-	$texte = echappe_retour($texte);
1623
-
1624
-	return $texte . $fin;
1573
+    if (!function_exists('echappe_html')) {
1574
+        include_spip('inc/texte_mini');
1575
+    }
1576
+    $texte = str_replace("\r\n", "\r", $texte);
1577
+    $texte = str_replace("\r", "\n", $texte);
1578
+
1579
+    if (preg_match(",\n+$,", $texte, $fin)) {
1580
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1581
+    } else {
1582
+        $fin = '';
1583
+    }
1584
+
1585
+    $texte = echappe_html($texte, '', true);
1586
+
1587
+    // echapper les modeles
1588
+    $collecteurModeles = null;
1589
+    if (strpos($texte, '<') !== false) {
1590
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
1591
+        include_spip("src/Texte/Collecteur/Modeles");
1592
+        $collecteurModeles = new Spip\Texte\Collecteur\Modeles();
1593
+        $texte = $collecteurModeles->echapper($texte);
1594
+    }
1595
+
1596
+    $debut = '';
1597
+    $suite = $texte;
1598
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1599
+        $debut .= substr($suite, 0, $t - 1);
1600
+        $suite = substr($suite, $t);
1601
+        $car = substr($suite, 0, 1);
1602
+        if (
1603
+            ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1604
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1605
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1606
+        ) {
1607
+            $debut .= $delim;
1608
+        } else {
1609
+            $debut .= "\n";
1610
+        }
1611
+        if (preg_match(",^\n+,", $suite, $regs)) {
1612
+            $debut .= $regs[0];
1613
+            $suite = substr($suite, strlen($regs[0]));
1614
+        }
1615
+    }
1616
+    $texte = $debut . $suite;
1617
+
1618
+    if ($collecteurModeles) {
1619
+        $texte = $collecteurModeles->retablir($texte);
1620
+    }
1621
+
1622
+    $texte = echappe_retour($texte);
1623
+
1624
+    return $texte . $fin;
1625 1625
 }
1626 1626
 
1627 1627
 
@@ -1656,30 +1656,30 @@  discard block
 block discarded – undo
1656 1656
  **/
1657 1657
 function extraire_idiome($letexte, $lang = null, $options = []) {
1658 1658
 
1659
-	if (
1660
-		$letexte
1661
-		and strpos($letexte, '<:') !== false
1662
-	) {
1663
-		if (!$lang) {
1664
-			$lang = $GLOBALS['spip_lang'];
1665
-		}
1666
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1667
-		if (is_bool($options)) {
1668
-			$options = ['echappe_span' => $options];
1669
-		}
1670
-		if (!isset($options['echappe_span'])) {
1671
-			$options = array_merge($options, ['echappe_span' => false]);
1672
-		}
1673
-		$options['lang'] = $lang;
1659
+    if (
1660
+        $letexte
1661
+        and strpos($letexte, '<:') !== false
1662
+    ) {
1663
+        if (!$lang) {
1664
+            $lang = $GLOBALS['spip_lang'];
1665
+        }
1666
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1667
+        if (is_bool($options)) {
1668
+            $options = ['echappe_span' => $options];
1669
+        }
1670
+        if (!isset($options['echappe_span'])) {
1671
+            $options = array_merge($options, ['echappe_span' => false]);
1672
+        }
1673
+        $options['lang'] = $lang;
1674 1674
 
1675
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
1676
-		include_spip("src/Texte/Collecteur/Idiomes");
1677
-		$collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes();
1675
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
1676
+        include_spip("src/Texte/Collecteur/Idiomes");
1677
+        $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes();
1678 1678
 
1679
-		$letexte = $collecteurIdiomes->traiter($letexte, $options);
1679
+        $letexte = $collecteurIdiomes->traiter($letexte, $options);
1680 1680
 
1681
-	}
1682
-	return $letexte;
1681
+    }
1682
+    return $letexte;
1683 1683
 }
1684 1684
 
1685 1685
 /**
@@ -1717,34 +1717,34 @@  discard block
 block discarded – undo
1717 1717
  **/
1718 1718
 function extraire_multi($letexte, $lang = null, $options = []) {
1719 1719
 
1720
-	if (
1721
-		$letexte
1722
-		and stripos($letexte, '<multi') !== false
1723
-	) {
1724
-		if (!$lang) {
1725
-			$lang = $GLOBALS['spip_lang'];
1726
-		}
1720
+    if (
1721
+        $letexte
1722
+        and stripos($letexte, '<multi') !== false
1723
+    ) {
1724
+        if (!$lang) {
1725
+            $lang = $GLOBALS['spip_lang'];
1726
+        }
1727 1727
 
1728
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1729
-		if (is_bool($options)) {
1730
-			$options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1731
-		}
1732
-		if (!isset($options['echappe_span'])) {
1733
-			$options = array_merge($options, ['echappe_span' => false]);
1734
-		}
1735
-		if (!isset($options['lang_defaut'])) {
1736
-			$options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1737
-		}
1738
-		$options['lang'] = $lang;
1728
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1729
+        if (is_bool($options)) {
1730
+            $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1731
+        }
1732
+        if (!isset($options['echappe_span'])) {
1733
+            $options = array_merge($options, ['echappe_span' => false]);
1734
+        }
1735
+        if (!isset($options['lang_defaut'])) {
1736
+            $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1737
+        }
1738
+        $options['lang'] = $lang;
1739 1739
 
1740
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
1741
-		include_spip("src/Texte/Collecteur/Multis");
1742
-		$collecteurMultis = new Spip\Texte\Collecteur\Multis();
1740
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
1741
+        include_spip("src/Texte/Collecteur/Multis");
1742
+        $collecteurMultis = new Spip\Texte\Collecteur\Multis();
1743 1743
 
1744
-		$letexte = $collecteurMultis->traiter($letexte, $options);
1745
-	}
1744
+        $letexte = $collecteurMultis->traiter($letexte, $options);
1745
+    }
1746 1746
 
1747
-	return $letexte;
1747
+    return $letexte;
1748 1748
 }
1749 1749
 
1750 1750
 /**
@@ -1754,7 +1754,7 @@  discard block
 block discarded – undo
1754 1754
  * @return string L'initiale en majuscule
1755 1755
  */
1756 1756
 function filtre_initiale($nom) {
1757
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1757
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1758 1758
 }
1759 1759
 
1760 1760
 
@@ -1799,33 +1799,33 @@  discard block
 block discarded – undo
1799 1799
  *      - null (interne) : si on empile
1800 1800
  **/
1801 1801
 function unique($donnee, $famille = '', $cpt = false) {
1802
-	static $mem = [];
1803
-	// permettre de vider la pile et de la restaurer
1804
-	// pour le calcul de introduction...
1805
-	if ($famille == '_spip_raz_') {
1806
-		$tmp = $mem;
1807
-		$mem = [];
1808
-
1809
-		return $tmp;
1810
-	} elseif ($famille == '_spip_set_') {
1811
-		$mem = $donnee;
1812
-
1813
-		return;
1814
-	}
1815
-	// eviter une notice
1816
-	if (!isset($mem[$famille])) {
1817
-		$mem[$famille] = [];
1818
-	}
1819
-	if ($cpt) {
1820
-		return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1821
-	}
1822
-	// eviter une notice
1823
-	if (!isset($mem[$famille][$donnee])) {
1824
-		$mem[$famille][$donnee] = 0;
1825
-	}
1826
-	if (!($mem[$famille][$donnee]++)) {
1827
-		return $donnee;
1828
-	}
1802
+    static $mem = [];
1803
+    // permettre de vider la pile et de la restaurer
1804
+    // pour le calcul de introduction...
1805
+    if ($famille == '_spip_raz_') {
1806
+        $tmp = $mem;
1807
+        $mem = [];
1808
+
1809
+        return $tmp;
1810
+    } elseif ($famille == '_spip_set_') {
1811
+        $mem = $donnee;
1812
+
1813
+        return;
1814
+    }
1815
+    // eviter une notice
1816
+    if (!isset($mem[$famille])) {
1817
+        $mem[$famille] = [];
1818
+    }
1819
+    if ($cpt) {
1820
+        return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1821
+    }
1822
+    // eviter une notice
1823
+    if (!isset($mem[$famille][$donnee])) {
1824
+        $mem[$famille][$donnee] = 0;
1825
+    }
1826
+    if (!($mem[$famille][$donnee]++)) {
1827
+        return $donnee;
1828
+    }
1829 1829
 }
1830 1830
 
1831 1831
 
@@ -1855,20 +1855,20 @@  discard block
 block discarded – undo
1855 1855
  *     Une des valeurs en fonction du compteur.
1856 1856
  **/
1857 1857
 function alterner($i, ...$args) {
1858
-	// recuperer les arguments (attention fonctions un peu space)
1859
-	$num = count($args);
1858
+    // recuperer les arguments (attention fonctions un peu space)
1859
+    $num = count($args);
1860 1860
 
1861
-	if ($num === 1 && is_array($args[0])) {
1862
-		// un tableau de valeur dont les cles sont numerotees de 0 a num
1863
-		$args = array_values($args[0]);
1864
-		$num = count($args);
1865
-	}
1861
+    if ($num === 1 && is_array($args[0])) {
1862
+        // un tableau de valeur dont les cles sont numerotees de 0 a num
1863
+        $args = array_values($args[0]);
1864
+        $num = count($args);
1865
+    }
1866 1866
 
1867
-	// un index compris entre 0 et num exclus
1868
-	$i = ((intval($i) - 1) % $num); // dans ]-$num;$num[
1869
-	$i = ($i + $num) % $num; // dans [0;$num[
1870
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1871
-	return $args[$i];
1867
+    // un index compris entre 0 et num exclus
1868
+    $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[
1869
+    $i = ($i + $num) % $num; // dans [0;$num[
1870
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1871
+    return $args[$i];
1872 1872
 }
1873 1873
 
1874 1874
 
@@ -1894,52 +1894,52 @@  discard block
 block discarded – undo
1894 1894
  *     - null lorsque l’attribut n’existe pas.
1895 1895
  **/
1896 1896
 function extraire_attribut($balise, $attribut, $complet = false) {
1897
-	if (is_array($balise)) {
1898
-		array_walk(
1899
-			$balise,
1900
-			function (&$a, $key, $t) {
1901
-				$a = extraire_attribut($a, $t);
1902
-			},
1903
-			$attribut
1904
-		);
1905
-
1906
-		return $balise;
1907
-	}
1908
-	if (
1909
-		$balise
1910
-		&& stripos($balise, $attribut) !== false
1911
-		&& preg_match(
1912
-			',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1913
-			. $attribut
1914
-			. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1915
-			$balise,
1916
-			$r
1917
-		)
1918
-	) {
1919
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1920
-			$r[4] = substr($r[3], 1, -1);
1921
-			$r[3] = $r[3][0];
1922
-		} elseif ($r[3] !== '') {
1923
-			$r[4] = $r[3];
1924
-			$r[3] = '';
1925
-		} else {
1926
-			$r[4] = trim($r[2]);
1927
-		}
1928
-		$att = $r[4];
1929
-		if (strpos($att, '&#') !== false) {
1930
-			$att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1931
-		}
1932
-		$att = filtrer_entites($att);
1933
-	} else {
1934
-		$att = null;
1935
-		$r = [];
1936
-	}
1937
-
1938
-	if ($complet) {
1939
-		return [$att, $r];
1940
-	} else {
1941
-		return $att;
1942
-	}
1897
+    if (is_array($balise)) {
1898
+        array_walk(
1899
+            $balise,
1900
+            function (&$a, $key, $t) {
1901
+                $a = extraire_attribut($a, $t);
1902
+            },
1903
+            $attribut
1904
+        );
1905
+
1906
+        return $balise;
1907
+    }
1908
+    if (
1909
+        $balise
1910
+        && stripos($balise, $attribut) !== false
1911
+        && preg_match(
1912
+            ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1913
+            . $attribut
1914
+            . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1915
+            $balise,
1916
+            $r
1917
+        )
1918
+    ) {
1919
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1920
+            $r[4] = substr($r[3], 1, -1);
1921
+            $r[3] = $r[3][0];
1922
+        } elseif ($r[3] !== '') {
1923
+            $r[4] = $r[3];
1924
+            $r[3] = '';
1925
+        } else {
1926
+            $r[4] = trim($r[2]);
1927
+        }
1928
+        $att = $r[4];
1929
+        if (strpos($att, '&#') !== false) {
1930
+            $att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1931
+        }
1932
+        $att = filtrer_entites($att);
1933
+    } else {
1934
+        $att = null;
1935
+        $r = [];
1936
+    }
1937
+
1938
+    if ($complet) {
1939
+        return [$att, $r];
1940
+    } else {
1941
+        return $att;
1942
+    }
1943 1943
 }
1944 1944
 
1945 1945
 /**
@@ -1972,41 +1972,41 @@  discard block
 block discarded – undo
1972 1972
  **/
1973 1973
 function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string {
1974 1974
 
1975
-	if ($balise === null or $balise === '') {
1976
-		return '';
1977
-	}
1975
+    if ($balise === null or $balise === '') {
1976
+        return '';
1977
+    }
1978 1978
 
1979
-	// preparer l'attribut
1980
-	// supprimer les &nbsp; etc mais pas les balises html
1981
-	// qui ont un sens dans un attribut value d'un input
1982
-	if ($proteger) {
1983
-		$val = attribut_html($val, false);
1984
-	}
1979
+    // preparer l'attribut
1980
+    // supprimer les &nbsp; etc mais pas les balises html
1981
+    // qui ont un sens dans un attribut value d'un input
1982
+    if ($proteger) {
1983
+        $val = attribut_html($val, false);
1984
+    }
1985 1985
 
1986
-	// echapper les ' pour eviter tout bug
1987
-	$val = str_replace("'", '&#039;', $val);
1988
-	if ($vider and strlen($val) === 0) {
1989
-		$insert = '';
1990
-	} else {
1991
-		$insert = " $attribut='$val'";
1992
-	}
1986
+    // echapper les ' pour eviter tout bug
1987
+    $val = str_replace("'", '&#039;', $val);
1988
+    if ($vider and strlen($val) === 0) {
1989
+        $insert = '';
1990
+    } else {
1991
+        $insert = " $attribut='$val'";
1992
+    }
1993 1993
 
1994
-	[$old, $r] = extraire_attribut($balise, $attribut, true);
1994
+    [$old, $r] = extraire_attribut($balise, $attribut, true);
1995 1995
 
1996
-	if ($old !== null) {
1997
-		// Remplacer l'ancien attribut du meme nom
1998
-		$balise = $r[1] . $insert . $r[5];
1999
-	} else {
2000
-		// preferer une balise " />" (comme <img />)
2001
-		if (preg_match(',/>,', $balise)) {
2002
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2003
-		} // sinon une balise <a ...> ... </a>
2004
-		else {
2005
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2006
-		}
2007
-	}
1996
+    if ($old !== null) {
1997
+        // Remplacer l'ancien attribut du meme nom
1998
+        $balise = $r[1] . $insert . $r[5];
1999
+    } else {
2000
+        // preferer une balise " />" (comme <img />)
2001
+        if (preg_match(',/>,', $balise)) {
2002
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2003
+        } // sinon une balise <a ...> ... </a>
2004
+        else {
2005
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2006
+        }
2007
+    }
2008 2008
 
2009
-	return $balise;
2009
+    return $balise;
2010 2010
 }
2011 2011
 
2012 2012
 /**
@@ -2024,7 +2024,7 @@  discard block
 block discarded – undo
2024 2024
  * @return string Code HTML sans l'attribut
2025 2025
  **/
2026 2026
 function vider_attribut(?string $balise, string $attribut): string {
2027
-	return inserer_attribut($balise, $attribut, '', false, true);
2027
+    return inserer_attribut($balise, $attribut, '', false, true);
2028 2028
 }
2029 2029
 
2030 2030
 /**
@@ -2036,53 +2036,53 @@  discard block
 block discarded – undo
2036 2036
  * @return string
2037 2037
  */
2038 2038
 function modifier_class($balise, $class, $operation = 'ajouter') {
2039
-	if (is_string($class)) {
2040
-		$class = explode(' ', trim($class));
2041
-	}
2042
-	$class = array_filter($class);
2043
-	$class = array_unique($class);
2044
-	if (!$class) {
2045
-		return $balise;
2046
-	}
2047
-
2048
-	// si la ou les classes ont des caracteres invalides on ne fait rien
2049
-	if (preg_match(',[^\w-],', implode('', $class))) {
2050
-		return $balise;
2051
-	}
2052
-
2053
-	$class_courante = extraire_attribut($balise, 'class');
2054
-	$class_new = $class_courante;
2055
-	foreach ($class as $c) {
2056
-		$is_class_presente = false;
2057
-		if (
2058
-			$class_courante
2059
-			and str_contains($class_courante, (string) $c)
2060
-			and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2061
-		) {
2062
-			$is_class_presente = true;
2063
-		}
2064
-		if (
2065
-			in_array($operation, ['ajouter', 'commuter'])
2066
-			and !$is_class_presente
2067
-		) {
2068
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2069
-		} elseif (
2070
-			in_array($operation, ['supprimer', 'commuter'])
2071
-			and $is_class_presente
2072
-		) {
2073
-			$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2074
-		}
2075
-	}
2076
-
2077
-	if ($class_new !== $class_courante) {
2078
-		if (strlen($class_new)) {
2079
-			$balise = inserer_attribut($balise, 'class', $class_new);
2080
-		} elseif ($class_courante) {
2081
-			$balise = vider_attribut($balise, 'class');
2082
-		}
2083
-	}
2084
-
2085
-	return $balise;
2039
+    if (is_string($class)) {
2040
+        $class = explode(' ', trim($class));
2041
+    }
2042
+    $class = array_filter($class);
2043
+    $class = array_unique($class);
2044
+    if (!$class) {
2045
+        return $balise;
2046
+    }
2047
+
2048
+    // si la ou les classes ont des caracteres invalides on ne fait rien
2049
+    if (preg_match(',[^\w-],', implode('', $class))) {
2050
+        return $balise;
2051
+    }
2052
+
2053
+    $class_courante = extraire_attribut($balise, 'class');
2054
+    $class_new = $class_courante;
2055
+    foreach ($class as $c) {
2056
+        $is_class_presente = false;
2057
+        if (
2058
+            $class_courante
2059
+            and str_contains($class_courante, (string) $c)
2060
+            and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2061
+        ) {
2062
+            $is_class_presente = true;
2063
+        }
2064
+        if (
2065
+            in_array($operation, ['ajouter', 'commuter'])
2066
+            and !$is_class_presente
2067
+        ) {
2068
+            $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2069
+        } elseif (
2070
+            in_array($operation, ['supprimer', 'commuter'])
2071
+            and $is_class_presente
2072
+        ) {
2073
+            $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2074
+        }
2075
+    }
2076
+
2077
+    if ($class_new !== $class_courante) {
2078
+        if (strlen($class_new)) {
2079
+            $balise = inserer_attribut($balise, 'class', $class_new);
2080
+        } elseif ($class_courante) {
2081
+            $balise = vider_attribut($balise, 'class');
2082
+        }
2083
+    }
2084
+
2085
+    return $balise;
2086 2086
 }
2087 2087
 
2088 2088
 /**
@@ -2092,7 +2092,7 @@  discard block
 block discarded – undo
2092 2092
  * @return string
2093 2093
  */
2094 2094
 function ajouter_class($balise, $class) {
2095
-	return modifier_class($balise, $class, 'ajouter');
2095
+    return modifier_class($balise, $class, 'ajouter');
2096 2096
 }
2097 2097
 
2098 2098
 /**
@@ -2102,7 +2102,7 @@  discard block
 block discarded – undo
2102 2102
  * @return string
2103 2103
  */
2104 2104
 function supprimer_class($balise, $class) {
2105
-	return modifier_class($balise, $class, 'supprimer');
2105
+    return modifier_class($balise, $class, 'supprimer');
2106 2106
 }
2107 2107
 
2108 2108
 /**
@@ -2113,7 +2113,7 @@  discard block
 block discarded – undo
2113 2113
  * @return string
2114 2114
  */
2115 2115
 function commuter_class($balise, $class) {
2116
-	return modifier_class($balise, $class, 'commuter');
2116
+    return modifier_class($balise, $class, 'commuter');
2117 2117
 }
2118 2118
 
2119 2119
 /**
@@ -2124,19 +2124,19 @@  discard block
 block discarded – undo
2124 2124
  * @return string
2125 2125
  */
2126 2126
 function tester_config($id, $mode = '') {
2127
-	include_spip('action/inscrire_auteur');
2127
+    include_spip('action/inscrire_auteur');
2128 2128
 
2129
-	return tester_statut_inscription($mode, $id);
2129
+    return tester_statut_inscription($mode, $id);
2130 2130
 }
2131 2131
 
2132 2132
 //
2133 2133
 // Quelques fonctions de calcul arithmetique
2134 2134
 //
2135 2135
 function floatstr($a) {
2136
- return str_replace(',', '.', (string)floatval($a));
2136
+    return str_replace(',', '.', (string)floatval($a));
2137 2137
 }
2138 2138
 function strize($f, $a, $b) {
2139
- return floatstr($f(floatstr($a), floatstr($b)));
2139
+    return floatstr($f(floatstr($a), floatstr($b)));
2140 2140
 }
2141 2141
 
2142 2142
 /**
@@ -2155,11 +2155,11 @@  discard block
 block discarded – undo
2155 2155
  * @return int $a+$b
2156 2156
  **/
2157 2157
 function plus($a, $b) {
2158
-	return $a + $b;
2158
+    return $a + $b;
2159 2159
 }
2160 2160
 
2161 2161
 function strplus($a, $b) {
2162
-	return strize('plus', $a, $b);
2162
+    return strize('plus', $a, $b);
2163 2163
 }
2164 2164
 
2165 2165
 /**
@@ -2178,11 +2178,11 @@  discard block
 block discarded – undo
2178 2178
  * @return int $a-$b
2179 2179
  **/
2180 2180
 function moins($a, $b) {
2181
-	return $a - $b;
2181
+    return $a - $b;
2182 2182
 }
2183 2183
 
2184 2184
 function strmoins($a, $b) {
2185
-	return strize('moins', $a, $b);
2185
+    return strize('moins', $a, $b);
2186 2186
 }
2187 2187
 
2188 2188
 /**
@@ -2202,11 +2202,11 @@  discard block
 block discarded – undo
2202 2202
  * @return int $a*$b
2203 2203
  **/
2204 2204
 function mult($a, $b) {
2205
-	return $a * $b;
2205
+    return $a * $b;
2206 2206
 }
2207 2207
 
2208 2208
 function strmult($a, $b) {
2209
-	return strize('mult', $a, $b);
2209
+    return strize('mult', $a, $b);
2210 2210
 }
2211 2211
 
2212 2212
 /**
@@ -2226,11 +2226,11 @@  discard block
 block discarded – undo
2226 2226
  * @return int $a/$b (ou 0 si $b est nul)
2227 2227
  **/
2228 2228
 function div($a, $b) {
2229
-	return $b ? $a / $b : 0;
2229
+    return $b ? $a / $b : 0;
2230 2230
 }
2231 2231
 
2232 2232
 function strdiv($a, $b) {
2233
-	return strize('div', $a, $b);
2233
+    return strize('div', $a, $b);
2234 2234
 }
2235 2235
 
2236 2236
 /**
@@ -2251,7 +2251,7 @@  discard block
 block discarded – undo
2251 2251
  * @return int ($nb % $mod) + $add
2252 2252
  **/
2253 2253
 function modulo($nb, $mod, $add = 0) {
2254
-	return ($mod ? $nb % $mod : 0) + $add;
2254
+    return ($mod ? $nb % $mod : 0) + $add;
2255 2255
 }
2256 2256
 
2257 2257
 
@@ -2266,26 +2266,26 @@  discard block
 block discarded – undo
2266 2266
  *      - true sinon
2267 2267
  **/
2268 2268
 function nom_acceptable($nom) {
2269
-	$remp2 = [];
2270
-	$remp1 = [];
2271
-	if (!is_string($nom)) {
2272
-		return false;
2273
-	}
2274
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2275
-		define('_TAGS_NOM_AUTEUR', '');
2276
-	}
2277
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2278
-	foreach ($tags_acceptes as $tag) {
2279
-		if (strlen($tag)) {
2280
-			$remp1[] = '<' . trim($tag) . '>';
2281
-			$remp1[] = '</' . trim($tag) . '>';
2282
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2283
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2284
-		}
2285
-	}
2286
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2287
-
2288
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2269
+    $remp2 = [];
2270
+    $remp1 = [];
2271
+    if (!is_string($nom)) {
2272
+        return false;
2273
+    }
2274
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2275
+        define('_TAGS_NOM_AUTEUR', '');
2276
+    }
2277
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2278
+    foreach ($tags_acceptes as $tag) {
2279
+        if (strlen($tag)) {
2280
+            $remp1[] = '<' . trim($tag) . '>';
2281
+            $remp1[] = '</' . trim($tag) . '>';
2282
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2283
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2284
+        }
2285
+    }
2286
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2287
+
2288
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2289 2289
 }
2290 2290
 
2291 2291
 
@@ -2301,14 +2301,14 @@  discard block
 block discarded – undo
2301 2301
  *      - renvoie un tableau si l'entree est un tableau
2302 2302
  **/
2303 2303
 function email_valide($adresses) {
2304
-	if (is_array($adresses)) {
2305
-		$adresses = array_map('email_valide', $adresses);
2306
-		$adresses = array_filter($adresses);
2307
-		return $adresses;
2308
-	}
2304
+    if (is_array($adresses)) {
2305
+        $adresses = array_map('email_valide', $adresses);
2306
+        $adresses = array_filter($adresses);
2307
+        return $adresses;
2308
+    }
2309 2309
 
2310
-	$email_valide = charger_fonction('email_valide', 'inc');
2311
-	return $email_valide($adresses);
2310
+    $email_valide = charger_fonction('email_valide', 'inc');
2311
+    return $email_valide($adresses);
2312 2312
 }
2313 2313
 
2314 2314
 /**
@@ -2322,29 +2322,29 @@  discard block
 block discarded – undo
2322 2322
  * @return string texte
2323 2323
  **/
2324 2324
 function afficher_enclosures($tags) {
2325
-	$s = [];
2326
-	foreach (extraire_balises($tags, 'a') as $tag) {
2327
-		if (
2328
-			extraire_attribut($tag, 'rel') == 'enclosure'
2329
-			and $t = extraire_attribut($tag, 'href')
2330
-		) {
2331
-			$s[] = preg_replace(
2332
-				',>[^<]+</a>,S',
2333
-				'>'
2334
-				. http_img_pack(
2335
-					'attachment-16.png',
2336
-					$t,
2337
-					'',
2338
-					$t,
2339
-					['utiliser_suffixe_size' => true]
2340
-				)
2341
-				. '</a>',
2342
-				$tag
2343
-			);
2344
-		}
2345
-	}
2346
-
2347
-	return join('&nbsp;', $s);
2325
+    $s = [];
2326
+    foreach (extraire_balises($tags, 'a') as $tag) {
2327
+        if (
2328
+            extraire_attribut($tag, 'rel') == 'enclosure'
2329
+            and $t = extraire_attribut($tag, 'href')
2330
+        ) {
2331
+            $s[] = preg_replace(
2332
+                ',>[^<]+</a>,S',
2333
+                '>'
2334
+                . http_img_pack(
2335
+                    'attachment-16.png',
2336
+                    $t,
2337
+                    '',
2338
+                    $t,
2339
+                    ['utiliser_suffixe_size' => true]
2340
+                )
2341
+                . '</a>',
2342
+                $tag
2343
+            );
2344
+        }
2345
+    }
2346
+
2347
+    return join('&nbsp;', $s);
2348 2348
 }
2349 2349
 
2350 2350
 /**
@@ -2359,15 +2359,15 @@  discard block
 block discarded – undo
2359 2359
  * @return string Liens trouvés
2360 2360
  **/
2361 2361
 function afficher_tags($tags, $rels = 'tag,directory') {
2362
-	$s = [];
2363
-	foreach (extraire_balises($tags, 'a') as $tag) {
2364
-		$rel = extraire_attribut($tag, 'rel');
2365
-		if (strstr(",$rels,", (string) ",$rel,")) {
2366
-			$s[] = $tag;
2367
-		}
2368
-	}
2362
+    $s = [];
2363
+    foreach (extraire_balises($tags, 'a') as $tag) {
2364
+        $rel = extraire_attribut($tag, 'rel');
2365
+        if (strstr(",$rels,", (string) ",$rel,")) {
2366
+            $s[] = $tag;
2367
+        }
2368
+    }
2369 2369
 
2370
-	return join(', ', $s);
2370
+    return join(', ', $s);
2371 2371
 }
2372 2372
 
2373 2373
 
@@ -2389,21 +2389,21 @@  discard block
 block discarded – undo
2389 2389
  * @return string Tag HTML `<a>` avec microformat.
2390 2390
  **/
2391 2391
 function enclosure2microformat($e) {
2392
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) {
2393
-		$url = filtrer_entites(extraire_attribut($e, 'href') ?? '');
2394
-	}
2395
-	$type = extraire_attribut($e, 'type');
2396
-	if (!$length = extraire_attribut($e, 'length')) {
2397
-		# <media:content : longeur dans fileSize. On tente.
2398
-		$length = extraire_attribut($e, 'fileSize');
2399
-	}
2400
-	$fichier = basename($url);
2392
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) {
2393
+        $url = filtrer_entites(extraire_attribut($e, 'href') ?? '');
2394
+    }
2395
+    $type = extraire_attribut($e, 'type');
2396
+    if (!$length = extraire_attribut($e, 'length')) {
2397
+        # <media:content : longeur dans fileSize. On tente.
2398
+        $length = extraire_attribut($e, 'fileSize');
2399
+    }
2400
+    $fichier = basename($url);
2401 2401
 
2402
-	return '<a rel="enclosure"'
2403
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2404
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2405
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2406
-	. '>' . $fichier . '</a>';
2402
+    return '<a rel="enclosure"'
2403
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2404
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2405
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2406
+    . '>' . $fichier . '</a>';
2407 2407
 }
2408 2408
 
2409 2409
 /**
@@ -2421,24 +2421,24 @@  discard block
 block discarded – undo
2421 2421
  * @return string Tags RSS `<enclosure>`.
2422 2422
  **/
2423 2423
 function microformat2enclosure($tags) {
2424
-	$enclosures = [];
2425
-	foreach (extraire_balises($tags, 'a') as $e) {
2426
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2427
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2428
-			$type = extraire_attribut($e, 'type');
2429
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2430
-				$length = intval(extraire_attribut($e, 'length'));
2431
-			} # vieux data
2432
-			$fichier = basename($url);
2433
-			$enclosures[] = '<enclosure'
2434
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2435
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2436
-				. ($length ? ' length="' . $length . '"' : '')
2437
-				. ' />';
2438
-		}
2439
-	}
2424
+    $enclosures = [];
2425
+    foreach (extraire_balises($tags, 'a') as $e) {
2426
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2427
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2428
+            $type = extraire_attribut($e, 'type');
2429
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2430
+                $length = intval(extraire_attribut($e, 'length'));
2431
+            } # vieux data
2432
+            $fichier = basename($url);
2433
+            $enclosures[] = '<enclosure'
2434
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2435
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2436
+                . ($length ? ' length="' . $length . '"' : '')
2437
+                . ' />';
2438
+        }
2439
+    }
2440 2440
 
2441
-	return join("\n", $enclosures);
2441
+    return join("\n", $enclosures);
2442 2442
 }
2443 2443
 
2444 2444
 
@@ -2454,16 +2454,16 @@  discard block
 block discarded – undo
2454 2454
  * @return string Tags RSS Atom `<dc:subject>`.
2455 2455
  **/
2456 2456
 function tags2dcsubject($tags) {
2457
-	$subjects = '';
2458
-	foreach (extraire_balises($tags, 'a') as $e) {
2459
-		if (extraire_attribut($e, 'rel') == 'tag') {
2460
-			$subjects .= '<dc:subject>'
2461
-				. texte_backend(textebrut($e))
2462
-				. '</dc:subject>' . "\n";
2463
-		}
2464
-	}
2457
+    $subjects = '';
2458
+    foreach (extraire_balises($tags, 'a') as $e) {
2459
+        if (extraire_attribut($e, 'rel') == 'tag') {
2460
+            $subjects .= '<dc:subject>'
2461
+                . texte_backend(textebrut($e))
2462
+                . '</dc:subject>' . "\n";
2463
+        }
2464
+    }
2465 2465
 
2466
-	return $subjects;
2466
+    return $subjects;
2467 2467
 }
2468 2468
 
2469 2469
 /**
@@ -2492,27 +2492,27 @@  discard block
 block discarded – undo
2492 2492
  *     - Tableau de résultats, si tableau en entrée.
2493 2493
  **/
2494 2494
 function extraire_balise($texte, $tag = 'a') {
2495
-	if (is_array($texte)) {
2496
-		array_walk(
2497
-			$texte,
2498
-			function (&$a, $key, $t) {
2499
-				$a = extraire_balise($a, $t);
2500
-			},
2501
-			$tag
2502
-		);
2503
-
2504
-		return $texte;
2505
-	}
2506
-
2507
-	if (
2508
-		preg_match(
2509
-			",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2510
-			$texte,
2511
-			$regs
2512
-		)
2513
-	) {
2514
-		return $regs[0];
2515
-	}
2495
+    if (is_array($texte)) {
2496
+        array_walk(
2497
+            $texte,
2498
+            function (&$a, $key, $t) {
2499
+                $a = extraire_balise($a, $t);
2500
+            },
2501
+            $tag
2502
+        );
2503
+
2504
+        return $texte;
2505
+    }
2506
+
2507
+    if (
2508
+        preg_match(
2509
+            ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2510
+            $texte,
2511
+            $regs
2512
+        )
2513
+    ) {
2514
+        return $regs[0];
2515
+    }
2516 2516
 }
2517 2517
 
2518 2518
 /**
@@ -2540,30 +2540,30 @@  discard block
 block discarded – undo
2540 2540
  *     - Tableau de résultats, si tableau en entrée.
2541 2541
  **/
2542 2542
 function extraire_balises($texte, $tag = 'a') {
2543
-	if (is_array($texte)) {
2544
-		array_walk(
2545
-			$texte,
2546
-			function (&$a, $key, $t) {
2547
-				$a = extraire_balises($a, $t);
2548
-			},
2549
-			$tag
2550
-		);
2551
-
2552
-		return $texte;
2553
-	}
2554
-
2555
-	if (
2556
-		preg_match_all(
2557
-			",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS",
2558
-			$texte,
2559
-			$regs,
2560
-			PREG_PATTERN_ORDER
2561
-		)
2562
-	) {
2563
-		return $regs[0];
2564
-	} else {
2565
-		return [];
2566
-	}
2543
+    if (is_array($texte)) {
2544
+        array_walk(
2545
+            $texte,
2546
+            function (&$a, $key, $t) {
2547
+                $a = extraire_balises($a, $t);
2548
+            },
2549
+            $tag
2550
+        );
2551
+
2552
+        return $texte;
2553
+    }
2554
+
2555
+    if (
2556
+        preg_match_all(
2557
+            ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS",
2558
+            $texte,
2559
+            $regs,
2560
+            PREG_PATTERN_ORDER
2561
+        )
2562
+    ) {
2563
+        return $regs[0];
2564
+    } else {
2565
+        return [];
2566
+    }
2567 2567
 }
2568 2568
 
2569 2569
 /**
@@ -2592,11 +2592,11 @@  discard block
 block discarded – undo
2592 2592
  *     - `$def` si on n'a pas transmis de tableau
2593 2593
  **/
2594 2594
 function in_any($val, $vals, $def = '') {
2595
-	if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2596
-		$vals = $v;
2597
-	}
2595
+    if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2596
+        $vals = $v;
2597
+    }
2598 2598
 
2599
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2599
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2600 2600
 }
2601 2601
 
2602 2602
 
@@ -2617,12 +2617,12 @@  discard block
 block discarded – undo
2617 2617
  *     Résultat du calcul
2618 2618
  **/
2619 2619
 function valeur_numerique($expr) {
2620
-	$a = 0;
2621
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2622
-		eval("\$a = $expr;");
2623
-	}
2620
+    $a = 0;
2621
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2622
+        eval("\$a = $expr;");
2623
+    }
2624 2624
 
2625
-	return intval($a);
2625
+    return intval($a);
2626 2626
 }
2627 2627
 
2628 2628
 /**
@@ -2641,7 +2641,7 @@  discard block
 block discarded – undo
2641 2641
  *      Retourne `$a*$b/$c`
2642 2642
  **/
2643 2643
 function regledetrois($a, $b, $c) {
2644
-	return round($a * $b / $c);
2644
+    return round($a * $b / $c);
2645 2645
 }
2646 2646
 
2647 2647
 
@@ -2664,79 +2664,79 @@  discard block
 block discarded – undo
2664 2664
  * @return string Suite de champs input hidden
2665 2665
  **/
2666 2666
 function form_hidden(?string $action = ''): string {
2667
-	$action ??= '';
2668
-
2669
-	$contexte = [];
2670
-	include_spip('inc/urls');
2671
-	if (
2672
-		$p = urls_decoder_url($action, '')
2673
-		and reset($p)
2674
-	) {
2675
-		$fond = array_shift($p);
2676
-		if ($fond != '404') {
2677
-			$contexte = array_shift($p);
2678
-			$contexte['page'] = $fond;
2679
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2680
-		}
2681
-	}
2682
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2683
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2684
-		unset($contexte['type']);
2685
-	}
2686
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2687
-		unset($contexte['type-page']);
2688
-	}
2689
-
2690
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2691
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2692
-	$values = [];
2693
-
2694
-	// d'abord avec celles de l'url
2695
-	if (false !== ($p = strpos($action, '?'))) {
2696
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2697
-			$c = explode('=', $c, 2);
2698
-			$var = array_shift($c);
2699
-			$val = array_shift($c) ?? '';
2700
-			if ($var) {
2701
-				$val = rawurldecode($val);
2702
-				$var = rawurldecode($var); // decoder les [] eventuels
2703
-				if (preg_match(',\[\]$,S', $var)) {
2704
-					$values[] = [$var, $val];
2705
-				} else {
2706
-					if (!isset($values[$var])) {
2707
-						$values[$var] = [$var, $val];
2708
-					}
2709
-				}
2710
-			}
2711
-		}
2712
-	}
2713
-
2714
-	// ensuite avec celles du contexte, sans doublonner !
2715
-	foreach ($contexte as $var => $val) {
2716
-		if (preg_match(',\[\]$,S', $var)) {
2717
-			$values[] = [$var, $val];
2718
-		} else {
2719
-			if (!isset($values[$var])) {
2720
-				$values[$var] = [$var, $val];
2721
-			}
2722
-		}
2723
-	}
2724
-
2725
-	// puis on rassemble le tout
2726
-	$hidden = [];
2727
-	foreach ($values as $value) {
2728
-		[$var, $val] = $value;
2729
-		$hidden[] = '<input name="'
2730
-			. entites_html($var)
2731
-			. '"'
2732
-			. (is_null($val)
2733
-				? ''
2734
-				: ' value="' . entites_html($val) . '"'
2735
-			)
2736
-			. ' type="hidden"' . "\n/>";
2737
-	}
2738
-
2739
-	return join('', $hidden);
2667
+    $action ??= '';
2668
+
2669
+    $contexte = [];
2670
+    include_spip('inc/urls');
2671
+    if (
2672
+        $p = urls_decoder_url($action, '')
2673
+        and reset($p)
2674
+    ) {
2675
+        $fond = array_shift($p);
2676
+        if ($fond != '404') {
2677
+            $contexte = array_shift($p);
2678
+            $contexte['page'] = $fond;
2679
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2680
+        }
2681
+    }
2682
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2683
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2684
+        unset($contexte['type']);
2685
+    }
2686
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2687
+        unset($contexte['type-page']);
2688
+    }
2689
+
2690
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2691
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2692
+    $values = [];
2693
+
2694
+    // d'abord avec celles de l'url
2695
+    if (false !== ($p = strpos($action, '?'))) {
2696
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2697
+            $c = explode('=', $c, 2);
2698
+            $var = array_shift($c);
2699
+            $val = array_shift($c) ?? '';
2700
+            if ($var) {
2701
+                $val = rawurldecode($val);
2702
+                $var = rawurldecode($var); // decoder les [] eventuels
2703
+                if (preg_match(',\[\]$,S', $var)) {
2704
+                    $values[] = [$var, $val];
2705
+                } else {
2706
+                    if (!isset($values[$var])) {
2707
+                        $values[$var] = [$var, $val];
2708
+                    }
2709
+                }
2710
+            }
2711
+        }
2712
+    }
2713
+
2714
+    // ensuite avec celles du contexte, sans doublonner !
2715
+    foreach ($contexte as $var => $val) {
2716
+        if (preg_match(',\[\]$,S', $var)) {
2717
+            $values[] = [$var, $val];
2718
+        } else {
2719
+            if (!isset($values[$var])) {
2720
+                $values[$var] = [$var, $val];
2721
+            }
2722
+        }
2723
+    }
2724
+
2725
+    // puis on rassemble le tout
2726
+    $hidden = [];
2727
+    foreach ($values as $value) {
2728
+        [$var, $val] = $value;
2729
+        $hidden[] = '<input name="'
2730
+            . entites_html($var)
2731
+            . '"'
2732
+            . (is_null($val)
2733
+                ? ''
2734
+                : ' value="' . entites_html($val) . '"'
2735
+            )
2736
+            . ' type="hidden"' . "\n/>";
2737
+    }
2738
+
2739
+    return join('', $hidden);
2740 2740
 }
2741 2741
 
2742 2742
 
@@ -2758,7 +2758,7 @@  discard block
 block discarded – undo
2758 2758
  *    - la première valeur du tableau sinon.
2759 2759
  **/
2760 2760
 function filtre_reset($array) {
2761
-	return !is_array($array) ? null : reset($array);
2761
+    return !is_array($array) ? null : reset($array);
2762 2762
 }
2763 2763
 
2764 2764
 /**
@@ -2779,7 +2779,7 @@  discard block
 block discarded – undo
2779 2779
  *    - la dernière valeur du tableau sinon.
2780 2780
  **/
2781 2781
 function filtre_end($array) {
2782
-	return !is_array($array) ? null : end($array);
2782
+    return !is_array($array) ? null : end($array);
2783 2783
 }
2784 2784
 
2785 2785
 /**
@@ -2799,11 +2799,11 @@  discard block
 block discarded – undo
2799 2799
  *
2800 2800
  **/
2801 2801
 function filtre_push($array, $val) {
2802
-	if (!is_array($array) or !array_push($array, $val)) {
2803
-		return '';
2804
-	}
2802
+    if (!is_array($array) or !array_push($array, $val)) {
2803
+        return '';
2804
+    }
2805 2805
 
2806
-	return $array;
2806
+    return $array;
2807 2807
 }
2808 2808
 
2809 2809
 /**
@@ -2822,7 +2822,7 @@  discard block
 block discarded – undo
2822 2822
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2823 2823
  **/
2824 2824
 function filtre_find($array, $val) {
2825
-	return (is_array($array) and in_array($val, $array));
2825
+    return (is_array($array) and in_array($val, $array));
2826 2826
 }
2827 2827
 
2828 2828
 
@@ -2839,13 +2839,13 @@  discard block
 block discarded – undo
2839 2839
  *     Contenu avec urls en absolus
2840 2840
  **/
2841 2841
 function urls_absolues_css($contenu, $source) {
2842
-	$path = suivre_lien(url_absolue($source), './');
2842
+    $path = suivre_lien(url_absolue($source), './');
2843 2843
 
2844
-	return preg_replace_callback(
2845
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2846
-		fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2847
-		$contenu
2848
-	);
2844
+    return preg_replace_callback(
2845
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2846
+        fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2847
+        $contenu
2848
+    );
2849 2849
 }
2850 2850
 
2851 2851
 
@@ -2874,119 +2874,119 @@  discard block
 block discarded – undo
2874 2874
  *     Chemin du fichier CSS inversé
2875 2875
  **/
2876 2876
 function direction_css($css, $voulue = '') {
2877
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2878
-		return $css;
2879
-	}
2880
-	include_spip('inc/lang');
2881
-	// si on a precise le sens voulu en argument, le prendre en compte
2882
-	if ($voulue = strtolower($voulue)) {
2883
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2884
-			$voulue = lang_dir($voulue);
2885
-		}
2886
-	} else {
2887
-		$voulue = lang_dir();
2888
-	}
2889
-
2890
-	$r = count($r) > 1;
2891
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2892
-	$dir = $r ? 'rtl' : 'ltr';
2893
-	$ndir = $r ? 'ltr' : 'rtl';
2894
-
2895
-	if ($voulue == $dir) {
2896
-		return $css;
2897
-	}
2898
-
2899
-	if (
2900
-		// url absolue
2901
-		preg_match(',^https?:,i', $css)
2902
-		// ou qui contient un ?
2903
-		or (($p = strpos($css, '?')) !== false)
2904
-	) {
2905
-		$distant = true;
2906
-		$cssf = parse_url($css);
2907
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2908
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2909
-	} else {
2910
-		$distant = false;
2911
-		$cssf = $css;
2912
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2913
-		//propose (rien a faire dans ce cas)
2914
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2915
-		if (@file_exists($f)) {
2916
-			return $f;
2917
-		}
2918
-	}
2919
-
2920
-	// 2.
2921
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2922
-	$f = $dir_var
2923
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2924
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2925
-
2926
-	// la css peut etre distante (url absolue !)
2927
-	if ($distant) {
2928
-		include_spip('inc/distant');
2929
-		$res = recuperer_url($css);
2930
-		if (!$res or !$contenu = $res['page']) {
2931
-			return $css;
2932
-		}
2933
-	} else {
2934
-		if (
2935
-			(@filemtime($f) > @filemtime($css))
2936
-			and (_VAR_MODE != 'recalcul')
2937
-		) {
2938
-			return $f;
2939
-		}
2940
-		if (!lire_fichier($css, $contenu)) {
2941
-			return $css;
2942
-		}
2943
-	}
2944
-
2945
-
2946
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2947
-	include_spip('lib/csstidy/class.csstidy');
2948
-	$parser = new csstidy();
2949
-	$parser->set_cfg('optimise_shorthands', 0);
2950
-	$parser->set_cfg('reverse_left_and_right', true);
2951
-	$parser->parse($contenu);
2952
-
2953
-	$contenu = $parser->print->plain();
2954
-
2955
-
2956
-	// reperer les @import auxquels il faut propager le direction_css
2957
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2958
-	$src = [];
2959
-	$src_direction_css = [];
2960
-	$src_faux_abs = [];
2961
-	$d = dirname($css);
2962
-	foreach ($regs[1] as $k => $import_css) {
2963
-		$css_direction = direction_css("$d/$import_css", $voulue);
2964
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2965
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2966
-			$css_direction = substr($css_direction, strlen($d) + 1);
2967
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2968
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2969
-			$css_direction = substr($css_direction, strlen($dir_var));
2970
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
2971
-			$css_direction = '/@@@@@@/' . $css_direction;
2972
-		}
2973
-		$src[] = $regs[0][$k];
2974
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2975
-	}
2976
-	$contenu = str_replace($src, $src_direction_css, $contenu);
2977
-
2978
-	$contenu = urls_absolues_css($contenu, $css);
2979
-
2980
-	// virer les fausses url absolues que l'on a mis dans les import
2981
-	if (count($src_faux_abs)) {
2982
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2983
-	}
2984
-
2985
-	if (!ecrire_fichier($f, $contenu)) {
2986
-		return $css;
2987
-	}
2988
-
2989
-	return $f;
2877
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2878
+        return $css;
2879
+    }
2880
+    include_spip('inc/lang');
2881
+    // si on a precise le sens voulu en argument, le prendre en compte
2882
+    if ($voulue = strtolower($voulue)) {
2883
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2884
+            $voulue = lang_dir($voulue);
2885
+        }
2886
+    } else {
2887
+        $voulue = lang_dir();
2888
+    }
2889
+
2890
+    $r = count($r) > 1;
2891
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2892
+    $dir = $r ? 'rtl' : 'ltr';
2893
+    $ndir = $r ? 'ltr' : 'rtl';
2894
+
2895
+    if ($voulue == $dir) {
2896
+        return $css;
2897
+    }
2898
+
2899
+    if (
2900
+        // url absolue
2901
+        preg_match(',^https?:,i', $css)
2902
+        // ou qui contient un ?
2903
+        or (($p = strpos($css, '?')) !== false)
2904
+    ) {
2905
+        $distant = true;
2906
+        $cssf = parse_url($css);
2907
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2908
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
2909
+    } else {
2910
+        $distant = false;
2911
+        $cssf = $css;
2912
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2913
+        //propose (rien a faire dans ce cas)
2914
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2915
+        if (@file_exists($f)) {
2916
+            return $f;
2917
+        }
2918
+    }
2919
+
2920
+    // 2.
2921
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2922
+    $f = $dir_var
2923
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2924
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2925
+
2926
+    // la css peut etre distante (url absolue !)
2927
+    if ($distant) {
2928
+        include_spip('inc/distant');
2929
+        $res = recuperer_url($css);
2930
+        if (!$res or !$contenu = $res['page']) {
2931
+            return $css;
2932
+        }
2933
+    } else {
2934
+        if (
2935
+            (@filemtime($f) > @filemtime($css))
2936
+            and (_VAR_MODE != 'recalcul')
2937
+        ) {
2938
+            return $f;
2939
+        }
2940
+        if (!lire_fichier($css, $contenu)) {
2941
+            return $css;
2942
+        }
2943
+    }
2944
+
2945
+
2946
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2947
+    include_spip('lib/csstidy/class.csstidy');
2948
+    $parser = new csstidy();
2949
+    $parser->set_cfg('optimise_shorthands', 0);
2950
+    $parser->set_cfg('reverse_left_and_right', true);
2951
+    $parser->parse($contenu);
2952
+
2953
+    $contenu = $parser->print->plain();
2954
+
2955
+
2956
+    // reperer les @import auxquels il faut propager le direction_css
2957
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2958
+    $src = [];
2959
+    $src_direction_css = [];
2960
+    $src_faux_abs = [];
2961
+    $d = dirname($css);
2962
+    foreach ($regs[1] as $k => $import_css) {
2963
+        $css_direction = direction_css("$d/$import_css", $voulue);
2964
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2965
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2966
+            $css_direction = substr($css_direction, strlen($d) + 1);
2967
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
2968
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2969
+            $css_direction = substr($css_direction, strlen($dir_var));
2970
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
2971
+            $css_direction = '/@@@@@@/' . $css_direction;
2972
+        }
2973
+        $src[] = $regs[0][$k];
2974
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2975
+    }
2976
+    $contenu = str_replace($src, $src_direction_css, $contenu);
2977
+
2978
+    $contenu = urls_absolues_css($contenu, $css);
2979
+
2980
+    // virer les fausses url absolues que l'on a mis dans les import
2981
+    if (count($src_faux_abs)) {
2982
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2983
+    }
2984
+
2985
+    if (!ecrire_fichier($f, $contenu)) {
2986
+        return $css;
2987
+    }
2988
+
2989
+    return $f;
2990 2990
 }
2991 2991
 
2992 2992
 
@@ -3009,46 +3009,46 @@  discard block
 block discarded – undo
3009 3009
  *     - Chemin ou URL du fichier CSS source sinon.
3010 3010
  **/
3011 3011
 function url_absolue_css($css) {
3012
-	if (!preg_match(',\.css$,i', $css, $r)) {
3013
-		return $css;
3014
-	}
3012
+    if (!preg_match(',\.css$,i', $css, $r)) {
3013
+        return $css;
3014
+    }
3015 3015
 
3016
-	$url_absolue_css = url_absolue($css);
3016
+    $url_absolue_css = url_absolue($css);
3017 3017
 
3018
-	$f = basename($css, '.css');
3019
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3020
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3021
-		. '.css';
3018
+    $f = basename($css, '.css');
3019
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3020
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3021
+        . '.css';
3022 3022
 
3023
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3024
-		return $f;
3025
-	}
3023
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3024
+        return $f;
3025
+    }
3026 3026
 
3027
-	if ($url_absolue_css == $css) {
3028
-		if (
3029
-			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3030
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3031
-		) {
3032
-			include_spip('inc/distant');
3033
-			$contenu = recuperer_url($css);
3034
-			$contenu = $contenu['page'] ?? '';
3035
-			if (!$contenu) {
3036
-				return $css;
3037
-			}
3038
-		}
3039
-	} elseif (!lire_fichier($css, $contenu)) {
3040
-		return $css;
3041
-	}
3027
+    if ($url_absolue_css == $css) {
3028
+        if (
3029
+            strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3030
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3031
+        ) {
3032
+            include_spip('inc/distant');
3033
+            $contenu = recuperer_url($css);
3034
+            $contenu = $contenu['page'] ?? '';
3035
+            if (!$contenu) {
3036
+                return $css;
3037
+            }
3038
+        }
3039
+    } elseif (!lire_fichier($css, $contenu)) {
3040
+        return $css;
3041
+    }
3042 3042
 
3043
-	// passer les url relatives a la css d'origine en url absolues
3044
-	$contenu = urls_absolues_css($contenu, $css);
3043
+    // passer les url relatives a la css d'origine en url absolues
3044
+    $contenu = urls_absolues_css($contenu, $css);
3045 3045
 
3046
-	// ecrire la css
3047
-	if (!ecrire_fichier($f, $contenu)) {
3048
-		return $css;
3049
-	}
3046
+    // ecrire la css
3047
+    if (!ecrire_fichier($f, $contenu)) {
3048
+        return $css;
3049
+    }
3050 3050
 
3051
-	return $f;
3051
+    return $f;
3052 3052
 }
3053 3053
 
3054 3054
 
@@ -3082,24 +3082,24 @@  discard block
 block discarded – undo
3082 3082
  *     Valeur trouvée ou valeur par défaut.
3083 3083
  **/
3084 3084
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3085
-	foreach (explode('/', $cle) as $k) {
3086
-		$table = (is_string($table) ? @unserialize($table) : $table);
3085
+    foreach (explode('/', $cle) as $k) {
3086
+        $table = (is_string($table) ? @unserialize($table) : $table);
3087 3087
 
3088
-		if (is_object($table)) {
3089
-			$table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3090
-		} elseif (is_array($table)) {
3091
-			if ($conserver_null) {
3092
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3093
-			} else {
3094
-				$table = ($table[$k] ?? $defaut);
3095
-			}
3096
-		} else {
3097
-			$table = $defaut;
3098
-			break;
3099
-		}
3100
-	}
3088
+        if (is_object($table)) {
3089
+            $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3090
+        } elseif (is_array($table)) {
3091
+            if ($conserver_null) {
3092
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3093
+            } else {
3094
+                $table = ($table[$k] ?? $defaut);
3095
+            }
3096
+        } else {
3097
+            $table = $defaut;
3098
+            break;
3099
+        }
3100
+    }
3101 3101
 
3102
-	return $table;
3102
+    return $table;
3103 3103
 }
3104 3104
 
3105 3105
 /**
@@ -3132,22 +3132,22 @@  discard block
 block discarded – undo
3132 3132
  *     - string : expression trouvée.
3133 3133
  **/
3134 3134
 function filtre_match_dist(?string $texte, $expression, $modif = 'UuimsS', $capte = 0) {
3135
-	if (intval($modif) and $capte == 0) {
3136
-		$capte = $modif;
3137
-		$modif = 'UuimsS';
3138
-	}
3139
-	$expression = str_replace('\/', '/', $expression);
3140
-	$expression = str_replace('/', '\/', $expression);
3135
+    if (intval($modif) and $capte == 0) {
3136
+        $capte = $modif;
3137
+        $modif = 'UuimsS';
3138
+    }
3139
+    $expression = str_replace('\/', '/', $expression);
3140
+    $expression = str_replace('/', '\/', $expression);
3141 3141
 
3142
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3143
-		if (isset($r[$capte])) {
3144
-			return $r[$capte];
3145
-		} else {
3146
-			return true;
3147
-		}
3148
-	}
3142
+    if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3143
+        if (isset($r[$capte])) {
3144
+            return $r[$capte];
3145
+        } else {
3146
+            return true;
3147
+        }
3148
+    }
3149 3149
 
3150
-	return false;
3150
+    return false;
3151 3151
 }
3152 3152
 
3153 3153
 
@@ -3174,10 +3174,10 @@  discard block
 block discarded – undo
3174 3174
  *     texte
3175 3175
  **/
3176 3176
 function replace($texte, $expression, $replace = '', $modif = 'UimsS') {
3177
-	$expression = str_replace('\/', '/', $expression);
3178
-	$expression = str_replace('/', '\/', $expression);
3177
+    $expression = str_replace('\/', '/', $expression);
3178
+    $expression = str_replace('/', '\/', $expression);
3179 3179
 
3180
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3180
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3181 3181
 }
3182 3182
 
3183 3183
 
@@ -3195,25 +3195,25 @@  discard block
 block discarded – undo
3195 3195
  **/
3196 3196
 function traiter_doublons_documents(&$doublons, $letexte) {
3197 3197
 
3198
-	// Verifier dans le texte & les notes (pas beau, helas)
3199
-	$t = $letexte . $GLOBALS['les_notes'];
3198
+    // Verifier dans le texte & les notes (pas beau, helas)
3199
+    $t = $letexte . $GLOBALS['les_notes'];
3200 3200
 
3201
-	if (
3202
-		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3203
-		and preg_match_all(
3204
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3205
-			$t,
3206
-			$matches,
3207
-			PREG_PATTERN_ORDER
3208
-		)
3209
-	) {
3210
-		if (!isset($doublons['documents'])) {
3211
-			$doublons['documents'] = '';
3212
-		}
3213
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3214
-	}
3201
+    if (
3202
+        strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3203
+        and preg_match_all(
3204
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3205
+            $t,
3206
+            $matches,
3207
+            PREG_PATTERN_ORDER
3208
+        )
3209
+    ) {
3210
+        if (!isset($doublons['documents'])) {
3211
+            $doublons['documents'] = '';
3212
+        }
3213
+        $doublons['documents'] .= ',' . join(',', $matches[1]);
3214
+    }
3215 3215
 
3216
-	return $letexte;
3216
+    return $letexte;
3217 3217
 }
3218 3218
 
3219 3219
 /**
@@ -3227,7 +3227,7 @@  discard block
 block discarded – undo
3227 3227
  * @return string Chaîne vide
3228 3228
  **/
3229 3229
 function vide($texte) {
3230
-	return '';
3230
+    return '';
3231 3231
 }
3232 3232
 
3233 3233
 //
@@ -3256,23 +3256,23 @@  discard block
 block discarded – undo
3256 3256
  *      Code HTML résultant
3257 3257
  **/
3258 3258
 function env_to_params($env, $ignore_params = []) {
3259
-	$ignore_params = array_merge(
3260
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3261
-		$ignore_params
3262
-	);
3263
-	if (!is_array($env)) {
3264
-		$env = unserialize($env);
3265
-	}
3266
-	$texte = '';
3267
-	if ($env) {
3268
-		foreach ($env as $i => $j) {
3269
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3270
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3271
-			}
3272
-		}
3273
-	}
3274
-
3275
-	return $texte;
3259
+    $ignore_params = array_merge(
3260
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3261
+        $ignore_params
3262
+    );
3263
+    if (!is_array($env)) {
3264
+        $env = unserialize($env);
3265
+    }
3266
+    $texte = '';
3267
+    if ($env) {
3268
+        foreach ($env as $i => $j) {
3269
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3270
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3271
+            }
3272
+        }
3273
+    }
3274
+
3275
+    return $texte;
3276 3276
 }
3277 3277
 
3278 3278
 /**
@@ -3295,23 +3295,23 @@  discard block
 block discarded – undo
3295 3295
  *      Code HTML résultant
3296 3296
  **/
3297 3297
 function env_to_attributs($env, $ignore_params = []) {
3298
-	$ignore_params = array_merge(
3299
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3300
-		$ignore_params
3301
-	);
3302
-	if (!is_array($env)) {
3303
-		$env = unserialize($env);
3304
-	}
3305
-	$texte = '';
3306
-	if ($env) {
3307
-		foreach ($env as $i => $j) {
3308
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3309
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3310
-			}
3311
-		}
3312
-	}
3298
+    $ignore_params = array_merge(
3299
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3300
+        $ignore_params
3301
+    );
3302
+    if (!is_array($env)) {
3303
+        $env = unserialize($env);
3304
+    }
3305
+    $texte = '';
3306
+    if ($env) {
3307
+        foreach ($env as $i => $j) {
3308
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3309
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3310
+            }
3311
+        }
3312
+    }
3313 3313
 
3314
-	return $texte;
3314
+    return $texte;
3315 3315
 }
3316 3316
 
3317 3317
 
@@ -3329,7 +3329,7 @@  discard block
 block discarded – undo
3329 3329
  * @return string Chaînes concaténés
3330 3330
  **/
3331 3331
 function concat(...$args): string {
3332
-	return join('', $args);
3332
+    return join('', $args);
3333 3333
 }
3334 3334
 
3335 3335
 
@@ -3349,23 +3349,23 @@  discard block
 block discarded – undo
3349 3349
  *     Contenu du ou des fichiers, concaténé
3350 3350
  **/
3351 3351
 function charge_scripts($files, $script = true) {
3352
-	$flux = '';
3353
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3354
-		if (!is_string($file)) {
3355
-			continue;
3356
-		}
3357
-		if ($script) {
3358
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3359
-		}
3360
-		if ($file) {
3361
-			$path = find_in_path($file);
3362
-			if ($path) {
3363
-				$flux .= spip_file_get_contents($path);
3364
-			}
3365
-		}
3366
-	}
3367
-
3368
-	return $flux;
3352
+    $flux = '';
3353
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3354
+        if (!is_string($file)) {
3355
+            continue;
3356
+        }
3357
+        if ($script) {
3358
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3359
+        }
3360
+        if ($file) {
3361
+            $path = find_in_path($file);
3362
+            if ($path) {
3363
+                $flux .= spip_file_get_contents($path);
3364
+            }
3365
+        }
3366
+    }
3367
+
3368
+    return $flux;
3369 3369
 }
3370 3370
 
3371 3371
 /**
@@ -3376,22 +3376,22 @@  discard block
 block discarded – undo
3376 3376
  * @return string
3377 3377
  */
3378 3378
 function http_img_variante_svg_si_possible($img_file) {
3379
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3380
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3381
-	if (
3382
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3383
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3384
-		and file_exists($variante_svg_generique)
3385
-	) {
3386
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3387
-			$img_file = $variante_svg_size;
3388
-		}
3389
-		else {
3390
-			$img_file = $variante_svg_generique;
3391
-		}
3392
-	}
3379
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3380
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3381
+    if (
3382
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3383
+        and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3384
+        and file_exists($variante_svg_generique)
3385
+    ) {
3386
+        if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3387
+            $img_file = $variante_svg_size;
3388
+        }
3389
+        else {
3390
+            $img_file = $variante_svg_generique;
3391
+        }
3392
+    }
3393 3393
 
3394
-	return $img_file;
3394
+    return $img_file;
3395 3395
 }
3396 3396
 
3397 3397
 /**
@@ -3412,54 +3412,54 @@  discard block
 block discarded – undo
3412 3412
  */
3413 3413
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3414 3414
 
3415
-	$img_file = $img;
3416
-	if ($p = strpos($img_file, '?')) {
3417
-		$img_file = substr($img_file, 0, $p);
3418
-	}
3419
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3420
-		$img_file = chemin_image($img);
3421
-	}
3422
-	else {
3423
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3424
-			$img_file = http_img_variante_svg_si_possible($img_file);
3425
-		}
3426
-	}
3427
-	if (stripos($atts, 'width') === false) {
3428
-		// utiliser directement l'info de taille presente dans le nom
3429
-		if (
3430
-			(!isset($options['utiliser_suffixe_size'])
3431
-				or $options['utiliser_suffixe_size'] == true
3432
-				or str_contains($img_file, '-xx.svg'))
3433
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3434
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3435
-		) {
3436
-			$largeur = $hauteur = intval($regs[1]);
3437
-		} else {
3438
-			$taille = taille_image($img_file);
3439
-			[$hauteur, $largeur] = $taille;
3440
-			if (!$hauteur or !$largeur) {
3441
-				return '';
3442
-			}
3443
-		}
3444
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3445
-	}
3446
-
3447
-	if (file_exists($img_file)) {
3448
-		$img_file = timestamp($img_file);
3449
-	}
3450
-	if ($alt === false) {
3451
-		$alt = '';
3452
-	}
3453
-	elseif ($alt or $alt === '') {
3454
-		$alt = " alt='" . attribut_html($alt) . "'";
3455
-	}
3456
-	else {
3457
-		$alt = " alt='" . attribut_html($title) . "'";
3458
-	}
3459
-	return "<img src='" . attribut_html($img_file) . "'$alt"
3460
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3461
-	. ' ' . ltrim($atts)
3462
-	. ' />';
3415
+    $img_file = $img;
3416
+    if ($p = strpos($img_file, '?')) {
3417
+        $img_file = substr($img_file, 0, $p);
3418
+    }
3419
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3420
+        $img_file = chemin_image($img);
3421
+    }
3422
+    else {
3423
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3424
+            $img_file = http_img_variante_svg_si_possible($img_file);
3425
+        }
3426
+    }
3427
+    if (stripos($atts, 'width') === false) {
3428
+        // utiliser directement l'info de taille presente dans le nom
3429
+        if (
3430
+            (!isset($options['utiliser_suffixe_size'])
3431
+                or $options['utiliser_suffixe_size'] == true
3432
+                or str_contains($img_file, '-xx.svg'))
3433
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3434
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3435
+        ) {
3436
+            $largeur = $hauteur = intval($regs[1]);
3437
+        } else {
3438
+            $taille = taille_image($img_file);
3439
+            [$hauteur, $largeur] = $taille;
3440
+            if (!$hauteur or !$largeur) {
3441
+                return '';
3442
+            }
3443
+        }
3444
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3445
+    }
3446
+
3447
+    if (file_exists($img_file)) {
3448
+        $img_file = timestamp($img_file);
3449
+    }
3450
+    if ($alt === false) {
3451
+        $alt = '';
3452
+    }
3453
+    elseif ($alt or $alt === '') {
3454
+        $alt = " alt='" . attribut_html($alt) . "'";
3455
+    }
3456
+    else {
3457
+        $alt = " alt='" . attribut_html($title) . "'";
3458
+    }
3459
+    return "<img src='" . attribut_html($img_file) . "'$alt"
3460
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3461
+    . ' ' . ltrim($atts)
3462
+    . ' />';
3463 3463
 }
3464 3464
 
3465 3465
 /**
@@ -3471,70 +3471,70 @@  discard block
 block discarded – undo
3471 3471
  * @return string
3472 3472
  */
3473 3473
 function http_style_background($img, $att = '', $size = null) {
3474
-	if ($size and is_numeric($size)) {
3475
-		$size = trim($size) . 'px';
3476
-	}
3477
-	return " style='background" .
3478
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3479
-		. ($size ? "background-size:{$size};" : '')
3480
-		. "'";
3474
+    if ($size and is_numeric($size)) {
3475
+        $size = trim($size) . 'px';
3476
+    }
3477
+    return " style='background" .
3478
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3479
+        . ($size ? "background-size:{$size};" : '')
3480
+        . "'";
3481 3481
 }
3482 3482
 
3483 3483
 
3484 3484
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3485
-	$args = [$alt_or_size, $class_or_size, $size];
3486
-	while (is_null(end($args)) and count($args)) {
3487
-		array_pop($args);
3488
-	}
3489
-	if (!count($args)) {
3490
-		return [null, null, null];
3491
-	}
3492
-	if (count($args) < 3) {
3493
-		$maybe_size = array_pop($args);
3494
-		// @2x
3495
-		// @1.5x
3496
-		// 512
3497
-		// 512x*
3498
-		// 512x300
3499
-		if (
3500
-			!strlen($maybe_size)
3501
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3502
-		) {
3503
-			$args[] = $maybe_size;
3504
-			$maybe_size = null;
3505
-		}
3506
-		while (count($args) < 2) {
3507
-			$args[] = null; // default alt or class
3508
-		}
3509
-		$args[] = $maybe_size;
3510
-	}
3511
-	return $args;
3485
+    $args = [$alt_or_size, $class_or_size, $size];
3486
+    while (is_null(end($args)) and count($args)) {
3487
+        array_pop($args);
3488
+    }
3489
+    if (!count($args)) {
3490
+        return [null, null, null];
3491
+    }
3492
+    if (count($args) < 3) {
3493
+        $maybe_size = array_pop($args);
3494
+        // @2x
3495
+        // @1.5x
3496
+        // 512
3497
+        // 512x*
3498
+        // 512x300
3499
+        if (
3500
+            !strlen($maybe_size)
3501
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3502
+        ) {
3503
+            $args[] = $maybe_size;
3504
+            $maybe_size = null;
3505
+        }
3506
+        while (count($args) < 2) {
3507
+            $args[] = null; // default alt or class
3508
+        }
3509
+        $args[] = $maybe_size;
3510
+    }
3511
+    return $args;
3512 3512
 }
3513 3513
 
3514 3514
 function helper_filtre_balise_img_svg_size($img, $size) {
3515
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3516
-	if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3517
-		$coef = floatval(substr($size, 1, -1));
3518
-		[$h, $w] = taille_image($img);
3519
-		$height = intval(round($h / $coef));
3520
-		$width = intval(round($w / $coef));
3521
-	}
3522
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3523
-	else {
3524
-		$size = explode('x', $size, 2);
3525
-		$size = array_map('trim', $size);
3526
-		$height = $width = intval(array_shift($size));
3527
-
3528
-		if (count($size) and reset($size)) {
3529
-			$height = array_shift($size);
3530
-			if ($height === '*') {
3531
-				[$h, $w] = taille_image($img);
3532
-				$height = intval(round($h * $width / $w));
3533
-			}
3534
-		}
3535
-	}
3536
-
3537
-	return [$width, $height];
3515
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3516
+    if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3517
+        $coef = floatval(substr($size, 1, -1));
3518
+        [$h, $w] = taille_image($img);
3519
+        $height = intval(round($h / $coef));
3520
+        $width = intval(round($w / $coef));
3521
+    }
3522
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3523
+    else {
3524
+        $size = explode('x', $size, 2);
3525
+        $size = array_map('trim', $size);
3526
+        $height = $width = intval(array_shift($size));
3527
+
3528
+        if (count($size) and reset($size)) {
3529
+            $height = array_shift($size);
3530
+            if ($height === '*') {
3531
+                [$h, $w] = taille_image($img);
3532
+                $height = intval(round($h * $width / $w));
3533
+            }
3534
+        }
3535
+    }
3536
+
3537
+    return [$width, $height];
3538 3538
 }
3539 3539
 
3540 3540
 /**
@@ -3570,43 +3570,43 @@  discard block
 block discarded – undo
3570 3570
  */
3571 3571
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3572 3572
 
3573
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3574
-
3575
-	$img = trim((string) $img);
3576
-	if (strpos($img, '<img') === 0) {
3577
-		if (!is_null($alt)) {
3578
-			$img = inserer_attribut($img, 'alt', $alt);
3579
-		}
3580
-		if (!is_null($class)) {
3581
-			if (strlen($class)) {
3582
-				$img = inserer_attribut($img, 'class', $class);
3583
-			}
3584
-			else {
3585
-				$img = vider_attribut($img, 'class');
3586
-			}
3587
-		}
3588
-	}
3589
-	else {
3590
-		$img = http_img_pack(
3591
-			$img,
3592
-			$alt,
3593
-			$class ? " class='" . attribut_html($class) . "'" : '',
3594
-			'',
3595
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3596
-		);
3597
-		if (is_null($alt)) {
3598
-			$img = vider_attribut($img, 'alt');
3599
-		}
3600
-	}
3601
-
3602
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3603
-		[$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3604
-
3605
-		$img = inserer_attribut($img, 'width', $width);
3606
-		$img = inserer_attribut($img, 'height', $height);
3607
-	}
3608
-
3609
-	return $img;
3573
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3574
+
3575
+    $img = trim((string) $img);
3576
+    if (strpos($img, '<img') === 0) {
3577
+        if (!is_null($alt)) {
3578
+            $img = inserer_attribut($img, 'alt', $alt);
3579
+        }
3580
+        if (!is_null($class)) {
3581
+            if (strlen($class)) {
3582
+                $img = inserer_attribut($img, 'class', $class);
3583
+            }
3584
+            else {
3585
+                $img = vider_attribut($img, 'class');
3586
+            }
3587
+        }
3588
+    }
3589
+    else {
3590
+        $img = http_img_pack(
3591
+            $img,
3592
+            $alt,
3593
+            $class ? " class='" . attribut_html($class) . "'" : '',
3594
+            '',
3595
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3596
+        );
3597
+        if (is_null($alt)) {
3598
+            $img = vider_attribut($img, 'alt');
3599
+        }
3600
+    }
3601
+
3602
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3603
+        [$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3604
+
3605
+        $img = inserer_attribut($img, 'width', $width);
3606
+        $img = inserer_attribut($img, 'height', $height);
3607
+    }
3608
+
3609
+    return $img;
3610 3610
 }
3611 3611
 
3612 3612
 
@@ -3640,80 +3640,80 @@  discard block
 block discarded – undo
3640 3640
  */
3641 3641
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3642 3642
 
3643
-	$svg = null;
3644
-	$img = trim($img);
3645
-	$img_file = $img;
3646
-	if (strpos($img, '<svg') === false) {
3647
-		if ($p = strpos($img_file, '?')) {
3648
-			$img_file = substr($img_file, 0, $p);
3649
-		}
3650
-
3651
-		// ne jamais operer directement sur une image distante pour des raisons de perfo
3652
-		// la copie locale a toutes les chances d'etre la ou de resservir
3653
-		if (tester_url_absolue($img_file)) {
3654
-			include_spip('inc/distant');
3655
-			$fichier = copie_locale($img_file);
3656
-			$img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3657
-		}
3658
-
3659
-		if (
3660
-			!$img_file
3661
-			or !file_exists($img_file)
3662
-			or !$svg = file_get_contents($img_file)
3663
-		) {
3664
-			return '';
3665
-		}
3666
-	}
3667
-
3668
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3669
-		return '';
3670
-	}
3671
-
3672
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3673
-
3674
-	$balise_svg = $match[0];
3675
-	$balise_svg_source = $balise_svg;
3676
-
3677
-	// entete XML à supprimer
3678
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3679
-
3680
-	// IE est toujours mon ami
3681
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3682
-
3683
-	// regler la classe
3684
-	if (!is_null($class)) {
3685
-		if (strlen($class)) {
3686
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3687
-		}
3688
-		else {
3689
-			$balise_svg = vider_attribut($balise_svg, 'class');
3690
-		}
3691
-	}
3692
-
3693
-	// regler le alt
3694
-	if ($alt) {
3695
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3696
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3697
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3698
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3699
-		$balise_svg .= $title;
3700
-	}
3701
-	else {
3702
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3703
-	}
3704
-
3705
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3706
-
3707
-	if (!is_null($size) and strlen($size = trim($size))) {
3708
-		[$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3709
-
3710
-		if (!function_exists('svg_redimensionner')) {
3711
-			include_spip('inc/svg');
3712
-		}
3713
-		$svg = svg_redimensionner($svg, $width, $height);
3714
-	}
3715
-
3716
-	return $svg;
3643
+    $svg = null;
3644
+    $img = trim($img);
3645
+    $img_file = $img;
3646
+    if (strpos($img, '<svg') === false) {
3647
+        if ($p = strpos($img_file, '?')) {
3648
+            $img_file = substr($img_file, 0, $p);
3649
+        }
3650
+
3651
+        // ne jamais operer directement sur une image distante pour des raisons de perfo
3652
+        // la copie locale a toutes les chances d'etre la ou de resservir
3653
+        if (tester_url_absolue($img_file)) {
3654
+            include_spip('inc/distant');
3655
+            $fichier = copie_locale($img_file);
3656
+            $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3657
+        }
3658
+
3659
+        if (
3660
+            !$img_file
3661
+            or !file_exists($img_file)
3662
+            or !$svg = file_get_contents($img_file)
3663
+        ) {
3664
+            return '';
3665
+        }
3666
+    }
3667
+
3668
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3669
+        return '';
3670
+    }
3671
+
3672
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3673
+
3674
+    $balise_svg = $match[0];
3675
+    $balise_svg_source = $balise_svg;
3676
+
3677
+    // entete XML à supprimer
3678
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3679
+
3680
+    // IE est toujours mon ami
3681
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3682
+
3683
+    // regler la classe
3684
+    if (!is_null($class)) {
3685
+        if (strlen($class)) {
3686
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3687
+        }
3688
+        else {
3689
+            $balise_svg = vider_attribut($balise_svg, 'class');
3690
+        }
3691
+    }
3692
+
3693
+    // regler le alt
3694
+    if ($alt) {
3695
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3696
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3697
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3698
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3699
+        $balise_svg .= $title;
3700
+    }
3701
+    else {
3702
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3703
+    }
3704
+
3705
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3706
+
3707
+    if (!is_null($size) and strlen($size = trim($size))) {
3708
+        [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3709
+
3710
+        if (!function_exists('svg_redimensionner')) {
3711
+            include_spip('inc/svg');
3712
+        }
3713
+        $svg = svg_redimensionner($svg, $width, $height);
3714
+    }
3715
+
3716
+    return $svg;
3717 3717
 }
3718 3718
 
3719 3719
 
@@ -3739,18 +3739,18 @@  discard block
 block discarded – undo
3739 3739
  *     Code HTML résultant
3740 3740
  **/
3741 3741
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3742
-	$texte = '';
3743
-	if (is_array($tableau)) {
3744
-		foreach ($tableau as $k => $v) {
3745
-			$res = recuperer_fond(
3746
-				'modeles/' . $modele,
3747
-				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3748
-			);
3749
-			$texte .= $res;
3750
-		}
3751
-	}
3742
+    $texte = '';
3743
+    if (is_array($tableau)) {
3744
+        foreach ($tableau as $k => $v) {
3745
+            $res = recuperer_fond(
3746
+                'modeles/' . $modele,
3747
+                array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3748
+            );
3749
+            $texte .= $res;
3750
+        }
3751
+    }
3752 3752
 
3753
-	return $texte;
3753
+    return $texte;
3754 3754
 }
3755 3755
 
3756 3756
 
@@ -3775,37 +3775,37 @@  discard block
 block discarded – undo
3775 3775
  *         - tout : retourne toutes les informations du plugin actif
3776 3776
  **/
3777 3777
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3778
-	include_spip('inc/plugin');
3779
-	$plugin = strtoupper($plugin);
3780
-	$plugins_actifs = liste_plugin_actifs();
3781
-
3782
-	if (!$plugin) {
3783
-		return serialize(array_keys($plugins_actifs));
3784
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3785
-		return '';
3786
-	} elseif (($type_info == 'est_actif') and !$reload) {
3787
-		return $plugins_actifs[$plugin] ? 1 : 0;
3788
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3789
-		return $plugins_actifs[$plugin][$type_info];
3790
-	} else {
3791
-		$get_infos = charger_fonction('get_infos', 'plugins');
3792
-		// On prend en compte les extensions
3793
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3794
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3795
-		} else {
3796
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3797
-		}
3798
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3799
-			return '';
3800
-		}
3801
-		if ($type_info == 'tout') {
3802
-			return $infos;
3803
-		} elseif ($type_info == 'est_actif') {
3804
-			return $infos ? 1 : 0;
3805
-		} else {
3806
-			return strval($infos[$type_info]);
3807
-		}
3808
-	}
3778
+    include_spip('inc/plugin');
3779
+    $plugin = strtoupper($plugin);
3780
+    $plugins_actifs = liste_plugin_actifs();
3781
+
3782
+    if (!$plugin) {
3783
+        return serialize(array_keys($plugins_actifs));
3784
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3785
+        return '';
3786
+    } elseif (($type_info == 'est_actif') and !$reload) {
3787
+        return $plugins_actifs[$plugin] ? 1 : 0;
3788
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3789
+        return $plugins_actifs[$plugin][$type_info];
3790
+    } else {
3791
+        $get_infos = charger_fonction('get_infos', 'plugins');
3792
+        // On prend en compte les extensions
3793
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3794
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3795
+        } else {
3796
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3797
+        }
3798
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3799
+            return '';
3800
+        }
3801
+        if ($type_info == 'tout') {
3802
+            return $infos;
3803
+        } elseif ($type_info == 'est_actif') {
3804
+            return $infos ? 1 : 0;
3805
+        } else {
3806
+            return strval($infos[$type_info]);
3807
+        }
3808
+    }
3809 3809
 }
3810 3810
 
3811 3811
 
@@ -3832,9 +3832,9 @@  discard block
 block discarded – undo
3832 3832
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3833 3833
  */
3834 3834
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3835
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3835
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3836 3836
 
3837
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3837
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3838 3838
 }
3839 3839
 
3840 3840
 
@@ -3864,19 +3864,19 @@  discard block
 block discarded – undo
3864 3864
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3865 3865
  */
3866 3866
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3867
-	static $puce_statut = null;
3868
-	if (!$puce_statut) {
3869
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3870
-	}
3867
+    static $puce_statut = null;
3868
+    if (!$puce_statut) {
3869
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3870
+    }
3871 3871
 
3872
-	return $puce_statut(
3873
-		$id_objet,
3874
-		$statut,
3875
-		$id_parent,
3876
-		$objet,
3877
-		false,
3878
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3879
-	);
3872
+    return $puce_statut(
3873
+        $id_objet,
3874
+        $statut,
3875
+        $id_parent,
3876
+        $objet,
3877
+        false,
3878
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3879
+    );
3880 3880
 }
3881 3881
 
3882 3882
 
@@ -3903,98 +3903,98 @@  discard block
 block discarded – undo
3903 3903
  *   hash du contexte
3904 3904
  */
3905 3905
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3906
-	$env = null;
3907
-	if (
3908
-		is_string($c)
3909
-		and @unserialize($c) !== false
3910
-	) {
3911
-		$c = unserialize($c);
3912
-	}
3913
-
3914
-	// supprimer les parametres debut_x
3915
-	// pour que la pagination ajax ne soit pas plantee
3916
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3917
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3918
-	if (is_array($c)) {
3919
-		foreach ($c as $k => $v) {
3920
-			if (strpos($k, 'debut_') === 0) {
3921
-				unset($c[$k]);
3922
-			}
3923
-		}
3924
-	}
3925
-
3926
-	if (!function_exists('calculer_cle_action')) {
3927
-		include_spip('inc/securiser_action');
3928
-	}
3929
-
3930
-	$c = serialize($c);
3931
-	$cle = calculer_cle_action($form . $c);
3932
-	$c = "$cle:$c";
3933
-
3934
-	// on ne stocke pas les contextes dans des fichiers en cache
3935
-	// par defaut, sauf si cette configuration a été forcée
3936
-	// OU que la longueur de l’argument géneré est plus long
3937
-	// que ce qui est toléré.
3938
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3939
-	if (!$cache_contextes_ajax) {
3940
-		$env = $c;
3941
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3942
-			$env = gzdeflate($env);
3943
-		}
3944
-		$env = _xor($env);
3945
-		$env = base64_encode($env);
3946
-		$len = strlen($env);
3947
-		// Si l’url est trop longue pour le navigateur
3948
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3949
-		if ($len > $max_len) {
3950
-			$cache_contextes_ajax = true;
3951
-			spip_log(
3952
-				'Contextes AJAX forces en fichiers !'
3953
-				. ' Cela arrive lorsque la valeur du contexte'
3954
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3955
-				_LOG_AVERTISSEMENT
3956
-			);
3957
-		}
3958
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3959
-		elseif (
3960
-			$max_len = @ini_get('suhosin.get.max_value_length')
3961
-			and $max_len < $len
3962
-		) {
3963
-			$cache_contextes_ajax = true;
3964
-			spip_log('Contextes AJAX forces en fichiers !'
3965
-				. ' Cela arrive lorsque la valeur du contexte'
3966
-				. ' depasse la longueur maximale autorisee par Suhosin'
3967
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3968
-				. ' Vous devriez modifier les parametres de Suhosin'
3969
-				. ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
3970
-		}
3971
-	}
3972
-
3973
-	if ($cache_contextes_ajax) {
3974
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
3975
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
3976
-		$md5 = md5($c);
3977
-		ecrire_fichier("$dir/c$md5", $c);
3978
-		$env = $md5;
3979
-	}
3980
-
3981
-	if ($emboite === null) {
3982
-		return $env;
3983
-	}
3984
-	if (!trim($emboite)) {
3985
-		return '';
3986
-	}
3987
-	// toujours encoder l'url source dans le bloc ajax
3988
-	$r = self();
3989
-	$r = ' data-origin="' . $r . '"';
3990
-	$class = 'ajaxbloc';
3991
-	if ($ajaxid and is_string($ajaxid)) {
3992
-		// ajaxid est normalement conforme a un nom de classe css
3993
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3994
-		$class .= ' ajax-id-' . entites_html($ajaxid);
3995
-	}
3996
-
3997
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3906
+    $env = null;
3907
+    if (
3908
+        is_string($c)
3909
+        and @unserialize($c) !== false
3910
+    ) {
3911
+        $c = unserialize($c);
3912
+    }
3913
+
3914
+    // supprimer les parametres debut_x
3915
+    // pour que la pagination ajax ne soit pas plantee
3916
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3917
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3918
+    if (is_array($c)) {
3919
+        foreach ($c as $k => $v) {
3920
+            if (strpos($k, 'debut_') === 0) {
3921
+                unset($c[$k]);
3922
+            }
3923
+        }
3924
+    }
3925
+
3926
+    if (!function_exists('calculer_cle_action')) {
3927
+        include_spip('inc/securiser_action');
3928
+    }
3929
+
3930
+    $c = serialize($c);
3931
+    $cle = calculer_cle_action($form . $c);
3932
+    $c = "$cle:$c";
3933
+
3934
+    // on ne stocke pas les contextes dans des fichiers en cache
3935
+    // par defaut, sauf si cette configuration a été forcée
3936
+    // OU que la longueur de l’argument géneré est plus long
3937
+    // que ce qui est toléré.
3938
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3939
+    if (!$cache_contextes_ajax) {
3940
+        $env = $c;
3941
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3942
+            $env = gzdeflate($env);
3943
+        }
3944
+        $env = _xor($env);
3945
+        $env = base64_encode($env);
3946
+        $len = strlen($env);
3947
+        // Si l’url est trop longue pour le navigateur
3948
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3949
+        if ($len > $max_len) {
3950
+            $cache_contextes_ajax = true;
3951
+            spip_log(
3952
+                'Contextes AJAX forces en fichiers !'
3953
+                . ' Cela arrive lorsque la valeur du contexte'
3954
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3955
+                _LOG_AVERTISSEMENT
3956
+            );
3957
+        }
3958
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3959
+        elseif (
3960
+            $max_len = @ini_get('suhosin.get.max_value_length')
3961
+            and $max_len < $len
3962
+        ) {
3963
+            $cache_contextes_ajax = true;
3964
+            spip_log('Contextes AJAX forces en fichiers !'
3965
+                . ' Cela arrive lorsque la valeur du contexte'
3966
+                . ' depasse la longueur maximale autorisee par Suhosin'
3967
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3968
+                . ' Vous devriez modifier les parametres de Suhosin'
3969
+                . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
3970
+        }
3971
+    }
3972
+
3973
+    if ($cache_contextes_ajax) {
3974
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
3975
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
3976
+        $md5 = md5($c);
3977
+        ecrire_fichier("$dir/c$md5", $c);
3978
+        $env = $md5;
3979
+    }
3980
+
3981
+    if ($emboite === null) {
3982
+        return $env;
3983
+    }
3984
+    if (!trim($emboite)) {
3985
+        return '';
3986
+    }
3987
+    // toujours encoder l'url source dans le bloc ajax
3988
+    $r = self();
3989
+    $r = ' data-origin="' . $r . '"';
3990
+    $class = 'ajaxbloc';
3991
+    if ($ajaxid and is_string($ajaxid)) {
3992
+        // ajaxid est normalement conforme a un nom de classe css
3993
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3994
+        $class .= ' ajax-id-' . entites_html($ajaxid);
3995
+    }
3996
+
3997
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3998 3998
 }
3999 3999
 
4000 4000
 /**
@@ -4014,37 +4014,37 @@  discard block
 block discarded – undo
4014 4014
  *   - false : erreur de décodage
4015 4015
  */
4016 4016
 function decoder_contexte_ajax($c, $form = '') {
4017
-	if (!function_exists('calculer_cle_action')) {
4018
-		include_spip('inc/securiser_action');
4019
-	}
4020
-	if (
4021
-		((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4022
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4023
-		and lire_fichier("$dir/c$c", $contexte)
4024
-	) {
4025
-		$c = $contexte;
4026
-	} else {
4027
-		$c = @base64_decode($c);
4028
-		$c = _xor($c);
4029
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4030
-			$c = @gzinflate($c);
4031
-		}
4032
-	}
4033
-
4034
-	// extraire la signature en debut de contexte
4035
-	// et la verifier avant de deserializer
4036
-	// format : signature:donneesserializees
4037
-	if ($p = strpos($c, ':')) {
4038
-		$cle = substr($c, 0, $p);
4039
-		$c = substr($c, $p + 1);
4040
-
4041
-		if ($cle == calculer_cle_action($form . $c)) {
4042
-			$env = @unserialize($c);
4043
-			return $env;
4044
-		}
4045
-	}
4046
-
4047
-	return false;
4017
+    if (!function_exists('calculer_cle_action')) {
4018
+        include_spip('inc/securiser_action');
4019
+    }
4020
+    if (
4021
+        ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4022
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4023
+        and lire_fichier("$dir/c$c", $contexte)
4024
+    ) {
4025
+        $c = $contexte;
4026
+    } else {
4027
+        $c = @base64_decode($c);
4028
+        $c = _xor($c);
4029
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4030
+            $c = @gzinflate($c);
4031
+        }
4032
+    }
4033
+
4034
+    // extraire la signature en debut de contexte
4035
+    // et la verifier avant de deserializer
4036
+    // format : signature:donneesserializees
4037
+    if ($p = strpos($c, ':')) {
4038
+        $cle = substr($c, 0, $p);
4039
+        $c = substr($c, $p + 1);
4040
+
4041
+        if ($cle == calculer_cle_action($form . $c)) {
4042
+            $env = @unserialize($c);
4043
+            return $env;
4044
+        }
4045
+    }
4046
+
4047
+    return false;
4048 4048
 }
4049 4049
 
4050 4050
 
@@ -4062,20 +4062,20 @@  discard block
 block discarded – undo
4062 4062
  *    Message décrypté ou encrypté
4063 4063
  **/
4064 4064
 function _xor($message, $key = null) {
4065
-	if (is_null($key)) {
4066
-		if (!function_exists('calculer_cle_action')) {
4067
-			include_spip('inc/securiser_action');
4068
-		}
4069
-		$key = pack('H*', calculer_cle_action('_xor'));
4070
-	}
4065
+    if (is_null($key)) {
4066
+        if (!function_exists('calculer_cle_action')) {
4067
+            include_spip('inc/securiser_action');
4068
+        }
4069
+        $key = pack('H*', calculer_cle_action('_xor'));
4070
+    }
4071 4071
 
4072
-	$keylen = strlen($key);
4073
-	$messagelen = strlen($message);
4074
-	for ($i = 0; $i < $messagelen; $i++) {
4075
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4076
-	}
4072
+    $keylen = strlen($key);
4073
+    $messagelen = strlen($message);
4074
+    for ($i = 0; $i < $messagelen; $i++) {
4075
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4076
+    }
4077 4077
 
4078
-	return $message;
4078
+    return $message;
4079 4079
 }
4080 4080
 
4081 4081
 /**
@@ -4089,7 +4089,7 @@  discard block
 block discarded – undo
4089 4089
  * @return string
4090 4090
  */
4091 4091
 function url_reponse_forum($texte) {
4092
- return $texte;
4092
+    return $texte;
4093 4093
 }
4094 4094
 
4095 4095
 /**
@@ -4103,7 +4103,7 @@  discard block
 block discarded – undo
4103 4103
  * @return string
4104 4104
  */
4105 4105
 function url_rss_forum($texte) {
4106
- return $texte;
4106
+    return $texte;
4107 4107
 }
4108 4108
 
4109 4109
 
@@ -4142,37 +4142,37 @@  discard block
 block discarded – undo
4142 4142
  *   Code HTML
4143 4143
  */
4144 4144
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4145
-	if ($on) {
4146
-		$bal = 'strong';
4147
-		$class = '';
4148
-		$att = '';
4149
-		// si $on passe la balise et optionnelement une ou ++classe
4150
-		// a.active span.selected.active etc....
4151
-		if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4152
-			$on = explode('.', $on);
4153
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4154
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4155
-				$bal = array_shift($on);
4156
-				$class = implode(' ', $on);
4157
-				if ($bal == 'a') {
4158
-					$att = 'href="#" ';
4159
-				}
4160
-			}
4161
-		}
4162
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4163
-	} else {
4164
-		$bal = 'a';
4165
-		$att = "href='$url'"
4166
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4167
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4168
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4169
-			. $evt;
4170
-	}
4171
-	if ($libelle === null) {
4172
-		$libelle = $url;
4173
-	}
4174
-
4175
-	return "<$bal $att>$libelle</$bal>";
4145
+    if ($on) {
4146
+        $bal = 'strong';
4147
+        $class = '';
4148
+        $att = '';
4149
+        // si $on passe la balise et optionnelement une ou ++classe
4150
+        // a.active span.selected.active etc....
4151
+        if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4152
+            $on = explode('.', $on);
4153
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4154
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4155
+                $bal = array_shift($on);
4156
+                $class = implode(' ', $on);
4157
+                if ($bal == 'a') {
4158
+                    $att = 'href="#" ';
4159
+                }
4160
+            }
4161
+        }
4162
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4163
+    } else {
4164
+        $bal = 'a';
4165
+        $att = "href='$url'"
4166
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4167
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4168
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4169
+            . $evt;
4170
+    }
4171
+    if ($libelle === null) {
4172
+        $libelle = $url;
4173
+    }
4174
+
4175
+    return "<$bal $att>$libelle</$bal>";
4176 4176
 }
4177 4177
 
4178 4178
 
@@ -4189,39 +4189,39 @@  discard block
 block discarded – undo
4189 4189
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4190 4190
  */
4191 4191
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4192
-	static $local_singulier_ou_pluriel = [];
4193
-
4194
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4195
-	if (!is_numeric($nb) or $nb == 0) {
4196
-		return '';
4197
-	}
4198
-	if (!is_array($vars)) {
4199
-		return '';
4200
-	}
4201
-
4202
-	$langue = $GLOBALS['spip_lang'];
4203
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4204
-		$local_singulier_ou_pluriel[$langue] = false;
4205
-		if (
4206
-			$f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)
4207
-			or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4208
-		) {
4209
-			$local_singulier_ou_pluriel[$langue] = $f;
4210
-		}
4211
-	}
4212
-
4213
-	// si on a une surcharge on l'utilise
4214
-	if ($local_singulier_ou_pluriel[$langue]) {
4215
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4216
-	}
4217
-
4218
-	// sinon traitement par defaut
4219
-	$vars[$var] = $nb;
4220
-	if ($nb >= 2) {
4221
-		return _T($chaine_plusieurs, $vars);
4222
-	} else {
4223
-		return _T($chaine_un, $vars);
4224
-	}
4192
+    static $local_singulier_ou_pluriel = [];
4193
+
4194
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4195
+    if (!is_numeric($nb) or $nb == 0) {
4196
+        return '';
4197
+    }
4198
+    if (!is_array($vars)) {
4199
+        return '';
4200
+    }
4201
+
4202
+    $langue = $GLOBALS['spip_lang'];
4203
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4204
+        $local_singulier_ou_pluriel[$langue] = false;
4205
+        if (
4206
+            $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)
4207
+            or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4208
+        ) {
4209
+            $local_singulier_ou_pluriel[$langue] = $f;
4210
+        }
4211
+    }
4212
+
4213
+    // si on a une surcharge on l'utilise
4214
+    if ($local_singulier_ou_pluriel[$langue]) {
4215
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4216
+    }
4217
+
4218
+    // sinon traitement par defaut
4219
+    $vars[$var] = $nb;
4220
+    if ($nb >= 2) {
4221
+        return _T($chaine_plusieurs, $vars);
4222
+    } else {
4223
+        return _T($chaine_un, $vars);
4224
+    }
4225 4225
 }
4226 4226
 
4227 4227
 
@@ -4249,73 +4249,73 @@  discard block
 block discarded – undo
4249 4249
  */
4250 4250
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4251 4251
 
4252
-	$class_lien = $class_bouton = $class;
4253
-
4254
-	// Normaliser la fonction et compléter la classe en fonction
4255
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4256
-		$class_lien .= ' danger';
4257
-		$class_bouton .= ' btn_danger';
4258
-	} elseif ($fonction == 'rien.gif') {
4259
-		$fonction = '';
4260
-	} elseif ($fonction == 'delsafe') {
4261
-		$fonction = 'del';
4262
-	}
4263
-
4264
-	$fond_origine = $fond;
4265
-	// Remappage des icone : article-24.png+new => article-new-24.png
4266
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4267
-		[$fond, $fonction] = $icone_renommer($fond, $fonction);
4268
-	}
4269
-
4270
-	// Ajouter le type d'objet dans la classe
4271
-	$objet_type = substr(basename($fond), 0, -4);
4272
-	$class_lien .= " $objet_type";
4273
-	$class_bouton .= " $objet_type";
4274
-
4275
-	// texte
4276
-	$alt = attribut_html($texte);
4277
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4278
-
4279
-	// Liens : préparer les classes ajax
4280
-	$ajax = '';
4281
-	if ($type === 'lien') {
4282
-		if (strpos($class_lien, 'ajax') !== false) {
4283
-			$ajax = 'ajax';
4284
-			if (strpos($class_lien, 'preload') !== false) {
4285
-				$ajax .= ' preload';
4286
-			}
4287
-			if (strpos($class_lien, 'nocache') !== false) {
4288
-				$ajax .= ' nocache';
4289
-			}
4290
-			$ajax = " class='$ajax'";
4291
-		}
4292
-	}
4293
-
4294
-	// Repérer la taille et l'ajouter dans la classe
4295
-	$size = 24;
4296
-	if (
4297
-		preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4298
-		or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4299
-	) {
4300
-		$size = $match[1];
4301
-	}
4302
-	$class_lien .= " s$size";
4303
-	$class_bouton .= " s$size";
4304
-
4305
-	// Icône
4306
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4307
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4308
-
4309
-	// Markup final
4310
-	if ($type == 'lien') {
4311
-		return "<span class='icone $class_lien'>"
4312
-		. "<a href='$lien'$title$ajax$javascript>"
4313
-		. $icone
4314
-		. "<b>$texte</b>"
4315
-		. "</a></span>\n";
4316
-	} else {
4317
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4318
-	}
4252
+    $class_lien = $class_bouton = $class;
4253
+
4254
+    // Normaliser la fonction et compléter la classe en fonction
4255
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4256
+        $class_lien .= ' danger';
4257
+        $class_bouton .= ' btn_danger';
4258
+    } elseif ($fonction == 'rien.gif') {
4259
+        $fonction = '';
4260
+    } elseif ($fonction == 'delsafe') {
4261
+        $fonction = 'del';
4262
+    }
4263
+
4264
+    $fond_origine = $fond;
4265
+    // Remappage des icone : article-24.png+new => article-new-24.png
4266
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4267
+        [$fond, $fonction] = $icone_renommer($fond, $fonction);
4268
+    }
4269
+
4270
+    // Ajouter le type d'objet dans la classe
4271
+    $objet_type = substr(basename($fond), 0, -4);
4272
+    $class_lien .= " $objet_type";
4273
+    $class_bouton .= " $objet_type";
4274
+
4275
+    // texte
4276
+    $alt = attribut_html($texte);
4277
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4278
+
4279
+    // Liens : préparer les classes ajax
4280
+    $ajax = '';
4281
+    if ($type === 'lien') {
4282
+        if (strpos($class_lien, 'ajax') !== false) {
4283
+            $ajax = 'ajax';
4284
+            if (strpos($class_lien, 'preload') !== false) {
4285
+                $ajax .= ' preload';
4286
+            }
4287
+            if (strpos($class_lien, 'nocache') !== false) {
4288
+                $ajax .= ' nocache';
4289
+            }
4290
+            $ajax = " class='$ajax'";
4291
+        }
4292
+    }
4293
+
4294
+    // Repérer la taille et l'ajouter dans la classe
4295
+    $size = 24;
4296
+    if (
4297
+        preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4298
+        or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4299
+    ) {
4300
+        $size = $match[1];
4301
+    }
4302
+    $class_lien .= " s$size";
4303
+    $class_bouton .= " s$size";
4304
+
4305
+    // Icône
4306
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4307
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4308
+
4309
+    // Markup final
4310
+    if ($type == 'lien') {
4311
+        return "<span class='icone $class_lien'>"
4312
+        . "<a href='$lien'$title$ajax$javascript>"
4313
+        . $icone
4314
+        . "<b>$texte</b>"
4315
+        . "</a></span>\n";
4316
+    } else {
4317
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4318
+    }
4319 4319
 }
4320 4320
 
4321 4321
 /**
@@ -4339,7 +4339,7 @@  discard block
 block discarded – undo
4339 4339
  *     Code HTML du lien
4340 4340
  **/
4341 4341
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4342
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4342
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4343 4343
 }
4344 4344
 
4345 4345
 /**
@@ -4374,7 +4374,7 @@  discard block
 block discarded – undo
4374 4374
  *     Code HTML du lien
4375 4375
  **/
4376 4376
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4377
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4377
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4378 4378
 }
4379 4379
 
4380 4380
 /**
@@ -4419,7 +4419,7 @@  discard block
 block discarded – undo
4419 4419
  *     Code HTML du lien
4420 4420
  **/
4421 4421
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4422
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4422
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4423 4423
 }
4424 4424
 
4425 4425
 /**
@@ -4450,7 +4450,7 @@  discard block
 block discarded – undo
4450 4450
  *     Code HTML du lien
4451 4451
  **/
4452 4452
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4453
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4453
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4454 4454
 }
4455 4455
 
4456 4456
 /**
@@ -4481,7 +4481,7 @@  discard block
 block discarded – undo
4481 4481
  *     Code HTML du lien
4482 4482
  */
4483 4483
 function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') {
4484
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4484
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4485 4485
 }
4486 4486
 
4487 4487
 
@@ -4503,7 +4503,7 @@  discard block
 block discarded – undo
4503 4503
  * @return array Liste des éléments
4504 4504
  */
4505 4505
 function filtre_explode_dist($a, $b) {
4506
-	return explode($b, (string) $a);
4506
+    return explode($b, (string) $a);
4507 4507
 }
4508 4508
 
4509 4509
 /**
@@ -4524,7 +4524,7 @@  discard block
 block discarded – undo
4524 4524
  * @return string texte
4525 4525
  */
4526 4526
 function filtre_implode_dist($a, $b) {
4527
-	return is_array($a) ? implode($b, $a) : $a;
4527
+    return is_array($a) ? implode($b, $a) : $a;
4528 4528
 }
4529 4529
 
4530 4530
 /**
@@ -4533,22 +4533,22 @@  discard block
 block discarded – undo
4533 4533
  * @return string Code CSS
4534 4534
  */
4535 4535
 function bando_images_background() {
4536
-	include_spip('inc/bandeau');
4537
-	// recuperer tous les boutons et leurs images
4538
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4536
+    include_spip('inc/bandeau');
4537
+    // recuperer tous les boutons et leurs images
4538
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4539 4539
 
4540
-	$res = '';
4541
-	foreach ($boutons as $page => $detail) {
4542
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4543
-		foreach ($detail->sousmenu as $souspage => $sousdetail) {
4544
-			if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4545
-				$img = http_img_variante_svg_si_possible($sousdetail->icone);
4546
-				$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4547
-			}
4548
-		}
4549
-	}
4540
+    $res = '';
4541
+    foreach ($boutons as $page => $detail) {
4542
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4543
+        foreach ($detail->sousmenu as $souspage => $sousdetail) {
4544
+            if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4545
+                $img = http_img_variante_svg_si_possible($sousdetail->icone);
4546
+                $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4547
+            }
4548
+        }
4549
+    }
4550 4550
 
4551
-	return $res;
4551
+    return $res;
4552 4552
 }
4553 4553
 
4554 4554
 /**
@@ -4573,27 +4573,27 @@  discard block
 block discarded – undo
4573 4573
  */
4574 4574
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4575 4575
 
4576
-	// Classes : dispatcher `ajax` sur le formulaire
4577
-	$class_form = '';
4578
-	if (strpos($class, 'ajax') !== false) {
4579
-		$class_form = 'ajax';
4580
-		$class = str_replace('ajax', '', $class);
4581
-	}
4582
-	$class_btn = 'submit ' . trim($class);
4576
+    // Classes : dispatcher `ajax` sur le formulaire
4577
+    $class_form = '';
4578
+    if (strpos($class, 'ajax') !== false) {
4579
+        $class_form = 'ajax';
4580
+        $class = str_replace('ajax', '', $class);
4581
+    }
4582
+    $class_btn = 'submit ' . trim($class);
4583 4583
 
4584
-	if ($confirm) {
4585
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4586
-		if ($callback) {
4587
-			$callback = "$confirm?($callback):false";
4588
-		} else {
4589
-			$callback = $confirm;
4590
-		}
4591
-	}
4592
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4593
-	$title = $title ? " title='$title'" : '';
4584
+    if ($confirm) {
4585
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4586
+        if ($callback) {
4587
+            $callback = "$confirm?($callback):false";
4588
+        } else {
4589
+            $callback = $confirm;
4590
+        }
4591
+    }
4592
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4593
+    $title = $title ? " title='$title'" : '';
4594 4594
 
4595
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4596
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4595
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4596
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4597 4597
 }
4598 4598
 
4599 4599
 /**
@@ -4616,101 +4616,101 @@  discard block
 block discarded – undo
4616 4616
  * @return string
4617 4617
  */
4618 4618
 function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string {
4619
-	static $trouver_table = null;
4620
-	static $objets;
4621
-
4622
-	// On verifie qu'on a tout ce qu'il faut
4623
-	$id_objet = intval($id_objet);
4624
-	if (!($id_objet and $type_objet and $info)) {
4625
-		return '';
4626
-	}
4627
-
4628
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4629
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4630
-		return '';
4631
-	}
4632
-
4633
-	// Si on demande l'url, on retourne direct la fonction
4634
-	if ($info == 'url') {
4635
-		return generer_objet_url($id_objet, $type_objet, ...$params);
4636
-	}
4637
-
4638
-	// Sinon on va tout chercher dans la table et on garde en memoire
4639
-	$demande_titre = ($info === 'titre');
4640
-	$demande_introduction = ($info === 'introduction');
4641
-
4642
-	// 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
4643
-	if (
4644
-		!isset($objets[$type_objet][$id_objet])
4645
-		or
4646
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4647
-	) {
4648
-		if (!$trouver_table) {
4649
-			$trouver_table = charger_fonction('trouver_table', 'base');
4650
-		}
4651
-		$desc = $trouver_table(table_objet_sql($type_objet));
4652
-		if (!$desc) {
4653
-			return $objets[$type_objet] = false;
4654
-		}
4655
-
4656
-		// Si on demande le titre, on le gere en interne
4657
-		$champ_titre = '';
4658
-		if ($demande_titre) {
4659
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4660
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4661
-		}
4662
-		include_spip('base/abstract_sql');
4663
-		include_spip('base/connect_sql');
4664
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4665
-			'*' . $champ_titre,
4666
-			$desc['table_sql'],
4667
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4668
-		);
4669
-
4670
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4671
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4672
-	}
4673
-
4674
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4675
-	// ajouter la longueur au début des params supplémentaires
4676
-	if ($demande_introduction) {
4677
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4678
-		array_unshift($params, $introduction_longueur);
4679
-	}
4680
-
4681
-	// Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4682
-	if (
4683
-		$generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)
4684
-		// @deprecated 4.1 generer_TRUC_TYPE
4685
-		or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)
4686
-	) {
4687
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4688
-	}
4689
-	// Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4690
-	elseif (
4691
-		$generer = charger_fonction("generer_objet_{$info}", '', true)
4692
-		// @deprecated 4.1 generer_TRUC_entite
4693
-		or $generer = charger_fonction("generer_{$info}_entite", '', true)
4694
-	) {
4695
-		$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4696
-	} // Sinon on prend directement le champ SQL tel quel
4697
-	else {
4698
-		$info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4699
-	}
4700
-
4701
-	// On va ensuite appliquer les traitements automatiques si besoin
4702
-	if (!$etoile) {
4703
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4704
-		// mais ce fonctionnement est a ameliorer !
4705
-		$info_generee = appliquer_traitement_champ(
4706
-			$info_generee,
4707
-			$info,
4708
-			table_objet($type_objet),
4709
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4710
-		);
4711
-	}
4712
-
4713
-	return $info_generee;
4619
+    static $trouver_table = null;
4620
+    static $objets;
4621
+
4622
+    // On verifie qu'on a tout ce qu'il faut
4623
+    $id_objet = intval($id_objet);
4624
+    if (!($id_objet and $type_objet and $info)) {
4625
+        return '';
4626
+    }
4627
+
4628
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4629
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4630
+        return '';
4631
+    }
4632
+
4633
+    // Si on demande l'url, on retourne direct la fonction
4634
+    if ($info == 'url') {
4635
+        return generer_objet_url($id_objet, $type_objet, ...$params);
4636
+    }
4637
+
4638
+    // Sinon on va tout chercher dans la table et on garde en memoire
4639
+    $demande_titre = ($info === 'titre');
4640
+    $demande_introduction = ($info === 'introduction');
4641
+
4642
+    // 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
4643
+    if (
4644
+        !isset($objets[$type_objet][$id_objet])
4645
+        or
4646
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4647
+    ) {
4648
+        if (!$trouver_table) {
4649
+            $trouver_table = charger_fonction('trouver_table', 'base');
4650
+        }
4651
+        $desc = $trouver_table(table_objet_sql($type_objet));
4652
+        if (!$desc) {
4653
+            return $objets[$type_objet] = false;
4654
+        }
4655
+
4656
+        // Si on demande le titre, on le gere en interne
4657
+        $champ_titre = '';
4658
+        if ($demande_titre) {
4659
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4660
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4661
+        }
4662
+        include_spip('base/abstract_sql');
4663
+        include_spip('base/connect_sql');
4664
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4665
+            '*' . $champ_titre,
4666
+            $desc['table_sql'],
4667
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4668
+        );
4669
+
4670
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4671
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4672
+    }
4673
+
4674
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4675
+    // ajouter la longueur au début des params supplémentaires
4676
+    if ($demande_introduction) {
4677
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4678
+        array_unshift($params, $introduction_longueur);
4679
+    }
4680
+
4681
+    // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4682
+    if (
4683
+        $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)
4684
+        // @deprecated 4.1 generer_TRUC_TYPE
4685
+        or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)
4686
+    ) {
4687
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4688
+    }
4689
+    // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4690
+    elseif (
4691
+        $generer = charger_fonction("generer_objet_{$info}", '', true)
4692
+        // @deprecated 4.1 generer_TRUC_entite
4693
+        or $generer = charger_fonction("generer_{$info}_entite", '', true)
4694
+    ) {
4695
+        $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4696
+    } // Sinon on prend directement le champ SQL tel quel
4697
+    else {
4698
+        $info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4699
+    }
4700
+
4701
+    // On va ensuite appliquer les traitements automatiques si besoin
4702
+    if (!$etoile) {
4703
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4704
+        // mais ce fonctionnement est a ameliorer !
4705
+        $info_generee = appliquer_traitement_champ(
4706
+            $info_generee,
4707
+            $info,
4708
+            table_objet($type_objet),
4709
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4710
+        );
4711
+    }
4712
+
4713
+    return $info_generee;
4714 4714
 }
4715 4715
 
4716 4716
 /**
@@ -4718,7 +4718,7 @@  discard block
 block discarded – undo
4718 4718
  * @see generer_objet_info
4719 4719
  */
4720 4720
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) {
4721
-	return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4721
+    return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4722 4722
 }
4723 4723
 
4724 4724
 /**
@@ -4751,36 +4751,36 @@  discard block
 block discarded – undo
4751 4751
  */
4752 4752
 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 {
4753 4753
 
4754
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4755
-	$texte = $ligne_sql['texte'] ?? '';
4756
-	// En absence de descriptif, on se rabat sur chapo + texte
4757
-	if (isset($ligne_sql['chapo'])) {
4758
-		$chapo = $ligne_sql['chapo'];
4759
-		$texte = strlen($descriptif) ?
4760
-			'' :
4761
-			"$chapo \n\n $texte";
4762
-	}
4754
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4755
+    $texte = $ligne_sql['texte'] ?? '';
4756
+    // En absence de descriptif, on se rabat sur chapo + texte
4757
+    if (isset($ligne_sql['chapo'])) {
4758
+        $chapo = $ligne_sql['chapo'];
4759
+        $texte = strlen($descriptif) ?
4760
+            '' :
4761
+            "$chapo \n\n $texte";
4762
+    }
4763 4763
 
4764
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4765
-	if (!intval($longueur_ou_suite)) {
4766
-		$longueur = intval($introduction_longueur ?: 600);
4767
-	} else {
4768
-		$longueur = intval($longueur_ou_suite);
4769
-	}
4764
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4765
+    if (!intval($longueur_ou_suite)) {
4766
+        $longueur = intval($introduction_longueur ?: 600);
4767
+    } else {
4768
+        $longueur = intval($longueur_ou_suite);
4769
+    }
4770 4770
 
4771
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4772
-	// Ex : #INTRODUCTION{...}
4773
-	if (
4774
-		is_null($suite)
4775
-		and !intval($longueur_ou_suite)
4776
-	) {
4777
-		$suite = $longueur_ou_suite;
4778
-	}
4771
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4772
+    // Ex : #INTRODUCTION{...}
4773
+    if (
4774
+        is_null($suite)
4775
+        and !intval($longueur_ou_suite)
4776
+    ) {
4777
+        $suite = $longueur_ou_suite;
4778
+    }
4779 4779
 
4780
-	$f = chercher_filtre('introduction');
4781
-	$introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4780
+    $f = chercher_filtre('introduction');
4781
+    $introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4782 4782
 
4783
-	return $introduction;
4783
+    return $introduction;
4784 4784
 }
4785 4785
 
4786 4786
 /**
@@ -4788,7 +4788,7 @@  discard block
 block discarded – undo
4788 4788
  * @see generer_objet_introduction
4789 4789
  */
4790 4790
 function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') {
4791
-	return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4791
+    return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4792 4792
 }
4793 4793
 
4794 4794
 /**
@@ -4802,49 +4802,49 @@  discard block
 block discarded – undo
4802 4802
  * @return string
4803 4803
  */
4804 4804
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') {
4805
-	if (!$champ) {
4806
-		return $texte;
4807
-	}
4805
+    if (!$champ) {
4806
+        return $texte;
4807
+    }
4808 4808
 
4809
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4810
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4811
-	include_fichiers_fonctions();
4809
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4810
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4811
+    include_fichiers_fonctions();
4812 4812
 
4813
-	$champ = strtoupper($champ);
4814
-	$traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4815
-	if (!$traitements or !is_array($traitements)) {
4816
-		return $texte;
4817
-	}
4813
+    $champ = strtoupper($champ);
4814
+    $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4815
+    if (!$traitements or !is_array($traitements)) {
4816
+        return $texte;
4817
+    }
4818 4818
 
4819
-	$traitement = '';
4820
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4821
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4822
-		$table_objet = table_objet($table_objet);
4823
-		if (isset($traitements[$table_objet])) {
4824
-			$traitement = $traitements[$table_objet];
4825
-		}
4826
-	}
4827
-	if (!$traitement and isset($traitements[0])) {
4828
-		$traitement = $traitements[0];
4829
-	}
4830
-	// (sinon prendre le premier de la liste par defaut ?)
4819
+    $traitement = '';
4820
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4821
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4822
+        $table_objet = table_objet($table_objet);
4823
+        if (isset($traitements[$table_objet])) {
4824
+            $traitement = $traitements[$table_objet];
4825
+        }
4826
+    }
4827
+    if (!$traitement and isset($traitements[0])) {
4828
+        $traitement = $traitements[0];
4829
+    }
4830
+    // (sinon prendre le premier de la liste par defaut ?)
4831 4831
 
4832
-	if (!$traitement) {
4833
-		return $texte;
4834
-	}
4832
+    if (!$traitement) {
4833
+        return $texte;
4834
+    }
4835 4835
 
4836
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4836
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4837 4837
 
4838
-	// signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4839
-	if (test_espace_prive()) {
4840
-		$env['espace_prive'] = 1;
4841
-	}
4838
+    // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4839
+    if (test_espace_prive()) {
4840
+        $env['espace_prive'] = 1;
4841
+    }
4842 4842
 
4843
-	// Fournir $connect et $Pile[0] au traitement si besoin
4844
-	$Pile = [0 => $env];
4845
-	eval("\$texte = $traitement;");
4843
+    // Fournir $connect et $Pile[0] au traitement si besoin
4844
+    $Pile = [0 => $env];
4845
+    eval("\$texte = $traitement;");
4846 4846
 
4847
-	return $texte;
4847
+    return $texte;
4848 4848
 }
4849 4849
 
4850 4850
 
@@ -4858,21 +4858,21 @@  discard block
 block discarded – undo
4858 4858
  * @return string
4859 4859
  */
4860 4860
 function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string {
4861
-	include_spip('inc/liens');
4862
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4863
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4864
-	// le raccourcis n'est plus valide
4865
-	$titre = typo($titre['titre'] ?? '');
4866
-	// on essaye avec generer_info_entite ?
4867
-	if (!strlen($titre) and !$connect) {
4868
-		$titre = generer_objet_info($id_objet, $objet, 'titre');
4869
-	}
4870
-	if (!strlen($titre)) {
4871
-		$titre = _T('info_sans_titre');
4872
-	}
4873
-	$url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4861
+    include_spip('inc/liens');
4862
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4863
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4864
+    // le raccourcis n'est plus valide
4865
+    $titre = typo($titre['titre'] ?? '');
4866
+    // on essaye avec generer_info_entite ?
4867
+    if (!strlen($titre) and !$connect) {
4868
+        $titre = generer_objet_info($id_objet, $objet, 'titre');
4869
+    }
4870
+    if (!strlen($titre)) {
4871
+        $titre = _T('info_sans_titre');
4872
+    }
4873
+    $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4874 4874
 
4875
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4875
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4876 4876
 }
4877 4877
 
4878 4878
 /**
@@ -4880,7 +4880,7 @@  discard block
 block discarded – undo
4880 4880
  * @see generer_objet_lien
4881 4881
  */
4882 4882
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4883
-	return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
4883
+    return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
4884 4884
 }
4885 4885
 
4886 4886
 /**
@@ -4896,15 +4896,15 @@  discard block
 block discarded – undo
4896 4896
  * @return string
4897 4897
  */
4898 4898
 function wrap($texte, $wrap) {
4899
-	$balises = extraire_balises($wrap);
4900
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4901
-		$texte = $wrap . $texte;
4902
-		$regs = array_reverse($regs[1]);
4903
-		$wrap = '</' . implode('></', $regs) . '>';
4904
-		$texte = $texte . $wrap;
4905
-	}
4899
+    $balises = extraire_balises($wrap);
4900
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4901
+        $texte = $wrap . $texte;
4902
+        $regs = array_reverse($regs[1]);
4903
+        $wrap = '</' . implode('></', $regs) . '>';
4904
+        $texte = $texte . $wrap;
4905
+    }
4906 4906
 
4907
-	return $texte;
4907
+    return $texte;
4908 4908
 }
4909 4909
 
4910 4910
 
@@ -4924,44 +4924,44 @@  discard block
 block discarded – undo
4924 4924
  * @return array|mixed|string
4925 4925
  */
4926 4926
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
4927
-	if (is_string($u)) {
4928
-		$u = typo($u);
4927
+    if (is_string($u)) {
4928
+        $u = typo($u);
4929 4929
 
4930
-		return $u;
4931
-	}
4930
+        return $u;
4931
+    }
4932 4932
 
4933
-	// caster $u en array si besoin
4934
-	if (is_object($u)) {
4935
-		$u = (array)$u;
4936
-	}
4933
+    // caster $u en array si besoin
4934
+    if (is_object($u)) {
4935
+        $u = (array)$u;
4936
+    }
4937 4937
 
4938
-	if (is_array($u)) {
4939
-		$out = '';
4940
-		// toutes les cles sont numeriques ?
4941
-		// et aucun enfant n'est un tableau
4942
-		// liste simple separee par des virgules
4943
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4944
-		$array_values = array_map('is_array', $u);
4945
-		$object_values = array_map('is_object', $u);
4946
-		if (
4947
-			array_sum($numeric_keys) == count($numeric_keys)
4948
-			and !array_sum($array_values)
4949
-			and !array_sum($object_values)
4950
-		) {
4951
-			return join(', ', array_map('filtre_print_dist', $u));
4952
-		}
4938
+    if (is_array($u)) {
4939
+        $out = '';
4940
+        // toutes les cles sont numeriques ?
4941
+        // et aucun enfant n'est un tableau
4942
+        // liste simple separee par des virgules
4943
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4944
+        $array_values = array_map('is_array', $u);
4945
+        $object_values = array_map('is_object', $u);
4946
+        if (
4947
+            array_sum($numeric_keys) == count($numeric_keys)
4948
+            and !array_sum($array_values)
4949
+            and !array_sum($object_values)
4950
+        ) {
4951
+            return join(', ', array_map('filtre_print_dist', $u));
4952
+        }
4953 4953
 
4954
-		// sinon on passe a la ligne et on indente
4955
-		$i_str = str_pad('', $indent, ' ');
4956
-		foreach ($u as $k => $v) {
4957
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4958
-		}
4954
+        // sinon on passe a la ligne et on indente
4955
+        $i_str = str_pad('', $indent, ' ');
4956
+        foreach ($u as $k => $v) {
4957
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4958
+        }
4959 4959
 
4960
-		return $out;
4961
-	}
4960
+        return $out;
4961
+    }
4962 4962
 
4963
-	// on sait pas quoi faire...
4964
-	return $u;
4963
+    // on sait pas quoi faire...
4964
+    return $u;
4965 4965
 }
4966 4966
 
4967 4967
 
@@ -4974,10 +4974,10 @@  discard block
 block discarded – undo
4974 4974
  * @return string|array
4975 4975
  */
4976 4976
 function objet_info($objet, $info) {
4977
-	$table = table_objet_sql($objet);
4978
-	$infos = lister_tables_objets_sql($table);
4977
+    $table = table_objet_sql($objet);
4978
+    $infos = lister_tables_objets_sql($table);
4979 4979
 
4980
-	return ($infos[$info] ?? '');
4980
+    return ($infos[$info] ?? '');
4981 4981
 }
4982 4982
 
4983 4983
 /**
@@ -4992,11 +4992,11 @@  discard block
 block discarded – undo
4992 4992
  *     texte traduit du comptage, tel que '3 articles'
4993 4993
  */
4994 4994
 function objet_afficher_nb($nb, $objet) {
4995
-	if (!$nb) {
4996
-		return _T(objet_info($objet, 'info_aucun_objet'));
4997
-	} else {
4998
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
4999
-	}
4995
+    if (!$nb) {
4996
+        return _T(objet_info($objet, 'info_aucun_objet'));
4997
+    } else {
4998
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
4999
+    }
5000 5000
 }
5001 5001
 
5002 5002
 /**
@@ -5008,11 +5008,11 @@  discard block
 block discarded – undo
5008 5008
  * @return string
5009 5009
  */
5010 5010
 function objet_icone($objet, $taille = 24, $class = '') {
5011
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5012
-	$icone = chemin_image($icone);
5013
-	$balise_img = charger_filtre('balise_img');
5011
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5012
+    $icone = chemin_image($icone);
5013
+    $balise_img = charger_filtre('balise_img');
5014 5014
 
5015
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5015
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5016 5016
 }
5017 5017
 
5018 5018
 /**
@@ -5033,12 +5033,12 @@  discard block
 block discarded – undo
5033 5033
  * @return string
5034 5034
  */
5035 5035
 function objet_T($objet, $chaine, $args = [], $options = []) {
5036
-	$chaine = explode(':', $chaine);
5037
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5038
-		return $t;
5039
-	}
5040
-	$chaine = implode(':', $chaine);
5041
-	return _T($chaine, $args, $options);
5036
+    $chaine = explode(':', $chaine);
5037
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5038
+        return $t;
5039
+    }
5040
+    $chaine = implode(':', $chaine);
5041
+    return _T($chaine, $args, $options);
5042 5042
 }
5043 5043
 
5044 5044
 /**
@@ -5052,18 +5052,18 @@  discard block
 block discarded – undo
5052 5052
  * @return string      Code HTML
5053 5053
  */
5054 5054
 function insert_head_css_conditionnel($flux) {
5055
-	if (
5056
-		strpos($flux, '<!-- insert_head_css -->') === false
5057
-		and $p = strpos($flux, '<!-- insert_head -->')
5058
-	) {
5059
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
5060
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5061
-			$p = $p1;
5062
-		}
5063
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5064
-	}
5055
+    if (
5056
+        strpos($flux, '<!-- insert_head_css -->') === false
5057
+        and $p = strpos($flux, '<!-- insert_head -->')
5058
+    ) {
5059
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
5060
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5061
+            $p = $p1;
5062
+        }
5063
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5064
+    }
5065 5065
 
5066
-	return $flux;
5066
+    return $flux;
5067 5067
 }
5068 5068
 
5069 5069
 /**
@@ -5086,75 +5086,75 @@  discard block
 block discarded – undo
5086 5086
  * @return string
5087 5087
  */
5088 5088
 function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') {
5089
-	if (isset($contexte['format'])) {
5090
-		$extension = $contexte['format'];
5091
-		unset($contexte['format']);
5092
-	} else {
5093
-		$extension = 'html';
5094
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5095
-			$extension = $m[1];
5096
-		}
5097
-	}
5098
-	// recuperer le contenu produit par le squelette
5099
-	$options['raw'] = true;
5100
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5101
-
5102
-	// calculer le nom de la css
5103
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5104
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5105
-	$contexte_implicite = calculer_contexte_implicite();
5106
-
5107
-	// par defaut on hash selon les contextes qui sont a priori moins variables
5108
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5109
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5110
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5111
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5112
-	}
5113
-	else {
5114
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5115
-		ksort($contexte);
5116
-		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5117
-	}
5118
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5119
-
5120
-	// mettre a jour le fichier si il n'existe pas
5121
-	// ou trop ancien
5122
-	// le dernier fichier produit est toujours suffixe par .last
5123
-	// et recopie sur le fichier cible uniquement si il change
5124
-	if (
5125
-		!file_exists($filename)
5126
-		or !file_exists($filename . '.last')
5127
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5128
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5129
-	) {
5130
-		$contenu = $cache['texte'];
5131
-		// passer les urls en absolu si c'est une css
5132
-		if ($extension == 'css') {
5133
-			$contenu = urls_absolues_css(
5134
-				$contenu,
5135
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5136
-			);
5137
-		}
5138
-
5139
-		$comment = '';
5140
-		// ne pas insérer de commentaire sur certains formats
5141
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
5142
-			$comment = "/* #PRODUIRE{fond=$fond";
5143
-			foreach ($contexte as $k => $v) {
5144
-				if (is_array($v)) {
5145
-					$v = var_export($v, true);
5146
-				}
5147
-				$comment .= ",$k=$v";
5148
-			}
5149
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5150
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5151
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5152
-		}
5153
-		// et ecrire le fichier si il change
5154
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5155
-	}
5156
-
5157
-	return timestamp($filename);
5089
+    if (isset($contexte['format'])) {
5090
+        $extension = $contexte['format'];
5091
+        unset($contexte['format']);
5092
+    } else {
5093
+        $extension = 'html';
5094
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5095
+            $extension = $m[1];
5096
+        }
5097
+    }
5098
+    // recuperer le contenu produit par le squelette
5099
+    $options['raw'] = true;
5100
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
5101
+
5102
+    // calculer le nom de la css
5103
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5104
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5105
+    $contexte_implicite = calculer_contexte_implicite();
5106
+
5107
+    // par defaut on hash selon les contextes qui sont a priori moins variables
5108
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5109
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5110
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5111
+        $hash = md5($contexte_implicite['host'] . '::' . $cache);
5112
+    }
5113
+    else {
5114
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5115
+        ksort($contexte);
5116
+        $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5117
+    }
5118
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5119
+
5120
+    // mettre a jour le fichier si il n'existe pas
5121
+    // ou trop ancien
5122
+    // le dernier fichier produit est toujours suffixe par .last
5123
+    // et recopie sur le fichier cible uniquement si il change
5124
+    if (
5125
+        !file_exists($filename)
5126
+        or !file_exists($filename . '.last')
5127
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5128
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5129
+    ) {
5130
+        $contenu = $cache['texte'];
5131
+        // passer les urls en absolu si c'est une css
5132
+        if ($extension == 'css') {
5133
+            $contenu = urls_absolues_css(
5134
+                $contenu,
5135
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5136
+            );
5137
+        }
5138
+
5139
+        $comment = '';
5140
+        // ne pas insérer de commentaire sur certains formats
5141
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
5142
+            $comment = "/* #PRODUIRE{fond=$fond";
5143
+            foreach ($contexte as $k => $v) {
5144
+                if (is_array($v)) {
5145
+                    $v = var_export($v, true);
5146
+                }
5147
+                $comment .= ",$k=$v";
5148
+            }
5149
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5150
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5151
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
5152
+        }
5153
+        // et ecrire le fichier si il change
5154
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5155
+    }
5156
+
5157
+    return timestamp($filename);
5158 5158
 }
5159 5159
 
5160 5160
 /**
@@ -5167,15 +5167,15 @@  discard block
 block discarded – undo
5167 5167
  *    $fichier auquel on a ajouté le timestamp
5168 5168
  */
5169 5169
 function timestamp($fichier) {
5170
-	if (
5171
-		!$fichier
5172
-		or !file_exists($fichier)
5173
-		or !$m = filemtime($fichier)
5174
-	) {
5175
-		return $fichier;
5176
-	}
5170
+    if (
5171
+        !$fichier
5172
+        or !file_exists($fichier)
5173
+        or !$m = filemtime($fichier)
5174
+    ) {
5175
+        return $fichier;
5176
+    }
5177 5177
 
5178
-	return "$fichier?$m";
5178
+    return "$fichier?$m";
5179 5179
 }
5180 5180
 
5181 5181
 /**
@@ -5185,11 +5185,11 @@  discard block
 block discarded – undo
5185 5185
  * @return string
5186 5186
  */
5187 5187
 function supprimer_timestamp($url) {
5188
-	if (strpos($url, '?') === false) {
5189
-		return $url;
5190
-	}
5188
+    if (strpos($url, '?') === false) {
5189
+        return $url;
5190
+    }
5191 5191
 
5192
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5192
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5193 5193
 }
5194 5194
 
5195 5195
 /**
@@ -5204,15 +5204,15 @@  discard block
 block discarded – undo
5204 5204
  * @return string
5205 5205
  */
5206 5206
 function filtre_nettoyer_titre_email_dist($titre) {
5207
-	include_spip('inc/envoyer_mail');
5207
+    include_spip('inc/envoyer_mail');
5208 5208
 
5209
-	$titre = nettoyer_titre_email($titre);
5210
-	// on est dans un squelette : securiser le retour
5211
-	if (strpos($titre, '<') !== false) {
5212
-		$titre = interdire_scripts($titre);
5213
-	}
5209
+    $titre = nettoyer_titre_email($titre);
5210
+    // on est dans un squelette : securiser le retour
5211
+    if (strpos($titre, '<') !== false) {
5212
+        $titre = interdire_scripts($titre);
5213
+    }
5214 5214
 
5215
-	return $titre;
5215
+    return $titre;
5216 5216
 }
5217 5217
 
5218 5218
 /**
@@ -5234,27 +5234,27 @@  discard block
 block discarded – undo
5234 5234
  * @return string
5235 5235
  */
5236 5236
 function filtre_chercher_rubrique_dist(
5237
-	$titre,
5238
-	$id_objet,
5239
-	$id_parent,
5240
-	$objet,
5241
-	$id_secteur,
5242
-	$restreint,
5243
-	$actionable = false,
5244
-	$retour_sans_cadre = false
5237
+    $titre,
5238
+    $id_objet,
5239
+    $id_parent,
5240
+    $objet,
5241
+    $id_secteur,
5242
+    $restreint,
5243
+    $actionable = false,
5244
+    $retour_sans_cadre = false
5245 5245
 ) {
5246
-	include_spip('inc/filtres_ecrire');
5246
+    include_spip('inc/filtres_ecrire');
5247 5247
 
5248
-	return chercher_rubrique(
5249
-		$titre,
5250
-		$id_objet,
5251
-		$id_parent,
5252
-		$objet,
5253
-		$id_secteur,
5254
-		$restreint,
5255
-		$actionable,
5256
-		$retour_sans_cadre
5257
-	);
5248
+    return chercher_rubrique(
5249
+        $titre,
5250
+        $id_objet,
5251
+        $id_parent,
5252
+        $objet,
5253
+        $id_secteur,
5254
+        $restreint,
5255
+        $actionable,
5256
+        $retour_sans_cadre
5257
+    );
5258 5258
 }
5259 5259
 
5260 5260
 /**
@@ -5283,56 +5283,56 @@  discard block
 block discarded – undo
5283 5283
  *     Chaîne vide si l'accès est autorisé
5284 5284
  */
5285 5285
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5286
-	if ($ok) {
5287
-		return '';
5288
-	}
5289
-
5290
-	// Vider tous les tampons
5291
-	$level = @ob_get_level();
5292
-	while ($level--) {
5293
-		@ob_end_clean();
5294
-	}
5295
-
5296
-	include_spip('inc/headers');
5297
-
5298
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5299
-	if ($url) {
5300
-		redirige_par_entete($url, '', $statut);
5301
-	}
5302
-
5303
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5304
-	if (!is_numeric($statut) and is_null($message)) {
5305
-		$message = $statut;
5306
-		$statut = 0;
5307
-	}
5308
-	if (!$message) {
5309
-		$message = '';
5310
-	}
5311
-	$statut = intval($statut);
5312
-
5313
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5314
-	if (test_espace_prive()) {
5315
-		if (!$statut or !in_array($statut, [404, 403])) {
5316
-			$statut = 403;
5317
-		}
5318
-		http_response_code(403);
5319
-		$echec = charger_fonction('403', 'exec');
5320
-		$echec($message);
5321
-	} else {
5322
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5323
-		if (!$statut) {
5324
-			$statut = 404;
5325
-		}
5326
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5327
-		http_response_code($statut);
5328
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5329
-		if ($statut >= 400) {
5330
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5331
-		}
5332
-	}
5333
-
5334
-
5335
-	exit;
5286
+    if ($ok) {
5287
+        return '';
5288
+    }
5289
+
5290
+    // Vider tous les tampons
5291
+    $level = @ob_get_level();
5292
+    while ($level--) {
5293
+        @ob_end_clean();
5294
+    }
5295
+
5296
+    include_spip('inc/headers');
5297
+
5298
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5299
+    if ($url) {
5300
+        redirige_par_entete($url, '', $statut);
5301
+    }
5302
+
5303
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5304
+    if (!is_numeric($statut) and is_null($message)) {
5305
+        $message = $statut;
5306
+        $statut = 0;
5307
+    }
5308
+    if (!$message) {
5309
+        $message = '';
5310
+    }
5311
+    $statut = intval($statut);
5312
+
5313
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5314
+    if (test_espace_prive()) {
5315
+        if (!$statut or !in_array($statut, [404, 403])) {
5316
+            $statut = 403;
5317
+        }
5318
+        http_response_code(403);
5319
+        $echec = charger_fonction('403', 'exec');
5320
+        $echec($message);
5321
+    } else {
5322
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5323
+        if (!$statut) {
5324
+            $statut = 404;
5325
+        }
5326
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5327
+        http_response_code($statut);
5328
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5329
+        if ($statut >= 400) {
5330
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5331
+        }
5332
+    }
5333
+
5334
+
5335
+    exit;
5336 5336
 }
5337 5337
 
5338 5338
 /**
@@ -5343,11 +5343,11 @@  discard block
 block discarded – undo
5343 5343
  * @return string
5344 5344
  */
5345 5345
 function filtre_compacte_dist($source, $format = null) {
5346
-	if (function_exists('minifier')) {
5347
-		return minifier($source, $format);
5348
-	}
5346
+    if (function_exists('minifier')) {
5347
+        return minifier($source, $format);
5348
+    }
5349 5349
 
5350
-	return $source;
5350
+    return $source;
5351 5351
 }
5352 5352
 
5353 5353
 
@@ -5359,32 +5359,32 @@  discard block
 block discarded – undo
5359 5359
  * @return string
5360 5360
  */
5361 5361
 function spip_affiche_mot_de_passe_masque(?string $passe, bool $afficher_partiellement = false, ?int $portion_pourcent = null): string {
5362
-	$passe ??= '';
5363
-	$l = strlen($passe);
5364
-
5365
-	if ($l <= 8 or !$afficher_partiellement) {
5366
-		if (!$l) {
5367
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5368
-		}
5369
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5370
-	}
5371
-
5372
-	if (is_null($portion_pourcent)) {
5373
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5374
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5375
-		}
5376
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5377
-	}
5378
-	if ($portion_pourcent >= 100) {
5379
-		return $passe;
5380
-	}
5381
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5382
-	$e = max($e, 0);
5383
-	$mid = str_pad('', $l - 2 * $e, '*');
5384
-	if ($e > 0 and strlen($mid) > 8) {
5385
-		$mid = '***...***';
5386
-	}
5387
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5362
+    $passe ??= '';
5363
+    $l = strlen($passe);
5364
+
5365
+    if ($l <= 8 or !$afficher_partiellement) {
5366
+        if (!$l) {
5367
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5368
+        }
5369
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5370
+    }
5371
+
5372
+    if (is_null($portion_pourcent)) {
5373
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5374
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5375
+        }
5376
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5377
+    }
5378
+    if ($portion_pourcent >= 100) {
5379
+        return $passe;
5380
+    }
5381
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5382
+    $e = max($e, 0);
5383
+    $mid = str_pad('', $l - 2 * $e, '*');
5384
+    if ($e > 0 and strlen($mid) > 8) {
5385
+        $mid = '***...***';
5386
+    }
5387
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5388 5388
 }
5389 5389
 
5390 5390
 
@@ -5405,64 +5405,64 @@  discard block
 block discarded – undo
5405 5405
  */
5406 5406
 function identifiant_slug($texte, $type = '', $options = []) {
5407 5407
 
5408
-	$original = $texte;
5409
-	$separateur = ($options['separateur'] ?? '_');
5410
-	$longueur_maxi = ($options['longueur_maxi'] ?? 60);
5411
-	$longueur_mini = ($options['longueur_mini'] ?? 0);
5408
+    $original = $texte;
5409
+    $separateur = ($options['separateur'] ?? '_');
5410
+    $longueur_maxi = ($options['longueur_maxi'] ?? 60);
5411
+    $longueur_mini = ($options['longueur_mini'] ?? 0);
5412 5412
 
5413
-	if (!function_exists('translitteration')) {
5414
-		include_spip('inc/charsets');
5415
-	}
5413
+    if (!function_exists('translitteration')) {
5414
+        include_spip('inc/charsets');
5415
+    }
5416 5416
 
5417
-	// pas de balise html
5418
-	if (strpos($texte, '<') !== false) {
5419
-		$texte = strip_tags($texte);
5420
-	}
5421
-	if (strpos($texte, '&') !== false) {
5422
-		$texte = unicode2charset($texte);
5423
-	}
5424
-	// On enlève les espaces indésirables
5425
-	$texte = trim($texte);
5417
+    // pas de balise html
5418
+    if (strpos($texte, '<') !== false) {
5419
+        $texte = strip_tags($texte);
5420
+    }
5421
+    if (strpos($texte, '&') !== false) {
5422
+        $texte = unicode2charset($texte);
5423
+    }
5424
+    // On enlève les espaces indésirables
5425
+    $texte = trim($texte);
5426 5426
 
5427
-	// On enlève les accents et cie
5428
-	$texte = translitteration($texte);
5427
+    // On enlève les accents et cie
5428
+    $texte = translitteration($texte);
5429 5429
 
5430
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5431
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5430
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5431
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5432 5432
 
5433
-	// nettoyer les doubles occurences du separateur si besoin
5434
-	while (strpos($texte, (string) "$separateur$separateur") !== false) {
5435
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5436
-	}
5433
+    // nettoyer les doubles occurences du separateur si besoin
5434
+    while (strpos($texte, (string) "$separateur$separateur") !== false) {
5435
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5436
+    }
5437 5437
 
5438
-	// pas de separateur au debut ni a la fin
5439
-	$texte = trim($texte, $separateur);
5438
+    // pas de separateur au debut ni a la fin
5439
+    $texte = trim($texte, $separateur);
5440 5440
 
5441
-	// en minuscules
5442
-	$texte = strtolower($texte);
5441
+    // en minuscules
5442
+    $texte = strtolower($texte);
5443 5443
 
5444
-	switch ($type) {
5445
-		case 'class':
5446
-		case 'id':
5447
-		case 'anchor':
5448
-			if (preg_match(',^\d,', $texte)) {
5449
-				$texte = substr($type, 0, 1) . $texte;
5450
-			}
5451
-	}
5444
+    switch ($type) {
5445
+        case 'class':
5446
+        case 'id':
5447
+        case 'anchor':
5448
+            if (preg_match(',^\d,', $texte)) {
5449
+                $texte = substr($type, 0, 1) . $texte;
5450
+            }
5451
+    }
5452 5452
 
5453
-	if (strlen($texte) > $longueur_maxi) {
5454
-		$texte = substr($texte, 0, $longueur_maxi);
5455
-	}
5453
+    if (strlen($texte) > $longueur_maxi) {
5454
+        $texte = substr($texte, 0, $longueur_maxi);
5455
+    }
5456 5456
 
5457
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5458
-		if (preg_match(',^\d,', $texte)) {
5459
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5460
-		}
5461
-		$texte .= $separateur . md5($original);
5462
-		$texte = substr($texte, 0, $longueur_mini);
5463
-	}
5457
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5458
+        if (preg_match(',^\d,', $texte)) {
5459
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5460
+        }
5461
+        $texte .= $separateur . md5($original);
5462
+        $texte = substr($texte, 0, $longueur_mini);
5463
+    }
5464 5464
 
5465
-	return $texte;
5465
+    return $texte;
5466 5466
 }
5467 5467
 
5468 5468
 
@@ -5483,11 +5483,11 @@  discard block
 block discarded – undo
5483 5483
  * @exemple `<:info_maximum|label_nettoyer:>`
5484 5484
  */
5485 5485
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5486
-	$label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5487
-	if ($ucfirst) {
5488
-		$label = spip_ucfirst($label);
5489
-	}
5490
-	return $label;
5486
+    $label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5487
+    if ($ucfirst) {
5488
+        $label = spip_ucfirst($label);
5489
+    }
5490
+    return $label;
5491 5491
 }
5492 5492
 
5493 5493
 /**
@@ -5500,8 +5500,8 @@  discard block
 block discarded – undo
5500 5500
  * @exemple `<:info_maximum|label_ponctuer:>`
5501 5501
  */
5502 5502
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5503
-	$label = label_nettoyer($text, $ucfirst);
5504
-	return _T('label_ponctuer', ['label' => $label]);
5503
+    $label = label_nettoyer($text, $ucfirst);
5504
+    return _T('label_ponctuer', ['label' => $label]);
5505 5505
 }
5506 5506
 
5507 5507
 
@@ -5514,19 +5514,19 @@  discard block
 block discarded – undo
5514 5514
  * @return array
5515 5515
  */
5516 5516
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5517
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5518
-		return [];
5519
-	}
5517
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5518
+        return [];
5519
+    }
5520 5520
 
5521
-	// compatibilite signature inversee
5522
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5523
-		[$objet, $id_objet] = [$id_objet, $objet];
5524
-	}
5521
+    // compatibilite signature inversee
5522
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5523
+        [$objet, $id_objet] = [$id_objet, $objet];
5524
+    }
5525 5525
 
5526
-	if (!function_exists($fonction)) {
5527
-		include_spip('base/objets');
5528
-	}
5529
-	return $fonction($objet, $id_objet);
5526
+    if (!function_exists($fonction)) {
5527
+        include_spip('base/objets');
5528
+    }
5529
+    return $fonction($objet, $id_objet);
5530 5530
 }
5531 5531
 
5532 5532
 
@@ -5541,7 +5541,7 @@  discard block
 block discarded – undo
5541 5541
  * @return array
5542 5542
  */
5543 5543
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5544
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5544
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5545 5545
 }
5546 5546
 
5547 5547
 /**
@@ -5555,7 +5555,7 @@  discard block
 block discarded – undo
5555 5555
  * @return array
5556 5556
  */
5557 5557
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5558
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5558
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5559 5559
 }
5560 5560
 
5561 5561
 /**
@@ -5569,7 +5569,7 @@  discard block
 block discarded – undo
5569 5569
  * @return array
5570 5570
  */
5571 5571
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5572
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5572
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5573 5573
 }
5574 5574
 
5575 5575
 /**
@@ -5583,5 +5583,5 @@  discard block
 block discarded – undo
5583 5583
  * @return array
5584 5584
  */
5585 5585
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5586
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5586
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5587 5587
 }
Please login to merge, or discard this patch.
Spacing   +123 added lines, -124 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	}
97 97
 
98 98
 	include_fichiers_fonctions();
99
-	foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
99
+	foreach (['filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc] as $f) {
100 100
 		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101 101
 		if (is_callable($f)) {
102 102
 			return $f;
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 	// affichage "GIT [master: abcdef]"
232 232
 	$commit = $desc['commit_short'] ?? $desc['commit'];
233 233
 	if ($desc['branch']) {
234
-		$commit = $desc['branch'] . ': ' . $commit;
234
+		$commit = $desc['branch'].': '.$commit;
235 235
 	}
236 236
 	return "{$desc['vcs']} [$commit]";
237 237
 }
@@ -250,9 +250,9 @@  discard block
 block discarded – undo
250 250
 	}
251 251
 
252 252
 	// version installee par GIT
253
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
253
+	if (lire_fichier($dir.'/.git/HEAD', $c)) {
254 254
 		$currentHead = trim(substr($c, 4));
255
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
255
+		if (lire_fichier($dir.'/.git/'.$currentHead, $hash)) {
256 256
 			return [
257 257
 				'vcs' => 'GIT',
258 258
 				'branch' => basename($currentHead),
@@ -267,12 +267,12 @@  discard block
 block discarded – undo
267 267
 
268 268
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
269 269
 // et laisser passer les fonctions personnelles baptisees image_...
270
-$GLOBALS['spip_matrice']['image_graver'] = true;//'inc/filtres_images_mini.php';
271
-$GLOBALS['spip_matrice']['image_select'] = true;//'inc/filtres_images_mini.php';
272
-$GLOBALS['spip_matrice']['image_reduire'] = true;//'inc/filtres_images_mini.php';
273
-$GLOBALS['spip_matrice']['image_reduire_par'] = true;//'inc/filtres_images_mini.php';
274
-$GLOBALS['spip_matrice']['image_passe_partout'] = true;//'inc/filtres_images_mini.php';
275
-$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true;//'inc/filtres_images_mini.php';
270
+$GLOBALS['spip_matrice']['image_graver'] = true; //'inc/filtres_images_mini.php';
271
+$GLOBALS['spip_matrice']['image_select'] = true; //'inc/filtres_images_mini.php';
272
+$GLOBALS['spip_matrice']['image_reduire'] = true; //'inc/filtres_images_mini.php';
273
+$GLOBALS['spip_matrice']['image_reduire_par'] = true; //'inc/filtres_images_mini.php';
274
+$GLOBALS['spip_matrice']['image_passe_partout'] = true; //'inc/filtres_images_mini.php';
275
+$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true; //'inc/filtres_images_mini.php';
276 276
 
277 277
 $GLOBALS['spip_matrice']['couleur_html_to_hex'] = 'inc/filtres_images_mini.php';
278 278
 $GLOBALS['spip_matrice']['couleur_hex_to_hsl'] = 'inc/filtres_images_mini.php';
@@ -431,8 +431,8 @@  discard block
 block discarded – undo
431 431
  */
432 432
 function filtre_debug($val, $key = null) {
433 433
 	$debug = (
434
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
435
-		) . var_export($val, true);
434
+		is_null($key) ? '' : (var_export($key, true).' = ')
435
+		).var_export($val, true);
436 436
 
437 437
 	include_spip('inc/autoriser');
438 438
 	if (autoriser('webmestre')) {
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 		$is_file = false;
489 489
 	}
490 490
 	if ($is_file) {
491
-		$is_local_file = function ($path) {
491
+		$is_local_file = function($path) {
492 492
 			if (strpos($path, '?') !== false) {
493 493
 				$path = supprimer_timestamp($path);
494 494
 				// remove ?24px added by find_in_theme on .svg files
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
 					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
538 538
 						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
539 539
 							$srcover = $match[1];
540
-							$srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
540
+							$srcover_filter = $filtre("<img src='".$match[1]."' />", ...$args);
541 541
 							$srcover_filter = extraire_attribut($srcover_filter, 'src');
542 542
 							$reduit = str_replace($srcover, $srcover_filter, $reduit);
543 543
 						}
@@ -939,7 +939,7 @@  discard block
 block discarded – undo
939 939
 	// " -> &quot; et tout ce genre de choses
940 940
 	$u = $GLOBALS['meta']['pcre_u'];
941 941
 	$texte = str_replace('&nbsp;', ' ', $texte);
942
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
942
+	$texte = preg_replace('/\s{2,}/S'.$u, ' ', $texte);
943 943
 	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
944 944
 	$texte = entites_html($texte, false, false);
945 945
 	// mais bien echapper les double quotes !
@@ -1001,7 +1001,7 @@  discard block
 block discarded – undo
1001 1001
 		return '';
1002 1002
 	}
1003 1003
 	return preg_replace(
1004
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1004
+		',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S',
1005 1005
 		'',
1006 1006
 		$texte
1007 1007
 	);
@@ -1030,7 +1030,7 @@  discard block
 block discarded – undo
1030 1030
 	if (
1031 1031
 		$texte and
1032 1032
 		preg_match(
1033
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1033
+			',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S',
1034 1034
 			$texte,
1035 1035
 			$regs
1036 1036
 		)
@@ -1121,8 +1121,8 @@  discard block
 block discarded – undo
1121 1121
  **/
1122 1122
 function textebrut($texte) {
1123 1123
 	$u = $GLOBALS['meta']['pcre_u'];
1124
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1125
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1124
+	$texte = preg_replace('/\s+/S'.$u, ' ', $texte);
1125
+	$texte = preg_replace('/<(p|br)( [^>]*)?'.'>/iS', "\n\n", $texte);
1126 1126
 	$texte = preg_replace("/^\n+/", '', $texte);
1127 1127
 	$texte = preg_replace("/\n+$/", '', $texte);
1128 1128
 	$texte = preg_replace("/\n +/", "\n", $texte);
@@ -1156,7 +1156,7 @@  discard block
 block discarded – undo
1156 1156
 		)
1157 1157
 	) {
1158 1158
 		foreach ($liens[0] as $a) {
1159
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1159
+			$rel = 'noopener noreferrer '.extraire_attribut($a, 'rel');
1160 1160
 			$ablank = inserer_attribut($a, 'rel', $rel);
1161 1161
 			$ablank = inserer_attribut($ablank, 'target', '_blank');
1162 1162
 			$texte = str_replace($a, $ablank, $texte);
@@ -1181,7 +1181,7 @@  discard block
 block discarded – undo
1181 1181
 		foreach ($regs[0] as $a) {
1182 1182
 			$rel = extraire_attribut($a, 'rel') ?? '';
1183 1183
 			if (strpos($rel, 'nofollow') === false) {
1184
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1184
+				$rel = 'nofollow'.($rel ? " $rel" : '');
1185 1185
 				$anofollow = inserer_attribut($a, 'rel', $rel);
1186 1186
 				$texte = str_replace($a, $anofollow, $texte);
1187 1187
 			}
@@ -1210,7 +1210,7 @@  discard block
 block discarded – undo
1210 1210
 	$u = $GLOBALS['meta']['pcre_u'];
1211 1211
 	$texte = preg_replace('@</p>@iS', "\n", $texte);
1212 1212
 	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1213
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1213
+	$texte = preg_replace('@^\s*<br />@S'.$u, '', $texte);
1214 1214
 
1215 1215
 	return $texte;
1216 1216
 }
@@ -1241,7 +1241,7 @@  discard block
 block discarded – undo
1241 1241
 		return $texte;
1242 1242
 	}
1243 1243
 	include_spip('inc/texte');
1244
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1244
+	$tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ?
1245 1245
 		'div' : 'span';
1246 1246
 
1247 1247
 	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
@@ -1353,7 +1353,7 @@  discard block
 block discarded – undo
1353 1353
 	}
1354 1354
 	$u = $GLOBALS['meta']['pcre_u'];
1355 1355
 	if ($textebrut) {
1356
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1356
+		$texte = preg_replace([",\n,", ',\s(?=\s),msS'.$u], [' ', ''], textebrut($texte));
1357 1357
 	}
1358 1358
 	$texte = texte_backend($texte);
1359 1359
 	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
@@ -1388,7 +1388,7 @@  discard block
 block discarded – undo
1388 1388
 	# un message pour abs_url
1389 1389
 	$GLOBALS['mode_abs_url'] = 'url';
1390 1390
 	$url = trim($url);
1391
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1391
+	$r = ',^(?:'._PROTOCOLES_STD.'):?/?/?$,iS';
1392 1392
 
1393 1393
 	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1394 1394
 }
@@ -1595,7 +1595,7 @@  discard block
 block discarded – undo
1595 1595
 
1596 1596
 	$debut = '';
1597 1597
 	$suite = $texte;
1598
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1598
+	while ($t = strpos('-'.$suite, "\n", 1)) {
1599 1599
 		$debut .= substr($suite, 0, $t - 1);
1600 1600
 		$suite = substr($suite, $t);
1601 1601
 		$car = substr($suite, 0, 1);
@@ -1613,7 +1613,7 @@  discard block
 block discarded – undo
1613 1613
 			$suite = substr($suite, strlen($regs[0]));
1614 1614
 		}
1615 1615
 	}
1616
-	$texte = $debut . $suite;
1616
+	$texte = $debut.$suite;
1617 1617
 
1618 1618
 	if ($collecteurModeles) {
1619 1619
 		$texte = $collecteurModeles->retablir($texte);
@@ -1621,7 +1621,7 @@  discard block
 block discarded – undo
1621 1621
 
1622 1622
 	$texte = echappe_retour($texte);
1623 1623
 
1624
-	return $texte . $fin;
1624
+	return $texte.$fin;
1625 1625
 }
1626 1626
 
1627 1627
 
@@ -1897,7 +1897,7 @@  discard block
 block discarded – undo
1897 1897
 	if (is_array($balise)) {
1898 1898
 		array_walk(
1899 1899
 			$balise,
1900
-			function (&$a, $key, $t) {
1900
+			function(&$a, $key, $t) {
1901 1901
 				$a = extraire_attribut($a, $t);
1902 1902
 			},
1903 1903
 			$attribut
@@ -1995,14 +1995,14 @@  discard block
 block discarded – undo
1995 1995
 
1996 1996
 	if ($old !== null) {
1997 1997
 		// Remplacer l'ancien attribut du meme nom
1998
-		$balise = $r[1] . $insert . $r[5];
1998
+		$balise = $r[1].$insert.$r[5];
1999 1999
 	} else {
2000 2000
 		// preferer une balise " />" (comme <img />)
2001 2001
 		if (preg_match(',/>,', $balise)) {
2002
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2002
+			$balise = preg_replace(',\s?/>,S', $insert.' />', $balise, 1);
2003 2003
 		} // sinon une balise <a ...> ... </a>
2004 2004
 		else {
2005
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2005
+			$balise = preg_replace(',\s?>,S', $insert.'>', $balise, 1);
2006 2006
 		}
2007 2007
 	}
2008 2008
 
@@ -2057,7 +2057,7 @@  discard block
 block discarded – undo
2057 2057
 		if (
2058 2058
 			$class_courante
2059 2059
 			and str_contains($class_courante, (string) $c)
2060
-			and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2060
+			and preg_match('/(^|\s)'.preg_quote($c).'($|\s)/', $class_courante)
2061 2061
 		) {
2062 2062
 			$is_class_presente = true;
2063 2063
 		}
@@ -2065,12 +2065,12 @@  discard block
 block discarded – undo
2065 2065
 			in_array($operation, ['ajouter', 'commuter'])
2066 2066
 			and !$is_class_presente
2067 2067
 		) {
2068
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2068
+			$class_new = ltrim(rtrim($class_new ?? '').' '.$c);
2069 2069
 		} elseif (
2070 2070
 			in_array($operation, ['supprimer', 'commuter'])
2071 2071
 			and $is_class_presente
2072 2072
 		) {
2073
-			$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2073
+			$class_new = trim(preg_replace('/(^|\s)'.preg_quote($c).'($|\s)/', "\\1", $class_new));
2074 2074
 		}
2075 2075
 	}
2076 2076
 
@@ -2133,7 +2133,7 @@  discard block
 block discarded – undo
2133 2133
 // Quelques fonctions de calcul arithmetique
2134 2134
 //
2135 2135
 function floatstr($a) {
2136
- return str_replace(',', '.', (string)floatval($a));
2136
+ return str_replace(',', '.', (string) floatval($a));
2137 2137
 }
2138 2138
 function strize($f, $a, $b) {
2139 2139
  return floatstr($f(floatstr($a), floatstr($b)));
@@ -2274,13 +2274,13 @@  discard block
 block discarded – undo
2274 2274
 	if (!defined('_TAGS_NOM_AUTEUR')) {
2275 2275
 		define('_TAGS_NOM_AUTEUR', '');
2276 2276
 	}
2277
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2277
+	$tags_acceptes = array_unique(explode(',', 'multi,'._TAGS_NOM_AUTEUR));
2278 2278
 	foreach ($tags_acceptes as $tag) {
2279 2279
 		if (strlen($tag)) {
2280
-			$remp1[] = '<' . trim($tag) . '>';
2281
-			$remp1[] = '</' . trim($tag) . '>';
2282
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2283
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2280
+			$remp1[] = '<'.trim($tag).'>';
2281
+			$remp1[] = '</'.trim($tag).'>';
2282
+			$remp2[] = '\x60'.trim($tag).'\x61';
2283
+			$remp2[] = '\x60/'.trim($tag).'\x61';
2284 2284
 		}
2285 2285
 	}
2286 2286
 	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
@@ -2400,10 +2400,10 @@  discard block
 block discarded – undo
2400 2400
 	$fichier = basename($url);
2401 2401
 
2402 2402
 	return '<a rel="enclosure"'
2403
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2404
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2405
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2406
-	. '>' . $fichier . '</a>';
2403
+	. ($url ? ' href="'.spip_htmlspecialchars($url).'"' : '')
2404
+	. ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '')
2405
+	. ($length ? ' title="'.spip_htmlspecialchars($length).'"' : '')
2406
+	. '>'.$fichier.'</a>';
2407 2407
 }
2408 2408
 
2409 2409
 /**
@@ -2431,9 +2431,9 @@  discard block
 block discarded – undo
2431 2431
 			} # vieux data
2432 2432
 			$fichier = basename($url);
2433 2433
 			$enclosures[] = '<enclosure'
2434
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2435
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2436
-				. ($length ? ' length="' . $length . '"' : '')
2434
+				. ($url ? ' url="'.spip_htmlspecialchars($url).'"' : '')
2435
+				. ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '')
2436
+				. ($length ? ' length="'.$length.'"' : '')
2437 2437
 				. ' />';
2438 2438
 		}
2439 2439
 	}
@@ -2459,7 +2459,7 @@  discard block
 block discarded – undo
2459 2459
 		if (extraire_attribut($e, 'rel') == 'tag') {
2460 2460
 			$subjects .= '<dc:subject>'
2461 2461
 				. texte_backend(textebrut($e))
2462
-				. '</dc:subject>' . "\n";
2462
+				. '</dc:subject>'."\n";
2463 2463
 		}
2464 2464
 	}
2465 2465
 
@@ -2495,7 +2495,7 @@  discard block
 block discarded – undo
2495 2495
 	if (is_array($texte)) {
2496 2496
 		array_walk(
2497 2497
 			$texte,
2498
-			function (&$a, $key, $t) {
2498
+			function(&$a, $key, $t) {
2499 2499
 				$a = extraire_balise($a, $t);
2500 2500
 			},
2501 2501
 			$tag
@@ -2543,7 +2543,7 @@  discard block
 block discarded – undo
2543 2543
 	if (is_array($texte)) {
2544 2544
 		array_walk(
2545 2545
 			$texte,
2546
-			function (&$a, $key, $t) {
2546
+			function(&$a, $key, $t) {
2547 2547
 				$a = extraire_balises($a, $t);
2548 2548
 			},
2549 2549
 			$tag
@@ -2676,7 +2676,7 @@  discard block
 block discarded – undo
2676 2676
 		if ($fond != '404') {
2677 2677
 			$contexte = array_shift($p);
2678 2678
 			$contexte['page'] = $fond;
2679
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2679
+			$action = preg_replace('/([?]'.preg_quote($fond).'[^&=]*[0-9]+)(&|$)/', '?&', $action);
2680 2680
 		}
2681 2681
 	}
2682 2682
 	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
@@ -2731,9 +2731,9 @@  discard block
 block discarded – undo
2731 2731
 			. '"'
2732 2732
 			. (is_null($val)
2733 2733
 				? ''
2734
-				: ' value="' . entites_html($val) . '"'
2734
+				: ' value="'.entites_html($val).'"'
2735 2735
 			)
2736
-			. ' type="hidden"' . "\n/>";
2736
+			. ' type="hidden"'."\n/>";
2737 2737
 	}
2738 2738
 
2739 2739
 	return join('', $hidden);
@@ -2843,7 +2843,7 @@  discard block
 block discarded – undo
2843 2843
 
2844 2844
 	return preg_replace_callback(
2845 2845
 		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2846
-		fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2846
+		fn($x) => "url('".suivre_lien($path, $x[1])."')",
2847 2847
 		$contenu
2848 2848
 	);
2849 2849
 }
@@ -2904,14 +2904,14 @@  discard block
 block discarded – undo
2904 2904
 	) {
2905 2905
 		$distant = true;
2906 2906
 		$cssf = parse_url($css);
2907
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2907
+		$cssf = $cssf['path'].($cssf['query'] ? '?'.$cssf['query'] : '');
2908 2908
 		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2909 2909
 	} else {
2910 2910
 		$distant = false;
2911 2911
 		$cssf = $css;
2912 2912
 		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2913 2913
 		//propose (rien a faire dans ce cas)
2914
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2914
+		$f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css);
2915 2915
 		if (@file_exists($f)) {
2916 2916
 			return $f;
2917 2917
 		}
@@ -2921,7 +2921,7 @@  discard block
 block discarded – undo
2921 2921
 	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2922 2922
 	$f = $dir_var
2923 2923
 		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2924
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2924
+		. '.'.substr(md5($cssf), 0, 4).'_'.$ndir.'.css';
2925 2925
 
2926 2926
 	// la css peut etre distante (url absolue !)
2927 2927
 	if ($distant) {
@@ -2967,8 +2967,8 @@  discard block
 block discarded – undo
2967 2967
 		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2968 2968
 		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2969 2969
 			$css_direction = substr($css_direction, strlen($dir_var));
2970
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
2971
-			$css_direction = '/@@@@@@/' . $css_direction;
2970
+			$src_faux_abs['/@@@@@@/'.$css_direction] = $css_direction;
2971
+			$css_direction = '/@@@@@@/'.$css_direction;
2972 2972
 		}
2973 2973
 		$src[] = $regs[0][$k];
2974 2974
 		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
@@ -3017,7 +3017,7 @@  discard block
 block discarded – undo
3017 3017
 
3018 3018
 	$f = basename($css, '.css');
3019 3019
 	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3020
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3020
+		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-".substr(md5("$css-urlabs"), 0, 4)."\\2", $f)
3021 3021
 		. '.css';
3022 3022
 
3023 3023
 	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
@@ -3027,7 +3027,7 @@  discard block
 block discarded – undo
3027 3027
 	if ($url_absolue_css == $css) {
3028 3028
 		if (
3029 3029
 			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3030
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3030
+			or !lire_fichier(_DIR_RACINE.substr($css, $l), $contenu)
3031 3031
 		) {
3032 3032
 			include_spip('inc/distant');
3033 3033
 			$contenu = recuperer_url($css);
@@ -3139,7 +3139,7 @@  discard block
 block discarded – undo
3139 3139
 	$expression = str_replace('\/', '/', $expression);
3140 3140
 	$expression = str_replace('/', '\/', $expression);
3141 3141
 
3142
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3142
+	if (preg_match('/'.$expression.'/'.$modif, $texte ?? '', $r)) {
3143 3143
 		if (isset($r[$capte])) {
3144 3144
 			return $r[$capte];
3145 3145
 		} else {
@@ -3177,7 +3177,7 @@  discard block
 block discarded – undo
3177 3177
 	$expression = str_replace('\/', '/', $expression);
3178 3178
 	$expression = str_replace('/', '\/', $expression);
3179 3179
 
3180
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3180
+	return preg_replace('/'.$expression.'/'.$modif, $replace, $texte);
3181 3181
 }
3182 3182
 
3183 3183
 
@@ -3196,7 +3196,7 @@  discard block
 block discarded – undo
3196 3196
 function traiter_doublons_documents(&$doublons, $letexte) {
3197 3197
 
3198 3198
 	// Verifier dans le texte & les notes (pas beau, helas)
3199
-	$t = $letexte . $GLOBALS['les_notes'];
3199
+	$t = $letexte.$GLOBALS['les_notes'];
3200 3200
 
3201 3201
 	if (
3202 3202
 		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
@@ -3210,7 +3210,7 @@  discard block
 block discarded – undo
3210 3210
 		if (!isset($doublons['documents'])) {
3211 3211
 			$doublons['documents'] = '';
3212 3212
 		}
3213
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3213
+		$doublons['documents'] .= ','.join(',', $matches[1]);
3214 3214
 	}
3215 3215
 
3216 3216
 	return $letexte;
@@ -3267,7 +3267,7 @@  discard block
 block discarded – undo
3267 3267
 	if ($env) {
3268 3268
 		foreach ($env as $i => $j) {
3269 3269
 			if (is_string($j) and !in_array($i, $ignore_params)) {
3270
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3270
+				$texte .= "<param name='".attribut_html($i)."'\n\tvalue='".attribut_html($j)."' />";
3271 3271
 			}
3272 3272
 		}
3273 3273
 	}
@@ -3306,7 +3306,7 @@  discard block
 block discarded – undo
3306 3306
 	if ($env) {
3307 3307
 		foreach ($env as $i => $j) {
3308 3308
 			if (is_string($j) and !in_array($i, $ignore_params)) {
3309
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3309
+				$texte .= attribut_html($i)."='".attribut_html($j)."' ";
3310 3310
 			}
3311 3311
 		}
3312 3312
 	}
@@ -3380,10 +3380,10 @@  discard block
 block discarded – undo
3380 3380
 	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3381 3381
 	if (
3382 3382
 		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3383
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3383
+		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])).'-xx.svg'
3384 3384
 		and file_exists($variante_svg_generique)
3385 3385
 	) {
3386
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3386
+		if ($variante_svg_size = substr($variante_svg_generique, 0, -6).$m[1].'.svg' and file_exists($variante_svg_size)) {
3387 3387
 			$img_file = $variante_svg_size;
3388 3388
 		}
3389 3389
 		else {
@@ -3441,7 +3441,7 @@  discard block
 block discarded – undo
3441 3441
 				return '';
3442 3442
 			}
3443 3443
 		}
3444
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3444
+		$atts .= " width='".$largeur."' height='".$hauteur."'";
3445 3445
 	}
3446 3446
 
3447 3447
 	if (file_exists($img_file)) {
@@ -3451,14 +3451,14 @@  discard block
 block discarded – undo
3451 3451
 		$alt = '';
3452 3452
 	}
3453 3453
 	elseif ($alt or $alt === '') {
3454
-		$alt = " alt='" . attribut_html($alt) . "'";
3454
+		$alt = " alt='".attribut_html($alt)."'";
3455 3455
 	}
3456 3456
 	else {
3457
-		$alt = " alt='" . attribut_html($title) . "'";
3457
+		$alt = " alt='".attribut_html($title)."'";
3458 3458
 	}
3459
-	return "<img src='" . attribut_html($img_file) . "'$alt"
3460
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3461
-	. ' ' . ltrim($atts)
3459
+	return "<img src='".attribut_html($img_file)."'$alt"
3460
+	. ($title ? ' title="'.attribut_html($title).'"' : '')
3461
+	. ' '.ltrim($atts)
3462 3462
 	. ' />';
3463 3463
 }
3464 3464
 
@@ -3472,10 +3472,10 @@  discard block
 block discarded – undo
3472 3472
  */
3473 3473
 function http_style_background($img, $att = '', $size = null) {
3474 3474
 	if ($size and is_numeric($size)) {
3475
-		$size = trim($size) . 'px';
3475
+		$size = trim($size).'px';
3476 3476
 	}
3477
-	return " style='background" .
3478
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3477
+	return " style='background".
3478
+		($att ? '' : '-image').': url("'.chemin_image($img).'")'.($att ? (' '.$att) : '').';'
3479 3479
 		. ($size ? "background-size:{$size};" : '')
3480 3480
 		. "'";
3481 3481
 }
@@ -3590,7 +3590,7 @@  discard block
 block discarded – undo
3590 3590
 		$img = http_img_pack(
3591 3591
 			$img,
3592 3592
 			$alt,
3593
-			$class ? " class='" . attribut_html($class) . "'" : '',
3593
+			$class ? " class='".attribut_html($class)."'" : '',
3594 3594
 			'',
3595 3595
 			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3596 3596
 		);
@@ -3675,7 +3675,7 @@  discard block
 block discarded – undo
3675 3675
 	$balise_svg_source = $balise_svg;
3676 3676
 
3677 3677
 	// entete XML à supprimer
3678
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3678
+	$svg = preg_replace(',^\s*<\?xml[^>]*\?'.'>,', '', $svg);
3679 3679
 
3680 3680
 	// IE est toujours mon ami
3681 3681
 	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
@@ -3693,9 +3693,9 @@  discard block
 block discarded – undo
3693 3693
 	// regler le alt
3694 3694
 	if ($alt) {
3695 3695
 		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3696
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3696
+		$id = 'img-svg-title-'.substr(md5("$img_file:$svg:$alt"), 0, 4);
3697 3697
 		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3698
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3698
+		$title = "<title id=\"$id\">".entites_html($alt)."</title>\n";
3699 3699
 		$balise_svg .= $title;
3700 3700
 	}
3701 3701
 	else {
@@ -3743,7 +3743,7 @@  discard block
 block discarded – undo
3743 3743
 	if (is_array($tableau)) {
3744 3744
 		foreach ($tableau as $k => $v) {
3745 3745
 			$res = recuperer_fond(
3746
-				'modeles/' . $modele,
3746
+				'modeles/'.$modele,
3747 3747
 				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3748 3748
 			);
3749 3749
 			$texte .= $res;
@@ -3928,7 +3928,7 @@  discard block
 block discarded – undo
3928 3928
 	}
3929 3929
 
3930 3930
 	$c = serialize($c);
3931
-	$cle = calculer_cle_action($form . $c);
3931
+	$cle = calculer_cle_action($form.$c);
3932 3932
 	$c = "$cle:$c";
3933 3933
 
3934 3934
 	// on ne stocke pas les contextes dans des fichiers en cache
@@ -3986,15 +3986,15 @@  discard block
 block discarded – undo
3986 3986
 	}
3987 3987
 	// toujours encoder l'url source dans le bloc ajax
3988 3988
 	$r = self();
3989
-	$r = ' data-origin="' . $r . '"';
3989
+	$r = ' data-origin="'.$r.'"';
3990 3990
 	$class = 'ajaxbloc';
3991 3991
 	if ($ajaxid and is_string($ajaxid)) {
3992 3992
 		// ajaxid est normalement conforme a un nom de classe css
3993 3993
 		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3994
-		$class .= ' ajax-id-' . entites_html($ajaxid);
3994
+		$class .= ' ajax-id-'.entites_html($ajaxid);
3995 3995
 	}
3996 3996
 
3997
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3997
+	return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3998 3998
 }
3999 3999
 
4000 4000
 /**
@@ -4038,7 +4038,7 @@  discard block
 block discarded – undo
4038 4038
 		$cle = substr($c, 0, $p);
4039 4039
 		$c = substr($c, $p + 1);
4040 4040
 
4041
-		if ($cle == calculer_cle_action($form . $c)) {
4041
+		if ($cle == calculer_cle_action($form.$c)) {
4042 4042
 			$env = @unserialize($c);
4043 4043
 			return $env;
4044 4044
 		}
@@ -4159,13 +4159,13 @@  discard block
 block discarded – undo
4159 4159
 				}
4160 4160
 			}
4161 4161
 		}
4162
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4162
+		$att .= 'class="'.($class ? attribut_html($class).' ' : '').(defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on').'"';
4163 4163
 	} else {
4164 4164
 		$bal = 'a';
4165 4165
 		$att = "href='$url'"
4166
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4167
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4168
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4166
+			. ($title ? " title='".attribut_html($title)."'" : '')
4167
+			. ($class ? " class='".attribut_html($class)."'" : '')
4168
+			. ($rel ? " rel='".attribut_html($rel)."'" : '')
4169 4169
 			. $evt;
4170 4170
 	}
4171 4171
 	if ($libelle === null) {
@@ -4304,7 +4304,7 @@  discard block
 block discarded – undo
4304 4304
 
4305 4305
 	// Icône
4306 4306
 	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4307
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4307
+	$icone = '<span class="icone-image'.($fonction ? " icone-fonction icone-fonction-$fonction" : '')."\">$icone</span>";
4308 4308
 
4309 4309
 	// Markup final
4310 4310
 	if ($type == 'lien') {
@@ -4579,20 +4579,20 @@  discard block
 block discarded – undo
4579 4579
 		$class_form = 'ajax';
4580 4580
 		$class = str_replace('ajax', '', $class);
4581 4581
 	}
4582
-	$class_btn = 'submit ' . trim($class);
4582
+	$class_btn = 'submit '.trim($class);
4583 4583
 
4584 4584
 	if ($confirm) {
4585
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4585
+		$confirm = 'confirm("'.attribut_html($confirm).'")';
4586 4586
 		if ($callback) {
4587 4587
 			$callback = "$confirm?($callback):false";
4588 4588
 		} else {
4589 4589
 			$callback = $confirm;
4590 4590
 		}
4591 4591
 	}
4592
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4592
+	$onclick = $callback ? " onclick='return ".addcslashes($callback, "'")."'" : '';
4593 4593
 	$title = $title ? " title='$title'" : '';
4594 4594
 
4595
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4595
+	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>".form_hidden($url)
4596 4596
 	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4597 4597
 }
4598 4598
 
@@ -4657,14 +4657,14 @@  discard block
 block discarded – undo
4657 4657
 		$champ_titre = '';
4658 4658
 		if ($demande_titre) {
4659 4659
 			// si pas de titre declare mais champ titre, il sera peuple par le select *
4660
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4660
+			$champ_titre = (!empty($desc['titre'])) ? ', '.$desc['titre'] : '';
4661 4661
 		}
4662 4662
 		include_spip('base/abstract_sql');
4663 4663
 		include_spip('base/connect_sql');
4664 4664
 		$objets[$type_objet][$id_objet] = sql_fetsel(
4665
-			'*' . $champ_titre,
4665
+			'*'.$champ_titre,
4666 4666
 			$desc['table_sql'],
4667
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4667
+			id_table_objet($type_objet).' = '.intval($id_objet)
4668 4668
 		);
4669 4669
 
4670 4670
 		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
@@ -4757,8 +4757,7 @@  discard block
 block discarded – undo
4757 4757
 	if (isset($ligne_sql['chapo'])) {
4758 4758
 		$chapo = $ligne_sql['chapo'];
4759 4759
 		$texte = strlen($descriptif) ?
4760
-			'' :
4761
-			"$chapo \n\n $texte";
4760
+			'' : "$chapo \n\n $texte";
4762 4761
 	}
4763 4762
 
4764 4763
 	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
@@ -4833,7 +4832,7 @@  discard block
 block discarded – undo
4833 4832
 		return $texte;
4834 4833
 	}
4835 4834
 
4836
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4835
+	$traitement = str_replace('%s', "'".texte_script($texte)."'", $traitement);
4837 4836
 
4838 4837
 	// signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4839 4838
 	if (test_espace_prive()) {
@@ -4872,7 +4871,7 @@  discard block
 block discarded – undo
4872 4871
 	}
4873 4872
 	$url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4874 4873
 
4875
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4874
+	return "<a href='$url' class='$objet'>".couper($titre, $longueur).'</a>';
4876 4875
 }
4877 4876
 
4878 4877
 /**
@@ -4898,10 +4897,10 @@  discard block
 block discarded – undo
4898 4897
 function wrap($texte, $wrap) {
4899 4898
 	$balises = extraire_balises($wrap);
4900 4899
 	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4901
-		$texte = $wrap . $texte;
4900
+		$texte = $wrap.$texte;
4902 4901
 		$regs = array_reverse($regs[1]);
4903
-		$wrap = '</' . implode('></', $regs) . '>';
4904
-		$texte = $texte . $wrap;
4902
+		$wrap = '</'.implode('></', $regs).'>';
4903
+		$texte = $texte.$wrap;
4905 4904
 	}
4906 4905
 
4907 4906
 	return $texte;
@@ -4932,7 +4931,7 @@  discard block
 block discarded – undo
4932 4931
 
4933 4932
 	// caster $u en array si besoin
4934 4933
 	if (is_object($u)) {
4935
-		$u = (array)$u;
4934
+		$u = (array) $u;
4936 4935
 	}
4937 4936
 
4938 4937
 	if (is_array($u)) {
@@ -4954,7 +4953,7 @@  discard block
 block discarded – undo
4954 4953
 		// sinon on passe a la ligne et on indente
4955 4954
 		$i_str = str_pad('', $indent, ' ');
4956 4955
 		foreach ($u as $k => $v) {
4957
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4956
+			$out .= $join.$i_str."$k: ".filtre_print_dist($v, $join, $indent + 2);
4958 4957
 		}
4959 4958
 
4960 4959
 		return $out;
@@ -5008,7 +5007,7 @@  discard block
 block discarded – undo
5008 5007
  * @return string
5009 5008
  */
5010 5009
 function objet_icone($objet, $taille = 24, $class = '') {
5011
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5010
+	$icone = objet_info($objet, 'icone_objet').'-'.$taille.'.png';
5012 5011
 	$icone = chemin_image($icone);
5013 5012
 	$balise_img = charger_filtre('balise_img');
5014 5013
 
@@ -5034,7 +5033,7 @@  discard block
 block discarded – undo
5034 5033
  */
5035 5034
 function objet_T($objet, $chaine, $args = [], $options = []) {
5036 5035
 	$chaine = explode(':', $chaine);
5037
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5036
+	if ($t = _T($objet.':'.end($chaine), $args, array_merge($options, ['force' => false]))) {
5038 5037
 		return $t;
5039 5038
 	}
5040 5039
 	$chaine = implode(':', $chaine);
@@ -5100,7 +5099,7 @@  discard block
 block discarded – undo
5100 5099
 	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5101 5100
 
5102 5101
 	// calculer le nom de la css
5103
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5102
+	$dir_var = sous_repertoire(_DIR_VAR, 'cache-'.$extension);
5104 5103
 	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5105 5104
 	$contexte_implicite = calculer_contexte_implicite();
5106 5105
 
@@ -5108,14 +5107,14 @@  discard block
 block discarded – undo
5108 5107
 	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5109 5108
 	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5110 5109
 	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5111
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5110
+		$hash = md5($contexte_implicite['host'].'::'.$cache);
5112 5111
 	}
5113 5112
 	else {
5114 5113
 		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5115 5114
 		ksort($contexte);
5116
-		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5115
+		$hash = md5($fond.json_encode($contexte_implicite, JSON_THROW_ON_ERROR).json_encode($contexte, JSON_THROW_ON_ERROR).$connect);
5117 5116
 	}
5118
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5117
+	$filename = $dir_var.$extension."dyn-$nom_safe-".substr($hash, 0, 8).".$extension";
5119 5118
 
5120 5119
 	// mettre a jour le fichier si il n'existe pas
5121 5120
 	// ou trop ancien
@@ -5123,8 +5122,8 @@  discard block
 block discarded – undo
5123 5122
 	// et recopie sur le fichier cible uniquement si il change
5124 5123
 	if (
5125 5124
 		!file_exists($filename)
5126
-		or !file_exists($filename . '.last')
5127
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5125
+		or !file_exists($filename.'.last')
5126
+		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename.'.last') < $cache['lastmodified'])
5128 5127
 		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5129 5128
 	) {
5130 5129
 		$contenu = $cache['texte'];
@@ -5148,10 +5147,10 @@  discard block
 block discarded – undo
5148 5147
 			}
5149 5148
 			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5150 5149
 			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5151
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5150
+			$comment .= "}\n   md5:".md5($contenu)." */\n";
5152 5151
 		}
5153 5152
 		// et ecrire le fichier si il change
5154
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5153
+		ecrire_fichier_calcule_si_modifie($filename, $comment.$contenu, false, true);
5155 5154
 	}
5156 5155
 
5157 5156
 	return timestamp($filename);
@@ -5384,7 +5383,7 @@  discard block
 block discarded – undo
5384 5383
 	if ($e > 0 and strlen($mid) > 8) {
5385 5384
 		$mid = '***...***';
5386 5385
 	}
5387
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5386
+	return substr($passe, 0, $e).$mid.($e > 0 ? substr($passe, -$e) : '');
5388 5387
 }
5389 5388
 
5390 5389
 
@@ -5446,7 +5445,7 @@  discard block
 block discarded – undo
5446 5445
 		case 'id':
5447 5446
 		case 'anchor':
5448 5447
 			if (preg_match(',^\d,', $texte)) {
5449
-				$texte = substr($type, 0, 1) . $texte;
5448
+				$texte = substr($type, 0, 1).$texte;
5450 5449
 			}
5451 5450
 	}
5452 5451
 
@@ -5456,9 +5455,9 @@  discard block
 block discarded – undo
5456 5455
 
5457 5456
 	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5458 5457
 		if (preg_match(',^\d,', $texte)) {
5459
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5458
+			$texte = ($type ? substr($type, 0, 1) : 's').$texte;
5460 5459
 		}
5461
-		$texte .= $separateur . md5($original);
5460
+		$texte .= $separateur.md5($original);
5462 5461
 		$texte = substr($texte, 0, $longueur_mini);
5463 5462
 	}
5464 5463
 
Please login to merge, or discard this patch.
ecrire/inc/rechercher.php 1 patch
Indentation   +317 added lines, -317 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 defined('_RECHERCHE_LOCK_KEY') || define('_RECHERCHE_LOCK_KEY', 'fulltext');
@@ -35,198 +35,198 @@  discard block
 block discarded – undo
35 35
  * @return array Couples (type d'objet => Couples (champ => score))
36 36
  */
37 37
 function liste_des_champs() {
38
-	static $liste = null;
39
-	if (is_null($liste)) {
40
-		$liste = [];
41
-		// recuperer les tables_objets_sql declarees
42
-		include_spip('base/objets');
43
-		$tables_objets = lister_tables_objets_sql();
44
-		foreach ($tables_objets as $t => $infos) {
45
-			if ($infos['rechercher_champs']) {
46
-				$liste[$infos['type']] = $infos['rechercher_champs'];
47
-			}
48
-		}
49
-		// puis passer dans le pipeline
50
-		$liste = pipeline('rechercher_liste_des_champs', $liste);
51
-	}
52
-
53
-	return $liste;
38
+    static $liste = null;
39
+    if (is_null($liste)) {
40
+        $liste = [];
41
+        // recuperer les tables_objets_sql declarees
42
+        include_spip('base/objets');
43
+        $tables_objets = lister_tables_objets_sql();
44
+        foreach ($tables_objets as $t => $infos) {
45
+            if ($infos['rechercher_champs']) {
46
+                $liste[$infos['type']] = $infos['rechercher_champs'];
47
+            }
48
+        }
49
+        // puis passer dans le pipeline
50
+        $liste = pipeline('rechercher_liste_des_champs', $liste);
51
+    }
52
+
53
+    return $liste;
54 54
 }
55 55
 
56 56
 
57 57
 // Recherche des auteurs et mots-cles associes
58 58
 // en ne regardant que le titre ou le nom
59 59
 function liste_des_jointures() {
60
-	static $liste = null;
61
-	if (is_null($liste)) {
62
-		$liste = [];
63
-		// recuperer les tables_objets_sql declarees
64
-		include_spip('base/objets');
65
-		$tables_objets = lister_tables_objets_sql();
66
-		foreach ($tables_objets as $t => $infos) {
67
-			if ($infos['rechercher_jointures']) {
68
-				$liste[$infos['type']] = $infos['rechercher_jointures'];
69
-			}
70
-		}
71
-		// puis passer dans le pipeline
72
-		$liste = pipeline('rechercher_liste_des_jointures', $liste);
73
-	}
74
-
75
-	return $liste;
60
+    static $liste = null;
61
+    if (is_null($liste)) {
62
+        $liste = [];
63
+        // recuperer les tables_objets_sql declarees
64
+        include_spip('base/objets');
65
+        $tables_objets = lister_tables_objets_sql();
66
+        foreach ($tables_objets as $t => $infos) {
67
+            if ($infos['rechercher_jointures']) {
68
+                $liste[$infos['type']] = $infos['rechercher_jointures'];
69
+            }
70
+        }
71
+        // puis passer dans le pipeline
72
+        $liste = pipeline('rechercher_liste_des_jointures', $liste);
73
+    }
74
+
75
+    return $liste;
76 76
 }
77 77
 
78 78
 function expression_recherche($recherche, $options) {
79
-	// ne calculer qu'une seule fois l'expression par hit
80
-	// (meme si utilisee dans plusieurs boucles)
81
-	static $expression = [];
82
-	$key = serialize([$recherche, $options['preg_flags']]);
83
-	if (isset($expression[$key])) {
84
-		return $expression[$key];
85
-	}
86
-
87
-	$u = $GLOBALS['meta']['pcre_u'];
88
-	if ($u and !str_contains($options['preg_flags'], (string) $u)) {
89
-		$options['preg_flags'] .= $u;
90
-	}
91
-	include_spip('inc/charsets');
92
-	$recherche = trim($recherche);
93
-
94
-	// retirer les + de +truc et les * de truc*
95
-	$recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche);
96
-	$recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche);
97
-
98
-	$is_preg = false;
99
-	if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) {
100
-		// c'est une preg
101
-		$recherche_trans = translitteration($recherche);
102
-		$preg = $recherche_trans . $options['preg_flags'];
103
-		$is_preg = true;
104
-	} else {
105
-		// s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
106
-		// sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
107
-		// 'une', 'des' ...)
108
-
109
-		// attention : plusieurs mots entre guillemets sont a rechercher tels quels
110
-		$recherche_trans = $recherche_mod = $recherche_org = $recherche;
111
-
112
-		// les expressions entre " " sont un mot a chercher tel quel
113
-		// -> on remplace les espaces par un \x1 et on enleve les guillemets
114
-		if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
115
-			foreach ($matches as $match) {
116
-				$word = preg_replace(',\s+,Uims', "\x1", $match);
117
-				$word = trim($word, '"');
118
-				$recherche_mod = str_replace($match, $word, $recherche_mod);
119
-			}
120
-		}
121
-
122
-		if (preg_match(',\s+,' . $u, $recherche_mod)) {
123
-			$is_preg = true;
124
-
125
-			$recherche_inter = '|';
126
-			$recherche_mots = explode(' ', $recherche_mod);
127
-			$min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
128
-			$petits_mots = true;
129
-			foreach ($recherche_mots as $mot) {
130
-				if (strlen($mot) >= $min_long) {
131
-					// echapper les caracteres de regexp qui sont eventuellement dans la recherche
132
-					$recherche_inter .= preg_quote($mot) . ' ';
133
-					$petits_mots = false;
134
-				}
135
-			}
136
-			$recherche_inter = str_replace("\x1", '\s', $recherche_inter);
137
-
138
-			// mais on cherche quand même l'expression complète, même si elle
139
-			// comporte des mots de moins de quatre lettres
140
-			$recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
141
-			if (!$recherche or $petits_mots) {
142
-				$recherche = preg_quote($recherche_org);
143
-			}
144
-			$recherche_trans = translitteration($recherche);
145
-		}
146
-
147
-		$preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags'];
148
-	}
149
-
150
-	// Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
151
-	// ou si l'expression reguliere est invalide
152
-	if (
153
-		!$is_preg
154
-		or (@preg_match($preg, '') === false)
155
-	) {
156
-		$methode = 'LIKE';
157
-		$u = $GLOBALS['meta']['pcre_u'];
158
-
159
-		// echapper les % et _
160
-		$q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche));
161
-
162
-		// 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
163
-		$recherche = preg_quote($recherche, '/');
164
-		$recherche_trans = translitteration($recherche);
165
-		$recherche_mod = $recherche_trans;
166
-
167
-		// les expressions entre " " sont un mot a chercher tel quel
168
-		// -> on remplace les espaces par un _ et on enleve les guillemets
169
-		// corriger le like dans le $q
170
-		if (preg_match(',["][^"]+["],Uims', $q, $matches)) {
171
-			foreach ($matches as $match) {
172
-				$word = preg_replace(',\s+,Uims', '_', $match);
173
-				$word = trim($word, '"');
174
-				$q = str_replace($match, $word, $q);
175
-			}
176
-		}
177
-		// corriger la regexp
178
-		if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
179
-			foreach ($matches as $match) {
180
-				$word = preg_replace(',\s+,Uims', '[\s]', $match);
181
-				$word = trim($word, '"');
182
-				$recherche_mod = str_replace($match, $word, $recherche_mod);
183
-			}
184
-		}
185
-		$q = sql_quote(
186
-			'%'
187
-			. preg_replace(',\s+,' . $u, '%', $q)
188
-			. '%'
189
-		);
190
-
191
-		$preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags'];
192
-	} else {
193
-		$methode = 'REGEXP';
194
-		$q = sql_quote(trim($recherche, '/'));
195
-	}
196
-
197
-	// tous les caracteres transliterables de $q sont remplaces par un joker
198
-	// permet de matcher en SQL meme si on est sensible aux accents (SQLite)
199
-	$q_t = $q;
200
-	for ($i = 0; $i < spip_strlen($q); $i++) {
201
-		$char = spip_substr($q, $i, 1);
202
-		if (
203
-			!is_ascii($char)
204
-			and $char_t = translitteration($char)
205
-			and $char_t !== $char
206
-		) {
207
-			// on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes
208
-			// mais c'est un pis aller cf #4354
209
-			$q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t);
210
-		}
211
-	}
212
-
213
-	$q = $q_t;
214
-
215
-	// fix : SQLite 3 est sensible aux accents, on jokerise les caracteres
216
-	// les plus frequents qui peuvent etre accentues
217
-	// (oui c'est tres dicustable...)
218
-	if (
219
-		isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'])
220
-		and strncmp($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite', 6) == 0
221
-	) {
222
-		$q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______');
223
-		// si il reste au moins un char significatif...
224
-		if (preg_match(",[^'%_.],", $q_t)) {
225
-			$q = $q_t;
226
-		}
227
-	}
228
-
229
-	return $expression[$key] = [$methode, $q, $preg];
79
+    // ne calculer qu'une seule fois l'expression par hit
80
+    // (meme si utilisee dans plusieurs boucles)
81
+    static $expression = [];
82
+    $key = serialize([$recherche, $options['preg_flags']]);
83
+    if (isset($expression[$key])) {
84
+        return $expression[$key];
85
+    }
86
+
87
+    $u = $GLOBALS['meta']['pcre_u'];
88
+    if ($u and !str_contains($options['preg_flags'], (string) $u)) {
89
+        $options['preg_flags'] .= $u;
90
+    }
91
+    include_spip('inc/charsets');
92
+    $recherche = trim($recherche);
93
+
94
+    // retirer les + de +truc et les * de truc*
95
+    $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche);
96
+    $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche);
97
+
98
+    $is_preg = false;
99
+    if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) {
100
+        // c'est une preg
101
+        $recherche_trans = translitteration($recherche);
102
+        $preg = $recherche_trans . $options['preg_flags'];
103
+        $is_preg = true;
104
+    } else {
105
+        // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
106
+        // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
107
+        // 'une', 'des' ...)
108
+
109
+        // attention : plusieurs mots entre guillemets sont a rechercher tels quels
110
+        $recherche_trans = $recherche_mod = $recherche_org = $recherche;
111
+
112
+        // les expressions entre " " sont un mot a chercher tel quel
113
+        // -> on remplace les espaces par un \x1 et on enleve les guillemets
114
+        if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
115
+            foreach ($matches as $match) {
116
+                $word = preg_replace(',\s+,Uims', "\x1", $match);
117
+                $word = trim($word, '"');
118
+                $recherche_mod = str_replace($match, $word, $recherche_mod);
119
+            }
120
+        }
121
+
122
+        if (preg_match(',\s+,' . $u, $recherche_mod)) {
123
+            $is_preg = true;
124
+
125
+            $recherche_inter = '|';
126
+            $recherche_mots = explode(' ', $recherche_mod);
127
+            $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
128
+            $petits_mots = true;
129
+            foreach ($recherche_mots as $mot) {
130
+                if (strlen($mot) >= $min_long) {
131
+                    // echapper les caracteres de regexp qui sont eventuellement dans la recherche
132
+                    $recherche_inter .= preg_quote($mot) . ' ';
133
+                    $petits_mots = false;
134
+                }
135
+            }
136
+            $recherche_inter = str_replace("\x1", '\s', $recherche_inter);
137
+
138
+            // mais on cherche quand même l'expression complète, même si elle
139
+            // comporte des mots de moins de quatre lettres
140
+            $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
141
+            if (!$recherche or $petits_mots) {
142
+                $recherche = preg_quote($recherche_org);
143
+            }
144
+            $recherche_trans = translitteration($recherche);
145
+        }
146
+
147
+        $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags'];
148
+    }
149
+
150
+    // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
151
+    // ou si l'expression reguliere est invalide
152
+    if (
153
+        !$is_preg
154
+        or (@preg_match($preg, '') === false)
155
+    ) {
156
+        $methode = 'LIKE';
157
+        $u = $GLOBALS['meta']['pcre_u'];
158
+
159
+        // echapper les % et _
160
+        $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche));
161
+
162
+        // 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
163
+        $recherche = preg_quote($recherche, '/');
164
+        $recherche_trans = translitteration($recherche);
165
+        $recherche_mod = $recherche_trans;
166
+
167
+        // les expressions entre " " sont un mot a chercher tel quel
168
+        // -> on remplace les espaces par un _ et on enleve les guillemets
169
+        // corriger le like dans le $q
170
+        if (preg_match(',["][^"]+["],Uims', $q, $matches)) {
171
+            foreach ($matches as $match) {
172
+                $word = preg_replace(',\s+,Uims', '_', $match);
173
+                $word = trim($word, '"');
174
+                $q = str_replace($match, $word, $q);
175
+            }
176
+        }
177
+        // corriger la regexp
178
+        if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
179
+            foreach ($matches as $match) {
180
+                $word = preg_replace(',\s+,Uims', '[\s]', $match);
181
+                $word = trim($word, '"');
182
+                $recherche_mod = str_replace($match, $word, $recherche_mod);
183
+            }
184
+        }
185
+        $q = sql_quote(
186
+            '%'
187
+            . preg_replace(',\s+,' . $u, '%', $q)
188
+            . '%'
189
+        );
190
+
191
+        $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags'];
192
+    } else {
193
+        $methode = 'REGEXP';
194
+        $q = sql_quote(trim($recherche, '/'));
195
+    }
196
+
197
+    // tous les caracteres transliterables de $q sont remplaces par un joker
198
+    // permet de matcher en SQL meme si on est sensible aux accents (SQLite)
199
+    $q_t = $q;
200
+    for ($i = 0; $i < spip_strlen($q); $i++) {
201
+        $char = spip_substr($q, $i, 1);
202
+        if (
203
+            !is_ascii($char)
204
+            and $char_t = translitteration($char)
205
+            and $char_t !== $char
206
+        ) {
207
+            // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes
208
+            // mais c'est un pis aller cf #4354
209
+            $q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t);
210
+        }
211
+    }
212
+
213
+    $q = $q_t;
214
+
215
+    // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres
216
+    // les plus frequents qui peuvent etre accentues
217
+    // (oui c'est tres dicustable...)
218
+    if (
219
+        isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'])
220
+        and strncmp($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite', 6) == 0
221
+    ) {
222
+        $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______');
223
+        // si il reste au moins un char significatif...
224
+        if (preg_match(",[^'%_.],", $q_t)) {
225
+            $q = $q_t;
226
+        }
227
+    }
228
+
229
+    return $expression[$key] = [$methode, $q, $preg];
230 230
 }
231 231
 
232 232
 
@@ -253,142 +253,142 @@  discard block
 block discarded – undo
253 253
  * @return array
254 254
  */
255 255
 function recherche_en_base($recherche = '', $tables = null, $options = [], $serveur = '') {
256
-	include_spip('base/abstract_sql');
257
-
258
-	if (!is_array($tables)) {
259
-		$liste = liste_des_champs();
260
-
261
-		if (
262
-			is_string($tables)
263
-			and $tables != ''
264
-		) {
265
-			$toutes = [];
266
-			foreach (explode(',', $tables) as $t) {
267
-				$t = trim($t);
268
-				if (isset($liste[$t])) {
269
-					$toutes[$t] = $liste[$t];
270
-				}
271
-			}
272
-			$tables = $toutes;
273
-			unset($toutes);
274
-		} else {
275
-			$tables = $liste;
276
-		}
277
-	}
278
-
279
-	if (!strlen($recherche) or !count($tables)) {
280
-		return [];
281
-	}
282
-
283
-	include_spip('inc/autoriser');
284
-
285
-	// options par defaut
286
-	$options = array_merge(
287
-		[
288
-		'preg_flags' => 'UimsS',
289
-		'toutvoir' => false,
290
-		'champs' => false,
291
-		'score' => false,
292
-		'matches' => false,
293
-		'jointures' => false,
294
-		'serveur' => $serveur
295
-		],
296
-		$options
297
-	);
298
-
299
-	$results = [];
300
-
301
-	// Utiliser l'iterateur (DATA:recherche)
302
-	// pour recuperer les couples (id_objet, score)
303
-	// Le resultat est au format {
304
-	//      id1 = { 'score' => x, attrs => { } },
305
-	//      id2 = { 'score' => x, attrs => { } },
306
-	// }
307
-
308
-	include_spip('inc/recherche_to_array');
309
-
310
-	foreach ($tables as $table => $champs) {
311
-		# lock via memoization, si dispo
312
-		if (function_exists('cache_lock')) {
313
-			cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
314
-		}
315
-
316
-		spip_timer('rech');
317
-
318
-		# TODO : ici plutot charger un iterateur via l'API iterateurs
319
-		$to_array = charger_fonction('recherche_to_array', 'inc');
320
-		$results[$table] = $to_array(
321
-			$recherche,
322
-			array_merge($options, ['table' => $table, 'champs' => $champs])
323
-		);
324
-		##var_dump($results[$table]);
325
-
326
-
327
-		spip_log(
328
-			"recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'),
329
-			'recherche'
330
-		);
331
-
332
-		if (isset($lock)) {
333
-			cache_unlock($lock);
334
-		}
335
-	}
336
-
337
-	return $results;
256
+    include_spip('base/abstract_sql');
257
+
258
+    if (!is_array($tables)) {
259
+        $liste = liste_des_champs();
260
+
261
+        if (
262
+            is_string($tables)
263
+            and $tables != ''
264
+        ) {
265
+            $toutes = [];
266
+            foreach (explode(',', $tables) as $t) {
267
+                $t = trim($t);
268
+                if (isset($liste[$t])) {
269
+                    $toutes[$t] = $liste[$t];
270
+                }
271
+            }
272
+            $tables = $toutes;
273
+            unset($toutes);
274
+        } else {
275
+            $tables = $liste;
276
+        }
277
+    }
278
+
279
+    if (!strlen($recherche) or !count($tables)) {
280
+        return [];
281
+    }
282
+
283
+    include_spip('inc/autoriser');
284
+
285
+    // options par defaut
286
+    $options = array_merge(
287
+        [
288
+        'preg_flags' => 'UimsS',
289
+        'toutvoir' => false,
290
+        'champs' => false,
291
+        'score' => false,
292
+        'matches' => false,
293
+        'jointures' => false,
294
+        'serveur' => $serveur
295
+        ],
296
+        $options
297
+    );
298
+
299
+    $results = [];
300
+
301
+    // Utiliser l'iterateur (DATA:recherche)
302
+    // pour recuperer les couples (id_objet, score)
303
+    // Le resultat est au format {
304
+    //      id1 = { 'score' => x, attrs => { } },
305
+    //      id2 = { 'score' => x, attrs => { } },
306
+    // }
307
+
308
+    include_spip('inc/recherche_to_array');
309
+
310
+    foreach ($tables as $table => $champs) {
311
+        # lock via memoization, si dispo
312
+        if (function_exists('cache_lock')) {
313
+            cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
314
+        }
315
+
316
+        spip_timer('rech');
317
+
318
+        # TODO : ici plutot charger un iterateur via l'API iterateurs
319
+        $to_array = charger_fonction('recherche_to_array', 'inc');
320
+        $results[$table] = $to_array(
321
+            $recherche,
322
+            array_merge($options, ['table' => $table, 'champs' => $champs])
323
+        );
324
+        ##var_dump($results[$table]);
325
+
326
+
327
+        spip_log(
328
+            "recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'),
329
+            'recherche'
330
+        );
331
+
332
+        if (isset($lock)) {
333
+            cache_unlock($lock);
334
+        }
335
+    }
336
+
337
+    return $results;
338 338
 }
339 339
 
340 340
 
341 341
 // Effectue une recherche sur toutes les tables de la base de donnees
342 342
 function remplace_en_base($recherche = '', $remplace = null, $tables = null, $options = []) {
343
-	include_spip('inc/modifier');
344
-
345
-	// options par defaut
346
-	$options = array_merge(
347
-		[
348
-		'preg_flags' => 'UimsS',
349
-		'toutmodifier' => false
350
-		],
351
-		$options
352
-	);
353
-	$options['champs'] = true;
354
-
355
-
356
-	if (!is_array($tables)) {
357
-		$tables = liste_des_champs();
358
-	}
359
-
360
-	$results = recherche_en_base($recherche, $tables, $options);
361
-
362
-	$preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags'];
363
-
364
-	foreach ($results as $table => $r) {
365
-		$_id_table = id_table_objet($table);
366
-		foreach ($r as $id => $x) {
367
-			if (
368
-				$options['toutmodifier']
369
-				or autoriser('modifier', $table, $id)
370
-			) {
371
-				$modifs = [];
372
-				foreach ($x['champs'] as $key => $val) {
373
-					if ($key == $_id_table) {
374
-						continue;
375
-					}
376
-					$repl = preg_replace($preg, $remplace, $val);
377
-					if ($repl <> $val) {
378
-						$modifs[$key] = $repl;
379
-					}
380
-				}
381
-				if ($modifs) {
382
-					objet_modifier_champs(
383
-						$table,
384
-						$id,
385
-						[
386
-							'champs' => array_keys($modifs),
387
-						],
388
-						$modifs
389
-					);
390
-				}
391
-			}
392
-		}
393
-	}
343
+    include_spip('inc/modifier');
344
+
345
+    // options par defaut
346
+    $options = array_merge(
347
+        [
348
+        'preg_flags' => 'UimsS',
349
+        'toutmodifier' => false
350
+        ],
351
+        $options
352
+    );
353
+    $options['champs'] = true;
354
+
355
+
356
+    if (!is_array($tables)) {
357
+        $tables = liste_des_champs();
358
+    }
359
+
360
+    $results = recherche_en_base($recherche, $tables, $options);
361
+
362
+    $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags'];
363
+
364
+    foreach ($results as $table => $r) {
365
+        $_id_table = id_table_objet($table);
366
+        foreach ($r as $id => $x) {
367
+            if (
368
+                $options['toutmodifier']
369
+                or autoriser('modifier', $table, $id)
370
+            ) {
371
+                $modifs = [];
372
+                foreach ($x['champs'] as $key => $val) {
373
+                    if ($key == $_id_table) {
374
+                        continue;
375
+                    }
376
+                    $repl = preg_replace($preg, $remplace, $val);
377
+                    if ($repl <> $val) {
378
+                        $modifs[$key] = $repl;
379
+                    }
380
+                }
381
+                if ($modifs) {
382
+                    objet_modifier_champs(
383
+                        $table,
384
+                        $id,
385
+                        [
386
+                            'champs' => array_keys($modifs),
387
+                        ],
388
+                        $modifs
389
+                    );
390
+                }
391
+            }
392
+        }
393
+    }
394 394
 }
Please login to merge, or discard this patch.
ecrire/inc/texte_mini.php 1 patch
Indentation   +519 added lines, -519 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 include_spip('inc/filtres');
23 23
 include_spip('inc/lang');
@@ -39,21 +39,21 @@  discard block
 block discarded – undo
39 39
  **/
40 40
 function definir_puce() {
41 41
 
42
-	// Attention au sens, qui n'est pas defini de la meme facon dans
43
-	// l'espace prive (spip_lang est la langue de l'interface, lang_dir
44
-	// celle du texte) et public (spip_lang est la langue du texte)
45
-	$dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']);
42
+    // Attention au sens, qui n'est pas defini de la meme facon dans
43
+    // l'espace prive (spip_lang est la langue de l'interface, lang_dir
44
+    // celle du texte) et public (spip_lang est la langue du texte)
45
+    $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']);
46 46
 
47
-	$p = 'puce' . (test_espace_prive() ? '_prive' : '');
48
-	if ($dir == 'rtl') {
49
-		$p .= '_rtl';
50
-	}
47
+    $p = 'puce' . (test_espace_prive() ? '_prive' : '');
48
+    if ($dir == 'rtl') {
49
+        $p .= '_rtl';
50
+    }
51 51
 
52
-	if (!isset($GLOBALS[$p])) {
53
-		$GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>';
54
-	}
52
+    if (!isset($GLOBALS[$p])) {
53
+        $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>';
54
+    }
55 55
 
56
-	return $GLOBALS[$p];
56
+    return $GLOBALS[$p];
57 57
 }
58 58
 
59 59
 /**
@@ -67,30 +67,30 @@  discard block
 block discarded – undo
67 67
  */
68 68
 function spip_balisage_code(string $corps, bool $bloc = false, string $attributs = '', string $langage = '') {
69 69
 
70
-	$echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code !
71
-	$class = "spip_code " . ($bloc ? 'spip_code_block' : 'spip_code_inline');
72
-	if ($langage) {
73
-		$class .= " language-$langage";
74
-	}
75
-	if ($attributs) {
76
-		$attributs = " " . trim($attributs);
77
-	}
78
-	if ($bloc) {
79
-		$html = "<div class=\"precode\">"
80
-		  . "<pre class=\"$class\" dir=\"ltr\" style=\"text-align: left;\"$attributs>"
81
-		  . "<code>"
82
-		  . $echap
83
-		  . '</code>'
84
-		  . '</pre>'
85
-		  . '</div>';
86
-	}
87
-	else {
88
-		$echap = str_replace("\t", "&nbsp; &nbsp; &nbsp; &nbsp; ", $echap);
89
-		$echap = str_replace("  ", " &nbsp;", $echap);
90
-		$html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>';
91
-	}
92
-
93
-	return $html;
70
+    $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code !
71
+    $class = "spip_code " . ($bloc ? 'spip_code_block' : 'spip_code_inline');
72
+    if ($langage) {
73
+        $class .= " language-$langage";
74
+    }
75
+    if ($attributs) {
76
+        $attributs = " " . trim($attributs);
77
+    }
78
+    if ($bloc) {
79
+        $html = "<div class=\"precode\">"
80
+            . "<pre class=\"$class\" dir=\"ltr\" style=\"text-align: left;\"$attributs>"
81
+            . "<code>"
82
+            . $echap
83
+            . '</code>'
84
+            . '</pre>'
85
+            . '</div>';
86
+    }
87
+    else {
88
+        $echap = str_replace("\t", "&nbsp; &nbsp; &nbsp; &nbsp; ", $echap);
89
+        $echap = str_replace("  ", " &nbsp;", $echap);
90
+        $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>';
91
+    }
92
+
93
+    return $html;
94 94
 }
95 95
 
96 96
 
@@ -98,14 +98,14 @@  discard block
 block discarded – undo
98 98
 // dont on souhaite qu'ils provoquent un saut de paragraphe
99 99
 
100 100
 if (!defined('_BALISES_BLOCS')) {
101
-	define(
102
-		'_BALISES_BLOCS',
103
-		'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style'
104
-	);
101
+    define(
102
+        '_BALISES_BLOCS',
103
+        'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style'
104
+    );
105 105
 }
106 106
 
107 107
 if (!defined('_BALISES_BLOCS_REGEXP')) {
108
-	define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS');
108
+    define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS');
109 109
 }
110 110
 
111 111
 //
@@ -116,100 +116,100 @@  discard block
 block discarded – undo
116 116
 // une $source differente ; le script detecte automagiquement si ce qu'on
117 117
 // echappe est un div ou un span
118 118
 function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) {
119
-	if (!strlen($rempl)) {
120
-		return '';
121
-	}
122
-
123
-	// Tester si on echappe en span ou en div
124
-	if (is_null($mode) or !in_array($mode, ['div', 'span'])) {
125
-		$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span';
126
-	}
127
-
128
-	// Decouper en morceaux, base64 a des probleme selon la taille de la pile
129
-	$taille = 30000;
130
-	$return = '';
131
-	for ($i = 0; $i < strlen($rempl); $i += $taille) {
132
-		// Convertir en base64 et cacher dans un attribut
133
-		// utiliser les " pour eviter le re-encodage de ' et &#8217
134
-		$base64 = base64_encode(substr($rempl, $i, $taille));
135
-		$return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>";
136
-	}
137
-
138
-	return $return;
119
+    if (!strlen($rempl)) {
120
+        return '';
121
+    }
122
+
123
+    // Tester si on echappe en span ou en div
124
+    if (is_null($mode) or !in_array($mode, ['div', 'span'])) {
125
+        $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span';
126
+    }
127
+
128
+    // Decouper en morceaux, base64 a des probleme selon la taille de la pile
129
+    $taille = 30000;
130
+    $return = '';
131
+    for ($i = 0; $i < strlen($rempl); $i += $taille) {
132
+        // Convertir en base64 et cacher dans un attribut
133
+        // utiliser les " pour eviter le re-encodage de ' et &#8217
134
+        $base64 = base64_encode(substr($rempl, $i, $taille));
135
+        $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>";
136
+    }
137
+
138
+    return $return;
139 139
 }
140 140
 
141 141
 
142 142
 // Echapper les <html>...</ html>
143 143
 function traiter_echap_html_dist($regs, $options = []) {
144
-	return $regs[3];
144
+    return $regs[3];
145 145
 }
146 146
 
147 147
 // Echapper les <pre>...</ pre>
148 148
 function traiter_echap_pre_dist($regs, $options = []) {
149
-	// echapper les <code> dans <pre>
150
-	$pre = $regs[3];
151
-
152
-	// echapper les < dans <code>
153
-	// on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code>
154
-	if (
155
-		strpos($pre, '<') !== false
156
-		and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER)
157
-	) {
158
-		foreach ($matches as $m) {
159
-			if ($m[1] === 'code') {
160
-				$code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>';
161
-				$pre = str_replace($m[0], $code, $pre);
162
-			}
163
-		}
164
-	}
165
-	return "<pre>$pre</pre>";
149
+    // echapper les <code> dans <pre>
150
+    $pre = $regs[3];
151
+
152
+    // echapper les < dans <code>
153
+    // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code>
154
+    if (
155
+        strpos($pre, '<') !== false
156
+        and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER)
157
+    ) {
158
+        foreach ($matches as $m) {
159
+            if ($m[1] === 'code') {
160
+                $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>';
161
+                $pre = str_replace($m[0], $code, $pre);
162
+            }
163
+        }
164
+    }
165
+    return "<pre>$pre</pre>";
166 166
 }
167 167
 
168 168
 // Echapper les <code>...</ code>
169 169
 function traiter_echap_code_dist($regs, $options = []) {
170
-	[, , $att, $corps] = $regs;
170
+    [, , $att, $corps] = $regs;
171 171
 
172
-	// ne pas mettre le <div...> s'il n'y a qu'une ligne
173
-	if (strpos($corps, "\n") !== false) {
174
-		// supprimer les sauts de ligne debut/fin
175
-		// (mais pas les espaces => ascii art).
176
-		$corps = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $corps);
172
+    // ne pas mettre le <div...> s'il n'y a qu'une ligne
173
+    if (strpos($corps, "\n") !== false) {
174
+        // supprimer les sauts de ligne debut/fin
175
+        // (mais pas les espaces => ascii art).
176
+        $corps = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $corps);
177 177
 
178
-		$echap = spip_balisage_code($corps, true, $att);
179
-	} else {
180
-		$echap = spip_balisage_code($corps, false, $att);
181
-	}
178
+        $echap = spip_balisage_code($corps, true, $att);
179
+    } else {
180
+        $echap = spip_balisage_code($corps, false, $att);
181
+    }
182 182
 
183
-	return $echap;
183
+    return $echap;
184 184
 }
185 185
 
186 186
 // Echapper les <cadre>...</ cadre> aka <frame>...</ frame>
187 187
 function traiter_echap_cadre_dist($regs, $options = []) {
188
-	$echap = trim(entites_html($regs[3]));
189
-	// compter les lignes un peu plus finement qu'avec les \n
190
-	$lignes = explode("\n", trim($echap));
191
-	$n = 0;
192
-	foreach ($lignes as $l) {
193
-		$n += floor(strlen($l) / 60) + 1;
194
-	}
195
-	$n = max($n, 2);
196
-	$echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre spip_cadre_block' dir='ltr'>$echap</textarea>";
197
-
198
-	return $echap;
188
+    $echap = trim(entites_html($regs[3]));
189
+    // compter les lignes un peu plus finement qu'avec les \n
190
+    $lignes = explode("\n", trim($echap));
191
+    $n = 0;
192
+    foreach ($lignes as $l) {
193
+        $n += floor(strlen($l) / 60) + 1;
194
+    }
195
+    $n = max($n, 2);
196
+    $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre spip_cadre_block' dir='ltr'>$echap</textarea>";
197
+
198
+    return $echap;
199 199
 }
200 200
 
201 201
 function traiter_echap_frame_dist($regs, $options = []) {
202
-	return traiter_echap_cadre_dist($regs);
202
+    return traiter_echap_cadre_dist($regs);
203 203
 }
204 204
 
205 205
 function traiter_echap_script_dist($regs, $options = []) {
206
-	// rendre joli (et inactif) si c'est un script language=php
207
-	if (preg_match(',<script\b[^>]+php,ims', $regs[0])) {
208
-		return highlight_string($regs[0], true);
209
-	}
206
+    // rendre joli (et inactif) si c'est un script language=php
207
+    if (preg_match(',<script\b[^>]+php,ims', $regs[0])) {
208
+        return highlight_string($regs[0], true);
209
+    }
210 210
 
211
-	// Cas normal : le script passe tel quel
212
-	return $regs[0];
211
+    // Cas normal : le script passe tel quel
212
+    return $regs[0];
213 213
 }
214 214
 
215 215
 define('_PROTEGE_BLOCS', ',<(html|pre|code|cadre|frame|script|style)(\b[^>]*)?>(.*)</\1>,UimsS');
@@ -228,73 +228,73 @@  discard block
 block discarded – undo
228 228
  * @return string|string[]
229 229
  */
230 230
 function echappe_html(
231
-	$letexte,
232
-	$source = '',
233
-	$no_transform = false,
234
-	$preg = '',
235
-	$callback_prefix = '',
236
-	$callback_options = []
231
+    $letexte,
232
+    $source = '',
233
+    $no_transform = false,
234
+    $preg = '',
235
+    $callback_prefix = '',
236
+    $callback_options = []
237 237
 ) {
238
-	if (!is_string($letexte) or !strlen($letexte)) {
239
-		return $letexte;
240
-	}
241
-
242
-	if (
243
-		($preg or str_contains($letexte, '<'))
244
-		and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER)
245
-	) {
246
-		foreach ($matches as $regs) {
247
-			// echappements tels quels ?
248
-			if ($no_transform) {
249
-				$echap = $regs[0];
250
-			} // sinon les traiter selon le cas
251
-			else {
252
-				$callback_secure_prefix = ($callback_options['secure_prefix'] ?? '');
253
-				if (
254
-					function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1]))
255
-					or function_exists($f = $f . '_dist')
256
-					or ($callback_secure_prefix and (
257
-						function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1]))
258
-						or function_exists($f = $f . '_dist')
259
-					))
260
-				) {
261
-					$echap = $f($regs, $callback_options);
262
-				}
263
-			}
264
-
265
-			$p = strpos($letexte, (string) $regs[0]);
266
-			$letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0]));
267
-		}
268
-	}
269
-
270
-	if ($no_transform) {
271
-		return $letexte;
272
-	}
273
-
274
-	// Echapper le php pour faire joli (ici, c'est pas pour la securite)
275
-	// seulement si on a echappe les <script>
276
-	// (derogatoire car on ne peut pas faire passer < ? ... ? >
277
-	// dans une callback autonommee
278
-	if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) {
279
-		if (
280
-			strpos($letexte, '<' . '?') !== false and preg_match_all(
281
-				',<[?].*($|[?]>),UisS',
282
-				$letexte,
283
-				$matches,
284
-				PREG_SET_ORDER
285
-			)
286
-		) {
287
-			foreach ($matches as $regs) {
288
-				$letexte = str_replace(
289
-					$regs[0],
290
-					code_echappement(highlight_string($regs[0], true), $source),
291
-					$letexte
292
-				);
293
-			}
294
-		}
295
-	}
296
-
297
-	return $letexte;
238
+    if (!is_string($letexte) or !strlen($letexte)) {
239
+        return $letexte;
240
+    }
241
+
242
+    if (
243
+        ($preg or str_contains($letexte, '<'))
244
+        and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER)
245
+    ) {
246
+        foreach ($matches as $regs) {
247
+            // echappements tels quels ?
248
+            if ($no_transform) {
249
+                $echap = $regs[0];
250
+            } // sinon les traiter selon le cas
251
+            else {
252
+                $callback_secure_prefix = ($callback_options['secure_prefix'] ?? '');
253
+                if (
254
+                    function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1]))
255
+                    or function_exists($f = $f . '_dist')
256
+                    or ($callback_secure_prefix and (
257
+                        function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1]))
258
+                        or function_exists($f = $f . '_dist')
259
+                    ))
260
+                ) {
261
+                    $echap = $f($regs, $callback_options);
262
+                }
263
+            }
264
+
265
+            $p = strpos($letexte, (string) $regs[0]);
266
+            $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0]));
267
+        }
268
+    }
269
+
270
+    if ($no_transform) {
271
+        return $letexte;
272
+    }
273
+
274
+    // Echapper le php pour faire joli (ici, c'est pas pour la securite)
275
+    // seulement si on a echappe les <script>
276
+    // (derogatoire car on ne peut pas faire passer < ? ... ? >
277
+    // dans une callback autonommee
278
+    if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) {
279
+        if (
280
+            strpos($letexte, '<' . '?') !== false and preg_match_all(
281
+                ',<[?].*($|[?]>),UisS',
282
+                $letexte,
283
+                $matches,
284
+                PREG_SET_ORDER
285
+            )
286
+        ) {
287
+            foreach ($matches as $regs) {
288
+                $letexte = str_replace(
289
+                    $regs[0],
290
+                    code_echappement(highlight_string($regs[0], true), $source),
291
+                    $letexte
292
+                );
293
+            }
294
+        }
295
+    }
296
+
297
+    return $letexte;
298 298
 }
299 299
 
300 300
 //
@@ -302,57 +302,57 @@  discard block
 block discarded – undo
302 302
 // Rq: $source sert a faire des echappements "a soi" qui ne sont pas nettoyes
303 303
 // par propre() : exemple dans multi et dans typo()
304 304
 function echappe_retour($letexte, $source = '', $filtre = '') {
305
-	if (strpos($letexte, (string) "base64$source")) {
306
-		# spip_log(spip_htmlspecialchars($letexte));  ## pour les curieux
307
-		$max_prof = 5;
308
-		while (
309
-			strpos($letexte, '<') !== false
310
-			and
311
-			preg_match_all(
312
-				',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS',
313
-				$letexte,
314
-				$regs,
315
-				PREG_SET_ORDER
316
-			)
317
-			and $max_prof--
318
-		) {
319
-			foreach ($regs as $reg) {
320
-				$rempl = base64_decode(extraire_attribut($reg[0], 'title'));
321
-				// recherche d'attributs supplementaires
322
-				$at = [];
323
-				foreach (['lang', 'dir'] as $attr) {
324
-					if ($a = extraire_attribut($reg[0], $attr)) {
325
-						$at[$attr] = $a;
326
-					}
327
-				}
328
-				if ($at) {
329
-					$rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>';
330
-					foreach ($at as $attr => $a) {
331
-						$rempl = inserer_attribut($rempl, $attr, $a);
332
-					}
333
-				}
334
-				if ($filtre) {
335
-					$rempl = $filtre($rempl);
336
-				}
337
-				$letexte = str_replace($reg[0], $rempl, $letexte);
338
-			}
339
-		}
340
-	}
341
-
342
-	return $letexte;
305
+    if (strpos($letexte, (string) "base64$source")) {
306
+        # spip_log(spip_htmlspecialchars($letexte));  ## pour les curieux
307
+        $max_prof = 5;
308
+        while (
309
+            strpos($letexte, '<') !== false
310
+            and
311
+            preg_match_all(
312
+                ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS',
313
+                $letexte,
314
+                $regs,
315
+                PREG_SET_ORDER
316
+            )
317
+            and $max_prof--
318
+        ) {
319
+            foreach ($regs as $reg) {
320
+                $rempl = base64_decode(extraire_attribut($reg[0], 'title'));
321
+                // recherche d'attributs supplementaires
322
+                $at = [];
323
+                foreach (['lang', 'dir'] as $attr) {
324
+                    if ($a = extraire_attribut($reg[0], $attr)) {
325
+                        $at[$attr] = $a;
326
+                    }
327
+                }
328
+                if ($at) {
329
+                    $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>';
330
+                    foreach ($at as $attr => $a) {
331
+                        $rempl = inserer_attribut($rempl, $attr, $a);
332
+                    }
333
+                }
334
+                if ($filtre) {
335
+                    $rempl = $filtre($rempl);
336
+                }
337
+                $letexte = str_replace($reg[0], $rempl, $letexte);
338
+            }
339
+        }
340
+    }
341
+
342
+    return $letexte;
343 343
 }
344 344
 
345 345
 // Reinserer le javascript de confiance (venant des modeles)
346 346
 
347 347
 function echappe_retour_modeles($letexte, $interdire_scripts = false) {
348
-	$letexte = echappe_retour($letexte);
348
+    $letexte = echappe_retour($letexte);
349 349
 
350
-	// Dans les appels directs hors squelette, securiser aussi ici
351
-	if ($interdire_scripts) {
352
-		$letexte = interdire_scripts($letexte);
353
-	}
350
+    // Dans les appels directs hors squelette, securiser aussi ici
351
+    if ($interdire_scripts) {
352
+        $letexte = interdire_scripts($letexte);
353
+    }
354 354
 
355
-	return trim($letexte);
355
+    return trim($letexte);
356 356
 }
357 357
 
358 358
 
@@ -380,131 +380,131 @@  discard block
 block discarded – undo
380 380
  *     texte coupé
381 381
  **/
382 382
 function couper($texte, $taille = 50, $suite = null) {
383
-	if (!($length = strlen($texte)) or $taille <= 0) {
384
-		return '';
385
-	}
386
-	$offset = 400 + 2 * $taille;
387
-	while (
388
-		$offset < $length
389
-		and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille
390
-	) {
391
-		$offset = 2 * $offset;
392
-	}
393
-	if (
394
-		$offset < $length
395
-		&& ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null
396
-	) {
397
-		$p_tag_fermant = strpos($texte, '>', $offset);
398
-		if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) {
399
-			$offset = $p_tag_fermant + 1;
400
-		} // prolonger la coupe jusqu'au tag fermant suivant eventuel
401
-	}
402
-	$texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */
403
-
404
-	if (!function_exists('nettoyer_raccourcis_typo')) {
405
-		include_spip('inc/lien');
406
-	}
407
-	$texte = nettoyer_raccourcis_typo($texte);
408
-
409
-	// balises de sauts de ligne et paragraphe
410
-	$texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte);
411
-	$texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte);
412
-
413
-	// on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier
414
-	$texte = str_replace("\n\n", "\r", $texte);
415
-
416
-	// supprimer les tags
417
-	$texte = supprimer_tags($texte);
418
-	$texte = trim(str_replace("\n", ' ', $texte));
419
-	$texte .= "\n";  // marquer la fin
420
-
421
-	// corriger la longueur de coupe
422
-	// en fonction de la presence de caracteres utf
423
-	if ($GLOBALS['meta']['charset'] == 'utf-8') {
424
-		$long = charset2unicode($texte);
425
-		$long = spip_substr($long, 0, max($taille, 1));
426
-		$nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches);
427
-		$taille += $nbcharutf;
428
-	}
429
-
430
-
431
-	// couper au mot precedent
432
-	$long = spip_substr($texte, 0, max($taille - 4, 1));
433
-	$u = $GLOBALS['meta']['pcre_u'];
434
-	$court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
435
-	if (is_null($suite)) {
436
-		$suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : '&nbsp;(...)');
437
-	}
438
-	$points = $suite;
439
-
440
-	// trop court ? ne pas faire de (...)
441
-	if (spip_strlen($court) < max(0.75 * $taille, 2)) {
442
-		$points = '';
443
-		$long = spip_substr($texte, 0, $taille);
444
-		$texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
445
-		// encore trop court ? couper au caractere
446
-		if (spip_strlen($texte) < 0.75 * $taille) {
447
-			$texte = $long;
448
-		}
449
-	} else {
450
-		$texte = $court;
451
-	}
452
-
453
-	if (strpos($texte, "\n")) {  // la fin est encore la : c'est qu'on n'a pas de texte de suite
454
-	$points = '';
455
-	}
456
-
457
-	// remettre les paragraphes
458
-	$texte = preg_replace("/\r+/", "\n\n", $texte);
459
-
460
-	// supprimer l'eventuelle entite finale mal coupee
461
-	$texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte);
462
-
463
-	return quote_amp(trim($texte)) . $points;
383
+    if (!($length = strlen($texte)) or $taille <= 0) {
384
+        return '';
385
+    }
386
+    $offset = 400 + 2 * $taille;
387
+    while (
388
+        $offset < $length
389
+        and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille
390
+    ) {
391
+        $offset = 2 * $offset;
392
+    }
393
+    if (
394
+        $offset < $length
395
+        && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null
396
+    ) {
397
+        $p_tag_fermant = strpos($texte, '>', $offset);
398
+        if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) {
399
+            $offset = $p_tag_fermant + 1;
400
+        } // prolonger la coupe jusqu'au tag fermant suivant eventuel
401
+    }
402
+    $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */
403
+
404
+    if (!function_exists('nettoyer_raccourcis_typo')) {
405
+        include_spip('inc/lien');
406
+    }
407
+    $texte = nettoyer_raccourcis_typo($texte);
408
+
409
+    // balises de sauts de ligne et paragraphe
410
+    $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte);
411
+    $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte);
412
+
413
+    // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier
414
+    $texte = str_replace("\n\n", "\r", $texte);
415
+
416
+    // supprimer les tags
417
+    $texte = supprimer_tags($texte);
418
+    $texte = trim(str_replace("\n", ' ', $texte));
419
+    $texte .= "\n";  // marquer la fin
420
+
421
+    // corriger la longueur de coupe
422
+    // en fonction de la presence de caracteres utf
423
+    if ($GLOBALS['meta']['charset'] == 'utf-8') {
424
+        $long = charset2unicode($texte);
425
+        $long = spip_substr($long, 0, max($taille, 1));
426
+        $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches);
427
+        $taille += $nbcharutf;
428
+    }
429
+
430
+
431
+    // couper au mot precedent
432
+    $long = spip_substr($texte, 0, max($taille - 4, 1));
433
+    $u = $GLOBALS['meta']['pcre_u'];
434
+    $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
435
+    if (is_null($suite)) {
436
+        $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : '&nbsp;(...)');
437
+    }
438
+    $points = $suite;
439
+
440
+    // trop court ? ne pas faire de (...)
441
+    if (spip_strlen($court) < max(0.75 * $taille, 2)) {
442
+        $points = '';
443
+        $long = spip_substr($texte, 0, $taille);
444
+        $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
445
+        // encore trop court ? couper au caractere
446
+        if (spip_strlen($texte) < 0.75 * $taille) {
447
+            $texte = $long;
448
+        }
449
+    } else {
450
+        $texte = $court;
451
+    }
452
+
453
+    if (strpos($texte, "\n")) {  // la fin est encore la : c'est qu'on n'a pas de texte de suite
454
+    $points = '';
455
+    }
456
+
457
+    // remettre les paragraphes
458
+    $texte = preg_replace("/\r+/", "\n\n", $texte);
459
+
460
+    // supprimer l'eventuelle entite finale mal coupee
461
+    $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte);
462
+
463
+    return quote_amp(trim($texte)) . $points;
464 464
 }
465 465
 
466 466
 
467 467
 function protege_js_modeles($t) {
468
-	if (isset($GLOBALS['visiteur_session'])) {
469
-		if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) {
470
-			if (!defined('_PROTEGE_JS_MODELES')) {
471
-				include_spip('inc/acces');
472
-				define('_PROTEGE_JS_MODELES', creer_uniqid());
473
-			}
474
-			foreach ($r as $regs) {
475
-				$t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t);
476
-			}
477
-		}
478
-		if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) {
479
-			if (!defined('_PROTEGE_PHP_MODELES')) {
480
-				include_spip('inc/acces');
481
-				define('_PROTEGE_PHP_MODELES', creer_uniqid());
482
-			}
483
-			foreach ($r as $regs) {
484
-				$t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t);
485
-			}
486
-		}
487
-	}
488
-
489
-	return $t;
468
+    if (isset($GLOBALS['visiteur_session'])) {
469
+        if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) {
470
+            if (!defined('_PROTEGE_JS_MODELES')) {
471
+                include_spip('inc/acces');
472
+                define('_PROTEGE_JS_MODELES', creer_uniqid());
473
+            }
474
+            foreach ($r as $regs) {
475
+                $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t);
476
+            }
477
+        }
478
+        if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) {
479
+            if (!defined('_PROTEGE_PHP_MODELES')) {
480
+                include_spip('inc/acces');
481
+                define('_PROTEGE_PHP_MODELES', creer_uniqid());
482
+            }
483
+            foreach ($r as $regs) {
484
+                $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t);
485
+            }
486
+        }
487
+    }
488
+
489
+    return $t;
490 490
 }
491 491
 
492 492
 
493 493
 function echapper_faux_tags($letexte) {
494
-	if (strpos($letexte, '<') === false) {
495
-		return $letexte;
496
-	}
497
-	$textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE);
498
-
499
-	$letexte = '';
500
-	while (is_countable($textMatches) ? count($textMatches) : 0) {
501
-		// un texte a echapper
502
-		$letexte .= str_replace('<', '&lt;', array_shift($textMatches));
503
-		// un tag html qui a servit a faite le split
504
-		$letexte .= array_shift($textMatches);
505
-	}
506
-
507
-	return $letexte;
494
+    if (strpos($letexte, '<') === false) {
495
+        return $letexte;
496
+    }
497
+    $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE);
498
+
499
+    $letexte = '';
500
+    while (is_countable($textMatches) ? count($textMatches) : 0) {
501
+        // un texte a echapper
502
+        $letexte .= str_replace('<', '&lt;', array_shift($textMatches));
503
+        // un tag html qui a servit a faite le split
504
+        $letexte .= array_shift($textMatches);
505
+    }
506
+
507
+    return $letexte;
508 508
 }
509 509
 
510 510
 /**
@@ -524,115 +524,115 @@  discard block
 block discarded – undo
524 524
  * @return string
525 525
  */
526 526
 function echapper_html_suspect($texte, $options = [], $connect = null, $env = []) {
527
-	static $echapper_html_suspect;
528
-	if (!$texte or !is_string($texte)) {
529
-		return $texte;
530
-	}
531
-
532
-	if (!isset($echapper_html_suspect)) {
533
-		$echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true);
534
-	}
535
-	// si fonction personalisee, on delegue
536
-	if ($echapper_html_suspect) {
537
-		// on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature
538
-		$args = [$texte, $options];
539
-		if ($connect or !empty($env)) {
540
-			$args[] = $connect;
541
-		}
542
-		if (!empty($env)) {
543
-			$args[] = $env;
544
-		}
545
-		return $echapper_html_suspect(...$args);
546
-	}
547
-
548
-	if (is_bool($options)) {
549
-		$options = ['strict' => $options];
550
-	}
551
-	$strict = $options['strict'] ?? true;
552
-
553
-	// pas de balise html ou pas d'attribut sur les balises ? c'est OK
554
-	if (
555
-		strpos($texte, '<') === false
556
-		or !str_contains($texte, '=')
557
-	) {
558
-		return $texte;
559
-	}
560
-
561
-	// dans le prive, on veut afficher tout echappé pour la moderation
562
-	if (!isset($env['espace_prive'])) {
563
-		// conserver le comportement historique en cas d'appel court sans env
564
-		$env['espace_prive'] = test_espace_prive();
565
-	}
566
-	if (!empty($env['espace_prive']) or !empty($env['wysiwyg'])) {
567
-
568
-		// quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx=
569
-		// car sinon on declenche sur les modeles ou ressources
570
-		if (
571
-			!$strict and
572
-			(strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte))
573
-		) {
574
-			return $texte;
575
-		}
576
-
577
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
578
-		include_spip("src/Texte/Collecteur/Modeles");
579
-		$collecteurModeles = new Spip\Texte\Collecteur\Modeles();
580
-		$texte = $collecteurModeles->echapper($texte);
581
-		$texte = echappe_js($texte);
582
-
583
-		$texte_to_check = $texte;
584
-		// si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe
585
-		// car un raccourci peut etre utilisé pour faire un lien malin
586
-		// et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe
587
-		if (!empty($options['expanser_liens'])) {
588
-			$texte_to_check = expanser_liens($texte_to_check, $env['connect'] ?? '', $env['env'] ?? []);
589
-		}
590
-		if (!is_html_safe($texte_to_check)) {
591
-			$texte = $options['texte_source_affiche'] ?? $texte;
592
-			$texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt>&lt;\\1</tt>", $texte);
593
-			$texte = str_replace('<', '&lt;', $texte);
594
-			$texte = str_replace('&lt;tt>', '<tt>', $texte);
595
-			$texte = str_replace('&lt;/tt>', '</tt>', $texte);
596
-			if (!function_exists('attribut_html')) {
597
-				include_spip('inc/filtres');
598
-			}
599
-			if (!empty($options['wrap_suspect'])) {
600
-				$texte = wrap($texte, $options['wrap_suspect']);
601
-			}
602
-			$texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte;
603
-		}
604
-
605
-		$texte = $collecteurModeles->retablir($texte);
606
-	}
607
-
608
-	// si on est là dans le public c'est le mode parano
609
-	// on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux
610
-	else {
611
-		$collecteurLiens = $collecteurModeles = null;
612
-		if (!empty($options['expanser_liens'])) {
613
-			$texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []);
614
-		}
615
-		else {
616
-			include_spip("src/Texte/Collecteur/AbstractCollecteur");
617
-			include_spip("src/Texte/Collecteur/Liens");
618
-			include_spip("src/Texte/Collecteur/Modeles");
619
-
620
-			$collecteurLiens = new Spip\Texte\Collecteur\Liens();
621
-			$texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']);
622
-
623
-			$collecteurModeles = new Spip\Texte\Collecteur\Modeles();
624
-			$texte = $collecteurModeles->echapper($texte);
625
-		}
626
-		$texte = safehtml($texte);
627
-		if ($collecteurModeles) {
628
-			$texte = $collecteurModeles->retablir($texte);
629
-		}
630
-		if ($collecteurLiens) {
631
-			$texte = $collecteurLiens->retablir($texte);
632
-		}
633
-	}
634
-
635
-	return $texte;
527
+    static $echapper_html_suspect;
528
+    if (!$texte or !is_string($texte)) {
529
+        return $texte;
530
+    }
531
+
532
+    if (!isset($echapper_html_suspect)) {
533
+        $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true);
534
+    }
535
+    // si fonction personalisee, on delegue
536
+    if ($echapper_html_suspect) {
537
+        // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature
538
+        $args = [$texte, $options];
539
+        if ($connect or !empty($env)) {
540
+            $args[] = $connect;
541
+        }
542
+        if (!empty($env)) {
543
+            $args[] = $env;
544
+        }
545
+        return $echapper_html_suspect(...$args);
546
+    }
547
+
548
+    if (is_bool($options)) {
549
+        $options = ['strict' => $options];
550
+    }
551
+    $strict = $options['strict'] ?? true;
552
+
553
+    // pas de balise html ou pas d'attribut sur les balises ? c'est OK
554
+    if (
555
+        strpos($texte, '<') === false
556
+        or !str_contains($texte, '=')
557
+    ) {
558
+        return $texte;
559
+    }
560
+
561
+    // dans le prive, on veut afficher tout echappé pour la moderation
562
+    if (!isset($env['espace_prive'])) {
563
+        // conserver le comportement historique en cas d'appel court sans env
564
+        $env['espace_prive'] = test_espace_prive();
565
+    }
566
+    if (!empty($env['espace_prive']) or !empty($env['wysiwyg'])) {
567
+
568
+        // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx=
569
+        // car sinon on declenche sur les modeles ou ressources
570
+        if (
571
+            !$strict and
572
+            (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte))
573
+        ) {
574
+            return $texte;
575
+        }
576
+
577
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
578
+        include_spip("src/Texte/Collecteur/Modeles");
579
+        $collecteurModeles = new Spip\Texte\Collecteur\Modeles();
580
+        $texte = $collecteurModeles->echapper($texte);
581
+        $texte = echappe_js($texte);
582
+
583
+        $texte_to_check = $texte;
584
+        // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe
585
+        // car un raccourci peut etre utilisé pour faire un lien malin
586
+        // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe
587
+        if (!empty($options['expanser_liens'])) {
588
+            $texte_to_check = expanser_liens($texte_to_check, $env['connect'] ?? '', $env['env'] ?? []);
589
+        }
590
+        if (!is_html_safe($texte_to_check)) {
591
+            $texte = $options['texte_source_affiche'] ?? $texte;
592
+            $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt>&lt;\\1</tt>", $texte);
593
+            $texte = str_replace('<', '&lt;', $texte);
594
+            $texte = str_replace('&lt;tt>', '<tt>', $texte);
595
+            $texte = str_replace('&lt;/tt>', '</tt>', $texte);
596
+            if (!function_exists('attribut_html')) {
597
+                include_spip('inc/filtres');
598
+            }
599
+            if (!empty($options['wrap_suspect'])) {
600
+                $texte = wrap($texte, $options['wrap_suspect']);
601
+            }
602
+            $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte;
603
+        }
604
+
605
+        $texte = $collecteurModeles->retablir($texte);
606
+    }
607
+
608
+    // si on est là dans le public c'est le mode parano
609
+    // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux
610
+    else {
611
+        $collecteurLiens = $collecteurModeles = null;
612
+        if (!empty($options['expanser_liens'])) {
613
+            $texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []);
614
+        }
615
+        else {
616
+            include_spip("src/Texte/Collecteur/AbstractCollecteur");
617
+            include_spip("src/Texte/Collecteur/Liens");
618
+            include_spip("src/Texte/Collecteur/Modeles");
619
+
620
+            $collecteurLiens = new Spip\Texte\Collecteur\Liens();
621
+            $texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']);
622
+
623
+            $collecteurModeles = new Spip\Texte\Collecteur\Modeles();
624
+            $texte = $collecteurModeles->echapper($texte);
625
+        }
626
+        $texte = safehtml($texte);
627
+        if ($collecteurModeles) {
628
+            $texte = $collecteurModeles->retablir($texte);
629
+        }
630
+        if ($collecteurLiens) {
631
+            $texte = $collecteurLiens->retablir($texte);
632
+        }
633
+    }
634
+
635
+    return $texte;
636 636
 }
637 637
 
638 638
 
@@ -653,52 +653,52 @@  discard block
 block discarded – undo
653 653
  *      texte sécurisé
654 654
  **/
655 655
 function safehtml($t) {
656
-	static $safehtml;
657
-
658
-	if (!$t or !is_string($t)) {
659
-		return $t;
660
-	}
661
-	# attention safehtml nettoie deux ou trois caracteres de plus. A voir
662
-	if (strpos($t, '<') === false) {
663
-		return str_replace("\x00", '', $t);
664
-	}
665
-
666
-	$collecteurIdiomes = null;
667
-	if (stripos($t, '<:') !== false) {
668
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
669
-		include_spip("src/Texte/Collecteur/Idiomes");
670
-		$collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes();
671
-		$t = $collecteurIdiomes->echapper($t);
672
-	}
673
-	$collecteurMultis = null;
674
-	if (stripos($t, '<multi') !== false) {
675
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
676
-		include_spip("src/Texte/Collecteur/Multis");
677
-		$collecteurMultis = new Spip\Texte\Collecteur\Multis();
678
-		$t = $collecteurMultis->echapper($t, ['sanitize_callback' => 'safehtml']);
679
-	}
680
-
681
-	if (!function_exists('interdire_scripts')) {
682
-		include_spip('inc/texte');
683
-	}
684
-	$t = interdire_scripts($t); // jolifier le php
685
-	$t = echappe_js($t);
686
-
687
-	if (!isset($safehtml)) {
688
-		$safehtml = charger_fonction('safehtml', 'inc', true);
689
-	}
690
-	if ($safehtml) {
691
-		$t = $safehtml($t);
692
-	}
693
-
694
-	if ($collecteurMultis) {
695
-		$t = $collecteurMultis->retablir($t);
696
-	}
697
-	if ($collecteurIdiomes) {
698
-		$t = $collecteurIdiomes->retablir($t);
699
-	}
700
-
701
-	return interdire_scripts($t); // interdire le php (2 precautions)
656
+    static $safehtml;
657
+
658
+    if (!$t or !is_string($t)) {
659
+        return $t;
660
+    }
661
+    # attention safehtml nettoie deux ou trois caracteres de plus. A voir
662
+    if (strpos($t, '<') === false) {
663
+        return str_replace("\x00", '', $t);
664
+    }
665
+
666
+    $collecteurIdiomes = null;
667
+    if (stripos($t, '<:') !== false) {
668
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
669
+        include_spip("src/Texte/Collecteur/Idiomes");
670
+        $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes();
671
+        $t = $collecteurIdiomes->echapper($t);
672
+    }
673
+    $collecteurMultis = null;
674
+    if (stripos($t, '<multi') !== false) {
675
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
676
+        include_spip("src/Texte/Collecteur/Multis");
677
+        $collecteurMultis = new Spip\Texte\Collecteur\Multis();
678
+        $t = $collecteurMultis->echapper($t, ['sanitize_callback' => 'safehtml']);
679
+    }
680
+
681
+    if (!function_exists('interdire_scripts')) {
682
+        include_spip('inc/texte');
683
+    }
684
+    $t = interdire_scripts($t); // jolifier le php
685
+    $t = echappe_js($t);
686
+
687
+    if (!isset($safehtml)) {
688
+        $safehtml = charger_fonction('safehtml', 'inc', true);
689
+    }
690
+    if ($safehtml) {
691
+        $t = $safehtml($t);
692
+    }
693
+
694
+    if ($collecteurMultis) {
695
+        $t = $collecteurMultis->retablir($t);
696
+    }
697
+    if ($collecteurIdiomes) {
698
+        $t = $collecteurIdiomes->retablir($t);
699
+    }
700
+
701
+    return interdire_scripts($t); // interdire le php (2 precautions)
702 702
 }
703 703
 
704 704
 
@@ -706,25 +706,25 @@  discard block
 block discarded – undo
706 706
  * Detecter si un texte est "safe" ie non modifie significativement par safehtml()
707 707
  */
708 708
 function is_html_safe(string $texte): bool {
709
-	if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) {
710
-		return $is_html_safe($texte);
711
-	}
712
-
713
-	// simplifier les retour ligne pour etre certain de ce que l'on compare
714
-	$texte = str_replace("\r\n", "\n", $texte);
715
-	// safehtml reduit aussi potentiellement les &nbsp;
716
-	$texte = str_replace("&nbsp;", " ", $texte);
717
-	// safehtml remplace les entités numériques
718
-	if (strpos($texte, '&#') !== false) {
719
-		$texte = unicode2charset($texte);
720
-	}
721
-
722
-	$texte_safe = safehtml($texte);
723
-
724
-	// on teste sur strlen car safehtml supprime le contenu dangereux
725
-	// mais il peut aussi changer des ' en " sur les attributs html,
726
-	// donc un test d'egalite est trop strict
727
-	return strlen($texte_safe) === strlen($texte);
709
+    if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) {
710
+        return $is_html_safe($texte);
711
+    }
712
+
713
+    // simplifier les retour ligne pour etre certain de ce que l'on compare
714
+    $texte = str_replace("\r\n", "\n", $texte);
715
+    // safehtml reduit aussi potentiellement les &nbsp;
716
+    $texte = str_replace("&nbsp;", " ", $texte);
717
+    // safehtml remplace les entités numériques
718
+    if (strpos($texte, '&#') !== false) {
719
+        $texte = unicode2charset($texte);
720
+    }
721
+
722
+    $texte_safe = safehtml($texte);
723
+
724
+    // on teste sur strlen car safehtml supprime le contenu dangereux
725
+    // mais il peut aussi changer des ' en " sur les attributs html,
726
+    // donc un test d'egalite est trop strict
727
+    return strlen($texte_safe) === strlen($texte);
728 728
 }
729 729
 
730 730
 /**
@@ -745,13 +745,13 @@  discard block
 block discarded – undo
745 745
  *     texte sans les modèles d'image
746 746
  **/
747 747
 function supprime_img($letexte, $message = null) {
748
-	if ($message === null) {
749
-		$message = '(' . _T('img_indisponible') . ')';
750
-	}
751
-
752
-	return preg_replace(
753
-		',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i',
754
-		$message,
755
-		$letexte
756
-	);
748
+    if ($message === null) {
749
+        $message = '(' . _T('img_indisponible') . ')';
750
+    }
751
+
752
+    return preg_replace(
753
+        ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i',
754
+        $message,
755
+        $letexte
756
+    );
757 757
 }
Please login to merge, or discard this patch.
ecrire/inc/utils.php 2 patches
Indentation   +2271 added lines, -2272 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -48,71 +48,71 @@  discard block
 block discarded – undo
48 48
  *     Nom de la fonction, ou false.
49 49
  */
50 50
 function charger_fonction($nom, $dossier = 'exec', $continue = false) {
51
-	static $echecs = [];
52
-
53
-	if (strlen($dossier) and substr($dossier, -1) != '/') {
54
-		$dossier .= '/';
55
-	}
56
-	$f = str_replace('/', '_', $dossier) . $nom;
57
-
58
-	if (function_exists($f)) {
59
-		return $f;
60
-	}
61
-	if (function_exists($g = $f . '_dist')) {
62
-		return $g;
63
-	}
64
-
65
-	if (isset($echecs[$f])) {
66
-		return $echecs[$f];
67
-	}
68
-	// Sinon charger le fichier de declaration si plausible
69
-
70
-	if (!preg_match(',^\w+$,', $f)) {
71
-		if ($continue) {
72
-			return false;
73
-		} //appel interne, on passe
74
-		include_spip('inc/minipres');
75
-		echo minipres();
76
-		exit;
77
-	}
78
-
79
-	// passer en minuscules (cf les balises de formulaires)
80
-	// et inclure le fichier
81
-	if (
82
-		!$inc = include_spip($dossier . ($d = strtolower($nom)))
83
-		// si le fichier truc/machin/nom.php n'existe pas,
84
-		// la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
85
-		and strlen(dirname($dossier)) and dirname($dossier) != '.'
86
-	) {
87
-		include_spip(substr($dossier, 0, -1));
88
-	}
89
-	if (function_exists($f)) {
90
-		return $f;
91
-	}
92
-	if (function_exists($g)) {
93
-		return $g;
94
-	}
95
-
96
-	if ($continue) {
97
-		return $echecs[$f] = false;
98
-	}
99
-
100
-	// Echec : message d'erreur
101
-	spip_log("fonction $nom ($f ou $g) indisponible" .
102
-		($inc ? '' : " (fichier $d absent de $dossier)"));
103
-
104
-	include_spip('inc/minipres');
105
-	echo minipres(
106
-		_T('forum_titre_erreur'),
107
-		$inc ?
108
-			_T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($f) . '</code>'])
109
-			. '<br />'
110
-			. _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($g) . '</code>'])
111
-			:
112
-			_T('fichier_introuvable', ['fichier' => '<code>' . spip_htmlentities($d) . '</code>']),
113
-		['all_inline' => true,'status' => 404]
114
-	);
115
-	exit;
51
+    static $echecs = [];
52
+
53
+    if (strlen($dossier) and substr($dossier, -1) != '/') {
54
+        $dossier .= '/';
55
+    }
56
+    $f = str_replace('/', '_', $dossier) . $nom;
57
+
58
+    if (function_exists($f)) {
59
+        return $f;
60
+    }
61
+    if (function_exists($g = $f . '_dist')) {
62
+        return $g;
63
+    }
64
+
65
+    if (isset($echecs[$f])) {
66
+        return $echecs[$f];
67
+    }
68
+    // Sinon charger le fichier de declaration si plausible
69
+
70
+    if (!preg_match(',^\w+$,', $f)) {
71
+        if ($continue) {
72
+            return false;
73
+        } //appel interne, on passe
74
+        include_spip('inc/minipres');
75
+        echo minipres();
76
+        exit;
77
+    }
78
+
79
+    // passer en minuscules (cf les balises de formulaires)
80
+    // et inclure le fichier
81
+    if (
82
+        !$inc = include_spip($dossier . ($d = strtolower($nom)))
83
+        // si le fichier truc/machin/nom.php n'existe pas,
84
+        // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
85
+        and strlen(dirname($dossier)) and dirname($dossier) != '.'
86
+    ) {
87
+        include_spip(substr($dossier, 0, -1));
88
+    }
89
+    if (function_exists($f)) {
90
+        return $f;
91
+    }
92
+    if (function_exists($g)) {
93
+        return $g;
94
+    }
95
+
96
+    if ($continue) {
97
+        return $echecs[$f] = false;
98
+    }
99
+
100
+    // Echec : message d'erreur
101
+    spip_log("fonction $nom ($f ou $g) indisponible" .
102
+        ($inc ? '' : " (fichier $d absent de $dossier)"));
103
+
104
+    include_spip('inc/minipres');
105
+    echo minipres(
106
+        _T('forum_titre_erreur'),
107
+        $inc ?
108
+            _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($f) . '</code>'])
109
+            . '<br />'
110
+            . _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($g) . '</code>'])
111
+            :
112
+            _T('fichier_introuvable', ['fichier' => '<code>' . spip_htmlentities($d) . '</code>']),
113
+        ['all_inline' => true,'status' => 404]
114
+    );
115
+    exit;
116 116
 }
117 117
 
118 118
 /**
@@ -122,17 +122,17 @@  discard block
 block discarded – undo
122 122
  * @return bool
123 123
  */
124 124
 function include_once_check($file) {
125
-	if (file_exists($file)) {
126
-		include_once $file;
125
+    if (file_exists($file)) {
126
+        include_once $file;
127 127
 
128
-		return true;
129
-	}
130
-	$crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
131
-	$crash = ($crash ?: []);
132
-	$crash[$file] = true;
133
-	ecrire_meta('message_crash_plugins', serialize($crash));
128
+        return true;
129
+    }
130
+    $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
131
+    $crash = ($crash ?: []);
132
+    $crash[$file] = true;
133
+    ecrire_meta('message_crash_plugins', serialize($crash));
134 134
 
135
-	return false;
135
+    return false;
136 136
 }
137 137
 
138 138
 
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
  *     - string : chemin du fichier trouvé
157 157
  **/
158 158
 function include_spip($f, $include = true) {
159
-	return find_in_path($f . '.php', '', $include);
159
+    return find_in_path($f . '.php', '', $include);
160 160
 }
161 161
 
162 162
 /**
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
  *     - string : chemin du fichier trouvé
177 177
  **/
178 178
 function require_spip($f) {
179
-	return find_in_path($f . '.php', '', 'required');
179
+    return find_in_path($f . '.php', '', 'required');
180 180
 }
181 181
 
182 182
 
@@ -185,27 +185,27 @@  discard block
 block discarded – undo
185 185
  * quand on a besoin dans le PHP de filtres/fonctions qui y sont definis
186 186
  */
187 187
 function include_fichiers_fonctions() {
188
-	static $done = false;
189
-	if (!$done) {
190
-		include_spip('inc/lang');
191
-
192
-		// NB: mes_fonctions peut initialiser $dossier_squelettes (old-style)
193
-		// donc il faut l'inclure "en globals"
194
-		if ($f = find_in_path('mes_fonctions.php')) {
195
-			global $dossier_squelettes;
196
-			include_once(_ROOT_CWD . $f);
197
-		}
198
-
199
-		if (@is_readable(_CACHE_PLUGINS_FCT)) {
200
-			// chargement optimise precompile
201
-			include_once(_CACHE_PLUGINS_FCT);
202
-		}
203
-		if (test_espace_prive()) {
204
-			include_spip('inc/filtres_ecrire');
205
-		}
206
-		include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises..
207
-		$done = true;
208
-	}
188
+    static $done = false;
189
+    if (!$done) {
190
+        include_spip('inc/lang');
191
+
192
+        // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style)
193
+        // donc il faut l'inclure "en globals"
194
+        if ($f = find_in_path('mes_fonctions.php')) {
195
+            global $dossier_squelettes;
196
+            include_once(_ROOT_CWD . $f);
197
+        }
198
+
199
+        if (@is_readable(_CACHE_PLUGINS_FCT)) {
200
+            // chargement optimise precompile
201
+            include_once(_CACHE_PLUGINS_FCT);
202
+        }
203
+        if (test_espace_prive()) {
204
+            include_spip('inc/filtres_ecrire');
205
+        }
206
+        include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises..
207
+        $done = true;
208
+    }
209 209
 }
210 210
 
211 211
 /**
@@ -231,23 +231,23 @@  discard block
 block discarded – undo
231 231
  *     Les paramètres du pipeline modifiés
232 232
  **/
233 233
 function minipipe($fonc, &$val) {
234
-	// fonction
235
-	if (function_exists($fonc)) {
236
-		$val = $fonc($val);
237
-	} // Class::Methode
238
-	else {
239
-		if (
240
-			preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs)
241
-			and $methode = [$regs[1], $regs[2]]
242
-			and is_callable($methode)
243
-		) {
244
-			$val = $methode($val);
245
-		} else {
246
-			spip_log("Erreur - '$fonc' non definie !");
247
-		}
248
-	}
249
-
250
-	return $val;
234
+    // fonction
235
+    if (function_exists($fonc)) {
236
+        $val = $fonc($val);
237
+    } // Class::Methode
238
+    else {
239
+        if (
240
+            preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs)
241
+            and $methode = [$regs[1], $regs[2]]
242
+            and is_callable($methode)
243
+        ) {
244
+            $val = $methode($val);
245
+        } else {
246
+            spip_log("Erreur - '$fonc' non definie !");
247
+        }
248
+    }
249
+
250
+    return $val;
251 251
 }
252 252
 
253 253
 /**
@@ -278,46 +278,46 @@  discard block
 block discarded – undo
278 278
  *     Résultat
279 279
  */
280 280
 function pipeline($action, $val = null) {
281
-	static $charger;
282
-
283
-	// chargement initial des fonctions mises en cache, ou generation du cache
284
-	if (!$charger) {
285
-		if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
286
-			include_spip('inc/plugin');
287
-			// generer les fichiers php precompiles
288
-			// de chargement des plugins et des pipelines
289
-			actualise_plugins_actifs();
290
-			if (!($ok = @is_readable($charger))) {
291
-				spip_log("fichier $charger pas cree");
292
-			}
293
-		}
294
-
295
-		if ($ok) {
296
-			include_once $charger;
297
-		}
298
-	}
299
-
300
-	// appliquer notre fonction si elle existe
301
-	$fonc = 'execute_pipeline_' . strtolower($action);
302
-	if (function_exists($fonc)) {
303
-		$val = $fonc($val);
304
-	} // plantage ?
305
-	else {
306
-		spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
307
-	}
308
-
309
-	// si le flux est une table avec 2 cle args&data
310
-	// on ne ressort du pipe que les donnees dans 'data'
311
-	// array_key_exists pour php 4.1.0
312
-	if (
313
-		is_array($val)
314
-		and count($val) == 2
315
-		and (array_key_exists('data', $val))
316
-	) {
317
-		$val = $val['data'];
318
-	}
319
-
320
-	return $val;
281
+    static $charger;
282
+
283
+    // chargement initial des fonctions mises en cache, ou generation du cache
284
+    if (!$charger) {
285
+        if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
286
+            include_spip('inc/plugin');
287
+            // generer les fichiers php precompiles
288
+            // de chargement des plugins et des pipelines
289
+            actualise_plugins_actifs();
290
+            if (!($ok = @is_readable($charger))) {
291
+                spip_log("fichier $charger pas cree");
292
+            }
293
+        }
294
+
295
+        if ($ok) {
296
+            include_once $charger;
297
+        }
298
+    }
299
+
300
+    // appliquer notre fonction si elle existe
301
+    $fonc = 'execute_pipeline_' . strtolower($action);
302
+    if (function_exists($fonc)) {
303
+        $val = $fonc($val);
304
+    } // plantage ?
305
+    else {
306
+        spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
307
+    }
308
+
309
+    // si le flux est une table avec 2 cle args&data
310
+    // on ne ressort du pipe que les donnees dans 'data'
311
+    // array_key_exists pour php 4.1.0
312
+    if (
313
+        is_array($val)
314
+        and count($val) == 2
315
+        and (array_key_exists('data', $val))
316
+    ) {
317
+        $val = $val['data'];
318
+    }
319
+
320
+    return $val;
321 321
 }
322 322
 
323 323
 /**
@@ -361,38 +361,38 @@  discard block
 block discarded – undo
361 361
  *     paramètre est planté pour cause de compatibilité ascendante.
362 362
  */
363 363
 function spip_log($message = null, $name = null) {
364
-	static $pre = [];
365
-	static $log;
366
-	preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
367
-	if (!isset($regs[1]) or !$logname = $regs[1]) {
368
-		$logname = null;
369
-	}
370
-	if (!isset($regs[2])) {
371
-		$niveau = _LOG_INFO;
372
-	}
373
-	else {
374
-		$niveau = intval($regs[2]);
375
-	}
376
-
377
-	if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
378
-		if (!$pre) {
379
-			$pre = [
380
-				_LOG_HS => 'HS:',
381
-				_LOG_ALERTE_ROUGE => 'ALERTE:',
382
-				_LOG_CRITIQUE => 'CRITIQUE:',
383
-				_LOG_ERREUR => 'ERREUR:',
384
-				_LOG_AVERTISSEMENT => 'WARNING:',
385
-				_LOG_INFO_IMPORTANTE => '!INFO:',
386
-				_LOG_INFO => 'info:',
387
-				_LOG_DEBUG => 'debug:'
388
-			];
389
-			$log = charger_fonction('log', 'inc');
390
-		}
391
-		if (!is_string($message)) {
392
-			$message = print_r($message, true);
393
-		}
394
-		$log($pre[$niveau] . ' ' . $message, $logname);
395
-	}
364
+    static $pre = [];
365
+    static $log;
366
+    preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
367
+    if (!isset($regs[1]) or !$logname = $regs[1]) {
368
+        $logname = null;
369
+    }
370
+    if (!isset($regs[2])) {
371
+        $niveau = _LOG_INFO;
372
+    }
373
+    else {
374
+        $niveau = intval($regs[2]);
375
+    }
376
+
377
+    if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
378
+        if (!$pre) {
379
+            $pre = [
380
+                _LOG_HS => 'HS:',
381
+                _LOG_ALERTE_ROUGE => 'ALERTE:',
382
+                _LOG_CRITIQUE => 'CRITIQUE:',
383
+                _LOG_ERREUR => 'ERREUR:',
384
+                _LOG_AVERTISSEMENT => 'WARNING:',
385
+                _LOG_INFO_IMPORTANTE => '!INFO:',
386
+                _LOG_INFO => 'info:',
387
+                _LOG_DEBUG => 'debug:'
388
+            ];
389
+            $log = charger_fonction('log', 'inc');
390
+        }
391
+        if (!is_string($message)) {
392
+            $message = print_r($message, true);
393
+        }
394
+        $log($pre[$niveau] . ' ' . $message, $logname);
395
+    }
396 396
 }
397 397
 
398 398
 /**
@@ -403,8 +403,8 @@  discard block
 block discarded – undo
403 403
  * @param array $opt Tableau d'options
404 404
  **/
405 405
 function journal($phrase, $opt = []) {
406
-	$journal = charger_fonction('journal', 'inc');
407
-	$journal($phrase, $opt);
406
+    $journal = charger_fonction('journal', 'inc');
407
+    $journal($phrase, $opt);
408 408
 }
409 409
 
410 410
 
@@ -423,37 +423,37 @@  discard block
 block discarded – undo
423 423
  **/
424 424
 function _request($var, $c = false) {
425 425
 
426
-	if (is_array($c)) {
427
-		return $c[$var] ?? null;
428
-	}
429
-
430
-	if (isset($_GET[$var])) {
431
-		$a = $_GET[$var];
432
-	} elseif (isset($_POST[$var])) {
433
-		$a = $_POST[$var];
434
-	} else {
435
-		return null;
436
-	}
437
-
438
-	// Si on est en ajax et en POST tout a ete encode
439
-	// via encodeURIComponent, il faut donc repasser
440
-	// dans le charset local...
441
-	if (
442
-		defined('_AJAX')
443
-		and _AJAX
444
-		and isset($GLOBALS['meta']['charset'])
445
-		and $GLOBALS['meta']['charset'] != 'utf-8'
446
-		and is_string($a)
447
-		// check rapide mais pas fiable
448
-		and preg_match(',[\x80-\xFF],', $a)
449
-		// check fiable
450
-		and include_spip('inc/charsets')
451
-		and is_utf8($a)
452
-	) {
453
-		return importer_charset($a, 'utf-8');
454
-	}
455
-
456
-	return $a;
426
+    if (is_array($c)) {
427
+        return $c[$var] ?? null;
428
+    }
429
+
430
+    if (isset($_GET[$var])) {
431
+        $a = $_GET[$var];
432
+    } elseif (isset($_POST[$var])) {
433
+        $a = $_POST[$var];
434
+    } else {
435
+        return null;
436
+    }
437
+
438
+    // Si on est en ajax et en POST tout a ete encode
439
+    // via encodeURIComponent, il faut donc repasser
440
+    // dans le charset local...
441
+    if (
442
+        defined('_AJAX')
443
+        and _AJAX
444
+        and isset($GLOBALS['meta']['charset'])
445
+        and $GLOBALS['meta']['charset'] != 'utf-8'
446
+        and is_string($a)
447
+        // check rapide mais pas fiable
448
+        and preg_match(',[\x80-\xFF],', $a)
449
+        // check fiable
450
+        and include_spip('inc/charsets')
451
+        and is_utf8($a)
452
+    ) {
453
+        return importer_charset($a, 'utf-8');
454
+    }
455
+
456
+    return $a;
457 457
 }
458 458
 
459 459
 
@@ -471,22 +471,22 @@  discard block
 block discarded – undo
471 471
  *     - false sinon
472 472
  **/
473 473
 function set_request($var, $val = null, $c = false) {
474
-	if (is_array($c)) {
475
-		unset($c[$var]);
476
-		if ($val !== null) {
477
-			$c[$var] = $val;
478
-		}
474
+    if (is_array($c)) {
475
+        unset($c[$var]);
476
+        if ($val !== null) {
477
+            $c[$var] = $val;
478
+        }
479 479
 
480
-		return $c;
481
-	}
480
+        return $c;
481
+    }
482 482
 
483
-	unset($_GET[$var]);
484
-	unset($_POST[$var]);
485
-	if ($val !== null) {
486
-		$_GET[$var] = $val;
487
-	}
483
+    unset($_GET[$var]);
484
+    unset($_POST[$var]);
485
+    if ($val !== null) {
486
+        $_GET[$var] = $val;
487
+    }
488 488
 
489
-	return false; # n'affecte pas $c
489
+    return false; # n'affecte pas $c
490 490
 }
491 491
 
492 492
 /**
@@ -506,25 +506,25 @@  discard block
 block discarded – undo
506 506
  * @return array|mixed|string
507 507
  */
508 508
 function spip_sanitize_from_request($value, $key, $sanitize_function = 'entites_html') {
509
-	if (is_array($value)) {
510
-		if ($key == '*') {
511
-			$key = array_keys($value);
512
-		}
513
-		if (!is_array($key)) {
514
-			$key = [$key];
515
-		}
516
-		foreach ($key as $k) {
517
-			if (!empty($value[$k])) {
518
-				$value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
519
-			}
520
-		}
521
-		return $value;
522
-	}
523
-	// si la valeur vient des GET ou POST on la sanitize
524
-	if (!empty($value) and $value == _request($key)) {
525
-		$value = $sanitize_function($value);
526
-	}
527
-	return $value;
509
+    if (is_array($value)) {
510
+        if ($key == '*') {
511
+            $key = array_keys($value);
512
+        }
513
+        if (!is_array($key)) {
514
+            $key = [$key];
515
+        }
516
+        foreach ($key as $k) {
517
+            if (!empty($value[$k])) {
518
+                $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
519
+            }
520
+        }
521
+        return $value;
522
+    }
523
+    // si la valeur vient des GET ou POST on la sanitize
524
+    if (!empty($value) and $value == _request($key)) {
525
+        $value = $sanitize_function($value);
526
+    }
527
+    return $value;
528 528
 }
529 529
 
530 530
 /**
@@ -532,23 +532,22 @@  discard block
 block discarded – undo
532 532
  *
533 533
  * On est sur le web, on exclut certains protocoles,
534 534
  * notamment 'file://', 'php://' et d'autres…
535
-
536 535
  * @param string $url
537 536
  * @return bool
538 537
  */
539 538
 function tester_url_absolue($url) {
540
-	$url = trim($url ?? '');
541
-	if ($url && preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) {
542
-		if (
543
-			isset($m[1])
544
-			and $p = strtolower(rtrim($m[1], ':'))
545
-			and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'])
546
-		) {
547
-			return false;
548
-		}
549
-		return true;
550
-	}
551
-	return false;
539
+    $url = trim($url ?? '');
540
+    if ($url && preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) {
541
+        if (
542
+            isset($m[1])
543
+            and $p = strtolower(rtrim($m[1], ':'))
544
+            and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'])
545
+        ) {
546
+            return false;
547
+        }
548
+        return true;
549
+    }
550
+    return false;
552 551
 }
553 552
 
554 553
 /**
@@ -570,100 +569,100 @@  discard block
 block discarded – undo
570 569
  * @return string URL
571 570
  */
572 571
 function parametre_url($url, $c, $v = null, $sep = '&amp;') {
573
-	// requete erronnee : plusieurs variable dans $c et aucun $v
574
-	if (strpos($c, '|') !== false and is_null($v)) {
575
-		return null;
576
-	}
577
-
578
-	// lever l'#ancre
579
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
580
-		$url = $r[1];
581
-		$ancre = $r[2];
582
-	} else {
583
-		$ancre = '';
584
-	}
585
-
586
-	// eclater
587
-	$url = preg_split(',[?]|&amp;|&,', $url);
588
-
589
-	// recuperer la base
590
-	$a = array_shift($url);
591
-	if (!$a) {
592
-		$a = './';
593
-	}
594
-
595
-	// preparer la regexp de maniere securisee
596
-	$regexp = explode('|', $c);
597
-	foreach ($regexp as $r => $e) {
598
-		$regexp[$r] = str_replace('[]', '\[\]', preg_replace(',[^\w\d\[\]-],', '', $e));
599
-	}
600
-	$regexp = ',^(' . implode('|', $regexp) . '[[]?[]]?)(=.*)?$,';
601
-	$ajouts = array_flip(explode('|', $c));
602
-	$u = is_array($v) ? $v : rawurlencode((string) $v);
603
-	$testv = (is_array($v) ? count($v) : strlen((string) $v));
604
-	$v_read = null;
605
-	// lire les variables et agir
606
-	foreach ($url as $n => $val) {
607
-		if (preg_match($regexp, urldecode($val), $r)) {
608
-			$r = array_pad($r, 3, null);
609
-			if ($v === null) {
610
-				// c'est un tableau, on memorise les valeurs
611
-				if (substr($r[1], -2) == '[]') {
612
-					if (!$v_read) {
613
-						$v_read = [];
614
-					}
615
-					$v_read[] = $r[2] ? substr($r[2], 1) : '';
616
-				} // c'est un scalaire, on retourne direct
617
-				else {
618
-					return $r[2] ? substr($r[2], 1) : '';
619
-				}
620
-			} // suppression
621
-			elseif (!$testv) {
622
-				unset($url[$n]);
623
-			}
624
-			// Ajout. Pour une variable, remplacer au meme endroit,
625
-			// pour un tableau ce sera fait dans la prochaine boucle
626
-			elseif (substr($r[1], -2) != '[]') {
627
-				$url[$n] = $r[1] . '=' . $u;
628
-				unset($ajouts[$r[1]]);
629
-			}
630
-			// Pour les tableaux on laisse tomber les valeurs de
631
-			// départ, on remplira à l'étape suivante
632
-			else {
633
-				unset($url[$n]);
634
-			}
635
-		}
636
-	}
637
-
638
-	// traiter les parametres pas encore trouves
639
-	if (
640
-		$v === null
641
-		and $args = func_get_args()
642
-		and count($args) == 2
643
-	) {
644
-		return $v_read; // rien trouve ou un tableau
645
-	} elseif ($testv) {
646
-		foreach ($ajouts as $k => $n) {
647
-			if (!is_array($v)) {
648
-				$url[] = $k . '=' . $u;
649
-			} else {
650
-				$id = (substr($k, -2) == '[]') ? $k : ($k . '[]');
651
-				foreach ($v as $w) {
652
-					$url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w));
653
-				}
654
-			}
655
-		}
656
-	}
657
-
658
-	// eliminer les vides
659
-	$url = array_filter($url);
660
-
661
-	// recomposer l'adresse
662
-	if ($url) {
663
-		$a .= '?' . join($sep, $url);
664
-	}
665
-
666
-	return $a . $ancre;
572
+    // requete erronnee : plusieurs variable dans $c et aucun $v
573
+    if (strpos($c, '|') !== false and is_null($v)) {
574
+        return null;
575
+    }
576
+
577
+    // lever l'#ancre
578
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
579
+        $url = $r[1];
580
+        $ancre = $r[2];
581
+    } else {
582
+        $ancre = '';
583
+    }
584
+
585
+    // eclater
586
+    $url = preg_split(',[?]|&amp;|&,', $url);
587
+
588
+    // recuperer la base
589
+    $a = array_shift($url);
590
+    if (!$a) {
591
+        $a = './';
592
+    }
593
+
594
+    // preparer la regexp de maniere securisee
595
+    $regexp = explode('|', $c);
596
+    foreach ($regexp as $r => $e) {
597
+        $regexp[$r] = str_replace('[]', '\[\]', preg_replace(',[^\w\d\[\]-],', '', $e));
598
+    }
599
+    $regexp = ',^(' . implode('|', $regexp) . '[[]?[]]?)(=.*)?$,';
600
+    $ajouts = array_flip(explode('|', $c));
601
+    $u = is_array($v) ? $v : rawurlencode((string) $v);
602
+    $testv = (is_array($v) ? count($v) : strlen((string) $v));
603
+    $v_read = null;
604
+    // lire les variables et agir
605
+    foreach ($url as $n => $val) {
606
+        if (preg_match($regexp, urldecode($val), $r)) {
607
+            $r = array_pad($r, 3, null);
608
+            if ($v === null) {
609
+                // c'est un tableau, on memorise les valeurs
610
+                if (substr($r[1], -2) == '[]') {
611
+                    if (!$v_read) {
612
+                        $v_read = [];
613
+                    }
614
+                    $v_read[] = $r[2] ? substr($r[2], 1) : '';
615
+                } // c'est un scalaire, on retourne direct
616
+                else {
617
+                    return $r[2] ? substr($r[2], 1) : '';
618
+                }
619
+            } // suppression
620
+            elseif (!$testv) {
621
+                unset($url[$n]);
622
+            }
623
+            // Ajout. Pour une variable, remplacer au meme endroit,
624
+            // pour un tableau ce sera fait dans la prochaine boucle
625
+            elseif (substr($r[1], -2) != '[]') {
626
+                $url[$n] = $r[1] . '=' . $u;
627
+                unset($ajouts[$r[1]]);
628
+            }
629
+            // Pour les tableaux on laisse tomber les valeurs de
630
+            // départ, on remplira à l'étape suivante
631
+            else {
632
+                unset($url[$n]);
633
+            }
634
+        }
635
+    }
636
+
637
+    // traiter les parametres pas encore trouves
638
+    if (
639
+        $v === null
640
+        and $args = func_get_args()
641
+        and count($args) == 2
642
+    ) {
643
+        return $v_read; // rien trouve ou un tableau
644
+    } elseif ($testv) {
645
+        foreach ($ajouts as $k => $n) {
646
+            if (!is_array($v)) {
647
+                $url[] = $k . '=' . $u;
648
+            } else {
649
+                $id = (substr($k, -2) == '[]') ? $k : ($k . '[]');
650
+                foreach ($v as $w) {
651
+                    $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w));
652
+                }
653
+            }
654
+        }
655
+    }
656
+
657
+    // eliminer les vides
658
+    $url = array_filter($url);
659
+
660
+    // recomposer l'adresse
661
+    if ($url) {
662
+        $a .= '?' . join($sep, $url);
663
+    }
664
+
665
+    return $a . $ancre;
667 666
 }
668 667
 
669 668
 /**
@@ -678,22 +677,22 @@  discard block
 block discarded – undo
678 677
  * @uses translitteration()
679 678
  */
680 679
 function ancre_url(string $url, ?string $ancre = ''): string {
681
-	$ancre ??= '';
682
-	// lever l'#ancre
683
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
684
-		$url = $r[1];
685
-	}
686
-	if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
687
-		if (!function_exists('translitteration')) {
688
-			include_spip('inc/charsets');
689
-		}
690
-		$ancre = preg_replace(
691
-			['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'],
692
-			['', '-'],
693
-			translitteration($ancre)
694
-		);
695
-	}
696
-	return $url . (strlen($ancre) ? '#' . $ancre : '');
680
+    $ancre ??= '';
681
+    // lever l'#ancre
682
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
683
+        $url = $r[1];
684
+    }
685
+    if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
686
+        if (!function_exists('translitteration')) {
687
+            include_spip('inc/charsets');
688
+        }
689
+        $ancre = preg_replace(
690
+            ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'],
691
+            ['', '-'],
692
+            translitteration($ancre)
693
+        );
694
+    }
695
+    return $url . (strlen($ancre) ? '#' . $ancre : '');
697 696
 }
698 697
 
699 698
 /**
@@ -703,16 +702,16 @@  discard block
 block discarded – undo
703 702
  * @return string
704 703
  */
705 704
 function nettoyer_uri($reset = null) {
706
-	static $done = false;
707
-	static $propre = '';
708
-	if (!is_null($reset)) {
709
-		return $propre = $reset;
710
-	}
711
-	if ($done) {
712
-		return $propre;
713
-	}
714
-	$done = true;
715
-	return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
705
+    static $done = false;
706
+    static $propre = '';
707
+    if (!is_null($reset)) {
708
+        return $propre = $reset;
709
+    }
710
+    if ($done) {
711
+        return $propre;
712
+    }
713
+    $done = true;
714
+    return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
716 715
 }
717 716
 
718 717
 /**
@@ -724,16 +723,16 @@  discard block
 block discarded – undo
724 723
  * @return string
725 724
  */
726 725
 function nettoyer_uri_var($request_uri) {
727
-	$uri1 = $request_uri;
728
-	do {
729
-		$uri = $uri1;
730
-		$uri1 = preg_replace(
731
-			',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
732
-			'\1',
733
-			$uri
734
-		);
735
-	} while ($uri <> $uri1);
736
-	return preg_replace(',[?&]$,', '', $uri1);
726
+    $uri1 = $request_uri;
727
+    do {
728
+        $uri = $uri1;
729
+        $uri1 = preg_replace(
730
+            ',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
731
+            '\1',
732
+            $uri
733
+        );
734
+    } while ($uri <> $uri1);
735
+    return preg_replace(',[?&]$,', '', $uri1);
737 736
 }
738 737
 
739 738
 
@@ -747,48 +746,48 @@  discard block
 block discarded – undo
747 746
  *    URL vers soi-même
748 747
  **/
749 748
 function self($amp = '&amp;', $root = false) {
750
-	$url = nettoyer_uri();
751
-	if (
752
-		!$root
753
-		and (
754
-			// si pas de profondeur on peut tronquer
755
-			$GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
756
-			// sinon c'est OK si _SET_HTML_BASE a ete force a false
757
-			or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
758
-	) {
759
-		$url = preg_replace(',^[^?]*/,', '', $url);
760
-	}
761
-	// ajouter le cas echeant les variables _POST['id_...']
762
-	foreach ($_POST as $v => $c) {
763
-		if (substr($v, 0, 3) == 'id_') {
764
-			$url = parametre_url($url, $v, $c, '&');
765
-		}
766
-	}
767
-
768
-	// supprimer les variables sans interet
769
-	if (test_espace_prive()) {
770
-		$url = preg_replace(',([?&])('
771
-			. 'lang|show_docs|'
772
-			. 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
773
-		$url = preg_replace(',([?&])[&]+,', '\1', $url);
774
-		$url = preg_replace(',[&]$,', '\1', $url);
775
-	}
776
-
777
-	// eviter les hacks
778
-	include_spip('inc/filtres_mini');
779
-	$url = spip_htmlspecialchars($url);
780
-
781
-	$url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
782
-
783
-	// &amp; ?
784
-	if ($amp != '&amp;') {
785
-		$url = str_replace('&amp;', $amp, $url);
786
-	}
787
-
788
-	// Si ca demarre par ? ou vide, donner './'
789
-	$url = preg_replace(',^([?].*)?$,', './\1', $url);
790
-
791
-	return $url;
749
+    $url = nettoyer_uri();
750
+    if (
751
+        !$root
752
+        and (
753
+            // si pas de profondeur on peut tronquer
754
+            $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
755
+            // sinon c'est OK si _SET_HTML_BASE a ete force a false
756
+            or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
757
+    ) {
758
+        $url = preg_replace(',^[^?]*/,', '', $url);
759
+    }
760
+    // ajouter le cas echeant les variables _POST['id_...']
761
+    foreach ($_POST as $v => $c) {
762
+        if (substr($v, 0, 3) == 'id_') {
763
+            $url = parametre_url($url, $v, $c, '&');
764
+        }
765
+    }
766
+
767
+    // supprimer les variables sans interet
768
+    if (test_espace_prive()) {
769
+        $url = preg_replace(',([?&])('
770
+            . 'lang|show_docs|'
771
+            . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
772
+        $url = preg_replace(',([?&])[&]+,', '\1', $url);
773
+        $url = preg_replace(',[&]$,', '\1', $url);
774
+    }
775
+
776
+    // eviter les hacks
777
+    include_spip('inc/filtres_mini');
778
+    $url = spip_htmlspecialchars($url);
779
+
780
+    $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
781
+
782
+    // &amp; ?
783
+    if ($amp != '&amp;') {
784
+        $url = str_replace('&amp;', $amp, $url);
785
+    }
786
+
787
+    // Si ca demarre par ? ou vide, donner './'
788
+    $url = preg_replace(',^([?].*)?$,', './\1', $url);
789
+
790
+    return $url;
792 791
 }
793 792
 
794 793
 
@@ -799,7 +798,7 @@  discard block
 block discarded – undo
799 798
  *     true si c'est le cas, false sinon.
800 799
  */
801 800
 function test_espace_prive() {
802
-	return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
801
+    return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
803 802
 }
804 803
 
805 804
 /**
@@ -809,7 +808,7 @@  discard block
 block discarded – undo
809 808
  * @return bool
810 809
  */
811 810
 function test_plugin_actif($plugin) {
812
-	return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
811
+    return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
813 812
 }
814 813
 
815 814
 /**
@@ -840,52 +839,52 @@  discard block
 block discarded – undo
840 839
  *     texte
841 840
  */
842 841
 function _T($texte, $args = [], $options = []) {
843
-	static $traduire = false;
844
-	$o = ['class' => '', 'force' => true, 'sanitize' => true];
845
-	if ($options) {
846
-		// support de l'ancien argument $class
847
-		if (is_string($options)) {
848
-			$options = ['class' => $options];
849
-		}
850
-		$o = array_merge($o, $options);
851
-	}
852
-
853
-	if (!$traduire) {
854
-		$traduire = charger_fonction('traduire', 'inc');
855
-		include_spip('inc/lang');
856
-	}
857
-
858
-	// On peut passer explicitement la langue dans le tableau
859
-	// On utilise le même nom de variable que la globale
860
-	if (isset($args['spip_lang'])) {
861
-		$lang = $args['spip_lang'];
862
-		// On l'enleve pour ne pas le passer au remplacement
863
-		unset($args['spip_lang']);
864
-	} // Sinon on prend la langue du contexte
865
-	else {
866
-		$lang = $GLOBALS['spip_lang'];
867
-	}
868
-	$text = $traduire($texte, $lang);
869
-
870
-	if ($text === null || !strlen($text)) {
871
-		if (!$o['force']) {
872
-			return '';
873
-		}
874
-
875
-		$text = $texte;
876
-
877
-		// pour les chaines non traduites, assurer un service minimum
878
-		if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
879
-			$n = strpos($text, ':');
880
-			if ($n !== false) {
881
-				$text = substr($text, $n + 1);
882
-			}
883
-			$text = str_replace('_', ' ', $text);
884
-		}
885
-		$o['class'] = null;
886
-	}
887
-
888
-	return _L($text, $args, $o);
842
+    static $traduire = false;
843
+    $o = ['class' => '', 'force' => true, 'sanitize' => true];
844
+    if ($options) {
845
+        // support de l'ancien argument $class
846
+        if (is_string($options)) {
847
+            $options = ['class' => $options];
848
+        }
849
+        $o = array_merge($o, $options);
850
+    }
851
+
852
+    if (!$traduire) {
853
+        $traduire = charger_fonction('traduire', 'inc');
854
+        include_spip('inc/lang');
855
+    }
856
+
857
+    // On peut passer explicitement la langue dans le tableau
858
+    // On utilise le même nom de variable que la globale
859
+    if (isset($args['spip_lang'])) {
860
+        $lang = $args['spip_lang'];
861
+        // On l'enleve pour ne pas le passer au remplacement
862
+        unset($args['spip_lang']);
863
+    } // Sinon on prend la langue du contexte
864
+    else {
865
+        $lang = $GLOBALS['spip_lang'];
866
+    }
867
+    $text = $traduire($texte, $lang);
868
+
869
+    if ($text === null || !strlen($text)) {
870
+        if (!$o['force']) {
871
+            return '';
872
+        }
873
+
874
+        $text = $texte;
875
+
876
+        // pour les chaines non traduites, assurer un service minimum
877
+        if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
878
+            $n = strpos($text, ':');
879
+            if ($n !== false) {
880
+                $text = substr($text, $n + 1);
881
+            }
882
+            $text = str_replace('_', ' ', $text);
883
+        }
884
+        $o['class'] = null;
885
+    }
886
+
887
+    return _L($text, $args, $o);
889 888
 }
890 889
 
891 890
 
@@ -912,53 +911,53 @@  discard block
 block discarded – undo
912 911
  *     texte
913 912
  */
914 913
 function _L($text, $args = [], $options = []) {
915
-	$f = $text;
916
-	$defaut_options = [
917
-		'class' => null,
918
-		'sanitize' => true,
919
-	];
920
-	// support de l'ancien argument $class
921
-	if ($options and is_string($options)) {
922
-		$options = ['class' => $options];
923
-	}
924
-	if (is_array($options)) {
925
-		$options += $defaut_options;
926
-	} else {
927
-		$options = $defaut_options;
928
-	}
929
-
930
-	if (is_array($args) and count($args)) {
931
-		if (!function_exists('interdire_scripts')) {
932
-			include_spip('inc/texte');
933
-		}
934
-		if (!function_exists('echapper_html_suspect')) {
935
-			include_spip('inc/texte_mini');
936
-		}
937
-		foreach ($args as $name => $value) {
938
-			if (strpos($text, (string) "@$name@") !== false) {
939
-				if ($options['sanitize']) {
940
-					$value = echapper_html_suspect($value);
941
-					$value = interdire_scripts($value, -1);
942
-				}
943
-				if (!empty($options['class'])) {
944
-					$value = "<span class='" . $options['class'] . "'>$value</span>";
945
-				}
946
-				$text = str_replace("@$name@", $value, $text);
947
-				unset($args[$name]);
948
-			}
949
-		}
950
-		// Si des variables n'ont pas ete inserees, le signaler
951
-		// (chaines de langues pas a jour)
952
-		if ($args) {
953
-			spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
954
-		}
955
-	}
956
-
957
-	if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
958
-		return "<span class='debug-traduction-erreur'>$text</span>";
959
-	} else {
960
-		return $text;
961
-	}
914
+    $f = $text;
915
+    $defaut_options = [
916
+        'class' => null,
917
+        'sanitize' => true,
918
+    ];
919
+    // support de l'ancien argument $class
920
+    if ($options and is_string($options)) {
921
+        $options = ['class' => $options];
922
+    }
923
+    if (is_array($options)) {
924
+        $options += $defaut_options;
925
+    } else {
926
+        $options = $defaut_options;
927
+    }
928
+
929
+    if (is_array($args) and count($args)) {
930
+        if (!function_exists('interdire_scripts')) {
931
+            include_spip('inc/texte');
932
+        }
933
+        if (!function_exists('echapper_html_suspect')) {
934
+            include_spip('inc/texte_mini');
935
+        }
936
+        foreach ($args as $name => $value) {
937
+            if (strpos($text, (string) "@$name@") !== false) {
938
+                if ($options['sanitize']) {
939
+                    $value = echapper_html_suspect($value);
940
+                    $value = interdire_scripts($value, -1);
941
+                }
942
+                if (!empty($options['class'])) {
943
+                    $value = "<span class='" . $options['class'] . "'>$value</span>";
944
+                }
945
+                $text = str_replace("@$name@", $value, $text);
946
+                unset($args[$name]);
947
+            }
948
+        }
949
+        // Si des variables n'ont pas ete inserees, le signaler
950
+        // (chaines de langues pas a jour)
951
+        if ($args) {
952
+            spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
953
+        }
954
+    }
955
+
956
+    if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
957
+        return "<span class='debug-traduction-erreur'>$text</span>";
958
+    } else {
959
+        return $text;
960
+    }
962 961
 }
963 962
 
964 963
 
@@ -972,13 +971,13 @@  discard block
 block discarded – undo
972 971
  * @return string
973 972
  */
974 973
 function joli_repertoire($rep) {
975
-	$a = substr($rep, 0, 1);
976
-	if ($a <> '.' and $a <> '/') {
977
-		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
978
-	}
979
-	$rep = preg_replace(',(^\.\.\/),', '', $rep);
974
+    $a = substr($rep, 0, 1);
975
+    if ($a <> '.' and $a <> '/') {
976
+        $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
977
+    }
978
+    $rep = preg_replace(',(^\.\.\/),', '', $rep);
980 979
 
981
-	return $rep;
980
+    return $rep;
982 981
 }
983 982
 
984 983
 
@@ -1003,54 +1002,54 @@  discard block
 block discarded – undo
1003 1002
  * @return float|int|string|void
1004 1003
  */
1005 1004
 function spip_timer($t = 'rien', $raw = false) {
1006
-	static $time;
1007
-	$a = time();
1008
-	$b = microtime();
1009
-	// microtime peut contenir les microsecondes et le temps
1010
-	$b = explode(' ', $b);
1011
-	if (count($b) == 2) {
1012
-		$a = end($b);
1013
-	} // plus precis !
1014
-	$b = reset($b);
1015
-	if (!isset($time[$t])) {
1016
-		$time[$t] = $a + $b;
1017
-	} else {
1018
-		$p = ($a + $b - $time[$t]) * 1000;
1019
-		unset($time[$t]);
1005
+    static $time;
1006
+    $a = time();
1007
+    $b = microtime();
1008
+    // microtime peut contenir les microsecondes et le temps
1009
+    $b = explode(' ', $b);
1010
+    if (count($b) == 2) {
1011
+        $a = end($b);
1012
+    } // plus precis !
1013
+    $b = reset($b);
1014
+    if (!isset($time[$t])) {
1015
+        $time[$t] = $a + $b;
1016
+    } else {
1017
+        $p = ($a + $b - $time[$t]) * 1000;
1018
+        unset($time[$t]);
1020 1019
 #			echo "'$p'";exit;
1021
-		if ($raw) {
1022
-			return $p;
1023
-		}
1024
-		if ($p < 1000) {
1025
-			$s = '';
1026
-		} else {
1027
-			$s = sprintf('%d ', $x = floor($p / 1000));
1028
-			$p -= ($x * 1000);
1029
-		}
1020
+        if ($raw) {
1021
+            return $p;
1022
+        }
1023
+        if ($p < 1000) {
1024
+            $s = '';
1025
+        } else {
1026
+            $s = sprintf('%d ', $x = floor($p / 1000));
1027
+            $p -= ($x * 1000);
1028
+        }
1030 1029
 
1031
-		return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1032
-	}
1030
+        return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1031
+    }
1033 1032
 }
1034 1033
 
1035 1034
 
1036 1035
 // Renvoie False si un fichier n'est pas plus vieux que $duree secondes,
1037 1036
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
1038 1037
 function spip_touch($fichier, $duree = 0, $touch = true) {
1039
-	if ($duree) {
1040
-		clearstatcache();
1041
-		if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
1042
-			return false;
1043
-		}
1044
-	}
1045
-	if ($touch !== false) {
1046
-		if (!@touch($fichier)) {
1047
-			spip_unlink($fichier);
1048
-			@touch($fichier);
1049
-		};
1050
-		@chmod($fichier, _SPIP_CHMOD & ~0111);
1051
-	}
1038
+    if ($duree) {
1039
+        clearstatcache();
1040
+        if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
1041
+            return false;
1042
+        }
1043
+    }
1044
+    if ($touch !== false) {
1045
+        if (!@touch($fichier)) {
1046
+            spip_unlink($fichier);
1047
+            @touch($fichier);
1048
+        };
1049
+        @chmod($fichier, _SPIP_CHMOD & ~0111);
1050
+    }
1052 1051
 
1053
-	return true;
1052
+    return true;
1054 1053
 }
1055 1054
 
1056 1055
 
@@ -1061,11 +1060,11 @@  discard block
 block discarded – undo
1061 1060
  * @uses cron()
1062 1061
  **/
1063 1062
 function action_cron() {
1064
-	include_spip('inc/headers');
1065
-	http_response_code(204); // No Content
1066
-	header('Connection: close');
1067
-	define('_DIRECT_CRON_FORCE', true);
1068
-	cron();
1063
+    include_spip('inc/headers');
1064
+    http_response_code(204); // No Content
1065
+    header('Connection: close');
1066
+    define('_DIRECT_CRON_FORCE', true);
1067
+    cron();
1069 1068
 }
1070 1069
 
1071 1070
 /**
@@ -1081,26 +1080,26 @@  discard block
 block discarded – undo
1081 1080
  *     True si la tache a pu être effectuée
1082 1081
  */
1083 1082
 function cron($taches = [], $taches_old = []) {
1084
-	// si pas en mode cron force, laisser tomber.
1085
-	if (!defined('_DIRECT_CRON_FORCE')) {
1086
-		return false;
1087
-	}
1088
-	if (!is_array($taches)) {
1089
-		$taches = $taches_old;
1090
-	} // compat anciens appels
1091
-	// si taches a inserer en base et base inaccessible, laisser tomber
1092
-	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1093
-	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1094
-	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1095
-	if ($taches and count($taches) and !spip_connect()) {
1096
-		return false;
1097
-	}
1098
-	spip_log('cron !', 'jq' . _LOG_DEBUG);
1099
-	if ($genie = charger_fonction('genie', 'inc', true)) {
1100
-		return $genie($taches);
1101
-	}
1102
-
1103
-	return false;
1083
+    // si pas en mode cron force, laisser tomber.
1084
+    if (!defined('_DIRECT_CRON_FORCE')) {
1085
+        return false;
1086
+    }
1087
+    if (!is_array($taches)) {
1088
+        $taches = $taches_old;
1089
+    } // compat anciens appels
1090
+    // si taches a inserer en base et base inaccessible, laisser tomber
1091
+    // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1092
+    // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1093
+    // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1094
+    if ($taches and count($taches) and !spip_connect()) {
1095
+        return false;
1096
+    }
1097
+    spip_log('cron !', 'jq' . _LOG_DEBUG);
1098
+    if ($genie = charger_fonction('genie', 'inc', true)) {
1099
+        return $genie($taches);
1100
+    }
1101
+
1102
+    return false;
1104 1103
 }
1105 1104
 
1106 1105
 /**
@@ -1132,17 +1131,17 @@  discard block
 block discarded – undo
1132 1131
  *     Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté.
1133 1132
  */
1134 1133
 function job_queue_add(
1135
-	$function,
1136
-	$description,
1137
-	$arguments = [],
1138
-	$file = '',
1139
-	$no_duplicate = false,
1140
-	$time = 0,
1141
-	$priority = 0
1134
+    $function,
1135
+    $description,
1136
+    $arguments = [],
1137
+    $file = '',
1138
+    $no_duplicate = false,
1139
+    $time = 0,
1140
+    $priority = 0
1142 1141
 ) {
1143
-	include_spip('inc/queue');
1142
+    include_spip('inc/queue');
1144 1143
 
1145
-	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1144
+    return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1146 1145
 }
1147 1146
 
1148 1147
 /**
@@ -1153,9 +1152,9 @@  discard block
 block discarded – undo
1153 1152
  * @return bool
1154 1153
  */
1155 1154
 function job_queue_remove($id_job) {
1156
-	include_spip('inc/queue');
1155
+    include_spip('inc/queue');
1157 1156
 
1158
-	return queue_remove_job($id_job);
1157
+    return queue_remove_job($id_job);
1159 1158
 }
1160 1159
 
1161 1160
 /**
@@ -1168,9 +1167,9 @@  discard block
 block discarded – undo
1168 1167
  *     or an array of simple array to link multiples objet in one time
1169 1168
  */
1170 1169
 function job_queue_link($id_job, $objets) {
1171
-	include_spip('inc/queue');
1170
+    include_spip('inc/queue');
1172 1171
 
1173
-	return queue_link_job($id_job, $objets);
1172
+    return queue_link_job($id_job, $objets);
1174 1173
 }
1175 1174
 
1176 1175
 
@@ -1190,36 +1189,36 @@  discard block
 block discarded – undo
1190 1189
  *  - `null` si la queue n'est pas encore initialisée
1191 1190
  */
1192 1191
 function queue_sleep_time_to_next_job($force = null) {
1193
-	static $queue_next_job_time = -1;
1194
-	if ($force === true) {
1195
-		$queue_next_job_time = -1;
1196
-	} elseif ($force) {
1197
-		$queue_next_job_time = $force;
1198
-	}
1199
-
1200
-	if ($queue_next_job_time == -1) {
1201
-		if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1202
-			define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1203
-		}
1204
-		// utiliser un cache memoire si dispo
1205
-		if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1206
-			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1207
-		} else {
1208
-			$queue_next_job_time = null;
1209
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1210
-				$queue_next_job_time = intval($contenu);
1211
-			}
1212
-		}
1213
-	}
1214
-
1215
-	if (is_null($queue_next_job_time)) {
1216
-		return null;
1217
-	}
1218
-	if (!$_SERVER['REQUEST_TIME']) {
1219
-		$_SERVER['REQUEST_TIME'] = time();
1220
-	}
1221
-
1222
-	return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1192
+    static $queue_next_job_time = -1;
1193
+    if ($force === true) {
1194
+        $queue_next_job_time = -1;
1195
+    } elseif ($force) {
1196
+        $queue_next_job_time = $force;
1197
+    }
1198
+
1199
+    if ($queue_next_job_time == -1) {
1200
+        if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1201
+            define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1202
+        }
1203
+        // utiliser un cache memoire si dispo
1204
+        if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1205
+            $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1206
+        } else {
1207
+            $queue_next_job_time = null;
1208
+            if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1209
+                $queue_next_job_time = intval($contenu);
1210
+            }
1211
+        }
1212
+    }
1213
+
1214
+    if (is_null($queue_next_job_time)) {
1215
+        return null;
1216
+    }
1217
+    if (!$_SERVER['REQUEST_TIME']) {
1218
+        $_SERVER['REQUEST_TIME'] = time();
1219
+    }
1220
+
1221
+    return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1223 1222
 }
1224 1223
 
1225 1224
 
@@ -1231,11 +1230,11 @@  discard block
 block discarded – undo
1231 1230
  * @return string
1232 1231
  */
1233 1232
 function quote_amp($u) {
1234
-	return preg_replace(
1235
-		'/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
1236
-		'&amp;',
1237
-		$u
1238
-	);
1233
+    return preg_replace(
1234
+        '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
1235
+        '&amp;',
1236
+        $u
1237
+    );
1239 1238
 }
1240 1239
 
1241 1240
 
@@ -1258,27 +1257,27 @@  discard block
 block discarded – undo
1258 1257
  *     Balise HTML `<script>` et son contenu
1259 1258
  **/
1260 1259
 function http_script($script, $src = '', $noscript = '') {
1261
-	static $done = [];
1260
+    static $done = [];
1262 1261
 
1263
-	if ($src && !isset($done[$src])) {
1264
-		$done[$src] = true;
1265
-		$src = find_in_path($src, _JAVASCRIPT);
1266
-		$src = " src='$src'";
1267
-	} else {
1268
-		$src = '';
1269
-	}
1270
-	if ($script) {
1271
-		$script = ("/*<![CDATA[*/\n" .
1272
-			preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1273
-			'/*]]>*/');
1274
-	}
1275
-	if ($noscript) {
1276
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1277
-	}
1262
+    if ($src && !isset($done[$src])) {
1263
+        $done[$src] = true;
1264
+        $src = find_in_path($src, _JAVASCRIPT);
1265
+        $src = " src='$src'";
1266
+    } else {
1267
+        $src = '';
1268
+    }
1269
+    if ($script) {
1270
+        $script = ("/*<![CDATA[*/\n" .
1271
+            preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1272
+            '/*]]>*/');
1273
+    }
1274
+    if ($noscript) {
1275
+        $noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1276
+    }
1278 1277
 
1279
-	return ($src or $script or $noscript)
1280
-		? "<script type='text/javascript'$src>$script</script>$noscript"
1281
-		: '';
1278
+    return ($src or $script or $noscript)
1279
+        ? "<script type='text/javascript'$src>$script</script>$noscript"
1280
+        : '';
1282 1281
 }
1283 1282
 
1284 1283
 
@@ -1313,7 +1312,7 @@  discard block
 block discarded – undo
1313 1312
  *     texte échappé
1314 1313
  **/
1315 1314
 function texte_script(string $texte): string {
1316
-	return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1315
+    return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1317 1316
 }
1318 1317
 
1319 1318
 
@@ -1350,68 +1349,68 @@  discard block
 block discarded – undo
1350 1349
  *     Liste des chemins, par ordre de priorité.
1351 1350
  **/
1352 1351
 function _chemin($dir_path = null) {
1353
-	static $path_base = null;
1354
-	static $path_full = null;
1355
-	if ($path_base == null) {
1356
-		// Chemin standard depuis l'espace public
1357
-		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
1358
-			_DIR_RACINE . ':' .
1359
-			_DIR_RACINE . 'squelettes-dist/:' .
1360
-			_DIR_RACINE . 'prive/:' .
1361
-			_DIR_RESTREINT;
1362
-		// Ajouter squelettes/
1363
-		if (@is_dir(_DIR_RACINE . 'squelettes')) {
1364
-			$path = _DIR_RACINE . 'squelettes/:' . $path;
1365
-		}
1366
-		foreach (explode(':', $path) as $dir) {
1367
-			if (strlen($dir) and substr($dir, -1) != '/') {
1368
-				$dir .= '/';
1369
-			}
1370
-			$path_base[] = $dir;
1371
-		}
1372
-		$path_full = $path_base;
1373
-		// Et le(s) dossier(s) des squelettes nommes
1374
-		if (strlen($GLOBALS['dossier_squelettes'])) {
1375
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1376
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1377
-			}
1378
-		}
1379
-		$GLOBALS['path_sig'] = md5(serialize($path_full));
1380
-	}
1381
-	if ($dir_path === null) {
1382
-		return $path_full;
1383
-	}
1384
-
1385
-	if (is_array($dir_path) or strlen($dir_path)) {
1386
-		$tete = '';
1387
-		if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1388
-			$tete = array_shift($path_base);
1389
-		}
1390
-		$dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
1391
-		$dirs = array_reverse($dirs);
1392
-		foreach ($dirs as $dir_path) {
1393
-			if (substr($dir_path, -1) != '/') {
1394
-				$dir_path .= '/';
1395
-			}
1396
-			if (!in_array($dir_path, $path_base)) {
1397
-				array_unshift($path_base, $dir_path);
1398
-			}
1399
-		}
1400
-		if (strlen($tete)) {
1401
-			array_unshift($path_base, $tete);
1402
-		}
1403
-	}
1404
-	$path_full = $path_base;
1405
-	// Et le(s) dossier(s) des squelettes nommes
1406
-	if (strlen($GLOBALS['dossier_squelettes'])) {
1407
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1408
-			array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1409
-		}
1410
-	}
1411
-
1412
-	$GLOBALS['path_sig'] = md5(serialize($path_full));
1413
-
1414
-	return $path_full;
1352
+    static $path_base = null;
1353
+    static $path_full = null;
1354
+    if ($path_base == null) {
1355
+        // Chemin standard depuis l'espace public
1356
+        $path = defined('_SPIP_PATH') ? _SPIP_PATH :
1357
+            _DIR_RACINE . ':' .
1358
+            _DIR_RACINE . 'squelettes-dist/:' .
1359
+            _DIR_RACINE . 'prive/:' .
1360
+            _DIR_RESTREINT;
1361
+        // Ajouter squelettes/
1362
+        if (@is_dir(_DIR_RACINE . 'squelettes')) {
1363
+            $path = _DIR_RACINE . 'squelettes/:' . $path;
1364
+        }
1365
+        foreach (explode(':', $path) as $dir) {
1366
+            if (strlen($dir) and substr($dir, -1) != '/') {
1367
+                $dir .= '/';
1368
+            }
1369
+            $path_base[] = $dir;
1370
+        }
1371
+        $path_full = $path_base;
1372
+        // Et le(s) dossier(s) des squelettes nommes
1373
+        if (strlen($GLOBALS['dossier_squelettes'])) {
1374
+            foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1375
+                array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1376
+            }
1377
+        }
1378
+        $GLOBALS['path_sig'] = md5(serialize($path_full));
1379
+    }
1380
+    if ($dir_path === null) {
1381
+        return $path_full;
1382
+    }
1383
+
1384
+    if (is_array($dir_path) or strlen($dir_path)) {
1385
+        $tete = '';
1386
+        if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1387
+            $tete = array_shift($path_base);
1388
+        }
1389
+        $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
1390
+        $dirs = array_reverse($dirs);
1391
+        foreach ($dirs as $dir_path) {
1392
+            if (substr($dir_path, -1) != '/') {
1393
+                $dir_path .= '/';
1394
+            }
1395
+            if (!in_array($dir_path, $path_base)) {
1396
+                array_unshift($path_base, $dir_path);
1397
+            }
1398
+        }
1399
+        if (strlen($tete)) {
1400
+            array_unshift($path_base, $tete);
1401
+        }
1402
+    }
1403
+    $path_full = $path_base;
1404
+    // Et le(s) dossier(s) des squelettes nommes
1405
+    if (strlen($GLOBALS['dossier_squelettes'])) {
1406
+        foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1407
+            array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1408
+        }
1409
+    }
1410
+
1411
+    $GLOBALS['path_sig'] = md5(serialize($path_full));
1412
+
1413
+    return $path_full;
1415 1414
 }
1416 1415
 
1417 1416
 /**
@@ -1424,78 +1423,78 @@  discard block
 block discarded – undo
1424 1423
  * @return array Liste de chemins
1425 1424
  **/
1426 1425
 function creer_chemin() {
1427
-	$path_a = _chemin();
1428
-	static $c = '';
1426
+    $path_a = _chemin();
1427
+    static $c = '';
1429 1428
 
1430
-	// on calcule le chemin si le dossier skel a change
1431
-	if ($c != $GLOBALS['dossier_squelettes']) {
1432
-		// assurer le non plantage lors de la montee de version :
1433
-		$c = $GLOBALS['dossier_squelettes'];
1434
-		$path_a = _chemin(''); // forcer un recalcul du chemin
1435
-	}
1429
+    // on calcule le chemin si le dossier skel a change
1430
+    if ($c != $GLOBALS['dossier_squelettes']) {
1431
+        // assurer le non plantage lors de la montee de version :
1432
+        $c = $GLOBALS['dossier_squelettes'];
1433
+        $path_a = _chemin(''); // forcer un recalcul du chemin
1434
+    }
1436 1435
 
1437
-	return $path_a;
1436
+    return $path_a;
1438 1437
 }
1439 1438
 
1440 1439
 
1441 1440
 function lister_themes_prives() {
1442
-	static $themes = null;
1443
-	if (is_null($themes)) {
1444
-		// si pas encore definie
1445
-		if (!defined('_SPIP_THEME_PRIVE')) {
1446
-			define('_SPIP_THEME_PRIVE', 'spip');
1447
-		}
1448
-		$themes = [_SPIP_THEME_PRIVE];
1449
-		// lors d'une installation neuve, prefs n'est pas definie.
1450
-		if (isset($GLOBALS['visiteur_session']['prefs'])) {
1451
-			$prefs = $GLOBALS['visiteur_session']['prefs'];
1452
-		} else {
1453
-			$prefs = [];
1454
-		}
1455
-		if (is_string($prefs)) {
1456
-			$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1457
-		}
1458
-		if (
1459
-			((isset($prefs['theme']) and $theme = $prefs['theme'])
1460
-				or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1461
-			and $theme != _SPIP_THEME_PRIVE
1462
-		) {
1463
-			array_unshift($themes, $theme);
1464
-		} // placer le theme choisi en tete
1465
-	}
1466
-
1467
-	return $themes;
1441
+    static $themes = null;
1442
+    if (is_null($themes)) {
1443
+        // si pas encore definie
1444
+        if (!defined('_SPIP_THEME_PRIVE')) {
1445
+            define('_SPIP_THEME_PRIVE', 'spip');
1446
+        }
1447
+        $themes = [_SPIP_THEME_PRIVE];
1448
+        // lors d'une installation neuve, prefs n'est pas definie.
1449
+        if (isset($GLOBALS['visiteur_session']['prefs'])) {
1450
+            $prefs = $GLOBALS['visiteur_session']['prefs'];
1451
+        } else {
1452
+            $prefs = [];
1453
+        }
1454
+        if (is_string($prefs)) {
1455
+            $prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1456
+        }
1457
+        if (
1458
+            ((isset($prefs['theme']) and $theme = $prefs['theme'])
1459
+                or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1460
+            and $theme != _SPIP_THEME_PRIVE
1461
+        ) {
1462
+            array_unshift($themes, $theme);
1463
+        } // placer le theme choisi en tete
1464
+    }
1465
+
1466
+    return $themes;
1468 1467
 }
1469 1468
 
1470 1469
 function find_in_theme($file, $subdir = '', $include = false) {
1471
-	static $themefiles = [];
1472
-	if (isset($themefiles["$subdir$file"])) {
1473
-		return $themefiles["$subdir$file"];
1474
-	}
1475
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1476
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1477
-	if (
1478
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1479
-		and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1480
-		and $f = find_in_theme("$file_svg_generique")
1481
-	) {
1482
-		if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1483
-			return $themefiles["$subdir$file"] = $fsize;
1484
-		}
1485
-		else {
1486
-			return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1487
-		}
1488
-	}
1489
-
1490
-	$themes = lister_themes_prives();
1491
-	foreach ($themes as $theme) {
1492
-		if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1493
-			return $themefiles["$subdir$file"] = $f;
1494
-		}
1495
-	}
1496
-	spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1497
-
1498
-	return $themefiles["$subdir$file"] = '';
1470
+    static $themefiles = [];
1471
+    if (isset($themefiles["$subdir$file"])) {
1472
+        return $themefiles["$subdir$file"];
1473
+    }
1474
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1475
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1476
+    if (
1477
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1478
+        and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1479
+        and $f = find_in_theme("$file_svg_generique")
1480
+    ) {
1481
+        if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1482
+            return $themefiles["$subdir$file"] = $fsize;
1483
+        }
1484
+        else {
1485
+            return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1486
+        }
1487
+    }
1488
+
1489
+    $themes = lister_themes_prives();
1490
+    foreach ($themes as $theme) {
1491
+        if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1492
+            return $themefiles["$subdir$file"] = $f;
1493
+        }
1494
+    }
1495
+    spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1496
+
1497
+    return $themefiles["$subdir$file"] = '';
1499 1498
 }
1500 1499
 
1501 1500
 
@@ -1519,31 +1518,31 @@  discard block
 block discarded – undo
1519 1518
  *     sinon chaîne vide.
1520 1519
  **/
1521 1520
 function chemin_image($icone) {
1522
-	static $icone_renommer;
1523
-	if ($p = strpos($icone, '?')) {
1524
-		$icone = substr($icone, 0, $p);
1525
-	}
1526
-	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
1527
-	if (strpos($icone, '/') !== false and file_exists($icone)) {
1528
-		return $icone;
1529
-	}
1530
-
1531
-	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1532
-	if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1533
-		return $f;
1534
-	}
1535
-	// sinon passer par le module de renommage
1536
-	if (is_null($icone_renommer)) {
1537
-		$icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1538
-	}
1539
-	if ($icone_renommer) {
1540
-		[$icone, $fonction] = $icone_renommer($icone, '');
1541
-		if (file_exists($icone)) {
1542
-			return $icone;
1543
-		}
1544
-	}
1545
-
1546
-	return find_in_path($icone, _NOM_IMG_PACK);
1521
+    static $icone_renommer;
1522
+    if ($p = strpos($icone, '?')) {
1523
+        $icone = substr($icone, 0, $p);
1524
+    }
1525
+    // gerer le cas d'un double appel en evitant de refaire le travail inutilement
1526
+    if (strpos($icone, '/') !== false and file_exists($icone)) {
1527
+        return $icone;
1528
+    }
1529
+
1530
+    // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1531
+    if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1532
+        return $f;
1533
+    }
1534
+    // sinon passer par le module de renommage
1535
+    if (is_null($icone_renommer)) {
1536
+        $icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1537
+    }
1538
+    if ($icone_renommer) {
1539
+        [$icone, $fonction] = $icone_renommer($icone, '');
1540
+        if (file_exists($icone)) {
1541
+            return $icone;
1542
+        }
1543
+    }
1544
+
1545
+    return find_in_path($icone, _NOM_IMG_PACK);
1547 1546
 }
1548 1547
 
1549 1548
 //
@@ -1581,128 +1580,128 @@  discard block
 block discarded – undo
1581 1580
  *     - false : fichier introuvable
1582 1581
  **/
1583 1582
 function find_in_path($file, $dirname = '', $include = false) {
1584
-	static $dirs = [];
1585
-	static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1586
-	static $c = '';
1587
-
1588
-	if (!$file and !strlen($file)) {
1589
-		return false;
1590
-	}
1591
-
1592
-	// on calcule le chemin si le dossier skel a change
1593
-	if ($c != $GLOBALS['dossier_squelettes']) {
1594
-		// assurer le non plantage lors de la montee de version :
1595
-		$c = $GLOBALS['dossier_squelettes'];
1596
-		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1597
-	}
1598
-
1599
-	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1600
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1601
-			return false;
1602
-		}
1603
-		if ($include and !isset($inc[$dirname][$file])) {
1604
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1605
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1606
-		}
1607
-
1608
-		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1609
-	}
1610
-
1611
-	$a = strrpos($file, '/');
1612
-	if ($a !== false) {
1613
-		$dirname .= substr($file, 0, ++$a);
1614
-		$file = substr($file, $a);
1615
-	}
1616
-
1617
-	foreach (creer_chemin() as $dir) {
1618
-		if (!isset($dirs[$a = $dir . $dirname])) {
1619
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1620
-		}
1621
-		if ($dirs[$a]) {
1622
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
1623
-				if ($include and !isset($inc[$dirname][$file])) {
1624
-					include_once _ROOT_CWD . $a;
1625
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1626
-				}
1627
-				if (!defined('_SAUVER_CHEMIN')) {
1628
-					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1629
-					if (is_null($GLOBALS['path_files'])) {
1630
-						return $a;
1631
-					}
1632
-					define('_SAUVER_CHEMIN', true);
1633
-				}
1634
-
1635
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1636
-			}
1637
-		}
1638
-	}
1639
-
1640
-	if ($include) {
1641
-		spip_log("include_spip $dirname$file non trouve");
1642
-		if ($include === 'required') {
1643
-			echo '<pre>',
1644
-			'<strong>Erreur Fatale</strong><br />';
1645
-			if (function_exists('debug_print_backtrace')) {
1646
-				echo debug_print_backtrace();
1647
-			}
1648
-			echo '</pre>';
1649
-			die("Erreur interne: ne peut inclure $dirname$file");
1650
-		}
1651
-	}
1652
-
1653
-	if (!defined('_SAUVER_CHEMIN')) {
1654
-		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1655
-		if (is_null($GLOBALS['path_files'])) {
1656
-			return false;
1657
-		}
1658
-		define('_SAUVER_CHEMIN', true);
1659
-	}
1660
-
1661
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1583
+    static $dirs = [];
1584
+    static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1585
+    static $c = '';
1586
+
1587
+    if (!$file and !strlen($file)) {
1588
+        return false;
1589
+    }
1590
+
1591
+    // on calcule le chemin si le dossier skel a change
1592
+    if ($c != $GLOBALS['dossier_squelettes']) {
1593
+        // assurer le non plantage lors de la montee de version :
1594
+        $c = $GLOBALS['dossier_squelettes'];
1595
+        creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1596
+    }
1597
+
1598
+    if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1599
+        if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1600
+            return false;
1601
+        }
1602
+        if ($include and !isset($inc[$dirname][$file])) {
1603
+            include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1604
+            $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1605
+        }
1606
+
1607
+        return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1608
+    }
1609
+
1610
+    $a = strrpos($file, '/');
1611
+    if ($a !== false) {
1612
+        $dirname .= substr($file, 0, ++$a);
1613
+        $file = substr($file, $a);
1614
+    }
1615
+
1616
+    foreach (creer_chemin() as $dir) {
1617
+        if (!isset($dirs[$a = $dir . $dirname])) {
1618
+            $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1619
+        }
1620
+        if ($dirs[$a]) {
1621
+            if (file_exists(_ROOT_CWD . ($a .= $file))) {
1622
+                if ($include and !isset($inc[$dirname][$file])) {
1623
+                    include_once _ROOT_CWD . $a;
1624
+                    $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1625
+                }
1626
+                if (!defined('_SAUVER_CHEMIN')) {
1627
+                    // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1628
+                    if (is_null($GLOBALS['path_files'])) {
1629
+                        return $a;
1630
+                    }
1631
+                    define('_SAUVER_CHEMIN', true);
1632
+                }
1633
+
1634
+                return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1635
+            }
1636
+        }
1637
+    }
1638
+
1639
+    if ($include) {
1640
+        spip_log("include_spip $dirname$file non trouve");
1641
+        if ($include === 'required') {
1642
+            echo '<pre>',
1643
+            '<strong>Erreur Fatale</strong><br />';
1644
+            if (function_exists('debug_print_backtrace')) {
1645
+                echo debug_print_backtrace();
1646
+            }
1647
+            echo '</pre>';
1648
+            die("Erreur interne: ne peut inclure $dirname$file");
1649
+        }
1650
+    }
1651
+
1652
+    if (!defined('_SAUVER_CHEMIN')) {
1653
+        // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1654
+        if (is_null($GLOBALS['path_files'])) {
1655
+            return false;
1656
+        }
1657
+        define('_SAUVER_CHEMIN', true);
1658
+    }
1659
+
1660
+    return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1662 1661
 }
1663 1662
 
1664 1663
 function clear_path_cache() {
1665
-	$GLOBALS['path_files'] = [];
1666
-	spip_unlink(_CACHE_CHEMIN);
1664
+    $GLOBALS['path_files'] = [];
1665
+    spip_unlink(_CACHE_CHEMIN);
1667 1666
 }
1668 1667
 
1669 1668
 function load_path_cache() {
1670
-	// charger le path des plugins
1671
-	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1672
-		include_once(_CACHE_PLUGINS_PATH);
1673
-	}
1674
-	$GLOBALS['path_files'] = [];
1675
-	// si le visiteur est admin,
1676
-	// on ne recharge pas le cache pour forcer sa mise a jour
1677
-	if (
1678
-		// la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1679
-		//AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1680
-		// utiliser le cookie est un pis aller qui marche 'en general'
1681
-		// on blinde par un second test au moment de la lecture de la session
1682
-		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1683
-		// et en ignorant ce cache en cas de recalcul explicite
1684
-		!_request('var_mode')
1685
-	) {
1686
-		// on essaye de lire directement sans verrou pour aller plus vite
1687
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1688
-			// mais si semble corrompu on relit avec un verrou
1689
-			if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1690
-				lire_fichier(_CACHE_CHEMIN, $contenu);
1691
-				if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1692
-					$GLOBALS['path_files'] = [];
1693
-				}
1694
-			}
1695
-		}
1696
-	}
1669
+    // charger le path des plugins
1670
+    if (@is_readable(_CACHE_PLUGINS_PATH)) {
1671
+        include_once(_CACHE_PLUGINS_PATH);
1672
+    }
1673
+    $GLOBALS['path_files'] = [];
1674
+    // si le visiteur est admin,
1675
+    // on ne recharge pas le cache pour forcer sa mise a jour
1676
+    if (
1677
+        // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1678
+        //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1679
+        // utiliser le cookie est un pis aller qui marche 'en general'
1680
+        // on blinde par un second test au moment de la lecture de la session
1681
+        // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1682
+        // et en ignorant ce cache en cas de recalcul explicite
1683
+        !_request('var_mode')
1684
+    ) {
1685
+        // on essaye de lire directement sans verrou pour aller plus vite
1686
+        if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1687
+            // mais si semble corrompu on relit avec un verrou
1688
+            if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1689
+                lire_fichier(_CACHE_CHEMIN, $contenu);
1690
+                if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1691
+                    $GLOBALS['path_files'] = [];
1692
+                }
1693
+            }
1694
+        }
1695
+    }
1697 1696
 }
1698 1697
 
1699 1698
 function save_path_cache() {
1700
-	if (
1701
-		defined('_SAUVER_CHEMIN')
1702
-		and _SAUVER_CHEMIN
1703
-	) {
1704
-		ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1705
-	}
1699
+    if (
1700
+        defined('_SAUVER_CHEMIN')
1701
+        and _SAUVER_CHEMIN
1702
+    ) {
1703
+        ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1704
+    }
1706 1705
 }
1707 1706
 
1708 1707
 
@@ -1722,33 +1721,33 @@  discard block
 block discarded – undo
1722 1721
  * @return array
1723 1722
  */
1724 1723
 function find_all_in_path($dir, $pattern, $recurs = false) {
1725
-	$liste_fichiers = [];
1726
-	$maxfiles = 10000;
1727
-
1728
-	// cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1729
-	// on a pas encore inclus flock.php
1730
-	if (!function_exists('preg_files')) {
1731
-		include_once _ROOT_RESTREINT . 'inc/flock.php';
1732
-	}
1733
-
1734
-	// Parcourir le chemin
1735
-	foreach (creer_chemin() as $d) {
1736
-		$f = $d . $dir;
1737
-		if (@is_dir($f)) {
1738
-			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1739
-			foreach ($liste as $chemin) {
1740
-				$nom = basename($chemin);
1741
-				// ne prendre que les fichiers pas deja trouves
1742
-				// car find_in_path prend le premier qu'il trouve,
1743
-				// les autres sont donc masques
1744
-				if (!isset($liste_fichiers[$nom])) {
1745
-					$liste_fichiers[$nom] = $chemin;
1746
-				}
1747
-			}
1748
-		}
1749
-	}
1750
-
1751
-	return $liste_fichiers;
1724
+    $liste_fichiers = [];
1725
+    $maxfiles = 10000;
1726
+
1727
+    // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1728
+    // on a pas encore inclus flock.php
1729
+    if (!function_exists('preg_files')) {
1730
+        include_once _ROOT_RESTREINT . 'inc/flock.php';
1731
+    }
1732
+
1733
+    // Parcourir le chemin
1734
+    foreach (creer_chemin() as $d) {
1735
+        $f = $d . $dir;
1736
+        if (@is_dir($f)) {
1737
+            $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1738
+            foreach ($liste as $chemin) {
1739
+                $nom = basename($chemin);
1740
+                // ne prendre que les fichiers pas deja trouves
1741
+                // car find_in_path prend le premier qu'il trouve,
1742
+                // les autres sont donc masques
1743
+                if (!isset($liste_fichiers[$nom])) {
1744
+                    $liste_fichiers[$nom] = $chemin;
1745
+                }
1746
+            }
1747
+        }
1748
+    }
1749
+
1750
+    return $liste_fichiers;
1752 1751
 }
1753 1752
 
1754 1753
 /**
@@ -1760,17 +1759,17 @@  discard block
 block discarded – undo
1760 1759
  * @return bool
1761 1760
  */
1762 1761
 function autoriser_sans_cookie($nom, $strict = false) {
1763
-	static $autsanscookie = ['install', 'base_repair'];
1762
+    static $autsanscookie = ['install', 'base_repair'];
1764 1763
 
1765
-	if (in_array($nom, $autsanscookie)) {
1766
-		if (test_espace_prive()) {
1767
-			include_spip('base/connect_sql');
1768
-			if (!$strict or !spip_connect()) {
1769
-				return true;
1770
-			}
1771
-		}
1772
-	}
1773
-	return false;
1764
+    if (in_array($nom, $autsanscookie)) {
1765
+        if (test_espace_prive()) {
1766
+            include_spip('base/connect_sql');
1767
+            if (!$strict or !spip_connect()) {
1768
+                return true;
1769
+            }
1770
+        }
1771
+    }
1772
+    return false;
1774 1773
 }
1775 1774
 
1776 1775
 /**
@@ -1780,60 +1779,60 @@  discard block
 block discarded – undo
1780 1779
  * @return string
1781 1780
  */
1782 1781
 function charger_fonction_url(string $quoi, string $type = '') {
1783
-	if ($type === 'defaut') {
1784
-		$objet = objet_type($quoi);
1785
-		if (
1786
-			$f = charger_fonction('generer_' . $objet . '_url', 'urls', true)
1787
-			// deprecated
1788
-			or $f = charger_fonction('generer_url_' . $objet, 'urls', true)
1789
-		) {
1790
-			return $f;
1791
-		}
1792
-		return '';
1793
-	}
1794
-
1795
-	$url_type = $type;
1796
-	if (!$url_type) {
1797
-		$url_type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut
1798
-	}
1799
-
1800
-	// inclure le module d'url
1801
-	include_spip('urls/' . $url_type);
1802
-
1803
-	switch ($quoi) {
1804
-		case 'page':
1805
-			if (
1806
-				 function_exists($f = "urls_{$url_type}_generer_url_page")
1807
-				or function_exists($f .= '_dist')
1808
-				// ou une fonction custom utilisateur independante du type d'url
1809
-				or function_exists($f = 'generer_url_page')
1810
-				or function_exists($f .= '_dist')
1811
-			) {
1812
-				return $f;
1813
-			}
1814
-			// pas de compat ancienne version ici, c'est une nouvelle feature
1815
-			return '';
1816
-		case 'objet':
1817
-		case 'decoder':
1818
-		default:
1819
-			$fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url');
1820
-			if (
1821
-				function_exists($f = "urls_{$url_type}_{$fquoi}")
1822
-				or function_exists($f .= '_dist')
1823
-			) {
1824
-				return $f;
1825
-			}
1826
-			// est-ce qu'on a une ancienne fonction urls_xxx_dist() ?
1827
-			// c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout
1828
-			if ($f = charger_fonction($url_type, 'urls', true)) {
1829
-				return $f;
1830
-			}
1831
-			// sinon on se rabat sur les urls page si ce n'est pas un type demande explicitement
1832
-			if (!$type and $url_type !== 'page') {
1833
-				return charger_fonction_url($quoi, 'page');
1834
-			}
1835
-			return '';
1836
-	}
1782
+    if ($type === 'defaut') {
1783
+        $objet = objet_type($quoi);
1784
+        if (
1785
+            $f = charger_fonction('generer_' . $objet . '_url', 'urls', true)
1786
+            // deprecated
1787
+            or $f = charger_fonction('generer_url_' . $objet, 'urls', true)
1788
+        ) {
1789
+            return $f;
1790
+        }
1791
+        return '';
1792
+    }
1793
+
1794
+    $url_type = $type;
1795
+    if (!$url_type) {
1796
+        $url_type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut
1797
+    }
1798
+
1799
+    // inclure le module d'url
1800
+    include_spip('urls/' . $url_type);
1801
+
1802
+    switch ($quoi) {
1803
+        case 'page':
1804
+            if (
1805
+                    function_exists($f = "urls_{$url_type}_generer_url_page")
1806
+                or function_exists($f .= '_dist')
1807
+                // ou une fonction custom utilisateur independante du type d'url
1808
+                or function_exists($f = 'generer_url_page')
1809
+                or function_exists($f .= '_dist')
1810
+            ) {
1811
+                return $f;
1812
+            }
1813
+            // pas de compat ancienne version ici, c'est une nouvelle feature
1814
+            return '';
1815
+        case 'objet':
1816
+        case 'decoder':
1817
+        default:
1818
+            $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url');
1819
+            if (
1820
+                function_exists($f = "urls_{$url_type}_{$fquoi}")
1821
+                or function_exists($f .= '_dist')
1822
+            ) {
1823
+                return $f;
1824
+            }
1825
+            // est-ce qu'on a une ancienne fonction urls_xxx_dist() ?
1826
+            // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout
1827
+            if ($f = charger_fonction($url_type, 'urls', true)) {
1828
+                return $f;
1829
+            }
1830
+            // sinon on se rabat sur les urls page si ce n'est pas un type demande explicitement
1831
+            if (!$type and $url_type !== 'page') {
1832
+                return charger_fonction_url($quoi, 'page');
1833
+            }
1834
+            return '';
1835
+    }
1837 1836
 }
1838 1837
 
1839 1838
 
@@ -1859,48 +1858,48 @@  discard block
 block discarded – undo
1859 1858
  *   url codee ou fonction de decodage
1860 1859
  */
1861 1860
 function generer_objet_url($id, string $entite, string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string {
1862
-	if ($public === null) {
1863
-		$public = !test_espace_prive();
1864
-	}
1865
-	$id = intval($id);
1866
-	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1867
-
1868
-	if (!$public) {
1869
-		if (!$entite) {
1870
-			return '';
1871
-		}
1872
-		if (!function_exists('generer_objet_url_ecrire')) {
1873
-			include_spip('inc/urls');
1874
-		}
1875
-		$res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect);
1876
-	} else {
1877
-		$f = charger_fonction_url('objet', $type ?? '');
1878
-
1879
-		// @deprecated si $entite='', on veut la fonction de passage URL ==> id
1880
-		// @see charger_fonction_url
1881
-		if (!$entite) {
1882
-			return $f;
1883
-		}
1884
-
1885
-		// mais d'abord il faut tester le cas des urls sur une
1886
-		// base distante
1887
-		if (
1888
-			$connect
1889
-			and $g = charger_fonction('connect', 'urls', true)
1890
-		) {
1891
-			$f = $g;
1892
-		}
1893
-
1894
-		$res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect);
1895
-	}
1896
-	if ($res) {
1897
-		return $res;
1898
-	}
1899
-
1900
-	// On a ete gentil mais la ....
1901
-	spip_log("generer_objet_url: entite $entite ($f) inconnue $type $public $connect", _LOG_ERREUR);
1902
-
1903
-	return '';
1861
+    if ($public === null) {
1862
+        $public = !test_espace_prive();
1863
+    }
1864
+    $id = intval($id);
1865
+    $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1866
+
1867
+    if (!$public) {
1868
+        if (!$entite) {
1869
+            return '';
1870
+        }
1871
+        if (!function_exists('generer_objet_url_ecrire')) {
1872
+            include_spip('inc/urls');
1873
+        }
1874
+        $res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect);
1875
+    } else {
1876
+        $f = charger_fonction_url('objet', $type ?? '');
1877
+
1878
+        // @deprecated si $entite='', on veut la fonction de passage URL ==> id
1879
+        // @see charger_fonction_url
1880
+        if (!$entite) {
1881
+            return $f;
1882
+        }
1883
+
1884
+        // mais d'abord il faut tester le cas des urls sur une
1885
+        // base distante
1886
+        if (
1887
+            $connect
1888
+            and $g = charger_fonction('connect', 'urls', true)
1889
+        ) {
1890
+            $f = $g;
1891
+        }
1892
+
1893
+        $res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect);
1894
+    }
1895
+    if ($res) {
1896
+        return $res;
1897
+    }
1898
+
1899
+    // On a ete gentil mais la ....
1900
+    spip_log("generer_objet_url: entite $entite ($f) inconnue $type $public $connect", _LOG_ERREUR);
1901
+
1902
+    return '';
1904 1903
 }
1905 1904
 
1906 1905
 /**
@@ -1908,10 +1907,10 @@  discard block
 block discarded – undo
1908 1907
  * @see generer_objet_url
1909 1908
  */
1910 1909
 function generer_url_entite($id = 0, $entite = '', $args = '', $ancre = '', $public = null, $type = null) {
1911
-	if ($public and is_string($public)) {
1912
-		return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public);
1913
-	}
1914
-	return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? '');
1910
+    if ($public and is_string($public)) {
1911
+        return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public);
1912
+    }
1913
+    return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? '');
1915 1914
 }
1916 1915
 
1917 1916
 /**
@@ -1923,19 +1922,19 @@  discard block
 block discarded – undo
1923 1922
  * @return string
1924 1923
  */
1925 1924
 function generer_objet_url_ecrire_edit($id, string $entite, string $args = '', string $ancre = ''): string {
1926
-	$id = intval($id);
1927
-	$exec = objet_info($entite, 'url_edit');
1928
-	$url = generer_url_ecrire($exec, $args);
1929
-	if (intval($id)) {
1930
-		$url = parametre_url($url, id_table_objet($entite), $id);
1931
-	} else {
1932
-		$url = parametre_url($url, 'new', 'oui');
1933
-	}
1934
-	if ($ancre) {
1935
-		$url = ancre_url($url, $ancre);
1936
-	}
1925
+    $id = intval($id);
1926
+    $exec = objet_info($entite, 'url_edit');
1927
+    $url = generer_url_ecrire($exec, $args);
1928
+    if (intval($id)) {
1929
+        $url = parametre_url($url, id_table_objet($entite), $id);
1930
+    } else {
1931
+        $url = parametre_url($url, 'new', 'oui');
1932
+    }
1933
+    if ($ancre) {
1934
+        $url = ancre_url($url, $ancre);
1935
+    }
1937 1936
 
1938
-	return $url;
1937
+    return $url;
1939 1938
 }
1940 1939
 
1941 1940
 /**
@@ -1943,18 +1942,18 @@  discard block
 block discarded – undo
1943 1942
  * @see generer_objet_url_ecrire_edit
1944 1943
  */
1945 1944
 function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') {
1946
-	return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre);
1945
+    return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre);
1947 1946
 }
1948 1947
 
1949 1948
 
1950 1949
 function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) {
1951
-	include_spip('base/connect_sql');
1952
-	$id_type = id_table_objet($entite, $public);
1950
+    include_spip('base/connect_sql');
1951
+    $id_type = id_table_objet($entite, $public);
1953 1952
 
1954
-	return _DIR_RACINE . get_spip_script('./')
1955
-	. '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1956
-	. (!$args ? '' : "&$args")
1957
-	. (!$ancre ? '' : "#$ancre");
1953
+    return _DIR_RACINE . get_spip_script('./')
1954
+    . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1955
+    . (!$args ? '' : "&$args")
1956
+    . (!$ancre ? '' : "#$ancre");
1958 1957
 }
1959 1958
 
1960 1959
 
@@ -1965,18 +1964,18 @@  discard block
 block discarded – undo
1965 1964
  * @return string
1966 1965
  */
1967 1966
 function urlencode_1738($url) {
1968
-	if (preg_match(',[^\x00-\x7E],sS', $url)) {
1969
-		$uri = '';
1970
-		for ($i = 0; $i < strlen($url); $i++) {
1971
-			if (ord($a = $url[$i]) > 127) {
1972
-				$a = rawurlencode($a);
1973
-			}
1974
-			$uri .= $a;
1975
-		}
1976
-		$url = $uri;
1977
-	}
1967
+    if (preg_match(',[^\x00-\x7E],sS', $url)) {
1968
+        $uri = '';
1969
+        for ($i = 0; $i < strlen($url); $i++) {
1970
+            if (ord($a = $url[$i]) > 127) {
1971
+                $a = rawurlencode($a);
1972
+            }
1973
+            $uri .= $a;
1974
+        }
1975
+        $url = $uri;
1976
+    }
1978 1977
 
1979
-	return quote_amp($url);
1978
+    return quote_amp($url);
1980 1979
 }
1981 1980
 
1982 1981
 /**
@@ -1992,14 +1991,14 @@  discard block
 block discarded – undo
1992 1991
  * @return string
1993 1992
  */
1994 1993
 function generer_objet_url_absolue($id = 0, string $entite = '', string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string {
1995
-	$id = intval($id);
1996
-	$h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect);
1997
-	if (!preg_match(',^\w+:,', $h)) {
1998
-		include_spip('inc/filtres_mini');
1999
-		$h = url_absolue($h);
2000
-	}
1994
+    $id = intval($id);
1995
+    $h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect);
1996
+    if (!preg_match(',^\w+:,', $h)) {
1997
+        include_spip('inc/filtres_mini');
1998
+        $h = url_absolue($h);
1999
+    }
2001 2000
 
2002
-	return $h;
2001
+    return $h;
2003 2002
 }
2004 2003
 
2005 2004
 /**
@@ -2007,7 +2006,7 @@  discard block
 block discarded – undo
2007 2006
  * @see  generer_objet_url_absolue
2008 2007
  */
2009 2008
 function generer_url_entite_absolue($id = 0, $entite = '', $args = '', $ancre = '', $connect = null) {
2010
-	return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect ?? '');
2009
+    return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect ?? '');
2011 2010
 }
2012 2011
 
2013 2012
 
@@ -2023,11 +2022,11 @@  discard block
 block discarded – undo
2023 2022
  *     true si la valeur est considérée active ; false sinon.
2024 2023
  **/
2025 2024
 function test_valeur_serveur($truc) {
2026
-	if (!$truc) {
2027
-		return false;
2028
-	}
2025
+    if (!$truc) {
2026
+        return false;
2027
+    }
2029 2028
 
2030
-	return (strtolower($truc) !== 'off');
2029
+    return (strtolower($truc) !== 'off');
2031 2030
 }
2032 2031
 
2033 2032
 //
@@ -2055,89 +2054,89 @@  discard block
 block discarded – undo
2055 2054
  */
2056 2055
 function url_de_base($profondeur = null) {
2057 2056
 
2058
-	static $url = [];
2059
-	if (is_array($profondeur)) {
2060
-		return $url = $profondeur;
2061
-	}
2062
-	if ($profondeur === false) {
2063
-		return $url;
2064
-	}
2065
-
2066
-	if (is_null($profondeur)) {
2067
-		$profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1);
2068
-	}
2069
-
2070
-	if (isset($url[$profondeur])) {
2071
-		return $url[$profondeur];
2072
-	}
2073
-
2074
-	$http = 'http';
2075
-
2076
-	if (
2077
-		isset($_SERVER['SCRIPT_URI'])
2078
-		and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https'
2079
-	) {
2080
-		$http = 'https';
2081
-	} elseif (
2082
-		isset($_SERVER['HTTPS'])
2083
-		and test_valeur_serveur($_SERVER['HTTPS'])
2084
-	) {
2085
-		$http = 'https';
2086
-	}
2087
-
2088
-	// note : HTTP_HOST contient le :port si necessaire
2089
-	if ($host = $_SERVER['HTTP_HOST'] ?? null) {
2090
-		// Filtrer $host pour proteger d'attaques d'entete HTTP
2091
-		$host = (filter_var($host, FILTER_SANITIZE_URL) ?: null);
2092
-	}
2093
-
2094
-	// si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
2095
-	if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
2096
-		$host = $GLOBALS['meta']['adresse_site'];
2097
-		if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
2098
-			$http = $scheme;
2099
-			$host = str_replace("{$scheme}://", '', $host);
2100
-		}
2101
-	}
2102
-	if (
2103
-		isset($_SERVER['SERVER_PORT'])
2104
-		and $port = $_SERVER['SERVER_PORT']
2105
-		and strpos($host, ':') == false
2106
-	) {
2107
-		if (!defined('_PORT_HTTP_STANDARD')) {
2108
-			define('_PORT_HTTP_STANDARD', '80');
2109
-		}
2110
-		if (!defined('_PORT_HTTPS_STANDARD')) {
2111
-			define('_PORT_HTTPS_STANDARD', '443');
2112
-		}
2113
-		if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2114
-			$host .= ":$port";
2115
-		}
2116
-		if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2117
-			$host .= ":$port";
2118
-		}
2119
-	}
2120
-
2121
-	if (!$GLOBALS['REQUEST_URI']) {
2122
-		if (isset($_SERVER['REQUEST_URI'])) {
2123
-			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2124
-		} else {
2125
-			$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2126
-			if (
2127
-				!empty($_SERVER['QUERY_STRING'])
2128
-				and !strpos($_SERVER['REQUEST_URI'], '?')
2129
-			) {
2130
-				$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2131
-			}
2132
-		}
2133
-	}
2134
-
2135
-	// Et nettoyer l'url
2136
-	$GLOBALS['REQUEST_URI'] = (filter_var($GLOBALS['REQUEST_URI'], FILTER_SANITIZE_URL) ?: '');
2137
-
2138
-	$url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2139
-
2140
-	return $url[$profondeur];
2057
+    static $url = [];
2058
+    if (is_array($profondeur)) {
2059
+        return $url = $profondeur;
2060
+    }
2061
+    if ($profondeur === false) {
2062
+        return $url;
2063
+    }
2064
+
2065
+    if (is_null($profondeur)) {
2066
+        $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1);
2067
+    }
2068
+
2069
+    if (isset($url[$profondeur])) {
2070
+        return $url[$profondeur];
2071
+    }
2072
+
2073
+    $http = 'http';
2074
+
2075
+    if (
2076
+        isset($_SERVER['SCRIPT_URI'])
2077
+        and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https'
2078
+    ) {
2079
+        $http = 'https';
2080
+    } elseif (
2081
+        isset($_SERVER['HTTPS'])
2082
+        and test_valeur_serveur($_SERVER['HTTPS'])
2083
+    ) {
2084
+        $http = 'https';
2085
+    }
2086
+
2087
+    // note : HTTP_HOST contient le :port si necessaire
2088
+    if ($host = $_SERVER['HTTP_HOST'] ?? null) {
2089
+        // Filtrer $host pour proteger d'attaques d'entete HTTP
2090
+        $host = (filter_var($host, FILTER_SANITIZE_URL) ?: null);
2091
+    }
2092
+
2093
+    // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
2094
+    if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
2095
+        $host = $GLOBALS['meta']['adresse_site'];
2096
+        if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
2097
+            $http = $scheme;
2098
+            $host = str_replace("{$scheme}://", '', $host);
2099
+        }
2100
+    }
2101
+    if (
2102
+        isset($_SERVER['SERVER_PORT'])
2103
+        and $port = $_SERVER['SERVER_PORT']
2104
+        and strpos($host, ':') == false
2105
+    ) {
2106
+        if (!defined('_PORT_HTTP_STANDARD')) {
2107
+            define('_PORT_HTTP_STANDARD', '80');
2108
+        }
2109
+        if (!defined('_PORT_HTTPS_STANDARD')) {
2110
+            define('_PORT_HTTPS_STANDARD', '443');
2111
+        }
2112
+        if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2113
+            $host .= ":$port";
2114
+        }
2115
+        if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2116
+            $host .= ":$port";
2117
+        }
2118
+    }
2119
+
2120
+    if (!$GLOBALS['REQUEST_URI']) {
2121
+        if (isset($_SERVER['REQUEST_URI'])) {
2122
+            $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2123
+        } else {
2124
+            $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2125
+            if (
2126
+                !empty($_SERVER['QUERY_STRING'])
2127
+                and !strpos($_SERVER['REQUEST_URI'], '?')
2128
+            ) {
2129
+                $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2130
+            }
2131
+        }
2132
+    }
2133
+
2134
+    // Et nettoyer l'url
2135
+    $GLOBALS['REQUEST_URI'] = (filter_var($GLOBALS['REQUEST_URI'], FILTER_SANITIZE_URL) ?: '');
2136
+
2137
+    $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2138
+
2139
+    return $url[$profondeur];
2141 2140
 }
2142 2141
 
2143 2142
 /**
@@ -2150,26 +2149,26 @@  discard block
 block discarded – undo
2150 2149
  * @return string
2151 2150
  */
2152 2151
 function url_de_($http, $host, $request, $prof = 0) {
2153
-	$prof = max($prof, 0);
2152
+    $prof = max($prof, 0);
2154 2153
 
2155
-	$myself = ltrim($request, '/');
2156
-	# supprimer la chaine de GET
2157
-	[$myself] = explode('?', $myself);
2158
-	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2159
-	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2160
-	if (strpos($myself, '://') !== false) {
2161
-		$myself = explode('://', $myself);
2162
-		array_shift($myself);
2163
-		$myself = implode('://', $myself);
2164
-		$myself = explode('/', $myself);
2165
-		array_shift($myself);
2166
-		$myself = implode('/', $myself);
2167
-	}
2168
-	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2154
+    $myself = ltrim($request, '/');
2155
+    # supprimer la chaine de GET
2156
+    [$myself] = explode('?', $myself);
2157
+    // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2158
+    // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2159
+    if (strpos($myself, '://') !== false) {
2160
+        $myself = explode('://', $myself);
2161
+        array_shift($myself);
2162
+        $myself = implode('://', $myself);
2163
+        $myself = explode('/', $myself);
2164
+        array_shift($myself);
2165
+        $myself = implode('/', $myself);
2166
+    }
2167
+    $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2169 2168
 
2170
-	$url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2169
+    $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2171 2170
 
2172
-	return $url;
2171
+    return $url;
2173 2172
 }
2174 2173
 
2175 2174
 
@@ -2204,26 +2203,26 @@  discard block
 block discarded – undo
2204 2203
  * @return string URL
2205 2204
  **/
2206 2205
 function generer_url_ecrire(?string $script = '', $args = '', $no_entities = false, $rel = false) {
2207
-	$script ??= '';
2208
-	if (!$rel) {
2209
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2210
-	} else {
2211
-		if (!is_string($rel)) {
2212
-			$rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
2213
-		}
2214
-	}
2215
-
2216
-	[$script, $ancre] = array_pad(explode('#', $script), 2, null);
2217
-	if ($script and ($script <> 'accueil' or $rel)) {
2218
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
2219
-	} elseif ($args) {
2220
-		$args = "?$args";
2221
-	}
2222
-	if ($ancre) {
2223
-		$args .= "#$ancre";
2224
-	}
2225
-
2226
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2206
+    $script ??= '';
2207
+    if (!$rel) {
2208
+        $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2209
+    } else {
2210
+        if (!is_string($rel)) {
2211
+            $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
2212
+        }
2213
+    }
2214
+
2215
+    [$script, $ancre] = array_pad(explode('#', $script), 2, null);
2216
+    if ($script and ($script <> 'accueil' or $rel)) {
2217
+        $args = "?exec=$script" . (!$args ? '' : "&$args");
2218
+    } elseif ($args) {
2219
+        $args = "?$args";
2220
+    }
2221
+    if ($ancre) {
2222
+        $args .= "#$ancre";
2223
+    }
2224
+
2225
+    return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2227 2226
 }
2228 2227
 
2229 2228
 //
@@ -2245,15 +2244,15 @@  discard block
 block discarded – undo
2245 2244
  *     Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut
2246 2245
  **/
2247 2246
 function get_spip_script($default = '') {
2248
-	if (!defined('_SPIP_SCRIPT')) {
2249
-		return 'spip.php';
2250
-	}
2251
-	# cas define('_SPIP_SCRIPT', '');
2252
-	if (_SPIP_SCRIPT) {
2253
-		return _SPIP_SCRIPT;
2254
-	} else {
2255
-		return $default;
2256
-	}
2247
+    if (!defined('_SPIP_SCRIPT')) {
2248
+        return 'spip.php';
2249
+    }
2250
+    # cas define('_SPIP_SCRIPT', '');
2251
+    if (_SPIP_SCRIPT) {
2252
+        return _SPIP_SCRIPT;
2253
+    } else {
2254
+        return $default;
2255
+    }
2257 2256
 }
2258 2257
 
2259 2258
 /**
@@ -2282,45 +2281,45 @@  discard block
 block discarded – undo
2282 2281
  * @return string URL
2283 2282
  **/
2284 2283
 function generer_url_public($script = '', $args = '', $no_entities = false, $rel = true, $action = '') {
2285
-	// si le script est une action (spip_pass, spip_inscription),
2286
-	// standardiser vers la nouvelle API
2287
-
2288
-	if (is_array($args)) {
2289
-		$args = http_build_query($args);
2290
-	}
2291
-
2292
-	$url = '';
2293
-	if ($f = charger_fonction_url('page')) {
2294
-		$url = $f($script, $args);
2295
-		if ($url and !$rel) {
2296
-			include_spip('inc/filtres_mini');
2297
-			$url = url_absolue($url);
2298
-		}
2299
-	}
2300
-	if (!$url) {
2301
-		if (!$action) {
2302
-			$action = get_spip_script();
2303
-		}
2304
-		if ($script) {
2305
-			$action = parametre_url($action, _SPIP_PAGE, $script, '&');
2306
-		}
2307
-		if ($args) {
2308
-			$action .= (strpos($action, '?') !== false ? '&' : '?') . $args;
2309
-		}
2310
-		// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2311
-		$url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2312
-	}
2313
-
2314
-	if (!$no_entities) {
2315
-		$url = quote_amp($url);
2316
-	}
2317
-
2318
-	return $url;
2284
+    // si le script est une action (spip_pass, spip_inscription),
2285
+    // standardiser vers la nouvelle API
2286
+
2287
+    if (is_array($args)) {
2288
+        $args = http_build_query($args);
2289
+    }
2290
+
2291
+    $url = '';
2292
+    if ($f = charger_fonction_url('page')) {
2293
+        $url = $f($script, $args);
2294
+        if ($url and !$rel) {
2295
+            include_spip('inc/filtres_mini');
2296
+            $url = url_absolue($url);
2297
+        }
2298
+    }
2299
+    if (!$url) {
2300
+        if (!$action) {
2301
+            $action = get_spip_script();
2302
+        }
2303
+        if ($script) {
2304
+            $action = parametre_url($action, _SPIP_PAGE, $script, '&');
2305
+        }
2306
+        if ($args) {
2307
+            $action .= (strpos($action, '?') !== false ? '&' : '?') . $args;
2308
+        }
2309
+        // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2310
+        $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2311
+    }
2312
+
2313
+    if (!$no_entities) {
2314
+        $url = quote_amp($url);
2315
+    }
2316
+
2317
+    return $url;
2319 2318
 }
2320 2319
 
2321 2320
 function generer_url_prive($script, $args = '', $no_entities = false) {
2322 2321
 
2323
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2322
+    return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2324 2323
 }
2325 2324
 
2326 2325
 // Pour les formulaires en methode POST,
@@ -2345,19 +2344,19 @@  discard block
 block discarded – undo
2345 2344
  **/
2346 2345
 function generer_form_ecrire($script, $corps, $atts = '', $submit = '') {
2347 2346
 
2348
-	$script1 = explode('&', $script);
2349
-	$script1 = reset($script1);
2347
+    $script1 = explode('&', $script);
2348
+    $script1 = reset($script1);
2350 2349
 
2351
-	return "<form action='"
2352
-	. ($script ? generer_url_ecrire($script) : '')
2353
-	. "' "
2354
-	. ($atts ?: " method='post'")
2355
-	. "><div>\n"
2356
-	. "<input type='hidden' name='exec' value='$script1' />"
2357
-	. $corps
2358
-	. (!$submit ? '' :
2359
-		("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2360
-	. "</div></form>\n";
2350
+    return "<form action='"
2351
+    . ($script ? generer_url_ecrire($script) : '')
2352
+    . "' "
2353
+    . ($atts ?: " method='post'")
2354
+    . "><div>\n"
2355
+    . "<input type='hidden' name='exec' value='$script1' />"
2356
+    . $corps
2357
+    . (!$submit ? '' :
2358
+        ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2359
+    . "</div></form>\n";
2361 2360
 }
2362 2361
 
2363 2362
 /**
@@ -2374,22 +2373,22 @@  discard block
 block discarded – undo
2374 2373
  * @return string
2375 2374
  */
2376 2375
 function generer_form_action($script, $corps, $atts = '', $public = false) {
2377
-	// si l'on est dans l'espace prive, on garde dans l'url
2378
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2379
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2380
-	$h = (_DIR_RACINE and !$public)
2381
-		? generer_url_ecrire(_request('exec'))
2382
-		: generer_url_public();
2376
+    // si l'on est dans l'espace prive, on garde dans l'url
2377
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2378
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2379
+    $h = (_DIR_RACINE and !$public)
2380
+        ? generer_url_ecrire(_request('exec'))
2381
+        : generer_url_public();
2383 2382
 
2384
-	return "\n<form action='" .
2385
-	$h .
2386
-	"'" .
2387
-	$atts .
2388
-	">\n" .
2389
-	'<div>' .
2390
-	"\n<input type='hidden' name='action' value='$script' />" .
2391
-	$corps .
2392
-	'</div></form>';
2383
+    return "\n<form action='" .
2384
+    $h .
2385
+    "'" .
2386
+    $atts .
2387
+    ">\n" .
2388
+    '<div>' .
2389
+    "\n<input type='hidden' name='action' value='$script' />" .
2390
+    $corps .
2391
+    '</div></form>';
2393 2392
 }
2394 2393
 
2395 2394
 /**
@@ -2408,22 +2407,22 @@  discard block
 block discarded – undo
2408 2407
  *     URL
2409 2408
  */
2410 2409
 function generer_url_action($script, $args = '', $no_entities = false, $public = false) {
2411
-	// si l'on est dans l'espace prive, on garde dans l'url
2412
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2413
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2414
-	$url = (_DIR_RACINE and !$public)
2415
-		? generer_url_ecrire(_request('exec'))
2416
-		: generer_url_public('', '', false, false);
2417
-	$url = parametre_url($url, 'action', $script);
2418
-	if ($args) {
2419
-		$url .= quote_amp('&' . $args);
2420
-	}
2410
+    // si l'on est dans l'espace prive, on garde dans l'url
2411
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2412
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2413
+    $url = (_DIR_RACINE and !$public)
2414
+        ? generer_url_ecrire(_request('exec'))
2415
+        : generer_url_public('', '', false, false);
2416
+    $url = parametre_url($url, 'action', $script);
2417
+    if ($args) {
2418
+        $url .= quote_amp('&' . $args);
2419
+    }
2421 2420
 
2422
-	if ($no_entities) {
2423
-		$url = str_replace('&amp;', '&', $url);
2424
-	}
2421
+    if ($no_entities) {
2422
+        $url = str_replace('&amp;', '&', $url);
2423
+    }
2425 2424
 
2426
-	return $url;
2425
+    return $url;
2427 2426
 }
2428 2427
 
2429 2428
 
@@ -2442,23 +2441,23 @@  discard block
 block discarded – undo
2442 2441
  *     URL
2443 2442
  */
2444 2443
 function generer_url_api(string $script, string $path, string $args, bool $no_entities = false, ?bool $public = null) {
2445
-	if (is_null($public)) {
2446
-		$public = (_DIR_RACINE ? false : '');
2447
-	}
2448
-	if (substr($script, -4) !== '.api') {
2449
-		$script .= '.api';
2450
-	}
2451
-	$url =
2452
-		(($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './')
2453
-	. $script . '/'
2454
-	. ($path ? trim($path, '/') : '')
2455
-	. ($args ? '?' . quote_amp($args) : '');
2444
+    if (is_null($public)) {
2445
+        $public = (_DIR_RACINE ? false : '');
2446
+    }
2447
+    if (substr($script, -4) !== '.api') {
2448
+        $script .= '.api';
2449
+    }
2450
+    $url =
2451
+        (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './')
2452
+    . $script . '/'
2453
+    . ($path ? trim($path, '/') : '')
2454
+    . ($args ? '?' . quote_amp($args) : '');
2456 2455
 
2457
-	if ($no_entities) {
2458
-		$url = str_replace('&amp;', '&', $url);
2459
-	}
2456
+    if ($no_entities) {
2457
+        $url = str_replace('&amp;', '&', $url);
2458
+    }
2460 2459
 
2461
-	return $url;
2460
+    return $url;
2462 2461
 }
2463 2462
 
2464 2463
 
@@ -2471,8 +2470,8 @@  discard block
 block discarded – undo
2471 2470
  * @param string $ta Répertoire temporaire accessible
2472 2471
  */
2473 2472
 function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) {
2474
-	spip_initialisation_core($pi, $pa, $ti, $ta);
2475
-	spip_initialisation_suite();
2473
+    spip_initialisation_core($pi, $pa, $ti, $ta);
2474
+    spip_initialisation_suite();
2476 2475
 }
2477 2476
 
2478 2477
 /**
@@ -2492,315 +2491,315 @@  discard block
 block discarded – undo
2492 2491
  * @param string $ta Répertoire temporaire accessible
2493 2492
  */
2494 2493
 function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) {
2495
-	static $too_late = 0;
2496
-	if ($too_late++) {
2497
-		return;
2498
-	}
2499
-
2500
-	// Declaration des repertoires
2501
-
2502
-	// le nom du repertoire plugins/ activables/desactivables
2503
-	if (!defined('_DIR_PLUGINS')) {
2504
-		define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2505
-	}
2506
-
2507
-	// le nom du repertoire des extensions/ permanentes du core, toujours actives
2508
-	if (!defined('_DIR_PLUGINS_DIST')) {
2509
-		define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2510
-	}
2511
-
2512
-	// le nom du repertoire des librairies
2513
-	if (!defined('_DIR_LIB')) {
2514
-		define('_DIR_LIB', _DIR_RACINE . 'lib/');
2515
-	}
2516
-
2517
-	// répertoire des libs via Composer
2518
-	if (!defined('_DIR_VENDOR')) {
2519
-		define('_DIR_VENDOR', _DIR_RACINE . 'vendor/');
2520
-	}
2521
-
2522
-	if (!defined('_DIR_IMG')) {
2523
-		define('_DIR_IMG', $pa);
2524
-	}
2525
-	if (!defined('_DIR_LOGOS')) {
2526
-		define('_DIR_LOGOS', $pa);
2527
-	}
2528
-	if (!defined('_DIR_IMG_ICONES')) {
2529
-		define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2530
-	}
2531
-
2532
-	if (!defined('_DIR_DUMP')) {
2533
-		define('_DIR_DUMP', $ti . 'dump/');
2534
-	}
2535
-	if (!defined('_DIR_SESSIONS')) {
2536
-		define('_DIR_SESSIONS', $ti . 'sessions/');
2537
-	}
2538
-	if (!defined('_DIR_TRANSFERT')) {
2539
-		define('_DIR_TRANSFERT', $ti . 'upload/');
2540
-	}
2541
-	if (!defined('_DIR_CACHE')) {
2542
-		define('_DIR_CACHE', $ti . 'cache/');
2543
-	}
2544
-	if (!defined('_DIR_CACHE_XML')) {
2545
-		define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2546
-	}
2547
-	if (!defined('_DIR_SKELS')) {
2548
-		define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2549
-	}
2550
-	if (!defined('_DIR_AIDE')) {
2551
-		define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2552
-	}
2553
-	if (!defined('_DIR_TMP')) {
2554
-		define('_DIR_TMP', $ti);
2555
-	}
2556
-
2557
-	if (!defined('_DIR_VAR')) {
2558
-		define('_DIR_VAR', $ta);
2559
-	}
2560
-
2561
-	if (!defined('_DIR_ETC')) {
2562
-		define('_DIR_ETC', $pi);
2563
-	}
2564
-	if (!defined('_DIR_CONNECT')) {
2565
-		define('_DIR_CONNECT', $pi);
2566
-	}
2567
-	if (!defined('_DIR_CHMOD')) {
2568
-		define('_DIR_CHMOD', $pi);
2569
-	}
2570
-
2571
-	if (!isset($GLOBALS['test_dirs'])) {
2572
-		// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2573
-		// il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2574
-	$GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2575
-	}
2576
-
2577
-	// Declaration des fichiers
2578
-
2579
-	if (!defined('_CACHE_PLUGINS_PATH')) {
2580
-		define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2581
-	}
2582
-	if (!defined('_CACHE_PLUGINS_OPT')) {
2583
-		define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2584
-	}
2585
-	if (!defined('_CACHE_PLUGINS_FCT')) {
2586
-		define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2587
-	}
2588
-	if (!defined('_CACHE_PIPELINES')) {
2589
-		define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2590
-	}
2591
-	if (!defined('_CACHE_CHEMIN')) {
2592
-		define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2593
-	}
2594
-
2595
-	# attention .php obligatoire pour ecrire_fichier_securise
2596
-	if (!defined('_FILE_META')) {
2597
-		define('_FILE_META', $ti . 'meta_cache.php');
2598
-	}
2599
-	if (!defined('_DIR_LOG')) {
2600
-		define('_DIR_LOG', _DIR_TMP . 'log/');
2601
-	}
2602
-	if (!defined('_FILE_LOG')) {
2603
-		define('_FILE_LOG', 'spip');
2604
-	}
2605
-	if (!defined('_FILE_LOG_SUFFIX')) {
2606
-		define('_FILE_LOG_SUFFIX', '.log');
2607
-	}
2608
-
2609
-	// Le fichier de connexion a la base de donnees
2610
-	// tient compte des anciennes versions (inc_connect...)
2611
-	if (!defined('_FILE_CONNECT_INS')) {
2612
-		define('_FILE_CONNECT_INS', 'connect');
2613
-	}
2614
-	if (!defined('_FILE_CONNECT')) {
2615
-		define(
2616
-			'_FILE_CONNECT',
2617
-			(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2618
-			: (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2619
-			: false))
2620
-		);
2621
-	}
2622
-
2623
-	// Le fichier de reglages des droits
2624
-	if (!defined('_FILE_CHMOD_INS')) {
2625
-		define('_FILE_CHMOD_INS', 'chmod');
2626
-	}
2627
-	if (!defined('_FILE_CHMOD')) {
2628
-		define(
2629
-			'_FILE_CHMOD',
2630
-			(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2631
-			: false)
2632
-		);
2633
-	}
2634
-
2635
-	if (!defined('_FILE_LDAP')) {
2636
-		define('_FILE_LDAP', 'ldap.php');
2637
-	}
2638
-
2639
-	if (!defined('_FILE_TMP_SUFFIX')) {
2640
-		define('_FILE_TMP_SUFFIX', '.tmp.php');
2641
-	}
2642
-	if (!defined('_FILE_CONNECT_TMP')) {
2643
-		define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2644
-	}
2645
-	if (!defined('_FILE_CHMOD_TMP')) {
2646
-		define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2647
-	}
2648
-
2649
-	// Definition des droits d'acces en ecriture
2650
-	if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2651
-		include_once _FILE_CHMOD;
2652
-	}
2653
-
2654
-	// Se mefier des fichiers mal remplis!
2655
-	if (!defined('_SPIP_CHMOD')) {
2656
-		define('_SPIP_CHMOD', 0777);
2657
-	}
2658
-
2659
-	if (!defined('_DEFAULT_CHARSET')) {
2660
-		/** Le charset par défaut lors de l'installation */
2661
-		define('_DEFAULT_CHARSET', 'utf-8');
2662
-	}
2663
-	if (!defined('_ROOT_PLUGINS')) {
2664
-		define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2665
-	}
2666
-	if (!defined('_ROOT_PLUGINS_DIST')) {
2667
-		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2668
-	}
2669
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2670
-		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2671
-	}
2672
-
2673
-	// La taille des Log
2674
-	if (!defined('_MAX_LOG')) {
2675
-		define('_MAX_LOG', 100);
2676
-	}
2677
-
2678
-	// Sommes-nous dans l'empire du Mal ?
2679
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
2680
-	if (isset($_SERVER['SERVER_SOFTWARE']) and str_contains($_SERVER['SERVER_SOFTWARE'], '(Win')) {
2681
-		if (!defined('_OS_SERVEUR')) {
2682
-			define('_OS_SERVEUR', 'windows');
2683
-		}
2684
-		if (!defined('_SPIP_LOCK_MODE')) {
2685
-			define('_SPIP_LOCK_MODE', 1);
2686
-		} // utiliser le flock php
2687
-	} else {
2688
-		if (!defined('_OS_SERVEUR')) {
2689
-			define('_OS_SERVEUR', '');
2690
-		}
2691
-		if (!defined('_SPIP_LOCK_MODE')) {
2692
-			define('_SPIP_LOCK_MODE', 1);
2693
-		} // utiliser le flock php
2694
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2695
-	}
2696
-
2697
-	// Langue par defaut
2698
-	if (!defined('_LANGUE_PAR_DEFAUT')) {
2699
-		define('_LANGUE_PAR_DEFAUT', 'fr');
2700
-	}
2701
-
2702
-	//
2703
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
2704
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
2705
-	// pour le rendre surchargeable, on va provoquer un reecriture
2706
-	// systematique du noyau ou une baisse de perfs => a etudier)
2707
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
2708
-
2709
-	// charger tout de suite le path et son cache
2710
-	load_path_cache();
2711
-
2712
-	// *********** traiter les variables ************
2713
-
2714
-	//
2715
-	// Securite
2716
-	//
2717
-
2718
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2719
-	if (isset($_REQUEST['GLOBALS'])) {
2720
-		die();
2721
-	}
2722
-	// nettoyer les magic quotes \' et les caracteres nuls %00
2723
-	spip_desinfecte($_GET);
2724
-	spip_desinfecte($_POST);
2725
-	spip_desinfecte($_COOKIE);
2726
-	spip_desinfecte($_REQUEST);
2727
-
2728
-	// appliquer le cookie_prefix
2729
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
2730
-		include_spip('inc/cookie');
2731
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2732
-	}
2733
-
2734
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2735
-	if (isset($_SERVER['REQUEST_URI'])) {
2736
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2737
-	} else {
2738
-		$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2739
-		if (
2740
-			!empty($_SERVER['QUERY_STRING'])
2741
-			and !strpos($_SERVER['REQUEST_URI'], '?')
2742
-		) {
2743
-			$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2744
-		}
2745
-	}
2746
-
2747
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2748
-	if (!defined('_RENOUVELLE_ALEA')) {
2749
-		define('_RENOUVELLE_ALEA', 12 * 3600);
2750
-	}
2751
-	if (!defined('_DUREE_COOKIE_ADMIN')) {
2752
-		define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2753
-	}
2754
-
2755
-	// charger les meta si possible et renouveller l'alea au besoin
2756
-	// charge aussi effacer_meta et ecrire_meta
2757
-	$inc_meta = charger_fonction('meta', 'inc');
2758
-	$inc_meta();
2759
-
2760
-	// nombre de repertoires depuis la racine
2761
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2762
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2763
-	// le calcul est faux)
2764
-	if (!_DIR_RESTREINT) {
2765
-		$GLOBALS['profondeur_url'] = 1;
2766
-	} else {
2767
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2768
-		$uri_ref = $_SERVER['SCRIPT_NAME'];
2769
-		if (
2770
-			!$uri_ref
2771
-			// si on est appele avec un autre ti, on est sans doute en mutu
2772
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2773
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2774
-			// s'en remettre a l'adresse du site. alea jacta est.
2775
-			or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2776
-		) {
2777
-			if (isset($GLOBALS['meta']['adresse_site'])) {
2778
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2779
-				$uri_ref = ($uri_ref['path'] ?? '') . '/';
2780
-			} else {
2781
-				$uri_ref = '';
2782
-			}
2783
-		}
2784
-		if (!$uri or !$uri_ref) {
2785
-			$GLOBALS['profondeur_url'] = 0;
2786
-		} else {
2787
-			$GLOBALS['profondeur_url'] = max(
2788
-				0,
2789
-				substr_count($uri[0], '/')
2790
-				- substr_count($uri_ref, '/')
2791
-			);
2792
-		}
2793
-	}
2794
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2795
-	if (_FILE_CONNECT) {
2796
-		if (
2797
-			verifier_visiteur() == '0minirezo'
2798
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2799
-			and !isset($_COOKIE['spip_admin'])
2800
-		) {
2801
-			clear_path_cache();
2802
-		}
2803
-	}
2494
+    static $too_late = 0;
2495
+    if ($too_late++) {
2496
+        return;
2497
+    }
2498
+
2499
+    // Declaration des repertoires
2500
+
2501
+    // le nom du repertoire plugins/ activables/desactivables
2502
+    if (!defined('_DIR_PLUGINS')) {
2503
+        define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2504
+    }
2505
+
2506
+    // le nom du repertoire des extensions/ permanentes du core, toujours actives
2507
+    if (!defined('_DIR_PLUGINS_DIST')) {
2508
+        define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2509
+    }
2510
+
2511
+    // le nom du repertoire des librairies
2512
+    if (!defined('_DIR_LIB')) {
2513
+        define('_DIR_LIB', _DIR_RACINE . 'lib/');
2514
+    }
2515
+
2516
+    // répertoire des libs via Composer
2517
+    if (!defined('_DIR_VENDOR')) {
2518
+        define('_DIR_VENDOR', _DIR_RACINE . 'vendor/');
2519
+    }
2520
+
2521
+    if (!defined('_DIR_IMG')) {
2522
+        define('_DIR_IMG', $pa);
2523
+    }
2524
+    if (!defined('_DIR_LOGOS')) {
2525
+        define('_DIR_LOGOS', $pa);
2526
+    }
2527
+    if (!defined('_DIR_IMG_ICONES')) {
2528
+        define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2529
+    }
2530
+
2531
+    if (!defined('_DIR_DUMP')) {
2532
+        define('_DIR_DUMP', $ti . 'dump/');
2533
+    }
2534
+    if (!defined('_DIR_SESSIONS')) {
2535
+        define('_DIR_SESSIONS', $ti . 'sessions/');
2536
+    }
2537
+    if (!defined('_DIR_TRANSFERT')) {
2538
+        define('_DIR_TRANSFERT', $ti . 'upload/');
2539
+    }
2540
+    if (!defined('_DIR_CACHE')) {
2541
+        define('_DIR_CACHE', $ti . 'cache/');
2542
+    }
2543
+    if (!defined('_DIR_CACHE_XML')) {
2544
+        define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2545
+    }
2546
+    if (!defined('_DIR_SKELS')) {
2547
+        define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2548
+    }
2549
+    if (!defined('_DIR_AIDE')) {
2550
+        define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2551
+    }
2552
+    if (!defined('_DIR_TMP')) {
2553
+        define('_DIR_TMP', $ti);
2554
+    }
2555
+
2556
+    if (!defined('_DIR_VAR')) {
2557
+        define('_DIR_VAR', $ta);
2558
+    }
2559
+
2560
+    if (!defined('_DIR_ETC')) {
2561
+        define('_DIR_ETC', $pi);
2562
+    }
2563
+    if (!defined('_DIR_CONNECT')) {
2564
+        define('_DIR_CONNECT', $pi);
2565
+    }
2566
+    if (!defined('_DIR_CHMOD')) {
2567
+        define('_DIR_CHMOD', $pi);
2568
+    }
2569
+
2570
+    if (!isset($GLOBALS['test_dirs'])) {
2571
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
2572
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2573
+    $GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2574
+    }
2575
+
2576
+    // Declaration des fichiers
2577
+
2578
+    if (!defined('_CACHE_PLUGINS_PATH')) {
2579
+        define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2580
+    }
2581
+    if (!defined('_CACHE_PLUGINS_OPT')) {
2582
+        define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2583
+    }
2584
+    if (!defined('_CACHE_PLUGINS_FCT')) {
2585
+        define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2586
+    }
2587
+    if (!defined('_CACHE_PIPELINES')) {
2588
+        define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2589
+    }
2590
+    if (!defined('_CACHE_CHEMIN')) {
2591
+        define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2592
+    }
2593
+
2594
+    # attention .php obligatoire pour ecrire_fichier_securise
2595
+    if (!defined('_FILE_META')) {
2596
+        define('_FILE_META', $ti . 'meta_cache.php');
2597
+    }
2598
+    if (!defined('_DIR_LOG')) {
2599
+        define('_DIR_LOG', _DIR_TMP . 'log/');
2600
+    }
2601
+    if (!defined('_FILE_LOG')) {
2602
+        define('_FILE_LOG', 'spip');
2603
+    }
2604
+    if (!defined('_FILE_LOG_SUFFIX')) {
2605
+        define('_FILE_LOG_SUFFIX', '.log');
2606
+    }
2607
+
2608
+    // Le fichier de connexion a la base de donnees
2609
+    // tient compte des anciennes versions (inc_connect...)
2610
+    if (!defined('_FILE_CONNECT_INS')) {
2611
+        define('_FILE_CONNECT_INS', 'connect');
2612
+    }
2613
+    if (!defined('_FILE_CONNECT')) {
2614
+        define(
2615
+            '_FILE_CONNECT',
2616
+            (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2617
+            : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2618
+            : false))
2619
+        );
2620
+    }
2621
+
2622
+    // Le fichier de reglages des droits
2623
+    if (!defined('_FILE_CHMOD_INS')) {
2624
+        define('_FILE_CHMOD_INS', 'chmod');
2625
+    }
2626
+    if (!defined('_FILE_CHMOD')) {
2627
+        define(
2628
+            '_FILE_CHMOD',
2629
+            (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2630
+            : false)
2631
+        );
2632
+    }
2633
+
2634
+    if (!defined('_FILE_LDAP')) {
2635
+        define('_FILE_LDAP', 'ldap.php');
2636
+    }
2637
+
2638
+    if (!defined('_FILE_TMP_SUFFIX')) {
2639
+        define('_FILE_TMP_SUFFIX', '.tmp.php');
2640
+    }
2641
+    if (!defined('_FILE_CONNECT_TMP')) {
2642
+        define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2643
+    }
2644
+    if (!defined('_FILE_CHMOD_TMP')) {
2645
+        define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2646
+    }
2647
+
2648
+    // Definition des droits d'acces en ecriture
2649
+    if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2650
+        include_once _FILE_CHMOD;
2651
+    }
2652
+
2653
+    // Se mefier des fichiers mal remplis!
2654
+    if (!defined('_SPIP_CHMOD')) {
2655
+        define('_SPIP_CHMOD', 0777);
2656
+    }
2657
+
2658
+    if (!defined('_DEFAULT_CHARSET')) {
2659
+        /** Le charset par défaut lors de l'installation */
2660
+        define('_DEFAULT_CHARSET', 'utf-8');
2661
+    }
2662
+    if (!defined('_ROOT_PLUGINS')) {
2663
+        define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2664
+    }
2665
+    if (!defined('_ROOT_PLUGINS_DIST')) {
2666
+        define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2667
+    }
2668
+    if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2669
+        define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2670
+    }
2671
+
2672
+    // La taille des Log
2673
+    if (!defined('_MAX_LOG')) {
2674
+        define('_MAX_LOG', 100);
2675
+    }
2676
+
2677
+    // Sommes-nous dans l'empire du Mal ?
2678
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
2679
+    if (isset($_SERVER['SERVER_SOFTWARE']) and str_contains($_SERVER['SERVER_SOFTWARE'], '(Win')) {
2680
+        if (!defined('_OS_SERVEUR')) {
2681
+            define('_OS_SERVEUR', 'windows');
2682
+        }
2683
+        if (!defined('_SPIP_LOCK_MODE')) {
2684
+            define('_SPIP_LOCK_MODE', 1);
2685
+        } // utiliser le flock php
2686
+    } else {
2687
+        if (!defined('_OS_SERVEUR')) {
2688
+            define('_OS_SERVEUR', '');
2689
+        }
2690
+        if (!defined('_SPIP_LOCK_MODE')) {
2691
+            define('_SPIP_LOCK_MODE', 1);
2692
+        } // utiliser le flock php
2693
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2694
+    }
2695
+
2696
+    // Langue par defaut
2697
+    if (!defined('_LANGUE_PAR_DEFAUT')) {
2698
+        define('_LANGUE_PAR_DEFAUT', 'fr');
2699
+    }
2700
+
2701
+    //
2702
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
2703
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
2704
+    // pour le rendre surchargeable, on va provoquer un reecriture
2705
+    // systematique du noyau ou une baisse de perfs => a etudier)
2706
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
2707
+
2708
+    // charger tout de suite le path et son cache
2709
+    load_path_cache();
2710
+
2711
+    // *********** traiter les variables ************
2712
+
2713
+    //
2714
+    // Securite
2715
+    //
2716
+
2717
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2718
+    if (isset($_REQUEST['GLOBALS'])) {
2719
+        die();
2720
+    }
2721
+    // nettoyer les magic quotes \' et les caracteres nuls %00
2722
+    spip_desinfecte($_GET);
2723
+    spip_desinfecte($_POST);
2724
+    spip_desinfecte($_COOKIE);
2725
+    spip_desinfecte($_REQUEST);
2726
+
2727
+    // appliquer le cookie_prefix
2728
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
2729
+        include_spip('inc/cookie');
2730
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2731
+    }
2732
+
2733
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2734
+    if (isset($_SERVER['REQUEST_URI'])) {
2735
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2736
+    } else {
2737
+        $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2738
+        if (
2739
+            !empty($_SERVER['QUERY_STRING'])
2740
+            and !strpos($_SERVER['REQUEST_URI'], '?')
2741
+        ) {
2742
+            $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2743
+        }
2744
+    }
2745
+
2746
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2747
+    if (!defined('_RENOUVELLE_ALEA')) {
2748
+        define('_RENOUVELLE_ALEA', 12 * 3600);
2749
+    }
2750
+    if (!defined('_DUREE_COOKIE_ADMIN')) {
2751
+        define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2752
+    }
2753
+
2754
+    // charger les meta si possible et renouveller l'alea au besoin
2755
+    // charge aussi effacer_meta et ecrire_meta
2756
+    $inc_meta = charger_fonction('meta', 'inc');
2757
+    $inc_meta();
2758
+
2759
+    // nombre de repertoires depuis la racine
2760
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2761
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2762
+    // le calcul est faux)
2763
+    if (!_DIR_RESTREINT) {
2764
+        $GLOBALS['profondeur_url'] = 1;
2765
+    } else {
2766
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2767
+        $uri_ref = $_SERVER['SCRIPT_NAME'];
2768
+        if (
2769
+            !$uri_ref
2770
+            // si on est appele avec un autre ti, on est sans doute en mutu
2771
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2772
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2773
+            // s'en remettre a l'adresse du site. alea jacta est.
2774
+            or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2775
+        ) {
2776
+            if (isset($GLOBALS['meta']['adresse_site'])) {
2777
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2778
+                $uri_ref = ($uri_ref['path'] ?? '') . '/';
2779
+            } else {
2780
+                $uri_ref = '';
2781
+            }
2782
+        }
2783
+        if (!$uri or !$uri_ref) {
2784
+            $GLOBALS['profondeur_url'] = 0;
2785
+        } else {
2786
+            $GLOBALS['profondeur_url'] = max(
2787
+                0,
2788
+                substr_count($uri[0], '/')
2789
+                - substr_count($uri_ref, '/')
2790
+            );
2791
+        }
2792
+    }
2793
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2794
+    if (_FILE_CONNECT) {
2795
+        if (
2796
+            verifier_visiteur() == '0minirezo'
2797
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2798
+            and !isset($_COOKIE['spip_admin'])
2799
+        ) {
2800
+            clear_path_cache();
2801
+        }
2802
+    }
2804 2803
 }
2805 2804
 
2806 2805
 /**
@@ -2809,157 +2808,157 @@  discard block
 block discarded – undo
2809 2808
  *
2810 2809
  */
2811 2810
 function spip_initialisation_suite() {
2812
-	static $too_late = 0;
2813
-	if ($too_late++) {
2814
-		return;
2815
-	}
2816
-
2817
-	// taille mini des login
2818
-	if (!defined('_LOGIN_TROP_COURT')) {
2819
-		define('_LOGIN_TROP_COURT', 4);
2820
-	}
2821
-
2822
-	// la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2823
-	#if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2824
-	#if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2825
-	#if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2826
-
2827
-	// la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2828
-	#if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2829
-	#if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2830
-	#if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2831
-	#if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2832
-
2833
-	if (!defined('_PASS_LONGUEUR_MINI')) {
2834
-		define('_PASS_LONGUEUR_MINI', 6);
2835
-	}
2836
-
2837
-	// largeur maximale des images dans l'administration
2838
-	if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2839
-		define('_IMG_ADMIN_MAX_WIDTH', 768);
2840
-	}
2841
-
2842
-	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2843
-	if (!defined('_IMG_QUALITE')) {
2844
-		define('_IMG_QUALITE', 85);
2845
-	} # valeur par defaut
2846
-	if (!defined('_IMG_GD_QUALITE')) {
2847
-		define('_IMG_GD_QUALITE', _IMG_QUALITE);
2848
-	} # surcharge pour la lib GD
2849
-	if (!defined('_IMG_CONVERT_QUALITE')) {
2850
-		define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2851
-	} # surcharge pour imagick en ligne de commande
2852
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2853
-	if (!defined('_IMG_IMAGICK_QUALITE')) {
2854
-		define('_IMG_IMAGICK_QUALITE', 75);
2855
-	} # surcharge pour imagick en PHP
2856
-
2857
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2858
-		define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2859
-	} // poids en octet
2860
-
2861
-	// qq chaines standard
2862
-	if (!defined('_ACCESS_FILE_NAME')) {
2863
-		define('_ACCESS_FILE_NAME', '.htaccess');
2864
-	}
2865
-	if (!defined('_AUTH_USER_FILE')) {
2866
-		define('_AUTH_USER_FILE', '.htpasswd');
2867
-	}
2868
-	if (!defined('_SPIP_DUMP')) {
2869
-		define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2870
-	}
2871
-	if (!defined('_CACHE_RUBRIQUES')) {
2872
-		/** Fichier cache pour le navigateur de rubrique du bandeau */
2873
-		define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2874
-	}
2875
-	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2876
-		/** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2877
-		define('_CACHE_RUBRIQUES_MAX', 500);
2878
-	}
2879
-
2880
-	if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2881
-		/**
2882
-		 * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2883
-		 * @var int Nombre de caractères */
2884
-		define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2885
-	}
2886
-
2887
-	if (!defined('_EXTENSION_SQUELETTES')) {
2888
-		define('_EXTENSION_SQUELETTES', 'html');
2889
-	}
2890
-
2891
-	if (!defined('_DOCTYPE_ECRIRE')) {
2892
-		/** Définit le doctype de l’espace privé */
2893
-		define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2894
-	}
2895
-	if (!defined('_DOCTYPE_AIDE')) {
2896
-		/** Définit le doctype de l’aide en ligne */
2897
-		define(
2898
-			'_DOCTYPE_AIDE',
2899
-			"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2900
-		);
2901
-	}
2902
-
2903
-	if (!defined('_SPIP_SCRIPT')) {
2904
-		/** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2905
-		 * le script de l'espace public, alias index.php */
2906
-		define('_SPIP_SCRIPT', 'spip.php');
2907
-	}
2908
-	if (!defined('_SPIP_PAGE')) {
2909
-		/** Argument page, personalisable en cas de conflit avec un autre script */
2910
-		define('_SPIP_PAGE', 'page');
2911
-	}
2912
-
2913
-	// le script de l'espace prive
2914
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2915
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2916
-	// meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2917
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2918
-		if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2919
-			define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2920
-		} else {
2921
-			define('_SPIP_ECRIRE_SCRIPT', '');
2922
-		}
2923
-	}
2924
-
2925
-
2926
-	if (!defined('_SPIP_AJAX')) {
2927
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2928
-			? 1
2929
-			: (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2930
-	}
2931
-
2932
-	// La requete est-elle en ajax ?
2933
-	if (!defined('_AJAX')) {
2934
-		define(
2935
-			'_AJAX',
2936
-			(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2937
-				or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2938
-				or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2939
-				or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2940
-			)
2941
-			and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient
2942
-		);
2943
-	}
2944
-
2945
-	# nombre de pixels maxi pour calcul de la vignette avec gd
2946
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2947
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2948
-	if (!defined('_IMG_GD_MAX_PIXELS')) {
2949
-		define(
2950
-			'_IMG_GD_MAX_PIXELS',
2951
-			(isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2952
-			? $GLOBALS['meta']['max_taille_vignettes']
2953
-			: 0
2954
-		);
2955
-	}
2956
-
2957
-	// Protocoles a normaliser dans les chaines de langues
2958
-	if (!defined('_PROTOCOLES_STD')) {
2959
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2960
-	}
2961
-
2962
-	init_var_mode();
2811
+    static $too_late = 0;
2812
+    if ($too_late++) {
2813
+        return;
2814
+    }
2815
+
2816
+    // taille mini des login
2817
+    if (!defined('_LOGIN_TROP_COURT')) {
2818
+        define('_LOGIN_TROP_COURT', 4);
2819
+    }
2820
+
2821
+    // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2822
+    #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2823
+    #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2824
+    #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2825
+
2826
+    // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2827
+    #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2828
+    #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2829
+    #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2830
+    #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2831
+
2832
+    if (!defined('_PASS_LONGUEUR_MINI')) {
2833
+        define('_PASS_LONGUEUR_MINI', 6);
2834
+    }
2835
+
2836
+    // largeur maximale des images dans l'administration
2837
+    if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2838
+        define('_IMG_ADMIN_MAX_WIDTH', 768);
2839
+    }
2840
+
2841
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2842
+    if (!defined('_IMG_QUALITE')) {
2843
+        define('_IMG_QUALITE', 85);
2844
+    } # valeur par defaut
2845
+    if (!defined('_IMG_GD_QUALITE')) {
2846
+        define('_IMG_GD_QUALITE', _IMG_QUALITE);
2847
+    } # surcharge pour la lib GD
2848
+    if (!defined('_IMG_CONVERT_QUALITE')) {
2849
+        define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2850
+    } # surcharge pour imagick en ligne de commande
2851
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2852
+    if (!defined('_IMG_IMAGICK_QUALITE')) {
2853
+        define('_IMG_IMAGICK_QUALITE', 75);
2854
+    } # surcharge pour imagick en PHP
2855
+
2856
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2857
+        define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2858
+    } // poids en octet
2859
+
2860
+    // qq chaines standard
2861
+    if (!defined('_ACCESS_FILE_NAME')) {
2862
+        define('_ACCESS_FILE_NAME', '.htaccess');
2863
+    }
2864
+    if (!defined('_AUTH_USER_FILE')) {
2865
+        define('_AUTH_USER_FILE', '.htpasswd');
2866
+    }
2867
+    if (!defined('_SPIP_DUMP')) {
2868
+        define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2869
+    }
2870
+    if (!defined('_CACHE_RUBRIQUES')) {
2871
+        /** Fichier cache pour le navigateur de rubrique du bandeau */
2872
+        define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2873
+    }
2874
+    if (!defined('_CACHE_RUBRIQUES_MAX')) {
2875
+        /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2876
+        define('_CACHE_RUBRIQUES_MAX', 500);
2877
+    }
2878
+
2879
+    if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2880
+        /**
2881
+         * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2882
+         * @var int Nombre de caractères */
2883
+        define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2884
+    }
2885
+
2886
+    if (!defined('_EXTENSION_SQUELETTES')) {
2887
+        define('_EXTENSION_SQUELETTES', 'html');
2888
+    }
2889
+
2890
+    if (!defined('_DOCTYPE_ECRIRE')) {
2891
+        /** Définit le doctype de l’espace privé */
2892
+        define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2893
+    }
2894
+    if (!defined('_DOCTYPE_AIDE')) {
2895
+        /** Définit le doctype de l’aide en ligne */
2896
+        define(
2897
+            '_DOCTYPE_AIDE',
2898
+            "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2899
+        );
2900
+    }
2901
+
2902
+    if (!defined('_SPIP_SCRIPT')) {
2903
+        /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2904
+         * le script de l'espace public, alias index.php */
2905
+        define('_SPIP_SCRIPT', 'spip.php');
2906
+    }
2907
+    if (!defined('_SPIP_PAGE')) {
2908
+        /** Argument page, personalisable en cas de conflit avec un autre script */
2909
+        define('_SPIP_PAGE', 'page');
2910
+    }
2911
+
2912
+    // le script de l'espace prive
2913
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2914
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2915
+    // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2916
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2917
+        if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2918
+            define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2919
+        } else {
2920
+            define('_SPIP_ECRIRE_SCRIPT', '');
2921
+        }
2922
+    }
2923
+
2924
+
2925
+    if (!defined('_SPIP_AJAX')) {
2926
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2927
+            ? 1
2928
+            : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2929
+    }
2930
+
2931
+    // La requete est-elle en ajax ?
2932
+    if (!defined('_AJAX')) {
2933
+        define(
2934
+            '_AJAX',
2935
+            (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2936
+                or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2937
+                or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2938
+                or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2939
+            )
2940
+            and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient
2941
+        );
2942
+    }
2943
+
2944
+    # nombre de pixels maxi pour calcul de la vignette avec gd
2945
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2946
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2947
+    if (!defined('_IMG_GD_MAX_PIXELS')) {
2948
+        define(
2949
+            '_IMG_GD_MAX_PIXELS',
2950
+            (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2951
+            ? $GLOBALS['meta']['max_taille_vignettes']
2952
+            : 0
2953
+        );
2954
+    }
2955
+
2956
+    // Protocoles a normaliser dans les chaines de langues
2957
+    if (!defined('_PROTOCOLES_STD')) {
2958
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2959
+    }
2960
+
2961
+    init_var_mode();
2963 2962
 }
2964 2963
 
2965 2964
 /**
@@ -2993,136 +2992,136 @@  discard block
 block discarded – undo
2993 2992
  * `   var_mode` (calcul ou recalcul).
2994 2993
  */
2995 2994
 function init_var_mode() {
2996
-	static $done = false;
2997
-	if (!$done) {
2998
-		if (isset($_GET['var_mode'])) {
2999
-			$var_mode = explode(',', $_GET['var_mode']);
3000
-			// tout le monde peut calcul/recalcul
3001
-			if (!defined('_VAR_MODE')) {
3002
-				if (in_array('recalcul', $var_mode)) {
3003
-					define('_VAR_MODE', 'recalcul');
3004
-				} elseif (in_array('calcul', $var_mode)) {
3005
-					define('_VAR_MODE', 'calcul');
3006
-				}
3007
-			}
3008
-			$var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
3009
-			if ($var_mode) {
3010
-				include_spip('inc/autoriser');
3011
-				// autoriser preview si preview seulement, et sinon autoriser debug
3012
-				if (
3013
-					autoriser(
3014
-						($_GET['var_mode'] == 'preview')
3015
-						? 'previsualiser'
3016
-						: 'debug'
3017
-					)
3018
-				) {
3019
-					if (in_array('traduction', $var_mode)) {
3020
-						// forcer le calcul pour passer dans traduire
3021
-						if (!defined('_VAR_MODE')) {
3022
-							define('_VAR_MODE', 'calcul');
3023
-						}
3024
-						// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3025
-						if (!defined('_VAR_NOCACHE')) {
3026
-							define('_VAR_NOCACHE', true);
3027
-						}
3028
-						$var_mode = array_diff($var_mode, ['traduction']);
3029
-					}
3030
-					if (in_array('preview', $var_mode)) {
3031
-						// basculer sur les criteres de preview dans les boucles
3032
-						if (!defined('_VAR_PREVIEW')) {
3033
-							define('_VAR_PREVIEW', true);
3034
-						}
3035
-						// forcer le calcul
3036
-						if (!defined('_VAR_MODE')) {
3037
-							define('_VAR_MODE', 'calcul');
3038
-						}
3039
-						// et ne pas enregistrer de cache
3040
-						if (!defined('_VAR_NOCACHE')) {
3041
-							define('_VAR_NOCACHE', true);
3042
-						}
3043
-						$var_mode = array_diff($var_mode, ['preview']);
3044
-					}
3045
-					if (in_array('inclure', $var_mode)) {
3046
-						// forcer le compilo et ignorer les caches existants
3047
-						if (!defined('_VAR_MODE')) {
3048
-							define('_VAR_MODE', 'calcul');
3049
-						}
3050
-						if (!defined('_VAR_INCLURE')) {
3051
-							define('_VAR_INCLURE', true);
3052
-						}
3053
-						// et ne pas enregistrer de cache
3054
-						if (!defined('_VAR_NOCACHE')) {
3055
-							define('_VAR_NOCACHE', true);
3056
-						}
3057
-						$var_mode = array_diff($var_mode, ['inclure']);
3058
-					}
3059
-					if (in_array('urls', $var_mode)) {
3060
-						// forcer le compilo et ignorer les caches existants
3061
-						if (!defined('_VAR_MODE')) {
3062
-							define('_VAR_MODE', 'calcul');
3063
-						}
3064
-						if (!defined('_VAR_URLS')) {
3065
-							define('_VAR_URLS', true);
3066
-						}
3067
-						$var_mode = array_diff($var_mode, ['urls']);
3068
-					}
3069
-					if (in_array('images', $var_mode)) {
3070
-						// forcer le compilo et ignorer les caches existants
3071
-						if (!defined('_VAR_MODE')) {
3072
-							define('_VAR_MODE', 'calcul');
3073
-						}
3074
-						// indiquer qu'on doit recalculer les images
3075
-						if (!defined('_VAR_IMAGES')) {
3076
-							define('_VAR_IMAGES', true);
3077
-						}
3078
-						$var_mode = array_diff($var_mode, ['images']);
3079
-					}
3080
-					if (in_array('debug', $var_mode)) {
3081
-						if (!defined('_VAR_MODE')) {
3082
-							define('_VAR_MODE', 'debug');
3083
-						}
3084
-						// et ne pas enregistrer de cache
3085
-						if (!defined('_VAR_NOCACHE')) {
3086
-							define('_VAR_NOCACHE', true);
3087
-						}
3088
-						$var_mode = array_diff($var_mode, ['debug']);
3089
-					}
3090
-					if (count($var_mode) and !defined('_VAR_MODE')) {
3091
-						define('_VAR_MODE', reset($var_mode));
3092
-					}
3093
-					if (isset($GLOBALS['visiteur_session']['nom'])) {
3094
-						spip_log($GLOBALS['visiteur_session']['nom']
3095
-							. ' ' . _VAR_MODE);
3096
-					}
3097
-				} // pas autorise ?
3098
-				else {
3099
-					// si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3100
-					if (
3101
-						!$GLOBALS['visiteur_session']
3102
-						and !empty($_SERVER['HTTP_HOST'])
3103
-						and !empty($_SERVER['REQUEST_METHOD'])
3104
-						and $_SERVER['REQUEST_METHOD'] === 'GET'
3105
-					) {
3106
-						$self = self('&', true);
3107
-						if (strpos($self, 'page=login') === false) {
3108
-							include_spip('inc/headers');
3109
-							$redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3110
-							redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3111
-						}
3112
-					}
3113
-					// sinon tant pis
3114
-				}
3115
-			}
3116
-		}
3117
-		if (!defined('_VAR_MODE')) {
3118
-			/**
3119
-			 * Indique le mode de calcul ou d'affichage de la page.
3120
-			 * @see init_var_mode()
3121
-			 */
3122
-			define('_VAR_MODE', false);
3123
-		}
3124
-		$done = true;
3125
-	}
2995
+    static $done = false;
2996
+    if (!$done) {
2997
+        if (isset($_GET['var_mode'])) {
2998
+            $var_mode = explode(',', $_GET['var_mode']);
2999
+            // tout le monde peut calcul/recalcul
3000
+            if (!defined('_VAR_MODE')) {
3001
+                if (in_array('recalcul', $var_mode)) {
3002
+                    define('_VAR_MODE', 'recalcul');
3003
+                } elseif (in_array('calcul', $var_mode)) {
3004
+                    define('_VAR_MODE', 'calcul');
3005
+                }
3006
+            }
3007
+            $var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
3008
+            if ($var_mode) {
3009
+                include_spip('inc/autoriser');
3010
+                // autoriser preview si preview seulement, et sinon autoriser debug
3011
+                if (
3012
+                    autoriser(
3013
+                        ($_GET['var_mode'] == 'preview')
3014
+                        ? 'previsualiser'
3015
+                        : 'debug'
3016
+                    )
3017
+                ) {
3018
+                    if (in_array('traduction', $var_mode)) {
3019
+                        // forcer le calcul pour passer dans traduire
3020
+                        if (!defined('_VAR_MODE')) {
3021
+                            define('_VAR_MODE', 'calcul');
3022
+                        }
3023
+                        // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3024
+                        if (!defined('_VAR_NOCACHE')) {
3025
+                            define('_VAR_NOCACHE', true);
3026
+                        }
3027
+                        $var_mode = array_diff($var_mode, ['traduction']);
3028
+                    }
3029
+                    if (in_array('preview', $var_mode)) {
3030
+                        // basculer sur les criteres de preview dans les boucles
3031
+                        if (!defined('_VAR_PREVIEW')) {
3032
+                            define('_VAR_PREVIEW', true);
3033
+                        }
3034
+                        // forcer le calcul
3035
+                        if (!defined('_VAR_MODE')) {
3036
+                            define('_VAR_MODE', 'calcul');
3037
+                        }
3038
+                        // et ne pas enregistrer de cache
3039
+                        if (!defined('_VAR_NOCACHE')) {
3040
+                            define('_VAR_NOCACHE', true);
3041
+                        }
3042
+                        $var_mode = array_diff($var_mode, ['preview']);
3043
+                    }
3044
+                    if (in_array('inclure', $var_mode)) {
3045
+                        // forcer le compilo et ignorer les caches existants
3046
+                        if (!defined('_VAR_MODE')) {
3047
+                            define('_VAR_MODE', 'calcul');
3048
+                        }
3049
+                        if (!defined('_VAR_INCLURE')) {
3050
+                            define('_VAR_INCLURE', true);
3051
+                        }
3052
+                        // et ne pas enregistrer de cache
3053
+                        if (!defined('_VAR_NOCACHE')) {
3054
+                            define('_VAR_NOCACHE', true);
3055
+                        }
3056
+                        $var_mode = array_diff($var_mode, ['inclure']);
3057
+                    }
3058
+                    if (in_array('urls', $var_mode)) {
3059
+                        // forcer le compilo et ignorer les caches existants
3060
+                        if (!defined('_VAR_MODE')) {
3061
+                            define('_VAR_MODE', 'calcul');
3062
+                        }
3063
+                        if (!defined('_VAR_URLS')) {
3064
+                            define('_VAR_URLS', true);
3065
+                        }
3066
+                        $var_mode = array_diff($var_mode, ['urls']);
3067
+                    }
3068
+                    if (in_array('images', $var_mode)) {
3069
+                        // forcer le compilo et ignorer les caches existants
3070
+                        if (!defined('_VAR_MODE')) {
3071
+                            define('_VAR_MODE', 'calcul');
3072
+                        }
3073
+                        // indiquer qu'on doit recalculer les images
3074
+                        if (!defined('_VAR_IMAGES')) {
3075
+                            define('_VAR_IMAGES', true);
3076
+                        }
3077
+                        $var_mode = array_diff($var_mode, ['images']);
3078
+                    }
3079
+                    if (in_array('debug', $var_mode)) {
3080
+                        if (!defined('_VAR_MODE')) {
3081
+                            define('_VAR_MODE', 'debug');
3082
+                        }
3083
+                        // et ne pas enregistrer de cache
3084
+                        if (!defined('_VAR_NOCACHE')) {
3085
+                            define('_VAR_NOCACHE', true);
3086
+                        }
3087
+                        $var_mode = array_diff($var_mode, ['debug']);
3088
+                    }
3089
+                    if (count($var_mode) and !defined('_VAR_MODE')) {
3090
+                        define('_VAR_MODE', reset($var_mode));
3091
+                    }
3092
+                    if (isset($GLOBALS['visiteur_session']['nom'])) {
3093
+                        spip_log($GLOBALS['visiteur_session']['nom']
3094
+                            . ' ' . _VAR_MODE);
3095
+                    }
3096
+                } // pas autorise ?
3097
+                else {
3098
+                    // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3099
+                    if (
3100
+                        !$GLOBALS['visiteur_session']
3101
+                        and !empty($_SERVER['HTTP_HOST'])
3102
+                        and !empty($_SERVER['REQUEST_METHOD'])
3103
+                        and $_SERVER['REQUEST_METHOD'] === 'GET'
3104
+                    ) {
3105
+                        $self = self('&', true);
3106
+                        if (strpos($self, 'page=login') === false) {
3107
+                            include_spip('inc/headers');
3108
+                            $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3109
+                            redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3110
+                        }
3111
+                    }
3112
+                    // sinon tant pis
3113
+                }
3114
+            }
3115
+        }
3116
+        if (!defined('_VAR_MODE')) {
3117
+            /**
3118
+             * Indique le mode de calcul ou d'affichage de la page.
3119
+             * @see init_var_mode()
3120
+             */
3121
+            define('_VAR_MODE', false);
3122
+        }
3123
+        $done = true;
3124
+    }
3126 3125
 }
3127 3126
 
3128 3127
 /**
@@ -3134,16 +3133,16 @@  discard block
 block discarded – undo
3134 3133
  * @param bool $deep = true : appliquer récursivement
3135 3134
 **/
3136 3135
 function spip_desinfecte(&$t, $deep = true) {
3137
-	foreach ($t as $key => $val) {
3138
-		if (is_string($t[$key])) {
3139
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
3140
-		} // traiter aussi les "texte_plus" de article_edit
3141
-		else {
3142
-			if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3143
-				spip_desinfecte($t[$key], $deep);
3144
-			}
3145
-		}
3146
-	}
3136
+    foreach ($t as $key => $val) {
3137
+        if (is_string($t[$key])) {
3138
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
3139
+        } // traiter aussi les "texte_plus" de article_edit
3140
+        else {
3141
+            if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3142
+                spip_desinfecte($t[$key], $deep);
3143
+            }
3144
+        }
3145
+    }
3147 3146
 }
3148 3147
 
3149 3148
 /**
@@ -3156,64 +3155,64 @@  discard block
 block discarded – undo
3156 3155
  * @return string|0|false
3157 3156
 **/
3158 3157
 function verifier_visiteur() {
3159
-	@spip_initialisation_core(
3160
-		(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3161
-		(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3162
-		(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3163
-		(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3164
-	);
3165
-
3166
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
3167
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3168
-	// Attention on separe bien session_nom et nom, pour eviter
3169
-	// les melanges entre donnees SQL et variables plus aleatoires
3170
-	$variables_session = ['session_nom', 'session_email'];
3171
-	foreach ($variables_session as $var) {
3172
-		if (_request($var) !== null) {
3173
-			$init = true;
3174
-			break;
3175
-		}
3176
-	}
3177
-	if (isset($init)) {
3178
-		#@spip_initialisation_suite();
3179
-		$session = charger_fonction('session', 'inc');
3180
-		$session();
3181
-		include_spip('inc/texte');
3182
-		foreach ($variables_session as $var) {
3183
-			if (($a = _request($var)) !== null) {
3184
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
3185
-			}
3186
-		}
3187
-		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3188
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
3189
-		}
3190
-		$session($GLOBALS['visiteur_session']);
3191
-
3192
-		return 0;
3193
-	}
3194
-
3195
-	$h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3196
-	if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3197
-		$session = charger_fonction('session', 'inc');
3198
-		if ($session()) {
3199
-			return $GLOBALS['visiteur_session']['statut'];
3200
-		}
3201
-		if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3202
-			include_spip('inc/auth');
3203
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3204
-		}
3205
-		if ($h) {
3206
-			$GLOBALS['visiteur_session'] = $h;
3207
-
3208
-			return $GLOBALS['visiteur_session']['statut'];
3209
-		}
3210
-	}
3211
-
3212
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
3213
-	include_spip('inc/lang');
3214
-	utiliser_langue_visiteur();
3215
-
3216
-	return false;
3158
+    @spip_initialisation_core(
3159
+        (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3160
+        (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3161
+        (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3162
+        (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3163
+    );
3164
+
3165
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
3166
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3167
+    // Attention on separe bien session_nom et nom, pour eviter
3168
+    // les melanges entre donnees SQL et variables plus aleatoires
3169
+    $variables_session = ['session_nom', 'session_email'];
3170
+    foreach ($variables_session as $var) {
3171
+        if (_request($var) !== null) {
3172
+            $init = true;
3173
+            break;
3174
+        }
3175
+    }
3176
+    if (isset($init)) {
3177
+        #@spip_initialisation_suite();
3178
+        $session = charger_fonction('session', 'inc');
3179
+        $session();
3180
+        include_spip('inc/texte');
3181
+        foreach ($variables_session as $var) {
3182
+            if (($a = _request($var)) !== null) {
3183
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
3184
+            }
3185
+        }
3186
+        if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3187
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
3188
+        }
3189
+        $session($GLOBALS['visiteur_session']);
3190
+
3191
+        return 0;
3192
+    }
3193
+
3194
+    $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3195
+    if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3196
+        $session = charger_fonction('session', 'inc');
3197
+        if ($session()) {
3198
+            return $GLOBALS['visiteur_session']['statut'];
3199
+        }
3200
+        if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3201
+            include_spip('inc/auth');
3202
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3203
+        }
3204
+        if ($h) {
3205
+            $GLOBALS['visiteur_session'] = $h;
3206
+
3207
+            return $GLOBALS['visiteur_session']['statut'];
3208
+        }
3209
+    }
3210
+
3211
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
3212
+    include_spip('inc/lang');
3213
+    utiliser_langue_visiteur();
3214
+
3215
+    return false;
3217 3216
 }
3218 3217
 
3219 3218
 
@@ -3236,21 +3235,21 @@  discard block
 block discarded – undo
3236 3235
  *     - string Langue utilisée.
3237 3236
  **/
3238 3237
 function lang_select($lang = null) {
3239
-	static $pile_langues = [];
3240
-	if (!function_exists('changer_langue')) {
3241
-		include_spip('inc/lang');
3242
-	}
3243
-	if ($lang === null) {
3244
-		$lang = array_pop($pile_langues);
3245
-	} else {
3246
-		array_push($pile_langues, $GLOBALS['spip_lang']);
3247
-	}
3248
-	if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3249
-		return $lang;
3250
-	}
3251
-	changer_langue($lang);
3238
+    static $pile_langues = [];
3239
+    if (!function_exists('changer_langue')) {
3240
+        include_spip('inc/lang');
3241
+    }
3242
+    if ($lang === null) {
3243
+        $lang = array_pop($pile_langues);
3244
+    } else {
3245
+        array_push($pile_langues, $GLOBALS['spip_lang']);
3246
+    }
3247
+    if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3248
+        return $lang;
3249
+    }
3250
+    changer_langue($lang);
3252 3251
 
3253
-	return $lang;
3252
+    return $lang;
3254 3253
 }
3255 3254
 
3256 3255
 /**
@@ -3267,20 +3266,20 @@  discard block
 block discarded – undo
3267 3266
  *     Identifiant de la session
3268 3267
  **/
3269 3268
 function spip_session($force = false) {
3270
-	static $session;
3271
-	if ($force or !isset($session)) {
3272
-		$s = pipeline(
3273
-			'definir_session',
3274
-			$GLOBALS['visiteur_session']
3275
-				? serialize($GLOBALS['visiteur_session'])
3276
-				. '_' . @$_COOKIE['spip_session']
3277
-				: ''
3278
-		);
3279
-		$session = $s ? substr(md5($s), 0, 8) : '';
3280
-	}
3269
+    static $session;
3270
+    if ($force or !isset($session)) {
3271
+        $s = pipeline(
3272
+            'definir_session',
3273
+            $GLOBALS['visiteur_session']
3274
+                ? serialize($GLOBALS['visiteur_session'])
3275
+                . '_' . @$_COOKIE['spip_session']
3276
+                : ''
3277
+        );
3278
+        $session = $s ? substr(md5($s), 0, 8) : '';
3279
+    }
3281 3280
 
3282
-	#spip_log('session: '.$session);
3283
-	return $session;
3281
+    #spip_log('session: '.$session);
3282
+    return $session;
3284 3283
 }
3285 3284
 
3286 3285
 
@@ -3299,9 +3298,9 @@  discard block
 block discarded – undo
3299 3298
  *    Lien sur une icone d'aide
3300 3299
  **/
3301 3300
 function aider($aide = '', $distante = false) {
3302
-	$aider = charger_fonction('aide', 'inc', true);
3301
+    $aider = charger_fonction('aide', 'inc', true);
3303 3302
 
3304
-	return $aider ? $aider($aide, '', [], $distante) : '';
3303
+    return $aider ? $aider($aide, '', [], $distante) : '';
3305 3304
 }
3306 3305
 
3307 3306
 /**
@@ -3311,35 +3310,35 @@  discard block
 block discarded – undo
3311 3310
  */
3312 3311
 function exec_info_dist() {
3313 3312
 
3314
-	include_spip('inc/autoriser');
3315
-	if (autoriser('phpinfos')) {
3316
-		$cookies_masques = ['spip_session', 'PHPSESSID'];
3317
-		$cookies_backup = [];
3318
-		$server_backup = ['HTTP_COOKIE' => $_SERVER['HTTP_COOKIE'] ?? []];
3319
-		$env_backup = ['HTTP_COOKIE' => $_ENV['HTTP_COOKIE'] ?? []];
3320
-		$mask = '******************************';
3321
-		foreach ($cookies_masques as $k) {
3322
-			if (!empty($_COOKIE[$k])) {
3323
-				$cookies_backup[$k] = $_COOKIE[$k];
3324
-				$_SERVER['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_SERVER['HTTP_COOKIE'] ?? []);
3325
-				$_ENV['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_ENV['HTTP_COOKIE'] ?? []);
3326
-				$_COOKIE[$k] = $mask;
3327
-			}
3328
-		}
3329
-		phpinfo();
3330
-		foreach ($cookies_backup as $k => $v) {
3331
-			$_COOKIE[$k] = $v;
3332
-		}
3333
-		foreach ($server_backup as $k => $v) {
3334
-			$_SERVER[$k] = $v;
3335
-		}
3336
-		foreach ($env_backup as $k => $v) {
3337
-			$_ENV[$k] = $v;
3338
-		}
3339
-	} else {
3340
-		include_spip('inc/filtres');
3341
-		sinon_interdire_acces();
3342
-	}
3313
+    include_spip('inc/autoriser');
3314
+    if (autoriser('phpinfos')) {
3315
+        $cookies_masques = ['spip_session', 'PHPSESSID'];
3316
+        $cookies_backup = [];
3317
+        $server_backup = ['HTTP_COOKIE' => $_SERVER['HTTP_COOKIE'] ?? []];
3318
+        $env_backup = ['HTTP_COOKIE' => $_ENV['HTTP_COOKIE'] ?? []];
3319
+        $mask = '******************************';
3320
+        foreach ($cookies_masques as $k) {
3321
+            if (!empty($_COOKIE[$k])) {
3322
+                $cookies_backup[$k] = $_COOKIE[$k];
3323
+                $_SERVER['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_SERVER['HTTP_COOKIE'] ?? []);
3324
+                $_ENV['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_ENV['HTTP_COOKIE'] ?? []);
3325
+                $_COOKIE[$k] = $mask;
3326
+            }
3327
+        }
3328
+        phpinfo();
3329
+        foreach ($cookies_backup as $k => $v) {
3330
+            $_COOKIE[$k] = $v;
3331
+        }
3332
+        foreach ($server_backup as $k => $v) {
3333
+            $_SERVER[$k] = $v;
3334
+        }
3335
+        foreach ($env_backup as $k => $v) {
3336
+            $_ENV[$k] = $v;
3337
+        }
3338
+    } else {
3339
+        include_spip('inc/filtres');
3340
+        sinon_interdire_acces();
3341
+    }
3343 3342
 }
3344 3343
 
3345 3344
 /**
@@ -3359,13 +3358,13 @@  discard block
 block discarded – undo
3359 3358
  *     - string si $message à false.
3360 3359
  **/
3361 3360
 function erreur_squelette($message = '', $lieu = '') {
3362
-	$debusquer = charger_fonction('debusquer', 'public');
3363
-	if (is_array($lieu)) {
3364
-		include_spip('public/compiler');
3365
-		$lieu = reconstruire_contexte_compil($lieu);
3366
-	}
3361
+    $debusquer = charger_fonction('debusquer', 'public');
3362
+    if (is_array($lieu)) {
3363
+        include_spip('public/compiler');
3364
+        $lieu = reconstruire_contexte_compil($lieu);
3365
+    }
3367 3366
 
3368
-	return $debusquer($message, $lieu);
3367
+    return $debusquer($message, $lieu);
3369 3368
 }
3370 3369
 
3371 3370
 /**
@@ -3402,108 +3401,108 @@  discard block
 block discarded – undo
3402 3401
  *     - ou tableau d'information sur le squelette.
3403 3402
  */
3404 3403
 function recuperer_fond($fond, $contexte = [], $options = [], string $connect = '') {
3405
-	if (!function_exists('evaluer_fond')) {
3406
-		include_spip('public/assembler');
3407
-	}
3408
-	// assurer la compat avec l'ancienne syntaxe
3409
-	// (trim etait le 3eme argument, par defaut a true)
3410
-	if (!is_array($options)) {
3411
-		$options = ['trim' => $options];
3412
-	}
3413
-	if (!isset($options['trim'])) {
3414
-		$options['trim'] = true;
3415
-	}
3416
-
3417
-	if (isset($contexte['connect'])) {
3418
-		$connect = $contexte['connect'];
3419
-		unset($contexte['connect']);
3420
-	}
3421
-
3422
-	$texte = '';
3423
-	$pages = [];
3424
-	$lang_select = '';
3425
-	if (!isset($options['etoile']) or !$options['etoile']) {
3426
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
3427
-		if (!isset($contexte['lang'])) {
3428
-			$contexte['lang'] = $GLOBALS['spip_lang'];
3429
-		}
3430
-
3431
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3432
-			$lang_select = lang_select($contexte['lang']);
3433
-		}
3434
-	}
3435
-
3436
-	if (!isset($GLOBALS['_INC_PUBLIC'])) {
3437
-		$GLOBALS['_INC_PUBLIC'] = 0;
3438
-	}
3439
-
3440
-	$GLOBALS['_INC_PUBLIC']++;
3441
-
3442
-	// fix #4235
3443
-	$cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3444
-
3445
-
3446
-	foreach (is_array($fond) ? $fond : [$fond] as $f) {
3447
-		unset($GLOBALS['cache_utilise_session']);	// fix #4235
3448
-
3449
-		$page = evaluer_fond($f, $contexte, $connect);
3450
-		if ($page === '') {
3451
-			$c = $options['compil'] ?? '';
3452
-			$a = ['fichier' => $f];
3453
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3454
-			erreur_squelette($erreur, $c);
3455
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3456
-			$page = ['texte' => '', 'erreur' => $erreur];
3457
-		}
3458
-
3459
-		$page = pipeline('recuperer_fond', [
3460
-			'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3461
-			'data' => $page
3462
-		]);
3463
-		if (isset($options['ajax']) and $options['ajax']) {
3464
-			if (!function_exists('encoder_contexte_ajax')) {
3465
-				include_spip('inc/filtres');
3466
-			}
3467
-			$page['texte'] = encoder_contexte_ajax(
3468
-				array_merge(
3469
-					$contexte,
3470
-					['fond' => $f],
3471
-					($connect ? ['connect' => $connect] : [])
3472
-				),
3473
-				'',
3474
-				$page['texte'],
3475
-				$options['ajax']
3476
-			);
3477
-		}
3478
-
3479
-		if (isset($options['raw']) and $options['raw']) {
3480
-			$pages[] = $page;
3481
-		} else {
3482
-			$texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte'];
3483
-		}
3484
-
3485
-		// contamination de la session appelante, pour les inclusions statiques
3486
-		if (isset($page['invalideurs']['session'])) {
3487
-			$cache_utilise_session_appelant = $page['invalideurs']['session'];
3488
-		}
3489
-	}
3490
-
3491
-	// restaurer le sessionnement du contexte appelant,
3492
-	// éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3493
-	if (isset($cache_utilise_session_appelant)) {
3494
-		$GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3495
-	}
3496
-
3497
-	$GLOBALS['_INC_PUBLIC']--;
3498
-
3499
-	if ($lang_select) {
3500
-		lang_select();
3501
-	}
3502
-	if (isset($options['raw']) and $options['raw']) {
3503
-		return is_array($fond) ? $pages : reset($pages);
3504
-	} else {
3505
-		return $options['trim'] ? ltrim($texte) : $texte;
3506
-	}
3404
+    if (!function_exists('evaluer_fond')) {
3405
+        include_spip('public/assembler');
3406
+    }
3407
+    // assurer la compat avec l'ancienne syntaxe
3408
+    // (trim etait le 3eme argument, par defaut a true)
3409
+    if (!is_array($options)) {
3410
+        $options = ['trim' => $options];
3411
+    }
3412
+    if (!isset($options['trim'])) {
3413
+        $options['trim'] = true;
3414
+    }
3415
+
3416
+    if (isset($contexte['connect'])) {
3417
+        $connect = $contexte['connect'];
3418
+        unset($contexte['connect']);
3419
+    }
3420
+
3421
+    $texte = '';
3422
+    $pages = [];
3423
+    $lang_select = '';
3424
+    if (!isset($options['etoile']) or !$options['etoile']) {
3425
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
3426
+        if (!isset($contexte['lang'])) {
3427
+            $contexte['lang'] = $GLOBALS['spip_lang'];
3428
+        }
3429
+
3430
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3431
+            $lang_select = lang_select($contexte['lang']);
3432
+        }
3433
+    }
3434
+
3435
+    if (!isset($GLOBALS['_INC_PUBLIC'])) {
3436
+        $GLOBALS['_INC_PUBLIC'] = 0;
3437
+    }
3438
+
3439
+    $GLOBALS['_INC_PUBLIC']++;
3440
+
3441
+    // fix #4235
3442
+    $cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3443
+
3444
+
3445
+    foreach (is_array($fond) ? $fond : [$fond] as $f) {
3446
+        unset($GLOBALS['cache_utilise_session']);	// fix #4235
3447
+
3448
+        $page = evaluer_fond($f, $contexte, $connect);
3449
+        if ($page === '') {
3450
+            $c = $options['compil'] ?? '';
3451
+            $a = ['fichier' => $f];
3452
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3453
+            erreur_squelette($erreur, $c);
3454
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3455
+            $page = ['texte' => '', 'erreur' => $erreur];
3456
+        }
3457
+
3458
+        $page = pipeline('recuperer_fond', [
3459
+            'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3460
+            'data' => $page
3461
+        ]);
3462
+        if (isset($options['ajax']) and $options['ajax']) {
3463
+            if (!function_exists('encoder_contexte_ajax')) {
3464
+                include_spip('inc/filtres');
3465
+            }
3466
+            $page['texte'] = encoder_contexte_ajax(
3467
+                array_merge(
3468
+                    $contexte,
3469
+                    ['fond' => $f],
3470
+                    ($connect ? ['connect' => $connect] : [])
3471
+                ),
3472
+                '',
3473
+                $page['texte'],
3474
+                $options['ajax']
3475
+            );
3476
+        }
3477
+
3478
+        if (isset($options['raw']) and $options['raw']) {
3479
+            $pages[] = $page;
3480
+        } else {
3481
+            $texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte'];
3482
+        }
3483
+
3484
+        // contamination de la session appelante, pour les inclusions statiques
3485
+        if (isset($page['invalideurs']['session'])) {
3486
+            $cache_utilise_session_appelant = $page['invalideurs']['session'];
3487
+        }
3488
+    }
3489
+
3490
+    // restaurer le sessionnement du contexte appelant,
3491
+    // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3492
+    if (isset($cache_utilise_session_appelant)) {
3493
+        $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3494
+    }
3495
+
3496
+    $GLOBALS['_INC_PUBLIC']--;
3497
+
3498
+    if ($lang_select) {
3499
+        lang_select();
3500
+    }
3501
+    if (isset($options['raw']) and $options['raw']) {
3502
+        return is_array($fond) ? $pages : reset($pages);
3503
+    } else {
3504
+        return $options['trim'] ? ltrim($texte) : $texte;
3505
+    }
3507 3506
 }
3508 3507
 
3509 3508
 /**
@@ -3513,7 +3512,7 @@  discard block
 block discarded – undo
3513 3512
  * @return string
3514 3513
  */
3515 3514
 function trouve_modele($nom) {
3516
-	return trouver_fond($nom, 'modeles/');
3515
+    return trouver_fond($nom, 'modeles/');
3517 3516
 }
3518 3517
 
3519 3518
 /**
@@ -3529,21 +3528,21 @@  discard block
 block discarded – undo
3529 3528
  * @return array|string
3530 3529
  */
3531 3530
 function trouver_fond($nom, $dir = '', $pathinfo = false) {
3532
-	$f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3533
-	if (!$pathinfo) {
3534
-		return $f;
3535
-	}
3536
-	// renvoyer un tableau detaille si $pathinfo==true
3537
-	$p = pathinfo($f);
3538
-	if (!isset($p['extension']) or !$p['extension']) {
3539
-		$p['extension'] = _EXTENSION_SQUELETTES;
3540
-	}
3541
-	if (!isset($p['extension']) or !$p['filename']) {
3542
-		$p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3543
-	}
3544
-	$p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3531
+    $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3532
+    if (!$pathinfo) {
3533
+        return $f;
3534
+    }
3535
+    // renvoyer un tableau detaille si $pathinfo==true
3536
+    $p = pathinfo($f);
3537
+    if (!isset($p['extension']) or !$p['extension']) {
3538
+        $p['extension'] = _EXTENSION_SQUELETTES;
3539
+    }
3540
+    if (!isset($p['extension']) or !$p['filename']) {
3541
+        $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3542
+    }
3543
+    $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3545 3544
 
3546
-	return $p;
3545
+    return $p;
3547 3546
 }
3548 3547
 
3549 3548
 /**
@@ -3563,21 +3562,21 @@  discard block
 block discarded – undo
3563 3562
  *     Nom de l'exec, sinon chaîne vide.
3564 3563
  **/
3565 3564
 function tester_url_ecrire($nom) {
3566
-	static $exec = [];
3567
-	if (isset($exec[$nom])) {
3568
-		return $exec[$nom];
3569
-	}
3570
-	// tester si c'est une page en squelette
3571
-	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3572
-		return $exec[$nom] = 'fond';
3573
-	} // echafaudage d'un fond !
3574
-	elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3575
-		return $exec[$nom] = 'fond';
3576
-	}
3577
-	// attention, il ne faut pas inclure l'exec ici
3578
-	// car sinon #URL_ECRIRE provoque des inclusions
3579
-	// et des define intrusifs potentiels
3580
-	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3565
+    static $exec = [];
3566
+    if (isset($exec[$nom])) {
3567
+        return $exec[$nom];
3568
+    }
3569
+    // tester si c'est une page en squelette
3570
+    if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3571
+        return $exec[$nom] = 'fond';
3572
+    } // echafaudage d'un fond !
3573
+    elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3574
+        return $exec[$nom] = 'fond';
3575
+    }
3576
+    // attention, il ne faut pas inclure l'exec ici
3577
+    // car sinon #URL_ECRIRE provoque des inclusions
3578
+    // et des define intrusifs potentiels
3579
+    return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3581 3580
 }
3582 3581
 
3583 3582
 /**
@@ -3587,8 +3586,8 @@  discard block
 block discarded – undo
3587 3586
  *     true si la constante _VERSION_HTML n'est pas définie ou égale à html5
3588 3587
  **/
3589 3588
 function html5_permis() {
3590
-	return (!defined('_VERSION_HTML')
3591
-		or _VERSION_HTML !== 'html4');
3589
+    return (!defined('_VERSION_HTML')
3590
+        or _VERSION_HTML !== 'html4');
3592 3591
 }
3593 3592
 
3594 3593
 /**
@@ -3598,30 +3597,30 @@  discard block
 block discarded – undo
3598 3597
  * @return array
3599 3598
  */
3600 3599
 function formats_image_acceptables($gd = null, $svg_allowed = true) {
3601
-	$formats = null;
3602
-	if (!is_null($gd)) {
3603
-		$config = ($gd ? 'gd_formats' : 'formats_graphiques');
3604
-		if (isset($GLOBALS['meta'][$config])) {
3605
-			$formats = $GLOBALS['meta'][$config];
3606
-			$formats = explode(',', $formats);
3607
-			$formats = array_filter($formats);
3608
-			$formats = array_map('trim', $formats);
3609
-		}
3610
-	}
3611
-	if (is_null($formats)) {
3612
-		include_spip('inc/filtres_images_lib_mini');
3613
-		$formats = _image_extensions_acceptees_en_entree();
3614
-	}
3615
-
3616
-	if ($svg_allowed) {
3617
-		if (!in_array('svg', $formats)) {
3618
-			$formats[] = 'svg';
3619
-		}
3620
-	}
3621
-	else {
3622
-		$formats = array_diff($formats, ['svg']);
3623
-	}
3624
-	return $formats;
3600
+    $formats = null;
3601
+    if (!is_null($gd)) {
3602
+        $config = ($gd ? 'gd_formats' : 'formats_graphiques');
3603
+        if (isset($GLOBALS['meta'][$config])) {
3604
+            $formats = $GLOBALS['meta'][$config];
3605
+            $formats = explode(',', $formats);
3606
+            $formats = array_filter($formats);
3607
+            $formats = array_map('trim', $formats);
3608
+        }
3609
+    }
3610
+    if (is_null($formats)) {
3611
+        include_spip('inc/filtres_images_lib_mini');
3612
+        $formats = _image_extensions_acceptees_en_entree();
3613
+    }
3614
+
3615
+    if ($svg_allowed) {
3616
+        if (!in_array('svg', $formats)) {
3617
+            $formats[] = 'svg';
3618
+        }
3619
+    }
3620
+    else {
3621
+        $formats = array_diff($formats, ['svg']);
3622
+    }
3623
+    return $formats;
3625 3624
 }
3626 3625
 
3627 3626
 /**
@@ -3630,20 +3629,20 @@  discard block
 block discarded – undo
3630 3629
  * @return array|bool
3631 3630
  */
3632 3631
 function spip_getimagesize($fichier) {
3633
-	if (!$imagesize = @getimagesize($fichier)) {
3634
-		include_spip('inc/svg');
3635
-		if ($attrs = svg_lire_attributs($fichier)) {
3636
-			[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3637
-			$imagesize = [
3638
-				$width,
3639
-				$height,
3640
-				IMAGETYPE_SVG,
3641
-				"width=\"{$width}\" height=\"{$height}\"",
3642
-				'mime' => 'image/svg+xml'
3643
-			];
3644
-		}
3645
-	}
3646
-	return $imagesize;
3632
+    if (!$imagesize = @getimagesize($fichier)) {
3633
+        include_spip('inc/svg');
3634
+        if ($attrs = svg_lire_attributs($fichier)) {
3635
+            [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3636
+            $imagesize = [
3637
+                $width,
3638
+                $height,
3639
+                IMAGETYPE_SVG,
3640
+                "width=\"{$width}\" height=\"{$height}\"",
3641
+                'mime' => 'image/svg+xml'
3642
+            ];
3643
+        }
3644
+    }
3645
+    return $imagesize;
3647 3646
 }
3648 3647
 
3649 3648
 /**
@@ -3657,19 +3656,19 @@  discard block
 block discarded – undo
3657 3656
  * @param string $statut
3658 3657
  */
3659 3658
 function avertir_auteurs($nom, $message, $statut = '') {
3660
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3661
-	if (
3662
-		!$alertes
3663
-		or !is_array($alertes = unserialize($alertes))
3664
-	) {
3665
-		$alertes = [];
3666
-	}
3659
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3660
+    if (
3661
+        !$alertes
3662
+        or !is_array($alertes = unserialize($alertes))
3663
+    ) {
3664
+        $alertes = [];
3665
+    }
3667 3666
 
3668
-	if (!isset($alertes[$statut])) {
3669
-		$alertes[$statut] = [];
3670
-	}
3671
-	$alertes[$statut][$nom] = $message;
3672
-	ecrire_meta('message_alertes_auteurs', serialize($alertes));
3667
+    if (!isset($alertes[$statut])) {
3668
+        $alertes[$statut] = [];
3669
+    }
3670
+    $alertes[$statut][$nom] = $message;
3671
+    ecrire_meta('message_alertes_auteurs', serialize($alertes));
3673 3672
 }
3674 3673
 
3675 3674
 /**
@@ -3683,10 +3682,10 @@  discard block
 block discarded – undo
3683 3682
  * @return string|string[]
3684 3683
  */
3685 3684
 function spip_sanitize_classname($classes) {
3686
-	if (is_array($classes)) {
3687
-		return array_map('spip_sanitize_classname', $classes);
3688
-	}
3689
-	return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3685
+    if (is_array($classes)) {
3686
+        return array_map('spip_sanitize_classname', $classes);
3687
+    }
3688
+    return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3690 3689
 }
3691 3690
 
3692 3691
 
@@ -3711,32 +3710,32 @@  discard block
 block discarded – undo
3711 3710
  *    Avec operateur : bool.
3712 3711
  **/
3713 3712
 function spip_version_compare($v1, $v2, $op = null) {
3714
-	$v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3715
-	$v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3716
-	$v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3717
-	$v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3718
-
3719
-	$v1 = explode('.', $v1);
3720
-	$v2 = explode('.', $v2);
3721
-	// $v1 est toujours une version, donc sans etoile
3722
-	while (count($v1) < count($v2)) {
3723
-		$v1[] = '0';
3724
-	}
3725
-
3726
-	// $v2 peut etre une borne, donc accepte l'etoile
3727
-	$etoile = false;
3728
-	foreach ($v1 as $k => $v) {
3729
-		if (!isset($v2[$k])) {
3730
-			$v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3731
-		} else {
3732
-			if ($v2[$k] == '*') {
3733
-				$etoile = true;
3734
-				$v2[$k] = $v;
3735
-			}
3736
-		}
3737
-	}
3738
-	$v1 = implode('.', $v1);
3739
-	$v2 = implode('.', $v2);
3740
-
3741
-	return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3713
+    $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3714
+    $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3715
+    $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3716
+    $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3717
+
3718
+    $v1 = explode('.', $v1);
3719
+    $v2 = explode('.', $v2);
3720
+    // $v1 est toujours une version, donc sans etoile
3721
+    while (count($v1) < count($v2)) {
3722
+        $v1[] = '0';
3723
+    }
3724
+
3725
+    // $v2 peut etre une borne, donc accepte l'etoile
3726
+    $etoile = false;
3727
+    foreach ($v1 as $k => $v) {
3728
+        if (!isset($v2[$k])) {
3729
+            $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3730
+        } else {
3731
+            if ($v2[$k] == '*') {
3732
+                $etoile = true;
3733
+                $v2[$k] = $v;
3734
+            }
3735
+        }
3736
+    }
3737
+    $v1 = implode('.', $v1);
3738
+    $v2 = implode('.', $v2);
3739
+
3740
+    return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3742 3741
 }
Please login to merge, or discard this patch.
Spacing   +125 added lines, -126 removed lines patch added patch discarded remove patch
@@ -53,12 +53,12 @@  discard block
 block discarded – undo
53 53
 	if (strlen($dossier) and substr($dossier, -1) != '/') {
54 54
 		$dossier .= '/';
55 55
 	}
56
-	$f = str_replace('/', '_', $dossier) . $nom;
56
+	$f = str_replace('/', '_', $dossier).$nom;
57 57
 
58 58
 	if (function_exists($f)) {
59 59
 		return $f;
60 60
 	}
61
-	if (function_exists($g = $f . '_dist')) {
61
+	if (function_exists($g = $f.'_dist')) {
62 62
 		return $g;
63 63
 	}
64 64
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	// passer en minuscules (cf les balises de formulaires)
80 80
 	// et inclure le fichier
81 81
 	if (
82
-		!$inc = include_spip($dossier . ($d = strtolower($nom)))
82
+		!$inc = include_spip($dossier.($d = strtolower($nom)))
83 83
 		// si le fichier truc/machin/nom.php n'existe pas,
84 84
 		// la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
85 85
 		and strlen(dirname($dossier)) and dirname($dossier) != '.'
@@ -98,19 +98,19 @@  discard block
 block discarded – undo
98 98
 	}
99 99
 
100 100
 	// Echec : message d'erreur
101
-	spip_log("fonction $nom ($f ou $g) indisponible" .
101
+	spip_log("fonction $nom ($f ou $g) indisponible".
102 102
 		($inc ? '' : " (fichier $d absent de $dossier)"));
103 103
 
104 104
 	include_spip('inc/minipres');
105 105
 	echo minipres(
106 106
 		_T('forum_titre_erreur'),
107 107
 		$inc ?
108
-			_T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($f) . '</code>'])
108
+			_T('fonction_introuvable', ['fonction' => '<code>'.spip_htmlentities($f).'</code>'])
109 109
 			. '<br />'
110
-			. _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($g) . '</code>'])
110
+			. _T('fonction_introuvable', ['fonction' => '<code>'.spip_htmlentities($g).'</code>'])
111 111
 			:
112
-			_T('fichier_introuvable', ['fichier' => '<code>' . spip_htmlentities($d) . '</code>']),
113
-		['all_inline' => true,'status' => 404]
112
+			_T('fichier_introuvable', ['fichier' => '<code>'.spip_htmlentities($d).'</code>']),
113
+		['all_inline' => true, 'status' => 404]
114 114
 	);
115 115
 	exit;
116 116
 }
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
  *     - string : chemin du fichier trouvé
157 157
  **/
158 158
 function include_spip($f, $include = true) {
159
-	return find_in_path($f . '.php', '', $include);
159
+	return find_in_path($f.'.php', '', $include);
160 160
 }
161 161
 
162 162
 /**
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
  *     - string : chemin du fichier trouvé
177 177
  **/
178 178
 function require_spip($f) {
179
-	return find_in_path($f . '.php', '', 'required');
179
+	return find_in_path($f.'.php', '', 'required');
180 180
 }
181 181
 
182 182
 
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 		// donc il faut l'inclure "en globals"
194 194
 		if ($f = find_in_path('mes_fonctions.php')) {
195 195
 			global $dossier_squelettes;
196
-			include_once(_ROOT_CWD . $f);
196
+			include_once(_ROOT_CWD.$f);
197 197
 		}
198 198
 
199 199
 		if (@is_readable(_CACHE_PLUGINS_FCT)) {
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 	}
299 299
 
300 300
 	// appliquer notre fonction si elle existe
301
-	$fonc = 'execute_pipeline_' . strtolower($action);
301
+	$fonc = 'execute_pipeline_'.strtolower($action);
302 302
 	if (function_exists($fonc)) {
303 303
 		$val = $fonc($val);
304 304
 	} // plantage ?
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 function spip_log($message = null, $name = null) {
364 364
 	static $pre = [];
365 365
 	static $log;
366
-	preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
366
+	preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string) $name, $regs);
367 367
 	if (!isset($regs[1]) or !$logname = $regs[1]) {
368 368
 		$logname = null;
369 369
 	}
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 		if (!is_string($message)) {
392 392
 			$message = print_r($message, true);
393 393
 		}
394
-		$log($pre[$niveau] . ' ' . $message, $logname);
394
+		$log($pre[$niveau].' '.$message, $logname);
395 395
 	}
396 396
 }
397 397
 
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
 	foreach ($regexp as $r => $e) {
598 598
 		$regexp[$r] = str_replace('[]', '\[\]', preg_replace(',[^\w\d\[\]-],', '', $e));
599 599
 	}
600
-	$regexp = ',^(' . implode('|', $regexp) . '[[]?[]]?)(=.*)?$,';
600
+	$regexp = ',^('.implode('|', $regexp).'[[]?[]]?)(=.*)?$,';
601 601
 	$ajouts = array_flip(explode('|', $c));
602 602
 	$u = is_array($v) ? $v : rawurlencode((string) $v);
603 603
 	$testv = (is_array($v) ? count($v) : strlen((string) $v));
@@ -624,7 +624,7 @@  discard block
 block discarded – undo
624 624
 			// Ajout. Pour une variable, remplacer au meme endroit,
625 625
 			// pour un tableau ce sera fait dans la prochaine boucle
626 626
 			elseif (substr($r[1], -2) != '[]') {
627
-				$url[$n] = $r[1] . '=' . $u;
627
+				$url[$n] = $r[1].'='.$u;
628 628
 				unset($ajouts[$r[1]]);
629 629
 			}
630 630
 			// Pour les tableaux on laisse tomber les valeurs de
@@ -645,11 +645,11 @@  discard block
 block discarded – undo
645 645
 	} elseif ($testv) {
646 646
 		foreach ($ajouts as $k => $n) {
647 647
 			if (!is_array($v)) {
648
-				$url[] = $k . '=' . $u;
648
+				$url[] = $k.'='.$u;
649 649
 			} else {
650
-				$id = (substr($k, -2) == '[]') ? $k : ($k . '[]');
650
+				$id = (substr($k, -2) == '[]') ? $k : ($k.'[]');
651 651
 				foreach ($v as $w) {
652
-					$url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w));
652
+					$url[] = $id.'='.(is_array($w) ? 'Array' : rawurlencode($w));
653 653
 				}
654 654
 			}
655 655
 		}
@@ -660,10 +660,10 @@  discard block
 block discarded – undo
660 660
 
661 661
 	// recomposer l'adresse
662 662
 	if ($url) {
663
-		$a .= '?' . join($sep, $url);
663
+		$a .= '?'.join($sep, $url);
664 664
 	}
665 665
 
666
-	return $a . $ancre;
666
+	return $a.$ancre;
667 667
 }
668 668
 
669 669
 /**
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
 			translitteration($ancre)
694 694
 		);
695 695
 	}
696
-	return $url . (strlen($ancre) ? '#' . $ancre : '');
696
+	return $url.(strlen($ancre) ? '#'.$ancre : '');
697 697
 }
698 698
 
699 699
 /**
@@ -809,7 +809,7 @@  discard block
 block discarded – undo
809 809
  * @return bool
810 810
  */
811 811
 function test_plugin_actif($plugin) {
812
-	return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
812
+	return ($plugin and defined('_DIR_PLUGIN_'.strtoupper($plugin))) ? true : false;
813 813
 }
814 814
 
815 815
 /**
@@ -941,7 +941,7 @@  discard block
 block discarded – undo
941 941
 					$value = interdire_scripts($value, -1);
942 942
 				}
943 943
 				if (!empty($options['class'])) {
944
-					$value = "<span class='" . $options['class'] . "'>$value</span>";
944
+					$value = "<span class='".$options['class']."'>$value</span>";
945 945
 				}
946 946
 				$text = str_replace("@$name@", $value, $text);
947 947
 				unset($args[$name]);
@@ -950,7 +950,7 @@  discard block
 block discarded – undo
950 950
 		// Si des variables n'ont pas ete inserees, le signaler
951 951
 		// (chaines de langues pas a jour)
952 952
 		if ($args) {
953
-			spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
953
+			spip_log("$f:  variables inutilisees ".join(', ', array_keys($args)), _LOG_DEBUG);
954 954
 		}
955 955
 	}
956 956
 
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
 function joli_repertoire($rep) {
975 975
 	$a = substr($rep, 0, 1);
976 976
 	if ($a <> '.' and $a <> '/') {
977
-		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
977
+		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS).$rep;
978 978
 	}
979 979
 	$rep = preg_replace(',(^\.\.\/),', '', $rep);
980 980
 
@@ -1028,7 +1028,7 @@  discard block
 block discarded – undo
1028 1028
 			$p -= ($x * 1000);
1029 1029
 		}
1030 1030
 
1031
-		return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1031
+		return $s.sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1032 1032
 	}
1033 1033
 }
1034 1034
 
@@ -1095,7 +1095,7 @@  discard block
 block discarded – undo
1095 1095
 	if ($taches and count($taches) and !spip_connect()) {
1096 1096
 		return false;
1097 1097
 	}
1098
-	spip_log('cron !', 'jq' . _LOG_DEBUG);
1098
+	spip_log('cron !', 'jq'._LOG_DEBUG);
1099 1099
 	if ($genie = charger_fonction('genie', 'inc', true)) {
1100 1100
 		return $genie($taches);
1101 1101
 	}
@@ -1199,7 +1199,7 @@  discard block
 block discarded – undo
1199 1199
 
1200 1200
 	if ($queue_next_job_time == -1) {
1201 1201
 		if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1202
-			define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1202
+			define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP.'job_queue_next.txt');
1203 1203
 		}
1204 1204
 		// utiliser un cache memoire si dispo
1205 1205
 		if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
@@ -1268,8 +1268,8 @@  discard block
 block discarded – undo
1268 1268
 		$src = '';
1269 1269
 	}
1270 1270
 	if ($script) {
1271
-		$script = ("/*<![CDATA[*/\n" .
1272
-			preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1271
+		$script = ("/*<![CDATA[*/\n".
1272
+			preg_replace(',</([^>]*)>,', '<\/\1>', $script).
1273 1273
 			'/*]]>*/');
1274 1274
 	}
1275 1275
 	if ($noscript) {
@@ -1355,13 +1355,13 @@  discard block
 block discarded – undo
1355 1355
 	if ($path_base == null) {
1356 1356
 		// Chemin standard depuis l'espace public
1357 1357
 		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
1358
-			_DIR_RACINE . ':' .
1359
-			_DIR_RACINE . 'squelettes-dist/:' .
1360
-			_DIR_RACINE . 'prive/:' .
1358
+			_DIR_RACINE.':'.
1359
+			_DIR_RACINE.'squelettes-dist/:'.
1360
+			_DIR_RACINE.'prive/:'.
1361 1361
 			_DIR_RESTREINT;
1362 1362
 		// Ajouter squelettes/
1363
-		if (@is_dir(_DIR_RACINE . 'squelettes')) {
1364
-			$path = _DIR_RACINE . 'squelettes/:' . $path;
1363
+		if (@is_dir(_DIR_RACINE.'squelettes')) {
1364
+			$path = _DIR_RACINE.'squelettes/:'.$path;
1365 1365
 		}
1366 1366
 		foreach (explode(':', $path) as $dir) {
1367 1367
 			if (strlen($dir) and substr($dir, -1) != '/') {
@@ -1373,7 +1373,7 @@  discard block
 block discarded – undo
1373 1373
 		// Et le(s) dossier(s) des squelettes nommes
1374 1374
 		if (strlen($GLOBALS['dossier_squelettes'])) {
1375 1375
 			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1376
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1376
+				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE).$d.'/');
1377 1377
 			}
1378 1378
 		}
1379 1379
 		$GLOBALS['path_sig'] = md5(serialize($path_full));
@@ -1384,7 +1384,7 @@  discard block
 block discarded – undo
1384 1384
 
1385 1385
 	if (is_array($dir_path) or strlen($dir_path)) {
1386 1386
 		$tete = '';
1387
-		if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1387
+		if (reset($path_base) == _DIR_RACINE.'squelettes/') {
1388 1388
 			$tete = array_shift($path_base);
1389 1389
 		}
1390 1390
 		$dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
@@ -1405,7 +1405,7 @@  discard block
 block discarded – undo
1405 1405
 	// Et le(s) dossier(s) des squelettes nommes
1406 1406
 	if (strlen($GLOBALS['dossier_squelettes'])) {
1407 1407
 		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1408
-			array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1408
+			array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE).$d.'/');
1409 1409
 		}
1410 1410
 	}
1411 1411
 
@@ -1476,14 +1476,14 @@  discard block
 block discarded – undo
1476 1476
 	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1477 1477
 	if (
1478 1478
 		preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1479
-		and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1479
+		and $file_svg_generique = substr($file, 0, -strlen($m[0])).'-xx.svg'
1480 1480
 		and $f = find_in_theme("$file_svg_generique")
1481 1481
 	) {
1482
-		if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1482
+		if ($fsize = substr($f, 0, -6).$m[1].'.svg' and file_exists($fsize)) {
1483 1483
 			return $themefiles["$subdir$file"] = $fsize;
1484 1484
 		}
1485 1485
 		else {
1486
-			return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1486
+			return $themefiles["$subdir$file"] = "$f?".$m[1].'px';
1487 1487
 		}
1488 1488
 	}
1489 1489
 
@@ -1493,7 +1493,7 @@  discard block
 block discarded – undo
1493 1493
 			return $themefiles["$subdir$file"] = $f;
1494 1494
 		}
1495 1495
 	}
1496
-	spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1496
+	spip_log("$file introuvable dans le theme prive ".reset($themes), 'theme');
1497 1497
 
1498 1498
 	return $themefiles["$subdir$file"] = '';
1499 1499
 }
@@ -1601,8 +1601,8 @@  discard block
 block discarded – undo
1601 1601
 			return false;
1602 1602
 		}
1603 1603
 		if ($include and !isset($inc[$dirname][$file])) {
1604
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1605
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1604
+			include_once _ROOT_CWD.$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1605
+			$inc[$dirname][$file] = $inc[''][$dirname.$file] = true;
1606 1606
 		}
1607 1607
 
1608 1608
 		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
@@ -1615,14 +1615,14 @@  discard block
 block discarded – undo
1615 1615
 	}
1616 1616
 
1617 1617
 	foreach (creer_chemin() as $dir) {
1618
-		if (!isset($dirs[$a = $dir . $dirname])) {
1619
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1618
+		if (!isset($dirs[$a = $dir.$dirname])) {
1619
+			$dirs[$a] = (is_dir(_ROOT_CWD.$a) || !$a);
1620 1620
 		}
1621 1621
 		if ($dirs[$a]) {
1622
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
1622
+			if (file_exists(_ROOT_CWD.($a .= $file))) {
1623 1623
 				if ($include and !isset($inc[$dirname][$file])) {
1624
-					include_once _ROOT_CWD . $a;
1625
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1624
+					include_once _ROOT_CWD.$a;
1625
+					$inc[$dirname][$file] = $inc[''][$dirname.$file] = true;
1626 1626
 				}
1627 1627
 				if (!defined('_SAUVER_CHEMIN')) {
1628 1628
 					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
@@ -1632,7 +1632,7 @@  discard block
 block discarded – undo
1632 1632
 					define('_SAUVER_CHEMIN', true);
1633 1633
 				}
1634 1634
 
1635
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1635
+				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname.$file] = $a;
1636 1636
 			}
1637 1637
 		}
1638 1638
 	}
@@ -1658,7 +1658,7 @@  discard block
 block discarded – undo
1658 1658
 		define('_SAUVER_CHEMIN', true);
1659 1659
 	}
1660 1660
 
1661
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1661
+	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname.$file] = false;
1662 1662
 }
1663 1663
 
1664 1664
 function clear_path_cache() {
@@ -1728,12 +1728,12 @@  discard block
 block discarded – undo
1728 1728
 	// cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1729 1729
 	// on a pas encore inclus flock.php
1730 1730
 	if (!function_exists('preg_files')) {
1731
-		include_once _ROOT_RESTREINT . 'inc/flock.php';
1731
+		include_once _ROOT_RESTREINT.'inc/flock.php';
1732 1732
 	}
1733 1733
 
1734 1734
 	// Parcourir le chemin
1735 1735
 	foreach (creer_chemin() as $d) {
1736
-		$f = $d . $dir;
1736
+		$f = $d.$dir;
1737 1737
 		if (@is_dir($f)) {
1738 1738
 			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1739 1739
 			foreach ($liste as $chemin) {
@@ -1783,9 +1783,9 @@  discard block
 block discarded – undo
1783 1783
 	if ($type === 'defaut') {
1784 1784
 		$objet = objet_type($quoi);
1785 1785
 		if (
1786
-			$f = charger_fonction('generer_' . $objet . '_url', 'urls', true)
1786
+			$f = charger_fonction('generer_'.$objet.'_url', 'urls', true)
1787 1787
 			// deprecated
1788
-			or $f = charger_fonction('generer_url_' . $objet, 'urls', true)
1788
+			or $f = charger_fonction('generer_url_'.$objet, 'urls', true)
1789 1789
 		) {
1790 1790
 			return $f;
1791 1791
 		}
@@ -1798,7 +1798,7 @@  discard block
 block discarded – undo
1798 1798
 	}
1799 1799
 
1800 1800
 	// inclure le module d'url
1801
-	include_spip('urls/' . $url_type);
1801
+	include_spip('urls/'.$url_type);
1802 1802
 
1803 1803
 	switch ($quoi) {
1804 1804
 		case 'page':
@@ -1951,8 +1951,8 @@  discard block
 block discarded – undo
1951 1951
 	include_spip('base/connect_sql');
1952 1952
 	$id_type = id_table_objet($entite, $public);
1953 1953
 
1954
-	return _DIR_RACINE . get_spip_script('./')
1955
-	. '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1954
+	return _DIR_RACINE.get_spip_script('./')
1955
+	. '?'._SPIP_PAGE."=$entite&$id_type=$i&connect=$public"
1956 1956
 	. (!$args ? '' : "&$args")
1957 1957
 	. (!$ancre ? '' : "#$ancre");
1958 1958
 }
@@ -2127,7 +2127,7 @@  discard block
 block discarded – undo
2127 2127
 				!empty($_SERVER['QUERY_STRING'])
2128 2128
 				and !strpos($_SERVER['REQUEST_URI'], '?')
2129 2129
 			) {
2130
-				$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2130
+				$GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
2131 2131
 			}
2132 2132
 		}
2133 2133
 	}
@@ -2165,9 +2165,9 @@  discard block
 block discarded – undo
2165 2165
 		array_shift($myself);
2166 2166
 		$myself = implode('/', $myself);
2167 2167
 	}
2168
-	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2168
+	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)).'/';
2169 2169
 
2170
-	$url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2170
+	$url = $http.'://'.rtrim($host, '/').'/'.ltrim($url, '/');
2171 2171
 
2172 2172
 	return $url;
2173 2173
 }
@@ -2206,16 +2206,16 @@  discard block
 block discarded – undo
2206 2206
 function generer_url_ecrire(?string $script = '', $args = '', $no_entities = false, $rel = false) {
2207 2207
 	$script ??= '';
2208 2208
 	if (!$rel) {
2209
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2209
+		$rel = url_de_base()._DIR_RESTREINT_ABS._SPIP_ECRIRE_SCRIPT;
2210 2210
 	} else {
2211 2211
 		if (!is_string($rel)) {
2212
-			$rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
2212
+			$rel = _DIR_RESTREINT ?: './'._SPIP_ECRIRE_SCRIPT;
2213 2213
 		}
2214 2214
 	}
2215 2215
 
2216 2216
 	[$script, $ancre] = array_pad(explode('#', $script), 2, null);
2217 2217
 	if ($script and ($script <> 'accueil' or $rel)) {
2218
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
2218
+		$args = "?exec=$script".(!$args ? '' : "&$args");
2219 2219
 	} elseif ($args) {
2220 2220
 		$args = "?$args";
2221 2221
 	}
@@ -2223,7 +2223,7 @@  discard block
 block discarded – undo
2223 2223
 		$args .= "#$ancre";
2224 2224
 	}
2225 2225
 
2226
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2226
+	return $rel.($no_entities ? $args : str_replace('&', '&amp;', $args));
2227 2227
 }
2228 2228
 
2229 2229
 //
@@ -2305,10 +2305,10 @@  discard block
 block discarded – undo
2305 2305
 			$action = parametre_url($action, _SPIP_PAGE, $script, '&');
2306 2306
 		}
2307 2307
 		if ($args) {
2308
-			$action .= (strpos($action, '?') !== false ? '&' : '?') . $args;
2308
+			$action .= (strpos($action, '?') !== false ? '&' : '?').$args;
2309 2309
 		}
2310 2310
 		// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2311
-		$url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2311
+		$url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/').preg_replace(',^/[.]/,', '/', "/$action"));
2312 2312
 	}
2313 2313
 
2314 2314
 	if (!$no_entities) {
@@ -2320,7 +2320,7 @@  discard block
 block discarded – undo
2320 2320
 
2321 2321
 function generer_url_prive($script, $args = '', $no_entities = false) {
2322 2322
 
2323
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2323
+	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS.'prive.php');
2324 2324
 }
2325 2325
 
2326 2326
 // Pour les formulaires en methode POST,
@@ -2355,8 +2355,7 @@  discard block
 block discarded – undo
2355 2355
 	. "><div>\n"
2356 2356
 	. "<input type='hidden' name='exec' value='$script1' />"
2357 2357
 	. $corps
2358
-	. (!$submit ? '' :
2359
-		("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2358
+	. (!$submit ? '' : ("<div style='text-align: ".$GLOBALS['spip_lang_right']."'><input class='fondo submit btn' type='submit' value=\"".entites_html($submit).'" /></div>'))
2360 2359
 	. "</div></form>\n";
2361 2360
 }
2362 2361
 
@@ -2381,14 +2380,14 @@  discard block
 block discarded – undo
2381 2380
 		? generer_url_ecrire(_request('exec'))
2382 2381
 		: generer_url_public();
2383 2382
 
2384
-	return "\n<form action='" .
2385
-	$h .
2386
-	"'" .
2387
-	$atts .
2388
-	">\n" .
2389
-	'<div>' .
2390
-	"\n<input type='hidden' name='action' value='$script' />" .
2391
-	$corps .
2383
+	return "\n<form action='".
2384
+	$h.
2385
+	"'".
2386
+	$atts.
2387
+	">\n".
2388
+	'<div>'.
2389
+	"\n<input type='hidden' name='action' value='$script' />".
2390
+	$corps.
2392 2391
 	'</div></form>';
2393 2392
 }
2394 2393
 
@@ -2416,7 +2415,7 @@  discard block
 block discarded – undo
2416 2415
 		: generer_url_public('', '', false, false);
2417 2416
 	$url = parametre_url($url, 'action', $script);
2418 2417
 	if ($args) {
2419
-		$url .= quote_amp('&' . $args);
2418
+		$url .= quote_amp('&'.$args);
2420 2419
 	}
2421 2420
 
2422 2421
 	if ($no_entities) {
@@ -2450,9 +2449,9 @@  discard block
 block discarded – undo
2450 2449
 	}
2451 2450
 	$url =
2452 2451
 		(($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './')
2453
-	. $script . '/'
2452
+	. $script.'/'
2454 2453
 	. ($path ? trim($path, '/') : '')
2455
-	. ($args ? '?' . quote_amp($args) : '');
2454
+	. ($args ? '?'.quote_amp($args) : '');
2456 2455
 
2457 2456
 	if ($no_entities) {
2458 2457
 		$url = str_replace('&amp;', '&', $url);
@@ -2501,22 +2500,22 @@  discard block
 block discarded – undo
2501 2500
 
2502 2501
 	// le nom du repertoire plugins/ activables/desactivables
2503 2502
 	if (!defined('_DIR_PLUGINS')) {
2504
-		define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2503
+		define('_DIR_PLUGINS', _DIR_RACINE.'plugins/');
2505 2504
 	}
2506 2505
 
2507 2506
 	// le nom du repertoire des extensions/ permanentes du core, toujours actives
2508 2507
 	if (!defined('_DIR_PLUGINS_DIST')) {
2509
-		define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2508
+		define('_DIR_PLUGINS_DIST', _DIR_RACINE.'plugins-dist/');
2510 2509
 	}
2511 2510
 
2512 2511
 	// le nom du repertoire des librairies
2513 2512
 	if (!defined('_DIR_LIB')) {
2514
-		define('_DIR_LIB', _DIR_RACINE . 'lib/');
2513
+		define('_DIR_LIB', _DIR_RACINE.'lib/');
2515 2514
 	}
2516 2515
 
2517 2516
 	// répertoire des libs via Composer
2518 2517
 	if (!defined('_DIR_VENDOR')) {
2519
-		define('_DIR_VENDOR', _DIR_RACINE . 'vendor/');
2518
+		define('_DIR_VENDOR', _DIR_RACINE.'vendor/');
2520 2519
 	}
2521 2520
 
2522 2521
 	if (!defined('_DIR_IMG')) {
@@ -2526,29 +2525,29 @@  discard block
 block discarded – undo
2526 2525
 		define('_DIR_LOGOS', $pa);
2527 2526
 	}
2528 2527
 	if (!defined('_DIR_IMG_ICONES')) {
2529
-		define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2528
+		define('_DIR_IMG_ICONES', _DIR_LOGOS.'icones/');
2530 2529
 	}
2531 2530
 
2532 2531
 	if (!defined('_DIR_DUMP')) {
2533
-		define('_DIR_DUMP', $ti . 'dump/');
2532
+		define('_DIR_DUMP', $ti.'dump/');
2534 2533
 	}
2535 2534
 	if (!defined('_DIR_SESSIONS')) {
2536
-		define('_DIR_SESSIONS', $ti . 'sessions/');
2535
+		define('_DIR_SESSIONS', $ti.'sessions/');
2537 2536
 	}
2538 2537
 	if (!defined('_DIR_TRANSFERT')) {
2539
-		define('_DIR_TRANSFERT', $ti . 'upload/');
2538
+		define('_DIR_TRANSFERT', $ti.'upload/');
2540 2539
 	}
2541 2540
 	if (!defined('_DIR_CACHE')) {
2542
-		define('_DIR_CACHE', $ti . 'cache/');
2541
+		define('_DIR_CACHE', $ti.'cache/');
2543 2542
 	}
2544 2543
 	if (!defined('_DIR_CACHE_XML')) {
2545
-		define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2544
+		define('_DIR_CACHE_XML', _DIR_CACHE.'xml/');
2546 2545
 	}
2547 2546
 	if (!defined('_DIR_SKELS')) {
2548
-		define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2547
+		define('_DIR_SKELS', _DIR_CACHE.'skel/');
2549 2548
 	}
2550 2549
 	if (!defined('_DIR_AIDE')) {
2551
-		define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2550
+		define('_DIR_AIDE', _DIR_CACHE.'aide/');
2552 2551
 	}
2553 2552
 	if (!defined('_DIR_TMP')) {
2554 2553
 		define('_DIR_TMP', $ti);
@@ -2577,27 +2576,27 @@  discard block
 block discarded – undo
2577 2576
 	// Declaration des fichiers
2578 2577
 
2579 2578
 	if (!defined('_CACHE_PLUGINS_PATH')) {
2580
-		define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2579
+		define('_CACHE_PLUGINS_PATH', _DIR_CACHE.'charger_plugins_chemins.php');
2581 2580
 	}
2582 2581
 	if (!defined('_CACHE_PLUGINS_OPT')) {
2583
-		define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2582
+		define('_CACHE_PLUGINS_OPT', _DIR_CACHE.'charger_plugins_options.php');
2584 2583
 	}
2585 2584
 	if (!defined('_CACHE_PLUGINS_FCT')) {
2586
-		define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2585
+		define('_CACHE_PLUGINS_FCT', _DIR_CACHE.'charger_plugins_fonctions.php');
2587 2586
 	}
2588 2587
 	if (!defined('_CACHE_PIPELINES')) {
2589
-		define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2588
+		define('_CACHE_PIPELINES', _DIR_CACHE.'charger_pipelines.php');
2590 2589
 	}
2591 2590
 	if (!defined('_CACHE_CHEMIN')) {
2592
-		define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2591
+		define('_CACHE_CHEMIN', _DIR_CACHE.'chemin.txt');
2593 2592
 	}
2594 2593
 
2595 2594
 	# attention .php obligatoire pour ecrire_fichier_securise
2596 2595
 	if (!defined('_FILE_META')) {
2597
-		define('_FILE_META', $ti . 'meta_cache.php');
2596
+		define('_FILE_META', $ti.'meta_cache.php');
2598 2597
 	}
2599 2598
 	if (!defined('_DIR_LOG')) {
2600
-		define('_DIR_LOG', _DIR_TMP . 'log/');
2599
+		define('_DIR_LOG', _DIR_TMP.'log/');
2601 2600
 	}
2602 2601
 	if (!defined('_FILE_LOG')) {
2603 2602
 		define('_FILE_LOG', 'spip');
@@ -2614,8 +2613,8 @@  discard block
 block discarded – undo
2614 2613
 	if (!defined('_FILE_CONNECT')) {
2615 2614
 		define(
2616 2615
 			'_FILE_CONNECT',
2617
-			(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2618
-			: (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2616
+			(@is_readable($f = _DIR_CONNECT._FILE_CONNECT_INS.'.php') ? $f
2617
+			: (@is_readable($f = _DIR_RESTREINT.'inc_connect.php') ? $f
2619 2618
 			: false))
2620 2619
 		);
2621 2620
 	}
@@ -2627,7 +2626,7 @@  discard block
 block discarded – undo
2627 2626
 	if (!defined('_FILE_CHMOD')) {
2628 2627
 		define(
2629 2628
 			'_FILE_CHMOD',
2630
-			(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2629
+			(@is_readable($f = _DIR_CHMOD._FILE_CHMOD_INS.'.php') ? $f
2631 2630
 			: false)
2632 2631
 		);
2633 2632
 	}
@@ -2640,10 +2639,10 @@  discard block
 block discarded – undo
2640 2639
 		define('_FILE_TMP_SUFFIX', '.tmp.php');
2641 2640
 	}
2642 2641
 	if (!defined('_FILE_CONNECT_TMP')) {
2643
-		define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2642
+		define('_FILE_CONNECT_TMP', _DIR_CONNECT._FILE_CONNECT_INS._FILE_TMP_SUFFIX);
2644 2643
 	}
2645 2644
 	if (!defined('_FILE_CHMOD_TMP')) {
2646
-		define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2645
+		define('_FILE_CHMOD_TMP', _DIR_CHMOD._FILE_CHMOD_INS._FILE_TMP_SUFFIX);
2647 2646
 	}
2648 2647
 
2649 2648
 	// Definition des droits d'acces en ecriture
@@ -2661,13 +2660,13 @@  discard block
 block discarded – undo
2661 2660
 		define('_DEFAULT_CHARSET', 'utf-8');
2662 2661
 	}
2663 2662
 	if (!defined('_ROOT_PLUGINS')) {
2664
-		define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2663
+		define('_ROOT_PLUGINS', _ROOT_RACINE.'plugins/');
2665 2664
 	}
2666 2665
 	if (!defined('_ROOT_PLUGINS_DIST')) {
2667
-		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2666
+		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE.'plugins-dist/');
2668 2667
 	}
2669 2668
 	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2670
-		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2669
+		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE.str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2671 2670
 	}
2672 2671
 
2673 2672
 	// La taille des Log
@@ -2704,7 +2703,7 @@  discard block
 block discarded – undo
2704 2703
 	// (non surchargeable en l'etat ; attention si on utilise include_spip()
2705 2704
 	// pour le rendre surchargeable, on va provoquer un reecriture
2706 2705
 	// systematique du noyau ou une baisse de perfs => a etudier)
2707
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
2706
+	include_once _ROOT_RESTREINT.'inc/flock.php';
2708 2707
 
2709 2708
 	// charger tout de suite le path et son cache
2710 2709
 	load_path_cache();
@@ -2740,7 +2739,7 @@  discard block
 block discarded – undo
2740 2739
 			!empty($_SERVER['QUERY_STRING'])
2741 2740
 			and !strpos($_SERVER['REQUEST_URI'], '?')
2742 2741
 		) {
2743
-			$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2742
+			$GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
2744 2743
 		}
2745 2744
 	}
2746 2745
 
@@ -2776,7 +2775,7 @@  discard block
 block discarded – undo
2776 2775
 		) {
2777 2776
 			if (isset($GLOBALS['meta']['adresse_site'])) {
2778 2777
 				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2779
-				$uri_ref = ($uri_ref['path'] ?? '') . '/';
2778
+				$uri_ref = ($uri_ref['path'] ?? '').'/';
2780 2779
 			} else {
2781 2780
 				$uri_ref = '';
2782 2781
 			}
@@ -2870,7 +2869,7 @@  discard block
 block discarded – undo
2870 2869
 	}
2871 2870
 	if (!defined('_CACHE_RUBRIQUES')) {
2872 2871
 		/** Fichier cache pour le navigateur de rubrique du bandeau */
2873
-		define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2872
+		define('_CACHE_RUBRIQUES', _DIR_TMP.'menu-rubriques-cache.txt');
2874 2873
 	}
2875 2874
 	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2876 2875
 		/** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
@@ -3092,7 +3091,7 @@  discard block
 block discarded – undo
3092 3091
 					}
3093 3092
 					if (isset($GLOBALS['visiteur_session']['nom'])) {
3094 3093
 						spip_log($GLOBALS['visiteur_session']['nom']
3095
-							. ' ' . _VAR_MODE);
3094
+							. ' '._VAR_MODE);
3096 3095
 					}
3097 3096
 				} // pas autorise ?
3098 3097
 				else {
@@ -3107,7 +3106,7 @@  discard block
 block discarded – undo
3107 3106
 						if (strpos($self, 'page=login') === false) {
3108 3107
 							include_spip('inc/headers');
3109 3108
 							$redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3110
-							redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3109
+							redirige_par_entete(generer_url_public('login', 'url='.rawurlencode($redirect), true));
3111 3110
 						}
3112 3111
 					}
3113 3112
 					// sinon tant pis
@@ -3157,10 +3156,10 @@  discard block
 block discarded – undo
3157 3156
 **/
3158 3157
 function verifier_visiteur() {
3159 3158
 	@spip_initialisation_core(
3160
-		(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3161
-		(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3162
-		(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3163
-		(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3159
+		(_DIR_RACINE._NOM_PERMANENTS_INACCESSIBLES),
3160
+		(_DIR_RACINE._NOM_PERMANENTS_ACCESSIBLES),
3161
+		(_DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES),
3162
+		(_DIR_RACINE._NOM_TEMPORAIRES_ACCESSIBLES)
3164 3163
 	);
3165 3164
 
3166 3165
 	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
@@ -3193,7 +3192,7 @@  discard block
 block discarded – undo
3193 3192
 	}
3194 3193
 
3195 3194
 	$h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3196
-	if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3195
+	if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'].'_session'])) {
3197 3196
 		$session = charger_fonction('session', 'inc');
3198 3197
 		if ($session()) {
3199 3198
 			return $GLOBALS['visiteur_session']['statut'];
@@ -3273,7 +3272,7 @@  discard block
 block discarded – undo
3273 3272
 			'definir_session',
3274 3273
 			$GLOBALS['visiteur_session']
3275 3274
 				? serialize($GLOBALS['visiteur_session'])
3276
-				. '_' . @$_COOKIE['spip_session']
3275
+				. '_'.@$_COOKIE['spip_session']
3277 3276
 				: ''
3278 3277
 		);
3279 3278
 		$session = $s ? substr(md5($s), 0, 8) : '';
@@ -3321,8 +3320,8 @@  discard block
 block discarded – undo
3321 3320
 		foreach ($cookies_masques as $k) {
3322 3321
 			if (!empty($_COOKIE[$k])) {
3323 3322
 				$cookies_backup[$k] = $_COOKIE[$k];
3324
-				$_SERVER['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_SERVER['HTTP_COOKIE'] ?? []);
3325
-				$_ENV['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_ENV['HTTP_COOKIE'] ?? []);
3323
+				$_SERVER['HTTP_COOKIE'] = str_replace("$k=".$_COOKIE[$k], "$k=$mask", $_SERVER['HTTP_COOKIE'] ?? []);
3324
+				$_ENV['HTTP_COOKIE'] = str_replace("$k=".$_COOKIE[$k], "$k=$mask", $_ENV['HTTP_COOKIE'] ?? []);
3326 3325
 				$_COOKIE[$k] = $mask;
3327 3326
 			}
3328 3327
 		}
@@ -3440,11 +3439,11 @@  discard block
 block discarded – undo
3440 3439
 	$GLOBALS['_INC_PUBLIC']++;
3441 3440
 
3442 3441
 	// fix #4235
3443
-	$cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3442
+	$cache_utilise_session_appelant = ($GLOBALS['cache_utilise_session'] ?? null);
3444 3443
 
3445 3444
 
3446 3445
 	foreach (is_array($fond) ? $fond : [$fond] as $f) {
3447
-		unset($GLOBALS['cache_utilise_session']);	// fix #4235
3446
+		unset($GLOBALS['cache_utilise_session']); // fix #4235
3448 3447
 
3449 3448
 		$page = evaluer_fond($f, $contexte, $connect);
3450 3449
 		if ($page === '') {
@@ -3529,7 +3528,7 @@  discard block
 block discarded – undo
3529 3528
  * @return array|string
3530 3529
  */
3531 3530
 function trouver_fond($nom, $dir = '', $pathinfo = false) {
3532
-	$f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3531
+	$f = find_in_path($nom.'.'._EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/').'/' : '');
3533 3532
 	if (!$pathinfo) {
3534 3533
 		return $f;
3535 3534
 	}
Please login to merge, or discard this patch.
ecrire/inc/securiser_action.php 1 patch
Indentation   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -16,10 +16,10 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Actions
17 17
  **/
18 18
 
19
- use Spip\Chiffrer\SpipCles;
19
+    use Spip\Chiffrer\SpipCles;
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 /**
@@ -52,19 +52,19 @@  discard block
 block discarded – undo
52 52
  * @return array|string
53 53
  */
54 54
 function inc_securiser_action_dist($action = '', $arg = '', $redirect = '', $mode = false, $att = '', $public = false) {
55
-	if ($action) {
56
-		return securiser_action_auteur($action, $arg, $redirect, $mode, $att, $public);
57
-	} else {
58
-		$arg = _request('arg');
59
-		$hash = _request('hash');
60
-		$action = _request('action') ?: _request('formulaire_action');
61
-		if ($a = verifier_action_auteur("$action-$arg", $hash)) {
62
-			return $arg;
63
-		}
64
-		include_spip('inc/minipres');
65
-		echo minipres();
66
-		exit;
67
-	}
55
+    if ($action) {
56
+        return securiser_action_auteur($action, $arg, $redirect, $mode, $att, $public);
57
+    } else {
58
+        $arg = _request('arg');
59
+        $hash = _request('hash');
60
+        $action = _request('action') ?: _request('formulaire_action');
61
+        if ($a = verifier_action_auteur("$action-$arg", $hash)) {
62
+            return $arg;
63
+        }
64
+        include_spip('inc/minipres');
65
+        echo minipres();
66
+        exit;
67
+    }
68 68
 }
69 69
 
70 70
 /**
@@ -83,29 +83,29 @@  discard block
 block discarded – undo
83 83
  */
84 84
 function demander_confirmation_avant_action($titre, $titre_bouton, $url_action = null) {
85 85
 
86
-	if (!$url_action) {
87
-		$url_action = self();
88
-		$action = _request('action');
89
-		$url_action = parametre_url($url_action, 'action', $action, '&');
90
-	}
91
-	else {
92
-		$action = parametre_url($url_action, 'action');
93
-	}
94
-
95
-	$arg = parametre_url($url_action, 'arg');
96
-	$confirm = md5("$action:$arg:" . realpath(__FILE__));
97
-	if (_request('confirm_action') === $confirm) {
98
-		return true;
99
-	}
100
-
101
-	$url_confirm = parametre_url($url_action, 'confirm_action', $confirm, '&');
102
-	include_spip('inc/filtres');
103
-	$bouton_action = bouton_action($titre_bouton, $url_confirm);
104
-	$corps = "<div style='text-align:center;'>$bouton_action</div>";
105
-
106
-	include_spip('inc/minipres');
107
-	echo minipres($titre, $corps);
108
-	exit;
86
+    if (!$url_action) {
87
+        $url_action = self();
88
+        $action = _request('action');
89
+        $url_action = parametre_url($url_action, 'action', $action, '&');
90
+    }
91
+    else {
92
+        $action = parametre_url($url_action, 'action');
93
+    }
94
+
95
+    $arg = parametre_url($url_action, 'arg');
96
+    $confirm = md5("$action:$arg:" . realpath(__FILE__));
97
+    if (_request('confirm_action') === $confirm) {
98
+        return true;
99
+    }
100
+
101
+    $url_confirm = parametre_url($url_action, 'confirm_action', $confirm, '&');
102
+    include_spip('inc/filtres');
103
+    $bouton_action = bouton_action($titre_bouton, $url_confirm);
104
+    $corps = "<div style='text-align:center;'>$bouton_action</div>";
105
+
106
+    include_spip('inc/minipres');
107
+    echo minipres($titre, $corps);
108
+    exit;
109 109
 }
110 110
 
111 111
 /**
@@ -136,34 +136,34 @@  discard block
 block discarded – undo
136 136
  */
137 137
 function securiser_action_auteur($action, $arg, $redirect = '', $mode = false, $att = '', $public = false) {
138 138
 
139
-	// mode URL ou array
140
-	if (!is_string($mode)) {
141
-		$hash = calculer_action_auteur("$action-$arg", is_numeric($att) ? $att : null);
142
-
143
-		$r = rawurlencode($redirect);
144
-		if ($mode === -1) {
145
-			return ['action' => $action, 'arg' => $arg, 'hash' => $hash];
146
-		} else {
147
-			return generer_url_action(
148
-				$action,
149
-				'arg=' . rawurlencode($arg) . "&hash=$hash" . (!$r ? '' : "&redirect=$r"),
150
-				$mode,
151
-				$public
152
-			);
153
-		}
154
-	}
155
-
156
-	// mode formulaire
157
-	$hash = calculer_action_auteur("$action-$arg");
158
-	$att .= " style='margin: 0px; border: 0px'";
159
-	if ($redirect) {
160
-		$redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", '&#39;', $redirect) . "' />";
161
-	}
162
-	$mode .= $redirect . "
139
+    // mode URL ou array
140
+    if (!is_string($mode)) {
141
+        $hash = calculer_action_auteur("$action-$arg", is_numeric($att) ? $att : null);
142
+
143
+        $r = rawurlencode($redirect);
144
+        if ($mode === -1) {
145
+            return ['action' => $action, 'arg' => $arg, 'hash' => $hash];
146
+        } else {
147
+            return generer_url_action(
148
+                $action,
149
+                'arg=' . rawurlencode($arg) . "&hash=$hash" . (!$r ? '' : "&redirect=$r"),
150
+                $mode,
151
+                $public
152
+            );
153
+        }
154
+    }
155
+
156
+    // mode formulaire
157
+    $hash = calculer_action_auteur("$action-$arg");
158
+    $att .= " style='margin: 0px; border: 0px'";
159
+    if ($redirect) {
160
+        $redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", '&#39;', $redirect) . "' />";
161
+    }
162
+    $mode .= $redirect . "
163 163
 <input name='hash' type='hidden' value='$hash' />
164 164
 <input name='arg' type='hidden' value='$arg' />";
165 165
 
166
-	return generer_form_action($action, $mode, $att, $public);
166
+    return generer_form_action($action, $mode, $att, $public);
167 167
 }
168 168
 
169 169
 /**
@@ -173,48 +173,48 @@  discard block
 block discarded – undo
173 173
  * @return array
174 174
  */
175 175
 function caracteriser_auteur($id_auteur = null) {
176
-	static $caracterisation = [];
177
-
178
-	if (is_null($id_auteur) and !isset($GLOBALS['visiteur_session']['id_auteur'])) {
179
-		// si l'auteur courant n'est pas connu alors qu'il peut demander une action
180
-		// c'est une connexion par php_auth ou 1 instal, on se rabat sur le cookie.
181
-		// S'il n'avait pas le droit de realiser cette action, le hash sera faux.
182
-		if (
183
-			isset($_COOKIE['spip_session'])
184
-			and (preg_match('/^(\d+)/', $_COOKIE['spip_session'], $r))
185
-		) {
186
-			return [$r[1], ''];
187
-			// Necessaire aux forums anonymes.
188
-			// Pour le reste, ca echouera.
189
-		} else {
190
-			return ['0', ''];
191
-		}
192
-	}
193
-	// Eviter l'acces SQL si le pass est connu de PHP
194
-	if (is_null($id_auteur)) {
195
-		$id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0;
196
-		if (isset($GLOBALS['visiteur_session']['pass']) and $GLOBALS['visiteur_session']['pass']) {
197
-			return $caracterisation[$id_auteur] = [$id_auteur, $GLOBALS['visiteur_session']['pass']];
198
-		}
199
-	}
200
-
201
-	if (isset($caracterisation[$id_auteur])) {
202
-		return $caracterisation[$id_auteur];
203
-	}
204
-
205
-	if ($id_auteur) {
206
-		include_spip('base/abstract_sql');
207
-		$t = sql_fetsel('id_auteur, pass', 'spip_auteurs', "id_auteur=$id_auteur");
208
-		if ($t) {
209
-			return $caracterisation[$id_auteur] = [$t['id_auteur'], $t['pass']];
210
-		}
211
-		include_spip('inc/minipres');
212
-		echo minipres();
213
-		exit;
214
-	} // Visiteur anonyme, pour ls forums par exemple
215
-	else {
216
-		return ['0', ''];
217
-	}
176
+    static $caracterisation = [];
177
+
178
+    if (is_null($id_auteur) and !isset($GLOBALS['visiteur_session']['id_auteur'])) {
179
+        // si l'auteur courant n'est pas connu alors qu'il peut demander une action
180
+        // c'est une connexion par php_auth ou 1 instal, on se rabat sur le cookie.
181
+        // S'il n'avait pas le droit de realiser cette action, le hash sera faux.
182
+        if (
183
+            isset($_COOKIE['spip_session'])
184
+            and (preg_match('/^(\d+)/', $_COOKIE['spip_session'], $r))
185
+        ) {
186
+            return [$r[1], ''];
187
+            // Necessaire aux forums anonymes.
188
+            // Pour le reste, ca echouera.
189
+        } else {
190
+            return ['0', ''];
191
+        }
192
+    }
193
+    // Eviter l'acces SQL si le pass est connu de PHP
194
+    if (is_null($id_auteur)) {
195
+        $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0;
196
+        if (isset($GLOBALS['visiteur_session']['pass']) and $GLOBALS['visiteur_session']['pass']) {
197
+            return $caracterisation[$id_auteur] = [$id_auteur, $GLOBALS['visiteur_session']['pass']];
198
+        }
199
+    }
200
+
201
+    if (isset($caracterisation[$id_auteur])) {
202
+        return $caracterisation[$id_auteur];
203
+    }
204
+
205
+    if ($id_auteur) {
206
+        include_spip('base/abstract_sql');
207
+        $t = sql_fetsel('id_auteur, pass', 'spip_auteurs', "id_auteur=$id_auteur");
208
+        if ($t) {
209
+            return $caracterisation[$id_auteur] = [$t['id_auteur'], $t['pass']];
210
+        }
211
+        include_spip('inc/minipres');
212
+        echo minipres();
213
+        exit;
214
+    } // Visiteur anonyme, pour ls forums par exemple
215
+    else {
216
+        return ['0', ''];
217
+    }
218 218
 }
219 219
 
220 220
 /**
@@ -229,30 +229,30 @@  discard block
 block discarded – undo
229 229
  * @return string
230 230
  */
231 231
 function _action_auteur(string $action, int $id_auteur, ?string $pass, string $alea): string {
232
-	static $sha = [];
233
-	$pass = $pass ?? '';
234
-	$entry = "$action:$id_auteur:$pass:$alea";
235
-	if (!isset($sha[$entry])) {
236
-		$sha[$entry] = hash_hmac('sha256', "$action::$id_auteur", "$pass::" . _action_get_alea($alea));
237
-	}
238
-
239
-	return $sha[$entry];
232
+    static $sha = [];
233
+    $pass = $pass ?? '';
234
+    $entry = "$action:$id_auteur:$pass:$alea";
235
+    if (!isset($sha[$entry])) {
236
+        $sha[$entry] = hash_hmac('sha256', "$action::$id_auteur", "$pass::" . _action_get_alea($alea));
237
+    }
238
+
239
+    return $sha[$entry];
240 240
 }
241 241
 
242 242
 function _action_get_alea(string $alea): string {
243
-	if (!isset($GLOBALS['meta'][$alea])) {
244
-		if (!$exec = _request('exec') or !autoriser_sans_cookie($exec)) {
245
-			include_spip('inc/acces');
246
-			charger_aleas();
247
-			if (empty($GLOBALS['meta'][$alea])) {
248
-				include_spip('inc/minipres');
249
-				echo minipres();
250
-				spip_log("$alea indisponible");
251
-				exit;
252
-			}
253
-		}
254
-	}
255
-	return $GLOBALS['meta'][$alea] ?? '';
243
+    if (!isset($GLOBALS['meta'][$alea])) {
244
+        if (!$exec = _request('exec') or !autoriser_sans_cookie($exec)) {
245
+            include_spip('inc/acces');
246
+            charger_aleas();
247
+            if (empty($GLOBALS['meta'][$alea])) {
248
+                include_spip('inc/minipres');
249
+                echo minipres();
250
+                spip_log("$alea indisponible");
251
+                exit;
252
+            }
253
+        }
254
+    }
255
+    return $GLOBALS['meta'][$alea] ?? '';
256 256
 }
257 257
 
258 258
 /**
@@ -263,9 +263,9 @@  discard block
 block discarded – undo
263 263
  * @return string
264 264
  */
265 265
 function calculer_action_auteur($action, $id_auteur = null) {
266
-	[$id_auteur, $pass] = caracteriser_auteur($id_auteur);
266
+    [$id_auteur, $pass] = caracteriser_auteur($id_auteur);
267 267
 
268
-	return _action_auteur($action, $id_auteur, $pass, 'alea_ephemere');
268
+    return _action_auteur($action, $id_auteur, $pass, 'alea_ephemere');
269 269
 }
270 270
 
271 271
 
@@ -278,15 +278,15 @@  discard block
 block discarded – undo
278 278
  * @return bool
279 279
  */
280 280
 function verifier_action_auteur($action, $hash) {
281
-	[$id_auteur, $pass] = caracteriser_auteur();
282
-	if (
283
-		hash_equals($hash, _action_auteur($action, $id_auteur, $pass, 'alea_ephemere'))
284
-		or hash_equals($hash, _action_auteur($action, $id_auteur, $pass, 'alea_ephemere_ancien'))
285
-	) {
286
-		return true;
287
-	}
288
-
289
-	return false;
281
+    [$id_auteur, $pass] = caracteriser_auteur();
282
+    if (
283
+        hash_equals($hash, _action_auteur($action, $id_auteur, $pass, 'alea_ephemere'))
284
+        or hash_equals($hash, _action_auteur($action, $id_auteur, $pass, 'alea_ephemere_ancien'))
285
+    ) {
286
+        return true;
287
+    }
288
+
289
+    return false;
290 290
 }
291 291
 
292 292
 //
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
  * @return string
302 302
  */
303 303
 function secret_du_site() {
304
-	return SpipCles::secret_du_site();
304
+    return SpipCles::secret_du_site();
305 305
 }
306 306
 
307 307
 /**
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
  * @return string
312 312
  */
313 313
 function calculer_cle_action($action) {
314
-	return hash_hmac('sha256', $action, secret_du_site());
314
+    return hash_hmac('sha256', $action, secret_du_site());
315 315
 }
316 316
 
317 317
 /**
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
  * @return bool
323 323
  */
324 324
 function verifier_cle_action($action, $cle) {
325
-	return hash_equals($cle, calculer_cle_action($action));
325
+    return hash_equals($cle, calculer_cle_action($action));
326 326
 }
327 327
 
328 328
 
@@ -339,19 +339,19 @@  discard block
 block discarded – undo
339 339
  * @return string Token, de la forme "{id}*{hash}"
340 340
  */
341 341
 function calculer_token_previsu($url, $id_auteur = null, $alea = 'alea_ephemere') {
342
-	if (is_null($id_auteur)) {
343
-		if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
344
-			$id_auteur = $GLOBALS['visiteur_session']['id_auteur'];
345
-		}
346
-	}
347
-	if (!$id_auteur = intval($id_auteur)) {
348
-		return '';
349
-	}
350
-	// On nettoie l’URL de tous les var_.
351
-	$url = nettoyer_uri_var($url);
352
-
353
-	$token = _action_auteur('previsualiser-' . $url, $id_auteur, secret_du_site(), $alea);
354
-	return "$id_auteur-$token";
342
+    if (is_null($id_auteur)) {
343
+        if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
344
+            $id_auteur = $GLOBALS['visiteur_session']['id_auteur'];
345
+        }
346
+    }
347
+    if (!$id_auteur = intval($id_auteur)) {
348
+        return '';
349
+    }
350
+    // On nettoie l’URL de tous les var_.
351
+    $url = nettoyer_uri_var($url);
352
+
353
+    $token = _action_auteur('previsualiser-' . $url, $id_auteur, secret_du_site(), $alea);
354
+    return "$id_auteur-$token";
355 355
 }
356 356
 
357 357
 
@@ -369,31 +369,31 @@  discard block
 block discarded – undo
369 369
  *     + Tableau (id auteur, type d’objet, id_objet) sinon.
370 370
  */
371 371
 function verifier_token_previsu($token) {
372
-	// retrouver auteur / hash
373
-	$e = explode('-', $token, 2);
374
-	if (count($e) == 2 and is_numeric(reset($e))) {
375
-		$id_auteur = intval(reset($e));
376
-	} else {
377
-		return false;
378
-	}
379
-
380
-	// calculer le type et id de l’url actuelle
381
-	include_spip('inc/urls');
382
-	include_spip('inc/filtres_mini');
383
-	$url = url_absolue(self());
384
-
385
-	// verifier le token
386
-	$_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere');
387
-	if (!$_token or !hash_equals($token, $_token)) {
388
-		$_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere_ancien');
389
-		if (!$_token or !hash_equals($token, $_token)) {
390
-			return false;
391
-		}
392
-	}
393
-
394
-	return [
395
-		'id_auteur' => $id_auteur,
396
-	];
372
+    // retrouver auteur / hash
373
+    $e = explode('-', $token, 2);
374
+    if (count($e) == 2 and is_numeric(reset($e))) {
375
+        $id_auteur = intval(reset($e));
376
+    } else {
377
+        return false;
378
+    }
379
+
380
+    // calculer le type et id de l’url actuelle
381
+    include_spip('inc/urls');
382
+    include_spip('inc/filtres_mini');
383
+    $url = url_absolue(self());
384
+
385
+    // verifier le token
386
+    $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere');
387
+    if (!$_token or !hash_equals($token, $_token)) {
388
+        $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere_ancien');
389
+        if (!$_token or !hash_equals($token, $_token)) {
390
+            return false;
391
+        }
392
+    }
393
+
394
+    return [
395
+        'id_auteur' => $id_auteur,
396
+    ];
397 397
 }
398 398
 
399 399
 /**
@@ -402,13 +402,13 @@  discard block
 block discarded – undo
402 402
  * @return bool|array
403 403
  */
404 404
 function decrire_token_previsu() {
405
-	static $desc = null;
406
-	if (is_null($desc)) {
407
-		if ($token = _request('var_previewtoken')) {
408
-			$desc = verifier_token_previsu($token);
409
-		} else {
410
-			$desc = false;
411
-		}
412
-	}
413
-	return $desc;
405
+    static $desc = null;
406
+    if (is_null($desc)) {
407
+        if ($token = _request('var_previewtoken')) {
408
+            $desc = verifier_token_previsu($token);
409
+        } else {
410
+            $desc = false;
411
+        }
412
+    }
413
+    return $desc;
414 414
 }
Please login to merge, or discard this patch.
ecrire/inc/boutons.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  */
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 /**
@@ -35,35 +35,35 @@  discard block
 block discarded – undo
35 35
  */
36 36
 function definir_barre_onglets($script) {
37 37
 
38
-	$onglets = [];
39
-	$liste_onglets = [];
38
+    $onglets = [];
39
+    $liste_onglets = [];
40 40
 
41
-	// ajouter les onglets issus des plugin via paquet.xml
42
-	if (function_exists('onglets_plugins')) {
43
-		$liste_onglets = onglets_plugins();
44
-	}
41
+    // ajouter les onglets issus des plugin via paquet.xml
42
+    if (function_exists('onglets_plugins')) {
43
+        $liste_onglets = onglets_plugins();
44
+    }
45 45
 
46 46
 
47
-	foreach ($liste_onglets as $id => $infos) {
48
-		if (
49
-			($parent = $infos['parent'])
50
-			&& $parent == $script
51
-			&& autoriser('onglet', "_$id")
52
-		) {
53
-			$onglets[$id] = new Bouton(
54
-				isset($infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
55
-				$infos['titre'],  // titre
56
-				(isset($infos['action']) and $infos['action'])
57
-					? generer_url_ecrire(
58
-						$infos['action'],
59
-						(isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : ''
60
-					)
61
-					: null
62
-			);
63
-		}
64
-	}
47
+    foreach ($liste_onglets as $id => $infos) {
48
+        if (
49
+            ($parent = $infos['parent'])
50
+            && $parent == $script
51
+            && autoriser('onglet', "_$id")
52
+        ) {
53
+            $onglets[$id] = new Bouton(
54
+                isset($infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
55
+                $infos['titre'],  // titre
56
+                (isset($infos['action']) and $infos['action'])
57
+                    ? generer_url_ecrire(
58
+                        $infos['action'],
59
+                        (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : ''
60
+                    )
61
+                    : null
62
+            );
63
+        }
64
+    }
65 65
 
66
-	return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]);
66
+    return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]);
67 67
 }
68 68
 
69 69
 /**
@@ -81,14 +81,14 @@  discard block
 block discarded – undo
81 81
  * @return string
82 82
  */
83 83
 function barre_onglets($rubrique, $ongletCourant, $class = 'barre_onglet') {
84
-	include_spip('inc/presentation');
84
+    include_spip('inc/presentation');
85 85
 
86
-	$res = '';
86
+    $res = '';
87 87
 
88
-	foreach (definir_barre_onglets($rubrique) as $exec => $onglet) {
89
-		$url = $onglet->url ?: generer_url_ecrire($exec);
90
-		$res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone);
91
-	}
88
+    foreach (definir_barre_onglets($rubrique) as $exec => $onglet) {
89
+        $url = $onglet->url ?: generer_url_ecrire($exec);
90
+        $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone);
91
+    }
92 92
 
93
-	return !$res ? '' : (debut_onglet($class) . $res . fin_onglet());
93
+    return !$res ? '' : (debut_onglet($class) . $res . fin_onglet());
94 94
 }
Please login to merge, or discard this patch.
ecrire/inc/charsets.php 2 patches
Indentation   +636 added lines, -636 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 // securité
24 24
 if (!defined('_ECRIRE_INC_VERSION')) {
25
-	return;
25
+    return;
26 26
 }
27 27
 
28 28
 // se faciliter la lecture du charset
@@ -32,19 +32,19 @@  discard block
 block discarded – undo
32 32
  * Initialisation
33 33
  */
34 34
 function init_charset(): void {
35
-	// Initialisation
36
-	$GLOBALS['CHARSET'] = [];
37
-
38
-	// noter a l'occasion dans la meta pcre_u notre capacite a utiliser le flag /u
39
-	// dans les preg_replace pour ne pas casser certaines lettres accentuees :
40
-	// en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp
41
-	if (
42
-		!isset($GLOBALS['meta']['pcre_u'])
43
-		or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
44
-	) {
45
-		include_spip('inc/meta');
46
-		ecrire_meta('pcre_u', (lire_config('charset', _DEFAULT_CHARSET) === 'utf-8') ? 'u' : '');
47
-	}
35
+    // Initialisation
36
+    $GLOBALS['CHARSET'] = [];
37
+
38
+    // noter a l'occasion dans la meta pcre_u notre capacite a utiliser le flag /u
39
+    // dans les preg_replace pour ne pas casser certaines lettres accentuees :
40
+    // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp
41
+    if (
42
+        !isset($GLOBALS['meta']['pcre_u'])
43
+        or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
44
+    ) {
45
+        include_spip('inc/meta');
46
+        ecrire_meta('pcre_u', (lire_config('charset', _DEFAULT_CHARSET) === 'utf-8') ? 'u' : '');
47
+    }
48 48
 }
49 49
 
50 50
 // TODO: code d’exécution en dehors du fichier.
@@ -65,39 +65,39 @@  discard block
 block discarded – undo
65 65
  *     - false si le charset n'est pas décrit dans le répertoire charsets/
66 66
  **/
67 67
 function load_charset($charset = 'AUTO') {
68
-	if ($charset == 'AUTO') {
69
-		$charset = $GLOBALS['meta']['charset'];
70
-	}
71
-	$charset = trim(strtolower($charset));
72
-	if (isset($GLOBALS['CHARSET'][$charset])) {
73
-		return $charset;
74
-	}
75
-
76
-	if ($charset == 'utf-8') {
77
-		$GLOBALS['CHARSET'][$charset] = [];
78
-
79
-		return $charset;
80
-	}
81
-
82
-	// Quelques synonymes
83
-	if ($charset === '') {
84
-		$charset = 'iso-8859-1';
85
-	} elseif ($charset === 'windows-1250') {
86
-		$charset = 'cp1250';
87
-	} elseif ($charset === 'windows-1251') {
88
-		$charset = 'cp1251';
89
-	} elseif ($charset === 'windows-1256') {
90
-		$charset = 'cp1256';
91
-	}
92
-
93
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
94
-		return $charset;
95
-	} else {
96
-		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
97
-		$GLOBALS['CHARSET'][$charset] = [];
98
-
99
-		return false;
100
-	}
68
+    if ($charset == 'AUTO') {
69
+        $charset = $GLOBALS['meta']['charset'];
70
+    }
71
+    $charset = trim(strtolower($charset));
72
+    if (isset($GLOBALS['CHARSET'][$charset])) {
73
+        return $charset;
74
+    }
75
+
76
+    if ($charset == 'utf-8') {
77
+        $GLOBALS['CHARSET'][$charset] = [];
78
+
79
+        return $charset;
80
+    }
81
+
82
+    // Quelques synonymes
83
+    if ($charset === '') {
84
+        $charset = 'iso-8859-1';
85
+    } elseif ($charset === 'windows-1250') {
86
+        $charset = 'cp1250';
87
+    } elseif ($charset === 'windows-1251') {
88
+        $charset = 'cp1251';
89
+    } elseif ($charset === 'windows-1256') {
90
+        $charset = 'cp1256';
91
+    }
92
+
93
+    if (find_in_path($charset . '.php', 'charsets/', true)) {
94
+        return $charset;
95
+    } else {
96
+        spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
97
+        $GLOBALS['CHARSET'][$charset] = [];
98
+
99
+        return false;
100
+    }
101 101
 }
102 102
 
103 103
 
@@ -110,19 +110,19 @@  discard block
 block discarded – undo
110 110
  *     true si notre charset est utilisable par mb_strsing
111 111
  **/
112 112
 function init_mb_string(): bool {
113
-	static $mb;
114
-
115
-	// verifier que le charset interne est connu de mb_string
116
-	if (!$mb) {
117
-		if (mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))) {
118
-			mb_internal_encoding('utf-8');
119
-			$mb = 1;
120
-		} else {
121
-			$mb = -1;
122
-		}
123
-	}
124
-
125
-	return ($mb === 1);
113
+    static $mb;
114
+
115
+    // verifier que le charset interne est connu de mb_string
116
+    if (!$mb) {
117
+        if (mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))) {
118
+            mb_internal_encoding('utf-8');
119
+            $mb = 1;
120
+        } else {
121
+            $mb = -1;
122
+        }
123
+    }
124
+
125
+    return ($mb === 1);
126 126
 }
127 127
 
128 128
 /**
@@ -137,21 +137,21 @@  discard block
 block discarded – undo
137 137
  *     true si iconv fonctionne correctement
138 138
  **/
139 139
 function test_iconv(): bool {
140
-	static $iconv_ok;
141
-
142
-	if (!$iconv_ok) {
143
-		if (!function_exists('iconv')) {
144
-			$iconv_ok = -1;
145
-		} else {
146
-			if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) === 'chaine de test') {
147
-				$iconv_ok = 1;
148
-			} else {
149
-				$iconv_ok = -1;
150
-			}
151
-		}
152
-	}
153
-
154
-	return ($iconv_ok === 1);
140
+    static $iconv_ok;
141
+
142
+    if (!$iconv_ok) {
143
+        if (!function_exists('iconv')) {
144
+            $iconv_ok = -1;
145
+        } else {
146
+            if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) === 'chaine de test') {
147
+                $iconv_ok = 1;
148
+            } else {
149
+                $iconv_ok = -1;
150
+            }
151
+        }
152
+    }
153
+
154
+    return ($iconv_ok === 1);
155 155
 }
156 156
 
157 157
 /**
@@ -171,75 +171,75 @@  discard block
 block discarded – undo
171 171
  *     texte corrigé
172 172
  **/
173 173
 function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') {
174
-	static $trans;
175
-
176
-	if (is_array($texte)) {
177
-		return array_map('corriger_caracteres_windows', $texte);
178
-	}
179
-
180
-	if ($charset == 'AUTO') {
181
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
182
-	}
183
-	if ($charset == 'utf-8') {
184
-		$p = chr(194);
185
-		if (strpos($texte, $p) == false) {
186
-			return $texte;
187
-		}
188
-	} else {
189
-		if ($charset == 'iso-8859-1') {
190
-			$p = '';
191
-		} else {
192
-			return $texte;
193
-		}
194
-	}
195
-
196
-	if (!isset($trans[$charset][$charset_cible])) {
197
-		$trans[$charset][$charset_cible] = [
198
-			$p . chr(128) => '&#8364;',
199
-			$p . chr(129) => ' ', # pas affecte
200
-			$p . chr(130) => '&#8218;',
201
-			$p . chr(131) => '&#402;',
202
-			$p . chr(132) => '&#8222;',
203
-			$p . chr(133) => '&#8230;',
204
-			$p . chr(134) => '&#8224;',
205
-			$p . chr(135) => '&#8225;',
206
-			$p . chr(136) => '&#710;',
207
-			$p . chr(137) => '&#8240;',
208
-			$p . chr(138) => '&#352;',
209
-			$p . chr(139) => '&#8249;',
210
-			$p . chr(140) => '&#338;',
211
-			$p . chr(141) => ' ', # pas affecte
212
-			$p . chr(142) => '&#381;',
213
-			$p . chr(143) => ' ', # pas affecte
214
-			$p . chr(144) => ' ', # pas affecte
215
-			$p . chr(145) => '&#8216;',
216
-			$p . chr(146) => '&#8217;',
217
-			$p . chr(147) => '&#8220;',
218
-			$p . chr(148) => '&#8221;',
219
-			$p . chr(149) => '&#8226;',
220
-			$p . chr(150) => '&#8211;',
221
-			$p . chr(151) => '&#8212;',
222
-			$p . chr(152) => '&#732;',
223
-			$p . chr(153) => '&#8482;',
224
-			$p . chr(154) => '&#353;',
225
-			$p . chr(155) => '&#8250;',
226
-			$p . chr(156) => '&#339;',
227
-			$p . chr(157) => ' ', # pas affecte
228
-			$p . chr(158) => '&#382;',
229
-			$p . chr(159) => '&#376;',
230
-		];
231
-		if ($charset_cible != 'unicode') {
232
-			foreach ($trans[$charset][$charset_cible] as $k => $c) {
233
-				$trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
234
-			}
235
-		}
236
-	}
237
-
238
-	return @str_replace(
239
-		array_keys($trans[$charset][$charset_cible]),
240
-		array_values($trans[$charset][$charset_cible]),
241
-		$texte
242
-	);
174
+    static $trans;
175
+
176
+    if (is_array($texte)) {
177
+        return array_map('corriger_caracteres_windows', $texte);
178
+    }
179
+
180
+    if ($charset == 'AUTO') {
181
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
182
+    }
183
+    if ($charset == 'utf-8') {
184
+        $p = chr(194);
185
+        if (strpos($texte, $p) == false) {
186
+            return $texte;
187
+        }
188
+    } else {
189
+        if ($charset == 'iso-8859-1') {
190
+            $p = '';
191
+        } else {
192
+            return $texte;
193
+        }
194
+    }
195
+
196
+    if (!isset($trans[$charset][$charset_cible])) {
197
+        $trans[$charset][$charset_cible] = [
198
+            $p . chr(128) => '&#8364;',
199
+            $p . chr(129) => ' ', # pas affecte
200
+            $p . chr(130) => '&#8218;',
201
+            $p . chr(131) => '&#402;',
202
+            $p . chr(132) => '&#8222;',
203
+            $p . chr(133) => '&#8230;',
204
+            $p . chr(134) => '&#8224;',
205
+            $p . chr(135) => '&#8225;',
206
+            $p . chr(136) => '&#710;',
207
+            $p . chr(137) => '&#8240;',
208
+            $p . chr(138) => '&#352;',
209
+            $p . chr(139) => '&#8249;',
210
+            $p . chr(140) => '&#338;',
211
+            $p . chr(141) => ' ', # pas affecte
212
+            $p . chr(142) => '&#381;',
213
+            $p . chr(143) => ' ', # pas affecte
214
+            $p . chr(144) => ' ', # pas affecte
215
+            $p . chr(145) => '&#8216;',
216
+            $p . chr(146) => '&#8217;',
217
+            $p . chr(147) => '&#8220;',
218
+            $p . chr(148) => '&#8221;',
219
+            $p . chr(149) => '&#8226;',
220
+            $p . chr(150) => '&#8211;',
221
+            $p . chr(151) => '&#8212;',
222
+            $p . chr(152) => '&#732;',
223
+            $p . chr(153) => '&#8482;',
224
+            $p . chr(154) => '&#353;',
225
+            $p . chr(155) => '&#8250;',
226
+            $p . chr(156) => '&#339;',
227
+            $p . chr(157) => ' ', # pas affecte
228
+            $p . chr(158) => '&#382;',
229
+            $p . chr(159) => '&#376;',
230
+        ];
231
+        if ($charset_cible != 'unicode') {
232
+            foreach ($trans[$charset][$charset_cible] as $k => $c) {
233
+                $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
234
+            }
235
+        }
236
+    }
237
+
238
+    return @str_replace(
239
+        array_keys($trans[$charset][$charset_cible]),
240
+        array_values($trans[$charset][$charset_cible]),
241
+        $texte
242
+    );
243 243
 }
244 244
 
245 245
 
@@ -256,26 +256,26 @@  discard block
 block discarded – undo
256 256
  *     texte converti
257 257
  **/
258 258
 function html2unicode($texte, $secure = false) {
259
-	if (strpos($texte, '&') === false) {
260
-		return $texte;
261
-	}
262
-	static $trans = [];
263
-	if (!$trans) {
264
-		load_charset('html');
265
-		foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
266
-			$trans["&$key;"] = $val;
267
-		}
268
-	}
269
-
270
-	if ($secure) {
271
-		return str_replace(array_keys($trans), array_values($trans), $texte);
272
-	} else {
273
-		return str_replace(
274
-			['&amp;', '&quot;', '&lt;', '&gt;'],
275
-			['&', '"', '<', '>'],
276
-			str_replace(array_keys($trans), array_values($trans), $texte)
277
-		);
278
-	}
259
+    if (strpos($texte, '&') === false) {
260
+        return $texte;
261
+    }
262
+    static $trans = [];
263
+    if (!$trans) {
264
+        load_charset('html');
265
+        foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
266
+            $trans["&$key;"] = $val;
267
+        }
268
+    }
269
+
270
+    if ($secure) {
271
+        return str_replace(array_keys($trans), array_values($trans), $texte);
272
+    } else {
273
+        return str_replace(
274
+            ['&amp;', '&quot;', '&lt;', '&gt;'],
275
+            ['&', '"', '<', '>'],
276
+            str_replace(array_keys($trans), array_values($trans), $texte)
277
+        );
278
+    }
279 279
 }
280 280
 
281 281
 
@@ -290,16 +290,16 @@  discard block
 block discarded – undo
290 290
  *     texte converti
291 291
  **/
292 292
 function mathml2unicode($texte) {
293
-	static $trans;
294
-	if (!$trans) {
295
-		load_charset('mathml');
293
+    static $trans;
294
+    if (!$trans) {
295
+        load_charset('mathml');
296 296
 
297
-		foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
298
-			$trans["&$key;"] = $val;
299
-		}
300
-	}
297
+        foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
298
+            $trans["&$key;"] = $val;
299
+        }
300
+    }
301 301
 
302
-	return str_replace(array_keys($trans), array_values($trans), $texte);
302
+    return str_replace(array_keys($trans), array_values($trans), $texte);
303 303
 }
304 304
 
305 305
 
@@ -321,75 +321,75 @@  discard block
 block discarded – undo
321 321
  *     texte converti en unicode
322 322
  **/
323 323
 function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) {
324
-	static $trans;
325
-
326
-	if ($charset === 'AUTO') {
327
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
328
-	}
329
-
330
-	if ($charset === '') {
331
-		$charset = 'iso-8859-1';
332
-	}
333
-	$charset = strtolower($charset);
334
-
335
-	switch ($charset) {
336
-		case 'utf-8':
337
-		case 'utf8':
338
-			return utf_8_to_unicode($texte);
339
-
340
-		case 'iso-8859-1':
341
-			$texte = corriger_caracteres_windows($texte, 'iso-8859-1');
342
-		// pas de break; ici, on suit sur default:
343
-
344
-		default:
345
-			// mbstring presente ?
346
-			if (init_mb_string()) {
347
-				$order = mb_detect_order();
348
-				try {
349
-					# mb_string connait-il $charset?
350
-					if ($order and mb_detect_order($charset)) {
351
-						$s = mb_convert_encoding($texte, 'utf-8', $charset);
352
-						if ($s && $s != $texte) {
353
-							return utf_8_to_unicode($s);
354
-						}
355
-					}
356
-				} catch (\Error $e) {
357
-					// Le charset n'existe probablement pas
358
-				} finally {
359
-					mb_detect_order($order); # remettre comme precedemment
360
-				}
361
-			}
362
-
363
-			// Sinon, peut-etre connaissons-nous ce charset ?
364
-			if (!isset($trans[$charset])) {
365
-				if (
366
-					$cset = load_charset($charset)
367
-					and is_array($GLOBALS['CHARSET'][$cset])
368
-				) {
369
-					foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
370
-						$trans[$charset][chr($key)] = '&#' . $val . ';';
371
-					}
372
-				}
373
-			}
374
-			if (isset($trans[$charset]) and is_countable($trans[$charset]) ? count($trans[$charset]) : 0) {
375
-				return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
376
-			}
377
-
378
-			// Sinon demander a iconv (malgre le fait qu'il coupe quand un
379
-			// caractere n'appartient pas au charset, mais c'est un probleme
380
-			// surtout en utf-8, gere ci-dessus)
381
-			if (test_iconv()) {
382
-				$s = iconv($charset, 'utf-32le', $texte);
383
-				if ($s) {
384
-					return utf_32_to_unicode($s);
385
-				}
386
-			}
387
-
388
-			// Au pire ne rien faire
389
-			spip_log("erreur charset '$charset' non supporte");
390
-
391
-			return $texte;
392
-	}
324
+    static $trans;
325
+
326
+    if ($charset === 'AUTO') {
327
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
328
+    }
329
+
330
+    if ($charset === '') {
331
+        $charset = 'iso-8859-1';
332
+    }
333
+    $charset = strtolower($charset);
334
+
335
+    switch ($charset) {
336
+        case 'utf-8':
337
+        case 'utf8':
338
+            return utf_8_to_unicode($texte);
339
+
340
+        case 'iso-8859-1':
341
+            $texte = corriger_caracteres_windows($texte, 'iso-8859-1');
342
+        // pas de break; ici, on suit sur default:
343
+
344
+        default:
345
+            // mbstring presente ?
346
+            if (init_mb_string()) {
347
+                $order = mb_detect_order();
348
+                try {
349
+                    # mb_string connait-il $charset?
350
+                    if ($order and mb_detect_order($charset)) {
351
+                        $s = mb_convert_encoding($texte, 'utf-8', $charset);
352
+                        if ($s && $s != $texte) {
353
+                            return utf_8_to_unicode($s);
354
+                        }
355
+                    }
356
+                } catch (\Error $e) {
357
+                    // Le charset n'existe probablement pas
358
+                } finally {
359
+                    mb_detect_order($order); # remettre comme precedemment
360
+                }
361
+            }
362
+
363
+            // Sinon, peut-etre connaissons-nous ce charset ?
364
+            if (!isset($trans[$charset])) {
365
+                if (
366
+                    $cset = load_charset($charset)
367
+                    and is_array($GLOBALS['CHARSET'][$cset])
368
+                ) {
369
+                    foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
370
+                        $trans[$charset][chr($key)] = '&#' . $val . ';';
371
+                    }
372
+                }
373
+            }
374
+            if (isset($trans[$charset]) and is_countable($trans[$charset]) ? count($trans[$charset]) : 0) {
375
+                return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
376
+            }
377
+
378
+            // Sinon demander a iconv (malgre le fait qu'il coupe quand un
379
+            // caractere n'appartient pas au charset, mais c'est un probleme
380
+            // surtout en utf-8, gere ci-dessus)
381
+            if (test_iconv()) {
382
+                $s = iconv($charset, 'utf-32le', $texte);
383
+                if ($s) {
384
+                    return utf_32_to_unicode($s);
385
+                }
386
+            }
387
+
388
+            // Au pire ne rien faire
389
+            spip_log("erreur charset '$charset' non supporte");
390
+
391
+            return $texte;
392
+    }
393 393
 }
394 394
 
395 395
 
@@ -408,43 +408,43 @@  discard block
 block discarded – undo
408 408
  *     texte transformé dans le charset souhaité
409 409
  **/
410 410
 function unicode2charset($texte, $charset = 'AUTO') {
411
-	static $CHARSET_REVERSE = [];
412
-	static $trans = [];
413
-
414
-	if ($charset == 'AUTO') {
415
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
416
-	}
417
-
418
-	switch ($charset) {
419
-		case 'utf-8':
420
-			return unicode_to_utf_8($texte);
421
-
422
-		default:
423
-			$charset = load_charset($charset);
424
-
425
-			if (empty($CHARSET_REVERSE[$charset])) {
426
-				$CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
427
-			}
428
-
429
-			if (!isset($trans[$charset])) {
430
-				$trans[$charset] = [];
431
-				$t = &$trans[$charset];
432
-				for ($e = 128; $e < 255; $e++) {
433
-					$h = dechex($e);
434
-					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
435
-						$s = $CHARSET_REVERSE[$charset][$e];
436
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
437
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
438
-					} else {
439
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
440
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
441
-					}
442
-				}
443
-			}
444
-			$texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
445
-
446
-			return $texte;
447
-	}
411
+    static $CHARSET_REVERSE = [];
412
+    static $trans = [];
413
+
414
+    if ($charset == 'AUTO') {
415
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
416
+    }
417
+
418
+    switch ($charset) {
419
+        case 'utf-8':
420
+            return unicode_to_utf_8($texte);
421
+
422
+        default:
423
+            $charset = load_charset($charset);
424
+
425
+            if (empty($CHARSET_REVERSE[$charset])) {
426
+                $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
427
+            }
428
+
429
+            if (!isset($trans[$charset])) {
430
+                $trans[$charset] = [];
431
+                $t = &$trans[$charset];
432
+                for ($e = 128; $e < 255; $e++) {
433
+                    $h = dechex($e);
434
+                    if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
435
+                        $s = $CHARSET_REVERSE[$charset][$e];
436
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
437
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
438
+                    } else {
439
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
440
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
441
+                    }
442
+                }
443
+            }
444
+            $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
445
+
446
+            return $texte;
447
+    }
448 448
 }
449 449
 
450 450
 
@@ -462,40 +462,40 @@  discard block
 block discarded – undo
462 462
  *     texte transformé dans le charset site
463 463
  **/
464 464
 function importer_charset($texte, $charset = 'AUTO') {
465
-	$s = null;
466
-	static $trans = [];
467
-	// on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
468
-	if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
469
-		$texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
470
-		if (init_mb_string()) {
471
-			if (
472
-				$order = mb_detect_order() # mb_string connait-il $charset?
473
-				and mb_detect_order($charset)
474
-			) {
475
-				$s = mb_convert_encoding($texte, 'utf-8', $charset);
476
-			}
477
-			mb_detect_order($order); # remettre comme precedemment
478
-			return $s;
479
-		}
480
-		// Sinon, peut-etre connaissons-nous ce charset ?
481
-		if (!isset($trans[$charset])) {
482
-			if (
483
-				$cset = load_charset($charset)
484
-				and is_array($GLOBALS['CHARSET'][$cset])
485
-			) {
486
-				foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
487
-					$trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
488
-				}
489
-			}
490
-		}
491
-		if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) {
492
-			return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
493
-		}
494
-
495
-		return $texte;
496
-	}
497
-
498
-	return unicode2charset(charset2unicode($texte, $charset));
465
+    $s = null;
466
+    static $trans = [];
467
+    // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
468
+    if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
469
+        $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
470
+        if (init_mb_string()) {
471
+            if (
472
+                $order = mb_detect_order() # mb_string connait-il $charset?
473
+                and mb_detect_order($charset)
474
+            ) {
475
+                $s = mb_convert_encoding($texte, 'utf-8', $charset);
476
+            }
477
+            mb_detect_order($order); # remettre comme precedemment
478
+            return $s;
479
+        }
480
+        // Sinon, peut-etre connaissons-nous ce charset ?
481
+        if (!isset($trans[$charset])) {
482
+            if (
483
+                $cset = load_charset($charset)
484
+                and is_array($GLOBALS['CHARSET'][$cset])
485
+            ) {
486
+                foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
487
+                    $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
488
+                }
489
+            }
490
+        }
491
+        if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) {
492
+            return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
493
+        }
494
+
495
+        return $texte;
496
+    }
497
+
498
+    return unicode2charset(charset2unicode($texte, $charset));
499 499
 }
500 500
 
501 501
 
@@ -511,92 +511,92 @@  discard block
 block discarded – undo
511 511
  **/
512 512
 function utf_8_to_unicode($source) {
513 513
 
514
-	// mb_string : methode rapide
515
-	if (init_mb_string()) {
516
-		$convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
517
-
518
-		return mb_encode_numericentity($source, $convmap, 'UTF-8');
519
-	}
520
-
521
-	// Sinon methode pas a pas
522
-	static $decrement;
523
-	static $shift;
524
-
525
-	// Cf. php.net, par Ronen. Adapte pour compatibilite < php4
526
-	if (!is_array($decrement)) {
527
-		// array used to figure what number to decrement from character order value
528
-		// according to number of characters used to map unicode to ascii by utf-8
529
-		$decrement[4] = 240;
530
-		$decrement[3] = 224;
531
-		$decrement[2] = 192;
532
-		$decrement[1] = 0;
533
-		// the number of bits to shift each charNum by
534
-		$shift[1][0] = 0;
535
-		$shift[2][0] = 6;
536
-		$shift[2][1] = 0;
537
-		$shift[3][0] = 12;
538
-		$shift[3][1] = 6;
539
-		$shift[3][2] = 0;
540
-		$shift[4][0] = 18;
541
-		$shift[4][1] = 12;
542
-		$shift[4][2] = 6;
543
-		$shift[4][3] = 0;
544
-	}
545
-
546
-	$pos = 0;
547
-	$len = strlen($source);
548
-	$encodedString = '';
549
-	while ($pos < $len) {
550
-		$char = '';
551
-		$ischar = false;
552
-		$asciiPos = ord(substr($source, $pos, 1));
553
-		if (($asciiPos >= 240) && ($asciiPos <= 255)) {
554
-			// 4 chars representing one unicode character
555
-			$thisLetter = substr($source, $pos, 4);
556
-			$pos += 4;
557
-		} else {
558
-			if (($asciiPos >= 224) && ($asciiPos <= 239)) {
559
-				// 3 chars representing one unicode character
560
-				$thisLetter = substr($source, $pos, 3);
561
-				$pos += 3;
562
-			} else {
563
-				if (($asciiPos >= 192) && ($asciiPos <= 223)) {
564
-					// 2 chars representing one unicode character
565
-					$thisLetter = substr($source, $pos, 2);
566
-					$pos += 2;
567
-				} else {
568
-					// 1 char (lower ascii)
569
-					$thisLetter = substr($source, $pos, 1);
570
-					$pos += 1;
571
-					$char = $thisLetter;
572
-					$ischar = true;
573
-				}
574
-			}
575
-		}
576
-
577
-		if ($ischar) {
578
-			$encodedString .= $char;
579
-		} else {  // process the string representing the letter to a unicode entity
580
-			$thisLen = strlen($thisLetter);
581
-			$thisPos = 0;
582
-			$decimalCode = 0;
583
-			while ($thisPos < $thisLen) {
584
-				$thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
585
-				if ($thisPos == 0) {
586
-					$charNum = intval($thisCharOrd - $decrement[$thisLen]);
587
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
588
-				} else {
589
-					$charNum = intval($thisCharOrd - 128);
590
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
591
-				}
592
-				$thisPos++;
593
-			}
594
-			$encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';';
595
-			$encodedString .= $encodedLetter;
596
-		}
597
-	}
598
-
599
-	return $encodedString;
514
+    // mb_string : methode rapide
515
+    if (init_mb_string()) {
516
+        $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
517
+
518
+        return mb_encode_numericentity($source, $convmap, 'UTF-8');
519
+    }
520
+
521
+    // Sinon methode pas a pas
522
+    static $decrement;
523
+    static $shift;
524
+
525
+    // Cf. php.net, par Ronen. Adapte pour compatibilite < php4
526
+    if (!is_array($decrement)) {
527
+        // array used to figure what number to decrement from character order value
528
+        // according to number of characters used to map unicode to ascii by utf-8
529
+        $decrement[4] = 240;
530
+        $decrement[3] = 224;
531
+        $decrement[2] = 192;
532
+        $decrement[1] = 0;
533
+        // the number of bits to shift each charNum by
534
+        $shift[1][0] = 0;
535
+        $shift[2][0] = 6;
536
+        $shift[2][1] = 0;
537
+        $shift[3][0] = 12;
538
+        $shift[3][1] = 6;
539
+        $shift[3][2] = 0;
540
+        $shift[4][0] = 18;
541
+        $shift[4][1] = 12;
542
+        $shift[4][2] = 6;
543
+        $shift[4][3] = 0;
544
+    }
545
+
546
+    $pos = 0;
547
+    $len = strlen($source);
548
+    $encodedString = '';
549
+    while ($pos < $len) {
550
+        $char = '';
551
+        $ischar = false;
552
+        $asciiPos = ord(substr($source, $pos, 1));
553
+        if (($asciiPos >= 240) && ($asciiPos <= 255)) {
554
+            // 4 chars representing one unicode character
555
+            $thisLetter = substr($source, $pos, 4);
556
+            $pos += 4;
557
+        } else {
558
+            if (($asciiPos >= 224) && ($asciiPos <= 239)) {
559
+                // 3 chars representing one unicode character
560
+                $thisLetter = substr($source, $pos, 3);
561
+                $pos += 3;
562
+            } else {
563
+                if (($asciiPos >= 192) && ($asciiPos <= 223)) {
564
+                    // 2 chars representing one unicode character
565
+                    $thisLetter = substr($source, $pos, 2);
566
+                    $pos += 2;
567
+                } else {
568
+                    // 1 char (lower ascii)
569
+                    $thisLetter = substr($source, $pos, 1);
570
+                    $pos += 1;
571
+                    $char = $thisLetter;
572
+                    $ischar = true;
573
+                }
574
+            }
575
+        }
576
+
577
+        if ($ischar) {
578
+            $encodedString .= $char;
579
+        } else {  // process the string representing the letter to a unicode entity
580
+            $thisLen = strlen($thisLetter);
581
+            $thisPos = 0;
582
+            $decimalCode = 0;
583
+            while ($thisPos < $thisLen) {
584
+                $thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
585
+                if ($thisPos == 0) {
586
+                    $charNum = intval($thisCharOrd - $decrement[$thisLen]);
587
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
588
+                } else {
589
+                    $charNum = intval($thisCharOrd - 128);
590
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
591
+                }
592
+                $thisPos++;
593
+            }
594
+            $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';';
595
+            $encodedString .= $encodedLetter;
596
+        }
597
+    }
598
+
599
+    return $encodedString;
600 600
 }
601 601
 
602 602
 /**
@@ -615,32 +615,32 @@  discard block
 block discarded – undo
615 615
  **/
616 616
 function utf_32_to_unicode($source) {
617 617
 
618
-	// mb_string : methode rapide
619
-	if (init_mb_string()) {
620
-		$convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
621
-		$source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
622
-
623
-		return str_replace(chr(0), '', $source);
624
-	}
625
-
626
-	// Sinon methode lente
627
-	$texte = '';
628
-	while ($source) {
629
-		$words = unpack('V*', substr($source, 0, 1024));
630
-		$source = substr($source, 1024);
631
-		foreach ($words as $word) {
632
-			if ($word < 128) {
633
-				$texte .= chr($word);
634
-			} // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
635
-			else {
636
-				if ($word != 65279) {
637
-					$texte .= '&#' . $word . ';';
638
-				}
639
-			}
640
-		}
641
-	}
642
-
643
-	return $texte;
618
+    // mb_string : methode rapide
619
+    if (init_mb_string()) {
620
+        $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
621
+        $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
622
+
623
+        return str_replace(chr(0), '', $source);
624
+    }
625
+
626
+    // Sinon methode lente
627
+    $texte = '';
628
+    while ($source) {
629
+        $words = unpack('V*', substr($source, 0, 1024));
630
+        $source = substr($source, 1024);
631
+        foreach ($words as $word) {
632
+            if ($word < 128) {
633
+                $texte .= chr($word);
634
+            } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
635
+            else {
636
+                if ($word != 65279) {
637
+                    $texte .= '&#' . $word . ';';
638
+                }
639
+            }
640
+        }
641
+    }
642
+
643
+    return $texte;
644 644
 }
645 645
 
646 646
 
@@ -657,21 +657,21 @@  discard block
 block discarded – undo
657 657
  *    Caractère utf8 si trouvé, '' sinon
658 658
  **/
659 659
 function caractere_utf_8($num) {
660
-	$num = intval($num);
661
-	if ($num < 128) {
662
-		return chr($num);
663
-	}
664
-	if ($num < 2048) {
665
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
666
-	}
667
-	if ($num < 65536) {
668
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
669
-	}
670
-	if ($num < 1_114_112) {
671
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
672
-	}
673
-
674
-	return '';
660
+    $num = intval($num);
661
+    if ($num < 128) {
662
+        return chr($num);
663
+    }
664
+    if ($num < 2048) {
665
+        return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
666
+    }
667
+    if ($num < 65536) {
668
+        return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
669
+    }
670
+    if ($num < 1_114_112) {
671
+        return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
672
+    }
673
+
674
+    return '';
675 675
 }
676 676
 
677 677
 /**
@@ -684,42 +684,42 @@  discard block
 block discarded – undo
684 684
  **/
685 685
 function unicode_to_utf_8($texte) {
686 686
 
687
-	// 1. Entites &#128; et suivantes
688
-	$vu = [];
689
-	if (
690
-		preg_match_all(
691
-			',&#0*([1-9][0-9][0-9]+);,S',
692
-			$texte,
693
-			$regs,
694
-			PREG_SET_ORDER
695
-		)
696
-	) {
697
-		foreach ($regs as $reg) {
698
-			if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
699
-				$vu[$reg[0]] = caractere_utf_8($reg[1]);
700
-			}
701
-		}
702
-	}
703
-	//$texte = str_replace(array_keys($vu), array_values($vu), $texte);
704
-
705
-	// 2. Entites > &#xFF;
706
-	//$vu = array();
707
-	if (
708
-		preg_match_all(
709
-			',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
710
-			$texte,
711
-			$regs,
712
-			PREG_SET_ORDER
713
-		)
714
-	) {
715
-		foreach ($regs as $reg) {
716
-			if (!isset($vu[$reg[0]])) {
717
-				$vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
718
-			}
719
-		}
720
-	}
721
-
722
-	return str_replace(array_keys($vu), array_values($vu), $texte);
687
+    // 1. Entites &#128; et suivantes
688
+    $vu = [];
689
+    if (
690
+        preg_match_all(
691
+            ',&#0*([1-9][0-9][0-9]+);,S',
692
+            $texte,
693
+            $regs,
694
+            PREG_SET_ORDER
695
+        )
696
+    ) {
697
+        foreach ($regs as $reg) {
698
+            if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
699
+                $vu[$reg[0]] = caractere_utf_8($reg[1]);
700
+            }
701
+        }
702
+    }
703
+    //$texte = str_replace(array_keys($vu), array_values($vu), $texte);
704
+
705
+    // 2. Entites > &#xFF;
706
+    //$vu = array();
707
+    if (
708
+        preg_match_all(
709
+            ',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
710
+            $texte,
711
+            $regs,
712
+            PREG_SET_ORDER
713
+        )
714
+    ) {
715
+        foreach ($regs as $reg) {
716
+            if (!isset($vu[$reg[0]])) {
717
+                $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
718
+            }
719
+        }
720
+    }
721
+
722
+    return str_replace(array_keys($vu), array_values($vu), $texte);
723 723
 }
724 724
 
725 725
 /**
@@ -731,15 +731,15 @@  discard block
 block discarded – undo
731 731
  *     texte converti
732 732
  **/
733 733
 function unicode_to_javascript($texte) {
734
-	$vu = [];
735
-	while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
736
-		$num = $regs[1];
737
-		$vu[$num] = true;
738
-		$s = '\u' . sprintf('%04x', $num);
739
-		$texte = str_replace($regs[0], $s, $texte);
740
-	}
741
-
742
-	return $texte;
734
+    $vu = [];
735
+    while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
736
+        $num = $regs[1];
737
+        $vu[$num] = true;
738
+        $s = '\u' . sprintf('%04x', $num);
739
+        $texte = str_replace($regs[0], $s, $texte);
740
+    }
741
+
742
+    return $texte;
743 743
 }
744 744
 
745 745
 /**
@@ -751,11 +751,11 @@  discard block
 block discarded – undo
751 751
  *     texte converti
752 752
  **/
753 753
 function javascript_to_unicode($texte) {
754
-	while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) {
755
-		$texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte);
756
-	}
754
+    while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) {
755
+        $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte);
756
+    }
757 757
 
758
-	return $texte;
758
+    return $texte;
759 759
 }
760 760
 
761 761
 /**
@@ -767,11 +767,11 @@  discard block
 block discarded – undo
767 767
  *     texte converti
768 768
  **/
769 769
 function javascript_to_binary($texte) {
770
-	while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) {
771
-		$texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
772
-	}
770
+    while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) {
771
+        $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
772
+    }
773 773
 
774
-	return $texte;
774
+    return $texte;
775 775
 }
776 776
 
777 777
 
@@ -789,26 +789,26 @@  discard block
 block discarded – undo
789 789
  * @return string
790 790
  */
791 791
 function translitteration_rapide($texte, $charset = 'AUTO', $complexe = ''): string {
792
-	static $trans = [];
793
-	if ($charset == 'AUTO') {
794
-		$charset = $GLOBALS['meta']['charset'];
795
-	}
796
-	if (!strlen($texte)) {
797
-		return $texte;
798
-	}
799
-
800
-	$table_translit = 'translit' . $complexe;
801
-
802
-	// 2. Translitterer grace a la table predefinie
803
-	if (!isset($trans[$complexe])) {
804
-		$trans[$complexe] = [];
805
-		load_charset($table_translit);
806
-		foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
807
-			$trans[$complexe][caractere_utf_8($key)] = $val;
808
-		}
809
-	}
810
-
811
-	return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
792
+    static $trans = [];
793
+    if ($charset == 'AUTO') {
794
+        $charset = $GLOBALS['meta']['charset'];
795
+    }
796
+    if (!strlen($texte)) {
797
+        return $texte;
798
+    }
799
+
800
+    $table_translit = 'translit' . $complexe;
801
+
802
+    // 2. Translitterer grace a la table predefinie
803
+    if (!isset($trans[$complexe])) {
804
+        $trans[$complexe] = [];
805
+        load_charset($table_translit);
806
+        foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
807
+            $trans[$complexe][caractere_utf_8($key)] = $val;
808
+        }
809
+    }
810
+
811
+    return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
812 812
 }
813 813
 
814 814
 /**
@@ -831,14 +831,14 @@  discard block
 block discarded – undo
831 831
  * @return string
832 832
  */
833 833
 function translitteration($texte, $charset = 'AUTO', $complexe = ''): string {
834
-	// 0. Supprimer les caracteres illegaux
835
-	include_spip('inc/filtres');
836
-	$texte = corriger_caracteres($texte);
834
+    // 0. Supprimer les caracteres illegaux
835
+    include_spip('inc/filtres');
836
+    $texte = corriger_caracteres($texte);
837 837
 
838
-	// 1. Passer le charset et les &eacute en utf-8
839
-	$texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset)));
838
+    // 1. Passer le charset et les &eacute en utf-8
839
+    $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset)));
840 840
 
841
-	return translitteration_rapide($texte, $charset, $complexe);
841
+    return translitteration_rapide($texte, $charset, $complexe);
842 842
 }
843 843
 
844 844
 /**
@@ -853,17 +853,17 @@  discard block
 block discarded – undo
853 853
  * @return string
854 854
  */
855 855
 function translitteration_complexe($texte, $chiffres = false): string {
856
-	$texte = translitteration($texte, 'AUTO', 'complexe');
856
+    $texte = translitteration($texte, 'AUTO', 'complexe');
857 857
 
858
-	if ($chiffres) {
859
-		$texte = preg_replace_callback(
860
-			"/[aeiuoyd]['`?~.^+(-]{1,2}/S",
861
-			fn($m) => translitteration_chiffree($m[0]),
862
-			$texte
863
-		);
864
-	}
858
+    if ($chiffres) {
859
+        $texte = preg_replace_callback(
860
+            "/[aeiuoyd]['`?~.^+(-]{1,2}/S",
861
+            fn($m) => translitteration_chiffree($m[0]),
862
+            $texte
863
+        );
864
+    }
865 865
 
866
-	return $texte;
866
+    return $texte;
867 867
 }
868 868
 
869 869
 /**
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
  * @return string
876 876
  */
877 877
 function translitteration_chiffree($car): string {
878
-	return strtr($car, "'`?~.^+(-", '123456789');
878
+    return strtr($car, "'`?~.^+(-", '123456789');
879 879
 }
880 880
 
881 881
 
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
  *    true s'il a un BOM
889 889
  **/
890 890
 function bom_utf8($texte): bool {
891
-	return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF));
891
+    return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF));
892 892
 }
893 893
 
894 894
 /**
@@ -905,21 +905,21 @@  discard block
 block discarded – undo
905 905
  *     true si c'est le cas
906 906
  **/
907 907
 function is_utf8($string): bool {
908
-	return !strlen(
909
-		preg_replace(
910
-			',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
911
-			. '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
912
-			. '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
913
-			. '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
914
-			. '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
915
-			. '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
916
-			. '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
917
-			. '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
918
-			. ',sS',
919
-			'',
920
-			$string
921
-		)
922
-	);
908
+    return !strlen(
909
+        preg_replace(
910
+            ',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
911
+            . '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
912
+            . '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
913
+            . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
914
+            . '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
915
+            . '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
916
+            . '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
917
+            . '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
918
+            . ',sS',
919
+            '',
920
+            $string
921
+        )
922
+    );
923 923
 }
924 924
 
925 925
 /**
@@ -931,13 +931,13 @@  discard block
 block discarded – undo
931 931
  *     true si c'est le cas
932 932
  **/
933 933
 function is_ascii($string): bool {
934
-	return !strlen(
935
-		preg_replace(
936
-			',[\x09\x0A\x0D\x20-\x7E],sS',
937
-			'',
938
-			$string
939
-		)
940
-	);
934
+    return !strlen(
935
+        preg_replace(
936
+            ',[\x09\x0A\x0D\x20-\x7E],sS',
937
+            '',
938
+            $string
939
+        )
940
+    );
941 941
 }
942 942
 
943 943
 /**
@@ -956,53 +956,53 @@  discard block
 block discarded – undo
956 956
  **/
957 957
 function transcoder_page($texte, $headers = ''): string {
958 958
 
959
-	// Si tout est < 128 pas la peine d'aller plus loin
960
-	if (is_ascii($texte)) {
961
-		#spip_log('charset: ascii');
962
-		return $texte;
963
-	}
964
-
965
-	if (bom_utf8($texte)) {
966
-		// Reconnaitre le BOM utf-8 (0xEFBBBF)
967
-		$charset = 'utf-8';
968
-		$texte = substr($texte, 3);
969
-	} elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
970
-		// charset precise par le contenu (xml)
971
-		$charset = trim(strtolower($regs[1]));
972
-	} elseif (
973
-		// charset precise par le contenu (html)
974
-		preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs)
975
-		# eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette
976
-		and !str_contains($regs[2], '#')
977
-		and $tmp = trim(strtolower($regs[2]))
978
-	) {
979
-		$charset = $tmp;
980
-	} elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
981
-		// charset de la reponse http
982
-		$charset = trim(strtolower($regs[1]));
983
-	} else {
984
-		$charset = '';
985
-	}
986
-
987
-
988
-	// normaliser les noms du shif-jis japonais
989
-	if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
990
-		$charset = 'shift-jis';
991
-	}
992
-
993
-	if ($charset) {
994
-		spip_log("charset: $charset");
995
-	} else {
996
-		// valeur par defaut
997
-		if (is_utf8($texte)) {
998
-			$charset = 'utf-8';
999
-		} else {
1000
-			$charset = 'iso-8859-1';
1001
-		}
1002
-		spip_log("charset probable: $charset");
1003
-	}
1004
-
1005
-	return importer_charset($texte, $charset);
959
+    // Si tout est < 128 pas la peine d'aller plus loin
960
+    if (is_ascii($texte)) {
961
+        #spip_log('charset: ascii');
962
+        return $texte;
963
+    }
964
+
965
+    if (bom_utf8($texte)) {
966
+        // Reconnaitre le BOM utf-8 (0xEFBBBF)
967
+        $charset = 'utf-8';
968
+        $texte = substr($texte, 3);
969
+    } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
970
+        // charset precise par le contenu (xml)
971
+        $charset = trim(strtolower($regs[1]));
972
+    } elseif (
973
+        // charset precise par le contenu (html)
974
+        preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs)
975
+        # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette
976
+        and !str_contains($regs[2], '#')
977
+        and $tmp = trim(strtolower($regs[2]))
978
+    ) {
979
+        $charset = $tmp;
980
+    } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
981
+        // charset de la reponse http
982
+        $charset = trim(strtolower($regs[1]));
983
+    } else {
984
+        $charset = '';
985
+    }
986
+
987
+
988
+    // normaliser les noms du shif-jis japonais
989
+    if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
990
+        $charset = 'shift-jis';
991
+    }
992
+
993
+    if ($charset) {
994
+        spip_log("charset: $charset");
995
+    } else {
996
+        // valeur par defaut
997
+        if (is_utf8($texte)) {
998
+            $charset = 'utf-8';
999
+        } else {
1000
+            $charset = 'iso-8859-1';
1001
+        }
1002
+        spip_log("charset probable: $charset");
1003
+    }
1004
+
1005
+    return importer_charset($texte, $charset);
1006 1006
 }
1007 1007
 
1008 1008
 
@@ -1026,19 +1026,19 @@  discard block
 block discarded – undo
1026 1026
  *     Le texte coupé
1027 1027
  **/
1028 1028
 function spip_substr($c, $start = 0, $length = null) {
1029
-	if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1030
-		if ($length) {
1031
-			return substr($c, $start, $length);
1032
-		} else {
1033
-			return substr($c, $start);
1034
-		}
1035
-	}
1036
-
1037
-	if ($length) {
1038
-		return mb_substr($c, $start, $length);
1039
-	} else {
1040
-		return mb_substr($c, $start);
1041
-	}
1029
+    if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1030
+        if ($length) {
1031
+            return substr($c, $start, $length);
1032
+        } else {
1033
+            return substr($c, $start);
1034
+        }
1035
+    }
1036
+
1037
+    if ($length) {
1038
+        return mb_substr($c, $start, $length);
1039
+    } else {
1040
+        return mb_substr($c, $start);
1041
+    }
1042 1042
 }
1043 1043
 
1044 1044
 /**
@@ -1052,13 +1052,13 @@  discard block
 block discarded – undo
1052 1052
  *     La chaîne avec une majuscule sur le premier mot
1053 1053
  */
1054 1054
 function spip_ucfirst($c) {
1055
-	if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1056
-		return ucfirst($c);
1057
-	}
1055
+    if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1056
+        return ucfirst($c);
1057
+    }
1058 1058
 
1059
-	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1059
+    $lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1060 1060
 
1061
-	return $lettre1 . spip_substr($c, 1);
1061
+    return $lettre1 . spip_substr($c, 1);
1062 1062
 }
1063 1063
 
1064 1064
 /**
@@ -1072,11 +1072,11 @@  discard block
 block discarded – undo
1072 1072
  *     La chaîne en minuscules
1073 1073
  */
1074 1074
 function spip_strtolower($c) {
1075
-	if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1076
-		return strtolower($c);
1077
-	}
1075
+    if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1076
+        return strtolower($c);
1077
+    }
1078 1078
 
1079
-	return mb_strtolower($c);
1079
+    return mb_strtolower($c);
1080 1080
 }
1081 1081
 
1082 1082
 /**
@@ -1090,15 +1090,15 @@  discard block
 block discarded – undo
1090 1090
  *     Longueur de la chaîne
1091 1091
  */
1092 1092
 function spip_strlen($c) {
1093
-	// On transforme les sauts de ligne pour ne pas compter deux caractères
1094
-	$c = str_replace("\r\n", "\n", $c);
1093
+    // On transforme les sauts de ligne pour ne pas compter deux caractères
1094
+    $c = str_replace("\r\n", "\n", $c);
1095 1095
 
1096
-	// Si ce n'est pas utf-8, utiliser strlen
1097
-	if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1098
-		return strlen($c);
1099
-	}
1096
+    // Si ce n'est pas utf-8, utiliser strlen
1097
+    if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1098
+        return strlen($c);
1099
+    }
1100 1100
 
1101
-	return mb_strlen($c);
1101
+    return mb_strlen($c);
1102 1102
 }
1103 1103
 
1104 1104
 /**
@@ -1113,17 +1113,17 @@  discard block
 block discarded – undo
1113 1113
  *     en unicode : &#128169;
1114 1114
  */
1115 1115
 function utf8_noplanes($x): string {
1116
-	$regexp_utf8_4bytes = '/(
1116
+    $regexp_utf8_4bytes = '/(
1117 1117
       \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
1118 1118
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
1119 1119
    |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
1120 1120
 )/xS';
1121
-	if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1122
-		foreach ($z[0] as $k) {
1123
-			$ku = utf_8_to_unicode($k);
1124
-			$x = str_replace($k, $ku, $x);
1125
-		}
1126
-	}
1127
-
1128
-	return $x;
1121
+    if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1122
+        foreach ($z[0] as $k) {
1123
+            $ku = utf_8_to_unicode($k);
1124
+            $x = str_replace($k, $ku, $x);
1125
+        }
1126
+    }
1127
+
1128
+    return $x;
1129 1129
 }
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 		$charset = 'cp1256';
91 91
 	}
92 92
 
93
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
93
+	if (find_in_path($charset.'.php', 'charsets/', true)) {
94 94
 		return $charset;
95 95
 	} else {
96 96
 		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
@@ -195,38 +195,38 @@  discard block
 block discarded – undo
195 195
 
196 196
 	if (!isset($trans[$charset][$charset_cible])) {
197 197
 		$trans[$charset][$charset_cible] = [
198
-			$p . chr(128) => '&#8364;',
199
-			$p . chr(129) => ' ', # pas affecte
200
-			$p . chr(130) => '&#8218;',
201
-			$p . chr(131) => '&#402;',
202
-			$p . chr(132) => '&#8222;',
203
-			$p . chr(133) => '&#8230;',
204
-			$p . chr(134) => '&#8224;',
205
-			$p . chr(135) => '&#8225;',
206
-			$p . chr(136) => '&#710;',
207
-			$p . chr(137) => '&#8240;',
208
-			$p . chr(138) => '&#352;',
209
-			$p . chr(139) => '&#8249;',
210
-			$p . chr(140) => '&#338;',
211
-			$p . chr(141) => ' ', # pas affecte
212
-			$p . chr(142) => '&#381;',
213
-			$p . chr(143) => ' ', # pas affecte
214
-			$p . chr(144) => ' ', # pas affecte
215
-			$p . chr(145) => '&#8216;',
216
-			$p . chr(146) => '&#8217;',
217
-			$p . chr(147) => '&#8220;',
218
-			$p . chr(148) => '&#8221;',
219
-			$p . chr(149) => '&#8226;',
220
-			$p . chr(150) => '&#8211;',
221
-			$p . chr(151) => '&#8212;',
222
-			$p . chr(152) => '&#732;',
223
-			$p . chr(153) => '&#8482;',
224
-			$p . chr(154) => '&#353;',
225
-			$p . chr(155) => '&#8250;',
226
-			$p . chr(156) => '&#339;',
227
-			$p . chr(157) => ' ', # pas affecte
228
-			$p . chr(158) => '&#382;',
229
-			$p . chr(159) => '&#376;',
198
+			$p.chr(128) => '&#8364;',
199
+			$p.chr(129) => ' ', # pas affecte
200
+			$p.chr(130) => '&#8218;',
201
+			$p.chr(131) => '&#402;',
202
+			$p.chr(132) => '&#8222;',
203
+			$p.chr(133) => '&#8230;',
204
+			$p.chr(134) => '&#8224;',
205
+			$p.chr(135) => '&#8225;',
206
+			$p.chr(136) => '&#710;',
207
+			$p.chr(137) => '&#8240;',
208
+			$p.chr(138) => '&#352;',
209
+			$p.chr(139) => '&#8249;',
210
+			$p.chr(140) => '&#338;',
211
+			$p.chr(141) => ' ', # pas affecte
212
+			$p.chr(142) => '&#381;',
213
+			$p.chr(143) => ' ', # pas affecte
214
+			$p.chr(144) => ' ', # pas affecte
215
+			$p.chr(145) => '&#8216;',
216
+			$p.chr(146) => '&#8217;',
217
+			$p.chr(147) => '&#8220;',
218
+			$p.chr(148) => '&#8221;',
219
+			$p.chr(149) => '&#8226;',
220
+			$p.chr(150) => '&#8211;',
221
+			$p.chr(151) => '&#8212;',
222
+			$p.chr(152) => '&#732;',
223
+			$p.chr(153) => '&#8482;',
224
+			$p.chr(154) => '&#353;',
225
+			$p.chr(155) => '&#8250;',
226
+			$p.chr(156) => '&#339;',
227
+			$p.chr(157) => ' ', # pas affecte
228
+			$p.chr(158) => '&#382;',
229
+			$p.chr(159) => '&#376;',
230 230
 		];
231 231
 		if ($charset_cible != 'unicode') {
232 232
 			foreach ($trans[$charset][$charset_cible] as $k => $c) {
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 					and is_array($GLOBALS['CHARSET'][$cset])
368 368
 				) {
369 369
 					foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
370
-						$trans[$charset][chr($key)] = '&#' . $val . ';';
370
+						$trans[$charset][chr($key)] = '&#'.$val.';';
371 371
 					}
372 372
 				}
373 373
 			}
@@ -433,11 +433,11 @@  discard block
 block discarded – undo
433 433
 					$h = dechex($e);
434 434
 					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
435 435
 						$s = $CHARSET_REVERSE[$charset][$e];
436
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
437
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
436
+						$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($s);
437
+						$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($s);
438 438
 					} else {
439
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
440
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
439
+						$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($e);
440
+						$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($e);
441 441
 					}
442 442
 				}
443 443
 			}
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
 				and is_array($GLOBALS['CHARSET'][$cset])
485 485
 			) {
486 486
 				foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
487
-					$trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
487
+					$trans[$charset][chr($key)] = unicode2charset('&#'.$val.';');
488 488
 				}
489 489
 			}
490 490
 		}
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
 				}
592 592
 				$thisPos++;
593 593
 			}
594
-			$encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';';
594
+			$encodedLetter = '&#'.preg_replace('/^0+/', '', $decimalCode).';';
595 595
 			$encodedString .= $encodedLetter;
596 596
 		}
597 597
 	}
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
 			} // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
635 635
 			else {
636 636
 				if ($word != 65279) {
637
-					$texte .= '&#' . $word . ';';
637
+					$texte .= '&#'.$word.';';
638 638
 				}
639 639
 			}
640 640
 		}
@@ -662,13 +662,13 @@  discard block
 block discarded – undo
662 662
 		return chr($num);
663 663
 	}
664 664
 	if ($num < 2048) {
665
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
665
+		return chr(($num >> 6) + 192).chr(($num & 63) + 128);
666 666
 	}
667 667
 	if ($num < 65536) {
668
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
668
+		return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
669 669
 	}
670 670
 	if ($num < 1_114_112) {
671
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
671
+		return chr(($num >> 18) + 240).chr((($num >> 12) & 63) + 128).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
672 672
 	}
673 673
 
674 674
 	return '';
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
 	while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
736 736
 		$num = $regs[1];
737 737
 		$vu[$num] = true;
738
-		$s = '\u' . sprintf('%04x', $num);
738
+		$s = '\u'.sprintf('%04x', $num);
739 739
 		$texte = str_replace($regs[0], $s, $texte);
740 740
 	}
741 741
 
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
  **/
753 753
 function javascript_to_unicode($texte) {
754 754
 	while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) {
755
-		$texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte);
755
+		$texte = str_replace($regs[0], '&#'.hexdec($regs[1]).';', $texte);
756 756
 	}
757 757
 
758 758
 	return $texte;
@@ -797,7 +797,7 @@  discard block
 block discarded – undo
797 797
 		return $texte;
798 798
 	}
799 799
 
800
-	$table_translit = 'translit' . $complexe;
800
+	$table_translit = 'translit'.$complexe;
801 801
 
802 802
 	// 2. Translitterer grace a la table predefinie
803 803
 	if (!isset($trans[$complexe])) {
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
  *    true s'il a un BOM
889 889
  **/
890 890
 function bom_utf8($texte): bool {
891
-	return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF));
891
+	return (substr($texte, 0, 3) === chr(0xEF).chr(0xBB).chr(0xBF));
892 892
 }
893 893
 
894 894
 /**
@@ -1058,7 +1058,7 @@  discard block
 block discarded – undo
1058 1058
 
1059 1059
 	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1060 1060
 
1061
-	return $lettre1 . spip_substr($c, 1);
1061
+	return $lettre1.spip_substr($c, 1);
1062 1062
 }
1063 1063
 
1064 1064
 /**
Please login to merge, or discard this patch.