Completed
Push — master ( c19252...72e794 )
by cam
06:08
created
prive/ajax_selecteur_fonctions.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (!defined('_ECRIRE_INC_VERSION')) {
4
-	return;
4
+    return;
5 5
 }
6 6
 
7 7
 include_spip('formulaires/selecteur/generique_fonctions');
Please login to merge, or discard this patch.
ecrire/base/objets.php 2 patches
Indentation   +942 added lines, -942 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,432 +53,432 @@  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
-				'rechercher_champs' => array(
165
-					'surtitre' => 5,
166
-					'titre' => 8,
167
-					'soustitre' => 5,
168
-					'chapo' => 3,
169
-					'texte' => 1,
170
-					'ps' => 1,
171
-					'nom_site' => 1,
172
-					'url_site' => 1,
173
-					'descriptif' => 4
174
-				),
175
-				'rechercher_jointures' => array(
176
-					'auteur' => array('nom' => 10),
177
-				),
178
-				'statut' => array(
179
-					array(
180
-						'champ' => 'statut',
181
-						'publie' => 'publie',
182
-						'previsu' => 'publie,prop,prepa/auteur',
183
-						'post_date' => 'date',
184
-						'exception' => array('statut', 'tout')
185
-					)
186
-				),
187
-				'statut_titres' => array(
188
-					'prepa' => 'info_article_redaction',
189
-					'prop' => 'info_article_propose',
190
-					'publie' => 'info_article_publie',
191
-					'refuse' => 'info_article_refuse',
192
-					'poubelle' => 'info_article_supprime'
193
-				),
194
-				'statut_textes_instituer' => array(
195
-					'prepa' => 'texte_statut_en_cours_redaction',
196
-					'prop' => 'texte_statut_propose_evaluation',
197
-					'publie' => 'texte_statut_publie',
198
-					'refuse' => 'texte_statut_refuse',
199
-					'poubelle' => 'texte_statut_poubelle',
200
-				),
201
-				'texte_changer_statut' => 'texte_article_statut',
202
-				'aide_changer_statut' => 'artstatut',
203
-				'tables_jointures' => array(
204
-					'profondeur' => 'rubriques',
205
-					#'id_auteur' => 'auteurs_liens' // declaration generique plus bas
206
-				),
207
-			),
208
-			'spip_auteurs' => array(
209
-				'page' => 'auteur',
210
-				'texte_retour' => 'icone_retour',
211
-				'texte_ajouter' => 'titre_ajouter_un_auteur',
212
-				'texte_modifier' => 'admin_modifier_auteur',
213
-				'texte_objets' => 'icone_auteurs',
214
-				'texte_objet' => 'public:auteur',
215
-				'info_aucun_objet' => 'info_aucun_auteur',
216
-				'info_1_objet' => 'info_1_auteur',
217
-				'info_nb_objets' => 'info_nb_auteurs',
218
-				'texte_logo_objet' => 'logo_auteur',
219
-				'texte_creer_associer' => 'creer_et_associer_un_auteur',
220
-				'titre' => "nom AS titre, '' AS lang",
221
-				'date' => 'date',
222
-				'principale' => 'oui',
223
-				'champs_editables' => array('nom', 'email', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'),
224
-				'champs_versionnes' => array('nom', 'bio', 'email', 'nom_site', 'url_site', 'login'),
225
-				'field' => array(
226
-					'id_auteur' => 'bigint(21) NOT NULL',
227
-					'nom' => "text DEFAULT '' NOT NULL",
228
-					'bio' => "text DEFAULT '' NOT NULL",
229
-					'email' => "tinytext DEFAULT '' NOT NULL",
230
-					'nom_site' => "tinytext DEFAULT '' NOT NULL",
231
-					'url_site' => "text DEFAULT '' NOT NULL",
232
-					'login' => 'VARCHAR(255) BINARY',
233
-					'pass' => "tinytext DEFAULT '' NOT NULL",
234
-					'low_sec' => "tinytext DEFAULT '' NOT NULL",
235
-					'statut' => "varchar(255)  DEFAULT '0' NOT NULL",
236
-					'webmestre' => "varchar(3)  DEFAULT 'non' NOT NULL",
237
-					'maj' => 'TIMESTAMP',
238
-					'pgp' => "TEXT DEFAULT '' NOT NULL",
239
-					'htpass' => "tinytext DEFAULT '' NOT NULL",
240
-					'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
241
-					'alea_actuel' => 'tinytext',
242
-					'alea_futur' => 'tinytext',
243
-					'prefs' => 'text',
244
-					'cookie_oubli' => 'tinytext',
245
-					'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL",
246
-					'lang' => "VARCHAR(10) DEFAULT '' NOT NULL"
247
-				),
248
-				'key' => array(
249
-					'PRIMARY KEY' => 'id_auteur',
250
-					'KEY login' => 'login',
251
-					'KEY statut' => 'statut',
252
-					'KEY en_ligne' => 'en_ligne',
253
-				),
254
-				'join' => array(
255
-					'id_auteur' => 'id_auteur',
256
-					'login' => 'login'
257
-				),
258
-				'rechercher_champs' => array(
259
-					'nom' => 5,
260
-					'bio' => 1,
261
-					'email' => 1,
262
-					'nom_site' => 1,
263
-					'url_site' => 1,
264
-					'login' => 1
265
-				),
266
-				// 2 conditions pour les auteurs : statut!=poubelle,
267
-				// et avoir des articles publies
268
-				'statut' => array(
269
-					array(
270
-						'champ' => 'statut',
271
-						'publie' => '!5poubelle',
272
-						'previsu' => '!5poubelle',
273
-						'exception' => 'statut'
274
-					),
275
-					array(
276
-						'champ' => array(
277
-							array('spip_auteurs_liens', 'id_auteur'),
278
-							array(
279
-								'spip_articles',
280
-								array('id_objet', 'id_article', 'objet', 'article')
281
-							),
282
-							'statut'
283
-						),
284
-						'publie' => 'publie',
285
-						'previsu' => '!',
286
-						'post_date' => 'date',
287
-						'exception' => array('statut', 'lien', 'tout')
288
-					),
289
-				),
290
-				'statut_images' => array(
291
-					'auteur-6forum-16.png',
292
-					'0minirezo' => 'auteur-0minirezo-16.png',
293
-					'1comite' => 'auteur-1comite-16.png',
294
-					'6forum' => 'auteur-6forum-16.png',
295
-					'5poubelle' => 'auteur-5poubelle-16.png',
296
-					'nouveau' => ''
297
-				),
298
-				'statut_titres' => array(
299
-					'titre_image_visiteur',
300
-					'0minirezo' => 'titre_image_administrateur',
301
-					'1comite' => 'titre_image_redacteur_02',
302
-					'6forum' => 'titre_image_visiteur',
303
-					'5poubelle' => 'titre_image_auteur_supprime',
304
-				),
305
-				'tables_jointures' => array(#'auteurs_liens' // declaration generique plus bas
306
-				),
307
-			),
308
-			'spip_rubriques' => array(
309
-				'page' => 'rubrique',
310
-				'url_voir' => 'rubrique',
311
-				'url_edit' => 'rubrique_edit',
312
-				'texte_retour' => 'icone_retour',
313
-				'texte_objets' => 'public:rubriques',
314
-				'texte_objet' => 'public:rubrique',
315
-				'texte_modifier' => 'icone_modifier_rubrique',
316
-				'texte_creer' => 'icone_creer_rubrique',
317
-				'texte_ajouter' => 'titre_ajouter_une_rubrique',
318
-				'texte_creer_associer' => 'creer_et_associer_une_rubrique',
319
-				'info_aucun_objet' => 'info_aucun_rubrique',
320
-				'info_1_objet' => 'info_1_rubrique',
321
-				'info_nb_objets' => 'info_nb_rubriques',
322
-				'texte_logo_objet' => 'logo_rubrique',
323
-				'texte_langue_objet' => 'titre_langue_rubrique',
324
-				'texte_definir_comme_traduction_objet' => 'texte_definir_comme_traduction_rubrique',
325
-				'titre' => 'titre, lang',
326
-				'date' => 'date',
327
-				'principale' => 'oui',
328
-				'introduction_longueur' => '600',
329
-				'champs_editables' => array('titre', 'texte', 'descriptif', 'extra'),
330
-				'champs_versionnes' => array('titre', 'descriptif', 'texte'),
331
-				'field' => array(
332
-					'id_rubrique' => 'bigint(21) NOT NULL',
333
-					'id_parent' => "bigint(21) DEFAULT '0' NOT NULL",
334
-					'titre' => "text DEFAULT '' NOT NULL",
335
-					'descriptif' => "text DEFAULT '' NOT NULL",
336
-					'texte' => "longtext DEFAULT '' NOT NULL",
337
-					'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL",
338
-					'maj' => 'TIMESTAMP',
339
-					'statut' => "varchar(10) DEFAULT '0' NOT NULL",
340
-					'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
341
-					'lang' => "VARCHAR(10) DEFAULT '' NOT NULL",
342
-					'langue_choisie' => "VARCHAR(3) DEFAULT 'non'",
343
-					'statut_tmp' => "varchar(10) DEFAULT '0' NOT NULL",
344
-					'date_tmp' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
345
-					'profondeur' => "smallint(5) DEFAULT '0' NOT NULL"
346
-				),
347
-				'key' => array(
348
-					'PRIMARY KEY' => 'id_rubrique',
349
-					'KEY lang' => 'lang',
350
-					'KEY id_parent' => 'id_parent',
351
-				),
352
-				'rechercher_champs' => array(
353
-					'titre' => 8,
354
-					'descriptif' => 5,
355
-					'texte' => 1
356
-				),
357
-				'statut' => array(
358
-					array(
359
-						'champ' => 'statut',
360
-						'publie' => 'publie',
361
-						'previsu' => '!',
362
-						'exception' => array('statut', 'tout')
363
-					),
364
-				),
365
-				'tables_jointures' => array(#'id_auteur' => 'auteurs_liens' // declaration generique plus bas
366
-				),
367
-			),
368
-			// toutes les tables ont le droit a une jointure sur les auteurs
369
-			array('tables_jointures' => array('id_auteur' => 'auteurs_liens'))
370
-		);
371
-
372
-		// avant d'appeller les pipeline qui peuvent generer une reentrance a l'install
373
-		// initialiser la signature
374
-		$md5 = md5(serialize($infos_tables));
375
-
376
-		$GLOBALS['tables_principales'] = pipeline('declarer_tables_principales', $GLOBALS['tables_principales']);
377
-		$GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires', $GLOBALS['tables_auxiliaires']);
378
-		$infos_tables = pipeline('declarer_tables_objets_sql', $infos_tables);
379
-
380
-		// completer les informations manquantes ou implicites
381
-		$all = array();
382
-		foreach (array_keys($infos_tables) as $t) {
383
-			// les cles numeriques servent a declarer
384
-			// les proprietes applicables a tous les objets
385
-			// on les mets de cote
386
-			if (is_numeric($t)) {
387
-				$all = array_merge_recursive($all, $infos_tables[$t]);
388
-				unset($infos_tables[$t]);
389
-			} else {
390
-				$infos_tables[$t] = renseigner_table_objet_sql($t, $infos_tables[$t]);
391
-			}
392
-		}
393
-
394
-		// repercuter les proprietes generales communes a tous les objets
395
-		foreach (array_keys($infos_tables) as $t) {
396
-			foreach ($all as $i => $v) {
397
-				if (in_array($i, array('tables_jointures', 'champs_versionnes'))) {
398
-					$add = $all[$i];
399
-					// eviter les doublons de declaration de table jointure (ex des mots sur auteurs)
400
-					// pour les declarations generiques avec cles numeriques
401
-					if ($i == 'tables_jointures' and isset($infos_tables[$t][$i]) and count($infos_tables[$t][$i])) {
402
-						$doublons = array_intersect($infos_tables[$t][$i], $add);
403
-						foreach ($doublons as $d) {
404
-							if (is_numeric(array_search($d, $infos_tables[$t][$i]))
405
-								and is_numeric($k = array_search($d, $add))
406
-							) {
407
-								unset($add[$k]);
408
-							}
409
-						}
410
-					}
411
-					$infos_tables[$t][$i] = array_merge(isset($infos_tables[$t][$i]) ? $infos_tables[$t][$i] : array(), $add);
412
-				} else {
413
-					$infos_tables[$t][$i] = array_merge_recursive(
414
-						isset($infos_tables[$t][$i]) ? $infos_tables[$t][$i] : array(),
415
-						$all[$i]
416
-					);
417
-				}
418
-			}
419
-		}
420
-
421
-		// completer les tables principales et auxiliaires
422
-		// avec celles declarees uniquement dans declarer_table_objets_sql
423
-		// pour assurer la compat en transition
424
-		foreach ($infos_tables as $table => $infos) {
425
-			$principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires');
426
-			// memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx
427
-			// qui a ete appelle avant
428
-			$mem = (isset($GLOBALS[$principale_ou_auxiliaire][$table]) ? $GLOBALS[$principale_ou_auxiliaire][$table] : array());
429
-			// l'ajouter au tableau
430
-			$GLOBALS[$principale_ou_auxiliaire][$table] = array();
431
-			if (isset($infos['field']) and isset($infos['key'])) {
432
-				foreach (array('field', 'key', 'join') as $k) {
433
-					if (isset($infos_tables[$table][$k])) {
434
-						$GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k];
435
-					}
436
-				}
437
-			} else {
438
-				// ici on ne renvoie que les declarations, donc RIEN
439
-				// pour avoir la vrai description en base, il faut passer par trouver_table
440
-				$GLOBALS[$principale_ou_auxiliaire][$table] = array();
441
-			}
442
-			if (count($mem)) {
443
-				foreach (array_keys($mem) as $k) {
444
-					if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) {
445
-						$GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge(
446
-							$GLOBALS[$principale_ou_auxiliaire][$table][$k],
447
-							$mem[$k]
448
-						);
449
-					} else {
450
-						$GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k];
451
-					}
452
-				}
453
-			}
454
-		}
455
-
456
-		// recuperer les interfaces (table_titre, table_date)
457
-		// on ne le fait que dans un second temps pour que table_objet soit fonctionnel
458
-		// dans le pipeline de declarer_tables_interfaces
459
-		include_spip('public/interfaces');
460
-		foreach (array_keys($infos_tables) as $t) {
461
-			$infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]);
462
-		}
463
-
464
-		$deja_la = false;
465
-		// signature
466
-		$md5 = md5(serialize($infos_tables));
467
-	}
468
-	if ($table_sql === '::md5') {
469
-		return $md5;
470
-	}
471
-	if ($table_sql and !isset($infos_tables[$table_sql])) {
472
-		#$desc = renseigner_table_objet_sql($table_sql,$desc);
473
-		$desc = renseigner_table_objet_interfaces($table_sql, $desc);
474
-
475
-		return $desc;
476
-	}
477
-	if ($table_sql) {
478
-		return isset($infos_tables[$table_sql]) ? $infos_tables[$table_sql] : array();
479
-	}
480
-
481
-	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
+                'rechercher_champs' => array(
165
+                    'surtitre' => 5,
166
+                    'titre' => 8,
167
+                    'soustitre' => 5,
168
+                    'chapo' => 3,
169
+                    'texte' => 1,
170
+                    'ps' => 1,
171
+                    'nom_site' => 1,
172
+                    'url_site' => 1,
173
+                    'descriptif' => 4
174
+                ),
175
+                'rechercher_jointures' => array(
176
+                    'auteur' => array('nom' => 10),
177
+                ),
178
+                'statut' => array(
179
+                    array(
180
+                        'champ' => 'statut',
181
+                        'publie' => 'publie',
182
+                        'previsu' => 'publie,prop,prepa/auteur',
183
+                        'post_date' => 'date',
184
+                        'exception' => array('statut', 'tout')
185
+                    )
186
+                ),
187
+                'statut_titres' => array(
188
+                    'prepa' => 'info_article_redaction',
189
+                    'prop' => 'info_article_propose',
190
+                    'publie' => 'info_article_publie',
191
+                    'refuse' => 'info_article_refuse',
192
+                    'poubelle' => 'info_article_supprime'
193
+                ),
194
+                'statut_textes_instituer' => array(
195
+                    'prepa' => 'texte_statut_en_cours_redaction',
196
+                    'prop' => 'texte_statut_propose_evaluation',
197
+                    'publie' => 'texte_statut_publie',
198
+                    'refuse' => 'texte_statut_refuse',
199
+                    'poubelle' => 'texte_statut_poubelle',
200
+                ),
201
+                'texte_changer_statut' => 'texte_article_statut',
202
+                'aide_changer_statut' => 'artstatut',
203
+                'tables_jointures' => array(
204
+                    'profondeur' => 'rubriques',
205
+                    #'id_auteur' => 'auteurs_liens' // declaration generique plus bas
206
+                ),
207
+            ),
208
+            'spip_auteurs' => array(
209
+                'page' => 'auteur',
210
+                'texte_retour' => 'icone_retour',
211
+                'texte_ajouter' => 'titre_ajouter_un_auteur',
212
+                'texte_modifier' => 'admin_modifier_auteur',
213
+                'texte_objets' => 'icone_auteurs',
214
+                'texte_objet' => 'public:auteur',
215
+                'info_aucun_objet' => 'info_aucun_auteur',
216
+                'info_1_objet' => 'info_1_auteur',
217
+                'info_nb_objets' => 'info_nb_auteurs',
218
+                'texte_logo_objet' => 'logo_auteur',
219
+                'texte_creer_associer' => 'creer_et_associer_un_auteur',
220
+                'titre' => "nom AS titre, '' AS lang",
221
+                'date' => 'date',
222
+                'principale' => 'oui',
223
+                'champs_editables' => array('nom', 'email', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'),
224
+                'champs_versionnes' => array('nom', 'bio', 'email', 'nom_site', 'url_site', 'login'),
225
+                'field' => array(
226
+                    'id_auteur' => 'bigint(21) NOT NULL',
227
+                    'nom' => "text DEFAULT '' NOT NULL",
228
+                    'bio' => "text DEFAULT '' NOT NULL",
229
+                    'email' => "tinytext DEFAULT '' NOT NULL",
230
+                    'nom_site' => "tinytext DEFAULT '' NOT NULL",
231
+                    'url_site' => "text DEFAULT '' NOT NULL",
232
+                    'login' => 'VARCHAR(255) BINARY',
233
+                    'pass' => "tinytext DEFAULT '' NOT NULL",
234
+                    'low_sec' => "tinytext DEFAULT '' NOT NULL",
235
+                    'statut' => "varchar(255)  DEFAULT '0' NOT NULL",
236
+                    'webmestre' => "varchar(3)  DEFAULT 'non' NOT NULL",
237
+                    'maj' => 'TIMESTAMP',
238
+                    'pgp' => "TEXT DEFAULT '' NOT NULL",
239
+                    'htpass' => "tinytext DEFAULT '' NOT NULL",
240
+                    'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
241
+                    'alea_actuel' => 'tinytext',
242
+                    'alea_futur' => 'tinytext',
243
+                    'prefs' => 'text',
244
+                    'cookie_oubli' => 'tinytext',
245
+                    'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL",
246
+                    'lang' => "VARCHAR(10) DEFAULT '' NOT NULL"
247
+                ),
248
+                'key' => array(
249
+                    'PRIMARY KEY' => 'id_auteur',
250
+                    'KEY login' => 'login',
251
+                    'KEY statut' => 'statut',
252
+                    'KEY en_ligne' => 'en_ligne',
253
+                ),
254
+                'join' => array(
255
+                    'id_auteur' => 'id_auteur',
256
+                    'login' => 'login'
257
+                ),
258
+                'rechercher_champs' => array(
259
+                    'nom' => 5,
260
+                    'bio' => 1,
261
+                    'email' => 1,
262
+                    'nom_site' => 1,
263
+                    'url_site' => 1,
264
+                    'login' => 1
265
+                ),
266
+                // 2 conditions pour les auteurs : statut!=poubelle,
267
+                // et avoir des articles publies
268
+                'statut' => array(
269
+                    array(
270
+                        'champ' => 'statut',
271
+                        'publie' => '!5poubelle',
272
+                        'previsu' => '!5poubelle',
273
+                        'exception' => 'statut'
274
+                    ),
275
+                    array(
276
+                        'champ' => array(
277
+                            array('spip_auteurs_liens', 'id_auteur'),
278
+                            array(
279
+                                'spip_articles',
280
+                                array('id_objet', 'id_article', 'objet', 'article')
281
+                            ),
282
+                            'statut'
283
+                        ),
284
+                        'publie' => 'publie',
285
+                        'previsu' => '!',
286
+                        'post_date' => 'date',
287
+                        'exception' => array('statut', 'lien', 'tout')
288
+                    ),
289
+                ),
290
+                'statut_images' => array(
291
+                    'auteur-6forum-16.png',
292
+                    '0minirezo' => 'auteur-0minirezo-16.png',
293
+                    '1comite' => 'auteur-1comite-16.png',
294
+                    '6forum' => 'auteur-6forum-16.png',
295
+                    '5poubelle' => 'auteur-5poubelle-16.png',
296
+                    'nouveau' => ''
297
+                ),
298
+                'statut_titres' => array(
299
+                    'titre_image_visiteur',
300
+                    '0minirezo' => 'titre_image_administrateur',
301
+                    '1comite' => 'titre_image_redacteur_02',
302
+                    '6forum' => 'titre_image_visiteur',
303
+                    '5poubelle' => 'titre_image_auteur_supprime',
304
+                ),
305
+                'tables_jointures' => array(#'auteurs_liens' // declaration generique plus bas
306
+                ),
307
+            ),
308
+            'spip_rubriques' => array(
309
+                'page' => 'rubrique',
310
+                'url_voir' => 'rubrique',
311
+                'url_edit' => 'rubrique_edit',
312
+                'texte_retour' => 'icone_retour',
313
+                'texte_objets' => 'public:rubriques',
314
+                'texte_objet' => 'public:rubrique',
315
+                'texte_modifier' => 'icone_modifier_rubrique',
316
+                'texte_creer' => 'icone_creer_rubrique',
317
+                'texte_ajouter' => 'titre_ajouter_une_rubrique',
318
+                'texte_creer_associer' => 'creer_et_associer_une_rubrique',
319
+                'info_aucun_objet' => 'info_aucun_rubrique',
320
+                'info_1_objet' => 'info_1_rubrique',
321
+                'info_nb_objets' => 'info_nb_rubriques',
322
+                'texte_logo_objet' => 'logo_rubrique',
323
+                'texte_langue_objet' => 'titre_langue_rubrique',
324
+                'texte_definir_comme_traduction_objet' => 'texte_definir_comme_traduction_rubrique',
325
+                'titre' => 'titre, lang',
326
+                'date' => 'date',
327
+                'principale' => 'oui',
328
+                'introduction_longueur' => '600',
329
+                'champs_editables' => array('titre', 'texte', 'descriptif', 'extra'),
330
+                'champs_versionnes' => array('titre', 'descriptif', 'texte'),
331
+                'field' => array(
332
+                    'id_rubrique' => 'bigint(21) NOT NULL',
333
+                    'id_parent' => "bigint(21) DEFAULT '0' NOT NULL",
334
+                    'titre' => "text DEFAULT '' NOT NULL",
335
+                    'descriptif' => "text DEFAULT '' NOT NULL",
336
+                    'texte' => "longtext DEFAULT '' NOT NULL",
337
+                    'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL",
338
+                    'maj' => 'TIMESTAMP',
339
+                    'statut' => "varchar(10) DEFAULT '0' NOT NULL",
340
+                    'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
341
+                    'lang' => "VARCHAR(10) DEFAULT '' NOT NULL",
342
+                    'langue_choisie' => "VARCHAR(3) DEFAULT 'non'",
343
+                    'statut_tmp' => "varchar(10) DEFAULT '0' NOT NULL",
344
+                    'date_tmp' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
345
+                    'profondeur' => "smallint(5) DEFAULT '0' NOT NULL"
346
+                ),
347
+                'key' => array(
348
+                    'PRIMARY KEY' => 'id_rubrique',
349
+                    'KEY lang' => 'lang',
350
+                    'KEY id_parent' => 'id_parent',
351
+                ),
352
+                'rechercher_champs' => array(
353
+                    'titre' => 8,
354
+                    'descriptif' => 5,
355
+                    'texte' => 1
356
+                ),
357
+                'statut' => array(
358
+                    array(
359
+                        'champ' => 'statut',
360
+                        'publie' => 'publie',
361
+                        'previsu' => '!',
362
+                        'exception' => array('statut', 'tout')
363
+                    ),
364
+                ),
365
+                'tables_jointures' => array(#'id_auteur' => 'auteurs_liens' // declaration generique plus bas
366
+                ),
367
+            ),
368
+            // toutes les tables ont le droit a une jointure sur les auteurs
369
+            array('tables_jointures' => array('id_auteur' => 'auteurs_liens'))
370
+        );
371
+
372
+        // avant d'appeller les pipeline qui peuvent generer une reentrance a l'install
373
+        // initialiser la signature
374
+        $md5 = md5(serialize($infos_tables));
375
+
376
+        $GLOBALS['tables_principales'] = pipeline('declarer_tables_principales', $GLOBALS['tables_principales']);
377
+        $GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires', $GLOBALS['tables_auxiliaires']);
378
+        $infos_tables = pipeline('declarer_tables_objets_sql', $infos_tables);
379
+
380
+        // completer les informations manquantes ou implicites
381
+        $all = array();
382
+        foreach (array_keys($infos_tables) as $t) {
383
+            // les cles numeriques servent a declarer
384
+            // les proprietes applicables a tous les objets
385
+            // on les mets de cote
386
+            if (is_numeric($t)) {
387
+                $all = array_merge_recursive($all, $infos_tables[$t]);
388
+                unset($infos_tables[$t]);
389
+            } else {
390
+                $infos_tables[$t] = renseigner_table_objet_sql($t, $infos_tables[$t]);
391
+            }
392
+        }
393
+
394
+        // repercuter les proprietes generales communes a tous les objets
395
+        foreach (array_keys($infos_tables) as $t) {
396
+            foreach ($all as $i => $v) {
397
+                if (in_array($i, array('tables_jointures', 'champs_versionnes'))) {
398
+                    $add = $all[$i];
399
+                    // eviter les doublons de declaration de table jointure (ex des mots sur auteurs)
400
+                    // pour les declarations generiques avec cles numeriques
401
+                    if ($i == 'tables_jointures' and isset($infos_tables[$t][$i]) and count($infos_tables[$t][$i])) {
402
+                        $doublons = array_intersect($infos_tables[$t][$i], $add);
403
+                        foreach ($doublons as $d) {
404
+                            if (is_numeric(array_search($d, $infos_tables[$t][$i]))
405
+                                and is_numeric($k = array_search($d, $add))
406
+                            ) {
407
+                                unset($add[$k]);
408
+                            }
409
+                        }
410
+                    }
411
+                    $infos_tables[$t][$i] = array_merge(isset($infos_tables[$t][$i]) ? $infos_tables[$t][$i] : array(), $add);
412
+                } else {
413
+                    $infos_tables[$t][$i] = array_merge_recursive(
414
+                        isset($infos_tables[$t][$i]) ? $infos_tables[$t][$i] : array(),
415
+                        $all[$i]
416
+                    );
417
+                }
418
+            }
419
+        }
420
+
421
+        // completer les tables principales et auxiliaires
422
+        // avec celles declarees uniquement dans declarer_table_objets_sql
423
+        // pour assurer la compat en transition
424
+        foreach ($infos_tables as $table => $infos) {
425
+            $principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires');
426
+            // memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx
427
+            // qui a ete appelle avant
428
+            $mem = (isset($GLOBALS[$principale_ou_auxiliaire][$table]) ? $GLOBALS[$principale_ou_auxiliaire][$table] : array());
429
+            // l'ajouter au tableau
430
+            $GLOBALS[$principale_ou_auxiliaire][$table] = array();
431
+            if (isset($infos['field']) and isset($infos['key'])) {
432
+                foreach (array('field', 'key', 'join') as $k) {
433
+                    if (isset($infos_tables[$table][$k])) {
434
+                        $GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k];
435
+                    }
436
+                }
437
+            } else {
438
+                // ici on ne renvoie que les declarations, donc RIEN
439
+                // pour avoir la vrai description en base, il faut passer par trouver_table
440
+                $GLOBALS[$principale_ou_auxiliaire][$table] = array();
441
+            }
442
+            if (count($mem)) {
443
+                foreach (array_keys($mem) as $k) {
444
+                    if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) {
445
+                        $GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge(
446
+                            $GLOBALS[$principale_ou_auxiliaire][$table][$k],
447
+                            $mem[$k]
448
+                        );
449
+                    } else {
450
+                        $GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k];
451
+                    }
452
+                }
453
+            }
454
+        }
455
+
456
+        // recuperer les interfaces (table_titre, table_date)
457
+        // on ne le fait que dans un second temps pour que table_objet soit fonctionnel
458
+        // dans le pipeline de declarer_tables_interfaces
459
+        include_spip('public/interfaces');
460
+        foreach (array_keys($infos_tables) as $t) {
461
+            $infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]);
462
+        }
463
+
464
+        $deja_la = false;
465
+        // signature
466
+        $md5 = md5(serialize($infos_tables));
467
+    }
468
+    if ($table_sql === '::md5') {
469
+        return $md5;
470
+    }
471
+    if ($table_sql and !isset($infos_tables[$table_sql])) {
472
+        #$desc = renseigner_table_objet_sql($table_sql,$desc);
473
+        $desc = renseigner_table_objet_interfaces($table_sql, $desc);
474
+
475
+        return $desc;
476
+    }
477
+    if ($table_sql) {
478
+        return isset($infos_tables[$table_sql]) ? $infos_tables[$table_sql] : array();
479
+    }
480
+
481
+    return $infos_tables;
482 482
 }
483 483
 
484 484
 
@@ -493,27 +493,27 @@  discard block
 block discarded – undo
493 493
  **/
494 494
 function base_serial(&$tables_principales) {
495 495
 
496
-	$spip_jobs = array(
497
-		'id_job' => 'bigint(21) NOT NULL',
498
-		'descriptif' => "text DEFAULT '' NOT NULL",
499
-		'fonction' => 'varchar(255) NOT NULL', //nom de la fonction
500
-		'args' => "longblob DEFAULT '' NOT NULL", // arguments
501
-		'md5args' => "char(32) NOT NULL default ''", // signature des arguments
502
-		'inclure' => 'varchar(255) NOT NULL', // fichier a inclure ou path/ pour charger_fonction
503
-		'priorite' => 'smallint(6) NOT NULL default 0',
504
-		'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", // date au plus tot
505
-		'status' => 'tinyint NOT NULL default 1',
506
-	);
507
-
508
-	$spip_jobs_key = array(
509
-		'PRIMARY KEY' => 'id_job',
510
-		'KEY date' => 'date',
511
-		'KEY status' => 'status',
512
-	);
513
-
514
-	/// Attention: mes_fonctions peut avoir deja defini cette variable
515
-	/// il faut donc rajouter, mais pas reinitialiser
516
-	$tables_principales['spip_jobs'] = array('field' => &$spip_jobs, 'key' => &$spip_jobs_key);
496
+    $spip_jobs = array(
497
+        'id_job' => 'bigint(21) NOT NULL',
498
+        'descriptif' => "text DEFAULT '' NOT NULL",
499
+        'fonction' => 'varchar(255) NOT NULL', //nom de la fonction
500
+        'args' => "longblob DEFAULT '' NOT NULL", // arguments
501
+        'md5args' => "char(32) NOT NULL default ''", // signature des arguments
502
+        'inclure' => 'varchar(255) NOT NULL', // fichier a inclure ou path/ pour charger_fonction
503
+        'priorite' => 'smallint(6) NOT NULL default 0',
504
+        'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", // date au plus tot
505
+        'status' => 'tinyint NOT NULL default 1',
506
+    );
507
+
508
+    $spip_jobs_key = array(
509
+        'PRIMARY KEY' => 'id_job',
510
+        'KEY date' => 'date',
511
+        'KEY status' => 'status',
512
+    );
513
+
514
+    /// Attention: mes_fonctions peut avoir deja defini cette variable
515
+    /// il faut donc rajouter, mais pas reinitialiser
516
+    $tables_principales['spip_jobs'] = array('field' => &$spip_jobs, 'key' => &$spip_jobs_key);
517 517
 }
518 518
 
519 519
 
@@ -525,71 +525,71 @@  discard block
 block discarded – undo
525 525
  * @return void
526 526
  **/
527 527
 function base_auxiliaires(&$tables_auxiliaires) {
528
-	$spip_resultats = array(
529
-		'recherche' => "char(16) DEFAULT '' NOT NULL",
530
-		'id' => 'INT UNSIGNED NOT NULL',
531
-		'points' => "INT UNSIGNED DEFAULT '0' NOT NULL",
532
-		'table_objet' => "varchar(30) DEFAULT '' NOT NULL",
533
-		'serveur' => "char(16) DEFAULT '' NOT NULL", // hash md5 partiel du serveur de base ('' pour le serveur principal)
534
-		'maj' => 'TIMESTAMP'
535
-	);
536
-
537
-	$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 ...
538
-	);
539
-
540
-	$spip_auteurs_liens = array(
541
-		'id_auteur' => "bigint(21) DEFAULT '0' NOT NULL",
542
-		'id_objet' => "bigint(21) DEFAULT '0' NOT NULL",
543
-		'objet' => "VARCHAR (25) DEFAULT '' NOT NULL",
544
-		'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL"
545
-	);
546
-
547
-	$spip_auteurs_liens_key = array(
548
-		'PRIMARY KEY' => 'id_auteur,id_objet,objet',
549
-		'KEY id_auteur' => 'id_auteur',
550
-		'KEY id_objet' => 'id_objet',
551
-		'KEY objet' => 'objet',
552
-	);
553
-
554
-	$spip_meta = array(
555
-		'nom' => 'VARCHAR (255) NOT NULL',
556
-		'valeur' => "text DEFAULT ''",
557
-		'impt' => "ENUM('non', 'oui') DEFAULT 'oui' NOT NULL",
558
-		'maj' => 'TIMESTAMP'
559
-	);
560
-
561
-	$spip_meta_key = array(
562
-		'PRIMARY KEY' => 'nom'
563
-	);
564
-
565
-	$spip_jobs_liens = array(
566
-		'id_job' => "bigint(21) DEFAULT '0' NOT NULL",
567
-		'id_objet' => "bigint(21) DEFAULT '0' NOT NULL",
568
-		'objet' => "VARCHAR (25) DEFAULT '' NOT NULL",
569
-	);
570
-
571
-	$spip_jobs_liens_key = array(
572
-		'PRIMARY KEY' => 'id_job,id_objet,objet',
573
-		'KEY id_job' => 'id_job'
574
-	);
575
-
576
-	$tables_auxiliaires['spip_auteurs_liens'] = array(
577
-		'field' => &$spip_auteurs_liens,
578
-		'key' => &$spip_auteurs_liens_key
579
-	);
580
-
581
-	$tables_auxiliaires['spip_meta'] = array(
582
-		'field' => &$spip_meta,
583
-		'key' => &$spip_meta_key
584
-	);
585
-	$tables_auxiliaires['spip_resultats'] = array(
586
-		'field' => &$spip_resultats,
587
-		'key' => &$spip_resultats_key
588
-	);
589
-	$tables_auxiliaires['spip_jobs_liens'] = array(
590
-		'field' => &$spip_jobs_liens,
591
-		'key' => &$spip_jobs_liens_key
592
-	);
528
+    $spip_resultats = array(
529
+        'recherche' => "char(16) DEFAULT '' NOT NULL",
530
+        'id' => 'INT UNSIGNED NOT NULL',
531
+        'points' => "INT UNSIGNED DEFAULT '0' NOT NULL",
532
+        'table_objet' => "varchar(30) DEFAULT '' NOT NULL",
533
+        'serveur' => "char(16) DEFAULT '' NOT NULL", // hash md5 partiel du serveur de base ('' pour le serveur principal)
534
+        'maj' => 'TIMESTAMP'
535
+    );
536
+
537
+    $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 ...
538
+    );
539
+
540
+    $spip_auteurs_liens = array(
541
+        'id_auteur' => "bigint(21) DEFAULT '0' NOT NULL",
542
+        'id_objet' => "bigint(21) DEFAULT '0' NOT NULL",
543
+        'objet' => "VARCHAR (25) DEFAULT '' NOT NULL",
544
+        'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL"
545
+    );
546
+
547
+    $spip_auteurs_liens_key = array(
548
+        'PRIMARY KEY' => 'id_auteur,id_objet,objet',
549
+        'KEY id_auteur' => 'id_auteur',
550
+        'KEY id_objet' => 'id_objet',
551
+        'KEY objet' => 'objet',
552
+    );
553
+
554
+    $spip_meta = array(
555
+        'nom' => 'VARCHAR (255) NOT NULL',
556
+        'valeur' => "text DEFAULT ''",
557
+        'impt' => "ENUM('non', 'oui') DEFAULT 'oui' NOT NULL",
558
+        'maj' => 'TIMESTAMP'
559
+    );
560
+
561
+    $spip_meta_key = array(
562
+        'PRIMARY KEY' => 'nom'
563
+    );
564
+
565
+    $spip_jobs_liens = array(
566
+        'id_job' => "bigint(21) DEFAULT '0' NOT NULL",
567
+        'id_objet' => "bigint(21) DEFAULT '0' NOT NULL",
568
+        'objet' => "VARCHAR (25) DEFAULT '' NOT NULL",
569
+    );
570
+
571
+    $spip_jobs_liens_key = array(
572
+        'PRIMARY KEY' => 'id_job,id_objet,objet',
573
+        'KEY id_job' => 'id_job'
574
+    );
575
+
576
+    $tables_auxiliaires['spip_auteurs_liens'] = array(
577
+        'field' => &$spip_auteurs_liens,
578
+        'key' => &$spip_auteurs_liens_key
579
+    );
580
+
581
+    $tables_auxiliaires['spip_meta'] = array(
582
+        'field' => &$spip_meta,
583
+        'key' => &$spip_meta_key
584
+    );
585
+    $tables_auxiliaires['spip_resultats'] = array(
586
+        'field' => &$spip_resultats,
587
+        'key' => &$spip_resultats_key
588
+    );
589
+    $tables_auxiliaires['spip_jobs_liens'] = array(
590
+        'field' => &$spip_jobs_liens,
591
+        'key' => &$spip_jobs_liens_key
592
+    );
593 593
 
594 594
 }
595 595
 
@@ -647,129 +647,129 @@  discard block
 block discarded – undo
647 647
  * @return array
648 648
  */
649 649
 function renseigner_table_objet_sql($table_sql, &$infos) {
650
-	if (!isset($infos['type'])) {
651
-		// si on arrive de base/trouver_table, on a la cle primaire :
652
-		// s'en servir pour extrapoler le type
653
-		if (isset($infos['key']['PRIMARY KEY'])) {
654
-			$primary = $infos['key']['PRIMARY KEY'];
655
-			$primary = explode(',', $primary);
656
-			$primary = reset($primary);
657
-			$infos['type'] = preg_replace(',^spip_|^id_|s$,', '', $primary);
658
-		} else {
659
-			$infos['type'] = preg_replace(',^spip_|s$,', '', $table_sql);
660
-		}
661
-	}
662
-	if (!isset($infos['type_surnoms'])) {
663
-		$infos['type_surnoms'] = array();
664
-	}
665
-
666
-	if (!isset($infos['table_objet'])) {
667
-		$infos['table_objet'] = preg_replace(',^spip_,', '', $table_sql);
668
-	}
669
-	if (!isset($infos['table_objet_surnoms'])) {
670
-		$infos['table_objet_surnoms'] = array();
671
-	}
672
-
673
-	if (!isset($infos['principale'])) {
674
-		$infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql]) ? 'oui' : false);
675
-	}
676
-
677
-	// normaliser pour pouvoir tester en php $infos['principale']?
678
-	// et dans une boucle {principale=oui}
679
-	$infos['principale'] = (($infos['principale'] and $infos['principale'] != 'non') ? 'oui' : false);
680
-
681
-	// declarer et normaliser pour pouvoir tester en php $infos['editable']?
682
-	// et dans une boucle {editable=oui}
683
-	if (!isset($infos['editable'])) {
684
-		$infos['editable'] = 'oui';
685
-	}
686
-
687
-	$infos['editable'] = (($infos['editable'] and $infos['editable'] != 'non') ? 'oui' : false);
688
-
689
-	// les urls publiques sont par defaut page=type pour les tables principales, et rien pour les autres
690
-	// seules les exceptions sont donc a declarer
691
-	if (!isset($infos['page'])) {
692
-		$infos['page'] = ($infos['principale'] ? $infos['type'] : '');
693
-	}
694
-
695
-	if (!isset($infos['url_voir'])) {
696
-		$infos['url_voir'] = $infos['type'];
697
-	}
698
-	if (!isset($infos['url_edit'])) {
699
-		$infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : '');
700
-	}
701
-	if (!isset($infos['icone_objet'])) {
702
-		$infos['icone_objet'] = $infos['type'];
703
-	}
704
-
705
-	// chaines de langue
706
-	// par defaut : objet:icone_xxx_objet
707
-	if (!isset($infos['texte_retour'])) {
708
-		$infos['texte_retour'] = 'icone_retour';
709
-	}
710
-	if (!isset($infos['texte_modifier'])) {
711
-		$infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type'];
712
-	}
713
-	if (!isset($infos['texte_creer'])) {
714
-		$infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type'];
715
-	}
716
-	if (!isset($infos['texte_creer_associer'])) {
717
-		$infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type'];
718
-	}
719
-	if (!isset($infos['texte_ajouter'])) {
720
-		// Ajouter un X
721
-		$infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type'];
722
-	}
723
-	if (!isset($infos['texte_objets'])) {
724
-		$infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet'];
725
-	}
726
-	if (!isset($infos['texte_objet'])) {
727
-		$infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type'];
728
-	}
729
-	if (!isset($infos['texte_logo_objet'])) {
730
-		// objet:titre_logo_objet "Logo de ce X"
731
-		$infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type'];
732
-	}
733
-	if (!isset($infos['texte_langue_objet'])) {
734
-		// objet:texte_langue_objet "Langue de ce X"
735
-		$infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type'];
736
-	}
737
-	if (!isset($infos['texte_definir_comme_traduction_objet'])) {
738
-		// "Ce X est une traduction du X numéro :"
739
-		$infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type'];
740
-	}
741
-
742
-	// objet:info_aucun_objet
743
-	if (!isset($infos['info_aucun_objet'])) {
744
-		$infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type'];
745
-	}
746
-	// objet:info_1_objet
747
-	if (!isset($infos['info_1_objet'])) {
748
-		$infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type'];
749
-	}
750
-	// objet:info_nb_objets
751
-	if (!isset($infos['info_nb_objets'])) {
752
-		$infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet'];
753
-	}
754
-
755
-	if (!isset($infos['champs_editables'])) {
756
-		$infos['champs_editables'] = array();
757
-	}
758
-	if (!isset($infos['champs_versionnes'])) {
759
-		$infos['champs_versionnes'] = array();
760
-	}
761
-	if (!isset($infos['rechercher_champs'])) {
762
-		$infos['rechercher_champs'] = array();
763
-	}
764
-	if (!isset($infos['rechercher_jointures'])) {
765
-		$infos['rechercher_jointures'] = array();
766
-	}
767
-
768
-	if (!isset($infos['modeles'])) {
769
-		$infos['modeles'] = array($infos['type']);
770
-	}
771
-
772
-	return $infos;
650
+    if (!isset($infos['type'])) {
651
+        // si on arrive de base/trouver_table, on a la cle primaire :
652
+        // s'en servir pour extrapoler le type
653
+        if (isset($infos['key']['PRIMARY KEY'])) {
654
+            $primary = $infos['key']['PRIMARY KEY'];
655
+            $primary = explode(',', $primary);
656
+            $primary = reset($primary);
657
+            $infos['type'] = preg_replace(',^spip_|^id_|s$,', '', $primary);
658
+        } else {
659
+            $infos['type'] = preg_replace(',^spip_|s$,', '', $table_sql);
660
+        }
661
+    }
662
+    if (!isset($infos['type_surnoms'])) {
663
+        $infos['type_surnoms'] = array();
664
+    }
665
+
666
+    if (!isset($infos['table_objet'])) {
667
+        $infos['table_objet'] = preg_replace(',^spip_,', '', $table_sql);
668
+    }
669
+    if (!isset($infos['table_objet_surnoms'])) {
670
+        $infos['table_objet_surnoms'] = array();
671
+    }
672
+
673
+    if (!isset($infos['principale'])) {
674
+        $infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql]) ? 'oui' : false);
675
+    }
676
+
677
+    // normaliser pour pouvoir tester en php $infos['principale']?
678
+    // et dans une boucle {principale=oui}
679
+    $infos['principale'] = (($infos['principale'] and $infos['principale'] != 'non') ? 'oui' : false);
680
+
681
+    // declarer et normaliser pour pouvoir tester en php $infos['editable']?
682
+    // et dans une boucle {editable=oui}
683
+    if (!isset($infos['editable'])) {
684
+        $infos['editable'] = 'oui';
685
+    }
686
+
687
+    $infos['editable'] = (($infos['editable'] and $infos['editable'] != 'non') ? 'oui' : false);
688
+
689
+    // les urls publiques sont par defaut page=type pour les tables principales, et rien pour les autres
690
+    // seules les exceptions sont donc a declarer
691
+    if (!isset($infos['page'])) {
692
+        $infos['page'] = ($infos['principale'] ? $infos['type'] : '');
693
+    }
694
+
695
+    if (!isset($infos['url_voir'])) {
696
+        $infos['url_voir'] = $infos['type'];
697
+    }
698
+    if (!isset($infos['url_edit'])) {
699
+        $infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : '');
700
+    }
701
+    if (!isset($infos['icone_objet'])) {
702
+        $infos['icone_objet'] = $infos['type'];
703
+    }
704
+
705
+    // chaines de langue
706
+    // par defaut : objet:icone_xxx_objet
707
+    if (!isset($infos['texte_retour'])) {
708
+        $infos['texte_retour'] = 'icone_retour';
709
+    }
710
+    if (!isset($infos['texte_modifier'])) {
711
+        $infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type'];
712
+    }
713
+    if (!isset($infos['texte_creer'])) {
714
+        $infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type'];
715
+    }
716
+    if (!isset($infos['texte_creer_associer'])) {
717
+        $infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type'];
718
+    }
719
+    if (!isset($infos['texte_ajouter'])) {
720
+        // Ajouter un X
721
+        $infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type'];
722
+    }
723
+    if (!isset($infos['texte_objets'])) {
724
+        $infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet'];
725
+    }
726
+    if (!isset($infos['texte_objet'])) {
727
+        $infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type'];
728
+    }
729
+    if (!isset($infos['texte_logo_objet'])) {
730
+        // objet:titre_logo_objet "Logo de ce X"
731
+        $infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type'];
732
+    }
733
+    if (!isset($infos['texte_langue_objet'])) {
734
+        // objet:texte_langue_objet "Langue de ce X"
735
+        $infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type'];
736
+    }
737
+    if (!isset($infos['texte_definir_comme_traduction_objet'])) {
738
+        // "Ce X est une traduction du X numéro :"
739
+        $infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type'];
740
+    }
741
+
742
+    // objet:info_aucun_objet
743
+    if (!isset($infos['info_aucun_objet'])) {
744
+        $infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type'];
745
+    }
746
+    // objet:info_1_objet
747
+    if (!isset($infos['info_1_objet'])) {
748
+        $infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type'];
749
+    }
750
+    // objet:info_nb_objets
751
+    if (!isset($infos['info_nb_objets'])) {
752
+        $infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet'];
753
+    }
754
+
755
+    if (!isset($infos['champs_editables'])) {
756
+        $infos['champs_editables'] = array();
757
+    }
758
+    if (!isset($infos['champs_versionnes'])) {
759
+        $infos['champs_versionnes'] = array();
760
+    }
761
+    if (!isset($infos['rechercher_champs'])) {
762
+        $infos['rechercher_champs'] = array();
763
+    }
764
+    if (!isset($infos['rechercher_jointures'])) {
765
+        $infos['rechercher_jointures'] = array();
766
+    }
767
+
768
+    if (!isset($infos['modeles'])) {
769
+        $infos['modeles'] = array($infos['type']);
770
+    }
771
+
772
+    return $infos;
773 773
 }
774 774
 
775 775
 /**
@@ -786,32 +786,32 @@  discard block
 block discarded – undo
786 786
  * @return array
787 787
  */
788 788
 function renseigner_table_objet_interfaces($table_sql, &$infos) {
789
-	if (!isset($infos['titre'])) {
790
-		if (isset($infos['table_objet']) and isset($GLOBALS['table_titre'][$infos['table_objet']])) {
791
-			$infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']];
792
-		} else {
793
-			$infos['titre'] = ((isset($infos['field']['titre'])) ? 'titre,' : "'' as titre,");
794
-			$infos['titre'] .= ((isset($infos['field']['lang'])) ? 'lang' : "'' as lang");
795
-		}
796
-	}
797
-	if (!isset($infos['date'])) {
798
-		if (isset($infos['table_objet']) and isset($GLOBALS['table_date'][$infos['table_objet']])) {
799
-			$infos['date'] = $GLOBALS['table_date'][$infos['table_objet']];
800
-		} else {
801
-			$infos['date'] = ((isset($infos['field']['date'])) ? 'date' : '');
802
-		}
803
-	}
804
-	if (!isset($infos['statut'])) {
805
-		$infos['statut'] = isset($GLOBALS['table_statut'][$table_sql]) ? $GLOBALS['table_statut'][$table_sql] : '';
806
-	}
807
-	if (!isset($infos['tables_jointures'])) {
808
-		$infos['tables_jointures'] = array();
809
-	}
810
-	if (isset($GLOBALS['tables_jointures'][$table_sql])) {
811
-		$infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]);
812
-	}
813
-
814
-	return $infos;
789
+    if (!isset($infos['titre'])) {
790
+        if (isset($infos['table_objet']) and isset($GLOBALS['table_titre'][$infos['table_objet']])) {
791
+            $infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']];
792
+        } else {
793
+            $infos['titre'] = ((isset($infos['field']['titre'])) ? 'titre,' : "'' as titre,");
794
+            $infos['titre'] .= ((isset($infos['field']['lang'])) ? 'lang' : "'' as lang");
795
+        }
796
+    }
797
+    if (!isset($infos['date'])) {
798
+        if (isset($infos['table_objet']) and isset($GLOBALS['table_date'][$infos['table_objet']])) {
799
+            $infos['date'] = $GLOBALS['table_date'][$infos['table_objet']];
800
+        } else {
801
+            $infos['date'] = ((isset($infos['field']['date'])) ? 'date' : '');
802
+        }
803
+    }
804
+    if (!isset($infos['statut'])) {
805
+        $infos['statut'] = isset($GLOBALS['table_statut'][$table_sql]) ? $GLOBALS['table_statut'][$table_sql] : '';
806
+    }
807
+    if (!isset($infos['tables_jointures'])) {
808
+        $infos['tables_jointures'] = array();
809
+    }
810
+    if (isset($GLOBALS['tables_jointures'][$table_sql])) {
811
+        $infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]);
812
+    }
813
+
814
+    return $infos;
815 815
 }
816 816
 
817 817
 /**
@@ -822,13 +822,13 @@  discard block
 block discarded – undo
822 822
  *     Liste et descriptions des tables principales
823 823
  **/
824 824
 function lister_tables_principales() {
825
-	static $done = false;
826
-	if (!$done or !count($GLOBALS['tables_principales'])) {
827
-		lister_tables_objets_sql();
828
-		$done = true;
829
-	}
825
+    static $done = false;
826
+    if (!$done or !count($GLOBALS['tables_principales'])) {
827
+        lister_tables_objets_sql();
828
+        $done = true;
829
+    }
830 830
 
831
-	return $GLOBALS['tables_principales'];
831
+    return $GLOBALS['tables_principales'];
832 832
 }
833 833
 
834 834
 /**
@@ -839,13 +839,13 @@  discard block
 block discarded – undo
839 839
  *     Liste et descriptions des tables auxiliaires
840 840
  **/
841 841
 function lister_tables_auxiliaires() {
842
-	static $done = false;
843
-	if (!$done or !count($GLOBALS['tables_auxiliaires'])) {
844
-		lister_tables_objets_sql();
845
-		$done = true;
846
-	}
842
+    static $done = false;
843
+    if (!$done or !count($GLOBALS['tables_auxiliaires'])) {
844
+        lister_tables_objets_sql();
845
+        $done = true;
846
+    }
847 847
 
848
-	return $GLOBALS['tables_auxiliaires'];
848
+    return $GLOBALS['tables_auxiliaires'];
849 849
 }
850 850
 
851 851
 /**
@@ -854,44 +854,44 @@  discard block
 block discarded – undo
854 854
  * @return array
855 855
  */
856 856
 function lister_tables_objets_surnoms() {
857
-	static $surnoms = null;
858
-	static $md5 = null;
859
-	if (!$surnoms
860
-		or $md5 != lister_tables_objets_sql('::md5')
861
-	) {
862
-		// passer dans un pipeline qui permet aux plugins de declarer leurs exceptions
863
-		// pour compatibilite, car il faut dorenavent utiliser
864
-		// declarer_table_objets_sql
865
-		$surnoms = pipeline(
866
-			'declarer_tables_objets_surnoms',
867
-			array(
868
-				# pour les modeles
869
-				# a enlever ?
870
-				'doc' => 'documents',
871
-				'img' => 'documents',
872
-				'emb' => 'documents',
873
-			)
874
-		);
875
-		$infos_tables = lister_tables_objets_sql();
876
-		foreach ($infos_tables as $t => $infos) {
877
-			// cas de base type=>table
878
-			// et preg_replace(',^spip_|^id_|s$,',table)=>table
879
-			if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide
880
-				// optimisations pour table_objet
881
-				//$surnoms[$infos['type']] = $infos['table_objet'];
882
-				$surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['table_objet'];
883
-				$surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['table_objet'];
884
-				if (is_array($infos['table_objet_surnoms']) and count($infos['table_objet_surnoms'])) {
885
-					foreach ($infos['table_objet_surnoms'] as $surnom) {
886
-						$surnoms[$surnom] = $infos['table_objet'];
887
-					}
888
-				}
889
-			}
890
-		}
891
-		$md5 = lister_tables_objets_sql('::md5');
892
-	}
893
-
894
-	return $surnoms;
857
+    static $surnoms = null;
858
+    static $md5 = null;
859
+    if (!$surnoms
860
+        or $md5 != lister_tables_objets_sql('::md5')
861
+    ) {
862
+        // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions
863
+        // pour compatibilite, car il faut dorenavent utiliser
864
+        // declarer_table_objets_sql
865
+        $surnoms = pipeline(
866
+            'declarer_tables_objets_surnoms',
867
+            array(
868
+                # pour les modeles
869
+                # a enlever ?
870
+                'doc' => 'documents',
871
+                'img' => 'documents',
872
+                'emb' => 'documents',
873
+            )
874
+        );
875
+        $infos_tables = lister_tables_objets_sql();
876
+        foreach ($infos_tables as $t => $infos) {
877
+            // cas de base type=>table
878
+            // et preg_replace(',^spip_|^id_|s$,',table)=>table
879
+            if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide
880
+                // optimisations pour table_objet
881
+                //$surnoms[$infos['type']] = $infos['table_objet'];
882
+                $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['table_objet'];
883
+                $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['table_objet'];
884
+                if (is_array($infos['table_objet_surnoms']) and count($infos['table_objet_surnoms'])) {
885
+                    foreach ($infos['table_objet_surnoms'] as $surnom) {
886
+                        $surnoms[$surnom] = $infos['table_objet'];
887
+                    }
888
+                }
889
+            }
890
+        }
891
+        $md5 = lister_tables_objets_sql('::md5');
892
+    }
893
+
894
+    return $surnoms;
895 895
 }
896 896
 
897 897
 /**
@@ -900,34 +900,34 @@  discard block
 block discarded – undo
900 900
  * @return array
901 901
  */
902 902
 function lister_types_surnoms() {
903
-	static $surnoms = null;
904
-	static $md5 = null;
905
-	if (!$surnoms
906
-		or $md5 != lister_tables_objets_sql('::md5')
907
-	) {
908
-		// passer dans un pipeline qui permet aux plugins de declarer leurs exceptions
909
-		// pour compatibilite, car il faut dorenavent utiliser
910
-		// declarer_table_objets_sql
911
-		$surnoms = pipeline('declarer_type_surnoms', array('racine-site' => 'site'));
912
-		$infos_tables = lister_tables_objets_sql();
913
-		foreach ($infos_tables as $t => $infos) {
914
-			if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide
915
-				// optimisations pour objet_type
916
-				//$surnoms[$infos['type']] = $infos['type'];
917
-				$surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['type'];
918
-				$surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['type'];
919
-				// surnoms declares
920
-				if (is_array($infos['type_surnoms']) and count($infos['type_surnoms'])) {
921
-					foreach ($infos['type_surnoms'] as $surnom) {
922
-						$surnoms[$surnom] = $infos['type'];
923
-					}
924
-				}
925
-			}
926
-		}
927
-		$md5 = lister_tables_objets_sql('::md5');
928
-	}
929
-
930
-	return $surnoms;
903
+    static $surnoms = null;
904
+    static $md5 = null;
905
+    if (!$surnoms
906
+        or $md5 != lister_tables_objets_sql('::md5')
907
+    ) {
908
+        // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions
909
+        // pour compatibilite, car il faut dorenavent utiliser
910
+        // declarer_table_objets_sql
911
+        $surnoms = pipeline('declarer_type_surnoms', array('racine-site' => 'site'));
912
+        $infos_tables = lister_tables_objets_sql();
913
+        foreach ($infos_tables as $t => $infos) {
914
+            if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide
915
+                // optimisations pour objet_type
916
+                //$surnoms[$infos['type']] = $infos['type'];
917
+                $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['type'];
918
+                $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['type'];
919
+                // surnoms declares
920
+                if (is_array($infos['type_surnoms']) and count($infos['type_surnoms'])) {
921
+                    foreach ($infos['type_surnoms'] as $surnom) {
922
+                        $surnoms[$surnom] = $infos['type'];
923
+                    }
924
+                }
925
+            }
926
+        }
927
+        $md5 = lister_tables_objets_sql('::md5');
928
+    }
929
+
930
+    return $surnoms;
931 931
 }
932 932
 
933 933
 /**
@@ -941,22 +941,22 @@  discard block
 block discarded – undo
941 941
  *     Couples (nom de la table SQL => même nom, sans 'spip_' devant)
942 942
  **/
943 943
 function lister_tables_spip($serveur = '') {
944
-	static $tables = array();
945
-	if (!isset($tables[$serveur])) {
946
-		$tables[$serveur] = array();
947
-		if (!function_exists('sql_alltable')) {
948
-			include_spip('base/abstract_sql');
949
-		}
950
-		$ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso)
951
-		$connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0];
952
-		$spip = $connexion['prefixe'] . '_';
953
-		foreach ($ts as $t) {
954
-			$t = substr($t, strlen($spip));
955
-			$tables[$serveur]["spip_$t"] = $t;
956
-		}
957
-	}
958
-
959
-	return $tables[$serveur];
944
+    static $tables = array();
945
+    if (!isset($tables[$serveur])) {
946
+        $tables[$serveur] = array();
947
+        if (!function_exists('sql_alltable')) {
948
+            include_spip('base/abstract_sql');
949
+        }
950
+        $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso)
951
+        $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0];
952
+        $spip = $connexion['prefixe'] . '_';
953
+        foreach ($ts as $t) {
954
+            $t = substr($t, strlen($spip));
955
+            $tables[$serveur]["spip_$t"] = $t;
956
+        }
957
+    }
958
+
959
+    return $tables[$serveur];
960 960
 }
961 961
 
962 962
 /**
@@ -976,34 +976,34 @@  discard block
 block discarded – undo
976 976
  *     Nom de l'objet
977 977
  **/
978 978
 function table_objet($type, $serveur = '') {
979
-	$surnoms = lister_tables_objets_surnoms();
980
-	$type = preg_replace(',^spip_|^id_|s$,', '', $type);
981
-	if (!$type) {
982
-		return;
983
-	}
984
-	if (isset($surnoms[$type])) {
985
-		return $surnoms[$type];
986
-	}
987
-
988
-	if ($serveur !== false) {
989
-		$t = lister_tables_spip($serveur);
990
-		$trouver_table = charger_fonction('trouver_table', 'base');
991
-		$typetrim = rtrim($type, 's') . 's';
992
-		if ((isset($t[$typetrim]) or in_array($typetrim, $t))
993
-			and ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur))
994
-		) {
995
-			return $desc['id_table'];
996
-		} elseif ((isset($t[$type]) or in_array($type, $t))
997
-			and ($desc = $trouver_table($type, $serveur))
998
-		) {
999
-			return $desc['id_table'];
1000
-		}
1001
-
1002
-		spip_log('table_objet(' . $type . ') calculee sans verification');
1003
-		#spip_log(debug_backtrace(),'db');
1004
-	}
1005
-
1006
-	return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false
979
+    $surnoms = lister_tables_objets_surnoms();
980
+    $type = preg_replace(',^spip_|^id_|s$,', '', $type);
981
+    if (!$type) {
982
+        return;
983
+    }
984
+    if (isset($surnoms[$type])) {
985
+        return $surnoms[$type];
986
+    }
987
+
988
+    if ($serveur !== false) {
989
+        $t = lister_tables_spip($serveur);
990
+        $trouver_table = charger_fonction('trouver_table', 'base');
991
+        $typetrim = rtrim($type, 's') . 's';
992
+        if ((isset($t[$typetrim]) or in_array($typetrim, $t))
993
+            and ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur))
994
+        ) {
995
+            return $desc['id_table'];
996
+        } elseif ((isset($t[$type]) or in_array($type, $t))
997
+            and ($desc = $trouver_table($type, $serveur))
998
+        ) {
999
+            return $desc['id_table'];
1000
+        }
1001
+
1002
+        spip_log('table_objet(' . $type . ') calculee sans verification');
1003
+        #spip_log(debug_backtrace(),'db');
1004
+    }
1005
+
1006
+    return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false
1007 1007
 }
1008 1008
 
1009 1009
 /**
@@ -1024,30 +1024,30 @@  discard block
 block discarded – undo
1024 1024
  **/
1025 1025
 function table_objet_sql($type, $serveur = '') {
1026 1026
 
1027
-	$nom = table_objet($type, $serveur);
1028
-	if (!isset($GLOBALS['table_des_tables']['articles'])) {
1029
-		// eviter de multiples inclusions
1030
-		include_spip('public/interfaces');
1031
-	}
1032
-	if (isset($GLOBALS['table_des_tables'][$nom])) {
1033
-		$nom = $GLOBALS['table_des_tables'][$nom];
1034
-		$nom = "spip_$nom";
1035
-	} else {
1036
-		$infos_tables = lister_tables_objets_sql();
1037
-		if (isset($infos_tables["spip_$nom"])) {
1038
-			$nom = "spip_$nom";
1039
-		} elseif ($serveur !== false) {
1040
-			$t = lister_tables_spip($serveur);
1041
-			if (isset($t[$nom]) or in_array($nom, $t)) {
1042
-				$trouver_table = charger_fonction('trouver_table', 'base');
1043
-				if ($desc = $trouver_table($nom, $serveur)) {
1044
-					return $desc['table_sql'];
1045
-				}
1046
-			}
1047
-		}
1048
-	}
1049
-
1050
-	return $nom;
1027
+    $nom = table_objet($type, $serveur);
1028
+    if (!isset($GLOBALS['table_des_tables']['articles'])) {
1029
+        // eviter de multiples inclusions
1030
+        include_spip('public/interfaces');
1031
+    }
1032
+    if (isset($GLOBALS['table_des_tables'][$nom])) {
1033
+        $nom = $GLOBALS['table_des_tables'][$nom];
1034
+        $nom = "spip_$nom";
1035
+    } else {
1036
+        $infos_tables = lister_tables_objets_sql();
1037
+        if (isset($infos_tables["spip_$nom"])) {
1038
+            $nom = "spip_$nom";
1039
+        } elseif ($serveur !== false) {
1040
+            $t = lister_tables_spip($serveur);
1041
+            if (isset($t[$nom]) or in_array($nom, $t)) {
1042
+                $trouver_table = charger_fonction('trouver_table', 'base');
1043
+                if ($desc = $trouver_table($nom, $serveur)) {
1044
+                    return $desc['table_sql'];
1045
+                }
1046
+            }
1047
+        }
1048
+    }
1049
+
1050
+    return $nom;
1051 1051
 }
1052 1052
 
1053 1053
 /**
@@ -1066,32 +1066,32 @@  discard block
 block discarded – undo
1066 1066
  *     Nom de la clé primaire
1067 1067
  **/
1068 1068
 function id_table_objet($type, $serveur = '') {
1069
-	static $trouver_table = null;
1070
-	$type = objet_type($type, $serveur);
1071
-	if (!$type) {
1072
-		return;
1073
-	}
1074
-	$t = table_objet($type);
1075
-	if (!$trouver_table) {
1076
-		$trouver_table = charger_fonction('trouver_table', 'base');
1077
-	}
1078
-
1079
-	$ts = lister_tables_spip($serveur);
1080
-	if (in_array($t, $ts)) {
1081
-		$desc = $trouver_table($t, $serveur);
1082
-		if (isset($desc['key']['PRIMARY KEY'])) {
1083
-			return $desc['key']['PRIMARY KEY'];
1084
-		}
1085
-		if (!$desc or isset($desc['field']["id_$type"])) {
1086
-			return "id_$type";
1087
-		}
1088
-		// sinon renvoyer le premier champ de la table...
1089
-		$keys = array_keys($desc['field']);
1090
-
1091
-		return array_shift($keys);
1092
-	}
1093
-
1094
-	return "id_$type";
1069
+    static $trouver_table = null;
1070
+    $type = objet_type($type, $serveur);
1071
+    if (!$type) {
1072
+        return;
1073
+    }
1074
+    $t = table_objet($type);
1075
+    if (!$trouver_table) {
1076
+        $trouver_table = charger_fonction('trouver_table', 'base');
1077
+    }
1078
+
1079
+    $ts = lister_tables_spip($serveur);
1080
+    if (in_array($t, $ts)) {
1081
+        $desc = $trouver_table($t, $serveur);
1082
+        if (isset($desc['key']['PRIMARY KEY'])) {
1083
+            return $desc['key']['PRIMARY KEY'];
1084
+        }
1085
+        if (!$desc or isset($desc['field']["id_$type"])) {
1086
+            return "id_$type";
1087
+        }
1088
+        // sinon renvoyer le premier champ de la table...
1089
+        $keys = array_keys($desc['field']);
1090
+
1091
+        return array_shift($keys);
1092
+    }
1093
+
1094
+    return "id_$type";
1095 1095
 }
1096 1096
 
1097 1097
 /**
@@ -1110,59 +1110,59 @@  discard block
 block discarded – undo
1110 1110
  *     Type de l'objet
1111 1111
  **/
1112 1112
 function objet_type($table_objet, $serveur = '') {
1113
-	if (!$table_objet) {
1114
-		return;
1115
-	}
1116
-	$surnoms = lister_types_surnoms();
1117
-
1118
-	// scenario de base
1119
-	// le type est decline a partir du nom de la table en enlevant le prefixe eventuel
1120
-	// et la marque du pluriel
1121
-	// on accepte id_xx en entree aussi
1122
-	$type = preg_replace(',^spip_|^id_|s$,', '', $table_objet);
1123
-	if (isset($surnoms[$type])) {
1124
-		return $surnoms[$type];
1125
-	}
1126
-
1127
-	// securite : eliminer les caracteres non \w
1128
-	$type = preg_replace(',[^\w-],', '', $type);
1129
-
1130
-	// si le type redonne bien la table c'est bon
1131
-	// oui si table_objet ressemblait deja a un type
1132
-	if ($type == $table_objet
1133
-		or (table_objet($type, $serveur) == $table_objet)
1134
-		or (table_objet_sql($type, $serveur) == $table_objet)
1135
-	) {
1136
-		return $type;
1137
-	}
1138
-
1139
-	// si on ne veut pas chercher en base
1140
-	if ($serveur === false) {
1141
-		return $type;
1142
-	}
1143
-
1144
-	// sinon on passe par la cle primaire id_xx pour trouver le type
1145
-	// car le s a la fin est incertain
1146
-	// notamment en cas de pluriel derogatoire
1147
-	// id_jeu/spip_jeux id_journal/spip_journaux qui necessitent tout deux
1148
-	// une declaration jeu => jeux, journal => journaux
1149
-	// dans le pipeline declarer_tables_objets_surnoms
1150
-	$trouver_table = charger_fonction('trouver_table', 'base');
1151
-	$ts = lister_tables_spip($serveur);
1152
-	$desc = false;
1153
-	if (in_array($table_objet, $ts)) {
1154
-		$desc = $trouver_table($table_objet);
1155
-	}
1156
-	if (!$desc and in_array($table_objet = table_objet($type, $serveur), $ts)) {
1157
-		$desc = $trouver_table($table_objet, $serveur);
1158
-	}
1159
-	// si le type est declare : bingo !
1160
-	if ($desc and isset($desc['type'])) {
1161
-		return $desc['type'];
1162
-	}
1163
-
1164
-	// on a fait ce qu'on a pu
1165
-	return $type;
1113
+    if (!$table_objet) {
1114
+        return;
1115
+    }
1116
+    $surnoms = lister_types_surnoms();
1117
+
1118
+    // scenario de base
1119
+    // le type est decline a partir du nom de la table en enlevant le prefixe eventuel
1120
+    // et la marque du pluriel
1121
+    // on accepte id_xx en entree aussi
1122
+    $type = preg_replace(',^spip_|^id_|s$,', '', $table_objet);
1123
+    if (isset($surnoms[$type])) {
1124
+        return $surnoms[$type];
1125
+    }
1126
+
1127
+    // securite : eliminer les caracteres non \w
1128
+    $type = preg_replace(',[^\w-],', '', $type);
1129
+
1130
+    // si le type redonne bien la table c'est bon
1131
+    // oui si table_objet ressemblait deja a un type
1132
+    if ($type == $table_objet
1133
+        or (table_objet($type, $serveur) == $table_objet)
1134
+        or (table_objet_sql($type, $serveur) == $table_objet)
1135
+    ) {
1136
+        return $type;
1137
+    }
1138
+
1139
+    // si on ne veut pas chercher en base
1140
+    if ($serveur === false) {
1141
+        return $type;
1142
+    }
1143
+
1144
+    // sinon on passe par la cle primaire id_xx pour trouver le type
1145
+    // car le s a la fin est incertain
1146
+    // notamment en cas de pluriel derogatoire
1147
+    // id_jeu/spip_jeux id_journal/spip_journaux qui necessitent tout deux
1148
+    // une declaration jeu => jeux, journal => journaux
1149
+    // dans le pipeline declarer_tables_objets_surnoms
1150
+    $trouver_table = charger_fonction('trouver_table', 'base');
1151
+    $ts = lister_tables_spip($serveur);
1152
+    $desc = false;
1153
+    if (in_array($table_objet, $ts)) {
1154
+        $desc = $trouver_table($table_objet);
1155
+    }
1156
+    if (!$desc and in_array($table_objet = table_objet($type, $serveur), $ts)) {
1157
+        $desc = $trouver_table($table_objet, $serveur);
1158
+    }
1159
+    // si le type est declare : bingo !
1160
+    if ($desc and isset($desc['type'])) {
1161
+        return $desc['type'];
1162
+    }
1163
+
1164
+    // on a fait ce qu'on a pu
1165
+    return $type;
1166 1166
 }
1167 1167
 
1168 1168
 /**
@@ -1178,54 +1178,54 @@  discard block
 block discarded – undo
1178 1178
  * @return bool
1179 1179
  */
1180 1180
 function objet_test_si_publie($objet, $id_objet, $serveur = '') {
1181
-	// voir si une fonction est definie pour faire le boulot
1182
-	// elle a la priorite dans ce cas
1183
-	if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) {
1184
-		return $f($objet, $id_objet, $serveur);
1185
-	}
1186
-
1187
-	// sinon on se fie a la declaration de l'objet si presente
1188
-	$id_table = $table_objet = table_objet($objet);
1189
-	$id_table_objet = id_table_objet($objet, $serveur);
1190
-	$trouver_table = charger_fonction('trouver_table', 'base');
1191
-	if ($desc = $trouver_table($table_objet, $serveur)
1192
-		and isset($desc['statut'])
1193
-		and $desc['statut']
1194
-	) {
1195
-		$boucle = new Boucle();
1196
-		$boucle->show = $desc;
1197
-		$boucle->nom = 'objet_test_si_publie';
1198
-		$boucle->id_boucle = $id_table;
1199
-		$boucle->id_table = $id_table;
1200
-		$boucle->sql_serveur = $serveur;
1201
-		$boucle->select[] = $id_table_objet;
1202
-		$boucle->from[$table_objet] = table_objet_sql($objet, $serveur);
1203
-		$boucle->where[] = $id_table . '.' . $id_table_objet . '=' . intval($id_objet);
1204
-
1205
-		include_spip('public/compiler');
1206
-		include_spip('public/composer');
1207
-		instituer_boucle($boucle, false, true);
1208
-		$res = calculer_select(
1209
-			$boucle->select,
1210
-			$boucle->from,
1211
-			$boucle->from_type,
1212
-			$boucle->where,
1213
-			$boucle->join,
1214
-			$boucle->group,
1215
-			$boucle->order,
1216
-			$boucle->limit,
1217
-			$boucle->having,
1218
-			$table_objet,
1219
-			$id_table,
1220
-			$serveur
1221
-		);
1222
-		if (sql_fetch($res)) {
1223
-			return true;
1224
-		}
1225
-
1226
-		return false;
1227
-	}
1228
-
1229
-	// si pas d'info statut ni de fonction : l'objet est publie
1230
-	return true;
1181
+    // voir si une fonction est definie pour faire le boulot
1182
+    // elle a la priorite dans ce cas
1183
+    if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) {
1184
+        return $f($objet, $id_objet, $serveur);
1185
+    }
1186
+
1187
+    // sinon on se fie a la declaration de l'objet si presente
1188
+    $id_table = $table_objet = table_objet($objet);
1189
+    $id_table_objet = id_table_objet($objet, $serveur);
1190
+    $trouver_table = charger_fonction('trouver_table', 'base');
1191
+    if ($desc = $trouver_table($table_objet, $serveur)
1192
+        and isset($desc['statut'])
1193
+        and $desc['statut']
1194
+    ) {
1195
+        $boucle = new Boucle();
1196
+        $boucle->show = $desc;
1197
+        $boucle->nom = 'objet_test_si_publie';
1198
+        $boucle->id_boucle = $id_table;
1199
+        $boucle->id_table = $id_table;
1200
+        $boucle->sql_serveur = $serveur;
1201
+        $boucle->select[] = $id_table_objet;
1202
+        $boucle->from[$table_objet] = table_objet_sql($objet, $serveur);
1203
+        $boucle->where[] = $id_table . '.' . $id_table_objet . '=' . intval($id_objet);
1204
+
1205
+        include_spip('public/compiler');
1206
+        include_spip('public/composer');
1207
+        instituer_boucle($boucle, false, true);
1208
+        $res = calculer_select(
1209
+            $boucle->select,
1210
+            $boucle->from,
1211
+            $boucle->from_type,
1212
+            $boucle->where,
1213
+            $boucle->join,
1214
+            $boucle->group,
1215
+            $boucle->order,
1216
+            $boucle->limit,
1217
+            $boucle->having,
1218
+            $table_objet,
1219
+            $id_table,
1220
+            $serveur
1221
+        );
1222
+        if (sql_fetch($res)) {
1223
+            return true;
1224
+        }
1225
+
1226
+        return false;
1227
+    }
1228
+
1229
+    // si pas d'info statut ni de fonction : l'objet est publie
1230
+    return true;
1231 1231
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
 		$infos['url_voir'] = $infos['type'];
697 697
 	}
698 698
 	if (!isset($infos['url_edit'])) {
699
-		$infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : '');
699
+		$infos['url_edit'] = $infos['url_voir'].($infos['editable'] ? '_edit' : '');
700 700
 	}
701 701
 	if (!isset($infos['icone_objet'])) {
702 702
 		$infos['icone_objet'] = $infos['type'];
@@ -708,48 +708,48 @@  discard block
 block discarded – undo
708 708
 		$infos['texte_retour'] = 'icone_retour';
709 709
 	}
710 710
 	if (!isset($infos['texte_modifier'])) {
711
-		$infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type'];
711
+		$infos['texte_modifier'] = $infos['type'].':'.'icone_modifier_'.$infos['type'];
712 712
 	}
713 713
 	if (!isset($infos['texte_creer'])) {
714
-		$infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type'];
714
+		$infos['texte_creer'] = $infos['type'].':'.'icone_creer_'.$infos['type'];
715 715
 	}
716 716
 	if (!isset($infos['texte_creer_associer'])) {
717
-		$infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type'];
717
+		$infos['texte_creer_associer'] = $infos['type'].':'.'texte_creer_associer_'.$infos['type'];
718 718
 	}
719 719
 	if (!isset($infos['texte_ajouter'])) {
720 720
 		// Ajouter un X
721
-		$infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type'];
721
+		$infos['texte_ajouter'] = $infos['type'].':'.'texte_ajouter_'.$infos['type'];
722 722
 	}
723 723
 	if (!isset($infos['texte_objets'])) {
724
-		$infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet'];
724
+		$infos['texte_objets'] = $infos['type'].':'.'titre_'.$infos['table_objet'];
725 725
 	}
726 726
 	if (!isset($infos['texte_objet'])) {
727
-		$infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type'];
727
+		$infos['texte_objet'] = $infos['type'].':'.'titre_'.$infos['type'];
728 728
 	}
729 729
 	if (!isset($infos['texte_logo_objet'])) {
730 730
 		// objet:titre_logo_objet "Logo de ce X"
731
-		$infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type'];
731
+		$infos['texte_logo_objet'] = $infos['type'].':'.'titre_logo_'.$infos['type'];
732 732
 	}
733 733
 	if (!isset($infos['texte_langue_objet'])) {
734 734
 		// objet:texte_langue_objet "Langue de ce X"
735
-		$infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type'];
735
+		$infos['texte_langue_objet'] = $infos['type'].':'.'titre_langue_'.$infos['type'];
736 736
 	}
737 737
 	if (!isset($infos['texte_definir_comme_traduction_objet'])) {
738 738
 		// "Ce X est une traduction du X numéro :"
739
-		$infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type'];
739
+		$infos['texte_definir_comme_traduction_objet'] = $infos['type'].':'.'texte_definir_comme_traduction_'.$infos['type'];
740 740
 	}
741 741
 
742 742
 	// objet:info_aucun_objet
743 743
 	if (!isset($infos['info_aucun_objet'])) {
744
-		$infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type'];
744
+		$infos['info_aucun_objet'] = $infos['type'].':'.'info_aucun_'.$infos['type'];
745 745
 	}
746 746
 	// objet:info_1_objet
747 747
 	if (!isset($infos['info_1_objet'])) {
748
-		$infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type'];
748
+		$infos['info_1_objet'] = $infos['type'].':'.'info_1_'.$infos['type'];
749 749
 	}
750 750
 	// objet:info_nb_objets
751 751
 	if (!isset($infos['info_nb_objets'])) {
752
-		$infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet'];
752
+		$infos['info_nb_objets'] = $infos['type'].':'.'info_nb_'.$infos['table_objet'];
753 753
 	}
754 754
 
755 755
 	if (!isset($infos['champs_editables'])) {
@@ -949,7 +949,7 @@  discard block
 block discarded – undo
949 949
 		}
950 950
 		$ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso)
951 951
 		$connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0];
952
-		$spip = $connexion['prefixe'] . '_';
952
+		$spip = $connexion['prefixe'].'_';
953 953
 		foreach ($ts as $t) {
954 954
 			$t = substr($t, strlen($spip));
955 955
 			$tables[$serveur]["spip_$t"] = $t;
@@ -988,9 +988,9 @@  discard block
 block discarded – undo
988 988
 	if ($serveur !== false) {
989 989
 		$t = lister_tables_spip($serveur);
990 990
 		$trouver_table = charger_fonction('trouver_table', 'base');
991
-		$typetrim = rtrim($type, 's') . 's';
991
+		$typetrim = rtrim($type, 's').'s';
992 992
 		if ((isset($t[$typetrim]) or in_array($typetrim, $t))
993
-			and ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur))
993
+			and ($desc = $trouver_table(rtrim($type, 's').'s', $serveur))
994 994
 		) {
995 995
 			return $desc['id_table'];
996 996
 		} elseif ((isset($t[$type]) or in_array($type, $t))
@@ -999,11 +999,11 @@  discard block
 block discarded – undo
999 999
 			return $desc['id_table'];
1000 1000
 		}
1001 1001
 
1002
-		spip_log('table_objet(' . $type . ') calculee sans verification');
1002
+		spip_log('table_objet('.$type.') calculee sans verification');
1003 1003
 		#spip_log(debug_backtrace(),'db');
1004 1004
 	}
1005 1005
 
1006
-	return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false
1006
+	return rtrim($type, 's').'s'; # cas historique ne devant plus servir, sauf si $serveur=false
1007 1007
 }
1008 1008
 
1009 1009
 /**
@@ -1180,7 +1180,7 @@  discard block
 block discarded – undo
1180 1180
 function objet_test_si_publie($objet, $id_objet, $serveur = '') {
1181 1181
 	// voir si une fonction est definie pour faire le boulot
1182 1182
 	// elle a la priorite dans ce cas
1183
-	if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) {
1183
+	if ($f = charger_fonction($objet.'_test_si_publie', 'base', true)) {
1184 1184
 		return $f($objet, $id_objet, $serveur);
1185 1185
 	}
1186 1186
 
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
 		$boucle->sql_serveur = $serveur;
1201 1201
 		$boucle->select[] = $id_table_objet;
1202 1202
 		$boucle->from[$table_objet] = table_objet_sql($objet, $serveur);
1203
-		$boucle->where[] = $id_table . '.' . $id_table_objet . '=' . intval($id_objet);
1203
+		$boucle->where[] = $id_table.'.'.$id_table_objet.'='.intval($id_objet);
1204 1204
 
1205 1205
 		include_spip('public/compiler');
1206 1206
 		include_spip('public/composer');
Please login to merge, or discard this patch.
ecrire/inc/chercher_rubrique.php 1 patch
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  **/
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 
24 24
 define('_SPIP_SELECT_RUBRIQUES', 20); /* mettre 100000 pour desactiver ajax */
@@ -49,21 +49,21 @@  discard block
 block discarded – undo
49 49
  *     Code HTML du sélecteur
50 50
  **/
51 51
 function inc_chercher_rubrique_dist($id_rubrique, $type, $restreint, $idem = 0, $do = 'aff') {
52
-	if (sql_countsel('spip_rubriques') < 1) {
53
-		return '';
54
-	}
55
-
56
-	// Mode sans Ajax :
57
-	// - soit parce que le cookie ajax n'est pas la
58
-	// - soit parce qu'il y a peu de rubriques
59
-	if (_SPIP_AJAX < 1
60
-		or $type == 'breve'
61
-		or sql_countsel('spip_rubriques') < _SPIP_SELECT_RUBRIQUES
62
-	) {
63
-		return selecteur_rubrique_html($id_rubrique, $type, $restreint, $idem);
64
-	} else {
65
-		return selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem, $do);
66
-	}
52
+    if (sql_countsel('spip_rubriques') < 1) {
53
+        return '';
54
+    }
55
+
56
+    // Mode sans Ajax :
57
+    // - soit parce que le cookie ajax n'est pas la
58
+    // - soit parce qu'il y a peu de rubriques
59
+    if (_SPIP_AJAX < 1
60
+        or $type == 'breve'
61
+        or sql_countsel('spip_rubriques') < _SPIP_SELECT_RUBRIQUES
62
+    ) {
63
+        return selecteur_rubrique_html($id_rubrique, $type, $restreint, $idem);
64
+    } else {
65
+        return selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem, $do);
66
+    }
67 67
 
68 68
 }
69 69
 
@@ -81,17 +81,17 @@  discard block
 block discarded – undo
81 81
  **/
82 82
 function style_menu_rubriques($i) {
83 83
 
84
-	$espace = '';
85
-	$style = '';
86
-	for ($count = 1; $count <= $i; $count++) {
87
-		$espace .= "&nbsp;&nbsp;&nbsp;&nbsp;";
88
-	}
89
-	if ($i == 1) {
90
-		$espace = "";
91
-	}
92
-	$class = "niveau_$i";
93
-
94
-	return array($class, $style, $espace);
84
+    $espace = '';
85
+    $style = '';
86
+    for ($count = 1; $count <= $i; $count++) {
87
+        $espace .= "&nbsp;&nbsp;&nbsp;&nbsp;";
88
+    }
89
+    if ($i == 1) {
90
+        $espace = "";
91
+    }
92
+    $class = "niveau_$i";
93
+
94
+    return array($class, $style, $espace);
95 95
 }
96 96
 
97 97
 /**
@@ -115,52 +115,52 @@  discard block
 block discarded – undo
115 115
  *     Code HTML du sélecteur
116 116
  **/
117 117
 function sous_menu_rubriques($id_rubrique, $root, $niv, &$data, &$enfants, $exclus, $restreint, $type) {
118
-	static $decalage_secteur;
119
-
120
-	// Si on a demande l'exclusion ne pas descendre dans la rubrique courante
121
-	if ($exclus > 0
122
-		and $root == $exclus
123
-	) {
124
-		return '';
125
-	}
126
-
127
-	// en fonction du niveau faire un affichage plus ou moins kikoo
128
-
129
-	// selected ?
130
-	$selected = ($root == $id_rubrique) ? ' selected="selected"' : '';
131
-
132
-	// le style en fonction de la profondeur
133
-	list($class, $style, $espace) = style_menu_rubriques($niv);
134
-
135
-	$class .= " selec_rub";
136
-
137
-	// creer l'<option> pour la rubrique $root
138
-
139
-	if (isset($data[$root])) # pas de racine sauf pour les rubriques
140
-	{
141
-		$r = "<option$selected value='$root' class='$class' style='$style'>$espace"
142
-			. $data[$root]
143
-			. '</option>' . "\n";
144
-	} else {
145
-		$r = '';
146
-	}
147
-
148
-	// et le sous-menu pour ses enfants
149
-	$sous = '';
150
-	if (isset($enfants[$root])) {
151
-		foreach ($enfants[$root] as $sousrub) {
152
-			$sous .= sous_menu_rubriques($id_rubrique, $sousrub,
153
-				$niv + 1, $data, $enfants, $exclus, $restreint, $type);
154
-		}
155
-	}
156
-
157
-	// si l'objet a deplacer est publie, verifier qu'on a acces aux rubriques
158
-	if ($restreint and $root != $id_rubrique and !autoriser('publierdans', 'rubrique', $root)) {
159
-		return $sous;
160
-	}
161
-
162
-	// et voila le travail
163
-	return $r . $sous;
118
+    static $decalage_secteur;
119
+
120
+    // Si on a demande l'exclusion ne pas descendre dans la rubrique courante
121
+    if ($exclus > 0
122
+        and $root == $exclus
123
+    ) {
124
+        return '';
125
+    }
126
+
127
+    // en fonction du niveau faire un affichage plus ou moins kikoo
128
+
129
+    // selected ?
130
+    $selected = ($root == $id_rubrique) ? ' selected="selected"' : '';
131
+
132
+    // le style en fonction de la profondeur
133
+    list($class, $style, $espace) = style_menu_rubriques($niv);
134
+
135
+    $class .= " selec_rub";
136
+
137
+    // creer l'<option> pour la rubrique $root
138
+
139
+    if (isset($data[$root])) # pas de racine sauf pour les rubriques
140
+    {
141
+        $r = "<option$selected value='$root' class='$class' style='$style'>$espace"
142
+            . $data[$root]
143
+            . '</option>' . "\n";
144
+    } else {
145
+        $r = '';
146
+    }
147
+
148
+    // et le sous-menu pour ses enfants
149
+    $sous = '';
150
+    if (isset($enfants[$root])) {
151
+        foreach ($enfants[$root] as $sousrub) {
152
+            $sous .= sous_menu_rubriques($id_rubrique, $sousrub,
153
+                $niv + 1, $data, $enfants, $exclus, $restreint, $type);
154
+        }
155
+    }
156
+
157
+    // si l'objet a deplacer est publie, verifier qu'on a acces aux rubriques
158
+    if ($restreint and $root != $id_rubrique and !autoriser('publierdans', 'rubrique', $root)) {
159
+        return $sous;
160
+    }
161
+
162
+    // et voila le travail
163
+    return $r . $sous;
164 164
 }
165 165
 
166 166
 /**
@@ -181,67 +181,67 @@  discard block
 block discarded – undo
181 181
  *     Code HTML du sélecteur
182 182
  **/
183 183
 function selecteur_rubrique_html($id_rubrique, $type, $restreint, $idem = 0) {
184
-	$data = array();
185
-	if ($type == 'rubrique' and autoriser('publierdans', 'rubrique', 0)) {
186
-		$data[0] = _T('info_racine_site');
187
-	}
188
-	# premier choix = neant
189
-	# si auteur (rubriques restreintes)
190
-	# ou si creation avec id_rubrique=0
191
-	elseif ($type == 'auteur' or !$id_rubrique) {
192
-		$data[0] = '&nbsp;';
193
-	}
194
-
195
-	//
196
-	// creer une structure contenant toute l'arborescence
197
-	//
198
-
199
-	include_spip('base/abstract_sql');
200
-	$q = sql_select("id_rubrique, id_parent, titre, statut, lang, langue_choisie", "spip_rubriques",
201
-		($type == 'breve' ? ' id_parent=0 ' : ''), '', "0+titre,titre");
202
-	while ($r = sql_fetch($q)) {
203
-		if (autoriser('voir', 'rubrique', $r['id_rubrique'])) {
204
-			// titre largeur maxi a 50
205
-			$titre = couper(supprimer_tags(typo($r['titre'])) . " ", 50);
206
-			if ($GLOBALS['meta']['multi_rubriques'] == 'oui'
207
-				and ($r['langue_choisie'] == "oui" or $r['id_parent'] == 0)
208
-			) {
209
-				$titre .= ' [' . traduire_nom_langue($r['lang']) . ']';
210
-			}
211
-			$data[$r['id_rubrique']] = $titre;
212
-			$enfants[$r['id_parent']][] = $r['id_rubrique'];
213
-			if ($id_rubrique == $r['id_rubrique']) {
214
-				$id_parent = $r['id_parent'];
215
-			}
216
-		}
217
-	}
218
-
219
-	// si une seule rubrique comme choix possible,
220
-	// inutile de mettre le selecteur sur un choix vide par defaut
221
-	// sauf si le selecteur s'adresse a une rubrique puisque on peut la mettre a la racine dans ce cas
222
-	if (count($data) == 2
223
-		and isset($data[0])
224
-		and !in_array($type, array('auteur', 'rubrique'))
225
-		and !$id_rubrique
226
-	) {
227
-		unset($data[0]);
228
-	}
229
-
230
-
231
-	$opt = sous_menu_rubriques($id_rubrique, 0, 0, $data, $enfants, $idem, $restreint, $type);
232
-	$att = " id='id_parent' name='id_parent'\nclass='selecteur_parent verdana1'";
233
-
234
-	if (preg_match(',^<option[^<>]*value=.(\d*).[^<>]*>([^<]*)</option>$,', $opt, $r)) {
235
-		$r = "<input$att type='hidden' value='" . $r[1] . "' />" . $r[2];
236
-	} else {
237
-		$r = "<select" . $att . " size='1'>\n$opt</select>\n";
238
-	}
239
-
240
-	# message pour neuneus (a supprimer ?)
184
+    $data = array();
185
+    if ($type == 'rubrique' and autoriser('publierdans', 'rubrique', 0)) {
186
+        $data[0] = _T('info_racine_site');
187
+    }
188
+    # premier choix = neant
189
+    # si auteur (rubriques restreintes)
190
+    # ou si creation avec id_rubrique=0
191
+    elseif ($type == 'auteur' or !$id_rubrique) {
192
+        $data[0] = '&nbsp;';
193
+    }
194
+
195
+    //
196
+    // creer une structure contenant toute l'arborescence
197
+    //
198
+
199
+    include_spip('base/abstract_sql');
200
+    $q = sql_select("id_rubrique, id_parent, titre, statut, lang, langue_choisie", "spip_rubriques",
201
+        ($type == 'breve' ? ' id_parent=0 ' : ''), '', "0+titre,titre");
202
+    while ($r = sql_fetch($q)) {
203
+        if (autoriser('voir', 'rubrique', $r['id_rubrique'])) {
204
+            // titre largeur maxi a 50
205
+            $titre = couper(supprimer_tags(typo($r['titre'])) . " ", 50);
206
+            if ($GLOBALS['meta']['multi_rubriques'] == 'oui'
207
+                and ($r['langue_choisie'] == "oui" or $r['id_parent'] == 0)
208
+            ) {
209
+                $titre .= ' [' . traduire_nom_langue($r['lang']) . ']';
210
+            }
211
+            $data[$r['id_rubrique']] = $titre;
212
+            $enfants[$r['id_parent']][] = $r['id_rubrique'];
213
+            if ($id_rubrique == $r['id_rubrique']) {
214
+                $id_parent = $r['id_parent'];
215
+            }
216
+        }
217
+    }
218
+
219
+    // si une seule rubrique comme choix possible,
220
+    // inutile de mettre le selecteur sur un choix vide par defaut
221
+    // sauf si le selecteur s'adresse a une rubrique puisque on peut la mettre a la racine dans ce cas
222
+    if (count($data) == 2
223
+        and isset($data[0])
224
+        and !in_array($type, array('auteur', 'rubrique'))
225
+        and !$id_rubrique
226
+    ) {
227
+        unset($data[0]);
228
+    }
229
+
230
+
231
+    $opt = sous_menu_rubriques($id_rubrique, 0, 0, $data, $enfants, $idem, $restreint, $type);
232
+    $att = " id='id_parent' name='id_parent'\nclass='selecteur_parent verdana1'";
233
+
234
+    if (preg_match(',^<option[^<>]*value=.(\d*).[^<>]*>([^<]*)</option>$,', $opt, $r)) {
235
+        $r = "<input$att type='hidden' value='" . $r[1] . "' />" . $r[2];
236
+    } else {
237
+        $r = "<select" . $att . " size='1'>\n$opt</select>\n";
238
+    }
239
+
240
+    # message pour neuneus (a supprimer ?)
241 241
 #	if ($type != 'auteur' AND $type != 'breve')
242 242
 #		$r .= "\n<br />"._T('texte_rappel_selection_champs');
243 243
 
244
-	return $r;
244
+    return $r;
245 245
 }
246 246
 
247 247
 /**
@@ -275,26 +275,26 @@  discard block
 block discarded – undo
275 275
  */
276 276
 function selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem = 0, $do) {
277 277
 
278
-	if ($id_rubrique) {
279
-		$titre = sql_getfetsel("titre", "spip_rubriques", "id_rubrique=" . intval($id_rubrique));
280
-	} else {
281
-		if ($type == 'auteur') {
282
-			$titre = '&nbsp;';
283
-		} else {
284
-			$titre = _T('info_racine_site');
285
-		}
286
-	}
278
+    if ($id_rubrique) {
279
+        $titre = sql_getfetsel("titre", "spip_rubriques", "id_rubrique=" . intval($id_rubrique));
280
+    } else {
281
+        if ($type == 'auteur') {
282
+            $titre = '&nbsp;';
283
+        } else {
284
+            $titre = _T('info_racine_site');
285
+        }
286
+    }
287 287
 
288
-	$titre = str_replace('&amp;', '&', entites_html(textebrut(typo($titre))));
289
-	$init = " disabled='disabled' type='text' value=\"" . $titre . "\"\nstyle='width:300px;'";
288
+    $titre = str_replace('&amp;', '&', entites_html(textebrut(typo($titre))));
289
+    $init = " disabled='disabled' type='text' value=\"" . $titre . "\"\nstyle='width:300px;'";
290 290
 
291
-	$url = generer_url_ecrire('selectionner', "id=$id_rubrique&type=$type&do=$do"
292
-		. (!$idem ? '' : "&exclus=$idem")
293
-		. ($restreint ? "" : "&racine=oui")
294
-		. (isset($GLOBALS['var_profile']) ? '&var_profile=1' : ''));
291
+    $url = generer_url_ecrire('selectionner', "id=$id_rubrique&type=$type&do=$do"
292
+        . (!$idem ? '' : "&exclus=$idem")
293
+        . ($restreint ? "" : "&racine=oui")
294
+        . (isset($GLOBALS['var_profile']) ? '&var_profile=1' : ''));
295 295
 
296 296
 
297
-	return construire_selecteur($url, '', 'selection_rubrique', 'id_parent', $init, $id_rubrique);
297
+    return construire_selecteur($url, '', 'selection_rubrique', 'id_parent', $init, $id_rubrique);
298 298
 }
299 299
 
300 300
 /**
@@ -324,26 +324,26 @@  discard block
 block discarded – undo
324 324
  *     Code HTML du sélecteur de rubrique AJAX
325 325
  **/
326 326
 function construire_selecteur($url, $js, $idom, $name, $init = '', $id = 0) {
327
-	$icone = (strpos($idom, 'auteur') !== false) ? 'auteur-24.png' : 'rechercher-20.png';
328
-
329
-	return
330
-		"<div class='rubrique_actuelle'><a href='#' onclick=\""
331
-		. $js
332
-		. "return charger_node_url_si_vide('"
333
-		. $url
334
-		. "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='" . attribut_html(_T('titre_image_selecteur')) . "'><img src='"
335
-		. chemin_image($icone)
336
-		. "'\nstyle='vertical-align: middle;' alt='" . attribut_html(_T('titre_image_selecteur')) . "' /></a><img src='"
337
-		. chemin_image('searching.gif')
338
-		. "' id='img_"
339
-		. $idom
340
-		. "'\nstyle='visibility: hidden;' alt='*' />"
341
-		. "<input id='titreparent' name='titreparent'"
342
-		. $init
343
-		. " />"
344
-		. "<input type='hidden' id='$name' name='$name' value='"
345
-		. $id
346
-		. "' /><div class='nettoyeur'></div></div><div id='"
347
-		. $idom
348
-		. "'\nstyle='display: none;'></div>";
327
+    $icone = (strpos($idom, 'auteur') !== false) ? 'auteur-24.png' : 'rechercher-20.png';
328
+
329
+    return
330
+        "<div class='rubrique_actuelle'><a href='#' onclick=\""
331
+        . $js
332
+        . "return charger_node_url_si_vide('"
333
+        . $url
334
+        . "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='" . attribut_html(_T('titre_image_selecteur')) . "'><img src='"
335
+        . chemin_image($icone)
336
+        . "'\nstyle='vertical-align: middle;' alt='" . attribut_html(_T('titre_image_selecteur')) . "' /></a><img src='"
337
+        . chemin_image('searching.gif')
338
+        . "' id='img_"
339
+        . $idom
340
+        . "'\nstyle='visibility: hidden;' alt='*' />"
341
+        . "<input id='titreparent' name='titreparent'"
342
+        . $init
343
+        . " />"
344
+        . "<input type='hidden' id='$name' name='$name' value='"
345
+        . $id
346
+        . "' /><div class='nettoyeur'></div></div><div id='"
347
+        . $idom
348
+        . "'\nstyle='display: none;'></div>";
349 349
 }
Please login to merge, or discard this patch.
ecrire/inc/utils.php 1 patch
Indentation   +2119 added lines, -2120 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -48,63 +48,63 @@  discard block
 block discarded – undo
48 48
  *     Nom de la fonction, ou false.
49 49
  */
50 50
 function charger_fonction($nom, $dossier = 'exec', $continue = false) {
51
-	static $echecs = array();
52
-
53
-	if (strlen($dossier) and substr($dossier, -1) != '/') {
54
-		$dossier .= '/';
55
-	}
56
-	$f = str_replace('/', '_', $dossier) . $nom;
57
-
58
-	if (function_exists($f)) {
59
-		return $f;
60
-	}
61
-	if (function_exists($g = $f . '_dist')) {
62
-		return $g;
63
-	}
64
-
65
-	if (isset($echecs[$f])) {
66
-		return $echecs[$f];
67
-	}
68
-	// Sinon charger le fichier de declaration si plausible
69
-
70
-	if (!preg_match(',^\w+$,', $f)) {
71
-		if ($continue) {
72
-			return false;
73
-		} //appel interne, on passe
74
-		include_spip('inc/minipres');
75
-		echo minipres();
76
-		exit;
77
-	}
78
-
79
-	// passer en minuscules (cf les balises de formulaires)
80
-	// et inclure le fichier
81
-	if (!$inc = include_spip($dossier . ($d = strtolower($nom)))
82
-		// si le fichier truc/machin/nom.php n'existe pas,
83
-		// la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
84
-		and strlen(dirname($dossier)) and dirname($dossier) != '.'
85
-	) {
86
-		include_spip(substr($dossier, 0, -1));
87
-	}
88
-	if (function_exists($f)) {
89
-		return $f;
90
-	}
91
-	if (function_exists($g)) {
92
-		return $g;
93
-	}
94
-
95
-	if ($continue) {
96
-		return $echecs[$f] = false;
97
-	}
98
-
99
-	// Echec : message d'erreur
100
-	spip_log("fonction $nom ($f ou $g) indisponible" .
101
-		($inc ? "" : " (fichier $d absent de $dossier)"));
102
-
103
-	include_spip('inc/minipres');
104
-	echo minipres(_T('forum_titre_erreur'),
105
-		_T('fichier_introuvable', array('fichier' => '<b>' . spip_htmlentities($d) . '</b>')),
106
-		array('all_inline'=>true,'status'=>404));
107
-	exit;
51
+    static $echecs = array();
52
+
53
+    if (strlen($dossier) and substr($dossier, -1) != '/') {
54
+        $dossier .= '/';
55
+    }
56
+    $f = str_replace('/', '_', $dossier) . $nom;
57
+
58
+    if (function_exists($f)) {
59
+        return $f;
60
+    }
61
+    if (function_exists($g = $f . '_dist')) {
62
+        return $g;
63
+    }
64
+
65
+    if (isset($echecs[$f])) {
66
+        return $echecs[$f];
67
+    }
68
+    // Sinon charger le fichier de declaration si plausible
69
+
70
+    if (!preg_match(',^\w+$,', $f)) {
71
+        if ($continue) {
72
+            return false;
73
+        } //appel interne, on passe
74
+        include_spip('inc/minipres');
75
+        echo minipres();
76
+        exit;
77
+    }
78
+
79
+    // passer en minuscules (cf les balises de formulaires)
80
+    // et inclure le fichier
81
+    if (!$inc = include_spip($dossier . ($d = strtolower($nom)))
82
+        // si le fichier truc/machin/nom.php n'existe pas,
83
+        // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
84
+        and strlen(dirname($dossier)) and dirname($dossier) != '.'
85
+    ) {
86
+        include_spip(substr($dossier, 0, -1));
87
+    }
88
+    if (function_exists($f)) {
89
+        return $f;
90
+    }
91
+    if (function_exists($g)) {
92
+        return $g;
93
+    }
94
+
95
+    if ($continue) {
96
+        return $echecs[$f] = false;
97
+    }
98
+
99
+    // Echec : message d'erreur
100
+    spip_log("fonction $nom ($f ou $g) indisponible" .
101
+        ($inc ? "" : " (fichier $d absent de $dossier)"));
102
+
103
+    include_spip('inc/minipres');
104
+    echo minipres(_T('forum_titre_erreur'),
105
+        _T('fichier_introuvable', array('fichier' => '<b>' . spip_htmlentities($d) . '</b>')),
106
+        array('all_inline'=>true,'status'=>404));
107
+    exit;
108 108
 }
109 109
 
110 110
 /**
@@ -114,17 +114,17 @@  discard block
 block discarded – undo
114 114
  * @return bool
115 115
  */
116 116
 function include_once_check($file) {
117
-	if (file_exists($file)) {
118
-		include_once $file;
117
+    if (file_exists($file)) {
118
+        include_once $file;
119 119
 
120
-		return true;
121
-	}
122
-	$crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
123
-	$crash = ($crash ? $crash : array());
124
-	$crash[$file] = true;
125
-	ecrire_meta('message_crash_plugins', serialize($crash));
120
+        return true;
121
+    }
122
+    $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
123
+    $crash = ($crash ? $crash : array());
124
+    $crash[$file] = true;
125
+    ecrire_meta('message_crash_plugins', serialize($crash));
126 126
 
127
-	return false;
127
+    return false;
128 128
 }
129 129
 
130 130
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
  *     - string : chemin du fichier trouvé
149 149
  **/
150 150
 function include_spip($f, $include = true) {
151
-	return find_in_path($f . '.php', '', $include);
151
+    return find_in_path($f . '.php', '', $include);
152 152
 }
153 153
 
154 154
 /**
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
  *     - string : chemin du fichier trouvé
169 169
  **/
170 170
 function require_spip($f) {
171
-	return find_in_path($f . '.php', '', 'required');
171
+    return find_in_path($f . '.php', '', 'required');
172 172
 }
173 173
 
174 174
 /**
@@ -194,22 +194,22 @@  discard block
 block discarded – undo
194 194
  *     Les paramètres du pipeline modifiés
195 195
  **/
196 196
 function minipipe($fonc, &$val) {
197
-	// fonction
198
-	if (function_exists($fonc)) {
199
-		$val = call_user_func($fonc, $val);
200
-	} // Class::Methode
201
-	else {
202
-		if (preg_match("/^(\w*)::(\w*)$/S", $fonc, $regs)
203
-			and $methode = array($regs[1], $regs[2])
204
-			and is_callable($methode)
205
-		) {
206
-			$val = call_user_func($methode, $val);
207
-		} else {
208
-			spip_log("Erreur - '$fonc' non definie !");
209
-		}
210
-	}
197
+    // fonction
198
+    if (function_exists($fonc)) {
199
+        $val = call_user_func($fonc, $val);
200
+    } // Class::Methode
201
+    else {
202
+        if (preg_match("/^(\w*)::(\w*)$/S", $fonc, $regs)
203
+            and $methode = array($regs[1], $regs[2])
204
+            and is_callable($methode)
205
+        ) {
206
+            $val = call_user_func($methode, $val);
207
+        } else {
208
+            spip_log("Erreur - '$fonc' non definie !");
209
+        }
210
+    }
211 211
 
212
-	return $val;
212
+    return $val;
213 213
 }
214 214
 
215 215
 /**
@@ -240,45 +240,45 @@  discard block
 block discarded – undo
240 240
  *     Résultat
241 241
  */
242 242
 function pipeline($action, $val = null) {
243
-	static $charger;
244
-
245
-	// chargement initial des fonctions mises en cache, ou generation du cache
246
-	if (!$charger) {
247
-		if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
248
-			include_spip('inc/plugin');
249
-			// generer les fichiers php precompiles
250
-			// de chargement des plugins et des pipelines
251
-			actualise_plugins_actifs();
252
-			if (!($ok = @is_readable($charger))) {
253
-				spip_log("fichier $charger pas cree");
254
-			}
255
-		}
256
-
257
-		if ($ok) {
258
-			include_once $charger;
259
-		}
260
-	}
261
-
262
-	// appliquer notre fonction si elle existe
263
-	$fonc = 'execute_pipeline_' . strtolower($action);
264
-	if (function_exists($fonc)) {
265
-		$val = $fonc($val);
266
-	} // plantage ?
267
-	else {
268
-		spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
269
-	}
270
-
271
-	// si le flux est une table avec 2 cle args&data
272
-	// on ne ressort du pipe que les donnees dans 'data'
273
-	// array_key_exists pour php 4.1.0
274
-	if (is_array($val)
275
-		and count($val) == 2
276
-		and (array_key_exists('data', $val))
277
-	) {
278
-		$val = $val['data'];
279
-	}
280
-
281
-	return $val;
243
+    static $charger;
244
+
245
+    // chargement initial des fonctions mises en cache, ou generation du cache
246
+    if (!$charger) {
247
+        if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
248
+            include_spip('inc/plugin');
249
+            // generer les fichiers php precompiles
250
+            // de chargement des plugins et des pipelines
251
+            actualise_plugins_actifs();
252
+            if (!($ok = @is_readable($charger))) {
253
+                spip_log("fichier $charger pas cree");
254
+            }
255
+        }
256
+
257
+        if ($ok) {
258
+            include_once $charger;
259
+        }
260
+    }
261
+
262
+    // appliquer notre fonction si elle existe
263
+    $fonc = 'execute_pipeline_' . strtolower($action);
264
+    if (function_exists($fonc)) {
265
+        $val = $fonc($val);
266
+    } // plantage ?
267
+    else {
268
+        spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
269
+    }
270
+
271
+    // si le flux est une table avec 2 cle args&data
272
+    // on ne ressort du pipe que les donnees dans 'data'
273
+    // array_key_exists pour php 4.1.0
274
+    if (is_array($val)
275
+        and count($val) == 2
276
+        and (array_key_exists('data', $val))
277
+    ) {
278
+        $val = $val['data'];
279
+    }
280
+
281
+    return $val;
282 282
 }
283 283
 
284 284
 /**
@@ -322,35 +322,35 @@  discard block
 block discarded – undo
322 322
  *     paramètre est planté pour cause de compatibilité ascendante.
323 323
  */
324 324
 function spip_log($message = null, $name = null) {
325
-	static $pre = array();
326
-	static $log;
327
-	preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
328
-	if (!isset($regs[1]) or !$logname = $regs[1]) {
329
-		$logname = null;
330
-	}
331
-	if (!isset($regs[2]) or !$niveau = $regs[2]) {
332
-		$niveau = _LOG_INFO;
333
-	}
334
-
335
-	if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
336
-		if (!$pre) {
337
-			$pre = array(
338
-				_LOG_HS => 'HS:',
339
-				_LOG_ALERTE_ROUGE => 'ALERTE:',
340
-				_LOG_CRITIQUE => 'CRITIQUE:',
341
-				_LOG_ERREUR => 'ERREUR:',
342
-				_LOG_AVERTISSEMENT => 'WARNING:',
343
-				_LOG_INFO_IMPORTANTE => '!INFO:',
344
-				_LOG_INFO => 'info:',
345
-				_LOG_DEBUG => 'debug:'
346
-			);
347
-			$log = charger_fonction('log', 'inc');
348
-		}
349
-		if (!is_string($message)) {
350
-			$message = print_r($message, true);
351
-		}
352
-		$log($pre[$niveau] . ' ' . $message, $logname);
353
-	}
325
+    static $pre = array();
326
+    static $log;
327
+    preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
328
+    if (!isset($regs[1]) or !$logname = $regs[1]) {
329
+        $logname = null;
330
+    }
331
+    if (!isset($regs[2]) or !$niveau = $regs[2]) {
332
+        $niveau = _LOG_INFO;
333
+    }
334
+
335
+    if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
336
+        if (!$pre) {
337
+            $pre = array(
338
+                _LOG_HS => 'HS:',
339
+                _LOG_ALERTE_ROUGE => 'ALERTE:',
340
+                _LOG_CRITIQUE => 'CRITIQUE:',
341
+                _LOG_ERREUR => 'ERREUR:',
342
+                _LOG_AVERTISSEMENT => 'WARNING:',
343
+                _LOG_INFO_IMPORTANTE => '!INFO:',
344
+                _LOG_INFO => 'info:',
345
+                _LOG_DEBUG => 'debug:'
346
+            );
347
+            $log = charger_fonction('log', 'inc');
348
+        }
349
+        if (!is_string($message)) {
350
+            $message = print_r($message, true);
351
+        }
352
+        $log($pre[$niveau] . ' ' . $message, $logname);
353
+    }
354 354
 }
355 355
 
356 356
 /**
@@ -361,8 +361,8 @@  discard block
 block discarded – undo
361 361
  * @param array $opt Tableau d'options
362 362
  **/
363 363
 function journal($phrase, $opt = array()) {
364
-	$journal = charger_fonction('journal', 'inc');
365
-	$journal($phrase, $opt);
364
+    $journal = charger_fonction('journal', 'inc');
365
+    $journal($phrase, $opt);
366 366
 }
367 367
 
368 368
 
@@ -381,36 +381,36 @@  discard block
 block discarded – undo
381 381
  **/
382 382
 function _request($var, $c = false) {
383 383
 
384
-	if (is_array($c)) {
385
-		return isset($c[$var]) ? $c[$var] : null;
386
-	}
384
+    if (is_array($c)) {
385
+        return isset($c[$var]) ? $c[$var] : null;
386
+    }
387 387
 
388
-	if (isset($_GET[$var])) {
389
-		$a = $_GET[$var];
390
-	} elseif (isset($_POST[$var])) {
391
-		$a = $_POST[$var];
392
-	} else {
393
-		return null;
394
-	}
388
+    if (isset($_GET[$var])) {
389
+        $a = $_GET[$var];
390
+    } elseif (isset($_POST[$var])) {
391
+        $a = $_POST[$var];
392
+    } else {
393
+        return null;
394
+    }
395 395
 
396
-	// Si on est en ajax et en POST tout a ete encode
397
-	// via encodeURIComponent, il faut donc repasser
398
-	// dans le charset local...
399
-	if (defined('_AJAX')
400
-		and _AJAX
401
-		and isset($GLOBALS['meta']['charset'])
402
-		and $GLOBALS['meta']['charset'] != 'utf-8'
403
-		and is_string($a)
404
-		// check rapide mais pas fiable
405
-		and preg_match(',[\x80-\xFF],', $a)
406
-		// check fiable
407
-		and include_spip('inc/charsets')
408
-		and is_utf8($a)
409
-	) {
410
-		return importer_charset($a, 'utf-8');
411
-	}
396
+    // Si on est en ajax et en POST tout a ete encode
397
+    // via encodeURIComponent, il faut donc repasser
398
+    // dans le charset local...
399
+    if (defined('_AJAX')
400
+        and _AJAX
401
+        and isset($GLOBALS['meta']['charset'])
402
+        and $GLOBALS['meta']['charset'] != 'utf-8'
403
+        and is_string($a)
404
+        // check rapide mais pas fiable
405
+        and preg_match(',[\x80-\xFF],', $a)
406
+        // check fiable
407
+        and include_spip('inc/charsets')
408
+        and is_utf8($a)
409
+    ) {
410
+        return importer_charset($a, 'utf-8');
411
+    }
412 412
 
413
-	return $a;
413
+    return $a;
414 414
 }
415 415
 
416 416
 
@@ -428,22 +428,22 @@  discard block
 block discarded – undo
428 428
  *     - false sinon
429 429
  **/
430 430
 function set_request($var, $val = null, $c = false) {
431
-	if (is_array($c)) {
432
-		unset($c[$var]);
433
-		if ($val !== null) {
434
-			$c[$var] = $val;
435
-		}
431
+    if (is_array($c)) {
432
+        unset($c[$var]);
433
+        if ($val !== null) {
434
+            $c[$var] = $val;
435
+        }
436 436
 
437
-		return $c;
438
-	}
437
+        return $c;
438
+    }
439 439
 
440
-	unset($_GET[$var]);
441
-	unset($_POST[$var]);
442
-	if ($val !== null) {
443
-		$_GET[$var] = $val;
444
-	}
440
+    unset($_GET[$var]);
441
+    unset($_POST[$var]);
442
+    if ($val !== null) {
443
+        $_GET[$var] = $val;
444
+    }
445 445
 
446
-	return false; # n'affecte pas $c
446
+    return false; # n'affecte pas $c
447 447
 }
448 448
 
449 449
 
@@ -452,23 +452,22 @@  discard block
 block discarded – undo
452 452
  * 
453 453
  * On est sur le web, on exclut certains protocoles, 
454 454
  * notamment 'file://', 'php://' et d'autres…
455
-
456 455
  * @param string $url
457 456
  * @return bool
458 457
  */
459 458
 function tester_url_absolue($url) {
460
-	$url = trim($url);
461
-	if (preg_match(";^([a-z]{3,7}:)?//;Uims", $url, $m)) {
462
-		if (
463
-			isset($m[1])
464
-			and $p = strtolower(rtrim($m[1], ':'))
465
-			and in_array($p, array('file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'))
466
-		  ) {
467
-			return false;
468
-		}
469
-		return true;
470
-	}
471
-	return false;
459
+    $url = trim($url);
460
+    if (preg_match(";^([a-z]{3,7}:)?//;Uims", $url, $m)) {
461
+        if (
462
+            isset($m[1])
463
+            and $p = strtolower(rtrim($m[1], ':'))
464
+            and in_array($p, array('file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'))
465
+            ) {
466
+            return false;
467
+        }
468
+        return true;
469
+    }
470
+    return false;
472 471
 }
473 472
 
474 473
 /**
@@ -490,94 +489,94 @@  discard block
 block discarded – undo
490 489
  * @return string URL
491 490
  */
492 491
 function parametre_url($url, $c, $v = null, $sep = '&amp;') {
493
-	// requete erronnee : plusieurs variable dans $c et aucun $v
494
-	if (strpos($c, "|") !== false and is_null($v)) {
495
-		return null;
496
-	}
497
-
498
-	// lever l'#ancre
499
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
500
-		$url = $r[1];
501
-		$ancre = $r[2];
502
-	} else {
503
-		$ancre = '';
504
-	}
505
-
506
-	// eclater
507
-	$url = preg_split(',[?]|&amp;|&,', $url);
508
-
509
-	// recuperer la base
510
-	$a = array_shift($url);
511
-	if (!$a) {
512
-		$a = './';
513
-	}
514
-
515
-	$regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,';
516
-	$ajouts = array_flip(explode('|', $c));
517
-	$u = is_array($v) ? $v : rawurlencode($v);
518
-	$testv = (is_array($v) ? count($v) : strlen($v));
519
-	$v_read = null;
520
-	// lire les variables et agir
521
-	foreach ($url as $n => $val) {
522
-		if (preg_match($regexp, urldecode($val), $r)) {
523
-			$r = array_pad($r, 3, null);
524
-			if ($v === null) {
525
-				// c'est un tableau, on memorise les valeurs
526
-				if (substr($r[1], -2) == "[]") {
527
-					if (!$v_read) {
528
-						$v_read = array();
529
-					}
530
-					$v_read[] = $r[2] ? substr($r[2], 1) : '';
531
-				} // c'est un scalaire, on retourne direct
532
-				else {
533
-					return $r[2] ? substr($r[2], 1) : '';
534
-				}
535
-			} // suppression
536
-			elseif (!$testv) {
537
-				unset($url[$n]);
538
-			}
539
-			// Ajout. Pour une variable, remplacer au meme endroit,
540
-			// pour un tableau ce sera fait dans la prochaine boucle
541
-			elseif (substr($r[1], -2) != '[]') {
542
-				$url[$n] = $r[1] . '=' . $u;
543
-				unset($ajouts[$r[1]]);
544
-			}
545
-			// Pour les tableaux on laisse tomber les valeurs de
546
-			// départ, on remplira à l'étape suivante
547
-			else {
548
-				unset($url[$n]);
549
-			}
550
-		}
551
-	}
552
-
553
-	// traiter les parametres pas encore trouves
554
-	if ($v === null
555
-		and $args = func_get_args()
556
-		and count($args) == 2
557
-	) {
558
-		return $v_read; // rien trouve ou un tableau
559
-	} elseif ($testv) {
560
-		foreach ($ajouts as $k => $n) {
561
-			if (!is_array($v)) {
562
-				$url[] = $k . '=' . $u;
563
-			} else {
564
-				$id = (substr($k, -2) == '[]') ? $k : ($k . "[]");
565
-				foreach ($v as $w) {
566
-					$url[] = $id . '=' . (is_array($w) ? 'Array' : $w);
567
-				}
568
-			}
569
-		}
570
-	}
571
-
572
-	// eliminer les vides
573
-	$url = array_filter($url);
574
-
575
-	// recomposer l'adresse
576
-	if ($url) {
577
-		$a .= '?' . join($sep, $url);
578
-	}
579
-
580
-	return $a . $ancre;
492
+    // requete erronnee : plusieurs variable dans $c et aucun $v
493
+    if (strpos($c, "|") !== false and is_null($v)) {
494
+        return null;
495
+    }
496
+
497
+    // lever l'#ancre
498
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
499
+        $url = $r[1];
500
+        $ancre = $r[2];
501
+    } else {
502
+        $ancre = '';
503
+    }
504
+
505
+    // eclater
506
+    $url = preg_split(',[?]|&amp;|&,', $url);
507
+
508
+    // recuperer la base
509
+    $a = array_shift($url);
510
+    if (!$a) {
511
+        $a = './';
512
+    }
513
+
514
+    $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,';
515
+    $ajouts = array_flip(explode('|', $c));
516
+    $u = is_array($v) ? $v : rawurlencode($v);
517
+    $testv = (is_array($v) ? count($v) : strlen($v));
518
+    $v_read = null;
519
+    // lire les variables et agir
520
+    foreach ($url as $n => $val) {
521
+        if (preg_match($regexp, urldecode($val), $r)) {
522
+            $r = array_pad($r, 3, null);
523
+            if ($v === null) {
524
+                // c'est un tableau, on memorise les valeurs
525
+                if (substr($r[1], -2) == "[]") {
526
+                    if (!$v_read) {
527
+                        $v_read = array();
528
+                    }
529
+                    $v_read[] = $r[2] ? substr($r[2], 1) : '';
530
+                } // c'est un scalaire, on retourne direct
531
+                else {
532
+                    return $r[2] ? substr($r[2], 1) : '';
533
+                }
534
+            } // suppression
535
+            elseif (!$testv) {
536
+                unset($url[$n]);
537
+            }
538
+            // Ajout. Pour une variable, remplacer au meme endroit,
539
+            // pour un tableau ce sera fait dans la prochaine boucle
540
+            elseif (substr($r[1], -2) != '[]') {
541
+                $url[$n] = $r[1] . '=' . $u;
542
+                unset($ajouts[$r[1]]);
543
+            }
544
+            // Pour les tableaux on laisse tomber les valeurs de
545
+            // départ, on remplira à l'étape suivante
546
+            else {
547
+                unset($url[$n]);
548
+            }
549
+        }
550
+    }
551
+
552
+    // traiter les parametres pas encore trouves
553
+    if ($v === null
554
+        and $args = func_get_args()
555
+        and count($args) == 2
556
+    ) {
557
+        return $v_read; // rien trouve ou un tableau
558
+    } elseif ($testv) {
559
+        foreach ($ajouts as $k => $n) {
560
+            if (!is_array($v)) {
561
+                $url[] = $k . '=' . $u;
562
+            } else {
563
+                $id = (substr($k, -2) == '[]') ? $k : ($k . "[]");
564
+                foreach ($v as $w) {
565
+                    $url[] = $id . '=' . (is_array($w) ? 'Array' : $w);
566
+                }
567
+            }
568
+        }
569
+    }
570
+
571
+    // eliminer les vides
572
+    $url = array_filter($url);
573
+
574
+    // recomposer l'adresse
575
+    if ($url) {
576
+        $a .= '?' . join($sep, $url);
577
+    }
578
+
579
+    return $a . $ancre;
581 580
 }
582 581
 
583 582
 /**
@@ -595,21 +594,21 @@  discard block
 block discarded – undo
595 594
  * @return string
596 595
  */
597 596
 function ancre_url($url, $ancre) {
598
-	// lever l'#ancre
599
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
600
-		$url = $r[1];
601
-	}
602
-	if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
603
-		if (!function_exists('translitteration')) {
604
-			include_spip('inc/charsets');
605
-		}
606
-		$ancre = preg_replace(
607
-			array('/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'),
608
-			array('', '-'),
609
-			translitteration($ancre)
610
-		);
611
-	}
612
-	return $url . (strlen($ancre) ? '#' . $ancre : '');
597
+    // lever l'#ancre
598
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
599
+        $url = $r[1];
600
+    }
601
+    if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
602
+        if (!function_exists('translitteration')) {
603
+            include_spip('inc/charsets');
604
+        }
605
+        $ancre = preg_replace(
606
+            array('/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'),
607
+            array('', '-'),
608
+            translitteration($ancre)
609
+        );
610
+    }
611
+    return $url . (strlen($ancre) ? '#' . $ancre : '');
613 612
 }
614 613
 
615 614
 /**
@@ -619,16 +618,16 @@  discard block
 block discarded – undo
619 618
  * @return string
620 619
  */
621 620
 function nettoyer_uri($reset = null) {
622
-	static $done = false;
623
-	static $propre = '';
624
-	if (!is_null($reset)) {
625
-		return $propre = $reset;
626
-	}
627
-	if ($done) {
628
-		return $propre;
629
-	}
630
-	$done = true;
631
-	return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
621
+    static $done = false;
622
+    static $propre = '';
623
+    if (!is_null($reset)) {
624
+        return $propre = $reset;
625
+    }
626
+    if ($done) {
627
+        return $propre;
628
+    }
629
+    $done = true;
630
+    return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
632 631
 }
633 632
 
634 633
 /**
@@ -637,13 +636,13 @@  discard block
 block discarded – undo
637 636
  * @return string
638 637
  */
639 638
 function nettoyer_uri_var($request_uri) {
640
-	$uri1 = $request_uri;
641
-	do {
642
-		$uri = $uri1;
643
-		$uri1 = preg_replace(',([?&])(PHPSESSID|(var_[^=&]*))=[^&]*(&|$),i',
644
-			'\1', $uri);
645
-	} while ($uri <> $uri1);
646
-	return preg_replace(',[?&]$,', '', $uri1);
639
+    $uri1 = $request_uri;
640
+    do {
641
+        $uri = $uri1;
642
+        $uri1 = preg_replace(',([?&])(PHPSESSID|(var_[^=&]*))=[^&]*(&|$),i',
643
+            '\1', $uri);
644
+    } while ($uri <> $uri1);
645
+    return preg_replace(',[?&]$,', '', $uri1);
647 646
 }
648 647
 
649 648
 
@@ -657,47 +656,47 @@  discard block
 block discarded – undo
657 656
  *    URL vers soi-même
658 657
  **/
659 658
 function self($amp = '&amp;', $root = false) {
660
-	$url = nettoyer_uri();
661
-	if (!$root
662
-		and (
663
-			// si pas de profondeur on peut tronquer
664
-			$GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
665
-			// sinon c'est OK si _SET_HTML_BASE a ete force a false
666
-			or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
667
-	) {
668
-		$url = preg_replace(',^[^?]*/,', '', $url);
669
-	}
670
-	// ajouter le cas echeant les variables _POST['id_...']
671
-	foreach ($_POST as $v => $c) {
672
-		if (substr($v, 0, 3) == 'id_') {
673
-			$url = parametre_url($url, $v, $c, '&');
674
-		}
675
-	}
676
-
677
-	// supprimer les variables sans interet
678
-	if (test_espace_prive()) {
679
-		$url = preg_replace(',([?&])('
680
-			. 'lang|show_docs|'
681
-			. 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
682
-		$url = preg_replace(',([?&])[&]+,', '\1', $url);
683
-		$url = preg_replace(',[&]$,', '\1', $url);
684
-	}
685
-
686
-	// eviter les hacks
687
-	include_spip('inc/filtres_mini');
688
-	$url = spip_htmlspecialchars($url);
659
+    $url = nettoyer_uri();
660
+    if (!$root
661
+        and (
662
+            // si pas de profondeur on peut tronquer
663
+            $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
664
+            // sinon c'est OK si _SET_HTML_BASE a ete force a false
665
+            or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
666
+    ) {
667
+        $url = preg_replace(',^[^?]*/,', '', $url);
668
+    }
669
+    // ajouter le cas echeant les variables _POST['id_...']
670
+    foreach ($_POST as $v => $c) {
671
+        if (substr($v, 0, 3) == 'id_') {
672
+            $url = parametre_url($url, $v, $c, '&');
673
+        }
674
+    }
675
+
676
+    // supprimer les variables sans interet
677
+    if (test_espace_prive()) {
678
+        $url = preg_replace(',([?&])('
679
+            . 'lang|show_docs|'
680
+            . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
681
+        $url = preg_replace(',([?&])[&]+,', '\1', $url);
682
+        $url = preg_replace(',[&]$,', '\1', $url);
683
+    }
684
+
685
+    // eviter les hacks
686
+    include_spip('inc/filtres_mini');
687
+    $url = spip_htmlspecialchars($url);
689 688
 	
690
-	$url = str_replace(array("'", '"', '<', '[', ']', ':'), array('%27', '%22', '%3C', '%5B', '%5D', '%3A'), $url);
689
+    $url = str_replace(array("'", '"', '<', '[', ']', ':'), array('%27', '%22', '%3C', '%5B', '%5D', '%3A'), $url);
691 690
 
692
-	// &amp; ?
693
-	if ($amp != '&amp;') {
694
-		$url = str_replace('&amp;', $amp, $url);
695
-	}
691
+    // &amp; ?
692
+    if ($amp != '&amp;') {
693
+        $url = str_replace('&amp;', $amp, $url);
694
+    }
696 695
 
697
-	// Si ca demarre par ? ou vide, donner './'
698
-	$url = preg_replace(',^([?].*)?$,', './\1', $url);
696
+    // Si ca demarre par ? ou vide, donner './'
697
+    $url = preg_replace(',^([?].*)?$,', './\1', $url);
699 698
 
700
-	return $url;
699
+    return $url;
701 700
 }
702 701
 
703 702
 
@@ -708,7 +707,7 @@  discard block
 block discarded – undo
708 707
  *     true si c'est le cas, false sinon.
709 708
  */
710 709
 function test_espace_prive() {
711
-	return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
710
+    return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
712 711
 }
713 712
 
714 713
 /**
@@ -718,7 +717,7 @@  discard block
 block discarded – undo
718 717
  * @return bool
719 718
  */
720 719
 function test_plugin_actif($plugin) {
721
-	return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
720
+    return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
722 721
 }
723 722
 
724 723
 /**
@@ -749,51 +748,51 @@  discard block
 block discarded – undo
749 748
  *     Texte
750 749
  */
751 750
 function _T($texte, $args = array(), $options = array()) {
752
-	static $traduire = false;
753
-	$o = array('class' => '', 'force' => true, 'sanitize' => true);
754
-	if ($options) {
755
-		// support de l'ancien argument $class
756
-		if (is_string($options)) {
757
-			$options = array('class' => $options);
758
-		}
759
-		$o = array_merge($o, $options);
760
-	}
751
+    static $traduire = false;
752
+    $o = array('class' => '', 'force' => true, 'sanitize' => true);
753
+    if ($options) {
754
+        // support de l'ancien argument $class
755
+        if (is_string($options)) {
756
+            $options = array('class' => $options);
757
+        }
758
+        $o = array_merge($o, $options);
759
+    }
761 760
 
762
-	if (!$traduire) {
763
-		$traduire = charger_fonction('traduire', 'inc');
764
-		include_spip('inc/lang');
765
-	}
761
+    if (!$traduire) {
762
+        $traduire = charger_fonction('traduire', 'inc');
763
+        include_spip('inc/lang');
764
+    }
766 765
 
767
-	// On peut passer explicitement la langue dans le tableau
768
-	// On utilise le même nom de variable que la globale
769
-	if (isset($args['spip_lang'])) {
770
-		$lang = $args['spip_lang'];
771
-		// On l'enleve pour ne pas le passer au remplacement
772
-		unset($args['spip_lang']);
773
-	} // Sinon on prend la langue du contexte
774
-	else {
775
-		$lang = $GLOBALS['spip_lang'];
776
-	}
777
-	$text = $traduire($texte, $lang);
766
+    // On peut passer explicitement la langue dans le tableau
767
+    // On utilise le même nom de variable que la globale
768
+    if (isset($args['spip_lang'])) {
769
+        $lang = $args['spip_lang'];
770
+        // On l'enleve pour ne pas le passer au remplacement
771
+        unset($args['spip_lang']);
772
+    } // Sinon on prend la langue du contexte
773
+    else {
774
+        $lang = $GLOBALS['spip_lang'];
775
+    }
776
+    $text = $traduire($texte, $lang);
778 777
 
779
-	if (!strlen($text)) {
780
-		if (!$o['force']) {
781
-			return '';
782
-		}
778
+    if (!strlen($text)) {
779
+        if (!$o['force']) {
780
+            return '';
781
+        }
783 782
 
784
-		$text = $texte;
783
+        $text = $texte;
785 784
 
786
-		// pour les chaines non traduites, assurer un service minimum
787
-		if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
788
-			$text = str_replace('_', ' ',
789
-				(($n = strpos($text, ':')) === false ? $texte :
790
-					substr($texte, $n + 1)));
791
-		}
792
-		$o['class'] = null;
785
+        // pour les chaines non traduites, assurer un service minimum
786
+        if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
787
+            $text = str_replace('_', ' ',
788
+                (($n = strpos($text, ':')) === false ? $texte :
789
+                    substr($texte, $n + 1)));
790
+        }
791
+        $o['class'] = null;
793 792
 
794
-	}
793
+    }
795 794
 
796
-	return _L($text, $args, $o);
795
+    return _L($text, $args, $o);
797 796
 
798 797
 }
799 798
 
@@ -821,54 +820,54 @@  discard block
 block discarded – undo
821 820
  *     Texte
822 821
  */
823 822
 function _L($text, $args = array(), $options = array()) {
824
-	$f = $text;
825
-	$defaut_options = array(
826
-		'class' => null,
827
-		'sanitize' => true,
828
-	);
829
-	// support de l'ancien argument $class
830
-	if ($options and is_string($options)) {
831
-		$options = array('class' => $options);
832
-	}
833
-	if (is_array($options)) {
834
-		$options += $defaut_options;
835
-	} else {
836
-		$options = $defaut_options;
837
-	}
838
-
839
-	if (is_array($args)) {
840
-		if (!function_exists('interdire_scripts')) {
841
-			include_spip('inc/texte');
842
-		}
843
-		if (!function_exists('echapper_html_suspect')) {
844
-			include_spip('inc/texte_mini');
845
-		}
846
-		foreach ($args as $name => $value) {
847
-			if ($options['sanitize']) {
848
-				$value = echapper_html_suspect($value);
849
-				$value = interdire_scripts($value, -1);
850
-			}
851
-			if (!empty($options['class'])) {
852
-				$value = "<span class='".$options['class']."'>$value</span>";
853
-			}
854
-			$t = str_replace("@$name@", $value, $text);
855
-			if ($text !== $t) {
856
-				unset($args[$name]);
857
-				$text = $t;
858
-			}
859
-		}
860
-		// Si des variables n'ont pas ete inserees, le signaler
861
-		// (chaines de langues pas a jour)
862
-		if ($args) {
863
-			spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
864
-		}
865
-	}
866
-
867
-	if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
868
-		return "<span class=debug-traduction-erreur>$text</span>";
869
-	} else {
870
-		return $text;
871
-	}
823
+    $f = $text;
824
+    $defaut_options = array(
825
+        'class' => null,
826
+        'sanitize' => true,
827
+    );
828
+    // support de l'ancien argument $class
829
+    if ($options and is_string($options)) {
830
+        $options = array('class' => $options);
831
+    }
832
+    if (is_array($options)) {
833
+        $options += $defaut_options;
834
+    } else {
835
+        $options = $defaut_options;
836
+    }
837
+
838
+    if (is_array($args)) {
839
+        if (!function_exists('interdire_scripts')) {
840
+            include_spip('inc/texte');
841
+        }
842
+        if (!function_exists('echapper_html_suspect')) {
843
+            include_spip('inc/texte_mini');
844
+        }
845
+        foreach ($args as $name => $value) {
846
+            if ($options['sanitize']) {
847
+                $value = echapper_html_suspect($value);
848
+                $value = interdire_scripts($value, -1);
849
+            }
850
+            if (!empty($options['class'])) {
851
+                $value = "<span class='".$options['class']."'>$value</span>";
852
+            }
853
+            $t = str_replace("@$name@", $value, $text);
854
+            if ($text !== $t) {
855
+                unset($args[$name]);
856
+                $text = $t;
857
+            }
858
+        }
859
+        // Si des variables n'ont pas ete inserees, le signaler
860
+        // (chaines de langues pas a jour)
861
+        if ($args) {
862
+            spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
863
+        }
864
+    }
865
+
866
+    if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
867
+        return "<span class=debug-traduction-erreur>$text</span>";
868
+    } else {
869
+        return $text;
870
+    }
872 871
 }
873 872
 
874 873
 
@@ -882,13 +881,13 @@  discard block
 block discarded – undo
882 881
  * @return string
883 882
  */
884 883
 function joli_repertoire($rep) {
885
-	$a = substr($rep, 0, 1);
886
-	if ($a <> '.' and $a <> '/') {
887
-		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
888
-	}
889
-	$rep = preg_replace(',(^\.\.\/),', '', $rep);
884
+    $a = substr($rep, 0, 1);
885
+    if ($a <> '.' and $a <> '/') {
886
+        $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
887
+    }
888
+    $rep = preg_replace(',(^\.\.\/),', '', $rep);
890 889
 
891
-	return $rep;
890
+    return $rep;
892 891
 }
893 892
 
894 893
 
@@ -913,33 +912,33 @@  discard block
 block discarded – undo
913 912
  * @return float|int|string|void
914 913
  */
915 914
 function spip_timer($t = 'rien', $raw = false) {
916
-	static $time;
917
-	$a = time();
918
-	$b = microtime();
919
-	// microtime peut contenir les microsecondes et le temps
920
-	$b = explode(' ', $b);
921
-	if (count($b) == 2) {
922
-		$a = end($b);
923
-	} // plus precis !
924
-	$b = reset($b);
925
-	if (!isset($time[$t])) {
926
-		$time[$t] = $a + $b;
927
-	} else {
928
-		$p = ($a + $b - $time[$t]) * 1000;
929
-		unset($time[$t]);
915
+    static $time;
916
+    $a = time();
917
+    $b = microtime();
918
+    // microtime peut contenir les microsecondes et le temps
919
+    $b = explode(' ', $b);
920
+    if (count($b) == 2) {
921
+        $a = end($b);
922
+    } // plus precis !
923
+    $b = reset($b);
924
+    if (!isset($time[$t])) {
925
+        $time[$t] = $a + $b;
926
+    } else {
927
+        $p = ($a + $b - $time[$t]) * 1000;
928
+        unset($time[$t]);
930 929
 #			echo "'$p'";exit;
931
-		if ($raw) {
932
-			return $p;
933
-		}
934
-		if ($p < 1000) {
935
-			$s = '';
936
-		} else {
937
-			$s = sprintf("%d ", $x = floor($p / 1000));
938
-			$p -= ($x * 1000);
939
-		}
930
+        if ($raw) {
931
+            return $p;
932
+        }
933
+        if ($p < 1000) {
934
+            $s = '';
935
+        } else {
936
+            $s = sprintf("%d ", $x = floor($p / 1000));
937
+            $p -= ($x * 1000);
938
+        }
940 939
 
941
-		return $s . sprintf($s ? "%07.3f ms" : "%.3f ms", $p);
942
-	}
940
+        return $s . sprintf($s ? "%07.3f ms" : "%.3f ms", $p);
941
+    }
943 942
 }
944 943
 
945 944
 
@@ -947,21 +946,21 @@  discard block
 block discarded – undo
947 946
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
948 947
 // http://code.spip.net/@spip_touch
949 948
 function spip_touch($fichier, $duree = 0, $touch = true) {
950
-	if ($duree) {
951
-		clearstatcache();
952
-		if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
953
-			return false;
954
-		}
955
-	}
956
-	if ($touch !== false) {
957
-		if (!@touch($fichier)) {
958
-			spip_unlink($fichier);
959
-			@touch($fichier);
960
-		};
961
-		@chmod($fichier, _SPIP_CHMOD & ~0111);
962
-	}
949
+    if ($duree) {
950
+        clearstatcache();
951
+        if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
952
+            return false;
953
+        }
954
+    }
955
+    if ($touch !== false) {
956
+        if (!@touch($fichier)) {
957
+            spip_unlink($fichier);
958
+            @touch($fichier);
959
+        };
960
+        @chmod($fichier, _SPIP_CHMOD & ~0111);
961
+    }
963 962
 
964
-	return true;
963
+    return true;
965 964
 }
966 965
 
967 966
 
@@ -973,11 +972,11 @@  discard block
 block discarded – undo
973 972
  * @uses cron()
974 973
  **/
975 974
 function action_cron() {
976
-	include_spip('inc/headers');
977
-	http_status(204); // No Content
978
-	header("Connection: close");
979
-	define('_DIRECT_CRON_FORCE', true);
980
-	cron();
975
+    include_spip('inc/headers');
976
+    http_status(204); // No Content
977
+    header("Connection: close");
978
+    define('_DIRECT_CRON_FORCE', true);
979
+    cron();
981 980
 }
982 981
 
983 982
 /**
@@ -993,26 +992,26 @@  discard block
 block discarded – undo
993 992
  *     True si la tache a pu être effectuée
994 993
  */
995 994
 function cron($taches = array(), $taches_old = array()) {
996
-	// si pas en mode cron force, laisser tomber.
997
-	if (!defined('_DIRECT_CRON_FORCE')) {
998
-		return false;
999
-	}
1000
-	if (!is_array($taches)) {
1001
-		$taches = $taches_old;
1002
-	} // compat anciens appels
1003
-	// si taches a inserer en base et base inaccessible, laisser tomber
1004
-	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1005
-	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1006
-	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1007
-	if ($taches and count($taches) and !spip_connect()) {
1008
-		return false;
1009
-	}
1010
-	spip_log("cron !", 'jq' . _LOG_DEBUG);
1011
-	if ($genie = charger_fonction('genie', 'inc', true)) {
1012
-		return $genie($taches);
1013
-	}
1014
-
1015
-	return false;
995
+    // si pas en mode cron force, laisser tomber.
996
+    if (!defined('_DIRECT_CRON_FORCE')) {
997
+        return false;
998
+    }
999
+    if (!is_array($taches)) {
1000
+        $taches = $taches_old;
1001
+    } // compat anciens appels
1002
+    // si taches a inserer en base et base inaccessible, laisser tomber
1003
+    // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1004
+    // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1005
+    // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1006
+    if ($taches and count($taches) and !spip_connect()) {
1007
+        return false;
1008
+    }
1009
+    spip_log("cron !", 'jq' . _LOG_DEBUG);
1010
+    if ($genie = charger_fonction('genie', 'inc', true)) {
1011
+        return $genie($taches);
1012
+    }
1013
+
1014
+    return false;
1016 1015
 }
1017 1016
 
1018 1017
 /**
@@ -1044,17 +1043,17 @@  discard block
 block discarded – undo
1044 1043
  *     Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté.
1045 1044
  */
1046 1045
 function job_queue_add(
1047
-	$function,
1048
-	$description,
1049
-	$arguments = array(),
1050
-	$file = '',
1051
-	$no_duplicate = false,
1052
-	$time = 0,
1053
-	$priority = 0
1046
+    $function,
1047
+    $description,
1048
+    $arguments = array(),
1049
+    $file = '',
1050
+    $no_duplicate = false,
1051
+    $time = 0,
1052
+    $priority = 0
1054 1053
 ) {
1055
-	include_spip('inc/queue');
1054
+    include_spip('inc/queue');
1056 1055
 
1057
-	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1056
+    return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1058 1057
 }
1059 1058
 
1060 1059
 /**
@@ -1065,9 +1064,9 @@  discard block
 block discarded – undo
1065 1064
  * @return bool
1066 1065
  */
1067 1066
 function job_queue_remove($id_job) {
1068
-	include_spip('inc/queue');
1067
+    include_spip('inc/queue');
1069 1068
 
1070
-	return queue_remove_job($id_job);
1069
+    return queue_remove_job($id_job);
1071 1070
 }
1072 1071
 
1073 1072
 /**
@@ -1080,9 +1079,9 @@  discard block
 block discarded – undo
1080 1079
  *     or an array of simple array to link multiples objet in one time
1081 1080
  */
1082 1081
 function job_queue_link($id_job, $objets) {
1083
-	include_spip('inc/queue');
1082
+    include_spip('inc/queue');
1084 1083
 
1085
-	return queue_link_job($id_job, $objets);
1084
+    return queue_link_job($id_job, $objets);
1086 1085
 }
1087 1086
 
1088 1087
 
@@ -1102,36 +1101,36 @@  discard block
 block discarded – undo
1102 1101
  *  - `null` si la queue n'est pas encore initialisée
1103 1102
  */
1104 1103
 function queue_sleep_time_to_next_job($force = null) {
1105
-	static $queue_next_job_time = -1;
1106
-	if ($force === true) {
1107
-		$queue_next_job_time = -1;
1108
-	} elseif ($force) {
1109
-		$queue_next_job_time = $force;
1110
-	}
1111
-
1112
-	if ($queue_next_job_time == -1) {
1113
-		if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1114
-			define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . "job_queue_next.txt");
1115
-		}
1116
-		// utiliser un cache memoire si dispo
1117
-		if (function_exists("cache_get") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1118
-			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1119
-		} else {
1120
-			$queue_next_job_time = null;
1121
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1122
-				$queue_next_job_time = intval($contenu);
1123
-			}
1124
-		}
1125
-	}
1126
-
1127
-	if (is_null($queue_next_job_time)) {
1128
-		return null;
1129
-	}
1130
-	if (!$_SERVER['REQUEST_TIME']) {
1131
-		$_SERVER['REQUEST_TIME'] = time();
1132
-	}
1133
-
1134
-	return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1104
+    static $queue_next_job_time = -1;
1105
+    if ($force === true) {
1106
+        $queue_next_job_time = -1;
1107
+    } elseif ($force) {
1108
+        $queue_next_job_time = $force;
1109
+    }
1110
+
1111
+    if ($queue_next_job_time == -1) {
1112
+        if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1113
+            define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . "job_queue_next.txt");
1114
+        }
1115
+        // utiliser un cache memoire si dispo
1116
+        if (function_exists("cache_get") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1117
+            $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1118
+        } else {
1119
+            $queue_next_job_time = null;
1120
+            if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1121
+                $queue_next_job_time = intval($contenu);
1122
+            }
1123
+        }
1124
+    }
1125
+
1126
+    if (is_null($queue_next_job_time)) {
1127
+        return null;
1128
+    }
1129
+    if (!$_SERVER['REQUEST_TIME']) {
1130
+        $_SERVER['REQUEST_TIME'] = time();
1131
+    }
1132
+
1133
+    return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1135 1134
 }
1136 1135
 
1137 1136
 
@@ -1143,9 +1142,9 @@  discard block
 block discarded – undo
1143 1142
  * @return string
1144 1143
  */
1145 1144
 function quote_amp($u) {
1146
-	return preg_replace(
1147
-		"/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i",
1148
-		"&amp;", $u);
1145
+    return preg_replace(
1146
+        "/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i",
1147
+        "&amp;", $u);
1149 1148
 }
1150 1149
 
1151 1150
 
@@ -1168,27 +1167,27 @@  discard block
 block discarded – undo
1168 1167
  *     Balise HTML `<script>` et son contenu
1169 1168
  **/
1170 1169
 function http_script($script, $src = '', $noscript = '') {
1171
-	static $done = array();
1170
+    static $done = array();
1172 1171
 
1173
-	if ($src && !isset($done[$src])) {
1174
-		$done[$src] = true;
1175
-		$src = find_in_path($src, _JAVASCRIPT);
1176
-		$src = " src='$src'";
1177
-	} else {
1178
-		$src = '';
1179
-	}
1180
-	if ($script) {
1181
-		$script = ("/*<![CDATA[*/\n" .
1182
-			preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1183
-			"/*]]>*/");
1184
-	}
1185
-	if ($noscript) {
1186
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1187
-	}
1172
+    if ($src && !isset($done[$src])) {
1173
+        $done[$src] = true;
1174
+        $src = find_in_path($src, _JAVASCRIPT);
1175
+        $src = " src='$src'";
1176
+    } else {
1177
+        $src = '';
1178
+    }
1179
+    if ($script) {
1180
+        $script = ("/*<![CDATA[*/\n" .
1181
+            preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1182
+            "/*]]>*/");
1183
+    }
1184
+    if ($noscript) {
1185
+        $noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1186
+    }
1188 1187
 
1189
-	return ($src or $script or $noscript)
1190
-		? "<script type='text/javascript'$src>$script</script>$noscript"
1191
-		: '';
1188
+    return ($src or $script or $noscript)
1189
+        ? "<script type='text/javascript'$src>$script</script>$noscript"
1190
+        : '';
1192 1191
 }
1193 1192
 
1194 1193
 
@@ -1223,7 +1222,7 @@  discard block
 block discarded – undo
1223 1222
  *     Texte échappé
1224 1223
  **/
1225 1224
 function texte_script($texte) {
1226
-	return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1225
+    return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1227 1226
 }
1228 1227
 
1229 1228
 
@@ -1260,69 +1259,69 @@  discard block
 block discarded – undo
1260 1259
  *     Liste des chemins, par ordre de priorité.
1261 1260
  **/
1262 1261
 function _chemin($dir_path = null) {
1263
-	static $path_base = null;
1264
-	static $path_full = null;
1265
-	if ($path_base == null) {
1266
-		// Chemin standard depuis l'espace public
1267
-		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
1268
-			_DIR_RACINE . ':' .
1269
-			_DIR_RACINE . 'squelettes-dist/:' .
1270
-			_DIR_RACINE . 'prive/:' .
1271
-			_DIR_RESTREINT;
1272
-		// Ajouter squelettes/
1273
-		if (@is_dir(_DIR_RACINE . 'squelettes')) {
1274
-			$path = _DIR_RACINE . 'squelettes/:' . $path;
1275
-		}
1276
-		foreach (explode(':', $path) as $dir) {
1277
-			if (strlen($dir) and substr($dir, -1) != '/') {
1278
-				$dir .= "/";
1279
-			}
1280
-			$path_base[] = $dir;
1281
-		}
1282
-		$path_full = $path_base;
1283
-		// Et le(s) dossier(s) des squelettes nommes
1284
-		if (strlen($GLOBALS['dossier_squelettes'])) {
1285
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1286
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1287
-			}
1288
-		}
1289
-		$GLOBALS['path_sig'] = md5(serialize($path_full));
1290
-	}
1291
-	if ($dir_path === null) {
1292
-		return $path_full;
1293
-	}
1294
-
1295
-	if (strlen($dir_path)) {
1296
-		$tete = "";
1297
-		if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1298
-			$tete = array_shift($path_base);
1299
-		}
1300
-		$dirs = array_reverse(explode(':', $dir_path));
1301
-		foreach ($dirs as $dir_path) {
1302
-			#if ($dir_path{0}!='/')
1303
-			#	$dir_path = $dir_path;
1304
-			if (substr($dir_path, -1) != '/') {
1305
-				$dir_path .= "/";
1306
-			}
1307
-			if (!in_array($dir_path, $path_base)) {
1308
-				array_unshift($path_base, $dir_path);
1309
-			}
1310
-		}
1311
-		if (strlen($tete)) {
1312
-			array_unshift($path_base, $tete);
1313
-		}
1314
-	}
1315
-	$path_full = $path_base;
1316
-	// Et le(s) dossier(s) des squelettes nommes
1317
-	if (strlen($GLOBALS['dossier_squelettes'])) {
1318
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1319
-			array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1320
-		}
1321
-	}
1322
-
1323
-	$GLOBALS['path_sig'] = md5(serialize($path_full));
1324
-
1325
-	return $path_full;
1262
+    static $path_base = null;
1263
+    static $path_full = null;
1264
+    if ($path_base == null) {
1265
+        // Chemin standard depuis l'espace public
1266
+        $path = defined('_SPIP_PATH') ? _SPIP_PATH :
1267
+            _DIR_RACINE . ':' .
1268
+            _DIR_RACINE . 'squelettes-dist/:' .
1269
+            _DIR_RACINE . 'prive/:' .
1270
+            _DIR_RESTREINT;
1271
+        // Ajouter squelettes/
1272
+        if (@is_dir(_DIR_RACINE . 'squelettes')) {
1273
+            $path = _DIR_RACINE . 'squelettes/:' . $path;
1274
+        }
1275
+        foreach (explode(':', $path) as $dir) {
1276
+            if (strlen($dir) and substr($dir, -1) != '/') {
1277
+                $dir .= "/";
1278
+            }
1279
+            $path_base[] = $dir;
1280
+        }
1281
+        $path_full = $path_base;
1282
+        // Et le(s) dossier(s) des squelettes nommes
1283
+        if (strlen($GLOBALS['dossier_squelettes'])) {
1284
+            foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1285
+                array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1286
+            }
1287
+        }
1288
+        $GLOBALS['path_sig'] = md5(serialize($path_full));
1289
+    }
1290
+    if ($dir_path === null) {
1291
+        return $path_full;
1292
+    }
1293
+
1294
+    if (strlen($dir_path)) {
1295
+        $tete = "";
1296
+        if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1297
+            $tete = array_shift($path_base);
1298
+        }
1299
+        $dirs = array_reverse(explode(':', $dir_path));
1300
+        foreach ($dirs as $dir_path) {
1301
+            #if ($dir_path{0}!='/')
1302
+            #	$dir_path = $dir_path;
1303
+            if (substr($dir_path, -1) != '/') {
1304
+                $dir_path .= "/";
1305
+            }
1306
+            if (!in_array($dir_path, $path_base)) {
1307
+                array_unshift($path_base, $dir_path);
1308
+            }
1309
+        }
1310
+        if (strlen($tete)) {
1311
+            array_unshift($path_base, $tete);
1312
+        }
1313
+    }
1314
+    $path_full = $path_base;
1315
+    // Et le(s) dossier(s) des squelettes nommes
1316
+    if (strlen($GLOBALS['dossier_squelettes'])) {
1317
+        foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1318
+            array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1319
+        }
1320
+    }
1321
+
1322
+    $GLOBALS['path_sig'] = md5(serialize($path_full));
1323
+
1324
+    return $path_full;
1326 1325
 }
1327 1326
 
1328 1327
 /**
@@ -1335,63 +1334,63 @@  discard block
 block discarded – undo
1335 1334
  * @return array Liste de chemins
1336 1335
  **/
1337 1336
 function creer_chemin() {
1338
-	$path_a = _chemin();
1339
-	static $c = '';
1337
+    $path_a = _chemin();
1338
+    static $c = '';
1340 1339
 
1341
-	// on calcule le chemin si le dossier skel a change
1342
-	if ($c != $GLOBALS['dossier_squelettes']) {
1343
-		// assurer le non plantage lors de la montee de version :
1344
-		$c = $GLOBALS['dossier_squelettes'];
1345
-		$path_a = _chemin(''); // forcer un recalcul du chemin
1346
-	}
1340
+    // on calcule le chemin si le dossier skel a change
1341
+    if ($c != $GLOBALS['dossier_squelettes']) {
1342
+        // assurer le non plantage lors de la montee de version :
1343
+        $c = $GLOBALS['dossier_squelettes'];
1344
+        $path_a = _chemin(''); // forcer un recalcul du chemin
1345
+    }
1347 1346
 
1348
-	return $path_a;
1347
+    return $path_a;
1349 1348
 }
1350 1349
 
1351 1350
 
1352 1351
 function lister_themes_prives() {
1353
-	static $themes = null;
1354
-	if (is_null($themes)) {
1355
-		// si pas encore definie
1356
-		if (!defined('_SPIP_THEME_PRIVE')) {
1357
-			define('_SPIP_THEME_PRIVE', 'spip');
1358
-		}
1359
-		$themes = array(_SPIP_THEME_PRIVE);
1360
-		// lors d'une installation neuve, prefs n'est pas definie.
1361
-		if (isset($GLOBALS['visiteur_session']['prefs'])) {
1362
-			$prefs = $GLOBALS['visiteur_session']['prefs'];
1363
-		} else {
1364
-			$prefs = array();
1365
-		}
1366
-		if (is_string($prefs)) {
1367
-			$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1368
-		}
1369
-		if (
1370
-			((isset($prefs['theme']) and $theme = $prefs['theme'])
1371
-				or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1372
-			and $theme != _SPIP_THEME_PRIVE
1373
-		) {
1374
-			array_unshift($themes, $theme);
1375
-		} // placer le theme choisi en tete
1376
-	}
1377
-
1378
-	return $themes;
1352
+    static $themes = null;
1353
+    if (is_null($themes)) {
1354
+        // si pas encore definie
1355
+        if (!defined('_SPIP_THEME_PRIVE')) {
1356
+            define('_SPIP_THEME_PRIVE', 'spip');
1357
+        }
1358
+        $themes = array(_SPIP_THEME_PRIVE);
1359
+        // lors d'une installation neuve, prefs n'est pas definie.
1360
+        if (isset($GLOBALS['visiteur_session']['prefs'])) {
1361
+            $prefs = $GLOBALS['visiteur_session']['prefs'];
1362
+        } else {
1363
+            $prefs = array();
1364
+        }
1365
+        if (is_string($prefs)) {
1366
+            $prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1367
+        }
1368
+        if (
1369
+            ((isset($prefs['theme']) and $theme = $prefs['theme'])
1370
+                or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1371
+            and $theme != _SPIP_THEME_PRIVE
1372
+        ) {
1373
+            array_unshift($themes, $theme);
1374
+        } // placer le theme choisi en tete
1375
+    }
1376
+
1377
+    return $themes;
1379 1378
 }
1380 1379
 
1381 1380
 function find_in_theme($file, $subdir = '', $include = false) {
1382
-	static $themefiles = array();
1383
-	if (isset($themefiles["$subdir$file"])) {
1384
-		return $themefiles["$subdir$file"];
1385
-	}
1386
-	$themes = lister_themes_prives();
1387
-	foreach ($themes as $theme) {
1388
-		if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1389
-			return $themefiles["$subdir$file"] = $f;
1390
-		}
1391
-	}
1392
-	spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1381
+    static $themefiles = array();
1382
+    if (isset($themefiles["$subdir$file"])) {
1383
+        return $themefiles["$subdir$file"];
1384
+    }
1385
+    $themes = lister_themes_prives();
1386
+    foreach ($themes as $theme) {
1387
+        if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1388
+            return $themefiles["$subdir$file"] = $f;
1389
+        }
1390
+    }
1391
+    spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1393 1392
 
1394
-	return $themefiles["$subdir$file"] = "";
1393
+    return $themefiles["$subdir$file"] = "";
1395 1394
 }
1396 1395
 
1397 1396
 
@@ -1415,28 +1414,28 @@  discard block
 block discarded – undo
1415 1414
  *     sinon chaîne vide.
1416 1415
  **/
1417 1416
 function chemin_image($icone) {
1418
-	static $icone_renommer;
1419
-	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
1420
-	if (strpos($icone, "/") !== false and file_exists($icone)) {
1421
-		return $icone;
1422
-	}
1423
-
1424
-	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1425
-	if (preg_match(',[.](png|gif|jpg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1426
-		return $f;
1427
-	}
1428
-	// sinon passer par le module de renommage
1429
-	if (is_null($icone_renommer)) {
1430
-		$icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1431
-	}
1432
-	if ($icone_renommer) {
1433
-		list($icone, $fonction) = $icone_renommer($icone, "");
1434
-		if (file_exists($icone)) {
1435
-			return $icone;
1436
-		}
1437
-	}
1438
-
1439
-	return find_in_path($icone, _NOM_IMG_PACK);
1417
+    static $icone_renommer;
1418
+    // gerer le cas d'un double appel en evitant de refaire le travail inutilement
1419
+    if (strpos($icone, "/") !== false and file_exists($icone)) {
1420
+        return $icone;
1421
+    }
1422
+
1423
+    // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1424
+    if (preg_match(',[.](png|gif|jpg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1425
+        return $f;
1426
+    }
1427
+    // sinon passer par le module de renommage
1428
+    if (is_null($icone_renommer)) {
1429
+        $icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1430
+    }
1431
+    if ($icone_renommer) {
1432
+        list($icone, $fonction) = $icone_renommer($icone, "");
1433
+        if (file_exists($icone)) {
1434
+            return $icone;
1435
+        }
1436
+    }
1437
+
1438
+    return find_in_path($icone, _NOM_IMG_PACK);
1440 1439
 }
1441 1440
 
1442 1441
 //
@@ -1474,123 +1473,123 @@  discard block
 block discarded – undo
1474 1473
  *     - false : fichier introuvable
1475 1474
  **/
1476 1475
 function find_in_path($file, $dirname = '', $include = false) {
1477
-	static $dirs = array();
1478
-	static $inc = array(); # cf http://trac.rezo.net/trac/spip/changeset/14743
1479
-	static $c = '';
1480
-
1481
-	// on calcule le chemin si le dossier skel a change
1482
-	if ($c != $GLOBALS['dossier_squelettes']) {
1483
-		// assurer le non plantage lors de la montee de version :
1484
-		$c = $GLOBALS['dossier_squelettes'];
1485
-		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1486
-	}
1487
-
1488
-	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1489
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1490
-			return false;
1491
-		}
1492
-		if ($include and !isset($inc[$dirname][$file])) {
1493
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1494
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1495
-		}
1496
-
1497
-		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1498
-	}
1499
-
1500
-	$a = strrpos($file, '/');
1501
-	if ($a !== false) {
1502
-		$dirname .= substr($file, 0, ++$a);
1503
-		$file = substr($file, $a);
1504
-	}
1505
-
1506
-	foreach (creer_chemin() as $dir) {
1507
-		if (!isset($dirs[$a = $dir . $dirname])) {
1508
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1509
-		}
1510
-		if ($dirs[$a]) {
1511
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
1512
-				if ($include and !isset($inc[$dirname][$file])) {
1513
-					include_once _ROOT_CWD . $a;
1514
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1515
-				}
1516
-				if (!defined('_SAUVER_CHEMIN')) {
1517
-					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1518
-					if (is_null($GLOBALS['path_files'])) {
1519
-						return $a;
1520
-					}
1521
-					define('_SAUVER_CHEMIN', true);
1522
-				}
1523
-
1524
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1525
-			}
1526
-		}
1527
-	}
1528
-
1529
-	if ($include) {
1530
-		spip_log("include_spip $dirname$file non trouve");
1531
-		if ($include === 'required') {
1532
-			echo '<pre>',
1533
-			"<strong>Erreur Fatale</strong><br />";
1534
-			if (function_exists('debug_print_backtrace')) {
1535
-				echo debug_print_backtrace();
1536
-			}
1537
-			echo '</pre>';
1538
-			die("Erreur interne: ne peut inclure $dirname$file");
1539
-		}
1540
-	}
1541
-
1542
-	if (!defined('_SAUVER_CHEMIN')) {
1543
-		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1544
-		if (is_null($GLOBALS['path_files'])) {
1545
-			return false;
1546
-		}
1547
-		define('_SAUVER_CHEMIN', true);
1548
-	}
1549
-
1550
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1476
+    static $dirs = array();
1477
+    static $inc = array(); # cf http://trac.rezo.net/trac/spip/changeset/14743
1478
+    static $c = '';
1479
+
1480
+    // on calcule le chemin si le dossier skel a change
1481
+    if ($c != $GLOBALS['dossier_squelettes']) {
1482
+        // assurer le non plantage lors de la montee de version :
1483
+        $c = $GLOBALS['dossier_squelettes'];
1484
+        creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1485
+    }
1486
+
1487
+    if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1488
+        if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1489
+            return false;
1490
+        }
1491
+        if ($include and !isset($inc[$dirname][$file])) {
1492
+            include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1493
+            $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1494
+        }
1495
+
1496
+        return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1497
+    }
1498
+
1499
+    $a = strrpos($file, '/');
1500
+    if ($a !== false) {
1501
+        $dirname .= substr($file, 0, ++$a);
1502
+        $file = substr($file, $a);
1503
+    }
1504
+
1505
+    foreach (creer_chemin() as $dir) {
1506
+        if (!isset($dirs[$a = $dir . $dirname])) {
1507
+            $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1508
+        }
1509
+        if ($dirs[$a]) {
1510
+            if (file_exists(_ROOT_CWD . ($a .= $file))) {
1511
+                if ($include and !isset($inc[$dirname][$file])) {
1512
+                    include_once _ROOT_CWD . $a;
1513
+                    $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1514
+                }
1515
+                if (!defined('_SAUVER_CHEMIN')) {
1516
+                    // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1517
+                    if (is_null($GLOBALS['path_files'])) {
1518
+                        return $a;
1519
+                    }
1520
+                    define('_SAUVER_CHEMIN', true);
1521
+                }
1522
+
1523
+                return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1524
+            }
1525
+        }
1526
+    }
1527
+
1528
+    if ($include) {
1529
+        spip_log("include_spip $dirname$file non trouve");
1530
+        if ($include === 'required') {
1531
+            echo '<pre>',
1532
+            "<strong>Erreur Fatale</strong><br />";
1533
+            if (function_exists('debug_print_backtrace')) {
1534
+                echo debug_print_backtrace();
1535
+            }
1536
+            echo '</pre>';
1537
+            die("Erreur interne: ne peut inclure $dirname$file");
1538
+        }
1539
+    }
1540
+
1541
+    if (!defined('_SAUVER_CHEMIN')) {
1542
+        // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1543
+        if (is_null($GLOBALS['path_files'])) {
1544
+            return false;
1545
+        }
1546
+        define('_SAUVER_CHEMIN', true);
1547
+    }
1548
+
1549
+    return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1551 1550
 }
1552 1551
 
1553 1552
 function clear_path_cache() {
1554
-	$GLOBALS['path_files'] = array();
1555
-	spip_unlink(_CACHE_CHEMIN);
1553
+    $GLOBALS['path_files'] = array();
1554
+    spip_unlink(_CACHE_CHEMIN);
1556 1555
 }
1557 1556
 
1558 1557
 function load_path_cache() {
1559
-	// charger le path des plugins
1560
-	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1561
-		include_once(_CACHE_PLUGINS_PATH);
1562
-	}
1563
-	$GLOBALS['path_files'] = array();
1564
-	// si le visiteur est admin,
1565
-	// on ne recharge pas le cache pour forcer sa mise a jour
1566
-	if (
1567
-		// la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1568
-		//AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1569
-		// utiliser le cookie est un pis aller qui marche 'en general'
1570
-		// on blinde par un second test au moment de la lecture de la session
1571
-		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1572
-		// et en ignorant ce cache en cas de recalcul explicite
1573
-	!_request('var_mode')
1574
-	) {
1575
-		// on essaye de lire directement sans verrou pour aller plus vite
1576
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1577
-			// mais si semble corrompu on relit avec un verrou
1578
-			if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1579
-				lire_fichier(_CACHE_CHEMIN, $contenu);
1580
-				if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1581
-					$GLOBALS['path_files'] = array();
1582
-				}
1583
-			}
1584
-		}
1585
-	}
1558
+    // charger le path des plugins
1559
+    if (@is_readable(_CACHE_PLUGINS_PATH)) {
1560
+        include_once(_CACHE_PLUGINS_PATH);
1561
+    }
1562
+    $GLOBALS['path_files'] = array();
1563
+    // si le visiteur est admin,
1564
+    // on ne recharge pas le cache pour forcer sa mise a jour
1565
+    if (
1566
+        // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1567
+        //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1568
+        // utiliser le cookie est un pis aller qui marche 'en general'
1569
+        // on blinde par un second test au moment de la lecture de la session
1570
+        // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1571
+        // et en ignorant ce cache en cas de recalcul explicite
1572
+    !_request('var_mode')
1573
+    ) {
1574
+        // on essaye de lire directement sans verrou pour aller plus vite
1575
+        if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1576
+            // mais si semble corrompu on relit avec un verrou
1577
+            if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1578
+                lire_fichier(_CACHE_CHEMIN, $contenu);
1579
+                if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1580
+                    $GLOBALS['path_files'] = array();
1581
+                }
1582
+            }
1583
+        }
1584
+    }
1586 1585
 }
1587 1586
 
1588 1587
 function save_path_cache() {
1589
-	if (defined('_SAUVER_CHEMIN')
1590
-		and _SAUVER_CHEMIN
1591
-	) {
1592
-		ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1593
-	}
1588
+    if (defined('_SAUVER_CHEMIN')
1589
+        and _SAUVER_CHEMIN
1590
+    ) {
1591
+        ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1592
+    }
1594 1593
 }
1595 1594
 
1596 1595
 
@@ -1610,33 +1609,33 @@  discard block
 block discarded – undo
1610 1609
  * @return array
1611 1610
  */
1612 1611
 function find_all_in_path($dir, $pattern, $recurs = false) {
1613
-	$liste_fichiers = array();
1614
-	$maxfiles = 10000;
1615
-
1616
-	// cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1617
-	// on a pas encore inclus flock.php
1618
-	if (!function_exists('preg_files')) {
1619
-		include_once _ROOT_RESTREINT . 'inc/flock.php';
1620
-	}
1621
-
1622
-	// Parcourir le chemin
1623
-	foreach (creer_chemin() as $d) {
1624
-		$f = $d . $dir;
1625
-		if (@is_dir($f)) {
1626
-			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? array() : $recurs);
1627
-			foreach ($liste as $chemin) {
1628
-				$nom = basename($chemin);
1629
-				// ne prendre que les fichiers pas deja trouves
1630
-				// car find_in_path prend le premier qu'il trouve,
1631
-				// les autres sont donc masques
1632
-				if (!isset($liste_fichiers[$nom])) {
1633
-					$liste_fichiers[$nom] = $chemin;
1634
-				}
1635
-			}
1636
-		}
1637
-	}
1638
-
1639
-	return $liste_fichiers;
1612
+    $liste_fichiers = array();
1613
+    $maxfiles = 10000;
1614
+
1615
+    // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1616
+    // on a pas encore inclus flock.php
1617
+    if (!function_exists('preg_files')) {
1618
+        include_once _ROOT_RESTREINT . 'inc/flock.php';
1619
+    }
1620
+
1621
+    // Parcourir le chemin
1622
+    foreach (creer_chemin() as $d) {
1623
+        $f = $d . $dir;
1624
+        if (@is_dir($f)) {
1625
+            $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? array() : $recurs);
1626
+            foreach ($liste as $chemin) {
1627
+                $nom = basename($chemin);
1628
+                // ne prendre que les fichiers pas deja trouves
1629
+                // car find_in_path prend le premier qu'il trouve,
1630
+                // les autres sont donc masques
1631
+                if (!isset($liste_fichiers[$nom])) {
1632
+                    $liste_fichiers[$nom] = $chemin;
1633
+                }
1634
+            }
1635
+        }
1636
+    }
1637
+
1638
+    return $liste_fichiers;
1640 1639
 }
1641 1640
 
1642 1641
 /**
@@ -1645,10 +1644,10 @@  discard block
 block discarded – undo
1645 1644
  * @return bool
1646 1645
  */
1647 1646
 function autoriser_sans_cookie($nom) {
1648
-	static $autsanscookie = array('install', 'base_repair');
1649
-	$nom = preg_replace('/.php[3]?$/', '', basename($nom));
1647
+    static $autsanscookie = array('install', 'base_repair');
1648
+    $nom = preg_replace('/.php[3]?$/', '', basename($nom));
1650 1649
 
1651
-	return in_array($nom, $autsanscookie);
1650
+    return in_array($nom, $autsanscookie);
1652 1651
 }
1653 1652
 
1654 1653
 /**
@@ -1674,99 +1673,99 @@  discard block
 block discarded – undo
1674 1673
  *           (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_url_spip et une fonction generer_url_ecrire_spip)
1675 1674
  */
1676 1675
 function generer_url_entite($id = '', $entite = '', $args = '', $ancre = '', $public = null, $type = null) {
1677
-	if ($public === null) {
1678
-		$public = !test_espace_prive();
1679
-	}
1680
-	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1681
-
1682
-	if (!$public) {
1683
-		if (!$entite) {
1684
-			return '';
1685
-		}
1686
-		if (!function_exists('generer_url_ecrire_objet')) {
1687
-			include_spip('inc/urls');
1688
-		}
1689
-		$res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false);
1690
-	} else {
1691
-		if ($type === null) {
1692
-			$type = (isset($GLOBALS['type_urls']))
1693
-				? $GLOBALS['type_urls'] // pour surcharge via fichier d'options
1694
-				: ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues
1695
-					? ($GLOBALS['meta']['type_urls']) : "page"); // sinon type "page" par défaut
1696
-		}
1697
-
1698
-		$f = charger_fonction($type, 'urls', true);
1699
-		// se rabattre sur les urls page si les urls perso non dispo
1700
-		if (!$f) {
1701
-			$f = charger_fonction('page', 'urls', true);
1702
-		}
1703
-
1704
-		// si $entite='', on veut la fonction de passage URL ==> id
1705
-		// sinon on veut effectuer le passage id ==> URL
1706
-		if (!$entite) {
1707
-			return $f;
1708
-		}
1709
-
1710
-		// mais d'abord il faut tester le cas des urls sur une
1711
-		// base distante
1712
-		if (is_string($public)
1713
-			and $g = charger_fonction('connect', 'urls', true)
1714
-		) {
1715
-			$f = $g;
1716
-		}
1717
-
1718
-		$res = $f(intval($id), $entite, $args, $ancre, $public);
1719
-
1720
-	}
1721
-	if ($res) {
1722
-		return $res;
1723
-	}
1724
-	// Sinon c'est un raccourci ou compat SPIP < 2
1725
-	if (!function_exists($f = 'generer_url_' . $entite)) {
1726
-		if (!function_exists($f .= '_dist')) {
1727
-			$f = '';
1728
-		}
1729
-	}
1730
-	if ($f) {
1731
-		$url = $f($id, $args, $ancre);
1732
-		if (strlen($args)) {
1733
-			$url .= strstr($url, '?')
1734
-				? '&amp;' . $args
1735
-				: '?' . $args;
1736
-		}
1737
-
1738
-		return $url;
1739
-	}
1740
-	// On a ete gentil mais la ....
1741
-	spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public");
1742
-
1743
-	return '';
1676
+    if ($public === null) {
1677
+        $public = !test_espace_prive();
1678
+    }
1679
+    $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1680
+
1681
+    if (!$public) {
1682
+        if (!$entite) {
1683
+            return '';
1684
+        }
1685
+        if (!function_exists('generer_url_ecrire_objet')) {
1686
+            include_spip('inc/urls');
1687
+        }
1688
+        $res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false);
1689
+    } else {
1690
+        if ($type === null) {
1691
+            $type = (isset($GLOBALS['type_urls']))
1692
+                ? $GLOBALS['type_urls'] // pour surcharge via fichier d'options
1693
+                : ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues
1694
+                    ? ($GLOBALS['meta']['type_urls']) : "page"); // sinon type "page" par défaut
1695
+        }
1696
+
1697
+        $f = charger_fonction($type, 'urls', true);
1698
+        // se rabattre sur les urls page si les urls perso non dispo
1699
+        if (!$f) {
1700
+            $f = charger_fonction('page', 'urls', true);
1701
+        }
1702
+
1703
+        // si $entite='', on veut la fonction de passage URL ==> id
1704
+        // sinon on veut effectuer le passage id ==> URL
1705
+        if (!$entite) {
1706
+            return $f;
1707
+        }
1708
+
1709
+        // mais d'abord il faut tester le cas des urls sur une
1710
+        // base distante
1711
+        if (is_string($public)
1712
+            and $g = charger_fonction('connect', 'urls', true)
1713
+        ) {
1714
+            $f = $g;
1715
+        }
1716
+
1717
+        $res = $f(intval($id), $entite, $args, $ancre, $public);
1718
+
1719
+    }
1720
+    if ($res) {
1721
+        return $res;
1722
+    }
1723
+    // Sinon c'est un raccourci ou compat SPIP < 2
1724
+    if (!function_exists($f = 'generer_url_' . $entite)) {
1725
+        if (!function_exists($f .= '_dist')) {
1726
+            $f = '';
1727
+        }
1728
+    }
1729
+    if ($f) {
1730
+        $url = $f($id, $args, $ancre);
1731
+        if (strlen($args)) {
1732
+            $url .= strstr($url, '?')
1733
+                ? '&amp;' . $args
1734
+                : '?' . $args;
1735
+        }
1736
+
1737
+        return $url;
1738
+    }
1739
+    // On a ete gentil mais la ....
1740
+    spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public");
1741
+
1742
+    return '';
1744 1743
 }
1745 1744
 
1746 1745
 function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') {
1747
-	$exec = objet_info($entite, 'url_edit');
1748
-	$url = generer_url_ecrire($exec, $args);
1749
-	if (intval($id)) {
1750
-		$url = parametre_url($url, id_table_objet($entite), $id);
1751
-	} else {
1752
-		$url = parametre_url($url, 'new', 'oui');
1753
-	}
1754
-	if ($ancre) {
1755
-		$url = ancre_url($url, $ancre);
1756
-	}
1746
+    $exec = objet_info($entite, 'url_edit');
1747
+    $url = generer_url_ecrire($exec, $args);
1748
+    if (intval($id)) {
1749
+        $url = parametre_url($url, id_table_objet($entite), $id);
1750
+    } else {
1751
+        $url = parametre_url($url, 'new', 'oui');
1752
+    }
1753
+    if ($ancre) {
1754
+        $url = ancre_url($url, $ancre);
1755
+    }
1757 1756
 
1758
-	return $url;
1757
+    return $url;
1759 1758
 }
1760 1759
 
1761 1760
 // http://code.spip.net/@urls_connect_dist
1762 1761
 function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) {
1763
-	include_spip('base/connect_sql');
1764
-	$id_type = id_table_objet($entite, $public);
1762
+    include_spip('base/connect_sql');
1763
+    $id_type = id_table_objet($entite, $public);
1765 1764
 
1766
-	return _DIR_RACINE . get_spip_script('./')
1767
-	. "?" . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1768
-	. (!$args ? '' : "&$args")
1769
-	. (!$ancre ? '' : "#$ancre");
1765
+    return _DIR_RACINE . get_spip_script('./')
1766
+    . "?" . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1767
+    . (!$args ? '' : "&$args")
1768
+    . (!$ancre ? '' : "#$ancre");
1770 1769
 }
1771 1770
 
1772 1771
 
@@ -1777,32 +1776,32 @@  discard block
 block discarded – undo
1777 1776
  * @return string
1778 1777
  */
1779 1778
 function urlencode_1738($url) {
1780
-	if (preg_match(',[^\x00-\x7E],sS', $url)) {
1781
-		$uri = '';
1782
-		for ($i = 0; $i < strlen($url); $i++) {
1783
-			if (ord($a = $url[$i]) > 127) {
1784
-				$a = rawurlencode($a);
1785
-			}
1786
-			$uri .= $a;
1787
-		}
1788
-		$url = $uri;
1789
-	}
1779
+    if (preg_match(',[^\x00-\x7E],sS', $url)) {
1780
+        $uri = '';
1781
+        for ($i = 0; $i < strlen($url); $i++) {
1782
+            if (ord($a = $url[$i]) > 127) {
1783
+                $a = rawurlencode($a);
1784
+            }
1785
+            $uri .= $a;
1786
+        }
1787
+        $url = $uri;
1788
+    }
1790 1789
 
1791
-	return quote_amp($url);
1790
+    return quote_amp($url);
1792 1791
 }
1793 1792
 
1794 1793
 // http://code.spip.net/@generer_url_entite_absolue
1795 1794
 function generer_url_entite_absolue($id = '', $entite = '', $args = '', $ancre = '', $connect = null) {
1796
-	if (!$connect) {
1797
-		$connect = true;
1798
-	}
1799
-	$h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1800
-	if (!preg_match(',^\w+:,', $h)) {
1801
-		include_spip('inc/filtres_mini');
1802
-		$h = url_absolue($h);
1803
-	}
1795
+    if (!$connect) {
1796
+        $connect = true;
1797
+    }
1798
+    $h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1799
+    if (!preg_match(',^\w+:,', $h)) {
1800
+        include_spip('inc/filtres_mini');
1801
+        $h = url_absolue($h);
1802
+    }
1804 1803
 
1805
-	return $h;
1804
+    return $h;
1806 1805
 }
1807 1806
 
1808 1807
 
@@ -1818,11 +1817,11 @@  discard block
 block discarded – undo
1818 1817
  *     true si la valeur est considérée active ; false sinon.
1819 1818
  **/
1820 1819
 function test_valeur_serveur($truc) {
1821
-	if (!$truc) {
1822
-		return false;
1823
-	}
1820
+    if (!$truc) {
1821
+        return false;
1822
+    }
1824 1823
 
1825
-	return (strtolower($truc) !== 'off');
1824
+    return (strtolower($truc) !== 'off');
1826 1825
 }
1827 1826
 
1828 1827
 //
@@ -1850,80 +1849,80 @@  discard block
 block discarded – undo
1850 1849
  */
1851 1850
 function url_de_base($profondeur = null) {
1852 1851
 
1853
-	static $url = array();
1854
-	if (is_array($profondeur)) {
1855
-		return $url = $profondeur;
1856
-	}
1857
-	if ($profondeur === false) {
1858
-		return $url;
1859
-	}
1860
-
1861
-	if (is_null($profondeur)) {
1862
-		$profondeur = $GLOBALS['profondeur_url'];
1863
-	}
1864
-
1865
-	if (isset($url[$profondeur])) {
1866
-		return $url[$profondeur];
1867
-	}
1868
-
1869
-	$http = 'http';
1870
-
1871
-	if (
1872
-		isset($_SERVER["SCRIPT_URI"])
1873
-		and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https'
1874
-	) {
1875
-		$http = 'https';
1876
-	} elseif (
1877
-		isset($_SERVER['HTTPS'])
1878
-		and test_valeur_serveur($_SERVER['HTTPS'])
1879
-	) {
1880
-		$http = 'https';
1881
-	}
1882
-
1883
-	// note : HTTP_HOST contient le :port si necessaire
1884
-	$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
1885
-	// si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
1886
-	if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
1887
-		$host = $GLOBALS['meta']['adresse_site'];
1888
-		if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
1889
-			$http = $scheme;
1890
-			$host = str_replace("{$scheme}://", '', $host);
1891
-		}
1892
-	}
1893
-	if (isset($_SERVER['SERVER_PORT'])
1894
-		and $port = $_SERVER['SERVER_PORT']
1895
-		and strpos($host, ":") == false
1896
-	) {
1897
-		if (!defined('_PORT_HTTP_STANDARD')) {
1898
-			define('_PORT_HTTP_STANDARD', '80');
1899
-		}
1900
-		if (!defined('_PORT_HTTPS_STANDARD')) {
1901
-			define('_PORT_HTTPS_STANDARD', '443');
1902
-		}
1903
-		if ($http == "http" and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
1904
-			$host .= ":$port";
1905
-		}
1906
-		if ($http == "https" and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
1907
-			$host .= ":$port";
1908
-		}
1909
-	}
1910
-
1911
-	if (!$GLOBALS['REQUEST_URI']) {
1912
-		if (isset($_SERVER['REQUEST_URI'])) {
1913
-			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1914
-		} else {
1915
-			$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
1916
-			if (!empty($_SERVER['QUERY_STRING'])
1917
-				and !strpos($_SERVER['REQUEST_URI'], '?')
1918
-			) {
1919
-				$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
1920
-			}
1921
-		}
1922
-	}
1923
-
1924
-	$url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
1925
-
1926
-	return $url[$profondeur];
1852
+    static $url = array();
1853
+    if (is_array($profondeur)) {
1854
+        return $url = $profondeur;
1855
+    }
1856
+    if ($profondeur === false) {
1857
+        return $url;
1858
+    }
1859
+
1860
+    if (is_null($profondeur)) {
1861
+        $profondeur = $GLOBALS['profondeur_url'];
1862
+    }
1863
+
1864
+    if (isset($url[$profondeur])) {
1865
+        return $url[$profondeur];
1866
+    }
1867
+
1868
+    $http = 'http';
1869
+
1870
+    if (
1871
+        isset($_SERVER["SCRIPT_URI"])
1872
+        and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https'
1873
+    ) {
1874
+        $http = 'https';
1875
+    } elseif (
1876
+        isset($_SERVER['HTTPS'])
1877
+        and test_valeur_serveur($_SERVER['HTTPS'])
1878
+    ) {
1879
+        $http = 'https';
1880
+    }
1881
+
1882
+    // note : HTTP_HOST contient le :port si necessaire
1883
+    $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
1884
+    // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
1885
+    if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
1886
+        $host = $GLOBALS['meta']['adresse_site'];
1887
+        if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
1888
+            $http = $scheme;
1889
+            $host = str_replace("{$scheme}://", '', $host);
1890
+        }
1891
+    }
1892
+    if (isset($_SERVER['SERVER_PORT'])
1893
+        and $port = $_SERVER['SERVER_PORT']
1894
+        and strpos($host, ":") == false
1895
+    ) {
1896
+        if (!defined('_PORT_HTTP_STANDARD')) {
1897
+            define('_PORT_HTTP_STANDARD', '80');
1898
+        }
1899
+        if (!defined('_PORT_HTTPS_STANDARD')) {
1900
+            define('_PORT_HTTPS_STANDARD', '443');
1901
+        }
1902
+        if ($http == "http" and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
1903
+            $host .= ":$port";
1904
+        }
1905
+        if ($http == "https" and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
1906
+            $host .= ":$port";
1907
+        }
1908
+    }
1909
+
1910
+    if (!$GLOBALS['REQUEST_URI']) {
1911
+        if (isset($_SERVER['REQUEST_URI'])) {
1912
+            $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1913
+        } else {
1914
+            $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
1915
+            if (!empty($_SERVER['QUERY_STRING'])
1916
+                and !strpos($_SERVER['REQUEST_URI'], '?')
1917
+            ) {
1918
+                $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
1919
+            }
1920
+        }
1921
+    }
1922
+
1923
+    $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
1924
+
1925
+    return $url[$profondeur];
1927 1926
 }
1928 1927
 
1929 1928
 /**
@@ -1936,26 +1935,26 @@  discard block
 block discarded – undo
1936 1935
  * @return string
1937 1936
  */
1938 1937
 function url_de_($http, $host, $request, $prof = 0) {
1939
-	$prof = max($prof, 0);
1938
+    $prof = max($prof, 0);
1940 1939
 
1941
-	$myself = ltrim($request, '/');
1942
-	# supprimer la chaine de GET
1943
-	list($myself) = explode('?', $myself);
1944
-	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
1945
-	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
1946
-	if (strpos($myself,'://') !== false) {
1947
-		$myself = explode('://',$myself);
1948
-		array_shift($myself);
1949
-		$myself = implode('://',$myself);
1950
-		$myself = explode('/',$myself);
1951
-		array_shift($myself);
1952
-		$myself = implode('/',$myself);
1953
-	}
1954
-	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
1940
+    $myself = ltrim($request, '/');
1941
+    # supprimer la chaine de GET
1942
+    list($myself) = explode('?', $myself);
1943
+    // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
1944
+    // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
1945
+    if (strpos($myself,'://') !== false) {
1946
+        $myself = explode('://',$myself);
1947
+        array_shift($myself);
1948
+        $myself = implode('://',$myself);
1949
+        $myself = explode('/',$myself);
1950
+        array_shift($myself);
1951
+        $myself = implode('/',$myself);
1952
+    }
1953
+    $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
1955 1954
 
1956
-	$url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
1955
+    $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
1957 1956
 
1958
-	return $url;
1957
+    return $url;
1959 1958
 }
1960 1959
 
1961 1960
 
@@ -1990,26 +1989,26 @@  discard block
 block discarded – undo
1990 1989
  * @return string URL
1991 1990
  **/
1992 1991
 function generer_url_ecrire($script = '', $args = "", $no_entities = false, $rel = false) {
1993
-	if (!$rel) {
1994
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
1995
-	} else {
1996
-		if (!is_string($rel)) {
1997
-			$rel = _DIR_RESTREINT ? _DIR_RESTREINT :
1998
-				('./' . _SPIP_ECRIRE_SCRIPT);
1999
-		}
2000
-	}
2001
-
2002
-	list($script, $ancre) = array_pad(explode('#', $script), 2, null);
2003
-	if ($script and ($script <> 'accueil' or $rel)) {
2004
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
2005
-	} elseif ($args) {
2006
-		$args = "?$args";
2007
-	}
2008
-	if ($ancre) {
2009
-		$args .= "#$ancre";
2010
-	}
2011
-
2012
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
1992
+    if (!$rel) {
1993
+        $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
1994
+    } else {
1995
+        if (!is_string($rel)) {
1996
+            $rel = _DIR_RESTREINT ? _DIR_RESTREINT :
1997
+                ('./' . _SPIP_ECRIRE_SCRIPT);
1998
+        }
1999
+    }
2000
+
2001
+    list($script, $ancre) = array_pad(explode('#', $script), 2, null);
2002
+    if ($script and ($script <> 'accueil' or $rel)) {
2003
+        $args = "?exec=$script" . (!$args ? '' : "&$args");
2004
+    } elseif ($args) {
2005
+        $args = "?$args";
2006
+    }
2007
+    if ($ancre) {
2008
+        $args .= "#$ancre";
2009
+    }
2010
+
2011
+    return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2013 2012
 }
2014 2013
 
2015 2014
 //
@@ -2031,12 +2030,12 @@  discard block
 block discarded – undo
2031 2030
  *     Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut
2032 2031
  **/
2033 2032
 function get_spip_script($default = '') {
2034
-	# cas define('_SPIP_SCRIPT', '');
2035
-	if (_SPIP_SCRIPT) {
2036
-		return _SPIP_SCRIPT;
2037
-	} else {
2038
-		return $default;
2039
-	}
2033
+    # cas define('_SPIP_SCRIPT', '');
2034
+    if (_SPIP_SCRIPT) {
2035
+        return _SPIP_SCRIPT;
2036
+    } else {
2037
+        return $default;
2038
+    }
2040 2039
 }
2041 2040
 
2042 2041
 /**
@@ -2065,39 +2064,39 @@  discard block
 block discarded – undo
2065 2064
  * @return string URL
2066 2065
  **/
2067 2066
 function generer_url_public($script = '', $args = "", $no_entities = false, $rel = true, $action = '') {
2068
-	// si le script est une action (spip_pass, spip_inscription),
2069
-	// standardiser vers la nouvelle API
2070
-
2071
-	if (!$action) {
2072
-		$action = get_spip_script();
2073
-	}
2074
-	if ($script) {
2075
-		$action = parametre_url($action, _SPIP_PAGE, $script, '&');
2076
-	}
2077
-
2078
-	if ($args) {
2079
-		if (is_array($args)) {
2080
-			$r = '';
2081
-			foreach ($args as $k => $v) {
2082
-				$r .= '&' . $k . '=' . $v;
2083
-			}
2084
-			$args = substr($r, 1);
2085
-		}
2086
-		$action .=
2087
-			(strpos($action, '?') !== false ? '&' : '?') . $args;
2088
-	}
2089
-	if (!$no_entities) {
2090
-		$action = quote_amp($action);
2091
-	}
2092
-
2093
-	// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2094
-	return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(",^/[.]/,", "/", "/$action"));
2067
+    // si le script est une action (spip_pass, spip_inscription),
2068
+    // standardiser vers la nouvelle API
2069
+
2070
+    if (!$action) {
2071
+        $action = get_spip_script();
2072
+    }
2073
+    if ($script) {
2074
+        $action = parametre_url($action, _SPIP_PAGE, $script, '&');
2075
+    }
2076
+
2077
+    if ($args) {
2078
+        if (is_array($args)) {
2079
+            $r = '';
2080
+            foreach ($args as $k => $v) {
2081
+                $r .= '&' . $k . '=' . $v;
2082
+            }
2083
+            $args = substr($r, 1);
2084
+        }
2085
+        $action .=
2086
+            (strpos($action, '?') !== false ? '&' : '?') . $args;
2087
+    }
2088
+    if (!$no_entities) {
2089
+        $action = quote_amp($action);
2090
+    }
2091
+
2092
+    // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2093
+    return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(",^/[.]/,", "/", "/$action"));
2095 2094
 }
2096 2095
 
2097 2096
 // http://code.spip.net/@generer_url_prive
2098 2097
 function generer_url_prive($script, $args = "", $no_entities = false) {
2099 2098
 
2100
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2099
+    return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2101 2100
 }
2102 2101
 
2103 2102
 // Pour les formulaires en methode POST,
@@ -2122,19 +2121,19 @@  discard block
 block discarded – undo
2122 2121
  **/
2123 2122
 function generer_form_ecrire($script, $corps, $atts = '', $submit = '') {
2124 2123
 
2125
-	$script1 = explode('&', $script);
2126
-	$script1 = reset($script1);
2124
+    $script1 = explode('&', $script);
2125
+    $script1 = reset($script1);
2127 2126
 
2128
-	return "<form action='"
2129
-	. ($script ? generer_url_ecrire($script) : '')
2130
-	. "' "
2131
-	. ($atts ? $atts : " method='post'")
2132
-	. "><div>\n"
2133
-	. "<input type='hidden' name='exec' value='$script1' />"
2134
-	. $corps
2135
-	. (!$submit ? '' :
2136
-		("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo' type='submit' value=\"" . entites_html($submit) . "\" /></div>"))
2137
-	. "</div></form>\n";
2127
+    return "<form action='"
2128
+    . ($script ? generer_url_ecrire($script) : '')
2129
+    . "' "
2130
+    . ($atts ? $atts : " method='post'")
2131
+    . "><div>\n"
2132
+    . "<input type='hidden' name='exec' value='$script1' />"
2133
+    . $corps
2134
+    . (!$submit ? '' :
2135
+        ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo' type='submit' value=\"" . entites_html($submit) . "\" /></div>"))
2136
+    . "</div></form>\n";
2138 2137
 }
2139 2138
 
2140 2139
 /**
@@ -2151,22 +2150,22 @@  discard block
 block discarded – undo
2151 2150
  * @return string
2152 2151
  */
2153 2152
 function generer_form_action($script, $corps, $atts = '', $public = false) {
2154
-	// si l'on est dans l'espace prive, on garde dans l'url
2155
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2156
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2157
-	$h = (_DIR_RACINE and !$public)
2158
-		? generer_url_ecrire(_request('exec'))
2159
-		: generer_url_public();
2153
+    // si l'on est dans l'espace prive, on garde dans l'url
2154
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2155
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2156
+    $h = (_DIR_RACINE and !$public)
2157
+        ? generer_url_ecrire(_request('exec'))
2158
+        : generer_url_public();
2160 2159
 
2161
-	return "\n<form action='" .
2162
-	$h .
2163
-	"'" .
2164
-	$atts .
2165
-	">\n" .
2166
-	"<div>" .
2167
-	"\n<input type='hidden' name='action' value='$script' />" .
2168
-	$corps .
2169
-	"</div></form>";
2160
+    return "\n<form action='" .
2161
+    $h .
2162
+    "'" .
2163
+    $atts .
2164
+    ">\n" .
2165
+    "<div>" .
2166
+    "\n<input type='hidden' name='action' value='$script' />" .
2167
+    $corps .
2168
+    "</div></form>";
2170 2169
 }
2171 2170
 
2172 2171
 /**
@@ -2185,22 +2184,22 @@  discard block
 block discarded – undo
2185 2184
  *     URL
2186 2185
  */
2187 2186
 function generer_url_action($script, $args = "", $no_entities = false, $public = false) {
2188
-	// si l'on est dans l'espace prive, on garde dans l'url
2189
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2190
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2191
-	$url = (_DIR_RACINE and !$public)
2192
-		? generer_url_ecrire(_request('exec'))
2193
-		: generer_url_public('', '', false, false);
2194
-	$url = parametre_url($url, 'action', $script);
2195
-	if ($args) {
2196
-		$url .= quote_amp('&' . $args);
2197
-	}
2187
+    // si l'on est dans l'espace prive, on garde dans l'url
2188
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2189
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2190
+    $url = (_DIR_RACINE and !$public)
2191
+        ? generer_url_ecrire(_request('exec'))
2192
+        : generer_url_public('', '', false, false);
2193
+    $url = parametre_url($url, 'action', $script);
2194
+    if ($args) {
2195
+        $url .= quote_amp('&' . $args);
2196
+    }
2198 2197
 
2199
-	if ($no_entities) {
2200
-		$url = str_replace('&amp;', '&', $url);
2201
-	}
2198
+    if ($no_entities) {
2199
+        $url = str_replace('&amp;', '&', $url);
2200
+    }
2202 2201
 
2203
-	return $url;
2202
+    return $url;
2204 2203
 }
2205 2204
 
2206 2205
 
@@ -2213,8 +2212,8 @@  discard block
 block discarded – undo
2213 2212
  * @param string $ta Répertoire temporaire accessible
2214 2213
  */
2215 2214
 function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) {
2216
-	spip_initialisation_core($pi, $pa, $ti, $ta);
2217
-	spip_initialisation_suite();
2215
+    spip_initialisation_core($pi, $pa, $ti, $ta);
2216
+    spip_initialisation_suite();
2218 2217
 }
2219 2218
 
2220 2219
 /**
@@ -2234,315 +2233,315 @@  discard block
 block discarded – undo
2234 2233
  * @param string $ta Répertoire temporaire accessible
2235 2234
  */
2236 2235
 function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) {
2237
-	static $too_late = 0;
2238
-	if ($too_late++) {
2239
-		return;
2240
-	}
2241
-
2242
-	// Declaration des repertoires
2243
-
2244
-	// le nom du repertoire plugins/ activables/desactivables
2245
-	if (!defined('_DIR_PLUGINS')) {
2246
-		define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
2247
-	}
2248
-
2249
-	// le nom du repertoire des extensions/ permanentes du core, toujours actives
2250
-	if (!defined('_DIR_PLUGINS_DIST')) {
2251
-		define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
2252
-	}
2253
-
2254
-	// le nom du repertoire des librairies
2255
-	if (!defined('_DIR_LIB')) {
2256
-		define('_DIR_LIB', _DIR_RACINE . "lib/");
2257
-	}
2258
-
2259
-	if (!defined('_DIR_IMG')) {
2260
-		define('_DIR_IMG', $pa);
2261
-	}
2262
-	if (!defined('_DIR_LOGOS')) {
2263
-		define('_DIR_LOGOS', $pa);
2264
-	}
2265
-	if (!defined('_DIR_IMG_ICONES')) {
2266
-		define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
2267
-	}
2268
-
2269
-	if (!defined('_DIR_DUMP')) {
2270
-		define('_DIR_DUMP', $ti . "dump/");
2271
-	}
2272
-	if (!defined('_DIR_SESSIONS')) {
2273
-		define('_DIR_SESSIONS', $ti . "sessions/");
2274
-	}
2275
-	if (!defined('_DIR_TRANSFERT')) {
2276
-		define('_DIR_TRANSFERT', $ti . "upload/");
2277
-	}
2278
-	if (!defined('_DIR_CACHE')) {
2279
-		define('_DIR_CACHE', $ti . "cache/");
2280
-	}
2281
-	if (!defined('_DIR_CACHE_XML')) {
2282
-		define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
2283
-	}
2284
-	if (!defined('_DIR_SKELS')) {
2285
-		define('_DIR_SKELS', _DIR_CACHE . "skel/");
2286
-	}
2287
-	if (!defined('_DIR_AIDE')) {
2288
-		define('_DIR_AIDE', _DIR_CACHE . "aide/");
2289
-	}
2290
-	if (!defined('_DIR_TMP')) {
2291
-		define('_DIR_TMP', $ti);
2292
-	}
2293
-
2294
-	if (!defined('_DIR_VAR')) {
2295
-		define('_DIR_VAR', $ta);
2296
-	}
2297
-
2298
-	if (!defined('_DIR_ETC')) {
2299
-		define('_DIR_ETC', $pi);
2300
-	}
2301
-	if (!defined('_DIR_CONNECT')) {
2302
-		define('_DIR_CONNECT', $pi);
2303
-	}
2304
-	if (!defined('_DIR_CHMOD')) {
2305
-		define('_DIR_CHMOD', $pi);
2306
-	}
2307
-
2308
-	if (!isset($GLOBALS['test_dirs']))
2309
-		// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2310
-		// il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2311
-	{
2312
-		$GLOBALS['test_dirs'] = array($pa, $ti, $ta);
2313
-	}
2314
-
2315
-	// Declaration des fichiers
2316
-
2317
-	if (!defined('_CACHE_PLUGINS_PATH')) {
2318
-		define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
2319
-	}
2320
-	if (!defined('_CACHE_PLUGINS_OPT')) {
2321
-		define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
2322
-	}
2323
-	if (!defined('_CACHE_PLUGINS_FCT')) {
2324
-		define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
2325
-	}
2326
-	if (!defined('_CACHE_PIPELINES')) {
2327
-		define('_CACHE_PIPELINES', _DIR_CACHE . "charger_pipelines.php");
2328
-	}
2329
-	if (!defined('_CACHE_CHEMIN')) {
2330
-		define('_CACHE_CHEMIN', _DIR_CACHE . "chemin.txt");
2331
-	}
2332
-
2333
-	# attention .php obligatoire pour ecrire_fichier_securise
2334
-	if (!defined('_FILE_META')) {
2335
-		define('_FILE_META', $ti . 'meta_cache.php');
2336
-	}
2337
-	if (!defined('_DIR_LOG')) {
2338
-		define('_DIR_LOG', _DIR_TMP . 'log/');
2339
-	}
2340
-	if (!defined('_FILE_LOG')) {
2341
-		define('_FILE_LOG', 'spip');
2342
-	}
2343
-	if (!defined('_FILE_LOG_SUFFIX')) {
2344
-		define('_FILE_LOG_SUFFIX', '.log');
2345
-	}
2346
-
2347
-	// Le fichier de connexion a la base de donnees
2348
-	// tient compte des anciennes versions (inc_connect...)
2349
-	if (!defined('_FILE_CONNECT_INS')) {
2350
-		define('_FILE_CONNECT_INS', 'connect');
2351
-	}
2352
-	if (!defined('_FILE_CONNECT')) {
2353
-		define('_FILE_CONNECT',
2354
-		(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2355
-			: (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2356
-				: false)));
2357
-	}
2358
-
2359
-	// Le fichier de reglages des droits
2360
-	if (!defined('_FILE_CHMOD_INS')) {
2361
-		define('_FILE_CHMOD_INS', 'chmod');
2362
-	}
2363
-	if (!defined('_FILE_CHMOD')) {
2364
-		define('_FILE_CHMOD',
2365
-		(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2366
-			: false));
2367
-	}
2368
-
2369
-	if (!defined('_FILE_LDAP')) {
2370
-		define('_FILE_LDAP', 'ldap.php');
2371
-	}
2372
-
2373
-	if (!defined('_FILE_TMP_SUFFIX')) {
2374
-		define('_FILE_TMP_SUFFIX', '.tmp.php');
2375
-	}
2376
-	if (!defined('_FILE_CONNECT_TMP')) {
2377
-		define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2378
-	}
2379
-	if (!defined('_FILE_CHMOD_TMP')) {
2380
-		define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2381
-	}
2382
-
2383
-	// Definition des droits d'acces en ecriture
2384
-	if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2385
-		include_once _FILE_CHMOD;
2386
-	}
2387
-
2388
-	// Se mefier des fichiers mal remplis!
2389
-	if (!defined('_SPIP_CHMOD')) {
2390
-		define('_SPIP_CHMOD', 0777);
2391
-	}
2392
-
2393
-	if (!defined('_DEFAULT_CHARSET')) {
2394
-		/** Le charset par défaut lors de l'installation */
2395
-		define('_DEFAULT_CHARSET', 'utf-8');
2396
-	}
2397
-	if (!defined('_ROOT_PLUGINS')) {
2398
-		define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
2399
-	}
2400
-	if (!defined('_ROOT_PLUGINS_DIST')) {
2401
-		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
2402
-	}
2403
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2404
-		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2405
-	}
2406
-
2407
-	// La taille des Log
2408
-	if (!defined('_MAX_LOG')) {
2409
-		define('_MAX_LOG', 100);
2410
-	}
2411
-
2412
-	// Sommes-nous dans l'empire du Mal ?
2413
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
2414
-	if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2415
-		if (!defined('_OS_SERVEUR')) {
2416
-			define('_OS_SERVEUR', 'windows');
2417
-		}
2418
-		if (!defined('_SPIP_LOCK_MODE')) {
2419
-			define('_SPIP_LOCK_MODE', 1);
2420
-		} // utiliser le flock php
2421
-	} else {
2422
-		if (!defined('_OS_SERVEUR')) {
2423
-			define('_OS_SERVEUR', '');
2424
-		}
2425
-		if (!defined('_SPIP_LOCK_MODE')) {
2426
-			define('_SPIP_LOCK_MODE', 1);
2427
-		} // utiliser le flock php
2428
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2429
-	}
2430
-
2431
-	// Langue par defaut
2432
-	if (!defined('_LANGUE_PAR_DEFAUT')) {
2433
-		define('_LANGUE_PAR_DEFAUT', 'fr');
2434
-	}
2435
-
2436
-	//
2437
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
2438
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
2439
-	// pour le rendre surchargeable, on va provoquer un reecriture
2440
-	// systematique du noyau ou une baisse de perfs => a etudier)
2441
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
2442
-
2443
-	// charger tout de suite le path et son cache
2444
-	load_path_cache();
2445
-
2446
-	// *********** traiter les variables ************
2447
-
2448
-	//
2449
-	// Securite
2450
-	//
2451
-
2452
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2453
-	if (isset($_REQUEST['GLOBALS'])) {
2454
-		die();
2455
-	}
2456
-	// nettoyer les magic quotes \' et les caracteres nuls %00
2457
-	spip_desinfecte($_GET);
2458
-	spip_desinfecte($_POST);
2459
-	spip_desinfecte($_COOKIE);
2460
-	spip_desinfecte($_REQUEST);
2461
-
2462
-	// appliquer le cookie_prefix
2463
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
2464
-		include_spip('inc/cookie');
2465
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2466
-	}
2467
-
2468
-	//
2469
-	// Capacites php (en fonction de la version)
2470
-	//
2471
-	$GLOBALS['flag_ob'] = (function_exists("ob_start")
2472
-		&& function_exists("ini_get")
2473
-		&& !strstr(@ini_get('disable_functions'), 'ob_'));
2474
-	$GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name");
2475
-	$GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != "");
2476
-	$GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2477
-		(get_cfg_var('upload_max_filesize') > 0));
2478
-
2479
-
2480
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2481
-	if (isset($_SERVER['REQUEST_URI'])) {
2482
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2483
-	} else {
2484
-		$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2485
-		if (!empty($_SERVER['QUERY_STRING'])
2486
-			and !strpos($_SERVER['REQUEST_URI'], '?')
2487
-		) {
2488
-			$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2489
-		}
2490
-	}
2491
-
2492
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2493
-	if (!defined('_RENOUVELLE_ALEA')) {
2494
-		define('_RENOUVELLE_ALEA', 12 * 3600);
2495
-	}
2496
-	if (!defined('_DUREE_COOKIE_ADMIN')) {
2497
-		define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2498
-	}
2499
-
2500
-	// charger les meta si possible et renouveller l'alea au besoin
2501
-	// charge aussi effacer_meta et ecrire_meta
2502
-	$inc_meta = charger_fonction('meta', 'inc');
2503
-	$inc_meta();
2504
-
2505
-	// nombre de repertoires depuis la racine
2506
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2507
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2508
-	// le calcul est faux)
2509
-	if (!_DIR_RESTREINT) {
2510
-		$GLOBALS['profondeur_url'] = 1;
2511
-	} else {
2512
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2513
-		$uri_ref = $_SERVER["SCRIPT_NAME"];
2514
-		if (!$uri_ref
2515
-			// si on est appele avec un autre ti, on est sans doute en mutu
2516
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2517
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2518
-			// s'en remettre a l'adresse du site. alea jacta est.
2519
-			or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2520
-		) {
2521
-
2522
-			if (isset($GLOBALS['meta']['adresse_site'])) {
2523
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2524
-				$uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/';
2525
-			} else {
2526
-				$uri_ref = "";
2527
-			}
2528
-		}
2529
-		if (!$uri or !$uri_ref) {
2530
-			$GLOBALS['profondeur_url'] = 0;
2531
-		} else {
2532
-			$GLOBALS['profondeur_url'] = max(0,
2533
-				substr_count($uri[0], '/')
2534
-				- substr_count($uri_ref, '/'));
2535
-		}
2536
-	}
2537
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2538
-	if (_FILE_CONNECT) {
2539
-		if (verifier_visiteur() == '0minirezo'
2540
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2541
-			and !isset($_COOKIE['spip_admin'])
2542
-		) {
2543
-			clear_path_cache();
2544
-		}
2545
-	}
2236
+    static $too_late = 0;
2237
+    if ($too_late++) {
2238
+        return;
2239
+    }
2240
+
2241
+    // Declaration des repertoires
2242
+
2243
+    // le nom du repertoire plugins/ activables/desactivables
2244
+    if (!defined('_DIR_PLUGINS')) {
2245
+        define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
2246
+    }
2247
+
2248
+    // le nom du repertoire des extensions/ permanentes du core, toujours actives
2249
+    if (!defined('_DIR_PLUGINS_DIST')) {
2250
+        define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
2251
+    }
2252
+
2253
+    // le nom du repertoire des librairies
2254
+    if (!defined('_DIR_LIB')) {
2255
+        define('_DIR_LIB', _DIR_RACINE . "lib/");
2256
+    }
2257
+
2258
+    if (!defined('_DIR_IMG')) {
2259
+        define('_DIR_IMG', $pa);
2260
+    }
2261
+    if (!defined('_DIR_LOGOS')) {
2262
+        define('_DIR_LOGOS', $pa);
2263
+    }
2264
+    if (!defined('_DIR_IMG_ICONES')) {
2265
+        define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
2266
+    }
2267
+
2268
+    if (!defined('_DIR_DUMP')) {
2269
+        define('_DIR_DUMP', $ti . "dump/");
2270
+    }
2271
+    if (!defined('_DIR_SESSIONS')) {
2272
+        define('_DIR_SESSIONS', $ti . "sessions/");
2273
+    }
2274
+    if (!defined('_DIR_TRANSFERT')) {
2275
+        define('_DIR_TRANSFERT', $ti . "upload/");
2276
+    }
2277
+    if (!defined('_DIR_CACHE')) {
2278
+        define('_DIR_CACHE', $ti . "cache/");
2279
+    }
2280
+    if (!defined('_DIR_CACHE_XML')) {
2281
+        define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
2282
+    }
2283
+    if (!defined('_DIR_SKELS')) {
2284
+        define('_DIR_SKELS', _DIR_CACHE . "skel/");
2285
+    }
2286
+    if (!defined('_DIR_AIDE')) {
2287
+        define('_DIR_AIDE', _DIR_CACHE . "aide/");
2288
+    }
2289
+    if (!defined('_DIR_TMP')) {
2290
+        define('_DIR_TMP', $ti);
2291
+    }
2292
+
2293
+    if (!defined('_DIR_VAR')) {
2294
+        define('_DIR_VAR', $ta);
2295
+    }
2296
+
2297
+    if (!defined('_DIR_ETC')) {
2298
+        define('_DIR_ETC', $pi);
2299
+    }
2300
+    if (!defined('_DIR_CONNECT')) {
2301
+        define('_DIR_CONNECT', $pi);
2302
+    }
2303
+    if (!defined('_DIR_CHMOD')) {
2304
+        define('_DIR_CHMOD', $pi);
2305
+    }
2306
+
2307
+    if (!isset($GLOBALS['test_dirs']))
2308
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
2309
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2310
+    {
2311
+        $GLOBALS['test_dirs'] = array($pa, $ti, $ta);
2312
+    }
2313
+
2314
+    // Declaration des fichiers
2315
+
2316
+    if (!defined('_CACHE_PLUGINS_PATH')) {
2317
+        define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
2318
+    }
2319
+    if (!defined('_CACHE_PLUGINS_OPT')) {
2320
+        define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
2321
+    }
2322
+    if (!defined('_CACHE_PLUGINS_FCT')) {
2323
+        define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
2324
+    }
2325
+    if (!defined('_CACHE_PIPELINES')) {
2326
+        define('_CACHE_PIPELINES', _DIR_CACHE . "charger_pipelines.php");
2327
+    }
2328
+    if (!defined('_CACHE_CHEMIN')) {
2329
+        define('_CACHE_CHEMIN', _DIR_CACHE . "chemin.txt");
2330
+    }
2331
+
2332
+    # attention .php obligatoire pour ecrire_fichier_securise
2333
+    if (!defined('_FILE_META')) {
2334
+        define('_FILE_META', $ti . 'meta_cache.php');
2335
+    }
2336
+    if (!defined('_DIR_LOG')) {
2337
+        define('_DIR_LOG', _DIR_TMP . 'log/');
2338
+    }
2339
+    if (!defined('_FILE_LOG')) {
2340
+        define('_FILE_LOG', 'spip');
2341
+    }
2342
+    if (!defined('_FILE_LOG_SUFFIX')) {
2343
+        define('_FILE_LOG_SUFFIX', '.log');
2344
+    }
2345
+
2346
+    // Le fichier de connexion a la base de donnees
2347
+    // tient compte des anciennes versions (inc_connect...)
2348
+    if (!defined('_FILE_CONNECT_INS')) {
2349
+        define('_FILE_CONNECT_INS', 'connect');
2350
+    }
2351
+    if (!defined('_FILE_CONNECT')) {
2352
+        define('_FILE_CONNECT',
2353
+        (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2354
+            : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2355
+                : false)));
2356
+    }
2357
+
2358
+    // Le fichier de reglages des droits
2359
+    if (!defined('_FILE_CHMOD_INS')) {
2360
+        define('_FILE_CHMOD_INS', 'chmod');
2361
+    }
2362
+    if (!defined('_FILE_CHMOD')) {
2363
+        define('_FILE_CHMOD',
2364
+        (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2365
+            : false));
2366
+    }
2367
+
2368
+    if (!defined('_FILE_LDAP')) {
2369
+        define('_FILE_LDAP', 'ldap.php');
2370
+    }
2371
+
2372
+    if (!defined('_FILE_TMP_SUFFIX')) {
2373
+        define('_FILE_TMP_SUFFIX', '.tmp.php');
2374
+    }
2375
+    if (!defined('_FILE_CONNECT_TMP')) {
2376
+        define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2377
+    }
2378
+    if (!defined('_FILE_CHMOD_TMP')) {
2379
+        define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2380
+    }
2381
+
2382
+    // Definition des droits d'acces en ecriture
2383
+    if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2384
+        include_once _FILE_CHMOD;
2385
+    }
2386
+
2387
+    // Se mefier des fichiers mal remplis!
2388
+    if (!defined('_SPIP_CHMOD')) {
2389
+        define('_SPIP_CHMOD', 0777);
2390
+    }
2391
+
2392
+    if (!defined('_DEFAULT_CHARSET')) {
2393
+        /** Le charset par défaut lors de l'installation */
2394
+        define('_DEFAULT_CHARSET', 'utf-8');
2395
+    }
2396
+    if (!defined('_ROOT_PLUGINS')) {
2397
+        define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
2398
+    }
2399
+    if (!defined('_ROOT_PLUGINS_DIST')) {
2400
+        define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
2401
+    }
2402
+    if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2403
+        define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2404
+    }
2405
+
2406
+    // La taille des Log
2407
+    if (!defined('_MAX_LOG')) {
2408
+        define('_MAX_LOG', 100);
2409
+    }
2410
+
2411
+    // Sommes-nous dans l'empire du Mal ?
2412
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
2413
+    if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2414
+        if (!defined('_OS_SERVEUR')) {
2415
+            define('_OS_SERVEUR', 'windows');
2416
+        }
2417
+        if (!defined('_SPIP_LOCK_MODE')) {
2418
+            define('_SPIP_LOCK_MODE', 1);
2419
+        } // utiliser le flock php
2420
+    } else {
2421
+        if (!defined('_OS_SERVEUR')) {
2422
+            define('_OS_SERVEUR', '');
2423
+        }
2424
+        if (!defined('_SPIP_LOCK_MODE')) {
2425
+            define('_SPIP_LOCK_MODE', 1);
2426
+        } // utiliser le flock php
2427
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2428
+    }
2429
+
2430
+    // Langue par defaut
2431
+    if (!defined('_LANGUE_PAR_DEFAUT')) {
2432
+        define('_LANGUE_PAR_DEFAUT', 'fr');
2433
+    }
2434
+
2435
+    //
2436
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
2437
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
2438
+    // pour le rendre surchargeable, on va provoquer un reecriture
2439
+    // systematique du noyau ou une baisse de perfs => a etudier)
2440
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
2441
+
2442
+    // charger tout de suite le path et son cache
2443
+    load_path_cache();
2444
+
2445
+    // *********** traiter les variables ************
2446
+
2447
+    //
2448
+    // Securite
2449
+    //
2450
+
2451
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2452
+    if (isset($_REQUEST['GLOBALS'])) {
2453
+        die();
2454
+    }
2455
+    // nettoyer les magic quotes \' et les caracteres nuls %00
2456
+    spip_desinfecte($_GET);
2457
+    spip_desinfecte($_POST);
2458
+    spip_desinfecte($_COOKIE);
2459
+    spip_desinfecte($_REQUEST);
2460
+
2461
+    // appliquer le cookie_prefix
2462
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
2463
+        include_spip('inc/cookie');
2464
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2465
+    }
2466
+
2467
+    //
2468
+    // Capacites php (en fonction de la version)
2469
+    //
2470
+    $GLOBALS['flag_ob'] = (function_exists("ob_start")
2471
+        && function_exists("ini_get")
2472
+        && !strstr(@ini_get('disable_functions'), 'ob_'));
2473
+    $GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name");
2474
+    $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != "");
2475
+    $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2476
+        (get_cfg_var('upload_max_filesize') > 0));
2477
+
2478
+
2479
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2480
+    if (isset($_SERVER['REQUEST_URI'])) {
2481
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2482
+    } else {
2483
+        $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2484
+        if (!empty($_SERVER['QUERY_STRING'])
2485
+            and !strpos($_SERVER['REQUEST_URI'], '?')
2486
+        ) {
2487
+            $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2488
+        }
2489
+    }
2490
+
2491
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2492
+    if (!defined('_RENOUVELLE_ALEA')) {
2493
+        define('_RENOUVELLE_ALEA', 12 * 3600);
2494
+    }
2495
+    if (!defined('_DUREE_COOKIE_ADMIN')) {
2496
+        define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2497
+    }
2498
+
2499
+    // charger les meta si possible et renouveller l'alea au besoin
2500
+    // charge aussi effacer_meta et ecrire_meta
2501
+    $inc_meta = charger_fonction('meta', 'inc');
2502
+    $inc_meta();
2503
+
2504
+    // nombre de repertoires depuis la racine
2505
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2506
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2507
+    // le calcul est faux)
2508
+    if (!_DIR_RESTREINT) {
2509
+        $GLOBALS['profondeur_url'] = 1;
2510
+    } else {
2511
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2512
+        $uri_ref = $_SERVER["SCRIPT_NAME"];
2513
+        if (!$uri_ref
2514
+            // si on est appele avec un autre ti, on est sans doute en mutu
2515
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2516
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2517
+            // s'en remettre a l'adresse du site. alea jacta est.
2518
+            or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2519
+        ) {
2520
+
2521
+            if (isset($GLOBALS['meta']['adresse_site'])) {
2522
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2523
+                $uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/';
2524
+            } else {
2525
+                $uri_ref = "";
2526
+            }
2527
+        }
2528
+        if (!$uri or !$uri_ref) {
2529
+            $GLOBALS['profondeur_url'] = 0;
2530
+        } else {
2531
+            $GLOBALS['profondeur_url'] = max(0,
2532
+                substr_count($uri[0], '/')
2533
+                - substr_count($uri_ref, '/'));
2534
+        }
2535
+    }
2536
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2537
+    if (_FILE_CONNECT) {
2538
+        if (verifier_visiteur() == '0minirezo'
2539
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2540
+            and !isset($_COOKIE['spip_admin'])
2541
+        ) {
2542
+            clear_path_cache();
2543
+        }
2544
+    }
2546 2545
 
2547 2546
 }
2548 2547
 
@@ -2552,172 +2551,172 @@  discard block
 block discarded – undo
2552 2551
  *
2553 2552
  */
2554 2553
 function spip_initialisation_suite() {
2555
-	static $too_late = 0;
2556
-	if ($too_late++) {
2557
-		return;
2558
-	}
2559
-
2560
-	// taille mini des login
2561
-	if (!defined('_LOGIN_TROP_COURT')) {
2562
-		define('_LOGIN_TROP_COURT', 4);
2563
-	}
2564
-
2565
-	// la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2566
-	#if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2567
-	#if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2568
-	#if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2569
-
2570
-	// la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2571
-	#if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2572
-	#if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2573
-	#if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2574
-	#if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2575
-
2576
-	if (!defined('_PASS_LONGUEUR_MINI')) {
2577
-		define('_PASS_LONGUEUR_MINI', 6);
2578
-	}
2579
-
2580
-
2581
-	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2582
-	if (!defined('_IMG_QUALITE')) {
2583
-		define('_IMG_QUALITE', 85);
2584
-	} # valeur par defaut
2585
-	if (!defined('_IMG_GD_QUALITE')) {
2586
-		define('_IMG_GD_QUALITE', _IMG_QUALITE);
2587
-	} # surcharge pour la lib GD
2588
-	if (!defined('_IMG_CONVERT_QUALITE')) {
2589
-		define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2590
-	} # surcharge pour imagick en ligne de commande
2591
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2592
-	if (!defined('_IMG_IMAGICK_QUALITE')) {
2593
-		define('_IMG_IMAGICK_QUALITE', 75);
2594
-	} # surcharge pour imagick en PHP
2595
-
2596
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2597
-		define('_COPIE_LOCALE_MAX_SIZE', 33554432);
2598
-	} // poids en octet
2599
-
2600
-	// qq chaines standard
2601
-	if (!defined('_ACCESS_FILE_NAME')) {
2602
-		define('_ACCESS_FILE_NAME', '.htaccess');
2603
-	}
2604
-	if (!defined('_AUTH_USER_FILE')) {
2605
-		define('_AUTH_USER_FILE', '.htpasswd');
2606
-	}
2607
-	if (!defined('_SPIP_DUMP')) {
2608
-		define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2609
-	}
2610
-	if (!defined('_CACHE_RUBRIQUES')) {
2611
-		/** Fichier cache pour le navigateur de rubrique du bandeau */
2612
-		define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2613
-	}
2614
-	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2615
-		/** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2616
-		define('_CACHE_RUBRIQUES_MAX', 500);
2617
-	}
2618
-
2619
-	if (!defined('_EXTENSION_SQUELETTES')) {
2620
-		define('_EXTENSION_SQUELETTES', 'html');
2621
-	}
2622
-
2623
-	if (!defined('_DOCTYPE_ECRIRE')) {
2624
-		/** Définit le doctype de l’espace privé */
2625
-		define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2626
-	}
2627
-	if (!defined('_DOCTYPE_AIDE')) {
2628
-		/** Définit le doctype de l’aide en ligne */
2629
-		define('_DOCTYPE_AIDE',
2630
-		"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
2631
-	}
2632
-
2633
-	if (!defined('_SPIP_SCRIPT')) {
2634
-		/** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2635
-		 * le script de l'espace public, alias index.php */
2636
-		define('_SPIP_SCRIPT', 'spip.php');
2637
-	}
2638
-	if (!defined('_SPIP_PAGE')) {
2639
-		/** Argument page, personalisable en cas de conflit avec un autre script */
2640
-		define('_SPIP_PAGE', 'page');
2641
-	}
2642
-
2643
-	// le script de l'espace prive
2644
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2645
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2646
-	// meme pb sur thttpd cf. http://forum.spip.net/fr_184153.html
2647
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2648
-		define('_SPIP_ECRIRE_SCRIPT', (empty($_SERVER['SERVER_SOFTWARE']) ? '' :
2649
-			preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE']) ?
2650
-				'index.php' : ''));
2651
-	}
2652
-
2653
-
2654
-	if (!defined('_SPIP_AJAX')) {
2655
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2656
-			? 1
2657
-			: (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2658
-	}
2659
-
2660
-	// La requete est-elle en ajax ?
2661
-	if (!defined('_AJAX')) {
2662
-		define('_AJAX',
2663
-			(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2664
-				or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2665
-				or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2666
-				or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2667
-			)
2668
-			and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient
2669
-		);
2670
-	}
2671
-
2672
-	# nombre de pixels maxi pour calcul de la vignette avec gd
2673
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2674
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2675
-	if (!defined('_IMG_GD_MAX_PIXELS')) {
2676
-		define('_IMG_GD_MAX_PIXELS',
2677
-		(isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2678
-			? $GLOBALS['meta']['max_taille_vignettes']
2679
-			: 0);
2680
-	}
2681
-
2682
-	if (!defined('_MEMORY_LIMIT_MIN')) {
2683
-		define('_MEMORY_LIMIT_MIN', 16);
2684
-	} // en Mo
2685
-	// si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2686
-	// on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2687
-	// il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2688
-	if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2689
-		if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2690
-			$unit = strtolower(substr($memory, -1));
2691
-			$memory = substr($memory, 0, -1);
2692
-			switch ($unit) {
2693
-				// Le modifieur 'G' est disponible depuis PHP 5.1.0
2694
-				case 'g':
2695
-					$memory *= 1024;
2696
-				case 'm':
2697
-					$memory *= 1024;
2698
-				case 'k':
2699
-					$memory *= 1024;
2700
-			}
2701
-			if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2702
-				@ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2703
-				if (trim(ini_get('memory_limit')) != $m) {
2704
-					if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2705
-						define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2706
-					} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2707
-				}
2708
-			}
2709
-		} else {
2710
-			if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2711
-				define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2712
-			}
2713
-		} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2714
-	}
2715
-	// Protocoles a normaliser dans les chaines de langues
2716
-	if (!defined('_PROTOCOLES_STD')) {
2717
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2718
-	}
2719
-
2720
-	init_var_mode();
2554
+    static $too_late = 0;
2555
+    if ($too_late++) {
2556
+        return;
2557
+    }
2558
+
2559
+    // taille mini des login
2560
+    if (!defined('_LOGIN_TROP_COURT')) {
2561
+        define('_LOGIN_TROP_COURT', 4);
2562
+    }
2563
+
2564
+    // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2565
+    #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2566
+    #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2567
+    #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2568
+
2569
+    // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2570
+    #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2571
+    #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2572
+    #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2573
+    #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2574
+
2575
+    if (!defined('_PASS_LONGUEUR_MINI')) {
2576
+        define('_PASS_LONGUEUR_MINI', 6);
2577
+    }
2578
+
2579
+
2580
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2581
+    if (!defined('_IMG_QUALITE')) {
2582
+        define('_IMG_QUALITE', 85);
2583
+    } # valeur par defaut
2584
+    if (!defined('_IMG_GD_QUALITE')) {
2585
+        define('_IMG_GD_QUALITE', _IMG_QUALITE);
2586
+    } # surcharge pour la lib GD
2587
+    if (!defined('_IMG_CONVERT_QUALITE')) {
2588
+        define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2589
+    } # surcharge pour imagick en ligne de commande
2590
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2591
+    if (!defined('_IMG_IMAGICK_QUALITE')) {
2592
+        define('_IMG_IMAGICK_QUALITE', 75);
2593
+    } # surcharge pour imagick en PHP
2594
+
2595
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2596
+        define('_COPIE_LOCALE_MAX_SIZE', 33554432);
2597
+    } // poids en octet
2598
+
2599
+    // qq chaines standard
2600
+    if (!defined('_ACCESS_FILE_NAME')) {
2601
+        define('_ACCESS_FILE_NAME', '.htaccess');
2602
+    }
2603
+    if (!defined('_AUTH_USER_FILE')) {
2604
+        define('_AUTH_USER_FILE', '.htpasswd');
2605
+    }
2606
+    if (!defined('_SPIP_DUMP')) {
2607
+        define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2608
+    }
2609
+    if (!defined('_CACHE_RUBRIQUES')) {
2610
+        /** Fichier cache pour le navigateur de rubrique du bandeau */
2611
+        define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2612
+    }
2613
+    if (!defined('_CACHE_RUBRIQUES_MAX')) {
2614
+        /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2615
+        define('_CACHE_RUBRIQUES_MAX', 500);
2616
+    }
2617
+
2618
+    if (!defined('_EXTENSION_SQUELETTES')) {
2619
+        define('_EXTENSION_SQUELETTES', 'html');
2620
+    }
2621
+
2622
+    if (!defined('_DOCTYPE_ECRIRE')) {
2623
+        /** Définit le doctype de l’espace privé */
2624
+        define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2625
+    }
2626
+    if (!defined('_DOCTYPE_AIDE')) {
2627
+        /** Définit le doctype de l’aide en ligne */
2628
+        define('_DOCTYPE_AIDE',
2629
+        "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
2630
+    }
2631
+
2632
+    if (!defined('_SPIP_SCRIPT')) {
2633
+        /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2634
+         * le script de l'espace public, alias index.php */
2635
+        define('_SPIP_SCRIPT', 'spip.php');
2636
+    }
2637
+    if (!defined('_SPIP_PAGE')) {
2638
+        /** Argument page, personalisable en cas de conflit avec un autre script */
2639
+        define('_SPIP_PAGE', 'page');
2640
+    }
2641
+
2642
+    // le script de l'espace prive
2643
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2644
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2645
+    // meme pb sur thttpd cf. http://forum.spip.net/fr_184153.html
2646
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2647
+        define('_SPIP_ECRIRE_SCRIPT', (empty($_SERVER['SERVER_SOFTWARE']) ? '' :
2648
+            preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE']) ?
2649
+                'index.php' : ''));
2650
+    }
2651
+
2652
+
2653
+    if (!defined('_SPIP_AJAX')) {
2654
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2655
+            ? 1
2656
+            : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2657
+    }
2658
+
2659
+    // La requete est-elle en ajax ?
2660
+    if (!defined('_AJAX')) {
2661
+        define('_AJAX',
2662
+            (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2663
+                or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2664
+                or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2665
+                or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2666
+            )
2667
+            and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient
2668
+        );
2669
+    }
2670
+
2671
+    # nombre de pixels maxi pour calcul de la vignette avec gd
2672
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2673
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2674
+    if (!defined('_IMG_GD_MAX_PIXELS')) {
2675
+        define('_IMG_GD_MAX_PIXELS',
2676
+        (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2677
+            ? $GLOBALS['meta']['max_taille_vignettes']
2678
+            : 0);
2679
+    }
2680
+
2681
+    if (!defined('_MEMORY_LIMIT_MIN')) {
2682
+        define('_MEMORY_LIMIT_MIN', 16);
2683
+    } // en Mo
2684
+    // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2685
+    // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2686
+    // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2687
+    if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2688
+        if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2689
+            $unit = strtolower(substr($memory, -1));
2690
+            $memory = substr($memory, 0, -1);
2691
+            switch ($unit) {
2692
+                // Le modifieur 'G' est disponible depuis PHP 5.1.0
2693
+                case 'g':
2694
+                    $memory *= 1024;
2695
+                case 'm':
2696
+                    $memory *= 1024;
2697
+                case 'k':
2698
+                    $memory *= 1024;
2699
+            }
2700
+            if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2701
+                @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2702
+                if (trim(ini_get('memory_limit')) != $m) {
2703
+                    if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2704
+                        define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2705
+                    } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2706
+                }
2707
+            }
2708
+        } else {
2709
+            if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2710
+                define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2711
+            }
2712
+        } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2713
+    }
2714
+    // Protocoles a normaliser dans les chaines de langues
2715
+    if (!defined('_PROTOCOLES_STD')) {
2716
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2717
+    }
2718
+
2719
+    init_var_mode();
2721 2720
 }
2722 2721
 
2723 2722
 /**
@@ -2751,129 +2750,129 @@  discard block
 block discarded – undo
2751 2750
  * `   var_mode` (calcul ou recalcul).
2752 2751
  */
2753 2752
 function init_var_mode() {
2754
-	static $done = false;
2755
-	if (!$done) {
2756
-
2757
-		if (isset($_GET['var_mode'])) {
2758
-			$var_mode = explode(',', $_GET['var_mode']);
2759
-			// tout le monde peut calcul/recalcul
2760
-			if (!defined('_VAR_MODE')) {
2761
-				if (in_array('recalcul', $var_mode)) {
2762
-					define('_VAR_MODE', 'recalcul');
2763
-				} elseif (in_array('calcul', $var_mode)) {
2764
-					define('_VAR_MODE', 'calcul');
2765
-				}
2766
-			}
2767
-			$var_mode = array_diff($var_mode, array('calcul', 'recalcul'));
2768
-			if ($var_mode) {
2769
-				include_spip('inc/autoriser');
2770
-				// autoriser preview si preview seulement, et sinon autoriser debug
2771
-				if (autoriser(
2772
-					($_GET['var_mode'] == 'preview')
2773
-						? 'previsualiser'
2774
-						: 'debug'
2775
-				)) {
2776
-					if (in_array('traduction', $var_mode)) {
2777
-						// forcer le calcul pour passer dans traduire
2778
-						if (!defined('_VAR_MODE')) {
2779
-							define('_VAR_MODE', 'calcul');
2780
-						}
2781
-						// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
2782
-						if (!defined('_VAR_NOCACHE')) {
2783
-							define('_VAR_NOCACHE', true);
2784
-						}
2785
-						$var_mode = array_diff($var_mode, array('traduction'));
2786
-					}
2787
-					if (in_array('preview', $var_mode)) {
2788
-						// basculer sur les criteres de preview dans les boucles
2789
-						if (!defined('_VAR_PREVIEW')) {
2790
-							define('_VAR_PREVIEW', true);
2791
-						}
2792
-						// forcer le calcul
2793
-						if (!defined('_VAR_MODE')) {
2794
-							define('_VAR_MODE', 'calcul');
2795
-						}
2796
-						// et ne pas enregistrer de cache
2797
-						if (!defined('_VAR_NOCACHE')) {
2798
-							define('_VAR_NOCACHE', true);
2799
-						}
2800
-						$var_mode = array_diff($var_mode, array('preview'));
2801
-					}
2802
-					if (in_array('inclure', $var_mode)) {
2803
-						// forcer le compilo et ignorer les caches existants
2804
-						if (!defined('_VAR_MODE')) {
2805
-							define('_VAR_MODE', 'calcul');
2806
-						}
2807
-						if (!defined('_VAR_INCLURE')) {
2808
-							define('_VAR_INCLURE', true);
2809
-						}
2810
-						// et ne pas enregistrer de cache
2811
-						if (!defined('_VAR_NOCACHE')) {
2812
-							define('_VAR_NOCACHE', true);
2813
-						}
2814
-						$var_mode = array_diff($var_mode, array('inclure'));
2815
-					}
2816
-					if (in_array('urls', $var_mode)) {
2817
-						// forcer le compilo et ignorer les caches existants
2818
-						if (!defined('_VAR_MODE')) {
2819
-							define('_VAR_MODE', 'calcul');
2820
-						}
2821
-						if (!defined('_VAR_URLS')) {
2822
-							define('_VAR_URLS', true);
2823
-						}
2824
-						$var_mode = array_diff($var_mode, array('urls'));
2825
-					}
2826
-					if (in_array('images', $var_mode)) {
2827
-						// forcer le compilo et ignorer les caches existants
2828
-						if (!defined('_VAR_MODE')) {
2829
-							define('_VAR_MODE', 'calcul');
2830
-						}
2831
-						// indiquer qu'on doit recalculer les images
2832
-						if (!defined('_VAR_IMAGES')) {
2833
-							define('_VAR_IMAGES', true);
2834
-						}
2835
-						$var_mode = array_diff($var_mode, array('images'));
2836
-					}
2837
-					if (in_array('debug', $var_mode)) {
2838
-						if (!defined('_VAR_MODE')) {
2839
-							define('_VAR_MODE', 'debug');
2840
-						}
2841
-						// et ne pas enregistrer de cache
2842
-						if (!defined('_VAR_NOCACHE')) {
2843
-							define('_VAR_NOCACHE', true);
2844
-						}
2845
-						$var_mode = array_diff($var_mode, array('debug'));
2846
-					}
2847
-					if (count($var_mode) and !defined('_VAR_MODE')) {
2848
-						define('_VAR_MODE', reset($var_mode));
2849
-					}
2850
-					if (isset($GLOBALS['visiteur_session']['nom'])) {
2851
-						spip_log($GLOBALS['visiteur_session']['nom']
2852
-							. " " . _VAR_MODE);
2853
-					}
2854
-				} // pas autorise ?
2855
-				else {
2856
-					// si on n'est pas connecte on se redirige
2857
-					if (!$GLOBALS['visiteur_session']) {
2858
-						include_spip('inc/headers');
2859
-						redirige_par_entete(generer_url_public('login',
2860
-							'url=' . rawurlencode(
2861
-								parametre_url(self(), 'var_mode', $_GET['var_mode'], '&')
2862
-							), true));
2863
-					}
2864
-					// sinon tant pis
2865
-				}
2866
-			}
2867
-		}
2868
-		if (!defined('_VAR_MODE')) {
2869
-			/**
2870
-			 * Indique le mode de calcul ou d'affichage de la page.
2871
-			 * @see init_var_mode()
2872
-			 */
2873
-			define('_VAR_MODE', false);
2874
-		}
2875
-		$done = true;
2876
-	}
2753
+    static $done = false;
2754
+    if (!$done) {
2755
+
2756
+        if (isset($_GET['var_mode'])) {
2757
+            $var_mode = explode(',', $_GET['var_mode']);
2758
+            // tout le monde peut calcul/recalcul
2759
+            if (!defined('_VAR_MODE')) {
2760
+                if (in_array('recalcul', $var_mode)) {
2761
+                    define('_VAR_MODE', 'recalcul');
2762
+                } elseif (in_array('calcul', $var_mode)) {
2763
+                    define('_VAR_MODE', 'calcul');
2764
+                }
2765
+            }
2766
+            $var_mode = array_diff($var_mode, array('calcul', 'recalcul'));
2767
+            if ($var_mode) {
2768
+                include_spip('inc/autoriser');
2769
+                // autoriser preview si preview seulement, et sinon autoriser debug
2770
+                if (autoriser(
2771
+                    ($_GET['var_mode'] == 'preview')
2772
+                        ? 'previsualiser'
2773
+                        : 'debug'
2774
+                )) {
2775
+                    if (in_array('traduction', $var_mode)) {
2776
+                        // forcer le calcul pour passer dans traduire
2777
+                        if (!defined('_VAR_MODE')) {
2778
+                            define('_VAR_MODE', 'calcul');
2779
+                        }
2780
+                        // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
2781
+                        if (!defined('_VAR_NOCACHE')) {
2782
+                            define('_VAR_NOCACHE', true);
2783
+                        }
2784
+                        $var_mode = array_diff($var_mode, array('traduction'));
2785
+                    }
2786
+                    if (in_array('preview', $var_mode)) {
2787
+                        // basculer sur les criteres de preview dans les boucles
2788
+                        if (!defined('_VAR_PREVIEW')) {
2789
+                            define('_VAR_PREVIEW', true);
2790
+                        }
2791
+                        // forcer le calcul
2792
+                        if (!defined('_VAR_MODE')) {
2793
+                            define('_VAR_MODE', 'calcul');
2794
+                        }
2795
+                        // et ne pas enregistrer de cache
2796
+                        if (!defined('_VAR_NOCACHE')) {
2797
+                            define('_VAR_NOCACHE', true);
2798
+                        }
2799
+                        $var_mode = array_diff($var_mode, array('preview'));
2800
+                    }
2801
+                    if (in_array('inclure', $var_mode)) {
2802
+                        // forcer le compilo et ignorer les caches existants
2803
+                        if (!defined('_VAR_MODE')) {
2804
+                            define('_VAR_MODE', 'calcul');
2805
+                        }
2806
+                        if (!defined('_VAR_INCLURE')) {
2807
+                            define('_VAR_INCLURE', true);
2808
+                        }
2809
+                        // et ne pas enregistrer de cache
2810
+                        if (!defined('_VAR_NOCACHE')) {
2811
+                            define('_VAR_NOCACHE', true);
2812
+                        }
2813
+                        $var_mode = array_diff($var_mode, array('inclure'));
2814
+                    }
2815
+                    if (in_array('urls', $var_mode)) {
2816
+                        // forcer le compilo et ignorer les caches existants
2817
+                        if (!defined('_VAR_MODE')) {
2818
+                            define('_VAR_MODE', 'calcul');
2819
+                        }
2820
+                        if (!defined('_VAR_URLS')) {
2821
+                            define('_VAR_URLS', true);
2822
+                        }
2823
+                        $var_mode = array_diff($var_mode, array('urls'));
2824
+                    }
2825
+                    if (in_array('images', $var_mode)) {
2826
+                        // forcer le compilo et ignorer les caches existants
2827
+                        if (!defined('_VAR_MODE')) {
2828
+                            define('_VAR_MODE', 'calcul');
2829
+                        }
2830
+                        // indiquer qu'on doit recalculer les images
2831
+                        if (!defined('_VAR_IMAGES')) {
2832
+                            define('_VAR_IMAGES', true);
2833
+                        }
2834
+                        $var_mode = array_diff($var_mode, array('images'));
2835
+                    }
2836
+                    if (in_array('debug', $var_mode)) {
2837
+                        if (!defined('_VAR_MODE')) {
2838
+                            define('_VAR_MODE', 'debug');
2839
+                        }
2840
+                        // et ne pas enregistrer de cache
2841
+                        if (!defined('_VAR_NOCACHE')) {
2842
+                            define('_VAR_NOCACHE', true);
2843
+                        }
2844
+                        $var_mode = array_diff($var_mode, array('debug'));
2845
+                    }
2846
+                    if (count($var_mode) and !defined('_VAR_MODE')) {
2847
+                        define('_VAR_MODE', reset($var_mode));
2848
+                    }
2849
+                    if (isset($GLOBALS['visiteur_session']['nom'])) {
2850
+                        spip_log($GLOBALS['visiteur_session']['nom']
2851
+                            . " " . _VAR_MODE);
2852
+                    }
2853
+                } // pas autorise ?
2854
+                else {
2855
+                    // si on n'est pas connecte on se redirige
2856
+                    if (!$GLOBALS['visiteur_session']) {
2857
+                        include_spip('inc/headers');
2858
+                        redirige_par_entete(generer_url_public('login',
2859
+                            'url=' . rawurlencode(
2860
+                                parametre_url(self(), 'var_mode', $_GET['var_mode'], '&')
2861
+                            ), true));
2862
+                    }
2863
+                    // sinon tant pis
2864
+                }
2865
+            }
2866
+        }
2867
+        if (!defined('_VAR_MODE')) {
2868
+            /**
2869
+             * Indique le mode de calcul ou d'affichage de la page.
2870
+             * @see init_var_mode()
2871
+             */
2872
+            define('_VAR_MODE', false);
2873
+        }
2874
+        $done = true;
2875
+    }
2877 2876
 }
2878 2877
 
2879 2878
 // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ;
@@ -2881,93 +2880,93 @@  discard block
 block discarded – undo
2881 2880
 // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal')
2882 2881
 // http://code.spip.net/@spip_desinfecte
2883 2882
 function spip_desinfecte(&$t, $deep = true) {
2884
-	static $magic_quotes;
2885
-	if (!isset($magic_quotes)) {
2886
-		$magic_quotes = @get_magic_quotes_gpc();
2887
-	}
2888
-
2889
-	foreach ($t as $key => $val) {
2890
-		if (is_string($t[$key])) {
2891
-			if ($magic_quotes) {
2892
-				$t[$key] = stripslashes($t[$key]);
2893
-			}
2894
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
2895
-		} // traiter aussi les "texte_plus" de article_edit
2896
-		else {
2897
-			if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
2898
-				spip_desinfecte($t[$key], $deep);
2899
-			}
2900
-		}
2901
-	}
2883
+    static $magic_quotes;
2884
+    if (!isset($magic_quotes)) {
2885
+        $magic_quotes = @get_magic_quotes_gpc();
2886
+    }
2887
+
2888
+    foreach ($t as $key => $val) {
2889
+        if (is_string($t[$key])) {
2890
+            if ($magic_quotes) {
2891
+                $t[$key] = stripslashes($t[$key]);
2892
+            }
2893
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
2894
+        } // traiter aussi les "texte_plus" de article_edit
2895
+        else {
2896
+            if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
2897
+                spip_desinfecte($t[$key], $deep);
2898
+            }
2899
+        }
2900
+    }
2902 2901
 }
2903 2902
 
2904 2903
 //  retourne le statut du visiteur s'il s'annonce
2905 2904
 
2906 2905
 // http://code.spip.net/@verifier_visiteur
2907 2906
 function verifier_visiteur() {
2908
-	// Rq: pour que cette fonction marche depuis mes_options
2909
-	// il faut forcer l'init si ce n'est fait
2910
-	// mais on risque de perturber des plugins en initialisant trop tot
2911
-	// certaines constantes
2912
-	@spip_initialisation_core(
2913
-		(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
2914
-		(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
2915
-		(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
2916
-		(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
2917
-	);
2918
-
2919
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
2920
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
2921
-	// Attention on separe bien session_nom et nom, pour eviter
2922
-	// les melanges entre donnees SQL et variables plus aleatoires
2923
-	$variables_session = array('session_nom', 'session_email');
2924
-	foreach ($variables_session as $var) {
2925
-		if (_request($var) !== null) {
2926
-			$init = true;
2927
-			break;
2928
-		}
2929
-	}
2930
-	if (isset($init)) {
2931
-		#@spip_initialisation_suite();
2932
-		$session = charger_fonction('session', 'inc');
2933
-		$session();
2934
-		include_spip('inc/texte');
2935
-		foreach ($variables_session as $var) {
2936
-			if (($a = _request($var)) !== null) {
2937
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
2938
-			}
2939
-		}
2940
-		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
2941
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
2942
-		}
2943
-		$session($GLOBALS['visiteur_session']);
2944
-
2945
-		return 0;
2946
-	}
2947
-
2948
-	$h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
2949
-	if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
2950
-
2951
-		$session = charger_fonction('session', 'inc');
2952
-		if ($session()) {
2953
-			return $GLOBALS['visiteur_session']['statut'];
2954
-		}
2955
-		if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
2956
-			include_spip('inc/auth');
2957
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
2958
-		}
2959
-		if ($h) {
2960
-			$GLOBALS['visiteur_session'] = $h;
2961
-
2962
-			return $GLOBALS['visiteur_session']['statut'];
2963
-		}
2964
-	}
2965
-
2966
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
2967
-	include_spip('inc/lang');
2968
-	utiliser_langue_visiteur();
2969
-
2970
-	return false;
2907
+    // Rq: pour que cette fonction marche depuis mes_options
2908
+    // il faut forcer l'init si ce n'est fait
2909
+    // mais on risque de perturber des plugins en initialisant trop tot
2910
+    // certaines constantes
2911
+    @spip_initialisation_core(
2912
+        (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
2913
+        (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
2914
+        (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
2915
+        (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
2916
+    );
2917
+
2918
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
2919
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
2920
+    // Attention on separe bien session_nom et nom, pour eviter
2921
+    // les melanges entre donnees SQL et variables plus aleatoires
2922
+    $variables_session = array('session_nom', 'session_email');
2923
+    foreach ($variables_session as $var) {
2924
+        if (_request($var) !== null) {
2925
+            $init = true;
2926
+            break;
2927
+        }
2928
+    }
2929
+    if (isset($init)) {
2930
+        #@spip_initialisation_suite();
2931
+        $session = charger_fonction('session', 'inc');
2932
+        $session();
2933
+        include_spip('inc/texte');
2934
+        foreach ($variables_session as $var) {
2935
+            if (($a = _request($var)) !== null) {
2936
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
2937
+            }
2938
+        }
2939
+        if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
2940
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
2941
+        }
2942
+        $session($GLOBALS['visiteur_session']);
2943
+
2944
+        return 0;
2945
+    }
2946
+
2947
+    $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
2948
+    if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
2949
+
2950
+        $session = charger_fonction('session', 'inc');
2951
+        if ($session()) {
2952
+            return $GLOBALS['visiteur_session']['statut'];
2953
+        }
2954
+        if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
2955
+            include_spip('inc/auth');
2956
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
2957
+        }
2958
+        if ($h) {
2959
+            $GLOBALS['visiteur_session'] = $h;
2960
+
2961
+            return $GLOBALS['visiteur_session']['statut'];
2962
+        }
2963
+    }
2964
+
2965
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
2966
+    include_spip('inc/lang');
2967
+    utiliser_langue_visiteur();
2968
+
2969
+    return false;
2971 2970
 }
2972 2971
 
2973 2972
 
@@ -2990,21 +2989,21 @@  discard block
 block discarded – undo
2990 2989
  *     - string Langue utilisée.
2991 2990
  **/
2992 2991
 function lang_select($lang = null) {
2993
-	static $pile_langues = array();
2994
-	if (!function_exists('changer_langue')) {
2995
-		include_spip('inc/lang');
2996
-	}
2997
-	if ($lang === null) {
2998
-		$lang = array_pop($pile_langues);
2999
-	} else {
3000
-		array_push($pile_langues, $GLOBALS['spip_lang']);
3001
-	}
3002
-	if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3003
-		return $lang;
3004
-	}
3005
-	changer_langue($lang);
2992
+    static $pile_langues = array();
2993
+    if (!function_exists('changer_langue')) {
2994
+        include_spip('inc/lang');
2995
+    }
2996
+    if ($lang === null) {
2997
+        $lang = array_pop($pile_langues);
2998
+    } else {
2999
+        array_push($pile_langues, $GLOBALS['spip_lang']);
3000
+    }
3001
+    if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3002
+        return $lang;
3003
+    }
3004
+    changer_langue($lang);
3006 3005
 
3007
-	return $lang;
3006
+    return $lang;
3008 3007
 }
3009 3008
 
3010 3009
 /**
@@ -3021,19 +3020,19 @@  discard block
 block discarded – undo
3021 3020
  *     Identifiant de la session
3022 3021
  **/
3023 3022
 function spip_session($force = false) {
3024
-	static $session;
3025
-	if ($force or !isset($session)) {
3026
-		$s = pipeline('definir_session',
3027
-			$GLOBALS['visiteur_session']
3028
-				? serialize($GLOBALS['visiteur_session'])
3029
-				. '_' . @$_COOKIE['spip_session']
3030
-				: ''
3031
-		);
3032
-		$session = $s ? substr(md5($s), 0, 8) : '';
3033
-	}
3023
+    static $session;
3024
+    if ($force or !isset($session)) {
3025
+        $s = pipeline('definir_session',
3026
+            $GLOBALS['visiteur_session']
3027
+                ? serialize($GLOBALS['visiteur_session'])
3028
+                . '_' . @$_COOKIE['spip_session']
3029
+                : ''
3030
+        );
3031
+        $session = $s ? substr(md5($s), 0, 8) : '';
3032
+    }
3034 3033
 
3035
-	#spip_log('session: '.$session);
3036
-	return $session;
3034
+    #spip_log('session: '.$session);
3035
+    return $session;
3037 3036
 }
3038 3037
 
3039 3038
 
@@ -3052,9 +3051,9 @@  discard block
 block discarded – undo
3052 3051
  *    Lien sur une icone d'aide
3053 3052
  **/
3054 3053
 function aider($aide = '', $distante = false) {
3055
-	$aider = charger_fonction('aide', 'inc', true);
3054
+    $aider = charger_fonction('aide', 'inc', true);
3056 3055
 
3057
-	return $aider ? $aider($aide, '', array(), $distante) : '';
3056
+    return $aider ? $aider($aide, '', array(), $distante) : '';
3058 3057
 }
3059 3058
 
3060 3059
 /**
@@ -3064,13 +3063,13 @@  discard block
 block discarded – undo
3064 3063
  */
3065 3064
 function exec_info_dist() {
3066 3065
 
3067
-	include_spip('inc/autoriser');
3068
-	if (autoriser('webmestre')) {
3069
-		phpinfo();
3070
-	} else {
3071
-		include_spip('inc/filtres');
3072
-		sinon_interdire_acces();
3073
-	}
3066
+    include_spip('inc/autoriser');
3067
+    if (autoriser('webmestre')) {
3068
+        phpinfo();
3069
+    } else {
3070
+        include_spip('inc/filtres');
3071
+        sinon_interdire_acces();
3072
+    }
3074 3073
 }
3075 3074
 
3076 3075
 /**
@@ -3090,13 +3089,13 @@  discard block
 block discarded – undo
3090 3089
  *     - string si $message à false.
3091 3090
  **/
3092 3091
 function erreur_squelette($message = '', $lieu = '') {
3093
-	$debusquer = charger_fonction('debusquer', 'public');
3094
-	if (is_array($lieu)) {
3095
-		include_spip('public/compiler');
3096
-		$lieu = reconstruire_contexte_compil($lieu);
3097
-	}
3092
+    $debusquer = charger_fonction('debusquer', 'public');
3093
+    if (is_array($lieu)) {
3094
+        include_spip('public/compiler');
3095
+        $lieu = reconstruire_contexte_compil($lieu);
3096
+    }
3098 3097
 
3099
-	return $debusquer($message, $lieu);
3098
+    return $debusquer($message, $lieu);
3100 3099
 }
3101 3100
 
3102 3101
 /**
@@ -3133,92 +3132,92 @@  discard block
 block discarded – undo
3133 3132
  *     - ou tableau d'information sur le squelette.
3134 3133
  */
3135 3134
 function recuperer_fond($fond, $contexte = array(), $options = array(), $connect = '') {
3136
-	if (!function_exists('evaluer_fond')) {
3137
-		include_spip('public/assembler');
3138
-	}
3139
-	// assurer la compat avec l'ancienne syntaxe
3140
-	// (trim etait le 3eme argument, par defaut a true)
3141
-	if (!is_array($options)) {
3142
-		$options = array('trim' => $options);
3143
-	}
3144
-	if (!isset($options['trim'])) {
3145
-		$options['trim'] = true;
3146
-	}
3147
-
3148
-	if (isset($contexte['connect'])) {
3149
-		$connect = $contexte['connect'];
3150
-		unset($contexte['connect']);
3151
-	}
3152
-
3153
-	$texte = "";
3154
-	$pages = array();
3155
-	$lang_select = '';
3156
-	if (!isset($options['etoile']) or !$options['etoile']) {
3157
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
3158
-		if (!isset($contexte['lang'])) {
3159
-			$contexte['lang'] = $GLOBALS['spip_lang'];
3160
-		}
3161
-
3162
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3163
-			$lang_select = lang_select($contexte['lang']);
3164
-		}
3165
-	}
3166
-
3167
-	if (!isset($GLOBALS['_INC_PUBLIC'])) {
3168
-		$GLOBALS['_INC_PUBLIC'] = 0;
3169
-	}
3170
-
3171
-	$GLOBALS['_INC_PUBLIC']++;
3172
-
3173
-
3174
-	foreach (is_array($fond) ? $fond : array($fond) as $f) {
3175
-		$page = evaluer_fond($f, $contexte, $connect);
3176
-		if ($page === '') {
3177
-			$c = isset($options['compil']) ? $options['compil'] : '';
3178
-			$a = array('fichier' => $fond);
3179
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3180
-			erreur_squelette($erreur, $c);
3181
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3182
-			$page = array('texte' => '', 'erreur' => $erreur);
3183
-		}
3184
-
3185
-		$page = pipeline('recuperer_fond', array(
3186
-			'args' => array('fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect),
3187
-			'data' => $page
3188
-		));
3189
-		if (isset($options['ajax']) and $options['ajax']) {
3190
-			if (!function_exists('encoder_contexte_ajax')) {
3191
-				include_spip('inc/filtres');
3192
-			}
3193
-			$page['texte'] = encoder_contexte_ajax(
3194
-				array_merge(
3195
-					$contexte,
3196
-					array('fond' => $f),
3197
-					($connect ? array('connect' => $connect) : array())
3198
-				),
3199
-				'',
3200
-				$page['texte'],
3201
-				$options['ajax']
3202
-			);
3203
-		}
3204
-
3205
-		if (isset($options['raw']) and $options['raw']) {
3206
-			$pages[] = $page;
3207
-		} else {
3208
-			$texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
3209
-		}
3210
-	}
3211
-
3212
-	$GLOBALS['_INC_PUBLIC']--;
3213
-
3214
-	if ($lang_select) {
3215
-		lang_select();
3216
-	}
3217
-	if (isset($options['raw']) and $options['raw']) {
3218
-		return is_array($fond) ? $pages : reset($pages);
3219
-	} else {
3220
-		return $options['trim'] ? ltrim($texte) : $texte;
3221
-	}
3135
+    if (!function_exists('evaluer_fond')) {
3136
+        include_spip('public/assembler');
3137
+    }
3138
+    // assurer la compat avec l'ancienne syntaxe
3139
+    // (trim etait le 3eme argument, par defaut a true)
3140
+    if (!is_array($options)) {
3141
+        $options = array('trim' => $options);
3142
+    }
3143
+    if (!isset($options['trim'])) {
3144
+        $options['trim'] = true;
3145
+    }
3146
+
3147
+    if (isset($contexte['connect'])) {
3148
+        $connect = $contexte['connect'];
3149
+        unset($contexte['connect']);
3150
+    }
3151
+
3152
+    $texte = "";
3153
+    $pages = array();
3154
+    $lang_select = '';
3155
+    if (!isset($options['etoile']) or !$options['etoile']) {
3156
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
3157
+        if (!isset($contexte['lang'])) {
3158
+            $contexte['lang'] = $GLOBALS['spip_lang'];
3159
+        }
3160
+
3161
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3162
+            $lang_select = lang_select($contexte['lang']);
3163
+        }
3164
+    }
3165
+
3166
+    if (!isset($GLOBALS['_INC_PUBLIC'])) {
3167
+        $GLOBALS['_INC_PUBLIC'] = 0;
3168
+    }
3169
+
3170
+    $GLOBALS['_INC_PUBLIC']++;
3171
+
3172
+
3173
+    foreach (is_array($fond) ? $fond : array($fond) as $f) {
3174
+        $page = evaluer_fond($f, $contexte, $connect);
3175
+        if ($page === '') {
3176
+            $c = isset($options['compil']) ? $options['compil'] : '';
3177
+            $a = array('fichier' => $fond);
3178
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3179
+            erreur_squelette($erreur, $c);
3180
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3181
+            $page = array('texte' => '', 'erreur' => $erreur);
3182
+        }
3183
+
3184
+        $page = pipeline('recuperer_fond', array(
3185
+            'args' => array('fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect),
3186
+            'data' => $page
3187
+        ));
3188
+        if (isset($options['ajax']) and $options['ajax']) {
3189
+            if (!function_exists('encoder_contexte_ajax')) {
3190
+                include_spip('inc/filtres');
3191
+            }
3192
+            $page['texte'] = encoder_contexte_ajax(
3193
+                array_merge(
3194
+                    $contexte,
3195
+                    array('fond' => $f),
3196
+                    ($connect ? array('connect' => $connect) : array())
3197
+                ),
3198
+                '',
3199
+                $page['texte'],
3200
+                $options['ajax']
3201
+            );
3202
+        }
3203
+
3204
+        if (isset($options['raw']) and $options['raw']) {
3205
+            $pages[] = $page;
3206
+        } else {
3207
+            $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
3208
+        }
3209
+    }
3210
+
3211
+    $GLOBALS['_INC_PUBLIC']--;
3212
+
3213
+    if ($lang_select) {
3214
+        lang_select();
3215
+    }
3216
+    if (isset($options['raw']) and $options['raw']) {
3217
+        return is_array($fond) ? $pages : reset($pages);
3218
+    } else {
3219
+        return $options['trim'] ? ltrim($texte) : $texte;
3220
+    }
3222 3221
 }
3223 3222
 
3224 3223
 /**
@@ -3228,7 +3227,7 @@  discard block
 block discarded – undo
3228 3227
  * @return string
3229 3228
  */
3230 3229
 function trouve_modele($nom) {
3231
-	return trouver_fond($nom, 'modeles/');
3230
+    return trouver_fond($nom, 'modeles/');
3232 3231
 }
3233 3232
 
3234 3233
 /**
@@ -3244,21 +3243,21 @@  discard block
 block discarded – undo
3244 3243
  * @return array|string
3245 3244
  */
3246 3245
 function trouver_fond($nom, $dir = '', $pathinfo = false) {
3247
-	$f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3248
-	if (!$pathinfo) {
3249
-		return $f;
3250
-	}
3251
-	// renvoyer un tableau detaille si $pathinfo==true
3252
-	$p = pathinfo($f);
3253
-	if (!isset($p['extension']) or !$p['extension']) {
3254
-		$p['extension'] = _EXTENSION_SQUELETTES;
3255
-	}
3256
-	if (!isset($p['extension']) or !$p['filename']) {
3257
-		$p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3258
-	}
3259
-	$p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3246
+    $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3247
+    if (!$pathinfo) {
3248
+        return $f;
3249
+    }
3250
+    // renvoyer un tableau detaille si $pathinfo==true
3251
+    $p = pathinfo($f);
3252
+    if (!isset($p['extension']) or !$p['extension']) {
3253
+        $p['extension'] = _EXTENSION_SQUELETTES;
3254
+    }
3255
+    if (!isset($p['extension']) or !$p['filename']) {
3256
+        $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3257
+    }
3258
+    $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3260 3259
 
3261
-	return $p;
3260
+    return $p;
3262 3261
 }
3263 3262
 
3264 3263
 /**
@@ -3279,24 +3278,24 @@  discard block
 block discarded – undo
3279 3278
  *     Nom de l'exec, sinon chaîne vide.
3280 3279
  **/
3281 3280
 function tester_url_ecrire($nom) {
3282
-	static $exec = array();
3283
-	if (isset($exec[$nom])) {
3284
-		return $exec[$nom];
3285
-	}
3286
-	// tester si c'est une page en squelette
3287
-	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3288
-		return $exec[$nom] = 'fond';
3289
-	} // compat skels orthogonaux version precedente
3290
-	elseif (trouver_fond($nom, 'prive/exec/')) {
3291
-		return $exec[$nom] = 'fond_monobloc';
3292
-	} // echafaudage d'un fond !
3293
-	elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3294
-		return $exec[$nom] = 'fond';
3295
-	}
3296
-	// attention, il ne faut pas inclure l'exec ici
3297
-	// car sinon #URL_ECRIRE provoque des inclusions
3298
-	// et des define intrusifs potentiels
3299
-	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3281
+    static $exec = array();
3282
+    if (isset($exec[$nom])) {
3283
+        return $exec[$nom];
3284
+    }
3285
+    // tester si c'est une page en squelette
3286
+    if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3287
+        return $exec[$nom] = 'fond';
3288
+    } // compat skels orthogonaux version precedente
3289
+    elseif (trouver_fond($nom, 'prive/exec/')) {
3290
+        return $exec[$nom] = 'fond_monobloc';
3291
+    } // echafaudage d'un fond !
3292
+    elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3293
+        return $exec[$nom] = 'fond';
3294
+    }
3295
+    // attention, il ne faut pas inclure l'exec ici
3296
+    // car sinon #URL_ECRIRE provoque des inclusions
3297
+    // et des define intrusifs potentiels
3298
+    return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3300 3299
 }
3301 3300
 
3302 3301
 
@@ -3312,10 +3311,10 @@  discard block
 block discarded – undo
3312 3311
  * @return bool true si le module est chargé
3313 3312
  **/
3314 3313
 function charger_php_extension($module) {
3315
-	if (extension_loaded($module)) {
3316
-		return true;
3317
-	}
3318
-	return false;
3314
+    if (extension_loaded($module)) {
3315
+        return true;
3316
+    }
3317
+    return false;
3319 3318
 }
3320 3319
 
3321 3320
 
@@ -3326,8 +3325,8 @@  discard block
 block discarded – undo
3326 3325
  *     true si et seulement si la configuration autorise le code HTML5 sur le site public
3327 3326
  **/
3328 3327
 function html5_permis() {
3329
-	return (isset($GLOBALS['meta']['version_html_max'])
3330
-		and ('html5' == $GLOBALS['meta']['version_html_max']));
3328
+    return (isset($GLOBALS['meta']['version_html_max'])
3329
+        and ('html5' == $GLOBALS['meta']['version_html_max']));
3331 3330
 }
3332 3331
 
3333 3332
 /*
@@ -3345,7 +3344,7 @@  discard block
 block discarded – undo
3345 3344
  * @return mixed Valeur de la meta.
3346 3345
  **/
3347 3346
 function lire_meta($nom) {
3348
-	return isset($GLOBALS['meta'][$nom]) ? $GLOBALS['meta'][$nom] : null;
3347
+    return isset($GLOBALS['meta'][$nom]) ? $GLOBALS['meta'][$nom] : null;
3349 3348
 }
3350 3349
 
3351 3350
 
@@ -3367,128 +3366,128 @@  discard block
 block discarded – undo
3367 3366
  * @param string $statut
3368 3367
  */
3369 3368
 function avertir_auteurs($nom, $message, $statut = '') {
3370
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3371
-	if (!$alertes
3372
-		or !is_array($alertes = unserialize($alertes))
3373
-	) {
3374
-		$alertes = array();
3375
-	}
3369
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3370
+    if (!$alertes
3371
+        or !is_array($alertes = unserialize($alertes))
3372
+    ) {
3373
+        $alertes = array();
3374
+    }
3376 3375
 
3377
-	if (!isset($alertes[$statut])) {
3378
-		$alertes[$statut] = array();
3379
-	}
3380
-	$alertes[$statut][$nom] = $message;
3381
-	ecrire_meta("message_alertes_auteurs", serialize($alertes));
3376
+    if (!isset($alertes[$statut])) {
3377
+        $alertes[$statut] = array();
3378
+    }
3379
+    $alertes[$statut][$nom] = $message;
3380
+    ecrire_meta("message_alertes_auteurs", serialize($alertes));
3382 3381
 }
3383 3382
 
3384 3383
 if (PHP_VERSION_ID < 50500) {
3385
-	if (!function_exists('array_column')) {
3386
-		/**
3387
-		 * Returns the values from a single column of the input array, identified by
3388
-		 * the $columnKey.
3389
-		 *
3390
-		 * Optionally, you may provide an $indexKey to index the values in the returned
3391
-		 * array by the values from the $indexKey column in the input array.
3392
-		 *
3393
-		 * @link http://php.net/manual/fr/function.array-column.php
3394
-		 * @link https://github.com/ramsey/array_column/blob/master/src/array_column.php
3395
-		 * @copyright Copyright (c) Ben Ramsey (http://benramsey.com)
3396
-		 * @license http://opensource.org/licenses/MIT MIT
3397
-		 *
3398
-		 * @param array $input A multi-dimensional array (record set) from which to pull
3399
-		 *                     a column of values.
3400
-		 * @param mixed $columnKey The column of values to return. This value may be the
3401
-		 *                         integer key of the column you wish to retrieve, or it
3402
-		 *                         may be the string key name for an associative array.
3403
-		 * @param mixed $indexKey (Optional.) The column to use as the index/keys for
3404
-		 *                        the returned array. This value may be the integer key
3405
-		 *                        of the column, or it may be the string key name.
3406
-		 * @return array
3407
-		 */
3408
-		function array_column($input = null, $columnKey = null, $indexKey = null)
3409
-		{
3410
-			// Using func_get_args() in order to check for proper number of
3411
-			// parameters and trigger errors exactly as the built-in array_column()
3412
-			// does in PHP 5.5.
3413
-			$argc = func_num_args();
3414
-			$params = func_get_args();
3415
-
3416
-			if ($argc < 2) {
3417
-				trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING);
3418
-				return null;
3419
-			}
3420
-
3421
-			if (!is_array($params[0])) {
3422
-				trigger_error(
3423
-					'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given',
3424
-					E_USER_WARNING
3425
-				);
3426
-				return null;
3427
-			}
3428
-
3429
-			if (!is_int($params[1])
3430
-				&& !is_float($params[1])
3431
-				&& !is_string($params[1])
3432
-				&& $params[1] !== null
3433
-				&& !(is_object($params[1]) && method_exists($params[1], '__toString'))
3434
-			) {
3435
-				trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
3436
-				return false;
3437
-			}
3438
-
3439
-			if (isset($params[2])
3440
-				&& !is_int($params[2])
3441
-				&& !is_float($params[2])
3442
-				&& !is_string($params[2])
3443
-				&& !(is_object($params[2]) && method_exists($params[2], '__toString'))
3444
-			) {
3445
-				trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
3446
-				return false;
3447
-			}
3448
-
3449
-			$paramsInput = $params[0];
3450
-			$paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null;
3451
-
3452
-			$paramsIndexKey = null;
3453
-			if (isset($params[2])) {
3454
-				if (is_float($params[2]) || is_int($params[2])) {
3455
-					$paramsIndexKey = (int) $params[2];
3456
-				} else {
3457
-					$paramsIndexKey = (string) $params[2];
3458
-				}
3459
-			}
3460
-
3461
-			$resultArray = array();
3462
-
3463
-			foreach ($paramsInput as $row) {
3464
-				$key = $value = null;
3465
-				$keySet = $valueSet = false;
3466
-
3467
-				if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) {
3468
-					$keySet = true;
3469
-					$key = (string) $row[$paramsIndexKey];
3470
-				}
3471
-
3472
-				if ($paramsColumnKey === null) {
3473
-					$valueSet = true;
3474
-					$value = $row;
3475
-				} elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) {
3476
-					$valueSet = true;
3477
-					$value = $row[$paramsColumnKey];
3478
-				}
3479
-
3480
-				if ($valueSet) {
3481
-					if ($keySet) {
3482
-						$resultArray[$key] = $value;
3483
-					} else {
3484
-						$resultArray[] = $value;
3485
-					}
3486
-				}
3487
-
3488
-			}
3489
-
3490
-			return $resultArray;
3491
-		}
3492
-
3493
-	}
3384
+    if (!function_exists('array_column')) {
3385
+        /**
3386
+         * Returns the values from a single column of the input array, identified by
3387
+         * the $columnKey.
3388
+         *
3389
+         * Optionally, you may provide an $indexKey to index the values in the returned
3390
+         * array by the values from the $indexKey column in the input array.
3391
+         *
3392
+         * @link http://php.net/manual/fr/function.array-column.php
3393
+         * @link https://github.com/ramsey/array_column/blob/master/src/array_column.php
3394
+         * @copyright Copyright (c) Ben Ramsey (http://benramsey.com)
3395
+         * @license http://opensource.org/licenses/MIT MIT
3396
+         *
3397
+         * @param array $input A multi-dimensional array (record set) from which to pull
3398
+         *                     a column of values.
3399
+         * @param mixed $columnKey The column of values to return. This value may be the
3400
+         *                         integer key of the column you wish to retrieve, or it
3401
+         *                         may be the string key name for an associative array.
3402
+         * @param mixed $indexKey (Optional.) The column to use as the index/keys for
3403
+         *                        the returned array. This value may be the integer key
3404
+         *                        of the column, or it may be the string key name.
3405
+         * @return array
3406
+         */
3407
+        function array_column($input = null, $columnKey = null, $indexKey = null)
3408
+        {
3409
+            // Using func_get_args() in order to check for proper number of
3410
+            // parameters and trigger errors exactly as the built-in array_column()
3411
+            // does in PHP 5.5.
3412
+            $argc = func_num_args();
3413
+            $params = func_get_args();
3414
+
3415
+            if ($argc < 2) {
3416
+                trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING);
3417
+                return null;
3418
+            }
3419
+
3420
+            if (!is_array($params[0])) {
3421
+                trigger_error(
3422
+                    'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given',
3423
+                    E_USER_WARNING
3424
+                );
3425
+                return null;
3426
+            }
3427
+
3428
+            if (!is_int($params[1])
3429
+                && !is_float($params[1])
3430
+                && !is_string($params[1])
3431
+                && $params[1] !== null
3432
+                && !(is_object($params[1]) && method_exists($params[1], '__toString'))
3433
+            ) {
3434
+                trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
3435
+                return false;
3436
+            }
3437
+
3438
+            if (isset($params[2])
3439
+                && !is_int($params[2])
3440
+                && !is_float($params[2])
3441
+                && !is_string($params[2])
3442
+                && !(is_object($params[2]) && method_exists($params[2], '__toString'))
3443
+            ) {
3444
+                trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
3445
+                return false;
3446
+            }
3447
+
3448
+            $paramsInput = $params[0];
3449
+            $paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null;
3450
+
3451
+            $paramsIndexKey = null;
3452
+            if (isset($params[2])) {
3453
+                if (is_float($params[2]) || is_int($params[2])) {
3454
+                    $paramsIndexKey = (int) $params[2];
3455
+                } else {
3456
+                    $paramsIndexKey = (string) $params[2];
3457
+                }
3458
+            }
3459
+
3460
+            $resultArray = array();
3461
+
3462
+            foreach ($paramsInput as $row) {
3463
+                $key = $value = null;
3464
+                $keySet = $valueSet = false;
3465
+
3466
+                if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) {
3467
+                    $keySet = true;
3468
+                    $key = (string) $row[$paramsIndexKey];
3469
+                }
3470
+
3471
+                if ($paramsColumnKey === null) {
3472
+                    $valueSet = true;
3473
+                    $value = $row;
3474
+                } elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) {
3475
+                    $valueSet = true;
3476
+                    $value = $row[$paramsColumnKey];
3477
+                }
3478
+
3479
+                if ($valueSet) {
3480
+                    if ($keySet) {
3481
+                        $resultArray[$key] = $value;
3482
+                    } else {
3483
+                        $resultArray[] = $value;
3484
+                    }
3485
+                }
3486
+
3487
+            }
3488
+
3489
+            return $resultArray;
3490
+        }
3491
+
3492
+    }
3494 3493
 }
3495 3494
\ No newline at end of file
Please login to merge, or discard this patch.
ecrire/public/assembler.php 1 patch
Indentation   +532 added lines, -532 removed lines patch added patch discarded remove patch
@@ -20,154 +20,154 @@  discard block
 block discarded – undo
20 20
  **/
21 21
 
22 22
 if (!defined('_ECRIRE_INC_VERSION')) {
23
-	return;
23
+    return;
24 24
 }
25 25
 
26 26
 if (!defined('_CONTEXTE_IGNORE_VARIABLES')) {
27
-	define('_CONTEXTE_IGNORE_VARIABLES', "/(^var_|^PHPSESSID$|^fbclid$|^utm_)/");
27
+    define('_CONTEXTE_IGNORE_VARIABLES', "/(^var_|^PHPSESSID$|^fbclid$|^utm_)/");
28 28
 }
29 29
 
30 30
 // http://code.spip.net/@assembler
31 31
 function assembler($fond, $connect = '') {
32 32
 
33
-	// flag_preserver est modifie ici, et utilise en globale
34
-	// use_cache sert a informer le bouton d'admin pr savoir s'il met un *
35
-	// contexte est utilise en globale dans le formulaire d'admin
36
-
37
-	$GLOBALS['contexte'] = calculer_contexte();
38
-	$page = array('contexte_implicite' => calculer_contexte_implicite());
39
-	$page['contexte_implicite']['cache'] = $fond . preg_replace(',\.[a-zA-Z0-9]*$,', '',
40
-			preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']));
41
-	// Cette fonction est utilisee deux fois
42
-	$cacher = charger_fonction('cacher', 'public', true);
43
-	// Les quatre derniers parametres sont modifies par la fonction:
44
-	// emplacement, validite, et, s'il est valide, contenu & age
45
-	if ($cacher) {
46
-		$res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified);
47
-	} else {
48
-		$GLOBALS['use_cache'] = -1;
49
-	}
50
-	// Si un resultat est retourne, c'est un message d'impossibilite
51
-	if ($res) {
52
-		return array('texte' => $res);
53
-	}
54
-
55
-	if (!$chemin_cache || !$lastmodified) {
56
-		$lastmodified = time();
57
-	}
58
-
59
-	$headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD');
60
-	$calculer_page = true;
61
-
62
-	// Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client})
63
-	// une perennite valide a meme reponse qu'une requete HEAD (par defaut les
64
-	// pages sont dynamiques)
65
-	if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])
66
-		and (!defined('_VAR_MODE') or !_VAR_MODE)
67
-		and $chemin_cache
68
-		and isset($page['entetes'])
69
-		and isset($page['entetes']['Cache-Control'])
70
-		and strstr($page['entetes']['Cache-Control'], 'max-age=')
71
-		and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/')
72
-	) {
73
-		$since = preg_replace('/;.*/', '',
74
-			$_SERVER['HTTP_IF_MODIFIED_SINCE']);
75
-		$since = str_replace('GMT', '', $since);
76
-		if (trim($since) == gmdate("D, d M Y H:i:s", $lastmodified)) {
77
-			$page['status'] = 304;
78
-			$headers_only = true;
79
-			$calculer_page = false;
80
-		}
81
-	}
82
-
83
-	// Si requete HEAD ou Last-modified compatible, ignorer le texte
84
-	// et pas de content-type (pour contrer le bouton admin de inc-public)
85
-	if (!$calculer_page) {
86
-		$page['texte'] = "";
87
-	} else {
88
-		// si la page est prise dans le cache
89
-		if (!$GLOBALS['use_cache']) {
90
-			// Informer les boutons d'admin du contexte
91
-			// (fourni par urls_decoder_url ci-dessous lors de la mise en cache)
92
-			$GLOBALS['contexte'] = $page['contexte'];
93
-
94
-			// vider les globales url propres qui ne doivent plus etre utilisees en cas
95
-			// d'inversion url => objet
96
-			// plus necessaire si on utilise bien la fonction urls_decoder_url
97
-			#unset($_SERVER['REDIRECT_url_propre']);
98
-			#unset($_ENV['url_propre']);
99
-		} else {
100
-			// Compat ascendante :
101
-			// 1. $contexte est global
102
-			// (a evacuer car urls_decoder_url gere ce probleme ?)
103
-			// et calculer la page
104
-			if (!test_espace_prive()) {
105
-				include_spip('inc/urls');
106
-				list($fond, $GLOBALS['contexte'], $url_redirect) = urls_decoder_url(nettoyer_uri(), $fond, $GLOBALS['contexte'],
107
-					true);
108
-			}
109
-			// squelette par defaut
110
-			if (!strlen($fond)) {
111
-				$fond = 'sommaire';
112
-			}
113
-
114
-			// produire la page : peut mettre a jour $lastmodified
115
-			$produire_page = charger_fonction('produire_page', 'public');
116
-			$page = $produire_page($fond, $GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, null, $page,
117
-				$lastmodified, $connect);
118
-			if ($page === '') {
119
-				$erreur = _T('info_erreur_squelette2',
120
-					array('fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES));
121
-				erreur_squelette($erreur);
122
-				// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
123
-				$page = array('texte' => '', 'erreur' => $erreur);
124
-			}
125
-		}
126
-
127
-		if ($page and $chemin_cache) {
128
-			$page['cache'] = $chemin_cache;
129
-		}
130
-
131
-		auto_content_type($page);
132
-
133
-		$GLOBALS['flag_preserver'] |= headers_sent();
134
-
135
-		// Definir les entetes si ce n'est fait 
136
-		if (!$GLOBALS['flag_preserver']) {
137
-			if ($GLOBALS['flag_ob']) {
138
-				// Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions
139
-				if (trim($page['texte']) === ''
140
-					and _VAR_MODE != 'debug'
141
-					and !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur
142
-				) {
143
-					$GLOBALS['contexte']['fond_erreur'] = $fond;
144
-					$page = message_page_indisponible($page, $GLOBALS['contexte']);
145
-				}
146
-				// pas de cache client en mode 'observation'
147
-				if (defined('_VAR_MODE') and _VAR_MODE) {
148
-					$page['entetes']["Cache-Control"] = "no-cache,must-revalidate";
149
-					$page['entetes']["Pragma"] = "no-cache";
150
-				}
151
-			}
152
-		}
153
-	}
154
-
155
-	// Entete Last-Modified:
156
-	// eviter d'etre incoherent en envoyant un lastmodified identique
157
-	// a celui qu'on a refuse d'honorer plus haut (cf. #655)
158
-	if ($lastmodified
159
-		and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])
160
-		and !isset($page['entetes']["Last-Modified"])
161
-	) {
162
-		$page['entetes']["Last-Modified"] = gmdate("D, d M Y H:i:s", $lastmodified) . " GMT";
163
-	}
164
-
165
-	// fermer la connexion apres les headers si requete HEAD
166
-	if ($headers_only) {
167
-		$page['entetes']["Connection"] = "close";
168
-	}
169
-
170
-	return $page;
33
+    // flag_preserver est modifie ici, et utilise en globale
34
+    // use_cache sert a informer le bouton d'admin pr savoir s'il met un *
35
+    // contexte est utilise en globale dans le formulaire d'admin
36
+
37
+    $GLOBALS['contexte'] = calculer_contexte();
38
+    $page = array('contexte_implicite' => calculer_contexte_implicite());
39
+    $page['contexte_implicite']['cache'] = $fond . preg_replace(',\.[a-zA-Z0-9]*$,', '',
40
+            preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']));
41
+    // Cette fonction est utilisee deux fois
42
+    $cacher = charger_fonction('cacher', 'public', true);
43
+    // Les quatre derniers parametres sont modifies par la fonction:
44
+    // emplacement, validite, et, s'il est valide, contenu & age
45
+    if ($cacher) {
46
+        $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified);
47
+    } else {
48
+        $GLOBALS['use_cache'] = -1;
49
+    }
50
+    // Si un resultat est retourne, c'est un message d'impossibilite
51
+    if ($res) {
52
+        return array('texte' => $res);
53
+    }
54
+
55
+    if (!$chemin_cache || !$lastmodified) {
56
+        $lastmodified = time();
57
+    }
58
+
59
+    $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD');
60
+    $calculer_page = true;
61
+
62
+    // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client})
63
+    // une perennite valide a meme reponse qu'une requete HEAD (par defaut les
64
+    // pages sont dynamiques)
65
+    if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])
66
+        and (!defined('_VAR_MODE') or !_VAR_MODE)
67
+        and $chemin_cache
68
+        and isset($page['entetes'])
69
+        and isset($page['entetes']['Cache-Control'])
70
+        and strstr($page['entetes']['Cache-Control'], 'max-age=')
71
+        and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/')
72
+    ) {
73
+        $since = preg_replace('/;.*/', '',
74
+            $_SERVER['HTTP_IF_MODIFIED_SINCE']);
75
+        $since = str_replace('GMT', '', $since);
76
+        if (trim($since) == gmdate("D, d M Y H:i:s", $lastmodified)) {
77
+            $page['status'] = 304;
78
+            $headers_only = true;
79
+            $calculer_page = false;
80
+        }
81
+    }
82
+
83
+    // Si requete HEAD ou Last-modified compatible, ignorer le texte
84
+    // et pas de content-type (pour contrer le bouton admin de inc-public)
85
+    if (!$calculer_page) {
86
+        $page['texte'] = "";
87
+    } else {
88
+        // si la page est prise dans le cache
89
+        if (!$GLOBALS['use_cache']) {
90
+            // Informer les boutons d'admin du contexte
91
+            // (fourni par urls_decoder_url ci-dessous lors de la mise en cache)
92
+            $GLOBALS['contexte'] = $page['contexte'];
93
+
94
+            // vider les globales url propres qui ne doivent plus etre utilisees en cas
95
+            // d'inversion url => objet
96
+            // plus necessaire si on utilise bien la fonction urls_decoder_url
97
+            #unset($_SERVER['REDIRECT_url_propre']);
98
+            #unset($_ENV['url_propre']);
99
+        } else {
100
+            // Compat ascendante :
101
+            // 1. $contexte est global
102
+            // (a evacuer car urls_decoder_url gere ce probleme ?)
103
+            // et calculer la page
104
+            if (!test_espace_prive()) {
105
+                include_spip('inc/urls');
106
+                list($fond, $GLOBALS['contexte'], $url_redirect) = urls_decoder_url(nettoyer_uri(), $fond, $GLOBALS['contexte'],
107
+                    true);
108
+            }
109
+            // squelette par defaut
110
+            if (!strlen($fond)) {
111
+                $fond = 'sommaire';
112
+            }
113
+
114
+            // produire la page : peut mettre a jour $lastmodified
115
+            $produire_page = charger_fonction('produire_page', 'public');
116
+            $page = $produire_page($fond, $GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, null, $page,
117
+                $lastmodified, $connect);
118
+            if ($page === '') {
119
+                $erreur = _T('info_erreur_squelette2',
120
+                    array('fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES));
121
+                erreur_squelette($erreur);
122
+                // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
123
+                $page = array('texte' => '', 'erreur' => $erreur);
124
+            }
125
+        }
126
+
127
+        if ($page and $chemin_cache) {
128
+            $page['cache'] = $chemin_cache;
129
+        }
130
+
131
+        auto_content_type($page);
132
+
133
+        $GLOBALS['flag_preserver'] |= headers_sent();
134
+
135
+        // Definir les entetes si ce n'est fait 
136
+        if (!$GLOBALS['flag_preserver']) {
137
+            if ($GLOBALS['flag_ob']) {
138
+                // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions
139
+                if (trim($page['texte']) === ''
140
+                    and _VAR_MODE != 'debug'
141
+                    and !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur
142
+                ) {
143
+                    $GLOBALS['contexte']['fond_erreur'] = $fond;
144
+                    $page = message_page_indisponible($page, $GLOBALS['contexte']);
145
+                }
146
+                // pas de cache client en mode 'observation'
147
+                if (defined('_VAR_MODE') and _VAR_MODE) {
148
+                    $page['entetes']["Cache-Control"] = "no-cache,must-revalidate";
149
+                    $page['entetes']["Pragma"] = "no-cache";
150
+                }
151
+            }
152
+        }
153
+    }
154
+
155
+    // Entete Last-Modified:
156
+    // eviter d'etre incoherent en envoyant un lastmodified identique
157
+    // a celui qu'on a refuse d'honorer plus haut (cf. #655)
158
+    if ($lastmodified
159
+        and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])
160
+        and !isset($page['entetes']["Last-Modified"])
161
+    ) {
162
+        $page['entetes']["Last-Modified"] = gmdate("D, d M Y H:i:s", $lastmodified) . " GMT";
163
+    }
164
+
165
+    // fermer la connexion apres les headers si requete HEAD
166
+    if ($headers_only) {
167
+        $page['entetes']["Connection"] = "close";
168
+    }
169
+
170
+    return $page;
171 171
 }
172 172
 
173 173
 /**
@@ -186,19 +186,19 @@  discard block
 block discarded – undo
186 186
  */
187 187
 function calculer_contexte() {
188 188
 
189
-	$contexte = array();
190
-	foreach ($_GET as $var => $val) {
191
-		if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) {
192
-			$contexte[$var] = $val;
193
-		}
194
-	}
195
-	foreach ($_POST as $var => $val) {
196
-		if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) {
197
-			$contexte[$var] = $val;
198
-		}
199
-	}
200
-
201
-	return $contexte;
189
+    $contexte = array();
190
+    foreach ($_GET as $var => $val) {
191
+        if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) {
192
+            $contexte[$var] = $val;
193
+        }
194
+    }
195
+    foreach ($_POST as $var => $val) {
196
+        if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) {
197
+            $contexte[$var] = $val;
198
+        }
199
+    }
200
+
201
+    return $contexte;
202 202
 }
203 203
 
204 204
 /**
@@ -209,25 +209,25 @@  discard block
 block discarded – undo
209 209
  * @return array
210 210
  */
211 211
 function calculer_contexte_implicite() {
212
-	static $notes = null;
213
-	if (is_null($notes)) {
214
-		$notes = charger_fonction('notes', 'inc', true);
215
-	}
216
-	$contexte_implicite = array(
217
-		'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ?
218
-		'host' => (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null),
219
-		'https' => (isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : ''),
220
-		'espace' => test_espace_prive(),
221
-		'marqueur' => (isset($GLOBALS['marqueur']) ? $GLOBALS['marqueur'] : ''),
222
-		'marqueur_skel' => (isset($GLOBALS['marqueur_skel']) ? $GLOBALS['marqueur_skel'] : ''),
223
-		'notes' => $notes ? $notes('', 'contexter_cache') : '',
224
-		'spip_version_code' => $GLOBALS['spip_version_code'],
225
-	);
226
-	if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
227
-		$contexte_implicite['host'] .= "|" . $_SERVER['HTTP_X_FORWARDED_HOST'];
228
-	}
229
-
230
-	return $contexte_implicite;
212
+    static $notes = null;
213
+    if (is_null($notes)) {
214
+        $notes = charger_fonction('notes', 'inc', true);
215
+    }
216
+    $contexte_implicite = array(
217
+        'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ?
218
+        'host' => (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null),
219
+        'https' => (isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : ''),
220
+        'espace' => test_espace_prive(),
221
+        'marqueur' => (isset($GLOBALS['marqueur']) ? $GLOBALS['marqueur'] : ''),
222
+        'marqueur_skel' => (isset($GLOBALS['marqueur_skel']) ? $GLOBALS['marqueur_skel'] : ''),
223
+        'notes' => $notes ? $notes('', 'contexter_cache') : '',
224
+        'spip_version_code' => $GLOBALS['spip_version_code'],
225
+    );
226
+    if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
227
+        $contexte_implicite['host'] .= "|" . $_SERVER['HTTP_X_FORWARDED_HOST'];
228
+    }
229
+
230
+    return $contexte_implicite;
231 231
 }
232 232
 
233 233
 //
@@ -237,50 +237,50 @@  discard block
 block discarded – undo
237 237
 // http://code.spip.net/@auto_content_type
238 238
 function auto_content_type($page) {
239 239
 
240
-	if (!isset($GLOBALS['flag_preserver'])) {
241
-		$GLOBALS['flag_preserver'] = ($page && preg_match("/header\s*\(\s*.content\-type:/isx",
242
-				$page['texte']) || (isset($page['entetes']['Content-Type'])));
243
-	}
240
+    if (!isset($GLOBALS['flag_preserver'])) {
241
+        $GLOBALS['flag_preserver'] = ($page && preg_match("/header\s*\(\s*.content\-type:/isx",
242
+                $page['texte']) || (isset($page['entetes']['Content-Type'])));
243
+    }
244 244
 }
245 245
 
246 246
 // http://code.spip.net/@inclure_page
247 247
 function inclure_page($fond, $contexte, $connect = '') {
248
-	static $cacher, $produire_page;
249
-
250
-	// enlever le fond de contexte inclus car sinon il prend la main
251
-	// dans les sous inclusions -> boucle infinie d'inclusion identique
252
-	// (cette precaution n'est probablement plus utile)
253
-	unset($contexte['fond']);
254
-	$page = array('contexte_implicite' => calculer_contexte_implicite());
255
-	$page['contexte_implicite']['cache'] = $fond;
256
-	if (is_null($cacher)) {
257
-		$cacher = charger_fonction('cacher', 'public', true);
258
-	}
259
-	// Les quatre derniers parametres sont modifies par la fonction:
260
-	// emplacement, validite, et, s'il est valide, contenu & age
261
-	if ($cacher) {
262
-		$res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude);
263
-	} else {
264
-		$use_cache = -1;
265
-	}
266
-	// $res = message d'erreur : on sort de la
267
-	if ($res) {
268
-		return array('texte' => $res);
269
-	}
270
-
271
-	// Si use_cache ne vaut pas 0, la page doit etre calculee
272
-	// produire la page : peut mettre a jour $lastinclude
273
-	// le contexte_cache envoye a cacher() a ete conserve et est passe a produire
274
-	if ($use_cache) {
275
-		if (is_null($produire_page)) {
276
-			$produire_page = charger_fonction('produire_page', 'public');
277
-		}
278
-		$page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect);
279
-	}
280
-	// dans tous les cas, mettre a jour $GLOBALS['lastmodified']
281
-	$GLOBALS['lastmodified'] = max((isset($GLOBALS['lastmodified']) ? $GLOBALS['lastmodified'] : 0), $lastinclude);
282
-
283
-	return $page;
248
+    static $cacher, $produire_page;
249
+
250
+    // enlever le fond de contexte inclus car sinon il prend la main
251
+    // dans les sous inclusions -> boucle infinie d'inclusion identique
252
+    // (cette precaution n'est probablement plus utile)
253
+    unset($contexte['fond']);
254
+    $page = array('contexte_implicite' => calculer_contexte_implicite());
255
+    $page['contexte_implicite']['cache'] = $fond;
256
+    if (is_null($cacher)) {
257
+        $cacher = charger_fonction('cacher', 'public', true);
258
+    }
259
+    // Les quatre derniers parametres sont modifies par la fonction:
260
+    // emplacement, validite, et, s'il est valide, contenu & age
261
+    if ($cacher) {
262
+        $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude);
263
+    } else {
264
+        $use_cache = -1;
265
+    }
266
+    // $res = message d'erreur : on sort de la
267
+    if ($res) {
268
+        return array('texte' => $res);
269
+    }
270
+
271
+    // Si use_cache ne vaut pas 0, la page doit etre calculee
272
+    // produire la page : peut mettre a jour $lastinclude
273
+    // le contexte_cache envoye a cacher() a ete conserve et est passe a produire
274
+    if ($use_cache) {
275
+        if (is_null($produire_page)) {
276
+            $produire_page = charger_fonction('produire_page', 'public');
277
+        }
278
+        $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect);
279
+    }
280
+    // dans tous les cas, mettre a jour $GLOBALS['lastmodified']
281
+    $GLOBALS['lastmodified'] = max((isset($GLOBALS['lastmodified']) ? $GLOBALS['lastmodified'] : 0), $lastinclude);
282
+
283
+    return $page;
284 284
 }
285 285
 
286 286
 /**
@@ -298,40 +298,40 @@  discard block
 block discarded – undo
298 298
  * @return array
299 299
  */
300 300
 function public_produire_page_dist(
301
-	$fond,
302
-	$contexte,
303
-	$use_cache,
304
-	$chemin_cache,
305
-	$contexte_cache,
306
-	&$page,
307
-	&$lastinclude,
308
-	$connect = ''
301
+    $fond,
302
+    $contexte,
303
+    $use_cache,
304
+    $chemin_cache,
305
+    $contexte_cache,
306
+    &$page,
307
+    &$lastinclude,
308
+    $connect = ''
309 309
 ) {
310
-	static $parametrer, $cacher;
311
-	if (!$parametrer) {
312
-		$parametrer = charger_fonction('parametrer', 'public');
313
-	}
314
-	$page = $parametrer($fond, $contexte, $chemin_cache, $connect);
315
-	// et on l'enregistre sur le disque
316
-	if ($chemin_cache
317
-		and $use_cache > -1
318
-		and is_array($page)
319
-		and count($page)
320
-		and isset($page['entetes']['X-Spip-Cache'])
321
-		and $page['entetes']['X-Spip-Cache'] > 0
322
-	) {
323
-		if (is_null($cacher)) {
324
-			$cacher = charger_fonction('cacher', 'public', true);
325
-		}
326
-		$lastinclude = time();
327
-		if ($cacher) {
328
-			$cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude);
329
-		} else {
330
-			$use_cache = -1;
331
-		}
332
-	}
333
-
334
-	return $page;
310
+    static $parametrer, $cacher;
311
+    if (!$parametrer) {
312
+        $parametrer = charger_fonction('parametrer', 'public');
313
+    }
314
+    $page = $parametrer($fond, $contexte, $chemin_cache, $connect);
315
+    // et on l'enregistre sur le disque
316
+    if ($chemin_cache
317
+        and $use_cache > -1
318
+        and is_array($page)
319
+        and count($page)
320
+        and isset($page['entetes']['X-Spip-Cache'])
321
+        and $page['entetes']['X-Spip-Cache'] > 0
322
+    ) {
323
+        if (is_null($cacher)) {
324
+            $cacher = charger_fonction('cacher', 'public', true);
325
+        }
326
+        $lastinclude = time();
327
+        if ($cacher) {
328
+            $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude);
329
+        } else {
330
+            $use_cache = -1;
331
+        }
332
+    }
333
+
334
+    return $page;
335 335
 }
336 336
 
337 337
 // Fonction inseree par le compilateur dans le code compile.
@@ -345,12 +345,12 @@  discard block
 block discarded – undo
345 345
 // 4: langue
346 346
 
347 347
 function inserer_balise_dynamique($contexte_exec, $contexte_compil) {
348
-	if (!is_array($contexte_exec)) {
349
-		echo $contexte_exec;
350
-	} // message d'erreur etc
351
-	else {
352
-		inclure_balise_dynamique($contexte_exec, true, $contexte_compil);
353
-	}
348
+    if (!is_array($contexte_exec)) {
349
+        echo $contexte_exec;
350
+    } // message d'erreur etc
351
+    else {
352
+        inclure_balise_dynamique($contexte_exec, true, $contexte_compil);
353
+    }
354 354
 }
355 355
 
356 356
 /**
@@ -365,124 +365,124 @@  discard block
 block discarded – undo
365 365
  * @return string
366 366
  */
367 367
 function inclure_balise_dynamique($texte, $echo = true, $contexte_compil = array()) {
368
-	if (is_array($texte)) {
369
-
370
-		list($fond, $delainc, $contexte_inclus) = $texte;
371
-
372
-		// delais a l'ancienne, c'est pratiquement mort
373
-		$d = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : null;
374
-		$GLOBALS['delais'] = $delainc;
375
-
376
-		$page = recuperer_fond($fond, $contexte_inclus,
377
-			array('trim' => false, 'raw' => true, 'compil' => $contexte_compil));
378
-
379
-		$texte = $page['texte'];
380
-
381
-		$GLOBALS['delais'] = $d;
382
-		// Faire remonter les entetes
383
-		if (is_array($page['entetes'])) {
384
-			// mais pas toutes
385
-			unset($page['entetes']['X-Spip-Cache']);
386
-			unset($page['entetes']['Content-Type']);
387
-			if (isset($GLOBALS['page']) and is_array($GLOBALS['page'])) {
388
-				if (!is_array($GLOBALS['page']['entetes'])) {
389
-					$GLOBALS['page']['entetes'] = array();
390
-				}
391
-				$GLOBALS['page']['entetes'] =
392
-					array_merge($GLOBALS['page']['entetes'], $page['entetes']);
393
-			}
394
-		}
395
-		// _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines
396
-		if (isset($page['contexte']['_pipelines'])
397
-			and is_array($page['contexte']['_pipelines'])
398
-			and count($page['contexte']['_pipelines'])
399
-		) {
400
-			foreach ($page['contexte']['_pipelines'] as $pipe => $args) {
401
-				$args['contexte'] = $page['contexte'];
402
-				unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul
403
-				$texte = pipeline(
404
-					$pipe,
405
-					array(
406
-						'data' => $texte,
407
-						'args' => $args
408
-					),
409
-					false
410
-				);
411
-			}
412
-		}
413
-	}
414
-
415
-	if (defined('_VAR_MODE') and _VAR_MODE == 'debug') {
416
-		// compatibilite : avant on donnait le numero de ligne ou rien.
417
-		$ligne = intval(isset($contexte_compil[3]) ? $contexte_compil[3] : $contexte_compil);
418
-		$GLOBALS['debug_objets']['resultat'][$ligne] = $texte;
419
-	}
420
-	if ($echo) {
421
-		echo $texte;
422
-	} else {
423
-		return $texte;
424
-	}
368
+    if (is_array($texte)) {
369
+
370
+        list($fond, $delainc, $contexte_inclus) = $texte;
371
+
372
+        // delais a l'ancienne, c'est pratiquement mort
373
+        $d = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : null;
374
+        $GLOBALS['delais'] = $delainc;
375
+
376
+        $page = recuperer_fond($fond, $contexte_inclus,
377
+            array('trim' => false, 'raw' => true, 'compil' => $contexte_compil));
378
+
379
+        $texte = $page['texte'];
380
+
381
+        $GLOBALS['delais'] = $d;
382
+        // Faire remonter les entetes
383
+        if (is_array($page['entetes'])) {
384
+            // mais pas toutes
385
+            unset($page['entetes']['X-Spip-Cache']);
386
+            unset($page['entetes']['Content-Type']);
387
+            if (isset($GLOBALS['page']) and is_array($GLOBALS['page'])) {
388
+                if (!is_array($GLOBALS['page']['entetes'])) {
389
+                    $GLOBALS['page']['entetes'] = array();
390
+                }
391
+                $GLOBALS['page']['entetes'] =
392
+                    array_merge($GLOBALS['page']['entetes'], $page['entetes']);
393
+            }
394
+        }
395
+        // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines
396
+        if (isset($page['contexte']['_pipelines'])
397
+            and is_array($page['contexte']['_pipelines'])
398
+            and count($page['contexte']['_pipelines'])
399
+        ) {
400
+            foreach ($page['contexte']['_pipelines'] as $pipe => $args) {
401
+                $args['contexte'] = $page['contexte'];
402
+                unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul
403
+                $texte = pipeline(
404
+                    $pipe,
405
+                    array(
406
+                        'data' => $texte,
407
+                        'args' => $args
408
+                    ),
409
+                    false
410
+                );
411
+            }
412
+        }
413
+    }
414
+
415
+    if (defined('_VAR_MODE') and _VAR_MODE == 'debug') {
416
+        // compatibilite : avant on donnait le numero de ligne ou rien.
417
+        $ligne = intval(isset($contexte_compil[3]) ? $contexte_compil[3] : $contexte_compil);
418
+        $GLOBALS['debug_objets']['resultat'][$ligne] = $texte;
419
+    }
420
+    if ($echo) {
421
+        echo $texte;
422
+    } else {
423
+        return $texte;
424
+    }
425 425
 }
426 426
 
427 427
 // http://code.spip.net/@message_page_indisponible
428 428
 function message_page_indisponible($page, $contexte) {
429
-	static $deja = false;
430
-	if ($deja) {
431
-		return "erreur";
432
-	}
433
-	$codes = array(
434
-		'404' => '404 Not Found',
435
-		'503' => '503 Service Unavailable',
436
-	);
437
-
438
-	$contexte['status'] = ($page !== false) ? '404' : '503';
439
-	$contexte['code'] = $codes[$contexte['status']];
440
-	$contexte['fond'] = '404'; // gere les 2 erreurs
441
-	if (!isset($contexte['lang'])) {
442
-		$contexte['lang'] = $GLOBALS['spip_lang'];
443
-	}
444
-
445
-	$deja = true;
446
-	// passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent
447
-	// ex restriction d'acces => 401
448
-	$contexte = pipeline('page_indisponible', $contexte);
449
-
450
-	// produire la page d'erreur
451
-	$page = inclure_page($contexte['fond'], $contexte);
452
-	if (!$page) {
453
-		$page = inclure_page('404', $contexte);
454
-	}
455
-	$page['status'] = $contexte['status'];
456
-
457
-	return $page;
429
+    static $deja = false;
430
+    if ($deja) {
431
+        return "erreur";
432
+    }
433
+    $codes = array(
434
+        '404' => '404 Not Found',
435
+        '503' => '503 Service Unavailable',
436
+    );
437
+
438
+    $contexte['status'] = ($page !== false) ? '404' : '503';
439
+    $contexte['code'] = $codes[$contexte['status']];
440
+    $contexte['fond'] = '404'; // gere les 2 erreurs
441
+    if (!isset($contexte['lang'])) {
442
+        $contexte['lang'] = $GLOBALS['spip_lang'];
443
+    }
444
+
445
+    $deja = true;
446
+    // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent
447
+    // ex restriction d'acces => 401
448
+    $contexte = pipeline('page_indisponible', $contexte);
449
+
450
+    // produire la page d'erreur
451
+    $page = inclure_page($contexte['fond'], $contexte);
452
+    if (!$page) {
453
+        $page = inclure_page('404', $contexte);
454
+    }
455
+    $page['status'] = $contexte['status'];
456
+
457
+    return $page;
458 458
 }
459 459
 
460 460
 // temporairement ici : a mettre dans le futur inc/modeles
461 461
 // creer_contexte_de_modele('left', 'autostart=true', ...) renvoie un array()
462 462
 // http://code.spip.net/@creer_contexte_de_modele
463 463
 function creer_contexte_de_modele($args) {
464
-	$contexte = array();
465
-	foreach ($args as $var => $val) {
466
-		if (is_int($var)) { // argument pas formate
467
-			if (in_array($val, array('left', 'right', 'center'))) {
468
-				$var = 'align';
469
-				$contexte[$var] = $val;
470
-			} else {
471
-				$args = explode('=', $val);
472
-				if (count($args) >= 2) // Flashvars=arg1=machin&arg2=truc genere plus de deux args
473
-				{
474
-					$contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1);
475
-				} else // notation abregee
476
-				{
477
-					$contexte[trim($val)] = trim($val);
478
-				}
479
-			}
480
-		} else {
481
-			$contexte[$var] = $val;
482
-		}
483
-	}
484
-
485
-	return $contexte;
464
+    $contexte = array();
465
+    foreach ($args as $var => $val) {
466
+        if (is_int($var)) { // argument pas formate
467
+            if (in_array($val, array('left', 'right', 'center'))) {
468
+                $var = 'align';
469
+                $contexte[$var] = $val;
470
+            } else {
471
+                $args = explode('=', $val);
472
+                if (count($args) >= 2) // Flashvars=arg1=machin&arg2=truc genere plus de deux args
473
+                {
474
+                    $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1);
475
+                } else // notation abregee
476
+                {
477
+                    $contexte[trim($val)] = trim($val);
478
+                }
479
+            }
480
+        } else {
481
+            $contexte[$var] = $val;
482
+        }
483
+    }
484
+
485
+    return $contexte;
486 486
 }
487 487
 
488 488
 /**
@@ -501,94 +501,94 @@  discard block
 block discarded – undo
501 501
  */
502 502
 function inclure_modele($type, $id, $params, $lien, $connect = '', $env = array()) {
503 503
 
504
-	static $compteur;
505
-	if (++$compteur > 10) {
506
-		return '';
507
-	} # ne pas boucler indefiniment
508
-
509
-	$type = strtolower($type);
510
-
511
-	$fond = $class = '';
512
-
513
-	$params = array_filter(explode('|', $params));
514
-	if ($params) {
515
-		$soustype = current($params);
516
-		$soustype = strtolower(trim($soustype));
517
-		if (in_array($soustype, array('left', 'right', 'center', 'ajax'))) {
518
-			$soustype = next($params);
519
-			$soustype = strtolower($soustype);
520
-		}
521
-
522
-		if (preg_match(',^[a-z0-9_]+$,', $soustype)) {
523
-			if (!trouve_modele($fond = ($type . '_' . $soustype))) {
524
-				$fond = '';
525
-				$class = $soustype;
526
-			}
527
-			// enlever le sous type des params
528
-			$params = array_diff($params, array($soustype));
529
-		}
530
-	}
531
-
532
-	// Si ca marche pas en precisant le sous-type, prendre le type
533
-	if (!$fond and !trouve_modele($fond = $type)) {
534
-		spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE);
535
-
536
-		return false;
537
-	}
538
-	$fond = 'modeles/' . $fond;
539
-	// Creer le contexte
540
-	$contexte = $env;
541
-	$contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte
542
-
543
-	// Le numero du modele est mis dans l'environnement
544
-	// d'une part sous l'identifiant "id"
545
-	// et d'autre part sous l'identifiant de la cle primaire
546
-	// par la fonction id_table_objet,
547
-	// (<article1> =>> article =>> id_article =>> id_article=1)
548
-	$_id = id_table_objet($type);
549
-	$contexte['id'] = $contexte[$_id] = $id;
550
-
551
-	if (isset($class)) {
552
-		$contexte['class'] = $class;
553
-	}
554
-
555
-	// Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url]
556
-	if ($lien) {
557
-		# un eventuel guillemet (") sera reechappe par #ENV
558
-		$contexte['lien'] = str_replace("&quot;", '"', $lien['href']);
559
-		$contexte['lien_class'] = $lien['class'];
560
-		$contexte['lien_mime'] = $lien['mime'];
561
-		$contexte['lien_title'] = $lien['title'];
562
-		$contexte['lien_hreflang'] = $lien['hreflang'];
563
-	}
564
-
565
-	// Traiter les parametres
566
-	// par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en>
567
-	$arg_list = creer_contexte_de_modele($params);
568
-	$contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args
569
-	$contexte = array_merge($contexte, $arg_list);
570
-
571
-	// Appliquer le modele avec le contexte
572
-	$retour = recuperer_fond($fond, $contexte, array(), $connect);
573
-
574
-	// Regarder si le modele tient compte des liens (il *doit* alors indiquer
575
-	// spip_lien_ok dans les classes de son conteneur de premier niveau ;
576
-	// sinon, s'il y a un lien, on l'ajoute classiquement
577
-	if (strstr(' ' . ($classes = extraire_attribut($retour, 'class')) . ' ',
578
-		'spip_lien_ok')) {
579
-		$retour = inserer_attribut($retour, 'class',
580
-			trim(str_replace(' spip_lien_ok ', ' ', " $classes ")));
581
-	} else {
582
-		if ($lien) {
583
-			$retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . "</a>";
584
-		}
585
-	}
586
-
587
-	$compteur--;
588
-
589
-	return (isset($arg_list['ajax']) and $arg_list['ajax'] == 'ajax')
590
-		? encoder_contexte_ajax($contexte, '', $retour)
591
-		: $retour;
504
+    static $compteur;
505
+    if (++$compteur > 10) {
506
+        return '';
507
+    } # ne pas boucler indefiniment
508
+
509
+    $type = strtolower($type);
510
+
511
+    $fond = $class = '';
512
+
513
+    $params = array_filter(explode('|', $params));
514
+    if ($params) {
515
+        $soustype = current($params);
516
+        $soustype = strtolower(trim($soustype));
517
+        if (in_array($soustype, array('left', 'right', 'center', 'ajax'))) {
518
+            $soustype = next($params);
519
+            $soustype = strtolower($soustype);
520
+        }
521
+
522
+        if (preg_match(',^[a-z0-9_]+$,', $soustype)) {
523
+            if (!trouve_modele($fond = ($type . '_' . $soustype))) {
524
+                $fond = '';
525
+                $class = $soustype;
526
+            }
527
+            // enlever le sous type des params
528
+            $params = array_diff($params, array($soustype));
529
+        }
530
+    }
531
+
532
+    // Si ca marche pas en precisant le sous-type, prendre le type
533
+    if (!$fond and !trouve_modele($fond = $type)) {
534
+        spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE);
535
+
536
+        return false;
537
+    }
538
+    $fond = 'modeles/' . $fond;
539
+    // Creer le contexte
540
+    $contexte = $env;
541
+    $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte
542
+
543
+    // Le numero du modele est mis dans l'environnement
544
+    // d'une part sous l'identifiant "id"
545
+    // et d'autre part sous l'identifiant de la cle primaire
546
+    // par la fonction id_table_objet,
547
+    // (<article1> =>> article =>> id_article =>> id_article=1)
548
+    $_id = id_table_objet($type);
549
+    $contexte['id'] = $contexte[$_id] = $id;
550
+
551
+    if (isset($class)) {
552
+        $contexte['class'] = $class;
553
+    }
554
+
555
+    // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url]
556
+    if ($lien) {
557
+        # un eventuel guillemet (") sera reechappe par #ENV
558
+        $contexte['lien'] = str_replace("&quot;", '"', $lien['href']);
559
+        $contexte['lien_class'] = $lien['class'];
560
+        $contexte['lien_mime'] = $lien['mime'];
561
+        $contexte['lien_title'] = $lien['title'];
562
+        $contexte['lien_hreflang'] = $lien['hreflang'];
563
+    }
564
+
565
+    // Traiter les parametres
566
+    // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en>
567
+    $arg_list = creer_contexte_de_modele($params);
568
+    $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args
569
+    $contexte = array_merge($contexte, $arg_list);
570
+
571
+    // Appliquer le modele avec le contexte
572
+    $retour = recuperer_fond($fond, $contexte, array(), $connect);
573
+
574
+    // Regarder si le modele tient compte des liens (il *doit* alors indiquer
575
+    // spip_lien_ok dans les classes de son conteneur de premier niveau ;
576
+    // sinon, s'il y a un lien, on l'ajoute classiquement
577
+    if (strstr(' ' . ($classes = extraire_attribut($retour, 'class')) . ' ',
578
+        'spip_lien_ok')) {
579
+        $retour = inserer_attribut($retour, 'class',
580
+            trim(str_replace(' spip_lien_ok ', ' ', " $classes ")));
581
+    } else {
582
+        if ($lien) {
583
+            $retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . "</a>";
584
+        }
585
+    }
586
+
587
+    $compteur--;
588
+
589
+    return (isset($arg_list['ajax']) and $arg_list['ajax'] == 'ajax')
590
+        ? encoder_contexte_ajax($contexte, '', $retour)
591
+        : $retour;
592 592
 }
593 593
 
594 594
 // Un inclure_page qui marche aussi pour l'espace prive
@@ -598,92 +598,92 @@  discard block
 block discarded – undo
598 598
 // http://code.spip.net/@evaluer_fond
599 599
 function evaluer_fond($fond, $contexte = array(), $connect = null) {
600 600
 
601
-	$page = inclure_page($fond, $contexte, $connect);
602
-
603
-	if (!$page) {
604
-		return $page;
605
-	}
606
-	// eval $page et affecte $res
607
-	include _ROOT_RESTREINT . "public/evaluer_page.php";
608
-
609
-	// Lever un drapeau (global) si le fond utilise #SESSION
610
-	// a destination de public/parametrer
611
-	// pour remonter vers les inclusions appelantes
612
-	// il faut bien lever ce drapeau apres avoir evalue le fond
613
-	// pour ne pas faire descendre le flag vers les inclusions appelees
614
-	if (isset($page['invalideurs'])
615
-		and isset($page['invalideurs']['session'])
616
-	) {
617
-		$GLOBALS['cache_utilise_session'] = $page['invalideurs']['session'];
618
-	}
619
-
620
-	return $page;
601
+    $page = inclure_page($fond, $contexte, $connect);
602
+
603
+    if (!$page) {
604
+        return $page;
605
+    }
606
+    // eval $page et affecte $res
607
+    include _ROOT_RESTREINT . "public/evaluer_page.php";
608
+
609
+    // Lever un drapeau (global) si le fond utilise #SESSION
610
+    // a destination de public/parametrer
611
+    // pour remonter vers les inclusions appelantes
612
+    // il faut bien lever ce drapeau apres avoir evalue le fond
613
+    // pour ne pas faire descendre le flag vers les inclusions appelees
614
+    if (isset($page['invalideurs'])
615
+        and isset($page['invalideurs']['session'])
616
+    ) {
617
+        $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session'];
618
+    }
619
+
620
+    return $page;
621 621
 }
622 622
 
623 623
 
624 624
 // http://code.spip.net/@page_base_href
625 625
 function page_base_href(&$texte) {
626
-	static $set_html_base = null;
627
-	if (is_null($set_html_base)) {
628
-		if (!defined('_SET_HTML_BASE'))
629
-			// si la profondeur est superieure a 1
630
-			// est que ce n'est pas une url page ni une url action
631
-			// activer par defaut
632
-		{
633
-			$set_html_base = ((
634
-				$GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2)
635
-				and _request(_SPIP_PAGE) !== 'login'
636
-				and !_request('action')) ? true : false);
637
-		} else {
638
-			$set_html_base = _SET_HTML_BASE;
639
-		}
640
-	}
641
-
642
-	if ($set_html_base
643
-		and isset($GLOBALS['html']) and $GLOBALS['html']
644
-		and $GLOBALS['profondeur_url'] > 0
645
-		and ($poshead = strpos($texte, '</head>')) !== false
646
-	) {
647
-		$head = substr($texte, 0, $poshead);
648
-		$insert = false;
649
-		if (strpos($head, '<base') === false) {
650
-			$insert = true;
651
-		} else {
652
-			// si aucun <base ...> n'a de href c'est bon quand meme !
653
-			$insert = true;
654
-			include_spip('inc/filtres');
655
-			$bases = extraire_balises($head, 'base');
656
-			foreach ($bases as $base) {
657
-				if (extraire_attribut($base, 'href')) {
658
-					$insert = false;
659
-				}
660
-			}
661
-		}
662
-		if ($insert) {
663
-			include_spip('inc/filtres_mini');
664
-			// ajouter un base qui reglera tous les liens relatifs
665
-			$base = url_absolue('./');
666
-			$bbase = "\n<base href=\"$base\" />";
667
-			if (($pos = strpos($head, '<head>')) !== false) {
668
-				$head = substr_replace($head, $bbase, $pos + 6, 0);
669
-			} elseif (preg_match(",<head[^>]*>,i", $head, $r)) {
670
-				$head = str_replace($r[0], $r[0] . $bbase, $head);
671
-			}
672
-			$texte = $head . substr($texte, $poshead);
673
-			// gerer les ancres
674
-			$base = $_SERVER['REQUEST_URI'];
675
-			// pas de guillemets ni < dans l'URL qu'on insere dans le HTML
676
-			if (strpos($base,"'") or strpos($base,'"') or strpos($base,'<')) {
677
-				$base = str_replace(array("'",'"','<'),array("%27",'%22','%3C'), $base);
678
-			}
679
-			if (strpos($texte, "href='#") !== false) {
680
-				$texte = str_replace("href='#", "href='$base#", $texte);
681
-			}
682
-			if (strpos($texte, "href=\"#") !== false) {
683
-				$texte = str_replace("href=\"#", "href=\"$base#", $texte);
684
-			}
685
-		}
686
-	}
626
+    static $set_html_base = null;
627
+    if (is_null($set_html_base)) {
628
+        if (!defined('_SET_HTML_BASE'))
629
+            // si la profondeur est superieure a 1
630
+            // est que ce n'est pas une url page ni une url action
631
+            // activer par defaut
632
+        {
633
+            $set_html_base = ((
634
+                $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2)
635
+                and _request(_SPIP_PAGE) !== 'login'
636
+                and !_request('action')) ? true : false);
637
+        } else {
638
+            $set_html_base = _SET_HTML_BASE;
639
+        }
640
+    }
641
+
642
+    if ($set_html_base
643
+        and isset($GLOBALS['html']) and $GLOBALS['html']
644
+        and $GLOBALS['profondeur_url'] > 0
645
+        and ($poshead = strpos($texte, '</head>')) !== false
646
+    ) {
647
+        $head = substr($texte, 0, $poshead);
648
+        $insert = false;
649
+        if (strpos($head, '<base') === false) {
650
+            $insert = true;
651
+        } else {
652
+            // si aucun <base ...> n'a de href c'est bon quand meme !
653
+            $insert = true;
654
+            include_spip('inc/filtres');
655
+            $bases = extraire_balises($head, 'base');
656
+            foreach ($bases as $base) {
657
+                if (extraire_attribut($base, 'href')) {
658
+                    $insert = false;
659
+                }
660
+            }
661
+        }
662
+        if ($insert) {
663
+            include_spip('inc/filtres_mini');
664
+            // ajouter un base qui reglera tous les liens relatifs
665
+            $base = url_absolue('./');
666
+            $bbase = "\n<base href=\"$base\" />";
667
+            if (($pos = strpos($head, '<head>')) !== false) {
668
+                $head = substr_replace($head, $bbase, $pos + 6, 0);
669
+            } elseif (preg_match(",<head[^>]*>,i", $head, $r)) {
670
+                $head = str_replace($r[0], $r[0] . $bbase, $head);
671
+            }
672
+            $texte = $head . substr($texte, $poshead);
673
+            // gerer les ancres
674
+            $base = $_SERVER['REQUEST_URI'];
675
+            // pas de guillemets ni < dans l'URL qu'on insere dans le HTML
676
+            if (strpos($base,"'") or strpos($base,'"') or strpos($base,'<')) {
677
+                $base = str_replace(array("'",'"','<'),array("%27",'%22','%3C'), $base);
678
+            }
679
+            if (strpos($texte, "href='#") !== false) {
680
+                $texte = str_replace("href='#", "href='$base#", $texte);
681
+            }
682
+            if (strpos($texte, "href=\"#") !== false) {
683
+                $texte = str_replace("href=\"#", "href=\"$base#", $texte);
684
+            }
685
+        }
686
+    }
687 687
 }
688 688
 
689 689
 
@@ -691,8 +691,8 @@  discard block
 block discarded – undo
691 691
 // et demarrent par X-Spip-...
692 692
 // http://code.spip.net/@envoyer_entetes
693 693
 function envoyer_entetes($entetes) {
694
-	foreach ($entetes as $k => $v) #	if (strncmp($k, 'X-Spip-', 7))
695
-	{
696
-		@header(strlen($v) ? "$k: $v" : $k);
697
-	}
694
+    foreach ($entetes as $k => $v) #	if (strncmp($k, 'X-Spip-', 7))
695
+    {
696
+        @header(strlen($v) ? "$k: $v" : $k);
697
+    }
698 698
 }
Please login to merge, or discard this patch.