Completed
Push — master ( feea64...6b28f6 )
by cam
01:26
created
prive/formulaires/instituer_objet.php 1 patch
Indentation   +108 added lines, -108 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('inc/editer');
@@ -32,17 +32,17 @@  discard block
 block discarded – undo
32 32
  * @return array
33 33
  */
34 34
 function lister_statuts_proposes($desc, $publiable = true) {
35
-	if (!isset($desc['statut_textes_instituer'])) {
36
-		return false;
37
-	}
35
+    if (!isset($desc['statut_textes_instituer'])) {
36
+        return false;
37
+    }
38 38
 
39
-	$l = $desc['statut_textes_instituer'];
40
-	if (!$publiable) {
41
-		unset($l['publie']);
42
-		unset($l['refuse']);
43
-	}
39
+    $l = $desc['statut_textes_instituer'];
40
+    if (!$publiable) {
41
+        unset($l['publie']);
42
+        unset($l['refuse']);
43
+    }
44 44
 
45
-	return $l;
45
+    return $l;
46 46
 }
47 47
 
48 48
 /**
@@ -64,54 +64,54 @@  discard block
 block discarded – undo
64 64
  *     Environnement du formulaire ou false si aucun affichage à faire.
65 65
  */
66 66
 function formulaires_instituer_objet_charger_dist($objet, $id_objet, $retour = '', $editable = true) {
67
-	$editable = ($editable ? true : false);
68
-
69
-	$table = table_objet_sql($objet);
70
-	$desc = lister_tables_objets_sql($table);
71
-
72
-	if (!isset($desc['statut_textes_instituer'])) {
73
-		return false;
74
-	}
75
-
76
-	if (!autoriser('modifier', $objet, $id_objet)) {
77
-		$editable = false;
78
-	}
79
-
80
-	// charger le contenu de l'objet
81
-	// dont son champ statut
82
-	$v = formulaires_editer_objet_charger($objet, $id_objet, 0, 0, '', '');
83
-
84
-	$publiable = true;
85
-	$statuts = lister_statuts_proposes($desc);
86
-	// tester si on a le droit de publier, si un statut publie existe
87
-	if (isset($statuts['publie'])) {
88
-		if (!autoriser('instituer', $objet, $id_objet, null, ['statut' => 'publie'])) {
89
-			if ($v['statut'] == 'publie') {
90
-				$editable = false;
91
-			} else {
92
-				$publiable = false;
93
-			}
94
-		}
95
-	}
96
-	$statuts = lister_statuts_proposes($desc, $editable ? $publiable : true);
97
-	if (count($statuts) == 1 and isset($statuts[$v['statut']])) {
98
-		$editable = false;
99
-	}
100
-
101
-	$valeurs = [
102
-		'editable' => $editable,
103
-		'statut' => $v['statut'],
104
-		'_objet' => $objet,
105
-		'_id_objet' => $id_objet,
106
-		'_statuts' => $statuts,
107
-		'_publiable' => $publiable,
108
-		'_label' => isset($desc['texte_changer_statut']) ? $desc['texte_changer_statut'] : 'texte_article_statut',
109
-		'_aide' => isset($desc['aide_changer_statut']) ? $desc['aide_changer_statut'] : '',
110
-		'_hidden' => "<input type='hidden' name='statut_old' value='" . $v['statut'] . "' />",
111
-	];
112
-
113
-	#if (!count($valeurs['statuts']))
114
-	return $valeurs;
67
+    $editable = ($editable ? true : false);
68
+
69
+    $table = table_objet_sql($objet);
70
+    $desc = lister_tables_objets_sql($table);
71
+
72
+    if (!isset($desc['statut_textes_instituer'])) {
73
+        return false;
74
+    }
75
+
76
+    if (!autoriser('modifier', $objet, $id_objet)) {
77
+        $editable = false;
78
+    }
79
+
80
+    // charger le contenu de l'objet
81
+    // dont son champ statut
82
+    $v = formulaires_editer_objet_charger($objet, $id_objet, 0, 0, '', '');
83
+
84
+    $publiable = true;
85
+    $statuts = lister_statuts_proposes($desc);
86
+    // tester si on a le droit de publier, si un statut publie existe
87
+    if (isset($statuts['publie'])) {
88
+        if (!autoriser('instituer', $objet, $id_objet, null, ['statut' => 'publie'])) {
89
+            if ($v['statut'] == 'publie') {
90
+                $editable = false;
91
+            } else {
92
+                $publiable = false;
93
+            }
94
+        }
95
+    }
96
+    $statuts = lister_statuts_proposes($desc, $editable ? $publiable : true);
97
+    if (count($statuts) == 1 and isset($statuts[$v['statut']])) {
98
+        $editable = false;
99
+    }
100
+
101
+    $valeurs = [
102
+        'editable' => $editable,
103
+        'statut' => $v['statut'],
104
+        '_objet' => $objet,
105
+        '_id_objet' => $id_objet,
106
+        '_statuts' => $statuts,
107
+        '_publiable' => $publiable,
108
+        '_label' => isset($desc['texte_changer_statut']) ? $desc['texte_changer_statut'] : 'texte_article_statut',
109
+        '_aide' => isset($desc['aide_changer_statut']) ? $desc['aide_changer_statut'] : '',
110
+        '_hidden' => "<input type='hidden' name='statut_old' value='" . $v['statut'] . "' />",
111
+    ];
112
+
113
+    #if (!count($valeurs['statuts']))
114
+    return $valeurs;
115 115
 }
116 116
 
117 117
 /**
@@ -131,35 +131,35 @@  discard block
 block discarded – undo
131 131
  *     Tableau des erreurs
132 132
  */
133 133
 function formulaires_instituer_objet_verifier_dist($objet, $id_objet, $retour = '', $editable = true) {
134
-	$erreurs = [];
135
-	// charger le contenu de l'objet
136
-	// dont son champ statut
137
-	$v = formulaires_editer_objet_charger($objet, $id_objet, 0, 0, '', '');
138
-
139
-	if ($v['statut'] !== _request('statut_old')) {
140
-		$erreurs['statut'] = _T('instituer_erreur_statut_a_change');
141
-	} else {
142
-		$table = table_objet_sql($objet);
143
-		$desc = lister_tables_objets_sql($table);
144
-
145
-		$publiable = true;
146
-		if (
147
-			isset($v['id_rubrique'])
148
-			and !autoriser('publierdans', 'rubrique', $v['id_rubrique'])
149
-		) {
150
-			$publiable = false;
151
-		}
152
-		$l = lister_statuts_proposes($desc, $publiable);
153
-		$statut = _request('statut');
154
-		if (
155
-			!isset($l[$statut])
156
-			or !autoriser('instituer', $objet, $id_objet, '', ['statut' => $statut])
157
-		) {
158
-			$erreurs['statut'] = _T('instituer_erreur_statut_non_autorise');
159
-		}
160
-	}
161
-
162
-	return $erreurs;
134
+    $erreurs = [];
135
+    // charger le contenu de l'objet
136
+    // dont son champ statut
137
+    $v = formulaires_editer_objet_charger($objet, $id_objet, 0, 0, '', '');
138
+
139
+    if ($v['statut'] !== _request('statut_old')) {
140
+        $erreurs['statut'] = _T('instituer_erreur_statut_a_change');
141
+    } else {
142
+        $table = table_objet_sql($objet);
143
+        $desc = lister_tables_objets_sql($table);
144
+
145
+        $publiable = true;
146
+        if (
147
+            isset($v['id_rubrique'])
148
+            and !autoriser('publierdans', 'rubrique', $v['id_rubrique'])
149
+        ) {
150
+            $publiable = false;
151
+        }
152
+        $l = lister_statuts_proposes($desc, $publiable);
153
+        $statut = _request('statut');
154
+        if (
155
+            !isset($l[$statut])
156
+            or !autoriser('instituer', $objet, $id_objet, '', ['statut' => $statut])
157
+        ) {
158
+            $erreurs['statut'] = _T('instituer_erreur_statut_non_autorise');
159
+        }
160
+    }
161
+
162
+    return $erreurs;
163 163
 }
164 164
 
165 165
 /**
@@ -178,25 +178,25 @@  discard block
 block discarded – undo
178 178
  */
179 179
 function formulaires_instituer_objet_traiter_dist($objet, $id_objet, $retour = '', $editable = true) {
180 180
 
181
-	$c = ['statut' => _request('statut')];
182
-	// si on a envoye une 'date_posterieure', l'enregistrer
183
-	// todo dans le HTML
184
-	if ($d = _request('date_posterieure')) {
185
-		$c['date'] = $d;
186
-	}
187
-
188
-
189
-	include_spip('action/editer_objet');
190
-	if ($err = objet_instituer($objet, $id_objet, $c)) {
191
-		$res = ['message_erreur' => $err];
192
-	} else {
193
-		$res = ['message_ok' => _T('info_modification_enregistree')];
194
-		if ($retour) {
195
-			$res['redirect'] = $retour;
196
-		}
197
-		set_request('statut');
198
-		set_request('date_posterieure');
199
-	}
200
-
201
-	return $res;
181
+    $c = ['statut' => _request('statut')];
182
+    // si on a envoye une 'date_posterieure', l'enregistrer
183
+    // todo dans le HTML
184
+    if ($d = _request('date_posterieure')) {
185
+        $c['date'] = $d;
186
+    }
187
+
188
+
189
+    include_spip('action/editer_objet');
190
+    if ($err = objet_instituer($objet, $id_objet, $c)) {
191
+        $res = ['message_erreur' => $err];
192
+    } else {
193
+        $res = ['message_ok' => _T('info_modification_enregistree')];
194
+        if ($retour) {
195
+            $res['redirect'] = $retour;
196
+        }
197
+        set_request('statut');
198
+        set_request('date_posterieure');
199
+    }
200
+
201
+    return $res;
202 202
 }
Please login to merge, or discard this patch.
prive/formulaires/configurer_preferences_menus.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -30,13 +30,13 @@  discard block
 block discarded – undo
30 30
  *     Environnement du formulaire
31 31
  **/
32 32
 function formulaires_configurer_preferences_menus_charger_dist() {
33
-	// travailler sur des meta fraîches
34
-	include_spip('inc/meta');
35
-	lire_metas();
36
-	$valeurs = [];
37
-	$valeurs['activer_menudev'] = table_valeur($GLOBALS['visiteur_session'], 'prefs/activer_menudev', 'non');
38
-	$valeurs['menus_favoris'] = obtenir_menus_favoris();
39
-	return $valeurs;
33
+    // travailler sur des meta fraîches
34
+    include_spip('inc/meta');
35
+    lire_metas();
36
+    $valeurs = [];
37
+    $valeurs['activer_menudev'] = table_valeur($GLOBALS['visiteur_session'], 'prefs/activer_menudev', 'non');
38
+    $valeurs['menus_favoris'] = obtenir_menus_favoris();
39
+    return $valeurs;
40 40
 }
41 41
 
42 42
 /**
@@ -47,32 +47,32 @@  discard block
 block discarded – undo
47 47
  **/
48 48
 function formulaires_configurer_preferences_menus_traiter_dist() {
49 49
 
50
-	$activer_menudev = _request('activer_menudev');
51
-	$menus_favoris = _request('menus_favoris');
52
-	$menus_favoris = array_filter($menus_favoris);
53
-	$menus_favoris = array_map('intval', $menus_favoris);
50
+    $activer_menudev = _request('activer_menudev');
51
+    $menus_favoris = _request('menus_favoris');
52
+    $menus_favoris = array_filter($menus_favoris);
53
+    $menus_favoris = array_map('intval', $menus_favoris);
54 54
 
55
-	if (_request('reset')) {
56
-		$menus_favoris = [];
57
-		set_request('menus_favoris', null);
58
-	}
55
+    if (_request('reset')) {
56
+        $menus_favoris = [];
57
+        set_request('menus_favoris', null);
58
+    }
59 59
 
60
-	// si le menu dev change, ou les menus favoris, on recharge toute la page.
61
-	if (
62
-		table_valeur($GLOBALS['visiteur_session'], 'prefs/activer_menudev') != $activer_menudev
63
-		or $menus_favoris != obtenir_menus_favoris()
64
-	) {
65
-		refuser_traiter_formulaire_ajax();
60
+    // si le menu dev change, ou les menus favoris, on recharge toute la page.
61
+    if (
62
+        table_valeur($GLOBALS['visiteur_session'], 'prefs/activer_menudev') != $activer_menudev
63
+        or $menus_favoris != obtenir_menus_favoris()
64
+    ) {
65
+        refuser_traiter_formulaire_ajax();
66 66
 
67
-		$GLOBALS['visiteur_session']['prefs']['activer_menudev'] = $activer_menudev;
68
-		$GLOBALS['visiteur_session']['prefs']['menus_favoris'] = $menus_favoris;
67
+        $GLOBALS['visiteur_session']['prefs']['activer_menudev'] = $activer_menudev;
68
+        $GLOBALS['visiteur_session']['prefs']['menus_favoris'] = $menus_favoris;
69 69
 
70
-		if (intval($GLOBALS['visiteur_session']['id_auteur'])) {
71
-			include_spip('action/editer_auteur');
72
-			$c = ['prefs' => serialize($GLOBALS['visiteur_session']['prefs'])];
73
-			auteur_modifier($GLOBALS['visiteur_session']['id_auteur'], $c);
74
-		}
75
-	}
70
+        if (intval($GLOBALS['visiteur_session']['id_auteur'])) {
71
+            include_spip('action/editer_auteur');
72
+            $c = ['prefs' => serialize($GLOBALS['visiteur_session']['prefs'])];
73
+            auteur_modifier($GLOBALS['visiteur_session']['id_auteur'], $c);
74
+        }
75
+    }
76 76
 
77
-	return ['message_ok' => _T('config_info_enregistree'), 'editable' => true];
77
+    return ['message_ok' => _T('config_info_enregistree'), 'editable' => true];
78 78
 }
Please login to merge, or discard this patch.
prive/formulaires/configurer_preferences.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
  **/
22 22
 
23 23
 if (!defined('_ECRIRE_INC_VERSION')) {
24
-	return;
24
+    return;
25 25
 }
26 26
 
27 27
 /**
@@ -31,28 +31,28 @@  discard block
 block discarded – undo
31 31
  *     Environnement du formulaire
32 32
  **/
33 33
 function formulaires_configurer_preferences_charger_dist() {
34
-	// travailler sur des meta fraiches
35
-	include_spip('inc/meta');
36
-	lire_metas();
34
+    // travailler sur des meta fraiches
35
+    include_spip('inc/meta');
36
+    lire_metas();
37 37
 
38
-	$valeurs = [];
39
-	$valeurs['display_navigation'] = isset($GLOBALS['visiteur_session']['prefs']['display_navigation']) ? $GLOBALS['visiteur_session']['prefs']['display_navigation'] : 'navigation_avec_icones';
40
-	$valeurs['display_outils'] = isset($GLOBALS['visiteur_session']['prefs']['display_outils']) ? $GLOBALS['visiteur_session']['prefs']['display_outils'] : 'oui';
41
-	$valeurs['display'] = (isset($GLOBALS['visiteur_session']['prefs']['display']) and $GLOBALS['visiteur_session']['prefs']['display'] > 0) ? $GLOBALS['visiteur_session']['prefs']['display'] : 2;
42
-	$valeurs['couleur'] = (isset($GLOBALS['visiteur_session']['prefs']['couleur']) and $GLOBALS['visiteur_session']['prefs']['couleur'] > 0) ? $GLOBALS['visiteur_session']['prefs']['couleur'] : 1;
38
+    $valeurs = [];
39
+    $valeurs['display_navigation'] = isset($GLOBALS['visiteur_session']['prefs']['display_navigation']) ? $GLOBALS['visiteur_session']['prefs']['display_navigation'] : 'navigation_avec_icones';
40
+    $valeurs['display_outils'] = isset($GLOBALS['visiteur_session']['prefs']['display_outils']) ? $GLOBALS['visiteur_session']['prefs']['display_outils'] : 'oui';
41
+    $valeurs['display'] = (isset($GLOBALS['visiteur_session']['prefs']['display']) and $GLOBALS['visiteur_session']['prefs']['display'] > 0) ? $GLOBALS['visiteur_session']['prefs']['display'] : 2;
42
+    $valeurs['couleur'] = (isset($GLOBALS['visiteur_session']['prefs']['couleur']) and $GLOBALS['visiteur_session']['prefs']['couleur'] > 0) ? $GLOBALS['visiteur_session']['prefs']['couleur'] : 1;
43 43
 
44
-	$couleurs = charger_fonction('couleurs', 'inc');
45
-	$les_couleurs = $couleurs();
46
-	foreach ($les_couleurs as $k => $c) {
47
-		$valeurs['_couleurs_url'][$k] = generer_url_public('style_prive.css', 'ltr='
48
-			. $GLOBALS['spip_lang_left'] . '&'
49
-			. $couleurs($k));
50
-		$valeurs['couleurs'][$k] = $c;
51
-	}
44
+    $couleurs = charger_fonction('couleurs', 'inc');
45
+    $les_couleurs = $couleurs();
46
+    foreach ($les_couleurs as $k => $c) {
47
+        $valeurs['_couleurs_url'][$k] = generer_url_public('style_prive.css', 'ltr='
48
+            . $GLOBALS['spip_lang_left'] . '&'
49
+            . $couleurs($k));
50
+        $valeurs['couleurs'][$k] = $c;
51
+    }
52 52
 
53
-	$valeurs['imessage'] = $GLOBALS['visiteur_session']['imessage'];
53
+    $valeurs['imessage'] = $GLOBALS['visiteur_session']['imessage'];
54 54
 
55
-	return $valeurs;
55
+    return $valeurs;
56 56
 }
57 57
 
58 58
 /**
@@ -63,36 +63,36 @@  discard block
 block discarded – undo
63 63
  **/
64 64
 function formulaires_configurer_preferences_traiter_dist() {
65 65
 
66
-	if ($couleur = _request('couleur')) {
67
-		$couleurs = charger_fonction('couleurs', 'inc');
68
-		$les_couleurs = $couleurs([], true);
69
-		if (isset($les_couleurs[$couleur])) {
70
-			$GLOBALS['visiteur_session']['prefs']['couleur'] = $couleur;
71
-		}
72
-	}
73
-	if ($display = intval(_request('display'))) {
74
-		$GLOBALS['visiteur_session']['prefs']['display'] = $display;
75
-	}
76
-	if (
77
-		$display_navigation = _request('display_navigation')
78
-		and in_array($display_navigation, ['navigation_sans_icone', 'navigation_avec_icones'])
79
-	) {
80
-		$GLOBALS['visiteur_session']['prefs']['display_navigation'] = $display_navigation;
81
-	}
82
-	if (!is_null($display_outils = _request('display_outils'))) {
83
-		$GLOBALS['visiteur_session']['prefs']['display_outils'] = ($display_outils ? 'oui' : '');
84
-	}
66
+    if ($couleur = _request('couleur')) {
67
+        $couleurs = charger_fonction('couleurs', 'inc');
68
+        $les_couleurs = $couleurs([], true);
69
+        if (isset($les_couleurs[$couleur])) {
70
+            $GLOBALS['visiteur_session']['prefs']['couleur'] = $couleur;
71
+        }
72
+    }
73
+    if ($display = intval(_request('display'))) {
74
+        $GLOBALS['visiteur_session']['prefs']['display'] = $display;
75
+    }
76
+    if (
77
+        $display_navigation = _request('display_navigation')
78
+        and in_array($display_navigation, ['navigation_sans_icone', 'navigation_avec_icones'])
79
+    ) {
80
+        $GLOBALS['visiteur_session']['prefs']['display_navigation'] = $display_navigation;
81
+    }
82
+    if (!is_null($display_outils = _request('display_outils'))) {
83
+        $GLOBALS['visiteur_session']['prefs']['display_outils'] = ($display_outils ? 'oui' : '');
84
+    }
85 85
 
86
-	if (intval($GLOBALS['visiteur_session']['id_auteur'])) {
87
-		include_spip('action/editer_auteur');
88
-		$c = ['prefs' => serialize($GLOBALS['visiteur_session']['prefs'])];
86
+    if (intval($GLOBALS['visiteur_session']['id_auteur'])) {
87
+        include_spip('action/editer_auteur');
88
+        $c = ['prefs' => serialize($GLOBALS['visiteur_session']['prefs'])];
89 89
 
90
-		if ($imessage = _request('imessage') and in_array($imessage, ['oui', 'non'])) {
91
-			$c['imessage'] = $imessage;
92
-		}
90
+        if ($imessage = _request('imessage') and in_array($imessage, ['oui', 'non'])) {
91
+            $c['imessage'] = $imessage;
92
+        }
93 93
 
94
-		auteur_modifier($GLOBALS['visiteur_session']['id_auteur'], $c);
95
-	}
94
+        auteur_modifier($GLOBALS['visiteur_session']['id_auteur'], $c);
95
+    }
96 96
 
97
-	return ['message_ok' => _T('config_info_enregistree'), 'editable' => true];
97
+    return ['message_ok' => _T('config_info_enregistree'), 'editable' => true];
98 98
 }
Please login to merge, or discard this patch.
ecrire/typographie/fr.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -11,74 +11,74 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 // Correction typographique francaise
18 18
 
19 19
 function typographie_fr_dist($letexte) {
20 20
 
21
-	static $trans;
21
+    static $trans;
22 22
 
23
-	// Nettoyer 160 = nbsp ; 187 = raquo ; 171 = laquo ; 176 = deg ;
24
-	// 147 = ldquo; 148 = rdquo; ' = zouli apostrophe
25
-	if (!$trans) {
26
-		$trans = [
27
-			"'" => '&#8217;',
28
-			'&nbsp;' => '~',
29
-			'&raquo;' => '&#187;',
30
-			'&laquo;' => '&#171;',
31
-			'&rdquo;' => '&#8221;',
32
-			'&ldquo;' => '&#8220;',
33
-			'&deg;' => '&#176;'
34
-		];
35
-		$chars = [160 => '~', 187 => '&#187;', 171 => '&#171;', 148 => '&#8221;', 147 => '&#8220;', 176 => '&#176;'];
36
-		$chars_trans = array_keys($chars);
37
-		$chars = array_values($chars);
38
-		$chars_trans = implode(' ', array_map('chr', $chars_trans));
39
-		$chars_trans = unicode2charset(charset2unicode($chars_trans, 'iso-8859-1', 'forcer'));
40
-		$chars_trans = explode(' ', $chars_trans);
41
-		foreach ($chars as $k => $r) {
42
-			$trans[$chars_trans[$k]] = $r;
43
-		}
44
-	}
23
+    // Nettoyer 160 = nbsp ; 187 = raquo ; 171 = laquo ; 176 = deg ;
24
+    // 147 = ldquo; 148 = rdquo; ' = zouli apostrophe
25
+    if (!$trans) {
26
+        $trans = [
27
+            "'" => '&#8217;',
28
+            '&nbsp;' => '~',
29
+            '&raquo;' => '&#187;',
30
+            '&laquo;' => '&#171;',
31
+            '&rdquo;' => '&#8221;',
32
+            '&ldquo;' => '&#8220;',
33
+            '&deg;' => '&#176;'
34
+        ];
35
+        $chars = [160 => '~', 187 => '&#187;', 171 => '&#171;', 148 => '&#8221;', 147 => '&#8220;', 176 => '&#176;'];
36
+        $chars_trans = array_keys($chars);
37
+        $chars = array_values($chars);
38
+        $chars_trans = implode(' ', array_map('chr', $chars_trans));
39
+        $chars_trans = unicode2charset(charset2unicode($chars_trans, 'iso-8859-1', 'forcer'));
40
+        $chars_trans = explode(' ', $chars_trans);
41
+        foreach ($chars as $k => $r) {
42
+            $trans[$chars_trans[$k]] = $r;
43
+        }
44
+    }
45 45
 
46
-	$letexte = strtr($letexte, $trans);
46
+    $letexte = strtr($letexte, $trans);
47 47
 
48
-	$cherche1 = [
49
-		/* 1 */
50
-		'/((?:^|[^\#0-9a-zA-Z\&])[\#0-9a-zA-Z]*)\;/S',
51
-		/* 2 */
52
-		'/&#187;| --?,|(?::(?!:)| %)(?:\W|$)/S',
53
-		/* 3 */
54
-		'/([^[<(!?.])([!?][!?\.]*)/iS',
55
-		/* 4 */
56
-		'/&#171;|(?:M(?:M?\.|mes?|r\.?)|[MnN]&#176;) /S'
57
-	];
58
-	$remplace1 = [
59
-		/* 1 */
60
-		'\1~;',
61
-		/* 2 */
62
-		'~\0',
63
-		/* 3 */
64
-		'\1~\2',
65
-		/* 4 */
66
-		'\0~'
67
-	];
68
-	$letexte = preg_replace($cherche1, $remplace1, $letexte);
69
-	$letexte = preg_replace('/ *~+ */S', '~', $letexte);
48
+    $cherche1 = [
49
+        /* 1 */
50
+        '/((?:^|[^\#0-9a-zA-Z\&])[\#0-9a-zA-Z]*)\;/S',
51
+        /* 2 */
52
+        '/&#187;| --?,|(?::(?!:)| %)(?:\W|$)/S',
53
+        /* 3 */
54
+        '/([^[<(!?.])([!?][!?\.]*)/iS',
55
+        /* 4 */
56
+        '/&#171;|(?:M(?:M?\.|mes?|r\.?)|[MnN]&#176;) /S'
57
+    ];
58
+    $remplace1 = [
59
+        /* 1 */
60
+        '\1~;',
61
+        /* 2 */
62
+        '~\0',
63
+        /* 3 */
64
+        '\1~\2',
65
+        /* 4 */
66
+        '\0~'
67
+    ];
68
+    $letexte = preg_replace($cherche1, $remplace1, $letexte);
69
+    $letexte = preg_replace('/ *~+ */S', '~', $letexte);
70 70
 
71
-	$cherche2 = [
72
-		'/([^-\n]|^)--([^-]|$)/S',
73
-		',(' . _PROTOCOLES_STD . ')~((://[^"\'\s\[\]\}\)<>]+)~([?]))?,S',
74
-		'/~/'
75
-	];
76
-	$remplace2 = [
77
-		'\1&mdash;\2',
78
-		'\1\3\4',
79
-		'&nbsp;'
80
-	];
81
-	$letexte = preg_replace($cherche2, $remplace2, $letexte);
71
+    $cherche2 = [
72
+        '/([^-\n]|^)--([^-]|$)/S',
73
+        ',(' . _PROTOCOLES_STD . ')~((://[^"\'\s\[\]\}\)<>]+)~([?]))?,S',
74
+        '/~/'
75
+    ];
76
+    $remplace2 = [
77
+        '\1&mdash;\2',
78
+        '\1\3\4',
79
+        '&nbsp;'
80
+    ];
81
+    $letexte = preg_replace($cherche2, $remplace2, $letexte);
82 82
 
83
-	return $letexte;
83
+    return $letexte;
84 84
 }
Please login to merge, or discard this patch.
ecrire/typographie/en.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -11,37 +11,37 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 // rien sauf les "~" et "-,"
18 18
 
19 19
 function typographie_en_dist($letexte) {
20 20
 
21
-	// zouli apostrophe
22
-	$letexte = str_replace("'", '&#8217;', $letexte);
21
+    // zouli apostrophe
22
+    $letexte = str_replace("'", '&#8217;', $letexte);
23 23
 
24
-	$cherche1 = [
25
-		'/ --?,/S'
26
-	];
27
-	$remplace1 = [
28
-		'~\0'
29
-	];
30
-	$letexte = preg_replace($cherche1, $remplace1, $letexte);
24
+    $cherche1 = [
25
+        '/ --?,/S'
26
+    ];
27
+    $remplace1 = [
28
+        '~\0'
29
+    ];
30
+    $letexte = preg_replace($cherche1, $remplace1, $letexte);
31 31
 
32
-	$letexte = str_replace('&nbsp;', '~', $letexte);
33
-	$letexte = preg_replace('/ *~+ */', '~', $letexte);
32
+    $letexte = str_replace('&nbsp;', '~', $letexte);
33
+    $letexte = preg_replace('/ *~+ */', '~', $letexte);
34 34
 
35
-	$cherche2 = [
36
-		'/([^-\n]|^)--([^-]|$)/',
37
-		'/~/'
38
-	];
39
-	$remplace2 = [
40
-		'\1&mdash;\2',
41
-		'&nbsp;'
42
-	];
35
+    $cherche2 = [
36
+        '/([^-\n]|^)--([^-]|$)/',
37
+        '/~/'
38
+    ];
39
+    $remplace2 = [
40
+        '\1&mdash;\2',
41
+        '&nbsp;'
42
+    ];
43 43
 
44
-	$letexte = preg_replace($cherche2, $remplace2, $letexte);
44
+    $letexte = preg_replace($cherche2, $remplace2, $letexte);
45 45
 
46
-	return $letexte;
46
+    return $letexte;
47 47
 }
Please login to merge, or discard this patch.
ecrire/public/quete.php 1 patch
Indentation   +408 added lines, -408 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  **/
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 
@@ -33,16 +33,16 @@  discard block
 block discarded – undo
33 33
  * @return array|bool|null
34 34
  */
35 35
 function quete_virtuel($id_article, $connect) {
36
-	return sql_getfetsel(
37
-		'virtuel',
38
-		'spip_articles',
39
-		['id_article=' . intval($id_article), "statut='publie'"],
40
-		'',
41
-		'',
42
-		'',
43
-		'',
44
-		$connect
45
-	);
36
+    return sql_getfetsel(
37
+        'virtuel',
38
+        'spip_articles',
39
+        ['id_article=' . intval($id_article), "statut='publie'"],
40
+        '',
41
+        '',
42
+        '',
43
+        '',
44
+        $connect
45
+    );
46 46
 }
47 47
 
48 48
 /**
@@ -57,41 +57,41 @@  discard block
 block discarded – undo
57 57
  * @return array
58 58
  */
59 59
 function quete_parent_lang($table, $id, $connect = '') {
60
-	static $cache_quete = [];
61
-
62
-	if (!isset($cache_quete[$connect][$table][$id])) {
63
-		if (!isset($cache_quete[$connect][$table]['_select'])) {
64
-			$trouver_table = charger_fonction('trouver_table', 'base');
65
-			if (
66
-				!$desc = $trouver_table(
67
-					$table,
68
-					$connect
69
-				) or !isset($desc['field']['id_rubrique'])
70
-			) {
71
-				// pas de parent rubrique, on passe
72
-				$cache_quete[$connect][$table]['_select'] = false;
73
-			} else {
74
-				$select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique');
75
-				$select .= isset($desc['field']['lang']) ? ', lang' : '';
76
-				$cache_quete[$connect][$table]['_select'] = $select;
77
-				$cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table));
78
-			}
79
-		}
80
-		if ($cache_quete[$connect][$table]['_select']) {
81
-			$cache_quete[$connect][$table][$id] = sql_fetsel(
82
-				$cache_quete[$connect][$table]['_select'],
83
-				$table,
84
-				$cache_quete[$connect][$table]['_id'] . '=' . intval($id),
85
-				'',
86
-				'',
87
-				'',
88
-				'',
89
-				$connect
90
-			);
91
-		}
92
-	}
93
-
94
-	return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null;
60
+    static $cache_quete = [];
61
+
62
+    if (!isset($cache_quete[$connect][$table][$id])) {
63
+        if (!isset($cache_quete[$connect][$table]['_select'])) {
64
+            $trouver_table = charger_fonction('trouver_table', 'base');
65
+            if (
66
+                !$desc = $trouver_table(
67
+                    $table,
68
+                    $connect
69
+                ) or !isset($desc['field']['id_rubrique'])
70
+            ) {
71
+                // pas de parent rubrique, on passe
72
+                $cache_quete[$connect][$table]['_select'] = false;
73
+            } else {
74
+                $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique');
75
+                $select .= isset($desc['field']['lang']) ? ', lang' : '';
76
+                $cache_quete[$connect][$table]['_select'] = $select;
77
+                $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table));
78
+            }
79
+        }
80
+        if ($cache_quete[$connect][$table]['_select']) {
81
+            $cache_quete[$connect][$table][$id] = sql_fetsel(
82
+                $cache_quete[$connect][$table]['_select'],
83
+                $table,
84
+                $cache_quete[$connect][$table]['_id'] . '=' . intval($id),
85
+                '',
86
+                '',
87
+                '',
88
+                '',
89
+                $connect
90
+            );
91
+        }
92
+    }
93
+
94
+    return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null;
95 95
 }
96 96
 
97 97
 
@@ -108,11 +108,11 @@  discard block
 block discarded – undo
108 108
  * @return int
109 109
  */
110 110
 function quete_parent($id_rubrique, $connect = '') {
111
-	if (!$id_rubrique = intval($id_rubrique)) {
112
-		return 0;
113
-	}
114
-	$id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect);
115
-	return $id_parent ? $id_parent['id_parent'] : 0;
111
+    if (!$id_rubrique = intval($id_rubrique)) {
112
+        return 0;
113
+    }
114
+    $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect);
115
+    return $id_parent ? $id_parent['id_parent'] : 0;
116 116
 }
117 117
 
118 118
 /**
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
  * @return int
129 129
  */
130 130
 function quete_rubrique($id_article, $serveur) {
131
-	$id_parent = quete_parent_lang('spip_articles', $id_article, $serveur);
131
+    $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur);
132 132
 
133
-	return $id_parent['id_rubrique'];
133
+    return $id_parent['id_rubrique'];
134 134
 }
135 135
 
136 136
 
@@ -144,13 +144,13 @@  discard block
 block discarded – undo
144 144
  * @return int
145 145
  */
146 146
 function quete_profondeur($id, $connect = '') {
147
-	$n = 0;
148
-	while ($id) {
149
-		$n++;
150
-		$id = quete_parent($id, $connect);
151
-	}
147
+    $n = 0;
148
+    while ($id) {
149
+        $n++;
150
+        $id = quete_parent($id, $connect);
151
+    }
152 152
 
153
-	return $n;
153
+    return $n;
154 154
 }
155 155
 
156 156
 
@@ -166,15 +166,15 @@  discard block
 block discarded – undo
166 166
  *     Morceau de la requête SQL testant la date
167 167
  */
168 168
 function quete_condition_postdates($champ_date, $serveur = '', $ignore_previsu = false) {
169
-	if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
170
-		return '1=1';
171
-	}
172
-
173
-	return
174
-		(isset($GLOBALS['meta']['date_prochain_postdate'])
175
-			and $GLOBALS['meta']['date_prochain_postdate'] > time())
176
-			? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur)
177
-			: '1=1';
169
+    if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
170
+        return '1=1';
171
+    }
172
+
173
+    return
174
+        (isset($GLOBALS['meta']['date_prochain_postdate'])
175
+            and $GLOBALS['meta']['date_prochain_postdate'] > time())
176
+            ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur)
177
+            : '1=1';
178 178
 }
179 179
 
180 180
 
@@ -194,101 +194,101 @@  discard block
 block discarded – undo
194 194
  * @return array|string
195 195
  */
196 196
 function quete_condition_statut($mstatut, $previsu, $publie, $serveur = '', $ignore_previsu = false) {
197
-	static $cond = [];
198
-	$key = func_get_args();
199
-	$key = implode('-', $key);
200
-	if (isset($cond[$key])) {
201
-		return $cond[$key];
202
-	}
203
-
204
-	$liste_statuts = $publie;
205
-	if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
206
-		$liste_statuts = $previsu;
207
-	}
208
-	$not = false;
209
-	if (strncmp($liste_statuts, '!', 1) == 0) {
210
-		$not = true;
211
-		$liste_statuts = substr($liste_statuts, 1);
212
-	}
213
-	// '' => ne rien afficher, '!'=> ne rien filtrer
214
-	if (!strlen($liste_statuts)) {
215
-		return $cond[$key] = ($not ? '1=1' : '0=1');
216
-	}
217
-
218
-	$liste_statuts = explode(',', $liste_statuts);
219
-	$where = [];
220
-	foreach ($liste_statuts as $k => $v) {
221
-		// filtrage /auteur pour limiter les objets d'un statut (prepa en general)
222
-		// a ceux de l'auteur identifie
223
-		if (strpos($v, '/') !== false) {
224
-			$v = explode('/', $v);
225
-			$filtre = end($v);
226
-			$v = reset($v);
227
-			$v = preg_replace(',\W,', '', $v);
228
-			if (
229
-				$filtre == 'auteur'
230
-				and (strpos($mstatut, '.') !== false)
231
-				and $objet = explode('.', $mstatut)
232
-				and $id_table = reset($objet)
233
-				and $objet = objet_type($id_table)
234
-			) {
235
-				$w = "$mstatut<>" . sql_quote($v);
236
-
237
-				// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
238
-				// sinon l’auteur en session
239
-				include_spip('inc/securiser_action');
240
-				if ($desc = decrire_token_previsu()) {
241
-					$id_auteur = $desc['id_auteur'];
242
-				} elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
243
-					$id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
244
-				} else {
245
-					$id_auteur = null;
246
-				}
247
-
248
-				// dans ce cas (admin en general), pas de filtrage sur ce statut
249
-				if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) {
250
-					// si pas d'auteur identifie pas de sous-requete car pas d'article qui matche
251
-					if (!$id_auteur) {
252
-						$where[] = $w;
253
-					} else {
254
-						$primary = id_table_objet($objet);
255
-						$where[] = "($w OR $id_table.$primary IN (" . sql_get_select(
256
-							'ssss.id_objet',
257
-							'spip_auteurs_liens AS ssss',
258
-							'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur),
259
-							'',
260
-							'',
261
-							'',
262
-							'',
263
-							$serveur
264
-						) . '))';
265
-					}
266
-				}
267
-			} // ignorer ce statut si on ne sait pas comment le filtrer
268
-			else {
269
-				$v = '';
270
-			}
271
-		}
272
-		// securite
273
-		$liste_statuts[$k] = preg_replace(',\W,', '', $v);
274
-	}
275
-	$liste_statuts = array_filter($liste_statuts);
276
-	if (count($liste_statuts) == 1) {
277
-		$where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)];
278
-	} else {
279
-		$where[] = sql_in($mstatut, $liste_statuts, $not, $serveur);
280
-	}
281
-
282
-	while (count($where) > 1) {
283
-		$and = ['AND', array_pop($where), array_pop($where)];
284
-		$where[] = $and;
285
-	}
286
-	$cond[$key] = reset($where);
287
-	if ($not) {
288
-		$cond[$key] = ['NOT', $cond[$key]];
289
-	}
290
-
291
-	return $cond[$key];
197
+    static $cond = [];
198
+    $key = func_get_args();
199
+    $key = implode('-', $key);
200
+    if (isset($cond[$key])) {
201
+        return $cond[$key];
202
+    }
203
+
204
+    $liste_statuts = $publie;
205
+    if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
206
+        $liste_statuts = $previsu;
207
+    }
208
+    $not = false;
209
+    if (strncmp($liste_statuts, '!', 1) == 0) {
210
+        $not = true;
211
+        $liste_statuts = substr($liste_statuts, 1);
212
+    }
213
+    // '' => ne rien afficher, '!'=> ne rien filtrer
214
+    if (!strlen($liste_statuts)) {
215
+        return $cond[$key] = ($not ? '1=1' : '0=1');
216
+    }
217
+
218
+    $liste_statuts = explode(',', $liste_statuts);
219
+    $where = [];
220
+    foreach ($liste_statuts as $k => $v) {
221
+        // filtrage /auteur pour limiter les objets d'un statut (prepa en general)
222
+        // a ceux de l'auteur identifie
223
+        if (strpos($v, '/') !== false) {
224
+            $v = explode('/', $v);
225
+            $filtre = end($v);
226
+            $v = reset($v);
227
+            $v = preg_replace(',\W,', '', $v);
228
+            if (
229
+                $filtre == 'auteur'
230
+                and (strpos($mstatut, '.') !== false)
231
+                and $objet = explode('.', $mstatut)
232
+                and $id_table = reset($objet)
233
+                and $objet = objet_type($id_table)
234
+            ) {
235
+                $w = "$mstatut<>" . sql_quote($v);
236
+
237
+                // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
238
+                // sinon l’auteur en session
239
+                include_spip('inc/securiser_action');
240
+                if ($desc = decrire_token_previsu()) {
241
+                    $id_auteur = $desc['id_auteur'];
242
+                } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
243
+                    $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
244
+                } else {
245
+                    $id_auteur = null;
246
+                }
247
+
248
+                // dans ce cas (admin en general), pas de filtrage sur ce statut
249
+                if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) {
250
+                    // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche
251
+                    if (!$id_auteur) {
252
+                        $where[] = $w;
253
+                    } else {
254
+                        $primary = id_table_objet($objet);
255
+                        $where[] = "($w OR $id_table.$primary IN (" . sql_get_select(
256
+                            'ssss.id_objet',
257
+                            'spip_auteurs_liens AS ssss',
258
+                            'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur),
259
+                            '',
260
+                            '',
261
+                            '',
262
+                            '',
263
+                            $serveur
264
+                        ) . '))';
265
+                    }
266
+                }
267
+            } // ignorer ce statut si on ne sait pas comment le filtrer
268
+            else {
269
+                $v = '';
270
+            }
271
+        }
272
+        // securite
273
+        $liste_statuts[$k] = preg_replace(',\W,', '', $v);
274
+    }
275
+    $liste_statuts = array_filter($liste_statuts);
276
+    if (count($liste_statuts) == 1) {
277
+        $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)];
278
+    } else {
279
+        $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur);
280
+    }
281
+
282
+    while (count($where) > 1) {
283
+        $and = ['AND', array_pop($where), array_pop($where)];
284
+        $where[] = $and;
285
+    }
286
+    $cond[$key] = reset($where);
287
+    if ($not) {
288
+        $cond[$key] = ['NOT', $cond[$key]];
289
+    }
290
+
291
+    return $cond[$key];
292 292
 }
293 293
 
294 294
 /**
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
  * @return array|bool|null
300 300
  */
301 301
 function quete_fichier($id_document, $serveur = '') {
302
-	return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur);
302
+    return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur);
303 303
 }
304 304
 
305 305
 /**
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
  * @return array|bool
311 311
  */
312 312
 function quete_document($id_document, $serveur = '') {
313
-	return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur);
313
+    return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur);
314 314
 }
315 315
 
316 316
 /**
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
  * @return array|bool|null
322 322
  */
323 323
 function quete_meta($nom, $serveur) {
324
-	return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur);
324
+    return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur);
325 325
 }
326 326
 
327 327
 /**
@@ -347,66 +347,66 @@  discard block
 block discarded – undo
347 347
  *     Retourne soit un tableau, soit le chemin du fichier.
348 348
  */
349 349
 function quete_logo($cle_objet, $onoff, $id, $id_rubrique, $flag) {
350
-	include_spip('base/objets');
351
-	$nom = strtolower($onoff);
352
-
353
-	$cle_objet = id_table_objet($cle_objet);
354
-
355
-	while (1) {
356
-		$objet = objet_type($cle_objet);
357
-
358
-		$on = quete_logo_objet($id, $objet, $nom);
359
-
360
-		if ($on) {
361
-			if ($flag) {
362
-				return basename($on['chemin']);
363
-			} else {
364
-				$taille = @spip_getimagesize($on['chemin']);
365
-
366
-				// Si on a déjà demandé un survol directement ($onoff = off)
367
-				// ou qu'on a demandé uniquement le normal ($onoff = on)
368
-				// alors on ne cherche pas du tout le survol ici
369
-				if ($onoff != 'ON') {
370
-					$off = '';
371
-				} else {
372
-					// Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol
373
-					$off = quete_logo_objet($id, $objet, 'off');
374
-				}
375
-
376
-				// on retourne une url du type IMG/artonXX?timestamp
377
-				// qui permet de distinguer le changement de logo
378
-				// et placer un expire sur le dossier IMG/
379
-				$res = [
380
-					$on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''),
381
-					($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''),
382
-					(!$taille ? '' : (' ' . $taille[3]))
383
-				];
384
-				$res['src'] = $res[0];
385
-				$res['logo_on'] = $res[0];
386
-				$res['logo_off'] = $res[1];
387
-				$res['width'] = ($taille ? $taille[0] : '');
388
-				$res['height'] = ($taille ? $taille[1] : '');
389
-
390
-				return $res;
391
-			}
392
-		} else {
393
-			if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) {
394
-				return '';
395
-			} else {
396
-				if ($id_rubrique) {
397
-					$cle_objet = 'id_rubrique';
398
-					$id = $id_rubrique;
399
-					$id_rubrique = 0;
400
-				} else {
401
-					if ($id and $cle_objet == 'id_rubrique') {
402
-						$id = quete_parent($id);
403
-					} else {
404
-						return '';
405
-					}
406
-				}
407
-			}
408
-		}
409
-	}
350
+    include_spip('base/objets');
351
+    $nom = strtolower($onoff);
352
+
353
+    $cle_objet = id_table_objet($cle_objet);
354
+
355
+    while (1) {
356
+        $objet = objet_type($cle_objet);
357
+
358
+        $on = quete_logo_objet($id, $objet, $nom);
359
+
360
+        if ($on) {
361
+            if ($flag) {
362
+                return basename($on['chemin']);
363
+            } else {
364
+                $taille = @spip_getimagesize($on['chemin']);
365
+
366
+                // Si on a déjà demandé un survol directement ($onoff = off)
367
+                // ou qu'on a demandé uniquement le normal ($onoff = on)
368
+                // alors on ne cherche pas du tout le survol ici
369
+                if ($onoff != 'ON') {
370
+                    $off = '';
371
+                } else {
372
+                    // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol
373
+                    $off = quete_logo_objet($id, $objet, 'off');
374
+                }
375
+
376
+                // on retourne une url du type IMG/artonXX?timestamp
377
+                // qui permet de distinguer le changement de logo
378
+                // et placer un expire sur le dossier IMG/
379
+                $res = [
380
+                    $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''),
381
+                    ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''),
382
+                    (!$taille ? '' : (' ' . $taille[3]))
383
+                ];
384
+                $res['src'] = $res[0];
385
+                $res['logo_on'] = $res[0];
386
+                $res['logo_off'] = $res[1];
387
+                $res['width'] = ($taille ? $taille[0] : '');
388
+                $res['height'] = ($taille ? $taille[1] : '');
389
+
390
+                return $res;
391
+            }
392
+        } else {
393
+            if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) {
394
+                return '';
395
+            } else {
396
+                if ($id_rubrique) {
397
+                    $cle_objet = 'id_rubrique';
398
+                    $id = $id_rubrique;
399
+                    $id_rubrique = 0;
400
+                } else {
401
+                    if ($id and $cle_objet == 'id_rubrique') {
402
+                        $id = quete_parent($id);
403
+                    } else {
404
+                        return '';
405
+                    }
406
+                }
407
+            }
408
+        }
409
+    }
410 410
 }
411 411
 
412 412
 /**
@@ -420,37 +420,37 @@  discard block
 block discarded – undo
420 420
  * 		"on" ou "off" suivant le logo normal ou survol
421 421
  **/
422 422
 function quete_logo_objet($id_objet, $objet, $mode) {
423
-	static $chercher_logo;
424
-	if (is_null($chercher_logo)) {
425
-		$chercher_logo = charger_fonction('chercher_logo', 'inc');
426
-	}
427
-	$cle_objet = id_table_objet($objet);
428
-
429
-	// On cherche pas la méthode classique
430
-	$infos_logo = $chercher_logo($id_objet, $cle_objet, $mode);
431
-	// Si la méthode classique a trouvé quelque chose, on utilise le nouveau format
432
-	if (!empty($infos_logo)) {
433
-		$infos_logo = [
434
-			'chemin' => $infos_logo[0],
435
-			'timestamp' => $infos_logo[4],
436
-		];
437
-	}
438
-
439
-	// On passe cette recherche de logo dans un pipeline
440
-	$infos_logo = pipeline(
441
-		'quete_logo_objet',
442
-		[
443
-			'args' => [
444
-				'id_objet' => $id_objet,
445
-				'objet' => $objet,
446
-				'cle_objet' => $cle_objet,
447
-				'mode' => $mode,
448
-			],
449
-			'data' => $infos_logo,
450
-		]
451
-	);
452
-
453
-	return $infos_logo;
423
+    static $chercher_logo;
424
+    if (is_null($chercher_logo)) {
425
+        $chercher_logo = charger_fonction('chercher_logo', 'inc');
426
+    }
427
+    $cle_objet = id_table_objet($objet);
428
+
429
+    // On cherche pas la méthode classique
430
+    $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode);
431
+    // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format
432
+    if (!empty($infos_logo)) {
433
+        $infos_logo = [
434
+            'chemin' => $infos_logo[0],
435
+            'timestamp' => $infos_logo[4],
436
+        ];
437
+    }
438
+
439
+    // On passe cette recherche de logo dans un pipeline
440
+    $infos_logo = pipeline(
441
+        'quete_logo_objet',
442
+        [
443
+            'args' => [
444
+                'id_objet' => $id_objet,
445
+                'objet' => $objet,
446
+                'cle_objet' => $cle_objet,
447
+                'mode' => $mode,
448
+            ],
449
+            'data' => $infos_logo,
450
+        ]
451
+    );
452
+
453
+    return $infos_logo;
454 454
 }
455 455
 
456 456
 /**
@@ -463,25 +463,25 @@  discard block
 block discarded – undo
463 463
  * @return bool|string
464 464
  */
465 465
 function quete_logo_file($row, $connect = null) {
466
-	include_spip('inc/documents');
467
-	$logo = vignette_logo_document($row, $connect);
468
-	if (!$logo) {
469
-		$logo = image_du_document($row, $connect);
470
-	}
471
-	if (!$logo) {
472
-		$f = charger_fonction('vignette', 'inc');
473
-		$logo = $f($row['extension'], false);
474
-	}
475
-	// si c'est une vignette type doc, la renvoyer direct
476
-	if (
477
-		strcmp($logo, _DIR_PLUGINS) == 0
478
-		or strcmp($logo, _DIR_PLUGINS_DIST) == 0
479
-		or strcmp($logo, _DIR_RACINE . 'prive/') == 0
480
-	) {
481
-		return $logo;
482
-	}
483
-
484
-	return get_spip_doc($logo);
466
+    include_spip('inc/documents');
467
+    $logo = vignette_logo_document($row, $connect);
468
+    if (!$logo) {
469
+        $logo = image_du_document($row, $connect);
470
+    }
471
+    if (!$logo) {
472
+        $f = charger_fonction('vignette', 'inc');
473
+        $logo = $f($row['extension'], false);
474
+    }
475
+    // si c'est une vignette type doc, la renvoyer direct
476
+    if (
477
+        strcmp($logo, _DIR_PLUGINS) == 0
478
+        or strcmp($logo, _DIR_PLUGINS_DIST) == 0
479
+        or strcmp($logo, _DIR_RACINE . 'prive/') == 0
480
+    ) {
481
+        return $logo;
482
+    }
483
+
484
+    return get_spip_doc($logo);
485 485
 }
486 486
 
487 487
 /**
@@ -509,20 +509,20 @@  discard block
 block discarded – undo
509 509
  */
510 510
 function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, $connect = null) {
511 511
 
512
-	include_spip('inc/documents');
513
-	$logo = '';
514
-	if (!in_array($mode_logo, ['icone', 'apercu'])) {
515
-		$logo = vignette_logo_document($row, $connect);
516
-	}
517
-	// si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas
518
-	if ($mode_logo == 'vignette' and !$logo) {
519
-		return '';
520
-	}
521
-	if ($mode_logo == 'icone') {
522
-		$row['fichier'] = '';
523
-	}
524
-
525
-	return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect);
512
+    include_spip('inc/documents');
513
+    $logo = '';
514
+    if (!in_array($mode_logo, ['icone', 'apercu'])) {
515
+        $logo = vignette_logo_document($row, $connect);
516
+    }
517
+    // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas
518
+    if ($mode_logo == 'vignette' and !$logo) {
519
+        return '';
520
+    }
521
+    if ($mode_logo == 'icone') {
522
+        $row['fichier'] = '';
523
+    }
524
+
525
+    return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect);
526 526
 }
527 527
 
528 528
 /**
@@ -534,19 +534,19 @@  discard block
 block discarded – undo
534 534
  */
535 535
 function quete_html_logo($logo, $align, $lien) {
536 536
 
537
-	if (!is_array($logo)) {
538
-		return '';
539
-	}
540
-
541
-	$contexte = [];
542
-	foreach ($logo as $k => $v) {
543
-		if (!is_numeric($k)) {
544
-			$contexte[$k] = $v;
545
-		}
546
-	}
547
-	$contexte['align'] = $align;
548
-	$contexte['lien'] = $lien;
549
-	return recuperer_fond('modeles/logo', $contexte);
537
+    if (!is_array($logo)) {
538
+        return '';
539
+    }
540
+
541
+    $contexte = [];
542
+    foreach ($logo as $k => $v) {
543
+        if (!is_numeric($k)) {
544
+            $contexte[$k] = $v;
545
+        }
546
+    }
547
+    $contexte['align'] = $align;
548
+    $contexte['lien'] = $lien;
549
+    return recuperer_fond('modeles/logo', $contexte);
550 550
 }
551 551
 
552 552
 /**
@@ -560,14 +560,14 @@  discard block
 block discarded – undo
560 560
  * @return string|false
561 561
  */
562 562
 function document_spip_externe($fichier, $connect) {
563
-	if ($connect) {
564
-		$site = quete_meta('adresse_site', $connect);
565
-		if ($site) {
566
-			$dir = quete_meta('dir_img', $connect);
567
-			return "$site/$dir$fichier";
568
-		}
569
-	}
570
-	return false;
563
+    if ($connect) {
564
+        $site = quete_meta('adresse_site', $connect);
565
+        if ($site) {
566
+            $dir = quete_meta('dir_img', $connect);
567
+            return "$site/$dir$fichier";
568
+        }
569
+    }
570
+    return false;
571 571
 }
572 572
 
573 573
 /**
@@ -580,23 +580,23 @@  discard block
 block discarded – undo
580 580
  * @return string
581 581
  */
582 582
 function vignette_logo_document($row, $connect = '') {
583
-	if (!$row['id_vignette']) {
584
-		return '';
585
-	}
586
-	$fichier = quete_fichier($row['id_vignette'], $connect);
587
-	if ($url = document_spip_externe($fichier, $connect)) {
588
-		return $url;
589
-	}
590
-
591
-	$f = get_spip_doc($fichier);
592
-	if ($f and @file_exists($f)) {
593
-		return $f;
594
-	}
595
-	if ($row['mode'] !== 'vignette') {
596
-		return '';
597
-	}
598
-
599
-	return generer_url_entite($row['id_document'], 'document', '', '', $connect);
583
+    if (!$row['id_vignette']) {
584
+        return '';
585
+    }
586
+    $fichier = quete_fichier($row['id_vignette'], $connect);
587
+    if ($url = document_spip_externe($fichier, $connect)) {
588
+        return $url;
589
+    }
590
+
591
+    $f = get_spip_doc($fichier);
592
+    if ($f and @file_exists($f)) {
593
+        return $f;
594
+    }
595
+    if ($row['mode'] !== 'vignette') {
596
+        return '';
597
+    }
598
+
599
+    return generer_url_entite($row['id_document'], 'document', '', '', $connect);
600 600
 }
601 601
 
602 602
 /**
@@ -612,69 +612,69 @@  discard block
 block discarded – undo
612 612
  * @return bool|string
613 613
  */
614 614
 function calcul_exposer($id, $prim, $reference, $parent, $type, $connect = '') {
615
-	static $exposer = [];
616
-
617
-	// Que faut-il exposer ? Tous les elements de $reference
618
-	// ainsi que leur hierarchie ; on ne fait donc ce calcul
619
-	// qu'une fois (par squelette) et on conserve le resultat
620
-	// en static.
621
-	if (!isset($exposer[$m = md5(serialize($reference))][$prim])) {
622
-		$principal = isset($reference[$type]) ? $reference[$type] :
623
-			// cas de la pagination indecte @xx qui positionne la page avec l'id xx
624
-			// et donne la reference dynamique @type=xx dans le contexte
625
-			(isset($reference["@$type"]) ? $reference["@$type"] : '');
626
-		// le parent fournit en argument est le parent de $id, pas celui de $principal
627
-		// il n'est donc pas utile
628
-		$parent = 0;
629
-		if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant
630
-			$enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']];
631
-			if (isset($enfants[$type])) {
632
-				foreach ($enfants[$type] as $t) {
633
-					if (
634
-						isset($reference[$t])
635
-						// cas de la reference donnee dynamiquement par la pagination
636
-						or isset($reference["@$t"])
637
-					) {
638
-						$type = $t;
639
-						$principal = isset($reference[$type]) ? $reference[$type] : $reference["@$type"];
640
-						continue;
641
-					}
642
-				}
643
-			}
644
-		}
645
-		$exposer[$m][$type] = [];
646
-		if ($principal) {
647
-			$principaux = is_array($principal) ? $principal : [$principal];
648
-			foreach ($principaux as $principal) {
649
-				$exposer[$m][$type][$principal] = true;
650
-				if ($type == 'id_mot') {
651
-					if (!$parent) {
652
-						$parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect);
653
-					}
654
-					if ($parent) {
655
-						$exposer[$m]['id_groupe'][$parent] = true;
656
-					}
657
-				} else {
658
-					if ($type != 'id_groupe') {
659
-						if (!$parent) {
660
-							if ($type == 'id_rubrique') {
661
-								$parent = $principal;
662
-							}
663
-							if ($type == 'id_article') {
664
-								$parent = quete_rubrique($principal, $connect);
665
-							}
666
-						}
667
-						do {
668
-							$exposer[$m]['id_rubrique'][$parent] = true;
669
-						} while ($parent = quete_parent($parent, $connect));
670
-					}
671
-				}
672
-			}
673
-		}
674
-	}
675
-
676
-	// And the winner is...
677
-	return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : '';
615
+    static $exposer = [];
616
+
617
+    // Que faut-il exposer ? Tous les elements de $reference
618
+    // ainsi que leur hierarchie ; on ne fait donc ce calcul
619
+    // qu'une fois (par squelette) et on conserve le resultat
620
+    // en static.
621
+    if (!isset($exposer[$m = md5(serialize($reference))][$prim])) {
622
+        $principal = isset($reference[$type]) ? $reference[$type] :
623
+            // cas de la pagination indecte @xx qui positionne la page avec l'id xx
624
+            // et donne la reference dynamique @type=xx dans le contexte
625
+            (isset($reference["@$type"]) ? $reference["@$type"] : '');
626
+        // le parent fournit en argument est le parent de $id, pas celui de $principal
627
+        // il n'est donc pas utile
628
+        $parent = 0;
629
+        if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant
630
+            $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']];
631
+            if (isset($enfants[$type])) {
632
+                foreach ($enfants[$type] as $t) {
633
+                    if (
634
+                        isset($reference[$t])
635
+                        // cas de la reference donnee dynamiquement par la pagination
636
+                        or isset($reference["@$t"])
637
+                    ) {
638
+                        $type = $t;
639
+                        $principal = isset($reference[$type]) ? $reference[$type] : $reference["@$type"];
640
+                        continue;
641
+                    }
642
+                }
643
+            }
644
+        }
645
+        $exposer[$m][$type] = [];
646
+        if ($principal) {
647
+            $principaux = is_array($principal) ? $principal : [$principal];
648
+            foreach ($principaux as $principal) {
649
+                $exposer[$m][$type][$principal] = true;
650
+                if ($type == 'id_mot') {
651
+                    if (!$parent) {
652
+                        $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect);
653
+                    }
654
+                    if ($parent) {
655
+                        $exposer[$m]['id_groupe'][$parent] = true;
656
+                    }
657
+                } else {
658
+                    if ($type != 'id_groupe') {
659
+                        if (!$parent) {
660
+                            if ($type == 'id_rubrique') {
661
+                                $parent = $principal;
662
+                            }
663
+                            if ($type == 'id_article') {
664
+                                $parent = quete_rubrique($principal, $connect);
665
+                            }
666
+                        }
667
+                        do {
668
+                            $exposer[$m]['id_rubrique'][$parent] = true;
669
+                        } while ($parent = quete_parent($parent, $connect));
670
+                    }
671
+                }
672
+            }
673
+        }
674
+    }
675
+
676
+    // And the winner is...
677
+    return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : '';
678 678
 }
679 679
 
680 680
 /**
@@ -689,21 +689,21 @@  discard block
 block discarded – undo
689 689
  * @return int
690 690
  */
691 691
 function quete_debut_pagination($primary, $valeur, $pas, $iter) {
692
-	// on ne devrait pas arriver ici si la cle primaire est inexistante
693
-	// ou composee, mais verifions
694
-	if (!$primary or preg_match('/[,\s]/', $primary)) {
695
-		return 0;
696
-	}
697
-
698
-	$pos = 0;
699
-	while ($row = $iter->fetch() and $row[$primary] != $valeur) {
700
-		$pos++;
701
-	}
702
-	// si on a pas trouve
703
-	if (!$row or $row[$primary] != $valeur) {
704
-		return 0;
705
-	}
706
-
707
-	// sinon, calculer le bon numero de page
708
-	return floor($pos / $pas) * $pas;
692
+    // on ne devrait pas arriver ici si la cle primaire est inexistante
693
+    // ou composee, mais verifions
694
+    if (!$primary or preg_match('/[,\s]/', $primary)) {
695
+        return 0;
696
+    }
697
+
698
+    $pos = 0;
699
+    while ($row = $iter->fetch() and $row[$primary] != $valeur) {
700
+        $pos++;
701
+    }
702
+    // si on a pas trouve
703
+    if (!$row or $row[$primary] != $valeur) {
704
+        return 0;
705
+    }
706
+
707
+    // sinon, calculer le bon numero de page
708
+    return floor($pos / $pas) * $pas;
709 709
 }
Please login to merge, or discard this patch.
ecrire/public/references.php 1 patch
Indentation   +521 added lines, -521 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Compilateur\References
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -41,14 +41,14 @@  discard block
 block discarded – undo
41 41
  *     - '' si une référence explicite incorrecte est envoyée
42 42
  */
43 43
 function index_boucle($p) {
44
-	if (strlen($p->nom_boucle)) {
45
-		// retourne l’index explicite demandé s’il existe
46
-		if (!empty($p->boucles[$p->nom_boucle])) {
47
-			return $p->nom_boucle;
48
-		}
49
-		return '';
50
-	}
51
-	return $p->id_boucle;
44
+    if (strlen($p->nom_boucle)) {
45
+        // retourne l’index explicite demandé s’il existe
46
+        if (!empty($p->boucles[$p->nom_boucle])) {
47
+            return $p->nom_boucle;
48
+        }
49
+        return '';
50
+    }
51
+    return $p->id_boucle;
52 52
 }
53 53
 
54 54
 
@@ -71,17 +71,17 @@  discard block
 block discarded – undo
71 71
  *     - '' si une référence explicite incorrecte est envoyée
72 72
  */
73 73
 function index_boucle_mere($p) {
74
-	if (strlen($p->nom_boucle)) {
75
-		// retourne l’index explicite demandé s’il existe
76
-		if (!empty($p->boucles[$p->nom_boucle])) {
77
-			return $p->nom_boucle;
78
-		}
79
-		return '';
80
-	}
81
-	if (!empty($p->descr['id_mere'])) {
82
-		return $p->descr['id_mere'];
83
-	}
84
-	return '';
74
+    if (strlen($p->nom_boucle)) {
75
+        // retourne l’index explicite demandé s’il existe
76
+        if (!empty($p->boucles[$p->nom_boucle])) {
77
+            return $p->nom_boucle;
78
+        }
79
+        return '';
80
+    }
81
+    if (!empty($p->descr['id_mere'])) {
82
+        return $p->descr['id_mere'];
83
+    }
84
+    return '';
85 85
 }
86 86
 
87 87
 /**
@@ -115,74 +115,74 @@  discard block
 block discarded – undo
115 115
  *     Code PHP pour obtenir le champ SQL
116 116
  */
117 117
 function index_pile(
118
-	$idb,
119
-	$nom_champ,
120
-	&$boucles,
121
-	$explicite = '',
122
-	$defaut = null,
123
-	$remonte_pile = true,
124
-	$select = true
118
+    $idb,
119
+    $nom_champ,
120
+    &$boucles,
121
+    $explicite = '',
122
+    $defaut = null,
123
+    $remonte_pile = true,
124
+    $select = true
125 125
 ) {
126
-	if (!is_string($defaut)) {
127
-		$defaut = '@$Pile[0][\'' . strtolower($nom_champ) . '\']';
128
-	}
129
-
130
-	$idb_origine = $idb;
131
-	$nom_champ_origine = $nom_champ;
132
-
133
-	$i = 0;
134
-	if (strlen($explicite)) {
135
-		// Recherche d'un champ dans un etage superieur
136
-		while (($idb !== $explicite) && ($idb !== '')) {
137
-			#	spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'");
138
-			$i++;
139
-			$idb = $boucles[$idb]->id_parent;
140
-		}
141
-	}
142
-
143
-	#	spip_log("Cherche: $nom_champ a partir de '$idb'");
144
-	$nom_champ = strtolower($nom_champ);
145
-	$conditionnel = [];
146
-	// attention: entre la boucle nommee 0, "" et le tableau vide,
147
-	// il y a incoherences qu'il vaut mieux eviter
148
-	while (isset($boucles[$idb])) {
149
-		$joker = true;
150
-		// modifie $joker si tous les champs sont autorisés.
151
-		// $t = le select pour le champ, si on l'a trouvé (ou si joker)
152
-		// $c = le nom du champ demandé
153
-		list($t, $c) = index_tables_en_pile($idb, $nom_champ, $boucles, $joker);
154
-		if ($t) {
155
-			if ($select and !in_array($t, $boucles[$idb]->select)) {
156
-				$boucles[$idb]->select[] = $t;
157
-			}
158
-			// renseigner la boucle source de ce champ pour les traitements
159
-			$boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb;
160
-			$champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']';
161
-			if (!$joker) {
162
-				return index_compose($conditionnel, $champ);
163
-			}
164
-
165
-			// tant que l'on trouve des tables avec joker, on continue
166
-			// avec la boucle parente et on conditionne à l'exécution
167
-			// la présence du champ. Si le champ existe à l'exécution
168
-			// dans une boucle, il est pris, sinon on le cherche dans le parent...
169
-			$conditionnel[] = "isset($champ)?$champ";
170
-		}
171
-
172
-		if ($remonte_pile) {
173
-			#	spip_log("On remonte vers $i");
174
-			// Sinon on remonte d'un cran
175
-			$idb = $boucles[$idb]->id_parent;
176
-			$i++;
177
-		} else {
178
-			$idb = null;
179
-		}
180
-	}
181
-
182
-	#	spip_log("Pas vu $nom_champ");
183
-	// esperons qu'il y sera
184
-	// ou qu'on a fourni une valeur par "defaut" plus pertinent
185
-	return index_compose($conditionnel, $defaut);
126
+    if (!is_string($defaut)) {
127
+        $defaut = '@$Pile[0][\'' . strtolower($nom_champ) . '\']';
128
+    }
129
+
130
+    $idb_origine = $idb;
131
+    $nom_champ_origine = $nom_champ;
132
+
133
+    $i = 0;
134
+    if (strlen($explicite)) {
135
+        // Recherche d'un champ dans un etage superieur
136
+        while (($idb !== $explicite) && ($idb !== '')) {
137
+            #	spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'");
138
+            $i++;
139
+            $idb = $boucles[$idb]->id_parent;
140
+        }
141
+    }
142
+
143
+    #	spip_log("Cherche: $nom_champ a partir de '$idb'");
144
+    $nom_champ = strtolower($nom_champ);
145
+    $conditionnel = [];
146
+    // attention: entre la boucle nommee 0, "" et le tableau vide,
147
+    // il y a incoherences qu'il vaut mieux eviter
148
+    while (isset($boucles[$idb])) {
149
+        $joker = true;
150
+        // modifie $joker si tous les champs sont autorisés.
151
+        // $t = le select pour le champ, si on l'a trouvé (ou si joker)
152
+        // $c = le nom du champ demandé
153
+        list($t, $c) = index_tables_en_pile($idb, $nom_champ, $boucles, $joker);
154
+        if ($t) {
155
+            if ($select and !in_array($t, $boucles[$idb]->select)) {
156
+                $boucles[$idb]->select[] = $t;
157
+            }
158
+            // renseigner la boucle source de ce champ pour les traitements
159
+            $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb;
160
+            $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']';
161
+            if (!$joker) {
162
+                return index_compose($conditionnel, $champ);
163
+            }
164
+
165
+            // tant que l'on trouve des tables avec joker, on continue
166
+            // avec la boucle parente et on conditionne à l'exécution
167
+            // la présence du champ. Si le champ existe à l'exécution
168
+            // dans une boucle, il est pris, sinon on le cherche dans le parent...
169
+            $conditionnel[] = "isset($champ)?$champ";
170
+        }
171
+
172
+        if ($remonte_pile) {
173
+            #	spip_log("On remonte vers $i");
174
+            // Sinon on remonte d'un cran
175
+            $idb = $boucles[$idb]->id_parent;
176
+            $i++;
177
+        } else {
178
+            $idb = null;
179
+        }
180
+    }
181
+
182
+    #	spip_log("Pas vu $nom_champ");
183
+    // esperons qu'il y sera
184
+    // ou qu'on a fourni une valeur par "defaut" plus pertinent
185
+    return index_compose($conditionnel, $defaut);
186 186
 }
187 187
 
188 188
 /**
@@ -196,12 +196,12 @@  discard block
 block discarded – undo
196 196
  * @return string              Code PHP complet de recherche d'un champ
197 197
  */
198 198
 function index_compose($conditionnel, $defaut) {
199
-	while ($c = array_pop($conditionnel)) {
200
-		// si on passe defaut = '', ne pas générer d'erreur de compilation.
201
-		$defaut = "($c:(" . ($defaut ? $defaut : "''") . '))';
202
-	}
199
+    while ($c = array_pop($conditionnel)) {
200
+        // si on passe defaut = '', ne pas générer d'erreur de compilation.
201
+        $defaut = "($c:(" . ($defaut ? $defaut : "''") . '))';
202
+    }
203 203
 
204
-	return $defaut;
204
+    return $defaut;
205 205
 }
206 206
 
207 207
 /**
@@ -237,77 +237,77 @@  discard block
 block discarded – undo
237 237
  **/
238 238
 function index_tables_en_pile($idb, $nom_champ, &$boucles, &$joker) {
239 239
 
240
-	$r = $boucles[$idb]->type_requete;
241
-	// boucle recursive, c'est foutu...
242
-	if ($r == TYPE_RECURSIF) {
243
-		return [];
244
-	}
245
-	if (!$r) {
246
-		$joker = false; // indiquer a l'appelant
247
-		# continuer pour chercher l'erreur suivante
248
-		return ["'#" . $r . ':' . $nom_champ . "'", ''];
249
-	}
250
-
251
-	$desc = $boucles[$idb]->show;
252
-	// le nom du champ est il une exception de la table ? un alias ?
253
-	$excep = isset($GLOBALS['exceptions_des_tables'][$r]) ? $GLOBALS['exceptions_des_tables'][$r] : '';
254
-	if ($excep) {
255
-		$excep = isset($excep[$nom_champ]) ? $excep[$nom_champ] : '';
256
-	}
257
-	if ($excep) {
258
-		$joker = false; // indiquer a l'appelant
259
-		return index_exception($boucles[$idb], $desc, $nom_champ, $excep);
260
-	} // pas d'alias. Le champ existe t'il ?
261
-	else {
262
-		// le champ est réellement présent, on le prend.
263
-		if (isset($desc['field'][$nom_champ])) {
264
-			$t = $boucles[$idb]->id_table;
265
-			$joker = false; // indiquer a l'appelant
266
-			return ["$t.$nom_champ", $nom_champ];
267
-		}
268
-		// Tous les champs sont-ils acceptés ?
269
-		// Si oui, on retourne le champ, et on lève le flag joker
270
-		// C'est le cas des itérateurs DATA qui acceptent tout
271
-		// et testent la présence du champ à l'exécution et non à la compilation
272
-		// car ils ne connaissent pas ici leurs contenus.
273
-		elseif (
240
+    $r = $boucles[$idb]->type_requete;
241
+    // boucle recursive, c'est foutu...
242
+    if ($r == TYPE_RECURSIF) {
243
+        return [];
244
+    }
245
+    if (!$r) {
246
+        $joker = false; // indiquer a l'appelant
247
+        # continuer pour chercher l'erreur suivante
248
+        return ["'#" . $r . ':' . $nom_champ . "'", ''];
249
+    }
250
+
251
+    $desc = $boucles[$idb]->show;
252
+    // le nom du champ est il une exception de la table ? un alias ?
253
+    $excep = isset($GLOBALS['exceptions_des_tables'][$r]) ? $GLOBALS['exceptions_des_tables'][$r] : '';
254
+    if ($excep) {
255
+        $excep = isset($excep[$nom_champ]) ? $excep[$nom_champ] : '';
256
+    }
257
+    if ($excep) {
258
+        $joker = false; // indiquer a l'appelant
259
+        return index_exception($boucles[$idb], $desc, $nom_champ, $excep);
260
+    } // pas d'alias. Le champ existe t'il ?
261
+    else {
262
+        // le champ est réellement présent, on le prend.
263
+        if (isset($desc['field'][$nom_champ])) {
264
+            $t = $boucles[$idb]->id_table;
265
+            $joker = false; // indiquer a l'appelant
266
+            return ["$t.$nom_champ", $nom_champ];
267
+        }
268
+        // Tous les champs sont-ils acceptés ?
269
+        // Si oui, on retourne le champ, et on lève le flag joker
270
+        // C'est le cas des itérateurs DATA qui acceptent tout
271
+        // et testent la présence du champ à l'exécution et non à la compilation
272
+        // car ils ne connaissent pas ici leurs contenus.
273
+        elseif (
274 274
 /*$joker AND */
275
-			isset($desc['field']['*'])
276
-		) {
277
-			$joker = true; // indiquer a l'appelant
278
-			return [$nom_champ, $nom_champ];
279
-		}
280
-		// pas d'alias, pas de champ, pas de joker...
281
-		// tenter via une jointure...
282
-		else {
283
-			$joker = false; // indiquer a l'appelant
284
-			// regarder si le champ est deja dans une jointure existante
285
-			// sinon, si il y a des joitures explicites, la construire
286
-			if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) {
287
-				if ($boucles[$idb]->jointures_explicites) {
288
-					// [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!!
289
-					// fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites
290
-					// mais est-ce ce qu'on veut ?
291
-					$jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites);
292
-					if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) {
293
-						$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]);
294
-					}
295
-				}
296
-			}
297
-			if ($t) {
298
-				// si on a trouvé une jointure possible, on fait comme
299
-				// si c'était une exception pour le champ demandé
300
-				return index_exception(
301
-					$boucles[$idb],
302
-					$desc,
303
-					$nom_champ,
304
-					[$t[1]['id_table'], reset($t[2])]
305
-				);
306
-			}
307
-
308
-			return ['', ''];
309
-		}
310
-	}
275
+            isset($desc['field']['*'])
276
+        ) {
277
+            $joker = true; // indiquer a l'appelant
278
+            return [$nom_champ, $nom_champ];
279
+        }
280
+        // pas d'alias, pas de champ, pas de joker...
281
+        // tenter via une jointure...
282
+        else {
283
+            $joker = false; // indiquer a l'appelant
284
+            // regarder si le champ est deja dans une jointure existante
285
+            // sinon, si il y a des joitures explicites, la construire
286
+            if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) {
287
+                if ($boucles[$idb]->jointures_explicites) {
288
+                    // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!!
289
+                    // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites
290
+                    // mais est-ce ce qu'on veut ?
291
+                    $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites);
292
+                    if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) {
293
+                        $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]);
294
+                    }
295
+                }
296
+            }
297
+            if ($t) {
298
+                // si on a trouvé une jointure possible, on fait comme
299
+                // si c'était une exception pour le champ demandé
300
+                return index_exception(
301
+                    $boucles[$idb],
302
+                    $desc,
303
+                    $nom_champ,
304
+                    [$t[1]['id_table'], reset($t[2])]
305
+                );
306
+            }
307
+
308
+            return ['', ''];
309
+        }
310
+    }
311 311
 }
312 312
 
313 313
 
@@ -335,52 +335,52 @@  discard block
 block discarded – undo
335 335
  *     est une expression pour le SELECT de la boucle du style "mots.titre AS titre_mot"
336 336
  **/
337 337
 function index_exception(&$boucle, $desc, $nom_champ, $excep) {
338
-	static $trouver_table;
339
-	if (!$trouver_table) {
340
-		$trouver_table = charger_fonction('trouver_table', 'base');
341
-	}
342
-
343
-	if (is_array($excep)) {
344
-		// permettre aux plugins de gerer eux meme des jointures derogatoire ingerables
345
-		$t = null;
346
-		if (count($excep) == 3) {
347
-			$index_exception_derogatoire = array_pop($excep);
348
-			$t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep);
349
-		}
350
-		if ($t == null) {
351
-			list($e, $x) = $excep;  #PHP4 affecte de gauche a droite
352
-			$excep = $x;    #PHP5 de droite a gauche !
353
-			$j = $trouver_table($e, $boucle->sql_serveur);
354
-			if (!$j) {
355
-				return ['', ''];
356
-			}
357
-			$e = $j['table'];
358
-			if (!$t = array_search($e, $boucle->from)) {
359
-				$k = $j['key']['PRIMARY KEY'];
360
-				if (strpos($k, ',')) {
361
-					$l = (preg_split('/\s*,\s*/', $k));
362
-					$k = $desc['key']['PRIMARY KEY'];
363
-					if (!in_array($k, $l)) {
364
-						spip_log("jointure impossible $e " . join(',', $l));
365
-
366
-						return ['', ''];
367
-					}
368
-				}
369
-				$k = [$boucle->id_table, [$e], $k];
370
-				fabrique_jointures($boucle, [$k]);
371
-				$t = array_search($e, $boucle->from);
372
-			}
373
-		}
374
-	} else {
375
-		$t = $boucle->id_table;
376
-	}
377
-	// demander a SQL de gerer le synonyme
378
-	// ca permet que excep soit dynamique (Cedric, 2/3/06)
379
-	if ($excep != $nom_champ) {
380
-		$excep .= ' AS ' . $nom_champ;
381
-	}
382
-
383
-	return ["$t.$excep", $nom_champ];
338
+    static $trouver_table;
339
+    if (!$trouver_table) {
340
+        $trouver_table = charger_fonction('trouver_table', 'base');
341
+    }
342
+
343
+    if (is_array($excep)) {
344
+        // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables
345
+        $t = null;
346
+        if (count($excep) == 3) {
347
+            $index_exception_derogatoire = array_pop($excep);
348
+            $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep);
349
+        }
350
+        if ($t == null) {
351
+            list($e, $x) = $excep;  #PHP4 affecte de gauche a droite
352
+            $excep = $x;    #PHP5 de droite a gauche !
353
+            $j = $trouver_table($e, $boucle->sql_serveur);
354
+            if (!$j) {
355
+                return ['', ''];
356
+            }
357
+            $e = $j['table'];
358
+            if (!$t = array_search($e, $boucle->from)) {
359
+                $k = $j['key']['PRIMARY KEY'];
360
+                if (strpos($k, ',')) {
361
+                    $l = (preg_split('/\s*,\s*/', $k));
362
+                    $k = $desc['key']['PRIMARY KEY'];
363
+                    if (!in_array($k, $l)) {
364
+                        spip_log("jointure impossible $e " . join(',', $l));
365
+
366
+                        return ['', ''];
367
+                    }
368
+                }
369
+                $k = [$boucle->id_table, [$e], $k];
370
+                fabrique_jointures($boucle, [$k]);
371
+                $t = array_search($e, $boucle->from);
372
+            }
373
+        }
374
+    } else {
375
+        $t = $boucle->id_table;
376
+    }
377
+    // demander a SQL de gerer le synonyme
378
+    // ca permet que excep soit dynamique (Cedric, 2/3/06)
379
+    if ($excep != $nom_champ) {
380
+        $excep .= ' AS ' . $nom_champ;
381
+    }
382
+
383
+    return ["$t.$excep", $nom_champ];
384 384
 }
385 385
 
386 386
 /**
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
  *     Code PHP pour retrouver le champ
406 406
  */
407 407
 function champ_sql($champ, $p, $defaut = null, $remonte_pile = true) {
408
-	return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile);
408
+    return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile);
409 409
 }
410 410
 
411 411
 
@@ -425,9 +425,9 @@  discard block
 block discarded – undo
425 425
  *     Code PHP pour d'exécution de la balise et de ses filtres
426 426
  **/
427 427
 function calculer_champ($p) {
428
-	$p = calculer_balise($p->nom_champ, $p);
428
+    $p = calculer_balise($p->nom_champ, $p);
429 429
 
430
-	return applique_filtres($p);
430
+    return applique_filtres($p);
431 431
 }
432 432
 
433 433
 
@@ -464,26 +464,26 @@  discard block
 block discarded – undo
464 464
  **/
465 465
 function calculer_balise($nom, $p) {
466 466
 
467
-	// S'agit-t-il d'une balise_XXXX[_dist]() ?
468
-	if ($f = charger_fonction($nom, 'balise', true)) {
469
-		$p->balise_calculee = true;
470
-		$res = $f($p);
471
-		if ($res !== null and is_object($res)) {
472
-			return $res;
473
-		}
474
-	}
475
-
476
-	// Certaines des balises comportant un _ sont generiques
477
-	if ($balise_generique = chercher_balise_generique($nom)) {
478
-		$res = $balise_generique['fonction_generique']($p);
479
-		if ($res !== null and is_object($res)) {
480
-			return $res;
481
-		}
482
-	}
483
-
484
-	$f = charger_fonction('DEFAUT', 'calculer_balise');
485
-
486
-	return $f($nom, $p);
467
+    // S'agit-t-il d'une balise_XXXX[_dist]() ?
468
+    if ($f = charger_fonction($nom, 'balise', true)) {
469
+        $p->balise_calculee = true;
470
+        $res = $f($p);
471
+        if ($res !== null and is_object($res)) {
472
+            return $res;
473
+        }
474
+    }
475
+
476
+    // Certaines des balises comportant un _ sont generiques
477
+    if ($balise_generique = chercher_balise_generique($nom)) {
478
+        $res = $balise_generique['fonction_generique']($p);
479
+        if ($res !== null and is_object($res)) {
480
+            return $res;
481
+        }
482
+    }
483
+
484
+    $f = charger_fonction('DEFAUT', 'calculer_balise');
485
+
486
+    return $f($nom, $p);
487 487
 }
488 488
 
489 489
 
@@ -511,37 +511,37 @@  discard block
 block discarded – undo
511 511
  **/
512 512
 function calculer_balise_DEFAUT_dist($nom, $p) {
513 513
 
514
-	// ca pourrait etre un champ SQL homonyme,
515
-	$p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle);
516
-
517
-	// compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour
518
-	// il faut recracher {...} quand ce n'est finalement pas des args
519
-	if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) {
520
-		$code = addslashes($p->fonctions[0][1]);
521
-		$p->code .= " . '$code'";
522
-	}
523
-
524
-	// ne pas passer le filtre securite sur les id_xxx
525
-	if (strpos($nom, 'ID_') === 0) {
526
-		$p->interdire_scripts = false;
527
-	}
528
-
529
-	// Compatibilite ascendante avec les couleurs html (#FEFEFE) :
530
-	// SI le champ SQL n'est pas trouve
531
-	// ET si la balise a une forme de couleur
532
-	// ET s'il n'y a ni filtre ni etoile
533
-	// ALORS retourner la couleur.
534
-	// Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)]
535
-	if (
536
-		preg_match('/^[A-F]{1,6}$/i', $nom)
537
-		and !$p->etoile
538
-		and !$p->fonctions
539
-	) {
540
-		$p->code = "'#$nom'";
541
-		$p->interdire_scripts = false;
542
-	}
543
-
544
-	return $p;
514
+    // ca pourrait etre un champ SQL homonyme,
515
+    $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle);
516
+
517
+    // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour
518
+    // il faut recracher {...} quand ce n'est finalement pas des args
519
+    if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) {
520
+        $code = addslashes($p->fonctions[0][1]);
521
+        $p->code .= " . '$code'";
522
+    }
523
+
524
+    // ne pas passer le filtre securite sur les id_xxx
525
+    if (strpos($nom, 'ID_') === 0) {
526
+        $p->interdire_scripts = false;
527
+    }
528
+
529
+    // Compatibilite ascendante avec les couleurs html (#FEFEFE) :
530
+    // SI le champ SQL n'est pas trouve
531
+    // ET si la balise a une forme de couleur
532
+    // ET s'il n'y a ni filtre ni etoile
533
+    // ALORS retourner la couleur.
534
+    // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)]
535
+    if (
536
+        preg_match('/^[A-F]{1,6}$/i', $nom)
537
+        and !$p->etoile
538
+        and !$p->fonctions
539
+    ) {
540
+        $p->code = "'#$nom'";
541
+        $p->interdire_scripts = false;
542
+    }
543
+
544
+    return $p;
545 545
 }
546 546
 
547 547
 
@@ -584,39 +584,39 @@  discard block
 block discarded – undo
584 584
  **/
585 585
 function calculer_balise_dynamique($p, $nom, $l, $supp = []) {
586 586
 
587
-	if (!balise_distante_interdite($p)) {
588
-		$p->code = "''";
589
-
590
-		return $p;
591
-	}
592
-	// compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour
593
-	// il faut recracher {...} quand ce n'est finalement pas des args
594
-	if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) {
595
-		$p->fonctions = null;
596
-	}
597
-
598
-	if ($p->param and ($c = $p->param[0])) {
599
-		// liste d'arguments commence toujours par la chaine vide
600
-		array_shift($c);
601
-		// construire la liste d'arguments comme pour un filtre
602
-		$param = compose_filtres_args($p, $c, ',');
603
-	} else {
604
-		$param = '';
605
-	}
606
-	$collecte = collecter_balise_dynamique($l, $p, $nom);
607
-
608
-	$p->code = sprintf(
609
-		CODE_EXECUTER_BALISE,
610
-		$nom,
611
-		join(',', $collecte),
612
-		($collecte ? $param : substr($param, 1)), # virer la virgule
613
-		memoriser_contexte_compil($p),
614
-		(!$supp ? '' : (', ' . join(',', $supp)))
615
-	);
616
-
617
-	$p->interdire_scripts = false;
618
-
619
-	return $p;
587
+    if (!balise_distante_interdite($p)) {
588
+        $p->code = "''";
589
+
590
+        return $p;
591
+    }
592
+    // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour
593
+    // il faut recracher {...} quand ce n'est finalement pas des args
594
+    if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) {
595
+        $p->fonctions = null;
596
+    }
597
+
598
+    if ($p->param and ($c = $p->param[0])) {
599
+        // liste d'arguments commence toujours par la chaine vide
600
+        array_shift($c);
601
+        // construire la liste d'arguments comme pour un filtre
602
+        $param = compose_filtres_args($p, $c, ',');
603
+    } else {
604
+        $param = '';
605
+    }
606
+    $collecte = collecter_balise_dynamique($l, $p, $nom);
607
+
608
+    $p->code = sprintf(
609
+        CODE_EXECUTER_BALISE,
610
+        $nom,
611
+        join(',', $collecte),
612
+        ($collecte ? $param : substr($param, 1)), # virer la virgule
613
+        memoriser_contexte_compil($p),
614
+        (!$supp ? '' : (', ' . join(',', $supp)))
615
+    );
616
+
617
+    $p->interdire_scripts = false;
618
+
619
+    return $p;
620 620
 }
621 621
 
622 622
 
@@ -646,13 +646,13 @@  discard block
 block discarded – undo
646 646
  *     Liste des codes PHP d'éxecution des balises collectées
647 647
  **/
648 648
 function collecter_balise_dynamique($l, &$p, $nom) {
649
-	$args = [];
650
-	foreach ($l as $c) {
651
-		$x = calculer_balise($c, $p);
652
-		$args[] = $x->code;
653
-	}
649
+    $args = [];
650
+    foreach ($l as $c) {
651
+        $x = calculer_balise($c, $p);
652
+        $args[] = $x->code;
653
+    }
654 654
 
655
-	return $args;
655
+    return $args;
656 656
 }
657 657
 
658 658
 
@@ -667,22 +667,22 @@  discard block
 block discarded – undo
667 667
  *     Nom de la connexion
668 668
  **/
669 669
 function trouver_nom_serveur_distant($p) {
670
-	$nom = $p->id_boucle;
671
-	if (
672
-		$nom
673
-		and isset($p->boucles[$nom])
674
-	) {
675
-		$s = $p->boucles[$nom]->sql_serveur;
676
-		if (
677
-			strlen($s)
678
-			and strlen($serveur = strtolower($s))
679
-			and !in_array($serveur, $GLOBALS['exception_des_connect'])
680
-		) {
681
-			return $serveur;
682
-		}
683
-	}
684
-
685
-	return '';
670
+    $nom = $p->id_boucle;
671
+    if (
672
+        $nom
673
+        and isset($p->boucles[$nom])
674
+    ) {
675
+        $s = $p->boucles[$nom]->sql_serveur;
676
+        if (
677
+            strlen($s)
678
+            and strlen($serveur = strtolower($s))
679
+            and !in_array($serveur, $GLOBALS['exception_des_connect'])
680
+        ) {
681
+            return $serveur;
682
+        }
683
+    }
684
+
685
+    return '';
686 686
 }
687 687
 
688 688
 
@@ -706,15 +706,15 @@  discard block
 block discarded – undo
706 706
  *     - false : La balise est interdite car le serveur est distant
707 707
  **/
708 708
 function balise_distante_interdite($p) {
709
-	$nom = $p->id_boucle;
709
+    $nom = $p->id_boucle;
710 710
 
711
-	if ($nom and trouver_nom_serveur_distant($p)) {
712
-		spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit'));
711
+    if ($nom and trouver_nom_serveur_distant($p)) {
712
+        spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit'));
713 713
 
714
-		return false;
715
-	}
714
+        return false;
715
+    }
716 716
 
717
-	return true;
717
+    return true;
718 718
 }
719 719
 
720 720
 
@@ -725,84 +725,84 @@  discard block
 block discarded – undo
725 725
 // https://code.spip.net/@champs_traitements
726 726
 function champs_traitements($p) {
727 727
 
728
-	if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) {
729
-		$ps = $GLOBALS['table_des_traitements'][$p->nom_champ];
730
-	} else {
731
-		// quand on utilise un traitement catch-all *
732
-		// celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer
733
-		// leur propre securite
734
-		if (!$p->balise_calculee) {
735
-			$ps = $GLOBALS['table_des_traitements']['*'];
736
-		} else {
737
-			$ps = false;
738
-		}
739
-	}
740
-
741
-	if (is_array($ps)) {
742
-		// Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte
743
-		$idb = index_boucle($p);
744
-		// si le champ a ete trouve dans une boucle parente sa source est renseignee ici
745
-		if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) {
746
-			$idb = $p->boucles[$idb]->index_champ[$p->nom_champ];
747
-		}
748
-
749
-		// mais on peut aussi etre hors boucle. Se mefier.
750
-		$type_requete = isset($p->boucles[$idb]->type_requete) ? $p->boucles[$idb]->type_requete : false;
751
-		$table_sql = isset($p->boucles[$idb]->show['table_sql']) ? $p->boucles[$idb]->show['table_sql'] : false;
752
-
753
-		// bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.)
754
-		if ($type_requete and isset($GLOBALS['table_des_tables'][$type_requete])) {
755
-			$type_alias = $type_requete;
756
-			$type_requete = $GLOBALS['table_des_tables'][$type_requete];
757
-		} else {
758
-			$type_alias = false;
759
-		}
760
-
761
-		// le traitement peut n'etre defini que pour une table en particulier "spip_articles"
762
-		if ($table_sql and isset($ps[$table_sql])) {
763
-			$ps = $ps[$table_sql];
764
-		} // ou pour une boucle en particulier "DATA","articles"
765
-		elseif ($type_requete and isset($ps[$type_requete])) {
766
-			$ps = $ps[$type_requete];
767
-		} // ou pour une boucle utilisant un alias ("hierarchie")
768
-		elseif ($type_alias and isset($ps[$type_alias])) {
769
-			$ps = $ps[$type_alias];
770
-		} // ou pour indifféremment quelle que soit la boucle
771
-		elseif (isset($ps[0])) {
772
-			$ps = $ps[0];
773
-		} else {
774
-			$ps = false;
775
-		}
776
-	}
777
-
778
-	if (!$ps) {
779
-		return $p->code;
780
-	}
781
-
782
-	// Si une boucle DOCUMENTS{doublons} est presente dans le squelette,
783
-	// ou si in INCLURE contient {doublons}
784
-	// on insere une fonction de remplissage du tableau des doublons
785
-	// dans les filtres propre() ou typo()
786
-	// (qui traitent les raccourcis <docXX> referencant les docs)
787
-
788
-	if (
789
-		isset($p->descr['documents'])
790
-		and
791
-		$p->descr['documents']
792
-		and (
793
-			(strpos($ps, 'propre') !== false)
794
-			or
795
-			(strpos($ps, 'typo') !== false)
796
-		)
797
-	) {
798
-		$ps = 'traiter_doublons_documents($doublons, ' . $ps . ')';
799
-	}
800
-
801
-	// La protection des champs par |safehtml est assuree par les extensions
802
-	// dans la declaration des traitements des champs sensibles
803
-
804
-	// Remplacer enfin le placeholder %s par le vrai code de la balise
805
-	return str_replace('%s', $p->code, $ps);
728
+    if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) {
729
+        $ps = $GLOBALS['table_des_traitements'][$p->nom_champ];
730
+    } else {
731
+        // quand on utilise un traitement catch-all *
732
+        // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer
733
+        // leur propre securite
734
+        if (!$p->balise_calculee) {
735
+            $ps = $GLOBALS['table_des_traitements']['*'];
736
+        } else {
737
+            $ps = false;
738
+        }
739
+    }
740
+
741
+    if (is_array($ps)) {
742
+        // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte
743
+        $idb = index_boucle($p);
744
+        // si le champ a ete trouve dans une boucle parente sa source est renseignee ici
745
+        if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) {
746
+            $idb = $p->boucles[$idb]->index_champ[$p->nom_champ];
747
+        }
748
+
749
+        // mais on peut aussi etre hors boucle. Se mefier.
750
+        $type_requete = isset($p->boucles[$idb]->type_requete) ? $p->boucles[$idb]->type_requete : false;
751
+        $table_sql = isset($p->boucles[$idb]->show['table_sql']) ? $p->boucles[$idb]->show['table_sql'] : false;
752
+
753
+        // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.)
754
+        if ($type_requete and isset($GLOBALS['table_des_tables'][$type_requete])) {
755
+            $type_alias = $type_requete;
756
+            $type_requete = $GLOBALS['table_des_tables'][$type_requete];
757
+        } else {
758
+            $type_alias = false;
759
+        }
760
+
761
+        // le traitement peut n'etre defini que pour une table en particulier "spip_articles"
762
+        if ($table_sql and isset($ps[$table_sql])) {
763
+            $ps = $ps[$table_sql];
764
+        } // ou pour une boucle en particulier "DATA","articles"
765
+        elseif ($type_requete and isset($ps[$type_requete])) {
766
+            $ps = $ps[$type_requete];
767
+        } // ou pour une boucle utilisant un alias ("hierarchie")
768
+        elseif ($type_alias and isset($ps[$type_alias])) {
769
+            $ps = $ps[$type_alias];
770
+        } // ou pour indifféremment quelle que soit la boucle
771
+        elseif (isset($ps[0])) {
772
+            $ps = $ps[0];
773
+        } else {
774
+            $ps = false;
775
+        }
776
+    }
777
+
778
+    if (!$ps) {
779
+        return $p->code;
780
+    }
781
+
782
+    // Si une boucle DOCUMENTS{doublons} est presente dans le squelette,
783
+    // ou si in INCLURE contient {doublons}
784
+    // on insere une fonction de remplissage du tableau des doublons
785
+    // dans les filtres propre() ou typo()
786
+    // (qui traitent les raccourcis <docXX> referencant les docs)
787
+
788
+    if (
789
+        isset($p->descr['documents'])
790
+        and
791
+        $p->descr['documents']
792
+        and (
793
+            (strpos($ps, 'propre') !== false)
794
+            or
795
+            (strpos($ps, 'typo') !== false)
796
+        )
797
+    ) {
798
+        $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')';
799
+    }
800
+
801
+    // La protection des champs par |safehtml est assuree par les extensions
802
+    // dans la declaration des traitements des champs sensibles
803
+
804
+    // Remplacer enfin le placeholder %s par le vrai code de la balise
805
+    return str_replace('%s', $p->code, $ps);
806 806
 }
807 807
 
808 808
 
@@ -815,112 +815,112 @@  discard block
 block discarded – undo
815 815
 // https://code.spip.net/@applique_filtres
816 816
 function applique_filtres($p) {
817 817
 
818
-	// Traitements standards (cf. supra)
819
-	if ($p->etoile == '') {
820
-		$code = champs_traitements($p);
821
-	} else {
822
-		$code = $p->code;
823
-	}
818
+    // Traitements standards (cf. supra)
819
+    if ($p->etoile == '') {
820
+        $code = champs_traitements($p);
821
+    } else {
822
+        $code = $p->code;
823
+    }
824 824
 
825
-	// Appliquer les filtres perso
826
-	if ($p->param) {
827
-		$code = compose_filtres($p, $code);
828
-	}
825
+    // Appliquer les filtres perso
826
+    if ($p->param) {
827
+        $code = compose_filtres($p, $code);
828
+    }
829 829
 
830
-	// S'il y a un lien avec la session, ajouter un code qui levera
831
-	// un drapeau dans la structure d'invalidation $Cache
832
-	if (isset($p->descr['session'])) {
833
-		$code = "invalideur_session(\$Cache, $code)";
834
-	}
830
+    // S'il y a un lien avec la session, ajouter un code qui levera
831
+    // un drapeau dans la structure d'invalidation $Cache
832
+    if (isset($p->descr['session'])) {
833
+        $code = "invalideur_session(\$Cache, $code)";
834
+    }
835 835
 
836
-	$code = sandbox_composer_interdire_scripts($code, $p);
836
+    $code = sandbox_composer_interdire_scripts($code, $p);
837 837
 
838
-	return $code;
838
+    return $code;
839 839
 }
840 840
 
841 841
 // Cf. function pipeline dans ecrire/inc_utils.php
842 842
 // https://code.spip.net/@compose_filtres
843 843
 function compose_filtres(&$p, $code) {
844 844
 
845
-	$image_miette = false;
846
-	foreach ($p->param as $filtre) {
847
-		$fonc = array_shift($filtre);
848
-		if (!$fonc) {
849
-			continue;
850
-		} // normalement qu'au premier tour.
851
-		$is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver');
852
-		if ($image_miette and !$is_filtre_image) {
853
-			// il faut graver maintenant car apres le filtre en cours
854
-			// on est pas sur d'avoir encore le nom du fichier dans le pipe
855
-			$code = "filtrer('image_graver', $code)";
856
-			$image_miette = false;
857
-		}
858
-
859
-		// recuperer les arguments du filtre,
860
-		// a separer par "," ou ":" dans le cas du filtre "?{a,b}"
861
-		$countfiltre = count($filtre);
862
-		if ($fonc !== '?') {
863
-			$sep = ',';
864
-		} else {
865
-			$sep = ':';
866
-			// |?{a,b} *doit* avoir exactement 2 arguments ; on les force
867
-			if ($countfiltre != 2) {
868
-				$filtre = [$filtre[0] ?? '', $filtre[1] ?? ''];
869
-				$countfiltre = 2;
870
-			}
871
-		}
872
-		$arglist = compose_filtres_args($p, $filtre, $sep);
873
-		$logique = filtre_logique($fonc, $code, substr($arglist, 1));
874
-		if ($logique) {
875
-			$code = $logique;
876
-		} else {
877
-			$code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre);
878
-			if ($is_filtre_image) {
879
-				$image_miette = true;
880
-			}
881
-		}
882
-	}
883
-	// ramasser les images intermediaires inutiles et graver l'image finale
884
-	if ($image_miette) {
885
-		$code = "filtrer('image_graver',$code)";
886
-	}
887
-
888
-	return $code;
845
+    $image_miette = false;
846
+    foreach ($p->param as $filtre) {
847
+        $fonc = array_shift($filtre);
848
+        if (!$fonc) {
849
+            continue;
850
+        } // normalement qu'au premier tour.
851
+        $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver');
852
+        if ($image_miette and !$is_filtre_image) {
853
+            // il faut graver maintenant car apres le filtre en cours
854
+            // on est pas sur d'avoir encore le nom du fichier dans le pipe
855
+            $code = "filtrer('image_graver', $code)";
856
+            $image_miette = false;
857
+        }
858
+
859
+        // recuperer les arguments du filtre,
860
+        // a separer par "," ou ":" dans le cas du filtre "?{a,b}"
861
+        $countfiltre = count($filtre);
862
+        if ($fonc !== '?') {
863
+            $sep = ',';
864
+        } else {
865
+            $sep = ':';
866
+            // |?{a,b} *doit* avoir exactement 2 arguments ; on les force
867
+            if ($countfiltre != 2) {
868
+                $filtre = [$filtre[0] ?? '', $filtre[1] ?? ''];
869
+                $countfiltre = 2;
870
+            }
871
+        }
872
+        $arglist = compose_filtres_args($p, $filtre, $sep);
873
+        $logique = filtre_logique($fonc, $code, substr($arglist, 1));
874
+        if ($logique) {
875
+            $code = $logique;
876
+        } else {
877
+            $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre);
878
+            if ($is_filtre_image) {
879
+                $image_miette = true;
880
+            }
881
+        }
882
+    }
883
+    // ramasser les images intermediaires inutiles et graver l'image finale
884
+    if ($image_miette) {
885
+        $code = "filtrer('image_graver',$code)";
886
+    }
887
+
888
+    return $code;
889 889
 }
890 890
 
891 891
 // Filtres et,ou,oui,non,sinon,xou,xor,and,or,not,yes
892 892
 // et comparateurs
893 893
 function filtre_logique($fonc, $code, $arg) {
894 894
 
895
-	switch (true) {
896
-		case in_array($fonc, $GLOBALS['table_criteres_infixes']):
897
-			return "($code $fonc $arg)";
898
-		case ($fonc == 'and') or ($fonc == 'et'):
899
-			return "((($code) AND ($arg)) ?' ' :'')";
900
-		case ($fonc == 'or') or ($fonc == 'ou'):
901
-			return "((($code) OR ($arg)) ?' ' :'')";
902
-		case ($fonc == 'xor') or ($fonc == 'xou'):
903
-			return "((($code) XOR ($arg)) ?' ' :'')";
904
-		case ($fonc == 'sinon'):
905
-			return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)";
906
-		case ($fonc == 'not') or ($fonc == 'non'):
907
-			return "(($code) ?'' :' ')";
908
-		case ($fonc == 'yes') or ($fonc == 'oui'):
909
-			return "(($code) ?' ' :'')";
910
-	}
911
-
912
-	return '';
895
+    switch (true) {
896
+        case in_array($fonc, $GLOBALS['table_criteres_infixes']):
897
+            return "($code $fonc $arg)";
898
+        case ($fonc == 'and') or ($fonc == 'et'):
899
+            return "((($code) AND ($arg)) ?' ' :'')";
900
+        case ($fonc == 'or') or ($fonc == 'ou'):
901
+            return "((($code) OR ($arg)) ?' ' :'')";
902
+        case ($fonc == 'xor') or ($fonc == 'xou'):
903
+            return "((($code) XOR ($arg)) ?' ' :'')";
904
+        case ($fonc == 'sinon'):
905
+            return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)";
906
+        case ($fonc == 'not') or ($fonc == 'non'):
907
+            return "(($code) ?'' :' ')";
908
+        case ($fonc == 'yes') or ($fonc == 'oui'):
909
+            return "(($code) ?' ' :'')";
910
+    }
911
+
912
+    return '';
913 913
 }
914 914
 
915 915
 // https://code.spip.net/@compose_filtres_args
916 916
 function compose_filtres_args($p, $args, $sep) {
917
-	$arglist = '';
918
-	foreach ($args as $arg) {
919
-		$arglist .= $sep .
920
-			calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle);
921
-	}
917
+    $arglist = '';
918
+    foreach ($args as $arg) {
919
+        $arglist .= $sep .
920
+            calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle);
921
+    }
922 922
 
923
-	return $arglist;
923
+    return $arglist;
924 924
 }
925 925
 
926 926
 
@@ -938,15 +938,15 @@  discard block
 block discarded – undo
938 938
  **/
939 939
 function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut = null) {
940 940
 
941
-	// si recursif, forcer l'extraction du champ SQL mais ignorer le code
942
-	if ($boucles[$idb]->externe) {
943
-		index_pile($idb, $nom_champ, $boucles, '', $defaut);
944
-		// retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle
945
-		// on ignore le defaut fourni dans ce cas
946
-		$defaut = "@\$Pile[\$SP]['$nom_champ']";
947
-	}
941
+    // si recursif, forcer l'extraction du champ SQL mais ignorer le code
942
+    if ($boucles[$idb]->externe) {
943
+        index_pile($idb, $nom_champ, $boucles, '', $defaut);
944
+        // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle
945
+        // on ignore le defaut fourni dans ce cas
946
+        $defaut = "@\$Pile[\$SP]['$nom_champ']";
947
+    }
948 948
 
949
-	return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut);
949
+    return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut);
950 950
 }
951 951
 
952 952
 //
@@ -961,30 +961,30 @@  discard block
 block discarded – undo
961 961
 
962 962
 // https://code.spip.net/@rindex_pile
963 963
 function rindex_pile($p, $champ, $motif) {
964
-	$n = 0;
965
-	$b = $p->id_boucle;
966
-	$p->code = '';
967
-	while ($b != '') {
968
-		foreach ($p->boucles[$b]->criteres as $critere) {
969
-			if ($critere->op == $motif) {
970
-				$p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") .
971
-					"]['$champ']";
972
-				$b = '';
973
-				break 2;
974
-			}
975
-		}
976
-		$n++;
977
-		$b = $p->boucles[$b]->id_parent;
978
-	}
979
-
980
-	// si on est hors d'une boucle de {recherche}, cette balise est vide
981
-	if (!$p->code) {
982
-		$p->code = "''";
983
-	}
984
-
985
-	$p->interdire_scripts = false;
986
-
987
-	return $p;
964
+    $n = 0;
965
+    $b = $p->id_boucle;
966
+    $p->code = '';
967
+    while ($b != '') {
968
+        foreach ($p->boucles[$b]->criteres as $critere) {
969
+            if ($critere->op == $motif) {
970
+                $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") .
971
+                    "]['$champ']";
972
+                $b = '';
973
+                break 2;
974
+            }
975
+        }
976
+        $n++;
977
+        $b = $p->boucles[$b]->id_parent;
978
+    }
979
+
980
+    // si on est hors d'une boucle de {recherche}, cette balise est vide
981
+    if (!$p->code) {
982
+        $p->code = "''";
983
+    }
984
+
985
+    $p->interdire_scripts = false;
986
+
987
+    return $p;
988 988
 }
989 989
 
990 990
 /**
@@ -994,7 +994,7 @@  discard block
 block discarded – undo
994 994
  * @return string Nom de la balise, avec indication de boucle explicite si présent.
995 995
  */
996 996
 function zbug_presenter_champ($p, $champ = '') {
997
-	$balise = $champ ? $champ : $p->nom_champ;
998
-	$explicite = $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : '';
999
-	return "#{$explicite}{$balise}";
997
+    $balise = $champ ? $champ : $p->nom_champ;
998
+    $explicite = $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : '';
999
+    return "#{$explicite}{$balise}";
1000 1000
 }
Please login to merge, or discard this patch.
ecrire/public/decompiler.php 1 patch
Indentation   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -11,130 +11,130 @@  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->type_requete :
30
-		$struct->table_optionnelle);
31
-
32
-	if ($struct->jointures_explicites) {
33
-		$type .= ' ' . $struct->jointures_explicites;
34
-	}
35
-	if ($struct->table_optionnelle) {
36
-		$type .= '?';
37
-	}
38
-	// Revoir le cas de la boucle recursive
39
-
40
-	$crit = $struct->param;
41
-	if ($crit and !is_array($crit[0])) {
42
-		$type = strtolower($type) . array_shift($crit);
43
-	}
44
-	$crit = decompiler_criteres($struct, $fmt, $prof);
45
-
46
-	$f = 'format_boucle_' . $fmt;
47
-
48
-	return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof);
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->type_requete :
30
+        $struct->table_optionnelle);
31
+
32
+    if ($struct->jointures_explicites) {
33
+        $type .= ' ' . $struct->jointures_explicites;
34
+    }
35
+    if ($struct->table_optionnelle) {
36
+        $type .= '?';
37
+    }
38
+    // Revoir le cas de la boucle recursive
39
+
40
+    $crit = $struct->param;
41
+    if ($crit and !is_array($crit[0])) {
42
+        $type = strtolower($type) . array_shift($crit);
43
+    }
44
+    $crit = decompiler_criteres($struct, $fmt, $prof);
45
+
46
+    $f = 'format_boucle_' . $fmt;
47
+
48
+    return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof);
49 49
 }
50 50
 
51 51
 function decompiler_include($struct, $fmt = '', $prof = 0) {
52
-	$res = [];
53
-	foreach ($struct->param ? $struct->param : [] as $couple) {
54
-		array_shift($couple);
55
-		foreach ($couple as $v) {
56
-			$res[] = decompiler_($v, $fmt, $prof);
57
-		}
58
-	}
59
-	$file = is_string($struct->texte) ? $struct->texte :
60
-		decompiler_($struct->texte, $fmt, $prof);
61
-	$f = 'format_inclure_' . $fmt;
62
-
63
-	return $f($file, $res, $prof);
52
+    $res = [];
53
+    foreach ($struct->param ? $struct->param : [] as $couple) {
54
+        array_shift($couple);
55
+        foreach ($couple as $v) {
56
+            $res[] = decompiler_($v, $fmt, $prof);
57
+        }
58
+    }
59
+    $file = is_string($struct->texte) ? $struct->texte :
60
+        decompiler_($struct->texte, $fmt, $prof);
61
+    $f = 'format_inclure_' . $fmt;
62
+
63
+    return $f($file, $res, $prof);
64 64
 }
65 65
 
66 66
 function decompiler_texte($struct, $fmt = '', $prof = 0) {
67
-	$f = 'format_texte_' . $fmt;
67
+    $f = 'format_texte_' . $fmt;
68 68
 
69
-	return strlen($struct->texte) ? $f($struct->texte, $prof) : '';
69
+    return strlen($struct->texte) ? $f($struct->texte, $prof) : '';
70 70
 }
71 71
 
72 72
 function decompiler_polyglotte($struct, $fmt = '', $prof = 0) {
73
-	$f = 'format_polyglotte_' . $fmt;
73
+    $f = 'format_polyglotte_' . $fmt;
74 74
 
75
-	return $f($struct->traductions, $prof);
75
+    return $f($struct->traductions, $prof);
76 76
 }
77 77
 
78 78
 function decompiler_idiome($struct, $fmt = '', $prof = 0) {
79
-	$args = [];
80
-	foreach ($struct->arg as $k => $v) {
81
-		$args[$k] = public_decompiler($v, $fmt, $prof);
82
-	}
79
+    $args = [];
80
+    foreach ($struct->arg as $k => $v) {
81
+        $args[$k] = public_decompiler($v, $fmt, $prof);
82
+    }
83 83
 
84
-	$filtres = decompiler_liste($struct->param, $fmt, $prof);
84
+    $filtres = decompiler_liste($struct->param, $fmt, $prof);
85 85
 
86
-	$f = 'format_idiome_' . $fmt;
86
+    $f = 'format_idiome_' . $fmt;
87 87
 
88
-	return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof);
88
+    return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof);
89 89
 }
90 90
 
91 91
 function decompiler_champ($struct, $fmt = '', $prof = 0) {
92
-	$avant = decompiler_($struct->avant, $fmt, $prof);
93
-	$apres = decompiler_($struct->apres, $fmt, $prof);
94
-	$args = $filtres = '';
95
-	if ($p = $struct->param) {
96
-		if ($p[0][0] === '') {
97
-			$args = decompiler_liste([array_shift($p)], $fmt, $prof);
98
-		}
99
-		$filtres = decompiler_liste($p, $fmt, $prof);
100
-	}
101
-	$f = 'format_champ_' . $fmt;
102
-
103
-	return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof);
92
+    $avant = decompiler_($struct->avant, $fmt, $prof);
93
+    $apres = decompiler_($struct->apres, $fmt, $prof);
94
+    $args = $filtres = '';
95
+    if ($p = $struct->param) {
96
+        if ($p[0][0] === '') {
97
+            $args = decompiler_liste([array_shift($p)], $fmt, $prof);
98
+        }
99
+        $filtres = decompiler_liste($p, $fmt, $prof);
100
+    }
101
+    $f = 'format_champ_' . $fmt;
102
+
103
+    return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof);
104 104
 }
105 105
 
106 106
 function decompiler_liste($sources, $fmt = '', $prof = 0) {
107
-	if (!is_array($sources)) {
108
-		return '';
109
-	}
110
-	$f = 'format_liste_' . $fmt;
111
-	$res = '';
112
-	foreach ($sources as $arg) {
113
-		if (!is_array($arg)) {
114
-			continue; // ne devrait pas arriver.
115
-		} else {
116
-			$r = array_shift($arg);
117
-		}
118
-		$args = [];
119
-		foreach ($arg as $v) {
120
-			// cas des arguments entoures de ' ou "
121
-			if (
122
-				(count($v) == 1)
123
-				and $v[0]->type == 'texte'
124
-				and (strlen($v[0]->apres) == 1)
125
-				and $v[0]->apres == $v[0]->avant
126
-			) {
127
-				$args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres;
128
-			} else {
129
-				$args[] = decompiler_($v, $fmt, 0 - $prof);
130
-			}
131
-		}
132
-		if (($r !== '') or $args) {
133
-			$res .= $f($r, $args, $prof);
134
-		}
135
-	}
136
-
137
-	return $res;
107
+    if (!is_array($sources)) {
108
+        return '';
109
+    }
110
+    $f = 'format_liste_' . $fmt;
111
+    $res = '';
112
+    foreach ($sources as $arg) {
113
+        if (!is_array($arg)) {
114
+            continue; // ne devrait pas arriver.
115
+        } else {
116
+            $r = array_shift($arg);
117
+        }
118
+        $args = [];
119
+        foreach ($arg as $v) {
120
+            // cas des arguments entoures de ' ou "
121
+            if (
122
+                (count($v) == 1)
123
+                and $v[0]->type == 'texte'
124
+                and (strlen($v[0]->apres) == 1)
125
+                and $v[0]->apres == $v[0]->avant
126
+            ) {
127
+                $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres;
128
+            } else {
129
+                $args[] = decompiler_($v, $fmt, 0 - $prof);
130
+            }
131
+        }
132
+        if (($r !== '') or $args) {
133
+            $res .= $f($r, $args, $prof);
134
+        }
135
+    }
136
+
137
+    return $res;
138 138
 }
139 139
 
140 140
 // Decompilation des criteres: on triche et on deroge:
@@ -142,93 +142,93 @@  discard block
 block discarded – undo
142 142
 // - le champ apres signale le critere {"separateur"} ou {'separateur'}
143 143
 // - les champs sont implicitement etendus (crochets implicites mais interdits)
144 144
 function decompiler_criteres($boucle, $fmt = '', $prof = 0) {
145
-	$sources = $boucle->param;
146
-	if (!is_array($sources)) {
147
-		return '';
148
-	}
149
-	$res = '';
150
-	$f = 'format_critere_' . $fmt;
151
-	foreach ($sources as $crit) {
152
-		if (!is_array($crit)) {
153
-			continue;
154
-		} // boucle recursive
155
-		array_shift($crit);
156
-		$args = [];
157
-		foreach ($crit as $i => $v) {
158
-			if (
159
-				(count($v) == 1)
160
-				and $v[0]->type == 'texte'
161
-				and $v[0]->apres
162
-			) {
163
-				$args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]];
164
-			} else {
165
-				$res2 = [];
166
-				foreach ($v as $k => $p) {
167
-					if (
168
-						isset($p->type)
169
-						and function_exists($d = 'decompiler_' . $p->type)
170
-					) {
171
-						$r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]);
172
-						$res2[] = [$p->type, $r];
173
-					} else {
174
-						spip_log("critere $i / $k mal forme");
175
-					}
176
-				}
177
-				$args[] = $res2;
178
-			}
179
-		}
180
-		$res .= $f($args);
181
-	}
182
-
183
-	return $res;
145
+    $sources = $boucle->param;
146
+    if (!is_array($sources)) {
147
+        return '';
148
+    }
149
+    $res = '';
150
+    $f = 'format_critere_' . $fmt;
151
+    foreach ($sources as $crit) {
152
+        if (!is_array($crit)) {
153
+            continue;
154
+        } // boucle recursive
155
+        array_shift($crit);
156
+        $args = [];
157
+        foreach ($crit as $i => $v) {
158
+            if (
159
+                (count($v) == 1)
160
+                and $v[0]->type == 'texte'
161
+                and $v[0]->apres
162
+            ) {
163
+                $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]];
164
+            } else {
165
+                $res2 = [];
166
+                foreach ($v as $k => $p) {
167
+                    if (
168
+                        isset($p->type)
169
+                        and function_exists($d = 'decompiler_' . $p->type)
170
+                    ) {
171
+                        $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]);
172
+                        $res2[] = [$p->type, $r];
173
+                    } else {
174
+                        spip_log("critere $i / $k mal forme");
175
+                    }
176
+                }
177
+                $args[] = $res2;
178
+            }
179
+        }
180
+        $res .= $f($args);
181
+    }
182
+
183
+    return $res;
184 184
 }
185 185
 
186 186
 
187 187
 function decompiler_($liste, $fmt = '', $prof = 0) {
188
-	if (!is_array($liste)) {
189
-		return '';
190
-	}
191
-	$prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1);
192
-	$contenu = [];
193
-	foreach ($liste as $k => $p) {
194
-		if (!isset($p->type)) {
195
-			continue;
196
-		} #??????
197
-		$d = 'decompiler_' . $p->type;
198
-		$next = isset($liste[$k + 1]) ? $liste[$k + 1] : false;
199
-		// Forcer le champ etendu si son source (pas les reecritures)
200
-		// contenait des args et s'il est suivi d'espaces,
201
-		// le champ simple les eliminant est un bug helas perenne.
202
-
203
-		if (
204
-			$next
205
-			and ($next->type == 'texte')
206
-			and $p->type == 'champ'
207
-			and !$p->apres
208
-			and !$p->avant
209
-			and $p->fonctions
210
-		) {
211
-			$n = strlen($next->texte) - strlen(ltrim($next->texte));
212
-			if ($n) {
213
-				$champ = new Texte();
214
-				$champ->texte = substr($next->texte, 0, $n);
215
-				$champ->ligne = $p->ligne;
216
-				$p->apres = [$champ];
217
-				$next->texte = substr($next->texte, $n);
218
-			}
219
-		}
220
-		$contenu[] = [$d($p, $fmt, $prof2), $p->type];
221
-	}
222
-	$f = 'format_suite_' . $fmt;
223
-
224
-	return $f($contenu);
188
+    if (!is_array($liste)) {
189
+        return '';
190
+    }
191
+    $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1);
192
+    $contenu = [];
193
+    foreach ($liste as $k => $p) {
194
+        if (!isset($p->type)) {
195
+            continue;
196
+        } #??????
197
+        $d = 'decompiler_' . $p->type;
198
+        $next = isset($liste[$k + 1]) ? $liste[$k + 1] : false;
199
+        // Forcer le champ etendu si son source (pas les reecritures)
200
+        // contenait des args et s'il est suivi d'espaces,
201
+        // le champ simple les eliminant est un bug helas perenne.
202
+
203
+        if (
204
+            $next
205
+            and ($next->type == 'texte')
206
+            and $p->type == 'champ'
207
+            and !$p->apres
208
+            and !$p->avant
209
+            and $p->fonctions
210
+        ) {
211
+            $n = strlen($next->texte) - strlen(ltrim($next->texte));
212
+            if ($n) {
213
+                $champ = new Texte();
214
+                $champ->texte = substr($next->texte, 0, $n);
215
+                $champ->ligne = $p->ligne;
216
+                $p->apres = [$champ];
217
+                $next->texte = substr($next->texte, $n);
218
+            }
219
+        }
220
+        $contenu[] = [$d($p, $fmt, $prof2), $p->type];
221
+    }
222
+    $f = 'format_suite_' . $fmt;
223
+
224
+    return $f($contenu);
225 225
 }
226 226
 
227 227
 function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') {
228
-	if (!include_spip('public/format_' . $fmt)) {
229
-		return "'$fmt'?";
230
-	}
231
-	$f = 'decompiler_' . $quoi;
228
+    if (!include_spip('public/format_' . $fmt)) {
229
+        return "'$fmt'?";
230
+    }
231
+    $f = 'decompiler_' . $quoi;
232 232
 
233
-	return $f($liste, $fmt, $prof);
233
+    return $f($liste, $fmt, $prof);
234 234
 }
Please login to merge, or discard this patch.
ecrire/public/iterateur.php 1 patch
Indentation   +570 added lines, -570 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,583 +21,583 @@  discard block
 block discarded – undo
21 21
  *
22 22
  */
23 23
 class IterFactory {
24
-	public static function create($iterateur, $command, $info = null) {
25
-
26
-		// cas des SI {si expression} analises tres tot
27
-		// pour eviter le chargement de tout iterateur
28
-		if (isset($command['si'])) {
29
-			foreach ($command['si'] as $si) {
30
-				if (!$si) {
31
-					// $command pour boucle SQL peut generer des erreurs de compilation
32
-					// s'il est transmis alors qu'on est dans un iterateur vide
33
-					return new IterDecorator(new EmptyIterator(), [], $info);
34
-				}
35
-			}
36
-		}
37
-
38
-		// chercher un iterateur PHP existant (par exemple dans SPL)
39
-		// (il faudrait passer l'argument ->sql_serveur
40
-		// pour etre certain qu'on est sur un "php:")
41
-		if (class_exists($iterateur)) {
42
-			$a = isset($command['args']) ? $command['args'] : [];
43
-
44
-			// permettre de passer un Iterateur directement {args #ITERATEUR} :
45
-			// si on recoit deja un iterateur en argument, on l'utilise
46
-			if (count($a) == 1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) {
47
-				$iter = $a[0];
48
-
49
-				// sinon, on cree un iterateur du type donne
50
-			} else {
51
-				// arguments de creation de l'iterateur...
52
-				// (pas glop)
53
-				try {
54
-					switch (count($a)) {
55
-						case 0:
56
-							$iter = new $iterateur();
57
-							break;
58
-						case 1:
59
-							$iter = new $iterateur($a[0]);
60
-							break;
61
-						case 2:
62
-							$iter = new $iterateur($a[0], $a[1]);
63
-							break;
64
-						case 3:
65
-							$iter = new $iterateur($a[0], $a[1], $a[2]);
66
-							break;
67
-						case 4:
68
-							$iter = new $iterateur($a[0], $a[1], $a[2], $a[3]);
69
-							break;
70
-					}
71
-				} catch (Exception $e) {
72
-					spip_log("Erreur de chargement de l'iterateur $iterateur");
73
-					spip_log($e->getMessage());
74
-					$iter = new EmptyIterator();
75
-				}
76
-			}
77
-		} else {
78
-			// chercher la classe d'iterateur
79
-			// IterateurXXX
80
-			// definie dans le fichier iterateurs/xxx.php
81
-			$class = 'Iterateur' . $iterateur;
82
-			if (!class_exists($class)) {
83
-				if (
84
-					!include_spip('iterateur/' . strtolower($iterateur))
85
-					or !class_exists($class)
86
-				) {
87
-					die("Iterateur $iterateur non trouv&#233;");
88
-					// si l'iterateur n'existe pas, on se rabat sur le generique
89
-					# $iter = new EmptyIterator();
90
-				}
91
-			}
92
-			$iter = new $class($command, $info);
93
-		}
94
-
95
-		return new IterDecorator($iter, $command, $info);
96
-	}
24
+    public static function create($iterateur, $command, $info = null) {
25
+
26
+        // cas des SI {si expression} analises tres tot
27
+        // pour eviter le chargement de tout iterateur
28
+        if (isset($command['si'])) {
29
+            foreach ($command['si'] as $si) {
30
+                if (!$si) {
31
+                    // $command pour boucle SQL peut generer des erreurs de compilation
32
+                    // s'il est transmis alors qu'on est dans un iterateur vide
33
+                    return new IterDecorator(new EmptyIterator(), [], $info);
34
+                }
35
+            }
36
+        }
37
+
38
+        // chercher un iterateur PHP existant (par exemple dans SPL)
39
+        // (il faudrait passer l'argument ->sql_serveur
40
+        // pour etre certain qu'on est sur un "php:")
41
+        if (class_exists($iterateur)) {
42
+            $a = isset($command['args']) ? $command['args'] : [];
43
+
44
+            // permettre de passer un Iterateur directement {args #ITERATEUR} :
45
+            // si on recoit deja un iterateur en argument, on l'utilise
46
+            if (count($a) == 1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) {
47
+                $iter = $a[0];
48
+
49
+                // sinon, on cree un iterateur du type donne
50
+            } else {
51
+                // arguments de creation de l'iterateur...
52
+                // (pas glop)
53
+                try {
54
+                    switch (count($a)) {
55
+                        case 0:
56
+                            $iter = new $iterateur();
57
+                            break;
58
+                        case 1:
59
+                            $iter = new $iterateur($a[0]);
60
+                            break;
61
+                        case 2:
62
+                            $iter = new $iterateur($a[0], $a[1]);
63
+                            break;
64
+                        case 3:
65
+                            $iter = new $iterateur($a[0], $a[1], $a[2]);
66
+                            break;
67
+                        case 4:
68
+                            $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]);
69
+                            break;
70
+                    }
71
+                } catch (Exception $e) {
72
+                    spip_log("Erreur de chargement de l'iterateur $iterateur");
73
+                    spip_log($e->getMessage());
74
+                    $iter = new EmptyIterator();
75
+                }
76
+            }
77
+        } else {
78
+            // chercher la classe d'iterateur
79
+            // IterateurXXX
80
+            // definie dans le fichier iterateurs/xxx.php
81
+            $class = 'Iterateur' . $iterateur;
82
+            if (!class_exists($class)) {
83
+                if (
84
+                    !include_spip('iterateur/' . strtolower($iterateur))
85
+                    or !class_exists($class)
86
+                ) {
87
+                    die("Iterateur $iterateur non trouv&#233;");
88
+                    // si l'iterateur n'existe pas, on se rabat sur le generique
89
+                    # $iter = new EmptyIterator();
90
+                }
91
+            }
92
+            $iter = new $class($command, $info);
93
+        }
94
+
95
+        return new IterDecorator($iter, $command, $info);
96
+    }
97 97
 }
98 98
 
99 99
 
100 100
 class IterDecorator extends FilterIterator {
101
-	private $iter;
102
-
103
-	/**
104
-	 * Conditions de filtrage
105
-	 * ie criteres de selection
106
-	 *
107
-	 * @var array
108
-	 */
109
-	protected $filtre = [];
110
-
111
-	/**
112
-	 * Fonction de filtrage compilee a partir des criteres de filtre
113
-	 *
114
-	 * @var string
115
-	 */
116
-	protected $func_filtre = null;
117
-
118
-	/**
119
-	 * Critere {offset, limit}
120
-	 *
121
-	 * @var int
122
-	 * @var int
123
-	 */
124
-	protected $offset = null;
125
-	protected $limit = null;
126
-
127
-	/**
128
-	 * nombre d'elements recuperes depuis la position 0,
129
-	 * en tenant compte des filtres
130
-	 *
131
-	 * @var int
132
-	 */
133
-	protected $fetched = 0;
134
-
135
-	/**
136
-	 * Y a t'il une erreur ?
137
-	 *
138
-	 * @var bool
139
-	 **/
140
-	protected $err = false;
141
-
142
-	/**
143
-	 * Drapeau a activer en cas d'echec
144
-	 * (select SQL errone, non chargement des DATA, etc)
145
-	 */
146
-	public function err() {
147
-		if (method_exists($this->iter, 'err')) {
148
-			return $this->iter->err();
149
-		}
150
-		if (property_exists($this->iter, 'err')) {
151
-			return $this->iter->err;
152
-		}
153
-
154
-		return false;
155
-	}
156
-
157
-	public function __construct(Iterator $iter, $command, $info) {
158
-		parent::__construct($iter);
159
-		parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator)
160
-
161
-		// recuperer l'iterateur transmis
162
-		$this->iter = $this->getInnerIterator();
163
-		$this->command = $command;
164
-		$this->info = $info;
165
-		$this->pos = 0;
166
-		$this->fetched = 0;
167
-
168
-		// chercher la liste des champs a retourner par
169
-		// fetch si l'objet ne les calcule pas tout seul
170
-		if (!method_exists($this->iter, 'fetch')) {
171
-			$this->calculer_select();
172
-			$this->calculer_filtres();
173
-		}
174
-
175
-		// emptyIterator critere {si} faux n'a pas d'erreur !
176
-		if (isset($this->iter->err)) {
177
-			$this->err = $this->iter->err;
178
-		}
179
-
180
-		// pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite)
181
-		//$this->total = $this->count();
182
-	}
183
-
184
-
185
-	// calcule les elements a retournes par fetch()
186
-	// enleve les elements inutiles du select()
187
-	//
188
-	private function calculer_select() {
189
-		if ($select = &$this->command['select']) {
190
-			foreach ($select as $s) {
191
-				// /!\ $s = '.nom'
192
-				if ($s[0] == '.') {
193
-					$s = substr($s, 1);
194
-				}
195
-				$this->select[] = $s;
196
-			}
197
-		}
198
-	}
199
-
200
-	// recuperer la valeur d'une balise #X
201
-	// en fonction des methodes
202
-	// et proprietes disponibles
203
-	public function get_select($nom) {
204
-		if (
205
-			is_object($this->iter)
206
-			and method_exists($this->iter, $nom)
207
-		) {
208
-			try {
209
-				return $this->iter->$nom();
210
-			} catch (Exception $e) {
211
-				// #GETCHILDREN sur un fichier de DirectoryIterator ...
212
-				spip_log("Methode $nom en echec sur " . get_class($this->iter));
213
-				spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode");
214
-
215
-				return '';
216
-			}
217
-		}
218
-		/*
101
+    private $iter;
102
+
103
+    /**
104
+     * Conditions de filtrage
105
+     * ie criteres de selection
106
+     *
107
+     * @var array
108
+     */
109
+    protected $filtre = [];
110
+
111
+    /**
112
+     * Fonction de filtrage compilee a partir des criteres de filtre
113
+     *
114
+     * @var string
115
+     */
116
+    protected $func_filtre = null;
117
+
118
+    /**
119
+     * Critere {offset, limit}
120
+     *
121
+     * @var int
122
+     * @var int
123
+     */
124
+    protected $offset = null;
125
+    protected $limit = null;
126
+
127
+    /**
128
+     * nombre d'elements recuperes depuis la position 0,
129
+     * en tenant compte des filtres
130
+     *
131
+     * @var int
132
+     */
133
+    protected $fetched = 0;
134
+
135
+    /**
136
+     * Y a t'il une erreur ?
137
+     *
138
+     * @var bool
139
+     **/
140
+    protected $err = false;
141
+
142
+    /**
143
+     * Drapeau a activer en cas d'echec
144
+     * (select SQL errone, non chargement des DATA, etc)
145
+     */
146
+    public function err() {
147
+        if (method_exists($this->iter, 'err')) {
148
+            return $this->iter->err();
149
+        }
150
+        if (property_exists($this->iter, 'err')) {
151
+            return $this->iter->err;
152
+        }
153
+
154
+        return false;
155
+    }
156
+
157
+    public function __construct(Iterator $iter, $command, $info) {
158
+        parent::__construct($iter);
159
+        parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator)
160
+
161
+        // recuperer l'iterateur transmis
162
+        $this->iter = $this->getInnerIterator();
163
+        $this->command = $command;
164
+        $this->info = $info;
165
+        $this->pos = 0;
166
+        $this->fetched = 0;
167
+
168
+        // chercher la liste des champs a retourner par
169
+        // fetch si l'objet ne les calcule pas tout seul
170
+        if (!method_exists($this->iter, 'fetch')) {
171
+            $this->calculer_select();
172
+            $this->calculer_filtres();
173
+        }
174
+
175
+        // emptyIterator critere {si} faux n'a pas d'erreur !
176
+        if (isset($this->iter->err)) {
177
+            $this->err = $this->iter->err;
178
+        }
179
+
180
+        // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite)
181
+        //$this->total = $this->count();
182
+    }
183
+
184
+
185
+    // calcule les elements a retournes par fetch()
186
+    // enleve les elements inutiles du select()
187
+    //
188
+    private function calculer_select() {
189
+        if ($select = &$this->command['select']) {
190
+            foreach ($select as $s) {
191
+                // /!\ $s = '.nom'
192
+                if ($s[0] == '.') {
193
+                    $s = substr($s, 1);
194
+                }
195
+                $this->select[] = $s;
196
+            }
197
+        }
198
+    }
199
+
200
+    // recuperer la valeur d'une balise #X
201
+    // en fonction des methodes
202
+    // et proprietes disponibles
203
+    public function get_select($nom) {
204
+        if (
205
+            is_object($this->iter)
206
+            and method_exists($this->iter, $nom)
207
+        ) {
208
+            try {
209
+                return $this->iter->$nom();
210
+            } catch (Exception $e) {
211
+                // #GETCHILDREN sur un fichier de DirectoryIterator ...
212
+                spip_log("Methode $nom en echec sur " . get_class($this->iter));
213
+                spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode");
214
+
215
+                return '';
216
+            }
217
+        }
218
+        /*
219 219
 		if (property_exists($this->iter, $nom)) {
220 220
 			return $this->iter->$nom;
221 221
 		}*/
222
-		// cle et valeur par defaut
223
-		// ICI PLANTAGE SI ON NE CONTROLE PAS $nom
224
-		if (
225
-			in_array($nom, ['cle', 'valeur'])
226
-			and method_exists($this, $nom)
227
-		) {
228
-			return $this->$nom();
229
-		}
230
-
231
-		// Par defaut chercher en xpath dans la valeur()
232
-		return table_valeur($this->valeur(), $nom, null);
233
-	}
234
-
235
-
236
-	private function calculer_filtres() {
237
-
238
-		// Issu de calculer_select() de public/composer L.519
239
-		// TODO: externaliser...
240
-		//
241
-		// retirer les criteres vides:
242
-		// {X ?} avec X absent de l'URL
243
-		// {par #ENV{X}} avec X absent de l'URL
244
-		// IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil)
245
-		if ($where = &$this->command['where']) {
246
-			foreach ($where as $k => $v) {
247
-				if (is_array($v)) {
248
-					if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) {
249
-						$op = false;
250
-					} elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) {
251
-						$op = false;
252
-					} else {
253
-						$op = $v[0] ? $v[0] : $v;
254
-					}
255
-				} else {
256
-					$op = $v;
257
-				}
258
-				if ((!$op) or ($op == 1) or ($op == '0=0')) {
259
-					unset($where[$k]);
260
-				}
261
-				// traiter {cle IN a,b} ou {valeur !IN a,b}
262
-				if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) {
263
-					$this->ajouter_filtre($regs[1], 'IN', $regs[3], $regs[2]);
264
-					unset($op, $where[$k]);
265
-				}
266
-			}
267
-			foreach ($where as $k => $v) {
268
-				// 3 possibilites : count($v) =
269
-				// * 1 : {x y} ; on recoit $v[0] = y
270
-				// * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y}
271
-				// * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y
272
-
273
-				// 1 : forcement traite par un critere, on passe
274
-				if (!$v or count($v) == 1) {
275
-					continue;
276
-				}
277
-				if (count($v) == 2 and is_array($v[1])) {
278
-					$this->ajouter_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT');
279
-				}
280
-				if (count($v) == 3) {
281
-					$this->ajouter_filtre($v[1], $v[0], $v[2]);
282
-				}
283
-			}
284
-		}
285
-
286
-		// critere {2,7}
287
-		if (isset($this->command['limit']) and $this->command['limit']) {
288
-			$limit = explode(',', $this->command['limit']);
289
-			$this->offset = $limit[0];
290
-			$this->limit = $limit[1];
291
-		}
292
-
293
-		// Creer la fonction de filtrage sur $this
294
-		if ($this->filtre) {
295
-			$filtres = 'return (' . join(') AND (', $this->filtre) . ');';
296
-			$this->func_filtre = function () use ($filtres) {
297
-				return eval($filtres);
298
-			};
299
-		}
300
-	}
301
-
302
-
303
-	protected function ajouter_filtre($cle, $op, $valeur, $not = false) {
304
-		if (method_exists($this->iter, 'exception_des_criteres')) {
305
-			if (in_array($cle, $this->iter->exception_des_criteres())) {
306
-				return;
307
-			}
308
-		}
309
-		// TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ?
310
-		# mais c'est normalement deja opere par calculer_critere_infixe()
311
-		# qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1}
312
-		# ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present.
313
-		# il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir...
314
-
315
-		# if (!in_array($cle, array('cle', 'valeur')))
316
-		#	return;
317
-
318
-		$a = '$this->get_select(\'' . $cle . '\')';
319
-
320
-		$filtre = '';
321
-
322
-		if ($op == 'REGEXP') {
323
-			$filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')';
324
-			$op = '';
325
-		} else {
326
-			if ($op == 'LIKE') {
327
-				$valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur));
328
-				$filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')';
329
-				$op = '';
330
-			} else {
331
-				if ($op == '=') {
332
-					$op = '==';
333
-				} else {
334
-					if ($op == 'IN') {
335
-						$filtre = 'in_array(' . $a . ', array' . $valeur . ')';
336
-						$op = '';
337
-					} else {
338
-						if (!in_array($op, ['<', '<=', '>', '>='])) {
339
-							spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette
340
-							$op = '';
341
-						}
342
-					}
343
-				}
344
-			}
345
-		}
346
-
347
-		if ($op) {
348
-			$filtre = $a . $op . str_replace('\"', '"', $valeur);
349
-		}
350
-
351
-		if ($not) {
352
-			$filtre = "!($filtre)";
353
-		}
354
-
355
-		if ($filtre) {
356
-			$this->filtre[] = $filtre;
357
-		}
358
-	}
359
-
360
-
361
-	public function next() {
362
-		$this->pos++;
363
-		parent::next();
364
-	}
365
-
366
-	/**
367
-	 * revient au depart
368
-	 *
369
-	 * @return void
370
-	 */
371
-	public function rewind() {
372
-		$this->pos = 0;
373
-		$this->fetched = 0;
374
-		parent::rewind();
375
-	}
376
-
377
-
378
-	# Extension SPIP des iterateurs PHP
379
-	/**
380
-	 * type de l'iterateur
381
-	 *
382
-	 * @var string
383
-	 */
384
-	protected $type;
385
-
386
-	/**
387
-	 * parametres de l'iterateur
388
-	 *
389
-	 * @var array
390
-	 */
391
-	protected $command;
392
-
393
-	/**
394
-	 * infos de compilateur
395
-	 *
396
-	 * @var array
397
-	 */
398
-	protected $info;
399
-
400
-	/**
401
-	 * position courante de l'iterateur
402
-	 *
403
-	 * @var int
404
-	 */
405
-	protected $pos = null;
406
-
407
-	/**
408
-	 * nombre total resultats dans l'iterateur
409
-	 *
410
-	 * @var int
411
-	 */
412
-	protected $total = null;
413
-
414
-	/**
415
-	 * nombre maximal de recherche pour $total
416
-	 * si l'iterateur n'implemente pas de fonction specifique
417
-	 */
418
-	protected $max = 100000;
419
-
420
-
421
-	/**
422
-	 * Liste des champs a inserer dans les $row
423
-	 * retournes par ->fetch()
424
-	 */
425
-	protected $select = [];
426
-
427
-
428
-	/**
429
-	 * aller a la position absolue n,
430
-	 * comptee depuis le debut
431
-	 *
432
-	 * @param int $n
433
-	 *   absolute pos
434
-	 * @param string $continue
435
-	 *   param for sql_ api
436
-	 * @return bool
437
-	 *   success or fail if not implemented
438
-	 */
439
-	public function seek($n = 0, $continue = null) {
440
-		if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) {
441
-			$this->seek_loop($n);
442
-		}
443
-		$this->pos = $n;
444
-		$this->fetched = $n;
445
-
446
-		return true;
447
-	}
448
-
449
-	/*
222
+        // cle et valeur par defaut
223
+        // ICI PLANTAGE SI ON NE CONTROLE PAS $nom
224
+        if (
225
+            in_array($nom, ['cle', 'valeur'])
226
+            and method_exists($this, $nom)
227
+        ) {
228
+            return $this->$nom();
229
+        }
230
+
231
+        // Par defaut chercher en xpath dans la valeur()
232
+        return table_valeur($this->valeur(), $nom, null);
233
+    }
234
+
235
+
236
+    private function calculer_filtres() {
237
+
238
+        // Issu de calculer_select() de public/composer L.519
239
+        // TODO: externaliser...
240
+        //
241
+        // retirer les criteres vides:
242
+        // {X ?} avec X absent de l'URL
243
+        // {par #ENV{X}} avec X absent de l'URL
244
+        // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil)
245
+        if ($where = &$this->command['where']) {
246
+            foreach ($where as $k => $v) {
247
+                if (is_array($v)) {
248
+                    if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) {
249
+                        $op = false;
250
+                    } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) {
251
+                        $op = false;
252
+                    } else {
253
+                        $op = $v[0] ? $v[0] : $v;
254
+                    }
255
+                } else {
256
+                    $op = $v;
257
+                }
258
+                if ((!$op) or ($op == 1) or ($op == '0=0')) {
259
+                    unset($where[$k]);
260
+                }
261
+                // traiter {cle IN a,b} ou {valeur !IN a,b}
262
+                if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) {
263
+                    $this->ajouter_filtre($regs[1], 'IN', $regs[3], $regs[2]);
264
+                    unset($op, $where[$k]);
265
+                }
266
+            }
267
+            foreach ($where as $k => $v) {
268
+                // 3 possibilites : count($v) =
269
+                // * 1 : {x y} ; on recoit $v[0] = y
270
+                // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y}
271
+                // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y
272
+
273
+                // 1 : forcement traite par un critere, on passe
274
+                if (!$v or count($v) == 1) {
275
+                    continue;
276
+                }
277
+                if (count($v) == 2 and is_array($v[1])) {
278
+                    $this->ajouter_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT');
279
+                }
280
+                if (count($v) == 3) {
281
+                    $this->ajouter_filtre($v[1], $v[0], $v[2]);
282
+                }
283
+            }
284
+        }
285
+
286
+        // critere {2,7}
287
+        if (isset($this->command['limit']) and $this->command['limit']) {
288
+            $limit = explode(',', $this->command['limit']);
289
+            $this->offset = $limit[0];
290
+            $this->limit = $limit[1];
291
+        }
292
+
293
+        // Creer la fonction de filtrage sur $this
294
+        if ($this->filtre) {
295
+            $filtres = 'return (' . join(') AND (', $this->filtre) . ');';
296
+            $this->func_filtre = function () use ($filtres) {
297
+                return eval($filtres);
298
+            };
299
+        }
300
+    }
301
+
302
+
303
+    protected function ajouter_filtre($cle, $op, $valeur, $not = false) {
304
+        if (method_exists($this->iter, 'exception_des_criteres')) {
305
+            if (in_array($cle, $this->iter->exception_des_criteres())) {
306
+                return;
307
+            }
308
+        }
309
+        // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ?
310
+        # mais c'est normalement deja opere par calculer_critere_infixe()
311
+        # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1}
312
+        # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present.
313
+        # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir...
314
+
315
+        # if (!in_array($cle, array('cle', 'valeur')))
316
+        #	return;
317
+
318
+        $a = '$this->get_select(\'' . $cle . '\')';
319
+
320
+        $filtre = '';
321
+
322
+        if ($op == 'REGEXP') {
323
+            $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')';
324
+            $op = '';
325
+        } else {
326
+            if ($op == 'LIKE') {
327
+                $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur));
328
+                $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')';
329
+                $op = '';
330
+            } else {
331
+                if ($op == '=') {
332
+                    $op = '==';
333
+                } else {
334
+                    if ($op == 'IN') {
335
+                        $filtre = 'in_array(' . $a . ', array' . $valeur . ')';
336
+                        $op = '';
337
+                    } else {
338
+                        if (!in_array($op, ['<', '<=', '>', '>='])) {
339
+                            spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette
340
+                            $op = '';
341
+                        }
342
+                    }
343
+                }
344
+            }
345
+        }
346
+
347
+        if ($op) {
348
+            $filtre = $a . $op . str_replace('\"', '"', $valeur);
349
+        }
350
+
351
+        if ($not) {
352
+            $filtre = "!($filtre)";
353
+        }
354
+
355
+        if ($filtre) {
356
+            $this->filtre[] = $filtre;
357
+        }
358
+    }
359
+
360
+
361
+    public function next() {
362
+        $this->pos++;
363
+        parent::next();
364
+    }
365
+
366
+    /**
367
+     * revient au depart
368
+     *
369
+     * @return void
370
+     */
371
+    public function rewind() {
372
+        $this->pos = 0;
373
+        $this->fetched = 0;
374
+        parent::rewind();
375
+    }
376
+
377
+
378
+    # Extension SPIP des iterateurs PHP
379
+    /**
380
+     * type de l'iterateur
381
+     *
382
+     * @var string
383
+     */
384
+    protected $type;
385
+
386
+    /**
387
+     * parametres de l'iterateur
388
+     *
389
+     * @var array
390
+     */
391
+    protected $command;
392
+
393
+    /**
394
+     * infos de compilateur
395
+     *
396
+     * @var array
397
+     */
398
+    protected $info;
399
+
400
+    /**
401
+     * position courante de l'iterateur
402
+     *
403
+     * @var int
404
+     */
405
+    protected $pos = null;
406
+
407
+    /**
408
+     * nombre total resultats dans l'iterateur
409
+     *
410
+     * @var int
411
+     */
412
+    protected $total = null;
413
+
414
+    /**
415
+     * nombre maximal de recherche pour $total
416
+     * si l'iterateur n'implemente pas de fonction specifique
417
+     */
418
+    protected $max = 100000;
419
+
420
+
421
+    /**
422
+     * Liste des champs a inserer dans les $row
423
+     * retournes par ->fetch()
424
+     */
425
+    protected $select = [];
426
+
427
+
428
+    /**
429
+     * aller a la position absolue n,
430
+     * comptee depuis le debut
431
+     *
432
+     * @param int $n
433
+     *   absolute pos
434
+     * @param string $continue
435
+     *   param for sql_ api
436
+     * @return bool
437
+     *   success or fail if not implemented
438
+     */
439
+    public function seek($n = 0, $continue = null) {
440
+        if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) {
441
+            $this->seek_loop($n);
442
+        }
443
+        $this->pos = $n;
444
+        $this->fetched = $n;
445
+
446
+        return true;
447
+    }
448
+
449
+    /*
450 450
 	 * aller a la position $n en parcourant
451 451
 	 * un par un tous les elements
452 452
 	 */
453
-	private function seek_loop($n) {
454
-		if ($this->pos > $n) {
455
-			$this->rewind();
456
-		}
457
-
458
-		while ($this->pos < $n and $this->valid()) {
459
-			$this->next();
460
-		}
461
-
462
-		return true;
463
-	}
464
-
465
-	/**
466
-	 * Avancer de $saut pas
467
-	 *
468
-	 * @param  $saut
469
-	 * @param  $max
470
-	 * @return int
471
-	 */
472
-	public function skip($saut, $max = null) {
473
-		// pas de saut en arriere autorise pour cette fonction
474
-		if (($saut = intval($saut)) <= 0) {
475
-			return $this->pos;
476
-		}
477
-		$seek = $this->pos + $saut;
478
-		// si le saut fait depasser le maxi, on libere la resource
479
-		// et on sort
480
-		if (is_null($max)) {
481
-			$max = $this->count();
482
-		}
483
-
484
-		if ($seek >= $max or $seek >= $this->count()) {
485
-			// sortie plus rapide que de faire next() jusqu'a la fin !
486
-			$this->free();
487
-
488
-			return $max;
489
-		}
490
-
491
-		$this->seek($seek);
492
-
493
-		return $this->pos;
494
-	}
495
-
496
-	/**
497
-	 * Renvoyer un tableau des donnees correspondantes
498
-	 * a la position courante de l'iterateur
499
-	 * en controlant si on respecte le filtre
500
-	 * Appliquer aussi le critere {offset,limit}
501
-	 *
502
-	 * @return array|bool
503
-	 */
504
-	public function fetch() {
505
-		if (method_exists($this->iter, 'fetch')) {
506
-			return $this->iter->fetch();
507
-		} else {
508
-			while (
509
-				$this->valid()
510
-				and (
511
-					!$this->accept()
512
-					or (isset($this->offset) and $this->fetched++ < $this->offset)
513
-				)
514
-			) {
515
-				$this->next();
516
-			}
517
-
518
-			if (!$this->valid()) {
519
-				return false;
520
-			}
521
-
522
-			if (
523
-				isset($this->limit)
524
-				and $this->fetched > $this->offset + $this->limit
525
-			) {
526
-				return false;
527
-			}
528
-
529
-			$r = [];
530
-			foreach ($this->select as $nom) {
531
-				$r[$nom] = $this->get_select($nom);
532
-			}
533
-			$this->next();
534
-
535
-			return $r;
536
-		}
537
-	}
538
-
539
-	// retourner la cle pour #CLE
540
-	public function cle() {
541
-		return $this->key();
542
-	}
543
-
544
-	// retourner la valeur pour #VALEUR
545
-	public function valeur() {
546
-		return $this->current();
547
-	}
548
-
549
-	/**
550
-	 * Accepte-t-on l'entree courante lue ?
551
-	 * On execute les filtres pour le savoir.
552
-	 **/
553
-	public function accept() {
554
-		if ($f = $this->func_filtre) {
555
-			return $f();
556
-		}
557
-
558
-		return true;
559
-	}
560
-
561
-	/**
562
-	 * liberer la ressource
563
-	 *
564
-	 * @return bool
565
-	 */
566
-	public function free() {
567
-		if (method_exists($this->iter, 'free')) {
568
-			$this->iter->free();
569
-		}
570
-		$this->pos = $this->total = 0;
571
-
572
-		return true;
573
-	}
574
-
575
-	/**
576
-	 * Compter le nombre total de resultats
577
-	 * pour #TOTAL_BOUCLE
578
-	 *
579
-	 * @return int
580
-	 */
581
-	public function count() {
582
-		if (is_null($this->total)) {
583
-			if (
584
-				method_exists($this->iter, 'count')
585
-				and !$this->func_filtre
586
-			) {
587
-				return $this->total = $this->iter->count();
588
-			} else {
589
-				// compter les lignes et rembobiner
590
-				$total = 0;
591
-				$pos = $this->pos; // sauver la position
592
-				$this->rewind();
593
-				while ($this->fetch() and $total < $this->max) {
594
-					$total++;
595
-				}
596
-				$this->seek($pos);
597
-				$this->total = $total;
598
-			}
599
-		}
600
-
601
-		return $this->total;
602
-	}
453
+    private function seek_loop($n) {
454
+        if ($this->pos > $n) {
455
+            $this->rewind();
456
+        }
457
+
458
+        while ($this->pos < $n and $this->valid()) {
459
+            $this->next();
460
+        }
461
+
462
+        return true;
463
+    }
464
+
465
+    /**
466
+     * Avancer de $saut pas
467
+     *
468
+     * @param  $saut
469
+     * @param  $max
470
+     * @return int
471
+     */
472
+    public function skip($saut, $max = null) {
473
+        // pas de saut en arriere autorise pour cette fonction
474
+        if (($saut = intval($saut)) <= 0) {
475
+            return $this->pos;
476
+        }
477
+        $seek = $this->pos + $saut;
478
+        // si le saut fait depasser le maxi, on libere la resource
479
+        // et on sort
480
+        if (is_null($max)) {
481
+            $max = $this->count();
482
+        }
483
+
484
+        if ($seek >= $max or $seek >= $this->count()) {
485
+            // sortie plus rapide que de faire next() jusqu'a la fin !
486
+            $this->free();
487
+
488
+            return $max;
489
+        }
490
+
491
+        $this->seek($seek);
492
+
493
+        return $this->pos;
494
+    }
495
+
496
+    /**
497
+     * Renvoyer un tableau des donnees correspondantes
498
+     * a la position courante de l'iterateur
499
+     * en controlant si on respecte le filtre
500
+     * Appliquer aussi le critere {offset,limit}
501
+     *
502
+     * @return array|bool
503
+     */
504
+    public function fetch() {
505
+        if (method_exists($this->iter, 'fetch')) {
506
+            return $this->iter->fetch();
507
+        } else {
508
+            while (
509
+                $this->valid()
510
+                and (
511
+                    !$this->accept()
512
+                    or (isset($this->offset) and $this->fetched++ < $this->offset)
513
+                )
514
+            ) {
515
+                $this->next();
516
+            }
517
+
518
+            if (!$this->valid()) {
519
+                return false;
520
+            }
521
+
522
+            if (
523
+                isset($this->limit)
524
+                and $this->fetched > $this->offset + $this->limit
525
+            ) {
526
+                return false;
527
+            }
528
+
529
+            $r = [];
530
+            foreach ($this->select as $nom) {
531
+                $r[$nom] = $this->get_select($nom);
532
+            }
533
+            $this->next();
534
+
535
+            return $r;
536
+        }
537
+    }
538
+
539
+    // retourner la cle pour #CLE
540
+    public function cle() {
541
+        return $this->key();
542
+    }
543
+
544
+    // retourner la valeur pour #VALEUR
545
+    public function valeur() {
546
+        return $this->current();
547
+    }
548
+
549
+    /**
550
+     * Accepte-t-on l'entree courante lue ?
551
+     * On execute les filtres pour le savoir.
552
+     **/
553
+    public function accept() {
554
+        if ($f = $this->func_filtre) {
555
+            return $f();
556
+        }
557
+
558
+        return true;
559
+    }
560
+
561
+    /**
562
+     * liberer la ressource
563
+     *
564
+     * @return bool
565
+     */
566
+    public function free() {
567
+        if (method_exists($this->iter, 'free')) {
568
+            $this->iter->free();
569
+        }
570
+        $this->pos = $this->total = 0;
571
+
572
+        return true;
573
+    }
574
+
575
+    /**
576
+     * Compter le nombre total de resultats
577
+     * pour #TOTAL_BOUCLE
578
+     *
579
+     * @return int
580
+     */
581
+    public function count() {
582
+        if (is_null($this->total)) {
583
+            if (
584
+                method_exists($this->iter, 'count')
585
+                and !$this->func_filtre
586
+            ) {
587
+                return $this->total = $this->iter->count();
588
+            } else {
589
+                // compter les lignes et rembobiner
590
+                $total = 0;
591
+                $pos = $this->pos; // sauver la position
592
+                $this->rewind();
593
+                while ($this->fetch() and $total < $this->max) {
594
+                    $total++;
595
+                }
596
+                $this->seek($pos);
597
+                $this->total = $total;
598
+            }
599
+        }
600
+
601
+        return $this->total;
602
+    }
603 603
 }
Please login to merge, or discard this patch.