Completed
Push — master ( 0b76de...a8026d )
by cam
04:30
created
ecrire/base/objets.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1578,7 +1578,7 @@
 block discarded – undo
1578 1578
 /**
1579 1579
  * Donne les informations de parenté directe d'un type d'objet si on en trouve
1580 1580
  * 
1581
- * @param $objet
1581
+ * @param string $objet
1582 1582
  *     Type de l'objet dont on cherche les informations de parent
1583 1583
  * @return array|false
1584 1584
  *     Retourne un tableau de tableau contenant les informations de type et de champ pour trouver le parent ou false sinon
Please login to merge, or discard this patch.
Indentation   +1233 added lines, -1233 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
 /**
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
  * @return void
33 33
  **/
34 34
 function array_set_merge(&$table, $index, $valeur) {
35
-	if (!isset($table[$index])) {
36
-		$table[$index] = $valeur;
37
-	} else {
38
-		$table[$index] = array_merge($table[$index], $valeur);
39
-	}
35
+    if (!isset($table[$index])) {
36
+        $table[$index] = $valeur;
37
+    } else {
38
+        $table[$index] = array_merge($table[$index], $valeur);
39
+    }
40 40
 }
41 41
 
42 42
 /**
@@ -53,439 +53,439 @@  discard block
 block discarded – undo
53 53
  * @return array|bool
54 54
  */
55 55
 function lister_tables_objets_sql($table_sql = null, $desc = array()) {
56
-	static $deja_la = false;
57
-	static $infos_tables = null;
58
-	static $md5 = null;
59
-	static $plugin_hash = null;
60
-
61
-	// plugins hash connu ? non si _CACHE_PLUGINS_OPT est pas encore chargé.
62
-	$_PLUGINS_HASH = defined('_PLUGINS_HASH') ? _PLUGINS_HASH : '!_CACHE_PLUGINS_OPT';
63
-
64
-	// prealablement recuperer les tables_principales
65
-	if (is_null($infos_tables) or $plugin_hash !== $_PLUGINS_HASH) {
66
-		// pas de reentrance (cas base/serial)
67
-		if ($deja_la) {
68
-			spip_log('Re-entrance anormale sur lister_tables_objets_sql : '
69
-				. var_export(debug_backtrace(), true), _LOG_CRITIQUE);
70
-
71
-			return ($table_sql === '::md5' ? $md5 : array());
72
-		}
73
-		$deja_la = true;
74
-		$plugin_hash = $_PLUGINS_HASH; // avant de lancer les pipelines
75
-
76
-		// recuperer les declarations explicites ancienne mode
77
-		// qui servent a completer declarer_tables_objets_sql
78
-		base_serial($GLOBALS['tables_principales']);
79
-		base_auxiliaires($GLOBALS['tables_auxiliaires']);
80
-		$infos_tables = array(
81
-			'spip_articles' => array(
82
-				'page' => 'article',
83
-				'texte_retour' => 'icone_retour_article',
84
-				'texte_modifier' => 'icone_modifier_article',
85
-				'texte_creer' => 'icone_ecrire_article',
86
-				'texte_objets' => 'public:articles',
87
-				'texte_objet' => 'public:article',
88
-				'texte_signale_edition' => 'texte_travail_article',
89
-				'info_aucun_objet' => 'info_aucun_article',
90
-				'info_1_objet' => 'info_1_article',
91
-				'info_nb_objets' => 'info_nb_articles',
92
-				'texte_logo_objet' => 'logo_article',
93
-				'texte_langue_objet' => 'titre_langue_article',
94
-				'texte_definir_comme_traduction_objet' => 'trad_lier',
95
-				'titre' => 'titre, lang',
96
-				'date' => 'date',
97
-				'principale' => 'oui',
98
-				'introduction_longueur' => '500',
99
-				'champs_editables' => array(
100
-					'surtitre',
101
-					'titre',
102
-					'soustitre',
103
-					'descriptif',
104
-					'nom_site',
105
-					'url_site',
106
-					'chapo',
107
-					'texte',
108
-					'ps',
109
-					'virtuel'
110
-				),
111
-				'champs_versionnes' => array(
112
-					'id_rubrique',
113
-					'surtitre',
114
-					'titre',
115
-					'soustitre',
116
-					'jointure_auteurs',
117
-					'descriptif',
118
-					'nom_site',
119
-					'url_site',
120
-					'chapo',
121
-					'texte',
122
-					'ps'
123
-				),
124
-				'field' => array(
125
-					'id_article' => 'bigint(21) NOT NULL',
126
-					'surtitre' => "text DEFAULT '' NOT NULL",
127
-					'titre' => "text DEFAULT '' NOT NULL",
128
-					'soustitre' => "text DEFAULT '' NOT NULL",
129
-					'id_rubrique' => "bigint(21) DEFAULT '0' NOT NULL",
130
-					'descriptif' => "text DEFAULT '' NOT NULL",
131
-					'chapo' => "mediumtext DEFAULT '' NOT NULL",
132
-					'texte' => "longtext DEFAULT '' NOT NULL",
133
-					'ps' => "mediumtext DEFAULT '' NOT NULL",
134
-					'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
135
-					'statut' => "varchar(10) DEFAULT '0' NOT NULL",
136
-					'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL",
137
-					'maj' => 'TIMESTAMP',
138
-					'export' => "VARCHAR(10) DEFAULT 'oui'",
139
-					'date_redac' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
140
-					'visites' => "integer DEFAULT '0' NOT NULL",
141
-					'referers' => "integer DEFAULT '0' NOT NULL",
142
-					'popularite' => "DOUBLE DEFAULT '0' NOT NULL",
143
-					'accepter_forum' => "CHAR(3) DEFAULT '' NOT NULL",
144
-					'date_modif' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
145
-					'lang' => "VARCHAR(10) DEFAULT '' NOT NULL",
146
-					'langue_choisie' => "VARCHAR(3) DEFAULT 'non'",
147
-					'id_trad' => "bigint(21) DEFAULT '0' NOT NULL",
148
-					'nom_site' => "tinytext DEFAULT '' NOT NULL",
149
-					'url_site' => "text DEFAULT '' NOT NULL",
150
-					'virtuel' => "text DEFAULT '' NOT NULL",
151
-				),
152
-				'key' => array(
153
-					'PRIMARY KEY' => 'id_article',
154
-					'KEY id_rubrique' => 'id_rubrique',
155
-					'KEY id_secteur' => 'id_secteur',
156
-					'KEY id_trad' => 'id_trad',
157
-					'KEY lang' => 'lang',
158
-					'KEY statut' => 'statut, date',
159
-				),
160
-				'join' => array(
161
-					'id_article' => 'id_article',
162
-					'id_rubrique' => 'id_rubrique'
163
-				),
164
-				'parent' => [
165
-					['type' => 'rubrique', 'champ' => 'id_rubrique']
166
-				],
167
-				'rechercher_champs' => array(
168
-					'surtitre' => 5,
169
-					'titre' => 8,
170
-					'soustitre' => 5,
171
-					'chapo' => 3,
172
-					'texte' => 1,
173
-					'ps' => 1,
174
-					'nom_site' => 1,
175
-					'url_site' => 1,
176
-					'descriptif' => 4
177
-				),
178
-				'rechercher_jointures' => array(
179
-					'auteur' => array('nom' => 10),
180
-				),
181
-				'statut' => array(
182
-					array(
183
-						'champ' => 'statut',
184
-						'publie' => 'publie',
185
-						'previsu' => 'publie,prop,prepa/auteur',
186
-						'post_date' => 'date',
187
-						'exception' => array('statut', 'tout')
188
-					)
189
-				),
190
-				'statut_titres' => array(
191
-					'prepa' => 'info_article_redaction',
192
-					'prop' => 'info_article_propose',
193
-					'publie' => 'info_article_publie',
194
-					'refuse' => 'info_article_refuse',
195
-					'poubelle' => 'info_article_supprime'
196
-				),
197
-				'statut_textes_instituer' => array(
198
-					'prepa' => 'texte_statut_en_cours_redaction',
199
-					'prop' => 'texte_statut_propose_evaluation',
200
-					'publie' => 'texte_statut_publie',
201
-					'refuse' => 'texte_statut_refuse',
202
-					'poubelle' => 'texte_statut_poubelle',
203
-				),
204
-				'texte_changer_statut' => 'texte_article_statut',
205
-				'aide_changer_statut' => 'artstatut',
206
-				'tables_jointures' => array(
207
-					'profondeur' => 'rubriques',
208
-					#'id_auteur' => 'auteurs_liens' // declaration generique plus bas
209
-				),
210
-			),
211
-			'spip_auteurs' => array(
212
-				'page' => 'auteur',
213
-				'texte_retour' => 'icone_retour',
214
-				'texte_ajouter' => 'titre_ajouter_un_auteur',
215
-				'texte_modifier' => 'admin_modifier_auteur',
216
-				'texte_objets' => 'icone_auteurs',
217
-				'texte_objet' => 'public:auteur',
218
-				'info_aucun_objet' => 'info_aucun_auteur',
219
-				'info_1_objet' => 'info_1_auteur',
220
-				'info_nb_objets' => 'info_nb_auteurs',
221
-				'texte_logo_objet' => 'logo_auteur',
222
-				'texte_creer_associer' => 'creer_et_associer_un_auteur',
223
-				'titre' => "nom AS titre, '' AS lang",
224
-				'date' => 'date',
225
-				'principale' => 'oui',
226
-				'champs_editables' => array('nom', 'email', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'),
227
-				'champs_versionnes' => array('nom', 'bio', 'email', 'nom_site', 'url_site', 'login'),
228
-				'field' => array(
229
-					'id_auteur' => 'bigint(21) NOT NULL',
230
-					'nom' => "text DEFAULT '' NOT NULL",
231
-					'bio' => "text DEFAULT '' NOT NULL",
232
-					'email' => "tinytext DEFAULT '' NOT NULL",
233
-					'nom_site' => "tinytext DEFAULT '' NOT NULL",
234
-					'url_site' => "text DEFAULT '' NOT NULL",
235
-					'login' => 'VARCHAR(255) BINARY',
236
-					'pass' => "tinytext DEFAULT '' NOT NULL",
237
-					'low_sec' => "tinytext DEFAULT '' NOT NULL",
238
-					'statut' => "varchar(255)  DEFAULT '0' NOT NULL",
239
-					'webmestre' => "varchar(3)  DEFAULT 'non' NOT NULL",
240
-					'maj' => 'TIMESTAMP',
241
-					'pgp' => "TEXT DEFAULT '' NOT NULL",
242
-					'htpass' => "tinytext DEFAULT '' NOT NULL",
243
-					'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
244
-					'alea_actuel' => 'tinytext',
245
-					'alea_futur' => 'tinytext',
246
-					'prefs' => 'text',
247
-					'cookie_oubli' => 'tinytext',
248
-					'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL",
249
-					'lang' => "VARCHAR(10) DEFAULT '' NOT NULL",
250
-					'imessage' => "VARCHAR(3) DEFAULT '' NOT NULL"
251
-				),
252
-				'key' => array(
253
-					'PRIMARY KEY' => 'id_auteur',
254
-					'KEY login' => 'login',
255
-					'KEY statut' => 'statut',
256
-					'KEY en_ligne' => 'en_ligne',
257
-				),
258
-				'join' => array(
259
-					'id_auteur' => 'id_auteur',
260
-					'login' => 'login'
261
-				),
262
-				'rechercher_champs' => array(
263
-					'nom' => 5,
264
-					'bio' => 1,
265
-					'email' => 1,
266
-					'nom_site' => 1,
267
-					'url_site' => 1,
268
-					'login' => 1
269
-				),
270
-				// 2 conditions pour les auteurs : statut!=poubelle,
271
-				// et avoir des articles publies
272
-				'statut' => array(
273
-					array(
274
-						'champ' => 'statut',
275
-						'publie' => '!5poubelle',
276
-						'previsu' => '!5poubelle',
277
-						'exception' => 'statut'
278
-					),
279
-					array(
280
-						'champ' => array(
281
-							array('spip_auteurs_liens', 'id_auteur'),
282
-							array(
283
-								'spip_articles',
284
-								array('id_objet', 'id_article', 'objet', 'article')
285
-							),
286
-							'statut'
287
-						),
288
-						'publie' => 'publie',
289
-						'previsu' => '!',
290
-						'post_date' => 'date',
291
-						'exception' => array('statut', 'lien', 'tout')
292
-					),
293
-				),
294
-				'statut_images' => array(
295
-					'auteur-6forum-16.png',
296
-					'0minirezo' => 'auteur-0minirezo-16.png',
297
-					'1comite' => 'auteur-1comite-16.png',
298
-					'6forum' => 'auteur-6forum-16.png',
299
-					'5poubelle' => 'auteur-5poubelle-16.png',
300
-					'nouveau' => ''
301
-				),
302
-				'statut_titres' => array(
303
-					'titre_image_visiteur',
304
-					'0minirezo' => 'titre_image_administrateur',
305
-					'1comite' => 'titre_image_redacteur_02',
306
-					'6forum' => 'titre_image_visiteur',
307
-					'5poubelle' => 'titre_image_auteur_supprime',
308
-				),
309
-				'tables_jointures' => array(#'auteurs_liens' // declaration generique plus bas
310
-				),
311
-			),
312
-			'spip_rubriques' => array(
313
-				'page' => 'rubrique',
314
-				'url_voir' => 'rubrique',
315
-				'url_edit' => 'rubrique_edit',
316
-				'texte_retour' => 'icone_retour',
317
-				'texte_objets' => 'public:rubriques',
318
-				'texte_objet' => 'public:rubrique',
319
-				'texte_modifier' => 'icone_modifier_rubrique',
320
-				'texte_creer' => 'icone_creer_rubrique',
321
-				'texte_ajouter' => 'titre_ajouter_une_rubrique',
322
-				'texte_creer_associer' => 'creer_et_associer_une_rubrique',
323
-				'info_aucun_objet' => 'info_aucun_rubrique',
324
-				'info_1_objet' => 'info_1_rubrique',
325
-				'info_nb_objets' => 'info_nb_rubriques',
326
-				'texte_logo_objet' => 'logo_rubrique',
327
-				'texte_langue_objet' => 'titre_langue_rubrique',
328
-				'texte_definir_comme_traduction_objet' => 'texte_definir_comme_traduction_rubrique',
329
-				'titre' => 'titre, lang',
330
-				'date' => 'date',
331
-				'principale' => 'oui',
332
-				'introduction_longueur' => '600',
333
-				'champs_editables' => array('titre', 'texte', 'descriptif', 'extra'),
334
-				'champs_versionnes' => array('titre', 'descriptif', 'texte'),
335
-				'field' => array(
336
-					'id_rubrique' => 'bigint(21) NOT NULL',
337
-					'id_parent' => "bigint(21) DEFAULT '0' NOT NULL",
338
-					'titre' => "text DEFAULT '' NOT NULL",
339
-					'descriptif' => "text DEFAULT '' NOT NULL",
340
-					'texte' => "longtext DEFAULT '' NOT NULL",
341
-					'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL",
342
-					'maj' => 'TIMESTAMP',
343
-					'statut' => "varchar(10) DEFAULT '0' NOT NULL",
344
-					'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
345
-					'lang' => "VARCHAR(10) DEFAULT '' NOT NULL",
346
-					'langue_choisie' => "VARCHAR(3) DEFAULT 'non'",
347
-					'statut_tmp' => "varchar(10) DEFAULT '0' NOT NULL",
348
-					'date_tmp' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
349
-					'profondeur' => "smallint(5) DEFAULT '0' NOT NULL"
350
-				),
351
-				'key' => array(
352
-					'PRIMARY KEY' => 'id_rubrique',
353
-					'KEY lang' => 'lang',
354
-					'KEY id_parent' => 'id_parent',
355
-				),
356
-				'parent' => [
357
-					['type' => 'rubrique', 'champ' => 'id_parent']
358
-				],
359
-				'rechercher_champs' => array(
360
-					'titre' => 8,
361
-					'descriptif' => 5,
362
-					'texte' => 1
363
-				),
364
-				'statut' => array(
365
-					array(
366
-						'champ' => 'statut',
367
-						'publie' => 'publie',
368
-						'previsu' => '!',
369
-						'exception' => array('statut', 'tout')
370
-					),
371
-				),
372
-				'tables_jointures' => array(#'id_auteur' => 'auteurs_liens' // declaration generique plus bas
373
-				),
374
-			),
375
-			// toutes les tables ont le droit a une jointure sur les auteurs
376
-			array('tables_jointures' => array('id_auteur' => 'auteurs_liens'))
377
-		);
378
-
379
-		// avant d'appeller les pipeline qui peuvent generer une reentrance a l'install
380
-		// initialiser la signature
381
-		$md5 = md5(serialize($infos_tables));
382
-
383
-		$GLOBALS['tables_principales'] = pipeline('declarer_tables_principales', $GLOBALS['tables_principales']);
384
-		$GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires', $GLOBALS['tables_auxiliaires']);
385
-		$infos_tables = pipeline('declarer_tables_objets_sql', $infos_tables);
386
-
387
-		// completer les informations manquantes ou implicites
388
-		$all = array();
389
-		foreach (array_keys($infos_tables) as $t) {
390
-			// les cles numeriques servent a declarer
391
-			// les proprietes applicables a tous les objets
392
-			// on les mets de cote
393
-			if (is_numeric($t)) {
394
-				$all = array_merge_recursive($all, $infos_tables[$t]);
395
-				unset($infos_tables[$t]);
396
-			} else {
397
-				$infos_tables[$t] = renseigner_table_objet_sql($t, $infos_tables[$t]);
398
-			}
399
-		}
400
-
401
-		// repercuter les proprietes generales communes a tous les objets
402
-		foreach (array_keys($infos_tables) as $t) {
403
-			foreach ($all as $i => $v) {
404
-				if (in_array($i, array('tables_jointures', 'champs_versionnes'))) {
405
-					$add = $all[$i];
406
-					// eviter les doublons de declaration de table jointure (ex des mots sur auteurs)
407
-					// pour les declarations generiques avec cles numeriques
408
-					if ($i == 'tables_jointures' and isset($infos_tables[$t][$i]) and count($infos_tables[$t][$i])) {
409
-						$doublons = array_intersect($infos_tables[$t][$i], $add);
410
-						foreach ($doublons as $d) {
411
-							if (is_numeric(array_search($d, $infos_tables[$t][$i]))
412
-								and is_numeric($k = array_search($d, $add))
413
-							) {
414
-								unset($add[$k]);
415
-							}
416
-						}
417
-					}
418
-					$infos_tables[$t][$i] = array_merge(isset($infos_tables[$t][$i]) ? $infos_tables[$t][$i] : array(), $add);
419
-				} else {
420
-					$infos_tables[$t][$i] = array_merge_recursive(
421
-						isset($infos_tables[$t][$i]) ? $infos_tables[$t][$i] : array(),
422
-						$all[$i]
423
-					);
424
-				}
425
-			}
426
-		}
427
-
428
-		// completer les tables principales et auxiliaires
429
-		// avec celles declarees uniquement dans declarer_table_objets_sql
430
-		// pour assurer la compat en transition
431
-		foreach ($infos_tables as $table => $infos) {
432
-			$principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires');
433
-			// memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx
434
-			// qui a ete appelle avant
435
-			$mem = (isset($GLOBALS[$principale_ou_auxiliaire][$table]) ? $GLOBALS[$principale_ou_auxiliaire][$table] : array());
436
-			// l'ajouter au tableau
437
-			$GLOBALS[$principale_ou_auxiliaire][$table] = array();
438
-			if (isset($infos['field']) and isset($infos['key'])) {
439
-				foreach (array('field', 'key', 'join') as $k) {
440
-					if (isset($infos_tables[$table][$k])) {
441
-						$GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k];
442
-					}
443
-				}
444
-			} else {
445
-				// ici on ne renvoie que les declarations, donc RIEN
446
-				// pour avoir la vrai description en base, il faut passer par trouver_table
447
-				$GLOBALS[$principale_ou_auxiliaire][$table] = array();
448
-			}
449
-			if (count($mem)) {
450
-				foreach (array_keys($mem) as $k) {
451
-					if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) {
452
-						$GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge(
453
-							$GLOBALS[$principale_ou_auxiliaire][$table][$k],
454
-							$mem[$k]
455
-						);
456
-					} else {
457
-						$GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k];
458
-					}
459
-				}
460
-			}
461
-		}
462
-
463
-		// recuperer les interfaces (table_titre, table_date)
464
-		// on ne le fait que dans un second temps pour que table_objet soit fonctionnel
465
-		// dans le pipeline de declarer_tables_interfaces
466
-		include_spip('public/interfaces');
467
-		foreach (array_keys($infos_tables) as $t) {
468
-			$infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]);
469
-		}
470
-
471
-		$deja_la = false;
472
-		// signature
473
-		$md5 = md5(serialize($infos_tables));
474
-	}
475
-	if ($table_sql === '::md5') {
476
-		return $md5;
477
-	}
478
-	if ($table_sql and !isset($infos_tables[$table_sql])) {
479
-		#$desc = renseigner_table_objet_sql($table_sql,$desc);
480
-		$desc = renseigner_table_objet_interfaces($table_sql, $desc);
481
-
482
-		return $desc;
483
-	}
484
-	if ($table_sql) {
485
-		return isset($infos_tables[$table_sql]) ? $infos_tables[$table_sql] : array();
486
-	}
487
-
488
-	return $infos_tables;
56
+    static $deja_la = false;
57
+    static $infos_tables = null;
58
+    static $md5 = null;
59
+    static $plugin_hash = null;
60
+
61
+    // plugins hash connu ? non si _CACHE_PLUGINS_OPT est pas encore chargé.
62
+    $_PLUGINS_HASH = defined('_PLUGINS_HASH') ? _PLUGINS_HASH : '!_CACHE_PLUGINS_OPT';
63
+
64
+    // prealablement recuperer les tables_principales
65
+    if (is_null($infos_tables) or $plugin_hash !== $_PLUGINS_HASH) {
66
+        // pas de reentrance (cas base/serial)
67
+        if ($deja_la) {
68
+            spip_log('Re-entrance anormale sur lister_tables_objets_sql : '
69
+                . var_export(debug_backtrace(), true), _LOG_CRITIQUE);
70
+
71
+            return ($table_sql === '::md5' ? $md5 : array());
72
+        }
73
+        $deja_la = true;
74
+        $plugin_hash = $_PLUGINS_HASH; // avant de lancer les pipelines
75
+
76
+        // recuperer les declarations explicites ancienne mode
77
+        // qui servent a completer declarer_tables_objets_sql
78
+        base_serial($GLOBALS['tables_principales']);
79
+        base_auxiliaires($GLOBALS['tables_auxiliaires']);
80
+        $infos_tables = array(
81
+            'spip_articles' => array(
82
+                'page' => 'article',
83
+                'texte_retour' => 'icone_retour_article',
84
+                'texte_modifier' => 'icone_modifier_article',
85
+                'texte_creer' => 'icone_ecrire_article',
86
+                'texte_objets' => 'public:articles',
87
+                'texte_objet' => 'public:article',
88
+                'texte_signale_edition' => 'texte_travail_article',
89
+                'info_aucun_objet' => 'info_aucun_article',
90
+                'info_1_objet' => 'info_1_article',
91
+                'info_nb_objets' => 'info_nb_articles',
92
+                'texte_logo_objet' => 'logo_article',
93
+                'texte_langue_objet' => 'titre_langue_article',
94
+                'texte_definir_comme_traduction_objet' => 'trad_lier',
95
+                'titre' => 'titre, lang',
96
+                'date' => 'date',
97
+                'principale' => 'oui',
98
+                'introduction_longueur' => '500',
99
+                'champs_editables' => array(
100
+                    'surtitre',
101
+                    'titre',
102
+                    'soustitre',
103
+                    'descriptif',
104
+                    'nom_site',
105
+                    'url_site',
106
+                    'chapo',
107
+                    'texte',
108
+                    'ps',
109
+                    'virtuel'
110
+                ),
111
+                'champs_versionnes' => array(
112
+                    'id_rubrique',
113
+                    'surtitre',
114
+                    'titre',
115
+                    'soustitre',
116
+                    'jointure_auteurs',
117
+                    'descriptif',
118
+                    'nom_site',
119
+                    'url_site',
120
+                    'chapo',
121
+                    'texte',
122
+                    'ps'
123
+                ),
124
+                'field' => array(
125
+                    'id_article' => 'bigint(21) NOT NULL',
126
+                    'surtitre' => "text DEFAULT '' NOT NULL",
127
+                    'titre' => "text DEFAULT '' NOT NULL",
128
+                    'soustitre' => "text DEFAULT '' NOT NULL",
129
+                    'id_rubrique' => "bigint(21) DEFAULT '0' NOT NULL",
130
+                    'descriptif' => "text DEFAULT '' NOT NULL",
131
+                    'chapo' => "mediumtext DEFAULT '' NOT NULL",
132
+                    'texte' => "longtext DEFAULT '' NOT NULL",
133
+                    'ps' => "mediumtext DEFAULT '' NOT NULL",
134
+                    'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
135
+                    'statut' => "varchar(10) DEFAULT '0' NOT NULL",
136
+                    'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL",
137
+                    'maj' => 'TIMESTAMP',
138
+                    'export' => "VARCHAR(10) DEFAULT 'oui'",
139
+                    'date_redac' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
140
+                    'visites' => "integer DEFAULT '0' NOT NULL",
141
+                    'referers' => "integer DEFAULT '0' NOT NULL",
142
+                    'popularite' => "DOUBLE DEFAULT '0' NOT NULL",
143
+                    'accepter_forum' => "CHAR(3) DEFAULT '' NOT NULL",
144
+                    'date_modif' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
145
+                    'lang' => "VARCHAR(10) DEFAULT '' NOT NULL",
146
+                    'langue_choisie' => "VARCHAR(3) DEFAULT 'non'",
147
+                    'id_trad' => "bigint(21) DEFAULT '0' NOT NULL",
148
+                    'nom_site' => "tinytext DEFAULT '' NOT NULL",
149
+                    'url_site' => "text DEFAULT '' NOT NULL",
150
+                    'virtuel' => "text DEFAULT '' NOT NULL",
151
+                ),
152
+                'key' => array(
153
+                    'PRIMARY KEY' => 'id_article',
154
+                    'KEY id_rubrique' => 'id_rubrique',
155
+                    'KEY id_secteur' => 'id_secteur',
156
+                    'KEY id_trad' => 'id_trad',
157
+                    'KEY lang' => 'lang',
158
+                    'KEY statut' => 'statut, date',
159
+                ),
160
+                'join' => array(
161
+                    'id_article' => 'id_article',
162
+                    'id_rubrique' => 'id_rubrique'
163
+                ),
164
+                'parent' => [
165
+                    ['type' => 'rubrique', 'champ' => 'id_rubrique']
166
+                ],
167
+                'rechercher_champs' => array(
168
+                    'surtitre' => 5,
169
+                    'titre' => 8,
170
+                    'soustitre' => 5,
171
+                    'chapo' => 3,
172
+                    'texte' => 1,
173
+                    'ps' => 1,
174
+                    'nom_site' => 1,
175
+                    'url_site' => 1,
176
+                    'descriptif' => 4
177
+                ),
178
+                'rechercher_jointures' => array(
179
+                    'auteur' => array('nom' => 10),
180
+                ),
181
+                'statut' => array(
182
+                    array(
183
+                        'champ' => 'statut',
184
+                        'publie' => 'publie',
185
+                        'previsu' => 'publie,prop,prepa/auteur',
186
+                        'post_date' => 'date',
187
+                        'exception' => array('statut', 'tout')
188
+                    )
189
+                ),
190
+                'statut_titres' => array(
191
+                    'prepa' => 'info_article_redaction',
192
+                    'prop' => 'info_article_propose',
193
+                    'publie' => 'info_article_publie',
194
+                    'refuse' => 'info_article_refuse',
195
+                    'poubelle' => 'info_article_supprime'
196
+                ),
197
+                'statut_textes_instituer' => array(
198
+                    'prepa' => 'texte_statut_en_cours_redaction',
199
+                    'prop' => 'texte_statut_propose_evaluation',
200
+                    'publie' => 'texte_statut_publie',
201
+                    'refuse' => 'texte_statut_refuse',
202
+                    'poubelle' => 'texte_statut_poubelle',
203
+                ),
204
+                'texte_changer_statut' => 'texte_article_statut',
205
+                'aide_changer_statut' => 'artstatut',
206
+                'tables_jointures' => array(
207
+                    'profondeur' => 'rubriques',
208
+                    #'id_auteur' => 'auteurs_liens' // declaration generique plus bas
209
+                ),
210
+            ),
211
+            'spip_auteurs' => array(
212
+                'page' => 'auteur',
213
+                'texte_retour' => 'icone_retour',
214
+                'texte_ajouter' => 'titre_ajouter_un_auteur',
215
+                'texte_modifier' => 'admin_modifier_auteur',
216
+                'texte_objets' => 'icone_auteurs',
217
+                'texte_objet' => 'public:auteur',
218
+                'info_aucun_objet' => 'info_aucun_auteur',
219
+                'info_1_objet' => 'info_1_auteur',
220
+                'info_nb_objets' => 'info_nb_auteurs',
221
+                'texte_logo_objet' => 'logo_auteur',
222
+                'texte_creer_associer' => 'creer_et_associer_un_auteur',
223
+                'titre' => "nom AS titre, '' AS lang",
224
+                'date' => 'date',
225
+                'principale' => 'oui',
226
+                'champs_editables' => array('nom', 'email', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'),
227
+                'champs_versionnes' => array('nom', 'bio', 'email', 'nom_site', 'url_site', 'login'),
228
+                'field' => array(
229
+                    'id_auteur' => 'bigint(21) NOT NULL',
230
+                    'nom' => "text DEFAULT '' NOT NULL",
231
+                    'bio' => "text DEFAULT '' NOT NULL",
232
+                    'email' => "tinytext DEFAULT '' NOT NULL",
233
+                    'nom_site' => "tinytext DEFAULT '' NOT NULL",
234
+                    'url_site' => "text DEFAULT '' NOT NULL",
235
+                    'login' => 'VARCHAR(255) BINARY',
236
+                    'pass' => "tinytext DEFAULT '' NOT NULL",
237
+                    'low_sec' => "tinytext DEFAULT '' NOT NULL",
238
+                    'statut' => "varchar(255)  DEFAULT '0' NOT NULL",
239
+                    'webmestre' => "varchar(3)  DEFAULT 'non' NOT NULL",
240
+                    'maj' => 'TIMESTAMP',
241
+                    'pgp' => "TEXT DEFAULT '' NOT NULL",
242
+                    'htpass' => "tinytext DEFAULT '' NOT NULL",
243
+                    'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
244
+                    'alea_actuel' => 'tinytext',
245
+                    'alea_futur' => 'tinytext',
246
+                    'prefs' => 'text',
247
+                    'cookie_oubli' => 'tinytext',
248
+                    'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL",
249
+                    'lang' => "VARCHAR(10) DEFAULT '' NOT NULL",
250
+                    'imessage' => "VARCHAR(3) DEFAULT '' NOT NULL"
251
+                ),
252
+                'key' => array(
253
+                    'PRIMARY KEY' => 'id_auteur',
254
+                    'KEY login' => 'login',
255
+                    'KEY statut' => 'statut',
256
+                    'KEY en_ligne' => 'en_ligne',
257
+                ),
258
+                'join' => array(
259
+                    'id_auteur' => 'id_auteur',
260
+                    'login' => 'login'
261
+                ),
262
+                'rechercher_champs' => array(
263
+                    'nom' => 5,
264
+                    'bio' => 1,
265
+                    'email' => 1,
266
+                    'nom_site' => 1,
267
+                    'url_site' => 1,
268
+                    'login' => 1
269
+                ),
270
+                // 2 conditions pour les auteurs : statut!=poubelle,
271
+                // et avoir des articles publies
272
+                'statut' => array(
273
+                    array(
274
+                        'champ' => 'statut',
275
+                        'publie' => '!5poubelle',
276
+                        'previsu' => '!5poubelle',
277
+                        'exception' => 'statut'
278
+                    ),
279
+                    array(
280
+                        'champ' => array(
281
+                            array('spip_auteurs_liens', 'id_auteur'),
282
+                            array(
283
+                                'spip_articles',
284
+                                array('id_objet', 'id_article', 'objet', 'article')
285
+                            ),
286
+                            'statut'
287
+                        ),
288
+                        'publie' => 'publie',
289
+                        'previsu' => '!',
290
+                        'post_date' => 'date',
291
+                        'exception' => array('statut', 'lien', 'tout')
292
+                    ),
293
+                ),
294
+                'statut_images' => array(
295
+                    'auteur-6forum-16.png',
296
+                    '0minirezo' => 'auteur-0minirezo-16.png',
297
+                    '1comite' => 'auteur-1comite-16.png',
298
+                    '6forum' => 'auteur-6forum-16.png',
299
+                    '5poubelle' => 'auteur-5poubelle-16.png',
300
+                    'nouveau' => ''
301
+                ),
302
+                'statut_titres' => array(
303
+                    'titre_image_visiteur',
304
+                    '0minirezo' => 'titre_image_administrateur',
305
+                    '1comite' => 'titre_image_redacteur_02',
306
+                    '6forum' => 'titre_image_visiteur',
307
+                    '5poubelle' => 'titre_image_auteur_supprime',
308
+                ),
309
+                'tables_jointures' => array(#'auteurs_liens' // declaration generique plus bas
310
+                ),
311
+            ),
312
+            'spip_rubriques' => array(
313
+                'page' => 'rubrique',
314
+                'url_voir' => 'rubrique',
315
+                'url_edit' => 'rubrique_edit',
316
+                'texte_retour' => 'icone_retour',
317
+                'texte_objets' => 'public:rubriques',
318
+                'texte_objet' => 'public:rubrique',
319
+                'texte_modifier' => 'icone_modifier_rubrique',
320
+                'texte_creer' => 'icone_creer_rubrique',
321
+                'texte_ajouter' => 'titre_ajouter_une_rubrique',
322
+                'texte_creer_associer' => 'creer_et_associer_une_rubrique',
323
+                'info_aucun_objet' => 'info_aucun_rubrique',
324
+                'info_1_objet' => 'info_1_rubrique',
325
+                'info_nb_objets' => 'info_nb_rubriques',
326
+                'texte_logo_objet' => 'logo_rubrique',
327
+                'texte_langue_objet' => 'titre_langue_rubrique',
328
+                'texte_definir_comme_traduction_objet' => 'texte_definir_comme_traduction_rubrique',
329
+                'titre' => 'titre, lang',
330
+                'date' => 'date',
331
+                'principale' => 'oui',
332
+                'introduction_longueur' => '600',
333
+                'champs_editables' => array('titre', 'texte', 'descriptif', 'extra'),
334
+                'champs_versionnes' => array('titre', 'descriptif', 'texte'),
335
+                'field' => array(
336
+                    'id_rubrique' => 'bigint(21) NOT NULL',
337
+                    'id_parent' => "bigint(21) DEFAULT '0' NOT NULL",
338
+                    'titre' => "text DEFAULT '' NOT NULL",
339
+                    'descriptif' => "text DEFAULT '' NOT NULL",
340
+                    'texte' => "longtext DEFAULT '' NOT NULL",
341
+                    'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL",
342
+                    'maj' => 'TIMESTAMP',
343
+                    'statut' => "varchar(10) DEFAULT '0' NOT NULL",
344
+                    'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
345
+                    'lang' => "VARCHAR(10) DEFAULT '' NOT NULL",
346
+                    'langue_choisie' => "VARCHAR(3) DEFAULT 'non'",
347
+                    'statut_tmp' => "varchar(10) DEFAULT '0' NOT NULL",
348
+                    'date_tmp' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
349
+                    'profondeur' => "smallint(5) DEFAULT '0' NOT NULL"
350
+                ),
351
+                'key' => array(
352
+                    'PRIMARY KEY' => 'id_rubrique',
353
+                    'KEY lang' => 'lang',
354
+                    'KEY id_parent' => 'id_parent',
355
+                ),
356
+                'parent' => [
357
+                    ['type' => 'rubrique', 'champ' => 'id_parent']
358
+                ],
359
+                'rechercher_champs' => array(
360
+                    'titre' => 8,
361
+                    'descriptif' => 5,
362
+                    'texte' => 1
363
+                ),
364
+                'statut' => array(
365
+                    array(
366
+                        'champ' => 'statut',
367
+                        'publie' => 'publie',
368
+                        'previsu' => '!',
369
+                        'exception' => array('statut', 'tout')
370
+                    ),
371
+                ),
372
+                'tables_jointures' => array(#'id_auteur' => 'auteurs_liens' // declaration generique plus bas
373
+                ),
374
+            ),
375
+            // toutes les tables ont le droit a une jointure sur les auteurs
376
+            array('tables_jointures' => array('id_auteur' => 'auteurs_liens'))
377
+        );
378
+
379
+        // avant d'appeller les pipeline qui peuvent generer une reentrance a l'install
380
+        // initialiser la signature
381
+        $md5 = md5(serialize($infos_tables));
382
+
383
+        $GLOBALS['tables_principales'] = pipeline('declarer_tables_principales', $GLOBALS['tables_principales']);
384
+        $GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires', $GLOBALS['tables_auxiliaires']);
385
+        $infos_tables = pipeline('declarer_tables_objets_sql', $infos_tables);
386
+
387
+        // completer les informations manquantes ou implicites
388
+        $all = array();
389
+        foreach (array_keys($infos_tables) as $t) {
390
+            // les cles numeriques servent a declarer
391
+            // les proprietes applicables a tous les objets
392
+            // on les mets de cote
393
+            if (is_numeric($t)) {
394
+                $all = array_merge_recursive($all, $infos_tables[$t]);
395
+                unset($infos_tables[$t]);
396
+            } else {
397
+                $infos_tables[$t] = renseigner_table_objet_sql($t, $infos_tables[$t]);
398
+            }
399
+        }
400
+
401
+        // repercuter les proprietes generales communes a tous les objets
402
+        foreach (array_keys($infos_tables) as $t) {
403
+            foreach ($all as $i => $v) {
404
+                if (in_array($i, array('tables_jointures', 'champs_versionnes'))) {
405
+                    $add = $all[$i];
406
+                    // eviter les doublons de declaration de table jointure (ex des mots sur auteurs)
407
+                    // pour les declarations generiques avec cles numeriques
408
+                    if ($i == 'tables_jointures' and isset($infos_tables[$t][$i]) and count($infos_tables[$t][$i])) {
409
+                        $doublons = array_intersect($infos_tables[$t][$i], $add);
410
+                        foreach ($doublons as $d) {
411
+                            if (is_numeric(array_search($d, $infos_tables[$t][$i]))
412
+                                and is_numeric($k = array_search($d, $add))
413
+                            ) {
414
+                                unset($add[$k]);
415
+                            }
416
+                        }
417
+                    }
418
+                    $infos_tables[$t][$i] = array_merge(isset($infos_tables[$t][$i]) ? $infos_tables[$t][$i] : array(), $add);
419
+                } else {
420
+                    $infos_tables[$t][$i] = array_merge_recursive(
421
+                        isset($infos_tables[$t][$i]) ? $infos_tables[$t][$i] : array(),
422
+                        $all[$i]
423
+                    );
424
+                }
425
+            }
426
+        }
427
+
428
+        // completer les tables principales et auxiliaires
429
+        // avec celles declarees uniquement dans declarer_table_objets_sql
430
+        // pour assurer la compat en transition
431
+        foreach ($infos_tables as $table => $infos) {
432
+            $principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires');
433
+            // memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx
434
+            // qui a ete appelle avant
435
+            $mem = (isset($GLOBALS[$principale_ou_auxiliaire][$table]) ? $GLOBALS[$principale_ou_auxiliaire][$table] : array());
436
+            // l'ajouter au tableau
437
+            $GLOBALS[$principale_ou_auxiliaire][$table] = array();
438
+            if (isset($infos['field']) and isset($infos['key'])) {
439
+                foreach (array('field', 'key', 'join') as $k) {
440
+                    if (isset($infos_tables[$table][$k])) {
441
+                        $GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k];
442
+                    }
443
+                }
444
+            } else {
445
+                // ici on ne renvoie que les declarations, donc RIEN
446
+                // pour avoir la vrai description en base, il faut passer par trouver_table
447
+                $GLOBALS[$principale_ou_auxiliaire][$table] = array();
448
+            }
449
+            if (count($mem)) {
450
+                foreach (array_keys($mem) as $k) {
451
+                    if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) {
452
+                        $GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge(
453
+                            $GLOBALS[$principale_ou_auxiliaire][$table][$k],
454
+                            $mem[$k]
455
+                        );
456
+                    } else {
457
+                        $GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k];
458
+                    }
459
+                }
460
+            }
461
+        }
462
+
463
+        // recuperer les interfaces (table_titre, table_date)
464
+        // on ne le fait que dans un second temps pour que table_objet soit fonctionnel
465
+        // dans le pipeline de declarer_tables_interfaces
466
+        include_spip('public/interfaces');
467
+        foreach (array_keys($infos_tables) as $t) {
468
+            $infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]);
469
+        }
470
+
471
+        $deja_la = false;
472
+        // signature
473
+        $md5 = md5(serialize($infos_tables));
474
+    }
475
+    if ($table_sql === '::md5') {
476
+        return $md5;
477
+    }
478
+    if ($table_sql and !isset($infos_tables[$table_sql])) {
479
+        #$desc = renseigner_table_objet_sql($table_sql,$desc);
480
+        $desc = renseigner_table_objet_interfaces($table_sql, $desc);
481
+
482
+        return $desc;
483
+    }
484
+    if ($table_sql) {
485
+        return isset($infos_tables[$table_sql]) ? $infos_tables[$table_sql] : array();
486
+    }
487
+
488
+    return $infos_tables;
489 489
 }
490 490
 
491 491
 
@@ -500,27 +500,27 @@  discard block
 block discarded – undo
500 500
  **/
501 501
 function base_serial(&$tables_principales) {
502 502
 
503
-	$spip_jobs = array(
504
-		'id_job' => 'bigint(21) NOT NULL',
505
-		'descriptif' => "text DEFAULT '' NOT NULL",
506
-		'fonction' => 'varchar(255) NOT NULL', //nom de la fonction
507
-		'args' => "longblob DEFAULT '' NOT NULL", // arguments
508
-		'md5args' => "char(32) NOT NULL default ''", // signature des arguments
509
-		'inclure' => 'varchar(255) NOT NULL', // fichier a inclure ou path/ pour charger_fonction
510
-		'priorite' => 'smallint(6) NOT NULL default 0',
511
-		'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", // date au plus tot
512
-		'status' => 'tinyint NOT NULL default 1',
513
-	);
514
-
515
-	$spip_jobs_key = array(
516
-		'PRIMARY KEY' => 'id_job',
517
-		'KEY date' => 'date',
518
-		'KEY status' => 'status',
519
-	);
520
-
521
-	/// Attention: mes_fonctions peut avoir deja defini cette variable
522
-	/// il faut donc rajouter, mais pas reinitialiser
523
-	$tables_principales['spip_jobs'] = array('field' => &$spip_jobs, 'key' => &$spip_jobs_key);
503
+    $spip_jobs = array(
504
+        'id_job' => 'bigint(21) NOT NULL',
505
+        'descriptif' => "text DEFAULT '' NOT NULL",
506
+        'fonction' => 'varchar(255) NOT NULL', //nom de la fonction
507
+        'args' => "longblob DEFAULT '' NOT NULL", // arguments
508
+        'md5args' => "char(32) NOT NULL default ''", // signature des arguments
509
+        'inclure' => 'varchar(255) NOT NULL', // fichier a inclure ou path/ pour charger_fonction
510
+        'priorite' => 'smallint(6) NOT NULL default 0',
511
+        'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", // date au plus tot
512
+        'status' => 'tinyint NOT NULL default 1',
513
+    );
514
+
515
+    $spip_jobs_key = array(
516
+        'PRIMARY KEY' => 'id_job',
517
+        'KEY date' => 'date',
518
+        'KEY status' => 'status',
519
+    );
520
+
521
+    /// Attention: mes_fonctions peut avoir deja defini cette variable
522
+    /// il faut donc rajouter, mais pas reinitialiser
523
+    $tables_principales['spip_jobs'] = array('field' => &$spip_jobs, 'key' => &$spip_jobs_key);
524 524
 }
525 525
 
526 526
 
@@ -532,71 +532,71 @@  discard block
 block discarded – undo
532 532
  * @return void
533 533
  **/
534 534
 function base_auxiliaires(&$tables_auxiliaires) {
535
-	$spip_resultats = array(
536
-		'recherche' => "char(16) DEFAULT '' NOT NULL",
537
-		'id' => 'INT UNSIGNED NOT NULL',
538
-		'points' => "INT UNSIGNED DEFAULT '0' NOT NULL",
539
-		'table_objet' => "varchar(30) DEFAULT '' NOT NULL",
540
-		'serveur' => "char(16) DEFAULT '' NOT NULL", // hash md5 partiel du serveur de base ('' pour le serveur principal)
541
-		'maj' => 'TIMESTAMP'
542
-	);
543
-
544
-	$spip_resultats_key = array(// pas de cle ni index, ca fait des insertions plus rapides et les requetes jointes utilisees en recheche ne sont pas plus lentes ...
545
-	);
546
-
547
-	$spip_auteurs_liens = array(
548
-		'id_auteur' => "bigint(21) DEFAULT '0' NOT NULL",
549
-		'id_objet' => "bigint(21) DEFAULT '0' NOT NULL",
550
-		'objet' => "VARCHAR (25) DEFAULT '' NOT NULL",
551
-		'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL"
552
-	);
553
-
554
-	$spip_auteurs_liens_key = array(
555
-		'PRIMARY KEY' => 'id_auteur,id_objet,objet',
556
-		'KEY id_auteur' => 'id_auteur',
557
-		'KEY id_objet' => 'id_objet',
558
-		'KEY objet' => 'objet',
559
-	);
560
-
561
-	$spip_meta = array(
562
-		'nom' => 'VARCHAR (255) NOT NULL',
563
-		'valeur' => "text DEFAULT ''",
564
-		'impt' => "ENUM('non', 'oui') DEFAULT 'oui' NOT NULL",
565
-		'maj' => 'TIMESTAMP'
566
-	);
567
-
568
-	$spip_meta_key = array(
569
-		'PRIMARY KEY' => 'nom'
570
-	);
571
-
572
-	$spip_jobs_liens = array(
573
-		'id_job' => "bigint(21) DEFAULT '0' NOT NULL",
574
-		'id_objet' => "bigint(21) DEFAULT '0' NOT NULL",
575
-		'objet' => "VARCHAR (25) DEFAULT '' NOT NULL",
576
-	);
577
-
578
-	$spip_jobs_liens_key = array(
579
-		'PRIMARY KEY' => 'id_job,id_objet,objet',
580
-		'KEY id_job' => 'id_job'
581
-	);
582
-
583
-	$tables_auxiliaires['spip_auteurs_liens'] = array(
584
-		'field' => &$spip_auteurs_liens,
585
-		'key' => &$spip_auteurs_liens_key
586
-	);
587
-
588
-	$tables_auxiliaires['spip_meta'] = array(
589
-		'field' => &$spip_meta,
590
-		'key' => &$spip_meta_key
591
-	);
592
-	$tables_auxiliaires['spip_resultats'] = array(
593
-		'field' => &$spip_resultats,
594
-		'key' => &$spip_resultats_key
595
-	);
596
-	$tables_auxiliaires['spip_jobs_liens'] = array(
597
-		'field' => &$spip_jobs_liens,
598
-		'key' => &$spip_jobs_liens_key
599
-	);
535
+    $spip_resultats = array(
536
+        'recherche' => "char(16) DEFAULT '' NOT NULL",
537
+        'id' => 'INT UNSIGNED NOT NULL',
538
+        'points' => "INT UNSIGNED DEFAULT '0' NOT NULL",
539
+        'table_objet' => "varchar(30) DEFAULT '' NOT NULL",
540
+        'serveur' => "char(16) DEFAULT '' NOT NULL", // hash md5 partiel du serveur de base ('' pour le serveur principal)
541
+        'maj' => 'TIMESTAMP'
542
+    );
543
+
544
+    $spip_resultats_key = array(// pas de cle ni index, ca fait des insertions plus rapides et les requetes jointes utilisees en recheche ne sont pas plus lentes ...
545
+    );
546
+
547
+    $spip_auteurs_liens = array(
548
+        'id_auteur' => "bigint(21) DEFAULT '0' NOT NULL",
549
+        'id_objet' => "bigint(21) DEFAULT '0' NOT NULL",
550
+        'objet' => "VARCHAR (25) DEFAULT '' NOT NULL",
551
+        'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL"
552
+    );
553
+
554
+    $spip_auteurs_liens_key = array(
555
+        'PRIMARY KEY' => 'id_auteur,id_objet,objet',
556
+        'KEY id_auteur' => 'id_auteur',
557
+        'KEY id_objet' => 'id_objet',
558
+        'KEY objet' => 'objet',
559
+    );
560
+
561
+    $spip_meta = array(
562
+        'nom' => 'VARCHAR (255) NOT NULL',
563
+        'valeur' => "text DEFAULT ''",
564
+        'impt' => "ENUM('non', 'oui') DEFAULT 'oui' NOT NULL",
565
+        'maj' => 'TIMESTAMP'
566
+    );
567
+
568
+    $spip_meta_key = array(
569
+        'PRIMARY KEY' => 'nom'
570
+    );
571
+
572
+    $spip_jobs_liens = array(
573
+        'id_job' => "bigint(21) DEFAULT '0' NOT NULL",
574
+        'id_objet' => "bigint(21) DEFAULT '0' NOT NULL",
575
+        'objet' => "VARCHAR (25) DEFAULT '' NOT NULL",
576
+    );
577
+
578
+    $spip_jobs_liens_key = array(
579
+        'PRIMARY KEY' => 'id_job,id_objet,objet',
580
+        'KEY id_job' => 'id_job'
581
+    );
582
+
583
+    $tables_auxiliaires['spip_auteurs_liens'] = array(
584
+        'field' => &$spip_auteurs_liens,
585
+        'key' => &$spip_auteurs_liens_key
586
+    );
587
+
588
+    $tables_auxiliaires['spip_meta'] = array(
589
+        'field' => &$spip_meta,
590
+        'key' => &$spip_meta_key
591
+    );
592
+    $tables_auxiliaires['spip_resultats'] = array(
593
+        'field' => &$spip_resultats,
594
+        'key' => &$spip_resultats_key
595
+    );
596
+    $tables_auxiliaires['spip_jobs_liens'] = array(
597
+        'field' => &$spip_jobs_liens,
598
+        'key' => &$spip_jobs_liens_key
599
+    );
600 600
 
601 601
 }
602 602
 
@@ -654,129 +654,129 @@  discard block
 block discarded – undo
654 654
  * @return array
655 655
  */
656 656
 function renseigner_table_objet_sql($table_sql, &$infos) {
657
-	if (!isset($infos['type'])) {
658
-		// si on arrive de base/trouver_table, on a la cle primaire :
659
-		// s'en servir pour extrapoler le type
660
-		if (isset($infos['key']['PRIMARY KEY'])) {
661
-			$primary = $infos['key']['PRIMARY KEY'];
662
-			$primary = explode(',', $primary);
663
-			$primary = reset($primary);
664
-			$infos['type'] = preg_replace(',^spip_|^id_|s$,', '', $primary);
665
-		} else {
666
-			$infos['type'] = preg_replace(',^spip_|s$,', '', $table_sql);
667
-		}
668
-	}
669
-	if (!isset($infos['type_surnoms'])) {
670
-		$infos['type_surnoms'] = array();
671
-	}
672
-
673
-	if (!isset($infos['table_objet'])) {
674
-		$infos['table_objet'] = preg_replace(',^spip_,', '', $table_sql);
675
-	}
676
-	if (!isset($infos['table_objet_surnoms'])) {
677
-		$infos['table_objet_surnoms'] = array();
678
-	}
679
-
680
-	if (!isset($infos['principale'])) {
681
-		$infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql]) ? 'oui' : false);
682
-	}
683
-
684
-	// normaliser pour pouvoir tester en php $infos['principale']?
685
-	// et dans une boucle {principale=oui}
686
-	$infos['principale'] = (($infos['principale'] and $infos['principale'] != 'non') ? 'oui' : false);
687
-
688
-	// declarer et normaliser pour pouvoir tester en php $infos['editable']?
689
-	// et dans une boucle {editable=oui}
690
-	if (!isset($infos['editable'])) {
691
-		$infos['editable'] = 'oui';
692
-	}
693
-
694
-	$infos['editable'] = (($infos['editable'] and $infos['editable'] != 'non') ? 'oui' : false);
695
-
696
-	// les urls publiques sont par defaut page=type pour les tables principales, et rien pour les autres
697
-	// seules les exceptions sont donc a declarer
698
-	if (!isset($infos['page'])) {
699
-		$infos['page'] = ($infos['principale'] ? $infos['type'] : '');
700
-	}
701
-
702
-	if (!isset($infos['url_voir'])) {
703
-		$infos['url_voir'] = $infos['type'];
704
-	}
705
-	if (!isset($infos['url_edit'])) {
706
-		$infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : '');
707
-	}
708
-	if (!isset($infos['icone_objet'])) {
709
-		$infos['icone_objet'] = $infos['type'];
710
-	}
711
-
712
-	// chaines de langue
713
-	// par defaut : objet:icone_xxx_objet
714
-	if (!isset($infos['texte_retour'])) {
715
-		$infos['texte_retour'] = 'icone_retour';
716
-	}
717
-	if (!isset($infos['texte_modifier'])) {
718
-		$infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type'];
719
-	}
720
-	if (!isset($infos['texte_creer'])) {
721
-		$infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type'];
722
-	}
723
-	if (!isset($infos['texte_creer_associer'])) {
724
-		$infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type'];
725
-	}
726
-	if (!isset($infos['texte_ajouter'])) {
727
-		// Ajouter un X
728
-		$infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type'];
729
-	}
730
-	if (!isset($infos['texte_objets'])) {
731
-		$infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet'];
732
-	}
733
-	if (!isset($infos['texte_objet'])) {
734
-		$infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type'];
735
-	}
736
-	if (!isset($infos['texte_logo_objet'])) {
737
-		// objet:titre_logo_objet "Logo de ce X"
738
-		$infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type'];
739
-	}
740
-	if (!isset($infos['texte_langue_objet'])) {
741
-		// objet:texte_langue_objet "Langue de ce X"
742
-		$infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type'];
743
-	}
744
-	if (!isset($infos['texte_definir_comme_traduction_objet'])) {
745
-		// "Ce X est une traduction du X numéro :"
746
-		$infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type'];
747
-	}
748
-
749
-	// objet:info_aucun_objet
750
-	if (!isset($infos['info_aucun_objet'])) {
751
-		$infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type'];
752
-	}
753
-	// objet:info_1_objet
754
-	if (!isset($infos['info_1_objet'])) {
755
-		$infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type'];
756
-	}
757
-	// objet:info_nb_objets
758
-	if (!isset($infos['info_nb_objets'])) {
759
-		$infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet'];
760
-	}
761
-
762
-	if (!isset($infos['champs_editables'])) {
763
-		$infos['champs_editables'] = array();
764
-	}
765
-	if (!isset($infos['champs_versionnes'])) {
766
-		$infos['champs_versionnes'] = array();
767
-	}
768
-	if (!isset($infos['rechercher_champs'])) {
769
-		$infos['rechercher_champs'] = array();
770
-	}
771
-	if (!isset($infos['rechercher_jointures'])) {
772
-		$infos['rechercher_jointures'] = array();
773
-	}
774
-
775
-	if (!isset($infos['modeles'])) {
776
-		$infos['modeles'] = array($infos['type']);
777
-	}
778
-
779
-	return $infos;
657
+    if (!isset($infos['type'])) {
658
+        // si on arrive de base/trouver_table, on a la cle primaire :
659
+        // s'en servir pour extrapoler le type
660
+        if (isset($infos['key']['PRIMARY KEY'])) {
661
+            $primary = $infos['key']['PRIMARY KEY'];
662
+            $primary = explode(',', $primary);
663
+            $primary = reset($primary);
664
+            $infos['type'] = preg_replace(',^spip_|^id_|s$,', '', $primary);
665
+        } else {
666
+            $infos['type'] = preg_replace(',^spip_|s$,', '', $table_sql);
667
+        }
668
+    }
669
+    if (!isset($infos['type_surnoms'])) {
670
+        $infos['type_surnoms'] = array();
671
+    }
672
+
673
+    if (!isset($infos['table_objet'])) {
674
+        $infos['table_objet'] = preg_replace(',^spip_,', '', $table_sql);
675
+    }
676
+    if (!isset($infos['table_objet_surnoms'])) {
677
+        $infos['table_objet_surnoms'] = array();
678
+    }
679
+
680
+    if (!isset($infos['principale'])) {
681
+        $infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql]) ? 'oui' : false);
682
+    }
683
+
684
+    // normaliser pour pouvoir tester en php $infos['principale']?
685
+    // et dans une boucle {principale=oui}
686
+    $infos['principale'] = (($infos['principale'] and $infos['principale'] != 'non') ? 'oui' : false);
687
+
688
+    // declarer et normaliser pour pouvoir tester en php $infos['editable']?
689
+    // et dans une boucle {editable=oui}
690
+    if (!isset($infos['editable'])) {
691
+        $infos['editable'] = 'oui';
692
+    }
693
+
694
+    $infos['editable'] = (($infos['editable'] and $infos['editable'] != 'non') ? 'oui' : false);
695
+
696
+    // les urls publiques sont par defaut page=type pour les tables principales, et rien pour les autres
697
+    // seules les exceptions sont donc a declarer
698
+    if (!isset($infos['page'])) {
699
+        $infos['page'] = ($infos['principale'] ? $infos['type'] : '');
700
+    }
701
+
702
+    if (!isset($infos['url_voir'])) {
703
+        $infos['url_voir'] = $infos['type'];
704
+    }
705
+    if (!isset($infos['url_edit'])) {
706
+        $infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : '');
707
+    }
708
+    if (!isset($infos['icone_objet'])) {
709
+        $infos['icone_objet'] = $infos['type'];
710
+    }
711
+
712
+    // chaines de langue
713
+    // par defaut : objet:icone_xxx_objet
714
+    if (!isset($infos['texte_retour'])) {
715
+        $infos['texte_retour'] = 'icone_retour';
716
+    }
717
+    if (!isset($infos['texte_modifier'])) {
718
+        $infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type'];
719
+    }
720
+    if (!isset($infos['texte_creer'])) {
721
+        $infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type'];
722
+    }
723
+    if (!isset($infos['texte_creer_associer'])) {
724
+        $infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type'];
725
+    }
726
+    if (!isset($infos['texte_ajouter'])) {
727
+        // Ajouter un X
728
+        $infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type'];
729
+    }
730
+    if (!isset($infos['texte_objets'])) {
731
+        $infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet'];
732
+    }
733
+    if (!isset($infos['texte_objet'])) {
734
+        $infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type'];
735
+    }
736
+    if (!isset($infos['texte_logo_objet'])) {
737
+        // objet:titre_logo_objet "Logo de ce X"
738
+        $infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type'];
739
+    }
740
+    if (!isset($infos['texte_langue_objet'])) {
741
+        // objet:texte_langue_objet "Langue de ce X"
742
+        $infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type'];
743
+    }
744
+    if (!isset($infos['texte_definir_comme_traduction_objet'])) {
745
+        // "Ce X est une traduction du X numéro :"
746
+        $infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type'];
747
+    }
748
+
749
+    // objet:info_aucun_objet
750
+    if (!isset($infos['info_aucun_objet'])) {
751
+        $infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type'];
752
+    }
753
+    // objet:info_1_objet
754
+    if (!isset($infos['info_1_objet'])) {
755
+        $infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type'];
756
+    }
757
+    // objet:info_nb_objets
758
+    if (!isset($infos['info_nb_objets'])) {
759
+        $infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet'];
760
+    }
761
+
762
+    if (!isset($infos['champs_editables'])) {
763
+        $infos['champs_editables'] = array();
764
+    }
765
+    if (!isset($infos['champs_versionnes'])) {
766
+        $infos['champs_versionnes'] = array();
767
+    }
768
+    if (!isset($infos['rechercher_champs'])) {
769
+        $infos['rechercher_champs'] = array();
770
+    }
771
+    if (!isset($infos['rechercher_jointures'])) {
772
+        $infos['rechercher_jointures'] = array();
773
+    }
774
+
775
+    if (!isset($infos['modeles'])) {
776
+        $infos['modeles'] = array($infos['type']);
777
+    }
778
+
779
+    return $infos;
780 780
 }
781 781
 
782 782
 /**
@@ -793,32 +793,32 @@  discard block
 block discarded – undo
793 793
  * @return array
794 794
  */
795 795
 function renseigner_table_objet_interfaces($table_sql, &$infos) {
796
-	if (!isset($infos['titre'])) {
797
-		if (isset($infos['table_objet']) and isset($GLOBALS['table_titre'][$infos['table_objet']])) {
798
-			$infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']];
799
-		} else {
800
-			$infos['titre'] = ((isset($infos['field']['titre'])) ? 'titre,' : "'' as titre,");
801
-			$infos['titre'] .= ((isset($infos['field']['lang'])) ? 'lang' : "'' as lang");
802
-		}
803
-	}
804
-	if (!isset($infos['date'])) {
805
-		if (isset($infos['table_objet']) and isset($GLOBALS['table_date'][$infos['table_objet']])) {
806
-			$infos['date'] = $GLOBALS['table_date'][$infos['table_objet']];
807
-		} else {
808
-			$infos['date'] = ((isset($infos['field']['date'])) ? 'date' : '');
809
-		}
810
-	}
811
-	if (!isset($infos['statut'])) {
812
-		$infos['statut'] = isset($GLOBALS['table_statut'][$table_sql]) ? $GLOBALS['table_statut'][$table_sql] : '';
813
-	}
814
-	if (!isset($infos['tables_jointures'])) {
815
-		$infos['tables_jointures'] = array();
816
-	}
817
-	if (isset($GLOBALS['tables_jointures'][$table_sql])) {
818
-		$infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]);
819
-	}
820
-
821
-	return $infos;
796
+    if (!isset($infos['titre'])) {
797
+        if (isset($infos['table_objet']) and isset($GLOBALS['table_titre'][$infos['table_objet']])) {
798
+            $infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']];
799
+        } else {
800
+            $infos['titre'] = ((isset($infos['field']['titre'])) ? 'titre,' : "'' as titre,");
801
+            $infos['titre'] .= ((isset($infos['field']['lang'])) ? 'lang' : "'' as lang");
802
+        }
803
+    }
804
+    if (!isset($infos['date'])) {
805
+        if (isset($infos['table_objet']) and isset($GLOBALS['table_date'][$infos['table_objet']])) {
806
+            $infos['date'] = $GLOBALS['table_date'][$infos['table_objet']];
807
+        } else {
808
+            $infos['date'] = ((isset($infos['field']['date'])) ? 'date' : '');
809
+        }
810
+    }
811
+    if (!isset($infos['statut'])) {
812
+        $infos['statut'] = isset($GLOBALS['table_statut'][$table_sql]) ? $GLOBALS['table_statut'][$table_sql] : '';
813
+    }
814
+    if (!isset($infos['tables_jointures'])) {
815
+        $infos['tables_jointures'] = array();
816
+    }
817
+    if (isset($GLOBALS['tables_jointures'][$table_sql])) {
818
+        $infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]);
819
+    }
820
+
821
+    return $infos;
822 822
 }
823 823
 
824 824
 /**
@@ -829,13 +829,13 @@  discard block
 block discarded – undo
829 829
  *     Liste et descriptions des tables principales
830 830
  **/
831 831
 function lister_tables_principales() {
832
-	static $done = false;
833
-	if (!$done or !count($GLOBALS['tables_principales'])) {
834
-		lister_tables_objets_sql();
835
-		$done = true;
836
-	}
832
+    static $done = false;
833
+    if (!$done or !count($GLOBALS['tables_principales'])) {
834
+        lister_tables_objets_sql();
835
+        $done = true;
836
+    }
837 837
 
838
-	return $GLOBALS['tables_principales'];
838
+    return $GLOBALS['tables_principales'];
839 839
 }
840 840
 
841 841
 /**
@@ -846,13 +846,13 @@  discard block
 block discarded – undo
846 846
  *     Liste et descriptions des tables auxiliaires
847 847
  **/
848 848
 function lister_tables_auxiliaires() {
849
-	static $done = false;
850
-	if (!$done or !count($GLOBALS['tables_auxiliaires'])) {
851
-		lister_tables_objets_sql();
852
-		$done = true;
853
-	}
849
+    static $done = false;
850
+    if (!$done or !count($GLOBALS['tables_auxiliaires'])) {
851
+        lister_tables_objets_sql();
852
+        $done = true;
853
+    }
854 854
 
855
-	return $GLOBALS['tables_auxiliaires'];
855
+    return $GLOBALS['tables_auxiliaires'];
856 856
 }
857 857
 
858 858
 /**
@@ -861,44 +861,44 @@  discard block
 block discarded – undo
861 861
  * @return array
862 862
  */
863 863
 function lister_tables_objets_surnoms() {
864
-	static $surnoms = null;
865
-	static $md5 = null;
866
-	if (!$surnoms
867
-		or $md5 != lister_tables_objets_sql('::md5')
868
-	) {
869
-		// passer dans un pipeline qui permet aux plugins de declarer leurs exceptions
870
-		// pour compatibilite, car il faut dorenavent utiliser
871
-		// declarer_table_objets_sql
872
-		$surnoms = pipeline(
873
-			'declarer_tables_objets_surnoms',
874
-			array(
875
-				# pour les modeles
876
-				# a enlever ?
877
-				'doc' => 'documents',
878
-				'img' => 'documents',
879
-				'emb' => 'documents',
880
-			)
881
-		);
882
-		$infos_tables = lister_tables_objets_sql();
883
-		foreach ($infos_tables as $t => $infos) {
884
-			// cas de base type=>table
885
-			// et preg_replace(',^spip_|^id_|s$,',table)=>table
886
-			if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide
887
-				// optimisations pour table_objet
888
-				//$surnoms[$infos['type']] = $infos['table_objet'];
889
-				$surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['table_objet'];
890
-				$surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['table_objet'];
891
-				if (is_array($infos['table_objet_surnoms']) and count($infos['table_objet_surnoms'])) {
892
-					foreach ($infos['table_objet_surnoms'] as $surnom) {
893
-						$surnoms[$surnom] = $infos['table_objet'];
894
-					}
895
-				}
896
-			}
897
-		}
898
-		$md5 = lister_tables_objets_sql('::md5');
899
-	}
900
-
901
-	return $surnoms;
864
+    static $surnoms = null;
865
+    static $md5 = null;
866
+    if (!$surnoms
867
+        or $md5 != lister_tables_objets_sql('::md5')
868
+    ) {
869
+        // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions
870
+        // pour compatibilite, car il faut dorenavent utiliser
871
+        // declarer_table_objets_sql
872
+        $surnoms = pipeline(
873
+            'declarer_tables_objets_surnoms',
874
+            array(
875
+                # pour les modeles
876
+                # a enlever ?
877
+                'doc' => 'documents',
878
+                'img' => 'documents',
879
+                'emb' => 'documents',
880
+            )
881
+        );
882
+        $infos_tables = lister_tables_objets_sql();
883
+        foreach ($infos_tables as $t => $infos) {
884
+            // cas de base type=>table
885
+            // et preg_replace(',^spip_|^id_|s$,',table)=>table
886
+            if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide
887
+                // optimisations pour table_objet
888
+                //$surnoms[$infos['type']] = $infos['table_objet'];
889
+                $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['table_objet'];
890
+                $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['table_objet'];
891
+                if (is_array($infos['table_objet_surnoms']) and count($infos['table_objet_surnoms'])) {
892
+                    foreach ($infos['table_objet_surnoms'] as $surnom) {
893
+                        $surnoms[$surnom] = $infos['table_objet'];
894
+                    }
895
+                }
896
+            }
897
+        }
898
+        $md5 = lister_tables_objets_sql('::md5');
899
+    }
900
+
901
+    return $surnoms;
902 902
 }
903 903
 
904 904
 /**
@@ -907,34 +907,34 @@  discard block
 block discarded – undo
907 907
  * @return array
908 908
  */
909 909
 function lister_types_surnoms() {
910
-	static $surnoms = null;
911
-	static $md5 = null;
912
-	if (!$surnoms
913
-		or $md5 != lister_tables_objets_sql('::md5')
914
-	) {
915
-		// passer dans un pipeline qui permet aux plugins de declarer leurs exceptions
916
-		// pour compatibilite, car il faut dorenavent utiliser
917
-		// declarer_table_objets_sql
918
-		$surnoms = pipeline('declarer_type_surnoms', array('racine-site' => 'site'));
919
-		$infos_tables = lister_tables_objets_sql();
920
-		foreach ($infos_tables as $t => $infos) {
921
-			if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide
922
-				// optimisations pour objet_type
923
-				//$surnoms[$infos['type']] = $infos['type'];
924
-				$surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['type'];
925
-				$surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['type'];
926
-				// surnoms declares
927
-				if (is_array($infos['type_surnoms']) and count($infos['type_surnoms'])) {
928
-					foreach ($infos['type_surnoms'] as $surnom) {
929
-						$surnoms[$surnom] = $infos['type'];
930
-					}
931
-				}
932
-			}
933
-		}
934
-		$md5 = lister_tables_objets_sql('::md5');
935
-	}
936
-
937
-	return $surnoms;
910
+    static $surnoms = null;
911
+    static $md5 = null;
912
+    if (!$surnoms
913
+        or $md5 != lister_tables_objets_sql('::md5')
914
+    ) {
915
+        // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions
916
+        // pour compatibilite, car il faut dorenavent utiliser
917
+        // declarer_table_objets_sql
918
+        $surnoms = pipeline('declarer_type_surnoms', array('racine-site' => 'site'));
919
+        $infos_tables = lister_tables_objets_sql();
920
+        foreach ($infos_tables as $t => $infos) {
921
+            if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide
922
+                // optimisations pour objet_type
923
+                //$surnoms[$infos['type']] = $infos['type'];
924
+                $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['type'];
925
+                $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['type'];
926
+                // surnoms declares
927
+                if (is_array($infos['type_surnoms']) and count($infos['type_surnoms'])) {
928
+                    foreach ($infos['type_surnoms'] as $surnom) {
929
+                        $surnoms[$surnom] = $infos['type'];
930
+                    }
931
+                }
932
+            }
933
+        }
934
+        $md5 = lister_tables_objets_sql('::md5');
935
+    }
936
+
937
+    return $surnoms;
938 938
 }
939 939
 
940 940
 /**
@@ -948,22 +948,22 @@  discard block
 block discarded – undo
948 948
  *     Couples (nom de la table SQL => même nom, sans 'spip_' devant)
949 949
  **/
950 950
 function lister_tables_spip($serveur = '') {
951
-	static $tables = array();
952
-	if (!isset($tables[$serveur])) {
953
-		$tables[$serveur] = array();
954
-		if (!function_exists('sql_alltable')) {
955
-			include_spip('base/abstract_sql');
956
-		}
957
-		$ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso)
958
-		$connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0];
959
-		$spip = $connexion['prefixe'] . '_';
960
-		foreach ($ts as $t) {
961
-			$t = substr($t, strlen($spip));
962
-			$tables[$serveur]["spip_$t"] = $t;
963
-		}
964
-	}
965
-
966
-	return $tables[$serveur];
951
+    static $tables = array();
952
+    if (!isset($tables[$serveur])) {
953
+        $tables[$serveur] = array();
954
+        if (!function_exists('sql_alltable')) {
955
+            include_spip('base/abstract_sql');
956
+        }
957
+        $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso)
958
+        $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0];
959
+        $spip = $connexion['prefixe'] . '_';
960
+        foreach ($ts as $t) {
961
+            $t = substr($t, strlen($spip));
962
+            $tables[$serveur]["spip_$t"] = $t;
963
+        }
964
+    }
965
+
966
+    return $tables[$serveur];
967 967
 }
968 968
 
969 969
 
@@ -978,17 +978,17 @@  discard block
 block discarded – undo
978 978
  *     Couples (nom de la table SQL => même nom)
979 979
  **/
980 980
 function lister_toutes_tables($serveur){
981
-	static $tables = array();
982
-	if (!isset($tables[$serveur])){
983
-		$tables[$serveur] = array();
984
-		if (!function_exists("sql_alltable"))
985
-			include_spip("base/abstract_sql");
986
-		$ts = sql_alltable('%',$serveur); // toutes les tables
987
-		foreach ($ts as $t){
988
-			$tables[$serveur][$t] = $t;
989
-		}
990
-	}
991
-	return $tables[$serveur];
981
+    static $tables = array();
982
+    if (!isset($tables[$serveur])){
983
+        $tables[$serveur] = array();
984
+        if (!function_exists("sql_alltable"))
985
+            include_spip("base/abstract_sql");
986
+        $ts = sql_alltable('%',$serveur); // toutes les tables
987
+        foreach ($ts as $t){
988
+            $tables[$serveur][$t] = $t;
989
+        }
990
+    }
991
+    return $tables[$serveur];
992 992
 }
993 993
 
994 994
 /**
@@ -1008,34 +1008,34 @@  discard block
 block discarded – undo
1008 1008
  *     Nom de l'objet
1009 1009
  **/
1010 1010
 function table_objet($type, $serveur = '') {
1011
-	$surnoms = lister_tables_objets_surnoms();
1012
-	$type = preg_replace(',^spip_|^id_|s$,', '', $type);
1013
-	if (!$type) {
1014
-		return;
1015
-	}
1016
-	if (isset($surnoms[$type])) {
1017
-		return $surnoms[$type];
1018
-	}
1019
-
1020
-	if ($serveur !== false) {
1021
-		$t = lister_tables_spip($serveur);
1022
-		$trouver_table = charger_fonction('trouver_table', 'base');
1023
-		$typetrim = rtrim($type, 's') . 's';
1024
-		if ((isset($t[$typetrim]) or in_array($typetrim, $t))
1025
-			and ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur))
1026
-		) {
1027
-			return $desc['id_table'];
1028
-		} elseif ((isset($t[$type]) or in_array($type, $t))
1029
-			and ($desc = $trouver_table($type, $serveur))
1030
-		) {
1031
-			return $desc['id_table'];
1032
-		}
1033
-
1034
-		spip_log('table_objet(' . $type . ') calculee sans verification');
1035
-		#spip_log(debug_backtrace(),'db');
1036
-	}
1037
-
1038
-	return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false
1011
+    $surnoms = lister_tables_objets_surnoms();
1012
+    $type = preg_replace(',^spip_|^id_|s$,', '', $type);
1013
+    if (!$type) {
1014
+        return;
1015
+    }
1016
+    if (isset($surnoms[$type])) {
1017
+        return $surnoms[$type];
1018
+    }
1019
+
1020
+    if ($serveur !== false) {
1021
+        $t = lister_tables_spip($serveur);
1022
+        $trouver_table = charger_fonction('trouver_table', 'base');
1023
+        $typetrim = rtrim($type, 's') . 's';
1024
+        if ((isset($t[$typetrim]) or in_array($typetrim, $t))
1025
+            and ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur))
1026
+        ) {
1027
+            return $desc['id_table'];
1028
+        } elseif ((isset($t[$type]) or in_array($type, $t))
1029
+            and ($desc = $trouver_table($type, $serveur))
1030
+        ) {
1031
+            return $desc['id_table'];
1032
+        }
1033
+
1034
+        spip_log('table_objet(' . $type . ') calculee sans verification');
1035
+        #spip_log(debug_backtrace(),'db');
1036
+    }
1037
+
1038
+    return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false
1039 1039
 }
1040 1040
 
1041 1041
 /**
@@ -1056,30 +1056,30 @@  discard block
 block discarded – undo
1056 1056
  **/
1057 1057
 function table_objet_sql($type, $serveur = '') {
1058 1058
 
1059
-	$nom = table_objet($type, $serveur);
1060
-	if (!isset($GLOBALS['table_des_tables']['articles'])) {
1061
-		// eviter de multiples inclusions
1062
-		include_spip('public/interfaces');
1063
-	}
1064
-	if (isset($GLOBALS['table_des_tables'][$nom])) {
1065
-		$nom = $GLOBALS['table_des_tables'][$nom];
1066
-		$nom = "spip_$nom";
1067
-	} else {
1068
-		$infos_tables = lister_tables_objets_sql();
1069
-		if (isset($infos_tables["spip_$nom"])) {
1070
-			$nom = "spip_$nom";
1071
-		} elseif ($serveur !== false) {
1072
-			$t = lister_tables_spip($serveur);
1073
-			if (isset($t[$nom]) or in_array($nom, $t)) {
1074
-				$trouver_table = charger_fonction('trouver_table', 'base');
1075
-				if ($desc = $trouver_table($nom, $serveur)) {
1076
-					return $desc['table_sql'];
1077
-				}
1078
-			}
1079
-		}
1080
-	}
1081
-
1082
-	return $nom;
1059
+    $nom = table_objet($type, $serveur);
1060
+    if (!isset($GLOBALS['table_des_tables']['articles'])) {
1061
+        // eviter de multiples inclusions
1062
+        include_spip('public/interfaces');
1063
+    }
1064
+    if (isset($GLOBALS['table_des_tables'][$nom])) {
1065
+        $nom = $GLOBALS['table_des_tables'][$nom];
1066
+        $nom = "spip_$nom";
1067
+    } else {
1068
+        $infos_tables = lister_tables_objets_sql();
1069
+        if (isset($infos_tables["spip_$nom"])) {
1070
+            $nom = "spip_$nom";
1071
+        } elseif ($serveur !== false) {
1072
+            $t = lister_tables_spip($serveur);
1073
+            if (isset($t[$nom]) or in_array($nom, $t)) {
1074
+                $trouver_table = charger_fonction('trouver_table', 'base');
1075
+                if ($desc = $trouver_table($nom, $serveur)) {
1076
+                    return $desc['table_sql'];
1077
+                }
1078
+            }
1079
+        }
1080
+    }
1081
+
1082
+    return $nom;
1083 1083
 }
1084 1084
 
1085 1085
 /**
@@ -1098,35 +1098,35 @@  discard block
 block discarded – undo
1098 1098
  *     Nom de la clé primaire
1099 1099
  **/
1100 1100
 function id_table_objet($type, $serveur = '') {
1101
-	static $trouver_table = null;
1102
-	$type = objet_type($type, $serveur);
1103
-	if (!$type) {
1104
-		return;
1105
-	}
1106
-	$t = table_objet($type);
1107
-	if (!$trouver_table) {
1108
-		$trouver_table = charger_fonction('trouver_table', 'base');
1109
-	}
1110
-
1111
-	$ts = lister_tables_spip($serveur);
1112
-	if (
1113
-		in_array($t, $ts)
1114
-		or in_array($t, lister_toutes_tables($serveur))
1115
-	){
1116
-		$desc = $trouver_table($t, $serveur);
1117
-		if (isset($desc['key']['PRIMARY KEY'])) {
1118
-			return $desc['key']['PRIMARY KEY'];
1119
-		}
1120
-		if (!$desc or isset($desc['field']["id_$type"])) {
1121
-			return "id_$type";
1122
-		}
1123
-		// sinon renvoyer le premier champ de la table...
1124
-		$keys = array_keys($desc['field']);
1125
-
1126
-		return array_shift($keys);
1127
-	}
1128
-
1129
-	return "id_$type";
1101
+    static $trouver_table = null;
1102
+    $type = objet_type($type, $serveur);
1103
+    if (!$type) {
1104
+        return;
1105
+    }
1106
+    $t = table_objet($type);
1107
+    if (!$trouver_table) {
1108
+        $trouver_table = charger_fonction('trouver_table', 'base');
1109
+    }
1110
+
1111
+    $ts = lister_tables_spip($serveur);
1112
+    if (
1113
+        in_array($t, $ts)
1114
+        or in_array($t, lister_toutes_tables($serveur))
1115
+    ){
1116
+        $desc = $trouver_table($t, $serveur);
1117
+        if (isset($desc['key']['PRIMARY KEY'])) {
1118
+            return $desc['key']['PRIMARY KEY'];
1119
+        }
1120
+        if (!$desc or isset($desc['field']["id_$type"])) {
1121
+            return "id_$type";
1122
+        }
1123
+        // sinon renvoyer le premier champ de la table...
1124
+        $keys = array_keys($desc['field']);
1125
+
1126
+        return array_shift($keys);
1127
+    }
1128
+
1129
+    return "id_$type";
1130 1130
 }
1131 1131
 
1132 1132
 /**
@@ -1145,59 +1145,59 @@  discard block
 block discarded – undo
1145 1145
  *     Type de l'objet
1146 1146
  **/
1147 1147
 function objet_type($table_objet, $serveur = '') {
1148
-	if (!$table_objet) {
1149
-		return;
1150
-	}
1151
-	$surnoms = lister_types_surnoms();
1152
-
1153
-	// scenario de base
1154
-	// le type est decline a partir du nom de la table en enlevant le prefixe eventuel
1155
-	// et la marque du pluriel
1156
-	// on accepte id_xx en entree aussi
1157
-	$type = preg_replace(',^spip_|^id_|s$,', '', $table_objet);
1158
-	if (isset($surnoms[$type])) {
1159
-		return $surnoms[$type];
1160
-	}
1161
-
1162
-	// securite : eliminer les caracteres non \w
1163
-	$type = preg_replace(',[^\w-],', '', $type);
1164
-
1165
-	// si le type redonne bien la table c'est bon
1166
-	// oui si table_objet ressemblait deja a un type
1167
-	if ($type == $table_objet
1168
-		or (table_objet($type, $serveur) == $table_objet)
1169
-		or (table_objet_sql($type, $serveur) == $table_objet)
1170
-	) {
1171
-		return $type;
1172
-	}
1173
-
1174
-	// si on ne veut pas chercher en base
1175
-	if ($serveur === false) {
1176
-		return $type;
1177
-	}
1178
-
1179
-	// sinon on passe par la cle primaire id_xx pour trouver le type
1180
-	// car le s a la fin est incertain
1181
-	// notamment en cas de pluriel derogatoire
1182
-	// id_jeu/spip_jeux id_journal/spip_journaux qui necessitent tout deux
1183
-	// une declaration jeu => jeux, journal => journaux
1184
-	// dans le pipeline declarer_tables_objets_surnoms
1185
-	$trouver_table = charger_fonction('trouver_table', 'base');
1186
-	$ts = lister_tables_spip($serveur);
1187
-	$desc = false;
1188
-	if (in_array($table_objet, $ts)) {
1189
-		$desc = $trouver_table($table_objet);
1190
-	}
1191
-	if (!$desc and in_array($table_objet = table_objet($type, $serveur), $ts)) {
1192
-		$desc = $trouver_table($table_objet, $serveur);
1193
-	}
1194
-	// si le type est declare : bingo !
1195
-	if ($desc and isset($desc['type'])) {
1196
-		return $desc['type'];
1197
-	}
1198
-
1199
-	// on a fait ce qu'on a pu
1200
-	return $type;
1148
+    if (!$table_objet) {
1149
+        return;
1150
+    }
1151
+    $surnoms = lister_types_surnoms();
1152
+
1153
+    // scenario de base
1154
+    // le type est decline a partir du nom de la table en enlevant le prefixe eventuel
1155
+    // et la marque du pluriel
1156
+    // on accepte id_xx en entree aussi
1157
+    $type = preg_replace(',^spip_|^id_|s$,', '', $table_objet);
1158
+    if (isset($surnoms[$type])) {
1159
+        return $surnoms[$type];
1160
+    }
1161
+
1162
+    // securite : eliminer les caracteres non \w
1163
+    $type = preg_replace(',[^\w-],', '', $type);
1164
+
1165
+    // si le type redonne bien la table c'est bon
1166
+    // oui si table_objet ressemblait deja a un type
1167
+    if ($type == $table_objet
1168
+        or (table_objet($type, $serveur) == $table_objet)
1169
+        or (table_objet_sql($type, $serveur) == $table_objet)
1170
+    ) {
1171
+        return $type;
1172
+    }
1173
+
1174
+    // si on ne veut pas chercher en base
1175
+    if ($serveur === false) {
1176
+        return $type;
1177
+    }
1178
+
1179
+    // sinon on passe par la cle primaire id_xx pour trouver le type
1180
+    // car le s a la fin est incertain
1181
+    // notamment en cas de pluriel derogatoire
1182
+    // id_jeu/spip_jeux id_journal/spip_journaux qui necessitent tout deux
1183
+    // une declaration jeu => jeux, journal => journaux
1184
+    // dans le pipeline declarer_tables_objets_surnoms
1185
+    $trouver_table = charger_fonction('trouver_table', 'base');
1186
+    $ts = lister_tables_spip($serveur);
1187
+    $desc = false;
1188
+    if (in_array($table_objet, $ts)) {
1189
+        $desc = $trouver_table($table_objet);
1190
+    }
1191
+    if (!$desc and in_array($table_objet = table_objet($type, $serveur), $ts)) {
1192
+        $desc = $trouver_table($table_objet, $serveur);
1193
+    }
1194
+    // si le type est declare : bingo !
1195
+    if ($desc and isset($desc['type'])) {
1196
+        return $desc['type'];
1197
+    }
1198
+
1199
+    // on a fait ce qu'on a pu
1200
+    return $type;
1201 1201
 }
1202 1202
 
1203 1203
 /**
@@ -1213,56 +1213,56 @@  discard block
 block discarded – undo
1213 1213
  * @return bool
1214 1214
  */
1215 1215
 function objet_test_si_publie($objet, $id_objet, $serveur = '') {
1216
-	// voir si une fonction est definie pour faire le boulot
1217
-	// elle a la priorite dans ce cas
1218
-	if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) {
1219
-		return $f($objet, $id_objet, $serveur);
1220
-	}
1221
-
1222
-	// sinon on se fie a la declaration de l'objet si presente
1223
-	$id_table = $table_objet = table_objet($objet);
1224
-	$id_table_objet = id_table_objet($objet, $serveur);
1225
-	$trouver_table = charger_fonction('trouver_table', 'base');
1226
-	if ($desc = $trouver_table($table_objet, $serveur)
1227
-		and isset($desc['statut'])
1228
-		and $desc['statut']
1229
-	) {
1230
-		$boucle = new Boucle();
1231
-		$boucle->show = $desc;
1232
-		$boucle->nom = 'objet_test_si_publie';
1233
-		$boucle->id_boucle = $id_table;
1234
-		$boucle->id_table = $id_table;
1235
-		$boucle->sql_serveur = $serveur;
1236
-		$boucle->select[] = $id_table_objet;
1237
-		$boucle->from[$table_objet] = table_objet_sql($objet, $serveur);
1238
-		$boucle->where[] = $id_table . '.' . $id_table_objet . '=' . intval($id_objet);
1239
-
1240
-		include_spip('public/compiler');
1241
-		include_spip('public/composer');
1242
-		instituer_boucle($boucle, false, true);
1243
-		$res = calculer_select(
1244
-			$boucle->select,
1245
-			$boucle->from,
1246
-			$boucle->from_type,
1247
-			$boucle->where,
1248
-			$boucle->join,
1249
-			$boucle->group,
1250
-			$boucle->order,
1251
-			$boucle->limit,
1252
-			$boucle->having,
1253
-			$table_objet,
1254
-			$id_table,
1255
-			$serveur
1256
-		);
1257
-		if (sql_fetch($res)) {
1258
-			return true;
1259
-		}
1260
-
1261
-		return false;
1262
-	}
1263
-
1264
-	// si pas d'info statut ni de fonction : l'objet est publie
1265
-	return true;
1216
+    // voir si une fonction est definie pour faire le boulot
1217
+    // elle a la priorite dans ce cas
1218
+    if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) {
1219
+        return $f($objet, $id_objet, $serveur);
1220
+    }
1221
+
1222
+    // sinon on se fie a la declaration de l'objet si presente
1223
+    $id_table = $table_objet = table_objet($objet);
1224
+    $id_table_objet = id_table_objet($objet, $serveur);
1225
+    $trouver_table = charger_fonction('trouver_table', 'base');
1226
+    if ($desc = $trouver_table($table_objet, $serveur)
1227
+        and isset($desc['statut'])
1228
+        and $desc['statut']
1229
+    ) {
1230
+        $boucle = new Boucle();
1231
+        $boucle->show = $desc;
1232
+        $boucle->nom = 'objet_test_si_publie';
1233
+        $boucle->id_boucle = $id_table;
1234
+        $boucle->id_table = $id_table;
1235
+        $boucle->sql_serveur = $serveur;
1236
+        $boucle->select[] = $id_table_objet;
1237
+        $boucle->from[$table_objet] = table_objet_sql($objet, $serveur);
1238
+        $boucle->where[] = $id_table . '.' . $id_table_objet . '=' . intval($id_objet);
1239
+
1240
+        include_spip('public/compiler');
1241
+        include_spip('public/composer');
1242
+        instituer_boucle($boucle, false, true);
1243
+        $res = calculer_select(
1244
+            $boucle->select,
1245
+            $boucle->from,
1246
+            $boucle->from_type,
1247
+            $boucle->where,
1248
+            $boucle->join,
1249
+            $boucle->group,
1250
+            $boucle->order,
1251
+            $boucle->limit,
1252
+            $boucle->having,
1253
+            $table_objet,
1254
+            $id_table,
1255
+            $serveur
1256
+        );
1257
+        if (sql_fetch($res)) {
1258
+            return true;
1259
+        }
1260
+
1261
+        return false;
1262
+    }
1263
+
1264
+    // si pas d'info statut ni de fonction : l'objet est publie
1265
+    return true;
1266 1266
 }
1267 1267
 
1268 1268
 
@@ -1297,125 +1297,125 @@  discard block
 block discarded – undo
1297 1297
  *     Retourne un tableau décrivant les parents trouvés
1298 1298
  */
1299 1299
 function objet_lister_parents($objet, $id_objet, $parent_direct_seulement = false) {
1300
-	$parents = [];
1301
-
1302
-	// Si on trouve une ou des méthodes de parent
1303
-	if ($parent_methodes = objet_type_decrire_infos_parents($objet)) {
1304
-
1305
-		// On identifie les informations sur l'objet source dont on cherche le parent.
1306
-		include_spip('base/abstract_sql');
1307
-		$table_objet = table_objet_sql($objet);
1308
-		$cle_objet = id_table_objet($objet);
1309
-		$id_objet = intval($id_objet);
1310
-
1311
-		// On teste chacun méthode dans l'ordre, et dès qu'on a trouvé un parent on s'arrête
1312
-		foreach ($parent_methodes as $parent_methode) {
1313
-			// Champ identifiant le parent (id et éventuellement le type)
1314
-			// -- cette identification ne dépend pas du fait que le parent soit stocké dans une table de différente
1315
-			//    de celle de l'objet source
1316
-			$select = array();
1317
-			if (isset($parent_methode['champ'])) {
1318
-				$select[] = $parent_methode['champ'];
1319
-			}
1320
-			if (isset($parent_methode['champ_type'])) {
1321
-				$select[] = $parent_methode['champ_type'];
1322
-			}
1323
-
1324
-			// Détermination de la table du parent et des conditions sur l'objet source et le parent.
1325
-			$condition_objet_invalide = false;
1326
-			$where = array();
1327
-			if (!isset($parent_methode['table'])) {
1328
-				// Le parent est stocké dans la même table que l'objet source :
1329
-				// -- toutes les conditions s'appliquent à la table source.
1330
-				$table = $table_objet;
1331
-				$where = array("$cle_objet = $id_objet");
1332
-				// -- Condition supplémentaire sur la détection du parent
1333
-				if (isset($parent_methode['condition'])) {
1334
-					$where[] = $parent_methode['condition'];
1335
-				}
1336
-			} elseif (!$parent_direct_seulement) {
1337
-				// Le parent est stocké dans une table différente de l'objet source.
1338
-				// -- on vérifie d'emblée si il y a une condition sur l'objet source et si celle-ci est vérifiée
1339
-				//    Si non, on peut arrêter le traitement.
1340
-				if (isset($parent_methode['condition'])) {
1341
-					$where = array(
1342
-						"$cle_objet = $id_objet",
1343
-						$parent_methode['condition']
1344
-					);
1345
-					if (!sql_countsel($table_objet, $where)) {
1346
-						$condition_objet_invalide = true;
1347
-					}
1348
-				}
1349
-
1350
-				// Si pas de condition sur l'objet source ou que la condition est vérifiée, on peut construire
1351
-				// la requête sur la table qui accueille le parent.
1352
-				if (!$condition_objet_invalide) {
1353
-					$table = $parent_methode['table'];
1354
-					// On construit les conditions en fonction de l'identification de l'objet source
1355
-					$where = array();
1356
-					// -- si le champ_source de l'id n'est pas précisé c'est qu'il est déjà connu et donc que c'est
1357
-					//    le même que celui de l'objet source.
1358
-					$where[] = isset($parent_methode['source_champ'])
1359
-						? "{$parent_methode['source_champ']} = $id_objet"
1360
-						: "${cle_objet} = $id_objet";
1361
-					if (isset($parent_methode['source_champ_type'])) {
1362
-						$where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet);
1363
-					}
1364
-					// -- Condition supplémentaire sur la détection du parent
1365
-					if (isset($parent_methode['table_condition'])) {
1366
-						$where[] = $parent_methode['table_condition'];
1367
-					}
1368
-				}
1369
-			}
1370
-
1371
-			// On lance la requête de récupération du parent
1372
-			$is_table_lien = (strpos($table, '_liens') !== false and substr($table, -6) === '_liens');
1373
-			if (
1374
-				!$condition_objet_invalide
1375
-				and $where
1376
-				and ($lignes = sql_allfetsel( $is_table_lien ? '*' : $select, $table, $where))
1377
-			) {
1378
-				foreach ($lignes as $ligne) {
1379
-					// Si le type est fixe
1380
-					if (isset($parent_methode['type'])) {
1381
-						$parent = array(
1382
-							'objet' 	=> $parent_methode['type'],
1383
-							'id_objet'	=> intval($ligne[$parent_methode['champ']]),
1384
-							'champ' 	=> $parent_methode['champ'],
1385
-							'table'    => $table,
1386
-						);
1387
-					}
1388
-					elseif (isset($parent_methode['champ_type'])) {
1389
-						$parent = array(
1390
-							'objet' 	 => $ligne[$parent_methode['champ_type']],
1391
-							'id_objet' 	 => intval($ligne[$parent_methode['champ']]),
1392
-							'champ' 	 => $parent_methode['champ'],
1393
-							'champ_type' => $parent_methode['champ_type'],
1394
-							'table'    => $table,
1395
-						);
1396
-					}
1397
-					if ($is_table_lien) {
1398
-						$parent['lien'] = $ligne;
1399
-					}
1400
-					$parents[] = $parent;
1401
-				}
1402
-			}
1403
-		}
1404
-	}
1405
-
1406
-	// On passe par un pipeline avant de retourner
1407
-	$parents = pipeline(
1408
-		'objet_lister_parents',
1409
-		array(
1410
-			'args' => array(
1411
-				'objet' => $objet,
1412
-				'id_objet' => $id_objet,
1413
-			),
1414
-			'data' => $parents,
1415
-		)
1416
-	);
1417
-
1418
-	return $parents;
1300
+    $parents = [];
1301
+
1302
+    // Si on trouve une ou des méthodes de parent
1303
+    if ($parent_methodes = objet_type_decrire_infos_parents($objet)) {
1304
+
1305
+        // On identifie les informations sur l'objet source dont on cherche le parent.
1306
+        include_spip('base/abstract_sql');
1307
+        $table_objet = table_objet_sql($objet);
1308
+        $cle_objet = id_table_objet($objet);
1309
+        $id_objet = intval($id_objet);
1310
+
1311
+        // On teste chacun méthode dans l'ordre, et dès qu'on a trouvé un parent on s'arrête
1312
+        foreach ($parent_methodes as $parent_methode) {
1313
+            // Champ identifiant le parent (id et éventuellement le type)
1314
+            // -- cette identification ne dépend pas du fait que le parent soit stocké dans une table de différente
1315
+            //    de celle de l'objet source
1316
+            $select = array();
1317
+            if (isset($parent_methode['champ'])) {
1318
+                $select[] = $parent_methode['champ'];
1319
+            }
1320
+            if (isset($parent_methode['champ_type'])) {
1321
+                $select[] = $parent_methode['champ_type'];
1322
+            }
1323
+
1324
+            // Détermination de la table du parent et des conditions sur l'objet source et le parent.
1325
+            $condition_objet_invalide = false;
1326
+            $where = array();
1327
+            if (!isset($parent_methode['table'])) {
1328
+                // Le parent est stocké dans la même table que l'objet source :
1329
+                // -- toutes les conditions s'appliquent à la table source.
1330
+                $table = $table_objet;
1331
+                $where = array("$cle_objet = $id_objet");
1332
+                // -- Condition supplémentaire sur la détection du parent
1333
+                if (isset($parent_methode['condition'])) {
1334
+                    $where[] = $parent_methode['condition'];
1335
+                }
1336
+            } elseif (!$parent_direct_seulement) {
1337
+                // Le parent est stocké dans une table différente de l'objet source.
1338
+                // -- on vérifie d'emblée si il y a une condition sur l'objet source et si celle-ci est vérifiée
1339
+                //    Si non, on peut arrêter le traitement.
1340
+                if (isset($parent_methode['condition'])) {
1341
+                    $where = array(
1342
+                        "$cle_objet = $id_objet",
1343
+                        $parent_methode['condition']
1344
+                    );
1345
+                    if (!sql_countsel($table_objet, $where)) {
1346
+                        $condition_objet_invalide = true;
1347
+                    }
1348
+                }
1349
+
1350
+                // Si pas de condition sur l'objet source ou que la condition est vérifiée, on peut construire
1351
+                // la requête sur la table qui accueille le parent.
1352
+                if (!$condition_objet_invalide) {
1353
+                    $table = $parent_methode['table'];
1354
+                    // On construit les conditions en fonction de l'identification de l'objet source
1355
+                    $where = array();
1356
+                    // -- si le champ_source de l'id n'est pas précisé c'est qu'il est déjà connu et donc que c'est
1357
+                    //    le même que celui de l'objet source.
1358
+                    $where[] = isset($parent_methode['source_champ'])
1359
+                        ? "{$parent_methode['source_champ']} = $id_objet"
1360
+                        : "${cle_objet} = $id_objet";
1361
+                    if (isset($parent_methode['source_champ_type'])) {
1362
+                        $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet);
1363
+                    }
1364
+                    // -- Condition supplémentaire sur la détection du parent
1365
+                    if (isset($parent_methode['table_condition'])) {
1366
+                        $where[] = $parent_methode['table_condition'];
1367
+                    }
1368
+                }
1369
+            }
1370
+
1371
+            // On lance la requête de récupération du parent
1372
+            $is_table_lien = (strpos($table, '_liens') !== false and substr($table, -6) === '_liens');
1373
+            if (
1374
+                !$condition_objet_invalide
1375
+                and $where
1376
+                and ($lignes = sql_allfetsel( $is_table_lien ? '*' : $select, $table, $where))
1377
+            ) {
1378
+                foreach ($lignes as $ligne) {
1379
+                    // Si le type est fixe
1380
+                    if (isset($parent_methode['type'])) {
1381
+                        $parent = array(
1382
+                            'objet' 	=> $parent_methode['type'],
1383
+                            'id_objet'	=> intval($ligne[$parent_methode['champ']]),
1384
+                            'champ' 	=> $parent_methode['champ'],
1385
+                            'table'    => $table,
1386
+                        );
1387
+                    }
1388
+                    elseif (isset($parent_methode['champ_type'])) {
1389
+                        $parent = array(
1390
+                            'objet' 	 => $ligne[$parent_methode['champ_type']],
1391
+                            'id_objet' 	 => intval($ligne[$parent_methode['champ']]),
1392
+                            'champ' 	 => $parent_methode['champ'],
1393
+                            'champ_type' => $parent_methode['champ_type'],
1394
+                            'table'    => $table,
1395
+                        );
1396
+                    }
1397
+                    if ($is_table_lien) {
1398
+                        $parent['lien'] = $ligne;
1399
+                    }
1400
+                    $parents[] = $parent;
1401
+                }
1402
+            }
1403
+        }
1404
+    }
1405
+
1406
+    // On passe par un pipeline avant de retourner
1407
+    $parents = pipeline(
1408
+        'objet_lister_parents',
1409
+        array(
1410
+            'args' => array(
1411
+                'objet' => $objet,
1412
+                'id_objet' => $id_objet,
1413
+            ),
1414
+            'data' => $parents,
1415
+        )
1416
+    );
1417
+
1418
+    return $parents;
1419 1419
 }
1420 1420
 
1421 1421
 /**
@@ -1427,17 +1427,17 @@  discard block
 block discarded – undo
1427 1427
  * @return array
1428 1428
  */
1429 1429
 function objet_lister_parents_par_type($objet, $id_objet) {
1430
-	$parents = objet_lister_parents($objet, $id_objet);
1430
+    $parents = objet_lister_parents($objet, $id_objet);
1431 1431
 
1432
-	$parents_par_type = [];
1433
-	foreach ($parents as $parent) {
1434
-		if (!isset($parents_par_type[$parent['objet']])) {
1435
-			$parents_par_type[$parent['objet']] = [];
1436
-		}
1437
-		$parents_par_type[$parent['objet']][] = $parent['id_objet'];
1438
-	}
1432
+    $parents_par_type = [];
1433
+    foreach ($parents as $parent) {
1434
+        if (!isset($parents_par_type[$parent['objet']])) {
1435
+            $parents_par_type[$parent['objet']] = [];
1436
+        }
1437
+        $parents_par_type[$parent['objet']][] = $parent['id_objet'];
1438
+    }
1439 1439
 
1440
-	return $parents_par_type;
1440
+    return $parents_par_type;
1441 1441
 }
1442 1442
 
1443 1443
 
@@ -1470,87 +1470,87 @@  discard block
 block discarded – undo
1470 1470
  *     Retourne un tableau de tableaux, avec comme clés les types des objets, et dans chacun un tableau des identifiants trouvés
1471 1471
  */
1472 1472
 function objet_lister_enfants($objet, $id_objet) {
1473
-	$enfants = array();
1473
+    $enfants = array();
1474 1474
 	
1475
-	// Si on trouve des types d'enfants et leurs méthodes
1476
-	if ($enfants_methodes = objet_type_decrire_infos_enfants($objet)) {
1477
-		include_spip('base/abstract_sql');
1478
-		$id_objet = intval($id_objet);
1475
+    // Si on trouve des types d'enfants et leurs méthodes
1476
+    if ($enfants_methodes = objet_type_decrire_infos_enfants($objet)) {
1477
+        include_spip('base/abstract_sql');
1478
+        $id_objet = intval($id_objet);
1479 1479
 		
1480
-		// On parcourt tous les types d'enfants trouvés
1481
-		foreach ($enfants_methodes as $objet_enfant => $_methode_parent) {
1482
-			// On construit les conditions d'identification du parent
1483
-			$where = array();
1484
-			// -- L'identifiant du parent
1485
-			if (isset($_methode_parent['champ'])) {
1486
-				$where[] = $_methode_parent['champ'] . ' = ' . $id_objet;
1487
-			}
1488
-			// -- Si le parent est variable
1489
-			if (isset($_methode_parent['champ_type'])) {
1490
-				$where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet);
1491
-			}
1492
-
1493
-			// On détermine la table, le champ id des enfants et on complète éventuellement les conditions
1494
-			if (!isset($_methode_parent['table'])) {
1495
-				// Les enfants sont stockés dans la même table que l'objet parent :
1496
-				$table_enfant = table_objet_sql($objet_enfant);
1497
-				$cle_objet_enfant = id_table_objet($objet_enfant);
1498
-
1499
-				// S'il y a une condition supplémentaire
1500
-				if (isset($_methode_parent['condition'])) {
1501
-					$where[] = $_methode_parent['condition'];
1502
-				}
1503
-			} else {
1504
-				// Les enfants sont stockés dans une table différente de l'objet parent.
1505
-				$table_enfant = $_methode_parent['table'];
1506
-				$cle_objet_enfant = isset($_methode_parent['source_champ'])
1507
-					? $_methode_parent['source_champ']
1508
-					: id_table_objet($objet_enfant);
1509
-
1510
-				// S'il y a une condition supplémentaire
1511
-				if (isset($_methode_parent['table_condition'])) {
1512
-					$where[] = $_methode_parent['table_condition'];
1513
-				}
1514
-			}
1515
-
1516
-			// On lance la requête
1517
-			$is_table_lien = (strpos($table_enfant, '_liens') !== false and substr($table_enfant, -6) === '_liens');
1518
-			if ($rows = sql_allfetsel($is_table_lien ? '*' : $cle_objet_enfant, $table_enfant, $where)) {
1519
-				$enfant = [
1520
-					'objet' => $objet_enfant,
1521
-					'id_objet' => 0,
1522
-					'table' => $table_enfant
1523
-				];
1524
-				if (isset($_methode_parent['champ'])) {
1525
-					$enfant['champ'] = $_methode_parent['champ'];
1526
-				}
1527
-				if (isset($_methode_parent['champ_type'])) {
1528
-					$enfant['champ_type'] = $_methode_parent['champ_type'];
1529
-				}
1530
-				foreach ($rows as $row) {
1531
-					$enfant['id_objet'] = intval($row[$cle_objet_enfant]);
1532
-					if ($is_table_lien) {
1533
-						$enfant['lien'] = $row;
1534
-					}
1535
-					$enfants[] = $enfant;
1536
-				}
1537
-			}
1538
-		}
1539
-	}
1540
-
1541
-	// On passe par un pipeline avant de retourner
1542
-	$enfants = pipeline(
1543
-		'objet_lister_enfants',
1544
-		array(
1545
-			'args' => array(
1546
-				'objet' => $objet,
1547
-				'id_objet' => $id_objet,
1548
-			),
1549
-			'data' => $enfants,
1550
-		)
1551
-	);
1552
-
1553
-	return $enfants;
1480
+        // On parcourt tous les types d'enfants trouvés
1481
+        foreach ($enfants_methodes as $objet_enfant => $_methode_parent) {
1482
+            // On construit les conditions d'identification du parent
1483
+            $where = array();
1484
+            // -- L'identifiant du parent
1485
+            if (isset($_methode_parent['champ'])) {
1486
+                $where[] = $_methode_parent['champ'] . ' = ' . $id_objet;
1487
+            }
1488
+            // -- Si le parent est variable
1489
+            if (isset($_methode_parent['champ_type'])) {
1490
+                $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet);
1491
+            }
1492
+
1493
+            // On détermine la table, le champ id des enfants et on complète éventuellement les conditions
1494
+            if (!isset($_methode_parent['table'])) {
1495
+                // Les enfants sont stockés dans la même table que l'objet parent :
1496
+                $table_enfant = table_objet_sql($objet_enfant);
1497
+                $cle_objet_enfant = id_table_objet($objet_enfant);
1498
+
1499
+                // S'il y a une condition supplémentaire
1500
+                if (isset($_methode_parent['condition'])) {
1501
+                    $where[] = $_methode_parent['condition'];
1502
+                }
1503
+            } else {
1504
+                // Les enfants sont stockés dans une table différente de l'objet parent.
1505
+                $table_enfant = $_methode_parent['table'];
1506
+                $cle_objet_enfant = isset($_methode_parent['source_champ'])
1507
+                    ? $_methode_parent['source_champ']
1508
+                    : id_table_objet($objet_enfant);
1509
+
1510
+                // S'il y a une condition supplémentaire
1511
+                if (isset($_methode_parent['table_condition'])) {
1512
+                    $where[] = $_methode_parent['table_condition'];
1513
+                }
1514
+            }
1515
+
1516
+            // On lance la requête
1517
+            $is_table_lien = (strpos($table_enfant, '_liens') !== false and substr($table_enfant, -6) === '_liens');
1518
+            if ($rows = sql_allfetsel($is_table_lien ? '*' : $cle_objet_enfant, $table_enfant, $where)) {
1519
+                $enfant = [
1520
+                    'objet' => $objet_enfant,
1521
+                    'id_objet' => 0,
1522
+                    'table' => $table_enfant
1523
+                ];
1524
+                if (isset($_methode_parent['champ'])) {
1525
+                    $enfant['champ'] = $_methode_parent['champ'];
1526
+                }
1527
+                if (isset($_methode_parent['champ_type'])) {
1528
+                    $enfant['champ_type'] = $_methode_parent['champ_type'];
1529
+                }
1530
+                foreach ($rows as $row) {
1531
+                    $enfant['id_objet'] = intval($row[$cle_objet_enfant]);
1532
+                    if ($is_table_lien) {
1533
+                        $enfant['lien'] = $row;
1534
+                    }
1535
+                    $enfants[] = $enfant;
1536
+                }
1537
+            }
1538
+        }
1539
+    }
1540
+
1541
+    // On passe par un pipeline avant de retourner
1542
+    $enfants = pipeline(
1543
+        'objet_lister_enfants',
1544
+        array(
1545
+            'args' => array(
1546
+                'objet' => $objet,
1547
+                'id_objet' => $id_objet,
1548
+            ),
1549
+            'data' => $enfants,
1550
+        )
1551
+    );
1552
+
1553
+    return $enfants;
1554 1554
 }
1555 1555
 
1556 1556
 /**
@@ -1562,17 +1562,17 @@  discard block
 block discarded – undo
1562 1562
  * @return array
1563 1563
  */
1564 1564
 function objet_lister_enfants_par_type($objet, $id_objet) {
1565
-	$enfants = objet_lister_enfants($objet, $id_objet);
1565
+    $enfants = objet_lister_enfants($objet, $id_objet);
1566 1566
 
1567
-	$enfants_par_type = [];
1568
-	foreach ($enfants as $enfant) {
1569
-		if (!isset($enfants_par_type[$enfant['objet']])) {
1570
-			$enfants_par_type[$enfant['objet']] = [];
1571
-		}
1572
-		$enfants_par_type[$enfant['objet']][] = $enfant['id_objet'];
1573
-	}
1567
+    $enfants_par_type = [];
1568
+    foreach ($enfants as $enfant) {
1569
+        if (!isset($enfants_par_type[$enfant['objet']])) {
1570
+            $enfants_par_type[$enfant['objet']] = [];
1571
+        }
1572
+        $enfants_par_type[$enfant['objet']][] = $enfant['id_objet'];
1573
+    }
1574 1574
 
1575
-	return $enfants_par_type;
1575
+    return $enfants_par_type;
1576 1576
 }
1577 1577
 
1578 1578
 /**
@@ -1584,35 +1584,35 @@  discard block
 block discarded – undo
1584 1584
  *     Retourne un tableau de tableau contenant les informations de type et de champ pour trouver le parent ou false sinon
1585 1585
  */
1586 1586
 function objet_type_decrire_infos_parents($objet) {
1587
-	static $parents = array();
1587
+    static $parents = array();
1588 1588
 	
1589
-	// Si on ne l'a pas encore cherché pour cet objet
1590
-	if (!isset($parents[$objet])) {
1591
-		$parents[$objet] = false;
1592
-		$table = table_objet_sql($objet);
1589
+    // Si on ne l'a pas encore cherché pour cet objet
1590
+    if (!isset($parents[$objet])) {
1591
+        $parents[$objet] = false;
1592
+        $table = table_objet_sql($objet);
1593 1593
 		
1594
-		// Si on trouve bien la description de cet objet
1595
-		if ($infos = lister_tables_objets_sql($table)) {
1596
-			if (isset($infos['parent']) and is_array($infos['parent'])) {
1597
-				// S'il y a une description explicite de parent, c'est prioritaire
1598
-				// -- on traite les cas où il y a une ou plusieurs description mais on renvoie toujours un tableau
1599
-				//    de description
1600
-				if (!isset($infos['parent'][0])) {
1601
-					$parents[$objet] = array($infos['parent']);
1602
-				} else {
1603
-					$parents[$objet] = $infos['parent'];
1604
-				}
1605
-			} elseif (isset($infos['field']['id_rubrique'])) {
1606
-				// Sinon on cherche des cas courants connus magiquement, à commencer par id_rubrique
1607
-				$parents[$objet] = array(array('type' => 'rubrique', 'champ' => 'id_rubrique'));
1608
-			} elseif (isset($infos['field']['id_parent'])) {
1609
-				// Sinon on cherche un champ id_parent, ce qui signifie que l'objet est parent de lui-même
1610
-				$parents[$objet] = array(array('type' => $objet, 'champ' => 'id_parent'));
1611
-			}
1612
-		}
1613
-	}
1594
+        // Si on trouve bien la description de cet objet
1595
+        if ($infos = lister_tables_objets_sql($table)) {
1596
+            if (isset($infos['parent']) and is_array($infos['parent'])) {
1597
+                // S'il y a une description explicite de parent, c'est prioritaire
1598
+                // -- on traite les cas où il y a une ou plusieurs description mais on renvoie toujours un tableau
1599
+                //    de description
1600
+                if (!isset($infos['parent'][0])) {
1601
+                    $parents[$objet] = array($infos['parent']);
1602
+                } else {
1603
+                    $parents[$objet] = $infos['parent'];
1604
+                }
1605
+            } elseif (isset($infos['field']['id_rubrique'])) {
1606
+                // Sinon on cherche des cas courants connus magiquement, à commencer par id_rubrique
1607
+                $parents[$objet] = array(array('type' => 'rubrique', 'champ' => 'id_rubrique'));
1608
+            } elseif (isset($infos['field']['id_parent'])) {
1609
+                // Sinon on cherche un champ id_parent, ce qui signifie que l'objet est parent de lui-même
1610
+                $parents[$objet] = array(array('type' => $objet, 'champ' => 'id_parent'));
1611
+            }
1612
+        }
1613
+    }
1614 1614
 	
1615
-	return $parents[$objet];
1615
+    return $parents[$objet];
1616 1616
 }
1617 1617
 
1618 1618
 /**
@@ -1624,36 +1624,36 @@  discard block
 block discarded – undo
1624 1624
  *     Retourne un tableau de tableaux contenant chacun les informations d'un type d'enfant
1625 1625
  */
1626 1626
 function objet_type_decrire_infos_enfants($objet) {
1627
-	static $enfants = array();
1627
+    static $enfants = array();
1628 1628
 	
1629
-	// Si on a déjà fait la recherche pour ce type d'objet
1630
-	if (!isset($enfants[$objet])) {
1631
-		$enfants[$objet] = array();
1632
-		$tables = lister_tables_objets_sql();
1629
+    // Si on a déjà fait la recherche pour ce type d'objet
1630
+    if (!isset($enfants[$objet])) {
1631
+        $enfants[$objet] = array();
1632
+        $tables = lister_tables_objets_sql();
1633 1633
 		
1634
-		// On parcourt toutes les tables d'objet, et on cherche si chacune peut être enfant
1635
-		foreach ($tables as $table => $infos) {
1636
-			$objet_enfant = objet_type($table);
1634
+        // On parcourt toutes les tables d'objet, et on cherche si chacune peut être enfant
1635
+        foreach ($tables as $table => $infos) {
1636
+            $objet_enfant = objet_type($table);
1637 1637
 			
1638
-			// On ne va pas refaire les tests des différents cas, on réutilise
1639
-			if ($parent_methodes = objet_type_decrire_infos_parents($objet_enfant)) {
1640
-				// On parcourt les différents cas possible, si certains peuvent concerner l'objet demandé
1641
-				foreach ($parent_methodes as $parent_methode) {
1642
-					// Si la méthode qu'on teste n'exclut pas le parent demandé
1643
-					if (!isset($parent_methode['exclus']) or !in_array($objet, $parent_methode['exclus'])) {
1644
-						// Si le type du parent est fixe et directement l'objet demandé
1645
-						if (isset($parent_methode['type']) and isset($parent_methode['champ']) and $parent_methode['type'] == $objet) {
1646
-							$enfants[$objet][$objet_enfant] = $parent_methode;
1647
-						}
1648
-						// Si le type est variable, alors l'objet demandé peut forcément être parent
1649
-						elseif (isset($parent_methode['champ_type']) and isset($parent_methode['champ'])) {
1650
-							$enfants[$objet][$objet_enfant] = $parent_methode;
1651
-						}
1652
-					}
1653
-				}
1654
-			}
1655
-		}
1656
-	}
1638
+            // On ne va pas refaire les tests des différents cas, on réutilise
1639
+            if ($parent_methodes = objet_type_decrire_infos_parents($objet_enfant)) {
1640
+                // On parcourt les différents cas possible, si certains peuvent concerner l'objet demandé
1641
+                foreach ($parent_methodes as $parent_methode) {
1642
+                    // Si la méthode qu'on teste n'exclut pas le parent demandé
1643
+                    if (!isset($parent_methode['exclus']) or !in_array($objet, $parent_methode['exclus'])) {
1644
+                        // Si le type du parent est fixe et directement l'objet demandé
1645
+                        if (isset($parent_methode['type']) and isset($parent_methode['champ']) and $parent_methode['type'] == $objet) {
1646
+                            $enfants[$objet][$objet_enfant] = $parent_methode;
1647
+                        }
1648
+                        // Si le type est variable, alors l'objet demandé peut forcément être parent
1649
+                        elseif (isset($parent_methode['champ_type']) and isset($parent_methode['champ'])) {
1650
+                            $enfants[$objet][$objet_enfant] = $parent_methode;
1651
+                        }
1652
+                    }
1653
+                }
1654
+            }
1655
+        }
1656
+    }
1657 1657
 	
1658
-	return $enfants[$objet];
1658
+    return $enfants[$objet];
1659 1659
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 		$infos['url_voir'] = $infos['type'];
704 704
 	}
705 705
 	if (!isset($infos['url_edit'])) {
706
-		$infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : '');
706
+		$infos['url_edit'] = $infos['url_voir'].($infos['editable'] ? '_edit' : '');
707 707
 	}
708 708
 	if (!isset($infos['icone_objet'])) {
709 709
 		$infos['icone_objet'] = $infos['type'];
@@ -715,48 +715,48 @@  discard block
 block discarded – undo
715 715
 		$infos['texte_retour'] = 'icone_retour';
716 716
 	}
717 717
 	if (!isset($infos['texte_modifier'])) {
718
-		$infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type'];
718
+		$infos['texte_modifier'] = $infos['type'].':'.'icone_modifier_'.$infos['type'];
719 719
 	}
720 720
 	if (!isset($infos['texte_creer'])) {
721
-		$infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type'];
721
+		$infos['texte_creer'] = $infos['type'].':'.'icone_creer_'.$infos['type'];
722 722
 	}
723 723
 	if (!isset($infos['texte_creer_associer'])) {
724
-		$infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type'];
724
+		$infos['texte_creer_associer'] = $infos['type'].':'.'texte_creer_associer_'.$infos['type'];
725 725
 	}
726 726
 	if (!isset($infos['texte_ajouter'])) {
727 727
 		// Ajouter un X
728
-		$infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type'];
728
+		$infos['texte_ajouter'] = $infos['type'].':'.'texte_ajouter_'.$infos['type'];
729 729
 	}
730 730
 	if (!isset($infos['texte_objets'])) {
731
-		$infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet'];
731
+		$infos['texte_objets'] = $infos['type'].':'.'titre_'.$infos['table_objet'];
732 732
 	}
733 733
 	if (!isset($infos['texte_objet'])) {
734
-		$infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type'];
734
+		$infos['texte_objet'] = $infos['type'].':'.'titre_'.$infos['type'];
735 735
 	}
736 736
 	if (!isset($infos['texte_logo_objet'])) {
737 737
 		// objet:titre_logo_objet "Logo de ce X"
738
-		$infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type'];
738
+		$infos['texte_logo_objet'] = $infos['type'].':'.'titre_logo_'.$infos['type'];
739 739
 	}
740 740
 	if (!isset($infos['texte_langue_objet'])) {
741 741
 		// objet:texte_langue_objet "Langue de ce X"
742
-		$infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type'];
742
+		$infos['texte_langue_objet'] = $infos['type'].':'.'titre_langue_'.$infos['type'];
743 743
 	}
744 744
 	if (!isset($infos['texte_definir_comme_traduction_objet'])) {
745 745
 		// "Ce X est une traduction du X numéro :"
746
-		$infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type'];
746
+		$infos['texte_definir_comme_traduction_objet'] = $infos['type'].':'.'texte_definir_comme_traduction_'.$infos['type'];
747 747
 	}
748 748
 
749 749
 	// objet:info_aucun_objet
750 750
 	if (!isset($infos['info_aucun_objet'])) {
751
-		$infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type'];
751
+		$infos['info_aucun_objet'] = $infos['type'].':'.'info_aucun_'.$infos['type'];
752 752
 	}
753 753
 	// objet:info_1_objet
754 754
 	if (!isset($infos['info_1_objet'])) {
755
-		$infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type'];
755
+		$infos['info_1_objet'] = $infos['type'].':'.'info_1_'.$infos['type'];
756 756
 	}
757 757
 	// objet:info_nb_objets
758 758
 	if (!isset($infos['info_nb_objets'])) {
759
-		$infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet'];
759
+		$infos['info_nb_objets'] = $infos['type'].':'.'info_nb_'.$infos['table_objet'];
760 760
 	}
761 761
 
762 762
 	if (!isset($infos['champs_editables'])) {
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
 		}
957 957
 		$ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso)
958 958
 		$connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0];
959
-		$spip = $connexion['prefixe'] . '_';
959
+		$spip = $connexion['prefixe'].'_';
960 960
 		foreach ($ts as $t) {
961 961
 			$t = substr($t, strlen($spip));
962 962
 			$tables[$serveur]["spip_$t"] = $t;
@@ -977,14 +977,14 @@  discard block
 block discarded – undo
977 977
  * @return array
978 978
  *     Couples (nom de la table SQL => même nom)
979 979
  **/
980
-function lister_toutes_tables($serveur){
980
+function lister_toutes_tables($serveur) {
981 981
 	static $tables = array();
982
-	if (!isset($tables[$serveur])){
982
+	if (!isset($tables[$serveur])) {
983 983
 		$tables[$serveur] = array();
984 984
 		if (!function_exists("sql_alltable"))
985 985
 			include_spip("base/abstract_sql");
986
-		$ts = sql_alltable('%',$serveur); // toutes les tables
987
-		foreach ($ts as $t){
986
+		$ts = sql_alltable('%', $serveur); // toutes les tables
987
+		foreach ($ts as $t) {
988 988
 			$tables[$serveur][$t] = $t;
989 989
 		}
990 990
 	}
@@ -1020,9 +1020,9 @@  discard block
 block discarded – undo
1020 1020
 	if ($serveur !== false) {
1021 1021
 		$t = lister_tables_spip($serveur);
1022 1022
 		$trouver_table = charger_fonction('trouver_table', 'base');
1023
-		$typetrim = rtrim($type, 's') . 's';
1023
+		$typetrim = rtrim($type, 's').'s';
1024 1024
 		if ((isset($t[$typetrim]) or in_array($typetrim, $t))
1025
-			and ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur))
1025
+			and ($desc = $trouver_table(rtrim($type, 's').'s', $serveur))
1026 1026
 		) {
1027 1027
 			return $desc['id_table'];
1028 1028
 		} elseif ((isset($t[$type]) or in_array($type, $t))
@@ -1031,11 +1031,11 @@  discard block
 block discarded – undo
1031 1031
 			return $desc['id_table'];
1032 1032
 		}
1033 1033
 
1034
-		spip_log('table_objet(' . $type . ') calculee sans verification');
1034
+		spip_log('table_objet('.$type.') calculee sans verification');
1035 1035
 		#spip_log(debug_backtrace(),'db');
1036 1036
 	}
1037 1037
 
1038
-	return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false
1038
+	return rtrim($type, 's').'s'; # cas historique ne devant plus servir, sauf si $serveur=false
1039 1039
 }
1040 1040
 
1041 1041
 /**
@@ -1112,7 +1112,7 @@  discard block
 block discarded – undo
1112 1112
 	if (
1113 1113
 		in_array($t, $ts)
1114 1114
 		or in_array($t, lister_toutes_tables($serveur))
1115
-	){
1115
+	) {
1116 1116
 		$desc = $trouver_table($t, $serveur);
1117 1117
 		if (isset($desc['key']['PRIMARY KEY'])) {
1118 1118
 			return $desc['key']['PRIMARY KEY'];
@@ -1215,7 +1215,7 @@  discard block
 block discarded – undo
1215 1215
 function objet_test_si_publie($objet, $id_objet, $serveur = '') {
1216 1216
 	// voir si une fonction est definie pour faire le boulot
1217 1217
 	// elle a la priorite dans ce cas
1218
-	if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) {
1218
+	if ($f = charger_fonction($objet.'_test_si_publie', 'base', true)) {
1219 1219
 		return $f($objet, $id_objet, $serveur);
1220 1220
 	}
1221 1221
 
@@ -1235,7 +1235,7 @@  discard block
 block discarded – undo
1235 1235
 		$boucle->sql_serveur = $serveur;
1236 1236
 		$boucle->select[] = $id_table_objet;
1237 1237
 		$boucle->from[$table_objet] = table_objet_sql($objet, $serveur);
1238
-		$boucle->where[] = $id_table . '.' . $id_table_objet . '=' . intval($id_objet);
1238
+		$boucle->where[] = $id_table.'.'.$id_table_objet.'='.intval($id_objet);
1239 1239
 
1240 1240
 		include_spip('public/compiler');
1241 1241
 		include_spip('public/composer');
@@ -1359,7 +1359,7 @@  discard block
 block discarded – undo
1359 1359
 						? "{$parent_methode['source_champ']} = $id_objet"
1360 1360
 						: "${cle_objet} = $id_objet";
1361 1361
 					if (isset($parent_methode['source_champ_type'])) {
1362
-						$where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet);
1362
+						$where[] = "{$parent_methode['source_champ_type']} = ".sql_quote($objet);
1363 1363
 					}
1364 1364
 					// -- Condition supplémentaire sur la détection du parent
1365 1365
 					if (isset($parent_methode['table_condition'])) {
@@ -1373,7 +1373,7 @@  discard block
 block discarded – undo
1373 1373
 			if (
1374 1374
 				!$condition_objet_invalide
1375 1375
 				and $where
1376
-				and ($lignes = sql_allfetsel( $is_table_lien ? '*' : $select, $table, $where))
1376
+				and ($lignes = sql_allfetsel($is_table_lien ? '*' : $select, $table, $where))
1377 1377
 			) {
1378 1378
 				foreach ($lignes as $ligne) {
1379 1379
 					// Si le type est fixe
@@ -1483,11 +1483,11 @@  discard block
 block discarded – undo
1483 1483
 			$where = array();
1484 1484
 			// -- L'identifiant du parent
1485 1485
 			if (isset($_methode_parent['champ'])) {
1486
-				$where[] = $_methode_parent['champ'] . ' = ' . $id_objet;
1486
+				$where[] = $_methode_parent['champ'].' = '.$id_objet;
1487 1487
 			}
1488 1488
 			// -- Si le parent est variable
1489 1489
 			if (isset($_methode_parent['champ_type'])) {
1490
-				$where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet);
1490
+				$where[] = $_methode_parent['champ_type'].' = '.sql_quote($objet);
1491 1491
 			}
1492 1492
 
1493 1493
 			// On détermine la table, le champ id des enfants et on complète éventuellement les conditions
Please login to merge, or discard this patch.
Braces   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -981,8 +981,9 @@  discard block
 block discarded – undo
981 981
 	static $tables = array();
982 982
 	if (!isset($tables[$serveur])){
983 983
 		$tables[$serveur] = array();
984
-		if (!function_exists("sql_alltable"))
985
-			include_spip("base/abstract_sql");
984
+		if (!function_exists("sql_alltable")) {
985
+					include_spip("base/abstract_sql");
986
+		}
986 987
 		$ts = sql_alltable('%',$serveur); // toutes les tables
987 988
 		foreach ($ts as $t){
988 989
 			$tables[$serveur][$t] = $t;
@@ -1384,8 +1385,7 @@  discard block
 block discarded – undo
1384 1385
 							'champ' 	=> $parent_methode['champ'],
1385 1386
 							'table'    => $table,
1386 1387
 						);
1387
-					}
1388
-					elseif (isset($parent_methode['champ_type'])) {
1388
+					} elseif (isset($parent_methode['champ_type'])) {
1389 1389
 						$parent = array(
1390 1390
 							'objet' 	 => $ligne[$parent_methode['champ_type']],
1391 1391
 							'id_objet' 	 => intval($ligne[$parent_methode['champ']]),
Please login to merge, or discard this patch.
ecrire/inc/filtres.php 2 patches
Doc Comments   +21 added lines, -9 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
  *
70 70
  * @param string $fonc
71 71
  *     Nom du filtre
72
- * @param null $default
72
+ * @param string $default
73 73
  *     Nom du filtre appliqué par défaut si celui demandé n'est pas trouvé
74 74
  * @return string
75 75
  *     Fonction PHP correspondante du filtre demandé
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
  * @see appliquer_si_filtre() Proche : retourne le texte d'origine si le filtre est absent
142 142
  * @uses appliquer_filtre_sinon()
143 143
  *
144
- * @param mixed $arg
144
+ * @param string $arg
145 145
  *     Texte (le plus souvent) sur lequel appliquer le filtre
146 146
  * @param string $filtre
147 147
  *     Nom du filtre à appliquer
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
  *   corriger toutes les `&xx;` en `&xx;`
797 797
  * @param bool $quote
798 798
  *   Échapper aussi les simples quotes en `'`
799
- * @return mixed|string
799
+ * @return string
800 800
  */
801 801
 function entites_html($texte, $tout = false, $quote = true) {
802 802
 	if (!is_string($texte) or !$texte
@@ -1431,7 +1431,7 @@  discard block
 block discarded – undo
1431 1431
  *
1432 1432
  * @param mixed $texte
1433 1433
  *     Contenu de reference a tester
1434
- * @param mixed $sinon
1434
+ * @param string|null $sinon
1435 1435
  *     Contenu a retourner si le contenu de reference est vide
1436 1436
  * @return mixed
1437 1437
  *     Retourne $texte, sinon $sinon.
@@ -1613,7 +1613,7 @@  discard block
 block discarded – undo
1613 1613
  * @param string $letexte
1614 1614
  * @param string $lang
1615 1615
  *     Langue à retrouver (si vide, utilise la langue en cours).
1616
- * @param array $options Options {
1616
+ * @param boolean $options Options {
1617 1617
  * @type bool $echappe_span
1618 1618
  *         True pour échapper les balises span (false par défaut)
1619 1619
  * @type string $lang_defaut
@@ -1703,7 +1703,7 @@  discard block
 block discarded – undo
1703 1703
  * @param string $letexte
1704 1704
  * @param string $lang
1705 1705
  *     Langue à retrouver (si vide, utilise la langue en cours).
1706
- * @param array $options Options {
1706
+ * @param boolean $options Options {
1707 1707
  * @type bool $echappe_span
1708 1708
  *         True pour échapper les balises span (false par défaut)
1709 1709
  * @type string $lang_defaut
@@ -2177,6 +2177,9 @@  discard block
 block discarded – undo
2177 2177
 // Quelques fonctions de calcul arithmetique
2178 2178
 //
2179 2179
 function floatstr($a) { return str_replace(',','.',(string)floatval($a)); }
2180
+/**
2181
+ * @param string $f
2182
+ */
2180 2183
 function strize($f, $a, $b) { return floatstr($f(floatstr($a),floatstr($b))); }
2181 2184
 
2182 2185
 /**
@@ -2320,7 +2323,7 @@  discard block
 block discarded – undo
2320 2323
  * @param string|array $adresses
2321 2324
  *      Adresse ou liste d'adresse
2322 2325
  *      si on fournit un tableau, il est filtre et la fonction renvoie avec uniquement les adresses email valides (donc possiblement vide)
2323
- * @return bool|string|array
2326
+ * @return string|null
2324 2327
  *      - false si une des adresses n'est pas conforme,
2325 2328
  *      - la normalisation de la dernière adresse donnée sinon
2326 2329
  *      - renvoie un tableau si l'entree est un tableau
@@ -2644,7 +2647,7 @@  discard block
 block discarded – undo
2644 2647
  * @param int $a
2645 2648
  * @param int $b
2646 2649
  * @param int $c
2647
- * @return int
2650
+ * @return double
2648 2651
  *      Retourne `$a*$b/$c`
2649 2652
  **/
2650 2653
 function regledetrois($a, $b, $c) {
@@ -3466,6 +3469,10 @@  discard block
 block discarded – undo
3466 3469
 }
3467 3470
 
3468 3471
 
3472
+/**
3473
+ * @param string $alt_or_size
3474
+ * @param string|null $class_or_size
3475
+ */
3469 3476
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3470 3477
 	$args = [$alt_or_size, $class_or_size, $size];
3471 3478
 	while (is_null(end($args)) and count($args)) {
@@ -3494,6 +3501,10 @@  discard block
 block discarded – undo
3494 3501
 	return $args;
3495 3502
 }
3496 3503
 
3504
+/**
3505
+ * @param string $img
3506
+ * @param string $size
3507
+ */
3497 3508
 function helper_filtre_balise_img_svg_size($img, $size) {
3498 3509
 	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3499 3510
 	if (strpos($size, '@') === 0 and substr($size,-1) === 'x') {
@@ -4814,7 +4825,7 @@  discard block
 block discarded – undo
4814 4825
  *     Nombre d'éléments
4815 4826
  * @param string $objet
4816 4827
  *     Objet
4817
- * @return mixed|string
4828
+ * @return string
4818 4829
  *     Texte traduit du comptage, tel que '3 articles'
4819 4830
  */
4820 4831
 function objet_afficher_nb($nb, $objet) {
@@ -5294,6 +5305,7 @@  discard block
 block discarded – undo
5294 5305
  *
5295 5306
  * @param string $objet
5296 5307
  * @param int|string $id_objet
5308
+ * @param string $fonction
5297 5309
  * @return array
5298 5310
  */
5299 5311
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
Please login to merge, or discard this patch.
Indentation   +2243 added lines, -2243 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
 /**
@@ -75,38 +75,38 @@  discard block
 block discarded – undo
75 75
  *     Fonction PHP correspondante du filtre demandé
76 76
  */
77 77
 function chercher_filtre($fonc, $default = null) {
78
-	if (!$fonc) {
79
-		return $default;
80
-	}
81
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
82
-	// Foo::Bar
83
-	// qui peuvent etre avec un namespace : space\Foo::Bar
84
-	if (preg_match(',^[\w]+/,', $fonc)) {
85
-		$nom = preg_replace(',\W,', '_', $fonc);
86
-		$f = chercher_filtre($nom);
87
-		// cas du sous-type MIME sans filtre associe, passer au type:
88
-		// si filtre_text_plain pas defini, passe a filtre_text
89
-		if (!$f and $nom !== $fonc) {
90
-			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
91
-		}
92
-
93
-		return $f;
94
-	}
95
-
96
-	include_fichiers_fonctions();
97
-	foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
98
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
99
-		// fonction ou name\space\fonction
100
-		if (is_callable($f)) {
101
-			return $f;
102
-		}
103
-		// méthode statique d'une classe Classe::methode ou name\space\Classe::methode
104
-		elseif (false === strpos($f, '::') and is_callable(array($f))) {
105
-			return $f;
106
-		}
107
-	}
108
-
109
-	return $default;
78
+    if (!$fonc) {
79
+        return $default;
80
+    }
81
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
82
+    // Foo::Bar
83
+    // qui peuvent etre avec un namespace : space\Foo::Bar
84
+    if (preg_match(',^[\w]+/,', $fonc)) {
85
+        $nom = preg_replace(',\W,', '_', $fonc);
86
+        $f = chercher_filtre($nom);
87
+        // cas du sous-type MIME sans filtre associe, passer au type:
88
+        // si filtre_text_plain pas defini, passe a filtre_text
89
+        if (!$f and $nom !== $fonc) {
90
+            $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
91
+        }
92
+
93
+        return $f;
94
+    }
95
+
96
+    include_fichiers_fonctions();
97
+    foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
98
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
99
+        // fonction ou name\space\fonction
100
+        if (is_callable($f)) {
101
+            return $f;
102
+        }
103
+        // méthode statique d'une classe Classe::methode ou name\space\Classe::methode
104
+        elseif (false === strpos($f, '::') and is_callable(array($f))) {
105
+            return $f;
106
+        }
107
+    }
108
+
109
+    return $default;
110 110
 }
111 111
 
112 112
 /**
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
  *     Chaîne vide sinon.
151 151
  **/
152 152
 function appliquer_filtre($arg, $filtre) {
153
-	$args = func_get_args();
154
-	return appliquer_filtre_sinon($arg, $filtre, $args, '');
153
+    $args = func_get_args();
154
+    return appliquer_filtre_sinon($arg, $filtre, $args, '');
155 155
 }
156 156
 
157 157
 /**
@@ -176,8 +176,8 @@  discard block
 block discarded – undo
176 176
  *     Texte d'origine sinon
177 177
  **/
178 178
 function appliquer_si_filtre($arg, $filtre) {
179
-	$args = func_get_args();
180
-	return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
179
+    $args = func_get_args();
180
+    return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
181 181
 }
182 182
 
183 183
 /**
@@ -193,12 +193,12 @@  discard block
 block discarded – undo
193 193
  *     Version de SPIP
194 194
  **/
195 195
 function spip_version() {
196
-	$version = $GLOBALS['spip_version_affichee'];
197
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
198
-		$version .= " $vcs_version";
199
-	}
196
+    $version = $GLOBALS['spip_version_affichee'];
197
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
198
+        $version .= " $vcs_version";
199
+    }
200 200
 
201
-	return $version;
201
+    return $version;
202 202
 }
203 203
 
204 204
 /**
@@ -211,19 +211,19 @@  discard block
 block discarded – undo
211 211
  *    - string|null si $raw = false
212 212
  */
213 213
 function version_vcs_courante($dir, $raw = false) {
214
-	$desc = decrire_version_git($dir);
215
-	if ($desc === null) {
216
-		$desc = decrire_version_svn($dir);
217
-	}
218
-	if ($desc === null or $raw) {
219
-		return $desc;
220
-	}
221
-	// affichage "GIT [master: abcdef]"
222
-	$commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
223
-	if ($desc['branch']) {
224
-		$commit = $desc['branch'] . ': ' . $commit;
225
-	}
226
-	return "{$desc['vcs']} [$commit]";
214
+    $desc = decrire_version_git($dir);
215
+    if ($desc === null) {
216
+        $desc = decrire_version_svn($dir);
217
+    }
218
+    if ($desc === null or $raw) {
219
+        return $desc;
220
+    }
221
+    // affichage "GIT [master: abcdef]"
222
+    $commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
223
+    if ($desc['branch']) {
224
+        $commit = $desc['branch'] . ': ' . $commit;
225
+    }
226
+    return "{$desc['vcs']} [$commit]";
227 227
 }
228 228
 
229 229
 /**
@@ -235,24 +235,24 @@  discard block
 block discarded – undo
235 235
  *      array ['branch' => xx, 'commit' => yy] sinon.
236 236
  **/
237 237
 function decrire_version_git($dir) {
238
-	if (!$dir) {
239
-		$dir = '.';
240
-	}
238
+    if (!$dir) {
239
+        $dir = '.';
240
+    }
241 241
 
242
-	// version installee par GIT
243
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
244
-		$currentHead = trim(substr($c, 4));
245
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
246
-			return [
247
-				'vcs' => 'GIT',
248
-				'branch' => basename($currentHead),
249
-				'commit' => trim($hash),
250
-				'commit_short' => substr(trim($hash), 0, 8),
251
-			];
252
-		}
253
-	}
242
+    // version installee par GIT
243
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
244
+        $currentHead = trim(substr($c, 4));
245
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
246
+            return [
247
+                'vcs' => 'GIT',
248
+                'branch' => basename($currentHead),
249
+                'commit' => trim($hash),
250
+                'commit_short' => substr(trim($hash), 0, 8),
251
+            ];
252
+        }
253
+    }
254 254
 
255
-	return null;
255
+    return null;
256 256
 }
257 257
 
258 258
 
@@ -265,25 +265,25 @@  discard block
 block discarded – undo
265 265
  *      array ['commit' => yy, 'date' => xx, 'author' => xx] sinon.
266 266
  **/
267 267
 function decrire_version_svn($dir) {
268
-	if (!$dir) {
269
-		$dir = '.';
270
-	}
271
-	// version installee par SVN
272
-	if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
273
-		$db = new SQLite3($dir . '/.svn/wc.db');
274
-		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
275
-		if ($result) {
276
-			$row = $result->fetchArray();
277
-			if ($row['changed_revision'] != "") {
278
-				return [
279
-					'vcs' => 'SVN',
280
-					'branch' => '',
281
-					'commit' => $row['changed_revision'],
282
-				];
283
-			}
284
-		}
285
-	}
286
-	return null;
268
+    if (!$dir) {
269
+        $dir = '.';
270
+    }
271
+    // version installee par SVN
272
+    if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
273
+        $db = new SQLite3($dir . '/.svn/wc.db');
274
+        $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
275
+        if ($result) {
276
+            $row = $result->fetchArray();
277
+            if ($row['changed_revision'] != "") {
278
+                return [
279
+                    'vcs' => 'SVN',
280
+                    'branch' => '',
281
+                    'commit' => $row['changed_revision'],
282
+                ];
283
+            }
284
+        }
285
+    }
286
+    return null;
287 287
 }
288 288
 
289 289
 /**
@@ -301,10 +301,10 @@  discard block
 block discarded – undo
301 301
  *
302 302
  **/
303 303
 function version_svn_courante($dir) {
304
-	if ($desc = decrire_version_svn($dir)) {
305
-		return -$desc['commit'];
306
-	}
307
-	return 0;
304
+    if ($desc = decrire_version_svn($dir)) {
305
+        return -$desc['commit'];
306
+    }
307
+    return 0;
308 308
 }
309 309
 
310 310
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -350,18 +350,18 @@  discard block
 block discarded – undo
350 350
  *     Code HTML retourné par le filtre
351 351
  **/
352 352
 function filtrer($filtre) {
353
-	$tous = func_get_args();
354
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
355
-		return image_filtrer($tous);
356
-	} elseif ($f = chercher_filtre($filtre)) {
357
-		array_shift($tous);
358
-		return call_user_func_array($f, $tous);
359
-	} else {
360
-		// le filtre n'existe pas, on provoque une erreur
361
-		$msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre)));
362
-		erreur_squelette($msg);
363
-		return '';
364
-	}
353
+    $tous = func_get_args();
354
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
355
+        return image_filtrer($tous);
356
+    } elseif ($f = chercher_filtre($filtre)) {
357
+        array_shift($tous);
358
+        return call_user_func_array($f, $tous);
359
+    } else {
360
+        // le filtre n'existe pas, on provoque une erreur
361
+        $msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre)));
362
+        erreur_squelette($msg);
363
+        return '';
364
+    }
365 365
 }
366 366
 
367 367
 /**
@@ -378,11 +378,11 @@  discard block
 block discarded – undo
378 378
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
379 379
  */
380 380
 function trouver_filtre_matrice($filtre) {
381
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
382
-		find_in_path($f, '', true);
383
-		$GLOBALS['spip_matrice'][$filtre] = true;
384
-	}
385
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
381
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
382
+        find_in_path($f, '', true);
383
+        $GLOBALS['spip_matrice'][$filtre] = true;
384
+    }
385
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
386 386
 }
387 387
 
388 388
 
@@ -410,8 +410,8 @@  discard block
 block discarded – undo
410 410
  * @return mixed
411 411
  */
412 412
 function filtre_set(&$Pile, $val, $key, $continue = null) {
413
-	$Pile['vars'][$key] = $val;
414
-	return $continue ? $val : '';
413
+    $Pile['vars'][$key] = $val;
414
+    return $continue ? $val : '';
415 415
 }
416 416
 
417 417
 /**
@@ -437,8 +437,8 @@  discard block
 block discarded – undo
437 437
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
438 438
  */
439 439
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
440
-	$Pile[0][$key] = $val;
441
-	return $continue ? $val : '';
440
+    $Pile[0][$key] = $val;
441
+    return $continue ? $val : '';
442 442
 }
443 443
 
444 444
 /**
@@ -447,8 +447,8 @@  discard block
 block discarded – undo
447 447
  * @return string
448 448
  */
449 449
 function filtre_sanitize_env(&$Pile, $keys) {
450
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
451
-	return '';
450
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
451
+    return '';
452 452
 }
453 453
 
454 454
 
@@ -471,18 +471,18 @@  discard block
 block discarded – undo
471 471
  * @return mixed Retourne la valeur (sans la modifier).
472 472
  */
473 473
 function filtre_debug($val, $key = null) {
474
-	$debug = (
475
-		is_null($key) ? '' : (var_export($key, true) . " = ")
476
-		) . var_export($val, true);
474
+    $debug = (
475
+        is_null($key) ? '' : (var_export($key, true) . " = ")
476
+        ) . var_export($val, true);
477 477
 
478
-	include_spip('inc/autoriser');
479
-	if (autoriser('webmestre')) {
480
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
481
-	}
478
+    include_spip('inc/autoriser');
479
+    if (autoriser('webmestre')) {
480
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
481
+    }
482 482
 
483
-	spip_log($debug, 'debug');
483
+    spip_log($debug, 'debug');
484 484
 
485
-	return $val;
485
+    return $val;
486 486
 }
487 487
 
488 488
 
@@ -510,82 +510,82 @@  discard block
 block discarded – undo
510 510
  *     Texte qui a reçu les filtres
511 511
  **/
512 512
 function image_filtrer($args) {
513
-	$filtre = array_shift($args); # enlever $filtre
514
-	$texte = array_shift($args);
515
-	if (!strlen($texte)) {
516
-		return;
517
-	}
518
-	find_in_path('filtres_images_mini.php', 'inc/', true);
519
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
520
-	// Cas du nom de fichier local
521
-	$is_file = trim($texte);
522
-	if (strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
523
-		  or strpbrk($is_file, "<>\n\r\t") !== false
524
-		  or strpos($is_file, '/') === 0
525
-	) {
526
-		$is_file = false;
527
-	}
528
-	if ($is_file) {
529
-		$is_local_file = function($path) {
530
-			if (strpos($path, "?") !== false) {
531
-				$path = supprimer_timestamp($path);
532
-				// remove ?24px added by find_in_theme on .svg files
533
-				$path = preg_replace(",\?[[:digit:]]+(px)$,", "", $path);
534
-			}
535
-			return file_exists($path);
536
-		};
537
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
538
-			array_unshift($args, "<img src='$is_file' />");
539
-			$res = call_user_func_array($filtre, $args);
540
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
541
-			return $res;
542
-		}
543
-	}
544
-
545
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
546
-	if (preg_match_all(
547
-		',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
548
-		$texte, $tags, PREG_SET_ORDER)) {
549
-		foreach ($tags as $tag) {
550
-			$class = extraire_attribut($tag[3], 'class');
551
-			if (!$class or
552
-				(strpos($class, 'filtre_inactif') === false
553
-					// compat historique a virer en 3.2
554
-					and strpos($class, 'no_image_filtrer') === false)
555
-			) {
556
-				array_unshift($args, $tag[3]);
557
-				if ($reduit = call_user_func_array($filtre, $args)) {
558
-					// En cas de span spip_documents, modifier le style=...width:
559
-					if ($tag[1]) {
560
-						$w = extraire_attribut($reduit, 'width');
561
-						if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) {
562
-							$w = $regs[1];
563
-						}
564
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
565
-							$style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
566
-							$replace = inserer_attribut($tag[1], 'style', $style);
567
-							$texte = str_replace($tag[1], $replace, $texte);
568
-						}
569
-					}
570
-					// traiter aussi un eventuel mouseover
571
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
572
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
573
-							$srcover = $match[1];
574
-							array_shift($args);
575
-							array_unshift($args, "<img src='" . $match[1] . "' />");
576
-							$srcover_filter = call_user_func_array($filtre, $args);
577
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
578
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
579
-						}
580
-					}
581
-					$texte = str_replace($tag[3], $reduit, $texte);
582
-				}
583
-				array_shift($args);
584
-			}
585
-		}
586
-	}
587
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
588
-	return $texte;
513
+    $filtre = array_shift($args); # enlever $filtre
514
+    $texte = array_shift($args);
515
+    if (!strlen($texte)) {
516
+        return;
517
+    }
518
+    find_in_path('filtres_images_mini.php', 'inc/', true);
519
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
520
+    // Cas du nom de fichier local
521
+    $is_file = trim($texte);
522
+    if (strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
523
+          or strpbrk($is_file, "<>\n\r\t") !== false
524
+          or strpos($is_file, '/') === 0
525
+    ) {
526
+        $is_file = false;
527
+    }
528
+    if ($is_file) {
529
+        $is_local_file = function($path) {
530
+            if (strpos($path, "?") !== false) {
531
+                $path = supprimer_timestamp($path);
532
+                // remove ?24px added by find_in_theme on .svg files
533
+                $path = preg_replace(",\?[[:digit:]]+(px)$,", "", $path);
534
+            }
535
+            return file_exists($path);
536
+        };
537
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
538
+            array_unshift($args, "<img src='$is_file' />");
539
+            $res = call_user_func_array($filtre, $args);
540
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
541
+            return $res;
542
+        }
543
+    }
544
+
545
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
546
+    if (preg_match_all(
547
+        ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
548
+        $texte, $tags, PREG_SET_ORDER)) {
549
+        foreach ($tags as $tag) {
550
+            $class = extraire_attribut($tag[3], 'class');
551
+            if (!$class or
552
+                (strpos($class, 'filtre_inactif') === false
553
+                    // compat historique a virer en 3.2
554
+                    and strpos($class, 'no_image_filtrer') === false)
555
+            ) {
556
+                array_unshift($args, $tag[3]);
557
+                if ($reduit = call_user_func_array($filtre, $args)) {
558
+                    // En cas de span spip_documents, modifier le style=...width:
559
+                    if ($tag[1]) {
560
+                        $w = extraire_attribut($reduit, 'width');
561
+                        if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) {
562
+                            $w = $regs[1];
563
+                        }
564
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
565
+                            $style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
566
+                            $replace = inserer_attribut($tag[1], 'style', $style);
567
+                            $texte = str_replace($tag[1], $replace, $texte);
568
+                        }
569
+                    }
570
+                    // traiter aussi un eventuel mouseover
571
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
572
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
573
+                            $srcover = $match[1];
574
+                            array_shift($args);
575
+                            array_unshift($args, "<img src='" . $match[1] . "' />");
576
+                            $srcover_filter = call_user_func_array($filtre, $args);
577
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
578
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
579
+                        }
580
+                    }
581
+                    $texte = str_replace($tag[3], $reduit, $texte);
582
+                }
583
+                array_shift($args);
584
+            }
585
+        }
586
+    }
587
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
588
+    return $texte;
589 589
 }
590 590
 
591 591
 /**
@@ -600,77 +600,77 @@  discard block
 block discarded – undo
600 600
  **/
601 601
 function taille_image($img, $force_refresh = false) {
602 602
 
603
-	static $largeur_img = array(), $hauteur_img = array();
604
-	$srcWidth = 0;
605
-	$srcHeight = 0;
606
-
607
-	$src = extraire_attribut($img, 'src');
608
-
609
-	if (!$src) {
610
-		$src = $img;
611
-	} else {
612
-		$srcWidth = extraire_attribut($img, 'width');
613
-		$srcHeight = extraire_attribut($img, 'height');
614
-	}
615
-
616
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
617
-	// la copie locale a toutes les chances d'etre la ou de resservir
618
-	if (tester_url_absolue($src)) {
619
-		include_spip('inc/distant');
620
-		$fichier = copie_locale($src);
621
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
622
-	}
623
-	if (($p = strpos($src, '?')) !== false) {
624
-		$src = substr($src, 0, $p);
625
-	}
626
-
627
-	$srcsize = false;
628
-	if (isset($largeur_img[$src]) and !$force_refresh) {
629
-		$srcWidth = $largeur_img[$src];
630
-	}
631
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
632
-		$srcHeight = $hauteur_img[$src];
633
-	}
634
-	if (!$srcWidth or !$srcHeight) {
635
-
636
-		if (file_exists($src)
637
-			and $srcsize = spip_getimagesize($src)
638
-		) {
639
-			if (!$srcWidth) {
640
-				$largeur_img[$src] = $srcWidth = $srcsize[0];
641
-			}
642
-			if (!$srcHeight) {
643
-				$hauteur_img[$src] = $srcHeight = $srcsize[1];
644
-			}
645
-		}
646
-		elseif(strpos($src, "<svg") !== false) {
647
-			include_spip('inc/svg');
648
-			if ($attrs = svg_lire_attributs($src)){
649
-				list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
650
-				if (!$srcWidth){
651
-					$largeur_img[$src] = $srcWidth = $width;
652
-				}
653
-				if (!$srcHeight){
654
-					$hauteur_img[$src] = $srcHeight = $height;
655
-				}
656
-			}
657
-		}
658
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
659
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
660
-		elseif (@file_exists($f = "$src.src")
661
-			and lire_fichier($f, $valeurs)
662
-			and $valeurs = unserialize($valeurs)
663
-		) {
664
-			if (!$srcWidth) {
665
-				$largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"];
666
-			}
667
-			if (!$srcHeight) {
668
-				$hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"];
669
-			}
670
-		}
671
-	}
672
-
673
-	return array($srcHeight, $srcWidth);
603
+    static $largeur_img = array(), $hauteur_img = array();
604
+    $srcWidth = 0;
605
+    $srcHeight = 0;
606
+
607
+    $src = extraire_attribut($img, 'src');
608
+
609
+    if (!$src) {
610
+        $src = $img;
611
+    } else {
612
+        $srcWidth = extraire_attribut($img, 'width');
613
+        $srcHeight = extraire_attribut($img, 'height');
614
+    }
615
+
616
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
617
+    // la copie locale a toutes les chances d'etre la ou de resservir
618
+    if (tester_url_absolue($src)) {
619
+        include_spip('inc/distant');
620
+        $fichier = copie_locale($src);
621
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
622
+    }
623
+    if (($p = strpos($src, '?')) !== false) {
624
+        $src = substr($src, 0, $p);
625
+    }
626
+
627
+    $srcsize = false;
628
+    if (isset($largeur_img[$src]) and !$force_refresh) {
629
+        $srcWidth = $largeur_img[$src];
630
+    }
631
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
632
+        $srcHeight = $hauteur_img[$src];
633
+    }
634
+    if (!$srcWidth or !$srcHeight) {
635
+
636
+        if (file_exists($src)
637
+            and $srcsize = spip_getimagesize($src)
638
+        ) {
639
+            if (!$srcWidth) {
640
+                $largeur_img[$src] = $srcWidth = $srcsize[0];
641
+            }
642
+            if (!$srcHeight) {
643
+                $hauteur_img[$src] = $srcHeight = $srcsize[1];
644
+            }
645
+        }
646
+        elseif(strpos($src, "<svg") !== false) {
647
+            include_spip('inc/svg');
648
+            if ($attrs = svg_lire_attributs($src)){
649
+                list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
650
+                if (!$srcWidth){
651
+                    $largeur_img[$src] = $srcWidth = $width;
652
+                }
653
+                if (!$srcHeight){
654
+                    $hauteur_img[$src] = $srcHeight = $height;
655
+                }
656
+            }
657
+        }
658
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
659
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
660
+        elseif (@file_exists($f = "$src.src")
661
+            and lire_fichier($f, $valeurs)
662
+            and $valeurs = unserialize($valeurs)
663
+        ) {
664
+            if (!$srcWidth) {
665
+                $largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"];
666
+            }
667
+            if (!$srcHeight) {
668
+                $hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"];
669
+            }
670
+        }
671
+    }
672
+
673
+    return array($srcHeight, $srcWidth);
674 674
 }
675 675
 
676 676
 
@@ -688,12 +688,12 @@  discard block
 block discarded – undo
688 688
  *     Largeur en pixels, NULL ou 0 si aucune image.
689 689
  **/
690 690
 function largeur($img) {
691
-	if (!$img) {
692
-		return;
693
-	}
694
-	list($h, $l) = taille_image($img);
691
+    if (!$img) {
692
+        return;
693
+    }
694
+    list($h, $l) = taille_image($img);
695 695
 
696
-	return $l;
696
+    return $l;
697 697
 }
698 698
 
699 699
 /**
@@ -710,12 +710,12 @@  discard block
 block discarded – undo
710 710
  *     Hauteur en pixels, NULL ou 0 si aucune image.
711 711
  **/
712 712
 function hauteur($img) {
713
-	if (!$img) {
714
-		return;
715
-	}
716
-	list($h, $l) = taille_image($img);
713
+    if (!$img) {
714
+        return;
715
+    }
716
+    list($h, $l) = taille_image($img);
717 717
 
718
-	return $h;
718
+    return $h;
719 719
 }
720 720
 
721 721
 
@@ -735,11 +735,11 @@  discard block
 block discarded – undo
735 735
  * @return string
736 736
  **/
737 737
 function corriger_entites_html($texte) {
738
-	if (strpos($texte, '&amp;') === false) {
739
-		return $texte;
740
-	}
738
+    if (strpos($texte, '&amp;') === false) {
739
+        return $texte;
740
+    }
741 741
 
742
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
742
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
743 743
 }
744 744
 
745 745
 /**
@@ -754,11 +754,11 @@  discard block
 block discarded – undo
754 754
  * @return string
755 755
  **/
756 756
 function corriger_toutes_entites_html($texte) {
757
-	if (strpos($texte, '&amp;') === false) {
758
-		return $texte;
759
-	}
757
+    if (strpos($texte, '&amp;') === false) {
758
+        return $texte;
759
+    }
760 760
 
761
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
761
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
762 762
 }
763 763
 
764 764
 /**
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
  * @return string
769 769
  **/
770 770
 function proteger_amp($texte) {
771
-	return str_replace('&', '&amp;', $texte);
771
+    return str_replace('&', '&amp;', $texte);
772 772
 }
773 773
 
774 774
 
@@ -799,20 +799,20 @@  discard block
 block discarded – undo
799 799
  * @return mixed|string
800 800
  */
801 801
 function entites_html($texte, $tout = false, $quote = true) {
802
-	if (!is_string($texte) or !$texte
803
-		or strpbrk($texte, "&\"'<>") == false
804
-	) {
805
-		return $texte;
806
-	}
807
-	include_spip('inc/texte');
808
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
809
-	$flags |= ENT_HTML401;
810
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
811
-	if ($tout) {
812
-		return corriger_toutes_entites_html($texte);
813
-	} else {
814
-		return corriger_entites_html($texte);
815
-	}
802
+    if (!is_string($texte) or !$texte
803
+        or strpbrk($texte, "&\"'<>") == false
804
+    ) {
805
+        return $texte;
806
+    }
807
+    include_spip('inc/texte');
808
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
809
+    $flags |= ENT_HTML401;
810
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
811
+    if ($tout) {
812
+        return corriger_toutes_entites_html($texte);
813
+    } else {
814
+        return corriger_entites_html($texte);
815
+    }
816 816
 }
817 817
 
818 818
 /**
@@ -831,37 +831,37 @@  discard block
 block discarded – undo
831 831
  *     Texte converti
832 832
  **/
833 833
 function filtrer_entites($texte) {
834
-	if (strpos($texte, '&') === false) {
835
-		return $texte;
836
-	}
837
-	// filtrer
838
-	$texte = html2unicode($texte);
839
-	// remettre le tout dans le charset cible
840
-	$texte = unicode2charset($texte);
841
-	// cas particulier des " et ' qu'il faut filtrer aussi
842
-	// (on le faisait deja avec un &quot;)
843
-	if (strpos($texte, "&#") !== false) {
844
-		$texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
845
-	}
834
+    if (strpos($texte, '&') === false) {
835
+        return $texte;
836
+    }
837
+    // filtrer
838
+    $texte = html2unicode($texte);
839
+    // remettre le tout dans le charset cible
840
+    $texte = unicode2charset($texte);
841
+    // cas particulier des " et ' qu'il faut filtrer aussi
842
+    // (on le faisait deja avec un &quot;)
843
+    if (strpos($texte, "&#") !== false) {
844
+        $texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
845
+    }
846 846
 
847
-	return $texte;
847
+    return $texte;
848 848
 }
849 849
 
850 850
 
851 851
 if (!function_exists('filtre_filtrer_entites_dist')) {
852
-	/**
853
-	 * Version sécurisée de filtrer_entites
854
-	 * 
855
-	 * @uses interdire_scripts()
856
-	 * @uses filtrer_entites()
857
-	 * 
858
-	 * @param string $t
859
-	 * @return string
860
-	 */
861
-	function filtre_filtrer_entites_dist($t) {
862
-		include_spip('inc/texte');
863
-		return interdire_scripts(filtrer_entites($t));
864
-	}
852
+    /**
853
+     * Version sécurisée de filtrer_entites
854
+     * 
855
+     * @uses interdire_scripts()
856
+     * @uses filtrer_entites()
857
+     * 
858
+     * @param string $t
859
+     * @return string
860
+     */
861
+    function filtre_filtrer_entites_dist($t) {
862
+        include_spip('inc/texte');
863
+        return interdire_scripts(filtrer_entites($t));
864
+    }
865 865
 }
866 866
 
867 867
 
@@ -876,18 +876,18 @@  discard block
 block discarded – undo
876 876
  * @return string|array
877 877
  **/
878 878
 function supprimer_caracteres_illegaux($texte) {
879
-	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";
880
-	static $to = null;
879
+    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";
880
+    static $to = null;
881 881
 
882
-	if (is_array($texte)) {
883
-		return array_map('supprimer_caracteres_illegaux', $texte);
884
-	}
882
+    if (is_array($texte)) {
883
+        return array_map('supprimer_caracteres_illegaux', $texte);
884
+    }
885 885
 
886
-	if (!$to) {
887
-		$to = str_repeat('-', strlen($from));
888
-	}
886
+    if (!$to) {
887
+        $to = str_repeat('-', strlen($from));
888
+    }
889 889
 
890
-	return strtr($texte, $from, $to);
890
+    return strtr($texte, $from, $to);
891 891
 }
892 892
 
893 893
 /**
@@ -899,10 +899,10 @@  discard block
 block discarded – undo
899 899
  * @return string|array
900 900
  **/
901 901
 function corriger_caracteres($texte) {
902
-	$texte = corriger_caracteres_windows($texte);
903
-	$texte = supprimer_caracteres_illegaux($texte);
902
+    $texte = corriger_caracteres_windows($texte);
903
+    $texte = supprimer_caracteres_illegaux($texte);
904 904
 
905
-	return $texte;
905
+    return $texte;
906 906
 }
907 907
 
908 908
 /**
@@ -920,40 +920,40 @@  discard block
 block discarded – undo
920 920
  */
921 921
 function texte_backend($texte) {
922 922
 
923
-	static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
923
+    static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
924 924
 
925
-	// si on a des liens ou des images, les passer en absolu
926
-	$texte = liens_absolus($texte);
925
+    // si on a des liens ou des images, les passer en absolu
926
+    $texte = liens_absolus($texte);
927 927
 
928
-	// echapper les tags &gt; &lt;
929
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
928
+    // echapper les tags &gt; &lt;
929
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
930 930
 
931
-	// importer les &eacute;
932
-	$texte = filtrer_entites($texte);
931
+    // importer les &eacute;
932
+    $texte = filtrer_entites($texte);
933 933
 
934
-	// " -> &quot; et tout ce genre de choses
935
-	$u = $GLOBALS['meta']['pcre_u'];
936
-	$texte = str_replace("&nbsp;", " ", $texte);
937
-	$texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
938
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
939
-	$texte = entites_html($texte, false, false);
940
-	// mais bien echapper les double quotes !
941
-	$texte = str_replace('"', '&#034;', $texte);
934
+    // " -> &quot; et tout ce genre de choses
935
+    $u = $GLOBALS['meta']['pcre_u'];
936
+    $texte = str_replace("&nbsp;", " ", $texte);
937
+    $texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
938
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
939
+    $texte = entites_html($texte, false, false);
940
+    // mais bien echapper les double quotes !
941
+    $texte = str_replace('"', '&#034;', $texte);
942 942
 
943
-	// verifier le charset
944
-	$texte = charset2unicode($texte);
943
+    // verifier le charset
944
+    $texte = charset2unicode($texte);
945 945
 
946
-	// Caracteres problematiques en iso-latin 1
947
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
948
-		$texte = str_replace(chr(156), '&#156;', $texte);
949
-		$texte = str_replace(chr(140), '&#140;', $texte);
950
-		$texte = str_replace(chr(159), '&#159;', $texte);
951
-	}
946
+    // Caracteres problematiques en iso-latin 1
947
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
948
+        $texte = str_replace(chr(156), '&#156;', $texte);
949
+        $texte = str_replace(chr(140), '&#140;', $texte);
950
+        $texte = str_replace(chr(159), '&#159;', $texte);
951
+    }
952 952
 
953
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
954
-	// et le caractere apostrophe alourdit les squelettes avec PHP
955
-	// ==> on les remplace par l'entite HTML
956
-	return str_replace($apostrophe, "'", $texte);
953
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
954
+    // et le caractere apostrophe alourdit les squelettes avec PHP
955
+    // ==> on les remplace par l'entite HTML
956
+    return str_replace($apostrophe, "'", $texte);
957 957
 }
958 958
 
959 959
 /**
@@ -970,7 +970,7 @@  discard block
 block discarded – undo
970 970
  *     Texte encodé et quote pour XML
971 971
  */
972 972
 function texte_backendq($texte) {
973
-	return addslashes(texte_backend($texte));
973
+    return addslashes(texte_backend($texte));
974 974
 }
975 975
 
976 976
 
@@ -993,9 +993,9 @@  discard block
 block discarded – undo
993 993
  *     Numéro de titre, sinon chaîne vide
994 994
  **/
995 995
 function supprimer_numero($texte) {
996
-	return preg_replace(
997
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
998
-		"", $texte);
996
+    return preg_replace(
997
+        ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
998
+        "", $texte);
999 999
 }
1000 1000
 
1001 1001
 /**
@@ -1018,13 +1018,13 @@  discard block
 block discarded – undo
1018 1018
  *     Numéro de titre, sinon chaîne vide
1019 1019
  **/
1020 1020
 function recuperer_numero($texte) {
1021
-	if (preg_match(
1022
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
1023
-		$texte, $regs)) {
1024
-		return strval($regs[1]);
1025
-	} else {
1026
-		return '';
1027
-	}
1021
+    if (preg_match(
1022
+        ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
1023
+        $texte, $regs)) {
1024
+        return strval($regs[1]);
1025
+    } else {
1026
+        return '';
1027
+    }
1028 1028
 }
1029 1029
 
1030 1030
 /**
@@ -1051,13 +1051,13 @@  discard block
 block discarded – undo
1051 1051
  *     Texte converti
1052 1052
  **/
1053 1053
 function supprimer_tags($texte, $rempl = "") {
1054
-	$texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte);
1055
-	// ne pas oublier un < final non ferme car coupe
1056
-	$texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte);
1057
-	// mais qui peut aussi etre un simple signe plus petit que
1058
-	$texte = str_replace('<', '&lt;', $texte);
1054
+    $texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte);
1055
+    // ne pas oublier un < final non ferme car coupe
1056
+    $texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte);
1057
+    // mais qui peut aussi etre un simple signe plus petit que
1058
+    $texte = str_replace('<', '&lt;', $texte);
1059 1059
 
1060
-	return $texte;
1060
+    return $texte;
1061 1061
 }
1062 1062
 
1063 1063
 /**
@@ -1080,9 +1080,9 @@  discard block
 block discarded – undo
1080 1080
  *     Texte converti
1081 1081
  **/
1082 1082
 function echapper_tags($texte, $rempl = "") {
1083
-	$texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
1083
+    $texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
1084 1084
 
1085
-	return $texte;
1085
+    return $texte;
1086 1086
 }
1087 1087
 
1088 1088
 /**
@@ -1103,18 +1103,18 @@  discard block
 block discarded – undo
1103 1103
  *     Texte converti
1104 1104
  **/
1105 1105
 function textebrut($texte) {
1106
-	$u = $GLOBALS['meta']['pcre_u'];
1107
-	$texte = preg_replace('/\s+/S' . $u, " ", $texte);
1108
-	$texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
1109
-	$texte = preg_replace("/^\n+/", "", $texte);
1110
-	$texte = preg_replace("/\n+$/", "", $texte);
1111
-	$texte = preg_replace("/\n +/", "\n", $texte);
1112
-	$texte = supprimer_tags($texte);
1113
-	$texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
1114
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1115
-	$texte = str_replace("&#8217;", "'", $texte);
1106
+    $u = $GLOBALS['meta']['pcre_u'];
1107
+    $texte = preg_replace('/\s+/S' . $u, " ", $texte);
1108
+    $texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
1109
+    $texte = preg_replace("/^\n+/", "", $texte);
1110
+    $texte = preg_replace("/\n+$/", "", $texte);
1111
+    $texte = preg_replace("/\n +/", "\n", $texte);
1112
+    $texte = supprimer_tags($texte);
1113
+    $texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
1114
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1115
+    $texte = str_replace("&#8217;", "'", $texte);
1116 1116
 
1117
-	return $texte;
1117
+    return $texte;
1118 1118
 }
1119 1119
 
1120 1120
 
@@ -1130,17 +1130,17 @@  discard block
 block discarded – undo
1130 1130
  *     Texte avec liens ouvrants
1131 1131
  **/
1132 1132
 function liens_ouvrants($texte) {
1133
-	if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1134
-		$texte, $liens, PREG_PATTERN_ORDER)) {
1135
-		foreach ($liens[0] as $a) {
1136
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1137
-			$ablank = inserer_attribut($a, 'rel', $rel);
1138
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1139
-			$texte = str_replace($a, $ablank, $texte);
1140
-		}
1141
-	}
1133
+    if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1134
+        $texte, $liens, PREG_PATTERN_ORDER)) {
1135
+        foreach ($liens[0] as $a) {
1136
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1137
+            $ablank = inserer_attribut($a, 'rel', $rel);
1138
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1139
+            $texte = str_replace($a, $ablank, $texte);
1140
+        }
1141
+    }
1142 1142
 
1143
-	return $texte;
1143
+    return $texte;
1144 1144
 }
1145 1145
 
1146 1146
 /**
@@ -1150,22 +1150,22 @@  discard block
 block discarded – undo
1150 1150
  * @return string
1151 1151
  */
1152 1152
 function liens_nofollow($texte) {
1153
-	if (stripos($texte, "<a") === false) {
1154
-		return $texte;
1155
-	}
1153
+    if (stripos($texte, "<a") === false) {
1154
+        return $texte;
1155
+    }
1156 1156
 
1157
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1158
-		foreach ($regs[0] as $a) {
1159
-			$rel = extraire_attribut($a, "rel");
1160
-			if (strpos($rel, "nofollow") === false) {
1161
-				$rel = "nofollow" . ($rel ? " $rel" : "");
1162
-				$anofollow = inserer_attribut($a, "rel", $rel);
1163
-				$texte = str_replace($a, $anofollow, $texte);
1164
-			}
1165
-		}
1166
-	}
1157
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1158
+        foreach ($regs[0] as $a) {
1159
+            $rel = extraire_attribut($a, "rel");
1160
+            if (strpos($rel, "nofollow") === false) {
1161
+                $rel = "nofollow" . ($rel ? " $rel" : "");
1162
+                $anofollow = inserer_attribut($a, "rel", $rel);
1163
+                $texte = str_replace($a, $anofollow, $texte);
1164
+            }
1165
+        }
1166
+    }
1167 1167
 
1168
-	return $texte;
1168
+    return $texte;
1169 1169
 }
1170 1170
 
1171 1171
 /**
@@ -1184,12 +1184,12 @@  discard block
 block discarded – undo
1184 1184
  *     Texte sans paraghaphes
1185 1185
  **/
1186 1186
 function PtoBR($texte) {
1187
-	$u = $GLOBALS['meta']['pcre_u'];
1188
-	$texte = preg_replace("@</p>@iS", "\n", $texte);
1189
-	$texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1190
-	$texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1187
+    $u = $GLOBALS['meta']['pcre_u'];
1188
+    $texte = preg_replace("@</p>@iS", "\n", $texte);
1189
+    $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1190
+    $texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1191 1191
 
1192
-	return $texte;
1192
+    return $texte;
1193 1193
 }
1194 1194
 
1195 1195
 
@@ -1213,14 +1213,14 @@  discard block
 block discarded – undo
1213 1213
  * @return string Texte encadré du style CSS
1214 1214
  */
1215 1215
 function lignes_longues($texte) {
1216
-	if (!strlen(trim($texte))) {
1217
-		return $texte;
1218
-	}
1219
-	include_spip('inc/texte');
1220
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1221
-		'div' : 'span';
1216
+    if (!strlen(trim($texte))) {
1217
+        return $texte;
1218
+    }
1219
+    include_spip('inc/texte');
1220
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1221
+        'div' : 'span';
1222 1222
 
1223
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1223
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1224 1224
 }
1225 1225
 
1226 1226
 /**
@@ -1239,30 +1239,30 @@  discard block
 block discarded – undo
1239 1239
  * @return string Texte en majuscule
1240 1240
  */
1241 1241
 function majuscules($texte) {
1242
-	if (!strlen($texte)) {
1243
-		return '';
1244
-	}
1242
+    if (!strlen($texte)) {
1243
+        return '';
1244
+    }
1245 1245
 
1246
-	// Cas du turc
1247
-	if ($GLOBALS['spip_lang'] == 'tr') {
1248
-		# remplacer hors des tags et des entites
1249
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1250
-			foreach ($regs as $n => $match) {
1251
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1252
-			}
1253
-		}
1246
+    // Cas du turc
1247
+    if ($GLOBALS['spip_lang'] == 'tr') {
1248
+        # remplacer hors des tags et des entites
1249
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1250
+            foreach ($regs as $n => $match) {
1251
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1252
+            }
1253
+        }
1254 1254
 
1255
-		$texte = str_replace('i', '&#304;', $texte);
1255
+        $texte = str_replace('i', '&#304;', $texte);
1256 1256
 
1257
-		if ($regs) {
1258
-			foreach ($regs as $n => $match) {
1259
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1260
-			}
1261
-		}
1262
-	}
1257
+        if ($regs) {
1258
+            foreach ($regs as $n => $match) {
1259
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1260
+            }
1261
+        }
1262
+    }
1263 1263
 
1264
-	// Cas general
1265
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1264
+    // Cas general
1265
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1266 1266
 }
1267 1267
 
1268 1268
 /**
@@ -1280,29 +1280,29 @@  discard block
 block discarded – undo
1280 1280
  * @return string
1281 1281
  **/
1282 1282
 function taille_en_octets($taille) {
1283
-	if (!defined('_KILOBYTE')) {
1284
-		/**
1285
-		 * Définit le nombre d'octets dans un Kilobyte
1286
-		 *
1287
-		 * @var int
1288
-		 **/
1289
-		define('_KILOBYTE', 1024);
1290
-	}
1283
+    if (!defined('_KILOBYTE')) {
1284
+        /**
1285
+         * Définit le nombre d'octets dans un Kilobyte
1286
+         *
1287
+         * @var int
1288
+         **/
1289
+        define('_KILOBYTE', 1024);
1290
+    }
1291 1291
 
1292
-	if ($taille < 1) {
1293
-		return '';
1294
-	}
1295
-	if ($taille < _KILOBYTE) {
1296
-		$taille = _T('taille_octets', array('taille' => $taille));
1297
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1298
-		$taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1)));
1299
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1300
-		$taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)));
1301
-	} else {
1302
-		$taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)));
1303
-	}
1292
+    if ($taille < 1) {
1293
+        return '';
1294
+    }
1295
+    if ($taille < _KILOBYTE) {
1296
+        $taille = _T('taille_octets', array('taille' => $taille));
1297
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1298
+        $taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1)));
1299
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1300
+        $taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)));
1301
+    } else {
1302
+        $taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)));
1303
+    }
1304 1304
 
1305
-	return $taille;
1305
+    return $taille;
1306 1306
 }
1307 1307
 
1308 1308
 
@@ -1324,15 +1324,15 @@  discard block
 block discarded – undo
1324 1324
  *     Texte prêt pour être utilisé en attribut HTML
1325 1325
  **/
1326 1326
 function attribut_html($texte, $textebrut = true) {
1327
-	$u = $GLOBALS['meta']['pcre_u'];
1328
-	if ($textebrut) {
1329
-		$texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1330
-	}
1331
-	$texte = texte_backend($texte);
1332
-	$texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
1327
+    $u = $GLOBALS['meta']['pcre_u'];
1328
+    if ($textebrut) {
1329
+        $texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1330
+    }
1331
+    $texte = texte_backend($texte);
1332
+    $texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
1333 1333
 
1334
-	return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"),
1335
-		$texte);
1334
+    return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"),
1335
+        $texte);
1336 1336
 }
1337 1337
 
1338 1338
 
@@ -1352,12 +1352,12 @@  discard block
 block discarded – undo
1352 1352
  *     URL ou chaîne vide
1353 1353
  **/
1354 1354
 function vider_url($url, $entites = true) {
1355
-	# un message pour abs_url
1356
-	$GLOBALS['mode_abs_url'] = 'url';
1357
-	$url = trim($url);
1358
-	$r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1355
+    # un message pour abs_url
1356
+    $GLOBALS['mode_abs_url'] = 'url';
1357
+    $url = trim($url);
1358
+    $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1359 1359
 
1360
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1360
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1361 1361
 }
1362 1362
 
1363 1363
 
@@ -1372,10 +1372,10 @@  discard block
 block discarded – undo
1372 1372
  * @return string Adresse email maquillée
1373 1373
  **/
1374 1374
 function antispam($texte) {
1375
-	include_spip('inc/acces');
1376
-	$masque = creer_pass_aleatoire(3);
1375
+    include_spip('inc/acces');
1376
+    $masque = creer_pass_aleatoire(3);
1377 1377
 
1378
-	return preg_replace("/@/", " $masque ", $texte);
1378
+    return preg_replace("/@/", " $masque ", $texte);
1379 1379
 }
1380 1380
 
1381 1381
 /**
@@ -1407,12 +1407,12 @@  discard block
 block discarded – undo
1407 1407
  *     True si on a le droit d'accès, false sinon.
1408 1408
  **/
1409 1409
 function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') {
1410
-	include_spip('inc/acces');
1411
-	if ($op) {
1412
-		$dir .= " $op $args";
1413
-	}
1410
+    include_spip('inc/acces');
1411
+    if ($op) {
1412
+        $dir .= " $op $args";
1413
+    }
1414 1414
 
1415
-	return verifier_low_sec($id_auteur, $cle, $dir);
1415
+    return verifier_low_sec($id_auteur, $cle, $dir);
1416 1416
 }
1417 1417
 
1418 1418
 /**
@@ -1437,11 +1437,11 @@  discard block
 block discarded – undo
1437 1437
  *     Retourne $texte, sinon $sinon.
1438 1438
  **/
1439 1439
 function sinon($texte, $sinon = '') {
1440
-	if ($texte or (!is_array($texte) and strlen($texte))) {
1441
-		return $texte;
1442
-	} else {
1443
-		return $sinon;
1444
-	}
1440
+    if ($texte or (!is_array($texte) and strlen($texte))) {
1441
+        return $texte;
1442
+    } else {
1443
+        return $sinon;
1444
+    }
1445 1445
 }
1446 1446
 
1447 1447
 /**
@@ -1465,7 +1465,7 @@  discard block
 block discarded – undo
1465 1465
  * @return mixed
1466 1466
  **/
1467 1467
 function choixsivide($a, $vide, $pasvide) {
1468
-	return $a ? $pasvide : $vide;
1468
+    return $a ? $pasvide : $vide;
1469 1469
 }
1470 1470
 
1471 1471
 /**
@@ -1489,7 +1489,7 @@  discard block
 block discarded – undo
1489 1489
  * @return mixed
1490 1490
  **/
1491 1491
 function choixsiegal($a1, $a2, $v, $f) {
1492
-	return ($a1 == $a2) ? $v : $f;
1492
+    return ($a1 == $a2) ? $v : $f;
1493 1493
 }
1494 1494
 
1495 1495
 //
@@ -1508,13 +1508,13 @@  discard block
 block discarded – undo
1508 1508
  * @return string
1509 1509
  **/
1510 1510
 function filtrer_ical($texte) {
1511
-	#include_spip('inc/charsets');
1512
-	$texte = html2unicode($texte);
1513
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1514
-	$texte = preg_replace("/\n/", " ", $texte);
1515
-	$texte = preg_replace("/,/", "\,", $texte);
1511
+    #include_spip('inc/charsets');
1512
+    $texte = html2unicode($texte);
1513
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1514
+    $texte = preg_replace("/\n/", " ", $texte);
1515
+    $texte = preg_replace("/,/", "\,", $texte);
1516 1516
 
1517
-	return $texte;
1517
+    return $texte;
1518 1518
 }
1519 1519
 
1520 1520
 
@@ -1539,53 +1539,53 @@  discard block
 block discarded – undo
1539 1539
  * @return string
1540 1540
  **/
1541 1541
 function post_autobr($texte, $delim = "\n_ ") {
1542
-	if (!function_exists('echappe_html')) {
1543
-		include_spip('inc/texte_mini');
1544
-	}
1545
-	$texte = str_replace("\r\n", "\r", $texte);
1546
-	$texte = str_replace("\r", "\n", $texte);
1547
-
1548
-	if (preg_match(",\n+$,", $texte, $fin)) {
1549
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1550
-	} else {
1551
-		$fin = '';
1552
-	}
1553
-
1554
-	$texte = echappe_html($texte, '', true);
1555
-
1556
-	// echapper les modeles
1557
-	if (strpos($texte, "<") !== false) {
1558
-		include_spip('inc/lien');
1559
-		if (defined('_PREG_MODELE')) {
1560
-			$preg_modeles = "@" . _PREG_MODELE . "@imsS";
1561
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1562
-		}
1563
-	}
1564
-
1565
-	$debut = '';
1566
-	$suite = $texte;
1567
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1568
-		$debut .= substr($suite, 0, $t - 1);
1569
-		$suite = substr($suite, $t);
1570
-		$car = substr($suite, 0, 1);
1571
-		if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}")
1572
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1573
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1574
-		) {
1575
-			$debut .= $delim;
1576
-		} else {
1577
-			$debut .= "\n";
1578
-		}
1579
-		if (preg_match(",^\n+,", $suite, $regs)) {
1580
-			$debut .= $regs[0];
1581
-			$suite = substr($suite, strlen($regs[0]));
1582
-		}
1583
-	}
1584
-	$texte = $debut . $suite;
1585
-
1586
-	$texte = echappe_retour($texte);
1587
-
1588
-	return $texte . $fin;
1542
+    if (!function_exists('echappe_html')) {
1543
+        include_spip('inc/texte_mini');
1544
+    }
1545
+    $texte = str_replace("\r\n", "\r", $texte);
1546
+    $texte = str_replace("\r", "\n", $texte);
1547
+
1548
+    if (preg_match(",\n+$,", $texte, $fin)) {
1549
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1550
+    } else {
1551
+        $fin = '';
1552
+    }
1553
+
1554
+    $texte = echappe_html($texte, '', true);
1555
+
1556
+    // echapper les modeles
1557
+    if (strpos($texte, "<") !== false) {
1558
+        include_spip('inc/lien');
1559
+        if (defined('_PREG_MODELE')) {
1560
+            $preg_modeles = "@" . _PREG_MODELE . "@imsS";
1561
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1562
+        }
1563
+    }
1564
+
1565
+    $debut = '';
1566
+    $suite = $texte;
1567
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1568
+        $debut .= substr($suite, 0, $t - 1);
1569
+        $suite = substr($suite, $t);
1570
+        $car = substr($suite, 0, 1);
1571
+        if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}")
1572
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1573
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1574
+        ) {
1575
+            $debut .= $delim;
1576
+        } else {
1577
+            $debut .= "\n";
1578
+        }
1579
+        if (preg_match(",^\n+,", $suite, $regs)) {
1580
+            $debut .= $regs[0];
1581
+            $suite = substr($suite, strlen($regs[0]));
1582
+        }
1583
+    }
1584
+    $texte = $debut . $suite;
1585
+
1586
+    $texte = echappe_retour($texte);
1587
+
1588
+    return $texte . $fin;
1589 1589
 }
1590 1590
 
1591 1591
 
@@ -1626,46 +1626,46 @@  discard block
 block discarded – undo
1626 1626
  * @return string
1627 1627
  **/
1628 1628
 function extraire_idiome($letexte, $lang = null, $options = array()) {
1629
-	static $traduire = false;
1630
-	if ($letexte
1631
-		and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1632
-	) {
1633
-		if (!$traduire) {
1634
-			$traduire = charger_fonction('traduire', 'inc');
1635
-			include_spip('inc/lang');
1636
-		}
1637
-		if (!$lang) {
1638
-			$lang = $GLOBALS['spip_lang'];
1639
-		}
1640
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1641
-		if (is_bool($options)) {
1642
-			$options = array('echappe_span' => $options);
1643
-		}
1644
-		if (!isset($options['echappe_span'])) {
1645
-			$options = array_merge($options, array('echappe_span' => false));
1646
-		}
1647
-
1648
-		foreach ($regs as $reg) {
1649
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1650
-			$desc = $traduire($cle, $lang, true);
1651
-			$l = $desc->langue;
1652
-			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1653
-			if (strlen($desc->texte)) {
1654
-				$trad = code_echappement($desc->texte, 'idiome', false);
1655
-				if ($l !== $lang) {
1656
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1657
-				}
1658
-				if (lang_dir($l) !== lang_dir($lang)) {
1659
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1660
-				}
1661
-				if (!$options['echappe_span']) {
1662
-					$trad = echappe_retour($trad, 'idiome');
1663
-				}
1664
-				$letexte = str_replace($reg[0], $trad, $letexte);
1665
-			}
1666
-		}
1667
-	}
1668
-	return $letexte;
1629
+    static $traduire = false;
1630
+    if ($letexte
1631
+        and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1632
+    ) {
1633
+        if (!$traduire) {
1634
+            $traduire = charger_fonction('traduire', 'inc');
1635
+            include_spip('inc/lang');
1636
+        }
1637
+        if (!$lang) {
1638
+            $lang = $GLOBALS['spip_lang'];
1639
+        }
1640
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1641
+        if (is_bool($options)) {
1642
+            $options = array('echappe_span' => $options);
1643
+        }
1644
+        if (!isset($options['echappe_span'])) {
1645
+            $options = array_merge($options, array('echappe_span' => false));
1646
+        }
1647
+
1648
+        foreach ($regs as $reg) {
1649
+            $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1650
+            $desc = $traduire($cle, $lang, true);
1651
+            $l = $desc->langue;
1652
+            // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1653
+            if (strlen($desc->texte)) {
1654
+                $trad = code_echappement($desc->texte, 'idiome', false);
1655
+                if ($l !== $lang) {
1656
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1657
+                }
1658
+                if (lang_dir($l) !== lang_dir($lang)) {
1659
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1660
+                }
1661
+                if (!$options['echappe_span']) {
1662
+                    $trad = echappe_retour($trad, 'idiome');
1663
+                }
1664
+                $letexte = str_replace($reg[0], $trad, $letexte);
1665
+            }
1666
+        }
1667
+    }
1668
+    return $letexte;
1669 1669
 }
1670 1670
 
1671 1671
 /**
@@ -1717,67 +1717,67 @@  discard block
 block discarded – undo
1717 1717
  **/
1718 1718
 function extraire_multi($letexte, $lang = null, $options = array()) {
1719 1719
 
1720
-	if ($letexte
1721
-		and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1722
-	) {
1723
-		if (!$lang) {
1724
-			$lang = $GLOBALS['spip_lang'];
1725
-		}
1726
-
1727
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1728
-		if (is_bool($options)) {
1729
-			$options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
1730
-		}
1731
-		if (!isset($options['echappe_span'])) {
1732
-			$options = array_merge($options, array('echappe_span' => false));
1733
-		}
1734
-		if (!isset($options['lang_defaut'])) {
1735
-			$options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
1736
-		}
1737
-
1738
-		include_spip('inc/lang');
1739
-		foreach ($regs as $reg) {
1740
-			// chercher la version de la langue courante
1741
-			$trads = extraire_trads($reg[1]);
1742
-			if ($l = approcher_langue($trads, $lang)) {
1743
-				$trad = $trads[$l];
1744
-			} else {
1745
-				if ($options['lang_defaut'] == 'aucune') {
1746
-					$trad = '';
1747
-				} else {
1748
-					// langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1749
-					// ou la premiere dispo
1750
-					// mais typographier le texte selon les regles de celle-ci
1751
-					// Attention aux blocs multi sur plusieurs lignes
1752
-					if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1753
-						$l = key($trads);
1754
-					}
1755
-					$trad = $trads[$l];
1756
-					$typographie = charger_fonction(lang_typo($l), 'typographie');
1757
-					$trad = $typographie($trad);
1758
-					// Tester si on echappe en span ou en div
1759
-					// il ne faut pas echapper en div si propre produit un seul paragraphe
1760
-					include_spip('inc/texte');
1761
-					$trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1762
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1763
-					if ($mode === 'div') {
1764
-						$trad = rtrim($trad) . "\n\n";
1765
-					}
1766
-					$trad = code_echappement($trad, 'multi', false, $mode);
1767
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1768
-					if (lang_dir($l) !== lang_dir($lang)) {
1769
-						$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1770
-					}
1771
-					if (!$options['echappe_span']) {
1772
-						$trad = echappe_retour($trad, 'multi');
1773
-					}
1774
-				}
1775
-			}
1776
-			$letexte = str_replace($reg[0], $trad, $letexte);
1777
-		}
1778
-	}
1779
-
1780
-	return $letexte;
1720
+    if ($letexte
1721
+        and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1722
+    ) {
1723
+        if (!$lang) {
1724
+            $lang = $GLOBALS['spip_lang'];
1725
+        }
1726
+
1727
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1728
+        if (is_bool($options)) {
1729
+            $options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
1730
+        }
1731
+        if (!isset($options['echappe_span'])) {
1732
+            $options = array_merge($options, array('echappe_span' => false));
1733
+        }
1734
+        if (!isset($options['lang_defaut'])) {
1735
+            $options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
1736
+        }
1737
+
1738
+        include_spip('inc/lang');
1739
+        foreach ($regs as $reg) {
1740
+            // chercher la version de la langue courante
1741
+            $trads = extraire_trads($reg[1]);
1742
+            if ($l = approcher_langue($trads, $lang)) {
1743
+                $trad = $trads[$l];
1744
+            } else {
1745
+                if ($options['lang_defaut'] == 'aucune') {
1746
+                    $trad = '';
1747
+                } else {
1748
+                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1749
+                    // ou la premiere dispo
1750
+                    // mais typographier le texte selon les regles de celle-ci
1751
+                    // Attention aux blocs multi sur plusieurs lignes
1752
+                    if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1753
+                        $l = key($trads);
1754
+                    }
1755
+                    $trad = $trads[$l];
1756
+                    $typographie = charger_fonction(lang_typo($l), 'typographie');
1757
+                    $trad = $typographie($trad);
1758
+                    // Tester si on echappe en span ou en div
1759
+                    // il ne faut pas echapper en div si propre produit un seul paragraphe
1760
+                    include_spip('inc/texte');
1761
+                    $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1762
+                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1763
+                    if ($mode === 'div') {
1764
+                        $trad = rtrim($trad) . "\n\n";
1765
+                    }
1766
+                    $trad = code_echappement($trad, 'multi', false, $mode);
1767
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1768
+                    if (lang_dir($l) !== lang_dir($lang)) {
1769
+                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1770
+                    }
1771
+                    if (!$options['echappe_span']) {
1772
+                        $trad = echappe_retour($trad, 'multi');
1773
+                    }
1774
+                }
1775
+            }
1776
+            $letexte = str_replace($reg[0], $trad, $letexte);
1777
+        }
1778
+    }
1779
+
1780
+    return $letexte;
1781 1781
 }
1782 1782
 
1783 1783
 /**
@@ -1793,20 +1793,20 @@  discard block
 block discarded – undo
1793 1793
  *     Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué.
1794 1794
  **/
1795 1795
 function extraire_trads($bloc) {
1796
-	$lang = '';
1796
+    $lang = '';
1797 1797
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1798 1798
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1799
-	while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1800
-		$texte = trim($regs[1]);
1801
-		if ($texte or $lang) {
1802
-			$trads[$lang] = $texte;
1803
-		}
1804
-		$bloc = substr($bloc, strlen($regs[0]));
1805
-		$lang = $regs[2];
1806
-	}
1807
-	$trads[$lang] = $bloc;
1799
+    while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1800
+        $texte = trim($regs[1]);
1801
+        if ($texte or $lang) {
1802
+            $trads[$lang] = $texte;
1803
+        }
1804
+        $bloc = substr($bloc, strlen($regs[0]));
1805
+        $lang = $regs[2];
1806
+    }
1807
+    $trads[$lang] = $bloc;
1808 1808
 
1809
-	return $trads;
1809
+    return $trads;
1810 1810
 }
1811 1811
 
1812 1812
 
@@ -1817,7 +1817,7 @@  discard block
 block discarded – undo
1817 1817
  * @return string L'initiale en majuscule
1818 1818
  */
1819 1819
 function filtre_initiale($nom) {
1820
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1820
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1821 1821
 }
1822 1822
 
1823 1823
 
@@ -1862,33 +1862,33 @@  discard block
 block discarded – undo
1862 1862
  *      - null (interne) : si on empile
1863 1863
  **/
1864 1864
 function unique($donnee, $famille = '', $cpt = false) {
1865
-	static $mem = array();
1866
-	// permettre de vider la pile et de la restaurer
1867
-	// pour le calcul de introduction...
1868
-	if ($famille == '_spip_raz_') {
1869
-		$tmp = $mem;
1870
-		$mem = array();
1871
-
1872
-		return $tmp;
1873
-	} elseif ($famille == '_spip_set_') {
1874
-		$mem = $donnee;
1875
-
1876
-		return;
1877
-	}
1878
-	// eviter une notice
1879
-	if (!isset($mem[$famille])) {
1880
-		$mem[$famille] = array();
1881
-	}
1882
-	if ($cpt) {
1883
-		return count($mem[$famille]);
1884
-	}
1885
-	// eviter une notice
1886
-	if (!isset($mem[$famille][$donnee])) {
1887
-		$mem[$famille][$donnee] = 0;
1888
-	}
1889
-	if (!($mem[$famille][$donnee]++)) {
1890
-		return $donnee;
1891
-	}
1865
+    static $mem = array();
1866
+    // permettre de vider la pile et de la restaurer
1867
+    // pour le calcul de introduction...
1868
+    if ($famille == '_spip_raz_') {
1869
+        $tmp = $mem;
1870
+        $mem = array();
1871
+
1872
+        return $tmp;
1873
+    } elseif ($famille == '_spip_set_') {
1874
+        $mem = $donnee;
1875
+
1876
+        return;
1877
+    }
1878
+    // eviter une notice
1879
+    if (!isset($mem[$famille])) {
1880
+        $mem[$famille] = array();
1881
+    }
1882
+    if ($cpt) {
1883
+        return count($mem[$famille]);
1884
+    }
1885
+    // eviter une notice
1886
+    if (!isset($mem[$famille][$donnee])) {
1887
+        $mem[$famille][$donnee] = 0;
1888
+    }
1889
+    if (!($mem[$famille][$donnee]++)) {
1890
+        return $donnee;
1891
+    }
1892 1892
 }
1893 1893
 
1894 1894
 
@@ -1916,18 +1916,18 @@  discard block
 block discarded – undo
1916 1916
  *     Une des valeurs en fonction du compteur.
1917 1917
  **/
1918 1918
 function alterner($i) {
1919
-	// recuperer les arguments (attention fonctions un peu space)
1920
-	$num = func_num_args();
1921
-	$args = func_get_args();
1919
+    // recuperer les arguments (attention fonctions un peu space)
1920
+    $num = func_num_args();
1921
+    $args = func_get_args();
1922 1922
 
1923
-	if ($num == 2 && is_array($args[1])) {
1924
-		$args = $args[1];
1925
-		array_unshift($args, '');
1926
-		$num = count($args);
1927
-	}
1923
+    if ($num == 2 && is_array($args[1])) {
1924
+        $args = $args[1];
1925
+        array_unshift($args, '');
1926
+        $num = count($args);
1927
+    }
1928 1928
 
1929
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1930
-	return $args[(intval($i) - 1) % ($num - 1) + 1];
1929
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1930
+    return $args[(intval($i) - 1) % ($num - 1) + 1];
1931 1931
 }
1932 1932
 
1933 1933
 
@@ -1952,46 +1952,46 @@  discard block
 block discarded – undo
1952 1952
  *     - Tableau complet (si 2e argument)
1953 1953
  **/
1954 1954
 function extraire_attribut($balise, $attribut, $complet = false) {
1955
-	if (is_array($balise)) {
1956
-		array_walk(
1957
-			$balise,
1958
-			function(&$a, $key, $t){
1959
-				$a = extraire_attribut($a, $t);
1960
-			},
1961
-			$attribut
1962
-		);
1963
-
1964
-		return $balise;
1965
-	}
1966
-	if (preg_match(
1967
-		',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1968
-		. $attribut
1969
-		. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1970
-
1971
-		$balise, $r)) {
1972
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1973
-			$r[4] = substr($r[3], 1, -1);
1974
-			$r[3] = $r[3][0];
1975
-		} elseif ($r[3] !== '') {
1976
-			$r[4] = $r[3];
1977
-			$r[3] = '';
1978
-		} else {
1979
-			$r[4] = trim($r[2]);
1980
-		}
1981
-		$att = $r[4];
1982
-		if (strpos($att, "&#") !== false) {
1983
-			$att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1984
-		}
1985
-		$att = filtrer_entites($att);
1986
-	} else {
1987
-		$att = null;
1988
-	}
1989
-
1990
-	if ($complet) {
1991
-		return array($att, $r);
1992
-	} else {
1993
-		return $att;
1994
-	}
1955
+    if (is_array($balise)) {
1956
+        array_walk(
1957
+            $balise,
1958
+            function(&$a, $key, $t){
1959
+                $a = extraire_attribut($a, $t);
1960
+            },
1961
+            $attribut
1962
+        );
1963
+
1964
+        return $balise;
1965
+    }
1966
+    if (preg_match(
1967
+        ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1968
+        . $attribut
1969
+        . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1970
+
1971
+        $balise, $r)) {
1972
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1973
+            $r[4] = substr($r[3], 1, -1);
1974
+            $r[3] = $r[3][0];
1975
+        } elseif ($r[3] !== '') {
1976
+            $r[4] = $r[3];
1977
+            $r[3] = '';
1978
+        } else {
1979
+            $r[4] = trim($r[2]);
1980
+        }
1981
+        $att = $r[4];
1982
+        if (strpos($att, "&#") !== false) {
1983
+            $att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1984
+        }
1985
+        $att = filtrer_entites($att);
1986
+    } else {
1987
+        $att = null;
1988
+    }
1989
+
1990
+    if ($complet) {
1991
+        return array($att, $r);
1992
+    } else {
1993
+        return $att;
1994
+    }
1995 1995
 }
1996 1996
 
1997 1997
 /**
@@ -2023,37 +2023,37 @@  discard block
 block discarded – undo
2023 2023
  *     Code html modifié
2024 2024
  **/
2025 2025
 function inserer_attribut($balise, $attribut, $val, $proteger = true, $vider = false) {
2026
-	// preparer l'attribut
2027
-	// supprimer les &nbsp; etc mais pas les balises html
2028
-	// qui ont un sens dans un attribut value d'un input
2029
-	if ($proteger) {
2030
-		$val = attribut_html($val, false);
2031
-	}
2032
-
2033
-	// echapper les ' pour eviter tout bug
2034
-	$val = str_replace("'", "&#039;", $val);
2035
-	if ($vider and strlen($val) == 0) {
2036
-		$insert = '';
2037
-	} else {
2038
-		$insert = " $attribut='$val'";
2039
-	}
2040
-
2041
-	list($old, $r) = extraire_attribut($balise, $attribut, true);
2042
-
2043
-	if ($old !== null) {
2044
-		// Remplacer l'ancien attribut du meme nom
2045
-		$balise = $r[1] . $insert . $r[5];
2046
-	} else {
2047
-		// preferer une balise " />" (comme <img />)
2048
-		if (preg_match(',/>,', $balise)) {
2049
-			$balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
2050
-		} // sinon une balise <a ...> ... </a>
2051
-		else {
2052
-			$balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
2053
-		}
2054
-	}
2055
-
2056
-	return $balise;
2026
+    // preparer l'attribut
2027
+    // supprimer les &nbsp; etc mais pas les balises html
2028
+    // qui ont un sens dans un attribut value d'un input
2029
+    if ($proteger) {
2030
+        $val = attribut_html($val, false);
2031
+    }
2032
+
2033
+    // echapper les ' pour eviter tout bug
2034
+    $val = str_replace("'", "&#039;", $val);
2035
+    if ($vider and strlen($val) == 0) {
2036
+        $insert = '';
2037
+    } else {
2038
+        $insert = " $attribut='$val'";
2039
+    }
2040
+
2041
+    list($old, $r) = extraire_attribut($balise, $attribut, true);
2042
+
2043
+    if ($old !== null) {
2044
+        // Remplacer l'ancien attribut du meme nom
2045
+        $balise = $r[1] . $insert . $r[5];
2046
+    } else {
2047
+        // preferer une balise " />" (comme <img />)
2048
+        if (preg_match(',/>,', $balise)) {
2049
+            $balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
2050
+        } // sinon une balise <a ...> ... </a>
2051
+        else {
2052
+            $balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
2053
+        }
2054
+    }
2055
+
2056
+    return $balise;
2057 2057
 }
2058 2058
 
2059 2059
 /**
@@ -2071,7 +2071,7 @@  discard block
 block discarded – undo
2071 2071
  * @return string Code HTML sans l'attribut
2072 2072
  **/
2073 2073
 function vider_attribut($balise, $attribut) {
2074
-	return inserer_attribut($balise, $attribut, '', false, true);
2074
+    return inserer_attribut($balise, $attribut, '', false, true);
2075 2075
 }
2076 2076
 
2077 2077
 /**
@@ -2083,50 +2083,50 @@  discard block
 block discarded – undo
2083 2083
  * @return string
2084 2084
  */
2085 2085
 function modifier_class($balise, $class, $operation='ajouter') {
2086
-	if (is_string($class)) {
2087
-		$class = explode(' ', trim($class));
2088
-	}
2089
-	$class = array_filter($class);
2090
-
2091
-	// si la ou les classes ont des caracteres invalides on ne fait rien
2092
-	if (preg_match(",[^\w-],", implode('', $class))) {
2093
-		return $balise;
2094
-	}
2095
-
2096
-	if ($class) {
2097
-		$class = array_unique($class);
2098
-		$class_courante = extraire_attribut($balise, 'class');
2099
-
2100
-		$class_new = $class_courante;
2101
-		foreach ($class as $c) {
2102
-			if ($c) {
2103
-				$is_class_presente = false;
2104
-				if (strpos($class_courante, $c) !== false
2105
-					and preg_match("/(^|\s)".preg_quote($c)."($|\s)/", $class_courante)) {
2106
-					$is_class_presente = true;
2107
-				}
2108
-				if (in_array($operation, ['ajouter', 'commuter'])
2109
-					and !$is_class_presente) {
2110
-					$class_new = rtrim($class_new) . " " . $c;
2111
-				}
2112
-				elseif (in_array($operation, ['supprimer', 'commuter'])
2113
-					and $is_class_presente) {
2114
-					$class_new = trim(preg_replace("/(^|\s)".preg_quote($c)."($|\s)/", "\\1", $class_new));
2115
-				}
2116
-			}
2117
-		}
2118
-
2119
-		if ($class_new !== $class_courante) {
2120
-			if (strlen($class_new)) {
2121
-				$balise = inserer_attribut($balise, 'class', $class_new);
2122
-			}
2123
-			elseif ($class_courante) {
2124
-				$balise = vider_attribut($balise, 'class');
2125
-			}
2126
-		}
2127
-	}
2128
-
2129
-	return $balise;
2086
+    if (is_string($class)) {
2087
+        $class = explode(' ', trim($class));
2088
+    }
2089
+    $class = array_filter($class);
2090
+
2091
+    // si la ou les classes ont des caracteres invalides on ne fait rien
2092
+    if (preg_match(",[^\w-],", implode('', $class))) {
2093
+        return $balise;
2094
+    }
2095
+
2096
+    if ($class) {
2097
+        $class = array_unique($class);
2098
+        $class_courante = extraire_attribut($balise, 'class');
2099
+
2100
+        $class_new = $class_courante;
2101
+        foreach ($class as $c) {
2102
+            if ($c) {
2103
+                $is_class_presente = false;
2104
+                if (strpos($class_courante, $c) !== false
2105
+                    and preg_match("/(^|\s)".preg_quote($c)."($|\s)/", $class_courante)) {
2106
+                    $is_class_presente = true;
2107
+                }
2108
+                if (in_array($operation, ['ajouter', 'commuter'])
2109
+                    and !$is_class_presente) {
2110
+                    $class_new = rtrim($class_new) . " " . $c;
2111
+                }
2112
+                elseif (in_array($operation, ['supprimer', 'commuter'])
2113
+                    and $is_class_presente) {
2114
+                    $class_new = trim(preg_replace("/(^|\s)".preg_quote($c)."($|\s)/", "\\1", $class_new));
2115
+                }
2116
+            }
2117
+        }
2118
+
2119
+        if ($class_new !== $class_courante) {
2120
+            if (strlen($class_new)) {
2121
+                $balise = inserer_attribut($balise, 'class', $class_new);
2122
+            }
2123
+            elseif ($class_courante) {
2124
+                $balise = vider_attribut($balise, 'class');
2125
+            }
2126
+        }
2127
+    }
2128
+
2129
+    return $balise;
2130 2130
 }
2131 2131
 
2132 2132
 /**
@@ -2136,7 +2136,7 @@  discard block
 block discarded – undo
2136 2136
  * @return string
2137 2137
  */
2138 2138
 function ajouter_class($balise, $class){
2139
-	return modifier_class($balise, $class, 'ajouter');
2139
+    return modifier_class($balise, $class, 'ajouter');
2140 2140
 }
2141 2141
 
2142 2142
 /**
@@ -2146,7 +2146,7 @@  discard block
 block discarded – undo
2146 2146
  * @return string
2147 2147
  */
2148 2148
 function supprimer_class($balise, $class){
2149
-	return modifier_class($balise, $class, 'supprimer');
2149
+    return modifier_class($balise, $class, 'supprimer');
2150 2150
 }
2151 2151
 
2152 2152
 /**
@@ -2157,7 +2157,7 @@  discard block
 block discarded – undo
2157 2157
  * @return string
2158 2158
  */
2159 2159
 function commuter_class($balise, $class){
2160
-	return modifier_class($balise, $class, 'commuter');
2160
+    return modifier_class($balise, $class, 'commuter');
2161 2161
 }
2162 2162
 
2163 2163
 /**
@@ -2168,9 +2168,9 @@  discard block
 block discarded – undo
2168 2168
  * @return string
2169 2169
  */
2170 2170
 function tester_config($id, $mode = '') {
2171
-	include_spip('action/inscrire_auteur');
2171
+    include_spip('action/inscrire_auteur');
2172 2172
 
2173
-	return tester_statut_inscription($mode, $id);
2173
+    return tester_statut_inscription($mode, $id);
2174 2174
 }
2175 2175
 
2176 2176
 //
@@ -2195,7 +2195,7 @@  discard block
 block discarded – undo
2195 2195
  * @return int $a+$b
2196 2196
  **/
2197 2197
 function plus($a, $b) {
2198
-	return $a + $b;
2198
+    return $a + $b;
2199 2199
 }
2200 2200
 function strplus($a, $b) {return strize('plus', $a, $b);}
2201 2201
 /**
@@ -2214,7 +2214,7 @@  discard block
 block discarded – undo
2214 2214
  * @return int $a-$b
2215 2215
  **/
2216 2216
 function moins($a, $b) {
2217
-	return $a - $b;
2217
+    return $a - $b;
2218 2218
 }
2219 2219
 function strmoins($a, $b) {return strize('moins', $a, $b);}
2220 2220
 
@@ -2235,7 +2235,7 @@  discard block
 block discarded – undo
2235 2235
  * @return int $a*$b
2236 2236
  **/
2237 2237
 function mult($a, $b) {
2238
-	return $a * $b;
2238
+    return $a * $b;
2239 2239
 }
2240 2240
 function strmult($a, $b) {return strize('mult', $a, $b);}
2241 2241
 
@@ -2256,7 +2256,7 @@  discard block
 block discarded – undo
2256 2256
  * @return int $a/$b (ou 0 si $b est nul)
2257 2257
  **/
2258 2258
 function div($a, $b) {
2259
-	return $b ? $a / $b : 0;
2259
+    return $b ? $a / $b : 0;
2260 2260
 }
2261 2261
 function strdiv($a, $b) {return strize('div', $a, $b);}
2262 2262
 
@@ -2278,7 +2278,7 @@  discard block
 block discarded – undo
2278 2278
  * @return int ($nb % $mod) + $add
2279 2279
  **/
2280 2280
 function modulo($nb, $mod, $add = 0) {
2281
-	return ($mod ? $nb % $mod : 0) + $add;
2281
+    return ($mod ? $nb % $mod : 0) + $add;
2282 2282
 }
2283 2283
 
2284 2284
 
@@ -2293,24 +2293,24 @@  discard block
 block discarded – undo
2293 2293
  *      - true sinon
2294 2294
  **/
2295 2295
 function nom_acceptable($nom) {
2296
-	if (!is_string($nom)) {
2297
-		return false;
2298
-	}
2299
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2300
-		define('_TAGS_NOM_AUTEUR', '');
2301
-	}
2302
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2303
-	foreach ($tags_acceptes as $tag) {
2304
-		if (strlen($tag)) {
2305
-			$remp1[] = '<' . trim($tag) . '>';
2306
-			$remp1[] = '</' . trim($tag) . '>';
2307
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2308
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2309
-		}
2310
-	}
2311
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2296
+    if (!is_string($nom)) {
2297
+        return false;
2298
+    }
2299
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2300
+        define('_TAGS_NOM_AUTEUR', '');
2301
+    }
2302
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2303
+    foreach ($tags_acceptes as $tag) {
2304
+        if (strlen($tag)) {
2305
+            $remp1[] = '<' . trim($tag) . '>';
2306
+            $remp1[] = '</' . trim($tag) . '>';
2307
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2308
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2309
+        }
2310
+    }
2311
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2312 2312
 
2313
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2313
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2314 2314
 }
2315 2315
 
2316 2316
 
@@ -2326,14 +2326,14 @@  discard block
 block discarded – undo
2326 2326
  *      - renvoie un tableau si l'entree est un tableau
2327 2327
  **/
2328 2328
 function email_valide($adresses) {
2329
-	if (is_array($adresses)) {
2330
-		$adresses = array_map('email_valide', $adresses);
2331
-		$adresses = array_filter($adresses);
2332
-		return $adresses;
2333
-	}
2329
+    if (is_array($adresses)) {
2330
+        $adresses = array_map('email_valide', $adresses);
2331
+        $adresses = array_filter($adresses);
2332
+        return $adresses;
2333
+    }
2334 2334
 
2335
-	$email_valide = charger_fonction('email_valide', 'inc');
2336
-	return $email_valide($adresses);
2335
+    $email_valide = charger_fonction('email_valide', 'inc');
2336
+    return $email_valide($adresses);
2337 2337
 }
2338 2338
 
2339 2339
 /**
@@ -2347,20 +2347,20 @@  discard block
 block discarded – undo
2347 2347
  * @return string Texte
2348 2348
  **/
2349 2349
 function afficher_enclosures($tags) {
2350
-	$s = array();
2351
-	foreach (extraire_balises($tags, 'a') as $tag) {
2352
-		if (extraire_attribut($tag, 'rel') == 'enclosure'
2353
-			and $t = extraire_attribut($tag, 'href')
2354
-		) {
2355
-			$s[] = preg_replace(',>[^<]+</a>,S',
2356
-				'>'
2357
-				. http_img_pack('attachment-16.png', $t,
2358
-					'title="' . attribut_html($t) . '"')
2359
-				. '</a>', $tag);
2360
-		}
2361
-	}
2350
+    $s = array();
2351
+    foreach (extraire_balises($tags, 'a') as $tag) {
2352
+        if (extraire_attribut($tag, 'rel') == 'enclosure'
2353
+            and $t = extraire_attribut($tag, 'href')
2354
+        ) {
2355
+            $s[] = preg_replace(',>[^<]+</a>,S',
2356
+                '>'
2357
+                . http_img_pack('attachment-16.png', $t,
2358
+                    'title="' . attribut_html($t) . '"')
2359
+                . '</a>', $tag);
2360
+        }
2361
+    }
2362 2362
 
2363
-	return join('&nbsp;', $s);
2363
+    return join('&nbsp;', $s);
2364 2364
 }
2365 2365
 
2366 2366
 /**
@@ -2375,15 +2375,15 @@  discard block
 block discarded – undo
2375 2375
  * @return string Liens trouvés
2376 2376
  **/
2377 2377
 function afficher_tags($tags, $rels = 'tag,directory') {
2378
-	$s = array();
2379
-	foreach (extraire_balises($tags, 'a') as $tag) {
2380
-		$rel = extraire_attribut($tag, 'rel');
2381
-		if (strstr(",$rels,", ",$rel,")) {
2382
-			$s[] = $tag;
2383
-		}
2384
-	}
2378
+    $s = array();
2379
+    foreach (extraire_balises($tags, 'a') as $tag) {
2380
+        $rel = extraire_attribut($tag, 'rel');
2381
+        if (strstr(",$rels,", ",$rel,")) {
2382
+            $s[] = $tag;
2383
+        }
2384
+    }
2385 2385
 
2386
-	return join(', ', $s);
2386
+    return join(', ', $s);
2387 2387
 }
2388 2388
 
2389 2389
 
@@ -2405,21 +2405,21 @@  discard block
 block discarded – undo
2405 2405
  * @return string Tag HTML `<a>` avec microformat.
2406 2406
  **/
2407 2407
 function enclosure2microformat($e) {
2408
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2409
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2410
-	}
2411
-	$type = extraire_attribut($e, 'type');
2412
-	if (!$length = extraire_attribut($e, 'length')) {
2413
-		# <media:content : longeur dans fileSize. On tente.
2414
-		$length = extraire_attribut($e, 'fileSize');
2415
-	}
2416
-	$fichier = basename($url);
2408
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2409
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2410
+    }
2411
+    $type = extraire_attribut($e, 'type');
2412
+    if (!$length = extraire_attribut($e, 'length')) {
2413
+        # <media:content : longeur dans fileSize. On tente.
2414
+        $length = extraire_attribut($e, 'fileSize');
2415
+    }
2416
+    $fichier = basename($url);
2417 2417
 
2418
-	return '<a rel="enclosure"'
2419
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2420
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2421
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2422
-	. '>' . $fichier . '</a>';
2418
+    return '<a rel="enclosure"'
2419
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2420
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2421
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2422
+    . '>' . $fichier . '</a>';
2423 2423
 }
2424 2424
 
2425 2425
 /**
@@ -2437,24 +2437,24 @@  discard block
 block discarded – undo
2437 2437
  * @return string Tags RSS `<enclosure>`.
2438 2438
  **/
2439 2439
 function microformat2enclosure($tags) {
2440
-	$enclosures = array();
2441
-	foreach (extraire_balises($tags, 'a') as $e) {
2442
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2443
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2444
-			$type = extraire_attribut($e, 'type');
2445
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2446
-				$length = intval(extraire_attribut($e, 'length'));
2447
-			} # vieux data
2448
-			$fichier = basename($url);
2449
-			$enclosures[] = '<enclosure'
2450
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2451
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2452
-				. ($length ? ' length="' . $length . '"' : '')
2453
-				. ' />';
2454
-		}
2455
-	}
2440
+    $enclosures = array();
2441
+    foreach (extraire_balises($tags, 'a') as $e) {
2442
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2443
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2444
+            $type = extraire_attribut($e, 'type');
2445
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2446
+                $length = intval(extraire_attribut($e, 'length'));
2447
+            } # vieux data
2448
+            $fichier = basename($url);
2449
+            $enclosures[] = '<enclosure'
2450
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2451
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2452
+                . ($length ? ' length="' . $length . '"' : '')
2453
+                . ' />';
2454
+        }
2455
+    }
2456 2456
 
2457
-	return join("\n", $enclosures);
2457
+    return join("\n", $enclosures);
2458 2458
 }
2459 2459
 
2460 2460
 
@@ -2470,16 +2470,16 @@  discard block
 block discarded – undo
2470 2470
  * @return string Tags RSS Atom `<dc:subject>`.
2471 2471
  **/
2472 2472
 function tags2dcsubject($tags) {
2473
-	$subjects = '';
2474
-	foreach (extraire_balises($tags, 'a') as $e) {
2475
-		if (extraire_attribut($e, 'rel') == 'tag') {
2476
-			$subjects .= '<dc:subject>'
2477
-				. texte_backend(textebrut($e))
2478
-				. '</dc:subject>' . "\n";
2479
-		}
2480
-	}
2473
+    $subjects = '';
2474
+    foreach (extraire_balises($tags, 'a') as $e) {
2475
+        if (extraire_attribut($e, 'rel') == 'tag') {
2476
+            $subjects .= '<dc:subject>'
2477
+                . texte_backend(textebrut($e))
2478
+                . '</dc:subject>' . "\n";
2479
+        }
2480
+    }
2481 2481
 
2482
-	return $subjects;
2482
+    return $subjects;
2483 2483
 }
2484 2484
 
2485 2485
 /**
@@ -2508,23 +2508,23 @@  discard block
 block discarded – undo
2508 2508
  *     - Tableau de résultats, si tableau en entrée.
2509 2509
  **/
2510 2510
 function extraire_balise($texte, $tag = 'a') {
2511
-	if (is_array($texte)) {
2512
-		array_walk(
2513
-			$texte,
2514
-			function(&$a, $key, $t){
2515
-				$a = extraire_balise($a, $t);
2516
-			},
2517
-			$tag
2518
-		);
2511
+    if (is_array($texte)) {
2512
+        array_walk(
2513
+            $texte,
2514
+            function(&$a, $key, $t){
2515
+                $a = extraire_balise($a, $t);
2516
+            },
2517
+            $tag
2518
+        );
2519 2519
 
2520
-		return $texte;
2521
-	}
2520
+        return $texte;
2521
+    }
2522 2522
 
2523
-	if (preg_match(
2524
-		",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2525
-		$texte, $regs)) {
2526
-		return $regs[0];
2527
-	}
2523
+    if (preg_match(
2524
+        ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2525
+        $texte, $regs)) {
2526
+        return $regs[0];
2527
+    }
2528 2528
 }
2529 2529
 
2530 2530
 /**
@@ -2552,25 +2552,25 @@  discard block
 block discarded – undo
2552 2552
  *     - Tableau de résultats, si tableau en entrée.
2553 2553
  **/
2554 2554
 function extraire_balises($texte, $tag = 'a') {
2555
-	if (is_array($texte)) {
2556
-		array_walk(
2557
-			$texte,
2558
-			function(&$a, $key, $t){
2559
-				$a = extraire_balises($a, $t);
2560
-			},
2561
-			$tag
2562
-		);
2555
+    if (is_array($texte)) {
2556
+        array_walk(
2557
+            $texte,
2558
+            function(&$a, $key, $t){
2559
+                $a = extraire_balises($a, $t);
2560
+            },
2561
+            $tag
2562
+        );
2563 2563
 
2564
-		return $texte;
2565
-	}
2564
+        return $texte;
2565
+    }
2566 2566
 
2567
-	if (preg_match_all(
2568
-		",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2569
-		$texte, $regs, PREG_PATTERN_ORDER)) {
2570
-		return $regs[0];
2571
-	} else {
2572
-		return array();
2573
-	}
2567
+    if (preg_match_all(
2568
+        ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2569
+        $texte, $regs, PREG_PATTERN_ORDER)) {
2570
+        return $regs[0];
2571
+    } else {
2572
+        return array();
2573
+    }
2574 2574
 }
2575 2575
 
2576 2576
 /**
@@ -2599,11 +2599,11 @@  discard block
 block discarded – undo
2599 2599
  *     - `$def` si on n'a pas transmis de tableau
2600 2600
  **/
2601 2601
 function in_any($val, $vals, $def = '') {
2602
-	if (!is_array($vals) and $v = unserialize($vals)) {
2603
-		$vals = $v;
2604
-	}
2602
+    if (!is_array($vals) and $v = unserialize($vals)) {
2603
+        $vals = $v;
2604
+    }
2605 2605
 
2606
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2606
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2607 2607
 }
2608 2608
 
2609 2609
 
@@ -2624,12 +2624,12 @@  discard block
 block discarded – undo
2624 2624
  *     Résultat du calcul
2625 2625
  **/
2626 2626
 function valeur_numerique($expr) {
2627
-	$a = 0;
2628
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2629
-		eval("\$a = $expr;");
2630
-	}
2627
+    $a = 0;
2628
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2629
+        eval("\$a = $expr;");
2630
+    }
2631 2631
 
2632
-	return intval($a);
2632
+    return intval($a);
2633 2633
 }
2634 2634
 
2635 2635
 /**
@@ -2648,7 +2648,7 @@  discard block
 block discarded – undo
2648 2648
  *      Retourne `$a*$b/$c`
2649 2649
  **/
2650 2650
 function regledetrois($a, $b, $c) {
2651
-	return round($a * $b / $c);
2651
+    return round($a * $b / $c);
2652 2652
 }
2653 2653
 
2654 2654
 
@@ -2672,76 +2672,76 @@  discard block
 block discarded – undo
2672 2672
  **/
2673 2673
 function form_hidden($action) {
2674 2674
 
2675
-	$contexte = array();
2676
-	include_spip('inc/urls');
2677
-	if ($p = urls_decoder_url($action, '')
2678
-		and reset($p)
2679
-	) {
2680
-		$fond = array_shift($p);
2681
-		if ($fond != '404') {
2682
-			$contexte = array_shift($p);
2683
-			$contexte['page'] = $fond;
2684
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2685
-		}
2686
-	}
2687
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2688
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2689
-		unset($contexte['type']);
2690
-	}
2691
-	if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) {
2692
-		unset($contexte['type-page']);
2693
-	}
2694
-
2695
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2696
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2697
-	$values = array();
2698
-
2699
-	// d'abord avec celles de l'url
2700
-	if (false !== ($p = strpos($action, '?'))) {
2701
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2702
-			$c = explode('=', $c, 2);
2703
-			$var = array_shift($c);
2704
-			$val = array_shift($c);
2705
-			if ($var) {
2706
-				$val = rawurldecode($val);
2707
-				$var = rawurldecode($var); // decoder les [] eventuels
2708
-				if (preg_match(',\[\]$,S', $var)) {
2709
-					$values[] = array($var, $val);
2710
-				} else {
2711
-					if (!isset($values[$var])) {
2712
-						$values[$var] = array($var, $val);
2713
-					}
2714
-				}
2715
-			}
2716
-		}
2717
-	}
2718
-
2719
-	// ensuite avec celles du contexte, sans doublonner !
2720
-	foreach ($contexte as $var => $val) {
2721
-		if (preg_match(',\[\]$,S', $var)) {
2722
-			$values[] = array($var, $val);
2723
-		} else {
2724
-			if (!isset($values[$var])) {
2725
-				$values[$var] = array($var, $val);
2726
-			}
2727
-		}
2728
-	}
2729
-
2730
-	// puis on rassemble le tout
2731
-	$hidden = array();
2732
-	foreach ($values as $value) {
2733
-		list($var, $val) = $value;
2734
-		$hidden[] = '<input name="'
2735
-			. entites_html($var)
2736
-			. '"'
2737
-			. (is_null($val)
2738
-				? ''
2739
-				: ' value="' . entites_html($val) . '"'
2740
-			)
2741
-			. ' type="hidden"' . "\n/>";
2742
-	}
2743
-
2744
-	return join("", $hidden);
2675
+    $contexte = array();
2676
+    include_spip('inc/urls');
2677
+    if ($p = urls_decoder_url($action, '')
2678
+        and reset($p)
2679
+    ) {
2680
+        $fond = array_shift($p);
2681
+        if ($fond != '404') {
2682
+            $contexte = array_shift($p);
2683
+            $contexte['page'] = $fond;
2684
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2685
+        }
2686
+    }
2687
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2688
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2689
+        unset($contexte['type']);
2690
+    }
2691
+    if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) {
2692
+        unset($contexte['type-page']);
2693
+    }
2694
+
2695
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2696
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2697
+    $values = array();
2698
+
2699
+    // d'abord avec celles de l'url
2700
+    if (false !== ($p = strpos($action, '?'))) {
2701
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2702
+            $c = explode('=', $c, 2);
2703
+            $var = array_shift($c);
2704
+            $val = array_shift($c);
2705
+            if ($var) {
2706
+                $val = rawurldecode($val);
2707
+                $var = rawurldecode($var); // decoder les [] eventuels
2708
+                if (preg_match(',\[\]$,S', $var)) {
2709
+                    $values[] = array($var, $val);
2710
+                } else {
2711
+                    if (!isset($values[$var])) {
2712
+                        $values[$var] = array($var, $val);
2713
+                    }
2714
+                }
2715
+            }
2716
+        }
2717
+    }
2718
+
2719
+    // ensuite avec celles du contexte, sans doublonner !
2720
+    foreach ($contexte as $var => $val) {
2721
+        if (preg_match(',\[\]$,S', $var)) {
2722
+            $values[] = array($var, $val);
2723
+        } else {
2724
+            if (!isset($values[$var])) {
2725
+                $values[$var] = array($var, $val);
2726
+            }
2727
+        }
2728
+    }
2729
+
2730
+    // puis on rassemble le tout
2731
+    $hidden = array();
2732
+    foreach ($values as $value) {
2733
+        list($var, $val) = $value;
2734
+        $hidden[] = '<input name="'
2735
+            . entites_html($var)
2736
+            . '"'
2737
+            . (is_null($val)
2738
+                ? ''
2739
+                : ' value="' . entites_html($val) . '"'
2740
+            )
2741
+            . ' type="hidden"' . "\n/>";
2742
+    }
2743
+
2744
+    return join("", $hidden);
2745 2745
 }
2746 2746
 
2747 2747
 
@@ -2763,7 +2763,7 @@  discard block
 block discarded – undo
2763 2763
  *    - la première valeur du tableau sinon.
2764 2764
  **/
2765 2765
 function filtre_reset($array) {
2766
-	return !is_array($array) ? null : reset($array);
2766
+    return !is_array($array) ? null : reset($array);
2767 2767
 }
2768 2768
 
2769 2769
 /**
@@ -2784,7 +2784,7 @@  discard block
 block discarded – undo
2784 2784
  *    - la dernière valeur du tableau sinon.
2785 2785
  **/
2786 2786
 function filtre_end($array) {
2787
-	return !is_array($array) ? null : end($array);
2787
+    return !is_array($array) ? null : end($array);
2788 2788
 }
2789 2789
 
2790 2790
 /**
@@ -2804,11 +2804,11 @@  discard block
 block discarded – undo
2804 2804
  *
2805 2805
  **/
2806 2806
 function filtre_push($array, $val) {
2807
-	if (!is_array($array) or !array_push($array, $val)) {
2808
-		return '';
2809
-	}
2807
+    if (!is_array($array) or !array_push($array, $val)) {
2808
+        return '';
2809
+    }
2810 2810
 
2811
-	return $array;
2811
+    return $array;
2812 2812
 }
2813 2813
 
2814 2814
 /**
@@ -2827,7 +2827,7 @@  discard block
 block discarded – undo
2827 2827
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2828 2828
  **/
2829 2829
 function filtre_find($array, $val) {
2830
-	return (is_array($array) and in_array($val, $array));
2830
+    return (is_array($array) and in_array($val, $array));
2831 2831
 }
2832 2832
 
2833 2833
 
@@ -2844,15 +2844,15 @@  discard block
 block discarded – undo
2844 2844
  *     Contenu avec urls en absolus
2845 2845
  **/
2846 2846
 function urls_absolues_css($contenu, $source) {
2847
-	$path = suivre_lien(url_absolue($source), './');
2847
+    $path = suivre_lien(url_absolue($source), './');
2848 2848
 
2849
-	return preg_replace_callback(
2850
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2851
-		function($x) use ($path) {
2852
-			return "url('" . suivre_lien($path, $x[1]) . "')";
2853
-		},
2854
-		$contenu
2855
-	);
2849
+    return preg_replace_callback(
2850
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2851
+        function($x) use ($path) {
2852
+            return "url('" . suivre_lien($path, $x[1]) . "')";
2853
+        },
2854
+        $contenu
2855
+    );
2856 2856
 }
2857 2857
 
2858 2858
 
@@ -2881,118 +2881,118 @@  discard block
 block discarded – undo
2881 2881
  *     Chemin du fichier CSS inversé
2882 2882
  **/
2883 2883
 function direction_css($css, $voulue = '') {
2884
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2885
-		return $css;
2886
-	}
2887
-
2888
-	// si on a precise le sens voulu en argument, le prendre en compte
2889
-	if ($voulue = strtolower($voulue)) {
2890
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2891
-			$voulue = lang_dir($voulue);
2892
-		}
2893
-	} else {
2894
-		$voulue = lang_dir();
2895
-	}
2896
-
2897
-	$r = count($r) > 1;
2898
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2899
-	$dir = $r ? 'rtl' : 'ltr';
2900
-	$ndir = $r ? 'ltr' : 'rtl';
2901
-
2902
-	if ($voulue == $dir) {
2903
-		return $css;
2904
-	}
2905
-
2906
-	if (
2907
-		// url absolue
2908
-		preg_match(",^https?:,i", $css)
2909
-		// ou qui contient un ?
2910
-		or (($p = strpos($css, '?')) !== false)
2911
-	) {
2912
-		$distant = true;
2913
-		$cssf = parse_url($css);
2914
-		$cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2915
-		$cssf = preg_replace(',[?:&=],', "_", $cssf);
2916
-	} else {
2917
-		$distant = false;
2918
-		$cssf = $css;
2919
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2920
-		//propose (rien a faire dans ce cas)
2921
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2922
-		if (@file_exists($f)) {
2923
-			return $f;
2924
-		}
2925
-	}
2926
-
2927
-	// 2.
2928
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2929
-	$f = $dir_var
2930
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2931
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2932
-
2933
-	// la css peut etre distante (url absolue !)
2934
-	if ($distant) {
2935
-		include_spip('inc/distant');
2936
-		$res = recuperer_url($css);
2937
-		if (!$res or !$contenu = $res['page']) {
2938
-			return $css;
2939
-		}
2940
-	} else {
2941
-		if ((@filemtime($f) > @filemtime($css))
2942
-			and (_VAR_MODE != 'recalcul')
2943
-		) {
2944
-			return $f;
2945
-		}
2946
-		if (!lire_fichier($css, $contenu)) {
2947
-			return $css;
2948
-		}
2949
-	}
2950
-
2951
-
2952
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2953
-	include_spip("lib/csstidy/class.csstidy");
2954
-	$parser = new csstidy();
2955
-	$parser->set_cfg('optimise_shorthands', 0);
2956
-	$parser->set_cfg('reverse_left_and_right', true);
2957
-	$parser->parse($contenu);
2958
-
2959
-	$contenu = $parser->print->plain();
2960
-
2961
-
2962
-	// reperer les @import auxquels il faut propager le direction_css
2963
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2964
-	$src = array();
2965
-	$src_direction_css = array();
2966
-	$src_faux_abs = array();
2967
-	$d = dirname($css);
2968
-	foreach ($regs[1] as $k => $import_css) {
2969
-		$css_direction = direction_css("$d/$import_css", $voulue);
2970
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2971
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2972
-			$css_direction = substr($css_direction, strlen($d) + 1);
2973
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2974
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2975
-			$css_direction = substr($css_direction, strlen($dir_var));
2976
-			$src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2977
-			$css_direction = "/@@@@@@/" . $css_direction;
2978
-		}
2979
-		$src[] = $regs[0][$k];
2980
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2981
-	}
2982
-	$contenu = str_replace($src, $src_direction_css, $contenu);
2983
-
2984
-	$contenu = urls_absolues_css($contenu, $css);
2985
-
2986
-	// virer les fausses url absolues que l'on a mis dans les import
2987
-	if (count($src_faux_abs)) {
2988
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2989
-	}
2990
-
2991
-	if (!ecrire_fichier($f, $contenu)) {
2992
-		return $css;
2993
-	}
2994
-
2995
-	return $f;
2884
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2885
+        return $css;
2886
+    }
2887
+
2888
+    // si on a precise le sens voulu en argument, le prendre en compte
2889
+    if ($voulue = strtolower($voulue)) {
2890
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2891
+            $voulue = lang_dir($voulue);
2892
+        }
2893
+    } else {
2894
+        $voulue = lang_dir();
2895
+    }
2896
+
2897
+    $r = count($r) > 1;
2898
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2899
+    $dir = $r ? 'rtl' : 'ltr';
2900
+    $ndir = $r ? 'ltr' : 'rtl';
2901
+
2902
+    if ($voulue == $dir) {
2903
+        return $css;
2904
+    }
2905
+
2906
+    if (
2907
+        // url absolue
2908
+        preg_match(",^https?:,i", $css)
2909
+        // ou qui contient un ?
2910
+        or (($p = strpos($css, '?')) !== false)
2911
+    ) {
2912
+        $distant = true;
2913
+        $cssf = parse_url($css);
2914
+        $cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2915
+        $cssf = preg_replace(',[?:&=],', "_", $cssf);
2916
+    } else {
2917
+        $distant = false;
2918
+        $cssf = $css;
2919
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2920
+        //propose (rien a faire dans ce cas)
2921
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2922
+        if (@file_exists($f)) {
2923
+            return $f;
2924
+        }
2925
+    }
2926
+
2927
+    // 2.
2928
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2929
+    $f = $dir_var
2930
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2931
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2932
+
2933
+    // la css peut etre distante (url absolue !)
2934
+    if ($distant) {
2935
+        include_spip('inc/distant');
2936
+        $res = recuperer_url($css);
2937
+        if (!$res or !$contenu = $res['page']) {
2938
+            return $css;
2939
+        }
2940
+    } else {
2941
+        if ((@filemtime($f) > @filemtime($css))
2942
+            and (_VAR_MODE != 'recalcul')
2943
+        ) {
2944
+            return $f;
2945
+        }
2946
+        if (!lire_fichier($css, $contenu)) {
2947
+            return $css;
2948
+        }
2949
+    }
2950
+
2951
+
2952
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2953
+    include_spip("lib/csstidy/class.csstidy");
2954
+    $parser = new csstidy();
2955
+    $parser->set_cfg('optimise_shorthands', 0);
2956
+    $parser->set_cfg('reverse_left_and_right', true);
2957
+    $parser->parse($contenu);
2958
+
2959
+    $contenu = $parser->print->plain();
2960
+
2961
+
2962
+    // reperer les @import auxquels il faut propager le direction_css
2963
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2964
+    $src = array();
2965
+    $src_direction_css = array();
2966
+    $src_faux_abs = array();
2967
+    $d = dirname($css);
2968
+    foreach ($regs[1] as $k => $import_css) {
2969
+        $css_direction = direction_css("$d/$import_css", $voulue);
2970
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2971
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2972
+            $css_direction = substr($css_direction, strlen($d) + 1);
2973
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
2974
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2975
+            $css_direction = substr($css_direction, strlen($dir_var));
2976
+            $src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2977
+            $css_direction = "/@@@@@@/" . $css_direction;
2978
+        }
2979
+        $src[] = $regs[0][$k];
2980
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2981
+    }
2982
+    $contenu = str_replace($src, $src_direction_css, $contenu);
2983
+
2984
+    $contenu = urls_absolues_css($contenu, $css);
2985
+
2986
+    // virer les fausses url absolues que l'on a mis dans les import
2987
+    if (count($src_faux_abs)) {
2988
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2989
+    }
2990
+
2991
+    if (!ecrire_fichier($f, $contenu)) {
2992
+        return $css;
2993
+    }
2994
+
2995
+    return $f;
2996 2996
 }
2997 2997
 
2998 2998
 
@@ -3015,43 +3015,43 @@  discard block
 block discarded – undo
3015 3015
  *     - Chemin ou URL du fichier CSS source sinon.
3016 3016
  **/
3017 3017
 function url_absolue_css($css) {
3018
-	if (!preg_match(',\.css$,i', $css, $r)) {
3019
-		return $css;
3020
-	}
3018
+    if (!preg_match(',\.css$,i', $css, $r)) {
3019
+        return $css;
3020
+    }
3021 3021
 
3022
-	$url_absolue_css = url_absolue($css);
3022
+    $url_absolue_css = url_absolue($css);
3023 3023
 
3024
-	$f = basename($css, '.css');
3025
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3026
-		. preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3027
-		. '.css';
3024
+    $f = basename($css, '.css');
3025
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3026
+        . preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3027
+        . '.css';
3028 3028
 
3029
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3030
-		return $f;
3031
-	}
3029
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3030
+        return $f;
3031
+    }
3032 3032
 
3033
-	if ($url_absolue_css == $css) {
3034
-		if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3035
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3036
-		) {
3037
-			include_spip('inc/distant');
3038
-			if (!$contenu = recuperer_page($css)) {
3039
-				return $css;
3040
-			}
3041
-		}
3042
-	} elseif (!lire_fichier($css, $contenu)) {
3043
-		return $css;
3044
-	}
3033
+    if ($url_absolue_css == $css) {
3034
+        if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3035
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3036
+        ) {
3037
+            include_spip('inc/distant');
3038
+            if (!$contenu = recuperer_page($css)) {
3039
+                return $css;
3040
+            }
3041
+        }
3042
+    } elseif (!lire_fichier($css, $contenu)) {
3043
+        return $css;
3044
+    }
3045 3045
 
3046
-	// passer les url relatives a la css d'origine en url absolues
3047
-	$contenu = urls_absolues_css($contenu, $css);
3046
+    // passer les url relatives a la css d'origine en url absolues
3047
+    $contenu = urls_absolues_css($contenu, $css);
3048 3048
 
3049
-	// ecrire la css
3050
-	if (!ecrire_fichier($f, $contenu)) {
3051
-		return $css;
3052
-	}
3049
+    // ecrire la css
3050
+    if (!ecrire_fichier($f, $contenu)) {
3051
+        return $css;
3052
+    }
3053 3053
 
3054
-	return $f;
3054
+    return $f;
3055 3055
 }
3056 3056
 
3057 3057
 
@@ -3085,24 +3085,24 @@  discard block
 block discarded – undo
3085 3085
  *     Valeur trouvée ou valeur par défaut.
3086 3086
  **/
3087 3087
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3088
-	foreach (explode('/', $cle) as $k) {
3088
+    foreach (explode('/', $cle) as $k) {
3089 3089
 
3090
-		$table = is_string($table) ? @unserialize($table) : $table;
3090
+        $table = is_string($table) ? @unserialize($table) : $table;
3091 3091
 
3092
-		if (is_object($table)) {
3093
-			$table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
3094
-		} elseif (is_array($table)) {
3095
-			if ($conserver_null) {
3096
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3097
-			} else {
3098
-				$table = isset($table[$k]) ? $table[$k] : $defaut;
3099
-			}
3100
-		} else {
3101
-			$table = $defaut;
3102
-		}
3103
-	}
3092
+        if (is_object($table)) {
3093
+            $table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
3094
+        } elseif (is_array($table)) {
3095
+            if ($conserver_null) {
3096
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3097
+            } else {
3098
+                $table = isset($table[$k]) ? $table[$k] : $defaut;
3099
+            }
3100
+        } else {
3101
+            $table = $defaut;
3102
+        }
3103
+    }
3104 3104
 
3105
-	return $table;
3105
+    return $table;
3106 3106
 }
3107 3107
 
3108 3108
 /**
@@ -3135,22 +3135,22 @@  discard block
 block discarded – undo
3135 3135
  *     - string : expression trouvée.
3136 3136
  **/
3137 3137
 function filtre_match_dist($texte, $expression, $modif = "UimsS", $capte = 0) {
3138
-	if (intval($modif) and $capte == 0) {
3139
-		$capte = $modif;
3140
-		$modif = "UimsS";
3141
-	}
3142
-	$expression = str_replace("\/", "/", $expression);
3143
-	$expression = str_replace("/", "\/", $expression);
3138
+    if (intval($modif) and $capte == 0) {
3139
+        $capte = $modif;
3140
+        $modif = "UimsS";
3141
+    }
3142
+    $expression = str_replace("\/", "/", $expression);
3143
+    $expression = str_replace("/", "\/", $expression);
3144 3144
 
3145
-	if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3146
-		if (isset($r[$capte])) {
3147
-			return $r[$capte];
3148
-		} else {
3149
-			return true;
3150
-		}
3151
-	}
3145
+    if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3146
+        if (isset($r[$capte])) {
3147
+            return $r[$capte];
3148
+        } else {
3149
+            return true;
3150
+        }
3151
+    }
3152 3152
 
3153
-	return false;
3153
+    return false;
3154 3154
 }
3155 3155
 
3156 3156
 
@@ -3177,10 +3177,10 @@  discard block
 block discarded – undo
3177 3177
  *     Texte
3178 3178
  **/
3179 3179
 function replace($texte, $expression, $replace = '', $modif = "UimsS") {
3180
-	$expression = str_replace("\/", "/", $expression);
3181
-	$expression = str_replace("/", "\/", $expression);
3180
+    $expression = str_replace("\/", "/", $expression);
3181
+    $expression = str_replace("/", "\/", $expression);
3182 3182
 
3183
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3183
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3184 3184
 }
3185 3185
 
3186 3186
 
@@ -3198,21 +3198,21 @@  discard block
 block discarded – undo
3198 3198
  **/
3199 3199
 function traiter_doublons_documents(&$doublons, $letexte) {
3200 3200
 
3201
-	// Verifier dans le texte & les notes (pas beau, helas)
3202
-	$t = $letexte . $GLOBALS['les_notes'];
3201
+    // Verifier dans le texte & les notes (pas beau, helas)
3202
+    $t = $letexte . $GLOBALS['les_notes'];
3203 3203
 
3204
-	if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3205
-		and preg_match_all(
3206
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3207
-			$t, $matches, PREG_PATTERN_ORDER)
3208
-	) {
3209
-		if (!isset($doublons['documents'])) {
3210
-			$doublons['documents'] = "";
3211
-		}
3212
-		$doublons['documents'] .= "," . join(',', $matches[1]);
3213
-	}
3204
+    if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3205
+        and preg_match_all(
3206
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3207
+            $t, $matches, PREG_PATTERN_ORDER)
3208
+    ) {
3209
+        if (!isset($doublons['documents'])) {
3210
+            $doublons['documents'] = "";
3211
+        }
3212
+        $doublons['documents'] .= "," . join(',', $matches[1]);
3213
+    }
3214 3214
 
3215
-	return $letexte;
3215
+    return $letexte;
3216 3216
 }
3217 3217
 
3218 3218
 /**
@@ -3226,7 +3226,7 @@  discard block
 block discarded – undo
3226 3226
  * @return string Chaîne vide
3227 3227
  **/
3228 3228
 function vide($texte) {
3229
-	return "";
3229
+    return "";
3230 3230
 }
3231 3231
 
3232 3232
 //
@@ -3255,23 +3255,23 @@  discard block
 block discarded – undo
3255 3255
  *      Code HTML résultant
3256 3256
  **/
3257 3257
 function env_to_params($env, $ignore_params = array()) {
3258
-	$ignore_params = array_merge(
3259
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3260
-		$ignore_params
3261
-	);
3262
-	if (!is_array($env)) {
3263
-		$env = unserialize($env);
3264
-	}
3265
-	$texte = "";
3266
-	if ($env) {
3267
-		foreach ($env as $i => $j) {
3268
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3269
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3270
-			}
3271
-		}
3272
-	}
3273
-
3274
-	return $texte;
3258
+    $ignore_params = array_merge(
3259
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3260
+        $ignore_params
3261
+    );
3262
+    if (!is_array($env)) {
3263
+        $env = unserialize($env);
3264
+    }
3265
+    $texte = "";
3266
+    if ($env) {
3267
+        foreach ($env as $i => $j) {
3268
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3269
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3270
+            }
3271
+        }
3272
+    }
3273
+
3274
+    return $texte;
3275 3275
 }
3276 3276
 
3277 3277
 /**
@@ -3294,23 +3294,23 @@  discard block
 block discarded – undo
3294 3294
  *      Code HTML résultant
3295 3295
  **/
3296 3296
 function env_to_attributs($env, $ignore_params = array()) {
3297
-	$ignore_params = array_merge(
3298
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3299
-		$ignore_params
3300
-	);
3301
-	if (!is_array($env)) {
3302
-		$env = unserialize($env);
3303
-	}
3304
-	$texte = "";
3305
-	if ($env) {
3306
-		foreach ($env as $i => $j) {
3307
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3308
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3309
-			}
3310
-		}
3311
-	}
3297
+    $ignore_params = array_merge(
3298
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3299
+        $ignore_params
3300
+    );
3301
+    if (!is_array($env)) {
3302
+        $env = unserialize($env);
3303
+    }
3304
+    $texte = "";
3305
+    if ($env) {
3306
+        foreach ($env as $i => $j) {
3307
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3308
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3309
+            }
3310
+        }
3311
+    }
3312 3312
 
3313
-	return $texte;
3313
+    return $texte;
3314 3314
 }
3315 3315
 
3316 3316
 
@@ -3327,9 +3327,9 @@  discard block
 block discarded – undo
3327 3327
  * @return string Chaînes concaténés
3328 3328
  **/
3329 3329
 function concat() {
3330
-	$args = func_get_args();
3330
+    $args = func_get_args();
3331 3331
 
3332
-	return join('', $args);
3332
+    return join('', $args);
3333 3333
 }
3334 3334
 
3335 3335
 
@@ -3349,23 +3349,23 @@  discard block
 block discarded – undo
3349 3349
  *     Contenu du ou des fichiers, concaténé
3350 3350
  **/
3351 3351
 function charge_scripts($files, $script = true) {
3352
-	$flux = "";
3353
-	foreach (is_array($files) ? $files : explode("|", $files) as $file) {
3354
-		if (!is_string($file)) {
3355
-			continue;
3356
-		}
3357
-		if ($script) {
3358
-			$file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
3359
-		}
3360
-		if ($file) {
3361
-			$path = find_in_path($file);
3362
-			if ($path) {
3363
-				$flux .= spip_file_get_contents($path);
3364
-			}
3365
-		}
3366
-	}
3352
+    $flux = "";
3353
+    foreach (is_array($files) ? $files : explode("|", $files) as $file) {
3354
+        if (!is_string($file)) {
3355
+            continue;
3356
+        }
3357
+        if ($script) {
3358
+            $file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
3359
+        }
3360
+        if ($file) {
3361
+            $path = find_in_path($file);
3362
+            if ($path) {
3363
+                $flux .= spip_file_get_contents($path);
3364
+            }
3365
+        }
3366
+    }
3367 3367
 
3368
-	return $flux;
3368
+    return $flux;
3369 3369
 }
3370 3370
 
3371 3371
 
@@ -3387,64 +3387,64 @@  discard block
 block discarded – undo
3387 3387
  */
3388 3388
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = array()) {
3389 3389
 
3390
-	$img_file = $img;
3391
-	if ($p = strpos($img_file, '?')) {
3392
-		$img_file = substr($img_file,0, $p);
3393
-	}
3394
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3395
-		$img_file = chemin_image($img);
3396
-	}
3397
-	else {
3398
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3399
-			// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3400
-			// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3401
-			if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3402
-			  and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3403
-			  and file_exists($variante_svg_generique)) {
3404
-				if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3405
-					$img_file = $variante_svg_size;
3406
-				}
3407
-				else {
3408
-					$img_file = $variante_svg_generique;
3409
-				}
3410
-			}
3411
-		}
3412
-	}
3413
-	if (stripos($atts, 'width') === false) {
3414
-		// utiliser directement l'info de taille presente dans le nom
3415
-		if ((!isset($options['utiliser_suffixe_size'])
3416
-				or $options['utiliser_suffixe_size'] == true
3417
-			  or strpos($img_file, '-xx.svg') !== false)
3418
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3419
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3420
-		) {
3421
-			$largeur = $hauteur = intval($regs[1]);
3422
-		} else {
3423
-			$taille = taille_image($img_file);
3424
-			list($hauteur, $largeur) = $taille;
3425
-			if (!$hauteur or !$largeur) {
3426
-				return "";
3427
-			}
3428
-		}
3429
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3430
-	}
3431
-
3432
-	if (file_exists($img_file)) {
3433
-		$img_file = timestamp($img_file);
3434
-	}
3435
-	if ($alt === false) {
3436
-		$alt = '';
3437
-	}
3438
-	elseif($alt or $alt==='') {
3439
-		$alt = " alt='".attribut_html($alt)."'";
3440
-	}
3441
-	else {
3442
-		$alt = " alt='".attribut_html($title)."'";
3443
-	}
3444
-	return "<img src='$img_file'$alt"
3445
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3446
-	. " " . ltrim($atts)
3447
-	. " />";
3390
+    $img_file = $img;
3391
+    if ($p = strpos($img_file, '?')) {
3392
+        $img_file = substr($img_file,0, $p);
3393
+    }
3394
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3395
+        $img_file = chemin_image($img);
3396
+    }
3397
+    else {
3398
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3399
+            // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3400
+            // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3401
+            if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3402
+              and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3403
+              and file_exists($variante_svg_generique)) {
3404
+                if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3405
+                    $img_file = $variante_svg_size;
3406
+                }
3407
+                else {
3408
+                    $img_file = $variante_svg_generique;
3409
+                }
3410
+            }
3411
+        }
3412
+    }
3413
+    if (stripos($atts, 'width') === false) {
3414
+        // utiliser directement l'info de taille presente dans le nom
3415
+        if ((!isset($options['utiliser_suffixe_size'])
3416
+                or $options['utiliser_suffixe_size'] == true
3417
+              or strpos($img_file, '-xx.svg') !== false)
3418
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3419
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3420
+        ) {
3421
+            $largeur = $hauteur = intval($regs[1]);
3422
+        } else {
3423
+            $taille = taille_image($img_file);
3424
+            list($hauteur, $largeur) = $taille;
3425
+            if (!$hauteur or !$largeur) {
3426
+                return "";
3427
+            }
3428
+        }
3429
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3430
+    }
3431
+
3432
+    if (file_exists($img_file)) {
3433
+        $img_file = timestamp($img_file);
3434
+    }
3435
+    if ($alt === false) {
3436
+        $alt = '';
3437
+    }
3438
+    elseif($alt or $alt==='') {
3439
+        $alt = " alt='".attribut_html($alt)."'";
3440
+    }
3441
+    else {
3442
+        $alt = " alt='".attribut_html($title)."'";
3443
+    }
3444
+    return "<img src='$img_file'$alt"
3445
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3446
+    . " " . ltrim($atts)
3447
+    . " />";
3448 3448
 }
3449 3449
 
3450 3450
 /**
@@ -3456,68 +3456,68 @@  discard block
 block discarded – undo
3456 3456
  * @return string
3457 3457
  */
3458 3458
 function http_style_background($img, $att = '', $size=null) {
3459
-	if ($size and is_numeric($size)){
3460
-		$size = trim($size) . "px";
3461
-	}
3462
-	return " style='background" .
3463
-		($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3464
-		. ($size ? "background-size:{$size};" : '')
3465
-		. "'";
3459
+    if ($size and is_numeric($size)){
3460
+        $size = trim($size) . "px";
3461
+    }
3462
+    return " style='background" .
3463
+        ($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3464
+        . ($size ? "background-size:{$size};" : '')
3465
+        . "'";
3466 3466
 }
3467 3467
 
3468 3468
 
3469 3469
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3470
-	$args = [$alt_or_size, $class_or_size, $size];
3471
-	while (is_null(end($args)) and count($args)) {
3472
-		array_pop($args);
3473
-	}
3474
-	if (!count($args)) {
3475
-		return [null, null, null];
3476
-	}
3477
-	if (count($args) < 3) {
3478
-		$maybe_size = array_pop($args);
3479
-		// @2x
3480
-		// @1.5x
3481
-		// 512
3482
-		// 512x*
3483
-		// 512x300
3484
-		if (!strlen($maybe_size)
3485
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))) {
3486
-			$args[] = $maybe_size;
3487
-			$maybe_size = null;
3488
-		}
3489
-		while (count($args)<2) {
3490
-			$args[] = null; // default alt or class
3491
-		}
3492
-		$args[] = $maybe_size;
3493
-	}
3494
-	return $args;
3470
+    $args = [$alt_or_size, $class_or_size, $size];
3471
+    while (is_null(end($args)) and count($args)) {
3472
+        array_pop($args);
3473
+    }
3474
+    if (!count($args)) {
3475
+        return [null, null, null];
3476
+    }
3477
+    if (count($args) < 3) {
3478
+        $maybe_size = array_pop($args);
3479
+        // @2x
3480
+        // @1.5x
3481
+        // 512
3482
+        // 512x*
3483
+        // 512x300
3484
+        if (!strlen($maybe_size)
3485
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))) {
3486
+            $args[] = $maybe_size;
3487
+            $maybe_size = null;
3488
+        }
3489
+        while (count($args)<2) {
3490
+            $args[] = null; // default alt or class
3491
+        }
3492
+        $args[] = $maybe_size;
3493
+    }
3494
+    return $args;
3495 3495
 }
3496 3496
 
3497 3497
 function helper_filtre_balise_img_svg_size($img, $size) {
3498
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3499
-	if (strpos($size, '@') === 0 and substr($size,-1) === 'x') {
3500
-		$coef = floatval(substr($size, 1, -1));
3501
-		list($h, $w) = taille_image($img);
3502
-		$height = intval(round($h / $coef));
3503
-		$width = intval(round($w / $coef));
3504
-	}
3505
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3506
-	else {
3507
-		$size = explode('x', $size, 2);
3508
-		$size = array_map('trim', $size);
3509
-		$height = $width = intval(array_shift($size));
3510
-
3511
-		if (count($size) and reset($size)) {
3512
-			$height = array_shift($size);
3513
-			if ($height === '*') {
3514
-				list($h, $w) = taille_image($img);
3515
-				$height = intval(round($h * $width / $w));
3516
-			}
3517
-		}
3518
-	}
3519
-
3520
-	return [$width, $height];
3498
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3499
+    if (strpos($size, '@') === 0 and substr($size,-1) === 'x') {
3500
+        $coef = floatval(substr($size, 1, -1));
3501
+        list($h, $w) = taille_image($img);
3502
+        $height = intval(round($h / $coef));
3503
+        $width = intval(round($w / $coef));
3504
+    }
3505
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3506
+    else {
3507
+        $size = explode('x', $size, 2);
3508
+        $size = array_map('trim', $size);
3509
+        $height = $width = intval(array_shift($size));
3510
+
3511
+        if (count($size) and reset($size)) {
3512
+            $height = array_shift($size);
3513
+            if ($height === '*') {
3514
+                list($h, $w) = taille_image($img);
3515
+                $height = intval(round($h * $width / $w));
3516
+            }
3517
+        }
3518
+    }
3519
+
3520
+    return [$width, $height];
3521 3521
 }
3522 3522
 
3523 3523
 /**
@@ -3553,38 +3553,38 @@  discard block
 block discarded – undo
3553 3553
  */
3554 3554
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size=null) {
3555 3555
 
3556
-	list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3556
+    list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3557 3557
 
3558
-	$img = trim($img);
3559
-	if (strpos($img, '<img') === 0) {
3560
-		if (!is_null($alt)) {
3561
-			$img = inserer_attribut($img, 'alt', $alt);
3562
-		}
3563
-		if (!is_null($class)) {
3564
-			if (strlen($class)) {
3565
-				$img = inserer_attribut($img, 'class', $class);
3566
-			}
3567
-			else {
3568
-				$img = vider_attribut($img, 'class');
3569
-			}
3570
-		}
3571
-	}
3572
-	else {
3573
-		$img = http_img_pack($img, $alt, $class ? " class='" . attribut_html($class) . "'" : '', '',
3574
-				array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3575
-		if (is_null($alt)) {
3576
-			$img = vider_attribut($img, 'alt');
3577
-		}
3578
-	}
3558
+    $img = trim($img);
3559
+    if (strpos($img, '<img') === 0) {
3560
+        if (!is_null($alt)) {
3561
+            $img = inserer_attribut($img, 'alt', $alt);
3562
+        }
3563
+        if (!is_null($class)) {
3564
+            if (strlen($class)) {
3565
+                $img = inserer_attribut($img, 'class', $class);
3566
+            }
3567
+            else {
3568
+                $img = vider_attribut($img, 'class');
3569
+            }
3570
+        }
3571
+    }
3572
+    else {
3573
+        $img = http_img_pack($img, $alt, $class ? " class='" . attribut_html($class) . "'" : '', '',
3574
+                array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3575
+        if (is_null($alt)) {
3576
+            $img = vider_attribut($img, 'alt');
3577
+        }
3578
+    }
3579 3579
 
3580
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3581
-		list($width, $height) = helper_filtre_balise_img_svg_size($img, $size);
3580
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3581
+        list($width, $height) = helper_filtre_balise_img_svg_size($img, $size);
3582 3582
 
3583
-		$img = inserer_attribut($img, 'width', $width);
3584
-		$img = inserer_attribut($img, 'height', $height);
3585
-	}
3583
+        $img = inserer_attribut($img, 'width', $width);
3584
+        $img = inserer_attribut($img, 'height', $height);
3585
+    }
3586 3586
 
3587
-	return $img;
3587
+    return $img;
3588 3588
 }
3589 3589
 
3590 3590
 
@@ -3618,67 +3618,67 @@  discard block
 block discarded – undo
3618 3618
  */
3619 3619
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size=null) {
3620 3620
 
3621
-	$img = trim($img);
3622
-	$img_file = $img;
3623
-	if (strpos($img, '<svg') === false){
3624
-		if ($p = strpos($img_file, '?')){
3625
-			$img_file = substr($img_file, 0, $p);
3626
-		}
3621
+    $img = trim($img);
3622
+    $img_file = $img;
3623
+    if (strpos($img, '<svg') === false){
3624
+        if ($p = strpos($img_file, '?')){
3625
+            $img_file = substr($img_file, 0, $p);
3626
+        }
3627 3627
 
3628
-		if (!$img_file or !$svg = file_get_contents($img_file)){
3629
-			return '';
3630
-		}
3631
-	}
3628
+        if (!$img_file or !$svg = file_get_contents($img_file)){
3629
+            return '';
3630
+        }
3631
+    }
3632 3632
 
3633
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3634
-		return '';
3635
-	}
3633
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3634
+        return '';
3635
+    }
3636 3636
 
3637
-	list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3637
+    list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3638 3638
 
3639
-	$balise_svg = $match[0];
3640
-	$balise_svg_source = $balise_svg;
3639
+    $balise_svg = $match[0];
3640
+    $balise_svg_source = $balise_svg;
3641 3641
 
3642
-	// entete XML à supprimer
3643
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3642
+    // entete XML à supprimer
3643
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3644 3644
 
3645
-	// IE est toujours mon ami
3646
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3645
+    // IE est toujours mon ami
3646
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3647 3647
 
3648
-	// regler la classe
3649
-	if (!is_null($class)) {
3650
-		if (strlen($class)) {
3651
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3652
-		}
3653
-		else {
3654
-			$balise_svg = vider_attribut($balise_svg, 'class');
3655
-		}
3656
-	}
3648
+    // regler la classe
3649
+    if (!is_null($class)) {
3650
+        if (strlen($class)) {
3651
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3652
+        }
3653
+        else {
3654
+            $balise_svg = vider_attribut($balise_svg, 'class');
3655
+        }
3656
+    }
3657 3657
 
3658
-	// regler le alt
3659
-	if ($alt){
3660
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3661
-		$id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3662
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3663
-		$title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3664
-		$balise_svg .= $title;
3665
-	}
3666
-	else {
3667
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3668
-	}
3658
+    // regler le alt
3659
+    if ($alt){
3660
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3661
+        $id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3662
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3663
+        $title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3664
+        $balise_svg .= $title;
3665
+    }
3666
+    else {
3667
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3668
+    }
3669 3669
 
3670
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3670
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3671 3671
 
3672
-	if (!is_null($size) and strlen($size = trim($size))) {
3673
-		list($width, $height) = helper_filtre_balise_img_svg_size($svg, $size);
3672
+    if (!is_null($size) and strlen($size = trim($size))) {
3673
+        list($width, $height) = helper_filtre_balise_img_svg_size($svg, $size);
3674 3674
 
3675
-		if (!function_exists('svg_redimensionner')) {
3676
-			include_spip('inc/svg');
3677
-		}
3678
-		$svg = svg_redimensionner($svg, $width, $height);
3679
-	}
3675
+        if (!function_exists('svg_redimensionner')) {
3676
+            include_spip('inc/svg');
3677
+        }
3678
+        $svg = svg_redimensionner($svg, $width, $height);
3679
+    }
3680 3680
 
3681
-	return $svg;
3681
+    return $svg;
3682 3682
 }
3683 3683
 
3684 3684
 
@@ -3701,17 +3701,17 @@  discard block
 block discarded – undo
3701 3701
  *     Code HTML résultant
3702 3702
  **/
3703 3703
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3704
-	$texte = '';
3705
-	if (is_array($tableau)) {
3706
-		foreach ($tableau as $k => $v) {
3707
-			$res = recuperer_fond('modeles/' . $modele,
3708
-				array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3709
-			);
3710
-			$texte .= $res;
3711
-		}
3712
-	}
3704
+    $texte = '';
3705
+    if (is_array($tableau)) {
3706
+        foreach ($tableau as $k => $v) {
3707
+            $res = recuperer_fond('modeles/' . $modele,
3708
+                array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3709
+            );
3710
+            $texte .= $res;
3711
+        }
3712
+    }
3713 3713
 
3714
-	return $texte;
3714
+    return $texte;
3715 3715
 }
3716 3716
 
3717 3717
 
@@ -3736,37 +3736,37 @@  discard block
 block discarded – undo
3736 3736
  *         - tout : retourne toutes les informations du plugin actif
3737 3737
  **/
3738 3738
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3739
-	include_spip('inc/plugin');
3740
-	$plugin = strtoupper($plugin);
3741
-	$plugins_actifs = liste_plugin_actifs();
3742
-
3743
-	if (!$plugin) {
3744
-		return serialize(array_keys($plugins_actifs));
3745
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3746
-		return '';
3747
-	} elseif (($type_info == 'est_actif') and !$reload) {
3748
-		return $plugins_actifs[$plugin] ? 1 : 0;
3749
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3750
-		return $plugins_actifs[$plugin][$type_info];
3751
-	} else {
3752
-		$get_infos = charger_fonction('get_infos', 'plugins');
3753
-		// On prend en compte les extensions
3754
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3755
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3756
-		} else {
3757
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3758
-		}
3759
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3760
-			return '';
3761
-		}
3762
-		if ($type_info == 'tout') {
3763
-			return $infos;
3764
-		} elseif ($type_info == 'est_actif') {
3765
-			return $infos ? 1 : 0;
3766
-		} else {
3767
-			return strval($infos[$type_info]);
3768
-		}
3769
-	}
3739
+    include_spip('inc/plugin');
3740
+    $plugin = strtoupper($plugin);
3741
+    $plugins_actifs = liste_plugin_actifs();
3742
+
3743
+    if (!$plugin) {
3744
+        return serialize(array_keys($plugins_actifs));
3745
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3746
+        return '';
3747
+    } elseif (($type_info == 'est_actif') and !$reload) {
3748
+        return $plugins_actifs[$plugin] ? 1 : 0;
3749
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3750
+        return $plugins_actifs[$plugin][$type_info];
3751
+    } else {
3752
+        $get_infos = charger_fonction('get_infos', 'plugins');
3753
+        // On prend en compte les extensions
3754
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3755
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3756
+        } else {
3757
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3758
+        }
3759
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3760
+            return '';
3761
+        }
3762
+        if ($type_info == 'tout') {
3763
+            return $infos;
3764
+        } elseif ($type_info == 'est_actif') {
3765
+            return $infos ? 1 : 0;
3766
+        } else {
3767
+            return strval($infos[$type_info]);
3768
+        }
3769
+    }
3770 3770
 }
3771 3771
 
3772 3772
 
@@ -3793,9 +3793,9 @@  discard block
 block discarded – undo
3793 3793
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3794 3794
  */
3795 3795
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3796
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3796
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3797 3797
 
3798
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3798
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3799 3799
 }
3800 3800
 
3801 3801
 
@@ -3825,13 +3825,13 @@  discard block
 block discarded – undo
3825 3825
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3826 3826
  */
3827 3827
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3828
-	static $puce_statut = null;
3829
-	if (!$puce_statut) {
3830
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3831
-	}
3828
+    static $puce_statut = null;
3829
+    if (!$puce_statut) {
3830
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3831
+    }
3832 3832
 
3833
-	return $puce_statut($id_objet, $statut, $id_parent, $objet, false,
3834
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false);
3833
+    return $puce_statut($id_objet, $statut, $id_parent, $objet, false,
3834
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false);
3835 3835
 }
3836 3836
 
3837 3837
 
@@ -3858,95 +3858,95 @@  discard block
 block discarded – undo
3858 3858
  *   hash du contexte
3859 3859
  */
3860 3860
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3861
-	if (is_string($c)
3862
-		and @unserialize($c) !== false
3863
-	) {
3864
-		$c = unserialize($c);
3865
-	}
3866
-
3867
-	// supprimer les parametres debut_x
3868
-	// pour que la pagination ajax ne soit pas plantee
3869
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3870
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3871
-	if (is_array($c)) {
3872
-		foreach ($c as $k => $v) {
3873
-			if (strpos($k, 'debut_') === 0) {
3874
-				unset($c[$k]);
3875
-			}
3876
-		}
3877
-	}
3878
-
3879
-	if (!function_exists('calculer_cle_action')) {
3880
-		include_spip("inc/securiser_action");
3881
-	}
3882
-
3883
-	$c = serialize($c);
3884
-	$cle = calculer_cle_action($form . $c);
3885
-	$c = "$cle:$c";
3886
-
3887
-	// on ne stocke pas les contextes dans des fichiers en cache
3888
-	// par defaut, sauf si cette configuration a été forcée
3889
-	// OU que la longueur de l’argument géneré est plus long
3890
-	// que ce qui est toléré.
3891
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3892
-	if (!$cache_contextes_ajax) {
3893
-		$env = $c;
3894
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3895
-			$env = gzdeflate($env);
3896
-		}
3897
-		$env = _xor($env);
3898
-		$env = base64_encode($env);
3899
-		$len = strlen($env);
3900
-		// Si l’url est trop longue pour le navigateur
3901
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3902
-		if ($len > $max_len) {
3903
-			$cache_contextes_ajax = true;
3904
-			spip_log("Contextes AJAX forces en fichiers !"
3905
-				. " Cela arrive lorsque la valeur du contexte" 
3906
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len."
3907
-				, _LOG_AVERTISSEMENT);
3908
-		}
3909
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3910
-		elseif (
3911
-			$max_len = @ini_get('suhosin.get.max_value_length')
3912
-			and $max_len < $len
3913
-		) {
3914
-			$cache_contextes_ajax = true;
3915
-			spip_log("Contextes AJAX forces en fichiers !"
3916
-				. " Cela arrive lorsque la valeur du contexte"
3917
-				. " depasse la longueur maximale autorisee par Suhosin"
3918
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3919
-				. " Vous devriez modifier les parametres de Suhosin"
3920
-				. " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
3921
-		} 
3922
-
3923
-	}
3924
-
3925
-	if ($cache_contextes_ajax) {
3926
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
3927
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
3928
-		$md5 = md5($c);
3929
-		ecrire_fichier("$dir/c$md5", $c);
3930
-		$env = $md5;
3931
-	}
3932
-
3933
-	if ($emboite === null) {
3934
-		return $env;
3935
-	}
3936
-	if (!trim($emboite)) {
3937
-		return "";
3938
-	}
3939
-	// toujours encoder l'url source dans le bloc ajax
3940
-	$r = self();
3941
-	$r = ' data-origin="' . $r . '"';
3942
-	$class = 'ajaxbloc';
3943
-	if ($ajaxid and is_string($ajaxid)) {
3944
-		// ajaxid est normalement conforme a un nom de classe css
3945
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3946
-		$class .= ' ajax-id-' . entites_html($ajaxid);
3947
-	}
3948
-
3949
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3861
+    if (is_string($c)
3862
+        and @unserialize($c) !== false
3863
+    ) {
3864
+        $c = unserialize($c);
3865
+    }
3866
+
3867
+    // supprimer les parametres debut_x
3868
+    // pour que la pagination ajax ne soit pas plantee
3869
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3870
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3871
+    if (is_array($c)) {
3872
+        foreach ($c as $k => $v) {
3873
+            if (strpos($k, 'debut_') === 0) {
3874
+                unset($c[$k]);
3875
+            }
3876
+        }
3877
+    }
3878
+
3879
+    if (!function_exists('calculer_cle_action')) {
3880
+        include_spip("inc/securiser_action");
3881
+    }
3882
+
3883
+    $c = serialize($c);
3884
+    $cle = calculer_cle_action($form . $c);
3885
+    $c = "$cle:$c";
3886
+
3887
+    // on ne stocke pas les contextes dans des fichiers en cache
3888
+    // par defaut, sauf si cette configuration a été forcée
3889
+    // OU que la longueur de l’argument géneré est plus long
3890
+    // que ce qui est toléré.
3891
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3892
+    if (!$cache_contextes_ajax) {
3893
+        $env = $c;
3894
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3895
+            $env = gzdeflate($env);
3896
+        }
3897
+        $env = _xor($env);
3898
+        $env = base64_encode($env);
3899
+        $len = strlen($env);
3900
+        // Si l’url est trop longue pour le navigateur
3901
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3902
+        if ($len > $max_len) {
3903
+            $cache_contextes_ajax = true;
3904
+            spip_log("Contextes AJAX forces en fichiers !"
3905
+                . " Cela arrive lorsque la valeur du contexte" 
3906
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len."
3907
+                , _LOG_AVERTISSEMENT);
3908
+        }
3909
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3910
+        elseif (
3911
+            $max_len = @ini_get('suhosin.get.max_value_length')
3912
+            and $max_len < $len
3913
+        ) {
3914
+            $cache_contextes_ajax = true;
3915
+            spip_log("Contextes AJAX forces en fichiers !"
3916
+                . " Cela arrive lorsque la valeur du contexte"
3917
+                . " depasse la longueur maximale autorisee par Suhosin"
3918
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3919
+                . " Vous devriez modifier les parametres de Suhosin"
3920
+                . " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
3921
+        } 
3922
+
3923
+    }
3924
+
3925
+    if ($cache_contextes_ajax) {
3926
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
3927
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
3928
+        $md5 = md5($c);
3929
+        ecrire_fichier("$dir/c$md5", $c);
3930
+        $env = $md5;
3931
+    }
3932
+
3933
+    if ($emboite === null) {
3934
+        return $env;
3935
+    }
3936
+    if (!trim($emboite)) {
3937
+        return "";
3938
+    }
3939
+    // toujours encoder l'url source dans le bloc ajax
3940
+    $r = self();
3941
+    $r = ' data-origin="' . $r . '"';
3942
+    $class = 'ajaxbloc';
3943
+    if ($ajaxid and is_string($ajaxid)) {
3944
+        // ajaxid est normalement conforme a un nom de classe css
3945
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3946
+        $class .= ' ajax-id-' . entites_html($ajaxid);
3947
+    }
3948
+
3949
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3950 3950
 }
3951 3951
 
3952 3952
 /**
@@ -3966,36 +3966,36 @@  discard block
 block discarded – undo
3966 3966
  *   - false : erreur de décodage
3967 3967
  */
3968 3968
 function decoder_contexte_ajax($c, $form = '') {
3969
-	if (!function_exists('calculer_cle_action')) {
3970
-		include_spip("inc/securiser_action");
3971
-	}
3972
-	if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
3973
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
3974
-		and lire_fichier("$dir/c$c", $contexte)
3975
-	) {
3976
-		$c = $contexte;
3977
-	} else {
3978
-		$c = @base64_decode($c);
3979
-		$c = _xor($c);
3980
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3981
-			$c = @gzinflate($c);
3982
-		}
3983
-	}
3984
-
3985
-	// extraire la signature en debut de contexte
3986
-	// et la verifier avant de deserializer
3987
-	// format : signature:donneesserializees
3988
-	if ($p = strpos($c,":")){
3989
-		$cle = substr($c,0,$p);
3990
-		$c = substr($c,$p+1);
3991
-
3992
-		if ($cle == calculer_cle_action($form . $c)) {
3993
-			$env = @unserialize($c);
3994
-			return $env;
3995
-		}
3996
-	}
3997
-
3998
-	return false;
3969
+    if (!function_exists('calculer_cle_action')) {
3970
+        include_spip("inc/securiser_action");
3971
+    }
3972
+    if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
3973
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
3974
+        and lire_fichier("$dir/c$c", $contexte)
3975
+    ) {
3976
+        $c = $contexte;
3977
+    } else {
3978
+        $c = @base64_decode($c);
3979
+        $c = _xor($c);
3980
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3981
+            $c = @gzinflate($c);
3982
+        }
3983
+    }
3984
+
3985
+    // extraire la signature en debut de contexte
3986
+    // et la verifier avant de deserializer
3987
+    // format : signature:donneesserializees
3988
+    if ($p = strpos($c,":")){
3989
+        $cle = substr($c,0,$p);
3990
+        $c = substr($c,$p+1);
3991
+
3992
+        if ($cle == calculer_cle_action($form . $c)) {
3993
+            $env = @unserialize($c);
3994
+            return $env;
3995
+        }
3996
+    }
3997
+
3998
+    return false;
3999 3999
 }
4000 4000
 
4001 4001
 
@@ -4013,20 +4013,20 @@  discard block
 block discarded – undo
4013 4013
  *    Message décrypté ou encrypté
4014 4014
  **/
4015 4015
 function _xor($message, $key = null) {
4016
-	if (is_null($key)) {
4017
-		if (!function_exists('calculer_cle_action')) {
4018
-			include_spip("inc/securiser_action");
4019
-		}
4020
-		$key = pack("H*", calculer_cle_action('_xor'));
4021
-	}
4016
+    if (is_null($key)) {
4017
+        if (!function_exists('calculer_cle_action')) {
4018
+            include_spip("inc/securiser_action");
4019
+        }
4020
+        $key = pack("H*", calculer_cle_action('_xor'));
4021
+    }
4022 4022
 
4023
-	$keylen = strlen($key);
4024
-	$messagelen = strlen($message);
4025
-	for ($i = 0; $i < $messagelen; $i++) {
4026
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4027
-	}
4023
+    $keylen = strlen($key);
4024
+    $messagelen = strlen($message);
4025
+    for ($i = 0; $i < $messagelen; $i++) {
4026
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4027
+    }
4028 4028
 
4029
-	return $message;
4029
+    return $message;
4030 4030
 }
4031 4031
 
4032 4032
 /**
@@ -4089,37 +4089,37 @@  discard block
 block discarded – undo
4089 4089
  *   Code HTML
4090 4090
  */
4091 4091
 function lien_ou_expose($url, $libelle = null, $on = false, $class = "", $title = "", $rel = "", $evt = '') {
4092
-	if ($on) {
4093
-		$bal = 'strong';
4094
-		$class = "";
4095
-		$att = "";
4096
-		// si $on passe la balise et optionnelement une ou ++classe
4097
-		// a.active span.selected.active etc....
4098
-		if (is_string($on) and (strncmp($on, 'a', 1)==0 or strncmp($on, 'span', 4)==0 or strncmp($on, 'strong', 6)==0)){
4099
-			$on = explode(".", $on);
4100
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4101
-			if (in_array(reset($on), array('a', 'span', 'strong'))){
4102
-				$bal = array_shift($on);
4103
-				$class = implode(" ", $on);
4104
-				if ($bal=="a"){
4105
-					$att = 'href="#" ';
4106
-				}
4107
-			}
4108
-		}
4109
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4110
-	} else {
4111
-		$bal = 'a';
4112
-		$att = "href='$url'"
4113
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4114
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4115
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4116
-			. $evt;
4117
-	}
4118
-	if ($libelle === null) {
4119
-		$libelle = $url;
4120
-	}
4121
-
4122
-	return "<$bal $att>$libelle</$bal>";
4092
+    if ($on) {
4093
+        $bal = 'strong';
4094
+        $class = "";
4095
+        $att = "";
4096
+        // si $on passe la balise et optionnelement une ou ++classe
4097
+        // a.active span.selected.active etc....
4098
+        if (is_string($on) and (strncmp($on, 'a', 1)==0 or strncmp($on, 'span', 4)==0 or strncmp($on, 'strong', 6)==0)){
4099
+            $on = explode(".", $on);
4100
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4101
+            if (in_array(reset($on), array('a', 'span', 'strong'))){
4102
+                $bal = array_shift($on);
4103
+                $class = implode(" ", $on);
4104
+                if ($bal=="a"){
4105
+                    $att = 'href="#" ';
4106
+                }
4107
+            }
4108
+        }
4109
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4110
+    } else {
4111
+        $bal = 'a';
4112
+        $att = "href='$url'"
4113
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4114
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4115
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4116
+            . $evt;
4117
+    }
4118
+    if ($libelle === null) {
4119
+        $libelle = $url;
4120
+    }
4121
+
4122
+    return "<$bal $att>$libelle</$bal>";
4123 4123
 }
4124 4124
 
4125 4125
 
@@ -4136,37 +4136,37 @@  discard block
 block discarded – undo
4136 4136
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4137 4137
  */
4138 4138
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = array()) {
4139
-	static $local_singulier_ou_pluriel = array();
4139
+    static $local_singulier_ou_pluriel = array();
4140 4140
 
4141
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4142
-	if (!is_numeric($nb) or $nb == 0) {
4143
-		return "";
4144
-	}
4145
-	if (!is_array($vars)) {
4146
-		return "";
4147
-	}
4141
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4142
+    if (!is_numeric($nb) or $nb == 0) {
4143
+        return "";
4144
+    }
4145
+    if (!is_array($vars)) {
4146
+        return "";
4147
+    }
4148 4148
 
4149
-	$langue = $GLOBALS['spip_lang'];
4150
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4151
-		$local_singulier_ou_pluriel[$langue] = false;
4152
-		if ($f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4153
-		  or $f = charger_fonction("singulier_ou_pluriel", 'inc', true)) {
4154
-			$local_singulier_ou_pluriel[$langue] = $f;
4155
-		}
4156
-	}
4149
+    $langue = $GLOBALS['spip_lang'];
4150
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4151
+        $local_singulier_ou_pluriel[$langue] = false;
4152
+        if ($f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4153
+          or $f = charger_fonction("singulier_ou_pluriel", 'inc', true)) {
4154
+            $local_singulier_ou_pluriel[$langue] = $f;
4155
+        }
4156
+    }
4157 4157
 
4158
-	// si on a une surcharge on l'utilise
4159
-	if ($local_singulier_ou_pluriel[$langue]) {
4160
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4161
-	}
4158
+    // si on a une surcharge on l'utilise
4159
+    if ($local_singulier_ou_pluriel[$langue]) {
4160
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4161
+    }
4162 4162
 
4163
-	// sinon traitement par defaut
4164
-	$vars[$var] = $nb;
4165
-	if ($nb >= 2) {
4166
-		return _T($chaine_plusieurs, $vars);
4167
-	} else {
4168
-		return _T($chaine_un, $vars);
4169
-	}
4163
+    // sinon traitement par defaut
4164
+    $vars[$var] = $nb;
4165
+    if ($nb >= 2) {
4166
+        return _T($chaine_plusieurs, $vars);
4167
+    } else {
4168
+        return _T($chaine_un, $vars);
4169
+    }
4170 4170
 }
4171 4171
 
4172 4172
 
@@ -4194,71 +4194,71 @@  discard block
 block discarded – undo
4194 4194
  */
4195 4195
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4196 4196
 
4197
-	$class_lien = $class_bouton = $class;
4198
-
4199
-	// Normaliser la fonction et compléter la classe en fonction
4200
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4201
-		$class_lien .= ' danger';
4202
-		$class_bouton .= ' btn_danger';
4203
-	} elseif ($fonction == 'rien.gif') {
4204
-		$fonction = '';
4205
-	} elseif ($fonction == 'delsafe') {
4206
-		$fonction = 'del';
4207
-	}
4208
-
4209
-	$fond_origine = $fond;
4210
-	// Remappage des icone : article-24.png+new => article-new-24.png
4211
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4212
-		list($fond, $fonction) = $icone_renommer($fond, $fonction);
4213
-	}
4214
-
4215
-	// Ajouter le type d'objet dans la classe
4216
-	$objet_type = substr(basename($fond), 0, -4);
4217
-	$class_lien .= " $objet_type";
4218
-	$class_bouton .= " $objet_type";
4219
-
4220
-	// Texte
4221
-	$alt = attribut_html($texte);
4222
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4223
-
4224
-	// Liens : préparer les classes ajax
4225
-	$ajax = '';
4226
-	if ($type === 'lien') {
4227
-		if (strpos($class_lien, 'ajax') !== false) {
4228
-			$ajax = 'ajax';
4229
-			if (strpos($class_lien, 'preload') !== false) {
4230
-				$ajax .= ' preload';
4231
-			}
4232
-			if (strpos($class_lien, 'nocache') !== false) {
4233
-				$ajax .= ' nocache';
4234
-			}
4235
-			$ajax = " class='$ajax'";
4236
-		}
4237
-	}
4238
-
4239
-	// Repérer la taille et l'ajouter dans la classe
4240
-	$size = 24;
4241
-	if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match)
4242
-	  or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) {
4243
-		$size = $match[1];
4244
-	}
4245
-	$class_lien .= " s$size";
4246
-	$class_bouton .= " s$size";
4247
-
4248
-	// Icône
4249
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4250
-	$icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
4251
-
4252
-	// Markup final
4253
-	if ($type == 'lien') {
4254
-		return "<span class='icone $class_lien'>"
4255
-		. "<a href='$lien'$title$ajax$javascript>"
4256
-		. $icone
4257
-		. "<b>$texte</b>"
4258
-		. "</a></span>\n";
4259
-	} else {
4260
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4261
-	}
4197
+    $class_lien = $class_bouton = $class;
4198
+
4199
+    // Normaliser la fonction et compléter la classe en fonction
4200
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4201
+        $class_lien .= ' danger';
4202
+        $class_bouton .= ' btn_danger';
4203
+    } elseif ($fonction == 'rien.gif') {
4204
+        $fonction = '';
4205
+    } elseif ($fonction == 'delsafe') {
4206
+        $fonction = 'del';
4207
+    }
4208
+
4209
+    $fond_origine = $fond;
4210
+    // Remappage des icone : article-24.png+new => article-new-24.png
4211
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4212
+        list($fond, $fonction) = $icone_renommer($fond, $fonction);
4213
+    }
4214
+
4215
+    // Ajouter le type d'objet dans la classe
4216
+    $objet_type = substr(basename($fond), 0, -4);
4217
+    $class_lien .= " $objet_type";
4218
+    $class_bouton .= " $objet_type";
4219
+
4220
+    // Texte
4221
+    $alt = attribut_html($texte);
4222
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4223
+
4224
+    // Liens : préparer les classes ajax
4225
+    $ajax = '';
4226
+    if ($type === 'lien') {
4227
+        if (strpos($class_lien, 'ajax') !== false) {
4228
+            $ajax = 'ajax';
4229
+            if (strpos($class_lien, 'preload') !== false) {
4230
+                $ajax .= ' preload';
4231
+            }
4232
+            if (strpos($class_lien, 'nocache') !== false) {
4233
+                $ajax .= ' nocache';
4234
+            }
4235
+            $ajax = " class='$ajax'";
4236
+        }
4237
+    }
4238
+
4239
+    // Repérer la taille et l'ajouter dans la classe
4240
+    $size = 24;
4241
+    if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match)
4242
+      or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) {
4243
+        $size = $match[1];
4244
+    }
4245
+    $class_lien .= " s$size";
4246
+    $class_bouton .= " s$size";
4247
+
4248
+    // Icône
4249
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4250
+    $icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
4251
+
4252
+    // Markup final
4253
+    if ($type == 'lien') {
4254
+        return "<span class='icone $class_lien'>"
4255
+        . "<a href='$lien'$title$ajax$javascript>"
4256
+        . $icone
4257
+        . "<b>$texte</b>"
4258
+        . "</a></span>\n";
4259
+    } else {
4260
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4261
+    }
4262 4262
 }
4263 4263
 
4264 4264
 /**
@@ -4282,7 +4282,7 @@  discard block
 block discarded – undo
4282 4282
  *     Code HTML du lien
4283 4283
  **/
4284 4284
 function icone_base($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4285
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4285
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4286 4286
 }
4287 4287
 
4288 4288
 /**
@@ -4317,7 +4317,7 @@  discard block
 block discarded – undo
4317 4317
  *     Code HTML du lien
4318 4318
  **/
4319 4319
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4320
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4320
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4321 4321
 }
4322 4322
 
4323 4323
 /**
@@ -4362,7 +4362,7 @@  discard block
 block discarded – undo
4362 4362
  *     Code HTML du lien
4363 4363
  **/
4364 4364
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4365
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4365
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4366 4366
 }
4367 4367
 
4368 4368
 /**
@@ -4393,7 +4393,7 @@  discard block
 block discarded – undo
4393 4393
  *     Code HTML du lien
4394 4394
  **/
4395 4395
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = "", $class = "", $confirm = "") {
4396
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4396
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4397 4397
 }
4398 4398
 
4399 4399
 /**
@@ -4423,7 +4423,7 @@  discard block
 block discarded – undo
4423 4423
  *     Code HTML du lien
4424 4424
  */
4425 4425
 function filtre_icone_dist($lien, $texte, $fond, $align = "", $fonction = "", $class = "", $javascript = "") {
4426
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4426
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4427 4427
 }
4428 4428
 
4429 4429
 
@@ -4471,26 +4471,26 @@  discard block
 block discarded – undo
4471 4471
  * @return string Code CSS
4472 4472
  */
4473 4473
 function bando_images_background() {
4474
-	include_spip('inc/bandeau');
4475
-	// recuperer tous les boutons et leurs images
4476
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4474
+    include_spip('inc/bandeau');
4475
+    // recuperer tous les boutons et leurs images
4476
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4477 4477
 
4478
-	$res = "";
4479
-	foreach ($boutons as $page => $detail) {
4480
-		if ($detail->icone and strlen(trim($detail->icone))) {
4481
-			$res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}";
4482
-		}
4483
-		$selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4484
-		if (is_array($detail->sousmenu)) {
4485
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4486
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4487
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4488
-				}
4489
-			}
4490
-		}
4491
-	}
4478
+    $res = "";
4479
+    foreach ($boutons as $page => $detail) {
4480
+        if ($detail->icone and strlen(trim($detail->icone))) {
4481
+            $res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}";
4482
+        }
4483
+        $selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4484
+        if (is_array($detail->sousmenu)) {
4485
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4486
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4487
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4488
+                }
4489
+            }
4490
+        }
4491
+    }
4492 4492
 
4493
-	return $res;
4493
+    return $res;
4494 4494
 }
4495 4495
 
4496 4496
 /**
@@ -4515,27 +4515,27 @@  discard block
 block discarded – undo
4515 4515
  */
4516 4516
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4517 4517
 
4518
-	// Classes : dispatcher `ajax` sur le formulaire
4519
-	$class_form = '';
4520
-	if (strpos($class, 'ajax') !== false) {
4521
-		$class_form = 'ajax';
4522
-		$class = str_replace('ajax', '', $class);
4523
-	}
4524
-	$class_btn = 'submit ' . trim($class);
4518
+    // Classes : dispatcher `ajax` sur le formulaire
4519
+    $class_form = '';
4520
+    if (strpos($class, 'ajax') !== false) {
4521
+        $class_form = 'ajax';
4522
+        $class = str_replace('ajax', '', $class);
4523
+    }
4524
+    $class_btn = 'submit ' . trim($class);
4525 4525
 
4526
-	if ($confirm) {
4527
-		$confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4528
-		if ($callback) {
4529
-			$callback = "$confirm?($callback):false";
4530
-		} else {
4531
-			$callback = $confirm;
4532
-		}
4533
-	}
4534
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4535
-	$title = $title ? " title='$title'" : '';
4526
+    if ($confirm) {
4527
+        $confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4528
+        if ($callback) {
4529
+            $callback = "$confirm?($callback):false";
4530
+        } else {
4531
+            $callback = $confirm;
4532
+        }
4533
+    }
4534
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4535
+    $title = $title ? " title='$title'" : '';
4536 4536
 
4537
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4538
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4537
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4538
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4539 4539
 }
4540 4540
 
4541 4541
 /**
@@ -4556,78 +4556,78 @@  discard block
 block discarded – undo
4556 4556
  * @return string
4557 4557
  */
4558 4558
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = "") {
4559
-	static $trouver_table = null;
4560
-	static $objets;
4561
-
4562
-	// On verifie qu'on a tout ce qu'il faut
4563
-	$id_objet = intval($id_objet);
4564
-	if (!($id_objet and $type_objet and $info)) {
4565
-		return '';
4566
-	}
4567
-
4568
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4569
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4570
-		return '';
4571
-	}
4572
-
4573
-	// Si on demande l'url, on retourne direct la fonction
4574
-	if ($info == 'url') {
4575
-		return generer_url_entite($id_objet, $type_objet);
4576
-	}
4577
-
4578
-	// Sinon on va tout chercher dans la table et on garde en memoire
4579
-	$demande_titre = ($info == 'titre');
4580
-
4581
-	// 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
4582
-	if (!isset($objets[$type_objet][$id_objet])
4583
-		or
4584
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4585
-	) {
4586
-		if (!$trouver_table) {
4587
-			$trouver_table = charger_fonction('trouver_table', 'base');
4588
-		}
4589
-		$desc = $trouver_table(table_objet_sql($type_objet));
4590
-		if (!$desc) {
4591
-			return $objets[$type_objet] = false;
4592
-		}
4593
-
4594
-		// Si on demande le titre, on le gere en interne
4595
-		$champ_titre = "";
4596
-		if ($demande_titre) {
4597
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4598
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4599
-		}
4600
-		include_spip('base/abstract_sql');
4601
-		include_spip('base/connect_sql');
4602
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4603
-			'*' . $champ_titre,
4604
-			$desc['table_sql'],
4605
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4606
-		);
4607
-	}
4608
-
4609
-	// Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4610
-	if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4611
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
4612
-	} // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4613
-	else {
4614
-		if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4615
-			$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
4616
-		} // Sinon on prend directement le champ SQL tel quel
4617
-		else {
4618
-			$info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4619
-		}
4620
-	}
4621
-
4622
-	// On va ensuite appliquer les traitements automatiques si besoin
4623
-	if (!$etoile) {
4624
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4625
-		// mais ce fonctionnement est a ameliorer !
4626
-		$info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet),
4627
-			array('id_objet' => $id_objet, 'objet' => $type_objet, ''));
4628
-	}
4629
-
4630
-	return $info_generee;
4559
+    static $trouver_table = null;
4560
+    static $objets;
4561
+
4562
+    // On verifie qu'on a tout ce qu'il faut
4563
+    $id_objet = intval($id_objet);
4564
+    if (!($id_objet and $type_objet and $info)) {
4565
+        return '';
4566
+    }
4567
+
4568
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4569
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4570
+        return '';
4571
+    }
4572
+
4573
+    // Si on demande l'url, on retourne direct la fonction
4574
+    if ($info == 'url') {
4575
+        return generer_url_entite($id_objet, $type_objet);
4576
+    }
4577
+
4578
+    // Sinon on va tout chercher dans la table et on garde en memoire
4579
+    $demande_titre = ($info == 'titre');
4580
+
4581
+    // 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
4582
+    if (!isset($objets[$type_objet][$id_objet])
4583
+        or
4584
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4585
+    ) {
4586
+        if (!$trouver_table) {
4587
+            $trouver_table = charger_fonction('trouver_table', 'base');
4588
+        }
4589
+        $desc = $trouver_table(table_objet_sql($type_objet));
4590
+        if (!$desc) {
4591
+            return $objets[$type_objet] = false;
4592
+        }
4593
+
4594
+        // Si on demande le titre, on le gere en interne
4595
+        $champ_titre = "";
4596
+        if ($demande_titre) {
4597
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4598
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4599
+        }
4600
+        include_spip('base/abstract_sql');
4601
+        include_spip('base/connect_sql');
4602
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4603
+            '*' . $champ_titre,
4604
+            $desc['table_sql'],
4605
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4606
+        );
4607
+    }
4608
+
4609
+    // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4610
+    if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4611
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
4612
+    } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4613
+    else {
4614
+        if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4615
+            $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
4616
+        } // Sinon on prend directement le champ SQL tel quel
4617
+        else {
4618
+            $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4619
+        }
4620
+    }
4621
+
4622
+    // On va ensuite appliquer les traitements automatiques si besoin
4623
+    if (!$etoile) {
4624
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4625
+        // mais ce fonctionnement est a ameliorer !
4626
+        $info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet),
4627
+            array('id_objet' => $id_objet, 'objet' => $type_objet, ''));
4628
+    }
4629
+
4630
+    return $info_generee;
4631 4631
 }
4632 4632
 
4633 4633
 /**
@@ -4641,44 +4641,44 @@  discard block
 block discarded – undo
4641 4641
  * @return string
4642 4642
  */
4643 4643
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = array(), $connect = '') {
4644
-	if (!$champ) {
4645
-		return $texte;
4646
-	}
4644
+    if (!$champ) {
4645
+        return $texte;
4646
+    }
4647 4647
 	
4648
-	// On charge toujours les filtres de texte car la majorité des traitements les utilisent
4649
-	// et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4650
-	include_spip('inc/texte');
4648
+    // On charge toujours les filtres de texte car la majorité des traitements les utilisent
4649
+    // et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4650
+    include_spip('inc/texte');
4651 4651
 	
4652
-	$champ = strtoupper($champ);
4653
-	$traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4654
-	if (!$traitements or !is_array($traitements)) {
4655
-		return $texte;
4656
-	}
4652
+    $champ = strtoupper($champ);
4653
+    $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4654
+    if (!$traitements or !is_array($traitements)) {
4655
+        return $texte;
4656
+    }
4657 4657
 
4658
-	$traitement = '';
4659
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4660
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4661
-		$table_objet = table_objet($table_objet);
4662
-		if (isset($traitements[$table_objet])) {
4663
-			$traitement = $traitements[$table_objet];
4664
-		}
4665
-	}
4666
-	if (!$traitement and isset($traitements[0])) {
4667
-		$traitement = $traitements[0];
4668
-	}
4669
-	// (sinon prendre le premier de la liste par defaut ?)
4658
+    $traitement = '';
4659
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4660
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4661
+        $table_objet = table_objet($table_objet);
4662
+        if (isset($traitements[$table_objet])) {
4663
+            $traitement = $traitements[$table_objet];
4664
+        }
4665
+    }
4666
+    if (!$traitement and isset($traitements[0])) {
4667
+        $traitement = $traitements[0];
4668
+    }
4669
+    // (sinon prendre le premier de la liste par defaut ?)
4670 4670
 
4671
-	if (!$traitement) {
4672
-		return $texte;
4673
-	}
4671
+    if (!$traitement) {
4672
+        return $texte;
4673
+    }
4674 4674
 
4675
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4675
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4676 4676
 
4677
-	// Fournir $connect et $Pile[0] au traitement si besoin
4678
-	$Pile = array(0 => $env);
4679
-	eval("\$texte = $traitement;");
4677
+    // Fournir $connect et $Pile[0] au traitement si besoin
4678
+    $Pile = array(0 => $env);
4679
+    eval("\$texte = $traitement;");
4680 4680
 
4681
-	return $texte;
4681
+    return $texte;
4682 4682
 }
4683 4683
 
4684 4684
 
@@ -4692,21 +4692,21 @@  discard block
 block discarded – undo
4692 4692
  * @return string
4693 4693
  */
4694 4694
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4695
-	include_spip('inc/liens');
4696
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4697
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4698
-	// le raccourcis n'est plus valide
4699
-	$titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4700
-	// on essaye avec generer_info_entite ?
4701
-	if (!strlen($titre) and !$connect) {
4702
-		$titre = generer_info_entite($id_objet, $objet, 'titre');
4703
-	}
4704
-	if (!strlen($titre)) {
4705
-		$titre = _T('info_sans_titre');
4706
-	}
4707
-	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4695
+    include_spip('inc/liens');
4696
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4697
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4698
+    // le raccourcis n'est plus valide
4699
+    $titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4700
+    // on essaye avec generer_info_entite ?
4701
+    if (!strlen($titre) and !$connect) {
4702
+        $titre = generer_info_entite($id_objet, $objet, 'titre');
4703
+    }
4704
+    if (!strlen($titre)) {
4705
+        $titre = _T('info_sans_titre');
4706
+    }
4707
+    $url = generer_url_entite($id_objet, $objet, '', '', $connect);
4708 4708
 
4709
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4709
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4710 4710
 }
4711 4711
 
4712 4712
 
@@ -4723,15 +4723,15 @@  discard block
 block discarded – undo
4723 4723
  * @return string
4724 4724
  */
4725 4725
 function wrap($texte, $wrap) {
4726
-	$balises = extraire_balises($wrap);
4727
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4728
-		$texte = $wrap . $texte;
4729
-		$regs = array_reverse($regs[1]);
4730
-		$wrap = "</" . implode("></", $regs) . ">";
4731
-		$texte = $texte . $wrap;
4732
-	}
4726
+    $balises = extraire_balises($wrap);
4727
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4728
+        $texte = $wrap . $texte;
4729
+        $regs = array_reverse($regs[1]);
4730
+        $wrap = "</" . implode("></", $regs) . ">";
4731
+        $texte = $texte . $wrap;
4732
+    }
4733 4733
 
4734
-	return $texte;
4734
+    return $texte;
4735 4735
 }
4736 4736
 
4737 4737
 
@@ -4751,43 +4751,43 @@  discard block
 block discarded – undo
4751 4751
  * @return array|mixed|string
4752 4752
  */
4753 4753
 function filtre_print_dist($u, $join = "<br />", $indent = 0) {
4754
-	if (is_string($u)) {
4755
-		$u = typo($u);
4754
+    if (is_string($u)) {
4755
+        $u = typo($u);
4756 4756
 
4757
-		return $u;
4758
-	}
4757
+        return $u;
4758
+    }
4759 4759
 
4760
-	// caster $u en array si besoin
4761
-	if (is_object($u)) {
4762
-		$u = (array)$u;
4763
-	}
4760
+    // caster $u en array si besoin
4761
+    if (is_object($u)) {
4762
+        $u = (array)$u;
4763
+    }
4764 4764
 
4765
-	if (is_array($u)) {
4766
-		$out = "";
4767
-		// toutes les cles sont numeriques ?
4768
-		// et aucun enfant n'est un tableau
4769
-		// liste simple separee par des virgules
4770
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4771
-		$array_values = array_map('is_array', $u);
4772
-		$object_values = array_map('is_object', $u);
4773
-		if (array_sum($numeric_keys) == count($numeric_keys)
4774
-			and !array_sum($array_values)
4775
-			and !array_sum($object_values)
4776
-		) {
4777
-			return join(", ", array_map('filtre_print_dist', $u));
4778
-		}
4765
+    if (is_array($u)) {
4766
+        $out = "";
4767
+        // toutes les cles sont numeriques ?
4768
+        // et aucun enfant n'est un tableau
4769
+        // liste simple separee par des virgules
4770
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4771
+        $array_values = array_map('is_array', $u);
4772
+        $object_values = array_map('is_object', $u);
4773
+        if (array_sum($numeric_keys) == count($numeric_keys)
4774
+            and !array_sum($array_values)
4775
+            and !array_sum($object_values)
4776
+        ) {
4777
+            return join(", ", array_map('filtre_print_dist', $u));
4778
+        }
4779 4779
 
4780
-		// sinon on passe a la ligne et on indente
4781
-		$i_str = str_pad("", $indent, " ");
4782
-		foreach ($u as $k => $v) {
4783
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4784
-		}
4780
+        // sinon on passe a la ligne et on indente
4781
+        $i_str = str_pad("", $indent, " ");
4782
+        foreach ($u as $k => $v) {
4783
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4784
+        }
4785 4785
 
4786
-		return $out;
4787
-	}
4786
+        return $out;
4787
+    }
4788 4788
 
4789
-	// on sait pas quoi faire...
4790
-	return $u;
4789
+    // on sait pas quoi faire...
4790
+    return $u;
4791 4791
 }
4792 4792
 
4793 4793
 
@@ -4800,10 +4800,10 @@  discard block
 block discarded – undo
4800 4800
  * @return string|array
4801 4801
  */
4802 4802
 function objet_info($objet, $info) {
4803
-	$table = table_objet_sql($objet);
4804
-	$infos = lister_tables_objets_sql($table);
4803
+    $table = table_objet_sql($objet);
4804
+    $infos = lister_tables_objets_sql($table);
4805 4805
 
4806
-	return (isset($infos[$info]) ? $infos[$info] : '');
4806
+    return (isset($infos[$info]) ? $infos[$info] : '');
4807 4807
 }
4808 4808
 
4809 4809
 /**
@@ -4818,11 +4818,11 @@  discard block
 block discarded – undo
4818 4818
  *     Texte traduit du comptage, tel que '3 articles'
4819 4819
  */
4820 4820
 function objet_afficher_nb($nb, $objet) {
4821
-	if (!$nb) {
4822
-		return _T(objet_info($objet, 'info_aucun_objet'));
4823
-	} else {
4824
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb));
4825
-	}
4821
+    if (!$nb) {
4822
+        return _T(objet_info($objet, 'info_aucun_objet'));
4823
+    } else {
4824
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb));
4825
+    }
4826 4826
 }
4827 4827
 
4828 4828
 /**
@@ -4834,11 +4834,11 @@  discard block
 block discarded – undo
4834 4834
  * @return string
4835 4835
  */
4836 4836
 function objet_icone($objet, $taille = 24, $class='') {
4837
-	$icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4838
-	$icone = chemin_image($icone);
4839
-	$balise_img = charger_filtre('balise_img');
4837
+    $icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4838
+    $icone = chemin_image($icone);
4839
+    $balise_img = charger_filtre('balise_img');
4840 4840
 
4841
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4841
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4842 4842
 }
4843 4843
 
4844 4844
 /**
@@ -4859,12 +4859,12 @@  discard block
 block discarded – undo
4859 4859
  * @return string
4860 4860
  */
4861 4861
 function objet_T($objet, $chaine, $args = array(), $options = array()){
4862
-	$chaine = explode(':',$chaine);
4863
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4864
-		return $t;
4865
-	}
4866
-	$chaine = implode(':',$chaine);
4867
-	return _T($chaine, $args, $options);
4862
+    $chaine = explode(':',$chaine);
4863
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4864
+        return $t;
4865
+    }
4866
+    $chaine = implode(':',$chaine);
4867
+    return _T($chaine, $args, $options);
4868 4868
 }
4869 4869
 
4870 4870
 /**
@@ -4878,17 +4878,17 @@  discard block
 block discarded – undo
4878 4878
  * @return string      Code HTML
4879 4879
  */
4880 4880
 function insert_head_css_conditionnel($flux) {
4881
-	if (strpos($flux, '<!-- insert_head_css -->') === false
4882
-		and $p = strpos($flux, '<!-- insert_head -->')
4883
-	) {
4884
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
4885
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
4886
-			$p = $p1;
4887
-		}
4888
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4889
-	}
4881
+    if (strpos($flux, '<!-- insert_head_css -->') === false
4882
+        and $p = strpos($flux, '<!-- insert_head -->')
4883
+    ) {
4884
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
4885
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
4886
+            $p = $p1;
4887
+        }
4888
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4889
+    }
4890 4890
 
4891
-	return $flux;
4891
+    return $flux;
4892 4892
 }
4893 4893
 
4894 4894
 /**
@@ -4909,69 +4909,69 @@  discard block
 block discarded – undo
4909 4909
  * @return string
4910 4910
  */
4911 4911
 function produire_fond_statique($fond, $contexte = array(), $options = array(), $connect = '') {
4912
-	if (isset($contexte['format'])) {
4913
-		$extension = $contexte['format'];
4914
-		unset($contexte['format']);
4915
-	} else {
4916
-		$extension = "html";
4917
-		if (preg_match(',[.](css|js|json)$,', $fond, $m)) {
4918
-			$extension = $m[1];
4919
-		}
4920
-	}
4921
-	// recuperer le contenu produit par le squelette
4922
-	$options['raw'] = true;
4923
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
4924
-
4925
-	// calculer le nom de la css
4926
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4927
-	$nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4928
-	$contexte_implicite = calculer_contexte_implicite();
4929
-
4930
-	// par defaut on hash selon les contextes qui sont a priori moins variables
4931
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4932
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4933
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
4934
-		$hash = md5($contexte_implicite['host'] . '::'. $cache);
4935
-	}
4936
-	else {
4937
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4938
-		ksort($contexte);
4939
-		$hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
4940
-	}
4941
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4942
-
4943
-	// mettre a jour le fichier si il n'existe pas
4944
-	// ou trop ancien
4945
-	// le dernier fichier produit est toujours suffixe par .last
4946
-	// et recopie sur le fichier cible uniquement si il change
4947
-	if (!file_exists($filename)
4948
-		or !file_exists($filename . ".last")
4949
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4950
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4951
-	) {
4952
-		$contenu = $cache['texte'];
4953
-		// passer les urls en absolu si c'est une css
4954
-		if ($extension == "css") {
4955
-			$contenu = urls_absolues_css($contenu,
4956
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond));
4957
-		}
4958
-
4959
-		$comment = '';
4960
-		// ne pas insérer de commentaire si c'est du json
4961
-		if ($extension != "json") {
4962
-			$comment = "/* #PRODUIRE{fond=$fond";
4963
-			foreach ($contexte as $k => $v) {
4964
-				$comment .= ",$k=$v";
4965
-			}
4966
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4967
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4968
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
4969
-		}
4970
-		// et ecrire le fichier si il change
4971
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
4972
-	}
4973
-
4974
-	return timestamp($filename);
4912
+    if (isset($contexte['format'])) {
4913
+        $extension = $contexte['format'];
4914
+        unset($contexte['format']);
4915
+    } else {
4916
+        $extension = "html";
4917
+        if (preg_match(',[.](css|js|json)$,', $fond, $m)) {
4918
+            $extension = $m[1];
4919
+        }
4920
+    }
4921
+    // recuperer le contenu produit par le squelette
4922
+    $options['raw'] = true;
4923
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
4924
+
4925
+    // calculer le nom de la css
4926
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4927
+    $nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4928
+    $contexte_implicite = calculer_contexte_implicite();
4929
+
4930
+    // par defaut on hash selon les contextes qui sont a priori moins variables
4931
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4932
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4933
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
4934
+        $hash = md5($contexte_implicite['host'] . '::'. $cache);
4935
+    }
4936
+    else {
4937
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4938
+        ksort($contexte);
4939
+        $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
4940
+    }
4941
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4942
+
4943
+    // mettre a jour le fichier si il n'existe pas
4944
+    // ou trop ancien
4945
+    // le dernier fichier produit est toujours suffixe par .last
4946
+    // et recopie sur le fichier cible uniquement si il change
4947
+    if (!file_exists($filename)
4948
+        or !file_exists($filename . ".last")
4949
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4950
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4951
+    ) {
4952
+        $contenu = $cache['texte'];
4953
+        // passer les urls en absolu si c'est une css
4954
+        if ($extension == "css") {
4955
+            $contenu = urls_absolues_css($contenu,
4956
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond));
4957
+        }
4958
+
4959
+        $comment = '';
4960
+        // ne pas insérer de commentaire si c'est du json
4961
+        if ($extension != "json") {
4962
+            $comment = "/* #PRODUIRE{fond=$fond";
4963
+            foreach ($contexte as $k => $v) {
4964
+                $comment .= ",$k=$v";
4965
+            }
4966
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4967
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4968
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
4969
+        }
4970
+        // et ecrire le fichier si il change
4971
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
4972
+    }
4973
+
4974
+    return timestamp($filename);
4975 4975
 }
4976 4976
 
4977 4977
 /**
@@ -4984,14 +4984,14 @@  discard block
 block discarded – undo
4984 4984
  *    $fichier auquel on a ajouté le timestamp
4985 4985
  */
4986 4986
 function timestamp($fichier) {
4987
-	if (!$fichier
4988
-		or !file_exists($fichier)
4989
-		or !$m = filemtime($fichier)
4990
-	) {
4991
-		return $fichier;
4992
-	}
4987
+    if (!$fichier
4988
+        or !file_exists($fichier)
4989
+        or !$m = filemtime($fichier)
4990
+    ) {
4991
+        return $fichier;
4992
+    }
4993 4993
 
4994
-	return "$fichier?$m";
4994
+    return "$fichier?$m";
4995 4995
 }
4996 4996
 
4997 4997
 /**
@@ -5001,11 +5001,11 @@  discard block
 block discarded – undo
5001 5001
  * @return string
5002 5002
  */
5003 5003
 function supprimer_timestamp($url) {
5004
-	if (strpos($url, "?") === false) {
5005
-		return $url;
5006
-	}
5004
+    if (strpos($url, "?") === false) {
5005
+        return $url;
5006
+    }
5007 5007
 
5008
-	return preg_replace(",\?[[:digit:]]+$,", "", $url);
5008
+    return preg_replace(",\?[[:digit:]]+$,", "", $url);
5009 5009
 }
5010 5010
 
5011 5011
 /**
@@ -5020,9 +5020,9 @@  discard block
 block discarded – undo
5020 5020
  * @return string
5021 5021
  */
5022 5022
 function filtre_nettoyer_titre_email_dist($titre) {
5023
-	include_spip('inc/envoyer_mail');
5023
+    include_spip('inc/envoyer_mail');
5024 5024
 
5025
-	return nettoyer_titre_email($titre);
5025
+    return nettoyer_titre_email($titre);
5026 5026
 }
5027 5027
 
5028 5028
 /**
@@ -5044,19 +5044,19 @@  discard block
 block discarded – undo
5044 5044
  * @return string
5045 5045
  */
5046 5046
 function filtre_chercher_rubrique_dist(
5047
-	$titre,
5048
-	$id_objet,
5049
-	$id_parent,
5050
-	$objet,
5051
-	$id_secteur,
5052
-	$restreint,
5053
-	$actionable = false,
5054
-	$retour_sans_cadre = false
5047
+    $titre,
5048
+    $id_objet,
5049
+    $id_parent,
5050
+    $objet,
5051
+    $id_secteur,
5052
+    $restreint,
5053
+    $actionable = false,
5054
+    $retour_sans_cadre = false
5055 5055
 ) {
5056
-	include_spip('inc/filtres_ecrire');
5056
+    include_spip('inc/filtres_ecrire');
5057 5057
 
5058
-	return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable,
5059
-		$retour_sans_cadre);
5058
+    return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable,
5059
+        $retour_sans_cadre);
5060 5060
 }
5061 5061
 
5062 5062
 /**
@@ -5085,56 +5085,56 @@  discard block
 block discarded – undo
5085 5085
  *     Chaîne vide si l'accès est autorisé
5086 5086
  */
5087 5087
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5088
-	if ($ok) {
5089
-		return '';
5090
-	}
5091
-
5092
-	// Vider tous les tampons
5093
-	$level = @ob_get_level();
5094
-	while ($level--) {
5095
-		@ob_end_clean();
5096
-	}
5097
-
5098
-	include_spip('inc/headers');
5099
-
5100
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5101
-	if ($url) {
5102
-		redirige_par_entete($url, '', $statut);
5103
-	}
5104
-
5105
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5106
-	if (!is_numeric($statut) and is_null($message)) {
5107
-		$message = $statut;
5108
-		$statut = 0;
5109
-	}
5110
-	if (!$message) {
5111
-		$message = '';
5112
-	}
5113
-	$statut = intval($statut);
5114
-
5115
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5116
-	if (test_espace_prive()) {
5117
-		if (!$statut or !in_array($statut, array(404, 403))) {
5118
-			$statut = 403;
5119
-		}
5120
-		http_status(403);
5121
-		$echec = charger_fonction('403', 'exec');
5122
-		$echec($message);
5123
-	} else {
5124
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5125
-		if (!$statut) {
5126
-			$statut = 404;
5127
-		}
5128
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5129
-		http_status($statut);
5130
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5131
-		if ($statut >= 400) {
5132
-			echo recuperer_fond("$statut", array('erreur' => $message));
5133
-		}
5134
-	}
5135
-
5136
-
5137
-	exit;
5088
+    if ($ok) {
5089
+        return '';
5090
+    }
5091
+
5092
+    // Vider tous les tampons
5093
+    $level = @ob_get_level();
5094
+    while ($level--) {
5095
+        @ob_end_clean();
5096
+    }
5097
+
5098
+    include_spip('inc/headers');
5099
+
5100
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5101
+    if ($url) {
5102
+        redirige_par_entete($url, '', $statut);
5103
+    }
5104
+
5105
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5106
+    if (!is_numeric($statut) and is_null($message)) {
5107
+        $message = $statut;
5108
+        $statut = 0;
5109
+    }
5110
+    if (!$message) {
5111
+        $message = '';
5112
+    }
5113
+    $statut = intval($statut);
5114
+
5115
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5116
+    if (test_espace_prive()) {
5117
+        if (!$statut or !in_array($statut, array(404, 403))) {
5118
+            $statut = 403;
5119
+        }
5120
+        http_status(403);
5121
+        $echec = charger_fonction('403', 'exec');
5122
+        $echec($message);
5123
+    } else {
5124
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5125
+        if (!$statut) {
5126
+            $statut = 404;
5127
+        }
5128
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5129
+        http_status($statut);
5130
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5131
+        if ($statut >= 400) {
5132
+            echo recuperer_fond("$statut", array('erreur' => $message));
5133
+        }
5134
+    }
5135
+
5136
+
5137
+    exit;
5138 5138
 }
5139 5139
 
5140 5140
 /**
@@ -5145,11 +5145,11 @@  discard block
 block discarded – undo
5145 5145
  * @return string
5146 5146
  */
5147 5147
 function filtre_compacte_dist($source, $format = null) {
5148
-	if (function_exists('compacte')) {
5149
-		return compacte($source, $format);
5150
-	}
5148
+    if (function_exists('compacte')) {
5149
+        return compacte($source, $format);
5150
+    }
5151 5151
 
5152
-	return $source;
5152
+    return $source;
5153 5153
 }
5154 5154
 
5155 5155
 
@@ -5161,31 +5161,31 @@  discard block
 block discarded – undo
5161 5161
  * @return string
5162 5162
  */
5163 5163
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
5164
-	$l = strlen($passe);
5165
-
5166
-	if ($l<=8 or !$afficher_partiellement){
5167
-		if (!$l) {
5168
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5169
-		}
5170
-		return str_pad('',$afficher_partiellement ? $l : 16,'*');
5171
-	}
5172
-
5173
-	if (is_null($portion_pourcent)) {
5174
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5175
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5176
-		}
5177
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5178
-	}
5179
-	if ($portion_pourcent >= 100) {
5180
-		return $passe;
5181
-	}
5182
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5183
-	$e = max($e, 0);
5184
-	$mid = str_pad('',$l-2*$e,'*');
5185
-	if ($e>0 and strlen($mid)>8){
5186
-		$mid = '***...***';
5187
-	}
5188
-	return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : '');
5164
+    $l = strlen($passe);
5165
+
5166
+    if ($l<=8 or !$afficher_partiellement){
5167
+        if (!$l) {
5168
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5169
+        }
5170
+        return str_pad('',$afficher_partiellement ? $l : 16,'*');
5171
+    }
5172
+
5173
+    if (is_null($portion_pourcent)) {
5174
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5175
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5176
+        }
5177
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5178
+    }
5179
+    if ($portion_pourcent >= 100) {
5180
+        return $passe;
5181
+    }
5182
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5183
+    $e = max($e, 0);
5184
+    $mid = str_pad('',$l-2*$e,'*');
5185
+    if ($e>0 and strlen($mid)>8){
5186
+        $mid = '***...***';
5187
+    }
5188
+    return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : '');
5189 5189
 }
5190 5190
 
5191 5191
 
@@ -5206,64 +5206,64 @@  discard block
 block discarded – undo
5206 5206
  */
5207 5207
 function identifiant_slug($texte, $type = '', $options = array()) {
5208 5208
 
5209
-	$original = $texte;
5210
-	$separateur = (isset($options['separateur'])?$options['separateur']:'_');
5211
-	$longueur_maxi = (isset($options['longueur_maxi'])?$options['longueur_maxi']:60);
5212
-	$longueur_mini = (isset($options['longueur_mini'])?$options['longueur_mini']:0);
5209
+    $original = $texte;
5210
+    $separateur = (isset($options['separateur'])?$options['separateur']:'_');
5211
+    $longueur_maxi = (isset($options['longueur_maxi'])?$options['longueur_maxi']:60);
5212
+    $longueur_mini = (isset($options['longueur_mini'])?$options['longueur_mini']:0);
5213 5213
 
5214
-	if (!function_exists('translitteration')) {
5215
-		include_spip('inc/charsets');
5216
-	}
5214
+    if (!function_exists('translitteration')) {
5215
+        include_spip('inc/charsets');
5216
+    }
5217 5217
 
5218
-	// pas de balise html
5219
-	if (strpos($texte, '<') !== false) {
5220
-		$texte = strip_tags($texte);
5221
-	}
5222
-	if (strpos($texte, '&') !== false) {
5223
-		$texte = unicode2charset($texte);
5224
-	}
5225
-	// On enlève les espaces indésirables
5226
-	$texte = trim($texte);
5218
+    // pas de balise html
5219
+    if (strpos($texte, '<') !== false) {
5220
+        $texte = strip_tags($texte);
5221
+    }
5222
+    if (strpos($texte, '&') !== false) {
5223
+        $texte = unicode2charset($texte);
5224
+    }
5225
+    // On enlève les espaces indésirables
5226
+    $texte = trim($texte);
5227 5227
 
5228
-	// On enlève les accents et cie
5229
-	$texte = translitteration($texte);
5228
+    // On enlève les accents et cie
5229
+    $texte = translitteration($texte);
5230 5230
 
5231
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5232
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5231
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5232
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5233 5233
 
5234
-	// nettoyer les doubles occurences du separateur si besoin
5235
-	while (strpos($texte, "$separateur$separateur") !== false) {
5236
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5237
-	}
5234
+    // nettoyer les doubles occurences du separateur si besoin
5235
+    while (strpos($texte, "$separateur$separateur") !== false) {
5236
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5237
+    }
5238 5238
 
5239
-	// pas de separateur au debut ni a la fin
5240
-	$texte = trim($texte, $separateur);
5239
+    // pas de separateur au debut ni a la fin
5240
+    $texte = trim($texte, $separateur);
5241 5241
 
5242
-	// en minuscules
5243
-	$texte = strtolower($texte);
5242
+    // en minuscules
5243
+    $texte = strtolower($texte);
5244 5244
 
5245
-	switch ($type) {
5246
-		case 'class':
5247
-		case 'id':
5248
-		case 'anchor':
5249
-			if (preg_match(',^\d,', $texte)) {
5250
-				$texte = substr($type, 0, 1).$texte;
5251
-			}
5252
-	}
5245
+    switch ($type) {
5246
+        case 'class':
5247
+        case 'id':
5248
+        case 'anchor':
5249
+            if (preg_match(',^\d,', $texte)) {
5250
+                $texte = substr($type, 0, 1).$texte;
5251
+            }
5252
+    }
5253 5253
 
5254
-	if (strlen($texte)>$longueur_maxi) {
5255
-		$texte = substr($texte, 0, $longueur_maxi);
5256
-	}
5254
+    if (strlen($texte)>$longueur_maxi) {
5255
+        $texte = substr($texte, 0, $longueur_maxi);
5256
+    }
5257 5257
 
5258
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5259
-		if (preg_match(',^\d,', $texte)) {
5260
-			$texte = ($type ? substr($type,0,1) : "s") . $texte;
5261
-		}
5262
-		$texte .= $separateur . md5($original);
5263
-		$texte = substr($texte, 0, $longueur_mini);
5264
-	}
5258
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5259
+        if (preg_match(',^\d,', $texte)) {
5260
+            $texte = ($type ? substr($type,0,1) : "s") . $texte;
5261
+        }
5262
+        $texte .= $separateur . md5($original);
5263
+        $texte = substr($texte, 0, $longueur_mini);
5264
+    }
5265 5265
 
5266
-	return $texte;
5266
+    return $texte;
5267 5267
 }
5268 5268
 
5269 5269
 
@@ -5278,14 +5278,14 @@  discard block
 block discarded – undo
5278 5278
  * @exemple `<:info_maximum|uniformiser_label:>`
5279 5279
  */
5280 5280
 function uniformiser_label(string $text, bool $ucfirst = true) : string {
5281
-	$label = rtrim($text, " : \t\n\r\0\x0B\xc2\xa0");
5282
-	if ($label and $label[-1] === ';') {
5283
-		$label = preg_replace("#(\&nbsp;)+$#", "", $label);
5284
-	}
5285
-	if ($ucfirst) {
5286
-		$label = spip_ucfirst($label);
5287
-	}
5288
-	return $label;
5281
+    $label = rtrim($text, " : \t\n\r\0\x0B\xc2\xa0");
5282
+    if ($label and $label[-1] === ';') {
5283
+        $label = preg_replace("#(\&nbsp;)+$#", "", $label);
5284
+    }
5285
+    if ($ucfirst) {
5286
+        $label = spip_ucfirst($label);
5287
+    }
5288
+    return $label;
5289 5289
 }
5290 5290
 
5291 5291
 
@@ -5297,19 +5297,19 @@  discard block
 block discarded – undo
5297 5297
  * @return array
5298 5298
  */
5299 5299
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5300
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5301
-		return [];
5302
-	}
5300
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5301
+        return [];
5302
+    }
5303 5303
 
5304
-	// compatibilite signature inversee
5305
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5306
-		list($objet, $id_objet) = [$id_objet, $objet];
5307
-	}
5304
+    // compatibilite signature inversee
5305
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5306
+        list($objet, $id_objet) = [$id_objet, $objet];
5307
+    }
5308 5308
 
5309
-	if (!function_exists($fonction)) {
5310
-		include_spip('base/objets');
5311
-	}
5312
-	return $fonction($objet, $id_objet);
5309
+    if (!function_exists($fonction)) {
5310
+        include_spip('base/objets');
5311
+    }
5312
+    return $fonction($objet, $id_objet);
5313 5313
 }
5314 5314
 
5315 5315
 
@@ -5324,7 +5324,7 @@  discard block
 block discarded – undo
5324 5324
  * @return array
5325 5325
  */
5326 5326
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5327
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5327
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5328 5328
 }
5329 5329
 
5330 5330
 /**
@@ -5338,7 +5338,7 @@  discard block
 block discarded – undo
5338 5338
  * @return array
5339 5339
  */
5340 5340
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5341
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5341
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5342 5342
 }
5343 5343
 
5344 5344
 /**
@@ -5352,7 +5352,7 @@  discard block
 block discarded – undo
5352 5352
  * @return array
5353 5353
  */
5354 5354
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5355
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5355
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5356 5356
 }
5357 5357
 
5358 5358
 /**
@@ -5366,6 +5366,6 @@  discard block
 block discarded – undo
5366 5366
  * @return array
5367 5367
  */
5368 5368
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5369
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5369
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5370 5370
 }
5371 5371
 
Please login to merge, or discard this patch.