Completed
Push — master ( 519300...f005c3 )
by cam
01:22
created
ecrire/balise/logo_.php 1 patch
Indentation   +95 added lines, -95 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
 
@@ -54,84 +54,84 @@  discard block
 block discarded – undo
54 54
  */
55 55
 function balise_LOGO__dist($p) {
56 56
 
57
-	preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs);
58
-	$type = strtolower($regs[1]);
59
-	$suite_logo = $regs[2];
60
-
61
-	// cas de #LOGO_SITE_SPIP
62
-	if ($type == 'site_spip') {
63
-		$type = 'site';
64
-		$_id_objet = "\"'0'\"";
65
-	}
66
-
67
-	$id_objet = id_table_objet($type);
68
-	if (!isset($_id_objet)) {
69
-		$_id_objet = champ_sql($id_objet, $p);
70
-	}
71
-
72
-	$fichier = ($p->etoile === '**') ? -1 : 0;
73
-	$coord = [];
74
-	$align = $lien = '';
75
-	$mode_logo = '';
76
-
77
-	if ($p->param and !$p->param[0][0]) {
78
-		$params = $p->param[0];
79
-		array_shift($params);
80
-		foreach ($params as $a) {
81
-			if ($a[0]->type === 'texte') {
82
-				$n = $a[0]->texte;
83
-				if (is_numeric($n)) {
84
-					$coord[] = $n;
85
-				} elseif (in_array($n, ['top', 'left', 'right', 'center', 'bottom'])) {
86
-					$align = $n;
87
-				} elseif (in_array($n, ['auto', 'icone', 'apercu', 'vignette'])) {
88
-					$mode_logo = $n;
89
-				}
90
-			} else {
91
-				$lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle);
92
-			}
93
-		}
94
-	}
95
-
96
-	$coord_x = !$coord ? 0 : intval(array_shift($coord));
97
-	$coord_y = !$coord ? 0 : intval(array_shift($coord));
98
-
99
-	if ($p->etoile === '*') {
100
-		include_spip('balise/url_');
101
-		$lien = generer_generer_url_arg($type, $p, $_id_objet);
102
-	}
103
-
104
-	$connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : '';
105
-	if ($type == 'document') {
106
-		$qconnect = _q($connect);
107
-		$doc = "quete_document($_id_objet, $qconnect)";
108
-		if ($fichier) {
109
-			$code = "quete_logo_file($doc, $qconnect)";
110
-		} else {
111
-			$code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)";
112
-		}
113
-		// (x=non-faux ? y : '') pour affecter x en retournant y
114
-		if ($p->descr['documents']) {
115
-			$code = '(($doublons["documents"] .= ",". '
116
-				. $_id_objet
117
-				. ") ? $code : '')";
118
-		}
119
-	} elseif ($connect) {
120
-		$code = "''";
121
-		spip_log('Les logos distants ne sont pas prevus');
122
-	} else {
123
-		$code = logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $lien, $p, $suite_logo);
124
-	}
125
-
126
-	// demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0}
127
-	if ($coord_x or $coord_y) {
128
-		$code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))";
129
-	}
130
-
131
-	$p->code = $code;
132
-	$p->interdire_scripts = false;
133
-
134
-	return $p;
57
+    preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs);
58
+    $type = strtolower($regs[1]);
59
+    $suite_logo = $regs[2];
60
+
61
+    // cas de #LOGO_SITE_SPIP
62
+    if ($type == 'site_spip') {
63
+        $type = 'site';
64
+        $_id_objet = "\"'0'\"";
65
+    }
66
+
67
+    $id_objet = id_table_objet($type);
68
+    if (!isset($_id_objet)) {
69
+        $_id_objet = champ_sql($id_objet, $p);
70
+    }
71
+
72
+    $fichier = ($p->etoile === '**') ? -1 : 0;
73
+    $coord = [];
74
+    $align = $lien = '';
75
+    $mode_logo = '';
76
+
77
+    if ($p->param and !$p->param[0][0]) {
78
+        $params = $p->param[0];
79
+        array_shift($params);
80
+        foreach ($params as $a) {
81
+            if ($a[0]->type === 'texte') {
82
+                $n = $a[0]->texte;
83
+                if (is_numeric($n)) {
84
+                    $coord[] = $n;
85
+                } elseif (in_array($n, ['top', 'left', 'right', 'center', 'bottom'])) {
86
+                    $align = $n;
87
+                } elseif (in_array($n, ['auto', 'icone', 'apercu', 'vignette'])) {
88
+                    $mode_logo = $n;
89
+                }
90
+            } else {
91
+                $lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle);
92
+            }
93
+        }
94
+    }
95
+
96
+    $coord_x = !$coord ? 0 : intval(array_shift($coord));
97
+    $coord_y = !$coord ? 0 : intval(array_shift($coord));
98
+
99
+    if ($p->etoile === '*') {
100
+        include_spip('balise/url_');
101
+        $lien = generer_generer_url_arg($type, $p, $_id_objet);
102
+    }
103
+
104
+    $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : '';
105
+    if ($type == 'document') {
106
+        $qconnect = _q($connect);
107
+        $doc = "quete_document($_id_objet, $qconnect)";
108
+        if ($fichier) {
109
+            $code = "quete_logo_file($doc, $qconnect)";
110
+        } else {
111
+            $code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)";
112
+        }
113
+        // (x=non-faux ? y : '') pour affecter x en retournant y
114
+        if ($p->descr['documents']) {
115
+            $code = '(($doublons["documents"] .= ",". '
116
+                . $_id_objet
117
+                . ") ? $code : '')";
118
+        }
119
+    } elseif ($connect) {
120
+        $code = "''";
121
+        spip_log('Les logos distants ne sont pas prevus');
122
+    } else {
123
+        $code = logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $lien, $p, $suite_logo);
124
+    }
125
+
126
+    // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0}
127
+    if ($coord_x or $coord_y) {
128
+        $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))";
129
+    }
130
+
131
+    $p->code = $code;
132
+    $p->interdire_scripts = false;
133
+
134
+    return $p;
135 135
 }
136 136
 
137 137
 /**
@@ -158,20 +158,20 @@  discard block
 block discarded – undo
158 158
  *     Code compilé retournant le chemin du logo ou le code HTML du logo.
159 159
  **/
160 160
 function logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $_lien, $p, $suite) {
161
-	$code = "quete_logo('$id_objet', '" .
162
-		(($suite == '_SURVOL') ? 'off' :
163
-			(($suite == '_NORMAL') ? 'on' : 'ON')) .
164
-		"', $_id_objet," .
165
-		(($suite == '_RUBRIQUE') ?
166
-			champ_sql('id_rubrique', $p) :
167
-			(($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) .
168
-		', ' . intval($fichier) . ')';
169
-
170
-	if ($fichier) {
171
-		return $code;
172
-	}
173
-
174
-	$align = preg_replace(',\W,', '', $align);
175
-
176
-	return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')';
161
+    $code = "quete_logo('$id_objet', '" .
162
+        (($suite == '_SURVOL') ? 'off' :
163
+            (($suite == '_NORMAL') ? 'on' : 'ON')) .
164
+        "', $_id_objet," .
165
+        (($suite == '_RUBRIQUE') ?
166
+            champ_sql('id_rubrique', $p) :
167
+            (($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) .
168
+        ', ' . intval($fichier) . ')';
169
+
170
+    if ($fichier) {
171
+        return $code;
172
+    }
173
+
174
+    $align = preg_replace(',\W,', '', $align);
175
+
176
+    return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')';
177 177
 }
Please login to merge, or discard this patch.
ecrire/balise/url_logout.php 1 patch
Indentation   +8 added lines, -8 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
 /**
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
  *     Pile complétée du code compilé
37 37
  **/
38 38
 function balise_URL_LOGOUT($p) {
39
-	return calculer_balise_dynamique($p, 'URL_LOGOUT', []);
39
+    return calculer_balise_dynamique($p, 'URL_LOGOUT', []);
40 40
 }
41 41
 
42 42
 
@@ -52,9 +52,9 @@  discard block
 block discarded – undo
52 52
  *   Liste (url) des arguments collectés.
53 53
  */
54 54
 function balise_URL_LOGOUT_stat($args, $context_compil) {
55
-	$url = $args[0] ?? '';
55
+    $url = $args[0] ?? '';
56 56
 
57
-	return [$url];
57
+    return [$url];
58 58
 }
59 59
 
60 60
 /**
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
  **/
70 70
 function balise_URL_LOGOUT_dyn($cible) {
71 71
 
72
-	if (empty($GLOBALS['visiteur_session']['login']) and empty($GLOBALS['visiteur_session']['statut'])) {
73
-		return '';
74
-	}
72
+    if (empty($GLOBALS['visiteur_session']['login']) and empty($GLOBALS['visiteur_session']['statut'])) {
73
+        return '';
74
+    }
75 75
 
76
-	return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&')));
76
+    return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&')));
77 77
 }
Please login to merge, or discard this patch.
ecrire/balise/formulaire_inscription.php 1 patch
Indentation   +6 added lines, -6 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
 include_spip('base/abstract_sql');
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
  *     Pile complétée du code compilé
44 44
  **/
45 45
 function balise_FORMULAIRE_INSCRIPTION($p) {
46
-	return calculer_balise_dynamique($p, 'FORMULAIRE_INSCRIPTION', []);
46
+    return calculer_balise_dynamique($p, 'FORMULAIRE_INSCRIPTION', []);
47 47
 }
48 48
 
49 49
 /**
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
  *   - chaîne vide sinon.
73 73
  */
74 74
 function balise_FORMULAIRE_INSCRIPTION_stat($args, $context_compil) {
75
-	[$mode, $id, $retour] = array_pad($args, 3, null);
76
-	include_spip('action/inscrire_auteur');
77
-	$mode = tester_statut_inscription($mode, $id ?? 0);
75
+    [$mode, $id, $retour] = array_pad($args, 3, null);
76
+    include_spip('action/inscrire_auteur');
77
+    $mode = tester_statut_inscription($mode, $id ?? 0);
78 78
 
79
-	return $mode ? [$mode, $id, $retour] : '';
79
+    return $mode ? [$mode, $id, $retour] : '';
80 80
 }
Please login to merge, or discard this patch.
ecrire/public/jointures.php 1 patch
Indentation   +401 added lines, -401 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
 
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
  *     Chaine sinon : le nom du champ (non décomposable donc)
34 34
  */
35 35
 function decompose_champ_id_objet($champ) {
36
-	if (($champ !== 'id_objet') and preg_match(',^id_([a-z_]+)$,', $champ, $regs)) {
37
-		return ['id_objet', 'objet', objet_type($champ)];
38
-	}
36
+    if (($champ !== 'id_objet') and preg_match(',^id_([a-z_]+)$,', $champ, $regs)) {
37
+        return ['id_objet', 'objet', objet_type($champ)];
38
+    }
39 39
 
40
-	return $champ;
40
+    return $champ;
41 41
 }
42 42
 
43 43
 /**
@@ -56,21 +56,21 @@  discard block
 block discarded – undo
56 56
  *     - array(id_objet, objet), si le champ n'existe pas mais qu'on peut décomposer
57 57
  */
58 58
 function trouver_champs_decomposes($champ, $desc) {
59
-	if (
60
-		!is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table
61
-		or array_key_exists($champ, $desc['field'])
62
-	) {
63
-		return [$champ];
64
-	}
65
-	// si le champ se décompose, tester que les colonnes décomposées sont présentes
66
-	if (is_array($decompose = decompose_champ_id_objet($champ))) {
67
-		array_pop($decompose);
68
-		if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) {
69
-			return $decompose;
70
-		}
71
-	}
72
-
73
-	return [$champ];
59
+    if (
60
+        !is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table
61
+        or array_key_exists($champ, $desc['field'])
62
+    ) {
63
+        return [$champ];
64
+    }
65
+    // si le champ se décompose, tester que les colonnes décomposées sont présentes
66
+    if (is_array($decompose = decompose_champ_id_objet($champ))) {
67
+        array_pop($decompose);
68
+        if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) {
69
+            return $decompose;
70
+        }
71
+    }
72
+
73
+    return [$champ];
74 74
 }
75 75
 
76 76
 
@@ -100,23 +100,23 @@  discard block
 block discarded – undo
100 100
  *     Alias de la table de jointure (Lx)
101 101
  */
102 102
 function calculer_jointure(&$boucle, $depart, $arrivee, $col = '', $cond = false, $max_liens = 5) {
103
-	// les jointures minimales sont optimales :
104
-	// on contraint le nombre d'etapes en l'augmentant
105
-	// jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi
106
-	$max = 1;
107
-	$res = false;
108
-	$milieu_exclus = ($col ?: []);
109
-	while ($max <= $max_liens and !$res) {
110
-		$res = calculer_chaine_jointures($boucle, $depart, $arrivee, [], $milieu_exclus, $max);
111
-		$max++;
112
-	}
113
-	if (!$res) {
114
-		return '';
115
-	}
116
-
117
-	[$nom, $desc] = $depart;
118
-
119
-	return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col);
103
+    // les jointures minimales sont optimales :
104
+    // on contraint le nombre d'etapes en l'augmentant
105
+    // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi
106
+    $max = 1;
107
+    $res = false;
108
+    $milieu_exclus = ($col ?: []);
109
+    while ($max <= $max_liens and !$res) {
110
+        $res = calculer_chaine_jointures($boucle, $depart, $arrivee, [], $milieu_exclus, $max);
111
+        $max++;
112
+    }
113
+    if (!$res) {
114
+        return '';
115
+    }
116
+
117
+    [$nom, $desc] = $depart;
118
+
119
+    return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col);
120 120
 }
121 121
 
122 122
 /**
@@ -155,82 +155,82 @@  discard block
 block discarded – undo
155 155
  *     Alias de la table de jointure (Lx)
156 156
  */
157 157
 function fabrique_jointures(&$boucle, $res, $cond = false, $desc = [], $nom = '', $col = '', $echap = true) {
158
-	$a = [];
159
-	$j = null;
160
-	$n = null;
161
-	static $num = [];
162
-	$id_table = '';
163
-	$cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle];
164
-	foreach ($res as $cle => $r) {
165
-		[$d, $a, $j] = $r;
166
-		if (!$id_table) {
167
-			$id_table = $d;
168
-		}
169
-		$n = ++$cpt;
170
-		if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article'
171
-			[$j1, $j2, $obj, $type] = $j;
172
-			// trouver de quel cote est (id_objet,objet)
173
-			if ($j1 == "id_$obj") {
174
-				$obj = "$id_table.$obj";
175
-			} else {
176
-				$obj = "L$n.$obj";
177
-			}
178
-			// le where complementaire est envoye dans la jointure et dans le where
179
-			// on utilise une clé qui le relie a la jointure pour que l'optimiseur
180
-			// sache qu'il peut enlever ce where si il enleve la jointure
181
-			$boucle->where["JOIN-L$n"] =
182
-				$echap ?
183
-					["'='","'$obj'","sql_quote('$type')"]
184
-					:
185
-					['=',"$obj",sql_quote($type)];
186
-			$boucle->join["L$n"] =
187
-				$echap ?
188
-					["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"]
189
-					:
190
-					[$id_table, $j2, $j1, "$obj=" . sql_quote($type)];
191
-		} else {
192
-			$boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j];
193
-		}
194
-		$boucle->from[$id_table = "L$n"] = $a[0];
195
-	}
196
-
197
-
198
-	// pas besoin de group by
199
-	// (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555)
200
-	// si une seule jointure et sur une table avec primary key formee
201
-	// de l'index principal et de l'index de jointure (non conditionnel! [6031])
202
-	// et operateur d'egalite (https://core.spip.net/issues/477)
203
-
204
-	if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) {
205
-		$pk = nogroupby_if($desc, $a[1], $col);
206
-	}
207
-
208
-	// pas de group by
209
-	// si une seule jointure
210
-	// et si l'index de jointure est une primary key a l'arrivee !
211
-	if (
212
-		!$pk
213
-		and (count($boucle->from) == 2)
214
-		and isset($a[1]['key']['PRIMARY KEY'])
215
-		and ($j == $a[1]['key']['PRIMARY KEY'])
216
-	) {
217
-		$pk = true;
218
-	}
219
-
220
-	// la clause Group by est en conflit avec ORDER BY, a completer
221
-	$groups = liste_champs_jointures($nom, $desc, true);
222
-	if (!$pk) {
223
-		foreach ($groups as $id_prim) {
224
-			$id_field = $nom . '.' . $id_prim;
225
-			if (!in_array($id_field, $boucle->group)) {
226
-				$boucle->group[] = $id_field;
227
-			}
228
-		}
229
-	}
230
-
231
-	$boucle->modificateur['lien'] = true;
232
-
233
-	return "L$n";
158
+    $a = [];
159
+    $j = null;
160
+    $n = null;
161
+    static $num = [];
162
+    $id_table = '';
163
+    $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle];
164
+    foreach ($res as $cle => $r) {
165
+        [$d, $a, $j] = $r;
166
+        if (!$id_table) {
167
+            $id_table = $d;
168
+        }
169
+        $n = ++$cpt;
170
+        if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article'
171
+            [$j1, $j2, $obj, $type] = $j;
172
+            // trouver de quel cote est (id_objet,objet)
173
+            if ($j1 == "id_$obj") {
174
+                $obj = "$id_table.$obj";
175
+            } else {
176
+                $obj = "L$n.$obj";
177
+            }
178
+            // le where complementaire est envoye dans la jointure et dans le where
179
+            // on utilise une clé qui le relie a la jointure pour que l'optimiseur
180
+            // sache qu'il peut enlever ce where si il enleve la jointure
181
+            $boucle->where["JOIN-L$n"] =
182
+                $echap ?
183
+                    ["'='","'$obj'","sql_quote('$type')"]
184
+                    :
185
+                    ['=',"$obj",sql_quote($type)];
186
+            $boucle->join["L$n"] =
187
+                $echap ?
188
+                    ["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"]
189
+                    :
190
+                    [$id_table, $j2, $j1, "$obj=" . sql_quote($type)];
191
+        } else {
192
+            $boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j];
193
+        }
194
+        $boucle->from[$id_table = "L$n"] = $a[0];
195
+    }
196
+
197
+
198
+    // pas besoin de group by
199
+    // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555)
200
+    // si une seule jointure et sur une table avec primary key formee
201
+    // de l'index principal et de l'index de jointure (non conditionnel! [6031])
202
+    // et operateur d'egalite (https://core.spip.net/issues/477)
203
+
204
+    if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) {
205
+        $pk = nogroupby_if($desc, $a[1], $col);
206
+    }
207
+
208
+    // pas de group by
209
+    // si une seule jointure
210
+    // et si l'index de jointure est une primary key a l'arrivee !
211
+    if (
212
+        !$pk
213
+        and (count($boucle->from) == 2)
214
+        and isset($a[1]['key']['PRIMARY KEY'])
215
+        and ($j == $a[1]['key']['PRIMARY KEY'])
216
+    ) {
217
+        $pk = true;
218
+    }
219
+
220
+    // la clause Group by est en conflit avec ORDER BY, a completer
221
+    $groups = liste_champs_jointures($nom, $desc, true);
222
+    if (!$pk) {
223
+        foreach ($groups as $id_prim) {
224
+            $id_field = $nom . '.' . $id_prim;
225
+            if (!in_array($id_field, $boucle->group)) {
226
+                $boucle->group[] = $id_field;
227
+            }
228
+        }
229
+    }
230
+
231
+    $boucle->modificateur['lien'] = true;
232
+
233
+    return "L$n";
234 234
 }
235 235
 
236 236
 /**
@@ -245,19 +245,19 @@  discard block
 block discarded – undo
245 245
  * @return bool
246 246
  */
247 247
 function nogroupby_if($depart, $arrivee, $col) {
248
-	if (
249
-		empty($arrivee['key']['PRIMARY KEY'])
250
-		or !($pk = $arrivee['key']['PRIMARY KEY'])
251
-		or empty($depart['key']['PRIMARY KEY'])
252
-	) {
253
-		return false;
254
-	}
255
-	$id_primary = $depart['key']['PRIMARY KEY'];
256
-	if (is_array($col)) {
257
-		$col = implode(', *', $col);
258
-	} // cas id_objet, objet
259
-	return (preg_match("/^$id_primary, *$col$/", $pk) or
260
-		preg_match("/^$col, *$id_primary$/", $pk));
248
+    if (
249
+        empty($arrivee['key']['PRIMARY KEY'])
250
+        or !($pk = $arrivee['key']['PRIMARY KEY'])
251
+        or empty($depart['key']['PRIMARY KEY'])
252
+    ) {
253
+        return false;
254
+    }
255
+    $id_primary = $depart['key']['PRIMARY KEY'];
256
+    if (is_array($col)) {
257
+        $col = implode(', *', $col);
258
+    } // cas id_objet, objet
259
+    return (preg_match("/^$id_primary, *$col$/", $pk) or
260
+        preg_match("/^$col, *$id_primary$/", $pk));
261 261
 }
262 262
 
263 263
 /**
@@ -275,46 +275,46 @@  discard block
 block discarded – undo
275 275
  */
276 276
 function liste_champs_jointures($nom, $desc, $primary = false) {
277 277
 
278
-	static $nojoin = ['idx', 'maj', 'date', 'statut'];
278
+    static $nojoin = ['idx', 'maj', 'date', 'statut'];
279 279
 
280
-	// si cle primaire demandee, la privilegier
281
-	if ($primary && isset($desc['key']['PRIMARY KEY'])) {
282
-		return split_key($desc['key']['PRIMARY KEY']);
283
-	}
280
+    // si cle primaire demandee, la privilegier
281
+    if ($primary && isset($desc['key']['PRIMARY KEY'])) {
282
+        return split_key($desc['key']['PRIMARY KEY']);
283
+    }
284 284
 
285
-	// les champs declares explicitement pour les jointures
286
-	if (isset($desc['join'])) {
287
-		return $desc['join'];
288
-	}
289
-	/*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join'];
285
+    // les champs declares explicitement pour les jointures
286
+    if (isset($desc['join'])) {
287
+        return $desc['join'];
288
+    }
289
+    /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join'];
290 290
 	elseif (isset($GLOBALS['tables_auxiliaires'][$nom]['join'])) return $GLOBALS['tables_auxiliaires'][$nom]['join'];*/
291 291
 
292
-	// si pas de cle, c'est fichu
293
-	if (!isset($desc['key'])) {
294
-		return [];
295
-	}
296
-
297
-	// si cle primaire
298
-	if (isset($desc['key']['PRIMARY KEY'])) {
299
-		return split_key($desc['key']['PRIMARY KEY']);
300
-	}
301
-
302
-	// ici on se rabat sur les cles secondaires,
303
-	// en eliminant celles qui sont pas pertinentes (idx, maj)
304
-	// si jamais le resultat n'est pas pertinent pour une table donnee,
305
-	// il faut declarer explicitement le champ 'join' de sa description
306
-
307
-	$join = [];
308
-	foreach ($desc['key'] as $v) {
309
-		$join = split_key($v, $join);
310
-	}
311
-	foreach ($join as $k) {
312
-		if (in_array($k, $nojoin)) {
313
-			unset($join[$k]);
314
-		}
315
-	}
316
-
317
-	return $join;
292
+    // si pas de cle, c'est fichu
293
+    if (!isset($desc['key'])) {
294
+        return [];
295
+    }
296
+
297
+    // si cle primaire
298
+    if (isset($desc['key']['PRIMARY KEY'])) {
299
+        return split_key($desc['key']['PRIMARY KEY']);
300
+    }
301
+
302
+    // ici on se rabat sur les cles secondaires,
303
+    // en eliminant celles qui sont pas pertinentes (idx, maj)
304
+    // si jamais le resultat n'est pas pertinent pour une table donnee,
305
+    // il faut declarer explicitement le champ 'join' de sa description
306
+
307
+    $join = [];
308
+    foreach ($desc['key'] as $v) {
309
+        $join = split_key($v, $join);
310
+    }
311
+    foreach ($join as $k) {
312
+        if (in_array($k, $nojoin)) {
313
+            unset($join[$k]);
314
+        }
315
+    }
316
+
317
+    return $join;
318 318
 }
319 319
 
320 320
 /**
@@ -325,14 +325,14 @@  discard block
 block discarded – undo
325 325
  * @return array
326 326
  */
327 327
 function split_key($v, $join = []) {
328
-	foreach (preg_split('/,\s*/', $v) as $k) {
329
-		if (strpos($k, '(') !== false) {
330
-			$k = explode('(', $k);
331
-			$k = trim(reset($k));
332
-		}
333
-		$join[$k] = $k;
334
-	}
335
-	return $join;
328
+    foreach (preg_split('/,\s*/', $v) as $k) {
329
+        if (strpos($k, '(') !== false) {
330
+            $k = explode('(', $k);
331
+            $k = trim(reset($k));
332
+        }
333
+        $join[$k] = $k;
334
+    }
335
+    return $join;
336 336
 }
337 337
 
338 338
 /**
@@ -355,135 +355,135 @@  discard block
 block discarded – undo
355 355
  * @return array
356 356
  */
357 357
 function calculer_chaine_jointures(
358
-	&$boucle,
359
-	$depart,
360
-	$arrivee,
361
-	$vu = [],
362
-	$milieu_exclus = [],
363
-	$max_liens = 5
358
+    &$boucle,
359
+    $depart,
360
+    $arrivee,
361
+    $vu = [],
362
+    $milieu_exclus = [],
363
+    $max_liens = 5
364 364
 ) {
365
-	static $trouver_table;
366
-	if (!$trouver_table) {
367
-		$trouver_table = charger_fonction('trouver_table', 'base');
368
-	}
369
-
370
-	if (is_string($milieu_exclus)) {
371
-		$milieu_exclus = [$milieu_exclus];
372
-	}
373
-	// quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet
374
-	// faire une jointure sur objet tout seul n'a pas de sens
375
-	if (in_array('id_objet', $milieu_exclus) and !in_array('objet', $milieu_exclus)) {
376
-		$milieu_exclus[] = 'objet';
377
-	}
378
-
379
-	[$dnom, $ddesc] = $depart;
380
-	[$anom, $adesc] = $arrivee;
381
-	if (!count($vu)) {
382
-		$vu[] = $dnom; // ne pas oublier la table de depart
383
-		$vu[] = $anom; // ne pas oublier la table d'arrivee
384
-	}
385
-
386
-	$akeys = [];
387
-	foreach ($adesc['key'] as $k) {
388
-		// respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres...
389
-		$akeys = array_merge($akeys, preg_split('/,\s*/', $k));
390
-	}
391
-
392
-	// enlever les cles d'arrivee exclues par l'appel
393
-	$akeys = array_diff($akeys, $milieu_exclus);
394
-
395
-	// cles candidates au depart
396
-	$keys = liste_champs_jointures($dnom, $ddesc);
397
-	// enlever les cles dde depart exclues par l'appel
398
-	$keys = array_diff($keys, $milieu_exclus);
399
-
400
-	$v = !$keys ? false : array_intersect(array_values($keys), $akeys);
401
-
402
-	if ($v) {
403
-		return [[$dnom, [$adesc['table'], $adesc], array_shift($v)]];
404
-	}
405
-
406
-	// regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx
407
-	if (count(array_intersect(['id_objet', 'objet'], $keys)) == 2) {
408
-		// regarder si l'une des cles d'arrivee peut se decomposer en
409
-		// id_objet,objet
410
-		// si oui on la prend
411
-		foreach ($akeys as $key) {
412
-			$v = decompose_champ_id_objet($key);
413
-			if (is_array($v)) {
414
-				$objet = array_shift($v); // objet,'article'
415
-				array_unshift($v, $key); // id_article,objet,'article'
416
-				array_unshift($v, $objet); // id_objet,id_article,objet,'article'
417
-				return [[$dnom, [$adesc['table'], $adesc], $v]];
418
-			}
419
-		}
420
-	} else {
421
-		// regarder si l'une des cles de depart peut se decomposer en
422
-		// id_objet,objet a l'arrivee
423
-		// si oui on la prend
424
-		foreach ($keys as $key) {
425
-			if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) {
426
-				if (count($v) == count(array_intersect($v, $akeys))) {
427
-					$v = decompose_champ_id_objet($key); // id_objet,objet,'article'
428
-					array_unshift($v, $key); // id_article,id_objet,objet,'article'
429
-					return [[$dnom, [$adesc['table'], $adesc], $v]];
430
-				}
431
-			}
432
-		}
433
-	}
434
-	// si l'on voulait une jointure direct, c'est rate !
435
-	if ($max_liens <= 1) {
436
-		return [];
437
-	}
438
-
439
-	// sinon essayer de passer par une autre table
440
-	$new = $vu;
441
-	foreach ($boucle->jointures as $v) {
442
-		if (
443
-			$v
444
-			and !in_array($v, $vu)
445
-			and $def = $trouver_table($v, $boucle->sql_serveur)
446
-			and !in_array($def['table_sql'], $vu)
447
-		) {
448
-			// ne pas tester les cles qui sont exclues a l'appel
449
-			// ie la cle de la jointure precedente
450
-			$test_cles = $milieu_exclus;
451
-			$new[] = $v;
452
-			$max_iter = 50; // securite
453
-			while (
454
-				count($jointure_directe_possible = calculer_chaine_jointures(
455
-					$boucle,
456
-					$depart,
457
-					[$v, $def],
458
-					$vu,
459
-					$test_cles,
460
-					1
461
-				))
462
-				and $max_iter--
463
-			) {
464
-				$jointure_directe_possible = reset($jointure_directe_possible);
465
-				$milieu = end($jointure_directe_possible);
466
-				$exclure_fin = $milieu_exclus;
467
-				if (is_string($milieu)) {
468
-					$exclure_fin[] = $milieu;
469
-					$test_cles[] = $milieu;
470
-				} else {
471
-					$exclure_fin = array_merge($exclure_fin, $milieu);
472
-					$test_cles = array_merge($test_cles, $milieu);
473
-				}
474
-				// essayer de rejoindre l'arrivee a partir de cette etape intermediaire
475
-				// sans repasser par la meme cle milieu, ni une cle deja vue !
476
-				$r = calculer_chaine_jointures($boucle, [$v, $def], $arrivee, $new, $exclure_fin, $max_liens - 1);
477
-				if ($r) {
478
-					array_unshift($r, $jointure_directe_possible);
479
-
480
-					return $r;
481
-				}
482
-			}
483
-		}
484
-	}
485
-
486
-	return [];
365
+    static $trouver_table;
366
+    if (!$trouver_table) {
367
+        $trouver_table = charger_fonction('trouver_table', 'base');
368
+    }
369
+
370
+    if (is_string($milieu_exclus)) {
371
+        $milieu_exclus = [$milieu_exclus];
372
+    }
373
+    // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet
374
+    // faire une jointure sur objet tout seul n'a pas de sens
375
+    if (in_array('id_objet', $milieu_exclus) and !in_array('objet', $milieu_exclus)) {
376
+        $milieu_exclus[] = 'objet';
377
+    }
378
+
379
+    [$dnom, $ddesc] = $depart;
380
+    [$anom, $adesc] = $arrivee;
381
+    if (!count($vu)) {
382
+        $vu[] = $dnom; // ne pas oublier la table de depart
383
+        $vu[] = $anom; // ne pas oublier la table d'arrivee
384
+    }
385
+
386
+    $akeys = [];
387
+    foreach ($adesc['key'] as $k) {
388
+        // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres...
389
+        $akeys = array_merge($akeys, preg_split('/,\s*/', $k));
390
+    }
391
+
392
+    // enlever les cles d'arrivee exclues par l'appel
393
+    $akeys = array_diff($akeys, $milieu_exclus);
394
+
395
+    // cles candidates au depart
396
+    $keys = liste_champs_jointures($dnom, $ddesc);
397
+    // enlever les cles dde depart exclues par l'appel
398
+    $keys = array_diff($keys, $milieu_exclus);
399
+
400
+    $v = !$keys ? false : array_intersect(array_values($keys), $akeys);
401
+
402
+    if ($v) {
403
+        return [[$dnom, [$adesc['table'], $adesc], array_shift($v)]];
404
+    }
405
+
406
+    // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx
407
+    if (count(array_intersect(['id_objet', 'objet'], $keys)) == 2) {
408
+        // regarder si l'une des cles d'arrivee peut se decomposer en
409
+        // id_objet,objet
410
+        // si oui on la prend
411
+        foreach ($akeys as $key) {
412
+            $v = decompose_champ_id_objet($key);
413
+            if (is_array($v)) {
414
+                $objet = array_shift($v); // objet,'article'
415
+                array_unshift($v, $key); // id_article,objet,'article'
416
+                array_unshift($v, $objet); // id_objet,id_article,objet,'article'
417
+                return [[$dnom, [$adesc['table'], $adesc], $v]];
418
+            }
419
+        }
420
+    } else {
421
+        // regarder si l'une des cles de depart peut se decomposer en
422
+        // id_objet,objet a l'arrivee
423
+        // si oui on la prend
424
+        foreach ($keys as $key) {
425
+            if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) {
426
+                if (count($v) == count(array_intersect($v, $akeys))) {
427
+                    $v = decompose_champ_id_objet($key); // id_objet,objet,'article'
428
+                    array_unshift($v, $key); // id_article,id_objet,objet,'article'
429
+                    return [[$dnom, [$adesc['table'], $adesc], $v]];
430
+                }
431
+            }
432
+        }
433
+    }
434
+    // si l'on voulait une jointure direct, c'est rate !
435
+    if ($max_liens <= 1) {
436
+        return [];
437
+    }
438
+
439
+    // sinon essayer de passer par une autre table
440
+    $new = $vu;
441
+    foreach ($boucle->jointures as $v) {
442
+        if (
443
+            $v
444
+            and !in_array($v, $vu)
445
+            and $def = $trouver_table($v, $boucle->sql_serveur)
446
+            and !in_array($def['table_sql'], $vu)
447
+        ) {
448
+            // ne pas tester les cles qui sont exclues a l'appel
449
+            // ie la cle de la jointure precedente
450
+            $test_cles = $milieu_exclus;
451
+            $new[] = $v;
452
+            $max_iter = 50; // securite
453
+            while (
454
+                count($jointure_directe_possible = calculer_chaine_jointures(
455
+                    $boucle,
456
+                    $depart,
457
+                    [$v, $def],
458
+                    $vu,
459
+                    $test_cles,
460
+                    1
461
+                ))
462
+                and $max_iter--
463
+            ) {
464
+                $jointure_directe_possible = reset($jointure_directe_possible);
465
+                $milieu = end($jointure_directe_possible);
466
+                $exclure_fin = $milieu_exclus;
467
+                if (is_string($milieu)) {
468
+                    $exclure_fin[] = $milieu;
469
+                    $test_cles[] = $milieu;
470
+                } else {
471
+                    $exclure_fin = array_merge($exclure_fin, $milieu);
472
+                    $test_cles = array_merge($test_cles, $milieu);
473
+                }
474
+                // essayer de rejoindre l'arrivee a partir de cette etape intermediaire
475
+                // sans repasser par la meme cle milieu, ni une cle deja vue !
476
+                $r = calculer_chaine_jointures($boucle, [$v, $def], $arrivee, $new, $exclure_fin, $max_liens - 1);
477
+                if ($r) {
478
+                    array_unshift($r, $jointure_directe_possible);
479
+
480
+                    return $r;
481
+                }
482
+            }
483
+        }
484
+    }
485
+
486
+    return [];
487 487
 }
488 488
 
489 489
 /**
@@ -494,18 +494,18 @@  discard block
 block discarded – undo
494 494
  * @return array
495 495
  */
496 496
 function trouver_cles_table($keys) {
497
-	$res = [];
498
-	foreach ($keys as $v) {
499
-		if (!strpos($v, ',')) {
500
-			$res[$v] = 1;
501
-		} else {
502
-			foreach (preg_split('/\s*,\s*/', $v) as $k) {
503
-				$res[$k] = 1;
504
-			}
505
-		}
506
-	}
507
-
508
-	return array_keys($res);
497
+    $res = [];
498
+    foreach ($keys as $v) {
499
+        if (!strpos($v, ',')) {
500
+            $res[$v] = 1;
501
+        } else {
502
+            foreach (preg_split('/\s*,\s*/', $v) as $k) {
503
+                $res[$k] = 1;
504
+            }
505
+        }
506
+    }
507
+
508
+    return array_keys($res);
509 509
 }
510 510
 
511 511
 
@@ -532,34 +532,34 @@  discard block
 block discarded – undo
532 532
  *     - 'alias' : alias utilisé pour la table (si pertinent. ie: avec `$boucle->from` transmis par exemple)
533 533
  */
534 534
 function chercher_champ_dans_tables($cle, $tables, $connect, $checkarrivee = false) {
535
-	static $trouver_table = '';
536
-	if (!$trouver_table) {
537
-		$trouver_table = charger_fonction('trouver_table', 'base');
538
-	}
539
-
540
-	if (!is_array($cle)) {
541
-		$cle = [$cle];
542
-	}
543
-
544
-	foreach ($tables as $k => $table) {
545
-		if ($table && $desc = $trouver_table($table, $connect)) {
546
-			if (
547
-				isset($desc['field'])
548
-				// verifier que toutes les cles cherchees sont la
549
-				and (count(array_intersect($cle, array_keys($desc['field']))) == count($cle))
550
-				// si on sait ou on veut arriver, il faut que ca colle
551
-				and ($checkarrivee == false || $checkarrivee == $desc['table'])
552
-			) {
553
-				return [
554
-					'desc' => $desc,
555
-					'table' => $desc['table'],
556
-					'alias' => $k,
557
-				];
558
-			}
559
-		}
560
-	}
561
-
562
-	return false;
535
+    static $trouver_table = '';
536
+    if (!$trouver_table) {
537
+        $trouver_table = charger_fonction('trouver_table', 'base');
538
+    }
539
+
540
+    if (!is_array($cle)) {
541
+        $cle = [$cle];
542
+    }
543
+
544
+    foreach ($tables as $k => $table) {
545
+        if ($table && $desc = $trouver_table($table, $connect)) {
546
+            if (
547
+                isset($desc['field'])
548
+                // verifier que toutes les cles cherchees sont la
549
+                and (count(array_intersect($cle, array_keys($desc['field']))) == count($cle))
550
+                // si on sait ou on veut arriver, il faut que ca colle
551
+                and ($checkarrivee == false || $checkarrivee == $desc['table'])
552
+            ) {
553
+                return [
554
+                    'desc' => $desc,
555
+                    'table' => $desc['table'],
556
+                    'alias' => $k,
557
+                ];
558
+            }
559
+        }
560
+    }
561
+
562
+    return false;
563 563
 }
564 564
 
565 565
 /**
@@ -585,52 +585,52 @@  discard block
 block discarded – undo
585 585
  */
586 586
 function trouver_champ_exterieur($cle, $joints, &$boucle, $checkarrivee = false) {
587 587
 
588
-	// support de la recherche multi champ :
589
-	// si en seconde etape on a decompose le champ id_xx en id_objet,objet
590
-	// on reentre ici soit en cherchant une table les 2 champs id_objet,objet
591
-	// soit une table avec les 3 champs id_xx, id_objet, objet
592
-	if (!is_array($cle)) {
593
-		$cle = [$cle];
594
-	}
595
-
596
-	if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) {
597
-		return [$infos['table'], $infos['desc'], $cle];
598
-	}
599
-
600
-	// au premier coup, on essaye de decomposer, si possible
601
-	if (
602
-		count($cle) == 1
603
-		and $c = reset($cle)
604
-		and is_array($decompose = decompose_champ_id_objet($c))
605
-	) {
606
-		$desc = $boucle->show;
607
-
608
-		// cas 1 : la cle id_xx est dans la table de depart
609
-		// -> on cherche uniquement id_objet,objet a l'arrivee
610
-		if (isset($desc['field'][$c])) {
611
-			$cle = [];
612
-			$cle[] = array_shift($decompose); // id_objet
613
-			$cle[] = array_shift($decompose); // objet
614
-			return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee);
615
-		}
616
-		// cas 2 : la cle id_xx n'est pas dans la table de depart
617
-		// -> il faut trouver une cle de depart zzz telle que
618
-		// id_objet,objet,zzz soit a l'arrivee
619
-		else {
620
-			$depart = liste_champs_jointures(($desc['table'] ?? ''), $desc);
621
-			foreach ($depart as $d) {
622
-				$cle = [];
623
-				$cle[] = array_shift($decompose); // id_objet
624
-				$cle[] = array_shift($decompose); // objet
625
-				$cle[] = $d;
626
-				if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) {
627
-					return $ext;
628
-				}
629
-			}
630
-		}
631
-	}
632
-
633
-	return '';
588
+    // support de la recherche multi champ :
589
+    // si en seconde etape on a decompose le champ id_xx en id_objet,objet
590
+    // on reentre ici soit en cherchant une table les 2 champs id_objet,objet
591
+    // soit une table avec les 3 champs id_xx, id_objet, objet
592
+    if (!is_array($cle)) {
593
+        $cle = [$cle];
594
+    }
595
+
596
+    if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) {
597
+        return [$infos['table'], $infos['desc'], $cle];
598
+    }
599
+
600
+    // au premier coup, on essaye de decomposer, si possible
601
+    if (
602
+        count($cle) == 1
603
+        and $c = reset($cle)
604
+        and is_array($decompose = decompose_champ_id_objet($c))
605
+    ) {
606
+        $desc = $boucle->show;
607
+
608
+        // cas 1 : la cle id_xx est dans la table de depart
609
+        // -> on cherche uniquement id_objet,objet a l'arrivee
610
+        if (isset($desc['field'][$c])) {
611
+            $cle = [];
612
+            $cle[] = array_shift($decompose); // id_objet
613
+            $cle[] = array_shift($decompose); // objet
614
+            return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee);
615
+        }
616
+        // cas 2 : la cle id_xx n'est pas dans la table de depart
617
+        // -> il faut trouver une cle de depart zzz telle que
618
+        // id_objet,objet,zzz soit a l'arrivee
619
+        else {
620
+            $depart = liste_champs_jointures(($desc['table'] ?? ''), $desc);
621
+            foreach ($depart as $d) {
622
+                $cle = [];
623
+                $cle[] = array_shift($decompose); // id_objet
624
+                $cle[] = array_shift($decompose); // objet
625
+                $cle[] = $d;
626
+                if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) {
627
+                    return $ext;
628
+                }
629
+            }
630
+        }
631
+    }
632
+
633
+    return '';
634 634
 }
635 635
 
636 636
 /**
@@ -662,21 +662,21 @@  discard block
 block discarded – undo
662 662
  * @return string
663 663
  */
664 664
 function trouver_jointure_champ($champ, &$boucle, $jointures = false, $cond = false, $checkarrivee = false) {
665
-	if ($jointures === false) {
666
-		$jointures = $boucle->jointures;
667
-	}
668
-	// TODO : aberration, on utilise $jointures pour trouver le champ
669
-	// mais pas poour construire la jointure ensuite
670
-	$arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee);
671
-	if ($arrivee) {
672
-		$desc = $boucle->show;
673
-		array_pop($arrivee); // enlever la cle en 3eme argument
674
-		$cle = calculer_jointure($boucle, [$desc['id_table'], $desc], $arrivee, '', $cond);
675
-		if ($cle) {
676
-			return $cle;
677
-		}
678
-	}
679
-	spip_log("trouver_jointure_champ: $champ inconnu");
680
-
681
-	return '';
665
+    if ($jointures === false) {
666
+        $jointures = $boucle->jointures;
667
+    }
668
+    // TODO : aberration, on utilise $jointures pour trouver le champ
669
+    // mais pas poour construire la jointure ensuite
670
+    $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee);
671
+    if ($arrivee) {
672
+        $desc = $boucle->show;
673
+        array_pop($arrivee); // enlever la cle en 3eme argument
674
+        $cle = calculer_jointure($boucle, [$desc['id_table'], $desc], $arrivee, '', $cond);
675
+        if ($cle) {
676
+            return $cle;
677
+        }
678
+    }
679
+    spip_log("trouver_jointure_champ: $champ inconnu");
680
+
681
+    return '';
682 682
 }
Please login to merge, or discard this patch.
ecrire/public/sandbox.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  **/
24 24
 
25 25
 if (!defined('_ECRIRE_INC_VERSION')) {
26
-	return;
26
+    return;
27 27
 }
28 28
 
29 29
 /**
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
  *     Texte
42 42
  */
43 43
 function sandbox_composer_texte($texte, &$p) {
44
-	$code = "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'";
44
+    $code = "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'";
45 45
 
46
-	return $code;
46
+    return $code;
47 47
 }
48 48
 
49 49
 
@@ -59,42 +59,42 @@  discard block
 block discarded – undo
59 59
  * @return string
60 60
  */
61 61
 function sandbox_composer_filtre($fonc, $code, $arglist, &$p, $nb_arg_droite = 1000): string {
62
-	if (isset($GLOBALS['spip_matrice'][$fonc])) {
63
-		$code = "filtrer('$fonc',$code$arglist)";
64
-	}
65
-
66
-	// le filtre est defini sous forme de fonction ou de methode
67
-	// par ex. dans inc_texte, inc_filtres ou mes_fonctions
68
-	elseif ($f = chercher_filtre($fonc)) {
69
-		// cas particulier : le filtre |set doit acceder a la $Pile
70
-		// proto: filtre_set(&$Pile, $val, $args...)
71
-		if (strpbrk($f, ':')) { // Class::method
72
-			$refl = new ReflectionMethod($f);
73
-		} else {
74
-			$refl = new ReflectionFunction($f);
75
-		}
76
-		$refs = $refl->getParameters();
77
-		if (isset($refs[0]) and $refs[0]->name == 'Pile') {
78
-			$code = "$f(\$Pile,$code$arglist)";
79
-			$nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile
80
-		} else {
81
-			$code = "$f($code$arglist)";
82
-			$nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre
83
-		}
84
-		$nb_args_f = $nb_arg_gauche + $nb_arg_droite;
85
-		$min_f = $refl->getNumberOfRequiredParameters();
86
-		if (($nb_args_f < $min_f)) {
87
-			$msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f];
88
-			erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p);
89
-		}
90
-	}
91
-	// le filtre n'existe pas,
92
-	// on le notifie
93
-	else {
94
-		erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p);
95
-	}
96
-
97
-	return $code;
62
+    if (isset($GLOBALS['spip_matrice'][$fonc])) {
63
+        $code = "filtrer('$fonc',$code$arglist)";
64
+    }
65
+
66
+    // le filtre est defini sous forme de fonction ou de methode
67
+    // par ex. dans inc_texte, inc_filtres ou mes_fonctions
68
+    elseif ($f = chercher_filtre($fonc)) {
69
+        // cas particulier : le filtre |set doit acceder a la $Pile
70
+        // proto: filtre_set(&$Pile, $val, $args...)
71
+        if (strpbrk($f, ':')) { // Class::method
72
+            $refl = new ReflectionMethod($f);
73
+        } else {
74
+            $refl = new ReflectionFunction($f);
75
+        }
76
+        $refs = $refl->getParameters();
77
+        if (isset($refs[0]) and $refs[0]->name == 'Pile') {
78
+            $code = "$f(\$Pile,$code$arglist)";
79
+            $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile
80
+        } else {
81
+            $code = "$f($code$arglist)";
82
+            $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre
83
+        }
84
+        $nb_args_f = $nb_arg_gauche + $nb_arg_droite;
85
+        $min_f = $refl->getNumberOfRequiredParameters();
86
+        if (($nb_args_f < $min_f)) {
87
+            $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f];
88
+            erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p);
89
+        }
90
+    }
91
+    // le filtre n'existe pas,
92
+    // on le notifie
93
+    else {
94
+        erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p);
95
+    }
96
+
97
+    return $code;
98 98
 }
99 99
 
100 100
 // Calculer un <INCLURE(xx.php)>
@@ -117,15 +117,15 @@  discard block
 block discarded – undo
117 117
  * @return string
118 118
  */
119 119
 function sandbox_composer_inclure_php($fichier, &$p, $_contexte) {
120
-	$compil = texte_script(memoriser_contexte_compil($p));
121
-	// si inexistant, on essaiera a l'execution
122
-	if ($path = find_in_path($fichier)) {
123
-		$path = "\"$path\"";
124
-	} else {
125
-		$path = "find_in_path(\"$fichier\")";
126
-	}
127
-
128
-	return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte);
120
+    $compil = texte_script(memoriser_contexte_compil($p));
121
+    // si inexistant, on essaiera a l'execution
122
+    if ($path = find_in_path($fichier)) {
123
+        $path = "\"$path\"";
124
+    } else {
125
+        $path = "find_in_path(\"$fichier\")";
126
+    }
127
+
128
+    return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte);
129 129
 }
130 130
 
131 131
 /**
@@ -137,20 +137,20 @@  discard block
 block discarded – undo
137 137
  * @return string
138 138
  */
139 139
 function sandbox_composer_interdire_scripts($code, &$p) {
140
-	// Securite
141
-	if (
142
-		$p->interdire_scripts
143
-		and $p->etoile != '**'
144
-	) {
145
-		if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) {
146
-			$code = "interdire_scripts($code)";
147
-		} else {
148
-			$code = interdire_scripts($r[2]);
149
-			$code = "sinon(interdire_scripts($r[1]),'$code')";
150
-		}
151
-	}
152
-
153
-	return $code;
140
+    // Securite
141
+    if (
142
+        $p->interdire_scripts
143
+        and $p->etoile != '**'
144
+    ) {
145
+        if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) {
146
+            $code = "interdire_scripts($code)";
147
+        } else {
148
+            $code = interdire_scripts($r[2]);
149
+            $code = "sinon(interdire_scripts($r[1]),'$code')";
150
+        }
151
+    }
152
+
153
+    return $code;
154 154
 }
155 155
 
156 156
 
@@ -169,30 +169,30 @@  discard block
 block discarded – undo
169 169
  * @return mixed|string
170 170
  */
171 171
 function sandbox_filtrer_squelette($skel, $corps, $filtres) {
172
-	$series_filtres = func_get_args();
173
-	array_shift($series_filtres);// skel
174
-	array_shift($series_filtres);// corps
175
-
176
-	// proteger les <INCLUDE> et tous les morceaux de php licites
177
-	if ($skel['process_ins'] == 'php') {
178
-		$corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps);
179
-	}
180
-
181
-	// recuperer les couples de remplacement
182
-	$replace = echapper_php_callback();
183
-
184
-	foreach ($series_filtres as $filtres) {
185
-		if (is_countable($filtres) ? count($filtres) : 0) {
186
-			foreach ($filtres as $filtre) {
187
-				if ($filtre and $f = chercher_filtre($filtre)) {
188
-					$corps = $f($corps);
189
-				}
190
-			}
191
-		}
192
-	}
193
-
194
-	// restaurer les echappements
195
-	return str_replace($replace[0], $replace[1], $corps);
172
+    $series_filtres = func_get_args();
173
+    array_shift($series_filtres);// skel
174
+    array_shift($series_filtres);// corps
175
+
176
+    // proteger les <INCLUDE> et tous les morceaux de php licites
177
+    if ($skel['process_ins'] == 'php') {
178
+        $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps);
179
+    }
180
+
181
+    // recuperer les couples de remplacement
182
+    $replace = echapper_php_callback();
183
+
184
+    foreach ($series_filtres as $filtres) {
185
+        if (is_countable($filtres) ? count($filtres) : 0) {
186
+            foreach ($filtres as $filtre) {
187
+                if ($filtre and $f = chercher_filtre($filtre)) {
188
+                    $corps = $f($corps);
189
+                }
190
+            }
191
+        }
192
+    }
193
+
194
+    // restaurer les echappements
195
+    return str_replace($replace[0], $replace[1], $corps);
196 196
 }
197 197
 
198 198
 
@@ -211,21 +211,21 @@  discard block
 block discarded – undo
211 211
  *     - array : Liste( liste des codes PHP, liste des substitutions )
212 212
  **/
213 213
 function echapper_php_callback($r = null) {
214
-	static $src = [];
215
-	static $dst = [];
214
+    static $src = [];
215
+    static $dst = [];
216 216
 
217
-	// si on recoit un tableau, on est en mode echappement
218
-	// on enregistre le code a echapper dans dst, et le code echappe dans src
219
-	if (is_array($r)) {
220
-		$dst[] = $r[0];
217
+    // si on recoit un tableau, on est en mode echappement
218
+    // on enregistre le code a echapper dans dst, et le code echappe dans src
219
+    if (is_array($r)) {
220
+        $dst[] = $r[0];
221 221
 
222
-		return $src[] = '___' . md5($r[0]) . '___';
223
-	}
222
+        return $src[] = '___' . md5($r[0]) . '___';
223
+    }
224 224
 
225
-	// si on recoit pas un tableau, on renvoit les couples de substitution
226
-	// et on RAZ les remplacements
227
-	$r = [$src, $dst];
228
-	$src = $dst = [];
225
+    // si on recoit pas un tableau, on renvoit les couples de substitution
226
+    // et on RAZ les remplacements
227
+    $r = [$src, $dst];
228
+    $src = $dst = [];
229 229
 
230
-	return $r;
230
+    return $r;
231 231
 }
Please login to merge, or discard this patch.
ecrire/public/decompiler.php 1 patch
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -11,129 +11,129 @@  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
 // Decompilation de l'arbre de syntaxe abstraite d'un squelette SPIP
18 18
 
19 19
 function decompiler_boucle($struct, $fmt = '', $prof = 0) {
20
-	$nom = $struct->id_boucle;
21
-	$preaff = decompiler_($struct->preaff, $fmt, $prof);
22
-	$avant = decompiler_($struct->avant, $fmt, $prof);
23
-	$apres = decompiler_($struct->apres, $fmt, $prof);
24
-	$altern = decompiler_($struct->altern, $fmt, $prof);
25
-	$milieu = decompiler_($struct->milieu, $fmt, $prof);
26
-	$postaff = decompiler_($struct->postaff, $fmt, $prof);
27
-
28
-	$type = $struct->sql_serveur ? "$struct->sql_serveur:" : '';
29
-	$type .= ($struct->type_requete ?: $struct->table_optionnelle);
30
-
31
-	if ($struct->jointures_explicites) {
32
-		$type .= ' ' . $struct->jointures_explicites;
33
-	}
34
-	if ($struct->table_optionnelle) {
35
-		$type .= '?';
36
-	}
37
-	// Revoir le cas de la boucle recursive
38
-
39
-	$crit = $struct->param;
40
-	if ($crit and !is_array($crit[0])) {
41
-		$type = strtolower($type) . array_shift($crit);
42
-	}
43
-	$crit = decompiler_criteres($struct, $fmt, $prof);
44
-
45
-	$f = 'format_boucle_' . $fmt;
46
-
47
-	return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof);
20
+    $nom = $struct->id_boucle;
21
+    $preaff = decompiler_($struct->preaff, $fmt, $prof);
22
+    $avant = decompiler_($struct->avant, $fmt, $prof);
23
+    $apres = decompiler_($struct->apres, $fmt, $prof);
24
+    $altern = decompiler_($struct->altern, $fmt, $prof);
25
+    $milieu = decompiler_($struct->milieu, $fmt, $prof);
26
+    $postaff = decompiler_($struct->postaff, $fmt, $prof);
27
+
28
+    $type = $struct->sql_serveur ? "$struct->sql_serveur:" : '';
29
+    $type .= ($struct->type_requete ?: $struct->table_optionnelle);
30
+
31
+    if ($struct->jointures_explicites) {
32
+        $type .= ' ' . $struct->jointures_explicites;
33
+    }
34
+    if ($struct->table_optionnelle) {
35
+        $type .= '?';
36
+    }
37
+    // Revoir le cas de la boucle recursive
38
+
39
+    $crit = $struct->param;
40
+    if ($crit and !is_array($crit[0])) {
41
+        $type = strtolower($type) . array_shift($crit);
42
+    }
43
+    $crit = decompiler_criteres($struct, $fmt, $prof);
44
+
45
+    $f = 'format_boucle_' . $fmt;
46
+
47
+    return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof);
48 48
 }
49 49
 
50 50
 function decompiler_include($struct, $fmt = '', $prof = 0) {
51
-	$res = [];
52
-	foreach ($struct->param ?: [] as $couple) {
53
-		array_shift($couple);
54
-		foreach ($couple as $v) {
55
-			$res[] = decompiler_($v, $fmt, $prof);
56
-		}
57
-	}
58
-	$file = is_string($struct->texte) ? $struct->texte :
59
-		decompiler_($struct->texte, $fmt, $prof);
60
-	$f = 'format_inclure_' . $fmt;
61
-
62
-	return $f($file, $res, $prof);
51
+    $res = [];
52
+    foreach ($struct->param ?: [] as $couple) {
53
+        array_shift($couple);
54
+        foreach ($couple as $v) {
55
+            $res[] = decompiler_($v, $fmt, $prof);
56
+        }
57
+    }
58
+    $file = is_string($struct->texte) ? $struct->texte :
59
+        decompiler_($struct->texte, $fmt, $prof);
60
+    $f = 'format_inclure_' . $fmt;
61
+
62
+    return $f($file, $res, $prof);
63 63
 }
64 64
 
65 65
 function decompiler_texte($struct, $fmt = '', $prof = 0) {
66
-	$f = 'format_texte_' . $fmt;
66
+    $f = 'format_texte_' . $fmt;
67 67
 
68
-	return strlen($struct->texte) ? $f($struct->texte, $prof) : '';
68
+    return strlen($struct->texte) ? $f($struct->texte, $prof) : '';
69 69
 }
70 70
 
71 71
 function decompiler_polyglotte($struct, $fmt = '', $prof = 0) {
72
-	$f = 'format_polyglotte_' . $fmt;
72
+    $f = 'format_polyglotte_' . $fmt;
73 73
 
74
-	return $f($struct->traductions, $prof);
74
+    return $f($struct->traductions, $prof);
75 75
 }
76 76
 
77 77
 function decompiler_idiome($struct, $fmt = '', $prof = 0) {
78
-	$args = [];
79
-	foreach ($struct->arg as $k => $v) {
80
-		$args[$k] = public_decompiler($v, $fmt, $prof);
81
-	}
78
+    $args = [];
79
+    foreach ($struct->arg as $k => $v) {
80
+        $args[$k] = public_decompiler($v, $fmt, $prof);
81
+    }
82 82
 
83
-	$filtres = decompiler_liste($struct->param, $fmt, $prof);
83
+    $filtres = decompiler_liste($struct->param, $fmt, $prof);
84 84
 
85
-	$f = 'format_idiome_' . $fmt;
85
+    $f = 'format_idiome_' . $fmt;
86 86
 
87
-	return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof);
87
+    return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof);
88 88
 }
89 89
 
90 90
 function decompiler_champ($struct, $fmt = '', $prof = 0) {
91
-	$avant = decompiler_($struct->avant, $fmt, $prof);
92
-	$apres = decompiler_($struct->apres, $fmt, $prof);
93
-	$args = $filtres = '';
94
-	if ($p = $struct->param) {
95
-		if ($p[0][0] === '') {
96
-			$args = decompiler_liste([array_shift($p)], $fmt, $prof);
97
-		}
98
-		$filtres = decompiler_liste($p, $fmt, $prof);
99
-	}
100
-	$f = 'format_champ_' . $fmt;
101
-
102
-	return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof);
91
+    $avant = decompiler_($struct->avant, $fmt, $prof);
92
+    $apres = decompiler_($struct->apres, $fmt, $prof);
93
+    $args = $filtres = '';
94
+    if ($p = $struct->param) {
95
+        if ($p[0][0] === '') {
96
+            $args = decompiler_liste([array_shift($p)], $fmt, $prof);
97
+        }
98
+        $filtres = decompiler_liste($p, $fmt, $prof);
99
+    }
100
+    $f = 'format_champ_' . $fmt;
101
+
102
+    return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof);
103 103
 }
104 104
 
105 105
 function decompiler_liste($sources, $fmt = '', $prof = 0) {
106
-	if (!is_array($sources)) {
107
-		return '';
108
-	}
109
-	$f = 'format_liste_' . $fmt;
110
-	$res = '';
111
-	foreach ($sources as $arg) {
112
-		if (!is_array($arg)) {
113
-			continue; // ne devrait pas arriver.
114
-		} else {
115
-			$r = array_shift($arg);
116
-		}
117
-		$args = [];
118
-		foreach ($arg as $v) {
119
-			// cas des arguments entoures de ' ou "
120
-			if (
121
-				((is_countable($v) ? count($v) : 0) == 1)
122
-				and $v[0]->type == 'texte'
123
-				and (strlen($v[0]->apres) == 1)
124
-				and $v[0]->apres == $v[0]->avant
125
-			) {
126
-				$args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres;
127
-			} else {
128
-				$args[] = decompiler_($v, $fmt, 0 - $prof);
129
-			}
130
-		}
131
-		if (($r !== '') or $args) {
132
-			$res .= $f($r, $args, $prof);
133
-		}
134
-	}
135
-
136
-	return $res;
106
+    if (!is_array($sources)) {
107
+        return '';
108
+    }
109
+    $f = 'format_liste_' . $fmt;
110
+    $res = '';
111
+    foreach ($sources as $arg) {
112
+        if (!is_array($arg)) {
113
+            continue; // ne devrait pas arriver.
114
+        } else {
115
+            $r = array_shift($arg);
116
+        }
117
+        $args = [];
118
+        foreach ($arg as $v) {
119
+            // cas des arguments entoures de ' ou "
120
+            if (
121
+                ((is_countable($v) ? count($v) : 0) == 1)
122
+                and $v[0]->type == 'texte'
123
+                and (strlen($v[0]->apres) == 1)
124
+                and $v[0]->apres == $v[0]->avant
125
+            ) {
126
+                $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres;
127
+            } else {
128
+                $args[] = decompiler_($v, $fmt, 0 - $prof);
129
+            }
130
+        }
131
+        if (($r !== '') or $args) {
132
+            $res .= $f($r, $args, $prof);
133
+        }
134
+    }
135
+
136
+    return $res;
137 137
 }
138 138
 
139 139
 // Decompilation des criteres: on triche et on deroge:
@@ -141,93 +141,93 @@  discard block
 block discarded – undo
141 141
 // - le champ apres signale le critere {"separateur"} ou {'separateur'}
142 142
 // - les champs sont implicitement etendus (crochets implicites mais interdits)
143 143
 function decompiler_criteres($boucle, $fmt = '', $prof = 0) {
144
-	$sources = $boucle->param;
145
-	if (!is_array($sources)) {
146
-		return '';
147
-	}
148
-	$res = '';
149
-	$f = 'format_critere_' . $fmt;
150
-	foreach ($sources as $crit) {
151
-		if (!is_array($crit)) {
152
-			continue;
153
-		} // boucle recursive
154
-		array_shift($crit);
155
-		$args = [];
156
-		foreach ($crit as $i => $v) {
157
-			if (
158
-				((is_countable($v) ? count($v) : 0) == 1)
159
-				and $v[0]->type == 'texte'
160
-				and $v[0]->apres
161
-			) {
162
-				$args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]];
163
-			} else {
164
-				$res2 = [];
165
-				foreach ($v as $k => $p) {
166
-					if (
167
-						isset($p->type)
168
-						and function_exists($d = 'decompiler_' . $p->type)
169
-					) {
170
-						$r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]);
171
-						$res2[] = [$p->type, $r];
172
-					} else {
173
-						spip_log("critere $i / $k mal forme");
174
-					}
175
-				}
176
-				$args[] = $res2;
177
-			}
178
-		}
179
-		$res .= $f($args);
180
-	}
181
-
182
-	return $res;
144
+    $sources = $boucle->param;
145
+    if (!is_array($sources)) {
146
+        return '';
147
+    }
148
+    $res = '';
149
+    $f = 'format_critere_' . $fmt;
150
+    foreach ($sources as $crit) {
151
+        if (!is_array($crit)) {
152
+            continue;
153
+        } // boucle recursive
154
+        array_shift($crit);
155
+        $args = [];
156
+        foreach ($crit as $i => $v) {
157
+            if (
158
+                ((is_countable($v) ? count($v) : 0) == 1)
159
+                and $v[0]->type == 'texte'
160
+                and $v[0]->apres
161
+            ) {
162
+                $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]];
163
+            } else {
164
+                $res2 = [];
165
+                foreach ($v as $k => $p) {
166
+                    if (
167
+                        isset($p->type)
168
+                        and function_exists($d = 'decompiler_' . $p->type)
169
+                    ) {
170
+                        $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]);
171
+                        $res2[] = [$p->type, $r];
172
+                    } else {
173
+                        spip_log("critere $i / $k mal forme");
174
+                    }
175
+                }
176
+                $args[] = $res2;
177
+            }
178
+        }
179
+        $res .= $f($args);
180
+    }
181
+
182
+    return $res;
183 183
 }
184 184
 
185 185
 
186 186
 function decompiler_($liste, $fmt = '', $prof = 0) {
187
-	if (!is_array($liste)) {
188
-		return '';
189
-	}
190
-	$prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1);
191
-	$contenu = [];
192
-	foreach ($liste as $k => $p) {
193
-		if (!isset($p->type)) {
194
-			continue;
195
-		} #??????
196
-		$d = 'decompiler_' . $p->type;
197
-		$next = $liste[$k + 1] ?? false;
198
-		// Forcer le champ etendu si son source (pas les reecritures)
199
-		// contenait des args et s'il est suivi d'espaces,
200
-		// le champ simple les eliminant est un bug helas perenne.
201
-
202
-		if (
203
-			$next
204
-			and ($next->type == 'texte')
205
-			and $p->type == 'champ'
206
-			and !$p->apres
207
-			and !$p->avant
208
-			and $p->fonctions
209
-		) {
210
-			$n = strlen($next->texte) - strlen(ltrim($next->texte));
211
-			if ($n) {
212
-				$champ = new Texte();
213
-				$champ->texte = substr($next->texte, 0, $n);
214
-				$champ->ligne = $p->ligne;
215
-				$p->apres = [$champ];
216
-				$next->texte = substr($next->texte, $n);
217
-			}
218
-		}
219
-		$contenu[] = [$d($p, $fmt, $prof2), $p->type];
220
-	}
221
-	$f = 'format_suite_' . $fmt;
222
-
223
-	return $f($contenu);
187
+    if (!is_array($liste)) {
188
+        return '';
189
+    }
190
+    $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1);
191
+    $contenu = [];
192
+    foreach ($liste as $k => $p) {
193
+        if (!isset($p->type)) {
194
+            continue;
195
+        } #??????
196
+        $d = 'decompiler_' . $p->type;
197
+        $next = $liste[$k + 1] ?? false;
198
+        // Forcer le champ etendu si son source (pas les reecritures)
199
+        // contenait des args et s'il est suivi d'espaces,
200
+        // le champ simple les eliminant est un bug helas perenne.
201
+
202
+        if (
203
+            $next
204
+            and ($next->type == 'texte')
205
+            and $p->type == 'champ'
206
+            and !$p->apres
207
+            and !$p->avant
208
+            and $p->fonctions
209
+        ) {
210
+            $n = strlen($next->texte) - strlen(ltrim($next->texte));
211
+            if ($n) {
212
+                $champ = new Texte();
213
+                $champ->texte = substr($next->texte, 0, $n);
214
+                $champ->ligne = $p->ligne;
215
+                $p->apres = [$champ];
216
+                $next->texte = substr($next->texte, $n);
217
+            }
218
+        }
219
+        $contenu[] = [$d($p, $fmt, $prof2), $p->type];
220
+    }
221
+    $f = 'format_suite_' . $fmt;
222
+
223
+    return $f($contenu);
224 224
 }
225 225
 
226 226
 function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') {
227
-	if (!include_spip('public/format_' . $fmt)) {
228
-		return "'$fmt'?";
229
-	}
230
-	$f = 'decompiler_' . $quoi;
227
+    if (!include_spip('public/format_' . $fmt)) {
228
+        return "'$fmt'?";
229
+    }
230
+    $f = 'decompiler_' . $quoi;
231 231
 
232
-	return $f($liste, $fmt, $prof);
232
+    return $f($liste, $fmt, $prof);
233 233
 }
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 = '', string $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
-		[$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
+        [$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 = $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 = $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/public/iterateur.php 1 patch
Indentation   +654 added lines, -654 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
 /**
@@ -21,667 +21,667 @@  discard block
 block discarded – undo
21 21
  *
22 22
  */
23 23
 class IterFactory {
24
-	public static function create($iterateur, $command, $info = null) {
25
-
26
-		$iter = null;
27
-		// cas des SI {si expression} analises tres tot
28
-		// pour eviter le chargement de tout iterateur
29
-		if (isset($command['si'])) {
30
-			foreach ($command['si'] as $si) {
31
-				if (!$si) {
32
-					// $command pour boucle SQL peut generer des erreurs de compilation
33
-					// s'il est transmis alors qu'on est dans un iterateur vide
34
-					return new IterDecorator(new EmptyIterator(), [], $info);
35
-				}
36
-			}
37
-		}
38
-
39
-		// chercher un iterateur PHP existant (par exemple dans SPL)
40
-		// (il faudrait passer l'argument ->sql_serveur
41
-		// pour etre certain qu'on est sur un "php:")
42
-		if (class_exists($iterateur)) {
43
-			$a = $command['args'] ?? [];
44
-
45
-			// permettre de passer un Iterateur directement {args #ITERATEUR} :
46
-			// si on recoit deja un iterateur en argument, on l'utilise
47
-			if ((is_countable($a) ? count($a) : 0) == 1 and is_object($a[0]) and is_subclass_of($a[0], \Iterator::class)) {
48
-				$iter = $a[0];
49
-
50
-				// sinon, on cree un iterateur du type donne
51
-			} else {
52
-				// arguments de creation de l'iterateur...
53
-				// (pas glop)
54
-				try {
55
-					switch (is_countable($a) ? count($a) : 0) {
56
-						case 0:
57
-							$iter = new $iterateur();
58
-							break;
59
-						case 1:
60
-							$iter = new $iterateur($a[0]);
61
-							break;
62
-						case 2:
63
-							$iter = new $iterateur($a[0], $a[1]);
64
-							break;
65
-						case 3:
66
-							$iter = new $iterateur($a[0], $a[1], $a[2]);
67
-							break;
68
-						case 4:
69
-							$iter = new $iterateur($a[0], $a[1], $a[2], $a[3]);
70
-							break;
71
-					}
72
-				} catch (Exception $e) {
73
-					spip_log("Erreur de chargement de l'iterateur $iterateur");
74
-					spip_log($e->getMessage());
75
-					$iter = new EmptyIterator();
76
-				}
77
-			}
78
-		} else {
79
-			// chercher la classe d'iterateur
80
-			// IterateurXXX
81
-			// definie dans le fichier iterateurs/xxx.php
82
-			$class = 'Iterateur' . $iterateur;
83
-			if (!class_exists($class)) {
84
-				if (
85
-					!include_spip('iterateur/' . strtolower($iterateur))
86
-					or !class_exists($class)
87
-				) {
88
-					die("Iterateur $iterateur non trouv&#233;");
89
-					// si l'iterateur n'existe pas, on se rabat sur le generique
90
-					# $iter = new EmptyIterator();
91
-				}
92
-			}
93
-			$iter = new $class($command, $info);
94
-		}
95
-
96
-		return new IterDecorator($iter, $command, $info);
97
-	}
24
+    public static function create($iterateur, $command, $info = null) {
25
+
26
+        $iter = null;
27
+        // cas des SI {si expression} analises tres tot
28
+        // pour eviter le chargement de tout iterateur
29
+        if (isset($command['si'])) {
30
+            foreach ($command['si'] as $si) {
31
+                if (!$si) {
32
+                    // $command pour boucle SQL peut generer des erreurs de compilation
33
+                    // s'il est transmis alors qu'on est dans un iterateur vide
34
+                    return new IterDecorator(new EmptyIterator(), [], $info);
35
+                }
36
+            }
37
+        }
38
+
39
+        // chercher un iterateur PHP existant (par exemple dans SPL)
40
+        // (il faudrait passer l'argument ->sql_serveur
41
+        // pour etre certain qu'on est sur un "php:")
42
+        if (class_exists($iterateur)) {
43
+            $a = $command['args'] ?? [];
44
+
45
+            // permettre de passer un Iterateur directement {args #ITERATEUR} :
46
+            // si on recoit deja un iterateur en argument, on l'utilise
47
+            if ((is_countable($a) ? count($a) : 0) == 1 and is_object($a[0]) and is_subclass_of($a[0], \Iterator::class)) {
48
+                $iter = $a[0];
49
+
50
+                // sinon, on cree un iterateur du type donne
51
+            } else {
52
+                // arguments de creation de l'iterateur...
53
+                // (pas glop)
54
+                try {
55
+                    switch (is_countable($a) ? count($a) : 0) {
56
+                        case 0:
57
+                            $iter = new $iterateur();
58
+                            break;
59
+                        case 1:
60
+                            $iter = new $iterateur($a[0]);
61
+                            break;
62
+                        case 2:
63
+                            $iter = new $iterateur($a[0], $a[1]);
64
+                            break;
65
+                        case 3:
66
+                            $iter = new $iterateur($a[0], $a[1], $a[2]);
67
+                            break;
68
+                        case 4:
69
+                            $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]);
70
+                            break;
71
+                    }
72
+                } catch (Exception $e) {
73
+                    spip_log("Erreur de chargement de l'iterateur $iterateur");
74
+                    spip_log($e->getMessage());
75
+                    $iter = new EmptyIterator();
76
+                }
77
+            }
78
+        } else {
79
+            // chercher la classe d'iterateur
80
+            // IterateurXXX
81
+            // definie dans le fichier iterateurs/xxx.php
82
+            $class = 'Iterateur' . $iterateur;
83
+            if (!class_exists($class)) {
84
+                if (
85
+                    !include_spip('iterateur/' . strtolower($iterateur))
86
+                    or !class_exists($class)
87
+                ) {
88
+                    die("Iterateur $iterateur non trouv&#233;");
89
+                    // si l'iterateur n'existe pas, on se rabat sur le generique
90
+                    # $iter = new EmptyIterator();
91
+                }
92
+            }
93
+            $iter = new $class($command, $info);
94
+        }
95
+
96
+        return new IterDecorator($iter, $command, $info);
97
+    }
98 98
 }
99 99
 
100 100
 
101 101
 class IterDecorator extends FilterIterator {
102
-	private $iter;
103
-
104
-	/**
105
-	 * Conditions de filtrage
106
-	 * ie criteres de selection
107
-	 *
108
-	 * @var array
109
-	 */
110
-	protected $filtre = [];
111
-
112
-	/**
113
-	 * Fonction de filtrage compilee a partir des criteres de filtre
114
-	 *
115
-	 * @var string
116
-	 */
117
-	protected $func_filtre = null;
118
-
119
-	/**
120
-	 * Critere {offset, limit}
121
-	 *
122
-	 * @var int
123
-	 * @var int
124
-	 */
125
-	protected $offset = null;
126
-	protected $limit = null;
127
-
128
-	/**
129
-	 * nombre d'elements recuperes depuis la position 0,
130
-	 * en tenant compte des filtres
131
-	 *
132
-	 * @var int
133
-	 */
134
-	protected $fetched = 0;
135
-
136
-	/**
137
-	 * Y a t'il une erreur ?
138
-	 *
139
-	 * @var bool
140
-	 **/
141
-	protected $err = false;
142
-
143
-	/**
144
-	 * Drapeau a activer en cas d'echec
145
-	 * (select SQL errone, non chargement des DATA, etc)
146
-	 */
147
-	public function err() {
148
-		if (method_exists($this->iter, 'err')) {
149
-			return $this->iter->err();
150
-		}
151
-		if (property_exists($this->iter, 'err')) {
152
-			return $this->iter->err;
153
-		}
154
-
155
-		return false;
156
-	}
157
-
158
-	public function __construct(Iterator $iter, $command, $info) {
159
-		parent::__construct($iter);
160
-		parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator)
161
-
162
-		// recuperer l'iterateur transmis
163
-		$this->iter = $this->getInnerIterator();
164
-		$this->command = $command;
165
-		$this->info = $info;
166
-		$this->pos = 0;
167
-		$this->fetched = 0;
168
-
169
-		// chercher la liste des champs a retourner par
170
-		// fetch si l'objet ne les calcule pas tout seul
171
-		if (!method_exists($this->iter, 'fetch')) {
172
-			$this->calculer_select();
173
-			$this->calculer_filtres();
174
-		}
175
-
176
-		// emptyIterator critere {si} faux n'a pas d'erreur !
177
-		if (isset($this->iter->err)) {
178
-			$this->err = $this->iter->err;
179
-		}
180
-
181
-		// pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite)
182
-		//$this->total = $this->count();
183
-	}
184
-
185
-
186
-	// calcule les elements a retournes par fetch()
187
-	// enleve les elements inutiles du select()
188
-	//
189
-	private function calculer_select() {
190
-		if ($select = &$this->command['select']) {
191
-			foreach ($select as $s) {
192
-				// /!\ $s = '.nom'
193
-				if ($s[0] == '.') {
194
-					$s = substr($s, 1);
195
-				}
196
-				$this->select[] = $s;
197
-			}
198
-		}
199
-	}
200
-
201
-	// recuperer la valeur d'une balise #X
202
-	// en fonction des methodes
203
-	// et proprietes disponibles
204
-	public function get_select($nom) {
205
-		if (
206
-			is_object($this->iter)
207
-			and method_exists($this->iter, $nom)
208
-		) {
209
-			try {
210
-				return $this->iter->$nom();
211
-			} catch (Exception $e) {
212
-				// #GETCHILDREN sur un fichier de DirectoryIterator ...
213
-				spip_log("Methode $nom en echec sur " . get_class($this->iter));
214
-				spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode");
215
-
216
-				return '';
217
-			}
218
-		}
219
-		/*
102
+    private $iter;
103
+
104
+    /**
105
+     * Conditions de filtrage
106
+     * ie criteres de selection
107
+     *
108
+     * @var array
109
+     */
110
+    protected $filtre = [];
111
+
112
+    /**
113
+     * Fonction de filtrage compilee a partir des criteres de filtre
114
+     *
115
+     * @var string
116
+     */
117
+    protected $func_filtre = null;
118
+
119
+    /**
120
+     * Critere {offset, limit}
121
+     *
122
+     * @var int
123
+     * @var int
124
+     */
125
+    protected $offset = null;
126
+    protected $limit = null;
127
+
128
+    /**
129
+     * nombre d'elements recuperes depuis la position 0,
130
+     * en tenant compte des filtres
131
+     *
132
+     * @var int
133
+     */
134
+    protected $fetched = 0;
135
+
136
+    /**
137
+     * Y a t'il une erreur ?
138
+     *
139
+     * @var bool
140
+     **/
141
+    protected $err = false;
142
+
143
+    /**
144
+     * Drapeau a activer en cas d'echec
145
+     * (select SQL errone, non chargement des DATA, etc)
146
+     */
147
+    public function err() {
148
+        if (method_exists($this->iter, 'err')) {
149
+            return $this->iter->err();
150
+        }
151
+        if (property_exists($this->iter, 'err')) {
152
+            return $this->iter->err;
153
+        }
154
+
155
+        return false;
156
+    }
157
+
158
+    public function __construct(Iterator $iter, $command, $info) {
159
+        parent::__construct($iter);
160
+        parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator)
161
+
162
+        // recuperer l'iterateur transmis
163
+        $this->iter = $this->getInnerIterator();
164
+        $this->command = $command;
165
+        $this->info = $info;
166
+        $this->pos = 0;
167
+        $this->fetched = 0;
168
+
169
+        // chercher la liste des champs a retourner par
170
+        // fetch si l'objet ne les calcule pas tout seul
171
+        if (!method_exists($this->iter, 'fetch')) {
172
+            $this->calculer_select();
173
+            $this->calculer_filtres();
174
+        }
175
+
176
+        // emptyIterator critere {si} faux n'a pas d'erreur !
177
+        if (isset($this->iter->err)) {
178
+            $this->err = $this->iter->err;
179
+        }
180
+
181
+        // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite)
182
+        //$this->total = $this->count();
183
+    }
184
+
185
+
186
+    // calcule les elements a retournes par fetch()
187
+    // enleve les elements inutiles du select()
188
+    //
189
+    private function calculer_select() {
190
+        if ($select = &$this->command['select']) {
191
+            foreach ($select as $s) {
192
+                // /!\ $s = '.nom'
193
+                if ($s[0] == '.') {
194
+                    $s = substr($s, 1);
195
+                }
196
+                $this->select[] = $s;
197
+            }
198
+        }
199
+    }
200
+
201
+    // recuperer la valeur d'une balise #X
202
+    // en fonction des methodes
203
+    // et proprietes disponibles
204
+    public function get_select($nom) {
205
+        if (
206
+            is_object($this->iter)
207
+            and method_exists($this->iter, $nom)
208
+        ) {
209
+            try {
210
+                return $this->iter->$nom();
211
+            } catch (Exception $e) {
212
+                // #GETCHILDREN sur un fichier de DirectoryIterator ...
213
+                spip_log("Methode $nom en echec sur " . get_class($this->iter));
214
+                spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode");
215
+
216
+                return '';
217
+            }
218
+        }
219
+        /*
220 220
 		if (property_exists($this->iter, $nom)) {
221 221
 			return $this->iter->$nom;
222 222
 		}*/
223
-		// cle et valeur par defaut
224
-		// ICI PLANTAGE SI ON NE CONTROLE PAS $nom
225
-		if (
226
-			in_array($nom, ['cle', 'valeur'])
227
-			and method_exists($this, $nom)
228
-		) {
229
-			return $this->$nom();
230
-		}
231
-
232
-		// Par defaut chercher en xpath dans la valeur()
233
-		return table_valeur($this->valeur(), $nom, null);
234
-	}
235
-
236
-
237
-	private function calculer_filtres() {
238
-
239
-		// Issu de calculer_select() de public/composer L.519
240
-		// TODO: externaliser...
241
-		//
242
-		// retirer les criteres vides:
243
-		// {X ?} avec X absent de l'URL
244
-		// {par #ENV{X}} avec X absent de l'URL
245
-		// IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil)
246
-		if ($where = &$this->command['where']) {
247
-			foreach ($where as $k => $v) {
248
-				$this->filtre[] = $this->traduire_condition_sql_en_filtre($v);
249
-			}
250
-		}
251
-
252
-		// critere {2,7}
253
-		if (isset($this->command['limit']) and $this->command['limit']) {
254
-			$limit = explode(',', $this->command['limit']);
255
-			$this->offset = $limit[0];
256
-			$this->limit = $limit[1];
257
-		}
258
-
259
-		// Creer la fonction de filtrage sur $this
260
-		if ($this->filtre) {
261
-			if ($filtres = $this->assembler_filtres($this->filtre)) {
262
-				$filtres = 'return ' . $filtres . ';';
263
-				$this->func_filtre = fn() => eval($filtres);
264
-			}
265
-			else {
266
-				$this->func_filtre = null;
267
-			}
268
-		}
269
-	}
270
-
271
-	/**
272
-	 * Assembler le tableau de filtres traduits depuis les conditions SQL
273
-	 * les filtres vides ou null sont ignores
274
-	 * @param $filtres
275
-	 * @param string $operateur
276
-	 * @return string|null
277
-	 */
278
-	protected function assembler_filtres($filtres, $operateur = 'AND') {
279
-
280
-		$filtres_string = [];
281
-		foreach ($filtres as $k => $v) {
282
-			// si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine
283
-			if (is_array($v) and in_array(reset($v), ['OR', 'AND'])) {
284
-				$op = array_shift($v);
285
-				$v = $this->assembler_filtres($v, $op);
286
-			}
287
-			if (is_null($v) or !is_string($v) or empty($v)) {
288
-				continue;
289
-			}
290
-			$filtres_string[] = $v;
291
-		}
292
-
293
-		if (!count($filtres_string)) {
294
-			return null;
295
-		}
296
-
297
-		return '(' . implode(") $operateur (", $filtres_string) . ')';
298
-	}
299
-
300
-	/**
301
-	 * Traduire un element du tableau where SQL en un filtre
302
-	 * @param $v
303
-	 * @return string|array|null
304
-	 */
305
-	protected function traduire_condition_sql_en_filtre($v) {
306
-		if (is_array($v)) {
307
-			if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) {
308
-				return 'true';
309
-			} elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) {
310
-				return 'true';
311
-			} else {
312
-				$op = $v[0] ?: $v;
313
-			}
314
-		} else {
315
-			$op = $v;
316
-		}
317
-		if ((!$op) or ($op == 1) or ($op == '0=0')) {
318
-			return 'true';
319
-		}
320
-		if ($op === '0=1') {
321
-			return 'false';
322
-		}
323
-		// traiter {cle IN a,b} ou {valeur !IN a,b}
324
-		if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) {
325
-			return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]);
326
-		}
327
-
328
-		// 3 possibilites : count($v) =
329
-		// * 1 : {x y} ; on recoit $v[0] = y
330
-		// * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y}
331
-		// * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y
332
-
333
-		// 1 : forcement traite par un critere, on passe
334
-		if (!$v or !is_array($v) or count($v) == 1) {
335
-			return null; // sera ignore
336
-		}
337
-		if (count($v) == 2 and is_array($v[1])) {
338
-			return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT');
339
-		}
340
-		if (count($v) == 3) {
341
-			// traiter le OR/AND suivi de 2 valeurs
342
-			if (in_array($op, ['OR', 'AND'])) {
343
-				array_shift($v);
344
-				foreach (array_keys($v) as $k) {
345
-					$v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]);
346
-					if ($v[$k] === null) {
347
-						unset($v[$k]);
348
-					}
349
-					elseif ($v[$k] === 'true') {
350
-						if ($op === 'OR') {
351
-							return 'true';
352
-						}
353
-						if ($op === 'AND') {
354
-							unset($v[$k]);
355
-						}
356
-					}
357
-					elseif ($v[$k] === 'false') {
358
-						if ($op === 'OR') {
359
-							unset($v[$k]);
360
-						}
361
-						if ($op === 'AND') {
362
-							return 'false';
363
-						}
364
-					}
365
-				}
366
-				if (!count($v)) {
367
-					return null;
368
-				}
369
-				if (count($v) === 1) {
370
-					return reset($v);
371
-				}
372
-				array_unshift($v, $op);
373
-				return $v;
374
-			}
375
-			return $this->composer_filtre($v[1], $v[0], $v[2]);
376
-		}
377
-
378
-		return null;  // sera ignore
379
-	}
380
-
381
-	/**
382
-	 * Calculer un filtre sur un champ du tableau
383
-	 * @param $cle
384
-	 * @param $op
385
-	 * @param $valeur
386
-	 * @param false $not
387
-	 * @return string|null
388
-	 */
389
-	protected function composer_filtre($cle, $op, $valeur, $not = false) {
390
-		if (method_exists($this->iter, 'exception_des_criteres')) {
391
-			if (in_array($cle, $this->iter->exception_des_criteres())) {
392
-				return null;
393
-			}
394
-		}
395
-		// TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ?
396
-		# mais c'est normalement deja opere par calculer_critere_infixe()
397
-		# qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1}
398
-		# ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present.
399
-		# il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir...
400
-
401
-		# if (!in_array($cle, array('cle', 'valeur')))
402
-		#	return;
403
-
404
-		$a = '$this->get_select(\'' . $cle . '\')';
405
-
406
-		$filtre = '';
407
-
408
-		if ($op == 'REGEXP') {
409
-			$filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')';
410
-			$op = '';
411
-		} else {
412
-			if ($op == 'LIKE') {
413
-				$valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur));
414
-				$filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')';
415
-				$op = '';
416
-			} else {
417
-				if ($op == '=') {
418
-					$op = '==';
419
-				} else {
420
-					if ($op == 'IN') {
421
-						$filtre = 'in_array(' . $a . ', array' . $valeur . ')';
422
-						$op = '';
423
-					} else {
424
-						if (!in_array($op, ['<', '<=', '>', '>='])) {
425
-							spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette
426
-							$op = '';
427
-						}
428
-					}
429
-				}
430
-			}
431
-		}
432
-
433
-		if ($op) {
434
-			$filtre = $a . $op . str_replace('\"', '"', $valeur);
435
-		}
436
-
437
-		if ($not) {
438
-			$filtre = "!($filtre)";
439
-		}
440
-
441
-		return $filtre;
442
-	}
443
-
444
-
445
-	public function next() : void {
446
-		$this->pos++;
447
-		parent::next();
448
-	}
449
-
450
-	/**
451
-	 * revient au depart
452
-	 *
453
-	 * @return void
454
-	 */
455
-	public function rewind() : void {
456
-		$this->pos = 0;
457
-		$this->fetched = 0;
458
-		parent::rewind();
459
-	}
460
-
461
-
462
-	# Extension SPIP des iterateurs PHP
463
-	/**
464
-	 * type de l'iterateur
465
-	 *
466
-	 * @var string
467
-	 */
468
-	protected $type;
469
-
470
-	/**
471
-	 * parametres de l'iterateur
472
-	 *
473
-	 * @var array
474
-	 */
475
-	protected $command;
476
-
477
-	/**
478
-	 * infos de compilateur
479
-	 *
480
-	 * @var array
481
-	 */
482
-	protected $info;
483
-
484
-	/**
485
-	 * position courante de l'iterateur
486
-	 *
487
-	 * @var int
488
-	 */
489
-	protected $pos = null;
490
-
491
-	/**
492
-	 * nombre total resultats dans l'iterateur
493
-	 *
494
-	 * @var int
495
-	 */
496
-	protected $total = null;
497
-
498
-	/**
499
-	 * nombre maximal de recherche pour $total
500
-	 * si l'iterateur n'implemente pas de fonction specifique
501
-	 */
502
-	protected $max = 100000;
503
-
504
-
505
-	/**
506
-	 * Liste des champs a inserer dans les $row
507
-	 * retournes par ->fetch()
508
-	 */
509
-	protected $select = [];
510
-
511
-
512
-	/**
513
-	 * aller a la position absolue n,
514
-	 * comptee depuis le debut
515
-	 *
516
-	 * @param int $n
517
-	 *   absolute pos
518
-	 * @param string $continue
519
-	 *   param for sql_ api
520
-	 * @return bool
521
-	 *   success or fail if not implemented
522
-	 */
523
-	public function seek($n = 0, $continue = null) {
524
-		if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) {
525
-			$this->seek_loop($n);
526
-		}
527
-		$this->pos = $n;
528
-		$this->fetched = $n;
529
-
530
-		return true;
531
-	}
532
-
533
-	/*
223
+        // cle et valeur par defaut
224
+        // ICI PLANTAGE SI ON NE CONTROLE PAS $nom
225
+        if (
226
+            in_array($nom, ['cle', 'valeur'])
227
+            and method_exists($this, $nom)
228
+        ) {
229
+            return $this->$nom();
230
+        }
231
+
232
+        // Par defaut chercher en xpath dans la valeur()
233
+        return table_valeur($this->valeur(), $nom, null);
234
+    }
235
+
236
+
237
+    private function calculer_filtres() {
238
+
239
+        // Issu de calculer_select() de public/composer L.519
240
+        // TODO: externaliser...
241
+        //
242
+        // retirer les criteres vides:
243
+        // {X ?} avec X absent de l'URL
244
+        // {par #ENV{X}} avec X absent de l'URL
245
+        // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil)
246
+        if ($where = &$this->command['where']) {
247
+            foreach ($where as $k => $v) {
248
+                $this->filtre[] = $this->traduire_condition_sql_en_filtre($v);
249
+            }
250
+        }
251
+
252
+        // critere {2,7}
253
+        if (isset($this->command['limit']) and $this->command['limit']) {
254
+            $limit = explode(',', $this->command['limit']);
255
+            $this->offset = $limit[0];
256
+            $this->limit = $limit[1];
257
+        }
258
+
259
+        // Creer la fonction de filtrage sur $this
260
+        if ($this->filtre) {
261
+            if ($filtres = $this->assembler_filtres($this->filtre)) {
262
+                $filtres = 'return ' . $filtres . ';';
263
+                $this->func_filtre = fn() => eval($filtres);
264
+            }
265
+            else {
266
+                $this->func_filtre = null;
267
+            }
268
+        }
269
+    }
270
+
271
+    /**
272
+     * Assembler le tableau de filtres traduits depuis les conditions SQL
273
+     * les filtres vides ou null sont ignores
274
+     * @param $filtres
275
+     * @param string $operateur
276
+     * @return string|null
277
+     */
278
+    protected function assembler_filtres($filtres, $operateur = 'AND') {
279
+
280
+        $filtres_string = [];
281
+        foreach ($filtres as $k => $v) {
282
+            // si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine
283
+            if (is_array($v) and in_array(reset($v), ['OR', 'AND'])) {
284
+                $op = array_shift($v);
285
+                $v = $this->assembler_filtres($v, $op);
286
+            }
287
+            if (is_null($v) or !is_string($v) or empty($v)) {
288
+                continue;
289
+            }
290
+            $filtres_string[] = $v;
291
+        }
292
+
293
+        if (!count($filtres_string)) {
294
+            return null;
295
+        }
296
+
297
+        return '(' . implode(") $operateur (", $filtres_string) . ')';
298
+    }
299
+
300
+    /**
301
+     * Traduire un element du tableau where SQL en un filtre
302
+     * @param $v
303
+     * @return string|array|null
304
+     */
305
+    protected function traduire_condition_sql_en_filtre($v) {
306
+        if (is_array($v)) {
307
+            if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) {
308
+                return 'true';
309
+            } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) {
310
+                return 'true';
311
+            } else {
312
+                $op = $v[0] ?: $v;
313
+            }
314
+        } else {
315
+            $op = $v;
316
+        }
317
+        if ((!$op) or ($op == 1) or ($op == '0=0')) {
318
+            return 'true';
319
+        }
320
+        if ($op === '0=1') {
321
+            return 'false';
322
+        }
323
+        // traiter {cle IN a,b} ou {valeur !IN a,b}
324
+        if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) {
325
+            return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]);
326
+        }
327
+
328
+        // 3 possibilites : count($v) =
329
+        // * 1 : {x y} ; on recoit $v[0] = y
330
+        // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y}
331
+        // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y
332
+
333
+        // 1 : forcement traite par un critere, on passe
334
+        if (!$v or !is_array($v) or count($v) == 1) {
335
+            return null; // sera ignore
336
+        }
337
+        if (count($v) == 2 and is_array($v[1])) {
338
+            return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT');
339
+        }
340
+        if (count($v) == 3) {
341
+            // traiter le OR/AND suivi de 2 valeurs
342
+            if (in_array($op, ['OR', 'AND'])) {
343
+                array_shift($v);
344
+                foreach (array_keys($v) as $k) {
345
+                    $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]);
346
+                    if ($v[$k] === null) {
347
+                        unset($v[$k]);
348
+                    }
349
+                    elseif ($v[$k] === 'true') {
350
+                        if ($op === 'OR') {
351
+                            return 'true';
352
+                        }
353
+                        if ($op === 'AND') {
354
+                            unset($v[$k]);
355
+                        }
356
+                    }
357
+                    elseif ($v[$k] === 'false') {
358
+                        if ($op === 'OR') {
359
+                            unset($v[$k]);
360
+                        }
361
+                        if ($op === 'AND') {
362
+                            return 'false';
363
+                        }
364
+                    }
365
+                }
366
+                if (!count($v)) {
367
+                    return null;
368
+                }
369
+                if (count($v) === 1) {
370
+                    return reset($v);
371
+                }
372
+                array_unshift($v, $op);
373
+                return $v;
374
+            }
375
+            return $this->composer_filtre($v[1], $v[0], $v[2]);
376
+        }
377
+
378
+        return null;  // sera ignore
379
+    }
380
+
381
+    /**
382
+     * Calculer un filtre sur un champ du tableau
383
+     * @param $cle
384
+     * @param $op
385
+     * @param $valeur
386
+     * @param false $not
387
+     * @return string|null
388
+     */
389
+    protected function composer_filtre($cle, $op, $valeur, $not = false) {
390
+        if (method_exists($this->iter, 'exception_des_criteres')) {
391
+            if (in_array($cle, $this->iter->exception_des_criteres())) {
392
+                return null;
393
+            }
394
+        }
395
+        // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ?
396
+        # mais c'est normalement deja opere par calculer_critere_infixe()
397
+        # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1}
398
+        # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present.
399
+        # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir...
400
+
401
+        # if (!in_array($cle, array('cle', 'valeur')))
402
+        #	return;
403
+
404
+        $a = '$this->get_select(\'' . $cle . '\')';
405
+
406
+        $filtre = '';
407
+
408
+        if ($op == 'REGEXP') {
409
+            $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')';
410
+            $op = '';
411
+        } else {
412
+            if ($op == 'LIKE') {
413
+                $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur));
414
+                $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')';
415
+                $op = '';
416
+            } else {
417
+                if ($op == '=') {
418
+                    $op = '==';
419
+                } else {
420
+                    if ($op == 'IN') {
421
+                        $filtre = 'in_array(' . $a . ', array' . $valeur . ')';
422
+                        $op = '';
423
+                    } else {
424
+                        if (!in_array($op, ['<', '<=', '>', '>='])) {
425
+                            spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette
426
+                            $op = '';
427
+                        }
428
+                    }
429
+                }
430
+            }
431
+        }
432
+
433
+        if ($op) {
434
+            $filtre = $a . $op . str_replace('\"', '"', $valeur);
435
+        }
436
+
437
+        if ($not) {
438
+            $filtre = "!($filtre)";
439
+        }
440
+
441
+        return $filtre;
442
+    }
443
+
444
+
445
+    public function next() : void {
446
+        $this->pos++;
447
+        parent::next();
448
+    }
449
+
450
+    /**
451
+     * revient au depart
452
+     *
453
+     * @return void
454
+     */
455
+    public function rewind() : void {
456
+        $this->pos = 0;
457
+        $this->fetched = 0;
458
+        parent::rewind();
459
+    }
460
+
461
+
462
+    # Extension SPIP des iterateurs PHP
463
+    /**
464
+     * type de l'iterateur
465
+     *
466
+     * @var string
467
+     */
468
+    protected $type;
469
+
470
+    /**
471
+     * parametres de l'iterateur
472
+     *
473
+     * @var array
474
+     */
475
+    protected $command;
476
+
477
+    /**
478
+     * infos de compilateur
479
+     *
480
+     * @var array
481
+     */
482
+    protected $info;
483
+
484
+    /**
485
+     * position courante de l'iterateur
486
+     *
487
+     * @var int
488
+     */
489
+    protected $pos = null;
490
+
491
+    /**
492
+     * nombre total resultats dans l'iterateur
493
+     *
494
+     * @var int
495
+     */
496
+    protected $total = null;
497
+
498
+    /**
499
+     * nombre maximal de recherche pour $total
500
+     * si l'iterateur n'implemente pas de fonction specifique
501
+     */
502
+    protected $max = 100000;
503
+
504
+
505
+    /**
506
+     * Liste des champs a inserer dans les $row
507
+     * retournes par ->fetch()
508
+     */
509
+    protected $select = [];
510
+
511
+
512
+    /**
513
+     * aller a la position absolue n,
514
+     * comptee depuis le debut
515
+     *
516
+     * @param int $n
517
+     *   absolute pos
518
+     * @param string $continue
519
+     *   param for sql_ api
520
+     * @return bool
521
+     *   success or fail if not implemented
522
+     */
523
+    public function seek($n = 0, $continue = null) {
524
+        if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) {
525
+            $this->seek_loop($n);
526
+        }
527
+        $this->pos = $n;
528
+        $this->fetched = $n;
529
+
530
+        return true;
531
+    }
532
+
533
+    /*
534 534
 	 * aller a la position $n en parcourant
535 535
 	 * un par un tous les elements
536 536
 	 */
537
-	private function seek_loop($n) {
538
-		if ($this->pos > $n) {
539
-			$this->rewind();
540
-		}
541
-
542
-		while ($this->pos < $n and $this->valid()) {
543
-			$this->next();
544
-		}
545
-
546
-		return true;
547
-	}
548
-
549
-	/**
550
-	 * Avancer de $saut pas
551
-	 *
552
-	 * @param  $saut
553
-	 * @param  $max
554
-	 * @return int
555
-	 */
556
-	public function skip($saut, $max = null) {
557
-		// pas de saut en arriere autorise pour cette fonction
558
-		if (($saut = intval($saut)) <= 0) {
559
-			return $this->pos;
560
-		}
561
-		$seek = $this->pos + $saut;
562
-		// si le saut fait depasser le maxi, on libere la resource
563
-		// et on sort
564
-		if (is_null($max)) {
565
-			$max = $this->count();
566
-		}
567
-
568
-		if ($seek >= $max or $seek >= $this->count()) {
569
-			// sortie plus rapide que de faire next() jusqu'a la fin !
570
-			$this->free();
571
-
572
-			return $max;
573
-		}
574
-
575
-		$this->seek($seek);
576
-
577
-		return $this->pos;
578
-	}
579
-
580
-	/**
581
-	 * Renvoyer un tableau des donnees correspondantes
582
-	 * a la position courante de l'iterateur
583
-	 * en controlant si on respecte le filtre
584
-	 * Appliquer aussi le critere {offset,limit}
585
-	 *
586
-	 * @return array|bool
587
-	 */
588
-	public function fetch() {
589
-		if (method_exists($this->iter, 'fetch')) {
590
-			return $this->iter->fetch();
591
-		} else {
592
-			while (
593
-				$this->valid()
594
-				and (
595
-					!$this->accept()
596
-					or (isset($this->offset) and $this->fetched++ < $this->offset)
597
-				)
598
-			) {
599
-				$this->next();
600
-			}
601
-
602
-			if (!$this->valid()) {
603
-				return false;
604
-			}
605
-
606
-			if (
607
-				isset($this->limit)
608
-				and $this->fetched > $this->offset + $this->limit
609
-			) {
610
-				return false;
611
-			}
612
-
613
-			$r = [];
614
-			foreach ($this->select as $nom) {
615
-				$r[$nom] = $this->get_select($nom);
616
-			}
617
-			$this->next();
618
-
619
-			return $r;
620
-		}
621
-	}
622
-
623
-	// retourner la cle pour #CLE
624
-	public function cle() {
625
-		return $this->key();
626
-	}
627
-
628
-	// retourner la valeur pour #VALEUR
629
-	public function valeur() {
630
-		return $this->current();
631
-	}
632
-
633
-	/**
634
-	 * Accepte-t-on l'entree courante lue ?
635
-	 * On execute les filtres pour le savoir.
636
-	 **/
637
-	public function accept(): bool {
638
-		if ($f = $this->func_filtre) {
639
-			return $f();
640
-		}
641
-
642
-		return true;
643
-	}
644
-
645
-	/**
646
-	 * liberer la ressource
647
-	 *
648
-	 * @return bool
649
-	 */
650
-	public function free() {
651
-		if (method_exists($this->iter, 'free')) {
652
-			$this->iter->free();
653
-		}
654
-		$this->pos = $this->total = 0;
655
-
656
-		return true;
657
-	}
658
-
659
-	/**
660
-	 * Compter le nombre total de resultats
661
-	 * pour #TOTAL_BOUCLE
662
-	 *
663
-	 * @return int
664
-	 */
665
-	public function count() {
666
-		if (is_null($this->total)) {
667
-			if (
668
-				method_exists($this->iter, 'count')
669
-				and !$this->func_filtre
670
-			) {
671
-				return $this->total = $this->iter->count();
672
-			} else {
673
-				// compter les lignes et rembobiner
674
-				$total = 0;
675
-				$pos = $this->pos; // sauver la position
676
-				$this->rewind();
677
-				while ($this->fetch() and $total < $this->max) {
678
-					$total++;
679
-				}
680
-				$this->seek($pos);
681
-				$this->total = $total;
682
-			}
683
-		}
684
-
685
-		return $this->total;
686
-	}
537
+    private function seek_loop($n) {
538
+        if ($this->pos > $n) {
539
+            $this->rewind();
540
+        }
541
+
542
+        while ($this->pos < $n and $this->valid()) {
543
+            $this->next();
544
+        }
545
+
546
+        return true;
547
+    }
548
+
549
+    /**
550
+     * Avancer de $saut pas
551
+     *
552
+     * @param  $saut
553
+     * @param  $max
554
+     * @return int
555
+     */
556
+    public function skip($saut, $max = null) {
557
+        // pas de saut en arriere autorise pour cette fonction
558
+        if (($saut = intval($saut)) <= 0) {
559
+            return $this->pos;
560
+        }
561
+        $seek = $this->pos + $saut;
562
+        // si le saut fait depasser le maxi, on libere la resource
563
+        // et on sort
564
+        if (is_null($max)) {
565
+            $max = $this->count();
566
+        }
567
+
568
+        if ($seek >= $max or $seek >= $this->count()) {
569
+            // sortie plus rapide que de faire next() jusqu'a la fin !
570
+            $this->free();
571
+
572
+            return $max;
573
+        }
574
+
575
+        $this->seek($seek);
576
+
577
+        return $this->pos;
578
+    }
579
+
580
+    /**
581
+     * Renvoyer un tableau des donnees correspondantes
582
+     * a la position courante de l'iterateur
583
+     * en controlant si on respecte le filtre
584
+     * Appliquer aussi le critere {offset,limit}
585
+     *
586
+     * @return array|bool
587
+     */
588
+    public function fetch() {
589
+        if (method_exists($this->iter, 'fetch')) {
590
+            return $this->iter->fetch();
591
+        } else {
592
+            while (
593
+                $this->valid()
594
+                and (
595
+                    !$this->accept()
596
+                    or (isset($this->offset) and $this->fetched++ < $this->offset)
597
+                )
598
+            ) {
599
+                $this->next();
600
+            }
601
+
602
+            if (!$this->valid()) {
603
+                return false;
604
+            }
605
+
606
+            if (
607
+                isset($this->limit)
608
+                and $this->fetched > $this->offset + $this->limit
609
+            ) {
610
+                return false;
611
+            }
612
+
613
+            $r = [];
614
+            foreach ($this->select as $nom) {
615
+                $r[$nom] = $this->get_select($nom);
616
+            }
617
+            $this->next();
618
+
619
+            return $r;
620
+        }
621
+    }
622
+
623
+    // retourner la cle pour #CLE
624
+    public function cle() {
625
+        return $this->key();
626
+    }
627
+
628
+    // retourner la valeur pour #VALEUR
629
+    public function valeur() {
630
+        return $this->current();
631
+    }
632
+
633
+    /**
634
+     * Accepte-t-on l'entree courante lue ?
635
+     * On execute les filtres pour le savoir.
636
+     **/
637
+    public function accept(): bool {
638
+        if ($f = $this->func_filtre) {
639
+            return $f();
640
+        }
641
+
642
+        return true;
643
+    }
644
+
645
+    /**
646
+     * liberer la ressource
647
+     *
648
+     * @return bool
649
+     */
650
+    public function free() {
651
+        if (method_exists($this->iter, 'free')) {
652
+            $this->iter->free();
653
+        }
654
+        $this->pos = $this->total = 0;
655
+
656
+        return true;
657
+    }
658
+
659
+    /**
660
+     * Compter le nombre total de resultats
661
+     * pour #TOTAL_BOUCLE
662
+     *
663
+     * @return int
664
+     */
665
+    public function count() {
666
+        if (is_null($this->total)) {
667
+            if (
668
+                method_exists($this->iter, 'count')
669
+                and !$this->func_filtre
670
+            ) {
671
+                return $this->total = $this->iter->count();
672
+            } else {
673
+                // compter les lignes et rembobiner
674
+                $total = 0;
675
+                $pos = $this->pos; // sauver la position
676
+                $this->rewind();
677
+                while ($this->fetch() and $total < $this->max) {
678
+                    $total++;
679
+                }
680
+                $this->seek($pos);
681
+                $this->total = $total;
682
+            }
683
+        }
684
+
685
+        return $this->total;
686
+    }
687 687
 }
Please login to merge, or discard this patch.
ecrire/public/format_html.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -11,127 +11,127 @@
 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
-			[$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
+            [$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 < (is_countable($args) ? count($args) : 0) - 1; $i++) {
104
-		[$texte, $type] = $args[$i];
105
-		[$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(fn($arg) => reset($arg), $args));
103
+    for ($i = 0; $i < (is_countable($args) ? count($args) : 0) - 1; $i++) {
104
+        [$texte, $type] = $args[$i];
105
+        [$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(fn($arg) => reset($arg), $args));
133 133
 }
134 134
 
135 135
 function format_texte_html($texte) {
136
-	return $texte;
136
+    return $texte;
137 137
 }
Please login to merge, or discard this patch.