Completed
Push — master ( 9b54d2...c65e43 )
by cam
01:57
created
ecrire/inc/filtres_dates.php 2 patches
Indentation   +562 added lines, -562 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Filtres
16 16
  **/
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 /**
@@ -36,29 +36,29 @@  discard block
 block discarded – undo
36 36
  *     - une chaîne vide si la date est considérée nulle
37 37
  **/
38 38
 function normaliser_date($date, $forcer_jour = false): string {
39
-	$date = vider_date($date);
40
-	if ($date) {
41
-		if (preg_match('/^\d{8,10}$/', $date)) {
42
-			$date = date('Y-m-d H:i:s', $date);
43
-		}
44
-		if (preg_match('#^([12]\d{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
45
-			$regs = array_pad($regs, 4, null); // eviter notice php
46
-			$date = $regs[1] . '-00-00' . $regs[3];
47
-		} else {
48
-			if (preg_match('#^([12]\d{3}[-/][01]?\d)([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
49
-				$regs = array_pad($regs, 4, null); // eviter notice php
50
-				$date = preg_replace('@/@', '-', (string) $regs[1]) . '-00' . $regs[3];
51
-			} else {
52
-				$date = date('Y-m-d H:i:s', strtotime($date));
53
-			}
54
-		}
55
-
56
-		if ($forcer_jour) {
57
-			$date = str_replace('-00', '-01', $date);
58
-		}
59
-	}
60
-
61
-	return $date;
39
+    $date = vider_date($date);
40
+    if ($date) {
41
+        if (preg_match('/^\d{8,10}$/', $date)) {
42
+            $date = date('Y-m-d H:i:s', $date);
43
+        }
44
+        if (preg_match('#^([12]\d{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
45
+            $regs = array_pad($regs, 4, null); // eviter notice php
46
+            $date = $regs[1] . '-00-00' . $regs[3];
47
+        } else {
48
+            if (preg_match('#^([12]\d{3}[-/][01]?\d)([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
49
+                $regs = array_pad($regs, 4, null); // eviter notice php
50
+                $date = preg_replace('@/@', '-', (string) $regs[1]) . '-00' . $regs[3];
51
+            } else {
52
+                $date = date('Y-m-d H:i:s', strtotime($date));
53
+            }
54
+        }
55
+
56
+        if ($forcer_jour) {
57
+            $date = str_replace('-00', '-01', $date);
58
+        }
59
+    }
60
+
61
+    return $date;
62 62
 }
63 63
 
64 64
 /**
@@ -71,22 +71,22 @@  discard block
 block discarded – undo
71 71
  *     - Une chaine vide
72 72
  **/
73 73
 function vider_date($letexte, $verif_format_date = false): string {
74
-	$letexte ??= '';
75
-	if (
76
-		!$verif_format_date
77
-		|| in_array(strlen($letexte), [10,19]) && preg_match('/^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}:\d{2})?$/', $letexte)
78
-	) {
79
-		if (strncmp('0000-00-00', $letexte, 10) == 0) {
80
-			return '';
81
-		}
82
-		if (strncmp('0001-01-01', $letexte, 10) == 0) {
83
-			return '';
84
-		}
85
-		if (strncmp('1970-01-01', $letexte, 10) == 0) {
86
-			return '';
87
-		}  // eviter le bug GMT-1
88
-	}
89
-	return $letexte;
74
+    $letexte ??= '';
75
+    if (
76
+        !$verif_format_date
77
+        || in_array(strlen($letexte), [10,19]) && preg_match('/^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}:\d{2})?$/', $letexte)
78
+    ) {
79
+        if (strncmp('0000-00-00', $letexte, 10) == 0) {
80
+            return '';
81
+        }
82
+        if (strncmp('0001-01-01', $letexte, 10) == 0) {
83
+            return '';
84
+        }
85
+        if (strncmp('1970-01-01', $letexte, 10) == 0) {
86
+            return '';
87
+        }  // eviter le bug GMT-1
88
+    }
89
+    return $letexte;
90 90
 }
91 91
 
92 92
 /**
@@ -102,17 +102,17 @@  discard block
 block discarded – undo
102 102
  **/
103 103
 function recup_heure($date): array {
104 104
 
105
-	if (preg_match('#(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?#', $date, $elements)) {
106
-		array_shift($elements);
107
-		if (!isset($elements[2])) {
108
-			$elements[2] = 0;
109
-		}
110
-		$heure = $elements;
111
-	} else {
112
-		$heure = [0, 0, 0];
113
-	}
114
-
115
-	return $heure;
105
+    if (preg_match('#(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?#', $date, $elements)) {
106
+        array_shift($elements);
107
+        if (!isset($elements[2])) {
108
+            $elements[2] = 0;
109
+        }
110
+        $heure = $elements;
111
+    } else {
112
+        $heure = [0, 0, 0];
113
+    }
114
+
115
+    return $heure;
116 116
 }
117 117
 
118 118
 /**
@@ -126,13 +126,13 @@  discard block
 block discarded – undo
126 126
  * @return string heures, sinon 0
127 127
  **/
128 128
 function heures($numdate): string {
129
-	$heures = null;
130
-	$date_array = recup_heure($numdate);
131
-	if ($date_array) {
132
-		[$heures, $minutes, $secondes] = $date_array;
133
-	}
129
+    $heures = null;
130
+    $date_array = recup_heure($numdate);
131
+    if ($date_array) {
132
+        [$heures, $minutes, $secondes] = $date_array;
133
+    }
134 134
 
135
-	return $heures;
135
+    return $heures;
136 136
 }
137 137
 
138 138
 /**
@@ -146,13 +146,13 @@  discard block
 block discarded – undo
146 146
  * @return string minutes, sinon 0
147 147
  **/
148 148
 function minutes($numdate): string {
149
-	$minutes = null;
150
-	$date_array = recup_heure($numdate);
151
-	if ($date_array) {
152
-		[$heures, $minutes, $secondes] = $date_array;
153
-	}
149
+    $minutes = null;
150
+    $date_array = recup_heure($numdate);
151
+    if ($date_array) {
152
+        [$heures, $minutes, $secondes] = $date_array;
153
+    }
154 154
 
155
-	return $minutes;
155
+    return $minutes;
156 156
 }
157 157
 
158 158
 /**
@@ -166,13 +166,13 @@  discard block
 block discarded – undo
166 166
  * @return string secondes, sinon 0
167 167
  **/
168 168
 function secondes($numdate): string {
169
-	$secondes = null;
170
-	$date_array = recup_heure($numdate);
171
-	if ($date_array) {
172
-		[$heures, $minutes, $secondes] = $date_array;
173
-	}
169
+    $secondes = null;
170
+    $date_array = recup_heure($numdate);
171
+    if ($date_array) {
172
+        [$heures, $minutes, $secondes] = $date_array;
173
+    }
174 174
 
175
-	return $secondes;
175
+    return $secondes;
176 176
 }
177 177
 
178 178
 /**
@@ -191,11 +191,11 @@  discard block
 block discarded – undo
191 191
  * @return string L'heure formatée dans la langue en cours.
192 192
  **/
193 193
 function heures_minutes($numdate, $forme = ''): string {
194
-	if ($forme !== 'abbr') {
195
-		return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]);
196
-	} else {
197
-		return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]);
198
-	}
194
+    if ($forme !== 'abbr') {
195
+        return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]);
196
+    } else {
197
+        return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]);
198
+    }
199 199
 }
200 200
 
201 201
 /**
@@ -220,57 +220,57 @@  discard block
 block discarded – undo
220 220
  * @return array [année, mois, jour, heures, minutes, secondes] ou []
221 221
  **/
222 222
 function recup_date($numdate, $forcer_jour = true): array {
223
-	if (!$numdate) {
224
-		return [];
225
-	}
226
-	$heures = $minutes = $secondes = 0;
227
-	if (preg_match('#(\d{1,2})/(\d{1,2})/(\d{4}|\d{1,2})#', $numdate, $regs)) {
228
-		$jour = $regs[1];
229
-		$mois = $regs[2];
230
-		$annee = $regs[3];
231
-		if ($annee < 90) {
232
-			$annee = 2000 + $annee;
233
-		} elseif ($annee < 100) {
234
-			$annee = 1900 + $annee;
235
-		}
236
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
237
-	} elseif (preg_match('#(\d{4})-(\d{1,2})-(\d{1,2})#', $numdate, $regs)) {
238
-		$annee = $regs[1];
239
-		$mois = $regs[2];
240
-		$jour = $regs[3];
241
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
242
-	} elseif (preg_match('#(\d{4})-(\d{2})#', $numdate, $regs)) {
243
-		$annee = $regs[1];
244
-		$mois = $regs[2];
245
-		$jour = '';
246
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
247
-	} elseif (preg_match('#^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$#', $numdate, $regs)) {
248
-		$annee = $regs[1];
249
-		$mois = $regs[2];
250
-		$jour = $regs[3];
251
-		$heures = $regs[4];
252
-		$minutes = $regs[5];
253
-		$secondes = $regs[6];
254
-	} else {
255
-		$annee = $mois = $jour = '';
256
-	}
257
-	if ($annee > 4000) {
258
-		$annee -= 9000;
259
-	}
260
-	if (strlen($jour) && str_starts_with($jour, '0')) {
261
-		$jour = substr($jour, 1);
262
-	}
263
-
264
-	if ($forcer_jour && $jour == '0') {
265
-		$jour = '1';
266
-	}
267
-	if ($forcer_jour && $mois == '0') {
268
-		$mois = '1';
269
-	}
270
-	if ($annee || $mois || $jour || $heures || $minutes || $secondes) {
271
-		return [$annee, $mois, $jour, $heures, $minutes, $secondes];
272
-	}
273
-	return [];
223
+    if (!$numdate) {
224
+        return [];
225
+    }
226
+    $heures = $minutes = $secondes = 0;
227
+    if (preg_match('#(\d{1,2})/(\d{1,2})/(\d{4}|\d{1,2})#', $numdate, $regs)) {
228
+        $jour = $regs[1];
229
+        $mois = $regs[2];
230
+        $annee = $regs[3];
231
+        if ($annee < 90) {
232
+            $annee = 2000 + $annee;
233
+        } elseif ($annee < 100) {
234
+            $annee = 1900 + $annee;
235
+        }
236
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
237
+    } elseif (preg_match('#(\d{4})-(\d{1,2})-(\d{1,2})#', $numdate, $regs)) {
238
+        $annee = $regs[1];
239
+        $mois = $regs[2];
240
+        $jour = $regs[3];
241
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
242
+    } elseif (preg_match('#(\d{4})-(\d{2})#', $numdate, $regs)) {
243
+        $annee = $regs[1];
244
+        $mois = $regs[2];
245
+        $jour = '';
246
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
247
+    } elseif (preg_match('#^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$#', $numdate, $regs)) {
248
+        $annee = $regs[1];
249
+        $mois = $regs[2];
250
+        $jour = $regs[3];
251
+        $heures = $regs[4];
252
+        $minutes = $regs[5];
253
+        $secondes = $regs[6];
254
+    } else {
255
+        $annee = $mois = $jour = '';
256
+    }
257
+    if ($annee > 4000) {
258
+        $annee -= 9000;
259
+    }
260
+    if (strlen($jour) && str_starts_with($jour, '0')) {
261
+        $jour = substr($jour, 1);
262
+    }
263
+
264
+    if ($forcer_jour && $jour == '0') {
265
+        $jour = '1';
266
+    }
267
+    if ($forcer_jour && $mois == '0') {
268
+        $mois = '1';
269
+    }
270
+    if ($annee || $mois || $jour || $heures || $minutes || $secondes) {
271
+        return [$annee, $mois, $jour, $heures, $minutes, $secondes];
272
+    }
273
+    return [];
274 274
 }
275 275
 
276 276
 /**
@@ -297,10 +297,10 @@  discard block
 block discarded – undo
297 297
  *     La date relative ou complète
298 298
  **/
299 299
 function date_interface($date, $decalage_maxi = 43200 /* 12*3600 */): string {
300
-	return sinon(
301
-		date_relative($date, $decalage_maxi),
302
-		affdate_heure($date)
303
-	);
300
+    return sinon(
301
+        date_relative($date, $decalage_maxi),
302
+        affdate_heure($date)
303
+    );
304 304
 }
305 305
 
306 306
 /**
@@ -333,72 +333,72 @@  discard block
 block discarded – undo
333 333
  **/
334 334
 function date_relative($date, $decalage_maxi = 0, $ref_date = null): string {
335 335
 
336
-	if (!$date) {
337
-		return '';
338
-	}
339
-
340
-	$ref_time = is_null($ref_date) ? time() : strtotime($ref_date);
341
-
342
-	$decal = date('U', $ref_time) - date('U', strtotime($date));
343
-
344
-	if ($decalage_maxi && ($decal > $decalage_maxi || $decal < 0)) {
345
-		return '';
346
-	}
347
-
348
-	if ($decal < 0) {
349
-		$il_y_a = 'date_dans';
350
-		$decal = -1 * $decal;
351
-	} else {
352
-		$il_y_a = 'date_il_y_a';
353
-	}
354
-
355
-	if ($decal > 3600 * 24 * 30 * 6) {
356
-		return affdate_court($date);
357
-	}
358
-
359
-	if ($decal > 3600 * 24 * 30) {
360
-		$mois = floor($decal / (3600 * 24 * 30));
361
-		$delai = $mois < 2
362
-			? "$mois " . _T('date_un_mois')
363
-			: "$mois " . _T('date_mois');
364
-	} else {
365
-		if ($decal > 3600 * 24 * 7) {
366
-			$semaines = floor($decal / (3600 * 24 * 7));
367
-			$delai = $semaines < 2
368
-				? "$semaines " . _T('date_une_semaine')
369
-				: "$semaines " . _T('date_semaines');
370
-		} else {
371
-			if ($decal > 3600 * 24) {
372
-				$jours = floor($decal / (3600 * 24));
373
-				if ($jours < 2) {
374
-					return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
375
-				} else {
376
-					$delai = "$jours " . _T('date_jours');
377
-				}
378
-			} else {
379
-				if ($decal >= 3600) {
380
-					$heures = floor($decal / 3600);
381
-					$delai = $heures < 2
382
-						? "$heures " . _T('date_une_heure')
383
-						: "$heures " . _T('date_heures');
384
-				} else {
385
-					if ($decal >= 60) {
386
-						$minutes = floor($decal / 60);
387
-						$delai = $minutes < 2
388
-							? "$minutes " . _T('date_une_minute')
389
-							: "$minutes " . _T('date_minutes');
390
-					} else {
391
-						$secondes = ceil($decal);
392
-						$delai = $secondes < 2
393
-							? "$secondes " . _T('date_une_seconde')
394
-							: "$secondes " . _T('date_secondes');
395
-					}
396
-				}
397
-			}
398
-		}
399
-	}
400
-
401
-	return _T($il_y_a, ['delai' => $delai]);
336
+    if (!$date) {
337
+        return '';
338
+    }
339
+
340
+    $ref_time = is_null($ref_date) ? time() : strtotime($ref_date);
341
+
342
+    $decal = date('U', $ref_time) - date('U', strtotime($date));
343
+
344
+    if ($decalage_maxi && ($decal > $decalage_maxi || $decal < 0)) {
345
+        return '';
346
+    }
347
+
348
+    if ($decal < 0) {
349
+        $il_y_a = 'date_dans';
350
+        $decal = -1 * $decal;
351
+    } else {
352
+        $il_y_a = 'date_il_y_a';
353
+    }
354
+
355
+    if ($decal > 3600 * 24 * 30 * 6) {
356
+        return affdate_court($date);
357
+    }
358
+
359
+    if ($decal > 3600 * 24 * 30) {
360
+        $mois = floor($decal / (3600 * 24 * 30));
361
+        $delai = $mois < 2
362
+            ? "$mois " . _T('date_un_mois')
363
+            : "$mois " . _T('date_mois');
364
+    } else {
365
+        if ($decal > 3600 * 24 * 7) {
366
+            $semaines = floor($decal / (3600 * 24 * 7));
367
+            $delai = $semaines < 2
368
+                ? "$semaines " . _T('date_une_semaine')
369
+                : "$semaines " . _T('date_semaines');
370
+        } else {
371
+            if ($decal > 3600 * 24) {
372
+                $jours = floor($decal / (3600 * 24));
373
+                if ($jours < 2) {
374
+                    return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
375
+                } else {
376
+                    $delai = "$jours " . _T('date_jours');
377
+                }
378
+            } else {
379
+                if ($decal >= 3600) {
380
+                    $heures = floor($decal / 3600);
381
+                    $delai = $heures < 2
382
+                        ? "$heures " . _T('date_une_heure')
383
+                        : "$heures " . _T('date_heures');
384
+                } else {
385
+                    if ($decal >= 60) {
386
+                        $minutes = floor($decal / 60);
387
+                        $delai = $minutes < 2
388
+                            ? "$minutes " . _T('date_une_minute')
389
+                            : "$minutes " . _T('date_minutes');
390
+                    } else {
391
+                        $secondes = ceil($decal);
392
+                        $delai = $secondes < 2
393
+                            ? "$secondes " . _T('date_une_seconde')
394
+                            : "$secondes " . _T('date_secondes');
395
+                    }
396
+                }
397
+            }
398
+        }
399
+    }
400
+
401
+    return _T($il_y_a, ['delai' => $delai]);
402 402
 }
403 403
 
404 404
 
@@ -424,30 +424,30 @@  discard block
 block discarded – undo
424 424
  **/
425 425
 function date_relativecourt($date, $decalage_maxi = 0): string {
426 426
 
427
-	if (!$date) {
428
-		return '';
429
-	}
430
-	$decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
431
-
432
-	if ($decalage_maxi && ($decal > $decalage_maxi || $decal < 0)) {
433
-		return '';
434
-	}
435
-
436
-	if ($decal < -24 * 3600) {
437
-		$retour = date_relative($date, $decalage_maxi);
438
-	} elseif ($decal < 0) {
439
-		$retour = _T('date_demain');
440
-	} else {
441
-		if ($decal < (3600 * 24)) {
442
-			$retour = _T('date_aujourdhui');
443
-		} else {
444
-			$retour = $decal < (3600 * 24 * 2)
445
-				? _T('date_hier')
446
-				: date_relative($date, $decalage_maxi);
447
-		}
448
-	}
449
-
450
-	return $retour;
427
+    if (!$date) {
428
+        return '';
429
+    }
430
+    $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
431
+
432
+    if ($decalage_maxi && ($decal > $decalage_maxi || $decal < 0)) {
433
+        return '';
434
+    }
435
+
436
+    if ($decal < -24 * 3600) {
437
+        $retour = date_relative($date, $decalage_maxi);
438
+    } elseif ($decal < 0) {
439
+        $retour = _T('date_demain');
440
+    } else {
441
+        if ($decal < (3600 * 24)) {
442
+            $retour = _T('date_aujourdhui');
443
+        } else {
444
+            $retour = $decal < (3600 * 24 * 2)
445
+                ? _T('date_hier')
446
+                : date_relative($date, $decalage_maxi);
447
+        }
448
+    }
449
+
450
+    return $retour;
451 451
 }
452 452
 
453 453
 /**
@@ -464,173 +464,173 @@  discard block
 block discarded – undo
464 464
  * @return string
465 465
  */
466 466
 function affdate_base($numdate, $vue, $options = []): string {
467
-	if (is_string($options)) {
468
-		$options = ['param' => $options];
469
-	}
470
-	$date_array = recup_date($numdate, false);
471
-	if (!$date_array) {
472
-		return '';
473
-	}
474
-	[$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
475
-
476
-	// 1er, 21st, etc.
477
-	$journum = $jour;
478
-
479
-	if ($jour == 0) {
480
-		$jour = '';
481
-		$njour = 0;
482
-	} else {
483
-		$njour = (int) $jour;
484
-		if ($jourth = _T('date_jnum' . $jour)) {
485
-			$jour = $jourth;
486
-		}
487
-	}
488
-
489
-	$mois = (int) $mois;
490
-	if ($mois > 0 && $mois < 13) {
491
-		/* Traiter le cas "abbr" pour les noms de mois */
492
-		$param = ((isset($options['param']) && $options['param'] === 'abbr') ? '_' . $options['param'] : '');
493
-		$nommois = _T('date_mois_' . $mois . $param);
494
-		$jourmois = $jour
495
-			? _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois])
496
-			: $nommois;
497
-	} else {
498
-		$nommois = '';
499
-		$jourmois = '';
500
-	}
501
-
502
-	if ($annee < 0) {
503
-		$annee = -$annee . ' ' . _T('date_avant_jc');
504
-		$avjc = true;
505
-	} else {
506
-		$avjc = false;
507
-	}
508
-
509
-	switch ($vue) {
510
-		case 'saison':
511
-		case 'saison_annee':
512
-			$saison = '';
513
-			if ($mois > 0) {
514
-				$saison = ($options['param'] == 'sud') ? 3 : 1;
515
-				if ($mois == 3 && $jour >= 21 || $mois > 3) {
516
-					$saison = ($options['param'] == 'sud') ? 4 : 2;
517
-				}
518
-				if ($mois == 6 && $jour >= 21 || $mois > 6) {
519
-					$saison = ($options['param'] == 'sud') ? 1 : 3;
520
-				}
521
-				if ($mois == 9 && $jour >= 21 || $mois > 9) {
522
-					$saison = ($options['param'] == 'sud') ? 2 : 4;
523
-				}
524
-				if ($mois == 12 && $jour >= 21 || $mois > 12) {
525
-					$saison = ($options['param'] == 'sud') ? 3 : 1;
526
-				}
527
-			}
528
-			if ($vue == 'saison') {
529
-				return $saison ? _T('date_saison_' . $saison) : '';
530
-			} else {
531
-				return $saison ? trim((string) _T(
532
-					'date_fmt_saison_annee',
533
-					['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
534
-				)) : '';
535
-			}
536
-
537
-		case 'court':
538
-			if ($avjc) {
539
-				return $annee;
540
-			}
541
-			$a = ((isset($options['annee_courante']) && $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
542
-			if ($annee < ($a - 100) || $annee > ($a + 100)) {
543
-				return $annee;
544
-			}
545
-			if ($annee != $a) {
546
-				return _T(
547
-					'date_fmt_mois_annee',
548
-					['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee]
549
-				);
550
-			}
551
-
552
-			return _T(
553
-				'date_fmt_jour_mois',
554
-				['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
555
-			);
556
-
557
-		case 'jourcourt':
558
-			if ($avjc) {
559
-				return $annee;
560
-			}
561
-			$a = ((isset($options['annee_courante']) && $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
562
-			if ($annee < ($a - 100) || $annee > ($a + 100)) {
563
-				return $annee;
564
-			}
565
-			if ($annee != $a) {
566
-				return _T(
567
-					'date_fmt_jour_mois_annee',
568
-					['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
569
-				);
570
-			}
571
-
572
-			return _T(
573
-				'date_fmt_jour_mois',
574
-				['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
575
-			);
576
-
577
-		case 'entier':
578
-			if ($avjc) {
579
-				return $annee;
580
-			}
581
-			if ($jour) {
582
-				return _T(
583
-					'date_fmt_jour_mois_annee',
584
-					['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
585
-				);
586
-			} elseif ($mois) {
587
-				return trim((string) _T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
588
-			} else {
589
-				return $annee;
590
-			}
591
-
592
-		case 'nom_mois':
593
-			return $nommois;
594
-
595
-		case 'mois':
596
-			return sprintf('%02s', $mois);
597
-
598
-		case 'jour':
599
-			return $jour;
600
-
601
-		case 'journum':
602
-			return $journum;
603
-
604
-		case 'nom_jour':
605
-			if (!$mois || !$njour) {
606
-				return '';
607
-			}
608
-			$nom = mktime(1, 1, 1, $mois, $njour, $annee);
609
-			$nom = 1 + (int) date('w', $nom);
610
-			$param = ((isset($options['param']) && $options['param']) ? '_' . $options['param'] : '');
611
-
612
-			return _T('date_jour_' . $nom . $param);
613
-
614
-		case 'mois_annee':
615
-			if ($avjc) {
616
-				return $annee;
617
-			}
618
-
619
-			return trim((string) _T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
620
-
621
-		case 'annee':
622
-			return $annee;
623
-
624
-		// Cas d'une vue non definie : retomber sur le format
625
-		// de date propose par http://www.php.net/date
626
-		default:
627
-			[$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
628
-			// il faut envoyer jour = 1 si jour pas défini, c'est le comportement qu'on avait historiquement en envoyant ''
629
-			if (!$time = mktime($heures, $minutes, $secondes, $mois, is_numeric($jour) ? $jour : 1, $annee)) {
630
-				$time = strtotime($numdate);
631
-			}
632
-			return date($vue, $time);
633
-	}
467
+    if (is_string($options)) {
468
+        $options = ['param' => $options];
469
+    }
470
+    $date_array = recup_date($numdate, false);
471
+    if (!$date_array) {
472
+        return '';
473
+    }
474
+    [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
475
+
476
+    // 1er, 21st, etc.
477
+    $journum = $jour;
478
+
479
+    if ($jour == 0) {
480
+        $jour = '';
481
+        $njour = 0;
482
+    } else {
483
+        $njour = (int) $jour;
484
+        if ($jourth = _T('date_jnum' . $jour)) {
485
+            $jour = $jourth;
486
+        }
487
+    }
488
+
489
+    $mois = (int) $mois;
490
+    if ($mois > 0 && $mois < 13) {
491
+        /* Traiter le cas "abbr" pour les noms de mois */
492
+        $param = ((isset($options['param']) && $options['param'] === 'abbr') ? '_' . $options['param'] : '');
493
+        $nommois = _T('date_mois_' . $mois . $param);
494
+        $jourmois = $jour
495
+            ? _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois])
496
+            : $nommois;
497
+    } else {
498
+        $nommois = '';
499
+        $jourmois = '';
500
+    }
501
+
502
+    if ($annee < 0) {
503
+        $annee = -$annee . ' ' . _T('date_avant_jc');
504
+        $avjc = true;
505
+    } else {
506
+        $avjc = false;
507
+    }
508
+
509
+    switch ($vue) {
510
+        case 'saison':
511
+        case 'saison_annee':
512
+            $saison = '';
513
+            if ($mois > 0) {
514
+                $saison = ($options['param'] == 'sud') ? 3 : 1;
515
+                if ($mois == 3 && $jour >= 21 || $mois > 3) {
516
+                    $saison = ($options['param'] == 'sud') ? 4 : 2;
517
+                }
518
+                if ($mois == 6 && $jour >= 21 || $mois > 6) {
519
+                    $saison = ($options['param'] == 'sud') ? 1 : 3;
520
+                }
521
+                if ($mois == 9 && $jour >= 21 || $mois > 9) {
522
+                    $saison = ($options['param'] == 'sud') ? 2 : 4;
523
+                }
524
+                if ($mois == 12 && $jour >= 21 || $mois > 12) {
525
+                    $saison = ($options['param'] == 'sud') ? 3 : 1;
526
+                }
527
+            }
528
+            if ($vue == 'saison') {
529
+                return $saison ? _T('date_saison_' . $saison) : '';
530
+            } else {
531
+                return $saison ? trim((string) _T(
532
+                    'date_fmt_saison_annee',
533
+                    ['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
534
+                )) : '';
535
+            }
536
+
537
+        case 'court':
538
+            if ($avjc) {
539
+                return $annee;
540
+            }
541
+            $a = ((isset($options['annee_courante']) && $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
542
+            if ($annee < ($a - 100) || $annee > ($a + 100)) {
543
+                return $annee;
544
+            }
545
+            if ($annee != $a) {
546
+                return _T(
547
+                    'date_fmt_mois_annee',
548
+                    ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee]
549
+                );
550
+            }
551
+
552
+            return _T(
553
+                'date_fmt_jour_mois',
554
+                ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
555
+            );
556
+
557
+        case 'jourcourt':
558
+            if ($avjc) {
559
+                return $annee;
560
+            }
561
+            $a = ((isset($options['annee_courante']) && $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
562
+            if ($annee < ($a - 100) || $annee > ($a + 100)) {
563
+                return $annee;
564
+            }
565
+            if ($annee != $a) {
566
+                return _T(
567
+                    'date_fmt_jour_mois_annee',
568
+                    ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
569
+                );
570
+            }
571
+
572
+            return _T(
573
+                'date_fmt_jour_mois',
574
+                ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
575
+            );
576
+
577
+        case 'entier':
578
+            if ($avjc) {
579
+                return $annee;
580
+            }
581
+            if ($jour) {
582
+                return _T(
583
+                    'date_fmt_jour_mois_annee',
584
+                    ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
585
+                );
586
+            } elseif ($mois) {
587
+                return trim((string) _T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
588
+            } else {
589
+                return $annee;
590
+            }
591
+
592
+        case 'nom_mois':
593
+            return $nommois;
594
+
595
+        case 'mois':
596
+            return sprintf('%02s', $mois);
597
+
598
+        case 'jour':
599
+            return $jour;
600
+
601
+        case 'journum':
602
+            return $journum;
603
+
604
+        case 'nom_jour':
605
+            if (!$mois || !$njour) {
606
+                return '';
607
+            }
608
+            $nom = mktime(1, 1, 1, $mois, $njour, $annee);
609
+            $nom = 1 + (int) date('w', $nom);
610
+            $param = ((isset($options['param']) && $options['param']) ? '_' . $options['param'] : '');
611
+
612
+            return _T('date_jour_' . $nom . $param);
613
+
614
+        case 'mois_annee':
615
+            if ($avjc) {
616
+                return $annee;
617
+            }
618
+
619
+            return trim((string) _T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
620
+
621
+        case 'annee':
622
+            return $annee;
623
+
624
+        // Cas d'une vue non definie : retomber sur le format
625
+        // de date propose par http://www.php.net/date
626
+        default:
627
+            [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
628
+            // il faut envoyer jour = 1 si jour pas défini, c'est le comportement qu'on avait historiquement en envoyant ''
629
+            if (!$time = mktime($heures, $minutes, $secondes, $mois, is_numeric($jour) ? $jour : 1, $annee)) {
630
+                $time = strtotime($numdate);
631
+            }
632
+            return date($vue, $time);
633
+    }
634 634
 }
635 635
 
636 636
 
@@ -657,11 +657,11 @@  discard block
 block discarded – undo
657 657
  *     Nom du jour
658 658
  **/
659 659
 function nom_jour($numdate, $forme = ''): string {
660
-	if ($forme !== 'abbr' && $forme !== 'initiale') {
661
-		$forme = '';
662
-	}
660
+    if ($forme !== 'abbr' && $forme !== 'initiale') {
661
+        $forme = '';
662
+    }
663 663
 
664
-	return affdate_base($numdate, 'nom_jour', ['param' => $forme]);
664
+    return affdate_base($numdate, 'nom_jour', ['param' => $forme]);
665 665
 }
666 666
 
667 667
 /**
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
  *     Numéro du jour
684 684
  **/
685 685
 function jour($numdate): string {
686
-	return affdate_base($numdate, 'jour');
686
+    return affdate_base($numdate, 'jour');
687 687
 }
688 688
 
689 689
 /**
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
  *     Numéro du jour
702 702
  **/
703 703
 function journum($numdate): string {
704
-	return affdate_base($numdate, 'journum');
704
+    return affdate_base($numdate, 'journum');
705 705
 }
706 706
 
707 707
 /**
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
  *     Numéro du mois (sur 2 chiffres)
720 720
  **/
721 721
 function mois($numdate): string {
722
-	return  affdate_base($numdate, 'mois');
722
+    return  affdate_base($numdate, 'mois');
723 723
 }
724 724
 
725 725
 /**
@@ -743,11 +743,11 @@  discard block
 block discarded – undo
743 743
  *     Nom du mois
744 744
  **/
745 745
 function nom_mois($numdate, $forme = ''): string {
746
-	if ($forme !== 'abbr') {
747
-		$forme = '';
748
-	}
746
+    if ($forme !== 'abbr') {
747
+        $forme = '';
748
+    }
749 749
 
750
-	return affdate_base($numdate, 'nom_mois', ['param' => $forme]);
750
+    return affdate_base($numdate, 'nom_mois', ['param' => $forme]);
751 751
 }
752 752
 
753 753
 /**
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
  *     Année (sur 4 chiffres)
766 766
  **/
767 767
 function annee($numdate): string {
768
-	return affdate_base($numdate, 'annee');
768
+    return affdate_base($numdate, 'annee');
769 769
 }
770 770
 
771 771
 
@@ -795,11 +795,11 @@  discard block
 block discarded – undo
795 795
  *     La date formatée
796 796
  **/
797 797
 function saison($numdate, $hemisphere = 'nord'): string {
798
-	if ($hemisphere !== 'sud') {
799
-		$hemisphere = 'nord';
800
-	}
798
+    if ($hemisphere !== 'sud') {
799
+        $hemisphere = 'nord';
800
+    }
801 801
 
802
-	return affdate_base($numdate, 'saison', ['param' => $hemisphere]);
802
+    return affdate_base($numdate, 'saison', ['param' => $hemisphere]);
803 803
 }
804 804
 
805 805
 
@@ -828,11 +828,11 @@  discard block
 block discarded – undo
828 828
  *     La date formatée
829 829
  **/
830 830
 function saison_annee($numdate, $hemisphere = 'nord'): string {
831
-	if ($hemisphere !== 'sud') {
832
-		$hemisphere = 'nord';
833
-	}
831
+    if ($hemisphere !== 'sud') {
832
+        $hemisphere = 'nord';
833
+    }
834 834
 
835
-	return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]);
835
+    return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]);
836 836
 }
837 837
 
838 838
 /**
@@ -860,7 +860,7 @@  discard block
 block discarded – undo
860 860
  *     La date formatée
861 861
  **/
862 862
 function affdate($numdate, $format = 'entier'): string {
863
-	return affdate_base($numdate, $format);
863
+    return affdate_base($numdate, $format);
864 864
 }
865 865
 
866 866
 
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
  *     La date formatée
888 888
  **/
889 889
 function affdate_court($numdate, $annee_courante = null): string {
890
-	return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]);
890
+    return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]);
891 891
 }
892 892
 
893 893
 
@@ -914,7 +914,7 @@  discard block
 block discarded – undo
914 914
  *     La date formatée
915 915
  **/
916 916
 function affdate_jourcourt($numdate, $annee_courante = null): string {
917
-	return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]);
917
+    return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]);
918 918
 }
919 919
 
920 920
 /**
@@ -932,7 +932,7 @@  discard block
 block discarded – undo
932 932
  *     La date formatée
933 933
  **/
934 934
 function affdate_mois_annee($numdate): string {
935
-	return affdate_base($numdate, 'mois_annee');
935
+    return affdate_base($numdate, 'mois_annee');
936 936
 }
937 937
 
938 938
 /**
@@ -950,16 +950,16 @@  discard block
 block discarded – undo
950 950
  *     La date formatée, sinon ''
951 951
  **/
952 952
 function affdate_heure($numdate): string {
953
-	$date_array = recup_date($numdate);
954
-	if (!$date_array) {
955
-		return '';
956
-	}
957
-	[$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array;
958
-
959
-	return _T('date_fmt_jour_heure', [
960
-		'jour' => affdate($numdate),
961
-		'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes])
962
-	]);
953
+    $date_array = recup_date($numdate);
954
+    if (!$date_array) {
955
+        return '';
956
+    }
957
+    [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array;
958
+
959
+    return _T('date_fmt_jour_heure', [
960
+        'jour' => affdate($numdate),
961
+        'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes])
962
+    ]);
963 963
 }
964 964
 
965 965
 /**
@@ -991,113 +991,113 @@  discard block
 block discarded – undo
991 991
  *     texte de la date
992 992
  */
993 993
 function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = ''): string {
994
-	$abbr = $jour = '';
995
-	$affdate = 'affdate_jourcourt';
996
-	if (str_contains($forme, 'abbr')) {
997
-		$abbr = 'abbr';
998
-	}
999
-	if (str_contains($forme, 'annee')) {
1000
-		$affdate = 'affdate';
1001
-	}
1002
-	if (str_contains($forme, 'jour')) {
1003
-		$jour = 'jour';
1004
-	}
1005
-
1006
-	$dtstart = $dtend = $dtabbr = '';
1007
-	if (str_contains($forme, 'hcal')) {
1008
-		$dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1009
-		$dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1010
-		$dtabbr = '</abbr>';
1011
-	}
1012
-
1013
-	$date_debut = strtotime($date_debut);
1014
-	$date_fin = strtotime($date_fin);
1015
-	$d = date('Y-m-d', $date_debut);
1016
-	$f = date('Y-m-d', $date_fin);
1017
-	$h = ($horaire === 'oui' || $horaire === true);
1018
-	$hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]);
1019
-	$hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]);
1020
-
1021
-	if ($d === $f) { // meme jour
1022
-		$nomjour = nom_jour($d, $abbr);
1023
-		$s = $affdate($d);
1024
-		$s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]);
1025
-		if ($h) {
1026
-			if ($hd === $hf) {
1027
-				// Lundi 20 fevrier a 18h25
1028
-				$s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd]));
1029
-				$s = "$dtstart$s$dtabbr";
1030
-			} else {
1031
-				// Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1032
-				if ($dtabbr && $dtstart && $dtend) {
1033
-					$s = _T(
1034
-						'date_fmt_jour_heure_debut_fin_abbr',
1035
-						[
1036
-						'jour' => spip_ucfirst($s),
1037
-						'heure_debut' => $hd,
1038
-						'heure_fin' => $hf,
1039
-						'dtstart' => $dtstart,
1040
-						'dtend' => $dtend,
1041
-						'dtabbr' => $dtabbr
1042
-						],
1043
-						[
1044
-							'sanitize' => false
1045
-						]
1046
-					);
1047
-				} // Le lundi 20 fevrier de 18h00 a 20h00
1048
-				else {
1049
-					$s = spip_ucfirst(_T(
1050
-						'date_fmt_jour_heure_debut_fin',
1051
-						['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf]
1052
-					));
1053
-				}
1054
-			}
1055
-		} else {
1056
-			$s = $dtabbr && $dtstart
1057
-				? $dtstart . spip_ucfirst($s) . $dtabbr
1058
-				: spip_ucfirst($s);
1059
-		}
1060
-	} else {
1061
-		if (date('Y-m', $date_debut) === date('Y-m', $date_fin)) { // meme annee et mois, jours differents
1062
-			$date_debut = $h
1063
-				? affdate_jourcourt($d, date('Y', $date_fin))
1064
-				: jour($d);
1065
-			$date_fin = $affdate($f);
1066
-			if ($jour) {
1067
-				$nomjour_debut = nom_jour($d, $abbr);
1068
-				$date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1069
-				$nomjour_fin = nom_jour($f, $abbr);
1070
-				$date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1071
-			}
1072
-			if ($h) {
1073
-				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1074
-				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1075
-			}
1076
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1077
-			$date_fin = $dtend . $date_fin . $dtabbr;
1078
-
1079
-			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1080
-		} else {
1081
-			$date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1082
-			$date_fin = $affdate($f);
1083
-			if ($jour) {
1084
-				$nomjour_debut = nom_jour($d, $abbr);
1085
-				$date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1086
-				$nomjour_fin = nom_jour($f, $abbr);
1087
-				$date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1088
-			}
1089
-			if ($h) {
1090
-				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1091
-				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1092
-			}
1093
-
1094
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1095
-			$date_fin = $dtend . $date_fin . $dtabbr;
1096
-			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1097
-		}
1098
-	}
1099
-
1100
-	return $s;
994
+    $abbr = $jour = '';
995
+    $affdate = 'affdate_jourcourt';
996
+    if (str_contains($forme, 'abbr')) {
997
+        $abbr = 'abbr';
998
+    }
999
+    if (str_contains($forme, 'annee')) {
1000
+        $affdate = 'affdate';
1001
+    }
1002
+    if (str_contains($forme, 'jour')) {
1003
+        $jour = 'jour';
1004
+    }
1005
+
1006
+    $dtstart = $dtend = $dtabbr = '';
1007
+    if (str_contains($forme, 'hcal')) {
1008
+        $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1009
+        $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1010
+        $dtabbr = '</abbr>';
1011
+    }
1012
+
1013
+    $date_debut = strtotime($date_debut);
1014
+    $date_fin = strtotime($date_fin);
1015
+    $d = date('Y-m-d', $date_debut);
1016
+    $f = date('Y-m-d', $date_fin);
1017
+    $h = ($horaire === 'oui' || $horaire === true);
1018
+    $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]);
1019
+    $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]);
1020
+
1021
+    if ($d === $f) { // meme jour
1022
+        $nomjour = nom_jour($d, $abbr);
1023
+        $s = $affdate($d);
1024
+        $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]);
1025
+        if ($h) {
1026
+            if ($hd === $hf) {
1027
+                // Lundi 20 fevrier a 18h25
1028
+                $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd]));
1029
+                $s = "$dtstart$s$dtabbr";
1030
+            } else {
1031
+                // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1032
+                if ($dtabbr && $dtstart && $dtend) {
1033
+                    $s = _T(
1034
+                        'date_fmt_jour_heure_debut_fin_abbr',
1035
+                        [
1036
+                        'jour' => spip_ucfirst($s),
1037
+                        'heure_debut' => $hd,
1038
+                        'heure_fin' => $hf,
1039
+                        'dtstart' => $dtstart,
1040
+                        'dtend' => $dtend,
1041
+                        'dtabbr' => $dtabbr
1042
+                        ],
1043
+                        [
1044
+                            'sanitize' => false
1045
+                        ]
1046
+                    );
1047
+                } // Le lundi 20 fevrier de 18h00 a 20h00
1048
+                else {
1049
+                    $s = spip_ucfirst(_T(
1050
+                        'date_fmt_jour_heure_debut_fin',
1051
+                        ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf]
1052
+                    ));
1053
+                }
1054
+            }
1055
+        } else {
1056
+            $s = $dtabbr && $dtstart
1057
+                ? $dtstart . spip_ucfirst($s) . $dtabbr
1058
+                : spip_ucfirst($s);
1059
+        }
1060
+    } else {
1061
+        if (date('Y-m', $date_debut) === date('Y-m', $date_fin)) { // meme annee et mois, jours differents
1062
+            $date_debut = $h
1063
+                ? affdate_jourcourt($d, date('Y', $date_fin))
1064
+                : jour($d);
1065
+            $date_fin = $affdate($f);
1066
+            if ($jour) {
1067
+                $nomjour_debut = nom_jour($d, $abbr);
1068
+                $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1069
+                $nomjour_fin = nom_jour($f, $abbr);
1070
+                $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1071
+            }
1072
+            if ($h) {
1073
+                $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1074
+                $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1075
+            }
1076
+            $date_debut = $dtstart . $date_debut . $dtabbr;
1077
+            $date_fin = $dtend . $date_fin . $dtabbr;
1078
+
1079
+            $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1080
+        } else {
1081
+            $date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1082
+            $date_fin = $affdate($f);
1083
+            if ($jour) {
1084
+                $nomjour_debut = nom_jour($d, $abbr);
1085
+                $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1086
+                $nomjour_fin = nom_jour($f, $abbr);
1087
+                $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1088
+            }
1089
+            if ($h) {
1090
+                $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1091
+                $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1092
+            }
1093
+
1094
+            $date_debut = $dtstart . $date_debut . $dtabbr;
1095
+            $date_fin = $dtend . $date_fin . $dtabbr;
1096
+            $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1097
+        }
1098
+    }
1099
+
1100
+    return $s;
1101 1101
 }
1102 1102
 
1103 1103
 /**
@@ -1118,10 +1118,10 @@  discard block
 block discarded – undo
1118 1118
  *     Date au format ical
1119 1119
  **/
1120 1120
 function date_ical($date, $addminutes = 0): string {
1121
-	[$heures, $minutes, $secondes] = recup_heure($date);
1122
-	[$annee, $mois, $jour] = recup_date($date);
1121
+    [$heures, $minutes, $secondes] = recup_heure($date);
1122
+    [$annee, $mois, $jour] = recup_date($date);
1123 1123
 
1124
-	return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1124
+    return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1125 1125
 }
1126 1126
 
1127 1127
 
@@ -1145,14 +1145,14 @@  discard block
 block discarded – undo
1145 1145
  *     La date formatée
1146 1146
  **/
1147 1147
 function date_iso($date_heure): string {
1148
-	$date = recup_date($date_heure);
1149
-	$annee = $date[0] ?? null;
1150
-	$mois = $date[1] ?? null;
1151
-	$jour = $date[2] ?? null;
1152
-	[$heures, $minutes, $secondes] = recup_heure($date_heure);
1153
-	$time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1154
-
1155
-	return gmdate('Y-m-d\TH:i:s\Z', $time);
1148
+    $date = recup_date($date_heure);
1149
+    $annee = $date[0] ?? null;
1150
+    $mois = $date[1] ?? null;
1151
+    $jour = $date[2] ?? null;
1152
+    [$heures, $minutes, $secondes] = recup_heure($date_heure);
1153
+    $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1154
+
1155
+    return gmdate('Y-m-d\TH:i:s\Z', $time);
1156 1156
 }
1157 1157
 
1158 1158
 /**
@@ -1175,11 +1175,11 @@  discard block
 block discarded – undo
1175 1175
  *     La date formatée
1176 1176
  **/
1177 1177
 function date_822($date_heure): string {
1178
-	[$annee, $mois, $jour] = recup_date($date_heure);
1179
-	[$heures, $minutes, $secondes] = recup_heure($date_heure);
1180
-	$time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1178
+    [$annee, $mois, $jour] = recup_date($date_heure);
1179
+    [$heures, $minutes, $secondes] = recup_heure($date_heure);
1180
+    $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1181 1181
 
1182
-	return date('r', $time);
1182
+    return date('r', $time);
1183 1183
 }
1184 1184
 
1185 1185
 /**
@@ -1195,11 +1195,11 @@  discard block
 block discarded – undo
1195 1195
  *     Date au format `Ymd`
1196 1196
  **/
1197 1197
 function date_anneemoisjour($d): string {
1198
-	if (!$d) {
1199
-		$d = date('Y-m-d');
1200
-	}
1198
+    if (!$d) {
1199
+        $d = date('Y-m-d');
1200
+    }
1201 1201
 
1202
-	return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1202
+    return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1203 1203
 }
1204 1204
 
1205 1205
 /**
@@ -1215,11 +1215,11 @@  discard block
 block discarded – undo
1215 1215
  *     Date au format `Ym`
1216 1216
  **/
1217 1217
 function date_anneemois($d): string {
1218
-	if (!$d) {
1219
-		$d = date('Y-m-d');
1220
-	}
1218
+    if (!$d) {
1219
+        $d = date('Y-m-d');
1220
+    }
1221 1221
 
1222
-	return substr($d, 0, 4) . substr($d, 5, 2);
1222
+    return substr($d, 0, 4) . substr($d, 5, 2);
1223 1223
 }
1224 1224
 
1225 1225
 /**
@@ -1235,13 +1235,13 @@  discard block
 block discarded – undo
1235 1235
  *     Date au lundi de la même semaine au format `Ymd`
1236 1236
  **/
1237 1237
 function date_debut_semaine($annee, $mois, $jour): string {
1238
-	$w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1239
-	if ($w_day == 0) {
1240
-		$w_day = 7;
1241
-	} // Gaffe: le dimanche est zero
1242
-	$debut = $jour - $w_day + 1;
1238
+    $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1239
+    if ($w_day == 0) {
1240
+        $w_day = 7;
1241
+    } // Gaffe: le dimanche est zero
1242
+    $debut = $jour - $w_day + 1;
1243 1243
 
1244
-	return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee));
1244
+    return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee));
1245 1245
 }
1246 1246
 
1247 1247
 /**
@@ -1257,11 +1257,11 @@  discard block
 block discarded – undo
1257 1257
  *     Date au dimanche de la même semaine au format `Ymd`
1258 1258
  **/
1259 1259
 function date_fin_semaine($annee, $mois, $jour): string {
1260
-	$w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1261
-	if ($w_day == 0) {
1262
-		$w_day = 7;
1263
-	} // Gaffe: le dimanche est zero
1264
-	$debut = $jour - $w_day + 1;
1260
+    $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1261
+    if ($w_day == 0) {
1262
+        $w_day = 7;
1263
+    } // Gaffe: le dimanche est zero
1264
+    $debut = $jour - $w_day + 1;
1265 1265
 
1266
-	return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee));
1266
+    return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee));
1267 1267
 }
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
 		}
44 44
 		if (preg_match('#^([12]\d{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
45 45
 			$regs = array_pad($regs, 4, null); // eviter notice php
46
-			$date = $regs[1] . '-00-00' . $regs[3];
46
+			$date = $regs[1].'-00-00'.$regs[3];
47 47
 		} else {
48 48
 			if (preg_match('#^([12]\d{3}[-/][01]?\d)([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
49 49
 				$regs = array_pad($regs, 4, null); // eviter notice php
50
-				$date = preg_replace('@/@', '-', (string) $regs[1]) . '-00' . $regs[3];
50
+				$date = preg_replace('@/@', '-', (string) $regs[1]).'-00'.$regs[3];
51 51
 			} else {
52 52
 				$date = date('Y-m-d H:i:s', strtotime($date));
53 53
 			}
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	$letexte ??= '';
75 75
 	if (
76 76
 		!$verif_format_date
77
-		|| in_array(strlen($letexte), [10,19]) && preg_match('/^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}:\d{2})?$/', $letexte)
77
+		|| in_array(strlen($letexte), [10, 19]) && preg_match('/^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}:\d{2})?$/', $letexte)
78 78
 	) {
79 79
 		if (strncmp('0000-00-00', $letexte, 10) == 0) {
80 80
 			return '';
@@ -359,39 +359,39 @@  discard block
 block discarded – undo
359 359
 	if ($decal > 3600 * 24 * 30) {
360 360
 		$mois = floor($decal / (3600 * 24 * 30));
361 361
 		$delai = $mois < 2
362
-			? "$mois " . _T('date_un_mois')
363
-			: "$mois " . _T('date_mois');
362
+			? "$mois "._T('date_un_mois')
363
+			: "$mois "._T('date_mois');
364 364
 	} else {
365 365
 		if ($decal > 3600 * 24 * 7) {
366 366
 			$semaines = floor($decal / (3600 * 24 * 7));
367 367
 			$delai = $semaines < 2
368
-				? "$semaines " . _T('date_une_semaine')
369
-				: "$semaines " . _T('date_semaines');
368
+				? "$semaines "._T('date_une_semaine')
369
+				: "$semaines "._T('date_semaines');
370 370
 		} else {
371 371
 			if ($decal > 3600 * 24) {
372 372
 				$jours = floor($decal / (3600 * 24));
373 373
 				if ($jours < 2) {
374 374
 					return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
375 375
 				} else {
376
-					$delai = "$jours " . _T('date_jours');
376
+					$delai = "$jours "._T('date_jours');
377 377
 				}
378 378
 			} else {
379 379
 				if ($decal >= 3600) {
380 380
 					$heures = floor($decal / 3600);
381 381
 					$delai = $heures < 2
382
-						? "$heures " . _T('date_une_heure')
383
-						: "$heures " . _T('date_heures');
382
+						? "$heures "._T('date_une_heure')
383
+						: "$heures "._T('date_heures');
384 384
 				} else {
385 385
 					if ($decal >= 60) {
386 386
 						$minutes = floor($decal / 60);
387 387
 						$delai = $minutes < 2
388
-							? "$minutes " . _T('date_une_minute')
389
-							: "$minutes " . _T('date_minutes');
388
+							? "$minutes "._T('date_une_minute')
389
+							: "$minutes "._T('date_minutes');
390 390
 					} else {
391 391
 						$secondes = ceil($decal);
392 392
 						$delai = $secondes < 2
393
-							? "$secondes " . _T('date_une_seconde')
394
-							: "$secondes " . _T('date_secondes');
393
+							? "$secondes "._T('date_une_seconde')
394
+							: "$secondes "._T('date_secondes');
395 395
 					}
396 396
 				}
397 397
 			}
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 		$njour = 0;
482 482
 	} else {
483 483
 		$njour = (int) $jour;
484
-		if ($jourth = _T('date_jnum' . $jour)) {
484
+		if ($jourth = _T('date_jnum'.$jour)) {
485 485
 			$jour = $jourth;
486 486
 		}
487 487
 	}
@@ -489,10 +489,10 @@  discard block
 block discarded – undo
489 489
 	$mois = (int) $mois;
490 490
 	if ($mois > 0 && $mois < 13) {
491 491
 		/* Traiter le cas "abbr" pour les noms de mois */
492
-		$param = ((isset($options['param']) && $options['param'] === 'abbr') ? '_' . $options['param'] : '');
493
-		$nommois = _T('date_mois_' . $mois . $param);
492
+		$param = ((isset($options['param']) && $options['param'] === 'abbr') ? '_'.$options['param'] : '');
493
+		$nommois = _T('date_mois_'.$mois.$param);
494 494
 		$jourmois = $jour
495
-			? _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois])
495
+			? _T('date_de_mois_'.$mois, ['j' => $jour, 'nommois' => $nommois])
496 496
 			: $nommois;
497 497
 	} else {
498 498
 		$nommois = '';
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 	}
501 501
 
502 502
 	if ($annee < 0) {
503
-		$annee = -$annee . ' ' . _T('date_avant_jc');
503
+		$annee = -$annee.' '._T('date_avant_jc');
504 504
 		$avjc = true;
505 505
 	} else {
506 506
 		$avjc = false;
@@ -526,11 +526,11 @@  discard block
 block discarded – undo
526 526
 				}
527 527
 			}
528 528
 			if ($vue == 'saison') {
529
-				return $saison ? _T('date_saison_' . $saison) : '';
529
+				return $saison ? _T('date_saison_'.$saison) : '';
530 530
 			} else {
531 531
 				return $saison ? trim((string) _T(
532 532
 					'date_fmt_saison_annee',
533
-					['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
533
+					['saison' => _T('date_saison_'.$saison), 'annee' => $annee]
534 534
 				)) : '';
535 535
 			}
536 536
 
@@ -607,9 +607,9 @@  discard block
 block discarded – undo
607 607
 			}
608 608
 			$nom = mktime(1, 1, 1, $mois, $njour, $annee);
609 609
 			$nom = 1 + (int) date('w', $nom);
610
-			$param = ((isset($options['param']) && $options['param']) ? '_' . $options['param'] : '');
610
+			$param = ((isset($options['param']) && $options['param']) ? '_'.$options['param'] : '');
611 611
 
612
-			return _T('date_jour_' . $nom . $param);
612
+			return _T('date_jour_'.$nom.$param);
613 613
 
614 614
 		case 'mois_annee':
615 615
 			if ($avjc) {
@@ -1005,8 +1005,8 @@  discard block
 block discarded – undo
1005 1005
 
1006 1006
 	$dtstart = $dtend = $dtabbr = '';
1007 1007
 	if (str_contains($forme, 'hcal')) {
1008
-		$dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1009
-		$dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1008
+		$dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>";
1009
+		$dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>";
1010 1010
 		$dtabbr = '</abbr>';
1011 1011
 	}
1012 1012
 
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
 			}
1055 1055
 		} else {
1056 1056
 			$s = $dtabbr && $dtstart
1057
-				? $dtstart . spip_ucfirst($s) . $dtabbr
1057
+				? $dtstart.spip_ucfirst($s).$dtabbr
1058 1058
 				: spip_ucfirst($s);
1059 1059
 		}
1060 1060
 	} else {
@@ -1073,8 +1073,8 @@  discard block
 block discarded – undo
1073 1073
 				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1074 1074
 				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1075 1075
 			}
1076
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1077
-			$date_fin = $dtend . $date_fin . $dtabbr;
1076
+			$date_debut = $dtstart.$date_debut.$dtabbr;
1077
+			$date_fin = $dtend.$date_fin.$dtabbr;
1078 1078
 
1079 1079
 			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1080 1080
 		} else {
@@ -1091,8 +1091,8 @@  discard block
 block discarded – undo
1091 1091
 				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1092 1092
 			}
1093 1093
 
1094
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1095
-			$date_fin = $dtend . $date_fin . $dtabbr;
1094
+			$date_debut = $dtstart.$date_debut.$dtabbr;
1095
+			$date_fin = $dtend.$date_fin.$dtabbr;
1096 1096
 			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1097 1097
 		}
1098 1098
 	}
@@ -1199,7 +1199,7 @@  discard block
 block discarded – undo
1199 1199
 		$d = date('Y-m-d');
1200 1200
 	}
1201 1201
 
1202
-	return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1202
+	return substr($d, 0, 4).substr($d, 5, 2).substr($d, 8, 2);
1203 1203
 }
1204 1204
 
1205 1205
 /**
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
 		$d = date('Y-m-d');
1220 1220
 	}
1221 1221
 
1222
-	return substr($d, 0, 4) . substr($d, 5, 2);
1222
+	return substr($d, 0, 4).substr($d, 5, 2);
1223 1223
 }
1224 1224
 
1225 1225
 /**
Please login to merge, or discard this patch.
ecrire/inc/chercher_logo.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Logos
16 16
  **/
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 /**
@@ -34,23 +34,23 @@  discard block
 block discarded – undo
34 34
  **/
35 35
 function inc_chercher_logo_dist(int $id, string $_id_objet, string $mode = 'on', bool $compat_old_logos = false): array {
36 36
 
37
-	$mode = preg_replace(',\W,', '', $mode);
38
-	if ($mode) {
39
-		// chercher dans la base
40
-		$mode_document = 'logo' . $mode;
41
-		$objet = objet_type($_id_objet);
42
-		$doc = sql_fetsel(
43
-			'D.*',
44
-			'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document',
45
-			'D.mode=' . sql_quote($mode_document) . ' AND L.objet=' . sql_quote($objet) . ' AND id_objet=' . $id
46
-		);
47
-		if ($doc) {
48
-			include_spip('inc/documents');
49
-			$d = get_spip_doc($doc['fichier']);
50
-			return [$d, _DIR_IMG, basename($d), $doc['extension'], @filemtime($d), $doc];
51
-		}
52
-	}
37
+    $mode = preg_replace(',\W,', '', $mode);
38
+    if ($mode) {
39
+        // chercher dans la base
40
+        $mode_document = 'logo' . $mode;
41
+        $objet = objet_type($_id_objet);
42
+        $doc = sql_fetsel(
43
+            'D.*',
44
+            'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document',
45
+            'D.mode=' . sql_quote($mode_document) . ' AND L.objet=' . sql_quote($objet) . ' AND id_objet=' . $id
46
+        );
47
+        if ($doc) {
48
+            include_spip('inc/documents');
49
+            $d = get_spip_doc($doc['fichier']);
50
+            return [$d, _DIR_IMG, basename($d), $doc['extension'], @filemtime($d), $doc];
51
+        }
52
+    }
53 53
 
54
-	# coherence de type pour servir comme filtre (formulaire_login)
55
-	return [];
54
+    # coherence de type pour servir comme filtre (formulaire_login)
55
+    return [];
56 56
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,12 +37,12 @@
 block discarded – undo
37 37
 	$mode = preg_replace(',\W,', '', $mode);
38 38
 	if ($mode) {
39 39
 		// chercher dans la base
40
-		$mode_document = 'logo' . $mode;
40
+		$mode_document = 'logo'.$mode;
41 41
 		$objet = objet_type($_id_objet);
42 42
 		$doc = sql_fetsel(
43 43
 			'D.*',
44 44
 			'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document',
45
-			'D.mode=' . sql_quote($mode_document) . ' AND L.objet=' . sql_quote($objet) . ' AND id_objet=' . $id
45
+			'D.mode='.sql_quote($mode_document).' AND L.objet='.sql_quote($objet).' AND id_objet='.$id
46 46
 		);
47 47
 		if ($doc) {
48 48
 			include_spip('inc/documents');
Please login to merge, or discard this patch.
prive/squelettes/contenu/job_queue_fonctions.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,24 +1,24 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (!defined('_ECRIRE_INC_VERSION')) {
4
-	return;
4
+    return;
5 5
 }
6 6
 
7 7
 function job_queue_block_and_watch() {
8
-	// bloquer la queue sur ce hit
9
-	// pour avoir coherence entre l'affichage de la liste de jobs
10
-	// et les jobs en base en fin de hit
11
-	define('_DEBUG_BLOCK_QUEUE', true);
12
-	include_spip('inc/genie');
13
-	genie_queue_watch_dist();
8
+    // bloquer la queue sur ce hit
9
+    // pour avoir coherence entre l'affichage de la liste de jobs
10
+    // et les jobs en base en fin de hit
11
+    define('_DEBUG_BLOCK_QUEUE', true);
12
+    include_spip('inc/genie');
13
+    genie_queue_watch_dist();
14 14
 }
15 15
 
16 16
 /**
17 17
  * Prévisu d'un appel à une fonction avec ses arguments
18 18
  */
19 19
 function job_queue_display_call(string $function, string $args): string {
20
-	$args = unserialize($args);
21
-	$args = array_map(fn ($arg) => is_scalar($arg) ? $arg : get_debug_type($arg), $args);
20
+    $args = unserialize($args);
21
+    $args = array_map(fn ($arg) => is_scalar($arg) ? $arg : get_debug_type($arg), $args);
22 22
 
23
-	return sprintf('%s(%s)', $function, implode(', ', $args));
23
+    return sprintf('%s(%s)', $function, implode(', ', $args));
24 24
 }
Please login to merge, or discard this patch.
rector.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -17,16 +17,16 @@
 block discarded – undo
17 17
         __DIR__ . '/index.php',
18 18
     ]);
19 19
 
20
-	$rectorConfig->sets([
21
-		LevelSetList::UP_TO_PHP_81
22
-	]);
20
+    $rectorConfig->sets([
21
+        LevelSetList::UP_TO_PHP_81
22
+    ]);
23 23
 
24 24
     $rectorConfig->skip([
25 25
         __DIR__ . '/ecrire/lang',
26
-		FinalizePublicClassConstantRector::class,
27
-		NullToStrictStringFuncCallArgRector::class,
28
-		CountOnNullRector::class,
29
-		MixedTypeRector::class,
26
+        FinalizePublicClassConstantRector::class,
27
+        NullToStrictStringFuncCallArgRector::class,
28
+        CountOnNullRector::class,
29
+        MixedTypeRector::class,
30 30
     ]);
31 31
 
32 32
 };
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -9,12 +9,12 @@  discard block
 block discarded – undo
9 9
 use Rector\Php71\Rector\FuncCall\CountOnNullRector;
10 10
 use Rector\Php80\Rector\FunctionLike\MixedTypeRector;
11 11
 
12
-return static function (RectorConfig $rectorConfig): void {
12
+return static function(RectorConfig $rectorConfig): void {
13 13
     $rectorConfig->paths([
14
-        __DIR__ . '/ecrire',
15
-        __DIR__ . '/prive',
16
-        __DIR__ . '/spip.php',
17
-        __DIR__ . '/index.php',
14
+        __DIR__.'/ecrire',
15
+        __DIR__.'/prive',
16
+        __DIR__.'/spip.php',
17
+        __DIR__.'/index.php',
18 18
     ]);
19 19
 
20 20
 	$rectorConfig->sets([
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	]);
23 23
 
24 24
     $rectorConfig->skip([
25
-        __DIR__ . '/ecrire/lang',
25
+        __DIR__.'/ecrire/lang',
26 26
 		FinalizePublicClassConstantRector::class,
27 27
 		NullToStrictStringFuncCallArgRector::class,
28 28
 		CountOnNullRector::class,
Please login to merge, or discard this patch.
ecrire/public/styliser_par_z.php 2 patches
Indentation   +305 added lines, -305 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  * @package SPIP\Core\Public\Styliser
19 19
  **/
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 
24 24
 /**
@@ -28,190 +28,190 @@  discard block
 block discarded – undo
28 28
  * @return array Données modifiées du pipeline
29 29
  */
30 30
 function public_styliser_par_z_dist($flux) {
31
-	static $prefix_path = null;
32
-	static $prefix_length;
33
-	static $z_blocs;
34
-	static $apl_constant;
35
-	static $page;
36
-	static $disponible = [];
37
-	static $echafauder;
38
-	static $prepend = '';
39
-
40
-	if (!isset($prefix_path)) {
41
-		$z_blocs = z_blocs(test_espace_prive());
42
-		if (test_espace_prive()) {
43
-			$prefix_path = 'prive/squelettes/';
44
-			$prefix_length = strlen($prefix_path);
45
-			$apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD';
46
-			$page = 'exec';
47
-			$echafauder = charger_fonction('echafauder', 'prive', true);
48
-			define('_ZCORE_EXCLURE_PATH', '');
49
-		} else {
50
-			$prefix_path = '';
51
-			$prefix_length = 0;
52
-			$apl_constant = '_Z_AJAX_PARALLEL_LOAD';
53
-			$page = _SPIP_PAGE;
54
-			$echafauder = charger_fonction('echafauder', 'public', true);
55
-			define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim(
56
-				(string) _DIR_PLUGIN_DIST,
57
-				'/'
58
-			) : ''));
59
-		}
60
-		$prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : '');
61
-	}
62
-	$z_contenu = reset($z_blocs); // contenu par defaut
63
-
64
-	$fond = $flux['args']['fond'];
65
-
66
-	if ($prepend || strncmp((string) $fond, (string) $prefix_path, $prefix_length) == 0) {
67
-		$fond = substr((string) $fond, $prefix_length);
68
-		$squelette = $flux['data'];
69
-		$ext = $flux['args']['ext'];
70
-		// Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax
71
-		if (
72
-			defined('_Z_AJAX_PARALLEL_LOAD_OK')
73
-			&& ($dir = explode('/', $fond))
74
-			&& count($dir) == 2 // pas un sous repertoire
75
-			&& ($dir = reset($dir))
76
-			&& in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z
77
-			&& defined($apl_constant)
78
-			&& in_array($dir, explode(',', (string) constant($apl_constant))) // et dans un demande en APL
79
-			&& ($pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext)) // et qui contient le squelette APL
80
-		) {
81
-			$flux['data'] = $pipe;
82
-
83
-			return $flux;
84
-		}
85
-
86
-		// surcharger aussi les squelettes venant de squelettes-dist/
87
-		if ($squelette && !z_fond_valide($squelette)) {
88
-			$squelette = '';
89
-			$echafauder = '';
90
-		}
91
-		if ($prepend) {
92
-			$squelette = substr((string) find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext"));
93
-			if ($squelette) {
94
-				$flux['data'] = $squelette;
95
-			}
96
-		}
97
-
98
-		// gerer les squelettes non trouves
99
-		// -> router vers les /dist.html
100
-		// ou scaffolding ou page automatique les contenus
101
-		if (!$squelette) {
102
-			// si on est sur un ?page=XX non trouve
103
-			if (
104
-				isset($flux['args']['contexte'][$page]) && $flux['args']['contexte'][$page] == $fond
105
-				|| isset($flux['args']['contexte']['type-page']) && $flux['args']['contexte']['type-page'] == $fond
106
-				|| $fond == 'sommaire' && (!isset($flux['args']['contexte'][$page]) || !$flux['args']['contexte'][$page])
107
-			) {
108
-				// si on est sur un ?page=XX non trouve
109
-				// se brancher sur contenu/xx si il existe
110
-				// ou si c'est un objet spip, associe a une table, utiliser le fond homonyme
111
-				if (!isset($disponible[$fond])) {
112
-					$disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, (bool) $echafauder);
113
-				}
114
-
115
-				if ($disponible[$fond]) {
116
-					$flux['data'] = substr((string) find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext"));
117
-				}
118
-			}
119
-
120
-			// echafaudage :
121
-			// si c'est un fond de contenu d'un objet en base
122
-			// generer un fond automatique a la volee pour les webmestres
123
-			elseif (strncmp($fond, "$z_contenu/", strlen((string) $z_contenu) + 1) == 0) {
124
-				$type = substr($fond, strlen((string) $z_contenu) + 1);
125
-				if ($type == 'page' && isset($flux['args']['contexte'][$page])) {
126
-					$type = $flux['args']['contexte'][$page];
127
-				}
128
-				if (!isset($disponible[$type])) {
129
-					$disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, (bool) $echafauder);
130
-				}
131
-				if (is_string($disponible[$type])) {
132
-					$flux['data'] = $disponible[$type];
133
-				} elseif (
134
-					$echafauder
135
-					&& include_spip('inc/autoriser')
136
-					&& isset($GLOBALS['visiteur_session']['statut'])
137
-					&& autoriser('echafauder', $type)
138
-					&& ($is = $disponible[$type])
139
-					&& is_array($is)
140
-				) {
141
-					$flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext);
142
-				} else {
143
-					$flux['data'] = ($disponible['404'] = z_contenu_disponible(
144
-						$prefix_path . $prepend,
145
-						$z_contenu,
146
-						'404',
147
-						$ext,
148
-						(bool) $echafauder
149
-					));
150
-				}
151
-			}
152
-
153
-			// sinon, si on demande un fond non trouve dans un des autres blocs
154
-			// et si il y a bien un contenu correspondant ou echafaudable
155
-			// se rabbatre sur le dist.html du bloc concerne
156
-			else {
157
-				if (
158
-					($dir = explode('/', $fond))
159
-					&& ($dir = reset($dir))
160
-					&& $dir !== $z_contenu
161
-					&& in_array($dir, $z_blocs)
162
-				) {
163
-					$type = substr($fond, strlen("$dir/"));
164
-					if ($type == 'page' && isset($flux['args']['contexte'][$page])) {
165
-						$type = $flux['args']['contexte'][$page];
166
-					}
167
-					if ($type !== 'page' && !isset($disponible[$type])) {
168
-						$disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, (bool) $echafauder);
169
-					}
170
-					if ($type == 'page' || $disponible[$type]) {
171
-						$flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext);
172
-					}
173
-				}
174
-			}
175
-			$squelette = $flux['data'];
176
-		}
177
-
178
-		// layout specifiques par type et compositions :
179
-		// body-article.html
180
-		// body-sommaire.html
181
-		// pour des raisons de perfo, les declinaisons doivent etre dans le
182
-		// meme dossier que body.html
183
-		$f = null;
184
-		if ($fond == 'body' && str_ends_with((string) $squelette, $fond)) {
185
-			if (
186
-				isset($flux['args']['contexte']['type-page'])
187
-				&& (
188
-					isset($flux['args']['contexte']['composition']) && file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext")
189
-					|| file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext")
190
-				)
191
-			) {
192
-				$flux['data'] = $f;
193
-			}
194
-		} elseif (
195
-			$fond == 'structure'
196
-			&& z_sanitize_var_zajax()
197
-			&& ($f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext"))
198
-		) {
199
-			$flux['data'] = substr((string) $f, 0, -strlen(".$ext"));
200
-		} elseif (
201
-			// chercher le fond correspondant a la composition
202
-			isset($flux['args']['contexte']['composition'])
203
-			&& (basename($fond) == 'page' || $squelette && str_ends_with((string) $squelette, $fond))
204
-			&& ($dir = substr($fond, $prefix_length))
205
-			&& ($dir = explode('/', $dir))
206
-			&& ($dir = reset($dir))
207
-			&& in_array($dir, $z_blocs)
208
-			&& ($f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext"))
209
-		) {
210
-			$flux['data'] = substr((string) $f, 0, -strlen(".$ext"));
211
-		}
212
-	}
213
-
214
-	return $flux;
31
+    static $prefix_path = null;
32
+    static $prefix_length;
33
+    static $z_blocs;
34
+    static $apl_constant;
35
+    static $page;
36
+    static $disponible = [];
37
+    static $echafauder;
38
+    static $prepend = '';
39
+
40
+    if (!isset($prefix_path)) {
41
+        $z_blocs = z_blocs(test_espace_prive());
42
+        if (test_espace_prive()) {
43
+            $prefix_path = 'prive/squelettes/';
44
+            $prefix_length = strlen($prefix_path);
45
+            $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD';
46
+            $page = 'exec';
47
+            $echafauder = charger_fonction('echafauder', 'prive', true);
48
+            define('_ZCORE_EXCLURE_PATH', '');
49
+        } else {
50
+            $prefix_path = '';
51
+            $prefix_length = 0;
52
+            $apl_constant = '_Z_AJAX_PARALLEL_LOAD';
53
+            $page = _SPIP_PAGE;
54
+            $echafauder = charger_fonction('echafauder', 'public', true);
55
+            define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim(
56
+                (string) _DIR_PLUGIN_DIST,
57
+                '/'
58
+            ) : ''));
59
+        }
60
+        $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : '');
61
+    }
62
+    $z_contenu = reset($z_blocs); // contenu par defaut
63
+
64
+    $fond = $flux['args']['fond'];
65
+
66
+    if ($prepend || strncmp((string) $fond, (string) $prefix_path, $prefix_length) == 0) {
67
+        $fond = substr((string) $fond, $prefix_length);
68
+        $squelette = $flux['data'];
69
+        $ext = $flux['args']['ext'];
70
+        // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax
71
+        if (
72
+            defined('_Z_AJAX_PARALLEL_LOAD_OK')
73
+            && ($dir = explode('/', $fond))
74
+            && count($dir) == 2 // pas un sous repertoire
75
+            && ($dir = reset($dir))
76
+            && in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z
77
+            && defined($apl_constant)
78
+            && in_array($dir, explode(',', (string) constant($apl_constant))) // et dans un demande en APL
79
+            && ($pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext)) // et qui contient le squelette APL
80
+        ) {
81
+            $flux['data'] = $pipe;
82
+
83
+            return $flux;
84
+        }
85
+
86
+        // surcharger aussi les squelettes venant de squelettes-dist/
87
+        if ($squelette && !z_fond_valide($squelette)) {
88
+            $squelette = '';
89
+            $echafauder = '';
90
+        }
91
+        if ($prepend) {
92
+            $squelette = substr((string) find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext"));
93
+            if ($squelette) {
94
+                $flux['data'] = $squelette;
95
+            }
96
+        }
97
+
98
+        // gerer les squelettes non trouves
99
+        // -> router vers les /dist.html
100
+        // ou scaffolding ou page automatique les contenus
101
+        if (!$squelette) {
102
+            // si on est sur un ?page=XX non trouve
103
+            if (
104
+                isset($flux['args']['contexte'][$page]) && $flux['args']['contexte'][$page] == $fond
105
+                || isset($flux['args']['contexte']['type-page']) && $flux['args']['contexte']['type-page'] == $fond
106
+                || $fond == 'sommaire' && (!isset($flux['args']['contexte'][$page]) || !$flux['args']['contexte'][$page])
107
+            ) {
108
+                // si on est sur un ?page=XX non trouve
109
+                // se brancher sur contenu/xx si il existe
110
+                // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme
111
+                if (!isset($disponible[$fond])) {
112
+                    $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, (bool) $echafauder);
113
+                }
114
+
115
+                if ($disponible[$fond]) {
116
+                    $flux['data'] = substr((string) find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext"));
117
+                }
118
+            }
119
+
120
+            // echafaudage :
121
+            // si c'est un fond de contenu d'un objet en base
122
+            // generer un fond automatique a la volee pour les webmestres
123
+            elseif (strncmp($fond, "$z_contenu/", strlen((string) $z_contenu) + 1) == 0) {
124
+                $type = substr($fond, strlen((string) $z_contenu) + 1);
125
+                if ($type == 'page' && isset($flux['args']['contexte'][$page])) {
126
+                    $type = $flux['args']['contexte'][$page];
127
+                }
128
+                if (!isset($disponible[$type])) {
129
+                    $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, (bool) $echafauder);
130
+                }
131
+                if (is_string($disponible[$type])) {
132
+                    $flux['data'] = $disponible[$type];
133
+                } elseif (
134
+                    $echafauder
135
+                    && include_spip('inc/autoriser')
136
+                    && isset($GLOBALS['visiteur_session']['statut'])
137
+                    && autoriser('echafauder', $type)
138
+                    && ($is = $disponible[$type])
139
+                    && is_array($is)
140
+                ) {
141
+                    $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext);
142
+                } else {
143
+                    $flux['data'] = ($disponible['404'] = z_contenu_disponible(
144
+                        $prefix_path . $prepend,
145
+                        $z_contenu,
146
+                        '404',
147
+                        $ext,
148
+                        (bool) $echafauder
149
+                    ));
150
+                }
151
+            }
152
+
153
+            // sinon, si on demande un fond non trouve dans un des autres blocs
154
+            // et si il y a bien un contenu correspondant ou echafaudable
155
+            // se rabbatre sur le dist.html du bloc concerne
156
+            else {
157
+                if (
158
+                    ($dir = explode('/', $fond))
159
+                    && ($dir = reset($dir))
160
+                    && $dir !== $z_contenu
161
+                    && in_array($dir, $z_blocs)
162
+                ) {
163
+                    $type = substr($fond, strlen("$dir/"));
164
+                    if ($type == 'page' && isset($flux['args']['contexte'][$page])) {
165
+                        $type = $flux['args']['contexte'][$page];
166
+                    }
167
+                    if ($type !== 'page' && !isset($disponible[$type])) {
168
+                        $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, (bool) $echafauder);
169
+                    }
170
+                    if ($type == 'page' || $disponible[$type]) {
171
+                        $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext);
172
+                    }
173
+                }
174
+            }
175
+            $squelette = $flux['data'];
176
+        }
177
+
178
+        // layout specifiques par type et compositions :
179
+        // body-article.html
180
+        // body-sommaire.html
181
+        // pour des raisons de perfo, les declinaisons doivent etre dans le
182
+        // meme dossier que body.html
183
+        $f = null;
184
+        if ($fond == 'body' && str_ends_with((string) $squelette, $fond)) {
185
+            if (
186
+                isset($flux['args']['contexte']['type-page'])
187
+                && (
188
+                    isset($flux['args']['contexte']['composition']) && file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext")
189
+                    || file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext")
190
+                )
191
+            ) {
192
+                $flux['data'] = $f;
193
+            }
194
+        } elseif (
195
+            $fond == 'structure'
196
+            && z_sanitize_var_zajax()
197
+            && ($f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext"))
198
+        ) {
199
+            $flux['data'] = substr((string) $f, 0, -strlen(".$ext"));
200
+        } elseif (
201
+            // chercher le fond correspondant a la composition
202
+            isset($flux['args']['contexte']['composition'])
203
+            && (basename($fond) == 'page' || $squelette && str_ends_with((string) $squelette, $fond))
204
+            && ($dir = substr($fond, $prefix_length))
205
+            && ($dir = explode('/', $dir))
206
+            && ($dir = reset($dir))
207
+            && in_array($dir, $z_blocs)
208
+            && ($f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext"))
209
+        ) {
210
+            $flux['data'] = substr((string) $f, 0, -strlen(".$ext"));
211
+        }
212
+    }
213
+
214
+    return $flux;
215 215
 }
216 216
 
217 217
 /**
@@ -221,18 +221,18 @@  discard block
 block discarded – undo
221 221
  * @return array
222 222
  */
223 223
 function z_blocs($espace_prive = false) {
224
-	if ($espace_prive) {
225
-		return ($GLOBALS['z_blocs_ecrire'] ?? [
226
-			'contenu',
227
-			'navigation',
228
-			'extra',
229
-			'head',
230
-			'hierarchie',
231
-			'top'
232
-		]);
233
-	}
234
-
235
-	return ($GLOBALS['z_blocs'] ?? ['contenu']);
224
+    if ($espace_prive) {
225
+        return ($GLOBALS['z_blocs_ecrire'] ?? [
226
+            'contenu',
227
+            'navigation',
228
+            'extra',
229
+            'head',
230
+            'hierarchie',
231
+            'top'
232
+        ]);
233
+    }
234
+
235
+    return ($GLOBALS['z_blocs'] ?? ['contenu']);
236 236
 }
237 237
 
238 238
 /**
@@ -247,11 +247,11 @@  discard block
 block discarded – undo
247 247
  * @return mixed
248 248
  */
249 249
 function z_contenu_disponible($prefix_path, $z_contenu, $type, $ext, $echafauder = true) {
250
-	if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) {
251
-		return $d;
252
-	}
250
+    if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) {
251
+        return $d;
252
+    }
253 253
 
254
-	return $echafauder ? z_echafaudable($type) : false;
254
+    return $echafauder ? z_echafaudable($type) : false;
255 255
 }
256 256
 
257 257
 /**
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
  *   `true` si on peut l'utiliser, `false` sinon.
266 266
  **/
267 267
 function z_fond_valide($squelette) {
268
-	return !_ZCORE_EXCLURE_PATH || !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette);
268
+    return !_ZCORE_EXCLURE_PATH || !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette);
269 269
 }
270 270
 
271 271
 /**
@@ -283,14 +283,14 @@  discard block
 block discarded – undo
283 283
  * @return string
284 284
  */
285 285
 function z_trouver_bloc($prefix_path, $bloc, $fond, $ext) {
286
-	if (
287
-		defined('_ZCORE_BLOC_PREFIX_SKEL') && ($f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext")) && z_fond_valide($f)
288
-		|| ($f = find_in_path("$prefix_path$bloc/$fond.$ext")) && z_fond_valide($f)
289
-	) {
290
-		return substr((string) $f, 0, -strlen(".$ext"));
291
-	}
292
-
293
-	return '';
286
+    if (
287
+        defined('_ZCORE_BLOC_PREFIX_SKEL') && ($f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext")) && z_fond_valide($f)
288
+        || ($f = find_in_path("$prefix_path$bloc/$fond.$ext")) && z_fond_valide($f)
289
+    ) {
290
+        return substr((string) $f, 0, -strlen(".$ext"));
291
+    }
292
+
293
+    return '';
294 294
 }
295 295
 
296 296
 /**
@@ -302,52 +302,52 @@  discard block
 block discarded – undo
302 302
  * @return bool
303 303
  */
304 304
 function z_echafaudable($type) {
305
-	static $pages = null;
306
-	static $echafaudable = [];
307
-	if (isset($echafaudable[$type])) {
308
-		return $echafaudable[$type];
309
-	}
310
-	if (preg_match(',[^\w],', $type)) {
311
-		return $echafaudable[$type] = false;
312
-	}
313
-
314
-	if (test_espace_prive()) {
315
-		if (!function_exists('trouver_objet_exec')) {
316
-			include_spip('inc/pipelines_ecrire');
317
-		}
318
-		if ($e = trouver_objet_exec($type)) {
319
-			return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $e];
320
-		} else {
321
-			// peut etre c'est un exec=types qui liste tous les objets "type"
322
-			if (
323
-				($t = objet_type($type, false)) !== $type
324
-				&& ($e = trouver_objet_exec($t))
325
-			) {
326
-				return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $t];
327
-			}
328
-		}
329
-	} else {
330
-		if (is_null($pages)) {
331
-			$pages = [];
332
-			$liste = lister_tables_objets_sql();
333
-			foreach ($liste as $t => $d) {
334
-				if ($d['page']) {
335
-					$pages[$d['page']] = [$d['table_objet'], $t];
336
-				}
337
-			}
338
-		}
339
-		if (!isset($pages[$type])) {
340
-			return $echafaudable[$type] = false;
341
-		}
342
-		if ((is_countable($pages[$type]) ? count($pages[$type]) : 0) == 2) {
343
-			$trouver_table = charger_fonction('trouver_table', 'base');
344
-			$pages[$type][] = $trouver_table(reset($pages[$type]));
345
-		}
346
-
347
-		return $echafaudable[$type] = $pages[$type];
348
-	}
349
-
350
-	return $echafaudable[$type] = false;
305
+    static $pages = null;
306
+    static $echafaudable = [];
307
+    if (isset($echafaudable[$type])) {
308
+        return $echafaudable[$type];
309
+    }
310
+    if (preg_match(',[^\w],', $type)) {
311
+        return $echafaudable[$type] = false;
312
+    }
313
+
314
+    if (test_espace_prive()) {
315
+        if (!function_exists('trouver_objet_exec')) {
316
+            include_spip('inc/pipelines_ecrire');
317
+        }
318
+        if ($e = trouver_objet_exec($type)) {
319
+            return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $e];
320
+        } else {
321
+            // peut etre c'est un exec=types qui liste tous les objets "type"
322
+            if (
323
+                ($t = objet_type($type, false)) !== $type
324
+                && ($e = trouver_objet_exec($t))
325
+            ) {
326
+                return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $t];
327
+            }
328
+        }
329
+    } else {
330
+        if (is_null($pages)) {
331
+            $pages = [];
332
+            $liste = lister_tables_objets_sql();
333
+            foreach ($liste as $t => $d) {
334
+                if ($d['page']) {
335
+                    $pages[$d['page']] = [$d['table_objet'], $t];
336
+                }
337
+            }
338
+        }
339
+        if (!isset($pages[$type])) {
340
+            return $echafaudable[$type] = false;
341
+        }
342
+        if ((is_countable($pages[$type]) ? count($pages[$type]) : 0) == 2) {
343
+            $trouver_table = charger_fonction('trouver_table', 'base');
344
+            $pages[$type][] = $trouver_table(reset($pages[$type]));
345
+        }
346
+
347
+        return $echafaudable[$type] = $pages[$type];
348
+    }
349
+
350
+    return $echafaudable[$type] = false;
351 351
 }
352 352
 
353 353
 
@@ -364,42 +364,42 @@  discard block
 block discarded – undo
364 364
  * @return string
365 365
  */
366 366
 function prive_echafauder_dist($exec, $table, $table_sql, $desc_exec, $ext) {
367
-	$scaffold = '';
368
-
369
-	// page objet ou objet_edit
370
-	if (is_array($desc_exec)) {
371
-		$type = $desc_exec['type'];
372
-		$primary = $desc_exec['id_table_objet'];
373
-
374
-		if ($desc_exec['edition'] === false) {
375
-			$fond = 'objet';
376
-		} else {
377
-			$trouver_table = charger_fonction('trouver_table', 'base');
378
-			$desc = $trouver_table($table_sql);
379
-			$fond = isset($desc['field']['id_rubrique']) ? 'objet_edit' : 'objet_edit.sans_rubrique';
380
-		}
381
-		$dir = z_blocs(test_espace_prive());
382
-		$dir = reset($dir);
383
-		$scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper((string) $primary) . ',env}>';
384
-	} // page objets
385
-	elseif (($type = $desc_exec) && !str_contains($type, '/')) {
386
-		$dir = z_blocs(test_espace_prive());
387
-		$dir = reset($dir);
388
-		$scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />';
389
-	}
390
-	// morceau d'objet : on fournit le fond de sibstitution dans $desc_exec
391
-	// et objet et tire de $table
392
-	elseif ($fond = $desc_exec) {
393
-		$dir = md5(dirname($fond));
394
-		$scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />';
395
-	}
396
-
397
-	$base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false);
398
-	$base_dir = sous_repertoire($base_dir, $dir, false);
399
-	$f = $base_dir . "$exec";
400
-	ecrire_fichier("$f.$ext", $scaffold);
401
-
402
-	return $f;
367
+    $scaffold = '';
368
+
369
+    // page objet ou objet_edit
370
+    if (is_array($desc_exec)) {
371
+        $type = $desc_exec['type'];
372
+        $primary = $desc_exec['id_table_objet'];
373
+
374
+        if ($desc_exec['edition'] === false) {
375
+            $fond = 'objet';
376
+        } else {
377
+            $trouver_table = charger_fonction('trouver_table', 'base');
378
+            $desc = $trouver_table($table_sql);
379
+            $fond = isset($desc['field']['id_rubrique']) ? 'objet_edit' : 'objet_edit.sans_rubrique';
380
+        }
381
+        $dir = z_blocs(test_espace_prive());
382
+        $dir = reset($dir);
383
+        $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper((string) $primary) . ',env}>';
384
+    } // page objets
385
+    elseif (($type = $desc_exec) && !str_contains($type, '/')) {
386
+        $dir = z_blocs(test_espace_prive());
387
+        $dir = reset($dir);
388
+        $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />';
389
+    }
390
+    // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec
391
+    // et objet et tire de $table
392
+    elseif ($fond = $desc_exec) {
393
+        $dir = md5(dirname($fond));
394
+        $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />';
395
+    }
396
+
397
+    $base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false);
398
+    $base_dir = sous_repertoire($base_dir, $dir, false);
399
+    $f = $base_dir . "$exec";
400
+    ecrire_fichier("$f.$ext", $scaffold);
401
+
402
+    return $f;
403 403
 }
404 404
 
405 405
 /**
@@ -408,17 +408,17 @@  discard block
 block discarded – undo
408 408
  * @return bool|string
409 409
  */
410 410
 function z_sanitize_var_zajax() {
411
-	$z_ajax = _request('var_zajax');
412
-	if (!$z_ajax) {
413
-		return false;
414
-	}
415
-	if (
416
-		!($z_blocs = z_blocs(test_espace_prive()))
417
-		|| !in_array($z_ajax, $z_blocs)
418
-	) {
419
-		set_request('var_zajax'); // enlever cette demande incongrue
420
-		$z_ajax = false;
421
-	}
422
-
423
-	return $z_ajax;
411
+    $z_ajax = _request('var_zajax');
412
+    if (!$z_ajax) {
413
+        return false;
414
+    }
415
+    if (
416
+        !($z_blocs = z_blocs(test_espace_prive()))
417
+        || !in_array($z_ajax, $z_blocs)
418
+    ) {
419
+        set_request('var_zajax'); // enlever cette demande incongrue
420
+        $z_ajax = false;
421
+    }
422
+
423
+    return $z_ajax;
424 424
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 			$apl_constant = '_Z_AJAX_PARALLEL_LOAD';
53 53
 			$page = _SPIP_PAGE;
54 54
 			$echafauder = charger_fonction('echafauder', 'public', true);
55
-			define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim(
55
+			define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist'.(defined('_DIR_PLUGIN_DIST') ? '|\b'.rtrim(
56 56
 				(string) _DIR_PLUGIN_DIST,
57 57
 				'/'
58 58
 			) : ''));
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 			&& in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z
77 77
 			&& defined($apl_constant)
78 78
 			&& in_array($dir, explode(',', (string) constant($apl_constant))) // et dans un demande en APL
79
-			&& ($pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext)) // et qui contient le squelette APL
79
+			&& ($pipe = z_trouver_bloc($prefix_path.$prepend, $dir, 'z_apl', $ext)) // et qui contient le squelette APL
80 80
 		) {
81 81
 			$flux['data'] = $pipe;
82 82
 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 			$echafauder = '';
90 90
 		}
91 91
 		if ($prepend) {
92
-			$squelette = substr((string) find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext"));
92
+			$squelette = substr((string) find_in_path($prefix_path.$prepend."$fond.$ext"), 0, -strlen(".$ext"));
93 93
 			if ($squelette) {
94 94
 				$flux['data'] = $squelette;
95 95
 			}
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
109 109
 				// se brancher sur contenu/xx si il existe
110 110
 				// ou si c'est un objet spip, associe a une table, utiliser le fond homonyme
111 111
 				if (!isset($disponible[$fond])) {
112
-					$disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, (bool) $echafauder);
112
+					$disponible[$fond] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $fond, $ext, (bool) $echafauder);
113 113
 				}
114 114
 
115 115
 				if ($disponible[$fond]) {
116
-					$flux['data'] = substr((string) find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext"));
116
+					$flux['data'] = substr((string) find_in_path($prefix_path."page.$ext"), 0, -strlen(".$ext"));
117 117
 				}
118 118
 			}
119 119
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 					$type = $flux['args']['contexte'][$page];
127 127
 				}
128 128
 				if (!isset($disponible[$type])) {
129
-					$disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, (bool) $echafauder);
129
+					$disponible[$type] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $type, $ext, (bool) $echafauder);
130 130
 				}
131 131
 				if (is_string($disponible[$type])) {
132 132
 					$flux['data'] = $disponible[$type];
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 					$flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext);
142 142
 				} else {
143 143
 					$flux['data'] = ($disponible['404'] = z_contenu_disponible(
144
-						$prefix_path . $prepend,
144
+						$prefix_path.$prepend,
145 145
 						$z_contenu,
146 146
 						'404',
147 147
 						$ext,
@@ -165,10 +165,10 @@  discard block
 block discarded – undo
165 165
 						$type = $flux['args']['contexte'][$page];
166 166
 					}
167 167
 					if ($type !== 'page' && !isset($disponible[$type])) {
168
-						$disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, (bool) $echafauder);
168
+						$disponible[$type] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $type, $ext, (bool) $echafauder);
169 169
 					}
170 170
 					if ($type == 'page' || $disponible[$type]) {
171
-						$flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext);
171
+						$flux['data'] = z_trouver_bloc($prefix_path.$prepend, $dir, 'dist', $ext);
172 172
 					}
173 173
 				}
174 174
 			}
@@ -185,8 +185,8 @@  discard block
 block discarded – undo
185 185
 			if (
186 186
 				isset($flux['args']['contexte']['type-page'])
187 187
 				&& (
188
-					isset($flux['args']['contexte']['composition']) && file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext")
189
-					|| file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext")
188
+					isset($flux['args']['contexte']['composition']) && file_exists(($f = $squelette.'-'.$flux['args']['contexte']['type-page'].'-'.$flux['args']['contexte']['composition']).".$ext")
189
+					|| file_exists(($f = $squelette.'-'.$flux['args']['contexte']['type-page']).".$ext")
190 190
 				)
191 191
 			) {
192 192
 				$flux['data'] = $f;
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 		} elseif (
195 195
 			$fond == 'structure'
196 196
 			&& z_sanitize_var_zajax()
197
-			&& ($f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext"))
197
+			&& ($f = find_in_path($prefix_path.$prepend.'ajax'.".$ext"))
198 198
 		) {
199 199
 			$flux['data'] = substr((string) $f, 0, -strlen(".$ext"));
200 200
 		} elseif (
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 			&& ($dir = explode('/', $dir))
206 206
 			&& ($dir = reset($dir))
207 207
 			&& in_array($dir, $z_blocs)
208
-			&& ($f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext"))
208
+			&& ($f = find_in_path($prefix_path.$prepend.$fond.'-'.$flux['args']['contexte']['composition'].".$ext"))
209 209
 		) {
210 210
 			$flux['data'] = substr((string) $f, 0, -strlen(".$ext"));
211 211
 		}
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
  *   `true` si on peut l'utiliser, `false` sinon.
266 266
  **/
267 267
 function z_fond_valide($squelette) {
268
-	return !_ZCORE_EXCLURE_PATH || !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette);
268
+	return !_ZCORE_EXCLURE_PATH || !preg_match(',('._ZCORE_EXCLURE_PATH.')/,', $squelette);
269 269
 }
270 270
 
271 271
 /**
@@ -380,23 +380,23 @@  discard block
 block discarded – undo
380 380
 		}
381 381
 		$dir = z_blocs(test_espace_prive());
382 382
 		$dir = reset($dir);
383
-		$scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper((string) $primary) . ',env}>';
383
+		$scaffold = "<INCLURE{fond=prive/echafaudage/$dir/".$fond.',objet='.$type.',id_objet=#'.strtoupper((string) $primary).',env}>';
384 384
 	} // page objets
385 385
 	elseif (($type = $desc_exec) && !str_contains($type, '/')) {
386 386
 		$dir = z_blocs(test_espace_prive());
387 387
 		$dir = reset($dir);
388
-		$scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />';
388
+		$scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=".$type.',env} />';
389 389
 	}
390 390
 	// morceau d'objet : on fournit le fond de sibstitution dans $desc_exec
391 391
 	// et objet et tire de $table
392 392
 	elseif ($fond = $desc_exec) {
393 393
 		$dir = md5(dirname($fond));
394
-		$scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />';
394
+		$scaffold = "<INCLURE{fond=$fond,objet=".objet_type($table).',env} />';
395 395
 	}
396 396
 
397 397
 	$base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false);
398 398
 	$base_dir = sous_repertoire($base_dir, $dir, false);
399
-	$f = $base_dir . "$exec";
399
+	$f = $base_dir."$exec";
400 400
 	ecrire_fichier("$f.$ext", $scaffold);
401 401
 
402 402
 	return $f;
Please login to merge, or discard this patch.
ecrire/public/normaliser.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -13,15 +13,15 @@  discard block
 block discarded – undo
13 13
 \***************************************************************************/
14 14
 
15 15
 if (!defined('_ECRIRE_INC_VERSION')) {
16
-	return;
16
+    return;
17 17
 }
18 18
 
19 19
 function phraser_vieux_modele($p) {
20
- normaliser_args_inclumodel($p);
20
+    normaliser_args_inclumodel($p);
21 21
 }
22 22
 
23 23
 function phraser_vieux_inclu($p) {
24
- normaliser_args_inclumodel($p);
24
+    normaliser_args_inclumodel($p);
25 25
 }
26 26
 
27 27
 /**
@@ -32,24 +32,24 @@  discard block
 block discarded – undo
32 32
  * @return void
33 33
  */
34 34
 function normaliser_args_inclumodel($p) {
35
-	$params = $p->param;
36
-	if (!$params) {
37
-		return;
38
-	}
39
-	$args = $params[0];
40
-	if ($args[0]) {
41
-		return;
42
-	} // filtre immediat
43
-	array_shift($p->param);
44
-	foreach ($p->param as $l) {
45
-		if (!array_shift($l)) {
46
-			$args = array_merge($args, $l);
47
-			array_shift($p->param);
48
-		} else {
49
-			break;
50
-		} // filtre
51
-	}
52
-	array_unshift($p->param, $args);
35
+    $params = $p->param;
36
+    if (!$params) {
37
+        return;
38
+    }
39
+    $args = $params[0];
40
+    if ($args[0]) {
41
+        return;
42
+    } // filtre immediat
43
+    array_shift($p->param);
44
+    foreach ($p->param as $l) {
45
+        if (!array_shift($l)) {
46
+            $args = array_merge($args, $l);
47
+            array_shift($p->param);
48
+        } else {
49
+            break;
50
+        } // filtre
51
+    }
52
+    array_unshift($p->param, $args);
53 53
 }
54 54
 
55 55
 
@@ -59,35 +59,35 @@  discard block
 block discarded – undo
59 59
  * @return void
60 60
  */
61 61
 function normaliser_inclure($champ) {
62
-	normaliser_args_inclumodel($champ);
63
-	$l = $champ->param[0];
64
-	if (is_array($l) && !$l[0]) {
65
-		foreach ($l as $k => $p) {
66
-			if ($p && $p[0]->type == 'texte' && !strpos((string) $p[0]->texte, '=')) {
67
-				$p[0]->texte = trim((string) $p[0]->texte);
68
-			}
69
-		}
70
-		foreach ($l as $k => $p) {
71
-			if (
72
-				!$p || $p[0]->type != 'texte'
73
-				|| !preg_match('/^fond\s*=\s*(.*)$/', (string) $p[0]->texte, $r)
74
-			) {
75
-				continue;
76
-			}
62
+    normaliser_args_inclumodel($champ);
63
+    $l = $champ->param[0];
64
+    if (is_array($l) && !$l[0]) {
65
+        foreach ($l as $k => $p) {
66
+            if ($p && $p[0]->type == 'texte' && !strpos((string) $p[0]->texte, '=')) {
67
+                $p[0]->texte = trim((string) $p[0]->texte);
68
+            }
69
+        }
70
+        foreach ($l as $k => $p) {
71
+            if (
72
+                !$p || $p[0]->type != 'texte'
73
+                || !preg_match('/^fond\s*=\s*(.*)$/', (string) $p[0]->texte, $r)
74
+            ) {
75
+                continue;
76
+            }
77 77
 
78
-			if ($r[1]) {
79
-				$p[0]->texte = $r[1];
80
-			} else {
81
-				unset($p[0]);
82
-			}
83
-			$champ->texte = $p;
84
-			unset($champ->param[0][$k]);
85
-			if ((is_countable($champ->param[0]) ? count($champ->param[0]) : 0) == 1) {
86
-				array_shift($champ->param);
87
-			}
78
+            if ($r[1]) {
79
+                $p[0]->texte = $r[1];
80
+            } else {
81
+                unset($p[0]);
82
+            }
83
+            $champ->texte = $p;
84
+            unset($champ->param[0][$k]);
85
+            if ((is_countable($champ->param[0]) ? count($champ->param[0]) : 0) == 1) {
86
+                array_shift($champ->param);
87
+            }
88 88
 
89
-			return;
90
-		}
91
-	}
92
-	spip_log('inclure sans fond ni fichier', 'vieilles_def');
89
+            return;
90
+        }
91
+    }
92
+    spip_log('inclure sans fond ni fichier', 'vieilles_def');
93 93
 }
Please login to merge, or discard this patch.
ecrire/public/decompiler.php 2 patches
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -12,129 +12,129 @@  discard block
 block discarded – undo
12 12
 \***************************************************************************/
13 13
 
14 14
 if (!defined('_ECRIRE_INC_VERSION')) {
15
-	return;
15
+    return;
16 16
 }
17 17
 
18 18
 // Decompilation de l'arbre de syntaxe abstraite d'un squelette SPIP
19 19
 
20 20
 function decompiler_boucle($struct, $fmt = '', $prof = 0) {
21
-	$nom = $struct->id_boucle;
22
-	$preaff = decompiler_($struct->preaff, $fmt, $prof);
23
-	$avant = decompiler_($struct->avant, $fmt, $prof);
24
-	$apres = decompiler_($struct->apres, $fmt, $prof);
25
-	$altern = decompiler_($struct->altern, $fmt, $prof);
26
-	$milieu = decompiler_($struct->milieu, $fmt, $prof);
27
-	$postaff = decompiler_($struct->postaff, $fmt, $prof);
28
-
29
-	$type = $struct->sql_serveur ? "$struct->sql_serveur:" : '';
30
-	$type .= ($struct->type_requete ?: $struct->type_table_optionnelle);
31
-
32
-	if ($struct->jointures_explicites) {
33
-		$type .= ' ' . $struct->jointures_explicites;
34
-	}
35
-	if ($struct->table_optionnelle) {
36
-		$type .= '?';
37
-	}
38
-	// Revoir le cas de la boucle recursive
39
-
40
-	$crit = $struct->param;
41
-	if ($crit && !is_array($crit[0])) {
42
-		$type = strtolower($type) . array_shift($crit);
43
-	}
44
-	$crit = decompiler_criteres($struct, $fmt, $prof);
45
-
46
-	$f = 'format_boucle_' . $fmt;
47
-
48
-	return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof);
21
+    $nom = $struct->id_boucle;
22
+    $preaff = decompiler_($struct->preaff, $fmt, $prof);
23
+    $avant = decompiler_($struct->avant, $fmt, $prof);
24
+    $apres = decompiler_($struct->apres, $fmt, $prof);
25
+    $altern = decompiler_($struct->altern, $fmt, $prof);
26
+    $milieu = decompiler_($struct->milieu, $fmt, $prof);
27
+    $postaff = decompiler_($struct->postaff, $fmt, $prof);
28
+
29
+    $type = $struct->sql_serveur ? "$struct->sql_serveur:" : '';
30
+    $type .= ($struct->type_requete ?: $struct->type_table_optionnelle);
31
+
32
+    if ($struct->jointures_explicites) {
33
+        $type .= ' ' . $struct->jointures_explicites;
34
+    }
35
+    if ($struct->table_optionnelle) {
36
+        $type .= '?';
37
+    }
38
+    // Revoir le cas de la boucle recursive
39
+
40
+    $crit = $struct->param;
41
+    if ($crit && !is_array($crit[0])) {
42
+        $type = strtolower($type) . array_shift($crit);
43
+    }
44
+    $crit = decompiler_criteres($struct, $fmt, $prof);
45
+
46
+    $f = 'format_boucle_' . $fmt;
47
+
48
+    return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof);
49 49
 }
50 50
 
51 51
 function decompiler_include($struct, $fmt = '', $prof = 0) {
52
-	$res = [];
53
-	foreach ($struct->param ?: [] as $couple) {
54
-		array_shift($couple);
55
-		foreach ($couple as $v) {
56
-			$res[] = decompiler_($v, $fmt, $prof);
57
-		}
58
-	}
59
-	$file = is_string($struct->texte) ? $struct->texte :
60
-		decompiler_($struct->texte, $fmt, $prof);
61
-	$f = 'format_inclure_' . $fmt;
62
-
63
-	return $f($file, $res, $prof);
52
+    $res = [];
53
+    foreach ($struct->param ?: [] as $couple) {
54
+        array_shift($couple);
55
+        foreach ($couple as $v) {
56
+            $res[] = decompiler_($v, $fmt, $prof);
57
+        }
58
+    }
59
+    $file = is_string($struct->texte) ? $struct->texte :
60
+        decompiler_($struct->texte, $fmt, $prof);
61
+    $f = 'format_inclure_' . $fmt;
62
+
63
+    return $f($file, $res, $prof);
64 64
 }
65 65
 
66 66
 function decompiler_texte($struct, $fmt = '', $prof = 0) {
67
-	$f = 'format_texte_' . $fmt;
67
+    $f = 'format_texte_' . $fmt;
68 68
 
69
-	return strlen((string) $struct->texte) ? $f($struct->texte, $prof) : '';
69
+    return strlen((string) $struct->texte) ? $f($struct->texte, $prof) : '';
70 70
 }
71 71
 
72 72
 function decompiler_polyglotte($struct, $fmt = '', $prof = 0) {
73
-	$f = 'format_polyglotte_' . $fmt;
73
+    $f = 'format_polyglotte_' . $fmt;
74 74
 
75
-	return $f($struct->traductions, $prof);
75
+    return $f($struct->traductions, $prof);
76 76
 }
77 77
 
78 78
 function decompiler_idiome($struct, $fmt = '', $prof = 0) {
79
-	$args = [];
80
-	foreach ($struct->arg as $k => $v) {
81
-		$args[$k] = public_decompiler($v, $fmt, $prof);
82
-	}
79
+    $args = [];
80
+    foreach ($struct->arg as $k => $v) {
81
+        $args[$k] = public_decompiler($v, $fmt, $prof);
82
+    }
83 83
 
84
-	$filtres = decompiler_liste($struct->param, $fmt, $prof);
84
+    $filtres = decompiler_liste($struct->param, $fmt, $prof);
85 85
 
86
-	$f = 'format_idiome_' . $fmt;
86
+    $f = 'format_idiome_' . $fmt;
87 87
 
88
-	return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof);
88
+    return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof);
89 89
 }
90 90
 
91 91
 function decompiler_champ($struct, $fmt = '', $prof = 0) {
92
-	$avant = decompiler_($struct->avant, $fmt, $prof);
93
-	$apres = decompiler_($struct->apres, $fmt, $prof);
94
-	$args = $filtres = '';
95
-	if ($p = $struct->param) {
96
-		if ($p[0][0] === '') {
97
-			$args = decompiler_liste([array_shift($p)], $fmt, $prof);
98
-		}
99
-		$filtres = decompiler_liste($p, $fmt, $prof);
100
-	}
101
-	$f = 'format_champ_' . $fmt;
102
-
103
-	return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof);
92
+    $avant = decompiler_($struct->avant, $fmt, $prof);
93
+    $apres = decompiler_($struct->apres, $fmt, $prof);
94
+    $args = $filtres = '';
95
+    if ($p = $struct->param) {
96
+        if ($p[0][0] === '') {
97
+            $args = decompiler_liste([array_shift($p)], $fmt, $prof);
98
+        }
99
+        $filtres = decompiler_liste($p, $fmt, $prof);
100
+    }
101
+    $f = 'format_champ_' . $fmt;
102
+
103
+    return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof);
104 104
 }
105 105
 
106 106
 function decompiler_liste($sources, $fmt = '', $prof = 0) {
107
-	if (!is_array($sources)) {
108
-		return '';
109
-	}
110
-	$f = 'format_liste_' . $fmt;
111
-	$res = '';
112
-	foreach ($sources as $arg) {
113
-		if (!is_array($arg)) {
114
-			continue; // ne devrait pas arriver.
115
-		} else {
116
-			$r = array_shift($arg);
117
-		}
118
-		$args = [];
119
-		foreach ($arg as $v) {
120
-			// cas des arguments entoures de ' ou "
121
-			if (
122
-				(is_countable($v) ? count($v) : 0) == 1
123
-				&& $v[0]->type == 'texte'
124
-				&& strlen((string) $v[0]->apres) == 1
125
-				&& $v[0]->apres == $v[0]->avant
126
-			) {
127
-				$args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres;
128
-			} else {
129
-				$args[] = decompiler_($v, $fmt, 0 - $prof);
130
-			}
131
-		}
132
-		if ($r !== '' || $args) {
133
-			$res .= $f($r, $args, $prof);
134
-		}
135
-	}
136
-
137
-	return $res;
107
+    if (!is_array($sources)) {
108
+        return '';
109
+    }
110
+    $f = 'format_liste_' . $fmt;
111
+    $res = '';
112
+    foreach ($sources as $arg) {
113
+        if (!is_array($arg)) {
114
+            continue; // ne devrait pas arriver.
115
+        } else {
116
+            $r = array_shift($arg);
117
+        }
118
+        $args = [];
119
+        foreach ($arg as $v) {
120
+            // cas des arguments entoures de ' ou "
121
+            if (
122
+                (is_countable($v) ? count($v) : 0) == 1
123
+                && $v[0]->type == 'texte'
124
+                && strlen((string) $v[0]->apres) == 1
125
+                && $v[0]->apres == $v[0]->avant
126
+            ) {
127
+                $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres;
128
+            } else {
129
+                $args[] = decompiler_($v, $fmt, 0 - $prof);
130
+            }
131
+        }
132
+        if ($r !== '' || $args) {
133
+            $res .= $f($r, $args, $prof);
134
+        }
135
+    }
136
+
137
+    return $res;
138 138
 }
139 139
 
140 140
 // Decompilation des criteres: on triche et on deroge:
@@ -142,93 +142,93 @@  discard block
 block discarded – undo
142 142
 // - le champ apres signale le critere {"separateur"} ou {'separateur'}
143 143
 // - les champs sont implicitement etendus (crochets implicites mais interdits)
144 144
 function decompiler_criteres($boucle, $fmt = '', $prof = 0) {
145
-	$sources = $boucle->param;
146
-	if (!is_array($sources)) {
147
-		return '';
148
-	}
149
-	$res = '';
150
-	$f = 'format_critere_' . $fmt;
151
-	foreach ($sources as $crit) {
152
-		if (!is_array($crit)) {
153
-			continue;
154
-		} // boucle recursive
155
-		array_shift($crit);
156
-		$args = [];
157
-		foreach ($crit as $i => $v) {
158
-			if (
159
-				(is_countable($v) ? count($v) : 0) == 1
160
-				&& $v[0]->type == 'texte'
161
-				&& $v[0]->apres
162
-			) {
163
-				$args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]];
164
-			} else {
165
-				$res2 = [];
166
-				foreach ($v as $k => $p) {
167
-					if (
168
-						isset($p->type)
169
-						&& function_exists($d = 'decompiler_' . $p->type)
170
-					) {
171
-						$r = $d($p, $fmt, (0 - $prof));
172
-						$res2[] = [$p->type, $r];
173
-					} else {
174
-						spip_log("critere $i / $k mal forme");
175
-					}
176
-				}
177
-				$args[] = $res2;
178
-			}
179
-		}
180
-		$res .= $f($args);
181
-	}
182
-
183
-	return $res;
145
+    $sources = $boucle->param;
146
+    if (!is_array($sources)) {
147
+        return '';
148
+    }
149
+    $res = '';
150
+    $f = 'format_critere_' . $fmt;
151
+    foreach ($sources as $crit) {
152
+        if (!is_array($crit)) {
153
+            continue;
154
+        } // boucle recursive
155
+        array_shift($crit);
156
+        $args = [];
157
+        foreach ($crit as $i => $v) {
158
+            if (
159
+                (is_countable($v) ? count($v) : 0) == 1
160
+                && $v[0]->type == 'texte'
161
+                && $v[0]->apres
162
+            ) {
163
+                $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]];
164
+            } else {
165
+                $res2 = [];
166
+                foreach ($v as $k => $p) {
167
+                    if (
168
+                        isset($p->type)
169
+                        && function_exists($d = 'decompiler_' . $p->type)
170
+                    ) {
171
+                        $r = $d($p, $fmt, (0 - $prof));
172
+                        $res2[] = [$p->type, $r];
173
+                    } else {
174
+                        spip_log("critere $i / $k mal forme");
175
+                    }
176
+                }
177
+                $args[] = $res2;
178
+            }
179
+        }
180
+        $res .= $f($args);
181
+    }
182
+
183
+    return $res;
184 184
 }
185 185
 
186 186
 
187 187
 function decompiler_($liste, $fmt = '', $prof = 0) {
188
-	if (!is_array($liste)) {
189
-		return '';
190
-	}
191
-	$prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1);
192
-	$contenu = [];
193
-	foreach ($liste as $k => $p) {
194
-		if (!isset($p->type)) {
195
-			continue;
196
-		} #??????
197
-		$d = 'decompiler_' . $p->type;
198
-		$next = $liste[$k + 1] ?? false;
199
-		// Forcer le champ etendu si son source (pas les reecritures)
200
-		// contenait des args et s'il est suivi d'espaces,
201
-		// le champ simple les eliminant est un bug helas perenne.
202
-
203
-		if (
204
-			$next
205
-			&& $next->type == 'texte'
206
-			&& $p->type == 'champ'
207
-			&& !$p->apres
208
-			&& !$p->avant
209
-			&& $p->fonctions
210
-		) {
211
-			$n = strlen((string) $next->texte) - strlen(ltrim((string) $next->texte));
212
-			if ($n) {
213
-				$champ = new Texte();
214
-				$champ->texte = substr((string) $next->texte, 0, $n);
215
-				$champ->ligne = $p->ligne;
216
-				$p->apres = [$champ];
217
-				$next->texte = substr((string) $next->texte, $n);
218
-			}
219
-		}
220
-		$contenu[] = [$d($p, $fmt, $prof2), $p->type];
221
-	}
222
-	$f = 'format_suite_' . $fmt;
223
-
224
-	return $f($contenu);
188
+    if (!is_array($liste)) {
189
+        return '';
190
+    }
191
+    $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1);
192
+    $contenu = [];
193
+    foreach ($liste as $k => $p) {
194
+        if (!isset($p->type)) {
195
+            continue;
196
+        } #??????
197
+        $d = 'decompiler_' . $p->type;
198
+        $next = $liste[$k + 1] ?? false;
199
+        // Forcer le champ etendu si son source (pas les reecritures)
200
+        // contenait des args et s'il est suivi d'espaces,
201
+        // le champ simple les eliminant est un bug helas perenne.
202
+
203
+        if (
204
+            $next
205
+            && $next->type == 'texte'
206
+            && $p->type == 'champ'
207
+            && !$p->apres
208
+            && !$p->avant
209
+            && $p->fonctions
210
+        ) {
211
+            $n = strlen((string) $next->texte) - strlen(ltrim((string) $next->texte));
212
+            if ($n) {
213
+                $champ = new Texte();
214
+                $champ->texte = substr((string) $next->texte, 0, $n);
215
+                $champ->ligne = $p->ligne;
216
+                $p->apres = [$champ];
217
+                $next->texte = substr((string) $next->texte, $n);
218
+            }
219
+        }
220
+        $contenu[] = [$d($p, $fmt, $prof2), $p->type];
221
+    }
222
+    $f = 'format_suite_' . $fmt;
223
+
224
+    return $f($contenu);
225 225
 }
226 226
 
227 227
 function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') {
228
-	if (!include_spip('public/format_' . $fmt)) {
229
-		return "'$fmt'?";
230
-	}
231
-	$f = 'decompiler_' . $quoi;
228
+    if (!include_spip('public/format_' . $fmt)) {
229
+        return "'$fmt'?";
230
+    }
231
+    $f = 'decompiler_' . $quoi;
232 232
 
233
-	return $f($liste, $fmt, $prof);
233
+    return $f($liste, $fmt, $prof);
234 234
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -19 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	$type .= ($struct->type_requete ?: $struct->type_table_optionnelle);
31 31
 
32 32
 	if ($struct->jointures_explicites) {
33
-		$type .= ' ' . $struct->jointures_explicites;
33
+		$type .= ' '.$struct->jointures_explicites;
34 34
 	}
35 35
 	if ($struct->table_optionnelle) {
36 36
 		$type .= '?';
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
 
40 40
 	$crit = $struct->param;
41 41
 	if ($crit && !is_array($crit[0])) {
42
-		$type = strtolower($type) . array_shift($crit);
42
+		$type = strtolower($type).array_shift($crit);
43 43
 	}
44 44
 	$crit = decompiler_criteres($struct, $fmt, $prof);
45 45
 
46
-	$f = 'format_boucle_' . $fmt;
46
+	$f = 'format_boucle_'.$fmt;
47 47
 
48 48
 	return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof);
49 49
 }
@@ -56,21 +56,20 @@  discard block
 block discarded – undo
56 56
 			$res[] = decompiler_($v, $fmt, $prof);
57 57
 		}
58 58
 	}
59
-	$file = is_string($struct->texte) ? $struct->texte :
60
-		decompiler_($struct->texte, $fmt, $prof);
61
-	$f = 'format_inclure_' . $fmt;
59
+	$file = is_string($struct->texte) ? $struct->texte : decompiler_($struct->texte, $fmt, $prof);
60
+	$f = 'format_inclure_'.$fmt;
62 61
 
63 62
 	return $f($file, $res, $prof);
64 63
 }
65 64
 
66 65
 function decompiler_texte($struct, $fmt = '', $prof = 0) {
67
-	$f = 'format_texte_' . $fmt;
66
+	$f = 'format_texte_'.$fmt;
68 67
 
69 68
 	return strlen((string) $struct->texte) ? $f($struct->texte, $prof) : '';
70 69
 }
71 70
 
72 71
 function decompiler_polyglotte($struct, $fmt = '', $prof = 0) {
73
-	$f = 'format_polyglotte_' . $fmt;
72
+	$f = 'format_polyglotte_'.$fmt;
74 73
 
75 74
 	return $f($struct->traductions, $prof);
76 75
 }
@@ -83,7 +82,7 @@  discard block
 block discarded – undo
83 82
 
84 83
 	$filtres = decompiler_liste($struct->param, $fmt, $prof);
85 84
 
86
-	$f = 'format_idiome_' . $fmt;
85
+	$f = 'format_idiome_'.$fmt;
87 86
 
88 87
 	return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof);
89 88
 }
@@ -98,7 +97,7 @@  discard block
 block discarded – undo
98 97
 		}
99 98
 		$filtres = decompiler_liste($p, $fmt, $prof);
100 99
 	}
101
-	$f = 'format_champ_' . $fmt;
100
+	$f = 'format_champ_'.$fmt;
102 101
 
103 102
 	return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof);
104 103
 }
@@ -107,7 +106,7 @@  discard block
 block discarded – undo
107 106
 	if (!is_array($sources)) {
108 107
 		return '';
109 108
 	}
110
-	$f = 'format_liste_' . $fmt;
109
+	$f = 'format_liste_'.$fmt;
111 110
 	$res = '';
112 111
 	foreach ($sources as $arg) {
113 112
 		if (!is_array($arg)) {
@@ -124,7 +123,7 @@  discard block
 block discarded – undo
124 123
 				&& strlen((string) $v[0]->apres) == 1
125 124
 				&& $v[0]->apres == $v[0]->avant
126 125
 			) {
127
-				$args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres;
126
+				$args[] = $v[0]->avant.$v[0]->texte.$v[0]->apres;
128 127
 			} else {
129 128
 				$args[] = decompiler_($v, $fmt, 0 - $prof);
130 129
 			}
@@ -147,7 +146,7 @@  discard block
 block discarded – undo
147 146
 		return '';
148 147
 	}
149 148
 	$res = '';
150
-	$f = 'format_critere_' . $fmt;
149
+	$f = 'format_critere_'.$fmt;
151 150
 	foreach ($sources as $crit) {
152 151
 		if (!is_array($crit)) {
153 152
 			continue;
@@ -160,13 +159,13 @@  discard block
 block discarded – undo
160 159
 				&& $v[0]->type == 'texte'
161 160
 				&& $v[0]->apres
162 161
 			) {
163
-				$args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]];
162
+				$args[] = [['texte', ($v[0]->apres.$v[0]->texte.$v[0]->apres)]];
164 163
 			} else {
165 164
 				$res2 = [];
166 165
 				foreach ($v as $k => $p) {
167 166
 					if (
168 167
 						isset($p->type)
169
-						&& function_exists($d = 'decompiler_' . $p->type)
168
+						&& function_exists($d = 'decompiler_'.$p->type)
170 169
 					) {
171 170
 						$r = $d($p, $fmt, (0 - $prof));
172 171
 						$res2[] = [$p->type, $r];
@@ -194,7 +193,7 @@  discard block
 block discarded – undo
194 193
 		if (!isset($p->type)) {
195 194
 			continue;
196 195
 		} #??????
197
-		$d = 'decompiler_' . $p->type;
196
+		$d = 'decompiler_'.$p->type;
198 197
 		$next = $liste[$k + 1] ?? false;
199 198
 		// Forcer le champ etendu si son source (pas les reecritures)
200 199
 		// contenait des args et s'il est suivi d'espaces,
@@ -219,16 +218,16 @@  discard block
 block discarded – undo
219 218
 		}
220 219
 		$contenu[] = [$d($p, $fmt, $prof2), $p->type];
221 220
 	}
222
-	$f = 'format_suite_' . $fmt;
221
+	$f = 'format_suite_'.$fmt;
223 222
 
224 223
 	return $f($contenu);
225 224
 }
226 225
 
227 226
 function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') {
228
-	if (!include_spip('public/format_' . $fmt)) {
227
+	if (!include_spip('public/format_'.$fmt)) {
229 228
 		return "'$fmt'?";
230 229
 	}
231
-	$f = 'decompiler_' . $quoi;
230
+	$f = 'decompiler_'.$quoi;
232 231
 
233 232
 	return $f($liste, $fmt, $prof);
234 233
 }
Please login to merge, or discard this patch.
ecrire/public/evaluer_page.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 /**
@@ -28,50 +28,50 @@  discard block
 block discarded – undo
28 28
  * @return void
29 29
  */
30 30
 
31
- /** @var bool Évaluation réussie ? */
31
+    /** @var bool Évaluation réussie ? */
32 32
 $res = true;
33 33
 
34 34
 // Cas d'une page contenant du PHP :
35 35
 if (empty($page['process_ins']) || $page['process_ins'] != 'html') {
36
-	include_spip('inc/lang');
36
+    include_spip('inc/lang');
37 37
 
38
-	// restaurer l'etat des notes avant calcul
39
-	if (
40
-		isset($page['notes'])
41
-		&& $page['notes']
42
-		&& ($notes = charger_fonction('notes', 'inc', true))
43
-	) {
44
-		$notes($page['notes'], 'restaurer_etat');
45
-	}
46
-	ob_start();
47
-	if (str_contains((string) $page['texte'], '?xml')) {
48
-		$page['texte'] = str_replace('<?xml', "<\1?xml", (string) $page['texte']);
49
-	}
38
+    // restaurer l'etat des notes avant calcul
39
+    if (
40
+        isset($page['notes'])
41
+        && $page['notes']
42
+        && ($notes = charger_fonction('notes', 'inc', true))
43
+    ) {
44
+        $notes($page['notes'], 'restaurer_etat');
45
+    }
46
+    ob_start();
47
+    if (str_contains((string) $page['texte'], '?xml')) {
48
+        $page['texte'] = str_replace('<?xml', "<\1?xml", (string) $page['texte']);
49
+    }
50 50
 
51
-	try {
52
-		$res = eval('?' . '>' . $page['texte']);
53
-		$page['texte'] = ob_get_contents();
54
-	} catch (\Throwable $e) {
55
-		$code = $page['texte'];
56
-		$GLOBALS['numero_ligne_php'] = 1;
57
-		if (!function_exists('numerote_ligne_php')) {
58
-			function numerote_ligne_php($match) {
59
-				$GLOBALS['numero_ligne_php']++;
60
-				return "\n/*" . str_pad((string) $GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/';
61
-			}
62
-		}
63
-		$code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', (string) $code);
64
-		$code = trim(highlight_string($code, true));
65
-		erreur_squelette('L' . $e->getLine() . ': ' . $e->getMessage() . '<br />' . $code, [$page['source'],'',$e->getFile(),'',$GLOBALS['spip_lang']]);
66
-		$page['texte'] = '<!-- Erreur -->';
67
-	}
68
-	ob_end_clean();
51
+    try {
52
+        $res = eval('?' . '>' . $page['texte']);
53
+        $page['texte'] = ob_get_contents();
54
+    } catch (\Throwable $e) {
55
+        $code = $page['texte'];
56
+        $GLOBALS['numero_ligne_php'] = 1;
57
+        if (!function_exists('numerote_ligne_php')) {
58
+            function numerote_ligne_php($match) {
59
+                $GLOBALS['numero_ligne_php']++;
60
+                return "\n/*" . str_pad((string) $GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/';
61
+            }
62
+        }
63
+        $code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', (string) $code);
64
+        $code = trim(highlight_string($code, true));
65
+        erreur_squelette('L' . $e->getLine() . ': ' . $e->getMessage() . '<br />' . $code, [$page['source'],'',$e->getFile(),'',$GLOBALS['spip_lang']]);
66
+        $page['texte'] = '<!-- Erreur -->';
67
+    }
68
+    ob_end_clean();
69 69
 
70
-	$page['process_ins'] = 'html';
70
+    $page['process_ins'] = 'html';
71 71
 
72
-	if (str_contains((string) $page['texte'], '?xml')) {
73
-		$page['texte'] = str_replace("<\1?xml", '<?xml', (string) $page['texte']);
74
-	}
72
+    if (str_contains((string) $page['texte'], '?xml')) {
73
+        $page['texte'] = str_replace("<\1?xml", '<?xml', (string) $page['texte']);
74
+    }
75 75
 }
76 76
 
77 77
 // le résultat de calcul d'un squelette est toujours de type string
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	}
50 50
 
51 51
 	try {
52
-		$res = eval('?' . '>' . $page['texte']);
52
+		$res = eval('?'.'>'.$page['texte']);
53 53
 		$page['texte'] = ob_get_contents();
54 54
 	} catch (\Throwable $e) {
55 55
 		$code = $page['texte'];
@@ -57,12 +57,12 @@  discard block
 block discarded – undo
57 57
 		if (!function_exists('numerote_ligne_php')) {
58 58
 			function numerote_ligne_php($match) {
59 59
 				$GLOBALS['numero_ligne_php']++;
60
-				return "\n/*" . str_pad((string) $GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/';
60
+				return "\n/*".str_pad((string) $GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT).'*/';
61 61
 			}
62 62
 		}
63
-		$code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', (string) $code);
63
+		$code = '/*001*/'.preg_replace_callback(",\n,", 'numerote_ligne_php', (string) $code);
64 64
 		$code = trim(highlight_string($code, true));
65
-		erreur_squelette('L' . $e->getLine() . ': ' . $e->getMessage() . '<br />' . $code, [$page['source'],'',$e->getFile(),'',$GLOBALS['spip_lang']]);
65
+		erreur_squelette('L'.$e->getLine().': '.$e->getMessage().'<br />'.$code, [$page['source'], '', $e->getFile(), '', $GLOBALS['spip_lang']]);
66 66
 		$page['texte'] = '<!-- Erreur -->';
67 67
 	}
68 68
 	ob_end_clean();
Please login to merge, or discard this patch.
ecrire/public/phraser_html.php 3 patches
Indentation   +1060 added lines, -1060 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
  **/
28 28
 
29 29
 if (!defined('_ECRIRE_INC_VERSION')) {
30
-	return;
30
+    return;
31 31
 }
32 32
 
33 33
 /** Début de la partie principale d'une boucle */
@@ -74,54 +74,54 @@  discard block
 block discarded – undo
74 74
  */
75 75
 function phraser_inclure(string $texte, int $ligne, array $result): array {
76 76
 
77
-	while (
78
-		(($p = strpos($texte, '<INC')) !== false)
79
-		&& preg_match(BALISE_INCLURE, $texte, $match, PREG_OFFSET_CAPTURE, $p)
80
-	) {
81
-		$poss = array_column($match, 1);
82
-		$match = array_column($match, 0);
83
-		$match = array_pad($match, 3, null);
84
-
85
-		$p = $poss[0];
86
-		$debut = substr($texte, 0, $p);
87
-		if ($p) {
88
-			$result = phraser_idiomes($debut, $ligne, $result);
89
-		}
90
-		$ligne += public_compte_ligne($debut);
91
-
92
-		$champ = new Inclure();
93
-		$champ->ligne = $ligne;
94
-		$ligne += public_compte_ligne((string) $match[0]);
95
-		$fichier = $match[2];
96
-		$champ->texte = $fichier;
97
-
98
-		$texte = substr($texte, $p + strlen((string) $match[0]));
99
-
100
-		// on assimile {var=val} a une liste de un argument sans fonction
101
-		$pos_apres = 0;
102
-		phraser_args($texte, '/>', '', $result, $champ, $pos_apres);
103
-		if (!$champ->texte || (is_countable($champ->param) ? count($champ->param) : 0) > 1) {
104
-			if (!function_exists('normaliser_inclure')) {
105
-				include_spip('public/normaliser');
106
-			}
107
-			normaliser_inclure($champ);
108
-		}
109
-		$pos_fin = strpos($texte, '>', $pos_apres) + 1;
110
-		if (
111
-			(strpos($texte, '</INCLUDE>', $pos_fin) === $pos_fin)
112
-			|| (strpos($texte, '</INCLURE>', $pos_fin) === $pos_fin)
113
-		) {
114
-			$pos_fin += 10;
115
-		}
116
-		$texte = substr($texte, $pos_fin);
117
-		$result[] = $champ;
118
-	}
119
-
120
-	if ($texte != '') {
121
-		$result = phraser_idiomes($texte, $ligne, $result);
122
-	}
123
-
124
-	return $result;
77
+    while (
78
+        (($p = strpos($texte, '<INC')) !== false)
79
+        && preg_match(BALISE_INCLURE, $texte, $match, PREG_OFFSET_CAPTURE, $p)
80
+    ) {
81
+        $poss = array_column($match, 1);
82
+        $match = array_column($match, 0);
83
+        $match = array_pad($match, 3, null);
84
+
85
+        $p = $poss[0];
86
+        $debut = substr($texte, 0, $p);
87
+        if ($p) {
88
+            $result = phraser_idiomes($debut, $ligne, $result);
89
+        }
90
+        $ligne += public_compte_ligne($debut);
91
+
92
+        $champ = new Inclure();
93
+        $champ->ligne = $ligne;
94
+        $ligne += public_compte_ligne((string) $match[0]);
95
+        $fichier = $match[2];
96
+        $champ->texte = $fichier;
97
+
98
+        $texte = substr($texte, $p + strlen((string) $match[0]));
99
+
100
+        // on assimile {var=val} a une liste de un argument sans fonction
101
+        $pos_apres = 0;
102
+        phraser_args($texte, '/>', '', $result, $champ, $pos_apres);
103
+        if (!$champ->texte || (is_countable($champ->param) ? count($champ->param) : 0) > 1) {
104
+            if (!function_exists('normaliser_inclure')) {
105
+                include_spip('public/normaliser');
106
+            }
107
+            normaliser_inclure($champ);
108
+        }
109
+        $pos_fin = strpos($texte, '>', $pos_apres) + 1;
110
+        if (
111
+            (strpos($texte, '</INCLUDE>', $pos_fin) === $pos_fin)
112
+            || (strpos($texte, '</INCLURE>', $pos_fin) === $pos_fin)
113
+        ) {
114
+            $pos_fin += 10;
115
+        }
116
+        $texte = substr($texte, $pos_fin);
117
+        $result[] = $champ;
118
+    }
119
+
120
+    if ($texte != '') {
121
+        $result = phraser_idiomes($texte, $ligne, $result);
122
+    }
123
+
124
+    return $result;
125 125
 }
126 126
 
127 127
 /**
@@ -133,38 +133,38 @@  discard block
 block discarded – undo
133 133
  */
134 134
 function phraser_polyglotte(string $texte, int $ligne, array $result): array {
135 135
 
136
-	$collecteur = new Spip\Texte\Collecteur\Multis();
137
-	$multis = $collecteur->collecter($texte);
138
-
139
-	if (!empty($multis)) {
140
-		$pos_prev = 0;
141
-		foreach ($multis as $multi) {
142
-			if ($multi['pos'] > $pos_prev) {
143
-				$champ = new Texte();
144
-				$champ->texte = substr($texte, $pos_prev, $multi['pos'] - $pos_prev);
145
-				$champ->ligne = $ligne;
146
-				$result[] = $champ;
147
-				$ligne += public_compte_ligne($champ->texte);
148
-			}
149
-
150
-			$champ = new Polyglotte();
151
-			$champ->ligne = $ligne;
152
-			$champ->traductions = $multi['trads'];
153
-			$result[] = $champ;
154
-			$ligne += public_compte_ligne($multi['raw']);
155
-			$pos_prev = $multi['pos'] + $multi['length'];
156
-		}
157
-		$texte = substr($texte, $pos_prev);
158
-	}
159
-
160
-	if ($texte !== '') {
161
-		$champ = new Texte();
162
-		$champ->texte = $texte;
163
-		$champ->ligne = $ligne;
164
-		$result[] = $champ;
165
-	}
166
-
167
-	return $result;
136
+    $collecteur = new Spip\Texte\Collecteur\Multis();
137
+    $multis = $collecteur->collecter($texte);
138
+
139
+    if (!empty($multis)) {
140
+        $pos_prev = 0;
141
+        foreach ($multis as $multi) {
142
+            if ($multi['pos'] > $pos_prev) {
143
+                $champ = new Texte();
144
+                $champ->texte = substr($texte, $pos_prev, $multi['pos'] - $pos_prev);
145
+                $champ->ligne = $ligne;
146
+                $result[] = $champ;
147
+                $ligne += public_compte_ligne($champ->texte);
148
+            }
149
+
150
+            $champ = new Polyglotte();
151
+            $champ->ligne = $ligne;
152
+            $champ->traductions = $multi['trads'];
153
+            $result[] = $champ;
154
+            $ligne += public_compte_ligne($multi['raw']);
155
+            $pos_prev = $multi['pos'] + $multi['length'];
156
+        }
157
+        $texte = substr($texte, $pos_prev);
158
+    }
159
+
160
+    if ($texte !== '') {
161
+        $champ = new Texte();
162
+        $champ->texte = $texte;
163
+        $champ->ligne = $ligne;
164
+        $result[] = $champ;
165
+    }
166
+
167
+    return $result;
168 168
 }
169 169
 
170 170
 
@@ -187,64 +187,64 @@  discard block
 block discarded – undo
187 187
  **/
188 188
 function phraser_idiomes(string $texte, int $ligne, array $result): array {
189 189
 
190
-	while (
191
-		(($p = strpos($texte, '<:')) !== false)
192
-		&& preg_match(BALISE_IDIOMES, $texte, $match, PREG_OFFSET_CAPTURE, $p)
193
-	) {
194
-		$poss = array_column($match, 1);
195
-		$match = array_column($match, 0);
196
-		$match = array_pad($match, 8, null);
197
-		$p = $poss[0];
198
-
199
-		$idiome = (string) $match[0];
200
-		// faux idiome ?
201
-		if (!$match[3] && (empty($match[5]) || $match[5][0] !== '=')) {
202
-			$debut = substr($texte, 0, $p + strlen($idiome));
203
-			$result = phraser_champs($debut, $ligne, $result);
204
-			$ligne += public_compte_ligne($debut);
205
-			continue;
206
-		}
207
-
208
-		$debut = substr($texte, 0, $p);
209
-		$result = phraser_champs($debut, $ligne, $result);
210
-		$ligne += public_compte_ligne($debut);
211
-
212
-		$texte = substr($texte, $p + strlen($idiome));
213
-
214
-		$champ = new Idiome();
215
-		$champ->ligne = $ligne;
216
-		$ligne += public_compte_ligne($idiome);
217
-		// Stocker les arguments de la balise de traduction
218
-		$args = [];
219
-		$largs = (string) $match[5];
220
-		while (
221
-			str_contains($largs, '=')
222
-			&& preg_match(BALISE_IDIOMES_ARGS, $largs, $r)
223
-		) {
224
-			$args[$r[1]] = phraser_champs($r[2], 0, []);
225
-			$largs = substr($largs, strlen($r[0]));
226
-		}
227
-		$champ->arg = $args;
228
-
229
-		// TODO : supprimer ce strtolower cf https://git.spip.net/spip/spip/issues/2536
230
-		$champ->nom_champ = strtolower((string) $match[3]);
231
-		$champ->module = $match[2];
232
-
233
-		// pas d'imbrication pour les filtres sur langue
234
-		$champ->apres = '';
235
-		if (!is_null($match[7])) {
236
-			$pos_apres = 0;
237
-			phraser_args($match[7], ':', '', [], $champ, $pos_apres);
238
-			$champ->apres = substr($match[7], $pos_apres);
239
-		}
240
-		$result[] = $champ;
241
-	}
242
-
243
-	if ($texte !== '') {
244
-		$result = phraser_champs($texte, $ligne, $result);
245
-	}
246
-
247
-	return $result;
190
+    while (
191
+        (($p = strpos($texte, '<:')) !== false)
192
+        && preg_match(BALISE_IDIOMES, $texte, $match, PREG_OFFSET_CAPTURE, $p)
193
+    ) {
194
+        $poss = array_column($match, 1);
195
+        $match = array_column($match, 0);
196
+        $match = array_pad($match, 8, null);
197
+        $p = $poss[0];
198
+
199
+        $idiome = (string) $match[0];
200
+        // faux idiome ?
201
+        if (!$match[3] && (empty($match[5]) || $match[5][0] !== '=')) {
202
+            $debut = substr($texte, 0, $p + strlen($idiome));
203
+            $result = phraser_champs($debut, $ligne, $result);
204
+            $ligne += public_compte_ligne($debut);
205
+            continue;
206
+        }
207
+
208
+        $debut = substr($texte, 0, $p);
209
+        $result = phraser_champs($debut, $ligne, $result);
210
+        $ligne += public_compte_ligne($debut);
211
+
212
+        $texte = substr($texte, $p + strlen($idiome));
213
+
214
+        $champ = new Idiome();
215
+        $champ->ligne = $ligne;
216
+        $ligne += public_compte_ligne($idiome);
217
+        // Stocker les arguments de la balise de traduction
218
+        $args = [];
219
+        $largs = (string) $match[5];
220
+        while (
221
+            str_contains($largs, '=')
222
+            && preg_match(BALISE_IDIOMES_ARGS, $largs, $r)
223
+        ) {
224
+            $args[$r[1]] = phraser_champs($r[2], 0, []);
225
+            $largs = substr($largs, strlen($r[0]));
226
+        }
227
+        $champ->arg = $args;
228
+
229
+        // TODO : supprimer ce strtolower cf https://git.spip.net/spip/spip/issues/2536
230
+        $champ->nom_champ = strtolower((string) $match[3]);
231
+        $champ->module = $match[2];
232
+
233
+        // pas d'imbrication pour les filtres sur langue
234
+        $champ->apres = '';
235
+        if (!is_null($match[7])) {
236
+            $pos_apres = 0;
237
+            phraser_args($match[7], ':', '', [], $champ, $pos_apres);
238
+            $champ->apres = substr($match[7], $pos_apres);
239
+        }
240
+        $result[] = $champ;
241
+    }
242
+
243
+    if ($texte !== '') {
244
+        $result = phraser_champs($texte, $ligne, $result);
245
+    }
246
+
247
+    return $result;
248 248
 }
249 249
 
250 250
 /**
@@ -263,53 +263,53 @@  discard block
 block discarded – undo
263 263
  **/
264 264
 function phraser_champs(string $texte, int $ligne, array $result): array {
265 265
 
266
-	while (
267
-		(($p = strpos($texte, '#')) !== false)
268
-		&& preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match, PREG_OFFSET_CAPTURE, $p)
269
-	) {
270
-		$poss = array_column($match, 1);
271
-		$match = array_column($match, 0);
272
-
273
-		$p = $poss[0];
274
-		if ($p) {
275
-			$debut = substr($texte, 0, $p);
276
-			$result = phraser_polyglotte($debut, $ligne, $result);
277
-			$ligne += public_compte_ligne($debut);
278
-		}
279
-
280
-		$champ = new Champ();
281
-		$champ->ligne = $ligne;
282
-		$ligne += public_compte_ligne($match[0]);
283
-		$champ->nom_boucle = $match[2];
284
-		$champ->nom_champ = $match[3];
285
-		$champ->etoile = $match[5];
286
-
287
-		// texte après la balise
288
-		$suite = substr($texte, $p + strlen($match[0]));
289
-		if ($suite && str_starts_with($suite, '{')) {
290
-			phraser_arg($suite, '', [], $champ);
291
-			// ce ltrim est une ereur de conception
292
-			// mais on le conserve par souci de compatibilite
293
-			$texte = ltrim((string) $suite);
294
-			// Il faudrait le normaliser dans l'arbre de syntaxe abstraite
295
-			// pour faire sauter ce cas particulier a la decompilation.
296
-			/* Ce qui suit est malheureusement incomplet pour cela:
266
+    while (
267
+        (($p = strpos($texte, '#')) !== false)
268
+        && preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match, PREG_OFFSET_CAPTURE, $p)
269
+    ) {
270
+        $poss = array_column($match, 1);
271
+        $match = array_column($match, 0);
272
+
273
+        $p = $poss[0];
274
+        if ($p) {
275
+            $debut = substr($texte, 0, $p);
276
+            $result = phraser_polyglotte($debut, $ligne, $result);
277
+            $ligne += public_compte_ligne($debut);
278
+        }
279
+
280
+        $champ = new Champ();
281
+        $champ->ligne = $ligne;
282
+        $ligne += public_compte_ligne($match[0]);
283
+        $champ->nom_boucle = $match[2];
284
+        $champ->nom_champ = $match[3];
285
+        $champ->etoile = $match[5];
286
+
287
+        // texte après la balise
288
+        $suite = substr($texte, $p + strlen($match[0]));
289
+        if ($suite && str_starts_with($suite, '{')) {
290
+            phraser_arg($suite, '', [], $champ);
291
+            // ce ltrim est une ereur de conception
292
+            // mais on le conserve par souci de compatibilite
293
+            $texte = ltrim((string) $suite);
294
+            // Il faudrait le normaliser dans l'arbre de syntaxe abstraite
295
+            // pour faire sauter ce cas particulier a la decompilation.
296
+            /* Ce qui suit est malheureusement incomplet pour cela:
297 297
 			if ($n = (strlen($suite) - strlen($texte))) {
298 298
 				$champ->apres = array(new Texte);
299 299
 				$champ->apres[0]->texte = substr($suite,0,$n);
300 300
 			}
301 301
 			*/
302
-		} else {
303
-			$texte = $suite;
304
-		}
305
-		phraser_vieux($champ);
306
-		$result[] = $champ;
307
-	}
308
-	if ($texte !== '') {
309
-		$result = phraser_polyglotte($texte, $ligne, $result);
310
-	}
311
-
312
-	return $result;
302
+        } else {
303
+            $texte = $suite;
304
+        }
305
+        phraser_vieux($champ);
306
+        $result[] = $champ;
307
+    }
308
+    if ($texte !== '') {
309
+        $result = phraser_polyglotte($texte, $ligne, $result);
310
+    }
311
+
312
+    return $result;
313 313
 }
314 314
 
315 315
 /**
@@ -324,17 +324,17 @@  discard block
 block discarded – undo
324 324
  * @see phraser_champs_interieurs()
325 325
  */
326 326
 function phraser_champs_etendus(string $texte, int $ligne, array $result): array {
327
-	if ($texte === '') {
328
-		return $result;
329
-	}
327
+    if ($texte === '') {
328
+        return $result;
329
+    }
330 330
 
331
-	$sep = '##';
332
-	while (str_contains($texte, $sep)) {
333
-		$sep .= '#';
334
-	}
331
+    $sep = '##';
332
+    while (str_contains($texte, $sep)) {
333
+        $sep .= '#';
334
+    }
335 335
 
336
-	$champs = phraser_champs_interieurs($texte, $ligne, $sep);
337
-	return array_merge($result, $champs);
336
+    $champs = phraser_champs_interieurs($texte, $ligne, $sep);
337
+    return array_merge($result, $champs);
338 338
 }
339 339
 
340 340
 /**
@@ -347,156 +347,156 @@  discard block
 block discarded – undo
347 347
  * @param Champ|Inclure|Idiome|Boucle $pointeur_champ
348 348
  */
349 349
 function phraser_args(string $texte, string $fin, string $sep, array $result, &$pointeur_champ, int &$pos_debut): array {
350
-	$length = strlen($texte);
351
-	while ($pos_debut < $length && trim($texte[$pos_debut]) === '') {
352
-		$pos_debut++;
353
-	}
354
-	while (($pos_debut < $length) && !str_contains($fin, $texte[$pos_debut])) {
355
-		// phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine
356
-		$st = substr($texte, $pos_debut);
357
-		$result = phraser_arg($st, $sep, $result, $pointeur_champ);
358
-		$pos_debut = $length - strlen((string) $st);
359
-		while ($pos_debut < $length && trim($texte[$pos_debut]) === '') {
360
-			$pos_debut++;
361
-		}
362
-	}
363
-
364
-	return $result;
350
+    $length = strlen($texte);
351
+    while ($pos_debut < $length && trim($texte[$pos_debut]) === '') {
352
+        $pos_debut++;
353
+    }
354
+    while (($pos_debut < $length) && !str_contains($fin, $texte[$pos_debut])) {
355
+        // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine
356
+        $st = substr($texte, $pos_debut);
357
+        $result = phraser_arg($st, $sep, $result, $pointeur_champ);
358
+        $pos_debut = $length - strlen((string) $st);
359
+        while ($pos_debut < $length && trim($texte[$pos_debut]) === '') {
360
+            $pos_debut++;
361
+        }
362
+    }
363
+
364
+    return $result;
365 365
 }
366 366
 
367 367
 function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) {
368
-	preg_match(',^(\|?[^}{)|]*)(.*)$,ms', (string) $texte, $match);
369
-	$suite = ltrim($match[2]);
370
-	$fonc = trim($match[1]);
371
-	if ($fonc && $fonc[0] == '|') {
372
-		$fonc = ltrim(substr($fonc, 1));
373
-	}
374
-	$res = [$fonc];
375
-	$err_f = '';
376
-	// cas du filtre sans argument ou du critere /
377
-	if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) {
378
-		// si pas d'argument, alors il faut une fonction ou un double |
379
-		if (!$match[1]) {
380
-			$err_f = ['zbug_erreur_filtre', ['filtre' => $texte]];
381
-			erreur_squelette($err_f, $pointeur_champ);
382
-			$texte = '';
383
-		} else {
384
-			$texte = $suite;
385
-		}
386
-		if ($err_f) {
387
-			$pointeur_champ->param = false;
388
-		} elseif ($fonc !== '') {
389
-			$pointeur_champ->param[] = $res;
390
-		}
391
-		// pour les balises avec faux filtres qui boudent ce dur larbeur
392
-		$pointeur_champ->fonctions[] = [$fonc, ''];
393
-
394
-		return $result;
395
-	}
396
-	$args = ltrim(substr($suite, 1)); // virer le '(' initial
397
-	$collecte = [];
398
-	while ($args && $args[0] != '}') {
399
-		if ($args[0] == '"') {
400
-			preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs);
401
-		} elseif ($args[0] == "'") {
402
-			preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs);
403
-		} else {
404
-			preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs);
405
-			if (!isset($regs[2]) || !strlen($regs[2])) {
406
-				$err_f = ['zbug_erreur_filtre', ['filtre' => $args]];
407
-				erreur_squelette($err_f, $pointeur_champ);
408
-				$champ = new Texte();
409
-				$champ->apres = $champ->avant = $args = '';
410
-				break;
411
-			}
412
-		}
413
-		$arg = $regs[2];
414
-		if (trim($regs[1])) {
415
-			$champ = new Texte();
416
-			$champ->texte = $arg;
417
-			$champ->apres = $champ->avant = $regs[1];
418
-			$result[] = $champ;
419
-			$collecte[] = $champ;
420
-			$args = ltrim($regs[count($regs) - 1]);
421
-		} else {
422
-			if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) {
423
-				// 0 est un aveu d'impuissance. A completer
424
-				$arg = phraser_champs_exterieurs($arg, 0, $sep, $result);
425
-
426
-				$args = ltrim($regs[count($regs) - 1]);
427
-				$collecte = array_merge($collecte, $arg);
428
-				$result = array_merge($result, $arg);
429
-			} else {
430
-				$n = strpos($args, (string) $r[0]);
431
-				$pred = substr($args, 0, $n);
432
-				$par = ',}';
433
-				if (preg_match('/^(.*)\($/', $pred, $m)) {
434
-					$pred = $m[1];
435
-					$par = ')';
436
-				}
437
-				if ($pred) {
438
-					$champ = new Texte();
439
-					$champ->texte = $pred;
440
-					$champ->apres = $champ->avant = '';
441
-					$result[] = $champ;
442
-					$collecte[] = $champ;
443
-				}
444
-				$rec = substr($args, $n + strlen($r[0]) - 1);
445
-				$champ = new Champ();
446
-				$champ->nom_boucle = $r[2];
447
-				$champ->nom_champ = $r[3];
448
-				$champ->etoile = $r[5];
449
-				$next = $r[6];
450
-				while ($next == '{') {
451
-					phraser_arg($rec, $sep, [], $champ);
452
-					$args = ltrim((string) $rec);
453
-					$next = $args[0] ?? '';
454
-				}
455
-				while ($next == '|') {
456
-					$pos_apres = 0;
457
-					phraser_args($rec, $par, $sep, [], $champ, $pos_apres);
458
-					$args = substr((string) $rec, $pos_apres);
459
-					$next = $args[0] ?? '';
460
-				}
461
-				// Si erreur de syntaxe dans un sous-argument, propager.
462
-				if ($champ->param === false) {
463
-					$err_f = true;
464
-				} else {
465
-					phraser_vieux($champ);
466
-				}
467
-				if ($par == ')') {
468
-					$args = substr($args, 1);
469
-				}
470
-				$collecte[] = $champ;
471
-				$result[] = $champ;
472
-			}
473
-		}
474
-		if (isset($args[0]) && $args[0] == ',') {
475
-			$args = ltrim(substr($args, 1));
476
-			if ($collecte) {
477
-				$res[] = $collecte;
478
-				$collecte = [];
479
-			}
480
-		}
481
-	}
482
-	if ($collecte) {
483
-		$res[] = $collecte;
484
-		$collecte = [];
485
-	}
486
-	$texte = substr($args, 1);
487
-	$source = substr($suite, 0, strlen($suite) - strlen($texte));
488
-	// propager les erreurs, et ignorer les param vides
489
-	if ($pointeur_champ->param !== false) {
490
-		if ($err_f) {
491
-			$pointeur_champ->param = false;
492
-		} elseif ($fonc !== '' || count($res) > 1) {
493
-			$pointeur_champ->param[] = $res;
494
-		}
495
-	}
496
-	// pour les balises avec faux filtres qui boudent ce dur larbeur
497
-	$pointeur_champ->fonctions[] = [$fonc, $source];
498
-
499
-	return $result;
368
+    preg_match(',^(\|?[^}{)|]*)(.*)$,ms', (string) $texte, $match);
369
+    $suite = ltrim($match[2]);
370
+    $fonc = trim($match[1]);
371
+    if ($fonc && $fonc[0] == '|') {
372
+        $fonc = ltrim(substr($fonc, 1));
373
+    }
374
+    $res = [$fonc];
375
+    $err_f = '';
376
+    // cas du filtre sans argument ou du critere /
377
+    if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) {
378
+        // si pas d'argument, alors il faut une fonction ou un double |
379
+        if (!$match[1]) {
380
+            $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]];
381
+            erreur_squelette($err_f, $pointeur_champ);
382
+            $texte = '';
383
+        } else {
384
+            $texte = $suite;
385
+        }
386
+        if ($err_f) {
387
+            $pointeur_champ->param = false;
388
+        } elseif ($fonc !== '') {
389
+            $pointeur_champ->param[] = $res;
390
+        }
391
+        // pour les balises avec faux filtres qui boudent ce dur larbeur
392
+        $pointeur_champ->fonctions[] = [$fonc, ''];
393
+
394
+        return $result;
395
+    }
396
+    $args = ltrim(substr($suite, 1)); // virer le '(' initial
397
+    $collecte = [];
398
+    while ($args && $args[0] != '}') {
399
+        if ($args[0] == '"') {
400
+            preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs);
401
+        } elseif ($args[0] == "'") {
402
+            preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs);
403
+        } else {
404
+            preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs);
405
+            if (!isset($regs[2]) || !strlen($regs[2])) {
406
+                $err_f = ['zbug_erreur_filtre', ['filtre' => $args]];
407
+                erreur_squelette($err_f, $pointeur_champ);
408
+                $champ = new Texte();
409
+                $champ->apres = $champ->avant = $args = '';
410
+                break;
411
+            }
412
+        }
413
+        $arg = $regs[2];
414
+        if (trim($regs[1])) {
415
+            $champ = new Texte();
416
+            $champ->texte = $arg;
417
+            $champ->apres = $champ->avant = $regs[1];
418
+            $result[] = $champ;
419
+            $collecte[] = $champ;
420
+            $args = ltrim($regs[count($regs) - 1]);
421
+        } else {
422
+            if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) {
423
+                // 0 est un aveu d'impuissance. A completer
424
+                $arg = phraser_champs_exterieurs($arg, 0, $sep, $result);
425
+
426
+                $args = ltrim($regs[count($regs) - 1]);
427
+                $collecte = array_merge($collecte, $arg);
428
+                $result = array_merge($result, $arg);
429
+            } else {
430
+                $n = strpos($args, (string) $r[0]);
431
+                $pred = substr($args, 0, $n);
432
+                $par = ',}';
433
+                if (preg_match('/^(.*)\($/', $pred, $m)) {
434
+                    $pred = $m[1];
435
+                    $par = ')';
436
+                }
437
+                if ($pred) {
438
+                    $champ = new Texte();
439
+                    $champ->texte = $pred;
440
+                    $champ->apres = $champ->avant = '';
441
+                    $result[] = $champ;
442
+                    $collecte[] = $champ;
443
+                }
444
+                $rec = substr($args, $n + strlen($r[0]) - 1);
445
+                $champ = new Champ();
446
+                $champ->nom_boucle = $r[2];
447
+                $champ->nom_champ = $r[3];
448
+                $champ->etoile = $r[5];
449
+                $next = $r[6];
450
+                while ($next == '{') {
451
+                    phraser_arg($rec, $sep, [], $champ);
452
+                    $args = ltrim((string) $rec);
453
+                    $next = $args[0] ?? '';
454
+                }
455
+                while ($next == '|') {
456
+                    $pos_apres = 0;
457
+                    phraser_args($rec, $par, $sep, [], $champ, $pos_apres);
458
+                    $args = substr((string) $rec, $pos_apres);
459
+                    $next = $args[0] ?? '';
460
+                }
461
+                // Si erreur de syntaxe dans un sous-argument, propager.
462
+                if ($champ->param === false) {
463
+                    $err_f = true;
464
+                } else {
465
+                    phraser_vieux($champ);
466
+                }
467
+                if ($par == ')') {
468
+                    $args = substr($args, 1);
469
+                }
470
+                $collecte[] = $champ;
471
+                $result[] = $champ;
472
+            }
473
+        }
474
+        if (isset($args[0]) && $args[0] == ',') {
475
+            $args = ltrim(substr($args, 1));
476
+            if ($collecte) {
477
+                $res[] = $collecte;
478
+                $collecte = [];
479
+            }
480
+        }
481
+    }
482
+    if ($collecte) {
483
+        $res[] = $collecte;
484
+        $collecte = [];
485
+    }
486
+    $texte = substr($args, 1);
487
+    $source = substr($suite, 0, strlen($suite) - strlen($texte));
488
+    // propager les erreurs, et ignorer les param vides
489
+    if ($pointeur_champ->param !== false) {
490
+        if ($err_f) {
491
+            $pointeur_champ->param = false;
492
+        } elseif ($fonc !== '' || count($res) > 1) {
493
+            $pointeur_champ->param[] = $res;
494
+        }
495
+    }
496
+    // pour les balises avec faux filtres qui boudent ce dur larbeur
497
+    $pointeur_champ->fonctions[] = [$fonc, $source];
498
+
499
+    return $result;
500 500
 }
501 501
 
502 502
 /**
@@ -504,28 +504,28 @@  discard block
 block discarded – undo
504 504
  * et phraser les inclure sur les morceaux intermédiaires
505 505
  */
506 506
 function phraser_champs_exterieurs(string $texte, int $ligne, string $sep, array $nested_res): array {
507
-	$res = [];
508
-	$preg = ',^%' . preg_quote($sep, ',') . '([0-9]+)(\n*)@,';
509
-	while (($p = strpos($texte, "%$sep")) !== false) {
510
-		$suite = substr($texte, $p);
511
-		if (!preg_match($preg, $suite, $m)) {
512
-			break;
513
-		}
514
-		if ($p) {
515
-			$debut = substr($texte, 0, $p);
516
-			$res = phraser_inclure($debut, $ligne, $res);
517
-			$ligne += public_compte_ligne($debut);
518
-		}
519
-		$res[] = $nested_res[$m[1]];
520
-		$ligne += strlen($m[2]);
521
-		$texte = substr($suite, strlen($m[0]));
522
-	}
523
-
524
-	if ($texte !== '') {
525
-		$res = phraser_inclure($texte, $ligne, $res);
526
-	}
527
-
528
-	return $res;
507
+    $res = [];
508
+    $preg = ',^%' . preg_quote($sep, ',') . '([0-9]+)(\n*)@,';
509
+    while (($p = strpos($texte, "%$sep")) !== false) {
510
+        $suite = substr($texte, $p);
511
+        if (!preg_match($preg, $suite, $m)) {
512
+            break;
513
+        }
514
+        if ($p) {
515
+            $debut = substr($texte, 0, $p);
516
+            $res = phraser_inclure($debut, $ligne, $res);
517
+            $ligne += public_compte_ligne($debut);
518
+        }
519
+        $res[] = $nested_res[$m[1]];
520
+        $ligne += strlen($m[2]);
521
+        $texte = substr($suite, strlen($m[0]));
522
+    }
523
+
524
+    if ($texte !== '') {
525
+        $res = phraser_inclure($texte, $ligne, $res);
526
+    }
527
+
528
+    return $res;
529 529
 }
530 530
 
531 531
 /**
@@ -542,75 +542,75 @@  discard block
 block discarded – undo
542 542
  */
543 543
 function phraser_champs_interieurs(string $texte, int $no_ligne, string $sep): array {
544 544
 
545
-	$champs_trouves = [];
546
-	do {
547
-		$parties = [];
548
-		$nbl = $no_ligne;
549
-		$search_pos = 0;
550
-
551
-		// trouver tous les champs intérieurs (sans autre champs imbriqués), les analyser, et les remplacer par un placehoder
552
-		// le $texte est découpé en parties qu'on re-parse ensuite jusqu'à ce qu'on ne trouve plus de nouveaux champs
553
-		while (
554
-			(($p = strpos($texte, '[', $search_pos)) !== false)
555
-			&& preg_match(CHAMP_ETENDU, $texte, $match, PREG_OFFSET_CAPTURE, $p)
556
-		) {
557
-			$poss = array_column($match, 1);
558
-			$match = array_column($match, 0);
559
-			// si jamais il y a une sous balise inclue dans la partie 7, alors on est pas dans le champ le plus interieur, on continue le search plus loin
560
-			if (str_contains($match[7], '[') && preg_match(CHAMP_ETENDU, $texte, $r, 0, $poss[7])) {
561
-				$search_pos = $poss[7];
562
-				continue;
563
-			}
564
-
565
-			$nbl_debut = 0;
566
-			if ($poss[0]) {
567
-				$nbl_debut = public_compte_ligne($texte, 0, $poss[0]);
568
-				$parties[] = substr($texte, 0, $poss[0]);
569
-			}
570
-			$nbl += $nbl_debut;
571
-
572
-			$champ = new Champ();
573
-			$champ->ligne = $nbl;
574
-			$champ->nom_boucle = $match[3];
575
-			$champ->nom_champ = $match[4];
576
-			$champ->etoile = $match[6];
577
-			$nbl_champ = public_compte_ligne($texte, $poss[0], $poss[0] + strlen($match[0]));
578
-
579
-			// phraser_args indiquera ou commence apres
580
-			$pos_apres = 0;
581
-			$champs_trouves = phraser_args($match[7], ')', $sep, $champs_trouves, $champ, $pos_apres);
582
-			phraser_vieux($champ);
583
-			$champ->avant =	phraser_champs_exterieurs($match[1], $nbl, $sep, $champs_trouves);
584
-			$apres = substr($match[7], $pos_apres + 1);
585
-
586
-			$nbl_debut_champ = 0;
587
-			if (!empty($apres)) {
588
-				$nbl_debut_champ = public_compte_ligne($texte, $poss[0], $poss[7] + $pos_apres + 1);
589
-			}
590
-			$champ->apres = phraser_champs_exterieurs($apres, $nbl + $nbl_debut_champ, $sep, $champs_trouves);
591
-
592
-			// reinjecter la boucle si c'en est une
593
-			phraser_boucle_placeholder($champ);
594
-
595
-			$champs_trouves[] = $champ;
596
-			$j = count($champs_trouves) - 1;
597
-			// on remplace ce champ par un placeholder
598
-			// ajouter $nbl_champ retour ligne pour que la partie conserve le nombre de lignes lors des itérations suivantes
599
-			$parties[] = ($t = "%{$sep}{$j}" . str_repeat("\n", $nbl_champ) . '@');
600
-			$nbl += $nbl_champ;
601
-
602
-			$texte = substr($texte, $poss[0] + strlen($match[0]));
603
-			$search_pos = 0;
604
-		}
605
-
606
-		// si on a trouvé des morceaux, il faut recommencer
607
-		if (count($parties)) {
608
-			// reprenons tous les morceaux qu'on a mis de côté car ne matchant pas (encore)
609
-			$texte = implode('', $parties) . $texte;
610
-		}
611
-	} while (count($parties));
612
-
613
-	return phraser_champs_exterieurs($texte, $no_ligne, $sep, $champs_trouves);
545
+    $champs_trouves = [];
546
+    do {
547
+        $parties = [];
548
+        $nbl = $no_ligne;
549
+        $search_pos = 0;
550
+
551
+        // trouver tous les champs intérieurs (sans autre champs imbriqués), les analyser, et les remplacer par un placehoder
552
+        // le $texte est découpé en parties qu'on re-parse ensuite jusqu'à ce qu'on ne trouve plus de nouveaux champs
553
+        while (
554
+            (($p = strpos($texte, '[', $search_pos)) !== false)
555
+            && preg_match(CHAMP_ETENDU, $texte, $match, PREG_OFFSET_CAPTURE, $p)
556
+        ) {
557
+            $poss = array_column($match, 1);
558
+            $match = array_column($match, 0);
559
+            // si jamais il y a une sous balise inclue dans la partie 7, alors on est pas dans le champ le plus interieur, on continue le search plus loin
560
+            if (str_contains($match[7], '[') && preg_match(CHAMP_ETENDU, $texte, $r, 0, $poss[7])) {
561
+                $search_pos = $poss[7];
562
+                continue;
563
+            }
564
+
565
+            $nbl_debut = 0;
566
+            if ($poss[0]) {
567
+                $nbl_debut = public_compte_ligne($texte, 0, $poss[0]);
568
+                $parties[] = substr($texte, 0, $poss[0]);
569
+            }
570
+            $nbl += $nbl_debut;
571
+
572
+            $champ = new Champ();
573
+            $champ->ligne = $nbl;
574
+            $champ->nom_boucle = $match[3];
575
+            $champ->nom_champ = $match[4];
576
+            $champ->etoile = $match[6];
577
+            $nbl_champ = public_compte_ligne($texte, $poss[0], $poss[0] + strlen($match[0]));
578
+
579
+            // phraser_args indiquera ou commence apres
580
+            $pos_apres = 0;
581
+            $champs_trouves = phraser_args($match[7], ')', $sep, $champs_trouves, $champ, $pos_apres);
582
+            phraser_vieux($champ);
583
+            $champ->avant =	phraser_champs_exterieurs($match[1], $nbl, $sep, $champs_trouves);
584
+            $apres = substr($match[7], $pos_apres + 1);
585
+
586
+            $nbl_debut_champ = 0;
587
+            if (!empty($apres)) {
588
+                $nbl_debut_champ = public_compte_ligne($texte, $poss[0], $poss[7] + $pos_apres + 1);
589
+            }
590
+            $champ->apres = phraser_champs_exterieurs($apres, $nbl + $nbl_debut_champ, $sep, $champs_trouves);
591
+
592
+            // reinjecter la boucle si c'en est une
593
+            phraser_boucle_placeholder($champ);
594
+
595
+            $champs_trouves[] = $champ;
596
+            $j = count($champs_trouves) - 1;
597
+            // on remplace ce champ par un placeholder
598
+            // ajouter $nbl_champ retour ligne pour que la partie conserve le nombre de lignes lors des itérations suivantes
599
+            $parties[] = ($t = "%{$sep}{$j}" . str_repeat("\n", $nbl_champ) . '@');
600
+            $nbl += $nbl_champ;
601
+
602
+            $texte = substr($texte, $poss[0] + strlen($match[0]));
603
+            $search_pos = 0;
604
+        }
605
+
606
+        // si on a trouvé des morceaux, il faut recommencer
607
+        if (count($parties)) {
608
+            // reprenons tous les morceaux qu'on a mis de côté car ne matchant pas (encore)
609
+            $texte = implode('', $parties) . $texte;
610
+        }
611
+    } while (count($parties));
612
+
613
+    return phraser_champs_exterieurs($texte, $no_ligne, $sep, $champs_trouves);
614 614
 }
615 615
 
616 616
 /**
@@ -621,20 +621,20 @@  discard block
 block discarded – undo
621 621
  * @return void
622 622
  */
623 623
 function phraser_vieux(&$champ) {
624
-	$nom = $champ->nom_champ;
625
-	if ($champ->param) {
626
-		if ($nom == 'MODELE') {
627
-			if (!function_exists('phraser_vieux_modele')) {
628
-				include_spip('public/normaliser');
629
-			}
630
-			phraser_vieux_modele($champ);
631
-		} elseif ($nom == 'INCLURE' || $nom == 'INCLUDE') {
632
-			if (!function_exists('phraser_vieux_inclu')) {
633
-				include_spip('public/normaliser');
634
-			}
635
-			phraser_vieux_inclu($champ);
636
-		}
637
-	}
624
+    $nom = $champ->nom_champ;
625
+    if ($champ->param) {
626
+        if ($nom == 'MODELE') {
627
+            if (!function_exists('phraser_vieux_modele')) {
628
+                include_spip('public/normaliser');
629
+            }
630
+            phraser_vieux_modele($champ);
631
+        } elseif ($nom == 'INCLURE' || $nom == 'INCLUDE') {
632
+            if (!function_exists('phraser_vieux_inclu')) {
633
+                include_spip('public/normaliser');
634
+            }
635
+            phraser_vieux_inclu($champ);
636
+        }
637
+    }
638 638
 }
639 639
 
640 640
 
@@ -662,199 +662,199 @@  discard block
 block discarded – undo
662 662
  **/
663 663
 function phraser_criteres($params, &$result) {
664 664
 
665
-	$err_ci = ''; // indiquera s'il y a eu une erreur
666
-	$args = [];
667
-	$type = $result->type_requete;
668
-	$doublons = [];
669
-	foreach ($params as $v) {
670
-		$var = $v[1][0];
671
-		$param = ($var->type != 'texte') ? '' : $var->texte;
672
-		if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', (string) $param))) {
673
-			// plus d'un argument et pas le critere IN:
674
-			// detecter comme on peut si c'est le critere implicite LIMIT debut, fin
675
-			if (
676
-				$var->type != 'texte' || preg_match('/^(n|n-|(n-)?\d+)$/S', (string) $param)
677
-			) {
678
-				$op = ',';
679
-				$not = false;
680
-				$cond = false;
681
-			} else {
682
-				// Le debut du premier argument est l'operateur
683
-				preg_match('/^([!]?)([a-zA-Z]\w*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', (string) $param, $m);
684
-				$op = $m[2];
685
-				$not = (bool) $m[1];
686
-				$cond = (bool) $m[3];
687
-				// virer le premier argument,
688
-				// et mettre son reliquat eventuel
689
-				// Recopier pour ne pas alterer le texte source
690
-				// utile au debusqueur
691
-				if ($m[4]) {
692
-					// une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"}
693
-					if (preg_match(',^(["\'])(.*)\1$,', $m[4])) {
694
-						$c = null;
695
-						eval('$c = ' . $m[4] . ';');
696
-						if (isset($c)) {
697
-							$m[4] = $c;
698
-						}
699
-					}
700
-					$texte = new Texte();
701
-					$texte->texte = $m[4];
702
-					$v[1][0] = $texte;
703
-				} else {
704
-					array_shift($v[1]);
705
-				}
706
-			}
707
-			array_shift($v); // $v[O] est vide
708
-			$crit = new Critere();
709
-			$crit->op = $op;
710
-			$crit->not = $not;
711
-			$crit->cond = $cond;
712
-			$crit->exclus = '';
713
-			$crit->param = $v;
714
-			$args[] = $crit;
715
-		} else {
716
-			if ($var->type != 'texte') {
717
-				// cas 1 seul arg ne commencant pas par du texte brut:
718
-				// erreur ou critere infixe "/"
719
-				if (($v[1][1]->type != 'texte') || (trim((string) $v[1][1]->texte) != '/')) {
720
-					$err_ci = [
721
-						'zbug_critere_inconnu',
722
-						['critere' => $var->nom_champ]
723
-					];
724
-					erreur_squelette($err_ci, $result);
725
-				} else {
726
-					$crit = new Critere();
727
-					$crit->op = '/';
728
-					$crit->not = false;
729
-					$crit->exclus = '';
730
-					$crit->param = [[$v[1][0]], [$v[1][2]]];
731
-					$args[] = $crit;
732
-				}
733
-			} else {
734
-				// traiter qq lexemes particuliers pour faciliter la suite
735
-				// les separateurs
736
-				if ($var->apres) {
737
-					$result->separateur[] = $param;
738
-				} elseif ($param == 'tout' || $param == 'tous') {
739
-					$result->modificateur['tout'] = true;
740
-				} elseif ($param == 'plat') {
741
-					$result->modificateur['plat'] = true;
742
-				}
743
-
744
-				// Boucle hierarchie, analyser le critere id_rubrique
745
-				// et les autres critères {id_x} pour forcer {tout} sur
746
-				// ceux-ci pour avoir la rubrique mere...
747
-				// Les autres critères de la boucle hierarchie doivent être
748
-				// traités normalement.
749
-				elseif (
750
-					strcasecmp($type, 'hierarchie') == 0
751
-					&& !preg_match(",^id_rubrique\b,", (string) $param)
752
-					&& preg_match(',^id_\w+\s*$,', (string) $param)
753
-				) {
754
-					$result->modificateur['tout'] = true;
755
-				} elseif (strcasecmp($type, 'hierarchie') == 0 && $param == 'id_rubrique') {
756
-					// rien a faire sur {id_rubrique} tout seul
757
-				} else {
758
-					// pas d'emplacement statique, faut un dynamique
759
-					// mais il y a 2 cas qui ont les 2 !
760
-					if (($param == 'unique') || (preg_match(',^!?doublons *,', (string) $param))) {
761
-						// cette variable sera inseree dans le code
762
-						// et son nom sert d'indicateur des maintenant
763
-						$result->doublons = '$doublons_index';
764
-						if ($param == 'unique') {
765
-							$param = 'doublons';
766
-						}
767
-					} elseif ($param == 'recherche') {
768
-						// meme chose (a cause de #nom_de_boucle:URL_*)
769
-						$result->hash = ' ';
770
-					}
771
-
772
-					if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', (string) $param, $m)) {
773
-						$crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', '');
774
-					} elseif (
775
-						preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC .
776
-						')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', (string) $param, $m)
777
-					) {
778
-						$a2 = trim($m[8]);
779
-						if ($a2 && ($a2[0] == "'" || $a2[0] == '"') && $a2[0] == substr($a2, -1)) {
780
-							$a2 = substr($a2, 1, -1);
781
-						}
782
-						$crit = phraser_critere_infixe(
783
-							$m[2],
784
-							$a2,
785
-							$v,
786
-							(($m[2] == 'lang_select') ? $m[2] : $m[7]),
787
-							$m[6],
788
-							$m[5]
789
-						);
790
-						$crit->exclus = $m[1];
791
-					} elseif (
792
-						preg_match('/^([!]?)\s*(' .
793
-						CHAMP_SQL_PLUS_FONC .
794
-						')\s*(\??)(.*)$/is', (string) $param, $m)
795
-					) {
796
-						// contient aussi les comparaisons implicites !
797
-						// Comme ci-dessus:
798
-						// le premier arg contient l'operateur
799
-						array_shift($v);
800
-						if ($m[6]) {
801
-							$v[0][0] = new Texte();
802
-							$v[0][0]->texte = $m[6];
803
-						} else {
804
-							array_shift($v[0]);
805
-							if (!$v[0]) {
806
-								array_shift($v);
807
-							}
808
-						}
809
-						$crit = new Critere();
810
-						$crit->op = $m[2];
811
-						$crit->param = $v;
812
-						$crit->not = (bool) $m[1];
813
-						$crit->cond = (bool) $m[5];
814
-					} else {
815
-						$err_ci = [
816
-							'zbug_critere_inconnu',
817
-							['critere' => $param]
818
-						];
819
-						erreur_squelette($err_ci, $result);
820
-					}
821
-
822
-					if ((!preg_match(',^!?doublons *,', (string) $param)) || $crit->not) {
823
-						$args[] = $crit;
824
-					} else {
825
-						$doublons[] = $crit;
826
-					}
827
-				}
828
-			}
829
-		}
830
-	}
831
-
832
-	// les doublons non nies doivent etre le dernier critere
833
-	// pour que la variable $doublon_index ait la bonne valeur
834
-	// cf critere_doublon
835
-	if ($doublons) {
836
-		$args = [...$args, ...$doublons];
837
-	}
838
-
839
-	// Si erreur, laisser la chaine dans ce champ pour le HTTP 503
840
-	if (!$err_ci) {
841
-		$result->criteres = $args;
842
-	}
665
+    $err_ci = ''; // indiquera s'il y a eu une erreur
666
+    $args = [];
667
+    $type = $result->type_requete;
668
+    $doublons = [];
669
+    foreach ($params as $v) {
670
+        $var = $v[1][0];
671
+        $param = ($var->type != 'texte') ? '' : $var->texte;
672
+        if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', (string) $param))) {
673
+            // plus d'un argument et pas le critere IN:
674
+            // detecter comme on peut si c'est le critere implicite LIMIT debut, fin
675
+            if (
676
+                $var->type != 'texte' || preg_match('/^(n|n-|(n-)?\d+)$/S', (string) $param)
677
+            ) {
678
+                $op = ',';
679
+                $not = false;
680
+                $cond = false;
681
+            } else {
682
+                // Le debut du premier argument est l'operateur
683
+                preg_match('/^([!]?)([a-zA-Z]\w*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', (string) $param, $m);
684
+                $op = $m[2];
685
+                $not = (bool) $m[1];
686
+                $cond = (bool) $m[3];
687
+                // virer le premier argument,
688
+                // et mettre son reliquat eventuel
689
+                // Recopier pour ne pas alterer le texte source
690
+                // utile au debusqueur
691
+                if ($m[4]) {
692
+                    // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"}
693
+                    if (preg_match(',^(["\'])(.*)\1$,', $m[4])) {
694
+                        $c = null;
695
+                        eval('$c = ' . $m[4] . ';');
696
+                        if (isset($c)) {
697
+                            $m[4] = $c;
698
+                        }
699
+                    }
700
+                    $texte = new Texte();
701
+                    $texte->texte = $m[4];
702
+                    $v[1][0] = $texte;
703
+                } else {
704
+                    array_shift($v[1]);
705
+                }
706
+            }
707
+            array_shift($v); // $v[O] est vide
708
+            $crit = new Critere();
709
+            $crit->op = $op;
710
+            $crit->not = $not;
711
+            $crit->cond = $cond;
712
+            $crit->exclus = '';
713
+            $crit->param = $v;
714
+            $args[] = $crit;
715
+        } else {
716
+            if ($var->type != 'texte') {
717
+                // cas 1 seul arg ne commencant pas par du texte brut:
718
+                // erreur ou critere infixe "/"
719
+                if (($v[1][1]->type != 'texte') || (trim((string) $v[1][1]->texte) != '/')) {
720
+                    $err_ci = [
721
+                        'zbug_critere_inconnu',
722
+                        ['critere' => $var->nom_champ]
723
+                    ];
724
+                    erreur_squelette($err_ci, $result);
725
+                } else {
726
+                    $crit = new Critere();
727
+                    $crit->op = '/';
728
+                    $crit->not = false;
729
+                    $crit->exclus = '';
730
+                    $crit->param = [[$v[1][0]], [$v[1][2]]];
731
+                    $args[] = $crit;
732
+                }
733
+            } else {
734
+                // traiter qq lexemes particuliers pour faciliter la suite
735
+                // les separateurs
736
+                if ($var->apres) {
737
+                    $result->separateur[] = $param;
738
+                } elseif ($param == 'tout' || $param == 'tous') {
739
+                    $result->modificateur['tout'] = true;
740
+                } elseif ($param == 'plat') {
741
+                    $result->modificateur['plat'] = true;
742
+                }
743
+
744
+                // Boucle hierarchie, analyser le critere id_rubrique
745
+                // et les autres critères {id_x} pour forcer {tout} sur
746
+                // ceux-ci pour avoir la rubrique mere...
747
+                // Les autres critères de la boucle hierarchie doivent être
748
+                // traités normalement.
749
+                elseif (
750
+                    strcasecmp($type, 'hierarchie') == 0
751
+                    && !preg_match(",^id_rubrique\b,", (string) $param)
752
+                    && preg_match(',^id_\w+\s*$,', (string) $param)
753
+                ) {
754
+                    $result->modificateur['tout'] = true;
755
+                } elseif (strcasecmp($type, 'hierarchie') == 0 && $param == 'id_rubrique') {
756
+                    // rien a faire sur {id_rubrique} tout seul
757
+                } else {
758
+                    // pas d'emplacement statique, faut un dynamique
759
+                    // mais il y a 2 cas qui ont les 2 !
760
+                    if (($param == 'unique') || (preg_match(',^!?doublons *,', (string) $param))) {
761
+                        // cette variable sera inseree dans le code
762
+                        // et son nom sert d'indicateur des maintenant
763
+                        $result->doublons = '$doublons_index';
764
+                        if ($param == 'unique') {
765
+                            $param = 'doublons';
766
+                        }
767
+                    } elseif ($param == 'recherche') {
768
+                        // meme chose (a cause de #nom_de_boucle:URL_*)
769
+                        $result->hash = ' ';
770
+                    }
771
+
772
+                    if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', (string) $param, $m)) {
773
+                        $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', '');
774
+                    } elseif (
775
+                        preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC .
776
+                        ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', (string) $param, $m)
777
+                    ) {
778
+                        $a2 = trim($m[8]);
779
+                        if ($a2 && ($a2[0] == "'" || $a2[0] == '"') && $a2[0] == substr($a2, -1)) {
780
+                            $a2 = substr($a2, 1, -1);
781
+                        }
782
+                        $crit = phraser_critere_infixe(
783
+                            $m[2],
784
+                            $a2,
785
+                            $v,
786
+                            (($m[2] == 'lang_select') ? $m[2] : $m[7]),
787
+                            $m[6],
788
+                            $m[5]
789
+                        );
790
+                        $crit->exclus = $m[1];
791
+                    } elseif (
792
+                        preg_match('/^([!]?)\s*(' .
793
+                        CHAMP_SQL_PLUS_FONC .
794
+                        ')\s*(\??)(.*)$/is', (string) $param, $m)
795
+                    ) {
796
+                        // contient aussi les comparaisons implicites !
797
+                        // Comme ci-dessus:
798
+                        // le premier arg contient l'operateur
799
+                        array_shift($v);
800
+                        if ($m[6]) {
801
+                            $v[0][0] = new Texte();
802
+                            $v[0][0]->texte = $m[6];
803
+                        } else {
804
+                            array_shift($v[0]);
805
+                            if (!$v[0]) {
806
+                                array_shift($v);
807
+                            }
808
+                        }
809
+                        $crit = new Critere();
810
+                        $crit->op = $m[2];
811
+                        $crit->param = $v;
812
+                        $crit->not = (bool) $m[1];
813
+                        $crit->cond = (bool) $m[5];
814
+                    } else {
815
+                        $err_ci = [
816
+                            'zbug_critere_inconnu',
817
+                            ['critere' => $param]
818
+                        ];
819
+                        erreur_squelette($err_ci, $result);
820
+                    }
821
+
822
+                    if ((!preg_match(',^!?doublons *,', (string) $param)) || $crit->not) {
823
+                        $args[] = $crit;
824
+                    } else {
825
+                        $doublons[] = $crit;
826
+                    }
827
+                }
828
+            }
829
+        }
830
+    }
831
+
832
+    // les doublons non nies doivent etre le dernier critere
833
+    // pour que la variable $doublon_index ait la bonne valeur
834
+    // cf critere_doublon
835
+    if ($doublons) {
836
+        $args = [...$args, ...$doublons];
837
+    }
838
+
839
+    // Si erreur, laisser la chaine dans ce champ pour le HTTP 503
840
+    if (!$err_ci) {
841
+        $result->criteres = $args;
842
+    }
843 843
 }
844 844
 
845 845
 function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) {
846
-	$args[0] = new Texte();
847
-	$args[0]->texte = $arg1;
848
-	$args[0] = [$args[0]];
849
-	$args[1][0] = new Texte();
850
-	$args[1][0]->texte = $arg2;
851
-	$crit = new Critere();
852
-	$crit->op = $op;
853
-	$crit->not = (bool) $not;
854
-	$crit->cond = (bool) $cond;
855
-	$crit->param = $args;
856
-
857
-	return $crit;
846
+    $args[0] = new Texte();
847
+    $args[0]->texte = $arg1;
848
+    $args[0] = [$args[0]];
849
+    $args[1][0] = new Texte();
850
+    $args[1][0]->texte = $arg2;
851
+    $crit = new Critere();
852
+    $crit->op = $op;
853
+    $crit->not = (bool) $not;
854
+    $crit->cond = (bool) $cond;
855
+    $crit->param = $args;
856
+
857
+    return $crit;
858 858
 }
859 859
 
860 860
 /**
@@ -865,11 +865,11 @@  discard block
 block discarded – undo
865 865
  * @return int
866 866
  */
867 867
 function public_compte_ligne($texte, $debut = 0, $fin = null) {
868
-	if (is_null($fin)) {
869
-		return substr_count((string) $texte, "\n", $debut);
870
-	} else {
871
-		return substr_count((string) $texte, "\n", $debut, $fin - $debut);
872
-	}
868
+    if (is_null($fin)) {
869
+        return substr_count((string) $texte, "\n", $debut);
870
+    } else {
871
+        return substr_count((string) $texte, "\n", $debut, $fin - $debut);
872
+    }
873 873
 }
874 874
 
875 875
 
@@ -879,87 +879,87 @@  discard block
 block discarded – undo
879 879
  * et ensuite on regarde son vrai debut soit <B_xxx> soit <BB_xxx>
880 880
  */
881 881
 function public_trouver_premiere_boucle(string $texte, string $id_parent, array $descr, int $pos_debut_texte = 0): ?array {
882
-	$premiere_boucle = null;
883
-	$pos_derniere_boucle_anonyme = $pos_debut_texte;
884
-
885
-	$current_pos = $pos_debut_texte;
886
-	while (($pos_boucle = strpos((string) $texte, BALISE_BOUCLE, $current_pos)) !== false) {
887
-		$current_pos = $pos_boucle + 1;
888
-		$pos_parent = strpos((string) $texte, '(', $pos_boucle);
889
-
890
-		$id_boucle = '';
891
-		if ($pos_parent !== false) {
892
-			$id_boucle = trim(substr((string) $texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE)));
893
-		}
894
-		if (
895
-			$pos_parent === false
896
-			|| strlen($id_boucle) && (!is_numeric($id_boucle) && !str_starts_with($id_boucle, '_'))
897
-		) {
898
-			$result = new Boucle();
899
-			$result->id_parent = $id_parent;
900
-			$result->descr = $descr;
901
-
902
-			// un id_boucle pour l'affichage de l'erreur
903
-			if (!strlen($id_boucle)) {
904
-				$id_boucle = substr((string) $texte, $pos_boucle + strlen(BALISE_BOUCLE), 15);
905
-			}
906
-			$result->id_boucle = $id_boucle;
907
-			$err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]];
908
-			erreur_squelette($err_b, $result);
909
-
910
-			continue;
911
-		}
912
-		else {
913
-			$boucle = [
914
-				'id_boucle' => $id_boucle,
915
-				'id_boucle_err' => $id_boucle,
916
-				'debut_boucle' => $pos_boucle,
917
-				'pos_boucle' => $pos_boucle,
918
-				'pos_parent' => $pos_parent,
919
-				'pos_precond' => false,
920
-				'pos_precond_inside' => false,
921
-				'pos_preaff' => false,
922
-				'pos_preaff_inside' => false,
923
-			];
924
-
925
-			// un id_boucle pour l'affichage de l'erreur sur les boucle anonymes
926
-			if (!strlen($id_boucle)) {
927
-				$boucle['id_boucle_err'] = substr((string) $texte, $pos_boucle + strlen(BALISE_BOUCLE), 15);
928
-			}
929
-
930
-			// trouver sa position de depart reelle : au <Bxx> ou au <BBxx>
931
-			$precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>';
932
-			$pos_precond = strpos((string) $texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme);
933
-			if (
934
-				$pos_precond !== false
935
-				&& $pos_precond < $boucle['debut_boucle']
936
-			) {
937
-				$boucle['debut_boucle'] = $pos_precond;
938
-				$boucle['pos_precond'] = $pos_precond;
939
-				$boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle);
940
-			}
941
-
942
-			$preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>';
943
-			$pos_preaff = strpos((string) $texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme);
944
-			if (
945
-				$pos_preaff !== false
946
-				&& $pos_preaff < $boucle['debut_boucle']
947
-			) {
948
-				$boucle['debut_boucle'] = $pos_preaff;
949
-				$boucle['pos_preaff'] = $pos_preaff;
950
-				$boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle);
951
-			}
952
-			if (!strlen($id_boucle)) {
953
-				$pos_derniere_boucle_anonyme = $pos_boucle;
954
-			}
955
-
956
-			if (is_null($premiere_boucle) || $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) {
957
-				$premiere_boucle = $boucle;
958
-			}
959
-		}
960
-	}
961
-
962
-	return $premiere_boucle;
882
+    $premiere_boucle = null;
883
+    $pos_derniere_boucle_anonyme = $pos_debut_texte;
884
+
885
+    $current_pos = $pos_debut_texte;
886
+    while (($pos_boucle = strpos((string) $texte, BALISE_BOUCLE, $current_pos)) !== false) {
887
+        $current_pos = $pos_boucle + 1;
888
+        $pos_parent = strpos((string) $texte, '(', $pos_boucle);
889
+
890
+        $id_boucle = '';
891
+        if ($pos_parent !== false) {
892
+            $id_boucle = trim(substr((string) $texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE)));
893
+        }
894
+        if (
895
+            $pos_parent === false
896
+            || strlen($id_boucle) && (!is_numeric($id_boucle) && !str_starts_with($id_boucle, '_'))
897
+        ) {
898
+            $result = new Boucle();
899
+            $result->id_parent = $id_parent;
900
+            $result->descr = $descr;
901
+
902
+            // un id_boucle pour l'affichage de l'erreur
903
+            if (!strlen($id_boucle)) {
904
+                $id_boucle = substr((string) $texte, $pos_boucle + strlen(BALISE_BOUCLE), 15);
905
+            }
906
+            $result->id_boucle = $id_boucle;
907
+            $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]];
908
+            erreur_squelette($err_b, $result);
909
+
910
+            continue;
911
+        }
912
+        else {
913
+            $boucle = [
914
+                'id_boucle' => $id_boucle,
915
+                'id_boucle_err' => $id_boucle,
916
+                'debut_boucle' => $pos_boucle,
917
+                'pos_boucle' => $pos_boucle,
918
+                'pos_parent' => $pos_parent,
919
+                'pos_precond' => false,
920
+                'pos_precond_inside' => false,
921
+                'pos_preaff' => false,
922
+                'pos_preaff_inside' => false,
923
+            ];
924
+
925
+            // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes
926
+            if (!strlen($id_boucle)) {
927
+                $boucle['id_boucle_err'] = substr((string) $texte, $pos_boucle + strlen(BALISE_BOUCLE), 15);
928
+            }
929
+
930
+            // trouver sa position de depart reelle : au <Bxx> ou au <BBxx>
931
+            $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>';
932
+            $pos_precond = strpos((string) $texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme);
933
+            if (
934
+                $pos_precond !== false
935
+                && $pos_precond < $boucle['debut_boucle']
936
+            ) {
937
+                $boucle['debut_boucle'] = $pos_precond;
938
+                $boucle['pos_precond'] = $pos_precond;
939
+                $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle);
940
+            }
941
+
942
+            $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>';
943
+            $pos_preaff = strpos((string) $texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme);
944
+            if (
945
+                $pos_preaff !== false
946
+                && $pos_preaff < $boucle['debut_boucle']
947
+            ) {
948
+                $boucle['debut_boucle'] = $pos_preaff;
949
+                $boucle['pos_preaff'] = $pos_preaff;
950
+                $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle);
951
+            }
952
+            if (!strlen($id_boucle)) {
953
+                $pos_derniere_boucle_anonyme = $pos_boucle;
954
+            }
955
+
956
+            if (is_null($premiere_boucle) || $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) {
957
+                $premiere_boucle = $boucle;
958
+            }
959
+        }
960
+    }
961
+
962
+    return $premiere_boucle;
963 963
 }
964 964
 
965 965
 /**
@@ -975,68 +975,68 @@  discard block
 block discarded – undo
975 975
  *   la description de la boucle dans un tableau associatif
976 976
  */
977 977
 function public_trouver_fin_boucle(string $texte, string $id_parent, array $boucle, int $pos_debut_texte, $result): array {
978
-	$id_boucle = $boucle['id_boucle'];
979
-	$pos_courante = $pos_debut_texte;
980
-
981
-	$boucle['pos_postcond'] = false;
982
-	$boucle['pos_postcond_inside'] = false;
983
-	$boucle['pos_altern'] = false;
984
-	$boucle['pos_altern_inside'] = false;
985
-	$boucle['pos_postaff'] = false;
986
-	$boucle['pos_postaff_inside'] = false;
987
-
988
-	$pos_anonyme_next = null;
989
-	// si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme
990
-	if (!strlen((string) $id_boucle)) {
991
-		$pos_anonyme_next = strpos((string) $texte, BALISE_BOUCLE . '(', $pos_courante);
992
-	}
993
-
994
-	//
995
-	// 1. Recuperer la partie conditionnelle apres
996
-	//
997
-	$apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>';
998
-	$pos_apres = strpos((string) $texte, $apres_boucle, $pos_courante);
999
-	if (
1000
-		$pos_apres !== false
1001
-		&& (!$pos_anonyme_next || $pos_apres < $pos_anonyme_next)
1002
-	) {
1003
-		$boucle['pos_postcond'] = $pos_apres;
1004
-		$pos_apres += strlen($apres_boucle);
1005
-		$boucle['pos_postcond_inside'] = $pos_apres;
1006
-		$pos_courante = $pos_apres ;
1007
-	}
1008
-
1009
-	//
1010
-	// 2. Récuperer la partie alternative apres
1011
-	//
1012
-	$altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>';
1013
-	$pos_altern = strpos((string) $texte, $altern_boucle, $pos_courante);
1014
-	if (
1015
-		$pos_altern !== false
1016
-		&& (!$pos_anonyme_next || $pos_altern < $pos_anonyme_next)
1017
-	) {
1018
-		$boucle['pos_altern'] = $pos_altern;
1019
-		$pos_altern += strlen($altern_boucle);
1020
-		$boucle['pos_altern_inside'] = $pos_altern;
1021
-		$pos_courante = $pos_altern;
1022
-	}
1023
-
1024
-	//
1025
-	// 3. Recuperer la partie footer non alternative
1026
-	//
1027
-	$postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>';
1028
-	$pos_postaff = strpos((string) $texte, $postaff_boucle, $pos_courante);
1029
-	if (
1030
-		$pos_postaff !== false
1031
-		&& (!$pos_anonyme_next || $pos_postaff < $pos_anonyme_next)
1032
-	) {
1033
-		$boucle['pos_postaff'] = $pos_postaff;
1034
-		$pos_postaff += strlen($postaff_boucle);
1035
-		$boucle['pos_postaff_inside'] = $pos_postaff;
1036
-		$pos_courante = $pos_postaff ;
1037
-	}
1038
-
1039
-	return $boucle;
978
+    $id_boucle = $boucle['id_boucle'];
979
+    $pos_courante = $pos_debut_texte;
980
+
981
+    $boucle['pos_postcond'] = false;
982
+    $boucle['pos_postcond_inside'] = false;
983
+    $boucle['pos_altern'] = false;
984
+    $boucle['pos_altern_inside'] = false;
985
+    $boucle['pos_postaff'] = false;
986
+    $boucle['pos_postaff_inside'] = false;
987
+
988
+    $pos_anonyme_next = null;
989
+    // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme
990
+    if (!strlen((string) $id_boucle)) {
991
+        $pos_anonyme_next = strpos((string) $texte, BALISE_BOUCLE . '(', $pos_courante);
992
+    }
993
+
994
+    //
995
+    // 1. Recuperer la partie conditionnelle apres
996
+    //
997
+    $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>';
998
+    $pos_apres = strpos((string) $texte, $apres_boucle, $pos_courante);
999
+    if (
1000
+        $pos_apres !== false
1001
+        && (!$pos_anonyme_next || $pos_apres < $pos_anonyme_next)
1002
+    ) {
1003
+        $boucle['pos_postcond'] = $pos_apres;
1004
+        $pos_apres += strlen($apres_boucle);
1005
+        $boucle['pos_postcond_inside'] = $pos_apres;
1006
+        $pos_courante = $pos_apres ;
1007
+    }
1008
+
1009
+    //
1010
+    // 2. Récuperer la partie alternative apres
1011
+    //
1012
+    $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>';
1013
+    $pos_altern = strpos((string) $texte, $altern_boucle, $pos_courante);
1014
+    if (
1015
+        $pos_altern !== false
1016
+        && (!$pos_anonyme_next || $pos_altern < $pos_anonyme_next)
1017
+    ) {
1018
+        $boucle['pos_altern'] = $pos_altern;
1019
+        $pos_altern += strlen($altern_boucle);
1020
+        $boucle['pos_altern_inside'] = $pos_altern;
1021
+        $pos_courante = $pos_altern;
1022
+    }
1023
+
1024
+    //
1025
+    // 3. Recuperer la partie footer non alternative
1026
+    //
1027
+    $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>';
1028
+    $pos_postaff = strpos((string) $texte, $postaff_boucle, $pos_courante);
1029
+    if (
1030
+        $pos_postaff !== false
1031
+        && (!$pos_anonyme_next || $pos_postaff < $pos_anonyme_next)
1032
+    ) {
1033
+        $boucle['pos_postaff'] = $pos_postaff;
1034
+        $pos_postaff += strlen($postaff_boucle);
1035
+        $boucle['pos_postaff_inside'] = $pos_postaff;
1036
+        $pos_courante = $pos_postaff ;
1037
+    }
1038
+
1039
+    return $boucle;
1040 1040
 }
1041 1041
 
1042 1042
 
@@ -1045,21 +1045,21 @@  discard block
 block discarded – undo
1045 1045
  * @param null|object $boucle
1046 1046
  */
1047 1047
 function phraser_boucle_placeholder(&$champ, ?string $boucle_placeholder = null, $boucle = null) {
1048
-	static $boucles_connues = [];
1049
-	// si c'est un appel pour memoriser une boucle, memorisons la
1050
-	if (is_string($champ) && !empty($boucle_placeholder) && !empty($boucle)) {
1051
-		$boucles_connues[$boucle_placeholder][$champ] = &$boucle;
1052
-	}
1053
-	else {
1054
-		if (!empty($champ->nom_champ) && !empty($boucles_connues[$champ->nom_champ])) {
1055
-			$placeholder = $champ->nom_champ;
1056
-			$id = reset($champ->param[0][1]);
1057
-			$id = $id->texte;
1058
-			if (!empty($boucles_connues[$placeholder][$id])) {
1059
-				$champ = $boucles_connues[$placeholder][$id];
1060
-			}
1061
-		}
1062
-	}
1048
+    static $boucles_connues = [];
1049
+    // si c'est un appel pour memoriser une boucle, memorisons la
1050
+    if (is_string($champ) && !empty($boucle_placeholder) && !empty($boucle)) {
1051
+        $boucles_connues[$boucle_placeholder][$champ] = &$boucle;
1052
+    }
1053
+    else {
1054
+        if (!empty($champ->nom_champ) && !empty($boucles_connues[$champ->nom_champ])) {
1055
+            $placeholder = $champ->nom_champ;
1056
+            $id = reset($champ->param[0][1]);
1057
+            $id = $id->texte;
1058
+            if (!empty($boucles_connues[$placeholder][$id])) {
1059
+                $champ = $boucles_connues[$placeholder][$id];
1060
+            }
1061
+        }
1062
+    }
1063 1063
 }
1064 1064
 
1065 1065
 
@@ -1069,11 +1069,11 @@  discard block
 block discarded – undo
1069 1069
  * @return string
1070 1070
  */
1071 1071
 function public_generer_boucle_placeholder(string $id_boucle, &$boucle, string $boucle_placeholder, int $nb_lignes): string {
1072
-	$placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']';
1073
-	//memoriser la boucle a reinjecter
1074
-	$id_boucle = "$id_boucle";
1075
-	phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle);
1076
-	return $placeholder;
1072
+    $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']';
1073
+    //memoriser la boucle a reinjecter
1074
+    $id_boucle = "$id_boucle";
1075
+    phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle);
1076
+    return $placeholder;
1077 1077
 }
1078 1078
 
1079 1079
 /**
@@ -1086,264 +1086,264 @@  discard block
 block discarded – undo
1086 1086
  */
1087 1087
 function public_phraser_html_dist(string $texte, string $id_parent, array &$boucles, array $descr, int $ligne_debut_texte = 1, ?string $boucle_placeholder = null): array {
1088 1088
 
1089
-	$all_res = [];
1090
-	// definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette
1091
-	if (is_null($boucle_placeholder)) {
1092
-		do {
1093
-			$boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid()));
1094
-		} while (str_contains((string) $texte, $boucle_placeholder));
1095
-	}
1096
-
1097
-	$ligne_debut_initial = $ligne_debut_texte;
1098
-	$pos_debut_texte = 0;
1099
-	while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) {
1100
-		$err_b = ''; // indiquera s'il y a eu une erreur
1101
-		$result = new Boucle();
1102
-		$result->id_parent = $id_parent;
1103
-		$result->descr = $descr;
1104
-
1105
-		$pos_courante = $boucle['pos_boucle'];
1106
-		$pos_parent = $boucle['pos_parent'];
1107
-		$id_boucle_search = $id_boucle = $boucle['id_boucle'];
1108
-
1109
-		$ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent);
1110
-
1111
-		// boucle anonyme ?
1112
-		if (!strlen((string) $id_boucle)) {
1113
-			$id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8);
1114
-		}
1115
-
1116
-		$pos_debut_boucle = $pos_courante;
1117
-
1118
-		$pos_milieu = $pos_parent;
1119
-
1120
-		// Regarder si on a une partie conditionnelle avant <B_xxx>
1121
-		if ($boucle['pos_precond'] !== false) {
1122
-			$pos_debut_boucle = $boucle['pos_precond'];
1123
-
1124
-			$pos_avant = $boucle['pos_precond_inside'];
1125
-			$result->avant = substr((string) $texte, $pos_avant, $pos_courante - $pos_avant);
1126
-			$ligne_avant = $ligne_debut_texte +  public_compte_ligne($texte, $pos_debut_texte, $pos_avant);
1127
-		}
1128
-
1129
-		// Regarder si on a une partie inconditionnelle avant <BB_xxx>
1130
-		if ($boucle['pos_preaff'] !== false) {
1131
-			$end_preaff = $pos_debut_boucle;
1132
-
1133
-			$pos_preaff = $boucle['pos_preaff_inside'];
1134
-			$result->preaff = substr((string) $texte, $pos_preaff, $end_preaff - $pos_preaff);
1135
-			$ligne_preaff = $ligne_debut_texte +  public_compte_ligne($texte, $pos_debut_texte, $pos_preaff);
1136
-		}
1137
-
1138
-		$result->id_boucle = $id_boucle;
1139
-
1140
-		if (
1141
-			!preg_match(SPEC_BOUCLE, (string) $texte, $match, 0, $pos_milieu)
1142
-			|| ($pos_match = strpos((string) $texte, (string) $match[0], $pos_milieu)) === false
1143
-			|| $pos_match > $pos_milieu
1144
-		) {
1145
-			$err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]];
1146
-			erreur_squelette($err_b, $result);
1147
-
1148
-			$ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1);
1149
-			$pos_debut_texte = $pos_courante + 1;
1150
-			continue;
1151
-		}
1152
-
1153
-		$result->type_requete = $match[0];
1154
-		$pos_milieu += strlen($match[0]);
1155
-		$pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment
1156
-
1157
-		$type = $match[1];
1158
-		$jointures = trim($match[2]);
1159
-		$table_optionnelle = ($match[3]);
1160
-		if ($jointures) {
1161
-			// on affecte pas ici les jointures explicites, mais dans la compilation
1162
-			// ou elles seront completees des jointures declarees
1163
-			$result->jointures_explicites = $jointures;
1164
-		}
1165
-
1166
-		if ($table_optionnelle) {
1167
-			$result->table_optionnelle = true;
1168
-			$result->type_table_optionnelle = $type;
1169
-		}
1170
-
1171
-		// 1ere passe sur les criteres, vu comme des arguments sans fct
1172
-		// Resultat mis dans result->param
1173
-		$pos_fin_criteres = $pos_milieu;
1174
-		phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres);
1175
-
1176
-		// En 2e passe result->criteres contiendra un tableau
1177
-		// pour l'instant on met le source (chaine) :
1178
-		// si elle reste ici au final, c'est qu'elle contient une erreur
1179
-		$pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment
1180
-		$result->criteres = substr((string) $texte, $pos_milieu, $pos_fin_criteres - $pos_milieu);
1181
-		$pos_milieu = $pos_fin_criteres;
1182
-
1183
-		//
1184
-		// Recuperer la fin :
1185
-		//
1186
-		if ($texte[$pos_milieu] === '/') {
1187
-			// boucle autofermante : pas de partie conditionnelle apres
1188
-			$pos_courante += 2;
1189
-			$result->milieu = '';
1190
-		} else {
1191
-			$pos_milieu += 1;
1192
-
1193
-			$fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>';
1194
-			$pos_fin = strpos((string) $texte, $fin_boucle, $pos_milieu);
1195
-			if ($pos_fin === false) {
1196
-				$err_b = [
1197
-					'zbug_erreur_boucle_fermant',
1198
-					['id' => $id_boucle]
1199
-				];
1200
-				erreur_squelette($err_b, $result);
1201
-				$pos_courante += strlen($fin_boucle);
1202
-			}
1203
-			else {
1204
-				// verifier une eventuelle imbrication d'une boucle homonyme
1205
-				// (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur)
1206
-				$search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '(';
1207
-				$search_from = $pos_milieu;
1208
-				$nb_open = 1;
1209
-				$nb_close = 1;
1210
-				$maxiter = 0;
1211
-				do {
1212
-					while (
1213
-						$nb_close < $nb_open
1214
-						&& ($p = strpos((string) $texte, $fin_boucle, $pos_fin + 1))
1215
-					) {
1216
-						$nb_close++;
1217
-						$pos_fin = $p;
1218
-					}
1219
-					// si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux
1220
-					if ($nb_close < $nb_open) {
1221
-						break;
1222
-					}
1223
-					while (
1224
-						($p = strpos((string) $texte, $search_debut_boucle, $search_from))
1225
-						&& $p < $pos_fin
1226
-					) {
1227
-						$nb_open++;
1228
-						$search_from = $p + 1;
1229
-					}
1230
-				} while ($nb_close < $nb_open && $maxiter++ < 5);
1231
-
1232
-				$pos_courante = $pos_fin + strlen($fin_boucle);
1233
-			}
1234
-			$result->milieu = substr((string) $texte, $pos_milieu, $pos_fin - $pos_milieu);
1235
-		}
1236
-
1237
-		$ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante);
1238
-		$boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result);
1239
-
1240
-		//
1241
-		// 1. Partie conditionnelle apres ?
1242
-		//
1243
-		if ($boucle['pos_postcond']) {
1244
-			$result->apres = substr((string) $texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante);
1245
-			$ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']);
1246
-			$pos_courante = $boucle['pos_postcond_inside'] ;
1247
-		}
1248
-
1249
-
1250
-		//
1251
-		// 2. Partie alternative apres ?
1252
-		//
1253
-		$ligne_altern = $ligne_suite;
1254
-		if ($boucle['pos_altern']) {
1255
-			$result->altern = substr((string) $texte, $pos_courante, $boucle['pos_altern'] - $pos_courante);
1256
-			$ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']);
1257
-			$pos_courante = $boucle['pos_altern_inside'];
1258
-		}
1259
-
1260
-		//
1261
-		// 3. Partie footer non alternative ?
1262
-		//
1263
-		$ligne_postaff = $ligne_suite;
1264
-		if ($boucle['pos_postaff']) {
1265
-			$result->postaff = substr((string) $texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante);
1266
-			$ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']);
1267
-			$pos_courante = $boucle['pos_postaff_inside'];
1268
-		}
1269
-
1270
-		$result->ligne = $ligne_preaff;
1271
-
1272
-		if ($p = strpos($type, ':')) {
1273
-			$result->sql_serveur = substr($type, 0, $p);
1274
-			$type = substr($type, $p + 1);
1275
-		}
1276
-		$soustype = strtolower($type);
1277
-
1278
-		if (!isset($GLOBALS['table_des_tables'][$soustype])) {
1279
-			$soustype = $type;
1280
-		}
1281
-
1282
-		$result->type_requete = $soustype;
1283
-		// Lancer la 2e passe sur les criteres si la 1ere etait bonne
1284
-		if (!is_array($result->param)) {
1285
-			$err_b = true;
1286
-		} else {
1287
-			phraser_criteres($result->param, $result);
1288
-			if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) {
1289
-				$result->type_requete = TYPE_RECURSIF;
1290
-				$args = $result->param;
1291
-				array_unshift(
1292
-					$args,
1293
-					substr($type, strlen(TYPE_RECURSIF))
1294
-				);
1295
-				$result->param = $args;
1296
-			}
1297
-		}
1298
-
1299
-		$descr['id_mere_contexte'] = $id_boucle;
1300
-		$result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder);
1301
-		// reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre
1302
-		// ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle
1303
-		// si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite
1304
-		if (empty($boucles[$id_boucle])) {
1305
-			$boucles[$id_boucle] = null;
1306
-		}
1307
-		$result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder);
1308
-		$result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder);
1309
-		$result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder);
1310
-		$result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder);
1311
-		$result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder);
1312
-
1313
-		// Prevenir le generateur de code que le squelette est faux
1314
-		if ($err_b) {
1315
-			$result->type_requete = false;
1316
-		}
1317
-
1318
-		// Verifier qu'il n'y a pas double definition
1319
-		// apres analyse des sous-parties (pas avant).
1320
-		if (!empty($boucles[$id_boucle])) {
1321
-			if ($boucles[$id_boucle]->type_requete !== false) {
1322
-				$err_b_d = [
1323
-					'zbug_erreur_boucle_double',
1324
-					['id' => $id_boucle]
1325
-				];
1326
-				erreur_squelette($err_b_d, $result);
1327
-				// Prevenir le generateur de code que le squelette est faux
1328
-				$boucles[$id_boucle]->type_requete = false;
1329
-			}
1330
-		} else {
1331
-			$boucles[$id_boucle] = $result;
1332
-		}
1333
-
1334
-		// remplacer la boucle par un placeholder qui compte le meme nombre de lignes
1335
-		$placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte);
1336
-		$longueur_boucle = $pos_courante - $boucle['debut_boucle'];
1337
-		$texte = substr_replace((string) $texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle);
1338
-		$pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder);
1339
-
1340
-		// phraser la partie avant le debut de la boucle
1341
-		#$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res);
1342
-		#$all_res[] = &$boucles[$id_boucle];
1343
-
1344
-		$ligne_debut_texte = $ligne_suite;
1345
-		$pos_debut_texte = $pos_courante;
1346
-	}
1347
-
1348
-	return phraser_champs_etendus($texte, $ligne_debut_initial, $all_res);
1089
+    $all_res = [];
1090
+    // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette
1091
+    if (is_null($boucle_placeholder)) {
1092
+        do {
1093
+            $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid()));
1094
+        } while (str_contains((string) $texte, $boucle_placeholder));
1095
+    }
1096
+
1097
+    $ligne_debut_initial = $ligne_debut_texte;
1098
+    $pos_debut_texte = 0;
1099
+    while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) {
1100
+        $err_b = ''; // indiquera s'il y a eu une erreur
1101
+        $result = new Boucle();
1102
+        $result->id_parent = $id_parent;
1103
+        $result->descr = $descr;
1104
+
1105
+        $pos_courante = $boucle['pos_boucle'];
1106
+        $pos_parent = $boucle['pos_parent'];
1107
+        $id_boucle_search = $id_boucle = $boucle['id_boucle'];
1108
+
1109
+        $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent);
1110
+
1111
+        // boucle anonyme ?
1112
+        if (!strlen((string) $id_boucle)) {
1113
+            $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8);
1114
+        }
1115
+
1116
+        $pos_debut_boucle = $pos_courante;
1117
+
1118
+        $pos_milieu = $pos_parent;
1119
+
1120
+        // Regarder si on a une partie conditionnelle avant <B_xxx>
1121
+        if ($boucle['pos_precond'] !== false) {
1122
+            $pos_debut_boucle = $boucle['pos_precond'];
1123
+
1124
+            $pos_avant = $boucle['pos_precond_inside'];
1125
+            $result->avant = substr((string) $texte, $pos_avant, $pos_courante - $pos_avant);
1126
+            $ligne_avant = $ligne_debut_texte +  public_compte_ligne($texte, $pos_debut_texte, $pos_avant);
1127
+        }
1128
+
1129
+        // Regarder si on a une partie inconditionnelle avant <BB_xxx>
1130
+        if ($boucle['pos_preaff'] !== false) {
1131
+            $end_preaff = $pos_debut_boucle;
1132
+
1133
+            $pos_preaff = $boucle['pos_preaff_inside'];
1134
+            $result->preaff = substr((string) $texte, $pos_preaff, $end_preaff - $pos_preaff);
1135
+            $ligne_preaff = $ligne_debut_texte +  public_compte_ligne($texte, $pos_debut_texte, $pos_preaff);
1136
+        }
1137
+
1138
+        $result->id_boucle = $id_boucle;
1139
+
1140
+        if (
1141
+            !preg_match(SPEC_BOUCLE, (string) $texte, $match, 0, $pos_milieu)
1142
+            || ($pos_match = strpos((string) $texte, (string) $match[0], $pos_milieu)) === false
1143
+            || $pos_match > $pos_milieu
1144
+        ) {
1145
+            $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]];
1146
+            erreur_squelette($err_b, $result);
1147
+
1148
+            $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1);
1149
+            $pos_debut_texte = $pos_courante + 1;
1150
+            continue;
1151
+        }
1152
+
1153
+        $result->type_requete = $match[0];
1154
+        $pos_milieu += strlen($match[0]);
1155
+        $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment
1156
+
1157
+        $type = $match[1];
1158
+        $jointures = trim($match[2]);
1159
+        $table_optionnelle = ($match[3]);
1160
+        if ($jointures) {
1161
+            // on affecte pas ici les jointures explicites, mais dans la compilation
1162
+            // ou elles seront completees des jointures declarees
1163
+            $result->jointures_explicites = $jointures;
1164
+        }
1165
+
1166
+        if ($table_optionnelle) {
1167
+            $result->table_optionnelle = true;
1168
+            $result->type_table_optionnelle = $type;
1169
+        }
1170
+
1171
+        // 1ere passe sur les criteres, vu comme des arguments sans fct
1172
+        // Resultat mis dans result->param
1173
+        $pos_fin_criteres = $pos_milieu;
1174
+        phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres);
1175
+
1176
+        // En 2e passe result->criteres contiendra un tableau
1177
+        // pour l'instant on met le source (chaine) :
1178
+        // si elle reste ici au final, c'est qu'elle contient une erreur
1179
+        $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment
1180
+        $result->criteres = substr((string) $texte, $pos_milieu, $pos_fin_criteres - $pos_milieu);
1181
+        $pos_milieu = $pos_fin_criteres;
1182
+
1183
+        //
1184
+        // Recuperer la fin :
1185
+        //
1186
+        if ($texte[$pos_milieu] === '/') {
1187
+            // boucle autofermante : pas de partie conditionnelle apres
1188
+            $pos_courante += 2;
1189
+            $result->milieu = '';
1190
+        } else {
1191
+            $pos_milieu += 1;
1192
+
1193
+            $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>';
1194
+            $pos_fin = strpos((string) $texte, $fin_boucle, $pos_milieu);
1195
+            if ($pos_fin === false) {
1196
+                $err_b = [
1197
+                    'zbug_erreur_boucle_fermant',
1198
+                    ['id' => $id_boucle]
1199
+                ];
1200
+                erreur_squelette($err_b, $result);
1201
+                $pos_courante += strlen($fin_boucle);
1202
+            }
1203
+            else {
1204
+                // verifier une eventuelle imbrication d'une boucle homonyme
1205
+                // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur)
1206
+                $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '(';
1207
+                $search_from = $pos_milieu;
1208
+                $nb_open = 1;
1209
+                $nb_close = 1;
1210
+                $maxiter = 0;
1211
+                do {
1212
+                    while (
1213
+                        $nb_close < $nb_open
1214
+                        && ($p = strpos((string) $texte, $fin_boucle, $pos_fin + 1))
1215
+                    ) {
1216
+                        $nb_close++;
1217
+                        $pos_fin = $p;
1218
+                    }
1219
+                    // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux
1220
+                    if ($nb_close < $nb_open) {
1221
+                        break;
1222
+                    }
1223
+                    while (
1224
+                        ($p = strpos((string) $texte, $search_debut_boucle, $search_from))
1225
+                        && $p < $pos_fin
1226
+                    ) {
1227
+                        $nb_open++;
1228
+                        $search_from = $p + 1;
1229
+                    }
1230
+                } while ($nb_close < $nb_open && $maxiter++ < 5);
1231
+
1232
+                $pos_courante = $pos_fin + strlen($fin_boucle);
1233
+            }
1234
+            $result->milieu = substr((string) $texte, $pos_milieu, $pos_fin - $pos_milieu);
1235
+        }
1236
+
1237
+        $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante);
1238
+        $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result);
1239
+
1240
+        //
1241
+        // 1. Partie conditionnelle apres ?
1242
+        //
1243
+        if ($boucle['pos_postcond']) {
1244
+            $result->apres = substr((string) $texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante);
1245
+            $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']);
1246
+            $pos_courante = $boucle['pos_postcond_inside'] ;
1247
+        }
1248
+
1249
+
1250
+        //
1251
+        // 2. Partie alternative apres ?
1252
+        //
1253
+        $ligne_altern = $ligne_suite;
1254
+        if ($boucle['pos_altern']) {
1255
+            $result->altern = substr((string) $texte, $pos_courante, $boucle['pos_altern'] - $pos_courante);
1256
+            $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']);
1257
+            $pos_courante = $boucle['pos_altern_inside'];
1258
+        }
1259
+
1260
+        //
1261
+        // 3. Partie footer non alternative ?
1262
+        //
1263
+        $ligne_postaff = $ligne_suite;
1264
+        if ($boucle['pos_postaff']) {
1265
+            $result->postaff = substr((string) $texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante);
1266
+            $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']);
1267
+            $pos_courante = $boucle['pos_postaff_inside'];
1268
+        }
1269
+
1270
+        $result->ligne = $ligne_preaff;
1271
+
1272
+        if ($p = strpos($type, ':')) {
1273
+            $result->sql_serveur = substr($type, 0, $p);
1274
+            $type = substr($type, $p + 1);
1275
+        }
1276
+        $soustype = strtolower($type);
1277
+
1278
+        if (!isset($GLOBALS['table_des_tables'][$soustype])) {
1279
+            $soustype = $type;
1280
+        }
1281
+
1282
+        $result->type_requete = $soustype;
1283
+        // Lancer la 2e passe sur les criteres si la 1ere etait bonne
1284
+        if (!is_array($result->param)) {
1285
+            $err_b = true;
1286
+        } else {
1287
+            phraser_criteres($result->param, $result);
1288
+            if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) {
1289
+                $result->type_requete = TYPE_RECURSIF;
1290
+                $args = $result->param;
1291
+                array_unshift(
1292
+                    $args,
1293
+                    substr($type, strlen(TYPE_RECURSIF))
1294
+                );
1295
+                $result->param = $args;
1296
+            }
1297
+        }
1298
+
1299
+        $descr['id_mere_contexte'] = $id_boucle;
1300
+        $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder);
1301
+        // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre
1302
+        // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle
1303
+        // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite
1304
+        if (empty($boucles[$id_boucle])) {
1305
+            $boucles[$id_boucle] = null;
1306
+        }
1307
+        $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder);
1308
+        $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder);
1309
+        $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder);
1310
+        $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder);
1311
+        $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder);
1312
+
1313
+        // Prevenir le generateur de code que le squelette est faux
1314
+        if ($err_b) {
1315
+            $result->type_requete = false;
1316
+        }
1317
+
1318
+        // Verifier qu'il n'y a pas double definition
1319
+        // apres analyse des sous-parties (pas avant).
1320
+        if (!empty($boucles[$id_boucle])) {
1321
+            if ($boucles[$id_boucle]->type_requete !== false) {
1322
+                $err_b_d = [
1323
+                    'zbug_erreur_boucle_double',
1324
+                    ['id' => $id_boucle]
1325
+                ];
1326
+                erreur_squelette($err_b_d, $result);
1327
+                // Prevenir le generateur de code que le squelette est faux
1328
+                $boucles[$id_boucle]->type_requete = false;
1329
+            }
1330
+        } else {
1331
+            $boucles[$id_boucle] = $result;
1332
+        }
1333
+
1334
+        // remplacer la boucle par un placeholder qui compte le meme nombre de lignes
1335
+        $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte);
1336
+        $longueur_boucle = $pos_courante - $boucle['debut_boucle'];
1337
+        $texte = substr_replace((string) $texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle);
1338
+        $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder);
1339
+
1340
+        // phraser la partie avant le debut de la boucle
1341
+        #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res);
1342
+        #$all_res[] = &$boucles[$id_boucle];
1343
+
1344
+        $ligne_debut_texte = $ligne_suite;
1345
+        $pos_debut_texte = $pos_courante;
1346
+    }
1347
+
1348
+    return phraser_champs_etendus($texte, $ligne_debut_initial, $all_res);
1349 1349
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -55,19 +55,19 @@  discard block
 block discarded – undo
55 55
  * Nom d'une balise #TOTO
56 56
  *
57 57
  * Écriture alambiquée pour rester compatible avec les hexadecimaux des vieux squelettes */
58
-define('NOM_DE_CHAMP', '#((' . NOM_DE_BOUCLE . "):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)\b(\*{0,2})");
58
+define('NOM_DE_CHAMP', '#(('.NOM_DE_BOUCLE."):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)\b(\*{0,2})");
59 59
 /** Balise complète [...(#TOTO) ... ] */
60
-define('CHAMP_ETENDU', '/\[([^\[]*?)\(' . NOM_DE_CHAMP . '([^)]*\)[^]]*)\]/S');
60
+define('CHAMP_ETENDU', '/\[([^\[]*?)\('.NOM_DE_CHAMP.'([^)]*\)[^]]*)\]/S');
61 61
 
62 62
 define('BALISE_INCLURE', '/<INCLU[DR]E[[:space:]]*(\(([^)]*)\))?/S');
63 63
 define('BALISE_POLYGLOTTE', ',<multi>(.*)</multi>,Uims');
64 64
 define('BALISE_IDIOMES', ',<:(([a-z0-9_]+):)?([a-z0-9_]*)({([^\|=>]*=[^\|>]*)})?((\|[^>]*)?:/?>),iS');
65
-define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*((' . NOM_DE_CHAMP . '[{][^}]*})?[^,]*)\s*,?\s*@s');
65
+define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*(('.NOM_DE_CHAMP.'[{][^}]*})?[^,]*)\s*,?\s*@s');
66 66
 
67 67
 /** Champ sql dans parenthèse ex: (id_article) */
68 68
 define('SQL_ARGS', '(\([^)]*\))');
69 69
 /** Fonction SQL sur un champ ex: SUM(visites) */
70
-define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_\/][A-Z_\/0-9.]*)' . SQL_ARGS . '?`?');
70
+define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_\/][A-Z_\/0-9.]*)'.SQL_ARGS.'?`?');
71 71
 
72 72
 /**
73 73
  * Parser les <INCLURE> dans le texte
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 
266 266
 	while (
267 267
 		(($p = strpos($texte, '#')) !== false)
268
-		&& preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match, PREG_OFFSET_CAPTURE, $p)
268
+		&& preg_match('/'.NOM_DE_CHAMP.'/S', $texte, $match, PREG_OFFSET_CAPTURE, $p)
269 269
 	) {
270 270
 		$poss = array_column($match, 1);
271 271
 		$match = array_column($match, 0);
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 			$collecte[] = $champ;
420 420
 			$args = ltrim($regs[count($regs) - 1]);
421 421
 		} else {
422
-			if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) {
422
+			if (!preg_match('/'.NOM_DE_CHAMP.'([{|])/', $arg, $r)) {
423 423
 				// 0 est un aveu d'impuissance. A completer
424 424
 				$arg = phraser_champs_exterieurs($arg, 0, $sep, $result);
425 425
 
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
  */
506 506
 function phraser_champs_exterieurs(string $texte, int $ligne, string $sep, array $nested_res): array {
507 507
 	$res = [];
508
-	$preg = ',^%' . preg_quote($sep, ',') . '([0-9]+)(\n*)@,';
508
+	$preg = ',^%'.preg_quote($sep, ',').'([0-9]+)(\n*)@,';
509 509
 	while (($p = strpos($texte, "%$sep")) !== false) {
510 510
 		$suite = substr($texte, $p);
511 511
 		if (!preg_match($preg, $suite, $m)) {
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
 			$pos_apres = 0;
581 581
 			$champs_trouves = phraser_args($match[7], ')', $sep, $champs_trouves, $champ, $pos_apres);
582 582
 			phraser_vieux($champ);
583
-			$champ->avant =	phraser_champs_exterieurs($match[1], $nbl, $sep, $champs_trouves);
583
+			$champ->avant = phraser_champs_exterieurs($match[1], $nbl, $sep, $champs_trouves);
584 584
 			$apres = substr($match[7], $pos_apres + 1);
585 585
 
586 586
 			$nbl_debut_champ = 0;
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
 			$j = count($champs_trouves) - 1;
597 597
 			// on remplace ce champ par un placeholder
598 598
 			// ajouter $nbl_champ retour ligne pour que la partie conserve le nombre de lignes lors des itérations suivantes
599
-			$parties[] = ($t = "%{$sep}{$j}" . str_repeat("\n", $nbl_champ) . '@');
599
+			$parties[] = ($t = "%{$sep}{$j}".str_repeat("\n", $nbl_champ).'@');
600 600
 			$nbl += $nbl_champ;
601 601
 
602 602
 			$texte = substr($texte, $poss[0] + strlen($match[0]));
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
 		// si on a trouvé des morceaux, il faut recommencer
607 607
 		if (count($parties)) {
608 608
 			// reprenons tous les morceaux qu'on a mis de côté car ne matchant pas (encore)
609
-			$texte = implode('', $parties) . $texte;
609
+			$texte = implode('', $parties).$texte;
610 610
 		}
611 611
 	} while (count($parties));
612 612
 
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
 					// une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"}
693 693
 					if (preg_match(',^(["\'])(.*)\1$,', $m[4])) {
694 694
 						$c = null;
695
-						eval('$c = ' . $m[4] . ';');
695
+						eval('$c = '.$m[4].';');
696 696
 						if (isset($c)) {
697 697
 							$m[4] = $c;
698 698
 						}
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
 					if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', (string) $param, $m)) {
773 773
 						$crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', '');
774 774
 					} elseif (
775
-						preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC .
775
+						preg_match(',^([!]?)('.CHAMP_SQL_PLUS_FONC.
776 776
 						')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', (string) $param, $m)
777 777
 					) {
778 778
 						$a2 = trim($m[8]);
@@ -789,8 +789,8 @@  discard block
 block discarded – undo
789 789
 						);
790 790
 						$crit->exclus = $m[1];
791 791
 					} elseif (
792
-						preg_match('/^([!]?)\s*(' .
793
-						CHAMP_SQL_PLUS_FONC .
792
+						preg_match('/^([!]?)\s*('.
793
+						CHAMP_SQL_PLUS_FONC.
794 794
 						')\s*(\??)(.*)$/is', (string) $param, $m)
795 795
 					) {
796 796
 						// contient aussi les comparaisons implicites !
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
 			}
929 929
 
930 930
 			// trouver sa position de depart reelle : au <Bxx> ou au <BBxx>
931
-			$precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>';
931
+			$precond_boucle = BALISE_PRECOND_BOUCLE.$id_boucle.'>';
932 932
 			$pos_precond = strpos((string) $texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme);
933 933
 			if (
934 934
 				$pos_precond !== false
@@ -939,7 +939,7 @@  discard block
 block discarded – undo
939 939
 				$boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle);
940 940
 			}
941 941
 
942
-			$preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>';
942
+			$preaff_boucle = BALISE_PREAFF_BOUCLE.$id_boucle.'>';
943 943
 			$pos_preaff = strpos((string) $texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme);
944 944
 			if (
945 945
 				$pos_preaff !== false
@@ -988,13 +988,13 @@  discard block
 block discarded – undo
988 988
 	$pos_anonyme_next = null;
989 989
 	// si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme
990 990
 	if (!strlen((string) $id_boucle)) {
991
-		$pos_anonyme_next = strpos((string) $texte, BALISE_BOUCLE . '(', $pos_courante);
991
+		$pos_anonyme_next = strpos((string) $texte, BALISE_BOUCLE.'(', $pos_courante);
992 992
 	}
993 993
 
994 994
 	//
995 995
 	// 1. Recuperer la partie conditionnelle apres
996 996
 	//
997
-	$apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>';
997
+	$apres_boucle = BALISE_POSTCOND_BOUCLE.$id_boucle.'>';
998 998
 	$pos_apres = strpos((string) $texte, $apres_boucle, $pos_courante);
999 999
 	if (
1000 1000
 		$pos_apres !== false
@@ -1003,13 +1003,13 @@  discard block
 block discarded – undo
1003 1003
 		$boucle['pos_postcond'] = $pos_apres;
1004 1004
 		$pos_apres += strlen($apres_boucle);
1005 1005
 		$boucle['pos_postcond_inside'] = $pos_apres;
1006
-		$pos_courante = $pos_apres ;
1006
+		$pos_courante = $pos_apres;
1007 1007
 	}
1008 1008
 
1009 1009
 	//
1010 1010
 	// 2. Récuperer la partie alternative apres
1011 1011
 	//
1012
-	$altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>';
1012
+	$altern_boucle = BALISE_ALT_BOUCLE.$id_boucle.'>';
1013 1013
 	$pos_altern = strpos((string) $texte, $altern_boucle, $pos_courante);
1014 1014
 	if (
1015 1015
 		$pos_altern !== false
@@ -1024,7 +1024,7 @@  discard block
 block discarded – undo
1024 1024
 	//
1025 1025
 	// 3. Recuperer la partie footer non alternative
1026 1026
 	//
1027
-	$postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>';
1027
+	$postaff_boucle = BALISE_POSTAFF_BOUCLE.$id_boucle.'>';
1028 1028
 	$pos_postaff = strpos((string) $texte, $postaff_boucle, $pos_courante);
1029 1029
 	if (
1030 1030
 		$pos_postaff !== false
@@ -1033,7 +1033,7 @@  discard block
 block discarded – undo
1033 1033
 		$boucle['pos_postaff'] = $pos_postaff;
1034 1034
 		$pos_postaff += strlen($postaff_boucle);
1035 1035
 		$boucle['pos_postaff_inside'] = $pos_postaff;
1036
-		$pos_courante = $pos_postaff ;
1036
+		$pos_courante = $pos_postaff;
1037 1037
 	}
1038 1038
 
1039 1039
 	return $boucle;
@@ -1069,7 +1069,7 @@  discard block
 block discarded – undo
1069 1069
  * @return string
1070 1070
  */
1071 1071
 function public_generer_boucle_placeholder(string $id_boucle, &$boucle, string $boucle_placeholder, int $nb_lignes): string {
1072
-	$placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']';
1072
+	$placeholder = "[(#{$boucle_placeholder}{".$id_boucle.'})'.str_pad('', $nb_lignes, "\n").']';
1073 1073
 	//memoriser la boucle a reinjecter
1074 1074
 	$id_boucle = "$id_boucle";
1075 1075
 	phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle);
@@ -1090,7 +1090,7 @@  discard block
 block discarded – undo
1090 1090
 	// definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette
1091 1091
 	if (is_null($boucle_placeholder)) {
1092 1092
 		do {
1093
-			$boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid()));
1093
+			$boucle_placeholder = 'BOUCLE_PLACEHOLDER_'.strtoupper(md5(uniqid()));
1094 1094
 		} while (str_contains((string) $texte, $boucle_placeholder));
1095 1095
 	}
1096 1096
 
@@ -1110,7 +1110,7 @@  discard block
 block discarded – undo
1110 1110
 
1111 1111
 		// boucle anonyme ?
1112 1112
 		if (!strlen((string) $id_boucle)) {
1113
-			$id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8);
1113
+			$id_boucle = '_anon_L'.$ligne_milieu.'_'.substr(md5('anonyme:'.$id_parent.':'.json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8);
1114 1114
 		}
1115 1115
 
1116 1116
 		$pos_debut_boucle = $pos_courante;
@@ -1123,7 +1123,7 @@  discard block
 block discarded – undo
1123 1123
 
1124 1124
 			$pos_avant = $boucle['pos_precond_inside'];
1125 1125
 			$result->avant = substr((string) $texte, $pos_avant, $pos_courante - $pos_avant);
1126
-			$ligne_avant = $ligne_debut_texte +  public_compte_ligne($texte, $pos_debut_texte, $pos_avant);
1126
+			$ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant);
1127 1127
 		}
1128 1128
 
1129 1129
 		// Regarder si on a une partie inconditionnelle avant <BB_xxx>
@@ -1132,7 +1132,7 @@  discard block
 block discarded – undo
1132 1132
 
1133 1133
 			$pos_preaff = $boucle['pos_preaff_inside'];
1134 1134
 			$result->preaff = substr((string) $texte, $pos_preaff, $end_preaff - $pos_preaff);
1135
-			$ligne_preaff = $ligne_debut_texte +  public_compte_ligne($texte, $pos_debut_texte, $pos_preaff);
1135
+			$ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff);
1136 1136
 		}
1137 1137
 
1138 1138
 		$result->id_boucle = $id_boucle;
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
 		} else {
1191 1191
 			$pos_milieu += 1;
1192 1192
 
1193
-			$fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>';
1193
+			$fin_boucle = BALISE_FIN_BOUCLE.$id_boucle_search.'>';
1194 1194
 			$pos_fin = strpos((string) $texte, $fin_boucle, $pos_milieu);
1195 1195
 			if ($pos_fin === false) {
1196 1196
 				$err_b = [
@@ -1203,7 +1203,7 @@  discard block
 block discarded – undo
1203 1203
 			else {
1204 1204
 				// verifier une eventuelle imbrication d'une boucle homonyme
1205 1205
 				// (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur)
1206
-				$search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '(';
1206
+				$search_debut_boucle = BALISE_BOUCLE.$id_boucle_search.'(';
1207 1207
 				$search_from = $pos_milieu;
1208 1208
 				$nb_open = 1;
1209 1209
 				$nb_close = 1;
@@ -1243,7 +1243,7 @@  discard block
 block discarded – undo
1243 1243
 		if ($boucle['pos_postcond']) {
1244 1244
 			$result->apres = substr((string) $texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante);
1245 1245
 			$ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']);
1246
-			$pos_courante = $boucle['pos_postcond_inside'] ;
1246
+			$pos_courante = $boucle['pos_postcond_inside'];
1247 1247
 		}
1248 1248
 
1249 1249
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -908,8 +908,7 @@  discard block
 block discarded – undo
908 908
 			erreur_squelette($err_b, $result);
909 909
 
910 910
 			continue;
911
-		}
912
-		else {
911
+		} else {
913 912
 			$boucle = [
914 913
 				'id_boucle' => $id_boucle,
915 914
 				'id_boucle_err' => $id_boucle,
@@ -1049,8 +1048,7 @@  discard block
 block discarded – undo
1049 1048
 	// si c'est un appel pour memoriser une boucle, memorisons la
1050 1049
 	if (is_string($champ) && !empty($boucle_placeholder) && !empty($boucle)) {
1051 1050
 		$boucles_connues[$boucle_placeholder][$champ] = &$boucle;
1052
-	}
1053
-	else {
1051
+	} else {
1054 1052
 		if (!empty($champ->nom_champ) && !empty($boucles_connues[$champ->nom_champ])) {
1055 1053
 			$placeholder = $champ->nom_champ;
1056 1054
 			$id = reset($champ->param[0][1]);
@@ -1199,8 +1197,7 @@  discard block
 block discarded – undo
1199 1197
 				];
1200 1198
 				erreur_squelette($err_b, $result);
1201 1199
 				$pos_courante += strlen($fin_boucle);
1202
-			}
1203
-			else {
1200
+			} else {
1204 1201
 				// verifier une eventuelle imbrication d'une boucle homonyme
1205 1202
 				// (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur)
1206 1203
 				$search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '(';
Please login to merge, or discard this patch.