Completed
Push — master ( b6e73f...0af572 )
by cam
04:04
created
ecrire/iterateur/data.php 2 patches
Indentation   +626 added lines, -626 removed lines patch added patch discarded remove patch
@@ -17,11 +17,11 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 if (!defined('_DATA_SOURCE_MAX_SIZE')) {
24
-	define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576);
24
+    define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576);
25 25
 }
26 26
 
27 27
 
@@ -42,17 +42,17 @@  discard block
 block discarded – undo
42 42
  *     Description de la boucle complétée des champs
43 43
  */
44 44
 function iterateur_DATA_dist($b) {
45
-	$b->iterateur = 'DATA'; # designe la classe d'iterateur
46
-	$b->show = array(
47
-		'field' => array(
48
-			'cle' => 'STRING',
49
-			'valeur' => 'STRING',
50
-			'*' => 'ALL' // Champ joker *
51
-		)
52
-	);
53
-	$b->select[] = '.valeur';
54
-
55
-	return $b;
45
+    $b->iterateur = 'DATA'; # designe la classe d'iterateur
46
+    $b->show = array(
47
+        'field' => array(
48
+            'cle' => 'STRING',
49
+            'valeur' => 'STRING',
50
+            '*' => 'ALL' // Champ joker *
51
+        )
52
+    );
53
+    $b->select[] = '.valeur';
54
+
55
+    return $b;
56 56
 }
57 57
 
58 58
 
@@ -62,513 +62,513 @@  discard block
 block discarded – undo
62 62
  * Pour itérer sur des données quelconques (transformables en tableau)
63 63
  */
64 64
 class IterateurDATA implements Iterator {
65
-	/**
66
-	 * tableau de donnees
67
-	 *
68
-	 * @var array
69
-	 */
70
-	protected $tableau = array();
71
-
72
-	/**
73
-	 * Conditions de filtrage
74
-	 * ie criteres de selection
75
-	 *
76
-	 * @var array
77
-	 */
78
-	protected $filtre = array();
79
-
80
-
81
-	/**
82
-	 * Cle courante
83
-	 *
84
-	 * @var null
85
-	 */
86
-	protected $cle = null;
87
-
88
-	/**
89
-	 * Valeur courante
90
-	 *
91
-	 * @var null
92
-	 */
93
-	protected $valeur = null;
94
-
95
-	/**
96
-	 * Erreur presente ?
97
-	 *
98
-	 * @var bool
99
-	 **/
100
-	public $err = false;
101
-
102
-	/**
103
-	 * Calcul du total des elements
104
-	 *
105
-	 * @var int|null
106
-	 **/
107
-	public $total = null;
108
-
109
-	/**
110
-	 * Constructeur
111
-	 *
112
-	 * @param  $command
113
-	 * @param array $info
114
-	 */
115
-	public function __construct($command, $info = array()) {
116
-		$this->type = 'DATA';
117
-		$this->command = $command;
118
-		$this->info = $info;
119
-
120
-		$this->select($command);
121
-	}
122
-
123
-	/**
124
-	 * Revenir au depart
125
-	 *
126
-	 * @return void
127
-	 */
128
-	public function rewind() {
129
-		reset($this->tableau);
130
-		$this->cle = key($this->tableau);
131
-		$this->valeur = current($this->tableau);
132
-		next($this->tableau);
133
-	}
134
-
135
-	/**
136
-	 * Déclarer les critères exceptions
137
-	 *
138
-	 * @return array
139
-	 */
140
-	public function exception_des_criteres() {
141
-		return array('tableau');
142
-	}
143
-
144
-	/**
145
-	 * Récupérer depuis le cache si possible
146
-	 *
147
-	 * @param string $cle
148
-	 * @return mixed
149
-	 */
150
-	protected function cache_get($cle) {
151
-		if (!$cle) {
152
-			return;
153
-		}
154
-		# utiliser memoization si dispo
155
-		if (!function_exists('cache_get')) {
156
-			return;
157
-		}
158
-
159
-		return cache_get($cle);
160
-	}
161
-
162
-	/**
163
-	 * Stocker en cache si possible
164
-	 *
165
-	 * @param string $cle
166
-	 * @param int $ttl
167
-	 * @param null|mixed $valeur
168
-	 * @return bool
169
-	 */
170
-	protected function cache_set($cle, $ttl, $valeur = null) {
171
-		if (!$cle) {
172
-			return;
173
-		}
174
-		if (is_null($valeur)) {
175
-			$valeur = $this->tableau;
176
-		}
177
-		# utiliser memoization si dispo
178
-		if (!function_exists('cache_set')) {
179
-			return;
180
-		}
181
-
182
-		return cache_set($cle,
183
-			array(
184
-				'data' => $valeur,
185
-				'time' => time(),
186
-				'ttl' => $ttl
187
-			),
188
-			3600 + $ttl);
189
-		# conserver le cache 1h de plus que la validite demandee,
190
-		# pour le cas ou le serveur distant ne reponde plus
191
-	}
192
-
193
-	/**
194
-	 * Aller chercher les données de la boucle DATA
195
-	 *
196
-	 * @throws Exception
197
-	 * @param array $command
198
-	 * @return void
199
-	 */
200
-	protected function select($command) {
201
-
202
-		// l'iterateur DATA peut etre appele en passant (data:type)
203
-		// le type se retrouve dans la commande 'from'
204
-		// dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument
205
-		if (isset($this->command['from'][0])) {
206
-			if (isset($this->command['source']) and is_array($this->command['source'])) {
207
-				array_unshift($this->command['source'], $this->command['sourcemode']);
208
-			}
209
-			$this->command['sourcemode'] = $this->command['from'][0];
210
-		}
211
-
212
-		// cherchons differents moyens de creer le tableau de donnees
213
-		// les commandes connues pour l'iterateur DATA
214
-		// sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...}
215
-
216
-		// {source format, [URL], [arg2]...}
217
-		if (isset($this->command['source'])
218
-			and isset($this->command['sourcemode'])
219
-		) {
220
-			$this->select_source();
221
-		}
222
-
223
-		// Critere {liste X1, X2, X3}
224
-		if (isset($this->command['liste'])) {
225
-			$this->select_liste();
226
-		}
227
-		if (isset($this->command['enum'])) {
228
-			$this->select_enum();
229
-		}
230
-
231
-		// Si a ce stade on n'a pas de table, il y a un bug
232
-		if (!is_array($this->tableau)) {
233
-			$this->err = true;
234
-			spip_log("erreur datasource " . var_export($command, true));
235
-		}
236
-
237
-		// {datapath query.results}
238
-		// extraire le chemin "query.results" du tableau de donnees
239
-		if (!$this->err
240
-			and isset($this->command['datapath'])
241
-			and is_array($this->command['datapath'])
242
-		) {
243
-			$this->select_datapath();
244
-		}
245
-
246
-		// tri {par x}
247
-		if ($this->command['orderby']) {
248
-			$this->select_orderby();
249
-		}
250
-
251
-		// grouper les resultats {fusion /x/y/z} ;
252
-		if ($this->command['groupby']) {
253
-			$this->select_groupby();
254
-		}
255
-
256
-		$this->rewind();
257
-		#var_dump($this->tableau);
258
-	}
259
-
260
-
261
-	/**
262
-	 * Aller chercher les donnees de la boucle DATA
263
-	 * depuis une source
264
-	 * {source format, [URL], [arg2]...}
265
-	 */
266
-	protected function select_source() {
267
-		# un peu crado : avant de charger le cache il faut charger
268
-		# les class indispensables, sinon PHP ne saura pas gerer
269
-		# l'objet en cache ; cf plugins/icalendar
270
-		# perf : pas de fonction table_to_array ! (table est deja un array)
271
-		if (isset($this->command['sourcemode'])
272
-			and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau'))
273
-		) {
274
-			charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true);
275
-		}
276
-
277
-		# le premier argument peut etre un array, une URL etc.
278
-		$src = $this->command['source'][0];
279
-
280
-		# avons-nous un cache dispo ?
281
-		$cle = null;
282
-		if (is_string($src)) {
283
-			$cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true));
284
-		}
285
-
286
-		$cache = $this->cache_get($cle);
287
-		if (isset($this->command['datacache'])) {
288
-			$ttl = intval($this->command['datacache']);
289
-		}
290
-		if ($cache
291
-			and ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl'])
292
-				> time())
293
-			and !(_request('var_mode') === 'recalcul'
294
-				and include_spip('inc/autoriser')
295
-				and autoriser('recalcul')
296
-			)
297
-		) {
298
-			$this->tableau = $cache['data'];
299
-		} else {
300
-			try {
301
-				if (isset($this->command['sourcemode'])
302
-					and in_array($this->command['sourcemode'],
303
-						array('table', 'array', 'tableau'))
304
-				) {
305
-					if (is_array($a = $src)
306
-						or (is_string($a)
307
-							and $a = str_replace('"', '"', $a) # fragile!
308
-							and is_array($a = @unserialize($a)))
309
-					) {
310
-						$this->tableau = $a;
311
-					}
312
-				} else {
313
-					if (tester_url_absolue($src)) {
314
-						include_spip('inc/distant');
315
-						$u = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE);
316
-						if (!$u) {
317
-							throw new Exception("404");
318
-						}
319
-						if (!isset($ttl)) {
320
-							$ttl = 24 * 3600;
321
-						}
322
-					} else {
323
-						if (@is_dir($src)) {
324
-							$u = $src;
325
-							if (!isset($ttl)) {
326
-								$ttl = 10;
327
-							}
328
-						} else {
329
-							if (@is_readable($src) && @is_file($src)) {
330
-								$u = spip_file_get_contents($src);
331
-								if (!isset($ttl)) {
332
-									$ttl = 10;
333
-								}
334
-							} else {
335
-								$u = $src;
336
-								if (!isset($ttl)) {
337
-									$ttl = 10;
338
-								}
339
-							}
340
-						}
341
-					}
342
-					if (!$this->err
343
-						and $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)
344
-					) {
345
-						$args = $this->command['source'];
346
-						$args[0] = $u;
347
-						if (is_array($a = call_user_func_array($g, $args))) {
348
-							$this->tableau = $a;
349
-						}
350
-					}
351
-				}
352
-
353
-				if (!is_array($this->tableau)) {
354
-					$this->err = true;
355
-				}
356
-
357
-				if (!$this->err and isset($ttl) and $ttl > 0) {
358
-					$this->cache_set($cle, $ttl);
359
-				}
360
-
361
-			} catch (Exception $e) {
362
-				$e = $e->getMessage();
363
-				$err = sprintf("[%s, %s] $e",
364
-					$src,
365
-					$this->command['sourcemode']);
366
-				erreur_squelette(array($err, array()));
367
-				$this->err = true;
368
-			}
369
-		}
370
-
371
-		# en cas d'erreur, utiliser le cache si encore dispo
372
-		if ($this->err
373
-			and $cache
374
-		) {
375
-			$this->tableau = $cache['data'];
376
-			$this->err = false;
377
-		}
378
-	}
379
-
380
-
381
-	/**
382
-	 * Retourne un tableau donne depuis un critère liste
383
-	 *
384
-	 * Critère `{liste X1, X2, X3}`
385
-	 *
386
-	 * @see critere_DATA_liste_dist()
387
-	 *
388
-	 **/
389
-	protected function select_liste() {
390
-		# s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
391
-		if (!isset($this->command['liste'][1])) {
392
-			if (!is_array($this->command['liste'][0])) {
393
-				$this->command['liste'] = explode(',', $this->command['liste'][0]);
394
-			} else {
395
-				$this->command['liste'] = $this->command['liste'][0];
396
-			}
397
-		}
398
-		$this->tableau = $this->command['liste'];
399
-	}
400
-
401
-	/**
402
-	 * Retourne un tableau donne depuis un critere liste
403
-	 * Critere {enum Xmin, Xmax}
404
-	 *
405
-	 **/
406
-	protected function select_enum() {
407
-		# s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
408
-		if (!isset($this->command['enum'][1])) {
409
-			if (!is_array($this->command['enum'][0])) {
410
-				$this->command['enum'] = explode(',', $this->command['enum'][0]);
411
-			} else {
412
-				$this->command['enum'] = $this->command['enum'][0];
413
-			}
414
-		}
415
-		if (count($this->command['enum']) >= 3) {
416
-			$enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']),
417
-				array_shift($this->command['enum']));
418
-		} else {
419
-			$enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']));
420
-		}
421
-		$this->tableau = $enum;
422
-	}
423
-
424
-
425
-	/**
426
-	 * extraire le chemin "query.results" du tableau de donnees
427
-	 * {datapath query.results}
428
-	 *
429
-	 **/
430
-	protected function select_datapath() {
431
-		$base = reset($this->command['datapath']);
432
-		if (strlen($base = ltrim(trim($base), "/"))) {
433
-			$this->tableau = table_valeur($this->tableau, $base);
434
-			if (!is_array($this->tableau)) {
435
-				$this->tableau = array();
436
-				$this->err = true;
437
-				spip_log("datapath '$base' absent");
438
-			}
439
-		}
440
-	}
441
-
442
-	/**
443
-	 * Ordonner les resultats
444
-	 * {par x}
445
-	 *
446
-	 **/
447
-	protected function select_orderby() {
448
-		$sortfunc = '';
449
-		$aleas = 0;
450
-		foreach ($this->command['orderby'] as $tri) {
451
-			// virer le / initial pour les criteres de la forme {par /xx}
452
-			if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) {
453
-				$r = array_pad($r, 3, null);
454
-
455
-				// tri par cle
456
-				if ($r[1] == 'cle') {
457
-					if (isset($r[2]) and $r[2]) {
458
-						krsort($this->tableau);
459
-					} else {
460
-						ksort($this->tableau);
461
-					}
462
-				} # {par hasard}
463
-				else {
464
-					if ($r[1] == 'hasard') {
465
-						$k = array_keys($this->tableau);
466
-						shuffle($k);
467
-						$v = array();
468
-						foreach ($k as $cle) {
469
-							$v[$cle] = $this->tableau[$cle];
470
-						}
471
-						$this->tableau = $v;
472
-					} else {
473
-						# {par valeur}
474
-						if ($r[1] == 'valeur') {
475
-							$tv = '%s';
476
-						} # {par valeur/xx/yy} ??
477
-						else {
478
-							$tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')';
479
-						}
480
-						$sortfunc .= '
65
+    /**
66
+     * tableau de donnees
67
+     *
68
+     * @var array
69
+     */
70
+    protected $tableau = array();
71
+
72
+    /**
73
+     * Conditions de filtrage
74
+     * ie criteres de selection
75
+     *
76
+     * @var array
77
+     */
78
+    protected $filtre = array();
79
+
80
+
81
+    /**
82
+     * Cle courante
83
+     *
84
+     * @var null
85
+     */
86
+    protected $cle = null;
87
+
88
+    /**
89
+     * Valeur courante
90
+     *
91
+     * @var null
92
+     */
93
+    protected $valeur = null;
94
+
95
+    /**
96
+     * Erreur presente ?
97
+     *
98
+     * @var bool
99
+     **/
100
+    public $err = false;
101
+
102
+    /**
103
+     * Calcul du total des elements
104
+     *
105
+     * @var int|null
106
+     **/
107
+    public $total = null;
108
+
109
+    /**
110
+     * Constructeur
111
+     *
112
+     * @param  $command
113
+     * @param array $info
114
+     */
115
+    public function __construct($command, $info = array()) {
116
+        $this->type = 'DATA';
117
+        $this->command = $command;
118
+        $this->info = $info;
119
+
120
+        $this->select($command);
121
+    }
122
+
123
+    /**
124
+     * Revenir au depart
125
+     *
126
+     * @return void
127
+     */
128
+    public function rewind() {
129
+        reset($this->tableau);
130
+        $this->cle = key($this->tableau);
131
+        $this->valeur = current($this->tableau);
132
+        next($this->tableau);
133
+    }
134
+
135
+    /**
136
+     * Déclarer les critères exceptions
137
+     *
138
+     * @return array
139
+     */
140
+    public function exception_des_criteres() {
141
+        return array('tableau');
142
+    }
143
+
144
+    /**
145
+     * Récupérer depuis le cache si possible
146
+     *
147
+     * @param string $cle
148
+     * @return mixed
149
+     */
150
+    protected function cache_get($cle) {
151
+        if (!$cle) {
152
+            return;
153
+        }
154
+        # utiliser memoization si dispo
155
+        if (!function_exists('cache_get')) {
156
+            return;
157
+        }
158
+
159
+        return cache_get($cle);
160
+    }
161
+
162
+    /**
163
+     * Stocker en cache si possible
164
+     *
165
+     * @param string $cle
166
+     * @param int $ttl
167
+     * @param null|mixed $valeur
168
+     * @return bool
169
+     */
170
+    protected function cache_set($cle, $ttl, $valeur = null) {
171
+        if (!$cle) {
172
+            return;
173
+        }
174
+        if (is_null($valeur)) {
175
+            $valeur = $this->tableau;
176
+        }
177
+        # utiliser memoization si dispo
178
+        if (!function_exists('cache_set')) {
179
+            return;
180
+        }
181
+
182
+        return cache_set($cle,
183
+            array(
184
+                'data' => $valeur,
185
+                'time' => time(),
186
+                'ttl' => $ttl
187
+            ),
188
+            3600 + $ttl);
189
+        # conserver le cache 1h de plus que la validite demandee,
190
+        # pour le cas ou le serveur distant ne reponde plus
191
+    }
192
+
193
+    /**
194
+     * Aller chercher les données de la boucle DATA
195
+     *
196
+     * @throws Exception
197
+     * @param array $command
198
+     * @return void
199
+     */
200
+    protected function select($command) {
201
+
202
+        // l'iterateur DATA peut etre appele en passant (data:type)
203
+        // le type se retrouve dans la commande 'from'
204
+        // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument
205
+        if (isset($this->command['from'][0])) {
206
+            if (isset($this->command['source']) and is_array($this->command['source'])) {
207
+                array_unshift($this->command['source'], $this->command['sourcemode']);
208
+            }
209
+            $this->command['sourcemode'] = $this->command['from'][0];
210
+        }
211
+
212
+        // cherchons differents moyens de creer le tableau de donnees
213
+        // les commandes connues pour l'iterateur DATA
214
+        // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...}
215
+
216
+        // {source format, [URL], [arg2]...}
217
+        if (isset($this->command['source'])
218
+            and isset($this->command['sourcemode'])
219
+        ) {
220
+            $this->select_source();
221
+        }
222
+
223
+        // Critere {liste X1, X2, X3}
224
+        if (isset($this->command['liste'])) {
225
+            $this->select_liste();
226
+        }
227
+        if (isset($this->command['enum'])) {
228
+            $this->select_enum();
229
+        }
230
+
231
+        // Si a ce stade on n'a pas de table, il y a un bug
232
+        if (!is_array($this->tableau)) {
233
+            $this->err = true;
234
+            spip_log("erreur datasource " . var_export($command, true));
235
+        }
236
+
237
+        // {datapath query.results}
238
+        // extraire le chemin "query.results" du tableau de donnees
239
+        if (!$this->err
240
+            and isset($this->command['datapath'])
241
+            and is_array($this->command['datapath'])
242
+        ) {
243
+            $this->select_datapath();
244
+        }
245
+
246
+        // tri {par x}
247
+        if ($this->command['orderby']) {
248
+            $this->select_orderby();
249
+        }
250
+
251
+        // grouper les resultats {fusion /x/y/z} ;
252
+        if ($this->command['groupby']) {
253
+            $this->select_groupby();
254
+        }
255
+
256
+        $this->rewind();
257
+        #var_dump($this->tableau);
258
+    }
259
+
260
+
261
+    /**
262
+     * Aller chercher les donnees de la boucle DATA
263
+     * depuis une source
264
+     * {source format, [URL], [arg2]...}
265
+     */
266
+    protected function select_source() {
267
+        # un peu crado : avant de charger le cache il faut charger
268
+        # les class indispensables, sinon PHP ne saura pas gerer
269
+        # l'objet en cache ; cf plugins/icalendar
270
+        # perf : pas de fonction table_to_array ! (table est deja un array)
271
+        if (isset($this->command['sourcemode'])
272
+            and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau'))
273
+        ) {
274
+            charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true);
275
+        }
276
+
277
+        # le premier argument peut etre un array, une URL etc.
278
+        $src = $this->command['source'][0];
279
+
280
+        # avons-nous un cache dispo ?
281
+        $cle = null;
282
+        if (is_string($src)) {
283
+            $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true));
284
+        }
285
+
286
+        $cache = $this->cache_get($cle);
287
+        if (isset($this->command['datacache'])) {
288
+            $ttl = intval($this->command['datacache']);
289
+        }
290
+        if ($cache
291
+            and ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl'])
292
+                > time())
293
+            and !(_request('var_mode') === 'recalcul'
294
+                and include_spip('inc/autoriser')
295
+                and autoriser('recalcul')
296
+            )
297
+        ) {
298
+            $this->tableau = $cache['data'];
299
+        } else {
300
+            try {
301
+                if (isset($this->command['sourcemode'])
302
+                    and in_array($this->command['sourcemode'],
303
+                        array('table', 'array', 'tableau'))
304
+                ) {
305
+                    if (is_array($a = $src)
306
+                        or (is_string($a)
307
+                            and $a = str_replace('"', '"', $a) # fragile!
308
+                            and is_array($a = @unserialize($a)))
309
+                    ) {
310
+                        $this->tableau = $a;
311
+                    }
312
+                } else {
313
+                    if (tester_url_absolue($src)) {
314
+                        include_spip('inc/distant');
315
+                        $u = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE);
316
+                        if (!$u) {
317
+                            throw new Exception("404");
318
+                        }
319
+                        if (!isset($ttl)) {
320
+                            $ttl = 24 * 3600;
321
+                        }
322
+                    } else {
323
+                        if (@is_dir($src)) {
324
+                            $u = $src;
325
+                            if (!isset($ttl)) {
326
+                                $ttl = 10;
327
+                            }
328
+                        } else {
329
+                            if (@is_readable($src) && @is_file($src)) {
330
+                                $u = spip_file_get_contents($src);
331
+                                if (!isset($ttl)) {
332
+                                    $ttl = 10;
333
+                                }
334
+                            } else {
335
+                                $u = $src;
336
+                                if (!isset($ttl)) {
337
+                                    $ttl = 10;
338
+                                }
339
+                            }
340
+                        }
341
+                    }
342
+                    if (!$this->err
343
+                        and $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)
344
+                    ) {
345
+                        $args = $this->command['source'];
346
+                        $args[0] = $u;
347
+                        if (is_array($a = call_user_func_array($g, $args))) {
348
+                            $this->tableau = $a;
349
+                        }
350
+                    }
351
+                }
352
+
353
+                if (!is_array($this->tableau)) {
354
+                    $this->err = true;
355
+                }
356
+
357
+                if (!$this->err and isset($ttl) and $ttl > 0) {
358
+                    $this->cache_set($cle, $ttl);
359
+                }
360
+
361
+            } catch (Exception $e) {
362
+                $e = $e->getMessage();
363
+                $err = sprintf("[%s, %s] $e",
364
+                    $src,
365
+                    $this->command['sourcemode']);
366
+                erreur_squelette(array($err, array()));
367
+                $this->err = true;
368
+            }
369
+        }
370
+
371
+        # en cas d'erreur, utiliser le cache si encore dispo
372
+        if ($this->err
373
+            and $cache
374
+        ) {
375
+            $this->tableau = $cache['data'];
376
+            $this->err = false;
377
+        }
378
+    }
379
+
380
+
381
+    /**
382
+     * Retourne un tableau donne depuis un critère liste
383
+     *
384
+     * Critère `{liste X1, X2, X3}`
385
+     *
386
+     * @see critere_DATA_liste_dist()
387
+     *
388
+     **/
389
+    protected function select_liste() {
390
+        # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
391
+        if (!isset($this->command['liste'][1])) {
392
+            if (!is_array($this->command['liste'][0])) {
393
+                $this->command['liste'] = explode(',', $this->command['liste'][0]);
394
+            } else {
395
+                $this->command['liste'] = $this->command['liste'][0];
396
+            }
397
+        }
398
+        $this->tableau = $this->command['liste'];
399
+    }
400
+
401
+    /**
402
+     * Retourne un tableau donne depuis un critere liste
403
+     * Critere {enum Xmin, Xmax}
404
+     *
405
+     **/
406
+    protected function select_enum() {
407
+        # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
408
+        if (!isset($this->command['enum'][1])) {
409
+            if (!is_array($this->command['enum'][0])) {
410
+                $this->command['enum'] = explode(',', $this->command['enum'][0]);
411
+            } else {
412
+                $this->command['enum'] = $this->command['enum'][0];
413
+            }
414
+        }
415
+        if (count($this->command['enum']) >= 3) {
416
+            $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']),
417
+                array_shift($this->command['enum']));
418
+        } else {
419
+            $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']));
420
+        }
421
+        $this->tableau = $enum;
422
+    }
423
+
424
+
425
+    /**
426
+     * extraire le chemin "query.results" du tableau de donnees
427
+     * {datapath query.results}
428
+     *
429
+     **/
430
+    protected function select_datapath() {
431
+        $base = reset($this->command['datapath']);
432
+        if (strlen($base = ltrim(trim($base), "/"))) {
433
+            $this->tableau = table_valeur($this->tableau, $base);
434
+            if (!is_array($this->tableau)) {
435
+                $this->tableau = array();
436
+                $this->err = true;
437
+                spip_log("datapath '$base' absent");
438
+            }
439
+        }
440
+    }
441
+
442
+    /**
443
+     * Ordonner les resultats
444
+     * {par x}
445
+     *
446
+     **/
447
+    protected function select_orderby() {
448
+        $sortfunc = '';
449
+        $aleas = 0;
450
+        foreach ($this->command['orderby'] as $tri) {
451
+            // virer le / initial pour les criteres de la forme {par /xx}
452
+            if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) {
453
+                $r = array_pad($r, 3, null);
454
+
455
+                // tri par cle
456
+                if ($r[1] == 'cle') {
457
+                    if (isset($r[2]) and $r[2]) {
458
+                        krsort($this->tableau);
459
+                    } else {
460
+                        ksort($this->tableau);
461
+                    }
462
+                } # {par hasard}
463
+                else {
464
+                    if ($r[1] == 'hasard') {
465
+                        $k = array_keys($this->tableau);
466
+                        shuffle($k);
467
+                        $v = array();
468
+                        foreach ($k as $cle) {
469
+                            $v[$cle] = $this->tableau[$cle];
470
+                        }
471
+                        $this->tableau = $v;
472
+                    } else {
473
+                        # {par valeur}
474
+                        if ($r[1] == 'valeur') {
475
+                            $tv = '%s';
476
+                        } # {par valeur/xx/yy} ??
477
+                        else {
478
+                            $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')';
479
+                        }
480
+                        $sortfunc .= '
481 481
 					$a = ' . sprintf($tv, '$aa') . ';
482 482
 					$b = ' . sprintf($tv, '$bb') . ';
483 483
 					if ($a <> $b)
484 484
 						return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;';
485
-					}
486
-				}
487
-			}
488
-		}
489
-
490
-		if ($sortfunc) {
491
-			$sortfunc .= "\n return 0;";
492
-			uasort($this->tableau, function($aa, $bb) use ($sortfunc) {
493
-				return eval($sortfunc);
494
-			});
495
-		}
496
-	}
497
-
498
-
499
-	/**
500
-	 * Grouper les resultats
501
-	 * {fusion /x/y/z}
502
-	 *
503
-	 **/
504
-	protected function select_groupby() {
505
-		// virer le / initial pour les criteres de la forme {fusion /xx}
506
-		if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) {
507
-			$vu = array();
508
-			foreach ($this->tableau as $k => $v) {
509
-				$val = table_valeur($v, $fusion);
510
-				if (isset($vu[$val])) {
511
-					unset($this->tableau[$k]);
512
-				} else {
513
-					$vu[$val] = true;
514
-				}
515
-			}
516
-		}
517
-	}
518
-
519
-
520
-	/**
521
-	 * L'iterateur est-il encore valide ?
522
-	 *
523
-	 * @return bool
524
-	 */
525
-	public function valid() {
526
-		return !is_null($this->cle);
527
-	}
528
-
529
-	/**
530
-	 * Retourner la valeur
531
-	 *
532
-	 * @return null
533
-	 */
534
-	public function current() {
535
-		return $this->valeur;
536
-	}
537
-
538
-	/**
539
-	 * Retourner la cle
540
-	 *
541
-	 * @return null
542
-	 */
543
-	public function key() {
544
-		return $this->cle;
545
-	}
546
-
547
-	/**
548
-	 * Passer a la valeur suivante
549
-	 *
550
-	 * @return void
551
-	 */
552
-	public function next() {
553
-		if ($this->valid()) {
554
-			$this->cle = key($this->tableau);
555
-			$this->valeur = current($this->tableau);
556
-			next($this->tableau);
557
-		}
558
-	}
559
-
560
-	/**
561
-	 * Compter le nombre total de resultats
562
-	 *
563
-	 * @return int
564
-	 */
565
-	public function count() {
566
-		if (is_null($this->total)) {
567
-			$this->total = count($this->tableau);
568
-		}
569
-
570
-		return $this->total;
571
-	}
485
+                    }
486
+                }
487
+            }
488
+        }
489
+
490
+        if ($sortfunc) {
491
+            $sortfunc .= "\n return 0;";
492
+            uasort($this->tableau, function($aa, $bb) use ($sortfunc) {
493
+                return eval($sortfunc);
494
+            });
495
+        }
496
+    }
497
+
498
+
499
+    /**
500
+     * Grouper les resultats
501
+     * {fusion /x/y/z}
502
+     *
503
+     **/
504
+    protected function select_groupby() {
505
+        // virer le / initial pour les criteres de la forme {fusion /xx}
506
+        if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) {
507
+            $vu = array();
508
+            foreach ($this->tableau as $k => $v) {
509
+                $val = table_valeur($v, $fusion);
510
+                if (isset($vu[$val])) {
511
+                    unset($this->tableau[$k]);
512
+                } else {
513
+                    $vu[$val] = true;
514
+                }
515
+            }
516
+        }
517
+    }
518
+
519
+
520
+    /**
521
+     * L'iterateur est-il encore valide ?
522
+     *
523
+     * @return bool
524
+     */
525
+    public function valid() {
526
+        return !is_null($this->cle);
527
+    }
528
+
529
+    /**
530
+     * Retourner la valeur
531
+     *
532
+     * @return null
533
+     */
534
+    public function current() {
535
+        return $this->valeur;
536
+    }
537
+
538
+    /**
539
+     * Retourner la cle
540
+     *
541
+     * @return null
542
+     */
543
+    public function key() {
544
+        return $this->cle;
545
+    }
546
+
547
+    /**
548
+     * Passer a la valeur suivante
549
+     *
550
+     * @return void
551
+     */
552
+    public function next() {
553
+        if ($this->valid()) {
554
+            $this->cle = key($this->tableau);
555
+            $this->valeur = current($this->tableau);
556
+            next($this->tableau);
557
+        }
558
+    }
559
+
560
+    /**
561
+     * Compter le nombre total de resultats
562
+     *
563
+     * @return int
564
+     */
565
+    public function count() {
566
+        if (is_null($this->total)) {
567
+            $this->total = count($this->tableau);
568
+        }
569
+
570
+        return $this->total;
571
+    }
572 572
 }
573 573
 
574 574
 /*
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
  * @return array
583 583
  */
584 584
 function inc_file_to_array_dist($u) {
585
-	return preg_split('/\r?\n/', $u);
585
+    return preg_split('/\r?\n/', $u);
586 586
 }
587 587
 
588 588
 /**
@@ -591,9 +591,9 @@  discard block
 block discarded – undo
591 591
  * @return unknown
592 592
  */
593 593
 function inc_plugins_to_array_dist() {
594
-	include_spip('inc/plugin');
594
+    include_spip('inc/plugin');
595 595
 
596
-	return liste_chemin_plugin_actifs();
596
+    return liste_chemin_plugin_actifs();
597 597
 }
598 598
 
599 599
 /**
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
  * @return array
604 604
  */
605 605
 function inc_xml_to_array_dist($u) {
606
-	return @XMLObjectToArray(new SimpleXmlIterator($u));
606
+    return @XMLObjectToArray(new SimpleXmlIterator($u));
607 607
 }
608 608
 
609 609
 /**
@@ -615,14 +615,14 @@  discard block
 block discarded – undo
615 615
  *
616 616
  */
617 617
 function inc_object_to_array($object) {
618
-	if (!is_object($object) && !is_array($object)) {
619
-		return $object;
620
-	}
621
-	if (is_object($object)) {
622
-		$object = get_object_vars($object);
623
-	}
624
-
625
-	return array_map('inc_object_to_array', $object);
618
+    if (!is_object($object) && !is_array($object)) {
619
+        return $object;
620
+    }
621
+    if (is_object($object)) {
622
+        $object = get_object_vars($object);
623
+    }
624
+
625
+    return array_map('inc_object_to_array', $object);
626 626
 }
627 627
 
628 628
 /**
@@ -632,20 +632,20 @@  discard block
 block discarded – undo
632 632
  * @return array|bool
633 633
  */
634 634
 function inc_sql_to_array_dist($u) {
635
-	# sortir le connecteur de $u
636
-	preg_match(',^(?:(\w+):)?(.*)$,S', $u, $v);
637
-	$serveur = (string)$v[1];
638
-	$req = trim($v[2]);
639
-	if ($s = sql_query($req, $serveur)) {
640
-		$r = array();
641
-		while ($t = sql_fetch($s)) {
642
-			$r[] = $t;
643
-		}
644
-
645
-		return $r;
646
-	}
647
-
648
-	return false;
635
+    # sortir le connecteur de $u
636
+    preg_match(',^(?:(\w+):)?(.*)$,S', $u, $v);
637
+    $serveur = (string)$v[1];
638
+    $req = trim($v[2]);
639
+    if ($s = sql_query($req, $serveur)) {
640
+        $r = array();
641
+        while ($t = sql_fetch($s)) {
642
+            $r[] = $t;
643
+        }
644
+
645
+        return $r;
646
+    }
647
+
648
+    return false;
649 649
 }
650 650
 
651 651
 /**
@@ -655,11 +655,11 @@  discard block
 block discarded – undo
655 655
  * @return array|bool
656 656
  */
657 657
 function inc_json_to_array_dist($u) {
658
-	if (is_array($json = json_decode($u))
659
-		or is_object($json)
660
-	) {
661
-		return (array)$json;
662
-	}
658
+    if (is_array($json = json_decode($u))
659
+        or is_object($json)
660
+    ) {
661
+        return (array)$json;
662
+    }
663 663
 }
664 664
 
665 665
 /**
@@ -669,30 +669,30 @@  discard block
 block discarded – undo
669 669
  * @return array|bool
670 670
  */
671 671
 function inc_csv_to_array_dist($u) {
672
-	include_spip('inc/csv');
673
-	list($entete, $csv) = analyse_csv($u);
674
-	array_unshift($csv, $entete);
675
-
676
-	include_spip('inc/charsets');
677
-	$i = 1;
678
-	foreach ($entete as $k => $v) {
679
-		if (trim($v) == "") {
680
-			$v = "col" . $i;
681
-		} // reperer des eventuelles cases vides
682
-		if (is_numeric($v) and $v < 0) {
683
-			$v = "__" . $v;
684
-		} // ne pas risquer d'ecraser une cle numerique
685
-		if (is_numeric($v)) {
686
-			$v = "_" . $v;
687
-		} // ne pas risquer d'ecraser une cle numerique
688
-		$v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
689
-		foreach ($csv as &$item) {
690
-			$item[$v] = &$item[$k];
691
-		}
692
-		$i++;
693
-	}
694
-
695
-	return $csv;
672
+    include_spip('inc/csv');
673
+    list($entete, $csv) = analyse_csv($u);
674
+    array_unshift($csv, $entete);
675
+
676
+    include_spip('inc/charsets');
677
+    $i = 1;
678
+    foreach ($entete as $k => $v) {
679
+        if (trim($v) == "") {
680
+            $v = "col" . $i;
681
+        } // reperer des eventuelles cases vides
682
+        if (is_numeric($v) and $v < 0) {
683
+            $v = "__" . $v;
684
+        } // ne pas risquer d'ecraser une cle numerique
685
+        if (is_numeric($v)) {
686
+            $v = "_" . $v;
687
+        } // ne pas risquer d'ecraser une cle numerique
688
+        $v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
689
+        foreach ($csv as &$item) {
690
+            $item[$v] = &$item[$k];
691
+        }
692
+        $i++;
693
+    }
694
+
695
+    return $csv;
696 696
 }
697 697
 
698 698
 /**
@@ -702,12 +702,12 @@  discard block
 block discarded – undo
702 702
  * @return array|bool
703 703
  */
704 704
 function inc_rss_to_array_dist($u) {
705
-	include_spip('inc/syndic');
706
-	if (is_array($rss = analyser_backend($u))) {
707
-		$tableau = $rss;
708
-	}
705
+    include_spip('inc/syndic');
706
+    if (is_array($rss = analyser_backend($u))) {
707
+        $tableau = $rss;
708
+    }
709 709
 
710
-	return $tableau;
710
+    return $tableau;
711 711
 }
712 712
 
713 713
 /**
@@ -717,9 +717,9 @@  discard block
 block discarded – undo
717 717
  * @return array|bool
718 718
  */
719 719
 function inc_atom_to_array_dist($u) {
720
-	$g = charger_fonction('rss_to_array', 'inc');
720
+    $g = charger_fonction('rss_to_array', 'inc');
721 721
 
722
-	return $g($u);
722
+    return $g($u);
723 723
 }
724 724
 
725 725
 /**
@@ -730,11 +730,11 @@  discard block
 block discarded – undo
730 730
  * @return array|bool
731 731
  */
732 732
 function inc_glob_to_array_dist($u) {
733
-	$a = glob($u,
734
-		GLOB_MARK | GLOB_NOSORT | GLOB_BRACE
735
-	);
733
+    $a = glob($u,
734
+        GLOB_MARK | GLOB_NOSORT | GLOB_BRACE
735
+    );
736 736
 
737
-	return $a ? $a : array();
737
+    return $a ? $a : array();
738 738
 }
739 739
 
740 740
 /**
@@ -745,14 +745,14 @@  discard block
 block discarded – undo
745 745
  * @throws Exception
746 746
  */
747 747
 function inc_yaml_to_array_dist($u) {
748
-	include_spip('inc/yaml-mini');
749
-	if (!function_exists("yaml_decode")) {
750
-		throw new Exception('YAML: impossible de trouver la fonction yaml_decode');
748
+    include_spip('inc/yaml-mini');
749
+    if (!function_exists("yaml_decode")) {
750
+        throw new Exception('YAML: impossible de trouver la fonction yaml_decode');
751 751
 
752
-		return false;
753
-	}
752
+        return false;
753
+    }
754 754
 
755
-	return yaml_decode($u);
755
+    return yaml_decode($u);
756 756
 }
757 757
 
758 758
 
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
  * @return array|bool
768 768
  */
769 769
 function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) {
770
-	return (array)preg_files($dir, $regexp, $limit);
770
+    return (array)preg_files($dir, $regexp, $limit);
771 771
 }
772 772
 
773 773
 /**
@@ -779,23 +779,23 @@  discard block
 block discarded – undo
779 779
  * @return array|bool
780 780
  */
781 781
 function inc_ls_to_array_dist($u) {
782
-	$glob = charger_fonction('glob_to_array', 'inc');
783
-	$a = $glob($u);
784
-	foreach ($a as &$v) {
785
-		$b = (array)@stat($v);
786
-		foreach ($b as $k => $ignore) {
787
-			if (is_numeric($k)) {
788
-				unset($b[$k]);
789
-			}
790
-		}
791
-		$b['file'] = preg_replace('`/$`','',$v) ;
792
-		$v = array_merge(
793
-			pathinfo($v),
794
-			$b
795
-		);
796
-	}
797
-
798
-	return $a;
782
+    $glob = charger_fonction('glob_to_array', 'inc');
783
+    $a = $glob($u);
784
+    foreach ($a as &$v) {
785
+        $b = (array)@stat($v);
786
+        foreach ($b as $k => $ignore) {
787
+            if (is_numeric($k)) {
788
+                unset($b[$k]);
789
+            }
790
+        }
791
+        $b['file'] = preg_replace('`/$`','',$v) ;
792
+        $v = array_merge(
793
+            pathinfo($v),
794
+            $b
795
+        );
796
+    }
797
+
798
+    return $a;
799 799
 }
800 800
 
801 801
 /**
@@ -805,24 +805,24 @@  discard block
 block discarded – undo
805 805
  * @return array|bool
806 806
  */
807 807
 function XMLObjectToArray($object) {
808
-	$xml_array = array();
809
-	for ($object->rewind(); $object->valid(); $object->next()) {
810
-		if (array_key_exists($key = $object->key(), $xml_array)) {
811
-			$key .= '-' . uniqid();
812
-		}
813
-		$vars = get_object_vars($object->current());
814
-		if (isset($vars['@attributes'])) {
815
-			foreach ($vars['@attributes'] as $k => $v) {
816
-				$xml_array[$key][$k] = $v;
817
-			}
818
-		}
819
-		if ($object->hasChildren()) {
820
-			$xml_array[$key][] = XMLObjectToArray(
821
-				$object->current());
822
-		} else {
823
-			$xml_array[$key][] = strval($object->current());
824
-		}
825
-	}
826
-
827
-	return $xml_array;
808
+    $xml_array = array();
809
+    for ($object->rewind(); $object->valid(); $object->next()) {
810
+        if (array_key_exists($key = $object->key(), $xml_array)) {
811
+            $key .= '-' . uniqid();
812
+        }
813
+        $vars = get_object_vars($object->current());
814
+        if (isset($vars['@attributes'])) {
815
+            foreach ($vars['@attributes'] as $k => $v) {
816
+                $xml_array[$key][$k] = $v;
817
+            }
818
+        }
819
+        if ($object->hasChildren()) {
820
+            $xml_array[$key][] = XMLObjectToArray(
821
+                $object->current());
822
+        } else {
823
+            $xml_array[$key][] = strval($object->current());
824
+        }
825
+    }
826
+
827
+    return $xml_array;
828 828
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 		// Si a ce stade on n'a pas de table, il y a un bug
232 232
 		if (!is_array($this->tableau)) {
233 233
 			$this->err = true;
234
-			spip_log("erreur datasource " . var_export($command, true));
234
+			spip_log("erreur datasource ".var_export($command, true));
235 235
 		}
236 236
 
237 237
 		// {datapath query.results}
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 		if (isset($this->command['sourcemode'])
272 272
 			and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau'))
273 273
 		) {
274
-			charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true);
274
+			charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true);
275 275
 		}
276 276
 
277 277
 		# le premier argument peut etre un array, une URL etc.
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 		# avons-nous un cache dispo ?
281 281
 		$cle = null;
282 282
 		if (is_string($src)) {
283
-			$cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true));
283
+			$cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'], true));
284 284
 		}
285 285
 
286 286
 		$cache = $this->cache_get($cle);
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 						}
341 341
 					}
342 342
 					if (!$this->err
343
-						and $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)
343
+						and $g = charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true)
344 344
 					) {
345 345
 						$args = $this->command['source'];
346 346
 						$args[0] = $u;
@@ -475,13 +475,13 @@  discard block
 block discarded – undo
475 475
 							$tv = '%s';
476 476
 						} # {par valeur/xx/yy} ??
477 477
 						else {
478
-							$tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')';
478
+							$tv = 'table_valeur(%s, '.var_export($r[1], true).')';
479 479
 						}
480 480
 						$sortfunc .= '
481
-					$a = ' . sprintf($tv, '$aa') . ';
482
-					$b = ' . sprintf($tv, '$bb') . ';
481
+					$a = ' . sprintf($tv, '$aa').';
482
+					$b = ' . sprintf($tv, '$bb').';
483 483
 					if ($a <> $b)
484
-						return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;';
484
+						return ($a ' . (!empty($r[2]) ? '>' : '<').' $b) ? -1 : 1;';
485 485
 					}
486 486
 				}
487 487
 			}
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
 function inc_sql_to_array_dist($u) {
635 635
 	# sortir le connecteur de $u
636 636
 	preg_match(',^(?:(\w+):)?(.*)$,S', $u, $v);
637
-	$serveur = (string)$v[1];
637
+	$serveur = (string) $v[1];
638 638
 	$req = trim($v[2]);
639 639
 	if ($s = sql_query($req, $serveur)) {
640 640
 		$r = array();
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
 	if (is_array($json = json_decode($u))
659 659
 		or is_object($json)
660 660
 	) {
661
-		return (array)$json;
661
+		return (array) $json;
662 662
 	}
663 663
 }
664 664
 
@@ -677,13 +677,13 @@  discard block
 block discarded – undo
677 677
 	$i = 1;
678 678
 	foreach ($entete as $k => $v) {
679 679
 		if (trim($v) == "") {
680
-			$v = "col" . $i;
680
+			$v = "col".$i;
681 681
 		} // reperer des eventuelles cases vides
682 682
 		if (is_numeric($v) and $v < 0) {
683
-			$v = "__" . $v;
683
+			$v = "__".$v;
684 684
 		} // ne pas risquer d'ecraser une cle numerique
685 685
 		if (is_numeric($v)) {
686
-			$v = "_" . $v;
686
+			$v = "_".$v;
687 687
 		} // ne pas risquer d'ecraser une cle numerique
688 688
 		$v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
689 689
 		foreach ($csv as &$item) {
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
  * @return array|bool
768 768
  */
769 769
 function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) {
770
-	return (array)preg_files($dir, $regexp, $limit);
770
+	return (array) preg_files($dir, $regexp, $limit);
771 771
 }
772 772
 
773 773
 /**
@@ -782,13 +782,13 @@  discard block
 block discarded – undo
782 782
 	$glob = charger_fonction('glob_to_array', 'inc');
783 783
 	$a = $glob($u);
784 784
 	foreach ($a as &$v) {
785
-		$b = (array)@stat($v);
785
+		$b = (array) @stat($v);
786 786
 		foreach ($b as $k => $ignore) {
787 787
 			if (is_numeric($k)) {
788 788
 				unset($b[$k]);
789 789
 			}
790 790
 		}
791
-		$b['file'] = preg_replace('`/$`','',$v) ;
791
+		$b['file'] = preg_replace('`/$`', '', $v);
792 792
 		$v = array_merge(
793 793
 			pathinfo($v),
794 794
 			$b
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
 	$xml_array = array();
809 809
 	for ($object->rewind(); $object->valid(); $object->next()) {
810 810
 		if (array_key_exists($key = $object->key(), $xml_array)) {
811
-			$key .= '-' . uniqid();
811
+			$key .= '-'.uniqid();
812 812
 		}
813 813
 		$vars = get_object_vars($object->current());
814 814
 		if (isset($vars['@attributes'])) {
Please login to merge, or discard this patch.