Completed
Push — master ( 2056af...6c9939 )
by cam
01:09
created
ecrire/inc/filtres_ecrire.php 1 patch
Indentation   +357 added lines, -357 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/filtres_boites');
@@ -41,25 +41,25 @@  discard block
 block discarded – undo
41 41
  */
42 42
 function parametres_css_prive() {
43 43
 
44
-	$args = [];
45
-	$args['v'] = $GLOBALS['spip_version_code'];
46
-	$args['p'] = substr(md5($GLOBALS['meta']['plugin']), 0, 4);
47
-	$args['themes'] = implode(',', lister_themes_prives());
48
-	$args['ltr'] = $GLOBALS['spip_lang_left'];
49
-	// un md5 des menus : si un menu change il faut maj la css
50
-	$args['md5b'] = (function_exists('md5_boutons_plugins') ? md5_boutons_plugins() : '');
44
+    $args = [];
45
+    $args['v'] = $GLOBALS['spip_version_code'];
46
+    $args['p'] = substr(md5($GLOBALS['meta']['plugin']), 0, 4);
47
+    $args['themes'] = implode(',', lister_themes_prives());
48
+    $args['ltr'] = $GLOBALS['spip_lang_left'];
49
+    // un md5 des menus : si un menu change il faut maj la css
50
+    $args['md5b'] = (function_exists('md5_boutons_plugins') ? md5_boutons_plugins() : '');
51 51
 
52
-	$c = $GLOBALS['visiteur_session']['prefs']['couleur'] ?? 2;
52
+    $c = $GLOBALS['visiteur_session']['prefs']['couleur'] ?? 2;
53 53
 
54
-	$couleurs = charger_fonction('couleurs', 'inc');
55
-	parse_str($couleurs($c), $c);
56
-	$args = array_merge($args, $c);
54
+    $couleurs = charger_fonction('couleurs', 'inc');
55
+    parse_str($couleurs($c), $c);
56
+    $args = array_merge($args, $c);
57 57
 
58
-	if (_request('var_mode') == 'recalcul' or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')) {
59
-		$args['var_mode'] = 'recalcul';
60
-	}
58
+    if (_request('var_mode') == 'recalcul' or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')) {
59
+        $args['var_mode'] = 'recalcul';
60
+    }
61 61
 
62
-	return http_build_query($args);
62
+    return http_build_query($args);
63 63
 }
64 64
 
65 65
 
@@ -82,91 +82,91 @@  discard block
 block discarded – undo
82 82
  * @return string
83 83
  */
84 84
 function chercher_rubrique(
85
-	$titre,
86
-	$id_objet,
87
-	$id_parent,
88
-	$objet,
89
-	$id_secteur,
90
-	$restreint,
91
-	$actionable = false,
92
-	$retour_sans_cadre = false
85
+    $titre,
86
+    $id_objet,
87
+    $id_parent,
88
+    $objet,
89
+    $id_secteur,
90
+    $restreint,
91
+    $actionable = false,
92
+    $retour_sans_cadre = false
93 93
 ) {
94 94
 
95
-	include_spip('inc/autoriser');
96
-	if (intval($id_objet) && !autoriser('modifier', $objet, $id_objet)) {
97
-		return '';
98
-	}
99
-	if (!sql_countsel('spip_rubriques')) {
100
-		return '';
101
-	}
102
-	$chercher_rubrique = charger_fonction('chercher_rubrique', 'inc');
103
-	$form = $chercher_rubrique($id_parent, $objet, $restreint, ($objet == 'rubrique') ? $id_objet : 0);
104
-
105
-	if ($id_parent == 0) {
106
-		$logo = 'racine-24.png';
107
-	} elseif ($id_secteur == $id_parent) {
108
-		$logo = 'secteur-24.png';
109
-	} else {
110
-		$logo = 'rubrique-24.png';
111
-	}
112
-
113
-	$confirm = '';
114
-	if ($objet == 'rubrique') {
115
-		// si c'est une rubrique-secteur contenant des breves, demander la
116
-		// confirmation du deplacement
117
-		$contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . intval($id_objet));
118
-
119
-		if ($contient_breves > 0) {
120
-			$scb = ($contient_breves > 1 ? 's' : '');
121
-			$scb = _T(
122
-				'avis_deplacement_rubrique',
123
-				[
124
-					'contient_breves' => $contient_breves,
125
-					'scb' => $scb
126
-				]
127
-			);
128
-			$confirm .= "\n<div class='confirmer_deplacement verdana2'>"
129
-				. "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>"
130
-				. $scb .
131
-				"</label></div></div>\n";
132
-		} else {
133
-			$confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n";
134
-		}
135
-	}
136
-	$form .= $confirm;
137
-	if ($actionable) {
138
-		if (strpos($form, '<select') !== false) {
139
-			$form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>"
140
-				. '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>'
141
-				. '</div>';
142
-		}
143
-		$form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form;
144
-		if ($action = charger_fonction("editer_$objet", 'action', true)) {
145
-			$form = generer_action_auteur(
146
-				"editer_$objet",
147
-				$id_objet,
148
-				self(),
149
-				$form,
150
-				" method='post' class='submit_plongeur'"
151
-			);
152
-		} else {
153
-			$form = generer_action_auteur(
154
-				'editer_objet',
155
-				"$objet/$id_objet",
156
-				self(),
157
-				$form,
158
-				" method='post' class='submit_plongeur'"
159
-			);
160
-		}
161
-	}
162
-
163
-	if ($retour_sans_cadre) {
164
-		return $form;
165
-	}
166
-
167
-	include_spip('inc/presentation');
168
-
169
-	return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur(true);
95
+    include_spip('inc/autoriser');
96
+    if (intval($id_objet) && !autoriser('modifier', $objet, $id_objet)) {
97
+        return '';
98
+    }
99
+    if (!sql_countsel('spip_rubriques')) {
100
+        return '';
101
+    }
102
+    $chercher_rubrique = charger_fonction('chercher_rubrique', 'inc');
103
+    $form = $chercher_rubrique($id_parent, $objet, $restreint, ($objet == 'rubrique') ? $id_objet : 0);
104
+
105
+    if ($id_parent == 0) {
106
+        $logo = 'racine-24.png';
107
+    } elseif ($id_secteur == $id_parent) {
108
+        $logo = 'secteur-24.png';
109
+    } else {
110
+        $logo = 'rubrique-24.png';
111
+    }
112
+
113
+    $confirm = '';
114
+    if ($objet == 'rubrique') {
115
+        // si c'est une rubrique-secteur contenant des breves, demander la
116
+        // confirmation du deplacement
117
+        $contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . intval($id_objet));
118
+
119
+        if ($contient_breves > 0) {
120
+            $scb = ($contient_breves > 1 ? 's' : '');
121
+            $scb = _T(
122
+                'avis_deplacement_rubrique',
123
+                [
124
+                    'contient_breves' => $contient_breves,
125
+                    'scb' => $scb
126
+                ]
127
+            );
128
+            $confirm .= "\n<div class='confirmer_deplacement verdana2'>"
129
+                . "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>"
130
+                . $scb .
131
+                "</label></div></div>\n";
132
+        } else {
133
+            $confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n";
134
+        }
135
+    }
136
+    $form .= $confirm;
137
+    if ($actionable) {
138
+        if (strpos($form, '<select') !== false) {
139
+            $form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>"
140
+                . '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>'
141
+                . '</div>';
142
+        }
143
+        $form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form;
144
+        if ($action = charger_fonction("editer_$objet", 'action', true)) {
145
+            $form = generer_action_auteur(
146
+                "editer_$objet",
147
+                $id_objet,
148
+                self(),
149
+                $form,
150
+                " method='post' class='submit_plongeur'"
151
+            );
152
+        } else {
153
+            $form = generer_action_auteur(
154
+                'editer_objet',
155
+                "$objet/$id_objet",
156
+                self(),
157
+                $form,
158
+                " method='post' class='submit_plongeur'"
159
+            );
160
+        }
161
+    }
162
+
163
+    if ($retour_sans_cadre) {
164
+        return $form;
165
+    }
166
+
167
+    include_spip('inc/presentation');
168
+
169
+    return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur(true);
170 170
 }
171 171
 
172 172
 
@@ -180,24 +180,24 @@  discard block
 block discarded – undo
180 180
  * @return bool
181 181
  */
182 182
 function avoir_visiteurs($past = false, $accepter = true) {
183
-	if ($GLOBALS['meta']['forums_publics'] == 'abo') {
184
-		return true;
185
-	}
186
-	if ($accepter and $GLOBALS['meta']['accepter_visiteurs'] <> 'non') {
187
-		return true;
188
-	}
189
-	if (sql_countsel('spip_articles', "accepter_forum='abo'")) {
190
-		return true;
191
-	}
192
-	if (!$past) {
193
-		return false;
194
-	}
195
-
196
-	return sql_countsel(
197
-		'spip_auteurs',
198
-		"statut NOT IN ('0minirezo','1comite', '5poubelle')
183
+    if ($GLOBALS['meta']['forums_publics'] == 'abo') {
184
+        return true;
185
+    }
186
+    if ($accepter and $GLOBALS['meta']['accepter_visiteurs'] <> 'non') {
187
+        return true;
188
+    }
189
+    if (sql_countsel('spip_articles', "accepter_forum='abo'")) {
190
+        return true;
191
+    }
192
+    if (!$past) {
193
+        return false;
194
+    }
195
+
196
+    return sql_countsel(
197
+        'spip_auteurs',
198
+        "statut NOT IN ('0minirezo','1comite', '5poubelle')
199 199
 	                    AND (statut<>'nouveau' OR prefs NOT IN ('0minirezo','1comite', '5poubelle'))"
200
-	);
200
+    );
201 201
 }
202 202
 
203 203
 /**
@@ -213,18 +213,18 @@  discard block
 block discarded – undo
213 213
  * @return array
214 214
  */
215 215
 function statuts_articles_visibles($statut_auteur) {
216
-	static $auth = [];
217
-	if (!isset($auth[$statut_auteur])) {
218
-		$auth[$statut_auteur] = [];
219
-		$statuts = array_column(sql_allfetsel('distinct statut', 'spip_articles'), 'statut');
220
-		foreach ($statuts as $s) {
221
-			if (autoriser('voir', 'article', 0, ['statut' => $statut_auteur], ['statut' => $s])) {
222
-				$auth[$statut_auteur][] = $s;
223
-			}
224
-		}
225
-	}
226
-
227
-	return $auth[$statut_auteur];
216
+    static $auth = [];
217
+    if (!isset($auth[$statut_auteur])) {
218
+        $auth[$statut_auteur] = [];
219
+        $statuts = array_column(sql_allfetsel('distinct statut', 'spip_articles'), 'statut');
220
+        foreach ($statuts as $s) {
221
+            if (autoriser('voir', 'article', 0, ['statut' => $statut_auteur], ['statut' => $s])) {
222
+                $auth[$statut_auteur][] = $s;
223
+            }
224
+        }
225
+    }
226
+
227
+    return $auth[$statut_auteur];
228 228
 }
229 229
 
230 230
 /**
@@ -238,38 +238,38 @@  discard block
 block discarded – undo
238 238
  * @return string
239 239
  */
240 240
 function traduire_statut_auteur($statut, $attente = '') {
241
-	$plus = '';
242
-	if ($statut == 'nouveau') {
243
-		if ($attente) {
244
-			$statut = $attente;
245
-			$plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')';
246
-		} else {
247
-			return _T('info_statut_auteur_a_confirmer');
248
-		}
249
-	}
250
-
251
-	$recom = [
252
-		'info_administrateurs' => _T('item_administrateur_2'),
253
-		'info_redacteurs' => _T('intem_redacteur'),
254
-		'info_visiteurs' => _T('item_visiteur'),
255
-		'5poubelle' => _T('texte_statut_poubelle'), // bouh
256
-	];
257
-	if (isset($recom[$statut])) {
258
-		return $recom[$statut] . $plus;
259
-	}
260
-
261
-	// retrouver directement par le statut sinon
262
-	if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) {
263
-		if (isset($recom[$t])) {
264
-			return $recom[$t] . $plus;
265
-		}
266
-
267
-		return _T($t) . $plus;
268
-	}
269
-
270
-	// si on a pas reussi a le traduire, retournons la chaine telle quelle
271
-	// c'est toujours plus informatif que rien du tout
272
-	return $statut;
241
+    $plus = '';
242
+    if ($statut == 'nouveau') {
243
+        if ($attente) {
244
+            $statut = $attente;
245
+            $plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')';
246
+        } else {
247
+            return _T('info_statut_auteur_a_confirmer');
248
+        }
249
+    }
250
+
251
+    $recom = [
252
+        'info_administrateurs' => _T('item_administrateur_2'),
253
+        'info_redacteurs' => _T('intem_redacteur'),
254
+        'info_visiteurs' => _T('item_visiteur'),
255
+        '5poubelle' => _T('texte_statut_poubelle'), // bouh
256
+    ];
257
+    if (isset($recom[$statut])) {
258
+        return $recom[$statut] . $plus;
259
+    }
260
+
261
+    // retrouver directement par le statut sinon
262
+    if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) {
263
+        if (isset($recom[$t])) {
264
+            return $recom[$t] . $plus;
265
+        }
266
+
267
+        return _T($t) . $plus;
268
+    }
269
+
270
+    // si on a pas reussi a le traduire, retournons la chaine telle quelle
271
+    // c'est toujours plus informatif que rien du tout
272
+    return $statut;
273 273
 }
274 274
 
275 275
 /**
@@ -280,28 +280,28 @@  discard block
 block discarded – undo
280 280
  * @return string
281 281
  */
282 282
 function afficher_qui_edite($id_objet, $objet) {
283
-	static $qui = [];
284
-	if (isset($qui[$objet][$id_objet])) {
285
-		return $qui[$objet][$id_objet];
286
-	}
287
-
288
-	if ($GLOBALS['meta']['articles_modif'] == 'non') {
289
-		return $qui[$objet][$id_objet] = '';
290
-	}
291
-
292
-	include_spip('inc/drapeau_edition');
293
-	$modif = mention_qui_edite($id_objet, $objet);
294
-	if (!$modif) {
295
-		return $qui[$objet][$id_objet] = '';
296
-	}
297
-
298
-	include_spip('base/objets');
299
-	$infos = lister_tables_objets_sql(table_objet_sql($objet));
300
-	if (isset($infos['texte_signale_edition'])) {
301
-		return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif);
302
-	}
303
-
304
-	return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif);
283
+    static $qui = [];
284
+    if (isset($qui[$objet][$id_objet])) {
285
+        return $qui[$objet][$id_objet];
286
+    }
287
+
288
+    if ($GLOBALS['meta']['articles_modif'] == 'non') {
289
+        return $qui[$objet][$id_objet] = '';
290
+    }
291
+
292
+    include_spip('inc/drapeau_edition');
293
+    $modif = mention_qui_edite($id_objet, $objet);
294
+    if (!$modif) {
295
+        return $qui[$objet][$id_objet] = '';
296
+    }
297
+
298
+    include_spip('base/objets');
299
+    $infos = lister_tables_objets_sql(table_objet_sql($objet));
300
+    if (isset($infos['texte_signale_edition'])) {
301
+        return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif);
302
+    }
303
+
304
+    return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif);
305 305
 }
306 306
 
307 307
 /**
@@ -319,57 +319,57 @@  discard block
 block discarded – undo
319 319
  * @return array
320 320
  */
321 321
 function auteurs_lister_statuts($quoi = 'tous', $en_base = true) {
322
-	if (!defined('AUTEURS_MIN_REDAC')) {
323
-		define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle');
324
-	}
325
-
326
-	switch ($quoi) {
327
-		case 'redacteurs':
328
-			$statut = AUTEURS_MIN_REDAC;
329
-			$statut = explode(',', $statut);
330
-			if ($en_base) {
331
-				$check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut');
332
-				$retire = array_diff($statut, $check);
333
-				$statut = array_diff($statut, $retire);
334
-			}
335
-
336
-			return array_unique($statut);
337
-			break;
338
-		case 'visiteurs':
339
-			$statut = [];
340
-			$exclus = AUTEURS_MIN_REDAC;
341
-			$exclus = explode(',', $exclus);
342
-			if (!$en_base) {
343
-				// prendre aussi les statuts de la table des status qui ne sont pas dans le define
344
-				$statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus);
345
-			}
346
-			$s_complement = array_column(
347
-				sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')),
348
-				'statut'
349
-			);
350
-
351
-			return array_unique(array_merge($statut, $s_complement));
352
-			break;
353
-		default:
354
-		case 'tous':
355
-			$statut = array_values($GLOBALS['liste_des_statuts']);
356
-			$s_complement = array_column(
357
-				sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')),
358
-				'statut'
359
-			);
360
-			$statut = array_merge($statut, $s_complement);
361
-			if ($en_base) {
362
-				$check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut');
363
-				$retire = array_diff($statut, $check);
364
-				$statut = array_diff($statut, $retire);
365
-			}
366
-
367
-			return array_unique($statut);
368
-			break;
369
-	}
370
-
371
-	// on arrive jamais ici
372
-	return array_values($GLOBALS['liste_des_statuts']);
322
+    if (!defined('AUTEURS_MIN_REDAC')) {
323
+        define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle');
324
+    }
325
+
326
+    switch ($quoi) {
327
+        case 'redacteurs':
328
+            $statut = AUTEURS_MIN_REDAC;
329
+            $statut = explode(',', $statut);
330
+            if ($en_base) {
331
+                $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut');
332
+                $retire = array_diff($statut, $check);
333
+                $statut = array_diff($statut, $retire);
334
+            }
335
+
336
+            return array_unique($statut);
337
+            break;
338
+        case 'visiteurs':
339
+            $statut = [];
340
+            $exclus = AUTEURS_MIN_REDAC;
341
+            $exclus = explode(',', $exclus);
342
+            if (!$en_base) {
343
+                // prendre aussi les statuts de la table des status qui ne sont pas dans le define
344
+                $statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus);
345
+            }
346
+            $s_complement = array_column(
347
+                sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')),
348
+                'statut'
349
+            );
350
+
351
+            return array_unique(array_merge($statut, $s_complement));
352
+            break;
353
+        default:
354
+        case 'tous':
355
+            $statut = array_values($GLOBALS['liste_des_statuts']);
356
+            $s_complement = array_column(
357
+                sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')),
358
+                'statut'
359
+            );
360
+            $statut = array_merge($statut, $s_complement);
361
+            if ($en_base) {
362
+                $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut');
363
+                $retire = array_diff($statut, $check);
364
+                $statut = array_diff($statut, $retire);
365
+            }
366
+
367
+            return array_unique($statut);
368
+            break;
369
+    }
370
+
371
+    // on arrive jamais ici
372
+    return array_values($GLOBALS['liste_des_statuts']);
373 373
 }
374 374
 
375 375
 /**
@@ -385,28 +385,28 @@  discard block
 block discarded – undo
385 385
  */
386 386
 function trouver_rubrique_creer_objet($id_rubrique, $objet) {
387 387
 
388
-	if (!$id_rubrique and defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') and _CHOIX_RUBRIQUE_PAR_DEFAUT) {
389
-		$in = !count($GLOBALS['connect_id_rubrique'])
390
-			? ''
391
-			: (' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique']));
392
-
393
-		// on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement
394
-		if ($objet == 'rubrique') {
395
-			$id_rubrique = 0;
396
-		} else {
397
-			$id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1);
398
-		}
399
-
400
-		if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) {
401
-			// manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises
402
-			$res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0');
403
-			while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) {
404
-				$id_rubrique = $row_rub['id_rubrique'];
405
-			}
406
-		}
407
-	}
408
-
409
-	return $id_rubrique;
388
+    if (!$id_rubrique and defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') and _CHOIX_RUBRIQUE_PAR_DEFAUT) {
389
+        $in = !count($GLOBALS['connect_id_rubrique'])
390
+            ? ''
391
+            : (' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique']));
392
+
393
+        // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement
394
+        if ($objet == 'rubrique') {
395
+            $id_rubrique = 0;
396
+        } else {
397
+            $id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1);
398
+        }
399
+
400
+        if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) {
401
+            // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises
402
+            $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0');
403
+            while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) {
404
+                $id_rubrique = $row_rub['id_rubrique'];
405
+            }
406
+        }
407
+    }
408
+
409
+    return $id_rubrique;
410 410
 }
411 411
 
412 412
 /**
@@ -417,12 +417,12 @@  discard block
 block discarded – undo
417 417
  * @return string
418 418
  */
419 419
 function lien_article_virtuel($virtuel) {
420
-	include_spip('inc/lien');
421
-	if (!$virtuel = virtuel_redirige($virtuel)) {
422
-		return '';
423
-	}
420
+    include_spip('inc/lien');
421
+    if (!$virtuel = virtuel_redirige($virtuel)) {
422
+        return '';
423
+    }
424 424
 
425
-	return propre('[->' . $virtuel . ']');
425
+    return propre('[->' . $virtuel . ']');
426 426
 }
427 427
 
428 428
 
@@ -445,12 +445,12 @@  discard block
 block discarded – undo
445 445
  *     Code HTML du lien
446 446
  */
447 447
 function bouton_spip_rss($op, $args = [], $lang = '', $title = 'RSS') {
448
-	include_spip('inc/acces');
449
-	$clic = http_img_pack('rss-16.png', 'RSS', '', $title);
450
-	$args = param_low_sec($op, $args, $lang, 'rss');
451
-	$url = generer_url_public('rss', $args);
448
+    include_spip('inc/acces');
449
+    $clic = http_img_pack('rss-16.png', 'RSS', '', $title);
450
+    $args = param_low_sec($op, $args, $lang, 'rss');
451
+    $url = generer_url_public('rss', $args);
452 452
 
453
-	return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>";
453
+    return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>";
454 454
 }
455 455
 
456 456
 
@@ -462,74 +462,74 @@  discard block
 block discarded – undo
462 462
  */
463 463
 function alertes_auteur($id_auteur) {
464 464
 
465
-	$alertes = [];
466
-
467
-	if (
468
-		isset($GLOBALS['meta']['message_crash_tables'])
469
-		and autoriser('detruire', null, null, $id_auteur)
470
-	) {
471
-		include_spip('genie/maintenance');
472
-		if ($msg = message_crash_tables()) {
473
-			$alertes[] = $msg;
474
-		}
475
-	}
476
-
477
-	if (
478
-		isset($GLOBALS['meta']['message_crash_plugins'])
479
-		and $GLOBALS['meta']['message_crash_plugins']
480
-		and autoriser('configurer', '_plugins', null, $id_auteur)
481
-		and is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins']))
482
-	) {
483
-		$msg = implode(', ', array_map('joli_repertoire', array_keys($msg)));
484
-		$alertes[] = _T('plugins_erreur', ['plugins' => $msg]);
485
-	}
486
-
487
-	$a = $GLOBALS['meta']['message_alertes_auteurs'] ?? '';
488
-	if (
489
-		$a
490
-		and is_array($a = unserialize($a))
491
-		and count($a)
492
-	) {
493
-		$update = false;
494
-		if (isset($a[$GLOBALS['visiteur_session']['statut']])) {
495
-			$alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]);
496
-			unset($a[$GLOBALS['visiteur_session']['statut']]);
497
-			$update = true;
498
-		}
499
-		if (isset($a[''])) {
500
-			$alertes = array_merge($alertes, $a['']);
501
-			unset($a['']);
502
-			$update = true;
503
-		}
504
-		if ($update) {
505
-			ecrire_meta('message_alertes_auteurs', serialize($a));
506
-		}
507
-	}
508
-
509
-	if (
510
-		isset($GLOBALS['meta']['plugin_erreur_activation'])
511
-		and autoriser('configurer', '_plugins', null, $id_auteur)
512
-	) {
513
-		include_spip('inc/plugin');
514
-		$alertes[] = plugin_donne_erreurs();
515
-	}
516
-
517
-	$alertes = pipeline(
518
-		'alertes_auteur',
519
-		[
520
-			'args' => [
521
-				'id_auteur' => $id_auteur,
522
-				'exec' => _request('exec'),
523
-			],
524
-			'data' => $alertes
525
-		]
526
-	);
527
-
528
-	if ($alertes = array_filter($alertes)) {
529
-		return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" .
530
-		join(' | ', $alertes)
531
-		. '</div></div>';
532
-	}
465
+    $alertes = [];
466
+
467
+    if (
468
+        isset($GLOBALS['meta']['message_crash_tables'])
469
+        and autoriser('detruire', null, null, $id_auteur)
470
+    ) {
471
+        include_spip('genie/maintenance');
472
+        if ($msg = message_crash_tables()) {
473
+            $alertes[] = $msg;
474
+        }
475
+    }
476
+
477
+    if (
478
+        isset($GLOBALS['meta']['message_crash_plugins'])
479
+        and $GLOBALS['meta']['message_crash_plugins']
480
+        and autoriser('configurer', '_plugins', null, $id_auteur)
481
+        and is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins']))
482
+    ) {
483
+        $msg = implode(', ', array_map('joli_repertoire', array_keys($msg)));
484
+        $alertes[] = _T('plugins_erreur', ['plugins' => $msg]);
485
+    }
486
+
487
+    $a = $GLOBALS['meta']['message_alertes_auteurs'] ?? '';
488
+    if (
489
+        $a
490
+        and is_array($a = unserialize($a))
491
+        and count($a)
492
+    ) {
493
+        $update = false;
494
+        if (isset($a[$GLOBALS['visiteur_session']['statut']])) {
495
+            $alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]);
496
+            unset($a[$GLOBALS['visiteur_session']['statut']]);
497
+            $update = true;
498
+        }
499
+        if (isset($a[''])) {
500
+            $alertes = array_merge($alertes, $a['']);
501
+            unset($a['']);
502
+            $update = true;
503
+        }
504
+        if ($update) {
505
+            ecrire_meta('message_alertes_auteurs', serialize($a));
506
+        }
507
+    }
508
+
509
+    if (
510
+        isset($GLOBALS['meta']['plugin_erreur_activation'])
511
+        and autoriser('configurer', '_plugins', null, $id_auteur)
512
+    ) {
513
+        include_spip('inc/plugin');
514
+        $alertes[] = plugin_donne_erreurs();
515
+    }
516
+
517
+    $alertes = pipeline(
518
+        'alertes_auteur',
519
+        [
520
+            'args' => [
521
+                'id_auteur' => $id_auteur,
522
+                'exec' => _request('exec'),
523
+            ],
524
+            'data' => $alertes
525
+        ]
526
+    );
527
+
528
+    if ($alertes = array_filter($alertes)) {
529
+        return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" .
530
+        join(' | ', $alertes)
531
+        . '</div></div>';
532
+    }
533 533
 }
534 534
 
535 535
 /**
@@ -539,9 +539,9 @@  discard block
 block discarded – undo
539 539
  * @return string
540 540
  */
541 541
 function filtre_afficher_enfant_rub_dist($id_rubrique) {
542
-	include_spip('inc/presenter_enfants');
542
+    include_spip('inc/presenter_enfants');
543 543
 
544
-	return afficher_enfant_rub(intval($id_rubrique));
544
+    return afficher_enfant_rub(intval($id_rubrique));
545 545
 }
546 546
 
547 547
 /**
@@ -559,15 +559,15 @@  discard block
 block discarded – undo
559 559
  * @return string
560 560
  */
561 561
 function afficher_plus_info($lien, $titre = '+', $titre_lien = '') {
562
-	$titre = attribut_html($titre);
563
-	$icone = "\n<a href='$lien' title='$titre' class='plus_info'>" .
564
-		http_img_pack('information-16.png', $titre) . '</a>';
565
-
566
-	if (!$titre_lien) {
567
-		return $icone;
568
-	} else {
569
-		return $icone . "\n<a href='$lien'>$titre_lien</a>";
570
-	}
562
+    $titre = attribut_html($titre);
563
+    $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" .
564
+        http_img_pack('information-16.png', $titre) . '</a>';
565
+
566
+    if (!$titre_lien) {
567
+        return $icone;
568
+    } else {
569
+        return $icone . "\n<a href='$lien'>$titre_lien</a>";
570
+    }
571 571
 }
572 572
 
573 573
 
@@ -586,17 +586,17 @@  discard block
 block discarded – undo
586 586
  * @return array
587 587
  */
588 588
 function lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien) {
589
-	$res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien);
590
-	if (!count($res)) {
591
-		return [];
592
-	}
593
-	$r = reset($res);
594
-	if (isset($r['rang_lien'])) {
595
-		$l = array_column($res, 'rang_lien', $objet_source);
596
-		asort($l);
597
-		$l = array_keys($l);
598
-	} else {
599
-		$l = array_column($res, $objet_source);
600
-	}
601
-	return $l;
589
+    $res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien);
590
+    if (!count($res)) {
591
+        return [];
592
+    }
593
+    $r = reset($res);
594
+    if (isset($r['rang_lien'])) {
595
+        $l = array_column($res, 'rang_lien', $objet_source);
596
+        asort($l);
597
+        $l = array_keys($l);
598
+    } else {
599
+        $l = array_column($res, $objet_source);
600
+    }
601
+    return $l;
602 602
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres_images_lib_mini.php 2 patches
Indentation   +1346 added lines, -1346 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  */
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 include_spip('inc/filtres'); // par precaution
24 24
 include_spip('inc/filtres_images_mini'); // par precaution
@@ -38,21 +38,21 @@  discard block
 block discarded – undo
38 38
  *     Le code de la couleur en hexadécimal.
39 39
  */
40 40
 function _couleur_dec_to_hex($red, $green, $blue) {
41
-	$red = dechex($red);
42
-	$green = dechex($green);
43
-	$blue = dechex($blue);
44
-
45
-	if (strlen($red) == 1) {
46
-		$red = '0' . $red;
47
-	}
48
-	if (strlen($green) == 1) {
49
-		$green = '0' . $green;
50
-	}
51
-	if (strlen($blue) == 1) {
52
-		$blue = '0' . $blue;
53
-	}
54
-
55
-	return "$red$green$blue";
41
+    $red = dechex($red);
42
+    $green = dechex($green);
43
+    $blue = dechex($blue);
44
+
45
+    if (strlen($red) == 1) {
46
+        $red = '0' . $red;
47
+    }
48
+    if (strlen($green) == 1) {
49
+        $green = '0' . $green;
50
+    }
51
+    if (strlen($blue) == 1) {
52
+        $blue = '0' . $blue;
53
+    }
54
+
55
+    return "$red$green$blue";
56 56
 }
57 57
 
58 58
 /**
@@ -64,17 +64,17 @@  discard block
 block discarded – undo
64 64
  *     Un tableau des 3 éléments : rouge, vert, bleu.
65 65
  */
66 66
 function _couleur_hex_to_dec($couleur) {
67
-	$couleur = couleur_html_to_hex($couleur);
68
-	$couleur = ltrim($couleur, '#');
69
-	if (strlen($couleur) === 3) {
70
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
71
-	}
72
-	$retour = [];
73
-	$retour['red'] = hexdec(substr($couleur, 0, 2));
74
-	$retour['green'] = hexdec(substr($couleur, 2, 2));
75
-	$retour['blue'] = hexdec(substr($couleur, 4, 2));
76
-
77
-	return $retour;
67
+    $couleur = couleur_html_to_hex($couleur);
68
+    $couleur = ltrim($couleur, '#');
69
+    if (strlen($couleur) === 3) {
70
+        $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
71
+    }
72
+    $retour = [];
73
+    $retour['red'] = hexdec(substr($couleur, 0, 2));
74
+    $retour['green'] = hexdec(substr($couleur, 2, 2));
75
+    $retour['blue'] = hexdec(substr($couleur, 4, 2));
76
+
77
+    return $retour;
78 78
 }
79 79
 
80 80
 
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
  *     Le code de la couleur en hexadécimal.
92 92
  */
93 93
 function _couleur_hsl_to_hex($hue, $saturation, $lightness) {
94
-	$rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
95
-	return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
94
+    $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
95
+    return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
96 96
 }
97 97
 
98 98
 /**
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
  *     Un tableau des 3 éléments : teinte, saturation, luminosité.
105 105
  */
106 106
 function _couleur_hex_to_hsl($couleur) {
107
-	$rgb = _couleur_hex_to_dec($couleur);
108
-	return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
107
+    $rgb = _couleur_hex_to_dec($couleur);
108
+    return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
109 109
 }
110 110
 
111 111
 /**
@@ -120,58 +120,58 @@  discard block
 block discarded – undo
120 120
  * @return array
121 121
  */
122 122
 function _couleur_rgb_to_hsl($R, $G, $B) {
123
-	$var_R = ($R / 255); // Where RGB values = 0 ÷ 255
124
-	$var_G = ($G / 255);
125
-	$var_B = ($B / 255);
126
-
127
-	$var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
128
-	$var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
129
-	$del_Max = $var_Max - $var_Min;           //Delta RGB value
130
-
131
-	$L = ($var_Max + $var_Min) / 2;
132
-
133
-	if ($del_Max == 0) {
134
-		//This is a gray, no chroma...
135
-		$H = 0; //HSL results = 0 ÷ 1
136
-		$S = 0;
137
-	} else {
138
-		// Chromatic data...
139
-		if ($L < 0.5) {
140
-			$S = $del_Max / ($var_Max + $var_Min);
141
-		} else {
142
-			$S = $del_Max / (2 - $var_Max - $var_Min);
143
-		}
144
-
145
-		$del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
146
-		$del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
147
-		$del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
148
-
149
-		if ($var_R == $var_Max) {
150
-			$H = $del_B - $del_G;
151
-		} else {
152
-			if ($var_G == $var_Max) {
153
-				$H = (1 / 3) + $del_R - $del_B;
154
-			} else {
155
-				if ($var_B == $var_Max) {
156
-					$H = (2 / 3) + $del_G - $del_R;
157
-				}
158
-			}
159
-		}
160
-
161
-		if ($H < 0) {
162
-			$H += 1;
163
-		}
164
-		if ($H > 1) {
165
-			$H -= 1;
166
-		}
167
-	}
168
-
169
-	$ret = [];
170
-	$ret['h'] = $H;
171
-	$ret['s'] = $S;
172
-	$ret['l'] = $L;
173
-
174
-	return $ret;
123
+    $var_R = ($R / 255); // Where RGB values = 0 ÷ 255
124
+    $var_G = ($G / 255);
125
+    $var_B = ($B / 255);
126
+
127
+    $var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
128
+    $var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
129
+    $del_Max = $var_Max - $var_Min;           //Delta RGB value
130
+
131
+    $L = ($var_Max + $var_Min) / 2;
132
+
133
+    if ($del_Max == 0) {
134
+        //This is a gray, no chroma...
135
+        $H = 0; //HSL results = 0 ÷ 1
136
+        $S = 0;
137
+    } else {
138
+        // Chromatic data...
139
+        if ($L < 0.5) {
140
+            $S = $del_Max / ($var_Max + $var_Min);
141
+        } else {
142
+            $S = $del_Max / (2 - $var_Max - $var_Min);
143
+        }
144
+
145
+        $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
146
+        $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
147
+        $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
148
+
149
+        if ($var_R == $var_Max) {
150
+            $H = $del_B - $del_G;
151
+        } else {
152
+            if ($var_G == $var_Max) {
153
+                $H = (1 / 3) + $del_R - $del_B;
154
+            } else {
155
+                if ($var_B == $var_Max) {
156
+                    $H = (2 / 3) + $del_G - $del_R;
157
+                }
158
+            }
159
+        }
160
+
161
+        if ($H < 0) {
162
+            $H += 1;
163
+        }
164
+        if ($H > 1) {
165
+            $H -= 1;
166
+        }
167
+    }
168
+
169
+    $ret = [];
170
+    $ret['h'] = $H;
171
+    $ret['s'] = $S;
172
+    $ret['l'] = $L;
173
+
174
+    return $ret;
175 175
 }
176 176
 
177 177
 
@@ -187,52 +187,52 @@  discard block
 block discarded – undo
187 187
  * @return array
188 188
  */
189 189
 function _couleur_hsl_to_rgb($H, $S, $L) {
190
-	// helper
191
-	$hue_2_rgb = function ($v1, $v2, $vH) {
192
-		if ($vH < 0) {
193
-			$vH += 1;
194
-		}
195
-		if ($vH > 1) {
196
-			$vH -= 1;
197
-		}
198
-		if ((6 * $vH) < 1) {
199
-			return ($v1 + ($v2 - $v1) * 6 * $vH);
200
-		}
201
-		if ((2 * $vH) < 1) {
202
-			return ($v2);
203
-		}
204
-		if ((3 * $vH) < 2) {
205
-			return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
206
-		}
207
-
208
-		return ($v1);
209
-	};
210
-
211
-	if ($S == 0) {
212
-		// HSV values = 0 -> 1
213
-		$R = $L * 255;
214
-		$G = $L * 255;
215
-		$B = $L * 255;
216
-	} else {
217
-		if ($L < 0.5) {
218
-			$var_2 = $L * (1 + $S);
219
-		} else {
220
-			$var_2 = ($L + $S) - ($S * $L);
221
-		}
222
-
223
-		$var_1 = 2 * $L - $var_2;
224
-
225
-		$R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
226
-		$G = 255 * $hue_2_rgb($var_1, $var_2, $H);
227
-		$B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
228
-	}
229
-
230
-	$ret = [];
231
-	$ret['r'] = floor($R);
232
-	$ret['g'] = floor($G);
233
-	$ret['b'] = floor($B);
234
-
235
-	return $ret;
190
+    // helper
191
+    $hue_2_rgb = function ($v1, $v2, $vH) {
192
+        if ($vH < 0) {
193
+            $vH += 1;
194
+        }
195
+        if ($vH > 1) {
196
+            $vH -= 1;
197
+        }
198
+        if ((6 * $vH) < 1) {
199
+            return ($v1 + ($v2 - $v1) * 6 * $vH);
200
+        }
201
+        if ((2 * $vH) < 1) {
202
+            return ($v2);
203
+        }
204
+        if ((3 * $vH) < 2) {
205
+            return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
206
+        }
207
+
208
+        return ($v1);
209
+    };
210
+
211
+    if ($S == 0) {
212
+        // HSV values = 0 -> 1
213
+        $R = $L * 255;
214
+        $G = $L * 255;
215
+        $B = $L * 255;
216
+    } else {
217
+        if ($L < 0.5) {
218
+            $var_2 = $L * (1 + $S);
219
+        } else {
220
+            $var_2 = ($L + $S) - ($S * $L);
221
+        }
222
+
223
+        $var_1 = 2 * $L - $var_2;
224
+
225
+        $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
226
+        $G = 255 * $hue_2_rgb($var_1, $var_2, $H);
227
+        $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
228
+    }
229
+
230
+    $ret = [];
231
+    $ret['r'] = floor($R);
232
+    $ret['g'] = floor($G);
233
+    $ret['b'] = floor($B);
234
+
235
+    return $ret;
236 236
 }
237 237
 
238 238
 /**
@@ -249,11 +249,11 @@  discard block
 block discarded – undo
249 249
  *     true si il faut supprimer le fichier temporaire ; false sinon.
250 250
  */
251 251
 function statut_effacer_images_temporaires($stat) {
252
-	static $statut = false; // par defaut on grave toute les images
253
-	if ($stat === 'get') {
254
-		return $statut;
255
-	}
256
-	$statut = $stat ? true : false;
252
+    static $statut = false; // par defaut on grave toute les images
253
+    if ($stat === 'get') {
254
+        return $statut;
255
+    }
256
+    $statut = $stat ? true : false;
257 257
 }
258 258
 
259 259
 
@@ -306,241 +306,241 @@  discard block
 block discarded – undo
306 306
  *     - array : tableau décrivant de l'image
307 307
  */
308 308
 function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) {
309
-	static $images_recalcul = [];
310
-	if (strlen($img) == 0) {
311
-		return false;
312
-	}
313
-
314
-	$source = trim(extraire_attribut($img, 'src') ?? '');
315
-	if (strlen($source) < 1) {
316
-		$source = $img;
317
-		$img = "<img src='$source' />";
318
-	} elseif (
319
-		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
320
-		and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
321
-		and in_array($extension, _image_extensions_acceptees_en_entree())
322
-	) {
323
-		# gerer img src="data:....base64"
324
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
325
-		if (!file_exists($local)) {
326
-			ecrire_fichier($local, base64_decode($regs[2]));
327
-		}
328
-		if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
329
-			$sanitizer($local);
330
-		}
331
-		$source = $local;
332
-		$img = inserer_attribut($img, 'src', $source);
333
-		# eviter les mauvaises surprises lors de conversions de format
334
-		$img = inserer_attribut($img, 'width', '');
335
-		$img = inserer_attribut($img, 'height', '');
336
-	}
337
-
338
-	// les protocoles web prennent au moins 3 lettres
339
-	if (tester_url_absolue($source)) {
340
-		include_spip('inc/distant');
341
-		$fichier = _DIR_RACINE . copie_locale($source);
342
-		if (!$fichier) {
343
-			return '';
344
-		}
345
-		if (
346
-			$extension = _image_trouver_extension($fichier)
347
-			and $sanitizer = charger_fonction($extension, 'sanitizer', true)
348
-		) {
349
-			$sanitizer($fichier);
350
-		}
351
-	} else {
352
-		// enlever le timestamp eventuel
353
-		if (strpos($source, '?') !== false) {
354
-			$source = preg_replace(',[?][0-9]+$,', '', $source);
355
-		}
356
-		if (
357
-			strpos($source, '?') !== false
358
-			and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
359
-			and file_exists($f = preg_replace(',[?].*$,', '', $source))
360
-		) {
361
-			$source = $f;
362
-		}
363
-		$fichier = $source;
364
-	}
365
-
366
-	$terminaison_dest = '';
367
-	if ($terminaison = _image_trouver_extension($fichier)) {
368
-		$terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
369
-	}
370
-
371
-	if (
372
-		$forcer_format !== false
373
-		// ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image
374
-		and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
375
-	) {
376
-		$terminaison_dest = $forcer_format;
377
-	}
378
-
379
-	if (!$terminaison_dest) {
380
-		return false;
381
-	}
382
-
383
-	$nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
384
-	$fichier_dest = $nom_fichier;
385
-	if (
386
-		($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
387
-		or @file_exists($f = $fichier)
388
-	) {
389
-		// on passe la balise img a taille image qui exraira les attributs si possible
390
-		// au lieu de faire un acces disque sur le fichier
391
-		list($ret['hauteur'], $ret['largeur']) = taille_image($find_in_path ? $f : $img);
392
-		$date_src = @filemtime($f);
393
-	} elseif (
394
-		@file_exists($f = "$fichier.src")
395
-		and lire_fichier($f, $valeurs)
396
-		and $valeurs = unserialize($valeurs)
397
-		and isset($valeurs['hauteur_dest'])
398
-		and isset($valeurs['largeur_dest'])
399
-	) {
400
-		$ret['hauteur'] = $valeurs['hauteur_dest'];
401
-		$ret['largeur'] = $valeurs['largeur_dest'];
402
-		$date_src = $valeurs['date'];
403
-	} // pas de fichier source par la
404
-	else {
405
-		return false;
406
-	}
407
-
408
-	// pas de taille mesurable
409
-	if (!($ret['hauteur'] or $ret['largeur'])) {
410
-		return false;
411
-	}
412
-
413
-	// les images calculees dependent du chemin du fichier source
414
-	// pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
415
-	// ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
416
-	// qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
417
-	// la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
418
-	// alors que ca concerne peu de site au final
419
-	// la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
420
-	$identifiant = $fichier;
421
-
422
-	// cas general :
423
-	// on a un dossier cache commun et un nom de fichier qui varie avec l'effet
424
-	// cas particulier de reduire :
425
-	// un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
426
-	$cache = 'cache-gd2';
427
-	if (substr($effet, 0, 7) == 'reduire') {
428
-		list(, $maxWidth, $maxHeight) = explode('-', $effet);
429
-		list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
430
-		$ret['largeur_dest'] = $destWidth;
431
-		$ret['hauteur_dest'] = $destHeight;
432
-		$effet = "L{$destWidth}xH$destHeight";
433
-		$cache = 'cache-vignettes';
434
-		$fichier_dest = basename($fichier_dest);
435
-		if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
436
-			// on garde la terminaison initiale car image simplement copiee
437
-			// et on postfixe son nom avec un md5 du path
438
-			$terminaison_dest = $terminaison;
439
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
440
-		} else {
441
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
442
-		}
443
-		$cache = sous_repertoire(_DIR_VAR, $cache);
444
-		$cache = sous_repertoire($cache, $effet);
445
-	} else {
446
-		$fichier_dest = md5("$identifiant-$effet");
447
-		$cache = sous_repertoire(_DIR_VAR, $cache);
448
-		$cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
449
-		$fichier_dest = substr($fichier_dest, 2);
450
-	}
451
-
452
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
453
-
454
-	$GLOBALS['images_calculees'][] = $fichier_dest;
455
-
456
-	$creer = true;
457
-	// si recalcul des images demande, recalculer chaque image une fois
458
-	if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
459
-		$images_recalcul[$fichier_dest] = true;
460
-	} else {
461
-		if (@file_exists($f = $fichier_dest)) {
462
-			if (filemtime($f) >= $date_src) {
463
-				$creer = false;
464
-			}
465
-		} else {
466
-			if (
467
-				@file_exists($f = "$fichier_dest.src")
468
-				and lire_fichier($f, $valeurs)
469
-				and $valeurs = unserialize($valeurs)
470
-				and $valeurs['date'] >= $date_src
471
-			) {
472
-				$creer = false;
473
-			}
474
-		}
475
-	}
476
-	if ($creer) {
477
-		if (!@file_exists($fichier)) {
478
-			if (!@file_exists("$fichier.src")) {
479
-				spip_log("Image absente : $fichier");
480
-
481
-				return false;
482
-			}
483
-			# on reconstruit l'image source absente a partir de la chaine des .src
484
-			reconstruire_image_intermediaire($fichier);
485
-		}
486
-	}
487
-
488
-	if ($creer) {
489
-		spip_log(
490
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
491
-			'images' . _LOG_DEBUG
492
-		);
493
-	}
494
-
495
-	$term_fonction = _image_trouver_extension_pertinente($fichier);
496
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
497
-	$ret['fichier'] = $fichier;
498
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
499
-	$ret['fichier_dest'] = $fichier_dest;
500
-	$ret['format_source'] = _image_extension_normalisee($terminaison);
501
-	$ret['format_dest'] = $terminaison_dest;
502
-	$ret['date_src'] = $date_src;
503
-	$ret['creer'] = $creer;
504
-	$ret['class'] = extraire_attribut($img, 'class');
505
-	$ret['alt'] = extraire_attribut($img, 'alt');
506
-	$ret['style'] = extraire_attribut($img, 'style');
507
-	$ret['tag'] = $img;
508
-	if ($fonction_creation) {
509
-		$ret['reconstruction'] = $fonction_creation;
510
-		# ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
511
-		# cas de image_reduire qui finalement ne reduit pas l'image source
512
-		# ca evite d'essayer de le creer au prochain hit si il n'est pas la
513
-		#ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
514
-	}
515
-
516
-	$ret = pipeline('image_preparer_filtre', [
517
-			'args' => [
518
-				'img' => $img,
519
-				'effet' => $effet,
520
-				'forcer_format' => $forcer_format,
521
-				'fonction_creation' => $fonction_creation,
522
-				'find_in_path' => $find_in_path,
523
-			],
524
-			'data' => $ret
525
-		]);
526
-
527
-	// une globale pour le debug en cas de crash memoire
528
-	$GLOBALS['derniere_image_calculee'] = $ret;
529
-
530
-	// traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
531
-	if ($term_fonction === 'svg') {
532
-		if ($creer and !$support_svg) {
533
-			process_image_svg_identite($ret);
534
-			$ret['creer'] = false;
535
-		}
536
-	}
537
-	else {
538
-		if (!function_exists($ret['fonction_imagecreatefrom'])) {
539
-			return false;
540
-		}
541
-	}
542
-
543
-	return $ret;
309
+    static $images_recalcul = [];
310
+    if (strlen($img) == 0) {
311
+        return false;
312
+    }
313
+
314
+    $source = trim(extraire_attribut($img, 'src') ?? '');
315
+    if (strlen($source) < 1) {
316
+        $source = $img;
317
+        $img = "<img src='$source' />";
318
+    } elseif (
319
+        preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
320
+        and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
321
+        and in_array($extension, _image_extensions_acceptees_en_entree())
322
+    ) {
323
+        # gerer img src="data:....base64"
324
+        $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
325
+        if (!file_exists($local)) {
326
+            ecrire_fichier($local, base64_decode($regs[2]));
327
+        }
328
+        if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
329
+            $sanitizer($local);
330
+        }
331
+        $source = $local;
332
+        $img = inserer_attribut($img, 'src', $source);
333
+        # eviter les mauvaises surprises lors de conversions de format
334
+        $img = inserer_attribut($img, 'width', '');
335
+        $img = inserer_attribut($img, 'height', '');
336
+    }
337
+
338
+    // les protocoles web prennent au moins 3 lettres
339
+    if (tester_url_absolue($source)) {
340
+        include_spip('inc/distant');
341
+        $fichier = _DIR_RACINE . copie_locale($source);
342
+        if (!$fichier) {
343
+            return '';
344
+        }
345
+        if (
346
+            $extension = _image_trouver_extension($fichier)
347
+            and $sanitizer = charger_fonction($extension, 'sanitizer', true)
348
+        ) {
349
+            $sanitizer($fichier);
350
+        }
351
+    } else {
352
+        // enlever le timestamp eventuel
353
+        if (strpos($source, '?') !== false) {
354
+            $source = preg_replace(',[?][0-9]+$,', '', $source);
355
+        }
356
+        if (
357
+            strpos($source, '?') !== false
358
+            and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
359
+            and file_exists($f = preg_replace(',[?].*$,', '', $source))
360
+        ) {
361
+            $source = $f;
362
+        }
363
+        $fichier = $source;
364
+    }
365
+
366
+    $terminaison_dest = '';
367
+    if ($terminaison = _image_trouver_extension($fichier)) {
368
+        $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
369
+    }
370
+
371
+    if (
372
+        $forcer_format !== false
373
+        // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image
374
+        and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
375
+    ) {
376
+        $terminaison_dest = $forcer_format;
377
+    }
378
+
379
+    if (!$terminaison_dest) {
380
+        return false;
381
+    }
382
+
383
+    $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
384
+    $fichier_dest = $nom_fichier;
385
+    if (
386
+        ($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
387
+        or @file_exists($f = $fichier)
388
+    ) {
389
+        // on passe la balise img a taille image qui exraira les attributs si possible
390
+        // au lieu de faire un acces disque sur le fichier
391
+        list($ret['hauteur'], $ret['largeur']) = taille_image($find_in_path ? $f : $img);
392
+        $date_src = @filemtime($f);
393
+    } elseif (
394
+        @file_exists($f = "$fichier.src")
395
+        and lire_fichier($f, $valeurs)
396
+        and $valeurs = unserialize($valeurs)
397
+        and isset($valeurs['hauteur_dest'])
398
+        and isset($valeurs['largeur_dest'])
399
+    ) {
400
+        $ret['hauteur'] = $valeurs['hauteur_dest'];
401
+        $ret['largeur'] = $valeurs['largeur_dest'];
402
+        $date_src = $valeurs['date'];
403
+    } // pas de fichier source par la
404
+    else {
405
+        return false;
406
+    }
407
+
408
+    // pas de taille mesurable
409
+    if (!($ret['hauteur'] or $ret['largeur'])) {
410
+        return false;
411
+    }
412
+
413
+    // les images calculees dependent du chemin du fichier source
414
+    // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
415
+    // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
416
+    // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
417
+    // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
418
+    // alors que ca concerne peu de site au final
419
+    // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
420
+    $identifiant = $fichier;
421
+
422
+    // cas general :
423
+    // on a un dossier cache commun et un nom de fichier qui varie avec l'effet
424
+    // cas particulier de reduire :
425
+    // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
426
+    $cache = 'cache-gd2';
427
+    if (substr($effet, 0, 7) == 'reduire') {
428
+        list(, $maxWidth, $maxHeight) = explode('-', $effet);
429
+        list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
430
+        $ret['largeur_dest'] = $destWidth;
431
+        $ret['hauteur_dest'] = $destHeight;
432
+        $effet = "L{$destWidth}xH$destHeight";
433
+        $cache = 'cache-vignettes';
434
+        $fichier_dest = basename($fichier_dest);
435
+        if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
436
+            // on garde la terminaison initiale car image simplement copiee
437
+            // et on postfixe son nom avec un md5 du path
438
+            $terminaison_dest = $terminaison;
439
+            $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
440
+        } else {
441
+            $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
442
+        }
443
+        $cache = sous_repertoire(_DIR_VAR, $cache);
444
+        $cache = sous_repertoire($cache, $effet);
445
+    } else {
446
+        $fichier_dest = md5("$identifiant-$effet");
447
+        $cache = sous_repertoire(_DIR_VAR, $cache);
448
+        $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
449
+        $fichier_dest = substr($fichier_dest, 2);
450
+    }
451
+
452
+    $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
453
+
454
+    $GLOBALS['images_calculees'][] = $fichier_dest;
455
+
456
+    $creer = true;
457
+    // si recalcul des images demande, recalculer chaque image une fois
458
+    if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
459
+        $images_recalcul[$fichier_dest] = true;
460
+    } else {
461
+        if (@file_exists($f = $fichier_dest)) {
462
+            if (filemtime($f) >= $date_src) {
463
+                $creer = false;
464
+            }
465
+        } else {
466
+            if (
467
+                @file_exists($f = "$fichier_dest.src")
468
+                and lire_fichier($f, $valeurs)
469
+                and $valeurs = unserialize($valeurs)
470
+                and $valeurs['date'] >= $date_src
471
+            ) {
472
+                $creer = false;
473
+            }
474
+        }
475
+    }
476
+    if ($creer) {
477
+        if (!@file_exists($fichier)) {
478
+            if (!@file_exists("$fichier.src")) {
479
+                spip_log("Image absente : $fichier");
480
+
481
+                return false;
482
+            }
483
+            # on reconstruit l'image source absente a partir de la chaine des .src
484
+            reconstruire_image_intermediaire($fichier);
485
+        }
486
+    }
487
+
488
+    if ($creer) {
489
+        spip_log(
490
+            'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
491
+            'images' . _LOG_DEBUG
492
+        );
493
+    }
494
+
495
+    $term_fonction = _image_trouver_extension_pertinente($fichier);
496
+    $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
497
+    $ret['fichier'] = $fichier;
498
+    $ret['fonction_image'] = '_image_image' . $terminaison_dest;
499
+    $ret['fichier_dest'] = $fichier_dest;
500
+    $ret['format_source'] = _image_extension_normalisee($terminaison);
501
+    $ret['format_dest'] = $terminaison_dest;
502
+    $ret['date_src'] = $date_src;
503
+    $ret['creer'] = $creer;
504
+    $ret['class'] = extraire_attribut($img, 'class');
505
+    $ret['alt'] = extraire_attribut($img, 'alt');
506
+    $ret['style'] = extraire_attribut($img, 'style');
507
+    $ret['tag'] = $img;
508
+    if ($fonction_creation) {
509
+        $ret['reconstruction'] = $fonction_creation;
510
+        # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
511
+        # cas de image_reduire qui finalement ne reduit pas l'image source
512
+        # ca evite d'essayer de le creer au prochain hit si il n'est pas la
513
+        #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
514
+    }
515
+
516
+    $ret = pipeline('image_preparer_filtre', [
517
+            'args' => [
518
+                'img' => $img,
519
+                'effet' => $effet,
520
+                'forcer_format' => $forcer_format,
521
+                'fonction_creation' => $fonction_creation,
522
+                'find_in_path' => $find_in_path,
523
+            ],
524
+            'data' => $ret
525
+        ]);
526
+
527
+    // une globale pour le debug en cas de crash memoire
528
+    $GLOBALS['derniere_image_calculee'] = $ret;
529
+
530
+    // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
531
+    if ($term_fonction === 'svg') {
532
+        if ($creer and !$support_svg) {
533
+            process_image_svg_identite($ret);
534
+            $ret['creer'] = false;
535
+        }
536
+    }
537
+    else {
538
+        if (!function_exists($ret['fonction_imagecreatefrom'])) {
539
+            return false;
540
+        }
541
+    }
542
+
543
+    return $ret;
544 544
 }
545 545
 
546 546
 
@@ -549,53 +549,53 @@  discard block
 block discarded – undo
549 549
  * @return array
550 550
  */
551 551
 function _image_extensions_acceptees_en_entree() {
552
-	static $extensions = null;
553
-	if (empty($extensions)) {
554
-		$extensions = ['png', 'gif', 'jpg', 'jpeg'];
555
-		if (!empty($GLOBALS['meta']['gd_formats'])) {
556
-			// action=tester renseigne gd_formats et detecte le support de webp
557
-			$extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
558
-			$extensions = array_map('trim', $extensions);
559
-			$extensions = array_filter($extensions);
560
-			$extensions = array_unique($extensions);
561
-			if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg';
562
-			}
563
-		}
564
-		$extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
565
-	}
566
-
567
-	return $extensions;
552
+    static $extensions = null;
553
+    if (empty($extensions)) {
554
+        $extensions = ['png', 'gif', 'jpg', 'jpeg'];
555
+        if (!empty($GLOBALS['meta']['gd_formats'])) {
556
+            // action=tester renseigne gd_formats et detecte le support de webp
557
+            $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
558
+            $extensions = array_map('trim', $extensions);
559
+            $extensions = array_filter($extensions);
560
+            $extensions = array_unique($extensions);
561
+            if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg';
562
+            }
563
+        }
564
+        $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
565
+    }
566
+
567
+    return $extensions;
568 568
 }
569 569
 
570 570
 /**
571 571
  * @return array|string[]|null
572 572
  */
573 573
 function _image_extensions_acceptees_en_sortie() {
574
-	static $extensions = null;
575
-	if (empty($extensions)) {
576
-		$extensions = _image_extensions_acceptees_en_entree();
577
-		$extensions = array_diff($extensions, ['jpeg']);
578
-		if (in_array('gif', $extensions) and !function_exists('imagegif')) {
579
-			$extensions = array_diff($extensions, ['gif']);
580
-		}
581
-		if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
582
-			$extensions = array_diff($extensions, ['webp']);
583
-		}
584
-	}
585
-
586
-	return $extensions;
574
+    static $extensions = null;
575
+    if (empty($extensions)) {
576
+        $extensions = _image_extensions_acceptees_en_entree();
577
+        $extensions = array_diff($extensions, ['jpeg']);
578
+        if (in_array('gif', $extensions) and !function_exists('imagegif')) {
579
+            $extensions = array_diff($extensions, ['gif']);
580
+        }
581
+        if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
582
+            $extensions = array_diff($extensions, ['webp']);
583
+        }
584
+    }
585
+
586
+    return $extensions;
587 587
 }
588 588
 
589 589
 function _image_extension_normalisee($extension) {
590
-	$extension = strtolower($extension);
591
-	if ($extension === 'jpeg') {
592
-		$extension = 'jpg';
593
-	}
594
-	return $extension;
590
+    $extension = strtolower($extension);
591
+    if ($extension === 'jpeg') {
592
+        $extension = 'jpg';
593
+    }
594
+    return $extension;
595 595
 }
596 596
 
597 597
 function _image_extensions_conservent_transparence() {
598
-	return ['png', 'webp'];
598
+    return ['png', 'webp'];
599 599
 }
600 600
 
601 601
 
@@ -605,12 +605,12 @@  discard block
 block discarded – undo
605 605
  * @return string
606 606
  */
607 607
 function _image_trouver_extension($path) {
608
-	$preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
609
-	if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
610
-		$terminaison = strtolower($regs[1]);
611
-		return $terminaison;
612
-	}
613
-	return '';
608
+    $preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
609
+    if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
610
+        $terminaison = strtolower($regs[1]);
611
+        return $terminaison;
612
+    }
613
+    return '';
614 614
 }
615 615
 
616 616
 /**
@@ -621,33 +621,33 @@  discard block
 block discarded – undo
621 621
  * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple)
622 622
  */
623 623
 function _image_trouver_extension_pertinente($path) {
624
-	$path = supprimer_timestamp($path);
625
-	$terminaison = _image_trouver_extension($path);
626
-	if ($terminaison == 'jpg') {
627
-		$terminaison = 'jpeg';
628
-	}
629
-
630
-	if (!file_exists($path)) {
631
-		return $terminaison;
632
-	}
633
-
634
-	if (!$info = @spip_getimagesize($path)) {
635
-		return $terminaison;
636
-	}
637
-
638
-	if (isset($info['mime'])) {
639
-		$mime = $info['mime'];
640
-	}
641
-	else {
642
-		$mime = image_type_to_mime_type($info[2]);
643
-	}
644
-
645
-	$_terminaison = _image_trouver_extension_depuis_mime($mime);
646
-	if ($_terminaison and $_terminaison !== $terminaison) {
647
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
648
-		$terminaison = $_terminaison;
649
-	}
650
-	return $terminaison;
624
+    $path = supprimer_timestamp($path);
625
+    $terminaison = _image_trouver_extension($path);
626
+    if ($terminaison == 'jpg') {
627
+        $terminaison = 'jpeg';
628
+    }
629
+
630
+    if (!file_exists($path)) {
631
+        return $terminaison;
632
+    }
633
+
634
+    if (!$info = @spip_getimagesize($path)) {
635
+        return $terminaison;
636
+    }
637
+
638
+    if (isset($info['mime'])) {
639
+        $mime = $info['mime'];
640
+    }
641
+    else {
642
+        $mime = image_type_to_mime_type($info[2]);
643
+    }
644
+
645
+    $_terminaison = _image_trouver_extension_depuis_mime($mime);
646
+    if ($_terminaison and $_terminaison !== $terminaison) {
647
+        spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
648
+        $terminaison = $_terminaison;
649
+    }
650
+    return $terminaison;
651 651
 }
652 652
 
653 653
 /**
@@ -655,36 +655,36 @@  discard block
 block discarded – undo
655 655
  * @return string
656 656
  */
657 657
 function _image_trouver_extension_depuis_mime($mime) {
658
-	switch (strtolower($mime)) {
659
-		case 'image/png':
660
-		case 'image/x-png':
661
-			$terminaison = 'png';
662
-			break;
663
-
664
-		case 'image/jpg':
665
-		case 'image/jpeg':
666
-		case 'image/pjpeg':
667
-			$terminaison = 'jpeg';
668
-			break;
669
-
670
-		case 'image/gif':
671
-			$terminaison = 'gif';
672
-			break;
673
-
674
-		case 'image/webp':
675
-		case 'image/x-webp':
676
-			$terminaison = 'webp';
677
-			break;
678
-
679
-		case 'image/svg+xml':
680
-			$terminaison = 'svg';
681
-			break;
682
-
683
-		default:
684
-			$terminaison = '';
685
-	}
686
-
687
-	return $terminaison;
658
+    switch (strtolower($mime)) {
659
+        case 'image/png':
660
+        case 'image/x-png':
661
+            $terminaison = 'png';
662
+            break;
663
+
664
+        case 'image/jpg':
665
+        case 'image/jpeg':
666
+        case 'image/pjpeg':
667
+            $terminaison = 'jpeg';
668
+            break;
669
+
670
+        case 'image/gif':
671
+            $terminaison = 'gif';
672
+            break;
673
+
674
+        case 'image/webp':
675
+        case 'image/x-webp':
676
+            $terminaison = 'webp';
677
+            break;
678
+
679
+        case 'image/svg+xml':
680
+            $terminaison = 'svg';
681
+            break;
682
+
683
+        default:
684
+            $terminaison = '';
685
+    }
686
+
687
+    return $terminaison;
688 688
 }
689 689
 
690 690
 
@@ -704,18 +704,18 @@  discard block
 block discarded – undo
704 704
  *     Une ressource de type Image GD.
705 705
  */
706 706
 function _imagecreatefrom_func(string $func, string $filename) {
707
-	if (!function_exists($func)) {
708
-		spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
709
-		erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
710
-		return null;
711
-	}
712
-	$img = @$func($filename);
713
-	if (!$img) {
714
-		spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
715
-		erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
716
-		$img = imagecreate(10, 10);
717
-	}
718
-	return $img;
707
+    if (!function_exists($func)) {
708
+        spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
709
+        erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
710
+        return null;
711
+    }
712
+    $img = @$func($filename);
713
+    if (!$img) {
714
+        spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
715
+        erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
716
+        $img = imagecreate(10, 10);
717
+    }
718
+    return $img;
719 719
 }
720 720
 
721 721
 /**
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
  *     Une ressource de type Image GD.
732 732
  */
733 733
 function _imagecreatefromjpeg($filename) {
734
-	return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
734
+    return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
735 735
 }
736 736
 
737 737
 /**
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
  *     Une ressource de type Image GD.
748 748
  */
749 749
 function _imagecreatefrompng($filename) {
750
-	return _imagecreatefrom_func('imagecreatefrompng', $filename);
750
+    return _imagecreatefrom_func('imagecreatefrompng', $filename);
751 751
 }
752 752
 
753 753
 /**
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
  *     Une ressource de type Image GD.
764 764
  */
765 765
 function _imagecreatefromgif($filename) {
766
-	return _imagecreatefrom_func('imagecreatefromgif', $filename);
766
+    return _imagecreatefrom_func('imagecreatefromgif', $filename);
767 767
 }
768 768
 
769 769
 
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
  *     Une ressource de type Image GD.
781 781
  */
782 782
 function _imagecreatefromwebp($filename) {
783
-	return _imagecreatefrom_func('imagecreatefromwebp', $filename);
783
+    return _imagecreatefrom_func('imagecreatefromwebp', $filename);
784 784
 }
785 785
 
786 786
 /**
@@ -798,24 +798,24 @@  discard block
 block discarded – undo
798 798
  *     - true si une image est bien retournée.
799 799
  */
800 800
 function _image_imagepng($img, $fichier) {
801
-	if (!function_exists('imagepng')) {
802
-		return false;
803
-	}
804
-	$tmp = $fichier . '.tmp';
805
-	$ret = imagepng($img, $tmp);
806
-	if (file_exists($tmp)) {
807
-		$taille_test = getimagesize($tmp);
808
-		if ($taille_test[0] < 1) {
809
-			return false;
810
-		}
811
-
812
-		spip_unlink($fichier); // le fichier peut deja exister
813
-		@rename($tmp, $fichier);
814
-
815
-		return $ret;
816
-	}
817
-
818
-	return false;
801
+    if (!function_exists('imagepng')) {
802
+        return false;
803
+    }
804
+    $tmp = $fichier . '.tmp';
805
+    $ret = imagepng($img, $tmp);
806
+    if (file_exists($tmp)) {
807
+        $taille_test = getimagesize($tmp);
808
+        if ($taille_test[0] < 1) {
809
+            return false;
810
+        }
811
+
812
+        spip_unlink($fichier); // le fichier peut deja exister
813
+        @rename($tmp, $fichier);
814
+
815
+        return $ret;
816
+    }
817
+
818
+    return false;
819 819
 }
820 820
 
821 821
 /**
@@ -833,24 +833,24 @@  discard block
 block discarded – undo
833 833
  *     - true si une image est bien retournée.
834 834
  */
835 835
 function _image_imagegif($img, $fichier) {
836
-	if (!function_exists('imagegif')) {
837
-		return false;
838
-	}
839
-	$tmp = $fichier . '.tmp';
840
-	$ret = imagegif($img, $tmp);
841
-	if (file_exists($tmp)) {
842
-		$taille_test = getimagesize($tmp);
843
-		if ($taille_test[0] < 1) {
844
-			return false;
845
-		}
846
-
847
-		spip_unlink($fichier); // le fichier peut deja exister
848
-		@rename($tmp, $fichier);
849
-
850
-		return $ret;
851
-	}
852
-
853
-	return false;
836
+    if (!function_exists('imagegif')) {
837
+        return false;
838
+    }
839
+    $tmp = $fichier . '.tmp';
840
+    $ret = imagegif($img, $tmp);
841
+    if (file_exists($tmp)) {
842
+        $taille_test = getimagesize($tmp);
843
+        if ($taille_test[0] < 1) {
844
+            return false;
845
+        }
846
+
847
+        spip_unlink($fichier); // le fichier peut deja exister
848
+        @rename($tmp, $fichier);
849
+
850
+        return $ret;
851
+    }
852
+
853
+    return false;
854 854
 }
855 855
 
856 856
 /**
@@ -873,29 +873,29 @@  discard block
 block discarded – undo
873 873
  *     - true si une image est bien retournée.
874 874
  */
875 875
 function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) {
876
-	if (!function_exists('imagejpeg')) {
877
-		return false;
878
-	}
879
-	$tmp = $fichier . '.tmp';
876
+    if (!function_exists('imagejpeg')) {
877
+        return false;
878
+    }
879
+    $tmp = $fichier . '.tmp';
880 880
 
881
-	// Enable interlancing
882
-	imageinterlace($img, true);
881
+    // Enable interlancing
882
+    imageinterlace($img, true);
883 883
 
884
-	$ret = imagejpeg($img, $tmp, $qualite);
884
+    $ret = imagejpeg($img, $tmp, $qualite);
885 885
 
886
-	if (file_exists($tmp)) {
887
-		$taille_test = getimagesize($tmp);
888
-		if ($taille_test[0] < 1) {
889
-			return false;
890
-		}
886
+    if (file_exists($tmp)) {
887
+        $taille_test = getimagesize($tmp);
888
+        if ($taille_test[0] < 1) {
889
+            return false;
890
+        }
891 891
 
892
-		spip_unlink($fichier); // le fichier peut deja exister
893
-		@rename($tmp, $fichier);
892
+        spip_unlink($fichier); // le fichier peut deja exister
893
+        @rename($tmp, $fichier);
894 894
 
895
-		return $ret;
896
-	}
895
+        return $ret;
896
+    }
897 897
 
898
-	return false;
898
+    return false;
899 899
 }
900 900
 
901 901
 /**
@@ -913,9 +913,9 @@  discard block
 block discarded – undo
913 913
  *     true si le fichier a bien été créé ; false sinon.
914 914
  */
915 915
 function _image_imageico($img, $fichier) {
916
-	$gd_image_array = [$img];
916
+    $gd_image_array = [$img];
917 917
 
918
-	return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
918
+    return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
919 919
 }
920 920
 
921 921
 
@@ -934,24 +934,24 @@  discard block
 block discarded – undo
934 934
  *     - true si une image est bien retournée.
935 935
  */
936 936
 function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) {
937
-	if (!function_exists('imagewebp')) {
938
-		return false;
939
-	}
940
-	$tmp = $fichier . '.tmp';
941
-	$ret = imagewebp($img, $tmp, $qualite);
942
-	if (file_exists($tmp)) {
943
-		$taille_test = getimagesize($tmp);
944
-		if ($taille_test[0] < 1) {
945
-			return false;
946
-		}
947
-
948
-		spip_unlink($fichier); // le fichier peut deja exister
949
-		@rename($tmp, $fichier);
950
-
951
-		return $ret;
952
-	}
953
-
954
-	return false;
937
+    if (!function_exists('imagewebp')) {
938
+        return false;
939
+    }
940
+    $tmp = $fichier . '.tmp';
941
+    $ret = imagewebp($img, $tmp, $qualite);
942
+    if (file_exists($tmp)) {
943
+        $taille_test = getimagesize($tmp);
944
+        if ($taille_test[0] < 1) {
945
+            return false;
946
+        }
947
+
948
+        spip_unlink($fichier); // le fichier peut deja exister
949
+        @rename($tmp, $fichier);
950
+
951
+        return $ret;
952
+    }
953
+
954
+    return false;
955 955
 }
956 956
 
957 957
 /**
@@ -971,35 +971,35 @@  discard block
 block discarded – undo
971 971
  */
972 972
 function _image_imagesvg($img, $fichier) {
973 973
 
974
-	$tmp = $fichier . '.tmp';
975
-	if (strpos($img, '<') === false) {
976
-		$img = supprimer_timestamp($img);
977
-		if (!file_exists($img)) {
978
-			return false;
979
-		}
980
-		@copy($img, $tmp);
981
-		if (filesize($tmp) == filesize($img)) {
982
-			spip_unlink($fichier); // le fichier peut deja exister
983
-			@rename($tmp, $fichier);
984
-			return true;
985
-		}
986
-		return false;
987
-	}
988
-
989
-	file_put_contents($tmp, $img);
990
-	if (file_exists($tmp)) {
991
-		$taille_test = spip_getimagesize($tmp);
992
-		if ($taille_test[0] < 1) {
993
-			return false;
994
-		}
995
-
996
-		spip_unlink($fichier); // le fichier peut deja exister
997
-		@rename($tmp, $fichier);
998
-
999
-		return true;
1000
-	}
1001
-
1002
-	return false;
974
+    $tmp = $fichier . '.tmp';
975
+    if (strpos($img, '<') === false) {
976
+        $img = supprimer_timestamp($img);
977
+        if (!file_exists($img)) {
978
+            return false;
979
+        }
980
+        @copy($img, $tmp);
981
+        if (filesize($tmp) == filesize($img)) {
982
+            spip_unlink($fichier); // le fichier peut deja exister
983
+            @rename($tmp, $fichier);
984
+            return true;
985
+        }
986
+        return false;
987
+    }
988
+
989
+    file_put_contents($tmp, $img);
990
+    if (file_exists($tmp)) {
991
+        $taille_test = spip_getimagesize($tmp);
992
+        if ($taille_test[0] < 1) {
993
+            return false;
994
+        }
995
+
996
+        spip_unlink($fichier); // le fichier peut deja exister
997
+        @rename($tmp, $fichier);
998
+
999
+        return true;
1000
+    }
1001
+
1002
+    return false;
1003 1003
 }
1004 1004
 
1005 1005
 
@@ -1027,29 +1027,29 @@  discard block
 block discarded – undo
1027 1027
  *     - false sinon.
1028 1028
  */
1029 1029
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1030
-	if (is_null($fonction)) {
1031
-		$fonction = '_image_image' . $valeurs['format_dest'];
1032
-	}
1033
-	$ret = false;
1034
-	#un flag pour reperer les images gravees
1035
-	$lock =
1036
-		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1037
-	or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
1038
-	if (
1039
-		function_exists($fonction)
1040
-		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1041
-		&& isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1042
-		&& !$lock
1043
-	) {
1044
-		if (@file_exists($valeurs['fichier_dest'])) {
1045
-			// dans tous les cas mettre a jour la taille de l'image finale
1046
-			list($valeurs['hauteur_dest'], $valeurs['largeur_dest']) = taille_image($valeurs['fichier_dest']);
1047
-			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1048
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1049
-		}
1050
-	}
1051
-
1052
-	return $ret;
1030
+    if (is_null($fonction)) {
1031
+        $fonction = '_image_image' . $valeurs['format_dest'];
1032
+    }
1033
+    $ret = false;
1034
+    #un flag pour reperer les images gravees
1035
+    $lock =
1036
+        !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1037
+    or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
1038
+    if (
1039
+        function_exists($fonction)
1040
+        && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1041
+        && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1042
+        && !$lock
1043
+    ) {
1044
+        if (@file_exists($valeurs['fichier_dest'])) {
1045
+            // dans tous les cas mettre a jour la taille de l'image finale
1046
+            list($valeurs['hauteur_dest'], $valeurs['largeur_dest']) = taille_image($valeurs['fichier_dest']);
1047
+            $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1048
+            ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1049
+        }
1050
+    }
1051
+
1052
+    return $ret;
1053 1053
 }
1054 1054
 
1055 1055
 /**
@@ -1062,27 +1062,27 @@  discard block
 block discarded – undo
1062 1062
  *     Chemin vers le fichier manquant
1063 1063
  **/
1064 1064
 function reconstruire_image_intermediaire($fichier_manquant) {
1065
-	$reconstruire = [];
1066
-	$fichier = $fichier_manquant;
1067
-	while (
1068
-		strpos($fichier, '://') === false
1069
-		and !@file_exists($fichier)
1070
-		and lire_fichier($src = "$fichier.src", $source)
1071
-		and $valeurs = unserialize($source)
1072
-		and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1073
-	) {
1074
-		spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1075
-		$reconstruire[] = $valeurs['reconstruction'];
1076
-	}
1077
-	while (count($reconstruire)) {
1078
-		$r = array_pop($reconstruire);
1079
-		$fonction = $r[0];
1080
-		$args = $r[1];
1081
-		call_user_func_array($fonction, $args);
1082
-	}
1083
-	// cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1084
-	// mais l'on peut nettoyer les miettes de sa creation
1085
-	ramasse_miettes($fichier_manquant);
1065
+    $reconstruire = [];
1066
+    $fichier = $fichier_manquant;
1067
+    while (
1068
+        strpos($fichier, '://') === false
1069
+        and !@file_exists($fichier)
1070
+        and lire_fichier($src = "$fichier.src", $source)
1071
+        and $valeurs = unserialize($source)
1072
+        and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1073
+    ) {
1074
+        spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1075
+        $reconstruire[] = $valeurs['reconstruction'];
1076
+    }
1077
+    while (count($reconstruire)) {
1078
+        $r = array_pop($reconstruire);
1079
+        $fonction = $r[0];
1080
+        $args = $r[1];
1081
+        call_user_func_array($fonction, $args);
1082
+    }
1083
+    // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1084
+    // mais l'on peut nettoyer les miettes de sa creation
1085
+    ramasse_miettes($fichier_manquant);
1086 1086
 }
1087 1087
 
1088 1088
 /**
@@ -1102,28 +1102,28 @@  discard block
 block discarded – undo
1102 1102
  *     Chemin du fichier d'image calculé
1103 1103
  **/
1104 1104
 function ramasse_miettes($fichier) {
1105
-	if (
1106
-		strpos($fichier, '://') !== false
1107
-		or !lire_fichier($src = "$fichier.src", $source)
1108
-		or !$valeurs = unserialize($source)
1109
-	) {
1110
-		return;
1111
-	}
1112
-	spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1113
-	while (
1114
-		($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1115
-		and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1116
-		and (lire_fichier(
1117
-			$src = "$fichier.src",
1118
-			$source
1119
-		)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1120
-		and ($valeurs = unserialize($source))  # et valide
1121
-	) {
1122
-		# on efface le fichier
1123
-		spip_unlink($fichier);
1124
-		# mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1125
-		#spip_unlink($src);
1126
-	}
1105
+    if (
1106
+        strpos($fichier, '://') !== false
1107
+        or !lire_fichier($src = "$fichier.src", $source)
1108
+        or !$valeurs = unserialize($source)
1109
+    ) {
1110
+        return;
1111
+    }
1112
+    spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1113
+    while (
1114
+        ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1115
+        and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1116
+        and (lire_fichier(
1117
+            $src = "$fichier.src",
1118
+            $source
1119
+        )) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1120
+        and ($valeurs = unserialize($source))  # et valide
1121
+    ) {
1122
+        # on efface le fichier
1123
+        spip_unlink($fichier);
1124
+        # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1125
+        #spip_unlink($src);
1126
+    }
1127 1127
 }
1128 1128
 
1129 1129
 
@@ -1148,71 +1148,71 @@  discard block
 block discarded – undo
1148 1148
  *     Code HTML de l'image
1149 1149
  **/
1150 1150
 function image_graver($img) {
1151
-	// appeler le filtre post_image_filtrer qui permet de faire
1152
-	// des traitements auto a la fin d'une serie de filtres
1153
-	$img = pipeline('post_image_filtrer', $img);
1154
-
1155
-	$fichier_ori = $fichier = extraire_attribut($img, 'src');
1156
-	if (($p = strpos($fichier, '?')) !== false) {
1157
-		$fichier = substr($fichier, 0, $p);
1158
-	}
1159
-	if (strlen($fichier) < 1) {
1160
-		$fichier = $img;
1161
-	}
1162
-	# si jamais le fichier final n'a pas ete calcule car suppose temporaire
1163
-	# et qu'il ne s'agit pas d'une URL
1164
-	if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1165
-		reconstruire_image_intermediaire($fichier);
1166
-	}
1167
-	ramasse_miettes($fichier);
1168
-
1169
-	// ajouter le timestamp si besoin
1170
-	if (strpos($fichier_ori, '?') === false) {
1171
-		// on utilise str_replace pour attraper le onmouseover des logo si besoin
1172
-		$img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1173
-	}
1174
-
1175
-	return $img;
1151
+    // appeler le filtre post_image_filtrer qui permet de faire
1152
+    // des traitements auto a la fin d'une serie de filtres
1153
+    $img = pipeline('post_image_filtrer', $img);
1154
+
1155
+    $fichier_ori = $fichier = extraire_attribut($img, 'src');
1156
+    if (($p = strpos($fichier, '?')) !== false) {
1157
+        $fichier = substr($fichier, 0, $p);
1158
+    }
1159
+    if (strlen($fichier) < 1) {
1160
+        $fichier = $img;
1161
+    }
1162
+    # si jamais le fichier final n'a pas ete calcule car suppose temporaire
1163
+    # et qu'il ne s'agit pas d'une URL
1164
+    if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1165
+        reconstruire_image_intermediaire($fichier);
1166
+    }
1167
+    ramasse_miettes($fichier);
1168
+
1169
+    // ajouter le timestamp si besoin
1170
+    if (strpos($fichier_ori, '?') === false) {
1171
+        // on utilise str_replace pour attraper le onmouseover des logo si besoin
1172
+        $img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1173
+    }
1174
+
1175
+    return $img;
1176 1176
 }
1177 1177
 
1178 1178
 
1179 1179
 if (!function_exists('imagepalettetotruecolor')) {
1180
-	/**
1181
-	 * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB
1182
-	 *
1183
-	 * @note Pour compatibilité avec PHP < 5.5
1184
-	 *
1185
-	 * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php
1186
-	 *
1187
-	 * @param ressource $img
1188
-	 * @return bool
1189
-	 *     - true si l'image est déjà en vrai RGB ou peut être transformée
1190
-	 *     - false si la transformation ne peut être faite.
1191
-	 **/
1192
-	function imagepalettetotruecolor(&$img) {
1193
-		if (!$img or !function_exists('imagecreatetruecolor')) {
1194
-			return false;
1195
-		} elseif (!imageistruecolor($img)) {
1196
-			$w = imagesx($img);
1197
-			$h = imagesy($img);
1198
-			$img1 = imagecreatetruecolor($w, $h);
1199
-			//Conserver la transparence si possible
1200
-			if (function_exists('ImageCopyResampled')) {
1201
-				if (function_exists('imageAntiAlias')) {
1202
-					imageAntiAlias($img1, true);
1203
-				}
1204
-				@imagealphablending($img1, false);
1205
-				@imagesavealpha($img1, true);
1206
-				@ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
1207
-			} else {
1208
-				imagecopy($img1, $img, 0, 0, 0, 0, $w, $h);
1209
-			}
1210
-
1211
-			$img = $img1;
1212
-		}
1213
-
1214
-		return true;
1215
-	}
1180
+    /**
1181
+     * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB
1182
+     *
1183
+     * @note Pour compatibilité avec PHP < 5.5
1184
+     *
1185
+     * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php
1186
+     *
1187
+     * @param ressource $img
1188
+     * @return bool
1189
+     *     - true si l'image est déjà en vrai RGB ou peut être transformée
1190
+     *     - false si la transformation ne peut être faite.
1191
+     **/
1192
+    function imagepalettetotruecolor(&$img) {
1193
+        if (!$img or !function_exists('imagecreatetruecolor')) {
1194
+            return false;
1195
+        } elseif (!imageistruecolor($img)) {
1196
+            $w = imagesx($img);
1197
+            $h = imagesy($img);
1198
+            $img1 = imagecreatetruecolor($w, $h);
1199
+            //Conserver la transparence si possible
1200
+            if (function_exists('ImageCopyResampled')) {
1201
+                if (function_exists('imageAntiAlias')) {
1202
+                    imageAntiAlias($img1, true);
1203
+                }
1204
+                @imagealphablending($img1, false);
1205
+                @imagesavealpha($img1, true);
1206
+                @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
1207
+            } else {
1208
+                imagecopy($img1, $img, 0, 0, 0, 0, $w, $h);
1209
+            }
1210
+
1211
+            $img = $img1;
1212
+        }
1213
+
1214
+        return true;
1215
+    }
1216 1216
 }
1217 1217
 
1218 1218
 /**
@@ -1239,34 +1239,34 @@  discard block
 block discarded – undo
1239 1239
  *     Code html modifié de la balise.
1240 1240
  **/
1241 1241
 function _image_tag_changer_taille($tag, $width, $height, $style = false) {
1242
-	if ($style === false) {
1243
-		$style = extraire_attribut($tag, 'style');
1244
-	}
1245
-
1246
-	// enlever le width et height du style
1247
-	if ($style) {
1248
-		$style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1249
-	}
1250
-	if ($style and $style[0] === ';') {
1251
-		$style = substr($style, 1);
1252
-	}
1253
-
1254
-	// mettre des attributs de width et height sur les images,
1255
-	// ca accelere le rendu du navigateur
1256
-	// ca permet aux navigateurs de reserver la bonne taille
1257
-	// quand on a desactive l'affichage des images.
1258
-	$tag = inserer_attribut($tag, 'width', round($width));
1259
-	$tag = inserer_attribut($tag, 'height', round($height));
1260
-
1261
-	// attributs deprecies. Transformer en CSS
1262
-	if ($espace = extraire_attribut($tag, 'hspace')) {
1263
-		$style = "margin:${espace}px;" . $style;
1264
-		$tag = inserer_attribut($tag, 'hspace', '');
1265
-	}
1266
-
1267
-	$tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true);
1268
-
1269
-	return $tag;
1242
+    if ($style === false) {
1243
+        $style = extraire_attribut($tag, 'style');
1244
+    }
1245
+
1246
+    // enlever le width et height du style
1247
+    if ($style) {
1248
+        $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1249
+    }
1250
+    if ($style and $style[0] === ';') {
1251
+        $style = substr($style, 1);
1252
+    }
1253
+
1254
+    // mettre des attributs de width et height sur les images,
1255
+    // ca accelere le rendu du navigateur
1256
+    // ca permet aux navigateurs de reserver la bonne taille
1257
+    // quand on a desactive l'affichage des images.
1258
+    $tag = inserer_attribut($tag, 'width', round($width));
1259
+    $tag = inserer_attribut($tag, 'height', round($height));
1260
+
1261
+    // attributs deprecies. Transformer en CSS
1262
+    if ($espace = extraire_attribut($tag, 'hspace')) {
1263
+        $style = "margin:${espace}px;" . $style;
1264
+        $tag = inserer_attribut($tag, 'hspace', '');
1265
+    }
1266
+
1267
+    $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true);
1268
+
1269
+    return $tag;
1270 1270
 }
1271 1271
 
1272 1272
 
@@ -1292,72 +1292,72 @@  discard block
 block discarded – undo
1292 1292
  *     Retourne le code HTML de l'image
1293 1293
  **/
1294 1294
 function _image_ecrire_tag($valeurs, $surcharge = []) {
1295
-	$valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1296
-
1297
-	// fermer les tags img pas bien fermes;
1298
-	$tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1299
-
1300
-	// le style
1301
-	$style = $valeurs['style'];
1302
-	if (isset($surcharge['style'])) {
1303
-		$style = $surcharge['style'];
1304
-		unset($surcharge['style']);
1305
-	}
1306
-
1307
-	// traiter specifiquement la largeur et la hauteur
1308
-	$width = $valeurs['largeur'];
1309
-	if (isset($surcharge['width'])) {
1310
-		$width = $surcharge['width'];
1311
-		unset($surcharge['width']);
1312
-	}
1313
-	$height = $valeurs['hauteur'];
1314
-	if (isset($surcharge['height'])) {
1315
-		$height = $surcharge['height'];
1316
-		unset($surcharge['height']);
1317
-	}
1318
-
1319
-	$tag = _image_tag_changer_taille($tag, $width, $height, $style);
1320
-	// traiter specifiquement le src qui peut etre repris dans un onmouseout
1321
-	// on remplace toute les ref a src dans le tag
1322
-	$src = extraire_attribut($tag, 'src');
1323
-	if (isset($surcharge['src'])) {
1324
-		$tag = str_replace($src, $surcharge['src'], $tag);
1325
-		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
1326
-		// pas garanti comme methode, mais mieux que rien
1327
-		if (strpos($src, '&') !== false) {
1328
-			$tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1329
-		}
1330
-		$src = $surcharge['src'];
1331
-		unset($surcharge['src']);
1332
-	}
1333
-
1334
-	$class = $valeurs['class'];
1335
-	if (isset($surcharge['class'])) {
1336
-		$class = $surcharge['class'];
1337
-		unset($surcharge['class']);
1338
-	}
1339
-	if (is_scalar($class) && strlen($class)) {
1340
-		$tag = inserer_attribut($tag, 'class', $class);
1341
-	}
1342
-
1343
-	if (count($surcharge)) {
1344
-		foreach ($surcharge as $attribut => $valeur) {
1345
-			$tag = inserer_attribut($tag, $attribut, $valeur);
1346
-		}
1347
-	}
1348
-
1349
-	$tag = pipeline(
1350
-		'image_ecrire_tag_finir',
1351
-		[
1352
-			'args' => [
1353
-				'valeurs' => $valeurs,
1354
-				'surcharge' => $surcharge,
1355
-			],
1356
-			'data' => $tag
1357
-		]
1358
-	);
1359
-
1360
-	return $tag;
1295
+    $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1296
+
1297
+    // fermer les tags img pas bien fermes;
1298
+    $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1299
+
1300
+    // le style
1301
+    $style = $valeurs['style'];
1302
+    if (isset($surcharge['style'])) {
1303
+        $style = $surcharge['style'];
1304
+        unset($surcharge['style']);
1305
+    }
1306
+
1307
+    // traiter specifiquement la largeur et la hauteur
1308
+    $width = $valeurs['largeur'];
1309
+    if (isset($surcharge['width'])) {
1310
+        $width = $surcharge['width'];
1311
+        unset($surcharge['width']);
1312
+    }
1313
+    $height = $valeurs['hauteur'];
1314
+    if (isset($surcharge['height'])) {
1315
+        $height = $surcharge['height'];
1316
+        unset($surcharge['height']);
1317
+    }
1318
+
1319
+    $tag = _image_tag_changer_taille($tag, $width, $height, $style);
1320
+    // traiter specifiquement le src qui peut etre repris dans un onmouseout
1321
+    // on remplace toute les ref a src dans le tag
1322
+    $src = extraire_attribut($tag, 'src');
1323
+    if (isset($surcharge['src'])) {
1324
+        $tag = str_replace($src, $surcharge['src'], $tag);
1325
+        // si il y a des & dans src, alors ils peuvent provenir d'un &amp
1326
+        // pas garanti comme methode, mais mieux que rien
1327
+        if (strpos($src, '&') !== false) {
1328
+            $tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1329
+        }
1330
+        $src = $surcharge['src'];
1331
+        unset($surcharge['src']);
1332
+    }
1333
+
1334
+    $class = $valeurs['class'];
1335
+    if (isset($surcharge['class'])) {
1336
+        $class = $surcharge['class'];
1337
+        unset($surcharge['class']);
1338
+    }
1339
+    if (is_scalar($class) && strlen($class)) {
1340
+        $tag = inserer_attribut($tag, 'class', $class);
1341
+    }
1342
+
1343
+    if (count($surcharge)) {
1344
+        foreach ($surcharge as $attribut => $valeur) {
1345
+            $tag = inserer_attribut($tag, $attribut, $valeur);
1346
+        }
1347
+    }
1348
+
1349
+    $tag = pipeline(
1350
+        'image_ecrire_tag_finir',
1351
+        [
1352
+            'args' => [
1353
+                'valeurs' => $valeurs,
1354
+                'surcharge' => $surcharge,
1355
+            ],
1356
+            'data' => $tag
1357
+        ]
1358
+    );
1359
+
1360
+    return $tag;
1361 1361
 }
1362 1362
 
1363 1363
 /**
@@ -1380,257 +1380,257 @@  discard block
 block discarded – undo
1380 1380
  *     Description de l'image, sinon null.
1381 1381
  **/
1382 1382
 function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) {
1383
-	// ordre de preference des formats graphiques pour creer les vignettes
1384
-	// le premier format disponible, selon la methode demandee, est utilise
1385
-	$image = $valeurs['fichier'];
1386
-	$format = $valeurs['format_source'];
1387
-	$destdir = dirname($valeurs['fichier_dest']);
1388
-	$destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1389
-
1390
-	$format_sortie = $valeurs['format_dest'];
1391
-
1392
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1393
-		$process = $GLOBALS['meta']['image_process'];
1394
-	}
1395
-
1396
-	// si le doc n'est pas une image dans un format accetpable, refuser
1397
-	if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1398
-		return;
1399
-	}
1400
-	$destination = "$destdir/$destfile";
1401
-
1402
-	// calculer la taille
1403
-	if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1404
-		if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1405
-			list($destWidth, $destHeight) = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1406
-		}
1407
-	} elseif ($process == 'convert' or $process == 'imagick') {
1408
-		$destWidth = $maxWidth;
1409
-		$destHeight = $maxHeight;
1410
-	} else {
1411
-		spip_log("echec $process sur $image");
1412
-
1413
-		return;
1414
-	}
1415
-
1416
-	$vignette = '';
1417
-
1418
-	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1419
-	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1420
-		$vignette = $destination . '.' . $format;
1421
-		@copy($image, $vignette);
1422
-	}
1423
-
1424
-	elseif ($valeurs['format_source'] === 'svg') {
1425
-		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1426
-			$format_sortie = 'svg';
1427
-			$vignette = $destination . '.' . $format_sortie;
1428
-			$valeurs['fichier_dest'] = $vignette;
1429
-			_image_gd_output($svg, $valeurs);
1430
-		}
1431
-	}
1432
-
1433
-	// imagemagick en ligne de commande
1434
-	elseif ($process == 'convert') {
1435
-		if (!defined('_CONVERT_COMMAND')) {
1436
-			define('_CONVERT_COMMAND', 'convert');
1437
-		} // Securite : mes_options.php peut preciser le chemin absolu
1438
-		if (!defined('_RESIZE_COMMAND')) {
1439
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1440
-		}
1441
-		$vignette = $destination . '.' . $format_sortie;
1442
-		$commande = str_replace(
1443
-			['%x', '%y', '%src', '%dest'],
1444
-			[
1445
-				$destWidth,
1446
-				$destHeight,
1447
-				escapeshellcmd($image),
1448
-				escapeshellcmd($vignette)
1449
-			],
1450
-			_RESIZE_COMMAND
1451
-		);
1452
-		spip_log($commande);
1453
-		exec($commande);
1454
-		if (!@file_exists($vignette)) {
1455
-			spip_log("echec convert sur $vignette");
1456
-
1457
-			return;  // echec commande
1458
-		}
1459
-	}
1460
-
1461
-	// php5 imagemagick
1462
-	elseif ($process == 'imagick') {
1463
-		$vignette = "$destination." . $format_sortie;
1464
-
1465
-		if (!class_exists('Imagick')) {
1466
-			spip_log('Classe Imagick absente !', _LOG_ERREUR);
1467
-
1468
-			return;
1469
-		}
1470
-		$imagick = new Imagick();
1471
-		$imagick->readImage($image);
1472
-		$imagick->resizeImage(
1473
-			$destWidth,
1474
-			$destHeight,
1475
-			Imagick::FILTER_LANCZOS,
1476
-			1
1477
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1478
-		$imagick->writeImage($vignette);
1479
-
1480
-		if (!@file_exists($vignette)) {
1481
-			spip_log("echec imagick sur $vignette");
1482
-
1483
-			return;
1484
-		}
1485
-	}
1486
-
1487
-	// netpbm
1488
-	elseif ($process == 'netpbm') {
1489
-		if (!defined('_PNMSCALE_COMMAND')) {
1490
-			define('_PNMSCALE_COMMAND', 'pnmscale');
1491
-		} // Securite : mes_options.php peut preciser le chemin absolu
1492
-		if (_PNMSCALE_COMMAND == '') {
1493
-			return;
1494
-		}
1495
-		$vignette = $destination . '.' . $format_sortie;
1496
-		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1497
-		if ($format == 'jpg') {
1498
-			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1499
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1500
-			if (!($s = @filesize($vignette))) {
1501
-				spip_unlink($vignette);
1502
-			}
1503
-			if (!@file_exists($vignette)) {
1504
-				spip_log("echec netpbm-jpg sur $vignette");
1505
-
1506
-				return;
1507
-			}
1508
-		} else {
1509
-			if ($format == 'gif') {
1510
-				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1511
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1512
-				if (!($s = @filesize($vignette))) {
1513
-					spip_unlink($vignette);
1514
-				}
1515
-				if (!@file_exists($vignette)) {
1516
-					spip_log("echec netpbm-gif sur $vignette");
1517
-
1518
-					return;
1519
-				}
1520
-			} else {
1521
-				if ($format == 'png') {
1522
-					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1523
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1524
-					if (!($s = @filesize($vignette))) {
1525
-						spip_unlink($vignette);
1526
-					}
1527
-					if (!@file_exists($vignette)) {
1528
-						spip_log("echec netpbm-png sur $vignette");
1529
-
1530
-						return;
1531
-					}
1532
-				}
1533
-			}
1534
-		}
1535
-	}
1536
-
1537
-	// gd ou gd2
1538
-	elseif ($process == 'gd1' or $process == 'gd2') {
1539
-		if (!function_exists('gd_info')) {
1540
-			spip_log('Librairie GD absente !', _LOG_ERREUR);
1541
-
1542
-			return;
1543
-		}
1544
-		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1545
-			spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1546
-
1547
-			return;
1548
-		}
1549
-		$destFormat = $format_sortie;
1550
-		if (!$destFormat) {
1551
-			spip_log("pas de format pour $image");
1552
-
1553
-			return;
1554
-		}
1555
-
1556
-		$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1557
-		if (!function_exists($fonction_imagecreatefrom)) {
1558
-			return '';
1559
-		}
1560
-		$srcImage = @$fonction_imagecreatefrom($image);
1561
-		if (!$srcImage) {
1562
-			spip_log('echec gd1/gd2');
1563
-
1564
-			return;
1565
-		}
1566
-
1567
-		// Initialisation de l'image destination
1568
-		$destImage = null;
1569
-		if ($process == 'gd2' and $destFormat != 'gif') {
1570
-			$destImage = ImageCreateTrueColor($destWidth, $destHeight);
1571
-		}
1572
-		if (!$destImage) {
1573
-			$destImage = ImageCreate($destWidth, $destHeight);
1574
-		}
1575
-
1576
-		// Recopie de l'image d'origine avec adaptation de la taille
1577
-		$ok = false;
1578
-		if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1579
-			if ($format == 'gif') {
1580
-				// Si un GIF est transparent,
1581
-				// fabriquer un PNG transparent
1582
-				$transp = imagecolortransparent($srcImage);
1583
-				if ($transp > 0) {
1584
-					$destFormat = 'png';
1585
-				}
1586
-			}
1587
-			if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1588
-				// Conserver la transparence
1589
-				if (function_exists('imageAntiAlias')) {
1590
-					imageAntiAlias($destImage, true);
1591
-				}
1592
-				@imagealphablending($destImage, false);
1593
-				@imagesavealpha($destImage, true);
1594
-			}
1595
-			$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1596
-		}
1597
-		if (!$ok) {
1598
-			$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1599
-		}
1600
-
1601
-		// Sauvegarde de l'image destination
1602
-		$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1603
-		$valeurs['format_dest'] = $format = $destFormat;
1604
-		_image_gd_output($destImage, $valeurs);
1605
-
1606
-		if ($srcImage) {
1607
-			ImageDestroy($srcImage);
1608
-		}
1609
-		ImageDestroy($destImage);
1610
-	}
1611
-
1612
-	if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1613
-		$size = [$destWidth, $destHeight];
1614
-	}
1615
-
1616
-	// Gaffe: en safe mode, pas d'acces a la vignette,
1617
-	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1618
-	if ($size[0] < 1) {
1619
-		$size[0] = $destWidth;
1620
-	}
1621
-	if ($size[1] < 1) {
1622
-		$size[1] = $destHeight;
1623
-	}
1624
-
1625
-	$retour['width'] = $largeur = $size[0];
1626
-	$retour['height'] = $hauteur = $size[1];
1627
-
1628
-	$retour['fichier'] = $vignette;
1629
-	$retour['format'] = $format;
1630
-	$retour['date'] = @filemtime($vignette);
1631
-
1632
-	// renvoyer l'image
1633
-	return $retour;
1383
+    // ordre de preference des formats graphiques pour creer les vignettes
1384
+    // le premier format disponible, selon la methode demandee, est utilise
1385
+    $image = $valeurs['fichier'];
1386
+    $format = $valeurs['format_source'];
1387
+    $destdir = dirname($valeurs['fichier_dest']);
1388
+    $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1389
+
1390
+    $format_sortie = $valeurs['format_dest'];
1391
+
1392
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1393
+        $process = $GLOBALS['meta']['image_process'];
1394
+    }
1395
+
1396
+    // si le doc n'est pas une image dans un format accetpable, refuser
1397
+    if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1398
+        return;
1399
+    }
1400
+    $destination = "$destdir/$destfile";
1401
+
1402
+    // calculer la taille
1403
+    if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1404
+        if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1405
+            list($destWidth, $destHeight) = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1406
+        }
1407
+    } elseif ($process == 'convert' or $process == 'imagick') {
1408
+        $destWidth = $maxWidth;
1409
+        $destHeight = $maxHeight;
1410
+    } else {
1411
+        spip_log("echec $process sur $image");
1412
+
1413
+        return;
1414
+    }
1415
+
1416
+    $vignette = '';
1417
+
1418
+    // Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1419
+    if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1420
+        $vignette = $destination . '.' . $format;
1421
+        @copy($image, $vignette);
1422
+    }
1423
+
1424
+    elseif ($valeurs['format_source'] === 'svg') {
1425
+        if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1426
+            $format_sortie = 'svg';
1427
+            $vignette = $destination . '.' . $format_sortie;
1428
+            $valeurs['fichier_dest'] = $vignette;
1429
+            _image_gd_output($svg, $valeurs);
1430
+        }
1431
+    }
1432
+
1433
+    // imagemagick en ligne de commande
1434
+    elseif ($process == 'convert') {
1435
+        if (!defined('_CONVERT_COMMAND')) {
1436
+            define('_CONVERT_COMMAND', 'convert');
1437
+        } // Securite : mes_options.php peut preciser le chemin absolu
1438
+        if (!defined('_RESIZE_COMMAND')) {
1439
+            define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1440
+        }
1441
+        $vignette = $destination . '.' . $format_sortie;
1442
+        $commande = str_replace(
1443
+            ['%x', '%y', '%src', '%dest'],
1444
+            [
1445
+                $destWidth,
1446
+                $destHeight,
1447
+                escapeshellcmd($image),
1448
+                escapeshellcmd($vignette)
1449
+            ],
1450
+            _RESIZE_COMMAND
1451
+        );
1452
+        spip_log($commande);
1453
+        exec($commande);
1454
+        if (!@file_exists($vignette)) {
1455
+            spip_log("echec convert sur $vignette");
1456
+
1457
+            return;  // echec commande
1458
+        }
1459
+    }
1460
+
1461
+    // php5 imagemagick
1462
+    elseif ($process == 'imagick') {
1463
+        $vignette = "$destination." . $format_sortie;
1464
+
1465
+        if (!class_exists('Imagick')) {
1466
+            spip_log('Classe Imagick absente !', _LOG_ERREUR);
1467
+
1468
+            return;
1469
+        }
1470
+        $imagick = new Imagick();
1471
+        $imagick->readImage($image);
1472
+        $imagick->resizeImage(
1473
+            $destWidth,
1474
+            $destHeight,
1475
+            Imagick::FILTER_LANCZOS,
1476
+            1
1477
+        );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1478
+        $imagick->writeImage($vignette);
1479
+
1480
+        if (!@file_exists($vignette)) {
1481
+            spip_log("echec imagick sur $vignette");
1482
+
1483
+            return;
1484
+        }
1485
+    }
1486
+
1487
+    // netpbm
1488
+    elseif ($process == 'netpbm') {
1489
+        if (!defined('_PNMSCALE_COMMAND')) {
1490
+            define('_PNMSCALE_COMMAND', 'pnmscale');
1491
+        } // Securite : mes_options.php peut preciser le chemin absolu
1492
+        if (_PNMSCALE_COMMAND == '') {
1493
+            return;
1494
+        }
1495
+        $vignette = $destination . '.' . $format_sortie;
1496
+        $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1497
+        if ($format == 'jpg') {
1498
+            $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1499
+            exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1500
+            if (!($s = @filesize($vignette))) {
1501
+                spip_unlink($vignette);
1502
+            }
1503
+            if (!@file_exists($vignette)) {
1504
+                spip_log("echec netpbm-jpg sur $vignette");
1505
+
1506
+                return;
1507
+            }
1508
+        } else {
1509
+            if ($format == 'gif') {
1510
+                $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1511
+                exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1512
+                if (!($s = @filesize($vignette))) {
1513
+                    spip_unlink($vignette);
1514
+                }
1515
+                if (!@file_exists($vignette)) {
1516
+                    spip_log("echec netpbm-gif sur $vignette");
1517
+
1518
+                    return;
1519
+                }
1520
+            } else {
1521
+                if ($format == 'png') {
1522
+                    $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1523
+                    exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1524
+                    if (!($s = @filesize($vignette))) {
1525
+                        spip_unlink($vignette);
1526
+                    }
1527
+                    if (!@file_exists($vignette)) {
1528
+                        spip_log("echec netpbm-png sur $vignette");
1529
+
1530
+                        return;
1531
+                    }
1532
+                }
1533
+            }
1534
+        }
1535
+    }
1536
+
1537
+    // gd ou gd2
1538
+    elseif ($process == 'gd1' or $process == 'gd2') {
1539
+        if (!function_exists('gd_info')) {
1540
+            spip_log('Librairie GD absente !', _LOG_ERREUR);
1541
+
1542
+            return;
1543
+        }
1544
+        if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1545
+            spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1546
+
1547
+            return;
1548
+        }
1549
+        $destFormat = $format_sortie;
1550
+        if (!$destFormat) {
1551
+            spip_log("pas de format pour $image");
1552
+
1553
+            return;
1554
+        }
1555
+
1556
+        $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1557
+        if (!function_exists($fonction_imagecreatefrom)) {
1558
+            return '';
1559
+        }
1560
+        $srcImage = @$fonction_imagecreatefrom($image);
1561
+        if (!$srcImage) {
1562
+            spip_log('echec gd1/gd2');
1563
+
1564
+            return;
1565
+        }
1566
+
1567
+        // Initialisation de l'image destination
1568
+        $destImage = null;
1569
+        if ($process == 'gd2' and $destFormat != 'gif') {
1570
+            $destImage = ImageCreateTrueColor($destWidth, $destHeight);
1571
+        }
1572
+        if (!$destImage) {
1573
+            $destImage = ImageCreate($destWidth, $destHeight);
1574
+        }
1575
+
1576
+        // Recopie de l'image d'origine avec adaptation de la taille
1577
+        $ok = false;
1578
+        if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1579
+            if ($format == 'gif') {
1580
+                // Si un GIF est transparent,
1581
+                // fabriquer un PNG transparent
1582
+                $transp = imagecolortransparent($srcImage);
1583
+                if ($transp > 0) {
1584
+                    $destFormat = 'png';
1585
+                }
1586
+            }
1587
+            if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1588
+                // Conserver la transparence
1589
+                if (function_exists('imageAntiAlias')) {
1590
+                    imageAntiAlias($destImage, true);
1591
+                }
1592
+                @imagealphablending($destImage, false);
1593
+                @imagesavealpha($destImage, true);
1594
+            }
1595
+            $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1596
+        }
1597
+        if (!$ok) {
1598
+            $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1599
+        }
1600
+
1601
+        // Sauvegarde de l'image destination
1602
+        $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1603
+        $valeurs['format_dest'] = $format = $destFormat;
1604
+        _image_gd_output($destImage, $valeurs);
1605
+
1606
+        if ($srcImage) {
1607
+            ImageDestroy($srcImage);
1608
+        }
1609
+        ImageDestroy($destImage);
1610
+    }
1611
+
1612
+    if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1613
+        $size = [$destWidth, $destHeight];
1614
+    }
1615
+
1616
+    // Gaffe: en safe mode, pas d'acces a la vignette,
1617
+    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1618
+    if ($size[0] < 1) {
1619
+        $size[0] = $destWidth;
1620
+    }
1621
+    if ($size[1] < 1) {
1622
+        $size[1] = $destHeight;
1623
+    }
1624
+
1625
+    $retour['width'] = $largeur = $size[0];
1626
+    $retour['height'] = $hauteur = $size[1];
1627
+
1628
+    $retour['fichier'] = $vignette;
1629
+    $retour['format'] = $format;
1630
+    $retour['date'] = @filemtime($vignette);
1631
+
1632
+    // renvoyer l'image
1633
+    return $retour;
1634 1634
 }
1635 1635
 
1636 1636
 /**
@@ -1650,25 +1650,25 @@  discard block
 block discarded – undo
1650 1650
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1651 1651
  **/
1652 1652
 function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1653
-	$ratioWidth = $srcWidth / $maxWidth;
1654
-	$ratioHeight = $srcHeight / $maxHeight;
1655
-
1656
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1657
-		$destWidth = $srcWidth;
1658
-		$destHeight = $srcHeight;
1659
-	} elseif ($ratioWidth < $ratioHeight) {
1660
-		$destWidth = $srcWidth / $ratioHeight;
1661
-		$destHeight = $maxHeight;
1662
-	} else {
1663
-		$destWidth = $maxWidth;
1664
-		$destHeight = $srcHeight / $ratioWidth;
1665
-	}
1666
-
1667
-	return [
1668
-		intval(round($destWidth)),
1669
-		intval(round($destHeight)),
1670
-		max($ratioWidth, $ratioHeight)
1671
-	];
1653
+    $ratioWidth = $srcWidth / $maxWidth;
1654
+    $ratioHeight = $srcHeight / $maxHeight;
1655
+
1656
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1657
+        $destWidth = $srcWidth;
1658
+        $destHeight = $srcHeight;
1659
+    } elseif ($ratioWidth < $ratioHeight) {
1660
+        $destWidth = $srcWidth / $ratioHeight;
1661
+        $destHeight = $maxHeight;
1662
+    } else {
1663
+        $destWidth = $maxWidth;
1664
+        $destHeight = $srcHeight / $ratioWidth;
1665
+    }
1666
+
1667
+    return [
1668
+        intval(round($destWidth)),
1669
+        intval(round($destHeight)),
1670
+        max($ratioWidth, $ratioHeight)
1671
+    ];
1672 1672
 }
1673 1673
 
1674 1674
 /**
@@ -1688,25 +1688,25 @@  discard block
 block discarded – undo
1688 1688
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1689 1689
  **/
1690 1690
 function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1691
-	$ratioWidth = $srcWidth / $maxWidth;
1692
-	$ratioHeight = $srcHeight / $maxHeight;
1693
-
1694
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1695
-		$destWidth = $srcWidth;
1696
-		$destHeight = $srcHeight;
1697
-	} elseif ($ratioWidth > $ratioHeight) {
1698
-		$destWidth = $srcWidth / $ratioHeight;
1699
-		$destHeight = $maxHeight;
1700
-	} else {
1701
-		$destWidth = $maxWidth;
1702
-		$destHeight = $srcHeight / $ratioWidth;
1703
-	}
1704
-
1705
-	return [
1706
-		intval(round($destWidth)),
1707
-		intval(round($destHeight)),
1708
-		min($ratioWidth, $ratioHeight)
1709
-	];
1691
+    $ratioWidth = $srcWidth / $maxWidth;
1692
+    $ratioHeight = $srcHeight / $maxHeight;
1693
+
1694
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1695
+        $destWidth = $srcWidth;
1696
+        $destHeight = $srcHeight;
1697
+    } elseif ($ratioWidth > $ratioHeight) {
1698
+        $destWidth = $srcWidth / $ratioHeight;
1699
+        $destHeight = $maxHeight;
1700
+    } else {
1701
+        $destWidth = $maxWidth;
1702
+        $destHeight = $srcHeight / $ratioWidth;
1703
+    }
1704
+
1705
+    return [
1706
+        intval(round($destWidth)),
1707
+        intval(round($destHeight)),
1708
+        min($ratioWidth, $ratioHeight)
1709
+    ];
1710 1710
 }
1711 1711
 
1712 1712
 
@@ -1719,12 +1719,12 @@  discard block
 block discarded – undo
1719 1719
  * @return string
1720 1720
  */
1721 1721
 function process_image_svg_identite($image) {
1722
-	if ($image['creer']) {
1723
-		$source = $image['fichier'];
1724
-		_image_gd_output($source, $image);
1725
-	}
1722
+    if ($image['creer']) {
1723
+        $source = $image['fichier'];
1724
+        _image_gd_output($source, $image);
1725
+    }
1726 1726
 
1727
-	return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1727
+    return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1728 1728
 }
1729 1729
 
1730 1730
 
@@ -1757,111 +1757,111 @@  discard block
 block discarded – undo
1757 1757
  *     Code HTML de la balise img produite
1758 1758
  **/
1759 1759
 function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') {
1760
-	$image = false;
1761
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1762
-		$process = $GLOBALS['meta']['image_process'];
1763
-	}
1764
-	# determiner le format de sortie
1765
-	$format_sortie = false; // le choix par defaut sera bon
1766
-	if ($process == 'netpbm') {
1767
-		$format_sortie = 'jpg';
1768
-	} elseif ($process == 'gd1' or $process == 'gd2') {
1769
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1770
-		// on verifie que l'extension choisie est bonne (en principe oui)
1771
-		$gd_formats = formats_image_acceptables(true);
1772
-		if (
1773
-			is_array($image)
1774
-			and (!in_array($image['format_dest'], $gd_formats)
1775
-				or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1776
-			)
1777
-		) {
1778
-			if ($image['format_source'] == 'jpg') {
1779
-				$formats_sortie = ['jpg', 'png', 'gif'];
1780
-			} else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1781
-			{
1782
-				$formats_sortie = ['png', 'jpg', 'gif'];
1783
-			}
1784
-			// Choisir le format destination
1785
-			// - on sauve de preference en JPEG (meilleure compression)
1786
-			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1787
-			# bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1788
-			# pas *ecrire*
1789
-			$format_sortie = '';
1790
-			foreach ($formats_sortie as $fmt) {
1791
-				if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1792
-					$format_sortie = $fmt;
1793
-					break;
1794
-				}
1795
-			}
1796
-			$image = false;
1797
-		}
1798
-	}
1799
-
1800
-	if (!is_array($image)) {
1801
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1802
-	}
1803
-
1804
-	if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1805
-		spip_log("image_reduire_src:pas de version locale de $img");
1806
-		// on peut resizer en mode html si on dispose des elements
1807
-		if (
1808
-			$srcw = extraire_attribut($img, 'width')
1809
-			and $srch = extraire_attribut($img, 'height')
1810
-		) {
1811
-			list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y);
1812
-
1813
-			return _image_tag_changer_taille($img, $w, $h);
1814
-		}
1815
-		// la on n'a pas d'infos sur l'image source... on refile le truc a css
1816
-		// sous la forme style='max-width: NNpx;'
1817
-		return inserer_attribut(
1818
-			$img,
1819
-			'style',
1820
-			"max-width: ${taille}px; max-height: ${taille_y}px"
1821
-		);
1822
-	}
1823
-
1824
-	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1825
-	if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1826
-		if ($image['creer']) {
1827
-			@copy($image['fichier'], $image['fichier_dest']);
1828
-		}
1829
-
1830
-		return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1831
-	}
1832
-
1833
-	if ($image['creer'] == false && !$force) {
1834
-		return _image_ecrire_tag(
1835
-			$image,
1836
-			['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1837
-		);
1838
-	}
1839
-
1840
-	if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1841
-		$destWidth = $image['largeur_dest'];
1842
-		$destHeight = $image['hauteur_dest'];
1843
-		$logo = $image['fichier'];
1844
-		$date = $image['date_src'];
1845
-		$preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1846
-
1847
-		if ($preview && $preview['fichier']) {
1848
-			$logo = $preview['fichier'];
1849
-			$destWidth = $preview['width'];
1850
-			$destHeight = $preview['height'];
1851
-			$date = $preview['date'];
1852
-		}
1853
-		// dans l'espace prive mettre un timestamp sur l'adresse
1854
-		// de l'image, de facon a tromper le cache du navigateur
1855
-		// quand on fait supprimer/reuploader un logo
1856
-		// (pas de filemtime si SAFE MODE)
1857
-		$date = test_espace_prive() ? ('?' . $date) : '';
1858
-
1859
-		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1860
-	}
1861
-	else {
1862
-		# BMP, tiff ... les redacteurs osent tout!
1863
-		return $img;
1864
-	}
1760
+    $image = false;
1761
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1762
+        $process = $GLOBALS['meta']['image_process'];
1763
+    }
1764
+    # determiner le format de sortie
1765
+    $format_sortie = false; // le choix par defaut sera bon
1766
+    if ($process == 'netpbm') {
1767
+        $format_sortie = 'jpg';
1768
+    } elseif ($process == 'gd1' or $process == 'gd2') {
1769
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1770
+        // on verifie que l'extension choisie est bonne (en principe oui)
1771
+        $gd_formats = formats_image_acceptables(true);
1772
+        if (
1773
+            is_array($image)
1774
+            and (!in_array($image['format_dest'], $gd_formats)
1775
+                or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1776
+            )
1777
+        ) {
1778
+            if ($image['format_source'] == 'jpg') {
1779
+                $formats_sortie = ['jpg', 'png', 'gif'];
1780
+            } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1781
+            {
1782
+                $formats_sortie = ['png', 'jpg', 'gif'];
1783
+            }
1784
+            // Choisir le format destination
1785
+            // - on sauve de preference en JPEG (meilleure compression)
1786
+            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1787
+            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1788
+            # pas *ecrire*
1789
+            $format_sortie = '';
1790
+            foreach ($formats_sortie as $fmt) {
1791
+                if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1792
+                    $format_sortie = $fmt;
1793
+                    break;
1794
+                }
1795
+            }
1796
+            $image = false;
1797
+        }
1798
+    }
1799
+
1800
+    if (!is_array($image)) {
1801
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1802
+    }
1803
+
1804
+    if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1805
+        spip_log("image_reduire_src:pas de version locale de $img");
1806
+        // on peut resizer en mode html si on dispose des elements
1807
+        if (
1808
+            $srcw = extraire_attribut($img, 'width')
1809
+            and $srch = extraire_attribut($img, 'height')
1810
+        ) {
1811
+            list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y);
1812
+
1813
+            return _image_tag_changer_taille($img, $w, $h);
1814
+        }
1815
+        // la on n'a pas d'infos sur l'image source... on refile le truc a css
1816
+        // sous la forme style='max-width: NNpx;'
1817
+        return inserer_attribut(
1818
+            $img,
1819
+            'style',
1820
+            "max-width: ${taille}px; max-height: ${taille_y}px"
1821
+        );
1822
+    }
1823
+
1824
+    // si l'image est plus petite que la cible retourner une copie cachee de l'image
1825
+    if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1826
+        if ($image['creer']) {
1827
+            @copy($image['fichier'], $image['fichier_dest']);
1828
+        }
1829
+
1830
+        return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1831
+    }
1832
+
1833
+    if ($image['creer'] == false && !$force) {
1834
+        return _image_ecrire_tag(
1835
+            $image,
1836
+            ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1837
+        );
1838
+    }
1839
+
1840
+    if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1841
+        $destWidth = $image['largeur_dest'];
1842
+        $destHeight = $image['hauteur_dest'];
1843
+        $logo = $image['fichier'];
1844
+        $date = $image['date_src'];
1845
+        $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1846
+
1847
+        if ($preview && $preview['fichier']) {
1848
+            $logo = $preview['fichier'];
1849
+            $destWidth = $preview['width'];
1850
+            $destHeight = $preview['height'];
1851
+            $date = $preview['date'];
1852
+        }
1853
+        // dans l'espace prive mettre un timestamp sur l'adresse
1854
+        // de l'image, de facon a tromper le cache du navigateur
1855
+        // quand on fait supprimer/reuploader un logo
1856
+        // (pas de filemtime si SAFE MODE)
1857
+        $date = test_espace_prive() ? ('?' . $date) : '';
1858
+
1859
+        return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1860
+    }
1861
+    else {
1862
+        # BMP, tiff ... les redacteurs osent tout!
1863
+        return $img;
1864
+    }
1865 1865
 }
1866 1866
 
1867 1867
 /**
@@ -1876,145 +1876,145 @@  discard block
 block discarded – undo
1876 1876
  */
1877 1877
 class phpthumb_functions {
1878 1878
 
1879
-	/**
1880
-	 * Retourne la couleur d'un pixel dans une image
1881
-	 *
1882
-	 * @param ressource $img
1883
-	 * @param int $x
1884
-	 * @param int $y
1885
-	 * @return array|bool
1886
-	 */
1887
-	public static function GetPixelColor(&$img, $x, $y) {
1888
-		if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1889
-			return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1890
-		}
1891
-		return false;
1892
-	}
1893
-
1894
-	/**
1895
-	 * Retourne un nombre dans une représentation en Little Endian
1896
-	 *
1897
-	 * @param int $number
1898
-	 * @param int $minbytes
1899
-	 * @return string
1900
-	 */
1901
-	public static function LittleEndian2String($number, $minbytes = 1) {
1902
-		$intstring = '';
1903
-		while ($number > 0) {
1904
-			$intstring = $intstring . chr($number & 255);
1905
-			$number >>= 8;
1906
-		}
1907
-
1908
-		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1909
-	}
1910
-
1911
-	/**
1912
-	 * Transforme une ressource GD en image au format ICO
1913
-	 *
1914
-	 * @param array $gd_image_array
1915
-	 *     Tableau de ressources d'images GD
1916
-	 * @return string
1917
-	 *     Image au format ICO
1918
-	 */
1919
-	public static function GD2ICOstring(&$gd_image_array) {
1920
-		foreach ($gd_image_array as $key => $gd_image) {
1921
-			$ImageWidths[$key] = ImageSX($gd_image);
1922
-			$ImageHeights[$key] = ImageSY($gd_image);
1923
-			$bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1924
-			$totalcolors[$key] = ImageColorsTotal($gd_image);
1925
-
1926
-			$icXOR[$key] = '';
1927
-			for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1928
-				for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1929
-					$argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1930
-					$a = round(255 * ((127 - $argb['alpha']) / 127));
1931
-					$r = $argb['red'];
1932
-					$g = $argb['green'];
1933
-					$b = $argb['blue'];
1934
-
1935
-					if ($bpp[$key] == 32) {
1936
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1937
-					} elseif ($bpp[$key] == 24) {
1938
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1939
-					}
1940
-
1941
-					if ($a < 128) {
1942
-						@$icANDmask[$key][$y] .= '1';
1943
-					} else {
1944
-						@$icANDmask[$key][$y] .= '0';
1945
-					}
1946
-				}
1947
-				// mask bits are 32-bit aligned per scanline
1948
-				while (strlen($icANDmask[$key][$y]) % 32) {
1949
-					$icANDmask[$key][$y] .= '0';
1950
-				}
1951
-			}
1952
-			$icAND[$key] = '';
1953
-			foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1954
-				for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1955
-					$icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1956
-				}
1957
-			}
1958
-		}
1959
-
1960
-		foreach ($gd_image_array as $key => $gd_image) {
1961
-			$biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1962
-
1963
-			// BITMAPINFOHEADER - 40 bytes
1964
-			$BitmapInfoHeader[$key] = '';
1965
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1966
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1967
-			// The biHeight member specifies the combined
1968
-			// height of the XOR and AND masks.
1969
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1970
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1971
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1972
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1973
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1974
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1975
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1976
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1977
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1978
-		}
1979
-
1980
-
1981
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1982
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1983
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1984
-
1985
-		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1986
-		foreach ($gd_image_array as $key => $gd_image) {
1987
-			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1988
-
1989
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1990
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1991
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1992
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1993
-
1994
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1995
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1996
-
1997
-			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1998
-			$icondata .= phpthumb_functions::LittleEndian2String(
1999
-				$dwBytesInRes,
2000
-				4
2001
-			);     // dwBytesInRes;	// How many bytes in this resource?
2002
-
2003
-			$icondata .= phpthumb_functions::LittleEndian2String(
2004
-				$dwImageOffset,
2005
-				4
2006
-			);    // dwImageOffset;   // Where in the file is this image?
2007
-			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
2008
-			$dwImageOffset += strlen($icXOR[$key]);
2009
-			$dwImageOffset += strlen($icAND[$key]);
2010
-		}
2011
-
2012
-		foreach ($gd_image_array as $key => $gd_image) {
2013
-			$icondata .= $BitmapInfoHeader[$key];
2014
-			$icondata .= $icXOR[$key];
2015
-			$icondata .= $icAND[$key];
2016
-		}
2017
-
2018
-		return $icondata;
2019
-	}
1879
+    /**
1880
+     * Retourne la couleur d'un pixel dans une image
1881
+     *
1882
+     * @param ressource $img
1883
+     * @param int $x
1884
+     * @param int $y
1885
+     * @return array|bool
1886
+     */
1887
+    public static function GetPixelColor(&$img, $x, $y) {
1888
+        if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1889
+            return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1890
+        }
1891
+        return false;
1892
+    }
1893
+
1894
+    /**
1895
+     * Retourne un nombre dans une représentation en Little Endian
1896
+     *
1897
+     * @param int $number
1898
+     * @param int $minbytes
1899
+     * @return string
1900
+     */
1901
+    public static function LittleEndian2String($number, $minbytes = 1) {
1902
+        $intstring = '';
1903
+        while ($number > 0) {
1904
+            $intstring = $intstring . chr($number & 255);
1905
+            $number >>= 8;
1906
+        }
1907
+
1908
+        return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1909
+    }
1910
+
1911
+    /**
1912
+     * Transforme une ressource GD en image au format ICO
1913
+     *
1914
+     * @param array $gd_image_array
1915
+     *     Tableau de ressources d'images GD
1916
+     * @return string
1917
+     *     Image au format ICO
1918
+     */
1919
+    public static function GD2ICOstring(&$gd_image_array) {
1920
+        foreach ($gd_image_array as $key => $gd_image) {
1921
+            $ImageWidths[$key] = ImageSX($gd_image);
1922
+            $ImageHeights[$key] = ImageSY($gd_image);
1923
+            $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1924
+            $totalcolors[$key] = ImageColorsTotal($gd_image);
1925
+
1926
+            $icXOR[$key] = '';
1927
+            for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1928
+                for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1929
+                    $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1930
+                    $a = round(255 * ((127 - $argb['alpha']) / 127));
1931
+                    $r = $argb['red'];
1932
+                    $g = $argb['green'];
1933
+                    $b = $argb['blue'];
1934
+
1935
+                    if ($bpp[$key] == 32) {
1936
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1937
+                    } elseif ($bpp[$key] == 24) {
1938
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r);
1939
+                    }
1940
+
1941
+                    if ($a < 128) {
1942
+                        @$icANDmask[$key][$y] .= '1';
1943
+                    } else {
1944
+                        @$icANDmask[$key][$y] .= '0';
1945
+                    }
1946
+                }
1947
+                // mask bits are 32-bit aligned per scanline
1948
+                while (strlen($icANDmask[$key][$y]) % 32) {
1949
+                    $icANDmask[$key][$y] .= '0';
1950
+                }
1951
+            }
1952
+            $icAND[$key] = '';
1953
+            foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1954
+                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1955
+                    $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1956
+                }
1957
+            }
1958
+        }
1959
+
1960
+        foreach ($gd_image_array as $key => $gd_image) {
1961
+            $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1962
+
1963
+            // BITMAPINFOHEADER - 40 bytes
1964
+            $BitmapInfoHeader[$key] = '';
1965
+            $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1966
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1967
+            // The biHeight member specifies the combined
1968
+            // height of the XOR and AND masks.
1969
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1970
+            $BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1971
+            $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1972
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1973
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1974
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1975
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1976
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1977
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1978
+        }
1979
+
1980
+
1981
+        $icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1982
+        $icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1983
+        $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1984
+
1985
+        $dwImageOffset = 6 + (count($gd_image_array) * 16);
1986
+        foreach ($gd_image_array as $key => $gd_image) {
1987
+            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1988
+
1989
+            $icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1990
+            $icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1991
+            $icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1992
+            $icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1993
+
1994
+            $icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1995
+            $icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1996
+
1997
+            $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1998
+            $icondata .= phpthumb_functions::LittleEndian2String(
1999
+                $dwBytesInRes,
2000
+                4
2001
+            );     // dwBytesInRes;	// How many bytes in this resource?
2002
+
2003
+            $icondata .= phpthumb_functions::LittleEndian2String(
2004
+                $dwImageOffset,
2005
+                4
2006
+            );    // dwImageOffset;   // Where in the file is this image?
2007
+            $dwImageOffset += strlen($BitmapInfoHeader[$key]);
2008
+            $dwImageOffset += strlen($icXOR[$key]);
2009
+            $dwImageOffset += strlen($icAND[$key]);
2010
+        }
2011
+
2012
+        foreach ($gd_image_array as $key => $gd_image) {
2013
+            $icondata .= $BitmapInfoHeader[$key];
2014
+            $icondata .= $icXOR[$key];
2015
+            $icondata .= $icAND[$key];
2016
+        }
2017
+
2018
+        return $icondata;
2019
+    }
2020 2020
 }
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -43,13 +43,13 @@  discard block
 block discarded – undo
43 43
 	$blue = dechex($blue);
44 44
 
45 45
 	if (strlen($red) == 1) {
46
-		$red = '0' . $red;
46
+		$red = '0'.$red;
47 47
 	}
48 48
 	if (strlen($green) == 1) {
49
-		$green = '0' . $green;
49
+		$green = '0'.$green;
50 50
 	}
51 51
 	if (strlen($blue) == 1) {
52
-		$blue = '0' . $blue;
52
+		$blue = '0'.$blue;
53 53
 	}
54 54
 
55 55
 	return "$red$green$blue";
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	$couleur = couleur_html_to_hex($couleur);
68 68
 	$couleur = ltrim($couleur, '#');
69 69
 	if (strlen($couleur) === 3) {
70
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
70
+		$couleur = $couleur[0].$couleur[0].$couleur[1].$couleur[1].$couleur[2].$couleur[2];
71 71
 	}
72 72
 	$retour = [];
73 73
 	$retour['red'] = hexdec(substr($couleur, 0, 2));
@@ -124,9 +124,9 @@  discard block
 block discarded – undo
124 124
 	$var_G = ($G / 255);
125 125
 	$var_B = ($B / 255);
126 126
 
127
-	$var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
128
-	$var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
129
-	$del_Max = $var_Max - $var_Min;           //Delta RGB value
127
+	$var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB
128
+	$var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB
129
+	$del_Max = $var_Max - $var_Min; //Delta RGB value
130 130
 
131 131
 	$L = ($var_Max + $var_Min) / 2;
132 132
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
  */
189 189
 function _couleur_hsl_to_rgb($H, $S, $L) {
190 190
 	// helper
191
-	$hue_2_rgb = function ($v1, $v2, $vH) {
191
+	$hue_2_rgb = function($v1, $v2, $vH) {
192 192
 		if ($vH < 0) {
193 193
 			$vH += 1;
194 194
 		}
@@ -317,11 +317,11 @@  discard block
 block discarded – undo
317 317
 		$img = "<img src='$source' />";
318 318
 	} elseif (
319 319
 		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
320
-		and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
320
+		and $extension = _image_trouver_extension_depuis_mime('image/'.$regs[1])
321 321
 		and in_array($extension, _image_extensions_acceptees_en_entree())
322 322
 	) {
323 323
 		# gerer img src="data:....base64"
324
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
324
+		$local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'._image_extension_normalisee($extension);
325 325
 		if (!file_exists($local)) {
326 326
 			ecrire_fichier($local, base64_decode($regs[2]));
327 327
 		}
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 	// les protocoles web prennent au moins 3 lettres
339 339
 	if (tester_url_absolue($source)) {
340 340
 		include_spip('inc/distant');
341
-		$fichier = _DIR_RACINE . copie_locale($source);
341
+		$fichier = _DIR_RACINE.copie_locale($source);
342 342
 		if (!$fichier) {
343 343
 			return '';
344 344
 		}
@@ -436,9 +436,9 @@  discard block
 block discarded – undo
436 436
 			// on garde la terminaison initiale car image simplement copiee
437 437
 			// et on postfixe son nom avec un md5 du path
438 438
 			$terminaison_dest = $terminaison;
439
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
439
+			$fichier_dest .= '-'.substr(md5("$identifiant"), 0, 5);
440 440
 		} else {
441
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
441
+			$fichier_dest .= '-'.substr(md5("$identifiant-$effet"), 0, 5);
442 442
 		}
443 443
 		$cache = sous_repertoire(_DIR_VAR, $cache);
444 444
 		$cache = sous_repertoire($cache, $effet);
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
 		$fichier_dest = substr($fichier_dest, 2);
450 450
 	}
451 451
 
452
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
452
+	$fichier_dest = $cache.$fichier_dest.'.'.$terminaison_dest;
453 453
 
454 454
 	$GLOBALS['images_calculees'][] = $fichier_dest;
455 455
 
@@ -487,15 +487,15 @@  discard block
 block discarded – undo
487 487
 
488 488
 	if ($creer) {
489 489
 		spip_log(
490
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
491
-			'images' . _LOG_DEBUG
490
+			'filtre image '.($fonction_creation ? reset($fonction_creation) : '')."[$effet] sur $fichier",
491
+			'images'._LOG_DEBUG
492 492
 		);
493 493
 	}
494 494
 
495 495
 	$term_fonction = _image_trouver_extension_pertinente($fichier);
496
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
496
+	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom'.$term_fonction;
497 497
 	$ret['fichier'] = $fichier;
498
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
498
+	$ret['fonction_image'] = '_image_image'.$terminaison_dest;
499 499
 	$ret['fichier_dest'] = $fichier_dest;
500 500
 	$ret['format_source'] = _image_extension_normalisee($terminaison);
501 501
 	$ret['format_dest'] = $terminaison_dest;
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
 
645 645
 	$_terminaison = _image_trouver_extension_depuis_mime($mime);
646 646
 	if ($_terminaison and $_terminaison !== $terminaison) {
647
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
647
+		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.'._LOG_INFO_IMPORTANTE);
648 648
 		$terminaison = $_terminaison;
649 649
 	}
650 650
 	return $terminaison;
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
 	if (!function_exists('imagepng')) {
802 802
 		return false;
803 803
 	}
804
-	$tmp = $fichier . '.tmp';
804
+	$tmp = $fichier.'.tmp';
805 805
 	$ret = imagepng($img, $tmp);
806 806
 	if (file_exists($tmp)) {
807 807
 		$taille_test = getimagesize($tmp);
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
 	if (!function_exists('imagegif')) {
837 837
 		return false;
838 838
 	}
839
-	$tmp = $fichier . '.tmp';
839
+	$tmp = $fichier.'.tmp';
840 840
 	$ret = imagegif($img, $tmp);
841 841
 	if (file_exists($tmp)) {
842 842
 		$taille_test = getimagesize($tmp);
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
 	if (!function_exists('imagejpeg')) {
877 877
 		return false;
878 878
 	}
879
-	$tmp = $fichier . '.tmp';
879
+	$tmp = $fichier.'.tmp';
880 880
 
881 881
 	// Enable interlancing
882 882
 	imageinterlace($img, true);
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
 	if (!function_exists('imagewebp')) {
938 938
 		return false;
939 939
 	}
940
-	$tmp = $fichier . '.tmp';
940
+	$tmp = $fichier.'.tmp';
941 941
 	$ret = imagewebp($img, $tmp, $qualite);
942 942
 	if (file_exists($tmp)) {
943 943
 		$taille_test = getimagesize($tmp);
@@ -971,7 +971,7 @@  discard block
 block discarded – undo
971 971
  */
972 972
 function _image_imagesvg($img, $fichier) {
973 973
 
974
-	$tmp = $fichier . '.tmp';
974
+	$tmp = $fichier.'.tmp';
975 975
 	if (strpos($img, '<') === false) {
976 976
 		$img = supprimer_timestamp($img);
977 977
 		if (!file_exists($img)) {
@@ -1028,13 +1028,13 @@  discard block
 block discarded – undo
1028 1028
  */
1029 1029
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1030 1030
 	if (is_null($fonction)) {
1031
-		$fonction = '_image_image' . $valeurs['format_dest'];
1031
+		$fonction = '_image_image'.$valeurs['format_dest'];
1032 1032
 	}
1033 1033
 	$ret = false;
1034 1034
 	#un flag pour reperer les images gravees
1035 1035
 	$lock =
1036 1036
 		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1037
-	or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
1037
+	or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'].'.src'));
1038 1038
 	if (
1039 1039
 		function_exists($fonction)
1040 1040
 		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
@@ -1045,7 +1045,7 @@  discard block
 block discarded – undo
1045 1045
 			// dans tous les cas mettre a jour la taille de l'image finale
1046 1046
 			list($valeurs['hauteur_dest'], $valeurs['largeur_dest']) = taille_image($valeurs['fichier_dest']);
1047 1047
 			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1048
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1048
+			ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true);
1049 1049
 		}
1050 1050
 	}
1051 1051
 
@@ -1260,7 +1260,7 @@  discard block
 block discarded – undo
1260 1260
 
1261 1261
 	// attributs deprecies. Transformer en CSS
1262 1262
 	if ($espace = extraire_attribut($tag, 'hspace')) {
1263
-		$style = "margin:${espace}px;" . $style;
1263
+		$style = "margin:${espace}px;".$style;
1264 1264
 		$tag = inserer_attribut($tag, 'hspace', '');
1265 1265
 	}
1266 1266
 
@@ -1385,7 +1385,7 @@  discard block
 block discarded – undo
1385 1385
 	$image = $valeurs['fichier'];
1386 1386
 	$format = $valeurs['format_source'];
1387 1387
 	$destdir = dirname($valeurs['fichier_dest']);
1388
-	$destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1388
+	$destfile = basename($valeurs['fichier_dest'], '.'.$valeurs['format_dest']);
1389 1389
 
1390 1390
 	$format_sortie = $valeurs['format_dest'];
1391 1391
 
@@ -1417,14 +1417,14 @@  discard block
 block discarded – undo
1417 1417
 
1418 1418
 	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1419 1419
 	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1420
-		$vignette = $destination . '.' . $format;
1420
+		$vignette = $destination.'.'.$format;
1421 1421
 		@copy($image, $vignette);
1422 1422
 	}
1423 1423
 
1424 1424
 	elseif ($valeurs['format_source'] === 'svg') {
1425 1425
 		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1426 1426
 			$format_sortie = 'svg';
1427
-			$vignette = $destination . '.' . $format_sortie;
1427
+			$vignette = $destination.'.'.$format_sortie;
1428 1428
 			$valeurs['fichier_dest'] = $vignette;
1429 1429
 			_image_gd_output($svg, $valeurs);
1430 1430
 		}
@@ -1436,9 +1436,9 @@  discard block
 block discarded – undo
1436 1436
 			define('_CONVERT_COMMAND', 'convert');
1437 1437
 		} // Securite : mes_options.php peut preciser le chemin absolu
1438 1438
 		if (!defined('_RESIZE_COMMAND')) {
1439
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1439
+			define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -resize %xx%y! %src %dest');
1440 1440
 		}
1441
-		$vignette = $destination . '.' . $format_sortie;
1441
+		$vignette = $destination.'.'.$format_sortie;
1442 1442
 		$commande = str_replace(
1443 1443
 			['%x', '%y', '%src', '%dest'],
1444 1444
 			[
@@ -1454,13 +1454,13 @@  discard block
 block discarded – undo
1454 1454
 		if (!@file_exists($vignette)) {
1455 1455
 			spip_log("echec convert sur $vignette");
1456 1456
 
1457
-			return;  // echec commande
1457
+			return; // echec commande
1458 1458
 		}
1459 1459
 	}
1460 1460
 
1461 1461
 	// php5 imagemagick
1462 1462
 	elseif ($process == 'imagick') {
1463
-		$vignette = "$destination." . $format_sortie;
1463
+		$vignette = "$destination.".$format_sortie;
1464 1464
 
1465 1465
 		if (!class_exists('Imagick')) {
1466 1466
 			spip_log('Classe Imagick absente !', _LOG_ERREUR);
@@ -1474,7 +1474,7 @@  discard block
 block discarded – undo
1474 1474
 			$destHeight,
1475 1475
 			Imagick::FILTER_LANCZOS,
1476 1476
 			1
1477
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1477
+		); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1478 1478
 		$imagick->writeImage($vignette);
1479 1479
 
1480 1480
 		if (!@file_exists($vignette)) {
@@ -1492,11 +1492,11 @@  discard block
 block discarded – undo
1492 1492
 		if (_PNMSCALE_COMMAND == '') {
1493 1493
 			return;
1494 1494
 		}
1495
-		$vignette = $destination . '.' . $format_sortie;
1495
+		$vignette = $destination.'.'.$format_sortie;
1496 1496
 		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1497 1497
 		if ($format == 'jpg') {
1498 1498
 			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1499
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1499
+			exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1500 1500
 			if (!($s = @filesize($vignette))) {
1501 1501
 				spip_unlink($vignette);
1502 1502
 			}
@@ -1508,7 +1508,7 @@  discard block
 block discarded – undo
1508 1508
 		} else {
1509 1509
 			if ($format == 'gif') {
1510 1510
 				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1511
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1511
+				exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1512 1512
 				if (!($s = @filesize($vignette))) {
1513 1513
 					spip_unlink($vignette);
1514 1514
 				}
@@ -1520,7 +1520,7 @@  discard block
 block discarded – undo
1520 1520
 			} else {
1521 1521
 				if ($format == 'png') {
1522 1522
 					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1523
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1523
+					exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1524 1524
 					if (!($s = @filesize($vignette))) {
1525 1525
 						spip_unlink($vignette);
1526 1526
 					}
@@ -1542,7 +1542,7 @@  discard block
 block discarded – undo
1542 1542
 			return;
1543 1543
 		}
1544 1544
 		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1545
-			spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1545
+			spip_log('vignette gd1/gd2 impossible : '.$srcWidth * $srcHeight.'pixels');
1546 1546
 
1547 1547
 			return;
1548 1548
 		}
@@ -1854,7 +1854,7 @@  discard block
 block discarded – undo
1854 1854
 		// de l'image, de facon a tromper le cache du navigateur
1855 1855
 		// quand on fait supprimer/reuploader un logo
1856 1856
 		// (pas de filemtime si SAFE MODE)
1857
-		$date = test_espace_prive() ? ('?' . $date) : '';
1857
+		$date = test_espace_prive() ? ('?'.$date) : '';
1858 1858
 
1859 1859
 		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1860 1860
 	}
@@ -1901,7 +1901,7 @@  discard block
 block discarded – undo
1901 1901
 	public static function LittleEndian2String($number, $minbytes = 1) {
1902 1902
 		$intstring = '';
1903 1903
 		while ($number > 0) {
1904
-			$intstring = $intstring . chr($number & 255);
1904
+			$intstring = $intstring.chr($number & 255);
1905 1905
 			$number >>= 8;
1906 1906
 		}
1907 1907
 
@@ -1933,9 +1933,9 @@  discard block
 block discarded – undo
1933 1933
 					$b = $argb['blue'];
1934 1934
 
1935 1935
 					if ($bpp[$key] == 32) {
1936
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1936
+						$icXOR[$key] .= chr($b).chr($g).chr($r).chr($a);
1937 1937
 					} elseif ($bpp[$key] == 24) {
1938
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1938
+						$icXOR[$key] .= chr($b).chr($g).chr($r);
1939 1939
 					}
1940 1940
 
1941 1941
 					if ($a < 128) {
@@ -1962,48 +1962,48 @@  discard block
 block discarded – undo
1962 1962
 
1963 1963
 			// BITMAPINFOHEADER - 40 bytes
1964 1964
 			$BitmapInfoHeader[$key] = '';
1965
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1966
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1965
+			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD  biSize;
1966
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG   biWidth;
1967 1967
 			// The biHeight member specifies the combined
1968 1968
 			// height of the XOR and AND masks.
1969 1969
 			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1970
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1971
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1972
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1973
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1974
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1975
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1976
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1977
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1970
+			$BitmapInfoHeader[$key] .= "\x01\x00"; // WORD   biPlanes;
1971
+			$BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount;
1972
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biCompression;
1973
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD  biSizeImage;
1974
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biXPelsPerMeter;
1975
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biYPelsPerMeter;
1976
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrUsed;
1977
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrImportant;
1978 1978
 		}
1979 1979
 
1980 1980
 
1981
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1982
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1983
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1981
+		$icondata = "\x00\x00"; // idReserved;   // Reserved (must be 0)
1982
+		$icondata .= "\x01\x00"; // idType;	   // Resource Type (1 for icons)
1983
+		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount;	  // How many images?
1984 1984
 
1985 1985
 		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1986 1986
 		foreach ($gd_image_array as $key => $gd_image) {
1987 1987
 			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1988 1988
 
1989
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1990
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1991
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1992
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1989
+			$icondata .= chr($ImageWidths[$key]); // bWidth;		  // Width, in pixels, of the image
1990
+			$icondata .= chr($ImageHeights[$key]); // bHeight;		 // Height, in pixels, of the image
1991
+			$icondata .= chr($totalcolors[$key]); // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1992
+			$icondata .= "\x00"; // bReserved;	   // Reserved ( must be 0)
1993 1993
 
1994
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1995
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1994
+			$icondata .= "\x01\x00"; // wPlanes;		 // Color Planes
1995
+			$icondata .= chr($bpp[$key])."\x00"; // wBitCount;	   // Bits per pixel
1996 1996
 
1997 1997
 			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1998 1998
 			$icondata .= phpthumb_functions::LittleEndian2String(
1999 1999
 				$dwBytesInRes,
2000 2000
 				4
2001
-			);     // dwBytesInRes;	// How many bytes in this resource?
2001
+			); // dwBytesInRes;	// How many bytes in this resource?
2002 2002
 
2003 2003
 			$icondata .= phpthumb_functions::LittleEndian2String(
2004 2004
 				$dwImageOffset,
2005 2005
 				4
2006
-			);    // dwImageOffset;   // Where in the file is this image?
2006
+			); // dwImageOffset;   // Where in the file is this image?
2007 2007
 			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
2008 2008
 			$dwImageOffset += strlen($icXOR[$key]);
2009 2009
 			$dwImageOffset += strlen($icAND[$key]);
Please login to merge, or discard this patch.
ecrire/inc/urls.php 1 patch
Indentation   +165 added lines, -165 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('base/objets');
23 23
 
@@ -57,116 +57,116 @@  discard block
 block discarded – undo
57 57
  *
58 58
  */
59 59
 function urls_decoder_url($url, $fond = '', $contexte = [], $assembler = false) {
60
-	static $current_base = null;
60
+    static $current_base = null;
61 61
 
62
-	// les anciennes fonctions modifient directement les globales
63
-	// on les sauve avant l'appel, et on les retablit apres !
64
-	$save = [
65
-		isset($GLOBALS['fond']) ? $GLOBALS['fond'] : null,
66
-		isset($GLOBALS['contexte']) ? $GLOBALS['contexte'] : null,
67
-		isset($_SERVER['REDIRECT_url_propre']) ? $_SERVER['REDIRECT_url_propre'] : null,
68
-		isset($_ENV['url_propre']) ? $_ENV['url_propre'] : null,
69
-		$GLOBALS['profondeur_url']
70
-	];
62
+    // les anciennes fonctions modifient directement les globales
63
+    // on les sauve avant l'appel, et on les retablit apres !
64
+    $save = [
65
+        isset($GLOBALS['fond']) ? $GLOBALS['fond'] : null,
66
+        isset($GLOBALS['contexte']) ? $GLOBALS['contexte'] : null,
67
+        isset($_SERVER['REDIRECT_url_propre']) ? $_SERVER['REDIRECT_url_propre'] : null,
68
+        isset($_ENV['url_propre']) ? $_ENV['url_propre'] : null,
69
+        $GLOBALS['profondeur_url']
70
+    ];
71 71
 
72
-	if (is_null($current_base)) {
73
-		include_spip('inc/filtres_mini');
74
-		// le decodage des urls se fait toujours par rapport au site public
75
-		$current_base = url_absolue(_DIR_RACINE ? _DIR_RACINE : './');
76
-	}
77
-	if (strncmp($url, $current_base, strlen($current_base)) == 0) {
78
-		$url = substr($url, strlen($current_base));
79
-	}
72
+    if (is_null($current_base)) {
73
+        include_spip('inc/filtres_mini');
74
+        // le decodage des urls se fait toujours par rapport au site public
75
+        $current_base = url_absolue(_DIR_RACINE ? _DIR_RACINE : './');
76
+    }
77
+    if (strncmp($url, $current_base, strlen($current_base)) == 0) {
78
+        $url = substr($url, strlen($current_base));
79
+    }
80 80
 
81
-	// si on est en train d'assembler la page principale,
82
-	// recuperer l'url depuis les globales url propres si fournies
83
-	// sinon extraire la bonne portion d'url
84
-	if ($assembler) {
85
-		if (isset($_SERVER['REDIRECT_url_propre'])) {
86
-			$url = $_SERVER['REDIRECT_url_propre'];
87
-		} elseif (isset($_ENV['url_propre'])) {
88
-			$url = $_ENV['url_propre'];
89
-		} else {
90
-			$qs = explode('?', $url);
91
-			// ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee
92
-			$url = ltrim($qs[0], '/');
93
-			$url = explode('/', $url);
94
-			while (count($url) > $GLOBALS['profondeur_url'] + 1) {
95
-				array_shift($url);
96
-			}
97
-			$qs[0] = implode('/', $url);
98
-			$url = implode('?', $qs);
99
-		}
100
-	}
81
+    // si on est en train d'assembler la page principale,
82
+    // recuperer l'url depuis les globales url propres si fournies
83
+    // sinon extraire la bonne portion d'url
84
+    if ($assembler) {
85
+        if (isset($_SERVER['REDIRECT_url_propre'])) {
86
+            $url = $_SERVER['REDIRECT_url_propre'];
87
+        } elseif (isset($_ENV['url_propre'])) {
88
+            $url = $_ENV['url_propre'];
89
+        } else {
90
+            $qs = explode('?', $url);
91
+            // ne prendre que le segment d'url qui correspond, en fonction de la profondeur calculee
92
+            $url = ltrim($qs[0], '/');
93
+            $url = explode('/', $url);
94
+            while (count($url) > $GLOBALS['profondeur_url'] + 1) {
95
+                array_shift($url);
96
+            }
97
+            $qs[0] = implode('/', $url);
98
+            $url = implode('?', $qs);
99
+        }
100
+    }
101 101
 
102
-	unset($_SERVER['REDIRECT_url_propre']);
103
-	unset($_ENV['url_propre']);
104
-	include_spip('inc/filtres_mini');
105
-	if (strpos($url, '://') === false) {
106
-		$GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/');
107
-	} else {
108
-		$GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/'));
109
-	}
102
+    unset($_SERVER['REDIRECT_url_propre']);
103
+    unset($_ENV['url_propre']);
104
+    include_spip('inc/filtres_mini');
105
+    if (strpos($url, '://') === false) {
106
+        $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/');
107
+    } else {
108
+        $GLOBALS['profondeur_url'] = max(0, substr_count($url, '/') - substr_count($current_base, '/'));
109
+    }
110 110
 
111
-	$url_redirect = '';
112
-	$renommer = generer_url_entite('', '', '', '', true);
113
-	if (!$renommer and !function_exists('recuperer_parametres_url')) {
114
-		$renommer = charger_fonction('page', 'urls');
115
-	} // fallback pour decoder l'url
116
-	if ($renommer) {
117
-		$a = $renommer($url, $fond, $contexte);
118
-		if (is_array($a)) {
119
-			list($ncontexte, $type, $url_redirect, $nfond) = array_pad($a, 4, null);
120
-			$url_redirect ??= '';
121
-			if ($url_redirect === $url) {
122
-				$url_redirect = '';
123
-			} // securite pour eviter une redirection infinie
124
-			if ($assembler and strlen($url_redirect)) {
125
-				spip_log("Redirige $url vers $url_redirect");
126
-				include_spip('inc/headers');
127
-				redirige_par_entete($url_redirect, '', 301);
128
-			}
129
-			if (isset($nfond)) {
130
-				$fond = $nfond;
131
-			} else {
132
-				if (
133
-					$fond == ''
134
-					or $fond == 'type_urls' /* compat avec htaccess 2.0.0 */
135
-				) {
136
-					$fond = $type;
137
-				}
138
-			}
139
-			if (isset($ncontexte)) {
140
-				$contexte = $ncontexte;
141
-			}
142
-			if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
143
-				$contexte['type'] = $type;
144
-			}
145
-			if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
146
-				$contexte['type-page'] = $type;
147
-			}
148
-		}
149
-	} // compatibilite <= 1.9.2
150
-	elseif (function_exists('recuperer_parametres_url')) {
151
-		$GLOBALS['fond'] = $fond;
152
-		$GLOBALS['contexte'] = $contexte;
153
-		recuperer_parametres_url($fond, nettoyer_uri());
154
-		// fond est en principe modifiee directement
155
-		$contexte = $GLOBALS['contexte'];
156
-	}
111
+    $url_redirect = '';
112
+    $renommer = generer_url_entite('', '', '', '', true);
113
+    if (!$renommer and !function_exists('recuperer_parametres_url')) {
114
+        $renommer = charger_fonction('page', 'urls');
115
+    } // fallback pour decoder l'url
116
+    if ($renommer) {
117
+        $a = $renommer($url, $fond, $contexte);
118
+        if (is_array($a)) {
119
+            list($ncontexte, $type, $url_redirect, $nfond) = array_pad($a, 4, null);
120
+            $url_redirect ??= '';
121
+            if ($url_redirect === $url) {
122
+                $url_redirect = '';
123
+            } // securite pour eviter une redirection infinie
124
+            if ($assembler and strlen($url_redirect)) {
125
+                spip_log("Redirige $url vers $url_redirect");
126
+                include_spip('inc/headers');
127
+                redirige_par_entete($url_redirect, '', 301);
128
+            }
129
+            if (isset($nfond)) {
130
+                $fond = $nfond;
131
+            } else {
132
+                if (
133
+                    $fond == ''
134
+                    or $fond == 'type_urls' /* compat avec htaccess 2.0.0 */
135
+                ) {
136
+                    $fond = $type;
137
+                }
138
+            }
139
+            if (isset($ncontexte)) {
140
+                $contexte = $ncontexte;
141
+            }
142
+            if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
143
+                $contexte['type'] = $type;
144
+            }
145
+            if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
146
+                $contexte['type-page'] = $type;
147
+            }
148
+        }
149
+    } // compatibilite <= 1.9.2
150
+    elseif (function_exists('recuperer_parametres_url')) {
151
+        $GLOBALS['fond'] = $fond;
152
+        $GLOBALS['contexte'] = $contexte;
153
+        recuperer_parametres_url($fond, nettoyer_uri());
154
+        // fond est en principe modifiee directement
155
+        $contexte = $GLOBALS['contexte'];
156
+    }
157 157
 
158
-	// retablir les globales
159
-	list($GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']) = $save;
158
+    // retablir les globales
159
+    list($GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']) = $save;
160 160
 
161
-	// vider les globales url propres qui ne doivent plus etre utilisees en cas
162
-	// d'inversion url => objet
163
-	// maintenir pour compat ?
164
-	#if ($assembler) {
165
-	#	unset($_SERVER['REDIRECT_url_propre']);
166
-	#	unset($_ENV['url_propre']);
167
-	#}
161
+    // vider les globales url propres qui ne doivent plus etre utilisees en cas
162
+    // d'inversion url => objet
163
+    // maintenir pour compat ?
164
+    #if ($assembler) {
165
+    #	unset($_SERVER['REDIRECT_url_propre']);
166
+    #	unset($_ENV['url_propre']);
167
+    #}
168 168
 
169
-	return [$fond, $contexte, $url_redirect];
169
+    return [$fond, $contexte, $url_redirect];
170 170
 }
171 171
 
172 172
 
@@ -180,24 +180,24 @@  discard block
 block discarded – undo
180 180
  * @return string|array
181 181
  */
182 182
 function urls_liste_objets($preg = true) {
183
-	static $url_objets = null;
184
-	if (is_null($url_objets)) {
185
-		$url_objets = [];
186
-		// recuperer les tables_objets_sql declarees
187
-		$tables_objets = lister_tables_objets_sql();
188
-		foreach ($tables_objets as $t => $infos) {
189
-			if ($infos['page']) {
190
-				$url_objets[] = $infos['type'];
191
-				$url_objets = array_merge($url_objets, $infos['type_surnoms']);
192
-			}
193
-		}
194
-		$url_objets = pipeline('declarer_url_objets', $url_objets);
195
-	}
196
-	if (!$preg) {
197
-		return $url_objets;
198
-	}
183
+    static $url_objets = null;
184
+    if (is_null($url_objets)) {
185
+        $url_objets = [];
186
+        // recuperer les tables_objets_sql declarees
187
+        $tables_objets = lister_tables_objets_sql();
188
+        foreach ($tables_objets as $t => $infos) {
189
+            if ($infos['page']) {
190
+                $url_objets[] = $infos['type'];
191
+                $url_objets = array_merge($url_objets, $infos['type_surnoms']);
192
+            }
193
+        }
194
+        $url_objets = pipeline('declarer_url_objets', $url_objets);
195
+    }
196
+    if (!$preg) {
197
+        return $url_objets;
198
+    }
199 199
 
200
-	return implode('|', array_map('preg_quote', $url_objets));
200
+    return implode('|', array_map('preg_quote', $url_objets));
201 201
 }
202 202
 
203 203
 /**
@@ -211,26 +211,26 @@  discard block
 block discarded – undo
211 211
  * @return array
212 212
  */
213 213
 function nettoyer_url_page($url, $contexte = []) {
214
-	$url_objets = urls_liste_objets();
215
-	$raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,';
216
-	$raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
217
-	$raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,';
214
+    $url_objets = urls_liste_objets();
215
+    $raccourci_url_page_html = ',^(?:[^?]*/)?(' . $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,';
216
+    $raccourci_url_page_id = ',^(?:[^?]*/)?(' . $url_objets . ')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
217
+    $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?](' . $url_objets . ')([0-9]+)=?(&.*)?$,';
218 218
 
219
-	if (
220
-		preg_match($raccourci_url_page_html, $url, $regs)
221
-		or preg_match($raccourci_url_page_id, $url, $regs)
222
-		or preg_match($raccourci_url_page_spip, $url, $regs)
223
-	) {
224
-		$regs = array_pad($regs, 4, null);
225
-		$type = objet_type($regs[1]);
226
-		$_id = id_table_objet($type);
227
-		$contexte[$_id] = $regs[2];
228
-		$suite = $regs[3];
219
+    if (
220
+        preg_match($raccourci_url_page_html, $url, $regs)
221
+        or preg_match($raccourci_url_page_id, $url, $regs)
222
+        or preg_match($raccourci_url_page_spip, $url, $regs)
223
+    ) {
224
+        $regs = array_pad($regs, 4, null);
225
+        $type = objet_type($regs[1]);
226
+        $_id = id_table_objet($type);
227
+        $contexte[$_id] = $regs[2];
228
+        $suite = $regs[3];
229 229
 
230
-		return [$contexte, $type, null, $type, $suite];
231
-	}
230
+        return [$contexte, $type, null, $type, $suite];
231
+    }
232 232
 
233
-	return [];
233
+    return [];
234 234
 }
235 235
 
236 236
 /**
@@ -249,33 +249,33 @@  discard block
 block discarded – undo
249 249
  *
250 250
  */
251 251
 function generer_url_ecrire_objet($objet, $id, $args = '', $ancre = '', $public = null, string $connect = '') {
252
-	static $furls = [];
253
-	if (!isset($furls[$objet])) {
254
-		if (
255
-			function_exists($f = 'generer_url_ecrire_' . $objet)
256
-			// ou definie par un plugin
257
-			or $f = charger_fonction($f, 'urls', true)
258
-		) {
259
-			$furls[$objet] = $f;
260
-		} else {
261
-			$furls[$objet] = '';
262
-		}
263
-	}
264
-	if ($furls[$objet]) {
265
-		return $furls[$objet]($id, $args, $ancre, $public, $connect);
266
-	}
267
-	// si pas de flag public fourni
268
-	// le calculer en fonction de la declaration de statut
269
-	if (is_null($public) and !$connect) {
270
-		$public = objet_test_si_publie($objet, $id, $connect);
271
-	}
272
-	if ($public or $connect) {
273
-		return generer_url_entite_absolue($id, $objet, $args, $ancre, $connect);
274
-	}
275
-	$a = id_table_objet($objet) . '=' . intval($id);
276
-	if (!function_exists('objet_info')) {
277
-		include_spip('inc/filtres');
278
-	}
252
+    static $furls = [];
253
+    if (!isset($furls[$objet])) {
254
+        if (
255
+            function_exists($f = 'generer_url_ecrire_' . $objet)
256
+            // ou definie par un plugin
257
+            or $f = charger_fonction($f, 'urls', true)
258
+        ) {
259
+            $furls[$objet] = $f;
260
+        } else {
261
+            $furls[$objet] = '';
262
+        }
263
+    }
264
+    if ($furls[$objet]) {
265
+        return $furls[$objet]($id, $args, $ancre, $public, $connect);
266
+    }
267
+    // si pas de flag public fourni
268
+    // le calculer en fonction de la declaration de statut
269
+    if (is_null($public) and !$connect) {
270
+        $public = objet_test_si_publie($objet, $id, $connect);
271
+    }
272
+    if ($public or $connect) {
273
+        return generer_url_entite_absolue($id, $objet, $args, $ancre, $connect);
274
+    }
275
+    $a = id_table_objet($objet) . '=' . intval($id);
276
+    if (!function_exists('objet_info')) {
277
+        include_spip('inc/filtres');
278
+    }
279 279
 
280
-	return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : '');
280
+    return generer_url_ecrire(objet_info($objet, 'url_voir'), $a . ($args ? "&$args" : '')) . ($ancre ? "#$ancre" : '');
281 281
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres_images_mini.php 1 patch
Indentation   +316 added lines, -316 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  */
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 include_spip('inc/filtres_images_lib_mini'); // par precaution
24 24
 
@@ -31,161 +31,161 @@  discard block
 block discarded – undo
31 31
  *    Le code hexadécimal de la couleur (sans le #) ou le code couleur textuel si non trouvé
32 32
  */
33 33
 function couleur_html_to_hex($couleur) {
34
-	$couleurs_html = [
35
-		'aliceblue' => 'F0F8FF',
36
-		'antiquewhite' => 'FAEBD7',
37
-		'aqua' => '00FFFF',
38
-		'aquamarine' => '7FFFD4',
39
-		'azure' => 'F0FFFF',
40
-		'beige' => 'F5F5DC',
41
-		'bisque' => 'FFE4C4',
42
-		'black' => '000000',
43
-		'blanchedalmond' => 'FFEBCD',
44
-		'blue' => '0000FF',
45
-		'blueviolet' => '8A2BE2',
46
-		'brown' => 'A52A2A',
47
-		'burlywood' => 'DEB887',
48
-		'cadetblue' => '5F9EA0',
49
-		'chartreuse' => '7FFF00',
50
-		'chocolate' => 'D2691E',
51
-		'coral' => 'FF7F50',
52
-		'cornflowerblue' => '6495ED',
53
-		'cornsilk' => 'FFF8DC',
54
-		'crimson' => 'DC143C',
55
-		'cyan' => '00FFFF',
56
-		'darkblue' => '00008B',
57
-		'darkcyan' => '008B8B',
58
-		'darkgoldenrod' => 'B8860B',
59
-		'darkgray' => 'A9A9A9',
60
-		'darkgreen' => '006400',
61
-		'darkgrey' => 'A9A9A9',
62
-		'darkkhaki' => 'BDB76B',
63
-		'darkmagenta' => '8B008B',
64
-		'darkolivegreen' => '556B2F',
65
-		'darkorange' => 'FF8C00',
66
-		'darkorchid' => '9932CC',
67
-		'darkred' => '8B0000',
68
-		'darksalmon' => 'E9967A',
69
-		'darkseagreen' => '8FBC8F',
70
-		'darkslateblue' => '483D8B',
71
-		'darkslategray' => '2F4F4F',
72
-		'darkslategrey' => '2F4F4F',
73
-		'darkturquoise' => '00CED1',
74
-		'darkviolet' => '9400D3',
75
-		'deeppink' => 'FF1493',
76
-		'deepskyblue' => '00BFFF',
77
-		'dimgray' => '696969',
78
-		'dimgrey' => '696969',
79
-		'dodgerblue' => '1E90FF',
80
-		'firebrick' => 'B22222',
81
-		'floralwhite' => 'FFFAF0',
82
-		'forestgreen' => '228B22',
83
-		'fuchsia' => 'FF00FF',
84
-		'gainsboro' => 'DCDCDC',
85
-		'ghostwhite' => 'F8F8FF',
86
-		'gold' => 'FFD700',
87
-		'goldenrod' => 'DAA520',
88
-		'gray' => '808080',
89
-		'green' => '008000',
90
-		'greenyellow' => 'ADFF2F',
91
-		'grey' => '808080',
92
-		'honeydew' => 'F0FFF0',
93
-		'hotpink' => 'FF69B4',
94
-		'indianred' => 'CD5C5C',
95
-		'indigo' => '4B0082',
96
-		'ivory' => 'FFFFF0',
97
-		'khaki' => 'F0E68C',
98
-		'lavender' => 'E6E6FA',
99
-		'lavenderblush' => 'FFF0F5',
100
-		'lawngreen' => '7CFC00',
101
-		'lemonchiffon' => 'FFFACD',
102
-		'lightblue' => 'ADD8E6',
103
-		'lightcoral' => 'F08080',
104
-		'lightcyan' => 'E0FFFF',
105
-		'lightgoldenrodyellow' => 'FAFAD2',
106
-		'lightgray' => 'D3D3D3',
107
-		'lightgreen' => '90EE90',
108
-		'lightgrey' => 'D3D3D3',
109
-		'lightpink' => 'FFB6C1',
110
-		'lightsalmon' => 'FFA07A',
111
-		'lightseagreen' => '20B2AA',
112
-		'lightskyblue' => '87CEFA',
113
-		'lightslategray' => '778899',
114
-		'lightslategrey' => '778899',
115
-		'lightsteelblue' => 'B0C4DE',
116
-		'lightyellow' => 'FFFFE0',
117
-		'lime' => '00FF00',
118
-		'limegreen' => '32CD32',
119
-		'linen' => 'FAF0E6',
120
-		'magenta' => 'FF00FF',
121
-		'maroon' => '800000',
122
-		'mediumaquamarine' => '66CDAA',
123
-		'mediumblue' => '0000CD',
124
-		'mediumorchid' => 'BA55D3',
125
-		'mediumpurple' => '9370DB',
126
-		'mediumseagreen' => '3CB371',
127
-		'mediumslateblue' => '7B68EE',
128
-		'mediumspringgreen' => '00FA9A',
129
-		'mediumturquoise' => '48D1CC',
130
-		'mediumvioletred' => 'C71585',
131
-		'midnightblue' => '191970',
132
-		'mintcream' => 'F5FFFA',
133
-		'mistyrose' => 'FFE4E1',
134
-		'moccasin' => 'FFE4B5',
135
-		'navajowhite' => 'FFDEAD',
136
-		'navy' => '000080',
137
-		'oldlace' => 'FDF5E6',
138
-		'olive' => '808000',
139
-		'olivedrab' => '6B8E23',
140
-		'orange' => 'FFA500',
141
-		'orangered' => 'FF4500',
142
-		'orchid' => 'DA70D6',
143
-		'palegoldenrod' => 'EEE8AA',
144
-		'palegreen' => '98FB98',
145
-		'paleturquoise' => 'AFEEEE',
146
-		'palevioletred' => 'DB7093',
147
-		'papayawhip' => 'FFEFD5',
148
-		'peachpuff' => 'FFDAB9',
149
-		'peru' => 'CD853F',
150
-		'pink' => 'FFC0CB',
151
-		'plum' => 'DDA0DD',
152
-		'powderblue' => 'B0E0E6',
153
-		'purple' => '800080',
154
-		'rebeccapurple' => '663399',
155
-		'red' => 'FF0000',
156
-		'rosybrown' => 'BC8F8F',
157
-		'royalblue' => '4169E1',
158
-		'saddlebrown' => '8B4513',
159
-		'salmon' => 'FA8072',
160
-		'sandybrown' => 'F4A460',
161
-		'seagreen' => '2E8B57',
162
-		'seashell' => 'FFF5EE',
163
-		'sienna' => 'A0522D',
164
-		'silver' => 'C0C0C0',
165
-		'skyblue' => '87CEEB',
166
-		'slateblue' => '6A5ACD',
167
-		'slategray' => '708090',
168
-		'slategrey' => '708090',
169
-		'snow' => 'FFFAFA',
170
-		'springgreen' => '00FF7F',
171
-		'steelblue' => '4682B4',
172
-		'tan' => 'D2B48C',
173
-		'teal' => '008080',
174
-		'thistle' => 'D8BFD8',
175
-		'tomato' => 'FF6347',
176
-		'turquoise' => '40E0D0',
177
-		'violet' => 'EE82EE',
178
-		'wheat' => 'F5DEB3',
179
-		'white' => 'FFFFFF',
180
-		'whitesmoke' => 'F5F5F5',
181
-		'yellow' => 'FFFF00',
182
-		'yellowgreen' => '9ACD32',
183
-	];
184
-	if (isset($couleurs_html[$lc = strtolower($couleur)])) {
185
-		return $couleurs_html[$lc];
186
-	}
187
-
188
-	return $couleur;
34
+    $couleurs_html = [
35
+        'aliceblue' => 'F0F8FF',
36
+        'antiquewhite' => 'FAEBD7',
37
+        'aqua' => '00FFFF',
38
+        'aquamarine' => '7FFFD4',
39
+        'azure' => 'F0FFFF',
40
+        'beige' => 'F5F5DC',
41
+        'bisque' => 'FFE4C4',
42
+        'black' => '000000',
43
+        'blanchedalmond' => 'FFEBCD',
44
+        'blue' => '0000FF',
45
+        'blueviolet' => '8A2BE2',
46
+        'brown' => 'A52A2A',
47
+        'burlywood' => 'DEB887',
48
+        'cadetblue' => '5F9EA0',
49
+        'chartreuse' => '7FFF00',
50
+        'chocolate' => 'D2691E',
51
+        'coral' => 'FF7F50',
52
+        'cornflowerblue' => '6495ED',
53
+        'cornsilk' => 'FFF8DC',
54
+        'crimson' => 'DC143C',
55
+        'cyan' => '00FFFF',
56
+        'darkblue' => '00008B',
57
+        'darkcyan' => '008B8B',
58
+        'darkgoldenrod' => 'B8860B',
59
+        'darkgray' => 'A9A9A9',
60
+        'darkgreen' => '006400',
61
+        'darkgrey' => 'A9A9A9',
62
+        'darkkhaki' => 'BDB76B',
63
+        'darkmagenta' => '8B008B',
64
+        'darkolivegreen' => '556B2F',
65
+        'darkorange' => 'FF8C00',
66
+        'darkorchid' => '9932CC',
67
+        'darkred' => '8B0000',
68
+        'darksalmon' => 'E9967A',
69
+        'darkseagreen' => '8FBC8F',
70
+        'darkslateblue' => '483D8B',
71
+        'darkslategray' => '2F4F4F',
72
+        'darkslategrey' => '2F4F4F',
73
+        'darkturquoise' => '00CED1',
74
+        'darkviolet' => '9400D3',
75
+        'deeppink' => 'FF1493',
76
+        'deepskyblue' => '00BFFF',
77
+        'dimgray' => '696969',
78
+        'dimgrey' => '696969',
79
+        'dodgerblue' => '1E90FF',
80
+        'firebrick' => 'B22222',
81
+        'floralwhite' => 'FFFAF0',
82
+        'forestgreen' => '228B22',
83
+        'fuchsia' => 'FF00FF',
84
+        'gainsboro' => 'DCDCDC',
85
+        'ghostwhite' => 'F8F8FF',
86
+        'gold' => 'FFD700',
87
+        'goldenrod' => 'DAA520',
88
+        'gray' => '808080',
89
+        'green' => '008000',
90
+        'greenyellow' => 'ADFF2F',
91
+        'grey' => '808080',
92
+        'honeydew' => 'F0FFF0',
93
+        'hotpink' => 'FF69B4',
94
+        'indianred' => 'CD5C5C',
95
+        'indigo' => '4B0082',
96
+        'ivory' => 'FFFFF0',
97
+        'khaki' => 'F0E68C',
98
+        'lavender' => 'E6E6FA',
99
+        'lavenderblush' => 'FFF0F5',
100
+        'lawngreen' => '7CFC00',
101
+        'lemonchiffon' => 'FFFACD',
102
+        'lightblue' => 'ADD8E6',
103
+        'lightcoral' => 'F08080',
104
+        'lightcyan' => 'E0FFFF',
105
+        'lightgoldenrodyellow' => 'FAFAD2',
106
+        'lightgray' => 'D3D3D3',
107
+        'lightgreen' => '90EE90',
108
+        'lightgrey' => 'D3D3D3',
109
+        'lightpink' => 'FFB6C1',
110
+        'lightsalmon' => 'FFA07A',
111
+        'lightseagreen' => '20B2AA',
112
+        'lightskyblue' => '87CEFA',
113
+        'lightslategray' => '778899',
114
+        'lightslategrey' => '778899',
115
+        'lightsteelblue' => 'B0C4DE',
116
+        'lightyellow' => 'FFFFE0',
117
+        'lime' => '00FF00',
118
+        'limegreen' => '32CD32',
119
+        'linen' => 'FAF0E6',
120
+        'magenta' => 'FF00FF',
121
+        'maroon' => '800000',
122
+        'mediumaquamarine' => '66CDAA',
123
+        'mediumblue' => '0000CD',
124
+        'mediumorchid' => 'BA55D3',
125
+        'mediumpurple' => '9370DB',
126
+        'mediumseagreen' => '3CB371',
127
+        'mediumslateblue' => '7B68EE',
128
+        'mediumspringgreen' => '00FA9A',
129
+        'mediumturquoise' => '48D1CC',
130
+        'mediumvioletred' => 'C71585',
131
+        'midnightblue' => '191970',
132
+        'mintcream' => 'F5FFFA',
133
+        'mistyrose' => 'FFE4E1',
134
+        'moccasin' => 'FFE4B5',
135
+        'navajowhite' => 'FFDEAD',
136
+        'navy' => '000080',
137
+        'oldlace' => 'FDF5E6',
138
+        'olive' => '808000',
139
+        'olivedrab' => '6B8E23',
140
+        'orange' => 'FFA500',
141
+        'orangered' => 'FF4500',
142
+        'orchid' => 'DA70D6',
143
+        'palegoldenrod' => 'EEE8AA',
144
+        'palegreen' => '98FB98',
145
+        'paleturquoise' => 'AFEEEE',
146
+        'palevioletred' => 'DB7093',
147
+        'papayawhip' => 'FFEFD5',
148
+        'peachpuff' => 'FFDAB9',
149
+        'peru' => 'CD853F',
150
+        'pink' => 'FFC0CB',
151
+        'plum' => 'DDA0DD',
152
+        'powderblue' => 'B0E0E6',
153
+        'purple' => '800080',
154
+        'rebeccapurple' => '663399',
155
+        'red' => 'FF0000',
156
+        'rosybrown' => 'BC8F8F',
157
+        'royalblue' => '4169E1',
158
+        'saddlebrown' => '8B4513',
159
+        'salmon' => 'FA8072',
160
+        'sandybrown' => 'F4A460',
161
+        'seagreen' => '2E8B57',
162
+        'seashell' => 'FFF5EE',
163
+        'sienna' => 'A0522D',
164
+        'silver' => 'C0C0C0',
165
+        'skyblue' => '87CEEB',
166
+        'slateblue' => '6A5ACD',
167
+        'slategray' => '708090',
168
+        'slategrey' => '708090',
169
+        'snow' => 'FFFAFA',
170
+        'springgreen' => '00FF7F',
171
+        'steelblue' => '4682B4',
172
+        'tan' => 'D2B48C',
173
+        'teal' => '008080',
174
+        'thistle' => 'D8BFD8',
175
+        'tomato' => 'FF6347',
176
+        'turquoise' => '40E0D0',
177
+        'violet' => 'EE82EE',
178
+        'wheat' => 'F5DEB3',
179
+        'white' => 'FFFFFF',
180
+        'whitesmoke' => 'F5F5F5',
181
+        'yellow' => 'FFFF00',
182
+        'yellowgreen' => '9ACD32',
183
+    ];
184
+    if (isset($couleurs_html[$lc = strtolower($couleur)])) {
185
+        return $couleurs_html[$lc];
186
+    }
187
+
188
+    return $couleur;
189 189
 }
190 190
 
191 191
 /**
@@ -201,16 +201,16 @@  discard block
 block discarded – undo
201 201
  * @return string Couleur tel que "hsl(200, 40%, 34%)" ou valeur formattée
202 202
  */
203 203
 function couleur_hex_to_hsl($couleur, $format = null) {
204
-	$hsl = _couleur_hex_to_hsl($couleur);
205
-	$hsl = [
206
-		'h' => round($hsl['h'] * 360),
207
-		's' => round($hsl['s'] * 100) . '%',
208
-		'l' => round($hsl['l'] * 100) . '%'
209
-	];
210
-	if ($format === null) {
211
-		return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})";
212
-	}
213
-	return str_replace(array_keys($hsl), $hsl, $format);
204
+    $hsl = _couleur_hex_to_hsl($couleur);
205
+    $hsl = [
206
+        'h' => round($hsl['h'] * 360),
207
+        's' => round($hsl['s'] * 100) . '%',
208
+        'l' => round($hsl['l'] * 100) . '%'
209
+    ];
210
+    if ($format === null) {
211
+        return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})";
212
+    }
213
+    return str_replace(array_keys($hsl), $hsl, $format);
214 214
 }
215 215
 
216 216
 
@@ -227,16 +227,16 @@  discard block
 block discarded – undo
227 227
  * @return string Couleur tel que "rgb(200, 40, 84)" ou valeur formattée
228 228
  */
229 229
 function couleur_hex_to_rgb($couleur, $format = null) {
230
-	$rgb = _couleur_hex_to_dec($couleur);
231
-	$rgb = [
232
-		'r' => $rgb['red'],
233
-		'g' => $rgb['green'],
234
-		'b' => $rgb['blue'],
235
-	];
236
-	if ($format === null) {
237
-		return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})";
238
-	}
239
-	return str_replace(array_keys($rgb), $rgb, $format);
230
+    $rgb = _couleur_hex_to_dec($couleur);
231
+    $rgb = [
232
+        'r' => $rgb['red'],
233
+        'g' => $rgb['green'],
234
+        'b' => $rgb['blue'],
235
+    ];
236
+    if ($format === null) {
237
+        return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})";
238
+    }
239
+    return str_replace(array_keys($rgb), $rgb, $format);
240 240
 }
241 241
 
242 242
 /**
@@ -252,15 +252,15 @@  discard block
 block discarded – undo
252 252
  *    Code hexadécimal de la couleur plus foncée
253 253
  */
254 254
 function couleur_foncer($couleur, $coeff = 0.5) {
255
-	$couleurs = _couleur_hex_to_dec($couleur);
255
+    $couleurs = _couleur_hex_to_dec($couleur);
256 256
 
257
-	$red = $couleurs['red'] - round(($couleurs['red']) * $coeff);
258
-	$green = $couleurs['green'] - round(($couleurs['green']) * $coeff);
259
-	$blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff);
257
+    $red = $couleurs['red'] - round(($couleurs['red']) * $coeff);
258
+    $green = $couleurs['green'] - round(($couleurs['green']) * $coeff);
259
+    $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff);
260 260
 
261
-	$couleur = _couleur_dec_to_hex($red, $green, $blue);
261
+    $couleur = _couleur_dec_to_hex($red, $green, $blue);
262 262
 
263
-	return $couleur;
263
+    return $couleur;
264 264
 }
265 265
 
266 266
 /**
@@ -276,15 +276,15 @@  discard block
 block discarded – undo
276 276
  *    Code hexadécimal de la couleur éclaircie
277 277
  */
278 278
 function couleur_eclaircir($couleur, $coeff = 0.5) {
279
-	$couleurs = _couleur_hex_to_dec($couleur);
279
+    $couleurs = _couleur_hex_to_dec($couleur);
280 280
 
281
-	$red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff);
282
-	$green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff);
283
-	$blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff);
281
+    $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff);
282
+    $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff);
283
+    $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff);
284 284
 
285
-	$couleur = _couleur_dec_to_hex($red, $green, $blue);
285
+    $couleur = _couleur_dec_to_hex($red, $green, $blue);
286 286
 
287
-	return $couleur;
287
+    return $couleur;
288 288
 }
289 289
 
290 290
 /**
@@ -307,28 +307,28 @@  discard block
 block discarded – undo
307 307
  *    Le tag html `<img src=... />` avec une class `filtre_inactif` ou pas
308 308
  */
309 309
 function image_select($img, $width_min = 0, $height_min = 0, $width_max = 10000, $height_max = 1000) {
310
-	if (!$img) {
311
-		return $img;
312
-	}
313
-	list($h, $l) = taille_image($img);
314
-	$select = true;
315
-	if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) {
316
-		$select = false;
317
-	}
318
-
319
-	$class = extraire_attribut($img, 'class');
320
-	$p = strpos($class, 'filtre_inactif');
321
-	if (($select == false) and ($p === false)) {
322
-		$class .= ' filtre_inactif';
323
-		$img = inserer_attribut($img, 'class', $class);
324
-	}
325
-	if (($select == true) and ($p !== false)) {
326
-		// no_image_filtrer : historique, a virer
327
-		$class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class);
328
-		$img = inserer_attribut($img, 'class', $class);
329
-	}
330
-
331
-	return $img;
310
+    if (!$img) {
311
+        return $img;
312
+    }
313
+    list($h, $l) = taille_image($img);
314
+    $select = true;
315
+    if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) {
316
+        $select = false;
317
+    }
318
+
319
+    $class = extraire_attribut($img, 'class');
320
+    $p = strpos($class, 'filtre_inactif');
321
+    if (($select == false) and ($p === false)) {
322
+        $class .= ' filtre_inactif';
323
+        $img = inserer_attribut($img, 'class', $class);
324
+    }
325
+    if (($select == true) and ($p !== false)) {
326
+        // no_image_filtrer : historique, a virer
327
+        $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class);
328
+        $img = inserer_attribut($img, 'class', $class);
329
+    }
330
+
331
+    return $img;
332 332
 }
333 333
 
334 334
 /**
@@ -376,45 +376,45 @@  discard block
 block discarded – undo
376 376
  *     Code HTML de l'image ou du texte.
377 377
  **/
378 378
 function image_passe_partout(
379
-	$img,
380
-	$taille_x = -1,
381
-	$taille_y = -1,
382
-	$force = false,
383
-	$cherche_image = false,
384
-	$process = 'AUTO'
379
+    $img,
380
+    $taille_x = -1,
381
+    $taille_y = -1,
382
+    $force = false,
383
+    $cherche_image = false,
384
+    $process = 'AUTO'
385 385
 ) {
386
-	// PHP 7+ type hint
387
-	$img = (string)$img;
388
-	$taille_x = (int)$taille_x;
389
-	$taille_y = (int)$taille_y;
390
-	$force = (bool)$force;
391
-	$process = (string)$process;
392
-
393
-	if (!$img) {
394
-		return '';
395
-	}
396
-	list($hauteur, $largeur) = taille_image($img);
397
-	if ($taille_x === -1) {
398
-		$taille_x = $GLOBALS['meta']['taille_preview'] ?? 150;
399
-	}
400
-	if ($taille_y === -1) {
401
-		$taille_y = $taille_x;
402
-	}
403
-
404
-	if ($taille_x === 0 and $taille_y > 0) {
405
-		$taille_x = 1;
406
-	} # {0,300} -> c'est 300 qui compte
407
-	elseif ($taille_x > 0 and $taille_y === 0) {
408
-		$taille_y = 1;
409
-	} # {300,0} -> c'est 300 qui compte
410
-	elseif ($taille_x == 0 and $taille_y === 0) {
411
-		return '';
412
-	}
413
-
414
-	list($destWidth, $destHeight, $ratio) = ratio_passe_partout($largeur ?? 0, $hauteur ?? 0, $taille_x, $taille_y);
415
-	$fonction = ['image_passe_partout', func_get_args()];
416
-
417
-	return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process);
386
+    // PHP 7+ type hint
387
+    $img = (string)$img;
388
+    $taille_x = (int)$taille_x;
389
+    $taille_y = (int)$taille_y;
390
+    $force = (bool)$force;
391
+    $process = (string)$process;
392
+
393
+    if (!$img) {
394
+        return '';
395
+    }
396
+    list($hauteur, $largeur) = taille_image($img);
397
+    if ($taille_x === -1) {
398
+        $taille_x = $GLOBALS['meta']['taille_preview'] ?? 150;
399
+    }
400
+    if ($taille_y === -1) {
401
+        $taille_y = $taille_x;
402
+    }
403
+
404
+    if ($taille_x === 0 and $taille_y > 0) {
405
+        $taille_x = 1;
406
+    } # {0,300} -> c'est 300 qui compte
407
+    elseif ($taille_x > 0 and $taille_y === 0) {
408
+        $taille_y = 1;
409
+    } # {300,0} -> c'est 300 qui compte
410
+    elseif ($taille_x == 0 and $taille_y === 0) {
411
+        return '';
412
+    }
413
+
414
+    list($destWidth, $destHeight, $ratio) = ratio_passe_partout($largeur ?? 0, $hauteur ?? 0, $taille_x, $taille_y);
415
+    $fonction = ['image_passe_partout', func_get_args()];
416
+
417
+    return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process);
418 418
 }
419 419
 
420 420
 /**
@@ -457,44 +457,44 @@  discard block
 block discarded – undo
457 457
  *     Code HTML de l'image ou du texte.
458 458
  **/
459 459
 function image_reduire(
460
-	$img,
461
-	$taille = -1,
462
-	$taille_y = -1,
463
-	$force = false,
464
-	$cherche_image = false,
465
-	$process = 'AUTO'
460
+    $img,
461
+    $taille = -1,
462
+    $taille_y = -1,
463
+    $force = false,
464
+    $cherche_image = false,
465
+    $process = 'AUTO'
466 466
 ) {
467
-	// PHP 7+ type hint
468
-	$img = (string)$img;
469
-	$taille = (int)$taille;
470
-	$taille_y = (int)$taille_y;
471
-	$force = (bool)$force;
472
-	$process = (string)$process;
473
-
474
-	// Determiner la taille x,y maxi
475
-	// prendre le reglage de previsu par defaut
476
-	if ($taille === -1) {
477
-		$taille = (isset($GLOBALS['meta']['taille_preview']) and intval($GLOBALS['meta']['taille_preview']))
478
-			? intval($GLOBALS['meta']['taille_preview'])
479
-			: 150;
480
-	}
481
-	if ($taille_y === -1) {
482
-		$taille_y = $taille;
483
-	}
484
-
485
-	if ($taille === 0 and $taille_y > 0) {
486
-		$taille = 10000;
487
-	} # {0,300} -> c'est 300 qui compte
488
-	elseif ($taille > 0 and $taille_y === 0) {
489
-		$taille_y = 10000;
490
-	} # {300,0} -> c'est 300 qui compte
491
-	elseif ($taille == 0 and $taille_y === 0) {
492
-		return '';
493
-	}
494
-
495
-	$fonction = ['image_reduire', func_get_args()];
496
-
497
-	return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process);
467
+    // PHP 7+ type hint
468
+    $img = (string)$img;
469
+    $taille = (int)$taille;
470
+    $taille_y = (int)$taille_y;
471
+    $force = (bool)$force;
472
+    $process = (string)$process;
473
+
474
+    // Determiner la taille x,y maxi
475
+    // prendre le reglage de previsu par defaut
476
+    if ($taille === -1) {
477
+        $taille = (isset($GLOBALS['meta']['taille_preview']) and intval($GLOBALS['meta']['taille_preview']))
478
+            ? intval($GLOBALS['meta']['taille_preview'])
479
+            : 150;
480
+    }
481
+    if ($taille_y === -1) {
482
+        $taille_y = $taille;
483
+    }
484
+
485
+    if ($taille === 0 and $taille_y > 0) {
486
+        $taille = 10000;
487
+    } # {0,300} -> c'est 300 qui compte
488
+    elseif ($taille > 0 and $taille_y === 0) {
489
+        $taille_y = 10000;
490
+    } # {300,0} -> c'est 300 qui compte
491
+    elseif ($taille == 0 and $taille_y === 0) {
492
+        return '';
493
+    }
494
+
495
+    $fonction = ['image_reduire', func_get_args()];
496
+
497
+    return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process);
498 498
 }
499 499
 
500 500
 /**
@@ -505,16 +505,16 @@  discard block
 block discarded – undo
505 505
  *
506 506
  **/
507 507
 function image_recadre_avec_fallback(
508
-	$im,
509
-	$width,
510
-	$height = '-',
511
-	$position = 'focus',
512
-	$background_color = 'white'
508
+    $im,
509
+    $width,
510
+    $height = '-',
511
+    $position = 'focus',
512
+    $background_color = 'white'
513 513
 ) {
514
-	if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') {
515
-		return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height);
516
-	} else { return image_passe_partout($im, $width, $height);
517
-	}
514
+    if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') {
515
+        return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height);
516
+    } else { return image_passe_partout($im, $width, $height);
517
+    }
518 518
 }
519 519
 
520 520
 /**
@@ -532,25 +532,25 @@  discard block
 block discarded – undo
532 532
  *     Code HTML de l'image ou du texte.
533 533
  **/
534 534
 function image_reduire_par($img, $val = 1, $force = false) {
535
-	// PHP 7+ type hint
536
-	$img = (string)$img;
537
-	$val = (int)$val;
538
-	$force = (bool)$force;
535
+    // PHP 7+ type hint
536
+    $img = (string)$img;
537
+    $val = (int)$val;
538
+    $force = (bool)$force;
539 539
 
540
-	list($hauteur, $largeur) = taille_image($img);
540
+    list($hauteur, $largeur) = taille_image($img);
541 541
 
542
-	$l = round($largeur / $val);
543
-	$h = round($hauteur / $val);
542
+    $l = round($largeur / $val);
543
+    $h = round($hauteur / $val);
544 544
 
545
-	if ($l > $h) {
546
-		$h = 0;
547
-	} else {
548
-		$l = 0;
549
-	}
545
+    if ($l > $h) {
546
+        $h = 0;
547
+    } else {
548
+        $l = 0;
549
+    }
550 550
 
551
-	$img = image_reduire($img, $l, $h, $force);
551
+    $img = image_reduire($img, $l, $h, $force);
552 552
 
553
-	return $img;
553
+    return $img;
554 554
 }
555 555
 
556 556
 /**
@@ -573,10 +573,10 @@  discard block
 block discarded – undo
573 573
  *      Couleur en écriture hexadécimale.
574 574
 **/
575 575
 function filtre_couleur_saturation_dist($couleur, $val, $strict = false) {
576
-	if (function_exists('couleur_saturation')) {
577
-		return couleur_saturation($couleur, $val, $strict);
578
-	}
579
-	return $couleur;
576
+    if (function_exists('couleur_saturation')) {
577
+        return couleur_saturation($couleur, $val, $strict);
578
+    }
579
+    return $couleur;
580 580
 }
581 581
 
582 582
 /**
@@ -597,8 +597,8 @@  discard block
 block discarded – undo
597 597
  *      Couleur en écriture hexadécimale.
598 598
 **/
599 599
 function filtre_couleur_luminance_dist($couleur, $val) {
600
-	if (function_exists('couleur_luminance')) {
601
-		return couleur_luminance($couleur, $val);
602
-	}
603
-	return $couleur;
600
+    if (function_exists('couleur_luminance')) {
601
+        return couleur_luminance($couleur, $val);
602
+    }
603
+    return $couleur;
604 604
 }
Please login to merge, or discard this patch.
ecrire/inc/pipelines_ecrire.php 1 patch
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Pipelines
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 
@@ -36,37 +36,37 @@  discard block
 block discarded – undo
36 36
  * @return string          Contenu complété des scripts javascripts, dont jQuery
37 37
  **/
38 38
 function f_jQuery_prive($texte) {
39
-	$x = '';
40
-	$jquery_plugins = pipeline(
41
-		'jquery_plugins',
42
-		[
43
-			'prive/javascript/jquery.js',
44
-			'prive/javascript/jquery.form.js',
45
-			'prive/javascript/jquery.autosave.js',
46
-			'prive/javascript/jquery.placeholder-label.js',
47
-			'prive/javascript/ajaxCallback.js',
48
-			'prive/javascript/js.cookie.js',
49
-			'prive/javascript/jquery.cookie.js',
50
-			'prive/javascript/spip_barre.js',
51
-		]
52
-	);
53
-	foreach (array_unique($jquery_plugins) as $script) {
54
-		if ($script = find_in_path(supprimer_timestamp($script))) {
55
-			$script = timestamp($script);
56
-			$x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
57
-		}
58
-	}
59
-	// inserer avant le premier script externe ou a la fin
60
-	if (
61
-		preg_match(',<script[^><]*src=,', $texte, $match)
62
-		and $p = strpos($texte, $match[0])
63
-	) {
64
-		$texte = substr_replace($texte, $x, $p, 0);
65
-	} else {
66
-		$texte .= $x;
67
-	}
39
+    $x = '';
40
+    $jquery_plugins = pipeline(
41
+        'jquery_plugins',
42
+        [
43
+            'prive/javascript/jquery.js',
44
+            'prive/javascript/jquery.form.js',
45
+            'prive/javascript/jquery.autosave.js',
46
+            'prive/javascript/jquery.placeholder-label.js',
47
+            'prive/javascript/ajaxCallback.js',
48
+            'prive/javascript/js.cookie.js',
49
+            'prive/javascript/jquery.cookie.js',
50
+            'prive/javascript/spip_barre.js',
51
+        ]
52
+    );
53
+    foreach (array_unique($jquery_plugins) as $script) {
54
+        if ($script = find_in_path(supprimer_timestamp($script))) {
55
+            $script = timestamp($script);
56
+            $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
57
+        }
58
+    }
59
+    // inserer avant le premier script externe ou a la fin
60
+    if (
61
+        preg_match(',<script[^><]*src=,', $texte, $match)
62
+        and $p = strpos($texte, $match[0])
63
+    ) {
64
+        $texte = substr_replace($texte, $x, $p, 0);
65
+    } else {
66
+        $texte .= $x;
67
+    }
68 68
 
69
-	return $texte;
69
+    return $texte;
70 70
 }
71 71
 
72 72
 
@@ -79,43 +79,43 @@  discard block
 block discarded – undo
79 79
  * @return string
80 80
  */
81 81
 function affichage_final_prive_title_auto($texte) {
82
-	if (
83
-		strpos($texte, '<title>') === false
84
-		and
85
-		(preg_match(',<h1[^>]*>(.+)</h1>,Uims', $texte, $match)
86
-			or preg_match(',<h[23][^>]*>(.+)</h[23]>,Uims', $texte, $match))
87
-		and $match = textebrut(trim($match[1]))
88
-		and ($p = strpos($texte, '<head>')) !== false
89
-	) {
90
-		if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) {
91
-			$nom_site_spip = _T('info_mon_site_spip');
92
-		}
82
+    if (
83
+        strpos($texte, '<title>') === false
84
+        and
85
+        (preg_match(',<h1[^>]*>(.+)</h1>,Uims', $texte, $match)
86
+            or preg_match(',<h[23][^>]*>(.+)</h[23]>,Uims', $texte, $match))
87
+        and $match = textebrut(trim($match[1]))
88
+        and ($p = strpos($texte, '<head>')) !== false
89
+    ) {
90
+        if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) {
91
+            $nom_site_spip = _T('info_mon_site_spip');
92
+        }
93 93
 
94
-		$titre = '<title>['
95
-			. $nom_site_spip
96
-			. '] ' . $match
97
-			. '</title>';
94
+        $titre = '<title>['
95
+            . $nom_site_spip
96
+            . '] ' . $match
97
+            . '</title>';
98 98
 
99
-		$texte = substr_replace($texte, $titre, $p + 6, 0);
100
-	}
99
+        $texte = substr_replace($texte, $titre, $p + 6, 0);
100
+    }
101 101
 
102
-	return $texte;
102
+    return $texte;
103 103
 }
104 104
 
105 105
 
106 106
 // Fonction standard pour le pipeline 'boite_infos'
107 107
 // https://code.spip.net/@f_boite_infos
108 108
 function f_boite_infos($flux) {
109
-	$args = $flux['args'];
110
-	$type = $args['type'];
111
-	unset($args['row']);
112
-	if (!trouver_fond($type, 'prive/objets/infos/')) {
113
-		$type = 'objet';
114
-	}
115
-	$args['espace_prive'] = 1;
116
-	$flux['data'] .= recuperer_fond("prive/objets/infos/$type", $args);
109
+    $args = $flux['args'];
110
+    $type = $args['type'];
111
+    unset($args['row']);
112
+    if (!trouver_fond($type, 'prive/objets/infos/')) {
113
+        $type = 'objet';
114
+    }
115
+    $args['espace_prive'] = 1;
116
+    $flux['data'] .= recuperer_fond("prive/objets/infos/$type", $args);
117 117
 
118
-	return $flux;
118
+    return $flux;
119 119
 }
120 120
 
121 121
 
@@ -134,97 +134,97 @@  discard block
 block discarded – undo
134 134
  * @return array Données du pipeline
135 135
  */
136 136
 function f_afficher_blocs_ecrire($flux) {
137
-	static $o = [];
138
-	if (is_string($fond = $flux['args']['fond'])) {
139
-		$exec = isset($flux['args']['contexte']['exec']) ? $flux['args']['contexte']['exec'] : _request('exec');
140
-		if (!isset($o[$exec])) {
141
-			$o[$exec] = trouver_objet_exec($exec);
142
-		}
143
-		// cas particulier
144
-		if ($exec == 'infos_perso') {
145
-			$flux['args']['contexte']['id_auteur'] = $GLOBALS['visiteur_session']['id_auteur'];
146
-		}
147
-		$typepage = (isset($flux['args']['contexte']['type-page']) ? $flux['args']['contexte']['type-page'] : $exec);
148
-		if ($fond == "prive/squelettes/navigation/$typepage") {
149
-			$flux['data']['texte'] = pipeline(
150
-				'affiche_gauche',
151
-				['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
152
-			);
153
-		} elseif ($fond == "prive/squelettes/extra/$typepage") {
154
-			include_spip('inc/presentation_mini');
155
-			$flux['data']['texte'] = pipeline(
156
-				'affiche_droite',
157
-				['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
158
-			) . liste_objets_bloques(
159
-				$exec,
160
-				$flux['args']['contexte']
161
-			);
162
-		} elseif ($fond == "prive/squelettes/hierarchie/$typepage" and $o[$exec]) {
163
-			// id non defini sur les formulaire de nouveaux objets
164
-			$id = isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) ? intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) : 0;
165
-			$flux['data']['texte'] = pipeline(
166
-				'affiche_hierarchie',
167
-				['args' => ['objet' => $o[$exec]['type'], 'id_objet' => $id], 'data' => $flux['data']['texte']]
168
-			);
169
-		} elseif ($fond == "prive/squelettes/contenu/$typepage") {
170
-			// Préparation du marqueur affiche_milieu
171
-			// Si c'est la page d'un objet pas en édition, on l'encapsule dans un div
172
-			$est_page_objet = !empty($o[$exec]['type']);
173
-			$est_en_edition = (isset($o[$exec]['edition']) and $o[$exec]['edition'] === true);
174
-			$encapsuler_milieu = ($est_page_objet and !$est_en_edition);
175
-			$flux['data']['texte'] = afficher_blocs_ecrire_preparer_marqueur(
176
-				$flux['data']['texte'],
177
-				'<!--affiche_milieu-->',
178
-				'<div id=["\']wysiwyg',
179
-				$encapsuler_milieu ? '<div class="affiche_milieu">' : '',
180
-				$encapsuler_milieu ? '</div>' : ''
181
-			);
182
-			if (
183
-				$o[$exec]
184
-				and $objet = $o[$exec]['type']
185
-				and $o[$exec]['edition'] == false
186
-				and isset($flux['args']['contexte'][$o[$exec]['id_table_objet']])
187
-				and $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']])
188
-			) {
189
-				// inserer le formulaire de traduction
190
-				$flux['data']['texte'] = str_replace('<!--affiche_milieu-->', recuperer_fond(
191
-					'prive/objets/editer/traductions',
192
-					['objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1]
193
-				) . '<!--affiche_milieu-->', $flux['data']['texte']);
194
-				$flux['data']['texte'] = pipeline('afficher_fiche_objet', [
195
-					'args' => [
196
-						'contexte' => $flux['args']['contexte'],
197
-						'type' => $objet,
198
-						'id' => $id
199
-					],
200
-					'data' => $flux['data']['texte']
201
-				]);
202
-			}
203
-			$flux['data']['texte'] = pipeline(
204
-				'affiche_milieu',
205
-				['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
206
-			);
207
-		} elseif ($fond == 'prive/squelettes/inclure/pied') {
208
-			$flux['data']['texte'] = pipeline(
209
-				'affiche_pied',
210
-				['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
211
-			);
212
-		} elseif (
213
-			strncmp($fond, 'prive/objets/contenu/', 21) == 0
214
-			and $objet = basename($fond)
215
-			and $objet == substr($fond, 21)
216
-			and isset($o[$objet])
217
-			and $o[$objet]
218
-		) {
219
-			$id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]);
220
-			$flux['data']['texte'] = pipeline('afficher_contenu_objet', [
221
-				'args' => ['type' => $objet, 'id_objet' => $id, 'contexte' => $flux['args']['contexte']],
222
-				'data' => $flux['data']['texte']
223
-			]);
224
-		}
225
-	}
137
+    static $o = [];
138
+    if (is_string($fond = $flux['args']['fond'])) {
139
+        $exec = isset($flux['args']['contexte']['exec']) ? $flux['args']['contexte']['exec'] : _request('exec');
140
+        if (!isset($o[$exec])) {
141
+            $o[$exec] = trouver_objet_exec($exec);
142
+        }
143
+        // cas particulier
144
+        if ($exec == 'infos_perso') {
145
+            $flux['args']['contexte']['id_auteur'] = $GLOBALS['visiteur_session']['id_auteur'];
146
+        }
147
+        $typepage = (isset($flux['args']['contexte']['type-page']) ? $flux['args']['contexte']['type-page'] : $exec);
148
+        if ($fond == "prive/squelettes/navigation/$typepage") {
149
+            $flux['data']['texte'] = pipeline(
150
+                'affiche_gauche',
151
+                ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
152
+            );
153
+        } elseif ($fond == "prive/squelettes/extra/$typepage") {
154
+            include_spip('inc/presentation_mini');
155
+            $flux['data']['texte'] = pipeline(
156
+                'affiche_droite',
157
+                ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
158
+            ) . liste_objets_bloques(
159
+                $exec,
160
+                $flux['args']['contexte']
161
+            );
162
+        } elseif ($fond == "prive/squelettes/hierarchie/$typepage" and $o[$exec]) {
163
+            // id non defini sur les formulaire de nouveaux objets
164
+            $id = isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) ? intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) : 0;
165
+            $flux['data']['texte'] = pipeline(
166
+                'affiche_hierarchie',
167
+                ['args' => ['objet' => $o[$exec]['type'], 'id_objet' => $id], 'data' => $flux['data']['texte']]
168
+            );
169
+        } elseif ($fond == "prive/squelettes/contenu/$typepage") {
170
+            // Préparation du marqueur affiche_milieu
171
+            // Si c'est la page d'un objet pas en édition, on l'encapsule dans un div
172
+            $est_page_objet = !empty($o[$exec]['type']);
173
+            $est_en_edition = (isset($o[$exec]['edition']) and $o[$exec]['edition'] === true);
174
+            $encapsuler_milieu = ($est_page_objet and !$est_en_edition);
175
+            $flux['data']['texte'] = afficher_blocs_ecrire_preparer_marqueur(
176
+                $flux['data']['texte'],
177
+                '<!--affiche_milieu-->',
178
+                '<div id=["\']wysiwyg',
179
+                $encapsuler_milieu ? '<div class="affiche_milieu">' : '',
180
+                $encapsuler_milieu ? '</div>' : ''
181
+            );
182
+            if (
183
+                $o[$exec]
184
+                and $objet = $o[$exec]['type']
185
+                and $o[$exec]['edition'] == false
186
+                and isset($flux['args']['contexte'][$o[$exec]['id_table_objet']])
187
+                and $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']])
188
+            ) {
189
+                // inserer le formulaire de traduction
190
+                $flux['data']['texte'] = str_replace('<!--affiche_milieu-->', recuperer_fond(
191
+                    'prive/objets/editer/traductions',
192
+                    ['objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1]
193
+                ) . '<!--affiche_milieu-->', $flux['data']['texte']);
194
+                $flux['data']['texte'] = pipeline('afficher_fiche_objet', [
195
+                    'args' => [
196
+                        'contexte' => $flux['args']['contexte'],
197
+                        'type' => $objet,
198
+                        'id' => $id
199
+                    ],
200
+                    'data' => $flux['data']['texte']
201
+                ]);
202
+            }
203
+            $flux['data']['texte'] = pipeline(
204
+                'affiche_milieu',
205
+                ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
206
+            );
207
+        } elseif ($fond == 'prive/squelettes/inclure/pied') {
208
+            $flux['data']['texte'] = pipeline(
209
+                'affiche_pied',
210
+                ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
211
+            );
212
+        } elseif (
213
+            strncmp($fond, 'prive/objets/contenu/', 21) == 0
214
+            and $objet = basename($fond)
215
+            and $objet == substr($fond, 21)
216
+            and isset($o[$objet])
217
+            and $o[$objet]
218
+        ) {
219
+            $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]);
220
+            $flux['data']['texte'] = pipeline('afficher_contenu_objet', [
221
+                'args' => ['type' => $objet, 'id_objet' => $id, 'contexte' => $flux['args']['contexte']],
222
+                'data' => $flux['data']['texte']
223
+            ]);
224
+        }
225
+    }
226 226
 
227
-	return $flux;
227
+    return $flux;
228 228
 }
229 229
 
230 230
 /**
@@ -252,36 +252,36 @@  discard block
 block discarded – undo
252 252
  */
253 253
 function afficher_blocs_ecrire_preparer_marqueur(?string $texte, string $marqueur, string $inserer_avant, string $ouvrir = '', string $fermer = ''): ?string {
254 254
 
255
-	if ($texte) {
256
-		$encapsuler = (($ouvrir and $fermer) ? true : false);
257
-		$marqueur_pos = strpos($texte, $marqueur);
258
-		$full_marqueur = "$ouvrir$marqueur$fermer";
255
+    if ($texte) {
256
+        $encapsuler = (($ouvrir and $fermer) ? true : false);
257
+        $marqueur_pos = strpos($texte, $marqueur);
258
+        $full_marqueur = "$ouvrir$marqueur$fermer";
259 259
 
260
-		// Le marqueur est absent : on l'ajoute avant l'élément indiqué
261
-		if ($marqueur_pos  === false) {
262
-			$texte = preg_replace(
263
-				",$inserer_avant,",
264
-				"$full_marqueur\\0",
265
-				$texte
266
-			);
267
-		// Le marqueur est présent mais pas encapsulé : on ajoute les balises ouvrantes et fermantes.
268
-		// Pour vérifier, on prend le texte précédent et on regarde si ça correspond à la balise ouvrante.
269
-		// Il ne faut donc aucun espace blanc en trop.
270
-		} elseif (
271
-			$marqueur_pos !== false
272
-			and $encapsuler
273
-			and substr($texte, $marqueur_pos - strlen($ouvrir), strlen($ouvrir)) !== $ouvrir
274
-		) {
275
-			$texte = substr_replace(
276
-				$texte,
277
-				$full_marqueur,
278
-				$marqueur_pos,
279
-				strlen($marqueur)
280
-			);
281
-		}
282
-	}
260
+        // Le marqueur est absent : on l'ajoute avant l'élément indiqué
261
+        if ($marqueur_pos  === false) {
262
+            $texte = preg_replace(
263
+                ",$inserer_avant,",
264
+                "$full_marqueur\\0",
265
+                $texte
266
+            );
267
+        // Le marqueur est présent mais pas encapsulé : on ajoute les balises ouvrantes et fermantes.
268
+        // Pour vérifier, on prend le texte précédent et on regarde si ça correspond à la balise ouvrante.
269
+        // Il ne faut donc aucun espace blanc en trop.
270
+        } elseif (
271
+            $marqueur_pos !== false
272
+            and $encapsuler
273
+            and substr($texte, $marqueur_pos - strlen($ouvrir), strlen($ouvrir)) !== $ouvrir
274
+        ) {
275
+            $texte = substr_replace(
276
+                $texte,
277
+                $full_marqueur,
278
+                $marqueur_pos,
279
+                strlen($marqueur)
280
+            );
281
+        }
282
+    }
283 283
 
284
-	return $texte;
284
+    return $texte;
285 285
 }
286 286
 
287 287
 /**
@@ -292,23 +292,23 @@  discard block
 block discarded – undo
292 292
  * @return string
293 293
  */
294 294
 function f_queue_affiche_milieu($flux) {
295
-	$args = $flux['args'];
296
-	$res = '';
297
-	foreach ($args as $key => $arg) {
298
-		if (preg_match(',^id_,', $key) and is_numeric($arg) and $arg = intval($arg)) {
299
-			$objet = preg_replace(',^id_,', '', $key);
300
-			$res .= recuperer_fond(
301
-				'modeles/object_jobs_list',
302
-				['id_objet' => $arg, 'objet' => $objet, 'espace_prive' => 1],
303
-				['ajax' => true]
304
-			);
305
-		}
306
-	}
307
-	if ($res) {
308
-		$flux['data'] = $res . $flux['data'];
309
-	}
295
+    $args = $flux['args'];
296
+    $res = '';
297
+    foreach ($args as $key => $arg) {
298
+        if (preg_match(',^id_,', $key) and is_numeric($arg) and $arg = intval($arg)) {
299
+            $objet = preg_replace(',^id_,', '', $key);
300
+            $res .= recuperer_fond(
301
+                'modeles/object_jobs_list',
302
+                ['id_objet' => $arg, 'objet' => $objet, 'espace_prive' => 1],
303
+                ['ajax' => true]
304
+            );
305
+        }
306
+    }
307
+    if ($res) {
308
+        $flux['data'] = $res . $flux['data'];
309
+    }
310 310
 
311
-	return $flux;
311
+    return $flux;
312 312
 }
313 313
 
314 314
 /**
@@ -322,39 +322,39 @@  discard block
 block discarded – undo
322 322
  * @return array|bool
323 323
  */
324 324
 function trouver_objet_exec(string $exec) {
325
-	static $objet_exec = [];
326
-	if (!$exec) {
327
-		return false;
328
-	}
329
-	// cas particulier
330
-	if ($exec === 'infos_perso') {
331
-		$exec = 'auteur';
332
-		set_request('id_auteur', $GLOBALS['visiteur_session']['id_auteur']);
333
-	}
334
-	if (!isset($objet_exec[$exec])) {
335
-		$objet_exec[$exec] = false;
336
-		$infos = lister_tables_objets_sql();
337
-		foreach ($infos as $t => $info) {
338
-			if ($exec === $info['url_edit'] and $info['editable']) {
339
-				return $objet_exec[$exec] = [
340
-					'edition' => $exec == $info['url_voir'] ? '' : true,
341
-					'table_objet_sql' => $t,
342
-					'table' => $info['table_objet'],
343
-					'type' => $info['type'],
344
-					'id_table_objet' => id_table_objet($info['type'])
345
-				];
346
-			}
347
-			if ($exec === $info['url_voir']) {
348
-				return $objet_exec[$exec] = [
349
-					'edition' => false,
350
-					'table_objet_sql' => $t,
351
-					'table' => $info['table_objet'],
352
-					'type' => $info['type'],
353
-					'id_table_objet' => id_table_objet($info['type'])
354
-				];
355
-			}
356
-		}
357
-	}
325
+    static $objet_exec = [];
326
+    if (!$exec) {
327
+        return false;
328
+    }
329
+    // cas particulier
330
+    if ($exec === 'infos_perso') {
331
+        $exec = 'auteur';
332
+        set_request('id_auteur', $GLOBALS['visiteur_session']['id_auteur']);
333
+    }
334
+    if (!isset($objet_exec[$exec])) {
335
+        $objet_exec[$exec] = false;
336
+        $infos = lister_tables_objets_sql();
337
+        foreach ($infos as $t => $info) {
338
+            if ($exec === $info['url_edit'] and $info['editable']) {
339
+                return $objet_exec[$exec] = [
340
+                    'edition' => $exec == $info['url_voir'] ? '' : true,
341
+                    'table_objet_sql' => $t,
342
+                    'table' => $info['table_objet'],
343
+                    'type' => $info['type'],
344
+                    'id_table_objet' => id_table_objet($info['type'])
345
+                ];
346
+            }
347
+            if ($exec === $info['url_voir']) {
348
+                return $objet_exec[$exec] = [
349
+                    'edition' => false,
350
+                    'table_objet_sql' => $t,
351
+                    'table' => $info['table_objet'],
352
+                    'type' => $info['type'],
353
+                    'id_table_objet' => id_table_objet($info['type'])
354
+                ];
355
+            }
356
+        }
357
+    }
358 358
 
359
-	return $objet_exec[$exec];
359
+    return $objet_exec[$exec];
360 360
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres.php 3 patches
Indentation   +2423 added lines, -2423 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,38 +77,38 @@  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
-		// fonction ou name\space\fonction
102
-		if (is_callable($f)) {
103
-			return $f;
104
-		}
105
-		// méthode statique d'une classe Classe::methode ou name\space\Classe::methode
106
-		elseif (false === strpos($f, '::') and is_callable([$f])) {
107
-			return $f;
108
-		}
109
-	}
110
-
111
-	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
+        // fonction ou name\space\fonction
102
+        if (is_callable($f)) {
103
+            return $f;
104
+        }
105
+        // méthode statique d'une classe Classe::methode ou name\space\Classe::methode
106
+        elseif (false === strpos($f, '::') and is_callable([$f])) {
107
+            return $f;
108
+        }
109
+    }
110
+
111
+    return $default;
112 112
 }
113 113
 
114 114
 /**
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
  *     Chaîne vide sinon.
153 153
  **/
154 154
 function appliquer_filtre($arg, $filtre) {
155
-	$args = func_get_args();
156
-	return appliquer_filtre_sinon($arg, $filtre, $args, '');
155
+    $args = func_get_args();
156
+    return appliquer_filtre_sinon($arg, $filtre, $args, '');
157 157
 }
158 158
 
159 159
 /**
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
  *     Texte d'origine sinon
179 179
  **/
180 180
 function appliquer_si_filtre($arg, $filtre) {
181
-	$args = func_get_args();
182
-	return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
181
+    $args = func_get_args();
182
+    return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
183 183
 }
184 184
 
185 185
 /**
@@ -195,12 +195,12 @@  discard block
 block discarded – undo
195 195
  *     Version de SPIP
196 196
  **/
197 197
 function spip_version() {
198
-	$version = $GLOBALS['spip_version_affichee'];
199
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
200
-		$version .= " $vcs_version";
201
-	}
198
+    $version = $GLOBALS['spip_version_affichee'];
199
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
200
+        $version .= " $vcs_version";
201
+    }
202 202
 
203
-	return $version;
203
+    return $version;
204 204
 }
205 205
 
206 206
 /**
@@ -213,19 +213,19 @@  discard block
 block discarded – undo
213 213
  *    - string|null si $raw = false
214 214
  */
215 215
 function version_vcs_courante($dir, $raw = false) {
216
-	$desc = decrire_version_git($dir);
217
-	if ($desc === null) {
218
-		$desc = decrire_version_svn($dir);
219
-	}
220
-	if ($desc === null or $raw) {
221
-		return $desc;
222
-	}
223
-	// affichage "GIT [master: abcdef]"
224
-	$commit = $desc['commit_short'] ?? $desc['commit'];
225
-	if ($desc['branch']) {
226
-		$commit = $desc['branch'] . ': ' . $commit;
227
-	}
228
-	return "{$desc['vcs']} [$commit]";
216
+    $desc = decrire_version_git($dir);
217
+    if ($desc === null) {
218
+        $desc = decrire_version_svn($dir);
219
+    }
220
+    if ($desc === null or $raw) {
221
+        return $desc;
222
+    }
223
+    // affichage "GIT [master: abcdef]"
224
+    $commit = $desc['commit_short'] ?? $desc['commit'];
225
+    if ($desc['branch']) {
226
+        $commit = $desc['branch'] . ': ' . $commit;
227
+    }
228
+    return "{$desc['vcs']} [$commit]";
229 229
 }
230 230
 
231 231
 /**
@@ -237,24 +237,24 @@  discard block
 block discarded – undo
237 237
  *      array ['branch' => xx, 'commit' => yy] sinon.
238 238
  **/
239 239
 function decrire_version_git($dir) {
240
-	if (!$dir) {
241
-		$dir = '.';
242
-	}
240
+    if (!$dir) {
241
+        $dir = '.';
242
+    }
243 243
 
244
-	// version installee par GIT
245
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
246
-		$currentHead = trim(substr($c, 4));
247
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
248
-			return [
249
-				'vcs' => 'GIT',
250
-				'branch' => basename($currentHead),
251
-				'commit' => trim($hash),
252
-				'commit_short' => substr(trim($hash), 0, 8),
253
-			];
254
-		}
255
-	}
244
+    // version installee par GIT
245
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
246
+        $currentHead = trim(substr($c, 4));
247
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
248
+            return [
249
+                'vcs' => 'GIT',
250
+                'branch' => basename($currentHead),
251
+                'commit' => trim($hash),
252
+                'commit_short' => substr(trim($hash), 0, 8),
253
+            ];
254
+        }
255
+    }
256 256
 
257
-	return null;
257
+    return null;
258 258
 }
259 259
 
260 260
 
@@ -267,25 +267,25 @@  discard block
 block discarded – undo
267 267
  *      array ['commit' => yy, 'date' => xx, 'author' => xx] sinon.
268 268
  **/
269 269
 function decrire_version_svn($dir) {
270
-	if (!$dir) {
271
-		$dir = '.';
272
-	}
273
-	// version installee par SVN
274
-	if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
275
-		$db = new SQLite3($dir . '/.svn/wc.db');
276
-		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
277
-		if ($result) {
278
-			$row = $result->fetchArray();
279
-			if ($row['changed_revision'] != '') {
280
-				return [
281
-					'vcs' => 'SVN',
282
-					'branch' => '',
283
-					'commit' => $row['changed_revision'],
284
-				];
285
-			}
286
-		}
287
-	}
288
-	return null;
270
+    if (!$dir) {
271
+        $dir = '.';
272
+    }
273
+    // version installee par SVN
274
+    if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
275
+        $db = new SQLite3($dir . '/.svn/wc.db');
276
+        $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
277
+        if ($result) {
278
+            $row = $result->fetchArray();
279
+            if ($row['changed_revision'] != '') {
280
+                return [
281
+                    'vcs' => 'SVN',
282
+                    'branch' => '',
283
+                    'commit' => $row['changed_revision'],
284
+                ];
285
+            }
286
+        }
287
+    }
288
+    return null;
289 289
 }
290 290
 
291 291
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -332,18 +332,18 @@  discard block
 block discarded – undo
332 332
  *     Code HTML retourné par le filtre
333 333
  **/
334 334
 function filtrer($filtre) {
335
-	$tous = func_get_args();
336
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
337
-		return image_filtrer($tous);
338
-	} elseif ($f = chercher_filtre($filtre)) {
339
-		array_shift($tous);
340
-		return call_user_func_array($f, $tous);
341
-	} else {
342
-		// le filtre n'existe pas, on provoque une erreur
343
-		$msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
344
-		erreur_squelette($msg);
345
-		return '';
346
-	}
335
+    $tous = func_get_args();
336
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
337
+        return image_filtrer($tous);
338
+    } elseif ($f = chercher_filtre($filtre)) {
339
+        array_shift($tous);
340
+        return call_user_func_array($f, $tous);
341
+    } else {
342
+        // le filtre n'existe pas, on provoque une erreur
343
+        $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
344
+        erreur_squelette($msg);
345
+        return '';
346
+    }
347 347
 }
348 348
 
349 349
 /**
@@ -360,11 +360,11 @@  discard block
 block discarded – undo
360 360
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
361 361
  */
362 362
 function trouver_filtre_matrice($filtre) {
363
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
364
-		find_in_path($f, '', true);
365
-		$GLOBALS['spip_matrice'][$filtre] = true;
366
-	}
367
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
363
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
364
+        find_in_path($f, '', true);
365
+        $GLOBALS['spip_matrice'][$filtre] = true;
366
+    }
367
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
368 368
 }
369 369
 
370 370
 
@@ -392,8 +392,8 @@  discard block
 block discarded – undo
392 392
  * @return mixed
393 393
  */
394 394
 function filtre_set(&$Pile, $val, $key, $continue = null) {
395
-	$Pile['vars'][$key] = $val;
396
-	return $continue ? $val : '';
395
+    $Pile['vars'][$key] = $val;
396
+    return $continue ? $val : '';
397 397
 }
398 398
 
399 399
 /**
@@ -419,8 +419,8 @@  discard block
 block discarded – undo
419 419
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
420 420
  */
421 421
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
422
-	$Pile[0][$key] = $val;
423
-	return $continue ? $val : '';
422
+    $Pile[0][$key] = $val;
423
+    return $continue ? $val : '';
424 424
 }
425 425
 
426 426
 /**
@@ -429,8 +429,8 @@  discard block
 block discarded – undo
429 429
  * @return string
430 430
  */
431 431
 function filtre_sanitize_env(&$Pile, $keys) {
432
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
433
-	return '';
432
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
433
+    return '';
434 434
 }
435 435
 
436 436
 
@@ -453,18 +453,18 @@  discard block
 block discarded – undo
453 453
  * @return mixed Retourne la valeur (sans la modifier).
454 454
  */
455 455
 function filtre_debug($val, $key = null) {
456
-	$debug = (
457
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
458
-		) . var_export($val, true);
456
+    $debug = (
457
+        is_null($key) ? '' : (var_export($key, true) . ' = ')
458
+        ) . var_export($val, true);
459 459
 
460
-	include_spip('inc/autoriser');
461
-	if (autoriser('webmestre')) {
462
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
463
-	}
460
+    include_spip('inc/autoriser');
461
+    if (autoriser('webmestre')) {
462
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
463
+    }
464 464
 
465
-	spip_log($debug, 'debug');
465
+    spip_log($debug, 'debug');
466 466
 
467
-	return $val;
467
+    return $val;
468 468
 }
469 469
 
470 470
 
@@ -492,89 +492,89 @@  discard block
 block discarded – undo
492 492
  *     Texte qui a reçu les filtres
493 493
  **/
494 494
 function image_filtrer($args) {
495
-	$filtre = array_shift($args); # enlever $filtre
496
-	$texte = array_shift($args);
497
-	if ($texte === null || !strlen($texte)) {
498
-		return;
499
-	}
500
-	find_in_path('filtres_images_mini.php', 'inc/', true);
501
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
502
-	// Cas du nom de fichier local
503
-	$is_file = trim($texte);
504
-	if (
505
-		strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
506
-		  or strpbrk($is_file, "<>\n\r\t") !== false
507
-		  or strpos($is_file, '/') === 0
508
-	) {
509
-		$is_file = false;
510
-	}
511
-	if ($is_file) {
512
-		$is_local_file = function ($path) {
513
-			if (strpos($path, '?') !== false) {
514
-				$path = supprimer_timestamp($path);
515
-				// remove ?24px added by find_in_theme on .svg files
516
-				$path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
517
-			}
518
-			return file_exists($path);
519
-		};
520
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
521
-			array_unshift($args, "<img src='$is_file' />");
522
-			$res = call_user_func_array($filtre, $args);
523
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
524
-			return $res;
525
-		}
526
-	}
527
-
528
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
529
-	if (
530
-		preg_match_all(
531
-			',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
532
-			$texte,
533
-			$tags,
534
-			PREG_SET_ORDER
535
-		)
536
-	) {
537
-		foreach ($tags as $tag) {
538
-			$class = extraire_attribut($tag[3], 'class');
539
-			if (
540
-				!$class or
541
-				(strpos($class, 'filtre_inactif') === false
542
-					// compat historique a virer en 3.2
543
-					and strpos($class, 'no_image_filtrer') === false)
544
-			) {
545
-				array_unshift($args, $tag[3]);
546
-				if ($reduit = call_user_func_array($filtre, $args)) {
547
-					// En cas de span spip_documents, modifier le style=...width:
548
-					if ($tag[1]) {
549
-						$w = extraire_attribut($reduit, 'width');
550
-						if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
551
-							$w = $regs[1];
552
-						}
553
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
554
-							$style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style);
555
-							$replace = inserer_attribut($tag[1], 'style', $style);
556
-							$texte = str_replace($tag[1], $replace, $texte);
557
-						}
558
-					}
559
-					// traiter aussi un eventuel mouseover
560
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
561
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
562
-							$srcover = $match[1];
563
-							array_shift($args);
564
-							array_unshift($args, "<img src='" . $match[1] . "' />");
565
-							$srcover_filter = call_user_func_array($filtre, $args);
566
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
567
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
568
-						}
569
-					}
570
-					$texte = str_replace($tag[3], $reduit, $texte);
571
-				}
572
-				array_shift($args);
573
-			}
574
-		}
575
-	}
576
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
577
-	return $texte;
495
+    $filtre = array_shift($args); # enlever $filtre
496
+    $texte = array_shift($args);
497
+    if ($texte === null || !strlen($texte)) {
498
+        return;
499
+    }
500
+    find_in_path('filtres_images_mini.php', 'inc/', true);
501
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
502
+    // Cas du nom de fichier local
503
+    $is_file = trim($texte);
504
+    if (
505
+        strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
506
+          or strpbrk($is_file, "<>\n\r\t") !== false
507
+          or strpos($is_file, '/') === 0
508
+    ) {
509
+        $is_file = false;
510
+    }
511
+    if ($is_file) {
512
+        $is_local_file = function ($path) {
513
+            if (strpos($path, '?') !== false) {
514
+                $path = supprimer_timestamp($path);
515
+                // remove ?24px added by find_in_theme on .svg files
516
+                $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
517
+            }
518
+            return file_exists($path);
519
+        };
520
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
521
+            array_unshift($args, "<img src='$is_file' />");
522
+            $res = call_user_func_array($filtre, $args);
523
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
524
+            return $res;
525
+        }
526
+    }
527
+
528
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
529
+    if (
530
+        preg_match_all(
531
+            ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
532
+            $texte,
533
+            $tags,
534
+            PREG_SET_ORDER
535
+        )
536
+    ) {
537
+        foreach ($tags as $tag) {
538
+            $class = extraire_attribut($tag[3], 'class');
539
+            if (
540
+                !$class or
541
+                (strpos($class, 'filtre_inactif') === false
542
+                    // compat historique a virer en 3.2
543
+                    and strpos($class, 'no_image_filtrer') === false)
544
+            ) {
545
+                array_unshift($args, $tag[3]);
546
+                if ($reduit = call_user_func_array($filtre, $args)) {
547
+                    // En cas de span spip_documents, modifier le style=...width:
548
+                    if ($tag[1]) {
549
+                        $w = extraire_attribut($reduit, 'width');
550
+                        if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
551
+                            $w = $regs[1];
552
+                        }
553
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
554
+                            $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style);
555
+                            $replace = inserer_attribut($tag[1], 'style', $style);
556
+                            $texte = str_replace($tag[1], $replace, $texte);
557
+                        }
558
+                    }
559
+                    // traiter aussi un eventuel mouseover
560
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
561
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
562
+                            $srcover = $match[1];
563
+                            array_shift($args);
564
+                            array_unshift($args, "<img src='" . $match[1] . "' />");
565
+                            $srcover_filter = call_user_func_array($filtre, $args);
566
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
567
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
568
+                        }
569
+                    }
570
+                    $texte = str_replace($tag[3], $reduit, $texte);
571
+                }
572
+                array_shift($args);
573
+            }
574
+        }
575
+    }
576
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
577
+    return $texte;
578 578
 }
579 579
 
580 580
 /**
@@ -589,78 +589,78 @@  discard block
 block discarded – undo
589 589
  **/
590 590
 function taille_image($img, $force_refresh = false) {
591 591
 
592
-	static $largeur_img = [], $hauteur_img = [];
593
-	$srcWidth = 0;
594
-	$srcHeight = 0;
595
-
596
-	$src = extraire_attribut($img, 'src');
597
-
598
-	if (!$src) {
599
-		$src = $img;
600
-	} else {
601
-		$srcWidth = extraire_attribut($img, 'width');
602
-		$srcHeight = extraire_attribut($img, 'height');
603
-	}
604
-
605
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
606
-	// la copie locale a toutes les chances d'etre la ou de resservir
607
-	if (tester_url_absolue($src)) {
608
-		include_spip('inc/distant');
609
-		$fichier = copie_locale($src);
610
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
611
-	}
612
-	if (($p = strpos($src, '?')) !== false) {
613
-		$src = substr($src, 0, $p);
614
-	}
615
-
616
-	$srcsize = false;
617
-	if (isset($largeur_img[$src]) and !$force_refresh) {
618
-		$srcWidth = $largeur_img[$src];
619
-	}
620
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
621
-		$srcHeight = $hauteur_img[$src];
622
-	}
623
-	if (!$srcWidth or !$srcHeight) {
624
-		if (
625
-			file_exists($src)
626
-			and $srcsize = spip_getimagesize($src)
627
-		) {
628
-			if (!$srcWidth) {
629
-				$largeur_img[$src] = $srcWidth = $srcsize[0];
630
-			}
631
-			if (!$srcHeight) {
632
-				$hauteur_img[$src] = $srcHeight = $srcsize[1];
633
-			}
634
-		}
635
-		elseif (strpos($src, '<svg') !== false) {
636
-			include_spip('inc/svg');
637
-			if ($attrs = svg_lire_attributs($src)) {
638
-				list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
639
-				if (!$srcWidth) {
640
-					$largeur_img[$src] = $srcWidth = $width;
641
-				}
642
-				if (!$srcHeight) {
643
-					$hauteur_img[$src] = $srcHeight = $height;
644
-				}
645
-			}
646
-		}
647
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
648
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
649
-		elseif (
650
-			@file_exists($f = "$src.src")
651
-			and lire_fichier($f, $valeurs)
652
-			and $valeurs = unserialize($valeurs)
653
-		) {
654
-			if (!$srcWidth) {
655
-				$largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
656
-			}
657
-			if (!$srcHeight) {
658
-				$hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
659
-			}
660
-		}
661
-	}
662
-
663
-	return [$srcHeight, $srcWidth];
592
+    static $largeur_img = [], $hauteur_img = [];
593
+    $srcWidth = 0;
594
+    $srcHeight = 0;
595
+
596
+    $src = extraire_attribut($img, 'src');
597
+
598
+    if (!$src) {
599
+        $src = $img;
600
+    } else {
601
+        $srcWidth = extraire_attribut($img, 'width');
602
+        $srcHeight = extraire_attribut($img, 'height');
603
+    }
604
+
605
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
606
+    // la copie locale a toutes les chances d'etre la ou de resservir
607
+    if (tester_url_absolue($src)) {
608
+        include_spip('inc/distant');
609
+        $fichier = copie_locale($src);
610
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
611
+    }
612
+    if (($p = strpos($src, '?')) !== false) {
613
+        $src = substr($src, 0, $p);
614
+    }
615
+
616
+    $srcsize = false;
617
+    if (isset($largeur_img[$src]) and !$force_refresh) {
618
+        $srcWidth = $largeur_img[$src];
619
+    }
620
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
621
+        $srcHeight = $hauteur_img[$src];
622
+    }
623
+    if (!$srcWidth or !$srcHeight) {
624
+        if (
625
+            file_exists($src)
626
+            and $srcsize = spip_getimagesize($src)
627
+        ) {
628
+            if (!$srcWidth) {
629
+                $largeur_img[$src] = $srcWidth = $srcsize[0];
630
+            }
631
+            if (!$srcHeight) {
632
+                $hauteur_img[$src] = $srcHeight = $srcsize[1];
633
+            }
634
+        }
635
+        elseif (strpos($src, '<svg') !== false) {
636
+            include_spip('inc/svg');
637
+            if ($attrs = svg_lire_attributs($src)) {
638
+                list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
639
+                if (!$srcWidth) {
640
+                    $largeur_img[$src] = $srcWidth = $width;
641
+                }
642
+                if (!$srcHeight) {
643
+                    $hauteur_img[$src] = $srcHeight = $height;
644
+                }
645
+            }
646
+        }
647
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
648
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
649
+        elseif (
650
+            @file_exists($f = "$src.src")
651
+            and lire_fichier($f, $valeurs)
652
+            and $valeurs = unserialize($valeurs)
653
+        ) {
654
+            if (!$srcWidth) {
655
+                $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
656
+            }
657
+            if (!$srcHeight) {
658
+                $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
659
+            }
660
+        }
661
+    }
662
+
663
+    return [$srcHeight, $srcWidth];
664 664
 }
665 665
 
666 666
 
@@ -678,12 +678,12 @@  discard block
 block discarded – undo
678 678
  *     Largeur en pixels, NULL ou 0 si aucune image.
679 679
  **/
680 680
 function largeur($img) {
681
-	if (!$img) {
682
-		return;
683
-	}
684
-	list($h, $l) = taille_image($img);
681
+    if (!$img) {
682
+        return;
683
+    }
684
+    list($h, $l) = taille_image($img);
685 685
 
686
-	return $l;
686
+    return $l;
687 687
 }
688 688
 
689 689
 /**
@@ -700,12 +700,12 @@  discard block
 block discarded – undo
700 700
  *     Hauteur en pixels, NULL ou 0 si aucune image.
701 701
  **/
702 702
 function hauteur($img) {
703
-	if (!$img) {
704
-		return;
705
-	}
706
-	list($h, $l) = taille_image($img);
703
+    if (!$img) {
704
+        return;
705
+    }
706
+    list($h, $l) = taille_image($img);
707 707
 
708
-	return $h;
708
+    return $h;
709 709
 }
710 710
 
711 711
 
@@ -725,11 +725,11 @@  discard block
 block discarded – undo
725 725
  * @return string
726 726
  **/
727 727
 function corriger_entites_html($texte) {
728
-	if (strpos($texte, '&amp;') === false) {
729
-		return $texte;
730
-	}
728
+    if (strpos($texte, '&amp;') === false) {
729
+        return $texte;
730
+    }
731 731
 
732
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
732
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
733 733
 }
734 734
 
735 735
 /**
@@ -744,11 +744,11 @@  discard block
 block discarded – undo
744 744
  * @return string
745 745
  **/
746 746
 function corriger_toutes_entites_html($texte) {
747
-	if (strpos($texte, '&amp;') === false) {
748
-		return $texte;
749
-	}
747
+    if (strpos($texte, '&amp;') === false) {
748
+        return $texte;
749
+    }
750 750
 
751
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
751
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
752 752
 }
753 753
 
754 754
 /**
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
  * @return string
759 759
  **/
760 760
 function proteger_amp($texte) {
761
-	return str_replace('&', '&amp;', $texte);
761
+    return str_replace('&', '&amp;', $texte);
762 762
 }
763 763
 
764 764
 
@@ -789,21 +789,21 @@  discard block
 block discarded – undo
789 789
  * @return mixed|string
790 790
  */
791 791
 function entites_html($texte, $tout = false, $quote = true) {
792
-	if (
793
-		!is_string($texte) or !$texte
794
-		or strpbrk($texte, "&\"'<>") == false
795
-	) {
796
-		return $texte;
797
-	}
798
-	include_spip('inc/texte');
799
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
800
-	$flags |= ENT_HTML401;
801
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
802
-	if ($tout) {
803
-		return corriger_toutes_entites_html($texte);
804
-	} else {
805
-		return corriger_entites_html($texte);
806
-	}
792
+    if (
793
+        !is_string($texte) or !$texte
794
+        or strpbrk($texte, "&\"'<>") == false
795
+    ) {
796
+        return $texte;
797
+    }
798
+    include_spip('inc/texte');
799
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
800
+    $flags |= ENT_HTML401;
801
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
802
+    if ($tout) {
803
+        return corriger_toutes_entites_html($texte);
804
+    } else {
805
+        return corriger_entites_html($texte);
806
+    }
807 807
 }
808 808
 
809 809
 /**
@@ -822,37 +822,37 @@  discard block
 block discarded – undo
822 822
  *     Texte converti
823 823
  **/
824 824
 function filtrer_entites($texte) {
825
-	if (strpos($texte, '&') === false) {
826
-		return $texte;
827
-	}
828
-	// filtrer
829
-	$texte = html2unicode($texte);
830
-	// remettre le tout dans le charset cible
831
-	$texte = unicode2charset($texte);
832
-	// cas particulier des " et ' qu'il faut filtrer aussi
833
-	// (on le faisait deja avec un &quot;)
834
-	if (strpos($texte, '&#') !== false) {
835
-		$texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
836
-	}
825
+    if (strpos($texte, '&') === false) {
826
+        return $texte;
827
+    }
828
+    // filtrer
829
+    $texte = html2unicode($texte);
830
+    // remettre le tout dans le charset cible
831
+    $texte = unicode2charset($texte);
832
+    // cas particulier des " et ' qu'il faut filtrer aussi
833
+    // (on le faisait deja avec un &quot;)
834
+    if (strpos($texte, '&#') !== false) {
835
+        $texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
836
+    }
837 837
 
838
-	return $texte;
838
+    return $texte;
839 839
 }
840 840
 
841 841
 
842 842
 if (!function_exists('filtre_filtrer_entites_dist')) {
843
-	/**
844
-	 * Version sécurisée de filtrer_entites
845
-	 *
846
-	 * @uses interdire_scripts()
847
-	 * @uses filtrer_entites()
848
-	 *
849
-	 * @param string $t
850
-	 * @return string
851
-	 */
852
-	function filtre_filtrer_entites_dist($t) {
853
-		include_spip('inc/texte');
854
-		return interdire_scripts(filtrer_entites($t));
855
-	}
843
+    /**
844
+     * Version sécurisée de filtrer_entites
845
+     *
846
+     * @uses interdire_scripts()
847
+     * @uses filtrer_entites()
848
+     *
849
+     * @param string $t
850
+     * @return string
851
+     */
852
+    function filtre_filtrer_entites_dist($t) {
853
+        include_spip('inc/texte');
854
+        return interdire_scripts(filtrer_entites($t));
855
+    }
856 856
 }
857 857
 
858 858
 
@@ -867,18 +867,18 @@  discard block
 block discarded – undo
867 867
  * @return string|array
868 868
  **/
869 869
 function supprimer_caracteres_illegaux($texte) {
870
-	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";
871
-	static $to = null;
870
+    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";
871
+    static $to = null;
872 872
 
873
-	if (is_array($texte)) {
874
-		return array_map('supprimer_caracteres_illegaux', $texte);
875
-	}
873
+    if (is_array($texte)) {
874
+        return array_map('supprimer_caracteres_illegaux', $texte);
875
+    }
876 876
 
877
-	if (!$to) {
878
-		$to = str_repeat('-', strlen($from));
879
-	}
877
+    if (!$to) {
878
+        $to = str_repeat('-', strlen($from));
879
+    }
880 880
 
881
-	return strtr($texte, $from, $to);
881
+    return strtr($texte, $from, $to);
882 882
 }
883 883
 
884 884
 /**
@@ -890,10 +890,10 @@  discard block
 block discarded – undo
890 890
  * @return string|array
891 891
  **/
892 892
 function corriger_caracteres($texte) {
893
-	$texte = corriger_caracteres_windows($texte);
894
-	$texte = supprimer_caracteres_illegaux($texte);
893
+    $texte = corriger_caracteres_windows($texte);
894
+    $texte = supprimer_caracteres_illegaux($texte);
895 895
 
896
-	return $texte;
896
+    return $texte;
897 897
 }
898 898
 
899 899
 /**
@@ -910,44 +910,44 @@  discard block
 block discarded – undo
910 910
  *     Texte encodé pour XML
911 911
  */
912 912
 function texte_backend(string $texte): string {
913
-	if ($texte === '') {
914
-		return '';
915
-	}
913
+    if ($texte === '') {
914
+        return '';
915
+    }
916 916
 
917
-	static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
917
+    static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
918 918
 
919
-	// si on a des liens ou des images, les passer en absolu
920
-	$texte = liens_absolus($texte);
919
+    // si on a des liens ou des images, les passer en absolu
920
+    $texte = liens_absolus($texte);
921 921
 
922
-	// echapper les tags &gt; &lt;
923
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
922
+    // echapper les tags &gt; &lt;
923
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
924 924
 
925
-	// importer les &eacute;
926
-	$texte = filtrer_entites($texte);
925
+    // importer les &eacute;
926
+    $texte = filtrer_entites($texte);
927 927
 
928
-	// " -> &quot; et tout ce genre de choses
929
-	$u = $GLOBALS['meta']['pcre_u'];
930
-	$texte = str_replace('&nbsp;', ' ', $texte);
931
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
932
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
933
-	$texte = entites_html($texte, false, false);
934
-	// mais bien echapper les double quotes !
935
-	$texte = str_replace('"', '&#034;', $texte);
928
+    // " -> &quot; et tout ce genre de choses
929
+    $u = $GLOBALS['meta']['pcre_u'];
930
+    $texte = str_replace('&nbsp;', ' ', $texte);
931
+    $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
932
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
933
+    $texte = entites_html($texte, false, false);
934
+    // mais bien echapper les double quotes !
935
+    $texte = str_replace('"', '&#034;', $texte);
936 936
 
937
-	// verifier le charset
938
-	$texte = charset2unicode($texte);
937
+    // verifier le charset
938
+    $texte = charset2unicode($texte);
939 939
 
940
-	// Caracteres problematiques en iso-latin 1
941
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
942
-		$texte = str_replace(chr(156), '&#156;', $texte);
943
-		$texte = str_replace(chr(140), '&#140;', $texte);
944
-		$texte = str_replace(chr(159), '&#159;', $texte);
945
-	}
940
+    // Caracteres problematiques en iso-latin 1
941
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
942
+        $texte = str_replace(chr(156), '&#156;', $texte);
943
+        $texte = str_replace(chr(140), '&#140;', $texte);
944
+        $texte = str_replace(chr(159), '&#159;', $texte);
945
+    }
946 946
 
947
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
948
-	// et le caractere apostrophe alourdit les squelettes avec PHP
949
-	// ==> on les remplace par l'entite HTML
950
-	return str_replace($apostrophe, "'", $texte);
947
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
948
+    // et le caractere apostrophe alourdit les squelettes avec PHP
949
+    // ==> on les remplace par l'entite HTML
950
+    return str_replace($apostrophe, "'", $texte);
951 951
 }
952 952
 
953 953
 /**
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
  *     Texte encodé et quote pour XML
965 965
  */
966 966
 function texte_backendq(string $texte): string {
967
-	return addslashes(texte_backend($texte));
967
+    return addslashes(texte_backend($texte));
968 968
 }
969 969
 
970 970
 
@@ -987,11 +987,11 @@  discard block
 block discarded – undo
987 987
  *     Numéro de titre, sinon chaîne vide
988 988
  **/
989 989
 function supprimer_numero($texte) {
990
-	return preg_replace(
991
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
992
-		'',
993
-		$texte
994
-	);
990
+    return preg_replace(
991
+        ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
992
+        '',
993
+        $texte
994
+    );
995 995
 }
996 996
 
997 997
 /**
@@ -1014,17 +1014,17 @@  discard block
 block discarded – undo
1014 1014
  *     Numéro de titre, sinon chaîne vide
1015 1015
  **/
1016 1016
 function recuperer_numero($texte) {
1017
-	if (
1018
-		preg_match(
1019
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1020
-			$texte,
1021
-			$regs
1022
-		)
1023
-	) {
1024
-		return strval($regs[1]);
1025
-	} else {
1026
-		return '';
1027
-	}
1017
+    if (
1018
+        preg_match(
1019
+            ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1020
+            $texte,
1021
+            $regs
1022
+        )
1023
+    ) {
1024
+        return strval($regs[1]);
1025
+    } else {
1026
+        return '';
1027
+    }
1028 1028
 }
1029 1029
 
1030 1030
 /**
@@ -1051,16 +1051,16 @@  discard block
 block discarded – undo
1051 1051
  *     Texte converti
1052 1052
  **/
1053 1053
 function supprimer_tags(?string $texte, $rempl = ''): string {
1054
-	if ($texte === null || !strlen($texte)) {
1055
-		return '';
1056
-	}
1057
-	$texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1058
-	// ne pas oublier un < final non ferme car coupe
1059
-	$texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1060
-	// mais qui peut aussi etre un simple signe plus petit que
1061
-	$texte = str_replace('<', '&lt;', $texte);
1054
+    if ($texte === null || !strlen($texte)) {
1055
+        return '';
1056
+    }
1057
+    $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1058
+    // ne pas oublier un < final non ferme car coupe
1059
+    $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1060
+    // mais qui peut aussi etre un simple signe plus petit que
1061
+    $texte = str_replace('<', '&lt;', $texte);
1062 1062
 
1063
-	return $texte;
1063
+    return $texte;
1064 1064
 }
1065 1065
 
1066 1066
 /**
@@ -1083,9 +1083,9 @@  discard block
 block discarded – undo
1083 1083
  *     Texte converti
1084 1084
  **/
1085 1085
 function echapper_tags($texte, $rempl = '') {
1086
-	$texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1086
+    $texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1087 1087
 
1088
-	return $texte;
1088
+    return $texte;
1089 1089
 }
1090 1090
 
1091 1091
 /**
@@ -1106,18 +1106,18 @@  discard block
 block discarded – undo
1106 1106
  *     Texte converti
1107 1107
  **/
1108 1108
 function textebrut($texte) {
1109
-	$u = $GLOBALS['meta']['pcre_u'];
1110
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1111
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1112
-	$texte = preg_replace("/^\n+/", '', $texte);
1113
-	$texte = preg_replace("/\n+$/", '', $texte);
1114
-	$texte = preg_replace("/\n +/", "\n", $texte);
1115
-	$texte = supprimer_tags($texte);
1116
-	$texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1117
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1118
-	$texte = str_replace('&#8217;', "'", $texte);
1109
+    $u = $GLOBALS['meta']['pcre_u'];
1110
+    $texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1111
+    $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1112
+    $texte = preg_replace("/^\n+/", '', $texte);
1113
+    $texte = preg_replace("/\n+$/", '', $texte);
1114
+    $texte = preg_replace("/\n +/", "\n", $texte);
1115
+    $texte = supprimer_tags($texte);
1116
+    $texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1117
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1118
+    $texte = str_replace('&#8217;', "'", $texte);
1119 1119
 
1120
-	return $texte;
1120
+    return $texte;
1121 1121
 }
1122 1122
 
1123 1123
 
@@ -1133,23 +1133,23 @@  discard block
 block discarded – undo
1133 1133
  *     Texte avec liens ouvrants
1134 1134
  **/
1135 1135
 function liens_ouvrants($texte) {
1136
-	if (
1137
-		preg_match_all(
1138
-			",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1139
-			$texte,
1140
-			$liens,
1141
-			PREG_PATTERN_ORDER
1142
-		)
1143
-	) {
1144
-		foreach ($liens[0] as $a) {
1145
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1146
-			$ablank = inserer_attribut($a, 'rel', $rel);
1147
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1148
-			$texte = str_replace($a, $ablank, $texte);
1149
-		}
1150
-	}
1151
-
1152
-	return $texte;
1136
+    if (
1137
+        preg_match_all(
1138
+            ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1139
+            $texte,
1140
+            $liens,
1141
+            PREG_PATTERN_ORDER
1142
+        )
1143
+    ) {
1144
+        foreach ($liens[0] as $a) {
1145
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1146
+            $ablank = inserer_attribut($a, 'rel', $rel);
1147
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1148
+            $texte = str_replace($a, $ablank, $texte);
1149
+        }
1150
+    }
1151
+
1152
+    return $texte;
1153 1153
 }
1154 1154
 
1155 1155
 /**
@@ -1159,22 +1159,22 @@  discard block
 block discarded – undo
1159 1159
  * @return string
1160 1160
  */
1161 1161
 function liens_nofollow($texte) {
1162
-	if (stripos($texte, '<a') === false) {
1163
-		return $texte;
1164
-	}
1162
+    if (stripos($texte, '<a') === false) {
1163
+        return $texte;
1164
+    }
1165 1165
 
1166
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1167
-		foreach ($regs[0] as $a) {
1168
-			$rel = extraire_attribut($a, 'rel');
1169
-			if (strpos($rel, 'nofollow') === false) {
1170
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1171
-				$anofollow = inserer_attribut($a, 'rel', $rel);
1172
-				$texte = str_replace($a, $anofollow, $texte);
1173
-			}
1174
-		}
1175
-	}
1166
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1167
+        foreach ($regs[0] as $a) {
1168
+            $rel = extraire_attribut($a, 'rel');
1169
+            if (strpos($rel, 'nofollow') === false) {
1170
+                $rel = 'nofollow' . ($rel ? " $rel" : '');
1171
+                $anofollow = inserer_attribut($a, 'rel', $rel);
1172
+                $texte = str_replace($a, $anofollow, $texte);
1173
+            }
1174
+        }
1175
+    }
1176 1176
 
1177
-	return $texte;
1177
+    return $texte;
1178 1178
 }
1179 1179
 
1180 1180
 /**
@@ -1193,12 +1193,12 @@  discard block
 block discarded – undo
1193 1193
  *     Texte sans paraghaphes
1194 1194
  **/
1195 1195
 function PtoBR($texte) {
1196
-	$u = $GLOBALS['meta']['pcre_u'];
1197
-	$texte = preg_replace('@</p>@iS', "\n", $texte);
1198
-	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1199
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1196
+    $u = $GLOBALS['meta']['pcre_u'];
1197
+    $texte = preg_replace('@</p>@iS', "\n", $texte);
1198
+    $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1199
+    $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1200 1200
 
1201
-	return $texte;
1201
+    return $texte;
1202 1202
 }
1203 1203
 
1204 1204
 
@@ -1223,14 +1223,14 @@  discard block
 block discarded – undo
1223 1223
  * @return string Texte encadré du style CSS
1224 1224
  */
1225 1225
 function lignes_longues($texte) {
1226
-	if (!strlen(trim($texte))) {
1227
-		return $texte;
1228
-	}
1229
-	include_spip('inc/texte');
1230
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1231
-		'div' : 'span';
1226
+    if (!strlen(trim($texte))) {
1227
+        return $texte;
1228
+    }
1229
+    include_spip('inc/texte');
1230
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1231
+        'div' : 'span';
1232 1232
 
1233
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1233
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1234 1234
 }
1235 1235
 
1236 1236
 /**
@@ -1249,30 +1249,30 @@  discard block
 block discarded – undo
1249 1249
  * @return string Texte en majuscule
1250 1250
  */
1251 1251
 function majuscules($texte) {
1252
-	if (!strlen($texte)) {
1253
-		return '';
1254
-	}
1252
+    if (!strlen($texte)) {
1253
+        return '';
1254
+    }
1255 1255
 
1256
-	// Cas du turc
1257
-	if ($GLOBALS['spip_lang'] == 'tr') {
1258
-		# remplacer hors des tags et des entites
1259
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1260
-			foreach ($regs as $n => $match) {
1261
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1262
-			}
1263
-		}
1256
+    // Cas du turc
1257
+    if ($GLOBALS['spip_lang'] == 'tr') {
1258
+        # remplacer hors des tags et des entites
1259
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1260
+            foreach ($regs as $n => $match) {
1261
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1262
+            }
1263
+        }
1264 1264
 
1265
-		$texte = str_replace('i', '&#304;', $texte);
1265
+        $texte = str_replace('i', '&#304;', $texte);
1266 1266
 
1267
-		if ($regs) {
1268
-			foreach ($regs as $n => $match) {
1269
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1270
-			}
1271
-		}
1272
-	}
1267
+        if ($regs) {
1268
+            foreach ($regs as $n => $match) {
1269
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1270
+            }
1271
+        }
1272
+    }
1273 1273
 
1274
-	// Cas general
1275
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1274
+    // Cas general
1275
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1276 1276
 }
1277 1277
 
1278 1278
 /**
@@ -1290,29 +1290,29 @@  discard block
 block discarded – undo
1290 1290
  * @return string
1291 1291
  **/
1292 1292
 function taille_en_octets($taille) {
1293
-	if (!defined('_KILOBYTE')) {
1294
-		/**
1295
-		 * Définit le nombre d'octets dans un Kilobyte
1296
-		 *
1297
-		 * @var int
1298
-		 **/
1299
-		define('_KILOBYTE', 1024);
1300
-	}
1293
+    if (!defined('_KILOBYTE')) {
1294
+        /**
1295
+         * Définit le nombre d'octets dans un Kilobyte
1296
+         *
1297
+         * @var int
1298
+         **/
1299
+        define('_KILOBYTE', 1024);
1300
+    }
1301 1301
 
1302
-	if ($taille < 1) {
1303
-		return '';
1304
-	}
1305
-	if ($taille < _KILOBYTE) {
1306
-		$taille = _T('taille_octets', ['taille' => $taille]);
1307
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1308
-		$taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1309
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1310
-		$taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1311
-	} else {
1312
-		$taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1313
-	}
1302
+    if ($taille < 1) {
1303
+        return '';
1304
+    }
1305
+    if ($taille < _KILOBYTE) {
1306
+        $taille = _T('taille_octets', ['taille' => $taille]);
1307
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1308
+        $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1309
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1310
+        $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1311
+    } else {
1312
+        $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1313
+    }
1314 1314
 
1315
-	return $taille;
1315
+    return $taille;
1316 1316
 }
1317 1317
 
1318 1318
 
@@ -1334,21 +1334,21 @@  discard block
 block discarded – undo
1334 1334
  *     Texte prêt pour être utilisé en attribut HTML
1335 1335
  **/
1336 1336
 function attribut_html(?string $texte, $textebrut = true): string {
1337
-	if ($texte === null) {
1338
-		return '';
1339
-	}
1340
-	$u = $GLOBALS['meta']['pcre_u'];
1341
-	if ($textebrut) {
1342
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1343
-	}
1344
-	$texte = texte_backend($texte);
1345
-	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1337
+    if ($texte === null) {
1338
+        return '';
1339
+    }
1340
+    $u = $GLOBALS['meta']['pcre_u'];
1341
+    if ($textebrut) {
1342
+        $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1343
+    }
1344
+    $texte = texte_backend($texte);
1345
+    $texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1346 1346
 
1347
-	return preg_replace(
1348
-		['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1349
-		['&', '&#38;'],
1350
-		$texte
1351
-	);
1347
+    return preg_replace(
1348
+        ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1349
+        ['&', '&#38;'],
1350
+        $texte
1351
+    );
1352 1352
 }
1353 1353
 
1354 1354
 
@@ -1368,15 +1368,15 @@  discard block
 block discarded – undo
1368 1368
  *     URL ou chaîne vide
1369 1369
  **/
1370 1370
 function vider_url(?string $url, $entites = true): string {
1371
-	if ($url === null) {
1372
-		return '';
1373
-	}
1374
-	# un message pour abs_url
1375
-	$GLOBALS['mode_abs_url'] = 'url';
1376
-	$url = trim($url);
1377
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1371
+    if ($url === null) {
1372
+        return '';
1373
+    }
1374
+    # un message pour abs_url
1375
+    $GLOBALS['mode_abs_url'] = 'url';
1376
+    $url = trim($url);
1377
+    $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1378 1378
 
1379
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1379
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1380 1380
 }
1381 1381
 
1382 1382
 
@@ -1391,10 +1391,10 @@  discard block
 block discarded – undo
1391 1391
  * @return string Adresse email maquillée
1392 1392
  **/
1393 1393
 function antispam($texte) {
1394
-	include_spip('inc/acces');
1395
-	$masque = creer_pass_aleatoire(3);
1394
+    include_spip('inc/acces');
1395
+    $masque = creer_pass_aleatoire(3);
1396 1396
 
1397
-	return preg_replace('/@/', " $masque ", $texte);
1397
+    return preg_replace('/@/', " $masque ", $texte);
1398 1398
 }
1399 1399
 
1400 1400
 /**
@@ -1426,12 +1426,12 @@  discard block
 block discarded – undo
1426 1426
  *     True si on a le droit d'accès, false sinon.
1427 1427
  **/
1428 1428
 function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') {
1429
-	include_spip('inc/acces');
1430
-	if ($op) {
1431
-		$dir .= " $op $args";
1432
-	}
1429
+    include_spip('inc/acces');
1430
+    if ($op) {
1431
+        $dir .= " $op $args";
1432
+    }
1433 1433
 
1434
-	return verifier_low_sec($id_auteur, $cle, $dir);
1434
+    return verifier_low_sec($id_auteur, $cle, $dir);
1435 1435
 }
1436 1436
 
1437 1437
 /**
@@ -1456,13 +1456,13 @@  discard block
 block discarded – undo
1456 1456
  *     Retourne $texte, sinon $sinon.
1457 1457
  **/
1458 1458
 function sinon($texte, $sinon = '') {
1459
-	if ($texte) {
1460
-		return $texte;
1461
-	} elseif (is_scalar($texte) and strlen($texte)) {
1462
-		return $texte;
1463
-	} else {
1464
-		return $sinon;
1465
-	}
1459
+    if ($texte) {
1460
+        return $texte;
1461
+    } elseif (is_scalar($texte) and strlen($texte)) {
1462
+        return $texte;
1463
+    } else {
1464
+        return $sinon;
1465
+    }
1466 1466
 }
1467 1467
 
1468 1468
 /**
@@ -1486,7 +1486,7 @@  discard block
 block discarded – undo
1486 1486
  * @return mixed
1487 1487
  **/
1488 1488
 function choixsivide($a, $vide, $pasvide) {
1489
-	return $a ? $pasvide : $vide;
1489
+    return $a ? $pasvide : $vide;
1490 1490
 }
1491 1491
 
1492 1492
 /**
@@ -1510,7 +1510,7 @@  discard block
 block discarded – undo
1510 1510
  * @return mixed
1511 1511
  **/
1512 1512
 function choixsiegal($a1, $a2, $v, $f) {
1513
-	return ($a1 == $a2) ? $v : $f;
1513
+    return ($a1 == $a2) ? $v : $f;
1514 1514
 }
1515 1515
 
1516 1516
 //
@@ -1529,13 +1529,13 @@  discard block
 block discarded – undo
1529 1529
  * @return string
1530 1530
  **/
1531 1531
 function filtrer_ical($texte) {
1532
-	#include_spip('inc/charsets');
1533
-	$texte = html2unicode($texte);
1534
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1535
-	$texte = preg_replace("/\n/", ' ', $texte);
1536
-	$texte = preg_replace('/,/', '\,', $texte);
1532
+    #include_spip('inc/charsets');
1533
+    $texte = html2unicode($texte);
1534
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1535
+    $texte = preg_replace("/\n/", ' ', $texte);
1536
+    $texte = preg_replace('/,/', '\,', $texte);
1537 1537
 
1538
-	return $texte;
1538
+    return $texte;
1539 1539
 }
1540 1540
 
1541 1541
 
@@ -1560,54 +1560,54 @@  discard block
 block discarded – undo
1560 1560
  * @return string
1561 1561
  **/
1562 1562
 function post_autobr($texte, $delim = "\n_ ") {
1563
-	if (!function_exists('echappe_html')) {
1564
-		include_spip('inc/texte_mini');
1565
-	}
1566
-	$texte = str_replace("\r\n", "\r", $texte);
1567
-	$texte = str_replace("\r", "\n", $texte);
1568
-
1569
-	if (preg_match(",\n+$,", $texte, $fin)) {
1570
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1571
-	} else {
1572
-		$fin = '';
1573
-	}
1574
-
1575
-	$texte = echappe_html($texte, '', true);
1576
-
1577
-	// echapper les modeles
1578
-	if (strpos($texte, '<') !== false) {
1579
-		include_spip('inc/lien');
1580
-		if (defined('_PREG_MODELE')) {
1581
-			$preg_modeles = '@' . _PREG_MODELE . '@imsS';
1582
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1583
-		}
1584
-	}
1585
-
1586
-	$debut = '';
1587
-	$suite = $texte;
1588
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1589
-		$debut .= substr($suite, 0, $t - 1);
1590
-		$suite = substr($suite, $t);
1591
-		$car = substr($suite, 0, 1);
1592
-		if (
1593
-			($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1594
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1595
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1596
-		) {
1597
-			$debut .= $delim;
1598
-		} else {
1599
-			$debut .= "\n";
1600
-		}
1601
-		if (preg_match(",^\n+,", $suite, $regs)) {
1602
-			$debut .= $regs[0];
1603
-			$suite = substr($suite, strlen($regs[0]));
1604
-		}
1605
-	}
1606
-	$texte = $debut . $suite;
1607
-
1608
-	$texte = echappe_retour($texte);
1609
-
1610
-	return $texte . $fin;
1563
+    if (!function_exists('echappe_html')) {
1564
+        include_spip('inc/texte_mini');
1565
+    }
1566
+    $texte = str_replace("\r\n", "\r", $texte);
1567
+    $texte = str_replace("\r", "\n", $texte);
1568
+
1569
+    if (preg_match(",\n+$,", $texte, $fin)) {
1570
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1571
+    } else {
1572
+        $fin = '';
1573
+    }
1574
+
1575
+    $texte = echappe_html($texte, '', true);
1576
+
1577
+    // echapper les modeles
1578
+    if (strpos($texte, '<') !== false) {
1579
+        include_spip('inc/lien');
1580
+        if (defined('_PREG_MODELE')) {
1581
+            $preg_modeles = '@' . _PREG_MODELE . '@imsS';
1582
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1583
+        }
1584
+    }
1585
+
1586
+    $debut = '';
1587
+    $suite = $texte;
1588
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1589
+        $debut .= substr($suite, 0, $t - 1);
1590
+        $suite = substr($suite, $t);
1591
+        $car = substr($suite, 0, 1);
1592
+        if (
1593
+            ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1594
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1595
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1596
+        ) {
1597
+            $debut .= $delim;
1598
+        } else {
1599
+            $debut .= "\n";
1600
+        }
1601
+        if (preg_match(",^\n+,", $suite, $regs)) {
1602
+            $debut .= $regs[0];
1603
+            $suite = substr($suite, strlen($regs[0]));
1604
+        }
1605
+    }
1606
+    $texte = $debut . $suite;
1607
+
1608
+    $texte = echappe_retour($texte);
1609
+
1610
+    return $texte . $fin;
1611 1611
 }
1612 1612
 
1613 1613
 
@@ -1648,47 +1648,47 @@  discard block
 block discarded – undo
1648 1648
  * @return string
1649 1649
  **/
1650 1650
 function extraire_idiome($letexte, $lang = null, $options = []) {
1651
-	static $traduire = false;
1652
-	if (
1653
-		$letexte
1654
-		and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1655
-	) {
1656
-		if (!$traduire) {
1657
-			$traduire = charger_fonction('traduire', 'inc');
1658
-			include_spip('inc/lang');
1659
-		}
1660
-		if (!$lang) {
1661
-			$lang = $GLOBALS['spip_lang'];
1662
-		}
1663
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1664
-		if (is_bool($options)) {
1665
-			$options = ['echappe_span' => $options];
1666
-		}
1667
-		if (!isset($options['echappe_span'])) {
1668
-			$options = array_merge($options, ['echappe_span' => false]);
1669
-		}
1670
-
1671
-		foreach ($regs as $reg) {
1672
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1673
-			$desc = $traduire($cle, $lang, true);
1674
-			$l = $desc->langue;
1675
-			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1676
-			if (strlen($desc->texte)) {
1677
-				$trad = code_echappement($desc->texte, 'idiome', false);
1678
-				if ($l !== $lang) {
1679
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1680
-				}
1681
-				if (lang_dir($l) !== lang_dir($lang)) {
1682
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1683
-				}
1684
-				if (!$options['echappe_span']) {
1685
-					$trad = echappe_retour($trad, 'idiome');
1686
-				}
1687
-				$letexte = str_replace($reg[0], $trad, $letexte);
1688
-			}
1689
-		}
1690
-	}
1691
-	return $letexte;
1651
+    static $traduire = false;
1652
+    if (
1653
+        $letexte
1654
+        and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1655
+    ) {
1656
+        if (!$traduire) {
1657
+            $traduire = charger_fonction('traduire', 'inc');
1658
+            include_spip('inc/lang');
1659
+        }
1660
+        if (!$lang) {
1661
+            $lang = $GLOBALS['spip_lang'];
1662
+        }
1663
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1664
+        if (is_bool($options)) {
1665
+            $options = ['echappe_span' => $options];
1666
+        }
1667
+        if (!isset($options['echappe_span'])) {
1668
+            $options = array_merge($options, ['echappe_span' => false]);
1669
+        }
1670
+
1671
+        foreach ($regs as $reg) {
1672
+            $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1673
+            $desc = $traduire($cle, $lang, true);
1674
+            $l = $desc->langue;
1675
+            // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1676
+            if (strlen($desc->texte)) {
1677
+                $trad = code_echappement($desc->texte, 'idiome', false);
1678
+                if ($l !== $lang) {
1679
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1680
+                }
1681
+                if (lang_dir($l) !== lang_dir($lang)) {
1682
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1683
+                }
1684
+                if (!$options['echappe_span']) {
1685
+                    $trad = echappe_retour($trad, 'idiome');
1686
+                }
1687
+                $letexte = str_replace($reg[0], $trad, $letexte);
1688
+            }
1689
+        }
1690
+    }
1691
+    return $letexte;
1692 1692
 }
1693 1693
 
1694 1694
 /**
@@ -1740,68 +1740,68 @@  discard block
 block discarded – undo
1740 1740
  **/
1741 1741
 function extraire_multi($letexte, $lang = null, $options = []) {
1742 1742
 
1743
-	if (
1744
-		$letexte
1745
-		and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1746
-	) {
1747
-		if (!$lang) {
1748
-			$lang = $GLOBALS['spip_lang'];
1749
-		}
1750
-
1751
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1752
-		if (is_bool($options)) {
1753
-			$options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1754
-		}
1755
-		if (!isset($options['echappe_span'])) {
1756
-			$options = array_merge($options, ['echappe_span' => false]);
1757
-		}
1758
-		if (!isset($options['lang_defaut'])) {
1759
-			$options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1760
-		}
1761
-
1762
-		include_spip('inc/lang');
1763
-		foreach ($regs as $reg) {
1764
-			// chercher la version de la langue courante
1765
-			$trads = extraire_trads($reg[1]);
1766
-			if ($l = approcher_langue($trads, $lang)) {
1767
-				$trad = $trads[$l];
1768
-			} else {
1769
-				if ($options['lang_defaut'] == 'aucune') {
1770
-					$trad = '';
1771
-				} else {
1772
-					// langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1773
-					// ou la premiere dispo
1774
-					// mais typographier le texte selon les regles de celle-ci
1775
-					// Attention aux blocs multi sur plusieurs lignes
1776
-					if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1777
-						$l = key($trads);
1778
-					}
1779
-					$trad = $trads[$l];
1780
-					$typographie = charger_fonction(lang_typo($l), 'typographie');
1781
-					$trad = $typographie($trad);
1782
-					// Tester si on echappe en span ou en div
1783
-					// il ne faut pas echapper en div si propre produit un seul paragraphe
1784
-					include_spip('inc/texte');
1785
-					$trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1786
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1787
-					if ($mode === 'div') {
1788
-						$trad = rtrim($trad) . "\n\n";
1789
-					}
1790
-					$trad = code_echappement($trad, 'multi', false, $mode);
1791
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1792
-					if (lang_dir($l) !== lang_dir($lang)) {
1793
-						$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1794
-					}
1795
-					if (!$options['echappe_span']) {
1796
-						$trad = echappe_retour($trad, 'multi');
1797
-					}
1798
-				}
1799
-			}
1800
-			$letexte = str_replace($reg[0], $trad, $letexte);
1801
-		}
1802
-	}
1803
-
1804
-	return $letexte;
1743
+    if (
1744
+        $letexte
1745
+        and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1746
+    ) {
1747
+        if (!$lang) {
1748
+            $lang = $GLOBALS['spip_lang'];
1749
+        }
1750
+
1751
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1752
+        if (is_bool($options)) {
1753
+            $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1754
+        }
1755
+        if (!isset($options['echappe_span'])) {
1756
+            $options = array_merge($options, ['echappe_span' => false]);
1757
+        }
1758
+        if (!isset($options['lang_defaut'])) {
1759
+            $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1760
+        }
1761
+
1762
+        include_spip('inc/lang');
1763
+        foreach ($regs as $reg) {
1764
+            // chercher la version de la langue courante
1765
+            $trads = extraire_trads($reg[1]);
1766
+            if ($l = approcher_langue($trads, $lang)) {
1767
+                $trad = $trads[$l];
1768
+            } else {
1769
+                if ($options['lang_defaut'] == 'aucune') {
1770
+                    $trad = '';
1771
+                } else {
1772
+                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1773
+                    // ou la premiere dispo
1774
+                    // mais typographier le texte selon les regles de celle-ci
1775
+                    // Attention aux blocs multi sur plusieurs lignes
1776
+                    if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1777
+                        $l = key($trads);
1778
+                    }
1779
+                    $trad = $trads[$l];
1780
+                    $typographie = charger_fonction(lang_typo($l), 'typographie');
1781
+                    $trad = $typographie($trad);
1782
+                    // Tester si on echappe en span ou en div
1783
+                    // il ne faut pas echapper en div si propre produit un seul paragraphe
1784
+                    include_spip('inc/texte');
1785
+                    $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1786
+                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1787
+                    if ($mode === 'div') {
1788
+                        $trad = rtrim($trad) . "\n\n";
1789
+                    }
1790
+                    $trad = code_echappement($trad, 'multi', false, $mode);
1791
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1792
+                    if (lang_dir($l) !== lang_dir($lang)) {
1793
+                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1794
+                    }
1795
+                    if (!$options['echappe_span']) {
1796
+                        $trad = echappe_retour($trad, 'multi');
1797
+                    }
1798
+                }
1799
+            }
1800
+            $letexte = str_replace($reg[0], $trad, $letexte);
1801
+        }
1802
+    }
1803
+
1804
+    return $letexte;
1805 1805
 }
1806 1806
 
1807 1807
 /**
@@ -1817,20 +1817,20 @@  discard block
 block discarded – undo
1817 1817
  *     Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué.
1818 1818
  **/
1819 1819
 function extraire_trads($bloc) {
1820
-	$lang = '';
1820
+    $lang = '';
1821 1821
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1822 1822
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1823
-	while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) {
1824
-		$texte = trim($regs[1]);
1825
-		if ($texte or $lang) {
1826
-			$trads[$lang] = $texte;
1827
-		}
1828
-		$bloc = substr($bloc, strlen($regs[0]));
1829
-		$lang = $regs[2];
1830
-	}
1831
-	$trads[$lang] = $bloc;
1823
+    while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) {
1824
+        $texte = trim($regs[1]);
1825
+        if ($texte or $lang) {
1826
+            $trads[$lang] = $texte;
1827
+        }
1828
+        $bloc = substr($bloc, strlen($regs[0]));
1829
+        $lang = $regs[2];
1830
+    }
1831
+    $trads[$lang] = $bloc;
1832 1832
 
1833
-	return $trads;
1833
+    return $trads;
1834 1834
 }
1835 1835
 
1836 1836
 
@@ -1841,7 +1841,7 @@  discard block
 block discarded – undo
1841 1841
  * @return string L'initiale en majuscule
1842 1842
  */
1843 1843
 function filtre_initiale($nom) {
1844
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1844
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1845 1845
 }
1846 1846
 
1847 1847
 
@@ -1886,33 +1886,33 @@  discard block
 block discarded – undo
1886 1886
  *      - null (interne) : si on empile
1887 1887
  **/
1888 1888
 function unique($donnee, $famille = '', $cpt = false) {
1889
-	static $mem = [];
1890
-	// permettre de vider la pile et de la restaurer
1891
-	// pour le calcul de introduction...
1892
-	if ($famille == '_spip_raz_') {
1893
-		$tmp = $mem;
1894
-		$mem = [];
1895
-
1896
-		return $tmp;
1897
-	} elseif ($famille == '_spip_set_') {
1898
-		$mem = $donnee;
1899
-
1900
-		return;
1901
-	}
1902
-	// eviter une notice
1903
-	if (!isset($mem[$famille])) {
1904
-		$mem[$famille] = [];
1905
-	}
1906
-	if ($cpt) {
1907
-		return count($mem[$famille]);
1908
-	}
1909
-	// eviter une notice
1910
-	if (!isset($mem[$famille][$donnee])) {
1911
-		$mem[$famille][$donnee] = 0;
1912
-	}
1913
-	if (!($mem[$famille][$donnee]++)) {
1914
-		return $donnee;
1915
-	}
1889
+    static $mem = [];
1890
+    // permettre de vider la pile et de la restaurer
1891
+    // pour le calcul de introduction...
1892
+    if ($famille == '_spip_raz_') {
1893
+        $tmp = $mem;
1894
+        $mem = [];
1895
+
1896
+        return $tmp;
1897
+    } elseif ($famille == '_spip_set_') {
1898
+        $mem = $donnee;
1899
+
1900
+        return;
1901
+    }
1902
+    // eviter une notice
1903
+    if (!isset($mem[$famille])) {
1904
+        $mem[$famille] = [];
1905
+    }
1906
+    if ($cpt) {
1907
+        return count($mem[$famille]);
1908
+    }
1909
+    // eviter une notice
1910
+    if (!isset($mem[$famille][$donnee])) {
1911
+        $mem[$famille][$donnee] = 0;
1912
+    }
1913
+    if (!($mem[$famille][$donnee]++)) {
1914
+        return $donnee;
1915
+    }
1916 1916
 }
1917 1917
 
1918 1918
 
@@ -1942,16 +1942,16 @@  discard block
 block discarded – undo
1942 1942
  *     Une des valeurs en fonction du compteur.
1943 1943
  **/
1944 1944
 function alterner($i, ...$args) {
1945
-	// recuperer les arguments (attention fonctions un peu space)
1946
-	$num = count($args);
1945
+    // recuperer les arguments (attention fonctions un peu space)
1946
+    $num = count($args);
1947 1947
 
1948
-	if ($num === 1 && is_array($args[0])) {
1949
-		$args = $args[0];
1950
-		$num = count($args);
1951
-	}
1948
+    if ($num === 1 && is_array($args[0])) {
1949
+        $args = $args[0];
1950
+        $num = count($args);
1951
+    }
1952 1952
 
1953
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1954
-	return $args[(intval($i) - 1) % $num];
1953
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1954
+    return $args[(intval($i) - 1) % $num];
1955 1955
 }
1956 1956
 
1957 1957
 
@@ -1977,51 +1977,51 @@  discard block
 block discarded – undo
1977 1977
  *     - null lorsque l’attribut n’existe pas.
1978 1978
  **/
1979 1979
 function extraire_attribut($balise, $attribut, $complet = false) {
1980
-	if (is_array($balise)) {
1981
-		array_walk(
1982
-			$balise,
1983
-			function (&$a, $key, $t) {
1984
-				$a = extraire_attribut($a, $t);
1985
-			},
1986
-			$attribut
1987
-		);
1988
-
1989
-		return $balise;
1990
-	}
1991
-	if (
1992
-		$balise
1993
-		&& preg_match(
1994
-			',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1995
-			. $attribut
1996
-			. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1997
-			$balise,
1998
-			$r
1999
-		)
2000
-	) {
2001
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
2002
-			$r[4] = substr($r[3], 1, -1);
2003
-			$r[3] = $r[3][0];
2004
-		} elseif ($r[3] !== '') {
2005
-			$r[4] = $r[3];
2006
-			$r[3] = '';
2007
-		} else {
2008
-			$r[4] = trim($r[2]);
2009
-		}
2010
-		$att = $r[4];
2011
-		if (strpos($att, '&#') !== false) {
2012
-			$att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
2013
-		}
2014
-		$att = filtrer_entites($att);
2015
-	} else {
2016
-		$att = null;
2017
-		$r = [];
2018
-	}
2019
-
2020
-	if ($complet) {
2021
-		return [$att, $r];
2022
-	} else {
2023
-		return $att;
2024
-	}
1980
+    if (is_array($balise)) {
1981
+        array_walk(
1982
+            $balise,
1983
+            function (&$a, $key, $t) {
1984
+                $a = extraire_attribut($a, $t);
1985
+            },
1986
+            $attribut
1987
+        );
1988
+
1989
+        return $balise;
1990
+    }
1991
+    if (
1992
+        $balise
1993
+        && preg_match(
1994
+            ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1995
+            . $attribut
1996
+            . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1997
+            $balise,
1998
+            $r
1999
+        )
2000
+    ) {
2001
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
2002
+            $r[4] = substr($r[3], 1, -1);
2003
+            $r[3] = $r[3][0];
2004
+        } elseif ($r[3] !== '') {
2005
+            $r[4] = $r[3];
2006
+            $r[3] = '';
2007
+        } else {
2008
+            $r[4] = trim($r[2]);
2009
+        }
2010
+        $att = $r[4];
2011
+        if (strpos($att, '&#') !== false) {
2012
+            $att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
2013
+        }
2014
+        $att = filtrer_entites($att);
2015
+    } else {
2016
+        $att = null;
2017
+        $r = [];
2018
+    }
2019
+
2020
+    if ($complet) {
2021
+        return [$att, $r];
2022
+    } else {
2023
+        return $att;
2024
+    }
2025 2025
 }
2026 2026
 
2027 2027
 /**
@@ -2053,37 +2053,37 @@  discard block
 block discarded – undo
2053 2053
  *     Code html modifié
2054 2054
  **/
2055 2055
 function inserer_attribut(string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string {
2056
-	// preparer l'attribut
2057
-	// supprimer les &nbsp; etc mais pas les balises html
2058
-	// qui ont un sens dans un attribut value d'un input
2059
-	if ($proteger) {
2060
-		$val = attribut_html($val, false);
2061
-	}
2062
-
2063
-	// echapper les ' pour eviter tout bug
2064
-	$val = str_replace("'", '&#039;', $val);
2065
-	if ($vider and strlen($val) === 0) {
2066
-		$insert = '';
2067
-	} else {
2068
-		$insert = " $attribut='$val'";
2069
-	}
2070
-
2071
-	list($old, $r) = extraire_attribut($balise, $attribut, true);
2072
-
2073
-	if ($old !== null) {
2074
-		// Remplacer l'ancien attribut du meme nom
2075
-		$balise = $r[1] . $insert . $r[5];
2076
-	} else {
2077
-		// preferer une balise " />" (comme <img />)
2078
-		if (preg_match(',/>,', $balise)) {
2079
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2080
-		} // sinon une balise <a ...> ... </a>
2081
-		else {
2082
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2083
-		}
2084
-	}
2085
-
2086
-	return $balise;
2056
+    // preparer l'attribut
2057
+    // supprimer les &nbsp; etc mais pas les balises html
2058
+    // qui ont un sens dans un attribut value d'un input
2059
+    if ($proteger) {
2060
+        $val = attribut_html($val, false);
2061
+    }
2062
+
2063
+    // echapper les ' pour eviter tout bug
2064
+    $val = str_replace("'", '&#039;', $val);
2065
+    if ($vider and strlen($val) === 0) {
2066
+        $insert = '';
2067
+    } else {
2068
+        $insert = " $attribut='$val'";
2069
+    }
2070
+
2071
+    list($old, $r) = extraire_attribut($balise, $attribut, true);
2072
+
2073
+    if ($old !== null) {
2074
+        // Remplacer l'ancien attribut du meme nom
2075
+        $balise = $r[1] . $insert . $r[5];
2076
+    } else {
2077
+        // preferer une balise " />" (comme <img />)
2078
+        if (preg_match(',/>,', $balise)) {
2079
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2080
+        } // sinon une balise <a ...> ... </a>
2081
+        else {
2082
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2083
+        }
2084
+    }
2085
+
2086
+    return $balise;
2087 2087
 }
2088 2088
 
2089 2089
 /**
@@ -2101,7 +2101,7 @@  discard block
 block discarded – undo
2101 2101
  * @return string Code HTML sans l'attribut
2102 2102
  **/
2103 2103
 function vider_attribut(string $balise, string $attribut): string {
2104
-	return inserer_attribut($balise, $attribut, '', false, true);
2104
+    return inserer_attribut($balise, $attribut, '', false, true);
2105 2105
 }
2106 2106
 
2107 2107
 /**
@@ -2113,53 +2113,53 @@  discard block
 block discarded – undo
2113 2113
  * @return string
2114 2114
  */
2115 2115
 function modifier_class($balise, $class, $operation = 'ajouter') {
2116
-	if (is_string($class)) {
2117
-		$class = explode(' ', trim($class));
2118
-	}
2119
-	$class = array_filter($class);
2120
-	$class = array_unique($class);
2121
-	if (!$class) {
2122
-		return $balise;
2123
-	}
2124
-
2125
-	// si la ou les classes ont des caracteres invalides on ne fait rien
2126
-	if (preg_match(',[^\w-],', implode('', $class))) {
2127
-		return $balise;
2128
-	}
2129
-
2130
-	$class_courante = extraire_attribut($balise, 'class');
2131
-	$class_new = $class_courante;
2132
-	foreach ($class as $c) {
2133
-		$is_class_presente = false;
2134
-		if (
2135
-			$class_courante
2136
-			and strpos($class_courante, $c) !== false
2137
-			and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2138
-		) {
2139
-			$is_class_presente = true;
2140
-		}
2141
-		if (
2142
-			in_array($operation, ['ajouter', 'commuter'])
2143
-			and !$is_class_presente
2144
-		) {
2145
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2146
-		} elseif (
2147
-			in_array($operation, ['supprimer', 'commuter'])
2148
-			and $is_class_presente
2149
-		) {
2150
-			$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2151
-		}
2152
-	}
2153
-
2154
-	if ($class_new !== $class_courante) {
2155
-		if (strlen($class_new)) {
2156
-			$balise = inserer_attribut($balise, 'class', $class_new);
2157
-		} elseif ($class_courante) {
2158
-			$balise = vider_attribut($balise, 'class');
2159
-		}
2160
-	}
2161
-
2162
-	return $balise;
2116
+    if (is_string($class)) {
2117
+        $class = explode(' ', trim($class));
2118
+    }
2119
+    $class = array_filter($class);
2120
+    $class = array_unique($class);
2121
+    if (!$class) {
2122
+        return $balise;
2123
+    }
2124
+
2125
+    // si la ou les classes ont des caracteres invalides on ne fait rien
2126
+    if (preg_match(',[^\w-],', implode('', $class))) {
2127
+        return $balise;
2128
+    }
2129
+
2130
+    $class_courante = extraire_attribut($balise, 'class');
2131
+    $class_new = $class_courante;
2132
+    foreach ($class as $c) {
2133
+        $is_class_presente = false;
2134
+        if (
2135
+            $class_courante
2136
+            and strpos($class_courante, $c) !== false
2137
+            and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2138
+        ) {
2139
+            $is_class_presente = true;
2140
+        }
2141
+        if (
2142
+            in_array($operation, ['ajouter', 'commuter'])
2143
+            and !$is_class_presente
2144
+        ) {
2145
+            $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2146
+        } elseif (
2147
+            in_array($operation, ['supprimer', 'commuter'])
2148
+            and $is_class_presente
2149
+        ) {
2150
+            $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2151
+        }
2152
+    }
2153
+
2154
+    if ($class_new !== $class_courante) {
2155
+        if (strlen($class_new)) {
2156
+            $balise = inserer_attribut($balise, 'class', $class_new);
2157
+        } elseif ($class_courante) {
2158
+            $balise = vider_attribut($balise, 'class');
2159
+        }
2160
+    }
2161
+
2162
+    return $balise;
2163 2163
 }
2164 2164
 
2165 2165
 /**
@@ -2169,7 +2169,7 @@  discard block
 block discarded – undo
2169 2169
  * @return string
2170 2170
  */
2171 2171
 function ajouter_class($balise, $class) {
2172
-	return modifier_class($balise, $class, 'ajouter');
2172
+    return modifier_class($balise, $class, 'ajouter');
2173 2173
 }
2174 2174
 
2175 2175
 /**
@@ -2179,7 +2179,7 @@  discard block
 block discarded – undo
2179 2179
  * @return string
2180 2180
  */
2181 2181
 function supprimer_class($balise, $class) {
2182
-	return modifier_class($balise, $class, 'supprimer');
2182
+    return modifier_class($balise, $class, 'supprimer');
2183 2183
 }
2184 2184
 
2185 2185
 /**
@@ -2190,7 +2190,7 @@  discard block
 block discarded – undo
2190 2190
  * @return string
2191 2191
  */
2192 2192
 function commuter_class($balise, $class) {
2193
-	return modifier_class($balise, $class, 'commuter');
2193
+    return modifier_class($balise, $class, 'commuter');
2194 2194
 }
2195 2195
 
2196 2196
 /**
@@ -2201,19 +2201,19 @@  discard block
 block discarded – undo
2201 2201
  * @return string
2202 2202
  */
2203 2203
 function tester_config($id, $mode = '') {
2204
-	include_spip('action/inscrire_auteur');
2204
+    include_spip('action/inscrire_auteur');
2205 2205
 
2206
-	return tester_statut_inscription($mode, $id);
2206
+    return tester_statut_inscription($mode, $id);
2207 2207
 }
2208 2208
 
2209 2209
 //
2210 2210
 // Quelques fonctions de calcul arithmetique
2211 2211
 //
2212 2212
 function floatstr($a) {
2213
- return str_replace(',', '.', (string)floatval($a));
2213
+    return str_replace(',', '.', (string)floatval($a));
2214 2214
 }
2215 2215
 function strize($f, $a, $b) {
2216
- return floatstr($f(floatstr($a), floatstr($b)));
2216
+    return floatstr($f(floatstr($a), floatstr($b)));
2217 2217
 }
2218 2218
 
2219 2219
 /**
@@ -2232,7 +2232,7 @@  discard block
 block discarded – undo
2232 2232
  * @return int $a+$b
2233 2233
  **/
2234 2234
 function plus($a, $b) {
2235
-	return $a + $b;
2235
+    return $a + $b;
2236 2236
 }
2237 2237
 function strplus($a, $b) {
2238 2238
 return strize('plus', $a, $b);
@@ -2253,7 +2253,7 @@  discard block
 block discarded – undo
2253 2253
  * @return int $a-$b
2254 2254
  **/
2255 2255
 function moins($a, $b) {
2256
-	return $a - $b;
2256
+    return $a - $b;
2257 2257
 }
2258 2258
 function strmoins($a, $b) {
2259 2259
 return strize('moins', $a, $b);
@@ -2276,7 +2276,7 @@  discard block
 block discarded – undo
2276 2276
  * @return int $a*$b
2277 2277
  **/
2278 2278
 function mult($a, $b) {
2279
-	return $a * $b;
2279
+    return $a * $b;
2280 2280
 }
2281 2281
 function strmult($a, $b) {
2282 2282
 return strize('mult', $a, $b);
@@ -2299,7 +2299,7 @@  discard block
 block discarded – undo
2299 2299
  * @return int $a/$b (ou 0 si $b est nul)
2300 2300
  **/
2301 2301
 function div($a, $b) {
2302
-	return $b ? $a / $b : 0;
2302
+    return $b ? $a / $b : 0;
2303 2303
 }
2304 2304
 function strdiv($a, $b) {
2305 2305
 return strize('div', $a, $b);
@@ -2323,7 +2323,7 @@  discard block
 block discarded – undo
2323 2323
  * @return int ($nb % $mod) + $add
2324 2324
  **/
2325 2325
 function modulo($nb, $mod, $add = 0) {
2326
-	return ($mod ? $nb % $mod : 0) + $add;
2326
+    return ($mod ? $nb % $mod : 0) + $add;
2327 2327
 }
2328 2328
 
2329 2329
 
@@ -2338,24 +2338,24 @@  discard block
 block discarded – undo
2338 2338
  *      - true sinon
2339 2339
  **/
2340 2340
 function nom_acceptable($nom) {
2341
-	if (!is_string($nom)) {
2342
-		return false;
2343
-	}
2344
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2345
-		define('_TAGS_NOM_AUTEUR', '');
2346
-	}
2347
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2348
-	foreach ($tags_acceptes as $tag) {
2349
-		if (strlen($tag)) {
2350
-			$remp1[] = '<' . trim($tag) . '>';
2351
-			$remp1[] = '</' . trim($tag) . '>';
2352
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2353
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2354
-		}
2355
-	}
2356
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2341
+    if (!is_string($nom)) {
2342
+        return false;
2343
+    }
2344
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2345
+        define('_TAGS_NOM_AUTEUR', '');
2346
+    }
2347
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2348
+    foreach ($tags_acceptes as $tag) {
2349
+        if (strlen($tag)) {
2350
+            $remp1[] = '<' . trim($tag) . '>';
2351
+            $remp1[] = '</' . trim($tag) . '>';
2352
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2353
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2354
+        }
2355
+    }
2356
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2357 2357
 
2358
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2358
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2359 2359
 }
2360 2360
 
2361 2361
 
@@ -2371,14 +2371,14 @@  discard block
 block discarded – undo
2371 2371
  *      - renvoie un tableau si l'entree est un tableau
2372 2372
  **/
2373 2373
 function email_valide($adresses) {
2374
-	if (is_array($adresses)) {
2375
-		$adresses = array_map('email_valide', $adresses);
2376
-		$adresses = array_filter($adresses);
2377
-		return $adresses;
2378
-	}
2374
+    if (is_array($adresses)) {
2375
+        $adresses = array_map('email_valide', $adresses);
2376
+        $adresses = array_filter($adresses);
2377
+        return $adresses;
2378
+    }
2379 2379
 
2380
-	$email_valide = charger_fonction('email_valide', 'inc');
2381
-	return $email_valide($adresses);
2380
+    $email_valide = charger_fonction('email_valide', 'inc');
2381
+    return $email_valide($adresses);
2382 2382
 }
2383 2383
 
2384 2384
 /**
@@ -2392,27 +2392,27 @@  discard block
 block discarded – undo
2392 2392
  * @return string Texte
2393 2393
  **/
2394 2394
 function afficher_enclosures($tags) {
2395
-	$s = [];
2396
-	foreach (extraire_balises($tags, 'a') as $tag) {
2397
-		if (
2398
-			extraire_attribut($tag, 'rel') == 'enclosure'
2399
-			and $t = extraire_attribut($tag, 'href')
2400
-		) {
2401
-			$s[] = preg_replace(
2402
-				',>[^<]+</a>,S',
2403
-				'>'
2404
-				. http_img_pack(
2405
-					'attachment-16.png',
2406
-					$t,
2407
-					'title="' . attribut_html($t) . '"'
2408
-				)
2409
-				. '</a>',
2410
-				$tag
2411
-			);
2412
-		}
2413
-	}
2414
-
2415
-	return join('&nbsp;', $s);
2395
+    $s = [];
2396
+    foreach (extraire_balises($tags, 'a') as $tag) {
2397
+        if (
2398
+            extraire_attribut($tag, 'rel') == 'enclosure'
2399
+            and $t = extraire_attribut($tag, 'href')
2400
+        ) {
2401
+            $s[] = preg_replace(
2402
+                ',>[^<]+</a>,S',
2403
+                '>'
2404
+                . http_img_pack(
2405
+                    'attachment-16.png',
2406
+                    $t,
2407
+                    'title="' . attribut_html($t) . '"'
2408
+                )
2409
+                . '</a>',
2410
+                $tag
2411
+            );
2412
+        }
2413
+    }
2414
+
2415
+    return join('&nbsp;', $s);
2416 2416
 }
2417 2417
 
2418 2418
 /**
@@ -2427,15 +2427,15 @@  discard block
 block discarded – undo
2427 2427
  * @return string Liens trouvés
2428 2428
  **/
2429 2429
 function afficher_tags($tags, $rels = 'tag,directory') {
2430
-	$s = [];
2431
-	foreach (extraire_balises($tags, 'a') as $tag) {
2432
-		$rel = extraire_attribut($tag, 'rel');
2433
-		if (strstr(",$rels,", ",$rel,")) {
2434
-			$s[] = $tag;
2435
-		}
2436
-	}
2430
+    $s = [];
2431
+    foreach (extraire_balises($tags, 'a') as $tag) {
2432
+        $rel = extraire_attribut($tag, 'rel');
2433
+        if (strstr(",$rels,", ",$rel,")) {
2434
+            $s[] = $tag;
2435
+        }
2436
+    }
2437 2437
 
2438
-	return join(', ', $s);
2438
+    return join(', ', $s);
2439 2439
 }
2440 2440
 
2441 2441
 
@@ -2457,21 +2457,21 @@  discard block
 block discarded – undo
2457 2457
  * @return string Tag HTML `<a>` avec microformat.
2458 2458
  **/
2459 2459
 function enclosure2microformat($e) {
2460
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2461
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2462
-	}
2463
-	$type = extraire_attribut($e, 'type');
2464
-	if (!$length = extraire_attribut($e, 'length')) {
2465
-		# <media:content : longeur dans fileSize. On tente.
2466
-		$length = extraire_attribut($e, 'fileSize');
2467
-	}
2468
-	$fichier = basename($url);
2460
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2461
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2462
+    }
2463
+    $type = extraire_attribut($e, 'type');
2464
+    if (!$length = extraire_attribut($e, 'length')) {
2465
+        # <media:content : longeur dans fileSize. On tente.
2466
+        $length = extraire_attribut($e, 'fileSize');
2467
+    }
2468
+    $fichier = basename($url);
2469 2469
 
2470
-	return '<a rel="enclosure"'
2471
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2472
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2473
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2474
-	. '>' . $fichier . '</a>';
2470
+    return '<a rel="enclosure"'
2471
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2472
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2473
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2474
+    . '>' . $fichier . '</a>';
2475 2475
 }
2476 2476
 
2477 2477
 /**
@@ -2489,24 +2489,24 @@  discard block
 block discarded – undo
2489 2489
  * @return string Tags RSS `<enclosure>`.
2490 2490
  **/
2491 2491
 function microformat2enclosure($tags) {
2492
-	$enclosures = [];
2493
-	foreach (extraire_balises($tags, 'a') as $e) {
2494
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2495
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2496
-			$type = extraire_attribut($e, 'type');
2497
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2498
-				$length = intval(extraire_attribut($e, 'length'));
2499
-			} # vieux data
2500
-			$fichier = basename($url);
2501
-			$enclosures[] = '<enclosure'
2502
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2503
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2504
-				. ($length ? ' length="' . $length . '"' : '')
2505
-				. ' />';
2506
-		}
2507
-	}
2492
+    $enclosures = [];
2493
+    foreach (extraire_balises($tags, 'a') as $e) {
2494
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2495
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2496
+            $type = extraire_attribut($e, 'type');
2497
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2498
+                $length = intval(extraire_attribut($e, 'length'));
2499
+            } # vieux data
2500
+            $fichier = basename($url);
2501
+            $enclosures[] = '<enclosure'
2502
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2503
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2504
+                . ($length ? ' length="' . $length . '"' : '')
2505
+                . ' />';
2506
+        }
2507
+    }
2508 2508
 
2509
-	return join("\n", $enclosures);
2509
+    return join("\n", $enclosures);
2510 2510
 }
2511 2511
 
2512 2512
 
@@ -2522,16 +2522,16 @@  discard block
 block discarded – undo
2522 2522
  * @return string Tags RSS Atom `<dc:subject>`.
2523 2523
  **/
2524 2524
 function tags2dcsubject($tags) {
2525
-	$subjects = '';
2526
-	foreach (extraire_balises($tags, 'a') as $e) {
2527
-		if (extraire_attribut($e, 'rel') == 'tag') {
2528
-			$subjects .= '<dc:subject>'
2529
-				. texte_backend(textebrut($e))
2530
-				. '</dc:subject>' . "\n";
2531
-		}
2532
-	}
2525
+    $subjects = '';
2526
+    foreach (extraire_balises($tags, 'a') as $e) {
2527
+        if (extraire_attribut($e, 'rel') == 'tag') {
2528
+            $subjects .= '<dc:subject>'
2529
+                . texte_backend(textebrut($e))
2530
+                . '</dc:subject>' . "\n";
2531
+        }
2532
+    }
2533 2533
 
2534
-	return $subjects;
2534
+    return $subjects;
2535 2535
 }
2536 2536
 
2537 2537
 /**
@@ -2560,27 +2560,27 @@  discard block
 block discarded – undo
2560 2560
  *     - Tableau de résultats, si tableau en entrée.
2561 2561
  **/
2562 2562
 function extraire_balise($texte, $tag = 'a') {
2563
-	if (is_array($texte)) {
2564
-		array_walk(
2565
-			$texte,
2566
-			function (&$a, $key, $t) {
2567
-				$a = extraire_balise($a, $t);
2568
-			},
2569
-			$tag
2570
-		);
2571
-
2572
-		return $texte;
2573
-	}
2574
-
2575
-	if (
2576
-		preg_match(
2577
-			",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2578
-			$texte,
2579
-			$regs
2580
-		)
2581
-	) {
2582
-		return $regs[0];
2583
-	}
2563
+    if (is_array($texte)) {
2564
+        array_walk(
2565
+            $texte,
2566
+            function (&$a, $key, $t) {
2567
+                $a = extraire_balise($a, $t);
2568
+            },
2569
+            $tag
2570
+        );
2571
+
2572
+        return $texte;
2573
+    }
2574
+
2575
+    if (
2576
+        preg_match(
2577
+            ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2578
+            $texte,
2579
+            $regs
2580
+        )
2581
+    ) {
2582
+        return $regs[0];
2583
+    }
2584 2584
 }
2585 2585
 
2586 2586
 /**
@@ -2608,30 +2608,30 @@  discard block
 block discarded – undo
2608 2608
  *     - Tableau de résultats, si tableau en entrée.
2609 2609
  **/
2610 2610
 function extraire_balises($texte, $tag = 'a') {
2611
-	if (is_array($texte)) {
2612
-		array_walk(
2613
-			$texte,
2614
-			function (&$a, $key, $t) {
2615
-				$a = extraire_balises($a, $t);
2616
-			},
2617
-			$tag
2618
-		);
2619
-
2620
-		return $texte;
2621
-	}
2622
-
2623
-	if (
2624
-		preg_match_all(
2625
-			",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2626
-			$texte,
2627
-			$regs,
2628
-			PREG_PATTERN_ORDER
2629
-		)
2630
-	) {
2631
-		return $regs[0];
2632
-	} else {
2633
-		return [];
2634
-	}
2611
+    if (is_array($texte)) {
2612
+        array_walk(
2613
+            $texte,
2614
+            function (&$a, $key, $t) {
2615
+                $a = extraire_balises($a, $t);
2616
+            },
2617
+            $tag
2618
+        );
2619
+
2620
+        return $texte;
2621
+    }
2622
+
2623
+    if (
2624
+        preg_match_all(
2625
+            ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2626
+            $texte,
2627
+            $regs,
2628
+            PREG_PATTERN_ORDER
2629
+        )
2630
+    ) {
2631
+        return $regs[0];
2632
+    } else {
2633
+        return [];
2634
+    }
2635 2635
 }
2636 2636
 
2637 2637
 /**
@@ -2660,11 +2660,11 @@  discard block
 block discarded – undo
2660 2660
  *     - `$def` si on n'a pas transmis de tableau
2661 2661
  **/
2662 2662
 function in_any($val, $vals, $def = '') {
2663
-	if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2664
-		$vals = $v;
2665
-	}
2663
+    if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2664
+        $vals = $v;
2665
+    }
2666 2666
 
2667
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2667
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2668 2668
 }
2669 2669
 
2670 2670
 
@@ -2685,12 +2685,12 @@  discard block
 block discarded – undo
2685 2685
  *     Résultat du calcul
2686 2686
  **/
2687 2687
 function valeur_numerique($expr) {
2688
-	$a = 0;
2689
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2690
-		eval("\$a = $expr;");
2691
-	}
2688
+    $a = 0;
2689
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2690
+        eval("\$a = $expr;");
2691
+    }
2692 2692
 
2693
-	return intval($a);
2693
+    return intval($a);
2694 2694
 }
2695 2695
 
2696 2696
 /**
@@ -2709,7 +2709,7 @@  discard block
 block discarded – undo
2709 2709
  *      Retourne `$a*$b/$c`
2710 2710
  **/
2711 2711
 function regledetrois($a, $b, $c) {
2712
-	return round($a * $b / $c);
2712
+    return round($a * $b / $c);
2713 2713
 }
2714 2714
 
2715 2715
 
@@ -2733,77 +2733,77 @@  discard block
 block discarded – undo
2733 2733
  **/
2734 2734
 function form_hidden($action) {
2735 2735
 
2736
-	$contexte = [];
2737
-	include_spip('inc/urls');
2738
-	if (
2739
-		$p = urls_decoder_url($action, '')
2740
-		and reset($p)
2741
-	) {
2742
-		$fond = array_shift($p);
2743
-		if ($fond != '404') {
2744
-			$contexte = array_shift($p);
2745
-			$contexte['page'] = $fond;
2746
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2747
-		}
2748
-	}
2749
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2750
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2751
-		unset($contexte['type']);
2752
-	}
2753
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2754
-		unset($contexte['type-page']);
2755
-	}
2756
-
2757
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2758
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2759
-	$values = [];
2760
-
2761
-	// d'abord avec celles de l'url
2762
-	if (false !== ($p = strpos($action, '?'))) {
2763
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2764
-			$c = explode('=', $c, 2);
2765
-			$var = array_shift($c);
2766
-			$val = array_shift($c);
2767
-			if ($var) {
2768
-				$val = rawurldecode($val);
2769
-				$var = rawurldecode($var); // decoder les [] eventuels
2770
-				if (preg_match(',\[\]$,S', $var)) {
2771
-					$values[] = [$var, $val];
2772
-				} else {
2773
-					if (!isset($values[$var])) {
2774
-						$values[$var] = [$var, $val];
2775
-					}
2776
-				}
2777
-			}
2778
-		}
2779
-	}
2780
-
2781
-	// ensuite avec celles du contexte, sans doublonner !
2782
-	foreach ($contexte as $var => $val) {
2783
-		if (preg_match(',\[\]$,S', $var)) {
2784
-			$values[] = [$var, $val];
2785
-		} else {
2786
-			if (!isset($values[$var])) {
2787
-				$values[$var] = [$var, $val];
2788
-			}
2789
-		}
2790
-	}
2791
-
2792
-	// puis on rassemble le tout
2793
-	$hidden = [];
2794
-	foreach ($values as $value) {
2795
-		list($var, $val) = $value;
2796
-		$hidden[] = '<input name="'
2797
-			. entites_html($var)
2798
-			. '"'
2799
-			. (is_null($val)
2800
-				? ''
2801
-				: ' value="' . entites_html($val) . '"'
2802
-			)
2803
-			. ' type="hidden"' . "\n/>";
2804
-	}
2805
-
2806
-	return join('', $hidden);
2736
+    $contexte = [];
2737
+    include_spip('inc/urls');
2738
+    if (
2739
+        $p = urls_decoder_url($action, '')
2740
+        and reset($p)
2741
+    ) {
2742
+        $fond = array_shift($p);
2743
+        if ($fond != '404') {
2744
+            $contexte = array_shift($p);
2745
+            $contexte['page'] = $fond;
2746
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2747
+        }
2748
+    }
2749
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2750
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2751
+        unset($contexte['type']);
2752
+    }
2753
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2754
+        unset($contexte['type-page']);
2755
+    }
2756
+
2757
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2758
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2759
+    $values = [];
2760
+
2761
+    // d'abord avec celles de l'url
2762
+    if (false !== ($p = strpos($action, '?'))) {
2763
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2764
+            $c = explode('=', $c, 2);
2765
+            $var = array_shift($c);
2766
+            $val = array_shift($c);
2767
+            if ($var) {
2768
+                $val = rawurldecode($val);
2769
+                $var = rawurldecode($var); // decoder les [] eventuels
2770
+                if (preg_match(',\[\]$,S', $var)) {
2771
+                    $values[] = [$var, $val];
2772
+                } else {
2773
+                    if (!isset($values[$var])) {
2774
+                        $values[$var] = [$var, $val];
2775
+                    }
2776
+                }
2777
+            }
2778
+        }
2779
+    }
2780
+
2781
+    // ensuite avec celles du contexte, sans doublonner !
2782
+    foreach ($contexte as $var => $val) {
2783
+        if (preg_match(',\[\]$,S', $var)) {
2784
+            $values[] = [$var, $val];
2785
+        } else {
2786
+            if (!isset($values[$var])) {
2787
+                $values[$var] = [$var, $val];
2788
+            }
2789
+        }
2790
+    }
2791
+
2792
+    // puis on rassemble le tout
2793
+    $hidden = [];
2794
+    foreach ($values as $value) {
2795
+        list($var, $val) = $value;
2796
+        $hidden[] = '<input name="'
2797
+            . entites_html($var)
2798
+            . '"'
2799
+            . (is_null($val)
2800
+                ? ''
2801
+                : ' value="' . entites_html($val) . '"'
2802
+            )
2803
+            . ' type="hidden"' . "\n/>";
2804
+    }
2805
+
2806
+    return join('', $hidden);
2807 2807
 }
2808 2808
 
2809 2809
 
@@ -2825,7 +2825,7 @@  discard block
 block discarded – undo
2825 2825
  *    - la première valeur du tableau sinon.
2826 2826
  **/
2827 2827
 function filtre_reset($array) {
2828
-	return !is_array($array) ? null : reset($array);
2828
+    return !is_array($array) ? null : reset($array);
2829 2829
 }
2830 2830
 
2831 2831
 /**
@@ -2846,7 +2846,7 @@  discard block
 block discarded – undo
2846 2846
  *    - la dernière valeur du tableau sinon.
2847 2847
  **/
2848 2848
 function filtre_end($array) {
2849
-	return !is_array($array) ? null : end($array);
2849
+    return !is_array($array) ? null : end($array);
2850 2850
 }
2851 2851
 
2852 2852
 /**
@@ -2866,11 +2866,11 @@  discard block
 block discarded – undo
2866 2866
  *
2867 2867
  **/
2868 2868
 function filtre_push($array, $val) {
2869
-	if (!is_array($array) or !array_push($array, $val)) {
2870
-		return '';
2871
-	}
2869
+    if (!is_array($array) or !array_push($array, $val)) {
2870
+        return '';
2871
+    }
2872 2872
 
2873
-	return $array;
2873
+    return $array;
2874 2874
 }
2875 2875
 
2876 2876
 /**
@@ -2889,7 +2889,7 @@  discard block
 block discarded – undo
2889 2889
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2890 2890
  **/
2891 2891
 function filtre_find($array, $val) {
2892
-	return (is_array($array) and in_array($val, $array));
2892
+    return (is_array($array) and in_array($val, $array));
2893 2893
 }
2894 2894
 
2895 2895
 
@@ -2906,15 +2906,15 @@  discard block
 block discarded – undo
2906 2906
  *     Contenu avec urls en absolus
2907 2907
  **/
2908 2908
 function urls_absolues_css($contenu, $source) {
2909
-	$path = suivre_lien(url_absolue($source), './');
2909
+    $path = suivre_lien(url_absolue($source), './');
2910 2910
 
2911
-	return preg_replace_callback(
2912
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2913
-		function ($x) use ($path) {
2914
-			return "url('" . suivre_lien($path, $x[1]) . "')";
2915
-		},
2916
-		$contenu
2917
-	);
2911
+    return preg_replace_callback(
2912
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2913
+        function ($x) use ($path) {
2914
+            return "url('" . suivre_lien($path, $x[1]) . "')";
2915
+        },
2916
+        $contenu
2917
+    );
2918 2918
 }
2919 2919
 
2920 2920
 
@@ -2943,119 +2943,119 @@  discard block
 block discarded – undo
2943 2943
  *     Chemin du fichier CSS inversé
2944 2944
  **/
2945 2945
 function direction_css($css, $voulue = '') {
2946
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2947
-		return $css;
2948
-	}
2949
-	include_spip('inc/lang');
2950
-	// si on a precise le sens voulu en argument, le prendre en compte
2951
-	if ($voulue = strtolower($voulue)) {
2952
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2953
-			$voulue = lang_dir($voulue);
2954
-		}
2955
-	} else {
2956
-		$voulue = lang_dir();
2957
-	}
2958
-
2959
-	$r = count($r) > 1;
2960
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2961
-	$dir = $r ? 'rtl' : 'ltr';
2962
-	$ndir = $r ? 'ltr' : 'rtl';
2963
-
2964
-	if ($voulue == $dir) {
2965
-		return $css;
2966
-	}
2967
-
2968
-	if (
2969
-		// url absolue
2970
-		preg_match(',^https?:,i', $css)
2971
-		// ou qui contient un ?
2972
-		or (($p = strpos($css, '?')) !== false)
2973
-	) {
2974
-		$distant = true;
2975
-		$cssf = parse_url($css);
2976
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2977
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2978
-	} else {
2979
-		$distant = false;
2980
-		$cssf = $css;
2981
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2982
-		//propose (rien a faire dans ce cas)
2983
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2984
-		if (@file_exists($f)) {
2985
-			return $f;
2986
-		}
2987
-	}
2988
-
2989
-	// 2.
2990
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2991
-	$f = $dir_var
2992
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2993
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2994
-
2995
-	// la css peut etre distante (url absolue !)
2996
-	if ($distant) {
2997
-		include_spip('inc/distant');
2998
-		$res = recuperer_url($css);
2999
-		if (!$res or !$contenu = $res['page']) {
3000
-			return $css;
3001
-		}
3002
-	} else {
3003
-		if (
3004
-			(@filemtime($f) > @filemtime($css))
3005
-			and (_VAR_MODE != 'recalcul')
3006
-		) {
3007
-			return $f;
3008
-		}
3009
-		if (!lire_fichier($css, $contenu)) {
3010
-			return $css;
3011
-		}
3012
-	}
3013
-
3014
-
3015
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3016
-	include_spip('lib/csstidy/class.csstidy');
3017
-	$parser = new csstidy();
3018
-	$parser->set_cfg('optimise_shorthands', 0);
3019
-	$parser->set_cfg('reverse_left_and_right', true);
3020
-	$parser->parse($contenu);
3021
-
3022
-	$contenu = $parser->print->plain();
3023
-
3024
-
3025
-	// reperer les @import auxquels il faut propager le direction_css
3026
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3027
-	$src = [];
3028
-	$src_direction_css = [];
3029
-	$src_faux_abs = [];
3030
-	$d = dirname($css);
3031
-	foreach ($regs[1] as $k => $import_css) {
3032
-		$css_direction = direction_css("$d/$import_css", $voulue);
3033
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3034
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3035
-			$css_direction = substr($css_direction, strlen($d) + 1);
3036
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
3037
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3038
-			$css_direction = substr($css_direction, strlen($dir_var));
3039
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3040
-			$css_direction = '/@@@@@@/' . $css_direction;
3041
-		}
3042
-		$src[] = $regs[0][$k];
3043
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3044
-	}
3045
-	$contenu = str_replace($src, $src_direction_css, $contenu);
3046
-
3047
-	$contenu = urls_absolues_css($contenu, $css);
3048
-
3049
-	// virer les fausses url absolues que l'on a mis dans les import
3050
-	if (count($src_faux_abs)) {
3051
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3052
-	}
3053
-
3054
-	if (!ecrire_fichier($f, $contenu)) {
3055
-		return $css;
3056
-	}
3057
-
3058
-	return $f;
2946
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2947
+        return $css;
2948
+    }
2949
+    include_spip('inc/lang');
2950
+    // si on a precise le sens voulu en argument, le prendre en compte
2951
+    if ($voulue = strtolower($voulue)) {
2952
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2953
+            $voulue = lang_dir($voulue);
2954
+        }
2955
+    } else {
2956
+        $voulue = lang_dir();
2957
+    }
2958
+
2959
+    $r = count($r) > 1;
2960
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2961
+    $dir = $r ? 'rtl' : 'ltr';
2962
+    $ndir = $r ? 'ltr' : 'rtl';
2963
+
2964
+    if ($voulue == $dir) {
2965
+        return $css;
2966
+    }
2967
+
2968
+    if (
2969
+        // url absolue
2970
+        preg_match(',^https?:,i', $css)
2971
+        // ou qui contient un ?
2972
+        or (($p = strpos($css, '?')) !== false)
2973
+    ) {
2974
+        $distant = true;
2975
+        $cssf = parse_url($css);
2976
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2977
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
2978
+    } else {
2979
+        $distant = false;
2980
+        $cssf = $css;
2981
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2982
+        //propose (rien a faire dans ce cas)
2983
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2984
+        if (@file_exists($f)) {
2985
+            return $f;
2986
+        }
2987
+    }
2988
+
2989
+    // 2.
2990
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2991
+    $f = $dir_var
2992
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2993
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2994
+
2995
+    // la css peut etre distante (url absolue !)
2996
+    if ($distant) {
2997
+        include_spip('inc/distant');
2998
+        $res = recuperer_url($css);
2999
+        if (!$res or !$contenu = $res['page']) {
3000
+            return $css;
3001
+        }
3002
+    } else {
3003
+        if (
3004
+            (@filemtime($f) > @filemtime($css))
3005
+            and (_VAR_MODE != 'recalcul')
3006
+        ) {
3007
+            return $f;
3008
+        }
3009
+        if (!lire_fichier($css, $contenu)) {
3010
+            return $css;
3011
+        }
3012
+    }
3013
+
3014
+
3015
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3016
+    include_spip('lib/csstidy/class.csstidy');
3017
+    $parser = new csstidy();
3018
+    $parser->set_cfg('optimise_shorthands', 0);
3019
+    $parser->set_cfg('reverse_left_and_right', true);
3020
+    $parser->parse($contenu);
3021
+
3022
+    $contenu = $parser->print->plain();
3023
+
3024
+
3025
+    // reperer les @import auxquels il faut propager le direction_css
3026
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3027
+    $src = [];
3028
+    $src_direction_css = [];
3029
+    $src_faux_abs = [];
3030
+    $d = dirname($css);
3031
+    foreach ($regs[1] as $k => $import_css) {
3032
+        $css_direction = direction_css("$d/$import_css", $voulue);
3033
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3034
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3035
+            $css_direction = substr($css_direction, strlen($d) + 1);
3036
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
3037
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3038
+            $css_direction = substr($css_direction, strlen($dir_var));
3039
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3040
+            $css_direction = '/@@@@@@/' . $css_direction;
3041
+        }
3042
+        $src[] = $regs[0][$k];
3043
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3044
+    }
3045
+    $contenu = str_replace($src, $src_direction_css, $contenu);
3046
+
3047
+    $contenu = urls_absolues_css($contenu, $css);
3048
+
3049
+    // virer les fausses url absolues que l'on a mis dans les import
3050
+    if (count($src_faux_abs)) {
3051
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3052
+    }
3053
+
3054
+    if (!ecrire_fichier($f, $contenu)) {
3055
+        return $css;
3056
+    }
3057
+
3058
+    return $f;
3059 3059
 }
3060 3060
 
3061 3061
 
@@ -3078,46 +3078,46 @@  discard block
 block discarded – undo
3078 3078
  *     - Chemin ou URL du fichier CSS source sinon.
3079 3079
  **/
3080 3080
 function url_absolue_css($css) {
3081
-	if (!preg_match(',\.css$,i', $css, $r)) {
3082
-		return $css;
3083
-	}
3081
+    if (!preg_match(',\.css$,i', $css, $r)) {
3082
+        return $css;
3083
+    }
3084 3084
 
3085
-	$url_absolue_css = url_absolue($css);
3085
+    $url_absolue_css = url_absolue($css);
3086 3086
 
3087
-	$f = basename($css, '.css');
3088
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3089
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3090
-		. '.css';
3087
+    $f = basename($css, '.css');
3088
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3089
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3090
+        . '.css';
3091 3091
 
3092
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3093
-		return $f;
3094
-	}
3092
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3093
+        return $f;
3094
+    }
3095 3095
 
3096
-	if ($url_absolue_css == $css) {
3097
-		if (
3098
-			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3099
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3100
-		) {
3101
-			include_spip('inc/distant');
3102
-			$contenu = recuperer_url($css);
3103
-			$contenu = $contenu['page'] ?? '';
3104
-			if (!$contenu) {
3105
-				return $css;
3106
-			}
3107
-		}
3108
-	} elseif (!lire_fichier($css, $contenu)) {
3109
-		return $css;
3110
-	}
3096
+    if ($url_absolue_css == $css) {
3097
+        if (
3098
+            strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3099
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3100
+        ) {
3101
+            include_spip('inc/distant');
3102
+            $contenu = recuperer_url($css);
3103
+            $contenu = $contenu['page'] ?? '';
3104
+            if (!$contenu) {
3105
+                return $css;
3106
+            }
3107
+        }
3108
+    } elseif (!lire_fichier($css, $contenu)) {
3109
+        return $css;
3110
+    }
3111 3111
 
3112
-	// passer les url relatives a la css d'origine en url absolues
3113
-	$contenu = urls_absolues_css($contenu, $css);
3112
+    // passer les url relatives a la css d'origine en url absolues
3113
+    $contenu = urls_absolues_css($contenu, $css);
3114 3114
 
3115
-	// ecrire la css
3116
-	if (!ecrire_fichier($f, $contenu)) {
3117
-		return $css;
3118
-	}
3115
+    // ecrire la css
3116
+    if (!ecrire_fichier($f, $contenu)) {
3117
+        return $css;
3118
+    }
3119 3119
 
3120
-	return $f;
3120
+    return $f;
3121 3121
 }
3122 3122
 
3123 3123
 
@@ -3151,24 +3151,24 @@  discard block
 block discarded – undo
3151 3151
  *     Valeur trouvée ou valeur par défaut.
3152 3152
  **/
3153 3153
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3154
-	foreach (explode('/', $cle) as $k) {
3155
-		$table = (is_string($table) ? @unserialize($table) : $table);
3154
+    foreach (explode('/', $cle) as $k) {
3155
+        $table = (is_string($table) ? @unserialize($table) : $table);
3156 3156
 
3157
-		if (is_object($table)) {
3158
-			$table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3159
-		} elseif (is_array($table)) {
3160
-			if ($conserver_null) {
3161
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3162
-			} else {
3163
-				$table = ($table[$k] ?? $defaut);
3164
-			}
3165
-		} else {
3166
-			$table = $defaut;
3167
-			break;
3168
-		}
3169
-	}
3157
+        if (is_object($table)) {
3158
+            $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3159
+        } elseif (is_array($table)) {
3160
+            if ($conserver_null) {
3161
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3162
+            } else {
3163
+                $table = ($table[$k] ?? $defaut);
3164
+            }
3165
+        } else {
3166
+            $table = $defaut;
3167
+            break;
3168
+        }
3169
+    }
3170 3170
 
3171
-	return $table;
3171
+    return $table;
3172 3172
 }
3173 3173
 
3174 3174
 /**
@@ -3201,22 +3201,22 @@  discard block
 block discarded – undo
3201 3201
  *     - string : expression trouvée.
3202 3202
  **/
3203 3203
 function filtre_match_dist(?string $texte, $expression, $modif = 'UimsS', $capte = 0) {
3204
-	if (intval($modif) and $capte == 0) {
3205
-		$capte = $modif;
3206
-		$modif = 'UimsS';
3207
-	}
3208
-	$expression = str_replace('\/', '/', $expression);
3209
-	$expression = str_replace('/', '\/', $expression);
3204
+    if (intval($modif) and $capte == 0) {
3205
+        $capte = $modif;
3206
+        $modif = 'UimsS';
3207
+    }
3208
+    $expression = str_replace('\/', '/', $expression);
3209
+    $expression = str_replace('/', '\/', $expression);
3210 3210
 
3211
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3212
-		if (isset($r[$capte])) {
3213
-			return $r[$capte];
3214
-		} else {
3215
-			return true;
3216
-		}
3217
-	}
3211
+    if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3212
+        if (isset($r[$capte])) {
3213
+            return $r[$capte];
3214
+        } else {
3215
+            return true;
3216
+        }
3217
+    }
3218 3218
 
3219
-	return false;
3219
+    return false;
3220 3220
 }
3221 3221
 
3222 3222
 
@@ -3243,10 +3243,10 @@  discard block
 block discarded – undo
3243 3243
  *     Texte
3244 3244
  **/
3245 3245
 function replace($texte, $expression, $replace = '', $modif = 'UimsS') {
3246
-	$expression = str_replace('\/', '/', $expression);
3247
-	$expression = str_replace('/', '\/', $expression);
3246
+    $expression = str_replace('\/', '/', $expression);
3247
+    $expression = str_replace('/', '\/', $expression);
3248 3248
 
3249
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3249
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3250 3250
 }
3251 3251
 
3252 3252
 
@@ -3264,25 +3264,25 @@  discard block
 block discarded – undo
3264 3264
  **/
3265 3265
 function traiter_doublons_documents(&$doublons, $letexte) {
3266 3266
 
3267
-	// Verifier dans le texte & les notes (pas beau, helas)
3268
-	$t = $letexte . $GLOBALS['les_notes'];
3267
+    // Verifier dans le texte & les notes (pas beau, helas)
3268
+    $t = $letexte . $GLOBALS['les_notes'];
3269 3269
 
3270
-	if (
3271
-		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3272
-		and preg_match_all(
3273
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3274
-			$t,
3275
-			$matches,
3276
-			PREG_PATTERN_ORDER
3277
-		)
3278
-	) {
3279
-		if (!isset($doublons['documents'])) {
3280
-			$doublons['documents'] = '';
3281
-		}
3282
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3283
-	}
3270
+    if (
3271
+        strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3272
+        and preg_match_all(
3273
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3274
+            $t,
3275
+            $matches,
3276
+            PREG_PATTERN_ORDER
3277
+        )
3278
+    ) {
3279
+        if (!isset($doublons['documents'])) {
3280
+            $doublons['documents'] = '';
3281
+        }
3282
+        $doublons['documents'] .= ',' . join(',', $matches[1]);
3283
+    }
3284 3284
 
3285
-	return $letexte;
3285
+    return $letexte;
3286 3286
 }
3287 3287
 
3288 3288
 /**
@@ -3296,7 +3296,7 @@  discard block
 block discarded – undo
3296 3296
  * @return string Chaîne vide
3297 3297
  **/
3298 3298
 function vide($texte) {
3299
-	return '';
3299
+    return '';
3300 3300
 }
3301 3301
 
3302 3302
 //
@@ -3325,23 +3325,23 @@  discard block
 block discarded – undo
3325 3325
  *      Code HTML résultant
3326 3326
  **/
3327 3327
 function env_to_params($env, $ignore_params = []) {
3328
-	$ignore_params = array_merge(
3329
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3330
-		$ignore_params
3331
-	);
3332
-	if (!is_array($env)) {
3333
-		$env = unserialize($env);
3334
-	}
3335
-	$texte = '';
3336
-	if ($env) {
3337
-		foreach ($env as $i => $j) {
3338
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3339
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3340
-			}
3341
-		}
3342
-	}
3343
-
3344
-	return $texte;
3328
+    $ignore_params = array_merge(
3329
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3330
+        $ignore_params
3331
+    );
3332
+    if (!is_array($env)) {
3333
+        $env = unserialize($env);
3334
+    }
3335
+    $texte = '';
3336
+    if ($env) {
3337
+        foreach ($env as $i => $j) {
3338
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3339
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3340
+            }
3341
+        }
3342
+    }
3343
+
3344
+    return $texte;
3345 3345
 }
3346 3346
 
3347 3347
 /**
@@ -3364,23 +3364,23 @@  discard block
 block discarded – undo
3364 3364
  *      Code HTML résultant
3365 3365
  **/
3366 3366
 function env_to_attributs($env, $ignore_params = []) {
3367
-	$ignore_params = array_merge(
3368
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3369
-		$ignore_params
3370
-	);
3371
-	if (!is_array($env)) {
3372
-		$env = unserialize($env);
3373
-	}
3374
-	$texte = '';
3375
-	if ($env) {
3376
-		foreach ($env as $i => $j) {
3377
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3378
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3379
-			}
3380
-		}
3381
-	}
3367
+    $ignore_params = array_merge(
3368
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3369
+        $ignore_params
3370
+    );
3371
+    if (!is_array($env)) {
3372
+        $env = unserialize($env);
3373
+    }
3374
+    $texte = '';
3375
+    if ($env) {
3376
+        foreach ($env as $i => $j) {
3377
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3378
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3379
+            }
3380
+        }
3381
+    }
3382 3382
 
3383
-	return $texte;
3383
+    return $texte;
3384 3384
 }
3385 3385
 
3386 3386
 
@@ -3398,7 +3398,7 @@  discard block
 block discarded – undo
3398 3398
  * @return string Chaînes concaténés
3399 3399
  **/
3400 3400
 function concat(...$args): string {
3401
-	return join('', $args);
3401
+    return join('', $args);
3402 3402
 }
3403 3403
 
3404 3404
 
@@ -3418,23 +3418,23 @@  discard block
 block discarded – undo
3418 3418
  *     Contenu du ou des fichiers, concaténé
3419 3419
  **/
3420 3420
 function charge_scripts($files, $script = true) {
3421
-	$flux = '';
3422
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3423
-		if (!is_string($file)) {
3424
-			continue;
3425
-		}
3426
-		if ($script) {
3427
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3428
-		}
3429
-		if ($file) {
3430
-			$path = find_in_path($file);
3431
-			if ($path) {
3432
-				$flux .= spip_file_get_contents($path);
3433
-			}
3434
-		}
3435
-	}
3436
-
3437
-	return $flux;
3421
+    $flux = '';
3422
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3423
+        if (!is_string($file)) {
3424
+            continue;
3425
+        }
3426
+        if ($script) {
3427
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3428
+        }
3429
+        if ($file) {
3430
+            $path = find_in_path($file);
3431
+            if ($path) {
3432
+                $flux .= spip_file_get_contents($path);
3433
+            }
3434
+        }
3435
+    }
3436
+
3437
+    return $flux;
3438 3438
 }
3439 3439
 
3440 3440
 /**
@@ -3445,22 +3445,22 @@  discard block
 block discarded – undo
3445 3445
  * @return string
3446 3446
  */
3447 3447
 function http_img_variante_svg_si_possible($img_file) {
3448
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3449
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3450
-	if (
3451
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3452
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3453
-		and file_exists($variante_svg_generique)
3454
-	) {
3455
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3456
-			$img_file = $variante_svg_size;
3457
-		}
3458
-		else {
3459
-			$img_file = $variante_svg_generique;
3460
-		}
3461
-	}
3448
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3449
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3450
+    if (
3451
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3452
+        and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3453
+        and file_exists($variante_svg_generique)
3454
+    ) {
3455
+        if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3456
+            $img_file = $variante_svg_size;
3457
+        }
3458
+        else {
3459
+            $img_file = $variante_svg_generique;
3460
+        }
3461
+    }
3462 3462
 
3463
-	return $img_file;
3463
+    return $img_file;
3464 3464
 }
3465 3465
 
3466 3466
 /**
@@ -3481,54 +3481,54 @@  discard block
 block discarded – undo
3481 3481
  */
3482 3482
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3483 3483
 
3484
-	$img_file = $img;
3485
-	if ($p = strpos($img_file, '?')) {
3486
-		$img_file = substr($img_file, 0, $p);
3487
-	}
3488
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3489
-		$img_file = chemin_image($img);
3490
-	}
3491
-	else {
3492
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3493
-			$img_file = http_img_variante_svg_si_possible($img_file);
3494
-		}
3495
-	}
3496
-	if (stripos($atts, 'width') === false) {
3497
-		// utiliser directement l'info de taille presente dans le nom
3498
-		if (
3499
-			(!isset($options['utiliser_suffixe_size'])
3500
-				or $options['utiliser_suffixe_size'] == true
3501
-			  or strpos($img_file, '-xx.svg') !== false)
3502
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3503
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3504
-		) {
3505
-			$largeur = $hauteur = intval($regs[1]);
3506
-		} else {
3507
-			$taille = taille_image($img_file);
3508
-			list($hauteur, $largeur) = $taille;
3509
-			if (!$hauteur or !$largeur) {
3510
-				return '';
3511
-			}
3512
-		}
3513
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3514
-	}
3515
-
3516
-	if (file_exists($img_file)) {
3517
-		$img_file = timestamp($img_file);
3518
-	}
3519
-	if ($alt === false) {
3520
-		$alt = '';
3521
-	}
3522
-	elseif ($alt or $alt === '') {
3523
-		$alt = " alt='" . attribut_html($alt) . "'";
3524
-	}
3525
-	else {
3526
-		$alt = " alt='" . attribut_html($title) . "'";
3527
-	}
3528
-	return "<img src='$img_file'$alt"
3529
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3530
-	. ' ' . ltrim($atts)
3531
-	. ' />';
3484
+    $img_file = $img;
3485
+    if ($p = strpos($img_file, '?')) {
3486
+        $img_file = substr($img_file, 0, $p);
3487
+    }
3488
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3489
+        $img_file = chemin_image($img);
3490
+    }
3491
+    else {
3492
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3493
+            $img_file = http_img_variante_svg_si_possible($img_file);
3494
+        }
3495
+    }
3496
+    if (stripos($atts, 'width') === false) {
3497
+        // utiliser directement l'info de taille presente dans le nom
3498
+        if (
3499
+            (!isset($options['utiliser_suffixe_size'])
3500
+                or $options['utiliser_suffixe_size'] == true
3501
+              or strpos($img_file, '-xx.svg') !== false)
3502
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3503
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3504
+        ) {
3505
+            $largeur = $hauteur = intval($regs[1]);
3506
+        } else {
3507
+            $taille = taille_image($img_file);
3508
+            list($hauteur, $largeur) = $taille;
3509
+            if (!$hauteur or !$largeur) {
3510
+                return '';
3511
+            }
3512
+        }
3513
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3514
+    }
3515
+
3516
+    if (file_exists($img_file)) {
3517
+        $img_file = timestamp($img_file);
3518
+    }
3519
+    if ($alt === false) {
3520
+        $alt = '';
3521
+    }
3522
+    elseif ($alt or $alt === '') {
3523
+        $alt = " alt='" . attribut_html($alt) . "'";
3524
+    }
3525
+    else {
3526
+        $alt = " alt='" . attribut_html($title) . "'";
3527
+    }
3528
+    return "<img src='$img_file'$alt"
3529
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3530
+    . ' ' . ltrim($atts)
3531
+    . ' />';
3532 3532
 }
3533 3533
 
3534 3534
 /**
@@ -3540,70 +3540,70 @@  discard block
 block discarded – undo
3540 3540
  * @return string
3541 3541
  */
3542 3542
 function http_style_background($img, $att = '', $size = null) {
3543
-	if ($size and is_numeric($size)) {
3544
-		$size = trim($size) . 'px';
3545
-	}
3546
-	return " style='background" .
3547
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3548
-		. ($size ? "background-size:{$size};" : '')
3549
-		. "'";
3543
+    if ($size and is_numeric($size)) {
3544
+        $size = trim($size) . 'px';
3545
+    }
3546
+    return " style='background" .
3547
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3548
+        . ($size ? "background-size:{$size};" : '')
3549
+        . "'";
3550 3550
 }
3551 3551
 
3552 3552
 
3553 3553
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3554
-	$args = [$alt_or_size, $class_or_size, $size];
3555
-	while (is_null(end($args)) and count($args)) {
3556
-		array_pop($args);
3557
-	}
3558
-	if (!count($args)) {
3559
-		return [null, null, null];
3560
-	}
3561
-	if (count($args) < 3) {
3562
-		$maybe_size = array_pop($args);
3563
-		// @2x
3564
-		// @1.5x
3565
-		// 512
3566
-		// 512x*
3567
-		// 512x300
3568
-		if (
3569
-			!strlen($maybe_size)
3570
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3571
-		) {
3572
-			$args[] = $maybe_size;
3573
-			$maybe_size = null;
3574
-		}
3575
-		while (count($args) < 2) {
3576
-			$args[] = null; // default alt or class
3577
-		}
3578
-		$args[] = $maybe_size;
3579
-	}
3580
-	return $args;
3554
+    $args = [$alt_or_size, $class_or_size, $size];
3555
+    while (is_null(end($args)) and count($args)) {
3556
+        array_pop($args);
3557
+    }
3558
+    if (!count($args)) {
3559
+        return [null, null, null];
3560
+    }
3561
+    if (count($args) < 3) {
3562
+        $maybe_size = array_pop($args);
3563
+        // @2x
3564
+        // @1.5x
3565
+        // 512
3566
+        // 512x*
3567
+        // 512x300
3568
+        if (
3569
+            !strlen($maybe_size)
3570
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3571
+        ) {
3572
+            $args[] = $maybe_size;
3573
+            $maybe_size = null;
3574
+        }
3575
+        while (count($args) < 2) {
3576
+            $args[] = null; // default alt or class
3577
+        }
3578
+        $args[] = $maybe_size;
3579
+    }
3580
+    return $args;
3581 3581
 }
3582 3582
 
3583 3583
 function helper_filtre_balise_img_svg_size($img, $size) {
3584
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3585
-	if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3586
-		$coef = floatval(substr($size, 1, -1));
3587
-		list($h, $w) = taille_image($img);
3588
-		$height = intval(round($h / $coef));
3589
-		$width = intval(round($w / $coef));
3590
-	}
3591
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3592
-	else {
3593
-		$size = explode('x', $size, 2);
3594
-		$size = array_map('trim', $size);
3595
-		$height = $width = intval(array_shift($size));
3596
-
3597
-		if (count($size) and reset($size)) {
3598
-			$height = array_shift($size);
3599
-			if ($height === '*') {
3600
-				list($h, $w) = taille_image($img);
3601
-				$height = intval(round($h * $width / $w));
3602
-			}
3603
-		}
3604
-	}
3605
-
3606
-	return [$width, $height];
3584
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3585
+    if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3586
+        $coef = floatval(substr($size, 1, -1));
3587
+        list($h, $w) = taille_image($img);
3588
+        $height = intval(round($h / $coef));
3589
+        $width = intval(round($w / $coef));
3590
+    }
3591
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3592
+    else {
3593
+        $size = explode('x', $size, 2);
3594
+        $size = array_map('trim', $size);
3595
+        $height = $width = intval(array_shift($size));
3596
+
3597
+        if (count($size) and reset($size)) {
3598
+            $height = array_shift($size);
3599
+            if ($height === '*') {
3600
+                list($h, $w) = taille_image($img);
3601
+                $height = intval(round($h * $width / $w));
3602
+            }
3603
+        }
3604
+    }
3605
+
3606
+    return [$width, $height];
3607 3607
 }
3608 3608
 
3609 3609
 /**
@@ -3639,43 +3639,43 @@  discard block
 block discarded – undo
3639 3639
  */
3640 3640
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3641 3641
 
3642
-	list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3643
-
3644
-	$img = trim($img);
3645
-	if (strpos($img, '<img') === 0) {
3646
-		if (!is_null($alt)) {
3647
-			$img = inserer_attribut($img, 'alt', $alt);
3648
-		}
3649
-		if (!is_null($class)) {
3650
-			if (strlen($class)) {
3651
-				$img = inserer_attribut($img, 'class', $class);
3652
-			}
3653
-			else {
3654
-				$img = vider_attribut($img, 'class');
3655
-			}
3656
-		}
3657
-	}
3658
-	else {
3659
-		$img = http_img_pack(
3660
-			$img,
3661
-			$alt,
3662
-			$class ? " class='" . attribut_html($class) . "'" : '',
3663
-			'',
3664
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3665
-		);
3666
-		if (is_null($alt)) {
3667
-			$img = vider_attribut($img, 'alt');
3668
-		}
3669
-	}
3670
-
3671
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3672
-		list($width, $height) = helper_filtre_balise_img_svg_size($img, $size);
3673
-
3674
-		$img = inserer_attribut($img, 'width', $width);
3675
-		$img = inserer_attribut($img, 'height', $height);
3676
-	}
3677
-
3678
-	return $img;
3642
+    list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3643
+
3644
+    $img = trim($img);
3645
+    if (strpos($img, '<img') === 0) {
3646
+        if (!is_null($alt)) {
3647
+            $img = inserer_attribut($img, 'alt', $alt);
3648
+        }
3649
+        if (!is_null($class)) {
3650
+            if (strlen($class)) {
3651
+                $img = inserer_attribut($img, 'class', $class);
3652
+            }
3653
+            else {
3654
+                $img = vider_attribut($img, 'class');
3655
+            }
3656
+        }
3657
+    }
3658
+    else {
3659
+        $img = http_img_pack(
3660
+            $img,
3661
+            $alt,
3662
+            $class ? " class='" . attribut_html($class) . "'" : '',
3663
+            '',
3664
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3665
+        );
3666
+        if (is_null($alt)) {
3667
+            $img = vider_attribut($img, 'alt');
3668
+        }
3669
+    }
3670
+
3671
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3672
+        list($width, $height) = helper_filtre_balise_img_svg_size($img, $size);
3673
+
3674
+        $img = inserer_attribut($img, 'width', $width);
3675
+        $img = inserer_attribut($img, 'height', $height);
3676
+    }
3677
+
3678
+    return $img;
3679 3679
 }
3680 3680
 
3681 3681
 
@@ -3709,79 +3709,79 @@  discard block
 block discarded – undo
3709 3709
  */
3710 3710
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3711 3711
 
3712
-	$img = trim($img);
3713
-	$img_file = $img;
3714
-	if (strpos($img, '<svg') === false) {
3715
-		if ($p = strpos($img_file, '?')) {
3716
-			$img_file = substr($img_file, 0, $p);
3717
-		}
3712
+    $img = trim($img);
3713
+    $img_file = $img;
3714
+    if (strpos($img, '<svg') === false) {
3715
+        if ($p = strpos($img_file, '?')) {
3716
+            $img_file = substr($img_file, 0, $p);
3717
+        }
3718 3718
 
3719
-		// ne jamais operer directement sur une image distante pour des raisons de perfo
3720
-		// la copie locale a toutes les chances d'etre la ou de resservir
3721
-		if (tester_url_absolue($img_file)) {
3722
-			include_spip('inc/distant');
3723
-			$fichier = copie_locale($img_file);
3724
-			$img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3725
-		}
3719
+        // ne jamais operer directement sur une image distante pour des raisons de perfo
3720
+        // la copie locale a toutes les chances d'etre la ou de resservir
3721
+        if (tester_url_absolue($img_file)) {
3722
+            include_spip('inc/distant');
3723
+            $fichier = copie_locale($img_file);
3724
+            $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3725
+        }
3726 3726
 
3727
-		if (
3728
-			!$img_file
3729
-			or !file_exists($img_file)
3730
-			or !$svg = file_get_contents($img_file)
3731
-		) {
3732
-			return '';
3733
-		}
3734
-	}
3727
+        if (
3728
+            !$img_file
3729
+            or !file_exists($img_file)
3730
+            or !$svg = file_get_contents($img_file)
3731
+        ) {
3732
+            return '';
3733
+        }
3734
+    }
3735 3735
 
3736
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3737
-		return '';
3738
-	}
3736
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3737
+        return '';
3738
+    }
3739 3739
 
3740
-	list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3740
+    list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3741 3741
 
3742
-	$balise_svg = $match[0];
3743
-	$balise_svg_source = $balise_svg;
3742
+    $balise_svg = $match[0];
3743
+    $balise_svg_source = $balise_svg;
3744 3744
 
3745
-	// entete XML à supprimer
3746
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3745
+    // entete XML à supprimer
3746
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3747 3747
 
3748
-	// IE est toujours mon ami
3749
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3748
+    // IE est toujours mon ami
3749
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3750 3750
 
3751
-	// regler la classe
3752
-	if (!is_null($class)) {
3753
-		if (strlen($class)) {
3754
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3755
-		}
3756
-		else {
3757
-			$balise_svg = vider_attribut($balise_svg, 'class');
3758
-		}
3759
-	}
3751
+    // regler la classe
3752
+    if (!is_null($class)) {
3753
+        if (strlen($class)) {
3754
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3755
+        }
3756
+        else {
3757
+            $balise_svg = vider_attribut($balise_svg, 'class');
3758
+        }
3759
+    }
3760 3760
 
3761
-	// regler le alt
3762
-	if ($alt) {
3763
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3764
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3765
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3766
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3767
-		$balise_svg .= $title;
3768
-	}
3769
-	else {
3770
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3771
-	}
3761
+    // regler le alt
3762
+    if ($alt) {
3763
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3764
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3765
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3766
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3767
+        $balise_svg .= $title;
3768
+    }
3769
+    else {
3770
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3771
+    }
3772 3772
 
3773
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3773
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3774 3774
 
3775
-	if (!is_null($size) and strlen($size = trim($size))) {
3776
-		list($width, $height) = helper_filtre_balise_img_svg_size($svg, $size);
3775
+    if (!is_null($size) and strlen($size = trim($size))) {
3776
+        list($width, $height) = helper_filtre_balise_img_svg_size($svg, $size);
3777 3777
 
3778
-		if (!function_exists('svg_redimensionner')) {
3779
-			include_spip('inc/svg');
3780
-		}
3781
-		$svg = svg_redimensionner($svg, $width, $height);
3782
-	}
3778
+        if (!function_exists('svg_redimensionner')) {
3779
+            include_spip('inc/svg');
3780
+        }
3781
+        $svg = svg_redimensionner($svg, $width, $height);
3782
+    }
3783 3783
 
3784
-	return $svg;
3784
+    return $svg;
3785 3785
 }
3786 3786
 
3787 3787
 
@@ -3807,18 +3807,18 @@  discard block
 block discarded – undo
3807 3807
  *     Code HTML résultant
3808 3808
  **/
3809 3809
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3810
-	$texte = '';
3811
-	if (is_array($tableau)) {
3812
-		foreach ($tableau as $k => $v) {
3813
-			$res = recuperer_fond(
3814
-				'modeles/' . $modele,
3815
-				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3816
-			);
3817
-			$texte .= $res;
3818
-		}
3819
-	}
3810
+    $texte = '';
3811
+    if (is_array($tableau)) {
3812
+        foreach ($tableau as $k => $v) {
3813
+            $res = recuperer_fond(
3814
+                'modeles/' . $modele,
3815
+                array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3816
+            );
3817
+            $texte .= $res;
3818
+        }
3819
+    }
3820 3820
 
3821
-	return $texte;
3821
+    return $texte;
3822 3822
 }
3823 3823
 
3824 3824
 
@@ -3843,37 +3843,37 @@  discard block
 block discarded – undo
3843 3843
  *         - tout : retourne toutes les informations du plugin actif
3844 3844
  **/
3845 3845
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3846
-	include_spip('inc/plugin');
3847
-	$plugin = strtoupper($plugin);
3848
-	$plugins_actifs = liste_plugin_actifs();
3849
-
3850
-	if (!$plugin) {
3851
-		return serialize(array_keys($plugins_actifs));
3852
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3853
-		return '';
3854
-	} elseif (($type_info == 'est_actif') and !$reload) {
3855
-		return $plugins_actifs[$plugin] ? 1 : 0;
3856
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3857
-		return $plugins_actifs[$plugin][$type_info];
3858
-	} else {
3859
-		$get_infos = charger_fonction('get_infos', 'plugins');
3860
-		// On prend en compte les extensions
3861
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3862
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3863
-		} else {
3864
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3865
-		}
3866
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3867
-			return '';
3868
-		}
3869
-		if ($type_info == 'tout') {
3870
-			return $infos;
3871
-		} elseif ($type_info == 'est_actif') {
3872
-			return $infos ? 1 : 0;
3873
-		} else {
3874
-			return strval($infos[$type_info]);
3875
-		}
3876
-	}
3846
+    include_spip('inc/plugin');
3847
+    $plugin = strtoupper($plugin);
3848
+    $plugins_actifs = liste_plugin_actifs();
3849
+
3850
+    if (!$plugin) {
3851
+        return serialize(array_keys($plugins_actifs));
3852
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3853
+        return '';
3854
+    } elseif (($type_info == 'est_actif') and !$reload) {
3855
+        return $plugins_actifs[$plugin] ? 1 : 0;
3856
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3857
+        return $plugins_actifs[$plugin][$type_info];
3858
+    } else {
3859
+        $get_infos = charger_fonction('get_infos', 'plugins');
3860
+        // On prend en compte les extensions
3861
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3862
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3863
+        } else {
3864
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3865
+        }
3866
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3867
+            return '';
3868
+        }
3869
+        if ($type_info == 'tout') {
3870
+            return $infos;
3871
+        } elseif ($type_info == 'est_actif') {
3872
+            return $infos ? 1 : 0;
3873
+        } else {
3874
+            return strval($infos[$type_info]);
3875
+        }
3876
+    }
3877 3877
 }
3878 3878
 
3879 3879
 
@@ -3900,9 +3900,9 @@  discard block
 block discarded – undo
3900 3900
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3901 3901
  */
3902 3902
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3903
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3903
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3904 3904
 
3905
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3905
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3906 3906
 }
3907 3907
 
3908 3908
 
@@ -3932,19 +3932,19 @@  discard block
 block discarded – undo
3932 3932
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3933 3933
  */
3934 3934
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3935
-	static $puce_statut = null;
3936
-	if (!$puce_statut) {
3937
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3938
-	}
3935
+    static $puce_statut = null;
3936
+    if (!$puce_statut) {
3937
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3938
+    }
3939 3939
 
3940
-	return $puce_statut(
3941
-		$id_objet,
3942
-		$statut,
3943
-		$id_parent,
3944
-		$objet,
3945
-		false,
3946
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3947
-	);
3940
+    return $puce_statut(
3941
+        $id_objet,
3942
+        $statut,
3943
+        $id_parent,
3944
+        $objet,
3945
+        false,
3946
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3947
+    );
3948 3948
 }
3949 3949
 
3950 3950
 
@@ -3971,97 +3971,97 @@  discard block
 block discarded – undo
3971 3971
  *   hash du contexte
3972 3972
  */
3973 3973
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3974
-	if (
3975
-		is_string($c)
3976
-		and @unserialize($c) !== false
3977
-	) {
3978
-		$c = unserialize($c);
3979
-	}
3980
-
3981
-	// supprimer les parametres debut_x
3982
-	// pour que la pagination ajax ne soit pas plantee
3983
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3984
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3985
-	if (is_array($c)) {
3986
-		foreach ($c as $k => $v) {
3987
-			if (strpos($k, 'debut_') === 0) {
3988
-				unset($c[$k]);
3989
-			}
3990
-		}
3991
-	}
3992
-
3993
-	if (!function_exists('calculer_cle_action')) {
3994
-		include_spip('inc/securiser_action');
3995
-	}
3996
-
3997
-	$c = serialize($c);
3998
-	$cle = calculer_cle_action($form . $c);
3999
-	$c = "$cle:$c";
4000
-
4001
-	// on ne stocke pas les contextes dans des fichiers en cache
4002
-	// par defaut, sauf si cette configuration a été forcée
4003
-	// OU que la longueur de l’argument géneré est plus long
4004
-	// que ce qui est toléré.
4005
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
4006
-	if (!$cache_contextes_ajax) {
4007
-		$env = $c;
4008
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4009
-			$env = gzdeflate($env);
4010
-		}
4011
-		$env = _xor($env);
4012
-		$env = base64_encode($env);
4013
-		$len = strlen($env);
4014
-		// Si l’url est trop longue pour le navigateur
4015
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
4016
-		if ($len > $max_len) {
4017
-			$cache_contextes_ajax = true;
4018
-			spip_log(
4019
-				'Contextes AJAX forces en fichiers !'
4020
-				. ' Cela arrive lorsque la valeur du contexte'
4021
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
4022
-				_LOG_AVERTISSEMENT
4023
-			);
4024
-		}
4025
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4026
-		elseif (
4027
-			$max_len = @ini_get('suhosin.get.max_value_length')
4028
-			and $max_len < $len
4029
-		) {
4030
-			$cache_contextes_ajax = true;
4031
-			spip_log('Contextes AJAX forces en fichiers !'
4032
-				. ' Cela arrive lorsque la valeur du contexte'
4033
-				. ' depasse la longueur maximale autorisee par Suhosin'
4034
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4035
-				. ' Vous devriez modifier les parametres de Suhosin'
4036
-				. ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4037
-		}
4038
-	}
4039
-
4040
-	if ($cache_contextes_ajax) {
4041
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
4042
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
4043
-		$md5 = md5($c);
4044
-		ecrire_fichier("$dir/c$md5", $c);
4045
-		$env = $md5;
4046
-	}
4047
-
4048
-	if ($emboite === null) {
4049
-		return $env;
4050
-	}
4051
-	if (!trim($emboite)) {
4052
-		return '';
4053
-	}
4054
-	// toujours encoder l'url source dans le bloc ajax
4055
-	$r = self();
4056
-	$r = ' data-origin="' . $r . '"';
4057
-	$class = 'ajaxbloc';
4058
-	if ($ajaxid and is_string($ajaxid)) {
4059
-		// ajaxid est normalement conforme a un nom de classe css
4060
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4061
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4062
-	}
4063
-
4064
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3974
+    if (
3975
+        is_string($c)
3976
+        and @unserialize($c) !== false
3977
+    ) {
3978
+        $c = unserialize($c);
3979
+    }
3980
+
3981
+    // supprimer les parametres debut_x
3982
+    // pour que la pagination ajax ne soit pas plantee
3983
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3984
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3985
+    if (is_array($c)) {
3986
+        foreach ($c as $k => $v) {
3987
+            if (strpos($k, 'debut_') === 0) {
3988
+                unset($c[$k]);
3989
+            }
3990
+        }
3991
+    }
3992
+
3993
+    if (!function_exists('calculer_cle_action')) {
3994
+        include_spip('inc/securiser_action');
3995
+    }
3996
+
3997
+    $c = serialize($c);
3998
+    $cle = calculer_cle_action($form . $c);
3999
+    $c = "$cle:$c";
4000
+
4001
+    // on ne stocke pas les contextes dans des fichiers en cache
4002
+    // par defaut, sauf si cette configuration a été forcée
4003
+    // OU que la longueur de l’argument géneré est plus long
4004
+    // que ce qui est toléré.
4005
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
4006
+    if (!$cache_contextes_ajax) {
4007
+        $env = $c;
4008
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4009
+            $env = gzdeflate($env);
4010
+        }
4011
+        $env = _xor($env);
4012
+        $env = base64_encode($env);
4013
+        $len = strlen($env);
4014
+        // Si l’url est trop longue pour le navigateur
4015
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
4016
+        if ($len > $max_len) {
4017
+            $cache_contextes_ajax = true;
4018
+            spip_log(
4019
+                'Contextes AJAX forces en fichiers !'
4020
+                . ' Cela arrive lorsque la valeur du contexte'
4021
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
4022
+                _LOG_AVERTISSEMENT
4023
+            );
4024
+        }
4025
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4026
+        elseif (
4027
+            $max_len = @ini_get('suhosin.get.max_value_length')
4028
+            and $max_len < $len
4029
+        ) {
4030
+            $cache_contextes_ajax = true;
4031
+            spip_log('Contextes AJAX forces en fichiers !'
4032
+                . ' Cela arrive lorsque la valeur du contexte'
4033
+                . ' depasse la longueur maximale autorisee par Suhosin'
4034
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4035
+                . ' Vous devriez modifier les parametres de Suhosin'
4036
+                . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4037
+        }
4038
+    }
4039
+
4040
+    if ($cache_contextes_ajax) {
4041
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
4042
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
4043
+        $md5 = md5($c);
4044
+        ecrire_fichier("$dir/c$md5", $c);
4045
+        $env = $md5;
4046
+    }
4047
+
4048
+    if ($emboite === null) {
4049
+        return $env;
4050
+    }
4051
+    if (!trim($emboite)) {
4052
+        return '';
4053
+    }
4054
+    // toujours encoder l'url source dans le bloc ajax
4055
+    $r = self();
4056
+    $r = ' data-origin="' . $r . '"';
4057
+    $class = 'ajaxbloc';
4058
+    if ($ajaxid and is_string($ajaxid)) {
4059
+        // ajaxid est normalement conforme a un nom de classe css
4060
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4061
+        $class .= ' ajax-id-' . entites_html($ajaxid);
4062
+    }
4063
+
4064
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4065 4065
 }
4066 4066
 
4067 4067
 /**
@@ -4081,37 +4081,37 @@  discard block
 block discarded – undo
4081 4081
  *   - false : erreur de décodage
4082 4082
  */
4083 4083
 function decoder_contexte_ajax($c, $form = '') {
4084
-	if (!function_exists('calculer_cle_action')) {
4085
-		include_spip('inc/securiser_action');
4086
-	}
4087
-	if (
4088
-		((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4089
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4090
-		and lire_fichier("$dir/c$c", $contexte)
4091
-	) {
4092
-		$c = $contexte;
4093
-	} else {
4094
-		$c = @base64_decode($c);
4095
-		$c = _xor($c);
4096
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4097
-			$c = @gzinflate($c);
4098
-		}
4099
-	}
4100
-
4101
-	// extraire la signature en debut de contexte
4102
-	// et la verifier avant de deserializer
4103
-	// format : signature:donneesserializees
4104
-	if ($p = strpos($c, ':')) {
4105
-		$cle = substr($c, 0, $p);
4106
-		$c = substr($c, $p + 1);
4107
-
4108
-		if ($cle == calculer_cle_action($form . $c)) {
4109
-			$env = @unserialize($c);
4110
-			return $env;
4111
-		}
4112
-	}
4113
-
4114
-	return false;
4084
+    if (!function_exists('calculer_cle_action')) {
4085
+        include_spip('inc/securiser_action');
4086
+    }
4087
+    if (
4088
+        ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4089
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4090
+        and lire_fichier("$dir/c$c", $contexte)
4091
+    ) {
4092
+        $c = $contexte;
4093
+    } else {
4094
+        $c = @base64_decode($c);
4095
+        $c = _xor($c);
4096
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4097
+            $c = @gzinflate($c);
4098
+        }
4099
+    }
4100
+
4101
+    // extraire la signature en debut de contexte
4102
+    // et la verifier avant de deserializer
4103
+    // format : signature:donneesserializees
4104
+    if ($p = strpos($c, ':')) {
4105
+        $cle = substr($c, 0, $p);
4106
+        $c = substr($c, $p + 1);
4107
+
4108
+        if ($cle == calculer_cle_action($form . $c)) {
4109
+            $env = @unserialize($c);
4110
+            return $env;
4111
+        }
4112
+    }
4113
+
4114
+    return false;
4115 4115
 }
4116 4116
 
4117 4117
 
@@ -4129,20 +4129,20 @@  discard block
 block discarded – undo
4129 4129
  *    Message décrypté ou encrypté
4130 4130
  **/
4131 4131
 function _xor($message, $key = null) {
4132
-	if (is_null($key)) {
4133
-		if (!function_exists('calculer_cle_action')) {
4134
-			include_spip('inc/securiser_action');
4135
-		}
4136
-		$key = pack('H*', calculer_cle_action('_xor'));
4137
-	}
4132
+    if (is_null($key)) {
4133
+        if (!function_exists('calculer_cle_action')) {
4134
+            include_spip('inc/securiser_action');
4135
+        }
4136
+        $key = pack('H*', calculer_cle_action('_xor'));
4137
+    }
4138 4138
 
4139
-	$keylen = strlen($key);
4140
-	$messagelen = strlen($message);
4141
-	for ($i = 0; $i < $messagelen; $i++) {
4142
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4143
-	}
4139
+    $keylen = strlen($key);
4140
+    $messagelen = strlen($message);
4141
+    for ($i = 0; $i < $messagelen; $i++) {
4142
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4143
+    }
4144 4144
 
4145
-	return $message;
4145
+    return $message;
4146 4146
 }
4147 4147
 
4148 4148
 /**
@@ -4156,7 +4156,7 @@  discard block
 block discarded – undo
4156 4156
  * @return string
4157 4157
  */
4158 4158
 function url_reponse_forum($texte) {
4159
- return $texte;
4159
+    return $texte;
4160 4160
 }
4161 4161
 
4162 4162
 /**
@@ -4170,7 +4170,7 @@  discard block
 block discarded – undo
4170 4170
  * @return string
4171 4171
  */
4172 4172
 function url_rss_forum($texte) {
4173
- return $texte;
4173
+    return $texte;
4174 4174
 }
4175 4175
 
4176 4176
 
@@ -4209,37 +4209,37 @@  discard block
 block discarded – undo
4209 4209
  *   Code HTML
4210 4210
  */
4211 4211
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4212
-	if ($on) {
4213
-		$bal = 'strong';
4214
-		$class = '';
4215
-		$att = '';
4216
-		// si $on passe la balise et optionnelement une ou ++classe
4217
-		// a.active span.selected.active etc....
4218
-		if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4219
-			$on = explode('.', $on);
4220
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4221
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4222
-				$bal = array_shift($on);
4223
-				$class = implode(' ', $on);
4224
-				if ($bal == 'a') {
4225
-					$att = 'href="#" ';
4226
-				}
4227
-			}
4228
-		}
4229
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4230
-	} else {
4231
-		$bal = 'a';
4232
-		$att = "href='$url'"
4233
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4234
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4235
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4236
-			. $evt;
4237
-	}
4238
-	if ($libelle === null) {
4239
-		$libelle = $url;
4240
-	}
4241
-
4242
-	return "<$bal $att>$libelle</$bal>";
4212
+    if ($on) {
4213
+        $bal = 'strong';
4214
+        $class = '';
4215
+        $att = '';
4216
+        // si $on passe la balise et optionnelement une ou ++classe
4217
+        // a.active span.selected.active etc....
4218
+        if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4219
+            $on = explode('.', $on);
4220
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4221
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4222
+                $bal = array_shift($on);
4223
+                $class = implode(' ', $on);
4224
+                if ($bal == 'a') {
4225
+                    $att = 'href="#" ';
4226
+                }
4227
+            }
4228
+        }
4229
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4230
+    } else {
4231
+        $bal = 'a';
4232
+        $att = "href='$url'"
4233
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4234
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4235
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4236
+            . $evt;
4237
+    }
4238
+    if ($libelle === null) {
4239
+        $libelle = $url;
4240
+    }
4241
+
4242
+    return "<$bal $att>$libelle</$bal>";
4243 4243
 }
4244 4244
 
4245 4245
 
@@ -4256,39 +4256,39 @@  discard block
 block discarded – undo
4256 4256
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4257 4257
  */
4258 4258
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4259
-	static $local_singulier_ou_pluriel = [];
4260
-
4261
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4262
-	if (!is_numeric($nb) or $nb == 0) {
4263
-		return '';
4264
-	}
4265
-	if (!is_array($vars)) {
4266
-		return '';
4267
-	}
4268
-
4269
-	$langue = $GLOBALS['spip_lang'];
4270
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4271
-		$local_singulier_ou_pluriel[$langue] = false;
4272
-		if (
4273
-			$f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4274
-			or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4275
-		) {
4276
-			$local_singulier_ou_pluriel[$langue] = $f;
4277
-		}
4278
-	}
4279
-
4280
-	// si on a une surcharge on l'utilise
4281
-	if ($local_singulier_ou_pluriel[$langue]) {
4282
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4283
-	}
4284
-
4285
-	// sinon traitement par defaut
4286
-	$vars[$var] = $nb;
4287
-	if ($nb >= 2) {
4288
-		return _T($chaine_plusieurs, $vars);
4289
-	} else {
4290
-		return _T($chaine_un, $vars);
4291
-	}
4259
+    static $local_singulier_ou_pluriel = [];
4260
+
4261
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4262
+    if (!is_numeric($nb) or $nb == 0) {
4263
+        return '';
4264
+    }
4265
+    if (!is_array($vars)) {
4266
+        return '';
4267
+    }
4268
+
4269
+    $langue = $GLOBALS['spip_lang'];
4270
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4271
+        $local_singulier_ou_pluriel[$langue] = false;
4272
+        if (
4273
+            $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4274
+            or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4275
+        ) {
4276
+            $local_singulier_ou_pluriel[$langue] = $f;
4277
+        }
4278
+    }
4279
+
4280
+    // si on a une surcharge on l'utilise
4281
+    if ($local_singulier_ou_pluriel[$langue]) {
4282
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4283
+    }
4284
+
4285
+    // sinon traitement par defaut
4286
+    $vars[$var] = $nb;
4287
+    if ($nb >= 2) {
4288
+        return _T($chaine_plusieurs, $vars);
4289
+    } else {
4290
+        return _T($chaine_un, $vars);
4291
+    }
4292 4292
 }
4293 4293
 
4294 4294
 
@@ -4316,73 +4316,73 @@  discard block
 block discarded – undo
4316 4316
  */
4317 4317
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4318 4318
 
4319
-	$class_lien = $class_bouton = $class;
4320
-
4321
-	// Normaliser la fonction et compléter la classe en fonction
4322
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4323
-		$class_lien .= ' danger';
4324
-		$class_bouton .= ' btn_danger';
4325
-	} elseif ($fonction == 'rien.gif') {
4326
-		$fonction = '';
4327
-	} elseif ($fonction == 'delsafe') {
4328
-		$fonction = 'del';
4329
-	}
4330
-
4331
-	$fond_origine = $fond;
4332
-	// Remappage des icone : article-24.png+new => article-new-24.png
4333
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4334
-		list($fond, $fonction) = $icone_renommer($fond, $fonction);
4335
-	}
4336
-
4337
-	// Ajouter le type d'objet dans la classe
4338
-	$objet_type = substr(basename($fond), 0, -4);
4339
-	$class_lien .= " $objet_type";
4340
-	$class_bouton .= " $objet_type";
4341
-
4342
-	// Texte
4343
-	$alt = attribut_html($texte);
4344
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4345
-
4346
-	// Liens : préparer les classes ajax
4347
-	$ajax = '';
4348
-	if ($type === 'lien') {
4349
-		if (strpos($class_lien, 'ajax') !== false) {
4350
-			$ajax = 'ajax';
4351
-			if (strpos($class_lien, 'preload') !== false) {
4352
-				$ajax .= ' preload';
4353
-			}
4354
-			if (strpos($class_lien, 'nocache') !== false) {
4355
-				$ajax .= ' nocache';
4356
-			}
4357
-			$ajax = " class='$ajax'";
4358
-		}
4359
-	}
4360
-
4361
-	// Repérer la taille et l'ajouter dans la classe
4362
-	$size = 24;
4363
-	if (
4364
-		preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4365
-		or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4366
-	) {
4367
-		$size = $match[1];
4368
-	}
4369
-	$class_lien .= " s$size";
4370
-	$class_bouton .= " s$size";
4371
-
4372
-	// Icône
4373
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4374
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4375
-
4376
-	// Markup final
4377
-	if ($type == 'lien') {
4378
-		return "<span class='icone $class_lien'>"
4379
-		. "<a href='$lien'$title$ajax$javascript>"
4380
-		. $icone
4381
-		. "<b>$texte</b>"
4382
-		. "</a></span>\n";
4383
-	} else {
4384
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4385
-	}
4319
+    $class_lien = $class_bouton = $class;
4320
+
4321
+    // Normaliser la fonction et compléter la classe en fonction
4322
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4323
+        $class_lien .= ' danger';
4324
+        $class_bouton .= ' btn_danger';
4325
+    } elseif ($fonction == 'rien.gif') {
4326
+        $fonction = '';
4327
+    } elseif ($fonction == 'delsafe') {
4328
+        $fonction = 'del';
4329
+    }
4330
+
4331
+    $fond_origine = $fond;
4332
+    // Remappage des icone : article-24.png+new => article-new-24.png
4333
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4334
+        list($fond, $fonction) = $icone_renommer($fond, $fonction);
4335
+    }
4336
+
4337
+    // Ajouter le type d'objet dans la classe
4338
+    $objet_type = substr(basename($fond), 0, -4);
4339
+    $class_lien .= " $objet_type";
4340
+    $class_bouton .= " $objet_type";
4341
+
4342
+    // Texte
4343
+    $alt = attribut_html($texte);
4344
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4345
+
4346
+    // Liens : préparer les classes ajax
4347
+    $ajax = '';
4348
+    if ($type === 'lien') {
4349
+        if (strpos($class_lien, 'ajax') !== false) {
4350
+            $ajax = 'ajax';
4351
+            if (strpos($class_lien, 'preload') !== false) {
4352
+                $ajax .= ' preload';
4353
+            }
4354
+            if (strpos($class_lien, 'nocache') !== false) {
4355
+                $ajax .= ' nocache';
4356
+            }
4357
+            $ajax = " class='$ajax'";
4358
+        }
4359
+    }
4360
+
4361
+    // Repérer la taille et l'ajouter dans la classe
4362
+    $size = 24;
4363
+    if (
4364
+        preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4365
+        or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4366
+    ) {
4367
+        $size = $match[1];
4368
+    }
4369
+    $class_lien .= " s$size";
4370
+    $class_bouton .= " s$size";
4371
+
4372
+    // Icône
4373
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4374
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4375
+
4376
+    // Markup final
4377
+    if ($type == 'lien') {
4378
+        return "<span class='icone $class_lien'>"
4379
+        . "<a href='$lien'$title$ajax$javascript>"
4380
+        . $icone
4381
+        . "<b>$texte</b>"
4382
+        . "</a></span>\n";
4383
+    } else {
4384
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4385
+    }
4386 4386
 }
4387 4387
 
4388 4388
 /**
@@ -4406,7 +4406,7 @@  discard block
 block discarded – undo
4406 4406
  *     Code HTML du lien
4407 4407
  **/
4408 4408
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4409
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4409
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4410 4410
 }
4411 4411
 
4412 4412
 /**
@@ -4441,7 +4441,7 @@  discard block
 block discarded – undo
4441 4441
  *     Code HTML du lien
4442 4442
  **/
4443 4443
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4444
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4444
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4445 4445
 }
4446 4446
 
4447 4447
 /**
@@ -4486,7 +4486,7 @@  discard block
 block discarded – undo
4486 4486
  *     Code HTML du lien
4487 4487
  **/
4488 4488
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4489
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4489
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4490 4490
 }
4491 4491
 
4492 4492
 /**
@@ -4517,7 +4517,7 @@  discard block
 block discarded – undo
4517 4517
  *     Code HTML du lien
4518 4518
  **/
4519 4519
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4520
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4520
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4521 4521
 }
4522 4522
 
4523 4523
 /**
@@ -4548,7 +4548,7 @@  discard block
 block discarded – undo
4548 4548
  *     Code HTML du lien
4549 4549
  */
4550 4550
 function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') {
4551
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4551
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4552 4552
 }
4553 4553
 
4554 4554
 
@@ -4570,7 +4570,7 @@  discard block
 block discarded – undo
4570 4570
  * @return array Liste des éléments
4571 4571
  */
4572 4572
 function filtre_explode_dist($a, $b) {
4573
- return explode($b, $a);
4573
+    return explode($b, $a);
4574 4574
 }
4575 4575
 
4576 4576
 /**
@@ -4591,7 +4591,7 @@  discard block
 block discarded – undo
4591 4591
  * @return string Texte
4592 4592
  */
4593 4593
 function filtre_implode_dist($a, $b) {
4594
- return is_array($a) ? implode($b, $a) : $a;
4594
+    return is_array($a) ? implode($b, $a) : $a;
4595 4595
 }
4596 4596
 
4597 4597
 /**
@@ -4600,24 +4600,24 @@  discard block
 block discarded – undo
4600 4600
  * @return string Code CSS
4601 4601
  */
4602 4602
 function bando_images_background() {
4603
-	include_spip('inc/bandeau');
4604
-	// recuperer tous les boutons et leurs images
4605
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4603
+    include_spip('inc/bandeau');
4604
+    // recuperer tous les boutons et leurs images
4605
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4606 4606
 
4607
-	$res = '';
4608
-	foreach ($boutons as $page => $detail) {
4609
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4610
-		if (is_array($detail->sousmenu)) {
4611
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4612
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4613
-					$img = http_img_variante_svg_si_possible($sousdetail->icone);
4614
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4615
-				}
4616
-			}
4617
-		}
4618
-	}
4607
+    $res = '';
4608
+    foreach ($boutons as $page => $detail) {
4609
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4610
+        if (is_array($detail->sousmenu)) {
4611
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4612
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4613
+                    $img = http_img_variante_svg_si_possible($sousdetail->icone);
4614
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4615
+                }
4616
+            }
4617
+        }
4618
+    }
4619 4619
 
4620
-	return $res;
4620
+    return $res;
4621 4621
 }
4622 4622
 
4623 4623
 /**
@@ -4642,27 +4642,27 @@  discard block
 block discarded – undo
4642 4642
  */
4643 4643
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4644 4644
 
4645
-	// Classes : dispatcher `ajax` sur le formulaire
4646
-	$class_form = '';
4647
-	if (strpos($class, 'ajax') !== false) {
4648
-		$class_form = 'ajax';
4649
-		$class = str_replace('ajax', '', $class);
4650
-	}
4651
-	$class_btn = 'submit ' . trim($class);
4645
+    // Classes : dispatcher `ajax` sur le formulaire
4646
+    $class_form = '';
4647
+    if (strpos($class, 'ajax') !== false) {
4648
+        $class_form = 'ajax';
4649
+        $class = str_replace('ajax', '', $class);
4650
+    }
4651
+    $class_btn = 'submit ' . trim($class);
4652 4652
 
4653
-	if ($confirm) {
4654
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4655
-		if ($callback) {
4656
-			$callback = "$confirm?($callback):false";
4657
-		} else {
4658
-			$callback = $confirm;
4659
-		}
4660
-	}
4661
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4662
-	$title = $title ? " title='$title'" : '';
4653
+    if ($confirm) {
4654
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4655
+        if ($callback) {
4656
+            $callback = "$confirm?($callback):false";
4657
+        } else {
4658
+            $callback = $confirm;
4659
+        }
4660
+    }
4661
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4662
+    $title = $title ? " title='$title'" : '';
4663 4663
 
4664
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4665
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4664
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4665
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4666 4666
 }
4667 4667
 
4668 4668
 /**
@@ -4685,94 +4685,94 @@  discard block
 block discarded – undo
4685 4685
  * @return string
4686 4686
  */
4687 4687
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) {
4688
-	static $trouver_table = null;
4689
-	static $objets;
4690
-
4691
-	// On verifie qu'on a tout ce qu'il faut
4692
-	$id_objet = intval($id_objet);
4693
-	if (!($id_objet and $type_objet and $info)) {
4694
-		return '';
4695
-	}
4696
-
4697
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4698
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4699
-		return '';
4700
-	}
4701
-
4702
-	// Si on demande l'url, on retourne direct la fonction
4703
-	if ($info == 'url') {
4704
-		return generer_url_entite($id_objet, $type_objet, ...$params);
4705
-	}
4706
-
4707
-	// Sinon on va tout chercher dans la table et on garde en memoire
4708
-	$demande_titre = ($info === 'titre');
4709
-	$demande_introduction = ($info === 'introduction');
4710
-
4711
-	// 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
4712
-	if (
4713
-		!isset($objets[$type_objet][$id_objet])
4714
-		or
4715
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4716
-	) {
4717
-		if (!$trouver_table) {
4718
-			$trouver_table = charger_fonction('trouver_table', 'base');
4719
-		}
4720
-		$desc = $trouver_table(table_objet_sql($type_objet));
4721
-		if (!$desc) {
4722
-			return $objets[$type_objet] = false;
4723
-		}
4724
-
4725
-		// Si on demande le titre, on le gere en interne
4726
-		$champ_titre = '';
4727
-		if ($demande_titre) {
4728
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4729
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4730
-		}
4731
-		include_spip('base/abstract_sql');
4732
-		include_spip('base/connect_sql');
4733
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4734
-			'*' . $champ_titre,
4735
-			$desc['table_sql'],
4736
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4737
-		);
4738
-
4739
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4740
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4741
-	}
4742
-
4743
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4744
-	// ajouter la longueur au début des params supplémentaires
4745
-	if ($demande_introduction) {
4746
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4747
-		array_unshift($params, $introduction_longueur);
4748
-	}
4749
-
4750
-	// Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4751
-	if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4752
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4753
-	} // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4754
-	else {
4755
-		if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4756
-			$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4757
-		} // Sinon on prend directement le champ SQL tel quel
4758
-		else {
4759
-			$info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4760
-		}
4761
-	}
4762
-
4763
-	// On va ensuite appliquer les traitements automatiques si besoin
4764
-	if (!$etoile) {
4765
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4766
-		// mais ce fonctionnement est a ameliorer !
4767
-		$info_generee = appliquer_traitement_champ(
4768
-			$info_generee,
4769
-			$info,
4770
-			table_objet($type_objet),
4771
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4772
-		);
4773
-	}
4774
-
4775
-	return $info_generee;
4688
+    static $trouver_table = null;
4689
+    static $objets;
4690
+
4691
+    // On verifie qu'on a tout ce qu'il faut
4692
+    $id_objet = intval($id_objet);
4693
+    if (!($id_objet and $type_objet and $info)) {
4694
+        return '';
4695
+    }
4696
+
4697
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4698
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4699
+        return '';
4700
+    }
4701
+
4702
+    // Si on demande l'url, on retourne direct la fonction
4703
+    if ($info == 'url') {
4704
+        return generer_url_entite($id_objet, $type_objet, ...$params);
4705
+    }
4706
+
4707
+    // Sinon on va tout chercher dans la table et on garde en memoire
4708
+    $demande_titre = ($info === 'titre');
4709
+    $demande_introduction = ($info === 'introduction');
4710
+
4711
+    // 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
4712
+    if (
4713
+        !isset($objets[$type_objet][$id_objet])
4714
+        or
4715
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4716
+    ) {
4717
+        if (!$trouver_table) {
4718
+            $trouver_table = charger_fonction('trouver_table', 'base');
4719
+        }
4720
+        $desc = $trouver_table(table_objet_sql($type_objet));
4721
+        if (!$desc) {
4722
+            return $objets[$type_objet] = false;
4723
+        }
4724
+
4725
+        // Si on demande le titre, on le gere en interne
4726
+        $champ_titre = '';
4727
+        if ($demande_titre) {
4728
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4729
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4730
+        }
4731
+        include_spip('base/abstract_sql');
4732
+        include_spip('base/connect_sql');
4733
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4734
+            '*' . $champ_titre,
4735
+            $desc['table_sql'],
4736
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4737
+        );
4738
+
4739
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4740
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4741
+    }
4742
+
4743
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4744
+    // ajouter la longueur au début des params supplémentaires
4745
+    if ($demande_introduction) {
4746
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4747
+        array_unshift($params, $introduction_longueur);
4748
+    }
4749
+
4750
+    // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4751
+    if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4752
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4753
+    } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4754
+    else {
4755
+        if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4756
+            $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4757
+        } // Sinon on prend directement le champ SQL tel quel
4758
+        else {
4759
+            $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4760
+        }
4761
+    }
4762
+
4763
+    // On va ensuite appliquer les traitements automatiques si besoin
4764
+    if (!$etoile) {
4765
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4766
+        // mais ce fonctionnement est a ameliorer !
4767
+        $info_generee = appliquer_traitement_champ(
4768
+            $info_generee,
4769
+            $info,
4770
+            table_objet($type_objet),
4771
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4772
+        );
4773
+    }
4774
+
4775
+    return $info_generee;
4776 4776
 }
4777 4777
 
4778 4778
 /**
@@ -4805,36 +4805,36 @@  discard block
 block discarded – undo
4805 4805
  */
4806 4806
 function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') {
4807 4807
 
4808
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4809
-	$texte = $ligne_sql['texte'] ?? '';
4810
-	// En absence de descriptif, on se rabat sur chapo + texte
4811
-	if (isset($ligne_sql['chapo'])) {
4812
-		$chapo = $ligne_sql['chapo'];
4813
-		$texte = strlen($descriptif) ?
4814
-			'' :
4815
-			"$chapo \n\n $texte";
4816
-	}
4808
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4809
+    $texte = $ligne_sql['texte'] ?? '';
4810
+    // En absence de descriptif, on se rabat sur chapo + texte
4811
+    if (isset($ligne_sql['chapo'])) {
4812
+        $chapo = $ligne_sql['chapo'];
4813
+        $texte = strlen($descriptif) ?
4814
+            '' :
4815
+            "$chapo \n\n $texte";
4816
+    }
4817 4817
 
4818
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4819
-	if (!intval($longueur_ou_suite)) {
4820
-		$longueur = intval($introduction_longueur ?: 600);
4821
-	} else {
4822
-		$longueur = intval($longueur_ou_suite);
4823
-	}
4818
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4819
+    if (!intval($longueur_ou_suite)) {
4820
+        $longueur = intval($introduction_longueur ?: 600);
4821
+    } else {
4822
+        $longueur = intval($longueur_ou_suite);
4823
+    }
4824 4824
 
4825
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4826
-	// Ex : #INTRODUCTION{...}
4827
-	if (
4828
-		is_null($suite)
4829
-		and !intval($longueur_ou_suite)
4830
-	) {
4831
-		$suite = $longueur_ou_suite;
4832
-	}
4825
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4826
+    // Ex : #INTRODUCTION{...}
4827
+    if (
4828
+        is_null($suite)
4829
+        and !intval($longueur_ou_suite)
4830
+    ) {
4831
+        $suite = $longueur_ou_suite;
4832
+    }
4833 4833
 
4834
-	$f = chercher_filtre('introduction');
4835
-	$introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4834
+    $f = chercher_filtre('introduction');
4835
+    $introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4836 4836
 
4837
-	return $introduction;
4837
+    return $introduction;
4838 4838
 }
4839 4839
 
4840 4840
 /**
@@ -4848,44 +4848,44 @@  discard block
 block discarded – undo
4848 4848
  * @return string
4849 4849
  */
4850 4850
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') {
4851
-	if (!$champ) {
4852
-		return $texte;
4853
-	}
4851
+    if (!$champ) {
4852
+        return $texte;
4853
+    }
4854 4854
 
4855
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4856
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4857
-	include_fichiers_fonctions();
4855
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4856
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4857
+    include_fichiers_fonctions();
4858 4858
 
4859
-	$champ = strtoupper($champ);
4860
-	$traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4861
-	if (!$traitements or !is_array($traitements)) {
4862
-		return $texte;
4863
-	}
4859
+    $champ = strtoupper($champ);
4860
+    $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4861
+    if (!$traitements or !is_array($traitements)) {
4862
+        return $texte;
4863
+    }
4864 4864
 
4865
-	$traitement = '';
4866
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4867
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4868
-		$table_objet = table_objet($table_objet);
4869
-		if (isset($traitements[$table_objet])) {
4870
-			$traitement = $traitements[$table_objet];
4871
-		}
4872
-	}
4873
-	if (!$traitement and isset($traitements[0])) {
4874
-		$traitement = $traitements[0];
4875
-	}
4876
-	// (sinon prendre le premier de la liste par defaut ?)
4865
+    $traitement = '';
4866
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4867
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4868
+        $table_objet = table_objet($table_objet);
4869
+        if (isset($traitements[$table_objet])) {
4870
+            $traitement = $traitements[$table_objet];
4871
+        }
4872
+    }
4873
+    if (!$traitement and isset($traitements[0])) {
4874
+        $traitement = $traitements[0];
4875
+    }
4876
+    // (sinon prendre le premier de la liste par defaut ?)
4877 4877
 
4878
-	if (!$traitement) {
4879
-		return $texte;
4880
-	}
4878
+    if (!$traitement) {
4879
+        return $texte;
4880
+    }
4881 4881
 
4882
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4882
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4883 4883
 
4884
-	// Fournir $connect et $Pile[0] au traitement si besoin
4885
-	$Pile = [0 => $env];
4886
-	eval("\$texte = $traitement;");
4884
+    // Fournir $connect et $Pile[0] au traitement si besoin
4885
+    $Pile = [0 => $env];
4886
+    eval("\$texte = $traitement;");
4887 4887
 
4888
-	return $texte;
4888
+    return $texte;
4889 4889
 }
4890 4890
 
4891 4891
 
@@ -4899,21 +4899,21 @@  discard block
 block discarded – undo
4899 4899
  * @return string
4900 4900
  */
4901 4901
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4902
-	include_spip('inc/liens');
4903
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4904
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4905
-	// le raccourcis n'est plus valide
4906
-	$titre = typo($titre['titre']) ?? '';
4907
-	// on essaye avec generer_info_entite ?
4908
-	if (!strlen($titre) and !$connect) {
4909
-		$titre = generer_info_entite($id_objet, $objet, 'titre');
4910
-	}
4911
-	if (!strlen($titre)) {
4912
-		$titre = _T('info_sans_titre');
4913
-	}
4914
-	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4902
+    include_spip('inc/liens');
4903
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4904
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4905
+    // le raccourcis n'est plus valide
4906
+    $titre = typo($titre['titre']) ?? '';
4907
+    // on essaye avec generer_info_entite ?
4908
+    if (!strlen($titre) and !$connect) {
4909
+        $titre = generer_info_entite($id_objet, $objet, 'titre');
4910
+    }
4911
+    if (!strlen($titre)) {
4912
+        $titre = _T('info_sans_titre');
4913
+    }
4914
+    $url = generer_url_entite($id_objet, $objet, '', '', $connect);
4915 4915
 
4916
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4916
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4917 4917
 }
4918 4918
 
4919 4919
 
@@ -4930,15 +4930,15 @@  discard block
 block discarded – undo
4930 4930
  * @return string
4931 4931
  */
4932 4932
 function wrap($texte, $wrap) {
4933
-	$balises = extraire_balises($wrap);
4934
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4935
-		$texte = $wrap . $texte;
4936
-		$regs = array_reverse($regs[1]);
4937
-		$wrap = '</' . implode('></', $regs) . '>';
4938
-		$texte = $texte . $wrap;
4939
-	}
4933
+    $balises = extraire_balises($wrap);
4934
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4935
+        $texte = $wrap . $texte;
4936
+        $regs = array_reverse($regs[1]);
4937
+        $wrap = '</' . implode('></', $regs) . '>';
4938
+        $texte = $texte . $wrap;
4939
+    }
4940 4940
 
4941
-	return $texte;
4941
+    return $texte;
4942 4942
 }
4943 4943
 
4944 4944
 
@@ -4958,44 +4958,44 @@  discard block
 block discarded – undo
4958 4958
  * @return array|mixed|string
4959 4959
  */
4960 4960
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
4961
-	if (is_string($u)) {
4962
-		$u = typo($u);
4961
+    if (is_string($u)) {
4962
+        $u = typo($u);
4963 4963
 
4964
-		return $u;
4965
-	}
4964
+        return $u;
4965
+    }
4966 4966
 
4967
-	// caster $u en array si besoin
4968
-	if (is_object($u)) {
4969
-		$u = (array)$u;
4970
-	}
4967
+    // caster $u en array si besoin
4968
+    if (is_object($u)) {
4969
+        $u = (array)$u;
4970
+    }
4971 4971
 
4972
-	if (is_array($u)) {
4973
-		$out = '';
4974
-		// toutes les cles sont numeriques ?
4975
-		// et aucun enfant n'est un tableau
4976
-		// liste simple separee par des virgules
4977
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4978
-		$array_values = array_map('is_array', $u);
4979
-		$object_values = array_map('is_object', $u);
4980
-		if (
4981
-			array_sum($numeric_keys) == count($numeric_keys)
4982
-			and !array_sum($array_values)
4983
-			and !array_sum($object_values)
4984
-		) {
4985
-			return join(', ', array_map('filtre_print_dist', $u));
4986
-		}
4972
+    if (is_array($u)) {
4973
+        $out = '';
4974
+        // toutes les cles sont numeriques ?
4975
+        // et aucun enfant n'est un tableau
4976
+        // liste simple separee par des virgules
4977
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4978
+        $array_values = array_map('is_array', $u);
4979
+        $object_values = array_map('is_object', $u);
4980
+        if (
4981
+            array_sum($numeric_keys) == count($numeric_keys)
4982
+            and !array_sum($array_values)
4983
+            and !array_sum($object_values)
4984
+        ) {
4985
+            return join(', ', array_map('filtre_print_dist', $u));
4986
+        }
4987 4987
 
4988
-		// sinon on passe a la ligne et on indente
4989
-		$i_str = str_pad('', $indent, ' ');
4990
-		foreach ($u as $k => $v) {
4991
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4992
-		}
4988
+        // sinon on passe a la ligne et on indente
4989
+        $i_str = str_pad('', $indent, ' ');
4990
+        foreach ($u as $k => $v) {
4991
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4992
+        }
4993 4993
 
4994
-		return $out;
4995
-	}
4994
+        return $out;
4995
+    }
4996 4996
 
4997
-	// on sait pas quoi faire...
4998
-	return $u;
4997
+    // on sait pas quoi faire...
4998
+    return $u;
4999 4999
 }
5000 5000
 
5001 5001
 
@@ -5008,10 +5008,10 @@  discard block
 block discarded – undo
5008 5008
  * @return string|array
5009 5009
  */
5010 5010
 function objet_info($objet, $info) {
5011
-	$table = table_objet_sql($objet);
5012
-	$infos = lister_tables_objets_sql($table);
5011
+    $table = table_objet_sql($objet);
5012
+    $infos = lister_tables_objets_sql($table);
5013 5013
 
5014
-	return (isset($infos[$info]) ? $infos[$info] : '');
5014
+    return (isset($infos[$info]) ? $infos[$info] : '');
5015 5015
 }
5016 5016
 
5017 5017
 /**
@@ -5026,11 +5026,11 @@  discard block
 block discarded – undo
5026 5026
  *     Texte traduit du comptage, tel que '3 articles'
5027 5027
  */
5028 5028
 function objet_afficher_nb($nb, $objet) {
5029
-	if (!$nb) {
5030
-		return _T(objet_info($objet, 'info_aucun_objet'));
5031
-	} else {
5032
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5033
-	}
5029
+    if (!$nb) {
5030
+        return _T(objet_info($objet, 'info_aucun_objet'));
5031
+    } else {
5032
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5033
+    }
5034 5034
 }
5035 5035
 
5036 5036
 /**
@@ -5042,11 +5042,11 @@  discard block
 block discarded – undo
5042 5042
  * @return string
5043 5043
  */
5044 5044
 function objet_icone($objet, $taille = 24, $class = '') {
5045
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5046
-	$icone = chemin_image($icone);
5047
-	$balise_img = charger_filtre('balise_img');
5045
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5046
+    $icone = chemin_image($icone);
5047
+    $balise_img = charger_filtre('balise_img');
5048 5048
 
5049
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5049
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5050 5050
 }
5051 5051
 
5052 5052
 /**
@@ -5067,12 +5067,12 @@  discard block
 block discarded – undo
5067 5067
  * @return string
5068 5068
  */
5069 5069
 function objet_T($objet, $chaine, $args = [], $options = []) {
5070
-	$chaine = explode(':', $chaine);
5071
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5072
-		return $t;
5073
-	}
5074
-	$chaine = implode(':', $chaine);
5075
-	return _T($chaine, $args, $options);
5070
+    $chaine = explode(':', $chaine);
5071
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5072
+        return $t;
5073
+    }
5074
+    $chaine = implode(':', $chaine);
5075
+    return _T($chaine, $args, $options);
5076 5076
 }
5077 5077
 
5078 5078
 /**
@@ -5086,18 +5086,18 @@  discard block
 block discarded – undo
5086 5086
  * @return string      Code HTML
5087 5087
  */
5088 5088
 function insert_head_css_conditionnel($flux) {
5089
-	if (
5090
-		strpos($flux, '<!-- insert_head_css -->') === false
5091
-		and $p = strpos($flux, '<!-- insert_head -->')
5092
-	) {
5093
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
5094
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5095
-			$p = $p1;
5096
-		}
5097
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5098
-	}
5089
+    if (
5090
+        strpos($flux, '<!-- insert_head_css -->') === false
5091
+        and $p = strpos($flux, '<!-- insert_head -->')
5092
+    ) {
5093
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
5094
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5095
+            $p = $p1;
5096
+        }
5097
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5098
+    }
5099 5099
 
5100
-	return $flux;
5100
+    return $flux;
5101 5101
 }
5102 5102
 
5103 5103
 /**
@@ -5120,72 +5120,72 @@  discard block
 block discarded – undo
5120 5120
  * @return string
5121 5121
  */
5122 5122
 function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') {
5123
-	if (isset($contexte['format'])) {
5124
-		$extension = $contexte['format'];
5125
-		unset($contexte['format']);
5126
-	} else {
5127
-		$extension = 'html';
5128
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5129
-			$extension = $m[1];
5130
-		}
5131
-	}
5132
-	// recuperer le contenu produit par le squelette
5133
-	$options['raw'] = true;
5134
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5135
-
5136
-	// calculer le nom de la css
5137
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5138
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5139
-	$contexte_implicite = calculer_contexte_implicite();
5140
-
5141
-	// par defaut on hash selon les contextes qui sont a priori moins variables
5142
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5143
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5144
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5145
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5146
-	}
5147
-	else {
5148
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5149
-		ksort($contexte);
5150
-		$hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
5151
-	}
5152
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5153
-
5154
-	// mettre a jour le fichier si il n'existe pas
5155
-	// ou trop ancien
5156
-	// le dernier fichier produit est toujours suffixe par .last
5157
-	// et recopie sur le fichier cible uniquement si il change
5158
-	if (
5159
-		!file_exists($filename)
5160
-		or !file_exists($filename . '.last')
5161
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5162
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5163
-	) {
5164
-		$contenu = $cache['texte'];
5165
-		// passer les urls en absolu si c'est une css
5166
-		if ($extension == 'css') {
5167
-			$contenu = urls_absolues_css(
5168
-				$contenu,
5169
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5170
-			);
5171
-		}
5172
-
5173
-		$comment = '';
5174
-		// ne pas insérer de commentaire sur certains formats
5175
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
5176
-			$comment = "/* #PRODUIRE{fond=$fond";
5177
-			foreach ($contexte as $k => $v) {
5178
-				$comment .= ",$k=$v";
5179
-			}
5180
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5181
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5182
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5183
-		}
5184
-		// et ecrire le fichier si il change
5185
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5186
-	}
5187
-
5188
-	return timestamp($filename);
5123
+    if (isset($contexte['format'])) {
5124
+        $extension = $contexte['format'];
5125
+        unset($contexte['format']);
5126
+    } else {
5127
+        $extension = 'html';
5128
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5129
+            $extension = $m[1];
5130
+        }
5131
+    }
5132
+    // recuperer le contenu produit par le squelette
5133
+    $options['raw'] = true;
5134
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
5135
+
5136
+    // calculer le nom de la css
5137
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5138
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5139
+    $contexte_implicite = calculer_contexte_implicite();
5140
+
5141
+    // par defaut on hash selon les contextes qui sont a priori moins variables
5142
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5143
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5144
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5145
+        $hash = md5($contexte_implicite['host'] . '::' . $cache);
5146
+    }
5147
+    else {
5148
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5149
+        ksort($contexte);
5150
+        $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
5151
+    }
5152
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5153
+
5154
+    // mettre a jour le fichier si il n'existe pas
5155
+    // ou trop ancien
5156
+    // le dernier fichier produit est toujours suffixe par .last
5157
+    // et recopie sur le fichier cible uniquement si il change
5158
+    if (
5159
+        !file_exists($filename)
5160
+        or !file_exists($filename . '.last')
5161
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5162
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5163
+    ) {
5164
+        $contenu = $cache['texte'];
5165
+        // passer les urls en absolu si c'est une css
5166
+        if ($extension == 'css') {
5167
+            $contenu = urls_absolues_css(
5168
+                $contenu,
5169
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5170
+            );
5171
+        }
5172
+
5173
+        $comment = '';
5174
+        // ne pas insérer de commentaire sur certains formats
5175
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
5176
+            $comment = "/* #PRODUIRE{fond=$fond";
5177
+            foreach ($contexte as $k => $v) {
5178
+                $comment .= ",$k=$v";
5179
+            }
5180
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5181
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5182
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
5183
+        }
5184
+        // et ecrire le fichier si il change
5185
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5186
+    }
5187
+
5188
+    return timestamp($filename);
5189 5189
 }
5190 5190
 
5191 5191
 /**
@@ -5198,15 +5198,15 @@  discard block
 block discarded – undo
5198 5198
  *    $fichier auquel on a ajouté le timestamp
5199 5199
  */
5200 5200
 function timestamp($fichier) {
5201
-	if (
5202
-		!$fichier
5203
-		or !file_exists($fichier)
5204
-		or !$m = filemtime($fichier)
5205
-	) {
5206
-		return $fichier;
5207
-	}
5201
+    if (
5202
+        !$fichier
5203
+        or !file_exists($fichier)
5204
+        or !$m = filemtime($fichier)
5205
+    ) {
5206
+        return $fichier;
5207
+    }
5208 5208
 
5209
-	return "$fichier?$m";
5209
+    return "$fichier?$m";
5210 5210
 }
5211 5211
 
5212 5212
 /**
@@ -5216,11 +5216,11 @@  discard block
 block discarded – undo
5216 5216
  * @return string
5217 5217
  */
5218 5218
 function supprimer_timestamp($url) {
5219
-	if (strpos($url, '?') === false) {
5220
-		return $url;
5221
-	}
5219
+    if (strpos($url, '?') === false) {
5220
+        return $url;
5221
+    }
5222 5222
 
5223
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5223
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5224 5224
 }
5225 5225
 
5226 5226
 /**
@@ -5235,9 +5235,9 @@  discard block
 block discarded – undo
5235 5235
  * @return string
5236 5236
  */
5237 5237
 function filtre_nettoyer_titre_email_dist($titre) {
5238
-	include_spip('inc/envoyer_mail');
5238
+    include_spip('inc/envoyer_mail');
5239 5239
 
5240
-	return nettoyer_titre_email($titre);
5240
+    return nettoyer_titre_email($titre);
5241 5241
 }
5242 5242
 
5243 5243
 /**
@@ -5259,27 +5259,27 @@  discard block
 block discarded – undo
5259 5259
  * @return string
5260 5260
  */
5261 5261
 function filtre_chercher_rubrique_dist(
5262
-	$titre,
5263
-	$id_objet,
5264
-	$id_parent,
5265
-	$objet,
5266
-	$id_secteur,
5267
-	$restreint,
5268
-	$actionable = false,
5269
-	$retour_sans_cadre = false
5262
+    $titre,
5263
+    $id_objet,
5264
+    $id_parent,
5265
+    $objet,
5266
+    $id_secteur,
5267
+    $restreint,
5268
+    $actionable = false,
5269
+    $retour_sans_cadre = false
5270 5270
 ) {
5271
-	include_spip('inc/filtres_ecrire');
5271
+    include_spip('inc/filtres_ecrire');
5272 5272
 
5273
-	return chercher_rubrique(
5274
-		$titre,
5275
-		$id_objet,
5276
-		$id_parent,
5277
-		$objet,
5278
-		$id_secteur,
5279
-		$restreint,
5280
-		$actionable,
5281
-		$retour_sans_cadre
5282
-	);
5273
+    return chercher_rubrique(
5274
+        $titre,
5275
+        $id_objet,
5276
+        $id_parent,
5277
+        $objet,
5278
+        $id_secteur,
5279
+        $restreint,
5280
+        $actionable,
5281
+        $retour_sans_cadre
5282
+    );
5283 5283
 }
5284 5284
 
5285 5285
 /**
@@ -5308,56 +5308,56 @@  discard block
 block discarded – undo
5308 5308
  *     Chaîne vide si l'accès est autorisé
5309 5309
  */
5310 5310
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5311
-	if ($ok) {
5312
-		return '';
5313
-	}
5314
-
5315
-	// Vider tous les tampons
5316
-	$level = @ob_get_level();
5317
-	while ($level--) {
5318
-		@ob_end_clean();
5319
-	}
5320
-
5321
-	include_spip('inc/headers');
5322
-
5323
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5324
-	if ($url) {
5325
-		redirige_par_entete($url, '', $statut);
5326
-	}
5327
-
5328
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5329
-	if (!is_numeric($statut) and is_null($message)) {
5330
-		$message = $statut;
5331
-		$statut = 0;
5332
-	}
5333
-	if (!$message) {
5334
-		$message = '';
5335
-	}
5336
-	$statut = intval($statut);
5337
-
5338
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5339
-	if (test_espace_prive()) {
5340
-		if (!$statut or !in_array($statut, [404, 403])) {
5341
-			$statut = 403;
5342
-		}
5343
-		http_response_code(403);
5344
-		$echec = charger_fonction('403', 'exec');
5345
-		$echec($message);
5346
-	} else {
5347
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5348
-		if (!$statut) {
5349
-			$statut = 404;
5350
-		}
5351
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5352
-		http_response_code($statut);
5353
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5354
-		if ($statut >= 400) {
5355
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5356
-		}
5357
-	}
5358
-
5359
-
5360
-	exit;
5311
+    if ($ok) {
5312
+        return '';
5313
+    }
5314
+
5315
+    // Vider tous les tampons
5316
+    $level = @ob_get_level();
5317
+    while ($level--) {
5318
+        @ob_end_clean();
5319
+    }
5320
+
5321
+    include_spip('inc/headers');
5322
+
5323
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5324
+    if ($url) {
5325
+        redirige_par_entete($url, '', $statut);
5326
+    }
5327
+
5328
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5329
+    if (!is_numeric($statut) and is_null($message)) {
5330
+        $message = $statut;
5331
+        $statut = 0;
5332
+    }
5333
+    if (!$message) {
5334
+        $message = '';
5335
+    }
5336
+    $statut = intval($statut);
5337
+
5338
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5339
+    if (test_espace_prive()) {
5340
+        if (!$statut or !in_array($statut, [404, 403])) {
5341
+            $statut = 403;
5342
+        }
5343
+        http_response_code(403);
5344
+        $echec = charger_fonction('403', 'exec');
5345
+        $echec($message);
5346
+    } else {
5347
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5348
+        if (!$statut) {
5349
+            $statut = 404;
5350
+        }
5351
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5352
+        http_response_code($statut);
5353
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5354
+        if ($statut >= 400) {
5355
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5356
+        }
5357
+    }
5358
+
5359
+
5360
+    exit;
5361 5361
 }
5362 5362
 
5363 5363
 /**
@@ -5368,11 +5368,11 @@  discard block
 block discarded – undo
5368 5368
  * @return string
5369 5369
  */
5370 5370
 function filtre_compacte_dist($source, $format = null) {
5371
-	if (function_exists('compacte')) {
5372
-		return compacte($source, $format);
5373
-	}
5371
+    if (function_exists('compacte')) {
5372
+        return compacte($source, $format);
5373
+    }
5374 5374
 
5375
-	return $source;
5375
+    return $source;
5376 5376
 }
5377 5377
 
5378 5378
 
@@ -5384,31 +5384,31 @@  discard block
 block discarded – undo
5384 5384
  * @return string
5385 5385
  */
5386 5386
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
5387
-	$l = strlen($passe);
5388
-
5389
-	if ($l <= 8 or !$afficher_partiellement) {
5390
-		if (!$l) {
5391
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5392
-		}
5393
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5394
-	}
5395
-
5396
-	if (is_null($portion_pourcent)) {
5397
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5398
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5399
-		}
5400
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5401
-	}
5402
-	if ($portion_pourcent >= 100) {
5403
-		return $passe;
5404
-	}
5405
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5406
-	$e = max($e, 0);
5407
-	$mid = str_pad('', $l - 2 * $e, '*');
5408
-	if ($e > 0 and strlen($mid) > 8) {
5409
-		$mid = '***...***';
5410
-	}
5411
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5387
+    $l = strlen($passe);
5388
+
5389
+    if ($l <= 8 or !$afficher_partiellement) {
5390
+        if (!$l) {
5391
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5392
+        }
5393
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5394
+    }
5395
+
5396
+    if (is_null($portion_pourcent)) {
5397
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5398
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5399
+        }
5400
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5401
+    }
5402
+    if ($portion_pourcent >= 100) {
5403
+        return $passe;
5404
+    }
5405
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5406
+    $e = max($e, 0);
5407
+    $mid = str_pad('', $l - 2 * $e, '*');
5408
+    if ($e > 0 and strlen($mid) > 8) {
5409
+        $mid = '***...***';
5410
+    }
5411
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5412 5412
 }
5413 5413
 
5414 5414
 
@@ -5429,64 +5429,64 @@  discard block
 block discarded – undo
5429 5429
  */
5430 5430
 function identifiant_slug($texte, $type = '', $options = []) {
5431 5431
 
5432
-	$original = $texte;
5433
-	$separateur = (isset($options['separateur']) ? $options['separateur'] : '_');
5434
-	$longueur_maxi = (isset($options['longueur_maxi']) ? $options['longueur_maxi'] : 60);
5435
-	$longueur_mini = (isset($options['longueur_mini']) ? $options['longueur_mini'] : 0);
5432
+    $original = $texte;
5433
+    $separateur = (isset($options['separateur']) ? $options['separateur'] : '_');
5434
+    $longueur_maxi = (isset($options['longueur_maxi']) ? $options['longueur_maxi'] : 60);
5435
+    $longueur_mini = (isset($options['longueur_mini']) ? $options['longueur_mini'] : 0);
5436 5436
 
5437
-	if (!function_exists('translitteration')) {
5438
-		include_spip('inc/charsets');
5439
-	}
5437
+    if (!function_exists('translitteration')) {
5438
+        include_spip('inc/charsets');
5439
+    }
5440 5440
 
5441
-	// pas de balise html
5442
-	if (strpos($texte, '<') !== false) {
5443
-		$texte = strip_tags($texte);
5444
-	}
5445
-	if (strpos($texte, '&') !== false) {
5446
-		$texte = unicode2charset($texte);
5447
-	}
5448
-	// On enlève les espaces indésirables
5449
-	$texte = trim($texte);
5441
+    // pas de balise html
5442
+    if (strpos($texte, '<') !== false) {
5443
+        $texte = strip_tags($texte);
5444
+    }
5445
+    if (strpos($texte, '&') !== false) {
5446
+        $texte = unicode2charset($texte);
5447
+    }
5448
+    // On enlève les espaces indésirables
5449
+    $texte = trim($texte);
5450 5450
 
5451
-	// On enlève les accents et cie
5452
-	$texte = translitteration($texte);
5451
+    // On enlève les accents et cie
5452
+    $texte = translitteration($texte);
5453 5453
 
5454
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5455
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5454
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5455
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5456 5456
 
5457
-	// nettoyer les doubles occurences du separateur si besoin
5458
-	while (strpos($texte, "$separateur$separateur") !== false) {
5459
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5460
-	}
5457
+    // nettoyer les doubles occurences du separateur si besoin
5458
+    while (strpos($texte, "$separateur$separateur") !== false) {
5459
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5460
+    }
5461 5461
 
5462
-	// pas de separateur au debut ni a la fin
5463
-	$texte = trim($texte, $separateur);
5462
+    // pas de separateur au debut ni a la fin
5463
+    $texte = trim($texte, $separateur);
5464 5464
 
5465
-	// en minuscules
5466
-	$texte = strtolower($texte);
5465
+    // en minuscules
5466
+    $texte = strtolower($texte);
5467 5467
 
5468
-	switch ($type) {
5469
-		case 'class':
5470
-		case 'id':
5471
-		case 'anchor':
5472
-			if (preg_match(',^\d,', $texte)) {
5473
-				$texte = substr($type, 0, 1) . $texte;
5474
-			}
5475
-	}
5468
+    switch ($type) {
5469
+        case 'class':
5470
+        case 'id':
5471
+        case 'anchor':
5472
+            if (preg_match(',^\d,', $texte)) {
5473
+                $texte = substr($type, 0, 1) . $texte;
5474
+            }
5475
+    }
5476 5476
 
5477
-	if (strlen($texte) > $longueur_maxi) {
5478
-		$texte = substr($texte, 0, $longueur_maxi);
5479
-	}
5477
+    if (strlen($texte) > $longueur_maxi) {
5478
+        $texte = substr($texte, 0, $longueur_maxi);
5479
+    }
5480 5480
 
5481
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5482
-		if (preg_match(',^\d,', $texte)) {
5483
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5484
-		}
5485
-		$texte .= $separateur . md5($original);
5486
-		$texte = substr($texte, 0, $longueur_mini);
5487
-	}
5481
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5482
+        if (preg_match(',^\d,', $texte)) {
5483
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5484
+        }
5485
+        $texte .= $separateur . md5($original);
5486
+        $texte = substr($texte, 0, $longueur_mini);
5487
+    }
5488 5488
 
5489
-	return $texte;
5489
+    return $texte;
5490 5490
 }
5491 5491
 
5492 5492
 
@@ -5507,11 +5507,11 @@  discard block
 block discarded – undo
5507 5507
  * @exemple `<:info_maximum|label_nettoyer:>`
5508 5508
  */
5509 5509
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5510
-	$label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5511
-	if ($ucfirst) {
5512
-		$label = spip_ucfirst($label);
5513
-	}
5514
-	return $label;
5510
+    $label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5511
+    if ($ucfirst) {
5512
+        $label = spip_ucfirst($label);
5513
+    }
5514
+    return $label;
5515 5515
 }
5516 5516
 
5517 5517
 /**
@@ -5524,8 +5524,8 @@  discard block
 block discarded – undo
5524 5524
  * @exemple `<:info_maximum|label_ponctuer:>`
5525 5525
  */
5526 5526
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5527
-	$label = label_nettoyer($text, $ucfirst);
5528
-	return _T('label_ponctuer', ['label' => $label]);
5527
+    $label = label_nettoyer($text, $ucfirst);
5528
+    return _T('label_ponctuer', ['label' => $label]);
5529 5529
 }
5530 5530
 
5531 5531
 
@@ -5538,19 +5538,19 @@  discard block
 block discarded – undo
5538 5538
  * @return array
5539 5539
  */
5540 5540
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5541
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5542
-		return [];
5543
-	}
5541
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5542
+        return [];
5543
+    }
5544 5544
 
5545
-	// compatibilite signature inversee
5546
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5547
-		list($objet, $id_objet) = [$id_objet, $objet];
5548
-	}
5545
+    // compatibilite signature inversee
5546
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5547
+        list($objet, $id_objet) = [$id_objet, $objet];
5548
+    }
5549 5549
 
5550
-	if (!function_exists($fonction)) {
5551
-		include_spip('base/objets');
5552
-	}
5553
-	return $fonction($objet, $id_objet);
5550
+    if (!function_exists($fonction)) {
5551
+        include_spip('base/objets');
5552
+    }
5553
+    return $fonction($objet, $id_objet);
5554 5554
 }
5555 5555
 
5556 5556
 
@@ -5565,7 +5565,7 @@  discard block
 block discarded – undo
5565 5565
  * @return array
5566 5566
  */
5567 5567
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5568
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5568
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5569 5569
 }
5570 5570
 
5571 5571
 /**
@@ -5579,7 +5579,7 @@  discard block
 block discarded – undo
5579 5579
  * @return array
5580 5580
  */
5581 5581
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5582
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5582
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5583 5583
 }
5584 5584
 
5585 5585
 /**
@@ -5593,7 +5593,7 @@  discard block
 block discarded – undo
5593 5593
  * @return array
5594 5594
  */
5595 5595
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5596
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5596
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5597 5597
 }
5598 5598
 
5599 5599
 /**
@@ -5607,5 +5607,5 @@  discard block
 block discarded – undo
5607 5607
  * @return array
5608 5608
  */
5609 5609
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5610
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5610
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5611 5611
 }
Please login to merge, or discard this patch.
Spacing   +130 added lines, -131 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
 		// fonction ou name\space\fonction
102 102
 		if (is_callable($f)) {
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 	// affichage "GIT [master: abcdef]"
224 224
 	$commit = $desc['commit_short'] ?? $desc['commit'];
225 225
 	if ($desc['branch']) {
226
-		$commit = $desc['branch'] . ': ' . $commit;
226
+		$commit = $desc['branch'].': '.$commit;
227 227
 	}
228 228
 	return "{$desc['vcs']} [$commit]";
229 229
 }
@@ -242,9 +242,9 @@  discard block
 block discarded – undo
242 242
 	}
243 243
 
244 244
 	// version installee par GIT
245
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
245
+	if (lire_fichier($dir.'/.git/HEAD', $c)) {
246 246
 		$currentHead = trim(substr($c, 4));
247
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
247
+		if (lire_fichier($dir.'/.git/'.$currentHead, $hash)) {
248 248
 			return [
249 249
 				'vcs' => 'GIT',
250 250
 				'branch' => basename($currentHead),
@@ -271,8 +271,8 @@  discard block
 block discarded – undo
271 271
 		$dir = '.';
272 272
 	}
273 273
 	// version installee par SVN
274
-	if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
275
-		$db = new SQLite3($dir . '/.svn/wc.db');
274
+	if (file_exists($dir.'/.svn/wc.db') && class_exists('SQLite3')) {
275
+		$db = new SQLite3($dir.'/.svn/wc.db');
276 276
 		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
277 277
 		if ($result) {
278 278
 			$row = $result->fetchArray();
@@ -290,12 +290,12 @@  discard block
 block discarded – undo
290 290
 
291 291
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
292 292
 // et laisser passer les fonctions personnelles baptisees image_...
293
-$GLOBALS['spip_matrice']['image_graver'] = true;//'inc/filtres_images_mini.php';
294
-$GLOBALS['spip_matrice']['image_select'] = true;//'inc/filtres_images_mini.php';
295
-$GLOBALS['spip_matrice']['image_reduire'] = true;//'inc/filtres_images_mini.php';
296
-$GLOBALS['spip_matrice']['image_reduire_par'] = true;//'inc/filtres_images_mini.php';
297
-$GLOBALS['spip_matrice']['image_passe_partout'] = true;//'inc/filtres_images_mini.php';
298
-$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true;//'inc/filtres_images_mini.php';
293
+$GLOBALS['spip_matrice']['image_graver'] = true; //'inc/filtres_images_mini.php';
294
+$GLOBALS['spip_matrice']['image_select'] = true; //'inc/filtres_images_mini.php';
295
+$GLOBALS['spip_matrice']['image_reduire'] = true; //'inc/filtres_images_mini.php';
296
+$GLOBALS['spip_matrice']['image_reduire_par'] = true; //'inc/filtres_images_mini.php';
297
+$GLOBALS['spip_matrice']['image_passe_partout'] = true; //'inc/filtres_images_mini.php';
298
+$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true; //'inc/filtres_images_mini.php';
299 299
 
300 300
 $GLOBALS['spip_matrice']['couleur_html_to_hex'] = 'inc/filtres_images_mini.php';
301 301
 $GLOBALS['spip_matrice']['couleur_hex_to_hsl'] = 'inc/filtres_images_mini.php';
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
  */
455 455
 function filtre_debug($val, $key = null) {
456 456
 	$debug = (
457
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
458
-		) . var_export($val, true);
457
+		is_null($key) ? '' : (var_export($key, true).' = ')
458
+		).var_export($val, true);
459 459
 
460 460
 	include_spip('inc/autoriser');
461 461
 	if (autoriser('webmestre')) {
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
 		$is_file = false;
510 510
 	}
511 511
 	if ($is_file) {
512
-		$is_local_file = function ($path) {
512
+		$is_local_file = function($path) {
513 513
 			if (strpos($path, '?') !== false) {
514 514
 				$path = supprimer_timestamp($path);
515 515
 				// remove ?24px added by find_in_theme on .svg files
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
562 562
 							$srcover = $match[1];
563 563
 							array_shift($args);
564
-							array_unshift($args, "<img src='" . $match[1] . "' />");
564
+							array_unshift($args, "<img src='".$match[1]."' />");
565 565
 							$srcover_filter = call_user_func_array($filtre, $args);
566 566
 							$srcover_filter = extraire_attribut($srcover_filter, 'src');
567 567
 							$reduit = str_replace($srcover, $srcover_filter, $reduit);
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
 	// " -> &quot; et tout ce genre de choses
929 929
 	$u = $GLOBALS['meta']['pcre_u'];
930 930
 	$texte = str_replace('&nbsp;', ' ', $texte);
931
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
931
+	$texte = preg_replace('/\s{2,}/S'.$u, ' ', $texte);
932 932
 	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
933 933
 	$texte = entites_html($texte, false, false);
934 934
 	// mais bien echapper les double quotes !
@@ -988,7 +988,7 @@  discard block
 block discarded – undo
988 988
  **/
989 989
 function supprimer_numero($texte) {
990 990
 	return preg_replace(
991
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
991
+		',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S',
992 992
 		'',
993 993
 		$texte
994 994
 	);
@@ -1016,7 +1016,7 @@  discard block
 block discarded – undo
1016 1016
 function recuperer_numero($texte) {
1017 1017
 	if (
1018 1018
 		preg_match(
1019
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1019
+			',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S',
1020 1020
 			$texte,
1021 1021
 			$regs
1022 1022
 		)
@@ -1107,8 +1107,8 @@  discard block
 block discarded – undo
1107 1107
  **/
1108 1108
 function textebrut($texte) {
1109 1109
 	$u = $GLOBALS['meta']['pcre_u'];
1110
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1111
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1110
+	$texte = preg_replace('/\s+/S'.$u, ' ', $texte);
1111
+	$texte = preg_replace('/<(p|br)( [^>]*)?'.'>/iS', "\n\n", $texte);
1112 1112
 	$texte = preg_replace("/^\n+/", '', $texte);
1113 1113
 	$texte = preg_replace("/\n+$/", '', $texte);
1114 1114
 	$texte = preg_replace("/\n +/", "\n", $texte);
@@ -1142,7 +1142,7 @@  discard block
 block discarded – undo
1142 1142
 		)
1143 1143
 	) {
1144 1144
 		foreach ($liens[0] as $a) {
1145
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1145
+			$rel = 'noopener noreferrer '.extraire_attribut($a, 'rel');
1146 1146
 			$ablank = inserer_attribut($a, 'rel', $rel);
1147 1147
 			$ablank = inserer_attribut($ablank, 'target', '_blank');
1148 1148
 			$texte = str_replace($a, $ablank, $texte);
@@ -1167,7 +1167,7 @@  discard block
 block discarded – undo
1167 1167
 		foreach ($regs[0] as $a) {
1168 1168
 			$rel = extraire_attribut($a, 'rel');
1169 1169
 			if (strpos($rel, 'nofollow') === false) {
1170
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1170
+				$rel = 'nofollow'.($rel ? " $rel" : '');
1171 1171
 				$anofollow = inserer_attribut($a, 'rel', $rel);
1172 1172
 				$texte = str_replace($a, $anofollow, $texte);
1173 1173
 			}
@@ -1196,7 +1196,7 @@  discard block
 block discarded – undo
1196 1196
 	$u = $GLOBALS['meta']['pcre_u'];
1197 1197
 	$texte = preg_replace('@</p>@iS', "\n", $texte);
1198 1198
 	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1199
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1199
+	$texte = preg_replace('@^\s*<br />@S'.$u, '', $texte);
1200 1200
 
1201 1201
 	return $texte;
1202 1202
 }
@@ -1227,7 +1227,7 @@  discard block
 block discarded – undo
1227 1227
 		return $texte;
1228 1228
 	}
1229 1229
 	include_spip('inc/texte');
1230
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1230
+	$tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ?
1231 1231
 		'div' : 'span';
1232 1232
 
1233 1233
 	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
@@ -1339,7 +1339,7 @@  discard block
 block discarded – undo
1339 1339
 	}
1340 1340
 	$u = $GLOBALS['meta']['pcre_u'];
1341 1341
 	if ($textebrut) {
1342
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1342
+		$texte = preg_replace([",\n,", ',\s(?=\s),msS'.$u], [' ', ''], textebrut($texte));
1343 1343
 	}
1344 1344
 	$texte = texte_backend($texte);
1345 1345
 	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
@@ -1374,7 +1374,7 @@  discard block
 block discarded – undo
1374 1374
 	# un message pour abs_url
1375 1375
 	$GLOBALS['mode_abs_url'] = 'url';
1376 1376
 	$url = trim($url);
1377
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1377
+	$r = ',^(?:'._PROTOCOLES_STD.'):?/?/?$,iS';
1378 1378
 
1379 1379
 	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1380 1380
 }
@@ -1578,14 +1578,14 @@  discard block
 block discarded – undo
1578 1578
 	if (strpos($texte, '<') !== false) {
1579 1579
 		include_spip('inc/lien');
1580 1580
 		if (defined('_PREG_MODELE')) {
1581
-			$preg_modeles = '@' . _PREG_MODELE . '@imsS';
1581
+			$preg_modeles = '@'._PREG_MODELE.'@imsS';
1582 1582
 			$texte = echappe_html($texte, '', true, $preg_modeles);
1583 1583
 		}
1584 1584
 	}
1585 1585
 
1586 1586
 	$debut = '';
1587 1587
 	$suite = $texte;
1588
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1588
+	while ($t = strpos('-'.$suite, "\n", 1)) {
1589 1589
 		$debut .= substr($suite, 0, $t - 1);
1590 1590
 		$suite = substr($suite, $t);
1591 1591
 		$car = substr($suite, 0, 1);
@@ -1603,11 +1603,11 @@  discard block
 block discarded – undo
1603 1603
 			$suite = substr($suite, strlen($regs[0]));
1604 1604
 		}
1605 1605
 	}
1606
-	$texte = $debut . $suite;
1606
+	$texte = $debut.$suite;
1607 1607
 
1608 1608
 	$texte = echappe_retour($texte);
1609 1609
 
1610
-	return $texte . $fin;
1610
+	return $texte.$fin;
1611 1611
 }
1612 1612
 
1613 1613
 
@@ -1669,7 +1669,7 @@  discard block
 block discarded – undo
1669 1669
 		}
1670 1670
 
1671 1671
 		foreach ($regs as $reg) {
1672
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1672
+			$cle = ($reg[1] ? $reg[1].':' : '').$reg[2];
1673 1673
 			$desc = $traduire($cle, $lang, true);
1674 1674
 			$l = $desc->langue;
1675 1675
 			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
@@ -1783,9 +1783,9 @@  discard block
 block discarded – undo
1783 1783
 					// il ne faut pas echapper en div si propre produit un seul paragraphe
1784 1784
 					include_spip('inc/texte');
1785 1785
 					$trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1786
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1786
+					$mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1787 1787
 					if ($mode === 'div') {
1788
-						$trad = rtrim($trad) . "\n\n";
1788
+						$trad = rtrim($trad)."\n\n";
1789 1789
 					}
1790 1790
 					$trad = code_echappement($trad, 'multi', false, $mode);
1791 1791
 					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
@@ -1980,7 +1980,7 @@  discard block
 block discarded – undo
1980 1980
 	if (is_array($balise)) {
1981 1981
 		array_walk(
1982 1982
 			$balise,
1983
-			function (&$a, $key, $t) {
1983
+			function(&$a, $key, $t) {
1984 1984
 				$a = extraire_attribut($a, $t);
1985 1985
 			},
1986 1986
 			$attribut
@@ -2072,14 +2072,14 @@  discard block
 block discarded – undo
2072 2072
 
2073 2073
 	if ($old !== null) {
2074 2074
 		// Remplacer l'ancien attribut du meme nom
2075
-		$balise = $r[1] . $insert . $r[5];
2075
+		$balise = $r[1].$insert.$r[5];
2076 2076
 	} else {
2077 2077
 		// preferer une balise " />" (comme <img />)
2078 2078
 		if (preg_match(',/>,', $balise)) {
2079
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2079
+			$balise = preg_replace(',\s?/>,S', $insert.' />', $balise, 1);
2080 2080
 		} // sinon une balise <a ...> ... </a>
2081 2081
 		else {
2082
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2082
+			$balise = preg_replace(',\s?>,S', $insert.'>', $balise, 1);
2083 2083
 		}
2084 2084
 	}
2085 2085
 
@@ -2134,7 +2134,7 @@  discard block
 block discarded – undo
2134 2134
 		if (
2135 2135
 			$class_courante
2136 2136
 			and strpos($class_courante, $c) !== false
2137
-			and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2137
+			and preg_match('/(^|\s)'.preg_quote($c).'($|\s)/', $class_courante)
2138 2138
 		) {
2139 2139
 			$is_class_presente = true;
2140 2140
 		}
@@ -2142,12 +2142,12 @@  discard block
 block discarded – undo
2142 2142
 			in_array($operation, ['ajouter', 'commuter'])
2143 2143
 			and !$is_class_presente
2144 2144
 		) {
2145
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2145
+			$class_new = ltrim(rtrim($class_new ?? '').' '.$c);
2146 2146
 		} elseif (
2147 2147
 			in_array($operation, ['supprimer', 'commuter'])
2148 2148
 			and $is_class_presente
2149 2149
 		) {
2150
-			$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2150
+			$class_new = trim(preg_replace('/(^|\s)'.preg_quote($c).'($|\s)/', "\\1", $class_new));
2151 2151
 		}
2152 2152
 	}
2153 2153
 
@@ -2210,7 +2210,7 @@  discard block
 block discarded – undo
2210 2210
 // Quelques fonctions de calcul arithmetique
2211 2211
 //
2212 2212
 function floatstr($a) {
2213
- return str_replace(',', '.', (string)floatval($a));
2213
+ return str_replace(',', '.', (string) floatval($a));
2214 2214
 }
2215 2215
 function strize($f, $a, $b) {
2216 2216
  return floatstr($f(floatstr($a), floatstr($b)));
@@ -2344,13 +2344,13 @@  discard block
 block discarded – undo
2344 2344
 	if (!defined('_TAGS_NOM_AUTEUR')) {
2345 2345
 		define('_TAGS_NOM_AUTEUR', '');
2346 2346
 	}
2347
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2347
+	$tags_acceptes = array_unique(explode(',', 'multi,'._TAGS_NOM_AUTEUR));
2348 2348
 	foreach ($tags_acceptes as $tag) {
2349 2349
 		if (strlen($tag)) {
2350
-			$remp1[] = '<' . trim($tag) . '>';
2351
-			$remp1[] = '</' . trim($tag) . '>';
2352
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2353
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2350
+			$remp1[] = '<'.trim($tag).'>';
2351
+			$remp1[] = '</'.trim($tag).'>';
2352
+			$remp2[] = '\x60'.trim($tag).'\x61';
2353
+			$remp2[] = '\x60/'.trim($tag).'\x61';
2354 2354
 		}
2355 2355
 	}
2356 2356
 	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
@@ -2404,7 +2404,7 @@  discard block
 block discarded – undo
2404 2404
 				. http_img_pack(
2405 2405
 					'attachment-16.png',
2406 2406
 					$t,
2407
-					'title="' . attribut_html($t) . '"'
2407
+					'title="'.attribut_html($t).'"'
2408 2408
 				)
2409 2409
 				. '</a>',
2410 2410
 				$tag
@@ -2468,10 +2468,10 @@  discard block
 block discarded – undo
2468 2468
 	$fichier = basename($url);
2469 2469
 
2470 2470
 	return '<a rel="enclosure"'
2471
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2472
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2473
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2474
-	. '>' . $fichier . '</a>';
2471
+	. ($url ? ' href="'.spip_htmlspecialchars($url).'"' : '')
2472
+	. ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '')
2473
+	. ($length ? ' title="'.spip_htmlspecialchars($length).'"' : '')
2474
+	. '>'.$fichier.'</a>';
2475 2475
 }
2476 2476
 
2477 2477
 /**
@@ -2499,9 +2499,9 @@  discard block
 block discarded – undo
2499 2499
 			} # vieux data
2500 2500
 			$fichier = basename($url);
2501 2501
 			$enclosures[] = '<enclosure'
2502
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2503
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2504
-				. ($length ? ' length="' . $length . '"' : '')
2502
+				. ($url ? ' url="'.spip_htmlspecialchars($url).'"' : '')
2503
+				. ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '')
2504
+				. ($length ? ' length="'.$length.'"' : '')
2505 2505
 				. ' />';
2506 2506
 		}
2507 2507
 	}
@@ -2527,7 +2527,7 @@  discard block
 block discarded – undo
2527 2527
 		if (extraire_attribut($e, 'rel') == 'tag') {
2528 2528
 			$subjects .= '<dc:subject>'
2529 2529
 				. texte_backend(textebrut($e))
2530
-				. '</dc:subject>' . "\n";
2530
+				. '</dc:subject>'."\n";
2531 2531
 		}
2532 2532
 	}
2533 2533
 
@@ -2563,7 +2563,7 @@  discard block
 block discarded – undo
2563 2563
 	if (is_array($texte)) {
2564 2564
 		array_walk(
2565 2565
 			$texte,
2566
-			function (&$a, $key, $t) {
2566
+			function(&$a, $key, $t) {
2567 2567
 				$a = extraire_balise($a, $t);
2568 2568
 			},
2569 2569
 			$tag
@@ -2611,7 +2611,7 @@  discard block
 block discarded – undo
2611 2611
 	if (is_array($texte)) {
2612 2612
 		array_walk(
2613 2613
 			$texte,
2614
-			function (&$a, $key, $t) {
2614
+			function(&$a, $key, $t) {
2615 2615
 				$a = extraire_balises($a, $t);
2616 2616
 			},
2617 2617
 			$tag
@@ -2743,7 +2743,7 @@  discard block
 block discarded – undo
2743 2743
 		if ($fond != '404') {
2744 2744
 			$contexte = array_shift($p);
2745 2745
 			$contexte['page'] = $fond;
2746
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2746
+			$action = preg_replace('/([?]'.preg_quote($fond).'[^&=]*[0-9]+)(&|$)/', '?&', $action);
2747 2747
 		}
2748 2748
 	}
2749 2749
 	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
@@ -2798,9 +2798,9 @@  discard block
 block discarded – undo
2798 2798
 			. '"'
2799 2799
 			. (is_null($val)
2800 2800
 				? ''
2801
-				: ' value="' . entites_html($val) . '"'
2801
+				: ' value="'.entites_html($val).'"'
2802 2802
 			)
2803
-			. ' type="hidden"' . "\n/>";
2803
+			. ' type="hidden"'."\n/>";
2804 2804
 	}
2805 2805
 
2806 2806
 	return join('', $hidden);
@@ -2910,8 +2910,8 @@  discard block
 block discarded – undo
2910 2910
 
2911 2911
 	return preg_replace_callback(
2912 2912
 		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2913
-		function ($x) use ($path) {
2914
-			return "url('" . suivre_lien($path, $x[1]) . "')";
2913
+		function($x) use ($path) {
2914
+			return "url('".suivre_lien($path, $x[1])."')";
2915 2915
 		},
2916 2916
 		$contenu
2917 2917
 	);
@@ -2973,14 +2973,14 @@  discard block
 block discarded – undo
2973 2973
 	) {
2974 2974
 		$distant = true;
2975 2975
 		$cssf = parse_url($css);
2976
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2976
+		$cssf = $cssf['path'].($cssf['query'] ? '?'.$cssf['query'] : '');
2977 2977
 		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2978 2978
 	} else {
2979 2979
 		$distant = false;
2980 2980
 		$cssf = $css;
2981 2981
 		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2982 2982
 		//propose (rien a faire dans ce cas)
2983
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2983
+		$f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css);
2984 2984
 		if (@file_exists($f)) {
2985 2985
 			return $f;
2986 2986
 		}
@@ -2990,7 +2990,7 @@  discard block
 block discarded – undo
2990 2990
 	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2991 2991
 	$f = $dir_var
2992 2992
 		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2993
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2993
+		. '.'.substr(md5($cssf), 0, 4).'_'.$ndir.'.css';
2994 2994
 
2995 2995
 	// la css peut etre distante (url absolue !)
2996 2996
 	if ($distant) {
@@ -3036,8 +3036,8 @@  discard block
 block discarded – undo
3036 3036
 		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
3037 3037
 		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3038 3038
 			$css_direction = substr($css_direction, strlen($dir_var));
3039
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3040
-			$css_direction = '/@@@@@@/' . $css_direction;
3039
+			$src_faux_abs['/@@@@@@/'.$css_direction] = $css_direction;
3040
+			$css_direction = '/@@@@@@/'.$css_direction;
3041 3041
 		}
3042 3042
 		$src[] = $regs[0][$k];
3043 3043
 		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
@@ -3086,7 +3086,7 @@  discard block
 block discarded – undo
3086 3086
 
3087 3087
 	$f = basename($css, '.css');
3088 3088
 	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3089
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3089
+		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-".substr(md5("$css-urlabs"), 0, 4)."\\2", $f)
3090 3090
 		. '.css';
3091 3091
 
3092 3092
 	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
@@ -3096,7 +3096,7 @@  discard block
 block discarded – undo
3096 3096
 	if ($url_absolue_css == $css) {
3097 3097
 		if (
3098 3098
 			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3099
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3099
+			or !lire_fichier(_DIR_RACINE.substr($css, $l), $contenu)
3100 3100
 		) {
3101 3101
 			include_spip('inc/distant');
3102 3102
 			$contenu = recuperer_url($css);
@@ -3208,7 +3208,7 @@  discard block
 block discarded – undo
3208 3208
 	$expression = str_replace('\/', '/', $expression);
3209 3209
 	$expression = str_replace('/', '\/', $expression);
3210 3210
 
3211
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3211
+	if (preg_match('/'.$expression.'/'.$modif, $texte ?? '', $r)) {
3212 3212
 		if (isset($r[$capte])) {
3213 3213
 			return $r[$capte];
3214 3214
 		} else {
@@ -3246,7 +3246,7 @@  discard block
 block discarded – undo
3246 3246
 	$expression = str_replace('\/', '/', $expression);
3247 3247
 	$expression = str_replace('/', '\/', $expression);
3248 3248
 
3249
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3249
+	return preg_replace('/'.$expression.'/'.$modif, $replace, $texte);
3250 3250
 }
3251 3251
 
3252 3252
 
@@ -3265,7 +3265,7 @@  discard block
 block discarded – undo
3265 3265
 function traiter_doublons_documents(&$doublons, $letexte) {
3266 3266
 
3267 3267
 	// Verifier dans le texte & les notes (pas beau, helas)
3268
-	$t = $letexte . $GLOBALS['les_notes'];
3268
+	$t = $letexte.$GLOBALS['les_notes'];
3269 3269
 
3270 3270
 	if (
3271 3271
 		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
@@ -3279,7 +3279,7 @@  discard block
 block discarded – undo
3279 3279
 		if (!isset($doublons['documents'])) {
3280 3280
 			$doublons['documents'] = '';
3281 3281
 		}
3282
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3282
+		$doublons['documents'] .= ','.join(',', $matches[1]);
3283 3283
 	}
3284 3284
 
3285 3285
 	return $letexte;
@@ -3336,7 +3336,7 @@  discard block
 block discarded – undo
3336 3336
 	if ($env) {
3337 3337
 		foreach ($env as $i => $j) {
3338 3338
 			if (is_string($j) and !in_array($i, $ignore_params)) {
3339
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3339
+				$texte .= "<param name='".attribut_html($i)."'\n\tvalue='".attribut_html($j)."' />";
3340 3340
 			}
3341 3341
 		}
3342 3342
 	}
@@ -3375,7 +3375,7 @@  discard block
 block discarded – undo
3375 3375
 	if ($env) {
3376 3376
 		foreach ($env as $i => $j) {
3377 3377
 			if (is_string($j) and !in_array($i, $ignore_params)) {
3378
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3378
+				$texte .= attribut_html($i)."='".attribut_html($j)."' ";
3379 3379
 			}
3380 3380
 		}
3381 3381
 	}
@@ -3449,10 +3449,10 @@  discard block
 block discarded – undo
3449 3449
 	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3450 3450
 	if (
3451 3451
 		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3452
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3452
+		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])).'-xx.svg'
3453 3453
 		and file_exists($variante_svg_generique)
3454 3454
 	) {
3455
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3455
+		if ($variante_svg_size = substr($variante_svg_generique, 0, -6).$m[1].'.svg' and file_exists($variante_svg_size)) {
3456 3456
 			$img_file = $variante_svg_size;
3457 3457
 		}
3458 3458
 		else {
@@ -3510,7 +3510,7 @@  discard block
 block discarded – undo
3510 3510
 				return '';
3511 3511
 			}
3512 3512
 		}
3513
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3513
+		$atts .= " width='".$largeur."' height='".$hauteur."'";
3514 3514
 	}
3515 3515
 
3516 3516
 	if (file_exists($img_file)) {
@@ -3520,14 +3520,14 @@  discard block
 block discarded – undo
3520 3520
 		$alt = '';
3521 3521
 	}
3522 3522
 	elseif ($alt or $alt === '') {
3523
-		$alt = " alt='" . attribut_html($alt) . "'";
3523
+		$alt = " alt='".attribut_html($alt)."'";
3524 3524
 	}
3525 3525
 	else {
3526
-		$alt = " alt='" . attribut_html($title) . "'";
3526
+		$alt = " alt='".attribut_html($title)."'";
3527 3527
 	}
3528 3528
 	return "<img src='$img_file'$alt"
3529
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3530
-	. ' ' . ltrim($atts)
3529
+	. ($title ? ' title="'.attribut_html($title).'"' : '')
3530
+	. ' '.ltrim($atts)
3531 3531
 	. ' />';
3532 3532
 }
3533 3533
 
@@ -3541,10 +3541,10 @@  discard block
 block discarded – undo
3541 3541
  */
3542 3542
 function http_style_background($img, $att = '', $size = null) {
3543 3543
 	if ($size and is_numeric($size)) {
3544
-		$size = trim($size) . 'px';
3544
+		$size = trim($size).'px';
3545 3545
 	}
3546
-	return " style='background" .
3547
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3546
+	return " style='background".
3547
+		($att ? '' : '-image').': url("'.chemin_image($img).'")'.($att ? (' '.$att) : '').';'
3548 3548
 		. ($size ? "background-size:{$size};" : '')
3549 3549
 		. "'";
3550 3550
 }
@@ -3659,7 +3659,7 @@  discard block
 block discarded – undo
3659 3659
 		$img = http_img_pack(
3660 3660
 			$img,
3661 3661
 			$alt,
3662
-			$class ? " class='" . attribut_html($class) . "'" : '',
3662
+			$class ? " class='".attribut_html($class)."'" : '',
3663 3663
 			'',
3664 3664
 			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3665 3665
 		);
@@ -3743,7 +3743,7 @@  discard block
 block discarded – undo
3743 3743
 	$balise_svg_source = $balise_svg;
3744 3744
 
3745 3745
 	// entete XML à supprimer
3746
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3746
+	$svg = preg_replace(',^\s*<\?xml[^>]*\?'.'>,', '', $svg);
3747 3747
 
3748 3748
 	// IE est toujours mon ami
3749 3749
 	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
@@ -3761,9 +3761,9 @@  discard block
 block discarded – undo
3761 3761
 	// regler le alt
3762 3762
 	if ($alt) {
3763 3763
 		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3764
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3764
+		$id = 'img-svg-title-'.substr(md5("$img_file:$svg:$alt"), 0, 4);
3765 3765
 		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3766
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3766
+		$title = "<title id=\"$id\">".entites_html($alt)."</title>\n";
3767 3767
 		$balise_svg .= $title;
3768 3768
 	}
3769 3769
 	else {
@@ -3811,7 +3811,7 @@  discard block
 block discarded – undo
3811 3811
 	if (is_array($tableau)) {
3812 3812
 		foreach ($tableau as $k => $v) {
3813 3813
 			$res = recuperer_fond(
3814
-				'modeles/' . $modele,
3814
+				'modeles/'.$modele,
3815 3815
 				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3816 3816
 			);
3817 3817
 			$texte .= $res;
@@ -3995,7 +3995,7 @@  discard block
 block discarded – undo
3995 3995
 	}
3996 3996
 
3997 3997
 	$c = serialize($c);
3998
-	$cle = calculer_cle_action($form . $c);
3998
+	$cle = calculer_cle_action($form.$c);
3999 3999
 	$c = "$cle:$c";
4000 4000
 
4001 4001
 	// on ne stocke pas les contextes dans des fichiers en cache
@@ -4053,15 +4053,15 @@  discard block
 block discarded – undo
4053 4053
 	}
4054 4054
 	// toujours encoder l'url source dans le bloc ajax
4055 4055
 	$r = self();
4056
-	$r = ' data-origin="' . $r . '"';
4056
+	$r = ' data-origin="'.$r.'"';
4057 4057
 	$class = 'ajaxbloc';
4058 4058
 	if ($ajaxid and is_string($ajaxid)) {
4059 4059
 		// ajaxid est normalement conforme a un nom de classe css
4060 4060
 		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4061
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4061
+		$class .= ' ajax-id-'.entites_html($ajaxid);
4062 4062
 	}
4063 4063
 
4064
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4064
+	return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4065 4065
 }
4066 4066
 
4067 4067
 /**
@@ -4105,7 +4105,7 @@  discard block
 block discarded – undo
4105 4105
 		$cle = substr($c, 0, $p);
4106 4106
 		$c = substr($c, $p + 1);
4107 4107
 
4108
-		if ($cle == calculer_cle_action($form . $c)) {
4108
+		if ($cle == calculer_cle_action($form.$c)) {
4109 4109
 			$env = @unserialize($c);
4110 4110
 			return $env;
4111 4111
 		}
@@ -4226,13 +4226,13 @@  discard block
 block discarded – undo
4226 4226
 				}
4227 4227
 			}
4228 4228
 		}
4229
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4229
+		$att .= 'class="'.($class ? attribut_html($class).' ' : '').(defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on').'"';
4230 4230
 	} else {
4231 4231
 		$bal = 'a';
4232 4232
 		$att = "href='$url'"
4233
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4234
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4235
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4233
+			. ($title ? " title='".attribut_html($title)."'" : '')
4234
+			. ($class ? " class='".attribut_html($class)."'" : '')
4235
+			. ($rel ? " rel='".attribut_html($rel)."'" : '')
4236 4236
 			. $evt;
4237 4237
 	}
4238 4238
 	if ($libelle === null) {
@@ -4371,7 +4371,7 @@  discard block
 block discarded – undo
4371 4371
 
4372 4372
 	// Icône
4373 4373
 	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4374
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4374
+	$icone = '<span class="icone-image'.($fonction ? " icone-fonction icone-fonction-$fonction" : '')."\">$icone</span>";
4375 4375
 
4376 4376
 	// Markup final
4377 4377
 	if ($type == 'lien') {
@@ -4648,20 +4648,20 @@  discard block
 block discarded – undo
4648 4648
 		$class_form = 'ajax';
4649 4649
 		$class = str_replace('ajax', '', $class);
4650 4650
 	}
4651
-	$class_btn = 'submit ' . trim($class);
4651
+	$class_btn = 'submit '.trim($class);
4652 4652
 
4653 4653
 	if ($confirm) {
4654
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4654
+		$confirm = 'confirm("'.attribut_html($confirm).'")';
4655 4655
 		if ($callback) {
4656 4656
 			$callback = "$confirm?($callback):false";
4657 4657
 		} else {
4658 4658
 			$callback = $confirm;
4659 4659
 		}
4660 4660
 	}
4661
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4661
+	$onclick = $callback ? " onclick='return ".addcslashes($callback, "'")."'" : '';
4662 4662
 	$title = $title ? " title='$title'" : '';
4663 4663
 
4664
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4664
+	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>".form_hidden($url)
4665 4665
 	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4666 4666
 }
4667 4667
 
@@ -4726,14 +4726,14 @@  discard block
 block discarded – undo
4726 4726
 		$champ_titre = '';
4727 4727
 		if ($demande_titre) {
4728 4728
 			// si pas de titre declare mais champ titre, il sera peuple par le select *
4729
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4729
+			$champ_titre = (!empty($desc['titre'])) ? ', '.$desc['titre'] : '';
4730 4730
 		}
4731 4731
 		include_spip('base/abstract_sql');
4732 4732
 		include_spip('base/connect_sql');
4733 4733
 		$objets[$type_objet][$id_objet] = sql_fetsel(
4734
-			'*' . $champ_titre,
4734
+			'*'.$champ_titre,
4735 4735
 			$desc['table_sql'],
4736
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4736
+			id_table_objet($type_objet).' = '.intval($id_objet)
4737 4737
 		);
4738 4738
 
4739 4739
 		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
@@ -4811,8 +4811,7 @@  discard block
 block discarded – undo
4811 4811
 	if (isset($ligne_sql['chapo'])) {
4812 4812
 		$chapo = $ligne_sql['chapo'];
4813 4813
 		$texte = strlen($descriptif) ?
4814
-			'' :
4815
-			"$chapo \n\n $texte";
4814
+			'' : "$chapo \n\n $texte";
4816 4815
 	}
4817 4816
 
4818 4817
 	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
@@ -4879,7 +4878,7 @@  discard block
 block discarded – undo
4879 4878
 		return $texte;
4880 4879
 	}
4881 4880
 
4882
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4881
+	$traitement = str_replace('%s', "'".texte_script($texte)."'", $traitement);
4883 4882
 
4884 4883
 	// Fournir $connect et $Pile[0] au traitement si besoin
4885 4884
 	$Pile = [0 => $env];
@@ -4913,7 +4912,7 @@  discard block
 block discarded – undo
4913 4912
 	}
4914 4913
 	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4915 4914
 
4916
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4915
+	return "<a href='$url' class='$objet'>".couper($titre, $longueur).'</a>';
4917 4916
 }
4918 4917
 
4919 4918
 
@@ -4932,10 +4931,10 @@  discard block
 block discarded – undo
4932 4931
 function wrap($texte, $wrap) {
4933 4932
 	$balises = extraire_balises($wrap);
4934 4933
 	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4935
-		$texte = $wrap . $texte;
4934
+		$texte = $wrap.$texte;
4936 4935
 		$regs = array_reverse($regs[1]);
4937
-		$wrap = '</' . implode('></', $regs) . '>';
4938
-		$texte = $texte . $wrap;
4936
+		$wrap = '</'.implode('></', $regs).'>';
4937
+		$texte = $texte.$wrap;
4939 4938
 	}
4940 4939
 
4941 4940
 	return $texte;
@@ -4966,7 +4965,7 @@  discard block
 block discarded – undo
4966 4965
 
4967 4966
 	// caster $u en array si besoin
4968 4967
 	if (is_object($u)) {
4969
-		$u = (array)$u;
4968
+		$u = (array) $u;
4970 4969
 	}
4971 4970
 
4972 4971
 	if (is_array($u)) {
@@ -4988,7 +4987,7 @@  discard block
 block discarded – undo
4988 4987
 		// sinon on passe a la ligne et on indente
4989 4988
 		$i_str = str_pad('', $indent, ' ');
4990 4989
 		foreach ($u as $k => $v) {
4991
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4990
+			$out .= $join.$i_str."$k: ".filtre_print_dist($v, $join, $indent + 2);
4992 4991
 		}
4993 4992
 
4994 4993
 		return $out;
@@ -5042,7 +5041,7 @@  discard block
 block discarded – undo
5042 5041
  * @return string
5043 5042
  */
5044 5043
 function objet_icone($objet, $taille = 24, $class = '') {
5045
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5044
+	$icone = objet_info($objet, 'icone_objet').'-'.$taille.'.png';
5046 5045
 	$icone = chemin_image($icone);
5047 5046
 	$balise_img = charger_filtre('balise_img');
5048 5047
 
@@ -5068,7 +5067,7 @@  discard block
 block discarded – undo
5068 5067
  */
5069 5068
 function objet_T($objet, $chaine, $args = [], $options = []) {
5070 5069
 	$chaine = explode(':', $chaine);
5071
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5070
+	if ($t = _T($objet.':'.end($chaine), $args, array_merge($options, ['force' => false]))) {
5072 5071
 		return $t;
5073 5072
 	}
5074 5073
 	$chaine = implode(':', $chaine);
@@ -5134,7 +5133,7 @@  discard block
 block discarded – undo
5134 5133
 	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5135 5134
 
5136 5135
 	// calculer le nom de la css
5137
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5136
+	$dir_var = sous_repertoire(_DIR_VAR, 'cache-'.$extension);
5138 5137
 	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5139 5138
 	$contexte_implicite = calculer_contexte_implicite();
5140 5139
 
@@ -5142,14 +5141,14 @@  discard block
 block discarded – undo
5142 5141
 	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5143 5142
 	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5144 5143
 	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5145
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5144
+		$hash = md5($contexte_implicite['host'].'::'.$cache);
5146 5145
 	}
5147 5146
 	else {
5148 5147
 		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5149 5148
 		ksort($contexte);
5150
-		$hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
5149
+		$hash = md5($fond.json_encode($contexte_implicite).json_encode($contexte).$connect);
5151 5150
 	}
5152
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5151
+	$filename = $dir_var.$extension."dyn-$nom_safe-".substr($hash, 0, 8).".$extension";
5153 5152
 
5154 5153
 	// mettre a jour le fichier si il n'existe pas
5155 5154
 	// ou trop ancien
@@ -5157,8 +5156,8 @@  discard block
 block discarded – undo
5157 5156
 	// et recopie sur le fichier cible uniquement si il change
5158 5157
 	if (
5159 5158
 		!file_exists($filename)
5160
-		or !file_exists($filename . '.last')
5161
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5159
+		or !file_exists($filename.'.last')
5160
+		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename.'.last') < $cache['lastmodified'])
5162 5161
 		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5163 5162
 	) {
5164 5163
 		$contenu = $cache['texte'];
@@ -5179,10 +5178,10 @@  discard block
 block discarded – undo
5179 5178
 			}
5180 5179
 			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5181 5180
 			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5182
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5181
+			$comment .= "}\n   md5:".md5($contenu)." */\n";
5183 5182
 		}
5184 5183
 		// et ecrire le fichier si il change
5185
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5184
+		ecrire_fichier_calcule_si_modifie($filename, $comment.$contenu, false, true);
5186 5185
 	}
5187 5186
 
5188 5187
 	return timestamp($filename);
@@ -5408,7 +5407,7 @@  discard block
 block discarded – undo
5408 5407
 	if ($e > 0 and strlen($mid) > 8) {
5409 5408
 		$mid = '***...***';
5410 5409
 	}
5411
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5410
+	return substr($passe, 0, $e).$mid.($e > 0 ? substr($passe, -$e) : '');
5412 5411
 }
5413 5412
 
5414 5413
 
@@ -5470,7 +5469,7 @@  discard block
 block discarded – undo
5470 5469
 		case 'id':
5471 5470
 		case 'anchor':
5472 5471
 			if (preg_match(',^\d,', $texte)) {
5473
-				$texte = substr($type, 0, 1) . $texte;
5472
+				$texte = substr($type, 0, 1).$texte;
5474 5473
 			}
5475 5474
 	}
5476 5475
 
@@ -5480,9 +5479,9 @@  discard block
 block discarded – undo
5480 5479
 
5481 5480
 	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5482 5481
 		if (preg_match(',^\d,', $texte)) {
5483
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5482
+			$texte = ($type ? substr($type, 0, 1) : 's').$texte;
5484 5483
 		}
5485
-		$texte .= $separateur . md5($original);
5484
+		$texte .= $separateur.md5($original);
5486 5485
 		$texte = substr($texte, 0, $longueur_mini);
5487 5486
 	}
5488 5487
 
Please login to merge, or discard this patch.
Braces   +10 added lines, -20 removed lines patch added patch discarded remove patch
@@ -631,8 +631,7 @@  discard block
 block discarded – undo
631 631
 			if (!$srcHeight) {
632 632
 				$hauteur_img[$src] = $srcHeight = $srcsize[1];
633 633
 			}
634
-		}
635
-		elseif (strpos($src, '<svg') !== false) {
634
+		} elseif (strpos($src, '<svg') !== false) {
636 635
 			include_spip('inc/svg');
637 636
 			if ($attrs = svg_lire_attributs($src)) {
638 637
 				list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
@@ -3454,8 +3453,7 @@  discard block
 block discarded – undo
3454 3453
 	) {
3455 3454
 		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3456 3455
 			$img_file = $variante_svg_size;
3457
-		}
3458
-		else {
3456
+		} else {
3459 3457
 			$img_file = $variante_svg_generique;
3460 3458
 		}
3461 3459
 	}
@@ -3487,8 +3485,7 @@  discard block
 block discarded – undo
3487 3485
 	}
3488 3486
 	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3489 3487
 		$img_file = chemin_image($img);
3490
-	}
3491
-	else {
3488
+	} else {
3492 3489
 		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3493 3490
 			$img_file = http_img_variante_svg_si_possible($img_file);
3494 3491
 		}
@@ -3518,11 +3515,9 @@  discard block
 block discarded – undo
3518 3515
 	}
3519 3516
 	if ($alt === false) {
3520 3517
 		$alt = '';
3521
-	}
3522
-	elseif ($alt or $alt === '') {
3518
+	} elseif ($alt or $alt === '') {
3523 3519
 		$alt = " alt='" . attribut_html($alt) . "'";
3524
-	}
3525
-	else {
3520
+	} else {
3526 3521
 		$alt = " alt='" . attribut_html($title) . "'";
3527 3522
 	}
3528 3523
 	return "<img src='$img_file'$alt"
@@ -3649,13 +3644,11 @@  discard block
 block discarded – undo
3649 3644
 		if (!is_null($class)) {
3650 3645
 			if (strlen($class)) {
3651 3646
 				$img = inserer_attribut($img, 'class', $class);
3652
-			}
3653
-			else {
3647
+			} else {
3654 3648
 				$img = vider_attribut($img, 'class');
3655 3649
 			}
3656 3650
 		}
3657
-	}
3658
-	else {
3651
+	} else {
3659 3652
 		$img = http_img_pack(
3660 3653
 			$img,
3661 3654
 			$alt,
@@ -3752,8 +3745,7 @@  discard block
 block discarded – undo
3752 3745
 	if (!is_null($class)) {
3753 3746
 		if (strlen($class)) {
3754 3747
 			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3755
-		}
3756
-		else {
3748
+		} else {
3757 3749
 			$balise_svg = vider_attribut($balise_svg, 'class');
3758 3750
 		}
3759 3751
 	}
@@ -3765,8 +3757,7 @@  discard block
 block discarded – undo
3765 3757
 		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3766 3758
 		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3767 3759
 		$balise_svg .= $title;
3768
-	}
3769
-	else {
3760
+	} else {
3770 3761
 		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3771 3762
 	}
3772 3763
 
@@ -5143,8 +5134,7 @@  discard block
 block discarded – undo
5143 5134
 	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5144 5135
 	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5145 5136
 		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5146
-	}
5147
-	else {
5137
+	} else {
5148 5138
 		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5149 5139
 		ksort($contexte);
5150 5140
 		$hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
Please login to merge, or discard this patch.
ecrire/inc/documents.php 2 patches
Indentation   +227 added lines, -227 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
 /**
@@ -30,12 +30,12 @@  discard block
 block discarded – undo
30 30
  * @return string
31 31
  */
32 32
 function set_spip_doc(?string $fichier): string {
33
-	if ($fichier and strpos($fichier, _DIR_IMG) === 0) {
34
-		return substr($fichier, strlen(_DIR_IMG));
35
-	} else {
36
-		// ex: fichier distant
37
-		return $fichier ?? '';
38
-	} 
33
+    if ($fichier and strpos($fichier, _DIR_IMG) === 0) {
34
+        return substr($fichier, strlen(_DIR_IMG));
35
+    } else {
36
+        // ex: fichier distant
37
+        return $fichier ?? '';
38
+    } 
39 39
 }
40 40
 
41 41
 /**
@@ -47,26 +47,26 @@  discard block
 block discarded – undo
47 47
  * @return bool|string
48 48
  */
49 49
 function get_spip_doc(?string $fichier) {
50
-	if ($fichier === null) {
51
-		return false;
52
-	}
53
-
54
-	// fichier distant
55
-	if (tester_url_absolue($fichier)) {
56
-		return $fichier;
57
-	}
58
-
59
-	// gestion d'erreurs, fichier=''
60
-	if (!strlen($fichier)) {
61
-		return false;
62
-	}
63
-
64
-	if (strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) !== 0) {
65
-		$fichier = _DIR_IMG . $fichier;
66
-	}
67
-
68
-	// fichier normal
69
-	return $fichier;
50
+    if ($fichier === null) {
51
+        return false;
52
+    }
53
+
54
+    // fichier distant
55
+    if (tester_url_absolue($fichier)) {
56
+        return $fichier;
57
+    }
58
+
59
+    // gestion d'erreurs, fichier=''
60
+    if (!strlen($fichier)) {
61
+        return false;
62
+    }
63
+
64
+    if (strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) !== 0) {
65
+        $fichier = _DIR_IMG . $fichier;
66
+    }
67
+
68
+    // fichier normal
69
+    return $fichier;
70 70
 }
71 71
 
72 72
 /**
@@ -80,26 +80,26 @@  discard block
 block discarded – undo
80 80
  * @return string
81 81
  */
82 82
 function creer_repertoire_documents($ext) {
83
-	$rep = sous_repertoire(_DIR_IMG, $ext);
84
-
85
-	if (!$ext or !$rep) {
86
-		spip_log("creer_repertoire_documents '$rep' interdit");
87
-		exit;
88
-	}
89
-
90
-	// Cette variable de configuration peut etre posee par un plugin
91
-	// par exemple acces_restreint
92
-	// sauf pour logo/ utilise pour stocker les logoon et logooff
93
-	if (
94
-		isset($GLOBALS['meta']['creer_htaccess'])
95
-		and $GLOBALS['meta']['creer_htaccess'] == 'oui'
96
-		and $ext !== 'logo'
97
-	) {
98
-		include_spip('inc/acces');
99
-		verifier_htaccess($rep);
100
-	}
101
-
102
-	return $rep;
83
+    $rep = sous_repertoire(_DIR_IMG, $ext);
84
+
85
+    if (!$ext or !$rep) {
86
+        spip_log("creer_repertoire_documents '$rep' interdit");
87
+        exit;
88
+    }
89
+
90
+    // Cette variable de configuration peut etre posee par un plugin
91
+    // par exemple acces_restreint
92
+    // sauf pour logo/ utilise pour stocker les logoon et logooff
93
+    if (
94
+        isset($GLOBALS['meta']['creer_htaccess'])
95
+        and $GLOBALS['meta']['creer_htaccess'] == 'oui'
96
+        and $ext !== 'logo'
97
+    ) {
98
+        include_spip('inc/acces');
99
+        verifier_htaccess($rep);
100
+    }
101
+
102
+    return $rep;
103 103
 }
104 104
 
105 105
 /**
@@ -108,22 +108,22 @@  discard block
 block discarded – undo
108 108
  * @param string $nom
109 109
  */
110 110
 function effacer_repertoire_temporaire($nom) {
111
-	if ($d = opendir($nom)) {
112
-		while (($f = readdir($d)) !== false) {
113
-			if (is_file("$nom/$f")) {
114
-				spip_unlink("$nom/$f");
115
-			} else {
116
-				if (
117
-					$f <> '.' and $f <> '..'
118
-					and is_dir("$nom/$f")
119
-				) {
120
-					effacer_repertoire_temporaire("$nom/$f");
121
-				}
122
-			}
123
-		}
124
-	}
125
-	closedir($d);
126
-	@rmdir($nom);
111
+    if ($d = opendir($nom)) {
112
+        while (($f = readdir($d)) !== false) {
113
+            if (is_file("$nom/$f")) {
114
+                spip_unlink("$nom/$f");
115
+            } else {
116
+                if (
117
+                    $f <> '.' and $f <> '..'
118
+                    and is_dir("$nom/$f")
119
+                ) {
120
+                    effacer_repertoire_temporaire("$nom/$f");
121
+                }
122
+            }
123
+        }
124
+    }
125
+    closedir($d);
126
+    @rmdir($nom);
127 127
 }
128 128
 
129 129
 //
@@ -140,45 +140,45 @@  discard block
 block discarded – undo
140 140
  */
141 141
 function copier_document($ext, $orig, $source, $subdir = null) {
142 142
 
143
-	$orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc
144
-	$dir = creer_repertoire_documents($subdir ? $subdir : $ext);
145
-
146
-	$dest = preg_replace('/<[^>]*>/', '', basename($orig));
147
-	$dest = preg_replace('/\.([^.]+)$/', '', $dest);
148
-	$dest = translitteration($dest);
149
-	$dest = preg_replace('/[^.=\w-]+/', '_', $dest);
150
-
151
-	// ne pas accepter de noms de la forme -r90.jpg qui sont reserves
152
-	// pour les images transformees par rotation (action/documenter)
153
-	$dest = preg_replace(',-r(90|180|270)$,', '', $dest);
154
-
155
-	while (preg_match(',\.(\w+)$,', $dest, $m)) {
156
-		if (
157
-			!function_exists('verifier_upload_autorise')
158
-			or !$r = verifier_upload_autorise($dest)
159
-			or $r['autozip']
160
-		) {
161
-			$dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1];
162
-			break;
163
-		}
164
-		else {
165
-			$dest = substr($dest, 0, -strlen($m[0]));
166
-			$ext = $m[1] . '.' . $ext;
167
-		}
168
-	}
169
-
170
-	// Si le document "source" est deja au bon endroit, ne rien faire
171
-	if ($source == ($dir . $dest . '.' . $ext)) {
172
-		return $source;
173
-	}
174
-
175
-	// sinon tourner jusqu'a trouver un numero correct
176
-	$n = 0;
177
-	while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) {
178
-		;
179
-	}
180
-
181
-	return deplacer_fichier_upload($source, $newFile);
143
+    $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc
144
+    $dir = creer_repertoire_documents($subdir ? $subdir : $ext);
145
+
146
+    $dest = preg_replace('/<[^>]*>/', '', basename($orig));
147
+    $dest = preg_replace('/\.([^.]+)$/', '', $dest);
148
+    $dest = translitteration($dest);
149
+    $dest = preg_replace('/[^.=\w-]+/', '_', $dest);
150
+
151
+    // ne pas accepter de noms de la forme -r90.jpg qui sont reserves
152
+    // pour les images transformees par rotation (action/documenter)
153
+    $dest = preg_replace(',-r(90|180|270)$,', '', $dest);
154
+
155
+    while (preg_match(',\.(\w+)$,', $dest, $m)) {
156
+        if (
157
+            !function_exists('verifier_upload_autorise')
158
+            or !$r = verifier_upload_autorise($dest)
159
+            or $r['autozip']
160
+        ) {
161
+            $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1];
162
+            break;
163
+        }
164
+        else {
165
+            $dest = substr($dest, 0, -strlen($m[0]));
166
+            $ext = $m[1] . '.' . $ext;
167
+        }
168
+    }
169
+
170
+    // Si le document "source" est deja au bon endroit, ne rien faire
171
+    if ($source == ($dir . $dest . '.' . $ext)) {
172
+        return $source;
173
+    }
174
+
175
+    // sinon tourner jusqu'a trouver un numero correct
176
+    $n = 0;
177
+    while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) {
178
+        ;
179
+    }
180
+
181
+    return deplacer_fichier_upload($source, $newFile);
182 182
 }
183 183
 
184 184
 /**
@@ -193,28 +193,28 @@  discard block
 block discarded – undo
193 193
  * @return bool|string
194 194
  */
195 195
 function determine_upload($type = '') {
196
-	if (!function_exists('autoriser')) {
197
-		include_spip('inc/autoriser');
198
-	}
199
-
200
-	if (
201
-		!autoriser('chargerftp')
202
-		or $type == 'logos'
203
-	) { # on ne le permet pas pour les logos
204
-	return false;
205
-	}
206
-
207
-	$repertoire = _DIR_TRANSFERT;
208
-	if (!@is_dir($repertoire)) {
209
-		$repertoire = str_replace(_DIR_TMP, '', $repertoire);
210
-		$repertoire = sous_repertoire(_DIR_TMP, $repertoire);
211
-	}
212
-
213
-	if (!$GLOBALS['visiteur_session']['restreint']) {
214
-		return $repertoire;
215
-	} else {
216
-		return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']);
217
-	}
196
+    if (!function_exists('autoriser')) {
197
+        include_spip('inc/autoriser');
198
+    }
199
+
200
+    if (
201
+        !autoriser('chargerftp')
202
+        or $type == 'logos'
203
+    ) { # on ne le permet pas pour les logos
204
+    return false;
205
+    }
206
+
207
+    $repertoire = _DIR_TRANSFERT;
208
+    if (!@is_dir($repertoire)) {
209
+        $repertoire = str_replace(_DIR_TMP, '', $repertoire);
210
+        $repertoire = sous_repertoire(_DIR_TMP, $repertoire);
211
+    }
212
+
213
+    if (!$GLOBALS['visiteur_session']['restreint']) {
214
+        return $repertoire;
215
+    } else {
216
+        return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']);
217
+    }
218 218
 }
219 219
 
220 220
 /**
@@ -233,35 +233,35 @@  discard block
 block discarded – undo
233 233
  * @return bool|mixed|string
234 234
  */
235 235
 function deplacer_fichier_upload($source, $dest, $move = false) {
236
-	// Securite
237
-	if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) {
238
-		$dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE)));
239
-	} else {
240
-		$dest = preg_replace(',\.\.+,', '.', $dest);
241
-	}
242
-
243
-	if ($move) {
244
-		$ok = @rename($source, $dest);
245
-	} else {
246
-		$ok = @copy($source, $dest);
247
-	}
248
-	if (!$ok) {
249
-		$ok = @move_uploaded_file($source, $dest);
250
-	}
251
-	if ($ok) {
252
-		@chmod($dest, _SPIP_CHMOD & ~0111);
253
-	} else {
254
-		$f = @fopen($dest, 'w');
255
-		if ($f) {
256
-			fclose($f);
257
-		} else {
258
-			include_spip('inc/flock');
259
-			raler_fichier($dest);
260
-		}
261
-		spip_unlink($dest);
262
-	}
263
-
264
-	return $ok ? $dest : false;
236
+    // Securite
237
+    if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) {
238
+        $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE)));
239
+    } else {
240
+        $dest = preg_replace(',\.\.+,', '.', $dest);
241
+    }
242
+
243
+    if ($move) {
244
+        $ok = @rename($source, $dest);
245
+    } else {
246
+        $ok = @copy($source, $dest);
247
+    }
248
+    if (!$ok) {
249
+        $ok = @move_uploaded_file($source, $dest);
250
+    }
251
+    if ($ok) {
252
+        @chmod($dest, _SPIP_CHMOD & ~0111);
253
+    } else {
254
+        $f = @fopen($dest, 'w');
255
+        if ($f) {
256
+            fclose($f);
257
+        } else {
258
+            include_spip('inc/flock');
259
+            raler_fichier($dest);
260
+        }
261
+        spip_unlink($dest);
262
+    }
263
+
264
+    return $ok ? $dest : false;
265 265
 }
266 266
 
267 267
 
@@ -285,60 +285,60 @@  discard block
 block discarded – undo
285 285
  */
286 286
 function check_upload_error($error, $msg = '', $return = false) {
287 287
 
288
-	if (!$error) {
289
-		return false;
290
-	}
291
-
292
-	spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php");
293
-
294
-	switch ($error) {
295
-		case 4: /* UPLOAD_ERR_NO_FILE */
296
-			return true;
297
-
298
-		# on peut affiner les differents messages d'erreur
299
-		case 1: /* UPLOAD_ERR_INI_SIZE */
300
-			$msg = _T(
301
-				'upload_limit',
302
-				['max' => ini_get('upload_max_filesize')]
303
-			);
304
-			break;
305
-		case 2: /* UPLOAD_ERR_FORM_SIZE */
306
-			$msg = _T(
307
-				'upload_limit',
308
-				['max' => ini_get('upload_max_filesize')]
309
-			);
310
-			break;
311
-		case 3: /* UPLOAD_ERR_PARTIAL  */
312
-			$msg = _T(
313
-				'upload_limit',
314
-				['max' => ini_get('upload_max_filesize')]
315
-			);
316
-			break;
317
-
318
-		default: /* autre */
319
-			if (!$msg) {
320
-				$msg = _T('pass_erreur') . ' ' . $error
321
-					. '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]');
322
-			}
323
-			break;
324
-	}
325
-
326
-	spip_log("erreur upload $error");
327
-	if ($return) {
328
-		return $msg;
329
-	}
330
-
331
-	if (_request('iframe') == 'iframe') {
332
-		echo "<div class='upload_answer upload_error'>$msg</div>";
333
-		exit;
334
-	}
335
-
336
-	include_spip('inc/minipres');
337
-	echo minipres(
338
-		$msg,
339
-		"<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>'
340
-	);
341
-	exit;
288
+    if (!$error) {
289
+        return false;
290
+    }
291
+
292
+    spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php");
293
+
294
+    switch ($error) {
295
+        case 4: /* UPLOAD_ERR_NO_FILE */
296
+            return true;
297
+
298
+        # on peut affiner les differents messages d'erreur
299
+        case 1: /* UPLOAD_ERR_INI_SIZE */
300
+            $msg = _T(
301
+                'upload_limit',
302
+                ['max' => ini_get('upload_max_filesize')]
303
+            );
304
+            break;
305
+        case 2: /* UPLOAD_ERR_FORM_SIZE */
306
+            $msg = _T(
307
+                'upload_limit',
308
+                ['max' => ini_get('upload_max_filesize')]
309
+            );
310
+            break;
311
+        case 3: /* UPLOAD_ERR_PARTIAL  */
312
+            $msg = _T(
313
+                'upload_limit',
314
+                ['max' => ini_get('upload_max_filesize')]
315
+            );
316
+            break;
317
+
318
+        default: /* autre */
319
+            if (!$msg) {
320
+                $msg = _T('pass_erreur') . ' ' . $error
321
+                    . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]');
322
+            }
323
+            break;
324
+    }
325
+
326
+    spip_log("erreur upload $error");
327
+    if ($return) {
328
+        return $msg;
329
+    }
330
+
331
+    if (_request('iframe') == 'iframe') {
332
+        echo "<div class='upload_answer upload_error'>$msg</div>";
333
+        exit;
334
+    }
335
+
336
+    include_spip('inc/minipres');
337
+    echo minipres(
338
+        $msg,
339
+        "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>'
340
+    );
341
+    exit;
342 342
 }
343 343
 
344 344
 /**
@@ -355,24 +355,24 @@  discard block
 block discarded – undo
355 355
  * @return string
356 356
  */
357 357
 function corriger_extension($ext) {
358
-	$ext = preg_replace(',[^a-z0-9],i', '', $ext);
359
-	switch ($ext) {
360
-		case 'htm':
361
-			$ext = 'html';
362
-			break;
363
-		case 'jpeg':
364
-			$ext = 'jpg';
365
-			break;
366
-		case 'tiff':
367
-			$ext = 'tif';
368
-			break;
369
-		case 'aif':
370
-			$ext = 'aiff';
371
-			break;
372
-		case 'mpeg':
373
-			$ext = 'mpg';
374
-			break;
375
-	}
376
-
377
-	return $ext;
358
+    $ext = preg_replace(',[^a-z0-9],i', '', $ext);
359
+    switch ($ext) {
360
+        case 'htm':
361
+            $ext = 'html';
362
+            break;
363
+        case 'jpeg':
364
+            $ext = 'jpg';
365
+            break;
366
+        case 'tiff':
367
+            $ext = 'tif';
368
+            break;
369
+        case 'aif':
370
+            $ext = 'aiff';
371
+            break;
372
+        case 'mpeg':
373
+            $ext = 'mpg';
374
+            break;
375
+    }
376
+
377
+    return $ext;
378 378
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	}
63 63
 
64 64
 	if (strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) !== 0) {
65
-		$fichier = _DIR_IMG . $fichier;
65
+		$fichier = _DIR_IMG.$fichier;
66 66
 	}
67 67
 
68 68
 	// fichier normal
@@ -158,23 +158,23 @@  discard block
 block discarded – undo
158 158
 			or !$r = verifier_upload_autorise($dest)
159 159
 			or $r['autozip']
160 160
 		) {
161
-			$dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1];
161
+			$dest = substr($dest, 0, -strlen($m[0])).'_'.$m[1];
162 162
 			break;
163 163
 		}
164 164
 		else {
165 165
 			$dest = substr($dest, 0, -strlen($m[0]));
166
-			$ext = $m[1] . '.' . $ext;
166
+			$ext = $m[1].'.'.$ext;
167 167
 		}
168 168
 	}
169 169
 
170 170
 	// Si le document "source" est deja au bon endroit, ne rien faire
171
-	if ($source == ($dir . $dest . '.' . $ext)) {
171
+	if ($source == ($dir.$dest.'.'.$ext)) {
172 172
 		return $source;
173 173
 	}
174 174
 
175 175
 	// sinon tourner jusqu'a trouver un numero correct
176 176
 	$n = 0;
177
-	while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) {
177
+	while (@file_exists($newFile = $dir.$dest.($n++ ? ('-'.$n) : '').'.'.$ext)) {
178 178
 		;
179 179
 	}
180 180
 
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 function deplacer_fichier_upload($source, $dest, $move = false) {
236 236
 	// Securite
237 237
 	if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) {
238
-		$dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE)));
238
+		$dest = _DIR_RACINE.preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE)));
239 239
 	} else {
240 240
 		$dest = preg_replace(',\.\.+,', '.', $dest);
241 241
 	}
@@ -317,8 +317,8 @@  discard block
 block discarded – undo
317 317
 
318 318
 		default: /* autre */
319 319
 			if (!$msg) {
320
-				$msg = _T('pass_erreur') . ' ' . $error
321
-					. '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]');
320
+				$msg = _T('pass_erreur').' '.$error
321
+					. '<br />'.propre('[->http://php.net/manual/fr/features.file-upload.errors.php]');
322 322
 			}
323 323
 			break;
324 324
 	}
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 	include_spip('inc/minipres');
337 337
 	echo minipres(
338 338
 		$msg,
339
-		"<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>'
339
+		"<div style='text-align: ".$GLOBALS['spip_lang_right']."'><a href='".rawurldecode($GLOBALS['redirect'])."'><button type='button'>"._T('ecrire:bouton_suivant').'</button></a></div>'
340 340
 	);
341 341
 	exit;
342 342
 }
Please login to merge, or discard this patch.
ecrire/inc/editer.php 2 patches
Indentation   +491 added lines, -491 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('base/abstract_sql');
23 23
 
@@ -59,56 +59,56 @@  discard block
 block discarded – undo
59 59
  *     Retour des traitements.
60 60
  **/
61 61
 function formulaires_editer_objet_traiter(
62
-	$type,
63
-	$id = 'new',
64
-	$id_parent = 0,
65
-	$lier_trad = 0,
66
-	$retour = '',
67
-	$config_fonc = 'articles_edit_config',
68
-	$row = [],
69
-	$hidden = ''
62
+    $type,
63
+    $id = 'new',
64
+    $id_parent = 0,
65
+    $lier_trad = 0,
66
+    $retour = '',
67
+    $config_fonc = 'articles_edit_config',
68
+    $row = [],
69
+    $hidden = ''
70 70
 ) {
71 71
 
72
-	$res = [];
73
-	// eviter la redirection forcee par l'action...
74
-	set_request('redirect');
75
-	if ($action_editer = charger_fonction("editer_$type", 'action', true)) {
76
-		list($id, $err) = $action_editer($id);
77
-	} else {
78
-		$action_editer = charger_fonction('editer_objet', 'action');
79
-		list($id, $err) = $action_editer($id, $type);
80
-	}
81
-	$id_table_objet = id_table_objet($type);
82
-	$res[$id_table_objet] = $id;
83
-	if ($err or !$id) {
84
-		$res['message_erreur'] = ($err ? $err : _T('erreur'));
85
-	} else {
86
-		// Un lien de trad a prendre en compte
87
-		if ($lier_trad) {
88
-			// referencer la traduction
89
-			$referencer_traduction = charger_fonction('referencer_traduction', 'action');
90
-			$referencer_traduction($type, $id, $lier_trad);
91
-			// actions de recopie de champs / liens sur le nouvel objet créé
92
-			$completer_traduction = charger_fonction('completer_traduction', 'inc');
93
-			$err = $completer_traduction($type, $id, $lier_trad);
94
-			if ($err) {
95
-				$res['message_erreur'] = $err;
96
-				return $res;
97
-			}
98
-		}
99
-
100
-		$res['message_ok'] = _T('info_modification_enregistree');
101
-		if ($retour) {
102
-			if (strncmp($retour, 'javascript:', 11) == 0) {
103
-				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
104
-				$res['editable'] = true;
105
-			} else {
106
-				$res['redirect'] = parametre_url($retour, $id_table_objet, $id);
107
-			}
108
-		}
109
-	}
110
-
111
-	return $res;
72
+    $res = [];
73
+    // eviter la redirection forcee par l'action...
74
+    set_request('redirect');
75
+    if ($action_editer = charger_fonction("editer_$type", 'action', true)) {
76
+        list($id, $err) = $action_editer($id);
77
+    } else {
78
+        $action_editer = charger_fonction('editer_objet', 'action');
79
+        list($id, $err) = $action_editer($id, $type);
80
+    }
81
+    $id_table_objet = id_table_objet($type);
82
+    $res[$id_table_objet] = $id;
83
+    if ($err or !$id) {
84
+        $res['message_erreur'] = ($err ? $err : _T('erreur'));
85
+    } else {
86
+        // Un lien de trad a prendre en compte
87
+        if ($lier_trad) {
88
+            // referencer la traduction
89
+            $referencer_traduction = charger_fonction('referencer_traduction', 'action');
90
+            $referencer_traduction($type, $id, $lier_trad);
91
+            // actions de recopie de champs / liens sur le nouvel objet créé
92
+            $completer_traduction = charger_fonction('completer_traduction', 'inc');
93
+            $err = $completer_traduction($type, $id, $lier_trad);
94
+            if ($err) {
95
+                $res['message_erreur'] = $err;
96
+                return $res;
97
+            }
98
+        }
99
+
100
+        $res['message_ok'] = _T('info_modification_enregistree');
101
+        if ($retour) {
102
+            if (strncmp($retour, 'javascript:', 11) == 0) {
103
+                $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
104
+                $res['editable'] = true;
105
+            } else {
106
+                $res['redirect'] = parametre_url($retour, $id_table_objet, $id);
107
+            }
108
+        }
109
+    }
110
+
111
+    return $res;
112 112
 }
113 113
 
114 114
 /**
@@ -132,29 +132,29 @@  discard block
 block discarded – undo
132 132
  *     Tableau des erreurs
133 133
  **/
134 134
 function formulaires_editer_objet_verifier($type, $id = 'new', $oblis = []) {
135
-	$erreurs = [];
136
-	if (intval($id)) {
137
-		$conflits = controler_contenu($type, $id);
138
-		if ($conflits and count($conflits)) {
139
-			foreach ($conflits as $champ => $conflit) {
140
-				if (!isset($erreurs[$champ])) {
141
-					$erreurs[$champ] = '';
142
-				}
143
-				$erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>';
144
-			}
145
-		}
146
-	}
147
-	foreach ($oblis as $obli) {
148
-		$value = _request($obli);
149
-		if (is_null($value) or !(is_array($value) ? count($value) : strlen($value))) {
150
-			if (!isset($erreurs[$obli])) {
151
-				$erreurs[$obli] = '';
152
-			}
153
-			$erreurs[$obli] .= _T('info_obligatoire');
154
-		}
155
-	}
156
-
157
-	return $erreurs;
135
+    $erreurs = [];
136
+    if (intval($id)) {
137
+        $conflits = controler_contenu($type, $id);
138
+        if ($conflits and count($conflits)) {
139
+            foreach ($conflits as $champ => $conflit) {
140
+                if (!isset($erreurs[$champ])) {
141
+                    $erreurs[$champ] = '';
142
+                }
143
+                $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>';
144
+            }
145
+        }
146
+    }
147
+    foreach ($oblis as $obli) {
148
+        $value = _request($obli);
149
+        if (is_null($value) or !(is_array($value) ? count($value) : strlen($value))) {
150
+            if (!isset($erreurs[$obli])) {
151
+                $erreurs[$obli] = '';
152
+            }
153
+            $erreurs[$obli] .= _T('info_obligatoire');
154
+        }
155
+    }
156
+
157
+    return $erreurs;
158 158
 }
159 159
 
160 160
 /**
@@ -199,151 +199,151 @@  discard block
 block discarded – undo
199 199
  *     Environnement du formulaire.
200 200
  **/
201 201
 function formulaires_editer_objet_charger(
202
-	$type,
203
-	$id = 'new',
204
-	$id_parent = 0,
205
-	$lier_trad = 0,
206
-	$retour = '',
207
-	$config_fonc = 'articles_edit_config',
208
-	$row = [],
209
-	$hidden = ''
202
+    $type,
203
+    $id = 'new',
204
+    $id_parent = 0,
205
+    $lier_trad = 0,
206
+    $retour = '',
207
+    $config_fonc = 'articles_edit_config',
208
+    $row = [],
209
+    $hidden = ''
210 210
 ) {
211 211
 
212
-	$table_objet = table_objet($type);
213
-	$table_objet_sql = table_objet_sql($type);
214
-	$id_table_objet = id_table_objet($type);
215
-
216
-	// on accepte pas une fonction de config inconnue si elle vient d'un modele
217
-	if (
218
-		$config_fonc
219
-		and !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config'])
220
-		and $config_fonc !== $table_objet . '_edit_config'
221
-	) {
222
-		if (
223
-			$args = test_formulaire_inclus_par_modele()
224
-			and in_array($config_fonc, $args)
225
-		) {
226
-			$config_fonc = '';
227
-		}
228
-	}
229
-
230
-	$new = !is_numeric($id);
231
-	$lang_default = '';
232
-	// Appel direct dans un squelette
233
-	if (!$row) {
234
-		if (!$new or $lier_trad) {
235
-			if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
236
-				$row = $select($id, $id_parent, $lier_trad);
237
-				// si on a une fonction precharger, elle pu faire un reglage de langue
238
-				$lang_default = (!empty($row['lang']) ? $row['lang'] : null);
239
-			} else {
240
-				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id));
241
-			}
242
-			if (!$new) {
243
-				$md5 = controles_md5($row);
244
-			}
245
-		}
246
-		if (!$row) {
247
-			$row = [];
248
-			$trouver_table = charger_fonction('trouver_table', 'base');
249
-			if ($desc = $trouver_table($table_objet)) {
250
-				foreach ($desc['field'] as $k => $v) {
251
-					$row[$k] = '';
252
-				}
253
-			}
254
-		}
255
-	}
256
-
257
-	// Gaffe: sans ceci, on ecrase systematiquement l'article d'origine
258
-	// (et donc: pas de lien de traduction)
259
-	$id = ($new or $lier_trad)
260
-		? 'oui'
261
-		: $row[$id_table_objet];
262
-	$row[$id_table_objet] = $id;
263
-
264
-	$contexte = $row;
265
-	if (is_numeric($id_parent) && strlen($id_parent) && (!isset($contexte['id_parent']) or $new)) {
266
-		if (!isset($contexte['id_parent'])) {
267
-			unset($contexte['id_rubrique']);
268
-		}
269
-		$contexte['id_parent'] = $id_parent;
270
-	} elseif (!isset($contexte['id_parent'])) {
271
-		// id_rubrique dans id_parent si possible
272
-		if (isset($contexte['id_rubrique'])) {
273
-			$contexte['id_parent'] = $contexte['id_rubrique'];
274
-			unset($contexte['id_rubrique']);
275
-		} else {
276
-			$contexte['id_parent'] = '';
277
-		}
278
-		if (
279
-			!$contexte['id_parent']
280
-			and $preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)
281
-		) {
282
-			$contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row);
283
-		}
284
-	}
285
-
286
-	$config = [];
287
-	if ($config_fonc) {
288
-		$contexte['config'] = $config = $config_fonc($contexte);
289
-		if (!$lang_default) {
290
-			$lang_default = $config['langue'] ?? session_get('lang') ;
291
-		}
292
-	}
293
-	$config = $config + [
294
-		'lignes' => 0,
295
-		'langue' => '',
296
-	];
297
-
298
-	$att_text = " class='textarea' "
299
-		. " rows='"
300
-		. ($config['lignes'] + 15)
301
-		. "' cols='40'";
302
-	if (isset($contexte['texte'])) {
303
-		list($contexte['texte'], $contexte['_texte_trop_long']) = editer_texte_recolle($contexte['texte'], $att_text);
304
-	}
305
-
306
-	// on veut conserver la langue de l'interface ;
307
-	// on passe cette donnee sous un autre nom, au cas ou le squelette
308
-	// voudrait l'exploiter
309
-	if (isset($contexte['lang'])) {
310
-		$contexte['langue'] = $contexte['lang'];
311
-		unset($contexte['lang']);
312
-	}
313
-
314
-	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
315
-		(!$lier_trad ? '' :
316
-			("\n<input type='hidden' name='lier_trad' value='" .
317
-				$lier_trad .
318
-				"' />" .
319
-				"\n<input type='hidden' name='changer_lang' value='" .
320
-				$lang_default .
321
-				"' />"))
322
-		. $hidden
323
-		. (isset($md5) ? $md5 : '');
324
-
325
-	// preciser que le formulaire doit passer dans un pipeline
326
-	$contexte['_pipeline'] = ['editer_contenu_objet', ['type' => $type, 'id' => $id]];
327
-
328
-	// preciser que le formulaire doit etre securise auteur/action
329
-	// n'est plus utile lorsque l'action accepte l'id en argument direct
330
-	// on le garde pour compat
331
-	$contexte['_action'] = ["editer_$type", $id];
332
-
333
-	// et in fine placer l'autorisation
334
-	include_spip('inc/autoriser');
335
-	if (intval($id)) {
336
-		if (!autoriser('modifier', $type, intval($id))) {
337
-			$valeurs['editable'] = '';
338
-		}
339
-	}
340
-	else {
341
-		if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) {
342
-			$valeurs['editable'] = '';
343
-		}
344
-	}
345
-
346
-	return $contexte;
212
+    $table_objet = table_objet($type);
213
+    $table_objet_sql = table_objet_sql($type);
214
+    $id_table_objet = id_table_objet($type);
215
+
216
+    // on accepte pas une fonction de config inconnue si elle vient d'un modele
217
+    if (
218
+        $config_fonc
219
+        and !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config'])
220
+        and $config_fonc !== $table_objet . '_edit_config'
221
+    ) {
222
+        if (
223
+            $args = test_formulaire_inclus_par_modele()
224
+            and in_array($config_fonc, $args)
225
+        ) {
226
+            $config_fonc = '';
227
+        }
228
+    }
229
+
230
+    $new = !is_numeric($id);
231
+    $lang_default = '';
232
+    // Appel direct dans un squelette
233
+    if (!$row) {
234
+        if (!$new or $lier_trad) {
235
+            if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
236
+                $row = $select($id, $id_parent, $lier_trad);
237
+                // si on a une fonction precharger, elle pu faire un reglage de langue
238
+                $lang_default = (!empty($row['lang']) ? $row['lang'] : null);
239
+            } else {
240
+                $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id));
241
+            }
242
+            if (!$new) {
243
+                $md5 = controles_md5($row);
244
+            }
245
+        }
246
+        if (!$row) {
247
+            $row = [];
248
+            $trouver_table = charger_fonction('trouver_table', 'base');
249
+            if ($desc = $trouver_table($table_objet)) {
250
+                foreach ($desc['field'] as $k => $v) {
251
+                    $row[$k] = '';
252
+                }
253
+            }
254
+        }
255
+    }
256
+
257
+    // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine
258
+    // (et donc: pas de lien de traduction)
259
+    $id = ($new or $lier_trad)
260
+        ? 'oui'
261
+        : $row[$id_table_objet];
262
+    $row[$id_table_objet] = $id;
263
+
264
+    $contexte = $row;
265
+    if (is_numeric($id_parent) && strlen($id_parent) && (!isset($contexte['id_parent']) or $new)) {
266
+        if (!isset($contexte['id_parent'])) {
267
+            unset($contexte['id_rubrique']);
268
+        }
269
+        $contexte['id_parent'] = $id_parent;
270
+    } elseif (!isset($contexte['id_parent'])) {
271
+        // id_rubrique dans id_parent si possible
272
+        if (isset($contexte['id_rubrique'])) {
273
+            $contexte['id_parent'] = $contexte['id_rubrique'];
274
+            unset($contexte['id_rubrique']);
275
+        } else {
276
+            $contexte['id_parent'] = '';
277
+        }
278
+        if (
279
+            !$contexte['id_parent']
280
+            and $preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)
281
+        ) {
282
+            $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row);
283
+        }
284
+    }
285
+
286
+    $config = [];
287
+    if ($config_fonc) {
288
+        $contexte['config'] = $config = $config_fonc($contexte);
289
+        if (!$lang_default) {
290
+            $lang_default = $config['langue'] ?? session_get('lang') ;
291
+        }
292
+    }
293
+    $config = $config + [
294
+        'lignes' => 0,
295
+        'langue' => '',
296
+    ];
297
+
298
+    $att_text = " class='textarea' "
299
+        . " rows='"
300
+        . ($config['lignes'] + 15)
301
+        . "' cols='40'";
302
+    if (isset($contexte['texte'])) {
303
+        list($contexte['texte'], $contexte['_texte_trop_long']) = editer_texte_recolle($contexte['texte'], $att_text);
304
+    }
305
+
306
+    // on veut conserver la langue de l'interface ;
307
+    // on passe cette donnee sous un autre nom, au cas ou le squelette
308
+    // voudrait l'exploiter
309
+    if (isset($contexte['lang'])) {
310
+        $contexte['langue'] = $contexte['lang'];
311
+        unset($contexte['lang']);
312
+    }
313
+
314
+    $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
315
+        (!$lier_trad ? '' :
316
+            ("\n<input type='hidden' name='lier_trad' value='" .
317
+                $lier_trad .
318
+                "' />" .
319
+                "\n<input type='hidden' name='changer_lang' value='" .
320
+                $lang_default .
321
+                "' />"))
322
+        . $hidden
323
+        . (isset($md5) ? $md5 : '');
324
+
325
+    // preciser que le formulaire doit passer dans un pipeline
326
+    $contexte['_pipeline'] = ['editer_contenu_objet', ['type' => $type, 'id' => $id]];
327
+
328
+    // preciser que le formulaire doit etre securise auteur/action
329
+    // n'est plus utile lorsque l'action accepte l'id en argument direct
330
+    // on le garde pour compat
331
+    $contexte['_action'] = ["editer_$type", $id];
332
+
333
+    // et in fine placer l'autorisation
334
+    include_spip('inc/autoriser');
335
+    if (intval($id)) {
336
+        if (!autoriser('modifier', $type, intval($id))) {
337
+            $valeurs['editable'] = '';
338
+        }
339
+    }
340
+    else {
341
+        if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) {
342
+            $valeurs['editable'] = '';
343
+        }
344
+    }
345
+
346
+    return $contexte;
347 347
 }
348 348
 
349 349
 /**
@@ -354,29 +354,29 @@  discard block
 block discarded – undo
354 354
  * @return array
355 355
  */
356 356
 function coupe_trop_long($texte) {
357
-	$aider = charger_fonction('aider', 'inc');
358
-	if (strlen($texte) > 28 * 1024) {
359
-		$texte = str_replace("\r\n", "\n", $texte);
360
-		$pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
361
-		if ($pos > 0 and $pos < 32 * 1024) {
362
-			$debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
363
-			$suite = substr($texte, $pos + 2);
364
-		} else {
365
-			$pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
366
-			if (!($pos > 0 and $pos < 32 * 1024)) {
367
-				$pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
368
-				$decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
369
-			} else {
370
-				$decalage = 1;
371
-			}
372
-			$debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un
373
-			$suite = substr($texte, $pos + $decalage);
374
-		}
375
-
376
-		return ([$debut, $suite]);
377
-	} else {
378
-		return ([$texte, '']);
379
-	}
357
+    $aider = charger_fonction('aider', 'inc');
358
+    if (strlen($texte) > 28 * 1024) {
359
+        $texte = str_replace("\r\n", "\n", $texte);
360
+        $pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
361
+        if ($pos > 0 and $pos < 32 * 1024) {
362
+            $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
363
+            $suite = substr($texte, $pos + 2);
364
+        } else {
365
+            $pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
366
+            if (!($pos > 0 and $pos < 32 * 1024)) {
367
+                $pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
368
+                $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
369
+            } else {
370
+                $decalage = 1;
371
+            }
372
+            $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un
373
+            $suite = substr($texte, $pos + $decalage);
374
+        }
375
+
376
+        return ([$debut, $suite]);
377
+    } else {
378
+        return ([$texte, '']);
379
+    }
380 380
 }
381 381
 
382 382
 /**
@@ -387,25 +387,25 @@  discard block
 block discarded – undo
387 387
  * @return array
388 388
  */
389 389
 function editer_texte_recolle($texte, $att_text) {
390
-	if (
391
-		(strlen($texte) < 29 * 1024)
392
-		or (include_spip('inc/layer') and ($GLOBALS['browser_name'] != 'MSIE'))
393
-	) {
394
-		return [$texte, ''];
395
-	}
396
-
397
-	include_spip('inc/barre');
398
-	$textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
399
-	$nombre = 0;
400
-
401
-	while (strlen($texte) > 29 * 1024) {
402
-		$nombre++;
403
-		list($texte1, $texte) = coupe_trop_long($texte);
404
-		$textes_supplement .= '<br />' .
405
-			"<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
406
-	}
407
-
408
-	return [$texte, $textes_supplement];
390
+    if (
391
+        (strlen($texte) < 29 * 1024)
392
+        or (include_spip('inc/layer') and ($GLOBALS['browser_name'] != 'MSIE'))
393
+    ) {
394
+        return [$texte, ''];
395
+    }
396
+
397
+    include_spip('inc/barre');
398
+    $textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
399
+    $nombre = 0;
400
+
401
+    while (strlen($texte) > 29 * 1024) {
402
+        $nombre++;
403
+        list($texte1, $texte) = coupe_trop_long($texte);
404
+        $textes_supplement .= '<br />' .
405
+            "<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
406
+    }
407
+
408
+    return [$texte, $textes_supplement];
409 409
 }
410 410
 
411 411
 /**
@@ -416,17 +416,17 @@  discard block
 block discarded – undo
416 416
  * @param int $longueur
417 417
  */
418 418
 function titre_automatique($champ_titre, $champs_contenu, $longueur = null) {
419
-	if (!_request($champ_titre)) {
420
-		$titrer_contenu = charger_fonction('titrer_contenu', 'inc');
421
-		if (!is_null($longueur)) {
422
-			$t = $titrer_contenu($champs_contenu, null, $longueur);
423
-		} else {
424
-			$t = $titrer_contenu($champs_contenu);
425
-		}
426
-		if ($t) {
427
-			set_request($champ_titre, $t);
428
-		}
429
-	}
419
+    if (!_request($champ_titre)) {
420
+        $titrer_contenu = charger_fonction('titrer_contenu', 'inc');
421
+        if (!is_null($longueur)) {
422
+            $t = $titrer_contenu($champs_contenu, null, $longueur);
423
+        } else {
424
+            $t = $titrer_contenu($champs_contenu);
425
+        }
426
+        if ($t) {
427
+            set_request($champ_titre, $t);
428
+        }
429
+    }
430 430
 }
431 431
 
432 432
 /**
@@ -446,20 +446,20 @@  discard block
 block discarded – undo
446 446
  * @return string
447 447
  */
448 448
 function inc_titrer_contenu_dist($champs_contenu, $c = null, $longueur = 50) {
449
-	// trouver un champ texte non vide
450
-	$t = '';
451
-	foreach ($champs_contenu as $champ) {
452
-		if ($t = _request($champ, $c)) {
453
-			break;
454
-		}
455
-	}
456
-
457
-	if ($t) {
458
-		include_spip('inc/texte_mini');
459
-		$t = couper($t, $longueur, '...');
460
-	}
461
-
462
-	return $t;
449
+    // trouver un champ texte non vide
450
+    $t = '';
451
+    foreach ($champs_contenu as $champ) {
452
+        if ($t = _request($champ, $c)) {
453
+            break;
454
+        }
455
+    }
456
+
457
+    if ($t) {
458
+        include_spip('inc/texte_mini');
459
+        $t = couper($t, $longueur, '...');
460
+    }
461
+
462
+    return $t;
463 463
 }
464 464
 
465 465
 /**
@@ -481,26 +481,26 @@  discard block
 block discarded – undo
481 481
  *      - array sinon couples ('$prefixe$colonne => md5)
482 482
  **/
483 483
 function controles_md5(array $data, string $prefixe = 'ctr_', string $format = 'html') {
484
-	$ctr = [];
485
-	foreach ($data as $key => $val) {
486
-		$m = md5($val ?? '');
487
-		$k = $prefixe . $key;
488
-
489
-		switch ($format) {
490
-			case 'html':
491
-				$ctr[$k] = "<input type='hidden' value='$m' name='$k' />";
492
-				break;
493
-			default:
494
-				$ctr[$k] = $m;
495
-				break;
496
-		}
497
-	}
498
-
499
-	if ($format === 'html') {
500
-		return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n";
501
-	} else {
502
-		return $ctr;
503
-	}
484
+    $ctr = [];
485
+    foreach ($data as $key => $val) {
486
+        $m = md5($val ?? '');
487
+        $k = $prefixe . $key;
488
+
489
+        switch ($format) {
490
+            case 'html':
491
+                $ctr[$k] = "<input type='hidden' value='$m' name='$k' />";
492
+                break;
493
+            default:
494
+                $ctr[$k] = $m;
495
+                break;
496
+        }
497
+    }
498
+
499
+    if ($format === 'html') {
500
+        return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n";
501
+    } else {
502
+        return $ctr;
503
+    }
504 504
 }
505 505
 
506 506
 /**
@@ -539,80 +539,80 @@  discard block
 block discarded – undo
539 539
  *     - post : le contenu posté
540 540
  **/
541 541
 function controler_contenu($type, $id, $options = [], $c = false, $serveur = '') {
542
-	include_spip('inc/filtres');
543
-
544
-	$table_objet = table_objet($type);
545
-	$spip_table_objet = table_objet_sql($type);
546
-	$trouver_table = charger_fonction('trouver_table', 'base');
547
-	$desc = $trouver_table($table_objet, $serveur);
548
-
549
-	// Appels incomplets (sans $c)
550
-	if (!is_array($c)) {
551
-		$c = [];
552
-		foreach ($desc['field'] as $champ => $ignore) {
553
-			if (_request($champ)) {
554
-				$c[$champ] = _request($champ);
555
-			}
556
-		}
557
-	}
558
-
559
-	// Securite : certaines variables ne sont jamais acceptees ici
560
-	// car elles ne relevent pas de autoriser(article, modifier) ;
561
-	// il faut passer par instituer_XX()
562
-	// TODO: faut-il passer ces variables interdites
563
-	// dans un fichier de description separe ?
564
-	unset($c['statut']);
565
-	unset($c['id_parent']);
566
-	unset($c['id_rubrique']);
567
-	unset($c['id_secteur']);
568
-
569
-	// Gerer les champs non vides
570
-	if (isset($options['nonvide']) and is_array($options['nonvide'])) {
571
-		foreach ($options['nonvide'] as $champ => $sinon) {
572
-			if ($c[$champ] === '') {
573
-				$c[$champ] = $sinon;
574
-			}
575
-		}
576
-	}
577
-
578
-	// N'accepter que les champs qui existent
579
-	// [TODO] ici aussi on peut valider les contenus en fonction du type
580
-	$champs = [];
581
-	foreach ($desc['field'] as $champ => $ignore) {
582
-		if (isset($c[$champ])) {
583
-			$champs[$champ] = $c[$champ];
584
-		}
585
-	}
586
-
587
-	// Nettoyer les valeurs
588
-	$champs = array_map('corriger_caracteres', $champs);
589
-
590
-	// Envoyer aux plugins
591
-	$champs = pipeline(
592
-		'pre_edition',
593
-		[
594
-			'args' => [
595
-				'table' => $spip_table_objet, // compatibilite
596
-				'table_objet' => $table_objet,
597
-				'spip_table_objet' => $spip_table_objet,
598
-				'type' => $type,
599
-				'id_objet' => $id,
600
-				'champs' => isset($options['champs']) ? $options['champs'] : [], // [doc] c'est quoi ?
601
-				'action' => 'controler',
602
-				'serveur' => $serveur,
603
-			],
604
-			'data' => $champs
605
-		]
606
-	);
607
-
608
-	if (!$champs) {
609
-		return false;
610
-	}
611
-
612
-	// Verifier si les mises a jour sont pertinentes, datees, en conflit etc
613
-	$conflits = controler_md5($champs, $_POST, $type, $id, $serveur, isset($options['prefix']) ? $options['prefix'] : 'ctr_');
614
-
615
-	return $conflits;
542
+    include_spip('inc/filtres');
543
+
544
+    $table_objet = table_objet($type);
545
+    $spip_table_objet = table_objet_sql($type);
546
+    $trouver_table = charger_fonction('trouver_table', 'base');
547
+    $desc = $trouver_table($table_objet, $serveur);
548
+
549
+    // Appels incomplets (sans $c)
550
+    if (!is_array($c)) {
551
+        $c = [];
552
+        foreach ($desc['field'] as $champ => $ignore) {
553
+            if (_request($champ)) {
554
+                $c[$champ] = _request($champ);
555
+            }
556
+        }
557
+    }
558
+
559
+    // Securite : certaines variables ne sont jamais acceptees ici
560
+    // car elles ne relevent pas de autoriser(article, modifier) ;
561
+    // il faut passer par instituer_XX()
562
+    // TODO: faut-il passer ces variables interdites
563
+    // dans un fichier de description separe ?
564
+    unset($c['statut']);
565
+    unset($c['id_parent']);
566
+    unset($c['id_rubrique']);
567
+    unset($c['id_secteur']);
568
+
569
+    // Gerer les champs non vides
570
+    if (isset($options['nonvide']) and is_array($options['nonvide'])) {
571
+        foreach ($options['nonvide'] as $champ => $sinon) {
572
+            if ($c[$champ] === '') {
573
+                $c[$champ] = $sinon;
574
+            }
575
+        }
576
+    }
577
+
578
+    // N'accepter que les champs qui existent
579
+    // [TODO] ici aussi on peut valider les contenus en fonction du type
580
+    $champs = [];
581
+    foreach ($desc['field'] as $champ => $ignore) {
582
+        if (isset($c[$champ])) {
583
+            $champs[$champ] = $c[$champ];
584
+        }
585
+    }
586
+
587
+    // Nettoyer les valeurs
588
+    $champs = array_map('corriger_caracteres', $champs);
589
+
590
+    // Envoyer aux plugins
591
+    $champs = pipeline(
592
+        'pre_edition',
593
+        [
594
+            'args' => [
595
+                'table' => $spip_table_objet, // compatibilite
596
+                'table_objet' => $table_objet,
597
+                'spip_table_objet' => $spip_table_objet,
598
+                'type' => $type,
599
+                'id_objet' => $id,
600
+                'champs' => isset($options['champs']) ? $options['champs'] : [], // [doc] c'est quoi ?
601
+                'action' => 'controler',
602
+                'serveur' => $serveur,
603
+            ],
604
+            'data' => $champs
605
+        ]
606
+    );
607
+
608
+    if (!$champs) {
609
+        return false;
610
+    }
611
+
612
+    // Verifier si les mises a jour sont pertinentes, datees, en conflit etc
613
+    $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, isset($options['prefix']) ? $options['prefix'] : 'ctr_');
614
+
615
+    return $conflits;
616 616
 }
617 617
 
618 618
 
@@ -642,64 +642,64 @@  discard block
 block discarded – undo
642 642
  *     - post : le contenu posté
643 643
  **/
644 644
 function controler_md5(&$champs, $ctr, $type, $id, $serveur, $prefix = 'ctr_') {
645
-	$spip_table_objet = table_objet_sql($type);
646
-	$id_table_objet = id_table_objet($type);
647
-
648
-	// Controle des MD5 envoyes
649
-	// On elimine les donnees non modifiees par le formulaire (mais
650
-	// potentiellement modifiees entre temps par un autre utilisateur)
651
-	foreach ($champs as $key => $val) {
652
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
653
-			if (is_scalar($val) and $m == md5($val)) {
654
-				unset($champs[$key]);
655
-			}
656
-		}
657
-	}
658
-	if (!$champs) {
659
-		return;
660
-	}
661
-
662
-	// On veut savoir si notre modif va avoir un impact
663
-	// par rapport aux donnees contenues dans la base
664
-	// (qui peuvent etre differentes de celles ayant servi a calculer le ctr)
665
-	$s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur);
666
-	$intact = true;
667
-	foreach ($champs as $ch => $val) {
668
-		$intact &= ($s[$ch] == $val);
669
-	}
670
-	if ($intact) {
671
-		return;
672
-	}
673
-
674
-	// Detection de conflits :
675
-	// On verifie si notre modif ne provient pas d'un formulaire
676
-	// genere a partir de donnees modifiees dans l'intervalle ; ici
677
-	// on compare a ce qui est dans la base, et on bloque en cas
678
-	// de conflit.
679
-	$ctrh = $ctrq = $conflits = [];
680
-	foreach (array_keys($champs) as $key) {
681
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
682
-			$ctrh[$key] = $m;
683
-			$ctrq[] = $key;
684
-		}
685
-	}
686
-	if ($ctrq) {
687
-		$ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur);
688
-		foreach ($ctrh as $key => $m) {
689
-			if (
690
-				$m != md5($ctrq[$key])
691
-				and $champs[$key] !== $ctrq[$key]
692
-			) {
693
-				$conflits[$key] = [
694
-					'base' => $ctrq[$key],
695
-					'post' => $champs[$key]
696
-				];
697
-				unset($champs[$key]); # stocker quand meme les modifs ?
698
-			}
699
-		}
700
-	}
701
-
702
-	return $conflits;
645
+    $spip_table_objet = table_objet_sql($type);
646
+    $id_table_objet = id_table_objet($type);
647
+
648
+    // Controle des MD5 envoyes
649
+    // On elimine les donnees non modifiees par le formulaire (mais
650
+    // potentiellement modifiees entre temps par un autre utilisateur)
651
+    foreach ($champs as $key => $val) {
652
+        if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
653
+            if (is_scalar($val) and $m == md5($val)) {
654
+                unset($champs[$key]);
655
+            }
656
+        }
657
+    }
658
+    if (!$champs) {
659
+        return;
660
+    }
661
+
662
+    // On veut savoir si notre modif va avoir un impact
663
+    // par rapport aux donnees contenues dans la base
664
+    // (qui peuvent etre differentes de celles ayant servi a calculer le ctr)
665
+    $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur);
666
+    $intact = true;
667
+    foreach ($champs as $ch => $val) {
668
+        $intact &= ($s[$ch] == $val);
669
+    }
670
+    if ($intact) {
671
+        return;
672
+    }
673
+
674
+    // Detection de conflits :
675
+    // On verifie si notre modif ne provient pas d'un formulaire
676
+    // genere a partir de donnees modifiees dans l'intervalle ; ici
677
+    // on compare a ce qui est dans la base, et on bloque en cas
678
+    // de conflit.
679
+    $ctrh = $ctrq = $conflits = [];
680
+    foreach (array_keys($champs) as $key) {
681
+        if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
682
+            $ctrh[$key] = $m;
683
+            $ctrq[] = $key;
684
+        }
685
+    }
686
+    if ($ctrq) {
687
+        $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur);
688
+        foreach ($ctrh as $key => $m) {
689
+            if (
690
+                $m != md5($ctrq[$key])
691
+                and $champs[$key] !== $ctrq[$key]
692
+            ) {
693
+                $conflits[$key] = [
694
+                    'base' => $ctrq[$key],
695
+                    'post' => $champs[$key]
696
+                ];
697
+                unset($champs[$key]); # stocker quand meme les modifs ?
698
+            }
699
+        }
700
+    }
701
+
702
+    return $conflits;
703 703
 }
704 704
 
705 705
 /**
@@ -711,11 +711,11 @@  discard block
 block discarded – undo
711 711
  * @return string
712 712
  */
713 713
 function display_conflit_champ($x) {
714
-	if (strstr($x, "\n") or strlen($x) > 80) {
715
-		return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
716
-	} else {
717
-		return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
718
-	}
714
+    if (strstr($x, "\n") or strlen($x) > 80) {
715
+        return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
716
+    } else {
717
+        return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
718
+    }
719 719
 }
720 720
 
721 721
 /**
@@ -733,57 +733,57 @@  discard block
 block discarded – undo
733 733
  * @return string
734 734
  */
735 735
 function signaler_conflits_edition($conflits, $redirect = '') {
736
-	include_spip('inc/minipres');
737
-	include_spip('inc/revisions');
738
-	include_spip('afficher_diff/champ');
739
-	include_spip('inc/suivi_versions');
740
-	include_spip('inc/diff');
741
-	$diffs = [];
742
-	foreach ($conflits as $champ => $a) {
743
-		// probleme de stockage ou conflit d'edition ?
744
-		$base = $a['save'] ?? $a['base'];
745
-
746
-		$diff = new Diff(new DiffTexte());
747
-		$n = preparer_diff($a['post']);
748
-		$o = preparer_diff($base);
749
-		$d = propre_diff(afficher_para_modifies(afficher_diff($diff->comparer($n, $o))));
750
-
751
-		$titre = isset($a['save']) ? _L(
752
-			'Echec lors de l\'enregistrement du champ @champ@',
753
-			['champ' => $champ]
754
-		) : $champ;
755
-
756
-		$diffs[] = "<h2>$titre</h2>\n"
757
-			. '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n"
758
-			. "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n"
759
-			. '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>'
760
-			. display_conflit_champ($a['post'])
761
-			. '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>'
762
-			. display_conflit_champ($base);
763
-	}
764
-
765
-	if ($redirect) {
766
-		$id = uniqid(rand());
767
-		$redirect = "<form action='$redirect' method='get'
736
+    include_spip('inc/minipres');
737
+    include_spip('inc/revisions');
738
+    include_spip('afficher_diff/champ');
739
+    include_spip('inc/suivi_versions');
740
+    include_spip('inc/diff');
741
+    $diffs = [];
742
+    foreach ($conflits as $champ => $a) {
743
+        // probleme de stockage ou conflit d'edition ?
744
+        $base = $a['save'] ?? $a['base'];
745
+
746
+        $diff = new Diff(new DiffTexte());
747
+        $n = preparer_diff($a['post']);
748
+        $o = preparer_diff($base);
749
+        $d = propre_diff(afficher_para_modifies(afficher_diff($diff->comparer($n, $o))));
750
+
751
+        $titre = isset($a['save']) ? _L(
752
+            'Echec lors de l\'enregistrement du champ @champ@',
753
+            ['champ' => $champ]
754
+        ) : $champ;
755
+
756
+        $diffs[] = "<h2>$titre</h2>\n"
757
+            . '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n"
758
+            . "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n"
759
+            . '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>'
760
+            . display_conflit_champ($a['post'])
761
+            . '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>'
762
+            . display_conflit_champ($base);
763
+    }
764
+
765
+    if ($redirect) {
766
+        $id = uniqid(rand());
767
+        $redirect = "<form action='$redirect' method='get'
768 768
 			id='$id'
769 769
 			style='float:" . $GLOBALS['spip_lang_right'] . "; margin-top:2em;'>\n"
770
-			. form_hidden($redirect)
771
-			. "<input type='submit' value='" . _T('icone_retour') . "' />
770
+            . form_hidden($redirect)
771
+            . "<input type='submit' value='" . _T('icone_retour') . "' />
772 772
 		</form>\n";
773 773
 
774
-		// pour les documents, on est probablement en ajax : il faut ajaxer
775
-		if (_AJAX) {
776
-			$redirect .= '<script type="text/javascript">'
777
-				. 'setTimeout(function(){$("#' . $id . '")
774
+        // pour les documents, on est probablement en ajax : il faut ajaxer
775
+        if (_AJAX) {
776
+            $redirect .= '<script type="text/javascript">'
777
+                . 'setTimeout(function(){$("#' . $id . '")
778 778
 			.ajaxForm({target:$("#' . $id . '").parent()});
779 779
 			}, 200);'
780
-				. "</script>\n";
781
-		}
782
-	}
780
+                . "</script>\n";
781
+        }
782
+    }
783 783
 
784
-	echo minipres(
785
-		_T('titre_conflit_edition'),
786
-		'<style>
784
+    echo minipres(
785
+        _T('titre_conflit_edition'),
786
+        '<style>
787 787
 .diff-para-deplace { background: #e8e8ff; }
788 788
 .diff-para-ajoute { background: #d0ffc0; color: #000; }
789 789
 .diff-para-supprime { background: #ffd0c0; color: #904040; text-decoration: line-through; }
@@ -794,12 +794,12 @@  discard block
 block discarded – undo
794 794
 .diff-para-deplace .diff-supprime { background: #ffb8b8; border: 1px solid #808080; }
795 795
 .diff-para-deplace .diff-deplace { background: #b8b8ff; border: 1px solid #808080; }
796 796
 </style>'
797
-		. '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>'
798
-		. '<p>' . _T('texte_conflit_edition_correction') . '</p>'
799
-		. "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>"
800
-		. join("\n", $diffs)
801
-		. "</div>\n"
802
-
803
-		. $redirect
804
-	);
797
+        . '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>'
798
+        . '<p>' . _T('texte_conflit_edition_correction') . '</p>'
799
+        . "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>"
800
+        . join("\n", $diffs)
801
+        . "</div>\n"
802
+
803
+        . $redirect
804
+    );
805 805
 }
Please login to merge, or discard this patch.
Spacing   +35 added lines, -36 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 		$res['message_ok'] = _T('info_modification_enregistree');
101 101
 		if ($retour) {
102 102
 			if (strncmp($retour, 'javascript:', 11) == 0) {
103
-				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
103
+				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/'.substr($retour, 11).'/*]]>*/</script>';
104 104
 				$res['editable'] = true;
105 105
 			} else {
106 106
 				$res['redirect'] = parametre_url($retour, $id_table_objet, $id);
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 				if (!isset($erreurs[$champ])) {
141 141
 					$erreurs[$champ] = '';
142 142
 				}
143
-				$erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>';
143
+				$erreurs[$champ] .= _T('alerte_modif_info_concourante')."<br /><textarea readonly='readonly' class='forml'>".entites_html($conflit['base']).'</textarea>';
144 144
 			}
145 145
 		}
146 146
 	}
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 	if (
218 218
 		$config_fonc
219 219
 		and !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config'])
220
-		and $config_fonc !== $table_objet . '_edit_config'
220
+		and $config_fonc !== $table_objet.'_edit_config'
221 221
 	) {
222 222
 		if (
223 223
 			$args = test_formulaire_inclus_par_modele()
@@ -232,12 +232,12 @@  discard block
 block discarded – undo
232 232
 	// Appel direct dans un squelette
233 233
 	if (!$row) {
234 234
 		if (!$new or $lier_trad) {
235
-			if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
235
+			if ($select = charger_fonction('precharger_'.$type, 'inc', true)) {
236 236
 				$row = $select($id, $id_parent, $lier_trad);
237 237
 				// si on a une fonction precharger, elle pu faire un reglage de langue
238 238
 				$lang_default = (!empty($row['lang']) ? $row['lang'] : null);
239 239
 			} else {
240
-				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id));
240
+				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet.'='.intval($id));
241 241
 			}
242 242
 			if (!$new) {
243 243
 				$md5 = controles_md5($row);
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 	if ($config_fonc) {
288 288
 		$contexte['config'] = $config = $config_fonc($contexte);
289 289
 		if (!$lang_default) {
290
-			$lang_default = $config['langue'] ?? session_get('lang') ;
290
+			$lang_default = $config['langue'] ?? session_get('lang');
291 291
 		}
292 292
 	}
293 293
 	$config = $config + [
@@ -311,13 +311,12 @@  discard block
 block discarded – undo
311 311
 		unset($contexte['lang']);
312 312
 	}
313 313
 
314
-	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
315
-		(!$lier_trad ? '' :
316
-			("\n<input type='hidden' name='lier_trad' value='" .
317
-				$lier_trad .
318
-				"' />" .
319
-				"\n<input type='hidden' name='changer_lang' value='" .
320
-				$lang_default .
314
+	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n".
315
+		(!$lier_trad ? '' : ("\n<input type='hidden' name='lier_trad' value='".
316
+				$lier_trad.
317
+				"' />".
318
+				"\n<input type='hidden' name='changer_lang' value='".
319
+				$lang_default.
321 320
 				"' />"))
322 321
 		. $hidden
323 322
 		. (isset($md5) ? $md5 : '');
@@ -357,14 +356,14 @@  discard block
 block discarded – undo
357 356
 	$aider = charger_fonction('aider', 'inc');
358 357
 	if (strlen($texte) > 28 * 1024) {
359 358
 		$texte = str_replace("\r\n", "\n", $texte);
360
-		$pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
359
+		$pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko
361 360
 		if ($pos > 0 and $pos < 32 * 1024) {
362
-			$debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
361
+			$debut = substr($texte, 0, $pos)."\n\n<!--SPIP-->\n";
363 362
 			$suite = substr($texte, $pos + 2);
364 363
 		} else {
365
-			$pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
364
+			$pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace
366 365
 			if (!($pos > 0 and $pos < 32 * 1024)) {
367
-				$pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
366
+				$pos = 28 * 1024; // au pire (pas d'espace trouv'e)
368 367
 				$decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
369 368
 			} else {
370 369
 				$decalage = 1;
@@ -395,13 +394,13 @@  discard block
 block discarded – undo
395 394
 	}
396 395
 
397 396
 	include_spip('inc/barre');
398
-	$textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
397
+	$textes_supplement = "<br /><span style='color: red'>"._T('info_texte_long')."</span>\n";
399 398
 	$nombre = 0;
400 399
 
401 400
 	while (strlen($texte) > 29 * 1024) {
402 401
 		$nombre++;
403 402
 		list($texte1, $texte) = coupe_trop_long($texte);
404
-		$textes_supplement .= '<br />' .
403
+		$textes_supplement .= '<br />'.
405 404
 			"<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
406 405
 	}
407 406
 
@@ -484,7 +483,7 @@  discard block
 block discarded – undo
484 483
 	$ctr = [];
485 484
 	foreach ($data as $key => $val) {
486 485
 		$m = md5($val ?? '');
487
-		$k = $prefixe . $key;
486
+		$k = $prefixe.$key;
488 487
 
489 488
 		switch ($format) {
490 489
 			case 'html':
@@ -497,7 +496,7 @@  discard block
 block discarded – undo
497 496
 	}
498 497
 
499 498
 	if ($format === 'html') {
500
-		return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n";
499
+		return "\n\n<!-- controles md5 -->\n".join("\n", $ctr)."\n\n";
501 500
 	} else {
502 501
 		return $ctr;
503 502
 	}
@@ -649,7 +648,7 @@  discard block
 block discarded – undo
649 648
 	// On elimine les donnees non modifiees par le formulaire (mais
650 649
 	// potentiellement modifiees entre temps par un autre utilisateur)
651 650
 	foreach ($champs as $key => $val) {
652
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
651
+		if (isset($ctr[$prefix.$key]) and $m = $ctr[$prefix.$key]) {
653 652
 			if (is_scalar($val) and $m == md5($val)) {
654 653
 				unset($champs[$key]);
655 654
 			}
@@ -678,7 +677,7 @@  discard block
 block discarded – undo
678 677
 	// de conflit.
679 678
 	$ctrh = $ctrq = $conflits = [];
680 679
 	foreach (array_keys($champs) as $key) {
681
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
680
+		if (isset($ctr[$prefix.$key]) and $m = $ctr[$prefix.$key]) {
682 681
 			$ctrh[$key] = $m;
683 682
 			$ctrq[] = $key;
684 683
 		}
@@ -712,9 +711,9 @@  discard block
 block discarded – undo
712 711
  */
713 712
 function display_conflit_champ($x) {
714 713
 	if (strstr($x, "\n") or strlen($x) > 80) {
715
-		return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
714
+		return "<textarea style='width:99%; height:10em;'>".entites_html($x)."</textarea>\n";
716 715
 	} else {
717
-		return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
716
+		return "<input type='text' size='40' style='width:99%' value=\"".entites_html($x)."\" />\n";
718 717
 	}
719 718
 }
720 719
 
@@ -754,11 +753,11 @@  discard block
 block discarded – undo
754 753
 		) : $champ;
755 754
 
756 755
 		$diffs[] = "<h2>$titre</h2>\n"
757
-			. '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n"
758
-			. "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n"
759
-			. '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>'
756
+			. '<h3>'._T('info_conflit_edition_differences')."</h3>\n"
757
+			. "<div style='max-height:8em; overflow: auto; width:99%;'>".$d."</div>\n"
758
+			. '<h4>'._T('info_conflit_edition_votre_version').'</h4>'
760 759
 			. display_conflit_champ($a['post'])
761
-			. '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>'
760
+			. '<h4>'._T('info_conflit_edition_version_enregistree').'</h4>'
762 761
 			. display_conflit_champ($base);
763 762
 	}
764 763
 
@@ -766,16 +765,16 @@  discard block
 block discarded – undo
766 765
 		$id = uniqid(rand());
767 766
 		$redirect = "<form action='$redirect' method='get'
768 767
 			id='$id'
769
-			style='float:" . $GLOBALS['spip_lang_right'] . "; margin-top:2em;'>\n"
768
+			style='float:".$GLOBALS['spip_lang_right']."; margin-top:2em;'>\n"
770 769
 			. form_hidden($redirect)
771
-			. "<input type='submit' value='" . _T('icone_retour') . "' />
770
+			. "<input type='submit' value='"._T('icone_retour')."' />
772 771
 		</form>\n";
773 772
 
774 773
 		// pour les documents, on est probablement en ajax : il faut ajaxer
775 774
 		if (_AJAX) {
776 775
 			$redirect .= '<script type="text/javascript">'
777
-				. 'setTimeout(function(){$("#' . $id . '")
778
-			.ajaxForm({target:$("#' . $id . '").parent()});
776
+				. 'setTimeout(function(){$("#'.$id.'")
777
+			.ajaxForm({target:$("#' . $id.'").parent()});
779 778
 			}, 200);'
780 779
 				. "</script>\n";
781 780
 		}
@@ -794,9 +793,9 @@  discard block
 block discarded – undo
794 793
 .diff-para-deplace .diff-supprime { background: #ffb8b8; border: 1px solid #808080; }
795 794
 .diff-para-deplace .diff-deplace { background: #b8b8ff; border: 1px solid #808080; }
796 795
 </style>'
797
-		. '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>'
798
-		. '<p>' . _T('texte_conflit_edition_correction') . '</p>'
799
-		. "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>"
796
+		. '<p>'._T('info_conflit_edition_avis_non_sauvegarde').'</p>'
797
+		. '<p>'._T('texte_conflit_edition_correction').'</p>'
798
+		. "<div style='text-align:".$GLOBALS['spip_lang_left'].";'>"
800 799
 		. join("\n", $diffs)
801 800
 		. "</div>\n"
802 801
 
Please login to merge, or discard this patch.
ecrire/inc/cvt_multietapes.php 1 patch
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
  */
67 67
 
68 68
 if (!defined('_ECRIRE_INC_VERSION')) {
69
-	return;
69
+    return;
70 70
 }
71 71
 
72 72
 /**
@@ -77,46 +77,46 @@  discard block
 block discarded – undo
77 77
  * @return array
78 78
  */
79 79
 function cvtmulti_recuperer_post_precedents($form) {
80
-	include_spip('inc/filtres');
81
-	if (
82
-		$form
83
-		and $c = _request('cvtm_prev_post')
84
-		and $c = decoder_contexte_ajax($c, $form)
85
-	) {
86
-		#var_dump($c);
80
+    include_spip('inc/filtres');
81
+    if (
82
+        $form
83
+        and $c = _request('cvtm_prev_post')
84
+        and $c = decoder_contexte_ajax($c, $form)
85
+    ) {
86
+        #var_dump($c);
87 87
 
88
-		# reinjecter dans la bonne variable pour permettre de retrouver
89
-		# toutes les saisies dans un seul tableau
90
-		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
91
-			$store = &$_POST;
92
-		} else {
93
-			$store = &$_GET;
94
-		}
88
+        # reinjecter dans la bonne variable pour permettre de retrouver
89
+        # toutes les saisies dans un seul tableau
90
+        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
91
+            $store = &$_POST;
92
+        } else {
93
+            $store = &$_GET;
94
+        }
95 95
 
96
-		foreach ($c as $k => $v) { // on ecrase pas si saisi a nouveau !
97
-		if (!isset($store[$k])) {
98
-				$_REQUEST[$k] = $store[$k] = $v;
99
-		} // mais si tableau des deux cotes, on merge avec priorite a la derniere saisie
100
-			elseif (
101
-				is_array($store[$k])
102
-				and is_array($v)
103
-				and $z = array_keys($v)
104
-				and !is_numeric(reset($z))
105
-				and $z = array_keys($store[$k])
106
-				and !is_numeric(reset($z))
107
-			) {
108
-				$_REQUEST[$k] = $store[$k] = array_merge($v, $store[$k]);
109
-			}
110
-		}
96
+        foreach ($c as $k => $v) { // on ecrase pas si saisi a nouveau !
97
+        if (!isset($store[$k])) {
98
+                $_REQUEST[$k] = $store[$k] = $v;
99
+        } // mais si tableau des deux cotes, on merge avec priorite a la derniere saisie
100
+            elseif (
101
+                is_array($store[$k])
102
+                and is_array($v)
103
+                and $z = array_keys($v)
104
+                and !is_numeric(reset($z))
105
+                and $z = array_keys($store[$k])
106
+                and !is_numeric(reset($z))
107
+            ) {
108
+                $_REQUEST[$k] = $store[$k] = array_merge($v, $store[$k]);
109
+            }
110
+        }
111 111
 
112
-		// vider pour eviter un second appel a verifier_n
113
-		// en cas de double implementation (unipotence)
114
-		set_request('cvtm_prev_post');
112
+        // vider pour eviter un second appel a verifier_n
113
+        // en cas de double implementation (unipotence)
114
+        set_request('cvtm_prev_post');
115 115
 
116
-		return [$c['_etape'], $c['_etapes']];
117
-	}
116
+        return [$c['_etape'], $c['_etapes']];
117
+    }
118 118
 
119
-	return false;
119
+    return false;
120 120
 }
121 121
 
122 122
 /**
@@ -129,28 +129,28 @@  discard block
 block discarded – undo
129 129
  * @return array
130 130
  */
131 131
 function cvtmulti_sauver_post($form, $je_suis_poste, &$valeurs) {
132
-	if (!isset($valeurs['_cvtm_prev_post'])) {
133
-		$post = ['_etape' => $valeurs['_etape'], '_etapes' => $valeurs['_etapes']];
134
-		foreach (array_keys($valeurs) as $champ) {
135
-			if (substr($champ, 0, 1) !== '_') {
136
-				if ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])) {
137
-					if (($v = _request($champ)) !== null) {
138
-						$post[$champ] = $v;
139
-					}
140
-				}
141
-			}
142
-		}
143
-		include_spip('inc/filtres');
144
-		$c = encoder_contexte_ajax($post, $form);
145
-		if (!isset($valeurs['_hidden'])) {
146
-			$valeurs['_hidden'] = '';
147
-		}
148
-		$valeurs['_hidden'] .= "<input type='hidden' name='cvtm_prev_post' value='$c' />";
149
-		// marquer comme fait, pour eviter double encodage (unipotence)
150
-		$valeurs['_cvtm_prev_post'] = true;
151
-	}
132
+    if (!isset($valeurs['_cvtm_prev_post'])) {
133
+        $post = ['_etape' => $valeurs['_etape'], '_etapes' => $valeurs['_etapes']];
134
+        foreach (array_keys($valeurs) as $champ) {
135
+            if (substr($champ, 0, 1) !== '_') {
136
+                if ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])) {
137
+                    if (($v = _request($champ)) !== null) {
138
+                        $post[$champ] = $v;
139
+                    }
140
+                }
141
+            }
142
+        }
143
+        include_spip('inc/filtres');
144
+        $c = encoder_contexte_ajax($post, $form);
145
+        if (!isset($valeurs['_hidden'])) {
146
+            $valeurs['_hidden'] = '';
147
+        }
148
+        $valeurs['_hidden'] .= "<input type='hidden' name='cvtm_prev_post' value='$c' />";
149
+        // marquer comme fait, pour eviter double encodage (unipotence)
150
+        $valeurs['_cvtm_prev_post'] = true;
151
+    }
152 152
 
153
-	return $valeurs;
153
+    return $valeurs;
154 154
 }
155 155
 
156 156
 
@@ -164,14 +164,14 @@  discard block
 block discarded – undo
164 164
  * @return array
165 165
  */
166 166
 function cvtmulti_formulaire_charger($flux) {
167
-	if (
168
-		is_array($flux['data'])
169
-		and isset($flux['data']['_etapes'])
170
-	) {
171
-		$flux['data'] = cvtmulti_formulaire_charger_etapes($flux['args'], $flux['data']);
172
-	}
167
+    if (
168
+        is_array($flux['data'])
169
+        and isset($flux['data']['_etapes'])
170
+    ) {
171
+        $flux['data'] = cvtmulti_formulaire_charger_etapes($flux['args'], $flux['data']);
172
+    }
173 173
 
174
-	return $flux;
174
+    return $flux;
175 175
 }
176 176
 
177 177
 /**
@@ -181,19 +181,19 @@  discard block
 block discarded – undo
181 181
  * @return array
182 182
  */
183 183
 function cvtmulti_formulaire_charger_etapes($args, $valeurs) {
184
-	if (!isset($valeurs['_etape'])) {
185
-		$form = $args['form'];
186
-		$je_suis_poste = $args['je_suis_poste'];
187
-		$nb_etapes = $valeurs['_etapes'];
188
-		$etape = _request('_etape');
189
-		$etape = min(max($etape, 1), $nb_etapes);
190
-		set_request('_etape', $etape);
191
-		$valeurs['_etape'] = $etape;
184
+    if (!isset($valeurs['_etape'])) {
185
+        $form = $args['form'];
186
+        $je_suis_poste = $args['je_suis_poste'];
187
+        $nb_etapes = $valeurs['_etapes'];
188
+        $etape = _request('_etape');
189
+        $etape = min(max($etape, 1), $nb_etapes);
190
+        set_request('_etape', $etape);
191
+        $valeurs['_etape'] = $etape;
192 192
 
193
-		// sauver les posts de cette etape pour les avoir a la prochaine etape
194
-		$valeurs = cvtmulti_sauver_post($form, $je_suis_poste, $valeurs);
195
-	}
196
-	return $valeurs;
193
+        // sauver les posts de cette etape pour les avoir a la prochaine etape
194
+        $valeurs = cvtmulti_sauver_post($form, $je_suis_poste, $valeurs);
195
+    }
196
+    return $valeurs;
197 197
 }
198 198
 
199 199
 
@@ -206,8 +206,8 @@  discard block
 block discarded – undo
206 206
  * @return array
207 207
  */
208 208
 function cvtmulti_formulaire_verifier($flux) {
209
-	$flux['data'] = cvtmulti_formulaire_verifier_etapes($flux['args'], $flux['data']);
210
-	return $flux;
209
+    $flux['data'] = cvtmulti_formulaire_verifier_etapes($flux['args'], $flux['data']);
210
+    return $flux;
211 211
 }
212 212
 
213 213
 /**
@@ -218,87 +218,87 @@  discard block
 block discarded – undo
218 218
  * @return array
219 219
  */
220 220
 function cvtmulti_formulaire_verifier_etapes($args, $erreurs) {
221
-	#var_dump('Pipe verifier');
221
+    #var_dump('Pipe verifier');
222 222
 
223
-	if (
224
-		$form = $args['form']
225
-		and ($e = cvtmulti_recuperer_post_precedents($form)) !== false
226
-	) {
227
-		// recuperer l'etape saisie et le nombre d'etapes total
228
-		list($etape, $etapes) = $e;
229
-		$etape_demandee = intval(_request('aller_a_etape')); // possibilite de poster un entier dans aller_a_etape
223
+    if (
224
+        $form = $args['form']
225
+        and ($e = cvtmulti_recuperer_post_precedents($form)) !== false
226
+    ) {
227
+        // recuperer l'etape saisie et le nombre d'etapes total
228
+        list($etape, $etapes) = $e;
229
+        $etape_demandee = intval(_request('aller_a_etape')); // possibilite de poster un entier dans aller_a_etape
230 230
 
231
-		$args['etape_saisie'] = $etape;
232
-		$args['etapes'] = $etapes;
233
-		// lancer les verifs pour chaque etape deja saisie de 1 a $etape
234
-		$erreurs_etapes = [];
235
-		$derniere_etape_ok = 0;
236
-		$e = 0;
237
-		while ($e < max($etape, $etape_demandee - 1) and $e < $etapes) {
238
-			$e++;
239
-			$erreurs_etapes[$e] = [];
240
-			if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) {
241
-				$erreurs_etapes[$e] = call_user_func_array($verifier, $args['args']);
242
-			} elseif ($verifier = charger_fonction('verifier_etape', "formulaires/$form/", true)) {
243
-				$a = $args['args'];
244
-				array_unshift($a, $e);
245
-				$erreurs_etapes[$e] = call_user_func_array($verifier, $a);
246
-			}
247
-			// et on appelle un pipeline dedie aux etapes, plus easy
248
-			$args['etape'] = $e;
249
-			$args['etape_demandee'] = $etape_demandee;
250
-			$erreurs_etapes[$e] = pipeline(
251
-				'formulaire_verifier_etape',
252
-				[
253
-					'args' => $args,
254
-					'data' => $erreurs_etapes[$e]
255
-				]
256
-			);
231
+        $args['etape_saisie'] = $etape;
232
+        $args['etapes'] = $etapes;
233
+        // lancer les verifs pour chaque etape deja saisie de 1 a $etape
234
+        $erreurs_etapes = [];
235
+        $derniere_etape_ok = 0;
236
+        $e = 0;
237
+        while ($e < max($etape, $etape_demandee - 1) and $e < $etapes) {
238
+            $e++;
239
+            $erreurs_etapes[$e] = [];
240
+            if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) {
241
+                $erreurs_etapes[$e] = call_user_func_array($verifier, $args['args']);
242
+            } elseif ($verifier = charger_fonction('verifier_etape', "formulaires/$form/", true)) {
243
+                $a = $args['args'];
244
+                array_unshift($a, $e);
245
+                $erreurs_etapes[$e] = call_user_func_array($verifier, $a);
246
+            }
247
+            // et on appelle un pipeline dedie aux etapes, plus easy
248
+            $args['etape'] = $e;
249
+            $args['etape_demandee'] = $etape_demandee;
250
+            $erreurs_etapes[$e] = pipeline(
251
+                'formulaire_verifier_etape',
252
+                [
253
+                    'args' => $args,
254
+                    'data' => $erreurs_etapes[$e]
255
+                ]
256
+            );
257 257
 
258
-			if ($derniere_etape_ok == $e - 1 and !count($erreurs_etapes[$e])) {
259
-				$derniere_etape_ok = $e;
260
-			}
261
-			// possibilite de poster dans _retour_etape_x ou aller_a_etape
262
-			if (!is_null(_request("_retour_etape_$e"))) {
263
-				$etape_demandee = $e;
264
-			}
265
-			// Il se peut que les verifications ait décidé de faire sauter des étapes
266
-			if ($aller_a_etape = intval(_request('aller_a_etape'))) {
267
-				$etape_demandee = $aller_a_etape; // possibilite de poster un entier dans aller_a_etape
268
-			}
269
-		}
258
+            if ($derniere_etape_ok == $e - 1 and !count($erreurs_etapes[$e])) {
259
+                $derniere_etape_ok = $e;
260
+            }
261
+            // possibilite de poster dans _retour_etape_x ou aller_a_etape
262
+            if (!is_null(_request("_retour_etape_$e"))) {
263
+                $etape_demandee = $e;
264
+            }
265
+            // Il se peut que les verifications ait décidé de faire sauter des étapes
266
+            if ($aller_a_etape = intval(_request('aller_a_etape'))) {
267
+                $etape_demandee = $aller_a_etape; // possibilite de poster un entier dans aller_a_etape
268
+            }
269
+        }
270 270
 
271 271
 
272
-		// si la derniere etape OK etait la derniere
273
-		// on renvoie le flux inchange et ca declenche traiter
274
-		if (
275
-			$derniere_etape_ok == $etapes
276
-			and (!$etape_demandee or $etape_demandee >= $etapes)
277
-		) {
278
-			return $erreurs;
279
-		} else {
280
-			$etape = $derniere_etape_ok + 1;
281
-			if ($etape_demandee > 0 and $etape_demandee < $etape) {
282
-				$etape = $etape_demandee;
283
-			}
284
-			$etape = min($etape, $etapes);
285
-			#var_dump("prochaine etape $etape");
286
-			// retourner les erreurs de l'etape ciblee
287
-			$erreurs = $erreurs_etapes[$etape] ?? [];
288
-			// Ne pas se tromper dans le texte du message d'erreur : la clé '_etapes' n'est pas une erreur !
289
-			if ($erreurs) {
290
-				if (!isset($erreurs['message_erreur'])) {
291
-					$erreurs['message_erreur'] = singulier_ou_pluriel(count($erreurs), 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie');
292
-				}
293
-			} else {
294
-				$erreurs['message_erreur'] = '';
295
-			}
296
-			$erreurs['_etapes'] = "etape suivante $etape";
297
-			set_request('_etape', $etape);
298
-		}
299
-	}
272
+        // si la derniere etape OK etait la derniere
273
+        // on renvoie le flux inchange et ca declenche traiter
274
+        if (
275
+            $derniere_etape_ok == $etapes
276
+            and (!$etape_demandee or $etape_demandee >= $etapes)
277
+        ) {
278
+            return $erreurs;
279
+        } else {
280
+            $etape = $derniere_etape_ok + 1;
281
+            if ($etape_demandee > 0 and $etape_demandee < $etape) {
282
+                $etape = $etape_demandee;
283
+            }
284
+            $etape = min($etape, $etapes);
285
+            #var_dump("prochaine etape $etape");
286
+            // retourner les erreurs de l'etape ciblee
287
+            $erreurs = $erreurs_etapes[$etape] ?? [];
288
+            // Ne pas se tromper dans le texte du message d'erreur : la clé '_etapes' n'est pas une erreur !
289
+            if ($erreurs) {
290
+                if (!isset($erreurs['message_erreur'])) {
291
+                    $erreurs['message_erreur'] = singulier_ou_pluriel(count($erreurs), 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie');
292
+                }
293
+            } else {
294
+                $erreurs['message_erreur'] = '';
295
+            }
296
+            $erreurs['_etapes'] = "etape suivante $etape";
297
+            set_request('_etape', $etape);
298
+        }
299
+    }
300 300
 
301
-	return $erreurs;
301
+    return $erreurs;
302 302
 }
303 303
 
304 304
 /**
@@ -310,17 +310,17 @@  discard block
 block discarded – undo
310 310
  * @return array
311 311
  */
312 312
 function cvtmulti_styliser($flux) {
313
-	if (
314
-		strncmp($flux['args']['fond'], 'formulaires/', 12) == 0
315
-		and isset($flux['args']['contexte']['_etapes'])
316
-		and isset($flux['args']['contexte']['_etape'])
317
-		and ($e = $flux['args']['contexte']['_etape']) > 1
318
-		and $ext = $flux['args']['ext']
319
-		and $f = $flux['data']
320
-		and file_exists($f . "_$e.$ext")
321
-	) {
322
-		$flux['data'] = $f . "_$e";
323
-	}
313
+    if (
314
+        strncmp($flux['args']['fond'], 'formulaires/', 12) == 0
315
+        and isset($flux['args']['contexte']['_etapes'])
316
+        and isset($flux['args']['contexte']['_etape'])
317
+        and ($e = $flux['args']['contexte']['_etape']) > 1
318
+        and $ext = $flux['args']['ext']
319
+        and $f = $flux['data']
320
+        and file_exists($f . "_$e.$ext")
321
+    ) {
322
+        $flux['data'] = $f . "_$e";
323
+    }
324 324
 
325
-	return $flux;
325
+    return $flux;
326 326
 }
Please login to merge, or discard this patch.