Completed
Push — spip-3.0 ( 77f3d0...1797f4 )
by cam
17:20 queued 08:11
created
ecrire/inc/puce_statut.php 4 patches
Doc Comments   +11 added lines patch added patch discarded remove patch
@@ -243,6 +243,12 @@  discard block
 block discarded – undo
243 243
 }
244 244
 
245 245
 // http://doc.spip.org/@puce_statut_article_dist
246
+/**
247
+ * @param integer $id
248
+ * @param string $statut
249
+ * @param integer $id_rubrique
250
+ * @param boolean $menu_rapide
251
+ */
246 252
 function puce_statut_changement_rapide($id, $statut, $id_rubrique, $type='article', $ajax = false, $menu_rapide=_ACTIVER_PUCE_RAPIDE) {
247 253
 	$src = statut_image($type, $statut);
248 254
 	if (!$src)
@@ -317,6 +323,11 @@  discard block
 block discarded – undo
317 323
 }
318 324
 
319 325
 // http://doc.spip.org/@afficher_script_statut
326
+/**
327
+ * @param string $type
328
+ * @param double $n
329
+ * @param string $img
330
+ */
320 331
 function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act='') {
321 332
 	$h = generer_action_auteur("instituer_objet","$type-$id-$statut");
322 333
 	$h = "selec_statut('$id', '$type', $n, jQuery('img',this).attr('src'), '$h');return false;";
Please login to merge, or discard this patch.
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) return;
14 14
 if (!defined('_ACTIVER_PUCE_RAPIDE'))
15
-	define('_ACTIVER_PUCE_RAPIDE', true);
15
+    define('_ACTIVER_PUCE_RAPIDE', true);
16 16
 
17 17
 /**
18 18
  * Afficher la puce statut d'un objet
@@ -30,23 +30,23 @@  discard block
 block discarded – undo
30 30
  * @return string
31 31
  */
32 32
 function inc_puce_statut_dist($id_objet, $statut, $id_parent, $type, $ajax=false, $menu_rapide=_ACTIVER_PUCE_RAPIDE) {
33
-	static $f_puce_statut = array();
34
-	$type = objet_type($type);
35
-	// cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques
36
-	if (!isset($f_puce_statut[$type]) OR is_null($f_puce_statut[$type]))
37
-		$f_puce_statut[$type] = charger_fonction($type,'puce_statut',true);
38
-	if ($f_puce_statut[$type])
39
-		return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide);
33
+    static $f_puce_statut = array();
34
+    $type = objet_type($type);
35
+    // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques
36
+    if (!isset($f_puce_statut[$type]) OR is_null($f_puce_statut[$type]))
37
+        $f_puce_statut[$type] = charger_fonction($type,'puce_statut',true);
38
+    if ($f_puce_statut[$type])
39
+        return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide);
40 40
 
41
-	// si statut_image trouve quelque chose (et '' est quelque chose)
42
-	// composer une puce, avec si possible changement rapide
43
-	elseif(!is_null($puce=puce_statut_changement_rapide($id_objet,$statut,$id_parent,$type,$ajax,$menu_rapide))){
44
-		return $puce;
45
-	}
41
+    // si statut_image trouve quelque chose (et '' est quelque chose)
42
+    // composer une puce, avec si possible changement rapide
43
+    elseif(!is_null($puce=puce_statut_changement_rapide($id_objet,$statut,$id_parent,$type,$ajax,$menu_rapide))){
44
+        return $puce;
45
+    }
46 46
 
47
-	// sinon fausse puce avec le type de l'image
48
-	else
49
-		return http_img_pack("$type-16.png",'');
47
+    // sinon fausse puce avec le type de l'image
48
+    else
49
+        return http_img_pack("$type-16.png",'');
50 50
 }
51 51
 
52 52
 /**
@@ -65,40 +65,40 @@  discard block
 block discarded – undo
65 65
  *   null si pas capable de determiner l'image
66 66
  */
67 67
 function statut_image($objet,$statut){
68
-	$src = null;
69
-	$table = table_objet_sql($objet);
70
-	$desc = lister_tables_objets_sql($table);
71
-	if (isset($desc['statut_images'])){
72
-		// si une declaration statut_images
73
-		// mais rien pour le statut demande, ne rien afficher
74
-		$src = '';
75
-		if (isset($desc['statut_images'][$statut]))
76
-			$src = $desc['statut_images'][$statut];
77
-		// sinon image par defaut ?
78
-		elseif (isset($desc['statut_images'][0]))
79
-			$src = $desc['statut_images'][0];
80
-	}
81
-	else {
82
-		switch ($statut) {
83
-			case 'prepa':
84
-				$src = 'puce-preparer-8.png';
85
-				break;
86
-			case 'prop':
87
-				$src = 'puce-proposer-8.png';
88
-				break;
89
-			case 'publie':
90
-				$src = 'puce-publier-8.png';
91
-				break;
92
-			case 'refuse':
93
-				$src = 'puce-refuser-8.png';
94
-				break;
95
-			case 'poubelle':
96
-			case 'poub':
97
-				$src = 'puce-supprimer-8.png';
98
-				break;
99
-		}
100
-	}
101
-	return $src;
68
+    $src = null;
69
+    $table = table_objet_sql($objet);
70
+    $desc = lister_tables_objets_sql($table);
71
+    if (isset($desc['statut_images'])){
72
+        // si une declaration statut_images
73
+        // mais rien pour le statut demande, ne rien afficher
74
+        $src = '';
75
+        if (isset($desc['statut_images'][$statut]))
76
+            $src = $desc['statut_images'][$statut];
77
+        // sinon image par defaut ?
78
+        elseif (isset($desc['statut_images'][0]))
79
+            $src = $desc['statut_images'][0];
80
+    }
81
+    else {
82
+        switch ($statut) {
83
+            case 'prepa':
84
+                $src = 'puce-preparer-8.png';
85
+                break;
86
+            case 'prop':
87
+                $src = 'puce-proposer-8.png';
88
+                break;
89
+            case 'publie':
90
+                $src = 'puce-publier-8.png';
91
+                break;
92
+            case 'refuse':
93
+                $src = 'puce-refuser-8.png';
94
+                break;
95
+            case 'poubelle':
96
+            case 'poub':
97
+                $src = 'puce-supprimer-8.png';
98
+                break;
99
+        }
100
+    }
101
+    return $src;
102 102
 }
103 103
 
104 104
 /**
@@ -116,39 +116,39 @@  discard block
 block discarded – undo
116 116
  * @return string
117 117
  */
118 118
 function statut_titre($objet,$statut){
119
-	$titre = '';
120
-	$table = table_objet_sql($objet);
121
-	$desc = lister_tables_objets_sql($table);
122
-	if (isset($desc['statut_titres'])){
123
-		// si une declaration statut_titres
124
-		// mais rien pour le statut demande, ne rien afficher
125
-		if (isset($desc['statut_titres'][$statut]))
126
-			$titre = $desc['statut_titres'][$statut];
127
-		// sinon image par defaut ?
128
-		elseif (isset($desc['statut_titres'][0]))
129
-			$titre = $desc['statut_titres'][0];
130
-	}
131
-	else {
132
-		switch ($statut) {
133
-			case 'prepa':
134
-				$titre = 'texte_statut_en_cours_redaction';
135
-				break;
136
-			case 'prop':
137
-				$titre = 'texte_statut_propose_evaluation';
138
-				break;
139
-			case 'publie':
140
-				$titre = 'texte_statut_publie';
141
-				break;
142
-			case 'refuse':
143
-				$titre = 'texte_statut_refuse';
144
-				break;
145
-			case 'poubelle':
146
-			case 'poub':
147
-				$titre = 'texte_statut_poubelle';
148
-				break;
149
-		}
150
-	}
151
-	return $titre?_T($titre):'';
119
+    $titre = '';
120
+    $table = table_objet_sql($objet);
121
+    $desc = lister_tables_objets_sql($table);
122
+    if (isset($desc['statut_titres'])){
123
+        // si une declaration statut_titres
124
+        // mais rien pour le statut demande, ne rien afficher
125
+        if (isset($desc['statut_titres'][$statut]))
126
+            $titre = $desc['statut_titres'][$statut];
127
+        // sinon image par defaut ?
128
+        elseif (isset($desc['statut_titres'][0]))
129
+            $titre = $desc['statut_titres'][0];
130
+    }
131
+    else {
132
+        switch ($statut) {
133
+            case 'prepa':
134
+                $titre = 'texte_statut_en_cours_redaction';
135
+                break;
136
+            case 'prop':
137
+                $titre = 'texte_statut_propose_evaluation';
138
+                break;
139
+            case 'publie':
140
+                $titre = 'texte_statut_publie';
141
+                break;
142
+            case 'refuse':
143
+                $titre = 'texte_statut_refuse';
144
+                break;
145
+            case 'poubelle':
146
+            case 'poub':
147
+                $titre = 'texte_statut_poubelle';
148
+                break;
149
+        }
150
+    }
151
+    return $titre?_T($titre):'';
152 152
 }
153 153
 
154 154
 
@@ -168,36 +168,36 @@  discard block
 block discarded – undo
168 168
  * @return string
169 169
  */
170 170
 function statut_texte_instituer($objet,$statut){
171
-	$texte = '';
172
-	$table = table_objet_sql($objet);
173
-	$desc = lister_tables_objets_sql($table);
174
-	if (isset($desc['statut_textes_instituer'])){
175
-		// si une declaration statut_titres
176
-		// mais rien pour le statut demande, ne rien afficher
177
-		if (isset($desc['statut_textes_instituer'][$statut]))
178
-			$texte = $desc['statut_textes_instituer'][$statut];
179
-	}
180
-	else {
181
-		switch ($statut) {
182
-			case 'prepa':
183
-				$texte = 'texte_statut_en_cours_redaction';
184
-				break;
185
-			case 'prop':
186
-				$texte = 'texte_statut_propose_evaluation';
187
-				break;
188
-			case 'publie':
189
-				$texte = 'texte_statut_publie';
190
-				break;
191
-			case 'refuse':
192
-				$texte = 'texte_statut_refuse';
193
-				break;
194
-			case 'poubelle':
195
-			case 'poub':
196
-				$texte = 'texte_statut_poubelle';
197
-				break;
198
-		}
199
-	}
200
-	return $texte?_T($texte):'';
171
+    $texte = '';
172
+    $table = table_objet_sql($objet);
173
+    $desc = lister_tables_objets_sql($table);
174
+    if (isset($desc['statut_textes_instituer'])){
175
+        // si une declaration statut_titres
176
+        // mais rien pour le statut demande, ne rien afficher
177
+        if (isset($desc['statut_textes_instituer'][$statut]))
178
+            $texte = $desc['statut_textes_instituer'][$statut];
179
+    }
180
+    else {
181
+        switch ($statut) {
182
+            case 'prepa':
183
+                $texte = 'texte_statut_en_cours_redaction';
184
+                break;
185
+            case 'prop':
186
+                $texte = 'texte_statut_propose_evaluation';
187
+                break;
188
+            case 'publie':
189
+                $texte = 'texte_statut_publie';
190
+                break;
191
+            case 'refuse':
192
+                $texte = 'texte_statut_refuse';
193
+                break;
194
+            case 'poubelle':
195
+            case 'poub':
196
+                $texte = 'texte_statut_poubelle';
197
+                break;
198
+        }
199
+    }
200
+    return $texte?_T($texte):'';
201 201
 }
202 202
 
203 203
 
@@ -219,12 +219,12 @@  discard block
 block discarded – undo
219 219
  * @return string
220 220
  */
221 221
 function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax='', $menu_rapide=_ACTIVER_PUCE_RAPIDE) {
222
-	$img = statut_image('auteur',$statut);
223
-	if (!$img) return '';
224
-	$alt = statut_titre('auteur',$statut);
222
+    $img = statut_image('auteur',$statut);
223
+    if (!$img) return '';
224
+    $alt = statut_titre('auteur',$statut);
225 225
 
226
-	$fond = ''; $titre = '';
227
-	/*
226
+    $fond = ''; $titre = '';
227
+    /*
228 228
 	if ($type != 'auteur') {
229 229
 	  $img2 = chemin_image('del-16.png');
230 230
 	  $titre = _T('titre_image_redacteur');
@@ -233,95 +233,95 @@  discard block
 block discarded – undo
233 233
 	else {
234 234
 	}
235 235
 	*/
236
-	return http_img_pack($img, $alt, $fond, $alt);
236
+    return http_img_pack($img, $alt, $fond, $alt);
237 237
 }
238 238
 
239 239
 
240 240
 // http://doc.spip.org/@puce_statut_rubrique_dist
241 241
 function puce_statut_rubrique_dist($id, $statut, $id_rubrique, $type, $ajax='',$menu_rapide=_ACTIVER_PUCE_RAPIDE) {
242
-	return http_img_pack('rubrique-16.png', '');
242
+    return http_img_pack('rubrique-16.png', '');
243 243
 }
244 244
 
245 245
 // http://doc.spip.org/@puce_statut_article_dist
246 246
 function puce_statut_changement_rapide($id, $statut, $id_rubrique, $type='article', $ajax = false, $menu_rapide=_ACTIVER_PUCE_RAPIDE) {
247
-	$src = statut_image($type, $statut);
248
-	if (!$src)
249
-		return $src;
247
+    $src = statut_image($type, $statut);
248
+    if (!$src)
249
+        return $src;
250 250
 
251
-	if (!$id
252
-	  OR !_SPIP_AJAX
253
-	  OR !$menu_rapide) {
254
-	  $ajax_node ='';
255
-	}
256
-	else
257
-		$ajax_node = " class='imgstatut$type$id'";
251
+    if (!$id
252
+      OR !_SPIP_AJAX
253
+      OR !$menu_rapide) {
254
+        $ajax_node ='';
255
+    }
256
+    else
257
+        $ajax_node = " class='imgstatut$type$id'";
258 258
 
259 259
 
260
-	$t = statut_titre($type, $statut);
261
-	$inser_puce = http_img_pack($src,$t,$ajax_node,$t);
260
+    $t = statut_titre($type, $statut);
261
+    $inser_puce = http_img_pack($src,$t,$ajax_node,$t);
262 262
 
263
-	if (!$ajax_node)
264
-		return $inser_puce;
263
+    if (!$ajax_node)
264
+        return $inser_puce;
265 265
 
266
-	$table = table_objet_sql($type);
267
-	$desc = lister_tables_objets_sql($table);
268
-	if (!isset($desc['statut_textes_instituer']))
269
-		return $inser_puce;
266
+    $table = table_objet_sql($type);
267
+    $desc = lister_tables_objets_sql($table);
268
+    if (!isset($desc['statut_textes_instituer']))
269
+        return $inser_puce;
270 270
 	
271
-	include_spip('inc/autoriser');
272
-	// cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique)
273
-	if ($id_rubrique){
274
-		if (!autoriser('publierdans', 'rubrique', $id_rubrique))
275
-			return $inser_puce;
276
-	}
277
-	// si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie
278
-	else {
279
-		if (!autoriser('instituer', $type, $id, null, array('statut'=>'publie')))
280
-			return $inser_puce;
281
-	}
271
+    include_spip('inc/autoriser');
272
+    // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique)
273
+    if ($id_rubrique){
274
+        if (!autoriser('publierdans', 'rubrique', $id_rubrique))
275
+            return $inser_puce;
276
+    }
277
+    // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie
278
+    else {
279
+        if (!autoriser('instituer', $type, $id, null, array('statut'=>'publie')))
280
+            return $inser_puce;
281
+    }
282 282
 
283
-	$coord = array_flip(array_keys($desc['statut_textes_instituer']));
284
-	if (!isset($coord[$statut]))
285
-		return $inser_puce;
283
+    $coord = array_flip(array_keys($desc['statut_textes_instituer']));
284
+    if (!isset($coord[$statut]))
285
+        return $inser_puce;
286 286
 
287
-	$unit = 8/*widh de img*/+4/*padding*/;
288
-	$margin = 4; /* marge a gauche + droite */
289
-	$zero = 1 /*border*/ + $margin/2 + 2 /*padding*/;
290
-	$clip = $zero+ ($unit*$coord[$statut]);
287
+    $unit = 8/*widh de img*/+4/*padding*/;
288
+    $margin = 4; /* marge a gauche + droite */
289
+    $zero = 1 /*border*/ + $margin/2 + 2 /*padding*/;
290
+    $clip = $zero+ ($unit*$coord[$statut]);
291 291
 
292
-	if ($ajax){
293
-		$width = $unit*count($desc['statut_textes_instituer'])+$margin;
294
-		$out = "<span class='puce_objet_fixe $type'>"
295
-		. $inser_puce
296
-		. "</span>"
297
-		. "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>";
298
-		$i=0;
299
-		foreach($desc['statut_textes_instituer'] as $s=>$t){
300
-			$out .= afficher_script_statut($id, $type, -$zero-$i++*$unit, statut_image($type,$s), $s, _T($t));
301
-		}
302
-		$out .= "</span>";
303
-		return $out;
304
-	}
305
-	else {
292
+    if ($ajax){
293
+        $width = $unit*count($desc['statut_textes_instituer'])+$margin;
294
+        $out = "<span class='puce_objet_fixe $type'>"
295
+        . $inser_puce
296
+        . "</span>"
297
+        . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>";
298
+        $i=0;
299
+        foreach($desc['statut_textes_instituer'] as $s=>$t){
300
+            $out .= afficher_script_statut($id, $type, -$zero-$i++*$unit, statut_image($type,$s), $s, _T($t));
301
+        }
302
+        $out .= "</span>";
303
+        return $out;
304
+    }
305
+    else {
306 306
 
307
-		$nom = "puce_statut_";
308
-	  $action = generer_url_ecrire('puce_statut',"",true);
309
-	  $action = "if (!this.puce_loaded) { this.puce_loaded = true; prepare_selec_statut(this, '$nom', '$type', '$id', '$action'); }";
310
-	  $over = " onmouseover=\"$action\"";
307
+        $nom = "puce_statut_";
308
+        $action = generer_url_ecrire('puce_statut',"",true);
309
+        $action = "if (!this.puce_loaded) { this.puce_loaded = true; prepare_selec_statut(this, '$nom', '$type', '$id', '$action'); }";
310
+        $over = " onmouseover=\"$action\"";
311 311
 
312
-		$lang_dir = lang_dir(lang_typo());
313
-		return 	"<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir'$over>"
314
-		. $inser_puce
315
-		. '</span>';
316
-	}
312
+        $lang_dir = lang_dir(lang_typo());
313
+        return 	"<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir'$over>"
314
+        . $inser_puce
315
+        . '</span>';
316
+    }
317 317
 }
318 318
 
319 319
 // http://doc.spip.org/@afficher_script_statut
320 320
 function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act='') {
321
-	$h = generer_action_auteur("instituer_objet","$type-$id-$statut");
322
-	$h = "selec_statut('$id', '$type', $n, jQuery('img',this).attr('src'), '$h');return false;";
323
-	$t = supprimer_tags($titre);
324
-	return "<a href=\"#\" onclick=\"$h\" title=\"$t\"$act>".http_img_pack($img,$t)."</a>";
321
+    $h = generer_action_auteur("instituer_objet","$type-$id-$statut");
322
+    $h = "selec_statut('$id', '$type', $n, jQuery('img',this).attr('src'), '$h');return false;";
323
+    $t = supprimer_tags($titre);
324
+    return "<a href=\"#\" onclick=\"$h\" title=\"$t\"$act>".http_img_pack($img,$t)."</a>";
325 325
 }
326 326
 
327 327
 // compat
@@ -329,9 +329,9 @@  discard block
 block discarded – undo
329 329
 // http://doc.spip.org/@puce_statut
330 330
 
331 331
 function puce_statut($statut, $atts='') {
332
-	$src = statut_image('article',$statut);
333
-	if (!$src) return '';
334
-	return http_img_pack($src, statut_titre('article',$statut), $atts);
332
+    $src = statut_image('article',$statut);
333
+    if (!$src) return '';
334
+    return http_img_pack($src, statut_titre('article',$statut), $atts);
335 335
 }
336 336
 
337 337
 ?>
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -29,24 +29,24 @@  discard block
 block discarded – undo
29 29
  * @param bool $menu_rapide
30 30
  * @return string
31 31
  */
32
-function inc_puce_statut_dist($id_objet, $statut, $id_parent, $type, $ajax=false, $menu_rapide=_ACTIVER_PUCE_RAPIDE) {
32
+function inc_puce_statut_dist($id_objet, $statut, $id_parent, $type, $ajax = false, $menu_rapide = _ACTIVER_PUCE_RAPIDE) {
33 33
 	static $f_puce_statut = array();
34 34
 	$type = objet_type($type);
35 35
 	// cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques
36 36
 	if (!isset($f_puce_statut[$type]) OR is_null($f_puce_statut[$type]))
37
-		$f_puce_statut[$type] = charger_fonction($type,'puce_statut',true);
37
+		$f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true);
38 38
 	if ($f_puce_statut[$type])
39 39
 		return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide);
40 40
 
41 41
 	// si statut_image trouve quelque chose (et '' est quelque chose)
42 42
 	// composer une puce, avec si possible changement rapide
43
-	elseif(!is_null($puce=puce_statut_changement_rapide($id_objet,$statut,$id_parent,$type,$ajax,$menu_rapide))){
43
+	elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) {
44 44
 		return $puce;
45 45
 	}
46 46
 
47 47
 	// sinon fausse puce avec le type de l'image
48 48
 	else
49
-		return http_img_pack("$type-16.png",'');
49
+		return http_img_pack("$type-16.png", '');
50 50
 }
51 51
 
52 52
 /**
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
  * @return string
65 65
  *   null si pas capable de determiner l'image
66 66
  */
67
-function statut_image($objet,$statut){
67
+function statut_image($objet, $statut) {
68 68
 	$src = null;
69 69
 	$table = table_objet_sql($objet);
70 70
 	$desc = lister_tables_objets_sql($table);
71
-	if (isset($desc['statut_images'])){
71
+	if (isset($desc['statut_images'])) {
72 72
 		// si une declaration statut_images
73 73
 		// mais rien pour le statut demande, ne rien afficher
74 74
 		$src = '';
@@ -115,11 +115,11 @@  discard block
 block discarded – undo
115 115
  * @param string $statut
116 116
  * @return string
117 117
  */
118
-function statut_titre($objet,$statut){
118
+function statut_titre($objet, $statut) {
119 119
 	$titre = '';
120 120
 	$table = table_objet_sql($objet);
121 121
 	$desc = lister_tables_objets_sql($table);
122
-	if (isset($desc['statut_titres'])){
122
+	if (isset($desc['statut_titres'])) {
123 123
 		// si une declaration statut_titres
124 124
 		// mais rien pour le statut demande, ne rien afficher
125 125
 		if (isset($desc['statut_titres'][$statut]))
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 				break;
149 149
 		}
150 150
 	}
151
-	return $titre?_T($titre):'';
151
+	return $titre ? _T($titre) : '';
152 152
 }
153 153
 
154 154
 
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
  * @param string $statut
168 168
  * @return string
169 169
  */
170
-function statut_texte_instituer($objet,$statut){
170
+function statut_texte_instituer($objet, $statut) {
171 171
 	$texte = '';
172 172
 	$table = table_objet_sql($objet);
173 173
 	$desc = lister_tables_objets_sql($table);
174
-	if (isset($desc['statut_textes_instituer'])){
174
+	if (isset($desc['statut_textes_instituer'])) {
175 175
 		// si une declaration statut_titres
176 176
 		// mais rien pour le statut demande, ne rien afficher
177 177
 		if (isset($desc['statut_textes_instituer'][$statut]))
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 				break;
198 198
 		}
199 199
 	}
200
-	return $texte?_T($texte):'';
200
+	return $texte ? _T($texte) : '';
201 201
 }
202 202
 
203 203
 
@@ -218,10 +218,10 @@  discard block
 block discarded – undo
218 218
  * @param bool $menu_rapide
219 219
  * @return string
220 220
  */
221
-function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax='', $menu_rapide=_ACTIVER_PUCE_RAPIDE) {
222
-	$img = statut_image('auteur',$statut);
221
+function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) {
222
+	$img = statut_image('auteur', $statut);
223 223
 	if (!$img) return '';
224
-	$alt = statut_titre('auteur',$statut);
224
+	$alt = statut_titre('auteur', $statut);
225 225
 
226 226
 	$fond = ''; $titre = '';
227 227
 	/*
@@ -238,12 +238,12 @@  discard block
 block discarded – undo
238 238
 
239 239
 
240 240
 // http://doc.spip.org/@puce_statut_rubrique_dist
241
-function puce_statut_rubrique_dist($id, $statut, $id_rubrique, $type, $ajax='',$menu_rapide=_ACTIVER_PUCE_RAPIDE) {
241
+function puce_statut_rubrique_dist($id, $statut, $id_rubrique, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) {
242 242
 	return http_img_pack('rubrique-16.png', '');
243 243
 }
244 244
 
245 245
 // http://doc.spip.org/@puce_statut_article_dist
246
-function puce_statut_changement_rapide($id, $statut, $id_rubrique, $type='article', $ajax = false, $menu_rapide=_ACTIVER_PUCE_RAPIDE) {
246
+function puce_statut_changement_rapide($id, $statut, $id_rubrique, $type = 'article', $ajax = false, $menu_rapide = _ACTIVER_PUCE_RAPIDE) {
247 247
 	$src = statut_image($type, $statut);
248 248
 	if (!$src)
249 249
 		return $src;
@@ -251,14 +251,14 @@  discard block
 block discarded – undo
251 251
 	if (!$id
252 252
 	  OR !_SPIP_AJAX
253 253
 	  OR !$menu_rapide) {
254
-	  $ajax_node ='';
254
+	  $ajax_node = '';
255 255
 	}
256 256
 	else
257 257
 		$ajax_node = " class='imgstatut$type$id'";
258 258
 
259 259
 
260 260
 	$t = statut_titre($type, $statut);
261
-	$inser_puce = http_img_pack($src,$t,$ajax_node,$t);
261
+	$inser_puce = http_img_pack($src, $t, $ajax_node, $t);
262 262
 
263 263
 	if (!$ajax_node)
264 264
 		return $inser_puce;
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 	
271 271
 	include_spip('inc/autoriser');
272 272
 	// cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique)
273
-	if ($id_rubrique){
273
+	if ($id_rubrique) {
274 274
 		if (!autoriser('publierdans', 'rubrique', $id_rubrique))
275 275
 			return $inser_puce;
276 276
 	}
@@ -286,18 +286,18 @@  discard block
 block discarded – undo
286 286
 
287 287
 	$unit = 8/*widh de img*/+4/*padding*/;
288 288
 	$margin = 4; /* marge a gauche + droite */
289
-	$zero = 1 /*border*/ + $margin/2 + 2 /*padding*/;
290
-	$clip = $zero+ ($unit*$coord[$statut]);
289
+	$zero = 1 /*border*/ + $margin / 2 + 2 /*padding*/;
290
+	$clip = $zero + ($unit * $coord[$statut]);
291 291
 
292
-	if ($ajax){
293
-		$width = $unit*count($desc['statut_textes_instituer'])+$margin;
292
+	if ($ajax) {
293
+		$width = $unit * count($desc['statut_textes_instituer']) + $margin;
294 294
 		$out = "<span class='puce_objet_fixe $type'>"
295 295
 		. $inser_puce
296 296
 		. "</span>"
297 297
 		. "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>";
298
-		$i=0;
299
-		foreach($desc['statut_textes_instituer'] as $s=>$t){
300
-			$out .= afficher_script_statut($id, $type, -$zero-$i++*$unit, statut_image($type,$s), $s, _T($t));
298
+		$i = 0;
299
+		foreach ($desc['statut_textes_instituer'] as $s=>$t) {
300
+			$out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t));
301 301
 		}
302 302
 		$out .= "</span>";
303 303
 		return $out;
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 	else {
306 306
 
307 307
 		$nom = "puce_statut_";
308
-	  $action = generer_url_ecrire('puce_statut',"",true);
308
+	  $action = generer_url_ecrire('puce_statut', "", true);
309 309
 	  $action = "if (!this.puce_loaded) { this.puce_loaded = true; prepare_selec_statut(this, '$nom', '$type', '$id', '$action'); }";
310 310
 	  $over = " onmouseover=\"$action\"";
311 311
 
@@ -317,21 +317,21 @@  discard block
 block discarded – undo
317 317
 }
318 318
 
319 319
 // http://doc.spip.org/@afficher_script_statut
320
-function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act='') {
321
-	$h = generer_action_auteur("instituer_objet","$type-$id-$statut");
320
+function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act = '') {
321
+	$h = generer_action_auteur("instituer_objet", "$type-$id-$statut");
322 322
 	$h = "selec_statut('$id', '$type', $n, jQuery('img',this).attr('src'), '$h');return false;";
323 323
 	$t = supprimer_tags($titre);
324
-	return "<a href=\"#\" onclick=\"$h\" title=\"$t\"$act>".http_img_pack($img,$t)."</a>";
324
+	return "<a href=\"#\" onclick=\"$h\" title=\"$t\"$act>".http_img_pack($img, $t)."</a>";
325 325
 }
326 326
 
327 327
 // compat
328 328
 // La couleur du statut
329 329
 // http://doc.spip.org/@puce_statut
330 330
 
331
-function puce_statut($statut, $atts='') {
332
-	$src = statut_image('article',$statut);
331
+function puce_statut($statut, $atts = '') {
332
+	$src = statut_image('article', $statut);
333 333
 	if (!$src) return '';
334
-	return http_img_pack($src, statut_titre('article',$statut), $atts);
334
+	return http_img_pack($src, statut_titre('article', $statut), $atts);
335 335
 }
336 336
 
337 337
 ?>
Please login to merge, or discard this patch.
Braces   +60 added lines, -43 removed lines patch added patch discarded remove patch
@@ -10,9 +10,12 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
14
-if (!defined('_ACTIVER_PUCE_RAPIDE'))
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
16
+if (!defined('_ACTIVER_PUCE_RAPIDE')) {
15 17
 	define('_ACTIVER_PUCE_RAPIDE', true);
18
+}
16 19
 
17 20
 /**
18 21
  * Afficher la puce statut d'un objet
@@ -33,10 +36,12 @@  discard block
 block discarded – undo
33 36
 	static $f_puce_statut = array();
34 37
 	$type = objet_type($type);
35 38
 	// cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques
36
-	if (!isset($f_puce_statut[$type]) OR is_null($f_puce_statut[$type]))
37
-		$f_puce_statut[$type] = charger_fonction($type,'puce_statut',true);
38
-	if ($f_puce_statut[$type])
39
-		return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide);
39
+	if (!isset($f_puce_statut[$type]) OR is_null($f_puce_statut[$type])) {
40
+			$f_puce_statut[$type] = charger_fonction($type,'puce_statut',true);
41
+	}
42
+	if ($f_puce_statut[$type]) {
43
+			return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide);
44
+	}
40 45
 
41 46
 	// si statut_image trouve quelque chose (et '' est quelque chose)
42 47
 	// composer une puce, avec si possible changement rapide
@@ -45,9 +50,10 @@  discard block
 block discarded – undo
45 50
 	}
46 51
 
47 52
 	// sinon fausse puce avec le type de l'image
48
-	else
49
-		return http_img_pack("$type-16.png",'');
50
-}
53
+	else {
54
+			return http_img_pack("$type-16.png",'');
55
+	}
56
+	}
51 57
 
52 58
 /**
53 59
  * Recuperer l'image correspondant au statut, telle que declaree dans
@@ -72,13 +78,14 @@  discard block
 block discarded – undo
72 78
 		// si une declaration statut_images
73 79
 		// mais rien pour le statut demande, ne rien afficher
74 80
 		$src = '';
75
-		if (isset($desc['statut_images'][$statut]))
76
-			$src = $desc['statut_images'][$statut];
81
+		if (isset($desc['statut_images'][$statut])) {
82
+					$src = $desc['statut_images'][$statut];
83
+		}
77 84
 		// sinon image par defaut ?
78
-		elseif (isset($desc['statut_images'][0]))
79
-			$src = $desc['statut_images'][0];
80
-	}
81
-	else {
85
+		elseif (isset($desc['statut_images'][0])) {
86
+					$src = $desc['statut_images'][0];
87
+		}
88
+	} else {
82 89
 		switch ($statut) {
83 90
 			case 'prepa':
84 91
 				$src = 'puce-preparer-8.png';
@@ -122,13 +129,14 @@  discard block
 block discarded – undo
122 129
 	if (isset($desc['statut_titres'])){
123 130
 		// si une declaration statut_titres
124 131
 		// mais rien pour le statut demande, ne rien afficher
125
-		if (isset($desc['statut_titres'][$statut]))
126
-			$titre = $desc['statut_titres'][$statut];
132
+		if (isset($desc['statut_titres'][$statut])) {
133
+					$titre = $desc['statut_titres'][$statut];
134
+		}
127 135
 		// sinon image par defaut ?
128
-		elseif (isset($desc['statut_titres'][0]))
129
-			$titre = $desc['statut_titres'][0];
130
-	}
131
-	else {
136
+		elseif (isset($desc['statut_titres'][0])) {
137
+					$titre = $desc['statut_titres'][0];
138
+		}
139
+	} else {
132 140
 		switch ($statut) {
133 141
 			case 'prepa':
134 142
 				$titre = 'texte_statut_en_cours_redaction';
@@ -174,10 +182,10 @@  discard block
 block discarded – undo
174 182
 	if (isset($desc['statut_textes_instituer'])){
175 183
 		// si une declaration statut_titres
176 184
 		// mais rien pour le statut demande, ne rien afficher
177
-		if (isset($desc['statut_textes_instituer'][$statut]))
178
-			$texte = $desc['statut_textes_instituer'][$statut];
179
-	}
180
-	else {
185
+		if (isset($desc['statut_textes_instituer'][$statut])) {
186
+					$texte = $desc['statut_textes_instituer'][$statut];
187
+		}
188
+	} else {
181 189
 		switch ($statut) {
182 190
 			case 'prepa':
183 191
 				$texte = 'texte_statut_en_cours_redaction';
@@ -220,7 +228,9 @@  discard block
 block discarded – undo
220 228
  */
221 229
 function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax='', $menu_rapide=_ACTIVER_PUCE_RAPIDE) {
222 230
 	$img = statut_image('auteur',$statut);
223
-	if (!$img) return '';
231
+	if (!$img) {
232
+	    return '';
233
+	}
224 234
 	$alt = statut_titre('auteur',$statut);
225 235
 
226 236
 	$fond = ''; $titre = '';
@@ -245,44 +255,50 @@  discard block
 block discarded – undo
245 255
 // http://doc.spip.org/@puce_statut_article_dist
246 256
 function puce_statut_changement_rapide($id, $statut, $id_rubrique, $type='article', $ajax = false, $menu_rapide=_ACTIVER_PUCE_RAPIDE) {
247 257
 	$src = statut_image($type, $statut);
248
-	if (!$src)
249
-		return $src;
258
+	if (!$src) {
259
+			return $src;
260
+	}
250 261
 
251 262
 	if (!$id
252 263
 	  OR !_SPIP_AJAX
253 264
 	  OR !$menu_rapide) {
254 265
 	  $ajax_node ='';
266
+	} else {
267
+			$ajax_node = " class='imgstatut$type$id'";
255 268
 	}
256
-	else
257
-		$ajax_node = " class='imgstatut$type$id'";
258 269
 
259 270
 
260 271
 	$t = statut_titre($type, $statut);
261 272
 	$inser_puce = http_img_pack($src,$t,$ajax_node,$t);
262 273
 
263
-	if (!$ajax_node)
264
-		return $inser_puce;
274
+	if (!$ajax_node) {
275
+			return $inser_puce;
276
+	}
265 277
 
266 278
 	$table = table_objet_sql($type);
267 279
 	$desc = lister_tables_objets_sql($table);
268
-	if (!isset($desc['statut_textes_instituer']))
269
-		return $inser_puce;
280
+	if (!isset($desc['statut_textes_instituer'])) {
281
+			return $inser_puce;
282
+	}
270 283
 	
271 284
 	include_spip('inc/autoriser');
272 285
 	// cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique)
273 286
 	if ($id_rubrique){
274
-		if (!autoriser('publierdans', 'rubrique', $id_rubrique))
275
-			return $inser_puce;
287
+		if (!autoriser('publierdans', 'rubrique', $id_rubrique)) {
288
+					return $inser_puce;
289
+		}
276 290
 	}
277 291
 	// si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie
278 292
 	else {
279
-		if (!autoriser('instituer', $type, $id, null, array('statut'=>'publie')))
280
-			return $inser_puce;
293
+		if (!autoriser('instituer', $type, $id, null, array('statut'=>'publie'))) {
294
+					return $inser_puce;
295
+		}
281 296
 	}
282 297
 
283 298
 	$coord = array_flip(array_keys($desc['statut_textes_instituer']));
284
-	if (!isset($coord[$statut]))
285
-		return $inser_puce;
299
+	if (!isset($coord[$statut])) {
300
+			return $inser_puce;
301
+	}
286 302
 
287 303
 	$unit = 8/*widh de img*/+4/*padding*/;
288 304
 	$margin = 4; /* marge a gauche + droite */
@@ -301,8 +317,7 @@  discard block
 block discarded – undo
301 317
 		}
302 318
 		$out .= "</span>";
303 319
 		return $out;
304
-	}
305
-	else {
320
+	} else {
306 321
 
307 322
 		$nom = "puce_statut_";
308 323
 	  $action = generer_url_ecrire('puce_statut',"",true);
@@ -330,7 +345,9 @@  discard block
 block discarded – undo
330 345
 
331 346
 function puce_statut($statut, $atts='') {
332 347
 	$src = statut_image('article',$statut);
333
-	if (!$src) return '';
348
+	if (!$src) {
349
+	    return '';
350
+	}
334 351
 	return http_img_pack($src, statut_titre('article',$statut), $atts);
335 352
 }
336 353
 
Please login to merge, or discard this patch.
ecrire/inc/queue.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
  *
269 269
  * @param array $force_jobs
270 270
  *   list of id_job to execute when provided
271
- * @return null|false
271
+ * @return null|boolean
272 272
  */
273 273
 function queue_schedule($force_jobs = null){
274 274
 	$time = time();
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
  *
395 395
  * @param <type> $function
396 396
  * @param <type> $inclure
397
- * @return <type>
397
+ * @return integer
398 398
  */
399 399
 function queue_is_cron_job($function,$inclure){
400 400
 	static $taches = null;
Please login to merge, or discard this patch.
Indentation   +426 added lines, -426 removed lines patch added patch discarded remove patch
@@ -48,85 +48,85 @@  discard block
 block discarded – undo
48 48
  *	id of job
49 49
  */
50 50
 function queue_add_job($function, $description, $arguments = array(), $file = '', $no_duplicate = false, $time=0, $priority=0){
51
-	include_spip('base/abstract_sql');
52
-
53
-	// cas pourri de ecrire/action/editer_site avec l'option reload=oui
54
-	if (defined('_GENIE_SYNDIC_NOW'))
55
-		$arguments['id_syndic'] = _GENIE_SYNDIC_NOW;
56
-
57
-	// serialiser les arguments
58
-	$arguments = serialize($arguments);
59
-	$md5args = md5($arguments);
60
-
61
-	// si pas de date programee, des que possible
62
-	$duplicate_where = 'status='.intval(_JQ_SCHEDULED).' AND ';
63
-	if (!$time){
64
-		$time = time();
65
-		$duplicate_where = ""; // ne pas dupliquer si deja le meme job en cours d'execution
66
-	}
67
-	$date = date('Y-m-d H:i:s',$time);
68
-
69
-	$set_job = array(
70
-		'fonction'=>$function,
71
-		'descriptif'=>$description,
72
-		'args'=>$arguments,
73
-		'md5args'=>$md5args,
74
-		'inclure'=>$file,
75
-		'priorite'=>max(-10,min(10,intval($priority))),
76
-		'date'=>$date,
77
-		'status'=>_JQ_SCHEDULED,
78
-	);
79
-	// si option ne pas dupliquer, regarder si la fonction existe deja
80
-	// avec les memes args et file
81
-	if (
82
-			$no_duplicate
83
-		AND
84
-			$id_job = sql_getfetsel('id_job','spip_jobs',
85
-				$duplicate_where =
86
-					$duplicate_where . 'fonction='.sql_quote($function)
87
-				.(($no_duplicate==='function_only')?'':
88
-				 ' AND md5args='.sql_quote($md5args).' AND inclure='.sql_quote($file)))
89
-		)
90
-		return $id_job;
91
-
92
-	$id_job = sql_insertq('spip_jobs',$set_job);
93
-	// en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele
94
-	// avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand
95
-	// doit s'effacer
96
-	if (
97
-			$no_duplicate
98
-		AND
99
-			$id_prev = sql_getfetsel('id_job','spip_jobs',"id_job<".intval($id_job)." AND $duplicate_where")){
100
-		sql_delete('spip_jobs','id_job='.intval($id_job));
101
-		return $id_prev;
102
-	}
103
-
104
-	// verifier la non duplication qui peut etre problematique en cas de concurence
105
-	// il faut dans ce cas que seul le dernier ajoute se supprime !
106
-
107
-	// une option de debug pour verifier que les arguments en base sont bons
108
-	// ie cas d'un char non acceptables sur certains type de champs
109
-	// qui coupe la valeur
110
-	if (defined('_JQ_INSERT_CHECK_ARGS') AND $id_job) {
111
-		$args = sql_getfetsel('args', 'spip_jobs', 'id_job='.intval($id_job));
112
-		if ($args!==$arguments) {
113
-			spip_log('arguments job errones / longueur '.strlen($args)." vs ".strlen($arguments).' / valeur : '.var_export($arguments,true),'queue');
114
-		}
115
-	}
116
-
117
-	if ($id_job){
118
-		queue_update_next_job_time($time);
119
-	}
120
-	// si la mise en file d'attente du job echoue,
121
-	// il ne faut pas perdre l'execution de la fonction
122
-	// on la lance immediatement, c'est un fallback
123
-	// sauf en cas d'upgrade necessaire (table spip_jobs inexistante)
124
-	elseif($GLOBALS['meta']['version_installee']==$GLOBALS['spip_version_base']) {
125
-		$set_job['id_job'] = 0;
126
-		queue_start_job($set_job);
127
-	}
128
-
129
-	return $id_job;
51
+    include_spip('base/abstract_sql');
52
+
53
+    // cas pourri de ecrire/action/editer_site avec l'option reload=oui
54
+    if (defined('_GENIE_SYNDIC_NOW'))
55
+        $arguments['id_syndic'] = _GENIE_SYNDIC_NOW;
56
+
57
+    // serialiser les arguments
58
+    $arguments = serialize($arguments);
59
+    $md5args = md5($arguments);
60
+
61
+    // si pas de date programee, des que possible
62
+    $duplicate_where = 'status='.intval(_JQ_SCHEDULED).' AND ';
63
+    if (!$time){
64
+        $time = time();
65
+        $duplicate_where = ""; // ne pas dupliquer si deja le meme job en cours d'execution
66
+    }
67
+    $date = date('Y-m-d H:i:s',$time);
68
+
69
+    $set_job = array(
70
+        'fonction'=>$function,
71
+        'descriptif'=>$description,
72
+        'args'=>$arguments,
73
+        'md5args'=>$md5args,
74
+        'inclure'=>$file,
75
+        'priorite'=>max(-10,min(10,intval($priority))),
76
+        'date'=>$date,
77
+        'status'=>_JQ_SCHEDULED,
78
+    );
79
+    // si option ne pas dupliquer, regarder si la fonction existe deja
80
+    // avec les memes args et file
81
+    if (
82
+            $no_duplicate
83
+        AND
84
+            $id_job = sql_getfetsel('id_job','spip_jobs',
85
+                $duplicate_where =
86
+                    $duplicate_where . 'fonction='.sql_quote($function)
87
+                .(($no_duplicate==='function_only')?'':
88
+                 ' AND md5args='.sql_quote($md5args).' AND inclure='.sql_quote($file)))
89
+        )
90
+        return $id_job;
91
+
92
+    $id_job = sql_insertq('spip_jobs',$set_job);
93
+    // en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele
94
+    // avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand
95
+    // doit s'effacer
96
+    if (
97
+            $no_duplicate
98
+        AND
99
+            $id_prev = sql_getfetsel('id_job','spip_jobs',"id_job<".intval($id_job)." AND $duplicate_where")){
100
+        sql_delete('spip_jobs','id_job='.intval($id_job));
101
+        return $id_prev;
102
+    }
103
+
104
+    // verifier la non duplication qui peut etre problematique en cas de concurence
105
+    // il faut dans ce cas que seul le dernier ajoute se supprime !
106
+
107
+    // une option de debug pour verifier que les arguments en base sont bons
108
+    // ie cas d'un char non acceptables sur certains type de champs
109
+    // qui coupe la valeur
110
+    if (defined('_JQ_INSERT_CHECK_ARGS') AND $id_job) {
111
+        $args = sql_getfetsel('args', 'spip_jobs', 'id_job='.intval($id_job));
112
+        if ($args!==$arguments) {
113
+            spip_log('arguments job errones / longueur '.strlen($args)." vs ".strlen($arguments).' / valeur : '.var_export($arguments,true),'queue');
114
+        }
115
+    }
116
+
117
+    if ($id_job){
118
+        queue_update_next_job_time($time);
119
+    }
120
+    // si la mise en file d'attente du job echoue,
121
+    // il ne faut pas perdre l'execution de la fonction
122
+    // on la lance immediatement, c'est un fallback
123
+    // sauf en cas d'upgrade necessaire (table spip_jobs inexistante)
124
+    elseif($GLOBALS['meta']['version_installee']==$GLOBALS['spip_version_base']) {
125
+        $set_job['id_job'] = 0;
126
+        queue_start_job($set_job);
127
+    }
128
+
129
+    return $id_job;
130 130
 }
131 131
 
132 132
 /**
@@ -135,11 +135,11 @@  discard block
 block discarded – undo
135 135
  * @return void
136 136
  */
137 137
 function queue_purger(){
138
-	include_spip('base/abstract_sql');
139
-	sql_delete('spip_jobs');
140
-  sql_delete("spip_jobs_liens","id_job NOT IN (".sql_get_select("id_job","spip_jobs").")");
141
-  include_spip('inc/genie');
142
-  genie_queue_watch_dist();
138
+    include_spip('base/abstract_sql');
139
+    sql_delete('spip_jobs');
140
+    sql_delete("spip_jobs_liens","id_job NOT IN (".sql_get_select("id_job","spip_jobs").")");
141
+    include_spip('inc/genie');
142
+    genie_queue_watch_dist();
143 143
 }
144 144
 
145 145
 /**
@@ -149,21 +149,21 @@  discard block
 block discarded – undo
149 149
  * @return bool
150 150
  */
151 151
 function queue_remove_job($id_job){
152
-	include_spip('base/abstract_sql');
153
-
154
-	if ($row = sql_fetsel('fonction,inclure,date','spip_jobs','id_job='.intval($id_job))
155
-	 AND $res = sql_delete('spip_jobs','id_job='.intval($id_job))){
156
-		queue_unlink_job($id_job);
157
-		// est-ce une tache cron qu'il faut relancer ?
158
-		if ($periode = queue_is_cron_job($row['fonction'],$row['inclure'])){
159
-			// relancer avec les nouveaux arguments de temps
160
-			include_spip('inc/genie');
161
-			// relancer avec la periode prevue
162
-			queue_genie_replan_job($row['fonction'],$periode,strtotime($row['date']));
163
-		}
164
-		queue_update_next_job_time();
165
-	}
166
-	return $res;
152
+    include_spip('base/abstract_sql');
153
+
154
+    if ($row = sql_fetsel('fonction,inclure,date','spip_jobs','id_job='.intval($id_job))
155
+     AND $res = sql_delete('spip_jobs','id_job='.intval($id_job))){
156
+        queue_unlink_job($id_job);
157
+        // est-ce une tache cron qu'il faut relancer ?
158
+        if ($periode = queue_is_cron_job($row['fonction'],$row['inclure'])){
159
+            // relancer avec les nouveaux arguments de temps
160
+            include_spip('inc/genie');
161
+            // relancer avec la periode prevue
162
+            queue_genie_replan_job($row['fonction'],$periode,strtotime($row['date']));
163
+        }
164
+        queue_update_next_job_time();
165
+    }
166
+    return $res;
167 167
 }
168 168
 
169 169
 /**
@@ -176,18 +176,18 @@  discard block
 block discarded – undo
176 176
  *  or an array of simple array to link multiples objet in one time
177 177
  */
178 178
 function queue_link_job($id_job,$objets){
179
-	include_spip('base/abstract_sql');
180
-
181
-	if (is_array($objets) AND count($objets)){
182
-		if (is_array(reset($objets))){
183
-			foreach($objets as $k=>$o){
184
-				$objets[$k]['id_job'] = $id_job;
185
-			}
186
-			sql_insertq_multi('spip_jobs_liens',$objets);
187
-		}
188
-		else
189
-			sql_insertq('spip_jobs_liens',array_merge(array('id_job'=>$id_job),$objets));
190
-	}
179
+    include_spip('base/abstract_sql');
180
+
181
+    if (is_array($objets) AND count($objets)){
182
+        if (is_array(reset($objets))){
183
+            foreach($objets as $k=>$o){
184
+                $objets[$k]['id_job'] = $id_job;
185
+            }
186
+            sql_insertq_multi('spip_jobs_liens',$objets);
187
+        }
188
+        else
189
+            sql_insertq('spip_jobs_liens',array_merge(array('id_job'=>$id_job),$objets));
190
+    }
191 191
 }
192 192
 
193 193
 /**
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
  *	result of sql_delete
200 200
  */
201 201
 function queue_unlink_job($id_job){
202
-	return sql_delete("spip_jobs_liens","id_job=".intval($id_job));
202
+    return sql_delete("spip_jobs_liens","id_job=".intval($id_job));
203 203
 }
204 204
 
205 205
 /**
@@ -211,48 +211,48 @@  discard block
 block discarded – undo
211 211
  */
212 212
 function queue_start_job($row){
213 213
 
214
-	// deserialiser les arguments
215
-	$args = unserialize($row['args']);
216
-	if ($args===false){
217
-		spip_log('arguments job errones '.var_export($row,true),'queue');
218
-		$args = array();
219
-	}
220
-
221
-	$fonction = $row['fonction'];
222
-	if (strlen($inclure = trim($row['inclure']))){
223
-		if (substr($inclure,-1)=='/'){ // c'est un chemin pour charger_fonction
224
-			$f = charger_fonction($fonction,rtrim($inclure,'/'),false);
225
-			if ($f)
226
-				$fonction = $f;
227
-		}
228
-		else
229
-			include_spip($inclure);
230
-	}
231
-
232
-	if (!function_exists($fonction)){
233
-		spip_log("fonction $fonction ($inclure) inexistante ".var_export($row,true),'queue');
234
-		return false;
235
-	}
236
-
237
-	spip_log("queue [".$row['id_job']."]: $fonction() start", 'queue');
238
-	switch (count($args)) {
239
-		case 0:	$res = $fonction(); break;
240
-		case 1:	$res = $fonction($args[0]); break;
241
-		case 2:	$res = $fonction($args[0],$args[1]); break;
242
-		case 3:	$res = $fonction($args[0],$args[1], $args[2]); break;
243
-		case 4:	$res = $fonction($args[0],$args[1], $args[2], $args[3]); break;
244
-		case 5:	$res = $fonction($args[0],$args[1], $args[2], $args[3], $args[4]); break;
245
-		case 6:	$res = $fonction($args[0],$args[1], $args[2], $args[3], $args[4], $args[5]); break;
246
-		case 7:	$res = $fonction($args[0],$args[1], $args[2], $args[3], $args[4], $args[5], $args[6]); break;
247
-		case 8:	$res = $fonction($args[0],$args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]); break;
248
-		case 9:	$res = $fonction($args[0],$args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]); break;
249
-		case 10:$res = $fonction($args[0],$args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8], $args[9]); break;
250
-		default:
251
-			# plus lent mais completement generique
252
-			$res = call_user_func_array($fonction, $args);
253
-	}
254
-	spip_log("queue [".$row['id_job']."]: $fonction() end", 'queue');
255
-	return $res;
214
+    // deserialiser les arguments
215
+    $args = unserialize($row['args']);
216
+    if ($args===false){
217
+        spip_log('arguments job errones '.var_export($row,true),'queue');
218
+        $args = array();
219
+    }
220
+
221
+    $fonction = $row['fonction'];
222
+    if (strlen($inclure = trim($row['inclure']))){
223
+        if (substr($inclure,-1)=='/'){ // c'est un chemin pour charger_fonction
224
+            $f = charger_fonction($fonction,rtrim($inclure,'/'),false);
225
+            if ($f)
226
+                $fonction = $f;
227
+        }
228
+        else
229
+            include_spip($inclure);
230
+    }
231
+
232
+    if (!function_exists($fonction)){
233
+        spip_log("fonction $fonction ($inclure) inexistante ".var_export($row,true),'queue');
234
+        return false;
235
+    }
236
+
237
+    spip_log("queue [".$row['id_job']."]: $fonction() start", 'queue');
238
+    switch (count($args)) {
239
+        case 0:	$res = $fonction(); break;
240
+        case 1:	$res = $fonction($args[0]); break;
241
+        case 2:	$res = $fonction($args[0],$args[1]); break;
242
+        case 3:	$res = $fonction($args[0],$args[1], $args[2]); break;
243
+        case 4:	$res = $fonction($args[0],$args[1], $args[2], $args[3]); break;
244
+        case 5:	$res = $fonction($args[0],$args[1], $args[2], $args[3], $args[4]); break;
245
+        case 6:	$res = $fonction($args[0],$args[1], $args[2], $args[3], $args[4], $args[5]); break;
246
+        case 7:	$res = $fonction($args[0],$args[1], $args[2], $args[3], $args[4], $args[5], $args[6]); break;
247
+        case 8:	$res = $fonction($args[0],$args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]); break;
248
+        case 9:	$res = $fonction($args[0],$args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]); break;
249
+        case 10:$res = $fonction($args[0],$args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8], $args[9]); break;
250
+        default:
251
+            # plus lent mais completement generique
252
+            $res = call_user_func_array($fonction, $args);
253
+    }
254
+    spip_log("queue [".$row['id_job']."]: $fonction() end", 'queue');
255
+    return $res;
256 256
 
257 257
 }
258 258
 
@@ -271,82 +271,82 @@  discard block
 block discarded – undo
271 271
  * @return null|false
272 272
  */
273 273
 function queue_schedule($force_jobs = null){
274
-	$time = time();
275
-	if (defined('_DEBUG_BLOCK_QUEUE')) {
276
-		spip_log("_DEBUG_BLOCK_QUEUE : schedule stop",'jq'._LOG_DEBUG);
277
-		return;
278
-	}
279
-
280
-	// rien a faire si le prochain job est encore dans le futur
281
-	if (queue_sleep_time_to_next_job()>0 AND (!$force_jobs OR !count($force_jobs))){
282
-		spip_log("queue_sleep_time_to_next_job",'jq'._LOG_DEBUG);
283
-		return;
284
-	}
285
-
286
-	include_spip('base/abstract_sql');
287
-	// on ne peut rien faire si pas de connexion SQL
288
-	if (!spip_connect())  return false;
289
-
290
-	if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')){
291
-		$max_time = ini_get('max_execution_time')/2;
292
-		// valeur conservatrice si on a pas reussi a lire le max_execution_time
293
-		if (!$max_time) $max_time=5;
294
-		define('_JQ_MAX_JOBS_TIME_TO_EXECUTE',min($max_time,15)); // une valeur maxi en temps.
295
-	}
296
-	$end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE;
297
-
298
-	spip_log("JQ schedule $time / $end_time",'jq'._LOG_DEBUG);
299
-
300
-	if (!defined('_JQ_MAX_JOBS_EXECUTE'))
301
-		define('_JQ_MAX_JOBS_EXECUTE',200);
302
-	$nbj=0;
303
-	// attraper les jobs
304
-	// dont la date est passee (echus en attente),
305
-	// par odre :
306
-	//	- de priorite
307
-	//	- de date
308
-	// lorsqu'un job cron n'a pas fini, sa priorite est descendue
309
-	// pour qu'il ne bloque pas les autres jobs en attente
310
-	if (is_array($force_jobs) AND count($force_jobs))
311
-		$cond = "status=".intval(_JQ_SCHEDULED)." AND ".sql_in("id_job", $force_jobs);
312
-	else {
313
-		$now = date('Y-m-d H:i:s',$time);
314
-		$cond = "status=".intval(_JQ_SCHEDULED)." AND date<=".sql_quote($now);
315
-	}
316
-
317
-	register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible
318
-	$res = sql_allfetsel('*','spip_jobs',$cond,'','priorite DESC,date','0,'.(_JQ_MAX_JOBS_EXECUTE+1));
319
-	do {
320
-		if ($row = array_shift($res)){
321
-			$nbj++;
322
-			// il faut un verrou, a base de sql_delete
323
-			if (sql_delete('spip_jobs',"id_job=".intval($row['id_job'])." AND status=".intval(_JQ_SCHEDULED))){
324
-				#spip_log("JQ schedule job ".$nbj." OK",'jq');
325
-				// on reinsert dans la base aussitot avec un status=_JQ_PENDING
326
-				$row['status'] = _JQ_PENDING;
327
-				$row['date'] = date('Y-m-d H:i:s',$time);
328
-				sql_insertq('spip_jobs', $row);
329
-
330
-				// on a la main sur le job :
331
-				// l'executer
332
-				$result = queue_start_job($row);
333
-
334
-				$time = time();
335
-				queue_close_job($row, $time, $result);
336
-			}
337
-		}
338
-		spip_log("JQ schedule job end time ".$time,'jq'._LOG_DEBUG);
339
-	} while ($nbj<_JQ_MAX_JOBS_EXECUTE AND $row AND $time<$end_time);
340
-	spip_log("JQ schedule end time ".time(),'jq'._LOG_DEBUG);
341
-
342
-	if ($row = array_shift($res)){
343
-		queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP
344
-		spip_log("JQ encore !",'jq'._LOG_DEBUG);
345
-	}
346
-	else
347
-		queue_update_next_job_time();
348
-
349
-	return true;
274
+    $time = time();
275
+    if (defined('_DEBUG_BLOCK_QUEUE')) {
276
+        spip_log("_DEBUG_BLOCK_QUEUE : schedule stop",'jq'._LOG_DEBUG);
277
+        return;
278
+    }
279
+
280
+    // rien a faire si le prochain job est encore dans le futur
281
+    if (queue_sleep_time_to_next_job()>0 AND (!$force_jobs OR !count($force_jobs))){
282
+        spip_log("queue_sleep_time_to_next_job",'jq'._LOG_DEBUG);
283
+        return;
284
+    }
285
+
286
+    include_spip('base/abstract_sql');
287
+    // on ne peut rien faire si pas de connexion SQL
288
+    if (!spip_connect())  return false;
289
+
290
+    if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')){
291
+        $max_time = ini_get('max_execution_time')/2;
292
+        // valeur conservatrice si on a pas reussi a lire le max_execution_time
293
+        if (!$max_time) $max_time=5;
294
+        define('_JQ_MAX_JOBS_TIME_TO_EXECUTE',min($max_time,15)); // une valeur maxi en temps.
295
+    }
296
+    $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE;
297
+
298
+    spip_log("JQ schedule $time / $end_time",'jq'._LOG_DEBUG);
299
+
300
+    if (!defined('_JQ_MAX_JOBS_EXECUTE'))
301
+        define('_JQ_MAX_JOBS_EXECUTE',200);
302
+    $nbj=0;
303
+    // attraper les jobs
304
+    // dont la date est passee (echus en attente),
305
+    // par odre :
306
+    //	- de priorite
307
+    //	- de date
308
+    // lorsqu'un job cron n'a pas fini, sa priorite est descendue
309
+    // pour qu'il ne bloque pas les autres jobs en attente
310
+    if (is_array($force_jobs) AND count($force_jobs))
311
+        $cond = "status=".intval(_JQ_SCHEDULED)." AND ".sql_in("id_job", $force_jobs);
312
+    else {
313
+        $now = date('Y-m-d H:i:s',$time);
314
+        $cond = "status=".intval(_JQ_SCHEDULED)." AND date<=".sql_quote($now);
315
+    }
316
+
317
+    register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible
318
+    $res = sql_allfetsel('*','spip_jobs',$cond,'','priorite DESC,date','0,'.(_JQ_MAX_JOBS_EXECUTE+1));
319
+    do {
320
+        if ($row = array_shift($res)){
321
+            $nbj++;
322
+            // il faut un verrou, a base de sql_delete
323
+            if (sql_delete('spip_jobs',"id_job=".intval($row['id_job'])." AND status=".intval(_JQ_SCHEDULED))){
324
+                #spip_log("JQ schedule job ".$nbj." OK",'jq');
325
+                // on reinsert dans la base aussitot avec un status=_JQ_PENDING
326
+                $row['status'] = _JQ_PENDING;
327
+                $row['date'] = date('Y-m-d H:i:s',$time);
328
+                sql_insertq('spip_jobs', $row);
329
+
330
+                // on a la main sur le job :
331
+                // l'executer
332
+                $result = queue_start_job($row);
333
+
334
+                $time = time();
335
+                queue_close_job($row, $time, $result);
336
+            }
337
+        }
338
+        spip_log("JQ schedule job end time ".$time,'jq'._LOG_DEBUG);
339
+    } while ($nbj<_JQ_MAX_JOBS_EXECUTE AND $row AND $time<$end_time);
340
+    spip_log("JQ schedule end time ".time(),'jq'._LOG_DEBUG);
341
+
342
+    if ($row = array_shift($res)){
343
+        queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP
344
+        spip_log("JQ encore !",'jq'._LOG_DEBUG);
345
+    }
346
+    else
347
+        queue_update_next_job_time();
348
+
349
+    return true;
350 350
 }
351 351
 
352 352
 /**
@@ -360,21 +360,21 @@  discard block
 block discarded – undo
360 360
  * @param int $result
361 361
  */
362 362
 function queue_close_job(&$row,$time,$result=0){
363
-	// est-ce une tache cron qu'il faut relancer ?
364
-	if ($periode = queue_is_cron_job($row['fonction'],$row['inclure'])){
365
-		// relancer avec les nouveaux arguments de temps
366
-		include_spip('inc/genie');
367
-		if ($result<0)
368
-			// relancer tout de suite, mais en baissant la priorite
369
-			queue_genie_replan_job($row['fonction'],$periode,0-$result,null,$row['priorite']-1);
370
-		else
371
-			// relancer avec la periode prevue
372
-			queue_genie_replan_job($row['fonction'],$periode,$time);
373
-	}
374
-	// purger ses liens eventuels avec des objets
375
-	sql_delete("spip_jobs_liens","id_job=".intval($row['id_job']));
376
-	// supprimer le job fini
377
-	sql_delete('spip_jobs','id_job='.intval($row['id_job']));
363
+    // est-ce une tache cron qu'il faut relancer ?
364
+    if ($periode = queue_is_cron_job($row['fonction'],$row['inclure'])){
365
+        // relancer avec les nouveaux arguments de temps
366
+        include_spip('inc/genie');
367
+        if ($result<0)
368
+            // relancer tout de suite, mais en baissant la priorite
369
+            queue_genie_replan_job($row['fonction'],$periode,0-$result,null,$row['priorite']-1);
370
+        else
371
+            // relancer avec la periode prevue
372
+            queue_genie_replan_job($row['fonction'],$periode,$time);
373
+    }
374
+    // purger ses liens eventuels avec des objets
375
+    sql_delete("spip_jobs_liens","id_job=".intval($row['id_job']));
376
+    // supprimer le job fini
377
+    sql_delete('spip_jobs','id_job='.intval($row['id_job']));
378 378
 }
379 379
 
380 380
 /**
@@ -382,10 +382,10 @@  discard block
 block discarded – undo
382 382
  * en terminant la gestion de la queue
383 383
  */
384 384
 function queue_error_handler(){
385
-	// se remettre dans le bon dossier, car Apache le change parfois (toujours?)
386
-	chdir(_ROOT_CWD);
385
+    // se remettre dans le bon dossier, car Apache le change parfois (toujours?)
386
+    chdir(_ROOT_CWD);
387 387
 
388
-	queue_update_next_job_time();
388
+    queue_update_next_job_time();
389 389
 }
390 390
 
391 391
 
@@ -397,16 +397,16 @@  discard block
 block discarded – undo
397 397
  * @return <type>
398 398
  */
399 399
 function queue_is_cron_job($function,$inclure){
400
-	static $taches = null;
401
-	if (strncmp($inclure,'genie/',6)==0){
402
-		if (is_null($taches)){
403
-			include_spip('inc/genie');
404
-			$taches = taches_generales();
405
-		}
406
-		if (isset($taches[$function]))
407
-			return $taches[$function];
408
-	}
409
-	return false;
400
+    static $taches = null;
401
+    if (strncmp($inclure,'genie/',6)==0){
402
+        if (is_null($taches)){
403
+            include_spip('inc/genie');
404
+            $taches = taches_generales();
405
+        }
406
+        if (isset($taches[$function]))
407
+            return $taches[$function];
408
+    }
409
+    return false;
410 410
 }
411 411
 
412 412
 /**
@@ -420,48 +420,48 @@  discard block
 block discarded – undo
420 420
  *	temps de la tache ajoutee ou 0 pour ASAP
421 421
  */
422 422
 function queue_update_next_job_time($next_time=null){
423
-	static $nb_jobs_scheduled = null;
424
-	static $deja_la = false;
425
-	// prendre le min des $next_time que l'on voit passer ici, en cas de reentrance
426
-	static $next = null;
427
-	// queue_close_job peut etre reentrant ici
428
-	if ($deja_la) return;
429
-	$deja_la = true;
430
-
431
-	include_spip('base/abstract_sql');
432
-	$time = time();
433
-
434
-	// traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s)
435
-	// pour cause de timeout ou autre erreur fatale
436
-	$res = sql_allfetsel("*","spip_jobs","status=".intval(_JQ_PENDING)." AND date<".sql_quote(date('Y-m-d H:i:s',$time-180)));
437
-	if (is_array($res)) {
438
-		foreach ($res as $row)
439
-			queue_close_job($row,$time);
440
-	}
441
-
442
-	// chercher la date du prochain job si pas connu
443
-	if (is_null($next) OR is_null(queue_sleep_time_to_next_job())){
444
-		$date = sql_getfetsel('date','spip_jobs',"status=".intval(_JQ_SCHEDULED),'','date','0,1');
445
-		$next = strtotime($date);
446
-	}
447
-	if (!is_null($next_time)){
448
-		if (is_null($next) OR $next>$next_time)
449
-			$next = $next_time;
450
-	}
451
-
452
-		if ($next){
453
-			if (is_null($nb_jobs_scheduled))
454
-				$nb_jobs_scheduled = sql_countsel('spip_jobs',"status=".intval(_JQ_SCHEDULED)." AND date<".sql_quote(date('Y-m-d H:i:s',$time)));
455
-			elseif ($next<=$time)
456
-				$nb_jobs_scheduled++;
457
-			// si trop de jobs en attente, on force la purge en fin de hit
458
-			// pour assurer le coup
459
-			if ($nb_jobs_scheduled>defined('_JQ_NB_JOBS_OVERFLOW')?_JQ_NB_JOBS_OVERFLOW:10000)
460
-				define('_DIRECT_CRON_FORCE',true);
461
-		}
462
-
463
-	queue_set_next_job_time($next);
464
-	$deja_la = false;
423
+    static $nb_jobs_scheduled = null;
424
+    static $deja_la = false;
425
+    // prendre le min des $next_time que l'on voit passer ici, en cas de reentrance
426
+    static $next = null;
427
+    // queue_close_job peut etre reentrant ici
428
+    if ($deja_la) return;
429
+    $deja_la = true;
430
+
431
+    include_spip('base/abstract_sql');
432
+    $time = time();
433
+
434
+    // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s)
435
+    // pour cause de timeout ou autre erreur fatale
436
+    $res = sql_allfetsel("*","spip_jobs","status=".intval(_JQ_PENDING)." AND date<".sql_quote(date('Y-m-d H:i:s',$time-180)));
437
+    if (is_array($res)) {
438
+        foreach ($res as $row)
439
+            queue_close_job($row,$time);
440
+    }
441
+
442
+    // chercher la date du prochain job si pas connu
443
+    if (is_null($next) OR is_null(queue_sleep_time_to_next_job())){
444
+        $date = sql_getfetsel('date','spip_jobs',"status=".intval(_JQ_SCHEDULED),'','date','0,1');
445
+        $next = strtotime($date);
446
+    }
447
+    if (!is_null($next_time)){
448
+        if (is_null($next) OR $next>$next_time)
449
+            $next = $next_time;
450
+    }
451
+
452
+        if ($next){
453
+            if (is_null($nb_jobs_scheduled))
454
+                $nb_jobs_scheduled = sql_countsel('spip_jobs',"status=".intval(_JQ_SCHEDULED)." AND date<".sql_quote(date('Y-m-d H:i:s',$time)));
455
+            elseif ($next<=$time)
456
+                $nb_jobs_scheduled++;
457
+            // si trop de jobs en attente, on force la purge en fin de hit
458
+            // pour assurer le coup
459
+            if ($nb_jobs_scheduled>defined('_JQ_NB_JOBS_OVERFLOW')?_JQ_NB_JOBS_OVERFLOW:10000)
460
+                define('_DIRECT_CRON_FORCE',true);
461
+        }
462
+
463
+    queue_set_next_job_time($next);
464
+    $deja_la = false;
465 465
 }
466 466
 
467 467
 
@@ -471,27 +471,27 @@  discard block
 block discarded – undo
471 471
  */
472 472
 function queue_set_next_job_time($next) {
473 473
 
474
-	// utiliser le temps courant reel plutot que temps de la requete ici
475
-	$time = time();
476
-
477
-	// toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes
478
-	// et ne mettre a jour que si il y a un interet a le faire
479
-	// permet ausis d'initialiser le nom de fichier a coup sur
480
-	$curr_next = $_SERVER['REQUEST_TIME'] + max(0,queue_sleep_time_to_next_job(true));
481
-	if (
482
-			($curr_next<=$time AND $next>$time) // le prochain job est dans le futur mais pas la date planifiee actuelle
483
-			OR $curr_next>$next // le prochain job est plus tot que la date planifiee actuelle
484
-		) {
485
-		if (include_spip('inc/memoization') AND defined('_MEMOIZE_MEMORY') AND _MEMOIZE_MEMORY) {
486
-			cache_set(_JQ_NEXT_JOB_TIME_FILENAME,intval($next));
487
-		}
488
-		else {
489
-			ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME,intval($next));
490
-		}
491
-		queue_sleep_time_to_next_job($next);
492
-	}
493
-
494
-	return queue_sleep_time_to_next_job();
474
+    // utiliser le temps courant reel plutot que temps de la requete ici
475
+    $time = time();
476
+
477
+    // toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes
478
+    // et ne mettre a jour que si il y a un interet a le faire
479
+    // permet ausis d'initialiser le nom de fichier a coup sur
480
+    $curr_next = $_SERVER['REQUEST_TIME'] + max(0,queue_sleep_time_to_next_job(true));
481
+    if (
482
+            ($curr_next<=$time AND $next>$time) // le prochain job est dans le futur mais pas la date planifiee actuelle
483
+            OR $curr_next>$next // le prochain job est plus tot que la date planifiee actuelle
484
+        ) {
485
+        if (include_spip('inc/memoization') AND defined('_MEMOIZE_MEMORY') AND _MEMOIZE_MEMORY) {
486
+            cache_set(_JQ_NEXT_JOB_TIME_FILENAME,intval($next));
487
+        }
488
+        else {
489
+            ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME,intval($next));
490
+        }
491
+        queue_sleep_time_to_next_job($next);
492
+    }
493
+
494
+    return queue_sleep_time_to_next_job();
495 495
 }
496 496
 
497 497
 /**
@@ -503,110 +503,110 @@  discard block
 block discarded – undo
503 503
  * @return string
504 504
  */
505 505
 function queue_affichage_cron(){
506
-	$texte = "";
507
-
508
-	$time_to_next = queue_sleep_time_to_next_job();
509
-	// rien a faire si le prochain job est encore dans le futur
510
-	if ($time_to_next>0 OR defined('_DEBUG_BLOCK_QUEUE'))
511
-		return $texte;
512
-
513
-	// ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent
514
-	if (file_exists($lock=_DIR_TMP."cron.lock") AND !(@filemtime($lock)<$_SERVER['REQUEST_TIME']))
515
-		return $texte;
516
-	@touch($lock);
517
-
518
-	// il y a des taches en attentes
519
-	// si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup
520
-	// on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic
521
-	$urgent = false;
522
-	if ($time_to_next<-300)
523
-		$urgent = true;
524
-
525
-	$url_cron = generer_url_action('cron','',false,true);
526
-
527
-	if (!defined('_HTML_BG_CRON_FORCE') OR !_HTML_BG_CRON_FORCE){
528
-
529
-		// methode la plus rapide :
530
-		// Si fsockopen est possible, on lance le cron via un socket en asynchrone
531
-		// si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL
532
-		// car on a toutes les chances d'echouer pareil mais sans moyen de le savoir
533
-		// on passe direct a la methode background-image
534
-		if(function_exists('fsockopen')){
535
-			$parts=parse_url($url_cron);
536
-
537
-			switch ($parts['scheme']) {
538
-				case 'https':
539
-					$scheme = 'ssl://';
540
-					$port = 443;
541
-					break;
542
-				case 'http':
543
-				default:
544
-					$scheme = '';
545
-					$port = 80;
546
-			}
547
-
548
-			$fp = @fsockopen($scheme.$parts['host'],
549
-		        isset($parts['port'])?$parts['port']:$port,
550
-		        $errno, $errstr, 1);
551
-
552
-			if ($fp) {
553
-				$timeout = 200; // ms
554
-				stream_set_timeout($fp,0,$timeout * 1000);
555
-				$query = $parts['path'].($parts['query']?"?".$parts['query']:"");
556
-				$out = "GET ".$query." HTTP/1.1\r\n";
557
-				$out.= "Host: ".$parts['host']."\r\n";
558
-				$out.= "Connection: Close\r\n\r\n";
559
-				fwrite($fp, $out);
560
-				spip_timer('read');
561
-				$t = 0;
562
-				// on lit la reponse si possible pour fermer proprement la connexion
563
-				// avec un timeout total de 200ms pour ne pas se bloquer
564
-				while (!feof($fp) AND $t<$timeout) {
565
-					@fgets($fp, 1024);
566
-					$t += spip_timer('read',true);
567
-					spip_timer('read');
568
-				}
569
-				fclose($fp);
570
-				if (!$urgent)
571
-					return $texte;
572
-			}
573
-		}
574
-		// si fsockopen n'est pas dispo on essaye cURL :
575
-		// lancer le cron par un cURL asynchrone si cURL est present
576
-		elseif (function_exists("curl_init")){
577
-			//setting the curl parameters.
578
-			$ch = curl_init($url_cron);
579
-			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
580
-			// cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597
581
-			curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
582
-			// valeur mini pour que la requete soit lancee
583
-			curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200);
584
-			// lancer
585
-			curl_exec($ch);
586
-			// fermer
587
-			curl_close($ch);
588
-			if (!$urgent)
589
-				return $texte;
590
-		}
591
-	}
592
-
593
-	// si deja force, on retourne sans rien
594
-	if (defined('_DIRECT_CRON_FORCE'))
595
-		return $texte;
596
-
597
-	// si c'est un bot
598
-	// inutile de faire un appel par image background,
599
-	// on force un appel direct en fin de hit
600
-	if ((defined('_IS_BOT') AND _IS_BOT)){
601
-		define('_DIRECT_CRON_FORCE',true);
602
-		return $texte;
603
-	}
604
-
605
-	// en derniere solution, on insere une image background dans la page
606
-	$texte = '<!-- SPIP-CRON --><div style="background-image: url(\'' .
607
-		generer_url_action('cron') .
608
-		'\');"></div>';
609
-
610
-	return $texte;
506
+    $texte = "";
507
+
508
+    $time_to_next = queue_sleep_time_to_next_job();
509
+    // rien a faire si le prochain job est encore dans le futur
510
+    if ($time_to_next>0 OR defined('_DEBUG_BLOCK_QUEUE'))
511
+        return $texte;
512
+
513
+    // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent
514
+    if (file_exists($lock=_DIR_TMP."cron.lock") AND !(@filemtime($lock)<$_SERVER['REQUEST_TIME']))
515
+        return $texte;
516
+    @touch($lock);
517
+
518
+    // il y a des taches en attentes
519
+    // si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup
520
+    // on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic
521
+    $urgent = false;
522
+    if ($time_to_next<-300)
523
+        $urgent = true;
524
+
525
+    $url_cron = generer_url_action('cron','',false,true);
526
+
527
+    if (!defined('_HTML_BG_CRON_FORCE') OR !_HTML_BG_CRON_FORCE){
528
+
529
+        // methode la plus rapide :
530
+        // Si fsockopen est possible, on lance le cron via un socket en asynchrone
531
+        // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL
532
+        // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir
533
+        // on passe direct a la methode background-image
534
+        if(function_exists('fsockopen')){
535
+            $parts=parse_url($url_cron);
536
+
537
+            switch ($parts['scheme']) {
538
+                case 'https':
539
+                    $scheme = 'ssl://';
540
+                    $port = 443;
541
+                    break;
542
+                case 'http':
543
+                default:
544
+                    $scheme = '';
545
+                    $port = 80;
546
+            }
547
+
548
+            $fp = @fsockopen($scheme.$parts['host'],
549
+                isset($parts['port'])?$parts['port']:$port,
550
+                $errno, $errstr, 1);
551
+
552
+            if ($fp) {
553
+                $timeout = 200; // ms
554
+                stream_set_timeout($fp,0,$timeout * 1000);
555
+                $query = $parts['path'].($parts['query']?"?".$parts['query']:"");
556
+                $out = "GET ".$query." HTTP/1.1\r\n";
557
+                $out.= "Host: ".$parts['host']."\r\n";
558
+                $out.= "Connection: Close\r\n\r\n";
559
+                fwrite($fp, $out);
560
+                spip_timer('read');
561
+                $t = 0;
562
+                // on lit la reponse si possible pour fermer proprement la connexion
563
+                // avec un timeout total de 200ms pour ne pas se bloquer
564
+                while (!feof($fp) AND $t<$timeout) {
565
+                    @fgets($fp, 1024);
566
+                    $t += spip_timer('read',true);
567
+                    spip_timer('read');
568
+                }
569
+                fclose($fp);
570
+                if (!$urgent)
571
+                    return $texte;
572
+            }
573
+        }
574
+        // si fsockopen n'est pas dispo on essaye cURL :
575
+        // lancer le cron par un cURL asynchrone si cURL est present
576
+        elseif (function_exists("curl_init")){
577
+            //setting the curl parameters.
578
+            $ch = curl_init($url_cron);
579
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
580
+            // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597
581
+            curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
582
+            // valeur mini pour que la requete soit lancee
583
+            curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200);
584
+            // lancer
585
+            curl_exec($ch);
586
+            // fermer
587
+            curl_close($ch);
588
+            if (!$urgent)
589
+                return $texte;
590
+        }
591
+    }
592
+
593
+    // si deja force, on retourne sans rien
594
+    if (defined('_DIRECT_CRON_FORCE'))
595
+        return $texte;
596
+
597
+    // si c'est un bot
598
+    // inutile de faire un appel par image background,
599
+    // on force un appel direct en fin de hit
600
+    if ((defined('_IS_BOT') AND _IS_BOT)){
601
+        define('_DIRECT_CRON_FORCE',true);
602
+        return $texte;
603
+    }
604
+
605
+    // en derniere solution, on insere une image background dans la page
606
+    $texte = '<!-- SPIP-CRON --><div style="background-image: url(\'' .
607
+        generer_url_action('cron') .
608
+        '\');"></div>';
609
+
610
+    return $texte;
611 611
 }
612 612
 ?>
Please login to merge, or discard this patch.
Spacing   +117 added lines, -118 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 **/
18 18
 if (!defined("_ECRIRE_INC_VERSION")) return;
19 19
 
20
-define('_JQ_SCHEDULED',1);
21
-define('_JQ_PENDING',0);
20
+define('_JQ_SCHEDULED', 1);
21
+define('_JQ_PENDING', 0);
22 22
 #define('_JQ_MAX_JOBS_EXECUTE',200); // pour personaliser le nombre de jobs traitables a chaque hit
23 23
 #define('_JQ_MAX_JOBS_TIME_TO_EXECUTE',15); // pour personaliser le temps d'excution dispo a chaque hit
24 24
 #define('_JQ_NB_JOBS_OVERFLOW',10000); // nombre de jobs a partir duquel on force le traitement en fin de hit pour purger
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
  * @return int
48 48
  *	id of job
49 49
  */
50
-function queue_add_job($function, $description, $arguments = array(), $file = '', $no_duplicate = false, $time=0, $priority=0){
50
+function queue_add_job($function, $description, $arguments = array(), $file = '', $no_duplicate = false, $time = 0, $priority = 0) {
51 51
 	include_spip('base/abstract_sql');
52 52
 
53 53
 	// cas pourri de ecrire/action/editer_site avec l'option reload=oui
@@ -60,11 +60,11 @@  discard block
 block discarded – undo
60 60
 
61 61
 	// si pas de date programee, des que possible
62 62
 	$duplicate_where = 'status='.intval(_JQ_SCHEDULED).' AND ';
63
-	if (!$time){
63
+	if (!$time) {
64 64
 		$time = time();
65 65
 		$duplicate_where = ""; // ne pas dupliquer si deja le meme job en cours d'execution
66 66
 	}
67
-	$date = date('Y-m-d H:i:s',$time);
67
+	$date = date('Y-m-d H:i:s', $time);
68 68
 
69 69
 	$set_job = array(
70 70
 		'fonction'=>$function,
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 		'args'=>$arguments,
73 73
 		'md5args'=>$md5args,
74 74
 		'inclure'=>$file,
75
-		'priorite'=>max(-10,min(10,intval($priority))),
75
+		'priorite'=>max(-10, min(10, intval($priority))),
76 76
 		'date'=>$date,
77 77
 		'status'=>_JQ_SCHEDULED,
78 78
 	);
@@ -81,23 +81,22 @@  discard block
 block discarded – undo
81 81
 	if (
82 82
 			$no_duplicate
83 83
 		AND
84
-			$id_job = sql_getfetsel('id_job','spip_jobs',
84
+			$id_job = sql_getfetsel('id_job', 'spip_jobs',
85 85
 				$duplicate_where =
86
-					$duplicate_where . 'fonction='.sql_quote($function)
87
-				.(($no_duplicate==='function_only')?'':
88
-				 ' AND md5args='.sql_quote($md5args).' AND inclure='.sql_quote($file)))
86
+					$duplicate_where.'fonction='.sql_quote($function)
87
+				.(($no_duplicate === 'function_only') ? '' : ' AND md5args='.sql_quote($md5args).' AND inclure='.sql_quote($file)))
89 88
 		)
90 89
 		return $id_job;
91 90
 
92
-	$id_job = sql_insertq('spip_jobs',$set_job);
91
+	$id_job = sql_insertq('spip_jobs', $set_job);
93 92
 	// en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele
94 93
 	// avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand
95 94
 	// doit s'effacer
96 95
 	if (
97 96
 			$no_duplicate
98 97
 		AND
99
-			$id_prev = sql_getfetsel('id_job','spip_jobs',"id_job<".intval($id_job)." AND $duplicate_where")){
100
-		sql_delete('spip_jobs','id_job='.intval($id_job));
98
+			$id_prev = sql_getfetsel('id_job', 'spip_jobs', "id_job<".intval($id_job)." AND $duplicate_where")) {
99
+		sql_delete('spip_jobs', 'id_job='.intval($id_job));
101 100
 		return $id_prev;
102 101
 	}
103 102
 
@@ -109,19 +108,19 @@  discard block
 block discarded – undo
109 108
 	// qui coupe la valeur
110 109
 	if (defined('_JQ_INSERT_CHECK_ARGS') AND $id_job) {
111 110
 		$args = sql_getfetsel('args', 'spip_jobs', 'id_job='.intval($id_job));
112
-		if ($args!==$arguments) {
113
-			spip_log('arguments job errones / longueur '.strlen($args)." vs ".strlen($arguments).' / valeur : '.var_export($arguments,true),'queue');
111
+		if ($args !== $arguments) {
112
+			spip_log('arguments job errones / longueur '.strlen($args)." vs ".strlen($arguments).' / valeur : '.var_export($arguments, true), 'queue');
114 113
 		}
115 114
 	}
116 115
 
117
-	if ($id_job){
116
+	if ($id_job) {
118 117
 		queue_update_next_job_time($time);
119 118
 	}
120 119
 	// si la mise en file d'attente du job echoue,
121 120
 	// il ne faut pas perdre l'execution de la fonction
122 121
 	// on la lance immediatement, c'est un fallback
123 122
 	// sauf en cas d'upgrade necessaire (table spip_jobs inexistante)
124
-	elseif($GLOBALS['meta']['version_installee']==$GLOBALS['spip_version_base']) {
123
+	elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) {
125 124
 		$set_job['id_job'] = 0;
126 125
 		queue_start_job($set_job);
127 126
 	}
@@ -134,10 +133,10 @@  discard block
 block discarded – undo
134 133
  * 
135 134
  * @return void
136 135
  */
137
-function queue_purger(){
136
+function queue_purger() {
138 137
 	include_spip('base/abstract_sql');
139 138
 	sql_delete('spip_jobs');
140
-  sql_delete("spip_jobs_liens","id_job NOT IN (".sql_get_select("id_job","spip_jobs").")");
139
+  sql_delete("spip_jobs_liens", "id_job NOT IN (".sql_get_select("id_job", "spip_jobs").")");
141 140
   include_spip('inc/genie');
142 141
   genie_queue_watch_dist();
143 142
 }
@@ -148,18 +147,18 @@  discard block
 block discarded – undo
148 147
  *  id de la tache a retirer
149 148
  * @return bool
150 149
  */
151
-function queue_remove_job($id_job){
150
+function queue_remove_job($id_job) {
152 151
 	include_spip('base/abstract_sql');
153 152
 
154
-	if ($row = sql_fetsel('fonction,inclure,date','spip_jobs','id_job='.intval($id_job))
155
-	 AND $res = sql_delete('spip_jobs','id_job='.intval($id_job))){
153
+	if ($row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job='.intval($id_job))
154
+	 AND $res = sql_delete('spip_jobs', 'id_job='.intval($id_job))) {
156 155
 		queue_unlink_job($id_job);
157 156
 		// est-ce une tache cron qu'il faut relancer ?
158
-		if ($periode = queue_is_cron_job($row['fonction'],$row['inclure'])){
157
+		if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) {
159 158
 			// relancer avec les nouveaux arguments de temps
160 159
 			include_spip('inc/genie');
161 160
 			// relancer avec la periode prevue
162
-			queue_genie_replan_job($row['fonction'],$periode,strtotime($row['date']));
161
+			queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date']));
163 162
 		}
164 163
 		queue_update_next_job_time();
165 164
 	}
@@ -175,18 +174,18 @@  discard block
 block discarded – undo
175 174
  *  can be a simple array('objet'=>'article','id_objet'=>23)
176 175
  *  or an array of simple array to link multiples objet in one time
177 176
  */
178
-function queue_link_job($id_job,$objets){
177
+function queue_link_job($id_job, $objets) {
179 178
 	include_spip('base/abstract_sql');
180 179
 
181
-	if (is_array($objets) AND count($objets)){
182
-		if (is_array(reset($objets))){
183
-			foreach($objets as $k=>$o){
180
+	if (is_array($objets) AND count($objets)) {
181
+		if (is_array(reset($objets))) {
182
+			foreach ($objets as $k=>$o) {
184 183
 				$objets[$k]['id_job'] = $id_job;
185 184
 			}
186
-			sql_insertq_multi('spip_jobs_liens',$objets);
185
+			sql_insertq_multi('spip_jobs_liens', $objets);
187 186
 		}
188 187
 		else
189
-			sql_insertq('spip_jobs_liens',array_merge(array('id_job'=>$id_job),$objets));
188
+			sql_insertq('spip_jobs_liens', array_merge(array('id_job'=>$id_job), $objets));
190 189
 	}
191 190
 }
192 191
 
@@ -198,8 +197,8 @@  discard block
 block discarded – undo
198 197
  * @return int/bool
199 198
  *	result of sql_delete
200 199
  */
201
-function queue_unlink_job($id_job){
202
-	return sql_delete("spip_jobs_liens","id_job=".intval($id_job));
200
+function queue_unlink_job($id_job) {
201
+	return sql_delete("spip_jobs_liens", "id_job=".intval($id_job));
203 202
 }
204 203
 
205 204
 /**
@@ -209,19 +208,19 @@  discard block
 block discarded – undo
209 208
  * @return mixed
210 209
  *	return the result of job
211 210
  */
212
-function queue_start_job($row){
211
+function queue_start_job($row) {
213 212
 
214 213
 	// deserialiser les arguments
215 214
 	$args = unserialize($row['args']);
216
-	if ($args===false){
217
-		spip_log('arguments job errones '.var_export($row,true),'queue');
215
+	if ($args === false) {
216
+		spip_log('arguments job errones '.var_export($row, true), 'queue');
218 217
 		$args = array();
219 218
 	}
220 219
 
221 220
 	$fonction = $row['fonction'];
222
-	if (strlen($inclure = trim($row['inclure']))){
223
-		if (substr($inclure,-1)=='/'){ // c'est un chemin pour charger_fonction
224
-			$f = charger_fonction($fonction,rtrim($inclure,'/'),false);
221
+	if (strlen($inclure = trim($row['inclure']))) {
222
+		if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction
223
+			$f = charger_fonction($fonction, rtrim($inclure, '/'), false);
225 224
 			if ($f)
226 225
 				$fonction = $f;
227 226
 		}
@@ -229,8 +228,8 @@  discard block
 block discarded – undo
229 228
 			include_spip($inclure);
230 229
 	}
231 230
 
232
-	if (!function_exists($fonction)){
233
-		spip_log("fonction $fonction ($inclure) inexistante ".var_export($row,true),'queue');
231
+	if (!function_exists($fonction)) {
232
+		spip_log("fonction $fonction ($inclure) inexistante ".var_export($row, true), 'queue');
234 233
 		return false;
235 234
 	}
236 235
 
@@ -238,15 +237,15 @@  discard block
 block discarded – undo
238 237
 	switch (count($args)) {
239 238
 		case 0:	$res = $fonction(); break;
240 239
 		case 1:	$res = $fonction($args[0]); break;
241
-		case 2:	$res = $fonction($args[0],$args[1]); break;
242
-		case 3:	$res = $fonction($args[0],$args[1], $args[2]); break;
243
-		case 4:	$res = $fonction($args[0],$args[1], $args[2], $args[3]); break;
244
-		case 5:	$res = $fonction($args[0],$args[1], $args[2], $args[3], $args[4]); break;
245
-		case 6:	$res = $fonction($args[0],$args[1], $args[2], $args[3], $args[4], $args[5]); break;
246
-		case 7:	$res = $fonction($args[0],$args[1], $args[2], $args[3], $args[4], $args[5], $args[6]); break;
247
-		case 8:	$res = $fonction($args[0],$args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]); break;
248
-		case 9:	$res = $fonction($args[0],$args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]); break;
249
-		case 10:$res = $fonction($args[0],$args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8], $args[9]); break;
240
+		case 2:	$res = $fonction($args[0], $args[1]); break;
241
+		case 3:	$res = $fonction($args[0], $args[1], $args[2]); break;
242
+		case 4:	$res = $fonction($args[0], $args[1], $args[2], $args[3]); break;
243
+		case 5:	$res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4]); break;
244
+		case 6:	$res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); break;
245
+		case 7:	$res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]); break;
246
+		case 8:	$res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]); break;
247
+		case 9:	$res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]); break;
248
+		case 10:$res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8], $args[9]); break;
250 249
 		default:
251 250
 			# plus lent mais completement generique
252 251
 			$res = call_user_func_array($fonction, $args);
@@ -270,16 +269,16 @@  discard block
 block discarded – undo
270 269
  *   list of id_job to execute when provided
271 270
  * @return null|false
272 271
  */
273
-function queue_schedule($force_jobs = null){
272
+function queue_schedule($force_jobs = null) {
274 273
 	$time = time();
275 274
 	if (defined('_DEBUG_BLOCK_QUEUE')) {
276
-		spip_log("_DEBUG_BLOCK_QUEUE : schedule stop",'jq'._LOG_DEBUG);
275
+		spip_log("_DEBUG_BLOCK_QUEUE : schedule stop", 'jq'._LOG_DEBUG);
277 276
 		return;
278 277
 	}
279 278
 
280 279
 	// rien a faire si le prochain job est encore dans le futur
281
-	if (queue_sleep_time_to_next_job()>0 AND (!$force_jobs OR !count($force_jobs))){
282
-		spip_log("queue_sleep_time_to_next_job",'jq'._LOG_DEBUG);
280
+	if (queue_sleep_time_to_next_job() > 0 AND (!$force_jobs OR !count($force_jobs))) {
281
+		spip_log("queue_sleep_time_to_next_job", 'jq'._LOG_DEBUG);
283 282
 		return;
284 283
 	}
285 284
 
@@ -287,19 +286,19 @@  discard block
 block discarded – undo
287 286
 	// on ne peut rien faire si pas de connexion SQL
288 287
 	if (!spip_connect())  return false;
289 288
 
290
-	if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')){
291
-		$max_time = ini_get('max_execution_time')/2;
289
+	if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) {
290
+		$max_time = ini_get('max_execution_time') / 2;
292 291
 		// valeur conservatrice si on a pas reussi a lire le max_execution_time
293
-		if (!$max_time) $max_time=5;
294
-		define('_JQ_MAX_JOBS_TIME_TO_EXECUTE',min($max_time,15)); // une valeur maxi en temps.
292
+		if (!$max_time) $max_time = 5;
293
+		define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps.
295 294
 	}
296 295
 	$end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE;
297 296
 
298
-	spip_log("JQ schedule $time / $end_time",'jq'._LOG_DEBUG);
297
+	spip_log("JQ schedule $time / $end_time", 'jq'._LOG_DEBUG);
299 298
 
300 299
 	if (!defined('_JQ_MAX_JOBS_EXECUTE'))
301
-		define('_JQ_MAX_JOBS_EXECUTE',200);
302
-	$nbj=0;
300
+		define('_JQ_MAX_JOBS_EXECUTE', 200);
301
+	$nbj = 0;
303 302
 	// attraper les jobs
304 303
 	// dont la date est passee (echus en attente),
305 304
 	// par odre :
@@ -310,21 +309,21 @@  discard block
 block discarded – undo
310 309
 	if (is_array($force_jobs) AND count($force_jobs))
311 310
 		$cond = "status=".intval(_JQ_SCHEDULED)." AND ".sql_in("id_job", $force_jobs);
312 311
 	else {
313
-		$now = date('Y-m-d H:i:s',$time);
312
+		$now = date('Y-m-d H:i:s', $time);
314 313
 		$cond = "status=".intval(_JQ_SCHEDULED)." AND date<=".sql_quote($now);
315 314
 	}
316 315
 
317 316
 	register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible
318
-	$res = sql_allfetsel('*','spip_jobs',$cond,'','priorite DESC,date','0,'.(_JQ_MAX_JOBS_EXECUTE+1));
317
+	$res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,'.(_JQ_MAX_JOBS_EXECUTE + 1));
319 318
 	do {
320
-		if ($row = array_shift($res)){
319
+		if ($row = array_shift($res)) {
321 320
 			$nbj++;
322 321
 			// il faut un verrou, a base de sql_delete
323
-			if (sql_delete('spip_jobs',"id_job=".intval($row['id_job'])." AND status=".intval(_JQ_SCHEDULED))){
322
+			if (sql_delete('spip_jobs', "id_job=".intval($row['id_job'])." AND status=".intval(_JQ_SCHEDULED))) {
324 323
 				#spip_log("JQ schedule job ".$nbj." OK",'jq');
325 324
 				// on reinsert dans la base aussitot avec un status=_JQ_PENDING
326 325
 				$row['status'] = _JQ_PENDING;
327
-				$row['date'] = date('Y-m-d H:i:s',$time);
326
+				$row['date'] = date('Y-m-d H:i:s', $time);
328 327
 				sql_insertq('spip_jobs', $row);
329 328
 
330 329
 				// on a la main sur le job :
@@ -335,13 +334,13 @@  discard block
 block discarded – undo
335 334
 				queue_close_job($row, $time, $result);
336 335
 			}
337 336
 		}
338
-		spip_log("JQ schedule job end time ".$time,'jq'._LOG_DEBUG);
339
-	} while ($nbj<_JQ_MAX_JOBS_EXECUTE AND $row AND $time<$end_time);
340
-	spip_log("JQ schedule end time ".time(),'jq'._LOG_DEBUG);
337
+		spip_log("JQ schedule job end time ".$time, 'jq'._LOG_DEBUG);
338
+	} while ($nbj < _JQ_MAX_JOBS_EXECUTE AND $row AND $time < $end_time);
339
+	spip_log("JQ schedule end time ".time(), 'jq'._LOG_DEBUG);
341 340
 
342
-	if ($row = array_shift($res)){
341
+	if ($row = array_shift($res)) {
343 342
 		queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP
344
-		spip_log("JQ encore !",'jq'._LOG_DEBUG);
343
+		spip_log("JQ encore !", 'jq'._LOG_DEBUG);
345 344
 	}
346 345
 	else
347 346
 		queue_update_next_job_time();
@@ -359,29 +358,29 @@  discard block
 block discarded – undo
359 358
  * @param int $time
360 359
  * @param int $result
361 360
  */
362
-function queue_close_job(&$row,$time,$result=0){
361
+function queue_close_job(&$row, $time, $result = 0) {
363 362
 	// est-ce une tache cron qu'il faut relancer ?
364
-	if ($periode = queue_is_cron_job($row['fonction'],$row['inclure'])){
363
+	if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) {
365 364
 		// relancer avec les nouveaux arguments de temps
366 365
 		include_spip('inc/genie');
367
-		if ($result<0)
366
+		if ($result < 0)
368 367
 			// relancer tout de suite, mais en baissant la priorite
369
-			queue_genie_replan_job($row['fonction'],$periode,0-$result,null,$row['priorite']-1);
368
+			queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1);
370 369
 		else
371 370
 			// relancer avec la periode prevue
372
-			queue_genie_replan_job($row['fonction'],$periode,$time);
371
+			queue_genie_replan_job($row['fonction'], $periode, $time);
373 372
 	}
374 373
 	// purger ses liens eventuels avec des objets
375
-	sql_delete("spip_jobs_liens","id_job=".intval($row['id_job']));
374
+	sql_delete("spip_jobs_liens", "id_job=".intval($row['id_job']));
376 375
 	// supprimer le job fini
377
-	sql_delete('spip_jobs','id_job='.intval($row['id_job']));
376
+	sql_delete('spip_jobs', 'id_job='.intval($row['id_job']));
378 377
 }
379 378
 
380 379
 /**
381 380
  * Recuperer des erreurs auant que possible
382 381
  * en terminant la gestion de la queue
383 382
  */
384
-function queue_error_handler(){
383
+function queue_error_handler() {
385 384
 	// se remettre dans le bon dossier, car Apache le change parfois (toujours?)
386 385
 	chdir(_ROOT_CWD);
387 386
 
@@ -396,10 +395,10 @@  discard block
 block discarded – undo
396 395
  * @param <type> $inclure
397 396
  * @return <type>
398 397
  */
399
-function queue_is_cron_job($function,$inclure){
398
+function queue_is_cron_job($function, $inclure) {
400 399
 	static $taches = null;
401
-	if (strncmp($inclure,'genie/',6)==0){
402
-		if (is_null($taches)){
400
+	if (strncmp($inclure, 'genie/', 6) == 0) {
401
+		if (is_null($taches)) {
403 402
 			include_spip('inc/genie');
404 403
 			$taches = taches_generales();
405 404
 		}
@@ -419,7 +418,7 @@  discard block
 block discarded – undo
419 418
  * @param int $next_time
420 419
  *	temps de la tache ajoutee ou 0 pour ASAP
421 420
  */
422
-function queue_update_next_job_time($next_time=null){
421
+function queue_update_next_job_time($next_time = null) {
423 422
 	static $nb_jobs_scheduled = null;
424 423
 	static $deja_la = false;
425 424
 	// prendre le min des $next_time que l'on voit passer ici, en cas de reentrance
@@ -433,31 +432,31 @@  discard block
 block discarded – undo
433 432
 
434 433
 	// traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s)
435 434
 	// pour cause de timeout ou autre erreur fatale
436
-	$res = sql_allfetsel("*","spip_jobs","status=".intval(_JQ_PENDING)." AND date<".sql_quote(date('Y-m-d H:i:s',$time-180)));
435
+	$res = sql_allfetsel("*", "spip_jobs", "status=".intval(_JQ_PENDING)." AND date<".sql_quote(date('Y-m-d H:i:s', $time - 180)));
437 436
 	if (is_array($res)) {
438 437
 		foreach ($res as $row)
439
-			queue_close_job($row,$time);
438
+			queue_close_job($row, $time);
440 439
 	}
441 440
 
442 441
 	// chercher la date du prochain job si pas connu
443
-	if (is_null($next) OR is_null(queue_sleep_time_to_next_job())){
444
-		$date = sql_getfetsel('date','spip_jobs',"status=".intval(_JQ_SCHEDULED),'','date','0,1');
442
+	if (is_null($next) OR is_null(queue_sleep_time_to_next_job())) {
443
+		$date = sql_getfetsel('date', 'spip_jobs', "status=".intval(_JQ_SCHEDULED), '', 'date', '0,1');
445 444
 		$next = strtotime($date);
446 445
 	}
447
-	if (!is_null($next_time)){
448
-		if (is_null($next) OR $next>$next_time)
446
+	if (!is_null($next_time)) {
447
+		if (is_null($next) OR $next > $next_time)
449 448
 			$next = $next_time;
450 449
 	}
451 450
 
452
-		if ($next){
451
+		if ($next) {
453 452
 			if (is_null($nb_jobs_scheduled))
454
-				$nb_jobs_scheduled = sql_countsel('spip_jobs',"status=".intval(_JQ_SCHEDULED)." AND date<".sql_quote(date('Y-m-d H:i:s',$time)));
455
-			elseif ($next<=$time)
453
+				$nb_jobs_scheduled = sql_countsel('spip_jobs', "status=".intval(_JQ_SCHEDULED)." AND date<".sql_quote(date('Y-m-d H:i:s', $time)));
454
+			elseif ($next <= $time)
456 455
 				$nb_jobs_scheduled++;
457 456
 			// si trop de jobs en attente, on force la purge en fin de hit
458 457
 			// pour assurer le coup
459
-			if ($nb_jobs_scheduled>defined('_JQ_NB_JOBS_OVERFLOW')?_JQ_NB_JOBS_OVERFLOW:10000)
460
-				define('_DIRECT_CRON_FORCE',true);
458
+			if ($nb_jobs_scheduled > defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)
459
+				define('_DIRECT_CRON_FORCE', true);
461 460
 		}
462 461
 
463 462
 	queue_set_next_job_time($next);
@@ -477,16 +476,16 @@  discard block
 block discarded – undo
477 476
 	// toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes
478 477
 	// et ne mettre a jour que si il y a un interet a le faire
479 478
 	// permet ausis d'initialiser le nom de fichier a coup sur
480
-	$curr_next = $_SERVER['REQUEST_TIME'] + max(0,queue_sleep_time_to_next_job(true));
479
+	$curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true));
481 480
 	if (
482
-			($curr_next<=$time AND $next>$time) // le prochain job est dans le futur mais pas la date planifiee actuelle
483
-			OR $curr_next>$next // le prochain job est plus tot que la date planifiee actuelle
481
+			($curr_next <= $time AND $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle
482
+			OR $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle
484 483
 		) {
485 484
 		if (include_spip('inc/memoization') AND defined('_MEMOIZE_MEMORY') AND _MEMOIZE_MEMORY) {
486
-			cache_set(_JQ_NEXT_JOB_TIME_FILENAME,intval($next));
485
+			cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next));
487 486
 		}
488 487
 		else {
489
-			ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME,intval($next));
488
+			ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next));
490 489
 		}
491 490
 		queue_sleep_time_to_next_job($next);
492 491
 	}
@@ -502,16 +501,16 @@  discard block
 block discarded – undo
502 501
  * 
503 502
  * @return string
504 503
  */
505
-function queue_affichage_cron(){
504
+function queue_affichage_cron() {
506 505
 	$texte = "";
507 506
 
508 507
 	$time_to_next = queue_sleep_time_to_next_job();
509 508
 	// rien a faire si le prochain job est encore dans le futur
510
-	if ($time_to_next>0 OR defined('_DEBUG_BLOCK_QUEUE'))
509
+	if ($time_to_next > 0 OR defined('_DEBUG_BLOCK_QUEUE'))
511 510
 		return $texte;
512 511
 
513 512
 	// ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent
514
-	if (file_exists($lock=_DIR_TMP."cron.lock") AND !(@filemtime($lock)<$_SERVER['REQUEST_TIME']))
513
+	if (file_exists($lock = _DIR_TMP."cron.lock") AND !(@filemtime($lock) < $_SERVER['REQUEST_TIME']))
515 514
 		return $texte;
516 515
 	@touch($lock);
517 516
 
@@ -519,20 +518,20 @@  discard block
 block discarded – undo
519 518
 	// si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup
520 519
 	// on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic
521 520
 	$urgent = false;
522
-	if ($time_to_next<-300)
521
+	if ($time_to_next < -300)
523 522
 		$urgent = true;
524 523
 
525
-	$url_cron = generer_url_action('cron','',false,true);
524
+	$url_cron = generer_url_action('cron', '', false, true);
526 525
 
527
-	if (!defined('_HTML_BG_CRON_FORCE') OR !_HTML_BG_CRON_FORCE){
526
+	if (!defined('_HTML_BG_CRON_FORCE') OR !_HTML_BG_CRON_FORCE) {
528 527
 
529 528
 		// methode la plus rapide :
530 529
 		// Si fsockopen est possible, on lance le cron via un socket en asynchrone
531 530
 		// si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL
532 531
 		// car on a toutes les chances d'echouer pareil mais sans moyen de le savoir
533 532
 		// on passe direct a la methode background-image
534
-		if(function_exists('fsockopen')){
535
-			$parts=parse_url($url_cron);
533
+		if (function_exists('fsockopen')) {
534
+			$parts = parse_url($url_cron);
536 535
 
537 536
 			switch ($parts['scheme']) {
538 537
 				case 'https':
@@ -546,24 +545,24 @@  discard block
 block discarded – undo
546 545
 			}
547 546
 
548 547
 			$fp = @fsockopen($scheme.$parts['host'],
549
-		        isset($parts['port'])?$parts['port']:$port,
548
+		        isset($parts['port']) ? $parts['port'] : $port,
550 549
 		        $errno, $errstr, 1);
551 550
 
552 551
 			if ($fp) {
553 552
 				$timeout = 200; // ms
554
-				stream_set_timeout($fp,0,$timeout * 1000);
555
-				$query = $parts['path'].($parts['query']?"?".$parts['query']:"");
553
+				stream_set_timeout($fp, 0, $timeout * 1000);
554
+				$query = $parts['path'].($parts['query'] ? "?".$parts['query'] : "");
556 555
 				$out = "GET ".$query." HTTP/1.1\r\n";
557
-				$out.= "Host: ".$parts['host']."\r\n";
558
-				$out.= "Connection: Close\r\n\r\n";
556
+				$out .= "Host: ".$parts['host']."\r\n";
557
+				$out .= "Connection: Close\r\n\r\n";
559 558
 				fwrite($fp, $out);
560 559
 				spip_timer('read');
561 560
 				$t = 0;
562 561
 				// on lit la reponse si possible pour fermer proprement la connexion
563 562
 				// avec un timeout total de 200ms pour ne pas se bloquer
564
-				while (!feof($fp) AND $t<$timeout) {
563
+				while (!feof($fp) AND $t < $timeout) {
565 564
 					@fgets($fp, 1024);
566
-					$t += spip_timer('read',true);
565
+					$t += spip_timer('read', true);
567 566
 					spip_timer('read');
568 567
 				}
569 568
 				fclose($fp);
@@ -573,7 +572,7 @@  discard block
 block discarded – undo
573 572
 		}
574 573
 		// si fsockopen n'est pas dispo on essaye cURL :
575 574
 		// lancer le cron par un cURL asynchrone si cURL est present
576
-		elseif (function_exists("curl_init")){
575
+		elseif (function_exists("curl_init")) {
577 576
 			//setting the curl parameters.
578 577
 			$ch = curl_init($url_cron);
579 578
 			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@@ -597,14 +596,14 @@  discard block
 block discarded – undo
597 596
 	// si c'est un bot
598 597
 	// inutile de faire un appel par image background,
599 598
 	// on force un appel direct en fin de hit
600
-	if ((defined('_IS_BOT') AND _IS_BOT)){
601
-		define('_DIRECT_CRON_FORCE',true);
599
+	if ((defined('_IS_BOT') AND _IS_BOT)) {
600
+		define('_DIRECT_CRON_FORCE', true);
602 601
 		return $texte;
603 602
 	}
604 603
 
605 604
 	// en derniere solution, on insere une image background dans la page
606
-	$texte = '<!-- SPIP-CRON --><div style="background-image: url(\'' .
607
-		generer_url_action('cron') .
605
+	$texte = '<!-- SPIP-CRON --><div style="background-image: url(\''.
606
+		generer_url_action('cron').
608 607
 		'\');"></div>';
609 608
 
610 609
 	return $texte;
Please login to merge, or discard this patch.
Braces   +74 added lines, -51 removed lines patch added patch discarded remove patch
@@ -15,7 +15,9 @@  discard block
 block discarded – undo
15 15
  *
16 16
  * @package SPIP\Queue
17 17
 **/
18
-if (!defined("_ECRIRE_INC_VERSION")) return;
18
+if (!defined("_ECRIRE_INC_VERSION")) {
19
+    return;
20
+}
19 21
 
20 22
 define('_JQ_SCHEDULED',1);
21 23
 define('_JQ_PENDING',0);
@@ -51,8 +53,9 @@  discard block
 block discarded – undo
51 53
 	include_spip('base/abstract_sql');
52 54
 
53 55
 	// cas pourri de ecrire/action/editer_site avec l'option reload=oui
54
-	if (defined('_GENIE_SYNDIC_NOW'))
55
-		$arguments['id_syndic'] = _GENIE_SYNDIC_NOW;
56
+	if (defined('_GENIE_SYNDIC_NOW')) {
57
+			$arguments['id_syndic'] = _GENIE_SYNDIC_NOW;
58
+	}
56 59
 
57 60
 	// serialiser les arguments
58 61
 	$arguments = serialize($arguments);
@@ -86,8 +89,9 @@  discard block
 block discarded – undo
86 89
 					$duplicate_where . 'fonction='.sql_quote($function)
87 90
 				.(($no_duplicate==='function_only')?'':
88 91
 				 ' AND md5args='.sql_quote($md5args).' AND inclure='.sql_quote($file)))
89
-		)
90
-		return $id_job;
92
+		) {
93
+			return $id_job;
94
+	}
91 95
 
92 96
 	$id_job = sql_insertq('spip_jobs',$set_job);
93 97
 	// en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele
@@ -184,9 +188,9 @@  discard block
 block discarded – undo
184 188
 				$objets[$k]['id_job'] = $id_job;
185 189
 			}
186 190
 			sql_insertq_multi('spip_jobs_liens',$objets);
191
+		} else {
192
+					sql_insertq('spip_jobs_liens',array_merge(array('id_job'=>$id_job),$objets));
187 193
 		}
188
-		else
189
-			sql_insertq('spip_jobs_liens',array_merge(array('id_job'=>$id_job),$objets));
190 194
 	}
191 195
 }
192 196
 
@@ -222,11 +226,12 @@  discard block
 block discarded – undo
222 226
 	if (strlen($inclure = trim($row['inclure']))){
223 227
 		if (substr($inclure,-1)=='/'){ // c'est un chemin pour charger_fonction
224 228
 			$f = charger_fonction($fonction,rtrim($inclure,'/'),false);
225
-			if ($f)
226
-				$fonction = $f;
229
+			if ($f) {
230
+							$fonction = $f;
231
+			}
232
+		} else {
233
+					include_spip($inclure);
227 234
 		}
228
-		else
229
-			include_spip($inclure);
230 235
 	}
231 236
 
232 237
 	if (!function_exists($fonction)){
@@ -285,20 +290,25 @@  discard block
 block discarded – undo
285 290
 
286 291
 	include_spip('base/abstract_sql');
287 292
 	// on ne peut rien faire si pas de connexion SQL
288
-	if (!spip_connect())  return false;
293
+	if (!spip_connect()) {
294
+	    return false;
295
+	}
289 296
 
290 297
 	if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')){
291 298
 		$max_time = ini_get('max_execution_time')/2;
292 299
 		// valeur conservatrice si on a pas reussi a lire le max_execution_time
293
-		if (!$max_time) $max_time=5;
300
+		if (!$max_time) {
301
+		    $max_time=5;
302
+		}
294 303
 		define('_JQ_MAX_JOBS_TIME_TO_EXECUTE',min($max_time,15)); // une valeur maxi en temps.
295 304
 	}
296 305
 	$end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE;
297 306
 
298 307
 	spip_log("JQ schedule $time / $end_time",'jq'._LOG_DEBUG);
299 308
 
300
-	if (!defined('_JQ_MAX_JOBS_EXECUTE'))
301
-		define('_JQ_MAX_JOBS_EXECUTE',200);
309
+	if (!defined('_JQ_MAX_JOBS_EXECUTE')) {
310
+			define('_JQ_MAX_JOBS_EXECUTE',200);
311
+	}
302 312
 	$nbj=0;
303 313
 	// attraper les jobs
304 314
 	// dont la date est passee (echus en attente),
@@ -307,9 +317,9 @@  discard block
 block discarded – undo
307 317
 	//	- de date
308 318
 	// lorsqu'un job cron n'a pas fini, sa priorite est descendue
309 319
 	// pour qu'il ne bloque pas les autres jobs en attente
310
-	if (is_array($force_jobs) AND count($force_jobs))
311
-		$cond = "status=".intval(_JQ_SCHEDULED)." AND ".sql_in("id_job", $force_jobs);
312
-	else {
320
+	if (is_array($force_jobs) AND count($force_jobs)) {
321
+			$cond = "status=".intval(_JQ_SCHEDULED)." AND ".sql_in("id_job", $force_jobs);
322
+	} else {
313 323
 		$now = date('Y-m-d H:i:s',$time);
314 324
 		$cond = "status=".intval(_JQ_SCHEDULED)." AND date<=".sql_quote($now);
315 325
 	}
@@ -342,9 +352,9 @@  discard block
 block discarded – undo
342 352
 	if ($row = array_shift($res)){
343 353
 		queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP
344 354
 		spip_log("JQ encore !",'jq'._LOG_DEBUG);
355
+	} else {
356
+			queue_update_next_job_time();
345 357
 	}
346
-	else
347
-		queue_update_next_job_time();
348 358
 
349 359
 	return true;
350 360
 }
@@ -364,12 +374,13 @@  discard block
 block discarded – undo
364 374
 	if ($periode = queue_is_cron_job($row['fonction'],$row['inclure'])){
365 375
 		// relancer avec les nouveaux arguments de temps
366 376
 		include_spip('inc/genie');
367
-		if ($result<0)
368
-			// relancer tout de suite, mais en baissant la priorite
377
+		if ($result<0) {
378
+					// relancer tout de suite, mais en baissant la priorite
369 379
 			queue_genie_replan_job($row['fonction'],$periode,0-$result,null,$row['priorite']-1);
370
-		else
371
-			// relancer avec la periode prevue
380
+		} else {
381
+					// relancer avec la periode prevue
372 382
 			queue_genie_replan_job($row['fonction'],$periode,$time);
383
+		}
373 384
 	}
374 385
 	// purger ses liens eventuels avec des objets
375 386
 	sql_delete("spip_jobs_liens","id_job=".intval($row['id_job']));
@@ -403,8 +414,9 @@  discard block
 block discarded – undo
403 414
 			include_spip('inc/genie');
404 415
 			$taches = taches_generales();
405 416
 		}
406
-		if (isset($taches[$function]))
407
-			return $taches[$function];
417
+		if (isset($taches[$function])) {
418
+					return $taches[$function];
419
+		}
408 420
 	}
409 421
 	return false;
410 422
 }
@@ -425,7 +437,9 @@  discard block
 block discarded – undo
425 437
 	// prendre le min des $next_time que l'on voit passer ici, en cas de reentrance
426 438
 	static $next = null;
427 439
 	// queue_close_job peut etre reentrant ici
428
-	if ($deja_la) return;
440
+	if ($deja_la) {
441
+	    return;
442
+	}
429 443
 	$deja_la = true;
430 444
 
431 445
 	include_spip('base/abstract_sql');
@@ -435,8 +449,9 @@  discard block
 block discarded – undo
435 449
 	// pour cause de timeout ou autre erreur fatale
436 450
 	$res = sql_allfetsel("*","spip_jobs","status=".intval(_JQ_PENDING)." AND date<".sql_quote(date('Y-m-d H:i:s',$time-180)));
437 451
 	if (is_array($res)) {
438
-		foreach ($res as $row)
439
-			queue_close_job($row,$time);
452
+		foreach ($res as $row) {
453
+					queue_close_job($row,$time);
454
+		}
440 455
 	}
441 456
 
442 457
 	// chercher la date du prochain job si pas connu
@@ -445,19 +460,22 @@  discard block
 block discarded – undo
445 460
 		$next = strtotime($date);
446 461
 	}
447 462
 	if (!is_null($next_time)){
448
-		if (is_null($next) OR $next>$next_time)
449
-			$next = $next_time;
463
+		if (is_null($next) OR $next>$next_time) {
464
+					$next = $next_time;
465
+		}
450 466
 	}
451 467
 
452 468
 		if ($next){
453
-			if (is_null($nb_jobs_scheduled))
454
-				$nb_jobs_scheduled = sql_countsel('spip_jobs',"status=".intval(_JQ_SCHEDULED)." AND date<".sql_quote(date('Y-m-d H:i:s',$time)));
455
-			elseif ($next<=$time)
456
-				$nb_jobs_scheduled++;
469
+			if (is_null($nb_jobs_scheduled)) {
470
+							$nb_jobs_scheduled = sql_countsel('spip_jobs',"status=".intval(_JQ_SCHEDULED)." AND date<".sql_quote(date('Y-m-d H:i:s',$time)));
471
+			} elseif ($next<=$time) {
472
+							$nb_jobs_scheduled++;
473
+			}
457 474
 			// si trop de jobs en attente, on force la purge en fin de hit
458 475
 			// pour assurer le coup
459
-			if ($nb_jobs_scheduled>defined('_JQ_NB_JOBS_OVERFLOW')?_JQ_NB_JOBS_OVERFLOW:10000)
460
-				define('_DIRECT_CRON_FORCE',true);
476
+			if ($nb_jobs_scheduled>defined('_JQ_NB_JOBS_OVERFLOW')?_JQ_NB_JOBS_OVERFLOW:10000) {
477
+							define('_DIRECT_CRON_FORCE',true);
478
+			}
461 479
 		}
462 480
 
463 481
 	queue_set_next_job_time($next);
@@ -484,8 +502,7 @@  discard block
 block discarded – undo
484 502
 		) {
485 503
 		if (include_spip('inc/memoization') AND defined('_MEMOIZE_MEMORY') AND _MEMOIZE_MEMORY) {
486 504
 			cache_set(_JQ_NEXT_JOB_TIME_FILENAME,intval($next));
487
-		}
488
-		else {
505
+		} else {
489 506
 			ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME,intval($next));
490 507
 		}
491 508
 		queue_sleep_time_to_next_job($next);
@@ -507,20 +524,23 @@  discard block
 block discarded – undo
507 524
 
508 525
 	$time_to_next = queue_sleep_time_to_next_job();
509 526
 	// rien a faire si le prochain job est encore dans le futur
510
-	if ($time_to_next>0 OR defined('_DEBUG_BLOCK_QUEUE'))
511
-		return $texte;
527
+	if ($time_to_next>0 OR defined('_DEBUG_BLOCK_QUEUE')) {
528
+			return $texte;
529
+	}
512 530
 
513 531
 	// ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent
514
-	if (file_exists($lock=_DIR_TMP."cron.lock") AND !(@filemtime($lock)<$_SERVER['REQUEST_TIME']))
515
-		return $texte;
532
+	if (file_exists($lock=_DIR_TMP."cron.lock") AND !(@filemtime($lock)<$_SERVER['REQUEST_TIME'])) {
533
+			return $texte;
534
+	}
516 535
 	@touch($lock);
517 536
 
518 537
 	// il y a des taches en attentes
519 538
 	// si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup
520 539
 	// on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic
521 540
 	$urgent = false;
522
-	if ($time_to_next<-300)
523
-		$urgent = true;
541
+	if ($time_to_next<-300) {
542
+			$urgent = true;
543
+	}
524 544
 
525 545
 	$url_cron = generer_url_action('cron','',false,true);
526 546
 
@@ -567,8 +587,9 @@  discard block
 block discarded – undo
567 587
 					spip_timer('read');
568 588
 				}
569 589
 				fclose($fp);
570
-				if (!$urgent)
571
-					return $texte;
590
+				if (!$urgent) {
591
+									return $texte;
592
+				}
572 593
 			}
573 594
 		}
574 595
 		// si fsockopen n'est pas dispo on essaye cURL :
@@ -585,14 +606,16 @@  discard block
 block discarded – undo
585 606
 			curl_exec($ch);
586 607
 			// fermer
587 608
 			curl_close($ch);
588
-			if (!$urgent)
589
-				return $texte;
609
+			if (!$urgent) {
610
+							return $texte;
611
+			}
590 612
 		}
591 613
 	}
592 614
 
593 615
 	// si deja force, on retourne sans rien
594
-	if (defined('_DIRECT_CRON_FORCE'))
595
-		return $texte;
616
+	if (defined('_DIRECT_CRON_FORCE')) {
617
+			return $texte;
618
+	}
596 619
 
597 620
 	// si c'est un bot
598 621
 	// inutile de faire un appel par image background,
Please login to merge, or discard this patch.
ecrire/inc/rubriques.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
  *     Ancien statut de la rubrique
45 45
  * @param bool $postdate
46 46
  *     true pour recalculer aussi la date du prochain article post-daté
47
- * @return bool
47
+ * @return boolean|null
48 48
  *     true si le statut change effectivement
49 49
 **/
50 50
 function calculer_rubriques_if ($id_rubrique, $modifs, $statut_ancien='', $postdate = false)
Please login to merge, or discard this patch.
Indentation   +407 added lines, -407 removed lines patch added patch discarded remove patch
@@ -49,35 +49,35 @@  discard block
 block discarded – undo
49 49
 **/
50 50
 function calculer_rubriques_if ($id_rubrique, $modifs, $statut_ancien='', $postdate = false)
51 51
 {
52
-	$neuf = false;
53
-	if ($statut_ancien == 'publie') {
54
-		if (isset($modifs['statut'])
55
-			OR isset($modifs['id_rubrique'])
56
-			OR ($postdate AND strtotime($postdate)>time()))
57
-			$neuf |= depublier_branche_rubrique_if($id_rubrique);
58
-		// ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur
59
-		if ($postdate){
60
-			calculer_prochain_postdate(true);
61
-			$neuf |= (strtotime($postdate)<=time()); // par securite
62
-		}
63
-		elseif (isset($modifs['id_rubrique']))
64
-			$neuf |= publier_branche_rubrique($modifs['id_rubrique']);
65
-	}
66
-	elseif ($modifs['statut']=='publie'){
67
-		if ($postdate){
68
-			calculer_prochain_postdate(true);
69
-			$neuf |= (strtotime($postdate)<=time()); // par securite
70
-		}
71
-		else
72
-			$neuf |= publier_branche_rubrique($id_rubrique);
73
-	}
74
-
75
-	if ($neuf)
76
-	// Sauver la date de la derniere mise a jour (pour menu_rubriques)
77
-	  ecrire_meta("date_calcul_rubriques", date("U"));
78
-
79
-	$langues = calculer_langues_utilisees();
80
-	ecrire_meta('langues_utilisees', $langues);
52
+    $neuf = false;
53
+    if ($statut_ancien == 'publie') {
54
+        if (isset($modifs['statut'])
55
+            OR isset($modifs['id_rubrique'])
56
+            OR ($postdate AND strtotime($postdate)>time()))
57
+            $neuf |= depublier_branche_rubrique_if($id_rubrique);
58
+        // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur
59
+        if ($postdate){
60
+            calculer_prochain_postdate(true);
61
+            $neuf |= (strtotime($postdate)<=time()); // par securite
62
+        }
63
+        elseif (isset($modifs['id_rubrique']))
64
+            $neuf |= publier_branche_rubrique($modifs['id_rubrique']);
65
+    }
66
+    elseif ($modifs['statut']=='publie'){
67
+        if ($postdate){
68
+            calculer_prochain_postdate(true);
69
+            $neuf |= (strtotime($postdate)<=time()); // par securite
70
+        }
71
+        else
72
+            $neuf |= publier_branche_rubrique($id_rubrique);
73
+    }
74
+
75
+    if ($neuf)
76
+    // Sauver la date de la derniere mise a jour (pour menu_rubriques)
77
+        ecrire_meta("date_calcul_rubriques", date("U"));
78
+
79
+    $langues = calculer_langues_utilisees();
80
+    ecrire_meta('langues_utilisees', $langues);
81 81
 }
82 82
 
83 83
 
@@ -96,16 +96,16 @@  discard block
 block discarded – undo
96 96
  */
97 97
 function publier_branche_rubrique($id_rubrique)
98 98
 {
99
-	$id_pred = $id_rubrique;
100
-	while (true) {
101
-		sql_updateq('spip_rubriques', array('statut'=>'publie', 'date'=>date('Y-m-d H:i:s')), "id_rubrique=$id_rubrique");
102
-		$id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=$id_rubrique");
103
-		if (!$id_parent) break;
104
-		$id_rubrique = $id_parent;
105
-	} 
99
+    $id_pred = $id_rubrique;
100
+    while (true) {
101
+        sql_updateq('spip_rubriques', array('statut'=>'publie', 'date'=>date('Y-m-d H:i:s')), "id_rubrique=$id_rubrique");
102
+        $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=$id_rubrique");
103
+        if (!$id_parent) break;
104
+        $id_rubrique = $id_parent;
105
+    } 
106 106
 
107 107
 #	spip_log(" publier_branche_rubrique($id_rubrique $id_pred");
108
-	return $id_pred != $id_rubrique;
108
+    return $id_pred != $id_rubrique;
109 109
 }
110 110
 
111 111
 /**
@@ -122,20 +122,20 @@  discard block
 block discarded – undo
122 122
  *     true si le statut change effectivement
123 123
  */
124 124
 function depublier_branche_rubrique_if($id_rubrique){
125
-	$date = date('Y-m-d H:i:s'); // figer la date
125
+    $date = date('Y-m-d H:i:s'); // figer la date
126 126
 
127
-	#	spip_log("depublier_branche_rubrique($id_rubrique ?");
128
-	$id_pred = $id_rubrique;
129
-	while ($id_pred) {
127
+    #	spip_log("depublier_branche_rubrique($id_rubrique ?");
128
+    $id_pred = $id_rubrique;
129
+    while ($id_pred) {
130 130
 
131
-		if (!depublier_rubrique_if($id_pred,$date))
132
-			return $id_pred != $id_rubrique;
133
-		// passer au parent si on a depublie
134
-		$r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=$id_pred");
135
-		$id_pred = $r['id_parent'];
136
-	}
131
+        if (!depublier_rubrique_if($id_pred,$date))
132
+            return $id_pred != $id_rubrique;
133
+        // passer au parent si on a depublie
134
+        $r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=$id_pred");
135
+        $id_pred = $r['id_parent'];
136
+    }
137 137
 
138
-	return $id_pred != $id_rubrique;
138
+    return $id_pred != $id_rubrique;
139 139
 }
140 140
 
141 141
 /**
@@ -150,49 +150,49 @@  discard block
 block discarded – undo
150 150
  *    true si la rubrique a été dépubliée
151 151
  */
152 152
 function depublier_rubrique_if($id_rubrique,$date=null){
153
-	if (is_null($date)) {
154
-		$date = date('Y-m-d H:i:s');
155
-	}
156
-	$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
157
-		" AND date <= ".sql_quote($date) : '';
158
-
159
-	if (!$id_rubrique=intval($id_rubrique))
160
-		return false;
161
-
162
-	// verifier qu'elle existe et est bien publiee
163
-	$r = sql_fetsel('id_rubrique,statut','spip_rubriques',"id_rubrique=$id_rubrique");
164
-	if (!$r OR $r['statut']!=='publie')
165
-		return false;
166
-
167
-	// On met le nombre de chaque type d'enfants dans un tableau
168
-	// Le type de l'objet est au pluriel
169
-	$compte = array(
170
-		'articles' => sql_countsel("spip_articles",  "id_rubrique=$id_rubrique AND statut='publie'$postdates"),
171
-		'rubriques' => sql_countsel("spip_rubriques",  "id_parent=$id_rubrique AND statut='publie'"),
172
-		'documents' => sql_countsel("spip_documents_liens",  "id_objet=$id_rubrique AND objet='rubrique'")
173
-	);
153
+    if (is_null($date)) {
154
+        $date = date('Y-m-d H:i:s');
155
+    }
156
+    $postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
157
+        " AND date <= ".sql_quote($date) : '';
158
+
159
+    if (!$id_rubrique=intval($id_rubrique))
160
+        return false;
161
+
162
+    // verifier qu'elle existe et est bien publiee
163
+    $r = sql_fetsel('id_rubrique,statut','spip_rubriques',"id_rubrique=$id_rubrique");
164
+    if (!$r OR $r['statut']!=='publie')
165
+        return false;
166
+
167
+    // On met le nombre de chaque type d'enfants dans un tableau
168
+    // Le type de l'objet est au pluriel
169
+    $compte = array(
170
+        'articles' => sql_countsel("spip_articles",  "id_rubrique=$id_rubrique AND statut='publie'$postdates"),
171
+        'rubriques' => sql_countsel("spip_rubriques",  "id_parent=$id_rubrique AND statut='publie'"),
172
+        'documents' => sql_countsel("spip_documents_liens",  "id_objet=$id_rubrique AND objet='rubrique'")
173
+    );
174 174
 	
175
-	// On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants
176
-	$compte = pipeline('objet_compte_enfants',
177
-		array(
178
-			'args' => array(
179
-				'objet' => 'rubrique',
180
-				'id_objet' => $id_rubrique,
181
-				'statut' => 'publie',
182
-				'date' => $date
183
-			),
184
-			'data' => $compte
185
-		)
186
-	);
175
+    // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants
176
+    $compte = pipeline('objet_compte_enfants',
177
+        array(
178
+            'args' => array(
179
+                'objet' => 'rubrique',
180
+                'id_objet' => $id_rubrique,
181
+                'statut' => 'publie',
182
+                'date' => $date
183
+            ),
184
+            'data' => $compte
185
+        )
186
+    );
187 187
 	
188
-	// S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas
189
-	foreach($compte as $objet => $n)
190
-		if ($n)
191
-			return false;
188
+    // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas
189
+    foreach($compte as $objet => $n)
190
+        if ($n)
191
+            return false;
192 192
 
193
-	sql_updateq("spip_rubriques", array("statut" => '0'), "id_rubrique=$id_rubrique");
193
+    sql_updateq("spip_rubriques", array("statut" => '0'), "id_rubrique=$id_rubrique");
194 194
 #		spip_log("depublier_rubrique $id_pred");
195
-	return true;
195
+    return true;
196 196
 }
197 197
 
198 198
 
@@ -211,18 +211,18 @@  discard block
 block discarded – undo
211 211
 **/
212 212
 function calculer_rubriques() {
213 213
 
214
-	calculer_rubriques_publiees();
214
+    calculer_rubriques_publiees();
215 215
 
216
-	// Apres chaque (de)publication 
217
-	// recalculer les langues utilisees sur le site
218
-	$langues = calculer_langues_utilisees();
219
-	ecrire_meta('langues_utilisees', $langues);
216
+    // Apres chaque (de)publication 
217
+    // recalculer les langues utilisees sur le site
218
+    $langues = calculer_langues_utilisees();
219
+    ecrire_meta('langues_utilisees', $langues);
220 220
 
221
-	// Sauver la date de la derniere mise a jour (pour menu_rubriques)
222
-	ecrire_meta("date_calcul_rubriques", date("U"));
221
+    // Sauver la date de la derniere mise a jour (pour menu_rubriques)
222
+    ecrire_meta("date_calcul_rubriques", date("U"));
223 223
 
224
-	// on calcule la date du prochain article post-date
225
-	calculer_prochain_postdate();
224
+    // on calcule la date du prochain article post-date
225
+    calculer_prochain_postdate();
226 226
 }
227 227
 
228 228
 
@@ -238,42 +238,42 @@  discard block
 block discarded – undo
238 238
 **/
239 239
 function calculer_rubriques_publiees() {
240 240
 
241
-	// Mettre les compteurs a zero
242
-	sql_updateq('spip_rubriques', array('date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prive'));
241
+    // Mettre les compteurs a zero
242
+    sql_updateq('spip_rubriques', array('date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prive'));
243 243
 
244
-	//
245
-	// Publier et dater les rubriques qui ont un article publie
246
-	//
244
+    //
245
+    // Publier et dater les rubriques qui ont un article publie
246
+    //
247 247
 
248
-	// Afficher les articles post-dates ?
249
-	$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
250
-		"AND A.date <= ".sql_quote(date('Y-m-d H:i:s')) : '';
248
+    // Afficher les articles post-dates ?
249
+    $postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
250
+        "AND A.date <= ".sql_quote(date('Y-m-d H:i:s')) : '';
251 251
 
252
-	$r = sql_select("R.id_rubrique AS id, max(A.date) AS date_h", "spip_rubriques AS R, spip_articles AS A", "R.id_rubrique = A.id_rubrique AND A.statut='publie' $postdates ", "R.id_rubrique");
253
-	while ($row = sql_fetch($r))
254
-		sql_updateq("spip_rubriques", array("statut_tmp" => 'publie', "date_tmp" => $row['date_h']), "id_rubrique=".$row['id']);
252
+    $r = sql_select("R.id_rubrique AS id, max(A.date) AS date_h", "spip_rubriques AS R, spip_articles AS A", "R.id_rubrique = A.id_rubrique AND A.statut='publie' $postdates ", "R.id_rubrique");
253
+    while ($row = sql_fetch($r))
254
+        sql_updateq("spip_rubriques", array("statut_tmp" => 'publie', "date_tmp" => $row['date_h']), "id_rubrique=".$row['id']);
255 255
 
256
-	// point d'entree pour permettre a des plugins de gerer le statut
257
-	// autrement (par ex: toute rubrique est publiee des sa creation)
258
-	// Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates
259
-	// c'est statut_tmp/date_tmp qu'il doit modifier
260
-	// [C'est un trigger... a renommer en trig_calculer_rubriques ?]
261
-	pipeline('calculer_rubriques', null);
256
+    // point d'entree pour permettre a des plugins de gerer le statut
257
+    // autrement (par ex: toute rubrique est publiee des sa creation)
258
+    // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates
259
+    // c'est statut_tmp/date_tmp qu'il doit modifier
260
+    // [C'est un trigger... a renommer en trig_calculer_rubriques ?]
261
+    pipeline('calculer_rubriques', null);
262 262
 	
263 263
 
264
-	// Les rubriques qui ont une rubrique fille plus recente
265
-	// on tourne tant que les donnees remontent vers la racine.
266
-	do {
267
-		$continuer = false;
268
-		$r = sql_select("R.id_rubrique AS id, max(A.date_tmp) AS date_h", "spip_rubriques AS R, spip_rubriques AS A", "R.id_rubrique = A.id_parent AND (R.date_tmp < A.date_tmp OR R.statut_tmp<>'publie') AND A.statut_tmp='publie' ", "R.id_rubrique");
269
-		while ($row = sql_fetch($r)) {
270
-		  sql_updateq('spip_rubriques', array('statut_tmp'=>'publie', 'date_tmp'=>$row['date_h']),"id_rubrique=".$row['id']);
271
-			$continuer = true;
272
-		}
273
-	} while ($continuer);
274
-
275
-	// Enregistrement des modifs
276
-	sql_update('spip_rubriques', array('date'=>'date_tmp', 'statut'=>'statut_tmp'));
264
+    // Les rubriques qui ont une rubrique fille plus recente
265
+    // on tourne tant que les donnees remontent vers la racine.
266
+    do {
267
+        $continuer = false;
268
+        $r = sql_select("R.id_rubrique AS id, max(A.date_tmp) AS date_h", "spip_rubriques AS R, spip_rubriques AS A", "R.id_rubrique = A.id_parent AND (R.date_tmp < A.date_tmp OR R.statut_tmp<>'publie') AND A.statut_tmp='publie' ", "R.id_rubrique");
269
+        while ($row = sql_fetch($r)) {
270
+            sql_updateq('spip_rubriques', array('statut_tmp'=>'publie', 'date_tmp'=>$row['date_h']),"id_rubrique=".$row['id']);
271
+            $continuer = true;
272
+        }
273
+    } while ($continuer);
274
+
275
+    // Enregistrement des modifs
276
+    sql_update('spip_rubriques', array('date'=>'date_tmp', 'statut'=>'statut_tmp'));
277 277
 }
278 278
 
279 279
 /**
@@ -287,93 +287,93 @@  discard block
 block discarded – undo
287 287
 **/
288 288
 function propager_les_secteurs()
289 289
 {
290
-	// Profondeur 0
291
-	// Toutes les rubriques racines sont de profondeur 0
292
-	// et fixer les id_secteur des rubriques racines
293
-	sql_update('spip_rubriques', array('id_secteur'=>'id_rubrique','profondeur'=>0), "id_parent=0");
294
-	// Toute rubrique non racine est de profondeur >0
295
-	sql_updateq('spip_rubriques', array('profondeur'=>1), "id_parent<>0 AND profondeur=0");
296
-
297
-	// securite : pas plus d'iteration que de rubriques dans la base
298
-	$maxiter = sql_countsel("spip_rubriques");
299
-
300
-	// reparer les rubriques qui n'ont pas l'id_secteur de leur parent
301
-	// on fait profondeur par profondeur
302
-
303
-	$prof = 0;
304
-	do {
305
-		$continuer = false;
306
-
307
-		// Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes
308
-		// on fixe le profondeur $prof+1
309
-
310
-		// Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1
311
-		// on teste A.profondeur > $prof+1 car :
312
-		// - toutes les rubriques de profondeur 0 à $prof sont bonnes
313
-		// - si A.profondeur = $prof+1 c'est bon
314
-		// - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques
315
-		$maxiter2 = $maxiter;
316
-		while ($maxiter2--
317
-			AND $rows = sql_allfetsel(
318
-			"A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur",
319
-			"spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique",
320
-			"R.profondeur=".intval($prof)." AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)",
321
-		  "","R.id_secteur","0,100")){
322
-
323
-			$id_secteur = null;
324
-			$ids = array();
325
-			while ($row = array_shift($rows)) {
326
-				if ($row['id_secteur']!==$id_secteur){
327
-					if (count($ids))
328
-						sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur,'profondeur' => $prof+1), sql_in('id_rubrique',$ids));
329
-					$id_secteur = $row['id_secteur'];
330
-					$ids = array();
331
-				}
332
-				$ids[] = $row['id'];
333
-			}
334
-			if (count($ids))
335
-				sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur,'profondeur' => $prof+1), sql_in('id_rubrique',$ids));
336
-		}
337
-
338
-
339
-		// Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees
340
-		$maxiter2 = $maxiter;
341
-		while ($maxiter2--
342
-			AND $rows = sql_allfetsel(
343
-			"id_rubrique as id",
344
-			"spip_rubriques",
345
-			"profondeur=".intval($prof+1)." AND id_parent NOT IN (".sql_get_select("zzz.id_rubrique","spip_rubriques AS zzz","zzz.profondeur=".intval($prof)).")",'','','0,100')){
346
-			$rows = array_map('reset',$rows);
347
-			sql_updateq("spip_rubriques", array('profondeur' => $prof+2), sql_in("id_rubrique",$rows));
348
-		}
349
-
350
-		// ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK
351
-		// si pas de rubrique a profondeur $prof+1 pas la peine de continuer
352
-		// si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse)
353
-		// on arrete les frais
354
-		if (sql_countsel("spip_rubriques","profondeur=".intval($prof+1))){
355
-			$prof++;
356
-			$continuer = true;
357
-		}
358
-	}
359
-	while ($continuer AND $maxiter--);
360
-
361
-	// loger si la table des rubriques semble foireuse
362
-	// et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles
363
-	if (sql_countsel("spip_rubriques","profondeur>".intval($prof+1))){
364
-		spip_log("Les rubriques de profondeur>".($prof+1)." semblent suspectes (branches morte ou reference circulaire dans les parents)",_LOG_CRITIQUE);
365
-		sql_update("spip_rubriques",array('id_secteur'=>0),"profondeur>".intval($prof+1));
366
-	}
367
-
368
-	// reparer les articles
369
-	$r = sql_select("A.id_article AS id, R.id_secteur AS secteur", "spip_articles AS A, spip_rubriques AS R", "A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur");
370
-
371
-	while ($row = sql_fetch($r)) {
372
-		sql_update("spip_articles", array("id_secteur" => $row['secteur']), "id_article=".$row['id']);
373
-	}
374
-
375
-	// avertir les plugins qui peuvent faire leur mises a jour egalement
376
-	pipeline('trig_propager_les_secteurs','');
290
+    // Profondeur 0
291
+    // Toutes les rubriques racines sont de profondeur 0
292
+    // et fixer les id_secteur des rubriques racines
293
+    sql_update('spip_rubriques', array('id_secteur'=>'id_rubrique','profondeur'=>0), "id_parent=0");
294
+    // Toute rubrique non racine est de profondeur >0
295
+    sql_updateq('spip_rubriques', array('profondeur'=>1), "id_parent<>0 AND profondeur=0");
296
+
297
+    // securite : pas plus d'iteration que de rubriques dans la base
298
+    $maxiter = sql_countsel("spip_rubriques");
299
+
300
+    // reparer les rubriques qui n'ont pas l'id_secteur de leur parent
301
+    // on fait profondeur par profondeur
302
+
303
+    $prof = 0;
304
+    do {
305
+        $continuer = false;
306
+
307
+        // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes
308
+        // on fixe le profondeur $prof+1
309
+
310
+        // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1
311
+        // on teste A.profondeur > $prof+1 car :
312
+        // - toutes les rubriques de profondeur 0 à $prof sont bonnes
313
+        // - si A.profondeur = $prof+1 c'est bon
314
+        // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques
315
+        $maxiter2 = $maxiter;
316
+        while ($maxiter2--
317
+            AND $rows = sql_allfetsel(
318
+            "A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur",
319
+            "spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique",
320
+            "R.profondeur=".intval($prof)." AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)",
321
+            "","R.id_secteur","0,100")){
322
+
323
+            $id_secteur = null;
324
+            $ids = array();
325
+            while ($row = array_shift($rows)) {
326
+                if ($row['id_secteur']!==$id_secteur){
327
+                    if (count($ids))
328
+                        sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur,'profondeur' => $prof+1), sql_in('id_rubrique',$ids));
329
+                    $id_secteur = $row['id_secteur'];
330
+                    $ids = array();
331
+                }
332
+                $ids[] = $row['id'];
333
+            }
334
+            if (count($ids))
335
+                sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur,'profondeur' => $prof+1), sql_in('id_rubrique',$ids));
336
+        }
337
+
338
+
339
+        // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees
340
+        $maxiter2 = $maxiter;
341
+        while ($maxiter2--
342
+            AND $rows = sql_allfetsel(
343
+            "id_rubrique as id",
344
+            "spip_rubriques",
345
+            "profondeur=".intval($prof+1)." AND id_parent NOT IN (".sql_get_select("zzz.id_rubrique","spip_rubriques AS zzz","zzz.profondeur=".intval($prof)).")",'','','0,100')){
346
+            $rows = array_map('reset',$rows);
347
+            sql_updateq("spip_rubriques", array('profondeur' => $prof+2), sql_in("id_rubrique",$rows));
348
+        }
349
+
350
+        // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK
351
+        // si pas de rubrique a profondeur $prof+1 pas la peine de continuer
352
+        // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse)
353
+        // on arrete les frais
354
+        if (sql_countsel("spip_rubriques","profondeur=".intval($prof+1))){
355
+            $prof++;
356
+            $continuer = true;
357
+        }
358
+    }
359
+    while ($continuer AND $maxiter--);
360
+
361
+    // loger si la table des rubriques semble foireuse
362
+    // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles
363
+    if (sql_countsel("spip_rubriques","profondeur>".intval($prof+1))){
364
+        spip_log("Les rubriques de profondeur>".($prof+1)." semblent suspectes (branches morte ou reference circulaire dans les parents)",_LOG_CRITIQUE);
365
+        sql_update("spip_rubriques",array('id_secteur'=>0),"profondeur>".intval($prof+1));
366
+    }
367
+
368
+    // reparer les articles
369
+    $r = sql_select("A.id_article AS id, R.id_secteur AS secteur", "spip_articles AS A, spip_rubriques AS R", "A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur");
370
+
371
+    while ($row = sql_fetch($r)) {
372
+        sql_update("spip_articles", array("id_secteur" => $row['secteur']), "id_article=".$row['id']);
373
+    }
374
+
375
+    // avertir les plugins qui peuvent faire leur mises a jour egalement
376
+    pipeline('trig_propager_les_secteurs','');
377 377
 }
378 378
 
379 379
 
@@ -388,15 +388,15 @@  discard block
 block discarded – undo
388 388
  *     true si un changement a eu lieu
389 389
 **/
390 390
 function calculer_langues_rubriques_etape() {
391
-	$s = sql_select("A.id_rubrique AS id_rubrique, R.lang AS lang", "spip_rubriques AS A, spip_rubriques AS R", "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang");
391
+    $s = sql_select("A.id_rubrique AS id_rubrique, R.lang AS lang", "spip_rubriques AS A, spip_rubriques AS R", "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang");
392 392
 
393
-	$t = false;
394
-	while ($row = sql_fetch($s)) {
395
-		$id_rubrique = $row['id_rubrique'];
396
-		$t = sql_updateq('spip_rubriques', array('lang' => $row['lang'], 'langue_choisie'=>'non'), "id_rubrique=$id_rubrique");
397
-	}
393
+    $t = false;
394
+    while ($row = sql_fetch($s)) {
395
+        $id_rubrique = $row['id_rubrique'];
396
+        $t = sql_updateq('spip_rubriques', array('lang' => $row['lang'], 'langue_choisie'=>'non'), "id_rubrique=$id_rubrique");
397
+    }
398 398
 
399
-	return $t;
399
+    return $t;
400 400
 }
401 401
 
402 402
 /**
@@ -413,25 +413,25 @@  discard block
 block discarded – undo
413 413
 **/
414 414
 function calculer_langues_rubriques() {
415 415
 
416
-	// rubriques (recursivite)
417
-	sql_updateq("spip_rubriques", array("lang" => $GLOBALS['meta']['langue_site'], "langue_choisie" => 'non'), "id_parent=0 AND langue_choisie != 'oui'");
418
-	while (calculer_langues_rubriques_etape());
416
+    // rubriques (recursivite)
417
+    sql_updateq("spip_rubriques", array("lang" => $GLOBALS['meta']['langue_site'], "langue_choisie" => 'non'), "id_parent=0 AND langue_choisie != 'oui'");
418
+    while (calculer_langues_rubriques_etape());
419 419
 
420
-	// articles
421
-	$s = sql_select("A.id_article AS id_article, R.lang AS lang", "spip_articles AS A, spip_rubriques AS R", "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang");
422
-	while ($row = sql_fetch($s)) {
423
-		$id_article = $row['id_article'];
424
-		sql_updateq('spip_articles', array("lang"=> $row['lang'], 'langue_choisie'=>'non'), "id_article=$id_article");
425
-	}
420
+    // articles
421
+    $s = sql_select("A.id_article AS id_article, R.lang AS lang", "spip_articles AS A, spip_rubriques AS R", "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang");
422
+    while ($row = sql_fetch($s)) {
423
+        $id_article = $row['id_article'];
424
+        sql_updateq('spip_articles', array("lang"=> $row['lang'], 'langue_choisie'=>'non'), "id_article=$id_article");
425
+    }
426 426
 
427
-	if ($GLOBALS['meta']['multi_rubriques'] == 'oui') {
427
+    if ($GLOBALS['meta']['multi_rubriques'] == 'oui') {
428 428
 
429
-		$langues = calculer_langues_utilisees();
430
-		ecrire_meta('langues_utilisees', $langues);
431
-	}
429
+        $langues = calculer_langues_utilisees();
430
+        ecrire_meta('langues_utilisees', $langues);
431
+    }
432 432
 	
433
-	// avertir les plugins qui peuvent faire leur mises a jour egalement
434
-	pipeline('trig_calculer_langues_rubriques','');
433
+    // avertir les plugins qui peuvent faire leur mises a jour egalement
434
+    pipeline('trig_calculer_langues_rubriques','');
435 435
 }
436 436
 
437 437
 
@@ -448,52 +448,52 @@  discard block
 block discarded – undo
448 448
  *    Liste des langues utilisées séparées par des virgules
449 449
 **/
450 450
 function calculer_langues_utilisees ($serveur='') {
451
-	include_spip('public/interfaces');
452
-	include_spip('public/compiler');
453
-	include_spip('public/composer');
454
-	$langues = array();
455
-
456
-	$langues[$GLOBALS['meta']['langue_site']] = 1;
457
-
458
-	include_spip('base/objets');
459
-	$tables = lister_tables_objets_sql();
460
-	$trouver_table = charger_fonction('trouver_table','base');
461
-
462
-	foreach(array_keys($tables) as $t){
463
-		$desc = $trouver_table($t,$serveur);
464
-		// c'est une table avec des langues
465
-		if ($desc['exist']
466
-		  AND isset($desc['field']['lang'])
467
-			AND isset($desc['field']['langue_choisie'])){
468
-
469
-			$boucle = new Boucle();
470
-			$boucle->show = $desc;
471
-			$boucle->nom = 'calculer_langues_utilisees';
472
-			$boucle->id_boucle = $desc['table_objet'];
473
-			$boucle->id_table = $desc['table_objet'];
474
-			$boucle->sql_serveur = $serveur;
475
-			$boucle->select[] = "DISTINCT lang";
476
-			$boucle->from[$desc['table_objet']] = $t;
477
-			$boucle = pipeline('pre_boucle', $boucle);
451
+    include_spip('public/interfaces');
452
+    include_spip('public/compiler');
453
+    include_spip('public/composer');
454
+    $langues = array();
455
+
456
+    $langues[$GLOBALS['meta']['langue_site']] = 1;
457
+
458
+    include_spip('base/objets');
459
+    $tables = lister_tables_objets_sql();
460
+    $trouver_table = charger_fonction('trouver_table','base');
461
+
462
+    foreach(array_keys($tables) as $t){
463
+        $desc = $trouver_table($t,$serveur);
464
+        // c'est une table avec des langues
465
+        if ($desc['exist']
466
+          AND isset($desc['field']['lang'])
467
+            AND isset($desc['field']['langue_choisie'])){
468
+
469
+            $boucle = new Boucle();
470
+            $boucle->show = $desc;
471
+            $boucle->nom = 'calculer_langues_utilisees';
472
+            $boucle->id_boucle = $desc['table_objet'];
473
+            $boucle->id_table = $desc['table_objet'];
474
+            $boucle->sql_serveur = $serveur;
475
+            $boucle->select[] = "DISTINCT lang";
476
+            $boucle->from[$desc['table_objet']] = $t;
477
+            $boucle = pipeline('pre_boucle', $boucle);
478 478
 			
479
-			if (isset($desc['statut'])
480
-		    AND $desc['statut']){
481
-				instituer_boucle($boucle, false);
482
-				$res = calculer_select($boucle->select,$boucle->from,$boucle->from_type,$boucle->where,$boucle->join,$boucle->group,$boucle->order,$boucle->limit,$boucle->having,$desc['table_objet'],$desc['table_objet'],$serveur);
483
-			}
484
-			else
485
-				$res = sql_select(implode(',',$boucle->select),$boucle->from);
486
-			while ($row = sql_fetch($res)) {
487
-				$langues[$row['lang']] = 1;
488
-			}
489
-		}
490
-	}
491
-
492
-	$langues = array_filter(array_keys($langues));
493
-	sort($langues);
494
-	$langues = join(',',$langues);
495
-	spip_log("langues utilisees: $langues");
496
-	return $langues;
479
+            if (isset($desc['statut'])
480
+            AND $desc['statut']){
481
+                instituer_boucle($boucle, false);
482
+                $res = calculer_select($boucle->select,$boucle->from,$boucle->from_type,$boucle->where,$boucle->join,$boucle->group,$boucle->order,$boucle->limit,$boucle->having,$desc['table_objet'],$desc['table_objet'],$serveur);
483
+            }
484
+            else
485
+                $res = sql_select(implode(',',$boucle->select),$boucle->from);
486
+            while ($row = sql_fetch($res)) {
487
+                $langues[$row['lang']] = 1;
488
+            }
489
+        }
490
+    }
491
+
492
+    $langues = array_filter(array_keys($langues));
493
+    sort($langues);
494
+    $langues = join(',',$langues);
495
+    spip_log("langues utilisees: $langues");
496
+    return $langues;
497 497
 }
498 498
 
499 499
 /**
@@ -523,8 +523,8 @@  discard block
 block discarded – undo
523 523
  *     incluant les rubriques noeuds et toutes leurs descendances
524 524
  */
525 525
 function calcul_branche_in($id) {
526
-	$calcul_branche_in = charger_fonction('calcul_branche_in','inc');
527
-	return $calcul_branche_in($id);
526
+    $calcul_branche_in = charger_fonction('calcul_branche_in','inc');
527
+    return $calcul_branche_in($id);
528 528
 }
529 529
 
530 530
 /**
@@ -542,8 +542,8 @@  discard block
 block discarded – undo
542 542
  *     incluant les rubriques transmises et toutes leurs parentées
543 543
  */
544 544
 function calcul_hierarchie_in($id, $tout=true) {
545
-	$calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in','inc');
546
-	return $calcul_hierarchie_in($id, $tout);
545
+    $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in','inc');
546
+    return $calcul_hierarchie_in($id, $tout);
547 547
 }
548 548
 
549 549
 
@@ -562,33 +562,33 @@  discard block
 block discarded – undo
562 562
  *     incluant les rubriques noeuds et toutes leurs descendances
563 563
  */
564 564
 function inc_calcul_branche_in_dist($id) {
565
-	static $b = array();
566
-
567
-	// normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
568
-	if (!is_array($id)) $id = explode(',',$id);
569
-	$id = join(',', array_map('intval', $id));
570
-	if (isset($b[$id]))
571
-		return $b[$id];
572
-
573
-	// Notre branche commence par la rubrique de depart
574
-	$branche = $r = $id;
575
-
576
-	// On ajoute une generation (les filles de la generation precedente)
577
-	// jusqu'a epuisement, en se protegeant des references circulaires
578
-	$maxiter = 10000;
579
-	while ($maxiter-- AND $filles = sql_allfetsel(
580
-					'id_rubrique',
581
-					'spip_rubriques',
582
-					sql_in('id_parent', $r) ." AND ". sql_in('id_rubrique', $r, 'NOT')
583
-					)) {
584
-		$r = join(',', array_map('reset', $filles));
585
-		$branche .= ',' . $r;
586
-	}
587
-
588
-	# securite pour ne pas plomber la conso memoire sur les sites prolifiques
589
-	if (strlen($branche)<10000)
590
-		$b[$id] = $branche;
591
-	return $branche;
565
+    static $b = array();
566
+
567
+    // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
568
+    if (!is_array($id)) $id = explode(',',$id);
569
+    $id = join(',', array_map('intval', $id));
570
+    if (isset($b[$id]))
571
+        return $b[$id];
572
+
573
+    // Notre branche commence par la rubrique de depart
574
+    $branche = $r = $id;
575
+
576
+    // On ajoute une generation (les filles de la generation precedente)
577
+    // jusqu'a epuisement, en se protegeant des references circulaires
578
+    $maxiter = 10000;
579
+    while ($maxiter-- AND $filles = sql_allfetsel(
580
+                    'id_rubrique',
581
+                    'spip_rubriques',
582
+                    sql_in('id_parent', $r) ." AND ". sql_in('id_rubrique', $r, 'NOT')
583
+                    )) {
584
+        $r = join(',', array_map('reset', $filles));
585
+        $branche .= ',' . $r;
586
+    }
587
+
588
+    # securite pour ne pas plomber la conso memoire sur les sites prolifiques
589
+    if (strlen($branche)<10000)
590
+        $b[$id] = $branche;
591
+    return $branche;
592 592
 }
593 593
 
594 594
 
@@ -608,41 +608,41 @@  discard block
 block discarded – undo
608 608
  *     incluant les rubriques transmises et toutes leurs parentées
609 609
  */
610 610
 function inc_calcul_hierarchie_in_dist($id, $tout=true) {
611
-	static $b = array();
612
-
613
-	// normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
614
-	if (!is_array($id)) $id = explode(',',$id);
615
-	$id = join(',', array_map('intval', $id));
616
-
617
-	if (isset($b[$id])) {
618
-		// Notre branche commence par la rubrique de depart si $tout=true
619
-		return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id];
620
-	}
621
-
622
-	$hier = "";
623
-
624
-	// On ajoute une generation (les filles de la generation precedente)
625
-	// jusqu'a epuisement, en se protegeant des references circulaires
626
-	$ids_nouveaux_parents = $id;
627
-	$maxiter = 10000;
628
-	while ($maxiter-- AND $parents = sql_allfetsel(
629
-			'id_parent',
630
-			'spip_rubriques',
631
-			sql_in('id_rubrique', $ids_nouveaux_parents) ." AND ". sql_in('id_parent',$hier,'NOT')
632
-		  )) {
633
-		$ids_nouveaux_parents = join(',', array_map('reset', $parents));
634
-		$hier = $ids_nouveaux_parents.(strlen($hier)?','.$hier:'');
635
-	}
636
-
637
-	# securite pour ne pas plomber la conso memoire sur les sites prolifiques
638
-	if (strlen($hier)<10000) {
639
-		$b[$id] = $hier;
640
-	}
641
-
642
-	// Notre branche commence par la rubrique de depart si $tout=true
643
-	$hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier;
644
-
645
-	return $hier;
611
+    static $b = array();
612
+
613
+    // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
614
+    if (!is_array($id)) $id = explode(',',$id);
615
+    $id = join(',', array_map('intval', $id));
616
+
617
+    if (isset($b[$id])) {
618
+        // Notre branche commence par la rubrique de depart si $tout=true
619
+        return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id];
620
+    }
621
+
622
+    $hier = "";
623
+
624
+    // On ajoute une generation (les filles de la generation precedente)
625
+    // jusqu'a epuisement, en se protegeant des references circulaires
626
+    $ids_nouveaux_parents = $id;
627
+    $maxiter = 10000;
628
+    while ($maxiter-- AND $parents = sql_allfetsel(
629
+            'id_parent',
630
+            'spip_rubriques',
631
+            sql_in('id_rubrique', $ids_nouveaux_parents) ." AND ". sql_in('id_parent',$hier,'NOT')
632
+            )) {
633
+        $ids_nouveaux_parents = join(',', array_map('reset', $parents));
634
+        $hier = $ids_nouveaux_parents.(strlen($hier)?','.$hier:'');
635
+    }
636
+
637
+    # securite pour ne pas plomber la conso memoire sur les sites prolifiques
638
+    if (strlen($hier)<10000) {
639
+        $b[$id] = $hier;
640
+    }
641
+
642
+    // Notre branche commence par la rubrique de depart si $tout=true
643
+    $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier;
644
+
645
+    return $hier;
646 646
 }
647 647
 
648 648
 
@@ -658,35 +658,35 @@  discard block
 block discarded – undo
658 658
  * @return void
659 659
 **/
660 660
 function calculer_prochain_postdate($check= false) {
661
-	include_spip('base/abstract_sql');
662
-	if ($check) {
663
-		$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
664
-			"AND A.date <= ".sql_quote(date('Y-m-d H:i:s')) : '';
661
+    include_spip('base/abstract_sql');
662
+    if ($check) {
663
+        $postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
664
+            "AND A.date <= ".sql_quote(date('Y-m-d H:i:s')) : '';
665 665
 
666
-		$r = sql_select("DISTINCT A.id_rubrique AS id",
667
-			"spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique", "R.statut != 'publie' AND A.statut='publie'$postdates");
668
-		while ($row = sql_fetch($r))
669
-			publier_branche_rubrique($row['id']);
666
+        $r = sql_select("DISTINCT A.id_rubrique AS id",
667
+            "spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique", "R.statut != 'publie' AND A.statut='publie'$postdates");
668
+        while ($row = sql_fetch($r))
669
+            publier_branche_rubrique($row['id']);
670 670
 
671
-		pipeline('trig_calculer_prochain_postdate','');
672
-	}
671
+        pipeline('trig_calculer_prochain_postdate','');
672
+    }
673 673
 
674
-	$t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > ".sql_quote(date('Y-m-d H:i:s')), "", "date", "1");
674
+    $t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > ".sql_quote(date('Y-m-d H:i:s')), "", "date", "1");
675 675
 	
676
-	if ($t) {
677
-		$t =  $t['date'];
678
-		if (!isset($GLOBALS['meta']['date_prochain_postdate'])
679
-			OR $t<>$GLOBALS['meta']['date_prochain_postdate']){
680
-			ecrire_meta('date_prochain_postdate', strtotime($t));
681
-			ecrire_meta('derniere_modif', time());
682
-		}
683
-	}
684
-	else {
685
-		effacer_meta('date_prochain_postdate');
686
-		ecrire_meta('derniere_modif', time());
687
-	}
688
-
689
-	spip_log("prochain postdate: $t");
676
+    if ($t) {
677
+        $t =  $t['date'];
678
+        if (!isset($GLOBALS['meta']['date_prochain_postdate'])
679
+            OR $t<>$GLOBALS['meta']['date_prochain_postdate']){
680
+            ecrire_meta('date_prochain_postdate', strtotime($t));
681
+            ecrire_meta('derniere_modif', time());
682
+        }
683
+    }
684
+    else {
685
+        effacer_meta('date_prochain_postdate');
686
+        ecrire_meta('derniere_modif', time());
687
+    }
688
+
689
+    spip_log("prochain postdate: $t");
690 690
 }
691 691
 
692 692
 /**
@@ -711,42 +711,42 @@  discard block
 block discarded – undo
711 711
  */
712 712
 function creer_rubrique_nommee($titre, $id_parent=0, $serveur='') {
713 713
 
714
-	// eclater l'arborescence demandee
715
-	// echapper les </multi> et autres balises fermantes html
716
-	$titre = preg_replace(",</([a-z][^>]*)>,ims","<@\\1>",$titre);
717
-	$arbo = explode('/', preg_replace(',^/,', '', $titre));
718
-	include_spip('base/abstract_sql');
719
-	foreach ($arbo as $titre) {
720
-		// retablir les </multi> et autres balises fermantes html
721
-		$titre = preg_replace(",<@([a-z][^>]*)>,ims","</\\1>",$titre);
722
-		$r = sql_getfetsel("id_rubrique", "spip_rubriques", "titre = ".sql_quote($titre)." AND id_parent=".intval($id_parent),
723
-		$groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur);
724
-		if ($r !== NULL) {
725
-			$id_parent = $r;
726
-		} else {
727
-			$id_rubrique = sql_insertq('spip_rubriques', array(
728
-				'titre' => $titre,
729
-				'id_parent' => $id_parent,
730
-				'statut' => 'prive')
731
-				,$desc=array(), $serveur);
732
-			if ($id_parent > 0) {
733
-				$data = sql_fetsel("id_secteur,lang", "spip_rubriques", "id_rubrique=$id_parent",
734
-				$groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur);
735
-				$id_secteur = $data['id_secteur'];
736
-				$lang = $data['lang'];
737
-			} else {
738
-				$id_secteur = $id_rubrique;
739
-				$lang = $GLOBALS['meta']['langue_site'];
740
-			}
741
-
742
-			sql_updateq('spip_rubriques', array('id_secteur'=>$id_secteur, "lang"=>$lang), "id_rubrique=$id_rubrique", $desc='', $serveur);
743
-
744
-			// pour la recursion
745
-			$id_parent = $id_rubrique;
746
-		}
747
-	}
748
-
749
-	return intval($id_parent);
714
+    // eclater l'arborescence demandee
715
+    // echapper les </multi> et autres balises fermantes html
716
+    $titre = preg_replace(",</([a-z][^>]*)>,ims","<@\\1>",$titre);
717
+    $arbo = explode('/', preg_replace(',^/,', '', $titre));
718
+    include_spip('base/abstract_sql');
719
+    foreach ($arbo as $titre) {
720
+        // retablir les </multi> et autres balises fermantes html
721
+        $titre = preg_replace(",<@([a-z][^>]*)>,ims","</\\1>",$titre);
722
+        $r = sql_getfetsel("id_rubrique", "spip_rubriques", "titre = ".sql_quote($titre)." AND id_parent=".intval($id_parent),
723
+        $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur);
724
+        if ($r !== NULL) {
725
+            $id_parent = $r;
726
+        } else {
727
+            $id_rubrique = sql_insertq('spip_rubriques', array(
728
+                'titre' => $titre,
729
+                'id_parent' => $id_parent,
730
+                'statut' => 'prive')
731
+                ,$desc=array(), $serveur);
732
+            if ($id_parent > 0) {
733
+                $data = sql_fetsel("id_secteur,lang", "spip_rubriques", "id_rubrique=$id_parent",
734
+                $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur);
735
+                $id_secteur = $data['id_secteur'];
736
+                $lang = $data['lang'];
737
+            } else {
738
+                $id_secteur = $id_rubrique;
739
+                $lang = $GLOBALS['meta']['langue_site'];
740
+            }
741
+
742
+            sql_updateq('spip_rubriques', array('id_secteur'=>$id_secteur, "lang"=>$lang), "id_rubrique=$id_rubrique", $desc='', $serveur);
743
+
744
+            // pour la recursion
745
+            $id_parent = $id_rubrique;
746
+        }
747
+    }
748
+
749
+    return intval($id_parent);
750 750
 }
751 751
 
752 752
 ?>
Please login to merge, or discard this patch.
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -47,26 +47,26 @@  discard block
 block discarded – undo
47 47
  * @return bool
48 48
  *     true si le statut change effectivement
49 49
 **/
50
-function calculer_rubriques_if ($id_rubrique, $modifs, $statut_ancien='', $postdate = false)
50
+function calculer_rubriques_if($id_rubrique, $modifs, $statut_ancien = '', $postdate = false)
51 51
 {
52 52
 	$neuf = false;
53 53
 	if ($statut_ancien == 'publie') {
54 54
 		if (isset($modifs['statut'])
55 55
 			OR isset($modifs['id_rubrique'])
56
-			OR ($postdate AND strtotime($postdate)>time()))
56
+			OR ($postdate AND strtotime($postdate) > time()))
57 57
 			$neuf |= depublier_branche_rubrique_if($id_rubrique);
58 58
 		// ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur
59
-		if ($postdate){
59
+		if ($postdate) {
60 60
 			calculer_prochain_postdate(true);
61
-			$neuf |= (strtotime($postdate)<=time()); // par securite
61
+			$neuf |= (strtotime($postdate) <= time()); // par securite
62 62
 		}
63 63
 		elseif (isset($modifs['id_rubrique']))
64 64
 			$neuf |= publier_branche_rubrique($modifs['id_rubrique']);
65 65
 	}
66
-	elseif ($modifs['statut']=='publie'){
67
-		if ($postdate){
66
+	elseif ($modifs['statut'] == 'publie') {
67
+		if ($postdate) {
68 68
 			calculer_prochain_postdate(true);
69
-			$neuf |= (strtotime($postdate)<=time()); // par securite
69
+			$neuf |= (strtotime($postdate) <= time()); // par securite
70 70
 		}
71 71
 		else
72 72
 			$neuf |= publier_branche_rubrique($id_rubrique);
@@ -121,14 +121,14 @@  discard block
 block discarded – undo
121 121
  * @return bool
122 122
  *     true si le statut change effectivement
123 123
  */
124
-function depublier_branche_rubrique_if($id_rubrique){
124
+function depublier_branche_rubrique_if($id_rubrique) {
125 125
 	$date = date('Y-m-d H:i:s'); // figer la date
126 126
 
127 127
 	#	spip_log("depublier_branche_rubrique($id_rubrique ?");
128 128
 	$id_pred = $id_rubrique;
129 129
 	while ($id_pred) {
130 130
 
131
-		if (!depublier_rubrique_if($id_pred,$date))
131
+		if (!depublier_rubrique_if($id_pred, $date))
132 132
 			return $id_pred != $id_rubrique;
133 133
 		// passer au parent si on a depublie
134 134
 		$r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=$id_pred");
@@ -149,27 +149,27 @@  discard block
 block discarded – undo
149 149
  * @return bool
150 150
  *    true si la rubrique a été dépubliée
151 151
  */
152
-function depublier_rubrique_if($id_rubrique,$date=null){
152
+function depublier_rubrique_if($id_rubrique, $date = null) {
153 153
 	if (is_null($date)) {
154 154
 		$date = date('Y-m-d H:i:s');
155 155
 	}
156 156
 	$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
157 157
 		" AND date <= ".sql_quote($date) : '';
158 158
 
159
-	if (!$id_rubrique=intval($id_rubrique))
159
+	if (!$id_rubrique = intval($id_rubrique))
160 160
 		return false;
161 161
 
162 162
 	// verifier qu'elle existe et est bien publiee
163
-	$r = sql_fetsel('id_rubrique,statut','spip_rubriques',"id_rubrique=$id_rubrique");
164
-	if (!$r OR $r['statut']!=='publie')
163
+	$r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', "id_rubrique=$id_rubrique");
164
+	if (!$r OR $r['statut'] !== 'publie')
165 165
 		return false;
166 166
 
167 167
 	// On met le nombre de chaque type d'enfants dans un tableau
168 168
 	// Le type de l'objet est au pluriel
169 169
 	$compte = array(
170
-		'articles' => sql_countsel("spip_articles",  "id_rubrique=$id_rubrique AND statut='publie'$postdates"),
171
-		'rubriques' => sql_countsel("spip_rubriques",  "id_parent=$id_rubrique AND statut='publie'"),
172
-		'documents' => sql_countsel("spip_documents_liens",  "id_objet=$id_rubrique AND objet='rubrique'")
170
+		'articles' => sql_countsel("spip_articles", "id_rubrique=$id_rubrique AND statut='publie'$postdates"),
171
+		'rubriques' => sql_countsel("spip_rubriques", "id_parent=$id_rubrique AND statut='publie'"),
172
+		'documents' => sql_countsel("spip_documents_liens", "id_objet=$id_rubrique AND objet='rubrique'")
173 173
 	);
174 174
 	
175 175
 	// On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 	);
187 187
 	
188 188
 	// S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas
189
-	foreach($compte as $objet => $n)
189
+	foreach ($compte as $objet => $n)
190 190
 		if ($n)
191 191
 			return false;
192 192
 
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 		$continuer = false;
268 268
 		$r = sql_select("R.id_rubrique AS id, max(A.date_tmp) AS date_h", "spip_rubriques AS R, spip_rubriques AS A", "R.id_rubrique = A.id_parent AND (R.date_tmp < A.date_tmp OR R.statut_tmp<>'publie') AND A.statut_tmp='publie' ", "R.id_rubrique");
269 269
 		while ($row = sql_fetch($r)) {
270
-		  sql_updateq('spip_rubriques', array('statut_tmp'=>'publie', 'date_tmp'=>$row['date_h']),"id_rubrique=".$row['id']);
270
+		  sql_updateq('spip_rubriques', array('statut_tmp'=>'publie', 'date_tmp'=>$row['date_h']), "id_rubrique=".$row['id']);
271 271
 			$continuer = true;
272 272
 		}
273 273
 	} while ($continuer);
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 	// Profondeur 0
291 291
 	// Toutes les rubriques racines sont de profondeur 0
292 292
 	// et fixer les id_secteur des rubriques racines
293
-	sql_update('spip_rubriques', array('id_secteur'=>'id_rubrique','profondeur'=>0), "id_parent=0");
293
+	sql_update('spip_rubriques', array('id_secteur'=>'id_rubrique', 'profondeur'=>0), "id_parent=0");
294 294
 	// Toute rubrique non racine est de profondeur >0
295 295
 	sql_updateq('spip_rubriques', array('profondeur'=>1), "id_parent<>0 AND profondeur=0");
296 296
 
@@ -318,21 +318,21 @@  discard block
 block discarded – undo
318 318
 			"A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur",
319 319
 			"spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique",
320 320
 			"R.profondeur=".intval($prof)." AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)",
321
-		  "","R.id_secteur","0,100")){
321
+		  "", "R.id_secteur", "0,100")) {
322 322
 
323 323
 			$id_secteur = null;
324 324
 			$ids = array();
325 325
 			while ($row = array_shift($rows)) {
326
-				if ($row['id_secteur']!==$id_secteur){
326
+				if ($row['id_secteur'] !== $id_secteur) {
327 327
 					if (count($ids))
328
-						sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur,'profondeur' => $prof+1), sql_in('id_rubrique',$ids));
328
+						sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1), sql_in('id_rubrique', $ids));
329 329
 					$id_secteur = $row['id_secteur'];
330 330
 					$ids = array();
331 331
 				}
332 332
 				$ids[] = $row['id'];
333 333
 			}
334 334
 			if (count($ids))
335
-				sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur,'profondeur' => $prof+1), sql_in('id_rubrique',$ids));
335
+				sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur, 'profondeur' => $prof + 1), sql_in('id_rubrique', $ids));
336 336
 		}
337 337
 
338 338
 
@@ -342,16 +342,16 @@  discard block
 block discarded – undo
342 342
 			AND $rows = sql_allfetsel(
343 343
 			"id_rubrique as id",
344 344
 			"spip_rubriques",
345
-			"profondeur=".intval($prof+1)." AND id_parent NOT IN (".sql_get_select("zzz.id_rubrique","spip_rubriques AS zzz","zzz.profondeur=".intval($prof)).")",'','','0,100')){
346
-			$rows = array_map('reset',$rows);
347
-			sql_updateq("spip_rubriques", array('profondeur' => $prof+2), sql_in("id_rubrique",$rows));
345
+			"profondeur=".intval($prof + 1)." AND id_parent NOT IN (".sql_get_select("zzz.id_rubrique", "spip_rubriques AS zzz", "zzz.profondeur=".intval($prof)).")", '', '', '0,100')) {
346
+			$rows = array_map('reset', $rows);
347
+			sql_updateq("spip_rubriques", array('profondeur' => $prof + 2), sql_in("id_rubrique", $rows));
348 348
 		}
349 349
 
350 350
 		// ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK
351 351
 		// si pas de rubrique a profondeur $prof+1 pas la peine de continuer
352 352
 		// si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse)
353 353
 		// on arrete les frais
354
-		if (sql_countsel("spip_rubriques","profondeur=".intval($prof+1))){
354
+		if (sql_countsel("spip_rubriques", "profondeur=".intval($prof + 1))) {
355 355
 			$prof++;
356 356
 			$continuer = true;
357 357
 		}
@@ -360,9 +360,9 @@  discard block
 block discarded – undo
360 360
 
361 361
 	// loger si la table des rubriques semble foireuse
362 362
 	// et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles
363
-	if (sql_countsel("spip_rubriques","profondeur>".intval($prof+1))){
364
-		spip_log("Les rubriques de profondeur>".($prof+1)." semblent suspectes (branches morte ou reference circulaire dans les parents)",_LOG_CRITIQUE);
365
-		sql_update("spip_rubriques",array('id_secteur'=>0),"profondeur>".intval($prof+1));
363
+	if (sql_countsel("spip_rubriques", "profondeur>".intval($prof + 1))) {
364
+		spip_log("Les rubriques de profondeur>".($prof + 1)." semblent suspectes (branches morte ou reference circulaire dans les parents)", _LOG_CRITIQUE);
365
+		sql_update("spip_rubriques", array('id_secteur'=>0), "profondeur>".intval($prof + 1));
366 366
 	}
367 367
 
368 368
 	// reparer les articles
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
 	}
374 374
 
375 375
 	// avertir les plugins qui peuvent faire leur mises a jour egalement
376
-	pipeline('trig_propager_les_secteurs','');
376
+	pipeline('trig_propager_les_secteurs', '');
377 377
 }
378 378
 
379 379
 
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 	}
432 432
 	
433 433
 	// avertir les plugins qui peuvent faire leur mises a jour egalement
434
-	pipeline('trig_calculer_langues_rubriques','');
434
+	pipeline('trig_calculer_langues_rubriques', '');
435 435
 }
436 436
 
437 437
 
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
  * @return string
448 448
  *    Liste des langues utilisées séparées par des virgules
449 449
 **/
450
-function calculer_langues_utilisees ($serveur='') {
450
+function calculer_langues_utilisees($serveur = '') {
451 451
 	include_spip('public/interfaces');
452 452
 	include_spip('public/compiler');
453 453
 	include_spip('public/composer');
@@ -457,14 +457,14 @@  discard block
 block discarded – undo
457 457
 
458 458
 	include_spip('base/objets');
459 459
 	$tables = lister_tables_objets_sql();
460
-	$trouver_table = charger_fonction('trouver_table','base');
460
+	$trouver_table = charger_fonction('trouver_table', 'base');
461 461
 
462
-	foreach(array_keys($tables) as $t){
463
-		$desc = $trouver_table($t,$serveur);
462
+	foreach (array_keys($tables) as $t) {
463
+		$desc = $trouver_table($t, $serveur);
464 464
 		// c'est une table avec des langues
465 465
 		if ($desc['exist']
466 466
 		  AND isset($desc['field']['lang'])
467
-			AND isset($desc['field']['langue_choisie'])){
467
+			AND isset($desc['field']['langue_choisie'])) {
468 468
 
469 469
 			$boucle = new Boucle();
470 470
 			$boucle->show = $desc;
@@ -477,12 +477,12 @@  discard block
 block discarded – undo
477 477
 			$boucle = pipeline('pre_boucle', $boucle);
478 478
 			
479 479
 			if (isset($desc['statut'])
480
-		    AND $desc['statut']){
480
+		    AND $desc['statut']) {
481 481
 				instituer_boucle($boucle, false);
482
-				$res = calculer_select($boucle->select,$boucle->from,$boucle->from_type,$boucle->where,$boucle->join,$boucle->group,$boucle->order,$boucle->limit,$boucle->having,$desc['table_objet'],$desc['table_objet'],$serveur);
482
+				$res = calculer_select($boucle->select, $boucle->from, $boucle->from_type, $boucle->where, $boucle->join, $boucle->group, $boucle->order, $boucle->limit, $boucle->having, $desc['table_objet'], $desc['table_objet'], $serveur);
483 483
 			}
484 484
 			else
485
-				$res = sql_select(implode(',',$boucle->select),$boucle->from);
485
+				$res = sql_select(implode(',', $boucle->select), $boucle->from);
486 486
 			while ($row = sql_fetch($res)) {
487 487
 				$langues[$row['lang']] = 1;
488 488
 			}
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
 
492 492
 	$langues = array_filter(array_keys($langues));
493 493
 	sort($langues);
494
-	$langues = join(',',$langues);
494
+	$langues = join(',', $langues);
495 495
 	spip_log("langues utilisees: $langues");
496 496
 	return $langues;
497 497
 }
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
  * @param string|int|array $generation
508 508
  * @return string
509 509
  */
510
-function calcul_branche ($generation) {return calcul_branche_in($generation);}
510
+function calcul_branche($generation) {return calcul_branche_in($generation); }
511 511
 
512 512
 /**
513 513
  * Calcul d'une branche de rubrique
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
  *     incluant les rubriques noeuds et toutes leurs descendances
524 524
  */
525 525
 function calcul_branche_in($id) {
526
-	$calcul_branche_in = charger_fonction('calcul_branche_in','inc');
526
+	$calcul_branche_in = charger_fonction('calcul_branche_in', 'inc');
527 527
 	return $calcul_branche_in($id);
528 528
 }
529 529
 
@@ -541,8 +541,8 @@  discard block
 block discarded – undo
541 541
  *     Liste des identifiants séparés par des virgules,
542 542
  *     incluant les rubriques transmises et toutes leurs parentées
543 543
  */
544
-function calcul_hierarchie_in($id, $tout=true) {
545
-	$calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in','inc');
544
+function calcul_hierarchie_in($id, $tout = true) {
545
+	$calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc');
546 546
 	return $calcul_hierarchie_in($id, $tout);
547 547
 }
548 548
 
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 	static $b = array();
566 566
 
567 567
 	// normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
568
-	if (!is_array($id)) $id = explode(',',$id);
568
+	if (!is_array($id)) $id = explode(',', $id);
569 569
 	$id = join(',', array_map('intval', $id));
570 570
 	if (isset($b[$id]))
571 571
 		return $b[$id];
@@ -579,14 +579,14 @@  discard block
 block discarded – undo
579 579
 	while ($maxiter-- AND $filles = sql_allfetsel(
580 580
 					'id_rubrique',
581 581
 					'spip_rubriques',
582
-					sql_in('id_parent', $r) ." AND ". sql_in('id_rubrique', $r, 'NOT')
582
+					sql_in('id_parent', $r)." AND ".sql_in('id_rubrique', $r, 'NOT')
583 583
 					)) {
584 584
 		$r = join(',', array_map('reset', $filles));
585
-		$branche .= ',' . $r;
585
+		$branche .= ','.$r;
586 586
 	}
587 587
 
588 588
 	# securite pour ne pas plomber la conso memoire sur les sites prolifiques
589
-	if (strlen($branche)<10000)
589
+	if (strlen($branche) < 10000)
590 590
 		$b[$id] = $branche;
591 591
 	return $branche;
592 592
 }
@@ -607,16 +607,16 @@  discard block
 block discarded – undo
607 607
  *     Liste des identifiants séparés par des virgules,
608 608
  *     incluant les rubriques transmises et toutes leurs parentées
609 609
  */
610
-function inc_calcul_hierarchie_in_dist($id, $tout=true) {
610
+function inc_calcul_hierarchie_in_dist($id, $tout = true) {
611 611
 	static $b = array();
612 612
 
613 613
 	// normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
614
-	if (!is_array($id)) $id = explode(',',$id);
614
+	if (!is_array($id)) $id = explode(',', $id);
615 615
 	$id = join(',', array_map('intval', $id));
616 616
 
617 617
 	if (isset($b[$id])) {
618 618
 		// Notre branche commence par la rubrique de depart si $tout=true
619
-		return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id];
619
+		return $tout ? (strlen($b[$id]) ? $b[$id].",$id" : $id) : $b[$id];
620 620
 	}
621 621
 
622 622
 	$hier = "";
@@ -628,14 +628,14 @@  discard block
 block discarded – undo
628 628
 	while ($maxiter-- AND $parents = sql_allfetsel(
629 629
 			'id_parent',
630 630
 			'spip_rubriques',
631
-			sql_in('id_rubrique', $ids_nouveaux_parents) ." AND ". sql_in('id_parent',$hier,'NOT')
631
+			sql_in('id_rubrique', $ids_nouveaux_parents)." AND ".sql_in('id_parent', $hier, 'NOT')
632 632
 		  )) {
633 633
 		$ids_nouveaux_parents = join(',', array_map('reset', $parents));
634
-		$hier = $ids_nouveaux_parents.(strlen($hier)?','.$hier:'');
634
+		$hier = $ids_nouveaux_parents.(strlen($hier) ? ','.$hier : '');
635 635
 	}
636 636
 
637 637
 	# securite pour ne pas plomber la conso memoire sur les sites prolifiques
638
-	if (strlen($hier)<10000) {
638
+	if (strlen($hier) < 10000) {
639 639
 		$b[$id] = $hier;
640 640
 	}
641 641
 
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
  *     true pour affecter le statut des rubriques concernées.
658 658
  * @return void
659 659
 **/
660
-function calculer_prochain_postdate($check= false) {
660
+function calculer_prochain_postdate($check = false) {
661 661
 	include_spip('base/abstract_sql');
662 662
 	if ($check) {
663 663
 		$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
@@ -668,15 +668,15 @@  discard block
 block discarded – undo
668 668
 		while ($row = sql_fetch($r))
669 669
 			publier_branche_rubrique($row['id']);
670 670
 
671
-		pipeline('trig_calculer_prochain_postdate','');
671
+		pipeline('trig_calculer_prochain_postdate', '');
672 672
 	}
673 673
 
674 674
 	$t = sql_fetsel("date", "spip_articles", "statut='publie' AND date > ".sql_quote(date('Y-m-d H:i:s')), "", "date", "1");
675 675
 	
676 676
 	if ($t) {
677
-		$t =  $t['date'];
677
+		$t = $t['date'];
678 678
 		if (!isset($GLOBALS['meta']['date_prochain_postdate'])
679
-			OR $t<>$GLOBALS['meta']['date_prochain_postdate']){
679
+			OR $t <> $GLOBALS['meta']['date_prochain_postdate']) {
680 680
 			ecrire_meta('date_prochain_postdate', strtotime($t));
681 681
 			ecrire_meta('derniere_modif', time());
682 682
 		}
@@ -709,16 +709,16 @@  discard block
 block discarded – undo
709 709
  * @return int
710 710
  *     Identifiant de la rubrique la plus profonde.
711 711
  */
712
-function creer_rubrique_nommee($titre, $id_parent=0, $serveur='') {
712
+function creer_rubrique_nommee($titre, $id_parent = 0, $serveur = '') {
713 713
 
714 714
 	// eclater l'arborescence demandee
715 715
 	// echapper les </multi> et autres balises fermantes html
716
-	$titre = preg_replace(",</([a-z][^>]*)>,ims","<@\\1>",$titre);
716
+	$titre = preg_replace(",</([a-z][^>]*)>,ims", "<@\\1>", $titre);
717 717
 	$arbo = explode('/', preg_replace(',^/,', '', $titre));
718 718
 	include_spip('base/abstract_sql');
719 719
 	foreach ($arbo as $titre) {
720 720
 		// retablir les </multi> et autres balises fermantes html
721
-		$titre = preg_replace(",<@([a-z][^>]*)>,ims","</\\1>",$titre);
721
+		$titre = preg_replace(",<@([a-z][^>]*)>,ims", "</\\1>", $titre);
722 722
 		$r = sql_getfetsel("id_rubrique", "spip_rubriques", "titre = ".sql_quote($titre)." AND id_parent=".intval($id_parent),
723 723
 		$groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur);
724 724
 		if ($r !== NULL) {
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
 				'titre' => $titre,
729 729
 				'id_parent' => $id_parent,
730 730
 				'statut' => 'prive')
731
-				,$desc=array(), $serveur);
731
+				,$desc = array(), $serveur);
732 732
 			if ($id_parent > 0) {
733 733
 				$data = sql_fetsel("id_secteur,lang", "spip_rubriques", "id_rubrique=$id_parent",
734 734
 				$groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur);
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
 				$lang = $GLOBALS['meta']['langue_site'];
740 740
 			}
741 741
 
742
-			sql_updateq('spip_rubriques', array('id_secteur'=>$id_secteur, "lang"=>$lang), "id_rubrique=$id_rubrique", $desc='', $serveur);
742
+			sql_updateq('spip_rubriques', array('id_secteur'=>$id_secteur, "lang"=>$lang), "id_rubrique=$id_rubrique", $desc = '', $serveur);
743 743
 
744 744
 			// pour la recursion
745 745
 			$id_parent = $id_rubrique;
Please login to merge, or discard this patch.
Braces   +56 added lines, -38 removed lines patch added patch discarded remove patch
@@ -16,7 +16,9 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Rubriques
17 17
  */
18 18
  
19
-if (!defined('_ECRIRE_INC_VERSION')) return;
19
+if (!defined('_ECRIRE_INC_VERSION')) {
20
+    return;
21
+}
20 22
 
21 23
 
22 24
 /**
@@ -53,28 +55,29 @@  discard block
 block discarded – undo
53 55
 	if ($statut_ancien == 'publie') {
54 56
 		if (isset($modifs['statut'])
55 57
 			OR isset($modifs['id_rubrique'])
56
-			OR ($postdate AND strtotime($postdate)>time()))
57
-			$neuf |= depublier_branche_rubrique_if($id_rubrique);
58
+			OR ($postdate AND strtotime($postdate)>time())) {
59
+					$neuf |= depublier_branche_rubrique_if($id_rubrique);
60
+		}
58 61
 		// ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur
59 62
 		if ($postdate){
60 63
 			calculer_prochain_postdate(true);
61 64
 			$neuf |= (strtotime($postdate)<=time()); // par securite
65
+		} elseif (isset($modifs['id_rubrique'])) {
66
+					$neuf |= publier_branche_rubrique($modifs['id_rubrique']);
62 67
 		}
63
-		elseif (isset($modifs['id_rubrique']))
64
-			$neuf |= publier_branche_rubrique($modifs['id_rubrique']);
65
-	}
66
-	elseif ($modifs['statut']=='publie'){
68
+	} elseif ($modifs['statut']=='publie'){
67 69
 		if ($postdate){
68 70
 			calculer_prochain_postdate(true);
69 71
 			$neuf |= (strtotime($postdate)<=time()); // par securite
72
+		} else {
73
+					$neuf |= publier_branche_rubrique($id_rubrique);
70 74
 		}
71
-		else
72
-			$neuf |= publier_branche_rubrique($id_rubrique);
73 75
 	}
74 76
 
75
-	if ($neuf)
76
-	// Sauver la date de la derniere mise a jour (pour menu_rubriques)
77
+	if ($neuf) {
78
+		// Sauver la date de la derniere mise a jour (pour menu_rubriques)
77 79
 	  ecrire_meta("date_calcul_rubriques", date("U"));
80
+	}
78 81
 
79 82
 	$langues = calculer_langues_utilisees();
80 83
 	ecrire_meta('langues_utilisees', $langues);
@@ -100,7 +103,9 @@  discard block
 block discarded – undo
100 103
 	while (true) {
101 104
 		sql_updateq('spip_rubriques', array('statut'=>'publie', 'date'=>date('Y-m-d H:i:s')), "id_rubrique=$id_rubrique");
102 105
 		$id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', "R.id_rubrique=$id_rubrique");
103
-		if (!$id_parent) break;
106
+		if (!$id_parent) {
107
+		    break;
108
+		}
104 109
 		$id_rubrique = $id_parent;
105 110
 	} 
106 111
 
@@ -128,8 +133,9 @@  discard block
 block discarded – undo
128 133
 	$id_pred = $id_rubrique;
129 134
 	while ($id_pred) {
130 135
 
131
-		if (!depublier_rubrique_if($id_pred,$date))
132
-			return $id_pred != $id_rubrique;
136
+		if (!depublier_rubrique_if($id_pred,$date)) {
137
+					return $id_pred != $id_rubrique;
138
+		}
133 139
 		// passer au parent si on a depublie
134 140
 		$r = sql_fetsel("id_parent", "spip_rubriques", "id_rubrique=$id_pred");
135 141
 		$id_pred = $r['id_parent'];
@@ -156,13 +162,15 @@  discard block
 block discarded – undo
156 162
 	$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
157 163
 		" AND date <= ".sql_quote($date) : '';
158 164
 
159
-	if (!$id_rubrique=intval($id_rubrique))
160
-		return false;
165
+	if (!$id_rubrique=intval($id_rubrique)) {
166
+			return false;
167
+	}
161 168
 
162 169
 	// verifier qu'elle existe et est bien publiee
163 170
 	$r = sql_fetsel('id_rubrique,statut','spip_rubriques',"id_rubrique=$id_rubrique");
164
-	if (!$r OR $r['statut']!=='publie')
165
-		return false;
171
+	if (!$r OR $r['statut']!=='publie') {
172
+			return false;
173
+	}
166 174
 
167 175
 	// On met le nombre de chaque type d'enfants dans un tableau
168 176
 	// Le type de l'objet est au pluriel
@@ -186,9 +194,10 @@  discard block
 block discarded – undo
186 194
 	);
187 195
 	
188 196
 	// S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas
189
-	foreach($compte as $objet => $n)
190
-		if ($n)
197
+	foreach($compte as $objet => $n) {
198
+			if ($n)
191 199
 			return false;
200
+	}
192 201
 
193 202
 	sql_updateq("spip_rubriques", array("statut" => '0'), "id_rubrique=$id_rubrique");
194 203
 #		spip_log("depublier_rubrique $id_pred");
@@ -250,8 +259,9 @@  discard block
 block discarded – undo
250 259
 		"AND A.date <= ".sql_quote(date('Y-m-d H:i:s')) : '';
251 260
 
252 261
 	$r = sql_select("R.id_rubrique AS id, max(A.date) AS date_h", "spip_rubriques AS R, spip_articles AS A", "R.id_rubrique = A.id_rubrique AND A.statut='publie' $postdates ", "R.id_rubrique");
253
-	while ($row = sql_fetch($r))
254
-		sql_updateq("spip_rubriques", array("statut_tmp" => 'publie', "date_tmp" => $row['date_h']), "id_rubrique=".$row['id']);
262
+	while ($row = sql_fetch($r)) {
263
+			sql_updateq("spip_rubriques", array("statut_tmp" => 'publie', "date_tmp" => $row['date_h']), "id_rubrique=".$row['id']);
264
+	}
255 265
 
256 266
 	// point d'entree pour permettre a des plugins de gerer le statut
257 267
 	// autrement (par ex: toute rubrique est publiee des sa creation)
@@ -324,15 +334,17 @@  discard block
 block discarded – undo
324 334
 			$ids = array();
325 335
 			while ($row = array_shift($rows)) {
326 336
 				if ($row['id_secteur']!==$id_secteur){
327
-					if (count($ids))
328
-						sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur,'profondeur' => $prof+1), sql_in('id_rubrique',$ids));
337
+					if (count($ids)) {
338
+											sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur,'profondeur' => $prof+1), sql_in('id_rubrique',$ids));
339
+					}
329 340
 					$id_secteur = $row['id_secteur'];
330 341
 					$ids = array();
331 342
 				}
332 343
 				$ids[] = $row['id'];
333 344
 			}
334
-			if (count($ids))
335
-				sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur,'profondeur' => $prof+1), sql_in('id_rubrique',$ids));
345
+			if (count($ids)) {
346
+							sql_updateq("spip_rubriques", array("id_secteur" => $id_secteur,'profondeur' => $prof+1), sql_in('id_rubrique',$ids));
347
+			}
336 348
 		}
337 349
 
338 350
 
@@ -480,9 +492,9 @@  discard block
 block discarded – undo
480 492
 		    AND $desc['statut']){
481 493
 				instituer_boucle($boucle, false);
482 494
 				$res = calculer_select($boucle->select,$boucle->from,$boucle->from_type,$boucle->where,$boucle->join,$boucle->group,$boucle->order,$boucle->limit,$boucle->having,$desc['table_objet'],$desc['table_objet'],$serveur);
495
+			} else {
496
+							$res = sql_select(implode(',',$boucle->select),$boucle->from);
483 497
 			}
484
-			else
485
-				$res = sql_select(implode(',',$boucle->select),$boucle->from);
486 498
 			while ($row = sql_fetch($res)) {
487 499
 				$langues[$row['lang']] = 1;
488 500
 			}
@@ -565,10 +577,13 @@  discard block
 block discarded – undo
565 577
 	static $b = array();
566 578
 
567 579
 	// normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
568
-	if (!is_array($id)) $id = explode(',',$id);
580
+	if (!is_array($id)) {
581
+	    $id = explode(',',$id);
582
+	}
569 583
 	$id = join(',', array_map('intval', $id));
570
-	if (isset($b[$id]))
571
-		return $b[$id];
584
+	if (isset($b[$id])) {
585
+			return $b[$id];
586
+	}
572 587
 
573 588
 	// Notre branche commence par la rubrique de depart
574 589
 	$branche = $r = $id;
@@ -586,8 +601,9 @@  discard block
 block discarded – undo
586 601
 	}
587 602
 
588 603
 	# securite pour ne pas plomber la conso memoire sur les sites prolifiques
589
-	if (strlen($branche)<10000)
590
-		$b[$id] = $branche;
604
+	if (strlen($branche)<10000) {
605
+			$b[$id] = $branche;
606
+	}
591 607
 	return $branche;
592 608
 }
593 609
 
@@ -611,7 +627,9 @@  discard block
 block discarded – undo
611 627
 	static $b = array();
612 628
 
613 629
 	// normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN
614
-	if (!is_array($id)) $id = explode(',',$id);
630
+	if (!is_array($id)) {
631
+	    $id = explode(',',$id);
632
+	}
615 633
 	$id = join(',', array_map('intval', $id));
616 634
 
617 635
 	if (isset($b[$id])) {
@@ -665,8 +683,9 @@  discard block
 block discarded – undo
665 683
 
666 684
 		$r = sql_select("DISTINCT A.id_rubrique AS id",
667 685
 			"spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique", "R.statut != 'publie' AND A.statut='publie'$postdates");
668
-		while ($row = sql_fetch($r))
669
-			publier_branche_rubrique($row['id']);
686
+		while ($row = sql_fetch($r)) {
687
+					publier_branche_rubrique($row['id']);
688
+		}
670 689
 
671 690
 		pipeline('trig_calculer_prochain_postdate','');
672 691
 	}
@@ -680,8 +699,7 @@  discard block
 block discarded – undo
680 699
 			ecrire_meta('date_prochain_postdate', strtotime($t));
681 700
 			ecrire_meta('derniere_modif', time());
682 701
 		}
683
-	}
684
-	else {
702
+	} else {
685 703
 		effacer_meta('date_prochain_postdate');
686 704
 		ecrire_meta('derniere_modif', time());
687 705
 	}
Please login to merge, or discard this patch.
ecrire/inc/surligne.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -20,6 +20,9 @@
 block discarded – undo
20 20
 
21 21
 
22 22
 // http://doc.spip.org/@surligner_mots
23
+/**
24
+ * @param string $page
25
+ */
23 26
 function surligner_mots($page, $surcharge_surligne = '') {
24 27
 	$surlignejs_engines = array(
25 28
 		array(",".str_replace(array("/", "."), array("\/", "\."), $GLOBALS['meta']['adresse_site']).",i", ",recherche=([^&]+),i"), //SPIP
Please login to merge, or discard this patch.
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -21,39 +21,39 @@  discard block
 block discarded – undo
21 21
 
22 22
 // http://doc.spip.org/@surligner_mots
23 23
 function surligner_mots($page, $surcharge_surligne = '') {
24
-	$surlignejs_engines = array(
25
-		array(",".str_replace(array("/", "."), array("\/", "\."), $GLOBALS['meta']['adresse_site']).",i", ",recherche=([^&]+),i"), //SPIP
26
-		array(",^http://(www\.)?google\.,i", ",q=([^&]+),i"), // Google
27
-		array(",^http://(www\.)?search\.yahoo\.,i", ",p=([^&]+),i"), // Yahoo
28
-		array(",^http://(www\.)?search\.msn\.,i", ",q=([^&]+),i"), // MSN
29
-		array(",^http://(www\.)?search\.live\.,i", ",query=([^&]+),i"), // MSN Live
30
-		array(",^http://(www\.)?search\.aol\.,i", ",userQuery=([^&]+),i"), // AOL
31
-		array(",^http://(www\.)?ask\.com,i", ",q=([^&]+),i"), // Ask.com
32
-		array(",^http://(www\.)?altavista\.,i", ",q=([^&]+),i"), // AltaVista
33
-		array(",^http://(www\.)?feedster\.,i", ",q=([^&]+),i"), // Feedster
34
-		array(",^http://(www\.)?search\.lycos\.,i", ",q=([^&]+),i"), // Lycos
35
-		array(",^http://(www\.)?alltheweb\.,i", ",q=([^&]+),i"), // AllTheWeb
36
-		array(",^http://(www\.)?technorati\.com,i", ",([^\?\/]+)(?:\?.*)$,i"), // Technorati
37
-	);
24
+    $surlignejs_engines = array(
25
+        array(",".str_replace(array("/", "."), array("\/", "\."), $GLOBALS['meta']['adresse_site']).",i", ",recherche=([^&]+),i"), //SPIP
26
+        array(",^http://(www\.)?google\.,i", ",q=([^&]+),i"), // Google
27
+        array(",^http://(www\.)?search\.yahoo\.,i", ",p=([^&]+),i"), // Yahoo
28
+        array(",^http://(www\.)?search\.msn\.,i", ",q=([^&]+),i"), // MSN
29
+        array(",^http://(www\.)?search\.live\.,i", ",query=([^&]+),i"), // MSN Live
30
+        array(",^http://(www\.)?search\.aol\.,i", ",userQuery=([^&]+),i"), // AOL
31
+        array(",^http://(www\.)?ask\.com,i", ",q=([^&]+),i"), // Ask.com
32
+        array(",^http://(www\.)?altavista\.,i", ",q=([^&]+),i"), // AltaVista
33
+        array(",^http://(www\.)?feedster\.,i", ",q=([^&]+),i"), // Feedster
34
+        array(",^http://(www\.)?search\.lycos\.,i", ",q=([^&]+),i"), // Lycos
35
+        array(",^http://(www\.)?alltheweb\.,i", ",q=([^&]+),i"), // AllTheWeb
36
+        array(",^http://(www\.)?technorati\.com,i", ",([^\?\/]+)(?:\?.*)$,i"), // Technorati
37
+    );
38 38
 
39 39
 
40
-	$ref = $_SERVER['HTTP_REFERER'];
41
-	//avoid a js injection
42
-	if ($surcharge_surligne){
43
-		$surcharge_surligne = preg_replace(",(?<!\\\\)((?:(?>\\\\){2})*)('),", "$1\\\\$2", $surcharge_surligne);
44
-		$surcharge_surligne = str_replace("\\", "\\\\", $surcharge_surligne);
45
-		if ($GLOBALS['meta']['charset']=='utf-8'){
46
-			include_spip('inc/charsets');
47
-			if (!is_utf8($surcharge_surligne)) $surcharge_surligne = utf8_encode($surcharge_surligne);
48
-		}
49
-		$surcharge_surligne = preg_replace(',\*$,', '', trim($surcharge_surligne)); # supprimer un * final
50
-	}
51
-	foreach ($surlignejs_engines as $engine)
52
-		if ($surcharge_surligne || (preg_match($engine[0], $ref) && preg_match($engine[1], $ref))){
40
+    $ref = $_SERVER['HTTP_REFERER'];
41
+    //avoid a js injection
42
+    if ($surcharge_surligne){
43
+        $surcharge_surligne = preg_replace(",(?<!\\\\)((?:(?>\\\\){2})*)('),", "$1\\\\$2", $surcharge_surligne);
44
+        $surcharge_surligne = str_replace("\\", "\\\\", $surcharge_surligne);
45
+        if ($GLOBALS['meta']['charset']=='utf-8'){
46
+            include_spip('inc/charsets');
47
+            if (!is_utf8($surcharge_surligne)) $surcharge_surligne = utf8_encode($surcharge_surligne);
48
+        }
49
+        $surcharge_surligne = preg_replace(',\*$,', '', trim($surcharge_surligne)); # supprimer un * final
50
+    }
51
+    foreach ($surlignejs_engines as $engine)
52
+        if ($surcharge_surligne || (preg_match($engine[0], $ref) && preg_match($engine[1], $ref))){
53 53
 
54
-			//good referrer found or var_recherche is not null
55
-			include_spip('inc/filtres');
56
-			$script = "
54
+            //good referrer found or var_recherche is not null
55
+            include_spip('inc/filtres');
56
+            $script = "
57 57
       <script type='text/javascript' src='".url_absolue(find_in_path('javascript/SearchHighlight.js'))."'></script>
58 58
       <script type='text/javascript'>/*<![CDATA[*/
59 59
       if (window.jQuery)
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
             engines:[/^".str_replace(array("/", "."), array("\/", "\."), $GLOBALS['meta']['adresse_site'])."/i,/recherche=([^&]+)/i],
67 67
             highlight:'.surlignable',
68 68
             nohighlight:'.pas_surlignable'".
69
-			          ($surcharge_surligne ? ",
69
+                        ($surcharge_surligne ? ",
70 70
             keys:'$surcharge_surligne'" : "").",
71 71
             min_length: 3
72 72
           })
@@ -74,13 +74,13 @@  discard block
 block discarded – undo
74 74
       })(jQuery);
75 75
       /*]]>*/</script>
76 76
       ";
77
-			// on l'insere juste avant </head>, sinon tout en bas
78
-			if (is_null($l = strpos($page, '</head>')))
79
-				$l = strlen($page);
80
-			$page = substr_replace($page, $script, $l, 0);
81
-			break;
82
-		}
83
-	return $page;
77
+            // on l'insere juste avant </head>, sinon tout en bas
78
+            if (is_null($l = strpos($page, '</head>')))
79
+                $l = strlen($page);
80
+            $page = substr_replace($page, $script, $l, 0);
81
+            break;
82
+        }
83
+    return $page;
84 84
 }
85 85
 
86 86
 ?>
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -39,17 +39,17 @@
 block discarded – undo
39 39
 
40 40
 	$ref = $_SERVER['HTTP_REFERER'];
41 41
 	//avoid a js injection
42
-	if ($surcharge_surligne){
42
+	if ($surcharge_surligne) {
43 43
 		$surcharge_surligne = preg_replace(",(?<!\\\\)((?:(?>\\\\){2})*)('),", "$1\\\\$2", $surcharge_surligne);
44 44
 		$surcharge_surligne = str_replace("\\", "\\\\", $surcharge_surligne);
45
-		if ($GLOBALS['meta']['charset']=='utf-8'){
45
+		if ($GLOBALS['meta']['charset'] == 'utf-8') {
46 46
 			include_spip('inc/charsets');
47 47
 			if (!is_utf8($surcharge_surligne)) $surcharge_surligne = utf8_encode($surcharge_surligne);
48 48
 		}
49 49
 		$surcharge_surligne = preg_replace(',\*$,', '', trim($surcharge_surligne)); # supprimer un * final
50 50
 	}
51 51
 	foreach ($surlignejs_engines as $engine)
52
-		if ($surcharge_surligne || (preg_match($engine[0], $ref) && preg_match($engine[1], $ref))){
52
+		if ($surcharge_surligne || (preg_match($engine[0], $ref) && preg_match($engine[1], $ref))) {
53 53
 
54 54
 			//good referrer found or var_recherche is not null
55 55
 			include_spip('inc/filtres');
Please login to merge, or discard this patch.
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 // Ces commentaires vont etre substitue's en mode recherche
16 18
 // voir balise_DEBUT_SURLIGNE et balise_FIN_SURLIGNE
@@ -44,15 +46,18 @@  discard block
 block discarded – undo
44 46
 		$surcharge_surligne = str_replace("\\", "\\\\", $surcharge_surligne);
45 47
 		if ($GLOBALS['meta']['charset']=='utf-8'){
46 48
 			include_spip('inc/charsets');
47
-			if (!is_utf8($surcharge_surligne)) $surcharge_surligne = utf8_encode($surcharge_surligne);
49
+			if (!is_utf8($surcharge_surligne)) {
50
+			    $surcharge_surligne = utf8_encode($surcharge_surligne);
51
+			}
48 52
 		}
49 53
 		$surcharge_surligne = preg_replace(',\*$,', '', trim($surcharge_surligne)); # supprimer un * final
50 54
 	}
51
-	foreach ($surlignejs_engines as $engine)
52
-		if ($surcharge_surligne || (preg_match($engine[0], $ref) && preg_match($engine[1], $ref))){
55
+	foreach ($surlignejs_engines as $engine) {
56
+			if ($surcharge_surligne || (preg_match($engine[0], $ref) && preg_match($engine[1], $ref))){
53 57
 
54 58
 			//good referrer found or var_recherche is not null
55 59
 			include_spip('inc/filtres');
60
+	}
56 61
 			$script = "
57 62
       <script type='text/javascript' src='".url_absolue(find_in_path('javascript/SearchHighlight.js'))."'></script>
58 63
       <script type='text/javascript'>/*<![CDATA[*/
@@ -75,8 +80,9 @@  discard block
 block discarded – undo
75 80
       /*]]>*/</script>
76 81
       ";
77 82
 			// on l'insere juste avant </head>, sinon tout en bas
78
-			if (is_null($l = strpos($page, '</head>')))
79
-				$l = strlen($page);
83
+			if (is_null($l = strpos($page, '</head>'))) {
84
+							$l = strlen($page);
85
+			}
80 86
 			$page = substr_replace($page, $script, $l, 0);
81 87
 			break;
82 88
 		}
Please login to merge, or discard this patch.
ecrire/inc/texte.php 4 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -65,6 +65,9 @@  discard block
 block discarded – undo
65 65
 
66 66
 // afficher joliment les <script>
67 67
 // http://doc.spip.org/@echappe_js
68
+/**
69
+ * @param string $t
70
+ */
68 71
 function echappe_js($t,$class=' class="echappe-js"') {
69 72
 	if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER))
70 73
 	foreach ($r as $regs)
@@ -256,6 +259,9 @@  discard block
 block discarded – undo
256 259
 //
257 260
 // http://doc.spip.org/@paragrapher
258 261
 // /!\ appelee dans inc/filtres et public/composer
262
+/**
263
+ * @param string $letexte
264
+ */
259 265
 function paragrapher($letexte, $forcer=true) {
260 266
 	return $letexte;
261 267
 }
Please login to merge, or discard this patch.
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 // Raccourcis dependant du sens de la langue
24 24
 function definir_raccourcis_alineas(){
25
-	return array('','');
25
+    return array('','');
26 26
 }
27 27
 
28 28
 
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 //
32 32
 // http://doc.spip.org/@traiter_tableau
33 33
 function traiter_tableau($bloc) {
34
-	return $bloc;
34
+    return $bloc;
35 35
 }
36 36
 
37 37
 
@@ -40,23 +40,23 @@  discard block
 block discarded – undo
40 40
 //
41 41
 // http://doc.spip.org/@traiter_listes
42 42
 function traiter_listes ($texte) {
43
-	return $texte;
43
+    return $texte;
44 44
 }
45 45
 
46 46
 // Nettoie un texte, traite les raccourcis autre qu'URL, la typo, etc.
47 47
 // http://doc.spip.org/@traiter_raccourcis
48 48
 function traiter_raccourcis($letexte) {
49 49
 
50
-	// Appeler les fonctions de pre_traitement
51
-	$letexte = pipeline('pre_propre', $letexte);
50
+    // Appeler les fonctions de pre_traitement
51
+    $letexte = pipeline('pre_propre', $letexte);
52 52
 
53
-	// APPELER ICI UN PIPELINE traiter_raccourcis ?
54
-	// $letexte = pipeline('traiter_raccourcis', $letexte);
53
+    // APPELER ICI UN PIPELINE traiter_raccourcis ?
54
+    // $letexte = pipeline('traiter_raccourcis', $letexte);
55 55
 
56
-	// Appeler les fonctions de post-traitement
57
-	$letexte = pipeline('post_propre', $letexte);
56
+    // Appeler les fonctions de post-traitement
57
+    $letexte = pipeline('post_propre', $letexte);
58 58
 
59
-	return $letexte;
59
+    return $letexte;
60 60
 }
61 61
 
62 62
 /*************************************************************************************************************************
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 // afficher joliment les <script>
67 67
 // http://doc.spip.org/@echappe_js
68 68
 function echappe_js($t,$class=' class="echappe-js"') {
69
-	if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER))
70
-	foreach ($r as $regs)
71
-		$t = str_replace($regs[0],
72
-			"<code$class>".nl2br(spip_htmlspecialchars($regs[0])).'</code>',
73
-			$t);
74
-	return $t;
69
+    if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER))
70
+    foreach ($r as $regs)
71
+        $t = str_replace($regs[0],
72
+            "<code$class>".nl2br(spip_htmlspecialchars($regs[0])).'</code>',
73
+            $t);
74
+    return $t;
75 75
 }
76 76
 
77 77
 
@@ -98,44 +98,44 @@  discard block
 block discarded – undo
98 98
  *     Code protégé
99 99
 **/
100 100
 function interdire_scripts($arg) {
101
-	// on memorise le resultat sur les arguments non triviaux
102
-	static $dejavu = array();
101
+    // on memorise le resultat sur les arguments non triviaux
102
+    static $dejavu = array();
103 103
 
104
-	// Attention, si ce n'est pas une chaine, laisser intact
105
-	if (!$arg OR !is_string($arg) OR !strstr($arg, '<')) return $arg; 
104
+    // Attention, si ce n'est pas une chaine, laisser intact
105
+    if (!$arg OR !is_string($arg) OR !strstr($arg, '<')) return $arg; 
106 106
 
107
-	if (isset($dejavu[$GLOBALS['filtrer_javascript']][$arg])) return $dejavu[$GLOBALS['filtrer_javascript']][$arg];
107
+    if (isset($dejavu[$GLOBALS['filtrer_javascript']][$arg])) return $dejavu[$GLOBALS['filtrer_javascript']][$arg];
108 108
 
109
-	// echapper les tags asp/php
110
-	$t = str_replace('<'.'%', '&lt;%', $arg);
109
+    // echapper les tags asp/php
110
+    $t = str_replace('<'.'%', '&lt;%', $arg);
111 111
 
112
-	// echapper le php
113
-	$t = str_replace('<'.'?', '&lt;?', $t);
112
+    // echapper le php
113
+    $t = str_replace('<'.'?', '&lt;?', $t);
114 114
 
115
-	// echapper le < script language=php >
116
-	$t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '&lt;\1', $t);
115
+    // echapper le < script language=php >
116
+    $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '&lt;\1', $t);
117 117
 
118
-	// Pour le js, trois modes : parano (-1), prive (0), ok (1)
119
-	switch($GLOBALS['filtrer_javascript']) {
120
-		case 0:
121
-			if (!_DIR_RESTREINT)
122
-				$t = echappe_js($t);
123
-			break;
124
-		case -1:
125
-			$t = echappe_js($t);
126
-			break;
127
-	}
118
+    // Pour le js, trois modes : parano (-1), prive (0), ok (1)
119
+    switch($GLOBALS['filtrer_javascript']) {
120
+        case 0:
121
+            if (!_DIR_RESTREINT)
122
+                $t = echappe_js($t);
123
+            break;
124
+        case -1:
125
+            $t = echappe_js($t);
126
+            break;
127
+    }
128 128
 
129
-	// pas de <base href /> svp !
130
-	$t = preg_replace(',<(base\b),iS', '&lt;\1', $t);
129
+    // pas de <base href /> svp !
130
+    $t = preg_replace(',<(base\b),iS', '&lt;\1', $t);
131 131
 
132
-	// Reinserer les echappements des modeles
133
-	if (defined('_PROTEGE_JS_MODELES'))
134
-		$t = echappe_retour($t,"javascript"._PROTEGE_JS_MODELES);
135
-	if (defined('_PROTEGE_PHP_MODELES'))
136
-		$t = echappe_retour($t,"php"._PROTEGE_PHP_MODELES);
132
+    // Reinserer les echappements des modeles
133
+    if (defined('_PROTEGE_JS_MODELES'))
134
+        $t = echappe_retour($t,"javascript"._PROTEGE_JS_MODELES);
135
+    if (defined('_PROTEGE_PHP_MODELES'))
136
+        $t = echappe_retour($t,"php"._PROTEGE_PHP_MODELES);
137 137
 
138
-	return $dejavu[$GLOBALS['filtrer_javascript']][$arg] = $t;
138
+    return $dejavu[$GLOBALS['filtrer_javascript']][$arg] = $t;
139 139
 }
140 140
 
141 141
 // Typographie generale
@@ -143,54 +143,54 @@  discard block
 block discarded – undo
143 143
 
144 144
 // http://doc.spip.org/@typo
145 145
 function typo($letexte, $echapper=true, $connect=null, $env=array()) {
146
-	// Plus vite !
147
-	if (!$letexte) return $letexte;
148
-
149
-	// les appels directs a cette fonction depuis le php de l'espace
150
-	// prive etant historiquement ecrit sans argment $connect
151
-	// on utilise la presence de celui-ci pour distinguer les cas
152
-	// ou il faut passer interdire_script explicitement
153
-	// les appels dans les squelettes (de l'espace prive) fournissant un $connect
154
-	// ne seront pas perturbes
155
-	$interdire_script = false;
156
-	if (is_null($connect)){
157
-		$connect = '';
158
-		$interdire_script = true;
159
-		$env['espace_prive'] = 1;
160
-	}
161
-
162
-	// Echapper les codes <html> etc
163
-	if ($echapper)
164
-		$letexte = echappe_html($letexte, 'TYPO');
165
-
166
-	//
167
-	// Installer les modeles, notamment images et documents ;
168
-	//
169
-	// NOTE : propre() ne passe pas par ici mais directement par corriger_typo
170
-	// cf. inc/lien
171
-
172
-	$letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env);
173
-	if ($letexte != $mem) $echapper = true;
174
-	unset($mem);
175
-
176
-	$letexte = corriger_typo($letexte);
177
-	$letexte = echapper_faux_tags($letexte);
178
-
179
-	// reintegrer les echappements
180
-	if ($echapper)
181
-		$letexte = echappe_retour($letexte, 'TYPO');
182
-
183
-	// Dans les appels directs hors squelette, securiser ici aussi
184
-	if ($interdire_script)
185
-		$letexte = interdire_scripts($letexte);
186
-
187
-	// Dans l'espace prive on se mefie de tout contenu dangereux
188
-	// https://core.spip.net/issues/3371
189
-	if (isset($env['espace_prive']) AND $env['espace_prive']){
190
-		$letexte = echapper_html_suspect($letexte);
191
-	}
192
-
193
-	return $letexte;
146
+    // Plus vite !
147
+    if (!$letexte) return $letexte;
148
+
149
+    // les appels directs a cette fonction depuis le php de l'espace
150
+    // prive etant historiquement ecrit sans argment $connect
151
+    // on utilise la presence de celui-ci pour distinguer les cas
152
+    // ou il faut passer interdire_script explicitement
153
+    // les appels dans les squelettes (de l'espace prive) fournissant un $connect
154
+    // ne seront pas perturbes
155
+    $interdire_script = false;
156
+    if (is_null($connect)){
157
+        $connect = '';
158
+        $interdire_script = true;
159
+        $env['espace_prive'] = 1;
160
+    }
161
+
162
+    // Echapper les codes <html> etc
163
+    if ($echapper)
164
+        $letexte = echappe_html($letexte, 'TYPO');
165
+
166
+    //
167
+    // Installer les modeles, notamment images et documents ;
168
+    //
169
+    // NOTE : propre() ne passe pas par ici mais directement par corriger_typo
170
+    // cf. inc/lien
171
+
172
+    $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env);
173
+    if ($letexte != $mem) $echapper = true;
174
+    unset($mem);
175
+
176
+    $letexte = corriger_typo($letexte);
177
+    $letexte = echapper_faux_tags($letexte);
178
+
179
+    // reintegrer les echappements
180
+    if ($echapper)
181
+        $letexte = echappe_retour($letexte, 'TYPO');
182
+
183
+    // Dans les appels directs hors squelette, securiser ici aussi
184
+    if ($interdire_script)
185
+        $letexte = interdire_scripts($letexte);
186
+
187
+    // Dans l'espace prive on se mefie de tout contenu dangereux
188
+    // https://core.spip.net/issues/3371
189
+    if (isset($env['espace_prive']) AND $env['espace_prive']){
190
+        $letexte = echapper_html_suspect($letexte);
191
+    }
192
+
193
+    return $letexte;
194 194
 }
195 195
 
196 196
 // Correcteur typographique
@@ -202,46 +202,46 @@  discard block
 block discarded – undo
202 202
 // http://doc.spip.org/@corriger_typo
203 203
 function corriger_typo($letexte, $lang='') {
204 204
 
205
-	// Plus vite !
206
-	if (!$letexte) return $letexte;
205
+    // Plus vite !
206
+    if (!$letexte) return $letexte;
207 207
 
208
-	$letexte = pipeline('pre_typo', $letexte);
208
+    $letexte = pipeline('pre_typo', $letexte);
209 209
 
210
-	// Caracteres de controle "illegaux"
211
-	$letexte = corriger_caracteres($letexte);
210
+    // Caracteres de controle "illegaux"
211
+    $letexte = corriger_caracteres($letexte);
212 212
 
213
-	// Proteger les caracteres typographiques a l'interieur des tags html
214
-	if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) {
215
-		foreach ($regs as $reg) {
216
-			$insert = $reg[0];
217
-			// hack: on transforme les caracteres a proteger en les remplacant
218
-			// par des caracteres "illegaux". (cf corriger_caracteres())
219
-			$insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR);
220
-			$letexte = str_replace($reg[0], $insert, $letexte);
221
-		}
222
-	}
213
+    // Proteger les caracteres typographiques a l'interieur des tags html
214
+    if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) {
215
+        foreach ($regs as $reg) {
216
+            $insert = $reg[0];
217
+            // hack: on transforme les caracteres a proteger en les remplacant
218
+            // par des caracteres "illegaux". (cf corriger_caracteres())
219
+            $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR);
220
+            $letexte = str_replace($reg[0], $insert, $letexte);
221
+        }
222
+    }
223 223
 
224
-	// trouver les blocs multi et les traiter a part
225
-	$letexte = extraire_multi($e = $letexte, $lang, true);
226
-	$e = ($e === $letexte);
224
+    // trouver les blocs multi et les traiter a part
225
+    $letexte = extraire_multi($e = $letexte, $lang, true);
226
+    $e = ($e === $letexte);
227 227
 
228
-	// Charger & appliquer les fonctions de typographie
229
-	$typographie = charger_fonction(lang_typo($lang), 'typographie');
230
-	$letexte = $typographie($letexte);
228
+    // Charger & appliquer les fonctions de typographie
229
+    $typographie = charger_fonction(lang_typo($lang), 'typographie');
230
+    $letexte = $typographie($letexte);
231 231
 
232
-	// Les citations en une autre langue, s'il y a lieu
233
-	if (!$e) $letexte = echappe_retour($letexte, 'multi');
232
+    // Les citations en une autre langue, s'il y a lieu
233
+    if (!$e) $letexte = echappe_retour($letexte, 'multi');
234 234
 
235
-	// Retablir les caracteres proteges
236
-	$letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER);
235
+    // Retablir les caracteres proteges
236
+    $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER);
237 237
 
238
-	// pipeline
239
-	$letexte = pipeline('post_typo', $letexte);
238
+    // pipeline
239
+    $letexte = pipeline('post_typo', $letexte);
240 240
 
241
-	# un message pour abs_url - on est passe en mode texte
242
-	$GLOBALS['mode_abs_url'] = 'texte';
241
+    # un message pour abs_url - on est passe en mode texte
242
+    $GLOBALS['mode_abs_url'] = 'texte';
243 243
 
244
-	return $letexte;
244
+    return $letexte;
245 245
 }
246 246
 
247 247
 
@@ -257,43 +257,43 @@  discard block
 block discarded – undo
257 257
 // http://doc.spip.org/@paragrapher
258 258
 // /!\ appelee dans inc/filtres et public/composer
259 259
 function paragrapher($letexte, $forcer=true) {
260
-	return $letexte;
260
+    return $letexte;
261 261
 }
262 262
 
263 263
 // Harmonise les retours chariots et mange les paragraphes html
264 264
 // http://doc.spip.org/@traiter_retours_chariots
265 265
 // ne sert plus
266 266
 function traiter_retours_chariots($letexte) {
267
-	$letexte = preg_replace(",\r\n?,S", "\n", $letexte);
268
-	$letexte = preg_replace(",<p[>[:space:]],iS", "\n\n\\0", $letexte);
269
-	$letexte = preg_replace(",</p[>[:space:]],iS", "\\0\n\n", $letexte);
270
-	return $letexte;
267
+    $letexte = preg_replace(",\r\n?,S", "\n", $letexte);
268
+    $letexte = preg_replace(",<p[>[:space:]],iS", "\n\n\\0", $letexte);
269
+    $letexte = preg_replace(",</p[>[:space:]],iS", "\\0\n\n", $letexte);
270
+    return $letexte;
271 271
 }
272 272
 
273 273
 
274 274
 // Filtre a appliquer aux champs du type #TEXTE*
275 275
 // http://doc.spip.org/@propre
276 276
 function propre($t, $connect=null, $env=array()) {
277
-	// les appels directs a cette fonction depuis le php de l'espace
278
-	// prive etant historiquement ecrits sans argment $connect
279
-	// on utilise la presence de celui-ci pour distinguer les cas
280
-	// ou il faut passer interdire_script explicitement
281
-	// les appels dans les squelettes (de l'espace prive) fournissant un $connect
282
-	// ne seront pas perturbes
283
-	$interdire_script = false;
284
-	if (is_null($connect)){
285
-		$connect = '';
286
-		$interdire_script = true;
287
-	}
288
-
289
-	if (!$t) return strval($t);
290
-
291
-	$t = echappe_html($t);
292
-	$t = expanser_liens($t,$connect, $env);
293
-	$t = traiter_raccourcis($t);
294
-	$t = echappe_retour_modeles($t, $interdire_script);
295
-
296
-	return $t;
277
+    // les appels directs a cette fonction depuis le php de l'espace
278
+    // prive etant historiquement ecrits sans argment $connect
279
+    // on utilise la presence de celui-ci pour distinguer les cas
280
+    // ou il faut passer interdire_script explicitement
281
+    // les appels dans les squelettes (de l'espace prive) fournissant un $connect
282
+    // ne seront pas perturbes
283
+    $interdire_script = false;
284
+    if (is_null($connect)){
285
+        $connect = '';
286
+        $interdire_script = true;
287
+    }
288
+
289
+    if (!$t) return strval($t);
290
+
291
+    $t = echappe_html($t);
292
+    $t = expanser_liens($t,$connect, $env);
293
+    $t = traiter_raccourcis($t);
294
+    $t = echappe_retour_modeles($t, $interdire_script);
295
+
296
+    return $t;
297 297
 }
298 298
 
299 299
 ?>
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
  */
22 22
 
23 23
 // Raccourcis dependant du sens de la langue
24
-function definir_raccourcis_alineas(){
25
-	return array('','');
24
+function definir_raccourcis_alineas() {
25
+	return array('', '');
26 26
 }
27 27
 
28 28
 
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 // Traitement des listes (merci a Michael Parienti)
40 40
 //
41 41
 // http://doc.spip.org/@traiter_listes
42
-function traiter_listes ($texte) {
42
+function traiter_listes($texte) {
43 43
 	return $texte;
44 44
 }
45 45
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 
66 66
 // afficher joliment les <script>
67 67
 // http://doc.spip.org/@echappe_js
68
-function echappe_js($t,$class=' class="echappe-js"') {
68
+function echappe_js($t, $class = ' class="echappe-js"') {
69 69
 	if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER))
70 70
 	foreach ($r as $regs)
71 71
 		$t = str_replace($regs[0],
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	$t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '&lt;\1', $t);
117 117
 
118 118
 	// Pour le js, trois modes : parano (-1), prive (0), ok (1)
119
-	switch($GLOBALS['filtrer_javascript']) {
119
+	switch ($GLOBALS['filtrer_javascript']) {
120 120
 		case 0:
121 121
 			if (!_DIR_RESTREINT)
122 122
 				$t = echappe_js($t);
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
 
132 132
 	// Reinserer les echappements des modeles
133 133
 	if (defined('_PROTEGE_JS_MODELES'))
134
-		$t = echappe_retour($t,"javascript"._PROTEGE_JS_MODELES);
134
+		$t = echappe_retour($t, "javascript"._PROTEGE_JS_MODELES);
135 135
 	if (defined('_PROTEGE_PHP_MODELES'))
136
-		$t = echappe_retour($t,"php"._PROTEGE_PHP_MODELES);
136
+		$t = echappe_retour($t, "php"._PROTEGE_PHP_MODELES);
137 137
 
138 138
 	return $dejavu[$GLOBALS['filtrer_javascript']][$arg] = $t;
139 139
 }
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 // avec protection prealable des balises HTML et SPIP
143 143
 
144 144
 // http://doc.spip.org/@typo
145
-function typo($letexte, $echapper=true, $connect=null, $env=array()) {
145
+function typo($letexte, $echapper = true, $connect = null, $env = array()) {
146 146
 	// Plus vite !
147 147
 	if (!$letexte) return $letexte;
148 148
 
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	// les appels dans les squelettes (de l'espace prive) fournissant un $connect
154 154
 	// ne seront pas perturbes
155 155
 	$interdire_script = false;
156
-	if (is_null($connect)){
156
+	if (is_null($connect)) {
157 157
 		$connect = '';
158 158
 		$interdire_script = true;
159 159
 		$env['espace_prive'] = 1;
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 
187 187
 	// Dans l'espace prive on se mefie de tout contenu dangereux
188 188
 	// https://core.spip.net/issues/3371
189
-	if (isset($env['espace_prive']) AND $env['espace_prive']){
189
+	if (isset($env['espace_prive']) AND $env['espace_prive']) {
190 190
 		$letexte = echapper_html_suspect($letexte);
191 191
 	}
192 192
 
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 define('_TYPO_BALISE', ",</?[a-z!][^<>]*[".preg_quote(_TYPO_PROTEGER)."][^<>]*>,imsS");
201 201
 
202 202
 // http://doc.spip.org/@corriger_typo
203
-function corriger_typo($letexte, $lang='') {
203
+function corriger_typo($letexte, $lang = '') {
204 204
 
205 205
 	// Plus vite !
206 206
 	if (!$letexte) return $letexte;
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 //
257 257
 // http://doc.spip.org/@paragrapher
258 258
 // /!\ appelee dans inc/filtres et public/composer
259
-function paragrapher($letexte, $forcer=true) {
259
+function paragrapher($letexte, $forcer = true) {
260 260
 	return $letexte;
261 261
 }
262 262
 
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 
274 274
 // Filtre a appliquer aux champs du type #TEXTE*
275 275
 // http://doc.spip.org/@propre
276
-function propre($t, $connect=null, $env=array()) {
276
+function propre($t, $connect = null, $env = array()) {
277 277
 	// les appels directs a cette fonction depuis le php de l'espace
278 278
 	// prive etant historiquement ecrits sans argment $connect
279 279
 	// on utilise la presence de celui-ci pour distinguer les cas
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 	// les appels dans les squelettes (de l'espace prive) fournissant un $connect
282 282
 	// ne seront pas perturbes
283 283
 	$interdire_script = false;
284
-	if (is_null($connect)){
284
+	if (is_null($connect)) {
285 285
 		$connect = '';
286 286
 		$interdire_script = true;
287 287
 	}
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 	if (!$t) return strval($t);
290 290
 
291 291
 	$t = echappe_html($t);
292
-	$t = expanser_liens($t,$connect, $env);
292
+	$t = expanser_liens($t, $connect, $env);
293 293
 	$t = traiter_raccourcis($t);
294 294
 	$t = echappe_retour_modeles($t, $interdire_script);
295 295
 
Please login to merge, or discard this patch.
Braces   +45 added lines, -22 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 include_spip('inc/texte_mini');
16 18
 include_spip('inc/lien');
@@ -66,11 +68,12 @@  discard block
 block discarded – undo
66 68
 // afficher joliment les <script>
67 69
 // http://doc.spip.org/@echappe_js
68 70
 function echappe_js($t,$class=' class="echappe-js"') {
69
-	if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER))
70
-	foreach ($r as $regs)
71
+	if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) {
72
+		foreach ($r as $regs)
71 73
 		$t = str_replace($regs[0],
72 74
 			"<code$class>".nl2br(spip_htmlspecialchars($regs[0])).'</code>',
73 75
 			$t);
76
+	}
74 77
 	return $t;
75 78
 }
76 79
 
@@ -102,9 +105,13 @@  discard block
 block discarded – undo
102 105
 	static $dejavu = array();
103 106
 
104 107
 	// Attention, si ce n'est pas une chaine, laisser intact
105
-	if (!$arg OR !is_string($arg) OR !strstr($arg, '<')) return $arg; 
108
+	if (!$arg OR !is_string($arg) OR !strstr($arg, '<')) {
109
+	    return $arg;
110
+	}
106 111
 
107
-	if (isset($dejavu[$GLOBALS['filtrer_javascript']][$arg])) return $dejavu[$GLOBALS['filtrer_javascript']][$arg];
112
+	if (isset($dejavu[$GLOBALS['filtrer_javascript']][$arg])) {
113
+	    return $dejavu[$GLOBALS['filtrer_javascript']][$arg];
114
+	}
108 115
 
109 116
 	// echapper les tags asp/php
110 117
 	$t = str_replace('<'.'%', '&lt;%', $arg);
@@ -118,8 +125,9 @@  discard block
 block discarded – undo
118 125
 	// Pour le js, trois modes : parano (-1), prive (0), ok (1)
119 126
 	switch($GLOBALS['filtrer_javascript']) {
120 127
 		case 0:
121
-			if (!_DIR_RESTREINT)
122
-				$t = echappe_js($t);
128
+			if (!_DIR_RESTREINT) {
129
+							$t = echappe_js($t);
130
+			}
123 131
 			break;
124 132
 		case -1:
125 133
 			$t = echappe_js($t);
@@ -130,10 +138,12 @@  discard block
 block discarded – undo
130 138
 	$t = preg_replace(',<(base\b),iS', '&lt;\1', $t);
131 139
 
132 140
 	// Reinserer les echappements des modeles
133
-	if (defined('_PROTEGE_JS_MODELES'))
134
-		$t = echappe_retour($t,"javascript"._PROTEGE_JS_MODELES);
135
-	if (defined('_PROTEGE_PHP_MODELES'))
136
-		$t = echappe_retour($t,"php"._PROTEGE_PHP_MODELES);
141
+	if (defined('_PROTEGE_JS_MODELES')) {
142
+			$t = echappe_retour($t,"javascript"._PROTEGE_JS_MODELES);
143
+	}
144
+	if (defined('_PROTEGE_PHP_MODELES')) {
145
+			$t = echappe_retour($t,"php"._PROTEGE_PHP_MODELES);
146
+	}
137 147
 
138 148
 	return $dejavu[$GLOBALS['filtrer_javascript']][$arg] = $t;
139 149
 }
@@ -144,7 +154,9 @@  discard block
 block discarded – undo
144 154
 // http://doc.spip.org/@typo
145 155
 function typo($letexte, $echapper=true, $connect=null, $env=array()) {
146 156
 	// Plus vite !
147
-	if (!$letexte) return $letexte;
157
+	if (!$letexte) {
158
+	    return $letexte;
159
+	}
148 160
 
149 161
 	// les appels directs a cette fonction depuis le php de l'espace
150 162
 	// prive etant historiquement ecrit sans argment $connect
@@ -160,8 +172,9 @@  discard block
 block discarded – undo
160 172
 	}
161 173
 
162 174
 	// Echapper les codes <html> etc
163
-	if ($echapper)
164
-		$letexte = echappe_html($letexte, 'TYPO');
175
+	if ($echapper) {
176
+			$letexte = echappe_html($letexte, 'TYPO');
177
+	}
165 178
 
166 179
 	//
167 180
 	// Installer les modeles, notamment images et documents ;
@@ -170,19 +183,23 @@  discard block
 block discarded – undo
170 183
 	// cf. inc/lien
171 184
 
172 185
 	$letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env);
173
-	if ($letexte != $mem) $echapper = true;
186
+	if ($letexte != $mem) {
187
+	    $echapper = true;
188
+	}
174 189
 	unset($mem);
175 190
 
176 191
 	$letexte = corriger_typo($letexte);
177 192
 	$letexte = echapper_faux_tags($letexte);
178 193
 
179 194
 	// reintegrer les echappements
180
-	if ($echapper)
181
-		$letexte = echappe_retour($letexte, 'TYPO');
195
+	if ($echapper) {
196
+			$letexte = echappe_retour($letexte, 'TYPO');
197
+	}
182 198
 
183 199
 	// Dans les appels directs hors squelette, securiser ici aussi
184
-	if ($interdire_script)
185
-		$letexte = interdire_scripts($letexte);
200
+	if ($interdire_script) {
201
+			$letexte = interdire_scripts($letexte);
202
+	}
186 203
 
187 204
 	// Dans l'espace prive on se mefie de tout contenu dangereux
188 205
 	// https://core.spip.net/issues/3371
@@ -203,7 +220,9 @@  discard block
 block discarded – undo
203 220
 function corriger_typo($letexte, $lang='') {
204 221
 
205 222
 	// Plus vite !
206
-	if (!$letexte) return $letexte;
223
+	if (!$letexte) {
224
+	    return $letexte;
225
+	}
207 226
 
208 227
 	$letexte = pipeline('pre_typo', $letexte);
209 228
 
@@ -230,7 +249,9 @@  discard block
 block discarded – undo
230 249
 	$letexte = $typographie($letexte);
231 250
 
232 251
 	// Les citations en une autre langue, s'il y a lieu
233
-	if (!$e) $letexte = echappe_retour($letexte, 'multi');
252
+	if (!$e) {
253
+	    $letexte = echappe_retour($letexte, 'multi');
254
+	}
234 255
 
235 256
 	// Retablir les caracteres proteges
236 257
 	$letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER);
@@ -286,7 +307,9 @@  discard block
 block discarded – undo
286 307
 		$interdire_script = true;
287 308
 	}
288 309
 
289
-	if (!$t) return strval($t);
310
+	if (!$t) {
311
+	    return strval($t);
312
+	}
290 313
 
291 314
 	$t = echappe_html($t);
292 315
 	$t = expanser_liens($t,$connect, $env);
Please login to merge, or discard this patch.
ecrire/inc/texte_mini.php 4 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -58,6 +58,9 @@  discard block
 block discarded – undo
58 58
 // une $source differente ; le script detecte automagiquement si ce qu'on
59 59
 // echappe est un div ou un span
60 60
 // http://doc.spip.org/@code_echappement
61
+/**
62
+ * @param string $mode
63
+ */
61 64
 function code_echappement($rempl, $source='', $no_transform=false, $mode=NULL) {
62 65
 	if (!strlen($rempl)) return '';
63 66
 
@@ -453,6 +456,9 @@  discard block
 block discarded – undo
453 456
 // Sert aussi a nettoyer un texte qu'on veut mettre dans un <a> etc.
454 457
 // TODO: gerer les modeles ?
455 458
 // http://doc.spip.org/@supprime_img
459
+/**
460
+ * @param string $message
461
+ */
456 462
 function supprime_img($letexte, $message=NULL) {
457 463
 	if ($message===NULL) $message = '(' . _T('img_indisponible') . ')';
458 464
 	return preg_replace(',<(img|doc|emb)([0-9]+)(\|([^>]*))?'.'\s*/?'.'>,i',
Please login to merge, or discard this patch.
Indentation   +295 added lines, -295 removed lines patch added patch discarded remove patch
@@ -20,20 +20,20 @@  discard block
 block discarded – undo
20 20
 // http://doc.spip.org/@definir_puce
21 21
 function definir_puce() {
22 22
 
23
-	// Attention au sens, qui n'est pas defini de la meme facon dans
24
-	// l'espace prive (spip_lang est la langue de l'interface, lang_dir
25
-	// celle du texte) et public (spip_lang est la langue du texte)
26
-	$dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']);
27
-
28
-	$p = 'puce' . (test_espace_prive() ? '_prive' : '');
29
-	if ($dir == 'rtl') $p .= '_rtl';
30
-
31
-	if (!isset($GLOBALS[$p])) {
32
-		$img = find_in_path($p.'.gif');
33
-		list(,,,$size) = @getimagesize($img);
34
-		$GLOBALS[$p] = '<img src="'.$img.'" '.$size.' class="puce" alt="-" />';
35
-	}
36
-	return $GLOBALS[$p];
23
+    // Attention au sens, qui n'est pas defini de la meme facon dans
24
+    // l'espace prive (spip_lang est la langue de l'interface, lang_dir
25
+    // celle du texte) et public (spip_lang est la langue du texte)
26
+    $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']);
27
+
28
+    $p = 'puce' . (test_espace_prive() ? '_prive' : '');
29
+    if ($dir == 'rtl') $p .= '_rtl';
30
+
31
+    if (!isset($GLOBALS[$p])) {
32
+        $img = find_in_path($p.'.gif');
33
+        list(,,,$size) = @getimagesize($img);
34
+        $GLOBALS[$p] = '<img src="'.$img.'" '.$size.' class="puce" alt="-" />';
35
+    }
36
+    return $GLOBALS[$p];
37 37
 }
38 38
 
39 39
 
@@ -41,14 +41,14 @@  discard block
 block discarded – undo
41 41
 // dont on souhaite qu'ils provoquent un saut de paragraphe
42 42
 
43 43
 if (!defined('_BALISES_BLOCS')) define('_BALISES_BLOCS',
44
-	'p|div|pre|ul|ol|li|blockquote|h[1-6r]|'
45
-	.'t(able|[rdh]|head|body|foot|extarea)|'
46
-	.'form|object|center|marquee|address|'
47
-	.'applet|iframe|'
48
-	.'d[ltd]|script|noscript|map|button|fieldset|style');
44
+    'p|div|pre|ul|ol|li|blockquote|h[1-6r]|'
45
+    .'t(able|[rdh]|head|body|foot|extarea)|'
46
+    .'form|object|center|marquee|address|'
47
+    .'applet|iframe|'
48
+    .'d[ltd]|script|noscript|map|button|fieldset|style');
49 49
 
50 50
 if (!defined('_BALISES_BLOCS_REGEXP'))
51
-	define('_BALISES_BLOCS_REGEXP',',</?('._BALISES_BLOCS.')[>[:space:]],iS');
51
+    define('_BALISES_BLOCS_REGEXP',',</?('._BALISES_BLOCS.')[>[:space:]],iS');
52 52
 
53 53
 //
54 54
 // Echapper les elements perilleux en les passant en base64
@@ -59,23 +59,23 @@  discard block
 block discarded – undo
59 59
 // echappe est un div ou un span
60 60
 // http://doc.spip.org/@code_echappement
61 61
 function code_echappement($rempl, $source='', $no_transform=false, $mode=NULL) {
62
-	if (!strlen($rempl)) return '';
62
+    if (!strlen($rempl)) return '';
63 63
 
64
-	// Tester si on echappe en span ou en div
65
-	if (is_null($mode) OR !in_array($mode,array('div','span')))
66
-		$mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $rempl) ? 'div' : 'span';
64
+    // Tester si on echappe en span ou en div
65
+    if (is_null($mode) OR !in_array($mode,array('div','span')))
66
+        $mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $rempl) ? 'div' : 'span';
67 67
 
68
-	// Decouper en morceaux, base64 a des probleme selon la taille de la pile
69
-	$taille = 30000;
70
-	$return = "";
71
-	for($i = 0; $i < strlen($rempl); $i += $taille) {
72
-		// Convertir en base64 et cacher dans un attribut
73
-		// utiliser les " pour eviter le re-encodage de ' et &#8217
74
-		$base64 = base64_encode(substr($rempl, $i, $taille));
75
-		$return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>";
76
-	}
68
+    // Decouper en morceaux, base64 a des probleme selon la taille de la pile
69
+    $taille = 30000;
70
+    $return = "";
71
+    for($i = 0; $i < strlen($rempl); $i += $taille) {
72
+        // Convertir en base64 et cacher dans un attribut
73
+        // utiliser les " pour eviter le re-encodage de ' et &#8217
74
+        $base64 = base64_encode(substr($rempl, $i, $taille));
75
+        $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>";
76
+    }
77 77
 
78
-	return $return;
78
+    return $return;
79 79
 
80 80
 }
81 81
 
@@ -83,59 +83,59 @@  discard block
 block discarded – undo
83 83
 // Echapper les <html>...</ html>
84 84
 // http://doc.spip.org/@traiter_echap_html_dist
85 85
 function traiter_echap_html_dist($regs) {
86
-	return $regs[3];
86
+    return $regs[3];
87 87
 }
88 88
 
89 89
 // Echapper les <code>...</ code>
90 90
 // http://doc.spip.org/@traiter_echap_code_dist
91 91
 function traiter_echap_code_dist($regs) {
92
-	list(,,$att,$corps) = $regs;
93
-	$echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code !
94
-
95
-	// ne pas mettre le <div...> s'il n'y a qu'une ligne
96
-	if (is_int(strpos($echap,"\n"))) {
97
-		// supprimer les sauts de ligne debut/fin
98
-		// (mais pas les espaces => ascii art).
99
-		$echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", "", $echap);
100
-		$echap = nl2br($echap);
101
-		$echap = "<div style='text-align: left;' "
102
-		. "class='spip_code' dir='ltr'><code$att>"
103
-		.$echap."</code></div>";
104
-	} else {
105
-		$echap = "<code$att class='spip_code' dir='ltr'>".$echap."</code>";
106
-	}
107
-
108
-	$echap = str_replace("\t", "&nbsp; &nbsp; &nbsp; &nbsp; ", $echap);
109
-	$echap = str_replace("  ", " &nbsp;", $echap);
110
-	return $echap;
92
+    list(,,$att,$corps) = $regs;
93
+    $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code !
94
+
95
+    // ne pas mettre le <div...> s'il n'y a qu'une ligne
96
+    if (is_int(strpos($echap,"\n"))) {
97
+        // supprimer les sauts de ligne debut/fin
98
+        // (mais pas les espaces => ascii art).
99
+        $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", "", $echap);
100
+        $echap = nl2br($echap);
101
+        $echap = "<div style='text-align: left;' "
102
+        . "class='spip_code' dir='ltr'><code$att>"
103
+        .$echap."</code></div>";
104
+    } else {
105
+        $echap = "<code$att class='spip_code' dir='ltr'>".$echap."</code>";
106
+    }
107
+
108
+    $echap = str_replace("\t", "&nbsp; &nbsp; &nbsp; &nbsp; ", $echap);
109
+    $echap = str_replace("  ", " &nbsp;", $echap);
110
+    return $echap;
111 111
 }
112 112
 
113 113
 // Echapper les <cadre>...</ cadre> aka <frame>...</ frame>
114 114
 // http://doc.spip.org/@traiter_echap_cadre_dist
115 115
 function traiter_echap_cadre_dist($regs) {
116
-	$echap = trim(entites_html($regs[3]));
117
-	// compter les lignes un peu plus finement qu'avec les \n
118
-	$lignes = explode("\n",trim($echap));
119
-	$n = 0;
120
-	foreach($lignes as $l)
121
-		$n+=floor(strlen($l)/60)+1;
122
-	$n = max($n,2);
123
-	$echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>";
124
-	return $echap;
116
+    $echap = trim(entites_html($regs[3]));
117
+    // compter les lignes un peu plus finement qu'avec les \n
118
+    $lignes = explode("\n",trim($echap));
119
+    $n = 0;
120
+    foreach($lignes as $l)
121
+        $n+=floor(strlen($l)/60)+1;
122
+    $n = max($n,2);
123
+    $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>";
124
+    return $echap;
125 125
 }
126 126
 // http://doc.spip.org/@traiter_echap_frame_dist
127 127
 function traiter_echap_frame_dist($regs) {
128
-	return traiter_echap_cadre_dist($regs);
128
+    return traiter_echap_cadre_dist($regs);
129 129
 }
130 130
 
131 131
 // http://doc.spip.org/@traiter_echap_script_dist
132 132
 function traiter_echap_script_dist($regs) {
133
-	// rendre joli (et inactif) si c'est un script language=php
134
-	if (preg_match(',<script\b[^>]+php,ims', $regs[0]))
135
-		return highlight_string($regs[0],true);
133
+    // rendre joli (et inactif) si c'est un script language=php
134
+    if (preg_match(',<script\b[^>]+php,ims', $regs[0]))
135
+        return highlight_string($regs[0],true);
136 136
 
137
-	// Cas normal : le script passe tel quel
138
-	return $regs[0];
137
+    // Cas normal : le script passe tel quel
138
+    return $regs[0];
139 139
 }
140 140
 
141 141
 /**
@@ -144,12 +144,12 @@  discard block
 block discarded – undo
144 144
  * @return string
145 145
  */
146 146
 function traiter_echap_math_dist($regs) {
147
-	// Gestion du TeX
148
-	if (!function_exists('traiter_math'))
149
-		include_spip('inc/math');
147
+    // Gestion du TeX
148
+    if (!function_exists('traiter_math'))
149
+        include_spip('inc/math');
150 150
 
151
-	$t = traiter_math($regs[0], '');
152
-	return $t;
151
+    $t = traiter_math($regs[0], '');
152
+    return $t;
153 153
 }
154 154
 
155 155
 define('_PROTEGE_BLOCS', ',<(html|code|cadre|frame|script)(\s[^>]*)?>(.*)</\1>,UimsS');
@@ -159,67 +159,67 @@  discard block
 block discarded – undo
159 159
 // http://doc.spip.org/@echappe_html
160 160
 function echappe_html($letexte, $source='', $no_transform=false,
161 161
 $preg='') {
162
-	if (!is_string($letexte) or !strlen($letexte))
163
-		return $letexte;
164
-
165
-	// si le texte recu est long PCRE risque d'exploser, on
166
-	// fait donc un mic-mac pour augmenter pcre.backtrack_limit
167
-	if (($len = strlen($letexte)) > 100000) {
168
-		if (!$old = @ini_get('pcre.backtrack_limit')) $old = 100000;
169
-		if ($len > $old) {
170
-			$a = @ini_set('pcre.backtrack_limit', $len);
171
-			spip_log("ini_set pcre.backtrack_limit=$len ($old)");
172
-		}
173
-	}
174
-
175
-	if (($preg OR strpos($letexte,"<")!==false)
176
-	  AND preg_match_all($preg ? $preg : _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER)) {
177
-		foreach ($matches as $regs) {
178
-			// echappements tels quels ?
179
-			if ($no_transform) {
180
-				$echap = $regs[0];
181
-			}
182
-
183
-			// sinon les traiter selon le cas
184
-			else if (function_exists($f = 'traiter_echap_'.strtolower($regs[1])))
185
-				$echap = $f($regs);
186
-			else if (function_exists($f = $f.'_dist'))
187
-				$echap = $f($regs);
188
-
189
-			$p = strpos($letexte,$regs[0]);
190
-			$letexte = substr_replace($letexte,code_echappement($echap, $source, $no_transform),$p,strlen($regs[0]));
191
-		}
192
-	}
193
-
194
-	if ($no_transform)
195
-		return $letexte;
196
-
197
-	// Gestion du TeX
198
-	// code mort sauf si on a personalise _PROTEGE_BLOCS sans y mettre <math>
199
-	// eviter la rupture de compat en branche 3.0
200
-	// a supprimer en branche 3.1
201
-	if (strpos($preg ? $preg : _PROTEGE_BLOCS,'code')!==false){
202
-		if (strpos($letexte, "<math>") !== false) {
203
-			include_spip('inc/math');
204
-			$letexte = traiter_math($letexte, $source);
205
-		}
206
-	}
207
-
208
-	// Echapper le php pour faire joli (ici, c'est pas pour la securite)
209
-	// seulement si on a echappe les <script>
210
-	// (derogatoire car on ne peut pas faire passer < ? ... ? >
211
-	// dans une callback autonommee
212
-	if (strpos($preg ? $preg : _PROTEGE_BLOCS,'script')!==false){
213
-		if (strpos($letexte,"<"."?")!==false AND preg_match_all(',<[?].*($|[?]>),UisS',
214
-		$letexte, $matches, PREG_SET_ORDER))
215
-		foreach ($matches as $regs) {
216
-			$letexte = str_replace($regs[0],
217
-				code_echappement(highlight_string($regs[0],true), $source),
218
-				$letexte);
219
-		}
220
-	}
221
-
222
-	return $letexte;
162
+    if (!is_string($letexte) or !strlen($letexte))
163
+        return $letexte;
164
+
165
+    // si le texte recu est long PCRE risque d'exploser, on
166
+    // fait donc un mic-mac pour augmenter pcre.backtrack_limit
167
+    if (($len = strlen($letexte)) > 100000) {
168
+        if (!$old = @ini_get('pcre.backtrack_limit')) $old = 100000;
169
+        if ($len > $old) {
170
+            $a = @ini_set('pcre.backtrack_limit', $len);
171
+            spip_log("ini_set pcre.backtrack_limit=$len ($old)");
172
+        }
173
+    }
174
+
175
+    if (($preg OR strpos($letexte,"<")!==false)
176
+      AND preg_match_all($preg ? $preg : _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER)) {
177
+        foreach ($matches as $regs) {
178
+            // echappements tels quels ?
179
+            if ($no_transform) {
180
+                $echap = $regs[0];
181
+            }
182
+
183
+            // sinon les traiter selon le cas
184
+            else if (function_exists($f = 'traiter_echap_'.strtolower($regs[1])))
185
+                $echap = $f($regs);
186
+            else if (function_exists($f = $f.'_dist'))
187
+                $echap = $f($regs);
188
+
189
+            $p = strpos($letexte,$regs[0]);
190
+            $letexte = substr_replace($letexte,code_echappement($echap, $source, $no_transform),$p,strlen($regs[0]));
191
+        }
192
+    }
193
+
194
+    if ($no_transform)
195
+        return $letexte;
196
+
197
+    // Gestion du TeX
198
+    // code mort sauf si on a personalise _PROTEGE_BLOCS sans y mettre <math>
199
+    // eviter la rupture de compat en branche 3.0
200
+    // a supprimer en branche 3.1
201
+    if (strpos($preg ? $preg : _PROTEGE_BLOCS,'code')!==false){
202
+        if (strpos($letexte, "<math>") !== false) {
203
+            include_spip('inc/math');
204
+            $letexte = traiter_math($letexte, $source);
205
+        }
206
+    }
207
+
208
+    // Echapper le php pour faire joli (ici, c'est pas pour la securite)
209
+    // seulement si on a echappe les <script>
210
+    // (derogatoire car on ne peut pas faire passer < ? ... ? >
211
+    // dans une callback autonommee
212
+    if (strpos($preg ? $preg : _PROTEGE_BLOCS,'script')!==false){
213
+        if (strpos($letexte,"<"."?")!==false AND preg_match_all(',<[?].*($|[?]>),UisS',
214
+        $letexte, $matches, PREG_SET_ORDER))
215
+        foreach ($matches as $regs) {
216
+            $letexte = str_replace($regs[0],
217
+                code_echappement(highlight_string($regs[0],true), $source),
218
+                $letexte);
219
+        }
220
+    }
221
+
222
+    return $letexte;
223 223
 }
224 224
 
225 225
 //
@@ -228,33 +228,33 @@  discard block
 block discarded – undo
228 228
 // par propre() : exemple dans multi et dans typo()
229 229
 // http://doc.spip.org/@echappe_retour
230 230
 function echappe_retour($letexte, $source='', $filtre = "") {
231
-	if (strpos($letexte,"base64$source")) {
232
-		# spip_log(spip_htmlspecialchars($letexte));  ## pour les curieux
233
-		$max_prof = 5;
234
-		while (strpos($letexte,"<")!==false
235
-			AND
236
-		  preg_match_all(',<(span|div)\sclass=[\'"]base64'.$source.'[\'"]\s(.*)>\s*</\1>,UmsS',
237
-		$letexte, $regs, PREG_SET_ORDER)
238
-		  AND $max_prof--) {
239
-			foreach ($regs as $reg) {
240
-				$rempl = base64_decode(extraire_attribut($reg[0], 'title'));
241
-				// recherche d'attributs supplementaires
242
-				$at = array();
243
-				foreach(array('lang', 'dir') as $attr) {
244
-					if ($a = extraire_attribut($reg[0], $attr))
245
-						$at[$attr] = $a;
246
-				}
247
-				if ($at) {
248
-					$rempl = '<'.$reg[1].'>'.$rempl.'</'.$reg[1].'>';
249
-					foreach($at as $attr => $a)
250
-						$rempl = inserer_attribut($rempl, $attr, $a);
251
-				}
252
-				if ($filtre) $rempl = $filtre($rempl);
253
-				$letexte = str_replace($reg[0], $rempl, $letexte);
254
-			}
255
-		}
256
-	}
257
-	return $letexte;
231
+    if (strpos($letexte,"base64$source")) {
232
+        # spip_log(spip_htmlspecialchars($letexte));  ## pour les curieux
233
+        $max_prof = 5;
234
+        while (strpos($letexte,"<")!==false
235
+            AND
236
+          preg_match_all(',<(span|div)\sclass=[\'"]base64'.$source.'[\'"]\s(.*)>\s*</\1>,UmsS',
237
+        $letexte, $regs, PREG_SET_ORDER)
238
+          AND $max_prof--) {
239
+            foreach ($regs as $reg) {
240
+                $rempl = base64_decode(extraire_attribut($reg[0], 'title'));
241
+                // recherche d'attributs supplementaires
242
+                $at = array();
243
+                foreach(array('lang', 'dir') as $attr) {
244
+                    if ($a = extraire_attribut($reg[0], $attr))
245
+                        $at[$attr] = $a;
246
+                }
247
+                if ($at) {
248
+                    $rempl = '<'.$reg[1].'>'.$rempl.'</'.$reg[1].'>';
249
+                    foreach($at as $attr => $a)
250
+                        $rempl = inserer_attribut($rempl, $attr, $a);
251
+                }
252
+                if ($filtre) $rempl = $filtre($rempl);
253
+                $letexte = str_replace($reg[0], $rempl, $letexte);
254
+            }
255
+        }
256
+    }
257
+    return $letexte;
258 258
 }
259 259
 
260 260
 // Reinserer le javascript de confiance (venant des modeles)
@@ -262,130 +262,130 @@  discard block
 block discarded – undo
262 262
 // http://doc.spip.org/@echappe_retour_modeles
263 263
 function echappe_retour_modeles($letexte, $interdire_scripts=false)
264 264
 {
265
-	$letexte = echappe_retour($letexte);
265
+    $letexte = echappe_retour($letexte);
266 266
 
267
-	// Dans les appels directs hors squelette, securiser aussi ici
268
-	if ($interdire_scripts)
269
-		$letexte = interdire_scripts($letexte);
267
+    // Dans les appels directs hors squelette, securiser aussi ici
268
+    if ($interdire_scripts)
269
+        $letexte = interdire_scripts($letexte);
270 270
 
271
-	return trim($letexte);
271
+    return trim($letexte);
272 272
 }
273 273
 
274 274
 
275 275
 // http://doc.spip.org/@couper
276 276
 function couper($texte, $taille=50, $suite = '&nbsp;(...)') {
277
-	if (!($length=strlen($texte)) OR $taille <= 0) return '';
278
-	$offset = 400 + 2*$taille;
279
-	while ($offset<$length
280
-		AND strlen(preg_replace(",<[^>]+>,Uims","",substr($texte,0,$offset)))<$taille)
281
-		$offset = 2*$offset;
282
-	if (	$offset<$length
283
-			&& ($p_tag_ouvrant = strpos($texte,'<',$offset))!==NULL){
284
-		$p_tag_fermant = strpos($texte,'>',$offset);
285
-		if ($p_tag_fermant && ($p_tag_fermant<$p_tag_ouvrant))
286
-			$offset = $p_tag_fermant+1; // prolonger la coupe jusqu'au tag fermant suivant eventuel
287
-	}
288
-	$texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */
289
-
290
-	// on utilise les \r pour passer entre les gouttes
291
-	$texte = str_replace("\r\n", "\n", $texte);
292
-	$texte = str_replace("\r", "\n", $texte);
293
-
294
-	// sauts de ligne et paragraphes
295
-	$texte = preg_replace("/\n\n+/", "\r", $texte);
296
-	$texte = preg_replace("/<(p|br)( [^>]*)?".">/", "\r", $texte);
297
-
298
-	// supprimer les traits, lignes etc
299
-	$texte = preg_replace("/(^|\r|\n)(-[-#\*]*|_ )/", "\r", $texte);
300
-
301
-	// supprimer les tags
302
-	$texte = supprimer_tags($texte);
303
-	$texte = trim(str_replace("\n"," ", $texte));
304
-	$texte .= "\n";	// marquer la fin
305
-
306
-	// travailler en accents charset
307
-	$texte = unicode2charset(html2unicode($texte, /* secure */ true));
308
-	if (!function_exists('nettoyer_raccourcis_typo'))
309
-		include_spip('inc/lien');
310
-	$texte = nettoyer_raccourcis_typo($texte);
311
-
312
-	// corriger la longueur de coupe
313
-	// en fonction de la presence de caracteres utf
314
-	if ($GLOBALS['meta']['charset']=='utf-8'){
315
-		$long = charset2unicode($texte);
316
-		$long = spip_substr($long, 0, max($taille,1));
317
-		$nbcharutf = preg_match_all('/(&#[0-9]{3,5};)/S', $long, $matches);
318
-		$taille += $nbcharutf;
319
-	}
320
-
321
-
322
-	// couper au mot precedent
323
-	$long = spip_substr($texte, 0, max($taille-4,1));
324
-	$u = $GLOBALS['meta']['pcre_u'];
325
-	$court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long);
326
-	$points = $suite;
327
-
328
-	// trop court ? ne pas faire de (...)
329
-	if (spip_strlen($court) < max(0.75 * $taille,2)) {
330
-		$points = '';
331
-		$long = spip_substr($texte, 0, $taille);
332
-		$texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long);
333
-		// encore trop court ? couper au caractere
334
-		if (spip_strlen($texte) < 0.75 * $taille)
335
-			$texte = $long;
336
-	} else
337
-		$texte = $court;
338
-
339
-	if (strpos($texte, "\n"))	// la fin est encore la : c'est qu'on n'a pas de texte de suite
340
-		$points = '';
341
-
342
-	// remettre les paragraphes
343
-	$texte = preg_replace("/\r+/", "\n\n", $texte);
344
-
345
-	// supprimer l'eventuelle entite finale mal coupee
346
-	$texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte);
347
-
348
-	return quote_amp(trim($texte)).$points;
277
+    if (!($length=strlen($texte)) OR $taille <= 0) return '';
278
+    $offset = 400 + 2*$taille;
279
+    while ($offset<$length
280
+        AND strlen(preg_replace(",<[^>]+>,Uims","",substr($texte,0,$offset)))<$taille)
281
+        $offset = 2*$offset;
282
+    if (	$offset<$length
283
+            && ($p_tag_ouvrant = strpos($texte,'<',$offset))!==NULL){
284
+        $p_tag_fermant = strpos($texte,'>',$offset);
285
+        if ($p_tag_fermant && ($p_tag_fermant<$p_tag_ouvrant))
286
+            $offset = $p_tag_fermant+1; // prolonger la coupe jusqu'au tag fermant suivant eventuel
287
+    }
288
+    $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */
289
+
290
+    // on utilise les \r pour passer entre les gouttes
291
+    $texte = str_replace("\r\n", "\n", $texte);
292
+    $texte = str_replace("\r", "\n", $texte);
293
+
294
+    // sauts de ligne et paragraphes
295
+    $texte = preg_replace("/\n\n+/", "\r", $texte);
296
+    $texte = preg_replace("/<(p|br)( [^>]*)?".">/", "\r", $texte);
297
+
298
+    // supprimer les traits, lignes etc
299
+    $texte = preg_replace("/(^|\r|\n)(-[-#\*]*|_ )/", "\r", $texte);
300
+
301
+    // supprimer les tags
302
+    $texte = supprimer_tags($texte);
303
+    $texte = trim(str_replace("\n"," ", $texte));
304
+    $texte .= "\n";	// marquer la fin
305
+
306
+    // travailler en accents charset
307
+    $texte = unicode2charset(html2unicode($texte, /* secure */ true));
308
+    if (!function_exists('nettoyer_raccourcis_typo'))
309
+        include_spip('inc/lien');
310
+    $texte = nettoyer_raccourcis_typo($texte);
311
+
312
+    // corriger la longueur de coupe
313
+    // en fonction de la presence de caracteres utf
314
+    if ($GLOBALS['meta']['charset']=='utf-8'){
315
+        $long = charset2unicode($texte);
316
+        $long = spip_substr($long, 0, max($taille,1));
317
+        $nbcharutf = preg_match_all('/(&#[0-9]{3,5};)/S', $long, $matches);
318
+        $taille += $nbcharutf;
319
+    }
320
+
321
+
322
+    // couper au mot precedent
323
+    $long = spip_substr($texte, 0, max($taille-4,1));
324
+    $u = $GLOBALS['meta']['pcre_u'];
325
+    $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long);
326
+    $points = $suite;
327
+
328
+    // trop court ? ne pas faire de (...)
329
+    if (spip_strlen($court) < max(0.75 * $taille,2)) {
330
+        $points = '';
331
+        $long = spip_substr($texte, 0, $taille);
332
+        $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long);
333
+        // encore trop court ? couper au caractere
334
+        if (spip_strlen($texte) < 0.75 * $taille)
335
+            $texte = $long;
336
+    } else
337
+        $texte = $court;
338
+
339
+    if (strpos($texte, "\n"))	// la fin est encore la : c'est qu'on n'a pas de texte de suite
340
+        $points = '';
341
+
342
+    // remettre les paragraphes
343
+    $texte = preg_replace("/\r+/", "\n\n", $texte);
344
+
345
+    // supprimer l'eventuelle entite finale mal coupee
346
+    $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte);
347
+
348
+    return quote_amp(trim($texte)).$points;
349 349
 }
350 350
 
351 351
 
352 352
 // http://doc.spip.org/@protege_js_modeles
353 353
 function protege_js_modeles($t) {
354
-	if (isset($GLOBALS['visiteur_session'])){
355
-		if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)){
356
-			if (!defined('_PROTEGE_JS_MODELES')){
357
-				include_spip('inc/acces');
358
-				define('_PROTEGE_JS_MODELES',creer_uniqid());
359
-			}
360
-			foreach ($r as $regs)
361
-				$t = str_replace($regs[0],code_echappement($regs[0],'javascript'._PROTEGE_JS_MODELES),$t);
362
-		}
363
-		if (preg_match_all(',<\?php.*?($|\?'.'>),isS', $t, $r, PREG_SET_ORDER)){
364
-			if (!defined('_PROTEGE_PHP_MODELES')){
365
-				include_spip('inc/acces');
366
-				define('_PROTEGE_PHP_MODELES',creer_uniqid());
367
-			}
368
-			foreach ($r as $regs)
369
-				$t = str_replace($regs[0],code_echappement($regs[0],'php'._PROTEGE_PHP_MODELES),$t);
370
-		}
371
-	}
372
-	return $t;
354
+    if (isset($GLOBALS['visiteur_session'])){
355
+        if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)){
356
+            if (!defined('_PROTEGE_JS_MODELES')){
357
+                include_spip('inc/acces');
358
+                define('_PROTEGE_JS_MODELES',creer_uniqid());
359
+            }
360
+            foreach ($r as $regs)
361
+                $t = str_replace($regs[0],code_echappement($regs[0],'javascript'._PROTEGE_JS_MODELES),$t);
362
+        }
363
+        if (preg_match_all(',<\?php.*?($|\?'.'>),isS', $t, $r, PREG_SET_ORDER)){
364
+            if (!defined('_PROTEGE_PHP_MODELES')){
365
+                include_spip('inc/acces');
366
+                define('_PROTEGE_PHP_MODELES',creer_uniqid());
367
+            }
368
+            foreach ($r as $regs)
369
+                $t = str_replace($regs[0],code_echappement($regs[0],'php'._PROTEGE_PHP_MODELES),$t);
370
+        }
371
+    }
372
+    return $t;
373 373
 }
374 374
 
375 375
 
376 376
 function echapper_faux_tags($letexte){
377
-	if (strpos($letexte,'<')===false)
378
-		return $letexte;
379
-  $textMatches = preg_split (',(</?[a-z!][^<>]*>),', $letexte, null, PREG_SPLIT_DELIM_CAPTURE);
380
-
381
-  $letexte = "";
382
-  while (count($textMatches)) {
383
-  	// un texte a echapper
384
-  	$letexte .= str_replace("<",'&lt;',array_shift($textMatches));
385
-  	// un tag html qui a servit a faite le split
386
- 		$letexte .= array_shift($textMatches);
387
-  }
388
-  return $letexte;
377
+    if (strpos($letexte,'<')===false)
378
+        return $letexte;
379
+    $textMatches = preg_split (',(</?[a-z!][^<>]*>),', $letexte, null, PREG_SPLIT_DELIM_CAPTURE);
380
+
381
+    $letexte = "";
382
+    while (count($textMatches)) {
383
+        // un texte a echapper
384
+        $letexte .= str_replace("<",'&lt;',array_shift($textMatches));
385
+        // un tag html qui a servit a faite le split
386
+            $letexte .= array_shift($textMatches);
387
+    }
388
+    return $letexte;
389 389
 }
390 390
 
391 391
 /**
@@ -397,17 +397,17 @@  discard block
 block discarded – undo
397 397
  * @return string
398 398
  */
399 399
 function echapper_html_suspect($texte){
400
-	if (strpos($texte,'<')===false OR strpos($texte,'=')===false)
401
-		return $texte;
400
+    if (strpos($texte,'<')===false OR strpos($texte,'=')===false)
401
+        return $texte;
402 402
 
403
-	// on teste sur strlen car safehtml supprime le contenu dangereux
404
-	// mais il peut aussi changer des ' en " sur les attributs html,
405
-	// donc un test d'egalite est trop strict
406
-	if (strlen(safehtml($texte))!==strlen($texte)){
407
-		$texte = str_replace("<","&lt;",$texte);
408
-	}
403
+    // on teste sur strlen car safehtml supprime le contenu dangereux
404
+    // mais il peut aussi changer des ' en " sur les attributs html,
405
+    // donc un test d'egalite est trop strict
406
+    if (strlen(safehtml($texte))!==strlen($texte)){
407
+        $texte = str_replace("<","&lt;",$texte);
408
+    }
409 409
 
410
-	return $texte;
410
+    return $texte;
411 411
 }
412 412
 
413 413
 
@@ -428,23 +428,23 @@  discard block
 block discarded – undo
428 428
  *      Texte sécurisé
429 429
 **/
430 430
 function safehtml($t) {
431
-	static $safehtml;
431
+    static $safehtml;
432 432
 
433
-	if (!$t OR !is_string($t))
434
-		return $t;
435
-	# attention safehtml nettoie deux ou trois caracteres de plus. A voir
436
-	if (strpos($t,'<')===false)
437
-		return str_replace("\x00", '', $t);
433
+    if (!$t OR !is_string($t))
434
+        return $t;
435
+    # attention safehtml nettoie deux ou trois caracteres de plus. A voir
436
+    if (strpos($t,'<')===false)
437
+        return str_replace("\x00", '', $t);
438 438
 
439
-	$t = interdire_scripts($t); // jolifier le php
440
-	$t = echappe_js($t);
439
+    $t = interdire_scripts($t); // jolifier le php
440
+    $t = echappe_js($t);
441 441
 
442
-	if (!isset($safehtml))
443
-		$safehtml = charger_fonction('safehtml', 'inc', true);
444
-	if ($safehtml)
445
-		$t = $safehtml($t);
442
+    if (!isset($safehtml))
443
+        $safehtml = charger_fonction('safehtml', 'inc', true);
444
+    if ($safehtml)
445
+        $t = $safehtml($t);
446 446
 
447
-	return interdire_scripts($t); // interdire le php (2 precautions)
447
+    return interdire_scripts($t); // interdire le php (2 precautions)
448 448
 }
449 449
 
450 450
 
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 // TODO: gerer les modeles ?
455 455
 // http://doc.spip.org/@supprime_img
456 456
 function supprime_img($letexte, $message=NULL) {
457
-	if ($message===NULL) $message = '(' . _T('img_indisponible') . ')';
458
-	return preg_replace(',<(img|doc|emb)([0-9]+)(\|([^>]*))?'.'\s*/?'.'>,i',
459
-		$message, $letexte);
457
+    if ($message===NULL) $message = '(' . _T('img_indisponible') . ')';
458
+    return preg_replace(',<(img|doc|emb)([0-9]+)(\|([^>]*))?'.'\s*/?'.'>,i',
459
+        $message, $letexte);
460 460
 }
Please login to merge, or discard this patch.
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	// celle du texte) et public (spip_lang est la langue du texte)
26 26
 	$dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']);
27 27
 
28
-	$p = 'puce' . (test_espace_prive() ? '_prive' : '');
28
+	$p = 'puce'.(test_espace_prive() ? '_prive' : '');
29 29
 	if ($dir == 'rtl') $p .= '_rtl';
30 30
 
31 31
 	if (!isset($GLOBALS[$p])) {
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	.'d[ltd]|script|noscript|map|button|fieldset|style');
49 49
 
50 50
 if (!defined('_BALISES_BLOCS_REGEXP'))
51
-	define('_BALISES_BLOCS_REGEXP',',</?('._BALISES_BLOCS.')[>[:space:]],iS');
51
+	define('_BALISES_BLOCS_REGEXP', ',</?('._BALISES_BLOCS.')[>[:space:]],iS');
52 52
 
53 53
 //
54 54
 // Echapper les elements perilleux en les passant en base64
@@ -58,17 +58,17 @@  discard block
 block discarded – undo
58 58
 // une $source differente ; le script detecte automagiquement si ce qu'on
59 59
 // echappe est un div ou un span
60 60
 // http://doc.spip.org/@code_echappement
61
-function code_echappement($rempl, $source='', $no_transform=false, $mode=NULL) {
61
+function code_echappement($rempl, $source = '', $no_transform = false, $mode = NULL) {
62 62
 	if (!strlen($rempl)) return '';
63 63
 
64 64
 	// Tester si on echappe en span ou en div
65
-	if (is_null($mode) OR !in_array($mode,array('div','span')))
65
+	if (is_null($mode) OR !in_array($mode, array('div', 'span')))
66 66
 		$mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $rempl) ? 'div' : 'span';
67 67
 
68 68
 	// Decouper en morceaux, base64 a des probleme selon la taille de la pile
69 69
 	$taille = 30000;
70 70
 	$return = "";
71
-	for($i = 0; $i < strlen($rempl); $i += $taille) {
71
+	for ($i = 0; $i < strlen($rempl); $i += $taille) {
72 72
 		// Convertir en base64 et cacher dans un attribut
73 73
 		// utiliser les " pour eviter le re-encodage de ' et &#8217
74 74
 		$base64 = base64_encode(substr($rempl, $i, $taille));
@@ -89,11 +89,11 @@  discard block
 block discarded – undo
89 89
 // Echapper les <code>...</ code>
90 90
 // http://doc.spip.org/@traiter_echap_code_dist
91 91
 function traiter_echap_code_dist($regs) {
92
-	list(,,$att,$corps) = $regs;
92
+	list(,, $att, $corps) = $regs;
93 93
 	$echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code !
94 94
 
95 95
 	// ne pas mettre le <div...> s'il n'y a qu'une ligne
96
-	if (is_int(strpos($echap,"\n"))) {
96
+	if (is_int(strpos($echap, "\n"))) {
97 97
 		// supprimer les sauts de ligne debut/fin
98 98
 		// (mais pas les espaces => ascii art).
99 99
 		$echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", "", $echap);
@@ -115,11 +115,11 @@  discard block
 block discarded – undo
115 115
 function traiter_echap_cadre_dist($regs) {
116 116
 	$echap = trim(entites_html($regs[3]));
117 117
 	// compter les lignes un peu plus finement qu'avec les \n
118
-	$lignes = explode("\n",trim($echap));
118
+	$lignes = explode("\n", trim($echap));
119 119
 	$n = 0;
120
-	foreach($lignes as $l)
121
-		$n+=floor(strlen($l)/60)+1;
122
-	$n = max($n,2);
120
+	foreach ($lignes as $l)
121
+		$n += floor(strlen($l) / 60) + 1;
122
+	$n = max($n, 2);
123 123
 	$echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>";
124 124
 	return $echap;
125 125
 }
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 function traiter_echap_script_dist($regs) {
133 133
 	// rendre joli (et inactif) si c'est un script language=php
134 134
 	if (preg_match(',<script\b[^>]+php,ims', $regs[0]))
135
-		return highlight_string($regs[0],true);
135
+		return highlight_string($regs[0], true);
136 136
 
137 137
 	// Cas normal : le script passe tel quel
138 138
 	return $regs[0];
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
 // - pour $source voir commentaire infra (echappe_retour)
158 158
 // - pour $no_transform voir le filtre post_autobr dans inc/filtres
159 159
 // http://doc.spip.org/@echappe_html
160
-function echappe_html($letexte, $source='', $no_transform=false,
161
-$preg='') {
160
+function echappe_html($letexte, $source = '', $no_transform = false,
161
+$preg = '') {
162 162
 	if (!is_string($letexte) or !strlen($letexte))
163 163
 		return $letexte;
164 164
 
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 		}
173 173
 	}
174 174
 
175
-	if (($preg OR strpos($letexte,"<")!==false)
175
+	if (($preg OR strpos($letexte, "<") !== false)
176 176
 	  AND preg_match_all($preg ? $preg : _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER)) {
177 177
 		foreach ($matches as $regs) {
178 178
 			// echappements tels quels ?
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
 			else if (function_exists($f = $f.'_dist'))
187 187
 				$echap = $f($regs);
188 188
 
189
-			$p = strpos($letexte,$regs[0]);
190
-			$letexte = substr_replace($letexte,code_echappement($echap, $source, $no_transform),$p,strlen($regs[0]));
189
+			$p = strpos($letexte, $regs[0]);
190
+			$letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0]));
191 191
 		}
192 192
 	}
193 193
 
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 	// code mort sauf si on a personalise _PROTEGE_BLOCS sans y mettre <math>
199 199
 	// eviter la rupture de compat en branche 3.0
200 200
 	// a supprimer en branche 3.1
201
-	if (strpos($preg ? $preg : _PROTEGE_BLOCS,'code')!==false){
201
+	if (strpos($preg ? $preg : _PROTEGE_BLOCS, 'code') !== false) {
202 202
 		if (strpos($letexte, "<math>") !== false) {
203 203
 			include_spip('inc/math');
204 204
 			$letexte = traiter_math($letexte, $source);
@@ -209,12 +209,12 @@  discard block
 block discarded – undo
209 209
 	// seulement si on a echappe les <script>
210 210
 	// (derogatoire car on ne peut pas faire passer < ? ... ? >
211 211
 	// dans une callback autonommee
212
-	if (strpos($preg ? $preg : _PROTEGE_BLOCS,'script')!==false){
213
-		if (strpos($letexte,"<"."?")!==false AND preg_match_all(',<[?].*($|[?]>),UisS',
212
+	if (strpos($preg ? $preg : _PROTEGE_BLOCS, 'script') !== false) {
213
+		if (strpos($letexte, "<"."?") !== false AND preg_match_all(',<[?].*($|[?]>),UisS',
214 214
 		$letexte, $matches, PREG_SET_ORDER))
215 215
 		foreach ($matches as $regs) {
216 216
 			$letexte = str_replace($regs[0],
217
-				code_echappement(highlight_string($regs[0],true), $source),
217
+				code_echappement(highlight_string($regs[0], true), $source),
218 218
 				$letexte);
219 219
 		}
220 220
 	}
@@ -227,11 +227,11 @@  discard block
 block discarded – undo
227 227
 // Rq: $source sert a faire des echappements "a soi" qui ne sont pas nettoyes
228 228
 // par propre() : exemple dans multi et dans typo()
229 229
 // http://doc.spip.org/@echappe_retour
230
-function echappe_retour($letexte, $source='', $filtre = "") {
231
-	if (strpos($letexte,"base64$source")) {
230
+function echappe_retour($letexte, $source = '', $filtre = "") {
231
+	if (strpos($letexte, "base64$source")) {
232 232
 		# spip_log(spip_htmlspecialchars($letexte));  ## pour les curieux
233 233
 		$max_prof = 5;
234
-		while (strpos($letexte,"<")!==false
234
+		while (strpos($letexte, "<") !== false
235 235
 			AND
236 236
 		  preg_match_all(',<(span|div)\sclass=[\'"]base64'.$source.'[\'"]\s(.*)>\s*</\1>,UmsS',
237 237
 		$letexte, $regs, PREG_SET_ORDER)
@@ -240,13 +240,13 @@  discard block
 block discarded – undo
240 240
 				$rempl = base64_decode(extraire_attribut($reg[0], 'title'));
241 241
 				// recherche d'attributs supplementaires
242 242
 				$at = array();
243
-				foreach(array('lang', 'dir') as $attr) {
243
+				foreach (array('lang', 'dir') as $attr) {
244 244
 					if ($a = extraire_attribut($reg[0], $attr))
245 245
 						$at[$attr] = $a;
246 246
 				}
247 247
 				if ($at) {
248 248
 					$rempl = '<'.$reg[1].'>'.$rempl.'</'.$reg[1].'>';
249
-					foreach($at as $attr => $a)
249
+					foreach ($at as $attr => $a)
250 250
 						$rempl = inserer_attribut($rempl, $attr, $a);
251 251
 				}
252 252
 				if ($filtre) $rempl = $filtre($rempl);
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 // Reinserer le javascript de confiance (venant des modeles)
261 261
 
262 262
 // http://doc.spip.org/@echappe_retour_modeles
263
-function echappe_retour_modeles($letexte, $interdire_scripts=false)
263
+function echappe_retour_modeles($letexte, $interdire_scripts = false)
264 264
 {
265 265
 	$letexte = echappe_retour($letexte);
266 266
 
@@ -273,17 +273,17 @@  discard block
 block discarded – undo
273 273
 
274 274
 
275 275
 // http://doc.spip.org/@couper
276
-function couper($texte, $taille=50, $suite = '&nbsp;(...)') {
277
-	if (!($length=strlen($texte)) OR $taille <= 0) return '';
278
-	$offset = 400 + 2*$taille;
279
-	while ($offset<$length
280
-		AND strlen(preg_replace(",<[^>]+>,Uims","",substr($texte,0,$offset)))<$taille)
281
-		$offset = 2*$offset;
282
-	if (	$offset<$length
283
-			&& ($p_tag_ouvrant = strpos($texte,'<',$offset))!==NULL){
284
-		$p_tag_fermant = strpos($texte,'>',$offset);
285
-		if ($p_tag_fermant && ($p_tag_fermant<$p_tag_ouvrant))
286
-			$offset = $p_tag_fermant+1; // prolonger la coupe jusqu'au tag fermant suivant eventuel
276
+function couper($texte, $taille = 50, $suite = '&nbsp;(...)') {
277
+	if (!($length = strlen($texte)) OR $taille <= 0) return '';
278
+	$offset = 400 + 2 * $taille;
279
+	while ($offset < $length
280
+		AND strlen(preg_replace(",<[^>]+>,Uims", "", substr($texte, 0, $offset))) < $taille)
281
+		$offset = 2 * $offset;
282
+	if ($offset < $length
283
+			&& ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== NULL) {
284
+		$p_tag_fermant = strpos($texte, '>', $offset);
285
+		if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant))
286
+			$offset = $p_tag_fermant + 1; // prolonger la coupe jusqu'au tag fermant suivant eventuel
287 287
 	}
288 288
 	$texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */
289 289
 
@@ -300,8 +300,8 @@  discard block
 block discarded – undo
300 300
 
301 301
 	// supprimer les tags
302 302
 	$texte = supprimer_tags($texte);
303
-	$texte = trim(str_replace("\n"," ", $texte));
304
-	$texte .= "\n";	// marquer la fin
303
+	$texte = trim(str_replace("\n", " ", $texte));
304
+	$texte .= "\n"; // marquer la fin
305 305
 
306 306
 	// travailler en accents charset
307 307
 	$texte = unicode2charset(html2unicode($texte, /* secure */ true));
@@ -311,22 +311,22 @@  discard block
 block discarded – undo
311 311
 
312 312
 	// corriger la longueur de coupe
313 313
 	// en fonction de la presence de caracteres utf
314
-	if ($GLOBALS['meta']['charset']=='utf-8'){
314
+	if ($GLOBALS['meta']['charset'] == 'utf-8') {
315 315
 		$long = charset2unicode($texte);
316
-		$long = spip_substr($long, 0, max($taille,1));
316
+		$long = spip_substr($long, 0, max($taille, 1));
317 317
 		$nbcharutf = preg_match_all('/(&#[0-9]{3,5};)/S', $long, $matches);
318 318
 		$taille += $nbcharutf;
319 319
 	}
320 320
 
321 321
 
322 322
 	// couper au mot precedent
323
-	$long = spip_substr($texte, 0, max($taille-4,1));
323
+	$long = spip_substr($texte, 0, max($taille - 4, 1));
324 324
 	$u = $GLOBALS['meta']['pcre_u'];
325 325
 	$court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long);
326 326
 	$points = $suite;
327 327
 
328 328
 	// trop court ? ne pas faire de (...)
329
-	if (spip_strlen($court) < max(0.75 * $taille,2)) {
329
+	if (spip_strlen($court) < max(0.75 * $taille, 2)) {
330 330
 		$points = '';
331 331
 		$long = spip_substr($texte, 0, $taille);
332 332
 		$texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long);
@@ -351,37 +351,37 @@  discard block
 block discarded – undo
351 351
 
352 352
 // http://doc.spip.org/@protege_js_modeles
353 353
 function protege_js_modeles($t) {
354
-	if (isset($GLOBALS['visiteur_session'])){
355
-		if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)){
356
-			if (!defined('_PROTEGE_JS_MODELES')){
354
+	if (isset($GLOBALS['visiteur_session'])) {
355
+		if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) {
356
+			if (!defined('_PROTEGE_JS_MODELES')) {
357 357
 				include_spip('inc/acces');
358
-				define('_PROTEGE_JS_MODELES',creer_uniqid());
358
+				define('_PROTEGE_JS_MODELES', creer_uniqid());
359 359
 			}
360 360
 			foreach ($r as $regs)
361
-				$t = str_replace($regs[0],code_echappement($regs[0],'javascript'._PROTEGE_JS_MODELES),$t);
361
+				$t = str_replace($regs[0], code_echappement($regs[0], 'javascript'._PROTEGE_JS_MODELES), $t);
362 362
 		}
363
-		if (preg_match_all(',<\?php.*?($|\?'.'>),isS', $t, $r, PREG_SET_ORDER)){
364
-			if (!defined('_PROTEGE_PHP_MODELES')){
363
+		if (preg_match_all(',<\?php.*?($|\?'.'>),isS', $t, $r, PREG_SET_ORDER)) {
364
+			if (!defined('_PROTEGE_PHP_MODELES')) {
365 365
 				include_spip('inc/acces');
366
-				define('_PROTEGE_PHP_MODELES',creer_uniqid());
366
+				define('_PROTEGE_PHP_MODELES', creer_uniqid());
367 367
 			}
368 368
 			foreach ($r as $regs)
369
-				$t = str_replace($regs[0],code_echappement($regs[0],'php'._PROTEGE_PHP_MODELES),$t);
369
+				$t = str_replace($regs[0], code_echappement($regs[0], 'php'._PROTEGE_PHP_MODELES), $t);
370 370
 		}
371 371
 	}
372 372
 	return $t;
373 373
 }
374 374
 
375 375
 
376
-function echapper_faux_tags($letexte){
377
-	if (strpos($letexte,'<')===false)
376
+function echapper_faux_tags($letexte) {
377
+	if (strpos($letexte, '<') === false)
378 378
 		return $letexte;
379
-  $textMatches = preg_split (',(</?[a-z!][^<>]*>),', $letexte, null, PREG_SPLIT_DELIM_CAPTURE);
379
+  $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, null, PREG_SPLIT_DELIM_CAPTURE);
380 380
 
381 381
   $letexte = "";
382 382
   while (count($textMatches)) {
383 383
   	// un texte a echapper
384
-  	$letexte .= str_replace("<",'&lt;',array_shift($textMatches));
384
+  	$letexte .= str_replace("<", '&lt;', array_shift($textMatches));
385 385
   	// un tag html qui a servit a faite le split
386 386
  		$letexte .= array_shift($textMatches);
387 387
   }
@@ -396,15 +396,15 @@  discard block
 block discarded – undo
396 396
  * @param string $texte
397 397
  * @return string
398 398
  */
399
-function echapper_html_suspect($texte){
400
-	if (strpos($texte,'<')===false OR strpos($texte,'=')===false)
399
+function echapper_html_suspect($texte) {
400
+	if (strpos($texte, '<') === false OR strpos($texte, '=') === false)
401 401
 		return $texte;
402 402
 
403 403
 	// on teste sur strlen car safehtml supprime le contenu dangereux
404 404
 	// mais il peut aussi changer des ' en " sur les attributs html,
405 405
 	// donc un test d'egalite est trop strict
406
-	if (strlen(safehtml($texte))!==strlen($texte)){
407
-		$texte = str_replace("<","&lt;",$texte);
406
+	if (strlen(safehtml($texte)) !== strlen($texte)) {
407
+		$texte = str_replace("<", "&lt;", $texte);
408 408
 	}
409 409
 
410 410
 	return $texte;
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 	if (!$t OR !is_string($t))
434 434
 		return $t;
435 435
 	# attention safehtml nettoie deux ou trois caracteres de plus. A voir
436
-	if (strpos($t,'<')===false)
436
+	if (strpos($t, '<') === false)
437 437
 		return str_replace("\x00", '', $t);
438 438
 
439 439
 	$t = interdire_scripts($t); // jolifier le php
@@ -453,8 +453,8 @@  discard block
 block discarded – undo
453 453
 // Sert aussi a nettoyer un texte qu'on veut mettre dans un <a> etc.
454 454
 // TODO: gerer les modeles ?
455 455
 // http://doc.spip.org/@supprime_img
456
-function supprime_img($letexte, $message=NULL) {
457
-	if ($message===NULL) $message = '(' . _T('img_indisponible') . ')';
456
+function supprime_img($letexte, $message = NULL) {
457
+	if ($message === NULL) $message = '('._T('img_indisponible').')';
458 458
 	return preg_replace(',<(img|doc|emb)([0-9]+)(\|([^>]*))?'.'\s*/?'.'>,i',
459 459
 		$message, $letexte);
460 460
 }
Please login to merge, or discard this patch.
Braces   +104 added lines, -60 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 include_spip('inc/filtres');
15 17
 include_spip('inc/lang');
16 18
 
@@ -26,7 +28,9 @@  discard block
 block discarded – undo
26 28
 	$dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']);
27 29
 
28 30
 	$p = 'puce' . (test_espace_prive() ? '_prive' : '');
29
-	if ($dir == 'rtl') $p .= '_rtl';
31
+	if ($dir == 'rtl') {
32
+	    $p .= '_rtl';
33
+	}
30 34
 
31 35
 	if (!isset($GLOBALS[$p])) {
32 36
 		$img = find_in_path($p.'.gif');
@@ -40,15 +44,18 @@  discard block
 block discarded – undo
40 44
 // XHTML - Preserver les balises-bloc : on liste ici tous les elements
41 45
 // dont on souhaite qu'ils provoquent un saut de paragraphe
42 46
 
43
-if (!defined('_BALISES_BLOCS')) define('_BALISES_BLOCS',
47
+if (!defined('_BALISES_BLOCS')) {
48
+    define('_BALISES_BLOCS',
44 49
 	'p|div|pre|ul|ol|li|blockquote|h[1-6r]|'
45 50
 	.'t(able|[rdh]|head|body|foot|extarea)|'
46 51
 	.'form|object|center|marquee|address|'
47 52
 	.'applet|iframe|'
48 53
 	.'d[ltd]|script|noscript|map|button|fieldset|style');
54
+}
49 55
 
50
-if (!defined('_BALISES_BLOCS_REGEXP'))
56
+if (!defined('_BALISES_BLOCS_REGEXP')) {
51 57
 	define('_BALISES_BLOCS_REGEXP',',</?('._BALISES_BLOCS.')[>[:space:]],iS');
58
+}
52 59
 
53 60
 //
54 61
 // Echapper les elements perilleux en les passant en base64
@@ -59,11 +66,14 @@  discard block
 block discarded – undo
59 66
 // echappe est un div ou un span
60 67
 // http://doc.spip.org/@code_echappement
61 68
 function code_echappement($rempl, $source='', $no_transform=false, $mode=NULL) {
62
-	if (!strlen($rempl)) return '';
69
+	if (!strlen($rempl)) {
70
+	    return '';
71
+	}
63 72
 
64 73
 	// Tester si on echappe en span ou en div
65
-	if (is_null($mode) OR !in_array($mode,array('div','span')))
66
-		$mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $rempl) ? 'div' : 'span';
74
+	if (is_null($mode) OR !in_array($mode,array('div','span'))) {
75
+			$mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $rempl) ? 'div' : 'span';
76
+	}
67 77
 
68 78
 	// Decouper en morceaux, base64 a des probleme selon la taille de la pile
69 79
 	$taille = 30000;
@@ -117,8 +127,9 @@  discard block
 block discarded – undo
117 127
 	// compter les lignes un peu plus finement qu'avec les \n
118 128
 	$lignes = explode("\n",trim($echap));
119 129
 	$n = 0;
120
-	foreach($lignes as $l)
121
-		$n+=floor(strlen($l)/60)+1;
130
+	foreach($lignes as $l) {
131
+			$n+=floor(strlen($l)/60)+1;
132
+	}
122 133
 	$n = max($n,2);
123 134
 	$echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>";
124 135
 	return $echap;
@@ -131,8 +142,9 @@  discard block
 block discarded – undo
131 142
 // http://doc.spip.org/@traiter_echap_script_dist
132 143
 function traiter_echap_script_dist($regs) {
133 144
 	// rendre joli (et inactif) si c'est un script language=php
134
-	if (preg_match(',<script\b[^>]+php,ims', $regs[0]))
135
-		return highlight_string($regs[0],true);
145
+	if (preg_match(',<script\b[^>]+php,ims', $regs[0])) {
146
+			return highlight_string($regs[0],true);
147
+	}
136 148
 
137 149
 	// Cas normal : le script passe tel quel
138 150
 	return $regs[0];
@@ -145,8 +157,9 @@  discard block
 block discarded – undo
145 157
  */
146 158
 function traiter_echap_math_dist($regs) {
147 159
 	// Gestion du TeX
148
-	if (!function_exists('traiter_math'))
149
-		include_spip('inc/math');
160
+	if (!function_exists('traiter_math')) {
161
+			include_spip('inc/math');
162
+	}
150 163
 
151 164
 	$t = traiter_math($regs[0], '');
152 165
 	return $t;
@@ -159,13 +172,16 @@  discard block
 block discarded – undo
159 172
 // http://doc.spip.org/@echappe_html
160 173
 function echappe_html($letexte, $source='', $no_transform=false,
161 174
 $preg='') {
162
-	if (!is_string($letexte) or !strlen($letexte))
163
-		return $letexte;
175
+	if (!is_string($letexte) or !strlen($letexte)) {
176
+			return $letexte;
177
+	}
164 178
 
165 179
 	// si le texte recu est long PCRE risque d'exploser, on
166 180
 	// fait donc un mic-mac pour augmenter pcre.backtrack_limit
167 181
 	if (($len = strlen($letexte)) > 100000) {
168
-		if (!$old = @ini_get('pcre.backtrack_limit')) $old = 100000;
182
+		if (!$old = @ini_get('pcre.backtrack_limit')) {
183
+		    $old = 100000;
184
+		}
169 185
 		if ($len > $old) {
170 186
 			$a = @ini_set('pcre.backtrack_limit', $len);
171 187
 			spip_log("ini_set pcre.backtrack_limit=$len ($old)");
@@ -181,18 +197,20 @@  discard block
 block discarded – undo
181 197
 			}
182 198
 
183 199
 			// sinon les traiter selon le cas
184
-			else if (function_exists($f = 'traiter_echap_'.strtolower($regs[1])))
185
-				$echap = $f($regs);
186
-			else if (function_exists($f = $f.'_dist'))
187
-				$echap = $f($regs);
200
+			else if (function_exists($f = 'traiter_echap_'.strtolower($regs[1]))) {
201
+							$echap = $f($regs);
202
+			} else if (function_exists($f = $f.'_dist')) {
203
+							$echap = $f($regs);
204
+			}
188 205
 
189 206
 			$p = strpos($letexte,$regs[0]);
190 207
 			$letexte = substr_replace($letexte,code_echappement($echap, $source, $no_transform),$p,strlen($regs[0]));
191 208
 		}
192 209
 	}
193 210
 
194
-	if ($no_transform)
195
-		return $letexte;
211
+	if ($no_transform) {
212
+			return $letexte;
213
+	}
196 214
 
197 215
 	// Gestion du TeX
198 216
 	// code mort sauf si on a personalise _PROTEGE_BLOCS sans y mettre <math>
@@ -211,12 +229,13 @@  discard block
 block discarded – undo
211 229
 	// dans une callback autonommee
212 230
 	if (strpos($preg ? $preg : _PROTEGE_BLOCS,'script')!==false){
213 231
 		if (strpos($letexte,"<"."?")!==false AND preg_match_all(',<[?].*($|[?]>),UisS',
214
-		$letexte, $matches, PREG_SET_ORDER))
215
-		foreach ($matches as $regs) {
232
+		$letexte, $matches, PREG_SET_ORDER)) {
233
+				foreach ($matches as $regs) {
216 234
 			$letexte = str_replace($regs[0],
217 235
 				code_echappement(highlight_string($regs[0],true), $source),
218 236
 				$letexte);
219 237
 		}
238
+		}
220 239
 	}
221 240
 
222 241
 	return $letexte;
@@ -241,15 +260,19 @@  discard block
 block discarded – undo
241 260
 				// recherche d'attributs supplementaires
242 261
 				$at = array();
243 262
 				foreach(array('lang', 'dir') as $attr) {
244
-					if ($a = extraire_attribut($reg[0], $attr))
245
-						$at[$attr] = $a;
263
+					if ($a = extraire_attribut($reg[0], $attr)) {
264
+											$at[$attr] = $a;
265
+					}
246 266
 				}
247 267
 				if ($at) {
248 268
 					$rempl = '<'.$reg[1].'>'.$rempl.'</'.$reg[1].'>';
249
-					foreach($at as $attr => $a)
250
-						$rempl = inserer_attribut($rempl, $attr, $a);
269
+					foreach($at as $attr => $a) {
270
+											$rempl = inserer_attribut($rempl, $attr, $a);
271
+					}
272
+				}
273
+				if ($filtre) {
274
+				    $rempl = $filtre($rempl);
251 275
 				}
252
-				if ($filtre) $rempl = $filtre($rempl);
253 276
 				$letexte = str_replace($reg[0], $rempl, $letexte);
254 277
 			}
255 278
 		}
@@ -265,8 +288,9 @@  discard block
 block discarded – undo
265 288
 	$letexte = echappe_retour($letexte);
266 289
 
267 290
 	// Dans les appels directs hors squelette, securiser aussi ici
268
-	if ($interdire_scripts)
269
-		$letexte = interdire_scripts($letexte);
291
+	if ($interdire_scripts) {
292
+			$letexte = interdire_scripts($letexte);
293
+	}
270 294
 
271 295
 	return trim($letexte);
272 296
 }
@@ -274,16 +298,21 @@  discard block
 block discarded – undo
274 298
 
275 299
 // http://doc.spip.org/@couper
276 300
 function couper($texte, $taille=50, $suite = '&nbsp;(...)') {
277
-	if (!($length=strlen($texte)) OR $taille <= 0) return '';
301
+	if (!($length=strlen($texte)) OR $taille <= 0) {
302
+	    return '';
303
+	}
278 304
 	$offset = 400 + 2*$taille;
279 305
 	while ($offset<$length
280
-		AND strlen(preg_replace(",<[^>]+>,Uims","",substr($texte,0,$offset)))<$taille)
281
-		$offset = 2*$offset;
306
+		AND strlen(preg_replace(",<[^>]+>,Uims","",substr($texte,0,$offset)))<$taille) {
307
+			$offset = 2*$offset;
308
+	}
282 309
 	if (	$offset<$length
283 310
 			&& ($p_tag_ouvrant = strpos($texte,'<',$offset))!==NULL){
284 311
 		$p_tag_fermant = strpos($texte,'>',$offset);
285
-		if ($p_tag_fermant && ($p_tag_fermant<$p_tag_ouvrant))
286
-			$offset = $p_tag_fermant+1; // prolonger la coupe jusqu'au tag fermant suivant eventuel
312
+		if ($p_tag_fermant && ($p_tag_fermant<$p_tag_ouvrant)) {
313
+					$offset = $p_tag_fermant+1;
314
+		}
315
+		// prolonger la coupe jusqu'au tag fermant suivant eventuel
287 316
 	}
288 317
 	$texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */
289 318
 
@@ -305,8 +334,9 @@  discard block
 block discarded – undo
305 334
 
306 335
 	// travailler en accents charset
307 336
 	$texte = unicode2charset(html2unicode($texte, /* secure */ true));
308
-	if (!function_exists('nettoyer_raccourcis_typo'))
309
-		include_spip('inc/lien');
337
+	if (!function_exists('nettoyer_raccourcis_typo')) {
338
+			include_spip('inc/lien');
339
+	}
310 340
 	$texte = nettoyer_raccourcis_typo($texte);
311 341
 
312 342
 	// corriger la longueur de coupe
@@ -331,13 +361,17 @@  discard block
 block discarded – undo
331 361
 		$long = spip_substr($texte, 0, $taille);
332 362
 		$texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long);
333 363
 		// encore trop court ? couper au caractere
334
-		if (spip_strlen($texte) < 0.75 * $taille)
335
-			$texte = $long;
336
-	} else
337
-		$texte = $court;
364
+		if (spip_strlen($texte) < 0.75 * $taille) {
365
+					$texte = $long;
366
+		}
367
+	} else {
368
+			$texte = $court;
369
+	}
338 370
 
339
-	if (strpos($texte, "\n"))	// la fin est encore la : c'est qu'on n'a pas de texte de suite
371
+	if (strpos($texte, "\n")) {
372
+	    // la fin est encore la : c'est qu'on n'a pas de texte de suite
340 373
 		$points = '';
374
+	}
341 375
 
342 376
 	// remettre les paragraphes
343 377
 	$texte = preg_replace("/\r+/", "\n\n", $texte);
@@ -357,16 +391,18 @@  discard block
 block discarded – undo
357 391
 				include_spip('inc/acces');
358 392
 				define('_PROTEGE_JS_MODELES',creer_uniqid());
359 393
 			}
360
-			foreach ($r as $regs)
361
-				$t = str_replace($regs[0],code_echappement($regs[0],'javascript'._PROTEGE_JS_MODELES),$t);
394
+			foreach ($r as $regs) {
395
+							$t = str_replace($regs[0],code_echappement($regs[0],'javascript'._PROTEGE_JS_MODELES),$t);
396
+			}
362 397
 		}
363 398
 		if (preg_match_all(',<\?php.*?($|\?'.'>),isS', $t, $r, PREG_SET_ORDER)){
364 399
 			if (!defined('_PROTEGE_PHP_MODELES')){
365 400
 				include_spip('inc/acces');
366 401
 				define('_PROTEGE_PHP_MODELES',creer_uniqid());
367 402
 			}
368
-			foreach ($r as $regs)
369
-				$t = str_replace($regs[0],code_echappement($regs[0],'php'._PROTEGE_PHP_MODELES),$t);
403
+			foreach ($r as $regs) {
404
+							$t = str_replace($regs[0],code_echappement($regs[0],'php'._PROTEGE_PHP_MODELES),$t);
405
+			}
370 406
 		}
371 407
 	}
372 408
 	return $t;
@@ -374,8 +410,9 @@  discard block
 block discarded – undo
374 410
 
375 411
 
376 412
 function echapper_faux_tags($letexte){
377
-	if (strpos($letexte,'<')===false)
378
-		return $letexte;
413
+	if (strpos($letexte,'<')===false) {
414
+			return $letexte;
415
+	}
379 416
   $textMatches = preg_split (',(</?[a-z!][^<>]*>),', $letexte, null, PREG_SPLIT_DELIM_CAPTURE);
380 417
 
381 418
   $letexte = "";
@@ -397,8 +434,9 @@  discard block
 block discarded – undo
397 434
  * @return string
398 435
  */
399 436
 function echapper_html_suspect($texte){
400
-	if (strpos($texte,'<')===false OR strpos($texte,'=')===false)
401
-		return $texte;
437
+	if (strpos($texte,'<')===false OR strpos($texte,'=')===false) {
438
+			return $texte;
439
+	}
402 440
 
403 441
 	// on teste sur strlen car safehtml supprime le contenu dangereux
404 442
 	// mais il peut aussi changer des ' en " sur les attributs html,
@@ -430,19 +468,23 @@  discard block
 block discarded – undo
430 468
 function safehtml($t) {
431 469
 	static $safehtml;
432 470
 
433
-	if (!$t OR !is_string($t))
434
-		return $t;
471
+	if (!$t OR !is_string($t)) {
472
+			return $t;
473
+	}
435 474
 	# attention safehtml nettoie deux ou trois caracteres de plus. A voir
436
-	if (strpos($t,'<')===false)
437
-		return str_replace("\x00", '', $t);
475
+	if (strpos($t,'<')===false) {
476
+			return str_replace("\x00", '', $t);
477
+	}
438 478
 
439 479
 	$t = interdire_scripts($t); // jolifier le php
440 480
 	$t = echappe_js($t);
441 481
 
442
-	if (!isset($safehtml))
443
-		$safehtml = charger_fonction('safehtml', 'inc', true);
444
-	if ($safehtml)
445
-		$t = $safehtml($t);
482
+	if (!isset($safehtml)) {
483
+			$safehtml = charger_fonction('safehtml', 'inc', true);
484
+	}
485
+	if ($safehtml) {
486
+			$t = $safehtml($t);
487
+	}
446 488
 
447 489
 	return interdire_scripts($t); // interdire le php (2 precautions)
448 490
 }
@@ -454,7 +496,9 @@  discard block
 block discarded – undo
454 496
 // TODO: gerer les modeles ?
455 497
 // http://doc.spip.org/@supprime_img
456 498
 function supprime_img($letexte, $message=NULL) {
457
-	if ($message===NULL) $message = '(' . _T('img_indisponible') . ')';
499
+	if ($message===NULL) {
500
+	    $message = '(' . _T('img_indisponible') . ')';
501
+	}
458 502
 	return preg_replace(',<(img|doc|emb)([0-9]+)(\|([^>]*))?'.'\s*/?'.'>,i',
459 503
 		$message, $letexte);
460 504
 }
Please login to merge, or discard this patch.
ecrire/inc/traduire.php 4 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  * version dediee et optimisee pour cet usage de find_in_path
19 19
  *
20 20
  * @staticvar <type> $dirs
21
- * @param <type> $file
21
+ * @param string $file
22 22
  * @param <type> $dirname
23 23
  * @return <type>
24 24
  */
@@ -40,6 +40,9 @@  discard block
 block discarded – undo
40 40
 // Charger un fichier langue
41 41
 //
42 42
 // http://doc.spip.org/@chercher_module_lang
43
+/**
44
+ * @param string $module
45
+ */
43 46
 function chercher_module_lang($module, $lang = '') {
44 47
 	if ($lang)
45 48
 		$lang = '_'.$lang;
Please login to merge, or discard this patch.
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -23,63 +23,63 @@  discard block
 block discarded – undo
23 23
  * @return <type>
24 24
  */
25 25
 function find_langs_in_path ($file, $dirname='lang') {
26
-	static $dirs=array();
27
-	$liste = array();
28
-	foreach(creer_chemin() as $dir) {
29
-		if (!isset($dirs[$a = $dir . $dirname]))
30
-			$dirs[$a] = (is_dir($a) || !$a) ;
31
-		if ($dirs[$a]) {
32
-			if (is_readable($a .= $file)) {
33
-				$liste[] = $a;
34
-			}
35
-		}
36
-	}
37
-	return array_reverse($liste);
26
+    static $dirs=array();
27
+    $liste = array();
28
+    foreach(creer_chemin() as $dir) {
29
+        if (!isset($dirs[$a = $dir . $dirname]))
30
+            $dirs[$a] = (is_dir($a) || !$a) ;
31
+        if ($dirs[$a]) {
32
+            if (is_readable($a .= $file)) {
33
+                $liste[] = $a;
34
+            }
35
+        }
36
+    }
37
+    return array_reverse($liste);
38 38
 }
39 39
 //
40 40
 // Charger un fichier langue
41 41
 //
42 42
 // http://doc.spip.org/@chercher_module_lang
43 43
 function chercher_module_lang($module, $lang = '') {
44
-	if ($lang)
45
-		$lang = '_'.$lang;
46
-
47
-	// 1) dans un repertoire nomme lang/ se trouvant sur le chemin
48
-	if ($f = ($module == 'local'
49
-		? find_in_path($module.$lang.'.php', 'lang/')
50
-		: find_langs_in_path($module.$lang.'.php', 'lang/')))
51
-		return is_array($f)?$f:array($f);
52
-
53
-	// 2) directement dans le chemin (old style, uniquement pour local)
54
-	return (($module == 'local') OR strpos($module, '/'))
55
-		? (($f = find_in_path($module.$lang. '.php')) ? array($f):false)
56
-		: false;
44
+    if ($lang)
45
+        $lang = '_'.$lang;
46
+
47
+    // 1) dans un repertoire nomme lang/ se trouvant sur le chemin
48
+    if ($f = ($module == 'local'
49
+        ? find_in_path($module.$lang.'.php', 'lang/')
50
+        : find_langs_in_path($module.$lang.'.php', 'lang/')))
51
+        return is_array($f)?$f:array($f);
52
+
53
+    // 2) directement dans le chemin (old style, uniquement pour local)
54
+    return (($module == 'local') OR strpos($module, '/'))
55
+        ? (($f = find_in_path($module.$lang. '.php')) ? array($f):false)
56
+        : false;
57 57
 }
58 58
 
59 59
 // http://doc.spip.org/@charger_langue
60 60
 function charger_langue($lang, $module = 'spip') {
61
-	if ($lang AND $fichiers_lang = chercher_module_lang($module, $lang)) {
62
-		$GLOBALS['idx_lang']='i18n_'.$module.'_'.$lang;
63
-		include(array_shift($fichiers_lang));
64
-		surcharger_langue($fichiers_lang);
65
-	} else {
66
-		// si le fichier de langue du module n'existe pas, on se rabat sur
67
-		// la langue par defaut du site -- et au pire sur le francais, qui
68
-		// *par definition* doit exister, et on copie le tableau dans la
69
-		// var liee a la langue
70
-		$l = $GLOBALS['meta']['langue_site'];
71
-		if (!$fichiers_lang = chercher_module_lang($module, $l))
72
-			$fichiers_lang = chercher_module_lang($module, _LANGUE_PAR_DEFAUT);
73
-
74
-		if ($fichiers_lang) {
75
-			$GLOBALS['idx_lang']='i18n_'.$module.'_' .$l;
76
-			include(array_shift($fichiers_lang));
77
-			surcharger_langue($fichiers_lang);
78
-			$GLOBALS['i18n_'.$module.'_'.$lang]
79
-				= &$GLOBALS['i18n_'.$module.'_'.$l];
80
-			#spip_log("module de langue : ${module}_$l.php");
81
-		}
82
-	}
61
+    if ($lang AND $fichiers_lang = chercher_module_lang($module, $lang)) {
62
+        $GLOBALS['idx_lang']='i18n_'.$module.'_'.$lang;
63
+        include(array_shift($fichiers_lang));
64
+        surcharger_langue($fichiers_lang);
65
+    } else {
66
+        // si le fichier de langue du module n'existe pas, on se rabat sur
67
+        // la langue par defaut du site -- et au pire sur le francais, qui
68
+        // *par definition* doit exister, et on copie le tableau dans la
69
+        // var liee a la langue
70
+        $l = $GLOBALS['meta']['langue_site'];
71
+        if (!$fichiers_lang = chercher_module_lang($module, $l))
72
+            $fichiers_lang = chercher_module_lang($module, _LANGUE_PAR_DEFAUT);
73
+
74
+        if ($fichiers_lang) {
75
+            $GLOBALS['idx_lang']='i18n_'.$module.'_' .$l;
76
+            include(array_shift($fichiers_lang));
77
+            surcharger_langue($fichiers_lang);
78
+            $GLOBALS['i18n_'.$module.'_'.$lang]
79
+                = &$GLOBALS['i18n_'.$module.'_'.$l];
80
+            #spip_log("module de langue : ${module}_$l.php");
81
+        }
82
+    }
83 83
 }
84 84
 
85 85
 //
@@ -87,27 +87,27 @@  discard block
 block discarded – undo
87 87
 //
88 88
 // http://doc.spip.org/@surcharger_langue
89 89
 function surcharger_langue($fichiers) {
90
-	static $surcharges = array();
91
-	if (!isset($GLOBALS['idx_lang'])) return;
92
-
93
-	if (!is_array($fichiers)) $fichiers = array($fichiers);
94
-	if (!count($fichiers)) return;
95
-	foreach($fichiers as $fichier){
96
-		if (!isset($surcharges[$fichier])) {
97
-			$idx_lang_normal = $GLOBALS['idx_lang'];
98
-			$GLOBALS['idx_lang'] = $GLOBALS['idx_lang'].'@temporaire';
99
-			include($fichier);
100
-			$surcharges[$fichier] = $GLOBALS[$GLOBALS['idx_lang']];
101
-			unset ($GLOBALS[$GLOBALS['idx_lang']]);
102
-			$GLOBALS['idx_lang'] = $idx_lang_normal;
103
-		}
104
-		if (is_array($surcharges[$fichier])) {
105
-			$GLOBALS[$GLOBALS['idx_lang']] = array_merge(
106
-				(array)$GLOBALS[$GLOBALS['idx_lang']],
107
-				$surcharges[$fichier]
108
-			);
109
-		}
110
-	}
90
+    static $surcharges = array();
91
+    if (!isset($GLOBALS['idx_lang'])) return;
92
+
93
+    if (!is_array($fichiers)) $fichiers = array($fichiers);
94
+    if (!count($fichiers)) return;
95
+    foreach($fichiers as $fichier){
96
+        if (!isset($surcharges[$fichier])) {
97
+            $idx_lang_normal = $GLOBALS['idx_lang'];
98
+            $GLOBALS['idx_lang'] = $GLOBALS['idx_lang'].'@temporaire';
99
+            include($fichier);
100
+            $surcharges[$fichier] = $GLOBALS[$GLOBALS['idx_lang']];
101
+            unset ($GLOBALS[$GLOBALS['idx_lang']]);
102
+            $GLOBALS['idx_lang'] = $idx_lang_normal;
103
+        }
104
+        if (is_array($surcharges[$fichier])) {
105
+            $GLOBALS[$GLOBALS['idx_lang']] = array_merge(
106
+                (array)$GLOBALS[$GLOBALS['idx_lang']],
107
+                $surcharges[$fichier]
108
+            );
109
+        }
110
+    }
111 111
 }
112 112
 
113 113
 //
@@ -115,95 +115,95 @@  discard block
 block discarded – undo
115 115
 //
116 116
 // http://doc.spip.org/@inc_traduire_dist
117 117
 function inc_traduire_dist($ori, $lang) {
118
-	static $deja_vu = array();
119
-	static $local = array();
118
+    static $deja_vu = array();
119
+    static $local = array();
120 120
   
121
-	if (isset($deja_vu[$lang][$ori]) AND (_request('var_mode') != 'traduction'))
122
-		return $deja_vu[$lang][$ori];
123
-
124
-	// modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES
125
-	if (strpos($ori,':')) {
126
-		list($modules,$code) = explode(':',$ori,2);
127
-		$modules = explode('|', $modules);
128
-		$ori_complet = $ori;
129
-	} else {
130
-		$modules = array('spip', 'ecrire');
131
-		$code = $ori;
132
-		$ori_complet = implode('|', $modules) . ':' . $ori;
133
-	}
134
-
135
-	$text = '';
136
-	// parcourir tous les modules jusqu'a ce qu'on trouve
137
-	foreach ($modules as $module) {
138
-		$var = "i18n_".$module."_".$lang;
139
-
140
-		if (empty($GLOBALS[$var])) {
141
-			charger_langue($lang, $module);
142
-
143
-			// surcharge perso
144
-			// -- on cherche (lang/)local_xx.php ...
145
-			if (!isset($local['local_'.$lang])) {
146
-				// redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer)
147
-				$GLOBALS['idx_lang']= $var;
148
-				$local['local_'.$lang] = chercher_module_lang('local', $lang);
149
-			}
150
-			if ($local['local_'.$lang])
151
-				surcharger_langue($local['local_'.$lang]);
152
-			// ... puis (lang/)local.php
153
-			if (!isset($local['local']))
154
-				$local['local'] = chercher_module_lang('local');
155
-			if ($local['local'])
156
-				surcharger_langue($local['local']);
157
-		}
158
-
159
-		if (isset($GLOBALS[$var][$code])) {
160
-			$module_retenu = $module;
161
-			$text = $GLOBALS[$var][$code];
162
-			break;
163
-		}
164
-	}
165
-
166
-	// Retour aux sources si la chaine est absente dans la langue cible ;
167
-	// on essaie d'abord la langue du site, puis a defaut la langue fr
168
-	$langue_retenue = $lang;
169
-	if (!strlen($text)
170
-	AND $lang !== _LANGUE_PAR_DEFAUT) {
171
-		if ($lang !== $GLOBALS['meta']['langue_site']) {
172
-			$text = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site']);
173
-			$langue_retenue = (!strlen($text) ? $GLOBALS['meta']['langue_site'] : '');
174
-		}
175
-		else {
176
-			$text = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT);
177
-			$langue_retenue = (!strlen($text) ? _LANGUE_PAR_DEFAUT : '');
178
-		}
179
-	}
180
-
181
-	// Supprimer la mention <NEW> ou <MODIF>
182
-	if (substr($text,0,1) === '<')
183
-		$text = str_replace(array('<NEW>', '<MODIF>'), array(), $text);
184
-
185
-	// Si on n'est pas en utf-8, la chaine peut l'etre...
186
-	// le cas echeant on la convertit en entites html &#xxx;
187
-	if ($GLOBALS['meta']['charset'] !== 'utf-8'
188
-	AND preg_match(',[\x7f-\xff],S', $text)) {
189
-		include_spip('inc/charsets');
190
-		$text = charset2unicode($text,'utf-8');
191
-	}
192
-
193
-	if (_request('var_mode') == 'traduction') {
194
-		if ($text)  {
195
-			$classe = 'debug-traduction' . ($module_retenu == 'ecrire' ? '-prive' : '');
196
-			$text = '<span lang=' . $langue_retenue . ' class=' . $classe . ' title=' . $ori_complet . '(' . $langue_retenue . ')>' . $text . '</span>';
197
-			$text = str_replace(
198
-						array("$module_retenu:", "$module_retenu|"),
199
-						array("*$module_retenu*:", "*$module_retenu*|"),
200
-						$text);
201
-		}
202
-	}
203
-	else {
204
-		$deja_vu[$lang][$ori] = $text;
205
-	}
206
-
207
-	return $text;
121
+    if (isset($deja_vu[$lang][$ori]) AND (_request('var_mode') != 'traduction'))
122
+        return $deja_vu[$lang][$ori];
123
+
124
+    // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES
125
+    if (strpos($ori,':')) {
126
+        list($modules,$code) = explode(':',$ori,2);
127
+        $modules = explode('|', $modules);
128
+        $ori_complet = $ori;
129
+    } else {
130
+        $modules = array('spip', 'ecrire');
131
+        $code = $ori;
132
+        $ori_complet = implode('|', $modules) . ':' . $ori;
133
+    }
134
+
135
+    $text = '';
136
+    // parcourir tous les modules jusqu'a ce qu'on trouve
137
+    foreach ($modules as $module) {
138
+        $var = "i18n_".$module."_".$lang;
139
+
140
+        if (empty($GLOBALS[$var])) {
141
+            charger_langue($lang, $module);
142
+
143
+            // surcharge perso
144
+            // -- on cherche (lang/)local_xx.php ...
145
+            if (!isset($local['local_'.$lang])) {
146
+                // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer)
147
+                $GLOBALS['idx_lang']= $var;
148
+                $local['local_'.$lang] = chercher_module_lang('local', $lang);
149
+            }
150
+            if ($local['local_'.$lang])
151
+                surcharger_langue($local['local_'.$lang]);
152
+            // ... puis (lang/)local.php
153
+            if (!isset($local['local']))
154
+                $local['local'] = chercher_module_lang('local');
155
+            if ($local['local'])
156
+                surcharger_langue($local['local']);
157
+        }
158
+
159
+        if (isset($GLOBALS[$var][$code])) {
160
+            $module_retenu = $module;
161
+            $text = $GLOBALS[$var][$code];
162
+            break;
163
+        }
164
+    }
165
+
166
+    // Retour aux sources si la chaine est absente dans la langue cible ;
167
+    // on essaie d'abord la langue du site, puis a defaut la langue fr
168
+    $langue_retenue = $lang;
169
+    if (!strlen($text)
170
+    AND $lang !== _LANGUE_PAR_DEFAUT) {
171
+        if ($lang !== $GLOBALS['meta']['langue_site']) {
172
+            $text = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site']);
173
+            $langue_retenue = (!strlen($text) ? $GLOBALS['meta']['langue_site'] : '');
174
+        }
175
+        else {
176
+            $text = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT);
177
+            $langue_retenue = (!strlen($text) ? _LANGUE_PAR_DEFAUT : '');
178
+        }
179
+    }
180
+
181
+    // Supprimer la mention <NEW> ou <MODIF>
182
+    if (substr($text,0,1) === '<')
183
+        $text = str_replace(array('<NEW>', '<MODIF>'), array(), $text);
184
+
185
+    // Si on n'est pas en utf-8, la chaine peut l'etre...
186
+    // le cas echeant on la convertit en entites html &#xxx;
187
+    if ($GLOBALS['meta']['charset'] !== 'utf-8'
188
+    AND preg_match(',[\x7f-\xff],S', $text)) {
189
+        include_spip('inc/charsets');
190
+        $text = charset2unicode($text,'utf-8');
191
+    }
192
+
193
+    if (_request('var_mode') == 'traduction') {
194
+        if ($text)  {
195
+            $classe = 'debug-traduction' . ($module_retenu == 'ecrire' ? '-prive' : '');
196
+            $text = '<span lang=' . $langue_retenue . ' class=' . $classe . ' title=' . $ori_complet . '(' . $langue_retenue . ')>' . $text . '</span>';
197
+            $text = str_replace(
198
+                        array("$module_retenu:", "$module_retenu|"),
199
+                        array("*$module_retenu*:", "*$module_retenu*|"),
200
+                        $text);
201
+        }
202
+    }
203
+    else {
204
+        $deja_vu[$lang][$ori] = $text;
205
+    }
206
+
207
+    return $text;
208 208
 }
209 209
 ?>
210 210
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -22,12 +22,12 @@  discard block
 block discarded – undo
22 22
  * @param <type> $dirname
23 23
  * @return <type>
24 24
  */
25
-function find_langs_in_path ($file, $dirname='lang') {
26
-	static $dirs=array();
25
+function find_langs_in_path($file, $dirname = 'lang') {
26
+	static $dirs = array();
27 27
 	$liste = array();
28
-	foreach(creer_chemin() as $dir) {
29
-		if (!isset($dirs[$a = $dir . $dirname]))
30
-			$dirs[$a] = (is_dir($a) || !$a) ;
28
+	foreach (creer_chemin() as $dir) {
29
+		if (!isset($dirs[$a = $dir.$dirname]))
30
+			$dirs[$a] = (is_dir($a) || !$a);
31 31
 		if ($dirs[$a]) {
32 32
 			if (is_readable($a .= $file)) {
33 33
 				$liste[] = $a;
@@ -48,18 +48,18 @@  discard block
 block discarded – undo
48 48
 	if ($f = ($module == 'local'
49 49
 		? find_in_path($module.$lang.'.php', 'lang/')
50 50
 		: find_langs_in_path($module.$lang.'.php', 'lang/')))
51
-		return is_array($f)?$f:array($f);
51
+		return is_array($f) ? $f : array($f);
52 52
 
53 53
 	// 2) directement dans le chemin (old style, uniquement pour local)
54 54
 	return (($module == 'local') OR strpos($module, '/'))
55
-		? (($f = find_in_path($module.$lang. '.php')) ? array($f):false)
55
+		? (($f = find_in_path($module.$lang.'.php')) ? array($f) : false)
56 56
 		: false;
57 57
 }
58 58
 
59 59
 // http://doc.spip.org/@charger_langue
60 60
 function charger_langue($lang, $module = 'spip') {
61 61
 	if ($lang AND $fichiers_lang = chercher_module_lang($module, $lang)) {
62
-		$GLOBALS['idx_lang']='i18n_'.$module.'_'.$lang;
62
+		$GLOBALS['idx_lang'] = 'i18n_'.$module.'_'.$lang;
63 63
 		include(array_shift($fichiers_lang));
64 64
 		surcharger_langue($fichiers_lang);
65 65
 	} else {
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 			$fichiers_lang = chercher_module_lang($module, _LANGUE_PAR_DEFAUT);
73 73
 
74 74
 		if ($fichiers_lang) {
75
-			$GLOBALS['idx_lang']='i18n_'.$module.'_' .$l;
75
+			$GLOBALS['idx_lang'] = 'i18n_'.$module.'_'.$l;
76 76
 			include(array_shift($fichiers_lang));
77 77
 			surcharger_langue($fichiers_lang);
78 78
 			$GLOBALS['i18n_'.$module.'_'.$lang]
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 
93 93
 	if (!is_array($fichiers)) $fichiers = array($fichiers);
94 94
 	if (!count($fichiers)) return;
95
-	foreach($fichiers as $fichier){
95
+	foreach ($fichiers as $fichier) {
96 96
 		if (!isset($surcharges[$fichier])) {
97 97
 			$idx_lang_normal = $GLOBALS['idx_lang'];
98 98
 			$GLOBALS['idx_lang'] = $GLOBALS['idx_lang'].'@temporaire';
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 		}
104 104
 		if (is_array($surcharges[$fichier])) {
105 105
 			$GLOBALS[$GLOBALS['idx_lang']] = array_merge(
106
-				(array)$GLOBALS[$GLOBALS['idx_lang']],
106
+				(array) $GLOBALS[$GLOBALS['idx_lang']],
107 107
 				$surcharges[$fichier]
108 108
 			);
109 109
 		}
@@ -122,14 +122,14 @@  discard block
 block discarded – undo
122 122
 		return $deja_vu[$lang][$ori];
123 123
 
124 124
 	// modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES
125
-	if (strpos($ori,':')) {
126
-		list($modules,$code) = explode(':',$ori,2);
125
+	if (strpos($ori, ':')) {
126
+		list($modules, $code) = explode(':', $ori, 2);
127 127
 		$modules = explode('|', $modules);
128 128
 		$ori_complet = $ori;
129 129
 	} else {
130 130
 		$modules = array('spip', 'ecrire');
131 131
 		$code = $ori;
132
-		$ori_complet = implode('|', $modules) . ':' . $ori;
132
+		$ori_complet = implode('|', $modules).':'.$ori;
133 133
 	}
134 134
 
135 135
 	$text = '';
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 			// -- on cherche (lang/)local_xx.php ...
145 145
 			if (!isset($local['local_'.$lang])) {
146 146
 				// redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer)
147
-				$GLOBALS['idx_lang']= $var;
147
+				$GLOBALS['idx_lang'] = $var;
148 148
 				$local['local_'.$lang] = chercher_module_lang('local', $lang);
149 149
 			}
150 150
 			if ($local['local_'.$lang])
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	}
180 180
 
181 181
 	// Supprimer la mention <NEW> ou <MODIF>
182
-	if (substr($text,0,1) === '<')
182
+	if (substr($text, 0, 1) === '<')
183 183
 		$text = str_replace(array('<NEW>', '<MODIF>'), array(), $text);
184 184
 
185 185
 	// Si on n'est pas en utf-8, la chaine peut l'etre...
@@ -187,13 +187,13 @@  discard block
 block discarded – undo
187 187
 	if ($GLOBALS['meta']['charset'] !== 'utf-8'
188 188
 	AND preg_match(',[\x7f-\xff],S', $text)) {
189 189
 		include_spip('inc/charsets');
190
-		$text = charset2unicode($text,'utf-8');
190
+		$text = charset2unicode($text, 'utf-8');
191 191
 	}
192 192
 
193 193
 	if (_request('var_mode') == 'traduction') {
194
-		if ($text)  {
195
-			$classe = 'debug-traduction' . ($module_retenu == 'ecrire' ? '-prive' : '');
196
-			$text = '<span lang=' . $langue_retenue . ' class=' . $classe . ' title=' . $ori_complet . '(' . $langue_retenue . ')>' . $text . '</span>';
194
+		if ($text) {
195
+			$classe = 'debug-traduction'.($module_retenu == 'ecrire' ? '-prive' : '');
196
+			$text = '<span lang='.$langue_retenue.' class='.$classe.' title='.$ori_complet.'('.$langue_retenue.')>'.$text.'</span>';
197 197
 			$text = str_replace(
198 198
 						array("$module_retenu:", "$module_retenu|"),
199 199
 						array("*$module_retenu*:", "*$module_retenu*|"),
Please login to merge, or discard this patch.
Braces   +41 added lines, -26 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 /**
16 18
  * Rechercher tous les lang/file dans le path
@@ -26,8 +28,9 @@  discard block
 block discarded – undo
26 28
 	static $dirs=array();
27 29
 	$liste = array();
28 30
 	foreach(creer_chemin() as $dir) {
29
-		if (!isset($dirs[$a = $dir . $dirname]))
30
-			$dirs[$a] = (is_dir($a) || !$a) ;
31
+		if (!isset($dirs[$a = $dir . $dirname])) {
32
+					$dirs[$a] = (is_dir($a) || !$a) ;
33
+		}
31 34
 		if ($dirs[$a]) {
32 35
 			if (is_readable($a .= $file)) {
33 36
 				$liste[] = $a;
@@ -41,14 +44,16 @@  discard block
 block discarded – undo
41 44
 //
42 45
 // http://doc.spip.org/@chercher_module_lang
43 46
 function chercher_module_lang($module, $lang = '') {
44
-	if ($lang)
45
-		$lang = '_'.$lang;
47
+	if ($lang) {
48
+			$lang = '_'.$lang;
49
+	}
46 50
 
47 51
 	// 1) dans un repertoire nomme lang/ se trouvant sur le chemin
48 52
 	if ($f = ($module == 'local'
49 53
 		? find_in_path($module.$lang.'.php', 'lang/')
50
-		: find_langs_in_path($module.$lang.'.php', 'lang/')))
51
-		return is_array($f)?$f:array($f);
54
+		: find_langs_in_path($module.$lang.'.php', 'lang/'))) {
55
+			return is_array($f)?$f:array($f);
56
+	}
52 57
 
53 58
 	// 2) directement dans le chemin (old style, uniquement pour local)
54 59
 	return (($module == 'local') OR strpos($module, '/'))
@@ -68,8 +73,9 @@  discard block
 block discarded – undo
68 73
 		// *par definition* doit exister, et on copie le tableau dans la
69 74
 		// var liee a la langue
70 75
 		$l = $GLOBALS['meta']['langue_site'];
71
-		if (!$fichiers_lang = chercher_module_lang($module, $l))
72
-			$fichiers_lang = chercher_module_lang($module, _LANGUE_PAR_DEFAUT);
76
+		if (!$fichiers_lang = chercher_module_lang($module, $l)) {
77
+					$fichiers_lang = chercher_module_lang($module, _LANGUE_PAR_DEFAUT);
78
+		}
73 79
 
74 80
 		if ($fichiers_lang) {
75 81
 			$GLOBALS['idx_lang']='i18n_'.$module.'_' .$l;
@@ -88,10 +94,16 @@  discard block
 block discarded – undo
88 94
 // http://doc.spip.org/@surcharger_langue
89 95
 function surcharger_langue($fichiers) {
90 96
 	static $surcharges = array();
91
-	if (!isset($GLOBALS['idx_lang'])) return;
97
+	if (!isset($GLOBALS['idx_lang'])) {
98
+	    return;
99
+	}
92 100
 
93
-	if (!is_array($fichiers)) $fichiers = array($fichiers);
94
-	if (!count($fichiers)) return;
101
+	if (!is_array($fichiers)) {
102
+	    $fichiers = array($fichiers);
103
+	}
104
+	if (!count($fichiers)) {
105
+	    return;
106
+	}
95 107
 	foreach($fichiers as $fichier){
96 108
 		if (!isset($surcharges[$fichier])) {
97 109
 			$idx_lang_normal = $GLOBALS['idx_lang'];
@@ -118,8 +130,9 @@  discard block
 block discarded – undo
118 130
 	static $deja_vu = array();
119 131
 	static $local = array();
120 132
   
121
-	if (isset($deja_vu[$lang][$ori]) AND (_request('var_mode') != 'traduction'))
122
-		return $deja_vu[$lang][$ori];
133
+	if (isset($deja_vu[$lang][$ori]) AND (_request('var_mode') != 'traduction')) {
134
+			return $deja_vu[$lang][$ori];
135
+	}
123 136
 
124 137
 	// modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES
125 138
 	if (strpos($ori,':')) {
@@ -147,13 +160,16 @@  discard block
 block discarded – undo
147 160
 				$GLOBALS['idx_lang']= $var;
148 161
 				$local['local_'.$lang] = chercher_module_lang('local', $lang);
149 162
 			}
150
-			if ($local['local_'.$lang])
151
-				surcharger_langue($local['local_'.$lang]);
163
+			if ($local['local_'.$lang]) {
164
+							surcharger_langue($local['local_'.$lang]);
165
+			}
152 166
 			// ... puis (lang/)local.php
153
-			if (!isset($local['local']))
154
-				$local['local'] = chercher_module_lang('local');
155
-			if ($local['local'])
156
-				surcharger_langue($local['local']);
167
+			if (!isset($local['local'])) {
168
+							$local['local'] = chercher_module_lang('local');
169
+			}
170
+			if ($local['local']) {
171
+							surcharger_langue($local['local']);
172
+			}
157 173
 		}
158 174
 
159 175
 		if (isset($GLOBALS[$var][$code])) {
@@ -171,16 +187,16 @@  discard block
 block discarded – undo
171 187
 		if ($lang !== $GLOBALS['meta']['langue_site']) {
172 188
 			$text = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site']);
173 189
 			$langue_retenue = (!strlen($text) ? $GLOBALS['meta']['langue_site'] : '');
174
-		}
175
-		else {
190
+		} else {
176 191
 			$text = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT);
177 192
 			$langue_retenue = (!strlen($text) ? _LANGUE_PAR_DEFAUT : '');
178 193
 		}
179 194
 	}
180 195
 
181 196
 	// Supprimer la mention <NEW> ou <MODIF>
182
-	if (substr($text,0,1) === '<')
183
-		$text = str_replace(array('<NEW>', '<MODIF>'), array(), $text);
197
+	if (substr($text,0,1) === '<') {
198
+			$text = str_replace(array('<NEW>', '<MODIF>'), array(), $text);
199
+	}
184 200
 
185 201
 	// Si on n'est pas en utf-8, la chaine peut l'etre...
186 202
 	// le cas echeant on la convertit en entites html &#xxx;
@@ -199,8 +215,7 @@  discard block
 block discarded – undo
199 215
 						array("*$module_retenu*:", "*$module_retenu*|"),
200 216
 						$text);
201 217
 		}
202
-	}
203
-	else {
218
+	} else {
204 219
 		$deja_vu[$lang][$ori] = $text;
205 220
 	}
206 221
 
Please login to merge, or discard this patch.
ecrire/inc/urls.php 4 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -187,8 +187,9 @@
 block discarded – undo
187 187
  * @param int $id
188 188
  * @param string $args
189 189
  * @param string $ancre
190
- * @param string $statut
191 190
  * @param string $connect
191
+ * @param string $objet
192
+ * @param boolean $public
192 193
  * @return string
193 194
  *
194 195
  */
Please login to merge, or discard this patch.
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -43,84 +43,84 @@  discard block
 block discarded – undo
43 43
  *
44 44
  */
45 45
 function urls_decoder_url($url, $fond='', $contexte=array(), $assembler=false){
46
-	static $current_base = null;
47
-	// les anciennes fonctions modifient directement les globales
48
-	// on les sauve avant l'appel, et on les retablit apres !
49
-	$save = array(@$GLOBALS['fond'],@$GLOBALS['contexte'],@$_SERVER['REDIRECT_url_propre'],@$_ENV['url_propre'],$GLOBALS['profondeur_url']);
50
-	if (is_null($current_base)){
51
-		include_spip('inc/filtres_mini');
52
-		// le decodage des urls se fait toujours par rapport au site public
53
-		$current_base = url_absolue(_DIR_RACINE?_DIR_RACINE:'./');
54
-	}
55
-	if (strncmp($url,$current_base,strlen($current_base))==0)
56
-		$url = substr($url,strlen($current_base));
46
+    static $current_base = null;
47
+    // les anciennes fonctions modifient directement les globales
48
+    // on les sauve avant l'appel, et on les retablit apres !
49
+    $save = array(@$GLOBALS['fond'],@$GLOBALS['contexte'],@$_SERVER['REDIRECT_url_propre'],@$_ENV['url_propre'],$GLOBALS['profondeur_url']);
50
+    if (is_null($current_base)){
51
+        include_spip('inc/filtres_mini');
52
+        // le decodage des urls se fait toujours par rapport au site public
53
+        $current_base = url_absolue(_DIR_RACINE?_DIR_RACINE:'./');
54
+    }
55
+    if (strncmp($url,$current_base,strlen($current_base))==0)
56
+        $url = substr($url,strlen($current_base));
57 57
 
58
-	// si on est pas en train d'assembler la page principale,
59
-	// vider les globales url propres qui ne doivent pas etre utilisees en cas
60
-	// d'inversion url => objet
61
-	if (!$assembler) {
62
-		unset($_SERVER['REDIRECT_url_propre']);
63
-		unset($_ENV['url_propre']);
64
-		include_spip('inc/filtres_mini');
65
-		if (strpos($url,"://")===false){
58
+    // si on est pas en train d'assembler la page principale,
59
+    // vider les globales url propres qui ne doivent pas etre utilisees en cas
60
+    // d'inversion url => objet
61
+    if (!$assembler) {
62
+        unset($_SERVER['REDIRECT_url_propre']);
63
+        unset($_ENV['url_propre']);
64
+        include_spip('inc/filtres_mini');
65
+        if (strpos($url,"://")===false){
66 66
             $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"),'/'),'/');
67 67
     }
68 68
     else {
69 69
             $GLOBALS['profondeur_url'] = max(0,substr_count($url,"/")-substr_count($current_base,"/"));
70 70
     }
71
-	}
71
+    }
72 72
 
73 73
 	
74
-	$url_redirect = "";
75
-	$renommer = generer_url_entite('','','','',true);
76
-	if (!$renommer AND !function_exists('recuperer_parametres_url'))
77
-		$renommer = charger_fonction('page','urls'); // fallback pour decoder l'url
78
-	if ($renommer) {
79
-		$a = $renommer($url, $fond, $contexte);
80
-		if (is_array($a)) {
81
-			list($ncontexte, $type, $url_redirect, $nfond) = array_pad($a, 4, null);
82
-			if ($url_redirect == $url)
83
-				$url_redirect = ""; // securite pour eviter une redirection infinie
84
-			if ($assembler AND strlen($url_redirect)) {
85
-				spip_log("Redirige $url vers $url_redirect");
86
-				include_spip('inc/headers');
87
-				redirige_par_entete($url_redirect, '', 301);
88
-			}
89
-			if (isset($nfond))
90
-				$fond = $nfond;
91
-			else if ($fond == ''
92
-			OR $fond == 'type_urls' /* compat avec htaccess 2.0.0 */
93
-			)
94
-				$fond = $type;
95
-			if (isset($ncontexte))
96
-				$contexte = $ncontexte;
97
-			if (defined('_DEFINIR_CONTEXTE_TYPE') AND _DEFINIR_CONTEXTE_TYPE)
98
-				$contexte['type'] = $type;
99
-			if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') AND _DEFINIR_CONTEXTE_TYPE_PAGE)
100
-				$contexte['type-page'] = $type;
101
-		}
102
-	}
103
-	// compatibilite <= 1.9.2
104
-	elseif (function_exists('recuperer_parametres_url')) {
105
-		$GLOBALS['fond'] = $fond;
106
-		$GLOBALS['contexte'] = $contexte;
107
-		recuperer_parametres_url($fond, nettoyer_uri());
108
-		// fond est en principe modifiee directement
109
-		$contexte = $GLOBALS['contexte'];
110
-	}
74
+    $url_redirect = "";
75
+    $renommer = generer_url_entite('','','','',true);
76
+    if (!$renommer AND !function_exists('recuperer_parametres_url'))
77
+        $renommer = charger_fonction('page','urls'); // fallback pour decoder l'url
78
+    if ($renommer) {
79
+        $a = $renommer($url, $fond, $contexte);
80
+        if (is_array($a)) {
81
+            list($ncontexte, $type, $url_redirect, $nfond) = array_pad($a, 4, null);
82
+            if ($url_redirect == $url)
83
+                $url_redirect = ""; // securite pour eviter une redirection infinie
84
+            if ($assembler AND strlen($url_redirect)) {
85
+                spip_log("Redirige $url vers $url_redirect");
86
+                include_spip('inc/headers');
87
+                redirige_par_entete($url_redirect, '', 301);
88
+            }
89
+            if (isset($nfond))
90
+                $fond = $nfond;
91
+            else if ($fond == ''
92
+            OR $fond == 'type_urls' /* compat avec htaccess 2.0.0 */
93
+            )
94
+                $fond = $type;
95
+            if (isset($ncontexte))
96
+                $contexte = $ncontexte;
97
+            if (defined('_DEFINIR_CONTEXTE_TYPE') AND _DEFINIR_CONTEXTE_TYPE)
98
+                $contexte['type'] = $type;
99
+            if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') AND _DEFINIR_CONTEXTE_TYPE_PAGE)
100
+                $contexte['type-page'] = $type;
101
+        }
102
+    }
103
+    // compatibilite <= 1.9.2
104
+    elseif (function_exists('recuperer_parametres_url')) {
105
+        $GLOBALS['fond'] = $fond;
106
+        $GLOBALS['contexte'] = $contexte;
107
+        recuperer_parametres_url($fond, nettoyer_uri());
108
+        // fond est en principe modifiee directement
109
+        $contexte = $GLOBALS['contexte'];
110
+    }
111 111
 
112
-	// retablir les globales
113
-	list($GLOBALS['fond'],$GLOBALS['contexte'],$_SERVER['REDIRECT_url_propre'],$_ENV['url_propre'],$GLOBALS['profondeur_url']) = $save;
112
+    // retablir les globales
113
+    list($GLOBALS['fond'],$GLOBALS['contexte'],$_SERVER['REDIRECT_url_propre'],$_ENV['url_propre'],$GLOBALS['profondeur_url']) = $save;
114 114
 	
115
-	// vider les globales url propres qui ne doivent plus etre utilisees en cas
116
-	// d'inversion url => objet
117
-	// maintenir pour compat ?
118
-	#if ($assembler) {
119
-	#	unset($_SERVER['REDIRECT_url_propre']);
120
-	#	unset($_ENV['url_propre']);
121
-	#}
115
+    // vider les globales url propres qui ne doivent plus etre utilisees en cas
116
+    // d'inversion url => objet
117
+    // maintenir pour compat ?
118
+    #if ($assembler) {
119
+    #	unset($_SERVER['REDIRECT_url_propre']);
120
+    #	unset($_ENV['url_propre']);
121
+    #}
122 122
 
123
-	return array($fond,$contexte,$url_redirect);
123
+    return array($fond,$contexte,$url_redirect);
124 124
 }
125 125
 
126 126
 
@@ -134,21 +134,21 @@  discard block
 block discarded – undo
134 134
  * @return string/array
135 135
  */
136 136
 function urls_liste_objets($preg = true){
137
-	static $url_objets = null;
138
-	if (is_null($url_objets)){
139
-		$url_objets = array();
140
-		// recuperer les tables_objets_sql declarees
141
-		$tables_objets = lister_tables_objets_sql();
142
-		foreach($tables_objets as $t=>$infos){
143
-			if ($infos['page']) {
144
-				$url_objets[] = $infos['type'];
145
-				$url_objets = array_merge($url_objets,$infos['type_surnoms']);
146
-			}
147
-		}
148
-		$url_objets = pipeline('declarer_url_objets',$url_objets);
149
-	}
150
-	if (!$preg) return $url_objets;
151
-	return implode('|',array_map('preg_quote',$url_objets));
137
+    static $url_objets = null;
138
+    if (is_null($url_objets)){
139
+        $url_objets = array();
140
+        // recuperer les tables_objets_sql declarees
141
+        $tables_objets = lister_tables_objets_sql();
142
+        foreach($tables_objets as $t=>$infos){
143
+            if ($infos['page']) {
144
+                $url_objets[] = $infos['type'];
145
+                $url_objets = array_merge($url_objets,$infos['type_surnoms']);
146
+            }
147
+        }
148
+        $url_objets = pipeline('declarer_url_objets',$url_objets);
149
+    }
150
+    if (!$preg) return $url_objets;
151
+    return implode('|',array_map('preg_quote',$url_objets));
152 152
 }
153 153
 
154 154
 /**
@@ -162,21 +162,21 @@  discard block
 block discarded – undo
162 162
  */
163 163
 function nettoyer_url_page($url, $contexte=array())
164 164
 {
165
-	$url_objets = urls_liste_objets();
166
-	$raccourci_url_page_html = ',^(?:[^?]*/)?('. $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,';
167
-	$raccourci_url_page_id = ',^(?:[^?]*/)?('. $url_objets .')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
168
-	$raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?]('. $url_objets .')([0-9]+)=?(&.*)?$,';
165
+    $url_objets = urls_liste_objets();
166
+    $raccourci_url_page_html = ',^(?:[^?]*/)?('. $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,';
167
+    $raccourci_url_page_id = ',^(?:[^?]*/)?('. $url_objets .')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
168
+    $raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?]('. $url_objets .')([0-9]+)=?(&.*)?$,';
169 169
 
170
-	if (preg_match($raccourci_url_page_html, $url, $regs)
171
-	OR preg_match($raccourci_url_page_id, $url, $regs)
172
-	OR preg_match($raccourci_url_page_spip, $url, $regs)) {
173
-		$type = objet_type($regs[1]);
174
-		$_id = id_table_objet($type);
175
-		$contexte[$_id] = $regs[2];
176
-		$suite = $regs[3];
177
-		return array($contexte, $type, null, $type, $suite);
178
-	}
179
-	return array();
170
+    if (preg_match($raccourci_url_page_html, $url, $regs)
171
+    OR preg_match($raccourci_url_page_id, $url, $regs)
172
+    OR preg_match($raccourci_url_page_spip, $url, $regs)) {
173
+        $type = objet_type($regs[1]);
174
+        $_id = id_table_objet($type);
175
+        $contexte[$_id] = $regs[2];
176
+        $suite = $regs[3];
177
+        return array($contexte, $type, null, $type, $suite);
178
+    }
179
+    return array();
180 180
 }
181 181
 
182 182
 /**
@@ -193,28 +193,28 @@  discard block
 block discarded – undo
193 193
  *
194 194
  */
195 195
 function generer_url_ecrire_objet($objet,$id, $args='', $ancre='', $public=null, $connect=''){
196
-	static $furls = array();
197
-	if (!isset($furls[$objet])){
198
-		if (function_exists($f = 'generer_url_ecrire_' . $objet)
199
-			// ou definie par un plugin
200
-			OR $f = charger_fonction($f,'urls',true))
201
-			$furls[$objet] = $f;
202
-		else
203
-			$furls[$objet] = '';
204
-	}
205
-	if ($furls[$objet])
206
-		return $furls[$objet]($id, $args, $ancre, $public, $connect);
207
-	// si pas de flag public fourni
208
-	// le calculer en fonction de la declaration de statut
209
-	if (is_null($public) AND !$connect)
210
-		$public = objet_test_si_publie($objet, $id, $connect);
211
-	if ($public OR $connect){
212
-		return generer_url_entite_absolue($id, $objet, $args, $ancre, $connect);
213
-	}
214
-	$a = id_table_objet($objet) . "=" . intval($id);
215
-	if (!function_exists('objet_info'))
216
-		include_spip('inc/filtres');
217
-	return generer_url_ecrire(objet_info($objet,'url_voir'), $a . ($args ? "&$args" : '')). ($ancre ? "#$ancre" : '');
196
+    static $furls = array();
197
+    if (!isset($furls[$objet])){
198
+        if (function_exists($f = 'generer_url_ecrire_' . $objet)
199
+            // ou definie par un plugin
200
+            OR $f = charger_fonction($f,'urls',true))
201
+            $furls[$objet] = $f;
202
+        else
203
+            $furls[$objet] = '';
204
+    }
205
+    if ($furls[$objet])
206
+        return $furls[$objet]($id, $args, $ancre, $public, $connect);
207
+    // si pas de flag public fourni
208
+    // le calculer en fonction de la declaration de statut
209
+    if (is_null($public) AND !$connect)
210
+        $public = objet_test_si_publie($objet, $id, $connect);
211
+    if ($public OR $connect){
212
+        return generer_url_entite_absolue($id, $objet, $args, $ancre, $connect);
213
+    }
214
+    $a = id_table_objet($objet) . "=" . intval($id);
215
+    if (!function_exists('objet_info'))
216
+        include_spip('inc/filtres');
217
+    return generer_url_ecrire(objet_info($objet,'url_voir'), $a . ($args ? "&$args" : '')). ($ancre ? "#$ancre" : '');
218 218
 }
219 219
 
220 220
 ?>
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -42,18 +42,18 @@  discard block
 block discarded – undo
42 42
  *  est non vide pour verifier une url
43 43
  *
44 44
  */
45
-function urls_decoder_url($url, $fond='', $contexte=array(), $assembler=false){
45
+function urls_decoder_url($url, $fond = '', $contexte = array(), $assembler = false) {
46 46
 	static $current_base = null;
47 47
 	// les anciennes fonctions modifient directement les globales
48 48
 	// on les sauve avant l'appel, et on les retablit apres !
49
-	$save = array(@$GLOBALS['fond'],@$GLOBALS['contexte'],@$_SERVER['REDIRECT_url_propre'],@$_ENV['url_propre'],$GLOBALS['profondeur_url']);
50
-	if (is_null($current_base)){
49
+	$save = array(@$GLOBALS['fond'], @$GLOBALS['contexte'], @$_SERVER['REDIRECT_url_propre'], @$_ENV['url_propre'], $GLOBALS['profondeur_url']);
50
+	if (is_null($current_base)) {
51 51
 		include_spip('inc/filtres_mini');
52 52
 		// le decodage des urls se fait toujours par rapport au site public
53
-		$current_base = url_absolue(_DIR_RACINE?_DIR_RACINE:'./');
53
+		$current_base = url_absolue(_DIR_RACINE ? _DIR_RACINE : './');
54 54
 	}
55
-	if (strncmp($url,$current_base,strlen($current_base))==0)
56
-		$url = substr($url,strlen($current_base));
55
+	if (strncmp($url, $current_base, strlen($current_base)) == 0)
56
+		$url = substr($url, strlen($current_base));
57 57
 
58 58
 	// si on est pas en train d'assembler la page principale,
59 59
 	// vider les globales url propres qui ne doivent pas etre utilisees en cas
@@ -62,19 +62,19 @@  discard block
 block discarded – undo
62 62
 		unset($_SERVER['REDIRECT_url_propre']);
63 63
 		unset($_ENV['url_propre']);
64 64
 		include_spip('inc/filtres_mini');
65
-		if (strpos($url,"://")===false){
66
-            $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"),'/'),'/');
65
+		if (strpos($url, "://") === false) {
66
+            $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"), '/'), '/');
67 67
     }
68 68
     else {
69
-            $GLOBALS['profondeur_url'] = max(0,substr_count($url,"/")-substr_count($current_base,"/"));
69
+            $GLOBALS['profondeur_url'] = max(0, substr_count($url, "/") - substr_count($current_base, "/"));
70 70
     }
71 71
 	}
72 72
 
73 73
 	
74 74
 	$url_redirect = "";
75
-	$renommer = generer_url_entite('','','','',true);
75
+	$renommer = generer_url_entite('', '', '', '', true);
76 76
 	if (!$renommer AND !function_exists('recuperer_parametres_url'))
77
-		$renommer = charger_fonction('page','urls'); // fallback pour decoder l'url
77
+		$renommer = charger_fonction('page', 'urls'); // fallback pour decoder l'url
78 78
 	if ($renommer) {
79 79
 		$a = $renommer($url, $fond, $contexte);
80 80
 		if (is_array($a)) {
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	}
111 111
 
112 112
 	// retablir les globales
113
-	list($GLOBALS['fond'],$GLOBALS['contexte'],$_SERVER['REDIRECT_url_propre'],$_ENV['url_propre'],$GLOBALS['profondeur_url']) = $save;
113
+	list($GLOBALS['fond'], $GLOBALS['contexte'], $_SERVER['REDIRECT_url_propre'], $_ENV['url_propre'], $GLOBALS['profondeur_url']) = $save;
114 114
 	
115 115
 	// vider les globales url propres qui ne doivent plus etre utilisees en cas
116 116
 	// d'inversion url => objet
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 	#	unset($_ENV['url_propre']);
121 121
 	#}
122 122
 
123
-	return array($fond,$contexte,$url_redirect);
123
+	return array($fond, $contexte, $url_redirect);
124 124
 }
125 125
 
126 126
 
@@ -133,22 +133,22 @@  discard block
 block discarded – undo
133 133
  *  pour utiliser en preg, ou un array()
134 134
  * @return string/array
135 135
  */
136
-function urls_liste_objets($preg = true){
136
+function urls_liste_objets($preg = true) {
137 137
 	static $url_objets = null;
138
-	if (is_null($url_objets)){
138
+	if (is_null($url_objets)) {
139 139
 		$url_objets = array();
140 140
 		// recuperer les tables_objets_sql declarees
141 141
 		$tables_objets = lister_tables_objets_sql();
142
-		foreach($tables_objets as $t=>$infos){
142
+		foreach ($tables_objets as $t=>$infos) {
143 143
 			if ($infos['page']) {
144 144
 				$url_objets[] = $infos['type'];
145
-				$url_objets = array_merge($url_objets,$infos['type_surnoms']);
145
+				$url_objets = array_merge($url_objets, $infos['type_surnoms']);
146 146
 			}
147 147
 		}
148
-		$url_objets = pipeline('declarer_url_objets',$url_objets);
148
+		$url_objets = pipeline('declarer_url_objets', $url_objets);
149 149
 	}
150 150
 	if (!$preg) return $url_objets;
151
-	return implode('|',array_map('preg_quote',$url_objets));
151
+	return implode('|', array_map('preg_quote', $url_objets));
152 152
 }
153 153
 
154 154
 /**
@@ -160,12 +160,12 @@  discard block
 block discarded – undo
160 160
  * @param array $contexte
161 161
  * @return array
162 162
  */
163
-function nettoyer_url_page($url, $contexte=array())
163
+function nettoyer_url_page($url, $contexte = array())
164 164
 {
165 165
 	$url_objets = urls_liste_objets();
166
-	$raccourci_url_page_html = ',^(?:[^?]*/)?('. $url_objets . ')([0-9]+)(?:\.html)?([?&].*)?$,';
167
-	$raccourci_url_page_id = ',^(?:[^?]*/)?('. $url_objets .')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
168
-	$raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?]('. $url_objets .')([0-9]+)=?(&.*)?$,';
166
+	$raccourci_url_page_html = ',^(?:[^?]*/)?('.$url_objets.')([0-9]+)(?:\.html)?([?&].*)?$,';
167
+	$raccourci_url_page_id = ',^(?:[^?]*/)?('.$url_objets.')\.php3?[?]id_\1=([0-9]+)([?&].*)?$,';
168
+	$raccourci_url_page_spip = ',^(?:[^?]*/)?(?:spip[.]php)?[?]('.$url_objets.')([0-9]+)=?(&.*)?$,';
169 169
 
170 170
 	if (preg_match($raccourci_url_page_html, $url, $regs)
171 171
 	OR preg_match($raccourci_url_page_id, $url, $regs)
@@ -192,12 +192,12 @@  discard block
 block discarded – undo
192 192
  * @return string
193 193
  *
194 194
  */
195
-function generer_url_ecrire_objet($objet,$id, $args='', $ancre='', $public=null, $connect=''){
195
+function generer_url_ecrire_objet($objet, $id, $args = '', $ancre = '', $public = null, $connect = '') {
196 196
 	static $furls = array();
197
-	if (!isset($furls[$objet])){
198
-		if (function_exists($f = 'generer_url_ecrire_' . $objet)
197
+	if (!isset($furls[$objet])) {
198
+		if (function_exists($f = 'generer_url_ecrire_'.$objet)
199 199
 			// ou definie par un plugin
200
-			OR $f = charger_fonction($f,'urls',true))
200
+			OR $f = charger_fonction($f, 'urls', true))
201 201
 			$furls[$objet] = $f;
202 202
 		else
203 203
 			$furls[$objet] = '';
@@ -208,13 +208,13 @@  discard block
 block discarded – undo
208 208
 	// le calculer en fonction de la declaration de statut
209 209
 	if (is_null($public) AND !$connect)
210 210
 		$public = objet_test_si_publie($objet, $id, $connect);
211
-	if ($public OR $connect){
211
+	if ($public OR $connect) {
212 212
 		return generer_url_entite_absolue($id, $objet, $args, $ancre, $connect);
213 213
 	}
214
-	$a = id_table_objet($objet) . "=" . intval($id);
214
+	$a = id_table_objet($objet)."=".intval($id);
215 215
 	if (!function_exists('objet_info'))
216 216
 		include_spip('inc/filtres');
217
-	return generer_url_ecrire(objet_info($objet,'url_voir'), $a . ($args ? "&$args" : '')). ($ancre ? "#$ancre" : '');
217
+	return generer_url_ecrire(objet_info($objet, 'url_voir'), $a.($args ? "&$args" : '')).($ancre ? "#$ancre" : '');
218 218
 }
219 219
 
220 220
 ?>
Please login to merge, or discard this patch.
Braces   +47 added lines, -31 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 include_spip('base/objets');
15 17
 
16 18
 /**
@@ -52,8 +54,9 @@  discard block
 block discarded – undo
52 54
 		// le decodage des urls se fait toujours par rapport au site public
53 55
 		$current_base = url_absolue(_DIR_RACINE?_DIR_RACINE:'./');
54 56
 	}
55
-	if (strncmp($url,$current_base,strlen($current_base))==0)
56
-		$url = substr($url,strlen($current_base));
57
+	if (strncmp($url,$current_base,strlen($current_base))==0) {
58
+			$url = substr($url,strlen($current_base));
59
+	}
57 60
 
58 61
 	// si on est pas en train d'assembler la page principale,
59 62
 	// vider les globales url propres qui ne doivent pas etre utilisees en cas
@@ -64,8 +67,7 @@  discard block
 block discarded – undo
64 67
 		include_spip('inc/filtres_mini');
65 68
 		if (strpos($url,"://")===false){
66 69
             $GLOBALS['profondeur_url'] = substr_count(ltrim(resolve_path("/$url"),'/'),'/');
67
-    }
68
-    else {
70
+    } else {
69 71
             $GLOBALS['profondeur_url'] = max(0,substr_count($url,"/")-substr_count($current_base,"/"));
70 72
     }
71 73
 	}
@@ -73,31 +75,39 @@  discard block
 block discarded – undo
73 75
 	
74 76
 	$url_redirect = "";
75 77
 	$renommer = generer_url_entite('','','','',true);
76
-	if (!$renommer AND !function_exists('recuperer_parametres_url'))
77
-		$renommer = charger_fonction('page','urls'); // fallback pour decoder l'url
78
+	if (!$renommer AND !function_exists('recuperer_parametres_url')) {
79
+			$renommer = charger_fonction('page','urls');
80
+	}
81
+	// fallback pour decoder l'url
78 82
 	if ($renommer) {
79 83
 		$a = $renommer($url, $fond, $contexte);
80 84
 		if (is_array($a)) {
81 85
 			list($ncontexte, $type, $url_redirect, $nfond) = array_pad($a, 4, null);
82
-			if ($url_redirect == $url)
83
-				$url_redirect = ""; // securite pour eviter une redirection infinie
86
+			if ($url_redirect == $url) {
87
+							$url_redirect = "";
88
+			}
89
+			// securite pour eviter une redirection infinie
84 90
 			if ($assembler AND strlen($url_redirect)) {
85 91
 				spip_log("Redirige $url vers $url_redirect");
86 92
 				include_spip('inc/headers');
87 93
 				redirige_par_entete($url_redirect, '', 301);
88 94
 			}
89
-			if (isset($nfond))
90
-				$fond = $nfond;
91
-			else if ($fond == ''
95
+			if (isset($nfond)) {
96
+							$fond = $nfond;
97
+			} else if ($fond == ''
92 98
 			OR $fond == 'type_urls' /* compat avec htaccess 2.0.0 */
93
-			)
94
-				$fond = $type;
95
-			if (isset($ncontexte))
96
-				$contexte = $ncontexte;
97
-			if (defined('_DEFINIR_CONTEXTE_TYPE') AND _DEFINIR_CONTEXTE_TYPE)
98
-				$contexte['type'] = $type;
99
-			if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') AND _DEFINIR_CONTEXTE_TYPE_PAGE)
100
-				$contexte['type-page'] = $type;
99
+			) {
100
+							$fond = $type;
101
+			}
102
+			if (isset($ncontexte)) {
103
+							$contexte = $ncontexte;
104
+			}
105
+			if (defined('_DEFINIR_CONTEXTE_TYPE') AND _DEFINIR_CONTEXTE_TYPE) {
106
+							$contexte['type'] = $type;
107
+			}
108
+			if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') AND _DEFINIR_CONTEXTE_TYPE_PAGE) {
109
+							$contexte['type-page'] = $type;
110
+			}
101 111
 		}
102 112
 	}
103 113
 	// compatibilite <= 1.9.2
@@ -147,7 +157,9 @@  discard block
 block discarded – undo
147 157
 		}
148 158
 		$url_objets = pipeline('declarer_url_objets',$url_objets);
149 159
 	}
150
-	if (!$preg) return $url_objets;
160
+	if (!$preg) {
161
+	    return $url_objets;
162
+	}
151 163
 	return implode('|',array_map('preg_quote',$url_objets));
152 164
 }
153 165
 
@@ -197,23 +209,27 @@  discard block
 block discarded – undo
197 209
 	if (!isset($furls[$objet])){
198 210
 		if (function_exists($f = 'generer_url_ecrire_' . $objet)
199 211
 			// ou definie par un plugin
200
-			OR $f = charger_fonction($f,'urls',true))
201
-			$furls[$objet] = $f;
202
-		else
203
-			$furls[$objet] = '';
212
+			OR $f = charger_fonction($f,'urls',true)) {
213
+					$furls[$objet] = $f;
214
+		} else {
215
+					$furls[$objet] = '';
216
+		}
217
+	}
218
+	if ($furls[$objet]) {
219
+			return $furls[$objet]($id, $args, $ancre, $public, $connect);
204 220
 	}
205
-	if ($furls[$objet])
206
-		return $furls[$objet]($id, $args, $ancre, $public, $connect);
207 221
 	// si pas de flag public fourni
208 222
 	// le calculer en fonction de la declaration de statut
209
-	if (is_null($public) AND !$connect)
210
-		$public = objet_test_si_publie($objet, $id, $connect);
223
+	if (is_null($public) AND !$connect) {
224
+			$public = objet_test_si_publie($objet, $id, $connect);
225
+	}
211 226
 	if ($public OR $connect){
212 227
 		return generer_url_entite_absolue($id, $objet, $args, $ancre, $connect);
213 228
 	}
214 229
 	$a = id_table_objet($objet) . "=" . intval($id);
215
-	if (!function_exists('objet_info'))
216
-		include_spip('inc/filtres');
230
+	if (!function_exists('objet_info')) {
231
+			include_spip('inc/filtres');
232
+	}
217 233
 	return generer_url_ecrire(objet_info($objet,'url_voir'), $a . ($args ? "&$args" : '')). ($ancre ? "#$ancre" : '');
218 234
 }
219 235
 
Please login to merge, or discard this patch.
ecrire/inc/utils.php 4 patches
Doc Comments   +31 added lines, -6 removed lines patch added patch discarded remove patch
@@ -88,6 +88,9 @@  discard block
 block discarded – undo
88 88
 // la fonction cherchant un fichier PHP dans le SPIP_PATH
89 89
 //
90 90
 // http://doc.spip.org/@include_spip
91
+/**
92
+ * @param string $f
93
+ */
91 94
 function include_spip($f, $include = true) {
92 95
 	return find_in_path($f . '.php', '', $include);
93 96
 }
@@ -180,8 +183,6 @@  discard block
 block discarded – undo
180 183
  *
181 184
  * @param string $message
182 185
  * @param string|int $name
183
- * @param string $logdir  ## inutile !! a supprimer ?
184
- * @param string $logsuf  ## inutile !! a supprimer ?
185 186
  */
186 187
 function spip_log($message=NULL, $name=NULL) {
187 188
 	static $pre = array();
@@ -366,6 +367,10 @@  discard block
 block discarded – undo
366 367
 // pour l'ancre on translitere, vire les non alphanum du debut,
367 368
 // et on remplace ceux a l'interieur ou au bout par -
368 369
 // http://doc.spip.org/@ancre_url
370
+/**
371
+ * @param null|string $url
372
+ * @param string $ancre
373
+ */
369 374
 function ancre_url($url, $ancre) {
370 375
 	// lever l'#ancre
371 376
 	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
@@ -596,6 +601,9 @@  discard block
 block discarded – undo
596 601
 // Renvoie False si un fichier n'est pas plus vieux que $duree secondes,
597 602
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
598 603
 // http://doc.spip.org/@spip_touch
604
+/**
605
+ * @param string $fichier
606
+ */
599 607
 function spip_touch($fichier, $duree=0, $touch=true) {
600 608
 	if ($duree) {
601 609
 		clearstatcache();
@@ -660,9 +668,9 @@  discard block
 block discarded – undo
660 668
 /**
661 669
  * Ajout d'une tache dans la file d'attente
662 670
  *
663
- * @param $function
671
+ * @param string $function
664 672
  *   The function name to call.
665
- * @param $description
673
+ * @param string $description
666 674
  *   A human-readable description of the queued job.
667 675
  * @param $arguments
668 676
  *   Optional array of arguments to pass to the function.
@@ -718,7 +726,6 @@  discard block
 block discarded – undo
718 726
  *  - si int, affecte la static directement avec la valeur
719 727
  *
720 728
  * @staticvar int $queue_next_job_time
721
- * @param int/bool $force_next
722 729
  * @return int
723 730
  */
724 731
 function queue_sleep_time_to_next_job($force=null) {
@@ -795,6 +802,9 @@  discard block
 block discarded – undo
795 802
 // du path, dans cet ordre.
796 803
 // Exception: si un $dossier_squelette est defini, il reste en tete, pour raison historique
797 804
 // http://doc.spip.org/@_chemin
805
+/**
806
+ * @param string $dir_path
807
+ */
798 808
 function _chemin($dir_path=NULL){
799 809
 	static $path_base = NULL;
800 810
 	static $path_full = NULL;
@@ -1050,6 +1060,9 @@  discard block
 block discarded – undo
1050 1060
  * @return array
1051 1061
  */
1052 1062
 // http://doc.spip.org/@find_all_in_path
1063
+/**
1064
+ * @param string $pattern
1065
+ */
1053 1066
 function find_all_in_path($dir,$pattern, $recurs=false){
1054 1067
 	$liste_fichiers=array();
1055 1068
 	$maxfiles = 10000;
@@ -1197,6 +1210,9 @@  discard block
 block discarded – undo
1197 1210
 }
1198 1211
 
1199 1212
 // http://doc.spip.org/@generer_url_entite_absolue
1213
+/**
1214
+ * @param boolean|string $connect
1215
+ */
1200 1216
 function generer_url_entite_absolue($id='', $entite='', $args='', $ancre='', $connect=NULL)
1201 1217
 {
1202 1218
 	if (!$connect) $connect = true;
@@ -1440,6 +1456,9 @@  discard block
 block discarded – undo
1440 1456
 }
1441 1457
 
1442 1458
 // http://doc.spip.org/@generer_url_action
1459
+/**
1460
+ * @param string $script
1461
+ */
1443 1462
 function generer_url_action($script, $args="", $no_entities=false , $public = false) {
1444 1463
 	// si l'on est dans l'espace prive, on garde dans l'url
1445 1464
 	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
@@ -2202,7 +2221,7 @@  discard block
 block discarded – undo
2202 2221
 /**
2203 2222
  * Trouve un squelette dans le repertoire modeles/
2204 2223
  *
2205
- * @param  $nom
2224
+ * @param  string $nom
2206 2225
  * @return string
2207 2226
  */
2208 2227
 function trouve_modele($nom) {
@@ -2256,6 +2275,9 @@  discard block
 block discarded – undo
2256 2275
 
2257 2276
 // Charger dynamiquement une extension php
2258 2277
 // http://doc.spip.org/@charger_php_extension
2278
+/**
2279
+ * @param string $module
2280
+ */
2259 2281
 function charger_php_extension($module) {
2260 2282
 	if (extension_loaded($module)) {
2261 2283
 		return true;
@@ -2279,6 +2301,9 @@  discard block
 block discarded – undo
2279 2301
  */
2280 2302
 // Fonction depreciee
2281 2303
 // http://doc.spip.org/@lire_meta
2304
+/**
2305
+ * @param string $nom
2306
+ */
2282 2307
 function lire_meta($nom) {
2283 2308
 	return $GLOBALS['meta'][$nom];
2284 2309
 }
Please login to merge, or discard this patch.
Indentation   +1522 added lines, -1523 removed lines patch added patch discarded remove patch
@@ -30,47 +30,47 @@  discard block
 block discarded – undo
30 30
  * @return string
31 31
  */
32 32
 function charger_fonction($nom, $dossier='exec', $continue=false) {
33
-	static $echecs = array();
33
+    static $echecs = array();
34 34
 
35
-	if (strlen($dossier) AND substr($dossier,-1) != '/') $dossier .= '/';
36
-	$f = str_replace('/','_',$dossier) . $nom;
35
+    if (strlen($dossier) AND substr($dossier,-1) != '/') $dossier .= '/';
36
+    $f = str_replace('/','_',$dossier) . $nom;
37 37
 
38
-	if (function_exists($f))
39
-		return $f;
40
-	if (function_exists($g = $f . '_dist'))
41
-		return $g;
38
+    if (function_exists($f))
39
+        return $f;
40
+    if (function_exists($g = $f . '_dist'))
41
+        return $g;
42 42
 
43
-	if (isset($echecs[$f])) return $echecs[$f];
44
-	// Sinon charger le fichier de declaration si plausible
43
+    if (isset($echecs[$f])) return $echecs[$f];
44
+    // Sinon charger le fichier de declaration si plausible
45 45
 
46
-	if (!preg_match(',^\w+$,', $f)){
47
-		if ($continue) return false; //appel interne, on passe
48
-		include_spip('inc/minipres');
49
-		echo minipres();
50
-		exit;
51
-	}
46
+    if (!preg_match(',^\w+$,', $f)){
47
+        if ($continue) return false; //appel interne, on passe
48
+        include_spip('inc/minipres');
49
+        echo minipres();
50
+        exit;
51
+    }
52 52
 
53
-	// passer en minuscules (cf les balises de formulaires)
54
-	// et inclure le fichier
55
-	if (!$inc = include_spip($dossier.($d = strtolower($nom)))
56
-		// si le fichier truc/machin/nom.php n'existe pas,
57
-		// la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
58
-		AND strlen(dirname($dossier)) AND dirname($dossier)!='.')
59
-		include_spip(substr($dossier,0,-1));
60
-	if (function_exists($f)) return $f;
61
-	if (function_exists($g)) return $g;
53
+    // passer en minuscules (cf les balises de formulaires)
54
+    // et inclure le fichier
55
+    if (!$inc = include_spip($dossier.($d = strtolower($nom)))
56
+        // si le fichier truc/machin/nom.php n'existe pas,
57
+        // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
58
+        AND strlen(dirname($dossier)) AND dirname($dossier)!='.')
59
+        include_spip(substr($dossier,0,-1));
60
+    if (function_exists($f)) return $f;
61
+    if (function_exists($g)) return $g;
62 62
 
63
-	if ($continue) return $echecs[$f] = false;
63
+    if ($continue) return $echecs[$f] = false;
64 64
 
65
-	// Echec : message d'erreur
66
-	spip_log("fonction $nom ($f ou $g) indisponible" .
67
-		($inc ? "" : " (fichier $d absent de $dossier)"));
65
+    // Echec : message d'erreur
66
+    spip_log("fonction $nom ($f ou $g) indisponible" .
67
+        ($inc ? "" : " (fichier $d absent de $dossier)"));
68 68
 
69
-	include_spip('inc/minipres');
70
-	echo minipres(_T('forum_titre_erreur'),
71
-		 _T('fichier_introuvable', array('fichier'=> '<b>'.spip_htmlentities($d).'</b>')),
72
-		array('all_inline'=>true,'status'=>404));
73
-	exit;
69
+    include_spip('inc/minipres');
70
+    echo minipres(_T('forum_titre_erreur'),
71
+            _T('fichier_introuvable', array('fichier'=> '<b>'.spip_htmlentities($d).'</b>')),
72
+        array('all_inline'=>true,'status'=>404));
73
+    exit;
74 74
 }
75 75
 
76 76
 /**
@@ -79,12 +79,12 @@  discard block
 block discarded – undo
79 79
  * @return bool
80 80
  */
81 81
 function include_once_check($file){
82
-	if (file_exists($file)) {include_once $file;return true;}
83
-	$crash = (isset($GLOBALS['meta']['message_crash_plugins'])?unserialize($GLOBALS['meta']['message_crash_plugins']):'');
84
-	$crash = ($crash?$crash:array());
85
-	$crash[$file] = true;
86
-	ecrire_meta('message_crash_plugins',serialize($crash));
87
-	return false;
82
+    if (file_exists($file)) {include_once $file;return true;}
83
+    $crash = (isset($GLOBALS['meta']['message_crash_plugins'])?unserialize($GLOBALS['meta']['message_crash_plugins']):'');
84
+    $crash = ($crash?$crash:array());
85
+    $crash[$file] = true;
86
+    ecrire_meta('message_crash_plugins',serialize($crash));
87
+    return false;
88 88
 }
89 89
 
90 90
 //
@@ -92,12 +92,12 @@  discard block
 block discarded – undo
92 92
 //
93 93
 // http://doc.spip.org/@include_spip
94 94
 function include_spip($f, $include = true) {
95
-	return find_in_path($f . '.php', '', $include);
95
+    return find_in_path($f . '.php', '', $include);
96 96
 }
97 97
 
98 98
 
99 99
 function require_spip($f) {
100
-	return find_in_path($f . '.php', '', 'required');
100
+    return find_in_path($f . '.php', '', 'required');
101 101
 }
102 102
 
103 103
 // un pipeline est lie a une action et une valeur
@@ -114,59 +114,59 @@  discard block
 block discarded – undo
114 114
 // on passe $val par reference pour limiter les allocations memoire
115 115
 // http://doc.spip.org/@minipipe
116 116
 function minipipe($fonc,&$val){
117
-	// fonction
118
-	if (function_exists($fonc))
119
-		$val = call_user_func($fonc, $val);
120
-	// Class::Methode
121
-	else if (preg_match("/^(\w*)::(\w*)$/S", $fonc, $regs)
122
-	AND $methode = array($regs[1], $regs[2])
123
-	AND is_callable($methode))
124
-		$val = call_user_func($methode, $val);
125
-	else {
126
-		spip_log("Erreur - '$fonc' non definie !");
127
-	}
128
-	return $val;
117
+    // fonction
118
+    if (function_exists($fonc))
119
+        $val = call_user_func($fonc, $val);
120
+    // Class::Methode
121
+    else if (preg_match("/^(\w*)::(\w*)$/S", $fonc, $regs)
122
+    AND $methode = array($regs[1], $regs[2])
123
+    AND is_callable($methode))
124
+        $val = call_user_func($methode, $val);
125
+    else {
126
+        spip_log("Erreur - '$fonc' non definie !");
127
+    }
128
+    return $val;
129 129
 }
130 130
 
131 131
 // chargement du pipeline sous la forme d'un fichier php prepare
132 132
 // http://doc.spip.org/@pipeline
133 133
 function pipeline($action, $val=null) {
134
-	static $charger;
135
-
136
-	// chargement initial des fonctions mises en cache, ou generation du cache
137
-	if (!$charger) {
138
-		if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
139
-			include_spip('inc/plugin');
140
-			// generer les fichiers php precompiles
141
-			// de chargement des plugins et des pipelines
142
-			actualise_plugins_actifs();
143
-			if (!($ok = @is_readable($charger)))
144
-				spip_log("fichier $charger pas cree");
145
-		}
146
-
147
-		if ($ok) {
148
-			include_once $charger;
149
-		}
150
-	}
151
-
152
-	// appliquer notre fonction si elle existe
153
-	$fonc = 'execute_pipeline_'.strtolower($action);
154
-	if (function_exists($fonc)) {
155
-		$val = $fonc($val);
156
-	}
157
-	// plantage ?
158
-	else {
159
-		spip_log("fonction $fonc absente : pipeline desactive",_LOG_ERREUR);
160
-	}
161
-
162
-	// si le flux est une table avec 2 cle args&data
163
-	// on ne ressort du pipe que les donnees dans 'data'
164
-	// array_key_exists pour php 4.1.0
165
-	if (is_array($val)
166
-	  AND count($val)==2
167
-	  AND (array_key_exists('data',$val)))
168
-		$val = $val['data'];
169
-	return $val;
134
+    static $charger;
135
+
136
+    // chargement initial des fonctions mises en cache, ou generation du cache
137
+    if (!$charger) {
138
+        if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
139
+            include_spip('inc/plugin');
140
+            // generer les fichiers php precompiles
141
+            // de chargement des plugins et des pipelines
142
+            actualise_plugins_actifs();
143
+            if (!($ok = @is_readable($charger)))
144
+                spip_log("fichier $charger pas cree");
145
+        }
146
+
147
+        if ($ok) {
148
+            include_once $charger;
149
+        }
150
+    }
151
+
152
+    // appliquer notre fonction si elle existe
153
+    $fonc = 'execute_pipeline_'.strtolower($action);
154
+    if (function_exists($fonc)) {
155
+        $val = $fonc($val);
156
+    }
157
+    // plantage ?
158
+    else {
159
+        spip_log("fonction $fonc absente : pipeline desactive",_LOG_ERREUR);
160
+    }
161
+
162
+    // si le flux est une table avec 2 cle args&data
163
+    // on ne ressort du pipe que les donnees dans 'data'
164
+    // array_key_exists pour php 4.1.0
165
+    if (is_array($val)
166
+      AND count($val)==2
167
+      AND (array_key_exists('data',$val)))
168
+        $val = $val['data'];
169
+    return $val;
170 170
 }
171 171
 
172 172
 /**
@@ -187,38 +187,38 @@  discard block
 block discarded – undo
187 187
  * @param string $logsuf  ## inutile !! a supprimer ?
188 188
  */
189 189
 function spip_log($message=NULL, $name=NULL) {
190
-	static $pre = array();
191
-	static $log;
192
-	preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string) $name, $regs);
193
-	if (!isset($regs[1]) OR !$logname = $regs[1])
194
-		$logname = null;
195
-	if (!isset($regs[2]) OR !$niveau = $regs[2])
196
-		$niveau = _LOG_INFO;
197
-
198
-	if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
199
-		if (!$pre){
200
-			$pre = array(
201
-				_LOG_HS=>'HS:',
202
-				_LOG_ALERTE_ROUGE=>'ALERTE:',
203
-				_LOG_CRITIQUE=>'CRITIQUE:',
204
-				_LOG_ERREUR=>'ERREUR:',
205
-				_LOG_AVERTISSEMENT=>'WARNING:',
206
-				_LOG_INFO_IMPORTANTE=>'!INFO:',
207
-				_LOG_INFO=>'info:',
208
-				_LOG_DEBUG=>'debug:');
209
-			$log = charger_fonction('log', 'inc');
210
-		}
211
-		if (!is_string($message)) $message = var_export($message, true);
212
-		$log($pre[$niveau].' '.$message, $logname);
213
-	}
190
+    static $pre = array();
191
+    static $log;
192
+    preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string) $name, $regs);
193
+    if (!isset($regs[1]) OR !$logname = $regs[1])
194
+        $logname = null;
195
+    if (!isset($regs[2]) OR !$niveau = $regs[2])
196
+        $niveau = _LOG_INFO;
197
+
198
+    if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
199
+        if (!$pre){
200
+            $pre = array(
201
+                _LOG_HS=>'HS:',
202
+                _LOG_ALERTE_ROUGE=>'ALERTE:',
203
+                _LOG_CRITIQUE=>'CRITIQUE:',
204
+                _LOG_ERREUR=>'ERREUR:',
205
+                _LOG_AVERTISSEMENT=>'WARNING:',
206
+                _LOG_INFO_IMPORTANTE=>'!INFO:',
207
+                _LOG_INFO=>'info:',
208
+                _LOG_DEBUG=>'debug:');
209
+            $log = charger_fonction('log', 'inc');
210
+        }
211
+        if (!is_string($message)) $message = var_export($message, true);
212
+        $log($pre[$niveau].' '.$message, $logname);
213
+    }
214 214
 }
215 215
 
216 216
 //
217 217
 // Enregistrement des journaux
218 218
 //
219 219
 function journal($phrase, $opt = array()) {
220
-	$journal = charger_fonction('journal', 'inc');
221
-	$journal($phrase, $opt);
220
+    $journal = charger_fonction('journal', 'inc');
221
+    $journal($phrase, $opt);
222 222
 }
223 223
 
224 224
 // Renvoie le _GET ou le _POST emis par l'utilisateur
@@ -226,50 +226,50 @@  discard block
 block discarded – undo
226 226
 // http://doc.spip.org/@_request
227 227
 function _request($var, $c=false) {
228 228
 
229
-	if (is_array($c))
230
-		return isset($c[$var]) ? $c[$var] : NULL;
231
-
232
-	if (isset($_GET[$var])) $a = $_GET[$var];
233
-	elseif (isset($_POST[$var])) $a = $_POST[$var];
234
-	else return NULL;
235
-
236
-	// Si on est en ajax et en POST tout a ete encode
237
-	// via encodeURIComponent, il faut donc repasser
238
-	// dans le charset local...
239
-	if (defined('_AJAX')
240
-	AND _AJAX
241
-	AND isset($GLOBALS['meta']['charset'])
242
-	AND $GLOBALS['meta']['charset'] != 'utf-8'
243
-	AND is_string($a)
244
-	// check rapide mais pas fiable
245
-	AND preg_match(',[\x80-\xFF],', $a)
246
-	// check fiable
247
-	AND include_spip('inc/charsets')
248
-	AND is_utf8($a)
249
-	) {
250
-		return importer_charset($a, 'utf-8');
251
-	}
252
-
253
-	return $a;
229
+    if (is_array($c))
230
+        return isset($c[$var]) ? $c[$var] : NULL;
231
+
232
+    if (isset($_GET[$var])) $a = $_GET[$var];
233
+    elseif (isset($_POST[$var])) $a = $_POST[$var];
234
+    else return NULL;
235
+
236
+    // Si on est en ajax et en POST tout a ete encode
237
+    // via encodeURIComponent, il faut donc repasser
238
+    // dans le charset local...
239
+    if (defined('_AJAX')
240
+    AND _AJAX
241
+    AND isset($GLOBALS['meta']['charset'])
242
+    AND $GLOBALS['meta']['charset'] != 'utf-8'
243
+    AND is_string($a)
244
+    // check rapide mais pas fiable
245
+    AND preg_match(',[\x80-\xFF],', $a)
246
+    // check fiable
247
+    AND include_spip('inc/charsets')
248
+    AND is_utf8($a)
249
+    ) {
250
+        return importer_charset($a, 'utf-8');
251
+    }
252
+
253
+    return $a;
254 254
 }
255 255
 
256 256
 // Methode set de la fonction _request()
257 257
 // Attention au cas ou l'on fait set_request('truc', NULL);
258 258
 // http://doc.spip.org/@set_request
259 259
 function set_request($var, $val = NULL, $c=false) {
260
-	if (is_array($c)) {
261
-		unset($c[$var]);
262
-		if ($val !== NULL)
263
-			$c[$var] = $val;
264
-		return $c;
265
-	}
260
+    if (is_array($c)) {
261
+        unset($c[$var]);
262
+        if ($val !== NULL)
263
+            $c[$var] = $val;
264
+        return $c;
265
+    }
266 266
 
267
-	unset($_GET[$var]);
268
-	unset($_POST[$var]);
269
-	if ($val !== NULL)
270
-		$_GET[$var] = $val;
267
+    unset($_GET[$var]);
268
+    unset($_POST[$var]);
269
+    if ($val !== NULL)
270
+        $_GET[$var] = $val;
271 271
 
272
-	return false; # n'affecte pas $c
272
+    return false; # n'affecte pas $c
273 273
 }
274 274
 
275 275
 
@@ -278,23 +278,22 @@  discard block
 block discarded – undo
278 278
  * 
279 279
  * On est sur le web, on exclut certains protocoles, 
280 280
  * notamment 'file://', 'php://' et d'autres…
281
-
282 281
  * @param string $url
283 282
  * @return bool
284 283
  */
285 284
 function tester_url_absolue($url) {
286
-	$url = trim($url);
287
-	if (preg_match(";^([a-z]{3,7}:)?//;Uims", $url, $m)) {
288
-		if (
289
-			isset($m[1])
290
-			and $p = strtolower(rtrim($m[1], ':'))
291
-			and in_array($p, array('file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'))
292
-		  ) {
293
-			return false;
294
-		}
295
-		return true;
296
-	}
297
-	return false;
285
+    $url = trim($url);
286
+    if (preg_match(";^([a-z]{3,7}:)?//;Uims", $url, $m)) {
287
+        if (
288
+            isset($m[1])
289
+            and $p = strtolower(rtrim($m[1], ':'))
290
+            and in_array($p, array('file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'))
291
+            ) {
292
+            return false;
293
+        }
294
+        return true;
295
+    }
296
+    return false;
298 297
 }
299 298
 
300 299
 /**
@@ -313,71 +312,71 @@  discard block
 block discarded – undo
313 312
  * @return string
314 313
  */
315 314
 function parametre_url($url, $c, $v=NULL, $sep='&amp;') {
316
-	// requete erronnee : plusieurs variable dans $c et aucun $v
317
-	if (strpos($c,"|")!==false AND is_null($v))
318
-		return null;
319
-
320
-	// lever l'#ancre
321
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
322
-		$url = $r[1];
323
-		$ancre = $r[2];
324
-	} else
325
-		$ancre = '';
326
-
327
-	// eclater
328
-	$url = preg_split(',[?]|&amp;|&,', $url);
329
-
330
-	// recuperer la base
331
-	$a = array_shift($url);
332
-	if (!$a) $a= './';
333
-
334
-	$regexp = ',^(' . str_replace('[]','\[\]',$c) . '[[]?[]]?)(=.*)?$,';
335
-	$ajouts = array_flip(explode('|',$c));
336
-	$u = is_array($v) ? $v : rawurlencode($v);
337
-	$testv = (is_array($v)?count($v):strlen($v));
338
-	// lire les variables et agir
339
-	foreach ($url as $n => $val) {
340
-		if (preg_match($regexp, urldecode($val), $r)) {
341
-			if ($v === NULL) {
342
-				return $r[2]?substr($r[2],1):'';
343
-			}
344
-			// suppression
345
-			elseif (!$testv) {
346
-				unset($url[$n]);
347
-			}
348
-	// Ajout. Pour une variable, remplacer au meme endroit,
349
-	// pour un tableau ce sera fait dans la prochaine boucle
350
-			elseif (substr($r[1],-2) != '[]') {
351
-				$url[$n] = $r[1].'='.$u;
352
-				unset($ajouts[$r[1]]);
353
-			}
354
-		}
355
-	}
356
-
357
-	// traiter les parametres pas encore trouves
358
-	if ($v === NULL
359
-	AND $args = func_get_args()
360
-	AND count($args)==2)
361
-		return $v;
362
-	elseif ($testv) {
363
-		foreach($ajouts as $k => $n) {
364
-		  if (!is_array($v))
365
-		    $url[] = $k .'=' . $u;
366
-		  else {
367
-		  	$id = (substr($k,-2) == '[]') ? $k : ($k ."[]");
368
-		    foreach ($v as $w) $url[]= $id .'=' . $w;
369
-		  }
370
-		}
371
-	}
372
-
373
-	// eliminer les vides
374
-	$url = array_filter($url);
375
-
376
-	// recomposer l'adresse
377
-	if ($url)
378
-		$a .= '?' . join($sep, $url);
379
-
380
-	return $a . $ancre;
315
+    // requete erronnee : plusieurs variable dans $c et aucun $v
316
+    if (strpos($c,"|")!==false AND is_null($v))
317
+        return null;
318
+
319
+    // lever l'#ancre
320
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
321
+        $url = $r[1];
322
+        $ancre = $r[2];
323
+    } else
324
+        $ancre = '';
325
+
326
+    // eclater
327
+    $url = preg_split(',[?]|&amp;|&,', $url);
328
+
329
+    // recuperer la base
330
+    $a = array_shift($url);
331
+    if (!$a) $a= './';
332
+
333
+    $regexp = ',^(' . str_replace('[]','\[\]',$c) . '[[]?[]]?)(=.*)?$,';
334
+    $ajouts = array_flip(explode('|',$c));
335
+    $u = is_array($v) ? $v : rawurlencode($v);
336
+    $testv = (is_array($v)?count($v):strlen($v));
337
+    // lire les variables et agir
338
+    foreach ($url as $n => $val) {
339
+        if (preg_match($regexp, urldecode($val), $r)) {
340
+            if ($v === NULL) {
341
+                return $r[2]?substr($r[2],1):'';
342
+            }
343
+            // suppression
344
+            elseif (!$testv) {
345
+                unset($url[$n]);
346
+            }
347
+    // Ajout. Pour une variable, remplacer au meme endroit,
348
+    // pour un tableau ce sera fait dans la prochaine boucle
349
+            elseif (substr($r[1],-2) != '[]') {
350
+                $url[$n] = $r[1].'='.$u;
351
+                unset($ajouts[$r[1]]);
352
+            }
353
+        }
354
+    }
355
+
356
+    // traiter les parametres pas encore trouves
357
+    if ($v === NULL
358
+    AND $args = func_get_args()
359
+    AND count($args)==2)
360
+        return $v;
361
+    elseif ($testv) {
362
+        foreach($ajouts as $k => $n) {
363
+            if (!is_array($v))
364
+            $url[] = $k .'=' . $u;
365
+            else {
366
+                $id = (substr($k,-2) == '[]') ? $k : ($k ."[]");
367
+            foreach ($v as $w) $url[]= $id .'=' . $w;
368
+            }
369
+        }
370
+    }
371
+
372
+    // eliminer les vides
373
+    $url = array_filter($url);
374
+
375
+    // recomposer l'adresse
376
+    if ($url)
377
+        $a .= '?' . join($sep, $url);
378
+
379
+    return $a . $ancre;
381 380
 }
382 381
 
383 382
 // Prend une URL et lui ajoute/retire une ancre apres l'avoir nettoyee
@@ -385,17 +384,17 @@  discard block
 block discarded – undo
385 384
 // et on remplace ceux a l'interieur ou au bout par -
386 385
 // http://doc.spip.org/@ancre_url
387 386
 function ancre_url($url, $ancre) {
388
-	// lever l'#ancre
389
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
390
-		$url = $r[1];
391
-	}
392
-	if (preg_match('/[^-_a-zA-Z0-9]+/S',$ancre)){
393
-		if (!function_exists('translitteration'))
394
-			include_spip('inc/charsets');
395
-		$ancre = preg_replace(array('/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'), array('', '-'),
396
-						translitteration($ancre));
397
-	}
398
-	return $url . (strlen($ancre) ? '#'. $ancre : '');
387
+    // lever l'#ancre
388
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
389
+        $url = $r[1];
390
+    }
391
+    if (preg_match('/[^-_a-zA-Z0-9]+/S',$ancre)){
392
+        if (!function_exists('translitteration'))
393
+            include_spip('inc/charsets');
394
+        $ancre = preg_replace(array('/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'), array('', '-'),
395
+                        translitteration($ancre));
396
+    }
397
+    return $url . (strlen($ancre) ? '#'. $ancre : '');
399 398
 }
400 399
 
401 400
 /**
@@ -407,21 +406,21 @@  discard block
 block discarded – undo
407 406
  */
408 407
 function nettoyer_uri($reset = null)
409 408
 {
410
-	static $done = false;
411
-	static $propre = '';
412
-	if (!is_null($reset)) return $propre=$reset;
413
-	if ($done) return $propre;
414
-	$done = true;
409
+    static $done = false;
410
+    static $propre = '';
411
+    if (!is_null($reset)) return $propre=$reset;
412
+    if ($done) return $propre;
413
+    $done = true;
415 414
 
416
-	$uri1 = $GLOBALS['REQUEST_URI'];
417
-	do {
418
-		$uri = $uri1;
419
-		$uri1 = preg_replace
420
-			(',([?&])(PHPSESSID|(var_[^=&]*))=[^&]*(&|$),i',
421
-			'\1', $uri);
422
-	} while ($uri<>$uri1);
415
+    $uri1 = $GLOBALS['REQUEST_URI'];
416
+    do {
417
+        $uri = $uri1;
418
+        $uri1 = preg_replace
419
+            (',([?&])(PHPSESSID|(var_[^=&]*))=[^&]*(&|$),i',
420
+            '\1', $uri);
421
+    } while ($uri<>$uri1);
423 422
 
424
-	return $propre = (preg_replace(',[?&]$,', '', $uri1));
423
+    return $propre = (preg_replace(',[?&]$,', '', $uri1));
425 424
 }
426 425
 
427 426
 
@@ -435,47 +434,47 @@  discard block
 block discarded – undo
435 434
  *    URL vers soi-même
436 435
 **/
437 436
 function self($amp = '&amp;', $root = false) {
438
-	$url = nettoyer_uri();
439
-	if (!$root
440
-		AND (
441
-			// si pas de profondeur on peut tronquer
442
-			$GLOBALS['profondeur_url']<(_DIR_RESTREINT?1:2)
443
-			// sinon c'est OK si _SET_HTML_BASE a ete force a false
444
-			OR (defined('_SET_HTML_BASE') AND !_SET_HTML_BASE))
445
-		)
446
-		$url = preg_replace(',^[^?]*/,', '', $url);
447
-	// ajouter le cas echeant les variables _POST['id_...']
448
-	foreach ($_POST as $v => $c)
449
-		if (substr($v,0,3) == 'id_')
450
-			$url = parametre_url($url, $v, $c, '&');
451
-
452
-	// supprimer les variables sans interet
453
-	if (test_espace_prive()) {
454
-		$url = preg_replace (',([?&])('
455
-		.'lang|show_docs|'
456
-		.'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
457
-		$url = preg_replace(',([?&])[&]+,', '\1', $url);
458
-		$url = preg_replace(',[&]$,', '\1', $url);
459
-	}
460
-
461
-	// eviter les hacks
462
-	include_spip('inc/filtres_mini');
463
-	$url = spip_htmlspecialchars($url);
464
-
465
-	// &amp; ?
466
-	if ($amp != '&amp;')
467
-		$url = str_replace('&amp;', $amp, $url);
468
-
469
-	// Si ca demarre par ? ou vide, donner './'
470
-	$url = preg_replace(',^([?].*)?$,', './\1', $url);
471
-
472
-	return $url;
437
+    $url = nettoyer_uri();
438
+    if (!$root
439
+        AND (
440
+            // si pas de profondeur on peut tronquer
441
+            $GLOBALS['profondeur_url']<(_DIR_RESTREINT?1:2)
442
+            // sinon c'est OK si _SET_HTML_BASE a ete force a false
443
+            OR (defined('_SET_HTML_BASE') AND !_SET_HTML_BASE))
444
+        )
445
+        $url = preg_replace(',^[^?]*/,', '', $url);
446
+    // ajouter le cas echeant les variables _POST['id_...']
447
+    foreach ($_POST as $v => $c)
448
+        if (substr($v,0,3) == 'id_')
449
+            $url = parametre_url($url, $v, $c, '&');
450
+
451
+    // supprimer les variables sans interet
452
+    if (test_espace_prive()) {
453
+        $url = preg_replace (',([?&])('
454
+        .'lang|show_docs|'
455
+        .'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
456
+        $url = preg_replace(',([?&])[&]+,', '\1', $url);
457
+        $url = preg_replace(',[&]$,', '\1', $url);
458
+    }
459
+
460
+    // eviter les hacks
461
+    include_spip('inc/filtres_mini');
462
+    $url = spip_htmlspecialchars($url);
463
+
464
+    // &amp; ?
465
+    if ($amp != '&amp;')
466
+        $url = str_replace('&amp;', $amp, $url);
467
+
468
+    // Si ca demarre par ? ou vide, donner './'
469
+    $url = preg_replace(',^([?].*)?$,', './\1', $url);
470
+
471
+    return $url;
473 472
 }
474 473
 
475 474
 // Indique si on est dans l'espace prive
476 475
 // http://doc.spip.org/@test_espace_prive
477 476
 function test_espace_prive() {
478
-	return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
477
+    return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
479 478
 }
480 479
 
481 480
 /**
@@ -486,7 +485,7 @@  discard block
 block discarded – undo
486 485
  * @return bool
487 486
  */
488 487
 function test_plugin_actif($plugin){
489
-	return ($plugin AND defined('_DIR_PLUGIN_'.strtoupper($plugin)))? true:false;
488
+    return ($plugin AND defined('_DIR_PLUGIN_'.strtoupper($plugin)))? true:false;
490 489
 }
491 490
 
492 491
 /**
@@ -501,49 +500,49 @@  discard block
 block discarded – undo
501 500
  * @return mixed|string
502 501
  */
503 502
 function _T($texte, $args=array(), $options=array()) {
504
-	static $traduire=false ;
505
-	$o = array('class'=>'', 'force'=>true);
506
-	if ($options){
507
-		// support de l'ancien argument $class
508
-		if (is_string($options))
509
-			$options = array('class'=>$options);
510
-		$o = array_merge($o,$options);
511
-	}
512
-
513
- 	if (!$traduire) {
514
-		$traduire = charger_fonction('traduire', 'inc');
515
-		include_spip('inc/lang');
516
-	}
503
+    static $traduire=false ;
504
+    $o = array('class'=>'', 'force'=>true);
505
+    if ($options){
506
+        // support de l'ancien argument $class
507
+        if (is_string($options))
508
+            $options = array('class'=>$options);
509
+        $o = array_merge($o,$options);
510
+    }
511
+
512
+        if (!$traduire) {
513
+        $traduire = charger_fonction('traduire', 'inc');
514
+        include_spip('inc/lang');
515
+    }
517 516
 	
518
-	// On peut passer explicitement la langue dans le tableau
519
-	// On utilise le même nom de variable que la globale
520
-	if (isset($args['spip_lang'])){
521
-		$lang = $args['spip_lang'];
522
-		// On l'enleve pour ne pas le passer au remplacement
523
-		unset($args['spip_lang']);
524
-	}
525
-	// Sinon on prend la langue du contexte
526
-	else {
527
-		$lang = $GLOBALS['spip_lang'];
528
-	}
529
-	$text = $traduire($texte, $lang);
517
+    // On peut passer explicitement la langue dans le tableau
518
+    // On utilise le même nom de variable que la globale
519
+    if (isset($args['spip_lang'])){
520
+        $lang = $args['spip_lang'];
521
+        // On l'enleve pour ne pas le passer au remplacement
522
+        unset($args['spip_lang']);
523
+    }
524
+    // Sinon on prend la langue du contexte
525
+    else {
526
+        $lang = $GLOBALS['spip_lang'];
527
+    }
528
+    $text = $traduire($texte, $lang);
530 529
 
531
-	if (!strlen($text)){
532
-		if (!$o['force'])
533
-			return '';
530
+    if (!strlen($text)){
531
+        if (!$o['force'])
532
+            return '';
534 533
 
535
-		$text = $texte;
534
+        $text = $texte;
536 535
 
537
-		// pour les chaines non traduites, assurer un service minimum
538
-		if (!$GLOBALS['test_i18n'] AND (_request('var_mode') != 'traduction'))
539
-			$text = str_replace('_', ' ',
540
-				 (($n = strpos($text,':')) === false ? $texte :
541
-					substr($texte, $n+1)));
542
-		$o['class'] = null;
536
+        // pour les chaines non traduites, assurer un service minimum
537
+        if (!$GLOBALS['test_i18n'] AND (_request('var_mode') != 'traduction'))
538
+            $text = str_replace('_', ' ',
539
+                    (($n = strpos($text,':')) === false ? $texte :
540
+                    substr($texte, $n+1)));
541
+        $o['class'] = null;
543 542
 
544
-	}
543
+    }
545 544
 
546
-	return _L($text, $args, $o['class']);
545
+    return _L($text, $args, $o['class']);
547 546
 
548 547
 }
549 548
 
@@ -551,34 +550,34 @@  discard block
 block discarded – undo
551 550
 // Aussi appelee quand une chaine n'est pas encore dans les fichiers de langue
552 551
 // http://doc.spip.org/@_L
553 552
 function _L($text, $args=array(), $class=null) {
554
-	$f = $text;
555
-	if (is_array($args)) {
556
-		foreach ($args as $name => $value) {
557
-			if ($class)
558
-				$value = "<span class='$class'>$value</span>";
559
-			$t = str_replace ("@$name@", $value, $text);
560
-			if ($text !== $t) {unset($args[$name]); $text = $t;}
561
-		}
562
-		// Si des variables n'ont pas ete inserees, le signaler
563
-		// (chaines de langues pas a jour)
564
-		if ($args) spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)),_LOG_DEBUG);
565
-	}
566
-
567
-	if (($GLOBALS['test_i18n'] OR (_request('var_mode') == 'traduction')) AND $class===null)
568
-		return "<span class=debug-traduction-erreur>$text</span>";
569
-	else
570
-		return $text;
553
+    $f = $text;
554
+    if (is_array($args)) {
555
+        foreach ($args as $name => $value) {
556
+            if ($class)
557
+                $value = "<span class='$class'>$value</span>";
558
+            $t = str_replace ("@$name@", $value, $text);
559
+            if ($text !== $t) {unset($args[$name]); $text = $t;}
560
+        }
561
+        // Si des variables n'ont pas ete inserees, le signaler
562
+        // (chaines de langues pas a jour)
563
+        if ($args) spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)),_LOG_DEBUG);
564
+    }
565
+
566
+    if (($GLOBALS['test_i18n'] OR (_request('var_mode') == 'traduction')) AND $class===null)
567
+        return "<span class=debug-traduction-erreur>$text</span>";
568
+    else
569
+        return $text;
571 570
 }
572 571
 
573 572
 // Afficher "ecrire/data/" au lieu de "data/" dans les messages
574 573
 // ou tmp/ au lieu de ../tmp/
575 574
 // http://doc.spip.org/@joli_repertoire
576 575
 function joli_repertoire($rep) {
577
-	$a = substr($rep,0,1);
578
-	if ($a<>'.' AND $a<>'/')
579
-		$rep = (_DIR_RESTREINT?'':_DIR_RESTREINT_ABS).$rep;
580
-	$rep = preg_replace(',(^\.\.\/),', '', $rep);
581
-	return $rep;
576
+    $a = substr($rep,0,1);
577
+    if ($a<>'.' AND $a<>'/')
578
+        $rep = (_DIR_RESTREINT?'':_DIR_RESTREINT_ABS).$rep;
579
+    $rep = preg_replace(',(^\.\.\/),', '', $rep);
580
+    return $rep;
582 581
 }
583 582
 
584 583
 
@@ -587,27 +586,27 @@  discard block
 block discarded – undo
587 586
 //
588 587
 // http://doc.spip.org/@spip_timer
589 588
 function spip_timer($t='rien', $raw = false) {
590
-	static $time;
591
-	$a=time(); $b=microtime();
592
-	// microtime peut contenir les microsecondes et le temps
593
-	$b=explode(' ',$b);
594
-	if (count($b)==2) $a = end($b); // plus precis !
595
-	$b = reset($b);
596
-	if (!isset($time[$t])) {
597
-		$time[$t] = $a + $b;
598
-	} else {
599
-		$p = ($a + $b - $time[$t]) * 1000;
600
-		unset($time[$t]);
589
+    static $time;
590
+    $a=time(); $b=microtime();
591
+    // microtime peut contenir les microsecondes et le temps
592
+    $b=explode(' ',$b);
593
+    if (count($b)==2) $a = end($b); // plus precis !
594
+    $b = reset($b);
595
+    if (!isset($time[$t])) {
596
+        $time[$t] = $a + $b;
597
+    } else {
598
+        $p = ($a + $b - $time[$t]) * 1000;
599
+        unset($time[$t]);
601 600
 #			echo "'$p'";exit;
602
-		if ($raw) return $p;
603
-		if ($p < 1000)
604
-			$s = '';
605
-		else {
606
-			$s = sprintf("%d ", $x = floor($p/1000));
607
-			$p -= ($x*1000);
608
-		}
609
-		return $s . sprintf($s?"%07.3f ms":"%.3f ms", $p);
610
-	}
601
+        if ($raw) return $p;
602
+        if ($p < 1000)
603
+            $s = '';
604
+        else {
605
+            $s = sprintf("%d ", $x = floor($p/1000));
606
+            $p -= ($x*1000);
607
+        }
608
+        return $s . sprintf($s?"%07.3f ms":"%.3f ms", $p);
609
+    }
611 610
 }
612 611
 
613 612
 
@@ -615,16 +614,16 @@  discard block
 block discarded – undo
615 614
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
616 615
 // http://doc.spip.org/@spip_touch
617 616
 function spip_touch($fichier, $duree=0, $touch=true) {
618
-	if ($duree) {
619
-		clearstatcache();
620
-		if ((@$f=filemtime($fichier)) AND ($f >= time() - $duree))
621
-			return false;
622
-	}
623
-	if ($touch!==false) {
624
-		if (!@touch($fichier)) { spip_unlink($fichier); @touch($fichier); };
625
-		@chmod($fichier, _SPIP_CHMOD & ~0111);
626
-	}
627
-	return true;
617
+    if ($duree) {
618
+        clearstatcache();
619
+        if ((@$f=filemtime($fichier)) AND ($f >= time() - $duree))
620
+            return false;
621
+    }
622
+    if ($touch!==false) {
623
+        if (!@touch($fichier)) { spip_unlink($fichier); @touch($fichier); };
624
+        @chmod($fichier, _SPIP_CHMOD & ~0111);
625
+    }
626
+    return true;
628 627
 }
629 628
 
630 629
 // Ce declencheur de tache de fond, de l'espace prive (cf inc_presentation)
@@ -636,11 +635,11 @@  discard block
 block discarded – undo
636 635
 
637 636
 // http://doc.spip.org/@action_cron
638 637
 function action_cron() {
639
-	include_spip('inc/headers');
640
-	http_status(204); // No Content
641
-	header("Connection: close");
642
-	define('_DIRECT_CRON_FORCE',true);
643
-	cron();
638
+    include_spip('inc/headers');
639
+    http_status(204); // No Content
640
+    header("Connection: close");
641
+    define('_DIRECT_CRON_FORCE',true);
642
+    cron();
644 643
 }
645 644
 
646 645
 /**
@@ -660,19 +659,19 @@  discard block
 block discarded – undo
660 659
  * @return bool
661 660
  */
662 661
 function cron ($taches=array(), $taches_old= array()) {
663
-	// si pas en mode cron force, laisser tomber.
664
-	if (!defined('_DIRECT_CRON_FORCE')) return false;
665
-	if (!is_array($taches)) $taches = $taches_old; // compat anciens appels
666
-	// si taches a inserer en base et base inaccessible, laisser tomber
667
-	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
668
-	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
669
-	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
670
-	if ($taches AND count($taches) AND !spip_connect())  return false;
671
-	spip_log("cron !",'jq'._LOG_DEBUG);
672
-	if ($genie = charger_fonction('genie', 'inc', true)) {
673
-		return $genie($taches);
674
-	}
675
-	return false;
662
+    // si pas en mode cron force, laisser tomber.
663
+    if (!defined('_DIRECT_CRON_FORCE')) return false;
664
+    if (!is_array($taches)) $taches = $taches_old; // compat anciens appels
665
+    // si taches a inserer en base et base inaccessible, laisser tomber
666
+    // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
667
+    // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
668
+    // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
669
+    if ($taches AND count($taches) AND !spip_connect())  return false;
670
+    spip_log("cron !",'jq'._LOG_DEBUG);
671
+    if ($genie = charger_fonction('genie', 'inc', true)) {
672
+        return $genie($taches);
673
+    }
674
+    return false;
676 675
 }
677 676
 
678 677
 /**
@@ -698,8 +697,8 @@  discard block
 block discarded – undo
698 697
  *	id of job
699 698
  */
700 699
 function job_queue_add($function, $description, $arguments = array(), $file = '', $no_duplicate = FALSE, $time=0, $priority=0) {
701
-	include_spip('inc/queue');
702
-	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
700
+    include_spip('inc/queue');
701
+    return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
703 702
 }
704 703
 
705 704
 /**
@@ -709,8 +708,8 @@  discard block
 block discarded – undo
709 708
  * @return bool
710 709
  */
711 710
 function job_queue_remove($id_job){
712
-	include_spip('inc/queue');
713
-	return queue_remove_job($id_job);
711
+    include_spip('inc/queue');
712
+    return queue_remove_job($id_job);
714 713
 }
715 714
 
716 715
 /**
@@ -722,8 +721,8 @@  discard block
 block discarded – undo
722 721
  *  or an array of simple array to link multiples objet in one time
723 722
  */
724 723
 function job_queue_link($id_job,$objets){
725
-	include_spip('inc/queue');
726
-	return queue_link_job($id_job,$objets);
724
+    include_spip('inc/queue');
725
+    return queue_link_job($id_job,$objets);
727 726
 }
728 727
 
729 728
 
@@ -740,62 +739,62 @@  discard block
 block discarded – undo
740 739
  * @return int
741 740
  */
742 741
 function queue_sleep_time_to_next_job($force=null) {
743
-	static $queue_next_job_time = -1;
744
-	if ($force===true)
745
-		$queue_next_job_time = -1;
746
-	elseif ($force)
747
-		$queue_next_job_time = $force;
748
-
749
-	if ($queue_next_job_time==-1) {
750
-		define('_JQ_NEXT_JOB_TIME_FILENAME',_DIR_TMP . "job_queue_next.txt");
751
-		// utiliser un cache memoire si dispo
752
-		if (include_spip('inc/memoization') AND defined('_MEMOIZE_MEMORY') AND _MEMOIZE_MEMORY) {
753
-			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
754
-		}
755
-		else {
756
-			$queue_next_job_time = null;
757
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu))
758
-				$queue_next_job_time = intval($contenu);
759
-		}
760
-	}
761
-
762
-	if (is_null($queue_next_job_time))
763
-		return null;
764
-	if (!$_SERVER['REQUEST_TIME'])
765
-		$_SERVER['REQUEST_TIME'] = time();
766
-	return $queue_next_job_time-$_SERVER['REQUEST_TIME'];
742
+    static $queue_next_job_time = -1;
743
+    if ($force===true)
744
+        $queue_next_job_time = -1;
745
+    elseif ($force)
746
+        $queue_next_job_time = $force;
747
+
748
+    if ($queue_next_job_time==-1) {
749
+        define('_JQ_NEXT_JOB_TIME_FILENAME',_DIR_TMP . "job_queue_next.txt");
750
+        // utiliser un cache memoire si dispo
751
+        if (include_spip('inc/memoization') AND defined('_MEMOIZE_MEMORY') AND _MEMOIZE_MEMORY) {
752
+            $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
753
+        }
754
+        else {
755
+            $queue_next_job_time = null;
756
+            if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu))
757
+                $queue_next_job_time = intval($contenu);
758
+        }
759
+    }
760
+
761
+    if (is_null($queue_next_job_time))
762
+        return null;
763
+    if (!$_SERVER['REQUEST_TIME'])
764
+        $_SERVER['REQUEST_TIME'] = time();
765
+    return $queue_next_job_time-$_SERVER['REQUEST_TIME'];
767 766
 }
768 767
 
769 768
 
770 769
 // transformation XML des "&" en "&amp;"
771 770
 // http://doc.spip.org/@quote_amp
772 771
 function quote_amp($u) {
773
-	return preg_replace(
774
-		"/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,5};)/i",
775
-		"&amp;",$u);
772
+    return preg_replace(
773
+        "/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,5};)/i",
774
+        "&amp;",$u);
776 775
 }
777 776
 
778 777
 // Production d'une balise Script valide
779 778
 // http://doc.spip.org/@http_script
780 779
 function http_script($script, $src='', $noscript='') {
781
-	static $done = array();
782
-
783
-	if ($src && !isset($done[$src])){
784
-		$done[$src] = true;
785
-		$src = find_in_path($src, _JAVASCRIPT);
786
-		$src = " src='$src'";
787
-	}
788
-	else $src = '';
789
-	if ($script)
790
-		$script = ("/*<![CDATA[*/\n" .
791
-		preg_replace(',</([^>]*)>,','<\/\1>', $script) .
792
-		"/*]]>*/");
793
-	if ($noscript)
794
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
795
-
796
-	return ($src OR $script OR $noscript)
797
-	? "<script type='text/javascript'$src>$script</script>$noscript"
798
-	: '';
780
+    static $done = array();
781
+
782
+    if ($src && !isset($done[$src])){
783
+        $done[$src] = true;
784
+        $src = find_in_path($src, _JAVASCRIPT);
785
+        $src = " src='$src'";
786
+    }
787
+    else $src = '';
788
+    if ($script)
789
+        $script = ("/*<![CDATA[*/\n" .
790
+        preg_replace(',</([^>]*)>,','<\/\1>', $script) .
791
+        "/*]]>*/");
792
+    if ($noscript)
793
+        $noscript = "<noscript>\n\t$noscript\n</noscript>\n";
794
+
795
+    return ($src OR $script OR $noscript)
796
+    ? "<script type='text/javascript'$src>$script</script>$noscript"
797
+    : '';
799 798
 }
800 799
 
801 800
 // Transforme n'importe quel champ en une chaine utilisable
@@ -803,7 +802,7 @@  discard block
 block discarded – undo
803 802
 // < ? php $x = '[(#TEXTE|texte_script)]'; ? >
804 803
 // http://doc.spip.org/@texte_script
805 804
 function texte_script($texte) {
806
-	return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
805
+    return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
807 806
 }
808 807
 
809 808
 // Chaque appel a cette fonction ajoute un repertoire en tete du chemin courant (path)
@@ -814,107 +813,107 @@  discard block
 block discarded – undo
814 813
 // Exception: si un $dossier_squelette est defini, il reste en tete, pour raison historique
815 814
 // http://doc.spip.org/@_chemin
816 815
 function _chemin($dir_path=NULL){
817
-	static $path_base = NULL;
818
-	static $path_full = NULL;
819
-	if ($path_base==NULL){
820
-		// Chemin standard depuis l'espace public
821
-		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
822
-			_DIR_RACINE.':'.
823
-			_DIR_RACINE.'squelettes-dist/:'.
824
-			_DIR_RACINE.'prive/:'.
825
-			_DIR_RESTREINT;
826
-		// Ajouter squelettes/
827
-		if (@is_dir(_DIR_RACINE.'squelettes'))
828
-			$path = _DIR_RACINE.'squelettes/:' . $path;
829
-		foreach (explode(':', $path) as $dir) {
830
-			if (strlen($dir) AND substr($dir,-1) != '/')
831
-				$dir .= "/";
832
-			$path_base[] = $dir;
833
-		}
834
-		$path_full = $path_base;
835
-		// Et le(s) dossier(s) des squelettes nommes
836
-		if (strlen($GLOBALS['dossier_squelettes']))
837
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
838
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
839
-		$GLOBALS['path_sig'] = md5(serialize($path_full));
840
-	}
841
-	if ($dir_path===NULL) return $path_full;
842
-
843
-	if (strlen($dir_path)){
844
-		$tete = "";
845
-		if (reset($path_base)==_DIR_RACINE.'squelettes/')
846
-			$tete = array_shift($path_base);
847
-		$dirs = array_reverse(explode(':',$dir_path));
848
-		foreach($dirs as $dir_path){
849
-				#if ($dir_path{0}!='/')
850
-				#	$dir_path = $dir_path;
851
-				if (substr($dir_path,-1) != '/')
852
-					$dir_path .= "/";
853
-				if (!in_array($dir_path,$path_base))
854
-					array_unshift($path_base,$dir_path);
855
-		}
856
-		if (strlen($tete))
857
-			array_unshift($path_base,$tete);
858
-	}
859
-	$path_full = $path_base;
860
-	// Et le(s) dossier(s) des squelettes nommes
861
-	if (strlen($GLOBALS['dossier_squelettes']))
862
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
863
-			array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
864
-
865
-	$GLOBALS['path_sig'] = md5(serialize($path_full));
866
-	return $path_full;
816
+    static $path_base = NULL;
817
+    static $path_full = NULL;
818
+    if ($path_base==NULL){
819
+        // Chemin standard depuis l'espace public
820
+        $path = defined('_SPIP_PATH') ? _SPIP_PATH :
821
+            _DIR_RACINE.':'.
822
+            _DIR_RACINE.'squelettes-dist/:'.
823
+            _DIR_RACINE.'prive/:'.
824
+            _DIR_RESTREINT;
825
+        // Ajouter squelettes/
826
+        if (@is_dir(_DIR_RACINE.'squelettes'))
827
+            $path = _DIR_RACINE.'squelettes/:' . $path;
828
+        foreach (explode(':', $path) as $dir) {
829
+            if (strlen($dir) AND substr($dir,-1) != '/')
830
+                $dir .= "/";
831
+            $path_base[] = $dir;
832
+        }
833
+        $path_full = $path_base;
834
+        // Et le(s) dossier(s) des squelettes nommes
835
+        if (strlen($GLOBALS['dossier_squelettes']))
836
+            foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
837
+                array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
838
+        $GLOBALS['path_sig'] = md5(serialize($path_full));
839
+    }
840
+    if ($dir_path===NULL) return $path_full;
841
+
842
+    if (strlen($dir_path)){
843
+        $tete = "";
844
+        if (reset($path_base)==_DIR_RACINE.'squelettes/')
845
+            $tete = array_shift($path_base);
846
+        $dirs = array_reverse(explode(':',$dir_path));
847
+        foreach($dirs as $dir_path){
848
+                #if ($dir_path{0}!='/')
849
+                #	$dir_path = $dir_path;
850
+                if (substr($dir_path,-1) != '/')
851
+                    $dir_path .= "/";
852
+                if (!in_array($dir_path,$path_base))
853
+                    array_unshift($path_base,$dir_path);
854
+        }
855
+        if (strlen($tete))
856
+            array_unshift($path_base,$tete);
857
+    }
858
+    $path_full = $path_base;
859
+    // Et le(s) dossier(s) des squelettes nommes
860
+    if (strlen($GLOBALS['dossier_squelettes']))
861
+        foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
862
+            array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
863
+
864
+    $GLOBALS['path_sig'] = md5(serialize($path_full));
865
+    return $path_full;
867 866
 }
868 867
 
869 868
 // http://doc.spip.org/@creer_chemin
870 869
 function creer_chemin() {
871
-	$path_a = _chemin();
872
-	static $c = '';
870
+    $path_a = _chemin();
871
+    static $c = '';
873 872
 
874
-	// on calcule le chemin si le dossier skel a change
875
-	if ($c != $GLOBALS['dossier_squelettes']) {
876
-		// assurer le non plantage lors de la montee de version :
877
-		$c = $GLOBALS['dossier_squelettes'];
878
-		$path_a = _chemin(''); // forcer un recalcul du chemin
879
-	}
880
-	return $path_a;
873
+    // on calcule le chemin si le dossier skel a change
874
+    if ($c != $GLOBALS['dossier_squelettes']) {
875
+        // assurer le non plantage lors de la montee de version :
876
+        $c = $GLOBALS['dossier_squelettes'];
877
+        $path_a = _chemin(''); // forcer un recalcul du chemin
878
+    }
879
+    return $path_a;
881 880
 }
882 881
 
883 882
 
884 883
 function lister_themes_prives(){
885
-	static $themes = null;
886
-	if (is_null($themes)){
887
-		// si pas encore definie
888
-		if (!defined('_SPIP_THEME_PRIVE'))
889
-			define('_SPIP_THEME_PRIVE', 'spip');
890
-		$themes = array(_SPIP_THEME_PRIVE);
891
-		// lors d'une installation neuve, prefs n'est pas definie.
892
-		if (isset($GLOBALS['visiteur_session']['prefs'])) {
893
-			$prefs = $GLOBALS['visiteur_session']['prefs'];
894
-		} else {
895
-			$prefs = array();
896
-		}
897
-		if (is_string($prefs))
898
-			$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
899
-		if (
900
-			((isset($prefs['theme']) AND $theme = $prefs['theme'])
901
-			OR (isset($GLOBALS['theme_prive_defaut']) AND $theme = $GLOBALS['theme_prive_defaut']))
902
-			AND $theme != _SPIP_THEME_PRIVE)
903
-			array_unshift($themes,$theme); // placer le theme choisi en tete
904
-	}
905
-	return $themes;
884
+    static $themes = null;
885
+    if (is_null($themes)){
886
+        // si pas encore definie
887
+        if (!defined('_SPIP_THEME_PRIVE'))
888
+            define('_SPIP_THEME_PRIVE', 'spip');
889
+        $themes = array(_SPIP_THEME_PRIVE);
890
+        // lors d'une installation neuve, prefs n'est pas definie.
891
+        if (isset($GLOBALS['visiteur_session']['prefs'])) {
892
+            $prefs = $GLOBALS['visiteur_session']['prefs'];
893
+        } else {
894
+            $prefs = array();
895
+        }
896
+        if (is_string($prefs))
897
+            $prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
898
+        if (
899
+            ((isset($prefs['theme']) AND $theme = $prefs['theme'])
900
+            OR (isset($GLOBALS['theme_prive_defaut']) AND $theme = $GLOBALS['theme_prive_defaut']))
901
+            AND $theme != _SPIP_THEME_PRIVE)
902
+            array_unshift($themes,$theme); // placer le theme choisi en tete
903
+    }
904
+    return $themes;
906 905
 }
907 906
 
908 907
 function find_in_theme($file, $subdir='', $include=false){
909
-	static $themefiles=array();
910
-	if (isset($themefiles["$subdir$file"])) return $themefiles["$subdir$file"];
911
-	$themes = lister_themes_prives();
912
-	foreach($themes as $theme){
913
-		if ($f = find_in_path($file,"prive/themes/$theme/$subdir",$include))
914
-			return $themefiles["$subdir$file"] = $f;
915
-	}
916
-	spip_log("$file introuvable dans le theme prive ".reset($themes),'theme');
917
-	return $themefiles["$subdir$file"] = "";
908
+    static $themefiles=array();
909
+    if (isset($themefiles["$subdir$file"])) return $themefiles["$subdir$file"];
910
+    $themes = lister_themes_prives();
911
+    foreach($themes as $theme){
912
+        if ($f = find_in_path($file,"prive/themes/$theme/$subdir",$include))
913
+            return $themefiles["$subdir$file"] = $f;
914
+    }
915
+    spip_log("$file introuvable dans le theme prive ".reset($themes),'theme');
916
+    return $themefiles["$subdir$file"] = "";
918 917
 }
919 918
 
920 919
 // Cherche une image dans les dossiers images
@@ -924,22 +923,22 @@  discard block
 block discarded – undo
924 923
 // dans _DIR_IMG_PACK
925 924
 // http://doc.spip.org/@chemin_image
926 925
 function chemin_image($icone){
927
-	static $icone_renommer;
928
-	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
929
-	if (strpos($icone,"/")!==false AND file_exists($icone)) return $icone;
926
+    static $icone_renommer;
927
+    // gerer le cas d'un double appel en evitant de refaire le travail inutilement
928
+    if (strpos($icone,"/")!==false AND file_exists($icone)) return $icone;
930 929
 	
931
-	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
932
-	if (preg_match(',[.](png|gif|jpg)$,',$icone) AND $f = find_in_theme("images/$icone"))
933
-		return $f;
934
-	// sinon passer par le module de renommage
935
-	if (is_null($icone_renommer))
936
-		$icone_renommer = charger_fonction('icone_renommer','inc',true);
937
-	if ($icone_renommer){
938
-		list($icone,$fonction) = $icone_renommer($icone,"");
939
-		if (file_exists($icone))
940
-			return $icone;
941
-	}
942
-	return find_in_path ($icone, _NOM_IMG_PACK);
930
+    // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
931
+    if (preg_match(',[.](png|gif|jpg)$,',$icone) AND $f = find_in_theme("images/$icone"))
932
+        return $f;
933
+    // sinon passer par le module de renommage
934
+    if (is_null($icone_renommer))
935
+        $icone_renommer = charger_fonction('icone_renommer','inc',true);
936
+    if ($icone_renommer){
937
+        list($icone,$fonction) = $icone_renommer($icone,"");
938
+        if (file_exists($icone))
939
+            return $icone;
940
+    }
941
+    return find_in_path ($icone, _NOM_IMG_PACK);
943 942
 }
944 943
 
945 944
 //
@@ -951,109 +950,109 @@  discard block
 block discarded – undo
951 950
 
952 951
 // http://doc.spip.org/@find_in_path
953 952
 function find_in_path ($file, $dirname='', $include=false) {
954
-	static $dirs=array();
955
-	static $inc = array(); # cf http://trac.rezo.net/trac/spip/changeset/14743
956
-	static $c = '';
957
-
958
-	// on calcule le chemin si le dossier skel a change
959
-	if ($c != $GLOBALS['dossier_squelettes']){
960
-		// assurer le non plantage lors de la montee de version :
961
-		$c = $GLOBALS['dossier_squelettes'];
962
-		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
963
-	}
964
-
965
-	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
966
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])
967
-			return false;
968
-		if ($include AND !isset($inc[$dirname][$file])) {
969
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
970
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
971
-		}
972
-		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
973
-	}
974
-
975
-	$a = strrpos($file,'/');
976
-	if ($a !== false) {
977
-		$dirname .= substr($file, 0, ++$a);
978
-		$file = substr($file, $a);
979
-	}
980
-
981
-	foreach(creer_chemin() as $dir) {
982
-		if (!isset($dirs[$a = $dir . $dirname]))
983
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a) ;
984
-		if ($dirs[$a]) {
985
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
986
-				if ($include AND !isset($inc[$dirname][$file])) {
987
-					include_once _ROOT_CWD . $a;
988
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
989
-				}
990
-				if (!defined('_SAUVER_CHEMIN')){
991
-					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
992
-					if (is_null($GLOBALS['path_files'])) return $a;
993
-					define('_SAUVER_CHEMIN', true);
994
-				}
995
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
996
-			}
997
-		}
998
-	}
999
-
1000
-	if ($include){
1001
-		spip_log("include_spip $dirname$file non trouve");
1002
-		if ($include==='required'){
1003
-			echo '<pre>',
1004
-			"<strong>Erreur Fatale</strong><br />";
1005
-			if (function_exists('debug_print_backtrace'))
1006
-				echo debug_print_backtrace();
1007
-			echo '</pre>';
1008
-			die("Erreur interne: ne peut inclure $dirname$file");
1009
-		}
1010
-	}
1011
-
1012
-	if (!defined('_SAUVER_CHEMIN')){
1013
-		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1014
-		if (is_null($GLOBALS['path_files'])) return false;
1015
-		define('_SAUVER_CHEMIN', true);
1016
-	}
1017
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
953
+    static $dirs=array();
954
+    static $inc = array(); # cf http://trac.rezo.net/trac/spip/changeset/14743
955
+    static $c = '';
956
+
957
+    // on calcule le chemin si le dossier skel a change
958
+    if ($c != $GLOBALS['dossier_squelettes']){
959
+        // assurer le non plantage lors de la montee de version :
960
+        $c = $GLOBALS['dossier_squelettes'];
961
+        creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
962
+    }
963
+
964
+    if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
965
+        if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])
966
+            return false;
967
+        if ($include AND !isset($inc[$dirname][$file])) {
968
+            include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
969
+            $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
970
+        }
971
+        return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
972
+    }
973
+
974
+    $a = strrpos($file,'/');
975
+    if ($a !== false) {
976
+        $dirname .= substr($file, 0, ++$a);
977
+        $file = substr($file, $a);
978
+    }
979
+
980
+    foreach(creer_chemin() as $dir) {
981
+        if (!isset($dirs[$a = $dir . $dirname]))
982
+            $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a) ;
983
+        if ($dirs[$a]) {
984
+            if (file_exists(_ROOT_CWD . ($a .= $file))) {
985
+                if ($include AND !isset($inc[$dirname][$file])) {
986
+                    include_once _ROOT_CWD . $a;
987
+                    $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
988
+                }
989
+                if (!defined('_SAUVER_CHEMIN')){
990
+                    // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
991
+                    if (is_null($GLOBALS['path_files'])) return $a;
992
+                    define('_SAUVER_CHEMIN', true);
993
+                }
994
+                return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
995
+            }
996
+        }
997
+    }
998
+
999
+    if ($include){
1000
+        spip_log("include_spip $dirname$file non trouve");
1001
+        if ($include==='required'){
1002
+            echo '<pre>',
1003
+            "<strong>Erreur Fatale</strong><br />";
1004
+            if (function_exists('debug_print_backtrace'))
1005
+                echo debug_print_backtrace();
1006
+            echo '</pre>';
1007
+            die("Erreur interne: ne peut inclure $dirname$file");
1008
+        }
1009
+    }
1010
+
1011
+    if (!defined('_SAUVER_CHEMIN')){
1012
+        // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1013
+        if (is_null($GLOBALS['path_files'])) return false;
1014
+        define('_SAUVER_CHEMIN', true);
1015
+    }
1016
+    return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1018 1017
 }
1019 1018
 
1020 1019
 function clear_path_cache(){
1021
-	$GLOBALS['path_files'] = array();
1022
-	spip_unlink(_CACHE_CHEMIN);
1020
+    $GLOBALS['path_files'] = array();
1021
+    spip_unlink(_CACHE_CHEMIN);
1023 1022
 }
1024 1023
 function load_path_cache(){
1025
-	// charger le path des plugins
1026
-	if (@is_readable(_CACHE_PLUGINS_PATH)){
1027
-		include_once(_CACHE_PLUGINS_PATH);
1028
-	}
1029
-	$GLOBALS['path_files'] = array();
1030
-	// si le visiteur est admin,
1031
-	// on ne recharge pas le cache pour forcer sa mise a jour
1032
-	if (
1033
-		// la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1034
-		//AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1035
-		// utiliser le cookie est un pis aller qui marche 'en general'
1036
-		// on blinde par un second test au moment de la lecture de la session
1037
-		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1038
-		// et en ignorant ce cache en cas de recalcul explicite
1039
-		!_request('var_mode')
1040
-		){
1041
-		// on essaye de lire directement sans verrou pour aller plus vite
1042
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)){
1043
-			// mais si semble corrompu on relit avec un verrou
1044
-			if (!$GLOBALS['path_files']=unserialize($contenu)){
1045
-				lire_fichier(_CACHE_CHEMIN,$contenu);
1046
-				if (!$GLOBALS['path_files']=unserialize($contenu))
1047
-					$GLOBALS['path_files'] = array();
1048
-			}
1049
-		}
1050
-	}
1024
+    // charger le path des plugins
1025
+    if (@is_readable(_CACHE_PLUGINS_PATH)){
1026
+        include_once(_CACHE_PLUGINS_PATH);
1027
+    }
1028
+    $GLOBALS['path_files'] = array();
1029
+    // si le visiteur est admin,
1030
+    // on ne recharge pas le cache pour forcer sa mise a jour
1031
+    if (
1032
+        // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1033
+        //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1034
+        // utiliser le cookie est un pis aller qui marche 'en general'
1035
+        // on blinde par un second test au moment de la lecture de la session
1036
+        // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1037
+        // et en ignorant ce cache en cas de recalcul explicite
1038
+        !_request('var_mode')
1039
+        ){
1040
+        // on essaye de lire directement sans verrou pour aller plus vite
1041
+        if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)){
1042
+            // mais si semble corrompu on relit avec un verrou
1043
+            if (!$GLOBALS['path_files']=unserialize($contenu)){
1044
+                lire_fichier(_CACHE_CHEMIN,$contenu);
1045
+                if (!$GLOBALS['path_files']=unserialize($contenu))
1046
+                    $GLOBALS['path_files'] = array();
1047
+            }
1048
+        }
1049
+    }
1051 1050
 }
1052 1051
 
1053 1052
 function save_path_cache(){
1054
-	if (defined('_SAUVER_CHEMIN')
1055
-		AND _SAUVER_CHEMIN)
1056
-		ecrire_fichier(_CACHE_CHEMIN,serialize($GLOBALS['path_files']));
1053
+    if (defined('_SAUVER_CHEMIN')
1054
+        AND _SAUVER_CHEMIN)
1055
+        ecrire_fichier(_CACHE_CHEMIN,serialize($GLOBALS['path_files']));
1057 1056
 }
1058 1057
 
1059 1058
 
@@ -1069,25 +1068,25 @@  discard block
 block discarded – undo
1069 1068
  */
1070 1069
 // http://doc.spip.org/@find_all_in_path
1071 1070
 function find_all_in_path($dir,$pattern, $recurs=false){
1072
-	$liste_fichiers=array();
1073
-	$maxfiles = 10000;
1074
-
1075
-	// Parcourir le chemin
1076
-	foreach (creer_chemin() as $d) {
1077
-		$f = $d.$dir;
1078
-		if (@is_dir($f)){
1079
-			$liste = preg_files($f,$pattern,$maxfiles-count($liste_fichiers),$recurs===true?array():$recurs);
1080
-			foreach($liste as $chemin){
1081
-				$nom = basename($chemin);
1082
-				// ne prendre que les fichiers pas deja trouves
1083
-				// car find_in_path prend le premier qu'il trouve,
1084
-				// les autres sont donc masques
1085
-				if (!isset($liste_fichiers[$nom]))
1086
-					$liste_fichiers[$nom] = $chemin;
1087
-			}
1088
-		}
1089
-	}
1090
-	return $liste_fichiers;
1071
+    $liste_fichiers=array();
1072
+    $maxfiles = 10000;
1073
+
1074
+    // Parcourir le chemin
1075
+    foreach (creer_chemin() as $d) {
1076
+        $f = $d.$dir;
1077
+        if (@is_dir($f)){
1078
+            $liste = preg_files($f,$pattern,$maxfiles-count($liste_fichiers),$recurs===true?array():$recurs);
1079
+            foreach($liste as $chemin){
1080
+                $nom = basename($chemin);
1081
+                // ne prendre que les fichiers pas deja trouves
1082
+                // car find_in_path prend le premier qu'il trouve,
1083
+                // les autres sont donc masques
1084
+                if (!isset($liste_fichiers[$nom]))
1085
+                    $liste_fichiers[$nom] = $chemin;
1086
+            }
1087
+        }
1088
+    }
1089
+    return $liste_fichiers;
1091 1090
 }
1092 1091
 
1093 1092
 // predicat sur les scripts de ecrire qui n'authentifient pas par cookie
@@ -1095,9 +1094,9 @@  discard block
 block discarded – undo
1095 1094
 // http://doc.spip.org/@autoriser_sans_cookie
1096 1095
 function autoriser_sans_cookie($nom)
1097 1096
 {
1098
-  static $autsanscookie = array('install', 'base_repair');
1099
-  $nom = preg_replace('/.php[3]?$/', '', basename($nom));
1100
-  return in_array($nom, $autsanscookie);
1097
+    static $autsanscookie = array('install', 'base_repair');
1098
+    $nom = preg_replace('/.php[3]?$/', '', basename($nom));
1099
+    return in_array($nom, $autsanscookie);
1101 1100
 }
1102 1101
 
1103 1102
 /**
@@ -1126,112 +1125,112 @@  discard block
 block discarded – undo
1126 1125
  */
1127 1126
 function generer_url_entite($id='', $entite='', $args='', $ancre='', $public=NULL, $type=NULL)
1128 1127
 {
1129
-	if ($public === NULL) $public = !test_espace_prive();
1130
-	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1131
-
1132
-	if (!$public) {
1133
-		if (!$entite) return '';
1134
-		if (!function_exists('generer_url_ecrire_objet'))
1135
-			include_spip('inc/urls');
1136
-		$res = generer_url_ecrire_objet($entite,$id, $args, $ancre, false);
1137
-	} else {
1138
-		if ($type === NULL) {
1139
-			$type = ($GLOBALS['type_urls'] === 'page'
1140
-				AND $GLOBALS['meta']['type_urls'])
1141
-			?  $GLOBALS['meta']['type_urls']
1142
-			:  $GLOBALS['type_urls']; // pour SPIP <2
1143
-		}
1144
-
1145
-		$f = charger_fonction($type, 'urls', true);
1146
-		// se rabattre sur les urls page si les urls perso non dispo
1147
-		if (!$f) $f = charger_fonction('page', 'urls', true);
1148
-
1149
-		// si $entite='', on veut la fonction de passage URL ==> id
1150
-		// sinon on veut effectuer le passage id ==> URL
1151
-		if (!$entite) return $f;
1152
-
1153
-		// mais d'abord il faut tester le cas des urls sur une
1154
-		// base distante
1155
-		if (is_string($public)
1156
-		AND $g = charger_fonction('connect', 'urls', true))
1157
-			$f = $g;
1158
-
1159
-		$res = $f(intval($id), $entite, $args, $ancre, $public);
1160
-
1161
-	}
1162
-	if ($res) return $res;
1163
-	// Sinon c'est un raccourci ou compat SPIP < 2
1164
-	if (!function_exists($f = 'generer_url_' . $entite)) {
1165
-		if (!function_exists($f .= '_dist')) $f = '';
1166
-	}
1167
-	if ($f) {
1168
-		$url = $f($id, $args, $ancre);
1169
-		if (strlen($args))
1170
-			$url .= strstr($url, '?')
1171
-				? '&amp;'.$args
1172
-				: '?'.$args;
1173
-		return $url;
1174
-	}
1175
-	// On a ete gentil mais la ....
1176
-	spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public");
1177
-	return '';
1128
+    if ($public === NULL) $public = !test_espace_prive();
1129
+    $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1130
+
1131
+    if (!$public) {
1132
+        if (!$entite) return '';
1133
+        if (!function_exists('generer_url_ecrire_objet'))
1134
+            include_spip('inc/urls');
1135
+        $res = generer_url_ecrire_objet($entite,$id, $args, $ancre, false);
1136
+    } else {
1137
+        if ($type === NULL) {
1138
+            $type = ($GLOBALS['type_urls'] === 'page'
1139
+                AND $GLOBALS['meta']['type_urls'])
1140
+            ?  $GLOBALS['meta']['type_urls']
1141
+            :  $GLOBALS['type_urls']; // pour SPIP <2
1142
+        }
1143
+
1144
+        $f = charger_fonction($type, 'urls', true);
1145
+        // se rabattre sur les urls page si les urls perso non dispo
1146
+        if (!$f) $f = charger_fonction('page', 'urls', true);
1147
+
1148
+        // si $entite='', on veut la fonction de passage URL ==> id
1149
+        // sinon on veut effectuer le passage id ==> URL
1150
+        if (!$entite) return $f;
1151
+
1152
+        // mais d'abord il faut tester le cas des urls sur une
1153
+        // base distante
1154
+        if (is_string($public)
1155
+        AND $g = charger_fonction('connect', 'urls', true))
1156
+            $f = $g;
1157
+
1158
+        $res = $f(intval($id), $entite, $args, $ancre, $public);
1159
+
1160
+    }
1161
+    if ($res) return $res;
1162
+    // Sinon c'est un raccourci ou compat SPIP < 2
1163
+    if (!function_exists($f = 'generer_url_' . $entite)) {
1164
+        if (!function_exists($f .= '_dist')) $f = '';
1165
+    }
1166
+    if ($f) {
1167
+        $url = $f($id, $args, $ancre);
1168
+        if (strlen($args))
1169
+            $url .= strstr($url, '?')
1170
+                ? '&amp;'.$args
1171
+                : '?'.$args;
1172
+        return $url;
1173
+    }
1174
+    // On a ete gentil mais la ....
1175
+    spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public");
1176
+    return '';
1178 1177
 }
1179 1178
 
1180 1179
 function generer_url_ecrire_entite_edit($id, $entite, $args='', $ancre=''){
1181
-	$exec = objet_info($entite,'url_edit');
1182
-	$url = generer_url_ecrire($exec,$args);
1183
-	if (intval($id))
1184
-		$url = parametre_url($url,id_table_objet($entite),$id);
1185
-	else
1186
-		$url = parametre_url($url,'new','oui');
1187
-	if ($ancre)
1188
-		$url = ancre_url($url,$ancre);
1189
-	return $url;
1180
+    $exec = objet_info($entite,'url_edit');
1181
+    $url = generer_url_ecrire($exec,$args);
1182
+    if (intval($id))
1183
+        $url = parametre_url($url,id_table_objet($entite),$id);
1184
+    else
1185
+        $url = parametre_url($url,'new','oui');
1186
+    if ($ancre)
1187
+        $url = ancre_url($url,$ancre);
1188
+    return $url;
1190 1189
 }
1191 1190
 
1192 1191
 // http://doc.spip.org/@urls_connect_dist
1193 1192
 function urls_connect_dist($i, &$entite, $args='', $ancre='', $public=null) {
1194
-	include_spip('base/connect_sql');
1195
-	$id_type = id_table_objet($entite,$public);
1196
-	return _DIR_RACINE . get_spip_script('./')
1197
-	  . "?"._SPIP_PAGE."=$entite&$id_type=$i&connect=$public"
1198
-	  . (!$args ? '' : "&$args")
1199
-	  . (!$ancre ? '' : "#$ancre");
1193
+    include_spip('base/connect_sql');
1194
+    $id_type = id_table_objet($entite,$public);
1195
+    return _DIR_RACINE . get_spip_script('./')
1196
+        . "?"._SPIP_PAGE."=$entite&$id_type=$i&connect=$public"
1197
+        . (!$args ? '' : "&$args")
1198
+        . (!$ancre ? '' : "#$ancre");
1200 1199
 }
1201 1200
 
1202 1201
 
1203 1202
 // Transformer les caracteres utf8 d'une URL (farsi par ex) selon la RFC 1738
1204 1203
 function urlencode_1738($url) {
1205
-	if (preg_match(',[^\x00-\x7E],sS', $url)){
1206
-		$uri = '';
1207
-		for ($i=0; $i < strlen($url); $i++) {
1208
-			if (ord($a = $url[$i]) > 127)
1209
-				$a = rawurlencode($a);
1210
-			$uri .= $a;
1211
-		}
1212
-		$url = $uri;
1213
-	}
1214
-	return quote_amp($url);
1204
+    if (preg_match(',[^\x00-\x7E],sS', $url)){
1205
+        $uri = '';
1206
+        for ($i=0; $i < strlen($url); $i++) {
1207
+            if (ord($a = $url[$i]) > 127)
1208
+                $a = rawurlencode($a);
1209
+            $uri .= $a;
1210
+        }
1211
+        $url = $uri;
1212
+    }
1213
+    return quote_amp($url);
1215 1214
 }
1216 1215
 
1217 1216
 // http://doc.spip.org/@generer_url_entite_absolue
1218 1217
 function generer_url_entite_absolue($id='', $entite='', $args='', $ancre='', $connect=NULL)
1219 1218
 {
1220
-	if (!$connect) $connect = true;
1221
-	$h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1222
-	if (!preg_match(',^\w+:,', $h)) {
1223
-		include_spip('inc/filtres_mini');
1224
-		$h = url_absolue($h);
1225
-	}
1226
-	return  $h;
1219
+    if (!$connect) $connect = true;
1220
+    $h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1221
+    if (!preg_match(',^\w+:,', $h)) {
1222
+        include_spip('inc/filtres_mini');
1223
+        $h = url_absolue($h);
1224
+    }
1225
+    return  $h;
1227 1226
 }
1228 1227
 
1229 1228
 // Sur certains serveurs, la valeur 'Off' tient lieu de false dans certaines
1230 1229
 // variables d'environnement comme $_SERVER[HTTPS] ou ini_get(register_globals)
1231 1230
 // http://doc.spip.org/@test_valeur_serveur
1232 1231
 function test_valeur_serveur($truc) {
1233
-	if (!$truc) return false;
1234
-	return (strtolower($truc) !== 'off');
1232
+    if (!$truc) return false;
1233
+    return (strtolower($truc) !== 'off');
1235 1234
 }
1236 1235
 
1237 1236
 //
@@ -1256,51 +1255,51 @@  discard block
 block discarded – undo
1256 1255
  */
1257 1256
 function url_de_base($profondeur=null) {
1258 1257
 
1259
-	static $url = array();
1260
-	if (is_array($profondeur)) return $url = $profondeur;
1261
-	if ($profondeur===false) return $url;
1262
-
1263
-	if (is_null($profondeur)) $profondeur = $GLOBALS['profondeur_url'];
1264
-
1265
-	if (isset($url[$profondeur]))
1266
-		return $url[$profondeur];
1267
-
1268
-	$http = (
1269
-		(isset($_SERVER["SCRIPT_URI"]) AND
1270
-			substr($_SERVER["SCRIPT_URI"],0,5) == 'https')
1271
-		OR (isset($_SERVER['HTTPS']) AND
1272
-		    test_valeur_serveur($_SERVER['HTTPS']))
1273
-	) ? 'https' : 'http';
1274
-	// note : HTTP_HOST contient le :port si necessaire
1275
-	$host = $_SERVER['HTTP_HOST'];
1276
-	// si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
1277
-	if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
1278
-		$host = $GLOBALS['meta']['adresse_site'];
1279
-		if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
1280
-			$http = $scheme;
1281
-			$host = str_replace("{$scheme}://", '', $host);
1282
-		}
1283
-	}
1284
-	if (isset($_SERVER['SERVER_PORT'])
1285
-		AND $port=$_SERVER['SERVER_PORT']
1286
-		AND strpos($host,":")==false){
1287
-		if ($http=="http" AND $port!=80) $host.=":$port";
1288
-		if ($http=="https" AND $port!=443) $host.=":$port";
1289
-	}
1290
-	if (!$GLOBALS['REQUEST_URI']){
1291
-		if (isset($_SERVER['REQUEST_URI'])) {
1292
-			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1293
-		} else {
1294
-			$GLOBALS['REQUEST_URI'] = $_SERVER['PHP_SELF'];
1295
-			if ($_SERVER['QUERY_STRING']
1296
-			AND !strpos($_SERVER['REQUEST_URI'], '?'))
1297
-				$GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
1298
-		}
1299
-	}
1300
-
1301
-	$url[$profondeur] = url_de_($http,$host,$GLOBALS['REQUEST_URI'],$profondeur);
1302
-
1303
-	return $url[$profondeur];
1258
+    static $url = array();
1259
+    if (is_array($profondeur)) return $url = $profondeur;
1260
+    if ($profondeur===false) return $url;
1261
+
1262
+    if (is_null($profondeur)) $profondeur = $GLOBALS['profondeur_url'];
1263
+
1264
+    if (isset($url[$profondeur]))
1265
+        return $url[$profondeur];
1266
+
1267
+    $http = (
1268
+        (isset($_SERVER["SCRIPT_URI"]) AND
1269
+            substr($_SERVER["SCRIPT_URI"],0,5) == 'https')
1270
+        OR (isset($_SERVER['HTTPS']) AND
1271
+            test_valeur_serveur($_SERVER['HTTPS']))
1272
+    ) ? 'https' : 'http';
1273
+    // note : HTTP_HOST contient le :port si necessaire
1274
+    $host = $_SERVER['HTTP_HOST'];
1275
+    // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
1276
+    if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
1277
+        $host = $GLOBALS['meta']['adresse_site'];
1278
+        if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
1279
+            $http = $scheme;
1280
+            $host = str_replace("{$scheme}://", '', $host);
1281
+        }
1282
+    }
1283
+    if (isset($_SERVER['SERVER_PORT'])
1284
+        AND $port=$_SERVER['SERVER_PORT']
1285
+        AND strpos($host,":")==false){
1286
+        if ($http=="http" AND $port!=80) $host.=":$port";
1287
+        if ($http=="https" AND $port!=443) $host.=":$port";
1288
+    }
1289
+    if (!$GLOBALS['REQUEST_URI']){
1290
+        if (isset($_SERVER['REQUEST_URI'])) {
1291
+            $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1292
+        } else {
1293
+            $GLOBALS['REQUEST_URI'] = $_SERVER['PHP_SELF'];
1294
+            if ($_SERVER['QUERY_STRING']
1295
+            AND !strpos($_SERVER['REQUEST_URI'], '?'))
1296
+                $GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
1297
+        }
1298
+    }
1299
+
1300
+    $url[$profondeur] = url_de_($http,$host,$GLOBALS['REQUEST_URI'],$profondeur);
1301
+
1302
+    return $url[$profondeur];
1304 1303
 }
1305 1304
 /**
1306 1305
  * fonction testable de construction d'une url appelee par url_de_base()
@@ -1311,25 +1310,25 @@  discard block
 block discarded – undo
1311 1310
  * @return string
1312 1311
  */
1313 1312
 function url_de_($http,$host,$request,$prof=0){
1314
-	$prof = max($prof,0);
1313
+    $prof = max($prof,0);
1315 1314
 
1316
-	$myself = ltrim($request,'/');
1317
-	# supprimer la chaine de GET
1318
-	list($myself) = explode('?', $myself);
1319
-	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
1320
-	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
1321
-	if (strpos($myself,'://') !== false) {
1322
-		$myself = explode('://',$myself);
1323
-		array_shift($myself);
1324
-		$myself = implode('://',$myself);
1325
-		$myself = explode('/',$myself);
1326
-		array_shift($myself);
1327
-		$myself = implode('/',$myself);
1328
-	}
1329
-	$url = join('/', array_slice(explode('/', $myself), 0, -1-$prof)).'/';
1315
+    $myself = ltrim($request,'/');
1316
+    # supprimer la chaine de GET
1317
+    list($myself) = explode('?', $myself);
1318
+    // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
1319
+    // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
1320
+    if (strpos($myself,'://') !== false) {
1321
+        $myself = explode('://',$myself);
1322
+        array_shift($myself);
1323
+        $myself = implode('://',$myself);
1324
+        $myself = explode('/',$myself);
1325
+        array_shift($myself);
1326
+        $myself = implode('/',$myself);
1327
+    }
1328
+    $url = join('/', array_slice(explode('/', $myself), 0, -1-$prof)).'/';
1330 1329
 
1331
-	$url = $http.'://'.rtrim($host,'/').'/'.ltrim($url,'/');
1332
-	return $url;
1330
+    $url = $http.'://'.rtrim($host,'/').'/'.ltrim($url,'/');
1331
+    return $url;
1333 1332
 }
1334 1333
 
1335 1334
 
@@ -1343,25 +1342,25 @@  discard block
 block discarded – undo
1343 1342
 
1344 1343
 // http://doc.spip.org/@generer_url_ecrire
1345 1344
 function generer_url_ecrire($script='', $args="", $no_entities=false, $rel=false) {
1346
-	if (!$rel)
1347
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
1348
-	else if (!is_string($rel))
1349
-		$rel = _DIR_RESTREINT ? _DIR_RESTREINT :
1350
-			('./'  . _SPIP_ECRIRE_SCRIPT);
1345
+    if (!$rel)
1346
+        $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
1347
+    else if (!is_string($rel))
1348
+        $rel = _DIR_RESTREINT ? _DIR_RESTREINT :
1349
+            ('./'  . _SPIP_ECRIRE_SCRIPT);
1351 1350
 
1352
-	@list($script, $ancre) = explode('#', $script);
1353
-	if ($script AND ($script<>'accueil' OR $rel))
1354
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
1355
-	elseif ($args)
1356
-		$args ="?$args";
1357
-	if ($ancre) $args .= "#$ancre";
1358
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
1351
+    @list($script, $ancre) = explode('#', $script);
1352
+    if ($script AND ($script<>'accueil' OR $rel))
1353
+        $args = "?exec=$script" . (!$args ? '' : "&$args");
1354
+    elseif ($args)
1355
+        $args ="?$args";
1356
+    if ($ancre) $args .= "#$ancre";
1357
+    return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
1359 1358
 }
1360 1359
 
1361 1360
 // http://doc.spip.org/@generer_url_retour
1362 1361
 function generer_url_retour($script, $args="")
1363 1362
 {
1364
-	return rawurlencode(generer_url_ecrire($script, $args, true, true));
1363
+    return rawurlencode(generer_url_ecrire($script, $args, true, true));
1365 1364
 }
1366 1365
 
1367 1366
 //
@@ -1372,42 +1371,42 @@  discard block
 block discarded – undo
1372 1371
 // dans le cas de '', un $default = './' peut servir (comme dans urls/page.php)
1373 1372
 // http://doc.spip.org/@get_spip_script
1374 1373
 function get_spip_script($default='') {
1375
-	# cas define('_SPIP_SCRIPT', '');
1376
-	if (_SPIP_SCRIPT)
1377
-		return _SPIP_SCRIPT;
1378
-	else
1379
-		return $default;
1374
+    # cas define('_SPIP_SCRIPT', '');
1375
+    if (_SPIP_SCRIPT)
1376
+        return _SPIP_SCRIPT;
1377
+    else
1378
+        return $default;
1380 1379
 }
1381 1380
 
1382 1381
 // http://doc.spip.org/@generer_url_public
1383 1382
 function generer_url_public($script='', $args="", $no_entities=false, $rel=true, $action='') {
1384
-	// si le script est une action (spip_pass, spip_inscription),
1385
-	// standardiser vers la nouvelle API
1383
+    // si le script est une action (spip_pass, spip_inscription),
1384
+    // standardiser vers la nouvelle API
1386 1385
 
1387
-	if (!$action) $action = get_spip_script();
1388
-	if ($script)
1389
-		$action = parametre_url($action, _SPIP_PAGE, $script, '&');
1386
+    if (!$action) $action = get_spip_script();
1387
+    if ($script)
1388
+        $action = parametre_url($action, _SPIP_PAGE, $script, '&');
1390 1389
 
1391
-	if ($args) {
1392
-		if (is_array($args)) {
1393
-			$r = '';
1394
-			foreach($args as $k => $v) $r .= '&' . $k . '=' . $v;
1395
-			$args = substr($r,1);
1396
-		}
1397
-		$action .=
1398
-			(strpos($action, '?') !== false ? '&' : '?') . $args;
1399
-	}
1400
-	if (!$no_entities)
1401
-		$action = quote_amp($action);
1390
+    if ($args) {
1391
+        if (is_array($args)) {
1392
+            $r = '';
1393
+            foreach($args as $k => $v) $r .= '&' . $k . '=' . $v;
1394
+            $args = substr($r,1);
1395
+        }
1396
+        $action .=
1397
+            (strpos($action, '?') !== false ? '&' : '?') . $args;
1398
+    }
1399
+    if (!$no_entities)
1400
+        $action = quote_amp($action);
1402 1401
 
1403
-	// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
1404
-	return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(),'/') . preg_replace(",^/[.]/,","/","/$action"));
1402
+    // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
1403
+    return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(),'/') . preg_replace(",^/[.]/,","/","/$action"));
1405 1404
 }
1406 1405
 
1407 1406
 // http://doc.spip.org/@generer_url_prive
1408 1407
 function generer_url_prive($script, $args="", $no_entities=false) {
1409 1408
 
1410
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS .  'prive.php');
1409
+    return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS .  'prive.php');
1411 1410
 }
1412 1411
 
1413 1412
 // Pour les formulaires en methode POST,
@@ -1417,21 +1416,21 @@  discard block
 block discarded – undo
1417 1416
 
1418 1417
 // http://doc.spip.org/@generer_form_ecrire
1419 1418
 function generer_form_ecrire($script, $corps, $atts='', $submit='') {
1420
-	global $spip_lang_right;
1419
+    global $spip_lang_right;
1421 1420
 
1422
-	$script1 = explode('&', $script);
1423
-	$script1 = reset($script1);
1421
+    $script1 = explode('&', $script);
1422
+    $script1 = reset($script1);
1424 1423
 
1425
-	return "<form action='"
1426
-	. ($script ? generer_url_ecrire($script) : '')
1427
-	. "' "
1428
-	. ($atts ? $atts : " method='post'")
1429
-	.  "><div>\n"
1430
-	. "<input type='hidden' name='exec' value='$script1' />"
1431
-	. $corps
1432
-	. (!$submit ? '' :
1433
-	     ("<div style='text-align: $spip_lang_right'><input class='fondo' type='submit' value=\"".entites_html($submit)."\" /></div>"))
1434
-	. "</div></form>\n";
1424
+    return "<form action='"
1425
+    . ($script ? generer_url_ecrire($script) : '')
1426
+    . "' "
1427
+    . ($atts ? $atts : " method='post'")
1428
+    .  "><div>\n"
1429
+    . "<input type='hidden' name='exec' value='$script1' />"
1430
+    . $corps
1431
+    . (!$submit ? '' :
1432
+         ("<div style='text-align: $spip_lang_right'><input class='fondo' type='submit' value=\"".entites_html($submit)."\" /></div>"))
1433
+    . "</div></form>\n";
1435 1434
 }
1436 1435
 
1437 1436
 /**
@@ -1449,37 +1448,37 @@  discard block
 block discarded – undo
1449 1448
  * @return string
1450 1449
  */
1451 1450
 function generer_form_action($script, $corps, $atts='', $public=false) {
1452
-	// si l'on est dans l'espace prive, on garde dans l'url
1453
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
1454
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
1455
-	$h = (_DIR_RACINE AND !$public)
1456
-	? generer_url_ecrire(_request('exec'))
1457
-	: generer_url_public();
1458
-
1459
-	return "\n<form action='" .
1460
-	  $h .
1461
-	  "'" .
1462
-	  $atts .
1463
-	  ">\n" .
1464
-	  "<div>" .
1465
-  	  "\n<input type='hidden' name='action' value='$script' />" .
1466
-	  $corps .
1467
-	  "</div></form>";
1451
+    // si l'on est dans l'espace prive, on garde dans l'url
1452
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
1453
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
1454
+    $h = (_DIR_RACINE AND !$public)
1455
+    ? generer_url_ecrire(_request('exec'))
1456
+    : generer_url_public();
1457
+
1458
+    return "\n<form action='" .
1459
+        $h .
1460
+        "'" .
1461
+        $atts .
1462
+        ">\n" .
1463
+        "<div>" .
1464
+        "\n<input type='hidden' name='action' value='$script' />" .
1465
+        $corps .
1466
+        "</div></form>";
1468 1467
 }
1469 1468
 
1470 1469
 // http://doc.spip.org/@generer_url_action
1471 1470
 function generer_url_action($script, $args="", $no_entities=false , $public = false) {
1472
-	// si l'on est dans l'espace prive, on garde dans l'url
1473
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
1474
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
1475
-	$url = (_DIR_RACINE  AND !$public)
1476
-	  ? generer_url_ecrire(_request('exec'))
1477
-	  :  generer_url_public('','',false,false);
1478
-	$url = parametre_url($url,'action',$script);
1479
-	if ($args) $url .= quote_amp('&'.$args);
1471
+    // si l'on est dans l'espace prive, on garde dans l'url
1472
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
1473
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
1474
+    $url = (_DIR_RACINE  AND !$public)
1475
+      ? generer_url_ecrire(_request('exec'))
1476
+      :  generer_url_public('','',false,false);
1477
+    $url = parametre_url($url,'action',$script);
1478
+    if ($args) $url .= quote_amp('&'.$args);
1480 1479
 
1481
-	if ($no_entities) $url = str_replace('&amp;','&',$url);
1482
-	return $url;
1480
+    if ($no_entities) $url = str_replace('&amp;','&',$url);
1481
+    return $url;
1483 1482
 }
1484 1483
 
1485 1484
 
@@ -1492,8 +1491,8 @@  discard block
 block discarded – undo
1492 1491
  * @param string $ta
1493 1492
  */
1494 1493
 function spip_initialisation($pi=NULL, $pa=NULL, $ti=NULL, $ta=NULL) {
1495
-	spip_initialisation_core($pi,$pa,$ti,$ta);
1496
-	spip_initialisation_suite();
1494
+    spip_initialisation_core($pi,$pa,$ti,$ta);
1495
+    spip_initialisation_suite();
1497 1496
 }
1498 1497
 
1499 1498
 /**
@@ -1511,235 +1510,235 @@  discard block
 block discarded – undo
1511 1510
  * @param string $ta
1512 1511
  */
1513 1512
 function spip_initialisation_core($pi=NULL, $pa=NULL, $ti=NULL, $ta=NULL) {
1514
-	static $too_late = 0;
1515
-	if ($too_late++) return;
1513
+    static $too_late = 0;
1514
+    if ($too_late++) return;
1516 1515
 	
1517
-	// Declaration des repertoires
1516
+    // Declaration des repertoires
1518 1517
 
1519
-	// le nom du repertoire plugins/ activables/desactivables
1520
-	if (!defined('_DIR_PLUGINS')) define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
1518
+    // le nom du repertoire plugins/ activables/desactivables
1519
+    if (!defined('_DIR_PLUGINS')) define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
1521 1520
 
1522
-	// le nom du repertoire des extensions/ permanentes du core, toujours actives
1523
-	if (!defined('_DIR_PLUGINS_DIST')) define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
1521
+    // le nom du repertoire des extensions/ permanentes du core, toujours actives
1522
+    if (!defined('_DIR_PLUGINS_DIST')) define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
1524 1523
 
1525
-	// le nom du repertoire des librairies
1526
-	if (!defined('_DIR_LIB')) define('_DIR_LIB', _DIR_RACINE . "lib/");
1524
+    // le nom du repertoire des librairies
1525
+    if (!defined('_DIR_LIB')) define('_DIR_LIB', _DIR_RACINE . "lib/");
1527 1526
 	
1528
-	if (!defined('_DIR_IMG')) define('_DIR_IMG', $pa);
1529
-	if (!defined('_DIR_LOGOS')) define('_DIR_LOGOS', $pa);
1530
-	if (!defined('_DIR_IMG_ICONES')) define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
1531
-
1532
-	if (!defined('_DIR_DUMP')) define('_DIR_DUMP', $ti . "dump/");
1533
-	if (!defined('_DIR_SESSIONS')) define('_DIR_SESSIONS', $ti . "sessions/");
1534
-	if (!defined('_DIR_TRANSFERT')) define('_DIR_TRANSFERT', $ti . "upload/");
1535
-	if (!defined('_DIR_CACHE')) define('_DIR_CACHE', $ti . "cache/");
1536
-	if (!defined('_DIR_CACHE_XML')) define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
1537
-	if (!defined('_DIR_SKELS')) define('_DIR_SKELS',  _DIR_CACHE . "skel/");
1538
-	if (!defined('_DIR_AIDE')) define('_DIR_AIDE',  _DIR_CACHE . "aide/");
1539
-	if (!defined('_DIR_TMP')) define('_DIR_TMP', $ti);
1540
-
1541
-	if (!defined('_DIR_VAR')) define('_DIR_VAR', $ta);
1542
-
1543
-	if (!defined('_DIR_ETC')) define('_DIR_ETC', $pi);
1544
-	if (!defined('_DIR_CONNECT')) define('_DIR_CONNECT', $pi);
1545
-	if (!defined('_DIR_CHMOD')) define('_DIR_CHMOD', $pi);
1546
-
1547
-	if (!isset($GLOBALS['test_dirs']))
1548
-	  // Pas $pi car il est bon de le mettre hors ecriture apres intstall
1549
-	  // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
1550
-		$GLOBALS['test_dirs'] =  array($pa, $ti, $ta);
1551
-
1552
-	// Declaration des fichiers
1553
-
1554
-	if (!defined('_CACHE_PLUGINS_PATH')) define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
1555
-	if (!defined('_CACHE_PLUGINS_OPT')) define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
1556
-	if (!defined('_CACHE_PLUGINS_FCT')) define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
1557
-	if (!defined('_CACHE_PIPELINES')) define('_CACHE_PIPELINES',  _DIR_CACHE."charger_pipelines.php");
1558
-	if (!defined('_CACHE_CHEMIN')) define('_CACHE_CHEMIN',  _DIR_CACHE."chemin.txt");
1559
-
1560
-	# attention .php obligatoire pour ecrire_fichier_securise
1561
-	if (!defined('_FILE_META')) define('_FILE_META', $ti . 'meta_cache.php');
1562
-	if (!defined('_DIR_LOG')) define('_DIR_LOG', _DIR_TMP . 'log/');
1563
-	if (!defined('_FILE_LOG')) define('_FILE_LOG', 'spip');
1564
-	if (!defined('_FILE_LOG_SUFFIX')) define('_FILE_LOG_SUFFIX', '.log');
1565
-
1566
-	// Le fichier de connexion a la base de donnees
1567
-	// tient compte des anciennes versions (inc_connect...)
1568
-	if (!defined('_FILE_CONNECT_INS')) define('_FILE_CONNECT_INS', 'connect');
1569
-	if (!defined('_FILE_CONNECT')) define('_FILE_CONNECT',
1570
-		(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
1571
-	:	(@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
1572
-	:	false)));
1573
-
1574
-	// Le fichier de reglages des droits
1575
-	if (!defined('_FILE_CHMOD_INS')) define('_FILE_CHMOD_INS', 'chmod');
1576
-	if (!defined('_FILE_CHMOD')) define('_FILE_CHMOD',
1577
-		(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
1578
-	:	false));
1579
-
1580
-	if (!defined('_FILE_LDAP')) define('_FILE_LDAP', 'ldap.php');
1581
-
1582
-	if (!defined('_FILE_TMP_SUFFIX')) define('_FILE_TMP_SUFFIX', '.tmp.php');
1583
-	if (!defined('_FILE_CONNECT_TMP')) define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
1584
-	if (!defined('_FILE_CHMOD_TMP')) define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
1585
-
1586
-	// Definition des droits d'acces en ecriture
1587
-	if (!defined('_SPIP_CHMOD') AND _FILE_CHMOD)
1588
-		include_once _FILE_CHMOD;
1589
-
1590
-	// Se mefier des fichiers mal remplis!
1591
-	if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', 0777);
1592
-
1593
-	// Le charset par defaut lors de l'installation
1594
-	if (!defined('_DEFAULT_CHARSET')) define('_DEFAULT_CHARSET', 'utf-8');
1595
-	if (!defined('_ROOT_PLUGINS')) define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
1596
-	if (!defined('_ROOT_PLUGINS_DIST')) define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
1597
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE,'',_DIR_PLUGINS_SUPPL));
1598
-
1599
-	// La taille des Log
1600
-	if (!defined('_MAX_LOG')) define('_MAX_LOG', 100);
1601
-
1602
-	// Sommes-nous dans l'empire du Mal ?
1603
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
1604
-	if (strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false){
1605
-		if (!defined('_OS_SERVEUR')) define('_OS_SERVEUR', 'windows');
1606
-		if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',1); // utiliser le flock php
1607
-	}
1608
-	else {
1609
-		if (!defined('_OS_SERVEUR')) define('_OS_SERVEUR', '');
1610
-		if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',1); // utiliser le flock php
1611
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
1612
-	}
1613
-
1614
-	// Langue par defaut
1615
-	if (!defined('_LANGUE_PAR_DEFAUT')) define('_LANGUE_PAR_DEFAUT','fr');
1616
-
1617
-	// PHP_VERSION_ID dispo depuis PHP 5.2.7
1618
-	if (!defined('PHP_VERSION_ID')) {
1619
-	   $version = explode('.',PHP_VERSION);
1620
-	   define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
1621
-	}
1622
-
1623
-	//
1624
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
1625
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
1626
-	// pour le rendre surchargeable, on va provoquer un reecriture
1627
-	// systematique du noyau ou une baisse de perfs => a etudier)
1628
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
1629
-
1630
-	// charger tout de suite le path et son cache
1631
-	load_path_cache();
1632
-
1633
-	// *********** traiter les variables ************
1634
-
1635
-	//
1636
-	// Securite
1637
-	//
1638
-
1639
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
1640
-	if (isset($_REQUEST['GLOBALS'])) die();
1641
-	// nettoyer les magic quotes \' et les caracteres nuls %00
1642
-	spip_desinfecte($_GET);
1643
-	spip_desinfecte($_POST);
1644
-	spip_desinfecte($_COOKIE);
1645
-	spip_desinfecte($_REQUEST);
1646
-
1647
-	// Par ailleurs on ne veut pas de magic_quotes au cours de l'execution
1648
-	if (PHP_VERSION_ID<50300) {
1649
-		@set_magic_quotes_runtime(0);
1650
-	}
1651
-
1652
-	// Si les variables sont passees en global par le serveur,
1653
-	// il faut faire quelques verifications de base
1654
-	$avertir_register_globals = false;
1655
-	if (test_valeur_serveur(@ini_get('register_globals'))) {
1656
-		// ne pas desinfecter les globales en profondeur car elle contient aussi les
1657
-		// precedentes, qui seraient desinfectees 2 fois.
1658
-		spip_desinfecte($GLOBALS,false);
1659
-		if (include_spip('inc/php3'))
1660
-			spip_register_globals(true);
1661
-
1662
-		$avertir_register_globals = true;
1663
-	}
1664
-
1665
-	// appliquer le cookie_prefix
1666
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
1667
-		include_spip('inc/cookie');
1668
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
1669
-	}
1670
-
1671
-	//
1672
-	// Capacites php (en fonction de la version)
1673
-	//
1674
-	$GLOBALS['flag_ob'] = (function_exists("ob_start")
1675
-		&& function_exists("ini_get")
1676
-		&& !strstr(@ini_get('disable_functions'), 'ob_'));
1677
-	$GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name");
1678
-	$GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != "");
1679
-	$GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
1680
-		(get_cfg_var('upload_max_filesize') > 0));
1681
-
1682
-
1683
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
1684
-	if (isset($_SERVER['REQUEST_URI'])) {
1685
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1686
-	} else {
1687
-		$GLOBALS['REQUEST_URI'] = $_SERVER['PHP_SELF'];
1688
-		if ($_SERVER['QUERY_STRING']
1689
-		AND !strpos($_SERVER['REQUEST_URI'], '?'))
1690
-			$GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
1691
-	}
1692
-
1693
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
1694
-	if (!defined('_RENOUVELLE_ALEA')) define('_RENOUVELLE_ALEA', 12 * 3600);
1695
-
1696
-	// charger les meta si possible et renouveller l'alea au besoin
1697
-	// charge aussi effacer_meta et ecrire_meta
1698
-	$inc_meta = charger_fonction('meta', 'inc');
1699
-	$inc_meta();
1700
-
1701
-	// on a pas pu le faire plus tot
1702
-	if  ($avertir_register_globals)
1703
-		avertir_auteurs("register_globals",_L("Probl&egrave;me de s&eacute;curit&eacute; : register_globals=on; dans php.ini &agrave; corriger."));
1704
-
1705
-	// nombre de repertoires depuis la racine
1706
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
1707
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
1708
-	// le calcul est faux)
1709
-	if (!_DIR_RESTREINT)
1710
-		$GLOBALS['profondeur_url'] = 1;
1711
-	else {
1712
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
1713
-		$uri_ref = $_SERVER["SCRIPT_NAME"];
1714
-		if (!$uri_ref
1715
-			// si on est appele avec un autre ti, on est sans doute en mutu
1716
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
1717
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
1718
-			// s'en remettre a l'adresse du site. alea jacta est.
1719
-			OR $ti!==_NOM_TEMPORAIRES_INACCESSIBLES){
1720
-
1721
-			if (isset($GLOBALS['meta']['adresse_site'])) {
1722
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
1723
-				$uri_ref = $uri_ref['path'].'/';
1724
-			}
1725
-		  else
1726
-			  $uri_ref = "";
1727
-		}
1728
-		if (!$uri OR !$uri_ref)
1729
-			$GLOBALS['profondeur_url'] = 0;
1730
-		else {
1731
-			$GLOBALS['profondeur_url'] = max(0,
1732
-				substr_count($uri[0], '/')
1733
-				- substr_count($uri_ref,'/'));
1734
-		}
1735
-	}
1736
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
1737
-	if (_FILE_CONNECT) {
1738
-		if (verifier_visiteur()=='0minirezo'
1739
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
1740
-		  AND !isset($_COOKIE['spip_admin']))
1741
-			clear_path_cache();
1742
-	}
1527
+    if (!defined('_DIR_IMG')) define('_DIR_IMG', $pa);
1528
+    if (!defined('_DIR_LOGOS')) define('_DIR_LOGOS', $pa);
1529
+    if (!defined('_DIR_IMG_ICONES')) define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
1530
+
1531
+    if (!defined('_DIR_DUMP')) define('_DIR_DUMP', $ti . "dump/");
1532
+    if (!defined('_DIR_SESSIONS')) define('_DIR_SESSIONS', $ti . "sessions/");
1533
+    if (!defined('_DIR_TRANSFERT')) define('_DIR_TRANSFERT', $ti . "upload/");
1534
+    if (!defined('_DIR_CACHE')) define('_DIR_CACHE', $ti . "cache/");
1535
+    if (!defined('_DIR_CACHE_XML')) define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
1536
+    if (!defined('_DIR_SKELS')) define('_DIR_SKELS',  _DIR_CACHE . "skel/");
1537
+    if (!defined('_DIR_AIDE')) define('_DIR_AIDE',  _DIR_CACHE . "aide/");
1538
+    if (!defined('_DIR_TMP')) define('_DIR_TMP', $ti);
1539
+
1540
+    if (!defined('_DIR_VAR')) define('_DIR_VAR', $ta);
1541
+
1542
+    if (!defined('_DIR_ETC')) define('_DIR_ETC', $pi);
1543
+    if (!defined('_DIR_CONNECT')) define('_DIR_CONNECT', $pi);
1544
+    if (!defined('_DIR_CHMOD')) define('_DIR_CHMOD', $pi);
1545
+
1546
+    if (!isset($GLOBALS['test_dirs']))
1547
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
1548
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
1549
+        $GLOBALS['test_dirs'] =  array($pa, $ti, $ta);
1550
+
1551
+    // Declaration des fichiers
1552
+
1553
+    if (!defined('_CACHE_PLUGINS_PATH')) define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
1554
+    if (!defined('_CACHE_PLUGINS_OPT')) define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
1555
+    if (!defined('_CACHE_PLUGINS_FCT')) define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
1556
+    if (!defined('_CACHE_PIPELINES')) define('_CACHE_PIPELINES',  _DIR_CACHE."charger_pipelines.php");
1557
+    if (!defined('_CACHE_CHEMIN')) define('_CACHE_CHEMIN',  _DIR_CACHE."chemin.txt");
1558
+
1559
+    # attention .php obligatoire pour ecrire_fichier_securise
1560
+    if (!defined('_FILE_META')) define('_FILE_META', $ti . 'meta_cache.php');
1561
+    if (!defined('_DIR_LOG')) define('_DIR_LOG', _DIR_TMP . 'log/');
1562
+    if (!defined('_FILE_LOG')) define('_FILE_LOG', 'spip');
1563
+    if (!defined('_FILE_LOG_SUFFIX')) define('_FILE_LOG_SUFFIX', '.log');
1564
+
1565
+    // Le fichier de connexion a la base de donnees
1566
+    // tient compte des anciennes versions (inc_connect...)
1567
+    if (!defined('_FILE_CONNECT_INS')) define('_FILE_CONNECT_INS', 'connect');
1568
+    if (!defined('_FILE_CONNECT')) define('_FILE_CONNECT',
1569
+        (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
1570
+    :	(@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
1571
+    :	false)));
1572
+
1573
+    // Le fichier de reglages des droits
1574
+    if (!defined('_FILE_CHMOD_INS')) define('_FILE_CHMOD_INS', 'chmod');
1575
+    if (!defined('_FILE_CHMOD')) define('_FILE_CHMOD',
1576
+        (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
1577
+    :	false));
1578
+
1579
+    if (!defined('_FILE_LDAP')) define('_FILE_LDAP', 'ldap.php');
1580
+
1581
+    if (!defined('_FILE_TMP_SUFFIX')) define('_FILE_TMP_SUFFIX', '.tmp.php');
1582
+    if (!defined('_FILE_CONNECT_TMP')) define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
1583
+    if (!defined('_FILE_CHMOD_TMP')) define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
1584
+
1585
+    // Definition des droits d'acces en ecriture
1586
+    if (!defined('_SPIP_CHMOD') AND _FILE_CHMOD)
1587
+        include_once _FILE_CHMOD;
1588
+
1589
+    // Se mefier des fichiers mal remplis!
1590
+    if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', 0777);
1591
+
1592
+    // Le charset par defaut lors de l'installation
1593
+    if (!defined('_DEFAULT_CHARSET')) define('_DEFAULT_CHARSET', 'utf-8');
1594
+    if (!defined('_ROOT_PLUGINS')) define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
1595
+    if (!defined('_ROOT_PLUGINS_DIST')) define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
1596
+    if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE,'',_DIR_PLUGINS_SUPPL));
1597
+
1598
+    // La taille des Log
1599
+    if (!defined('_MAX_LOG')) define('_MAX_LOG', 100);
1600
+
1601
+    // Sommes-nous dans l'empire du Mal ?
1602
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
1603
+    if (strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false){
1604
+        if (!defined('_OS_SERVEUR')) define('_OS_SERVEUR', 'windows');
1605
+        if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',1); // utiliser le flock php
1606
+    }
1607
+    else {
1608
+        if (!defined('_OS_SERVEUR')) define('_OS_SERVEUR', '');
1609
+        if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',1); // utiliser le flock php
1610
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
1611
+    }
1612
+
1613
+    // Langue par defaut
1614
+    if (!defined('_LANGUE_PAR_DEFAUT')) define('_LANGUE_PAR_DEFAUT','fr');
1615
+
1616
+    // PHP_VERSION_ID dispo depuis PHP 5.2.7
1617
+    if (!defined('PHP_VERSION_ID')) {
1618
+        $version = explode('.',PHP_VERSION);
1619
+        define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
1620
+    }
1621
+
1622
+    //
1623
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
1624
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
1625
+    // pour le rendre surchargeable, on va provoquer un reecriture
1626
+    // systematique du noyau ou une baisse de perfs => a etudier)
1627
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
1628
+
1629
+    // charger tout de suite le path et son cache
1630
+    load_path_cache();
1631
+
1632
+    // *********** traiter les variables ************
1633
+
1634
+    //
1635
+    // Securite
1636
+    //
1637
+
1638
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
1639
+    if (isset($_REQUEST['GLOBALS'])) die();
1640
+    // nettoyer les magic quotes \' et les caracteres nuls %00
1641
+    spip_desinfecte($_GET);
1642
+    spip_desinfecte($_POST);
1643
+    spip_desinfecte($_COOKIE);
1644
+    spip_desinfecte($_REQUEST);
1645
+
1646
+    // Par ailleurs on ne veut pas de magic_quotes au cours de l'execution
1647
+    if (PHP_VERSION_ID<50300) {
1648
+        @set_magic_quotes_runtime(0);
1649
+    }
1650
+
1651
+    // Si les variables sont passees en global par le serveur,
1652
+    // il faut faire quelques verifications de base
1653
+    $avertir_register_globals = false;
1654
+    if (test_valeur_serveur(@ini_get('register_globals'))) {
1655
+        // ne pas desinfecter les globales en profondeur car elle contient aussi les
1656
+        // precedentes, qui seraient desinfectees 2 fois.
1657
+        spip_desinfecte($GLOBALS,false);
1658
+        if (include_spip('inc/php3'))
1659
+            spip_register_globals(true);
1660
+
1661
+        $avertir_register_globals = true;
1662
+    }
1663
+
1664
+    // appliquer le cookie_prefix
1665
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
1666
+        include_spip('inc/cookie');
1667
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
1668
+    }
1669
+
1670
+    //
1671
+    // Capacites php (en fonction de la version)
1672
+    //
1673
+    $GLOBALS['flag_ob'] = (function_exists("ob_start")
1674
+        && function_exists("ini_get")
1675
+        && !strstr(@ini_get('disable_functions'), 'ob_'));
1676
+    $GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name");
1677
+    $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != "");
1678
+    $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
1679
+        (get_cfg_var('upload_max_filesize') > 0));
1680
+
1681
+
1682
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
1683
+    if (isset($_SERVER['REQUEST_URI'])) {
1684
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1685
+    } else {
1686
+        $GLOBALS['REQUEST_URI'] = $_SERVER['PHP_SELF'];
1687
+        if ($_SERVER['QUERY_STRING']
1688
+        AND !strpos($_SERVER['REQUEST_URI'], '?'))
1689
+            $GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
1690
+    }
1691
+
1692
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
1693
+    if (!defined('_RENOUVELLE_ALEA')) define('_RENOUVELLE_ALEA', 12 * 3600);
1694
+
1695
+    // charger les meta si possible et renouveller l'alea au besoin
1696
+    // charge aussi effacer_meta et ecrire_meta
1697
+    $inc_meta = charger_fonction('meta', 'inc');
1698
+    $inc_meta();
1699
+
1700
+    // on a pas pu le faire plus tot
1701
+    if  ($avertir_register_globals)
1702
+        avertir_auteurs("register_globals",_L("Probl&egrave;me de s&eacute;curit&eacute; : register_globals=on; dans php.ini &agrave; corriger."));
1703
+
1704
+    // nombre de repertoires depuis la racine
1705
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
1706
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
1707
+    // le calcul est faux)
1708
+    if (!_DIR_RESTREINT)
1709
+        $GLOBALS['profondeur_url'] = 1;
1710
+    else {
1711
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
1712
+        $uri_ref = $_SERVER["SCRIPT_NAME"];
1713
+        if (!$uri_ref
1714
+            // si on est appele avec un autre ti, on est sans doute en mutu
1715
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
1716
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
1717
+            // s'en remettre a l'adresse du site. alea jacta est.
1718
+            OR $ti!==_NOM_TEMPORAIRES_INACCESSIBLES){
1719
+
1720
+            if (isset($GLOBALS['meta']['adresse_site'])) {
1721
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
1722
+                $uri_ref = $uri_ref['path'].'/';
1723
+            }
1724
+            else
1725
+                $uri_ref = "";
1726
+        }
1727
+        if (!$uri OR !$uri_ref)
1728
+            $GLOBALS['profondeur_url'] = 0;
1729
+        else {
1730
+            $GLOBALS['profondeur_url'] = max(0,
1731
+                substr_count($uri[0], '/')
1732
+                - substr_count($uri_ref,'/'));
1733
+        }
1734
+    }
1735
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
1736
+    if (_FILE_CONNECT) {
1737
+        if (verifier_visiteur()=='0minirezo'
1738
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
1739
+          AND !isset($_COOKIE['spip_admin']))
1740
+            clear_path_cache();
1741
+    }
1743 1742
 
1744 1743
 }
1745 1744
 
@@ -1749,205 +1748,205 @@  discard block
 block discarded – undo
1749 1748
  *
1750 1749
  */
1751 1750
 function spip_initialisation_suite() {
1752
-	static $too_late = 0;
1753
-	if ($too_late++) return;
1751
+    static $too_late = 0;
1752
+    if ($too_late++) return;
1754 1753
 
1755
-	// taille mini des login
1756
-	if (!defined('_LOGIN_TROP_COURT')) define('_LOGIN_TROP_COURT', 4);
1754
+    // taille mini des login
1755
+    if (!defined('_LOGIN_TROP_COURT')) define('_LOGIN_TROP_COURT', 4);
1757 1756
 
1758
-	// la taille maxi des logos (0 : pas de limite)
1759
-	if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
1760
-	if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
1761
-	if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
1757
+    // la taille maxi des logos (0 : pas de limite)
1758
+    if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
1759
+    if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
1760
+    if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
1762 1761
 
1763
-	if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
1762
+    if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
1764 1763
 
1765
-	if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
1766
-	if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
1767
-	if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
1768
-	if (!defined('_PASS_LONGUEUR_MINI')) define('_PASS_LONGUEUR_MINI',6);
1764
+    if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
1765
+    if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
1766
+    if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
1767
+    if (!defined('_PASS_LONGUEUR_MINI')) define('_PASS_LONGUEUR_MINI',6);
1769 1768
 
1770 1769
 
1771
-	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
1770
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
1772 1771
         if (!defined('_IMG_QUALITE')) define('_IMG_QUALITE', 85); # valeur par defaut
1773 1772
         if (!defined('_IMG_GD_QUALITE')) define('_IMG_GD_QUALITE', _IMG_QUALITE); # surcharge pour la lib GD
1774 1773
         if (!defined('_IMG_CONVERT_QUALITE')) define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); # surcharge pour imagick en ligne de commande
1775
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
1774
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
1776 1775
         if (!defined('_IMG_IMAGICK_QUALITE')) define('_IMG_IMAGICK_QUALITE', 75); # surcharge pour imagick en PHP
1777 1776
 
1778
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) define('_COPIE_LOCALE_MAX_SIZE',16777216); // poids en octet
1779
-
1780
-	// qq chaines standard
1781
-	if (!defined('_ACCESS_FILE_NAME')) define('_ACCESS_FILE_NAME', '.htaccess');
1782
-	if (!defined('_AUTH_USER_FILE')) define('_AUTH_USER_FILE', '.htpasswd');
1783
-	if (!defined('_SPIP_DUMP')) define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
1784
-	if (!defined('_CACHE_RUBRIQUES')) define('_CACHE_RUBRIQUES', _DIR_TMP.'menu-rubriques-cache.txt');
1785
-	if (!defined('_CACHE_RUBRIQUES_MAX')) define('_CACHE_RUBRIQUES_MAX', 500);
1786
-
1787
-	if (!defined('_EXTENSION_SQUELETTES')) define('_EXTENSION_SQUELETTES', 'html');
1788
-
1789
-	if (!defined('_DOCTYPE_ECRIRE')) define('_DOCTYPE_ECRIRE',
1790
-		// "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>\n");
1791
-		//"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n");
1792
-		//"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n");
1793
-	       // "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1 //EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>\n");
1794
-		"<!DOCTYPE html>\n");
1795
-	if (!defined('_DOCTYPE_AIDE')) define('_DOCTYPE_AIDE',
1796
-	       "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
1797
-
1798
-	// L'adresse de base du site ; on peut mettre '' si la racine est geree par
1799
-	// le script de l'espace public, alias  index.php
1800
-	if (!defined('_SPIP_SCRIPT')) define('_SPIP_SCRIPT', 'spip.php');
1801
-	// argument page, personalisable en cas de conflit avec un autre script
1802
-	if (!defined('_SPIP_PAGE')) define('_SPIP_PAGE', 'page');
1803
-
1804
-	// le script de l'espace prive
1805
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
1806
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
1807
-	// meme pb sur thttpd cf. http://forum.spip.org/fr_184153.html
1808
-
1809
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) define('_SPIP_ECRIRE_SCRIPT', // true ? #decommenter ici et commenter la
1810
-	       preg_match(',IIS|thttpd,',$_SERVER['SERVER_SOFTWARE']) ?
1811
-	       'index.php' : '');
1812
-
1813
-
1814
-	if (!defined('_SPIP_AJAX'))
1815
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
1816
-			? 1
1817
-		       : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
1818
-
1819
-	// La requete est-elle en ajax ?
1820
-	if (!defined('_AJAX')) define('_AJAX',
1821
-		(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
1822
-		OR @$_REQUEST['var_ajax_redir'] # redirection 302 apres ajax jQuery
1823
-		OR @$_REQUEST['var_ajaxcharset'] # compat ascendante pour plugins
1824
-		OR @$_REQUEST['var_ajax'] # forms ajax & inclure ajax de spip
1825
-		)
1826
-		AND !@$_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
1827
-	);
1828
-
1829
-	# nombre de pixels maxi pour calcul de la vignette avec gd
1830
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
1831
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
1832
-	if (!defined('_IMG_GD_MAX_PIXELS')) define('_IMG_GD_MAX_PIXELS',
1833
-		(isset($GLOBALS['meta']['max_taille_vignettes'])&&$GLOBALS['meta']['max_taille_vignettes']<5500000)
1834
-		 ? $GLOBALS['meta']['max_taille_vignettes']
1835
-		 : 0);
1836
-
1837
-	if (!defined('_MEMORY_LIMIT_MIN')) define('_MEMORY_LIMIT_MIN',10); // en Mo
1838
-	// si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
1839
-	// on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
1840
-	// il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
1841
-	if (test_espace_prive() AND _MEMORY_LIMIT_MIN>8){
1842
-		if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
1843
-			$unit = strtolower(substr($memory,strlen($memory/1),1));
1844
-			switch($unit) {
1845
-				// Le modifieur 'G' est disponible depuis PHP 5.1.0
1846
-				case 'g': $memory *= 1024;
1847
-				case 'm': $memory *= 1024;
1848
-				case 'k': $memory *= 1024;
1849
-			}
1850
-			if ($memory<_MEMORY_LIMIT_MIN*1024*1024){
1851
-				ini_set('memory_limit',$m=_MEMORY_LIMIT_MIN.'M');
1852
-				if (trim(ini_get('memory_limit'))!=$m){
1853
-					if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) define('_INTERDIRE_COMPACTE_HEAD_ECRIRE',true); // evite une page blanche car on ne saura pas calculer la css dans ce hit
1854
-				}
1855
-			}
1856
-		}
1857
-		else
1858
-			if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) define('_INTERDIRE_COMPACTE_HEAD_ECRIRE',true); // evite une page blanche car on ne saura pas calculer la css dans ce hit
1859
-	}
1860
-	// Protocoles a normaliser dans les chaines de langues
1861
-	if (!defined('_PROTOCOLES_STD'))
1862
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
1863
-
1864
-	init_var_mode();
1777
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) define('_COPIE_LOCALE_MAX_SIZE',16777216); // poids en octet
1778
+
1779
+    // qq chaines standard
1780
+    if (!defined('_ACCESS_FILE_NAME')) define('_ACCESS_FILE_NAME', '.htaccess');
1781
+    if (!defined('_AUTH_USER_FILE')) define('_AUTH_USER_FILE', '.htpasswd');
1782
+    if (!defined('_SPIP_DUMP')) define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
1783
+    if (!defined('_CACHE_RUBRIQUES')) define('_CACHE_RUBRIQUES', _DIR_TMP.'menu-rubriques-cache.txt');
1784
+    if (!defined('_CACHE_RUBRIQUES_MAX')) define('_CACHE_RUBRIQUES_MAX', 500);
1785
+
1786
+    if (!defined('_EXTENSION_SQUELETTES')) define('_EXTENSION_SQUELETTES', 'html');
1787
+
1788
+    if (!defined('_DOCTYPE_ECRIRE')) define('_DOCTYPE_ECRIRE',
1789
+        // "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>\n");
1790
+        //"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n");
1791
+        //"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n");
1792
+            // "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1 //EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>\n");
1793
+        "<!DOCTYPE html>\n");
1794
+    if (!defined('_DOCTYPE_AIDE')) define('_DOCTYPE_AIDE',
1795
+            "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
1796
+
1797
+    // L'adresse de base du site ; on peut mettre '' si la racine est geree par
1798
+    // le script de l'espace public, alias  index.php
1799
+    if (!defined('_SPIP_SCRIPT')) define('_SPIP_SCRIPT', 'spip.php');
1800
+    // argument page, personalisable en cas de conflit avec un autre script
1801
+    if (!defined('_SPIP_PAGE')) define('_SPIP_PAGE', 'page');
1802
+
1803
+    // le script de l'espace prive
1804
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
1805
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
1806
+    // meme pb sur thttpd cf. http://forum.spip.org/fr_184153.html
1807
+
1808
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) define('_SPIP_ECRIRE_SCRIPT', // true ? #decommenter ici et commenter la
1809
+            preg_match(',IIS|thttpd,',$_SERVER['SERVER_SOFTWARE']) ?
1810
+           'index.php' : '');
1811
+
1812
+
1813
+    if (!defined('_SPIP_AJAX'))
1814
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
1815
+            ? 1
1816
+               : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
1817
+
1818
+    // La requete est-elle en ajax ?
1819
+    if (!defined('_AJAX')) define('_AJAX',
1820
+        (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
1821
+        OR @$_REQUEST['var_ajax_redir'] # redirection 302 apres ajax jQuery
1822
+        OR @$_REQUEST['var_ajaxcharset'] # compat ascendante pour plugins
1823
+        OR @$_REQUEST['var_ajax'] # forms ajax & inclure ajax de spip
1824
+        )
1825
+        AND !@$_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
1826
+    );
1827
+
1828
+    # nombre de pixels maxi pour calcul de la vignette avec gd
1829
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
1830
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
1831
+    if (!defined('_IMG_GD_MAX_PIXELS')) define('_IMG_GD_MAX_PIXELS',
1832
+        (isset($GLOBALS['meta']['max_taille_vignettes'])&&$GLOBALS['meta']['max_taille_vignettes']<5500000)
1833
+         ? $GLOBALS['meta']['max_taille_vignettes']
1834
+         : 0);
1835
+
1836
+    if (!defined('_MEMORY_LIMIT_MIN')) define('_MEMORY_LIMIT_MIN',10); // en Mo
1837
+    // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
1838
+    // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
1839
+    // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
1840
+    if (test_espace_prive() AND _MEMORY_LIMIT_MIN>8){
1841
+        if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
1842
+            $unit = strtolower(substr($memory,strlen($memory/1),1));
1843
+            switch($unit) {
1844
+                // Le modifieur 'G' est disponible depuis PHP 5.1.0
1845
+                case 'g': $memory *= 1024;
1846
+                case 'm': $memory *= 1024;
1847
+                case 'k': $memory *= 1024;
1848
+            }
1849
+            if ($memory<_MEMORY_LIMIT_MIN*1024*1024){
1850
+                ini_set('memory_limit',$m=_MEMORY_LIMIT_MIN.'M');
1851
+                if (trim(ini_get('memory_limit'))!=$m){
1852
+                    if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) define('_INTERDIRE_COMPACTE_HEAD_ECRIRE',true); // evite une page blanche car on ne saura pas calculer la css dans ce hit
1853
+                }
1854
+            }
1855
+        }
1856
+        else
1857
+            if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) define('_INTERDIRE_COMPACTE_HEAD_ECRIRE',true); // evite une page blanche car on ne saura pas calculer la css dans ce hit
1858
+    }
1859
+    // Protocoles a normaliser dans les chaines de langues
1860
+    if (!defined('_PROTOCOLES_STD'))
1861
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
1862
+
1863
+    init_var_mode();
1865 1864
 }
1866 1865
 
1867 1866
 // Reperer les variables d'URL qui conditionnent la perennite du cache, des urls
1868 1867
 // ou d'autres petit caches (trouver_table, css et js compactes ...)
1869 1868
 // http://doc.spip.org/@init_var_mode
1870 1869
 function init_var_mode(){
1871
-	static $done = false;
1872
-	if (!$done) {
1873
-
1874
-		if (isset($_GET['var_mode'])) {
1875
-			// tout le monde peut calcul/recalcul
1876
-			if ($_GET['var_mode'] == 'calcul'
1877
-			OR $_GET['var_mode'] == 'recalcul') {
1878
-				if (!defined('_VAR_MODE')) define('_VAR_MODE',$_GET['var_mode']);
1879
-			}
1880
-			// preview, debug, blocs, urls et images necessitent une autorisation
1881
-			else if (in_array($_GET['var_mode'],array('preview','debug','inclure','urls','images','traduction'))) {
1882
-				include_spip('inc/autoriser');
1883
-				if (autoriser(
1884
-					($_GET['var_mode'] == 'preview')
1885
-						? 'previsualiser'
1886
-						: 'debug'
1887
-				)) {
1888
-					switch($_GET['var_mode']){
1889
-						case 'traduction':
1890
-							// forcer le calcul pour passer dans traduire
1891
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1892
-							// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
1893
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1894
-							break;
1895
-						case 'preview':
1896
-							// basculer sur les criteres de preview dans les boucles
1897
-							if (!defined('_VAR_PREVIEW')) define('_VAR_PREVIEW',true);
1898
-							// forcer le calcul
1899
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1900
-							// et ne pas enregistrer de cache
1901
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1902
-							break;
1903
-						case 'inclure':
1904
-							// forcer le compilo et ignorer les caches existants
1905
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1906
-							if (!defined('_VAR_INCLURE')) define('_VAR_INCLURE',true);
1907
-							// et ne pas enregistrer de cache
1908
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1909
-							break;
1910
-						case 'urls':
1911
-							// forcer le compilo et ignorer les caches existants
1912
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1913
-							if (!defined('_VAR_URLS')) define('_VAR_URLS',true);
1914
-							break;
1915
-						case 'images':
1916
-							// forcer le compilo et ignorer les caches existants
1917
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1918
-							// indiquer qu'on doit recalculer les images
1919
-							if (!defined('_VAR_IMAGES')) define('_VAR_IMAGES',true);
1920
-							break;
1921
-						case 'debug':
1922
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','debug');
1923
-							// et ne pas enregistrer de cache
1924
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1925
-							break;
1926
-						default :
1927
-							if (!defined('_VAR_MODE')) define('_VAR_MODE',$_GET['var_mode']);
1928
-							break;
1929
-					}
1930
-          if (isset($GLOBALS['visiteur_session']['nom']))
1931
-					spip_log($GLOBALS['visiteur_session']['nom']
1932
-						. " "._VAR_MODE);
1933
-				}
1934
-				// pas autorise ?
1935
-				else {
1936
-					// si on n'est pas connecte on se redirige
1937
-					if (!$GLOBALS['visiteur_session']) {
1938
-						include_spip('inc/headers');
1939
-						redirige_par_entete(generer_url_public('login',
1940
-						'url='.rawurlencode(
1941
-						parametre_url(self(), 'var_mode', $_GET['var_mode'], '&')
1942
-						), true));
1943
-					}
1944
-					// sinon tant pis
1945
-				}
1946
-			}
1947
-			if (!defined('_VAR_MODE')) define('_VAR_MODE',false);
1948
-		}
1949
-		$done = true;
1950
-	}
1870
+    static $done = false;
1871
+    if (!$done) {
1872
+
1873
+        if (isset($_GET['var_mode'])) {
1874
+            // tout le monde peut calcul/recalcul
1875
+            if ($_GET['var_mode'] == 'calcul'
1876
+            OR $_GET['var_mode'] == 'recalcul') {
1877
+                if (!defined('_VAR_MODE')) define('_VAR_MODE',$_GET['var_mode']);
1878
+            }
1879
+            // preview, debug, blocs, urls et images necessitent une autorisation
1880
+            else if (in_array($_GET['var_mode'],array('preview','debug','inclure','urls','images','traduction'))) {
1881
+                include_spip('inc/autoriser');
1882
+                if (autoriser(
1883
+                    ($_GET['var_mode'] == 'preview')
1884
+                        ? 'previsualiser'
1885
+                        : 'debug'
1886
+                )) {
1887
+                    switch($_GET['var_mode']){
1888
+                        case 'traduction':
1889
+                            // forcer le calcul pour passer dans traduire
1890
+                            if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1891
+                            // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
1892
+                            if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1893
+                            break;
1894
+                        case 'preview':
1895
+                            // basculer sur les criteres de preview dans les boucles
1896
+                            if (!defined('_VAR_PREVIEW')) define('_VAR_PREVIEW',true);
1897
+                            // forcer le calcul
1898
+                            if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1899
+                            // et ne pas enregistrer de cache
1900
+                            if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1901
+                            break;
1902
+                        case 'inclure':
1903
+                            // forcer le compilo et ignorer les caches existants
1904
+                            if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1905
+                            if (!defined('_VAR_INCLURE')) define('_VAR_INCLURE',true);
1906
+                            // et ne pas enregistrer de cache
1907
+                            if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1908
+                            break;
1909
+                        case 'urls':
1910
+                            // forcer le compilo et ignorer les caches existants
1911
+                            if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1912
+                            if (!defined('_VAR_URLS')) define('_VAR_URLS',true);
1913
+                            break;
1914
+                        case 'images':
1915
+                            // forcer le compilo et ignorer les caches existants
1916
+                            if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1917
+                            // indiquer qu'on doit recalculer les images
1918
+                            if (!defined('_VAR_IMAGES')) define('_VAR_IMAGES',true);
1919
+                            break;
1920
+                        case 'debug':
1921
+                            if (!defined('_VAR_MODE')) define('_VAR_MODE','debug');
1922
+                            // et ne pas enregistrer de cache
1923
+                            if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1924
+                            break;
1925
+                        default :
1926
+                            if (!defined('_VAR_MODE')) define('_VAR_MODE',$_GET['var_mode']);
1927
+                            break;
1928
+                    }
1929
+            if (isset($GLOBALS['visiteur_session']['nom']))
1930
+                    spip_log($GLOBALS['visiteur_session']['nom']
1931
+                        . " "._VAR_MODE);
1932
+                }
1933
+                // pas autorise ?
1934
+                else {
1935
+                    // si on n'est pas connecte on se redirige
1936
+                    if (!$GLOBALS['visiteur_session']) {
1937
+                        include_spip('inc/headers');
1938
+                        redirige_par_entete(generer_url_public('login',
1939
+                        'url='.rawurlencode(
1940
+                        parametre_url(self(), 'var_mode', $_GET['var_mode'], '&')
1941
+                        ), true));
1942
+                    }
1943
+                    // sinon tant pis
1944
+                }
1945
+            }
1946
+            if (!defined('_VAR_MODE')) define('_VAR_MODE',false);
1947
+        }
1948
+        $done = true;
1949
+    }
1951 1950
 }
1952 1951
 
1953 1952
 // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ;
@@ -1955,84 +1954,84 @@  discard block
 block discarded – undo
1955 1954
 // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal')
1956 1955
 // http://doc.spip.org/@spip_desinfecte
1957 1956
 function spip_desinfecte(&$t,$deep = true) {
1958
-	static $magic_quotes;
1959
-	if (!isset($magic_quotes))
1960
-		$magic_quotes = @get_magic_quotes_gpc();
1961
-
1962
-	foreach ($t as $key => $val) {
1963
-		if (is_string($t[$key])) {
1964
-			if ($magic_quotes)
1965
-				$t[$key] = stripslashes($t[$key]);
1966
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
1967
-		}
1968
-		// traiter aussi les "texte_plus" de article_edit
1969
-		else if ($deep AND is_array($t[$key]) AND $key!=='GLOBALS')
1970
-			spip_desinfecte($t[$key],$deep);
1971
-	}
1957
+    static $magic_quotes;
1958
+    if (!isset($magic_quotes))
1959
+        $magic_quotes = @get_magic_quotes_gpc();
1960
+
1961
+    foreach ($t as $key => $val) {
1962
+        if (is_string($t[$key])) {
1963
+            if ($magic_quotes)
1964
+                $t[$key] = stripslashes($t[$key]);
1965
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
1966
+        }
1967
+        // traiter aussi les "texte_plus" de article_edit
1968
+        else if ($deep AND is_array($t[$key]) AND $key!=='GLOBALS')
1969
+            spip_desinfecte($t[$key],$deep);
1970
+    }
1972 1971
 }
1973 1972
 
1974 1973
 //  retourne le statut du visiteur s'il s'annonce
1975 1974
 
1976 1975
 // http://doc.spip.org/@verifier_visiteur
1977 1976
 function verifier_visiteur() {
1978
-	// Rq: pour que cette fonction marche depuis mes_options
1979
-	// il faut forcer l'init si ce n'est fait
1980
-	// mais on risque de perturber des plugins en initialisant trop tot
1981
-	// certaines constantes
1982
-	@spip_initialisation_core(
1983
-		(_DIR_RACINE  . _NOM_PERMANENTS_INACCESSIBLES),
1984
-		(_DIR_RACINE  . _NOM_PERMANENTS_ACCESSIBLES),
1985
-		(_DIR_RACINE  . _NOM_TEMPORAIRES_INACCESSIBLES),
1986
-		(_DIR_RACINE  . _NOM_TEMPORAIRES_ACCESSIBLES)
1987
-	);
1988
-
1989
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
1990
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
1991
-	// Attention on separe bien session_nom et nom, pour eviter
1992
-	// les melanges entre donnees SQL et variables plus aleatoires
1993
-	$variables_session = array('session_nom', 'session_email');
1994
-	foreach($variables_session as $var) {
1995
-		if (_request($var) !== null) {
1996
-			$init = true;
1997
-			break;
1998
-		}
1999
-	}
2000
-	if (isset($init)) {
2001
-		#@spip_initialisation_suite();
2002
-		$session = charger_fonction('session', 'inc');
2003
-		$session();
2004
-		include_spip('inc/texte');
2005
-		foreach($variables_session as $var)
2006
-			if (($a = _request($var)) !== null)
2007
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
2008
-		if (!isset($GLOBALS['visiteur_session']['id_auteur']))
2009
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
2010
-		$session($GLOBALS['visiteur_session']);
2011
-		return 0;
2012
-	}
2013
-
2014
-	$h = (isset($_SERVER['PHP_AUTH_USER'])  AND !$GLOBALS['ignore_auth_http']);
2015
-	if ($h OR isset($_COOKIE['spip_session']) OR isset($_COOKIE[$GLOBALS['cookie_prefix'].'_session'])) {
2016
-
2017
-		$session = charger_fonction('session', 'inc');
2018
-		if ($session()) {
2019
-			return $GLOBALS['visiteur_session']['statut'];
2020
-		}
2021
-		if ($h  AND isset($_SERVER['PHP_AUTH_PW'])) {
2022
-			include_spip('inc/auth');
2023
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
2024
-		}
2025
-		if ($h) {
2026
-			$GLOBALS['visiteur_session'] = $h;
2027
-			return $GLOBALS['visiteur_session']['statut'];
2028
-		}
2029
-	}
2030
-
2031
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
2032
-	include_spip('inc/lang');
2033
-	utiliser_langue_visiteur();
2034
-
2035
-	return false;
1977
+    // Rq: pour que cette fonction marche depuis mes_options
1978
+    // il faut forcer l'init si ce n'est fait
1979
+    // mais on risque de perturber des plugins en initialisant trop tot
1980
+    // certaines constantes
1981
+    @spip_initialisation_core(
1982
+        (_DIR_RACINE  . _NOM_PERMANENTS_INACCESSIBLES),
1983
+        (_DIR_RACINE  . _NOM_PERMANENTS_ACCESSIBLES),
1984
+        (_DIR_RACINE  . _NOM_TEMPORAIRES_INACCESSIBLES),
1985
+        (_DIR_RACINE  . _NOM_TEMPORAIRES_ACCESSIBLES)
1986
+    );
1987
+
1988
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
1989
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
1990
+    // Attention on separe bien session_nom et nom, pour eviter
1991
+    // les melanges entre donnees SQL et variables plus aleatoires
1992
+    $variables_session = array('session_nom', 'session_email');
1993
+    foreach($variables_session as $var) {
1994
+        if (_request($var) !== null) {
1995
+            $init = true;
1996
+            break;
1997
+        }
1998
+    }
1999
+    if (isset($init)) {
2000
+        #@spip_initialisation_suite();
2001
+        $session = charger_fonction('session', 'inc');
2002
+        $session();
2003
+        include_spip('inc/texte');
2004
+        foreach($variables_session as $var)
2005
+            if (($a = _request($var)) !== null)
2006
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
2007
+        if (!isset($GLOBALS['visiteur_session']['id_auteur']))
2008
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
2009
+        $session($GLOBALS['visiteur_session']);
2010
+        return 0;
2011
+    }
2012
+
2013
+    $h = (isset($_SERVER['PHP_AUTH_USER'])  AND !$GLOBALS['ignore_auth_http']);
2014
+    if ($h OR isset($_COOKIE['spip_session']) OR isset($_COOKIE[$GLOBALS['cookie_prefix'].'_session'])) {
2015
+
2016
+        $session = charger_fonction('session', 'inc');
2017
+        if ($session()) {
2018
+            return $GLOBALS['visiteur_session']['statut'];
2019
+        }
2020
+        if ($h  AND isset($_SERVER['PHP_AUTH_PW'])) {
2021
+            include_spip('inc/auth');
2022
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
2023
+        }
2024
+        if ($h) {
2025
+            $GLOBALS['visiteur_session'] = $h;
2026
+            return $GLOBALS['visiteur_session']['statut'];
2027
+        }
2028
+    }
2029
+
2030
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
2031
+    include_spip('inc/lang');
2032
+    utiliser_langue_visiteur();
2033
+
2034
+    return false;
2036 2035
 }
2037 2036
 
2038 2037
 // selectionne la langue donnee en argument et memorise la courante
@@ -2044,18 +2043,18 @@  discard block
 block discarded – undo
2044 2043
 
2045 2044
 // http://doc.spip.org/@lang_select
2046 2045
 function lang_select ($lang=NULL) {
2047
-	static $pile_langues = array();
2048
-	if (!function_exists('changer_langue'))
2049
-		include_spip('inc/lang');
2050
-	if ($lang === NULL)
2051
-		$lang = array_pop($pile_langues);
2052
-	else {
2053
-		array_push($pile_langues, $GLOBALS['spip_lang']);
2054
-	}
2055
-	if (isset($GLOBALS['spip_lang']) AND $lang == $GLOBALS['spip_lang'])
2056
-		return $lang;
2057
-	changer_langue($lang);
2058
-	return $lang;
2046
+    static $pile_langues = array();
2047
+    if (!function_exists('changer_langue'))
2048
+        include_spip('inc/lang');
2049
+    if ($lang === NULL)
2050
+        $lang = array_pop($pile_langues);
2051
+    else {
2052
+        array_push($pile_langues, $GLOBALS['spip_lang']);
2053
+    }
2054
+    if (isset($GLOBALS['spip_lang']) AND $lang == $GLOBALS['spip_lang'])
2055
+        return $lang;
2056
+    changer_langue($lang);
2057
+    return $lang;
2059 2058
 }
2060 2059
 
2061 2060
 
@@ -2068,18 +2067,18 @@  discard block
 block discarded – undo
2068 2067
 // de fichier cache
2069 2068
 // http://doc.spip.org/@spip_session
2070 2069
 function spip_session($force = false) {
2071
-	static $session;
2072
-	if ($force OR !isset($session)) {
2073
-		$s = pipeline('definir_session',
2074
-			$GLOBALS['visiteur_session']
2075
-			? serialize($GLOBALS['visiteur_session'])
2076
-				. '_' . @$_COOKIE['spip_session']
2077
-			: ''
2078
-		);
2079
-		$session = $s ? substr(md5($s), 0, 8) : '';
2080
-	}
2081
-	#spip_log('session: '.$session);
2082
-	return $session;
2070
+    static $session;
2071
+    if ($force OR !isset($session)) {
2072
+        $s = pipeline('definir_session',
2073
+            $GLOBALS['visiteur_session']
2074
+            ? serialize($GLOBALS['visiteur_session'])
2075
+                . '_' . @$_COOKIE['spip_session']
2076
+            : ''
2077
+        );
2078
+        $session = $s ? substr(md5($s), 0, 8) : '';
2079
+    }
2080
+    #spip_log('session: '.$session);
2081
+    return $session;
2083 2082
 }
2084 2083
 
2085 2084
 
@@ -2096,18 +2095,18 @@  discard block
 block discarded – undo
2096 2095
 **/
2097 2096
 // http://doc.spip.org/@aide
2098 2097
 function aide($aide='', $distante = false) {
2099
-		$aider = charger_fonction('aider', 'inc', true);
2100
-	return $aider ?  $aider($aide, '', array(), $distante) : '';
2098
+        $aider = charger_fonction('aider', 'inc', true);
2099
+    return $aider ?  $aider($aide, '', array(), $distante) : '';
2101 2100
 }
2102 2101
 
2103 2102
 // normalement il faudrait creer exec/info.php, mais pour mettre juste ca:
2104 2103
 // http://doc.spip.org/@exec_info_dist
2105 2104
 function exec_info_dist() {
2106
-	global $connect_statut;
2107
-	if ($connect_statut == '0minirezo')
2108
-		phpinfo();
2109
-	else
2110
-		echo "pas admin";
2105
+    global $connect_statut;
2106
+    if ($connect_statut == '0minirezo')
2107
+        phpinfo();
2108
+    else
2109
+        echo "pas admin";
2111 2110
 }
2112 2111
 
2113 2112
 /**
@@ -2127,12 +2126,12 @@  discard block
 block discarded – undo
2127 2126
  * 		- string si $message à false.
2128 2127
 **/
2129 2128
 function erreur_squelette($message='', $lieu='') {
2130
-	$debusquer = charger_fonction('debusquer', 'public');
2131
-	if (is_array($lieu)) {
2132
-		include_spip('public/compiler');
2133
-		$lieu = reconstruire_contexte_compil($lieu);
2134
-	}
2135
-	return $debusquer($message, $lieu);
2129
+    $debusquer = charger_fonction('debusquer', 'public');
2130
+    if (is_array($lieu)) {
2131
+        include_spip('public/compiler');
2132
+        $lieu = reconstruire_contexte_compil($lieu);
2133
+    }
2134
+    return $debusquer($message, $lieu);
2136 2135
 }
2137 2136
 
2138 2137
 /**
@@ -2167,67 +2166,67 @@  discard block
 block discarded – undo
2167 2166
  * 		ou tableau d'information sur le squelette.
2168 2167
  */
2169 2168
 function recuperer_fond($fond, $contexte=array(), $options = array(), $connect='') {
2170
-	if (!function_exists('evaluer_fond'))
2171
-		include_spip('public/assembler');
2172
-	// assurer la compat avec l'ancienne syntaxe
2173
-	// (trim etait le 3eme argument, par defaut a true)
2174
-	if (!is_array($options)) $options = array('trim'=>$options);
2175
-	if (!isset($options['trim'])) $options['trim']=true;
2176
-
2177
-	if (isset($contexte['connect'])){
2178
-		$connect = ($connect ? $connect : $contexte['connect']);
2179
-		unset($contexte['connect']);
2180
-	}
2181
-
2182
-	$texte = "";
2183
-	$pages = array();
2184
-	$lang_select = '';
2185
-	if (!isset($options['etoile']) OR !$options['etoile']){
2186
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
2187
-		if (!isset($contexte['lang']))
2188
-			$contexte['lang'] = $GLOBALS['spip_lang'];
2189
-
2190
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
2191
-			$lang_select = lang_select($contexte['lang']);
2192
-		}
2193
-	}
2194
-
2195
-	@$GLOBALS['_INC_PUBLIC']++;
2196
-
2197
-	foreach(is_array($fond) ? $fond : array($fond) as $f){
2198
-		$page = evaluer_fond($f, $contexte, $connect);
2199
-		if ($page === '') {
2200
-			$c = isset($options['compil']) ? $options['compil'] :'';
2201
-			$a = array('fichier'=>$fond);
2202
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
2203
-			erreur_squelette($erreur, $c);
2204
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
2205
-			$page = array('texte' => '', 'erreur' => $erreur);
2206
-		}
2207
-
2208
-		$page = pipeline('recuperer_fond',array(
2209
-			'args'=>array('fond'=>$f,'contexte'=>$contexte,'options'=>$options,'connect'=>$connect),
2210
-			'data'=>$page
2211
-		));
2212
-		if (isset($options['ajax']) AND $options['ajax']){
2213
-			if (!function_exists('encoder_contexte_ajax'))
2214
-				include_spip('inc/filtres');
2215
-			$page['texte'] = encoder_contexte_ajax(array_merge($contexte,array('fond'=>$f)),'',$page['texte'], $options['ajax']);
2216
-		}
2217
-
2218
-		if (isset($options['raw']) AND $options['raw'])
2219
-			$pages[] = $page;
2220
-		else
2221
-			$texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
2222
-	}
2223
-
2224
-	$GLOBALS['_INC_PUBLIC']--;
2225
-
2226
-	if ($lang_select) lang_select();
2227
-	if (isset($options['raw']) AND $options['raw'])
2228
-		return is_array($fond)?$pages:reset($pages);
2229
-	else
2230
-		return $options['trim'] ? ltrim($texte) : $texte;
2169
+    if (!function_exists('evaluer_fond'))
2170
+        include_spip('public/assembler');
2171
+    // assurer la compat avec l'ancienne syntaxe
2172
+    // (trim etait le 3eme argument, par defaut a true)
2173
+    if (!is_array($options)) $options = array('trim'=>$options);
2174
+    if (!isset($options['trim'])) $options['trim']=true;
2175
+
2176
+    if (isset($contexte['connect'])){
2177
+        $connect = ($connect ? $connect : $contexte['connect']);
2178
+        unset($contexte['connect']);
2179
+    }
2180
+
2181
+    $texte = "";
2182
+    $pages = array();
2183
+    $lang_select = '';
2184
+    if (!isset($options['etoile']) OR !$options['etoile']){
2185
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
2186
+        if (!isset($contexte['lang']))
2187
+            $contexte['lang'] = $GLOBALS['spip_lang'];
2188
+
2189
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
2190
+            $lang_select = lang_select($contexte['lang']);
2191
+        }
2192
+    }
2193
+
2194
+    @$GLOBALS['_INC_PUBLIC']++;
2195
+
2196
+    foreach(is_array($fond) ? $fond : array($fond) as $f){
2197
+        $page = evaluer_fond($f, $contexte, $connect);
2198
+        if ($page === '') {
2199
+            $c = isset($options['compil']) ? $options['compil'] :'';
2200
+            $a = array('fichier'=>$fond);
2201
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
2202
+            erreur_squelette($erreur, $c);
2203
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
2204
+            $page = array('texte' => '', 'erreur' => $erreur);
2205
+        }
2206
+
2207
+        $page = pipeline('recuperer_fond',array(
2208
+            'args'=>array('fond'=>$f,'contexte'=>$contexte,'options'=>$options,'connect'=>$connect),
2209
+            'data'=>$page
2210
+        ));
2211
+        if (isset($options['ajax']) AND $options['ajax']){
2212
+            if (!function_exists('encoder_contexte_ajax'))
2213
+                include_spip('inc/filtres');
2214
+            $page['texte'] = encoder_contexte_ajax(array_merge($contexte,array('fond'=>$f)),'',$page['texte'], $options['ajax']);
2215
+        }
2216
+
2217
+        if (isset($options['raw']) AND $options['raw'])
2218
+            $pages[] = $page;
2219
+        else
2220
+            $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
2221
+    }
2222
+
2223
+    $GLOBALS['_INC_PUBLIC']--;
2224
+
2225
+    if ($lang_select) lang_select();
2226
+    if (isset($options['raw']) AND $options['raw'])
2227
+        return is_array($fond)?$pages:reset($pages);
2228
+    else
2229
+        return $options['trim'] ? ltrim($texte) : $texte;
2231 2230
 }
2232 2231
 
2233 2232
 /**
@@ -2237,7 +2236,7 @@  discard block
 block discarded – undo
2237 2236
  * @return string
2238 2237
  */
2239 2238
 function trouve_modele($nom) {
2240
-	return trouver_fond($nom,'modeles/');
2239
+    return trouver_fond($nom,'modeles/');
2241 2240
 }
2242 2241
 
2243 2242
 /**
@@ -2253,54 +2252,54 @@  discard block
 block discarded – undo
2253 2252
  * @return array|string
2254 2253
  */
2255 2254
 function trouver_fond($nom, $dir='', $pathinfo = false) {
2256
-	$f = find_in_path($nom.'.'. _EXTENSION_SQUELETTES, $dir?rtrim($dir,'/').'/':'');
2257
-	if (!$pathinfo) return $f;
2258
-	// renvoyer un tableau detaille si $pathinfo==true
2259
-	$p = pathinfo($f);
2260
-	if (!isset($p['extension']) OR !$p['extension']) {
2261
-		$p['extension'] = _EXTENSION_SQUELETTES;
2262
-	}
2263
-	if (!isset($p['extension']) OR !$p['filename']) {
2264
-		$p['filename'] = ($p['basename']?substr($p['basename'],0,-strlen($p['extension'])-1):'');
2265
-	}
2266
-	$p['fond'] = ($f?substr($f,0,-strlen($p['extension'])-1):'');
2267
-	return $p;
2255
+    $f = find_in_path($nom.'.'. _EXTENSION_SQUELETTES, $dir?rtrim($dir,'/').'/':'');
2256
+    if (!$pathinfo) return $f;
2257
+    // renvoyer un tableau detaille si $pathinfo==true
2258
+    $p = pathinfo($f);
2259
+    if (!isset($p['extension']) OR !$p['extension']) {
2260
+        $p['extension'] = _EXTENSION_SQUELETTES;
2261
+    }
2262
+    if (!isset($p['extension']) OR !$p['filename']) {
2263
+        $p['filename'] = ($p['basename']?substr($p['basename'],0,-strlen($p['extension'])-1):'');
2264
+    }
2265
+    $p['fond'] = ($f?substr($f,0,-strlen($p['extension'])-1):'');
2266
+    return $p;
2268 2267
 }
2269 2268
 
2270 2269
 function tester_url_ecrire($nom){
2271
-	static $exec=array();
2272
-	if (isset($exec[$nom])) return $exec[$nom];
2273
-	// tester si c'est une page en squelette
2274
-	if (trouver_fond($nom, 'prive/squelettes/contenu/'))
2275
-		return $exec[$nom] = 'fond';
2276
-	// compat skels orthogonaux version precedente
2277
-	elseif (trouver_fond($nom, 'prive/exec/'))
2278
-		return $exec[$nom] = 'fond_monobloc';
2279
-	// echafaudage d'un fond !
2280
-	elseif(include_spip('public/styliser_par_z') AND z_echafaudable($nom))
2281
-		return $exec[$nom] = 'fond';
2282
-	// attention, il ne faut pas inclure l'exec ici
2283
-	// car sinon #URL_ECRIRE provoque des inclusions
2284
-	// et des define intrusifs potentiels
2285
-	return $exec[$nom] = ((find_in_path("{$nom}.php",'exec/') OR charger_fonction($nom,'exec',true))?$nom:'');
2270
+    static $exec=array();
2271
+    if (isset($exec[$nom])) return $exec[$nom];
2272
+    // tester si c'est une page en squelette
2273
+    if (trouver_fond($nom, 'prive/squelettes/contenu/'))
2274
+        return $exec[$nom] = 'fond';
2275
+    // compat skels orthogonaux version precedente
2276
+    elseif (trouver_fond($nom, 'prive/exec/'))
2277
+        return $exec[$nom] = 'fond_monobloc';
2278
+    // echafaudage d'un fond !
2279
+    elseif(include_spip('public/styliser_par_z') AND z_echafaudable($nom))
2280
+        return $exec[$nom] = 'fond';
2281
+    // attention, il ne faut pas inclure l'exec ici
2282
+    // car sinon #URL_ECRIRE provoque des inclusions
2283
+    // et des define intrusifs potentiels
2284
+    return $exec[$nom] = ((find_in_path("{$nom}.php",'exec/') OR charger_fonction($nom,'exec',true))?$nom:'');
2286 2285
 }
2287 2286
 
2288 2287
 // Charger dynamiquement une extension php
2289 2288
 // http://doc.spip.org/@charger_php_extension
2290 2289
 function charger_php_extension($module) {
2291
-	if (extension_loaded($module)) {
2292
-		return true;
2293
-	} else {
2294
-		$charger_php_extension = charger_fonction('charger_php_extension','inc');
2295
-		return $charger_php_extension($module);
2296
-	}
2290
+    if (extension_loaded($module)) {
2291
+        return true;
2292
+    } else {
2293
+        $charger_php_extension = charger_fonction('charger_php_extension','inc');
2294
+        return $charger_php_extension($module);
2295
+    }
2297 2296
 }
2298 2297
 
2299 2298
 // Renvoie TRUE si et seulement si la configuration autorise
2300 2299
 // le code HTML5 sur le site public
2301 2300
 function html5_permis() {
2302 2301
         return (isset($GLOBALS['meta']['version_html_max'])
2303
-		AND ('html5' == $GLOBALS['meta']['version_html_max']));
2302
+        AND ('html5' == $GLOBALS['meta']['version_html_max']));
2304 2303
 }
2305 2304
 
2306 2305
 /*
@@ -2311,7 +2310,7 @@  discard block
 block discarded – undo
2311 2310
 // Fonction depreciee
2312 2311
 // http://doc.spip.org/@lire_meta
2313 2312
 function lire_meta($nom) {
2314
-	return $GLOBALS['meta'][$nom];
2313
+    return $GLOBALS['meta'][$nom];
2315 2314
 }
2316 2315
 
2317 2316
 // Fonction depreciee
@@ -2321,15 +2320,15 @@  discard block
 block discarded – undo
2321 2320
 // Fonction depreciee, cf. http://doc.spip.org/@sql_fetch
2322 2321
 // http://doc.spip.org/@spip_fetch_array
2323 2322
 function spip_fetch_array($r, $t=NULL) {
2324
-	if (!isset($t)) {
2325
-		if ($r) return sql_fetch($r);
2326
-	} else {
2327
-		if ($t=='SPIP_NUM') $t = MYSQL_NUM;
2328
-		if ($t=='SPIP_BOTH') $t = MYSQL_BOTH;
2329
-		if ($t=='SPIP_ASSOC') $t = MYSQL_ASSOC;
2330
-		spip_log("appel deprecie de spip_fetch_array(..., $t)", 'vieilles_defs');
2331
-		if ($r) return mysql_fetch_array($r, $t);
2332
-	}
2323
+    if (!isset($t)) {
2324
+        if ($r) return sql_fetch($r);
2325
+    } else {
2326
+        if ($t=='SPIP_NUM') $t = MYSQL_NUM;
2327
+        if ($t=='SPIP_BOTH') $t = MYSQL_BOTH;
2328
+        if ($t=='SPIP_ASSOC') $t = MYSQL_ASSOC;
2329
+        spip_log("appel deprecie de spip_fetch_array(..., $t)", 'vieilles_defs');
2330
+        if ($r) return mysql_fetch_array($r, $t);
2331
+    }
2333 2332
 }
2334 2333
 
2335 2334
 /**
@@ -2343,14 +2342,14 @@  discard block
 block discarded – undo
2343 2342
  * @param string $statut
2344 2343
  */
2345 2344
 function avertir_auteurs($nom,$message, $statut=''){
2346
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
2347
-	if (!$alertes
2348
-		OR !is_array($alertes = unserialize($alertes)))
2349
-		$alertes = array();
2350
-
2351
-	if (!isset($alertes[$statut]))
2352
-		$alertes[$statut] = array();
2353
-	$alertes[$statut][$nom] = $message;
2354
-	ecrire_meta("message_alertes_auteurs",serialize($alertes));
2345
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
2346
+    if (!$alertes
2347
+        OR !is_array($alertes = unserialize($alertes)))
2348
+        $alertes = array();
2349
+
2350
+    if (!isset($alertes[$statut]))
2351
+        $alertes[$statut] = array();
2352
+    $alertes[$statut][$nom] = $message;
2353
+    ecrire_meta("message_alertes_auteurs",serialize($alertes));
2355 2354
 }
2356 2355
 ?>
Please login to merge, or discard this patch.
Spacing   +343 added lines, -348 removed lines patch added patch discarded remove patch
@@ -29,21 +29,21 @@  discard block
 block discarded – undo
29 29
  * @param bool $continue
30 30
  * @return string
31 31
  */
32
-function charger_fonction($nom, $dossier='exec', $continue=false) {
32
+function charger_fonction($nom, $dossier = 'exec', $continue = false) {
33 33
 	static $echecs = array();
34 34
 
35
-	if (strlen($dossier) AND substr($dossier,-1) != '/') $dossier .= '/';
36
-	$f = str_replace('/','_',$dossier) . $nom;
35
+	if (strlen($dossier) AND substr($dossier, -1) != '/') $dossier .= '/';
36
+	$f = str_replace('/', '_', $dossier).$nom;
37 37
 
38 38
 	if (function_exists($f))
39 39
 		return $f;
40
-	if (function_exists($g = $f . '_dist'))
40
+	if (function_exists($g = $f.'_dist'))
41 41
 		return $g;
42 42
 
43 43
 	if (isset($echecs[$f])) return $echecs[$f];
44 44
 	// Sinon charger le fichier de declaration si plausible
45 45
 
46
-	if (!preg_match(',^\w+$,', $f)){
46
+	if (!preg_match(',^\w+$,', $f)) {
47 47
 		if ($continue) return false; //appel interne, on passe
48 48
 		include_spip('inc/minipres');
49 49
 		echo minipres();
@@ -55,21 +55,21 @@  discard block
 block discarded – undo
55 55
 	if (!$inc = include_spip($dossier.($d = strtolower($nom)))
56 56
 		// si le fichier truc/machin/nom.php n'existe pas,
57 57
 		// la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
58
-		AND strlen(dirname($dossier)) AND dirname($dossier)!='.')
59
-		include_spip(substr($dossier,0,-1));
58
+		AND strlen(dirname($dossier)) AND dirname($dossier) != '.')
59
+		include_spip(substr($dossier, 0, -1));
60 60
 	if (function_exists($f)) return $f;
61 61
 	if (function_exists($g)) return $g;
62 62
 
63 63
 	if ($continue) return $echecs[$f] = false;
64 64
 
65 65
 	// Echec : message d'erreur
66
-	spip_log("fonction $nom ($f ou $g) indisponible" .
66
+	spip_log("fonction $nom ($f ou $g) indisponible".
67 67
 		($inc ? "" : " (fichier $d absent de $dossier)"));
68 68
 
69 69
 	include_spip('inc/minipres');
70 70
 	echo minipres(_T('forum_titre_erreur'),
71 71
 		 _T('fichier_introuvable', array('fichier'=> '<b>'.spip_htmlentities($d).'</b>')),
72
-		array('all_inline'=>true,'status'=>404));
72
+		array('all_inline'=>true, 'status'=>404));
73 73
 	exit;
74 74
 }
75 75
 
@@ -78,12 +78,12 @@  discard block
 block discarded – undo
78 78
  * @param string $file
79 79
  * @return bool
80 80
  */
81
-function include_once_check($file){
82
-	if (file_exists($file)) {include_once $file;return true;}
83
-	$crash = (isset($GLOBALS['meta']['message_crash_plugins'])?unserialize($GLOBALS['meta']['message_crash_plugins']):'');
84
-	$crash = ($crash?$crash:array());
81
+function include_once_check($file) {
82
+	if (file_exists($file)) {include_once $file; return true; }
83
+	$crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
84
+	$crash = ($crash ? $crash : array());
85 85
 	$crash[$file] = true;
86
-	ecrire_meta('message_crash_plugins',serialize($crash));
86
+	ecrire_meta('message_crash_plugins', serialize($crash));
87 87
 	return false;
88 88
 }
89 89
 
@@ -92,12 +92,12 @@  discard block
 block discarded – undo
92 92
 //
93 93
 // http://doc.spip.org/@include_spip
94 94
 function include_spip($f, $include = true) {
95
-	return find_in_path($f . '.php', '', $include);
95
+	return find_in_path($f.'.php', '', $include);
96 96
 }
97 97
 
98 98
 
99 99
 function require_spip($f) {
100
-	return find_in_path($f . '.php', '', 'required');
100
+	return find_in_path($f.'.php', '', 'required');
101 101
 }
102 102
 
103 103
 // un pipeline est lie a une action et une valeur
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 // utilisee dans le script pipeline precompile
114 114
 // on passe $val par reference pour limiter les allocations memoire
115 115
 // http://doc.spip.org/@minipipe
116
-function minipipe($fonc,&$val){
116
+function minipipe($fonc, &$val) {
117 117
 	// fonction
118 118
 	if (function_exists($fonc))
119 119
 		$val = call_user_func($fonc, $val);
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 
131 131
 // chargement du pipeline sous la forme d'un fichier php prepare
132 132
 // http://doc.spip.org/@pipeline
133
-function pipeline($action, $val=null) {
133
+function pipeline($action, $val = null) {
134 134
 	static $charger;
135 135
 
136 136
 	// chargement initial des fonctions mises en cache, ou generation du cache
@@ -156,15 +156,15 @@  discard block
 block discarded – undo
156 156
 	}
157 157
 	// plantage ?
158 158
 	else {
159
-		spip_log("fonction $fonc absente : pipeline desactive",_LOG_ERREUR);
159
+		spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
160 160
 	}
161 161
 
162 162
 	// si le flux est une table avec 2 cle args&data
163 163
 	// on ne ressort du pipe que les donnees dans 'data'
164 164
 	// array_key_exists pour php 4.1.0
165 165
 	if (is_array($val)
166
-	  AND count($val)==2
167
-	  AND (array_key_exists('data',$val)))
166
+	  AND count($val) == 2
167
+	  AND (array_key_exists('data', $val)))
168 168
 		$val = $val['data'];
169 169
 	return $val;
170 170
 }
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
  * @param string $logdir  ## inutile !! a supprimer ?
187 187
  * @param string $logsuf  ## inutile !! a supprimer ?
188 188
  */
189
-function spip_log($message=NULL, $name=NULL) {
189
+function spip_log($message = NULL, $name = NULL) {
190 190
 	static $pre = array();
191 191
 	static $log;
192 192
 	preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string) $name, $regs);
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 		$niveau = _LOG_INFO;
197 197
 
198 198
 	if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
199
-		if (!$pre){
199
+		if (!$pre) {
200 200
 			$pre = array(
201 201
 				_LOG_HS=>'HS:',
202 202
 				_LOG_ALERTE_ROUGE=>'ALERTE:',
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 // Renvoie le _GET ou le _POST emis par l'utilisateur
225 225
 // ou pioche dans $c si c'est un array()
226 226
 // http://doc.spip.org/@_request
227
-function _request($var, $c=false) {
227
+function _request($var, $c = false) {
228 228
 
229 229
 	if (is_array($c))
230 230
 		return isset($c[$var]) ? $c[$var] : NULL;
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 // Methode set de la fonction _request()
257 257
 // Attention au cas ou l'on fait set_request('truc', NULL);
258 258
 // http://doc.spip.org/@set_request
259
-function set_request($var, $val = NULL, $c=false) {
259
+function set_request($var, $val = NULL, $c = false) {
260 260
 	if (is_array($c)) {
261 261
 		unset($c[$var]);
262 262
 		if ($val !== NULL)
@@ -312,9 +312,9 @@  discard block
 block discarded – undo
312 312
  * @param string $sep
313 313
  * @return string
314 314
  */
315
-function parametre_url($url, $c, $v=NULL, $sep='&amp;') {
315
+function parametre_url($url, $c, $v = NULL, $sep = '&amp;') {
316 316
 	// requete erronnee : plusieurs variable dans $c et aucun $v
317
-	if (strpos($c,"|")!==false AND is_null($v))
317
+	if (strpos($c, "|") !== false AND is_null($v))
318 318
 		return null;
319 319
 
320 320
 	// lever l'#ancre
@@ -329,17 +329,17 @@  discard block
 block discarded – undo
329 329
 
330 330
 	// recuperer la base
331 331
 	$a = array_shift($url);
332
-	if (!$a) $a= './';
332
+	if (!$a) $a = './';
333 333
 
334
-	$regexp = ',^(' . str_replace('[]','\[\]',$c) . '[[]?[]]?)(=.*)?$,';
335
-	$ajouts = array_flip(explode('|',$c));
334
+	$regexp = ',^('.str_replace('[]', '\[\]', $c).'[[]?[]]?)(=.*)?$,';
335
+	$ajouts = array_flip(explode('|', $c));
336 336
 	$u = is_array($v) ? $v : rawurlencode($v);
337
-	$testv = (is_array($v)?count($v):strlen($v));
337
+	$testv = (is_array($v) ? count($v) : strlen($v));
338 338
 	// lire les variables et agir
339 339
 	foreach ($url as $n => $val) {
340 340
 		if (preg_match($regexp, urldecode($val), $r)) {
341 341
 			if ($v === NULL) {
342
-				return $r[2]?substr($r[2],1):'';
342
+				return $r[2] ? substr($r[2], 1) : '';
343 343
 			}
344 344
 			// suppression
345 345
 			elseif (!$testv) {
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 			}
348 348
 	// Ajout. Pour une variable, remplacer au meme endroit,
349 349
 	// pour un tableau ce sera fait dans la prochaine boucle
350
-			elseif (substr($r[1],-2) != '[]') {
350
+			elseif (substr($r[1], -2) != '[]') {
351 351
 				$url[$n] = $r[1].'='.$u;
352 352
 				unset($ajouts[$r[1]]);
353 353
 			}
@@ -357,15 +357,15 @@  discard block
 block discarded – undo
357 357
 	// traiter les parametres pas encore trouves
358 358
 	if ($v === NULL
359 359
 	AND $args = func_get_args()
360
-	AND count($args)==2)
360
+	AND count($args) == 2)
361 361
 		return $v;
362 362
 	elseif ($testv) {
363
-		foreach($ajouts as $k => $n) {
363
+		foreach ($ajouts as $k => $n) {
364 364
 		  if (!is_array($v))
365
-		    $url[] = $k .'=' . $u;
365
+		    $url[] = $k.'='.$u;
366 366
 		  else {
367
-		  	$id = (substr($k,-2) == '[]') ? $k : ($k ."[]");
368
-		    foreach ($v as $w) $url[]= $id .'=' . $w;
367
+		  	$id = (substr($k, -2) == '[]') ? $k : ($k."[]");
368
+		    foreach ($v as $w) $url[] = $id.'='.$w;
369 369
 		  }
370 370
 		}
371 371
 	}
@@ -375,9 +375,9 @@  discard block
 block discarded – undo
375 375
 
376 376
 	// recomposer l'adresse
377 377
 	if ($url)
378
-		$a .= '?' . join($sep, $url);
378
+		$a .= '?'.join($sep, $url);
379 379
 
380
-	return $a . $ancre;
380
+	return $a.$ancre;
381 381
 }
382 382
 
383 383
 // Prend une URL et lui ajoute/retire une ancre apres l'avoir nettoyee
@@ -389,13 +389,13 @@  discard block
 block discarded – undo
389 389
 	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
390 390
 		$url = $r[1];
391 391
 	}
392
-	if (preg_match('/[^-_a-zA-Z0-9]+/S',$ancre)){
392
+	if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
393 393
 		if (!function_exists('translitteration'))
394 394
 			include_spip('inc/charsets');
395 395
 		$ancre = preg_replace(array('/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'), array('', '-'),
396 396
 						translitteration($ancre));
397 397
 	}
398
-	return $url . (strlen($ancre) ? '#'. $ancre : '');
398
+	return $url.(strlen($ancre) ? '#'.$ancre : '');
399 399
 }
400 400
 
401 401
 /**
@@ -409,17 +409,16 @@  discard block
 block discarded – undo
409 409
 {
410 410
 	static $done = false;
411 411
 	static $propre = '';
412
-	if (!is_null($reset)) return $propre=$reset;
412
+	if (!is_null($reset)) return $propre = $reset;
413 413
 	if ($done) return $propre;
414 414
 	$done = true;
415 415
 
416 416
 	$uri1 = $GLOBALS['REQUEST_URI'];
417 417
 	do {
418 418
 		$uri = $uri1;
419
-		$uri1 = preg_replace
420
-			(',([?&])(PHPSESSID|(var_[^=&]*))=[^&]*(&|$),i',
419
+		$uri1 = preg_replace(',([?&])(PHPSESSID|(var_[^=&]*))=[^&]*(&|$),i',
421 420
 			'\1', $uri);
422
-	} while ($uri<>$uri1);
421
+	} while ($uri <> $uri1);
423 422
 
424 423
 	return $propre = (preg_replace(',[?&]$,', '', $uri1));
425 424
 }
@@ -439,19 +438,19 @@  discard block
 block discarded – undo
439 438
 	if (!$root
440 439
 		AND (
441 440
 			// si pas de profondeur on peut tronquer
442
-			$GLOBALS['profondeur_url']<(_DIR_RESTREINT?1:2)
441
+			$GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
443 442
 			// sinon c'est OK si _SET_HTML_BASE a ete force a false
444 443
 			OR (defined('_SET_HTML_BASE') AND !_SET_HTML_BASE))
445 444
 		)
446 445
 		$url = preg_replace(',^[^?]*/,', '', $url);
447 446
 	// ajouter le cas echeant les variables _POST['id_...']
448 447
 	foreach ($_POST as $v => $c)
449
-		if (substr($v,0,3) == 'id_')
448
+		if (substr($v, 0, 3) == 'id_')
450 449
 			$url = parametre_url($url, $v, $c, '&');
451 450
 
452 451
 	// supprimer les variables sans interet
453 452
 	if (test_espace_prive()) {
454
-		$url = preg_replace (',([?&])('
453
+		$url = preg_replace(',([?&])('
455 454
 		.'lang|show_docs|'
456 455
 		.'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
457 456
 		$url = preg_replace(',([?&])[&]+,', '\1', $url);
@@ -485,8 +484,8 @@  discard block
 block discarded – undo
485 484
  * @param string $plugin
486 485
  * @return bool
487 486
  */
488
-function test_plugin_actif($plugin){
489
-	return ($plugin AND defined('_DIR_PLUGIN_'.strtoupper($plugin)))? true:false;
487
+function test_plugin_actif($plugin) {
488
+	return ($plugin AND defined('_DIR_PLUGIN_'.strtoupper($plugin))) ? true : false;
490 489
 }
491 490
 
492 491
 /**
@@ -500,14 +499,14 @@  discard block
 block discarded – undo
500 499
  *   bool force : forcer un retour meme si la chaine n'a pas de traduction
501 500
  * @return mixed|string
502 501
  */
503
-function _T($texte, $args=array(), $options=array()) {
504
-	static $traduire=false ;
502
+function _T($texte, $args = array(), $options = array()) {
503
+	static $traduire = false;
505 504
 	$o = array('class'=>'', 'force'=>true);
506
-	if ($options){
505
+	if ($options) {
507 506
 		// support de l'ancien argument $class
508 507
 		if (is_string($options))
509 508
 			$options = array('class'=>$options);
510
-		$o = array_merge($o,$options);
509
+		$o = array_merge($o, $options);
511 510
 	}
512 511
 
513 512
  	if (!$traduire) {
@@ -517,7 +516,7 @@  discard block
 block discarded – undo
517 516
 	
518 517
 	// On peut passer explicitement la langue dans le tableau
519 518
 	// On utilise le même nom de variable que la globale
520
-	if (isset($args['spip_lang'])){
519
+	if (isset($args['spip_lang'])) {
521 520
 		$lang = $args['spip_lang'];
522 521
 		// On l'enleve pour ne pas le passer au remplacement
523 522
 		unset($args['spip_lang']);
@@ -528,7 +527,7 @@  discard block
 block discarded – undo
528 527
 	}
529 528
 	$text = $traduire($texte, $lang);
530 529
 
531
-	if (!strlen($text)){
530
+	if (!strlen($text)) {
532 531
 		if (!$o['force'])
533 532
 			return '';
534 533
 
@@ -537,8 +536,7 @@  discard block
 block discarded – undo
537 536
 		// pour les chaines non traduites, assurer un service minimum
538 537
 		if (!$GLOBALS['test_i18n'] AND (_request('var_mode') != 'traduction'))
539 538
 			$text = str_replace('_', ' ',
540
-				 (($n = strpos($text,':')) === false ? $texte :
541
-					substr($texte, $n+1)));
539
+				 (($n = strpos($text, ':')) === false ? $texte : substr($texte, $n + 1)));
542 540
 		$o['class'] = null;
543 541
 
544 542
 	}
@@ -550,21 +548,21 @@  discard block
 block discarded – undo
550 548
 // Remplacer les variables @....@ par leur valeur dans une chaine de langue.
551 549
 // Aussi appelee quand une chaine n'est pas encore dans les fichiers de langue
552 550
 // http://doc.spip.org/@_L
553
-function _L($text, $args=array(), $class=null) {
551
+function _L($text, $args = array(), $class = null) {
554 552
 	$f = $text;
555 553
 	if (is_array($args)) {
556 554
 		foreach ($args as $name => $value) {
557 555
 			if ($class)
558 556
 				$value = "<span class='$class'>$value</span>";
559
-			$t = str_replace ("@$name@", $value, $text);
560
-			if ($text !== $t) {unset($args[$name]); $text = $t;}
557
+			$t = str_replace("@$name@", $value, $text);
558
+			if ($text !== $t) {unset($args[$name]); $text = $t; }
561 559
 		}
562 560
 		// Si des variables n'ont pas ete inserees, le signaler
563 561
 		// (chaines de langues pas a jour)
564
-		if ($args) spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)),_LOG_DEBUG);
562
+		if ($args) spip_log("$f:  variables inutilisees ".join(', ', array_keys($args)), _LOG_DEBUG);
565 563
 	}
566 564
 
567
-	if (($GLOBALS['test_i18n'] OR (_request('var_mode') == 'traduction')) AND $class===null)
565
+	if (($GLOBALS['test_i18n'] OR (_request('var_mode') == 'traduction')) AND $class === null)
568 566
 		return "<span class=debug-traduction-erreur>$text</span>";
569 567
 	else
570 568
 		return $text;
@@ -574,9 +572,9 @@  discard block
 block discarded – undo
574 572
 // ou tmp/ au lieu de ../tmp/
575 573
 // http://doc.spip.org/@joli_repertoire
576 574
 function joli_repertoire($rep) {
577
-	$a = substr($rep,0,1);
578
-	if ($a<>'.' AND $a<>'/')
579
-		$rep = (_DIR_RESTREINT?'':_DIR_RESTREINT_ABS).$rep;
575
+	$a = substr($rep, 0, 1);
576
+	if ($a <> '.' AND $a <> '/')
577
+		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS).$rep;
580 578
 	$rep = preg_replace(',(^\.\.\/),', '', $rep);
581 579
 	return $rep;
582 580
 }
@@ -586,12 +584,12 @@  discard block
 block discarded – undo
586 584
 // spip_timer : on l'appelle deux fois et on a la difference, affichable
587 585
 //
588 586
 // http://doc.spip.org/@spip_timer
589
-function spip_timer($t='rien', $raw = false) {
587
+function spip_timer($t = 'rien', $raw = false) {
590 588
 	static $time;
591
-	$a=time(); $b=microtime();
589
+	$a = time(); $b = microtime();
592 590
 	// microtime peut contenir les microsecondes et le temps
593
-	$b=explode(' ',$b);
594
-	if (count($b)==2) $a = end($b); // plus precis !
591
+	$b = explode(' ', $b);
592
+	if (count($b) == 2) $a = end($b); // plus precis !
595 593
 	$b = reset($b);
596 594
 	if (!isset($time[$t])) {
597 595
 		$time[$t] = $a + $b;
@@ -603,10 +601,10 @@  discard block
 block discarded – undo
603 601
 		if ($p < 1000)
604 602
 			$s = '';
605 603
 		else {
606
-			$s = sprintf("%d ", $x = floor($p/1000));
607
-			$p -= ($x*1000);
604
+			$s = sprintf("%d ", $x = floor($p / 1000));
605
+			$p -= ($x * 1000);
608 606
 		}
609
-		return $s . sprintf($s?"%07.3f ms":"%.3f ms", $p);
607
+		return $s.sprintf($s ? "%07.3f ms" : "%.3f ms", $p);
610 608
 	}
611 609
 }
612 610
 
@@ -614,13 +612,13 @@  discard block
 block discarded – undo
614 612
 // Renvoie False si un fichier n'est pas plus vieux que $duree secondes,
615 613
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
616 614
 // http://doc.spip.org/@spip_touch
617
-function spip_touch($fichier, $duree=0, $touch=true) {
615
+function spip_touch($fichier, $duree = 0, $touch = true) {
618 616
 	if ($duree) {
619 617
 		clearstatcache();
620
-		if ((@$f=filemtime($fichier)) AND ($f >= time() - $duree))
618
+		if ((@$f = filemtime($fichier)) AND ($f >= time() - $duree))
621 619
 			return false;
622 620
 	}
623
-	if ($touch!==false) {
621
+	if ($touch !== false) {
624 622
 		if (!@touch($fichier)) { spip_unlink($fichier); @touch($fichier); };
625 623
 		@chmod($fichier, _SPIP_CHMOD & ~0111);
626 624
 	}
@@ -639,7 +637,7 @@  discard block
 block discarded – undo
639 637
 	include_spip('inc/headers');
640 638
 	http_status(204); // No Content
641 639
 	header("Connection: close");
642
-	define('_DIRECT_CRON_FORCE',true);
640
+	define('_DIRECT_CRON_FORCE', true);
643 641
 	cron();
644 642
 }
645 643
 
@@ -659,7 +657,7 @@  discard block
 block discarded – undo
659 657
  *   taches forcees, pour compat avec ancienne syntaxe
660 658
  * @return bool
661 659
  */
662
-function cron ($taches=array(), $taches_old= array()) {
660
+function cron($taches = array(), $taches_old = array()) {
663 661
 	// si pas en mode cron force, laisser tomber.
664 662
 	if (!defined('_DIRECT_CRON_FORCE')) return false;
665 663
 	if (!is_array($taches)) $taches = $taches_old; // compat anciens appels
@@ -668,7 +666,7 @@  discard block
 block discarded – undo
668 666
 	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
669 667
 	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
670 668
 	if ($taches AND count($taches) AND !spip_connect())  return false;
671
-	spip_log("cron !",'jq'._LOG_DEBUG);
669
+	spip_log("cron !", 'jq'._LOG_DEBUG);
672 670
 	if ($genie = charger_fonction('genie', 'inc', true)) {
673 671
 		return $genie($taches);
674 672
 	}
@@ -697,7 +695,7 @@  discard block
 block discarded – undo
697 695
  * @return int
698 696
  *	id of job
699 697
  */
700
-function job_queue_add($function, $description, $arguments = array(), $file = '', $no_duplicate = FALSE, $time=0, $priority=0) {
698
+function job_queue_add($function, $description, $arguments = array(), $file = '', $no_duplicate = FALSE, $time = 0, $priority = 0) {
701 699
 	include_spip('inc/queue');
702 700
 	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
703 701
 }
@@ -708,7 +706,7 @@  discard block
 block discarded – undo
708 706
  *  id of jonb to delete
709 707
  * @return bool
710 708
  */
711
-function job_queue_remove($id_job){
709
+function job_queue_remove($id_job) {
712 710
 	include_spip('inc/queue');
713 711
 	return queue_remove_job($id_job);
714 712
 }
@@ -721,9 +719,9 @@  discard block
 block discarded – undo
721 719
  *  can be a simple array('objet'=>'article','id_objet'=>23)
722 720
  *  or an array of simple array to link multiples objet in one time
723 721
  */
724
-function job_queue_link($id_job,$objets){
722
+function job_queue_link($id_job, $objets) {
725 723
 	include_spip('inc/queue');
726
-	return queue_link_job($id_job,$objets);
724
+	return queue_link_job($id_job, $objets);
727 725
 }
728 726
 
729 727
 
@@ -739,15 +737,15 @@  discard block
 block discarded – undo
739 737
  * @param int/bool $force_next
740 738
  * @return int
741 739
  */
742
-function queue_sleep_time_to_next_job($force=null) {
740
+function queue_sleep_time_to_next_job($force = null) {
743 741
 	static $queue_next_job_time = -1;
744
-	if ($force===true)
742
+	if ($force === true)
745 743
 		$queue_next_job_time = -1;
746 744
 	elseif ($force)
747 745
 		$queue_next_job_time = $force;
748 746
 
749
-	if ($queue_next_job_time==-1) {
750
-		define('_JQ_NEXT_JOB_TIME_FILENAME',_DIR_TMP . "job_queue_next.txt");
747
+	if ($queue_next_job_time == -1) {
748
+		define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP."job_queue_next.txt");
751 749
 		// utiliser un cache memoire si dispo
752 750
 		if (include_spip('inc/memoization') AND defined('_MEMOIZE_MEMORY') AND _MEMOIZE_MEMORY) {
753 751
 			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
@@ -763,7 +761,7 @@  discard block
 block discarded – undo
763 761
 		return null;
764 762
 	if (!$_SERVER['REQUEST_TIME'])
765 763
 		$_SERVER['REQUEST_TIME'] = time();
766
-	return $queue_next_job_time-$_SERVER['REQUEST_TIME'];
764
+	return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
767 765
 }
768 766
 
769 767
 
@@ -772,23 +770,23 @@  discard block
 block discarded – undo
772 770
 function quote_amp($u) {
773 771
 	return preg_replace(
774 772
 		"/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,5};)/i",
775
-		"&amp;",$u);
773
+		"&amp;", $u);
776 774
 }
777 775
 
778 776
 // Production d'une balise Script valide
779 777
 // http://doc.spip.org/@http_script
780
-function http_script($script, $src='', $noscript='') {
778
+function http_script($script, $src = '', $noscript = '') {
781 779
 	static $done = array();
782 780
 
783
-	if ($src && !isset($done[$src])){
781
+	if ($src && !isset($done[$src])) {
784 782
 		$done[$src] = true;
785 783
 		$src = find_in_path($src, _JAVASCRIPT);
786 784
 		$src = " src='$src'";
787 785
 	}
788 786
 	else $src = '';
789 787
 	if ($script)
790
-		$script = ("/*<![CDATA[*/\n" .
791
-		preg_replace(',</([^>]*)>,','<\/\1>', $script) .
788
+		$script = ("/*<![CDATA[*/\n".
789
+		preg_replace(',</([^>]*)>,', '<\/\1>', $script).
792 790
 		"/*]]>*/");
793 791
 	if ($noscript)
794 792
 		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
@@ -813,21 +811,20 @@  discard block
 block discarded – undo
813 811
 // du path, dans cet ordre.
814 812
 // Exception: si un $dossier_squelette est defini, il reste en tete, pour raison historique
815 813
 // http://doc.spip.org/@_chemin
816
-function _chemin($dir_path=NULL){
814
+function _chemin($dir_path = NULL) {
817 815
 	static $path_base = NULL;
818 816
 	static $path_full = NULL;
819
-	if ($path_base==NULL){
817
+	if ($path_base == NULL) {
820 818
 		// Chemin standard depuis l'espace public
821
-		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
822
-			_DIR_RACINE.':'.
819
+		$path = defined('_SPIP_PATH') ? _SPIP_PATH : _DIR_RACINE.':'.
823 820
 			_DIR_RACINE.'squelettes-dist/:'.
824 821
 			_DIR_RACINE.'prive/:'.
825 822
 			_DIR_RESTREINT;
826 823
 		// Ajouter squelettes/
827 824
 		if (@is_dir(_DIR_RACINE.'squelettes'))
828
-			$path = _DIR_RACINE.'squelettes/:' . $path;
825
+			$path = _DIR_RACINE.'squelettes/:'.$path;
829 826
 		foreach (explode(':', $path) as $dir) {
830
-			if (strlen($dir) AND substr($dir,-1) != '/')
827
+			if (strlen($dir) AND substr($dir, -1) != '/')
831 828
 				$dir .= "/";
832 829
 			$path_base[] = $dir;
833 830
 		}
@@ -835,32 +832,32 @@  discard block
 block discarded – undo
835 832
 		// Et le(s) dossier(s) des squelettes nommes
836 833
 		if (strlen($GLOBALS['dossier_squelettes']))
837 834
 			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
838
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
835
+				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE).$d.'/');
839 836
 		$GLOBALS['path_sig'] = md5(serialize($path_full));
840 837
 	}
841
-	if ($dir_path===NULL) return $path_full;
838
+	if ($dir_path === NULL) return $path_full;
842 839
 
843
-	if (strlen($dir_path)){
840
+	if (strlen($dir_path)) {
844 841
 		$tete = "";
845
-		if (reset($path_base)==_DIR_RACINE.'squelettes/')
842
+		if (reset($path_base) == _DIR_RACINE.'squelettes/')
846 843
 			$tete = array_shift($path_base);
847
-		$dirs = array_reverse(explode(':',$dir_path));
848
-		foreach($dirs as $dir_path){
844
+		$dirs = array_reverse(explode(':', $dir_path));
845
+		foreach ($dirs as $dir_path) {
849 846
 				#if ($dir_path{0}!='/')
850 847
 				#	$dir_path = $dir_path;
851
-				if (substr($dir_path,-1) != '/')
848
+				if (substr($dir_path, -1) != '/')
852 849
 					$dir_path .= "/";
853
-				if (!in_array($dir_path,$path_base))
854
-					array_unshift($path_base,$dir_path);
850
+				if (!in_array($dir_path, $path_base))
851
+					array_unshift($path_base, $dir_path);
855 852
 		}
856 853
 		if (strlen($tete))
857
-			array_unshift($path_base,$tete);
854
+			array_unshift($path_base, $tete);
858 855
 	}
859 856
 	$path_full = $path_base;
860 857
 	// Et le(s) dossier(s) des squelettes nommes
861 858
 	if (strlen($GLOBALS['dossier_squelettes']))
862 859
 		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
863
-			array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
860
+			array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE).$d.'/');
864 861
 
865 862
 	$GLOBALS['path_sig'] = md5(serialize($path_full));
866 863
 	return $path_full;
@@ -881,9 +878,9 @@  discard block
 block discarded – undo
881 878
 }
882 879
 
883 880
 
884
-function lister_themes_prives(){
881
+function lister_themes_prives() {
885 882
 	static $themes = null;
886
-	if (is_null($themes)){
883
+	if (is_null($themes)) {
887 884
 		// si pas encore definie
888 885
 		if (!defined('_SPIP_THEME_PRIVE'))
889 886
 			define('_SPIP_THEME_PRIVE', 'spip');
@@ -900,20 +897,20 @@  discard block
 block discarded – undo
900 897
 			((isset($prefs['theme']) AND $theme = $prefs['theme'])
901 898
 			OR (isset($GLOBALS['theme_prive_defaut']) AND $theme = $GLOBALS['theme_prive_defaut']))
902 899
 			AND $theme != _SPIP_THEME_PRIVE)
903
-			array_unshift($themes,$theme); // placer le theme choisi en tete
900
+			array_unshift($themes, $theme); // placer le theme choisi en tete
904 901
 	}
905 902
 	return $themes;
906 903
 }
907 904
 
908
-function find_in_theme($file, $subdir='', $include=false){
909
-	static $themefiles=array();
905
+function find_in_theme($file, $subdir = '', $include = false) {
906
+	static $themefiles = array();
910 907
 	if (isset($themefiles["$subdir$file"])) return $themefiles["$subdir$file"];
911 908
 	$themes = lister_themes_prives();
912
-	foreach($themes as $theme){
913
-		if ($f = find_in_path($file,"prive/themes/$theme/$subdir",$include))
909
+	foreach ($themes as $theme) {
910
+		if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include))
914 911
 			return $themefiles["$subdir$file"] = $f;
915 912
 	}
916
-	spip_log("$file introuvable dans le theme prive ".reset($themes),'theme');
913
+	spip_log("$file introuvable dans le theme prive ".reset($themes), 'theme');
917 914
 	return $themefiles["$subdir$file"] = "";
918 915
 }
919 916
 
@@ -923,23 +920,23 @@  discard block
 block discarded – undo
923 920
 // peut se trouver dans un dossier plugin, donc on passe par un find_in_path si elle n'est pas
924 921
 // dans _DIR_IMG_PACK
925 922
 // http://doc.spip.org/@chemin_image
926
-function chemin_image($icone){
923
+function chemin_image($icone) {
927 924
 	static $icone_renommer;
928 925
 	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
929
-	if (strpos($icone,"/")!==false AND file_exists($icone)) return $icone;
926
+	if (strpos($icone, "/") !== false AND file_exists($icone)) return $icone;
930 927
 	
931 928
 	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
932
-	if (preg_match(',[.](png|gif|jpg)$,',$icone) AND $f = find_in_theme("images/$icone"))
929
+	if (preg_match(',[.](png|gif|jpg)$,', $icone) AND $f = find_in_theme("images/$icone"))
933 930
 		return $f;
934 931
 	// sinon passer par le module de renommage
935 932
 	if (is_null($icone_renommer))
936
-		$icone_renommer = charger_fonction('icone_renommer','inc',true);
937
-	if ($icone_renommer){
938
-		list($icone,$fonction) = $icone_renommer($icone,"");
933
+		$icone_renommer = charger_fonction('icone_renommer', 'inc', true);
934
+	if ($icone_renommer) {
935
+		list($icone, $fonction) = $icone_renommer($icone, "");
939 936
 		if (file_exists($icone))
940 937
 			return $icone;
941 938
 	}
942
-	return find_in_path ($icone, _NOM_IMG_PACK);
939
+	return find_in_path($icone, _NOM_IMG_PACK);
943 940
 }
944 941
 
945 942
 //
@@ -950,13 +947,13 @@  discard block
 block discarded – undo
950 947
 $GLOBALS['path_files'] = null;
951 948
 
952 949
 // http://doc.spip.org/@find_in_path
953
-function find_in_path ($file, $dirname='', $include=false) {
954
-	static $dirs=array();
950
+function find_in_path($file, $dirname = '', $include = false) {
951
+	static $dirs = array();
955 952
 	static $inc = array(); # cf http://trac.rezo.net/trac/spip/changeset/14743
956 953
 	static $c = '';
957 954
 
958 955
 	// on calcule le chemin si le dossier skel a change
959
-	if ($c != $GLOBALS['dossier_squelettes']){
956
+	if ($c != $GLOBALS['dossier_squelettes']) {
960 957
 		// assurer le non plantage lors de la montee de version :
961 958
 		$c = $GLOBALS['dossier_squelettes'];
962 959
 		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
@@ -966,40 +963,40 @@  discard block
 block discarded – undo
966 963
 		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])
967 964
 			return false;
968 965
 		if ($include AND !isset($inc[$dirname][$file])) {
969
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
970
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
966
+			include_once _ROOT_CWD.$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
967
+			$inc[$dirname][$file] = $inc[''][$dirname.$file] = true;
971 968
 		}
972 969
 		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
973 970
 	}
974 971
 
975
-	$a = strrpos($file,'/');
972
+	$a = strrpos($file, '/');
976 973
 	if ($a !== false) {
977 974
 		$dirname .= substr($file, 0, ++$a);
978 975
 		$file = substr($file, $a);
979 976
 	}
980 977
 
981
-	foreach(creer_chemin() as $dir) {
982
-		if (!isset($dirs[$a = $dir . $dirname]))
983
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a) ;
978
+	foreach (creer_chemin() as $dir) {
979
+		if (!isset($dirs[$a = $dir.$dirname]))
980
+			$dirs[$a] = (is_dir(_ROOT_CWD.$a) || !$a);
984 981
 		if ($dirs[$a]) {
985
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
982
+			if (file_exists(_ROOT_CWD.($a .= $file))) {
986 983
 				if ($include AND !isset($inc[$dirname][$file])) {
987
-					include_once _ROOT_CWD . $a;
988
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
984
+					include_once _ROOT_CWD.$a;
985
+					$inc[$dirname][$file] = $inc[''][$dirname.$file] = true;
989 986
 				}
990
-				if (!defined('_SAUVER_CHEMIN')){
987
+				if (!defined('_SAUVER_CHEMIN')) {
991 988
 					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
992 989
 					if (is_null($GLOBALS['path_files'])) return $a;
993 990
 					define('_SAUVER_CHEMIN', true);
994 991
 				}
995
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
992
+				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname.$file] = $a;
996 993
 			}
997 994
 		}
998 995
 	}
999 996
 
1000
-	if ($include){
997
+	if ($include) {
1001 998
 		spip_log("include_spip $dirname$file non trouve");
1002
-		if ($include==='required'){
999
+		if ($include === 'required') {
1003 1000
 			echo '<pre>',
1004 1001
 			"<strong>Erreur Fatale</strong><br />";
1005 1002
 			if (function_exists('debug_print_backtrace'))
@@ -1009,21 +1006,21 @@  discard block
 block discarded – undo
1009 1006
 		}
1010 1007
 	}
1011 1008
 
1012
-	if (!defined('_SAUVER_CHEMIN')){
1009
+	if (!defined('_SAUVER_CHEMIN')) {
1013 1010
 		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1014 1011
 		if (is_null($GLOBALS['path_files'])) return false;
1015 1012
 		define('_SAUVER_CHEMIN', true);
1016 1013
 	}
1017
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1014
+	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname.$file] = false;
1018 1015
 }
1019 1016
 
1020
-function clear_path_cache(){
1017
+function clear_path_cache() {
1021 1018
 	$GLOBALS['path_files'] = array();
1022 1019
 	spip_unlink(_CACHE_CHEMIN);
1023 1020
 }
1024
-function load_path_cache(){
1021
+function load_path_cache() {
1025 1022
 	// charger le path des plugins
1026
-	if (@is_readable(_CACHE_PLUGINS_PATH)){
1023
+	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1027 1024
 		include_once(_CACHE_PLUGINS_PATH);
1028 1025
 	}
1029 1026
 	$GLOBALS['path_files'] = array();
@@ -1037,23 +1034,23 @@  discard block
 block discarded – undo
1037 1034
 		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1038 1035
 		// et en ignorant ce cache en cas de recalcul explicite
1039 1036
 		!_request('var_mode')
1040
-		){
1037
+		) {
1041 1038
 		// on essaye de lire directement sans verrou pour aller plus vite
1042
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)){
1039
+		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1043 1040
 			// mais si semble corrompu on relit avec un verrou
1044
-			if (!$GLOBALS['path_files']=unserialize($contenu)){
1045
-				lire_fichier(_CACHE_CHEMIN,$contenu);
1046
-				if (!$GLOBALS['path_files']=unserialize($contenu))
1041
+			if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1042
+				lire_fichier(_CACHE_CHEMIN, $contenu);
1043
+				if (!$GLOBALS['path_files'] = unserialize($contenu))
1047 1044
 					$GLOBALS['path_files'] = array();
1048 1045
 			}
1049 1046
 		}
1050 1047
 	}
1051 1048
 }
1052 1049
 
1053
-function save_path_cache(){
1050
+function save_path_cache() {
1054 1051
 	if (defined('_SAUVER_CHEMIN')
1055 1052
 		AND _SAUVER_CHEMIN)
1056
-		ecrire_fichier(_CACHE_CHEMIN,serialize($GLOBALS['path_files']));
1053
+		ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1057 1054
 }
1058 1055
 
1059 1056
 
@@ -1068,16 +1065,16 @@  discard block
 block discarded – undo
1068 1065
  * @return array
1069 1066
  */
1070 1067
 // http://doc.spip.org/@find_all_in_path
1071
-function find_all_in_path($dir,$pattern, $recurs=false){
1072
-	$liste_fichiers=array();
1068
+function find_all_in_path($dir, $pattern, $recurs = false) {
1069
+	$liste_fichiers = array();
1073 1070
 	$maxfiles = 10000;
1074 1071
 
1075 1072
 	// Parcourir le chemin
1076 1073
 	foreach (creer_chemin() as $d) {
1077 1074
 		$f = $d.$dir;
1078
-		if (@is_dir($f)){
1079
-			$liste = preg_files($f,$pattern,$maxfiles-count($liste_fichiers),$recurs===true?array():$recurs);
1080
-			foreach($liste as $chemin){
1075
+		if (@is_dir($f)) {
1076
+			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? array() : $recurs);
1077
+			foreach ($liste as $chemin) {
1081 1078
 				$nom = basename($chemin);
1082 1079
 				// ne prendre que les fichiers pas deja trouves
1083 1080
 				// car find_in_path prend le premier qu'il trouve,
@@ -1124,7 +1121,7 @@  discard block
 block discarded – undo
1124 1121
  *   array : derogatoire, la fonction d'url retourne (objet,id_objet) utilises par nettoyer_raccourcis_typo() pour generer un lien titre
1125 1122
  *           (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_url_spip et une fonction generer_url_ecrire_spip)
1126 1123
  */
1127
-function generer_url_entite($id='', $entite='', $args='', $ancre='', $public=NULL, $type=NULL)
1124
+function generer_url_entite($id = '', $entite = '', $args = '', $ancre = '', $public = NULL, $type = NULL)
1128 1125
 {
1129 1126
 	if ($public === NULL) $public = !test_espace_prive();
1130 1127
 	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
@@ -1133,12 +1130,12 @@  discard block
 block discarded – undo
1133 1130
 		if (!$entite) return '';
1134 1131
 		if (!function_exists('generer_url_ecrire_objet'))
1135 1132
 			include_spip('inc/urls');
1136
-		$res = generer_url_ecrire_objet($entite,$id, $args, $ancre, false);
1133
+		$res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false);
1137 1134
 	} else {
1138 1135
 		if ($type === NULL) {
1139 1136
 			$type = ($GLOBALS['type_urls'] === 'page'
1140 1137
 				AND $GLOBALS['meta']['type_urls'])
1141
-			?  $GLOBALS['meta']['type_urls']
1138
+			? $GLOBALS['meta']['type_urls']
1142 1139
 			:  $GLOBALS['type_urls']; // pour SPIP <2
1143 1140
 		}
1144 1141
 
@@ -1161,7 +1158,7 @@  discard block
 block discarded – undo
1161 1158
 	}
1162 1159
 	if ($res) return $res;
1163 1160
 	// Sinon c'est un raccourci ou compat SPIP < 2
1164
-	if (!function_exists($f = 'generer_url_' . $entite)) {
1161
+	if (!function_exists($f = 'generer_url_'.$entite)) {
1165 1162
 		if (!function_exists($f .= '_dist')) $f = '';
1166 1163
 	}
1167 1164
 	if ($f) {
@@ -1177,23 +1174,23 @@  discard block
 block discarded – undo
1177 1174
 	return '';
1178 1175
 }
1179 1176
 
1180
-function generer_url_ecrire_entite_edit($id, $entite, $args='', $ancre=''){
1181
-	$exec = objet_info($entite,'url_edit');
1182
-	$url = generer_url_ecrire($exec,$args);
1177
+function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') {
1178
+	$exec = objet_info($entite, 'url_edit');
1179
+	$url = generer_url_ecrire($exec, $args);
1183 1180
 	if (intval($id))
1184
-		$url = parametre_url($url,id_table_objet($entite),$id);
1181
+		$url = parametre_url($url, id_table_objet($entite), $id);
1185 1182
 	else
1186
-		$url = parametre_url($url,'new','oui');
1183
+		$url = parametre_url($url, 'new', 'oui');
1187 1184
 	if ($ancre)
1188
-		$url = ancre_url($url,$ancre);
1185
+		$url = ancre_url($url, $ancre);
1189 1186
 	return $url;
1190 1187
 }
1191 1188
 
1192 1189
 // http://doc.spip.org/@urls_connect_dist
1193
-function urls_connect_dist($i, &$entite, $args='', $ancre='', $public=null) {
1190
+function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) {
1194 1191
 	include_spip('base/connect_sql');
1195
-	$id_type = id_table_objet($entite,$public);
1196
-	return _DIR_RACINE . get_spip_script('./')
1192
+	$id_type = id_table_objet($entite, $public);
1193
+	return _DIR_RACINE.get_spip_script('./')
1197 1194
 	  . "?"._SPIP_PAGE."=$entite&$id_type=$i&connect=$public"
1198 1195
 	  . (!$args ? '' : "&$args")
1199 1196
 	  . (!$ancre ? '' : "#$ancre");
@@ -1202,9 +1199,9 @@  discard block
 block discarded – undo
1202 1199
 
1203 1200
 // Transformer les caracteres utf8 d'une URL (farsi par ex) selon la RFC 1738
1204 1201
 function urlencode_1738($url) {
1205
-	if (preg_match(',[^\x00-\x7E],sS', $url)){
1202
+	if (preg_match(',[^\x00-\x7E],sS', $url)) {
1206 1203
 		$uri = '';
1207
-		for ($i=0; $i < strlen($url); $i++) {
1204
+		for ($i = 0; $i < strlen($url); $i++) {
1208 1205
 			if (ord($a = $url[$i]) > 127)
1209 1206
 				$a = rawurlencode($a);
1210 1207
 			$uri .= $a;
@@ -1215,7 +1212,7 @@  discard block
 block discarded – undo
1215 1212
 }
1216 1213
 
1217 1214
 // http://doc.spip.org/@generer_url_entite_absolue
1218
-function generer_url_entite_absolue($id='', $entite='', $args='', $ancre='', $connect=NULL)
1215
+function generer_url_entite_absolue($id = '', $entite = '', $args = '', $ancre = '', $connect = NULL)
1219 1216
 {
1220 1217
 	if (!$connect) $connect = true;
1221 1218
 	$h = generer_url_entite($id, $entite, $args, $ancre, $connect);
@@ -1254,11 +1251,11 @@  discard block
 block discarded – undo
1254 1251
  *    si array : reinitialise le tableau static complet avec la valeur fournie
1255 1252
  * @return string|array
1256 1253
  */
1257
-function url_de_base($profondeur=null) {
1254
+function url_de_base($profondeur = null) {
1258 1255
 
1259 1256
 	static $url = array();
1260 1257
 	if (is_array($profondeur)) return $url = $profondeur;
1261
-	if ($profondeur===false) return $url;
1258
+	if ($profondeur === false) return $url;
1262 1259
 
1263 1260
 	if (is_null($profondeur)) $profondeur = $GLOBALS['profondeur_url'];
1264 1261
 
@@ -1267,7 +1264,7 @@  discard block
 block discarded – undo
1267 1264
 
1268 1265
 	$http = (
1269 1266
 		(isset($_SERVER["SCRIPT_URI"]) AND
1270
-			substr($_SERVER["SCRIPT_URI"],0,5) == 'https')
1267
+			substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https')
1271 1268
 		OR (isset($_SERVER['HTTPS']) AND
1272 1269
 		    test_valeur_serveur($_SERVER['HTTPS']))
1273 1270
 	) ? 'https' : 'http';
@@ -1282,12 +1279,12 @@  discard block
 block discarded – undo
1282 1279
 		}
1283 1280
 	}
1284 1281
 	if (isset($_SERVER['SERVER_PORT'])
1285
-		AND $port=$_SERVER['SERVER_PORT']
1286
-		AND strpos($host,":")==false){
1287
-		if ($http=="http" AND $port!=80) $host.=":$port";
1288
-		if ($http=="https" AND $port!=443) $host.=":$port";
1282
+		AND $port = $_SERVER['SERVER_PORT']
1283
+		AND strpos($host, ":") == false) {
1284
+		if ($http == "http" AND $port != 80) $host .= ":$port";
1285
+		if ($http == "https" AND $port != 443) $host .= ":$port";
1289 1286
 	}
1290
-	if (!$GLOBALS['REQUEST_URI']){
1287
+	if (!$GLOBALS['REQUEST_URI']) {
1291 1288
 		if (isset($_SERVER['REQUEST_URI'])) {
1292 1289
 			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1293 1290
 		} else {
@@ -1298,7 +1295,7 @@  discard block
 block discarded – undo
1298 1295
 		}
1299 1296
 	}
1300 1297
 
1301
-	$url[$profondeur] = url_de_($http,$host,$GLOBALS['REQUEST_URI'],$profondeur);
1298
+	$url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
1302 1299
 
1303 1300
 	return $url[$profondeur];
1304 1301
 }
@@ -1310,25 +1307,25 @@  discard block
 block discarded – undo
1310 1307
  * @param int $prof
1311 1308
  * @return string
1312 1309
  */
1313
-function url_de_($http,$host,$request,$prof=0){
1314
-	$prof = max($prof,0);
1310
+function url_de_($http, $host, $request, $prof = 0) {
1311
+	$prof = max($prof, 0);
1315 1312
 
1316
-	$myself = ltrim($request,'/');
1313
+	$myself = ltrim($request, '/');
1317 1314
 	# supprimer la chaine de GET
1318 1315
 	list($myself) = explode('?', $myself);
1319 1316
 	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
1320 1317
 	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
1321
-	if (strpos($myself,'://') !== false) {
1322
-		$myself = explode('://',$myself);
1318
+	if (strpos($myself, '://') !== false) {
1319
+		$myself = explode('://', $myself);
1323 1320
 		array_shift($myself);
1324
-		$myself = implode('://',$myself);
1325
-		$myself = explode('/',$myself);
1321
+		$myself = implode('://', $myself);
1322
+		$myself = explode('/', $myself);
1326 1323
 		array_shift($myself);
1327
-		$myself = implode('/',$myself);
1324
+		$myself = implode('/', $myself);
1328 1325
 	}
1329
-	$url = join('/', array_slice(explode('/', $myself), 0, -1-$prof)).'/';
1326
+	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)).'/';
1330 1327
 
1331
-	$url = $http.'://'.rtrim($host,'/').'/'.ltrim($url,'/');
1328
+	$url = $http.'://'.rtrim($host, '/').'/'.ltrim($url, '/');
1332 1329
 	return $url;
1333 1330
 }
1334 1331
 
@@ -1342,24 +1339,23 @@  discard block
 block discarded – undo
1342 1339
 // http://httpd.apache.org/docs/2.0/mod/mod_dir.html
1343 1340
 
1344 1341
 // http://doc.spip.org/@generer_url_ecrire
1345
-function generer_url_ecrire($script='', $args="", $no_entities=false, $rel=false) {
1342
+function generer_url_ecrire($script = '', $args = "", $no_entities = false, $rel = false) {
1346 1343
 	if (!$rel)
1347
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
1344
+		$rel = url_de_base()._DIR_RESTREINT_ABS._SPIP_ECRIRE_SCRIPT;
1348 1345
 	else if (!is_string($rel))
1349
-		$rel = _DIR_RESTREINT ? _DIR_RESTREINT :
1350
-			('./'  . _SPIP_ECRIRE_SCRIPT);
1346
+		$rel = _DIR_RESTREINT ? _DIR_RESTREINT : ('./'._SPIP_ECRIRE_SCRIPT);
1351 1347
 
1352 1348
 	@list($script, $ancre) = explode('#', $script);
1353
-	if ($script AND ($script<>'accueil' OR $rel))
1354
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
1349
+	if ($script AND ($script <> 'accueil' OR $rel))
1350
+		$args = "?exec=$script".(!$args ? '' : "&$args");
1355 1351
 	elseif ($args)
1356
-		$args ="?$args";
1352
+		$args = "?$args";
1357 1353
 	if ($ancre) $args .= "#$ancre";
1358
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
1354
+	return $rel.($no_entities ? $args : str_replace('&', '&amp;', $args));
1359 1355
 }
1360 1356
 
1361 1357
 // http://doc.spip.org/@generer_url_retour
1362
-function generer_url_retour($script, $args="")
1358
+function generer_url_retour($script, $args = "")
1363 1359
 {
1364 1360
 	return rawurlencode(generer_url_ecrire($script, $args, true, true));
1365 1361
 }
@@ -1371,7 +1367,7 @@  discard block
 block discarded – undo
1371 1367
 // Detecter le fichier de base, a la racine, comme etant spip.php ou ''
1372 1368
 // dans le cas de '', un $default = './' peut servir (comme dans urls/page.php)
1373 1369
 // http://doc.spip.org/@get_spip_script
1374
-function get_spip_script($default='') {
1370
+function get_spip_script($default = '') {
1375 1371
 	# cas define('_SPIP_SCRIPT', '');
1376 1372
 	if (_SPIP_SCRIPT)
1377 1373
 		return _SPIP_SCRIPT;
@@ -1380,7 +1376,7 @@  discard block
 block discarded – undo
1380 1376
 }
1381 1377
 
1382 1378
 // http://doc.spip.org/@generer_url_public
1383
-function generer_url_public($script='', $args="", $no_entities=false, $rel=true, $action='') {
1379
+function generer_url_public($script = '', $args = "", $no_entities = false, $rel = true, $action = '') {
1384 1380
 	// si le script est une action (spip_pass, spip_inscription),
1385 1381
 	// standardiser vers la nouvelle API
1386 1382
 
@@ -1391,23 +1387,23 @@  discard block
 block discarded – undo
1391 1387
 	if ($args) {
1392 1388
 		if (is_array($args)) {
1393 1389
 			$r = '';
1394
-			foreach($args as $k => $v) $r .= '&' . $k . '=' . $v;
1395
-			$args = substr($r,1);
1390
+			foreach ($args as $k => $v) $r .= '&'.$k.'='.$v;
1391
+			$args = substr($r, 1);
1396 1392
 		}
1397 1393
 		$action .=
1398
-			(strpos($action, '?') !== false ? '&' : '?') . $args;
1394
+			(strpos($action, '?') !== false ? '&' : '?').$args;
1399 1395
 	}
1400 1396
 	if (!$no_entities)
1401 1397
 		$action = quote_amp($action);
1402 1398
 
1403 1399
 	// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
1404
-	return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(),'/') . preg_replace(",^/[.]/,","/","/$action"));
1400
+	return ($rel ? _DIR_RACINE.$action : rtrim(url_de_base(), '/').preg_replace(",^/[.]/,", "/", "/$action"));
1405 1401
 }
1406 1402
 
1407 1403
 // http://doc.spip.org/@generer_url_prive
1408
-function generer_url_prive($script, $args="", $no_entities=false) {
1404
+function generer_url_prive($script, $args = "", $no_entities = false) {
1409 1405
 
1410
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS .  'prive.php');
1406
+	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS.'prive.php');
1411 1407
 }
1412 1408
 
1413 1409
 // Pour les formulaires en methode POST,
@@ -1416,7 +1412,7 @@  discard block
 block discarded – undo
1416 1412
 // 2) ca suit http://en.wikipedia.org/wiki/Representational_State_Transfer
1417 1413
 
1418 1414
 // http://doc.spip.org/@generer_form_ecrire
1419
-function generer_form_ecrire($script, $corps, $atts='', $submit='') {
1415
+function generer_form_ecrire($script, $corps, $atts = '', $submit = '') {
1420 1416
 	global $spip_lang_right;
1421 1417
 
1422 1418
 	$script1 = explode('&', $script);
@@ -1429,8 +1425,7 @@  discard block
 block discarded – undo
1429 1425
 	.  "><div>\n"
1430 1426
 	. "<input type='hidden' name='exec' value='$script1' />"
1431 1427
 	. $corps
1432
-	. (!$submit ? '' :
1433
-	     ("<div style='text-align: $spip_lang_right'><input class='fondo' type='submit' value=\"".entites_html($submit)."\" /></div>"))
1428
+	. (!$submit ? '' : ("<div style='text-align: $spip_lang_right'><input class='fondo' type='submit' value=\"".entites_html($submit)."\" /></div>"))
1434 1429
 	. "</div></form>\n";
1435 1430
 }
1436 1431
 
@@ -1448,7 +1443,7 @@  discard block
 block discarded – undo
1448 1443
  * @param bool $public
1449 1444
  * @return string
1450 1445
  */
1451
-function generer_form_action($script, $corps, $atts='', $public=false) {
1446
+function generer_form_action($script, $corps, $atts = '', $public = false) {
1452 1447
 	// si l'on est dans l'espace prive, on garde dans l'url
1453 1448
 	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
1454 1449
 	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
@@ -1456,29 +1451,29 @@  discard block
 block discarded – undo
1456 1451
 	? generer_url_ecrire(_request('exec'))
1457 1452
 	: generer_url_public();
1458 1453
 
1459
-	return "\n<form action='" .
1460
-	  $h .
1461
-	  "'" .
1462
-	  $atts .
1463
-	  ">\n" .
1464
-	  "<div>" .
1465
-  	  "\n<input type='hidden' name='action' value='$script' />" .
1466
-	  $corps .
1454
+	return "\n<form action='".
1455
+	  $h.
1456
+	  "'".
1457
+	  $atts.
1458
+	  ">\n".
1459
+	  "<div>".
1460
+  	  "\n<input type='hidden' name='action' value='$script' />".
1461
+	  $corps.
1467 1462
 	  "</div></form>";
1468 1463
 }
1469 1464
 
1470 1465
 // http://doc.spip.org/@generer_url_action
1471
-function generer_url_action($script, $args="", $no_entities=false , $public = false) {
1466
+function generer_url_action($script, $args = "", $no_entities = false, $public = false) {
1472 1467
 	// si l'on est dans l'espace prive, on garde dans l'url
1473 1468
 	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
1474 1469
 	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
1475
-	$url = (_DIR_RACINE  AND !$public)
1470
+	$url = (_DIR_RACINE AND !$public)
1476 1471
 	  ? generer_url_ecrire(_request('exec'))
1477
-	  :  generer_url_public('','',false,false);
1478
-	$url = parametre_url($url,'action',$script);
1472
+	  :  generer_url_public('', '', false, false);
1473
+	$url = parametre_url($url, 'action', $script);
1479 1474
 	if ($args) $url .= quote_amp('&'.$args);
1480 1475
 
1481
-	if ($no_entities) $url = str_replace('&amp;','&',$url);
1476
+	if ($no_entities) $url = str_replace('&amp;', '&', $url);
1482 1477
 	return $url;
1483 1478
 }
1484 1479
 
@@ -1491,8 +1486,8 @@  discard block
 block discarded – undo
1491 1486
  * @param string $ti
1492 1487
  * @param string $ta
1493 1488
  */
1494
-function spip_initialisation($pi=NULL, $pa=NULL, $ti=NULL, $ta=NULL) {
1495
-	spip_initialisation_core($pi,$pa,$ti,$ta);
1489
+function spip_initialisation($pi = NULL, $pa = NULL, $ti = NULL, $ta = NULL) {
1490
+	spip_initialisation_core($pi, $pa, $ti, $ta);
1496 1491
 	spip_initialisation_suite();
1497 1492
 }
1498 1493
 
@@ -1510,32 +1505,32 @@  discard block
 block discarded – undo
1510 1505
  * @param string $ti
1511 1506
  * @param string $ta
1512 1507
  */
1513
-function spip_initialisation_core($pi=NULL, $pa=NULL, $ti=NULL, $ta=NULL) {
1508
+function spip_initialisation_core($pi = NULL, $pa = NULL, $ti = NULL, $ta = NULL) {
1514 1509
 	static $too_late = 0;
1515 1510
 	if ($too_late++) return;
1516 1511
 	
1517 1512
 	// Declaration des repertoires
1518 1513
 
1519 1514
 	// le nom du repertoire plugins/ activables/desactivables
1520
-	if (!defined('_DIR_PLUGINS')) define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
1515
+	if (!defined('_DIR_PLUGINS')) define('_DIR_PLUGINS', _DIR_RACINE."plugins/");
1521 1516
 
1522 1517
 	// le nom du repertoire des extensions/ permanentes du core, toujours actives
1523
-	if (!defined('_DIR_PLUGINS_DIST')) define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
1518
+	if (!defined('_DIR_PLUGINS_DIST')) define('_DIR_PLUGINS_DIST', _DIR_RACINE."plugins-dist/");
1524 1519
 
1525 1520
 	// le nom du repertoire des librairies
1526
-	if (!defined('_DIR_LIB')) define('_DIR_LIB', _DIR_RACINE . "lib/");
1521
+	if (!defined('_DIR_LIB')) define('_DIR_LIB', _DIR_RACINE."lib/");
1527 1522
 	
1528 1523
 	if (!defined('_DIR_IMG')) define('_DIR_IMG', $pa);
1529 1524
 	if (!defined('_DIR_LOGOS')) define('_DIR_LOGOS', $pa);
1530
-	if (!defined('_DIR_IMG_ICONES')) define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
1531
-
1532
-	if (!defined('_DIR_DUMP')) define('_DIR_DUMP', $ti . "dump/");
1533
-	if (!defined('_DIR_SESSIONS')) define('_DIR_SESSIONS', $ti . "sessions/");
1534
-	if (!defined('_DIR_TRANSFERT')) define('_DIR_TRANSFERT', $ti . "upload/");
1535
-	if (!defined('_DIR_CACHE')) define('_DIR_CACHE', $ti . "cache/");
1536
-	if (!defined('_DIR_CACHE_XML')) define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
1537
-	if (!defined('_DIR_SKELS')) define('_DIR_SKELS',  _DIR_CACHE . "skel/");
1538
-	if (!defined('_DIR_AIDE')) define('_DIR_AIDE',  _DIR_CACHE . "aide/");
1525
+	if (!defined('_DIR_IMG_ICONES')) define('_DIR_IMG_ICONES', _DIR_LOGOS."icones/");
1526
+
1527
+	if (!defined('_DIR_DUMP')) define('_DIR_DUMP', $ti."dump/");
1528
+	if (!defined('_DIR_SESSIONS')) define('_DIR_SESSIONS', $ti."sessions/");
1529
+	if (!defined('_DIR_TRANSFERT')) define('_DIR_TRANSFERT', $ti."upload/");
1530
+	if (!defined('_DIR_CACHE')) define('_DIR_CACHE', $ti."cache/");
1531
+	if (!defined('_DIR_CACHE_XML')) define('_DIR_CACHE_XML', _DIR_CACHE."xml/");
1532
+	if (!defined('_DIR_SKELS')) define('_DIR_SKELS', _DIR_CACHE."skel/");
1533
+	if (!defined('_DIR_AIDE')) define('_DIR_AIDE', _DIR_CACHE."aide/");
1539 1534
 	if (!defined('_DIR_TMP')) define('_DIR_TMP', $ti);
1540 1535
 
1541 1536
 	if (!defined('_DIR_VAR')) define('_DIR_VAR', $ta);
@@ -1547,19 +1542,19 @@  discard block
 block discarded – undo
1547 1542
 	if (!isset($GLOBALS['test_dirs']))
1548 1543
 	  // Pas $pi car il est bon de le mettre hors ecriture apres intstall
1549 1544
 	  // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
1550
-		$GLOBALS['test_dirs'] =  array($pa, $ti, $ta);
1545
+		$GLOBALS['test_dirs'] = array($pa, $ti, $ta);
1551 1546
 
1552 1547
 	// Declaration des fichiers
1553 1548
 
1554
-	if (!defined('_CACHE_PLUGINS_PATH')) define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
1555
-	if (!defined('_CACHE_PLUGINS_OPT')) define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
1556
-	if (!defined('_CACHE_PLUGINS_FCT')) define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
1557
-	if (!defined('_CACHE_PIPELINES')) define('_CACHE_PIPELINES',  _DIR_CACHE."charger_pipelines.php");
1558
-	if (!defined('_CACHE_CHEMIN')) define('_CACHE_CHEMIN',  _DIR_CACHE."chemin.txt");
1549
+	if (!defined('_CACHE_PLUGINS_PATH')) define('_CACHE_PLUGINS_PATH', _DIR_CACHE."charger_plugins_chemins.php");
1550
+	if (!defined('_CACHE_PLUGINS_OPT')) define('_CACHE_PLUGINS_OPT', _DIR_CACHE."charger_plugins_options.php");
1551
+	if (!defined('_CACHE_PLUGINS_FCT')) define('_CACHE_PLUGINS_FCT', _DIR_CACHE."charger_plugins_fonctions.php");
1552
+	if (!defined('_CACHE_PIPELINES')) define('_CACHE_PIPELINES', _DIR_CACHE."charger_pipelines.php");
1553
+	if (!defined('_CACHE_CHEMIN')) define('_CACHE_CHEMIN', _DIR_CACHE."chemin.txt");
1559 1554
 
1560 1555
 	# attention .php obligatoire pour ecrire_fichier_securise
1561
-	if (!defined('_FILE_META')) define('_FILE_META', $ti . 'meta_cache.php');
1562
-	if (!defined('_DIR_LOG')) define('_DIR_LOG', _DIR_TMP . 'log/');
1556
+	if (!defined('_FILE_META')) define('_FILE_META', $ti.'meta_cache.php');
1557
+	if (!defined('_DIR_LOG')) define('_DIR_LOG', _DIR_TMP.'log/');
1563 1558
 	if (!defined('_FILE_LOG')) define('_FILE_LOG', 'spip');
1564 1559
 	if (!defined('_FILE_LOG_SUFFIX')) define('_FILE_LOG_SUFFIX', '.log');
1565 1560
 
@@ -1567,21 +1562,21 @@  discard block
 block discarded – undo
1567 1562
 	// tient compte des anciennes versions (inc_connect...)
1568 1563
 	if (!defined('_FILE_CONNECT_INS')) define('_FILE_CONNECT_INS', 'connect');
1569 1564
 	if (!defined('_FILE_CONNECT')) define('_FILE_CONNECT',
1570
-		(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
1571
-	:	(@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
1565
+		(@is_readable($f = _DIR_CONNECT._FILE_CONNECT_INS.'.php') ? $f
1566
+	:	(@is_readable($f = _DIR_RESTREINT.'inc_connect.php') ? $f
1572 1567
 	:	false)));
1573 1568
 
1574 1569
 	// Le fichier de reglages des droits
1575 1570
 	if (!defined('_FILE_CHMOD_INS')) define('_FILE_CHMOD_INS', 'chmod');
1576 1571
 	if (!defined('_FILE_CHMOD')) define('_FILE_CHMOD',
1577
-		(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
1572
+		(@is_readable($f = _DIR_CHMOD._FILE_CHMOD_INS.'.php') ? $f
1578 1573
 	:	false));
1579 1574
 
1580 1575
 	if (!defined('_FILE_LDAP')) define('_FILE_LDAP', 'ldap.php');
1581 1576
 
1582 1577
 	if (!defined('_FILE_TMP_SUFFIX')) define('_FILE_TMP_SUFFIX', '.tmp.php');
1583
-	if (!defined('_FILE_CONNECT_TMP')) define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
1584
-	if (!defined('_FILE_CHMOD_TMP')) define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
1578
+	if (!defined('_FILE_CONNECT_TMP')) define('_FILE_CONNECT_TMP', _DIR_CONNECT._FILE_CONNECT_INS._FILE_TMP_SUFFIX);
1579
+	if (!defined('_FILE_CHMOD_TMP')) define('_FILE_CHMOD_TMP', _DIR_CHMOD._FILE_CHMOD_INS._FILE_TMP_SUFFIX);
1585 1580
 
1586 1581
 	// Definition des droits d'acces en ecriture
1587 1582
 	if (!defined('_SPIP_CHMOD') AND _FILE_CHMOD)
@@ -1592,31 +1587,31 @@  discard block
 block discarded – undo
1592 1587
 
1593 1588
 	// Le charset par defaut lors de l'installation
1594 1589
 	if (!defined('_DEFAULT_CHARSET')) define('_DEFAULT_CHARSET', 'utf-8');
1595
-	if (!defined('_ROOT_PLUGINS')) define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
1596
-	if (!defined('_ROOT_PLUGINS_DIST')) define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
1597
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE,'',_DIR_PLUGINS_SUPPL));
1590
+	if (!defined('_ROOT_PLUGINS')) define('_ROOT_PLUGINS', _ROOT_RACINE."plugins/");
1591
+	if (!defined('_ROOT_PLUGINS_DIST')) define('_ROOT_PLUGINS_DIST', _ROOT_RACINE."plugins-dist/");
1592
+	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE.str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
1598 1593
 
1599 1594
 	// La taille des Log
1600 1595
 	if (!defined('_MAX_LOG')) define('_MAX_LOG', 100);
1601 1596
 
1602 1597
 	// Sommes-nous dans l'empire du Mal ?
1603 1598
 	// (ou sous le signe du Pingouin, ascendant GNU ?)
1604
-	if (strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false){
1599
+	if (strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
1605 1600
 		if (!defined('_OS_SERVEUR')) define('_OS_SERVEUR', 'windows');
1606
-		if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',1); // utiliser le flock php
1601
+		if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE', 1); // utiliser le flock php
1607 1602
 	}
1608 1603
 	else {
1609 1604
 		if (!defined('_OS_SERVEUR')) define('_OS_SERVEUR', '');
1610
-		if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',1); // utiliser le flock php
1605
+		if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE', 1); // utiliser le flock php
1611 1606
 		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
1612 1607
 	}
1613 1608
 
1614 1609
 	// Langue par defaut
1615
-	if (!defined('_LANGUE_PAR_DEFAUT')) define('_LANGUE_PAR_DEFAUT','fr');
1610
+	if (!defined('_LANGUE_PAR_DEFAUT')) define('_LANGUE_PAR_DEFAUT', 'fr');
1616 1611
 
1617 1612
 	// PHP_VERSION_ID dispo depuis PHP 5.2.7
1618 1613
 	if (!defined('PHP_VERSION_ID')) {
1619
-	   $version = explode('.',PHP_VERSION);
1614
+	   $version = explode('.', PHP_VERSION);
1620 1615
 	   define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
1621 1616
 	}
1622 1617
 
@@ -1625,7 +1620,7 @@  discard block
 block discarded – undo
1625 1620
 	// (non surchargeable en l'etat ; attention si on utilise include_spip()
1626 1621
 	// pour le rendre surchargeable, on va provoquer un reecriture
1627 1622
 	// systematique du noyau ou une baisse de perfs => a etudier)
1628
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
1623
+	include_once _ROOT_RESTREINT.'inc/flock.php';
1629 1624
 
1630 1625
 	// charger tout de suite le path et son cache
1631 1626
 	load_path_cache();
@@ -1645,7 +1640,7 @@  discard block
 block discarded – undo
1645 1640
 	spip_desinfecte($_REQUEST);
1646 1641
 
1647 1642
 	// Par ailleurs on ne veut pas de magic_quotes au cours de l'execution
1648
-	if (PHP_VERSION_ID<50300) {
1643
+	if (PHP_VERSION_ID < 50300) {
1649 1644
 		@set_magic_quotes_runtime(0);
1650 1645
 	}
1651 1646
 
@@ -1655,7 +1650,7 @@  discard block
 block discarded – undo
1655 1650
 	if (test_valeur_serveur(@ini_get('register_globals'))) {
1656 1651
 		// ne pas desinfecter les globales en profondeur car elle contient aussi les
1657 1652
 		// precedentes, qui seraient desinfectees 2 fois.
1658
-		spip_desinfecte($GLOBALS,false);
1653
+		spip_desinfecte($GLOBALS, false);
1659 1654
 		if (include_spip('inc/php3'))
1660 1655
 			spip_register_globals(true);
1661 1656
 
@@ -1699,8 +1694,8 @@  discard block
 block discarded – undo
1699 1694
 	$inc_meta();
1700 1695
 
1701 1696
 	// on a pas pu le faire plus tot
1702
-	if  ($avertir_register_globals)
1703
-		avertir_auteurs("register_globals",_L("Probl&egrave;me de s&eacute;curit&eacute; : register_globals=on; dans php.ini &agrave; corriger."));
1697
+	if ($avertir_register_globals)
1698
+		avertir_auteurs("register_globals", _L("Probl&egrave;me de s&eacute;curit&eacute; : register_globals=on; dans php.ini &agrave; corriger."));
1704 1699
 
1705 1700
 	// nombre de repertoires depuis la racine
1706 1701
 	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
@@ -1716,7 +1711,7 @@  discard block
 block discarded – undo
1716 1711
 			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
1717 1712
 			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
1718 1713
 			// s'en remettre a l'adresse du site. alea jacta est.
1719
-			OR $ti!==_NOM_TEMPORAIRES_INACCESSIBLES){
1714
+			OR $ti !== _NOM_TEMPORAIRES_INACCESSIBLES) {
1720 1715
 
1721 1716
 			if (isset($GLOBALS['meta']['adresse_site'])) {
1722 1717
 				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
@@ -1730,12 +1725,12 @@  discard block
 block discarded – undo
1730 1725
 		else {
1731 1726
 			$GLOBALS['profondeur_url'] = max(0,
1732 1727
 				substr_count($uri[0], '/')
1733
-				- substr_count($uri_ref,'/'));
1728
+				- substr_count($uri_ref, '/'));
1734 1729
 		}
1735 1730
 	}
1736 1731
 	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
1737 1732
 	if (_FILE_CONNECT) {
1738
-		if (verifier_visiteur()=='0minirezo'
1733
+		if (verifier_visiteur() == '0minirezo'
1739 1734
 			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
1740 1735
 		  AND !isset($_COOKIE['spip_admin']))
1741 1736
 			clear_path_cache();
@@ -1765,7 +1760,7 @@  discard block
 block discarded – undo
1765 1760
 	if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
1766 1761
 	if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
1767 1762
 	if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
1768
-	if (!defined('_PASS_LONGUEUR_MINI')) define('_PASS_LONGUEUR_MINI',6);
1763
+	if (!defined('_PASS_LONGUEUR_MINI')) define('_PASS_LONGUEUR_MINI', 6);
1769 1764
 
1770 1765
 
1771 1766
 	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
@@ -1775,7 +1770,7 @@  discard block
 block discarded – undo
1775 1770
 	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
1776 1771
         if (!defined('_IMG_IMAGICK_QUALITE')) define('_IMG_IMAGICK_QUALITE', 75); # surcharge pour imagick en PHP
1777 1772
 
1778
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) define('_COPIE_LOCALE_MAX_SIZE',16777216); // poids en octet
1773
+	if (!defined('_COPIE_LOCALE_MAX_SIZE')) define('_COPIE_LOCALE_MAX_SIZE', 16777216); // poids en octet
1779 1774
 
1780 1775
 	// qq chaines standard
1781 1776
 	if (!defined('_ACCESS_FILE_NAME')) define('_ACCESS_FILE_NAME', '.htaccess');
@@ -1807,7 +1802,7 @@  discard block
 block discarded – undo
1807 1802
 	// meme pb sur thttpd cf. http://forum.spip.org/fr_184153.html
1808 1803
 
1809 1804
 	if (!defined('_SPIP_ECRIRE_SCRIPT')) define('_SPIP_ECRIRE_SCRIPT', // true ? #decommenter ici et commenter la
1810
-	       preg_match(',IIS|thttpd,',$_SERVER['SERVER_SOFTWARE']) ?
1805
+	       preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE']) ?
1811 1806
 	       'index.php' : '');
1812 1807
 
1813 1808
 
@@ -1830,32 +1825,32 @@  discard block
 block discarded – undo
1830 1825
 	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
1831 1826
 	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
1832 1827
 	if (!defined('_IMG_GD_MAX_PIXELS')) define('_IMG_GD_MAX_PIXELS',
1833
-		(isset($GLOBALS['meta']['max_taille_vignettes'])&&$GLOBALS['meta']['max_taille_vignettes']<5500000)
1828
+		(isset($GLOBALS['meta']['max_taille_vignettes']) && $GLOBALS['meta']['max_taille_vignettes'] < 5500000)
1834 1829
 		 ? $GLOBALS['meta']['max_taille_vignettes']
1835 1830
 		 : 0);
1836 1831
 
1837
-	if (!defined('_MEMORY_LIMIT_MIN')) define('_MEMORY_LIMIT_MIN',10); // en Mo
1832
+	if (!defined('_MEMORY_LIMIT_MIN')) define('_MEMORY_LIMIT_MIN', 10); // en Mo
1838 1833
 	// si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
1839 1834
 	// on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
1840 1835
 	// il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
1841
-	if (test_espace_prive() AND _MEMORY_LIMIT_MIN>8){
1836
+	if (test_espace_prive() AND _MEMORY_LIMIT_MIN > 8) {
1842 1837
 		if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
1843
-			$unit = strtolower(substr($memory,strlen($memory/1),1));
1844
-			switch($unit) {
1838
+			$unit = strtolower(substr($memory, strlen($memory / 1), 1));
1839
+			switch ($unit) {
1845 1840
 				// Le modifieur 'G' est disponible depuis PHP 5.1.0
1846 1841
 				case 'g': $memory *= 1024;
1847 1842
 				case 'm': $memory *= 1024;
1848 1843
 				case 'k': $memory *= 1024;
1849 1844
 			}
1850
-			if ($memory<_MEMORY_LIMIT_MIN*1024*1024){
1851
-				ini_set('memory_limit',$m=_MEMORY_LIMIT_MIN.'M');
1852
-				if (trim(ini_get('memory_limit'))!=$m){
1853
-					if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) define('_INTERDIRE_COMPACTE_HEAD_ECRIRE',true); // evite une page blanche car on ne saura pas calculer la css dans ce hit
1845
+			if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
1846
+				ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN.'M');
1847
+				if (trim(ini_get('memory_limit')) != $m) {
1848
+					if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); // evite une page blanche car on ne saura pas calculer la css dans ce hit
1854 1849
 				}
1855 1850
 			}
1856 1851
 		}
1857 1852
 		else
1858
-			if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) define('_INTERDIRE_COMPACTE_HEAD_ECRIRE',true); // evite une page blanche car on ne saura pas calculer la css dans ce hit
1853
+			if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); // evite une page blanche car on ne saura pas calculer la css dans ce hit
1859 1854
 	}
1860 1855
 	// Protocoles a normaliser dans les chaines de langues
1861 1856
 	if (!defined('_PROTOCOLES_STD'))
@@ -1867,7 +1862,7 @@  discard block
 block discarded – undo
1867 1862
 // Reperer les variables d'URL qui conditionnent la perennite du cache, des urls
1868 1863
 // ou d'autres petit caches (trouver_table, css et js compactes ...)
1869 1864
 // http://doc.spip.org/@init_var_mode
1870
-function init_var_mode(){
1865
+function init_var_mode() {
1871 1866
 	static $done = false;
1872 1867
 	if (!$done) {
1873 1868
 
@@ -1875,56 +1870,56 @@  discard block
 block discarded – undo
1875 1870
 			// tout le monde peut calcul/recalcul
1876 1871
 			if ($_GET['var_mode'] == 'calcul'
1877 1872
 			OR $_GET['var_mode'] == 'recalcul') {
1878
-				if (!defined('_VAR_MODE')) define('_VAR_MODE',$_GET['var_mode']);
1873
+				if (!defined('_VAR_MODE')) define('_VAR_MODE', $_GET['var_mode']);
1879 1874
 			}
1880 1875
 			// preview, debug, blocs, urls et images necessitent une autorisation
1881
-			else if (in_array($_GET['var_mode'],array('preview','debug','inclure','urls','images','traduction'))) {
1876
+			else if (in_array($_GET['var_mode'], array('preview', 'debug', 'inclure', 'urls', 'images', 'traduction'))) {
1882 1877
 				include_spip('inc/autoriser');
1883 1878
 				if (autoriser(
1884 1879
 					($_GET['var_mode'] == 'preview')
1885 1880
 						? 'previsualiser'
1886 1881
 						: 'debug'
1887 1882
 				)) {
1888
-					switch($_GET['var_mode']){
1883
+					switch ($_GET['var_mode']) {
1889 1884
 						case 'traduction':
1890 1885
 							// forcer le calcul pour passer dans traduire
1891
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1886
+							if (!defined('_VAR_MODE')) define('_VAR_MODE', 'calcul');
1892 1887
 							// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
1893
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1888
+							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE', true);
1894 1889
 							break;
1895 1890
 						case 'preview':
1896 1891
 							// basculer sur les criteres de preview dans les boucles
1897
-							if (!defined('_VAR_PREVIEW')) define('_VAR_PREVIEW',true);
1892
+							if (!defined('_VAR_PREVIEW')) define('_VAR_PREVIEW', true);
1898 1893
 							// forcer le calcul
1899
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1894
+							if (!defined('_VAR_MODE')) define('_VAR_MODE', 'calcul');
1900 1895
 							// et ne pas enregistrer de cache
1901
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1896
+							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE', true);
1902 1897
 							break;
1903 1898
 						case 'inclure':
1904 1899
 							// forcer le compilo et ignorer les caches existants
1905
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1906
-							if (!defined('_VAR_INCLURE')) define('_VAR_INCLURE',true);
1900
+							if (!defined('_VAR_MODE')) define('_VAR_MODE', 'calcul');
1901
+							if (!defined('_VAR_INCLURE')) define('_VAR_INCLURE', true);
1907 1902
 							// et ne pas enregistrer de cache
1908
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1903
+							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE', true);
1909 1904
 							break;
1910 1905
 						case 'urls':
1911 1906
 							// forcer le compilo et ignorer les caches existants
1912
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1913
-							if (!defined('_VAR_URLS')) define('_VAR_URLS',true);
1907
+							if (!defined('_VAR_MODE')) define('_VAR_MODE', 'calcul');
1908
+							if (!defined('_VAR_URLS')) define('_VAR_URLS', true);
1914 1909
 							break;
1915 1910
 						case 'images':
1916 1911
 							// forcer le compilo et ignorer les caches existants
1917
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1912
+							if (!defined('_VAR_MODE')) define('_VAR_MODE', 'calcul');
1918 1913
 							// indiquer qu'on doit recalculer les images
1919
-							if (!defined('_VAR_IMAGES')) define('_VAR_IMAGES',true);
1914
+							if (!defined('_VAR_IMAGES')) define('_VAR_IMAGES', true);
1920 1915
 							break;
1921 1916
 						case 'debug':
1922
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','debug');
1917
+							if (!defined('_VAR_MODE')) define('_VAR_MODE', 'debug');
1923 1918
 							// et ne pas enregistrer de cache
1924
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1919
+							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE', true);
1925 1920
 							break;
1926 1921
 						default :
1927
-							if (!defined('_VAR_MODE')) define('_VAR_MODE',$_GET['var_mode']);
1922
+							if (!defined('_VAR_MODE')) define('_VAR_MODE', $_GET['var_mode']);
1928 1923
 							break;
1929 1924
 					}
1930 1925
           if (isset($GLOBALS['visiteur_session']['nom']))
@@ -1944,7 +1939,7 @@  discard block
 block discarded – undo
1944 1939
 					// sinon tant pis
1945 1940
 				}
1946 1941
 			}
1947
-			if (!defined('_VAR_MODE')) define('_VAR_MODE',false);
1942
+			if (!defined('_VAR_MODE')) define('_VAR_MODE', false);
1948 1943
 		}
1949 1944
 		$done = true;
1950 1945
 	}
@@ -1954,7 +1949,7 @@  discard block
 block discarded – undo
1954 1949
 // supprimer aussi les eventuels caracteres nuls %00, qui peuvent tromper
1955 1950
 // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal')
1956 1951
 // http://doc.spip.org/@spip_desinfecte
1957
-function spip_desinfecte(&$t,$deep = true) {
1952
+function spip_desinfecte(&$t, $deep = true) {
1958 1953
 	static $magic_quotes;
1959 1954
 	if (!isset($magic_quotes))
1960 1955
 		$magic_quotes = @get_magic_quotes_gpc();
@@ -1966,8 +1961,8 @@  discard block
 block discarded – undo
1966 1961
 			$t[$key] = str_replace(chr(0), '-', $t[$key]);
1967 1962
 		}
1968 1963
 		// traiter aussi les "texte_plus" de article_edit
1969
-		else if ($deep AND is_array($t[$key]) AND $key!=='GLOBALS')
1970
-			spip_desinfecte($t[$key],$deep);
1964
+		else if ($deep AND is_array($t[$key]) AND $key !== 'GLOBALS')
1965
+			spip_desinfecte($t[$key], $deep);
1971 1966
 	}
1972 1967
 }
1973 1968
 
@@ -1980,10 +1975,10 @@  discard block
 block discarded – undo
1980 1975
 	// mais on risque de perturber des plugins en initialisant trop tot
1981 1976
 	// certaines constantes
1982 1977
 	@spip_initialisation_core(
1983
-		(_DIR_RACINE  . _NOM_PERMANENTS_INACCESSIBLES),
1984
-		(_DIR_RACINE  . _NOM_PERMANENTS_ACCESSIBLES),
1985
-		(_DIR_RACINE  . _NOM_TEMPORAIRES_INACCESSIBLES),
1986
-		(_DIR_RACINE  . _NOM_TEMPORAIRES_ACCESSIBLES)
1978
+		(_DIR_RACINE._NOM_PERMANENTS_INACCESSIBLES),
1979
+		(_DIR_RACINE._NOM_PERMANENTS_ACCESSIBLES),
1980
+		(_DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES),
1981
+		(_DIR_RACINE._NOM_TEMPORAIRES_ACCESSIBLES)
1987 1982
 	);
1988 1983
 
1989 1984
 	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
@@ -1991,7 +1986,7 @@  discard block
 block discarded – undo
1991 1986
 	// Attention on separe bien session_nom et nom, pour eviter
1992 1987
 	// les melanges entre donnees SQL et variables plus aleatoires
1993 1988
 	$variables_session = array('session_nom', 'session_email');
1994
-	foreach($variables_session as $var) {
1989
+	foreach ($variables_session as $var) {
1995 1990
 		if (_request($var) !== null) {
1996 1991
 			$init = true;
1997 1992
 			break;
@@ -2002,7 +1997,7 @@  discard block
 block discarded – undo
2002 1997
 		$session = charger_fonction('session', 'inc');
2003 1998
 		$session();
2004 1999
 		include_spip('inc/texte');
2005
-		foreach($variables_session as $var)
2000
+		foreach ($variables_session as $var)
2006 2001
 			if (($a = _request($var)) !== null)
2007 2002
 				$GLOBALS['visiteur_session'][$var] = safehtml($a);
2008 2003
 		if (!isset($GLOBALS['visiteur_session']['id_auteur']))
@@ -2011,14 +2006,14 @@  discard block
 block discarded – undo
2011 2006
 		return 0;
2012 2007
 	}
2013 2008
 
2014
-	$h = (isset($_SERVER['PHP_AUTH_USER'])  AND !$GLOBALS['ignore_auth_http']);
2009
+	$h = (isset($_SERVER['PHP_AUTH_USER']) AND !$GLOBALS['ignore_auth_http']);
2015 2010
 	if ($h OR isset($_COOKIE['spip_session']) OR isset($_COOKIE[$GLOBALS['cookie_prefix'].'_session'])) {
2016 2011
 
2017 2012
 		$session = charger_fonction('session', 'inc');
2018 2013
 		if ($session()) {
2019 2014
 			return $GLOBALS['visiteur_session']['statut'];
2020 2015
 		}
2021
-		if ($h  AND isset($_SERVER['PHP_AUTH_PW'])) {
2016
+		if ($h AND isset($_SERVER['PHP_AUTH_PW'])) {
2022 2017
 			include_spip('inc/auth');
2023 2018
 			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
2024 2019
 		}
@@ -2043,7 +2038,7 @@  discard block
 block discarded – undo
2043 2038
 // cette fonction retourne toujours non False
2044 2039
 
2045 2040
 // http://doc.spip.org/@lang_select
2046
-function lang_select ($lang=NULL) {
2041
+function lang_select($lang = NULL) {
2047 2042
 	static $pile_langues = array();
2048 2043
 	if (!function_exists('changer_langue'))
2049 2044
 		include_spip('inc/lang');
@@ -2073,7 +2068,7 @@  discard block
 block discarded – undo
2073 2068
 		$s = pipeline('definir_session',
2074 2069
 			$GLOBALS['visiteur_session']
2075 2070
 			? serialize($GLOBALS['visiteur_session'])
2076
-				. '_' . @$_COOKIE['spip_session']
2071
+				. '_'.@$_COOKIE['spip_session']
2077 2072
 			: ''
2078 2073
 		);
2079 2074
 		$session = $s ? substr(md5($s), 0, 8) : '';
@@ -2095,9 +2090,9 @@  discard block
 block discarded – undo
2095 2090
  * @return Lien sur une icone d'aide
2096 2091
 **/
2097 2092
 // http://doc.spip.org/@aide
2098
-function aide($aide='', $distante = false) {
2093
+function aide($aide = '', $distante = false) {
2099 2094
 		$aider = charger_fonction('aider', 'inc', true);
2100
-	return $aider ?  $aider($aide, '', array(), $distante) : '';
2095
+	return $aider ? $aider($aide, '', array(), $distante) : '';
2101 2096
 }
2102 2097
 
2103 2098
 // normalement il faudrait creer exec/info.php, mais pour mettre juste ca:
@@ -2126,7 +2121,7 @@  discard block
 block discarded – undo
2126 2121
  * 		Rien dans la plupart des cas
2127 2122
  * 		- string si $message à false.
2128 2123
 **/
2129
-function erreur_squelette($message='', $lieu='') {
2124
+function erreur_squelette($message = '', $lieu = '') {
2130 2125
 	$debusquer = charger_fonction('debusquer', 'public');
2131 2126
 	if (is_array($lieu)) {
2132 2127
 		include_spip('public/compiler');
@@ -2166,15 +2161,15 @@  discard block
 block discarded – undo
2166 2161
  * 		Contenu du squelette calculé
2167 2162
  * 		ou tableau d'information sur le squelette.
2168 2163
  */
2169
-function recuperer_fond($fond, $contexte=array(), $options = array(), $connect='') {
2164
+function recuperer_fond($fond, $contexte = array(), $options = array(), $connect = '') {
2170 2165
 	if (!function_exists('evaluer_fond'))
2171 2166
 		include_spip('public/assembler');
2172 2167
 	// assurer la compat avec l'ancienne syntaxe
2173 2168
 	// (trim etait le 3eme argument, par defaut a true)
2174 2169
 	if (!is_array($options)) $options = array('trim'=>$options);
2175
-	if (!isset($options['trim'])) $options['trim']=true;
2170
+	if (!isset($options['trim'])) $options['trim'] = true;
2176 2171
 
2177
-	if (isset($contexte['connect'])){
2172
+	if (isset($contexte['connect'])) {
2178 2173
 		$connect = ($connect ? $connect : $contexte['connect']);
2179 2174
 		unset($contexte['connect']);
2180 2175
 	}
@@ -2182,7 +2177,7 @@  discard block
 block discarded – undo
2182 2177
 	$texte = "";
2183 2178
 	$pages = array();
2184 2179
 	$lang_select = '';
2185
-	if (!isset($options['etoile']) OR !$options['etoile']){
2180
+	if (!isset($options['etoile']) OR !$options['etoile']) {
2186 2181
 		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
2187 2182
 		if (!isset($contexte['lang']))
2188 2183
 			$contexte['lang'] = $GLOBALS['spip_lang'];
@@ -2194,10 +2189,10 @@  discard block
 block discarded – undo
2194 2189
 
2195 2190
 	@$GLOBALS['_INC_PUBLIC']++;
2196 2191
 
2197
-	foreach(is_array($fond) ? $fond : array($fond) as $f){
2192
+	foreach (is_array($fond) ? $fond : array($fond) as $f) {
2198 2193
 		$page = evaluer_fond($f, $contexte, $connect);
2199 2194
 		if ($page === '') {
2200
-			$c = isset($options['compil']) ? $options['compil'] :'';
2195
+			$c = isset($options['compil']) ? $options['compil'] : '';
2201 2196
 			$a = array('fichier'=>$fond);
2202 2197
 			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
2203 2198
 			erreur_squelette($erreur, $c);
@@ -2205,14 +2200,14 @@  discard block
 block discarded – undo
2205 2200
 			$page = array('texte' => '', 'erreur' => $erreur);
2206 2201
 		}
2207 2202
 
2208
-		$page = pipeline('recuperer_fond',array(
2209
-			'args'=>array('fond'=>$f,'contexte'=>$contexte,'options'=>$options,'connect'=>$connect),
2203
+		$page = pipeline('recuperer_fond', array(
2204
+			'args'=>array('fond'=>$f, 'contexte'=>$contexte, 'options'=>$options, 'connect'=>$connect),
2210 2205
 			'data'=>$page
2211 2206
 		));
2212
-		if (isset($options['ajax']) AND $options['ajax']){
2207
+		if (isset($options['ajax']) AND $options['ajax']) {
2213 2208
 			if (!function_exists('encoder_contexte_ajax'))
2214 2209
 				include_spip('inc/filtres');
2215
-			$page['texte'] = encoder_contexte_ajax(array_merge($contexte,array('fond'=>$f)),'',$page['texte'], $options['ajax']);
2210
+			$page['texte'] = encoder_contexte_ajax(array_merge($contexte, array('fond'=>$f)), '', $page['texte'], $options['ajax']);
2216 2211
 		}
2217 2212
 
2218 2213
 		if (isset($options['raw']) AND $options['raw'])
@@ -2225,7 +2220,7 @@  discard block
 block discarded – undo
2225 2220
 
2226 2221
 	if ($lang_select) lang_select();
2227 2222
 	if (isset($options['raw']) AND $options['raw'])
2228
-		return is_array($fond)?$pages:reset($pages);
2223
+		return is_array($fond) ? $pages : reset($pages);
2229 2224
 	else
2230 2225
 		return $options['trim'] ? ltrim($texte) : $texte;
2231 2226
 }
@@ -2237,7 +2232,7 @@  discard block
 block discarded – undo
2237 2232
  * @return string
2238 2233
  */
2239 2234
 function trouve_modele($nom) {
2240
-	return trouver_fond($nom,'modeles/');
2235
+	return trouver_fond($nom, 'modeles/');
2241 2236
 }
2242 2237
 
2243 2238
 /**
@@ -2252,8 +2247,8 @@  discard block
 block discarded – undo
2252 2247
  * @param bool $pathinfo
2253 2248
  * @return array|string
2254 2249
  */
2255
-function trouver_fond($nom, $dir='', $pathinfo = false) {
2256
-	$f = find_in_path($nom.'.'. _EXTENSION_SQUELETTES, $dir?rtrim($dir,'/').'/':'');
2250
+function trouver_fond($nom, $dir = '', $pathinfo = false) {
2251
+	$f = find_in_path($nom.'.'._EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/').'/' : '');
2257 2252
 	if (!$pathinfo) return $f;
2258 2253
 	// renvoyer un tableau detaille si $pathinfo==true
2259 2254
 	$p = pathinfo($f);
@@ -2261,14 +2256,14 @@  discard block
 block discarded – undo
2261 2256
 		$p['extension'] = _EXTENSION_SQUELETTES;
2262 2257
 	}
2263 2258
 	if (!isset($p['extension']) OR !$p['filename']) {
2264
-		$p['filename'] = ($p['basename']?substr($p['basename'],0,-strlen($p['extension'])-1):'');
2259
+		$p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
2265 2260
 	}
2266
-	$p['fond'] = ($f?substr($f,0,-strlen($p['extension'])-1):'');
2261
+	$p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
2267 2262
 	return $p;
2268 2263
 }
2269 2264
 
2270
-function tester_url_ecrire($nom){
2271
-	static $exec=array();
2265
+function tester_url_ecrire($nom) {
2266
+	static $exec = array();
2272 2267
 	if (isset($exec[$nom])) return $exec[$nom];
2273 2268
 	// tester si c'est une page en squelette
2274 2269
 	if (trouver_fond($nom, 'prive/squelettes/contenu/'))
@@ -2277,12 +2272,12 @@  discard block
 block discarded – undo
2277 2272
 	elseif (trouver_fond($nom, 'prive/exec/'))
2278 2273
 		return $exec[$nom] = 'fond_monobloc';
2279 2274
 	// echafaudage d'un fond !
2280
-	elseif(include_spip('public/styliser_par_z') AND z_echafaudable($nom))
2275
+	elseif (include_spip('public/styliser_par_z') AND z_echafaudable($nom))
2281 2276
 		return $exec[$nom] = 'fond';
2282 2277
 	// attention, il ne faut pas inclure l'exec ici
2283 2278
 	// car sinon #URL_ECRIRE provoque des inclusions
2284 2279
 	// et des define intrusifs potentiels
2285
-	return $exec[$nom] = ((find_in_path("{$nom}.php",'exec/') OR charger_fonction($nom,'exec',true))?$nom:'');
2280
+	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') OR charger_fonction($nom, 'exec', true)) ? $nom : '');
2286 2281
 }
2287 2282
 
2288 2283
 // Charger dynamiquement une extension php
@@ -2291,7 +2286,7 @@  discard block
 block discarded – undo
2291 2286
 	if (extension_loaded($module)) {
2292 2287
 		return true;
2293 2288
 	} else {
2294
-		$charger_php_extension = charger_fonction('charger_php_extension','inc');
2289
+		$charger_php_extension = charger_fonction('charger_php_extension', 'inc');
2295 2290
 		return $charger_php_extension($module);
2296 2291
 	}
2297 2292
 }
@@ -2320,13 +2315,13 @@  discard block
 block discarded – undo
2320 2315
 
2321 2316
 // Fonction depreciee, cf. http://doc.spip.org/@sql_fetch
2322 2317
 // http://doc.spip.org/@spip_fetch_array
2323
-function spip_fetch_array($r, $t=NULL) {
2318
+function spip_fetch_array($r, $t = NULL) {
2324 2319
 	if (!isset($t)) {
2325 2320
 		if ($r) return sql_fetch($r);
2326 2321
 	} else {
2327
-		if ($t=='SPIP_NUM') $t = MYSQL_NUM;
2328
-		if ($t=='SPIP_BOTH') $t = MYSQL_BOTH;
2329
-		if ($t=='SPIP_ASSOC') $t = MYSQL_ASSOC;
2322
+		if ($t == 'SPIP_NUM') $t = MYSQL_NUM;
2323
+		if ($t == 'SPIP_BOTH') $t = MYSQL_BOTH;
2324
+		if ($t == 'SPIP_ASSOC') $t = MYSQL_ASSOC;
2330 2325
 		spip_log("appel deprecie de spip_fetch_array(..., $t)", 'vieilles_defs');
2331 2326
 		if ($r) return mysql_fetch_array($r, $t);
2332 2327
 	}
@@ -2342,7 +2337,7 @@  discard block
 block discarded – undo
2342 2337
  * @param string $message
2343 2338
  * @param string $statut
2344 2339
  */
2345
-function avertir_auteurs($nom,$message, $statut=''){
2340
+function avertir_auteurs($nom, $message, $statut = '') {
2346 2341
 	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
2347 2342
 	if (!$alertes
2348 2343
 		OR !is_array($alertes = unserialize($alertes)))
@@ -2351,6 +2346,6 @@  discard block
 block discarded – undo
2351 2346
 	if (!isset($alertes[$statut]))
2352 2347
 		$alertes[$statut] = array();
2353 2348
 	$alertes[$statut][$nom] = $message;
2354
-	ecrire_meta("message_alertes_auteurs",serialize($alertes));
2349
+	ecrire_meta("message_alertes_auteurs", serialize($alertes));
2355 2350
 }
2356 2351
 ?>
Please login to merge, or discard this patch.
Braces   +804 added lines, -393 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 //
16 18
 // Utilitaires indispensables autour du serveur Http.
@@ -32,19 +34,28 @@  discard block
 block discarded – undo
32 34
 function charger_fonction($nom, $dossier='exec', $continue=false) {
33 35
 	static $echecs = array();
34 36
 
35
-	if (strlen($dossier) AND substr($dossier,-1) != '/') $dossier .= '/';
37
+	if (strlen($dossier) AND substr($dossier,-1) != '/') {
38
+	    $dossier .= '/';
39
+	}
36 40
 	$f = str_replace('/','_',$dossier) . $nom;
37 41
 
38
-	if (function_exists($f))
39
-		return $f;
40
-	if (function_exists($g = $f . '_dist'))
41
-		return $g;
42
+	if (function_exists($f)) {
43
+			return $f;
44
+	}
45
+	if (function_exists($g = $f . '_dist')) {
46
+			return $g;
47
+	}
42 48
 
43
-	if (isset($echecs[$f])) return $echecs[$f];
49
+	if (isset($echecs[$f])) {
50
+	    return $echecs[$f];
51
+	}
44 52
 	// Sinon charger le fichier de declaration si plausible
45 53
 
46 54
 	if (!preg_match(',^\w+$,', $f)){
47
-		if ($continue) return false; //appel interne, on passe
55
+		if ($continue) {
56
+		    return false;
57
+		}
58
+		//appel interne, on passe
48 59
 		include_spip('inc/minipres');
49 60
 		echo minipres();
50 61
 		exit;
@@ -55,12 +66,19 @@  discard block
 block discarded – undo
55 66
 	if (!$inc = include_spip($dossier.($d = strtolower($nom)))
56 67
 		// si le fichier truc/machin/nom.php n'existe pas,
57 68
 		// la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
58
-		AND strlen(dirname($dossier)) AND dirname($dossier)!='.')
59
-		include_spip(substr($dossier,0,-1));
60
-	if (function_exists($f)) return $f;
61
-	if (function_exists($g)) return $g;
69
+		AND strlen(dirname($dossier)) AND dirname($dossier)!='.') {
70
+			include_spip(substr($dossier,0,-1));
71
+	}
72
+	if (function_exists($f)) {
73
+	    return $f;
74
+	}
75
+	if (function_exists($g)) {
76
+	    return $g;
77
+	}
62 78
 
63
-	if ($continue) return $echecs[$f] = false;
79
+	if ($continue) {
80
+	    return $echecs[$f] = false;
81
+	}
64 82
 
65 83
 	// Echec : message d'erreur
66 84
 	spip_log("fonction $nom ($f ou $g) indisponible" .
@@ -115,14 +133,15 @@  discard block
 block discarded – undo
115 133
 // http://doc.spip.org/@minipipe
116 134
 function minipipe($fonc,&$val){
117 135
 	// fonction
118
-	if (function_exists($fonc))
119
-		$val = call_user_func($fonc, $val);
136
+	if (function_exists($fonc)) {
137
+			$val = call_user_func($fonc, $val);
138
+	}
120 139
 	// Class::Methode
121 140
 	else if (preg_match("/^(\w*)::(\w*)$/S", $fonc, $regs)
122 141
 	AND $methode = array($regs[1], $regs[2])
123
-	AND is_callable($methode))
124
-		$val = call_user_func($methode, $val);
125
-	else {
142
+	AND is_callable($methode)) {
143
+			$val = call_user_func($methode, $val);
144
+	} else {
126 145
 		spip_log("Erreur - '$fonc' non definie !");
127 146
 	}
128 147
 	return $val;
@@ -140,8 +159,9 @@  discard block
 block discarded – undo
140 159
 			// generer les fichiers php precompiles
141 160
 			// de chargement des plugins et des pipelines
142 161
 			actualise_plugins_actifs();
143
-			if (!($ok = @is_readable($charger)))
144
-				spip_log("fichier $charger pas cree");
162
+			if (!($ok = @is_readable($charger))) {
163
+							spip_log("fichier $charger pas cree");
164
+			}
145 165
 		}
146 166
 
147 167
 		if ($ok) {
@@ -164,8 +184,9 @@  discard block
 block discarded – undo
164 184
 	// array_key_exists pour php 4.1.0
165 185
 	if (is_array($val)
166 186
 	  AND count($val)==2
167
-	  AND (array_key_exists('data',$val)))
168
-		$val = $val['data'];
187
+	  AND (array_key_exists('data',$val))) {
188
+			$val = $val['data'];
189
+	}
169 190
 	return $val;
170 191
 }
171 192
 
@@ -190,10 +211,12 @@  discard block
 block discarded – undo
190 211
 	static $pre = array();
191 212
 	static $log;
192 213
 	preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string) $name, $regs);
193
-	if (!isset($regs[1]) OR !$logname = $regs[1])
194
-		$logname = null;
195
-	if (!isset($regs[2]) OR !$niveau = $regs[2])
196
-		$niveau = _LOG_INFO;
214
+	if (!isset($regs[1]) OR !$logname = $regs[1]) {
215
+			$logname = null;
216
+	}
217
+	if (!isset($regs[2]) OR !$niveau = $regs[2]) {
218
+			$niveau = _LOG_INFO;
219
+	}
197 220
 
198 221
 	if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
199 222
 		if (!$pre){
@@ -208,7 +231,9 @@  discard block
 block discarded – undo
208 231
 				_LOG_DEBUG=>'debug:');
209 232
 			$log = charger_fonction('log', 'inc');
210 233
 		}
211
-		if (!is_string($message)) $message = var_export($message, true);
234
+		if (!is_string($message)) {
235
+		    $message = var_export($message, true);
236
+		}
212 237
 		$log($pre[$niveau].' '.$message, $logname);
213 238
 	}
214 239
 }
@@ -226,12 +251,17 @@  discard block
 block discarded – undo
226 251
 // http://doc.spip.org/@_request
227 252
 function _request($var, $c=false) {
228 253
 
229
-	if (is_array($c))
230
-		return isset($c[$var]) ? $c[$var] : NULL;
254
+	if (is_array($c)) {
255
+			return isset($c[$var]) ? $c[$var] : NULL;
256
+	}
231 257
 
232
-	if (isset($_GET[$var])) $a = $_GET[$var];
233
-	elseif (isset($_POST[$var])) $a = $_POST[$var];
234
-	else return NULL;
258
+	if (isset($_GET[$var])) {
259
+	    $a = $_GET[$var];
260
+	} elseif (isset($_POST[$var])) {
261
+	    $a = $_POST[$var];
262
+	} else {
263
+	    return NULL;
264
+	}
235 265
 
236 266
 	// Si on est en ajax et en POST tout a ete encode
237 267
 	// via encodeURIComponent, il faut donc repasser
@@ -259,15 +289,17 @@  discard block
 block discarded – undo
259 289
 function set_request($var, $val = NULL, $c=false) {
260 290
 	if (is_array($c)) {
261 291
 		unset($c[$var]);
262
-		if ($val !== NULL)
263
-			$c[$var] = $val;
292
+		if ($val !== NULL) {
293
+					$c[$var] = $val;
294
+		}
264 295
 		return $c;
265 296
 	}
266 297
 
267 298
 	unset($_GET[$var]);
268 299
 	unset($_POST[$var]);
269
-	if ($val !== NULL)
270
-		$_GET[$var] = $val;
300
+	if ($val !== NULL) {
301
+			$_GET[$var] = $val;
302
+	}
271 303
 
272 304
 	return false; # n'affecte pas $c
273 305
 }
@@ -314,22 +346,26 @@  discard block
 block discarded – undo
314 346
  */
315 347
 function parametre_url($url, $c, $v=NULL, $sep='&amp;') {
316 348
 	// requete erronnee : plusieurs variable dans $c et aucun $v
317
-	if (strpos($c,"|")!==false AND is_null($v))
318
-		return null;
349
+	if (strpos($c,"|")!==false AND is_null($v)) {
350
+			return null;
351
+	}
319 352
 
320 353
 	// lever l'#ancre
321 354
 	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
322 355
 		$url = $r[1];
323 356
 		$ancre = $r[2];
324
-	} else
325
-		$ancre = '';
357
+	} else {
358
+			$ancre = '';
359
+	}
326 360
 
327 361
 	// eclater
328 362
 	$url = preg_split(',[?]|&amp;|&,', $url);
329 363
 
330 364
 	// recuperer la base
331 365
 	$a = array_shift($url);
332
-	if (!$a) $a= './';
366
+	if (!$a) {
367
+	    $a= './';
368
+	}
333 369
 
334 370
 	$regexp = ',^(' . str_replace('[]','\[\]',$c) . '[[]?[]]?)(=.*)?$,';
335 371
 	$ajouts = array_flip(explode('|',$c));
@@ -357,15 +393,17 @@  discard block
 block discarded – undo
357 393
 	// traiter les parametres pas encore trouves
358 394
 	if ($v === NULL
359 395
 	AND $args = func_get_args()
360
-	AND count($args)==2)
361
-		return $v;
362
-	elseif ($testv) {
396
+	AND count($args)==2) {
397
+			return $v;
398
+	} elseif ($testv) {
363 399
 		foreach($ajouts as $k => $n) {
364
-		  if (!is_array($v))
365
-		    $url[] = $k .'=' . $u;
366
-		  else {
400
+		  if (!is_array($v)) {
401
+		  		    $url[] = $k .'=' . $u;
402
+		  } else {
367 403
 		  	$id = (substr($k,-2) == '[]') ? $k : ($k ."[]");
368
-		    foreach ($v as $w) $url[]= $id .'=' . $w;
404
+		    foreach ($v as $w) {
405
+		        $url[]= $id .'=' . $w;
406
+		    }
369 407
 		  }
370 408
 		}
371 409
 	}
@@ -374,8 +412,9 @@  discard block
 block discarded – undo
374 412
 	$url = array_filter($url);
375 413
 
376 414
 	// recomposer l'adresse
377
-	if ($url)
378
-		$a .= '?' . join($sep, $url);
415
+	if ($url) {
416
+			$a .= '?' . join($sep, $url);
417
+	}
379 418
 
380 419
 	return $a . $ancre;
381 420
 }
@@ -390,8 +429,9 @@  discard block
 block discarded – undo
390 429
 		$url = $r[1];
391 430
 	}
392 431
 	if (preg_match('/[^-_a-zA-Z0-9]+/S',$ancre)){
393
-		if (!function_exists('translitteration'))
394
-			include_spip('inc/charsets');
432
+		if (!function_exists('translitteration')) {
433
+					include_spip('inc/charsets');
434
+		}
395 435
 		$ancre = preg_replace(array('/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'), array('', '-'),
396 436
 						translitteration($ancre));
397 437
 	}
@@ -409,8 +449,12 @@  discard block
 block discarded – undo
409 449
 {
410 450
 	static $done = false;
411 451
 	static $propre = '';
412
-	if (!is_null($reset)) return $propre=$reset;
413
-	if ($done) return $propre;
452
+	if (!is_null($reset)) {
453
+	    return $propre=$reset;
454
+	}
455
+	if ($done) {
456
+	    return $propre;
457
+	}
414 458
 	$done = true;
415 459
 
416 460
 	$uri1 = $GLOBALS['REQUEST_URI'];
@@ -442,12 +486,14 @@  discard block
 block discarded – undo
442 486
 			$GLOBALS['profondeur_url']<(_DIR_RESTREINT?1:2)
443 487
 			// sinon c'est OK si _SET_HTML_BASE a ete force a false
444 488
 			OR (defined('_SET_HTML_BASE') AND !_SET_HTML_BASE))
445
-		)
446
-		$url = preg_replace(',^[^?]*/,', '', $url);
489
+		) {
490
+			$url = preg_replace(',^[^?]*/,', '', $url);
491
+	}
447 492
 	// ajouter le cas echeant les variables _POST['id_...']
448
-	foreach ($_POST as $v => $c)
449
-		if (substr($v,0,3) == 'id_')
493
+	foreach ($_POST as $v => $c) {
494
+			if (substr($v,0,3) == 'id_')
450 495
 			$url = parametre_url($url, $v, $c, '&');
496
+	}
451 497
 
452 498
 	// supprimer les variables sans interet
453 499
 	if (test_espace_prive()) {
@@ -463,8 +509,9 @@  discard block
 block discarded – undo
463 509
 	$url = spip_htmlspecialchars($url);
464 510
 
465 511
 	// &amp; ?
466
-	if ($amp != '&amp;')
467
-		$url = str_replace('&amp;', $amp, $url);
512
+	if ($amp != '&amp;') {
513
+			$url = str_replace('&amp;', $amp, $url);
514
+	}
468 515
 
469 516
 	// Si ca demarre par ? ou vide, donner './'
470 517
 	$url = preg_replace(',^([?].*)?$,', './\1', $url);
@@ -505,8 +552,9 @@  discard block
 block discarded – undo
505 552
 	$o = array('class'=>'', 'force'=>true);
506 553
 	if ($options){
507 554
 		// support de l'ancien argument $class
508
-		if (is_string($options))
509
-			$options = array('class'=>$options);
555
+		if (is_string($options)) {
556
+					$options = array('class'=>$options);
557
+		}
510 558
 		$o = array_merge($o,$options);
511 559
 	}
512 560
 
@@ -529,16 +577,18 @@  discard block
 block discarded – undo
529 577
 	$text = $traduire($texte, $lang);
530 578
 
531 579
 	if (!strlen($text)){
532
-		if (!$o['force'])
533
-			return '';
580
+		if (!$o['force']) {
581
+					return '';
582
+		}
534 583
 
535 584
 		$text = $texte;
536 585
 
537 586
 		// pour les chaines non traduites, assurer un service minimum
538
-		if (!$GLOBALS['test_i18n'] AND (_request('var_mode') != 'traduction'))
539
-			$text = str_replace('_', ' ',
587
+		if (!$GLOBALS['test_i18n'] AND (_request('var_mode') != 'traduction')) {
588
+					$text = str_replace('_', ' ',
540 589
 				 (($n = strpos($text,':')) === false ? $texte :
541 590
 					substr($texte, $n+1)));
591
+		}
542 592
 		$o['class'] = null;
543 593
 
544 594
 	}
@@ -554,29 +604,34 @@  discard block
 block discarded – undo
554 604
 	$f = $text;
555 605
 	if (is_array($args)) {
556 606
 		foreach ($args as $name => $value) {
557
-			if ($class)
558
-				$value = "<span class='$class'>$value</span>";
607
+			if ($class) {
608
+							$value = "<span class='$class'>$value</span>";
609
+			}
559 610
 			$t = str_replace ("@$name@", $value, $text);
560 611
 			if ($text !== $t) {unset($args[$name]); $text = $t;}
561 612
 		}
562 613
 		// Si des variables n'ont pas ete inserees, le signaler
563 614
 		// (chaines de langues pas a jour)
564
-		if ($args) spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)),_LOG_DEBUG);
615
+		if ($args) {
616
+		    spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)),_LOG_DEBUG);
617
+		}
565 618
 	}
566 619
 
567
-	if (($GLOBALS['test_i18n'] OR (_request('var_mode') == 'traduction')) AND $class===null)
568
-		return "<span class=debug-traduction-erreur>$text</span>";
569
-	else
570
-		return $text;
571
-}
620
+	if (($GLOBALS['test_i18n'] OR (_request('var_mode') == 'traduction')) AND $class===null) {
621
+			return "<span class=debug-traduction-erreur>$text</span>";
622
+	} else {
623
+			return $text;
624
+	}
625
+	}
572 626
 
573 627
 // Afficher "ecrire/data/" au lieu de "data/" dans les messages
574 628
 // ou tmp/ au lieu de ../tmp/
575 629
 // http://doc.spip.org/@joli_repertoire
576 630
 function joli_repertoire($rep) {
577 631
 	$a = substr($rep,0,1);
578
-	if ($a<>'.' AND $a<>'/')
579
-		$rep = (_DIR_RESTREINT?'':_DIR_RESTREINT_ABS).$rep;
632
+	if ($a<>'.' AND $a<>'/') {
633
+			$rep = (_DIR_RESTREINT?'':_DIR_RESTREINT_ABS).$rep;
634
+	}
580 635
 	$rep = preg_replace(',(^\.\.\/),', '', $rep);
581 636
 	return $rep;
582 637
 }
@@ -591,7 +646,10 @@  discard block
 block discarded – undo
591 646
 	$a=time(); $b=microtime();
592 647
 	// microtime peut contenir les microsecondes et le temps
593 648
 	$b=explode(' ',$b);
594
-	if (count($b)==2) $a = end($b); // plus precis !
649
+	if (count($b)==2) {
650
+	    $a = end($b);
651
+	}
652
+	// plus precis !
595 653
 	$b = reset($b);
596 654
 	if (!isset($time[$t])) {
597 655
 		$time[$t] = $a + $b;
@@ -599,10 +657,12 @@  discard block
 block discarded – undo
599 657
 		$p = ($a + $b - $time[$t]) * 1000;
600 658
 		unset($time[$t]);
601 659
 #			echo "'$p'";exit;
602
-		if ($raw) return $p;
603
-		if ($p < 1000)
604
-			$s = '';
605
-		else {
660
+		if ($raw) {
661
+		    return $p;
662
+		}
663
+		if ($p < 1000) {
664
+					$s = '';
665
+		} else {
606 666
 			$s = sprintf("%d ", $x = floor($p/1000));
607 667
 			$p -= ($x*1000);
608 668
 		}
@@ -617,8 +677,9 @@  discard block
 block discarded – undo
617 677
 function spip_touch($fichier, $duree=0, $touch=true) {
618 678
 	if ($duree) {
619 679
 		clearstatcache();
620
-		if ((@$f=filemtime($fichier)) AND ($f >= time() - $duree))
621
-			return false;
680
+		if ((@$f=filemtime($fichier)) AND ($f >= time() - $duree)) {
681
+					return false;
682
+		}
622 683
 	}
623 684
 	if ($touch!==false) {
624 685
 		if (!@touch($fichier)) { spip_unlink($fichier); @touch($fichier); };
@@ -661,13 +722,20 @@  discard block
 block discarded – undo
661 722
  */
662 723
 function cron ($taches=array(), $taches_old= array()) {
663 724
 	// si pas en mode cron force, laisser tomber.
664
-	if (!defined('_DIRECT_CRON_FORCE')) return false;
665
-	if (!is_array($taches)) $taches = $taches_old; // compat anciens appels
725
+	if (!defined('_DIRECT_CRON_FORCE')) {
726
+	    return false;
727
+	}
728
+	if (!is_array($taches)) {
729
+	    $taches = $taches_old;
730
+	}
731
+	// compat anciens appels
666 732
 	// si taches a inserer en base et base inaccessible, laisser tomber
667 733
 	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
668 734
 	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
669 735
 	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
670
-	if ($taches AND count($taches) AND !spip_connect())  return false;
736
+	if ($taches AND count($taches) AND !spip_connect()) {
737
+	    return false;
738
+	}
671 739
 	spip_log("cron !",'jq'._LOG_DEBUG);
672 740
 	if ($genie = charger_fonction('genie', 'inc', true)) {
673 741
 		return $genie($taches);
@@ -741,28 +809,31 @@  discard block
 block discarded – undo
741 809
  */
742 810
 function queue_sleep_time_to_next_job($force=null) {
743 811
 	static $queue_next_job_time = -1;
744
-	if ($force===true)
745
-		$queue_next_job_time = -1;
746
-	elseif ($force)
747
-		$queue_next_job_time = $force;
812
+	if ($force===true) {
813
+			$queue_next_job_time = -1;
814
+	} elseif ($force) {
815
+			$queue_next_job_time = $force;
816
+	}
748 817
 
749 818
 	if ($queue_next_job_time==-1) {
750 819
 		define('_JQ_NEXT_JOB_TIME_FILENAME',_DIR_TMP . "job_queue_next.txt");
751 820
 		// utiliser un cache memoire si dispo
752 821
 		if (include_spip('inc/memoization') AND defined('_MEMOIZE_MEMORY') AND _MEMOIZE_MEMORY) {
753 822
 			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
754
-		}
755
-		else {
823
+		} else {
756 824
 			$queue_next_job_time = null;
757
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu))
758
-				$queue_next_job_time = intval($contenu);
825
+			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
826
+							$queue_next_job_time = intval($contenu);
827
+			}
759 828
 		}
760 829
 	}
761 830
 
762
-	if (is_null($queue_next_job_time))
763
-		return null;
764
-	if (!$_SERVER['REQUEST_TIME'])
765
-		$_SERVER['REQUEST_TIME'] = time();
831
+	if (is_null($queue_next_job_time)) {
832
+			return null;
833
+	}
834
+	if (!$_SERVER['REQUEST_TIME']) {
835
+			$_SERVER['REQUEST_TIME'] = time();
836
+	}
766 837
 	return $queue_next_job_time-$_SERVER['REQUEST_TIME'];
767 838
 }
768 839
 
@@ -784,14 +855,17 @@  discard block
 block discarded – undo
784 855
 		$done[$src] = true;
785 856
 		$src = find_in_path($src, _JAVASCRIPT);
786 857
 		$src = " src='$src'";
858
+	} else {
859
+	    $src = '';
787 860
 	}
788
-	else $src = '';
789
-	if ($script)
790
-		$script = ("/*<![CDATA[*/\n" .
861
+	if ($script) {
862
+			$script = ("/*<![CDATA[*/\n" .
791 863
 		preg_replace(',</([^>]*)>,','<\/\1>', $script) .
792 864
 		"/*]]>*/");
793
-	if ($noscript)
794
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
865
+	}
866
+	if ($noscript) {
867
+			$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
868
+	}
795 869
 
796 870
 	return ($src OR $script OR $noscript)
797 871
 	? "<script type='text/javascript'$src>$script</script>$noscript"
@@ -824,43 +898,53 @@  discard block
 block discarded – undo
824 898
 			_DIR_RACINE.'prive/:'.
825 899
 			_DIR_RESTREINT;
826 900
 		// Ajouter squelettes/
827
-		if (@is_dir(_DIR_RACINE.'squelettes'))
828
-			$path = _DIR_RACINE.'squelettes/:' . $path;
901
+		if (@is_dir(_DIR_RACINE.'squelettes')) {
902
+					$path = _DIR_RACINE.'squelettes/:' . $path;
903
+		}
829 904
 		foreach (explode(':', $path) as $dir) {
830
-			if (strlen($dir) AND substr($dir,-1) != '/')
831
-				$dir .= "/";
905
+			if (strlen($dir) AND substr($dir,-1) != '/') {
906
+							$dir .= "/";
907
+			}
832 908
 			$path_base[] = $dir;
833 909
 		}
834 910
 		$path_full = $path_base;
835 911
 		// Et le(s) dossier(s) des squelettes nommes
836
-		if (strlen($GLOBALS['dossier_squelettes']))
837
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
912
+		if (strlen($GLOBALS['dossier_squelettes'])) {
913
+					foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
838 914
 				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
915
+		}
839 916
 		$GLOBALS['path_sig'] = md5(serialize($path_full));
840 917
 	}
841
-	if ($dir_path===NULL) return $path_full;
918
+	if ($dir_path===NULL) {
919
+	    return $path_full;
920
+	}
842 921
 
843 922
 	if (strlen($dir_path)){
844 923
 		$tete = "";
845
-		if (reset($path_base)==_DIR_RACINE.'squelettes/')
846
-			$tete = array_shift($path_base);
924
+		if (reset($path_base)==_DIR_RACINE.'squelettes/') {
925
+					$tete = array_shift($path_base);
926
+		}
847 927
 		$dirs = array_reverse(explode(':',$dir_path));
848 928
 		foreach($dirs as $dir_path){
849 929
 				#if ($dir_path{0}!='/')
850 930
 				#	$dir_path = $dir_path;
851
-				if (substr($dir_path,-1) != '/')
852
-					$dir_path .= "/";
853
-				if (!in_array($dir_path,$path_base))
854
-					array_unshift($path_base,$dir_path);
931
+				if (substr($dir_path,-1) != '/') {
932
+									$dir_path .= "/";
933
+				}
934
+				if (!in_array($dir_path,$path_base)) {
935
+									array_unshift($path_base,$dir_path);
936
+				}
937
+		}
938
+		if (strlen($tete)) {
939
+					array_unshift($path_base,$tete);
855 940
 		}
856
-		if (strlen($tete))
857
-			array_unshift($path_base,$tete);
858 941
 	}
859 942
 	$path_full = $path_base;
860 943
 	// Et le(s) dossier(s) des squelettes nommes
861
-	if (strlen($GLOBALS['dossier_squelettes']))
862
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
944
+	if (strlen($GLOBALS['dossier_squelettes'])) {
945
+			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
863 946
 			array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
947
+	}
864 948
 
865 949
 	$GLOBALS['path_sig'] = md5(serialize($path_full));
866 950
 	return $path_full;
@@ -885,8 +969,9 @@  discard block
 block discarded – undo
885 969
 	static $themes = null;
886 970
 	if (is_null($themes)){
887 971
 		// si pas encore definie
888
-		if (!defined('_SPIP_THEME_PRIVE'))
889
-			define('_SPIP_THEME_PRIVE', 'spip');
972
+		if (!defined('_SPIP_THEME_PRIVE')) {
973
+					define('_SPIP_THEME_PRIVE', 'spip');
974
+		}
890 975
 		$themes = array(_SPIP_THEME_PRIVE);
891 976
 		// lors d'une installation neuve, prefs n'est pas definie.
892 977
 		if (isset($GLOBALS['visiteur_session']['prefs'])) {
@@ -894,24 +979,30 @@  discard block
 block discarded – undo
894 979
 		} else {
895 980
 			$prefs = array();
896 981
 		}
897
-		if (is_string($prefs))
898
-			$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
982
+		if (is_string($prefs)) {
983
+					$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
984
+		}
899 985
 		if (
900 986
 			((isset($prefs['theme']) AND $theme = $prefs['theme'])
901 987
 			OR (isset($GLOBALS['theme_prive_defaut']) AND $theme = $GLOBALS['theme_prive_defaut']))
902
-			AND $theme != _SPIP_THEME_PRIVE)
903
-			array_unshift($themes,$theme); // placer le theme choisi en tete
988
+			AND $theme != _SPIP_THEME_PRIVE) {
989
+					array_unshift($themes,$theme);
990
+		}
991
+		// placer le theme choisi en tete
904 992
 	}
905 993
 	return $themes;
906 994
 }
907 995
 
908 996
 function find_in_theme($file, $subdir='', $include=false){
909 997
 	static $themefiles=array();
910
-	if (isset($themefiles["$subdir$file"])) return $themefiles["$subdir$file"];
998
+	if (isset($themefiles["$subdir$file"])) {
999
+	    return $themefiles["$subdir$file"];
1000
+	}
911 1001
 	$themes = lister_themes_prives();
912 1002
 	foreach($themes as $theme){
913
-		if ($f = find_in_path($file,"prive/themes/$theme/$subdir",$include))
914
-			return $themefiles["$subdir$file"] = $f;
1003
+		if ($f = find_in_path($file,"prive/themes/$theme/$subdir",$include)) {
1004
+					return $themefiles["$subdir$file"] = $f;
1005
+		}
915 1006
 	}
916 1007
 	spip_log("$file introuvable dans le theme prive ".reset($themes),'theme');
917 1008
 	return $themefiles["$subdir$file"] = "";
@@ -926,18 +1017,23 @@  discard block
 block discarded – undo
926 1017
 function chemin_image($icone){
927 1018
 	static $icone_renommer;
928 1019
 	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
929
-	if (strpos($icone,"/")!==false AND file_exists($icone)) return $icone;
1020
+	if (strpos($icone,"/")!==false AND file_exists($icone)) {
1021
+	    return $icone;
1022
+	}
930 1023
 	
931 1024
 	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
932
-	if (preg_match(',[.](png|gif|jpg)$,',$icone) AND $f = find_in_theme("images/$icone"))
933
-		return $f;
1025
+	if (preg_match(',[.](png|gif|jpg)$,',$icone) AND $f = find_in_theme("images/$icone")) {
1026
+			return $f;
1027
+	}
934 1028
 	// sinon passer par le module de renommage
935
-	if (is_null($icone_renommer))
936
-		$icone_renommer = charger_fonction('icone_renommer','inc',true);
1029
+	if (is_null($icone_renommer)) {
1030
+			$icone_renommer = charger_fonction('icone_renommer','inc',true);
1031
+	}
937 1032
 	if ($icone_renommer){
938 1033
 		list($icone,$fonction) = $icone_renommer($icone,"");
939
-		if (file_exists($icone))
940
-			return $icone;
1034
+		if (file_exists($icone)) {
1035
+					return $icone;
1036
+		}
941 1037
 	}
942 1038
 	return find_in_path ($icone, _NOM_IMG_PACK);
943 1039
 }
@@ -963,8 +1059,9 @@  discard block
 block discarded – undo
963 1059
 	}
964 1060
 
965 1061
 	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
966
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])
967
-			return false;
1062
+		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1063
+					return false;
1064
+		}
968 1065
 		if ($include AND !isset($inc[$dirname][$file])) {
969 1066
 			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
970 1067
 			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
@@ -979,8 +1076,9 @@  discard block
 block discarded – undo
979 1076
 	}
980 1077
 
981 1078
 	foreach(creer_chemin() as $dir) {
982
-		if (!isset($dirs[$a = $dir . $dirname]))
983
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a) ;
1079
+		if (!isset($dirs[$a = $dir . $dirname])) {
1080
+					$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a) ;
1081
+		}
984 1082
 		if ($dirs[$a]) {
985 1083
 			if (file_exists(_ROOT_CWD . ($a .= $file))) {
986 1084
 				if ($include AND !isset($inc[$dirname][$file])) {
@@ -989,7 +1087,9 @@  discard block
 block discarded – undo
989 1087
 				}
990 1088
 				if (!defined('_SAUVER_CHEMIN')){
991 1089
 					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
992
-					if (is_null($GLOBALS['path_files'])) return $a;
1090
+					if (is_null($GLOBALS['path_files'])) {
1091
+					    return $a;
1092
+					}
993 1093
 					define('_SAUVER_CHEMIN', true);
994 1094
 				}
995 1095
 				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
@@ -1002,8 +1102,9 @@  discard block
 block discarded – undo
1002 1102
 		if ($include==='required'){
1003 1103
 			echo '<pre>',
1004 1104
 			"<strong>Erreur Fatale</strong><br />";
1005
-			if (function_exists('debug_print_backtrace'))
1006
-				echo debug_print_backtrace();
1105
+			if (function_exists('debug_print_backtrace')) {
1106
+							echo debug_print_backtrace();
1107
+			}
1007 1108
 			echo '</pre>';
1008 1109
 			die("Erreur interne: ne peut inclure $dirname$file");
1009 1110
 		}
@@ -1011,7 +1112,9 @@  discard block
 block discarded – undo
1011 1112
 
1012 1113
 	if (!defined('_SAUVER_CHEMIN')){
1013 1114
 		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1014
-		if (is_null($GLOBALS['path_files'])) return false;
1115
+		if (is_null($GLOBALS['path_files'])) {
1116
+		    return false;
1117
+		}
1015 1118
 		define('_SAUVER_CHEMIN', true);
1016 1119
 	}
1017 1120
 	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
@@ -1043,8 +1146,9 @@  discard block
 block discarded – undo
1043 1146
 			// mais si semble corrompu on relit avec un verrou
1044 1147
 			if (!$GLOBALS['path_files']=unserialize($contenu)){
1045 1148
 				lire_fichier(_CACHE_CHEMIN,$contenu);
1046
-				if (!$GLOBALS['path_files']=unserialize($contenu))
1047
-					$GLOBALS['path_files'] = array();
1149
+				if (!$GLOBALS['path_files']=unserialize($contenu)) {
1150
+									$GLOBALS['path_files'] = array();
1151
+				}
1048 1152
 			}
1049 1153
 		}
1050 1154
 	}
@@ -1052,9 +1156,10 @@  discard block
 block discarded – undo
1052 1156
 
1053 1157
 function save_path_cache(){
1054 1158
 	if (defined('_SAUVER_CHEMIN')
1055
-		AND _SAUVER_CHEMIN)
1056
-		ecrire_fichier(_CACHE_CHEMIN,serialize($GLOBALS['path_files']));
1057
-}
1159
+		AND _SAUVER_CHEMIN) {
1160
+			ecrire_fichier(_CACHE_CHEMIN,serialize($GLOBALS['path_files']));
1161
+	}
1162
+	}
1058 1163
 
1059 1164
 
1060 1165
 /**
@@ -1082,8 +1187,9 @@  discard block
 block discarded – undo
1082 1187
 				// ne prendre que les fichiers pas deja trouves
1083 1188
 				// car find_in_path prend le premier qu'il trouve,
1084 1189
 				// les autres sont donc masques
1085
-				if (!isset($liste_fichiers[$nom]))
1086
-					$liste_fichiers[$nom] = $chemin;
1190
+				if (!isset($liste_fichiers[$nom])) {
1191
+									$liste_fichiers[$nom] = $chemin;
1192
+				}
1087 1193
 			}
1088 1194
 		}
1089 1195
 	}
@@ -1126,13 +1232,18 @@  discard block
 block discarded – undo
1126 1232
  */
1127 1233
 function generer_url_entite($id='', $entite='', $args='', $ancre='', $public=NULL, $type=NULL)
1128 1234
 {
1129
-	if ($public === NULL) $public = !test_espace_prive();
1235
+	if ($public === NULL) {
1236
+	    $public = !test_espace_prive();
1237
+	}
1130 1238
 	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1131 1239
 
1132 1240
 	if (!$public) {
1133
-		if (!$entite) return '';
1134
-		if (!function_exists('generer_url_ecrire_objet'))
1135
-			include_spip('inc/urls');
1241
+		if (!$entite) {
1242
+		    return '';
1243
+		}
1244
+		if (!function_exists('generer_url_ecrire_objet')) {
1245
+					include_spip('inc/urls');
1246
+		}
1136 1247
 		$res = generer_url_ecrire_objet($entite,$id, $args, $ancre, false);
1137 1248
 	} else {
1138 1249
 		if ($type === NULL) {
@@ -1144,32 +1255,42 @@  discard block
 block discarded – undo
1144 1255
 
1145 1256
 		$f = charger_fonction($type, 'urls', true);
1146 1257
 		// se rabattre sur les urls page si les urls perso non dispo
1147
-		if (!$f) $f = charger_fonction('page', 'urls', true);
1258
+		if (!$f) {
1259
+		    $f = charger_fonction('page', 'urls', true);
1260
+		}
1148 1261
 
1149 1262
 		// si $entite='', on veut la fonction de passage URL ==> id
1150 1263
 		// sinon on veut effectuer le passage id ==> URL
1151
-		if (!$entite) return $f;
1264
+		if (!$entite) {
1265
+		    return $f;
1266
+		}
1152 1267
 
1153 1268
 		// mais d'abord il faut tester le cas des urls sur une
1154 1269
 		// base distante
1155 1270
 		if (is_string($public)
1156
-		AND $g = charger_fonction('connect', 'urls', true))
1157
-			$f = $g;
1271
+		AND $g = charger_fonction('connect', 'urls', true)) {
1272
+					$f = $g;
1273
+		}
1158 1274
 
1159 1275
 		$res = $f(intval($id), $entite, $args, $ancre, $public);
1160 1276
 
1161 1277
 	}
1162
-	if ($res) return $res;
1278
+	if ($res) {
1279
+	    return $res;
1280
+	}
1163 1281
 	// Sinon c'est un raccourci ou compat SPIP < 2
1164 1282
 	if (!function_exists($f = 'generer_url_' . $entite)) {
1165
-		if (!function_exists($f .= '_dist')) $f = '';
1283
+		if (!function_exists($f .= '_dist')) {
1284
+		    $f = '';
1285
+		}
1166 1286
 	}
1167 1287
 	if ($f) {
1168 1288
 		$url = $f($id, $args, $ancre);
1169
-		if (strlen($args))
1170
-			$url .= strstr($url, '?')
1289
+		if (strlen($args)) {
1290
+					$url .= strstr($url, '?')
1171 1291
 				? '&amp;'.$args
1172 1292
 				: '?'.$args;
1293
+		}
1173 1294
 		return $url;
1174 1295
 	}
1175 1296
 	// On a ete gentil mais la ....
@@ -1180,12 +1301,14 @@  discard block
 block discarded – undo
1180 1301
 function generer_url_ecrire_entite_edit($id, $entite, $args='', $ancre=''){
1181 1302
 	$exec = objet_info($entite,'url_edit');
1182 1303
 	$url = generer_url_ecrire($exec,$args);
1183
-	if (intval($id))
1184
-		$url = parametre_url($url,id_table_objet($entite),$id);
1185
-	else
1186
-		$url = parametre_url($url,'new','oui');
1187
-	if ($ancre)
1188
-		$url = ancre_url($url,$ancre);
1304
+	if (intval($id)) {
1305
+			$url = parametre_url($url,id_table_objet($entite),$id);
1306
+	} else {
1307
+			$url = parametre_url($url,'new','oui');
1308
+	}
1309
+	if ($ancre) {
1310
+			$url = ancre_url($url,$ancre);
1311
+	}
1189 1312
 	return $url;
1190 1313
 }
1191 1314
 
@@ -1205,8 +1328,9 @@  discard block
 block discarded – undo
1205 1328
 	if (preg_match(',[^\x00-\x7E],sS', $url)){
1206 1329
 		$uri = '';
1207 1330
 		for ($i=0; $i < strlen($url); $i++) {
1208
-			if (ord($a = $url[$i]) > 127)
1209
-				$a = rawurlencode($a);
1331
+			if (ord($a = $url[$i]) > 127) {
1332
+							$a = rawurlencode($a);
1333
+			}
1210 1334
 			$uri .= $a;
1211 1335
 		}
1212 1336
 		$url = $uri;
@@ -1217,7 +1341,9 @@  discard block
 block discarded – undo
1217 1341
 // http://doc.spip.org/@generer_url_entite_absolue
1218 1342
 function generer_url_entite_absolue($id='', $entite='', $args='', $ancre='', $connect=NULL)
1219 1343
 {
1220
-	if (!$connect) $connect = true;
1344
+	if (!$connect) {
1345
+	    $connect = true;
1346
+	}
1221 1347
 	$h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1222 1348
 	if (!preg_match(',^\w+:,', $h)) {
1223 1349
 		include_spip('inc/filtres_mini');
@@ -1230,7 +1356,9 @@  discard block
 block discarded – undo
1230 1356
 // variables d'environnement comme $_SERVER[HTTPS] ou ini_get(register_globals)
1231 1357
 // http://doc.spip.org/@test_valeur_serveur
1232 1358
 function test_valeur_serveur($truc) {
1233
-	if (!$truc) return false;
1359
+	if (!$truc) {
1360
+	    return false;
1361
+	}
1234 1362
 	return (strtolower($truc) !== 'off');
1235 1363
 }
1236 1364
 
@@ -1257,13 +1385,20 @@  discard block
 block discarded – undo
1257 1385
 function url_de_base($profondeur=null) {
1258 1386
 
1259 1387
 	static $url = array();
1260
-	if (is_array($profondeur)) return $url = $profondeur;
1261
-	if ($profondeur===false) return $url;
1388
+	if (is_array($profondeur)) {
1389
+	    return $url = $profondeur;
1390
+	}
1391
+	if ($profondeur===false) {
1392
+	    return $url;
1393
+	}
1262 1394
 
1263
-	if (is_null($profondeur)) $profondeur = $GLOBALS['profondeur_url'];
1395
+	if (is_null($profondeur)) {
1396
+	    $profondeur = $GLOBALS['profondeur_url'];
1397
+	}
1264 1398
 
1265
-	if (isset($url[$profondeur]))
1266
-		return $url[$profondeur];
1399
+	if (isset($url[$profondeur])) {
1400
+			return $url[$profondeur];
1401
+	}
1267 1402
 
1268 1403
 	$http = (
1269 1404
 		(isset($_SERVER["SCRIPT_URI"]) AND
@@ -1284,8 +1419,12 @@  discard block
 block discarded – undo
1284 1419
 	if (isset($_SERVER['SERVER_PORT'])
1285 1420
 		AND $port=$_SERVER['SERVER_PORT']
1286 1421
 		AND strpos($host,":")==false){
1287
-		if ($http=="http" AND $port!=80) $host.=":$port";
1288
-		if ($http=="https" AND $port!=443) $host.=":$port";
1422
+		if ($http=="http" AND $port!=80) {
1423
+		    $host.=":$port";
1424
+		}
1425
+		if ($http=="https" AND $port!=443) {
1426
+		    $host.=":$port";
1427
+		}
1289 1428
 	}
1290 1429
 	if (!$GLOBALS['REQUEST_URI']){
1291 1430
 		if (isset($_SERVER['REQUEST_URI'])) {
@@ -1293,8 +1432,9 @@  discard block
 block discarded – undo
1293 1432
 		} else {
1294 1433
 			$GLOBALS['REQUEST_URI'] = $_SERVER['PHP_SELF'];
1295 1434
 			if ($_SERVER['QUERY_STRING']
1296
-			AND !strpos($_SERVER['REQUEST_URI'], '?'))
1297
-				$GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
1435
+			AND !strpos($_SERVER['REQUEST_URI'], '?')) {
1436
+							$GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
1437
+			}
1298 1438
 		}
1299 1439
 	}
1300 1440
 
@@ -1343,18 +1483,22 @@  discard block
 block discarded – undo
1343 1483
 
1344 1484
 // http://doc.spip.org/@generer_url_ecrire
1345 1485
 function generer_url_ecrire($script='', $args="", $no_entities=false, $rel=false) {
1346
-	if (!$rel)
1347
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
1348
-	else if (!is_string($rel))
1349
-		$rel = _DIR_RESTREINT ? _DIR_RESTREINT :
1486
+	if (!$rel) {
1487
+			$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
1488
+	} else if (!is_string($rel)) {
1489
+			$rel = _DIR_RESTREINT ? _DIR_RESTREINT :
1350 1490
 			('./'  . _SPIP_ECRIRE_SCRIPT);
1491
+	}
1351 1492
 
1352 1493
 	@list($script, $ancre) = explode('#', $script);
1353
-	if ($script AND ($script<>'accueil' OR $rel))
1354
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
1355
-	elseif ($args)
1356
-		$args ="?$args";
1357
-	if ($ancre) $args .= "#$ancre";
1494
+	if ($script AND ($script<>'accueil' OR $rel)) {
1495
+			$args = "?exec=$script" . (!$args ? '' : "&$args");
1496
+	} elseif ($args) {
1497
+			$args ="?$args";
1498
+	}
1499
+	if ($ancre) {
1500
+	    $args .= "#$ancre";
1501
+	}
1358 1502
 	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
1359 1503
 }
1360 1504
 
@@ -1373,32 +1517,39 @@  discard block
 block discarded – undo
1373 1517
 // http://doc.spip.org/@get_spip_script
1374 1518
 function get_spip_script($default='') {
1375 1519
 	# cas define('_SPIP_SCRIPT', '');
1376
-	if (_SPIP_SCRIPT)
1377
-		return _SPIP_SCRIPT;
1378
-	else
1379
-		return $default;
1380
-}
1520
+	if (_SPIP_SCRIPT) {
1521
+			return _SPIP_SCRIPT;
1522
+	} else {
1523
+			return $default;
1524
+	}
1525
+	}
1381 1526
 
1382 1527
 // http://doc.spip.org/@generer_url_public
1383 1528
 function generer_url_public($script='', $args="", $no_entities=false, $rel=true, $action='') {
1384 1529
 	// si le script est une action (spip_pass, spip_inscription),
1385 1530
 	// standardiser vers la nouvelle API
1386 1531
 
1387
-	if (!$action) $action = get_spip_script();
1388
-	if ($script)
1389
-		$action = parametre_url($action, _SPIP_PAGE, $script, '&');
1532
+	if (!$action) {
1533
+	    $action = get_spip_script();
1534
+	}
1535
+	if ($script) {
1536
+			$action = parametre_url($action, _SPIP_PAGE, $script, '&');
1537
+	}
1390 1538
 
1391 1539
 	if ($args) {
1392 1540
 		if (is_array($args)) {
1393 1541
 			$r = '';
1394
-			foreach($args as $k => $v) $r .= '&' . $k . '=' . $v;
1542
+			foreach($args as $k => $v) {
1543
+			    $r .= '&' . $k . '=' . $v;
1544
+			}
1395 1545
 			$args = substr($r,1);
1396 1546
 		}
1397 1547
 		$action .=
1398 1548
 			(strpos($action, '?') !== false ? '&' : '?') . $args;
1399 1549
 	}
1400
-	if (!$no_entities)
1401
-		$action = quote_amp($action);
1550
+	if (!$no_entities) {
1551
+			$action = quote_amp($action);
1552
+	}
1402 1553
 
1403 1554
 	// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
1404 1555
 	return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(),'/') . preg_replace(",^/[.]/,","/","/$action"));
@@ -1476,9 +1627,13 @@  discard block
 block discarded – undo
1476 1627
 	  ? generer_url_ecrire(_request('exec'))
1477 1628
 	  :  generer_url_public('','',false,false);
1478 1629
 	$url = parametre_url($url,'action',$script);
1479
-	if ($args) $url .= quote_amp('&'.$args);
1630
+	if ($args) {
1631
+	    $url .= quote_amp('&'.$args);
1632
+	}
1480 1633
 
1481
-	if ($no_entities) $url = str_replace('&amp;','&',$url);
1634
+	if ($no_entities) {
1635
+	    $url = str_replace('&amp;','&',$url);
1636
+	}
1482 1637
 	return $url;
1483 1638
 }
1484 1639
 
@@ -1512,107 +1667,204 @@  discard block
 block discarded – undo
1512 1667
  */
1513 1668
 function spip_initialisation_core($pi=NULL, $pa=NULL, $ti=NULL, $ta=NULL) {
1514 1669
 	static $too_late = 0;
1515
-	if ($too_late++) return;
1670
+	if ($too_late++) {
1671
+	    return;
1672
+	}
1516 1673
 	
1517 1674
 	// Declaration des repertoires
1518 1675
 
1519 1676
 	// le nom du repertoire plugins/ activables/desactivables
1520
-	if (!defined('_DIR_PLUGINS')) define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
1677
+	if (!defined('_DIR_PLUGINS')) {
1678
+	    define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
1679
+	}
1521 1680
 
1522 1681
 	// le nom du repertoire des extensions/ permanentes du core, toujours actives
1523
-	if (!defined('_DIR_PLUGINS_DIST')) define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
1682
+	if (!defined('_DIR_PLUGINS_DIST')) {
1683
+	    define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
1684
+	}
1524 1685
 
1525 1686
 	// le nom du repertoire des librairies
1526
-	if (!defined('_DIR_LIB')) define('_DIR_LIB', _DIR_RACINE . "lib/");
1687
+	if (!defined('_DIR_LIB')) {
1688
+	    define('_DIR_LIB', _DIR_RACINE . "lib/");
1689
+	}
1527 1690
 	
1528
-	if (!defined('_DIR_IMG')) define('_DIR_IMG', $pa);
1529
-	if (!defined('_DIR_LOGOS')) define('_DIR_LOGOS', $pa);
1530
-	if (!defined('_DIR_IMG_ICONES')) define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
1531
-
1532
-	if (!defined('_DIR_DUMP')) define('_DIR_DUMP', $ti . "dump/");
1533
-	if (!defined('_DIR_SESSIONS')) define('_DIR_SESSIONS', $ti . "sessions/");
1534
-	if (!defined('_DIR_TRANSFERT')) define('_DIR_TRANSFERT', $ti . "upload/");
1535
-	if (!defined('_DIR_CACHE')) define('_DIR_CACHE', $ti . "cache/");
1536
-	if (!defined('_DIR_CACHE_XML')) define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
1537
-	if (!defined('_DIR_SKELS')) define('_DIR_SKELS',  _DIR_CACHE . "skel/");
1538
-	if (!defined('_DIR_AIDE')) define('_DIR_AIDE',  _DIR_CACHE . "aide/");
1539
-	if (!defined('_DIR_TMP')) define('_DIR_TMP', $ti);
1540
-
1541
-	if (!defined('_DIR_VAR')) define('_DIR_VAR', $ta);
1542
-
1543
-	if (!defined('_DIR_ETC')) define('_DIR_ETC', $pi);
1544
-	if (!defined('_DIR_CONNECT')) define('_DIR_CONNECT', $pi);
1545
-	if (!defined('_DIR_CHMOD')) define('_DIR_CHMOD', $pi);
1546
-
1547
-	if (!isset($GLOBALS['test_dirs']))
1548
-	  // Pas $pi car il est bon de le mettre hors ecriture apres intstall
1691
+	if (!defined('_DIR_IMG')) {
1692
+	    define('_DIR_IMG', $pa);
1693
+	}
1694
+	if (!defined('_DIR_LOGOS')) {
1695
+	    define('_DIR_LOGOS', $pa);
1696
+	}
1697
+	if (!defined('_DIR_IMG_ICONES')) {
1698
+	    define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
1699
+	}
1700
+
1701
+	if (!defined('_DIR_DUMP')) {
1702
+	    define('_DIR_DUMP', $ti . "dump/");
1703
+	}
1704
+	if (!defined('_DIR_SESSIONS')) {
1705
+	    define('_DIR_SESSIONS', $ti . "sessions/");
1706
+	}
1707
+	if (!defined('_DIR_TRANSFERT')) {
1708
+	    define('_DIR_TRANSFERT', $ti . "upload/");
1709
+	}
1710
+	if (!defined('_DIR_CACHE')) {
1711
+	    define('_DIR_CACHE', $ti . "cache/");
1712
+	}
1713
+	if (!defined('_DIR_CACHE_XML')) {
1714
+	    define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
1715
+	}
1716
+	if (!defined('_DIR_SKELS')) {
1717
+	    define('_DIR_SKELS',  _DIR_CACHE . "skel/");
1718
+	}
1719
+	if (!defined('_DIR_AIDE')) {
1720
+	    define('_DIR_AIDE',  _DIR_CACHE . "aide/");
1721
+	}
1722
+	if (!defined('_DIR_TMP')) {
1723
+	    define('_DIR_TMP', $ti);
1724
+	}
1725
+
1726
+	if (!defined('_DIR_VAR')) {
1727
+	    define('_DIR_VAR', $ta);
1728
+	}
1729
+
1730
+	if (!defined('_DIR_ETC')) {
1731
+	    define('_DIR_ETC', $pi);
1732
+	}
1733
+	if (!defined('_DIR_CONNECT')) {
1734
+	    define('_DIR_CONNECT', $pi);
1735
+	}
1736
+	if (!defined('_DIR_CHMOD')) {
1737
+	    define('_DIR_CHMOD', $pi);
1738
+	}
1739
+
1740
+	if (!isset($GLOBALS['test_dirs'])) {
1741
+		  // Pas $pi car il est bon de le mettre hors ecriture apres intstall
1549 1742
 	  // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
1550 1743
 		$GLOBALS['test_dirs'] =  array($pa, $ti, $ta);
1744
+	}
1551 1745
 
1552 1746
 	// Declaration des fichiers
1553 1747
 
1554
-	if (!defined('_CACHE_PLUGINS_PATH')) define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
1555
-	if (!defined('_CACHE_PLUGINS_OPT')) define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
1556
-	if (!defined('_CACHE_PLUGINS_FCT')) define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
1557
-	if (!defined('_CACHE_PIPELINES')) define('_CACHE_PIPELINES',  _DIR_CACHE."charger_pipelines.php");
1558
-	if (!defined('_CACHE_CHEMIN')) define('_CACHE_CHEMIN',  _DIR_CACHE."chemin.txt");
1748
+	if (!defined('_CACHE_PLUGINS_PATH')) {
1749
+	    define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
1750
+	}
1751
+	if (!defined('_CACHE_PLUGINS_OPT')) {
1752
+	    define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
1753
+	}
1754
+	if (!defined('_CACHE_PLUGINS_FCT')) {
1755
+	    define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
1756
+	}
1757
+	if (!defined('_CACHE_PIPELINES')) {
1758
+	    define('_CACHE_PIPELINES',  _DIR_CACHE."charger_pipelines.php");
1759
+	}
1760
+	if (!defined('_CACHE_CHEMIN')) {
1761
+	    define('_CACHE_CHEMIN',  _DIR_CACHE."chemin.txt");
1762
+	}
1559 1763
 
1560 1764
 	# attention .php obligatoire pour ecrire_fichier_securise
1561
-	if (!defined('_FILE_META')) define('_FILE_META', $ti . 'meta_cache.php');
1562
-	if (!defined('_DIR_LOG')) define('_DIR_LOG', _DIR_TMP . 'log/');
1563
-	if (!defined('_FILE_LOG')) define('_FILE_LOG', 'spip');
1564
-	if (!defined('_FILE_LOG_SUFFIX')) define('_FILE_LOG_SUFFIX', '.log');
1765
+	if (!defined('_FILE_META')) {
1766
+	    define('_FILE_META', $ti . 'meta_cache.php');
1767
+	}
1768
+	if (!defined('_DIR_LOG')) {
1769
+	    define('_DIR_LOG', _DIR_TMP . 'log/');
1770
+	}
1771
+	if (!defined('_FILE_LOG')) {
1772
+	    define('_FILE_LOG', 'spip');
1773
+	}
1774
+	if (!defined('_FILE_LOG_SUFFIX')) {
1775
+	    define('_FILE_LOG_SUFFIX', '.log');
1776
+	}
1565 1777
 
1566 1778
 	// Le fichier de connexion a la base de donnees
1567 1779
 	// tient compte des anciennes versions (inc_connect...)
1568
-	if (!defined('_FILE_CONNECT_INS')) define('_FILE_CONNECT_INS', 'connect');
1569
-	if (!defined('_FILE_CONNECT')) define('_FILE_CONNECT',
1780
+	if (!defined('_FILE_CONNECT_INS')) {
1781
+	    define('_FILE_CONNECT_INS', 'connect');
1782
+	}
1783
+	if (!defined('_FILE_CONNECT')) {
1784
+	    define('_FILE_CONNECT',
1570 1785
 		(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
1571 1786
 	:	(@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
1572 1787
 	:	false)));
1788
+	}
1573 1789
 
1574 1790
 	// Le fichier de reglages des droits
1575
-	if (!defined('_FILE_CHMOD_INS')) define('_FILE_CHMOD_INS', 'chmod');
1576
-	if (!defined('_FILE_CHMOD')) define('_FILE_CHMOD',
1791
+	if (!defined('_FILE_CHMOD_INS')) {
1792
+	    define('_FILE_CHMOD_INS', 'chmod');
1793
+	}
1794
+	if (!defined('_FILE_CHMOD')) {
1795
+	    define('_FILE_CHMOD',
1577 1796
 		(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
1578 1797
 	:	false));
1798
+	}
1579 1799
 
1580
-	if (!defined('_FILE_LDAP')) define('_FILE_LDAP', 'ldap.php');
1800
+	if (!defined('_FILE_LDAP')) {
1801
+	    define('_FILE_LDAP', 'ldap.php');
1802
+	}
1581 1803
 
1582
-	if (!defined('_FILE_TMP_SUFFIX')) define('_FILE_TMP_SUFFIX', '.tmp.php');
1583
-	if (!defined('_FILE_CONNECT_TMP')) define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
1584
-	if (!defined('_FILE_CHMOD_TMP')) define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
1804
+	if (!defined('_FILE_TMP_SUFFIX')) {
1805
+	    define('_FILE_TMP_SUFFIX', '.tmp.php');
1806
+	}
1807
+	if (!defined('_FILE_CONNECT_TMP')) {
1808
+	    define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
1809
+	}
1810
+	if (!defined('_FILE_CHMOD_TMP')) {
1811
+	    define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
1812
+	}
1585 1813
 
1586 1814
 	// Definition des droits d'acces en ecriture
1587
-	if (!defined('_SPIP_CHMOD') AND _FILE_CHMOD)
1588
-		include_once _FILE_CHMOD;
1815
+	if (!defined('_SPIP_CHMOD') AND _FILE_CHMOD) {
1816
+			include_once _FILE_CHMOD;
1817
+	}
1589 1818
 
1590 1819
 	// Se mefier des fichiers mal remplis!
1591
-	if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', 0777);
1820
+	if (!defined('_SPIP_CHMOD')) {
1821
+	    define('_SPIP_CHMOD', 0777);
1822
+	}
1592 1823
 
1593 1824
 	// Le charset par defaut lors de l'installation
1594
-	if (!defined('_DEFAULT_CHARSET')) define('_DEFAULT_CHARSET', 'utf-8');
1595
-	if (!defined('_ROOT_PLUGINS')) define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
1596
-	if (!defined('_ROOT_PLUGINS_DIST')) define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
1597
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE,'',_DIR_PLUGINS_SUPPL));
1825
+	if (!defined('_DEFAULT_CHARSET')) {
1826
+	    define('_DEFAULT_CHARSET', 'utf-8');
1827
+	}
1828
+	if (!defined('_ROOT_PLUGINS')) {
1829
+	    define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
1830
+	}
1831
+	if (!defined('_ROOT_PLUGINS_DIST')) {
1832
+	    define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
1833
+	}
1834
+	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
1835
+	    define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE,'',_DIR_PLUGINS_SUPPL));
1836
+	}
1598 1837
 
1599 1838
 	// La taille des Log
1600
-	if (!defined('_MAX_LOG')) define('_MAX_LOG', 100);
1839
+	if (!defined('_MAX_LOG')) {
1840
+	    define('_MAX_LOG', 100);
1841
+	}
1601 1842
 
1602 1843
 	// Sommes-nous dans l'empire du Mal ?
1603 1844
 	// (ou sous le signe du Pingouin, ascendant GNU ?)
1604 1845
 	if (strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false){
1605
-		if (!defined('_OS_SERVEUR')) define('_OS_SERVEUR', 'windows');
1606
-		if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',1); // utiliser le flock php
1607
-	}
1608
-	else {
1609
-		if (!defined('_OS_SERVEUR')) define('_OS_SERVEUR', '');
1610
-		if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',1); // utiliser le flock php
1846
+		if (!defined('_OS_SERVEUR')) {
1847
+		    define('_OS_SERVEUR', 'windows');
1848
+		}
1849
+		if (!defined('_SPIP_LOCK_MODE')) {
1850
+		    define('_SPIP_LOCK_MODE',1);
1851
+		}
1852
+		// utiliser le flock php
1853
+	} else {
1854
+		if (!defined('_OS_SERVEUR')) {
1855
+		    define('_OS_SERVEUR', '');
1856
+		}
1857
+		if (!defined('_SPIP_LOCK_MODE')) {
1858
+		    define('_SPIP_LOCK_MODE',1);
1859
+		}
1860
+		// utiliser le flock php
1611 1861
 		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
1612 1862
 	}
1613 1863
 
1614 1864
 	// Langue par defaut
1615
-	if (!defined('_LANGUE_PAR_DEFAUT')) define('_LANGUE_PAR_DEFAUT','fr');
1865
+	if (!defined('_LANGUE_PAR_DEFAUT')) {
1866
+	    define('_LANGUE_PAR_DEFAUT','fr');
1867
+	}
1616 1868
 
1617 1869
 	// PHP_VERSION_ID dispo depuis PHP 5.2.7
1618 1870
 	if (!defined('PHP_VERSION_ID')) {
@@ -1637,7 +1889,9 @@  discard block
 block discarded – undo
1637 1889
 	//
1638 1890
 
1639 1891
 	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
1640
-	if (isset($_REQUEST['GLOBALS'])) die();
1892
+	if (isset($_REQUEST['GLOBALS'])) {
1893
+	    die();
1894
+	}
1641 1895
 	// nettoyer les magic quotes \' et les caracteres nuls %00
1642 1896
 	spip_desinfecte($_GET);
1643 1897
 	spip_desinfecte($_POST);
@@ -1656,8 +1910,9 @@  discard block
 block discarded – undo
1656 1910
 		// ne pas desinfecter les globales en profondeur car elle contient aussi les
1657 1911
 		// precedentes, qui seraient desinfectees 2 fois.
1658 1912
 		spip_desinfecte($GLOBALS,false);
1659
-		if (include_spip('inc/php3'))
1660
-			spip_register_globals(true);
1913
+		if (include_spip('inc/php3')) {
1914
+					spip_register_globals(true);
1915
+		}
1661 1916
 
1662 1917
 		$avertir_register_globals = true;
1663 1918
 	}
@@ -1686,12 +1941,15 @@  discard block
 block discarded – undo
1686 1941
 	} else {
1687 1942
 		$GLOBALS['REQUEST_URI'] = $_SERVER['PHP_SELF'];
1688 1943
 		if ($_SERVER['QUERY_STRING']
1689
-		AND !strpos($_SERVER['REQUEST_URI'], '?'))
1690
-			$GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
1944
+		AND !strpos($_SERVER['REQUEST_URI'], '?')) {
1945
+					$GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
1946
+		}
1691 1947
 	}
1692 1948
 
1693 1949
 	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
1694
-	if (!defined('_RENOUVELLE_ALEA')) define('_RENOUVELLE_ALEA', 12 * 3600);
1950
+	if (!defined('_RENOUVELLE_ALEA')) {
1951
+	    define('_RENOUVELLE_ALEA', 12 * 3600);
1952
+	}
1695 1953
 
1696 1954
 	// charger les meta si possible et renouveller l'alea au besoin
1697 1955
 	// charge aussi effacer_meta et ecrire_meta
@@ -1699,16 +1957,17 @@  discard block
 block discarded – undo
1699 1957
 	$inc_meta();
1700 1958
 
1701 1959
 	// on a pas pu le faire plus tot
1702
-	if  ($avertir_register_globals)
1703
-		avertir_auteurs("register_globals",_L("Probl&egrave;me de s&eacute;curit&eacute; : register_globals=on; dans php.ini &agrave; corriger."));
1960
+	if  ($avertir_register_globals) {
1961
+			avertir_auteurs("register_globals",_L("Probl&egrave;me de s&eacute;curit&eacute; : register_globals=on; dans php.ini &agrave; corriger."));
1962
+	}
1704 1963
 
1705 1964
 	// nombre de repertoires depuis la racine
1706 1965
 	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
1707 1966
 	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
1708 1967
 	// le calcul est faux)
1709
-	if (!_DIR_RESTREINT)
1710
-		$GLOBALS['profondeur_url'] = 1;
1711
-	else {
1968
+	if (!_DIR_RESTREINT) {
1969
+			$GLOBALS['profondeur_url'] = 1;
1970
+	} else {
1712 1971
 		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
1713 1972
 		$uri_ref = $_SERVER["SCRIPT_NAME"];
1714 1973
 		if (!$uri_ref
@@ -1721,13 +1980,13 @@  discard block
 block discarded – undo
1721 1980
 			if (isset($GLOBALS['meta']['adresse_site'])) {
1722 1981
 				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
1723 1982
 				$uri_ref = $uri_ref['path'].'/';
1724
-			}
1725
-		  else
1726
-			  $uri_ref = "";
1983
+			} else {
1984
+		  			  $uri_ref = "";
1985
+		  }
1727 1986
 		}
1728
-		if (!$uri OR !$uri_ref)
1729
-			$GLOBALS['profondeur_url'] = 0;
1730
-		else {
1987
+		if (!$uri OR !$uri_ref) {
1988
+					$GLOBALS['profondeur_url'] = 0;
1989
+		} else {
1731 1990
 			$GLOBALS['profondeur_url'] = max(0,
1732 1991
 				substr_count($uri[0], '/')
1733 1992
 				- substr_count($uri_ref,'/'));
@@ -1737,8 +1996,9 @@  discard block
 block discarded – undo
1737 1996
 	if (_FILE_CONNECT) {
1738 1997
 		if (verifier_visiteur()=='0minirezo'
1739 1998
 			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
1740
-		  AND !isset($_COOKIE['spip_admin']))
1741
-			clear_path_cache();
1999
+		  AND !isset($_COOKIE['spip_admin'])) {
2000
+					clear_path_cache();
2001
+		}
1742 2002
 	}
1743 2003
 
1744 2004
 }
@@ -1750,74 +2010,140 @@  discard block
 block discarded – undo
1750 2010
  */
1751 2011
 function spip_initialisation_suite() {
1752 2012
 	static $too_late = 0;
1753
-	if ($too_late++) return;
2013
+	if ($too_late++) {
2014
+	    return;
2015
+	}
1754 2016
 
1755 2017
 	// taille mini des login
1756
-	if (!defined('_LOGIN_TROP_COURT')) define('_LOGIN_TROP_COURT', 4);
2018
+	if (!defined('_LOGIN_TROP_COURT')) {
2019
+	    define('_LOGIN_TROP_COURT', 4);
2020
+	}
1757 2021
 
1758 2022
 	// la taille maxi des logos (0 : pas de limite)
1759
-	if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
1760
-	if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
1761
-	if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2023
+	if (!defined('_LOGO_MAX_SIZE')) {
2024
+	    define('_LOGO_MAX_SIZE', 0);
2025
+	}
2026
+	# poids en ko
2027
+	if (!defined('_LOGO_MAX_WIDTH')) {
2028
+	    define('_LOGO_MAX_WIDTH', 0);
2029
+	}
2030
+	# largeur en pixels
2031
+	if (!defined('_LOGO_MAX_HEIGHT')) {
2032
+	    define('_LOGO_MAX_HEIGHT', 0);
2033
+	}
2034
+	# hauteur en pixels
1762 2035
 
1763
-	if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2036
+	if (!defined('_DOC_MAX_SIZE')) {
2037
+	    define('_DOC_MAX_SIZE', 0);
2038
+	}
2039
+	# poids en ko
1764 2040
 
1765
-	if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
1766
-	if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
1767
-	if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
1768
-	if (!defined('_PASS_LONGUEUR_MINI')) define('_PASS_LONGUEUR_MINI',6);
2041
+	if (!defined('_IMG_MAX_SIZE')) {
2042
+	    define('_IMG_MAX_SIZE', 0);
2043
+	}
2044
+	# poids en ko
2045
+	if (!defined('_IMG_MAX_WIDTH')) {
2046
+	    define('_IMG_MAX_WIDTH', 0);
2047
+	}
2048
+	# largeur en pixels
2049
+	if (!defined('_IMG_MAX_HEIGHT')) {
2050
+	    define('_IMG_MAX_HEIGHT', 0);
2051
+	}
2052
+	# hauteur en pixels
2053
+	if (!defined('_PASS_LONGUEUR_MINI')) {
2054
+	    define('_PASS_LONGUEUR_MINI',6);
2055
+	}
1769 2056
 
1770 2057
 
1771 2058
 	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
1772
-        if (!defined('_IMG_QUALITE')) define('_IMG_QUALITE', 85); # valeur par defaut
1773
-        if (!defined('_IMG_GD_QUALITE')) define('_IMG_GD_QUALITE', _IMG_QUALITE); # surcharge pour la lib GD
1774
-        if (!defined('_IMG_CONVERT_QUALITE')) define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); # surcharge pour imagick en ligne de commande
2059
+        if (!defined('_IMG_QUALITE')) {
2060
+            define('_IMG_QUALITE', 85);
2061
+        }
2062
+        # valeur par defaut
2063
+        if (!defined('_IMG_GD_QUALITE')) {
2064
+            define('_IMG_GD_QUALITE', _IMG_QUALITE);
2065
+        }
2066
+        # surcharge pour la lib GD
2067
+        if (!defined('_IMG_CONVERT_QUALITE')) {
2068
+            define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2069
+        }
2070
+        # surcharge pour imagick en ligne de commande
1775 2071
 	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
1776
-        if (!defined('_IMG_IMAGICK_QUALITE')) define('_IMG_IMAGICK_QUALITE', 75); # surcharge pour imagick en PHP
2072
+        if (!defined('_IMG_IMAGICK_QUALITE')) {
2073
+            define('_IMG_IMAGICK_QUALITE', 75);
2074
+        }
2075
+        # surcharge pour imagick en PHP
1777 2076
 
1778
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) define('_COPIE_LOCALE_MAX_SIZE',16777216); // poids en octet
2077
+	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2078
+	    define('_COPIE_LOCALE_MAX_SIZE',16777216);
2079
+	}
2080
+	// poids en octet
1779 2081
 
1780 2082
 	// qq chaines standard
1781
-	if (!defined('_ACCESS_FILE_NAME')) define('_ACCESS_FILE_NAME', '.htaccess');
1782
-	if (!defined('_AUTH_USER_FILE')) define('_AUTH_USER_FILE', '.htpasswd');
1783
-	if (!defined('_SPIP_DUMP')) define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
1784
-	if (!defined('_CACHE_RUBRIQUES')) define('_CACHE_RUBRIQUES', _DIR_TMP.'menu-rubriques-cache.txt');
1785
-	if (!defined('_CACHE_RUBRIQUES_MAX')) define('_CACHE_RUBRIQUES_MAX', 500);
2083
+	if (!defined('_ACCESS_FILE_NAME')) {
2084
+	    define('_ACCESS_FILE_NAME', '.htaccess');
2085
+	}
2086
+	if (!defined('_AUTH_USER_FILE')) {
2087
+	    define('_AUTH_USER_FILE', '.htpasswd');
2088
+	}
2089
+	if (!defined('_SPIP_DUMP')) {
2090
+	    define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2091
+	}
2092
+	if (!defined('_CACHE_RUBRIQUES')) {
2093
+	    define('_CACHE_RUBRIQUES', _DIR_TMP.'menu-rubriques-cache.txt');
2094
+	}
2095
+	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2096
+	    define('_CACHE_RUBRIQUES_MAX', 500);
2097
+	}
1786 2098
 
1787
-	if (!defined('_EXTENSION_SQUELETTES')) define('_EXTENSION_SQUELETTES', 'html');
2099
+	if (!defined('_EXTENSION_SQUELETTES')) {
2100
+	    define('_EXTENSION_SQUELETTES', 'html');
2101
+	}
1788 2102
 
1789
-	if (!defined('_DOCTYPE_ECRIRE')) define('_DOCTYPE_ECRIRE',
2103
+	if (!defined('_DOCTYPE_ECRIRE')) {
2104
+	    define('_DOCTYPE_ECRIRE',
1790 2105
 		// "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>\n");
1791 2106
 		//"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n");
1792 2107
 		//"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n");
1793 2108
 	       // "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1 //EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>\n");
1794 2109
 		"<!DOCTYPE html>\n");
1795
-	if (!defined('_DOCTYPE_AIDE')) define('_DOCTYPE_AIDE',
2110
+	}
2111
+	if (!defined('_DOCTYPE_AIDE')) {
2112
+	    define('_DOCTYPE_AIDE',
1796 2113
 	       "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
2114
+	}
1797 2115
 
1798 2116
 	// L'adresse de base du site ; on peut mettre '' si la racine est geree par
1799 2117
 	// le script de l'espace public, alias  index.php
1800
-	if (!defined('_SPIP_SCRIPT')) define('_SPIP_SCRIPT', 'spip.php');
2118
+	if (!defined('_SPIP_SCRIPT')) {
2119
+	    define('_SPIP_SCRIPT', 'spip.php');
2120
+	}
1801 2121
 	// argument page, personalisable en cas de conflit avec un autre script
1802
-	if (!defined('_SPIP_PAGE')) define('_SPIP_PAGE', 'page');
2122
+	if (!defined('_SPIP_PAGE')) {
2123
+	    define('_SPIP_PAGE', 'page');
2124
+	}
1803 2125
 
1804 2126
 	// le script de l'espace prive
1805 2127
 	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
1806 2128
 	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
1807 2129
 	// meme pb sur thttpd cf. http://forum.spip.org/fr_184153.html
1808 2130
 
1809
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) define('_SPIP_ECRIRE_SCRIPT', // true ? #decommenter ici et commenter la
2131
+	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2132
+	    define('_SPIP_ECRIRE_SCRIPT', // true ? #decommenter ici et commenter la
1810 2133
 	       preg_match(',IIS|thttpd,',$_SERVER['SERVER_SOFTWARE']) ?
1811 2134
 	       'index.php' : '');
2135
+	}
1812 2136
 
1813 2137
 
1814
-	if (!defined('_SPIP_AJAX'))
1815
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2138
+	if (!defined('_SPIP_AJAX')) {
2139
+			define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
1816 2140
 			? 1
1817 2141
 		       : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2142
+	}
1818 2143
 
1819 2144
 	// La requete est-elle en ajax ?
1820
-	if (!defined('_AJAX')) define('_AJAX',
2145
+	if (!defined('_AJAX')) {
2146
+	    define('_AJAX',
1821 2147
 		(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
1822 2148
 		OR @$_REQUEST['var_ajax_redir'] # redirection 302 apres ajax jQuery
1823 2149
 		OR @$_REQUEST['var_ajaxcharset'] # compat ascendante pour plugins
@@ -1825,16 +2151,22 @@  discard block
 block discarded – undo
1825 2151
 		)
1826 2152
 		AND !@$_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
1827 2153
 	);
2154
+	}
1828 2155
 
1829 2156
 	# nombre de pixels maxi pour calcul de la vignette avec gd
1830 2157
 	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
1831 2158
 	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
1832
-	if (!defined('_IMG_GD_MAX_PIXELS')) define('_IMG_GD_MAX_PIXELS',
2159
+	if (!defined('_IMG_GD_MAX_PIXELS')) {
2160
+	    define('_IMG_GD_MAX_PIXELS',
1833 2161
 		(isset($GLOBALS['meta']['max_taille_vignettes'])&&$GLOBALS['meta']['max_taille_vignettes']<5500000)
1834 2162
 		 ? $GLOBALS['meta']['max_taille_vignettes']
1835 2163
 		 : 0);
2164
+	}
1836 2165
 
1837
-	if (!defined('_MEMORY_LIMIT_MIN')) define('_MEMORY_LIMIT_MIN',10); // en Mo
2166
+	if (!defined('_MEMORY_LIMIT_MIN')) {
2167
+	    define('_MEMORY_LIMIT_MIN',10);
2168
+	}
2169
+	// en Mo
1838 2170
 	// si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
1839 2171
 	// on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
1840 2172
 	// il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
@@ -1850,16 +2182,22 @@  discard block
 block discarded – undo
1850 2182
 			if ($memory<_MEMORY_LIMIT_MIN*1024*1024){
1851 2183
 				ini_set('memory_limit',$m=_MEMORY_LIMIT_MIN.'M');
1852 2184
 				if (trim(ini_get('memory_limit'))!=$m){
1853
-					if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) define('_INTERDIRE_COMPACTE_HEAD_ECRIRE',true); // evite une page blanche car on ne saura pas calculer la css dans ce hit
2185
+					if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2186
+					    define('_INTERDIRE_COMPACTE_HEAD_ECRIRE',true);
2187
+					}
2188
+					// evite une page blanche car on ne saura pas calculer la css dans ce hit
1854 2189
 				}
1855 2190
 			}
1856
-		}
1857
-		else
1858
-			if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) define('_INTERDIRE_COMPACTE_HEAD_ECRIRE',true); // evite une page blanche car on ne saura pas calculer la css dans ce hit
2191
+		} else
2192
+			if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2193
+			    define('_INTERDIRE_COMPACTE_HEAD_ECRIRE',true);
2194
+			}
2195
+			// evite une page blanche car on ne saura pas calculer la css dans ce hit
1859 2196
 	}
1860 2197
 	// Protocoles a normaliser dans les chaines de langues
1861
-	if (!defined('_PROTOCOLES_STD'))
1862
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2198
+	if (!defined('_PROTOCOLES_STD')) {
2199
+			define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2200
+	}
1863 2201
 
1864 2202
 	init_var_mode();
1865 2203
 }
@@ -1875,7 +2213,9 @@  discard block
 block discarded – undo
1875 2213
 			// tout le monde peut calcul/recalcul
1876 2214
 			if ($_GET['var_mode'] == 'calcul'
1877 2215
 			OR $_GET['var_mode'] == 'recalcul') {
1878
-				if (!defined('_VAR_MODE')) define('_VAR_MODE',$_GET['var_mode']);
2216
+				if (!defined('_VAR_MODE')) {
2217
+				    define('_VAR_MODE',$_GET['var_mode']);
2218
+				}
1879 2219
 			}
1880 2220
 			// preview, debug, blocs, urls et images necessitent une autorisation
1881 2221
 			else if (in_array($_GET['var_mode'],array('preview','debug','inclure','urls','images','traduction'))) {
@@ -1888,48 +2228,79 @@  discard block
 block discarded – undo
1888 2228
 					switch($_GET['var_mode']){
1889 2229
 						case 'traduction':
1890 2230
 							// forcer le calcul pour passer dans traduire
1891
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
2231
+							if (!defined('_VAR_MODE')) {
2232
+							    define('_VAR_MODE','calcul');
2233
+							}
1892 2234
 							// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
1893
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
2235
+							if (!defined('_VAR_NOCACHE')) {
2236
+							    define('_VAR_NOCACHE',true);
2237
+							}
1894 2238
 							break;
1895 2239
 						case 'preview':
1896 2240
 							// basculer sur les criteres de preview dans les boucles
1897
-							if (!defined('_VAR_PREVIEW')) define('_VAR_PREVIEW',true);
2241
+							if (!defined('_VAR_PREVIEW')) {
2242
+							    define('_VAR_PREVIEW',true);
2243
+							}
1898 2244
 							// forcer le calcul
1899
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
2245
+							if (!defined('_VAR_MODE')) {
2246
+							    define('_VAR_MODE','calcul');
2247
+							}
1900 2248
 							// et ne pas enregistrer de cache
1901
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
2249
+							if (!defined('_VAR_NOCACHE')) {
2250
+							    define('_VAR_NOCACHE',true);
2251
+							}
1902 2252
 							break;
1903 2253
 						case 'inclure':
1904 2254
 							// forcer le compilo et ignorer les caches existants
1905
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1906
-							if (!defined('_VAR_INCLURE')) define('_VAR_INCLURE',true);
2255
+							if (!defined('_VAR_MODE')) {
2256
+							    define('_VAR_MODE','calcul');
2257
+							}
2258
+							if (!defined('_VAR_INCLURE')) {
2259
+							    define('_VAR_INCLURE',true);
2260
+							}
1907 2261
 							// et ne pas enregistrer de cache
1908
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
2262
+							if (!defined('_VAR_NOCACHE')) {
2263
+							    define('_VAR_NOCACHE',true);
2264
+							}
1909 2265
 							break;
1910 2266
 						case 'urls':
1911 2267
 							// forcer le compilo et ignorer les caches existants
1912
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1913
-							if (!defined('_VAR_URLS')) define('_VAR_URLS',true);
2268
+							if (!defined('_VAR_MODE')) {
2269
+							    define('_VAR_MODE','calcul');
2270
+							}
2271
+							if (!defined('_VAR_URLS')) {
2272
+							    define('_VAR_URLS',true);
2273
+							}
1914 2274
 							break;
1915 2275
 						case 'images':
1916 2276
 							// forcer le compilo et ignorer les caches existants
1917
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
2277
+							if (!defined('_VAR_MODE')) {
2278
+							    define('_VAR_MODE','calcul');
2279
+							}
1918 2280
 							// indiquer qu'on doit recalculer les images
1919
-							if (!defined('_VAR_IMAGES')) define('_VAR_IMAGES',true);
2281
+							if (!defined('_VAR_IMAGES')) {
2282
+							    define('_VAR_IMAGES',true);
2283
+							}
1920 2284
 							break;
1921 2285
 						case 'debug':
1922
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','debug');
2286
+							if (!defined('_VAR_MODE')) {
2287
+							    define('_VAR_MODE','debug');
2288
+							}
1923 2289
 							// et ne pas enregistrer de cache
1924
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
2290
+							if (!defined('_VAR_NOCACHE')) {
2291
+							    define('_VAR_NOCACHE',true);
2292
+							}
1925 2293
 							break;
1926 2294
 						default :
1927
-							if (!defined('_VAR_MODE')) define('_VAR_MODE',$_GET['var_mode']);
2295
+							if (!defined('_VAR_MODE')) {
2296
+							    define('_VAR_MODE',$_GET['var_mode']);
2297
+							}
1928 2298
 							break;
1929 2299
 					}
1930
-          if (isset($GLOBALS['visiteur_session']['nom']))
1931
-					spip_log($GLOBALS['visiteur_session']['nom']
2300
+          if (isset($GLOBALS['visiteur_session']['nom'])) {
2301
+          					spip_log($GLOBALS['visiteur_session']['nom']
1932 2302
 						. " "._VAR_MODE);
2303
+          }
1933 2304
 				}
1934 2305
 				// pas autorise ?
1935 2306
 				else {
@@ -1944,7 +2315,9 @@  discard block
 block discarded – undo
1944 2315
 					// sinon tant pis
1945 2316
 				}
1946 2317
 			}
1947
-			if (!defined('_VAR_MODE')) define('_VAR_MODE',false);
2318
+			if (!defined('_VAR_MODE')) {
2319
+			    define('_VAR_MODE',false);
2320
+			}
1948 2321
 		}
1949 2322
 		$done = true;
1950 2323
 	}
@@ -1956,18 +2329,21 @@  discard block
 block discarded – undo
1956 2329
 // http://doc.spip.org/@spip_desinfecte
1957 2330
 function spip_desinfecte(&$t,$deep = true) {
1958 2331
 	static $magic_quotes;
1959
-	if (!isset($magic_quotes))
1960
-		$magic_quotes = @get_magic_quotes_gpc();
2332
+	if (!isset($magic_quotes)) {
2333
+			$magic_quotes = @get_magic_quotes_gpc();
2334
+	}
1961 2335
 
1962 2336
 	foreach ($t as $key => $val) {
1963 2337
 		if (is_string($t[$key])) {
1964
-			if ($magic_quotes)
1965
-				$t[$key] = stripslashes($t[$key]);
2338
+			if ($magic_quotes) {
2339
+							$t[$key] = stripslashes($t[$key]);
2340
+			}
1966 2341
 			$t[$key] = str_replace(chr(0), '-', $t[$key]);
1967 2342
 		}
1968 2343
 		// traiter aussi les "texte_plus" de article_edit
1969
-		else if ($deep AND is_array($t[$key]) AND $key!=='GLOBALS')
1970
-			spip_desinfecte($t[$key],$deep);
2344
+		else if ($deep AND is_array($t[$key]) AND $key!=='GLOBALS') {
2345
+					spip_desinfecte($t[$key],$deep);
2346
+		}
1971 2347
 	}
1972 2348
 }
1973 2349
 
@@ -2002,11 +2378,13 @@  discard block
 block discarded – undo
2002 2378
 		$session = charger_fonction('session', 'inc');
2003 2379
 		$session();
2004 2380
 		include_spip('inc/texte');
2005
-		foreach($variables_session as $var)
2006
-			if (($a = _request($var)) !== null)
2381
+		foreach($variables_session as $var) {
2382
+					if (($a = _request($var)) !== null)
2007 2383
 				$GLOBALS['visiteur_session'][$var] = safehtml($a);
2008
-		if (!isset($GLOBALS['visiteur_session']['id_auteur']))
2009
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
2384
+		}
2385
+		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
2386
+					$GLOBALS['visiteur_session']['id_auteur'] = 0;
2387
+		}
2010 2388
 		$session($GLOBALS['visiteur_session']);
2011 2389
 		return 0;
2012 2390
 	}
@@ -2045,15 +2423,17 @@  discard block
 block discarded – undo
2045 2423
 // http://doc.spip.org/@lang_select
2046 2424
 function lang_select ($lang=NULL) {
2047 2425
 	static $pile_langues = array();
2048
-	if (!function_exists('changer_langue'))
2049
-		include_spip('inc/lang');
2050
-	if ($lang === NULL)
2051
-		$lang = array_pop($pile_langues);
2052
-	else {
2426
+	if (!function_exists('changer_langue')) {
2427
+			include_spip('inc/lang');
2428
+	}
2429
+	if ($lang === NULL) {
2430
+			$lang = array_pop($pile_langues);
2431
+	} else {
2053 2432
 		array_push($pile_langues, $GLOBALS['spip_lang']);
2054 2433
 	}
2055
-	if (isset($GLOBALS['spip_lang']) AND $lang == $GLOBALS['spip_lang'])
2056
-		return $lang;
2434
+	if (isset($GLOBALS['spip_lang']) AND $lang == $GLOBALS['spip_lang']) {
2435
+			return $lang;
2436
+	}
2057 2437
 	changer_langue($lang);
2058 2438
 	return $lang;
2059 2439
 }
@@ -2104,11 +2484,12 @@  discard block
 block discarded – undo
2104 2484
 // http://doc.spip.org/@exec_info_dist
2105 2485
 function exec_info_dist() {
2106 2486
 	global $connect_statut;
2107
-	if ($connect_statut == '0minirezo')
2108
-		phpinfo();
2109
-	else
2110
-		echo "pas admin";
2111
-}
2487
+	if ($connect_statut == '0minirezo') {
2488
+			phpinfo();
2489
+	} else {
2490
+			echo "pas admin";
2491
+	}
2492
+	}
2112 2493
 
2113 2494
 /**
2114 2495
  * Génère une erreur de squelette
@@ -2167,12 +2548,17 @@  discard block
 block discarded – undo
2167 2548
  * 		ou tableau d'information sur le squelette.
2168 2549
  */
2169 2550
 function recuperer_fond($fond, $contexte=array(), $options = array(), $connect='') {
2170
-	if (!function_exists('evaluer_fond'))
2171
-		include_spip('public/assembler');
2551
+	if (!function_exists('evaluer_fond')) {
2552
+			include_spip('public/assembler');
2553
+	}
2172 2554
 	// assurer la compat avec l'ancienne syntaxe
2173 2555
 	// (trim etait le 3eme argument, par defaut a true)
2174
-	if (!is_array($options)) $options = array('trim'=>$options);
2175
-	if (!isset($options['trim'])) $options['trim']=true;
2556
+	if (!is_array($options)) {
2557
+	    $options = array('trim'=>$options);
2558
+	}
2559
+	if (!isset($options['trim'])) {
2560
+	    $options['trim']=true;
2561
+	}
2176 2562
 
2177 2563
 	if (isset($contexte['connect'])){
2178 2564
 		$connect = ($connect ? $connect : $contexte['connect']);
@@ -2184,8 +2570,9 @@  discard block
 block discarded – undo
2184 2570
 	$lang_select = '';
2185 2571
 	if (!isset($options['etoile']) OR !$options['etoile']){
2186 2572
 		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
2187
-		if (!isset($contexte['lang']))
2188
-			$contexte['lang'] = $GLOBALS['spip_lang'];
2573
+		if (!isset($contexte['lang'])) {
2574
+					$contexte['lang'] = $GLOBALS['spip_lang'];
2575
+		}
2189 2576
 
2190 2577
 		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
2191 2578
 			$lang_select = lang_select($contexte['lang']);
@@ -2210,25 +2597,30 @@  discard block
 block discarded – undo
2210 2597
 			'data'=>$page
2211 2598
 		));
2212 2599
 		if (isset($options['ajax']) AND $options['ajax']){
2213
-			if (!function_exists('encoder_contexte_ajax'))
2214
-				include_spip('inc/filtres');
2600
+			if (!function_exists('encoder_contexte_ajax')) {
2601
+							include_spip('inc/filtres');
2602
+			}
2215 2603
 			$page['texte'] = encoder_contexte_ajax(array_merge($contexte,array('fond'=>$f)),'',$page['texte'], $options['ajax']);
2216 2604
 		}
2217 2605
 
2218
-		if (isset($options['raw']) AND $options['raw'])
2219
-			$pages[] = $page;
2220
-		else
2221
-			$texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
2606
+		if (isset($options['raw']) AND $options['raw']) {
2607
+					$pages[] = $page;
2608
+		} else {
2609
+					$texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
2610
+		}
2222 2611
 	}
2223 2612
 
2224 2613
 	$GLOBALS['_INC_PUBLIC']--;
2225 2614
 
2226
-	if ($lang_select) lang_select();
2227
-	if (isset($options['raw']) AND $options['raw'])
2228
-		return is_array($fond)?$pages:reset($pages);
2229
-	else
2230
-		return $options['trim'] ? ltrim($texte) : $texte;
2231
-}
2615
+	if ($lang_select) {
2616
+	    lang_select();
2617
+	}
2618
+	if (isset($options['raw']) AND $options['raw']) {
2619
+			return is_array($fond)?$pages:reset($pages);
2620
+	} else {
2621
+			return $options['trim'] ? ltrim($texte) : $texte;
2622
+	}
2623
+	}
2232 2624
 
2233 2625
 /**
2234 2626
  * Trouve un squelette dans le repertoire modeles/
@@ -2254,7 +2646,9 @@  discard block
 block discarded – undo
2254 2646
  */
2255 2647
 function trouver_fond($nom, $dir='', $pathinfo = false) {
2256 2648
 	$f = find_in_path($nom.'.'. _EXTENSION_SQUELETTES, $dir?rtrim($dir,'/').'/':'');
2257
-	if (!$pathinfo) return $f;
2649
+	if (!$pathinfo) {
2650
+	    return $f;
2651
+	}
2258 2652
 	// renvoyer un tableau detaille si $pathinfo==true
2259 2653
 	$p = pathinfo($f);
2260 2654
 	if (!isset($p['extension']) OR !$p['extension']) {
@@ -2269,16 +2663,21 @@  discard block
 block discarded – undo
2269 2663
 
2270 2664
 function tester_url_ecrire($nom){
2271 2665
 	static $exec=array();
2272
-	if (isset($exec[$nom])) return $exec[$nom];
2666
+	if (isset($exec[$nom])) {
2667
+	    return $exec[$nom];
2668
+	}
2273 2669
 	// tester si c'est une page en squelette
2274
-	if (trouver_fond($nom, 'prive/squelettes/contenu/'))
2275
-		return $exec[$nom] = 'fond';
2670
+	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
2671
+			return $exec[$nom] = 'fond';
2672
+	}
2276 2673
 	// compat skels orthogonaux version precedente
2277
-	elseif (trouver_fond($nom, 'prive/exec/'))
2278
-		return $exec[$nom] = 'fond_monobloc';
2674
+	elseif (trouver_fond($nom, 'prive/exec/')) {
2675
+			return $exec[$nom] = 'fond_monobloc';
2676
+	}
2279 2677
 	// echafaudage d'un fond !
2280
-	elseif(include_spip('public/styliser_par_z') AND z_echafaudable($nom))
2281
-		return $exec[$nom] = 'fond';
2678
+	elseif(include_spip('public/styliser_par_z') AND z_echafaudable($nom)) {
2679
+			return $exec[$nom] = 'fond';
2680
+	}
2282 2681
 	// attention, il ne faut pas inclure l'exec ici
2283 2682
 	// car sinon #URL_ECRIRE provoque des inclusions
2284 2683
 	// et des define intrusifs potentiels
@@ -2322,13 +2721,23 @@  discard block
 block discarded – undo
2322 2721
 // http://doc.spip.org/@spip_fetch_array
2323 2722
 function spip_fetch_array($r, $t=NULL) {
2324 2723
 	if (!isset($t)) {
2325
-		if ($r) return sql_fetch($r);
2724
+		if ($r) {
2725
+		    return sql_fetch($r);
2726
+		}
2326 2727
 	} else {
2327
-		if ($t=='SPIP_NUM') $t = MYSQL_NUM;
2328
-		if ($t=='SPIP_BOTH') $t = MYSQL_BOTH;
2329
-		if ($t=='SPIP_ASSOC') $t = MYSQL_ASSOC;
2728
+		if ($t=='SPIP_NUM') {
2729
+		    $t = MYSQL_NUM;
2730
+		}
2731
+		if ($t=='SPIP_BOTH') {
2732
+		    $t = MYSQL_BOTH;
2733
+		}
2734
+		if ($t=='SPIP_ASSOC') {
2735
+		    $t = MYSQL_ASSOC;
2736
+		}
2330 2737
 		spip_log("appel deprecie de spip_fetch_array(..., $t)", 'vieilles_defs');
2331
-		if ($r) return mysql_fetch_array($r, $t);
2738
+		if ($r) {
2739
+		    return mysql_fetch_array($r, $t);
2740
+		}
2332 2741
 	}
2333 2742
 }
2334 2743
 
@@ -2345,11 +2754,13 @@  discard block
 block discarded – undo
2345 2754
 function avertir_auteurs($nom,$message, $statut=''){
2346 2755
 	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
2347 2756
 	if (!$alertes
2348
-		OR !is_array($alertes = unserialize($alertes)))
2349
-		$alertes = array();
2757
+		OR !is_array($alertes = unserialize($alertes))) {
2758
+			$alertes = array();
2759
+	}
2350 2760
 
2351
-	if (!isset($alertes[$statut]))
2352
-		$alertes[$statut] = array();
2761
+	if (!isset($alertes[$statut])) {
2762
+			$alertes[$statut] = array();
2763
+	}
2353 2764
 	$alertes[$statut][$nom] = $message;
2354 2765
 	ecrire_meta("message_alertes_auteurs",serialize($alertes));
2355 2766
 }
Please login to merge, or discard this patch.