Completed
Push — spip-3.0 ( cd2822...016705 )
by cam
08:31
created
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.
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.
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.
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   +163 added lines, -163 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
 
@@ -101,50 +101,50 @@  discard block
 block discarded – undo
101 101
  *     Code protégé
102 102
 **/
103 103
 function interdire_scripts($arg, $mode_filtre=null) {
104
-	// on memorise le resultat sur les arguments non triviaux
105
-	static $dejavu = array();
106
-
107
-	// Attention, si ce n'est pas une chaine, laisser intact
108
-	if (!$arg OR !is_string($arg) OR !strstr($arg, '<')) return $arg; 
109
-
110
-	if (is_null($mode_filtre) or !in_array($mode_filtre, array(-1, 0, 1))) {
111
-		$mode_filtre = $GLOBALS['filtrer_javascript'];
112
-	}
113
-
114
-	if (isset($dejavu[$mode_filtre][$arg])) {
115
-		return $dejavu[$mode_filtre][$arg];
116
-	}
117
-
118
-	// echapper les tags asp/php
119
-	$t = str_replace('<'.'%', '&lt;%', $arg);
120
-
121
-	// echapper le php
122
-	$t = str_replace('<'.'?', '&lt;?', $t);
123
-
124
-	// echapper le < script language=php >
125
-	$t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '&lt;\1', $t);
126
-
127
-	// Pour le js, trois modes : parano (-1), prive (0), ok (1)
128
-	switch ($mode_filtre) {
129
-		case 0:
130
-			if (!_DIR_RESTREINT)
131
-				$t = echappe_js($t);
132
-			break;
133
-		case -1:
134
-			$t = echappe_js($t);
135
-			break;
136
-	}
137
-
138
-	// pas de <base href /> svp !
139
-	$t = preg_replace(',<(base\b),iS', '&lt;\1', $t);
140
-
141
-	// Reinserer les echappements des modeles
142
-	if (defined('_PROTEGE_JS_MODELES'))
143
-		$t = echappe_retour($t,"javascript"._PROTEGE_JS_MODELES);
144
-	if (defined('_PROTEGE_PHP_MODELES'))
145
-		$t = echappe_retour($t,"php"._PROTEGE_PHP_MODELES);
146
-
147
-	return $dejavu[$mode_filtre][$arg] = $t;
104
+    // on memorise le resultat sur les arguments non triviaux
105
+    static $dejavu = array();
106
+
107
+    // Attention, si ce n'est pas une chaine, laisser intact
108
+    if (!$arg OR !is_string($arg) OR !strstr($arg, '<')) return $arg; 
109
+
110
+    if (is_null($mode_filtre) or !in_array($mode_filtre, array(-1, 0, 1))) {
111
+        $mode_filtre = $GLOBALS['filtrer_javascript'];
112
+    }
113
+
114
+    if (isset($dejavu[$mode_filtre][$arg])) {
115
+        return $dejavu[$mode_filtre][$arg];
116
+    }
117
+
118
+    // echapper les tags asp/php
119
+    $t = str_replace('<'.'%', '&lt;%', $arg);
120
+
121
+    // echapper le php
122
+    $t = str_replace('<'.'?', '&lt;?', $t);
123
+
124
+    // echapper le < script language=php >
125
+    $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '&lt;\1', $t);
126
+
127
+    // Pour le js, trois modes : parano (-1), prive (0), ok (1)
128
+    switch ($mode_filtre) {
129
+        case 0:
130
+            if (!_DIR_RESTREINT)
131
+                $t = echappe_js($t);
132
+            break;
133
+        case -1:
134
+            $t = echappe_js($t);
135
+            break;
136
+    }
137
+
138
+    // pas de <base href /> svp !
139
+    $t = preg_replace(',<(base\b),iS', '&lt;\1', $t);
140
+
141
+    // Reinserer les echappements des modeles
142
+    if (defined('_PROTEGE_JS_MODELES'))
143
+        $t = echappe_retour($t,"javascript"._PROTEGE_JS_MODELES);
144
+    if (defined('_PROTEGE_PHP_MODELES'))
145
+        $t = echappe_retour($t,"php"._PROTEGE_PHP_MODELES);
146
+
147
+    return $dejavu[$mode_filtre][$arg] = $t;
148 148
 }
149 149
 
150 150
 // Typographie generale
@@ -152,54 +152,54 @@  discard block
 block discarded – undo
152 152
 
153 153
 // http://doc.spip.org/@typo
154 154
 function typo($letexte, $echapper=true, $connect=null, $env=array()) {
155
-	// Plus vite !
156
-	if (!$letexte) return $letexte;
157
-
158
-	// les appels directs a cette fonction depuis le php de l'espace
159
-	// prive etant historiquement ecrit sans argment $connect
160
-	// on utilise la presence de celui-ci pour distinguer les cas
161
-	// ou il faut passer interdire_script explicitement
162
-	// les appels dans les squelettes (de l'espace prive) fournissant un $connect
163
-	// ne seront pas perturbes
164
-	$interdire_script = false;
165
-	if (is_null($connect)){
166
-		$connect = '';
167
-		$interdire_script = true;
168
-		$env['espace_prive'] = 1;
169
-	}
170
-
171
-	// Echapper les codes <html> etc
172
-	if ($echapper)
173
-		$letexte = echappe_html($letexte, 'TYPO');
174
-
175
-	//
176
-	// Installer les modeles, notamment images et documents ;
177
-	//
178
-	// NOTE : propre() ne passe pas par ici mais directement par corriger_typo
179
-	// cf. inc/lien
180
-
181
-	$letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env);
182
-	if ($letexte != $mem) $echapper = true;
183
-	unset($mem);
184
-
185
-	$letexte = corriger_typo($letexte);
186
-	$letexte = echapper_faux_tags($letexte);
187
-
188
-	// reintegrer les echappements
189
-	if ($echapper)
190
-		$letexte = echappe_retour($letexte, 'TYPO');
191
-
192
-	// Dans les appels directs hors squelette, securiser ici aussi
193
-	if ($interdire_script)
194
-		$letexte = interdire_scripts($letexte);
195
-
196
-	// Dans l'espace prive on se mefie de tout contenu dangereux
197
-	// https://core.spip.net/issues/3371
198
-	if (isset($env['espace_prive']) AND $env['espace_prive']){
199
-		$letexte = echapper_html_suspect($letexte);
200
-	}
201
-
202
-	return $letexte;
155
+    // Plus vite !
156
+    if (!$letexte) return $letexte;
157
+
158
+    // les appels directs a cette fonction depuis le php de l'espace
159
+    // prive etant historiquement ecrit sans argment $connect
160
+    // on utilise la presence de celui-ci pour distinguer les cas
161
+    // ou il faut passer interdire_script explicitement
162
+    // les appels dans les squelettes (de l'espace prive) fournissant un $connect
163
+    // ne seront pas perturbes
164
+    $interdire_script = false;
165
+    if (is_null($connect)){
166
+        $connect = '';
167
+        $interdire_script = true;
168
+        $env['espace_prive'] = 1;
169
+    }
170
+
171
+    // Echapper les codes <html> etc
172
+    if ($echapper)
173
+        $letexte = echappe_html($letexte, 'TYPO');
174
+
175
+    //
176
+    // Installer les modeles, notamment images et documents ;
177
+    //
178
+    // NOTE : propre() ne passe pas par ici mais directement par corriger_typo
179
+    // cf. inc/lien
180
+
181
+    $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env);
182
+    if ($letexte != $mem) $echapper = true;
183
+    unset($mem);
184
+
185
+    $letexte = corriger_typo($letexte);
186
+    $letexte = echapper_faux_tags($letexte);
187
+
188
+    // reintegrer les echappements
189
+    if ($echapper)
190
+        $letexte = echappe_retour($letexte, 'TYPO');
191
+
192
+    // Dans les appels directs hors squelette, securiser ici aussi
193
+    if ($interdire_script)
194
+        $letexte = interdire_scripts($letexte);
195
+
196
+    // Dans l'espace prive on se mefie de tout contenu dangereux
197
+    // https://core.spip.net/issues/3371
198
+    if (isset($env['espace_prive']) AND $env['espace_prive']){
199
+        $letexte = echapper_html_suspect($letexte);
200
+    }
201
+
202
+    return $letexte;
203 203
 }
204 204
 
205 205
 // Correcteur typographique
@@ -211,46 +211,46 @@  discard block
 block discarded – undo
211 211
 // http://doc.spip.org/@corriger_typo
212 212
 function corriger_typo($letexte, $lang='') {
213 213
 
214
-	// Plus vite !
215
-	if (!$letexte) return $letexte;
214
+    // Plus vite !
215
+    if (!$letexte) return $letexte;
216 216
 
217
-	$letexte = pipeline('pre_typo', $letexte);
217
+    $letexte = pipeline('pre_typo', $letexte);
218 218
 
219
-	// Caracteres de controle "illegaux"
220
-	$letexte = corriger_caracteres($letexte);
219
+    // Caracteres de controle "illegaux"
220
+    $letexte = corriger_caracteres($letexte);
221 221
 
222
-	// Proteger les caracteres typographiques a l'interieur des tags html
223
-	if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) {
224
-		foreach ($regs as $reg) {
225
-			$insert = $reg[0];
226
-			// hack: on transforme les caracteres a proteger en les remplacant
227
-			// par des caracteres "illegaux". (cf corriger_caracteres())
228
-			$insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR);
229
-			$letexte = str_replace($reg[0], $insert, $letexte);
230
-		}
231
-	}
222
+    // Proteger les caracteres typographiques a l'interieur des tags html
223
+    if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) {
224
+        foreach ($regs as $reg) {
225
+            $insert = $reg[0];
226
+            // hack: on transforme les caracteres a proteger en les remplacant
227
+            // par des caracteres "illegaux". (cf corriger_caracteres())
228
+            $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR);
229
+            $letexte = str_replace($reg[0], $insert, $letexte);
230
+        }
231
+    }
232 232
 
233
-	// trouver les blocs multi et les traiter a part
234
-	$letexte = extraire_multi($e = $letexte, $lang, true);
235
-	$e = ($e === $letexte);
233
+    // trouver les blocs multi et les traiter a part
234
+    $letexte = extraire_multi($e = $letexte, $lang, true);
235
+    $e = ($e === $letexte);
236 236
 
237
-	// Charger & appliquer les fonctions de typographie
238
-	$typographie = charger_fonction(lang_typo($lang), 'typographie');
239
-	$letexte = $typographie($letexte);
237
+    // Charger & appliquer les fonctions de typographie
238
+    $typographie = charger_fonction(lang_typo($lang), 'typographie');
239
+    $letexte = $typographie($letexte);
240 240
 
241
-	// Les citations en une autre langue, s'il y a lieu
242
-	if (!$e) $letexte = echappe_retour($letexte, 'multi');
241
+    // Les citations en une autre langue, s'il y a lieu
242
+    if (!$e) $letexte = echappe_retour($letexte, 'multi');
243 243
 
244
-	// Retablir les caracteres proteges
245
-	$letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER);
244
+    // Retablir les caracteres proteges
245
+    $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER);
246 246
 
247
-	// pipeline
248
-	$letexte = pipeline('post_typo', $letexte);
247
+    // pipeline
248
+    $letexte = pipeline('post_typo', $letexte);
249 249
 
250
-	# un message pour abs_url - on est passe en mode texte
251
-	$GLOBALS['mode_abs_url'] = 'texte';
250
+    # un message pour abs_url - on est passe en mode texte
251
+    $GLOBALS['mode_abs_url'] = 'texte';
252 252
 
253
-	return $letexte;
253
+    return $letexte;
254 254
 }
255 255
 
256 256
 
@@ -266,43 +266,43 @@  discard block
 block discarded – undo
266 266
 // http://doc.spip.org/@paragrapher
267 267
 // /!\ appelee dans inc/filtres et public/composer
268 268
 function paragrapher($letexte, $forcer=true) {
269
-	return $letexte;
269
+    return $letexte;
270 270
 }
271 271
 
272 272
 // Harmonise les retours chariots et mange les paragraphes html
273 273
 // http://doc.spip.org/@traiter_retours_chariots
274 274
 // ne sert plus
275 275
 function traiter_retours_chariots($letexte) {
276
-	$letexte = preg_replace(",\r\n?,S", "\n", $letexte);
277
-	$letexte = preg_replace(",<p[>[:space:]],iS", "\n\n\\0", $letexte);
278
-	$letexte = preg_replace(",</p[>[:space:]],iS", "\\0\n\n", $letexte);
279
-	return $letexte;
276
+    $letexte = preg_replace(",\r\n?,S", "\n", $letexte);
277
+    $letexte = preg_replace(",<p[>[:space:]],iS", "\n\n\\0", $letexte);
278
+    $letexte = preg_replace(",</p[>[:space:]],iS", "\\0\n\n", $letexte);
279
+    return $letexte;
280 280
 }
281 281
 
282 282
 
283 283
 // Filtre a appliquer aux champs du type #TEXTE*
284 284
 // http://doc.spip.org/@propre
285 285
 function propre($t, $connect=null, $env=array()) {
286
-	// les appels directs a cette fonction depuis le php de l'espace
287
-	// prive etant historiquement ecrits sans argment $connect
288
-	// on utilise la presence de celui-ci pour distinguer les cas
289
-	// ou il faut passer interdire_script explicitement
290
-	// les appels dans les squelettes (de l'espace prive) fournissant un $connect
291
-	// ne seront pas perturbes
292
-	$interdire_script = false;
293
-	if (is_null($connect)){
294
-		$connect = '';
295
-		$interdire_script = true;
296
-	}
297
-
298
-	if (!$t) return strval($t);
299
-
300
-	$t = echappe_html($t);
301
-	$t = expanser_liens($t,$connect, $env);
302
-	$t = traiter_raccourcis($t);
303
-	$t = echappe_retour_modeles($t, $interdire_script);
304
-
305
-	return $t;
286
+    // les appels directs a cette fonction depuis le php de l'espace
287
+    // prive etant historiquement ecrits sans argment $connect
288
+    // on utilise la presence de celui-ci pour distinguer les cas
289
+    // ou il faut passer interdire_script explicitement
290
+    // les appels dans les squelettes (de l'espace prive) fournissant un $connect
291
+    // ne seront pas perturbes
292
+    $interdire_script = false;
293
+    if (is_null($connect)){
294
+        $connect = '';
295
+        $interdire_script = true;
296
+    }
297
+
298
+    if (!$t) return strval($t);
299
+
300
+    $t = echappe_html($t);
301
+    $t = expanser_liens($t,$connect, $env);
302
+    $t = traiter_raccourcis($t);
303
+    $t = echappe_retour_modeles($t, $interdire_script);
304
+
305
+    return $t;
306 306
 }
307 307
 
308 308
 ?>
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],
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
  * @return string
101 101
  *     Code protégé
102 102
 **/
103
-function interdire_scripts($arg, $mode_filtre=null) {
103
+function interdire_scripts($arg, $mode_filtre = null) {
104 104
 	// on memorise le resultat sur les arguments non triviaux
105 105
 	static $dejavu = array();
106 106
 
@@ -140,9 +140,9 @@  discard block
 block discarded – undo
140 140
 
141 141
 	// Reinserer les echappements des modeles
142 142
 	if (defined('_PROTEGE_JS_MODELES'))
143
-		$t = echappe_retour($t,"javascript"._PROTEGE_JS_MODELES);
143
+		$t = echappe_retour($t, "javascript"._PROTEGE_JS_MODELES);
144 144
 	if (defined('_PROTEGE_PHP_MODELES'))
145
-		$t = echappe_retour($t,"php"._PROTEGE_PHP_MODELES);
145
+		$t = echappe_retour($t, "php"._PROTEGE_PHP_MODELES);
146 146
 
147 147
 	return $dejavu[$mode_filtre][$arg] = $t;
148 148
 }
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 // avec protection prealable des balises HTML et SPIP
152 152
 
153 153
 // http://doc.spip.org/@typo
154
-function typo($letexte, $echapper=true, $connect=null, $env=array()) {
154
+function typo($letexte, $echapper = true, $connect = null, $env = array()) {
155 155
 	// Plus vite !
156 156
 	if (!$letexte) return $letexte;
157 157
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	// les appels dans les squelettes (de l'espace prive) fournissant un $connect
163 163
 	// ne seront pas perturbes
164 164
 	$interdire_script = false;
165
-	if (is_null($connect)){
165
+	if (is_null($connect)) {
166 166
 		$connect = '';
167 167
 		$interdire_script = true;
168 168
 		$env['espace_prive'] = 1;
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 
196 196
 	// Dans l'espace prive on se mefie de tout contenu dangereux
197 197
 	// https://core.spip.net/issues/3371
198
-	if (isset($env['espace_prive']) AND $env['espace_prive']){
198
+	if (isset($env['espace_prive']) AND $env['espace_prive']) {
199 199
 		$letexte = echapper_html_suspect($letexte);
200 200
 	}
201 201
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 define('_TYPO_BALISE', ",</?[a-z!][^<>]*[".preg_quote(_TYPO_PROTEGER)."][^<>]*>,imsS");
210 210
 
211 211
 // http://doc.spip.org/@corriger_typo
212
-function corriger_typo($letexte, $lang='') {
212
+function corriger_typo($letexte, $lang = '') {
213 213
 
214 214
 	// Plus vite !
215 215
 	if (!$letexte) return $letexte;
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 //
266 266
 // http://doc.spip.org/@paragrapher
267 267
 // /!\ appelee dans inc/filtres et public/composer
268
-function paragrapher($letexte, $forcer=true) {
268
+function paragrapher($letexte, $forcer = true) {
269 269
 	return $letexte;
270 270
 }
271 271
 
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 
283 283
 // Filtre a appliquer aux champs du type #TEXTE*
284 284
 // http://doc.spip.org/@propre
285
-function propre($t, $connect=null, $env=array()) {
285
+function propre($t, $connect = null, $env = array()) {
286 286
 	// les appels directs a cette fonction depuis le php de l'espace
287 287
 	// prive etant historiquement ecrits sans argment $connect
288 288
 	// on utilise la presence de celui-ci pour distinguer les cas
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 	// les appels dans les squelettes (de l'espace prive) fournissant un $connect
291 291
 	// ne seront pas perturbes
292 292
 	$interdire_script = false;
293
-	if (is_null($connect)){
293
+	if (is_null($connect)) {
294 294
 		$connect = '';
295 295
 		$interdire_script = true;
296 296
 	}
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 	if (!$t) return strval($t);
299 299
 
300 300
 	$t = echappe_html($t);
301
-	$t = expanser_liens($t,$connect, $env);
301
+	$t = expanser_liens($t, $connect, $env);
302 302
 	$t = traiter_raccourcis($t);
303 303
 	$t = echappe_retour_modeles($t, $interdire_script);
304 304
 
Please login to merge, or discard this patch.
Braces   +42 added lines, -21 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
 
@@ -105,7 +108,9 @@  discard block
 block discarded – undo
105 108
 	static $dejavu = array();
106 109
 
107 110
 	// Attention, si ce n'est pas une chaine, laisser intact
108
-	if (!$arg OR !is_string($arg) OR !strstr($arg, '<')) return $arg; 
111
+	if (!$arg OR !is_string($arg) OR !strstr($arg, '<')) {
112
+	    return $arg;
113
+	}
109 114
 
110 115
 	if (is_null($mode_filtre) or !in_array($mode_filtre, array(-1, 0, 1))) {
111 116
 		$mode_filtre = $GLOBALS['filtrer_javascript'];
@@ -127,8 +132,9 @@  discard block
 block discarded – undo
127 132
 	// Pour le js, trois modes : parano (-1), prive (0), ok (1)
128 133
 	switch ($mode_filtre) {
129 134
 		case 0:
130
-			if (!_DIR_RESTREINT)
131
-				$t = echappe_js($t);
135
+			if (!_DIR_RESTREINT) {
136
+							$t = echappe_js($t);
137
+			}
132 138
 			break;
133 139
 		case -1:
134 140
 			$t = echappe_js($t);
@@ -139,10 +145,12 @@  discard block
 block discarded – undo
139 145
 	$t = preg_replace(',<(base\b),iS', '&lt;\1', $t);
140 146
 
141 147
 	// Reinserer les echappements des modeles
142
-	if (defined('_PROTEGE_JS_MODELES'))
143
-		$t = echappe_retour($t,"javascript"._PROTEGE_JS_MODELES);
144
-	if (defined('_PROTEGE_PHP_MODELES'))
145
-		$t = echappe_retour($t,"php"._PROTEGE_PHP_MODELES);
148
+	if (defined('_PROTEGE_JS_MODELES')) {
149
+			$t = echappe_retour($t,"javascript"._PROTEGE_JS_MODELES);
150
+	}
151
+	if (defined('_PROTEGE_PHP_MODELES')) {
152
+			$t = echappe_retour($t,"php"._PROTEGE_PHP_MODELES);
153
+	}
146 154
 
147 155
 	return $dejavu[$mode_filtre][$arg] = $t;
148 156
 }
@@ -153,7 +161,9 @@  discard block
 block discarded – undo
153 161
 // http://doc.spip.org/@typo
154 162
 function typo($letexte, $echapper=true, $connect=null, $env=array()) {
155 163
 	// Plus vite !
156
-	if (!$letexte) return $letexte;
164
+	if (!$letexte) {
165
+	    return $letexte;
166
+	}
157 167
 
158 168
 	// les appels directs a cette fonction depuis le php de l'espace
159 169
 	// prive etant historiquement ecrit sans argment $connect
@@ -169,8 +179,9 @@  discard block
 block discarded – undo
169 179
 	}
170 180
 
171 181
 	// Echapper les codes <html> etc
172
-	if ($echapper)
173
-		$letexte = echappe_html($letexte, 'TYPO');
182
+	if ($echapper) {
183
+			$letexte = echappe_html($letexte, 'TYPO');
184
+	}
174 185
 
175 186
 	//
176 187
 	// Installer les modeles, notamment images et documents ;
@@ -179,19 +190,23 @@  discard block
 block discarded – undo
179 190
 	// cf. inc/lien
180 191
 
181 192
 	$letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env);
182
-	if ($letexte != $mem) $echapper = true;
193
+	if ($letexte != $mem) {
194
+	    $echapper = true;
195
+	}
183 196
 	unset($mem);
184 197
 
185 198
 	$letexte = corriger_typo($letexte);
186 199
 	$letexte = echapper_faux_tags($letexte);
187 200
 
188 201
 	// reintegrer les echappements
189
-	if ($echapper)
190
-		$letexte = echappe_retour($letexte, 'TYPO');
202
+	if ($echapper) {
203
+			$letexte = echappe_retour($letexte, 'TYPO');
204
+	}
191 205
 
192 206
 	// Dans les appels directs hors squelette, securiser ici aussi
193
-	if ($interdire_script)
194
-		$letexte = interdire_scripts($letexte);
207
+	if ($interdire_script) {
208
+			$letexte = interdire_scripts($letexte);
209
+	}
195 210
 
196 211
 	// Dans l'espace prive on se mefie de tout contenu dangereux
197 212
 	// https://core.spip.net/issues/3371
@@ -212,7 +227,9 @@  discard block
 block discarded – undo
212 227
 function corriger_typo($letexte, $lang='') {
213 228
 
214 229
 	// Plus vite !
215
-	if (!$letexte) return $letexte;
230
+	if (!$letexte) {
231
+	    return $letexte;
232
+	}
216 233
 
217 234
 	$letexte = pipeline('pre_typo', $letexte);
218 235
 
@@ -239,7 +256,9 @@  discard block
 block discarded – undo
239 256
 	$letexte = $typographie($letexte);
240 257
 
241 258
 	// Les citations en une autre langue, s'il y a lieu
242
-	if (!$e) $letexte = echappe_retour($letexte, 'multi');
259
+	if (!$e) {
260
+	    $letexte = echappe_retour($letexte, 'multi');
261
+	}
243 262
 
244 263
 	// Retablir les caracteres proteges
245 264
 	$letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER);
@@ -295,7 +314,9 @@  discard block
 block discarded – undo
295 314
 		$interdire_script = true;
296 315
 	}
297 316
 
298
-	if (!$t) return strval($t);
317
+	if (!$t) {
318
+	    return strval($t);
319
+	}
299 320
 
300 321
 	$t = echappe_html($t);
301 322
 	$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.
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.
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.
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   +1520 added lines, -1521 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,49 +434,49 @@  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);
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);
464 463
 	
465
-	$url = str_replace(array("'", '"', '<', '[', ']'), array('%27', '%22', '%3C', '%5B', '%5D'), $url);
464
+    $url = str_replace(array("'", '"', '<', '[', ']'), array('%27', '%22', '%3C', '%5B', '%5D'), $url);
466 465
 
467
-	// &amp; ?
468
-	if ($amp != '&amp;')
469
-		$url = str_replace('&amp;', $amp, $url);
466
+    // &amp; ?
467
+    if ($amp != '&amp;')
468
+        $url = str_replace('&amp;', $amp, $url);
470 469
 
471
-	// Si ca demarre par ? ou vide, donner './'
472
-	$url = preg_replace(',^([?].*)?$,', './\1', $url);
470
+    // Si ca demarre par ? ou vide, donner './'
471
+    $url = preg_replace(',^([?].*)?$,', './\1', $url);
473 472
 
474
-	return $url;
473
+    return $url;
475 474
 }
476 475
 
477 476
 // Indique si on est dans l'espace prive
478 477
 // http://doc.spip.org/@test_espace_prive
479 478
 function test_espace_prive() {
480
-	return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
479
+    return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
481 480
 }
482 481
 
483 482
 /**
@@ -488,7 +487,7 @@  discard block
 block discarded – undo
488 487
  * @return bool
489 488
  */
490 489
 function test_plugin_actif($plugin){
491
-	return ($plugin AND defined('_DIR_PLUGIN_'.strtoupper($plugin)))? true:false;
490
+    return ($plugin AND defined('_DIR_PLUGIN_'.strtoupper($plugin)))? true:false;
492 491
 }
493 492
 
494 493
 /**
@@ -503,49 +502,49 @@  discard block
 block discarded – undo
503 502
  * @return mixed|string
504 503
  */
505 504
 function _T($texte, $args=array(), $options=array()) {
506
-	static $traduire=false ;
507
-	$o = array('class'=>'', 'force'=>true);
508
-	if ($options){
509
-		// support de l'ancien argument $class
510
-		if (is_string($options))
511
-			$options = array('class'=>$options);
512
-		$o = array_merge($o,$options);
513
-	}
514
-
515
- 	if (!$traduire) {
516
-		$traduire = charger_fonction('traduire', 'inc');
517
-		include_spip('inc/lang');
518
-	}
505
+    static $traduire=false ;
506
+    $o = array('class'=>'', 'force'=>true);
507
+    if ($options){
508
+        // support de l'ancien argument $class
509
+        if (is_string($options))
510
+            $options = array('class'=>$options);
511
+        $o = array_merge($o,$options);
512
+    }
513
+
514
+        if (!$traduire) {
515
+        $traduire = charger_fonction('traduire', 'inc');
516
+        include_spip('inc/lang');
517
+    }
519 518
 	
520
-	// On peut passer explicitement la langue dans le tableau
521
-	// On utilise le même nom de variable que la globale
522
-	if (isset($args['spip_lang'])){
523
-		$lang = $args['spip_lang'];
524
-		// On l'enleve pour ne pas le passer au remplacement
525
-		unset($args['spip_lang']);
526
-	}
527
-	// Sinon on prend la langue du contexte
528
-	else {
529
-		$lang = $GLOBALS['spip_lang'];
530
-	}
531
-	$text = $traduire($texte, $lang);
519
+    // On peut passer explicitement la langue dans le tableau
520
+    // On utilise le même nom de variable que la globale
521
+    if (isset($args['spip_lang'])){
522
+        $lang = $args['spip_lang'];
523
+        // On l'enleve pour ne pas le passer au remplacement
524
+        unset($args['spip_lang']);
525
+    }
526
+    // Sinon on prend la langue du contexte
527
+    else {
528
+        $lang = $GLOBALS['spip_lang'];
529
+    }
530
+    $text = $traduire($texte, $lang);
532 531
 
533
-	if (!strlen($text)){
534
-		if (!$o['force'])
535
-			return '';
532
+    if (!strlen($text)){
533
+        if (!$o['force'])
534
+            return '';
536 535
 
537
-		$text = $texte;
536
+        $text = $texte;
538 537
 
539
-		// pour les chaines non traduites, assurer un service minimum
540
-		if (!$GLOBALS['test_i18n'] AND (_request('var_mode') != 'traduction'))
541
-			$text = str_replace('_', ' ',
542
-				 (($n = strpos($text,':')) === false ? $texte :
543
-					substr($texte, $n+1)));
544
-		$o['class'] = null;
538
+        // pour les chaines non traduites, assurer un service minimum
539
+        if (!$GLOBALS['test_i18n'] AND (_request('var_mode') != 'traduction'))
540
+            $text = str_replace('_', ' ',
541
+                    (($n = strpos($text,':')) === false ? $texte :
542
+                    substr($texte, $n+1)));
543
+        $o['class'] = null;
545 544
 
546
-	}
545
+    }
547 546
 
548
-	return _L($text, $args, $o['class']);
547
+    return _L($text, $args, $o['class']);
549 548
 
550 549
 }
551 550
 
@@ -553,34 +552,34 @@  discard block
 block discarded – undo
553 552
 // Aussi appelee quand une chaine n'est pas encore dans les fichiers de langue
554 553
 // http://doc.spip.org/@_L
555 554
 function _L($text, $args=array(), $class=null) {
556
-	$f = $text;
557
-	if (is_array($args)) {
558
-		foreach ($args as $name => $value) {
559
-			if ($class)
560
-				$value = "<span class='$class'>$value</span>";
561
-			$t = str_replace ("@$name@", $value, $text);
562
-			if ($text !== $t) {unset($args[$name]); $text = $t;}
563
-		}
564
-		// Si des variables n'ont pas ete inserees, le signaler
565
-		// (chaines de langues pas a jour)
566
-		if ($args) spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)),_LOG_DEBUG);
567
-	}
568
-
569
-	if (($GLOBALS['test_i18n'] OR (_request('var_mode') == 'traduction')) AND $class===null)
570
-		return "<span class=debug-traduction-erreur>$text</span>";
571
-	else
572
-		return $text;
555
+    $f = $text;
556
+    if (is_array($args)) {
557
+        foreach ($args as $name => $value) {
558
+            if ($class)
559
+                $value = "<span class='$class'>$value</span>";
560
+            $t = str_replace ("@$name@", $value, $text);
561
+            if ($text !== $t) {unset($args[$name]); $text = $t;}
562
+        }
563
+        // Si des variables n'ont pas ete inserees, le signaler
564
+        // (chaines de langues pas a jour)
565
+        if ($args) spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)),_LOG_DEBUG);
566
+    }
567
+
568
+    if (($GLOBALS['test_i18n'] OR (_request('var_mode') == 'traduction')) AND $class===null)
569
+        return "<span class=debug-traduction-erreur>$text</span>";
570
+    else
571
+        return $text;
573 572
 }
574 573
 
575 574
 // Afficher "ecrire/data/" au lieu de "data/" dans les messages
576 575
 // ou tmp/ au lieu de ../tmp/
577 576
 // http://doc.spip.org/@joli_repertoire
578 577
 function joli_repertoire($rep) {
579
-	$a = substr($rep,0,1);
580
-	if ($a<>'.' AND $a<>'/')
581
-		$rep = (_DIR_RESTREINT?'':_DIR_RESTREINT_ABS).$rep;
582
-	$rep = preg_replace(',(^\.\.\/),', '', $rep);
583
-	return $rep;
578
+    $a = substr($rep,0,1);
579
+    if ($a<>'.' AND $a<>'/')
580
+        $rep = (_DIR_RESTREINT?'':_DIR_RESTREINT_ABS).$rep;
581
+    $rep = preg_replace(',(^\.\.\/),', '', $rep);
582
+    return $rep;
584 583
 }
585 584
 
586 585
 
@@ -589,27 +588,27 @@  discard block
 block discarded – undo
589 588
 //
590 589
 // http://doc.spip.org/@spip_timer
591 590
 function spip_timer($t='rien', $raw = false) {
592
-	static $time;
593
-	$a=time(); $b=microtime();
594
-	// microtime peut contenir les microsecondes et le temps
595
-	$b=explode(' ',$b);
596
-	if (count($b)==2) $a = end($b); // plus precis !
597
-	$b = reset($b);
598
-	if (!isset($time[$t])) {
599
-		$time[$t] = $a + $b;
600
-	} else {
601
-		$p = ($a + $b - $time[$t]) * 1000;
602
-		unset($time[$t]);
591
+    static $time;
592
+    $a=time(); $b=microtime();
593
+    // microtime peut contenir les microsecondes et le temps
594
+    $b=explode(' ',$b);
595
+    if (count($b)==2) $a = end($b); // plus precis !
596
+    $b = reset($b);
597
+    if (!isset($time[$t])) {
598
+        $time[$t] = $a + $b;
599
+    } else {
600
+        $p = ($a + $b - $time[$t]) * 1000;
601
+        unset($time[$t]);
603 602
 #			echo "'$p'";exit;
604
-		if ($raw) return $p;
605
-		if ($p < 1000)
606
-			$s = '';
607
-		else {
608
-			$s = sprintf("%d ", $x = floor($p/1000));
609
-			$p -= ($x*1000);
610
-		}
611
-		return $s . sprintf($s?"%07.3f ms":"%.3f ms", $p);
612
-	}
603
+        if ($raw) return $p;
604
+        if ($p < 1000)
605
+            $s = '';
606
+        else {
607
+            $s = sprintf("%d ", $x = floor($p/1000));
608
+            $p -= ($x*1000);
609
+        }
610
+        return $s . sprintf($s?"%07.3f ms":"%.3f ms", $p);
611
+    }
613 612
 }
614 613
 
615 614
 
@@ -617,16 +616,16 @@  discard block
 block discarded – undo
617 616
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
618 617
 // http://doc.spip.org/@spip_touch
619 618
 function spip_touch($fichier, $duree=0, $touch=true) {
620
-	if ($duree) {
621
-		clearstatcache();
622
-		if ((@$f=filemtime($fichier)) AND ($f >= time() - $duree))
623
-			return false;
624
-	}
625
-	if ($touch!==false) {
626
-		if (!@touch($fichier)) { spip_unlink($fichier); @touch($fichier); };
627
-		@chmod($fichier, _SPIP_CHMOD & ~0111);
628
-	}
629
-	return true;
619
+    if ($duree) {
620
+        clearstatcache();
621
+        if ((@$f=filemtime($fichier)) AND ($f >= time() - $duree))
622
+            return false;
623
+    }
624
+    if ($touch!==false) {
625
+        if (!@touch($fichier)) { spip_unlink($fichier); @touch($fichier); };
626
+        @chmod($fichier, _SPIP_CHMOD & ~0111);
627
+    }
628
+    return true;
630 629
 }
631 630
 
632 631
 // Ce declencheur de tache de fond, de l'espace prive (cf inc_presentation)
@@ -638,11 +637,11 @@  discard block
 block discarded – undo
638 637
 
639 638
 // http://doc.spip.org/@action_cron
640 639
 function action_cron() {
641
-	include_spip('inc/headers');
642
-	http_status(204); // No Content
643
-	header("Connection: close");
644
-	define('_DIRECT_CRON_FORCE',true);
645
-	cron();
640
+    include_spip('inc/headers');
641
+    http_status(204); // No Content
642
+    header("Connection: close");
643
+    define('_DIRECT_CRON_FORCE',true);
644
+    cron();
646 645
 }
647 646
 
648 647
 /**
@@ -662,19 +661,19 @@  discard block
 block discarded – undo
662 661
  * @return bool
663 662
  */
664 663
 function cron ($taches=array(), $taches_old= array()) {
665
-	// si pas en mode cron force, laisser tomber.
666
-	if (!defined('_DIRECT_CRON_FORCE')) return false;
667
-	if (!is_array($taches)) $taches = $taches_old; // compat anciens appels
668
-	// si taches a inserer en base et base inaccessible, laisser tomber
669
-	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
670
-	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
671
-	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
672
-	if ($taches AND count($taches) AND !spip_connect())  return false;
673
-	spip_log("cron !",'jq'._LOG_DEBUG);
674
-	if ($genie = charger_fonction('genie', 'inc', true)) {
675
-		return $genie($taches);
676
-	}
677
-	return false;
664
+    // si pas en mode cron force, laisser tomber.
665
+    if (!defined('_DIRECT_CRON_FORCE')) return false;
666
+    if (!is_array($taches)) $taches = $taches_old; // compat anciens appels
667
+    // si taches a inserer en base et base inaccessible, laisser tomber
668
+    // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
669
+    // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
670
+    // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
671
+    if ($taches AND count($taches) AND !spip_connect())  return false;
672
+    spip_log("cron !",'jq'._LOG_DEBUG);
673
+    if ($genie = charger_fonction('genie', 'inc', true)) {
674
+        return $genie($taches);
675
+    }
676
+    return false;
678 677
 }
679 678
 
680 679
 /**
@@ -700,8 +699,8 @@  discard block
 block discarded – undo
700 699
  *	id of job
701 700
  */
702 701
 function job_queue_add($function, $description, $arguments = array(), $file = '', $no_duplicate = FALSE, $time=0, $priority=0) {
703
-	include_spip('inc/queue');
704
-	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
702
+    include_spip('inc/queue');
703
+    return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
705 704
 }
706 705
 
707 706
 /**
@@ -711,8 +710,8 @@  discard block
 block discarded – undo
711 710
  * @return bool
712 711
  */
713 712
 function job_queue_remove($id_job){
714
-	include_spip('inc/queue');
715
-	return queue_remove_job($id_job);
713
+    include_spip('inc/queue');
714
+    return queue_remove_job($id_job);
716 715
 }
717 716
 
718 717
 /**
@@ -724,8 +723,8 @@  discard block
 block discarded – undo
724 723
  *  or an array of simple array to link multiples objet in one time
725 724
  */
726 725
 function job_queue_link($id_job,$objets){
727
-	include_spip('inc/queue');
728
-	return queue_link_job($id_job,$objets);
726
+    include_spip('inc/queue');
727
+    return queue_link_job($id_job,$objets);
729 728
 }
730 729
 
731 730
 
@@ -742,62 +741,62 @@  discard block
 block discarded – undo
742 741
  * @return int
743 742
  */
744 743
 function queue_sleep_time_to_next_job($force=null) {
745
-	static $queue_next_job_time = -1;
746
-	if ($force===true)
747
-		$queue_next_job_time = -1;
748
-	elseif ($force)
749
-		$queue_next_job_time = $force;
750
-
751
-	if ($queue_next_job_time==-1) {
752
-		define('_JQ_NEXT_JOB_TIME_FILENAME',_DIR_TMP . "job_queue_next.txt");
753
-		// utiliser un cache memoire si dispo
754
-		if (include_spip('inc/memoization') AND defined('_MEMOIZE_MEMORY') AND _MEMOIZE_MEMORY) {
755
-			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
756
-		}
757
-		else {
758
-			$queue_next_job_time = null;
759
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu))
760
-				$queue_next_job_time = intval($contenu);
761
-		}
762
-	}
763
-
764
-	if (is_null($queue_next_job_time))
765
-		return null;
766
-	if (!$_SERVER['REQUEST_TIME'])
767
-		$_SERVER['REQUEST_TIME'] = time();
768
-	return $queue_next_job_time-$_SERVER['REQUEST_TIME'];
744
+    static $queue_next_job_time = -1;
745
+    if ($force===true)
746
+        $queue_next_job_time = -1;
747
+    elseif ($force)
748
+        $queue_next_job_time = $force;
749
+
750
+    if ($queue_next_job_time==-1) {
751
+        define('_JQ_NEXT_JOB_TIME_FILENAME',_DIR_TMP . "job_queue_next.txt");
752
+        // utiliser un cache memoire si dispo
753
+        if (include_spip('inc/memoization') AND defined('_MEMOIZE_MEMORY') AND _MEMOIZE_MEMORY) {
754
+            $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
755
+        }
756
+        else {
757
+            $queue_next_job_time = null;
758
+            if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu))
759
+                $queue_next_job_time = intval($contenu);
760
+        }
761
+    }
762
+
763
+    if (is_null($queue_next_job_time))
764
+        return null;
765
+    if (!$_SERVER['REQUEST_TIME'])
766
+        $_SERVER['REQUEST_TIME'] = time();
767
+    return $queue_next_job_time-$_SERVER['REQUEST_TIME'];
769 768
 }
770 769
 
771 770
 
772 771
 // transformation XML des "&" en "&amp;"
773 772
 // http://doc.spip.org/@quote_amp
774 773
 function quote_amp($u) {
775
-	return preg_replace(
776
-		"/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,5};)/i",
777
-		"&amp;",$u);
774
+    return preg_replace(
775
+        "/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,5};)/i",
776
+        "&amp;",$u);
778 777
 }
779 778
 
780 779
 // Production d'une balise Script valide
781 780
 // http://doc.spip.org/@http_script
782 781
 function http_script($script, $src='', $noscript='') {
783
-	static $done = array();
784
-
785
-	if ($src && !isset($done[$src])){
786
-		$done[$src] = true;
787
-		$src = find_in_path($src, _JAVASCRIPT);
788
-		$src = " src='$src'";
789
-	}
790
-	else $src = '';
791
-	if ($script)
792
-		$script = ("/*<![CDATA[*/\n" .
793
-		preg_replace(',</([^>]*)>,','<\/\1>', $script) .
794
-		"/*]]>*/");
795
-	if ($noscript)
796
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
797
-
798
-	return ($src OR $script OR $noscript)
799
-	? "<script type='text/javascript'$src>$script</script>$noscript"
800
-	: '';
782
+    static $done = array();
783
+
784
+    if ($src && !isset($done[$src])){
785
+        $done[$src] = true;
786
+        $src = find_in_path($src, _JAVASCRIPT);
787
+        $src = " src='$src'";
788
+    }
789
+    else $src = '';
790
+    if ($script)
791
+        $script = ("/*<![CDATA[*/\n" .
792
+        preg_replace(',</([^>]*)>,','<\/\1>', $script) .
793
+        "/*]]>*/");
794
+    if ($noscript)
795
+        $noscript = "<noscript>\n\t$noscript\n</noscript>\n";
796
+
797
+    return ($src OR $script OR $noscript)
798
+    ? "<script type='text/javascript'$src>$script</script>$noscript"
799
+    : '';
801 800
 }
802 801
 
803 802
 // Transforme n'importe quel champ en une chaine utilisable
@@ -805,7 +804,7 @@  discard block
 block discarded – undo
805 804
 // < ? php $x = '[(#TEXTE|texte_script)]'; ? >
806 805
 // http://doc.spip.org/@texte_script
807 806
 function texte_script($texte) {
808
-	return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
807
+    return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
809 808
 }
810 809
 
811 810
 // Chaque appel a cette fonction ajoute un repertoire en tete du chemin courant (path)
@@ -816,107 +815,107 @@  discard block
 block discarded – undo
816 815
 // Exception: si un $dossier_squelette est defini, il reste en tete, pour raison historique
817 816
 // http://doc.spip.org/@_chemin
818 817
 function _chemin($dir_path=NULL){
819
-	static $path_base = NULL;
820
-	static $path_full = NULL;
821
-	if ($path_base==NULL){
822
-		// Chemin standard depuis l'espace public
823
-		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
824
-			_DIR_RACINE.':'.
825
-			_DIR_RACINE.'squelettes-dist/:'.
826
-			_DIR_RACINE.'prive/:'.
827
-			_DIR_RESTREINT;
828
-		// Ajouter squelettes/
829
-		if (@is_dir(_DIR_RACINE.'squelettes'))
830
-			$path = _DIR_RACINE.'squelettes/:' . $path;
831
-		foreach (explode(':', $path) as $dir) {
832
-			if (strlen($dir) AND substr($dir,-1) != '/')
833
-				$dir .= "/";
834
-			$path_base[] = $dir;
835
-		}
836
-		$path_full = $path_base;
837
-		// Et le(s) dossier(s) des squelettes nommes
838
-		if (strlen($GLOBALS['dossier_squelettes']))
839
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
840
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
841
-		$GLOBALS['path_sig'] = md5(serialize($path_full));
842
-	}
843
-	if ($dir_path===NULL) return $path_full;
844
-
845
-	if (strlen($dir_path)){
846
-		$tete = "";
847
-		if (reset($path_base)==_DIR_RACINE.'squelettes/')
848
-			$tete = array_shift($path_base);
849
-		$dirs = array_reverse(explode(':',$dir_path));
850
-		foreach($dirs as $dir_path){
851
-				#if ($dir_path{0}!='/')
852
-				#	$dir_path = $dir_path;
853
-				if (substr($dir_path,-1) != '/')
854
-					$dir_path .= "/";
855
-				if (!in_array($dir_path,$path_base))
856
-					array_unshift($path_base,$dir_path);
857
-		}
858
-		if (strlen($tete))
859
-			array_unshift($path_base,$tete);
860
-	}
861
-	$path_full = $path_base;
862
-	// Et le(s) dossier(s) des squelettes nommes
863
-	if (strlen($GLOBALS['dossier_squelettes']))
864
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
865
-			array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
866
-
867
-	$GLOBALS['path_sig'] = md5(serialize($path_full));
868
-	return $path_full;
818
+    static $path_base = NULL;
819
+    static $path_full = NULL;
820
+    if ($path_base==NULL){
821
+        // Chemin standard depuis l'espace public
822
+        $path = defined('_SPIP_PATH') ? _SPIP_PATH :
823
+            _DIR_RACINE.':'.
824
+            _DIR_RACINE.'squelettes-dist/:'.
825
+            _DIR_RACINE.'prive/:'.
826
+            _DIR_RESTREINT;
827
+        // Ajouter squelettes/
828
+        if (@is_dir(_DIR_RACINE.'squelettes'))
829
+            $path = _DIR_RACINE.'squelettes/:' . $path;
830
+        foreach (explode(':', $path) as $dir) {
831
+            if (strlen($dir) AND substr($dir,-1) != '/')
832
+                $dir .= "/";
833
+            $path_base[] = $dir;
834
+        }
835
+        $path_full = $path_base;
836
+        // Et le(s) dossier(s) des squelettes nommes
837
+        if (strlen($GLOBALS['dossier_squelettes']))
838
+            foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
839
+                array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
840
+        $GLOBALS['path_sig'] = md5(serialize($path_full));
841
+    }
842
+    if ($dir_path===NULL) return $path_full;
843
+
844
+    if (strlen($dir_path)){
845
+        $tete = "";
846
+        if (reset($path_base)==_DIR_RACINE.'squelettes/')
847
+            $tete = array_shift($path_base);
848
+        $dirs = array_reverse(explode(':',$dir_path));
849
+        foreach($dirs as $dir_path){
850
+                #if ($dir_path{0}!='/')
851
+                #	$dir_path = $dir_path;
852
+                if (substr($dir_path,-1) != '/')
853
+                    $dir_path .= "/";
854
+                if (!in_array($dir_path,$path_base))
855
+                    array_unshift($path_base,$dir_path);
856
+        }
857
+        if (strlen($tete))
858
+            array_unshift($path_base,$tete);
859
+    }
860
+    $path_full = $path_base;
861
+    // Et le(s) dossier(s) des squelettes nommes
862
+    if (strlen($GLOBALS['dossier_squelettes']))
863
+        foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
864
+            array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
865
+
866
+    $GLOBALS['path_sig'] = md5(serialize($path_full));
867
+    return $path_full;
869 868
 }
870 869
 
871 870
 // http://doc.spip.org/@creer_chemin
872 871
 function creer_chemin() {
873
-	$path_a = _chemin();
874
-	static $c = '';
872
+    $path_a = _chemin();
873
+    static $c = '';
875 874
 
876
-	// on calcule le chemin si le dossier skel a change
877
-	if ($c != $GLOBALS['dossier_squelettes']) {
878
-		// assurer le non plantage lors de la montee de version :
879
-		$c = $GLOBALS['dossier_squelettes'];
880
-		$path_a = _chemin(''); // forcer un recalcul du chemin
881
-	}
882
-	return $path_a;
875
+    // on calcule le chemin si le dossier skel a change
876
+    if ($c != $GLOBALS['dossier_squelettes']) {
877
+        // assurer le non plantage lors de la montee de version :
878
+        $c = $GLOBALS['dossier_squelettes'];
879
+        $path_a = _chemin(''); // forcer un recalcul du chemin
880
+    }
881
+    return $path_a;
883 882
 }
884 883
 
885 884
 
886 885
 function lister_themes_prives(){
887
-	static $themes = null;
888
-	if (is_null($themes)){
889
-		// si pas encore definie
890
-		if (!defined('_SPIP_THEME_PRIVE'))
891
-			define('_SPIP_THEME_PRIVE', 'spip');
892
-		$themes = array(_SPIP_THEME_PRIVE);
893
-		// lors d'une installation neuve, prefs n'est pas definie.
894
-		if (isset($GLOBALS['visiteur_session']['prefs'])) {
895
-			$prefs = $GLOBALS['visiteur_session']['prefs'];
896
-		} else {
897
-			$prefs = array();
898
-		}
899
-		if (is_string($prefs))
900
-			$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
901
-		if (
902
-			((isset($prefs['theme']) AND $theme = $prefs['theme'])
903
-			OR (isset($GLOBALS['theme_prive_defaut']) AND $theme = $GLOBALS['theme_prive_defaut']))
904
-			AND $theme != _SPIP_THEME_PRIVE)
905
-			array_unshift($themes,$theme); // placer le theme choisi en tete
906
-	}
907
-	return $themes;
886
+    static $themes = null;
887
+    if (is_null($themes)){
888
+        // si pas encore definie
889
+        if (!defined('_SPIP_THEME_PRIVE'))
890
+            define('_SPIP_THEME_PRIVE', 'spip');
891
+        $themes = array(_SPIP_THEME_PRIVE);
892
+        // lors d'une installation neuve, prefs n'est pas definie.
893
+        if (isset($GLOBALS['visiteur_session']['prefs'])) {
894
+            $prefs = $GLOBALS['visiteur_session']['prefs'];
895
+        } else {
896
+            $prefs = array();
897
+        }
898
+        if (is_string($prefs))
899
+            $prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
900
+        if (
901
+            ((isset($prefs['theme']) AND $theme = $prefs['theme'])
902
+            OR (isset($GLOBALS['theme_prive_defaut']) AND $theme = $GLOBALS['theme_prive_defaut']))
903
+            AND $theme != _SPIP_THEME_PRIVE)
904
+            array_unshift($themes,$theme); // placer le theme choisi en tete
905
+    }
906
+    return $themes;
908 907
 }
909 908
 
910 909
 function find_in_theme($file, $subdir='', $include=false){
911
-	static $themefiles=array();
912
-	if (isset($themefiles["$subdir$file"])) return $themefiles["$subdir$file"];
913
-	$themes = lister_themes_prives();
914
-	foreach($themes as $theme){
915
-		if ($f = find_in_path($file,"prive/themes/$theme/$subdir",$include))
916
-			return $themefiles["$subdir$file"] = $f;
917
-	}
918
-	spip_log("$file introuvable dans le theme prive ".reset($themes),'theme');
919
-	return $themefiles["$subdir$file"] = "";
910
+    static $themefiles=array();
911
+    if (isset($themefiles["$subdir$file"])) return $themefiles["$subdir$file"];
912
+    $themes = lister_themes_prives();
913
+    foreach($themes as $theme){
914
+        if ($f = find_in_path($file,"prive/themes/$theme/$subdir",$include))
915
+            return $themefiles["$subdir$file"] = $f;
916
+    }
917
+    spip_log("$file introuvable dans le theme prive ".reset($themes),'theme');
918
+    return $themefiles["$subdir$file"] = "";
920 919
 }
921 920
 
922 921
 // Cherche une image dans les dossiers images
@@ -926,22 +925,22 @@  discard block
 block discarded – undo
926 925
 // dans _DIR_IMG_PACK
927 926
 // http://doc.spip.org/@chemin_image
928 927
 function chemin_image($icone){
929
-	static $icone_renommer;
930
-	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
931
-	if (strpos($icone,"/")!==false AND file_exists($icone)) return $icone;
928
+    static $icone_renommer;
929
+    // gerer le cas d'un double appel en evitant de refaire le travail inutilement
930
+    if (strpos($icone,"/")!==false AND file_exists($icone)) return $icone;
932 931
 	
933
-	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
934
-	if (preg_match(',[.](png|gif|jpg)$,',$icone) AND $f = find_in_theme("images/$icone"))
935
-		return $f;
936
-	// sinon passer par le module de renommage
937
-	if (is_null($icone_renommer))
938
-		$icone_renommer = charger_fonction('icone_renommer','inc',true);
939
-	if ($icone_renommer){
940
-		list($icone,$fonction) = $icone_renommer($icone,"");
941
-		if (file_exists($icone))
942
-			return $icone;
943
-	}
944
-	return find_in_path ($icone, _NOM_IMG_PACK);
932
+    // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
933
+    if (preg_match(',[.](png|gif|jpg)$,',$icone) AND $f = find_in_theme("images/$icone"))
934
+        return $f;
935
+    // sinon passer par le module de renommage
936
+    if (is_null($icone_renommer))
937
+        $icone_renommer = charger_fonction('icone_renommer','inc',true);
938
+    if ($icone_renommer){
939
+        list($icone,$fonction) = $icone_renommer($icone,"");
940
+        if (file_exists($icone))
941
+            return $icone;
942
+    }
943
+    return find_in_path ($icone, _NOM_IMG_PACK);
945 944
 }
946 945
 
947 946
 //
@@ -953,109 +952,109 @@  discard block
 block discarded – undo
953 952
 
954 953
 // http://doc.spip.org/@find_in_path
955 954
 function find_in_path ($file, $dirname='', $include=false) {
956
-	static $dirs=array();
957
-	static $inc = array(); # cf http://trac.rezo.net/trac/spip/changeset/14743
958
-	static $c = '';
959
-
960
-	// on calcule le chemin si le dossier skel a change
961
-	if ($c != $GLOBALS['dossier_squelettes']){
962
-		// assurer le non plantage lors de la montee de version :
963
-		$c = $GLOBALS['dossier_squelettes'];
964
-		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
965
-	}
966
-
967
-	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
968
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])
969
-			return false;
970
-		if ($include AND !isset($inc[$dirname][$file])) {
971
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
972
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
973
-		}
974
-		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
975
-	}
976
-
977
-	$a = strrpos($file,'/');
978
-	if ($a !== false) {
979
-		$dirname .= substr($file, 0, ++$a);
980
-		$file = substr($file, $a);
981
-	}
982
-
983
-	foreach(creer_chemin() as $dir) {
984
-		if (!isset($dirs[$a = $dir . $dirname]))
985
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a) ;
986
-		if ($dirs[$a]) {
987
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
988
-				if ($include AND !isset($inc[$dirname][$file])) {
989
-					include_once _ROOT_CWD . $a;
990
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
991
-				}
992
-				if (!defined('_SAUVER_CHEMIN')){
993
-					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
994
-					if (is_null($GLOBALS['path_files'])) return $a;
995
-					define('_SAUVER_CHEMIN', true);
996
-				}
997
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
998
-			}
999
-		}
1000
-	}
1001
-
1002
-	if ($include){
1003
-		spip_log("include_spip $dirname$file non trouve");
1004
-		if ($include==='required'){
1005
-			echo '<pre>',
1006
-			"<strong>Erreur Fatale</strong><br />";
1007
-			if (function_exists('debug_print_backtrace'))
1008
-				echo debug_print_backtrace();
1009
-			echo '</pre>';
1010
-			die("Erreur interne: ne peut inclure $dirname$file");
1011
-		}
1012
-	}
1013
-
1014
-	if (!defined('_SAUVER_CHEMIN')){
1015
-		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1016
-		if (is_null($GLOBALS['path_files'])) return false;
1017
-		define('_SAUVER_CHEMIN', true);
1018
-	}
1019
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
955
+    static $dirs=array();
956
+    static $inc = array(); # cf http://trac.rezo.net/trac/spip/changeset/14743
957
+    static $c = '';
958
+
959
+    // on calcule le chemin si le dossier skel a change
960
+    if ($c != $GLOBALS['dossier_squelettes']){
961
+        // assurer le non plantage lors de la montee de version :
962
+        $c = $GLOBALS['dossier_squelettes'];
963
+        creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
964
+    }
965
+
966
+    if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
967
+        if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])
968
+            return false;
969
+        if ($include AND !isset($inc[$dirname][$file])) {
970
+            include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
971
+            $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
972
+        }
973
+        return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
974
+    }
975
+
976
+    $a = strrpos($file,'/');
977
+    if ($a !== false) {
978
+        $dirname .= substr($file, 0, ++$a);
979
+        $file = substr($file, $a);
980
+    }
981
+
982
+    foreach(creer_chemin() as $dir) {
983
+        if (!isset($dirs[$a = $dir . $dirname]))
984
+            $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a) ;
985
+        if ($dirs[$a]) {
986
+            if (file_exists(_ROOT_CWD . ($a .= $file))) {
987
+                if ($include AND !isset($inc[$dirname][$file])) {
988
+                    include_once _ROOT_CWD . $a;
989
+                    $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
990
+                }
991
+                if (!defined('_SAUVER_CHEMIN')){
992
+                    // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
993
+                    if (is_null($GLOBALS['path_files'])) return $a;
994
+                    define('_SAUVER_CHEMIN', true);
995
+                }
996
+                return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
997
+            }
998
+        }
999
+    }
1000
+
1001
+    if ($include){
1002
+        spip_log("include_spip $dirname$file non trouve");
1003
+        if ($include==='required'){
1004
+            echo '<pre>',
1005
+            "<strong>Erreur Fatale</strong><br />";
1006
+            if (function_exists('debug_print_backtrace'))
1007
+                echo debug_print_backtrace();
1008
+            echo '</pre>';
1009
+            die("Erreur interne: ne peut inclure $dirname$file");
1010
+        }
1011
+    }
1012
+
1013
+    if (!defined('_SAUVER_CHEMIN')){
1014
+        // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1015
+        if (is_null($GLOBALS['path_files'])) return false;
1016
+        define('_SAUVER_CHEMIN', true);
1017
+    }
1018
+    return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1020 1019
 }
1021 1020
 
1022 1021
 function clear_path_cache(){
1023
-	$GLOBALS['path_files'] = array();
1024
-	spip_unlink(_CACHE_CHEMIN);
1022
+    $GLOBALS['path_files'] = array();
1023
+    spip_unlink(_CACHE_CHEMIN);
1025 1024
 }
1026 1025
 function load_path_cache(){
1027
-	// charger le path des plugins
1028
-	if (@is_readable(_CACHE_PLUGINS_PATH)){
1029
-		include_once(_CACHE_PLUGINS_PATH);
1030
-	}
1031
-	$GLOBALS['path_files'] = array();
1032
-	// si le visiteur est admin,
1033
-	// on ne recharge pas le cache pour forcer sa mise a jour
1034
-	if (
1035
-		// la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1036
-		//AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1037
-		// utiliser le cookie est un pis aller qui marche 'en general'
1038
-		// on blinde par un second test au moment de la lecture de la session
1039
-		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1040
-		// et en ignorant ce cache en cas de recalcul explicite
1041
-		!_request('var_mode')
1042
-		){
1043
-		// on essaye de lire directement sans verrou pour aller plus vite
1044
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)){
1045
-			// mais si semble corrompu on relit avec un verrou
1046
-			if (!$GLOBALS['path_files']=unserialize($contenu)){
1047
-				lire_fichier(_CACHE_CHEMIN,$contenu);
1048
-				if (!$GLOBALS['path_files']=unserialize($contenu))
1049
-					$GLOBALS['path_files'] = array();
1050
-			}
1051
-		}
1052
-	}
1026
+    // charger le path des plugins
1027
+    if (@is_readable(_CACHE_PLUGINS_PATH)){
1028
+        include_once(_CACHE_PLUGINS_PATH);
1029
+    }
1030
+    $GLOBALS['path_files'] = array();
1031
+    // si le visiteur est admin,
1032
+    // on ne recharge pas le cache pour forcer sa mise a jour
1033
+    if (
1034
+        // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1035
+        //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1036
+        // utiliser le cookie est un pis aller qui marche 'en general'
1037
+        // on blinde par un second test au moment de la lecture de la session
1038
+        // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1039
+        // et en ignorant ce cache en cas de recalcul explicite
1040
+        !_request('var_mode')
1041
+        ){
1042
+        // on essaye de lire directement sans verrou pour aller plus vite
1043
+        if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)){
1044
+            // mais si semble corrompu on relit avec un verrou
1045
+            if (!$GLOBALS['path_files']=unserialize($contenu)){
1046
+                lire_fichier(_CACHE_CHEMIN,$contenu);
1047
+                if (!$GLOBALS['path_files']=unserialize($contenu))
1048
+                    $GLOBALS['path_files'] = array();
1049
+            }
1050
+        }
1051
+    }
1053 1052
 }
1054 1053
 
1055 1054
 function save_path_cache(){
1056
-	if (defined('_SAUVER_CHEMIN')
1057
-		AND _SAUVER_CHEMIN)
1058
-		ecrire_fichier(_CACHE_CHEMIN,serialize($GLOBALS['path_files']));
1055
+    if (defined('_SAUVER_CHEMIN')
1056
+        AND _SAUVER_CHEMIN)
1057
+        ecrire_fichier(_CACHE_CHEMIN,serialize($GLOBALS['path_files']));
1059 1058
 }
1060 1059
 
1061 1060
 
@@ -1071,25 +1070,25 @@  discard block
 block discarded – undo
1071 1070
  */
1072 1071
 // http://doc.spip.org/@find_all_in_path
1073 1072
 function find_all_in_path($dir,$pattern, $recurs=false){
1074
-	$liste_fichiers=array();
1075
-	$maxfiles = 10000;
1076
-
1077
-	// Parcourir le chemin
1078
-	foreach (creer_chemin() as $d) {
1079
-		$f = $d.$dir;
1080
-		if (@is_dir($f)){
1081
-			$liste = preg_files($f,$pattern,$maxfiles-count($liste_fichiers),$recurs===true?array():$recurs);
1082
-			foreach($liste as $chemin){
1083
-				$nom = basename($chemin);
1084
-				// ne prendre que les fichiers pas deja trouves
1085
-				// car find_in_path prend le premier qu'il trouve,
1086
-				// les autres sont donc masques
1087
-				if (!isset($liste_fichiers[$nom]))
1088
-					$liste_fichiers[$nom] = $chemin;
1089
-			}
1090
-		}
1091
-	}
1092
-	return $liste_fichiers;
1073
+    $liste_fichiers=array();
1074
+    $maxfiles = 10000;
1075
+
1076
+    // Parcourir le chemin
1077
+    foreach (creer_chemin() as $d) {
1078
+        $f = $d.$dir;
1079
+        if (@is_dir($f)){
1080
+            $liste = preg_files($f,$pattern,$maxfiles-count($liste_fichiers),$recurs===true?array():$recurs);
1081
+            foreach($liste as $chemin){
1082
+                $nom = basename($chemin);
1083
+                // ne prendre que les fichiers pas deja trouves
1084
+                // car find_in_path prend le premier qu'il trouve,
1085
+                // les autres sont donc masques
1086
+                if (!isset($liste_fichiers[$nom]))
1087
+                    $liste_fichiers[$nom] = $chemin;
1088
+            }
1089
+        }
1090
+    }
1091
+    return $liste_fichiers;
1093 1092
 }
1094 1093
 
1095 1094
 // predicat sur les scripts de ecrire qui n'authentifient pas par cookie
@@ -1097,9 +1096,9 @@  discard block
 block discarded – undo
1097 1096
 // http://doc.spip.org/@autoriser_sans_cookie
1098 1097
 function autoriser_sans_cookie($nom)
1099 1098
 {
1100
-  static $autsanscookie = array('install', 'base_repair');
1101
-  $nom = preg_replace('/.php[3]?$/', '', basename($nom));
1102
-  return in_array($nom, $autsanscookie);
1099
+    static $autsanscookie = array('install', 'base_repair');
1100
+    $nom = preg_replace('/.php[3]?$/', '', basename($nom));
1101
+    return in_array($nom, $autsanscookie);
1103 1102
 }
1104 1103
 
1105 1104
 /**
@@ -1128,112 +1127,112 @@  discard block
 block discarded – undo
1128 1127
  */
1129 1128
 function generer_url_entite($id='', $entite='', $args='', $ancre='', $public=NULL, $type=NULL)
1130 1129
 {
1131
-	if ($public === NULL) $public = !test_espace_prive();
1132
-	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1133
-
1134
-	if (!$public) {
1135
-		if (!$entite) return '';
1136
-		if (!function_exists('generer_url_ecrire_objet'))
1137
-			include_spip('inc/urls');
1138
-		$res = generer_url_ecrire_objet($entite,$id, $args, $ancre, false);
1139
-	} else {
1140
-		if ($type === NULL) {
1141
-			$type = ($GLOBALS['type_urls'] === 'page'
1142
-				AND $GLOBALS['meta']['type_urls'])
1143
-			?  $GLOBALS['meta']['type_urls']
1144
-			:  $GLOBALS['type_urls']; // pour SPIP <2
1145
-		}
1146
-
1147
-		$f = charger_fonction($type, 'urls', true);
1148
-		// se rabattre sur les urls page si les urls perso non dispo
1149
-		if (!$f) $f = charger_fonction('page', 'urls', true);
1150
-
1151
-		// si $entite='', on veut la fonction de passage URL ==> id
1152
-		// sinon on veut effectuer le passage id ==> URL
1153
-		if (!$entite) return $f;
1154
-
1155
-		// mais d'abord il faut tester le cas des urls sur une
1156
-		// base distante
1157
-		if (is_string($public)
1158
-		AND $g = charger_fonction('connect', 'urls', true))
1159
-			$f = $g;
1160
-
1161
-		$res = $f(intval($id), $entite, $args, $ancre, $public);
1162
-
1163
-	}
1164
-	if ($res) return $res;
1165
-	// Sinon c'est un raccourci ou compat SPIP < 2
1166
-	if (!function_exists($f = 'generer_url_' . $entite)) {
1167
-		if (!function_exists($f .= '_dist')) $f = '';
1168
-	}
1169
-	if ($f) {
1170
-		$url = $f($id, $args, $ancre);
1171
-		if (strlen($args))
1172
-			$url .= strstr($url, '?')
1173
-				? '&amp;'.$args
1174
-				: '?'.$args;
1175
-		return $url;
1176
-	}
1177
-	// On a ete gentil mais la ....
1178
-	spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public");
1179
-	return '';
1130
+    if ($public === NULL) $public = !test_espace_prive();
1131
+    $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1132
+
1133
+    if (!$public) {
1134
+        if (!$entite) return '';
1135
+        if (!function_exists('generer_url_ecrire_objet'))
1136
+            include_spip('inc/urls');
1137
+        $res = generer_url_ecrire_objet($entite,$id, $args, $ancre, false);
1138
+    } else {
1139
+        if ($type === NULL) {
1140
+            $type = ($GLOBALS['type_urls'] === 'page'
1141
+                AND $GLOBALS['meta']['type_urls'])
1142
+            ?  $GLOBALS['meta']['type_urls']
1143
+            :  $GLOBALS['type_urls']; // pour SPIP <2
1144
+        }
1145
+
1146
+        $f = charger_fonction($type, 'urls', true);
1147
+        // se rabattre sur les urls page si les urls perso non dispo
1148
+        if (!$f) $f = charger_fonction('page', 'urls', true);
1149
+
1150
+        // si $entite='', on veut la fonction de passage URL ==> id
1151
+        // sinon on veut effectuer le passage id ==> URL
1152
+        if (!$entite) return $f;
1153
+
1154
+        // mais d'abord il faut tester le cas des urls sur une
1155
+        // base distante
1156
+        if (is_string($public)
1157
+        AND $g = charger_fonction('connect', 'urls', true))
1158
+            $f = $g;
1159
+
1160
+        $res = $f(intval($id), $entite, $args, $ancre, $public);
1161
+
1162
+    }
1163
+    if ($res) return $res;
1164
+    // Sinon c'est un raccourci ou compat SPIP < 2
1165
+    if (!function_exists($f = 'generer_url_' . $entite)) {
1166
+        if (!function_exists($f .= '_dist')) $f = '';
1167
+    }
1168
+    if ($f) {
1169
+        $url = $f($id, $args, $ancre);
1170
+        if (strlen($args))
1171
+            $url .= strstr($url, '?')
1172
+                ? '&amp;'.$args
1173
+                : '?'.$args;
1174
+        return $url;
1175
+    }
1176
+    // On a ete gentil mais la ....
1177
+    spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public");
1178
+    return '';
1180 1179
 }
1181 1180
 
1182 1181
 function generer_url_ecrire_entite_edit($id, $entite, $args='', $ancre=''){
1183
-	$exec = objet_info($entite,'url_edit');
1184
-	$url = generer_url_ecrire($exec,$args);
1185
-	if (intval($id))
1186
-		$url = parametre_url($url,id_table_objet($entite),$id);
1187
-	else
1188
-		$url = parametre_url($url,'new','oui');
1189
-	if ($ancre)
1190
-		$url = ancre_url($url,$ancre);
1191
-	return $url;
1182
+    $exec = objet_info($entite,'url_edit');
1183
+    $url = generer_url_ecrire($exec,$args);
1184
+    if (intval($id))
1185
+        $url = parametre_url($url,id_table_objet($entite),$id);
1186
+    else
1187
+        $url = parametre_url($url,'new','oui');
1188
+    if ($ancre)
1189
+        $url = ancre_url($url,$ancre);
1190
+    return $url;
1192 1191
 }
1193 1192
 
1194 1193
 // http://doc.spip.org/@urls_connect_dist
1195 1194
 function urls_connect_dist($i, &$entite, $args='', $ancre='', $public=null) {
1196
-	include_spip('base/connect_sql');
1197
-	$id_type = id_table_objet($entite,$public);
1198
-	return _DIR_RACINE . get_spip_script('./')
1199
-	  . "?"._SPIP_PAGE."=$entite&$id_type=$i&connect=$public"
1200
-	  . (!$args ? '' : "&$args")
1201
-	  . (!$ancre ? '' : "#$ancre");
1195
+    include_spip('base/connect_sql');
1196
+    $id_type = id_table_objet($entite,$public);
1197
+    return _DIR_RACINE . get_spip_script('./')
1198
+        . "?"._SPIP_PAGE."=$entite&$id_type=$i&connect=$public"
1199
+        . (!$args ? '' : "&$args")
1200
+        . (!$ancre ? '' : "#$ancre");
1202 1201
 }
1203 1202
 
1204 1203
 
1205 1204
 // Transformer les caracteres utf8 d'une URL (farsi par ex) selon la RFC 1738
1206 1205
 function urlencode_1738($url) {
1207
-	if (preg_match(',[^\x00-\x7E],sS', $url)){
1208
-		$uri = '';
1209
-		for ($i=0; $i < strlen($url); $i++) {
1210
-			if (ord($a = $url[$i]) > 127)
1211
-				$a = rawurlencode($a);
1212
-			$uri .= $a;
1213
-		}
1214
-		$url = $uri;
1215
-	}
1216
-	return quote_amp($url);
1206
+    if (preg_match(',[^\x00-\x7E],sS', $url)){
1207
+        $uri = '';
1208
+        for ($i=0; $i < strlen($url); $i++) {
1209
+            if (ord($a = $url[$i]) > 127)
1210
+                $a = rawurlencode($a);
1211
+            $uri .= $a;
1212
+        }
1213
+        $url = $uri;
1214
+    }
1215
+    return quote_amp($url);
1217 1216
 }
1218 1217
 
1219 1218
 // http://doc.spip.org/@generer_url_entite_absolue
1220 1219
 function generer_url_entite_absolue($id='', $entite='', $args='', $ancre='', $connect=NULL)
1221 1220
 {
1222
-	if (!$connect) $connect = true;
1223
-	$h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1224
-	if (!preg_match(',^\w+:,', $h)) {
1225
-		include_spip('inc/filtres_mini');
1226
-		$h = url_absolue($h);
1227
-	}
1228
-	return  $h;
1221
+    if (!$connect) $connect = true;
1222
+    $h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1223
+    if (!preg_match(',^\w+:,', $h)) {
1224
+        include_spip('inc/filtres_mini');
1225
+        $h = url_absolue($h);
1226
+    }
1227
+    return  $h;
1229 1228
 }
1230 1229
 
1231 1230
 // Sur certains serveurs, la valeur 'Off' tient lieu de false dans certaines
1232 1231
 // variables d'environnement comme $_SERVER[HTTPS] ou ini_get(register_globals)
1233 1232
 // http://doc.spip.org/@test_valeur_serveur
1234 1233
 function test_valeur_serveur($truc) {
1235
-	if (!$truc) return false;
1236
-	return (strtolower($truc) !== 'off');
1234
+    if (!$truc) return false;
1235
+    return (strtolower($truc) !== 'off');
1237 1236
 }
1238 1237
 
1239 1238
 //
@@ -1258,51 +1257,51 @@  discard block
 block discarded – undo
1258 1257
  */
1259 1258
 function url_de_base($profondeur=null) {
1260 1259
 
1261
-	static $url = array();
1262
-	if (is_array($profondeur)) return $url = $profondeur;
1263
-	if ($profondeur===false) return $url;
1264
-
1265
-	if (is_null($profondeur)) $profondeur = $GLOBALS['profondeur_url'];
1266
-
1267
-	if (isset($url[$profondeur]))
1268
-		return $url[$profondeur];
1269
-
1270
-	$http = (
1271
-		(isset($_SERVER["SCRIPT_URI"]) AND
1272
-			substr($_SERVER["SCRIPT_URI"],0,5) == 'https')
1273
-		OR (isset($_SERVER['HTTPS']) AND
1274
-		    test_valeur_serveur($_SERVER['HTTPS']))
1275
-	) ? 'https' : 'http';
1276
-	// note : HTTP_HOST contient le :port si necessaire
1277
-	$host = $_SERVER['HTTP_HOST'];
1278
-	// si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
1279
-	if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
1280
-		$host = $GLOBALS['meta']['adresse_site'];
1281
-		if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
1282
-			$http = $scheme;
1283
-			$host = str_replace("{$scheme}://", '', $host);
1284
-		}
1285
-	}
1286
-	if (isset($_SERVER['SERVER_PORT'])
1287
-		AND $port=$_SERVER['SERVER_PORT']
1288
-		AND strpos($host,":")==false){
1289
-		if ($http=="http" AND $port!=80) $host.=":$port";
1290
-		if ($http=="https" AND $port!=443) $host.=":$port";
1291
-	}
1292
-	if (!$GLOBALS['REQUEST_URI']){
1293
-		if (isset($_SERVER['REQUEST_URI'])) {
1294
-			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1295
-		} else {
1296
-			$GLOBALS['REQUEST_URI'] = $_SERVER['PHP_SELF'];
1297
-			if ($_SERVER['QUERY_STRING']
1298
-			AND !strpos($_SERVER['REQUEST_URI'], '?'))
1299
-				$GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
1300
-		}
1301
-	}
1302
-
1303
-	$url[$profondeur] = url_de_($http,$host,$GLOBALS['REQUEST_URI'],$profondeur);
1304
-
1305
-	return $url[$profondeur];
1260
+    static $url = array();
1261
+    if (is_array($profondeur)) return $url = $profondeur;
1262
+    if ($profondeur===false) return $url;
1263
+
1264
+    if (is_null($profondeur)) $profondeur = $GLOBALS['profondeur_url'];
1265
+
1266
+    if (isset($url[$profondeur]))
1267
+        return $url[$profondeur];
1268
+
1269
+    $http = (
1270
+        (isset($_SERVER["SCRIPT_URI"]) AND
1271
+            substr($_SERVER["SCRIPT_URI"],0,5) == 'https')
1272
+        OR (isset($_SERVER['HTTPS']) AND
1273
+            test_valeur_serveur($_SERVER['HTTPS']))
1274
+    ) ? 'https' : 'http';
1275
+    // note : HTTP_HOST contient le :port si necessaire
1276
+    $host = $_SERVER['HTTP_HOST'];
1277
+    // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
1278
+    if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
1279
+        $host = $GLOBALS['meta']['adresse_site'];
1280
+        if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
1281
+            $http = $scheme;
1282
+            $host = str_replace("{$scheme}://", '', $host);
1283
+        }
1284
+    }
1285
+    if (isset($_SERVER['SERVER_PORT'])
1286
+        AND $port=$_SERVER['SERVER_PORT']
1287
+        AND strpos($host,":")==false){
1288
+        if ($http=="http" AND $port!=80) $host.=":$port";
1289
+        if ($http=="https" AND $port!=443) $host.=":$port";
1290
+    }
1291
+    if (!$GLOBALS['REQUEST_URI']){
1292
+        if (isset($_SERVER['REQUEST_URI'])) {
1293
+            $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1294
+        } else {
1295
+            $GLOBALS['REQUEST_URI'] = $_SERVER['PHP_SELF'];
1296
+            if ($_SERVER['QUERY_STRING']
1297
+            AND !strpos($_SERVER['REQUEST_URI'], '?'))
1298
+                $GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
1299
+        }
1300
+    }
1301
+
1302
+    $url[$profondeur] = url_de_($http,$host,$GLOBALS['REQUEST_URI'],$profondeur);
1303
+
1304
+    return $url[$profondeur];
1306 1305
 }
1307 1306
 /**
1308 1307
  * fonction testable de construction d'une url appelee par url_de_base()
@@ -1313,25 +1312,25 @@  discard block
 block discarded – undo
1313 1312
  * @return string
1314 1313
  */
1315 1314
 function url_de_($http,$host,$request,$prof=0){
1316
-	$prof = max($prof,0);
1315
+    $prof = max($prof,0);
1317 1316
 
1318
-	$myself = ltrim($request,'/');
1319
-	# supprimer la chaine de GET
1320
-	list($myself) = explode('?', $myself);
1321
-	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
1322
-	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
1323
-	if (strpos($myself,'://') !== false) {
1324
-		$myself = explode('://',$myself);
1325
-		array_shift($myself);
1326
-		$myself = implode('://',$myself);
1327
-		$myself = explode('/',$myself);
1328
-		array_shift($myself);
1329
-		$myself = implode('/',$myself);
1330
-	}
1331
-	$url = join('/', array_slice(explode('/', $myself), 0, -1-$prof)).'/';
1317
+    $myself = ltrim($request,'/');
1318
+    # supprimer la chaine de GET
1319
+    list($myself) = explode('?', $myself);
1320
+    // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
1321
+    // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
1322
+    if (strpos($myself,'://') !== false) {
1323
+        $myself = explode('://',$myself);
1324
+        array_shift($myself);
1325
+        $myself = implode('://',$myself);
1326
+        $myself = explode('/',$myself);
1327
+        array_shift($myself);
1328
+        $myself = implode('/',$myself);
1329
+    }
1330
+    $url = join('/', array_slice(explode('/', $myself), 0, -1-$prof)).'/';
1332 1331
 
1333
-	$url = $http.'://'.rtrim($host,'/').'/'.ltrim($url,'/');
1334
-	return $url;
1332
+    $url = $http.'://'.rtrim($host,'/').'/'.ltrim($url,'/');
1333
+    return $url;
1335 1334
 }
1336 1335
 
1337 1336
 
@@ -1345,25 +1344,25 @@  discard block
 block discarded – undo
1345 1344
 
1346 1345
 // http://doc.spip.org/@generer_url_ecrire
1347 1346
 function generer_url_ecrire($script='', $args="", $no_entities=false, $rel=false) {
1348
-	if (!$rel)
1349
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
1350
-	else if (!is_string($rel))
1351
-		$rel = _DIR_RESTREINT ? _DIR_RESTREINT :
1352
-			('./'  . _SPIP_ECRIRE_SCRIPT);
1347
+    if (!$rel)
1348
+        $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
1349
+    else if (!is_string($rel))
1350
+        $rel = _DIR_RESTREINT ? _DIR_RESTREINT :
1351
+            ('./'  . _SPIP_ECRIRE_SCRIPT);
1353 1352
 
1354
-	@list($script, $ancre) = explode('#', $script);
1355
-	if ($script AND ($script<>'accueil' OR $rel))
1356
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
1357
-	elseif ($args)
1358
-		$args ="?$args";
1359
-	if ($ancre) $args .= "#$ancre";
1360
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
1353
+    @list($script, $ancre) = explode('#', $script);
1354
+    if ($script AND ($script<>'accueil' OR $rel))
1355
+        $args = "?exec=$script" . (!$args ? '' : "&$args");
1356
+    elseif ($args)
1357
+        $args ="?$args";
1358
+    if ($ancre) $args .= "#$ancre";
1359
+    return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
1361 1360
 }
1362 1361
 
1363 1362
 // http://doc.spip.org/@generer_url_retour
1364 1363
 function generer_url_retour($script, $args="")
1365 1364
 {
1366
-	return rawurlencode(generer_url_ecrire($script, $args, true, true));
1365
+    return rawurlencode(generer_url_ecrire($script, $args, true, true));
1367 1366
 }
1368 1367
 
1369 1368
 //
@@ -1374,42 +1373,42 @@  discard block
 block discarded – undo
1374 1373
 // dans le cas de '', un $default = './' peut servir (comme dans urls/page.php)
1375 1374
 // http://doc.spip.org/@get_spip_script
1376 1375
 function get_spip_script($default='') {
1377
-	# cas define('_SPIP_SCRIPT', '');
1378
-	if (_SPIP_SCRIPT)
1379
-		return _SPIP_SCRIPT;
1380
-	else
1381
-		return $default;
1376
+    # cas define('_SPIP_SCRIPT', '');
1377
+    if (_SPIP_SCRIPT)
1378
+        return _SPIP_SCRIPT;
1379
+    else
1380
+        return $default;
1382 1381
 }
1383 1382
 
1384 1383
 // http://doc.spip.org/@generer_url_public
1385 1384
 function generer_url_public($script='', $args="", $no_entities=false, $rel=true, $action='') {
1386
-	// si le script est une action (spip_pass, spip_inscription),
1387
-	// standardiser vers la nouvelle API
1385
+    // si le script est une action (spip_pass, spip_inscription),
1386
+    // standardiser vers la nouvelle API
1388 1387
 
1389
-	if (!$action) $action = get_spip_script();
1390
-	if ($script)
1391
-		$action = parametre_url($action, _SPIP_PAGE, $script, '&');
1388
+    if (!$action) $action = get_spip_script();
1389
+    if ($script)
1390
+        $action = parametre_url($action, _SPIP_PAGE, $script, '&');
1392 1391
 
1393
-	if ($args) {
1394
-		if (is_array($args)) {
1395
-			$r = '';
1396
-			foreach($args as $k => $v) $r .= '&' . $k . '=' . $v;
1397
-			$args = substr($r,1);
1398
-		}
1399
-		$action .=
1400
-			(strpos($action, '?') !== false ? '&' : '?') . $args;
1401
-	}
1402
-	if (!$no_entities)
1403
-		$action = quote_amp($action);
1392
+    if ($args) {
1393
+        if (is_array($args)) {
1394
+            $r = '';
1395
+            foreach($args as $k => $v) $r .= '&' . $k . '=' . $v;
1396
+            $args = substr($r,1);
1397
+        }
1398
+        $action .=
1399
+            (strpos($action, '?') !== false ? '&' : '?') . $args;
1400
+    }
1401
+    if (!$no_entities)
1402
+        $action = quote_amp($action);
1404 1403
 
1405
-	// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
1406
-	return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(),'/') . preg_replace(",^/[.]/,","/","/$action"));
1404
+    // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
1405
+    return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(),'/') . preg_replace(",^/[.]/,","/","/$action"));
1407 1406
 }
1408 1407
 
1409 1408
 // http://doc.spip.org/@generer_url_prive
1410 1409
 function generer_url_prive($script, $args="", $no_entities=false) {
1411 1410
 
1412
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS .  'prive.php');
1411
+    return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS .  'prive.php');
1413 1412
 }
1414 1413
 
1415 1414
 // Pour les formulaires en methode POST,
@@ -1419,21 +1418,21 @@  discard block
 block discarded – undo
1419 1418
 
1420 1419
 // http://doc.spip.org/@generer_form_ecrire
1421 1420
 function generer_form_ecrire($script, $corps, $atts='', $submit='') {
1422
-	global $spip_lang_right;
1421
+    global $spip_lang_right;
1423 1422
 
1424
-	$script1 = explode('&', $script);
1425
-	$script1 = reset($script1);
1423
+    $script1 = explode('&', $script);
1424
+    $script1 = reset($script1);
1426 1425
 
1427
-	return "<form action='"
1428
-	. ($script ? generer_url_ecrire($script) : '')
1429
-	. "' "
1430
-	. ($atts ? $atts : " method='post'")
1431
-	.  "><div>\n"
1432
-	. "<input type='hidden' name='exec' value='$script1' />"
1433
-	. $corps
1434
-	. (!$submit ? '' :
1435
-	     ("<div style='text-align: $spip_lang_right'><input class='fondo' type='submit' value=\"".entites_html($submit)."\" /></div>"))
1436
-	. "</div></form>\n";
1426
+    return "<form action='"
1427
+    . ($script ? generer_url_ecrire($script) : '')
1428
+    . "' "
1429
+    . ($atts ? $atts : " method='post'")
1430
+    .  "><div>\n"
1431
+    . "<input type='hidden' name='exec' value='$script1' />"
1432
+    . $corps
1433
+    . (!$submit ? '' :
1434
+         ("<div style='text-align: $spip_lang_right'><input class='fondo' type='submit' value=\"".entites_html($submit)."\" /></div>"))
1435
+    . "</div></form>\n";
1437 1436
 }
1438 1437
 
1439 1438
 /**
@@ -1451,37 +1450,37 @@  discard block
 block discarded – undo
1451 1450
  * @return string
1452 1451
  */
1453 1452
 function generer_form_action($script, $corps, $atts='', $public=false) {
1454
-	// si l'on est dans l'espace prive, on garde dans l'url
1455
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
1456
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
1457
-	$h = (_DIR_RACINE AND !$public)
1458
-	? generer_url_ecrire(_request('exec'))
1459
-	: generer_url_public();
1460
-
1461
-	return "\n<form action='" .
1462
-	  $h .
1463
-	  "'" .
1464
-	  $atts .
1465
-	  ">\n" .
1466
-	  "<div>" .
1467
-  	  "\n<input type='hidden' name='action' value='$script' />" .
1468
-	  $corps .
1469
-	  "</div></form>";
1453
+    // si l'on est dans l'espace prive, on garde dans l'url
1454
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
1455
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
1456
+    $h = (_DIR_RACINE AND !$public)
1457
+    ? generer_url_ecrire(_request('exec'))
1458
+    : generer_url_public();
1459
+
1460
+    return "\n<form action='" .
1461
+        $h .
1462
+        "'" .
1463
+        $atts .
1464
+        ">\n" .
1465
+        "<div>" .
1466
+        "\n<input type='hidden' name='action' value='$script' />" .
1467
+        $corps .
1468
+        "</div></form>";
1470 1469
 }
1471 1470
 
1472 1471
 // http://doc.spip.org/@generer_url_action
1473 1472
 function generer_url_action($script, $args="", $no_entities=false , $public = false) {
1474
-	// si l'on est dans l'espace prive, on garde dans l'url
1475
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
1476
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
1477
-	$url = (_DIR_RACINE  AND !$public)
1478
-	  ? generer_url_ecrire(_request('exec'))
1479
-	  :  generer_url_public('','',false,false);
1480
-	$url = parametre_url($url,'action',$script);
1481
-	if ($args) $url .= quote_amp('&'.$args);
1473
+    // si l'on est dans l'espace prive, on garde dans l'url
1474
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
1475
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
1476
+    $url = (_DIR_RACINE  AND !$public)
1477
+      ? generer_url_ecrire(_request('exec'))
1478
+      :  generer_url_public('','',false,false);
1479
+    $url = parametre_url($url,'action',$script);
1480
+    if ($args) $url .= quote_amp('&'.$args);
1482 1481
 
1483
-	if ($no_entities) $url = str_replace('&amp;','&',$url);
1484
-	return $url;
1482
+    if ($no_entities) $url = str_replace('&amp;','&',$url);
1483
+    return $url;
1485 1484
 }
1486 1485
 
1487 1486
 
@@ -1494,8 +1493,8 @@  discard block
 block discarded – undo
1494 1493
  * @param string $ta
1495 1494
  */
1496 1495
 function spip_initialisation($pi=NULL, $pa=NULL, $ti=NULL, $ta=NULL) {
1497
-	spip_initialisation_core($pi,$pa,$ti,$ta);
1498
-	spip_initialisation_suite();
1496
+    spip_initialisation_core($pi,$pa,$ti,$ta);
1497
+    spip_initialisation_suite();
1499 1498
 }
1500 1499
 
1501 1500
 /**
@@ -1513,235 +1512,235 @@  discard block
 block discarded – undo
1513 1512
  * @param string $ta
1514 1513
  */
1515 1514
 function spip_initialisation_core($pi=NULL, $pa=NULL, $ti=NULL, $ta=NULL) {
1516
-	static $too_late = 0;
1517
-	if ($too_late++) return;
1515
+    static $too_late = 0;
1516
+    if ($too_late++) return;
1518 1517
 	
1519
-	// Declaration des repertoires
1518
+    // Declaration des repertoires
1520 1519
 
1521
-	// le nom du repertoire plugins/ activables/desactivables
1522
-	if (!defined('_DIR_PLUGINS')) define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
1520
+    // le nom du repertoire plugins/ activables/desactivables
1521
+    if (!defined('_DIR_PLUGINS')) define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
1523 1522
 
1524
-	// le nom du repertoire des extensions/ permanentes du core, toujours actives
1525
-	if (!defined('_DIR_PLUGINS_DIST')) define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
1523
+    // le nom du repertoire des extensions/ permanentes du core, toujours actives
1524
+    if (!defined('_DIR_PLUGINS_DIST')) define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
1526 1525
 
1527
-	// le nom du repertoire des librairies
1528
-	if (!defined('_DIR_LIB')) define('_DIR_LIB', _DIR_RACINE . "lib/");
1526
+    // le nom du repertoire des librairies
1527
+    if (!defined('_DIR_LIB')) define('_DIR_LIB', _DIR_RACINE . "lib/");
1529 1528
 	
1530
-	if (!defined('_DIR_IMG')) define('_DIR_IMG', $pa);
1531
-	if (!defined('_DIR_LOGOS')) define('_DIR_LOGOS', $pa);
1532
-	if (!defined('_DIR_IMG_ICONES')) define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
1533
-
1534
-	if (!defined('_DIR_DUMP')) define('_DIR_DUMP', $ti . "dump/");
1535
-	if (!defined('_DIR_SESSIONS')) define('_DIR_SESSIONS', $ti . "sessions/");
1536
-	if (!defined('_DIR_TRANSFERT')) define('_DIR_TRANSFERT', $ti . "upload/");
1537
-	if (!defined('_DIR_CACHE')) define('_DIR_CACHE', $ti . "cache/");
1538
-	if (!defined('_DIR_CACHE_XML')) define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
1539
-	if (!defined('_DIR_SKELS')) define('_DIR_SKELS',  _DIR_CACHE . "skel/");
1540
-	if (!defined('_DIR_AIDE')) define('_DIR_AIDE',  _DIR_CACHE . "aide/");
1541
-	if (!defined('_DIR_TMP')) define('_DIR_TMP', $ti);
1542
-
1543
-	if (!defined('_DIR_VAR')) define('_DIR_VAR', $ta);
1544
-
1545
-	if (!defined('_DIR_ETC')) define('_DIR_ETC', $pi);
1546
-	if (!defined('_DIR_CONNECT')) define('_DIR_CONNECT', $pi);
1547
-	if (!defined('_DIR_CHMOD')) define('_DIR_CHMOD', $pi);
1548
-
1549
-	if (!isset($GLOBALS['test_dirs']))
1550
-	  // Pas $pi car il est bon de le mettre hors ecriture apres intstall
1551
-	  // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
1552
-		$GLOBALS['test_dirs'] =  array($pa, $ti, $ta);
1553
-
1554
-	// Declaration des fichiers
1555
-
1556
-	if (!defined('_CACHE_PLUGINS_PATH')) define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
1557
-	if (!defined('_CACHE_PLUGINS_OPT')) define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
1558
-	if (!defined('_CACHE_PLUGINS_FCT')) define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
1559
-	if (!defined('_CACHE_PIPELINES')) define('_CACHE_PIPELINES',  _DIR_CACHE."charger_pipelines.php");
1560
-	if (!defined('_CACHE_CHEMIN')) define('_CACHE_CHEMIN',  _DIR_CACHE."chemin.txt");
1561
-
1562
-	# attention .php obligatoire pour ecrire_fichier_securise
1563
-	if (!defined('_FILE_META')) define('_FILE_META', $ti . 'meta_cache.php');
1564
-	if (!defined('_DIR_LOG')) define('_DIR_LOG', _DIR_TMP . 'log/');
1565
-	if (!defined('_FILE_LOG')) define('_FILE_LOG', 'spip');
1566
-	if (!defined('_FILE_LOG_SUFFIX')) define('_FILE_LOG_SUFFIX', '.log');
1567
-
1568
-	// Le fichier de connexion a la base de donnees
1569
-	// tient compte des anciennes versions (inc_connect...)
1570
-	if (!defined('_FILE_CONNECT_INS')) define('_FILE_CONNECT_INS', 'connect');
1571
-	if (!defined('_FILE_CONNECT')) define('_FILE_CONNECT',
1572
-		(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
1573
-	:	(@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
1574
-	:	false)));
1575
-
1576
-	// Le fichier de reglages des droits
1577
-	if (!defined('_FILE_CHMOD_INS')) define('_FILE_CHMOD_INS', 'chmod');
1578
-	if (!defined('_FILE_CHMOD')) define('_FILE_CHMOD',
1579
-		(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
1580
-	:	false));
1581
-
1582
-	if (!defined('_FILE_LDAP')) define('_FILE_LDAP', 'ldap.php');
1583
-
1584
-	if (!defined('_FILE_TMP_SUFFIX')) define('_FILE_TMP_SUFFIX', '.tmp.php');
1585
-	if (!defined('_FILE_CONNECT_TMP')) define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
1586
-	if (!defined('_FILE_CHMOD_TMP')) define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
1587
-
1588
-	// Definition des droits d'acces en ecriture
1589
-	if (!defined('_SPIP_CHMOD') AND _FILE_CHMOD)
1590
-		include_once _FILE_CHMOD;
1591
-
1592
-	// Se mefier des fichiers mal remplis!
1593
-	if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', 0777);
1594
-
1595
-	// Le charset par defaut lors de l'installation
1596
-	if (!defined('_DEFAULT_CHARSET')) define('_DEFAULT_CHARSET', 'utf-8');
1597
-	if (!defined('_ROOT_PLUGINS')) define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
1598
-	if (!defined('_ROOT_PLUGINS_DIST')) define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
1599
-	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));
1600
-
1601
-	// La taille des Log
1602
-	if (!defined('_MAX_LOG')) define('_MAX_LOG', 100);
1603
-
1604
-	// Sommes-nous dans l'empire du Mal ?
1605
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
1606
-	if (strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false){
1607
-		if (!defined('_OS_SERVEUR')) define('_OS_SERVEUR', 'windows');
1608
-		if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',1); // utiliser le flock php
1609
-	}
1610
-	else {
1611
-		if (!defined('_OS_SERVEUR')) define('_OS_SERVEUR', '');
1612
-		if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',1); // utiliser le flock php
1613
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
1614
-	}
1615
-
1616
-	// Langue par defaut
1617
-	if (!defined('_LANGUE_PAR_DEFAUT')) define('_LANGUE_PAR_DEFAUT','fr');
1618
-
1619
-	// PHP_VERSION_ID dispo depuis PHP 5.2.7
1620
-	if (!defined('PHP_VERSION_ID')) {
1621
-	   $version = explode('.',PHP_VERSION);
1622
-	   define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
1623
-	}
1624
-
1625
-	//
1626
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
1627
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
1628
-	// pour le rendre surchargeable, on va provoquer un reecriture
1629
-	// systematique du noyau ou une baisse de perfs => a etudier)
1630
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
1631
-
1632
-	// charger tout de suite le path et son cache
1633
-	load_path_cache();
1634
-
1635
-	// *********** traiter les variables ************
1636
-
1637
-	//
1638
-	// Securite
1639
-	//
1640
-
1641
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
1642
-	if (isset($_REQUEST['GLOBALS'])) die();
1643
-	// nettoyer les magic quotes \' et les caracteres nuls %00
1644
-	spip_desinfecte($_GET);
1645
-	spip_desinfecte($_POST);
1646
-	spip_desinfecte($_COOKIE);
1647
-	spip_desinfecte($_REQUEST);
1648
-
1649
-	// Par ailleurs on ne veut pas de magic_quotes au cours de l'execution
1650
-	if (PHP_VERSION_ID<50300) {
1651
-		@set_magic_quotes_runtime(0);
1652
-	}
1653
-
1654
-	// Si les variables sont passees en global par le serveur,
1655
-	// il faut faire quelques verifications de base
1656
-	$avertir_register_globals = false;
1657
-	if (test_valeur_serveur(@ini_get('register_globals'))) {
1658
-		// ne pas desinfecter les globales en profondeur car elle contient aussi les
1659
-		// precedentes, qui seraient desinfectees 2 fois.
1660
-		spip_desinfecte($GLOBALS,false);
1661
-		if (include_spip('inc/php3'))
1662
-			spip_register_globals(true);
1663
-
1664
-		$avertir_register_globals = true;
1665
-	}
1666
-
1667
-	// appliquer le cookie_prefix
1668
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
1669
-		include_spip('inc/cookie');
1670
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
1671
-	}
1672
-
1673
-	//
1674
-	// Capacites php (en fonction de la version)
1675
-	//
1676
-	$GLOBALS['flag_ob'] = (function_exists("ob_start")
1677
-		&& function_exists("ini_get")
1678
-		&& !strstr(@ini_get('disable_functions'), 'ob_'));
1679
-	$GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name");
1680
-	$GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != "");
1681
-	$GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
1682
-		(get_cfg_var('upload_max_filesize') > 0));
1683
-
1684
-
1685
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
1686
-	if (isset($_SERVER['REQUEST_URI'])) {
1687
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1688
-	} else {
1689
-		$GLOBALS['REQUEST_URI'] = $_SERVER['PHP_SELF'];
1690
-		if ($_SERVER['QUERY_STRING']
1691
-		AND !strpos($_SERVER['REQUEST_URI'], '?'))
1692
-			$GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
1693
-	}
1694
-
1695
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
1696
-	if (!defined('_RENOUVELLE_ALEA')) define('_RENOUVELLE_ALEA', 12 * 3600);
1697
-
1698
-	// charger les meta si possible et renouveller l'alea au besoin
1699
-	// charge aussi effacer_meta et ecrire_meta
1700
-	$inc_meta = charger_fonction('meta', 'inc');
1701
-	$inc_meta();
1702
-
1703
-	// on a pas pu le faire plus tot
1704
-	if  ($avertir_register_globals)
1705
-		avertir_auteurs("register_globals",_L("Probl&egrave;me de s&eacute;curit&eacute; : register_globals=on; dans php.ini &agrave; corriger."));
1706
-
1707
-	// nombre de repertoires depuis la racine
1708
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
1709
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
1710
-	// le calcul est faux)
1711
-	if (!_DIR_RESTREINT)
1712
-		$GLOBALS['profondeur_url'] = 1;
1713
-	else {
1714
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
1715
-		$uri_ref = $_SERVER["SCRIPT_NAME"];
1716
-		if (!$uri_ref
1717
-			// si on est appele avec un autre ti, on est sans doute en mutu
1718
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
1719
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
1720
-			// s'en remettre a l'adresse du site. alea jacta est.
1721
-			OR $ti!==_NOM_TEMPORAIRES_INACCESSIBLES){
1722
-
1723
-			if (isset($GLOBALS['meta']['adresse_site'])) {
1724
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
1725
-				$uri_ref = $uri_ref['path'].'/';
1726
-			}
1727
-		  else
1728
-			  $uri_ref = "";
1729
-		}
1730
-		if (!$uri OR !$uri_ref)
1731
-			$GLOBALS['profondeur_url'] = 0;
1732
-		else {
1733
-			$GLOBALS['profondeur_url'] = max(0,
1734
-				substr_count($uri[0], '/')
1735
-				- substr_count($uri_ref,'/'));
1736
-		}
1737
-	}
1738
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
1739
-	if (_FILE_CONNECT) {
1740
-		if (verifier_visiteur()=='0minirezo'
1741
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
1742
-		  AND !isset($_COOKIE['spip_admin']))
1743
-			clear_path_cache();
1744
-	}
1529
+    if (!defined('_DIR_IMG')) define('_DIR_IMG', $pa);
1530
+    if (!defined('_DIR_LOGOS')) define('_DIR_LOGOS', $pa);
1531
+    if (!defined('_DIR_IMG_ICONES')) define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
1532
+
1533
+    if (!defined('_DIR_DUMP')) define('_DIR_DUMP', $ti . "dump/");
1534
+    if (!defined('_DIR_SESSIONS')) define('_DIR_SESSIONS', $ti . "sessions/");
1535
+    if (!defined('_DIR_TRANSFERT')) define('_DIR_TRANSFERT', $ti . "upload/");
1536
+    if (!defined('_DIR_CACHE')) define('_DIR_CACHE', $ti . "cache/");
1537
+    if (!defined('_DIR_CACHE_XML')) define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
1538
+    if (!defined('_DIR_SKELS')) define('_DIR_SKELS',  _DIR_CACHE . "skel/");
1539
+    if (!defined('_DIR_AIDE')) define('_DIR_AIDE',  _DIR_CACHE . "aide/");
1540
+    if (!defined('_DIR_TMP')) define('_DIR_TMP', $ti);
1541
+
1542
+    if (!defined('_DIR_VAR')) define('_DIR_VAR', $ta);
1543
+
1544
+    if (!defined('_DIR_ETC')) define('_DIR_ETC', $pi);
1545
+    if (!defined('_DIR_CONNECT')) define('_DIR_CONNECT', $pi);
1546
+    if (!defined('_DIR_CHMOD')) define('_DIR_CHMOD', $pi);
1547
+
1548
+    if (!isset($GLOBALS['test_dirs']))
1549
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
1550
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
1551
+        $GLOBALS['test_dirs'] =  array($pa, $ti, $ta);
1552
+
1553
+    // Declaration des fichiers
1554
+
1555
+    if (!defined('_CACHE_PLUGINS_PATH')) define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
1556
+    if (!defined('_CACHE_PLUGINS_OPT')) define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
1557
+    if (!defined('_CACHE_PLUGINS_FCT')) define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
1558
+    if (!defined('_CACHE_PIPELINES')) define('_CACHE_PIPELINES',  _DIR_CACHE."charger_pipelines.php");
1559
+    if (!defined('_CACHE_CHEMIN')) define('_CACHE_CHEMIN',  _DIR_CACHE."chemin.txt");
1560
+
1561
+    # attention .php obligatoire pour ecrire_fichier_securise
1562
+    if (!defined('_FILE_META')) define('_FILE_META', $ti . 'meta_cache.php');
1563
+    if (!defined('_DIR_LOG')) define('_DIR_LOG', _DIR_TMP . 'log/');
1564
+    if (!defined('_FILE_LOG')) define('_FILE_LOG', 'spip');
1565
+    if (!defined('_FILE_LOG_SUFFIX')) define('_FILE_LOG_SUFFIX', '.log');
1566
+
1567
+    // Le fichier de connexion a la base de donnees
1568
+    // tient compte des anciennes versions (inc_connect...)
1569
+    if (!defined('_FILE_CONNECT_INS')) define('_FILE_CONNECT_INS', 'connect');
1570
+    if (!defined('_FILE_CONNECT')) define('_FILE_CONNECT',
1571
+        (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
1572
+    :	(@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
1573
+    :	false)));
1574
+
1575
+    // Le fichier de reglages des droits
1576
+    if (!defined('_FILE_CHMOD_INS')) define('_FILE_CHMOD_INS', 'chmod');
1577
+    if (!defined('_FILE_CHMOD')) define('_FILE_CHMOD',
1578
+        (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
1579
+    :	false));
1580
+
1581
+    if (!defined('_FILE_LDAP')) define('_FILE_LDAP', 'ldap.php');
1582
+
1583
+    if (!defined('_FILE_TMP_SUFFIX')) define('_FILE_TMP_SUFFIX', '.tmp.php');
1584
+    if (!defined('_FILE_CONNECT_TMP')) define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
1585
+    if (!defined('_FILE_CHMOD_TMP')) define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
1586
+
1587
+    // Definition des droits d'acces en ecriture
1588
+    if (!defined('_SPIP_CHMOD') AND _FILE_CHMOD)
1589
+        include_once _FILE_CHMOD;
1590
+
1591
+    // Se mefier des fichiers mal remplis!
1592
+    if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', 0777);
1593
+
1594
+    // Le charset par defaut lors de l'installation
1595
+    if (!defined('_DEFAULT_CHARSET')) define('_DEFAULT_CHARSET', 'utf-8');
1596
+    if (!defined('_ROOT_PLUGINS')) define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
1597
+    if (!defined('_ROOT_PLUGINS_DIST')) define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
1598
+    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));
1599
+
1600
+    // La taille des Log
1601
+    if (!defined('_MAX_LOG')) define('_MAX_LOG', 100);
1602
+
1603
+    // Sommes-nous dans l'empire du Mal ?
1604
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
1605
+    if (strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false){
1606
+        if (!defined('_OS_SERVEUR')) define('_OS_SERVEUR', 'windows');
1607
+        if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',1); // utiliser le flock php
1608
+    }
1609
+    else {
1610
+        if (!defined('_OS_SERVEUR')) define('_OS_SERVEUR', '');
1611
+        if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',1); // utiliser le flock php
1612
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
1613
+    }
1614
+
1615
+    // Langue par defaut
1616
+    if (!defined('_LANGUE_PAR_DEFAUT')) define('_LANGUE_PAR_DEFAUT','fr');
1617
+
1618
+    // PHP_VERSION_ID dispo depuis PHP 5.2.7
1619
+    if (!defined('PHP_VERSION_ID')) {
1620
+        $version = explode('.',PHP_VERSION);
1621
+        define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
1622
+    }
1623
+
1624
+    //
1625
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
1626
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
1627
+    // pour le rendre surchargeable, on va provoquer un reecriture
1628
+    // systematique du noyau ou une baisse de perfs => a etudier)
1629
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
1630
+
1631
+    // charger tout de suite le path et son cache
1632
+    load_path_cache();
1633
+
1634
+    // *********** traiter les variables ************
1635
+
1636
+    //
1637
+    // Securite
1638
+    //
1639
+
1640
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
1641
+    if (isset($_REQUEST['GLOBALS'])) die();
1642
+    // nettoyer les magic quotes \' et les caracteres nuls %00
1643
+    spip_desinfecte($_GET);
1644
+    spip_desinfecte($_POST);
1645
+    spip_desinfecte($_COOKIE);
1646
+    spip_desinfecte($_REQUEST);
1647
+
1648
+    // Par ailleurs on ne veut pas de magic_quotes au cours de l'execution
1649
+    if (PHP_VERSION_ID<50300) {
1650
+        @set_magic_quotes_runtime(0);
1651
+    }
1652
+
1653
+    // Si les variables sont passees en global par le serveur,
1654
+    // il faut faire quelques verifications de base
1655
+    $avertir_register_globals = false;
1656
+    if (test_valeur_serveur(@ini_get('register_globals'))) {
1657
+        // ne pas desinfecter les globales en profondeur car elle contient aussi les
1658
+        // precedentes, qui seraient desinfectees 2 fois.
1659
+        spip_desinfecte($GLOBALS,false);
1660
+        if (include_spip('inc/php3'))
1661
+            spip_register_globals(true);
1662
+
1663
+        $avertir_register_globals = true;
1664
+    }
1665
+
1666
+    // appliquer le cookie_prefix
1667
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
1668
+        include_spip('inc/cookie');
1669
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
1670
+    }
1671
+
1672
+    //
1673
+    // Capacites php (en fonction de la version)
1674
+    //
1675
+    $GLOBALS['flag_ob'] = (function_exists("ob_start")
1676
+        && function_exists("ini_get")
1677
+        && !strstr(@ini_get('disable_functions'), 'ob_'));
1678
+    $GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name");
1679
+    $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != "");
1680
+    $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
1681
+        (get_cfg_var('upload_max_filesize') > 0));
1682
+
1683
+
1684
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
1685
+    if (isset($_SERVER['REQUEST_URI'])) {
1686
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1687
+    } else {
1688
+        $GLOBALS['REQUEST_URI'] = $_SERVER['PHP_SELF'];
1689
+        if ($_SERVER['QUERY_STRING']
1690
+        AND !strpos($_SERVER['REQUEST_URI'], '?'))
1691
+            $GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
1692
+    }
1693
+
1694
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
1695
+    if (!defined('_RENOUVELLE_ALEA')) define('_RENOUVELLE_ALEA', 12 * 3600);
1696
+
1697
+    // charger les meta si possible et renouveller l'alea au besoin
1698
+    // charge aussi effacer_meta et ecrire_meta
1699
+    $inc_meta = charger_fonction('meta', 'inc');
1700
+    $inc_meta();
1701
+
1702
+    // on a pas pu le faire plus tot
1703
+    if  ($avertir_register_globals)
1704
+        avertir_auteurs("register_globals",_L("Probl&egrave;me de s&eacute;curit&eacute; : register_globals=on; dans php.ini &agrave; corriger."));
1705
+
1706
+    // nombre de repertoires depuis la racine
1707
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
1708
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
1709
+    // le calcul est faux)
1710
+    if (!_DIR_RESTREINT)
1711
+        $GLOBALS['profondeur_url'] = 1;
1712
+    else {
1713
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
1714
+        $uri_ref = $_SERVER["SCRIPT_NAME"];
1715
+        if (!$uri_ref
1716
+            // si on est appele avec un autre ti, on est sans doute en mutu
1717
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
1718
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
1719
+            // s'en remettre a l'adresse du site. alea jacta est.
1720
+            OR $ti!==_NOM_TEMPORAIRES_INACCESSIBLES){
1721
+
1722
+            if (isset($GLOBALS['meta']['adresse_site'])) {
1723
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
1724
+                $uri_ref = $uri_ref['path'].'/';
1725
+            }
1726
+            else
1727
+                $uri_ref = "";
1728
+        }
1729
+        if (!$uri OR !$uri_ref)
1730
+            $GLOBALS['profondeur_url'] = 0;
1731
+        else {
1732
+            $GLOBALS['profondeur_url'] = max(0,
1733
+                substr_count($uri[0], '/')
1734
+                - substr_count($uri_ref,'/'));
1735
+        }
1736
+    }
1737
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
1738
+    if (_FILE_CONNECT) {
1739
+        if (verifier_visiteur()=='0minirezo'
1740
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
1741
+          AND !isset($_COOKIE['spip_admin']))
1742
+            clear_path_cache();
1743
+    }
1745 1744
 
1746 1745
 }
1747 1746
 
@@ -1751,205 +1750,205 @@  discard block
 block discarded – undo
1751 1750
  *
1752 1751
  */
1753 1752
 function spip_initialisation_suite() {
1754
-	static $too_late = 0;
1755
-	if ($too_late++) return;
1753
+    static $too_late = 0;
1754
+    if ($too_late++) return;
1756 1755
 
1757
-	// taille mini des login
1758
-	if (!defined('_LOGIN_TROP_COURT')) define('_LOGIN_TROP_COURT', 4);
1756
+    // taille mini des login
1757
+    if (!defined('_LOGIN_TROP_COURT')) define('_LOGIN_TROP_COURT', 4);
1759 1758
 
1760
-	// la taille maxi des logos (0 : pas de limite)
1761
-	if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
1762
-	if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
1763
-	if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
1759
+    // la taille maxi des logos (0 : pas de limite)
1760
+    if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
1761
+    if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
1762
+    if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
1764 1763
 
1765
-	if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
1764
+    if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
1766 1765
 
1767
-	if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
1768
-	if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
1769
-	if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
1770
-	if (!defined('_PASS_LONGUEUR_MINI')) define('_PASS_LONGUEUR_MINI',6);
1766
+    if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
1767
+    if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
1768
+    if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
1769
+    if (!defined('_PASS_LONGUEUR_MINI')) define('_PASS_LONGUEUR_MINI',6);
1771 1770
 
1772 1771
 
1773
-	// 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
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
1774 1773
         if (!defined('_IMG_QUALITE')) define('_IMG_QUALITE', 85); # valeur par defaut
1775 1774
         if (!defined('_IMG_GD_QUALITE')) define('_IMG_GD_QUALITE', _IMG_QUALITE); # surcharge pour la lib GD
1776 1775
         if (!defined('_IMG_CONVERT_QUALITE')) define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); # surcharge pour imagick en ligne de commande
1777
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
1776
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
1778 1777
         if (!defined('_IMG_IMAGICK_QUALITE')) define('_IMG_IMAGICK_QUALITE', 75); # surcharge pour imagick en PHP
1779 1778
 
1780
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) define('_COPIE_LOCALE_MAX_SIZE',16777216); // poids en octet
1781
-
1782
-	// qq chaines standard
1783
-	if (!defined('_ACCESS_FILE_NAME')) define('_ACCESS_FILE_NAME', '.htaccess');
1784
-	if (!defined('_AUTH_USER_FILE')) define('_AUTH_USER_FILE', '.htpasswd');
1785
-	if (!defined('_SPIP_DUMP')) define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
1786
-	if (!defined('_CACHE_RUBRIQUES')) define('_CACHE_RUBRIQUES', _DIR_TMP.'menu-rubriques-cache.txt');
1787
-	if (!defined('_CACHE_RUBRIQUES_MAX')) define('_CACHE_RUBRIQUES_MAX', 500);
1788
-
1789
-	if (!defined('_EXTENSION_SQUELETTES')) define('_EXTENSION_SQUELETTES', 'html');
1790
-
1791
-	if (!defined('_DOCTYPE_ECRIRE')) define('_DOCTYPE_ECRIRE',
1792
-		// "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>\n");
1793
-		//"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n");
1794
-		//"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n");
1795
-	       // "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1 //EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>\n");
1796
-		"<!DOCTYPE html>\n");
1797
-	if (!defined('_DOCTYPE_AIDE')) define('_DOCTYPE_AIDE',
1798
-	       "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
1799
-
1800
-	// L'adresse de base du site ; on peut mettre '' si la racine est geree par
1801
-	// le script de l'espace public, alias  index.php
1802
-	if (!defined('_SPIP_SCRIPT')) define('_SPIP_SCRIPT', 'spip.php');
1803
-	// argument page, personalisable en cas de conflit avec un autre script
1804
-	if (!defined('_SPIP_PAGE')) define('_SPIP_PAGE', 'page');
1805
-
1806
-	// le script de l'espace prive
1807
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
1808
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
1809
-	// meme pb sur thttpd cf. http://forum.spip.org/fr_184153.html
1810
-
1811
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) define('_SPIP_ECRIRE_SCRIPT', // true ? #decommenter ici et commenter la
1812
-	       preg_match(',IIS|thttpd,',$_SERVER['SERVER_SOFTWARE']) ?
1813
-	       'index.php' : '');
1814
-
1815
-
1816
-	if (!defined('_SPIP_AJAX'))
1817
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
1818
-			? 1
1819
-		       : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
1820
-
1821
-	// La requete est-elle en ajax ?
1822
-	if (!defined('_AJAX')) define('_AJAX',
1823
-		(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
1824
-		OR @$_REQUEST['var_ajax_redir'] # redirection 302 apres ajax jQuery
1825
-		OR @$_REQUEST['var_ajaxcharset'] # compat ascendante pour plugins
1826
-		OR @$_REQUEST['var_ajax'] # forms ajax & inclure ajax de spip
1827
-		)
1828
-		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
1829
-	);
1830
-
1831
-	# nombre de pixels maxi pour calcul de la vignette avec gd
1832
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
1833
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
1834
-	if (!defined('_IMG_GD_MAX_PIXELS')) define('_IMG_GD_MAX_PIXELS',
1835
-		(isset($GLOBALS['meta']['max_taille_vignettes'])&&$GLOBALS['meta']['max_taille_vignettes']<5500000)
1836
-		 ? $GLOBALS['meta']['max_taille_vignettes']
1837
-		 : 0);
1838
-
1839
-	if (!defined('_MEMORY_LIMIT_MIN')) define('_MEMORY_LIMIT_MIN',10); // en Mo
1840
-	// si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
1841
-	// on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
1842
-	// il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
1843
-	if (test_espace_prive() AND _MEMORY_LIMIT_MIN>8){
1844
-		if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
1845
-			$unit = strtolower(substr($memory,strlen($memory/1),1));
1846
-			switch($unit) {
1847
-				// Le modifieur 'G' est disponible depuis PHP 5.1.0
1848
-				case 'g': $memory *= 1024;
1849
-				case 'm': $memory *= 1024;
1850
-				case 'k': $memory *= 1024;
1851
-			}
1852
-			if ($memory<_MEMORY_LIMIT_MIN*1024*1024){
1853
-				ini_set('memory_limit',$m=_MEMORY_LIMIT_MIN.'M');
1854
-				if (trim(ini_get('memory_limit'))!=$m){
1855
-					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
1856
-				}
1857
-			}
1858
-		}
1859
-		else
1860
-			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
1861
-	}
1862
-	// Protocoles a normaliser dans les chaines de langues
1863
-	if (!defined('_PROTOCOLES_STD'))
1864
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
1865
-
1866
-	init_var_mode();
1779
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) define('_COPIE_LOCALE_MAX_SIZE',16777216); // poids en octet
1780
+
1781
+    // qq chaines standard
1782
+    if (!defined('_ACCESS_FILE_NAME')) define('_ACCESS_FILE_NAME', '.htaccess');
1783
+    if (!defined('_AUTH_USER_FILE')) define('_AUTH_USER_FILE', '.htpasswd');
1784
+    if (!defined('_SPIP_DUMP')) define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
1785
+    if (!defined('_CACHE_RUBRIQUES')) define('_CACHE_RUBRIQUES', _DIR_TMP.'menu-rubriques-cache.txt');
1786
+    if (!defined('_CACHE_RUBRIQUES_MAX')) define('_CACHE_RUBRIQUES_MAX', 500);
1787
+
1788
+    if (!defined('_EXTENSION_SQUELETTES')) define('_EXTENSION_SQUELETTES', 'html');
1789
+
1790
+    if (!defined('_DOCTYPE_ECRIRE')) define('_DOCTYPE_ECRIRE',
1791
+        // "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>\n");
1792
+        //"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n");
1793
+        //"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n");
1794
+            // "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1 //EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>\n");
1795
+        "<!DOCTYPE html>\n");
1796
+    if (!defined('_DOCTYPE_AIDE')) define('_DOCTYPE_AIDE',
1797
+            "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
1798
+
1799
+    // L'adresse de base du site ; on peut mettre '' si la racine est geree par
1800
+    // le script de l'espace public, alias  index.php
1801
+    if (!defined('_SPIP_SCRIPT')) define('_SPIP_SCRIPT', 'spip.php');
1802
+    // argument page, personalisable en cas de conflit avec un autre script
1803
+    if (!defined('_SPIP_PAGE')) define('_SPIP_PAGE', 'page');
1804
+
1805
+    // le script de l'espace prive
1806
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
1807
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
1808
+    // meme pb sur thttpd cf. http://forum.spip.org/fr_184153.html
1809
+
1810
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) define('_SPIP_ECRIRE_SCRIPT', // true ? #decommenter ici et commenter la
1811
+            preg_match(',IIS|thttpd,',$_SERVER['SERVER_SOFTWARE']) ?
1812
+           'index.php' : '');
1813
+
1814
+
1815
+    if (!defined('_SPIP_AJAX'))
1816
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
1817
+            ? 1
1818
+               : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
1819
+
1820
+    // La requete est-elle en ajax ?
1821
+    if (!defined('_AJAX')) define('_AJAX',
1822
+        (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
1823
+        OR @$_REQUEST['var_ajax_redir'] # redirection 302 apres ajax jQuery
1824
+        OR @$_REQUEST['var_ajaxcharset'] # compat ascendante pour plugins
1825
+        OR @$_REQUEST['var_ajax'] # forms ajax & inclure ajax de spip
1826
+        )
1827
+        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
1828
+    );
1829
+
1830
+    # nombre de pixels maxi pour calcul de la vignette avec gd
1831
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
1832
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
1833
+    if (!defined('_IMG_GD_MAX_PIXELS')) define('_IMG_GD_MAX_PIXELS',
1834
+        (isset($GLOBALS['meta']['max_taille_vignettes'])&&$GLOBALS['meta']['max_taille_vignettes']<5500000)
1835
+         ? $GLOBALS['meta']['max_taille_vignettes']
1836
+         : 0);
1837
+
1838
+    if (!defined('_MEMORY_LIMIT_MIN')) define('_MEMORY_LIMIT_MIN',10); // en Mo
1839
+    // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
1840
+    // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
1841
+    // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
1842
+    if (test_espace_prive() AND _MEMORY_LIMIT_MIN>8){
1843
+        if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
1844
+            $unit = strtolower(substr($memory,strlen($memory/1),1));
1845
+            switch($unit) {
1846
+                // Le modifieur 'G' est disponible depuis PHP 5.1.0
1847
+                case 'g': $memory *= 1024;
1848
+                case 'm': $memory *= 1024;
1849
+                case 'k': $memory *= 1024;
1850
+            }
1851
+            if ($memory<_MEMORY_LIMIT_MIN*1024*1024){
1852
+                ini_set('memory_limit',$m=_MEMORY_LIMIT_MIN.'M');
1853
+                if (trim(ini_get('memory_limit'))!=$m){
1854
+                    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
1855
+                }
1856
+            }
1857
+        }
1858
+        else
1859
+            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
1860
+    }
1861
+    // Protocoles a normaliser dans les chaines de langues
1862
+    if (!defined('_PROTOCOLES_STD'))
1863
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
1864
+
1865
+    init_var_mode();
1867 1866
 }
1868 1867
 
1869 1868
 // Reperer les variables d'URL qui conditionnent la perennite du cache, des urls
1870 1869
 // ou d'autres petit caches (trouver_table, css et js compactes ...)
1871 1870
 // http://doc.spip.org/@init_var_mode
1872 1871
 function init_var_mode(){
1873
-	static $done = false;
1874
-	if (!$done) {
1875
-
1876
-		if (isset($_GET['var_mode'])) {
1877
-			// tout le monde peut calcul/recalcul
1878
-			if ($_GET['var_mode'] == 'calcul'
1879
-			OR $_GET['var_mode'] == 'recalcul') {
1880
-				if (!defined('_VAR_MODE')) define('_VAR_MODE',$_GET['var_mode']);
1881
-			}
1882
-			// preview, debug, blocs, urls et images necessitent une autorisation
1883
-			else if (in_array($_GET['var_mode'],array('preview','debug','inclure','urls','images','traduction'))) {
1884
-				include_spip('inc/autoriser');
1885
-				if (autoriser(
1886
-					($_GET['var_mode'] == 'preview')
1887
-						? 'previsualiser'
1888
-						: 'debug'
1889
-				)) {
1890
-					switch($_GET['var_mode']){
1891
-						case 'traduction':
1892
-							// forcer le calcul pour passer dans traduire
1893
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1894
-							// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
1895
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1896
-							break;
1897
-						case 'preview':
1898
-							// basculer sur les criteres de preview dans les boucles
1899
-							if (!defined('_VAR_PREVIEW')) define('_VAR_PREVIEW',true);
1900
-							// forcer le calcul
1901
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1902
-							// et ne pas enregistrer de cache
1903
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1904
-							break;
1905
-						case 'inclure':
1906
-							// forcer le compilo et ignorer les caches existants
1907
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1908
-							if (!defined('_VAR_INCLURE')) define('_VAR_INCLURE',true);
1909
-							// et ne pas enregistrer de cache
1910
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1911
-							break;
1912
-						case 'urls':
1913
-							// forcer le compilo et ignorer les caches existants
1914
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1915
-							if (!defined('_VAR_URLS')) define('_VAR_URLS',true);
1916
-							break;
1917
-						case 'images':
1918
-							// forcer le compilo et ignorer les caches existants
1919
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1920
-							// indiquer qu'on doit recalculer les images
1921
-							if (!defined('_VAR_IMAGES')) define('_VAR_IMAGES',true);
1922
-							break;
1923
-						case 'debug':
1924
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','debug');
1925
-							// et ne pas enregistrer de cache
1926
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1927
-							break;
1928
-						default :
1929
-							if (!defined('_VAR_MODE')) define('_VAR_MODE',$_GET['var_mode']);
1930
-							break;
1931
-					}
1932
-          if (isset($GLOBALS['visiteur_session']['nom']))
1933
-					spip_log($GLOBALS['visiteur_session']['nom']
1934
-						. " "._VAR_MODE);
1935
-				}
1936
-				// pas autorise ?
1937
-				else {
1938
-					// si on n'est pas connecte on se redirige
1939
-					if (!$GLOBALS['visiteur_session']) {
1940
-						include_spip('inc/headers');
1941
-						redirige_par_entete(generer_url_public('login',
1942
-						'url='.rawurlencode(
1943
-						parametre_url(self(), 'var_mode', $_GET['var_mode'], '&')
1944
-						), true));
1945
-					}
1946
-					// sinon tant pis
1947
-				}
1948
-			}
1949
-			if (!defined('_VAR_MODE')) define('_VAR_MODE',false);
1950
-		}
1951
-		$done = true;
1952
-	}
1872
+    static $done = false;
1873
+    if (!$done) {
1874
+
1875
+        if (isset($_GET['var_mode'])) {
1876
+            // tout le monde peut calcul/recalcul
1877
+            if ($_GET['var_mode'] == 'calcul'
1878
+            OR $_GET['var_mode'] == 'recalcul') {
1879
+                if (!defined('_VAR_MODE')) define('_VAR_MODE',$_GET['var_mode']);
1880
+            }
1881
+            // preview, debug, blocs, urls et images necessitent une autorisation
1882
+            else if (in_array($_GET['var_mode'],array('preview','debug','inclure','urls','images','traduction'))) {
1883
+                include_spip('inc/autoriser');
1884
+                if (autoriser(
1885
+                    ($_GET['var_mode'] == 'preview')
1886
+                        ? 'previsualiser'
1887
+                        : 'debug'
1888
+                )) {
1889
+                    switch($_GET['var_mode']){
1890
+                        case 'traduction':
1891
+                            // forcer le calcul pour passer dans traduire
1892
+                            if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1893
+                            // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
1894
+                            if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1895
+                            break;
1896
+                        case 'preview':
1897
+                            // basculer sur les criteres de preview dans les boucles
1898
+                            if (!defined('_VAR_PREVIEW')) define('_VAR_PREVIEW',true);
1899
+                            // forcer le calcul
1900
+                            if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1901
+                            // et ne pas enregistrer de cache
1902
+                            if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1903
+                            break;
1904
+                        case 'inclure':
1905
+                            // forcer le compilo et ignorer les caches existants
1906
+                            if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1907
+                            if (!defined('_VAR_INCLURE')) define('_VAR_INCLURE',true);
1908
+                            // et ne pas enregistrer de cache
1909
+                            if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1910
+                            break;
1911
+                        case 'urls':
1912
+                            // forcer le compilo et ignorer les caches existants
1913
+                            if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1914
+                            if (!defined('_VAR_URLS')) define('_VAR_URLS',true);
1915
+                            break;
1916
+                        case 'images':
1917
+                            // forcer le compilo et ignorer les caches existants
1918
+                            if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1919
+                            // indiquer qu'on doit recalculer les images
1920
+                            if (!defined('_VAR_IMAGES')) define('_VAR_IMAGES',true);
1921
+                            break;
1922
+                        case 'debug':
1923
+                            if (!defined('_VAR_MODE')) define('_VAR_MODE','debug');
1924
+                            // et ne pas enregistrer de cache
1925
+                            if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1926
+                            break;
1927
+                        default :
1928
+                            if (!defined('_VAR_MODE')) define('_VAR_MODE',$_GET['var_mode']);
1929
+                            break;
1930
+                    }
1931
+            if (isset($GLOBALS['visiteur_session']['nom']))
1932
+                    spip_log($GLOBALS['visiteur_session']['nom']
1933
+                        . " "._VAR_MODE);
1934
+                }
1935
+                // pas autorise ?
1936
+                else {
1937
+                    // si on n'est pas connecte on se redirige
1938
+                    if (!$GLOBALS['visiteur_session']) {
1939
+                        include_spip('inc/headers');
1940
+                        redirige_par_entete(generer_url_public('login',
1941
+                        'url='.rawurlencode(
1942
+                        parametre_url(self(), 'var_mode', $_GET['var_mode'], '&')
1943
+                        ), true));
1944
+                    }
1945
+                    // sinon tant pis
1946
+                }
1947
+            }
1948
+            if (!defined('_VAR_MODE')) define('_VAR_MODE',false);
1949
+        }
1950
+        $done = true;
1951
+    }
1953 1952
 }
1954 1953
 
1955 1954
 // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ;
@@ -1957,84 +1956,84 @@  discard block
 block discarded – undo
1957 1956
 // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal')
1958 1957
 // http://doc.spip.org/@spip_desinfecte
1959 1958
 function spip_desinfecte(&$t,$deep = true) {
1960
-	static $magic_quotes;
1961
-	if (!isset($magic_quotes))
1962
-		$magic_quotes = @get_magic_quotes_gpc();
1963
-
1964
-	foreach ($t as $key => $val) {
1965
-		if (is_string($t[$key])) {
1966
-			if ($magic_quotes)
1967
-				$t[$key] = stripslashes($t[$key]);
1968
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
1969
-		}
1970
-		// traiter aussi les "texte_plus" de article_edit
1971
-		else if ($deep AND is_array($t[$key]) AND $key!=='GLOBALS')
1972
-			spip_desinfecte($t[$key],$deep);
1973
-	}
1959
+    static $magic_quotes;
1960
+    if (!isset($magic_quotes))
1961
+        $magic_quotes = @get_magic_quotes_gpc();
1962
+
1963
+    foreach ($t as $key => $val) {
1964
+        if (is_string($t[$key])) {
1965
+            if ($magic_quotes)
1966
+                $t[$key] = stripslashes($t[$key]);
1967
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
1968
+        }
1969
+        // traiter aussi les "texte_plus" de article_edit
1970
+        else if ($deep AND is_array($t[$key]) AND $key!=='GLOBALS')
1971
+            spip_desinfecte($t[$key],$deep);
1972
+    }
1974 1973
 }
1975 1974
 
1976 1975
 //  retourne le statut du visiteur s'il s'annonce
1977 1976
 
1978 1977
 // http://doc.spip.org/@verifier_visiteur
1979 1978
 function verifier_visiteur() {
1980
-	// Rq: pour que cette fonction marche depuis mes_options
1981
-	// il faut forcer l'init si ce n'est fait
1982
-	// mais on risque de perturber des plugins en initialisant trop tot
1983
-	// certaines constantes
1984
-	@spip_initialisation_core(
1985
-		(_DIR_RACINE  . _NOM_PERMANENTS_INACCESSIBLES),
1986
-		(_DIR_RACINE  . _NOM_PERMANENTS_ACCESSIBLES),
1987
-		(_DIR_RACINE  . _NOM_TEMPORAIRES_INACCESSIBLES),
1988
-		(_DIR_RACINE  . _NOM_TEMPORAIRES_ACCESSIBLES)
1989
-	);
1990
-
1991
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
1992
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
1993
-	// Attention on separe bien session_nom et nom, pour eviter
1994
-	// les melanges entre donnees SQL et variables plus aleatoires
1995
-	$variables_session = array('session_nom', 'session_email');
1996
-	foreach($variables_session as $var) {
1997
-		if (_request($var) !== null) {
1998
-			$init = true;
1999
-			break;
2000
-		}
2001
-	}
2002
-	if (isset($init)) {
2003
-		#@spip_initialisation_suite();
2004
-		$session = charger_fonction('session', 'inc');
2005
-		$session();
2006
-		include_spip('inc/texte');
2007
-		foreach($variables_session as $var)
2008
-			if (($a = _request($var)) !== null)
2009
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
2010
-		if (!isset($GLOBALS['visiteur_session']['id_auteur']))
2011
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
2012
-		$session($GLOBALS['visiteur_session']);
2013
-		return 0;
2014
-	}
2015
-
2016
-	$h = (isset($_SERVER['PHP_AUTH_USER'])  AND !$GLOBALS['ignore_auth_http']);
2017
-	if ($h OR isset($_COOKIE['spip_session']) OR isset($_COOKIE[$GLOBALS['cookie_prefix'].'_session'])) {
2018
-
2019
-		$session = charger_fonction('session', 'inc');
2020
-		if ($session()) {
2021
-			return $GLOBALS['visiteur_session']['statut'];
2022
-		}
2023
-		if ($h  AND isset($_SERVER['PHP_AUTH_PW'])) {
2024
-			include_spip('inc/auth');
2025
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
2026
-		}
2027
-		if ($h) {
2028
-			$GLOBALS['visiteur_session'] = $h;
2029
-			return $GLOBALS['visiteur_session']['statut'];
2030
-		}
2031
-	}
2032
-
2033
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
2034
-	include_spip('inc/lang');
2035
-	utiliser_langue_visiteur();
2036
-
2037
-	return false;
1979
+    // Rq: pour que cette fonction marche depuis mes_options
1980
+    // il faut forcer l'init si ce n'est fait
1981
+    // mais on risque de perturber des plugins en initialisant trop tot
1982
+    // certaines constantes
1983
+    @spip_initialisation_core(
1984
+        (_DIR_RACINE  . _NOM_PERMANENTS_INACCESSIBLES),
1985
+        (_DIR_RACINE  . _NOM_PERMANENTS_ACCESSIBLES),
1986
+        (_DIR_RACINE  . _NOM_TEMPORAIRES_INACCESSIBLES),
1987
+        (_DIR_RACINE  . _NOM_TEMPORAIRES_ACCESSIBLES)
1988
+    );
1989
+
1990
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
1991
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
1992
+    // Attention on separe bien session_nom et nom, pour eviter
1993
+    // les melanges entre donnees SQL et variables plus aleatoires
1994
+    $variables_session = array('session_nom', 'session_email');
1995
+    foreach($variables_session as $var) {
1996
+        if (_request($var) !== null) {
1997
+            $init = true;
1998
+            break;
1999
+        }
2000
+    }
2001
+    if (isset($init)) {
2002
+        #@spip_initialisation_suite();
2003
+        $session = charger_fonction('session', 'inc');
2004
+        $session();
2005
+        include_spip('inc/texte');
2006
+        foreach($variables_session as $var)
2007
+            if (($a = _request($var)) !== null)
2008
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
2009
+        if (!isset($GLOBALS['visiteur_session']['id_auteur']))
2010
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
2011
+        $session($GLOBALS['visiteur_session']);
2012
+        return 0;
2013
+    }
2014
+
2015
+    $h = (isset($_SERVER['PHP_AUTH_USER'])  AND !$GLOBALS['ignore_auth_http']);
2016
+    if ($h OR isset($_COOKIE['spip_session']) OR isset($_COOKIE[$GLOBALS['cookie_prefix'].'_session'])) {
2017
+
2018
+        $session = charger_fonction('session', 'inc');
2019
+        if ($session()) {
2020
+            return $GLOBALS['visiteur_session']['statut'];
2021
+        }
2022
+        if ($h  AND isset($_SERVER['PHP_AUTH_PW'])) {
2023
+            include_spip('inc/auth');
2024
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
2025
+        }
2026
+        if ($h) {
2027
+            $GLOBALS['visiteur_session'] = $h;
2028
+            return $GLOBALS['visiteur_session']['statut'];
2029
+        }
2030
+    }
2031
+
2032
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
2033
+    include_spip('inc/lang');
2034
+    utiliser_langue_visiteur();
2035
+
2036
+    return false;
2038 2037
 }
2039 2038
 
2040 2039
 // selectionne la langue donnee en argument et memorise la courante
@@ -2046,18 +2045,18 @@  discard block
 block discarded – undo
2046 2045
 
2047 2046
 // http://doc.spip.org/@lang_select
2048 2047
 function lang_select ($lang=NULL) {
2049
-	static $pile_langues = array();
2050
-	if (!function_exists('changer_langue'))
2051
-		include_spip('inc/lang');
2052
-	if ($lang === NULL)
2053
-		$lang = array_pop($pile_langues);
2054
-	else {
2055
-		array_push($pile_langues, $GLOBALS['spip_lang']);
2056
-	}
2057
-	if (isset($GLOBALS['spip_lang']) AND $lang == $GLOBALS['spip_lang'])
2058
-		return $lang;
2059
-	changer_langue($lang);
2060
-	return $lang;
2048
+    static $pile_langues = array();
2049
+    if (!function_exists('changer_langue'))
2050
+        include_spip('inc/lang');
2051
+    if ($lang === NULL)
2052
+        $lang = array_pop($pile_langues);
2053
+    else {
2054
+        array_push($pile_langues, $GLOBALS['spip_lang']);
2055
+    }
2056
+    if (isset($GLOBALS['spip_lang']) AND $lang == $GLOBALS['spip_lang'])
2057
+        return $lang;
2058
+    changer_langue($lang);
2059
+    return $lang;
2061 2060
 }
2062 2061
 
2063 2062
 
@@ -2070,18 +2069,18 @@  discard block
 block discarded – undo
2070 2069
 // de fichier cache
2071 2070
 // http://doc.spip.org/@spip_session
2072 2071
 function spip_session($force = false) {
2073
-	static $session;
2074
-	if ($force OR !isset($session)) {
2075
-		$s = pipeline('definir_session',
2076
-			$GLOBALS['visiteur_session']
2077
-			? serialize($GLOBALS['visiteur_session'])
2078
-				. '_' . @$_COOKIE['spip_session']
2079
-			: ''
2080
-		);
2081
-		$session = $s ? substr(md5($s), 0, 8) : '';
2082
-	}
2083
-	#spip_log('session: '.$session);
2084
-	return $session;
2072
+    static $session;
2073
+    if ($force OR !isset($session)) {
2074
+        $s = pipeline('definir_session',
2075
+            $GLOBALS['visiteur_session']
2076
+            ? serialize($GLOBALS['visiteur_session'])
2077
+                . '_' . @$_COOKIE['spip_session']
2078
+            : ''
2079
+        );
2080
+        $session = $s ? substr(md5($s), 0, 8) : '';
2081
+    }
2082
+    #spip_log('session: '.$session);
2083
+    return $session;
2085 2084
 }
2086 2085
 
2087 2086
 
@@ -2098,18 +2097,18 @@  discard block
 block discarded – undo
2098 2097
 **/
2099 2098
 // http://doc.spip.org/@aide
2100 2099
 function aide($aide='', $distante = false) {
2101
-		$aider = charger_fonction('aider', 'inc', true);
2102
-	return $aider ?  $aider($aide, '', array(), $distante) : '';
2100
+        $aider = charger_fonction('aider', 'inc', true);
2101
+    return $aider ?  $aider($aide, '', array(), $distante) : '';
2103 2102
 }
2104 2103
 
2105 2104
 // normalement il faudrait creer exec/info.php, mais pour mettre juste ca:
2106 2105
 // http://doc.spip.org/@exec_info_dist
2107 2106
 function exec_info_dist() {
2108
-	global $connect_statut;
2109
-	if ($connect_statut == '0minirezo')
2110
-		phpinfo();
2111
-	else
2112
-		echo "pas admin";
2107
+    global $connect_statut;
2108
+    if ($connect_statut == '0minirezo')
2109
+        phpinfo();
2110
+    else
2111
+        echo "pas admin";
2113 2112
 }
2114 2113
 
2115 2114
 /**
@@ -2129,12 +2128,12 @@  discard block
 block discarded – undo
2129 2128
  * 		- string si $message à false.
2130 2129
 **/
2131 2130
 function erreur_squelette($message='', $lieu='') {
2132
-	$debusquer = charger_fonction('debusquer', 'public');
2133
-	if (is_array($lieu)) {
2134
-		include_spip('public/compiler');
2135
-		$lieu = reconstruire_contexte_compil($lieu);
2136
-	}
2137
-	return $debusquer($message, $lieu);
2131
+    $debusquer = charger_fonction('debusquer', 'public');
2132
+    if (is_array($lieu)) {
2133
+        include_spip('public/compiler');
2134
+        $lieu = reconstruire_contexte_compil($lieu);
2135
+    }
2136
+    return $debusquer($message, $lieu);
2138 2137
 }
2139 2138
 
2140 2139
 /**
@@ -2169,67 +2168,67 @@  discard block
 block discarded – undo
2169 2168
  * 		ou tableau d'information sur le squelette.
2170 2169
  */
2171 2170
 function recuperer_fond($fond, $contexte=array(), $options = array(), $connect='') {
2172
-	if (!function_exists('evaluer_fond'))
2173
-		include_spip('public/assembler');
2174
-	// assurer la compat avec l'ancienne syntaxe
2175
-	// (trim etait le 3eme argument, par defaut a true)
2176
-	if (!is_array($options)) $options = array('trim'=>$options);
2177
-	if (!isset($options['trim'])) $options['trim']=true;
2178
-
2179
-	if (isset($contexte['connect'])){
2180
-		$connect = ($connect ? $connect : $contexte['connect']);
2181
-		unset($contexte['connect']);
2182
-	}
2183
-
2184
-	$texte = "";
2185
-	$pages = array();
2186
-	$lang_select = '';
2187
-	if (!isset($options['etoile']) OR !$options['etoile']){
2188
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
2189
-		if (!isset($contexte['lang']))
2190
-			$contexte['lang'] = $GLOBALS['spip_lang'];
2191
-
2192
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
2193
-			$lang_select = lang_select($contexte['lang']);
2194
-		}
2195
-	}
2196
-
2197
-	@$GLOBALS['_INC_PUBLIC']++;
2198
-
2199
-	foreach(is_array($fond) ? $fond : array($fond) as $f){
2200
-		$page = evaluer_fond($f, $contexte, $connect);
2201
-		if ($page === '') {
2202
-			$c = isset($options['compil']) ? $options['compil'] :'';
2203
-			$a = array('fichier'=>$fond);
2204
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
2205
-			erreur_squelette($erreur, $c);
2206
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
2207
-			$page = array('texte' => '', 'erreur' => $erreur);
2208
-		}
2209
-
2210
-		$page = pipeline('recuperer_fond',array(
2211
-			'args'=>array('fond'=>$f,'contexte'=>$contexte,'options'=>$options,'connect'=>$connect),
2212
-			'data'=>$page
2213
-		));
2214
-		if (isset($options['ajax']) AND $options['ajax']){
2215
-			if (!function_exists('encoder_contexte_ajax'))
2216
-				include_spip('inc/filtres');
2217
-			$page['texte'] = encoder_contexte_ajax(array_merge($contexte,array('fond'=>$f)),'',$page['texte'], $options['ajax']);
2218
-		}
2219
-
2220
-		if (isset($options['raw']) AND $options['raw'])
2221
-			$pages[] = $page;
2222
-		else
2223
-			$texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
2224
-	}
2225
-
2226
-	$GLOBALS['_INC_PUBLIC']--;
2227
-
2228
-	if ($lang_select) lang_select();
2229
-	if (isset($options['raw']) AND $options['raw'])
2230
-		return is_array($fond)?$pages:reset($pages);
2231
-	else
2232
-		return $options['trim'] ? ltrim($texte) : $texte;
2171
+    if (!function_exists('evaluer_fond'))
2172
+        include_spip('public/assembler');
2173
+    // assurer la compat avec l'ancienne syntaxe
2174
+    // (trim etait le 3eme argument, par defaut a true)
2175
+    if (!is_array($options)) $options = array('trim'=>$options);
2176
+    if (!isset($options['trim'])) $options['trim']=true;
2177
+
2178
+    if (isset($contexte['connect'])){
2179
+        $connect = ($connect ? $connect : $contexte['connect']);
2180
+        unset($contexte['connect']);
2181
+    }
2182
+
2183
+    $texte = "";
2184
+    $pages = array();
2185
+    $lang_select = '';
2186
+    if (!isset($options['etoile']) OR !$options['etoile']){
2187
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
2188
+        if (!isset($contexte['lang']))
2189
+            $contexte['lang'] = $GLOBALS['spip_lang'];
2190
+
2191
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
2192
+            $lang_select = lang_select($contexte['lang']);
2193
+        }
2194
+    }
2195
+
2196
+    @$GLOBALS['_INC_PUBLIC']++;
2197
+
2198
+    foreach(is_array($fond) ? $fond : array($fond) as $f){
2199
+        $page = evaluer_fond($f, $contexte, $connect);
2200
+        if ($page === '') {
2201
+            $c = isset($options['compil']) ? $options['compil'] :'';
2202
+            $a = array('fichier'=>$fond);
2203
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
2204
+            erreur_squelette($erreur, $c);
2205
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
2206
+            $page = array('texte' => '', 'erreur' => $erreur);
2207
+        }
2208
+
2209
+        $page = pipeline('recuperer_fond',array(
2210
+            'args'=>array('fond'=>$f,'contexte'=>$contexte,'options'=>$options,'connect'=>$connect),
2211
+            'data'=>$page
2212
+        ));
2213
+        if (isset($options['ajax']) AND $options['ajax']){
2214
+            if (!function_exists('encoder_contexte_ajax'))
2215
+                include_spip('inc/filtres');
2216
+            $page['texte'] = encoder_contexte_ajax(array_merge($contexte,array('fond'=>$f)),'',$page['texte'], $options['ajax']);
2217
+        }
2218
+
2219
+        if (isset($options['raw']) AND $options['raw'])
2220
+            $pages[] = $page;
2221
+        else
2222
+            $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
2223
+    }
2224
+
2225
+    $GLOBALS['_INC_PUBLIC']--;
2226
+
2227
+    if ($lang_select) lang_select();
2228
+    if (isset($options['raw']) AND $options['raw'])
2229
+        return is_array($fond)?$pages:reset($pages);
2230
+    else
2231
+        return $options['trim'] ? ltrim($texte) : $texte;
2233 2232
 }
2234 2233
 
2235 2234
 /**
@@ -2239,7 +2238,7 @@  discard block
 block discarded – undo
2239 2238
  * @return string
2240 2239
  */
2241 2240
 function trouve_modele($nom) {
2242
-	return trouver_fond($nom,'modeles/');
2241
+    return trouver_fond($nom,'modeles/');
2243 2242
 }
2244 2243
 
2245 2244
 /**
@@ -2255,54 +2254,54 @@  discard block
 block discarded – undo
2255 2254
  * @return array|string
2256 2255
  */
2257 2256
 function trouver_fond($nom, $dir='', $pathinfo = false) {
2258
-	$f = find_in_path($nom.'.'. _EXTENSION_SQUELETTES, $dir?rtrim($dir,'/').'/':'');
2259
-	if (!$pathinfo) return $f;
2260
-	// renvoyer un tableau detaille si $pathinfo==true
2261
-	$p = pathinfo($f);
2262
-	if (!isset($p['extension']) OR !$p['extension']) {
2263
-		$p['extension'] = _EXTENSION_SQUELETTES;
2264
-	}
2265
-	if (!isset($p['extension']) OR !$p['filename']) {
2266
-		$p['filename'] = ($p['basename']?substr($p['basename'],0,-strlen($p['extension'])-1):'');
2267
-	}
2268
-	$p['fond'] = ($f?substr($f,0,-strlen($p['extension'])-1):'');
2269
-	return $p;
2257
+    $f = find_in_path($nom.'.'. _EXTENSION_SQUELETTES, $dir?rtrim($dir,'/').'/':'');
2258
+    if (!$pathinfo) return $f;
2259
+    // renvoyer un tableau detaille si $pathinfo==true
2260
+    $p = pathinfo($f);
2261
+    if (!isset($p['extension']) OR !$p['extension']) {
2262
+        $p['extension'] = _EXTENSION_SQUELETTES;
2263
+    }
2264
+    if (!isset($p['extension']) OR !$p['filename']) {
2265
+        $p['filename'] = ($p['basename']?substr($p['basename'],0,-strlen($p['extension'])-1):'');
2266
+    }
2267
+    $p['fond'] = ($f?substr($f,0,-strlen($p['extension'])-1):'');
2268
+    return $p;
2270 2269
 }
2271 2270
 
2272 2271
 function tester_url_ecrire($nom){
2273
-	static $exec=array();
2274
-	if (isset($exec[$nom])) return $exec[$nom];
2275
-	// tester si c'est une page en squelette
2276
-	if (trouver_fond($nom, 'prive/squelettes/contenu/'))
2277
-		return $exec[$nom] = 'fond';
2278
-	// compat skels orthogonaux version precedente
2279
-	elseif (trouver_fond($nom, 'prive/exec/'))
2280
-		return $exec[$nom] = 'fond_monobloc';
2281
-	// echafaudage d'un fond !
2282
-	elseif(include_spip('public/styliser_par_z') AND z_echafaudable($nom))
2283
-		return $exec[$nom] = 'fond';
2284
-	// attention, il ne faut pas inclure l'exec ici
2285
-	// car sinon #URL_ECRIRE provoque des inclusions
2286
-	// et des define intrusifs potentiels
2287
-	return $exec[$nom] = ((find_in_path("{$nom}.php",'exec/') OR charger_fonction($nom,'exec',true))?$nom:'');
2272
+    static $exec=array();
2273
+    if (isset($exec[$nom])) return $exec[$nom];
2274
+    // tester si c'est une page en squelette
2275
+    if (trouver_fond($nom, 'prive/squelettes/contenu/'))
2276
+        return $exec[$nom] = 'fond';
2277
+    // compat skels orthogonaux version precedente
2278
+    elseif (trouver_fond($nom, 'prive/exec/'))
2279
+        return $exec[$nom] = 'fond_monobloc';
2280
+    // echafaudage d'un fond !
2281
+    elseif(include_spip('public/styliser_par_z') AND z_echafaudable($nom))
2282
+        return $exec[$nom] = 'fond';
2283
+    // attention, il ne faut pas inclure l'exec ici
2284
+    // car sinon #URL_ECRIRE provoque des inclusions
2285
+    // et des define intrusifs potentiels
2286
+    return $exec[$nom] = ((find_in_path("{$nom}.php",'exec/') OR charger_fonction($nom,'exec',true))?$nom:'');
2288 2287
 }
2289 2288
 
2290 2289
 // Charger dynamiquement une extension php
2291 2290
 // http://doc.spip.org/@charger_php_extension
2292 2291
 function charger_php_extension($module) {
2293
-	if (extension_loaded($module)) {
2294
-		return true;
2295
-	} else {
2296
-		$charger_php_extension = charger_fonction('charger_php_extension','inc');
2297
-		return $charger_php_extension($module);
2298
-	}
2292
+    if (extension_loaded($module)) {
2293
+        return true;
2294
+    } else {
2295
+        $charger_php_extension = charger_fonction('charger_php_extension','inc');
2296
+        return $charger_php_extension($module);
2297
+    }
2299 2298
 }
2300 2299
 
2301 2300
 // Renvoie TRUE si et seulement si la configuration autorise
2302 2301
 // le code HTML5 sur le site public
2303 2302
 function html5_permis() {
2304 2303
         return (isset($GLOBALS['meta']['version_html_max'])
2305
-		AND ('html5' == $GLOBALS['meta']['version_html_max']));
2304
+        AND ('html5' == $GLOBALS['meta']['version_html_max']));
2306 2305
 }
2307 2306
 
2308 2307
 /*
@@ -2313,7 +2312,7 @@  discard block
 block discarded – undo
2313 2312
 // Fonction depreciee
2314 2313
 // http://doc.spip.org/@lire_meta
2315 2314
 function lire_meta($nom) {
2316
-	return $GLOBALS['meta'][$nom];
2315
+    return $GLOBALS['meta'][$nom];
2317 2316
 }
2318 2317
 
2319 2318
 // Fonction depreciee
@@ -2323,15 +2322,15 @@  discard block
 block discarded – undo
2323 2322
 // Fonction depreciee, cf. http://doc.spip.org/@sql_fetch
2324 2323
 // http://doc.spip.org/@spip_fetch_array
2325 2324
 function spip_fetch_array($r, $t=NULL) {
2326
-	if (!isset($t)) {
2327
-		if ($r) return sql_fetch($r);
2328
-	} else {
2329
-		if ($t=='SPIP_NUM') $t = MYSQL_NUM;
2330
-		if ($t=='SPIP_BOTH') $t = MYSQL_BOTH;
2331
-		if ($t=='SPIP_ASSOC') $t = MYSQL_ASSOC;
2332
-		spip_log("appel deprecie de spip_fetch_array(..., $t)", 'vieilles_defs');
2333
-		if ($r) return mysql_fetch_array($r, $t);
2334
-	}
2325
+    if (!isset($t)) {
2326
+        if ($r) return sql_fetch($r);
2327
+    } else {
2328
+        if ($t=='SPIP_NUM') $t = MYSQL_NUM;
2329
+        if ($t=='SPIP_BOTH') $t = MYSQL_BOTH;
2330
+        if ($t=='SPIP_ASSOC') $t = MYSQL_ASSOC;
2331
+        spip_log("appel deprecie de spip_fetch_array(..., $t)", 'vieilles_defs');
2332
+        if ($r) return mysql_fetch_array($r, $t);
2333
+    }
2335 2334
 }
2336 2335
 
2337 2336
 /**
@@ -2345,14 +2344,14 @@  discard block
 block discarded – undo
2345 2344
  * @param string $statut
2346 2345
  */
2347 2346
 function avertir_auteurs($nom,$message, $statut=''){
2348
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
2349
-	if (!$alertes
2350
-		OR !is_array($alertes = unserialize($alertes)))
2351
-		$alertes = array();
2352
-
2353
-	if (!isset($alertes[$statut]))
2354
-		$alertes[$statut] = array();
2355
-	$alertes[$statut][$nom] = $message;
2356
-	ecrire_meta("message_alertes_auteurs",serialize($alertes));
2347
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
2348
+    if (!$alertes
2349
+        OR !is_array($alertes = unserialize($alertes)))
2350
+        $alertes = array();
2351
+
2352
+    if (!isset($alertes[$statut]))
2353
+        $alertes[$statut] = array();
2354
+    $alertes[$statut][$nom] = $message;
2355
+    ecrire_meta("message_alertes_auteurs",serialize($alertes));
2357 2356
 }
2358 2357
 ?>
Please login to merge, or discard this patch.
Spacing   +342 added lines, -345 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);
@@ -487,8 +486,8 @@  discard block
 block discarded – undo
487 486
  * @param string $plugin
488 487
  * @return bool
489 488
  */
490
-function test_plugin_actif($plugin){
491
-	return ($plugin AND defined('_DIR_PLUGIN_'.strtoupper($plugin)))? true:false;
489
+function test_plugin_actif($plugin) {
490
+	return ($plugin AND defined('_DIR_PLUGIN_'.strtoupper($plugin))) ? true:false;
492 491
 }
493 492
 
494 493
 /**
@@ -502,14 +501,14 @@  discard block
 block discarded – undo
502 501
  *   bool force : forcer un retour meme si la chaine n'a pas de traduction
503 502
  * @return mixed|string
504 503
  */
505
-function _T($texte, $args=array(), $options=array()) {
506
-	static $traduire=false ;
504
+function _T($texte, $args = array(), $options = array()) {
505
+	static $traduire = false;
507 506
 	$o = array('class'=>'', 'force'=>true);
508
-	if ($options){
507
+	if ($options) {
509 508
 		// support de l'ancien argument $class
510 509
 		if (is_string($options))
511 510
 			$options = array('class'=>$options);
512
-		$o = array_merge($o,$options);
511
+		$o = array_merge($o, $options);
513 512
 	}
514 513
 
515 514
  	if (!$traduire) {
@@ -519,7 +518,7 @@  discard block
 block discarded – undo
519 518
 	
520 519
 	// On peut passer explicitement la langue dans le tableau
521 520
 	// On utilise le même nom de variable que la globale
522
-	if (isset($args['spip_lang'])){
521
+	if (isset($args['spip_lang'])) {
523 522
 		$lang = $args['spip_lang'];
524 523
 		// On l'enleve pour ne pas le passer au remplacement
525 524
 		unset($args['spip_lang']);
@@ -530,7 +529,7 @@  discard block
 block discarded – undo
530 529
 	}
531 530
 	$text = $traduire($texte, $lang);
532 531
 
533
-	if (!strlen($text)){
532
+	if (!strlen($text)) {
534 533
 		if (!$o['force'])
535 534
 			return '';
536 535
 
@@ -539,8 +538,7 @@  discard block
 block discarded – undo
539 538
 		// pour les chaines non traduites, assurer un service minimum
540 539
 		if (!$GLOBALS['test_i18n'] AND (_request('var_mode') != 'traduction'))
541 540
 			$text = str_replace('_', ' ',
542
-				 (($n = strpos($text,':')) === false ? $texte :
543
-					substr($texte, $n+1)));
541
+				 (($n = strpos($text, ':')) === false ? $texte : substr($texte, $n + 1)));
544 542
 		$o['class'] = null;
545 543
 
546 544
 	}
@@ -552,21 +550,21 @@  discard block
 block discarded – undo
552 550
 // Remplacer les variables @....@ par leur valeur dans une chaine de langue.
553 551
 // Aussi appelee quand une chaine n'est pas encore dans les fichiers de langue
554 552
 // http://doc.spip.org/@_L
555
-function _L($text, $args=array(), $class=null) {
553
+function _L($text, $args = array(), $class = null) {
556 554
 	$f = $text;
557 555
 	if (is_array($args)) {
558 556
 		foreach ($args as $name => $value) {
559 557
 			if ($class)
560 558
 				$value = "<span class='$class'>$value</span>";
561
-			$t = str_replace ("@$name@", $value, $text);
562
-			if ($text !== $t) {unset($args[$name]); $text = $t;}
559
+			$t = str_replace("@$name@", $value, $text);
560
+			if ($text !== $t) {unset($args[$name]); $text = $t; }
563 561
 		}
564 562
 		// Si des variables n'ont pas ete inserees, le signaler
565 563
 		// (chaines de langues pas a jour)
566
-		if ($args) spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)),_LOG_DEBUG);
564
+		if ($args) spip_log("$f:  variables inutilisees ".join(', ', array_keys($args)), _LOG_DEBUG);
567 565
 	}
568 566
 
569
-	if (($GLOBALS['test_i18n'] OR (_request('var_mode') == 'traduction')) AND $class===null)
567
+	if (($GLOBALS['test_i18n'] OR (_request('var_mode') == 'traduction')) AND $class === null)
570 568
 		return "<span class=debug-traduction-erreur>$text</span>";
571 569
 	else
572 570
 		return $text;
@@ -576,9 +574,9 @@  discard block
 block discarded – undo
576 574
 // ou tmp/ au lieu de ../tmp/
577 575
 // http://doc.spip.org/@joli_repertoire
578 576
 function joli_repertoire($rep) {
579
-	$a = substr($rep,0,1);
580
-	if ($a<>'.' AND $a<>'/')
581
-		$rep = (_DIR_RESTREINT?'':_DIR_RESTREINT_ABS).$rep;
577
+	$a = substr($rep, 0, 1);
578
+	if ($a <> '.' AND $a <> '/')
579
+		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS).$rep;
582 580
 	$rep = preg_replace(',(^\.\.\/),', '', $rep);
583 581
 	return $rep;
584 582
 }
@@ -588,12 +586,12 @@  discard block
 block discarded – undo
588 586
 // spip_timer : on l'appelle deux fois et on a la difference, affichable
589 587
 //
590 588
 // http://doc.spip.org/@spip_timer
591
-function spip_timer($t='rien', $raw = false) {
589
+function spip_timer($t = 'rien', $raw = false) {
592 590
 	static $time;
593
-	$a=time(); $b=microtime();
591
+	$a = time(); $b = microtime();
594 592
 	// microtime peut contenir les microsecondes et le temps
595
-	$b=explode(' ',$b);
596
-	if (count($b)==2) $a = end($b); // plus precis !
593
+	$b = explode(' ', $b);
594
+	if (count($b) == 2) $a = end($b); // plus precis !
597 595
 	$b = reset($b);
598 596
 	if (!isset($time[$t])) {
599 597
 		$time[$t] = $a + $b;
@@ -605,10 +603,10 @@  discard block
 block discarded – undo
605 603
 		if ($p < 1000)
606 604
 			$s = '';
607 605
 		else {
608
-			$s = sprintf("%d ", $x = floor($p/1000));
609
-			$p -= ($x*1000);
606
+			$s = sprintf("%d ", $x = floor($p / 1000));
607
+			$p -= ($x * 1000);
610 608
 		}
611
-		return $s . sprintf($s?"%07.3f ms":"%.3f ms", $p);
609
+		return $s.sprintf($s ? "%07.3f ms" : "%.3f ms", $p);
612 610
 	}
613 611
 }
614 612
 
@@ -616,13 +614,13 @@  discard block
 block discarded – undo
616 614
 // Renvoie False si un fichier n'est pas plus vieux que $duree secondes,
617 615
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
618 616
 // http://doc.spip.org/@spip_touch
619
-function spip_touch($fichier, $duree=0, $touch=true) {
617
+function spip_touch($fichier, $duree = 0, $touch = true) {
620 618
 	if ($duree) {
621 619
 		clearstatcache();
622
-		if ((@$f=filemtime($fichier)) AND ($f >= time() - $duree))
620
+		if ((@$f = filemtime($fichier)) AND ($f >= time() - $duree))
623 621
 			return false;
624 622
 	}
625
-	if ($touch!==false) {
623
+	if ($touch !== false) {
626 624
 		if (!@touch($fichier)) { spip_unlink($fichier); @touch($fichier); };
627 625
 		@chmod($fichier, _SPIP_CHMOD & ~0111);
628 626
 	}
@@ -641,7 +639,7 @@  discard block
 block discarded – undo
641 639
 	include_spip('inc/headers');
642 640
 	http_status(204); // No Content
643 641
 	header("Connection: close");
644
-	define('_DIRECT_CRON_FORCE',true);
642
+	define('_DIRECT_CRON_FORCE', true);
645 643
 	cron();
646 644
 }
647 645
 
@@ -661,7 +659,7 @@  discard block
 block discarded – undo
661 659
  *   taches forcees, pour compat avec ancienne syntaxe
662 660
  * @return bool
663 661
  */
664
-function cron ($taches=array(), $taches_old= array()) {
662
+function cron($taches = array(), $taches_old = array()) {
665 663
 	// si pas en mode cron force, laisser tomber.
666 664
 	if (!defined('_DIRECT_CRON_FORCE')) return false;
667 665
 	if (!is_array($taches)) $taches = $taches_old; // compat anciens appels
@@ -670,7 +668,7 @@  discard block
 block discarded – undo
670 668
 	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
671 669
 	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
672 670
 	if ($taches AND count($taches) AND !spip_connect())  return false;
673
-	spip_log("cron !",'jq'._LOG_DEBUG);
671
+	spip_log("cron !", 'jq'._LOG_DEBUG);
674 672
 	if ($genie = charger_fonction('genie', 'inc', true)) {
675 673
 		return $genie($taches);
676 674
 	}
@@ -699,7 +697,7 @@  discard block
 block discarded – undo
699 697
  * @return int
700 698
  *	id of job
701 699
  */
702
-function job_queue_add($function, $description, $arguments = array(), $file = '', $no_duplicate = FALSE, $time=0, $priority=0) {
700
+function job_queue_add($function, $description, $arguments = array(), $file = '', $no_duplicate = FALSE, $time = 0, $priority = 0) {
703 701
 	include_spip('inc/queue');
704 702
 	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
705 703
 }
@@ -710,7 +708,7 @@  discard block
 block discarded – undo
710 708
  *  id of jonb to delete
711 709
  * @return bool
712 710
  */
713
-function job_queue_remove($id_job){
711
+function job_queue_remove($id_job) {
714 712
 	include_spip('inc/queue');
715 713
 	return queue_remove_job($id_job);
716 714
 }
@@ -723,9 +721,9 @@  discard block
 block discarded – undo
723 721
  *  can be a simple array('objet'=>'article','id_objet'=>23)
724 722
  *  or an array of simple array to link multiples objet in one time
725 723
  */
726
-function job_queue_link($id_job,$objets){
724
+function job_queue_link($id_job, $objets) {
727 725
 	include_spip('inc/queue');
728
-	return queue_link_job($id_job,$objets);
726
+	return queue_link_job($id_job, $objets);
729 727
 }
730 728
 
731 729
 
@@ -741,15 +739,15 @@  discard block
 block discarded – undo
741 739
  * @param int/bool $force_next
742 740
  * @return int
743 741
  */
744
-function queue_sleep_time_to_next_job($force=null) {
742
+function queue_sleep_time_to_next_job($force = null) {
745 743
 	static $queue_next_job_time = -1;
746
-	if ($force===true)
744
+	if ($force === true)
747 745
 		$queue_next_job_time = -1;
748 746
 	elseif ($force)
749 747
 		$queue_next_job_time = $force;
750 748
 
751
-	if ($queue_next_job_time==-1) {
752
-		define('_JQ_NEXT_JOB_TIME_FILENAME',_DIR_TMP . "job_queue_next.txt");
749
+	if ($queue_next_job_time == -1) {
750
+		define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP."job_queue_next.txt");
753 751
 		// utiliser un cache memoire si dispo
754 752
 		if (include_spip('inc/memoization') AND defined('_MEMOIZE_MEMORY') AND _MEMOIZE_MEMORY) {
755 753
 			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
@@ -765,7 +763,7 @@  discard block
 block discarded – undo
765 763
 		return null;
766 764
 	if (!$_SERVER['REQUEST_TIME'])
767 765
 		$_SERVER['REQUEST_TIME'] = time();
768
-	return $queue_next_job_time-$_SERVER['REQUEST_TIME'];
766
+	return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
769 767
 }
770 768
 
771 769
 
@@ -774,23 +772,23 @@  discard block
 block discarded – undo
774 772
 function quote_amp($u) {
775 773
 	return preg_replace(
776 774
 		"/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,5};)/i",
777
-		"&amp;",$u);
775
+		"&amp;", $u);
778 776
 }
779 777
 
780 778
 // Production d'une balise Script valide
781 779
 // http://doc.spip.org/@http_script
782
-function http_script($script, $src='', $noscript='') {
780
+function http_script($script, $src = '', $noscript = '') {
783 781
 	static $done = array();
784 782
 
785
-	if ($src && !isset($done[$src])){
783
+	if ($src && !isset($done[$src])) {
786 784
 		$done[$src] = true;
787 785
 		$src = find_in_path($src, _JAVASCRIPT);
788 786
 		$src = " src='$src'";
789 787
 	}
790 788
 	else $src = '';
791 789
 	if ($script)
792
-		$script = ("/*<![CDATA[*/\n" .
793
-		preg_replace(',</([^>]*)>,','<\/\1>', $script) .
790
+		$script = ("/*<![CDATA[*/\n".
791
+		preg_replace(',</([^>]*)>,', '<\/\1>', $script).
794 792
 		"/*]]>*/");
795 793
 	if ($noscript)
796 794
 		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
@@ -815,10 +813,10 @@  discard block
 block discarded – undo
815 813
 // du path, dans cet ordre.
816 814
 // Exception: si un $dossier_squelette est defini, il reste en tete, pour raison historique
817 815
 // http://doc.spip.org/@_chemin
818
-function _chemin($dir_path=NULL){
816
+function _chemin($dir_path = NULL) {
819 817
 	static $path_base = NULL;
820 818
 	static $path_full = NULL;
821
-	if ($path_base==NULL){
819
+	if ($path_base == NULL) {
822 820
 		// Chemin standard depuis l'espace public
823 821
 		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
824 822
 			_DIR_RACINE.':'.
@@ -827,9 +825,9 @@  discard block
 block discarded – undo
827 825
 			_DIR_RESTREINT;
828 826
 		// Ajouter squelettes/
829 827
 		if (@is_dir(_DIR_RACINE.'squelettes'))
830
-			$path = _DIR_RACINE.'squelettes/:' . $path;
828
+			$path = _DIR_RACINE.'squelettes/:'.$path;
831 829
 		foreach (explode(':', $path) as $dir) {
832
-			if (strlen($dir) AND substr($dir,-1) != '/')
830
+			if (strlen($dir) AND substr($dir, -1) != '/')
833 831
 				$dir .= "/";
834 832
 			$path_base[] = $dir;
835 833
 		}
@@ -837,32 +835,32 @@  discard block
 block discarded – undo
837 835
 		// Et le(s) dossier(s) des squelettes nommes
838 836
 		if (strlen($GLOBALS['dossier_squelettes']))
839 837
 			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
840
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
838
+				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE).$d.'/');
841 839
 		$GLOBALS['path_sig'] = md5(serialize($path_full));
842 840
 	}
843
-	if ($dir_path===NULL) return $path_full;
841
+	if ($dir_path === NULL) return $path_full;
844 842
 
845
-	if (strlen($dir_path)){
843
+	if (strlen($dir_path)) {
846 844
 		$tete = "";
847
-		if (reset($path_base)==_DIR_RACINE.'squelettes/')
845
+		if (reset($path_base) == _DIR_RACINE.'squelettes/')
848 846
 			$tete = array_shift($path_base);
849
-		$dirs = array_reverse(explode(':',$dir_path));
850
-		foreach($dirs as $dir_path){
847
+		$dirs = array_reverse(explode(':', $dir_path));
848
+		foreach ($dirs as $dir_path) {
851 849
 				#if ($dir_path{0}!='/')
852 850
 				#	$dir_path = $dir_path;
853
-				if (substr($dir_path,-1) != '/')
851
+				if (substr($dir_path, -1) != '/')
854 852
 					$dir_path .= "/";
855
-				if (!in_array($dir_path,$path_base))
856
-					array_unshift($path_base,$dir_path);
853
+				if (!in_array($dir_path, $path_base))
854
+					array_unshift($path_base, $dir_path);
857 855
 		}
858 856
 		if (strlen($tete))
859
-			array_unshift($path_base,$tete);
857
+			array_unshift($path_base, $tete);
860 858
 	}
861 859
 	$path_full = $path_base;
862 860
 	// Et le(s) dossier(s) des squelettes nommes
863 861
 	if (strlen($GLOBALS['dossier_squelettes']))
864 862
 		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
865
-			array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
863
+			array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE).$d.'/');
866 864
 
867 865
 	$GLOBALS['path_sig'] = md5(serialize($path_full));
868 866
 	return $path_full;
@@ -883,9 +881,9 @@  discard block
 block discarded – undo
883 881
 }
884 882
 
885 883
 
886
-function lister_themes_prives(){
884
+function lister_themes_prives() {
887 885
 	static $themes = null;
888
-	if (is_null($themes)){
886
+	if (is_null($themes)) {
889 887
 		// si pas encore definie
890 888
 		if (!defined('_SPIP_THEME_PRIVE'))
891 889
 			define('_SPIP_THEME_PRIVE', 'spip');
@@ -902,20 +900,20 @@  discard block
 block discarded – undo
902 900
 			((isset($prefs['theme']) AND $theme = $prefs['theme'])
903 901
 			OR (isset($GLOBALS['theme_prive_defaut']) AND $theme = $GLOBALS['theme_prive_defaut']))
904 902
 			AND $theme != _SPIP_THEME_PRIVE)
905
-			array_unshift($themes,$theme); // placer le theme choisi en tete
903
+			array_unshift($themes, $theme); // placer le theme choisi en tete
906 904
 	}
907 905
 	return $themes;
908 906
 }
909 907
 
910
-function find_in_theme($file, $subdir='', $include=false){
911
-	static $themefiles=array();
908
+function find_in_theme($file, $subdir = '', $include = false) {
909
+	static $themefiles = array();
912 910
 	if (isset($themefiles["$subdir$file"])) return $themefiles["$subdir$file"];
913 911
 	$themes = lister_themes_prives();
914
-	foreach($themes as $theme){
915
-		if ($f = find_in_path($file,"prive/themes/$theme/$subdir",$include))
912
+	foreach ($themes as $theme) {
913
+		if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include))
916 914
 			return $themefiles["$subdir$file"] = $f;
917 915
 	}
918
-	spip_log("$file introuvable dans le theme prive ".reset($themes),'theme');
916
+	spip_log("$file introuvable dans le theme prive ".reset($themes), 'theme');
919 917
 	return $themefiles["$subdir$file"] = "";
920 918
 }
921 919
 
@@ -925,23 +923,23 @@  discard block
 block discarded – undo
925 923
 // peut se trouver dans un dossier plugin, donc on passe par un find_in_path si elle n'est pas
926 924
 // dans _DIR_IMG_PACK
927 925
 // http://doc.spip.org/@chemin_image
928
-function chemin_image($icone){
926
+function chemin_image($icone) {
929 927
 	static $icone_renommer;
930 928
 	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
931
-	if (strpos($icone,"/")!==false AND file_exists($icone)) return $icone;
929
+	if (strpos($icone, "/") !== false AND file_exists($icone)) return $icone;
932 930
 	
933 931
 	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
934
-	if (preg_match(',[.](png|gif|jpg)$,',$icone) AND $f = find_in_theme("images/$icone"))
932
+	if (preg_match(',[.](png|gif|jpg)$,', $icone) AND $f = find_in_theme("images/$icone"))
935 933
 		return $f;
936 934
 	// sinon passer par le module de renommage
937 935
 	if (is_null($icone_renommer))
938
-		$icone_renommer = charger_fonction('icone_renommer','inc',true);
939
-	if ($icone_renommer){
940
-		list($icone,$fonction) = $icone_renommer($icone,"");
936
+		$icone_renommer = charger_fonction('icone_renommer', 'inc', true);
937
+	if ($icone_renommer) {
938
+		list($icone, $fonction) = $icone_renommer($icone, "");
941 939
 		if (file_exists($icone))
942 940
 			return $icone;
943 941
 	}
944
-	return find_in_path ($icone, _NOM_IMG_PACK);
942
+	return find_in_path($icone, _NOM_IMG_PACK);
945 943
 }
946 944
 
947 945
 //
@@ -952,13 +950,13 @@  discard block
 block discarded – undo
952 950
 $GLOBALS['path_files'] = null;
953 951
 
954 952
 // http://doc.spip.org/@find_in_path
955
-function find_in_path ($file, $dirname='', $include=false) {
956
-	static $dirs=array();
953
+function find_in_path($file, $dirname = '', $include = false) {
954
+	static $dirs = array();
957 955
 	static $inc = array(); # cf http://trac.rezo.net/trac/spip/changeset/14743
958 956
 	static $c = '';
959 957
 
960 958
 	// on calcule le chemin si le dossier skel a change
961
-	if ($c != $GLOBALS['dossier_squelettes']){
959
+	if ($c != $GLOBALS['dossier_squelettes']) {
962 960
 		// assurer le non plantage lors de la montee de version :
963 961
 		$c = $GLOBALS['dossier_squelettes'];
964 962
 		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
@@ -968,40 +966,40 @@  discard block
 block discarded – undo
968 966
 		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])
969 967
 			return false;
970 968
 		if ($include AND !isset($inc[$dirname][$file])) {
971
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
972
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
969
+			include_once _ROOT_CWD.$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
970
+			$inc[$dirname][$file] = $inc[''][$dirname.$file] = true;
973 971
 		}
974 972
 		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
975 973
 	}
976 974
 
977
-	$a = strrpos($file,'/');
975
+	$a = strrpos($file, '/');
978 976
 	if ($a !== false) {
979 977
 		$dirname .= substr($file, 0, ++$a);
980 978
 		$file = substr($file, $a);
981 979
 	}
982 980
 
983
-	foreach(creer_chemin() as $dir) {
984
-		if (!isset($dirs[$a = $dir . $dirname]))
985
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a) ;
981
+	foreach (creer_chemin() as $dir) {
982
+		if (!isset($dirs[$a = $dir.$dirname]))
983
+			$dirs[$a] = (is_dir(_ROOT_CWD.$a) || !$a);
986 984
 		if ($dirs[$a]) {
987
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
985
+			if (file_exists(_ROOT_CWD.($a .= $file))) {
988 986
 				if ($include AND !isset($inc[$dirname][$file])) {
989
-					include_once _ROOT_CWD . $a;
990
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
987
+					include_once _ROOT_CWD.$a;
988
+					$inc[$dirname][$file] = $inc[''][$dirname.$file] = true;
991 989
 				}
992
-				if (!defined('_SAUVER_CHEMIN')){
990
+				if (!defined('_SAUVER_CHEMIN')) {
993 991
 					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
994 992
 					if (is_null($GLOBALS['path_files'])) return $a;
995 993
 					define('_SAUVER_CHEMIN', true);
996 994
 				}
997
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
995
+				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname.$file] = $a;
998 996
 			}
999 997
 		}
1000 998
 	}
1001 999
 
1002
-	if ($include){
1000
+	if ($include) {
1003 1001
 		spip_log("include_spip $dirname$file non trouve");
1004
-		if ($include==='required'){
1002
+		if ($include === 'required') {
1005 1003
 			echo '<pre>',
1006 1004
 			"<strong>Erreur Fatale</strong><br />";
1007 1005
 			if (function_exists('debug_print_backtrace'))
@@ -1011,21 +1009,21 @@  discard block
 block discarded – undo
1011 1009
 		}
1012 1010
 	}
1013 1011
 
1014
-	if (!defined('_SAUVER_CHEMIN')){
1012
+	if (!defined('_SAUVER_CHEMIN')) {
1015 1013
 		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1016 1014
 		if (is_null($GLOBALS['path_files'])) return false;
1017 1015
 		define('_SAUVER_CHEMIN', true);
1018 1016
 	}
1019
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1017
+	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname.$file] = false;
1020 1018
 }
1021 1019
 
1022
-function clear_path_cache(){
1020
+function clear_path_cache() {
1023 1021
 	$GLOBALS['path_files'] = array();
1024 1022
 	spip_unlink(_CACHE_CHEMIN);
1025 1023
 }
1026
-function load_path_cache(){
1024
+function load_path_cache() {
1027 1025
 	// charger le path des plugins
1028
-	if (@is_readable(_CACHE_PLUGINS_PATH)){
1026
+	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1029 1027
 		include_once(_CACHE_PLUGINS_PATH);
1030 1028
 	}
1031 1029
 	$GLOBALS['path_files'] = array();
@@ -1039,23 +1037,23 @@  discard block
 block discarded – undo
1039 1037
 		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1040 1038
 		// et en ignorant ce cache en cas de recalcul explicite
1041 1039
 		!_request('var_mode')
1042
-		){
1040
+		) {
1043 1041
 		// on essaye de lire directement sans verrou pour aller plus vite
1044
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)){
1042
+		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1045 1043
 			// mais si semble corrompu on relit avec un verrou
1046
-			if (!$GLOBALS['path_files']=unserialize($contenu)){
1047
-				lire_fichier(_CACHE_CHEMIN,$contenu);
1048
-				if (!$GLOBALS['path_files']=unserialize($contenu))
1044
+			if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1045
+				lire_fichier(_CACHE_CHEMIN, $contenu);
1046
+				if (!$GLOBALS['path_files'] = unserialize($contenu))
1049 1047
 					$GLOBALS['path_files'] = array();
1050 1048
 			}
1051 1049
 		}
1052 1050
 	}
1053 1051
 }
1054 1052
 
1055
-function save_path_cache(){
1053
+function save_path_cache() {
1056 1054
 	if (defined('_SAUVER_CHEMIN')
1057 1055
 		AND _SAUVER_CHEMIN)
1058
-		ecrire_fichier(_CACHE_CHEMIN,serialize($GLOBALS['path_files']));
1056
+		ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1059 1057
 }
1060 1058
 
1061 1059
 
@@ -1070,16 +1068,16 @@  discard block
 block discarded – undo
1070 1068
  * @return array
1071 1069
  */
1072 1070
 // http://doc.spip.org/@find_all_in_path
1073
-function find_all_in_path($dir,$pattern, $recurs=false){
1074
-	$liste_fichiers=array();
1071
+function find_all_in_path($dir, $pattern, $recurs = false) {
1072
+	$liste_fichiers = array();
1075 1073
 	$maxfiles = 10000;
1076 1074
 
1077 1075
 	// Parcourir le chemin
1078 1076
 	foreach (creer_chemin() as $d) {
1079 1077
 		$f = $d.$dir;
1080
-		if (@is_dir($f)){
1081
-			$liste = preg_files($f,$pattern,$maxfiles-count($liste_fichiers),$recurs===true?array():$recurs);
1082
-			foreach($liste as $chemin){
1078
+		if (@is_dir($f)) {
1079
+			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? array() : $recurs);
1080
+			foreach ($liste as $chemin) {
1083 1081
 				$nom = basename($chemin);
1084 1082
 				// ne prendre que les fichiers pas deja trouves
1085 1083
 				// car find_in_path prend le premier qu'il trouve,
@@ -1126,7 +1124,7 @@  discard block
 block discarded – undo
1126 1124
  *   array : derogatoire, la fonction d'url retourne (objet,id_objet) utilises par nettoyer_raccourcis_typo() pour generer un lien titre
1127 1125
  *           (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_url_spip et une fonction generer_url_ecrire_spip)
1128 1126
  */
1129
-function generer_url_entite($id='', $entite='', $args='', $ancre='', $public=NULL, $type=NULL)
1127
+function generer_url_entite($id = '', $entite = '', $args = '', $ancre = '', $public = NULL, $type = NULL)
1130 1128
 {
1131 1129
 	if ($public === NULL) $public = !test_espace_prive();
1132 1130
 	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
@@ -1135,12 +1133,12 @@  discard block
 block discarded – undo
1135 1133
 		if (!$entite) return '';
1136 1134
 		if (!function_exists('generer_url_ecrire_objet'))
1137 1135
 			include_spip('inc/urls');
1138
-		$res = generer_url_ecrire_objet($entite,$id, $args, $ancre, false);
1136
+		$res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false);
1139 1137
 	} else {
1140 1138
 		if ($type === NULL) {
1141 1139
 			$type = ($GLOBALS['type_urls'] === 'page'
1142 1140
 				AND $GLOBALS['meta']['type_urls'])
1143
-			?  $GLOBALS['meta']['type_urls']
1141
+			? $GLOBALS['meta']['type_urls']
1144 1142
 			:  $GLOBALS['type_urls']; // pour SPIP <2
1145 1143
 		}
1146 1144
 
@@ -1163,7 +1161,7 @@  discard block
 block discarded – undo
1163 1161
 	}
1164 1162
 	if ($res) return $res;
1165 1163
 	// Sinon c'est un raccourci ou compat SPIP < 2
1166
-	if (!function_exists($f = 'generer_url_' . $entite)) {
1164
+	if (!function_exists($f = 'generer_url_'.$entite)) {
1167 1165
 		if (!function_exists($f .= '_dist')) $f = '';
1168 1166
 	}
1169 1167
 	if ($f) {
@@ -1179,23 +1177,23 @@  discard block
 block discarded – undo
1179 1177
 	return '';
1180 1178
 }
1181 1179
 
1182
-function generer_url_ecrire_entite_edit($id, $entite, $args='', $ancre=''){
1183
-	$exec = objet_info($entite,'url_edit');
1184
-	$url = generer_url_ecrire($exec,$args);
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);
1185 1183
 	if (intval($id))
1186
-		$url = parametre_url($url,id_table_objet($entite),$id);
1184
+		$url = parametre_url($url, id_table_objet($entite), $id);
1187 1185
 	else
1188
-		$url = parametre_url($url,'new','oui');
1186
+		$url = parametre_url($url, 'new', 'oui');
1189 1187
 	if ($ancre)
1190
-		$url = ancre_url($url,$ancre);
1188
+		$url = ancre_url($url, $ancre);
1191 1189
 	return $url;
1192 1190
 }
1193 1191
 
1194 1192
 // http://doc.spip.org/@urls_connect_dist
1195
-function urls_connect_dist($i, &$entite, $args='', $ancre='', $public=null) {
1193
+function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) {
1196 1194
 	include_spip('base/connect_sql');
1197
-	$id_type = id_table_objet($entite,$public);
1198
-	return _DIR_RACINE . get_spip_script('./')
1195
+	$id_type = id_table_objet($entite, $public);
1196
+	return _DIR_RACINE.get_spip_script('./')
1199 1197
 	  . "?"._SPIP_PAGE."=$entite&$id_type=$i&connect=$public"
1200 1198
 	  . (!$args ? '' : "&$args")
1201 1199
 	  . (!$ancre ? '' : "#$ancre");
@@ -1204,9 +1202,9 @@  discard block
 block discarded – undo
1204 1202
 
1205 1203
 // Transformer les caracteres utf8 d'une URL (farsi par ex) selon la RFC 1738
1206 1204
 function urlencode_1738($url) {
1207
-	if (preg_match(',[^\x00-\x7E],sS', $url)){
1205
+	if (preg_match(',[^\x00-\x7E],sS', $url)) {
1208 1206
 		$uri = '';
1209
-		for ($i=0; $i < strlen($url); $i++) {
1207
+		for ($i = 0; $i < strlen($url); $i++) {
1210 1208
 			if (ord($a = $url[$i]) > 127)
1211 1209
 				$a = rawurlencode($a);
1212 1210
 			$uri .= $a;
@@ -1217,7 +1215,7 @@  discard block
 block discarded – undo
1217 1215
 }
1218 1216
 
1219 1217
 // http://doc.spip.org/@generer_url_entite_absolue
1220
-function generer_url_entite_absolue($id='', $entite='', $args='', $ancre='', $connect=NULL)
1218
+function generer_url_entite_absolue($id = '', $entite = '', $args = '', $ancre = '', $connect = NULL)
1221 1219
 {
1222 1220
 	if (!$connect) $connect = true;
1223 1221
 	$h = generer_url_entite($id, $entite, $args, $ancre, $connect);
@@ -1256,11 +1254,11 @@  discard block
 block discarded – undo
1256 1254
  *    si array : reinitialise le tableau static complet avec la valeur fournie
1257 1255
  * @return string|array
1258 1256
  */
1259
-function url_de_base($profondeur=null) {
1257
+function url_de_base($profondeur = null) {
1260 1258
 
1261 1259
 	static $url = array();
1262 1260
 	if (is_array($profondeur)) return $url = $profondeur;
1263
-	if ($profondeur===false) return $url;
1261
+	if ($profondeur === false) return $url;
1264 1262
 
1265 1263
 	if (is_null($profondeur)) $profondeur = $GLOBALS['profondeur_url'];
1266 1264
 
@@ -1269,7 +1267,7 @@  discard block
 block discarded – undo
1269 1267
 
1270 1268
 	$http = (
1271 1269
 		(isset($_SERVER["SCRIPT_URI"]) AND
1272
-			substr($_SERVER["SCRIPT_URI"],0,5) == 'https')
1270
+			substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https')
1273 1271
 		OR (isset($_SERVER['HTTPS']) AND
1274 1272
 		    test_valeur_serveur($_SERVER['HTTPS']))
1275 1273
 	) ? 'https' : 'http';
@@ -1284,12 +1282,12 @@  discard block
 block discarded – undo
1284 1282
 		}
1285 1283
 	}
1286 1284
 	if (isset($_SERVER['SERVER_PORT'])
1287
-		AND $port=$_SERVER['SERVER_PORT']
1288
-		AND strpos($host,":")==false){
1289
-		if ($http=="http" AND $port!=80) $host.=":$port";
1290
-		if ($http=="https" AND $port!=443) $host.=":$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";
1291 1289
 	}
1292
-	if (!$GLOBALS['REQUEST_URI']){
1290
+	if (!$GLOBALS['REQUEST_URI']) {
1293 1291
 		if (isset($_SERVER['REQUEST_URI'])) {
1294 1292
 			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1295 1293
 		} else {
@@ -1300,7 +1298,7 @@  discard block
 block discarded – undo
1300 1298
 		}
1301 1299
 	}
1302 1300
 
1303
-	$url[$profondeur] = url_de_($http,$host,$GLOBALS['REQUEST_URI'],$profondeur);
1301
+	$url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
1304 1302
 
1305 1303
 	return $url[$profondeur];
1306 1304
 }
@@ -1312,25 +1310,25 @@  discard block
 block discarded – undo
1312 1310
  * @param int $prof
1313 1311
  * @return string
1314 1312
  */
1315
-function url_de_($http,$host,$request,$prof=0){
1316
-	$prof = max($prof,0);
1313
+function url_de_($http, $host, $request, $prof = 0) {
1314
+	$prof = max($prof, 0);
1317 1315
 
1318
-	$myself = ltrim($request,'/');
1316
+	$myself = ltrim($request, '/');
1319 1317
 	# supprimer la chaine de GET
1320 1318
 	list($myself) = explode('?', $myself);
1321 1319
 	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
1322 1320
 	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
1323
-	if (strpos($myself,'://') !== false) {
1324
-		$myself = explode('://',$myself);
1321
+	if (strpos($myself, '://') !== false) {
1322
+		$myself = explode('://', $myself);
1325 1323
 		array_shift($myself);
1326
-		$myself = implode('://',$myself);
1327
-		$myself = explode('/',$myself);
1324
+		$myself = implode('://', $myself);
1325
+		$myself = explode('/', $myself);
1328 1326
 		array_shift($myself);
1329
-		$myself = implode('/',$myself);
1327
+		$myself = implode('/', $myself);
1330 1328
 	}
1331
-	$url = join('/', array_slice(explode('/', $myself), 0, -1-$prof)).'/';
1329
+	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)).'/';
1332 1330
 
1333
-	$url = $http.'://'.rtrim($host,'/').'/'.ltrim($url,'/');
1331
+	$url = $http.'://'.rtrim($host, '/').'/'.ltrim($url, '/');
1334 1332
 	return $url;
1335 1333
 }
1336 1334
 
@@ -1344,24 +1342,24 @@  discard block
 block discarded – undo
1344 1342
 // http://httpd.apache.org/docs/2.0/mod/mod_dir.html
1345 1343
 
1346 1344
 // http://doc.spip.org/@generer_url_ecrire
1347
-function generer_url_ecrire($script='', $args="", $no_entities=false, $rel=false) {
1345
+function generer_url_ecrire($script = '', $args = "", $no_entities = false, $rel = false) {
1348 1346
 	if (!$rel)
1349
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
1347
+		$rel = url_de_base()._DIR_RESTREINT_ABS._SPIP_ECRIRE_SCRIPT;
1350 1348
 	else if (!is_string($rel))
1351 1349
 		$rel = _DIR_RESTREINT ? _DIR_RESTREINT :
1352
-			('./'  . _SPIP_ECRIRE_SCRIPT);
1350
+			('./'._SPIP_ECRIRE_SCRIPT);
1353 1351
 
1354 1352
 	@list($script, $ancre) = explode('#', $script);
1355
-	if ($script AND ($script<>'accueil' OR $rel))
1356
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
1353
+	if ($script AND ($script <> 'accueil' OR $rel))
1354
+		$args = "?exec=$script".(!$args ? '' : "&$args");
1357 1355
 	elseif ($args)
1358
-		$args ="?$args";
1356
+		$args = "?$args";
1359 1357
 	if ($ancre) $args .= "#$ancre";
1360
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
1358
+	return $rel.($no_entities ? $args : str_replace('&', '&amp;', $args));
1361 1359
 }
1362 1360
 
1363 1361
 // http://doc.spip.org/@generer_url_retour
1364
-function generer_url_retour($script, $args="")
1362
+function generer_url_retour($script, $args = "")
1365 1363
 {
1366 1364
 	return rawurlencode(generer_url_ecrire($script, $args, true, true));
1367 1365
 }
@@ -1373,7 +1371,7 @@  discard block
 block discarded – undo
1373 1371
 // Detecter le fichier de base, a la racine, comme etant spip.php ou ''
1374 1372
 // dans le cas de '', un $default = './' peut servir (comme dans urls/page.php)
1375 1373
 // http://doc.spip.org/@get_spip_script
1376
-function get_spip_script($default='') {
1374
+function get_spip_script($default = '') {
1377 1375
 	# cas define('_SPIP_SCRIPT', '');
1378 1376
 	if (_SPIP_SCRIPT)
1379 1377
 		return _SPIP_SCRIPT;
@@ -1382,7 +1380,7 @@  discard block
 block discarded – undo
1382 1380
 }
1383 1381
 
1384 1382
 // http://doc.spip.org/@generer_url_public
1385
-function generer_url_public($script='', $args="", $no_entities=false, $rel=true, $action='') {
1383
+function generer_url_public($script = '', $args = "", $no_entities = false, $rel = true, $action = '') {
1386 1384
 	// si le script est une action (spip_pass, spip_inscription),
1387 1385
 	// standardiser vers la nouvelle API
1388 1386
 
@@ -1393,23 +1391,23 @@  discard block
 block discarded – undo
1393 1391
 	if ($args) {
1394 1392
 		if (is_array($args)) {
1395 1393
 			$r = '';
1396
-			foreach($args as $k => $v) $r .= '&' . $k . '=' . $v;
1397
-			$args = substr($r,1);
1394
+			foreach ($args as $k => $v) $r .= '&'.$k.'='.$v;
1395
+			$args = substr($r, 1);
1398 1396
 		}
1399 1397
 		$action .=
1400
-			(strpos($action, '?') !== false ? '&' : '?') . $args;
1398
+			(strpos($action, '?') !== false ? '&' : '?').$args;
1401 1399
 	}
1402 1400
 	if (!$no_entities)
1403 1401
 		$action = quote_amp($action);
1404 1402
 
1405 1403
 	// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
1406
-	return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(),'/') . preg_replace(",^/[.]/,","/","/$action"));
1404
+	return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/').preg_replace(",^/[.]/,", "/", "/$action"));
1407 1405
 }
1408 1406
 
1409 1407
 // http://doc.spip.org/@generer_url_prive
1410
-function generer_url_prive($script, $args="", $no_entities=false) {
1408
+function generer_url_prive($script, $args = "", $no_entities = false) {
1411 1409
 
1412
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS .  'prive.php');
1410
+	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS.'prive.php');
1413 1411
 }
1414 1412
 
1415 1413
 // Pour les formulaires en methode POST,
@@ -1418,7 +1416,7 @@  discard block
 block discarded – undo
1418 1416
 // 2) ca suit http://en.wikipedia.org/wiki/Representational_State_Transfer
1419 1417
 
1420 1418
 // http://doc.spip.org/@generer_form_ecrire
1421
-function generer_form_ecrire($script, $corps, $atts='', $submit='') {
1419
+function generer_form_ecrire($script, $corps, $atts = '', $submit = '') {
1422 1420
 	global $spip_lang_right;
1423 1421
 
1424 1422
 	$script1 = explode('&', $script);
@@ -1431,8 +1429,7 @@  discard block
 block discarded – undo
1431 1429
 	.  "><div>\n"
1432 1430
 	. "<input type='hidden' name='exec' value='$script1' />"
1433 1431
 	. $corps
1434
-	. (!$submit ? '' :
1435
-	     ("<div style='text-align: $spip_lang_right'><input class='fondo' type='submit' value=\"".entites_html($submit)."\" /></div>"))
1432
+	. (!$submit ? '' : ("<div style='text-align: $spip_lang_right'><input class='fondo' type='submit' value=\"".entites_html($submit)."\" /></div>"))
1436 1433
 	. "</div></form>\n";
1437 1434
 }
1438 1435
 
@@ -1450,7 +1447,7 @@  discard block
 block discarded – undo
1450 1447
  * @param bool $public
1451 1448
  * @return string
1452 1449
  */
1453
-function generer_form_action($script, $corps, $atts='', $public=false) {
1450
+function generer_form_action($script, $corps, $atts = '', $public = false) {
1454 1451
 	// si l'on est dans l'espace prive, on garde dans l'url
1455 1452
 	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
1456 1453
 	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
@@ -1458,29 +1455,29 @@  discard block
 block discarded – undo
1458 1455
 	? generer_url_ecrire(_request('exec'))
1459 1456
 	: generer_url_public();
1460 1457
 
1461
-	return "\n<form action='" .
1462
-	  $h .
1463
-	  "'" .
1464
-	  $atts .
1465
-	  ">\n" .
1466
-	  "<div>" .
1467
-  	  "\n<input type='hidden' name='action' value='$script' />" .
1468
-	  $corps .
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.
1469 1466
 	  "</div></form>";
1470 1467
 }
1471 1468
 
1472 1469
 // http://doc.spip.org/@generer_url_action
1473
-function generer_url_action($script, $args="", $no_entities=false , $public = false) {
1470
+function generer_url_action($script, $args = "", $no_entities = false, $public = false) {
1474 1471
 	// si l'on est dans l'espace prive, on garde dans l'url
1475 1472
 	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
1476 1473
 	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
1477
-	$url = (_DIR_RACINE  AND !$public)
1474
+	$url = (_DIR_RACINE AND !$public)
1478 1475
 	  ? generer_url_ecrire(_request('exec'))
1479
-	  :  generer_url_public('','',false,false);
1480
-	$url = parametre_url($url,'action',$script);
1476
+	  :  generer_url_public('', '', false, false);
1477
+	$url = parametre_url($url, 'action', $script);
1481 1478
 	if ($args) $url .= quote_amp('&'.$args);
1482 1479
 
1483
-	if ($no_entities) $url = str_replace('&amp;','&',$url);
1480
+	if ($no_entities) $url = str_replace('&amp;', '&', $url);
1484 1481
 	return $url;
1485 1482
 }
1486 1483
 
@@ -1493,8 +1490,8 @@  discard block
 block discarded – undo
1493 1490
  * @param string $ti
1494 1491
  * @param string $ta
1495 1492
  */
1496
-function spip_initialisation($pi=NULL, $pa=NULL, $ti=NULL, $ta=NULL) {
1497
-	spip_initialisation_core($pi,$pa,$ti,$ta);
1493
+function spip_initialisation($pi = NULL, $pa = NULL, $ti = NULL, $ta = NULL) {
1494
+	spip_initialisation_core($pi, $pa, $ti, $ta);
1498 1495
 	spip_initialisation_suite();
1499 1496
 }
1500 1497
 
@@ -1512,32 +1509,32 @@  discard block
 block discarded – undo
1512 1509
  * @param string $ti
1513 1510
  * @param string $ta
1514 1511
  */
1515
-function spip_initialisation_core($pi=NULL, $pa=NULL, $ti=NULL, $ta=NULL) {
1512
+function spip_initialisation_core($pi = NULL, $pa = NULL, $ti = NULL, $ta = NULL) {
1516 1513
 	static $too_late = 0;
1517 1514
 	if ($too_late++) return;
1518 1515
 	
1519 1516
 	// Declaration des repertoires
1520 1517
 
1521 1518
 	// le nom du repertoire plugins/ activables/desactivables
1522
-	if (!defined('_DIR_PLUGINS')) define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
1519
+	if (!defined('_DIR_PLUGINS')) define('_DIR_PLUGINS', _DIR_RACINE."plugins/");
1523 1520
 
1524 1521
 	// le nom du repertoire des extensions/ permanentes du core, toujours actives
1525
-	if (!defined('_DIR_PLUGINS_DIST')) define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
1522
+	if (!defined('_DIR_PLUGINS_DIST')) define('_DIR_PLUGINS_DIST', _DIR_RACINE."plugins-dist/");
1526 1523
 
1527 1524
 	// le nom du repertoire des librairies
1528
-	if (!defined('_DIR_LIB')) define('_DIR_LIB', _DIR_RACINE . "lib/");
1525
+	if (!defined('_DIR_LIB')) define('_DIR_LIB', _DIR_RACINE."lib/");
1529 1526
 	
1530 1527
 	if (!defined('_DIR_IMG')) define('_DIR_IMG', $pa);
1531 1528
 	if (!defined('_DIR_LOGOS')) define('_DIR_LOGOS', $pa);
1532
-	if (!defined('_DIR_IMG_ICONES')) define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
1533
-
1534
-	if (!defined('_DIR_DUMP')) define('_DIR_DUMP', $ti . "dump/");
1535
-	if (!defined('_DIR_SESSIONS')) define('_DIR_SESSIONS', $ti . "sessions/");
1536
-	if (!defined('_DIR_TRANSFERT')) define('_DIR_TRANSFERT', $ti . "upload/");
1537
-	if (!defined('_DIR_CACHE')) define('_DIR_CACHE', $ti . "cache/");
1538
-	if (!defined('_DIR_CACHE_XML')) define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
1539
-	if (!defined('_DIR_SKELS')) define('_DIR_SKELS',  _DIR_CACHE . "skel/");
1540
-	if (!defined('_DIR_AIDE')) define('_DIR_AIDE',  _DIR_CACHE . "aide/");
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/");
1541 1538
 	if (!defined('_DIR_TMP')) define('_DIR_TMP', $ti);
1542 1539
 
1543 1540
 	if (!defined('_DIR_VAR')) define('_DIR_VAR', $ta);
@@ -1549,19 +1546,19 @@  discard block
 block discarded – undo
1549 1546
 	if (!isset($GLOBALS['test_dirs']))
1550 1547
 	  // Pas $pi car il est bon de le mettre hors ecriture apres intstall
1551 1548
 	  // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
1552
-		$GLOBALS['test_dirs'] =  array($pa, $ti, $ta);
1549
+		$GLOBALS['test_dirs'] = array($pa, $ti, $ta);
1553 1550
 
1554 1551
 	// Declaration des fichiers
1555 1552
 
1556
-	if (!defined('_CACHE_PLUGINS_PATH')) define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
1557
-	if (!defined('_CACHE_PLUGINS_OPT')) define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
1558
-	if (!defined('_CACHE_PLUGINS_FCT')) define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
1559
-	if (!defined('_CACHE_PIPELINES')) define('_CACHE_PIPELINES',  _DIR_CACHE."charger_pipelines.php");
1560
-	if (!defined('_CACHE_CHEMIN')) define('_CACHE_CHEMIN',  _DIR_CACHE."chemin.txt");
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");
1561 1558
 
1562 1559
 	# attention .php obligatoire pour ecrire_fichier_securise
1563
-	if (!defined('_FILE_META')) define('_FILE_META', $ti . 'meta_cache.php');
1564
-	if (!defined('_DIR_LOG')) define('_DIR_LOG', _DIR_TMP . 'log/');
1560
+	if (!defined('_FILE_META')) define('_FILE_META', $ti.'meta_cache.php');
1561
+	if (!defined('_DIR_LOG')) define('_DIR_LOG', _DIR_TMP.'log/');
1565 1562
 	if (!defined('_FILE_LOG')) define('_FILE_LOG', 'spip');
1566 1563
 	if (!defined('_FILE_LOG_SUFFIX')) define('_FILE_LOG_SUFFIX', '.log');
1567 1564
 
@@ -1569,21 +1566,21 @@  discard block
 block discarded – undo
1569 1566
 	// tient compte des anciennes versions (inc_connect...)
1570 1567
 	if (!defined('_FILE_CONNECT_INS')) define('_FILE_CONNECT_INS', 'connect');
1571 1568
 	if (!defined('_FILE_CONNECT')) define('_FILE_CONNECT',
1572
-		(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
1573
-	:	(@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
1569
+		(@is_readable($f = _DIR_CONNECT._FILE_CONNECT_INS.'.php') ? $f
1570
+	:	(@is_readable($f = _DIR_RESTREINT.'inc_connect.php') ? $f
1574 1571
 	:	false)));
1575 1572
 
1576 1573
 	// Le fichier de reglages des droits
1577 1574
 	if (!defined('_FILE_CHMOD_INS')) define('_FILE_CHMOD_INS', 'chmod');
1578 1575
 	if (!defined('_FILE_CHMOD')) define('_FILE_CHMOD',
1579
-		(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
1576
+		(@is_readable($f = _DIR_CHMOD._FILE_CHMOD_INS.'.php') ? $f
1580 1577
 	:	false));
1581 1578
 
1582 1579
 	if (!defined('_FILE_LDAP')) define('_FILE_LDAP', 'ldap.php');
1583 1580
 
1584 1581
 	if (!defined('_FILE_TMP_SUFFIX')) define('_FILE_TMP_SUFFIX', '.tmp.php');
1585
-	if (!defined('_FILE_CONNECT_TMP')) define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
1586
-	if (!defined('_FILE_CHMOD_TMP')) define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
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);
1587 1584
 
1588 1585
 	// Definition des droits d'acces en ecriture
1589 1586
 	if (!defined('_SPIP_CHMOD') AND _FILE_CHMOD)
@@ -1594,31 +1591,31 @@  discard block
 block discarded – undo
1594 1591
 
1595 1592
 	// Le charset par defaut lors de l'installation
1596 1593
 	if (!defined('_DEFAULT_CHARSET')) define('_DEFAULT_CHARSET', 'utf-8');
1597
-	if (!defined('_ROOT_PLUGINS')) define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
1598
-	if (!defined('_ROOT_PLUGINS_DIST')) define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
1599
-	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));
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));
1600 1597
 
1601 1598
 	// La taille des Log
1602 1599
 	if (!defined('_MAX_LOG')) define('_MAX_LOG', 100);
1603 1600
 
1604 1601
 	// Sommes-nous dans l'empire du Mal ?
1605 1602
 	// (ou sous le signe du Pingouin, ascendant GNU ?)
1606
-	if (strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false){
1603
+	if (strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
1607 1604
 		if (!defined('_OS_SERVEUR')) define('_OS_SERVEUR', 'windows');
1608
-		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
1609 1606
 	}
1610 1607
 	else {
1611 1608
 		if (!defined('_OS_SERVEUR')) define('_OS_SERVEUR', '');
1612
-		if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',1); // utiliser le flock php
1609
+		if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE', 1); // utiliser le flock php
1613 1610
 		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
1614 1611
 	}
1615 1612
 
1616 1613
 	// Langue par defaut
1617
-	if (!defined('_LANGUE_PAR_DEFAUT')) define('_LANGUE_PAR_DEFAUT','fr');
1614
+	if (!defined('_LANGUE_PAR_DEFAUT')) define('_LANGUE_PAR_DEFAUT', 'fr');
1618 1615
 
1619 1616
 	// PHP_VERSION_ID dispo depuis PHP 5.2.7
1620 1617
 	if (!defined('PHP_VERSION_ID')) {
1621
-	   $version = explode('.',PHP_VERSION);
1618
+	   $version = explode('.', PHP_VERSION);
1622 1619
 	   define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
1623 1620
 	}
1624 1621
 
@@ -1627,7 +1624,7 @@  discard block
 block discarded – undo
1627 1624
 	// (non surchargeable en l'etat ; attention si on utilise include_spip()
1628 1625
 	// pour le rendre surchargeable, on va provoquer un reecriture
1629 1626
 	// systematique du noyau ou une baisse de perfs => a etudier)
1630
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
1627
+	include_once _ROOT_RESTREINT.'inc/flock.php';
1631 1628
 
1632 1629
 	// charger tout de suite le path et son cache
1633 1630
 	load_path_cache();
@@ -1647,7 +1644,7 @@  discard block
 block discarded – undo
1647 1644
 	spip_desinfecte($_REQUEST);
1648 1645
 
1649 1646
 	// Par ailleurs on ne veut pas de magic_quotes au cours de l'execution
1650
-	if (PHP_VERSION_ID<50300) {
1647
+	if (PHP_VERSION_ID < 50300) {
1651 1648
 		@set_magic_quotes_runtime(0);
1652 1649
 	}
1653 1650
 
@@ -1657,7 +1654,7 @@  discard block
 block discarded – undo
1657 1654
 	if (test_valeur_serveur(@ini_get('register_globals'))) {
1658 1655
 		// ne pas desinfecter les globales en profondeur car elle contient aussi les
1659 1656
 		// precedentes, qui seraient desinfectees 2 fois.
1660
-		spip_desinfecte($GLOBALS,false);
1657
+		spip_desinfecte($GLOBALS, false);
1661 1658
 		if (include_spip('inc/php3'))
1662 1659
 			spip_register_globals(true);
1663 1660
 
@@ -1701,8 +1698,8 @@  discard block
 block discarded – undo
1701 1698
 	$inc_meta();
1702 1699
 
1703 1700
 	// on a pas pu le faire plus tot
1704
-	if  ($avertir_register_globals)
1705
-		avertir_auteurs("register_globals",_L("Probl&egrave;me de s&eacute;curit&eacute; : register_globals=on; dans php.ini &agrave; corriger."));
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."));
1706 1703
 
1707 1704
 	// nombre de repertoires depuis la racine
1708 1705
 	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
@@ -1718,7 +1715,7 @@  discard block
 block discarded – undo
1718 1715
 			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
1719 1716
 			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
1720 1717
 			// s'en remettre a l'adresse du site. alea jacta est.
1721
-			OR $ti!==_NOM_TEMPORAIRES_INACCESSIBLES){
1718
+			OR $ti !== _NOM_TEMPORAIRES_INACCESSIBLES) {
1722 1719
 
1723 1720
 			if (isset($GLOBALS['meta']['adresse_site'])) {
1724 1721
 				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
@@ -1732,12 +1729,12 @@  discard block
 block discarded – undo
1732 1729
 		else {
1733 1730
 			$GLOBALS['profondeur_url'] = max(0,
1734 1731
 				substr_count($uri[0], '/')
1735
-				- substr_count($uri_ref,'/'));
1732
+				- substr_count($uri_ref, '/'));
1736 1733
 		}
1737 1734
 	}
1738 1735
 	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
1739 1736
 	if (_FILE_CONNECT) {
1740
-		if (verifier_visiteur()=='0minirezo'
1737
+		if (verifier_visiteur() == '0minirezo'
1741 1738
 			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
1742 1739
 		  AND !isset($_COOKIE['spip_admin']))
1743 1740
 			clear_path_cache();
@@ -1767,7 +1764,7 @@  discard block
 block discarded – undo
1767 1764
 	if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
1768 1765
 	if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
1769 1766
 	if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
1770
-	if (!defined('_PASS_LONGUEUR_MINI')) define('_PASS_LONGUEUR_MINI',6);
1767
+	if (!defined('_PASS_LONGUEUR_MINI')) define('_PASS_LONGUEUR_MINI', 6);
1771 1768
 
1772 1769
 
1773 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)
@@ -1777,7 +1774,7 @@  discard block
 block discarded – undo
1777 1774
 	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
1778 1775
         if (!defined('_IMG_IMAGICK_QUALITE')) define('_IMG_IMAGICK_QUALITE', 75); # surcharge pour imagick en PHP
1779 1776
 
1780
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) define('_COPIE_LOCALE_MAX_SIZE',16777216); // poids en octet
1777
+	if (!defined('_COPIE_LOCALE_MAX_SIZE')) define('_COPIE_LOCALE_MAX_SIZE', 16777216); // poids en octet
1781 1778
 
1782 1779
 	// qq chaines standard
1783 1780
 	if (!defined('_ACCESS_FILE_NAME')) define('_ACCESS_FILE_NAME', '.htaccess');
@@ -1809,7 +1806,7 @@  discard block
 block discarded – undo
1809 1806
 	// meme pb sur thttpd cf. http://forum.spip.org/fr_184153.html
1810 1807
 
1811 1808
 	if (!defined('_SPIP_ECRIRE_SCRIPT')) define('_SPIP_ECRIRE_SCRIPT', // true ? #decommenter ici et commenter la
1812
-	       preg_match(',IIS|thttpd,',$_SERVER['SERVER_SOFTWARE']) ?
1809
+	       preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE']) ?
1813 1810
 	       'index.php' : '');
1814 1811
 
1815 1812
 
@@ -1832,32 +1829,32 @@  discard block
 block discarded – undo
1832 1829
 	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
1833 1830
 	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
1834 1831
 	if (!defined('_IMG_GD_MAX_PIXELS')) define('_IMG_GD_MAX_PIXELS',
1835
-		(isset($GLOBALS['meta']['max_taille_vignettes'])&&$GLOBALS['meta']['max_taille_vignettes']<5500000)
1832
+		(isset($GLOBALS['meta']['max_taille_vignettes']) && $GLOBALS['meta']['max_taille_vignettes'] < 5500000)
1836 1833
 		 ? $GLOBALS['meta']['max_taille_vignettes']
1837 1834
 		 : 0);
1838 1835
 
1839
-	if (!defined('_MEMORY_LIMIT_MIN')) define('_MEMORY_LIMIT_MIN',10); // en Mo
1836
+	if (!defined('_MEMORY_LIMIT_MIN')) define('_MEMORY_LIMIT_MIN', 10); // en Mo
1840 1837
 	// si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
1841 1838
 	// on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
1842 1839
 	// il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
1843
-	if (test_espace_prive() AND _MEMORY_LIMIT_MIN>8){
1840
+	if (test_espace_prive() AND _MEMORY_LIMIT_MIN > 8) {
1844 1841
 		if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
1845
-			$unit = strtolower(substr($memory,strlen($memory/1),1));
1846
-			switch($unit) {
1842
+			$unit = strtolower(substr($memory, strlen($memory / 1), 1));
1843
+			switch ($unit) {
1847 1844
 				// Le modifieur 'G' est disponible depuis PHP 5.1.0
1848 1845
 				case 'g': $memory *= 1024;
1849 1846
 				case 'm': $memory *= 1024;
1850 1847
 				case 'k': $memory *= 1024;
1851 1848
 			}
1852
-			if ($memory<_MEMORY_LIMIT_MIN*1024*1024){
1853
-				ini_set('memory_limit',$m=_MEMORY_LIMIT_MIN.'M');
1854
-				if (trim(ini_get('memory_limit'))!=$m){
1855
-					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
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
1856 1853
 				}
1857 1854
 			}
1858 1855
 		}
1859 1856
 		else
1860
-			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
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
1861 1858
 	}
1862 1859
 	// Protocoles a normaliser dans les chaines de langues
1863 1860
 	if (!defined('_PROTOCOLES_STD'))
@@ -1869,7 +1866,7 @@  discard block
 block discarded – undo
1869 1866
 // Reperer les variables d'URL qui conditionnent la perennite du cache, des urls
1870 1867
 // ou d'autres petit caches (trouver_table, css et js compactes ...)
1871 1868
 // http://doc.spip.org/@init_var_mode
1872
-function init_var_mode(){
1869
+function init_var_mode() {
1873 1870
 	static $done = false;
1874 1871
 	if (!$done) {
1875 1872
 
@@ -1877,56 +1874,56 @@  discard block
 block discarded – undo
1877 1874
 			// tout le monde peut calcul/recalcul
1878 1875
 			if ($_GET['var_mode'] == 'calcul'
1879 1876
 			OR $_GET['var_mode'] == 'recalcul') {
1880
-				if (!defined('_VAR_MODE')) define('_VAR_MODE',$_GET['var_mode']);
1877
+				if (!defined('_VAR_MODE')) define('_VAR_MODE', $_GET['var_mode']);
1881 1878
 			}
1882 1879
 			// preview, debug, blocs, urls et images necessitent une autorisation
1883
-			else if (in_array($_GET['var_mode'],array('preview','debug','inclure','urls','images','traduction'))) {
1880
+			else if (in_array($_GET['var_mode'], array('preview', 'debug', 'inclure', 'urls', 'images', 'traduction'))) {
1884 1881
 				include_spip('inc/autoriser');
1885 1882
 				if (autoriser(
1886 1883
 					($_GET['var_mode'] == 'preview')
1887 1884
 						? 'previsualiser'
1888 1885
 						: 'debug'
1889 1886
 				)) {
1890
-					switch($_GET['var_mode']){
1887
+					switch ($_GET['var_mode']) {
1891 1888
 						case 'traduction':
1892 1889
 							// forcer le calcul pour passer dans traduire
1893
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1890
+							if (!defined('_VAR_MODE')) define('_VAR_MODE', 'calcul');
1894 1891
 							// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
1895
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1892
+							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE', true);
1896 1893
 							break;
1897 1894
 						case 'preview':
1898 1895
 							// basculer sur les criteres de preview dans les boucles
1899
-							if (!defined('_VAR_PREVIEW')) define('_VAR_PREVIEW',true);
1896
+							if (!defined('_VAR_PREVIEW')) define('_VAR_PREVIEW', true);
1900 1897
 							// forcer le calcul
1901
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1898
+							if (!defined('_VAR_MODE')) define('_VAR_MODE', 'calcul');
1902 1899
 							// et ne pas enregistrer de cache
1903
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1900
+							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE', true);
1904 1901
 							break;
1905 1902
 						case 'inclure':
1906 1903
 							// forcer le compilo et ignorer les caches existants
1907
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1908
-							if (!defined('_VAR_INCLURE')) define('_VAR_INCLURE',true);
1904
+							if (!defined('_VAR_MODE')) define('_VAR_MODE', 'calcul');
1905
+							if (!defined('_VAR_INCLURE')) define('_VAR_INCLURE', true);
1909 1906
 							// et ne pas enregistrer de cache
1910
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1907
+							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE', true);
1911 1908
 							break;
1912 1909
 						case 'urls':
1913 1910
 							// forcer le compilo et ignorer les caches existants
1914
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1915
-							if (!defined('_VAR_URLS')) define('_VAR_URLS',true);
1911
+							if (!defined('_VAR_MODE')) define('_VAR_MODE', 'calcul');
1912
+							if (!defined('_VAR_URLS')) define('_VAR_URLS', true);
1916 1913
 							break;
1917 1914
 						case 'images':
1918 1915
 							// forcer le compilo et ignorer les caches existants
1919
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1916
+							if (!defined('_VAR_MODE')) define('_VAR_MODE', 'calcul');
1920 1917
 							// indiquer qu'on doit recalculer les images
1921
-							if (!defined('_VAR_IMAGES')) define('_VAR_IMAGES',true);
1918
+							if (!defined('_VAR_IMAGES')) define('_VAR_IMAGES', true);
1922 1919
 							break;
1923 1920
 						case 'debug':
1924
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','debug');
1921
+							if (!defined('_VAR_MODE')) define('_VAR_MODE', 'debug');
1925 1922
 							// et ne pas enregistrer de cache
1926
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
1923
+							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE', true);
1927 1924
 							break;
1928 1925
 						default :
1929
-							if (!defined('_VAR_MODE')) define('_VAR_MODE',$_GET['var_mode']);
1926
+							if (!defined('_VAR_MODE')) define('_VAR_MODE', $_GET['var_mode']);
1930 1927
 							break;
1931 1928
 					}
1932 1929
           if (isset($GLOBALS['visiteur_session']['nom']))
@@ -1946,7 +1943,7 @@  discard block
 block discarded – undo
1946 1943
 					// sinon tant pis
1947 1944
 				}
1948 1945
 			}
1949
-			if (!defined('_VAR_MODE')) define('_VAR_MODE',false);
1946
+			if (!defined('_VAR_MODE')) define('_VAR_MODE', false);
1950 1947
 		}
1951 1948
 		$done = true;
1952 1949
 	}
@@ -1956,7 +1953,7 @@  discard block
 block discarded – undo
1956 1953
 // supprimer aussi les eventuels caracteres nuls %00, qui peuvent tromper
1957 1954
 // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal')
1958 1955
 // http://doc.spip.org/@spip_desinfecte
1959
-function spip_desinfecte(&$t,$deep = true) {
1956
+function spip_desinfecte(&$t, $deep = true) {
1960 1957
 	static $magic_quotes;
1961 1958
 	if (!isset($magic_quotes))
1962 1959
 		$magic_quotes = @get_magic_quotes_gpc();
@@ -1968,8 +1965,8 @@  discard block
 block discarded – undo
1968 1965
 			$t[$key] = str_replace(chr(0), '-', $t[$key]);
1969 1966
 		}
1970 1967
 		// traiter aussi les "texte_plus" de article_edit
1971
-		else if ($deep AND is_array($t[$key]) AND $key!=='GLOBALS')
1972
-			spip_desinfecte($t[$key],$deep);
1968
+		else if ($deep AND is_array($t[$key]) AND $key !== 'GLOBALS')
1969
+			spip_desinfecte($t[$key], $deep);
1973 1970
 	}
1974 1971
 }
1975 1972
 
@@ -1982,10 +1979,10 @@  discard block
 block discarded – undo
1982 1979
 	// mais on risque de perturber des plugins en initialisant trop tot
1983 1980
 	// certaines constantes
1984 1981
 	@spip_initialisation_core(
1985
-		(_DIR_RACINE  . _NOM_PERMANENTS_INACCESSIBLES),
1986
-		(_DIR_RACINE  . _NOM_PERMANENTS_ACCESSIBLES),
1987
-		(_DIR_RACINE  . _NOM_TEMPORAIRES_INACCESSIBLES),
1988
-		(_DIR_RACINE  . _NOM_TEMPORAIRES_ACCESSIBLES)
1982
+		(_DIR_RACINE._NOM_PERMANENTS_INACCESSIBLES),
1983
+		(_DIR_RACINE._NOM_PERMANENTS_ACCESSIBLES),
1984
+		(_DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES),
1985
+		(_DIR_RACINE._NOM_TEMPORAIRES_ACCESSIBLES)
1989 1986
 	);
1990 1987
 
1991 1988
 	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
@@ -1993,7 +1990,7 @@  discard block
 block discarded – undo
1993 1990
 	// Attention on separe bien session_nom et nom, pour eviter
1994 1991
 	// les melanges entre donnees SQL et variables plus aleatoires
1995 1992
 	$variables_session = array('session_nom', 'session_email');
1996
-	foreach($variables_session as $var) {
1993
+	foreach ($variables_session as $var) {
1997 1994
 		if (_request($var) !== null) {
1998 1995
 			$init = true;
1999 1996
 			break;
@@ -2004,7 +2001,7 @@  discard block
 block discarded – undo
2004 2001
 		$session = charger_fonction('session', 'inc');
2005 2002
 		$session();
2006 2003
 		include_spip('inc/texte');
2007
-		foreach($variables_session as $var)
2004
+		foreach ($variables_session as $var)
2008 2005
 			if (($a = _request($var)) !== null)
2009 2006
 				$GLOBALS['visiteur_session'][$var] = safehtml($a);
2010 2007
 		if (!isset($GLOBALS['visiteur_session']['id_auteur']))
@@ -2013,14 +2010,14 @@  discard block
 block discarded – undo
2013 2010
 		return 0;
2014 2011
 	}
2015 2012
 
2016
-	$h = (isset($_SERVER['PHP_AUTH_USER'])  AND !$GLOBALS['ignore_auth_http']);
2013
+	$h = (isset($_SERVER['PHP_AUTH_USER']) AND !$GLOBALS['ignore_auth_http']);
2017 2014
 	if ($h OR isset($_COOKIE['spip_session']) OR isset($_COOKIE[$GLOBALS['cookie_prefix'].'_session'])) {
2018 2015
 
2019 2016
 		$session = charger_fonction('session', 'inc');
2020 2017
 		if ($session()) {
2021 2018
 			return $GLOBALS['visiteur_session']['statut'];
2022 2019
 		}
2023
-		if ($h  AND isset($_SERVER['PHP_AUTH_PW'])) {
2020
+		if ($h AND isset($_SERVER['PHP_AUTH_PW'])) {
2024 2021
 			include_spip('inc/auth');
2025 2022
 			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
2026 2023
 		}
@@ -2045,7 +2042,7 @@  discard block
 block discarded – undo
2045 2042
 // cette fonction retourne toujours non False
2046 2043
 
2047 2044
 // http://doc.spip.org/@lang_select
2048
-function lang_select ($lang=NULL) {
2045
+function lang_select($lang = NULL) {
2049 2046
 	static $pile_langues = array();
2050 2047
 	if (!function_exists('changer_langue'))
2051 2048
 		include_spip('inc/lang');
@@ -2075,7 +2072,7 @@  discard block
 block discarded – undo
2075 2072
 		$s = pipeline('definir_session',
2076 2073
 			$GLOBALS['visiteur_session']
2077 2074
 			? serialize($GLOBALS['visiteur_session'])
2078
-				. '_' . @$_COOKIE['spip_session']
2075
+				. '_'.@$_COOKIE['spip_session']
2079 2076
 			: ''
2080 2077
 		);
2081 2078
 		$session = $s ? substr(md5($s), 0, 8) : '';
@@ -2097,9 +2094,9 @@  discard block
 block discarded – undo
2097 2094
  * @return Lien sur une icone d'aide
2098 2095
 **/
2099 2096
 // http://doc.spip.org/@aide
2100
-function aide($aide='', $distante = false) {
2097
+function aide($aide = '', $distante = false) {
2101 2098
 		$aider = charger_fonction('aider', 'inc', true);
2102
-	return $aider ?  $aider($aide, '', array(), $distante) : '';
2099
+	return $aider ? $aider($aide, '', array(), $distante) : '';
2103 2100
 }
2104 2101
 
2105 2102
 // normalement il faudrait creer exec/info.php, mais pour mettre juste ca:
@@ -2128,7 +2125,7 @@  discard block
 block discarded – undo
2128 2125
  * 		Rien dans la plupart des cas
2129 2126
  * 		- string si $message à false.
2130 2127
 **/
2131
-function erreur_squelette($message='', $lieu='') {
2128
+function erreur_squelette($message = '', $lieu = '') {
2132 2129
 	$debusquer = charger_fonction('debusquer', 'public');
2133 2130
 	if (is_array($lieu)) {
2134 2131
 		include_spip('public/compiler');
@@ -2168,15 +2165,15 @@  discard block
 block discarded – undo
2168 2165
  * 		Contenu du squelette calculé
2169 2166
  * 		ou tableau d'information sur le squelette.
2170 2167
  */
2171
-function recuperer_fond($fond, $contexte=array(), $options = array(), $connect='') {
2168
+function recuperer_fond($fond, $contexte = array(), $options = array(), $connect = '') {
2172 2169
 	if (!function_exists('evaluer_fond'))
2173 2170
 		include_spip('public/assembler');
2174 2171
 	// assurer la compat avec l'ancienne syntaxe
2175 2172
 	// (trim etait le 3eme argument, par defaut a true)
2176 2173
 	if (!is_array($options)) $options = array('trim'=>$options);
2177
-	if (!isset($options['trim'])) $options['trim']=true;
2174
+	if (!isset($options['trim'])) $options['trim'] = true;
2178 2175
 
2179
-	if (isset($contexte['connect'])){
2176
+	if (isset($contexte['connect'])) {
2180 2177
 		$connect = ($connect ? $connect : $contexte['connect']);
2181 2178
 		unset($contexte['connect']);
2182 2179
 	}
@@ -2184,7 +2181,7 @@  discard block
 block discarded – undo
2184 2181
 	$texte = "";
2185 2182
 	$pages = array();
2186 2183
 	$lang_select = '';
2187
-	if (!isset($options['etoile']) OR !$options['etoile']){
2184
+	if (!isset($options['etoile']) OR !$options['etoile']) {
2188 2185
 		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
2189 2186
 		if (!isset($contexte['lang']))
2190 2187
 			$contexte['lang'] = $GLOBALS['spip_lang'];
@@ -2196,10 +2193,10 @@  discard block
 block discarded – undo
2196 2193
 
2197 2194
 	@$GLOBALS['_INC_PUBLIC']++;
2198 2195
 
2199
-	foreach(is_array($fond) ? $fond : array($fond) as $f){
2196
+	foreach (is_array($fond) ? $fond : array($fond) as $f) {
2200 2197
 		$page = evaluer_fond($f, $contexte, $connect);
2201 2198
 		if ($page === '') {
2202
-			$c = isset($options['compil']) ? $options['compil'] :'';
2199
+			$c = isset($options['compil']) ? $options['compil'] : '';
2203 2200
 			$a = array('fichier'=>$fond);
2204 2201
 			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
2205 2202
 			erreur_squelette($erreur, $c);
@@ -2207,14 +2204,14 @@  discard block
 block discarded – undo
2207 2204
 			$page = array('texte' => '', 'erreur' => $erreur);
2208 2205
 		}
2209 2206
 
2210
-		$page = pipeline('recuperer_fond',array(
2211
-			'args'=>array('fond'=>$f,'contexte'=>$contexte,'options'=>$options,'connect'=>$connect),
2207
+		$page = pipeline('recuperer_fond', array(
2208
+			'args'=>array('fond'=>$f, 'contexte'=>$contexte, 'options'=>$options, 'connect'=>$connect),
2212 2209
 			'data'=>$page
2213 2210
 		));
2214
-		if (isset($options['ajax']) AND $options['ajax']){
2211
+		if (isset($options['ajax']) AND $options['ajax']) {
2215 2212
 			if (!function_exists('encoder_contexte_ajax'))
2216 2213
 				include_spip('inc/filtres');
2217
-			$page['texte'] = encoder_contexte_ajax(array_merge($contexte,array('fond'=>$f)),'',$page['texte'], $options['ajax']);
2214
+			$page['texte'] = encoder_contexte_ajax(array_merge($contexte, array('fond'=>$f)), '', $page['texte'], $options['ajax']);
2218 2215
 		}
2219 2216
 
2220 2217
 		if (isset($options['raw']) AND $options['raw'])
@@ -2227,7 +2224,7 @@  discard block
 block discarded – undo
2227 2224
 
2228 2225
 	if ($lang_select) lang_select();
2229 2226
 	if (isset($options['raw']) AND $options['raw'])
2230
-		return is_array($fond)?$pages:reset($pages);
2227
+		return is_array($fond) ? $pages : reset($pages);
2231 2228
 	else
2232 2229
 		return $options['trim'] ? ltrim($texte) : $texte;
2233 2230
 }
@@ -2239,7 +2236,7 @@  discard block
 block discarded – undo
2239 2236
  * @return string
2240 2237
  */
2241 2238
 function trouve_modele($nom) {
2242
-	return trouver_fond($nom,'modeles/');
2239
+	return trouver_fond($nom, 'modeles/');
2243 2240
 }
2244 2241
 
2245 2242
 /**
@@ -2254,8 +2251,8 @@  discard block
 block discarded – undo
2254 2251
  * @param bool $pathinfo
2255 2252
  * @return array|string
2256 2253
  */
2257
-function trouver_fond($nom, $dir='', $pathinfo = false) {
2258
-	$f = find_in_path($nom.'.'. _EXTENSION_SQUELETTES, $dir?rtrim($dir,'/').'/':'');
2254
+function trouver_fond($nom, $dir = '', $pathinfo = false) {
2255
+	$f = find_in_path($nom.'.'._EXTENSION_SQUELETTES, $dir ?rtrim($dir, '/').'/' : '');
2259 2256
 	if (!$pathinfo) return $f;
2260 2257
 	// renvoyer un tableau detaille si $pathinfo==true
2261 2258
 	$p = pathinfo($f);
@@ -2263,14 +2260,14 @@  discard block
 block discarded – undo
2263 2260
 		$p['extension'] = _EXTENSION_SQUELETTES;
2264 2261
 	}
2265 2262
 	if (!isset($p['extension']) OR !$p['filename']) {
2266
-		$p['filename'] = ($p['basename']?substr($p['basename'],0,-strlen($p['extension'])-1):'');
2263
+		$p['filename'] = ($p['basename'] ?substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
2267 2264
 	}
2268
-	$p['fond'] = ($f?substr($f,0,-strlen($p['extension'])-1):'');
2265
+	$p['fond'] = ($f ?substr($f, 0, -strlen($p['extension']) - 1) : '');
2269 2266
 	return $p;
2270 2267
 }
2271 2268
 
2272
-function tester_url_ecrire($nom){
2273
-	static $exec=array();
2269
+function tester_url_ecrire($nom) {
2270
+	static $exec = array();
2274 2271
 	if (isset($exec[$nom])) return $exec[$nom];
2275 2272
 	// tester si c'est une page en squelette
2276 2273
 	if (trouver_fond($nom, 'prive/squelettes/contenu/'))
@@ -2279,12 +2276,12 @@  discard block
 block discarded – undo
2279 2276
 	elseif (trouver_fond($nom, 'prive/exec/'))
2280 2277
 		return $exec[$nom] = 'fond_monobloc';
2281 2278
 	// echafaudage d'un fond !
2282
-	elseif(include_spip('public/styliser_par_z') AND z_echafaudable($nom))
2279
+	elseif (include_spip('public/styliser_par_z') AND z_echafaudable($nom))
2283 2280
 		return $exec[$nom] = 'fond';
2284 2281
 	// attention, il ne faut pas inclure l'exec ici
2285 2282
 	// car sinon #URL_ECRIRE provoque des inclusions
2286 2283
 	// et des define intrusifs potentiels
2287
-	return $exec[$nom] = ((find_in_path("{$nom}.php",'exec/') OR charger_fonction($nom,'exec',true))?$nom:'');
2284
+	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') OR charger_fonction($nom, 'exec', true)) ? $nom : '');
2288 2285
 }
2289 2286
 
2290 2287
 // Charger dynamiquement une extension php
@@ -2293,7 +2290,7 @@  discard block
 block discarded – undo
2293 2290
 	if (extension_loaded($module)) {
2294 2291
 		return true;
2295 2292
 	} else {
2296
-		$charger_php_extension = charger_fonction('charger_php_extension','inc');
2293
+		$charger_php_extension = charger_fonction('charger_php_extension', 'inc');
2297 2294
 		return $charger_php_extension($module);
2298 2295
 	}
2299 2296
 }
@@ -2322,13 +2319,13 @@  discard block
 block discarded – undo
2322 2319
 
2323 2320
 // Fonction depreciee, cf. http://doc.spip.org/@sql_fetch
2324 2321
 // http://doc.spip.org/@spip_fetch_array
2325
-function spip_fetch_array($r, $t=NULL) {
2322
+function spip_fetch_array($r, $t = NULL) {
2326 2323
 	if (!isset($t)) {
2327 2324
 		if ($r) return sql_fetch($r);
2328 2325
 	} else {
2329
-		if ($t=='SPIP_NUM') $t = MYSQL_NUM;
2330
-		if ($t=='SPIP_BOTH') $t = MYSQL_BOTH;
2331
-		if ($t=='SPIP_ASSOC') $t = MYSQL_ASSOC;
2326
+		if ($t == 'SPIP_NUM') $t = MYSQL_NUM;
2327
+		if ($t == 'SPIP_BOTH') $t = MYSQL_BOTH;
2328
+		if ($t == 'SPIP_ASSOC') $t = MYSQL_ASSOC;
2332 2329
 		spip_log("appel deprecie de spip_fetch_array(..., $t)", 'vieilles_defs');
2333 2330
 		if ($r) return mysql_fetch_array($r, $t);
2334 2331
 	}
@@ -2344,7 +2341,7 @@  discard block
 block discarded – undo
2344 2341
  * @param string $message
2345 2342
  * @param string $statut
2346 2343
  */
2347
-function avertir_auteurs($nom,$message, $statut=''){
2344
+function avertir_auteurs($nom, $message, $statut = '') {
2348 2345
 	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
2349 2346
 	if (!$alertes
2350 2347
 		OR !is_array($alertes = unserialize($alertes)))
@@ -2353,6 +2350,6 @@  discard block
 block discarded – undo
2353 2350
 	if (!isset($alertes[$statut]))
2354 2351
 		$alertes[$statut] = array();
2355 2352
 	$alertes[$statut][$nom] = $message;
2356
-	ecrire_meta("message_alertes_auteurs",serialize($alertes));
2353
+	ecrire_meta("message_alertes_auteurs", serialize($alertes));
2357 2354
 }
2358 2355
 ?>
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()) {
@@ -465,8 +511,9 @@  discard block
 block discarded – undo
465 511
 	$url = str_replace(array("'", '"', '<', '[', ']'), array('%27', '%22', '%3C', '%5B', '%5D'), $url);
466 512
 
467 513
 	// &amp; ?
468
-	if ($amp != '&amp;')
469
-		$url = str_replace('&amp;', $amp, $url);
514
+	if ($amp != '&amp;') {
515
+			$url = str_replace('&amp;', $amp, $url);
516
+	}
470 517
 
471 518
 	// Si ca demarre par ? ou vide, donner './'
472 519
 	$url = preg_replace(',^([?].*)?$,', './\1', $url);
@@ -507,8 +554,9 @@  discard block
 block discarded – undo
507 554
 	$o = array('class'=>'', 'force'=>true);
508 555
 	if ($options){
509 556
 		// support de l'ancien argument $class
510
-		if (is_string($options))
511
-			$options = array('class'=>$options);
557
+		if (is_string($options)) {
558
+					$options = array('class'=>$options);
559
+		}
512 560
 		$o = array_merge($o,$options);
513 561
 	}
514 562
 
@@ -531,16 +579,18 @@  discard block
 block discarded – undo
531 579
 	$text = $traduire($texte, $lang);
532 580
 
533 581
 	if (!strlen($text)){
534
-		if (!$o['force'])
535
-			return '';
582
+		if (!$o['force']) {
583
+					return '';
584
+		}
536 585
 
537 586
 		$text = $texte;
538 587
 
539 588
 		// pour les chaines non traduites, assurer un service minimum
540
-		if (!$GLOBALS['test_i18n'] AND (_request('var_mode') != 'traduction'))
541
-			$text = str_replace('_', ' ',
589
+		if (!$GLOBALS['test_i18n'] AND (_request('var_mode') != 'traduction')) {
590
+					$text = str_replace('_', ' ',
542 591
 				 (($n = strpos($text,':')) === false ? $texte :
543 592
 					substr($texte, $n+1)));
593
+		}
544 594
 		$o['class'] = null;
545 595
 
546 596
 	}
@@ -556,29 +606,34 @@  discard block
 block discarded – undo
556 606
 	$f = $text;
557 607
 	if (is_array($args)) {
558 608
 		foreach ($args as $name => $value) {
559
-			if ($class)
560
-				$value = "<span class='$class'>$value</span>";
609
+			if ($class) {
610
+							$value = "<span class='$class'>$value</span>";
611
+			}
561 612
 			$t = str_replace ("@$name@", $value, $text);
562 613
 			if ($text !== $t) {unset($args[$name]); $text = $t;}
563 614
 		}
564 615
 		// Si des variables n'ont pas ete inserees, le signaler
565 616
 		// (chaines de langues pas a jour)
566
-		if ($args) spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)),_LOG_DEBUG);
617
+		if ($args) {
618
+		    spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)),_LOG_DEBUG);
619
+		}
567 620
 	}
568 621
 
569
-	if (($GLOBALS['test_i18n'] OR (_request('var_mode') == 'traduction')) AND $class===null)
570
-		return "<span class=debug-traduction-erreur>$text</span>";
571
-	else
572
-		return $text;
573
-}
622
+	if (($GLOBALS['test_i18n'] OR (_request('var_mode') == 'traduction')) AND $class===null) {
623
+			return "<span class=debug-traduction-erreur>$text</span>";
624
+	} else {
625
+			return $text;
626
+	}
627
+	}
574 628
 
575 629
 // Afficher "ecrire/data/" au lieu de "data/" dans les messages
576 630
 // ou tmp/ au lieu de ../tmp/
577 631
 // http://doc.spip.org/@joli_repertoire
578 632
 function joli_repertoire($rep) {
579 633
 	$a = substr($rep,0,1);
580
-	if ($a<>'.' AND $a<>'/')
581
-		$rep = (_DIR_RESTREINT?'':_DIR_RESTREINT_ABS).$rep;
634
+	if ($a<>'.' AND $a<>'/') {
635
+			$rep = (_DIR_RESTREINT?'':_DIR_RESTREINT_ABS).$rep;
636
+	}
582 637
 	$rep = preg_replace(',(^\.\.\/),', '', $rep);
583 638
 	return $rep;
584 639
 }
@@ -593,7 +648,10 @@  discard block
 block discarded – undo
593 648
 	$a=time(); $b=microtime();
594 649
 	// microtime peut contenir les microsecondes et le temps
595 650
 	$b=explode(' ',$b);
596
-	if (count($b)==2) $a = end($b); // plus precis !
651
+	if (count($b)==2) {
652
+	    $a = end($b);
653
+	}
654
+	// plus precis !
597 655
 	$b = reset($b);
598 656
 	if (!isset($time[$t])) {
599 657
 		$time[$t] = $a + $b;
@@ -601,10 +659,12 @@  discard block
 block discarded – undo
601 659
 		$p = ($a + $b - $time[$t]) * 1000;
602 660
 		unset($time[$t]);
603 661
 #			echo "'$p'";exit;
604
-		if ($raw) return $p;
605
-		if ($p < 1000)
606
-			$s = '';
607
-		else {
662
+		if ($raw) {
663
+		    return $p;
664
+		}
665
+		if ($p < 1000) {
666
+					$s = '';
667
+		} else {
608 668
 			$s = sprintf("%d ", $x = floor($p/1000));
609 669
 			$p -= ($x*1000);
610 670
 		}
@@ -619,8 +679,9 @@  discard block
 block discarded – undo
619 679
 function spip_touch($fichier, $duree=0, $touch=true) {
620 680
 	if ($duree) {
621 681
 		clearstatcache();
622
-		if ((@$f=filemtime($fichier)) AND ($f >= time() - $duree))
623
-			return false;
682
+		if ((@$f=filemtime($fichier)) AND ($f >= time() - $duree)) {
683
+					return false;
684
+		}
624 685
 	}
625 686
 	if ($touch!==false) {
626 687
 		if (!@touch($fichier)) { spip_unlink($fichier); @touch($fichier); };
@@ -663,13 +724,20 @@  discard block
 block discarded – undo
663 724
  */
664 725
 function cron ($taches=array(), $taches_old= array()) {
665 726
 	// si pas en mode cron force, laisser tomber.
666
-	if (!defined('_DIRECT_CRON_FORCE')) return false;
667
-	if (!is_array($taches)) $taches = $taches_old; // compat anciens appels
727
+	if (!defined('_DIRECT_CRON_FORCE')) {
728
+	    return false;
729
+	}
730
+	if (!is_array($taches)) {
731
+	    $taches = $taches_old;
732
+	}
733
+	// compat anciens appels
668 734
 	// si taches a inserer en base et base inaccessible, laisser tomber
669 735
 	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
670 736
 	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
671 737
 	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
672
-	if ($taches AND count($taches) AND !spip_connect())  return false;
738
+	if ($taches AND count($taches) AND !spip_connect()) {
739
+	    return false;
740
+	}
673 741
 	spip_log("cron !",'jq'._LOG_DEBUG);
674 742
 	if ($genie = charger_fonction('genie', 'inc', true)) {
675 743
 		return $genie($taches);
@@ -743,28 +811,31 @@  discard block
 block discarded – undo
743 811
  */
744 812
 function queue_sleep_time_to_next_job($force=null) {
745 813
 	static $queue_next_job_time = -1;
746
-	if ($force===true)
747
-		$queue_next_job_time = -1;
748
-	elseif ($force)
749
-		$queue_next_job_time = $force;
814
+	if ($force===true) {
815
+			$queue_next_job_time = -1;
816
+	} elseif ($force) {
817
+			$queue_next_job_time = $force;
818
+	}
750 819
 
751 820
 	if ($queue_next_job_time==-1) {
752 821
 		define('_JQ_NEXT_JOB_TIME_FILENAME',_DIR_TMP . "job_queue_next.txt");
753 822
 		// utiliser un cache memoire si dispo
754 823
 		if (include_spip('inc/memoization') AND defined('_MEMOIZE_MEMORY') AND _MEMOIZE_MEMORY) {
755 824
 			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
756
-		}
757
-		else {
825
+		} else {
758 826
 			$queue_next_job_time = null;
759
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu))
760
-				$queue_next_job_time = intval($contenu);
827
+			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
828
+							$queue_next_job_time = intval($contenu);
829
+			}
761 830
 		}
762 831
 	}
763 832
 
764
-	if (is_null($queue_next_job_time))
765
-		return null;
766
-	if (!$_SERVER['REQUEST_TIME'])
767
-		$_SERVER['REQUEST_TIME'] = time();
833
+	if (is_null($queue_next_job_time)) {
834
+			return null;
835
+	}
836
+	if (!$_SERVER['REQUEST_TIME']) {
837
+			$_SERVER['REQUEST_TIME'] = time();
838
+	}
768 839
 	return $queue_next_job_time-$_SERVER['REQUEST_TIME'];
769 840
 }
770 841
 
@@ -786,14 +857,17 @@  discard block
 block discarded – undo
786 857
 		$done[$src] = true;
787 858
 		$src = find_in_path($src, _JAVASCRIPT);
788 859
 		$src = " src='$src'";
860
+	} else {
861
+	    $src = '';
789 862
 	}
790
-	else $src = '';
791
-	if ($script)
792
-		$script = ("/*<![CDATA[*/\n" .
863
+	if ($script) {
864
+			$script = ("/*<![CDATA[*/\n" .
793 865
 		preg_replace(',</([^>]*)>,','<\/\1>', $script) .
794 866
 		"/*]]>*/");
795
-	if ($noscript)
796
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
867
+	}
868
+	if ($noscript) {
869
+			$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
870
+	}
797 871
 
798 872
 	return ($src OR $script OR $noscript)
799 873
 	? "<script type='text/javascript'$src>$script</script>$noscript"
@@ -826,43 +900,53 @@  discard block
 block discarded – undo
826 900
 			_DIR_RACINE.'prive/:'.
827 901
 			_DIR_RESTREINT;
828 902
 		// Ajouter squelettes/
829
-		if (@is_dir(_DIR_RACINE.'squelettes'))
830
-			$path = _DIR_RACINE.'squelettes/:' . $path;
903
+		if (@is_dir(_DIR_RACINE.'squelettes')) {
904
+					$path = _DIR_RACINE.'squelettes/:' . $path;
905
+		}
831 906
 		foreach (explode(':', $path) as $dir) {
832
-			if (strlen($dir) AND substr($dir,-1) != '/')
833
-				$dir .= "/";
907
+			if (strlen($dir) AND substr($dir,-1) != '/') {
908
+							$dir .= "/";
909
+			}
834 910
 			$path_base[] = $dir;
835 911
 		}
836 912
 		$path_full = $path_base;
837 913
 		// Et le(s) dossier(s) des squelettes nommes
838
-		if (strlen($GLOBALS['dossier_squelettes']))
839
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
914
+		if (strlen($GLOBALS['dossier_squelettes'])) {
915
+					foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
840 916
 				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
917
+		}
841 918
 		$GLOBALS['path_sig'] = md5(serialize($path_full));
842 919
 	}
843
-	if ($dir_path===NULL) return $path_full;
920
+	if ($dir_path===NULL) {
921
+	    return $path_full;
922
+	}
844 923
 
845 924
 	if (strlen($dir_path)){
846 925
 		$tete = "";
847
-		if (reset($path_base)==_DIR_RACINE.'squelettes/')
848
-			$tete = array_shift($path_base);
926
+		if (reset($path_base)==_DIR_RACINE.'squelettes/') {
927
+					$tete = array_shift($path_base);
928
+		}
849 929
 		$dirs = array_reverse(explode(':',$dir_path));
850 930
 		foreach($dirs as $dir_path){
851 931
 				#if ($dir_path{0}!='/')
852 932
 				#	$dir_path = $dir_path;
853
-				if (substr($dir_path,-1) != '/')
854
-					$dir_path .= "/";
855
-				if (!in_array($dir_path,$path_base))
856
-					array_unshift($path_base,$dir_path);
933
+				if (substr($dir_path,-1) != '/') {
934
+									$dir_path .= "/";
935
+				}
936
+				if (!in_array($dir_path,$path_base)) {
937
+									array_unshift($path_base,$dir_path);
938
+				}
939
+		}
940
+		if (strlen($tete)) {
941
+					array_unshift($path_base,$tete);
857 942
 		}
858
-		if (strlen($tete))
859
-			array_unshift($path_base,$tete);
860 943
 	}
861 944
 	$path_full = $path_base;
862 945
 	// Et le(s) dossier(s) des squelettes nommes
863
-	if (strlen($GLOBALS['dossier_squelettes']))
864
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
946
+	if (strlen($GLOBALS['dossier_squelettes'])) {
947
+			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d)
865 948
 			array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
949
+	}
866 950
 
867 951
 	$GLOBALS['path_sig'] = md5(serialize($path_full));
868 952
 	return $path_full;
@@ -887,8 +971,9 @@  discard block
 block discarded – undo
887 971
 	static $themes = null;
888 972
 	if (is_null($themes)){
889 973
 		// si pas encore definie
890
-		if (!defined('_SPIP_THEME_PRIVE'))
891
-			define('_SPIP_THEME_PRIVE', 'spip');
974
+		if (!defined('_SPIP_THEME_PRIVE')) {
975
+					define('_SPIP_THEME_PRIVE', 'spip');
976
+		}
892 977
 		$themes = array(_SPIP_THEME_PRIVE);
893 978
 		// lors d'une installation neuve, prefs n'est pas definie.
894 979
 		if (isset($GLOBALS['visiteur_session']['prefs'])) {
@@ -896,24 +981,30 @@  discard block
 block discarded – undo
896 981
 		} else {
897 982
 			$prefs = array();
898 983
 		}
899
-		if (is_string($prefs))
900
-			$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
984
+		if (is_string($prefs)) {
985
+					$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
986
+		}
901 987
 		if (
902 988
 			((isset($prefs['theme']) AND $theme = $prefs['theme'])
903 989
 			OR (isset($GLOBALS['theme_prive_defaut']) AND $theme = $GLOBALS['theme_prive_defaut']))
904
-			AND $theme != _SPIP_THEME_PRIVE)
905
-			array_unshift($themes,$theme); // placer le theme choisi en tete
990
+			AND $theme != _SPIP_THEME_PRIVE) {
991
+					array_unshift($themes,$theme);
992
+		}
993
+		// placer le theme choisi en tete
906 994
 	}
907 995
 	return $themes;
908 996
 }
909 997
 
910 998
 function find_in_theme($file, $subdir='', $include=false){
911 999
 	static $themefiles=array();
912
-	if (isset($themefiles["$subdir$file"])) return $themefiles["$subdir$file"];
1000
+	if (isset($themefiles["$subdir$file"])) {
1001
+	    return $themefiles["$subdir$file"];
1002
+	}
913 1003
 	$themes = lister_themes_prives();
914 1004
 	foreach($themes as $theme){
915
-		if ($f = find_in_path($file,"prive/themes/$theme/$subdir",$include))
916
-			return $themefiles["$subdir$file"] = $f;
1005
+		if ($f = find_in_path($file,"prive/themes/$theme/$subdir",$include)) {
1006
+					return $themefiles["$subdir$file"] = $f;
1007
+		}
917 1008
 	}
918 1009
 	spip_log("$file introuvable dans le theme prive ".reset($themes),'theme');
919 1010
 	return $themefiles["$subdir$file"] = "";
@@ -928,18 +1019,23 @@  discard block
 block discarded – undo
928 1019
 function chemin_image($icone){
929 1020
 	static $icone_renommer;
930 1021
 	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
931
-	if (strpos($icone,"/")!==false AND file_exists($icone)) return $icone;
1022
+	if (strpos($icone,"/")!==false AND file_exists($icone)) {
1023
+	    return $icone;
1024
+	}
932 1025
 	
933 1026
 	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
934
-	if (preg_match(',[.](png|gif|jpg)$,',$icone) AND $f = find_in_theme("images/$icone"))
935
-		return $f;
1027
+	if (preg_match(',[.](png|gif|jpg)$,',$icone) AND $f = find_in_theme("images/$icone")) {
1028
+			return $f;
1029
+	}
936 1030
 	// sinon passer par le module de renommage
937
-	if (is_null($icone_renommer))
938
-		$icone_renommer = charger_fonction('icone_renommer','inc',true);
1031
+	if (is_null($icone_renommer)) {
1032
+			$icone_renommer = charger_fonction('icone_renommer','inc',true);
1033
+	}
939 1034
 	if ($icone_renommer){
940 1035
 		list($icone,$fonction) = $icone_renommer($icone,"");
941
-		if (file_exists($icone))
942
-			return $icone;
1036
+		if (file_exists($icone)) {
1037
+					return $icone;
1038
+		}
943 1039
 	}
944 1040
 	return find_in_path ($icone, _NOM_IMG_PACK);
945 1041
 }
@@ -965,8 +1061,9 @@  discard block
 block discarded – undo
965 1061
 	}
966 1062
 
967 1063
 	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
968
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])
969
-			return false;
1064
+		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1065
+					return false;
1066
+		}
970 1067
 		if ($include AND !isset($inc[$dirname][$file])) {
971 1068
 			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
972 1069
 			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
@@ -981,8 +1078,9 @@  discard block
 block discarded – undo
981 1078
 	}
982 1079
 
983 1080
 	foreach(creer_chemin() as $dir) {
984
-		if (!isset($dirs[$a = $dir . $dirname]))
985
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a) ;
1081
+		if (!isset($dirs[$a = $dir . $dirname])) {
1082
+					$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a) ;
1083
+		}
986 1084
 		if ($dirs[$a]) {
987 1085
 			if (file_exists(_ROOT_CWD . ($a .= $file))) {
988 1086
 				if ($include AND !isset($inc[$dirname][$file])) {
@@ -991,7 +1089,9 @@  discard block
 block discarded – undo
991 1089
 				}
992 1090
 				if (!defined('_SAUVER_CHEMIN')){
993 1091
 					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
994
-					if (is_null($GLOBALS['path_files'])) return $a;
1092
+					if (is_null($GLOBALS['path_files'])) {
1093
+					    return $a;
1094
+					}
995 1095
 					define('_SAUVER_CHEMIN', true);
996 1096
 				}
997 1097
 				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
@@ -1004,8 +1104,9 @@  discard block
 block discarded – undo
1004 1104
 		if ($include==='required'){
1005 1105
 			echo '<pre>',
1006 1106
 			"<strong>Erreur Fatale</strong><br />";
1007
-			if (function_exists('debug_print_backtrace'))
1008
-				echo debug_print_backtrace();
1107
+			if (function_exists('debug_print_backtrace')) {
1108
+							echo debug_print_backtrace();
1109
+			}
1009 1110
 			echo '</pre>';
1010 1111
 			die("Erreur interne: ne peut inclure $dirname$file");
1011 1112
 		}
@@ -1013,7 +1114,9 @@  discard block
 block discarded – undo
1013 1114
 
1014 1115
 	if (!defined('_SAUVER_CHEMIN')){
1015 1116
 		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1016
-		if (is_null($GLOBALS['path_files'])) return false;
1117
+		if (is_null($GLOBALS['path_files'])) {
1118
+		    return false;
1119
+		}
1017 1120
 		define('_SAUVER_CHEMIN', true);
1018 1121
 	}
1019 1122
 	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
@@ -1045,8 +1148,9 @@  discard block
 block discarded – undo
1045 1148
 			// mais si semble corrompu on relit avec un verrou
1046 1149
 			if (!$GLOBALS['path_files']=unserialize($contenu)){
1047 1150
 				lire_fichier(_CACHE_CHEMIN,$contenu);
1048
-				if (!$GLOBALS['path_files']=unserialize($contenu))
1049
-					$GLOBALS['path_files'] = array();
1151
+				if (!$GLOBALS['path_files']=unserialize($contenu)) {
1152
+									$GLOBALS['path_files'] = array();
1153
+				}
1050 1154
 			}
1051 1155
 		}
1052 1156
 	}
@@ -1054,9 +1158,10 @@  discard block
 block discarded – undo
1054 1158
 
1055 1159
 function save_path_cache(){
1056 1160
 	if (defined('_SAUVER_CHEMIN')
1057
-		AND _SAUVER_CHEMIN)
1058
-		ecrire_fichier(_CACHE_CHEMIN,serialize($GLOBALS['path_files']));
1059
-}
1161
+		AND _SAUVER_CHEMIN) {
1162
+			ecrire_fichier(_CACHE_CHEMIN,serialize($GLOBALS['path_files']));
1163
+	}
1164
+	}
1060 1165
 
1061 1166
 
1062 1167
 /**
@@ -1084,8 +1189,9 @@  discard block
 block discarded – undo
1084 1189
 				// ne prendre que les fichiers pas deja trouves
1085 1190
 				// car find_in_path prend le premier qu'il trouve,
1086 1191
 				// les autres sont donc masques
1087
-				if (!isset($liste_fichiers[$nom]))
1088
-					$liste_fichiers[$nom] = $chemin;
1192
+				if (!isset($liste_fichiers[$nom])) {
1193
+									$liste_fichiers[$nom] = $chemin;
1194
+				}
1089 1195
 			}
1090 1196
 		}
1091 1197
 	}
@@ -1128,13 +1234,18 @@  discard block
 block discarded – undo
1128 1234
  */
1129 1235
 function generer_url_entite($id='', $entite='', $args='', $ancre='', $public=NULL, $type=NULL)
1130 1236
 {
1131
-	if ($public === NULL) $public = !test_espace_prive();
1237
+	if ($public === NULL) {
1238
+	    $public = !test_espace_prive();
1239
+	}
1132 1240
 	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1133 1241
 
1134 1242
 	if (!$public) {
1135
-		if (!$entite) return '';
1136
-		if (!function_exists('generer_url_ecrire_objet'))
1137
-			include_spip('inc/urls');
1243
+		if (!$entite) {
1244
+		    return '';
1245
+		}
1246
+		if (!function_exists('generer_url_ecrire_objet')) {
1247
+					include_spip('inc/urls');
1248
+		}
1138 1249
 		$res = generer_url_ecrire_objet($entite,$id, $args, $ancre, false);
1139 1250
 	} else {
1140 1251
 		if ($type === NULL) {
@@ -1146,32 +1257,42 @@  discard block
 block discarded – undo
1146 1257
 
1147 1258
 		$f = charger_fonction($type, 'urls', true);
1148 1259
 		// se rabattre sur les urls page si les urls perso non dispo
1149
-		if (!$f) $f = charger_fonction('page', 'urls', true);
1260
+		if (!$f) {
1261
+		    $f = charger_fonction('page', 'urls', true);
1262
+		}
1150 1263
 
1151 1264
 		// si $entite='', on veut la fonction de passage URL ==> id
1152 1265
 		// sinon on veut effectuer le passage id ==> URL
1153
-		if (!$entite) return $f;
1266
+		if (!$entite) {
1267
+		    return $f;
1268
+		}
1154 1269
 
1155 1270
 		// mais d'abord il faut tester le cas des urls sur une
1156 1271
 		// base distante
1157 1272
 		if (is_string($public)
1158
-		AND $g = charger_fonction('connect', 'urls', true))
1159
-			$f = $g;
1273
+		AND $g = charger_fonction('connect', 'urls', true)) {
1274
+					$f = $g;
1275
+		}
1160 1276
 
1161 1277
 		$res = $f(intval($id), $entite, $args, $ancre, $public);
1162 1278
 
1163 1279
 	}
1164
-	if ($res) return $res;
1280
+	if ($res) {
1281
+	    return $res;
1282
+	}
1165 1283
 	// Sinon c'est un raccourci ou compat SPIP < 2
1166 1284
 	if (!function_exists($f = 'generer_url_' . $entite)) {
1167
-		if (!function_exists($f .= '_dist')) $f = '';
1285
+		if (!function_exists($f .= '_dist')) {
1286
+		    $f = '';
1287
+		}
1168 1288
 	}
1169 1289
 	if ($f) {
1170 1290
 		$url = $f($id, $args, $ancre);
1171
-		if (strlen($args))
1172
-			$url .= strstr($url, '?')
1291
+		if (strlen($args)) {
1292
+					$url .= strstr($url, '?')
1173 1293
 				? '&amp;'.$args
1174 1294
 				: '?'.$args;
1295
+		}
1175 1296
 		return $url;
1176 1297
 	}
1177 1298
 	// On a ete gentil mais la ....
@@ -1182,12 +1303,14 @@  discard block
 block discarded – undo
1182 1303
 function generer_url_ecrire_entite_edit($id, $entite, $args='', $ancre=''){
1183 1304
 	$exec = objet_info($entite,'url_edit');
1184 1305
 	$url = generer_url_ecrire($exec,$args);
1185
-	if (intval($id))
1186
-		$url = parametre_url($url,id_table_objet($entite),$id);
1187
-	else
1188
-		$url = parametre_url($url,'new','oui');
1189
-	if ($ancre)
1190
-		$url = ancre_url($url,$ancre);
1306
+	if (intval($id)) {
1307
+			$url = parametre_url($url,id_table_objet($entite),$id);
1308
+	} else {
1309
+			$url = parametre_url($url,'new','oui');
1310
+	}
1311
+	if ($ancre) {
1312
+			$url = ancre_url($url,$ancre);
1313
+	}
1191 1314
 	return $url;
1192 1315
 }
1193 1316
 
@@ -1207,8 +1330,9 @@  discard block
 block discarded – undo
1207 1330
 	if (preg_match(',[^\x00-\x7E],sS', $url)){
1208 1331
 		$uri = '';
1209 1332
 		for ($i=0; $i < strlen($url); $i++) {
1210
-			if (ord($a = $url[$i]) > 127)
1211
-				$a = rawurlencode($a);
1333
+			if (ord($a = $url[$i]) > 127) {
1334
+							$a = rawurlencode($a);
1335
+			}
1212 1336
 			$uri .= $a;
1213 1337
 		}
1214 1338
 		$url = $uri;
@@ -1219,7 +1343,9 @@  discard block
 block discarded – undo
1219 1343
 // http://doc.spip.org/@generer_url_entite_absolue
1220 1344
 function generer_url_entite_absolue($id='', $entite='', $args='', $ancre='', $connect=NULL)
1221 1345
 {
1222
-	if (!$connect) $connect = true;
1346
+	if (!$connect) {
1347
+	    $connect = true;
1348
+	}
1223 1349
 	$h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1224 1350
 	if (!preg_match(',^\w+:,', $h)) {
1225 1351
 		include_spip('inc/filtres_mini');
@@ -1232,7 +1358,9 @@  discard block
 block discarded – undo
1232 1358
 // variables d'environnement comme $_SERVER[HTTPS] ou ini_get(register_globals)
1233 1359
 // http://doc.spip.org/@test_valeur_serveur
1234 1360
 function test_valeur_serveur($truc) {
1235
-	if (!$truc) return false;
1361
+	if (!$truc) {
1362
+	    return false;
1363
+	}
1236 1364
 	return (strtolower($truc) !== 'off');
1237 1365
 }
1238 1366
 
@@ -1259,13 +1387,20 @@  discard block
 block discarded – undo
1259 1387
 function url_de_base($profondeur=null) {
1260 1388
 
1261 1389
 	static $url = array();
1262
-	if (is_array($profondeur)) return $url = $profondeur;
1263
-	if ($profondeur===false) return $url;
1390
+	if (is_array($profondeur)) {
1391
+	    return $url = $profondeur;
1392
+	}
1393
+	if ($profondeur===false) {
1394
+	    return $url;
1395
+	}
1264 1396
 
1265
-	if (is_null($profondeur)) $profondeur = $GLOBALS['profondeur_url'];
1397
+	if (is_null($profondeur)) {
1398
+	    $profondeur = $GLOBALS['profondeur_url'];
1399
+	}
1266 1400
 
1267
-	if (isset($url[$profondeur]))
1268
-		return $url[$profondeur];
1401
+	if (isset($url[$profondeur])) {
1402
+			return $url[$profondeur];
1403
+	}
1269 1404
 
1270 1405
 	$http = (
1271 1406
 		(isset($_SERVER["SCRIPT_URI"]) AND
@@ -1286,8 +1421,12 @@  discard block
 block discarded – undo
1286 1421
 	if (isset($_SERVER['SERVER_PORT'])
1287 1422
 		AND $port=$_SERVER['SERVER_PORT']
1288 1423
 		AND strpos($host,":")==false){
1289
-		if ($http=="http" AND $port!=80) $host.=":$port";
1290
-		if ($http=="https" AND $port!=443) $host.=":$port";
1424
+		if ($http=="http" AND $port!=80) {
1425
+		    $host.=":$port";
1426
+		}
1427
+		if ($http=="https" AND $port!=443) {
1428
+		    $host.=":$port";
1429
+		}
1291 1430
 	}
1292 1431
 	if (!$GLOBALS['REQUEST_URI']){
1293 1432
 		if (isset($_SERVER['REQUEST_URI'])) {
@@ -1295,8 +1434,9 @@  discard block
 block discarded – undo
1295 1434
 		} else {
1296 1435
 			$GLOBALS['REQUEST_URI'] = $_SERVER['PHP_SELF'];
1297 1436
 			if ($_SERVER['QUERY_STRING']
1298
-			AND !strpos($_SERVER['REQUEST_URI'], '?'))
1299
-				$GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
1437
+			AND !strpos($_SERVER['REQUEST_URI'], '?')) {
1438
+							$GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
1439
+			}
1300 1440
 		}
1301 1441
 	}
1302 1442
 
@@ -1345,18 +1485,22 @@  discard block
 block discarded – undo
1345 1485
 
1346 1486
 // http://doc.spip.org/@generer_url_ecrire
1347 1487
 function generer_url_ecrire($script='', $args="", $no_entities=false, $rel=false) {
1348
-	if (!$rel)
1349
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
1350
-	else if (!is_string($rel))
1351
-		$rel = _DIR_RESTREINT ? _DIR_RESTREINT :
1488
+	if (!$rel) {
1489
+			$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
1490
+	} else if (!is_string($rel)) {
1491
+			$rel = _DIR_RESTREINT ? _DIR_RESTREINT :
1352 1492
 			('./'  . _SPIP_ECRIRE_SCRIPT);
1493
+	}
1353 1494
 
1354 1495
 	@list($script, $ancre) = explode('#', $script);
1355
-	if ($script AND ($script<>'accueil' OR $rel))
1356
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
1357
-	elseif ($args)
1358
-		$args ="?$args";
1359
-	if ($ancre) $args .= "#$ancre";
1496
+	if ($script AND ($script<>'accueil' OR $rel)) {
1497
+			$args = "?exec=$script" . (!$args ? '' : "&$args");
1498
+	} elseif ($args) {
1499
+			$args ="?$args";
1500
+	}
1501
+	if ($ancre) {
1502
+	    $args .= "#$ancre";
1503
+	}
1360 1504
 	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
1361 1505
 }
1362 1506
 
@@ -1375,32 +1519,39 @@  discard block
 block discarded – undo
1375 1519
 // http://doc.spip.org/@get_spip_script
1376 1520
 function get_spip_script($default='') {
1377 1521
 	# cas define('_SPIP_SCRIPT', '');
1378
-	if (_SPIP_SCRIPT)
1379
-		return _SPIP_SCRIPT;
1380
-	else
1381
-		return $default;
1382
-}
1522
+	if (_SPIP_SCRIPT) {
1523
+			return _SPIP_SCRIPT;
1524
+	} else {
1525
+			return $default;
1526
+	}
1527
+	}
1383 1528
 
1384 1529
 // http://doc.spip.org/@generer_url_public
1385 1530
 function generer_url_public($script='', $args="", $no_entities=false, $rel=true, $action='') {
1386 1531
 	// si le script est une action (spip_pass, spip_inscription),
1387 1532
 	// standardiser vers la nouvelle API
1388 1533
 
1389
-	if (!$action) $action = get_spip_script();
1390
-	if ($script)
1391
-		$action = parametre_url($action, _SPIP_PAGE, $script, '&');
1534
+	if (!$action) {
1535
+	    $action = get_spip_script();
1536
+	}
1537
+	if ($script) {
1538
+			$action = parametre_url($action, _SPIP_PAGE, $script, '&');
1539
+	}
1392 1540
 
1393 1541
 	if ($args) {
1394 1542
 		if (is_array($args)) {
1395 1543
 			$r = '';
1396
-			foreach($args as $k => $v) $r .= '&' . $k . '=' . $v;
1544
+			foreach($args as $k => $v) {
1545
+			    $r .= '&' . $k . '=' . $v;
1546
+			}
1397 1547
 			$args = substr($r,1);
1398 1548
 		}
1399 1549
 		$action .=
1400 1550
 			(strpos($action, '?') !== false ? '&' : '?') . $args;
1401 1551
 	}
1402
-	if (!$no_entities)
1403
-		$action = quote_amp($action);
1552
+	if (!$no_entities) {
1553
+			$action = quote_amp($action);
1554
+	}
1404 1555
 
1405 1556
 	// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
1406 1557
 	return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(),'/') . preg_replace(",^/[.]/,","/","/$action"));
@@ -1478,9 +1629,13 @@  discard block
 block discarded – undo
1478 1629
 	  ? generer_url_ecrire(_request('exec'))
1479 1630
 	  :  generer_url_public('','',false,false);
1480 1631
 	$url = parametre_url($url,'action',$script);
1481
-	if ($args) $url .= quote_amp('&'.$args);
1632
+	if ($args) {
1633
+	    $url .= quote_amp('&'.$args);
1634
+	}
1482 1635
 
1483
-	if ($no_entities) $url = str_replace('&amp;','&',$url);
1636
+	if ($no_entities) {
1637
+	    $url = str_replace('&amp;','&',$url);
1638
+	}
1484 1639
 	return $url;
1485 1640
 }
1486 1641
 
@@ -1514,107 +1669,204 @@  discard block
 block discarded – undo
1514 1669
  */
1515 1670
 function spip_initialisation_core($pi=NULL, $pa=NULL, $ti=NULL, $ta=NULL) {
1516 1671
 	static $too_late = 0;
1517
-	if ($too_late++) return;
1672
+	if ($too_late++) {
1673
+	    return;
1674
+	}
1518 1675
 	
1519 1676
 	// Declaration des repertoires
1520 1677
 
1521 1678
 	// le nom du repertoire plugins/ activables/desactivables
1522
-	if (!defined('_DIR_PLUGINS')) define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
1679
+	if (!defined('_DIR_PLUGINS')) {
1680
+	    define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
1681
+	}
1523 1682
 
1524 1683
 	// le nom du repertoire des extensions/ permanentes du core, toujours actives
1525
-	if (!defined('_DIR_PLUGINS_DIST')) define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
1684
+	if (!defined('_DIR_PLUGINS_DIST')) {
1685
+	    define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
1686
+	}
1526 1687
 
1527 1688
 	// le nom du repertoire des librairies
1528
-	if (!defined('_DIR_LIB')) define('_DIR_LIB', _DIR_RACINE . "lib/");
1689
+	if (!defined('_DIR_LIB')) {
1690
+	    define('_DIR_LIB', _DIR_RACINE . "lib/");
1691
+	}
1529 1692
 	
1530
-	if (!defined('_DIR_IMG')) define('_DIR_IMG', $pa);
1531
-	if (!defined('_DIR_LOGOS')) define('_DIR_LOGOS', $pa);
1532
-	if (!defined('_DIR_IMG_ICONES')) define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
1533
-
1534
-	if (!defined('_DIR_DUMP')) define('_DIR_DUMP', $ti . "dump/");
1535
-	if (!defined('_DIR_SESSIONS')) define('_DIR_SESSIONS', $ti . "sessions/");
1536
-	if (!defined('_DIR_TRANSFERT')) define('_DIR_TRANSFERT', $ti . "upload/");
1537
-	if (!defined('_DIR_CACHE')) define('_DIR_CACHE', $ti . "cache/");
1538
-	if (!defined('_DIR_CACHE_XML')) define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
1539
-	if (!defined('_DIR_SKELS')) define('_DIR_SKELS',  _DIR_CACHE . "skel/");
1540
-	if (!defined('_DIR_AIDE')) define('_DIR_AIDE',  _DIR_CACHE . "aide/");
1541
-	if (!defined('_DIR_TMP')) define('_DIR_TMP', $ti);
1542
-
1543
-	if (!defined('_DIR_VAR')) define('_DIR_VAR', $ta);
1544
-
1545
-	if (!defined('_DIR_ETC')) define('_DIR_ETC', $pi);
1546
-	if (!defined('_DIR_CONNECT')) define('_DIR_CONNECT', $pi);
1547
-	if (!defined('_DIR_CHMOD')) define('_DIR_CHMOD', $pi);
1548
-
1549
-	if (!isset($GLOBALS['test_dirs']))
1550
-	  // Pas $pi car il est bon de le mettre hors ecriture apres intstall
1693
+	if (!defined('_DIR_IMG')) {
1694
+	    define('_DIR_IMG', $pa);
1695
+	}
1696
+	if (!defined('_DIR_LOGOS')) {
1697
+	    define('_DIR_LOGOS', $pa);
1698
+	}
1699
+	if (!defined('_DIR_IMG_ICONES')) {
1700
+	    define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
1701
+	}
1702
+
1703
+	if (!defined('_DIR_DUMP')) {
1704
+	    define('_DIR_DUMP', $ti . "dump/");
1705
+	}
1706
+	if (!defined('_DIR_SESSIONS')) {
1707
+	    define('_DIR_SESSIONS', $ti . "sessions/");
1708
+	}
1709
+	if (!defined('_DIR_TRANSFERT')) {
1710
+	    define('_DIR_TRANSFERT', $ti . "upload/");
1711
+	}
1712
+	if (!defined('_DIR_CACHE')) {
1713
+	    define('_DIR_CACHE', $ti . "cache/");
1714
+	}
1715
+	if (!defined('_DIR_CACHE_XML')) {
1716
+	    define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
1717
+	}
1718
+	if (!defined('_DIR_SKELS')) {
1719
+	    define('_DIR_SKELS',  _DIR_CACHE . "skel/");
1720
+	}
1721
+	if (!defined('_DIR_AIDE')) {
1722
+	    define('_DIR_AIDE',  _DIR_CACHE . "aide/");
1723
+	}
1724
+	if (!defined('_DIR_TMP')) {
1725
+	    define('_DIR_TMP', $ti);
1726
+	}
1727
+
1728
+	if (!defined('_DIR_VAR')) {
1729
+	    define('_DIR_VAR', $ta);
1730
+	}
1731
+
1732
+	if (!defined('_DIR_ETC')) {
1733
+	    define('_DIR_ETC', $pi);
1734
+	}
1735
+	if (!defined('_DIR_CONNECT')) {
1736
+	    define('_DIR_CONNECT', $pi);
1737
+	}
1738
+	if (!defined('_DIR_CHMOD')) {
1739
+	    define('_DIR_CHMOD', $pi);
1740
+	}
1741
+
1742
+	if (!isset($GLOBALS['test_dirs'])) {
1743
+		  // Pas $pi car il est bon de le mettre hors ecriture apres intstall
1551 1744
 	  // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
1552 1745
 		$GLOBALS['test_dirs'] =  array($pa, $ti, $ta);
1746
+	}
1553 1747
 
1554 1748
 	// Declaration des fichiers
1555 1749
 
1556
-	if (!defined('_CACHE_PLUGINS_PATH')) define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
1557
-	if (!defined('_CACHE_PLUGINS_OPT')) define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
1558
-	if (!defined('_CACHE_PLUGINS_FCT')) define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
1559
-	if (!defined('_CACHE_PIPELINES')) define('_CACHE_PIPELINES',  _DIR_CACHE."charger_pipelines.php");
1560
-	if (!defined('_CACHE_CHEMIN')) define('_CACHE_CHEMIN',  _DIR_CACHE."chemin.txt");
1750
+	if (!defined('_CACHE_PLUGINS_PATH')) {
1751
+	    define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
1752
+	}
1753
+	if (!defined('_CACHE_PLUGINS_OPT')) {
1754
+	    define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
1755
+	}
1756
+	if (!defined('_CACHE_PLUGINS_FCT')) {
1757
+	    define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
1758
+	}
1759
+	if (!defined('_CACHE_PIPELINES')) {
1760
+	    define('_CACHE_PIPELINES',  _DIR_CACHE."charger_pipelines.php");
1761
+	}
1762
+	if (!defined('_CACHE_CHEMIN')) {
1763
+	    define('_CACHE_CHEMIN',  _DIR_CACHE."chemin.txt");
1764
+	}
1561 1765
 
1562 1766
 	# attention .php obligatoire pour ecrire_fichier_securise
1563
-	if (!defined('_FILE_META')) define('_FILE_META', $ti . 'meta_cache.php');
1564
-	if (!defined('_DIR_LOG')) define('_DIR_LOG', _DIR_TMP . 'log/');
1565
-	if (!defined('_FILE_LOG')) define('_FILE_LOG', 'spip');
1566
-	if (!defined('_FILE_LOG_SUFFIX')) define('_FILE_LOG_SUFFIX', '.log');
1767
+	if (!defined('_FILE_META')) {
1768
+	    define('_FILE_META', $ti . 'meta_cache.php');
1769
+	}
1770
+	if (!defined('_DIR_LOG')) {
1771
+	    define('_DIR_LOG', _DIR_TMP . 'log/');
1772
+	}
1773
+	if (!defined('_FILE_LOG')) {
1774
+	    define('_FILE_LOG', 'spip');
1775
+	}
1776
+	if (!defined('_FILE_LOG_SUFFIX')) {
1777
+	    define('_FILE_LOG_SUFFIX', '.log');
1778
+	}
1567 1779
 
1568 1780
 	// Le fichier de connexion a la base de donnees
1569 1781
 	// tient compte des anciennes versions (inc_connect...)
1570
-	if (!defined('_FILE_CONNECT_INS')) define('_FILE_CONNECT_INS', 'connect');
1571
-	if (!defined('_FILE_CONNECT')) define('_FILE_CONNECT',
1782
+	if (!defined('_FILE_CONNECT_INS')) {
1783
+	    define('_FILE_CONNECT_INS', 'connect');
1784
+	}
1785
+	if (!defined('_FILE_CONNECT')) {
1786
+	    define('_FILE_CONNECT',
1572 1787
 		(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
1573 1788
 	:	(@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
1574 1789
 	:	false)));
1790
+	}
1575 1791
 
1576 1792
 	// Le fichier de reglages des droits
1577
-	if (!defined('_FILE_CHMOD_INS')) define('_FILE_CHMOD_INS', 'chmod');
1578
-	if (!defined('_FILE_CHMOD')) define('_FILE_CHMOD',
1793
+	if (!defined('_FILE_CHMOD_INS')) {
1794
+	    define('_FILE_CHMOD_INS', 'chmod');
1795
+	}
1796
+	if (!defined('_FILE_CHMOD')) {
1797
+	    define('_FILE_CHMOD',
1579 1798
 		(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
1580 1799
 	:	false));
1800
+	}
1581 1801
 
1582
-	if (!defined('_FILE_LDAP')) define('_FILE_LDAP', 'ldap.php');
1802
+	if (!defined('_FILE_LDAP')) {
1803
+	    define('_FILE_LDAP', 'ldap.php');
1804
+	}
1583 1805
 
1584
-	if (!defined('_FILE_TMP_SUFFIX')) define('_FILE_TMP_SUFFIX', '.tmp.php');
1585
-	if (!defined('_FILE_CONNECT_TMP')) define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
1586
-	if (!defined('_FILE_CHMOD_TMP')) define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
1806
+	if (!defined('_FILE_TMP_SUFFIX')) {
1807
+	    define('_FILE_TMP_SUFFIX', '.tmp.php');
1808
+	}
1809
+	if (!defined('_FILE_CONNECT_TMP')) {
1810
+	    define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
1811
+	}
1812
+	if (!defined('_FILE_CHMOD_TMP')) {
1813
+	    define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
1814
+	}
1587 1815
 
1588 1816
 	// Definition des droits d'acces en ecriture
1589
-	if (!defined('_SPIP_CHMOD') AND _FILE_CHMOD)
1590
-		include_once _FILE_CHMOD;
1817
+	if (!defined('_SPIP_CHMOD') AND _FILE_CHMOD) {
1818
+			include_once _FILE_CHMOD;
1819
+	}
1591 1820
 
1592 1821
 	// Se mefier des fichiers mal remplis!
1593
-	if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', 0777);
1822
+	if (!defined('_SPIP_CHMOD')) {
1823
+	    define('_SPIP_CHMOD', 0777);
1824
+	}
1594 1825
 
1595 1826
 	// Le charset par defaut lors de l'installation
1596
-	if (!defined('_DEFAULT_CHARSET')) define('_DEFAULT_CHARSET', 'utf-8');
1597
-	if (!defined('_ROOT_PLUGINS')) define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
1598
-	if (!defined('_ROOT_PLUGINS_DIST')) define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
1599
-	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));
1827
+	if (!defined('_DEFAULT_CHARSET')) {
1828
+	    define('_DEFAULT_CHARSET', 'utf-8');
1829
+	}
1830
+	if (!defined('_ROOT_PLUGINS')) {
1831
+	    define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
1832
+	}
1833
+	if (!defined('_ROOT_PLUGINS_DIST')) {
1834
+	    define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
1835
+	}
1836
+	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
1837
+	    define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE,'',_DIR_PLUGINS_SUPPL));
1838
+	}
1600 1839
 
1601 1840
 	// La taille des Log
1602
-	if (!defined('_MAX_LOG')) define('_MAX_LOG', 100);
1841
+	if (!defined('_MAX_LOG')) {
1842
+	    define('_MAX_LOG', 100);
1843
+	}
1603 1844
 
1604 1845
 	// Sommes-nous dans l'empire du Mal ?
1605 1846
 	// (ou sous le signe du Pingouin, ascendant GNU ?)
1606 1847
 	if (strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false){
1607
-		if (!defined('_OS_SERVEUR')) define('_OS_SERVEUR', 'windows');
1608
-		if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',1); // utiliser le flock php
1609
-	}
1610
-	else {
1611
-		if (!defined('_OS_SERVEUR')) define('_OS_SERVEUR', '');
1612
-		if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',1); // utiliser le flock php
1848
+		if (!defined('_OS_SERVEUR')) {
1849
+		    define('_OS_SERVEUR', 'windows');
1850
+		}
1851
+		if (!defined('_SPIP_LOCK_MODE')) {
1852
+		    define('_SPIP_LOCK_MODE',1);
1853
+		}
1854
+		// utiliser le flock php
1855
+	} else {
1856
+		if (!defined('_OS_SERVEUR')) {
1857
+		    define('_OS_SERVEUR', '');
1858
+		}
1859
+		if (!defined('_SPIP_LOCK_MODE')) {
1860
+		    define('_SPIP_LOCK_MODE',1);
1861
+		}
1862
+		// utiliser le flock php
1613 1863
 		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
1614 1864
 	}
1615 1865
 
1616 1866
 	// Langue par defaut
1617
-	if (!defined('_LANGUE_PAR_DEFAUT')) define('_LANGUE_PAR_DEFAUT','fr');
1867
+	if (!defined('_LANGUE_PAR_DEFAUT')) {
1868
+	    define('_LANGUE_PAR_DEFAUT','fr');
1869
+	}
1618 1870
 
1619 1871
 	// PHP_VERSION_ID dispo depuis PHP 5.2.7
1620 1872
 	if (!defined('PHP_VERSION_ID')) {
@@ -1639,7 +1891,9 @@  discard block
 block discarded – undo
1639 1891
 	//
1640 1892
 
1641 1893
 	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
1642
-	if (isset($_REQUEST['GLOBALS'])) die();
1894
+	if (isset($_REQUEST['GLOBALS'])) {
1895
+	    die();
1896
+	}
1643 1897
 	// nettoyer les magic quotes \' et les caracteres nuls %00
1644 1898
 	spip_desinfecte($_GET);
1645 1899
 	spip_desinfecte($_POST);
@@ -1658,8 +1912,9 @@  discard block
 block discarded – undo
1658 1912
 		// ne pas desinfecter les globales en profondeur car elle contient aussi les
1659 1913
 		// precedentes, qui seraient desinfectees 2 fois.
1660 1914
 		spip_desinfecte($GLOBALS,false);
1661
-		if (include_spip('inc/php3'))
1662
-			spip_register_globals(true);
1915
+		if (include_spip('inc/php3')) {
1916
+					spip_register_globals(true);
1917
+		}
1663 1918
 
1664 1919
 		$avertir_register_globals = true;
1665 1920
 	}
@@ -1688,12 +1943,15 @@  discard block
 block discarded – undo
1688 1943
 	} else {
1689 1944
 		$GLOBALS['REQUEST_URI'] = $_SERVER['PHP_SELF'];
1690 1945
 		if ($_SERVER['QUERY_STRING']
1691
-		AND !strpos($_SERVER['REQUEST_URI'], '?'))
1692
-			$GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
1946
+		AND !strpos($_SERVER['REQUEST_URI'], '?')) {
1947
+					$GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
1948
+		}
1693 1949
 	}
1694 1950
 
1695 1951
 	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
1696
-	if (!defined('_RENOUVELLE_ALEA')) define('_RENOUVELLE_ALEA', 12 * 3600);
1952
+	if (!defined('_RENOUVELLE_ALEA')) {
1953
+	    define('_RENOUVELLE_ALEA', 12 * 3600);
1954
+	}
1697 1955
 
1698 1956
 	// charger les meta si possible et renouveller l'alea au besoin
1699 1957
 	// charge aussi effacer_meta et ecrire_meta
@@ -1701,16 +1959,17 @@  discard block
 block discarded – undo
1701 1959
 	$inc_meta();
1702 1960
 
1703 1961
 	// on a pas pu le faire plus tot
1704
-	if  ($avertir_register_globals)
1705
-		avertir_auteurs("register_globals",_L("Probl&egrave;me de s&eacute;curit&eacute; : register_globals=on; dans php.ini &agrave; corriger."));
1962
+	if  ($avertir_register_globals) {
1963
+			avertir_auteurs("register_globals",_L("Probl&egrave;me de s&eacute;curit&eacute; : register_globals=on; dans php.ini &agrave; corriger."));
1964
+	}
1706 1965
 
1707 1966
 	// nombre de repertoires depuis la racine
1708 1967
 	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
1709 1968
 	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
1710 1969
 	// le calcul est faux)
1711
-	if (!_DIR_RESTREINT)
1712
-		$GLOBALS['profondeur_url'] = 1;
1713
-	else {
1970
+	if (!_DIR_RESTREINT) {
1971
+			$GLOBALS['profondeur_url'] = 1;
1972
+	} else {
1714 1973
 		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
1715 1974
 		$uri_ref = $_SERVER["SCRIPT_NAME"];
1716 1975
 		if (!$uri_ref
@@ -1723,13 +1982,13 @@  discard block
 block discarded – undo
1723 1982
 			if (isset($GLOBALS['meta']['adresse_site'])) {
1724 1983
 				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
1725 1984
 				$uri_ref = $uri_ref['path'].'/';
1726
-			}
1727
-		  else
1728
-			  $uri_ref = "";
1985
+			} else {
1986
+		  			  $uri_ref = "";
1987
+		  }
1729 1988
 		}
1730
-		if (!$uri OR !$uri_ref)
1731
-			$GLOBALS['profondeur_url'] = 0;
1732
-		else {
1989
+		if (!$uri OR !$uri_ref) {
1990
+					$GLOBALS['profondeur_url'] = 0;
1991
+		} else {
1733 1992
 			$GLOBALS['profondeur_url'] = max(0,
1734 1993
 				substr_count($uri[0], '/')
1735 1994
 				- substr_count($uri_ref,'/'));
@@ -1739,8 +1998,9 @@  discard block
 block discarded – undo
1739 1998
 	if (_FILE_CONNECT) {
1740 1999
 		if (verifier_visiteur()=='0minirezo'
1741 2000
 			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
1742
-		  AND !isset($_COOKIE['spip_admin']))
1743
-			clear_path_cache();
2001
+		  AND !isset($_COOKIE['spip_admin'])) {
2002
+					clear_path_cache();
2003
+		}
1744 2004
 	}
1745 2005
 
1746 2006
 }
@@ -1752,74 +2012,140 @@  discard block
 block discarded – undo
1752 2012
  */
1753 2013
 function spip_initialisation_suite() {
1754 2014
 	static $too_late = 0;
1755
-	if ($too_late++) return;
2015
+	if ($too_late++) {
2016
+	    return;
2017
+	}
1756 2018
 
1757 2019
 	// taille mini des login
1758
-	if (!defined('_LOGIN_TROP_COURT')) define('_LOGIN_TROP_COURT', 4);
2020
+	if (!defined('_LOGIN_TROP_COURT')) {
2021
+	    define('_LOGIN_TROP_COURT', 4);
2022
+	}
1759 2023
 
1760 2024
 	// la taille maxi des logos (0 : pas de limite)
1761
-	if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
1762
-	if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
1763
-	if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2025
+	if (!defined('_LOGO_MAX_SIZE')) {
2026
+	    define('_LOGO_MAX_SIZE', 0);
2027
+	}
2028
+	# poids en ko
2029
+	if (!defined('_LOGO_MAX_WIDTH')) {
2030
+	    define('_LOGO_MAX_WIDTH', 0);
2031
+	}
2032
+	# largeur en pixels
2033
+	if (!defined('_LOGO_MAX_HEIGHT')) {
2034
+	    define('_LOGO_MAX_HEIGHT', 0);
2035
+	}
2036
+	# hauteur en pixels
1764 2037
 
1765
-	if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2038
+	if (!defined('_DOC_MAX_SIZE')) {
2039
+	    define('_DOC_MAX_SIZE', 0);
2040
+	}
2041
+	# poids en ko
1766 2042
 
1767
-	if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
1768
-	if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
1769
-	if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
1770
-	if (!defined('_PASS_LONGUEUR_MINI')) define('_PASS_LONGUEUR_MINI',6);
2043
+	if (!defined('_IMG_MAX_SIZE')) {
2044
+	    define('_IMG_MAX_SIZE', 0);
2045
+	}
2046
+	# poids en ko
2047
+	if (!defined('_IMG_MAX_WIDTH')) {
2048
+	    define('_IMG_MAX_WIDTH', 0);
2049
+	}
2050
+	# largeur en pixels
2051
+	if (!defined('_IMG_MAX_HEIGHT')) {
2052
+	    define('_IMG_MAX_HEIGHT', 0);
2053
+	}
2054
+	# hauteur en pixels
2055
+	if (!defined('_PASS_LONGUEUR_MINI')) {
2056
+	    define('_PASS_LONGUEUR_MINI',6);
2057
+	}
1771 2058
 
1772 2059
 
1773 2060
 	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
1774
-        if (!defined('_IMG_QUALITE')) define('_IMG_QUALITE', 85); # valeur par defaut
1775
-        if (!defined('_IMG_GD_QUALITE')) define('_IMG_GD_QUALITE', _IMG_QUALITE); # surcharge pour la lib GD
1776
-        if (!defined('_IMG_CONVERT_QUALITE')) define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); # surcharge pour imagick en ligne de commande
2061
+        if (!defined('_IMG_QUALITE')) {
2062
+            define('_IMG_QUALITE', 85);
2063
+        }
2064
+        # valeur par defaut
2065
+        if (!defined('_IMG_GD_QUALITE')) {
2066
+            define('_IMG_GD_QUALITE', _IMG_QUALITE);
2067
+        }
2068
+        # surcharge pour la lib GD
2069
+        if (!defined('_IMG_CONVERT_QUALITE')) {
2070
+            define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2071
+        }
2072
+        # surcharge pour imagick en ligne de commande
1777 2073
 	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
1778
-        if (!defined('_IMG_IMAGICK_QUALITE')) define('_IMG_IMAGICK_QUALITE', 75); # surcharge pour imagick en PHP
2074
+        if (!defined('_IMG_IMAGICK_QUALITE')) {
2075
+            define('_IMG_IMAGICK_QUALITE', 75);
2076
+        }
2077
+        # surcharge pour imagick en PHP
1779 2078
 
1780
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) define('_COPIE_LOCALE_MAX_SIZE',16777216); // poids en octet
2079
+	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2080
+	    define('_COPIE_LOCALE_MAX_SIZE',16777216);
2081
+	}
2082
+	// poids en octet
1781 2083
 
1782 2084
 	// qq chaines standard
1783
-	if (!defined('_ACCESS_FILE_NAME')) define('_ACCESS_FILE_NAME', '.htaccess');
1784
-	if (!defined('_AUTH_USER_FILE')) define('_AUTH_USER_FILE', '.htpasswd');
1785
-	if (!defined('_SPIP_DUMP')) define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
1786
-	if (!defined('_CACHE_RUBRIQUES')) define('_CACHE_RUBRIQUES', _DIR_TMP.'menu-rubriques-cache.txt');
1787
-	if (!defined('_CACHE_RUBRIQUES_MAX')) define('_CACHE_RUBRIQUES_MAX', 500);
2085
+	if (!defined('_ACCESS_FILE_NAME')) {
2086
+	    define('_ACCESS_FILE_NAME', '.htaccess');
2087
+	}
2088
+	if (!defined('_AUTH_USER_FILE')) {
2089
+	    define('_AUTH_USER_FILE', '.htpasswd');
2090
+	}
2091
+	if (!defined('_SPIP_DUMP')) {
2092
+	    define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2093
+	}
2094
+	if (!defined('_CACHE_RUBRIQUES')) {
2095
+	    define('_CACHE_RUBRIQUES', _DIR_TMP.'menu-rubriques-cache.txt');
2096
+	}
2097
+	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2098
+	    define('_CACHE_RUBRIQUES_MAX', 500);
2099
+	}
1788 2100
 
1789
-	if (!defined('_EXTENSION_SQUELETTES')) define('_EXTENSION_SQUELETTES', 'html');
2101
+	if (!defined('_EXTENSION_SQUELETTES')) {
2102
+	    define('_EXTENSION_SQUELETTES', 'html');
2103
+	}
1790 2104
 
1791
-	if (!defined('_DOCTYPE_ECRIRE')) define('_DOCTYPE_ECRIRE',
2105
+	if (!defined('_DOCTYPE_ECRIRE')) {
2106
+	    define('_DOCTYPE_ECRIRE',
1792 2107
 		// "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>\n");
1793 2108
 		//"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n");
1794 2109
 		//"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n");
1795 2110
 	       // "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1 //EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>\n");
1796 2111
 		"<!DOCTYPE html>\n");
1797
-	if (!defined('_DOCTYPE_AIDE')) define('_DOCTYPE_AIDE',
2112
+	}
2113
+	if (!defined('_DOCTYPE_AIDE')) {
2114
+	    define('_DOCTYPE_AIDE',
1798 2115
 	       "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
2116
+	}
1799 2117
 
1800 2118
 	// L'adresse de base du site ; on peut mettre '' si la racine est geree par
1801 2119
 	// le script de l'espace public, alias  index.php
1802
-	if (!defined('_SPIP_SCRIPT')) define('_SPIP_SCRIPT', 'spip.php');
2120
+	if (!defined('_SPIP_SCRIPT')) {
2121
+	    define('_SPIP_SCRIPT', 'spip.php');
2122
+	}
1803 2123
 	// argument page, personalisable en cas de conflit avec un autre script
1804
-	if (!defined('_SPIP_PAGE')) define('_SPIP_PAGE', 'page');
2124
+	if (!defined('_SPIP_PAGE')) {
2125
+	    define('_SPIP_PAGE', 'page');
2126
+	}
1805 2127
 
1806 2128
 	// le script de l'espace prive
1807 2129
 	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
1808 2130
 	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
1809 2131
 	// meme pb sur thttpd cf. http://forum.spip.org/fr_184153.html
1810 2132
 
1811
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) define('_SPIP_ECRIRE_SCRIPT', // true ? #decommenter ici et commenter la
2133
+	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2134
+	    define('_SPIP_ECRIRE_SCRIPT', // true ? #decommenter ici et commenter la
1812 2135
 	       preg_match(',IIS|thttpd,',$_SERVER['SERVER_SOFTWARE']) ?
1813 2136
 	       'index.php' : '');
2137
+	}
1814 2138
 
1815 2139
 
1816
-	if (!defined('_SPIP_AJAX'))
1817
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2140
+	if (!defined('_SPIP_AJAX')) {
2141
+			define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
1818 2142
 			? 1
1819 2143
 		       : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2144
+	}
1820 2145
 
1821 2146
 	// La requete est-elle en ajax ?
1822
-	if (!defined('_AJAX')) define('_AJAX',
2147
+	if (!defined('_AJAX')) {
2148
+	    define('_AJAX',
1823 2149
 		(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
1824 2150
 		OR @$_REQUEST['var_ajax_redir'] # redirection 302 apres ajax jQuery
1825 2151
 		OR @$_REQUEST['var_ajaxcharset'] # compat ascendante pour plugins
@@ -1827,16 +2153,22 @@  discard block
 block discarded – undo
1827 2153
 		)
1828 2154
 		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
1829 2155
 	);
2156
+	}
1830 2157
 
1831 2158
 	# nombre de pixels maxi pour calcul de la vignette avec gd
1832 2159
 	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
1833 2160
 	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
1834
-	if (!defined('_IMG_GD_MAX_PIXELS')) define('_IMG_GD_MAX_PIXELS',
2161
+	if (!defined('_IMG_GD_MAX_PIXELS')) {
2162
+	    define('_IMG_GD_MAX_PIXELS',
1835 2163
 		(isset($GLOBALS['meta']['max_taille_vignettes'])&&$GLOBALS['meta']['max_taille_vignettes']<5500000)
1836 2164
 		 ? $GLOBALS['meta']['max_taille_vignettes']
1837 2165
 		 : 0);
2166
+	}
1838 2167
 
1839
-	if (!defined('_MEMORY_LIMIT_MIN')) define('_MEMORY_LIMIT_MIN',10); // en Mo
2168
+	if (!defined('_MEMORY_LIMIT_MIN')) {
2169
+	    define('_MEMORY_LIMIT_MIN',10);
2170
+	}
2171
+	// en Mo
1840 2172
 	// si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
1841 2173
 	// on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
1842 2174
 	// il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
@@ -1852,16 +2184,22 @@  discard block
 block discarded – undo
1852 2184
 			if ($memory<_MEMORY_LIMIT_MIN*1024*1024){
1853 2185
 				ini_set('memory_limit',$m=_MEMORY_LIMIT_MIN.'M');
1854 2186
 				if (trim(ini_get('memory_limit'))!=$m){
1855
-					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
2187
+					if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2188
+					    define('_INTERDIRE_COMPACTE_HEAD_ECRIRE',true);
2189
+					}
2190
+					// evite une page blanche car on ne saura pas calculer la css dans ce hit
1856 2191
 				}
1857 2192
 			}
1858
-		}
1859
-		else
1860
-			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
2193
+		} else
2194
+			if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2195
+			    define('_INTERDIRE_COMPACTE_HEAD_ECRIRE',true);
2196
+			}
2197
+			// evite une page blanche car on ne saura pas calculer la css dans ce hit
1861 2198
 	}
1862 2199
 	// Protocoles a normaliser dans les chaines de langues
1863
-	if (!defined('_PROTOCOLES_STD'))
1864
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2200
+	if (!defined('_PROTOCOLES_STD')) {
2201
+			define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2202
+	}
1865 2203
 
1866 2204
 	init_var_mode();
1867 2205
 }
@@ -1877,7 +2215,9 @@  discard block
 block discarded – undo
1877 2215
 			// tout le monde peut calcul/recalcul
1878 2216
 			if ($_GET['var_mode'] == 'calcul'
1879 2217
 			OR $_GET['var_mode'] == 'recalcul') {
1880
-				if (!defined('_VAR_MODE')) define('_VAR_MODE',$_GET['var_mode']);
2218
+				if (!defined('_VAR_MODE')) {
2219
+				    define('_VAR_MODE',$_GET['var_mode']);
2220
+				}
1881 2221
 			}
1882 2222
 			// preview, debug, blocs, urls et images necessitent une autorisation
1883 2223
 			else if (in_array($_GET['var_mode'],array('preview','debug','inclure','urls','images','traduction'))) {
@@ -1890,48 +2230,79 @@  discard block
 block discarded – undo
1890 2230
 					switch($_GET['var_mode']){
1891 2231
 						case 'traduction':
1892 2232
 							// forcer le calcul pour passer dans traduire
1893
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
2233
+							if (!defined('_VAR_MODE')) {
2234
+							    define('_VAR_MODE','calcul');
2235
+							}
1894 2236
 							// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
1895
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
2237
+							if (!defined('_VAR_NOCACHE')) {
2238
+							    define('_VAR_NOCACHE',true);
2239
+							}
1896 2240
 							break;
1897 2241
 						case 'preview':
1898 2242
 							// basculer sur les criteres de preview dans les boucles
1899
-							if (!defined('_VAR_PREVIEW')) define('_VAR_PREVIEW',true);
2243
+							if (!defined('_VAR_PREVIEW')) {
2244
+							    define('_VAR_PREVIEW',true);
2245
+							}
1900 2246
 							// forcer le calcul
1901
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
2247
+							if (!defined('_VAR_MODE')) {
2248
+							    define('_VAR_MODE','calcul');
2249
+							}
1902 2250
 							// et ne pas enregistrer de cache
1903
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
2251
+							if (!defined('_VAR_NOCACHE')) {
2252
+							    define('_VAR_NOCACHE',true);
2253
+							}
1904 2254
 							break;
1905 2255
 						case 'inclure':
1906 2256
 							// forcer le compilo et ignorer les caches existants
1907
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1908
-							if (!defined('_VAR_INCLURE')) define('_VAR_INCLURE',true);
2257
+							if (!defined('_VAR_MODE')) {
2258
+							    define('_VAR_MODE','calcul');
2259
+							}
2260
+							if (!defined('_VAR_INCLURE')) {
2261
+							    define('_VAR_INCLURE',true);
2262
+							}
1909 2263
 							// et ne pas enregistrer de cache
1910
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
2264
+							if (!defined('_VAR_NOCACHE')) {
2265
+							    define('_VAR_NOCACHE',true);
2266
+							}
1911 2267
 							break;
1912 2268
 						case 'urls':
1913 2269
 							// forcer le compilo et ignorer les caches existants
1914
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
1915
-							if (!defined('_VAR_URLS')) define('_VAR_URLS',true);
2270
+							if (!defined('_VAR_MODE')) {
2271
+							    define('_VAR_MODE','calcul');
2272
+							}
2273
+							if (!defined('_VAR_URLS')) {
2274
+							    define('_VAR_URLS',true);
2275
+							}
1916 2276
 							break;
1917 2277
 						case 'images':
1918 2278
 							// forcer le compilo et ignorer les caches existants
1919
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','calcul');
2279
+							if (!defined('_VAR_MODE')) {
2280
+							    define('_VAR_MODE','calcul');
2281
+							}
1920 2282
 							// indiquer qu'on doit recalculer les images
1921
-							if (!defined('_VAR_IMAGES')) define('_VAR_IMAGES',true);
2283
+							if (!defined('_VAR_IMAGES')) {
2284
+							    define('_VAR_IMAGES',true);
2285
+							}
1922 2286
 							break;
1923 2287
 						case 'debug':
1924
-							if (!defined('_VAR_MODE')) define('_VAR_MODE','debug');
2288
+							if (!defined('_VAR_MODE')) {
2289
+							    define('_VAR_MODE','debug');
2290
+							}
1925 2291
 							// et ne pas enregistrer de cache
1926
-							if (!defined('_VAR_NOCACHE')) define('_VAR_NOCACHE',true);
2292
+							if (!defined('_VAR_NOCACHE')) {
2293
+							    define('_VAR_NOCACHE',true);
2294
+							}
1927 2295
 							break;
1928 2296
 						default :
1929
-							if (!defined('_VAR_MODE')) define('_VAR_MODE',$_GET['var_mode']);
2297
+							if (!defined('_VAR_MODE')) {
2298
+							    define('_VAR_MODE',$_GET['var_mode']);
2299
+							}
1930 2300
 							break;
1931 2301
 					}
1932
-          if (isset($GLOBALS['visiteur_session']['nom']))
1933
-					spip_log($GLOBALS['visiteur_session']['nom']
2302
+          if (isset($GLOBALS['visiteur_session']['nom'])) {
2303
+          					spip_log($GLOBALS['visiteur_session']['nom']
1934 2304
 						. " "._VAR_MODE);
2305
+          }
1935 2306
 				}
1936 2307
 				// pas autorise ?
1937 2308
 				else {
@@ -1946,7 +2317,9 @@  discard block
 block discarded – undo
1946 2317
 					// sinon tant pis
1947 2318
 				}
1948 2319
 			}
1949
-			if (!defined('_VAR_MODE')) define('_VAR_MODE',false);
2320
+			if (!defined('_VAR_MODE')) {
2321
+			    define('_VAR_MODE',false);
2322
+			}
1950 2323
 		}
1951 2324
 		$done = true;
1952 2325
 	}
@@ -1958,18 +2331,21 @@  discard block
 block discarded – undo
1958 2331
 // http://doc.spip.org/@spip_desinfecte
1959 2332
 function spip_desinfecte(&$t,$deep = true) {
1960 2333
 	static $magic_quotes;
1961
-	if (!isset($magic_quotes))
1962
-		$magic_quotes = @get_magic_quotes_gpc();
2334
+	if (!isset($magic_quotes)) {
2335
+			$magic_quotes = @get_magic_quotes_gpc();
2336
+	}
1963 2337
 
1964 2338
 	foreach ($t as $key => $val) {
1965 2339
 		if (is_string($t[$key])) {
1966
-			if ($magic_quotes)
1967
-				$t[$key] = stripslashes($t[$key]);
2340
+			if ($magic_quotes) {
2341
+							$t[$key] = stripslashes($t[$key]);
2342
+			}
1968 2343
 			$t[$key] = str_replace(chr(0), '-', $t[$key]);
1969 2344
 		}
1970 2345
 		// traiter aussi les "texte_plus" de article_edit
1971
-		else if ($deep AND is_array($t[$key]) AND $key!=='GLOBALS')
1972
-			spip_desinfecte($t[$key],$deep);
2346
+		else if ($deep AND is_array($t[$key]) AND $key!=='GLOBALS') {
2347
+					spip_desinfecte($t[$key],$deep);
2348
+		}
1973 2349
 	}
1974 2350
 }
1975 2351
 
@@ -2004,11 +2380,13 @@  discard block
 block discarded – undo
2004 2380
 		$session = charger_fonction('session', 'inc');
2005 2381
 		$session();
2006 2382
 		include_spip('inc/texte');
2007
-		foreach($variables_session as $var)
2008
-			if (($a = _request($var)) !== null)
2383
+		foreach($variables_session as $var) {
2384
+					if (($a = _request($var)) !== null)
2009 2385
 				$GLOBALS['visiteur_session'][$var] = safehtml($a);
2010
-		if (!isset($GLOBALS['visiteur_session']['id_auteur']))
2011
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
2386
+		}
2387
+		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
2388
+					$GLOBALS['visiteur_session']['id_auteur'] = 0;
2389
+		}
2012 2390
 		$session($GLOBALS['visiteur_session']);
2013 2391
 		return 0;
2014 2392
 	}
@@ -2047,15 +2425,17 @@  discard block
 block discarded – undo
2047 2425
 // http://doc.spip.org/@lang_select
2048 2426
 function lang_select ($lang=NULL) {
2049 2427
 	static $pile_langues = array();
2050
-	if (!function_exists('changer_langue'))
2051
-		include_spip('inc/lang');
2052
-	if ($lang === NULL)
2053
-		$lang = array_pop($pile_langues);
2054
-	else {
2428
+	if (!function_exists('changer_langue')) {
2429
+			include_spip('inc/lang');
2430
+	}
2431
+	if ($lang === NULL) {
2432
+			$lang = array_pop($pile_langues);
2433
+	} else {
2055 2434
 		array_push($pile_langues, $GLOBALS['spip_lang']);
2056 2435
 	}
2057
-	if (isset($GLOBALS['spip_lang']) AND $lang == $GLOBALS['spip_lang'])
2058
-		return $lang;
2436
+	if (isset($GLOBALS['spip_lang']) AND $lang == $GLOBALS['spip_lang']) {
2437
+			return $lang;
2438
+	}
2059 2439
 	changer_langue($lang);
2060 2440
 	return $lang;
2061 2441
 }
@@ -2106,11 +2486,12 @@  discard block
 block discarded – undo
2106 2486
 // http://doc.spip.org/@exec_info_dist
2107 2487
 function exec_info_dist() {
2108 2488
 	global $connect_statut;
2109
-	if ($connect_statut == '0minirezo')
2110
-		phpinfo();
2111
-	else
2112
-		echo "pas admin";
2113
-}
2489
+	if ($connect_statut == '0minirezo') {
2490
+			phpinfo();
2491
+	} else {
2492
+			echo "pas admin";
2493
+	}
2494
+	}
2114 2495
 
2115 2496
 /**
2116 2497
  * Génère une erreur de squelette
@@ -2169,12 +2550,17 @@  discard block
 block discarded – undo
2169 2550
  * 		ou tableau d'information sur le squelette.
2170 2551
  */
2171 2552
 function recuperer_fond($fond, $contexte=array(), $options = array(), $connect='') {
2172
-	if (!function_exists('evaluer_fond'))
2173
-		include_spip('public/assembler');
2553
+	if (!function_exists('evaluer_fond')) {
2554
+			include_spip('public/assembler');
2555
+	}
2174 2556
 	// assurer la compat avec l'ancienne syntaxe
2175 2557
 	// (trim etait le 3eme argument, par defaut a true)
2176
-	if (!is_array($options)) $options = array('trim'=>$options);
2177
-	if (!isset($options['trim'])) $options['trim']=true;
2558
+	if (!is_array($options)) {
2559
+	    $options = array('trim'=>$options);
2560
+	}
2561
+	if (!isset($options['trim'])) {
2562
+	    $options['trim']=true;
2563
+	}
2178 2564
 
2179 2565
 	if (isset($contexte['connect'])){
2180 2566
 		$connect = ($connect ? $connect : $contexte['connect']);
@@ -2186,8 +2572,9 @@  discard block
 block discarded – undo
2186 2572
 	$lang_select = '';
2187 2573
 	if (!isset($options['etoile']) OR !$options['etoile']){
2188 2574
 		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
2189
-		if (!isset($contexte['lang']))
2190
-			$contexte['lang'] = $GLOBALS['spip_lang'];
2575
+		if (!isset($contexte['lang'])) {
2576
+					$contexte['lang'] = $GLOBALS['spip_lang'];
2577
+		}
2191 2578
 
2192 2579
 		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
2193 2580
 			$lang_select = lang_select($contexte['lang']);
@@ -2212,25 +2599,30 @@  discard block
 block discarded – undo
2212 2599
 			'data'=>$page
2213 2600
 		));
2214 2601
 		if (isset($options['ajax']) AND $options['ajax']){
2215
-			if (!function_exists('encoder_contexte_ajax'))
2216
-				include_spip('inc/filtres');
2602
+			if (!function_exists('encoder_contexte_ajax')) {
2603
+							include_spip('inc/filtres');
2604
+			}
2217 2605
 			$page['texte'] = encoder_contexte_ajax(array_merge($contexte,array('fond'=>$f)),'',$page['texte'], $options['ajax']);
2218 2606
 		}
2219 2607
 
2220
-		if (isset($options['raw']) AND $options['raw'])
2221
-			$pages[] = $page;
2222
-		else
2223
-			$texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
2608
+		if (isset($options['raw']) AND $options['raw']) {
2609
+					$pages[] = $page;
2610
+		} else {
2611
+					$texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
2612
+		}
2224 2613
 	}
2225 2614
 
2226 2615
 	$GLOBALS['_INC_PUBLIC']--;
2227 2616
 
2228
-	if ($lang_select) lang_select();
2229
-	if (isset($options['raw']) AND $options['raw'])
2230
-		return is_array($fond)?$pages:reset($pages);
2231
-	else
2232
-		return $options['trim'] ? ltrim($texte) : $texte;
2233
-}
2617
+	if ($lang_select) {
2618
+	    lang_select();
2619
+	}
2620
+	if (isset($options['raw']) AND $options['raw']) {
2621
+			return is_array($fond)?$pages:reset($pages);
2622
+	} else {
2623
+			return $options['trim'] ? ltrim($texte) : $texte;
2624
+	}
2625
+	}
2234 2626
 
2235 2627
 /**
2236 2628
  * Trouve un squelette dans le repertoire modeles/
@@ -2256,7 +2648,9 @@  discard block
 block discarded – undo
2256 2648
  */
2257 2649
 function trouver_fond($nom, $dir='', $pathinfo = false) {
2258 2650
 	$f = find_in_path($nom.'.'. _EXTENSION_SQUELETTES, $dir?rtrim($dir,'/').'/':'');
2259
-	if (!$pathinfo) return $f;
2651
+	if (!$pathinfo) {
2652
+	    return $f;
2653
+	}
2260 2654
 	// renvoyer un tableau detaille si $pathinfo==true
2261 2655
 	$p = pathinfo($f);
2262 2656
 	if (!isset($p['extension']) OR !$p['extension']) {
@@ -2271,16 +2665,21 @@  discard block
 block discarded – undo
2271 2665
 
2272 2666
 function tester_url_ecrire($nom){
2273 2667
 	static $exec=array();
2274
-	if (isset($exec[$nom])) return $exec[$nom];
2668
+	if (isset($exec[$nom])) {
2669
+	    return $exec[$nom];
2670
+	}
2275 2671
 	// tester si c'est une page en squelette
2276
-	if (trouver_fond($nom, 'prive/squelettes/contenu/'))
2277
-		return $exec[$nom] = 'fond';
2672
+	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
2673
+			return $exec[$nom] = 'fond';
2674
+	}
2278 2675
 	// compat skels orthogonaux version precedente
2279
-	elseif (trouver_fond($nom, 'prive/exec/'))
2280
-		return $exec[$nom] = 'fond_monobloc';
2676
+	elseif (trouver_fond($nom, 'prive/exec/')) {
2677
+			return $exec[$nom] = 'fond_monobloc';
2678
+	}
2281 2679
 	// echafaudage d'un fond !
2282
-	elseif(include_spip('public/styliser_par_z') AND z_echafaudable($nom))
2283
-		return $exec[$nom] = 'fond';
2680
+	elseif(include_spip('public/styliser_par_z') AND z_echafaudable($nom)) {
2681
+			return $exec[$nom] = 'fond';
2682
+	}
2284 2683
 	// attention, il ne faut pas inclure l'exec ici
2285 2684
 	// car sinon #URL_ECRIRE provoque des inclusions
2286 2685
 	// et des define intrusifs potentiels
@@ -2324,13 +2723,23 @@  discard block
 block discarded – undo
2324 2723
 // http://doc.spip.org/@spip_fetch_array
2325 2724
 function spip_fetch_array($r, $t=NULL) {
2326 2725
 	if (!isset($t)) {
2327
-		if ($r) return sql_fetch($r);
2726
+		if ($r) {
2727
+		    return sql_fetch($r);
2728
+		}
2328 2729
 	} else {
2329
-		if ($t=='SPIP_NUM') $t = MYSQL_NUM;
2330
-		if ($t=='SPIP_BOTH') $t = MYSQL_BOTH;
2331
-		if ($t=='SPIP_ASSOC') $t = MYSQL_ASSOC;
2730
+		if ($t=='SPIP_NUM') {
2731
+		    $t = MYSQL_NUM;
2732
+		}
2733
+		if ($t=='SPIP_BOTH') {
2734
+		    $t = MYSQL_BOTH;
2735
+		}
2736
+		if ($t=='SPIP_ASSOC') {
2737
+		    $t = MYSQL_ASSOC;
2738
+		}
2332 2739
 		spip_log("appel deprecie de spip_fetch_array(..., $t)", 'vieilles_defs');
2333
-		if ($r) return mysql_fetch_array($r, $t);
2740
+		if ($r) {
2741
+		    return mysql_fetch_array($r, $t);
2742
+		}
2334 2743
 	}
2335 2744
 }
2336 2745
 
@@ -2347,11 +2756,13 @@  discard block
 block discarded – undo
2347 2756
 function avertir_auteurs($nom,$message, $statut=''){
2348 2757
 	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
2349 2758
 	if (!$alertes
2350
-		OR !is_array($alertes = unserialize($alertes)))
2351
-		$alertes = array();
2759
+		OR !is_array($alertes = unserialize($alertes))) {
2760
+			$alertes = array();
2761
+	}
2352 2762
 
2353
-	if (!isset($alertes[$statut]))
2354
-		$alertes[$statut] = array();
2763
+	if (!isset($alertes[$statut])) {
2764
+			$alertes[$statut] = array();
2765
+	}
2355 2766
 	$alertes[$statut][$nom] = $message;
2356 2767
 	ecrire_meta("message_alertes_auteurs",serialize($alertes));
2357 2768
 }
Please login to merge, or discard this patch.
ecrire/iterateur/data.php 4 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 
106 106
 	/**
107 107
 	 * Declarer les criteres exceptions
108
-	 * @return array
108
+	 * @return string[]
109 109
 	 */
110 110
 	public function exception_des_criteres() {
111 111
 		return array('tableau');
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 
114 114
 	/**
115 115
 	 * Recuperer depuis le cache si possible
116
-	 * @param  $cle
116
+	 * @param  string|null $cle
117 117
 	 * @return
118 118
 	 */
119 119
 	protected function cache_get($cle) {
@@ -126,8 +126,8 @@  discard block
 block discarded – undo
126 126
 
127 127
 	/**
128 128
 	 * Stocker en cache si possible
129
-	 * @param  $cle
130
-	 * @param  $ttl
129
+	 * @param  string|null $cle
130
+	 * @param  integer $ttl
131 131
 	 * @return
132 132
 	 */
133 133
 	protected function cache_set($cle, $ttl, $valeur = null) {
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
  * lister des fichiers a partir d'un dossier de base et selon une regexp.
662 662
  * pour la syntaxe cf la fonction spip preg_files
663 663
  * @param string $dir
664
- * @param string $regexp
664
+ * @param integer $regexp
665 665
  * @param int $limit
666 666
  * @return array|bool
667 667
  */
@@ -694,7 +694,7 @@  discard block
 block discarded – undo
694 694
 
695 695
 /**
696 696
  * Object -> tableau
697
- * @param Object $object
697
+ * @param SimpleXMLIterator $object
698 698
  * @return array|bool
699 699
  */
700 700
 function XMLObjectToArray($object){
Please login to merge, or discard this patch.
Indentation   +532 added lines, -532 removed lines patch added patch discarded remove patch
@@ -23,16 +23,16 @@  discard block
 block discarded – undo
23 23
  * @return
24 24
  */
25 25
 function iterateur_DATA_dist($b) {
26
-	$b->iterateur = 'DATA'; # designe la classe d'iterateur
27
-	$b->show = array(
28
-		'field' => array(
29
-			'cle' => 'STRING',
30
-			'valeur' => 'STRING',
31
-			'*' => 'ALL' // Champ joker *
32
-		)
33
-	);
34
-	$b->select[] = '.valeur';
35
-	return $b;
26
+    $b->iterateur = 'DATA'; # designe la classe d'iterateur
27
+    $b->show = array(
28
+        'field' => array(
29
+            'cle' => 'STRING',
30
+            'valeur' => 'STRING',
31
+            '*' => 'ALL' // Champ joker *
32
+        )
33
+    );
34
+    $b->select[] = '.valeur';
35
+    return $b;
36 36
 }
37 37
 
38 38
 
@@ -40,453 +40,453 @@  discard block
 block discarded – undo
40 40
  * IterateurDATA pour iterer sur des donnees
41 41
  */
42 42
 class IterateurDATA implements Iterator {
43
-	/**
44
-	 * tableau de donnees
45
-	 * @var array
46
-	 */
47
-	protected $tableau = array();
48
-
49
-	/**
50
-	 * Conditions de filtrage
51
-	 * ie criteres de selection
52
-	 * @var array
53
-	 */
54
-	protected $filtre = array();
55
-
56
-
57
-	/**
58
-	 * Cle courante
59
-	 * @var null
60
-	 */
61
-	protected $cle = null;
62
-
63
-	/**
64
-	 * Valeur courante
65
-	 * @var null
66
-	 */
67
-	protected $valeur = null;
68
-
69
-	/**
70
-	 * Erreur presente ? 
71
-	 *
72
-	 * @var bool
73
-	**/
74
-	public $err = false;
75
-
76
-	/**
77
-	 * Calcul du total des elements 
78
-	 *
79
-	 * @var int|null
80
-	**/
81
-	public $total = null;
82
-
83
-	/**
84
-	 * Constructeur
85
-	 *
86
-	 * @param  $command
87
-	 * @param array $info
88
-	 */
89
-	public function __construct($command, $info=array()) {
90
-		$this->type='DATA';
91
-		$this->command = $command;
92
-		$this->info = $info;
93
-
94
-		$this->select($command);
95
-	}
96
-
97
-	/**
98
-	 * Revenir au depart
99
-	 * @return void
100
-	 */
101
-	public function rewind() {
102
-		reset($this->tableau);
103
-		list($this->cle, $this->valeur) = each($this->tableau);
104
-	}
105
-
106
-	/**
107
-	 * Declarer les criteres exceptions
108
-	 * @return array
109
-	 */
110
-	public function exception_des_criteres() {
111
-		return array('tableau');
112
-	}
113
-
114
-	/**
115
-	 * Recuperer depuis le cache si possible
116
-	 * @param  $cle
117
-	 * @return
118
-	 */
119
-	protected function cache_get($cle) {
120
-		if (!$cle) return;
121
-		# utiliser memoization si dispo
122
-		include_spip('inc/memoization');
123
-		if (!function_exists('cache_get')) return;
124
-		return cache_get($cle);
125
-	}
126
-
127
-	/**
128
-	 * Stocker en cache si possible
129
-	 * @param  $cle
130
-	 * @param  $ttl
131
-	 * @return
132
-	 */
133
-	protected function cache_set($cle, $ttl, $valeur = null) {
134
-		if (!$cle) return;
135
-		if (is_null($valeur)) {
136
-			$valeur = $this->tableau;
137
-		}
138
-		# utiliser memoization si dispo
139
-		include_spip('inc/memoization');
140
-		if (!function_exists('cache_set')) return;
141
-		return cache_set($cle,
142
-			array(
143
-				'data' => $valeur,
144
-				'time' => time(),
145
-				'ttl' => $ttl
146
-			),
147
-			3600 + $ttl);
148
-			# conserver le cache 1h de plus que la validite demandee,
149
-			# pour le cas ou le serveur distant ne reponde plus
150
-	}
151
-
152
-	/**
153
-	 * Aller chercher les donnees de la boucle DATA
154
-	 *
155
-	 * @throws Exception
156
-	 * @param  $command
157
-	 * @return void
158
-	 */
159
-	protected function select($command) {
160
-
161
-		// l'iterateur DATA peut etre appele en passant (data:type)
162
-		// le type se retrouve dans la commande 'from'
163
-		// dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument
164
-		if (isset($this->command['from'][0])) {
165
-			if (isset($this->command['source']) and is_array($this->command['source'])) {
166
-				array_unshift($this->command['source'], $this->command['sourcemode']);
167
-			}
168
-			$this->command['sourcemode'] = $this->command['from'][0];
169
-		}
170
-
171
-		// cherchons differents moyens de creer le tableau de donnees
172
-		// les commandes connues pour l'iterateur DATA
173
-		// sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...}
43
+    /**
44
+     * tableau de donnees
45
+     * @var array
46
+     */
47
+    protected $tableau = array();
48
+
49
+    /**
50
+     * Conditions de filtrage
51
+     * ie criteres de selection
52
+     * @var array
53
+     */
54
+    protected $filtre = array();
55
+
56
+
57
+    /**
58
+     * Cle courante
59
+     * @var null
60
+     */
61
+    protected $cle = null;
62
+
63
+    /**
64
+     * Valeur courante
65
+     * @var null
66
+     */
67
+    protected $valeur = null;
68
+
69
+    /**
70
+     * Erreur presente ? 
71
+     *
72
+     * @var bool
73
+     **/
74
+    public $err = false;
75
+
76
+    /**
77
+     * Calcul du total des elements 
78
+     *
79
+     * @var int|null
80
+     **/
81
+    public $total = null;
82
+
83
+    /**
84
+     * Constructeur
85
+     *
86
+     * @param  $command
87
+     * @param array $info
88
+     */
89
+    public function __construct($command, $info=array()) {
90
+        $this->type='DATA';
91
+        $this->command = $command;
92
+        $this->info = $info;
93
+
94
+        $this->select($command);
95
+    }
96
+
97
+    /**
98
+     * Revenir au depart
99
+     * @return void
100
+     */
101
+    public function rewind() {
102
+        reset($this->tableau);
103
+        list($this->cle, $this->valeur) = each($this->tableau);
104
+    }
105
+
106
+    /**
107
+     * Declarer les criteres exceptions
108
+     * @return array
109
+     */
110
+    public function exception_des_criteres() {
111
+        return array('tableau');
112
+    }
113
+
114
+    /**
115
+     * Recuperer depuis le cache si possible
116
+     * @param  $cle
117
+     * @return
118
+     */
119
+    protected function cache_get($cle) {
120
+        if (!$cle) return;
121
+        # utiliser memoization si dispo
122
+        include_spip('inc/memoization');
123
+        if (!function_exists('cache_get')) return;
124
+        return cache_get($cle);
125
+    }
126
+
127
+    /**
128
+     * Stocker en cache si possible
129
+     * @param  $cle
130
+     * @param  $ttl
131
+     * @return
132
+     */
133
+    protected function cache_set($cle, $ttl, $valeur = null) {
134
+        if (!$cle) return;
135
+        if (is_null($valeur)) {
136
+            $valeur = $this->tableau;
137
+        }
138
+        # utiliser memoization si dispo
139
+        include_spip('inc/memoization');
140
+        if (!function_exists('cache_set')) return;
141
+        return cache_set($cle,
142
+            array(
143
+                'data' => $valeur,
144
+                'time' => time(),
145
+                'ttl' => $ttl
146
+            ),
147
+            3600 + $ttl);
148
+            # conserver le cache 1h de plus que la validite demandee,
149
+            # pour le cas ou le serveur distant ne reponde plus
150
+    }
151
+
152
+    /**
153
+     * Aller chercher les donnees de la boucle DATA
154
+     *
155
+     * @throws Exception
156
+     * @param  $command
157
+     * @return void
158
+     */
159
+    protected function select($command) {
160
+
161
+        // l'iterateur DATA peut etre appele en passant (data:type)
162
+        // le type se retrouve dans la commande 'from'
163
+        // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument
164
+        if (isset($this->command['from'][0])) {
165
+            if (isset($this->command['source']) and is_array($this->command['source'])) {
166
+                array_unshift($this->command['source'], $this->command['sourcemode']);
167
+            }
168
+            $this->command['sourcemode'] = $this->command['from'][0];
169
+        }
170
+
171
+        // cherchons differents moyens de creer le tableau de donnees
172
+        // les commandes connues pour l'iterateur DATA
173
+        // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...}
174 174
 		
175
-		// {source format, [URL], [arg2]...}
176
-		if (isset($this->command['source'])
177
-		AND isset($this->command['sourcemode'])) {
178
-			$this->select_source();
179
-		}
180
-
181
-		// Critere {liste X1, X2, X3}
182
-		if (isset($this->command['liste'])) {
183
-			$this->select_liste();
184
-		}
185
-		if (isset($this->command['enum'])) {
186
-			$this->select_enum();
187
-		}
188
-
189
-		// Si a ce stade on n'a pas de table, il y a un bug
190
-		if (!is_array($this->tableau)) {
191
-			$this->err = true;
192
-			spip_log("erreur datasource ".var_export($command,true));
193
-		}
194
-
195
-		// {datapath query.results}
196
-		// extraire le chemin "query.results" du tableau de donnees
197
-		if (!$this->err
198
-		AND isset($this->command['datapath'])
199
-		AND is_array($this->command['datapath'])) {
200
-			$this->select_datapath();
201
-		}
202
-
203
-		// tri {par x}
204
-		if ($this->command['orderby']) {
205
-			$this->select_orderby();
206
-		}
207
-
208
-		// grouper les resultats {fusion /x/y/z} ;
209
-		if ($this->command['groupby']) {
210
-			$this->select_groupby();
211
-		}
212
-
213
-		$this->rewind();
214
-		#var_dump($this->tableau);
215
-	}
216
-
217
-
218
-	/**
219
-	 * Aller chercher les donnees de la boucle DATA
220
-	 * depuis une source
221
-	 * {source format, [URL], [arg2]...}
222
-	 */
223
-	protected function select_source() {
224
-		# un peu crado : avant de charger le cache il faut charger
225
-		# les class indispensables, sinon PHP ne saura pas gerer
226
-		# l'objet en cache ; cf plugins/icalendar
227
-		# perf : pas de fonction table_to_array ! (table est deja un array)
228
-		if (isset($this->command['sourcemode'])
229
-		  AND !in_array($this->command['sourcemode'],array('table', 'array', 'tableau')))
230
-			charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true);
231
-
232
-		# le premier argument peut etre un array, une URL etc.
233
-		$src = $this->command['source'][0];
234
-
235
-		# avons-nous un cache dispo ?
236
-		$cle = null;
237
-		if (is_string($src))
238
-			$cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'],true));
239
-
240
-		$cache = $this->cache_get($cle);
241
-		if (isset($this->command['datacache']))
242
-			$ttl = intval($this->command['datacache']);
243
-		if ($cache
244
-		AND ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl'])
245
-			> time())
246
-		AND !(_request('var_mode') === 'recalcul'
247
-			AND include_spip('inc/autoriser')
248
-			AND autoriser('recalcul')
249
-		)) {
250
-			$this->tableau = $cache['data'];
251
-		}
252
-		else try {
253
-			# dommage que ca ne soit pas une option de yql_to_array...
254
-			if ($this->command['sourcemode'] == 'yql')
255
-				if (!isset($ttl)) $ttl = 3600;
256
-
257
-			if (isset($this->command['sourcemode'])
258
-			AND in_array($this->command['sourcemode'],
259
-				array('table', 'array', 'tableau'))
260
-			) {
261
-				if (is_array($a = $src)
262
-				OR (is_string($a)
263
-				AND $a = str_replace('&quot;', '"', $a) # fragile!
264
-				AND is_array($a = @unserialize($a)))
265
-				)
266
-					$this->tableau = $a;
267
-			}
268
-			else {
269
-				if (preg_match(',^https?://,', $src)) {
270
-					include_spip('inc/distant');
271
-					$u = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE);
272
-					if (!$u)
273
-						throw new Exception("404");
274
-					if (!isset($ttl)) $ttl = 24*3600;
275
-				} else if (@is_dir($src)) {
276
-					$u = $src;
277
-					if (!isset($ttl)) $ttl = 10;
278
-				} else if (@is_readable($src) && @is_file($src)) {
279
-					$u = spip_file_get_contents($src);
280
-					if (!isset($ttl)) $ttl = 10;
281
-				} else {
282
-					$u = $src;
283
-					if (!isset($ttl)) $ttl = 10;
284
-				}
285
-				if (!$this->err
286
-				AND $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)) {
287
-					$args = $this->command['source'];
288
-					$args[0] = $u;
289
-					if (is_array($a = call_user_func_array($g,$args))) {
290
-						$this->tableau = $a;
291
-					}
292
-				}
293
-			}
294
-
295
-			if (!is_array($this->tableau))
296
-				$this->err = true;
297
-
298
-			if (!$this->err AND isset($ttl) and $ttl>0)
299
-				$this->cache_set($cle, $ttl);
300
-
301
-		}
302
-		catch (Exception $e) {
303
-			$e = $e->getMessage();
304
-			$err = sprintf("[%s, %s] $e",
305
-				$src,
306
-				$this->command['sourcemode']);
307
-			erreur_squelette(array($err, array()));
308
-			$this->err = true;
309
-		}
310
-
311
-		# en cas d'erreur, utiliser le cache si encore dispo
312
-		if ($this->err
313
-		AND $cache) {
314
-			$this->tableau = $cache['data'];
315
-			$this->err = false;
316
-		}
317
-	}
318
-
319
-
320
-	/**
321
-	 * Retourne un tableau donne depuis un critere liste
322
-	 * Critere {liste X1, X2, X3}
323
-	 * 
324
-	**/
325
-	protected function select_liste() {
326
-		# s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
327
-		if (!isset($this->command['liste'][1])) {
328
-			if (!is_array($this->command['liste'][0])) {
329
-				$this->command['liste'] = explode(',', $this->command['liste'][0]);
330
-			} else {
331
-				$this->command['liste'] = $this->command['liste'][0];
332
-			}
333
-		}
334
-		$this->tableau = $this->command['liste'];
335
-	}
336
-
337
-	/**
338
-	 * Retourne un tableau donne depuis un critere liste
339
-	 * Critere {enum Xmin, Xmax}
340
-	 *
341
-	**/
342
-	protected function select_enum() {
343
-		# s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
344
-		if (!isset($this->command['enum'][1])) {
345
-			if (!is_array($this->command['enum'][0])) {
346
-				$this->command['enum'] = explode(',', $this->command['enum'][0]);
347
-			} else {
348
-				$this->command['enum'] = $this->command['enum'][0];
349
-			}
350
-		}
351
-		if (count($this->command['enum'])>=3)
352
-			$enum = range(array_shift($this->command['enum']),array_shift($this->command['enum']),array_shift($this->command['enum']));
353
-		else
354
-			$enum = range(array_shift($this->command['enum']),array_shift($this->command['enum']));
355
-		$this->tableau = $enum;
356
-	}
357
-
358
-
359
-	/**
360
-	 * extraire le chemin "query.results" du tableau de donnees
361
-	 * {datapath query.results}
362
-	 * 
363
-	**/
364
-	protected function select_datapath() {
365
-		list(,$base) = each($this->command['datapath']);
366
-		if (strlen($base = ltrim(trim($base),"/"))) {
367
-			$this->tableau = table_valeur($this->tableau, $base);
368
-			if (!is_array($this->tableau)) {
369
-				$this->tableau = array();
370
-				$this->err = true;
371
-				spip_log("datapath '$base' absent");
372
-			}
373
-		}
374
-	}
375
-
376
-	/**
377
-	 * Ordonner les resultats
378
-	 * {par x}
379
-	 * 
380
-	**/
381
-	protected function select_orderby() {
382
-		$sortfunc = '';
383
-		$aleas = 0;
384
-		foreach($this->command['orderby'] as $tri) {
385
-			// virer le / initial pour les criteres de la forme {par /xx}
386
-			if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) {
387
-				// tri par cle
388
-				if ($r[1] == 'cle'){
389
-					if (isset($r[2]) and $r[2])
390
-						krsort($this->tableau);
391
-					else
392
-						ksort($this->tableau);
393
-				}
394
-				# {par hasard}
395
-				else if ($r[1] == 'alea') {
396
-					$k = array_keys($this->tableau);
397
-					shuffle($k);
398
-					$v = array();
399
-					foreach($k as $cle)
400
-						$v[$cle] = $this->tableau[$cle];
401
-					$this->tableau = $v;
402
-				}
403
-				else {
404
-					# {par valeur}
405
-					if ($r[1] == 'valeur')
406
-						$tv = '%s';
407
-					# {par valeur/xx/yy} ??
408
-					else
409
-						$tv = 'table_valeur(%s, '.var_export($r[1],true).')';
410
-					$sortfunc .= '
175
+        // {source format, [URL], [arg2]...}
176
+        if (isset($this->command['source'])
177
+        AND isset($this->command['sourcemode'])) {
178
+            $this->select_source();
179
+        }
180
+
181
+        // Critere {liste X1, X2, X3}
182
+        if (isset($this->command['liste'])) {
183
+            $this->select_liste();
184
+        }
185
+        if (isset($this->command['enum'])) {
186
+            $this->select_enum();
187
+        }
188
+
189
+        // Si a ce stade on n'a pas de table, il y a un bug
190
+        if (!is_array($this->tableau)) {
191
+            $this->err = true;
192
+            spip_log("erreur datasource ".var_export($command,true));
193
+        }
194
+
195
+        // {datapath query.results}
196
+        // extraire le chemin "query.results" du tableau de donnees
197
+        if (!$this->err
198
+        AND isset($this->command['datapath'])
199
+        AND is_array($this->command['datapath'])) {
200
+            $this->select_datapath();
201
+        }
202
+
203
+        // tri {par x}
204
+        if ($this->command['orderby']) {
205
+            $this->select_orderby();
206
+        }
207
+
208
+        // grouper les resultats {fusion /x/y/z} ;
209
+        if ($this->command['groupby']) {
210
+            $this->select_groupby();
211
+        }
212
+
213
+        $this->rewind();
214
+        #var_dump($this->tableau);
215
+    }
216
+
217
+
218
+    /**
219
+     * Aller chercher les donnees de la boucle DATA
220
+     * depuis une source
221
+     * {source format, [URL], [arg2]...}
222
+     */
223
+    protected function select_source() {
224
+        # un peu crado : avant de charger le cache il faut charger
225
+        # les class indispensables, sinon PHP ne saura pas gerer
226
+        # l'objet en cache ; cf plugins/icalendar
227
+        # perf : pas de fonction table_to_array ! (table est deja un array)
228
+        if (isset($this->command['sourcemode'])
229
+          AND !in_array($this->command['sourcemode'],array('table', 'array', 'tableau')))
230
+            charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true);
231
+
232
+        # le premier argument peut etre un array, une URL etc.
233
+        $src = $this->command['source'][0];
234
+
235
+        # avons-nous un cache dispo ?
236
+        $cle = null;
237
+        if (is_string($src))
238
+            $cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'],true));
239
+
240
+        $cache = $this->cache_get($cle);
241
+        if (isset($this->command['datacache']))
242
+            $ttl = intval($this->command['datacache']);
243
+        if ($cache
244
+        AND ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl'])
245
+            > time())
246
+        AND !(_request('var_mode') === 'recalcul'
247
+            AND include_spip('inc/autoriser')
248
+            AND autoriser('recalcul')
249
+        )) {
250
+            $this->tableau = $cache['data'];
251
+        }
252
+        else try {
253
+            # dommage que ca ne soit pas une option de yql_to_array...
254
+            if ($this->command['sourcemode'] == 'yql')
255
+                if (!isset($ttl)) $ttl = 3600;
256
+
257
+            if (isset($this->command['sourcemode'])
258
+            AND in_array($this->command['sourcemode'],
259
+                array('table', 'array', 'tableau'))
260
+            ) {
261
+                if (is_array($a = $src)
262
+                OR (is_string($a)
263
+                AND $a = str_replace('&quot;', '"', $a) # fragile!
264
+                AND is_array($a = @unserialize($a)))
265
+                )
266
+                    $this->tableau = $a;
267
+            }
268
+            else {
269
+                if (preg_match(',^https?://,', $src)) {
270
+                    include_spip('inc/distant');
271
+                    $u = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE);
272
+                    if (!$u)
273
+                        throw new Exception("404");
274
+                    if (!isset($ttl)) $ttl = 24*3600;
275
+                } else if (@is_dir($src)) {
276
+                    $u = $src;
277
+                    if (!isset($ttl)) $ttl = 10;
278
+                } else if (@is_readable($src) && @is_file($src)) {
279
+                    $u = spip_file_get_contents($src);
280
+                    if (!isset($ttl)) $ttl = 10;
281
+                } else {
282
+                    $u = $src;
283
+                    if (!isset($ttl)) $ttl = 10;
284
+                }
285
+                if (!$this->err
286
+                AND $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)) {
287
+                    $args = $this->command['source'];
288
+                    $args[0] = $u;
289
+                    if (is_array($a = call_user_func_array($g,$args))) {
290
+                        $this->tableau = $a;
291
+                    }
292
+                }
293
+            }
294
+
295
+            if (!is_array($this->tableau))
296
+                $this->err = true;
297
+
298
+            if (!$this->err AND isset($ttl) and $ttl>0)
299
+                $this->cache_set($cle, $ttl);
300
+
301
+        }
302
+        catch (Exception $e) {
303
+            $e = $e->getMessage();
304
+            $err = sprintf("[%s, %s] $e",
305
+                $src,
306
+                $this->command['sourcemode']);
307
+            erreur_squelette(array($err, array()));
308
+            $this->err = true;
309
+        }
310
+
311
+        # en cas d'erreur, utiliser le cache si encore dispo
312
+        if ($this->err
313
+        AND $cache) {
314
+            $this->tableau = $cache['data'];
315
+            $this->err = false;
316
+        }
317
+    }
318
+
319
+
320
+    /**
321
+     * Retourne un tableau donne depuis un critere liste
322
+     * Critere {liste X1, X2, X3}
323
+     * 
324
+     **/
325
+    protected function select_liste() {
326
+        # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
327
+        if (!isset($this->command['liste'][1])) {
328
+            if (!is_array($this->command['liste'][0])) {
329
+                $this->command['liste'] = explode(',', $this->command['liste'][0]);
330
+            } else {
331
+                $this->command['liste'] = $this->command['liste'][0];
332
+            }
333
+        }
334
+        $this->tableau = $this->command['liste'];
335
+    }
336
+
337
+    /**
338
+     * Retourne un tableau donne depuis un critere liste
339
+     * Critere {enum Xmin, Xmax}
340
+     *
341
+     **/
342
+    protected function select_enum() {
343
+        # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
344
+        if (!isset($this->command['enum'][1])) {
345
+            if (!is_array($this->command['enum'][0])) {
346
+                $this->command['enum'] = explode(',', $this->command['enum'][0]);
347
+            } else {
348
+                $this->command['enum'] = $this->command['enum'][0];
349
+            }
350
+        }
351
+        if (count($this->command['enum'])>=3)
352
+            $enum = range(array_shift($this->command['enum']),array_shift($this->command['enum']),array_shift($this->command['enum']));
353
+        else
354
+            $enum = range(array_shift($this->command['enum']),array_shift($this->command['enum']));
355
+        $this->tableau = $enum;
356
+    }
357
+
358
+
359
+    /**
360
+     * extraire le chemin "query.results" du tableau de donnees
361
+     * {datapath query.results}
362
+     * 
363
+     **/
364
+    protected function select_datapath() {
365
+        list(,$base) = each($this->command['datapath']);
366
+        if (strlen($base = ltrim(trim($base),"/"))) {
367
+            $this->tableau = table_valeur($this->tableau, $base);
368
+            if (!is_array($this->tableau)) {
369
+                $this->tableau = array();
370
+                $this->err = true;
371
+                spip_log("datapath '$base' absent");
372
+            }
373
+        }
374
+    }
375
+
376
+    /**
377
+     * Ordonner les resultats
378
+     * {par x}
379
+     * 
380
+     **/
381
+    protected function select_orderby() {
382
+        $sortfunc = '';
383
+        $aleas = 0;
384
+        foreach($this->command['orderby'] as $tri) {
385
+            // virer le / initial pour les criteres de la forme {par /xx}
386
+            if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) {
387
+                // tri par cle
388
+                if ($r[1] == 'cle'){
389
+                    if (isset($r[2]) and $r[2])
390
+                        krsort($this->tableau);
391
+                    else
392
+                        ksort($this->tableau);
393
+                }
394
+                # {par hasard}
395
+                else if ($r[1] == 'alea') {
396
+                    $k = array_keys($this->tableau);
397
+                    shuffle($k);
398
+                    $v = array();
399
+                    foreach($k as $cle)
400
+                        $v[$cle] = $this->tableau[$cle];
401
+                    $this->tableau = $v;
402
+                }
403
+                else {
404
+                    # {par valeur}
405
+                    if ($r[1] == 'valeur')
406
+                        $tv = '%s';
407
+                    # {par valeur/xx/yy} ??
408
+                    else
409
+                        $tv = 'table_valeur(%s, '.var_export($r[1],true).')';
410
+                    $sortfunc .= '
411 411
 					$a = '.sprintf($tv,'$aa').';
412 412
 					$b = '.sprintf($tv,'$bb').';
413 413
 					if ($a <> $b)
414 414
 						return ($a ' . ((isset($r[2]) and $r[2]) ? '>' : '<').' $b) ? -1 : 1;';
415
-				}
416
-			}
417
-		}
415
+                }
416
+            }
417
+        }
418 418
 
419
-		if ($sortfunc) {
420
-			uasort($this->tableau, create_function('$aa,$bb',
421
-				$sortfunc.'
419
+        if ($sortfunc) {
420
+            uasort($this->tableau, create_function('$aa,$bb',
421
+                $sortfunc.'
422 422
 				return 0;'
423
-			));
424
-		}
425
-	}
426
-
427
-
428
-	/**
429
-	 * Grouper les resultats
430
-	 * {fusion /x/y/z}
431
-	 * 
432
-	**/
433
-	protected function select_groupby() {
434
-		// virer le / initial pour les criteres de la forme {fusion /xx}
435
-		if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) {
436
-			$vu = array();
437
-			foreach($this->tableau as $k => $v) {
438
-				$val = table_valeur($v, $fusion);
439
-				if (isset($vu[$val]))
440
-					unset($this->tableau[$k]);
441
-				else
442
-					$vu[$val] = true;
443
-			}
444
-		}
445
-	}
423
+            ));
424
+        }
425
+    }
426
+
427
+
428
+    /**
429
+     * Grouper les resultats
430
+     * {fusion /x/y/z}
431
+     * 
432
+     **/
433
+    protected function select_groupby() {
434
+        // virer le / initial pour les criteres de la forme {fusion /xx}
435
+        if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) {
436
+            $vu = array();
437
+            foreach($this->tableau as $k => $v) {
438
+                $val = table_valeur($v, $fusion);
439
+                if (isset($vu[$val]))
440
+                    unset($this->tableau[$k]);
441
+                else
442
+                    $vu[$val] = true;
443
+            }
444
+        }
445
+    }
446 446
 	
447 447
 	
448
-	/**
449
-	 * L'iterateur est-il encore valide ?
450
-	 * @return bool
451
-	 */
452
-	public function valid(){
453
-		return !is_null($this->cle);
454
-	}
455
-
456
-	/**
457
-	 * Retourner la valeur
458
-	 * @return null
459
-	 */
460
-	public function current() {
461
-		return $this->valeur;
462
-	}
463
-
464
-	/**
465
-	 * Retourner la cle
466
-	 * @return null
467
-	 */
468
-	public function key() {
469
-		return $this->cle;
470
-	}
471
-
472
-	/**
473
-	 * Passer a la valeur suivante
474
-	 * @return void
475
-	 */
476
-	public function next(){
477
-		if ($this->valid())
478
-			list($this->cle, $this->valeur) = each($this->tableau);
479
-	}
480
-
481
-	/**
482
-	 * Compter le nombre total de resultats
483
-	 * @return int
484
-	 */
485
-	public function count() {
486
-		if (is_null($this->total))
487
-			$this->total = count($this->tableau);
488
-	  return $this->total;
489
-	}
448
+    /**
449
+     * L'iterateur est-il encore valide ?
450
+     * @return bool
451
+     */
452
+    public function valid(){
453
+        return !is_null($this->cle);
454
+    }
455
+
456
+    /**
457
+     * Retourner la valeur
458
+     * @return null
459
+     */
460
+    public function current() {
461
+        return $this->valeur;
462
+    }
463
+
464
+    /**
465
+     * Retourner la cle
466
+     * @return null
467
+     */
468
+    public function key() {
469
+        return $this->cle;
470
+    }
471
+
472
+    /**
473
+     * Passer a la valeur suivante
474
+     * @return void
475
+     */
476
+    public function next(){
477
+        if ($this->valid())
478
+            list($this->cle, $this->valeur) = each($this->tableau);
479
+    }
480
+
481
+    /**
482
+     * Compter le nombre total de resultats
483
+     * @return int
484
+     */
485
+    public function count() {
486
+        if (is_null($this->total))
487
+            $this->total = count($this->tableau);
488
+        return $this->total;
489
+    }
490 490
 }
491 491
 
492 492
 /*
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
  * @return array
501 501
  */
502 502
 function inc_file_to_array_dist($u) {
503
-	return preg_split('/\r?\n/', $u);
503
+    return preg_split('/\r?\n/', $u);
504 504
 }
505 505
 
506 506
 /**
@@ -508,8 +508,8 @@  discard block
 block discarded – undo
508 508
  * @return unknown
509 509
  */
510 510
 function inc_plugins_to_array_dist() {
511
-	include_spip('inc/plugin');
512
-	return liste_chemin_plugin_actifs();
511
+    include_spip('inc/plugin');
512
+    return liste_chemin_plugin_actifs();
513 513
 }
514 514
 
515 515
 /**
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
  * @return array
519 519
  */
520 520
 function inc_xml_to_array_dist($u) {
521
-	return @XMLObjectToArray(new SimpleXmlIterator($u));
521
+    return @XMLObjectToArray(new SimpleXmlIterator($u));
522 522
 }
523 523
 
524 524
 /**
@@ -546,14 +546,14 @@  discard block
 block discarded – undo
546 546
  * @return array|bool
547 547
  */
548 548
 function inc_yql_to_array_dist($u) {
549
-	define('_YQL_ENDPOINT', 'http://query.yahooapis.com/v1/public/yql?&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q=');
550
-	$v = recuperer_page($url = _YQL_ENDPOINT.urlencode($u).'&format=json');
551
-	$w = json_decode($v);
552
-	if (!$w) {
553
-		throw new Exception('YQL: r&#233;ponse vide ou mal form&#233;e');
554
-		return false;
555
-	}
556
-	return inc_object_to_array($w);
549
+    define('_YQL_ENDPOINT', 'http://query.yahooapis.com/v1/public/yql?&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q=');
550
+    $v = recuperer_page($url = _YQL_ENDPOINT.urlencode($u).'&format=json');
551
+    $w = json_decode($v);
552
+    if (!$w) {
553
+        throw new Exception('YQL: r&#233;ponse vide ou mal form&#233;e');
554
+        return false;
555
+    }
556
+    return inc_object_to_array($w);
557 557
 }
558 558
 
559 559
 /**
@@ -562,17 +562,17 @@  discard block
 block discarded – undo
562 562
  * @return array|bool
563 563
  */
564 564
 function inc_sql_to_array_dist($u) {
565
-	# sortir le connecteur de $u
566
-	preg_match(',^(?:(\w+):)?(.*)$,S', $u, $v);
567
-	$serveur = (string) $v[1];
568
-	$req = trim($v[2]);
569
-	if ($s = sql_query($req, $serveur)) {
570
-		$r = array();
571
-		while ($t = sql_fetch($s))
572
-			$r[] = $t;
573
-		return $r;
574
-	}
575
-	return false;
565
+    # sortir le connecteur de $u
566
+    preg_match(',^(?:(\w+):)?(.*)$,S', $u, $v);
567
+    $serveur = (string) $v[1];
568
+    $req = trim($v[2]);
569
+    if ($s = sql_query($req, $serveur)) {
570
+        $r = array();
571
+        while ($t = sql_fetch($s))
572
+            $r[] = $t;
573
+        return $r;
574
+    }
575
+    return false;
576 576
 }
577 577
 
578 578
 /**
@@ -581,9 +581,9 @@  discard block
 block discarded – undo
581 581
  * @return array|bool
582 582
  */
583 583
 function inc_json_to_array_dist($u) {
584
-	if (is_array($json = json_decode($u))
585
-	OR is_object($json))
586
-		return (array) $json;
584
+    if (is_array($json = json_decode($u))
585
+    OR is_object($json))
586
+        return (array) $json;
587 587
 }
588 588
 
589 589
 /**
@@ -592,17 +592,17 @@  discard block
 block discarded – undo
592 592
  * @return array|bool
593 593
  */
594 594
 function inc_csv_to_array_dist($u) {
595
-	include_spip('inc/csv');
596
-	list($entete,$csv) = analyse_csv($u);
597
-	array_unshift($csv,$entete);
598
-
599
-	include_spip('inc/charsets');
600
-	foreach ($entete as $k => $v) {
601
-		$v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
602
-		foreach ($csv as &$item)
603
-			$item[$v] = &$item[$k];
604
-	}
605
-	return $csv;
595
+    include_spip('inc/csv');
596
+    list($entete,$csv) = analyse_csv($u);
597
+    array_unshift($csv,$entete);
598
+
599
+    include_spip('inc/charsets');
600
+    foreach ($entete as $k => $v) {
601
+        $v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
602
+        foreach ($csv as &$item)
603
+            $item[$v] = &$item[$k];
604
+    }
605
+    return $csv;
606 606
 }
607 607
 
608 608
 /**
@@ -611,10 +611,10 @@  discard block
 block discarded – undo
611 611
  * @return array|bool
612 612
  */
613 613
 function inc_rss_to_array_dist($u) {
614
-	include_spip('inc/syndic');
615
-	if (is_array($rss = analyser_backend($u)))
616
-		$tableau = $rss;
617
-	return $tableau;
614
+    include_spip('inc/syndic');
615
+    if (is_array($rss = analyser_backend($u)))
616
+        $tableau = $rss;
617
+    return $tableau;
618 618
 }
619 619
 
620 620
 /**
@@ -623,8 +623,8 @@  discard block
 block discarded – undo
623 623
  * @return array|bool
624 624
  */
625 625
 function inc_atom_to_array_dist($u) {
626
-	$g = charger_fonction('rss_to_array', 'inc');
627
-	return $g($u);
626
+    $g = charger_fonction('rss_to_array', 'inc');
627
+    return $g($u);
628 628
 }
629 629
 
630 630
 /**
@@ -634,9 +634,9 @@  discard block
 block discarded – undo
634 634
  * @return array|bool
635 635
  */
636 636
 function inc_glob_to_array_dist($u) {
637
-	return (array) glob($u,
638
-		GLOB_MARK | GLOB_NOSORT | GLOB_BRACE
639
-	);
637
+    return (array) glob($u,
638
+        GLOB_MARK | GLOB_NOSORT | GLOB_BRACE
639
+    );
640 640
 }
641 641
 
642 642
 /**
@@ -646,13 +646,13 @@  discard block
 block discarded – undo
646 646
  * @throws Exception
647 647
  */
648 648
 function inc_yaml_to_array_dist($u){
649
-	include_spip('inc/yaml-mini');
650
-	if (!function_exists("yaml_decode")){
651
-		throw new Exception('YAML: impossible de trouver la fonction yaml_decode');
652
-		return false;
653
-	}
649
+    include_spip('inc/yaml-mini');
650
+    if (!function_exists("yaml_decode")){
651
+        throw new Exception('YAML: impossible de trouver la fonction yaml_decode');
652
+        return false;
653
+    }
654 654
 
655
-	return yaml_decode($u);
655
+    return yaml_decode($u);
656 656
 }
657 657
 
658 658
 
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
  * @return array|bool
667 667
  */
668 668
 function inc_pregfiles_to_array_dist($dir, $regexp=-1, $limit=10000) {
669
-	return (array) preg_files($dir, $regexp, $limit);
669
+    return (array) preg_files($dir, $regexp, $limit);
670 670
 }
671 671
 
672 672
 /**
@@ -677,19 +677,19 @@  discard block
 block discarded – undo
677 677
  * @return array|bool
678 678
  */
679 679
 function inc_ls_to_array_dist($u) {
680
-	$glob = charger_fonction('glob_to_array', 'inc');
681
-	$a = $glob($u);
682
-	foreach ($a as &$v) {
683
-		$b = (array) @stat($v);
684
-		foreach ($b as $k => $ignore)
685
-			if (is_numeric($k)) unset($b[$k]);
686
-		$b['file'] = preg_replace('`/$`','',$v) ;
687
-		$v = array_merge(
688
-			pathinfo($v),
689
-			$b
690
-		);
691
-	}
692
-	return $a;
680
+    $glob = charger_fonction('glob_to_array', 'inc');
681
+    $a = $glob($u);
682
+    foreach ($a as &$v) {
683
+        $b = (array) @stat($v);
684
+        foreach ($b as $k => $ignore)
685
+            if (is_numeric($k)) unset($b[$k]);
686
+        $b['file'] = preg_replace('`/$`','',$v) ;
687
+        $v = array_merge(
688
+            pathinfo($v),
689
+            $b
690
+        );
691
+    }
692
+    return $a;
693 693
 }
694 694
 
695 695
 /**
@@ -698,23 +698,23 @@  discard block
 block discarded – undo
698 698
  * @return array|bool
699 699
  */
700 700
 function XMLObjectToArray($object){
701
-	$xml_array = array();
702
-	for( $object->rewind(); $object->valid(); $object->next() ) {
703
-		if(array_key_exists($key = $object->key(), $xml_array)){
704
-			$key .= '-'.uniqid();
705
-		}
706
-		$vars = get_object_vars($object->current());
707
-		if (isset($vars['@attributes']))
708
-			foreach($vars['@attributes'] as $k => $v)
709
-			$xml_array[$key][$k] = $v;
710
-		if($object->hasChildren()){
711
-			$xml_array[$key][] = XMLObjectToArray(
712
-				$object->current());
713
-		}
714
-		else{
715
-			$xml_array[$key][] = strval($object->current());
716
-		}
717
-	}
718
-	return $xml_array;
701
+    $xml_array = array();
702
+    for( $object->rewind(); $object->valid(); $object->next() ) {
703
+        if(array_key_exists($key = $object->key(), $xml_array)){
704
+            $key .= '-'.uniqid();
705
+        }
706
+        $vars = get_object_vars($object->current());
707
+        if (isset($vars['@attributes']))
708
+            foreach($vars['@attributes'] as $k => $v)
709
+            $xml_array[$key][$k] = $v;
710
+        if($object->hasChildren()){
711
+            $xml_array[$key][] = XMLObjectToArray(
712
+                $object->current());
713
+        }
714
+        else{
715
+            $xml_array[$key][] = strval($object->current());
716
+        }
717
+    }
718
+    return $xml_array;
719 719
 }
720 720
 ?>
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 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
 
15
-if (!defined('_DATA_SOURCE_MAX_SIZE')) define('_DATA_SOURCE_MAX_SIZE',2*1048576);
15
+if (!defined('_DATA_SOURCE_MAX_SIZE')) define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576);
16 16
 
17 17
 
18 18
 /**
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
 	 * @param  $command
87 87
 	 * @param array $info
88 88
 	 */
89
-	public function __construct($command, $info=array()) {
90
-		$this->type='DATA';
89
+	public function __construct($command, $info = array()) {
90
+		$this->type = 'DATA';
91 91
 		$this->command = $command;
92 92
 		$this->info = $info;
93 93
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 		// Si a ce stade on n'a pas de table, il y a un bug
190 190
 		if (!is_array($this->tableau)) {
191 191
 			$this->err = true;
192
-			spip_log("erreur datasource ".var_export($command,true));
192
+			spip_log("erreur datasource ".var_export($command, true));
193 193
 		}
194 194
 
195 195
 		// {datapath query.results}
@@ -226,8 +226,8 @@  discard block
 block discarded – undo
226 226
 		# l'objet en cache ; cf plugins/icalendar
227 227
 		# perf : pas de fonction table_to_array ! (table est deja un array)
228 228
 		if (isset($this->command['sourcemode'])
229
-		  AND !in_array($this->command['sourcemode'],array('table', 'array', 'tableau')))
230
-			charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true);
229
+		  AND !in_array($this->command['sourcemode'], array('table', 'array', 'tableau')))
230
+			charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true);
231 231
 
232 232
 		# le premier argument peut etre un array, une URL etc.
233 233
 		$src = $this->command['source'][0];
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 		# avons-nous un cache dispo ?
236 236
 		$cle = null;
237 237
 		if (is_string($src))
238
-			$cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'],true));
238
+			$cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'], true));
239 239
 
240 240
 		$cache = $this->cache_get($cle);
241 241
 		if (isset($this->command['datacache']))
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 					$u = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE);
272 272
 					if (!$u)
273 273
 						throw new Exception("404");
274
-					if (!isset($ttl)) $ttl = 24*3600;
274
+					if (!isset($ttl)) $ttl = 24 * 3600;
275 275
 				} else if (@is_dir($src)) {
276 276
 					$u = $src;
277 277
 					if (!isset($ttl)) $ttl = 10;
@@ -283,10 +283,10 @@  discard block
 block discarded – undo
283 283
 					if (!isset($ttl)) $ttl = 10;
284 284
 				}
285 285
 				if (!$this->err
286
-				AND $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)) {
286
+				AND $g = charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true)) {
287 287
 					$args = $this->command['source'];
288 288
 					$args[0] = $u;
289
-					if (is_array($a = call_user_func_array($g,$args))) {
289
+					if (is_array($a = call_user_func_array($g, $args))) {
290 290
 						$this->tableau = $a;
291 291
 					}
292 292
 				}
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 			if (!is_array($this->tableau))
296 296
 				$this->err = true;
297 297
 
298
-			if (!$this->err AND isset($ttl) and $ttl>0)
298
+			if (!$this->err AND isset($ttl) and $ttl > 0)
299 299
 				$this->cache_set($cle, $ttl);
300 300
 
301 301
 		}
@@ -348,10 +348,10 @@  discard block
 block discarded – undo
348 348
 				$this->command['enum'] = $this->command['enum'][0];
349 349
 			}
350 350
 		}
351
-		if (count($this->command['enum'])>=3)
352
-			$enum = range(array_shift($this->command['enum']),array_shift($this->command['enum']),array_shift($this->command['enum']));
351
+		if (count($this->command['enum']) >= 3)
352
+			$enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']), array_shift($this->command['enum']));
353 353
 		else
354
-			$enum = range(array_shift($this->command['enum']),array_shift($this->command['enum']));
354
+			$enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']));
355 355
 		$this->tableau = $enum;
356 356
 	}
357 357
 
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 	**/
364 364
 	protected function select_datapath() {
365 365
 		list(,$base) = each($this->command['datapath']);
366
-		if (strlen($base = ltrim(trim($base),"/"))) {
366
+		if (strlen($base = ltrim(trim($base), "/"))) {
367 367
 			$this->tableau = table_valeur($this->tableau, $base);
368 368
 			if (!is_array($this->tableau)) {
369 369
 				$this->tableau = array();
@@ -381,11 +381,11 @@  discard block
 block discarded – undo
381 381
 	protected function select_orderby() {
382 382
 		$sortfunc = '';
383 383
 		$aleas = 0;
384
-		foreach($this->command['orderby'] as $tri) {
384
+		foreach ($this->command['orderby'] as $tri) {
385 385
 			// virer le / initial pour les criteres de la forme {par /xx}
386 386
 			if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) {
387 387
 				// tri par cle
388
-				if ($r[1] == 'cle'){
388
+				if ($r[1] == 'cle') {
389 389
 					if (isset($r[2]) and $r[2])
390 390
 						krsort($this->tableau);
391 391
 					else
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 					$k = array_keys($this->tableau);
397 397
 					shuffle($k);
398 398
 					$v = array();
399
-					foreach($k as $cle)
399
+					foreach ($k as $cle)
400 400
 						$v[$cle] = $this->tableau[$cle];
401 401
 					$this->tableau = $v;
402 402
 				}
@@ -406,10 +406,10 @@  discard block
 block discarded – undo
406 406
 						$tv = '%s';
407 407
 					# {par valeur/xx/yy} ??
408 408
 					else
409
-						$tv = 'table_valeur(%s, '.var_export($r[1],true).')';
409
+						$tv = 'table_valeur(%s, '.var_export($r[1], true).')';
410 410
 					$sortfunc .= '
411
-					$a = '.sprintf($tv,'$aa').';
412
-					$b = '.sprintf($tv,'$bb').';
411
+					$a = '.sprintf($tv, '$aa').';
412
+					$b = '.sprintf($tv, '$bb').';
413 413
 					if ($a <> $b)
414 414
 						return ($a ' . ((isset($r[2]) and $r[2]) ? '>' : '<').' $b) ? -1 : 1;';
415 415
 				}
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 		// virer le / initial pour les criteres de la forme {fusion /xx}
435 435
 		if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) {
436 436
 			$vu = array();
437
-			foreach($this->tableau as $k => $v) {
437
+			foreach ($this->tableau as $k => $v) {
438 438
 				$val = table_valeur($v, $fusion);
439 439
 				if (isset($vu[$val]))
440 440
 					unset($this->tableau[$k]);
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
 	 * L'iterateur est-il encore valide ?
450 450
 	 * @return bool
451 451
 	 */
452
-	public function valid(){
452
+	public function valid() {
453 453
 		return !is_null($this->cle);
454 454
 	}
455 455
 
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
 	 * Passer a la valeur suivante
474 474
 	 * @return void
475 475
 	 */
476
-	public function next(){
476
+	public function next() {
477 477
 		if ($this->valid())
478 478
 			list($this->cle, $this->valeur) = each($this->tableau);
479 479
 	}
@@ -529,14 +529,14 @@  discard block
 block discarded – undo
529 529
  * @return   array
530 530
  *
531 531
  */
532
-function inc_object_to_array( $object ) {
533
-    if( !is_object( $object ) && !is_array( $object ) ) {
532
+function inc_object_to_array($object) {
533
+    if (!is_object($object) && !is_array($object)) {
534 534
         return $object;
535 535
     }
536
-    if( is_object( $object ) ) {
537
-        $object = get_object_vars( $object );
536
+    if (is_object($object)) {
537
+        $object = get_object_vars($object);
538 538
     }
539
-    return array_map( 'inc_object_to_array', $object );
539
+    return array_map('inc_object_to_array', $object);
540 540
 }
541 541
 
542 542
 /**
@@ -593,8 +593,8 @@  discard block
 block discarded – undo
593 593
  */
594 594
 function inc_csv_to_array_dist($u) {
595 595
 	include_spip('inc/csv');
596
-	list($entete,$csv) = analyse_csv($u);
597
-	array_unshift($csv,$entete);
596
+	list($entete, $csv) = analyse_csv($u);
597
+	array_unshift($csv, $entete);
598 598
 
599 599
 	include_spip('inc/charsets');
600 600
 	foreach ($entete as $k => $v) {
@@ -645,9 +645,9 @@  discard block
 block discarded – undo
645 645
  * @return bool|array
646 646
  * @throws Exception
647 647
  */
648
-function inc_yaml_to_array_dist($u){
648
+function inc_yaml_to_array_dist($u) {
649 649
 	include_spip('inc/yaml-mini');
650
-	if (!function_exists("yaml_decode")){
650
+	if (!function_exists("yaml_decode")) {
651 651
 		throw new Exception('YAML: impossible de trouver la fonction yaml_decode');
652 652
 		return false;
653 653
 	}
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
  * @param int $limit
666 666
  * @return array|bool
667 667
  */
668
-function inc_pregfiles_to_array_dist($dir, $regexp=-1, $limit=10000) {
668
+function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) {
669 669
 	return (array) preg_files($dir, $regexp, $limit);
670 670
 }
671 671
 
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
 		$b = (array) @stat($v);
684 684
 		foreach ($b as $k => $ignore)
685 685
 			if (is_numeric($k)) unset($b[$k]);
686
-		$b['file'] = preg_replace('`/$`','',$v) ;
686
+		$b['file'] = preg_replace('`/$`', '', $v);
687 687
 		$v = array_merge(
688 688
 			pathinfo($v),
689 689
 			$b
@@ -697,21 +697,21 @@  discard block
 block discarded – undo
697 697
  * @param Object $object
698 698
  * @return array|bool
699 699
  */
700
-function XMLObjectToArray($object){
700
+function XMLObjectToArray($object) {
701 701
 	$xml_array = array();
702
-	for( $object->rewind(); $object->valid(); $object->next() ) {
703
-		if(array_key_exists($key = $object->key(), $xml_array)){
702
+	for ($object->rewind(); $object->valid(); $object->next()) {
703
+		if (array_key_exists($key = $object->key(), $xml_array)) {
704 704
 			$key .= '-'.uniqid();
705 705
 		}
706 706
 		$vars = get_object_vars($object->current());
707 707
 		if (isset($vars['@attributes']))
708
-			foreach($vars['@attributes'] as $k => $v)
708
+			foreach ($vars['@attributes'] as $k => $v)
709 709
 			$xml_array[$key][$k] = $v;
710
-		if($object->hasChildren()){
710
+		if ($object->hasChildren()) {
711 711
 			$xml_array[$key][] = XMLObjectToArray(
712 712
 				$object->current());
713 713
 		}
714
-		else{
714
+		else {
715 715
 			$xml_array[$key][] = strval($object->current());
716 716
 		}
717 717
 	}
Please login to merge, or discard this patch.
Braces   +107 added lines, -69 removed lines patch added patch discarded remove patch
@@ -10,9 +10,13 @@  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
-if (!defined('_DATA_SOURCE_MAX_SIZE')) define('_DATA_SOURCE_MAX_SIZE',2*1048576);
17
+if (!defined('_DATA_SOURCE_MAX_SIZE')) {
18
+    define('_DATA_SOURCE_MAX_SIZE',2*1048576);
19
+}
16 20
 
17 21
 
18 22
 /**
@@ -117,10 +121,14 @@  discard block
 block discarded – undo
117 121
 	 * @return
118 122
 	 */
119 123
 	protected function cache_get($cle) {
120
-		if (!$cle) return;
124
+		if (!$cle) {
125
+		    return;
126
+		}
121 127
 		# utiliser memoization si dispo
122 128
 		include_spip('inc/memoization');
123
-		if (!function_exists('cache_get')) return;
129
+		if (!function_exists('cache_get')) {
130
+		    return;
131
+		}
124 132
 		return cache_get($cle);
125 133
 	}
126 134
 
@@ -131,13 +139,17 @@  discard block
 block discarded – undo
131 139
 	 * @return
132 140
 	 */
133 141
 	protected function cache_set($cle, $ttl, $valeur = null) {
134
-		if (!$cle) return;
142
+		if (!$cle) {
143
+		    return;
144
+		}
135 145
 		if (is_null($valeur)) {
136 146
 			$valeur = $this->tableau;
137 147
 		}
138 148
 		# utiliser memoization si dispo
139 149
 		include_spip('inc/memoization');
140
-		if (!function_exists('cache_set')) return;
150
+		if (!function_exists('cache_set')) {
151
+		    return;
152
+		}
141 153
 		return cache_set($cle,
142 154
 			array(
143 155
 				'data' => $valeur,
@@ -226,20 +238,23 @@  discard block
 block discarded – undo
226 238
 		# l'objet en cache ; cf plugins/icalendar
227 239
 		# perf : pas de fonction table_to_array ! (table est deja un array)
228 240
 		if (isset($this->command['sourcemode'])
229
-		  AND !in_array($this->command['sourcemode'],array('table', 'array', 'tableau')))
230
-			charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true);
241
+		  AND !in_array($this->command['sourcemode'],array('table', 'array', 'tableau'))) {
242
+					charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true);
243
+		}
231 244
 
232 245
 		# le premier argument peut etre un array, une URL etc.
233 246
 		$src = $this->command['source'][0];
234 247
 
235 248
 		# avons-nous un cache dispo ?
236 249
 		$cle = null;
237
-		if (is_string($src))
238
-			$cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'],true));
250
+		if (is_string($src)) {
251
+					$cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'],true));
252
+		}
239 253
 
240 254
 		$cache = $this->cache_get($cle);
241
-		if (isset($this->command['datacache']))
242
-			$ttl = intval($this->command['datacache']);
255
+		if (isset($this->command['datacache'])) {
256
+					$ttl = intval($this->command['datacache']);
257
+		}
243 258
 		if ($cache
244 259
 		AND ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl'])
245 260
 			> time())
@@ -248,11 +263,12 @@  discard block
 block discarded – undo
248 263
 			AND autoriser('recalcul')
249 264
 		)) {
250 265
 			$this->tableau = $cache['data'];
251
-		}
252
-		else try {
266
+		} else {
267
+		    try {
253 268
 			# dommage que ca ne soit pas une option de yql_to_array...
254 269
 			if ($this->command['sourcemode'] == 'yql')
255 270
 				if (!isset($ttl)) $ttl = 3600;
271
+		}
256 272
 
257 273
 			if (isset($this->command['sourcemode'])
258 274
 			AND in_array($this->command['sourcemode'],
@@ -262,25 +278,34 @@  discard block
 block discarded – undo
262 278
 				OR (is_string($a)
263 279
 				AND $a = str_replace('&quot;', '"', $a) # fragile!
264 280
 				AND is_array($a = @unserialize($a)))
265
-				)
266
-					$this->tableau = $a;
267
-			}
268
-			else {
281
+				) {
282
+									$this->tableau = $a;
283
+				}
284
+			} else {
269 285
 				if (preg_match(',^https?://,', $src)) {
270 286
 					include_spip('inc/distant');
271 287
 					$u = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE);
272
-					if (!$u)
273
-						throw new Exception("404");
274
-					if (!isset($ttl)) $ttl = 24*3600;
288
+					if (!$u) {
289
+											throw new Exception("404");
290
+					}
291
+					if (!isset($ttl)) {
292
+					    $ttl = 24*3600;
293
+					}
275 294
 				} else if (@is_dir($src)) {
276 295
 					$u = $src;
277
-					if (!isset($ttl)) $ttl = 10;
296
+					if (!isset($ttl)) {
297
+					    $ttl = 10;
298
+					}
278 299
 				} else if (@is_readable($src) && @is_file($src)) {
279 300
 					$u = spip_file_get_contents($src);
280
-					if (!isset($ttl)) $ttl = 10;
301
+					if (!isset($ttl)) {
302
+					    $ttl = 10;
303
+					}
281 304
 				} else {
282 305
 					$u = $src;
283
-					if (!isset($ttl)) $ttl = 10;
306
+					if (!isset($ttl)) {
307
+					    $ttl = 10;
308
+					}
284 309
 				}
285 310
 				if (!$this->err
286 311
 				AND $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)) {
@@ -292,14 +317,15 @@  discard block
 block discarded – undo
292 317
 				}
293 318
 			}
294 319
 
295
-			if (!is_array($this->tableau))
296
-				$this->err = true;
320
+			if (!is_array($this->tableau)) {
321
+							$this->err = true;
322
+			}
297 323
 
298
-			if (!$this->err AND isset($ttl) and $ttl>0)
299
-				$this->cache_set($cle, $ttl);
324
+			if (!$this->err AND isset($ttl) and $ttl>0) {
325
+							$this->cache_set($cle, $ttl);
326
+			}
300 327
 
301
-		}
302
-		catch (Exception $e) {
328
+		} catch (Exception $e) {
303 329
 			$e = $e->getMessage();
304 330
 			$err = sprintf("[%s, %s] $e",
305 331
 				$src,
@@ -348,10 +374,11 @@  discard block
 block discarded – undo
348 374
 				$this->command['enum'] = $this->command['enum'][0];
349 375
 			}
350 376
 		}
351
-		if (count($this->command['enum'])>=3)
352
-			$enum = range(array_shift($this->command['enum']),array_shift($this->command['enum']),array_shift($this->command['enum']));
353
-		else
354
-			$enum = range(array_shift($this->command['enum']),array_shift($this->command['enum']));
377
+		if (count($this->command['enum'])>=3) {
378
+					$enum = range(array_shift($this->command['enum']),array_shift($this->command['enum']),array_shift($this->command['enum']));
379
+		} else {
380
+					$enum = range(array_shift($this->command['enum']),array_shift($this->command['enum']));
381
+		}
355 382
 		$this->tableau = $enum;
356 383
 	}
357 384
 
@@ -386,27 +413,30 @@  discard block
 block discarded – undo
386 413
 			if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) {
387 414
 				// tri par cle
388 415
 				if ($r[1] == 'cle'){
389
-					if (isset($r[2]) and $r[2])
390
-						krsort($this->tableau);
391
-					else
392
-						ksort($this->tableau);
416
+					if (isset($r[2]) and $r[2]) {
417
+											krsort($this->tableau);
418
+					} else {
419
+											ksort($this->tableau);
420
+					}
393 421
 				}
394 422
 				# {par hasard}
395 423
 				else if ($r[1] == 'alea') {
396 424
 					$k = array_keys($this->tableau);
397 425
 					shuffle($k);
398 426
 					$v = array();
399
-					foreach($k as $cle)
400
-						$v[$cle] = $this->tableau[$cle];
427
+					foreach($k as $cle) {
428
+											$v[$cle] = $this->tableau[$cle];
429
+					}
401 430
 					$this->tableau = $v;
402
-				}
403
-				else {
431
+				} else {
404 432
 					# {par valeur}
405
-					if ($r[1] == 'valeur')
406
-						$tv = '%s';
433
+					if ($r[1] == 'valeur') {
434
+											$tv = '%s';
435
+					}
407 436
 					# {par valeur/xx/yy} ??
408
-					else
409
-						$tv = 'table_valeur(%s, '.var_export($r[1],true).')';
437
+					else {
438
+											$tv = 'table_valeur(%s, '.var_export($r[1],true).')';
439
+					}
410 440
 					$sortfunc .= '
411 441
 					$a = '.sprintf($tv,'$aa').';
412 442
 					$b = '.sprintf($tv,'$bb').';
@@ -436,10 +466,11 @@  discard block
 block discarded – undo
436 466
 			$vu = array();
437 467
 			foreach($this->tableau as $k => $v) {
438 468
 				$val = table_valeur($v, $fusion);
439
-				if (isset($vu[$val]))
440
-					unset($this->tableau[$k]);
441
-				else
442
-					$vu[$val] = true;
469
+				if (isset($vu[$val])) {
470
+									unset($this->tableau[$k]);
471
+				} else {
472
+									$vu[$val] = true;
473
+				}
443 474
 			}
444 475
 		}
445 476
 	}
@@ -474,8 +505,9 @@  discard block
 block discarded – undo
474 505
 	 * @return void
475 506
 	 */
476 507
 	public function next(){
477
-		if ($this->valid())
478
-			list($this->cle, $this->valeur) = each($this->tableau);
508
+		if ($this->valid()) {
509
+					list($this->cle, $this->valeur) = each($this->tableau);
510
+		}
479 511
 	}
480 512
 
481 513
 	/**
@@ -483,8 +515,9 @@  discard block
 block discarded – undo
483 515
 	 * @return int
484 516
 	 */
485 517
 	public function count() {
486
-		if (is_null($this->total))
487
-			$this->total = count($this->tableau);
518
+		if (is_null($this->total)) {
519
+					$this->total = count($this->tableau);
520
+		}
488 521
 	  return $this->total;
489 522
 	}
490 523
 }
@@ -568,8 +601,9 @@  discard block
 block discarded – undo
568 601
 	$req = trim($v[2]);
569 602
 	if ($s = sql_query($req, $serveur)) {
570 603
 		$r = array();
571
-		while ($t = sql_fetch($s))
572
-			$r[] = $t;
604
+		while ($t = sql_fetch($s)) {
605
+					$r[] = $t;
606
+		}
573 607
 		return $r;
574 608
 	}
575 609
 	return false;
@@ -582,9 +616,10 @@  discard block
 block discarded – undo
582 616
  */
583 617
 function inc_json_to_array_dist($u) {
584 618
 	if (is_array($json = json_decode($u))
585
-	OR is_object($json))
586
-		return (array) $json;
587
-}
619
+	OR is_object($json)) {
620
+			return (array) $json;
621
+	}
622
+	}
588 623
 
589 624
 /**
590 625
  * csv -> tableau
@@ -599,8 +634,9 @@  discard block
 block discarded – undo
599 634
 	include_spip('inc/charsets');
600 635
 	foreach ($entete as $k => $v) {
601 636
 		$v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
602
-		foreach ($csv as &$item)
603
-			$item[$v] = &$item[$k];
637
+		foreach ($csv as &$item) {
638
+					$item[$v] = &$item[$k];
639
+		}
604 640
 	}
605 641
 	return $csv;
606 642
 }
@@ -612,8 +648,9 @@  discard block
 block discarded – undo
612 648
  */
613 649
 function inc_rss_to_array_dist($u) {
614 650
 	include_spip('inc/syndic');
615
-	if (is_array($rss = analyser_backend($u)))
616
-		$tableau = $rss;
651
+	if (is_array($rss = analyser_backend($u))) {
652
+			$tableau = $rss;
653
+	}
617 654
 	return $tableau;
618 655
 }
619 656
 
@@ -681,8 +718,9 @@  discard block
 block discarded – undo
681 718
 	$a = $glob($u);
682 719
 	foreach ($a as &$v) {
683 720
 		$b = (array) @stat($v);
684
-		foreach ($b as $k => $ignore)
685
-			if (is_numeric($k)) unset($b[$k]);
721
+		foreach ($b as $k => $ignore) {
722
+					if (is_numeric($k)) unset($b[$k]);
723
+		}
686 724
 		$b['file'] = preg_replace('`/$`','',$v) ;
687 725
 		$v = array_merge(
688 726
 			pathinfo($v),
@@ -704,14 +742,14 @@  discard block
 block discarded – undo
704 742
 			$key .= '-'.uniqid();
705 743
 		}
706 744
 		$vars = get_object_vars($object->current());
707
-		if (isset($vars['@attributes']))
708
-			foreach($vars['@attributes'] as $k => $v)
745
+		if (isset($vars['@attributes'])) {
746
+					foreach($vars['@attributes'] as $k => $v)
709 747
 			$xml_array[$key][$k] = $v;
748
+		}
710 749
 		if($object->hasChildren()){
711 750
 			$xml_array[$key][] = XMLObjectToArray(
712 751
 				$object->current());
713
-		}
714
-		else{
752
+		} else{
715 753
 			$xml_array[$key][] = strval($object->current());
716 754
 		}
717 755
 	}
Please login to merge, or discard this patch.