Completed
Push — master ( 72d0e2...cf43de )
by cam
01:25
created
ecrire/public/sandbox.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  **/
24 24
 
25 25
 if (!defined('_ECRIRE_INC_VERSION')) {
26
-	return;
26
+    return;
27 27
 }
28 28
 
29 29
 /**
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
  *     texte
42 42
  */
43 43
 function sandbox_composer_texte($texte, &$p) {
44
-	$code = "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'";
44
+    $code = "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'";
45 45
 
46
-	return $code;
46
+    return $code;
47 47
 }
48 48
 
49 49
 
@@ -59,42 +59,42 @@  discard block
 block discarded – undo
59 59
  * @return string
60 60
  */
61 61
 function sandbox_composer_filtre($fonc, $code, $arglist, &$p, $nb_arg_droite = 1000): string {
62
-	if (isset($GLOBALS['spip_matrice'][$fonc])) {
63
-		$code = "filtrer('$fonc',$code$arglist)";
64
-	}
65
-
66
-	// le filtre est defini sous forme de fonction ou de methode
67
-	// par ex. dans inc_texte, inc_filtres ou mes_fonctions
68
-	elseif ($f = chercher_filtre($fonc)) {
69
-		// cas particulier : le filtre |set doit acceder a la $Pile
70
-		// proto: filtre_set(&$Pile, $val, $args...)
71
-		if (strpbrk($f, ':')) { // Class::method
72
-			$refl = new ReflectionMethod($f);
73
-		} else {
74
-			$refl = new ReflectionFunction($f);
75
-		}
76
-		$refs = $refl->getParameters();
77
-		if (isset($refs[0]) and $refs[0]->name == 'Pile') {
78
-			$code = "$f(\$Pile,$code$arglist)";
79
-			$nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile
80
-		} else {
81
-			$code = "$f($code$arglist)";
82
-			$nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre
83
-		}
84
-		$nb_args_f = $nb_arg_gauche + $nb_arg_droite;
85
-		$min_f = $refl->getNumberOfRequiredParameters();
86
-		if (($nb_args_f < $min_f)) {
87
-			$msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f];
88
-			erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p);
89
-		}
90
-	}
91
-	// le filtre n'existe pas,
92
-	// on le notifie
93
-	else {
94
-		erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p);
95
-	}
96
-
97
-	return $code;
62
+    if (isset($GLOBALS['spip_matrice'][$fonc])) {
63
+        $code = "filtrer('$fonc',$code$arglist)";
64
+    }
65
+
66
+    // le filtre est defini sous forme de fonction ou de methode
67
+    // par ex. dans inc_texte, inc_filtres ou mes_fonctions
68
+    elseif ($f = chercher_filtre($fonc)) {
69
+        // cas particulier : le filtre |set doit acceder a la $Pile
70
+        // proto: filtre_set(&$Pile, $val, $args...)
71
+        if (strpbrk($f, ':')) { // Class::method
72
+            $refl = new ReflectionMethod($f);
73
+        } else {
74
+            $refl = new ReflectionFunction($f);
75
+        }
76
+        $refs = $refl->getParameters();
77
+        if (isset($refs[0]) and $refs[0]->name == 'Pile') {
78
+            $code = "$f(\$Pile,$code$arglist)";
79
+            $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile
80
+        } else {
81
+            $code = "$f($code$arglist)";
82
+            $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre
83
+        }
84
+        $nb_args_f = $nb_arg_gauche + $nb_arg_droite;
85
+        $min_f = $refl->getNumberOfRequiredParameters();
86
+        if (($nb_args_f < $min_f)) {
87
+            $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f];
88
+            erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p);
89
+        }
90
+    }
91
+    // le filtre n'existe pas,
92
+    // on le notifie
93
+    else {
94
+        erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p);
95
+    }
96
+
97
+    return $code;
98 98
 }
99 99
 
100 100
 // Calculer un <INCLURE(xx.php)>
@@ -117,15 +117,15 @@  discard block
 block discarded – undo
117 117
  * @return string
118 118
  */
119 119
 function sandbox_composer_inclure_php($fichier, &$p, $_contexte) {
120
-	$compil = texte_script(memoriser_contexte_compil($p));
121
-	// si inexistant, on essaiera a l'execution
122
-	if ($path = find_in_path($fichier)) {
123
-		$path = "\"$path\"";
124
-	} else {
125
-		$path = "find_in_path(\"$fichier\")";
126
-	}
127
-
128
-	return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte);
120
+    $compil = texte_script(memoriser_contexte_compil($p));
121
+    // si inexistant, on essaiera a l'execution
122
+    if ($path = find_in_path($fichier)) {
123
+        $path = "\"$path\"";
124
+    } else {
125
+        $path = "find_in_path(\"$fichier\")";
126
+    }
127
+
128
+    return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte);
129 129
 }
130 130
 
131 131
 /**
@@ -137,20 +137,20 @@  discard block
 block discarded – undo
137 137
  * @return string
138 138
  */
139 139
 function sandbox_composer_interdire_scripts($code, &$p) {
140
-	// Securite
141
-	if (
142
-		$p->interdire_scripts
143
-		and $p->etoile != '**'
144
-	) {
145
-		if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) {
146
-			$code = "interdire_scripts($code)";
147
-		} else {
148
-			$code = interdire_scripts($r[2]);
149
-			$code = "sinon(interdire_scripts($r[1]),'$code')";
150
-		}
151
-	}
152
-
153
-	return $code;
140
+    // Securite
141
+    if (
142
+        $p->interdire_scripts
143
+        and $p->etoile != '**'
144
+    ) {
145
+        if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) {
146
+            $code = "interdire_scripts($code)";
147
+        } else {
148
+            $code = interdire_scripts($r[2]);
149
+            $code = "sinon(interdire_scripts($r[1]),'$code')";
150
+        }
151
+    }
152
+
153
+    return $code;
154 154
 }
155 155
 
156 156
 
@@ -169,30 +169,30 @@  discard block
 block discarded – undo
169 169
  * @return mixed|string
170 170
  */
171 171
 function sandbox_filtrer_squelette($skel, $corps, $filtres) {
172
-	$series_filtres = func_get_args();
173
-	array_shift($series_filtres);// skel
174
-	array_shift($series_filtres);// corps
175
-
176
-	// proteger les <INCLUDE> et tous les morceaux de php licites
177
-	if ($skel['process_ins'] == 'php') {
178
-		$corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps);
179
-	}
180
-
181
-	// recuperer les couples de remplacement
182
-	$replace = echapper_php_callback();
183
-
184
-	foreach ($series_filtres as $filtres) {
185
-		if (is_countable($filtres) ? count($filtres) : 0) {
186
-			foreach ($filtres as $filtre) {
187
-				if ($filtre and $f = chercher_filtre($filtre)) {
188
-					$corps = $f($corps);
189
-				}
190
-			}
191
-		}
192
-	}
193
-
194
-	// restaurer les echappements
195
-	return str_replace($replace[0], $replace[1], $corps);
172
+    $series_filtres = func_get_args();
173
+    array_shift($series_filtres);// skel
174
+    array_shift($series_filtres);// corps
175
+
176
+    // proteger les <INCLUDE> et tous les morceaux de php licites
177
+    if ($skel['process_ins'] == 'php') {
178
+        $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps);
179
+    }
180
+
181
+    // recuperer les couples de remplacement
182
+    $replace = echapper_php_callback();
183
+
184
+    foreach ($series_filtres as $filtres) {
185
+        if (is_countable($filtres) ? count($filtres) : 0) {
186
+            foreach ($filtres as $filtre) {
187
+                if ($filtre and $f = chercher_filtre($filtre)) {
188
+                    $corps = $f($corps);
189
+                }
190
+            }
191
+        }
192
+    }
193
+
194
+    // restaurer les echappements
195
+    return str_replace($replace[0], $replace[1], $corps);
196 196
 }
197 197
 
198 198
 
@@ -211,21 +211,21 @@  discard block
 block discarded – undo
211 211
  *     - array : Liste( liste des codes PHP, liste des substitutions )
212 212
  **/
213 213
 function echapper_php_callback($r = null) {
214
-	static $src = [];
215
-	static $dst = [];
214
+    static $src = [];
215
+    static $dst = [];
216 216
 
217
-	// si on recoit un tableau, on est en mode echappement
218
-	// on enregistre le code a echapper dans dst, et le code echappe dans src
219
-	if (is_array($r)) {
220
-		$dst[] = $r[0];
217
+    // si on recoit un tableau, on est en mode echappement
218
+    // on enregistre le code a echapper dans dst, et le code echappe dans src
219
+    if (is_array($r)) {
220
+        $dst[] = $r[0];
221 221
 
222
-		return $src[] = '___' . md5($r[0]) . '___';
223
-	}
222
+        return $src[] = '___' . md5($r[0]) . '___';
223
+    }
224 224
 
225
-	// si on recoit pas un tableau, on renvoit les couples de substitution
226
-	// et on RAZ les remplacements
227
-	$r = [$src, $dst];
228
-	$src = $dst = [];
225
+    // si on recoit pas un tableau, on renvoit les couples de substitution
226
+    // et on RAZ les remplacements
227
+    $r = [$src, $dst];
228
+    $src = $dst = [];
229 229
 
230
-	return $r;
230
+    return $r;
231 231
 }
Please login to merge, or discard this patch.
ecrire/public/phraser_html.php 1 patch
Indentation   +1032 added lines, -1032 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
  **/
29 29
 
30 30
 if (!defined('_ECRIRE_INC_VERSION')) {
31
-	return;
31
+    return;
32 32
 }
33 33
 
34 34
 /** Début de la partie principale d'une boucle */
@@ -72,82 +72,82 @@  discard block
 block discarded – undo
72 72
 
73 73
 function phraser_inclure($texte, $ligne, $result) {
74 74
 
75
-	while (preg_match(BALISE_INCLURE, $texte, $match)) {
76
-		$match = array_pad($match, 3, null);
77
-		$p = strpos($texte, (string) $match[0]);
78
-		$debut = substr($texte, 0, $p);
79
-		if ($p) {
80
-			$result = phraser_idiomes($debut, $ligne, $result);
81
-		}
82
-		$ligne += substr_count($debut, "\n");
83
-		$champ = new Inclure();
84
-		$champ->ligne = $ligne;
85
-		$ligne += substr_count($match[0], "\n");
86
-		$fichier = $match[2];
87
-		# assurer ici la migration .php3 => .php
88
-		# et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue
89
-		if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) {
90
-			$fichier = $r[1];
91
-		}
92
-		$champ->texte = ($fichier !== 'page.php') ? $fichier : '';
93
-		$texte = substr($texte, $p + strlen($match[0]));
94
-		// on assimile {var=val} a une liste de un argument sans fonction
95
-		$pos_apres = 0;
96
-		phraser_args($texte, '/>', '', $result, $champ, $pos_apres);
97
-		if (!$champ->texte or (is_countable($champ->param) ? count($champ->param) : 0) > 1) {
98
-			if (!function_exists('normaliser_inclure')) {
99
-				include_spip('public/normaliser');
100
-			}
101
-			normaliser_inclure($champ);
102
-		}
103
-		$texte = substr($texte, strpos($texte, '>', $pos_apres) + 1);
104
-		$texte = preg_replace(',^</INCLU[DR]E>,', '', $texte);
105
-		$result[] = $champ;
106
-	}
107
-
108
-	return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result));
75
+    while (preg_match(BALISE_INCLURE, $texte, $match)) {
76
+        $match = array_pad($match, 3, null);
77
+        $p = strpos($texte, (string) $match[0]);
78
+        $debut = substr($texte, 0, $p);
79
+        if ($p) {
80
+            $result = phraser_idiomes($debut, $ligne, $result);
81
+        }
82
+        $ligne += substr_count($debut, "\n");
83
+        $champ = new Inclure();
84
+        $champ->ligne = $ligne;
85
+        $ligne += substr_count($match[0], "\n");
86
+        $fichier = $match[2];
87
+        # assurer ici la migration .php3 => .php
88
+        # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue
89
+        if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) {
90
+            $fichier = $r[1];
91
+        }
92
+        $champ->texte = ($fichier !== 'page.php') ? $fichier : '';
93
+        $texte = substr($texte, $p + strlen($match[0]));
94
+        // on assimile {var=val} a une liste de un argument sans fonction
95
+        $pos_apres = 0;
96
+        phraser_args($texte, '/>', '', $result, $champ, $pos_apres);
97
+        if (!$champ->texte or (is_countable($champ->param) ? count($champ->param) : 0) > 1) {
98
+            if (!function_exists('normaliser_inclure')) {
99
+                include_spip('public/normaliser');
100
+            }
101
+            normaliser_inclure($champ);
102
+        }
103
+        $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1);
104
+        $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte);
105
+        $result[] = $champ;
106
+    }
107
+
108
+    return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result));
109 109
 }
110 110
 
111 111
 function phraser_polyglotte($texte, $ligne, $result) {
112 112
 
113
-	if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) {
114
-		foreach ($m as $match) {
115
-			$p = strpos($texte, (string) $match[0]);
116
-			$debut = substr($texte, 0, $p);
117
-			if ($p) {
118
-				$champ = new Texte();
119
-				$champ->texte = $debut;
120
-				$champ->ligne = $ligne;
121
-				$result[] = $champ;
122
-				$ligne += substr_count($champ->texte, "\n");
123
-			}
124
-
125
-			$champ = new Polyglotte();
126
-			$champ->ligne = $ligne;
127
-			$ligne += substr_count($match[0], "\n");
128
-			$lang = '';
129
-			$bloc = $match[1];
130
-			$texte = substr($texte, $p + strlen($match[0]));
131
-			while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) {
132
-				$trad = $regs[1];
133
-				if ($trad or $lang) {
134
-					$champ->traductions[$lang] = $trad;
135
-				}
136
-				$lang = $regs[2];
137
-				$bloc = $regs[3];
138
-			}
139
-			$champ->traductions[$lang] = $bloc;
140
-			$result[] = $champ;
141
-		}
142
-	}
143
-	if ($texte !== '') {
144
-		$champ = new Texte();
145
-		$champ->texte = $texte;
146
-		$champ->ligne = $ligne;
147
-		$result[] = $champ;
148
-	}
149
-
150
-	return $result;
113
+    if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) {
114
+        foreach ($m as $match) {
115
+            $p = strpos($texte, (string) $match[0]);
116
+            $debut = substr($texte, 0, $p);
117
+            if ($p) {
118
+                $champ = new Texte();
119
+                $champ->texte = $debut;
120
+                $champ->ligne = $ligne;
121
+                $result[] = $champ;
122
+                $ligne += substr_count($champ->texte, "\n");
123
+            }
124
+
125
+            $champ = new Polyglotte();
126
+            $champ->ligne = $ligne;
127
+            $ligne += substr_count($match[0], "\n");
128
+            $lang = '';
129
+            $bloc = $match[1];
130
+            $texte = substr($texte, $p + strlen($match[0]));
131
+            while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) {
132
+                $trad = $regs[1];
133
+                if ($trad or $lang) {
134
+                    $champ->traductions[$lang] = $trad;
135
+                }
136
+                $lang = $regs[2];
137
+                $bloc = $regs[3];
138
+            }
139
+            $champ->traductions[$lang] = $bloc;
140
+            $result[] = $champ;
141
+        }
142
+    }
143
+    if ($texte !== '') {
144
+        $champ = new Texte();
145
+        $champ->texte = $texte;
146
+        $champ->ligne = $ligne;
147
+        $result[] = $champ;
148
+    }
149
+
150
+    return $result;
151 151
 }
152 152
 
153 153
 
@@ -169,43 +169,43 @@  discard block
 block discarded – undo
169 169
  * @return array
170 170
  **/
171 171
 function phraser_idiomes($texte, $ligne, $result) {
172
-	while (preg_match(BALISE_IDIOMES, $texte, $match)) {
173
-		$match = array_pad($match, 8, null);
174
-		$p = strpos($texte, (string) $match[0]);
175
-		$ko = (!$match[3] && ($match[5][0] !== '='));
176
-		$debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0));
177
-		if ($debut) {
178
-			$result = phraser_champs($debut, $ligne, $result);
179
-		}
180
-		$texte = substr($texte, $p + strlen($match[0]));
181
-		$ligne += substr_count($debut, "\n");
182
-		if ($ko) {
183
-			continue;
184
-		} // faux idiome
185
-		$champ = new Idiome();
186
-		$champ->ligne = $ligne;
187
-		$ligne += substr_count($match[0], "\n");
188
-		// Stocker les arguments de la balise de traduction
189
-		$args = [];
190
-		$largs = $match[5];
191
-		while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) {
192
-			$args[$r[1]] = phraser_champs($r[2], 0, []);
193
-			$largs = substr($largs, strlen($r[0]));
194
-		}
195
-		$champ->arg = $args;
196
-		$champ->nom_champ = strtolower($match[3]);
197
-		$champ->module = $match[2];
198
-		// pas d'imbrication pour les filtres sur langue
199
-		$pos_apres = 0;
200
-		phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres);
201
-		$champ->apres = substr($match[7] ?? '', $pos_apres);
202
-		$result[] = $champ;
203
-	}
204
-	if ($texte !== '') {
205
-		$result = phraser_champs($texte, $ligne, $result);
206
-	}
207
-
208
-	return $result;
172
+    while (preg_match(BALISE_IDIOMES, $texte, $match)) {
173
+        $match = array_pad($match, 8, null);
174
+        $p = strpos($texte, (string) $match[0]);
175
+        $ko = (!$match[3] && ($match[5][0] !== '='));
176
+        $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0));
177
+        if ($debut) {
178
+            $result = phraser_champs($debut, $ligne, $result);
179
+        }
180
+        $texte = substr($texte, $p + strlen($match[0]));
181
+        $ligne += substr_count($debut, "\n");
182
+        if ($ko) {
183
+            continue;
184
+        } // faux idiome
185
+        $champ = new Idiome();
186
+        $champ->ligne = $ligne;
187
+        $ligne += substr_count($match[0], "\n");
188
+        // Stocker les arguments de la balise de traduction
189
+        $args = [];
190
+        $largs = $match[5];
191
+        while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) {
192
+            $args[$r[1]] = phraser_champs($r[2], 0, []);
193
+            $largs = substr($largs, strlen($r[0]));
194
+        }
195
+        $champ->arg = $args;
196
+        $champ->nom_champ = strtolower($match[3]);
197
+        $champ->module = $match[2];
198
+        // pas d'imbrication pour les filtres sur langue
199
+        $pos_apres = 0;
200
+        phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres);
201
+        $champ->apres = substr($match[7] ?? '', $pos_apres);
202
+        $result[] = $champ;
203
+    }
204
+    if ($texte !== '') {
205
+        $result = phraser_champs($texte, $ligne, $result);
206
+    }
207
+
208
+    return $result;
209 209
 }
210 210
 
211 211
 /**
@@ -223,47 +223,47 @@  discard block
 block discarded – undo
223 223
  * @return array
224 224
  **/
225 225
 function phraser_champs($texte, $ligne, $result) {
226
-	while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) {
227
-		$p = strpos($texte, (string) $match[0]);
228
-		// texte après la balise
229
-		$suite = substr($texte, $p + strlen($match[0]));
230
-
231
-		$debut = substr($texte, 0, $p);
232
-		if ($p) {
233
-			$result = phraser_polyglotte($debut, $ligne, $result);
234
-		}
235
-		$ligne += substr_count($debut, "\n");
236
-		$champ = new Champ();
237
-		$champ->ligne = $ligne;
238
-		$ligne += substr_count($match[0], "\n");
239
-		$champ->nom_boucle = $match[2];
240
-		$champ->nom_champ = $match[3];
241
-		$champ->etoile = $match[5];
242
-
243
-		if ($suite and $suite[0] == '{') {
244
-			phraser_arg($suite, '', [], $champ);
245
-			// ce ltrim est une ereur de conception
246
-			// mais on le conserve par souci de compatibilite
247
-			$texte = ltrim($suite);
248
-			// Il faudrait le normaliser dans l'arbre de syntaxe abstraite
249
-			// pour faire sauter ce cas particulier a la decompilation.
250
-			/* Ce qui suit est malheureusement incomplet pour cela:
226
+    while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) {
227
+        $p = strpos($texte, (string) $match[0]);
228
+        // texte après la balise
229
+        $suite = substr($texte, $p + strlen($match[0]));
230
+
231
+        $debut = substr($texte, 0, $p);
232
+        if ($p) {
233
+            $result = phraser_polyglotte($debut, $ligne, $result);
234
+        }
235
+        $ligne += substr_count($debut, "\n");
236
+        $champ = new Champ();
237
+        $champ->ligne = $ligne;
238
+        $ligne += substr_count($match[0], "\n");
239
+        $champ->nom_boucle = $match[2];
240
+        $champ->nom_champ = $match[3];
241
+        $champ->etoile = $match[5];
242
+
243
+        if ($suite and $suite[0] == '{') {
244
+            phraser_arg($suite, '', [], $champ);
245
+            // ce ltrim est une ereur de conception
246
+            // mais on le conserve par souci de compatibilite
247
+            $texte = ltrim($suite);
248
+            // Il faudrait le normaliser dans l'arbre de syntaxe abstraite
249
+            // pour faire sauter ce cas particulier a la decompilation.
250
+            /* Ce qui suit est malheureusement incomplet pour cela:
251 251
 			if ($n = (strlen($suite) - strlen($texte))) {
252 252
 				$champ->apres = array(new Texte);
253 253
 				$champ->apres[0]->texte = substr($suite,0,$n);
254 254
 			}
255 255
 			*/
256
-		} else {
257
-			$texte = $suite;
258
-		}
259
-		phraser_vieux($champ);
260
-		$result[] = $champ;
261
-	}
262
-	if ($texte !== '') {
263
-		$result = phraser_polyglotte($texte, $ligne, $result);
264
-	}
265
-
266
-	return $result;
256
+        } else {
257
+            $texte = $suite;
258
+        }
259
+        phraser_vieux($champ);
260
+        $result[] = $champ;
261
+    }
262
+    if ($texte !== '') {
263
+        $result = phraser_polyglotte($texte, $ligne, $result);
264
+    }
265
+
266
+    return $result;
267 267
 }
268 268
 
269 269
 // Gestion des imbrications:
@@ -272,15 +272,15 @@  discard block
 block discarded – undo
272 272
 // on recommence tant qu'il y a des [...] en substituant a l'appel suivant
273 273
 
274 274
 function phraser_champs_etendus($texte, $ligne, $result) {
275
-	if ($texte === '') {
276
-		return $result;
277
-	}
278
-	$sep = '##';
279
-	while (strpos($texte, (string) $sep) !== false) {
280
-		$sep .= '#';
281
-	}
282
-
283
-	return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, []));
275
+    if ($texte === '') {
276
+        return $result;
277
+    }
278
+    $sep = '##';
279
+    while (strpos($texte, (string) $sep) !== false) {
280
+        $sep .= '#';
281
+    }
282
+
283
+    return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, []));
284 284
 }
285 285
 
286 286
 /**
@@ -299,275 +299,275 @@  discard block
 block discarded – undo
299 299
  * @return array
300 300
  */
301 301
 function phraser_args(string $texte, $fin, $sep, $result, &$pointeur_champ, &$pos_debut) {
302
-	$length = strlen($texte);
303
-	while ($pos_debut < $length and trim($texte[$pos_debut]) === '') {
304
-		$pos_debut++;
305
-	}
306
-	while (($pos_debut < $length) && !str_contains($fin, $texte[$pos_debut])) {
307
-		// phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine
308
-		$st = substr($texte, $pos_debut);
309
-		$result = phraser_arg($st, $sep, $result, $pointeur_champ);
310
-		$pos_debut = $length - strlen($st);
311
-		while ($pos_debut < $length and trim($texte[$pos_debut]) === '') {
312
-			$pos_debut++;
313
-		}
314
-	}
315
-
316
-	return $result;
302
+    $length = strlen($texte);
303
+    while ($pos_debut < $length and trim($texte[$pos_debut]) === '') {
304
+        $pos_debut++;
305
+    }
306
+    while (($pos_debut < $length) && !str_contains($fin, $texte[$pos_debut])) {
307
+        // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine
308
+        $st = substr($texte, $pos_debut);
309
+        $result = phraser_arg($st, $sep, $result, $pointeur_champ);
310
+        $pos_debut = $length - strlen($st);
311
+        while ($pos_debut < $length and trim($texte[$pos_debut]) === '') {
312
+            $pos_debut++;
313
+        }
314
+    }
315
+
316
+    return $result;
317 317
 }
318 318
 
319 319
 function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) {
320
-	preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match);
321
-	$suite = ltrim($match[2]);
322
-	$fonc = trim($match[1]);
323
-	if ($fonc && $fonc[0] == '|') {
324
-		$fonc = ltrim(substr($fonc, 1));
325
-	}
326
-	$res = [$fonc];
327
-	$err_f = '';
328
-	// cas du filtre sans argument ou du critere /
329
-	if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) {
330
-		// si pas d'argument, alors il faut une fonction ou un double |
331
-		if (!$match[1]) {
332
-			$err_f = ['zbug_erreur_filtre', ['filtre' => $texte]];
333
-			erreur_squelette($err_f, $pointeur_champ);
334
-			$texte = '';
335
-		} else {
336
-			$texte = $suite;
337
-		}
338
-		if ($err_f) {
339
-			$pointeur_champ->param = false;
340
-		} elseif ($fonc !== '') {
341
-			$pointeur_champ->param[] = $res;
342
-		}
343
-		// pour les balises avec faux filtres qui boudent ce dur larbeur
344
-		$pointeur_champ->fonctions[] = [$fonc, ''];
345
-
346
-		return $result;
347
-	}
348
-	$args = ltrim(substr($suite, 1)); // virer le '(' initial
349
-	$collecte = [];
350
-	while ($args && $args[0] != '}') {
351
-		if ($args[0] == '"') {
352
-			preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs);
353
-		} elseif ($args[0] == "'") {
354
-			preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs);
355
-		} else {
356
-			preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs);
357
-			if (!isset($regs[2]) or !strlen($regs[2])) {
358
-				$err_f = ['zbug_erreur_filtre', ['filtre' => $args]];
359
-				erreur_squelette($err_f, $pointeur_champ);
360
-				$champ = new Texte();
361
-				$champ->apres = $champ->avant = $args = '';
362
-				break;
363
-			}
364
-		}
365
-		$arg = $regs[2];
366
-		if (trim($regs[1])) {
367
-			$champ = new Texte();
368
-			$champ->texte = $arg;
369
-			$champ->apres = $champ->avant = $regs[1];
370
-			$result[] = $champ;
371
-			$collecte[] = $champ;
372
-			$args = ltrim($regs[count($regs) - 1]);
373
-		} else {
374
-			if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) {
375
-				// 0 est un aveu d'impuissance. A completer
376
-				$arg = phraser_champs_exterieurs($arg, 0, $sep, $result);
377
-
378
-				$args = ltrim($regs[count($regs) - 1]);
379
-				$collecte = array_merge($collecte, $arg);
380
-				$result = array_merge($result, $arg);
381
-			} else {
382
-				$n = strpos($args, (string) $r[0]);
383
-				$pred = substr($args, 0, $n);
384
-				$par = ',}';
385
-				if (preg_match('/^(.*)\($/', $pred, $m)) {
386
-					$pred = $m[1];
387
-					$par = ')';
388
-				}
389
-				if ($pred) {
390
-					$champ = new Texte();
391
-					$champ->texte = $pred;
392
-					$champ->apres = $champ->avant = '';
393
-					$result[] = $champ;
394
-					$collecte[] = $champ;
395
-				}
396
-				$rec = substr($args, $n + strlen($r[0]) - 1);
397
-				$champ = new Champ();
398
-				$champ->nom_boucle = $r[2];
399
-				$champ->nom_champ = $r[3];
400
-				$champ->etoile = $r[5];
401
-				$next = $r[6];
402
-				while ($next == '{') {
403
-					phraser_arg($rec, $sep, [], $champ);
404
-					$args = ltrim($rec);
405
-					$next = $args[0] ?? '';
406
-				}
407
-				while ($next == '|') {
408
-					$pos_apres = 0;
409
-					phraser_args($rec, $par, $sep, [], $champ, $pos_apres);
410
-					$args = substr($rec, $pos_apres);
411
-					$next = $args[0] ?? '';
412
-				}
413
-				// Si erreur de syntaxe dans un sous-argument, propager.
414
-				if ($champ->param === false) {
415
-					$err_f = true;
416
-				} else {
417
-					phraser_vieux($champ);
418
-				}
419
-				if ($par == ')') {
420
-					$args = substr($args, 1);
421
-				}
422
-				$collecte[] = $champ;
423
-				$result[] = $champ;
424
-			}
425
-		}
426
-		if (isset($args[0]) and $args[0] == ',') {
427
-			$args = ltrim(substr($args, 1));
428
-			if ($collecte) {
429
-				$res[] = $collecte;
430
-				$collecte = [];
431
-			}
432
-		}
433
-	}
434
-	if ($collecte) {
435
-		$res[] = $collecte;
436
-		$collecte = [];
437
-	}
438
-	$texte = substr($args, 1);
439
-	$source = substr($suite, 0, strlen($suite) - strlen($texte));
440
-	// propager les erreurs, et ignorer les param vides
441
-	if ($pointeur_champ->param !== false) {
442
-		if ($err_f) {
443
-			$pointeur_champ->param = false;
444
-		} elseif ($fonc !== '' || count($res) > 1) {
445
-			$pointeur_champ->param[] = $res;
446
-		}
447
-	}
448
-	// pour les balises avec faux filtres qui boudent ce dur larbeur
449
-	$pointeur_champ->fonctions[] = [$fonc, $source];
450
-
451
-	return $result;
320
+    preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match);
321
+    $suite = ltrim($match[2]);
322
+    $fonc = trim($match[1]);
323
+    if ($fonc && $fonc[0] == '|') {
324
+        $fonc = ltrim(substr($fonc, 1));
325
+    }
326
+    $res = [$fonc];
327
+    $err_f = '';
328
+    // cas du filtre sans argument ou du critere /
329
+    if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) {
330
+        // si pas d'argument, alors il faut une fonction ou un double |
331
+        if (!$match[1]) {
332
+            $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]];
333
+            erreur_squelette($err_f, $pointeur_champ);
334
+            $texte = '';
335
+        } else {
336
+            $texte = $suite;
337
+        }
338
+        if ($err_f) {
339
+            $pointeur_champ->param = false;
340
+        } elseif ($fonc !== '') {
341
+            $pointeur_champ->param[] = $res;
342
+        }
343
+        // pour les balises avec faux filtres qui boudent ce dur larbeur
344
+        $pointeur_champ->fonctions[] = [$fonc, ''];
345
+
346
+        return $result;
347
+    }
348
+    $args = ltrim(substr($suite, 1)); // virer le '(' initial
349
+    $collecte = [];
350
+    while ($args && $args[0] != '}') {
351
+        if ($args[0] == '"') {
352
+            preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs);
353
+        } elseif ($args[0] == "'") {
354
+            preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs);
355
+        } else {
356
+            preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs);
357
+            if (!isset($regs[2]) or !strlen($regs[2])) {
358
+                $err_f = ['zbug_erreur_filtre', ['filtre' => $args]];
359
+                erreur_squelette($err_f, $pointeur_champ);
360
+                $champ = new Texte();
361
+                $champ->apres = $champ->avant = $args = '';
362
+                break;
363
+            }
364
+        }
365
+        $arg = $regs[2];
366
+        if (trim($regs[1])) {
367
+            $champ = new Texte();
368
+            $champ->texte = $arg;
369
+            $champ->apres = $champ->avant = $regs[1];
370
+            $result[] = $champ;
371
+            $collecte[] = $champ;
372
+            $args = ltrim($regs[count($regs) - 1]);
373
+        } else {
374
+            if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) {
375
+                // 0 est un aveu d'impuissance. A completer
376
+                $arg = phraser_champs_exterieurs($arg, 0, $sep, $result);
377
+
378
+                $args = ltrim($regs[count($regs) - 1]);
379
+                $collecte = array_merge($collecte, $arg);
380
+                $result = array_merge($result, $arg);
381
+            } else {
382
+                $n = strpos($args, (string) $r[0]);
383
+                $pred = substr($args, 0, $n);
384
+                $par = ',}';
385
+                if (preg_match('/^(.*)\($/', $pred, $m)) {
386
+                    $pred = $m[1];
387
+                    $par = ')';
388
+                }
389
+                if ($pred) {
390
+                    $champ = new Texte();
391
+                    $champ->texte = $pred;
392
+                    $champ->apres = $champ->avant = '';
393
+                    $result[] = $champ;
394
+                    $collecte[] = $champ;
395
+                }
396
+                $rec = substr($args, $n + strlen($r[0]) - 1);
397
+                $champ = new Champ();
398
+                $champ->nom_boucle = $r[2];
399
+                $champ->nom_champ = $r[3];
400
+                $champ->etoile = $r[5];
401
+                $next = $r[6];
402
+                while ($next == '{') {
403
+                    phraser_arg($rec, $sep, [], $champ);
404
+                    $args = ltrim($rec);
405
+                    $next = $args[0] ?? '';
406
+                }
407
+                while ($next == '|') {
408
+                    $pos_apres = 0;
409
+                    phraser_args($rec, $par, $sep, [], $champ, $pos_apres);
410
+                    $args = substr($rec, $pos_apres);
411
+                    $next = $args[0] ?? '';
412
+                }
413
+                // Si erreur de syntaxe dans un sous-argument, propager.
414
+                if ($champ->param === false) {
415
+                    $err_f = true;
416
+                } else {
417
+                    phraser_vieux($champ);
418
+                }
419
+                if ($par == ')') {
420
+                    $args = substr($args, 1);
421
+                }
422
+                $collecte[] = $champ;
423
+                $result[] = $champ;
424
+            }
425
+        }
426
+        if (isset($args[0]) and $args[0] == ',') {
427
+            $args = ltrim(substr($args, 1));
428
+            if ($collecte) {
429
+                $res[] = $collecte;
430
+                $collecte = [];
431
+            }
432
+        }
433
+    }
434
+    if ($collecte) {
435
+        $res[] = $collecte;
436
+        $collecte = [];
437
+    }
438
+    $texte = substr($args, 1);
439
+    $source = substr($suite, 0, strlen($suite) - strlen($texte));
440
+    // propager les erreurs, et ignorer les param vides
441
+    if ($pointeur_champ->param !== false) {
442
+        if ($err_f) {
443
+            $pointeur_champ->param = false;
444
+        } elseif ($fonc !== '' || count($res) > 1) {
445
+            $pointeur_champ->param[] = $res;
446
+        }
447
+    }
448
+    // pour les balises avec faux filtres qui boudent ce dur larbeur
449
+    $pointeur_champ->fonctions[] = [$fonc, $source];
450
+
451
+    return $result;
452 452
 }
453 453
 
454 454
 
455 455
 function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) {
456
-	$res = [];
457
-	while (($p = strpos($texte, (string) "%$sep")) !== false) {
458
-		if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) {
459
-			break;
460
-		}
461
-		$debut = substr($texte, 0, $p);
462
-		$texte = substr($texte, $p + strlen($m[0]));
463
-		if ($p) {
464
-			$res = phraser_inclure($debut, $ligne, $res);
465
-		}
466
-		$ligne += substr_count($debut, "\n");
467
-		$res[] = $nested[$m[1]];
468
-	}
469
-
470
-	return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res));
456
+    $res = [];
457
+    while (($p = strpos($texte, (string) "%$sep")) !== false) {
458
+        if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) {
459
+            break;
460
+        }
461
+        $debut = substr($texte, 0, $p);
462
+        $texte = substr($texte, $p + strlen($m[0]));
463
+        if ($p) {
464
+            $res = phraser_inclure($debut, $ligne, $res);
465
+        }
466
+        $ligne += substr_count($debut, "\n");
467
+        $res[] = $nested[$m[1]];
468
+    }
469
+
470
+    return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res));
471 471
 }
472 472
 
473 473
 function phraser_champs_interieurs($texte, $ligne, $sep, $result) {
474
-	$i = 0; // en fait count($result)
475
-	$x = '';
476
-
477
-	while (true) {
478
-		$j = $i;
479
-		$n = $ligne;
480
-		while (preg_match(CHAMP_ETENDU, $texte, $match)) {
481
-			$p = strpos($texte, (string) $match[0]);
482
-			$debut = substr($texte, 0, $p);
483
-			if ($p) {
484
-				$result[$i] = $debut;
485
-				$i++;
486
-			}
487
-			$nom = $match[4];
488
-			$champ = new Champ();
489
-			// ca ne marche pas encore en cas de champ imbrique
490
-			$champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n"));
491
-			$champ->nom_boucle = $match[3];
492
-			$champ->nom_champ = $nom;
493
-			$champ->etoile = $match[6];
494
-			// phraser_args indiquera ou commence apres
495
-			$pos_apres = 0;
496
-			$result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres);
497
-			phraser_vieux($champ);
498
-			$champ->avant =	phraser_champs_exterieurs($match[1], $n, $sep, $result);
499
-			$debut = substr($match[7], $pos_apres + 1);
500
-			if (!empty($debut)) {
501
-				$n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n");
502
-			}
503
-			$champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result);
504
-
505
-			// reinjecter la boucle si c'en est une
506
-			phraser_boucle_placeholder($champ);
507
-
508
-			$result[$i] = $champ;
509
-			$i++;
510
-			$texte = substr($texte, $p + strlen($match[0]));
511
-		}
512
-		if ($texte !== '') {
513
-			$result[$i] = $texte;
514
-			$i++;
515
-		}
516
-		$x = '';
517
-
518
-		while ($j < $i) {
519
-			$z = $result[$j];
520
-			// j'aurais besoin de connaitre le nombre de lignes...
521
-			if (is_object($z)) {
522
-				$x .= "%$sep$j@";
523
-			} else {
524
-				$x .= $z;
525
-			}
526
-			$j++;
527
-		}
528
-		if (preg_match(CHAMP_ETENDU, $x)) {
529
-			$texte = $x;
530
-		} else {
531
-			return phraser_champs_exterieurs($x, $ligne, $sep, $result);
532
-		}
533
-	}
474
+    $i = 0; // en fait count($result)
475
+    $x = '';
476
+
477
+    while (true) {
478
+        $j = $i;
479
+        $n = $ligne;
480
+        while (preg_match(CHAMP_ETENDU, $texte, $match)) {
481
+            $p = strpos($texte, (string) $match[0]);
482
+            $debut = substr($texte, 0, $p);
483
+            if ($p) {
484
+                $result[$i] = $debut;
485
+                $i++;
486
+            }
487
+            $nom = $match[4];
488
+            $champ = new Champ();
489
+            // ca ne marche pas encore en cas de champ imbrique
490
+            $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n"));
491
+            $champ->nom_boucle = $match[3];
492
+            $champ->nom_champ = $nom;
493
+            $champ->etoile = $match[6];
494
+            // phraser_args indiquera ou commence apres
495
+            $pos_apres = 0;
496
+            $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres);
497
+            phraser_vieux($champ);
498
+            $champ->avant =	phraser_champs_exterieurs($match[1], $n, $sep, $result);
499
+            $debut = substr($match[7], $pos_apres + 1);
500
+            if (!empty($debut)) {
501
+                $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n");
502
+            }
503
+            $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result);
504
+
505
+            // reinjecter la boucle si c'en est une
506
+            phraser_boucle_placeholder($champ);
507
+
508
+            $result[$i] = $champ;
509
+            $i++;
510
+            $texte = substr($texte, $p + strlen($match[0]));
511
+        }
512
+        if ($texte !== '') {
513
+            $result[$i] = $texte;
514
+            $i++;
515
+        }
516
+        $x = '';
517
+
518
+        while ($j < $i) {
519
+            $z = $result[$j];
520
+            // j'aurais besoin de connaitre le nombre de lignes...
521
+            if (is_object($z)) {
522
+                $x .= "%$sep$j@";
523
+            } else {
524
+                $x .= $z;
525
+            }
526
+            $j++;
527
+        }
528
+        if (preg_match(CHAMP_ETENDU, $x)) {
529
+            $texte = $x;
530
+        } else {
531
+            return phraser_champs_exterieurs($x, $ligne, $sep, $result);
532
+        }
533
+    }
534 534
 }
535 535
 
536 536
 function phraser_vieux(&$champ) {
537
-	$nom = $champ->nom_champ;
538
-	if ($nom == 'EMBED_DOCUMENT') {
539
-		if (!function_exists('phraser_vieux_emb')) {
540
-			include_spip('public/normaliser');
541
-		}
542
-		phraser_vieux_emb($champ);
543
-	} elseif ($nom == 'EXPOSER') {
544
-		if (!function_exists('phraser_vieux_exposer')) {
545
-			include_spip('public/normaliser');
546
-		}
547
-		phraser_vieux_exposer($champ);
548
-	} elseif ($champ->param) {
549
-		if ($nom == 'FORMULAIRE_RECHERCHE') {
550
-			if (!function_exists('phraser_vieux_recherche')) {
551
-				include_spip('public/normaliser');
552
-			}
553
-			phraser_vieux_recherche($champ);
554
-		} elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) {
555
-			if (!function_exists('phraser_vieux_logos')) {
556
-				include_spip('public/normaliser');
557
-			}
558
-			phraser_vieux_logos($champ);
559
-		} elseif ($nom == 'MODELE') {
560
-			if (!function_exists('phraser_vieux_modele')) {
561
-				include_spip('public/normaliser');
562
-			}
563
-			phraser_vieux_modele($champ);
564
-		} elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') {
565
-			if (!function_exists('phraser_vieux_inclu')) {
566
-				include_spip('public/normaliser');
567
-			}
568
-			phraser_vieux_inclu($champ);
569
-		}
570
-	}
537
+    $nom = $champ->nom_champ;
538
+    if ($nom == 'EMBED_DOCUMENT') {
539
+        if (!function_exists('phraser_vieux_emb')) {
540
+            include_spip('public/normaliser');
541
+        }
542
+        phraser_vieux_emb($champ);
543
+    } elseif ($nom == 'EXPOSER') {
544
+        if (!function_exists('phraser_vieux_exposer')) {
545
+            include_spip('public/normaliser');
546
+        }
547
+        phraser_vieux_exposer($champ);
548
+    } elseif ($champ->param) {
549
+        if ($nom == 'FORMULAIRE_RECHERCHE') {
550
+            if (!function_exists('phraser_vieux_recherche')) {
551
+                include_spip('public/normaliser');
552
+            }
553
+            phraser_vieux_recherche($champ);
554
+        } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) {
555
+            if (!function_exists('phraser_vieux_logos')) {
556
+                include_spip('public/normaliser');
557
+            }
558
+            phraser_vieux_logos($champ);
559
+        } elseif ($nom == 'MODELE') {
560
+            if (!function_exists('phraser_vieux_modele')) {
561
+                include_spip('public/normaliser');
562
+            }
563
+            phraser_vieux_modele($champ);
564
+        } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') {
565
+            if (!function_exists('phraser_vieux_inclu')) {
566
+                include_spip('public/normaliser');
567
+            }
568
+            phraser_vieux_inclu($champ);
569
+        }
570
+    }
571 571
 }
572 572
 
573 573
 
@@ -595,200 +595,200 @@  discard block
 block discarded – undo
595 595
  **/
596 596
 function phraser_criteres($params, &$result) {
597 597
 
598
-	$err_ci = ''; // indiquera s'il y a eu une erreur
599
-	$args = [];
600
-	$type = $result->type_requete;
601
-	$doublons = [];
602
-	foreach ($params as $v) {
603
-		$var = $v[1][0];
604
-		$param = ($var->type != 'texte') ? '' : $var->texte;
605
-		if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) {
606
-			// plus d'un argument et pas le critere IN:
607
-			// detecter comme on peut si c'est le critere implicite LIMIT debut, fin
608
-			if (
609
-				$var->type != 'texte'
610
-				or preg_match('/^(n|n-|(n-)?\d+)$/S', $param)
611
-			) {
612
-				$op = ',';
613
-				$not = false;
614
-				$cond = false;
615
-			} else {
616
-				// Le debut du premier argument est l'operateur
617
-				preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m);
618
-				$op = $m[2];
619
-				$not = (bool) $m[1];
620
-				$cond = $m[3];
621
-				// virer le premier argument,
622
-				// et mettre son reliquat eventuel
623
-				// Recopier pour ne pas alterer le texte source
624
-				// utile au debusqueur
625
-				if ($m[4]) {
626
-					// une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"}
627
-					if (preg_match(',^(["\'])(.*)\1$,', $m[4])) {
628
-						$c = null;
629
-						eval('$c = ' . $m[4] . ';');
630
-						if (isset($c)) {
631
-							$m[4] = $c;
632
-						}
633
-					}
634
-					$texte = new Texte();
635
-					$texte->texte = $m[4];
636
-					$v[1][0] = $texte;
637
-				} else {
638
-					array_shift($v[1]);
639
-				}
640
-			}
641
-			array_shift($v); // $v[O] est vide
642
-			$crit = new Critere();
643
-			$crit->op = $op;
644
-			$crit->not = $not;
645
-			$crit->cond = $cond;
646
-			$crit->exclus = '';
647
-			$crit->param = $v;
648
-			$args[] = $crit;
649
-		} else {
650
-			if ($var->type != 'texte') {
651
-				// cas 1 seul arg ne commencant pas par du texte brut:
652
-				// erreur ou critere infixe "/"
653
-				if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) {
654
-					$err_ci = [
655
-						'zbug_critere_inconnu',
656
-						['critere' => $var->nom_champ]
657
-					];
658
-					erreur_squelette($err_ci, $result);
659
-				} else {
660
-					$crit = new Critere();
661
-					$crit->op = '/';
662
-					$crit->not = false;
663
-					$crit->exclus = '';
664
-					$crit->param = [[$v[1][0]], [$v[1][2]]];
665
-					$args[] = $crit;
666
-				}
667
-			} else {
668
-				// traiter qq lexemes particuliers pour faciliter la suite
669
-				// les separateurs
670
-				if ($var->apres) {
671
-					$result->separateur[] = $param;
672
-				} elseif (($param == 'tout') or ($param == 'tous')) {
673
-					$result->modificateur['tout'] = true;
674
-				} elseif ($param == 'plat') {
675
-					$result->modificateur['plat'] = true;
676
-				}
677
-
678
-				// Boucle hierarchie, analyser le critere id_rubrique
679
-				// et les autres critères {id_x} pour forcer {tout} sur
680
-				// ceux-ci pour avoir la rubrique mere...
681
-				// Les autres critères de la boucle hierarchie doivent être
682
-				// traités normalement.
683
-				elseif (
684
-					strcasecmp($type, 'hierarchie') == 0
685
-					and !preg_match(",^id_rubrique\b,", $param)
686
-					and preg_match(',^id_\w+\s*$,', $param)
687
-				) {
688
-					$result->modificateur['tout'] = true;
689
-				} elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') {
690
-					// rien a faire sur {id_rubrique} tout seul
691
-				} else {
692
-					// pas d'emplacement statique, faut un dynamique
693
-					// mais il y a 2 cas qui ont les 2 !
694
-					if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) {
695
-						// cette variable sera inseree dans le code
696
-						// et son nom sert d'indicateur des maintenant
697
-						$result->doublons = '$doublons_index';
698
-						if ($param == 'unique') {
699
-							$param = 'doublons';
700
-						}
701
-					} elseif ($param == 'recherche') {
702
-						// meme chose (a cause de #nom_de_boucle:URL_*)
703
-						$result->hash = ' ';
704
-					}
705
-
706
-					if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) {
707
-						$crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', '');
708
-					} elseif (
709
-						preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC .
710
-						')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m)
711
-					) {
712
-						$a2 = trim($m[8]);
713
-						if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) {
714
-							$a2 = substr($a2, 1, -1);
715
-						}
716
-						$crit = phraser_critere_infixe(
717
-							$m[2],
718
-							$a2,
719
-							$v,
720
-							(($m[2] == 'lang_select') ? $m[2] : $m[7]),
721
-							$m[6],
722
-							$m[5]
723
-						);
724
-						$crit->exclus = $m[1];
725
-					} elseif (
726
-						preg_match('/^([!]?)\s*(' .
727
-						CHAMP_SQL_PLUS_FONC .
728
-						')\s*(\??)(.*)$/is', $param, $m)
729
-					) {
730
-						// contient aussi les comparaisons implicites !
731
-						// Comme ci-dessus:
732
-						// le premier arg contient l'operateur
733
-						array_shift($v);
734
-						if ($m[6]) {
735
-							$v[0][0] = new Texte();
736
-							$v[0][0]->texte = $m[6];
737
-						} else {
738
-							array_shift($v[0]);
739
-							if (!$v[0]) {
740
-								array_shift($v);
741
-							}
742
-						}
743
-						$crit = new Critere();
744
-						$crit->op = $m[2];
745
-						$crit->param = $v;
746
-						$crit->not = (bool) $m[1];
747
-						$crit->cond = $m[5];
748
-					} else {
749
-						$err_ci = [
750
-							'zbug_critere_inconnu',
751
-							['critere' => $param]
752
-						];
753
-						erreur_squelette($err_ci, $result);
754
-					}
755
-
756
-					if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) {
757
-						$args[] = $crit;
758
-					} else {
759
-						$doublons[] = $crit;
760
-					}
761
-				}
762
-			}
763
-		}
764
-	}
765
-
766
-	// les doublons non nies doivent etre le dernier critere
767
-	// pour que la variable $doublon_index ait la bonne valeur
768
-	// cf critere_doublon
769
-	if ($doublons) {
770
-		$args = [...$args, ...$doublons];
771
-	}
772
-
773
-	// Si erreur, laisser la chaine dans ce champ pour le HTTP 503
774
-	if (!$err_ci) {
775
-		$result->criteres = $args;
776
-	}
598
+    $err_ci = ''; // indiquera s'il y a eu une erreur
599
+    $args = [];
600
+    $type = $result->type_requete;
601
+    $doublons = [];
602
+    foreach ($params as $v) {
603
+        $var = $v[1][0];
604
+        $param = ($var->type != 'texte') ? '' : $var->texte;
605
+        if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) {
606
+            // plus d'un argument et pas le critere IN:
607
+            // detecter comme on peut si c'est le critere implicite LIMIT debut, fin
608
+            if (
609
+                $var->type != 'texte'
610
+                or preg_match('/^(n|n-|(n-)?\d+)$/S', $param)
611
+            ) {
612
+                $op = ',';
613
+                $not = false;
614
+                $cond = false;
615
+            } else {
616
+                // Le debut du premier argument est l'operateur
617
+                preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m);
618
+                $op = $m[2];
619
+                $not = (bool) $m[1];
620
+                $cond = $m[3];
621
+                // virer le premier argument,
622
+                // et mettre son reliquat eventuel
623
+                // Recopier pour ne pas alterer le texte source
624
+                // utile au debusqueur
625
+                if ($m[4]) {
626
+                    // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"}
627
+                    if (preg_match(',^(["\'])(.*)\1$,', $m[4])) {
628
+                        $c = null;
629
+                        eval('$c = ' . $m[4] . ';');
630
+                        if (isset($c)) {
631
+                            $m[4] = $c;
632
+                        }
633
+                    }
634
+                    $texte = new Texte();
635
+                    $texte->texte = $m[4];
636
+                    $v[1][0] = $texte;
637
+                } else {
638
+                    array_shift($v[1]);
639
+                }
640
+            }
641
+            array_shift($v); // $v[O] est vide
642
+            $crit = new Critere();
643
+            $crit->op = $op;
644
+            $crit->not = $not;
645
+            $crit->cond = $cond;
646
+            $crit->exclus = '';
647
+            $crit->param = $v;
648
+            $args[] = $crit;
649
+        } else {
650
+            if ($var->type != 'texte') {
651
+                // cas 1 seul arg ne commencant pas par du texte brut:
652
+                // erreur ou critere infixe "/"
653
+                if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) {
654
+                    $err_ci = [
655
+                        'zbug_critere_inconnu',
656
+                        ['critere' => $var->nom_champ]
657
+                    ];
658
+                    erreur_squelette($err_ci, $result);
659
+                } else {
660
+                    $crit = new Critere();
661
+                    $crit->op = '/';
662
+                    $crit->not = false;
663
+                    $crit->exclus = '';
664
+                    $crit->param = [[$v[1][0]], [$v[1][2]]];
665
+                    $args[] = $crit;
666
+                }
667
+            } else {
668
+                // traiter qq lexemes particuliers pour faciliter la suite
669
+                // les separateurs
670
+                if ($var->apres) {
671
+                    $result->separateur[] = $param;
672
+                } elseif (($param == 'tout') or ($param == 'tous')) {
673
+                    $result->modificateur['tout'] = true;
674
+                } elseif ($param == 'plat') {
675
+                    $result->modificateur['plat'] = true;
676
+                }
677
+
678
+                // Boucle hierarchie, analyser le critere id_rubrique
679
+                // et les autres critères {id_x} pour forcer {tout} sur
680
+                // ceux-ci pour avoir la rubrique mere...
681
+                // Les autres critères de la boucle hierarchie doivent être
682
+                // traités normalement.
683
+                elseif (
684
+                    strcasecmp($type, 'hierarchie') == 0
685
+                    and !preg_match(",^id_rubrique\b,", $param)
686
+                    and preg_match(',^id_\w+\s*$,', $param)
687
+                ) {
688
+                    $result->modificateur['tout'] = true;
689
+                } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') {
690
+                    // rien a faire sur {id_rubrique} tout seul
691
+                } else {
692
+                    // pas d'emplacement statique, faut un dynamique
693
+                    // mais il y a 2 cas qui ont les 2 !
694
+                    if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) {
695
+                        // cette variable sera inseree dans le code
696
+                        // et son nom sert d'indicateur des maintenant
697
+                        $result->doublons = '$doublons_index';
698
+                        if ($param == 'unique') {
699
+                            $param = 'doublons';
700
+                        }
701
+                    } elseif ($param == 'recherche') {
702
+                        // meme chose (a cause de #nom_de_boucle:URL_*)
703
+                        $result->hash = ' ';
704
+                    }
705
+
706
+                    if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) {
707
+                        $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', '');
708
+                    } elseif (
709
+                        preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC .
710
+                        ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m)
711
+                    ) {
712
+                        $a2 = trim($m[8]);
713
+                        if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) {
714
+                            $a2 = substr($a2, 1, -1);
715
+                        }
716
+                        $crit = phraser_critere_infixe(
717
+                            $m[2],
718
+                            $a2,
719
+                            $v,
720
+                            (($m[2] == 'lang_select') ? $m[2] : $m[7]),
721
+                            $m[6],
722
+                            $m[5]
723
+                        );
724
+                        $crit->exclus = $m[1];
725
+                    } elseif (
726
+                        preg_match('/^([!]?)\s*(' .
727
+                        CHAMP_SQL_PLUS_FONC .
728
+                        ')\s*(\??)(.*)$/is', $param, $m)
729
+                    ) {
730
+                        // contient aussi les comparaisons implicites !
731
+                        // Comme ci-dessus:
732
+                        // le premier arg contient l'operateur
733
+                        array_shift($v);
734
+                        if ($m[6]) {
735
+                            $v[0][0] = new Texte();
736
+                            $v[0][0]->texte = $m[6];
737
+                        } else {
738
+                            array_shift($v[0]);
739
+                            if (!$v[0]) {
740
+                                array_shift($v);
741
+                            }
742
+                        }
743
+                        $crit = new Critere();
744
+                        $crit->op = $m[2];
745
+                        $crit->param = $v;
746
+                        $crit->not = (bool) $m[1];
747
+                        $crit->cond = $m[5];
748
+                    } else {
749
+                        $err_ci = [
750
+                            'zbug_critere_inconnu',
751
+                            ['critere' => $param]
752
+                        ];
753
+                        erreur_squelette($err_ci, $result);
754
+                    }
755
+
756
+                    if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) {
757
+                        $args[] = $crit;
758
+                    } else {
759
+                        $doublons[] = $crit;
760
+                    }
761
+                }
762
+            }
763
+        }
764
+    }
765
+
766
+    // les doublons non nies doivent etre le dernier critere
767
+    // pour que la variable $doublon_index ait la bonne valeur
768
+    // cf critere_doublon
769
+    if ($doublons) {
770
+        $args = [...$args, ...$doublons];
771
+    }
772
+
773
+    // Si erreur, laisser la chaine dans ce champ pour le HTTP 503
774
+    if (!$err_ci) {
775
+        $result->criteres = $args;
776
+    }
777 777
 }
778 778
 
779 779
 function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) {
780
-	$args[0] = new Texte();
781
-	$args[0]->texte = $arg1;
782
-	$args[0] = [$args[0]];
783
-	$args[1][0] = new Texte();
784
-	$args[1][0]->texte = $arg2;
785
-	$crit = new Critere();
786
-	$crit->op = $op;
787
-	$crit->not = $not;
788
-	$crit->cond = $cond;
789
-	$crit->param = $args;
790
-
791
-	return $crit;
780
+    $args[0] = new Texte();
781
+    $args[0]->texte = $arg1;
782
+    $args[0] = [$args[0]];
783
+    $args[1][0] = new Texte();
784
+    $args[1][0]->texte = $arg2;
785
+    $crit = new Critere();
786
+    $crit->op = $op;
787
+    $crit->not = $not;
788
+    $crit->cond = $cond;
789
+    $crit->param = $args;
790
+
791
+    return $crit;
792 792
 }
793 793
 
794 794
 /**
@@ -799,12 +799,12 @@  discard block
 block discarded – undo
799 799
  * @return int
800 800
  */
801 801
 function public_compte_ligne($texte, $debut = 0, $fin = null) {
802
-	if (is_null($fin)) {
803
-		return substr_count($texte, "\n", $debut);
804
-	}
805
-	else {
806
-		return substr_count($texte, "\n", $debut, $fin - $debut);
807
-	}
802
+    if (is_null($fin)) {
803
+        return substr_count($texte, "\n", $debut);
804
+    }
805
+    else {
806
+        return substr_count($texte, "\n", $debut, $fin - $debut);
807
+    }
808 808
 }
809 809
 
810 810
 
@@ -820,87 +820,87 @@  discard block
 block discarded – undo
820 820
  * @return array|null
821 821
  */
822 822
 function public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte = 0) {
823
-	$premiere_boucle = null;
824
-	$pos_derniere_boucle_anonyme = $pos_debut_texte;
825
-
826
-	$current_pos = $pos_debut_texte;
827
-	while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) {
828
-		$current_pos = $pos_boucle + 1;
829
-		$pos_parent = strpos($texte, '(', $pos_boucle);
830
-
831
-		$id_boucle = '';
832
-		if ($pos_parent !== false) {
833
-			$id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE)));
834
-		}
835
-		if (
836
-			$pos_parent === false
837
-			or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0))
838
-		) {
839
-			$result = new Boucle();
840
-			$result->id_parent = $id_parent;
841
-			$result->descr = $descr;
842
-
843
-			// un id_boucle pour l'affichage de l'erreur
844
-			if (!strlen($id_boucle)) {
845
-				$id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15);
846
-			}
847
-			$result->id_boucle = $id_boucle;
848
-			$err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]];
849
-			erreur_squelette($err_b, $result);
850
-
851
-			continue;
852
-		}
853
-		else {
854
-			$boucle = [
855
-				'id_boucle' => $id_boucle,
856
-				'id_boucle_err' => $id_boucle,
857
-				'debut_boucle' => $pos_boucle,
858
-				'pos_boucle' => $pos_boucle,
859
-				'pos_parent' => $pos_parent,
860
-				'pos_precond' => false,
861
-				'pos_precond_inside' => false,
862
-				'pos_preaff' => false,
863
-				'pos_preaff_inside' => false,
864
-			];
865
-
866
-			// un id_boucle pour l'affichage de l'erreur sur les boucle anonymes
867
-			if (!strlen($id_boucle)) {
868
-				$boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15);
869
-			}
870
-
871
-			// trouver sa position de depart reelle : au <Bxx> ou au <BBxx>
872
-			$precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>';
873
-			$pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme);
874
-			if (
875
-				$pos_precond !== false
876
-				and $pos_precond < $boucle['debut_boucle']
877
-			) {
878
-				$boucle['debut_boucle'] = $pos_precond;
879
-				$boucle['pos_precond'] = $pos_precond;
880
-				$boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle);
881
-			}
882
-
883
-			$preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>';
884
-			$pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme);
885
-			if (
886
-				$pos_preaff !== false
887
-				and $pos_preaff < $boucle['debut_boucle']
888
-			) {
889
-				$boucle['debut_boucle'] = $pos_preaff;
890
-				$boucle['pos_preaff'] = $pos_preaff;
891
-				$boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle);
892
-			}
893
-			if (!strlen($id_boucle)) {
894
-				$pos_derniere_boucle_anonyme = $pos_boucle;
895
-			}
896
-
897
-			if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) {
898
-				$premiere_boucle = $boucle;
899
-			}
900
-		}
901
-	}
902
-
903
-	return $premiere_boucle;
823
+    $premiere_boucle = null;
824
+    $pos_derniere_boucle_anonyme = $pos_debut_texte;
825
+
826
+    $current_pos = $pos_debut_texte;
827
+    while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) {
828
+        $current_pos = $pos_boucle + 1;
829
+        $pos_parent = strpos($texte, '(', $pos_boucle);
830
+
831
+        $id_boucle = '';
832
+        if ($pos_parent !== false) {
833
+            $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE)));
834
+        }
835
+        if (
836
+            $pos_parent === false
837
+            or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0))
838
+        ) {
839
+            $result = new Boucle();
840
+            $result->id_parent = $id_parent;
841
+            $result->descr = $descr;
842
+
843
+            // un id_boucle pour l'affichage de l'erreur
844
+            if (!strlen($id_boucle)) {
845
+                $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15);
846
+            }
847
+            $result->id_boucle = $id_boucle;
848
+            $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]];
849
+            erreur_squelette($err_b, $result);
850
+
851
+            continue;
852
+        }
853
+        else {
854
+            $boucle = [
855
+                'id_boucle' => $id_boucle,
856
+                'id_boucle_err' => $id_boucle,
857
+                'debut_boucle' => $pos_boucle,
858
+                'pos_boucle' => $pos_boucle,
859
+                'pos_parent' => $pos_parent,
860
+                'pos_precond' => false,
861
+                'pos_precond_inside' => false,
862
+                'pos_preaff' => false,
863
+                'pos_preaff_inside' => false,
864
+            ];
865
+
866
+            // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes
867
+            if (!strlen($id_boucle)) {
868
+                $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15);
869
+            }
870
+
871
+            // trouver sa position de depart reelle : au <Bxx> ou au <BBxx>
872
+            $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>';
873
+            $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme);
874
+            if (
875
+                $pos_precond !== false
876
+                and $pos_precond < $boucle['debut_boucle']
877
+            ) {
878
+                $boucle['debut_boucle'] = $pos_precond;
879
+                $boucle['pos_precond'] = $pos_precond;
880
+                $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle);
881
+            }
882
+
883
+            $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>';
884
+            $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme);
885
+            if (
886
+                $pos_preaff !== false
887
+                and $pos_preaff < $boucle['debut_boucle']
888
+            ) {
889
+                $boucle['debut_boucle'] = $pos_preaff;
890
+                $boucle['pos_preaff'] = $pos_preaff;
891
+                $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle);
892
+            }
893
+            if (!strlen($id_boucle)) {
894
+                $pos_derniere_boucle_anonyme = $pos_boucle;
895
+            }
896
+
897
+            if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) {
898
+                $premiere_boucle = $boucle;
899
+            }
900
+        }
901
+    }
902
+
903
+    return $premiere_boucle;
904 904
 }
905 905
 
906 906
 /**
@@ -915,68 +915,68 @@  discard block
 block discarded – undo
915 915
  * @return mixed
916 916
  */
917 917
 function public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_debut_texte, $result) {
918
-	$id_boucle = $boucle['id_boucle'];
919
-	$pos_courante = $pos_debut_texte;
920
-
921
-	$boucle['pos_postcond'] = false;
922
-	$boucle['pos_postcond_inside'] = false;
923
-	$boucle['pos_altern'] = false;
924
-	$boucle['pos_altern_inside'] = false;
925
-	$boucle['pos_postaff'] = false;
926
-	$boucle['pos_postaff_inside'] = false;
927
-
928
-	$pos_anonyme_next = null;
929
-	// si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme
930
-	if (!strlen($id_boucle)) {
931
-		$pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante);
932
-	}
933
-
934
-	//
935
-	// 1. Recuperer la partie conditionnelle apres
936
-	//
937
-	$apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>';
938
-	$pos_apres = strpos($texte, $apres_boucle, $pos_courante);
939
-	if (
940
-		$pos_apres !== false
941
-		and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next)
942
-	) {
943
-		$boucle['pos_postcond'] = $pos_apres;
944
-		$pos_apres += strlen($apres_boucle);
945
-		$boucle['pos_postcond_inside'] = $pos_apres;
946
-		$pos_courante = $pos_apres ;
947
-	}
948
-
949
-	//
950
-	// 2. Récuperer la partie alternative apres
951
-	//
952
-	$altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>';
953
-	$pos_altern = strpos($texte, $altern_boucle, $pos_courante);
954
-	if (
955
-		$pos_altern !== false
956
-		and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next)
957
-	) {
958
-		$boucle['pos_altern'] = $pos_altern;
959
-		$pos_altern += strlen($altern_boucle);
960
-		$boucle['pos_altern_inside'] = $pos_altern;
961
-		$pos_courante = $pos_altern;
962
-	}
963
-
964
-	//
965
-	// 3. Recuperer la partie footer non alternative
966
-	//
967
-	$postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>';
968
-	$pos_postaff = strpos($texte, $postaff_boucle, $pos_courante);
969
-	if (
970
-		$pos_postaff !== false
971
-		and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next)
972
-	) {
973
-		$boucle['pos_postaff'] = $pos_postaff;
974
-		$pos_postaff += strlen($postaff_boucle);
975
-		$boucle['pos_postaff_inside'] = $pos_postaff;
976
-		$pos_courante = $pos_postaff ;
977
-	}
978
-
979
-	return $boucle;
918
+    $id_boucle = $boucle['id_boucle'];
919
+    $pos_courante = $pos_debut_texte;
920
+
921
+    $boucle['pos_postcond'] = false;
922
+    $boucle['pos_postcond_inside'] = false;
923
+    $boucle['pos_altern'] = false;
924
+    $boucle['pos_altern_inside'] = false;
925
+    $boucle['pos_postaff'] = false;
926
+    $boucle['pos_postaff_inside'] = false;
927
+
928
+    $pos_anonyme_next = null;
929
+    // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme
930
+    if (!strlen($id_boucle)) {
931
+        $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante);
932
+    }
933
+
934
+    //
935
+    // 1. Recuperer la partie conditionnelle apres
936
+    //
937
+    $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>';
938
+    $pos_apres = strpos($texte, $apres_boucle, $pos_courante);
939
+    if (
940
+        $pos_apres !== false
941
+        and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next)
942
+    ) {
943
+        $boucle['pos_postcond'] = $pos_apres;
944
+        $pos_apres += strlen($apres_boucle);
945
+        $boucle['pos_postcond_inside'] = $pos_apres;
946
+        $pos_courante = $pos_apres ;
947
+    }
948
+
949
+    //
950
+    // 2. Récuperer la partie alternative apres
951
+    //
952
+    $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>';
953
+    $pos_altern = strpos($texte, $altern_boucle, $pos_courante);
954
+    if (
955
+        $pos_altern !== false
956
+        and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next)
957
+    ) {
958
+        $boucle['pos_altern'] = $pos_altern;
959
+        $pos_altern += strlen($altern_boucle);
960
+        $boucle['pos_altern_inside'] = $pos_altern;
961
+        $pos_courante = $pos_altern;
962
+    }
963
+
964
+    //
965
+    // 3. Recuperer la partie footer non alternative
966
+    //
967
+    $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>';
968
+    $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante);
969
+    if (
970
+        $pos_postaff !== false
971
+        and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next)
972
+    ) {
973
+        $boucle['pos_postaff'] = $pos_postaff;
974
+        $pos_postaff += strlen($postaff_boucle);
975
+        $boucle['pos_postaff_inside'] = $pos_postaff;
976
+        $pos_courante = $pos_postaff ;
977
+    }
978
+
979
+    return $boucle;
980 980
 }
981 981
 
982 982
 
@@ -986,21 +986,21 @@  discard block
 block discarded – undo
986 986
  * @param null|object $boucle
987 987
  */
988 988
 function phraser_boucle_placeholder(&$champ, $boucle_placeholder = null, $boucle = null) {
989
-	static $boucles_connues = [];
990
-	// si c'est un appel pour memoriser une boucle, memorisons la
991
-	if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) {
992
-		$boucles_connues[$boucle_placeholder][$champ] = &$boucle;
993
-	}
994
-	else {
995
-		if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) {
996
-			$placeholder = $champ->nom_champ;
997
-			$id = reset($champ->param[0][1]);
998
-			$id = $id->texte;
999
-			if (!empty($boucles_connues[$placeholder][$id])) {
1000
-				$champ = $boucles_connues[$placeholder][$id];
1001
-			}
1002
-		}
1003
-	}
989
+    static $boucles_connues = [];
990
+    // si c'est un appel pour memoriser une boucle, memorisons la
991
+    if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) {
992
+        $boucles_connues[$boucle_placeholder][$champ] = &$boucle;
993
+    }
994
+    else {
995
+        if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) {
996
+            $placeholder = $champ->nom_champ;
997
+            $id = reset($champ->param[0][1]);
998
+            $id = $id->texte;
999
+            if (!empty($boucles_connues[$placeholder][$id])) {
1000
+                $champ = $boucles_connues[$placeholder][$id];
1001
+            }
1002
+        }
1003
+    }
1004 1004
 }
1005 1005
 
1006 1006
 
@@ -1013,274 +1013,274 @@  discard block
 block discarded – undo
1013 1013
  * @return string
1014 1014
  */
1015 1015
 function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) {
1016
-	$placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']';
1017
-	//memoriser la boucle a reinjecter
1018
-	$id_boucle = "$id_boucle";
1019
-	phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle);
1020
-	return $placeholder;
1016
+    $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']';
1017
+    //memoriser la boucle a reinjecter
1018
+    $id_boucle = "$id_boucle";
1019
+    phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle);
1020
+    return $placeholder;
1021 1021
 }
1022 1022
 
1023 1023
 function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne_debut_texte = 1, $boucle_placeholder = null) {
1024 1024
 
1025
-	$all_res = [];
1026
-	// definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette
1027
-	if (is_null($boucle_placeholder)) {
1028
-		do {
1029
-			$boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid()));
1030
-		} while (strpos($texte, $boucle_placeholder) !== false);
1031
-	}
1032
-
1033
-	$ligne_debut_initial = $ligne_debut_texte;
1034
-	$pos_debut_texte = 0;
1035
-	while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) {
1036
-		$err_b = ''; // indiquera s'il y a eu une erreur
1037
-		$result = new Boucle();
1038
-		$result->id_parent = $id_parent;
1039
-		$result->descr = $descr;
1040
-
1041
-		$pos_courante = $boucle['pos_boucle'];
1042
-		$pos_parent = $boucle['pos_parent'];
1043
-		$id_boucle_search = $id_boucle = $boucle['id_boucle'];
1044
-
1045
-		$ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent);
1046
-
1047
-		// boucle anonyme ?
1048
-		if (!strlen($id_boucle)) {
1049
-			$id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8);
1050
-		}
1051
-
1052
-		$pos_debut_boucle = $pos_courante;
1053
-
1054
-		$pos_milieu = $pos_parent;
1055
-
1056
-		// Regarder si on a une partie conditionnelle avant <B_xxx>
1057
-		if ($boucle['pos_precond'] !== false) {
1058
-			$pos_debut_boucle = $boucle['pos_precond'];
1059
-
1060
-			$pos_avant = $boucle['pos_precond_inside'];
1061
-			$result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant);
1062
-			$ligne_avant = $ligne_debut_texte +  public_compte_ligne($texte, $pos_debut_texte, $pos_avant);
1063
-		}
1064
-
1065
-		// Regarder si on a une partie inconditionnelle avant <BB_xxx>
1066
-		if ($boucle['pos_preaff'] !== false) {
1067
-			$end_preaff = $pos_debut_boucle;
1068
-
1069
-			$pos_preaff = $boucle['pos_preaff_inside'];
1070
-			$result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff);
1071
-			$ligne_preaff = $ligne_debut_texte +  public_compte_ligne($texte, $pos_debut_texte, $pos_preaff);
1072
-		}
1073
-
1074
-		$result->id_boucle = $id_boucle;
1075
-
1076
-		if (
1077
-			!preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu)
1078
-			or ($pos_match = strpos($texte, (string) $match[0], $pos_milieu)) === false
1079
-			or $pos_match > $pos_milieu
1080
-		) {
1081
-			$err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]];
1082
-			erreur_squelette($err_b, $result);
1083
-
1084
-			$ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1);
1085
-			$pos_debut_texte = $pos_courante + 1;
1086
-			continue;
1087
-		}
1088
-
1089
-		$result->type_requete = $match[0];
1090
-		$pos_milieu += strlen($match[0]);
1091
-		$pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment
1092
-
1093
-		$type = $match[1];
1094
-		$jointures = trim($match[2]);
1095
-		$table_optionnelle = ($match[3]);
1096
-		if ($jointures) {
1097
-			// on affecte pas ici les jointures explicites, mais dans la compilation
1098
-			// ou elles seront completees des jointures declarees
1099
-			$result->jointures_explicites = $jointures;
1100
-		}
1101
-
1102
-		if ($table_optionnelle) {
1103
-			$result->table_optionnelle = $type;
1104
-		}
1105
-
1106
-		// 1ere passe sur les criteres, vu comme des arguments sans fct
1107
-		// Resultat mis dans result->param
1108
-		$pos_fin_criteres = $pos_milieu;
1109
-		phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres);
1110
-
1111
-		// En 2e passe result->criteres contiendra un tableau
1112
-		// pour l'instant on met le source (chaine) :
1113
-		// si elle reste ici au final, c'est qu'elle contient une erreur
1114
-		$pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment
1115
-		$result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu);
1116
-		$pos_milieu = $pos_fin_criteres;
1117
-
1118
-		//
1119
-		// Recuperer la fin :
1120
-		//
1121
-		if ($texte[$pos_milieu] === '/') {
1122
-			// boucle autofermante : pas de partie conditionnelle apres
1123
-			$pos_courante += 2;
1124
-			$result->milieu = '';
1125
-		} else {
1126
-			$pos_milieu += 1;
1127
-
1128
-			$fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>';
1129
-			$pos_fin = strpos($texte, $fin_boucle, $pos_milieu);
1130
-			if ($pos_fin === false) {
1131
-				$err_b = [
1132
-					'zbug_erreur_boucle_fermant',
1133
-					['id' => $id_boucle]
1134
-				];
1135
-				erreur_squelette($err_b, $result);
1136
-				$pos_courante += strlen($fin_boucle);
1137
-			}
1138
-			else {
1139
-				// verifier une eventuelle imbrication d'une boucle homonyme
1140
-				// (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur)
1141
-				$search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '(';
1142
-				$search_from = $pos_milieu;
1143
-				$nb_open = 1;
1144
-				$nb_close = 1;
1145
-				$maxiter = 0;
1146
-				do {
1147
-					while (
1148
-						$nb_close < $nb_open
1149
-						and $p = strpos($texte, $fin_boucle, $pos_fin + 1)
1150
-					) {
1151
-						$nb_close++;
1152
-						$pos_fin = $p;
1153
-					}
1154
-					// si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux
1155
-					if ($nb_close < $nb_open) {
1156
-						break;
1157
-					}
1158
-					while (
1159
-						$p = strpos($texte, $search_debut_boucle, $search_from)
1160
-						and $p < $pos_fin
1161
-					) {
1162
-						$nb_open++;
1163
-						$search_from = $p + 1;
1164
-					}
1165
-				} while ($nb_close < $nb_open and $maxiter++ < 5);
1166
-
1167
-				$pos_courante = $pos_fin + strlen($fin_boucle);
1168
-			}
1169
-			$result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu);
1170
-		}
1171
-
1172
-		$ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante);
1173
-		$boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result);
1174
-
1175
-		//
1176
-		// 1. Partie conditionnelle apres ?
1177
-		//
1178
-		if ($boucle['pos_postcond']) {
1179
-			$result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante);
1180
-			$ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']);
1181
-			$pos_courante = $boucle['pos_postcond_inside'] ;
1182
-		}
1183
-
1184
-
1185
-		//
1186
-		// 2. Partie alternative apres ?
1187
-		//
1188
-		$ligne_altern = $ligne_suite;
1189
-		if ($boucle['pos_altern']) {
1190
-			$result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante);
1191
-			$ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']);
1192
-			$pos_courante = $boucle['pos_altern_inside'];
1193
-		}
1194
-
1195
-		//
1196
-		// 3. Partie footer non alternative ?
1197
-		//
1198
-		$ligne_postaff = $ligne_suite;
1199
-		if ($boucle['pos_postaff']) {
1200
-			$result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante);
1201
-			$ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']);
1202
-			$pos_courante = $boucle['pos_postaff_inside'];
1203
-		}
1204
-
1205
-		$result->ligne = $ligne_preaff;
1206
-
1207
-		if ($p = strpos($type, ':')) {
1208
-			$result->sql_serveur = substr($type, 0, $p);
1209
-			$type = substr($type, $p + 1);
1210
-		}
1211
-		$soustype = strtolower($type);
1212
-
1213
-		if (!isset($GLOBALS['table_des_tables'][$soustype])) {
1214
-			$soustype = $type;
1215
-		}
1216
-
1217
-		$result->type_requete = $soustype;
1218
-		// Lancer la 2e passe sur les criteres si la 1ere etait bonne
1219
-		if (!is_array($result->param)) {
1220
-			$err_b = true;
1221
-		} else {
1222
-			phraser_criteres($result->param, $result);
1223
-			if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) {
1224
-				$result->type_requete = TYPE_RECURSIF;
1225
-				$args = $result->param;
1226
-				array_unshift(
1227
-					$args,
1228
-					substr($type, strlen(TYPE_RECURSIF))
1229
-				);
1230
-				$result->param = $args;
1231
-			}
1232
-		}
1233
-
1234
-		$descr['id_mere_contexte'] = $id_boucle;
1235
-		$result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder);
1236
-		// reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre
1237
-		// ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle
1238
-		// si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite
1239
-		if (empty($boucles[$id_boucle])) {
1240
-			$boucles[$id_boucle] = null;
1241
-		}
1242
-		$result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder);
1243
-		$result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder);
1244
-		$result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder);
1245
-		$result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder);
1246
-		$result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder);
1247
-
1248
-		// Prevenir le generateur de code que le squelette est faux
1249
-		if ($err_b) {
1250
-			$result->type_requete = false;
1251
-		}
1252
-
1253
-		// Verifier qu'il n'y a pas double definition
1254
-		// apres analyse des sous-parties (pas avant).
1255
-		if (!empty($boucles[$id_boucle])) {
1256
-			if ($boucles[$id_boucle]->type_requete !== false) {
1257
-				$err_b_d = [
1258
-					'zbug_erreur_boucle_double',
1259
-					['id' => $id_boucle]
1260
-				];
1261
-				erreur_squelette($err_b_d, $result);
1262
-				// Prevenir le generateur de code que le squelette est faux
1263
-				$boucles[$id_boucle]->type_requete = false;
1264
-			}
1265
-		} else {
1266
-			$boucles[$id_boucle] = $result;
1267
-		}
1268
-
1269
-		// remplacer la boucle par un placeholder qui compte le meme nombre de lignes
1270
-		$placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte);
1271
-		$longueur_boucle = $pos_courante - $boucle['debut_boucle'];
1272
-		$texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle);
1273
-		$pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder);
1274
-
1275
-		// phraser la partie avant le debut de la boucle
1276
-		#$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res);
1277
-		#$all_res[] = &$boucles[$id_boucle];
1278
-
1279
-		$ligne_debut_texte = $ligne_suite;
1280
-		$pos_debut_texte = $pos_courante;
1281
-	}
1282
-
1283
-	$all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res);
1284
-
1285
-	return $all_res;
1025
+    $all_res = [];
1026
+    // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette
1027
+    if (is_null($boucle_placeholder)) {
1028
+        do {
1029
+            $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid()));
1030
+        } while (strpos($texte, $boucle_placeholder) !== false);
1031
+    }
1032
+
1033
+    $ligne_debut_initial = $ligne_debut_texte;
1034
+    $pos_debut_texte = 0;
1035
+    while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) {
1036
+        $err_b = ''; // indiquera s'il y a eu une erreur
1037
+        $result = new Boucle();
1038
+        $result->id_parent = $id_parent;
1039
+        $result->descr = $descr;
1040
+
1041
+        $pos_courante = $boucle['pos_boucle'];
1042
+        $pos_parent = $boucle['pos_parent'];
1043
+        $id_boucle_search = $id_boucle = $boucle['id_boucle'];
1044
+
1045
+        $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent);
1046
+
1047
+        // boucle anonyme ?
1048
+        if (!strlen($id_boucle)) {
1049
+            $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8);
1050
+        }
1051
+
1052
+        $pos_debut_boucle = $pos_courante;
1053
+
1054
+        $pos_milieu = $pos_parent;
1055
+
1056
+        // Regarder si on a une partie conditionnelle avant <B_xxx>
1057
+        if ($boucle['pos_precond'] !== false) {
1058
+            $pos_debut_boucle = $boucle['pos_precond'];
1059
+
1060
+            $pos_avant = $boucle['pos_precond_inside'];
1061
+            $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant);
1062
+            $ligne_avant = $ligne_debut_texte +  public_compte_ligne($texte, $pos_debut_texte, $pos_avant);
1063
+        }
1064
+
1065
+        // Regarder si on a une partie inconditionnelle avant <BB_xxx>
1066
+        if ($boucle['pos_preaff'] !== false) {
1067
+            $end_preaff = $pos_debut_boucle;
1068
+
1069
+            $pos_preaff = $boucle['pos_preaff_inside'];
1070
+            $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff);
1071
+            $ligne_preaff = $ligne_debut_texte +  public_compte_ligne($texte, $pos_debut_texte, $pos_preaff);
1072
+        }
1073
+
1074
+        $result->id_boucle = $id_boucle;
1075
+
1076
+        if (
1077
+            !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu)
1078
+            or ($pos_match = strpos($texte, (string) $match[0], $pos_milieu)) === false
1079
+            or $pos_match > $pos_milieu
1080
+        ) {
1081
+            $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]];
1082
+            erreur_squelette($err_b, $result);
1083
+
1084
+            $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1);
1085
+            $pos_debut_texte = $pos_courante + 1;
1086
+            continue;
1087
+        }
1088
+
1089
+        $result->type_requete = $match[0];
1090
+        $pos_milieu += strlen($match[0]);
1091
+        $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment
1092
+
1093
+        $type = $match[1];
1094
+        $jointures = trim($match[2]);
1095
+        $table_optionnelle = ($match[3]);
1096
+        if ($jointures) {
1097
+            // on affecte pas ici les jointures explicites, mais dans la compilation
1098
+            // ou elles seront completees des jointures declarees
1099
+            $result->jointures_explicites = $jointures;
1100
+        }
1101
+
1102
+        if ($table_optionnelle) {
1103
+            $result->table_optionnelle = $type;
1104
+        }
1105
+
1106
+        // 1ere passe sur les criteres, vu comme des arguments sans fct
1107
+        // Resultat mis dans result->param
1108
+        $pos_fin_criteres = $pos_milieu;
1109
+        phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres);
1110
+
1111
+        // En 2e passe result->criteres contiendra un tableau
1112
+        // pour l'instant on met le source (chaine) :
1113
+        // si elle reste ici au final, c'est qu'elle contient une erreur
1114
+        $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment
1115
+        $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu);
1116
+        $pos_milieu = $pos_fin_criteres;
1117
+
1118
+        //
1119
+        // Recuperer la fin :
1120
+        //
1121
+        if ($texte[$pos_milieu] === '/') {
1122
+            // boucle autofermante : pas de partie conditionnelle apres
1123
+            $pos_courante += 2;
1124
+            $result->milieu = '';
1125
+        } else {
1126
+            $pos_milieu += 1;
1127
+
1128
+            $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>';
1129
+            $pos_fin = strpos($texte, $fin_boucle, $pos_milieu);
1130
+            if ($pos_fin === false) {
1131
+                $err_b = [
1132
+                    'zbug_erreur_boucle_fermant',
1133
+                    ['id' => $id_boucle]
1134
+                ];
1135
+                erreur_squelette($err_b, $result);
1136
+                $pos_courante += strlen($fin_boucle);
1137
+            }
1138
+            else {
1139
+                // verifier une eventuelle imbrication d'une boucle homonyme
1140
+                // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur)
1141
+                $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '(';
1142
+                $search_from = $pos_milieu;
1143
+                $nb_open = 1;
1144
+                $nb_close = 1;
1145
+                $maxiter = 0;
1146
+                do {
1147
+                    while (
1148
+                        $nb_close < $nb_open
1149
+                        and $p = strpos($texte, $fin_boucle, $pos_fin + 1)
1150
+                    ) {
1151
+                        $nb_close++;
1152
+                        $pos_fin = $p;
1153
+                    }
1154
+                    // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux
1155
+                    if ($nb_close < $nb_open) {
1156
+                        break;
1157
+                    }
1158
+                    while (
1159
+                        $p = strpos($texte, $search_debut_boucle, $search_from)
1160
+                        and $p < $pos_fin
1161
+                    ) {
1162
+                        $nb_open++;
1163
+                        $search_from = $p + 1;
1164
+                    }
1165
+                } while ($nb_close < $nb_open and $maxiter++ < 5);
1166
+
1167
+                $pos_courante = $pos_fin + strlen($fin_boucle);
1168
+            }
1169
+            $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu);
1170
+        }
1171
+
1172
+        $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante);
1173
+        $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result);
1174
+
1175
+        //
1176
+        // 1. Partie conditionnelle apres ?
1177
+        //
1178
+        if ($boucle['pos_postcond']) {
1179
+            $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante);
1180
+            $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']);
1181
+            $pos_courante = $boucle['pos_postcond_inside'] ;
1182
+        }
1183
+
1184
+
1185
+        //
1186
+        // 2. Partie alternative apres ?
1187
+        //
1188
+        $ligne_altern = $ligne_suite;
1189
+        if ($boucle['pos_altern']) {
1190
+            $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante);
1191
+            $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']);
1192
+            $pos_courante = $boucle['pos_altern_inside'];
1193
+        }
1194
+
1195
+        //
1196
+        // 3. Partie footer non alternative ?
1197
+        //
1198
+        $ligne_postaff = $ligne_suite;
1199
+        if ($boucle['pos_postaff']) {
1200
+            $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante);
1201
+            $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']);
1202
+            $pos_courante = $boucle['pos_postaff_inside'];
1203
+        }
1204
+
1205
+        $result->ligne = $ligne_preaff;
1206
+
1207
+        if ($p = strpos($type, ':')) {
1208
+            $result->sql_serveur = substr($type, 0, $p);
1209
+            $type = substr($type, $p + 1);
1210
+        }
1211
+        $soustype = strtolower($type);
1212
+
1213
+        if (!isset($GLOBALS['table_des_tables'][$soustype])) {
1214
+            $soustype = $type;
1215
+        }
1216
+
1217
+        $result->type_requete = $soustype;
1218
+        // Lancer la 2e passe sur les criteres si la 1ere etait bonne
1219
+        if (!is_array($result->param)) {
1220
+            $err_b = true;
1221
+        } else {
1222
+            phraser_criteres($result->param, $result);
1223
+            if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) {
1224
+                $result->type_requete = TYPE_RECURSIF;
1225
+                $args = $result->param;
1226
+                array_unshift(
1227
+                    $args,
1228
+                    substr($type, strlen(TYPE_RECURSIF))
1229
+                );
1230
+                $result->param = $args;
1231
+            }
1232
+        }
1233
+
1234
+        $descr['id_mere_contexte'] = $id_boucle;
1235
+        $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder);
1236
+        // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre
1237
+        // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle
1238
+        // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite
1239
+        if (empty($boucles[$id_boucle])) {
1240
+            $boucles[$id_boucle] = null;
1241
+        }
1242
+        $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder);
1243
+        $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder);
1244
+        $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder);
1245
+        $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder);
1246
+        $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder);
1247
+
1248
+        // Prevenir le generateur de code que le squelette est faux
1249
+        if ($err_b) {
1250
+            $result->type_requete = false;
1251
+        }
1252
+
1253
+        // Verifier qu'il n'y a pas double definition
1254
+        // apres analyse des sous-parties (pas avant).
1255
+        if (!empty($boucles[$id_boucle])) {
1256
+            if ($boucles[$id_boucle]->type_requete !== false) {
1257
+                $err_b_d = [
1258
+                    'zbug_erreur_boucle_double',
1259
+                    ['id' => $id_boucle]
1260
+                ];
1261
+                erreur_squelette($err_b_d, $result);
1262
+                // Prevenir le generateur de code que le squelette est faux
1263
+                $boucles[$id_boucle]->type_requete = false;
1264
+            }
1265
+        } else {
1266
+            $boucles[$id_boucle] = $result;
1267
+        }
1268
+
1269
+        // remplacer la boucle par un placeholder qui compte le meme nombre de lignes
1270
+        $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte);
1271
+        $longueur_boucle = $pos_courante - $boucle['debut_boucle'];
1272
+        $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle);
1273
+        $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder);
1274
+
1275
+        // phraser la partie avant le debut de la boucle
1276
+        #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res);
1277
+        #$all_res[] = &$boucles[$id_boucle];
1278
+
1279
+        $ligne_debut_texte = $ligne_suite;
1280
+        $pos_debut_texte = $pos_courante;
1281
+    }
1282
+
1283
+    $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res);
1284
+
1285
+    return $all_res;
1286 1286
 }
Please login to merge, or discard this patch.
ecrire/genie/maintenance.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -35,19 +35,19 @@  discard block
 block discarded – undo
35 35
  */
36 36
 function genie_maintenance_dist($t) {
37 37
 
38
-	// (re)mettre .htaccess avec deny from all
39
-	// dans les deux repertoires dits inaccessibles par http
40
-	include_spip('inc/acces');
41
-	verifier_htaccess(_DIR_ETC);
42
-	verifier_htaccess(_DIR_TMP);
43
-	verifier_htaccess(_DIR_VENDOR);
38
+    // (re)mettre .htaccess avec deny from all
39
+    // dans les deux repertoires dits inaccessibles par http
40
+    include_spip('inc/acces');
41
+    verifier_htaccess(_DIR_ETC);
42
+    verifier_htaccess(_DIR_TMP);
43
+    verifier_htaccess(_DIR_VENDOR);
44 44
 
45
-	// Verifier qu'aucune table n'est crashee
46
-	if (!_request('reinstall')) {
47
-		verifier_crash_tables();
48
-	}
45
+    // Verifier qu'aucune table n'est crashee
46
+    if (!_request('reinstall')) {
47
+        verifier_crash_tables();
48
+    }
49 49
 
50
-	return 1;
50
+    return 1;
51 51
 }
52 52
 
53 53
 
@@ -64,33 +64,33 @@  discard block
 block discarded – undo
64 64
  *     des tables qui ont crashé.
65 65
  */
66 66
 function verifier_crash_tables() {
67
-	if (spip_connect()) {
68
-		include_spip('base/serial');
69
-		include_spip('base/auxiliaires');
70
-		$crash = [];
71
-		foreach (['tables_principales', 'tables_auxiliaires'] as $com) {
72
-			foreach ($GLOBALS[$com] as $table => $desc) {
73
-				if (
74
-					!sql_select('*', $table, '', '', '', 1)
75
-					and !defined('spip_interdire_cache')
76
-				) { # cas "LOST CONNECTION"
77
-				$crash[] = $table;
78
-				}
79
-			}
80
-		}
81
-		#$crash[] = 'test';
82
-		if ($crash) {
83
-			ecrire_meta('message_crash_tables', serialize($crash));
84
-			spip_log('crash des tables', 'err');
85
-			spip_log($crash, 'err');
86
-		} else {
87
-			effacer_meta('message_crash_tables');
88
-		}
67
+    if (spip_connect()) {
68
+        include_spip('base/serial');
69
+        include_spip('base/auxiliaires');
70
+        $crash = [];
71
+        foreach (['tables_principales', 'tables_auxiliaires'] as $com) {
72
+            foreach ($GLOBALS[$com] as $table => $desc) {
73
+                if (
74
+                    !sql_select('*', $table, '', '', '', 1)
75
+                    and !defined('spip_interdire_cache')
76
+                ) { # cas "LOST CONNECTION"
77
+                $crash[] = $table;
78
+                }
79
+            }
80
+        }
81
+        #$crash[] = 'test';
82
+        if ($crash) {
83
+            ecrire_meta('message_crash_tables', serialize($crash));
84
+            spip_log('crash des tables', 'err');
85
+            spip_log($crash, 'err');
86
+        } else {
87
+            effacer_meta('message_crash_tables');
88
+        }
89 89
 
90
-		return $crash;
91
-	}
90
+        return $crash;
91
+    }
92 92
 
93
-	return false;
93
+    return false;
94 94
 }
95 95
 
96 96
 /**
@@ -106,16 +106,16 @@  discard block
 block discarded – undo
106 106
  * @return string
107 107
  */
108 108
 function message_crash_tables() {
109
-	if ($crash = verifier_crash_tables()) {
110
-		return
111
-			'<strong>' . _T('texte_recuperer_base') . '</strong><br />'
112
-			. ' <tt>' . join(', ', $crash) . '</tt><br />'
113
-			. generer_form_ecrire(
114
-				'base_repair',
115
-				_T('texte_crash_base'),
116
-				'',
117
-				_T('bouton_tenter_recuperation')
118
-			);
119
-	}
120
-	return '';
109
+    if ($crash = verifier_crash_tables()) {
110
+        return
111
+            '<strong>' . _T('texte_recuperer_base') . '</strong><br />'
112
+            . ' <tt>' . join(', ', $crash) . '</tt><br />'
113
+            . generer_form_ecrire(
114
+                'base_repair',
115
+                _T('texte_crash_base'),
116
+                '',
117
+                _T('bouton_tenter_recuperation')
118
+            );
119
+    }
120
+    return '';
121 121
 }
Please login to merge, or discard this patch.
ecrire/iterateur/data.php 1 patch
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -19,11 +19,11 @@  discard block
 block discarded – undo
19 19
  **/
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 if (!defined('_DATA_SOURCE_MAX_SIZE')) {
26
-	define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576);
26
+    define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576);
27 27
 }
28 28
 
29 29
 
@@ -44,17 +44,17 @@  discard block
 block discarded – undo
44 44
  *     Description de la boucle complétée des champs
45 45
  */
46 46
 function iterateur_DATA_dist($b) {
47
-	$b->iterateur = 'DATA'; # designe la classe d'iterateur
48
-	$b->show = [
49
-		'field' => [
50
-			'cle' => 'STRING',
51
-			'valeur' => 'STRING',
52
-			'*' => 'ALL' // Champ joker *
53
-		]
54
-	];
55
-	$b->select[] = '.valeur';
56
-
57
-	return $b;
47
+    $b->iterateur = 'DATA'; # designe la classe d'iterateur
48
+    $b->show = [
49
+        'field' => [
50
+            'cle' => 'STRING',
51
+            'valeur' => 'STRING',
52
+            '*' => 'ALL' // Champ joker *
53
+        ]
54
+    ];
55
+    $b->select[] = '.valeur';
56
+
57
+    return $b;
58 58
 }
59 59
 
60 60
 
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
  * @return array
70 70
  */
71 71
 function inc_file_to_array_dist($data) {
72
-	return preg_split('/\r?\n/', $data);
72
+    return preg_split('/\r?\n/', $data);
73 73
 }
74 74
 
75 75
 /**
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
  * @return array
79 79
  */
80 80
 function inc_plugins_to_array_dist() {
81
-	include_spip('inc/plugin');
81
+    include_spip('inc/plugin');
82 82
 
83
-	return liste_chemin_plugin_actifs();
83
+    return liste_chemin_plugin_actifs();
84 84
 }
85 85
 
86 86
 /**
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
  * @return array
91 91
  */
92 92
 function inc_xml_to_array_dist($data) {
93
-	return @XMLObjectToArray(new SimpleXmlIterator($data));
93
+    return @XMLObjectToArray(new SimpleXmlIterator($data));
94 94
 }
95 95
 
96 96
 /**
@@ -102,14 +102,14 @@  discard block
 block discarded – undo
102 102
  *
103 103
  */
104 104
 function inc_object_to_array($object) {
105
-	if (!is_object($object) && !is_array($object)) {
106
-		return $object;
107
-	}
108
-	if (is_object($object)) {
109
-		$object = get_object_vars($object);
110
-	}
111
-
112
-	return array_map('inc_object_to_array', $object);
105
+    if (!is_object($object) && !is_array($object)) {
106
+        return $object;
107
+    }
108
+    if (is_object($object)) {
109
+        $object = get_object_vars($object);
110
+    }
111
+
112
+    return array_map('inc_object_to_array', $object);
113 113
 }
114 114
 
115 115
 /**
@@ -119,20 +119,20 @@  discard block
 block discarded – undo
119 119
  * @return array|bool
120 120
  */
121 121
 function inc_sql_to_array_dist($data) {
122
-	# sortir le connecteur de $data
123
-	preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v);
124
-	$serveur = (string)$v[1];
125
-	$req = trim($v[2]);
126
-	if ($s = sql_query($req, $serveur)) {
127
-		$r = [];
128
-		while ($t = sql_fetch($s)) {
129
-			$r[] = $t;
130
-		}
131
-
132
-		return $r;
133
-	}
134
-
135
-	return false;
122
+    # sortir le connecteur de $data
123
+    preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v);
124
+    $serveur = (string)$v[1];
125
+    $req = trim($v[2]);
126
+    if ($s = sql_query($req, $serveur)) {
127
+        $r = [];
128
+        while ($t = sql_fetch($s)) {
129
+            $r[] = $t;
130
+        }
131
+
132
+        return $r;
133
+    }
134
+
135
+    return false;
136 136
 }
137 137
 
138 138
 /**
@@ -142,13 +142,13 @@  discard block
 block discarded – undo
142 142
  * @return array|bool
143 143
  */
144 144
 function inc_json_to_array_dist($data) {
145
-	try {
146
-		$json = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
147
-	} catch (JsonException $e) {
148
-		$json = null;
149
-		spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO);
150
-	}
151
-	return is_array($json) ? (array) $json : [];
145
+    try {
146
+        $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
147
+    } catch (JsonException $e) {
148
+        $json = null;
149
+        spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO);
150
+    }
151
+    return is_array($json) ? (array) $json : [];
152 152
 }
153 153
 
154 154
 /**
@@ -158,30 +158,30 @@  discard block
 block discarded – undo
158 158
  * @return array|bool
159 159
  */
160 160
 function inc_csv_to_array_dist($data) {
161
-	include_spip('inc/csv');
162
-	[$entete, $csv] = analyse_csv($data);
163
-	array_unshift($csv, $entete);
164
-
165
-	include_spip('inc/charsets');
166
-	$i = 1;
167
-	foreach ($entete as $k => $v) {
168
-		if (trim($v) == '') {
169
-			$v = 'col' . $i;
170
-		} // reperer des eventuelles cases vides
171
-		if (is_numeric($v) and $v < 0) {
172
-			$v = '__' . $v;
173
-		} // ne pas risquer d'ecraser une cle numerique
174
-		if (is_numeric($v)) {
175
-			$v = '_' . $v;
176
-		} // ne pas risquer d'ecraser une cle numerique
177
-		$v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
178
-		foreach ($csv as &$item) {
179
-			$item[$v] = &$item[$k];
180
-		}
181
-		$i++;
182
-	}
183
-
184
-	return $csv;
161
+    include_spip('inc/csv');
162
+    [$entete, $csv] = analyse_csv($data);
163
+    array_unshift($csv, $entete);
164
+
165
+    include_spip('inc/charsets');
166
+    $i = 1;
167
+    foreach ($entete as $k => $v) {
168
+        if (trim($v) == '') {
169
+            $v = 'col' . $i;
170
+        } // reperer des eventuelles cases vides
171
+        if (is_numeric($v) and $v < 0) {
172
+            $v = '__' . $v;
173
+        } // ne pas risquer d'ecraser une cle numerique
174
+        if (is_numeric($v)) {
175
+            $v = '_' . $v;
176
+        } // ne pas risquer d'ecraser une cle numerique
177
+        $v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
178
+        foreach ($csv as &$item) {
179
+            $item[$v] = &$item[$k];
180
+        }
181
+        $i++;
182
+    }
183
+
184
+    return $csv;
185 185
 }
186 186
 
187 187
 /**
@@ -191,13 +191,13 @@  discard block
 block discarded – undo
191 191
  * @return array|bool
192 192
  */
193 193
 function inc_rss_to_array_dist($data) {
194
-	$tableau = null;
195
-	include_spip('inc/syndic');
196
-	if (is_array($rss = analyser_backend($data))) {
197
-		$tableau = $rss;
198
-	}
194
+    $tableau = null;
195
+    include_spip('inc/syndic');
196
+    if (is_array($rss = analyser_backend($data))) {
197
+        $tableau = $rss;
198
+    }
199 199
 
200
-	return $tableau;
200
+    return $tableau;
201 201
 }
202 202
 
203 203
 /**
@@ -207,9 +207,9 @@  discard block
 block discarded – undo
207 207
  * @return array|bool
208 208
  */
209 209
 function inc_atom_to_array_dist($data) {
210
-	$rss_to_array = charger_fonction('rss_to_array', 'inc');
210
+    $rss_to_array = charger_fonction('rss_to_array', 'inc');
211 211
 
212
-	return $rss_to_array($data);
212
+    return $rss_to_array($data);
213 213
 }
214 214
 
215 215
 /**
@@ -220,12 +220,12 @@  discard block
 block discarded – undo
220 220
  * @return array|bool
221 221
  */
222 222
 function inc_glob_to_array_dist($data) {
223
-	$a = glob(
224
-		$data,
225
-		GLOB_MARK | GLOB_NOSORT | GLOB_BRACE
226
-	);
223
+    $a = glob(
224
+        $data,
225
+        GLOB_MARK | GLOB_NOSORT | GLOB_BRACE
226
+    );
227 227
 
228
-	return $a ?: [];
228
+    return $a ?: [];
229 229
 }
230 230
 
231 231
 /**
@@ -236,14 +236,14 @@  discard block
 block discarded – undo
236 236
  * @throws Exception
237 237
  */
238 238
 function inc_yaml_to_array_dist($data) {
239
-	include_spip('inc/yaml-mini');
240
-	if (!function_exists('yaml_decode')) {
241
-		throw new Exception('YAML: impossible de trouver la fonction yaml_decode');
239
+    include_spip('inc/yaml-mini');
240
+    if (!function_exists('yaml_decode')) {
241
+        throw new Exception('YAML: impossible de trouver la fonction yaml_decode');
242 242
 
243
-		return false;
244
-	}
243
+        return false;
244
+    }
245 245
 
246
-	return yaml_decode($data);
246
+    return yaml_decode($data);
247 247
 }
248 248
 
249 249
 
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
  * @return array|bool
259 259
  */
260 260
 function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) {
261
-	return (array)preg_files($dir, $regexp, $limit);
261
+    return (array)preg_files($dir, $regexp, $limit);
262 262
 }
263 263
 
264 264
 /**
@@ -270,23 +270,23 @@  discard block
 block discarded – undo
270 270
  * @return array|bool
271 271
  */
272 272
 function inc_ls_to_array_dist($data) {
273
-	$glob_to_array = charger_fonction('glob_to_array', 'inc');
274
-	$a = $glob_to_array($data);
275
-	foreach ($a as &$v) {
276
-		$b = (array)@stat($v);
277
-		foreach ($b as $k => $ignore) {
278
-			if (is_numeric($k)) {
279
-				unset($b[$k]);
280
-			}
281
-		}
282
-		$b['file'] = preg_replace('`/$`', '', $v) ;
283
-		$v = array_merge(
284
-			pathinfo($v),
285
-			$b
286
-		);
287
-	}
288
-
289
-	return $a;
273
+    $glob_to_array = charger_fonction('glob_to_array', 'inc');
274
+    $a = $glob_to_array($data);
275
+    foreach ($a as &$v) {
276
+        $b = (array)@stat($v);
277
+        foreach ($b as $k => $ignore) {
278
+            if (is_numeric($k)) {
279
+                unset($b[$k]);
280
+            }
281
+        }
282
+        $b['file'] = preg_replace('`/$`', '', $v) ;
283
+        $v = array_merge(
284
+            pathinfo($v),
285
+            $b
286
+        );
287
+    }
288
+
289
+    return $a;
290 290
 }
291 291
 
292 292
 /**
@@ -296,25 +296,25 @@  discard block
 block discarded – undo
296 296
  * @return array|bool
297 297
  */
298 298
 function XMLObjectToArray($object) {
299
-	$xml_array = [];
300
-	for ($object->rewind(); $object->valid(); $object->next()) {
301
-		if (array_key_exists($key = $object->key(), $xml_array)) {
302
-			$key .= '-' . uniqid();
303
-		}
304
-		$vars = get_object_vars($object->current());
305
-		if (isset($vars['@attributes'])) {
306
-			foreach ($vars['@attributes'] as $k => $v) {
307
-				$xml_array[$key][$k] = $v;
308
-			}
309
-		}
310
-		if ($object->hasChildren()) {
311
-			$xml_array[$key][] = XMLObjectToArray(
312
-				$object->current()
313
-			);
314
-		} else {
315
-			$xml_array[$key][] = strval($object->current());
316
-		}
317
-	}
318
-
319
-	return $xml_array;
299
+    $xml_array = [];
300
+    for ($object->rewind(); $object->valid(); $object->next()) {
301
+        if (array_key_exists($key = $object->key(), $xml_array)) {
302
+            $key .= '-' . uniqid();
303
+        }
304
+        $vars = get_object_vars($object->current());
305
+        if (isset($vars['@attributes'])) {
306
+            foreach ($vars['@attributes'] as $k => $v) {
307
+                $xml_array[$key][$k] = $v;
308
+            }
309
+        }
310
+        if ($object->hasChildren()) {
311
+            $xml_array[$key][] = XMLObjectToArray(
312
+                $object->current()
313
+            );
314
+        } else {
315
+            $xml_array[$key][] = strval($object->current());
316
+        }
317
+    }
318
+
319
+    return $xml_array;
320 320
 }
Please login to merge, or discard this patch.
ecrire/iterateur/condition.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  **/
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 include_spip('iterateur/data');
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
  *     Description de la boucle complétée des champs
38 38
  */
39 39
 function iterateur_CONDITION_dist($b) {
40
-	$b->iterateur = 'CONDITION'; # designe la classe d'iterateur
41
-	$b->show = [
42
-		'field' => []
43
-	];
40
+    $b->iterateur = 'CONDITION'; # designe la classe d'iterateur
41
+    $b->show = [
42
+        'field' => []
43
+    ];
44 44
 
45
-	return $b;
45
+    return $b;
46 46
 }
Please login to merge, or discard this patch.
ecrire/iterateur/pour.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  **/
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 /**
@@ -38,13 +38,13 @@  discard block
 block discarded – undo
38 38
  *     Description de la boucle complétée des champs
39 39
  */
40 40
 function iterateur_POUR_dist($b) {
41
-	$b->iterateur = 'DATA'; # designe la classe d'iterateur
42
-	$b->show = [
43
-		'field' => [
44
-			'cle' => 'STRING',
45
-			'valeur' => 'STRING',
46
-		]
47
-	];
41
+    $b->iterateur = 'DATA'; # designe la classe d'iterateur
42
+    $b->show = [
43
+        'field' => [
44
+            'cle' => 'STRING',
45
+            'valeur' => 'STRING',
46
+        ]
47
+    ];
48 48
 
49
-	return $b;
49
+    return $b;
50 50
 }
Please login to merge, or discard this patch.
ecrire/iterateur/php.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 
21 21
 
22 22
 if (!defined('_ECRIRE_INC_VERSION')) {
23
-	return;
23
+    return;
24 24
 }
25 25
 
26 26
 
@@ -38,17 +38,17 @@  discard block
 block discarded – undo
38 38
  *     Description de la boucle complétée des champs
39 39
  */
40 40
 function iterateur_php_dist($b, $iteratorName) {
41
-	$b->iterateur = $iteratorName; # designe la classe d'iterateur
42
-	$b->show = [
43
-		'field' => [
44
-			'cle' => 'STRING',
45
-			'valeur' => 'STRING',
46
-		]
47
-	];
48
-
49
-	foreach (get_class_methods($iteratorName) as $method) {
50
-		$b->show['field'][strtolower($method)] = 'METHOD';
51
-	}
52
-
53
-	return $b;
41
+    $b->iterateur = $iteratorName; # designe la classe d'iterateur
42
+    $b->show = [
43
+        'field' => [
44
+            'cle' => 'STRING',
45
+            'valeur' => 'STRING',
46
+        ]
47
+    ];
48
+
49
+    foreach (get_class_methods($iteratorName) as $method) {
50
+        $b->show['field'][strtolower($method)] = 'METHOD';
51
+    }
52
+
53
+    return $b;
54 54
 }
Please login to merge, or discard this patch.
ecrire/inc/pipelines.php 1 patch
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -16,10 +16,10 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Pipelines
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 if (test_espace_prive()) {
22
-	include_spip('inc/pipelines_ecrire');
22
+    include_spip('inc/pipelines_ecrire');
23 23
 }
24 24
 
25 25
 
@@ -45,28 +45,28 @@  discard block
 block discarded – undo
45 45
  * @return string          Contenu qui sera inséré dans le head HTML
46 46
  **/
47 47
 function f_jQuery($texte) {
48
-	$x = '';
49
-	$jquery_plugins = pipeline(
50
-		'jquery_plugins',
51
-		[
52
-			'javascript/jquery.js',
53
-			'javascript/jquery.form.js',
54
-			'javascript/jquery.autosave.js',
55
-			'javascript/jquery.placeholder-label.js',
56
-			'javascript/ajaxCallback.js',
57
-			'javascript/js.cookie.js',
58
-		]
59
-	);
60
-	foreach (array_unique($jquery_plugins) as $script) {
61
-		if ($script = find_in_path(supprimer_timestamp($script))) {
62
-			$script = timestamp($script);
63
-			$x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
64
-		}
65
-	}
48
+    $x = '';
49
+    $jquery_plugins = pipeline(
50
+        'jquery_plugins',
51
+        [
52
+            'javascript/jquery.js',
53
+            'javascript/jquery.form.js',
54
+            'javascript/jquery.autosave.js',
55
+            'javascript/jquery.placeholder-label.js',
56
+            'javascript/ajaxCallback.js',
57
+            'javascript/js.cookie.js',
58
+        ]
59
+    );
60
+    foreach (array_unique($jquery_plugins) as $script) {
61
+        if ($script = find_in_path(supprimer_timestamp($script))) {
62
+            $script = timestamp($script);
63
+            $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
64
+        }
65
+    }
66 66
 
67
-	$texte = $x . $texte;
67
+    $texte = $x . $texte;
68 68
 
69
-	return $texte;
69
+    return $texte;
70 70
 }
71 71
 
72 72
 
@@ -85,28 +85,28 @@  discard block
 block discarded – undo
85 85
  * @return string         Contenu de la page envoyée au navigateur
86 86
  **/
87 87
 function f_surligne($texte) {
88
-	if (!$GLOBALS['html']) {
89
-		return $texte;
90
-	}
91
-	$rech = _request('var_recherche');
92
-	if (
93
-		!$rech
94
-		and (!defined('_SURLIGNE_RECHERCHE_REFERERS')
95
-			or !_SURLIGNE_RECHERCHE_REFERERS
96
-			or !isset($_SERVER['HTTP_REFERER']))
97
-	) {
98
-		return $texte;
99
-	}
100
-	include_spip('inc/surligne');
88
+    if (!$GLOBALS['html']) {
89
+        return $texte;
90
+    }
91
+    $rech = _request('var_recherche');
92
+    if (
93
+        !$rech
94
+        and (!defined('_SURLIGNE_RECHERCHE_REFERERS')
95
+            or !_SURLIGNE_RECHERCHE_REFERERS
96
+            or !isset($_SERVER['HTTP_REFERER']))
97
+    ) {
98
+        return $texte;
99
+    }
100
+    include_spip('inc/surligne');
101 101
 
102
-	if (isset($_SERVER['HTTP_REFERER'])) {
103
-		$_SERVER['HTTP_REFERER'] = preg_replace(',[^\w\,/#&;:-]+,', ' ', $_SERVER['HTTP_REFERER']);
104
-	}
105
-	if ($rech) {
106
-		$rech = preg_replace(',[^\w\,/#&;:-]+,', ' ', $rech);
107
-	}
102
+    if (isset($_SERVER['HTTP_REFERER'])) {
103
+        $_SERVER['HTTP_REFERER'] = preg_replace(',[^\w\,/#&;:-]+,', ' ', $_SERVER['HTTP_REFERER']);
104
+    }
105
+    if ($rech) {
106
+        $rech = preg_replace(',[^\w\,/#&;:-]+,', ' ', $rech);
107
+    }
108 108
 
109
-	return surligner_mots($texte, $rech);
109
+    return surligner_mots($texte, $rech);
110 110
 }
111 111
 
112 112
 /**
@@ -123,33 +123,33 @@  discard block
 block discarded – undo
123 123
  * @return string         Contenu de la page envoyée au navigateur
124 124
  **/
125 125
 function f_tidy($texte) {
126
-	/**
127
-	 * Indentation à faire ?
128
-	 *
129
-	 * - true : actif.
130
-	 * - false par défaut.
131
-	 */
126
+    /**
127
+     * Indentation à faire ?
128
+     *
129
+     * - true : actif.
130
+     * - false par défaut.
131
+     */
132 132
 
133
-	if (
134
-		$GLOBALS['xhtml'] # tidy demande
135
-		and $GLOBALS['html'] # verifie que la page avait l'entete text/html
136
-		and strlen($texte)
137
-		and !headers_sent()
138
-	) {
139
-		# Compatibilite ascendante
140
-		if (!is_string($GLOBALS['xhtml'])) {
141
-			$GLOBALS['xhtml'] = 'tidy';
142
-		}
133
+    if (
134
+        $GLOBALS['xhtml'] # tidy demande
135
+        and $GLOBALS['html'] # verifie que la page avait l'entete text/html
136
+        and strlen($texte)
137
+        and !headers_sent()
138
+    ) {
139
+        # Compatibilite ascendante
140
+        if (!is_string($GLOBALS['xhtml'])) {
141
+            $GLOBALS['xhtml'] = 'tidy';
142
+        }
143 143
 
144
-		if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) {
145
-			spip_log("tidy absent, l'indenteur SPIP le remplace");
146
-			$f = charger_fonction('sax', 'xml');
147
-		}
144
+        if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) {
145
+            spip_log("tidy absent, l'indenteur SPIP le remplace");
146
+            $f = charger_fonction('sax', 'xml');
147
+        }
148 148
 
149
-		return $f($texte);
150
-	}
149
+        return $f($texte);
150
+    }
151 151
 
152
-	return $texte;
152
+    return $texte;
153 153
 }
154 154
 
155 155
 
@@ -168,21 +168,21 @@  discard block
 block discarded – undo
168 168
  * @return string         Contenu de la page envoyée au navigateur
169 169
  **/
170 170
 function f_insert_head($texte) {
171
-	if (!$GLOBALS['html']) {
172
-		return $texte;
173
-	}
174
-	include_spip('public/admin'); // pour strripos
171
+    if (!$GLOBALS['html']) {
172
+        return $texte;
173
+    }
174
+    include_spip('public/admin'); // pour strripos
175 175
 
176
-	($pos = stripos($texte, '</head>'))
177
-	|| ($pos = stripos($texte, '<body>'))
178
-	|| ($pos = 0);
176
+    ($pos = stripos($texte, '</head>'))
177
+    || ($pos = stripos($texte, '<body>'))
178
+    || ($pos = 0);
179 179
 
180
-	if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) {
181
-		$insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n";
182
-		$texte = substr_replace($texte, $insert, $pos, 0);
183
-	}
180
+    if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) {
181
+        $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n";
182
+        $texte = substr_replace($texte, $insert, $pos, 0);
183
+    }
184 184
 
185
-	return $texte;
185
+    return $texte;
186 186
 }
187 187
 
188 188
 
@@ -198,34 +198,34 @@  discard block
 block discarded – undo
198 198
  * @return string         Contenu de la page envoyée au navigateur
199 199
  **/
200 200
 function f_admin($texte) {
201
-	if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and $GLOBALS['html']) {
202
-		include_spip('inc/filtres'); // pour http_img_pack
203
-		$x = "<div class='spip-previsu' "
204
-			. http_style_background('preview-32.png', '', 32)
205
-			. '>'
206
-			. _T('previsualisation')
207
-			. '</div>';
208
-		if (!$pos = stripos($texte, '</body>')) {
209
-			$pos = strlen($texte);
210
-		}
211
-		$texte = substr_replace($texte, $x, $pos, 0);
212
-		// pas de preview en fenetre enfant
213
-		$x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes($GLOBALS['meta']['adresse_site']) . "';}</script>";
214
-		if (!$pos = stripos($texte, '<head') or !$pos = strpos($texte, '>', $pos)) {
215
-			$pos = -1;
216
-		}
217
-		$texte = substr_replace($texte, $x, $pos + 1, 0);
218
-	}
201
+    if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and $GLOBALS['html']) {
202
+        include_spip('inc/filtres'); // pour http_img_pack
203
+        $x = "<div class='spip-previsu' "
204
+            . http_style_background('preview-32.png', '', 32)
205
+            . '>'
206
+            . _T('previsualisation')
207
+            . '</div>';
208
+        if (!$pos = stripos($texte, '</body>')) {
209
+            $pos = strlen($texte);
210
+        }
211
+        $texte = substr_replace($texte, $x, $pos, 0);
212
+        // pas de preview en fenetre enfant
213
+        $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes($GLOBALS['meta']['adresse_site']) . "';}</script>";
214
+        if (!$pos = stripos($texte, '<head') or !$pos = strpos($texte, '>', $pos)) {
215
+            $pos = -1;
216
+        }
217
+        $texte = substr_replace($texte, $x, $pos + 1, 0);
218
+    }
219 219
 
220
-	if (isset($GLOBALS['affiche_boutons_admin']) and $GLOBALS['affiche_boutons_admin']) {
221
-		include_spip('public/admin');
222
-		$texte = affiche_boutons_admin($texte);
223
-	}
224
-	if (_request('var_mode') == 'noajax') {
225
-		$texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte);
226
-	}
220
+    if (isset($GLOBALS['affiche_boutons_admin']) and $GLOBALS['affiche_boutons_admin']) {
221
+        include_spip('public/admin');
222
+        $texte = affiche_boutons_admin($texte);
223
+    }
224
+    if (_request('var_mode') == 'noajax') {
225
+        $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte);
226
+    }
227 227
 
228
-	return $texte;
228
+    return $texte;
229 229
 }
230 230
 
231 231
 /**
@@ -243,11 +243,11 @@  discard block
 block discarded – undo
243 243
  * @return array $flux  Description et contenu de l'inclusion
244 244
  **/
245 245
 function f_recuperer_fond($flux) {
246
-	if (!test_espace_prive()) {
247
-		return $flux;
248
-	}
246
+    if (!test_espace_prive()) {
247
+        return $flux;
248
+    }
249 249
 
250
-	return f_afficher_blocs_ecrire($flux);
250
+    return f_afficher_blocs_ecrire($flux);
251 251
 }
252 252
 
253 253
 /**
@@ -261,30 +261,30 @@  discard block
 block discarded – undo
261 261
  * @return string         Contenu de la page envoyée au navigateur
262 262
  */
263 263
 function f_queue($texte) {
264
-	// eviter une inclusion si rien a faire
265
-	if (
266
-		_request('action') == 'cron'
267
-		or queue_sleep_time_to_next_job() > 0
268
-		or defined('_DEBUG_BLOCK_QUEUE')
269
-	) {
270
-		return $texte;
271
-	}
264
+    // eviter une inclusion si rien a faire
265
+    if (
266
+        _request('action') == 'cron'
267
+        or queue_sleep_time_to_next_job() > 0
268
+        or defined('_DEBUG_BLOCK_QUEUE')
269
+    ) {
270
+        return $texte;
271
+    }
272 272
 
273
-	include_spip('inc/queue');
274
-	$code = queue_affichage_cron();
273
+    include_spip('inc/queue');
274
+    $code = queue_affichage_cron();
275 275
 
276
-	// si rien a afficher
277
-	// ou si on est pas dans une page html, on ne sait rien faire de mieux
278
-	if (!$code or !isset($GLOBALS['html']) or !$GLOBALS['html']) {
279
-		return $texte;
280
-	}
276
+    // si rien a afficher
277
+    // ou si on est pas dans une page html, on ne sait rien faire de mieux
278
+    if (!$code or !isset($GLOBALS['html']) or !$GLOBALS['html']) {
279
+        return $texte;
280
+    }
281 281
 
282
-	// inserer avant le </body> fermant si on peut, a la fin de la page sinon
283
-	if (($p = strpos($texte, '</body>')) !== false) {
284
-		$texte = substr($texte, 0, $p) . $code . substr($texte, $p);
285
-	} else {
286
-		$texte .= $code;
287
-	}
282
+    // inserer avant le </body> fermant si on peut, a la fin de la page sinon
283
+    if (($p = strpos($texte, '</body>')) !== false) {
284
+        $texte = substr($texte, 0, $p) . $code . substr($texte, $p);
285
+    } else {
286
+        $texte .= $code;
287
+    }
288 288
 
289
-	return $texte;
289
+    return $texte;
290 290
 }
Please login to merge, or discard this patch.
ecrire/inc/lang.php 1 patch
Indentation   +256 added lines, -256 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Langue
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 
@@ -39,35 +39,35 @@  discard block
 block discarded – undo
39 39
  **/
40 40
 function changer_langue($lang, $liste_langues = null) {
41 41
 
42
-	if (is_null($liste_langues)) {
43
-		$liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? '');
44
-	} else {
45
-		if (is_array($liste_langues)) {
46
-			$liste_langues = implode(',', $liste_langues);
47
-		}
48
-	}
49
-	$liste_langues = ',' . $liste_langues . ',';
50
-
51
-	// Si la langue demandee n'existe pas, on essaie d'autres variantes
52
-	// Exemple : 'pt-br' => 'pt_br' => 'pt'
53
-	$lang = str_replace('-', '_', trim($lang));
54
-	if (!$lang) {
55
-		return false;
56
-	}
57
-
58
-	if (
59
-		strpos($liste_langues, (string) ",$lang,") !== false
60
-		or ($lang = preg_replace(',_.*,', '', $lang)
61
-			and str_contains($liste_langues, (string) ",$lang,"))
62
-	) {
63
-		$GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl');
64
-		$GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right';
65
-		$GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left';
66
-
67
-		return $GLOBALS['spip_lang'] = $lang;
68
-	} else {
69
-		return false;
70
-	}
42
+    if (is_null($liste_langues)) {
43
+        $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? '');
44
+    } else {
45
+        if (is_array($liste_langues)) {
46
+            $liste_langues = implode(',', $liste_langues);
47
+        }
48
+    }
49
+    $liste_langues = ',' . $liste_langues . ',';
50
+
51
+    // Si la langue demandee n'existe pas, on essaie d'autres variantes
52
+    // Exemple : 'pt-br' => 'pt_br' => 'pt'
53
+    $lang = str_replace('-', '_', trim($lang));
54
+    if (!$lang) {
55
+        return false;
56
+    }
57
+
58
+    if (
59
+        strpos($liste_langues, (string) ",$lang,") !== false
60
+        or ($lang = preg_replace(',_.*,', '', $lang)
61
+            and str_contains($liste_langues, (string) ",$lang,"))
62
+    ) {
63
+        $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl');
64
+        $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right';
65
+        $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left';
66
+
67
+        return $GLOBALS['spip_lang'] = $lang;
68
+    } else {
69
+        return false;
70
+    }
71 71
 }
72 72
 
73 73
 //
@@ -80,9 +80,9 @@  discard block
 block discarded – undo
80 80
 // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc.
81 81
 
82 82
 function choisir_traduction($trads, $lang = '') {
83
-	$k = approcher_langue($trads, $lang);
83
+    $k = approcher_langue($trads, $lang);
84 84
 
85
-	return $k ? $trads[$k] : array_shift($trads);
85
+    return $k ? $trads[$k] : array_shift($trads);
86 86
 }
87 87
 
88 88
 // retourne son 2e argument si c'est un index du premier
@@ -90,21 +90,21 @@  discard block
 block discarded – undo
90 90
 // la langue X etant consideree comme une approche de X_Y
91 91
 function approcher_langue($trads, $lang = '') {
92 92
 
93
-	if (!$lang) {
94
-		$lang = $GLOBALS['spip_lang'];
95
-	}
96
-
97
-	if (isset($trads[$lang])) {
98
-		return $lang;
99
-	} // cas des langues xx_yy
100
-	else {
101
-		$r = explode('_', $lang);
102
-		if (isset($trads[$r[0]])) {
103
-			return $r[0];
104
-		}
105
-	}
106
-
107
-	return '';
93
+    if (!$lang) {
94
+        $lang = $GLOBALS['spip_lang'];
95
+    }
96
+
97
+    if (isset($trads[$lang])) {
98
+        return $lang;
99
+    } // cas des langues xx_yy
100
+    else {
101
+        $r = explode('_', $lang);
102
+        if (isset($trads[$r[0]])) {
103
+            return $r[0];
104
+        }
105
+    }
106
+
107
+    return '';
108 108
 }
109 109
 
110 110
 /**
@@ -119,10 +119,10 @@  discard block
 block discarded – undo
119 119
  *     Nom de la langue, sinon son code.
120 120
  **/
121 121
 function traduire_nom_langue($lang) {
122
-	include_spip('inc/lang_liste');
123
-	include_spip('inc/charsets');
122
+    include_spip('inc/lang_liste');
123
+    include_spip('inc/charsets');
124 124
 
125
-	return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang);
125
+    return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang);
126 126
 }
127 127
 
128 128
 //
@@ -135,10 +135,10 @@  discard block
 block discarded – undo
135 135
 // hebreu a priori), 'droitier' sinon.
136 136
 // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT.
137 137
 function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') {
138
-	static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi'];
138
+    static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi'];
139 139
 
140
-	return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ?
141
-		$gaucher : $droitier;
140
+    return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ?
141
+        $gaucher : $droitier;
142 142
 }
143 143
 
144 144
 // typo francaise ou anglaise ?
@@ -147,29 +147,29 @@  discard block
 block discarded – undo
147 147
 // sinon determiner la typo en fonction de la langue courante
148 148
 
149 149
 function lang_typo($lang = '') {
150
-	if (!$lang) {
151
-		$lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang'];
152
-	}
153
-	if (
154
-		$lang == 'eo'
155
-		or $lang == 'fr'
156
-		or strncmp($lang, 'fr_', 3) == 0
157
-		or $lang == 'cpf'
158
-	) {
159
-		return 'fr';
160
-	} else {
161
-		return 'en';
162
-	}
150
+    if (!$lang) {
151
+        $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang'];
152
+    }
153
+    if (
154
+        $lang == 'eo'
155
+        or $lang == 'fr'
156
+        or strncmp($lang, 'fr_', 3) == 0
157
+        or $lang == 'cpf'
158
+    ) {
159
+        return 'fr';
160
+    } else {
161
+        return 'en';
162
+    }
163 163
 }
164 164
 
165 165
 // gestion de la globale $lang_objet pour que les textes soient affiches
166 166
 // avec les memes typo et direction dans l'espace prive que dans le public
167 167
 function changer_typo($lang = '') {
168
-	if ($lang) {
169
-		$GLOBALS['lang_objet'] = $lang;
170
-	} else {
171
-		unset($GLOBALS['lang_objet']);
172
-	}
168
+    if ($lang) {
169
+        $GLOBALS['lang_objet'] = $lang;
170
+    } else {
171
+        unset($GLOBALS['lang_objet']);
172
+    }
173 173
 }
174 174
 
175 175
 //
@@ -179,58 +179,58 @@  discard block
 block discarded – undo
179 179
 // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax
180 180
 //
181 181
 function menu_langues($nom_select, $default = '') {
182
-	include_spip('inc/actions');
183
-
184
-	$langues = liste_options_langues($nom_select);
185
-	$ret = '';
186
-	if (!count($langues)) {
187
-		return '';
188
-	}
189
-
190
-	if (!$default) {
191
-		$default = $GLOBALS['spip_lang'];
192
-	}
193
-	foreach ($langues as $l) {
194
-		$selected = ($l == $default) ? ' selected=\'selected\'' : '';
195
-		$ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n";
196
-	}
197
-
198
-	if (!test_espace_prive()) {
199
-		$cible = self();
200
-		$base = '';
201
-	} else {
202
-		$cible = self();
203
-		$base = spip_connect() ? 'base' : '';
204
-	}
205
-
206
-	$change = ' onchange="this.parentNode.parentNode.submit()"';
207
-
208
-	return generer_action_auteur(
209
-		'converser',
210
-		$base,
211
-		$cible,
212
-		(select_langues($nom_select, $change, $ret)
213
-			. "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"),
214
-		" method='post'"
215
-	);
182
+    include_spip('inc/actions');
183
+
184
+    $langues = liste_options_langues($nom_select);
185
+    $ret = '';
186
+    if (!count($langues)) {
187
+        return '';
188
+    }
189
+
190
+    if (!$default) {
191
+        $default = $GLOBALS['spip_lang'];
192
+    }
193
+    foreach ($langues as $l) {
194
+        $selected = ($l == $default) ? ' selected=\'selected\'' : '';
195
+        $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n";
196
+    }
197
+
198
+    if (!test_espace_prive()) {
199
+        $cible = self();
200
+        $base = '';
201
+    } else {
202
+        $cible = self();
203
+        $base = spip_connect() ? 'base' : '';
204
+    }
205
+
206
+    $change = ' onchange="this.parentNode.parentNode.submit()"';
207
+
208
+    return generer_action_auteur(
209
+        'converser',
210
+        $base,
211
+        $cible,
212
+        (select_langues($nom_select, $change, $ret)
213
+            . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"),
214
+        " method='post'"
215
+    );
216 216
 }
217 217
 
218 218
 function select_langues($nom_select, $change, $options, $label = '') {
219
-	static $cpt = 0;
220
-	$id = 'menu_langues' . $cpt++;
221
-
222
-	return
223
-		"<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' .
224
-		"<select name='$nom_select' id='$id' "
225
-		. ((!test_espace_prive()) ?
226
-			("class='forml menu_langues'") :
227
-			(($nom_select == 'var_lang_ecrire') ?
228
-				("class='lang_ecrire'") :
229
-				"class='fondl'"))
230
-		. $change
231
-		. ">\n"
232
-		. $options
233
-		. '</select>';
219
+    static $cpt = 0;
220
+    $id = 'menu_langues' . $cpt++;
221
+
222
+    return
223
+        "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' .
224
+        "<select name='$nom_select' id='$id' "
225
+        . ((!test_espace_prive()) ?
226
+            ("class='forml menu_langues'") :
227
+            (($nom_select == 'var_lang_ecrire') ?
228
+                ("class='lang_ecrire'") :
229
+                "class='fondl'"))
230
+        . $change
231
+        . ">\n"
232
+        . $options
233
+        . '</select>';
234 234
 }
235 235
 
236 236
 /**
@@ -252,34 +252,34 @@  discard block
 block discarded – undo
252 252
  */
253 253
 function liste_options_langues($nom_select) {
254 254
 
255
-	switch ($nom_select) {
256
-		# #MENU_LANG
257
-		case 'var_lang':
258
-			# menu de changement de la langue d'un article
259
-			# les langues selectionnees dans la configuration "multilinguisme"
260
-		case 'changer_lang':
261
-			$langues = explode(',', $GLOBALS['meta']['langues_multilingue']);
262
-			break;
263
-		# menu de l'interface (privee, installation et panneau de login)
264
-		# les langues presentes sous forme de fichiers de langue
265
-		# on force la relecture du repertoire des langues pour etre synchrone.
266
-		case 'var_lang_ecrire':
267
-		default:
268
-			$GLOBALS['meta']['langues_proposees'] = '';
269
-			init_langues();
270
-			$langues = explode(',', $GLOBALS['meta']['langues_proposees']);
271
-			break;
255
+    switch ($nom_select) {
256
+        # #MENU_LANG
257
+        case 'var_lang':
258
+            # menu de changement de la langue d'un article
259
+            # les langues selectionnees dans la configuration "multilinguisme"
260
+        case 'changer_lang':
261
+            $langues = explode(',', $GLOBALS['meta']['langues_multilingue']);
262
+            break;
263
+        # menu de l'interface (privee, installation et panneau de login)
264
+        # les langues presentes sous forme de fichiers de langue
265
+        # on force la relecture du repertoire des langues pour etre synchrone.
266
+        case 'var_lang_ecrire':
267
+        default:
268
+            $GLOBALS['meta']['langues_proposees'] = '';
269
+            init_langues();
270
+            $langues = explode(',', $GLOBALS['meta']['langues_proposees']);
271
+            break;
272 272
 
273 273
 # dernier choix possible : toutes les langues = langues_proposees
274 274
 # + langues_multilingues ; mais, ne sert pas
275 275
 #			$langues = explode(',', $GLOBALS['all_langs']);
276
-	}
277
-	if (count($langues) <= 1) {
278
-		return [];
279
-	}
280
-	sort($langues);
276
+    }
277
+    if (count($langues) <= 1) {
278
+        return [];
279
+    }
280
+    sort($langues);
281 281
 
282
-	return $langues;
282
+    return $langues;
283 283
 }
284 284
 
285 285
 
@@ -294,39 +294,39 @@  discard block
 block discarded – undo
294 294
  **/
295 295
 function verifier_lang_url() {
296 296
 
297
-	// quelle langue est demandee ?
298
-	$lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']);
299
-	if (isset($_COOKIE['spip_lang_ecrire'])) {
300
-		$lang_demandee = $_COOKIE['spip_lang_ecrire'];
301
-	}
302
-	if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) {
303
-		$lang_demandee = $_COOKIE['spip_lang'];
304
-	}
305
-	if (isset($_GET['lang'])) {
306
-		$lang_demandee = $_GET['lang'];
307
-	}
308
-
309
-	// Renvoyer si besoin (et si la langue demandee existe)
310
-	if (
311
-		$GLOBALS['spip_lang'] != $lang_demandee
312
-		and changer_langue($lang_demandee)
313
-		and $lang_demandee != @$_GET['lang']
314
-	) {
315
-		$destination = parametre_url(self(), 'lang', $lang_demandee, '&');
316
-		// ici on a besoin des var_truc
317
-		foreach ($_GET as $var => $val) {
318
-			if (!strncmp('var_', $var, 4)) {
319
-				$destination = parametre_url($destination, $var, $val, '&');
320
-			}
321
-		}
322
-		include_spip('inc/headers');
323
-		redirige_par_entete($destination);
324
-	}
325
-
326
-	// Subtilite : si la langue demandee par cookie est la bonne
327
-	// alors on fait comme si $lang etait passee dans l'URL
328
-	// (pour criteres {lang}).
329
-	$GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang'];
297
+    // quelle langue est demandee ?
298
+    $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']);
299
+    if (isset($_COOKIE['spip_lang_ecrire'])) {
300
+        $lang_demandee = $_COOKIE['spip_lang_ecrire'];
301
+    }
302
+    if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) {
303
+        $lang_demandee = $_COOKIE['spip_lang'];
304
+    }
305
+    if (isset($_GET['lang'])) {
306
+        $lang_demandee = $_GET['lang'];
307
+    }
308
+
309
+    // Renvoyer si besoin (et si la langue demandee existe)
310
+    if (
311
+        $GLOBALS['spip_lang'] != $lang_demandee
312
+        and changer_langue($lang_demandee)
313
+        and $lang_demandee != @$_GET['lang']
314
+    ) {
315
+        $destination = parametre_url(self(), 'lang', $lang_demandee, '&');
316
+        // ici on a besoin des var_truc
317
+        foreach ($_GET as $var => $val) {
318
+            if (!strncmp('var_', $var, 4)) {
319
+                $destination = parametre_url($destination, $var, $val, '&');
320
+            }
321
+        }
322
+        include_spip('inc/headers');
323
+        redirige_par_entete($destination);
324
+    }
325
+
326
+    // Subtilite : si la langue demandee par cookie est la bonne
327
+    // alors on fait comme si $lang etait passee dans l'URL
328
+    // (pour criteres {lang}).
329
+    $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang'];
330 330
 }
331 331
 
332 332
 
@@ -344,22 +344,22 @@  discard block
 block discarded – undo
344 344
  *     La langue sélectionnée
345 345
  **/
346 346
 function utiliser_langue_site($liste_langues = null) {
347
-	// s'il existe une langue du site (en gros tout le temps en théorie)
348
-	if (
349
-		isset($GLOBALS['meta']['langue_site'])
350
-		// et si spip_langue est pas encore définie (ce que va faire changer_langue())
351
-		// ou qu'elle n'est pas identique à la langue du site
352
-		and (!isset($GLOBALS['spip_lang'])
353
-			or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site'])
354
-	) {
355
-		return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install
356
-	}
357
-	// en theorie là, la globale est définie, sinon c'est un problème.
358
-	if (!isset($GLOBALS['spip_lang'])) {
359
-		spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR);
360
-	}
361
-
362
-	return $GLOBALS['spip_lang'];
347
+    // s'il existe une langue du site (en gros tout le temps en théorie)
348
+    if (
349
+        isset($GLOBALS['meta']['langue_site'])
350
+        // et si spip_langue est pas encore définie (ce que va faire changer_langue())
351
+        // ou qu'elle n'est pas identique à la langue du site
352
+        and (!isset($GLOBALS['spip_lang'])
353
+            or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site'])
354
+    ) {
355
+        return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install
356
+    }
357
+    // en theorie là, la globale est définie, sinon c'est un problème.
358
+    if (!isset($GLOBALS['spip_lang'])) {
359
+        spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR);
360
+    }
361
+
362
+    return $GLOBALS['spip_lang'];
363 363
 }
364 364
 
365 365
 /**
@@ -378,35 +378,35 @@  discard block
 block discarded – undo
378 378
  **/
379 379
 function utiliser_langue_visiteur($liste_langues = null) {
380 380
 
381
-	// si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie
382
-	if (is_null($liste_langues) and !test_espace_prive() and !empty($GLOBALS['meta']['langues_multilingue'])) {
383
-		$liste_langues = $GLOBALS['meta']['langues_multilingue'];
384
-	}
385
-
386
-	$l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire');
387
-	if (isset($_COOKIE[$l])) {
388
-		if (changer_langue($l = $_COOKIE[$l], $liste_langues)) {
389
-			return $l;
390
-		}
391
-	}
392
-
393
-	if (isset($GLOBALS['visiteur_session']['lang'])) {
394
-		if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) {
395
-			return $l;
396
-		}
397
-	}
398
-
399
-	if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
400
-		foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) {
401
-			if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) {
402
-				if (changer_langue($l = strtolower($r[1]), $liste_langues)) {
403
-					return $l;
404
-				}
405
-			}
406
-		}
407
-	}
408
-
409
-	return utiliser_langue_site($liste_langues);
381
+    // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie
382
+    if (is_null($liste_langues) and !test_espace_prive() and !empty($GLOBALS['meta']['langues_multilingue'])) {
383
+        $liste_langues = $GLOBALS['meta']['langues_multilingue'];
384
+    }
385
+
386
+    $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire');
387
+    if (isset($_COOKIE[$l])) {
388
+        if (changer_langue($l = $_COOKIE[$l], $liste_langues)) {
389
+            return $l;
390
+        }
391
+    }
392
+
393
+    if (isset($GLOBALS['visiteur_session']['lang'])) {
394
+        if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) {
395
+            return $l;
396
+        }
397
+    }
398
+
399
+    if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
400
+        foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) {
401
+            if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) {
402
+                if (changer_langue($l = strtolower($r[1]), $liste_langues)) {
403
+                    return $l;
404
+                }
405
+            }
406
+        }
407
+    }
408
+
409
+    return utiliser_langue_site($liste_langues);
410 410
 }
411 411
 
412 412
 
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
  * @return int
417 417
  */
418 418
 function match_langue($chaine) {
419
-	return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine);
419
+    return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine);
420 420
 }
421 421
 
422 422
 /**
@@ -434,36 +434,36 @@  discard block
 block discarded – undo
434 434
  **/
435 435
 function init_langues() {
436 436
 
437
-	// liste des langues dans les meta, sauf a l'install
438
-	$all_langs = $GLOBALS['meta']['langues_proposees'] ?? '';
439
-
440
-	$tout = [];
441
-	if (!$all_langs) {
442
-		// trouver tous les modules lang/spip_xx.php
443
-		$modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$');
444
-		foreach ($modules as $name => $path) {
445
-			if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) {
446
-				if (match_langue($regs[1])) {
447
-					$tout[] = $regs[1];
448
-				}
449
-			}
450
-		}
451
-		sort($tout);
452
-		$tout = join(',', $tout);
453
-		// Si les langues n'ont pas change, ne rien faire
454
-		if ($tout != $all_langs) {
455
-			$GLOBALS['meta']['langues_proposees'] = $tout;
456
-			include_spip('inc/meta');
457
-			ecrire_meta('langues_proposees', $tout);
458
-		}
459
-	}
460
-	if (!isset($GLOBALS['meta']['langue_site'])) {
461
-		// Initialisation : le francais si dispo, sinon la premiere langue trouvee
462
-		$GLOBALS['meta']['langue_site'] = $tout =
463
-			(!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false))
464
-				? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ','));
465
-		ecrire_meta('langue_site', $tout);
466
-	}
437
+    // liste des langues dans les meta, sauf a l'install
438
+    $all_langs = $GLOBALS['meta']['langues_proposees'] ?? '';
439
+
440
+    $tout = [];
441
+    if (!$all_langs) {
442
+        // trouver tous les modules lang/spip_xx.php
443
+        $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$');
444
+        foreach ($modules as $name => $path) {
445
+            if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) {
446
+                if (match_langue($regs[1])) {
447
+                    $tout[] = $regs[1];
448
+                }
449
+            }
450
+        }
451
+        sort($tout);
452
+        $tout = join(',', $tout);
453
+        // Si les langues n'ont pas change, ne rien faire
454
+        if ($tout != $all_langs) {
455
+            $GLOBALS['meta']['langues_proposees'] = $tout;
456
+            include_spip('inc/meta');
457
+            ecrire_meta('langues_proposees', $tout);
458
+        }
459
+    }
460
+    if (!isset($GLOBALS['meta']['langue_site'])) {
461
+        // Initialisation : le francais si dispo, sinon la premiere langue trouvee
462
+        $GLOBALS['meta']['langue_site'] = $tout =
463
+            (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false))
464
+                ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ','));
465
+        ecrire_meta('langue_site', $tout);
466
+    }
467 467
 }
468 468
 
469 469
 /**
@@ -477,10 +477,10 @@  discard block
 block discarded – undo
477 477
  *     Code html de la balise <html>
478 478
  **/
479 479
 function html_lang_attributes() {
480
-	$lang = $GLOBALS['spip_lang'];
481
-	$dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr');
480
+    $lang = $GLOBALS['spip_lang'];
481
+    $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr');
482 482
 
483
-	return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n";
483
+    return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n";
484 484
 }
485 485
 
486 486
 
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
  * @return string
495 495
  */
496 496
 function aide_lang_dir($spip_lang, $spip_lang_rtl) {
497
-	return ($spip_lang <> 'he') ? $spip_lang_rtl : '';
497
+    return ($spip_lang <> 'he') ? $spip_lang_rtl : '';
498 498
 }
499 499
 
500 500
 
Please login to merge, or discard this patch.