Completed
Push — master ( 99acaa...4aa2c5 )
by cam
01:19
created
ecrire/action/debloquer_edition.php 1 patch
Indentation   +13 added lines, -13 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
 /**
@@ -31,17 +31,17 @@  discard block
 block discarded – undo
31 31
  */
32 32
 function action_debloquer_edition_dist() {
33 33
 
34
-	$securiser_action = charger_fonction('securiser_action', 'inc');
35
-	$arg = $securiser_action();
34
+    $securiser_action = charger_fonction('securiser_action', 'inc');
35
+    $arg = $securiser_action();
36 36
 
37
-	if ($arg) {
38
-		include_spip('inc/drapeau_edition');
39
-		if ($arg == 'tous') {
40
-			debloquer_tous($GLOBALS['visiteur_session']['id_auteur']);
41
-		} else {
42
-			$arg = explode('-', $arg);
43
-			[$objet, $id_objet] = $arg;
44
-			debloquer_edition($GLOBALS['visiteur_session']['id_auteur'], $id_objet, $objet);
45
-		}
46
-	}
37
+    if ($arg) {
38
+        include_spip('inc/drapeau_edition');
39
+        if ($arg == 'tous') {
40
+            debloquer_tous($GLOBALS['visiteur_session']['id_auteur']);
41
+        } else {
42
+            $arg = explode('-', $arg);
43
+            [$objet, $id_objet] = $arg;
44
+            debloquer_edition($GLOBALS['visiteur_session']['id_auteur'], $id_objet, $objet);
45
+        }
46
+    }
47 47
 }
Please login to merge, or discard this patch.
ecrire/action/cookie.php 2 patches
Indentation   +85 added lines, -85 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/actions');
@@ -33,93 +33,93 @@  discard block
 block discarded – undo
33 33
  * @return void
34 34
  */
35 35
 function action_cookie_dist($set_cookie_admin = null, $change_session = null) {
36
-	$redirect_echec = $redirect = null;
37
-	$test_echec_cookie = null;
38
-	$url = '';
39
-	if (is_null($set_cookie_admin)) {
40
-		$set_cookie_admin = _request('cookie_admin');
41
-		$change_session = _request('change_session');
42
-		$test_echec_cookie = _request('test_echec_cookie');
36
+    $redirect_echec = $redirect = null;
37
+    $test_echec_cookie = null;
38
+    $url = '';
39
+    if (is_null($set_cookie_admin)) {
40
+        $set_cookie_admin = _request('cookie_admin');
41
+        $change_session = _request('change_session');
42
+        $test_echec_cookie = _request('test_echec_cookie');
43 43
 
44
-		// La cible de notre operation de connexion
45
-		$url = securiser_redirect_action(_request('url'));
46
-		$redirect = $url ?: generer_url_ecrire('accueil');
47
-		$redirect_echec = _request('url_echec');
48
-		if (!isset($redirect_echec)) {
49
-			if (strpos($redirect, (string) _DIR_RESTREINT_ABS) !== false) {
50
-				$redirect_echec = generer_url_public('login', '', true);
51
-			} else {
52
-				$redirect_echec = $redirect;
53
-			}
54
-		}
55
-	}
44
+        // La cible de notre operation de connexion
45
+        $url = securiser_redirect_action(_request('url'));
46
+        $redirect = $url ?: generer_url_ecrire('accueil');
47
+        $redirect_echec = _request('url_echec');
48
+        if (!isset($redirect_echec)) {
49
+            if (strpos($redirect, (string) _DIR_RESTREINT_ABS) !== false) {
50
+                $redirect_echec = generer_url_public('login', '', true);
51
+            } else {
52
+                $redirect_echec = $redirect;
53
+            }
54
+        }
55
+    }
56 56
 
57 57
 
58
-	// rejoue le cookie pour renouveler spip_session
59
-	if ($change_session == 'oui') {
60
-		$session = charger_fonction('session', 'inc');
61
-		$session(true);
62
-		spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']);
63
-		http_response_code(204); // No Content
64
-		return;
65
-	}
58
+    // rejoue le cookie pour renouveler spip_session
59
+    if ($change_session == 'oui') {
60
+        $session = charger_fonction('session', 'inc');
61
+        $session(true);
62
+        spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']);
63
+        http_response_code(204); // No Content
64
+        return;
65
+    }
66 66
 
67
-	// tentative de connexion en auth_http
68
-	if (_request('essai_auth_http') and !$GLOBALS['ignore_auth_http']) {
69
-		include_spip('inc/auth');
70
-		if (
71
-			@$_SERVER['PHP_AUTH_USER']
72
-			and @$_SERVER['PHP_AUTH_PW']
73
-			and $auteur = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])
74
-		) {
75
-			auth_loger($auteur);
76
-			redirige_par_entete(parametre_url($redirect, 't', time(), '&'));
77
-		} else {
78
-			ask_php_auth(
79
-				_T('info_connexion_refusee'),
80
-				_T('login_login_pass_incorrect'),
81
-				_T('login_retour_site'),
82
-				'url=' . rawurlencode($redirect),
83
-				_T('login_nouvelle_tentative'),
84
-				(strpos($url, (string) _DIR_RESTREINT_ABS) !== false)
85
-			);
86
-		}
87
-	} else {
88
-		// en cas de login sur bonjour=oui, on tente de poser un cookie
89
-		// puis de passer au login qui diagnostiquera l'echec de cookie
90
-		// le cas echeant.
91
-		if ($test_echec_cookie == 'oui') {
92
-			spip_setcookie('spip_session', 'test_echec_cookie');
93
-			if ($redirect) {
94
-				$redirect = parametre_url(
95
-					parametre_url($redirect_echec, 'var_echec_cookie', 'oui', '&'),
96
-					'url',
97
-					rawurlencode($redirect),
98
-					'&'
99
-				);
100
-			}
101
-		} else {
102
-			$cook = $_COOKIE['spip_admin'] ?? '';
103
-			// Suppression cookie d'admin ?
104
-			if ($set_cookie_admin == 'non') {
105
-				if ($cook) {
106
-					spip_setcookie('spip_admin', $cook, [
107
-						'expires' => time() - 3600 * 24
108
-					]);
109
-				}
110
-			} // Ajout de cookie d'admin
111
-			else {
112
-				if ($set_cookie_admin and _DUREE_COOKIE_ADMIN) {
113
-					spip_setcookie('spip_admin', $set_cookie_admin, [
114
-						'expires' => time() + max(_DUREE_COOKIE_ADMIN, 2 * _RENOUVELLE_ALEA)
115
-					]);
116
-				}
117
-			}
118
-		}
119
-	}
67
+    // tentative de connexion en auth_http
68
+    if (_request('essai_auth_http') and !$GLOBALS['ignore_auth_http']) {
69
+        include_spip('inc/auth');
70
+        if (
71
+            @$_SERVER['PHP_AUTH_USER']
72
+            and @$_SERVER['PHP_AUTH_PW']
73
+            and $auteur = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])
74
+        ) {
75
+            auth_loger($auteur);
76
+            redirige_par_entete(parametre_url($redirect, 't', time(), '&'));
77
+        } else {
78
+            ask_php_auth(
79
+                _T('info_connexion_refusee'),
80
+                _T('login_login_pass_incorrect'),
81
+                _T('login_retour_site'),
82
+                'url=' . rawurlencode($redirect),
83
+                _T('login_nouvelle_tentative'),
84
+                (strpos($url, (string) _DIR_RESTREINT_ABS) !== false)
85
+            );
86
+        }
87
+    } else {
88
+        // en cas de login sur bonjour=oui, on tente de poser un cookie
89
+        // puis de passer au login qui diagnostiquera l'echec de cookie
90
+        // le cas echeant.
91
+        if ($test_echec_cookie == 'oui') {
92
+            spip_setcookie('spip_session', 'test_echec_cookie');
93
+            if ($redirect) {
94
+                $redirect = parametre_url(
95
+                    parametre_url($redirect_echec, 'var_echec_cookie', 'oui', '&'),
96
+                    'url',
97
+                    rawurlencode($redirect),
98
+                    '&'
99
+                );
100
+            }
101
+        } else {
102
+            $cook = $_COOKIE['spip_admin'] ?? '';
103
+            // Suppression cookie d'admin ?
104
+            if ($set_cookie_admin == 'non') {
105
+                if ($cook) {
106
+                    spip_setcookie('spip_admin', $cook, [
107
+                        'expires' => time() - 3600 * 24
108
+                    ]);
109
+                }
110
+            } // Ajout de cookie d'admin
111
+            else {
112
+                if ($set_cookie_admin and _DUREE_COOKIE_ADMIN) {
113
+                    spip_setcookie('spip_admin', $set_cookie_admin, [
114
+                        'expires' => time() + max(_DUREE_COOKIE_ADMIN, 2 * _RENOUVELLE_ALEA)
115
+                    ]);
116
+                }
117
+            }
118
+        }
119
+    }
120 120
 
121
-	// Redirection finale
122
-	if ($redirect) {
123
-		redirige_par_entete($redirect, true);
124
-	}
121
+    // Redirection finale
122
+    if ($redirect) {
123
+        redirige_par_entete($redirect, true);
124
+    }
125 125
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	if ($change_session == 'oui') {
60 60
 		$session = charger_fonction('session', 'inc');
61 61
 		$session(true);
62
-		spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']);
62
+		spip_log('statut 204 pour '.$_SERVER['REQUEST_URI']);
63 63
 		http_response_code(204); // No Content
64 64
 		return;
65 65
 	}
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 				_T('info_connexion_refusee'),
80 80
 				_T('login_login_pass_incorrect'),
81 81
 				_T('login_retour_site'),
82
-				'url=' . rawurlencode($redirect),
82
+				'url='.rawurlencode($redirect),
83 83
 				_T('login_nouvelle_tentative'),
84 84
 				(strpos($url, (string) _DIR_RESTREINT_ABS) !== false)
85 85
 			);
Please login to merge, or discard this patch.
ecrire/action/desinstaller_plugin.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -32,28 +32,28 @@  discard block
 block discarded – undo
32 32
  */
33 33
 function action_desinstaller_plugin_dist() {
34 34
 
35
-	$securiser_action = charger_fonction('securiser_action', 'inc');
36
-	$arg = $securiser_action();
37
-	[$dir_plugins, $plugin] = explode('::', $arg);
38
-	$dir_type = '_DIR_PLUGINS';
39
-	if (defined('_DIR_PLUGINS_SUPPL') and $dir_plugins == _DIR_PLUGINS_SUPPL) {
40
-		$dir_type = '_DIR_PLUGINS_SUPPL';
41
-	}
42
-	$installer_plugins = charger_fonction('installer', 'plugins');
43
-	$infos = $installer_plugins($plugin, 'uninstall', $dir_type);
44
-	if ($infos and !$infos['install_test'][0]) {
45
-		include_spip('inc/plugin');
46
-		ecrire_plugin_actifs([$plugin], false, 'enleve');
47
-		$erreur = '';
48
-	} else {
49
-		$erreur = 'erreur_plugin_desinstalation_echouee';
50
-	}
51
-	if ($redirect = _request('redirect')) {
52
-		include_spip('inc/headers');
53
-		if ($erreur) {
54
-			$redirect = parametre_url($redirect, 'erreur', $erreur);
55
-		}
56
-		$redirect = str_replace('&', '&', $redirect);
57
-		redirige_par_entete($redirect);
58
-	}
35
+    $securiser_action = charger_fonction('securiser_action', 'inc');
36
+    $arg = $securiser_action();
37
+    [$dir_plugins, $plugin] = explode('::', $arg);
38
+    $dir_type = '_DIR_PLUGINS';
39
+    if (defined('_DIR_PLUGINS_SUPPL') and $dir_plugins == _DIR_PLUGINS_SUPPL) {
40
+        $dir_type = '_DIR_PLUGINS_SUPPL';
41
+    }
42
+    $installer_plugins = charger_fonction('installer', 'plugins');
43
+    $infos = $installer_plugins($plugin, 'uninstall', $dir_type);
44
+    if ($infos and !$infos['install_test'][0]) {
45
+        include_spip('inc/plugin');
46
+        ecrire_plugin_actifs([$plugin], false, 'enleve');
47
+        $erreur = '';
48
+    } else {
49
+        $erreur = 'erreur_plugin_desinstalation_echouee';
50
+    }
51
+    if ($redirect = _request('redirect')) {
52
+        include_spip('inc/headers');
53
+        if ($erreur) {
54
+            $redirect = parametre_url($redirect, 'erreur', $erreur);
55
+        }
56
+        $redirect = str_replace('&', '&', $redirect);
57
+        redirige_par_entete($redirect);
58
+    }
59 59
 }
Please login to merge, or discard this patch.
ecrire/balise/logo_.php 2 patches
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -54,84 +54,84 @@  discard block
 block discarded – undo
54 54
  */
55 55
 function balise_LOGO__dist($p) {
56 56
 
57
-	preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs);
58
-	$type = strtolower($regs[1]);
59
-	$suite_logo = $regs[2];
60
-
61
-	// cas de #LOGO_SITE_SPIP
62
-	if ($type == 'site_spip') {
63
-		$type = 'site';
64
-		$_id_objet = "\"'0'\"";
65
-	}
66
-
67
-	$id_objet = id_table_objet($type);
68
-	if (!isset($_id_objet)) {
69
-		$_id_objet = champ_sql($id_objet, $p);
70
-	}
71
-
72
-	$fichier = ($p->etoile === '**') ? -1 : 0;
73
-	$coord = [];
74
-	$align = $lien = '';
75
-	$mode_logo = '';
76
-
77
-	if ($p->param and !$p->param[0][0]) {
78
-		$params = $p->param[0];
79
-		array_shift($params);
80
-		foreach ($params as $a) {
81
-			if ($a[0]->type === 'texte') {
82
-				$n = $a[0]->texte;
83
-				if (is_numeric($n)) {
84
-					$coord[] = $n;
85
-				} elseif (in_array($n, ['top', 'left', 'right', 'center', 'bottom'])) {
86
-					$align = $n;
87
-				} elseif (in_array($n, ['auto', 'icone', 'apercu', 'vignette'])) {
88
-					$mode_logo = $n;
89
-				}
90
-			} else {
91
-				$lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle);
92
-			}
93
-		}
94
-	}
95
-
96
-	$coord_x = !$coord ? 0 : intval(array_shift($coord));
97
-	$coord_y = !$coord ? 0 : intval(array_shift($coord));
98
-
99
-	if ($p->etoile === '*') {
100
-		include_spip('balise/url_');
101
-		$lien = generer_generer_url_arg($type, $p, $_id_objet);
102
-	}
103
-
104
-	$connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : '';
105
-	if ($type == 'document') {
106
-		$qconnect = _q($connect);
107
-		$doc = "quete_document($_id_objet, $qconnect)";
108
-		if ($fichier) {
109
-			$code = "quete_logo_file($doc, $qconnect)";
110
-		} else {
111
-			$code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)";
112
-		}
113
-		// (x=non-faux ? y : '') pour affecter x en retournant y
114
-		if ($p->descr['documents']) {
115
-			$code = '(($doublons["documents"] .= ",". '
116
-				. $_id_objet
117
-				. ") ? $code : '')";
118
-		}
119
-	} elseif ($connect) {
120
-		$code = "''";
121
-		spip_log('Les logos distants ne sont pas prevus');
122
-	} else {
123
-		$code = logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $lien, $p, $suite_logo);
124
-	}
125
-
126
-	// demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0}
127
-	if ($coord_x or $coord_y) {
128
-		$code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))";
129
-	}
130
-
131
-	$p->code = $code;
132
-	$p->interdire_scripts = false;
133
-
134
-	return $p;
57
+    preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs);
58
+    $type = strtolower($regs[1]);
59
+    $suite_logo = $regs[2];
60
+
61
+    // cas de #LOGO_SITE_SPIP
62
+    if ($type == 'site_spip') {
63
+        $type = 'site';
64
+        $_id_objet = "\"'0'\"";
65
+    }
66
+
67
+    $id_objet = id_table_objet($type);
68
+    if (!isset($_id_objet)) {
69
+        $_id_objet = champ_sql($id_objet, $p);
70
+    }
71
+
72
+    $fichier = ($p->etoile === '**') ? -1 : 0;
73
+    $coord = [];
74
+    $align = $lien = '';
75
+    $mode_logo = '';
76
+
77
+    if ($p->param and !$p->param[0][0]) {
78
+        $params = $p->param[0];
79
+        array_shift($params);
80
+        foreach ($params as $a) {
81
+            if ($a[0]->type === 'texte') {
82
+                $n = $a[0]->texte;
83
+                if (is_numeric($n)) {
84
+                    $coord[] = $n;
85
+                } elseif (in_array($n, ['top', 'left', 'right', 'center', 'bottom'])) {
86
+                    $align = $n;
87
+                } elseif (in_array($n, ['auto', 'icone', 'apercu', 'vignette'])) {
88
+                    $mode_logo = $n;
89
+                }
90
+            } else {
91
+                $lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle);
92
+            }
93
+        }
94
+    }
95
+
96
+    $coord_x = !$coord ? 0 : intval(array_shift($coord));
97
+    $coord_y = !$coord ? 0 : intval(array_shift($coord));
98
+
99
+    if ($p->etoile === '*') {
100
+        include_spip('balise/url_');
101
+        $lien = generer_generer_url_arg($type, $p, $_id_objet);
102
+    }
103
+
104
+    $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : '';
105
+    if ($type == 'document') {
106
+        $qconnect = _q($connect);
107
+        $doc = "quete_document($_id_objet, $qconnect)";
108
+        if ($fichier) {
109
+            $code = "quete_logo_file($doc, $qconnect)";
110
+        } else {
111
+            $code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)";
112
+        }
113
+        // (x=non-faux ? y : '') pour affecter x en retournant y
114
+        if ($p->descr['documents']) {
115
+            $code = '(($doublons["documents"] .= ",". '
116
+                . $_id_objet
117
+                . ") ? $code : '')";
118
+        }
119
+    } elseif ($connect) {
120
+        $code = "''";
121
+        spip_log('Les logos distants ne sont pas prevus');
122
+    } else {
123
+        $code = logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $lien, $p, $suite_logo);
124
+    }
125
+
126
+    // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0}
127
+    if ($coord_x or $coord_y) {
128
+        $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))";
129
+    }
130
+
131
+    $p->code = $code;
132
+    $p->interdire_scripts = false;
133
+
134
+    return $p;
135 135
 }
136 136
 
137 137
 /**
@@ -158,20 +158,20 @@  discard block
 block discarded – undo
158 158
  *     Code compilé retournant le chemin du logo ou le code HTML du logo.
159 159
  **/
160 160
 function logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $_lien, $p, $suite) {
161
-	$code = "quete_logo('$id_objet', '" .
162
-		(($suite == '_SURVOL') ? 'off' :
163
-			(($suite == '_NORMAL') ? 'on' : 'ON')) .
164
-		"', $_id_objet," .
165
-		(($suite == '_RUBRIQUE') ?
166
-			champ_sql('id_rubrique', $p) :
167
-			(($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) .
168
-		', ' . intval($fichier) . ')';
169
-
170
-	if ($fichier) {
171
-		return $code;
172
-	}
173
-
174
-	$align = preg_replace(',\W,', '', $align);
175
-
176
-	return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')';
161
+    $code = "quete_logo('$id_objet', '" .
162
+        (($suite == '_SURVOL') ? 'off' :
163
+            (($suite == '_NORMAL') ? 'on' : 'ON')) .
164
+        "', $_id_objet," .
165
+        (($suite == '_RUBRIQUE') ?
166
+            champ_sql('id_rubrique', $p) :
167
+            (($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) .
168
+        ', ' . intval($fichier) . ')';
169
+
170
+    if ($fichier) {
171
+        return $code;
172
+    }
173
+
174
+    $align = preg_replace(',\W,', '', $align);
175
+
176
+    return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')';
177 177
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -10 removed lines patch added patch discarded remove patch
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 		if ($fichier) {
109 109
 			$code = "quete_logo_file($doc, $qconnect)";
110 110
 		} else {
111
-			$code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)";
111
+			$code = "quete_logo_document($doc, ".($lien ?: "''").", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)";
112 112
 		}
113 113
 		// (x=non-faux ? y : '') pour affecter x en retournant y
114 114
 		if ($p->descr['documents']) {
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 
126 126
 	// demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0}
127 127
 	if ($coord_x or $coord_y) {
128
-		$code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))";
128
+		$code = "filtrer('image_graver',filtrer('image_reduire',".$code.", '$coord_x', '$coord_y'))";
129 129
 	}
130 130
 
131 131
 	$p->code = $code;
@@ -158,14 +158,12 @@  discard block
 block discarded – undo
158 158
  *     Code compilé retournant le chemin du logo ou le code HTML du logo.
159 159
  **/
160 160
 function logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $_lien, $p, $suite) {
161
-	$code = "quete_logo('$id_objet', '" .
162
-		(($suite == '_SURVOL') ? 'off' :
163
-			(($suite == '_NORMAL') ? 'on' : 'ON')) .
164
-		"', $_id_objet," .
161
+	$code = "quete_logo('$id_objet', '".
162
+		(($suite == '_SURVOL') ? 'off' : (($suite == '_NORMAL') ? 'on' : 'ON')).
163
+		"', $_id_objet,".
165 164
 		(($suite == '_RUBRIQUE') ?
166
-			champ_sql('id_rubrique', $p) :
167
-			(($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) .
168
-		', ' . intval($fichier) . ')';
165
+			champ_sql('id_rubrique', $p) : (($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")).
166
+		', '.intval($fichier).')';
169 167
 
170 168
 	if ($fichier) {
171 169
 		return $code;
@@ -173,5 +171,5 @@  discard block
 block discarded – undo
173 171
 
174 172
 	$align = preg_replace(',\W,', '', $align);
175 173
 
176
-	return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')';
174
+	return "quete_html_logo($code, '$align', ".($_lien ?: "''").')';
177 175
 }
Please login to merge, or discard this patch.
ecrire/balise/url_logout.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
  *     Pile complétée du code compilé
37 37
  **/
38 38
 function balise_URL_LOGOUT($p) {
39
-	return calculer_balise_dynamique($p, 'URL_LOGOUT', []);
39
+    return calculer_balise_dynamique($p, 'URL_LOGOUT', []);
40 40
 }
41 41
 
42 42
 
@@ -52,9 +52,9 @@  discard block
 block discarded – undo
52 52
  *   Liste (url) des arguments collectés.
53 53
  */
54 54
 function balise_URL_LOGOUT_stat($args, $context_compil) {
55
-	$url = $args[0] ?? '';
55
+    $url = $args[0] ?? '';
56 56
 
57
-	return [$url];
57
+    return [$url];
58 58
 }
59 59
 
60 60
 /**
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
  **/
70 70
 function balise_URL_LOGOUT_dyn($cible) {
71 71
 
72
-	if (empty($GLOBALS['visiteur_session']['login']) and empty($GLOBALS['visiteur_session']['statut'])) {
73
-		return '';
74
-	}
72
+    if (empty($GLOBALS['visiteur_session']['login']) and empty($GLOBALS['visiteur_session']['statut'])) {
73
+        return '';
74
+    }
75 75
 
76
-	return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&')));
76
+    return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&')));
77 77
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -73,5 +73,5 @@
 block discarded – undo
73 73
 		return '';
74 74
 	}
75 75
 
76
-	return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&')));
76
+	return generer_url_action('logout', 'logout=public&url='.rawurlencode($cible ?: self('&')));
77 77
 }
Please login to merge, or discard this patch.
ecrire/balise/formulaire_inscription.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 include_spip('base/abstract_sql');
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
  *     Pile complétée du code compilé
44 44
  **/
45 45
 function balise_FORMULAIRE_INSCRIPTION($p) {
46
-	return calculer_balise_dynamique($p, 'FORMULAIRE_INSCRIPTION', []);
46
+    return calculer_balise_dynamique($p, 'FORMULAIRE_INSCRIPTION', []);
47 47
 }
48 48
 
49 49
 /**
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
  *   - chaîne vide sinon.
73 73
  */
74 74
 function balise_FORMULAIRE_INSCRIPTION_stat($args, $context_compil) {
75
-	[$mode, $id, $retour] = array_pad($args, 3, null);
76
-	include_spip('action/inscrire_auteur');
77
-	$mode = tester_statut_inscription($mode, $id ?? 0);
75
+    [$mode, $id, $retour] = array_pad($args, 3, null);
76
+    include_spip('action/inscrire_auteur');
77
+    $mode = tester_statut_inscription($mode, $id ?? 0);
78 78
 
79
-	return $mode ? [$mode, $id, $retour] : '';
79
+    return $mode ? [$mode, $id, $retour] : '';
80 80
 }
Please login to merge, or discard this patch.
ecrire/public/styliser.php 1 patch
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  **/
21 21
 
22 22
 if (!defined('_ECRIRE_INC_VERSION')) {
23
-	return;
23
+    return;
24 24
 }
25 25
 
26 26
 // Ce fichier doit imperativement definir la fonction ci-dessous:
@@ -39,59 +39,59 @@  discard block
 block discarded – undo
39 39
  * @return array
40 40
  */
41 41
 function public_styliser_dist($fond, $contexte, $lang = '', string $connect = '') {
42
-	static $styliser_par_z;
43
-
44
-	// s'assurer que le fond est licite
45
-	// car il peut etre construit a partir d'une variable d'environnement
46
-	if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) {
47
-		$fond = '404';
48
-	}
49
-
50
-	if (strncmp($fond, 'modeles/', 8) == 0) {
51
-		$modele = substr($fond, 8);
52
-		$modele = styliser_modele($modele, null, $contexte);
53
-		$fond = "modeles/$modele";
54
-	}
55
-
56
-	// Choisir entre $fond-dist.html, $fond=7.html, etc?
57
-	$id_rubrique = 0;
58
-	// Chercher le fond qui va servir de squelette
59
-	if ($r = quete_rubrique_fond($contexte)) {
60
-		[$id_rubrique, $lang] = $r;
61
-	}
62
-
63
-	// trouver un squelette du nom demande
64
-	// ne rien dire si on ne trouve pas,
65
-	// c'est l'appelant qui sait comment gerer la situation
66
-	// ou les plugins qui feront mieux dans le pipeline
67
-	$squelette = trouver_fond($fond, '', true);
68
-	$ext = $squelette['extension'];
69
-
70
-	$flux = [
71
-		'args' => [
72
-			'id_rubrique' => $id_rubrique,
73
-			'ext' => $ext,
74
-			'fond' => $fond,
75
-			'lang' => $lang,
76
-			'contexte' => $contexte, // le style d'un objet peut dependre de lui meme
77
-			'connect' => $connect
78
-		],
79
-		'data' => $squelette['fond'],
80
-	];
81
-
82
-	if (test_espace_prive() or defined('_ZPIP')) {
83
-		if (!$styliser_par_z) {
84
-			$styliser_par_z = charger_fonction('styliser_par_z', 'public');
85
-		}
86
-		$flux = $styliser_par_z($flux);
87
-	}
88
-
89
-	$flux = styliser_par_objets($flux);
90
-
91
-	// pipeline styliser
92
-	$squelette = pipeline('styliser', $flux);
93
-
94
-	return [$squelette, $ext, $ext, "$squelette.$ext"];
42
+    static $styliser_par_z;
43
+
44
+    // s'assurer que le fond est licite
45
+    // car il peut etre construit a partir d'une variable d'environnement
46
+    if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) {
47
+        $fond = '404';
48
+    }
49
+
50
+    if (strncmp($fond, 'modeles/', 8) == 0) {
51
+        $modele = substr($fond, 8);
52
+        $modele = styliser_modele($modele, null, $contexte);
53
+        $fond = "modeles/$modele";
54
+    }
55
+
56
+    // Choisir entre $fond-dist.html, $fond=7.html, etc?
57
+    $id_rubrique = 0;
58
+    // Chercher le fond qui va servir de squelette
59
+    if ($r = quete_rubrique_fond($contexte)) {
60
+        [$id_rubrique, $lang] = $r;
61
+    }
62
+
63
+    // trouver un squelette du nom demande
64
+    // ne rien dire si on ne trouve pas,
65
+    // c'est l'appelant qui sait comment gerer la situation
66
+    // ou les plugins qui feront mieux dans le pipeline
67
+    $squelette = trouver_fond($fond, '', true);
68
+    $ext = $squelette['extension'];
69
+
70
+    $flux = [
71
+        'args' => [
72
+            'id_rubrique' => $id_rubrique,
73
+            'ext' => $ext,
74
+            'fond' => $fond,
75
+            'lang' => $lang,
76
+            'contexte' => $contexte, // le style d'un objet peut dependre de lui meme
77
+            'connect' => $connect
78
+        ],
79
+        'data' => $squelette['fond'],
80
+    ];
81
+
82
+    if (test_espace_prive() or defined('_ZPIP')) {
83
+        if (!$styliser_par_z) {
84
+            $styliser_par_z = charger_fonction('styliser_par_z', 'public');
85
+        }
86
+        $flux = $styliser_par_z($flux);
87
+    }
88
+
89
+    $flux = styliser_par_objets($flux);
90
+
91
+    // pipeline styliser
92
+    $squelette = pipeline('styliser', $flux);
93
+
94
+    return [$squelette, $ext, $ext, "$squelette.$ext"];
95 95
 }
96 96
 
97 97
 /**
@@ -110,32 +110,32 @@  discard block
 block discarded – undo
110 110
  *     Données du pipeline styliser
111 111
  **/
112 112
 function styliser_par_objets($flux) {
113
-	if (
114
-		test_espace_prive()
115
-		and !$squelette = $flux['data']
116
-		and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0
117
-		and $echafauder = charger_fonction('echafauder', 'prive', true)
118
-	) {
119
-		if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) {
120
-			$table = table_objet(substr($flux['args']['fond'], 19));
121
-			$table_sql = table_objet_sql($table);
122
-			$objets = lister_tables_objets_sql();
123
-			if (isset($objets[$table_sql])) {
124
-				$flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']);
125
-			}
126
-		}
127
-		if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) {
128
-			$type = substr($flux['args']['fond'], 21);
129
-			$table = table_objet($type);
130
-			$table_sql = table_objet_sql($table);
131
-			$objets = lister_tables_objets_sql();
132
-			if (isset($objets[$table_sql])) {
133
-				$flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']);
134
-			}
135
-		}
136
-	}
137
-
138
-	return $flux;
113
+    if (
114
+        test_espace_prive()
115
+        and !$squelette = $flux['data']
116
+        and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0
117
+        and $echafauder = charger_fonction('echafauder', 'prive', true)
118
+    ) {
119
+        if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) {
120
+            $table = table_objet(substr($flux['args']['fond'], 19));
121
+            $table_sql = table_objet_sql($table);
122
+            $objets = lister_tables_objets_sql();
123
+            if (isset($objets[$table_sql])) {
124
+                $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']);
125
+            }
126
+        }
127
+        if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) {
128
+            $type = substr($flux['args']['fond'], 21);
129
+            $table = table_objet($type);
130
+            $table_sql = table_objet_sql($table);
131
+            $objets = lister_tables_objets_sql();
132
+            if (isset($objets[$table_sql])) {
133
+                $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']);
134
+            }
135
+        }
136
+    }
137
+
138
+    return $flux;
139 139
 }
140 140
 
141 141
 /**
@@ -151,50 +151,50 @@  discard block
 block discarded – undo
151 151
  * @return array
152 152
  */
153 153
 function quete_rubrique_fond($contexte) {
154
-	static $liste_objets = null;
155
-	static $quete = [];
156
-	if (is_null($liste_objets)) {
157
-		$liste_objets = [];
158
-		include_spip('inc/urls');
159
-		include_spip('public/quete');
160
-		$l = urls_liste_objets(false);
161
-		// placer la rubrique en tete des objets
162
-		$l = array_diff($l, ['rubrique']);
163
-		array_unshift($l, 'rubrique');
164
-		foreach ($l as $objet) {
165
-			$id = id_table_objet($objet);
166
-			if (!isset($liste_objets[$id])) {
167
-				$liste_objets[$id] = objet_type($objet, false);
168
-			}
169
-		}
170
-	}
171
-	$c = array_intersect_key($contexte, $liste_objets);
172
-	if (!count($c)) {
173
-		return false;
174
-	}
175
-
176
-	$c = array_map('intval', $c);
177
-	$s = serialize($c);
178
-	if (isset($quete[$s])) {
179
-		return $quete[$s];
180
-	}
181
-
182
-	if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) {
183
-		unset($c['id_rubrique']);
184
-		$c = ['id_rubrique' => $r] + $c;
185
-	}
186
-
187
-	foreach ($c as $_id => $id) {
188
-		if (
189
-			$id
190
-			and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id)
191
-		) {
192
-			$lang = $row['lang'] ?? '';
193
-			if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) {
194
-				return $quete[$s] = [$id, $lang];
195
-			}
196
-		}
197
-	}
198
-
199
-	return $quete[$s] = false;
154
+    static $liste_objets = null;
155
+    static $quete = [];
156
+    if (is_null($liste_objets)) {
157
+        $liste_objets = [];
158
+        include_spip('inc/urls');
159
+        include_spip('public/quete');
160
+        $l = urls_liste_objets(false);
161
+        // placer la rubrique en tete des objets
162
+        $l = array_diff($l, ['rubrique']);
163
+        array_unshift($l, 'rubrique');
164
+        foreach ($l as $objet) {
165
+            $id = id_table_objet($objet);
166
+            if (!isset($liste_objets[$id])) {
167
+                $liste_objets[$id] = objet_type($objet, false);
168
+            }
169
+        }
170
+    }
171
+    $c = array_intersect_key($contexte, $liste_objets);
172
+    if (!count($c)) {
173
+        return false;
174
+    }
175
+
176
+    $c = array_map('intval', $c);
177
+    $s = serialize($c);
178
+    if (isset($quete[$s])) {
179
+        return $quete[$s];
180
+    }
181
+
182
+    if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) {
183
+        unset($c['id_rubrique']);
184
+        $c = ['id_rubrique' => $r] + $c;
185
+    }
186
+
187
+    foreach ($c as $_id => $id) {
188
+        if (
189
+            $id
190
+            and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id)
191
+        ) {
192
+            $lang = $row['lang'] ?? '';
193
+            if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) {
194
+                return $quete[$s] = [$id, $lang];
195
+            }
196
+        }
197
+    }
198
+
199
+    return $quete[$s] = false;
200 200
 }
Please login to merge, or discard this patch.
ecrire/public/iterateur.php 3 patches
Spacing   +13 added lines, -14 removed lines patch added patch discarded remove patch
@@ -53,8 +53,7 @@  discard block
 block discarded – undo
53 53
 				// (pas glop)
54 54
 				try {
55 55
 					switch (is_countable($a) ? count($a) : 0) {
56
-						case 0:
57
-							$iter = new $iterateur();
56
+						case 0 : $iter = new $iterateur();
58 57
 							break;
59 58
 						case 1:
60 59
 							$iter = new $iterateur($a[0]);
@@ -79,10 +78,10 @@  discard block
 block discarded – undo
79 78
 			// chercher la classe d'iterateur
80 79
 			// IterateurXXX
81 80
 			// definie dans le fichier iterateurs/xxx.php
82
-			$class = 'Iterateur' . $iterateur;
81
+			$class = 'Iterateur'.$iterateur;
83 82
 			if (!class_exists($class)) {
84 83
 				if (
85
-					!include_spip('iterateur/' . strtolower($iterateur))
84
+					!include_spip('iterateur/'.strtolower($iterateur))
86 85
 					or !class_exists($class)
87 86
 				) {
88 87
 					die("Iterateur $iterateur non trouvé");
@@ -210,7 +209,7 @@  discard block
 block discarded – undo
210 209
 				return $this->iter->$nom();
211 210
 			} catch (Exception $e) {
212 211
 				// #GETCHILDREN sur un fichier de DirectoryIterator ...
213
-				spip_log("Methode $nom en echec sur " . get_class($this->iter));
212
+				spip_log("Methode $nom en echec sur ".get_class($this->iter));
214 213
 				spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode");
215 214
 
216 215
 				return '';
@@ -259,7 +258,7 @@  discard block
 block discarded – undo
259 258
 		// Creer la fonction de filtrage sur $this
260 259
 		if ($this->filtre) {
261 260
 			if ($filtres = $this->assembler_filtres($this->filtre)) {
262
-				$filtres = 'return ' . $filtres . ';';
261
+				$filtres = 'return '.$filtres.';';
263 262
 				$this->func_filtre = fn() => eval($filtres);
264 263
 			}
265 264
 			else {
@@ -294,7 +293,7 @@  discard block
 block discarded – undo
294 293
 			return null;
295 294
 		}
296 295
 
297
-		return '(' . implode(") $operateur (", $filtres_string) . ')';
296
+		return '('.implode(") $operateur (", $filtres_string).')';
298 297
 	}
299 298
 
300 299
 	/**
@@ -375,7 +374,7 @@  discard block
 block discarded – undo
375 374
 			return $this->composer_filtre($v[1], $v[0], $v[2]);
376 375
 		}
377 376
 
378
-		return null;  // sera ignore
377
+		return null; // sera ignore
379 378
 	}
380 379
 
381 380
 	/**
@@ -401,28 +400,28 @@  discard block
 block discarded – undo
401 400
 		# if (!in_array($cle, array('cle', 'valeur')))
402 401
 		#	return;
403 402
 
404
-		$a = '$this->get_select(\'' . $cle . '\')';
403
+		$a = '$this->get_select(\''.$cle.'\')';
405 404
 
406 405
 		$filtre = '';
407 406
 
408 407
 		if ($op == 'REGEXP') {
409
-			$filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')';
408
+			$filtre = 'filtrer("match", '.$a.', '.str_replace('\"', '"', $valeur).')';
410 409
 			$op = '';
411 410
 		} else {
412 411
 			if ($op == 'LIKE') {
413 412
 				$valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur));
414
-				$filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')';
413
+				$filtre = 'filtrer("match", '.$a.', '.$valeur.')';
415 414
 				$op = '';
416 415
 			} else {
417 416
 				if ($op == '=') {
418 417
 					$op = '==';
419 418
 				} else {
420 419
 					if ($op == 'IN') {
421
-						$filtre = 'in_array(' . $a . ', array' . $valeur . ')';
420
+						$filtre = 'in_array('.$a.', array'.$valeur.')';
422 421
 						$op = '';
423 422
 					} else {
424 423
 						if (!in_array($op, ['<', '<=', '>', '>='])) {
425
-							spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette
424
+							spip_log('operateur non reconnu '.$op); // [todo] mettre une erreur de squelette
426 425
 							$op = '';
427 426
 						}
428 427
 					}
@@ -431,7 +430,7 @@  discard block
 block discarded – undo
431 430
 		}
432 431
 
433 432
 		if ($op) {
434
-			$filtre = $a . $op . str_replace('\"', '"', $valeur);
433
+			$filtre = $a.$op.str_replace('\"', '"', $valeur);
435 434
 		}
436 435
 
437 436
 		if ($not) {
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -261,8 +261,7 @@  discard block
 block discarded – undo
261 261
 			if ($filtres = $this->assembler_filtres($this->filtre)) {
262 262
 				$filtres = 'return ' . $filtres . ';';
263 263
 				$this->func_filtre = fn() => eval($filtres);
264
-			}
265
-			else {
264
+			} else {
266 265
 				$this->func_filtre = null;
267 266
 			}
268 267
 		}
@@ -345,16 +344,14 @@  discard block
 block discarded – undo
345 344
 					$v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]);
346 345
 					if ($v[$k] === null) {
347 346
 						unset($v[$k]);
348
-					}
349
-					elseif ($v[$k] === 'true') {
347
+					} elseif ($v[$k] === 'true') {
350 348
 						if ($op === 'OR') {
351 349
 							return 'true';
352 350
 						}
353 351
 						if ($op === 'AND') {
354 352
 							unset($v[$k]);
355 353
 						}
356
-					}
357
-					elseif ($v[$k] === 'false') {
354
+					} elseif ($v[$k] === 'false') {
358 355
 						if ($op === 'OR') {
359 356
 							unset($v[$k]);
360 357
 						}
Please login to merge, or discard this patch.
Indentation   +654 added lines, -654 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 /**
@@ -21,667 +21,667 @@  discard block
 block discarded – undo
21 21
  *
22 22
  */
23 23
 class IterFactory {
24
-	public static function create($iterateur, $command, $info = null) {
25
-
26
-		$iter = null;
27
-		// cas des SI {si expression} analises tres tot
28
-		// pour eviter le chargement de tout iterateur
29
-		if (isset($command['si'])) {
30
-			foreach ($command['si'] as $si) {
31
-				if (!$si) {
32
-					// $command pour boucle SQL peut generer des erreurs de compilation
33
-					// s'il est transmis alors qu'on est dans un iterateur vide
34
-					return new IterDecorator(new EmptyIterator(), [], $info);
35
-				}
36
-			}
37
-		}
38
-
39
-		// chercher un iterateur PHP existant (par exemple dans SPL)
40
-		// (il faudrait passer l'argument ->sql_serveur
41
-		// pour etre certain qu'on est sur un "php:")
42
-		if (class_exists($iterateur)) {
43
-			$a = $command['args'] ?? [];
44
-
45
-			// permettre de passer un Iterateur directement {args #ITERATEUR} :
46
-			// si on recoit deja un iterateur en argument, on l'utilise
47
-			if ((is_countable($a) ? count($a) : 0) == 1 and is_object($a[0]) and is_subclass_of($a[0], \Iterator::class)) {
48
-				$iter = $a[0];
49
-
50
-				// sinon, on cree un iterateur du type donne
51
-			} else {
52
-				// arguments de creation de l'iterateur...
53
-				// (pas glop)
54
-				try {
55
-					switch (is_countable($a) ? count($a) : 0) {
56
-						case 0:
57
-							$iter = new $iterateur();
58
-							break;
59
-						case 1:
60
-							$iter = new $iterateur($a[0]);
61
-							break;
62
-						case 2:
63
-							$iter = new $iterateur($a[0], $a[1]);
64
-							break;
65
-						case 3:
66
-							$iter = new $iterateur($a[0], $a[1], $a[2]);
67
-							break;
68
-						case 4:
69
-							$iter = new $iterateur($a[0], $a[1], $a[2], $a[3]);
70
-							break;
71
-					}
72
-				} catch (Exception $e) {
73
-					spip_log("Erreur de chargement de l'iterateur $iterateur");
74
-					spip_log($e->getMessage());
75
-					$iter = new EmptyIterator();
76
-				}
77
-			}
78
-		} else {
79
-			// chercher la classe d'iterateur
80
-			// IterateurXXX
81
-			// definie dans le fichier iterateurs/xxx.php
82
-			$class = 'Iterateur' . $iterateur;
83
-			if (!class_exists($class)) {
84
-				if (
85
-					!include_spip('iterateur/' . strtolower($iterateur))
86
-					or !class_exists($class)
87
-				) {
88
-					die("Iterateur $iterateur non trouv&#233;");
89
-					// si l'iterateur n'existe pas, on se rabat sur le generique
90
-					# $iter = new EmptyIterator();
91
-				}
92
-			}
93
-			$iter = new $class($command, $info);
94
-		}
95
-
96
-		return new IterDecorator($iter, $command, $info);
97
-	}
24
+    public static function create($iterateur, $command, $info = null) {
25
+
26
+        $iter = null;
27
+        // cas des SI {si expression} analises tres tot
28
+        // pour eviter le chargement de tout iterateur
29
+        if (isset($command['si'])) {
30
+            foreach ($command['si'] as $si) {
31
+                if (!$si) {
32
+                    // $command pour boucle SQL peut generer des erreurs de compilation
33
+                    // s'il est transmis alors qu'on est dans un iterateur vide
34
+                    return new IterDecorator(new EmptyIterator(), [], $info);
35
+                }
36
+            }
37
+        }
38
+
39
+        // chercher un iterateur PHP existant (par exemple dans SPL)
40
+        // (il faudrait passer l'argument ->sql_serveur
41
+        // pour etre certain qu'on est sur un "php:")
42
+        if (class_exists($iterateur)) {
43
+            $a = $command['args'] ?? [];
44
+
45
+            // permettre de passer un Iterateur directement {args #ITERATEUR} :
46
+            // si on recoit deja un iterateur en argument, on l'utilise
47
+            if ((is_countable($a) ? count($a) : 0) == 1 and is_object($a[0]) and is_subclass_of($a[0], \Iterator::class)) {
48
+                $iter = $a[0];
49
+
50
+                // sinon, on cree un iterateur du type donne
51
+            } else {
52
+                // arguments de creation de l'iterateur...
53
+                // (pas glop)
54
+                try {
55
+                    switch (is_countable($a) ? count($a) : 0) {
56
+                        case 0:
57
+                            $iter = new $iterateur();
58
+                            break;
59
+                        case 1:
60
+                            $iter = new $iterateur($a[0]);
61
+                            break;
62
+                        case 2:
63
+                            $iter = new $iterateur($a[0], $a[1]);
64
+                            break;
65
+                        case 3:
66
+                            $iter = new $iterateur($a[0], $a[1], $a[2]);
67
+                            break;
68
+                        case 4:
69
+                            $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]);
70
+                            break;
71
+                    }
72
+                } catch (Exception $e) {
73
+                    spip_log("Erreur de chargement de l'iterateur $iterateur");
74
+                    spip_log($e->getMessage());
75
+                    $iter = new EmptyIterator();
76
+                }
77
+            }
78
+        } else {
79
+            // chercher la classe d'iterateur
80
+            // IterateurXXX
81
+            // definie dans le fichier iterateurs/xxx.php
82
+            $class = 'Iterateur' . $iterateur;
83
+            if (!class_exists($class)) {
84
+                if (
85
+                    !include_spip('iterateur/' . strtolower($iterateur))
86
+                    or !class_exists($class)
87
+                ) {
88
+                    die("Iterateur $iterateur non trouv&#233;");
89
+                    // si l'iterateur n'existe pas, on se rabat sur le generique
90
+                    # $iter = new EmptyIterator();
91
+                }
92
+            }
93
+            $iter = new $class($command, $info);
94
+        }
95
+
96
+        return new IterDecorator($iter, $command, $info);
97
+    }
98 98
 }
99 99
 
100 100
 
101 101
 class IterDecorator extends FilterIterator {
102
-	private $iter;
103
-
104
-	/**
105
-	 * Conditions de filtrage
106
-	 * ie criteres de selection
107
-	 *
108
-	 * @var array
109
-	 */
110
-	protected $filtre = [];
111
-
112
-	/**
113
-	 * Fonction de filtrage compilee a partir des criteres de filtre
114
-	 *
115
-	 * @var string
116
-	 */
117
-	protected $func_filtre = null;
118
-
119
-	/**
120
-	 * Critere {offset, limit}
121
-	 *
122
-	 * @var int
123
-	 * @var int
124
-	 */
125
-	protected $offset = null;
126
-	protected $limit = null;
127
-
128
-	/**
129
-	 * nombre d'elements recuperes depuis la position 0,
130
-	 * en tenant compte des filtres
131
-	 *
132
-	 * @var int
133
-	 */
134
-	protected $fetched = 0;
135
-
136
-	/**
137
-	 * Y a t'il une erreur ?
138
-	 *
139
-	 * @var bool
140
-	 **/
141
-	protected $err = false;
142
-
143
-	/**
144
-	 * Drapeau a activer en cas d'echec
145
-	 * (select SQL errone, non chargement des DATA, etc)
146
-	 */
147
-	public function err() {
148
-		if (method_exists($this->iter, 'err')) {
149
-			return $this->iter->err();
150
-		}
151
-		if (property_exists($this->iter, 'err')) {
152
-			return $this->iter->err;
153
-		}
154
-
155
-		return false;
156
-	}
157
-
158
-	public function __construct(Iterator $iter, $command, $info) {
159
-		parent::__construct($iter);
160
-		parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator)
161
-
162
-		// recuperer l'iterateur transmis
163
-		$this->iter = $this->getInnerIterator();
164
-		$this->command = $command;
165
-		$this->info = $info;
166
-		$this->pos = 0;
167
-		$this->fetched = 0;
168
-
169
-		// chercher la liste des champs a retourner par
170
-		// fetch si l'objet ne les calcule pas tout seul
171
-		if (!method_exists($this->iter, 'fetch')) {
172
-			$this->calculer_select();
173
-			$this->calculer_filtres();
174
-		}
175
-
176
-		// emptyIterator critere {si} faux n'a pas d'erreur !
177
-		if (isset($this->iter->err)) {
178
-			$this->err = $this->iter->err;
179
-		}
180
-
181
-		// pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite)
182
-		//$this->total = $this->count();
183
-	}
184
-
185
-
186
-	// calcule les elements a retournes par fetch()
187
-	// enleve les elements inutiles du select()
188
-	//
189
-	private function calculer_select() {
190
-		if ($select = &$this->command['select']) {
191
-			foreach ($select as $s) {
192
-				// /!\ $s = '.nom'
193
-				if ($s[0] == '.') {
194
-					$s = substr($s, 1);
195
-				}
196
-				$this->select[] = $s;
197
-			}
198
-		}
199
-	}
200
-
201
-	// recuperer la valeur d'une balise #X
202
-	// en fonction des methodes
203
-	// et proprietes disponibles
204
-	public function get_select($nom) {
205
-		if (
206
-			is_object($this->iter)
207
-			and method_exists($this->iter, $nom)
208
-		) {
209
-			try {
210
-				return $this->iter->$nom();
211
-			} catch (Exception $e) {
212
-				// #GETCHILDREN sur un fichier de DirectoryIterator ...
213
-				spip_log("Methode $nom en echec sur " . get_class($this->iter));
214
-				spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode");
215
-
216
-				return '';
217
-			}
218
-		}
219
-		/*
102
+    private $iter;
103
+
104
+    /**
105
+     * Conditions de filtrage
106
+     * ie criteres de selection
107
+     *
108
+     * @var array
109
+     */
110
+    protected $filtre = [];
111
+
112
+    /**
113
+     * Fonction de filtrage compilee a partir des criteres de filtre
114
+     *
115
+     * @var string
116
+     */
117
+    protected $func_filtre = null;
118
+
119
+    /**
120
+     * Critere {offset, limit}
121
+     *
122
+     * @var int
123
+     * @var int
124
+     */
125
+    protected $offset = null;
126
+    protected $limit = null;
127
+
128
+    /**
129
+     * nombre d'elements recuperes depuis la position 0,
130
+     * en tenant compte des filtres
131
+     *
132
+     * @var int
133
+     */
134
+    protected $fetched = 0;
135
+
136
+    /**
137
+     * Y a t'il une erreur ?
138
+     *
139
+     * @var bool
140
+     **/
141
+    protected $err = false;
142
+
143
+    /**
144
+     * Drapeau a activer en cas d'echec
145
+     * (select SQL errone, non chargement des DATA, etc)
146
+     */
147
+    public function err() {
148
+        if (method_exists($this->iter, 'err')) {
149
+            return $this->iter->err();
150
+        }
151
+        if (property_exists($this->iter, 'err')) {
152
+            return $this->iter->err;
153
+        }
154
+
155
+        return false;
156
+    }
157
+
158
+    public function __construct(Iterator $iter, $command, $info) {
159
+        parent::__construct($iter);
160
+        parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator)
161
+
162
+        // recuperer l'iterateur transmis
163
+        $this->iter = $this->getInnerIterator();
164
+        $this->command = $command;
165
+        $this->info = $info;
166
+        $this->pos = 0;
167
+        $this->fetched = 0;
168
+
169
+        // chercher la liste des champs a retourner par
170
+        // fetch si l'objet ne les calcule pas tout seul
171
+        if (!method_exists($this->iter, 'fetch')) {
172
+            $this->calculer_select();
173
+            $this->calculer_filtres();
174
+        }
175
+
176
+        // emptyIterator critere {si} faux n'a pas d'erreur !
177
+        if (isset($this->iter->err)) {
178
+            $this->err = $this->iter->err;
179
+        }
180
+
181
+        // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite)
182
+        //$this->total = $this->count();
183
+    }
184
+
185
+
186
+    // calcule les elements a retournes par fetch()
187
+    // enleve les elements inutiles du select()
188
+    //
189
+    private function calculer_select() {
190
+        if ($select = &$this->command['select']) {
191
+            foreach ($select as $s) {
192
+                // /!\ $s = '.nom'
193
+                if ($s[0] == '.') {
194
+                    $s = substr($s, 1);
195
+                }
196
+                $this->select[] = $s;
197
+            }
198
+        }
199
+    }
200
+
201
+    // recuperer la valeur d'une balise #X
202
+    // en fonction des methodes
203
+    // et proprietes disponibles
204
+    public function get_select($nom) {
205
+        if (
206
+            is_object($this->iter)
207
+            and method_exists($this->iter, $nom)
208
+        ) {
209
+            try {
210
+                return $this->iter->$nom();
211
+            } catch (Exception $e) {
212
+                // #GETCHILDREN sur un fichier de DirectoryIterator ...
213
+                spip_log("Methode $nom en echec sur " . get_class($this->iter));
214
+                spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode");
215
+
216
+                return '';
217
+            }
218
+        }
219
+        /*
220 220
 		if (property_exists($this->iter, $nom)) {
221 221
 			return $this->iter->$nom;
222 222
 		}*/
223
-		// cle et valeur par defaut
224
-		// ICI PLANTAGE SI ON NE CONTROLE PAS $nom
225
-		if (
226
-			in_array($nom, ['cle', 'valeur'])
227
-			and method_exists($this, $nom)
228
-		) {
229
-			return $this->$nom();
230
-		}
231
-
232
-		// Par defaut chercher en xpath dans la valeur()
233
-		return table_valeur($this->valeur(), $nom, null);
234
-	}
235
-
236
-
237
-	private function calculer_filtres() {
238
-
239
-		// Issu de calculer_select() de public/composer L.519
240
-		// TODO: externaliser...
241
-		//
242
-		// retirer les criteres vides:
243
-		// {X ?} avec X absent de l'URL
244
-		// {par #ENV{X}} avec X absent de l'URL
245
-		// IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil)
246
-		if ($where = &$this->command['where']) {
247
-			foreach ($where as $k => $v) {
248
-				$this->filtre[] = $this->traduire_condition_sql_en_filtre($v);
249
-			}
250
-		}
251
-
252
-		// critere {2,7}
253
-		if (isset($this->command['limit']) and $this->command['limit']) {
254
-			$limit = explode(',', $this->command['limit']);
255
-			$this->offset = $limit[0];
256
-			$this->limit = $limit[1];
257
-		}
258
-
259
-		// Creer la fonction de filtrage sur $this
260
-		if ($this->filtre) {
261
-			if ($filtres = $this->assembler_filtres($this->filtre)) {
262
-				$filtres = 'return ' . $filtres . ';';
263
-				$this->func_filtre = fn() => eval($filtres);
264
-			}
265
-			else {
266
-				$this->func_filtre = null;
267
-			}
268
-		}
269
-	}
270
-
271
-	/**
272
-	 * Assembler le tableau de filtres traduits depuis les conditions SQL
273
-	 * les filtres vides ou null sont ignores
274
-	 * @param $filtres
275
-	 * @param string $operateur
276
-	 * @return string|null
277
-	 */
278
-	protected function assembler_filtres($filtres, $operateur = 'AND') {
279
-
280
-		$filtres_string = [];
281
-		foreach ($filtres as $k => $v) {
282
-			// si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine
283
-			if (is_array($v) and in_array(reset($v), ['OR', 'AND'])) {
284
-				$op = array_shift($v);
285
-				$v = $this->assembler_filtres($v, $op);
286
-			}
287
-			if (is_null($v) or !is_string($v) or empty($v)) {
288
-				continue;
289
-			}
290
-			$filtres_string[] = $v;
291
-		}
292
-
293
-		if (!count($filtres_string)) {
294
-			return null;
295
-		}
296
-
297
-		return '(' . implode(") $operateur (", $filtres_string) . ')';
298
-	}
299
-
300
-	/**
301
-	 * Traduire un element du tableau where SQL en un filtre
302
-	 * @param $v
303
-	 * @return string|array|null
304
-	 */
305
-	protected function traduire_condition_sql_en_filtre($v) {
306
-		if (is_array($v)) {
307
-			if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) {
308
-				return 'true';
309
-			} elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) {
310
-				return 'true';
311
-			} else {
312
-				$op = $v[0] ?: $v;
313
-			}
314
-		} else {
315
-			$op = $v;
316
-		}
317
-		if ((!$op) or ($op == 1) or ($op == '0=0')) {
318
-			return 'true';
319
-		}
320
-		if ($op === '0=1') {
321
-			return 'false';
322
-		}
323
-		// traiter {cle IN a,b} ou {valeur !IN a,b}
324
-		if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) {
325
-			return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]);
326
-		}
327
-
328
-		// 3 possibilites : count($v) =
329
-		// * 1 : {x y} ; on recoit $v[0] = y
330
-		// * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y}
331
-		// * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y
332
-
333
-		// 1 : forcement traite par un critere, on passe
334
-		if (!$v or !is_array($v) or count($v) == 1) {
335
-			return null; // sera ignore
336
-		}
337
-		if (count($v) == 2 and is_array($v[1])) {
338
-			return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT');
339
-		}
340
-		if (count($v) == 3) {
341
-			// traiter le OR/AND suivi de 2 valeurs
342
-			if (in_array($op, ['OR', 'AND'])) {
343
-				array_shift($v);
344
-				foreach (array_keys($v) as $k) {
345
-					$v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]);
346
-					if ($v[$k] === null) {
347
-						unset($v[$k]);
348
-					}
349
-					elseif ($v[$k] === 'true') {
350
-						if ($op === 'OR') {
351
-							return 'true';
352
-						}
353
-						if ($op === 'AND') {
354
-							unset($v[$k]);
355
-						}
356
-					}
357
-					elseif ($v[$k] === 'false') {
358
-						if ($op === 'OR') {
359
-							unset($v[$k]);
360
-						}
361
-						if ($op === 'AND') {
362
-							return 'false';
363
-						}
364
-					}
365
-				}
366
-				if (!count($v)) {
367
-					return null;
368
-				}
369
-				if (count($v) === 1) {
370
-					return reset($v);
371
-				}
372
-				array_unshift($v, $op);
373
-				return $v;
374
-			}
375
-			return $this->composer_filtre($v[1], $v[0], $v[2]);
376
-		}
377
-
378
-		return null;  // sera ignore
379
-	}
380
-
381
-	/**
382
-	 * Calculer un filtre sur un champ du tableau
383
-	 * @param $cle
384
-	 * @param $op
385
-	 * @param $valeur
386
-	 * @param false $not
387
-	 * @return string|null
388
-	 */
389
-	protected function composer_filtre($cle, $op, $valeur, $not = false) {
390
-		if (method_exists($this->iter, 'exception_des_criteres')) {
391
-			if (in_array($cle, $this->iter->exception_des_criteres())) {
392
-				return null;
393
-			}
394
-		}
395
-		// TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ?
396
-		# mais c'est normalement deja opere par calculer_critere_infixe()
397
-		# qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1}
398
-		# ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present.
399
-		# il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir...
400
-
401
-		# if (!in_array($cle, array('cle', 'valeur')))
402
-		#	return;
403
-
404
-		$a = '$this->get_select(\'' . $cle . '\')';
405
-
406
-		$filtre = '';
407
-
408
-		if ($op == 'REGEXP') {
409
-			$filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')';
410
-			$op = '';
411
-		} else {
412
-			if ($op == 'LIKE') {
413
-				$valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur));
414
-				$filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')';
415
-				$op = '';
416
-			} else {
417
-				if ($op == '=') {
418
-					$op = '==';
419
-				} else {
420
-					if ($op == 'IN') {
421
-						$filtre = 'in_array(' . $a . ', array' . $valeur . ')';
422
-						$op = '';
423
-					} else {
424
-						if (!in_array($op, ['<', '<=', '>', '>='])) {
425
-							spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette
426
-							$op = '';
427
-						}
428
-					}
429
-				}
430
-			}
431
-		}
432
-
433
-		if ($op) {
434
-			$filtre = $a . $op . str_replace('\"', '"', $valeur);
435
-		}
436
-
437
-		if ($not) {
438
-			$filtre = "!($filtre)";
439
-		}
440
-
441
-		return $filtre;
442
-	}
443
-
444
-
445
-	public function next(): void {
446
-		$this->pos++;
447
-		parent::next();
448
-	}
449
-
450
-	/**
451
-	 * revient au depart
452
-	 *
453
-	 * @return void
454
-	 */
455
-	public function rewind(): void {
456
-		$this->pos = 0;
457
-		$this->fetched = 0;
458
-		parent::rewind();
459
-	}
460
-
461
-
462
-	# Extension SPIP des iterateurs PHP
463
-	/**
464
-	 * type de l'iterateur
465
-	 *
466
-	 * @var string
467
-	 */
468
-	protected $type;
469
-
470
-	/**
471
-	 * parametres de l'iterateur
472
-	 *
473
-	 * @var array
474
-	 */
475
-	protected $command;
476
-
477
-	/**
478
-	 * infos de compilateur
479
-	 *
480
-	 * @var array
481
-	 */
482
-	protected $info;
483
-
484
-	/**
485
-	 * position courante de l'iterateur
486
-	 *
487
-	 * @var int
488
-	 */
489
-	protected $pos = null;
490
-
491
-	/**
492
-	 * nombre total resultats dans l'iterateur
493
-	 *
494
-	 * @var int
495
-	 */
496
-	protected $total = null;
497
-
498
-	/**
499
-	 * nombre maximal de recherche pour $total
500
-	 * si l'iterateur n'implemente pas de fonction specifique
501
-	 */
502
-	protected $max = 100000;
503
-
504
-
505
-	/**
506
-	 * Liste des champs a inserer dans les $row
507
-	 * retournes par ->fetch()
508
-	 */
509
-	protected $select = [];
510
-
511
-
512
-	/**
513
-	 * aller a la position absolue n,
514
-	 * comptee depuis le debut
515
-	 *
516
-	 * @param int $n
517
-	 *   absolute pos
518
-	 * @param string $continue
519
-	 *   param for sql_ api
520
-	 * @return bool
521
-	 *   success or fail if not implemented
522
-	 */
523
-	public function seek($n = 0, $continue = null) {
524
-		if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) {
525
-			$this->seek_loop($n);
526
-		}
527
-		$this->pos = $n;
528
-		$this->fetched = $n;
529
-
530
-		return true;
531
-	}
532
-
533
-	/*
223
+        // cle et valeur par defaut
224
+        // ICI PLANTAGE SI ON NE CONTROLE PAS $nom
225
+        if (
226
+            in_array($nom, ['cle', 'valeur'])
227
+            and method_exists($this, $nom)
228
+        ) {
229
+            return $this->$nom();
230
+        }
231
+
232
+        // Par defaut chercher en xpath dans la valeur()
233
+        return table_valeur($this->valeur(), $nom, null);
234
+    }
235
+
236
+
237
+    private function calculer_filtres() {
238
+
239
+        // Issu de calculer_select() de public/composer L.519
240
+        // TODO: externaliser...
241
+        //
242
+        // retirer les criteres vides:
243
+        // {X ?} avec X absent de l'URL
244
+        // {par #ENV{X}} avec X absent de l'URL
245
+        // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil)
246
+        if ($where = &$this->command['where']) {
247
+            foreach ($where as $k => $v) {
248
+                $this->filtre[] = $this->traduire_condition_sql_en_filtre($v);
249
+            }
250
+        }
251
+
252
+        // critere {2,7}
253
+        if (isset($this->command['limit']) and $this->command['limit']) {
254
+            $limit = explode(',', $this->command['limit']);
255
+            $this->offset = $limit[0];
256
+            $this->limit = $limit[1];
257
+        }
258
+
259
+        // Creer la fonction de filtrage sur $this
260
+        if ($this->filtre) {
261
+            if ($filtres = $this->assembler_filtres($this->filtre)) {
262
+                $filtres = 'return ' . $filtres . ';';
263
+                $this->func_filtre = fn() => eval($filtres);
264
+            }
265
+            else {
266
+                $this->func_filtre = null;
267
+            }
268
+        }
269
+    }
270
+
271
+    /**
272
+     * Assembler le tableau de filtres traduits depuis les conditions SQL
273
+     * les filtres vides ou null sont ignores
274
+     * @param $filtres
275
+     * @param string $operateur
276
+     * @return string|null
277
+     */
278
+    protected function assembler_filtres($filtres, $operateur = 'AND') {
279
+
280
+        $filtres_string = [];
281
+        foreach ($filtres as $k => $v) {
282
+            // si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine
283
+            if (is_array($v) and in_array(reset($v), ['OR', 'AND'])) {
284
+                $op = array_shift($v);
285
+                $v = $this->assembler_filtres($v, $op);
286
+            }
287
+            if (is_null($v) or !is_string($v) or empty($v)) {
288
+                continue;
289
+            }
290
+            $filtres_string[] = $v;
291
+        }
292
+
293
+        if (!count($filtres_string)) {
294
+            return null;
295
+        }
296
+
297
+        return '(' . implode(") $operateur (", $filtres_string) . ')';
298
+    }
299
+
300
+    /**
301
+     * Traduire un element du tableau where SQL en un filtre
302
+     * @param $v
303
+     * @return string|array|null
304
+     */
305
+    protected function traduire_condition_sql_en_filtre($v) {
306
+        if (is_array($v)) {
307
+            if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) {
308
+                return 'true';
309
+            } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) {
310
+                return 'true';
311
+            } else {
312
+                $op = $v[0] ?: $v;
313
+            }
314
+        } else {
315
+            $op = $v;
316
+        }
317
+        if ((!$op) or ($op == 1) or ($op == '0=0')) {
318
+            return 'true';
319
+        }
320
+        if ($op === '0=1') {
321
+            return 'false';
322
+        }
323
+        // traiter {cle IN a,b} ou {valeur !IN a,b}
324
+        if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) {
325
+            return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]);
326
+        }
327
+
328
+        // 3 possibilites : count($v) =
329
+        // * 1 : {x y} ; on recoit $v[0] = y
330
+        // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y}
331
+        // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y
332
+
333
+        // 1 : forcement traite par un critere, on passe
334
+        if (!$v or !is_array($v) or count($v) == 1) {
335
+            return null; // sera ignore
336
+        }
337
+        if (count($v) == 2 and is_array($v[1])) {
338
+            return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT');
339
+        }
340
+        if (count($v) == 3) {
341
+            // traiter le OR/AND suivi de 2 valeurs
342
+            if (in_array($op, ['OR', 'AND'])) {
343
+                array_shift($v);
344
+                foreach (array_keys($v) as $k) {
345
+                    $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]);
346
+                    if ($v[$k] === null) {
347
+                        unset($v[$k]);
348
+                    }
349
+                    elseif ($v[$k] === 'true') {
350
+                        if ($op === 'OR') {
351
+                            return 'true';
352
+                        }
353
+                        if ($op === 'AND') {
354
+                            unset($v[$k]);
355
+                        }
356
+                    }
357
+                    elseif ($v[$k] === 'false') {
358
+                        if ($op === 'OR') {
359
+                            unset($v[$k]);
360
+                        }
361
+                        if ($op === 'AND') {
362
+                            return 'false';
363
+                        }
364
+                    }
365
+                }
366
+                if (!count($v)) {
367
+                    return null;
368
+                }
369
+                if (count($v) === 1) {
370
+                    return reset($v);
371
+                }
372
+                array_unshift($v, $op);
373
+                return $v;
374
+            }
375
+            return $this->composer_filtre($v[1], $v[0], $v[2]);
376
+        }
377
+
378
+        return null;  // sera ignore
379
+    }
380
+
381
+    /**
382
+     * Calculer un filtre sur un champ du tableau
383
+     * @param $cle
384
+     * @param $op
385
+     * @param $valeur
386
+     * @param false $not
387
+     * @return string|null
388
+     */
389
+    protected function composer_filtre($cle, $op, $valeur, $not = false) {
390
+        if (method_exists($this->iter, 'exception_des_criteres')) {
391
+            if (in_array($cle, $this->iter->exception_des_criteres())) {
392
+                return null;
393
+            }
394
+        }
395
+        // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ?
396
+        # mais c'est normalement deja opere par calculer_critere_infixe()
397
+        # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1}
398
+        # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present.
399
+        # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir...
400
+
401
+        # if (!in_array($cle, array('cle', 'valeur')))
402
+        #	return;
403
+
404
+        $a = '$this->get_select(\'' . $cle . '\')';
405
+
406
+        $filtre = '';
407
+
408
+        if ($op == 'REGEXP') {
409
+            $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')';
410
+            $op = '';
411
+        } else {
412
+            if ($op == 'LIKE') {
413
+                $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur));
414
+                $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')';
415
+                $op = '';
416
+            } else {
417
+                if ($op == '=') {
418
+                    $op = '==';
419
+                } else {
420
+                    if ($op == 'IN') {
421
+                        $filtre = 'in_array(' . $a . ', array' . $valeur . ')';
422
+                        $op = '';
423
+                    } else {
424
+                        if (!in_array($op, ['<', '<=', '>', '>='])) {
425
+                            spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette
426
+                            $op = '';
427
+                        }
428
+                    }
429
+                }
430
+            }
431
+        }
432
+
433
+        if ($op) {
434
+            $filtre = $a . $op . str_replace('\"', '"', $valeur);
435
+        }
436
+
437
+        if ($not) {
438
+            $filtre = "!($filtre)";
439
+        }
440
+
441
+        return $filtre;
442
+    }
443
+
444
+
445
+    public function next(): void {
446
+        $this->pos++;
447
+        parent::next();
448
+    }
449
+
450
+    /**
451
+     * revient au depart
452
+     *
453
+     * @return void
454
+     */
455
+    public function rewind(): void {
456
+        $this->pos = 0;
457
+        $this->fetched = 0;
458
+        parent::rewind();
459
+    }
460
+
461
+
462
+    # Extension SPIP des iterateurs PHP
463
+    /**
464
+     * type de l'iterateur
465
+     *
466
+     * @var string
467
+     */
468
+    protected $type;
469
+
470
+    /**
471
+     * parametres de l'iterateur
472
+     *
473
+     * @var array
474
+     */
475
+    protected $command;
476
+
477
+    /**
478
+     * infos de compilateur
479
+     *
480
+     * @var array
481
+     */
482
+    protected $info;
483
+
484
+    /**
485
+     * position courante de l'iterateur
486
+     *
487
+     * @var int
488
+     */
489
+    protected $pos = null;
490
+
491
+    /**
492
+     * nombre total resultats dans l'iterateur
493
+     *
494
+     * @var int
495
+     */
496
+    protected $total = null;
497
+
498
+    /**
499
+     * nombre maximal de recherche pour $total
500
+     * si l'iterateur n'implemente pas de fonction specifique
501
+     */
502
+    protected $max = 100000;
503
+
504
+
505
+    /**
506
+     * Liste des champs a inserer dans les $row
507
+     * retournes par ->fetch()
508
+     */
509
+    protected $select = [];
510
+
511
+
512
+    /**
513
+     * aller a la position absolue n,
514
+     * comptee depuis le debut
515
+     *
516
+     * @param int $n
517
+     *   absolute pos
518
+     * @param string $continue
519
+     *   param for sql_ api
520
+     * @return bool
521
+     *   success or fail if not implemented
522
+     */
523
+    public function seek($n = 0, $continue = null) {
524
+        if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) {
525
+            $this->seek_loop($n);
526
+        }
527
+        $this->pos = $n;
528
+        $this->fetched = $n;
529
+
530
+        return true;
531
+    }
532
+
533
+    /*
534 534
 	 * aller a la position $n en parcourant
535 535
 	 * un par un tous les elements
536 536
 	 */
537
-	private function seek_loop($n) {
538
-		if ($this->pos > $n) {
539
-			$this->rewind();
540
-		}
541
-
542
-		while ($this->pos < $n and $this->valid()) {
543
-			$this->next();
544
-		}
545
-
546
-		return true;
547
-	}
548
-
549
-	/**
550
-	 * Avancer de $saut pas
551
-	 *
552
-	 * @param  $saut
553
-	 * @param  $max
554
-	 * @return int
555
-	 */
556
-	public function skip($saut, $max = null) {
557
-		// pas de saut en arriere autorise pour cette fonction
558
-		if (($saut = intval($saut)) <= 0) {
559
-			return $this->pos;
560
-		}
561
-		$seek = $this->pos + $saut;
562
-		// si le saut fait depasser le maxi, on libere la resource
563
-		// et on sort
564
-		if (is_null($max)) {
565
-			$max = $this->count();
566
-		}
567
-
568
-		if ($seek >= $max or $seek >= $this->count()) {
569
-			// sortie plus rapide que de faire next() jusqu'a la fin !
570
-			$this->free();
571
-
572
-			return $max;
573
-		}
574
-
575
-		$this->seek($seek);
576
-
577
-		return $this->pos;
578
-	}
579
-
580
-	/**
581
-	 * Renvoyer un tableau des donnees correspondantes
582
-	 * a la position courante de l'iterateur
583
-	 * en controlant si on respecte le filtre
584
-	 * Appliquer aussi le critere {offset,limit}
585
-	 *
586
-	 * @return array|bool
587
-	 */
588
-	public function fetch() {
589
-		if (method_exists($this->iter, 'fetch')) {
590
-			return $this->iter->fetch();
591
-		} else {
592
-			while (
593
-				$this->valid()
594
-				and (
595
-					!$this->accept()
596
-					or (isset($this->offset) and $this->fetched++ < $this->offset)
597
-				)
598
-			) {
599
-				$this->next();
600
-			}
601
-
602
-			if (!$this->valid()) {
603
-				return false;
604
-			}
605
-
606
-			if (
607
-				isset($this->limit)
608
-				and $this->fetched > $this->offset + $this->limit
609
-			) {
610
-				return false;
611
-			}
612
-
613
-			$r = [];
614
-			foreach ($this->select as $nom) {
615
-				$r[$nom] = $this->get_select($nom);
616
-			}
617
-			$this->next();
618
-
619
-			return $r;
620
-		}
621
-	}
622
-
623
-	// retourner la cle pour #CLE
624
-	public function cle() {
625
-		return $this->key();
626
-	}
627
-
628
-	// retourner la valeur pour #VALEUR
629
-	public function valeur() {
630
-		return $this->current();
631
-	}
632
-
633
-	/**
634
-	 * Accepte-t-on l'entree courante lue ?
635
-	 * On execute les filtres pour le savoir.
636
-	 **/
637
-	public function accept(): bool {
638
-		if ($f = $this->func_filtre) {
639
-			return $f();
640
-		}
641
-
642
-		return true;
643
-	}
644
-
645
-	/**
646
-	 * liberer la ressource
647
-	 *
648
-	 * @return bool
649
-	 */
650
-	public function free() {
651
-		if (method_exists($this->iter, 'free')) {
652
-			$this->iter->free();
653
-		}
654
-		$this->pos = $this->total = 0;
655
-
656
-		return true;
657
-	}
658
-
659
-	/**
660
-	 * Compter le nombre total de resultats
661
-	 * pour #TOTAL_BOUCLE
662
-	 *
663
-	 * @return int
664
-	 */
665
-	public function count() {
666
-		if (is_null($this->total)) {
667
-			if (
668
-				method_exists($this->iter, 'count')
669
-				and !$this->func_filtre
670
-			) {
671
-				return $this->total = $this->iter->count();
672
-			} else {
673
-				// compter les lignes et rembobiner
674
-				$total = 0;
675
-				$pos = $this->pos; // sauver la position
676
-				$this->rewind();
677
-				while ($this->fetch() and $total < $this->max) {
678
-					$total++;
679
-				}
680
-				$this->seek($pos);
681
-				$this->total = $total;
682
-			}
683
-		}
684
-
685
-		return $this->total;
686
-	}
537
+    private function seek_loop($n) {
538
+        if ($this->pos > $n) {
539
+            $this->rewind();
540
+        }
541
+
542
+        while ($this->pos < $n and $this->valid()) {
543
+            $this->next();
544
+        }
545
+
546
+        return true;
547
+    }
548
+
549
+    /**
550
+     * Avancer de $saut pas
551
+     *
552
+     * @param  $saut
553
+     * @param  $max
554
+     * @return int
555
+     */
556
+    public function skip($saut, $max = null) {
557
+        // pas de saut en arriere autorise pour cette fonction
558
+        if (($saut = intval($saut)) <= 0) {
559
+            return $this->pos;
560
+        }
561
+        $seek = $this->pos + $saut;
562
+        // si le saut fait depasser le maxi, on libere la resource
563
+        // et on sort
564
+        if (is_null($max)) {
565
+            $max = $this->count();
566
+        }
567
+
568
+        if ($seek >= $max or $seek >= $this->count()) {
569
+            // sortie plus rapide que de faire next() jusqu'a la fin !
570
+            $this->free();
571
+
572
+            return $max;
573
+        }
574
+
575
+        $this->seek($seek);
576
+
577
+        return $this->pos;
578
+    }
579
+
580
+    /**
581
+     * Renvoyer un tableau des donnees correspondantes
582
+     * a la position courante de l'iterateur
583
+     * en controlant si on respecte le filtre
584
+     * Appliquer aussi le critere {offset,limit}
585
+     *
586
+     * @return array|bool
587
+     */
588
+    public function fetch() {
589
+        if (method_exists($this->iter, 'fetch')) {
590
+            return $this->iter->fetch();
591
+        } else {
592
+            while (
593
+                $this->valid()
594
+                and (
595
+                    !$this->accept()
596
+                    or (isset($this->offset) and $this->fetched++ < $this->offset)
597
+                )
598
+            ) {
599
+                $this->next();
600
+            }
601
+
602
+            if (!$this->valid()) {
603
+                return false;
604
+            }
605
+
606
+            if (
607
+                isset($this->limit)
608
+                and $this->fetched > $this->offset + $this->limit
609
+            ) {
610
+                return false;
611
+            }
612
+
613
+            $r = [];
614
+            foreach ($this->select as $nom) {
615
+                $r[$nom] = $this->get_select($nom);
616
+            }
617
+            $this->next();
618
+
619
+            return $r;
620
+        }
621
+    }
622
+
623
+    // retourner la cle pour #CLE
624
+    public function cle() {
625
+        return $this->key();
626
+    }
627
+
628
+    // retourner la valeur pour #VALEUR
629
+    public function valeur() {
630
+        return $this->current();
631
+    }
632
+
633
+    /**
634
+     * Accepte-t-on l'entree courante lue ?
635
+     * On execute les filtres pour le savoir.
636
+     **/
637
+    public function accept(): bool {
638
+        if ($f = $this->func_filtre) {
639
+            return $f();
640
+        }
641
+
642
+        return true;
643
+    }
644
+
645
+    /**
646
+     * liberer la ressource
647
+     *
648
+     * @return bool
649
+     */
650
+    public function free() {
651
+        if (method_exists($this->iter, 'free')) {
652
+            $this->iter->free();
653
+        }
654
+        $this->pos = $this->total = 0;
655
+
656
+        return true;
657
+    }
658
+
659
+    /**
660
+     * Compter le nombre total de resultats
661
+     * pour #TOTAL_BOUCLE
662
+     *
663
+     * @return int
664
+     */
665
+    public function count() {
666
+        if (is_null($this->total)) {
667
+            if (
668
+                method_exists($this->iter, 'count')
669
+                and !$this->func_filtre
670
+            ) {
671
+                return $this->total = $this->iter->count();
672
+            } else {
673
+                // compter les lignes et rembobiner
674
+                $total = 0;
675
+                $pos = $this->pos; // sauver la position
676
+                $this->rewind();
677
+                while ($this->fetch() and $total < $this->max) {
678
+                    $total++;
679
+                }
680
+                $this->seek($pos);
681
+                $this->total = $total;
682
+            }
683
+        }
684
+
685
+        return $this->total;
686
+    }
687 687
 }
Please login to merge, or discard this patch.
ecrire/public/quete.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	return sql_getfetsel(
37 37
 		'virtuel',
38 38
 		'spip_articles',
39
-		['id_article=' . intval($id_article), "statut='publie'"],
39
+		['id_article='.intval($id_article), "statut='publie'"],
40 40
 		'',
41 41
 		'',
42 42
 		'',
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 			$cache_quete[$connect][$table][$id] = sql_fetsel(
82 82
 				$cache_quete[$connect][$table]['_select'],
83 83
 				$table,
84
-				$cache_quete[$connect][$table]['_id'] . '=' . intval($id),
84
+				$cache_quete[$connect][$table]['_id'].'='.intval($id),
85 85
 				'',
86 86
 				'',
87 87
 				'',
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 	return
174 174
 		(isset($GLOBALS['meta']['date_prochain_postdate'])
175 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)
176
+			? "$champ_date<".sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur)
177 177
 			: '1=1';
178 178
 }
179 179
 
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 				and $id_table = reset($objet)
233 233
 				and $objet = objet_type($id_table)
234 234
 			) {
235
-				$w = "$mstatut<>" . sql_quote($v);
235
+				$w = "$mstatut<>".sql_quote($v);
236 236
 
237 237
 				// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
238 238
 				// sinon l’auteur en session
@@ -246,22 +246,22 @@  discard block
 block discarded – undo
246 246
 				}
247 247
 
248 248
 				// dans ce cas (admin en general), pas de filtrage sur ce statut
249
-				if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) {
249
+				if (!autoriser('previsualiser'.$v, $objet, '', $id_auteur)) {
250 250
 					// si pas d'auteur identifie pas de sous-requete car pas d'article qui matche
251 251
 					if (!$id_auteur) {
252 252
 						$where[] = $w;
253 253
 					} else {
254 254
 						$primary = id_table_objet($objet);
255
-						$where[] = "($w OR $id_table.$primary IN (" . sql_get_select(
255
+						$where[] = "($w OR $id_table.$primary IN (".sql_get_select(
256 256
 							'ssss.id_objet',
257 257
 							'spip_auteurs_liens AS ssss',
258
-							'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur),
258
+							'ssss.objet='.sql_quote($objet).' AND ssss.id_auteur='.intval($id_auteur),
259 259
 							'',
260 260
 							'',
261 261
 							'',
262 262
 							'',
263 263
 							$serveur
264
-						) . '))';
264
+						).'))';
265 265
 					}
266 266
 				}
267 267
 			} // ignorer ce statut si on ne sait pas comment le filtrer
@@ -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
 /**
@@ -377,9 +377,9 @@  discard block
 block discarded – undo
377 377
 				// qui permet de distinguer le changement de logo
378 378
 				// et placer un expire sur le dossier IMG/
379 379
 				$res = [
380
-					$on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''),
381
-					($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''),
382
-					(!$taille ? '' : (' ' . $taille[3]))
380
+					$on['chemin'].($on['timestamp'] ? "?{$on['timestamp']}" : ''),
381
+					($off ? $off['chemin'].($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''),
382
+					(!$taille ? '' : (' '.$taille[3]))
383 383
 				];
384 384
 				$res['src'] = $res[0];
385 385
 				$res['logo_on'] = $res[0];
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
 	if (
477 477
 		strcmp($logo, _DIR_PLUGINS) == 0
478 478
 		or strcmp($logo, _DIR_PLUGINS_DIST) == 0
479
-		or strcmp($logo, _DIR_RACINE . 'prive/') == 0
479
+		or strcmp($logo, _DIR_RACINE.'prive/') == 0
480 480
 	) {
481 481
 		return $logo;
482 482
 	}
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
 				$exposer[$m][$type][$principal] = true;
647 647
 				if ($type == 'id_mot') {
648 648
 					if (!$parent) {
649
-						$parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect);
649
+						$parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot='.intval($principal), '', '', '', '', $connect);
650 650
 					}
651 651
 					if ($parent) {
652 652
 						$exposer[$m]['id_groupe'][$parent] = true;
Please login to merge, or discard this patch.
Indentation   +412 added lines, -412 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, string $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 $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 $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, string $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, string $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, string $connect = '') {
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
 /**
@@ -581,23 +581,23 @@  discard block
 block discarded – undo
581 581
  */
582 582
 function vignette_logo_document($row, string $connect = '') {
583 583
 
584
-	if (!$row or empty($row['id_vignette'])) {
585
-		return '';
586
-	}
587
-	$fichier = quete_fichier($row['id_vignette'], $connect);
588
-	if ($url = document_spip_externe($fichier, $connect)) {
589
-		return $url;
590
-	}
591
-
592
-	$f = get_spip_doc($fichier);
593
-	if ($f and @file_exists($f)) {
594
-		return $f;
595
-	}
596
-	if ($row['mode'] !== 'vignette') {
597
-		return '';
598
-	}
599
-
600
-	return generer_objet_url($row['id_document'], 'document', '', '', null, '', $connect);
584
+    if (!$row or empty($row['id_vignette'])) {
585
+        return '';
586
+    }
587
+    $fichier = quete_fichier($row['id_vignette'], $connect);
588
+    if ($url = document_spip_externe($fichier, $connect)) {
589
+        return $url;
590
+    }
591
+
592
+    $f = get_spip_doc($fichier);
593
+    if ($f and @file_exists($f)) {
594
+        return $f;
595
+    }
596
+    if ($row['mode'] !== 'vignette') {
597
+        return '';
598
+    }
599
+
600
+    return generer_objet_url($row['id_document'], 'document', '', '', null, '', $connect);
601 601
 }
602 602
 
603 603
 /**
@@ -613,66 +613,66 @@  discard block
 block discarded – undo
613 613
  * @return bool|string
614 614
  */
615 615
 function calcul_exposer($id, $prim, $reference, $parent, $type, string $connect = '') {
616
-	static $exposer = [];
617
-
618
-	// Que faut-il exposer ? Tous les elements de $reference
619
-	// ainsi que leur hierarchie ; on ne fait donc ce calcul
620
-	// qu'une fois (par squelette) et on conserve le resultat
621
-	// en static.
622
-	if (!isset($exposer[$m = md5(serialize($reference))][$prim])) {
623
-		$principal = $reference[$type] ?? $reference["@$type"] ?? '';
624
-		// le parent fournit en argument est le parent de $id, pas celui de $principal
625
-		// il n'est donc pas utile
626
-		$parent = 0;
627
-		if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant
628
-			$enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']];
629
-			if (isset($enfants[$type])) {
630
-				foreach ($enfants[$type] as $t) {
631
-					if (
632
-						isset($reference[$t])
633
-						// cas de la reference donnee dynamiquement par la pagination
634
-						or isset($reference["@$t"])
635
-					) {
636
-						$type = $t;
637
-						$principal = $reference[$type] ?? $reference["@$type"];
638
-						continue;
639
-					}
640
-				}
641
-			}
642
-		}
643
-		$exposer[$m][$type] = [];
644
-		if ($principal) {
645
-			$principaux = is_array($principal) ? $principal : [$principal];
646
-			foreach ($principaux as $principal) {
647
-				$exposer[$m][$type][$principal] = true;
648
-				if ($type == 'id_mot') {
649
-					if (!$parent) {
650
-						$parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect);
651
-					}
652
-					if ($parent) {
653
-						$exposer[$m]['id_groupe'][$parent] = true;
654
-					}
655
-				} else {
656
-					if ($type != 'id_groupe') {
657
-						if (!$parent) {
658
-							if ($type == 'id_rubrique') {
659
-								$parent = $principal;
660
-							}
661
-							if ($type == 'id_article') {
662
-								$parent = quete_rubrique($principal, $connect);
663
-							}
664
-						}
665
-						do {
666
-							$exposer[$m]['id_rubrique'][$parent] = true;
667
-						} while ($parent = quete_parent($parent, $connect));
668
-					}
669
-				}
670
-			}
671
-		}
672
-	}
673
-
674
-	// And the winner is...
675
-	return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : '';
616
+    static $exposer = [];
617
+
618
+    // Que faut-il exposer ? Tous les elements de $reference
619
+    // ainsi que leur hierarchie ; on ne fait donc ce calcul
620
+    // qu'une fois (par squelette) et on conserve le resultat
621
+    // en static.
622
+    if (!isset($exposer[$m = md5(serialize($reference))][$prim])) {
623
+        $principal = $reference[$type] ?? $reference["@$type"] ?? '';
624
+        // le parent fournit en argument est le parent de $id, pas celui de $principal
625
+        // il n'est donc pas utile
626
+        $parent = 0;
627
+        if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant
628
+            $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']];
629
+            if (isset($enfants[$type])) {
630
+                foreach ($enfants[$type] as $t) {
631
+                    if (
632
+                        isset($reference[$t])
633
+                        // cas de la reference donnee dynamiquement par la pagination
634
+                        or isset($reference["@$t"])
635
+                    ) {
636
+                        $type = $t;
637
+                        $principal = $reference[$type] ?? $reference["@$type"];
638
+                        continue;
639
+                    }
640
+                }
641
+            }
642
+        }
643
+        $exposer[$m][$type] = [];
644
+        if ($principal) {
645
+            $principaux = is_array($principal) ? $principal : [$principal];
646
+            foreach ($principaux as $principal) {
647
+                $exposer[$m][$type][$principal] = true;
648
+                if ($type == 'id_mot') {
649
+                    if (!$parent) {
650
+                        $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect);
651
+                    }
652
+                    if ($parent) {
653
+                        $exposer[$m]['id_groupe'][$parent] = true;
654
+                    }
655
+                } else {
656
+                    if ($type != 'id_groupe') {
657
+                        if (!$parent) {
658
+                            if ($type == 'id_rubrique') {
659
+                                $parent = $principal;
660
+                            }
661
+                            if ($type == 'id_article') {
662
+                                $parent = quete_rubrique($principal, $connect);
663
+                            }
664
+                        }
665
+                        do {
666
+                            $exposer[$m]['id_rubrique'][$parent] = true;
667
+                        } while ($parent = quete_parent($parent, $connect));
668
+                    }
669
+                }
670
+            }
671
+        }
672
+    }
673
+
674
+    // And the winner is...
675
+    return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : '';
676 676
 }
677 677
 
678 678
 /**
@@ -687,23 +687,23 @@  discard block
 block discarded – undo
687 687
  * @return int
688 688
  */
689 689
 function quete_debut_pagination($primary, $valeur, $pas, $iter) {
690
-	// on ne devrait pas arriver ici si la cle primaire est inexistante
691
-	// ou composee, mais verifions
692
-	if (!$primary or preg_match('/[,\s]/', $primary)) {
693
-		return 0;
694
-	}
695
-
696
-	$pos = 0;
697
-	while ($row = $iter->fetch() and $row[$primary] != $valeur) {
698
-		$pos++;
699
-	}
700
-	// si on a pas trouve
701
-	if (!$row or $row[$primary] != $valeur) {
702
-		return 0;
703
-	}
704
-
705
-	// sinon, calculer le bon numero de page
706
-	return floor($pos / $pas) * $pas;
690
+    // on ne devrait pas arriver ici si la cle primaire est inexistante
691
+    // ou composee, mais verifions
692
+    if (!$primary or preg_match('/[,\s]/', $primary)) {
693
+        return 0;
694
+    }
695
+
696
+    $pos = 0;
697
+    while ($row = $iter->fetch() and $row[$primary] != $valeur) {
698
+        $pos++;
699
+    }
700
+    // si on a pas trouve
701
+    if (!$row or $row[$primary] != $valeur) {
702
+        return 0;
703
+    }
704
+
705
+    // sinon, calculer le bon numero de page
706
+    return floor($pos / $pas) * $pas;
707 707
 }
708 708
 
709 709
 /**
@@ -714,11 +714,11 @@  discard block
 block discarded – undo
714 714
  * @return boolean
715 715
  */
716 716
 function is_whereable($value): bool {
717
-	if (is_array($value) && count($value)) {
718
-		return true;
719
-	}
720
-	if (is_scalar($value) && strlen($value)) {
721
-		return true;
722
-	}
723
-	return false;
717
+    if (is_array($value) && count($value)) {
718
+        return true;
719
+    }
720
+    if (is_scalar($value) && strlen($value)) {
721
+        return true;
722
+    }
723
+    return false;
724 724
 }
Please login to merge, or discard this patch.