Completed
Push — master ( 0df2ac...a4a09d )
by cam
01:04
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 (count($filtres)) {
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 (count($filtres)) {
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/format_html.php 1 patch
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -11,129 +11,129 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 function format_boucle_html($preaff, $avant, $nom, $type, $crit, $corps, $apres, $altern, $postaff, $prof) {
18
-	$preaff = $preaff ? "<BB$nom>$preaff" : '';
19
-	$avant = $avant ? "<B$nom>$avant" : '';
20
-	$apres = $apres ? "$apres</B$nom>" : '';
21
-	$altern = $altern ? "$altern<//B$nom>" : '';
22
-	$postaff = $postaff ? "$postaff</BB$nom>" : '';
23
-	if (!$corps) {
24
-		$corps = ' />';
25
-	} else {
26
-		$corps = ">$corps</BOUCLE$nom>";
27
-	}
28
-
29
-	return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff";
18
+    $preaff = $preaff ? "<BB$nom>$preaff" : '';
19
+    $avant = $avant ? "<B$nom>$avant" : '';
20
+    $apres = $apres ? "$apres</B$nom>" : '';
21
+    $altern = $altern ? "$altern<//B$nom>" : '';
22
+    $postaff = $postaff ? "$postaff</BB$nom>" : '';
23
+    if (!$corps) {
24
+        $corps = ' />';
25
+    } else {
26
+        $corps = ">$corps</BOUCLE$nom>";
27
+    }
28
+
29
+    return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff";
30 30
 }
31 31
 
32 32
 function format_inclure_html($file, $args, $prof) {
33
-	if (strpos($file, '#') === false) {
34
-		$t = $file ? ('(' . $file . ')') : '';
35
-	} else {
36
-		$t = '{fond=' . $file . '}';
37
-	}
38
-	$args = !$args ? '' : ('{' . join(', ', $args) . '}');
39
-
40
-	return ('<INCLURE' . $t . $args . '>');
33
+    if (strpos($file, '#') === false) {
34
+        $t = $file ? ('(' . $file . ')') : '';
35
+    } else {
36
+        $t = '{fond=' . $file . '}';
37
+    }
38
+    $args = !$args ? '' : ('{' . join(', ', $args) . '}');
39
+
40
+    return ('<INCLURE' . $t . $args . '>');
41 41
 }
42 42
 
43 43
 function format_polyglotte_html($args, $prof) {
44
-	$contenu = [];
45
-	foreach ($args as $l => $t) {
46
-		$contenu[] = ($l ? "[$l]" : '') . $t;
47
-	}
44
+    $contenu = [];
45
+    foreach ($args as $l => $t) {
46
+        $contenu[] = ($l ? "[$l]" : '') . $t;
47
+    }
48 48
 
49
-	return ('<multi>' . join(' ', $contenu) . '</multi>');
49
+    return ('<multi>' . join(' ', $contenu) . '</multi>');
50 50
 }
51 51
 
52 52
 function format_idiome_html($nom, $module, $args, $filtres, $prof) {
53
-	foreach ($args as $k => $v) {
54
-		$args[$k] = "$k=$v";
55
-	}
56
-	$args = (!$args ? '' : ('{' . join(',', $args) . '}'));
53
+    foreach ($args as $k => $v) {
54
+        $args[$k] = "$k=$v";
55
+    }
56
+    $args = (!$args ? '' : ('{' . join(',', $args) . '}'));
57 57
 
58
-	return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>');
58
+    return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>');
59 59
 }
60 60
 
61 61
 function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) {
62
-	$nom = '#'
63
-		. ($boucle ? ($boucle . ':') : '')
64
-		. $nom
65
-		. $etoile
66
-		. $args
67
-		. $filtres;
62
+    $nom = '#'
63
+        . ($boucle ? ($boucle . ':') : '')
64
+        . $nom
65
+        . $etoile
66
+        . $args
67
+        . $filtres;
68 68
 
69
-	// Determiner si c'est un champ etendu,
69
+    // Determiner si c'est un champ etendu,
70 70
 
71
-	$s = ($avant or $apres or $filtres
72
-		or (strpos($args, '(#') !== false));
71
+    $s = ($avant or $apres or $filtres
72
+        or (strpos($args, '(#') !== false));
73 73
 
74
-	return ($s ? "[$avant($nom)$apres]" : $nom);
74
+    return ($s ? "[$avant($nom)$apres]" : $nom);
75 75
 }
76 76
 
77 77
 function format_critere_html($critere) {
78
-	foreach ($critere as $k => $crit) {
79
-		$crit_s = '';
80
-		foreach ($crit as $operande) {
81
-			list($type, $valeur) = $operande;
82
-			if ($type == 'champ' and $valeur[0] == '[') {
83
-				$valeur = substr($valeur, 1, -1);
84
-				if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) {
85
-					$valeur = substr($valeur, 1, -1);
86
-				}
87
-			}
88
-			$crit_s .= $valeur;
89
-		}
90
-		$critere[$k] = $crit_s;
91
-	}
92
-
93
-	return (!$critere ? '' : ('{' . join(',', $critere) . '}'));
78
+    foreach ($critere as $k => $crit) {
79
+        $crit_s = '';
80
+        foreach ($crit as $operande) {
81
+            list($type, $valeur) = $operande;
82
+            if ($type == 'champ' and $valeur[0] == '[') {
83
+                $valeur = substr($valeur, 1, -1);
84
+                if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) {
85
+                    $valeur = substr($valeur, 1, -1);
86
+                }
87
+            }
88
+            $crit_s .= $valeur;
89
+        }
90
+        $critere[$k] = $crit_s;
91
+    }
92
+
93
+    return (!$critere ? '' : ('{' . join(',', $critere) . '}'));
94 94
 }
95 95
 
96 96
 function format_liste_html($fonc, $args, $prof) {
97
-	return ((($fonc !== '') ? "|$fonc" : $fonc)
98
-		. (!$args ? '' : ('{' . join(',', $args) . '}')));
97
+    return ((($fonc !== '') ? "|$fonc" : $fonc)
98
+        . (!$args ? '' : ('{' . join(',', $args) . '}')));
99 99
 }
100 100
 
101 101
 // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes
102 102
 function format_suite_html($args) {
103
-	for ($i = 0; $i < count($args) - 1; $i++) {
104
-		list($texte, $type) = $args[$i];
105
-		list($texte2, $type2) = $args[$i + 1];
106
-		if (!$texte or !$texte2) {
107
-			continue;
108
-		}
109
-		$c1 = substr($texte, -1);
110
-		if ($type2 !== 'texte') {
111
-			// si un texte se termine par ( et est suivi d'un champ
112
-			// ou assimiles, forcer la notation pleine
113
-			if ($c1 == '(' and substr($texte2, 0, 1) == '#') {
114
-				$args[$i + 1][0] = '[(' . $texte2 . ')]';
115
-			}
116
-		} else {
117
-			if ($type == 'texte') {
118
-				continue;
119
-			}
120
-			// si un champ ou assimiles est suivi d'un texte
121
-			// et si celui-ci commence par un caractere de champ
122
-			// forcer la notation pleine
123
-			if (
124
-				($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|')
125
-				or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2))
126
-			) {
127
-				$args[$i][0] = '[(' . $texte . ')]';
128
-			}
129
-		}
130
-	}
131
-
132
-	return join('', array_map(function ($arg) {
133
- return reset($arg);
134
-	}, $args));
103
+    for ($i = 0; $i < count($args) - 1; $i++) {
104
+        list($texte, $type) = $args[$i];
105
+        list($texte2, $type2) = $args[$i + 1];
106
+        if (!$texte or !$texte2) {
107
+            continue;
108
+        }
109
+        $c1 = substr($texte, -1);
110
+        if ($type2 !== 'texte') {
111
+            // si un texte se termine par ( et est suivi d'un champ
112
+            // ou assimiles, forcer la notation pleine
113
+            if ($c1 == '(' and substr($texte2, 0, 1) == '#') {
114
+                $args[$i + 1][0] = '[(' . $texte2 . ')]';
115
+            }
116
+        } else {
117
+            if ($type == 'texte') {
118
+                continue;
119
+            }
120
+            // si un champ ou assimiles est suivi d'un texte
121
+            // et si celui-ci commence par un caractere de champ
122
+            // forcer la notation pleine
123
+            if (
124
+                ($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|')
125
+                or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2))
126
+            ) {
127
+                $args[$i][0] = '[(' . $texte . ')]';
128
+            }
129
+        }
130
+    }
131
+
132
+    return join('', array_map(function ($arg) {
133
+    return reset($arg);
134
+    }, $args));
135 135
 }
136 136
 
137 137
 function format_texte_html($texte) {
138
-	return $texte;
138
+    return $texte;
139 139
 }
Please login to merge, or discard this patch.
ecrire/public/styliser_par_z.php 1 patch
Indentation   +319 added lines, -319 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  * @package SPIP\Core\Public\Styliser
20 20
  **/
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 /**
@@ -29,193 +29,193 @@  discard block
 block discarded – undo
29 29
  * @return array Données modifiées du pipeline
30 30
  */
31 31
 function public_styliser_par_z_dist($flux) {
32
-	static $prefix_path = null;
33
-	static $prefix_length;
34
-	static $z_blocs;
35
-	static $apl_constant;
36
-	static $page;
37
-	static $disponible = [];
38
-	static $echafauder;
39
-	static $prepend = '';
40
-
41
-	if (!isset($prefix_path)) {
42
-		$z_blocs = z_blocs(test_espace_prive());
43
-		if (test_espace_prive()) {
44
-			$prefix_path = 'prive/squelettes/';
45
-			$prefix_length = strlen($prefix_path);
46
-			$apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD';
47
-			$page = 'exec';
48
-			$echafauder = charger_fonction('echafauder', 'prive', true);
49
-			define('_ZCORE_EXCLURE_PATH', '');
50
-		} else {
51
-			$prefix_path = '';
52
-			$prefix_length = 0;
53
-			$apl_constant = '_Z_AJAX_PARALLEL_LOAD';
54
-			$page = _SPIP_PAGE;
55
-			$echafauder = charger_fonction('echafauder', 'public', true);
56
-			define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim(
57
-				_DIR_PLUGIN_DIST,
58
-				'/'
59
-			) : ''));
60
-		}
61
-		$prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : '');
62
-	}
63
-	$z_contenu = reset($z_blocs); // contenu par defaut
64
-
65
-	$fond = $flux['args']['fond'];
66
-
67
-	if ($prepend or strncmp($fond, $prefix_path, $prefix_length) == 0) {
68
-		$fond = substr($fond, $prefix_length);
69
-		$squelette = $flux['data'];
70
-		$ext = $flux['args']['ext'];
71
-		// Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax
72
-		if (
73
-			defined('_Z_AJAX_PARALLEL_LOAD_OK')
74
-			and $dir = explode('/', $fond)
75
-			and count($dir) == 2 // pas un sous repertoire
76
-			and $dir = reset($dir)
77
-			and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z
78
-			and defined($apl_constant)
79
-			and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL
80
-			and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL
81
-		) {
82
-			$flux['data'] = $pipe;
83
-
84
-			return $flux;
85
-		}
86
-
87
-		// surcharger aussi les squelettes venant de squelettes-dist/
88
-		if ($squelette and !z_fond_valide($squelette)) {
89
-			$squelette = '';
90
-			$echafauder = '';
91
-		}
92
-		if ($prepend) {
93
-			$squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext"));
94
-			if ($squelette) {
95
-				$flux['data'] = $squelette;
96
-			}
97
-		}
98
-
99
-		// gerer les squelettes non trouves
100
-		// -> router vers les /dist.html
101
-		// ou scaffolding ou page automatique les contenus
102
-		if (!$squelette) {
103
-			// si on est sur un ?page=XX non trouve
104
-			if (
105
-				(isset($flux['args']['contexte'][$page])
106
-					and $flux['args']['contexte'][$page] == $fond)
107
-				or (isset($flux['args']['contexte']['type-page'])
108
-					and $flux['args']['contexte']['type-page'] == $fond)
109
-				or ($fond == 'sommaire'
110
-					and (!isset($flux['args']['contexte'][$page]) or !$flux['args']['contexte'][$page]))
111
-			) {
112
-				// si on est sur un ?page=XX non trouve
113
-				// se brancher sur contenu/xx si il existe
114
-				// ou si c'est un objet spip, associe a une table, utiliser le fond homonyme
115
-				if (!isset($disponible[$fond])) {
116
-					$disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder);
117
-				}
118
-
119
-				if ($disponible[$fond]) {
120
-					$flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext"));
121
-				}
122
-			}
123
-
124
-			// echafaudage :
125
-			// si c'est un fond de contenu d'un objet en base
126
-			// generer un fond automatique a la volee pour les webmestres
127
-			elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) {
128
-				$type = substr($fond, strlen($z_contenu) + 1);
129
-				if (($type == 'page') and isset($flux['args']['contexte'][$page])) {
130
-					$type = $flux['args']['contexte'][$page];
131
-				}
132
-				if (!isset($disponible[$type])) {
133
-					$disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder);
134
-				}
135
-				if (is_string($disponible[$type])) {
136
-					$flux['data'] = $disponible[$type];
137
-				} elseif (
138
-					$echafauder
139
-					and include_spip('inc/autoriser')
140
-					and isset($GLOBALS['visiteur_session']['statut']) // performance
141
-					and autoriser('echafauder', $type)
142
-					and $is = $disponible[$type]
143
-					and is_array($is)
144
-				) {
145
-					$flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext);
146
-				} else {
147
-					$flux['data'] = ($disponible['404'] = z_contenu_disponible(
148
-						$prefix_path . $prepend,
149
-						$z_contenu,
150
-						'404',
151
-						$ext,
152
-						$echafauder
153
-					));
154
-				}
155
-			}
156
-
157
-			// sinon, si on demande un fond non trouve dans un des autres blocs
158
-			// et si il y a bien un contenu correspondant ou echafaudable
159
-			// se rabbatre sur le dist.html du bloc concerne
160
-			else {
161
-				if (
162
-					$dir = explode('/', $fond)
163
-					and $dir = reset($dir)
164
-					and $dir !== $z_contenu
165
-					and in_array($dir, $z_blocs)
166
-				) {
167
-					$type = substr($fond, strlen("$dir/"));
168
-					if (($type == 'page') and isset($flux['args']['contexte'][$page])) {
169
-						$type = $flux['args']['contexte'][$page];
170
-					}
171
-					if ($type !== 'page' and !isset($disponible[$type])) {
172
-						$disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder);
173
-					}
174
-					if ($type == 'page' or $disponible[$type]) {
175
-						$flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext);
176
-					}
177
-				}
178
-			}
179
-			$squelette = $flux['data'];
180
-		}
181
-		// layout specifiques par type et compositions :
182
-		// body-article.html
183
-		// body-sommaire.html
184
-		// pour des raisons de perfo, les declinaisons doivent etre dans le
185
-		// meme dossier que body.html
186
-		if ($fond == 'body' and substr($squelette, -strlen($fond)) == $fond) {
187
-			if (
188
-				isset($flux['args']['contexte']['type-page'])
189
-				and (
190
-					(isset($flux['args']['contexte']['composition'])
191
-						and file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext"))
192
-					or
193
-					file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext")
194
-				)
195
-			) {
196
-				$flux['data'] = $f;
197
-			}
198
-		} elseif (
199
-			$fond == 'structure'
200
-			and z_sanitize_var_zajax()
201
-			and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext")
202
-		) {
203
-			$flux['data'] = substr($f, 0, -strlen(".$ext"));
204
-		} // chercher le fond correspondant a la composition
205
-		elseif (
206
-			isset($flux['args']['contexte']['composition'])
207
-			and (basename($fond) == 'page' or ($squelette and substr($squelette, -strlen($fond)) == $fond))
208
-			and $dir = substr($fond, $prefix_length)
209
-			and $dir = explode('/', $dir)
210
-			and $dir = reset($dir)
211
-			and in_array($dir, $z_blocs)
212
-			and $f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext")
213
-		) {
214
-			$flux['data'] = substr($f, 0, -strlen(".$ext"));
215
-		}
216
-	}
217
-
218
-	return $flux;
32
+    static $prefix_path = null;
33
+    static $prefix_length;
34
+    static $z_blocs;
35
+    static $apl_constant;
36
+    static $page;
37
+    static $disponible = [];
38
+    static $echafauder;
39
+    static $prepend = '';
40
+
41
+    if (!isset($prefix_path)) {
42
+        $z_blocs = z_blocs(test_espace_prive());
43
+        if (test_espace_prive()) {
44
+            $prefix_path = 'prive/squelettes/';
45
+            $prefix_length = strlen($prefix_path);
46
+            $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD';
47
+            $page = 'exec';
48
+            $echafauder = charger_fonction('echafauder', 'prive', true);
49
+            define('_ZCORE_EXCLURE_PATH', '');
50
+        } else {
51
+            $prefix_path = '';
52
+            $prefix_length = 0;
53
+            $apl_constant = '_Z_AJAX_PARALLEL_LOAD';
54
+            $page = _SPIP_PAGE;
55
+            $echafauder = charger_fonction('echafauder', 'public', true);
56
+            define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim(
57
+                _DIR_PLUGIN_DIST,
58
+                '/'
59
+            ) : ''));
60
+        }
61
+        $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : '');
62
+    }
63
+    $z_contenu = reset($z_blocs); // contenu par defaut
64
+
65
+    $fond = $flux['args']['fond'];
66
+
67
+    if ($prepend or strncmp($fond, $prefix_path, $prefix_length) == 0) {
68
+        $fond = substr($fond, $prefix_length);
69
+        $squelette = $flux['data'];
70
+        $ext = $flux['args']['ext'];
71
+        // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax
72
+        if (
73
+            defined('_Z_AJAX_PARALLEL_LOAD_OK')
74
+            and $dir = explode('/', $fond)
75
+            and count($dir) == 2 // pas un sous repertoire
76
+            and $dir = reset($dir)
77
+            and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z
78
+            and defined($apl_constant)
79
+            and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL
80
+            and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL
81
+        ) {
82
+            $flux['data'] = $pipe;
83
+
84
+            return $flux;
85
+        }
86
+
87
+        // surcharger aussi les squelettes venant de squelettes-dist/
88
+        if ($squelette and !z_fond_valide($squelette)) {
89
+            $squelette = '';
90
+            $echafauder = '';
91
+        }
92
+        if ($prepend) {
93
+            $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext"));
94
+            if ($squelette) {
95
+                $flux['data'] = $squelette;
96
+            }
97
+        }
98
+
99
+        // gerer les squelettes non trouves
100
+        // -> router vers les /dist.html
101
+        // ou scaffolding ou page automatique les contenus
102
+        if (!$squelette) {
103
+            // si on est sur un ?page=XX non trouve
104
+            if (
105
+                (isset($flux['args']['contexte'][$page])
106
+                    and $flux['args']['contexte'][$page] == $fond)
107
+                or (isset($flux['args']['contexte']['type-page'])
108
+                    and $flux['args']['contexte']['type-page'] == $fond)
109
+                or ($fond == 'sommaire'
110
+                    and (!isset($flux['args']['contexte'][$page]) or !$flux['args']['contexte'][$page]))
111
+            ) {
112
+                // si on est sur un ?page=XX non trouve
113
+                // se brancher sur contenu/xx si il existe
114
+                // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme
115
+                if (!isset($disponible[$fond])) {
116
+                    $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder);
117
+                }
118
+
119
+                if ($disponible[$fond]) {
120
+                    $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext"));
121
+                }
122
+            }
123
+
124
+            // echafaudage :
125
+            // si c'est un fond de contenu d'un objet en base
126
+            // generer un fond automatique a la volee pour les webmestres
127
+            elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) {
128
+                $type = substr($fond, strlen($z_contenu) + 1);
129
+                if (($type == 'page') and isset($flux['args']['contexte'][$page])) {
130
+                    $type = $flux['args']['contexte'][$page];
131
+                }
132
+                if (!isset($disponible[$type])) {
133
+                    $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder);
134
+                }
135
+                if (is_string($disponible[$type])) {
136
+                    $flux['data'] = $disponible[$type];
137
+                } elseif (
138
+                    $echafauder
139
+                    and include_spip('inc/autoriser')
140
+                    and isset($GLOBALS['visiteur_session']['statut']) // performance
141
+                    and autoriser('echafauder', $type)
142
+                    and $is = $disponible[$type]
143
+                    and is_array($is)
144
+                ) {
145
+                    $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext);
146
+                } else {
147
+                    $flux['data'] = ($disponible['404'] = z_contenu_disponible(
148
+                        $prefix_path . $prepend,
149
+                        $z_contenu,
150
+                        '404',
151
+                        $ext,
152
+                        $echafauder
153
+                    ));
154
+                }
155
+            }
156
+
157
+            // sinon, si on demande un fond non trouve dans un des autres blocs
158
+            // et si il y a bien un contenu correspondant ou echafaudable
159
+            // se rabbatre sur le dist.html du bloc concerne
160
+            else {
161
+                if (
162
+                    $dir = explode('/', $fond)
163
+                    and $dir = reset($dir)
164
+                    and $dir !== $z_contenu
165
+                    and in_array($dir, $z_blocs)
166
+                ) {
167
+                    $type = substr($fond, strlen("$dir/"));
168
+                    if (($type == 'page') and isset($flux['args']['contexte'][$page])) {
169
+                        $type = $flux['args']['contexte'][$page];
170
+                    }
171
+                    if ($type !== 'page' and !isset($disponible[$type])) {
172
+                        $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder);
173
+                    }
174
+                    if ($type == 'page' or $disponible[$type]) {
175
+                        $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext);
176
+                    }
177
+                }
178
+            }
179
+            $squelette = $flux['data'];
180
+        }
181
+        // layout specifiques par type et compositions :
182
+        // body-article.html
183
+        // body-sommaire.html
184
+        // pour des raisons de perfo, les declinaisons doivent etre dans le
185
+        // meme dossier que body.html
186
+        if ($fond == 'body' and substr($squelette, -strlen($fond)) == $fond) {
187
+            if (
188
+                isset($flux['args']['contexte']['type-page'])
189
+                and (
190
+                    (isset($flux['args']['contexte']['composition'])
191
+                        and file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext"))
192
+                    or
193
+                    file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext")
194
+                )
195
+            ) {
196
+                $flux['data'] = $f;
197
+            }
198
+        } elseif (
199
+            $fond == 'structure'
200
+            and z_sanitize_var_zajax()
201
+            and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext")
202
+        ) {
203
+            $flux['data'] = substr($f, 0, -strlen(".$ext"));
204
+        } // chercher le fond correspondant a la composition
205
+        elseif (
206
+            isset($flux['args']['contexte']['composition'])
207
+            and (basename($fond) == 'page' or ($squelette and substr($squelette, -strlen($fond)) == $fond))
208
+            and $dir = substr($fond, $prefix_length)
209
+            and $dir = explode('/', $dir)
210
+            and $dir = reset($dir)
211
+            and in_array($dir, $z_blocs)
212
+            and $f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext")
213
+        ) {
214
+            $flux['data'] = substr($f, 0, -strlen(".$ext"));
215
+        }
216
+    }
217
+
218
+    return $flux;
219 219
 }
220 220
 
221 221
 /**
@@ -225,18 +225,18 @@  discard block
 block discarded – undo
225 225
  * @return array
226 226
  */
227 227
 function z_blocs($espace_prive = false) {
228
-	if ($espace_prive) {
229
-		return (isset($GLOBALS['z_blocs_ecrire']) ? $GLOBALS['z_blocs_ecrire'] : [
230
-			'contenu',
231
-			'navigation',
232
-			'extra',
233
-			'head',
234
-			'hierarchie',
235
-			'top'
236
-		]);
237
-	}
238
-
239
-	return (isset($GLOBALS['z_blocs']) ? $GLOBALS['z_blocs'] : ['contenu']);
228
+    if ($espace_prive) {
229
+        return (isset($GLOBALS['z_blocs_ecrire']) ? $GLOBALS['z_blocs_ecrire'] : [
230
+            'contenu',
231
+            'navigation',
232
+            'extra',
233
+            'head',
234
+            'hierarchie',
235
+            'top'
236
+        ]);
237
+    }
238
+
239
+    return (isset($GLOBALS['z_blocs']) ? $GLOBALS['z_blocs'] : ['contenu']);
240 240
 }
241 241
 
242 242
 /**
@@ -251,11 +251,11 @@  discard block
 block discarded – undo
251 251
  * @return mixed
252 252
  */
253 253
 function z_contenu_disponible($prefix_path, $z_contenu, $type, $ext, $echafauder = true) {
254
-	if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) {
255
-		return $d;
256
-	}
254
+    if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) {
255
+        return $d;
256
+    }
257 257
 
258
-	return $echafauder ? z_echafaudable($type) : false;
258
+    return $echafauder ? z_echafaudable($type) : false;
259 259
 }
260 260
 
261 261
 /**
@@ -269,14 +269,14 @@  discard block
 block discarded – undo
269 269
  *   `true` si on peut l'utiliser, `false` sinon.
270 270
  **/
271 271
 function z_fond_valide($squelette) {
272
-	if (
273
-		!_ZCORE_EXCLURE_PATH
274
-		or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette)
275
-	) {
276
-		return true;
277
-	}
278
-
279
-	return false;
272
+    if (
273
+        !_ZCORE_EXCLURE_PATH
274
+        or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette)
275
+    ) {
276
+        return true;
277
+    }
278
+
279
+    return false;
280 280
 }
281 281
 
282 282
 /**
@@ -294,14 +294,14 @@  discard block
 block discarded – undo
294 294
  * @return string
295 295
  */
296 296
 function z_trouver_bloc($prefix_path, $bloc, $fond, $ext) {
297
-	if (
298
-		(defined('_ZCORE_BLOC_PREFIX_SKEL') and $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") and z_fond_valide($f))
299
-		or ($f = find_in_path("$prefix_path$bloc/$fond.$ext") and z_fond_valide($f))
300
-	) {
301
-		return substr($f, 0, -strlen(".$ext"));
302
-	}
303
-
304
-	return '';
297
+    if (
298
+        (defined('_ZCORE_BLOC_PREFIX_SKEL') and $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") and z_fond_valide($f))
299
+        or ($f = find_in_path("$prefix_path$bloc/$fond.$ext") and z_fond_valide($f))
300
+    ) {
301
+        return substr($f, 0, -strlen(".$ext"));
302
+    }
303
+
304
+    return '';
305 305
 }
306 306
 
307 307
 /**
@@ -313,52 +313,52 @@  discard block
 block discarded – undo
313 313
  * @return bool
314 314
  */
315 315
 function z_echafaudable($type) {
316
-	static $pages = null;
317
-	static $echafaudable = [];
318
-	if (isset($echafaudable[$type])) {
319
-		return $echafaudable[$type];
320
-	}
321
-	if (preg_match(',[^\w],', $type)) {
322
-		return $echafaudable[$type] = false;
323
-	}
324
-
325
-	if (test_espace_prive()) {
326
-		if (!function_exists('trouver_objet_exec')) {
327
-			include_spip('inc/pipelines_ecrire');
328
-		}
329
-		if ($e = trouver_objet_exec($type)) {
330
-			return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $e];
331
-		} else {
332
-			// peut etre c'est un exec=types qui liste tous les objets "type"
333
-			if (
334
-				($t = objet_type($type, false)) !== $type
335
-				and $e = trouver_objet_exec($t)
336
-			) {
337
-				return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $t];
338
-			}
339
-		}
340
-	} else {
341
-		if (is_null($pages)) {
342
-			$pages = [];
343
-			$liste = lister_tables_objets_sql();
344
-			foreach ($liste as $t => $d) {
345
-				if ($d['page']) {
346
-					$pages[$d['page']] = [$d['table_objet'], $t];
347
-				}
348
-			}
349
-		}
350
-		if (!isset($pages[$type])) {
351
-			return $echafaudable[$type] = false;
352
-		}
353
-		if (count($pages[$type]) == 2) {
354
-			$trouver_table = charger_fonction('trouver_table', 'base');
355
-			$pages[$type][] = $trouver_table(reset($pages[$type]));
356
-		}
357
-
358
-		return $echafaudable[$type] = $pages[$type];
359
-	}
360
-
361
-	return $echafaudable[$type] = false;
316
+    static $pages = null;
317
+    static $echafaudable = [];
318
+    if (isset($echafaudable[$type])) {
319
+        return $echafaudable[$type];
320
+    }
321
+    if (preg_match(',[^\w],', $type)) {
322
+        return $echafaudable[$type] = false;
323
+    }
324
+
325
+    if (test_espace_prive()) {
326
+        if (!function_exists('trouver_objet_exec')) {
327
+            include_spip('inc/pipelines_ecrire');
328
+        }
329
+        if ($e = trouver_objet_exec($type)) {
330
+            return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $e];
331
+        } else {
332
+            // peut etre c'est un exec=types qui liste tous les objets "type"
333
+            if (
334
+                ($t = objet_type($type, false)) !== $type
335
+                and $e = trouver_objet_exec($t)
336
+            ) {
337
+                return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $t];
338
+            }
339
+        }
340
+    } else {
341
+        if (is_null($pages)) {
342
+            $pages = [];
343
+            $liste = lister_tables_objets_sql();
344
+            foreach ($liste as $t => $d) {
345
+                if ($d['page']) {
346
+                    $pages[$d['page']] = [$d['table_objet'], $t];
347
+                }
348
+            }
349
+        }
350
+        if (!isset($pages[$type])) {
351
+            return $echafaudable[$type] = false;
352
+        }
353
+        if (count($pages[$type]) == 2) {
354
+            $trouver_table = charger_fonction('trouver_table', 'base');
355
+            $pages[$type][] = $trouver_table(reset($pages[$type]));
356
+        }
357
+
358
+        return $echafaudable[$type] = $pages[$type];
359
+    }
360
+
361
+    return $echafaudable[$type] = false;
362 362
 }
363 363
 
364 364
 
@@ -375,46 +375,46 @@  discard block
 block discarded – undo
375 375
  * @return string
376 376
  */
377 377
 function prive_echafauder_dist($exec, $table, $table_sql, $desc_exec, $ext) {
378
-	$scaffold = '';
379
-
380
-	// page objet ou objet_edit
381
-	if (is_array($desc_exec)) {
382
-		$type = $desc_exec['type'];
383
-		$primary = $desc_exec['id_table_objet'];
384
-
385
-		if ($desc_exec['edition'] === false) {
386
-			$fond = 'objet';
387
-		} else {
388
-			$trouver_table = charger_fonction('trouver_table', 'base');
389
-			$desc = $trouver_table($table_sql);
390
-			if (isset($desc['field']['id_rubrique'])) {
391
-				$fond = 'objet_edit';
392
-			} else {
393
-				$fond = 'objet_edit.sans_rubrique';
394
-			}
395
-		}
396
-		$dir = z_blocs(test_espace_prive());
397
-		$dir = reset($dir);
398
-		$scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper($primary) . ',env}>';
399
-	} // page objets
400
-	elseif ($type = $desc_exec and strpos($type, '/') === false) {
401
-		$dir = z_blocs(test_espace_prive());
402
-		$dir = reset($dir);
403
-		$scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />';
404
-	}
405
-	// morceau d'objet : on fournit le fond de sibstitution dans $desc_exec
406
-	// et objet et tire de $table
407
-	elseif ($fond = $desc_exec) {
408
-		$dir = md5(dirname($fond));
409
-		$scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />';
410
-	}
411
-
412
-	$base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false);
413
-	$base_dir = sous_repertoire($base_dir, $dir, false);
414
-	$f = $base_dir . "$exec";
415
-	ecrire_fichier("$f.$ext", $scaffold);
416
-
417
-	return $f;
378
+    $scaffold = '';
379
+
380
+    // page objet ou objet_edit
381
+    if (is_array($desc_exec)) {
382
+        $type = $desc_exec['type'];
383
+        $primary = $desc_exec['id_table_objet'];
384
+
385
+        if ($desc_exec['edition'] === false) {
386
+            $fond = 'objet';
387
+        } else {
388
+            $trouver_table = charger_fonction('trouver_table', 'base');
389
+            $desc = $trouver_table($table_sql);
390
+            if (isset($desc['field']['id_rubrique'])) {
391
+                $fond = 'objet_edit';
392
+            } else {
393
+                $fond = 'objet_edit.sans_rubrique';
394
+            }
395
+        }
396
+        $dir = z_blocs(test_espace_prive());
397
+        $dir = reset($dir);
398
+        $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper($primary) . ',env}>';
399
+    } // page objets
400
+    elseif ($type = $desc_exec and strpos($type, '/') === false) {
401
+        $dir = z_blocs(test_espace_prive());
402
+        $dir = reset($dir);
403
+        $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />';
404
+    }
405
+    // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec
406
+    // et objet et tire de $table
407
+    elseif ($fond = $desc_exec) {
408
+        $dir = md5(dirname($fond));
409
+        $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />';
410
+    }
411
+
412
+    $base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false);
413
+    $base_dir = sous_repertoire($base_dir, $dir, false);
414
+    $f = $base_dir . "$exec";
415
+    ecrire_fichier("$f.$ext", $scaffold);
416
+
417
+    return $f;
418 418
 }
419 419
 
420 420
 /**
@@ -423,17 +423,17 @@  discard block
 block discarded – undo
423 423
  * @return bool|string
424 424
  */
425 425
 function z_sanitize_var_zajax() {
426
-	$z_ajax = _request('var_zajax');
427
-	if (!$z_ajax) {
428
-		return false;
429
-	}
430
-	if (
431
-		!$z_blocs = z_blocs(test_espace_prive())
432
-		or !in_array($z_ajax, $z_blocs)
433
-	) {
434
-		set_request('var_zajax'); // enlever cette demande incongrue
435
-		$z_ajax = false;
436
-	}
437
-
438
-	return $z_ajax;
426
+    $z_ajax = _request('var_zajax');
427
+    if (!$z_ajax) {
428
+        return false;
429
+    }
430
+    if (
431
+        !$z_blocs = z_blocs(test_espace_prive())
432
+        or !in_array($z_ajax, $z_blocs)
433
+    ) {
434
+        set_request('var_zajax'); // enlever cette demande incongrue
435
+        $z_ajax = false;
436
+    }
437
+
438
+    return $z_ajax;
439 439
 }
Please login to merge, or discard this patch.
ecrire/public/evaluer_page.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 /**
@@ -32,67 +32,67 @@  discard block
 block discarded – undo
32 32
 
33 33
 // Cas d'une page contenant du PHP :
34 34
 if (empty($page['process_ins']) or $page['process_ins'] != 'html') {
35
-	include_spip('inc/lang');
35
+    include_spip('inc/lang');
36 36
 
37
-	// restaurer l'etat des notes avant calcul
38
-	if (
39
-		isset($page['notes'])
40
-		and $page['notes']
41
-		and $notes = charger_fonction('notes', 'inc', true)
42
-	) {
43
-		$notes($page['notes'], 'restaurer_etat');
44
-	}
45
-	ob_start();
46
-	if (strpos($page['texte'], '?xml') !== false) {
47
-		$page['texte'] = str_replace('<' . '?xml', "<\1?xml", $page['texte']);
48
-	}
37
+    // restaurer l'etat des notes avant calcul
38
+    if (
39
+        isset($page['notes'])
40
+        and $page['notes']
41
+        and $notes = charger_fonction('notes', 'inc', true)
42
+    ) {
43
+        $notes($page['notes'], 'restaurer_etat');
44
+    }
45
+    ob_start();
46
+    if (strpos($page['texte'], '?xml') !== false) {
47
+        $page['texte'] = str_replace('<' . '?xml', "<\1?xml", $page['texte']);
48
+    }
49 49
 
50
-	try {
51
-		$res = eval('?' . '>' . $page['texte']);
52
-		// error catching 5.2<=PHP<7
53
-		if (
54
-			$res === false
55
-			and function_exists('error_get_last')
56
-			and ($erreur = error_get_last())
57
-		) {
58
-			$code = $page['texte'];
59
-			$GLOBALS['numero_ligne_php'] = 1;
60
-			if (!function_exists('numerote_ligne_php')) {
61
-				function numerote_ligne_php($match) {
62
-					$GLOBALS['numero_ligne_php']++;
63
-					return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/';
64
-				}
65
-			}
66
-			$code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', $code);
67
-			$code = trim(highlight_string($code, true));
68
-			erreur_squelette('L' . $erreur['line'] . ': ' . $erreur['message'] . '<br />' . $code, [$page['source'],'',$erreur['file'],'',$GLOBALS['spip_lang']]);
69
-			$page['texte'] = '<!-- Erreur -->';
70
-		}
71
-		else {
72
-			$page['texte'] = ob_get_contents();
73
-		}
74
-	}
75
-	catch (Exception $e) {
76
-		$code = $page['texte'];
77
-		$GLOBALS['numero_ligne_php'] = 1;
78
-		if (!function_exists('numerote_ligne_php')) {
79
-			function numerote_ligne_php($match) {
80
-				$GLOBALS['numero_ligne_php']++;
81
-				return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/';
82
-			}
83
-		}
84
-		$code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', $code);
85
-		$code = trim(highlight_string($code, true));
86
-		erreur_squelette('L' . $e->getLine() . ': ' . $e->getMessage() . '<br />' . $code, [$page['source'],'',$e->getFile(),'',$GLOBALS['spip_lang']]);
87
-		$page['texte'] = '<!-- Erreur -->';
88
-	}
89
-	ob_end_clean();
50
+    try {
51
+        $res = eval('?' . '>' . $page['texte']);
52
+        // error catching 5.2<=PHP<7
53
+        if (
54
+            $res === false
55
+            and function_exists('error_get_last')
56
+            and ($erreur = error_get_last())
57
+        ) {
58
+            $code = $page['texte'];
59
+            $GLOBALS['numero_ligne_php'] = 1;
60
+            if (!function_exists('numerote_ligne_php')) {
61
+                function numerote_ligne_php($match) {
62
+                    $GLOBALS['numero_ligne_php']++;
63
+                    return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/';
64
+                }
65
+            }
66
+            $code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', $code);
67
+            $code = trim(highlight_string($code, true));
68
+            erreur_squelette('L' . $erreur['line'] . ': ' . $erreur['message'] . '<br />' . $code, [$page['source'],'',$erreur['file'],'',$GLOBALS['spip_lang']]);
69
+            $page['texte'] = '<!-- Erreur -->';
70
+        }
71
+        else {
72
+            $page['texte'] = ob_get_contents();
73
+        }
74
+    }
75
+    catch (Exception $e) {
76
+        $code = $page['texte'];
77
+        $GLOBALS['numero_ligne_php'] = 1;
78
+        if (!function_exists('numerote_ligne_php')) {
79
+            function numerote_ligne_php($match) {
80
+                $GLOBALS['numero_ligne_php']++;
81
+                return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/';
82
+            }
83
+        }
84
+        $code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', $code);
85
+        $code = trim(highlight_string($code, true));
86
+        erreur_squelette('L' . $e->getLine() . ': ' . $e->getMessage() . '<br />' . $code, [$page['source'],'',$e->getFile(),'',$GLOBALS['spip_lang']]);
87
+        $page['texte'] = '<!-- Erreur -->';
88
+    }
89
+    ob_end_clean();
90 90
 
91
-	$page['process_ins'] = 'html';
91
+    $page['process_ins'] = 'html';
92 92
 
93
-	if (strpos($page['texte'], '?xml') !== false) {
94
-		$page['texte'] = str_replace("<\1?xml", '<' . '?xml', $page['texte']);
95
-	}
93
+    if (strpos($page['texte'], '?xml') !== false) {
94
+        $page['texte'] = str_replace("<\1?xml", '<' . '?xml', $page['texte']);
95
+    }
96 96
 }
97 97
 
98 98
 page_base_href($page['texte']);
Please login to merge, or discard this patch.
ecrire/public/balises.php 1 patch
Indentation   +951 added lines, -951 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
  **/
27 27
 
28 28
 if (!defined('_ECRIRE_INC_VERSION')) {
29
-	return;
29
+    return;
30 30
 }
31 31
 
32 32
 /**
@@ -48,16 +48,16 @@  discard block
 block discarded – undo
48 48
  *     Code PHP si cet argument est présent, sinon null
49 49
  **/
50 50
 function interprete_argument_balise($n, $p) {
51
-	if (($p->param) && (!$p->param[0][0]) && (count($p->param[0]) > $n)) {
52
-		return calculer_liste(
53
-			$p->param[0][$n],
54
-			$p->descr,
55
-			$p->boucles,
56
-			$p->id_boucle
57
-		);
58
-	} else {
59
-		return null;
60
-	}
51
+    if (($p->param) && (!$p->param[0][0]) && (count($p->param[0]) > $n)) {
52
+        return calculer_liste(
53
+            $p->param[0][$n],
54
+            $p->descr,
55
+            $p->boucles,
56
+            $p->id_boucle
57
+        );
58
+    } else {
59
+        return null;
60
+    }
61 61
 }
62 62
 
63 63
 
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
  *     Pile complétée par le code à générer
78 78
  **/
79 79
 function balise_NOM_SITE_SPIP_dist($p) {
80
-	$p->code = "\$GLOBALS['meta']['nom_site']";
80
+    $p->code = "\$GLOBALS['meta']['nom_site']";
81 81
 
82
-	#$p->interdire_scripts = true;
83
-	return $p;
82
+    #$p->interdire_scripts = true;
83
+    return $p;
84 84
 }
85 85
 
86 86
 /**
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
  *     Pile complétée par le code à générer
97 97
  **/
98 98
 function balise_EMAIL_WEBMASTER_dist($p) {
99
-	$p->code = "\$GLOBALS['meta']['email_webmaster']";
99
+    $p->code = "\$GLOBALS['meta']['email_webmaster']";
100 100
 
101
-	#$p->interdire_scripts = true;
102
-	return $p;
101
+    #$p->interdire_scripts = true;
102
+    return $p;
103 103
 }
104 104
 
105 105
 /**
@@ -115,10 +115,10 @@  discard block
 block discarded – undo
115 115
  *     Pile complétée par le code à générer
116 116
  **/
117 117
 function balise_DESCRIPTIF_SITE_SPIP_dist($p) {
118
-	$p->code = "\$GLOBALS['meta']['descriptif_site']";
118
+    $p->code = "\$GLOBALS['meta']['descriptif_site']";
119 119
 
120
-	#$p->interdire_scripts = true;
121
-	return $p;
120
+    #$p->interdire_scripts = true;
121
+    return $p;
122 122
 }
123 123
 
124 124
 
@@ -139,10 +139,10 @@  discard block
 block discarded – undo
139 139
  *     Pile complétée par le code à générer
140 140
  **/
141 141
 function balise_CHARSET_dist($p) {
142
-	$p->code = "\$GLOBALS['meta']['charset']";
142
+    $p->code = "\$GLOBALS['meta']['charset']";
143 143
 
144
-	#$p->interdire_scripts = true;
145
-	return $p;
144
+    #$p->interdire_scripts = true;
145
+    return $p;
146 146
 }
147 147
 
148 148
 /**
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
  *     Pile complétée par le code à générer
168 168
  **/
169 169
 function balise_LANG_LEFT_dist($p) {
170
-	$_lang = champ_sql('lang', $p);
171
-	$p->code = "lang_dir($_lang, 'left','right')";
172
-	$p->interdire_scripts = false;
170
+    $_lang = champ_sql('lang', $p);
171
+    $p->code = "lang_dir($_lang, 'left','right')";
172
+    $p->interdire_scripts = false;
173 173
 
174
-	return $p;
174
+    return $p;
175 175
 }
176 176
 
177 177
 /**
@@ -191,11 +191,11 @@  discard block
 block discarded – undo
191 191
  *     Pile complétée par le code à générer
192 192
  **/
193 193
 function balise_LANG_RIGHT_dist($p) {
194
-	$_lang = champ_sql('lang', $p);
195
-	$p->code = "lang_dir($_lang, 'right','left')";
196
-	$p->interdire_scripts = false;
194
+    $_lang = champ_sql('lang', $p);
195
+    $p->code = "lang_dir($_lang, 'right','left')";
196
+    $p->interdire_scripts = false;
197 197
 
198
-	return $p;
198
+    return $p;
199 199
 }
200 200
 
201 201
 /**
@@ -220,11 +220,11 @@  discard block
 block discarded – undo
220 220
  *     Pile complétée par le code à générer
221 221
  **/
222 222
 function balise_LANG_DIR_dist($p) {
223
-	$_lang = champ_sql('lang', $p);
224
-	$p->code = "lang_dir($_lang, 'ltr','rtl')";
225
-	$p->interdire_scripts = false;
223
+    $_lang = champ_sql('lang', $p);
224
+    $p->code = "lang_dir($_lang, 'ltr','rtl')";
225
+    $p->interdire_scripts = false;
226 226
 
227
-	return $p;
227
+    return $p;
228 228
 }
229 229
 
230 230
 
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
  *     Pile complétée par le code à générer
242 242
  **/
243 243
 function balise_PUCE_dist($p) {
244
-	$p->code = 'definir_puce()';
245
-	$p->interdire_scripts = false;
244
+    $p->code = 'definir_puce()';
245
+    $p->interdire_scripts = false;
246 246
 
247
-	return $p;
247
+    return $p;
248 248
 }
249 249
 
250 250
 
@@ -268,12 +268,12 @@  discard block
 block discarded – undo
268 268
  *     Pile completée du code PHP d'exécution de la balise
269 269
  */
270 270
 function balise_DATE_dist($p) {
271
-	$d = champ_sql('date', $p);
271
+    $d = champ_sql('date', $p);
272 272
 #	if ($d === "@\$Pile[0]['date']")
273 273
 #		$d = "isset(\$Pile[0]['date']) ? $d : time()";
274
-	$p->code = $d;
274
+    $p->code = $d;
275 275
 
276
-	return $p;
276
+    return $p;
277 277
 }
278 278
 
279 279
 
@@ -293,13 +293,13 @@  discard block
 block discarded – undo
293 293
  *     Pile completée du code PHP d'exécution de la balise
294 294
  */
295 295
 function balise_DATE_REDAC_dist($p) {
296
-	$d = champ_sql('date_redac', $p);
296
+    $d = champ_sql('date_redac', $p);
297 297
 #	if ($d === "@\$Pile[0]['date_redac']")
298 298
 #		$d = "isset(\$Pile[0]['date_redac']) ? $d : time()";
299
-	$p->code = $d;
300
-	$p->interdire_scripts = false;
299
+    $p->code = $d;
300
+    $p->interdire_scripts = false;
301 301
 
302
-	return $p;
302
+    return $p;
303 303
 }
304 304
 
305 305
 /**
@@ -318,10 +318,10 @@  discard block
 block discarded – undo
318 318
  *     Pile completée du code PHP d'exécution de la balise
319 319
  */
320 320
 function balise_DATE_MODIF_dist($p) {
321
-	$p->code = champ_sql('date_modif', $p);
322
-	$p->interdire_scripts = false;
321
+    $p->code = champ_sql('date_modif', $p);
322
+    $p->interdire_scripts = false;
323 323
 
324
-	return $p;
324
+    return $p;
325 325
 }
326 326
 
327 327
 /**
@@ -339,13 +339,13 @@  discard block
 block discarded – undo
339 339
  *     Pile completée du code PHP d'exécution de la balise
340 340
  */
341 341
 function balise_DATE_NOUVEAUTES_dist($p) {
342
-	$p->code = "((\$GLOBALS['meta']['quoi_de_neuf'] == 'oui'
342
+    $p->code = "((\$GLOBALS['meta']['quoi_de_neuf'] == 'oui'
343 343
 	AND isset(\$GLOBALS['meta']['dernier_envoi_neuf'])) ?
344 344
 	\$GLOBALS['meta']['dernier_envoi_neuf'] :
345 345
 	\"'0000-00-00'\")";
346
-	$p->interdire_scripts = false;
346
+    $p->interdire_scripts = false;
347 347
 
348
-	return $p;
348
+    return $p;
349 349
 }
350 350
 
351 351
 
@@ -363,11 +363,11 @@  discard block
 block discarded – undo
363 363
  *     Pile completée du code PHP d'exécution de la balise
364 364
  */
365 365
 function balise_DOSSIER_SQUELETTE_dist($p) {
366
-	$code = substr(addslashes(dirname($p->descr['sourcefile'])), strlen(_DIR_RACINE));
367
-	$p->code = "_DIR_RACINE . '$code'" .
368
-		$p->interdire_scripts = false;
366
+    $code = substr(addslashes(dirname($p->descr['sourcefile'])), strlen(_DIR_RACINE));
367
+    $p->code = "_DIR_RACINE . '$code'" .
368
+        $p->interdire_scripts = false;
369 369
 
370
-	return $p;
370
+    return $p;
371 371
 }
372 372
 
373 373
 /**
@@ -382,11 +382,11 @@  discard block
 block discarded – undo
382 382
  *     Pile completée du code PHP d'exécution de la balise
383 383
  */
384 384
 function balise_SQUELETTE_dist($p) {
385
-	$code = addslashes($p->descr['sourcefile']);
386
-	$p->code = "'$code'" .
387
-		$p->interdire_scripts = false;
385
+    $code = addslashes($p->descr['sourcefile']);
386
+    $p->code = "'$code'" .
387
+        $p->interdire_scripts = false;
388 388
 
389
-	return $p;
389
+    return $p;
390 390
 }
391 391
 
392 392
 /**
@@ -405,10 +405,10 @@  discard block
 block discarded – undo
405 405
  *     Pile completée du code PHP d'exécution de la balise
406 406
  */
407 407
 function balise_SPIP_VERSION_dist($p) {
408
-	$p->code = 'spip_version()';
409
-	$p->interdire_scripts = false;
408
+    $p->code = 'spip_version()';
409
+    $p->interdire_scripts = false;
410 410
 
411
-	return $p;
411
+    return $p;
412 412
 }
413 413
 
414 414
 
@@ -434,18 +434,18 @@  discard block
 block discarded – undo
434 434
  *     Pile complétée par le code à générer
435 435
  **/
436 436
 function balise_NOM_SITE_dist($p) {
437
-	if (!$p->etoile) {
438
-		$p->code = 'supprimer_numero(calculer_url(' .
439
-			champ_sql('url_site', $p) . ',' .
440
-			champ_sql('nom_site', $p) .
441
-			", 'titre', \$connect, false))";
442
-	} else {
443
-		$p->code = champ_sql('nom_site', $p);
444
-	}
437
+    if (!$p->etoile) {
438
+        $p->code = 'supprimer_numero(calculer_url(' .
439
+            champ_sql('url_site', $p) . ',' .
440
+            champ_sql('nom_site', $p) .
441
+            ", 'titre', \$connect, false))";
442
+    } else {
443
+        $p->code = champ_sql('nom_site', $p);
444
+    }
445 445
 
446
-	$p->interdire_scripts = true;
446
+    $p->interdire_scripts = true;
447 447
 
448
-	return $p;
448
+    return $p;
449 449
 }
450 450
 
451 451
 
@@ -462,11 +462,11 @@  discard block
 block discarded – undo
462 462
  *     Pile complétée par le code à générer
463 463
  **/
464 464
 function balise_NOTES_dist($p) {
465
-	// Recuperer les notes
466
-	$p->code = 'calculer_notes()';
465
+    // Recuperer les notes
466
+    $p->code = 'calculer_notes()';
467 467
 
468
-	#$p->interdire_scripts = true;
469
-	return $p;
468
+    #$p->interdire_scripts = true;
469
+    return $p;
470 470
 }
471 471
 
472 472
 
@@ -488,10 +488,10 @@  discard block
 block discarded – undo
488 488
  *     Pile complétée par le code à générer
489 489
  **/
490 490
 function balise_RECHERCHE_dist($p) {
491
-	$p->code = 'entites_html(_request("recherche"))';
492
-	$p->interdire_scripts = false;
491
+    $p->code = 'entites_html(_request("recherche"))';
492
+    $p->interdire_scripts = false;
493 493
 
494
-	return $p;
494
+    return $p;
495 495
 }
496 496
 
497 497
 
@@ -509,17 +509,17 @@  discard block
 block discarded – undo
509 509
  *     Pile complétée par le code à générer
510 510
  **/
511 511
 function balise_COMPTEUR_BOUCLE_dist($p) {
512
-	$b = index_boucle_mere($p);
513
-	if ($b === '') {
514
-		$msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]];
515
-		erreur_squelette($msg, $p);
516
-	} else {
517
-		$p->code = "\$Numrows['$b']['compteur_boucle']";
518
-		$p->boucles[$b]->cptrows = true;
519
-		$p->interdire_scripts = false;
512
+    $b = index_boucle_mere($p);
513
+    if ($b === '') {
514
+        $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]];
515
+        erreur_squelette($msg, $p);
516
+    } else {
517
+        $p->code = "\$Numrows['$b']['compteur_boucle']";
518
+        $p->boucles[$b]->cptrows = true;
519
+        $p->interdire_scripts = false;
520 520
 
521
-		return $p;
522
-	}
521
+        return $p;
522
+    }
523 523
 }
524 524
 
525 525
 /**
@@ -537,17 +537,17 @@  discard block
 block discarded – undo
537 537
  *     Pile complétée par le code à générer
538 538
  **/
539 539
 function balise_TOTAL_BOUCLE_dist($p) {
540
-	$b = index_boucle_mere($p);
541
-	if ($b === '') {
542
-		$msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]];
543
-		erreur_squelette($msg, $p);
544
-	} else {
545
-		$p->code = "\$Numrows['$b']['total']";
546
-		$p->boucles[$b]->numrows = true;
547
-		$p->interdire_scripts = false;
548
-	}
540
+    $b = index_boucle_mere($p);
541
+    if ($b === '') {
542
+        $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]];
543
+        erreur_squelette($msg, $p);
544
+    } else {
545
+        $p->code = "\$Numrows['$b']['total']";
546
+        $p->boucles[$b]->numrows = true;
547
+        $p->interdire_scripts = false;
548
+    }
549 549
 
550
-	return $p;
550
+    return $p;
551 551
 }
552 552
 
553 553
 
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
  *     Pile complétée par le code à générer
568 568
  **/
569 569
 function balise_POINTS_dist($p) {
570
-	return rindex_pile($p, 'points', 'recherche');
570
+    return rindex_pile($p, 'points', 'recherche');
571 571
 }
572 572
 
573 573
 
@@ -588,12 +588,12 @@  discard block
 block discarded – undo
588 588
  *     Pile complétée par le code à générer
589 589
  **/
590 590
 function balise_POPULARITE_ABSOLUE_dist($p) {
591
-	$p->code = 'ceil(' .
592
-		champ_sql('popularite', $p) .
593
-		')';
594
-	$p->interdire_scripts = false;
591
+    $p->code = 'ceil(' .
592
+        champ_sql('popularite', $p) .
593
+        ')';
594
+    $p->interdire_scripts = false;
595 595
 
596
-	return $p;
596
+    return $p;
597 597
 }
598 598
 
599 599
 /**
@@ -613,10 +613,10 @@  discard block
 block discarded – undo
613 613
  *     Pile complétée par le code à générer
614 614
  **/
615 615
 function balise_POPULARITE_SITE_dist($p) {
616
-	$p->code = 'ceil($GLOBALS["meta"][\'popularite_total\'])';
617
-	$p->interdire_scripts = false;
616
+    $p->code = 'ceil($GLOBALS["meta"][\'popularite_total\'])';
617
+    $p->interdire_scripts = false;
618 618
 
619
-	return $p;
619
+    return $p;
620 620
 }
621 621
 
622 622
 /**
@@ -637,10 +637,10 @@  discard block
 block discarded – undo
637 637
  *     Pile complétée par le code à générer
638 638
  **/
639 639
 function balise_POPULARITE_MAX_dist($p) {
640
-	$p->code = 'ceil($GLOBALS["meta"][\'popularite_max\'])';
641
-	$p->interdire_scripts = false;
640
+    $p->code = 'ceil($GLOBALS["meta"][\'popularite_max\'])';
641
+    $p->interdire_scripts = false;
642 642
 
643
-	return $p;
643
+    return $p;
644 644
 }
645 645
 
646 646
 
@@ -666,15 +666,15 @@  discard block
 block discarded – undo
666 666
  *     Pile complétée par le code à générer
667 667
  **/
668 668
 function balise_VALEUR_dist($p) {
669
-	$b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle;
670
-	$p->code = index_pile($p->id_boucle, 'valeur', $p->boucles, $b);
669
+    $b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle;
670
+    $p->code = index_pile($p->id_boucle, 'valeur', $p->boucles, $b);
671 671
 ;
672
-	if (($v = interprete_argument_balise(1, $p)) !== null) {
673
-		$p->code = 'table_valeur(' . $p->code . ', ' . $v . ')';
674
-	}
675
-	$p->interdire_scripts = true;
672
+    if (($v = interprete_argument_balise(1, $p)) !== null) {
673
+        $p->code = 'table_valeur(' . $p->code . ', ' . $v . ')';
674
+    }
675
+    $p->interdire_scripts = true;
676 676
 
677
-	return $p;
677
+    return $p;
678 678
 }
679 679
 
680 680
 /**
@@ -703,16 +703,16 @@  discard block
 block discarded – undo
703 703
  *     Pile complétée par le code à générer
704 704
  **/
705 705
 function balise_EXPOSE_dist($p) {
706
-	$on = "'on'";
707
-	$off = "''";
708
-	if (($v = interprete_argument_balise(1, $p)) !== null) {
709
-		$on = $v;
710
-		if (($v = interprete_argument_balise(2, $p)) !== null) {
711
-			$off = $v;
712
-		}
713
-	}
706
+    $on = "'on'";
707
+    $off = "''";
708
+    if (($v = interprete_argument_balise(1, $p)) !== null) {
709
+        $on = $v;
710
+        if (($v = interprete_argument_balise(2, $p)) !== null) {
711
+            $off = $v;
712
+        }
713
+    }
714 714
 
715
-	return calculer_balise_expose($p, $on, $off);
715
+    return calculer_balise_expose($p, $on, $off);
716 716
 }
717 717
 
718 718
 /**
@@ -730,35 +730,35 @@  discard block
 block discarded – undo
730 730
  *     Pile complétée par le code à générer
731 731
  **/
732 732
 function calculer_balise_expose($p, $on, $off) {
733
-	$b = index_boucle($p);
734
-	if (empty($p->boucles[$b]->primary)) {
735
-		$msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]];
736
-		erreur_squelette($msg, $p);
737
-	} else {
738
-		$key = $p->boucles[$b]->primary;
739
-		$type = $p->boucles[$p->id_boucle]->primary;
740
-		$desc = $p->boucles[$b]->show;
741
-		$connect = sql_quote($p->boucles[$b]->sql_serveur);
733
+    $b = index_boucle($p);
734
+    if (empty($p->boucles[$b]->primary)) {
735
+        $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]];
736
+        erreur_squelette($msg, $p);
737
+    } else {
738
+        $key = $p->boucles[$b]->primary;
739
+        $type = $p->boucles[$p->id_boucle]->primary;
740
+        $desc = $p->boucles[$b]->show;
741
+        $connect = sql_quote($p->boucles[$b]->sql_serveur);
742 742
 
743
-		// Ne pas utiliser champ_sql, on jongle avec le nom boucle explicite
744
-		$c = index_pile($p->id_boucle, $type, $p->boucles);
743
+        // Ne pas utiliser champ_sql, on jongle avec le nom boucle explicite
744
+        $c = index_pile($p->id_boucle, $type, $p->boucles);
745 745
 
746
-		if (isset($desc['field']['id_parent'])) {
747
-			$parent = 0; // pour if (!$parent) dans calculer_expose
748
-		} elseif (isset($desc['field']['id_rubrique'])) {
749
-			$parent = index_pile($p->id_boucle, 'id_rubrique', $p->boucles, $b);
750
-		} elseif (isset($desc['field']['id_groupe'])) {
751
-			$parent = index_pile($p->id_boucle, 'id_groupe', $p->boucles, $b);
752
-		} else {
753
-			$parent = "''";
754
-		}
746
+        if (isset($desc['field']['id_parent'])) {
747
+            $parent = 0; // pour if (!$parent) dans calculer_expose
748
+        } elseif (isset($desc['field']['id_rubrique'])) {
749
+            $parent = index_pile($p->id_boucle, 'id_rubrique', $p->boucles, $b);
750
+        } elseif (isset($desc['field']['id_groupe'])) {
751
+            $parent = index_pile($p->id_boucle, 'id_groupe', $p->boucles, $b);
752
+        } else {
753
+            $parent = "''";
754
+        }
755 755
 
756
-		$p->code = "(calcul_exposer($c, '$type', \$Pile[0], $parent, '$key', $connect) ? $on : $off)";
757
-	}
756
+        $p->code = "(calcul_exposer($c, '$type', \$Pile[0], $parent, '$key', $connect) ? $on : $off)";
757
+    }
758 758
 
759
-	$p->interdire_scripts = false;
759
+    $p->interdire_scripts = false;
760 760
 
761
-	return $p;
761
+    return $p;
762 762
 }
763 763
 
764 764
 
@@ -798,46 +798,46 @@  discard block
 block discarded – undo
798 798
  **/
799 799
 function balise_INTRODUCTION_dist($p) {
800 800
 
801
-	$type_objet = $p->type_requete;
802
-	$cle_objet = id_table_objet($type_objet);
803
-	$_id_objet = champ_sql($cle_objet, $p);
804
-
805
-	// Récupérer les valeurs sql nécessaires : descriptif, texte et chapo
806
-	// ainsi que le longueur d'introduction donnée dans la description de l'objet.
807
-	$_introduction_longueur = 'null';
808
-	$_ligne = 'array(';
809
-	$trouver_table = charger_fonction('trouver_table', 'base');
810
-	if ($desc = $trouver_table(table_objet_sql($type_objet))) {
811
-		if (isset($desc['field']['descriptif'])) {
812
-			$_ligne .= "'descriptif' => " . champ_sql('descriptif', $p) . ',';
813
-		}
814
-		if (isset($desc['field']['texte'])) {
815
-			$_ligne .= "'texte' => " . champ_sql('texte', $p) . ',';
816
-		}
817
-		if (isset($desc['field']['chapo'])) {
818
-			$_ligne .= "'chapo' => " . champ_sql('chapo', $p) . ',';
819
-		}
820
-		if (isset($desc['introduction_longueur'])) {
821
-			$_introduction_longueur = "'" . $desc['introduction_longueur'] . "'";
822
-		}
823
-	}
824
-	$_ligne .= ')';
825
-
826
-	// Récupérer la longueur et la suite passés en paramètres
827
-	$_longueur_ou_suite = 'null';
828
-	if (($v1 = interprete_argument_balise(1, $p)) !== null) {
829
-		$_longueur_ou_suite = $v1;
830
-	}
831
-	$_suite = 'null';
832
-	if (($v2 = interprete_argument_balise(2, $p)) !== null) {
833
-		$_suite = $v2;
834
-	}
835
-
836
-	$p->code = "generer_introduction_entite($_id_objet, '$type_objet', $_ligne, $_introduction_longueur, $_longueur_ou_suite, $_suite, \$connect)";
837
-
838
-	#$p->interdire_scripts = true;
839
-	$p->etoile = '*'; // propre est deja fait dans le calcul de l'intro
840
-	return $p;
801
+    $type_objet = $p->type_requete;
802
+    $cle_objet = id_table_objet($type_objet);
803
+    $_id_objet = champ_sql($cle_objet, $p);
804
+
805
+    // Récupérer les valeurs sql nécessaires : descriptif, texte et chapo
806
+    // ainsi que le longueur d'introduction donnée dans la description de l'objet.
807
+    $_introduction_longueur = 'null';
808
+    $_ligne = 'array(';
809
+    $trouver_table = charger_fonction('trouver_table', 'base');
810
+    if ($desc = $trouver_table(table_objet_sql($type_objet))) {
811
+        if (isset($desc['field']['descriptif'])) {
812
+            $_ligne .= "'descriptif' => " . champ_sql('descriptif', $p) . ',';
813
+        }
814
+        if (isset($desc['field']['texte'])) {
815
+            $_ligne .= "'texte' => " . champ_sql('texte', $p) . ',';
816
+        }
817
+        if (isset($desc['field']['chapo'])) {
818
+            $_ligne .= "'chapo' => " . champ_sql('chapo', $p) . ',';
819
+        }
820
+        if (isset($desc['introduction_longueur'])) {
821
+            $_introduction_longueur = "'" . $desc['introduction_longueur'] . "'";
822
+        }
823
+    }
824
+    $_ligne .= ')';
825
+
826
+    // Récupérer la longueur et la suite passés en paramètres
827
+    $_longueur_ou_suite = 'null';
828
+    if (($v1 = interprete_argument_balise(1, $p)) !== null) {
829
+        $_longueur_ou_suite = $v1;
830
+    }
831
+    $_suite = 'null';
832
+    if (($v2 = interprete_argument_balise(2, $p)) !== null) {
833
+        $_suite = $v2;
834
+    }
835
+
836
+    $p->code = "generer_introduction_entite($_id_objet, '$type_objet', $_ligne, $_introduction_longueur, $_longueur_ou_suite, $_suite, \$connect)";
837
+
838
+    #$p->interdire_scripts = true;
839
+    $p->etoile = '*'; // propre est deja fait dans le calcul de l'intro
840
+    return $p;
841 841
 }
842 842
 
843 843
 
@@ -857,15 +857,15 @@  discard block
 block discarded – undo
857 857
  *     Pile complétée par le code à générer
858 858
  **/
859 859
 function balise_LANG_dist($p) {
860
-	$_lang = champ_sql('lang', $p);
861
-	if (!$p->etoile) {
862
-		$p->code = "spip_htmlentities($_lang ? $_lang : \$GLOBALS['spip_lang'])";
863
-	} else {
864
-		$p->code = "spip_htmlentities($_lang)";
865
-	}
866
-	$p->interdire_scripts = false;
860
+    $_lang = champ_sql('lang', $p);
861
+    if (!$p->etoile) {
862
+        $p->code = "spip_htmlentities($_lang ? $_lang : \$GLOBALS['spip_lang'])";
863
+    } else {
864
+        $p->code = "spip_htmlentities($_lang)";
865
+    }
866
+    $p->interdire_scripts = false;
867 867
 
868
-	return $p;
868
+    return $p;
869 869
 }
870 870
 
871 871
 /**
@@ -887,48 +887,48 @@  discard block
 block discarded – undo
887 887
  *     Pile complétée par le code à générer
888 888
  */
889 889
 function balise_LESAUTEURS_dist($p) {
890
-	// Cherche le champ 'lesauteurs' dans la pile
891
-	$_lesauteurs = champ_sql('lesauteurs', $p, false);
892
-
893
-	// Si le champ n'existe pas (cas de spip_articles), on applique
894
-	// le modele lesauteurs.html en passant id_article dans le contexte;
895
-	// dans le cas contraire on prend le champ 'lesauteurs'
896
-	// (cf extension sites/)
897
-	if (
898
-		$_lesauteurs
899
-		and $_lesauteurs != '@$Pile[0][\'lesauteurs\']'
900
-	) {
901
-		$p->code = "safehtml($_lesauteurs)";
902
-		// $p->interdire_scripts = true;
903
-	} else {
904
-		if (!$p->id_boucle) {
905
-			$connect = '';
906
-			$objet = 'article';
907
-			$id_table_objet = 'id_article';
908
-		} else {
909
-			$b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle;
910
-			$connect = $p->boucles[$b]->sql_serveur;
911
-			$type_boucle = $p->boucles[$b]->type_requete;
912
-			$objet = objet_type($type_boucle);
913
-			$id_table_objet = id_table_objet($type_boucle);
914
-		}
915
-		$c = memoriser_contexte_compil($p);
916
-
917
-		$p->code = sprintf(
918
-			CODE_RECUPERER_FOND,
919
-			"'modeles/lesauteurs'",
920
-			"array('objet'=>'" . $objet .
921
-			"','id_objet' => " . champ_sql($id_table_objet, $p) .
922
-			",'$id_table_objet' => " . champ_sql($id_table_objet, $p) .
923
-			($objet == 'article' ? '' : ",'id_article' => " . champ_sql('id_article', $p)) .
924
-			')',
925
-			"'trim'=>true, 'compil'=>array($c)",
926
-			_q($connect)
927
-		);
928
-		$p->interdire_scripts = false; // securite apposee par recuperer_fond()
929
-	}
930
-
931
-	return $p;
890
+    // Cherche le champ 'lesauteurs' dans la pile
891
+    $_lesauteurs = champ_sql('lesauteurs', $p, false);
892
+
893
+    // Si le champ n'existe pas (cas de spip_articles), on applique
894
+    // le modele lesauteurs.html en passant id_article dans le contexte;
895
+    // dans le cas contraire on prend le champ 'lesauteurs'
896
+    // (cf extension sites/)
897
+    if (
898
+        $_lesauteurs
899
+        and $_lesauteurs != '@$Pile[0][\'lesauteurs\']'
900
+    ) {
901
+        $p->code = "safehtml($_lesauteurs)";
902
+        // $p->interdire_scripts = true;
903
+    } else {
904
+        if (!$p->id_boucle) {
905
+            $connect = '';
906
+            $objet = 'article';
907
+            $id_table_objet = 'id_article';
908
+        } else {
909
+            $b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle;
910
+            $connect = $p->boucles[$b]->sql_serveur;
911
+            $type_boucle = $p->boucles[$b]->type_requete;
912
+            $objet = objet_type($type_boucle);
913
+            $id_table_objet = id_table_objet($type_boucle);
914
+        }
915
+        $c = memoriser_contexte_compil($p);
916
+
917
+        $p->code = sprintf(
918
+            CODE_RECUPERER_FOND,
919
+            "'modeles/lesauteurs'",
920
+            "array('objet'=>'" . $objet .
921
+            "','id_objet' => " . champ_sql($id_table_objet, $p) .
922
+            ",'$id_table_objet' => " . champ_sql($id_table_objet, $p) .
923
+            ($objet == 'article' ? '' : ",'id_article' => " . champ_sql('id_article', $p)) .
924
+            ')',
925
+            "'trim'=>true, 'compil'=>array($c)",
926
+            _q($connect)
927
+        );
928
+        $p->interdire_scripts = false; // securite apposee par recuperer_fond()
929
+    }
930
+
931
+    return $p;
932 932
 }
933 933
 
934 934
 
@@ -955,76 +955,76 @@  discard block
 block discarded – undo
955 955
  *     Pile complétée par le code à générer
956 956
  */
957 957
 function balise_RANG_dist($p) {
958
-	$b = index_boucle($p);
959
-	if ($b === '') {
960
-		$msg = [
961
-			'zbug_champ_hors_boucle',
962
-			['champ' => '#RANG']
963
-		];
964
-		erreur_squelette($msg, $p);
965
-	} else {
966
-		// chercher d'abord un champ sql rang (mais pas dans le env : defaut '' si on trouve pas de champ sql)
967
-		// dans la boucle immediatement englobante uniquement
968
-		// sinon on compose le champ calcule
969
-		$_rang = champ_sql('rang', $p, '', false);
970
-
971
-		// si pas trouve de champ sql rang :
972
-		if (!$_rang or $_rang == "''") {
973
-			$boucle = &$p->boucles[$b];
974
-
975
-			// on gere le cas ou #RANG est une extraction du numero dans le titre
976
-			$trouver_table = charger_fonction('trouver_table', 'base');
977
-			$desc = $trouver_table($boucle->id_table);
978
-			$_titre = ''; # où extraire le numero ?
979
-
980
-			if (isset($desc['titre'])) {
981
-				$t = $desc['titre'];
982
-				if (
983
-					// Soit on trouve avec la déclaration de la lang AVANT
984
-					preg_match(';(?:lang\s*,)\s*(.*?titre)\s*(,|$);', $t, $m)
985
-					// Soit on prend depuis le début
986
-					or preg_match(';^(.*?titre)\s*(,|$);', $t, $m)
987
-				) {
988
-					$m = preg_replace(',as\s+titre$,i', '', $m[1]);
989
-					$m = trim($m);
990
-					if ($m != "''") {
991
-						if (!preg_match(',\W,', $m)) {
992
-							$m = $boucle->id_table . ".$m";
993
-						}
994
-
995
-						$m .= ' AS titre_rang';
996
-
997
-						$boucle->select[] = $m;
998
-						$_titre = '$Pile[$SP][\'titre_rang\']';
999
-					}
1000
-				}
1001
-			}
1002
-
1003
-			// si on n'a rien trouvé, on utilise le champ titre classique
1004
-			if (!$_titre) {
1005
-				$_titre = champ_sql('titre', $p);
1006
-			}
1007
-
1008
-			// et on recupere aussi les infos de liaison si on est en train d'editer les liens justement
1009
-			// cas des formulaires xxx_lies utilises par #FORMULAIRE_EDITER_LIENS
1010
-			$type_boucle = $boucle->type_requete;
1011
-			$objet = objet_type($type_boucle);
1012
-			$id_table_objet = id_table_objet($type_boucle);
1013
-			$_primary = champ_sql($id_table_objet, $p, '', false);
1014
-			$_env = '$Pile[0]';
1015
-
1016
-			if (!$_titre) {$_titre = "''";
1017
-			}
1018
-			if (!$_primary) {$_primary = "''";
1019
-			}
1020
-			$_rang = "calculer_rang_smart($_titre, '$objet', $_primary, $_env)";
1021
-		}
1022
-
1023
-		$p->code = $_rang;
1024
-		$p->interdire_scripts = false;
1025
-	}
1026
-
1027
-	return $p;
958
+    $b = index_boucle($p);
959
+    if ($b === '') {
960
+        $msg = [
961
+            'zbug_champ_hors_boucle',
962
+            ['champ' => '#RANG']
963
+        ];
964
+        erreur_squelette($msg, $p);
965
+    } else {
966
+        // chercher d'abord un champ sql rang (mais pas dans le env : defaut '' si on trouve pas de champ sql)
967
+        // dans la boucle immediatement englobante uniquement
968
+        // sinon on compose le champ calcule
969
+        $_rang = champ_sql('rang', $p, '', false);
970
+
971
+        // si pas trouve de champ sql rang :
972
+        if (!$_rang or $_rang == "''") {
973
+            $boucle = &$p->boucles[$b];
974
+
975
+            // on gere le cas ou #RANG est une extraction du numero dans le titre
976
+            $trouver_table = charger_fonction('trouver_table', 'base');
977
+            $desc = $trouver_table($boucle->id_table);
978
+            $_titre = ''; # où extraire le numero ?
979
+
980
+            if (isset($desc['titre'])) {
981
+                $t = $desc['titre'];
982
+                if (
983
+                    // Soit on trouve avec la déclaration de la lang AVANT
984
+                    preg_match(';(?:lang\s*,)\s*(.*?titre)\s*(,|$);', $t, $m)
985
+                    // Soit on prend depuis le début
986
+                    or preg_match(';^(.*?titre)\s*(,|$);', $t, $m)
987
+                ) {
988
+                    $m = preg_replace(',as\s+titre$,i', '', $m[1]);
989
+                    $m = trim($m);
990
+                    if ($m != "''") {
991
+                        if (!preg_match(',\W,', $m)) {
992
+                            $m = $boucle->id_table . ".$m";
993
+                        }
994
+
995
+                        $m .= ' AS titre_rang';
996
+
997
+                        $boucle->select[] = $m;
998
+                        $_titre = '$Pile[$SP][\'titre_rang\']';
999
+                    }
1000
+                }
1001
+            }
1002
+
1003
+            // si on n'a rien trouvé, on utilise le champ titre classique
1004
+            if (!$_titre) {
1005
+                $_titre = champ_sql('titre', $p);
1006
+            }
1007
+
1008
+            // et on recupere aussi les infos de liaison si on est en train d'editer les liens justement
1009
+            // cas des formulaires xxx_lies utilises par #FORMULAIRE_EDITER_LIENS
1010
+            $type_boucle = $boucle->type_requete;
1011
+            $objet = objet_type($type_boucle);
1012
+            $id_table_objet = id_table_objet($type_boucle);
1013
+            $_primary = champ_sql($id_table_objet, $p, '', false);
1014
+            $_env = '$Pile[0]';
1015
+
1016
+            if (!$_titre) {$_titre = "''";
1017
+            }
1018
+            if (!$_primary) {$_primary = "''";
1019
+            }
1020
+            $_rang = "calculer_rang_smart($_titre, '$objet', $_primary, $_env)";
1021
+        }
1022
+
1023
+        $p->code = $_rang;
1024
+        $p->interdire_scripts = false;
1025
+    }
1026
+
1027
+    return $p;
1028 1028
 }
1029 1029
 
1030 1030
 
@@ -1046,12 +1046,12 @@  discard block
 block discarded – undo
1046 1046
  *     Pile complétée par le code à générer
1047 1047
  **/
1048 1048
 function balise_POPULARITE_dist($p) {
1049
-	$_popularite = champ_sql('popularite', $p);
1050
-	$p->code = "(ceil(min(100, 100 * $_popularite
1049
+    $_popularite = champ_sql('popularite', $p);
1050
+    $p->code = "(ceil(min(100, 100 * $_popularite
1051 1051
 	/ max(1 , 0 + \$GLOBALS['meta']['popularite_max']))))";
1052
-	$p->interdire_scripts = false;
1052
+    $p->interdire_scripts = false;
1053 1053
 
1054
-	return $p;
1054
+    return $p;
1055 1055
 }
1056 1056
 
1057 1057
 /**
@@ -1062,8 +1062,8 @@  discard block
 block discarded – undo
1062 1062
  * l'absence peut-être due à une faute de frappe dans le contexte inclus.
1063 1063
  */
1064 1064
 define(
1065
-	'CODE_PAGINATION',
1066
-	'%s($Numrows["%s"]["grand_total"],
1065
+    'CODE_PAGINATION',
1066
+    '%s($Numrows["%s"]["grand_total"],
1067 1067
  		%s,
1068 1068
 		isset($Pile[0][%4$s])?$Pile[0][%4$s]:intval(_request(%4$s)),
1069 1069
 		%5$s, %6$s, %7$s, %8$s, array(%9$s))'
@@ -1100,75 +1100,75 @@  discard block
 block discarded – undo
1100 1100
  *     Pile complétée par le code à générer
1101 1101
  */
1102 1102
 function balise_PAGINATION_dist($p, $liste = 'true') {
1103
-	$b = index_boucle_mere($p);
1104
-
1105
-	// s'il n'y a pas de nom de boucle, on ne peut pas paginer
1106
-	if ($b === '') {
1107
-		$msg = [
1108
-			'zbug_champ_hors_boucle',
1109
-			['champ' => $liste ? 'PAGINATION' : 'ANCRE_PAGINATION']
1110
-		];
1111
-		erreur_squelette($msg, $p);
1112
-
1113
-		return $p;
1114
-	}
1115
-
1116
-	// s'il n'y a pas de mode_partie, c'est qu'on se trouve
1117
-	// dans un boucle recursive ou qu'on a oublie le critere {pagination}
1118
-	if (!$p->boucles[$b]->mode_partie) {
1119
-		if (!$p->boucles[$b]->table_optionnelle) {
1120
-			$msg = [
1121
-				'zbug_pagination_sans_critere',
1122
-				['champ' => '#PAGINATION']
1123
-			];
1124
-			erreur_squelette($msg, $p);
1125
-		}
1126
-
1127
-		return $p;
1128
-	}
1129
-
1130
-	// a priori true
1131
-	// si false, le compilo va bloquer sur des syntaxes avec un filtre sans argument qui suit la balise
1132
-	// si true, les arguments simples (sans truc=chose) vont degager
1133
-	$_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false, false);
1134
-	if (count($_contexte)) {
1135
-		$key = key($_contexte);
1136
-		if (is_numeric($key)) {
1137
-			array_shift($_contexte);
1138
-			$__modele = interprete_argument_balise(1, $p);
1139
-		}
1140
-	}
1141
-
1142
-	if (count($_contexte)) {
1143
-		$code_contexte = implode(',', $_contexte);
1144
-	} else {
1145
-		$code_contexte = '';
1146
-	}
1147
-
1148
-	$connect = $p->boucles[$b]->sql_serveur;
1149
-	$pas = $p->boucles[$b]->total_parties;
1150
-	$f_pagination = chercher_filtre('pagination');
1151
-	$type = $p->boucles[$b]->modificateur['debut_nom'];
1152
-	$modif = ($type[0] !== "'") ? "'debut'.$type"
1153
-		: ("'debut" . substr($type, 1));
1154
-
1155
-	$p->code = sprintf(
1156
-		CODE_PAGINATION,
1157
-		$f_pagination,
1158
-		$b,
1159
-		$type,
1160
-		$modif,
1161
-		$pas,
1162
-		$liste,
1163
-		((isset($__modele) and $__modele) ? $__modele : "''"),
1164
-		_q($connect),
1165
-		$code_contexte
1166
-	);
1167
-
1168
-	$p->boucles[$b]->numrows = true;
1169
-	$p->interdire_scripts = false;
1170
-
1171
-	return $p;
1103
+    $b = index_boucle_mere($p);
1104
+
1105
+    // s'il n'y a pas de nom de boucle, on ne peut pas paginer
1106
+    if ($b === '') {
1107
+        $msg = [
1108
+            'zbug_champ_hors_boucle',
1109
+            ['champ' => $liste ? 'PAGINATION' : 'ANCRE_PAGINATION']
1110
+        ];
1111
+        erreur_squelette($msg, $p);
1112
+
1113
+        return $p;
1114
+    }
1115
+
1116
+    // s'il n'y a pas de mode_partie, c'est qu'on se trouve
1117
+    // dans un boucle recursive ou qu'on a oublie le critere {pagination}
1118
+    if (!$p->boucles[$b]->mode_partie) {
1119
+        if (!$p->boucles[$b]->table_optionnelle) {
1120
+            $msg = [
1121
+                'zbug_pagination_sans_critere',
1122
+                ['champ' => '#PAGINATION']
1123
+            ];
1124
+            erreur_squelette($msg, $p);
1125
+        }
1126
+
1127
+        return $p;
1128
+    }
1129
+
1130
+    // a priori true
1131
+    // si false, le compilo va bloquer sur des syntaxes avec un filtre sans argument qui suit la balise
1132
+    // si true, les arguments simples (sans truc=chose) vont degager
1133
+    $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false, false);
1134
+    if (count($_contexte)) {
1135
+        $key = key($_contexte);
1136
+        if (is_numeric($key)) {
1137
+            array_shift($_contexte);
1138
+            $__modele = interprete_argument_balise(1, $p);
1139
+        }
1140
+    }
1141
+
1142
+    if (count($_contexte)) {
1143
+        $code_contexte = implode(',', $_contexte);
1144
+    } else {
1145
+        $code_contexte = '';
1146
+    }
1147
+
1148
+    $connect = $p->boucles[$b]->sql_serveur;
1149
+    $pas = $p->boucles[$b]->total_parties;
1150
+    $f_pagination = chercher_filtre('pagination');
1151
+    $type = $p->boucles[$b]->modificateur['debut_nom'];
1152
+    $modif = ($type[0] !== "'") ? "'debut'.$type"
1153
+        : ("'debut" . substr($type, 1));
1154
+
1155
+    $p->code = sprintf(
1156
+        CODE_PAGINATION,
1157
+        $f_pagination,
1158
+        $b,
1159
+        $type,
1160
+        $modif,
1161
+        $pas,
1162
+        $liste,
1163
+        ((isset($__modele) and $__modele) ? $__modele : "''"),
1164
+        _q($connect),
1165
+        $code_contexte
1166
+    );
1167
+
1168
+    $p->boucles[$b]->numrows = true;
1169
+    $p->interdire_scripts = false;
1170
+
1171
+    return $p;
1172 1172
 }
1173 1173
 
1174 1174
 
@@ -1195,11 +1195,11 @@  discard block
 block discarded – undo
1195 1195
  *     Pile complétée par le code à générer
1196 1196
  **/
1197 1197
 function balise_ANCRE_PAGINATION_dist($p) {
1198
-	if ($f = charger_fonction('PAGINATION', 'balise', true)) {
1199
-		return $f($p, $liste = 'false');
1200
-	} else {
1201
-		return null;
1202
-	} // ou une erreur ?
1198
+    if ($f = charger_fonction('PAGINATION', 'balise', true)) {
1199
+        return $f($p, $liste = 'false');
1200
+    } else {
1201
+        return null;
1202
+    } // ou une erreur ?
1203 1203
 }
1204 1204
 
1205 1205
 
@@ -1220,18 +1220,18 @@  discard block
 block discarded – undo
1220 1220
  *     Pile complétée par le code à générer
1221 1221
  **/
1222 1222
 function balise_GRAND_TOTAL_dist($p) {
1223
-	$b = index_boucle_mere($p);
1224
-	if ($b === '') {
1225
-		$msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]];
1226
-		erreur_squelette($msg, $p);
1227
-	} else {
1228
-		$p->code = "(isset(\$Numrows['$b']['grand_total'])
1223
+    $b = index_boucle_mere($p);
1224
+    if ($b === '') {
1225
+        $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]];
1226
+        erreur_squelette($msg, $p);
1227
+    } else {
1228
+        $p->code = "(isset(\$Numrows['$b']['grand_total'])
1229 1229
 			? \$Numrows['$b']['grand_total'] : \$Numrows['$b']['total'])";
1230
-		$p->boucles[$b]->numrows = true;
1231
-		$p->interdire_scripts = false;
1232
-	}
1230
+        $p->boucles[$b]->numrows = true;
1231
+        $p->interdire_scripts = false;
1232
+    }
1233 1233
 
1234
-	return $p;
1234
+    return $p;
1235 1235
 }
1236 1236
 
1237 1237
 
@@ -1259,10 +1259,10 @@  discard block
 block discarded – undo
1259 1259
  *     Pile complétée par le code à générer
1260 1260
  **/
1261 1261
 function balise_SELF_dist($p) {
1262
-	$p->code = 'self()';
1263
-	$p->interdire_scripts = false;
1262
+    $p->code = 'self()';
1263
+    $p->interdire_scripts = false;
1264 1264
 
1265
-	return $p;
1265
+    return $p;
1266 1266
 }
1267 1267
 
1268 1268
 
@@ -1289,17 +1289,17 @@  discard block
 block discarded – undo
1289 1289
  *     Pile complétée par le code à générer
1290 1290
  **/
1291 1291
 function balise_CHEMIN_dist($p) {
1292
-	$arg = interprete_argument_balise(1, $p);
1293
-	if (!$arg) {
1294
-		$msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN']];
1295
-		erreur_squelette($msg, $p);
1296
-	} else {
1297
-		$p->code = 'find_in_path(' . $arg . ')';
1298
-	}
1292
+    $arg = interprete_argument_balise(1, $p);
1293
+    if (!$arg) {
1294
+        $msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN']];
1295
+        erreur_squelette($msg, $p);
1296
+    } else {
1297
+        $p->code = 'find_in_path(' . $arg . ')';
1298
+    }
1299 1299
 
1300
-	$p->interdire_scripts = false;
1300
+    $p->interdire_scripts = false;
1301 1301
 
1302
-	return $p;
1302
+    return $p;
1303 1303
 }
1304 1304
 
1305 1305
 /**
@@ -1324,16 +1324,16 @@  discard block
 block discarded – undo
1324 1324
  *     Pile complétée par le code à générer
1325 1325
  **/
1326 1326
 function balise_CHEMIN_IMAGE_dist($p) {
1327
-	$arg = interprete_argument_balise(1, $p);
1328
-	if (!$arg) {
1329
-		$msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN_IMAGE']];
1330
-		erreur_squelette($msg, $p);
1331
-	} else {
1332
-		$p->code = 'chemin_image(' . $arg . ')';
1333
-	}
1327
+    $arg = interprete_argument_balise(1, $p);
1328
+    if (!$arg) {
1329
+        $msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN_IMAGE']];
1330
+        erreur_squelette($msg, $p);
1331
+    } else {
1332
+        $p->code = 'chemin_image(' . $arg . ')';
1333
+    }
1334 1334
 
1335
-	$p->interdire_scripts = false;
1336
-	return $p;
1335
+    $p->interdire_scripts = false;
1336
+    return $p;
1337 1337
 }
1338 1338
 
1339 1339
 
@@ -1371,36 +1371,36 @@  discard block
 block discarded – undo
1371 1371
  **/
1372 1372
 function balise_ENV_dist($p, $src = null) {
1373 1373
 
1374
-	// cle du tableau desiree
1375
-	$_nom = interprete_argument_balise(1, $p);
1376
-	// valeur par defaut
1377
-	$_sinon = interprete_argument_balise(2, $p);
1374
+    // cle du tableau desiree
1375
+    $_nom = interprete_argument_balise(1, $p);
1376
+    // valeur par defaut
1377
+    $_sinon = interprete_argument_balise(2, $p);
1378 1378
 
1379
-	// $src est un tableau de donnees sources eventuellement transmis
1380
-	// en absence, on utilise l'environnement du squelette $Pile[0]
1379
+    // $src est un tableau de donnees sources eventuellement transmis
1380
+    // en absence, on utilise l'environnement du squelette $Pile[0]
1381 1381
 
1382
-	if (!$_nom) {
1383
-		// cas de #ENV sans argument : on retourne le serialize() du tableau
1384
-		// une belle fonction [(#ENV|affiche_env)] serait pratique
1385
-		if ($src) {
1386
-			$p->code = '(is_array($a = (' . $src . ')) ? serialize($a) : "")';
1387
-		} else {
1388
-			$p->code = 'serialize($Pile[0]??[])';
1389
-		}
1390
-	} else {
1391
-		if (!$src) {
1392
-			$src = '$Pile[0]??[]';
1393
-		}
1394
-		if ($_sinon) {
1395
-			$p->code = "sinon(table_valeur($src, (string)$_nom, null), $_sinon)";
1396
-		} else {
1397
-			$p->code = "table_valeur($src, (string)$_nom, null)";
1398
-		}
1399
-	}
1382
+    if (!$_nom) {
1383
+        // cas de #ENV sans argument : on retourne le serialize() du tableau
1384
+        // une belle fonction [(#ENV|affiche_env)] serait pratique
1385
+        if ($src) {
1386
+            $p->code = '(is_array($a = (' . $src . ')) ? serialize($a) : "")';
1387
+        } else {
1388
+            $p->code = 'serialize($Pile[0]??[])';
1389
+        }
1390
+    } else {
1391
+        if (!$src) {
1392
+            $src = '$Pile[0]??[]';
1393
+        }
1394
+        if ($_sinon) {
1395
+            $p->code = "sinon(table_valeur($src, (string)$_nom, null), $_sinon)";
1396
+        } else {
1397
+            $p->code = "table_valeur($src, (string)$_nom, null)";
1398
+        }
1399
+    }
1400 1400
 
1401
-	#$p->interdire_scripts = true;
1401
+    #$p->interdire_scripts = true;
1402 1402
 
1403
-	return $p;
1403
+    return $p;
1404 1404
 }
1405 1405
 
1406 1406
 /**
@@ -1430,16 +1430,16 @@  discard block
 block discarded – undo
1430 1430
  *     Pile completée du code PHP d'exécution de la balise
1431 1431
  */
1432 1432
 function balise_CONFIG_dist($p) {
1433
-	if (!$arg = interprete_argument_balise(1, $p)) {
1434
-		$arg = "''";
1435
-	}
1436
-	$_sinon = interprete_argument_balise(2, $p);
1437
-	$_unserialize = sinon(interprete_argument_balise(3, $p), 'false');
1433
+    if (!$arg = interprete_argument_balise(1, $p)) {
1434
+        $arg = "''";
1435
+    }
1436
+    $_sinon = interprete_argument_balise(2, $p);
1437
+    $_unserialize = sinon(interprete_argument_balise(3, $p), 'false');
1438 1438
 
1439
-	$p->code = '(include_spip(\'inc/config\')?lire_config(' . $arg . ',' .
1440
-		($_sinon && $_sinon != "''" ? $_sinon : 'null') . ',' . $_unserialize . "):'')";
1439
+    $p->code = '(include_spip(\'inc/config\')?lire_config(' . $arg . ',' .
1440
+        ($_sinon && $_sinon != "''" ? $_sinon : 'null') . ',' . $_unserialize . "):'')";
1441 1441
 
1442
-	return $p;
1442
+    return $p;
1443 1443
 }
1444 1444
 
1445 1445
 
@@ -1462,10 +1462,10 @@  discard block
 block discarded – undo
1462 1462
  *     Pile completée du code PHP d'exécution de la balise
1463 1463
  */
1464 1464
 function balise_CONNECT_dist($p) {
1465
-	$p->code = '($connect ? $connect : NULL)';
1466
-	$p->interdire_scripts = false;
1465
+    $p->code = '($connect ? $connect : NULL)';
1466
+    $p->interdire_scripts = false;
1467 1467
 
1468
-	return $p;
1468
+    return $p;
1469 1469
 }
1470 1470
 
1471 1471
 
@@ -1493,15 +1493,15 @@  discard block
 block discarded – undo
1493 1493
  *     Pile completée du code PHP d'exécution de la balise
1494 1494
  **/
1495 1495
 function balise_SESSION_dist($p) {
1496
-	$p->descr['session'] = true;
1496
+    $p->descr['session'] = true;
1497 1497
 
1498
-	$f = function_exists('balise_ENV')
1499
-		? 'balise_ENV'
1500
-		: 'balise_ENV_dist';
1498
+    $f = function_exists('balise_ENV')
1499
+        ? 'balise_ENV'
1500
+        : 'balise_ENV_dist';
1501 1501
 
1502
-	$p = $f($p, '$GLOBALS["visiteur_session"]??[]');
1502
+    $p = $f($p, '$GLOBALS["visiteur_session"]??[]');
1503 1503
 
1504
-	return $p;
1504
+    return $p;
1505 1505
 }
1506 1506
 
1507 1507
 
@@ -1524,18 +1524,18 @@  discard block
 block discarded – undo
1524 1524
  *     Pile completée du code PHP d'exécution de la balise
1525 1525
  **/
1526 1526
 function balise_SESSION_SET_dist($p) {
1527
-	$_nom = interprete_argument_balise(1, $p);
1528
-	$_val = interprete_argument_balise(2, $p);
1529
-	if (!$_nom or !$_val) {
1530
-		$err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SESSION_SET']];
1531
-		erreur_squelette($err_b_s_a, $p);
1532
-	} else {
1533
-		$p->code = '(include_spip("inc/session") AND session_set(' . $_nom . ',' . $_val . '))';
1534
-	}
1527
+    $_nom = interprete_argument_balise(1, $p);
1528
+    $_val = interprete_argument_balise(2, $p);
1529
+    if (!$_nom or !$_val) {
1530
+        $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SESSION_SET']];
1531
+        erreur_squelette($err_b_s_a, $p);
1532
+    } else {
1533
+        $p->code = '(include_spip("inc/session") AND session_set(' . $_nom . ',' . $_val . '))';
1534
+    }
1535 1535
 
1536
-	$p->interdire_scripts = false;
1536
+    $p->interdire_scripts = false;
1537 1537
 
1538
-	return $p;
1538
+    return $p;
1539 1539
 }
1540 1540
 
1541 1541
 
@@ -1566,30 +1566,30 @@  discard block
 block discarded – undo
1566 1566
  *     Pile completée du code PHP d'exécution de la balise
1567 1567
  **/
1568 1568
 function balise_EVAL_dist($p) {
1569
-	$php = interprete_argument_balise(1, $p);
1570
-	if ($php) {
1571
-		# optimisation sur les #EVAL{une expression sans #BALISE}
1572
-		# attention au commentaire "// x signes" qui precede
1573
-		if (
1574
-			preg_match(
1575
-				",^([[:space:]]*//[^\n]*\n)'([^']+)'$,ms",
1576
-				$php,
1577
-				$r
1578
-			)
1579
-		) {
1580
-			$p->code = /* $r[1]. */
1581
-				'(' . $r[2] . ')';
1582
-		} else {
1583
-			$p->code = "eval('return '.$php.';')";
1584
-		}
1585
-	} else {
1586
-		$msg = ['zbug_balise_sans_argument', ['balise' => ' EVAL']];
1587
-		erreur_squelette($msg, $p);
1588
-	}
1589
-
1590
-	#$p->interdire_scripts = true;
1591
-
1592
-	return $p;
1569
+    $php = interprete_argument_balise(1, $p);
1570
+    if ($php) {
1571
+        # optimisation sur les #EVAL{une expression sans #BALISE}
1572
+        # attention au commentaire "// x signes" qui precede
1573
+        if (
1574
+            preg_match(
1575
+                ",^([[:space:]]*//[^\n]*\n)'([^']+)'$,ms",
1576
+                $php,
1577
+                $r
1578
+            )
1579
+        ) {
1580
+            $p->code = /* $r[1]. */
1581
+                '(' . $r[2] . ')';
1582
+        } else {
1583
+            $p->code = "eval('return '.$php.';')";
1584
+        }
1585
+    } else {
1586
+        $msg = ['zbug_balise_sans_argument', ['balise' => ' EVAL']];
1587
+        erreur_squelette($msg, $p);
1588
+    }
1589
+
1590
+    #$p->interdire_scripts = true;
1591
+
1592
+    return $p;
1593 1593
 }
1594 1594
 
1595 1595
 
@@ -1619,19 +1619,19 @@  discard block
 block discarded – undo
1619 1619
  **/
1620 1620
 function balise_CHAMP_SQL_dist($p) {
1621 1621
 
1622
-	if (
1623
-		$p->param
1624
-		and isset($p->param[0][1][0])
1625
-		and $champ = ($p->param[0][1][0]->texte)
1626
-	) {
1627
-		$p->code = champ_sql($champ, $p);
1628
-	} else {
1629
-		$err_b_s_a = ['zbug_balise_sans_argument', ['balise' => ' CHAMP_SQL']];
1630
-		erreur_squelette($err_b_s_a, $p);
1631
-	}
1622
+    if (
1623
+        $p->param
1624
+        and isset($p->param[0][1][0])
1625
+        and $champ = ($p->param[0][1][0]->texte)
1626
+    ) {
1627
+        $p->code = champ_sql($champ, $p);
1628
+    } else {
1629
+        $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => ' CHAMP_SQL']];
1630
+        erreur_squelette($err_b_s_a, $p);
1631
+    }
1632 1632
 
1633
-	#$p->interdire_scripts = true;
1634
-	return $p;
1633
+    #$p->interdire_scripts = true;
1634
+    return $p;
1635 1635
 }
1636 1636
 
1637 1637
 /**
@@ -1657,13 +1657,13 @@  discard block
 block discarded – undo
1657 1657
  *     Pile complétée par le code à générer
1658 1658
  **/
1659 1659
 function balise_VAL_dist($p) {
1660
-	$p->code = interprete_argument_balise(1, $p);
1661
-	if (!strlen($p->code)) {
1662
-		$p->code = "''";
1663
-	}
1664
-	$p->interdire_scripts = false;
1660
+    $p->code = interprete_argument_balise(1, $p);
1661
+    if (!strlen($p->code)) {
1662
+        $p->code = "''";
1663
+    }
1664
+    $p->interdire_scripts = false;
1665 1665
 
1666
-	return $p;
1666
+    return $p;
1667 1667
 }
1668 1668
 
1669 1669
 /**
@@ -1692,10 +1692,10 @@  discard block
 block discarded – undo
1692 1692
  *     Pile complétée par le code à générer
1693 1693
  **/
1694 1694
 function balise_REM_dist($p) {
1695
-	$p->code = "''";
1696
-	$p->interdire_scripts = false;
1695
+    $p->code = "''";
1696
+    $p->interdire_scripts = false;
1697 1697
 
1698
-	return $p;
1698
+    return $p;
1699 1699
 }
1700 1700
 
1701 1701
 /**
@@ -1705,10 +1705,10 @@  discard block
 block discarded – undo
1705 1705
  * @return mixed
1706 1706
  */
1707 1707
 function balise_NULL_dist($p) {
1708
-	$p->code = 'null';
1709
-	$p->interdire_scripts = false;
1708
+    $p->code = 'null';
1709
+    $p->interdire_scripts = false;
1710 1710
 
1711
-	return $p;
1711
+    return $p;
1712 1712
 }
1713 1713
 
1714 1714
 
@@ -1732,18 +1732,18 @@  discard block
 block discarded – undo
1732 1732
  **/
1733 1733
 function balise_HTTP_HEADER_dist($p) {
1734 1734
 
1735
-	$header = interprete_argument_balise(1, $p);
1736
-	if (!$header) {
1737
-		$err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'HTTP_HEADER']];
1738
-		erreur_squelette($err_b_s_a, $p);
1739
-	} else {
1740
-		$p->code = "'<'.'?php header(' . _q("
1741
-			. $header
1742
-			. ") . '); ?'.'>'";
1743
-	}
1744
-	$p->interdire_scripts = false;
1735
+    $header = interprete_argument_balise(1, $p);
1736
+    if (!$header) {
1737
+        $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'HTTP_HEADER']];
1738
+        erreur_squelette($err_b_s_a, $p);
1739
+    } else {
1740
+        $p->code = "'<'.'?php header(' . _q("
1741
+            . $header
1742
+            . ") . '); ?'.'>'";
1743
+    }
1744
+    $p->interdire_scripts = false;
1745 1745
 
1746
-	return $p;
1746
+    return $p;
1747 1747
 }
1748 1748
 
1749 1749
 
@@ -1768,20 +1768,20 @@  discard block
 block discarded – undo
1768 1768
  *     Pile complétée par le code à générer
1769 1769
  **/
1770 1770
 function balise_FILTRE_dist($p) {
1771
-	if ($p->param) {
1772
-		$args = [];
1773
-		foreach ($p->param as $i => $ignore) {
1774
-			$args[] = interprete_argument_balise($i + 1, $p);
1775
-		}
1776
-		$p->code = "'<' . '"
1777
-			. '?php header("X-Spip-Filtre: \'.'
1778
-			. join('.\'|\'.', $args)
1779
-			. " . '\"); ?'.'>'";
1771
+    if ($p->param) {
1772
+        $args = [];
1773
+        foreach ($p->param as $i => $ignore) {
1774
+            $args[] = interprete_argument_balise($i + 1, $p);
1775
+        }
1776
+        $p->code = "'<' . '"
1777
+            . '?php header("X-Spip-Filtre: \'.'
1778
+            . join('.\'|\'.', $args)
1779
+            . " . '\"); ?'.'>'";
1780 1780
 
1781
-		$p->interdire_scripts = false;
1781
+        $p->interdire_scripts = false;
1782 1782
 
1783
-		return $p;
1784
-	}
1783
+        return $p;
1784
+    }
1785 1785
 }
1786 1786
 
1787 1787
 
@@ -1817,55 +1817,55 @@  discard block
 block discarded – undo
1817 1817
  **/
1818 1818
 function balise_CACHE_dist($p) {
1819 1819
 
1820
-	if ($p->param) {
1821
-		$duree = valeur_numerique($p->param[0][1][0]->texte);
1822
-
1823
-		// noter la duree du cache dans un entete proprietaire
1824
-
1825
-		$code = "'<'.'" . '?php header("X-Spip-Cache: '
1826
-			. $duree
1827
-			. '"); ?' . "'.'>'";
1828
-
1829
-		// Remplir le header Cache-Control
1830
-		// cas #CACHE{0}
1831
-		if ($duree == 0) {
1832
-			$code .= ".'<'.'"
1833
-				. '?php header("Cache-Control: no-cache, must-revalidate"); ?'
1834
-				. "'.'><'.'"
1835
-				. '?php header("Pragma: no-cache"); ?'
1836
-				. "'.'>'";
1837
-		}
1838
-
1839
-		// recuperer les parametres suivants
1840
-		$i = 1;
1841
-		while (isset($p->param[0][++$i])) {
1842
-			$pa = ($p->param[0][$i][0]->texte);
1843
-
1844
-			if (
1845
-				$pa == 'cache-client'
1846
-				and $duree > 0
1847
-			) {
1848
-				$code .= ".'<'.'" . '?php header("Cache-Control: max-age='
1849
-					. $duree
1850
-					. '"); ?' . "'.'>'";
1851
-				// il semble logique, si on cache-client, de ne pas invalider
1852
-				$pa = 'statique';
1853
-			}
1854
-
1855
-			if (
1856
-				$pa == 'statique'
1857
-				and $duree > 0
1858
-			) {
1859
-				$code .= ".'<'.'" . '?php header("X-Spip-Statique: oui"); ?' . "'.'>'";
1860
-			}
1861
-		}
1862
-	} else {
1863
-		$code = "''";
1864
-	}
1865
-	$p->code = $code;
1866
-	$p->interdire_scripts = false;
1867
-
1868
-	return $p;
1820
+    if ($p->param) {
1821
+        $duree = valeur_numerique($p->param[0][1][0]->texte);
1822
+
1823
+        // noter la duree du cache dans un entete proprietaire
1824
+
1825
+        $code = "'<'.'" . '?php header("X-Spip-Cache: '
1826
+            . $duree
1827
+            . '"); ?' . "'.'>'";
1828
+
1829
+        // Remplir le header Cache-Control
1830
+        // cas #CACHE{0}
1831
+        if ($duree == 0) {
1832
+            $code .= ".'<'.'"
1833
+                . '?php header("Cache-Control: no-cache, must-revalidate"); ?'
1834
+                . "'.'><'.'"
1835
+                . '?php header("Pragma: no-cache"); ?'
1836
+                . "'.'>'";
1837
+        }
1838
+
1839
+        // recuperer les parametres suivants
1840
+        $i = 1;
1841
+        while (isset($p->param[0][++$i])) {
1842
+            $pa = ($p->param[0][$i][0]->texte);
1843
+
1844
+            if (
1845
+                $pa == 'cache-client'
1846
+                and $duree > 0
1847
+            ) {
1848
+                $code .= ".'<'.'" . '?php header("Cache-Control: max-age='
1849
+                    . $duree
1850
+                    . '"); ?' . "'.'>'";
1851
+                // il semble logique, si on cache-client, de ne pas invalider
1852
+                $pa = 'statique';
1853
+            }
1854
+
1855
+            if (
1856
+                $pa == 'statique'
1857
+                and $duree > 0
1858
+            ) {
1859
+                $code .= ".'<'.'" . '?php header("X-Spip-Statique: oui"); ?' . "'.'>'";
1860
+            }
1861
+        }
1862
+    } else {
1863
+        $code = "''";
1864
+    }
1865
+    $p->code = $code;
1866
+    $p->interdire_scripts = false;
1867
+
1868
+    return $p;
1869 1869
 }
1870 1870
 
1871 1871
 
@@ -1897,13 +1897,13 @@  discard block
 block discarded – undo
1897 1897
  *     Pile complétée par le code à générer
1898 1898
  */
1899 1899
 function balise_INSERT_HEAD_dist($p) {
1900
-	$p->code = "'<'.'"
1901
-		. '?php header("X-Spip-Filtre: insert_head_css_conditionnel"); ?'
1902
-		. "'.'>'";
1903
-	$p->code .= ". pipeline('insert_head','<!-- insert_head -->')";
1904
-	$p->interdire_scripts = false;
1900
+    $p->code = "'<'.'"
1901
+        . '?php header("X-Spip-Filtre: insert_head_css_conditionnel"); ?'
1902
+        . "'.'>'";
1903
+    $p->code .= ". pipeline('insert_head','<!-- insert_head -->')";
1904
+    $p->interdire_scripts = false;
1905 1905
 
1906
-	return $p;
1906
+    return $p;
1907 1907
 }
1908 1908
 
1909 1909
 /**
@@ -1921,10 +1921,10 @@  discard block
 block discarded – undo
1921 1921
  *     Pile complétée par le code à générer
1922 1922
  */
1923 1923
 function balise_INSERT_HEAD_CSS_dist($p) {
1924
-	$p->code = "pipeline('insert_head_css','<!-- insert_head_css -->')";
1925
-	$p->interdire_scripts = false;
1924
+    $p->code = "pipeline('insert_head_css','<!-- insert_head_css -->')";
1925
+    $p->interdire_scripts = false;
1926 1926
 
1927
-	return $p;
1927
+    return $p;
1928 1928
 }
1929 1929
 
1930 1930
 /**
@@ -1939,11 +1939,11 @@  discard block
 block discarded – undo
1939 1939
  *     Pile complétée par le code à générer
1940 1940
  **/
1941 1941
 function balise_INCLUDE_dist($p) {
1942
-	if (function_exists('balise_INCLURE')) {
1943
-		return balise_INCLURE($p);
1944
-	} else {
1945
-		return balise_INCLURE_dist($p);
1946
-	}
1942
+    if (function_exists('balise_INCLURE')) {
1943
+        return balise_INCLURE($p);
1944
+    } else {
1945
+        return balise_INCLURE_dist($p);
1946
+    }
1947 1947
 }
1948 1948
 
1949 1949
 /**
@@ -1977,66 +1977,66 @@  discard block
 block discarded – undo
1977 1977
  *     Pile complétée par le code à générer
1978 1978
  **/
1979 1979
 function balise_INCLURE_dist($p) {
1980
-	$id_boucle = $p->id_boucle;
1981
-	// la lang n'est pas passe de facon automatique par argumenter
1982
-	// mais le sera pas recuperer_fond, sauf si etoile=>true est passe
1983
-	// en option
1984
-
1985
-	$_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $id_boucle, false, false);
1986
-
1987
-	// erreur de syntaxe = fond absent
1988
-	// (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP
1989
-	if (!$_contexte) {
1990
-		$contexte = [];
1991
-	}
1992
-
1993
-	if (isset($_contexte['fond'])) {
1994
-		$f = $_contexte['fond'];
1995
-		// toujours vrai :
1996
-		if (preg_match('/^.fond.\s*=>(.*)$/s', $f, $r)) {
1997
-			$f = $r[1];
1998
-			unset($_contexte['fond']);
1999
-		} else {
2000
-			spip_log('compilation de #INCLURE a revoir');
2001
-		}
2002
-
2003
-		// #INCLURE{doublons}
2004
-		if (isset($_contexte['doublons'])) {
2005
-			$_contexte['doublons'] = "'doublons' => \$doublons";
2006
-		}
2007
-
2008
-		// Critere d'inclusion {env} (et {self} pour compatibilite ascendante)
2009
-		$flag_env = false;
2010
-		if (isset($_contexte['env']) or isset($_contexte['self'])) {
2011
-			$flag_env = true;
2012
-			unset($_contexte['env']);
2013
-		}
2014
-
2015
-		$_options = [];
2016
-		if (isset($_contexte['ajax'])) {
2017
-			$_options[] = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']);
2018
-			unset($_contexte['ajax']);
2019
-		}
2020
-		if ($p->etoile) {
2021
-			$_options[] = "'etoile'=>true";
2022
-		}
2023
-		$_options[] = "'compil'=>array(" . memoriser_contexte_compil($p) . ')';
2024
-
2025
-		$_l = 'array(' . join(",\n\t", $_contexte) . ')';
2026
-		if ($flag_env) {
2027
-			$_l = "array_merge(\$Pile[0],$_l)";
2028
-		}
2029
-
2030
-		$p->code = sprintf(CODE_RECUPERER_FOND, $f, $_l, join(',', $_options), "_request('connect')");
2031
-	} elseif (!isset($_contexte[1])) {
2032
-		$msg = ['zbug_balise_sans_argument', ['balise' => ' INCLURE']];
2033
-		erreur_squelette($msg, $p);
2034
-	} else {
2035
-		$p->code = 'charge_scripts(' . $_contexte[1] . ',false)';
2036
-	}
2037
-
2038
-	$p->interdire_scripts = false; // la securite est assuree par recuperer_fond
2039
-	return $p;
1980
+    $id_boucle = $p->id_boucle;
1981
+    // la lang n'est pas passe de facon automatique par argumenter
1982
+    // mais le sera pas recuperer_fond, sauf si etoile=>true est passe
1983
+    // en option
1984
+
1985
+    $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $id_boucle, false, false);
1986
+
1987
+    // erreur de syntaxe = fond absent
1988
+    // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP
1989
+    if (!$_contexte) {
1990
+        $contexte = [];
1991
+    }
1992
+
1993
+    if (isset($_contexte['fond'])) {
1994
+        $f = $_contexte['fond'];
1995
+        // toujours vrai :
1996
+        if (preg_match('/^.fond.\s*=>(.*)$/s', $f, $r)) {
1997
+            $f = $r[1];
1998
+            unset($_contexte['fond']);
1999
+        } else {
2000
+            spip_log('compilation de #INCLURE a revoir');
2001
+        }
2002
+
2003
+        // #INCLURE{doublons}
2004
+        if (isset($_contexte['doublons'])) {
2005
+            $_contexte['doublons'] = "'doublons' => \$doublons";
2006
+        }
2007
+
2008
+        // Critere d'inclusion {env} (et {self} pour compatibilite ascendante)
2009
+        $flag_env = false;
2010
+        if (isset($_contexte['env']) or isset($_contexte['self'])) {
2011
+            $flag_env = true;
2012
+            unset($_contexte['env']);
2013
+        }
2014
+
2015
+        $_options = [];
2016
+        if (isset($_contexte['ajax'])) {
2017
+            $_options[] = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']);
2018
+            unset($_contexte['ajax']);
2019
+        }
2020
+        if ($p->etoile) {
2021
+            $_options[] = "'etoile'=>true";
2022
+        }
2023
+        $_options[] = "'compil'=>array(" . memoriser_contexte_compil($p) . ')';
2024
+
2025
+        $_l = 'array(' . join(",\n\t", $_contexte) . ')';
2026
+        if ($flag_env) {
2027
+            $_l = "array_merge(\$Pile[0],$_l)";
2028
+        }
2029
+
2030
+        $p->code = sprintf(CODE_RECUPERER_FOND, $f, $_l, join(',', $_options), "_request('connect')");
2031
+    } elseif (!isset($_contexte[1])) {
2032
+        $msg = ['zbug_balise_sans_argument', ['balise' => ' INCLURE']];
2033
+        erreur_squelette($msg, $p);
2034
+    } else {
2035
+        $p->code = 'charge_scripts(' . $_contexte[1] . ',false)';
2036
+    }
2037
+
2038
+    $p->interdire_scripts = false; // la securite est assuree par recuperer_fond
2039
+    return $p;
2040 2040
 }
2041 2041
 
2042 2042
 
@@ -2064,69 +2064,69 @@  discard block
 block discarded – undo
2064 2064
  **/
2065 2065
 function balise_MODELE_dist($p) {
2066 2066
 
2067
-	$_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false);
2068
-
2069
-	// erreur de syntaxe = fond absent
2070
-	// (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP
2071
-	if (!$_contexte) {
2072
-		$_contexte = [];
2073
-	}
2074
-
2075
-	if (!isset($_contexte[1])) {
2076
-		$msg = ['zbug_balise_sans_argument', ['balise' => ' MODELE']];
2077
-		erreur_squelette($msg, $p);
2078
-	} else {
2079
-		$nom = $_contexte[1];
2080
-		unset($_contexte[1]);
2081
-
2082
-		if (preg_match("/^\s*'[^']*'/s", $nom)) {
2083
-			$nom = "'modeles/" . substr($nom, 1);
2084
-		} else {
2085
-			$nom = "'modeles/' . $nom";
2086
-		}
2087
-
2088
-		$flag_env = false;
2089
-		if (isset($_contexte['env'])) {
2090
-			$flag_env = true;
2091
-			unset($_contexte['env']);
2092
-		}
2093
-
2094
-		// Incoherence dans la syntaxe du contexte. A revoir.
2095
-		// Reserver la cle primaire de la boucle courante si elle existe
2096
-		if (isset($p->boucles[$p->id_boucle]->primary)) {
2097
-			$primary = $p->boucles[$p->id_boucle]->primary;
2098
-			if (!strpos($primary, ',')) {
2099
-				$id = champ_sql($primary, $p);
2100
-				$_contexte[] = "'$primary'=>" . $id;
2101
-				$_contexte[] = "'id'=>" . $id;
2102
-			}
2103
-		}
2104
-		$_contexte[] = "'recurs'=>(++\$recurs)";
2105
-		$connect = '';
2106
-		if (isset($p->boucles[$p->id_boucle])) {
2107
-			$connect = $p->boucles[$p->id_boucle]->sql_serveur;
2108
-		}
2109
-
2110
-		$_options = memoriser_contexte_compil($p);
2111
-		$_options = "'compil'=>array($_options), 'trim'=>true";
2112
-		if (isset($_contexte['ajax'])) {
2113
-			$_options .= ', ' . preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']);
2114
-			unset($_contexte['ajax']);
2115
-		}
2116
-
2117
-		$_l = 'array(' . join(",\n\t", $_contexte) . ')';
2118
-		if ($flag_env) {
2119
-			$_l = "array_merge(\$Pile[0],$_l)";
2120
-		}
2121
-
2122
-		$page = sprintf(CODE_RECUPERER_FOND, $nom, $_l, $_options, _q($connect));
2123
-
2124
-		$p->code = "\n\t(((\$recurs=(isset(\$Pile[0]['recurs'])?\$Pile[0]['recurs']:0))>=5)? '' :\n\t$page)\n";
2125
-
2126
-		$p->interdire_scripts = false; // securite assuree par le squelette
2127
-	}
2128
-
2129
-	return $p;
2067
+    $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false);
2068
+
2069
+    // erreur de syntaxe = fond absent
2070
+    // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP
2071
+    if (!$_contexte) {
2072
+        $_contexte = [];
2073
+    }
2074
+
2075
+    if (!isset($_contexte[1])) {
2076
+        $msg = ['zbug_balise_sans_argument', ['balise' => ' MODELE']];
2077
+        erreur_squelette($msg, $p);
2078
+    } else {
2079
+        $nom = $_contexte[1];
2080
+        unset($_contexte[1]);
2081
+
2082
+        if (preg_match("/^\s*'[^']*'/s", $nom)) {
2083
+            $nom = "'modeles/" . substr($nom, 1);
2084
+        } else {
2085
+            $nom = "'modeles/' . $nom";
2086
+        }
2087
+
2088
+        $flag_env = false;
2089
+        if (isset($_contexte['env'])) {
2090
+            $flag_env = true;
2091
+            unset($_contexte['env']);
2092
+        }
2093
+
2094
+        // Incoherence dans la syntaxe du contexte. A revoir.
2095
+        // Reserver la cle primaire de la boucle courante si elle existe
2096
+        if (isset($p->boucles[$p->id_boucle]->primary)) {
2097
+            $primary = $p->boucles[$p->id_boucle]->primary;
2098
+            if (!strpos($primary, ',')) {
2099
+                $id = champ_sql($primary, $p);
2100
+                $_contexte[] = "'$primary'=>" . $id;
2101
+                $_contexte[] = "'id'=>" . $id;
2102
+            }
2103
+        }
2104
+        $_contexte[] = "'recurs'=>(++\$recurs)";
2105
+        $connect = '';
2106
+        if (isset($p->boucles[$p->id_boucle])) {
2107
+            $connect = $p->boucles[$p->id_boucle]->sql_serveur;
2108
+        }
2109
+
2110
+        $_options = memoriser_contexte_compil($p);
2111
+        $_options = "'compil'=>array($_options), 'trim'=>true";
2112
+        if (isset($_contexte['ajax'])) {
2113
+            $_options .= ', ' . preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']);
2114
+            unset($_contexte['ajax']);
2115
+        }
2116
+
2117
+        $_l = 'array(' . join(",\n\t", $_contexte) . ')';
2118
+        if ($flag_env) {
2119
+            $_l = "array_merge(\$Pile[0],$_l)";
2120
+        }
2121
+
2122
+        $page = sprintf(CODE_RECUPERER_FOND, $nom, $_l, $_options, _q($connect));
2123
+
2124
+        $p->code = "\n\t(((\$recurs=(isset(\$Pile[0]['recurs'])?\$Pile[0]['recurs']:0))>=5)? '' :\n\t$page)\n";
2125
+
2126
+        $p->interdire_scripts = false; // securite assuree par le squelette
2127
+    }
2128
+
2129
+    return $p;
2130 2130
 }
2131 2131
 
2132 2132
 
@@ -2150,21 +2150,21 @@  discard block
 block discarded – undo
2150 2150
  *     Pile complétée par le code à générer
2151 2151
  **/
2152 2152
 function balise_SET_dist($p) {
2153
-	$_nom = interprete_argument_balise(1, $p);
2154
-	$_val = interprete_argument_balise(2, $p);
2153
+    $_nom = interprete_argument_balise(1, $p);
2154
+    $_val = interprete_argument_balise(2, $p);
2155 2155
 
2156
-	if (!$_nom or !$_val) {
2157
-		$err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SET']];
2158
-		erreur_squelette($err_b_s_a, $p);
2159
-	}
2160
-	// affectation $_zzz inutile, mais permet de contourner un bug OpCode cache sous PHP 5.5.4
2161
-	// cf https://bugs.php.net/bug.php?id=65845
2162
-	else {
2163
-		$p->code = "vide(\$Pile['vars'][\$_zzz=(string)$_nom] = $_val)";
2164
-	}
2156
+    if (!$_nom or !$_val) {
2157
+        $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SET']];
2158
+        erreur_squelette($err_b_s_a, $p);
2159
+    }
2160
+    // affectation $_zzz inutile, mais permet de contourner un bug OpCode cache sous PHP 5.5.4
2161
+    // cf https://bugs.php.net/bug.php?id=65845
2162
+    else {
2163
+        $p->code = "vide(\$Pile['vars'][\$_zzz=(string)$_nom] = $_val)";
2164
+    }
2165 2165
 
2166
-	$p->interdire_scripts = false; // la balise ne renvoie rien
2167
-	return $p;
2166
+    $p->interdire_scripts = false; // la balise ne renvoie rien
2167
+    return $p;
2168 2168
 }
2169 2169
 
2170 2170
 
@@ -2194,12 +2194,12 @@  discard block
 block discarded – undo
2194 2194
  *     Pile complétée par le code à générer
2195 2195
  **/
2196 2196
 function balise_GET_dist($p) {
2197
-	$p->interdire_scripts = false; // le contenu vient de #SET, donc il est de confiance
2198
-	if (function_exists('balise_ENV')) {
2199
-		return balise_ENV($p, '$Pile["vars"]??[]');
2200
-	} else {
2201
-		return balise_ENV_dist($p, '$Pile["vars"]??[]');
2202
-	}
2197
+    $p->interdire_scripts = false; // le contenu vient de #SET, donc il est de confiance
2198
+    if (function_exists('balise_ENV')) {
2199
+        return balise_ENV($p, '$Pile["vars"]??[]');
2200
+    } else {
2201
+        return balise_ENV_dist($p, '$Pile["vars"]??[]');
2202
+    }
2203 2203
 }
2204 2204
 
2205 2205
 
@@ -2222,22 +2222,22 @@  discard block
 block discarded – undo
2222 2222
  *     Pile complétée par le code à générer
2223 2223
  **/
2224 2224
 function balise_DOUBLONS_dist($p) {
2225
-	if ($type = interprete_argument_balise(1, $p)) {
2226
-		if ($famille = interprete_argument_balise(2, $p)) {
2227
-			$type .= '.' . $famille;
2228
-		}
2229
-		$p->code = '(isset($doublons[' . $type . ']) ? $doublons[' . $type . '] : "")';
2230
-		if (!$p->etoile) {
2231
-			$p->code = 'array_filter(array_map("intval",explode(",",'
2232
-				. $p->code . ')))';
2233
-		}
2234
-	} else {
2235
-		$p->code = '$doublons';
2236
-	}
2225
+    if ($type = interprete_argument_balise(1, $p)) {
2226
+        if ($famille = interprete_argument_balise(2, $p)) {
2227
+            $type .= '.' . $famille;
2228
+        }
2229
+        $p->code = '(isset($doublons[' . $type . ']) ? $doublons[' . $type . '] : "")';
2230
+        if (!$p->etoile) {
2231
+            $p->code = 'array_filter(array_map("intval",explode(",",'
2232
+                . $p->code . ')))';
2233
+        }
2234
+    } else {
2235
+        $p->code = '$doublons';
2236
+    }
2237 2237
 
2238
-	$p->interdire_scripts = false;
2238
+    $p->interdire_scripts = false;
2239 2239
 
2240
-	return $p;
2240
+    return $p;
2241 2241
 }
2242 2242
 
2243 2243
 
@@ -2260,18 +2260,18 @@  discard block
 block discarded – undo
2260 2260
  *     Pile complétée par le code à générer
2261 2261
  **/
2262 2262
 function balise_PIPELINE_dist($p) {
2263
-	$_pipe = interprete_argument_balise(1, $p);
2264
-	if (!$_pipe) {
2265
-		$err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'PIPELINE']];
2266
-		erreur_squelette($err_b_s_a, $p);
2267
-	} else {
2268
-		$_flux = interprete_argument_balise(2, $p);
2269
-		$_flux = $_flux ? $_flux : "''";
2270
-		$p->code = "pipeline( $_pipe , $_flux )";
2271
-		$p->interdire_scripts = false;
2272
-	}
2263
+    $_pipe = interprete_argument_balise(1, $p);
2264
+    if (!$_pipe) {
2265
+        $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'PIPELINE']];
2266
+        erreur_squelette($err_b_s_a, $p);
2267
+    } else {
2268
+        $_flux = interprete_argument_balise(2, $p);
2269
+        $_flux = $_flux ? $_flux : "''";
2270
+        $p->code = "pipeline( $_pipe , $_flux )";
2271
+        $p->interdire_scripts = false;
2272
+    }
2273 2273
 
2274
-	return $p;
2274
+    return $p;
2275 2275
 }
2276 2276
 
2277 2277
 
@@ -2296,10 +2296,10 @@  discard block
 block discarded – undo
2296 2296
  *     Pile complétée par le code à générer
2297 2297
  **/
2298 2298
 function balise_EDIT_dist($p) {
2299
-	$p->code = "''";
2300
-	$p->interdire_scripts = false;
2299
+    $p->code = "''";
2300
+    $p->interdire_scripts = false;
2301 2301
 
2302
-	return $p;
2302
+    return $p;
2303 2303
 }
2304 2304
 
2305 2305
 
@@ -2322,11 +2322,11 @@  discard block
 block discarded – undo
2322 2322
  *     Pile complétée par le code à générer
2323 2323
  **/
2324 2324
 function balise_TOTAL_UNIQUE_dist($p) {
2325
-	$_famille = interprete_argument_balise(1, $p);
2326
-	$_famille = $_famille ? $_famille : "''";
2327
-	$p->code = "unique('', $_famille, true)";
2325
+    $_famille = interprete_argument_balise(1, $p);
2326
+    $_famille = $_famille ? $_famille : "''";
2327
+    $p->code = "unique('', $_famille, true)";
2328 2328
 
2329
-	return $p;
2329
+    return $p;
2330 2330
 }
2331 2331
 
2332 2332
 /**
@@ -2349,19 +2349,19 @@  discard block
 block discarded – undo
2349 2349
  *     Pile complétée par le code à générer
2350 2350
  **/
2351 2351
 function balise_ARRAY_dist($p) {
2352
-	$_code = [];
2353
-	$n = 1;
2354
-	do {
2355
-		$_key = interprete_argument_balise($n++, $p);
2356
-		$_val = interprete_argument_balise($n++, $p);
2357
-		if ($_key and $_val) {
2358
-			$_code[] = "$_key => $_val";
2359
-		}
2360
-	} while ($_key && $_val);
2361
-	$p->code = 'array(' . join(', ', $_code) . ')';
2362
-	$p->interdire_scripts = false;
2352
+    $_code = [];
2353
+    $n = 1;
2354
+    do {
2355
+        $_key = interprete_argument_balise($n++, $p);
2356
+        $_val = interprete_argument_balise($n++, $p);
2357
+        if ($_key and $_val) {
2358
+            $_code[] = "$_key => $_val";
2359
+        }
2360
+    } while ($_key && $_val);
2361
+    $p->code = 'array(' . join(', ', $_code) . ')';
2362
+    $p->interdire_scripts = false;
2363 2363
 
2364
-	return $p;
2364
+    return $p;
2365 2365
 }
2366 2366
 
2367 2367
 /**
@@ -2380,15 +2380,15 @@  discard block
 block discarded – undo
2380 2380
  *     Pile complétée par le code à générer
2381 2381
  */
2382 2382
 function balise_LISTE_dist($p) {
2383
-	$_code = [];
2384
-	$n = 1;
2385
-	while ($_val = interprete_argument_balise($n++, $p)) {
2386
-		$_code[] = $_val;
2387
-	}
2388
-	$p->code = 'array(' . join(', ', $_code) . ')';
2389
-	$p->interdire_scripts = false;
2383
+    $_code = [];
2384
+    $n = 1;
2385
+    while ($_val = interprete_argument_balise($n++, $p)) {
2386
+        $_code[] = $_val;
2387
+    }
2388
+    $p->code = 'array(' . join(', ', $_code) . ')';
2389
+    $p->interdire_scripts = false;
2390 2390
 
2391
-	return $p;
2391
+    return $p;
2392 2392
 }
2393 2393
 
2394 2394
 
@@ -2422,21 +2422,21 @@  discard block
 block discarded – undo
2422 2422
  *     Pile complétée par le code à générer
2423 2423
  **/
2424 2424
 function balise_AUTORISER_dist($p) {
2425
-	$_code = [];
2426
-	$p->descr['session'] = true; // faire un cache par session
2425
+    $_code = [];
2426
+    $p->descr['session'] = true; // faire un cache par session
2427 2427
 
2428
-	$n = 1;
2429
-	while ($_v = interprete_argument_balise($n++, $p)) {
2430
-		$_code[] = $_v;
2431
-	}
2428
+    $n = 1;
2429
+    while ($_v = interprete_argument_balise($n++, $p)) {
2430
+        $_code[] = $_v;
2431
+    }
2432 2432
 
2433
-	$p->code = '((function_exists("autoriser")||include_spip("inc/autoriser"))&&autoriser(' . join(
2434
-		', ',
2435
-		$_code
2436
-	) . ')?" ":"")';
2437
-	$p->interdire_scripts = false;
2433
+    $p->code = '((function_exists("autoriser")||include_spip("inc/autoriser"))&&autoriser(' . join(
2434
+        ', ',
2435
+        $_code
2436
+    ) . ')?" ":"")';
2437
+    $p->interdire_scripts = false;
2438 2438
 
2439
-	return $p;
2439
+    return $p;
2440 2440
 }
2441 2441
 
2442 2442
 
@@ -2460,15 +2460,15 @@  discard block
 block discarded – undo
2460 2460
  *     Pile complétée par le code à générer
2461 2461
  **/
2462 2462
 function balise_PLUGIN_dist($p) {
2463
-	$plugin = interprete_argument_balise(1, $p);
2464
-	$plugin = isset($plugin) ? str_replace('\'', '"', $plugin) : '""';
2465
-	$type_info = interprete_argument_balise(2, $p);
2466
-	$type_info = isset($type_info) ? str_replace('\'', '"', $type_info) : '"est_actif"';
2463
+    $plugin = interprete_argument_balise(1, $p);
2464
+    $plugin = isset($plugin) ? str_replace('\'', '"', $plugin) : '""';
2465
+    $type_info = interprete_argument_balise(2, $p);
2466
+    $type_info = isset($type_info) ? str_replace('\'', '"', $type_info) : '"est_actif"';
2467 2467
 
2468
-	$f = chercher_filtre('info_plugin');
2469
-	$p->code = $f . '(' . $plugin . ', ' . $type_info . ')';
2468
+    $f = chercher_filtre('info_plugin');
2469
+    $p->code = $f . '(' . $plugin . ', ' . $type_info . ')';
2470 2470
 
2471
-	return $p;
2471
+    return $p;
2472 2472
 }
2473 2473
 
2474 2474
 /**
@@ -2489,9 +2489,9 @@  discard block
 block discarded – undo
2489 2489
  *     Pile complétée par le code à générer
2490 2490
  **/
2491 2491
 function balise_AIDER_dist($p) {
2492
-	$_motif = interprete_argument_balise(1, $p);
2493
-	$p->code = "((\$aider=charger_fonction('aide','inc',true))?\$aider($_motif):'')";
2494
-	return $p;
2492
+    $_motif = interprete_argument_balise(1, $p);
2493
+    $p->code = "((\$aider=charger_fonction('aide','inc',true))?\$aider($_motif):'')";
2494
+    return $p;
2495 2495
 }
2496 2496
 
2497 2497
 /**
@@ -2517,16 +2517,16 @@  discard block
 block discarded – undo
2517 2517
  *     Pile complétée par le code à générer
2518 2518
  **/
2519 2519
 function balise_ACTION_FORMULAIRE($p) {
2520
-	if (!$_url = interprete_argument_balise(1, $p)) {
2521
-		$_url = "@\$Pile[0]['action']";
2522
-	}
2523
-	if (!$_form = interprete_argument_balise(2, $p)) {
2524
-		$_form = "@\$Pile[0]['form']";
2525
-	}
2526
-
2527
-	// envoyer le nom du formulaire que l'on traite
2528
-	// transmettre les eventuels args de la balise formulaire
2529
-	$p->code = "	'<span class=\"form-hidden\">' .
2520
+    if (!$_url = interprete_argument_balise(1, $p)) {
2521
+        $_url = "@\$Pile[0]['action']";
2522
+    }
2523
+    if (!$_form = interprete_argument_balise(2, $p)) {
2524
+        $_form = "@\$Pile[0]['form']";
2525
+    }
2526
+
2527
+    // envoyer le nom du formulaire que l'on traite
2528
+    // transmettre les eventuels args de la balise formulaire
2529
+    $p->code = "	'<span class=\"form-hidden\">' .
2530 2530
 	form_hidden($_url) .
2531 2531
 	'<input name=\'formulaire_action\' type=\'hidden\'
2532 2532
 		value=\'' . $_form . '\' />' .
@@ -2535,9 +2535,9 @@  discard block
 block discarded – undo
2535 2535
 	(!empty(\$Pile[0]['_hidden']) ? @\$Pile[0]['_hidden'] : '') .
2536 2536
 	'</span>'";
2537 2537
 
2538
-	$p->interdire_scripts = false;
2538
+    $p->interdire_scripts = false;
2539 2539
 
2540
-	return $p;
2540
+    return $p;
2541 2541
 }
2542 2542
 
2543 2543
 
@@ -2578,25 +2578,25 @@  discard block
 block discarded – undo
2578 2578
  */
2579 2579
 function balise_BOUTON_ACTION_dist($p) {
2580 2580
 
2581
-	$args = [];
2582
-	for ($k = 1; $k <= 6; $k++) {
2583
-		$_a = interprete_argument_balise($k, $p);
2584
-		if (!$_a) {
2585
-			$_a = "''";
2586
-		}
2587
-		$args[] = $_a;
2588
-	}
2589
-	// supprimer les args vides
2590
-	while (end($args) == "''" and count($args) > 2) {
2591
-		array_pop($args);
2592
-	}
2593
-	$args = implode(',', $args);
2581
+    $args = [];
2582
+    for ($k = 1; $k <= 6; $k++) {
2583
+        $_a = interprete_argument_balise($k, $p);
2584
+        if (!$_a) {
2585
+            $_a = "''";
2586
+        }
2587
+        $args[] = $_a;
2588
+    }
2589
+    // supprimer les args vides
2590
+    while (end($args) == "''" and count($args) > 2) {
2591
+        array_pop($args);
2592
+    }
2593
+    $args = implode(',', $args);
2594 2594
 
2595
-	$bouton_action = chercher_filtre('bouton_action');
2596
-	$p->code = "$bouton_action($args)";
2597
-	$p->interdire_scripts = false;
2595
+    $bouton_action = chercher_filtre('bouton_action');
2596
+    $p->code = "$bouton_action($args)";
2597
+    $p->interdire_scripts = false;
2598 2598
 
2599
-	return $p;
2599
+    return $p;
2600 2600
 }
2601 2601
 
2602 2602
 
@@ -2615,10 +2615,10 @@  discard block
 block discarded – undo
2615 2615
  *     Pile complétée par le code à générer
2616 2616
  */
2617 2617
 function balise_SLOGAN_SITE_SPIP_dist($p) {
2618
-	$p->code = "\$GLOBALS['meta']['slogan_site']";
2618
+    $p->code = "\$GLOBALS['meta']['slogan_site']";
2619 2619
 
2620
-	#$p->interdire_scripts = true;
2621
-	return $p;
2620
+    #$p->interdire_scripts = true;
2621
+    return $p;
2622 2622
 }
2623 2623
 
2624 2624
 
@@ -2642,10 +2642,10 @@  discard block
 block discarded – undo
2642 2642
  *     Pile complétée par le code à générer
2643 2643
  */
2644 2644
 function balise_HTML5_dist($p) {
2645
-	$p->code = html5_permis() ? "' '" : "''";
2646
-	$p->interdire_scripts = false;
2645
+    $p->code = html5_permis() ? "' '" : "''";
2646
+    $p->interdire_scripts = false;
2647 2647
 
2648
-	return $p;
2648
+    return $p;
2649 2649
 }
2650 2650
 
2651 2651
 
@@ -2671,61 +2671,61 @@  discard block
 block discarded – undo
2671 2671
  *     Pile complétée par le code à générer
2672 2672
  */
2673 2673
 function balise_TRI_dist($p, $liste = 'true') {
2674
-	$b = index_boucle_mere($p);
2675
-	// s'il n'y a pas de nom de boucle, on ne peut pas trier
2676
-	if ($b === '') {
2677
-		$msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]];
2678
-		erreur_squelette($msg, $p);
2679
-		$p->code = "''";
2674
+    $b = index_boucle_mere($p);
2675
+    // s'il n'y a pas de nom de boucle, on ne peut pas trier
2676
+    if ($b === '') {
2677
+        $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]];
2678
+        erreur_squelette($msg, $p);
2679
+        $p->code = "''";
2680 2680
 
2681
-		return $p;
2682
-	}
2683
-	$boucle = $p->boucles[$b];
2681
+        return $p;
2682
+    }
2683
+    $boucle = $p->boucles[$b];
2684 2684
 
2685
-	// s'il n'y a pas de tri_champ, c'est qu'on se trouve
2686
-	// dans un boucle recursive ou qu'on a oublie le critere {tri}
2687
-	if (!isset($boucle->modificateur['tri_champ'])) {
2688
-		$msg = ['zbug_champ_hors_critere', [
2689
-			'champ' => zbug_presenter_champ($p),
2690
-			'critere' => 'tri'
2691
-		]];
2692
-		erreur_squelette($msg, $p);
2693
-		$p->code = "''";
2685
+    // s'il n'y a pas de tri_champ, c'est qu'on se trouve
2686
+    // dans un boucle recursive ou qu'on a oublie le critere {tri}
2687
+    if (!isset($boucle->modificateur['tri_champ'])) {
2688
+        $msg = ['zbug_champ_hors_critere', [
2689
+            'champ' => zbug_presenter_champ($p),
2690
+            'critere' => 'tri'
2691
+        ]];
2692
+        erreur_squelette($msg, $p);
2693
+        $p->code = "''";
2694 2694
 
2695
-		return $p;
2696
-	}
2695
+        return $p;
2696
+    }
2697 2697
 
2698
-	$_champ = interprete_argument_balise(1, $p);
2699
-	// si pas de champ, renvoyer le critere de tri utilise
2700
-	if (!$_champ) {
2701
-		$p->code = $boucle->modificateur['tri_champ'];
2698
+    $_champ = interprete_argument_balise(1, $p);
2699
+    // si pas de champ, renvoyer le critere de tri utilise
2700
+    if (!$_champ) {
2701
+        $p->code = $boucle->modificateur['tri_champ'];
2702 2702
 
2703
-		return $p;
2704
-	}
2705
-	// forcer la jointure si besoin, et si le champ est statique
2706
-	if (preg_match(",^'([\w.]+)'$,i", $_champ, $m)) {
2707
-		index_pile($b, $m[1], $p->boucles, '', null, true, false);
2708
-	}
2703
+        return $p;
2704
+    }
2705
+    // forcer la jointure si besoin, et si le champ est statique
2706
+    if (preg_match(",^'([\w.]+)'$,i", $_champ, $m)) {
2707
+        index_pile($b, $m[1], $p->boucles, '', null, true, false);
2708
+    }
2709 2709
 
2710
-	$_libelle = interprete_argument_balise(2, $p);
2711
-	$_libelle = $_libelle ? $_libelle : $_champ;
2710
+    $_libelle = interprete_argument_balise(2, $p);
2711
+    $_libelle = $_libelle ? $_libelle : $_champ;
2712 2712
 
2713
-	$_class = interprete_argument_balise(3, $p);
2714
-	// si champ = ">" c'est un lien vers le tri croissant : de gauche a droite ==> 1
2715
-	// si champ = "<" c'est un lien vers le tri decroissant : (sens inverse) == -1
2716
-	$_issens = "in_array($_champ,array('>','<'))";
2717
-	$_sens = "(strpos('< >',$_champ)-1)";
2713
+    $_class = interprete_argument_balise(3, $p);
2714
+    // si champ = ">" c'est un lien vers le tri croissant : de gauche a droite ==> 1
2715
+    // si champ = "<" c'est un lien vers le tri decroissant : (sens inverse) == -1
2716
+    $_issens = "in_array($_champ,array('>','<'))";
2717
+    $_sens = "(strpos('< >',$_champ)-1)";
2718 2718
 
2719
-	$_variable = "((\$s=$_issens)?'sens':'tri')." . $boucle->modificateur['tri_nom'];
2720
-	$_url = "parametre_url(self(),$_variable,\$s?$_sens:$_champ)";
2721
-	$_url = "parametre_url($_url,'var_memotri',strncmp(" . $boucle->modificateur['tri_nom'] . ",'session',7)==0?$_variable:'')";
2722
-	$_on = '$s?(' . $boucle->modificateur['tri_sens'] . "==$_sens" . '):(' . $boucle->modificateur['tri_champ'] . "==$_champ)";
2719
+    $_variable = "((\$s=$_issens)?'sens':'tri')." . $boucle->modificateur['tri_nom'];
2720
+    $_url = "parametre_url(self(),$_variable,\$s?$_sens:$_champ)";
2721
+    $_url = "parametre_url($_url,'var_memotri',strncmp(" . $boucle->modificateur['tri_nom'] . ",'session',7)==0?$_variable:'')";
2722
+    $_on = '$s?(' . $boucle->modificateur['tri_sens'] . "==$_sens" . '):(' . $boucle->modificateur['tri_champ'] . "==$_champ)";
2723 2723
 
2724
-	$p->code = "lien_ou_expose($_url,$_libelle,$_on" . ($_class ? ",$_class" : '') . ')';
2725
-	//$p->code = "''";
2726
-	$p->interdire_scripts = false;
2724
+    $p->code = "lien_ou_expose($_url,$_libelle,$_on" . ($_class ? ",$_class" : '') . ')';
2725
+    //$p->code = "''";
2726
+    $p->interdire_scripts = false;
2727 2727
 
2728
-	return $p;
2728
+    return $p;
2729 2729
 }
2730 2730
 
2731 2731
 
@@ -2746,22 +2746,22 @@  discard block
 block discarded – undo
2746 2746
  *     Pile complétée par le code à générer
2747 2747
  */
2748 2748
 function balise_SAUTER_dist($p) {
2749
-	$id_boucle = $p->id_boucle;
2749
+    $id_boucle = $p->id_boucle;
2750 2750
 
2751
-	if (empty($p->boucles[$id_boucle])) {
2752
-		$msg = ['zbug_champ_hors_boucle', ['champ' => '#SAUTER']];
2753
-		erreur_squelette($msg, $p);
2754
-	} else {
2755
-		$boucle = $p->boucles[$id_boucle];
2756
-		$_saut = interprete_argument_balise(1, $p);
2757
-		$_compteur = "\$Numrows['$id_boucle']['compteur_boucle']";
2758
-		$_total = "\$Numrows['$id_boucle']['total']";
2751
+    if (empty($p->boucles[$id_boucle])) {
2752
+        $msg = ['zbug_champ_hors_boucle', ['champ' => '#SAUTER']];
2753
+        erreur_squelette($msg, $p);
2754
+    } else {
2755
+        $boucle = $p->boucles[$id_boucle];
2756
+        $_saut = interprete_argument_balise(1, $p);
2757
+        $_compteur = "\$Numrows['$id_boucle']['compteur_boucle']";
2758
+        $_total = "\$Numrows['$id_boucle']['total']";
2759 2759
 
2760
-		$p->code = "vide($_compteur=\$iter->skip($_saut,$_total))";
2761
-	}
2762
-	$p->interdire_scripts = false;
2760
+        $p->code = "vide($_compteur=\$iter->skip($_saut,$_total))";
2761
+    }
2762
+    $p->interdire_scripts = false;
2763 2763
 
2764
-	return $p;
2764
+    return $p;
2765 2765
 }
2766 2766
 
2767 2767
 
@@ -2783,22 +2783,22 @@  discard block
 block discarded – undo
2783 2783
  *     Pile complétée par le code à générer
2784 2784
  */
2785 2785
 function balise_PUBLIE_dist($p) {
2786
-	if (!$_type = interprete_argument_balise(1, $p)) {
2787
-		$_type = _q($p->type_requete);
2788
-		$_id = champ_sql($p->boucles[$p->id_boucle]->primary, $p);
2789
-	} else {
2790
-		$_id = interprete_argument_balise(2, $p);
2791
-	}
2786
+    if (!$_type = interprete_argument_balise(1, $p)) {
2787
+        $_type = _q($p->type_requete);
2788
+        $_id = champ_sql($p->boucles[$p->id_boucle]->primary, $p);
2789
+    } else {
2790
+        $_id = interprete_argument_balise(2, $p);
2791
+    }
2792 2792
 
2793
-	$connect = '';
2794
-	if (isset($p->boucles[$p->id_boucle])) {
2795
-		$connect = $p->boucles[$p->id_boucle]->sql_serveur;
2796
-	}
2793
+    $connect = '';
2794
+    if (isset($p->boucles[$p->id_boucle])) {
2795
+        $connect = $p->boucles[$p->id_boucle]->sql_serveur;
2796
+    }
2797 2797
 
2798
-	$p->code = '(objet_test_si_publie(' . $_type . ',intval(' . $_id . '),' . _q($connect) . ")?' ':'')";
2799
-	$p->interdire_scripts = false;
2798
+    $p->code = '(objet_test_si_publie(' . $_type . ',intval(' . $_id . '),' . _q($connect) . ")?' ':'')";
2799
+    $p->interdire_scripts = false;
2800 2800
 
2801
-	return $p;
2801
+    return $p;
2802 2802
 }
2803 2803
 
2804 2804
 /**
@@ -2827,12 +2827,12 @@  discard block
 block discarded – undo
2827 2827
  *     Pile complétée par le code à générer
2828 2828
  */
2829 2829
 function balise_PRODUIRE_dist($p) {
2830
-	$balise_inclure = charger_fonction('INCLURE', 'balise');
2831
-	$p = $balise_inclure($p);
2830
+    $balise_inclure = charger_fonction('INCLURE', 'balise');
2831
+    $p = $balise_inclure($p);
2832 2832
 
2833
-	$p->code = str_replace('recuperer_fond(', 'produire_fond_statique(', $p->code);
2833
+    $p->code = str_replace('recuperer_fond(', 'produire_fond_statique(', $p->code);
2834 2834
 
2835
-	return $p;
2835
+    return $p;
2836 2836
 }
2837 2837
 
2838 2838
 /**
@@ -2851,13 +2851,13 @@  discard block
 block discarded – undo
2851 2851
  *     Pile complétée par le code à générer
2852 2852
  */
2853 2853
 function balise_LARGEUR_ECRAN_dist($p) {
2854
-	$_class = interprete_argument_balise(1, $p);
2855
-	if (!$_class) {
2856
-		$_class = 'null';
2857
-	}
2858
-	$p->code = "(is_string($_class)?vide(\$GLOBALS['largeur_ecran']=$_class):(isset(\$GLOBALS['largeur_ecran'])?\$GLOBALS['largeur_ecran']:''))";
2854
+    $_class = interprete_argument_balise(1, $p);
2855
+    if (!$_class) {
2856
+        $_class = 'null';
2857
+    }
2858
+    $p->code = "(is_string($_class)?vide(\$GLOBALS['largeur_ecran']=$_class):(isset(\$GLOBALS['largeur_ecran'])?\$GLOBALS['largeur_ecran']:''))";
2859 2859
 
2860
-	return $p;
2860
+    return $p;
2861 2861
 }
2862 2862
 
2863 2863
 
@@ -2873,14 +2873,14 @@  discard block
 block discarded – undo
2873 2873
  *     Pile complétée par le code à générer
2874 2874
  **/
2875 2875
 function balise_CONST_dist($p) {
2876
-	$_const = interprete_argument_balise(1, $p);
2877
-	if (!strlen($_const)) {
2878
-		$p->code = "''";
2879
-	}
2880
-	else {
2881
-		$p->code = "(defined($_const)?constant($_const):'')";
2882
-	}
2883
-	$p->interdire_scripts = false;
2884
-
2885
-	return $p;
2876
+    $_const = interprete_argument_balise(1, $p);
2877
+    if (!strlen($_const)) {
2878
+        $p->code = "''";
2879
+    }
2880
+    else {
2881
+        $p->code = "(defined($_const)?constant($_const):'')";
2882
+    }
2883
+    $p->interdire_scripts = false;
2884
+
2885
+    return $p;
2886 2886
 }
Please login to merge, or discard this patch.
ecrire/public/composer.php 1 patch
Indentation   +757 added lines, -757 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  **/
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 
24 24
 include_spip('inc/texte');
@@ -43,233 +43,233 @@  discard block
 block discarded – undo
43 43
 // https://code.spip.net/@public_composer_dist
44 44
 function public_composer_dist($squelette, $mime_type, $gram, $source, $connect = '') {
45 45
 
46
-	$nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect);
47
-
48
-	//  si deja en memoire (INCLURE  a repetition) c'est bon.
49
-	if (function_exists($nom)) {
50
-		return $nom;
51
-	}
52
-
53
-	if (defined('_VAR_MODE') and _VAR_MODE == 'debug') {
54
-		$GLOBALS['debug_objets']['courant'] = $nom;
55
-	}
56
-
57
-	$phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php';
58
-
59
-	// si squelette est deja compile et perenne, le charger
60
-	if (!squelette_obsolete($phpfile, $source)) {
61
-		include_once $phpfile;
62
-		#if (!squelette_obsolete($phpfile, $source)
63
-		#  AND lire_fichier ($phpfile, $skel_code,
64
-		#  array('critique' => 'oui', 'phpcheck' => 'oui'))){
65
-		## eval('?'.'>'.$skel_code);
66
-		#	 spip_log($skel_code, 'comp')
67
-		#}
68
-	}
69
-
70
-	if (file_exists($lib = $squelette . '_fonctions' . '.php')) {
71
-		include_once $lib;
72
-	}
73
-
74
-	// tester si le eval ci-dessus a mis le squelette en memoire
75
-
76
-	if (function_exists($nom)) {
77
-		return $nom;
78
-	}
79
-
80
-	// charger le source, si possible, et compiler
81
-	$skel_code = '';
82
-	if (lire_fichier($source, $skel)) {
83
-		$compiler = charger_fonction('compiler', 'public');
84
-		$skel_code = $compiler($skel, $nom, $gram, $source, $connect);
85
-	}
86
-
87
-	// Ne plus rien faire si le compilateur n'a pas pu operer.
88
-	if (!$skel_code) {
89
-		return false;
90
-	}
91
-
92
-	foreach ($skel_code as $id => $boucle) {
93
-		$f = $boucle->return;
94
-		try {
95
-			eval("return true; $f ;");
96
-		} catch (\ParseError $e) {
97
-			// Code syntaxiquement faux (critere etc mal programme')
98
-			$msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage();
99
-			erreur_squelette($msg, $boucle);
100
-			// continuer pour trouver d'autres fautes eventuelles
101
-			// mais prevenir que c'est mort
102
-			$nom = '';
103
-		}
104
-
105
-		// Contexte de compil inutile a present
106
-		// (mais la derniere valeur de $boucle est utilisee ci-dessous)
107
-		$skel_code[$id] = $f;
108
-	}
109
-
110
-	$code = '';
111
-	if ($nom) {
112
-		// Si le code est bon, concatener et mettre en cache
113
-		if (function_exists($nom)) {
114
-			$code = squelette_traduit($skel, $source, $phpfile, $skel_code);
115
-		} else {
116
-			// code semantiquement faux: bug du compilateur
117
-			// $boucle est en fait ici la fct principale du squelette
118
-			$msg = _T('zbug_erreur_compilation');
119
-			erreur_squelette($msg, $boucle);
120
-			$nom = '';
121
-		}
122
-	}
123
-
124
-	if (defined('_VAR_MODE') and _VAR_MODE == 'debug') {
125
-		// Tracer ce qui vient d'etre compile
126
-		$GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code;
127
-
128
-		// si c'est ce que demande le debusqueur, lui passer la main
129
-		if (
130
-			$GLOBALS['debug_objets']['sourcefile']
131
-			and (_request('var_mode_objet') == $nom)
132
-			and (_request('var_mode_affiche') == 'code')
133
-		) {
134
-			erreur_squelette();
135
-		}
136
-	}
137
-
138
-	return $nom ? $nom : false;
46
+    $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect);
47
+
48
+    //  si deja en memoire (INCLURE  a repetition) c'est bon.
49
+    if (function_exists($nom)) {
50
+        return $nom;
51
+    }
52
+
53
+    if (defined('_VAR_MODE') and _VAR_MODE == 'debug') {
54
+        $GLOBALS['debug_objets']['courant'] = $nom;
55
+    }
56
+
57
+    $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php';
58
+
59
+    // si squelette est deja compile et perenne, le charger
60
+    if (!squelette_obsolete($phpfile, $source)) {
61
+        include_once $phpfile;
62
+        #if (!squelette_obsolete($phpfile, $source)
63
+        #  AND lire_fichier ($phpfile, $skel_code,
64
+        #  array('critique' => 'oui', 'phpcheck' => 'oui'))){
65
+        ## eval('?'.'>'.$skel_code);
66
+        #	 spip_log($skel_code, 'comp')
67
+        #}
68
+    }
69
+
70
+    if (file_exists($lib = $squelette . '_fonctions' . '.php')) {
71
+        include_once $lib;
72
+    }
73
+
74
+    // tester si le eval ci-dessus a mis le squelette en memoire
75
+
76
+    if (function_exists($nom)) {
77
+        return $nom;
78
+    }
79
+
80
+    // charger le source, si possible, et compiler
81
+    $skel_code = '';
82
+    if (lire_fichier($source, $skel)) {
83
+        $compiler = charger_fonction('compiler', 'public');
84
+        $skel_code = $compiler($skel, $nom, $gram, $source, $connect);
85
+    }
86
+
87
+    // Ne plus rien faire si le compilateur n'a pas pu operer.
88
+    if (!$skel_code) {
89
+        return false;
90
+    }
91
+
92
+    foreach ($skel_code as $id => $boucle) {
93
+        $f = $boucle->return;
94
+        try {
95
+            eval("return true; $f ;");
96
+        } catch (\ParseError $e) {
97
+            // Code syntaxiquement faux (critere etc mal programme')
98
+            $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage();
99
+            erreur_squelette($msg, $boucle);
100
+            // continuer pour trouver d'autres fautes eventuelles
101
+            // mais prevenir que c'est mort
102
+            $nom = '';
103
+        }
104
+
105
+        // Contexte de compil inutile a present
106
+        // (mais la derniere valeur de $boucle est utilisee ci-dessous)
107
+        $skel_code[$id] = $f;
108
+    }
109
+
110
+    $code = '';
111
+    if ($nom) {
112
+        // Si le code est bon, concatener et mettre en cache
113
+        if (function_exists($nom)) {
114
+            $code = squelette_traduit($skel, $source, $phpfile, $skel_code);
115
+        } else {
116
+            // code semantiquement faux: bug du compilateur
117
+            // $boucle est en fait ici la fct principale du squelette
118
+            $msg = _T('zbug_erreur_compilation');
119
+            erreur_squelette($msg, $boucle);
120
+            $nom = '';
121
+        }
122
+    }
123
+
124
+    if (defined('_VAR_MODE') and _VAR_MODE == 'debug') {
125
+        // Tracer ce qui vient d'etre compile
126
+        $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code;
127
+
128
+        // si c'est ce que demande le debusqueur, lui passer la main
129
+        if (
130
+            $GLOBALS['debug_objets']['sourcefile']
131
+            and (_request('var_mode_objet') == $nom)
132
+            and (_request('var_mode_affiche') == 'code')
133
+        ) {
134
+            erreur_squelette();
135
+        }
136
+    }
137
+
138
+    return $nom ? $nom : false;
139 139
 }
140 140
 
141 141
 function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) {
142 142
 
143
-	// Le dernier index est '' (fonction principale)
144
-	$noms = substr(join(', ', array_keys($boucles)), 0, -2);
145
-	if (CODE_COMMENTE) {
146
-		$code = "
143
+    // Le dernier index est '' (fonction principale)
144
+    $noms = substr(join(', ', array_keys($boucles)), 0, -2);
145
+    if (CODE_COMMENTE) {
146
+        $code = "
147 147
 /*
148 148
  * Squelette : $sourcefile
149 149
  * Date :      " . gmdate('D, d M Y H:i:s', @filemtime($sourcefile)) . ' GMT
150 150
  * Compile :   ' . gmdate('D, d M Y H:i:s', time()) . ' GMT
151 151
  * ' . (!$boucles ? 'Pas de boucle' : ('Boucles :   ' . $noms)) . '
152 152
  */ ';
153
-	}
153
+    }
154 154
 
155
-	$code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>';
156
-	if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) {
157
-		ecrire_fichier($phpfile, $code);
158
-	}
155
+    $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>';
156
+    if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) {
157
+        ecrire_fichier($phpfile, $code);
158
+    }
159 159
 
160
-	return $code;
160
+    return $code;
161 161
 }
162 162
 
163 163
 // Le squelette compile est-il trop vieux ?
164 164
 // https://code.spip.net/@squelette_obsolete
165 165
 function squelette_obsolete($skel, $squelette) {
166
-	static $date_change = null;
167
-	// ne verifier la date de mes_fonctions et mes_options qu'une seule fois
168
-	// par hit
169
-	if (is_null($date_change)) {
170
-		if (@file_exists($fonc = 'mes_fonctions.php')) {
171
-			$date_change = @filemtime($fonc);
172
-		} # compatibilite
173
-		if (defined('_FILE_OPTIONS')) {
174
-			$date_change = max($date_change, @filemtime(_FILE_OPTIONS));
175
-		}
176
-	}
177
-
178
-	return (
179
-		(defined('_VAR_MODE') and in_array(_VAR_MODE, ['recalcul', 'preview', 'debug']))
180
-		or !@file_exists($skel)
181
-		or ((@file_exists($squelette) ? @filemtime($squelette) : 0)
182
-			> ($date = @filemtime($skel)))
183
-		or ($date_change > $date)
184
-	);
166
+    static $date_change = null;
167
+    // ne verifier la date de mes_fonctions et mes_options qu'une seule fois
168
+    // par hit
169
+    if (is_null($date_change)) {
170
+        if (@file_exists($fonc = 'mes_fonctions.php')) {
171
+            $date_change = @filemtime($fonc);
172
+        } # compatibilite
173
+        if (defined('_FILE_OPTIONS')) {
174
+            $date_change = max($date_change, @filemtime(_FILE_OPTIONS));
175
+        }
176
+    }
177
+
178
+    return (
179
+        (defined('_VAR_MODE') and in_array(_VAR_MODE, ['recalcul', 'preview', 'debug']))
180
+        or !@file_exists($skel)
181
+        or ((@file_exists($squelette) ? @filemtime($squelette) : 0)
182
+            > ($date = @filemtime($skel)))
183
+        or ($date_change > $date)
184
+    );
185 185
 }
186 186
 
187 187
 // Activer l'invalideur de session
188 188
 // https://code.spip.net/@invalideur_session
189 189
 function invalideur_session(&$Cache, $code = null) {
190
-	$Cache['session'] = spip_session();
190
+    $Cache['session'] = spip_session();
191 191
 
192
-	return $code;
192
+    return $code;
193 193
 }
194 194
 
195 195
 
196 196
 // https://code.spip.net/@analyse_resultat_skel
197 197
 function analyse_resultat_skel($nom, $cache, $corps, $source = '') {
198
-	static $filtres = [];
199
-	$headers = [];
200
-
201
-	// Recupere les < ?php header('Xx: y'); ? > pour $page['headers']
202
-	// note: on essaie d'attrapper aussi certains de ces entetes codes
203
-	// "a la main" dans les squelettes, mais evidemment sans exhaustivite
204
-	if (
205
-		stripos($corps, 'header') !== false
206
-		and preg_match_all(
207
-			'/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims',
208
-			$corps,
209
-			$regs,
210
-			PREG_SET_ORDER
211
-		)
212
-	) {
213
-		foreach ($regs as $r) {
214
-			$corps = str_replace($r[0], '', $corps);
215
-			# $j = Content-Type, et pas content-TYPE.
216
-			$j = join('-', array_map('ucwords', explode('-', strtolower($r[2]))));
217
-
218
-			if ($j == 'X-Spip-Filtre' and isset($headers[$j])) {
219
-				$headers[$j] .= '|' . $r[3];
220
-			} else {
221
-				$headers[$j] = $r[3];
222
-			}
223
-		}
224
-	}
225
-	// S'agit-il d'un resultat constant ou contenant du code php
226
-	$process_ins = (
227
-		strpos($corps, '<' . '?') === false
228
-		or
229
-		(strpos($corps, '<' . '?xml') !== false and
230
-			strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false)
231
-	)
232
-		? 'html'
233
-		: 'php';
234
-
235
-	$skel = [
236
-		'squelette' => $nom,
237
-		'source' => $source,
238
-		'process_ins' => $process_ins,
239
-		'invalideurs' => $cache,
240
-		'entetes' => $headers,
241
-		'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0
242
-	];
243
-
244
-	// traiter #FILTRE{} et filtres
245
-	if (!isset($filtres[$nom])) {
246
-		$filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]);
247
-	}
248
-	$filtres_headers = [];
249
-	if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) {
250
-		$filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre']));
251
-		unset($headers['X-Spip-Filtre']);
252
-	}
253
-	if (count($filtres[$nom]) or count($filtres_headers)) {
254
-		include_spip('public/sandbox');
255
-		$corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]);
256
-
257
-		if ($process_ins == 'html') {
258
-			$skel['process_ins'] = (
259
-				strpos($corps, '<' . '?') === false
260
-				or
261
-				(strpos($corps, '<' . '?xml') !== false and
262
-					strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false)
263
-			)
264
-				? 'html'
265
-				: 'php';
266
-		}
267
-	}
268
-
269
-	$skel['entetes'] = $headers;
270
-	$skel['texte'] = $corps;
271
-
272
-	return $skel;
198
+    static $filtres = [];
199
+    $headers = [];
200
+
201
+    // Recupere les < ?php header('Xx: y'); ? > pour $page['headers']
202
+    // note: on essaie d'attrapper aussi certains de ces entetes codes
203
+    // "a la main" dans les squelettes, mais evidemment sans exhaustivite
204
+    if (
205
+        stripos($corps, 'header') !== false
206
+        and preg_match_all(
207
+            '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims',
208
+            $corps,
209
+            $regs,
210
+            PREG_SET_ORDER
211
+        )
212
+    ) {
213
+        foreach ($regs as $r) {
214
+            $corps = str_replace($r[0], '', $corps);
215
+            # $j = Content-Type, et pas content-TYPE.
216
+            $j = join('-', array_map('ucwords', explode('-', strtolower($r[2]))));
217
+
218
+            if ($j == 'X-Spip-Filtre' and isset($headers[$j])) {
219
+                $headers[$j] .= '|' . $r[3];
220
+            } else {
221
+                $headers[$j] = $r[3];
222
+            }
223
+        }
224
+    }
225
+    // S'agit-il d'un resultat constant ou contenant du code php
226
+    $process_ins = (
227
+        strpos($corps, '<' . '?') === false
228
+        or
229
+        (strpos($corps, '<' . '?xml') !== false and
230
+            strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false)
231
+    )
232
+        ? 'html'
233
+        : 'php';
234
+
235
+    $skel = [
236
+        'squelette' => $nom,
237
+        'source' => $source,
238
+        'process_ins' => $process_ins,
239
+        'invalideurs' => $cache,
240
+        'entetes' => $headers,
241
+        'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0
242
+    ];
243
+
244
+    // traiter #FILTRE{} et filtres
245
+    if (!isset($filtres[$nom])) {
246
+        $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]);
247
+    }
248
+    $filtres_headers = [];
249
+    if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) {
250
+        $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre']));
251
+        unset($headers['X-Spip-Filtre']);
252
+    }
253
+    if (count($filtres[$nom]) or count($filtres_headers)) {
254
+        include_spip('public/sandbox');
255
+        $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]);
256
+
257
+        if ($process_ins == 'html') {
258
+            $skel['process_ins'] = (
259
+                strpos($corps, '<' . '?') === false
260
+                or
261
+                (strpos($corps, '<' . '?xml') !== false and
262
+                    strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false)
263
+            )
264
+                ? 'html'
265
+                : 'php';
266
+        }
267
+    }
268
+
269
+    $skel['entetes'] = $headers;
270
+    $skel['texte'] = $corps;
271
+
272
+    return $skel;
273 273
 }
274 274
 
275 275
 //
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 inserer_balise_dynamique(balise_%s_dyn(%s), array(%s));
284 284
 if ($lang_select) lang_select();
285 285
 ?'
286
-	. '>');
286
+    . '>');
287 287
 
288 288
 /**
289 289
  * Synthétise une balise dynamique : crée l'appel à l'inclusion
@@ -303,35 +303,35 @@  discard block
 block discarded – undo
303 303
  *     Code PHP pour inclure le squelette de la balise dynamique
304 304
  **/
305 305
 function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) {
306
-	if (
307
-		strncmp($file, '/', 1) !== 0
308
-		// pas de lien symbolique sous Windows
309
-		and !(stristr(PHP_OS, 'WIN') and strpos($file, ':') !== false)
310
-	) {
311
-		$file = './" . _DIR_RACINE . "' . $file;
312
-	}
313
-
314
-	$lang = $context_compil[4];
315
-	if (preg_match(',\W,', $lang)) {
316
-		$lang = '';
317
-	}
318
-
319
-	$args = array_map('argumenter_squelette', $args);
320
-	if (!empty($context_compil['appel_php_depuis_modele'])) {
321
-		$args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')';
322
-	}
323
-	$args = join(', ', $args);
324
-
325
-	$r = sprintf(
326
-		CODE_INCLURE_BALISE,
327
-		$file,
328
-		$lang,
329
-		$nom,
330
-		$args,
331
-		join(', ', array_map('_q', $context_compil))
332
-	);
333
-
334
-	return $r;
306
+    if (
307
+        strncmp($file, '/', 1) !== 0
308
+        // pas de lien symbolique sous Windows
309
+        and !(stristr(PHP_OS, 'WIN') and strpos($file, ':') !== false)
310
+    ) {
311
+        $file = './" . _DIR_RACINE . "' . $file;
312
+    }
313
+
314
+    $lang = $context_compil[4];
315
+    if (preg_match(',\W,', $lang)) {
316
+        $lang = '';
317
+    }
318
+
319
+    $args = array_map('argumenter_squelette', $args);
320
+    if (!empty($context_compil['appel_php_depuis_modele'])) {
321
+        $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')';
322
+    }
323
+    $args = join(', ', $args);
324
+
325
+    $r = sprintf(
326
+        CODE_INCLURE_BALISE,
327
+        $file,
328
+        $lang,
329
+        $nom,
330
+        $args,
331
+        join(', ', array_map('_q', $context_compil))
332
+    );
333
+
334
+    return $r;
335 335
 }
336 336
 
337 337
 /**
@@ -349,18 +349,18 @@  discard block
 block discarded – undo
349 349
  **/
350 350
 function argumenter_squelette($v) {
351 351
 
352
-	if (is_object($v)) {
353
-		return var_export($v, true);
354
-	} elseif (!is_array($v)) {
355
-		return "'" . texte_script($v) . "'";
356
-	} else {
357
-		$out = [];
358
-		foreach ($v as $k => $val) {
359
-			$out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val);
360
-		}
361
-
362
-		return 'array(' . join(', ', $out) . ')';
363
-	}
352
+    if (is_object($v)) {
353
+        return var_export($v, true);
354
+    } elseif (!is_array($v)) {
355
+        return "'" . texte_script($v) . "'";
356
+    } else {
357
+        $out = [];
358
+        foreach ($v as $k => $val) {
359
+            $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val);
360
+        }
361
+
362
+        return 'array(' . join(', ', $out) . ')';
363
+    }
364 364
 }
365 365
 
366 366
 
@@ -391,87 +391,87 @@  discard block
 block discarded – undo
391 391
  *     Code PHP d'exécutant l'inclusion du squelette (ou texte) de la balise dynamique
392 392
  **/
393 393
 function executer_balise_dynamique($nom, $args, $context_compil) {
394
-	/** @var string Nom de la balise à charger (balise demandée ou balise générique) */
395
-	$nom_balise = $nom;
396
-	/** @var string Nom de la balise générique (si utilisée) */
397
-	$nom_balise_generique = '';
398
-
399
-	$appel_php_depuis_modele = false;
400
-	if (
401
-		is_array($context_compil)
402
-		and !is_numeric($context_compil[3])
403
-		and empty($context_compil[0])
404
-		and empty($context_compil[1])
405
-		and empty($context_compil[2])
406
-		and empty($context_compil[3])
407
-	) {
408
-		$appel_php_depuis_modele = true;
409
-	}
410
-
411
-	if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) {
412
-		// Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article')
413
-		if ($balise_generique = chercher_balise_generique($nom)) {
414
-			// injecter en premier arg le nom de la balise
415
-			array_unshift($args, $nom);
416
-			$nom_balise_generique = $balise_generique['nom_generique'];
417
-			$fonction_balise = $balise_generique['fonction_generique'];
418
-			$nom_balise = $nom_balise_generique;
419
-		}
420
-		unset($balise_generique);
421
-	}
422
-
423
-	if (!$fonction_balise) {
424
-		$msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]];
425
-		erreur_squelette($msg, $context_compil);
426
-
427
-		return '';
428
-	}
429
-
430
-	// retrouver le fichier qui a déclaré la fonction
431
-	// même si la fonction dynamique est déclarée dans un fichier de fonctions.
432
-	// Attention sous windows, getFileName() retourne un antislash.
433
-	$reflector = new ReflectionFunction($fonction_balise);
434
-	$file = str_replace('\\', '/', $reflector->getFileName());
435
-	if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) {
436
-		$file = substr($file, strlen(_ROOT_RACINE));
437
-	}
438
-
439
-	// Y a-t-il une fonction de traitement des arguments ?
440
-	$f = 'balise_' . $nom_balise . '_stat';
441
-
442
-	$r = !function_exists($f) ? $args : $f($args, $context_compil);
443
-
444
-	if (!is_array($r)) {
445
-		return $r;
446
-	}
447
-
448
-	// verifier que la fonction dyn est la,
449
-	// sinon se replier sur la generique si elle existe
450
-	if (!function_exists('balise_' . $nom_balise . '_dyn')) {
451
-		if (
452
-			$balise_generique = chercher_balise_generique($nom)
453
-			and $nom_balise_generique = $balise_generique['nom_generique']
454
-			and $file = include_spip('balise/' . strtolower($nom_balise_generique))
455
-			and function_exists('balise_' . $nom_balise_generique . '_dyn')
456
-		) {
457
-			// et lui injecter en premier arg le nom de la balise
458
-			array_unshift($r, $nom);
459
-			$nom_balise = $nom_balise_generique;
460
-			if (!_DIR_RESTREINT) {
461
-				$file = _DIR_RESTREINT_ABS . $file;
462
-			}
463
-		} else {
464
-			$msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]];
465
-			erreur_squelette($msg, $context_compil);
466
-
467
-			return '';
468
-		}
469
-	}
470
-
471
-	if ($appel_php_depuis_modele) {
472
-		$context_compil['appel_php_depuis_modele'] = true;
473
-	}
474
-	return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil);
394
+    /** @var string Nom de la balise à charger (balise demandée ou balise générique) */
395
+    $nom_balise = $nom;
396
+    /** @var string Nom de la balise générique (si utilisée) */
397
+    $nom_balise_generique = '';
398
+
399
+    $appel_php_depuis_modele = false;
400
+    if (
401
+        is_array($context_compil)
402
+        and !is_numeric($context_compil[3])
403
+        and empty($context_compil[0])
404
+        and empty($context_compil[1])
405
+        and empty($context_compil[2])
406
+        and empty($context_compil[3])
407
+    ) {
408
+        $appel_php_depuis_modele = true;
409
+    }
410
+
411
+    if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) {
412
+        // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article')
413
+        if ($balise_generique = chercher_balise_generique($nom)) {
414
+            // injecter en premier arg le nom de la balise
415
+            array_unshift($args, $nom);
416
+            $nom_balise_generique = $balise_generique['nom_generique'];
417
+            $fonction_balise = $balise_generique['fonction_generique'];
418
+            $nom_balise = $nom_balise_generique;
419
+        }
420
+        unset($balise_generique);
421
+    }
422
+
423
+    if (!$fonction_balise) {
424
+        $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]];
425
+        erreur_squelette($msg, $context_compil);
426
+
427
+        return '';
428
+    }
429
+
430
+    // retrouver le fichier qui a déclaré la fonction
431
+    // même si la fonction dynamique est déclarée dans un fichier de fonctions.
432
+    // Attention sous windows, getFileName() retourne un antislash.
433
+    $reflector = new ReflectionFunction($fonction_balise);
434
+    $file = str_replace('\\', '/', $reflector->getFileName());
435
+    if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) {
436
+        $file = substr($file, strlen(_ROOT_RACINE));
437
+    }
438
+
439
+    // Y a-t-il une fonction de traitement des arguments ?
440
+    $f = 'balise_' . $nom_balise . '_stat';
441
+
442
+    $r = !function_exists($f) ? $args : $f($args, $context_compil);
443
+
444
+    if (!is_array($r)) {
445
+        return $r;
446
+    }
447
+
448
+    // verifier que la fonction dyn est la,
449
+    // sinon se replier sur la generique si elle existe
450
+    if (!function_exists('balise_' . $nom_balise . '_dyn')) {
451
+        if (
452
+            $balise_generique = chercher_balise_generique($nom)
453
+            and $nom_balise_generique = $balise_generique['nom_generique']
454
+            and $file = include_spip('balise/' . strtolower($nom_balise_generique))
455
+            and function_exists('balise_' . $nom_balise_generique . '_dyn')
456
+        ) {
457
+            // et lui injecter en premier arg le nom de la balise
458
+            array_unshift($r, $nom);
459
+            $nom_balise = $nom_balise_generique;
460
+            if (!_DIR_RESTREINT) {
461
+                $file = _DIR_RESTREINT_ABS . $file;
462
+            }
463
+        } else {
464
+            $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]];
465
+            erreur_squelette($msg, $context_compil);
466
+
467
+            return '';
468
+        }
469
+    }
470
+
471
+    if ($appel_php_depuis_modele) {
472
+        $context_compil['appel_php_depuis_modele'] = true;
473
+    }
474
+    return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil);
475 475
 }
476 476
 
477 477
 /**
@@ -486,23 +486,23 @@  discard block
 block discarded – undo
486 486
  * @return array|null
487 487
  */
488 488
 function chercher_balise_generique($nom) {
489
-	if (false === strpos($nom, '_')) {
490
-		return null;
491
-	}
492
-	$nom_generique = $nom;
493
-	while (false !== ($p = strrpos($nom_generique, '_'))) {
494
-		$nom_generique = substr($nom_generique, 0, $p + 1);
495
-		$fonction_generique = charger_fonction($nom_generique, 'balise', true);
496
-		if ($fonction_generique) {
497
-			return [
498
-				'nom' => $nom,
499
-				'nom_generique' => $nom_generique,
500
-				'fonction_generique' => $fonction_generique,
501
-			];
502
-		}
503
-		$nom_generique = substr($nom_generique, 0, -1);
504
-	}
505
-	return null;
489
+    if (false === strpos($nom, '_')) {
490
+        return null;
491
+    }
492
+    $nom_generique = $nom;
493
+    while (false !== ($p = strrpos($nom_generique, '_'))) {
494
+        $nom_generique = substr($nom_generique, 0, $p + 1);
495
+        $fonction_generique = charger_fonction($nom_generique, 'balise', true);
496
+        if ($fonction_generique) {
497
+            return [
498
+                'nom' => $nom,
499
+                'nom_generique' => $nom_generique,
500
+                'fonction_generique' => $fonction_generique,
501
+            ];
502
+        }
503
+        $nom_generique = substr($nom_generique, 0, -1);
504
+    }
505
+    return null;
506 506
 }
507 507
 
508 508
 
@@ -526,29 +526,29 @@  discard block
 block discarded – undo
526 526
  * @return null;
527 527
  **/
528 528
 function lang_select_public($lang, $lang_select, $titre = null) {
529
-	// Cas 1. forcer_lang = true et pas de critere {lang_select}
530
-	if (
531
-		isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang']
532
-		and $lang_select !== 'oui'
533
-	) {
534
-		$lang = $GLOBALS['spip_lang'];
535
-	} // Cas 2. l'objet n'a pas de langue definie (ou definie a '')
536
-	elseif (!strlen($lang)) {
537
-		$lang = $GLOBALS['spip_lang'];
538
-	} // Cas 3. l'objet est multilingue !
539
-	elseif (
540
-		$lang_select !== 'oui'
541
-		and strlen($titre) > 10
542
-		and strpos($titre, '<multi>') !== false
543
-		and strpos(echappe_html($titre), '<multi>') !== false
544
-	) {
545
-		$lang = $GLOBALS['spip_lang'];
546
-	}
547
-
548
-	// faire un lang_select() eventuellement sur la langue inchangee
549
-	lang_select($lang);
550
-
551
-	return;
529
+    // Cas 1. forcer_lang = true et pas de critere {lang_select}
530
+    if (
531
+        isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang']
532
+        and $lang_select !== 'oui'
533
+    ) {
534
+        $lang = $GLOBALS['spip_lang'];
535
+    } // Cas 2. l'objet n'a pas de langue definie (ou definie a '')
536
+    elseif (!strlen($lang)) {
537
+        $lang = $GLOBALS['spip_lang'];
538
+    } // Cas 3. l'objet est multilingue !
539
+    elseif (
540
+        $lang_select !== 'oui'
541
+        and strlen($titre) > 10
542
+        and strpos($titre, '<multi>') !== false
543
+        and strpos(echappe_html($titre), '<multi>') !== false
544
+    ) {
545
+        $lang = $GLOBALS['spip_lang'];
546
+    }
547
+
548
+    // faire un lang_select() eventuellement sur la langue inchangee
549
+    lang_select($lang);
550
+
551
+    return;
552 552
 }
553 553
 
554 554
 
@@ -556,21 +556,21 @@  discard block
 block discarded – undo
556 556
 // il faut le nettoyer car il pourrait etre injecte en SQL
557 557
 // https://code.spip.net/@nettoyer_env_doublons
558 558
 function nettoyer_env_doublons($envd) {
559
-	foreach ($envd as $table => $liste) {
560
-		$n = '';
561
-		foreach (explode(',', $liste) as $val) {
562
-			if ($a = intval($val) and $val === strval($a)) {
563
-				$n .= ',' . $val;
564
-			}
565
-		}
566
-		if (strlen($n)) {
567
-			$envd[$table] = $n;
568
-		} else {
569
-			unset($envd[$table]);
570
-		}
571
-	}
572
-
573
-	return $envd;
559
+    foreach ($envd as $table => $liste) {
560
+        $n = '';
561
+        foreach (explode(',', $liste) as $val) {
562
+            if ($a = intval($val) and $val === strval($a)) {
563
+                $n .= ',' . $val;
564
+            }
565
+        }
566
+        if (strlen($n)) {
567
+            $envd[$table] = $n;
568
+        } else {
569
+            unset($envd[$table]);
570
+        }
571
+    }
572
+
573
+    return $envd;
574 574
 }
575 575
 
576 576
 /**
@@ -589,21 +589,21 @@  discard block
 block discarded – undo
589 589
  *     Opérateur trouvé (SELF ou SUBSELECT) sinon false.
590 590
  **/
591 591
 function match_self($w) {
592
-	if (is_string($w)) {
593
-		return false;
594
-	}
595
-	if (is_array($w)) {
596
-		if (in_array(reset($w), ['SELF', 'SUBSELECT'])) {
597
-			return $w;
598
-		}
599
-		foreach (array_filter($w, 'is_array') as $sw) {
600
-			if ($m = match_self($sw)) {
601
-				return $m;
602
-			}
603
-		}
604
-	}
605
-
606
-	return false;
592
+    if (is_string($w)) {
593
+        return false;
594
+    }
595
+    if (is_array($w)) {
596
+        if (in_array(reset($w), ['SELF', 'SUBSELECT'])) {
597
+            return $w;
598
+        }
599
+        foreach (array_filter($w, 'is_array') as $sw) {
600
+            if ($m = match_self($sw)) {
601
+                return $m;
602
+            }
603
+        }
604
+    }
605
+
606
+    return false;
607 607
 }
608 608
 
609 609
 /**
@@ -619,16 +619,16 @@  discard block
 block discarded – undo
619 619
  *     est remplacée par son code.
620 620
  **/
621 621
 function remplace_sous_requete($w, $sousrequete) {
622
-	if (is_array($w)) {
623
-		if (in_array(reset($w), ['SELF', 'SUBSELECT'])) {
624
-			return $sousrequete;
625
-		}
626
-		foreach ($w as $k => $sw) {
627
-			$w[$k] = remplace_sous_requete($sw, $sousrequete);
628
-		}
629
-	}
630
-
631
-	return $w;
622
+    if (is_array($w)) {
623
+        if (in_array(reset($w), ['SELF', 'SUBSELECT'])) {
624
+            return $sousrequete;
625
+        }
626
+        foreach ($w as $k => $sw) {
627
+            $w[$k] = remplace_sous_requete($sw, $sousrequete);
628
+        }
629
+    }
630
+
631
+    return $w;
632 632
 }
633 633
 
634 634
 /**
@@ -642,17 +642,17 @@  discard block
 block discarded – undo
642 642
  *     - Conditions avec des sous requêtes
643 643
  **/
644 644
 function trouver_sous_requetes($where) {
645
-	$where_simples = [];
646
-	$where_sous = [];
647
-	foreach ($where as $k => $w) {
648
-		if (match_self($w)) {
649
-			$where_sous[$k] = $w;
650
-		} else {
651
-			$where_simples[$k] = $w;
652
-		}
653
-	}
654
-
655
-	return [$where_simples, $where_sous];
645
+    $where_simples = [];
646
+    $where_sous = [];
647
+    foreach ($where as $k => $w) {
648
+        if (match_self($w)) {
649
+            $where_sous[$k] = $w;
650
+        } else {
651
+            $where_simples[$k] = $w;
652
+        }
653
+    }
654
+
655
+    return [$where_simples, $where_sous];
656 656
 }
657 657
 
658 658
 
@@ -678,292 +678,292 @@  discard block
 block discarded – undo
678 678
  * @return resource
679 679
  */
680 680
 function calculer_select(
681
-	$select = [],
682
-	$from = [],
683
-	$from_type = [],
684
-	$where = [],
685
-	$join = [],
686
-	$groupby = [],
687
-	$orderby = [],
688
-	$limit = '',
689
-	$having = [],
690
-	$table = '',
691
-	$id = '',
692
-	$serveur = '',
693
-	$requeter = true
681
+    $select = [],
682
+    $from = [],
683
+    $from_type = [],
684
+    $where = [],
685
+    $join = [],
686
+    $groupby = [],
687
+    $orderby = [],
688
+    $limit = '',
689
+    $having = [],
690
+    $table = '',
691
+    $id = '',
692
+    $serveur = '',
693
+    $requeter = true
694 694
 ) {
695 695
 
696
-	// retirer les criteres vides:
697
-	// {X ?} avec X absent de l'URL
698
-	// {par #ENV{X}} avec X absent de l'URL
699
-	// IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil)
700
-	$menage = false;
701
-	foreach ($where as $k => $v) {
702
-		if (is_array($v)) {
703
-			if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) {
704
-				$op = false;
705
-			} elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) {
706
-				$op = false;
707
-			} else {
708
-				$op = $v[0] ? $v[0] : $v;
709
-			}
710
-		} else {
711
-			$op = $v;
712
-		}
713
-		if ((!$op) or ($op == 1) or ($op == '0=0')) {
714
-			unset($where[$k]);
715
-			$menage = true;
716
-		}
717
-	}
718
-
719
-	// evacuer les eventuels groupby vide issus d'un calcul dynamique
720
-	$groupby = array_diff($groupby, ['']);
721
-
722
-	// remplacer les sous requetes recursives au calcul
723
-	list($where_simples, $where_sous) = trouver_sous_requetes($where);
724
-	foreach ($where_sous as $k => $w) {
725
-		$menage = true;
726
-		// on recupere la sous requete
727
-		$sous = match_self($w);
728
-		if ($sous[0] == 'SELF') {
729
-			// c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where)
730
-			array_push($where_simples, $sous[2]);
731
-			$wheresub = [
732
-				$sous[2],
733
-				'0=0'
734
-			]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where
735
-			$jsub = $join;
736
-			// trouver les jointures utiles a
737
-			// reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees
738
-			// ie L1.objet='article'
739
-			// on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction
740
-			$i = 0;
741
-			do {
742
-				$where[$k] = remplace_sous_requete($w, '(' . calculer_select(
743
-					[$sous[1] . ' AS id'],
744
-					$from,
745
-					$from_type,
746
-					$wheresub,
747
-					$jsub,
748
-					[],
749
-					[],
750
-					'',
751
-					$having,
752
-					$table,
753
-					$id,
754
-					$serveur,
755
-					false
756
-				) . ')');
757
-				if (!$i) {
758
-					$i = 1;
759
-					$wherestring = calculer_where_to_string($where[$k]);
760
-					foreach ($join as $cle => $wj) {
761
-						if (
762
-							count($wj) == 4
763
-							and strpos($wherestring, "{$cle}.") !== false
764
-						) {
765
-							$i = 0;
766
-							$wheresub[] = $wj[3];
767
-							unset($jsub[$cle][3]);
768
-						}
769
-					}
770
-				}
771
-			} while ($i++ < 1);
772
-		}
773
-		if ($sous[0] == 'SUBSELECT') {
774
-			// c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having)
775
-			array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ?
776
-			$where[$k] = remplace_sous_requete($w, '(' . calculer_select(
777
-				$sous[1], # select
778
-				$sous[2], #from
779
-				[], #from_type
780
-				$sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [],
781
-				#where, qui peut etre de la forme string comme dans sql_select
782
-					[], #join
783
-				$sous[4] ? $sous[4] : [], #groupby
784
-				$sous[5] ? $sous[5] : [], #orderby
785
-				$sous[6], #limit
786
-				$sous[7] ? $sous[7] : [], #having
787
-				$table,
788
-				$id,
789
-				$serveur,
790
-				false
791
-			) . ')');
792
-		}
793
-		array_pop($where_simples);
794
-	}
795
-
796
-	foreach ($having as $k => $v) {
797
-		if ((!$v) or ($v == 1) or ($v == '0=0')) {
798
-			unset($having[$k]);
799
-		}
800
-	}
801
-
802
-	// Installer les jointures.
803
-	// Retirer celles seulement utiles aux criteres finalement absents mais
804
-	// parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln
805
-	// si elle est seulement utile a Ln+1 elle meme inutile
806
-
807
-	$afrom = [];
808
-	$equiv = [];
809
-	$k = count($join);
810
-	foreach (array_reverse($join, true) as $cledef => $j) {
811
-		$cle = $cledef;
812
-		// le format de join est :
813
-		// array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]])
814
-		$join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber
815
-		if (count($join[$cle]) == 2) {
816
-			$join[$cle][] = $join[$cle][1];
817
-		}
818
-		if (count($join[$cle]) == 3) {
819
-			$join[$cle][] = '';
820
-		}
821
-		list($t, $c, $carr, $and) = $join[$cle];
822
-		// si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste
823
-		// pour compat avec ancienne convention
824
-		if (is_numeric($cle)) {
825
-			$cle = "L$k";
826
-		}
827
-		$cle_where_lie = "JOIN-$cle";
828
-		if (
829
-			!$menage
830
-			or isset($afrom[$cle])
831
-			or calculer_jointnul($cle, $select)
832
-			or calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]]))
833
-			or calculer_jointnul($cle, $having)
834
-			or calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => '']))
835
-		) {
836
-			// corriger les references non explicites dans select
837
-			// ou groupby
838
-			foreach ($select as $i => $s) {
839
-				if ($s == $c) {
840
-					$select[$i] = "$cle.$c AS $c";
841
-					break;
842
-				}
843
-			}
844
-			foreach ($groupby as $i => $g) {
845
-				if ($g == $c) {
846
-					$groupby[$i] = "$cle.$c";
847
-					break;
848
-				}
849
-			}
850
-			// on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin
851
-			// sans recours a preg_match
852
-			// un implode(' ',..) est fait dans reinjecte_joint un peu plus bas
853
-			$afrom[$t][$cle] = [
854
-				"\n" .
855
-				(isset($from_type[$cle]) ? $from_type[$cle] : 'INNER') . ' JOIN',
856
-				$from[$cle],
857
-				"AS $cle",
858
-				'ON (',
859
-				"$cle.$c",
860
-				'=',
861
-				"$t.$carr",
862
-				($and ? 'AND ' . $and : '') .
863
-				')'
864
-			];
865
-			if (isset($afrom[$cle])) {
866
-				$afrom[$t] = $afrom[$t] + $afrom[$cle];
867
-				unset($afrom[$cle]);
868
-			}
869
-			$equiv[] = $carr;
870
-		} else {
871
-			unset($join[$cledef]);
872
-			if (isset($where_simples[$cle_where_lie])) {
873
-				unset($where_simples[$cle_where_lie]);
874
-				unset($where[$cle_where_lie]);
875
-			}
876
-		}
877
-		unset($from[$cle]);
878
-		$k--;
879
-	}
880
-
881
-	if (count($afrom)) {
882
-		// Regarder si la table principale ne sert finalement a rien comme dans
883
-		//<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3>
884
-		//<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2>
885
-		//<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5>
886
-		// ou dans
887
-		//<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8>
888
-		// qui comporte plusieurs jointures
889
-		// ou dans
890
-		// <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6>
891
-		// <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7>
892
-		// penser a regarder aussi la clause orderby pour ne pas simplifier abusivement
893
-		// <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9>
894
-		// penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement
895
-		// <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10>
896
-
897
-		$t = key($from);
898
-		$c = current($from);
899
-		reset($from);
900
-		$e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/';
901
-		if (
902
-			!(strpos($t, ' ') or // jointure des le depart cf boucle_doc
903
-				calculer_jointnul($t, $select, $e) or
904
-				calculer_jointnul($t, $join, $e) or
905
-				calculer_jointnul($t, $where, $e) or
906
-				calculer_jointnul($t, $orderby, $e) or
907
-				calculer_jointnul($t, $groupby, $e) or
908
-				calculer_jointnul($t, $having, $e))
909
-			&& count($afrom[$t])
910
-		) {
911
-			$nfrom = reset($afrom[$t]);
912
-			$nt = key($afrom[$t]);
913
-			unset($from[$t]);
914
-			$from[$nt] = $nfrom[1];
915
-			unset($afrom[$t][$nt]);
916
-			$afrom[$nt] = $afrom[$t];
917
-			unset($afrom[$t]);
918
-			$e = '/\b' . preg_quote($nfrom[6]) . '\b/';
919
-			$t = $nfrom[4];
920
-			$alias = '';
921
-			// verifier que les deux cles sont homonymes, sinon installer un alias dans le select
922
-			$oldcle = explode('.', $nfrom[6]);
923
-			$oldcle = end($oldcle);
924
-			$newcle = explode('.', $nfrom[4]);
925
-			$newcle = end($newcle);
926
-			if ($newcle != $oldcle) {
927
-				// si l'ancienne cle etait deja dans le select avec un AS
928
-				// reprendre simplement ce AS
929
-				$as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/';
930
-				if (preg_match($as, implode(',', $select), $m)) {
931
-					$alias = '';
932
-				} else {
933
-					$alias = ', ' . $nfrom[4] . " AS $oldcle";
934
-				}
935
-			}
936
-			$select = remplacer_jointnul($t . $alias, $select, $e);
937
-			$join = remplacer_jointnul($t, $join, $e);
938
-			$where = remplacer_jointnul($t, $where, $e);
939
-			$having = remplacer_jointnul($t, $having, $e);
940
-			$groupby = remplacer_jointnul($t, $groupby, $e);
941
-			$orderby = remplacer_jointnul($t, $orderby, $e);
942
-		}
943
-		$from = reinjecte_joint($afrom, $from);
944
-	}
945
-	if (empty($GLOBALS['debug']) or !is_array($GLOBALS['debug'])) {
946
-		$wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug'];
947
-		$GLOBALS['debug'] = [];
948
-		if ($wasdebug) {
949
-			$GLOBALS['debug']['debug'] = true;
950
-		}
951
-	}
952
-	$GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter];
953
-	$r = sql_select(
954
-		$select,
955
-		$from,
956
-		$where,
957
-		$groupby,
958
-		array_filter($orderby),
959
-		$limit,
960
-		$having,
961
-		$serveur,
962
-		$requeter
963
-	);
964
-	unset($GLOBALS['debug']['aucasou']);
965
-
966
-	return $r;
696
+    // retirer les criteres vides:
697
+    // {X ?} avec X absent de l'URL
698
+    // {par #ENV{X}} avec X absent de l'URL
699
+    // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil)
700
+    $menage = false;
701
+    foreach ($where as $k => $v) {
702
+        if (is_array($v)) {
703
+            if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) {
704
+                $op = false;
705
+            } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) {
706
+                $op = false;
707
+            } else {
708
+                $op = $v[0] ? $v[0] : $v;
709
+            }
710
+        } else {
711
+            $op = $v;
712
+        }
713
+        if ((!$op) or ($op == 1) or ($op == '0=0')) {
714
+            unset($where[$k]);
715
+            $menage = true;
716
+        }
717
+    }
718
+
719
+    // evacuer les eventuels groupby vide issus d'un calcul dynamique
720
+    $groupby = array_diff($groupby, ['']);
721
+
722
+    // remplacer les sous requetes recursives au calcul
723
+    list($where_simples, $where_sous) = trouver_sous_requetes($where);
724
+    foreach ($where_sous as $k => $w) {
725
+        $menage = true;
726
+        // on recupere la sous requete
727
+        $sous = match_self($w);
728
+        if ($sous[0] == 'SELF') {
729
+            // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where)
730
+            array_push($where_simples, $sous[2]);
731
+            $wheresub = [
732
+                $sous[2],
733
+                '0=0'
734
+            ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where
735
+            $jsub = $join;
736
+            // trouver les jointures utiles a
737
+            // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees
738
+            // ie L1.objet='article'
739
+            // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction
740
+            $i = 0;
741
+            do {
742
+                $where[$k] = remplace_sous_requete($w, '(' . calculer_select(
743
+                    [$sous[1] . ' AS id'],
744
+                    $from,
745
+                    $from_type,
746
+                    $wheresub,
747
+                    $jsub,
748
+                    [],
749
+                    [],
750
+                    '',
751
+                    $having,
752
+                    $table,
753
+                    $id,
754
+                    $serveur,
755
+                    false
756
+                ) . ')');
757
+                if (!$i) {
758
+                    $i = 1;
759
+                    $wherestring = calculer_where_to_string($where[$k]);
760
+                    foreach ($join as $cle => $wj) {
761
+                        if (
762
+                            count($wj) == 4
763
+                            and strpos($wherestring, "{$cle}.") !== false
764
+                        ) {
765
+                            $i = 0;
766
+                            $wheresub[] = $wj[3];
767
+                            unset($jsub[$cle][3]);
768
+                        }
769
+                    }
770
+                }
771
+            } while ($i++ < 1);
772
+        }
773
+        if ($sous[0] == 'SUBSELECT') {
774
+            // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having)
775
+            array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ?
776
+            $where[$k] = remplace_sous_requete($w, '(' . calculer_select(
777
+                $sous[1], # select
778
+                $sous[2], #from
779
+                [], #from_type
780
+                $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [],
781
+                #where, qui peut etre de la forme string comme dans sql_select
782
+                    [], #join
783
+                $sous[4] ? $sous[4] : [], #groupby
784
+                $sous[5] ? $sous[5] : [], #orderby
785
+                $sous[6], #limit
786
+                $sous[7] ? $sous[7] : [], #having
787
+                $table,
788
+                $id,
789
+                $serveur,
790
+                false
791
+            ) . ')');
792
+        }
793
+        array_pop($where_simples);
794
+    }
795
+
796
+    foreach ($having as $k => $v) {
797
+        if ((!$v) or ($v == 1) or ($v == '0=0')) {
798
+            unset($having[$k]);
799
+        }
800
+    }
801
+
802
+    // Installer les jointures.
803
+    // Retirer celles seulement utiles aux criteres finalement absents mais
804
+    // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln
805
+    // si elle est seulement utile a Ln+1 elle meme inutile
806
+
807
+    $afrom = [];
808
+    $equiv = [];
809
+    $k = count($join);
810
+    foreach (array_reverse($join, true) as $cledef => $j) {
811
+        $cle = $cledef;
812
+        // le format de join est :
813
+        // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]])
814
+        $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber
815
+        if (count($join[$cle]) == 2) {
816
+            $join[$cle][] = $join[$cle][1];
817
+        }
818
+        if (count($join[$cle]) == 3) {
819
+            $join[$cle][] = '';
820
+        }
821
+        list($t, $c, $carr, $and) = $join[$cle];
822
+        // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste
823
+        // pour compat avec ancienne convention
824
+        if (is_numeric($cle)) {
825
+            $cle = "L$k";
826
+        }
827
+        $cle_where_lie = "JOIN-$cle";
828
+        if (
829
+            !$menage
830
+            or isset($afrom[$cle])
831
+            or calculer_jointnul($cle, $select)
832
+            or calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]]))
833
+            or calculer_jointnul($cle, $having)
834
+            or calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => '']))
835
+        ) {
836
+            // corriger les references non explicites dans select
837
+            // ou groupby
838
+            foreach ($select as $i => $s) {
839
+                if ($s == $c) {
840
+                    $select[$i] = "$cle.$c AS $c";
841
+                    break;
842
+                }
843
+            }
844
+            foreach ($groupby as $i => $g) {
845
+                if ($g == $c) {
846
+                    $groupby[$i] = "$cle.$c";
847
+                    break;
848
+                }
849
+            }
850
+            // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin
851
+            // sans recours a preg_match
852
+            // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas
853
+            $afrom[$t][$cle] = [
854
+                "\n" .
855
+                (isset($from_type[$cle]) ? $from_type[$cle] : 'INNER') . ' JOIN',
856
+                $from[$cle],
857
+                "AS $cle",
858
+                'ON (',
859
+                "$cle.$c",
860
+                '=',
861
+                "$t.$carr",
862
+                ($and ? 'AND ' . $and : '') .
863
+                ')'
864
+            ];
865
+            if (isset($afrom[$cle])) {
866
+                $afrom[$t] = $afrom[$t] + $afrom[$cle];
867
+                unset($afrom[$cle]);
868
+            }
869
+            $equiv[] = $carr;
870
+        } else {
871
+            unset($join[$cledef]);
872
+            if (isset($where_simples[$cle_where_lie])) {
873
+                unset($where_simples[$cle_where_lie]);
874
+                unset($where[$cle_where_lie]);
875
+            }
876
+        }
877
+        unset($from[$cle]);
878
+        $k--;
879
+    }
880
+
881
+    if (count($afrom)) {
882
+        // Regarder si la table principale ne sert finalement a rien comme dans
883
+        //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3>
884
+        //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2>
885
+        //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5>
886
+        // ou dans
887
+        //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8>
888
+        // qui comporte plusieurs jointures
889
+        // ou dans
890
+        // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6>
891
+        // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7>
892
+        // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement
893
+        // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9>
894
+        // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement
895
+        // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10>
896
+
897
+        $t = key($from);
898
+        $c = current($from);
899
+        reset($from);
900
+        $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/';
901
+        if (
902
+            !(strpos($t, ' ') or // jointure des le depart cf boucle_doc
903
+                calculer_jointnul($t, $select, $e) or
904
+                calculer_jointnul($t, $join, $e) or
905
+                calculer_jointnul($t, $where, $e) or
906
+                calculer_jointnul($t, $orderby, $e) or
907
+                calculer_jointnul($t, $groupby, $e) or
908
+                calculer_jointnul($t, $having, $e))
909
+            && count($afrom[$t])
910
+        ) {
911
+            $nfrom = reset($afrom[$t]);
912
+            $nt = key($afrom[$t]);
913
+            unset($from[$t]);
914
+            $from[$nt] = $nfrom[1];
915
+            unset($afrom[$t][$nt]);
916
+            $afrom[$nt] = $afrom[$t];
917
+            unset($afrom[$t]);
918
+            $e = '/\b' . preg_quote($nfrom[6]) . '\b/';
919
+            $t = $nfrom[4];
920
+            $alias = '';
921
+            // verifier que les deux cles sont homonymes, sinon installer un alias dans le select
922
+            $oldcle = explode('.', $nfrom[6]);
923
+            $oldcle = end($oldcle);
924
+            $newcle = explode('.', $nfrom[4]);
925
+            $newcle = end($newcle);
926
+            if ($newcle != $oldcle) {
927
+                // si l'ancienne cle etait deja dans le select avec un AS
928
+                // reprendre simplement ce AS
929
+                $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/';
930
+                if (preg_match($as, implode(',', $select), $m)) {
931
+                    $alias = '';
932
+                } else {
933
+                    $alias = ', ' . $nfrom[4] . " AS $oldcle";
934
+                }
935
+            }
936
+            $select = remplacer_jointnul($t . $alias, $select, $e);
937
+            $join = remplacer_jointnul($t, $join, $e);
938
+            $where = remplacer_jointnul($t, $where, $e);
939
+            $having = remplacer_jointnul($t, $having, $e);
940
+            $groupby = remplacer_jointnul($t, $groupby, $e);
941
+            $orderby = remplacer_jointnul($t, $orderby, $e);
942
+        }
943
+        $from = reinjecte_joint($afrom, $from);
944
+    }
945
+    if (empty($GLOBALS['debug']) or !is_array($GLOBALS['debug'])) {
946
+        $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug'];
947
+        $GLOBALS['debug'] = [];
948
+        if ($wasdebug) {
949
+            $GLOBALS['debug']['debug'] = true;
950
+        }
951
+    }
952
+    $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter];
953
+    $r = sql_select(
954
+        $select,
955
+        $from,
956
+        $where,
957
+        $groupby,
958
+        array_filter($orderby),
959
+        $limit,
960
+        $having,
961
+        $serveur,
962
+        $requeter
963
+    );
964
+    unset($GLOBALS['debug']['aucasou']);
965
+
966
+    return $r;
967 967
 }
968 968
 
969 969
 /**
@@ -974,20 +974,20 @@  discard block
 block discarded – undo
974 974
  * @return string
975 975
  */
976 976
 function calculer_where_to_string($v, $join = 'AND') {
977
-	if (empty($v)) {
978
-		return '';
979
-	}
980
-
981
-	if (!is_array($v)) {
982
-		return $v;
983
-	} else {
984
-		$exp = '';
985
-		if (strtoupper($join) === 'AND') {
986
-			return $exp . join(" $join ", array_map('calculer_where_to_string', $v));
987
-		} else {
988
-			return $exp . join($join, $v);
989
-		}
990
-	}
977
+    if (empty($v)) {
978
+        return '';
979
+    }
980
+
981
+    if (!is_array($v)) {
982
+        return $v;
983
+    } else {
984
+        $exp = '';
985
+        if (strtoupper($join) === 'AND') {
986
+            return $exp . join(" $join ", array_map('calculer_where_to_string', $v));
987
+        } else {
988
+            return $exp . join($join, $v);
989
+        }
990
+    }
991 991
 }
992 992
 
993 993
 
@@ -995,62 +995,62 @@  discard block
 block discarded – undo
995 995
 
996 996
 // https://code.spip.net/@calculer_jointnul
997 997
 function calculer_jointnul($cle, $exp, $equiv = '') {
998
-	if (!is_array($exp)) {
999
-		if ($equiv) {
1000
-			$exp = preg_replace($equiv, '', $exp);
1001
-		}
1002
-
1003
-		return preg_match("/\\b$cle\\./", $exp);
1004
-	} else {
1005
-		foreach ($exp as $v) {
1006
-			if (calculer_jointnul($cle, $v, $equiv)) {
1007
-				return true;
1008
-			}
1009
-		}
1010
-
1011
-		return false;
1012
-	}
998
+    if (!is_array($exp)) {
999
+        if ($equiv) {
1000
+            $exp = preg_replace($equiv, '', $exp);
1001
+        }
1002
+
1003
+        return preg_match("/\\b$cle\\./", $exp);
1004
+    } else {
1005
+        foreach ($exp as $v) {
1006
+            if (calculer_jointnul($cle, $v, $equiv)) {
1007
+                return true;
1008
+            }
1009
+        }
1010
+
1011
+        return false;
1012
+    }
1013 1013
 }
1014 1014
 
1015 1015
 // https://code.spip.net/@reinjecte_joint
1016 1016
 function reinjecte_joint($afrom, $from) {
1017
-	$from_synth = [];
1018
-	foreach ($from as $k => $v) {
1019
-		$from_synth[$k] = $from[$k];
1020
-		if (isset($afrom[$k])) {
1021
-			foreach ($afrom[$k] as $kk => $vv) {
1022
-				$afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]);
1023
-			}
1024
-			$from_synth["$k@"] = implode(' ', $afrom[$k]);
1025
-			unset($afrom[$k]);
1026
-		}
1027
-	}
1028
-
1029
-	return $from_synth;
1017
+    $from_synth = [];
1018
+    foreach ($from as $k => $v) {
1019
+        $from_synth[$k] = $from[$k];
1020
+        if (isset($afrom[$k])) {
1021
+            foreach ($afrom[$k] as $kk => $vv) {
1022
+                $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]);
1023
+            }
1024
+            $from_synth["$k@"] = implode(' ', $afrom[$k]);
1025
+            unset($afrom[$k]);
1026
+        }
1027
+    }
1028
+
1029
+    return $from_synth;
1030 1030
 }
1031 1031
 
1032 1032
 // https://code.spip.net/@remplacer_jointnul
1033 1033
 function remplacer_jointnul($cle, $exp, $equiv = '') {
1034
-	if (!is_array($exp)) {
1035
-		return preg_replace($equiv, $cle, $exp);
1036
-	} else {
1037
-		foreach ($exp as $k => $v) {
1038
-			$exp[$k] = remplacer_jointnul($cle, $v, $equiv);
1039
-		}
1040
-
1041
-		return $exp;
1042
-	}
1034
+    if (!is_array($exp)) {
1035
+        return preg_replace($equiv, $cle, $exp);
1036
+    } else {
1037
+        foreach ($exp as $k => $v) {
1038
+            $exp[$k] = remplacer_jointnul($cle, $v, $equiv);
1039
+        }
1040
+
1041
+        return $exp;
1042
+    }
1043 1043
 }
1044 1044
 
1045 1045
 // calcul du nom du squelette
1046 1046
 // https://code.spip.net/@calculer_nom_fonction_squel
1047 1047
 function calculer_nom_fonction_squel($skel, $mime_type = 'html', $connect = '') {
1048
-	// ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine
1049
-	if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) {
1050
-		$skel = substr($skel, strlen(_DIR_RACINE));
1051
-	}
1052
-
1053
-	return $mime_type
1054
-	. (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_'
1055
-	. md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : ''));
1048
+    // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine
1049
+    if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) {
1050
+        $skel = substr($skel, strlen(_DIR_RACINE));
1051
+    }
1052
+
1053
+    return $mime_type
1054
+    . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_'
1055
+    . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : ''));
1056 1056
 }
Please login to merge, or discard this patch.
ecrire/public/boucles.php 1 patch
Indentation   +24 added lines, -24 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
 
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
  *     Code PHP compilé de la boucle
33 33
  **/
34 34
 function boucle_DEFAUT_dist($id_boucle, &$boucles) {
35
-	return calculer_boucle($id_boucle, $boucles);
35
+    return calculer_boucle($id_boucle, $boucles);
36 36
 }
37 37
 
38 38
 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
  *     Code PHP compilé de la boucle
52 52
  **/
53 53
 function boucle_BOUCLE_dist($id_boucle, &$boucles) {
54
-	return calculer_boucle($id_boucle, $boucles);
54
+    return calculer_boucle($id_boucle, $boucles);
55 55
 }
56 56
 
57 57
 
@@ -81,30 +81,30 @@  discard block
 block discarded – undo
81 81
  *     Code PHP compilé de la boucle
82 82
  **/
83 83
 function boucle_HIERARCHIE_dist($id_boucle, &$boucles) {
84
-	$boucle = &$boucles[$id_boucle];
85
-	$id_table = $boucle->id_table . '.id_rubrique';
84
+    $boucle = &$boucles[$id_boucle];
85
+    $id_table = $boucle->id_table . '.id_rubrique';
86 86
 
87
-	// Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille
88
-	// sauf en presence du critere {tout} (vu par phraser_html)
89
-	// ou {id_article} qui positionne aussi le {tout}
87
+    // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille
88
+    // sauf en presence du critere {tout} (vu par phraser_html)
89
+    // ou {id_article} qui positionne aussi le {tout}
90 90
 
91
-	$boucle->hierarchie = 'if (!($id_rubrique = intval('
92
-		. calculer_argument_precedent($boucle->id_boucle, 'id_rubrique', $boucles)
93
-		. ")))\n\t\treturn '';\n\t"
94
-		. "include_spip('inc/rubriques');\n\t"
95
-		. '$hierarchie = calcul_hierarchie_in($id_rubrique,'
96
-		. (isset($boucle->modificateur['tout']) ? 'true' : 'false')
97
-		. ");\n\t"
98
-		. 'if (!$hierarchie) return "";' . "\n\t";
91
+    $boucle->hierarchie = 'if (!($id_rubrique = intval('
92
+        . calculer_argument_precedent($boucle->id_boucle, 'id_rubrique', $boucles)
93
+        . ")))\n\t\treturn '';\n\t"
94
+        . "include_spip('inc/rubriques');\n\t"
95
+        . '$hierarchie = calcul_hierarchie_in($id_rubrique,'
96
+        . (isset($boucle->modificateur['tout']) ? 'true' : 'false')
97
+        . ");\n\t"
98
+        . 'if (!$hierarchie) return "";' . "\n\t";
99 99
 
100
-	$boucle->where[] = ["'IN'", "'$id_table'", '"($hierarchie)"'];
100
+    $boucle->where[] = ["'IN'", "'$id_table'", '"($hierarchie)"'];
101 101
 
102
-	$order = "FIELD($id_table, \$hierarchie)";
103
-	if (!isset($boucle->default_order[0]) or $boucle->default_order[0] != ' DESC') {
104
-		$boucle->default_order[] = "\"$order\"";
105
-	} else {
106
-		$boucle->default_order[0] = "\"$order DESC\"";
107
-	}
102
+    $order = "FIELD($id_table, \$hierarchie)";
103
+    if (!isset($boucle->default_order[0]) or $boucle->default_order[0] != ' DESC') {
104
+        $boucle->default_order[] = "\"$order\"";
105
+    } else {
106
+        $boucle->default_order[0] = "\"$order DESC\"";
107
+    }
108 108
 
109
-	return calculer_boucle($id_boucle, $boucles);
109
+    return calculer_boucle($id_boucle, $boucles);
110 110
 }
Please login to merge, or discard this patch.
ecrire/public/styliser.php 1 patch
Indentation   +126 added lines, -126 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
 // Ce fichier doit imperativement definir la fonction ci-dessous:
@@ -39,59 +39,59 @@  discard block
 block discarded – undo
39 39
  * @return array
40 40
  */
41 41
 function public_styliser_dist($fond, $contexte, $lang = '', $connect = '') {
42
-	static $styliser_par_z;
43
-
44
-	// s'assurer que le fond est licite
45
-	// car il peut etre construit a partir d'une variable d'environnement
46
-	if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) {
47
-		$fond = '404';
48
-	}
49
-
50
-	if (strncmp($fond, 'modeles/', 8) == 0) {
51
-		$modele = substr($fond, 8);
52
-		$modele = styliser_modele($modele, null, $contexte);
53
-		$fond = "modeles/$modele";
54
-	}
55
-
56
-	// Choisir entre $fond-dist.html, $fond=7.html, etc?
57
-	$id_rubrique = 0;
58
-	// Chercher le fond qui va servir de squelette
59
-	if ($r = quete_rubrique_fond($contexte)) {
60
-		list($id_rubrique, $lang) = $r;
61
-	}
62
-
63
-	// trouver un squelette du nom demande
64
-	// ne rien dire si on ne trouve pas,
65
-	// c'est l'appelant qui sait comment gerer la situation
66
-	// ou les plugins qui feront mieux dans le pipeline
67
-	$squelette = trouver_fond($fond, '', true);
68
-	$ext = $squelette['extension'];
69
-
70
-	$flux = [
71
-		'args' => [
72
-			'id_rubrique' => $id_rubrique,
73
-			'ext' => $ext,
74
-			'fond' => $fond,
75
-			'lang' => $lang,
76
-			'contexte' => $contexte, // le style d'un objet peut dependre de lui meme
77
-			'connect' => $connect
78
-		],
79
-		'data' => $squelette['fond'],
80
-	];
81
-
82
-	if (test_espace_prive() or defined('_ZPIP')) {
83
-		if (!$styliser_par_z) {
84
-			$styliser_par_z = charger_fonction('styliser_par_z', 'public');
85
-		}
86
-		$flux = $styliser_par_z($flux);
87
-	}
88
-
89
-	$flux = styliser_par_objets($flux);
90
-
91
-	// pipeline styliser
92
-	$squelette = pipeline('styliser', $flux);
93
-
94
-	return [$squelette, $ext, $ext, "$squelette.$ext"];
42
+    static $styliser_par_z;
43
+
44
+    // s'assurer que le fond est licite
45
+    // car il peut etre construit a partir d'une variable d'environnement
46
+    if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) {
47
+        $fond = '404';
48
+    }
49
+
50
+    if (strncmp($fond, 'modeles/', 8) == 0) {
51
+        $modele = substr($fond, 8);
52
+        $modele = styliser_modele($modele, null, $contexte);
53
+        $fond = "modeles/$modele";
54
+    }
55
+
56
+    // Choisir entre $fond-dist.html, $fond=7.html, etc?
57
+    $id_rubrique = 0;
58
+    // Chercher le fond qui va servir de squelette
59
+    if ($r = quete_rubrique_fond($contexte)) {
60
+        list($id_rubrique, $lang) = $r;
61
+    }
62
+
63
+    // trouver un squelette du nom demande
64
+    // ne rien dire si on ne trouve pas,
65
+    // c'est l'appelant qui sait comment gerer la situation
66
+    // ou les plugins qui feront mieux dans le pipeline
67
+    $squelette = trouver_fond($fond, '', true);
68
+    $ext = $squelette['extension'];
69
+
70
+    $flux = [
71
+        'args' => [
72
+            'id_rubrique' => $id_rubrique,
73
+            'ext' => $ext,
74
+            'fond' => $fond,
75
+            'lang' => $lang,
76
+            'contexte' => $contexte, // le style d'un objet peut dependre de lui meme
77
+            'connect' => $connect
78
+        ],
79
+        'data' => $squelette['fond'],
80
+    ];
81
+
82
+    if (test_espace_prive() or defined('_ZPIP')) {
83
+        if (!$styliser_par_z) {
84
+            $styliser_par_z = charger_fonction('styliser_par_z', 'public');
85
+        }
86
+        $flux = $styliser_par_z($flux);
87
+    }
88
+
89
+    $flux = styliser_par_objets($flux);
90
+
91
+    // pipeline styliser
92
+    $squelette = pipeline('styliser', $flux);
93
+
94
+    return [$squelette, $ext, $ext, "$squelette.$ext"];
95 95
 }
96 96
 
97 97
 /**
@@ -110,32 +110,32 @@  discard block
 block discarded – undo
110 110
  *     Données du pipeline styliser
111 111
  **/
112 112
 function styliser_par_objets($flux) {
113
-	if (
114
-		test_espace_prive()
115
-		and !$squelette = $flux['data']
116
-		and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0
117
-		and $echafauder = charger_fonction('echafauder', 'prive', true)
118
-	) {
119
-		if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) {
120
-			$table = table_objet(substr($flux['args']['fond'], 19));
121
-			$table_sql = table_objet_sql($table);
122
-			$objets = lister_tables_objets_sql();
123
-			if (isset($objets[$table_sql])) {
124
-				$flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']);
125
-			}
126
-		}
127
-		if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) {
128
-			$type = substr($flux['args']['fond'], 21);
129
-			$table = table_objet($type);
130
-			$table_sql = table_objet_sql($table);
131
-			$objets = lister_tables_objets_sql();
132
-			if (isset($objets[$table_sql])) {
133
-				$flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']);
134
-			}
135
-		}
136
-	}
137
-
138
-	return $flux;
113
+    if (
114
+        test_espace_prive()
115
+        and !$squelette = $flux['data']
116
+        and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0
117
+        and $echafauder = charger_fonction('echafauder', 'prive', true)
118
+    ) {
119
+        if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) {
120
+            $table = table_objet(substr($flux['args']['fond'], 19));
121
+            $table_sql = table_objet_sql($table);
122
+            $objets = lister_tables_objets_sql();
123
+            if (isset($objets[$table_sql])) {
124
+                $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']);
125
+            }
126
+        }
127
+        if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) {
128
+            $type = substr($flux['args']['fond'], 21);
129
+            $table = table_objet($type);
130
+            $table_sql = table_objet_sql($table);
131
+            $objets = lister_tables_objets_sql();
132
+            if (isset($objets[$table_sql])) {
133
+                $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']);
134
+            }
135
+        }
136
+    }
137
+
138
+    return $flux;
139 139
 }
140 140
 
141 141
 /**
@@ -151,50 +151,50 @@  discard block
 block discarded – undo
151 151
  * @return array
152 152
  */
153 153
 function quete_rubrique_fond($contexte) {
154
-	static $liste_objets = null;
155
-	static $quete = [];
156
-	if (is_null($liste_objets)) {
157
-		$liste_objets = [];
158
-		include_spip('inc/urls');
159
-		include_spip('public/quete');
160
-		$l = urls_liste_objets(false);
161
-		// placer la rubrique en tete des objets
162
-		$l = array_diff($l, ['rubrique']);
163
-		array_unshift($l, 'rubrique');
164
-		foreach ($l as $objet) {
165
-			$id = id_table_objet($objet);
166
-			if (!isset($liste_objets[$id])) {
167
-				$liste_objets[$id] = objet_type($objet, false);
168
-			}
169
-		}
170
-	}
171
-	$c = array_intersect_key($contexte, $liste_objets);
172
-	if (!count($c)) {
173
-		return false;
174
-	}
175
-
176
-	$c = array_map('intval', $c);
177
-	$s = serialize($c);
178
-	if (isset($quete[$s])) {
179
-		return $quete[$s];
180
-	}
181
-
182
-	if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) {
183
-		unset($c['id_rubrique']);
184
-		$c = ['id_rubrique' => $r] + $c;
185
-	}
186
-
187
-	foreach ($c as $_id => $id) {
188
-		if (
189
-			$id
190
-			and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id)
191
-		) {
192
-			$lang = isset($row['lang']) ? $row['lang'] : '';
193
-			if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) {
194
-				return $quete[$s] = [$id, $lang];
195
-			}
196
-		}
197
-	}
198
-
199
-	return $quete[$s] = false;
154
+    static $liste_objets = null;
155
+    static $quete = [];
156
+    if (is_null($liste_objets)) {
157
+        $liste_objets = [];
158
+        include_spip('inc/urls');
159
+        include_spip('public/quete');
160
+        $l = urls_liste_objets(false);
161
+        // placer la rubrique en tete des objets
162
+        $l = array_diff($l, ['rubrique']);
163
+        array_unshift($l, 'rubrique');
164
+        foreach ($l as $objet) {
165
+            $id = id_table_objet($objet);
166
+            if (!isset($liste_objets[$id])) {
167
+                $liste_objets[$id] = objet_type($objet, false);
168
+            }
169
+        }
170
+    }
171
+    $c = array_intersect_key($contexte, $liste_objets);
172
+    if (!count($c)) {
173
+        return false;
174
+    }
175
+
176
+    $c = array_map('intval', $c);
177
+    $s = serialize($c);
178
+    if (isset($quete[$s])) {
179
+        return $quete[$s];
180
+    }
181
+
182
+    if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) {
183
+        unset($c['id_rubrique']);
184
+        $c = ['id_rubrique' => $r] + $c;
185
+    }
186
+
187
+    foreach ($c as $_id => $id) {
188
+        if (
189
+            $id
190
+            and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id)
191
+        ) {
192
+            $lang = isset($row['lang']) ? $row['lang'] : '';
193
+            if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) {
194
+                return $quete[$s] = [$id, $lang];
195
+            }
196
+        }
197
+    }
198
+
199
+    return $quete[$s] = false;
200 200
 }
Please login to merge, or discard this patch.
ecrire/maj/2021.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -19,10 +19,10 @@
 block discarded – undo
19 19
  * @package SPIP\Core\SQL\Upgrade
20 20
  **/
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 $GLOBALS['maj'][2021021800] = [
26
-	['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ],
27
-	['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ],
26
+    ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ],
27
+    ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ],
28 28
 ];
Please login to merge, or discard this patch.