Completed
Push — master ( b0cbd6...fdca64 )
by cam
01:18
created
ecrire/action/activer_plugins.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -27,49 +27,49 @@  discard block
 block discarded – undo
27 27
  * @return void
28 28
  */
29 29
 function enregistre_modif_plugin() {
30
-	include_spip('inc/plugin');
31
-	// recuperer les plugins dans l'ordre des $_POST
32
-	$test = [];
33
-	foreach (liste_plugin_files() as $file) {
34
-		$test['s' . substr(md5(_DIR_PLUGINS . $file), 0, 16)] = $file;
35
-	}
36
-	if (defined('_DIR_PLUGINS_SUPPL')) {
37
-		foreach (liste_plugin_files(_DIR_PLUGINS_SUPPL) as $file) {
38
-			$test['s' . substr(md5(_DIR_PLUGINS_SUPPL . $file), 0, 16)] = $file;
39
-		}
40
-	}
30
+    include_spip('inc/plugin');
31
+    // recuperer les plugins dans l'ordre des $_POST
32
+    $test = [];
33
+    foreach (liste_plugin_files() as $file) {
34
+        $test['s' . substr(md5(_DIR_PLUGINS . $file), 0, 16)] = $file;
35
+    }
36
+    if (defined('_DIR_PLUGINS_SUPPL')) {
37
+        foreach (liste_plugin_files(_DIR_PLUGINS_SUPPL) as $file) {
38
+            $test['s' . substr(md5(_DIR_PLUGINS_SUPPL . $file), 0, 16)] = $file;
39
+        }
40
+    }
41 41
 
42
-	$plugin = [];
42
+    $plugin = [];
43 43
 
44
-	foreach ($_POST as $choix => $val) {
45
-		if (isset($test[$choix]) && $val == 'O') {
46
-			$plugin[] = $test[$choix];
47
-		}
48
-	}
44
+    foreach ($_POST as $choix => $val) {
45
+        if (isset($test[$choix]) && $val == 'O') {
46
+            $plugin[] = $test[$choix];
47
+        }
48
+    }
49 49
 
50
-	spip_log("Changement des plugins actifs par l'auteur " . $GLOBALS['visiteur_session']['id_auteur'] . ': ' . implode(
51
-		',',
52
-		$plugin
53
-	));
54
-	ecrire_plugin_actifs($plugin);
50
+    spip_log("Changement des plugins actifs par l'auteur " . $GLOBALS['visiteur_session']['id_auteur'] . ': ' . implode(
51
+        ',',
52
+        $plugin
53
+    ));
54
+    ecrire_plugin_actifs($plugin);
55 55
 
56
-	// Chaque fois que l'on valide des plugins, on memorise la liste de ces plugins comme etant "interessants", avec un score initial, qui sera decremente a chaque tour : ainsi un plugin active pourra reter visible a l'ecran, jusqu'a ce qu'il tombe dans l'oubli.
57
-	$plugins_interessants = @unserialize($GLOBALS['meta']['plugins_interessants']);
58
-	if (!is_array($plugins_interessants)) {
59
-		$plugins_interessants = [];
60
-	}
56
+    // Chaque fois que l'on valide des plugins, on memorise la liste de ces plugins comme etant "interessants", avec un score initial, qui sera decremente a chaque tour : ainsi un plugin active pourra reter visible a l'ecran, jusqu'a ce qu'il tombe dans l'oubli.
57
+    $plugins_interessants = @unserialize($GLOBALS['meta']['plugins_interessants']);
58
+    if (!is_array($plugins_interessants)) {
59
+        $plugins_interessants = [];
60
+    }
61 61
 
62
-	$plugins_interessants2 = [];
62
+    $plugins_interessants2 = [];
63 63
 
64
-	foreach ($plugins_interessants as $plug => $score) {
65
-		if ($score > 1) {
66
-			$plugins_interessants2[$plug] = $score - 1;
67
-		}
68
-	}
69
-	foreach ($plugin as $plug) {
70
-		$plugins_interessants2[$plug] = 10;
71
-	} // score initial
72
-	ecrire_meta('plugins_interessants', serialize($plugins_interessants2));
64
+    foreach ($plugins_interessants as $plug => $score) {
65
+        if ($score > 1) {
66
+            $plugins_interessants2[$plug] = $score - 1;
67
+        }
68
+    }
69
+    foreach ($plugin as $plug) {
70
+        $plugins_interessants2[$plug] = 10;
71
+    } // score initial
72
+    ecrire_meta('plugins_interessants', serialize($plugins_interessants2));
73 73
 }
74 74
 
75 75
 /**
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
  */
82 82
 function action_activer_plugins_dist() {
83 83
 
84
-	$securiser_action = charger_fonction('securiser_action', 'inc');
85
-	$securiser_action();
84
+    $securiser_action = charger_fonction('securiser_action', 'inc');
85
+    $securiser_action();
86 86
 
87
-	if (!autoriser('configurer', '_plugins')) {
88
-		die('erreur');
89
-	}
90
-	// forcer la maj des meta pour les cas de modif de numero de version base via phpmyadmin
91
-	lire_metas();
92
-	enregistre_modif_plugin();
87
+    if (!autoriser('configurer', '_plugins')) {
88
+        die('erreur');
89
+    }
90
+    // forcer la maj des meta pour les cas de modif de numero de version base via phpmyadmin
91
+    lire_metas();
92
+    enregistre_modif_plugin();
93 93
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -31,11 +31,11 @@  discard block
 block discarded – undo
31 31
 	// recuperer les plugins dans l'ordre des $_POST
32 32
 	$test = [];
33 33
 	foreach (liste_plugin_files() as $file) {
34
-		$test['s' . substr(md5(_DIR_PLUGINS . $file), 0, 16)] = $file;
34
+		$test['s'.substr(md5(_DIR_PLUGINS.$file), 0, 16)] = $file;
35 35
 	}
36 36
 	if (defined('_DIR_PLUGINS_SUPPL')) {
37 37
 		foreach (liste_plugin_files(_DIR_PLUGINS_SUPPL) as $file) {
38
-			$test['s' . substr(md5(_DIR_PLUGINS_SUPPL . $file), 0, 16)] = $file;
38
+			$test['s'.substr(md5(_DIR_PLUGINS_SUPPL.$file), 0, 16)] = $file;
39 39
 		}
40 40
 	}
41 41
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 		}
48 48
 	}
49 49
 
50
-	spip_log("Changement des plugins actifs par l'auteur " . $GLOBALS['visiteur_session']['id_auteur'] . ': ' . implode(
50
+	spip_log("Changement des plugins actifs par l'auteur ".$GLOBALS['visiteur_session']['id_auteur'].': '.implode(
51 51
 		',',
52 52
 		$plugin
53 53
 	));
Please login to merge, or discard this patch.
ecrire/action/cookie.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	if ($change_session == 'oui') {
59 59
 		$session = charger_fonction('session', 'inc');
60 60
 		$session(true);
61
-		spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']);
61
+		spip_log('statut 204 pour '.$_SERVER['REQUEST_URI']);
62 62
 		http_response_code(204); // No Content
63 63
 		return;
64 64
 	}
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 				_T('info_connexion_refusee'),
79 79
 				_T('login_login_pass_incorrect'),
80 80
 				_T('login_retour_site'),
81
-				'url=' . rawurlencode((string) $redirect),
81
+				'url='.rawurlencode((string) $redirect),
82 82
 				_T('login_nouvelle_tentative'),
83 83
 				(str_contains((string) $url, (string) _DIR_RESTREINT_ABS))
84 84
 			);
Please login to merge, or discard this patch.
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  */
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/actions');
@@ -32,94 +32,94 @@  discard block
 block discarded – undo
32 32
  * @return void
33 33
  */
34 34
 function action_cookie_dist($set_cookie_admin = null, $change_session = null) {
35
-	$redirect_echec = $redirect = null;
36
-	$test_echec_cookie = null;
37
-	$url = '';
38
-	if (is_null($set_cookie_admin)) {
39
-		$set_cookie_admin = _request('cookie_admin');
40
-		$change_session = _request('change_session');
41
-		$test_echec_cookie = _request('test_echec_cookie');
35
+    $redirect_echec = $redirect = null;
36
+    $test_echec_cookie = null;
37
+    $url = '';
38
+    if (is_null($set_cookie_admin)) {
39
+        $set_cookie_admin = _request('cookie_admin');
40
+        $change_session = _request('change_session');
41
+        $test_echec_cookie = _request('test_echec_cookie');
42 42
 
43
-		// La cible de notre operation de connexion
44
-		$url = securiser_redirect_action(_request('url'));
45
-		$redirect = $url ?: generer_url_ecrire('accueil');
46
-		$redirect_echec = _request('url_echec');
47
-		if (!isset($redirect_echec)) {
48
-			if (str_contains((string) $redirect, (string) _DIR_RESTREINT_ABS)) {
49
-				$redirect_echec = generer_url_public('login', '', true);
50
-			} else {
51
-				$redirect_echec = $redirect;
52
-			}
53
-		}
54
-	}
43
+        // La cible de notre operation de connexion
44
+        $url = securiser_redirect_action(_request('url'));
45
+        $redirect = $url ?: generer_url_ecrire('accueil');
46
+        $redirect_echec = _request('url_echec');
47
+        if (!isset($redirect_echec)) {
48
+            if (str_contains((string) $redirect, (string) _DIR_RESTREINT_ABS)) {
49
+                $redirect_echec = generer_url_public('login', '', true);
50
+            } else {
51
+                $redirect_echec = $redirect;
52
+            }
53
+        }
54
+    }
55 55
 
56 56
 
57
-	// rejoue le cookie pour renouveler spip_session
58
-	if ($change_session == 'oui') {
59
-		$session = charger_fonction('session', 'inc');
60
-		$session(true);
61
-		spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']);
62
-		http_response_code(204); // No Content
63
-		return;
64
-	}
57
+    // rejoue le cookie pour renouveler spip_session
58
+    if ($change_session == 'oui') {
59
+        $session = charger_fonction('session', 'inc');
60
+        $session(true);
61
+        spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']);
62
+        http_response_code(204); // No Content
63
+        return;
64
+    }
65 65
 
66
-	// tentative de connexion en auth_http
67
-	if (_request('essai_auth_http') && !$GLOBALS['ignore_auth_http']) {
68
-		include_spip('inc/auth');
69
-		if (
70
-			@$_SERVER['PHP_AUTH_USER']
71
-			&& @$_SERVER['PHP_AUTH_PW']
72
-			&& ($auteur = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']))
73
-		) {
74
-			auth_loger($auteur);
75
-			redirige_par_entete(parametre_url($redirect, 't', time(), '&'));
76
-		} else {
77
-			ask_php_auth(
78
-				_T('info_connexion_refusee'),
79
-				_T('login_login_pass_incorrect'),
80
-				_T('login_retour_site'),
81
-				'url=' . rawurlencode((string) $redirect),
82
-				_T('login_nouvelle_tentative'),
83
-				(str_contains((string) $url, (string) _DIR_RESTREINT_ABS))
84
-			);
85
-		}
86
-	} else {
87
-		// en cas de login sur bonjour=oui, on tente de poser un cookie
88
-		// puis de passer au login qui diagnostiquera l'echec de cookie
89
-		// le cas echeant.
90
-		if ($test_echec_cookie == 'oui') {
91
-			spip_setcookie('spip_session', 'test_echec_cookie', httponly: true);
92
-			if ($redirect) {
93
-				$redirect = parametre_url(
94
-					parametre_url($redirect_echec, 'var_echec_cookie', 'oui', '&'),
95
-					'url',
96
-					rawurlencode((string) $redirect),
97
-					'&'
98
-				);
99
-			}
100
-		} else {
101
-			$cook = $_COOKIE['spip_admin'] ?? '';
102
-			// Suppression cookie d'admin ?
103
-			if ($set_cookie_admin == 'non') {
104
-				if ($cook) {
105
-					spip_setcookie('spip_admin', $cook, time() - 3600 * 24, httponly: true);
106
-				}
107
-			} // Ajout de cookie d'admin
108
-			else {
109
-				if ($set_cookie_admin && _DUREE_COOKIE_ADMIN) {
110
-					spip_setcookie(
111
-						'spip_admin',
112
-						$set_cookie_admin,
113
-						time() + max(_DUREE_COOKIE_ADMIN, 2 * _RENOUVELLE_ALEA),
114
-						httponly: true
115
-					);
116
-				}
117
-			}
118
-		}
119
-	}
66
+    // tentative de connexion en auth_http
67
+    if (_request('essai_auth_http') && !$GLOBALS['ignore_auth_http']) {
68
+        include_spip('inc/auth');
69
+        if (
70
+            @$_SERVER['PHP_AUTH_USER']
71
+            && @$_SERVER['PHP_AUTH_PW']
72
+            && ($auteur = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']))
73
+        ) {
74
+            auth_loger($auteur);
75
+            redirige_par_entete(parametre_url($redirect, 't', time(), '&'));
76
+        } else {
77
+            ask_php_auth(
78
+                _T('info_connexion_refusee'),
79
+                _T('login_login_pass_incorrect'),
80
+                _T('login_retour_site'),
81
+                'url=' . rawurlencode((string) $redirect),
82
+                _T('login_nouvelle_tentative'),
83
+                (str_contains((string) $url, (string) _DIR_RESTREINT_ABS))
84
+            );
85
+        }
86
+    } else {
87
+        // en cas de login sur bonjour=oui, on tente de poser un cookie
88
+        // puis de passer au login qui diagnostiquera l'echec de cookie
89
+        // le cas echeant.
90
+        if ($test_echec_cookie == 'oui') {
91
+            spip_setcookie('spip_session', 'test_echec_cookie', httponly: true);
92
+            if ($redirect) {
93
+                $redirect = parametre_url(
94
+                    parametre_url($redirect_echec, 'var_echec_cookie', 'oui', '&'),
95
+                    'url',
96
+                    rawurlencode((string) $redirect),
97
+                    '&'
98
+                );
99
+            }
100
+        } else {
101
+            $cook = $_COOKIE['spip_admin'] ?? '';
102
+            // Suppression cookie d'admin ?
103
+            if ($set_cookie_admin == 'non') {
104
+                if ($cook) {
105
+                    spip_setcookie('spip_admin', $cook, time() - 3600 * 24, httponly: true);
106
+                }
107
+            } // Ajout de cookie d'admin
108
+            else {
109
+                if ($set_cookie_admin && _DUREE_COOKIE_ADMIN) {
110
+                    spip_setcookie(
111
+                        'spip_admin',
112
+                        $set_cookie_admin,
113
+                        time() + max(_DUREE_COOKIE_ADMIN, 2 * _RENOUVELLE_ALEA),
114
+                        httponly: true
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.
ecrire/src/Sql/Sqlite/Traducteur.php 2 patches
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -9,195 +9,195 @@
 block discarded – undo
9 9
  */
10 10
 class Traducteur
11 11
 {
12
-	/** Pour les corrections à effectuer sur les requêtes : array(code=>'texte') trouvé
13
-	 *
14
-	 * @var array
15
-	 */
16
-	public $textes = [];
17
-
18
-	/**
19
-	 * Constructeur
20
-	 */
21
-	public function __construct(
22
-		/** Requête à préparer */
23
-		public string $query,
24
-		/** Prefixe des tables à utiliser */
25
-		public string $prefixe,
26
-		/** Version SQLite (2 ou 3) */
27
-		public string $sqlite_version
28
-	) {
29
-	}
30
-
31
-	/**
32
-	 * Transformer la requete pour SQLite
33
-	 *
34
-	 * Enlève les textes, transforme la requête pour quelle soit
35
-	 * bien interprétée par SQLite, puis remet les textes
36
-	 * la fonction affecte `$this->query`
37
-	 */
38
-	public function traduire_requete() {
39
-		//
40
-		// 1) Protection des textes en les remplacant par des codes
41
-		//
42
-		// enlever les 'textes' et initialiser avec
43
-		[$this->query, $textes] = query_echappe_textes($this->query);
44
-
45
-		//
46
-		// 2) Corrections de la requete
47
-		//
48
-		// Correction Create Database
49
-		// Create Database -> requete ignoree
50
-		if (str_starts_with((string) $this->query, 'CREATE DATABASE')) {
51
-			spip_log("Sqlite : requete non executee -> $this->query", 'sqlite.' . _LOG_AVERTISSEMENT);
52
-			$this->query = 'SELECT 1';
53
-		}
54
-
55
-		// Correction Insert Ignore
56
-		// INSERT IGNORE -> insert (tout court et pas 'insert or replace')
57
-		if (str_starts_with((string) $this->query, 'INSERT IGNORE')) {
58
-			spip_log("Sqlite : requete transformee -> $this->query", 'sqlite.' . _LOG_DEBUG);
59
-			$this->query = 'INSERT ' . substr((string) $this->query, '13');
60
-		}
61
-
62
-		// Correction des dates avec INTERVAL
63
-		// utiliser sql_date_proche() de preference
64
-		if (str_contains((string) $this->query, 'INTERVAL')) {
65
-			$this->query = preg_replace_callback(
66
-				'/DATE_(ADD|SUB)(.*)INTERVAL\s+(\d+)\s+([a-zA-Z]+)\)/U',
67
-				fn(array $matches): string => $this->_remplacerDateParTime($matches),
68
-				(string) $this->query
69
-			);
70
-		}
71
-
72
-		if (str_contains((string) $this->query, 'LEFT(')) {
73
-			$this->query = str_replace('LEFT(', '_LEFT(', (string) $this->query);
74
-		}
75
-
76
-		if (str_contains((string) $this->query, 'TIMESTAMPDIFF(')) {
77
-			$this->query = preg_replace('/TIMESTAMPDIFF\(\s*([^,]*)\s*,/Uims', "TIMESTAMPDIFF('\\1',", (string) $this->query);
78
-		}
79
-
80
-
81
-		// Correction Using
82
-		// USING (non reconnu en sqlite2)
83
-		// problematique car la jointure ne se fait pas du coup.
84
-		if (($this->sqlite_version == 2) && (str_contains((string) $this->query, 'USING'))) {
85
-			spip_log(
86
-				"'USING (champ)' n'est pas reconnu en SQLite 2. Utilisez 'ON table1.champ = table2.champ'",
87
-				'sqlite.' . _LOG_ERREUR
88
-			);
89
-			$this->query = preg_replace('/USING\s*\([^\)]*\)/', '', (string) $this->query);
90
-		}
91
-
92
-		// Correction Field
93
-		// remplace FIELD(table,i,j,k...) par CASE WHEN table=i THEN n ... ELSE 0 END
94
-		if (str_contains((string) $this->query, 'FIELD')) {
95
-			$this->query = preg_replace_callback(
96
-				'/FIELD\s*\(([^\)]*)\)/',
97
-				fn(array $matches): string => $this->_remplacerFieldParCase($matches),
98
-				(string) $this->query
99
-			);
100
-		}
101
-
102
-		// Correction des noms de tables FROM
103
-		// mettre les bons noms de table dans from, update, insert, replace...
104
-		if (preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/iS', (string) $this->query, $regs)) {
105
-			$suite = strstr((string) $this->query, $regs[0]);
106
-			$this->query = substr((string) $this->query, 0, -strlen($suite));
107
-		} else {
108
-			$suite = '';
109
-		}
110
-		$pref = ($this->prefixe) ? $this->prefixe . '_' : '';
111
-		$this->query = preg_replace('/([,\s])spip_/S', '\1' . $pref, (string) $this->query) . $suite;
112
-
113
-		// Correction zero AS x
114
-		// pg n'aime pas 0+x AS alias, sqlite, dans le meme style,
115
-		// n'apprecie pas du tout SELECT 0 as x ... ORDER BY x
116
-		// il dit que x ne doit pas être un integer dans le order by !
117
-		// on remplace du coup x par vide() dans ce cas uniquement
118
-		//
119
-		// apparait dans public/vertebrer.php et dans le plugin menu aussi qui genere aussi ce genre de requete via un {par num #GET{tri_num}}
120
-		// mais est-ce encore un soucis pour sqlite en 2021 ? (ie commenter le preg_replace marche très bien en sqlite 3.28)
121
-		// on ne remplace que dans ORDER BY ou GROUP BY
122
-		if (str_contains($this->query, '0 AS') && preg_match('/\s(ORDER|GROUP) BY\s/i', $this->query, $regs)) {
123
-			$suite = strstr($this->query, $regs[0]);
124
-			$this->query = substr($this->query, 0, -strlen($suite));
125
-			// on cherche les noms des x dans 0 AS x
126
-			// on remplace dans $suite le nom par vide()
127
-			preg_match_all('/\b0 AS\s*([^\s,]+)/', $this->query, $matches, PREG_PATTERN_ORDER);
128
-			foreach ($matches[1] as $m) {
129
-				if (str_contains($suite, $m)) {
130
-					$suite = preg_replace(",\b$m\b,", 'VIDE()', $suite);
131
-				}
132
-			}
133
-			$this->query .= $suite;
134
-		}
135
-
136
-		// Correction possible des divisions entieres
137
-		// Le standard SQL (lequel? ou?) semble indiquer que
138
-		// a/b=c doit donner c entier si a et b sont entiers 4/3=1.
139
-		// C'est ce que retournent effectivement SQL Server et SQLite
140
-		// Ce n'est pas ce qu'applique MySQL qui retourne un reel : 4/3=1.333...
141
-		//
142
-		// On peut forcer la conversion en multipliant par 1.0 avant la division
143
-		// /!\ SQLite 3.5.9 Debian/Ubuntu est victime d'un bug en plus !
144
-		// cf. https://bugs.launchpad.net/ubuntu/+source/sqlite3/+bug/254228
145
-		//     http://www.sqlite.org/cvstrac/tktview?tn=3202
146
-		// (4*1.0/3) n'est pas rendu dans ce cas !
147
-		# $this->query = str_replace('/','* 1.00 / ',$this->query);
148
-
149
-
150
-		// Correction critere REGEXP, non reconnu en sqlite2
151
-		if (($this->sqlite_version == 2) && (str_contains($this->query, 'REGEXP'))) {
152
-			$this->query = preg_replace('/([^\s\(]*)(\s*)REGEXP(\s*)([^\s\)]*)/', 'REGEXP($4, $1)', $this->query);
153
-		}
154
-
155
-		//
156
-		// 3) Remise en place des textes d'origine
157
-		//
158
-		// Correction Antiquotes et echappements
159
-		// ` => rien
160
-		if (str_contains($this->query, '`')) {
161
-			$this->query = str_replace('`', '', $this->query);
162
-		}
163
-
164
-		$this->query = query_reinjecte_textes($this->query, $textes);
165
-
166
-		return $this->query;
167
-	}
168
-
169
-	/**
170
-	 * Callback pour remplacer `DATE_` / `INTERVAL`
171
-	 * par `DATE ... strtotime`
172
-	 *
173
-	 * @param array $matches Captures
174
-	 * @return string texte de date compris par SQLite
175
-	 */
176
-	public function _remplacerDateParTime($matches) {
177
-		$op = strtoupper($matches[1] == 'ADD') ? '+' : '-';
178
-
179
-		return "datetime$matches[2] '$op$matches[3] $matches[4]')";
180
-	}
181
-
182
-	/**
183
-	 * Callback pour remplacer `FIELD(table,i,j,k...)`
184
-	 * par `CASE WHEN table=i THEN n ... ELSE 0 END`
185
-	 *
186
-	 * @param array $matches Captures
187
-	 * @return string texte de liste ordonnée compris par SQLite
188
-	 */
189
-	public function _remplacerFieldParCase($matches) {
190
-		$fields = substr((string) $matches[0], 6, -1); // ne recuperer que l'interieur X de field(X)
191
-		$t = explode(',', $fields);
192
-		$index = array_shift($t);
193
-
194
-		$res = '';
195
-		$n = 0;
196
-		foreach ($t as $v) {
197
-			$n++;
198
-			$res .= "\nWHEN $index=$v THEN $n";
199
-		}
200
-
201
-		return "CASE $res ELSE 0 END ";
202
-	}
12
+    /** Pour les corrections à effectuer sur les requêtes : array(code=>'texte') trouvé
13
+     *
14
+     * @var array
15
+     */
16
+    public $textes = [];
17
+
18
+    /**
19
+     * Constructeur
20
+     */
21
+    public function __construct(
22
+        /** Requête à préparer */
23
+        public string $query,
24
+        /** Prefixe des tables à utiliser */
25
+        public string $prefixe,
26
+        /** Version SQLite (2 ou 3) */
27
+        public string $sqlite_version
28
+    ) {
29
+    }
30
+
31
+    /**
32
+     * Transformer la requete pour SQLite
33
+     *
34
+     * Enlève les textes, transforme la requête pour quelle soit
35
+     * bien interprétée par SQLite, puis remet les textes
36
+     * la fonction affecte `$this->query`
37
+     */
38
+    public function traduire_requete() {
39
+        //
40
+        // 1) Protection des textes en les remplacant par des codes
41
+        //
42
+        // enlever les 'textes' et initialiser avec
43
+        [$this->query, $textes] = query_echappe_textes($this->query);
44
+
45
+        //
46
+        // 2) Corrections de la requete
47
+        //
48
+        // Correction Create Database
49
+        // Create Database -> requete ignoree
50
+        if (str_starts_with((string) $this->query, 'CREATE DATABASE')) {
51
+            spip_log("Sqlite : requete non executee -> $this->query", 'sqlite.' . _LOG_AVERTISSEMENT);
52
+            $this->query = 'SELECT 1';
53
+        }
54
+
55
+        // Correction Insert Ignore
56
+        // INSERT IGNORE -> insert (tout court et pas 'insert or replace')
57
+        if (str_starts_with((string) $this->query, 'INSERT IGNORE')) {
58
+            spip_log("Sqlite : requete transformee -> $this->query", 'sqlite.' . _LOG_DEBUG);
59
+            $this->query = 'INSERT ' . substr((string) $this->query, '13');
60
+        }
61
+
62
+        // Correction des dates avec INTERVAL
63
+        // utiliser sql_date_proche() de preference
64
+        if (str_contains((string) $this->query, 'INTERVAL')) {
65
+            $this->query = preg_replace_callback(
66
+                '/DATE_(ADD|SUB)(.*)INTERVAL\s+(\d+)\s+([a-zA-Z]+)\)/U',
67
+                fn(array $matches): string => $this->_remplacerDateParTime($matches),
68
+                (string) $this->query
69
+            );
70
+        }
71
+
72
+        if (str_contains((string) $this->query, 'LEFT(')) {
73
+            $this->query = str_replace('LEFT(', '_LEFT(', (string) $this->query);
74
+        }
75
+
76
+        if (str_contains((string) $this->query, 'TIMESTAMPDIFF(')) {
77
+            $this->query = preg_replace('/TIMESTAMPDIFF\(\s*([^,]*)\s*,/Uims', "TIMESTAMPDIFF('\\1',", (string) $this->query);
78
+        }
79
+
80
+
81
+        // Correction Using
82
+        // USING (non reconnu en sqlite2)
83
+        // problematique car la jointure ne se fait pas du coup.
84
+        if (($this->sqlite_version == 2) && (str_contains((string) $this->query, 'USING'))) {
85
+            spip_log(
86
+                "'USING (champ)' n'est pas reconnu en SQLite 2. Utilisez 'ON table1.champ = table2.champ'",
87
+                'sqlite.' . _LOG_ERREUR
88
+            );
89
+            $this->query = preg_replace('/USING\s*\([^\)]*\)/', '', (string) $this->query);
90
+        }
91
+
92
+        // Correction Field
93
+        // remplace FIELD(table,i,j,k...) par CASE WHEN table=i THEN n ... ELSE 0 END
94
+        if (str_contains((string) $this->query, 'FIELD')) {
95
+            $this->query = preg_replace_callback(
96
+                '/FIELD\s*\(([^\)]*)\)/',
97
+                fn(array $matches): string => $this->_remplacerFieldParCase($matches),
98
+                (string) $this->query
99
+            );
100
+        }
101
+
102
+        // Correction des noms de tables FROM
103
+        // mettre les bons noms de table dans from, update, insert, replace...
104
+        if (preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/iS', (string) $this->query, $regs)) {
105
+            $suite = strstr((string) $this->query, $regs[0]);
106
+            $this->query = substr((string) $this->query, 0, -strlen($suite));
107
+        } else {
108
+            $suite = '';
109
+        }
110
+        $pref = ($this->prefixe) ? $this->prefixe . '_' : '';
111
+        $this->query = preg_replace('/([,\s])spip_/S', '\1' . $pref, (string) $this->query) . $suite;
112
+
113
+        // Correction zero AS x
114
+        // pg n'aime pas 0+x AS alias, sqlite, dans le meme style,
115
+        // n'apprecie pas du tout SELECT 0 as x ... ORDER BY x
116
+        // il dit que x ne doit pas être un integer dans le order by !
117
+        // on remplace du coup x par vide() dans ce cas uniquement
118
+        //
119
+        // apparait dans public/vertebrer.php et dans le plugin menu aussi qui genere aussi ce genre de requete via un {par num #GET{tri_num}}
120
+        // mais est-ce encore un soucis pour sqlite en 2021 ? (ie commenter le preg_replace marche très bien en sqlite 3.28)
121
+        // on ne remplace que dans ORDER BY ou GROUP BY
122
+        if (str_contains($this->query, '0 AS') && preg_match('/\s(ORDER|GROUP) BY\s/i', $this->query, $regs)) {
123
+            $suite = strstr($this->query, $regs[0]);
124
+            $this->query = substr($this->query, 0, -strlen($suite));
125
+            // on cherche les noms des x dans 0 AS x
126
+            // on remplace dans $suite le nom par vide()
127
+            preg_match_all('/\b0 AS\s*([^\s,]+)/', $this->query, $matches, PREG_PATTERN_ORDER);
128
+            foreach ($matches[1] as $m) {
129
+                if (str_contains($suite, $m)) {
130
+                    $suite = preg_replace(",\b$m\b,", 'VIDE()', $suite);
131
+                }
132
+            }
133
+            $this->query .= $suite;
134
+        }
135
+
136
+        // Correction possible des divisions entieres
137
+        // Le standard SQL (lequel? ou?) semble indiquer que
138
+        // a/b=c doit donner c entier si a et b sont entiers 4/3=1.
139
+        // C'est ce que retournent effectivement SQL Server et SQLite
140
+        // Ce n'est pas ce qu'applique MySQL qui retourne un reel : 4/3=1.333...
141
+        //
142
+        // On peut forcer la conversion en multipliant par 1.0 avant la division
143
+        // /!\ SQLite 3.5.9 Debian/Ubuntu est victime d'un bug en plus !
144
+        // cf. https://bugs.launchpad.net/ubuntu/+source/sqlite3/+bug/254228
145
+        //     http://www.sqlite.org/cvstrac/tktview?tn=3202
146
+        // (4*1.0/3) n'est pas rendu dans ce cas !
147
+        # $this->query = str_replace('/','* 1.00 / ',$this->query);
148
+
149
+
150
+        // Correction critere REGEXP, non reconnu en sqlite2
151
+        if (($this->sqlite_version == 2) && (str_contains($this->query, 'REGEXP'))) {
152
+            $this->query = preg_replace('/([^\s\(]*)(\s*)REGEXP(\s*)([^\s\)]*)/', 'REGEXP($4, $1)', $this->query);
153
+        }
154
+
155
+        //
156
+        // 3) Remise en place des textes d'origine
157
+        //
158
+        // Correction Antiquotes et echappements
159
+        // ` => rien
160
+        if (str_contains($this->query, '`')) {
161
+            $this->query = str_replace('`', '', $this->query);
162
+        }
163
+
164
+        $this->query = query_reinjecte_textes($this->query, $textes);
165
+
166
+        return $this->query;
167
+    }
168
+
169
+    /**
170
+     * Callback pour remplacer `DATE_` / `INTERVAL`
171
+     * par `DATE ... strtotime`
172
+     *
173
+     * @param array $matches Captures
174
+     * @return string texte de date compris par SQLite
175
+     */
176
+    public function _remplacerDateParTime($matches) {
177
+        $op = strtoupper($matches[1] == 'ADD') ? '+' : '-';
178
+
179
+        return "datetime$matches[2] '$op$matches[3] $matches[4]')";
180
+    }
181
+
182
+    /**
183
+     * Callback pour remplacer `FIELD(table,i,j,k...)`
184
+     * par `CASE WHEN table=i THEN n ... ELSE 0 END`
185
+     *
186
+     * @param array $matches Captures
187
+     * @return string texte de liste ordonnée compris par SQLite
188
+     */
189
+    public function _remplacerFieldParCase($matches) {
190
+        $fields = substr((string) $matches[0], 6, -1); // ne recuperer que l'interieur X de field(X)
191
+        $t = explode(',', $fields);
192
+        $index = array_shift($t);
193
+
194
+        $res = '';
195
+        $n = 0;
196
+        foreach ($t as $v) {
197
+            $n++;
198
+            $res .= "\nWHEN $index=$v THEN $n";
199
+        }
200
+
201
+        return "CASE $res ELSE 0 END ";
202
+    }
203 203
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -48,15 +48,15 @@  discard block
 block discarded – undo
48 48
 		// Correction Create Database
49 49
 		// Create Database -> requete ignoree
50 50
 		if (str_starts_with((string) $this->query, 'CREATE DATABASE')) {
51
-			spip_log("Sqlite : requete non executee -> $this->query", 'sqlite.' . _LOG_AVERTISSEMENT);
51
+			spip_log("Sqlite : requete non executee -> $this->query", 'sqlite.'._LOG_AVERTISSEMENT);
52 52
 			$this->query = 'SELECT 1';
53 53
 		}
54 54
 
55 55
 		// Correction Insert Ignore
56 56
 		// INSERT IGNORE -> insert (tout court et pas 'insert or replace')
57 57
 		if (str_starts_with((string) $this->query, 'INSERT IGNORE')) {
58
-			spip_log("Sqlite : requete transformee -> $this->query", 'sqlite.' . _LOG_DEBUG);
59
-			$this->query = 'INSERT ' . substr((string) $this->query, '13');
58
+			spip_log("Sqlite : requete transformee -> $this->query", 'sqlite.'._LOG_DEBUG);
59
+			$this->query = 'INSERT '.substr((string) $this->query, '13');
60 60
 		}
61 61
 
62 62
 		// Correction des dates avec INTERVAL
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 		if (($this->sqlite_version == 2) && (str_contains((string) $this->query, 'USING'))) {
85 85
 			spip_log(
86 86
 				"'USING (champ)' n'est pas reconnu en SQLite 2. Utilisez 'ON table1.champ = table2.champ'",
87
-				'sqlite.' . _LOG_ERREUR
87
+				'sqlite.'._LOG_ERREUR
88 88
 			);
89 89
 			$this->query = preg_replace('/USING\s*\([^\)]*\)/', '', (string) $this->query);
90 90
 		}
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 		} else {
108 108
 			$suite = '';
109 109
 		}
110
-		$pref = ($this->prefixe) ? $this->prefixe . '_' : '';
111
-		$this->query = preg_replace('/([,\s])spip_/S', '\1' . $pref, (string) $this->query) . $suite;
110
+		$pref = ($this->prefixe) ? $this->prefixe.'_' : '';
111
+		$this->query = preg_replace('/([,\s])spip_/S', '\1'.$pref, (string) $this->query).$suite;
112 112
 
113 113
 		// Correction zero AS x
114 114
 		// pg n'aime pas 0+x AS alias, sqlite, dans le meme style,
Please login to merge, or discard this patch.
ecrire/src/Texte/Collecteur/Liens.php 1 patch
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -15,98 +15,98 @@
 block discarded – undo
15 15
  *    Collecte les raccourcis liens [titre->url] de SPIP
16 16
  */
17 17
 class Liens extends AbstractCollecteur {
18
-	protected static string $markPrefix = 'LIEN';
19
-
20
-	/**
21
-	 * La preg pour découper et collecter les modèles
22
-	 * @var string
23
-	 */
24
-	protected string $preg_lien;
25
-
26
-	public function __construct(?string $preg = null) {
27
-
28
-		// Regexp des raccourcis, aussi utilisee pour la fusion de sauvegarde Spip
29
-		// Laisser passer des paires de crochets pour la balise multi
30
-		// mais refuser plus d'imbrications ou de mauvaises imbrications
31
-		// sinon les crochets ne peuvent plus servir qu'a ce type de raccourci
32
-		$this->preg_lien = ($preg ?: '/\[([^][]*?([[][^]>-]*[]][^][]*)*)->(>?)([^]]*)\]/msS');
33
-	}
34
-
35
-
36
-	/**
37
-	 * Sanitizer une collection d'occurences de liens : il faut sanitizer le href et le texte uniquement
38
-	 *
39
-	 * @param array $collection
40
-	 * @param string $sanitize_callback
41
-	 * @return array
42
-	 */
43
-	protected function sanitizer_collection(array $collection, string $sanitize_callback): array {
44
-		foreach ($collection as &$lien) {
45
-			$t = $sanitize_callback($lien['texte']);
46
-			if ($t !== $lien['texte']) {
47
-				$lien['raw'] = str_replace($lien['texte'], $t, (string) $lien['raw']);
48
-				$lien['texte'] = $t;
49
-			}
50
-			$href = $sanitize_callback($lien['href']);
51
-			if ($href !== $lien['href']) {
52
-				$lien['raw'] = str_replace($lien['href'], $href, (string) $lien['raw']);
53
-				$lien['href'] = $href;
54
-			}
55
-		}
56
-
57
-		return $collection;
58
-	}
59
-
60
-	/**
61
-	 * @param string $texte
62
-	 * @param array $options
63
-	 *   bool $collecter_liens
64
-	 * @return array
65
-	 */
66
-	public function collecter(string $texte, array $options = []): array {
67
-		if (!$texte) {
68
-			return [];
69
-		}
70
-
71
-		$liens = [];
72
-		if (str_contains($texte, '->')) {
73
-			$desechappe_crochets = false;
74
-			// si il y a un crochet ouvrant échappé ou un crochet fermant échappé, les substituer pour les ignorer
75
-			if (str_contains($texte, '\[') || str_contains($texte, '\]')) {
76
-				$texte = str_replace(['\[', '\]'], ["\x1\x5", "\x1\x6"], $texte);
77
-				$desechappe_crochets = true;
78
-			}
79
-
80
-			// collecter les matchs de la preg
81
-			$liens = static::collecteur($texte, '->', '[', $this->preg_lien, empty($options['detecter_presence']) ? 0 : 1);
82
-
83
-			// si on veut seulement detecter la présence, on peut retourner tel quel
84
-			if (empty($options['detecter_presence'])) {
85
-				foreach ($liens as $k => &$lien) {
86
-					$lien['href'] = end($lien['match']);
87
-					$lien['texte'] = $lien['match'][1];
88
-					$lien['ouvrant'] = $lien['match'][3] ?? '';
89
-
90
-					// la mise en lien automatique est passee par la a tort !
91
-					// corrigeons pour eviter d'avoir un <a...> dans un href...
92
-					if (str_starts_with((string) $lien['href'], '<a')) {
93
-						$href = extraire_attribut($lien['href'], 'href');
94
-						// remplacons dans la source qui peut etre reinjectee dans les arguments
95
-						// d'un modele
96
-						$lien['raw'] = str_replace($lien['href'], $href, (string) $lien['raw']);
97
-						// et prenons le href comme la vraie url a linker
98
-						$lien['href'] = $href;
99
-					}
100
-
101
-					if ($desechappe_crochets && str_contains((string) $lien['raw'], "\x1")) {
102
-						$lien['raw'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], (string) $lien['raw']);
103
-						$lien['texte'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], (string) $lien['texte']);
104
-						$lien['href'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], (string) $lien['href']);
105
-					}
106
-				}
107
-			}
108
-		}
109
-
110
-		return $liens;
111
-	}
18
+    protected static string $markPrefix = 'LIEN';
19
+
20
+    /**
21
+     * La preg pour découper et collecter les modèles
22
+     * @var string
23
+     */
24
+    protected string $preg_lien;
25
+
26
+    public function __construct(?string $preg = null) {
27
+
28
+        // Regexp des raccourcis, aussi utilisee pour la fusion de sauvegarde Spip
29
+        // Laisser passer des paires de crochets pour la balise multi
30
+        // mais refuser plus d'imbrications ou de mauvaises imbrications
31
+        // sinon les crochets ne peuvent plus servir qu'a ce type de raccourci
32
+        $this->preg_lien = ($preg ?: '/\[([^][]*?([[][^]>-]*[]][^][]*)*)->(>?)([^]]*)\]/msS');
33
+    }
34
+
35
+
36
+    /**
37
+     * Sanitizer une collection d'occurences de liens : il faut sanitizer le href et le texte uniquement
38
+     *
39
+     * @param array $collection
40
+     * @param string $sanitize_callback
41
+     * @return array
42
+     */
43
+    protected function sanitizer_collection(array $collection, string $sanitize_callback): array {
44
+        foreach ($collection as &$lien) {
45
+            $t = $sanitize_callback($lien['texte']);
46
+            if ($t !== $lien['texte']) {
47
+                $lien['raw'] = str_replace($lien['texte'], $t, (string) $lien['raw']);
48
+                $lien['texte'] = $t;
49
+            }
50
+            $href = $sanitize_callback($lien['href']);
51
+            if ($href !== $lien['href']) {
52
+                $lien['raw'] = str_replace($lien['href'], $href, (string) $lien['raw']);
53
+                $lien['href'] = $href;
54
+            }
55
+        }
56
+
57
+        return $collection;
58
+    }
59
+
60
+    /**
61
+     * @param string $texte
62
+     * @param array $options
63
+     *   bool $collecter_liens
64
+     * @return array
65
+     */
66
+    public function collecter(string $texte, array $options = []): array {
67
+        if (!$texte) {
68
+            return [];
69
+        }
70
+
71
+        $liens = [];
72
+        if (str_contains($texte, '->')) {
73
+            $desechappe_crochets = false;
74
+            // si il y a un crochet ouvrant échappé ou un crochet fermant échappé, les substituer pour les ignorer
75
+            if (str_contains($texte, '\[') || str_contains($texte, '\]')) {
76
+                $texte = str_replace(['\[', '\]'], ["\x1\x5", "\x1\x6"], $texte);
77
+                $desechappe_crochets = true;
78
+            }
79
+
80
+            // collecter les matchs de la preg
81
+            $liens = static::collecteur($texte, '->', '[', $this->preg_lien, empty($options['detecter_presence']) ? 0 : 1);
82
+
83
+            // si on veut seulement detecter la présence, on peut retourner tel quel
84
+            if (empty($options['detecter_presence'])) {
85
+                foreach ($liens as $k => &$lien) {
86
+                    $lien['href'] = end($lien['match']);
87
+                    $lien['texte'] = $lien['match'][1];
88
+                    $lien['ouvrant'] = $lien['match'][3] ?? '';
89
+
90
+                    // la mise en lien automatique est passee par la a tort !
91
+                    // corrigeons pour eviter d'avoir un <a...> dans un href...
92
+                    if (str_starts_with((string) $lien['href'], '<a')) {
93
+                        $href = extraire_attribut($lien['href'], 'href');
94
+                        // remplacons dans la source qui peut etre reinjectee dans les arguments
95
+                        // d'un modele
96
+                        $lien['raw'] = str_replace($lien['href'], $href, (string) $lien['raw']);
97
+                        // et prenons le href comme la vraie url a linker
98
+                        $lien['href'] = $href;
99
+                    }
100
+
101
+                    if ($desechappe_crochets && str_contains((string) $lien['raw'], "\x1")) {
102
+                        $lien['raw'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], (string) $lien['raw']);
103
+                        $lien['texte'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], (string) $lien['texte']);
104
+                        $lien['href'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], (string) $lien['href']);
105
+                    }
106
+                }
107
+            }
108
+        }
109
+
110
+        return $liens;
111
+    }
112 112
 }
Please login to merge, or discard this patch.
ecrire/src/Afficher/Minipage/AbstractPage.php 2 patches
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -65,17 +65,17 @@  discard block
 block discarded – undo
65 65
 
66 66
 		$page_title = ($options['page_title'] ?? $GLOBALS['meta']['nom_site']);
67 67
 		$doctype = ($options['doctype'] ?? '<!DOCTYPE html>');
68
-		$doctype = trim((string) $doctype) . "\n";
68
+		$doctype = trim((string) $doctype)."\n";
69 69
 		$charset = ($options['charset'] ?? 'utf-8');
70 70
 		$all_inline = ($options['all_inline'] ?? true);
71 71
 		$onLoad = ($options['onLoad'] ?? '');
72 72
 		if ($onLoad) {
73
-			$onLoad = ' onload="' . attribut_html($onLoad) . '"';
73
+			$onLoad = ' onload="'.attribut_html($onLoad).'"';
74 74
 		}
75 75
 
76 76
 		# envoyer le charset
77 77
 		if (!headers_sent()) {
78
-			header('Content-Type: text/html; charset=' . $charset);
78
+			header('Content-Type: text/html; charset='.$charset);
79 79
 		}
80 80
 
81 81
 		$css = '';
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 			. "--minipage-color-theme--s: $s;"
95 95
 			. "--minipage-color-theme--l: $l;}";
96 96
 		$vars = file_get_contents(find_in_theme('minipage.vars.css'));
97
-		$inline .= "\n" . trim($vars);
97
+		$inline .= "\n".trim($vars);
98 98
 		if (function_exists('minifier')) {
99 99
 			$inline = minifier($inline, 'css');
100 100
 		}
@@ -121,31 +121,31 @@  discard block
 block discarded – undo
121 121
 			}
122 122
 			$css = "$inline\n$css";
123 123
 			if (!empty($options['css'])) {
124
-				$css .= "\n" . $options['css'];
124
+				$css .= "\n".$options['css'];
125 125
 			}
126 126
 			$css = "<style type='text/css'>$css</style>";
127 127
 		} else {
128 128
 			$css = "<style type='text/css'>$inline</style>";
129 129
 			foreach ($files as $name) {
130 130
 				$file = timestamp(direction_css($name));
131
-				$css .= "<link rel='stylesheet' href='" . attribut_html($file) . "' type='text/css' />\n";
131
+				$css .= "<link rel='stylesheet' href='".attribut_html($file)."' type='text/css' />\n";
132 132
 			}
133 133
 			if (!empty($options['css'])) {
134
-				$css .= "<style type='text/css'>" . $options['css'] . '</style>';
134
+				$css .= "<style type='text/css'>".$options['css'].'</style>';
135 135
 			}
136 136
 		}
137 137
 
138
-		return $doctype .
139
-			html_lang_attributes() .
140
-			"<head>\n" .
141
-			'<title>' .
142
-			textebrut($page_title) .
143
-			"</title>\n" .
144
-			"<meta name=\"viewport\" content=\"width=device-width\" />\n" .
145
-			$css .
146
-			(empty($options['head']) ? '' : $options['head']) .
147
-			"</head>\n" .
148
-			"<body{$onLoad} class=\"minipage" . ($this::TYPE ? ' minipage--' . $this::TYPE : '') . "\">\n" .
138
+		return $doctype.
139
+			html_lang_attributes().
140
+			"<head>\n".
141
+			'<title>'.
142
+			textebrut($page_title).
143
+			"</title>\n".
144
+			"<meta name=\"viewport\" content=\"width=device-width\" />\n".
145
+			$css.
146
+			(empty($options['head']) ? '' : $options['head']).
147
+			"</head>\n".
148
+			"<body{$onLoad} class=\"minipage".($this::TYPE ? ' minipage--'.$this::TYPE : '')."\">\n".
149 149
 			"\t<div class=\"minipage-bloc\">\n";
150 150
 	}
151 151
 
@@ -156,16 +156,16 @@  discard block
 block discarded – undo
156 156
 	 */
157 157
 	protected function ouvreCorps($options = []) {
158 158
 		$url_site = url_de_base();
159
-		$header = "<header>\n" .
160
-			'<h1><a href="' . attribut_html($url_site) . '">' . interdire_scripts($GLOBALS['meta']['nom_site'] ?? '') . "</a></h1>\n";
159
+		$header = "<header>\n".
160
+			'<h1><a href="'.attribut_html($url_site).'">'.interdire_scripts($GLOBALS['meta']['nom_site'] ?? '')."</a></h1>\n";
161 161
 
162 162
 		$titre = ($options['titre'] ?? '');
163 163
 		if ($titre) {
164
-			$header .= '<h2>' . interdire_scripts($titre) . '</h2>';
164
+			$header .= '<h2>'.interdire_scripts($titre).'</h2>';
165 165
 		}
166 166
 		$header .= '</header>';
167 167
 
168
-		return $header . "<div class='corps'>\n";
168
+		return $header."<div class='corps'>\n";
169 169
 	}
170 170
 
171 171
 	/**
@@ -179,13 +179,13 @@  discard block
 block discarded – undo
179 179
 		if (isset($options['footer'])) {
180 180
 			$footer = $options['footer'];
181 181
 		} else {
182
-			$footer = '<a href="' . attribut_html($url_site) . '">' . _T('retour') . "</a>\n";
182
+			$footer = '<a href="'.attribut_html($url_site).'">'._T('retour')."</a>\n";
183 183
 		}
184 184
 		if (!empty($footer)) {
185 185
 			$footer = "<footer>\n{$footer}</footer>";
186 186
 		}
187 187
 
188
-		return "</div>\n" . $footer;
188
+		return "</div>\n".$footer;
189 189
 	}
190 190
 
191 191
 
Please login to merge, or discard this patch.
Indentation   +236 added lines, -236 removed lines patch added patch discarded remove patch
@@ -15,265 +15,265 @@
 block discarded – undo
15 15
  * Présentation des pages simplifiées
16 16
  **/
17 17
 abstract class AbstractPage {
18
-	public const TYPE = '';
18
+    public const TYPE = '';
19 19
 
20
-	public function __construct() {
21
-		include_fichiers_fonctions();
22
-		include_spip('inc/headers');
23
-		include_spip('inc/texte'); //inclue inc/lang et inc/filtres
24
-		include_spip('inc/filtres_images_mini');
25
-	}
20
+    public function __construct() {
21
+        include_fichiers_fonctions();
22
+        include_spip('inc/headers');
23
+        include_spip('inc/texte'); //inclue inc/lang et inc/filtres
24
+        include_spip('inc/filtres_images_mini');
25
+    }
26 26
 
27
-	/**
28
-	 * Retourne le début d'une page HTML minimale
29
-	 *
30
-	 * Le contenu de CSS minimales (reset.css, clear.css, minipage.css) est inséré
31
-	 * dans une balise script inline (compactée si possible)
32
-	 *
33
-	 * @param array $options
34
-	 *   string $lang : forcer la langue utilisateur
35
-	 *   string $page_title : titre éventuel de la page (nom du site par défaut)
36
-	 *   string $couleur_fond : pour la couleur dominante de la page (par défaut on reprend le réglage de la page de login)
37
-	 *   bool $all_inline : inliner les CSS pour envoyer toute la page en 1 hit
38
-	 *   string $doctype
39
-	 *   string $charset
40
-	 *   string $onload
41
-	 *   array $css_files : ajouter des fichiers css
42
-	 *   string $css : ajouter du CSS inline
43
-	 *   string $head : contenu à ajouter à la fin <head> (pour inclusion de JS ou JS inline...)
44
-	 * @return string
45
-	 *    Code HTML
46
-	 *
47
-	 * @uses html_lang_attributes()
48
-	 * @uses minifier() si le plugin compresseur est présent
49
-	 * @uses url_absolue_css()
50
-	 *
51
-	 * @uses utiliser_langue_visiteur()
52
-	 * @uses http_no_cache()
53
-	 */
54
-	protected function ouvreBody($options = []) {
55
-		$h = null;
56
-		$s = null;
57
-		$l = null;
58
-		if (empty($options['lang'])) {
59
-			// on se limite sur une langue de $GLOBALS['meta']['langues_multilingue'] car on est dans le public
60
-			utiliser_langue_visiteur($GLOBALS['meta']['langues_multilingue'] ?? null);
61
-		} else {
62
-			changer_langue($options['lang']);
63
-		}
64
-		http_no_cache();
27
+    /**
28
+     * Retourne le début d'une page HTML minimale
29
+     *
30
+     * Le contenu de CSS minimales (reset.css, clear.css, minipage.css) est inséré
31
+     * dans une balise script inline (compactée si possible)
32
+     *
33
+     * @param array $options
34
+     *   string $lang : forcer la langue utilisateur
35
+     *   string $page_title : titre éventuel de la page (nom du site par défaut)
36
+     *   string $couleur_fond : pour la couleur dominante de la page (par défaut on reprend le réglage de la page de login)
37
+     *   bool $all_inline : inliner les CSS pour envoyer toute la page en 1 hit
38
+     *   string $doctype
39
+     *   string $charset
40
+     *   string $onload
41
+     *   array $css_files : ajouter des fichiers css
42
+     *   string $css : ajouter du CSS inline
43
+     *   string $head : contenu à ajouter à la fin <head> (pour inclusion de JS ou JS inline...)
44
+     * @return string
45
+     *    Code HTML
46
+     *
47
+     * @uses html_lang_attributes()
48
+     * @uses minifier() si le plugin compresseur est présent
49
+     * @uses url_absolue_css()
50
+     *
51
+     * @uses utiliser_langue_visiteur()
52
+     * @uses http_no_cache()
53
+     */
54
+    protected function ouvreBody($options = []) {
55
+        $h = null;
56
+        $s = null;
57
+        $l = null;
58
+        if (empty($options['lang'])) {
59
+            // on se limite sur une langue de $GLOBALS['meta']['langues_multilingue'] car on est dans le public
60
+            utiliser_langue_visiteur($GLOBALS['meta']['langues_multilingue'] ?? null);
61
+        } else {
62
+            changer_langue($options['lang']);
63
+        }
64
+        http_no_cache();
65 65
 
66
-		$page_title = ($options['page_title'] ?? $GLOBALS['meta']['nom_site']);
67
-		$doctype = ($options['doctype'] ?? '<!DOCTYPE html>');
68
-		$doctype = trim((string) $doctype) . "\n";
69
-		$charset = ($options['charset'] ?? 'utf-8');
70
-		$all_inline = ($options['all_inline'] ?? true);
71
-		$onLoad = ($options['onLoad'] ?? '');
72
-		if ($onLoad) {
73
-			$onLoad = ' onload="' . attribut_html($onLoad) . '"';
74
-		}
66
+        $page_title = ($options['page_title'] ?? $GLOBALS['meta']['nom_site']);
67
+        $doctype = ($options['doctype'] ?? '<!DOCTYPE html>');
68
+        $doctype = trim((string) $doctype) . "\n";
69
+        $charset = ($options['charset'] ?? 'utf-8');
70
+        $all_inline = ($options['all_inline'] ?? true);
71
+        $onLoad = ($options['onLoad'] ?? '');
72
+        if ($onLoad) {
73
+            $onLoad = ' onload="' . attribut_html($onLoad) . '"';
74
+        }
75 75
 
76
-		# envoyer le charset
77
-		if (!headers_sent()) {
78
-			header('Content-Type: text/html; charset=' . $charset);
79
-		}
76
+        # envoyer le charset
77
+        if (!headers_sent()) {
78
+            header('Content-Type: text/html; charset=' . $charset);
79
+        }
80 80
 
81
-		$css = '';
81
+        $css = '';
82 82
 
83
-		if (function_exists('couleur_hex_to_hsl')) {
84
-			$couleur_fond = empty($options['couleur_fond'])
85
-				? lire_config('couleur_login', '#db1762')
86
-				: $options['couleur_fond'];
87
-			$h = couleur_hex_to_hsl($couleur_fond, 'h');
88
-			$s = couleur_hex_to_hsl($couleur_fond, 's');
89
-			$l = couleur_hex_to_hsl($couleur_fond, 'l');
90
-		}
83
+        if (function_exists('couleur_hex_to_hsl')) {
84
+            $couleur_fond = empty($options['couleur_fond'])
85
+                ? lire_config('couleur_login', '#db1762')
86
+                : $options['couleur_fond'];
87
+            $h = couleur_hex_to_hsl($couleur_fond, 'h');
88
+            $s = couleur_hex_to_hsl($couleur_fond, 's');
89
+            $l = couleur_hex_to_hsl($couleur_fond, 'l');
90
+        }
91 91
 
92
-		$inline = ':root {'
93
-			. "--minipage-color-theme--h: $h;"
94
-			. "--minipage-color-theme--s: $s;"
95
-			. "--minipage-color-theme--l: $l;}";
96
-		$vars = file_get_contents(find_in_theme('minipage.vars.css'));
97
-		$inline .= "\n" . trim($vars);
98
-		if (function_exists('minifier')) {
99
-			$inline = minifier($inline, 'css');
100
-		}
101
-		$files = [
102
-			find_in_theme('reset.css'),
103
-			find_in_theme('clear.css'),
104
-			find_in_theme('minipage.css'),
105
-		];
106
-		if (!empty($options['css_files'])) {
107
-			foreach ($options['css_files'] as $css_file) {
108
-				$files[] = $css_file;
109
-			}
110
-		}
111
-		if ($all_inline) {
112
-			// inliner les CSS (optimisation de la page minipage qui passe en un seul hit a la demande)
113
-			foreach ($files as $name) {
114
-				$file = direction_css($name);
115
-				if (function_exists('minifier')) {
116
-					$file = minifier($file);
117
-				} else {
118
-					$file = url_absolue_css($file); // precaution
119
-				}
120
-				$css .= file_get_contents($file);
121
-			}
122
-			$css = "$inline\n$css";
123
-			if (!empty($options['css'])) {
124
-				$css .= "\n" . $options['css'];
125
-			}
126
-			$css = "<style type='text/css'>$css</style>";
127
-		} else {
128
-			$css = "<style type='text/css'>$inline</style>";
129
-			foreach ($files as $name) {
130
-				$file = timestamp(direction_css($name));
131
-				$css .= "<link rel='stylesheet' href='" . attribut_html($file) . "' type='text/css' />\n";
132
-			}
133
-			if (!empty($options['css'])) {
134
-				$css .= "<style type='text/css'>" . $options['css'] . '</style>';
135
-			}
136
-		}
92
+        $inline = ':root {'
93
+            . "--minipage-color-theme--h: $h;"
94
+            . "--minipage-color-theme--s: $s;"
95
+            . "--minipage-color-theme--l: $l;}";
96
+        $vars = file_get_contents(find_in_theme('minipage.vars.css'));
97
+        $inline .= "\n" . trim($vars);
98
+        if (function_exists('minifier')) {
99
+            $inline = minifier($inline, 'css');
100
+        }
101
+        $files = [
102
+            find_in_theme('reset.css'),
103
+            find_in_theme('clear.css'),
104
+            find_in_theme('minipage.css'),
105
+        ];
106
+        if (!empty($options['css_files'])) {
107
+            foreach ($options['css_files'] as $css_file) {
108
+                $files[] = $css_file;
109
+            }
110
+        }
111
+        if ($all_inline) {
112
+            // inliner les CSS (optimisation de la page minipage qui passe en un seul hit a la demande)
113
+            foreach ($files as $name) {
114
+                $file = direction_css($name);
115
+                if (function_exists('minifier')) {
116
+                    $file = minifier($file);
117
+                } else {
118
+                    $file = url_absolue_css($file); // precaution
119
+                }
120
+                $css .= file_get_contents($file);
121
+            }
122
+            $css = "$inline\n$css";
123
+            if (!empty($options['css'])) {
124
+                $css .= "\n" . $options['css'];
125
+            }
126
+            $css = "<style type='text/css'>$css</style>";
127
+        } else {
128
+            $css = "<style type='text/css'>$inline</style>";
129
+            foreach ($files as $name) {
130
+                $file = timestamp(direction_css($name));
131
+                $css .= "<link rel='stylesheet' href='" . attribut_html($file) . "' type='text/css' />\n";
132
+            }
133
+            if (!empty($options['css'])) {
134
+                $css .= "<style type='text/css'>" . $options['css'] . '</style>';
135
+            }
136
+        }
137 137
 
138
-		return $doctype .
139
-			html_lang_attributes() .
140
-			"<head>\n" .
141
-			'<title>' .
142
-			textebrut($page_title) .
143
-			"</title>\n" .
144
-			"<meta name=\"viewport\" content=\"width=device-width\" />\n" .
145
-			$css .
146
-			(empty($options['head']) ? '' : $options['head']) .
147
-			"</head>\n" .
148
-			"<body{$onLoad} class=\"minipage" . ($this::TYPE ? ' minipage--' . $this::TYPE : '') . "\">\n" .
149
-			"\t<div class=\"minipage-bloc\">\n";
150
-	}
138
+        return $doctype .
139
+            html_lang_attributes() .
140
+            "<head>\n" .
141
+            '<title>' .
142
+            textebrut($page_title) .
143
+            "</title>\n" .
144
+            "<meta name=\"viewport\" content=\"width=device-width\" />\n" .
145
+            $css .
146
+            (empty($options['head']) ? '' : $options['head']) .
147
+            "</head>\n" .
148
+            "<body{$onLoad} class=\"minipage" . ($this::TYPE ? ' minipage--' . $this::TYPE : '') . "\">\n" .
149
+            "\t<div class=\"minipage-bloc\">\n";
150
+    }
151 151
 
152
-	/**
153
-	 * Ouvre le corps : affiche le header avec un éventuel titre + ouvre le div corps
154
-	 * @param array options
155
-	 * @return string
156
-	 */
157
-	protected function ouvreCorps($options = []) {
158
-		$url_site = url_de_base();
159
-		$header = "<header>\n" .
160
-			'<h1><a href="' . attribut_html($url_site) . '">' . interdire_scripts($GLOBALS['meta']['nom_site'] ?? '') . "</a></h1>\n";
152
+    /**
153
+     * Ouvre le corps : affiche le header avec un éventuel titre + ouvre le div corps
154
+     * @param array options
155
+     * @return string
156
+     */
157
+    protected function ouvreCorps($options = []) {
158
+        $url_site = url_de_base();
159
+        $header = "<header>\n" .
160
+            '<h1><a href="' . attribut_html($url_site) . '">' . interdire_scripts($GLOBALS['meta']['nom_site'] ?? '') . "</a></h1>\n";
161 161
 
162
-		$titre = ($options['titre'] ?? '');
163
-		if ($titre) {
164
-			$header .= '<h2>' . interdire_scripts($titre) . '</h2>';
165
-		}
166
-		$header .= '</header>';
162
+        $titre = ($options['titre'] ?? '');
163
+        if ($titre) {
164
+            $header .= '<h2>' . interdire_scripts($titre) . '</h2>';
165
+        }
166
+        $header .= '</header>';
167 167
 
168
-		return $header . "<div class='corps'>\n";
169
-	}
168
+        return $header . "<div class='corps'>\n";
169
+    }
170 170
 
171
-	/**
172
-	 * Ferme le corps : affiche le footer par défaut ou custom et ferme le div corps
173
-	 * @param array $options
174
-	 * @return string
175
-	 */
176
-	protected function fermeCorps($options = []) {
177
-		$url_site = url_de_base();
171
+    /**
172
+     * Ferme le corps : affiche le footer par défaut ou custom et ferme le div corps
173
+     * @param array $options
174
+     * @return string
175
+     */
176
+    protected function fermeCorps($options = []) {
177
+        $url_site = url_de_base();
178 178
 
179
-		if (isset($options['footer'])) {
180
-			$footer = $options['footer'];
181
-		} else {
182
-			$footer = '<a href="' . attribut_html($url_site) . '">' . _T('retour') . "</a>\n";
183
-		}
184
-		if (!empty($footer)) {
185
-			$footer = "<footer>\n{$footer}</footer>";
186
-		}
179
+        if (isset($options['footer'])) {
180
+            $footer = $options['footer'];
181
+        } else {
182
+            $footer = '<a href="' . attribut_html($url_site) . '">' . _T('retour') . "</a>\n";
183
+        }
184
+        if (!empty($footer)) {
185
+            $footer = "<footer>\n{$footer}</footer>";
186
+        }
187 187
 
188
-		return "</div>\n" . $footer;
189
-	}
188
+        return "</div>\n" . $footer;
189
+    }
190 190
 
191 191
 
192
-	/**
193
-	 * Retourne la fin d'une page HTML minimale
194
-	 *
195
-	 * @return string Code HTML
196
-	 */
197
-	protected function fermeBody() {
198
-		return "\n\t</div>\n</body>\n</html>";
199
-	}
192
+    /**
193
+     * Retourne la fin d'une page HTML minimale
194
+     *
195
+     * @return string Code HTML
196
+     */
197
+    protected function fermeBody() {
198
+        return "\n\t</div>\n</body>\n</html>";
199
+    }
200 200
 
201 201
 
202
-	/**
203
-	 * Retourne une page HTML contenant, dans une présentation minimale,
204
-	 * le contenu transmis dans `$corps`.
205
-	 *
206
-	 * Appelée pour afficher un message ou une demande de confirmation simple et rapide
207
-	 *
208
-	 * @param string $corps
209
-	 *   Corps de la page
210
-	 * @param array $options
211
-	 * @return string
212
-	 *   HTML de la page
213
-	 * @see  ouvreBody()
214
-	 * @see  ouvreCorps()
215
-	 *   string $titre : Titre à l'affichage (différent de $page_title)
216
-	 *   int $status : status de la page
217
-	 *   string $footer : pied de la box en remplacement du bouton retour par défaut
218
-	 * @uses ouvreBody()
219
-	 * @uses ouvreCorps()
220
-	 * @uses fermeCorps()
221
-	 * @uses fermeBody()
222
-	 *
223
-	 */
224
-	public function page($corps, $options = []) {
202
+    /**
203
+     * Retourne une page HTML contenant, dans une présentation minimale,
204
+     * le contenu transmis dans `$corps`.
205
+     *
206
+     * Appelée pour afficher un message ou une demande de confirmation simple et rapide
207
+     *
208
+     * @param string $corps
209
+     *   Corps de la page
210
+     * @param array $options
211
+     * @return string
212
+     *   HTML de la page
213
+     * @see  ouvreBody()
214
+     * @see  ouvreCorps()
215
+     *   string $titre : Titre à l'affichage (différent de $page_title)
216
+     *   int $status : status de la page
217
+     *   string $footer : pied de la box en remplacement du bouton retour par défaut
218
+     * @uses ouvreBody()
219
+     * @uses ouvreCorps()
220
+     * @uses fermeCorps()
221
+     * @uses fermeBody()
222
+     *
223
+     */
224
+    public function page($corps, $options = []) {
225 225
 
226
-		// par securite
227
-		if (!defined('_AJAX')) {
228
-			define('_AJAX', false);
229
-		}
226
+        // par securite
227
+        if (!defined('_AJAX')) {
228
+            define('_AJAX', false);
229
+        }
230 230
 
231
-		$status = ((int) ($options['status'] ?? 200)) ?: 200;
231
+        $status = ((int) ($options['status'] ?? 200)) ?: 200;
232 232
 
233
-		http_response_code($status);
233
+        http_response_code($status);
234 234
 
235
-		$html = $this->ouvreBody($options)
236
-			. $this->ouvreCorps($options)
237
-			. $corps
238
-			. $this->fermeCorps($options)
239
-			. $this->fermeBody();
235
+        $html = $this->ouvreBody($options)
236
+            . $this->ouvreCorps($options)
237
+            . $corps
238
+            . $this->fermeCorps($options)
239
+            . $this->fermeBody();
240 240
 
241
-		if (
242
-			$GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2)
243
-			&& empty($options['all_inline'])
244
-		) {
245
-			define('_SET_HTML_BASE', true);
246
-			include_spip('public/assembler');
247
-			$GLOBALS['html'] = true;
248
-			page_base_href($html);
249
-		}
250
-		return $html;
251
-	}
241
+        if (
242
+            $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2)
243
+            && empty($options['all_inline'])
244
+        ) {
245
+            define('_SET_HTML_BASE', true);
246
+            include_spip('public/assembler');
247
+            $GLOBALS['html'] = true;
248
+            page_base_href($html);
249
+        }
250
+        return $html;
251
+    }
252 252
 
253
-	/**
254
-	 * Fonction helper pour les erreurs
255
-	 * @param ?string $message_erreur
256
-	 * @param array $options
257
-	 * @see page()
258
-	 * @return string
259
-	 *
260
-	 */
261
-	public function pageErreur($message_erreur = null, $options = []) {
253
+    /**
254
+     * Fonction helper pour les erreurs
255
+     * @param ?string $message_erreur
256
+     * @param array $options
257
+     * @see page()
258
+     * @return string
259
+     *
260
+     */
261
+    public function pageErreur($message_erreur = null, $options = []) {
262 262
 
263
-		if (empty($message_erreur)) {
264
-			if (empty($options['lang'])) {
265
-				utiliser_langue_visiteur();
266
-			} else {
267
-				changer_langue($options['lang']);
268
-			}
269
-			$message_erreur = _T('info_acces_interdit');
270
-		}
271
-		$corps = "<div class='msg-alert error'>"
272
-			. $message_erreur
273
-			. '</div>';
274
-		if (empty($options['status'])) {
275
-			$options['status'] = 403;
276
-		}
277
-		return $this->page($corps, $options);
278
-	}
263
+        if (empty($message_erreur)) {
264
+            if (empty($options['lang'])) {
265
+                utiliser_langue_visiteur();
266
+            } else {
267
+                changer_langue($options['lang']);
268
+            }
269
+            $message_erreur = _T('info_acces_interdit');
270
+        }
271
+        $corps = "<div class='msg-alert error'>"
272
+            . $message_erreur
273
+            . '</div>';
274
+        if (empty($options['status'])) {
275
+            $options['status'] = 403;
276
+        }
277
+        return $this->page($corps, $options);
278
+    }
279 279
 }
Please login to merge, or discard this patch.
ecrire/src/Compilateur/Iterateur/Decorator.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 				return $this->iter->{$nom}();
136 136
 			} catch (Exception) {
137 137
 				// #GETCHILDREN sur un fichier de DirectoryIterator ...
138
-				spip_log("Methode {$nom} en echec sur " . $this->iter::class);
138
+				spip_log("Methode {$nom} en echec sur ".$this->iter::class);
139 139
 				spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode");
140 140
 
141 141
 				return '';
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 			return null;
357 357
 		}
358 358
 
359
-		return '(' . implode(") {$operateur} (", $filtres_string) . ')';
359
+		return '('.implode(") {$operateur} (", $filtres_string).')';
360 360
 	}
361 361
 
362 362
 	/**
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 			return $this->composer_filtre($v[1], $v[0], $v[2]);
440 440
 		}
441 441
 
442
-		return null;  // sera ignore
442
+		return null; // sera ignore
443 443
 	}
444 444
 
445 445
 	/**
@@ -468,28 +468,28 @@  discard block
 block discarded – undo
468 468
 		// if (!in_array($cle, array('cle', 'valeur')))
469 469
 		//	return;
470 470
 
471
-		$a = '$this->get_select(\'' . $cle . '\')';
471
+		$a = '$this->get_select(\''.$cle.'\')';
472 472
 
473 473
 		$filtre = '';
474 474
 
475 475
 		if ('REGEXP' == $op) {
476
-			$filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', (string) $valeur) . ')';
476
+			$filtre = 'filtrer("match", '.$a.', '.str_replace('\"', '"', (string) $valeur).')';
477 477
 			$op = '';
478 478
 		} else {
479 479
 			if ('LIKE' == $op) {
480 480
 				$valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote((string) $valeur));
481
-				$filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')';
481
+				$filtre = 'filtrer("match", '.$a.', '.$valeur.')';
482 482
 				$op = '';
483 483
 			} else {
484 484
 				if ('=' == $op) {
485 485
 					$op = '==';
486 486
 				} else {
487 487
 					if ('IN' == $op) {
488
-						$filtre = 'in_array(' . $a . ', array' . $valeur . ')';
488
+						$filtre = 'in_array('.$a.', array'.$valeur.')';
489 489
 						$op = '';
490 490
 					} else {
491 491
 						if (!in_array($op, ['<', '<=', '>', '>='])) {
492
-							spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette
492
+							spip_log('operateur non reconnu '.$op); // [todo] mettre une erreur de squelette
493 493
 							$op = '';
494 494
 						}
495 495
 					}
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
 		}
499 499
 
500 500
 		if ($op) {
501
-			$filtre = $a . $op . str_replace('\"', '"', (string) $valeur);
501
+			$filtre = $a.$op.str_replace('\"', '"', (string) $valeur);
502 502
 		}
503 503
 
504 504
 		if ($not) {
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
 		// Creer la fonction de filtrage sur $this
548 548
 		if ($this->filtre) {
549 549
 			if ($filtres = $this->assembler_filtres($this->filtre)) {
550
-				$filtres = 'return ' . $filtres . ';';
550
+				$filtres = 'return '.$filtres.';';
551 551
 				$this->func_filtre = fn () => eval($filtres);
552 552
 			} else {
553 553
 				$this->func_filtre = null;
Please login to merge, or discard this patch.
Indentation   +554 added lines, -554 removed lines patch added patch discarded remove patch
@@ -8,566 +8,566 @@
 block discarded – undo
8 8
 
9 9
 class Decorator extends FilterIterator
10 10
 {
11
-	/**
12
-	 * Conditions de filtrage
13
-	 * ie criteres de selection.
14
-	 *
15
-	 * @var array
16
-	 */
17
-	protected $filtre = [];
18
-
19
-	/**
20
-	 * Fonction de filtrage compilee a partir des criteres de filtre.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $func_filtre;
25
-
26
-	/**
27
-	 * Critere {offset, limit}.
28
-	 *
29
-	 * @var int
30
-	 * @var int
31
-	 */
32
-	protected $offset;
33
-	protected $limit;
34
-
35
-	/**
36
-	 * nombre d'elements recuperes depuis la position 0,
37
-	 * en tenant compte des filtres.
38
-	 *
39
-	 * @var int
40
-	 */
41
-	protected $fetched = 0;
42
-
43
-	/**
44
-	 * Y a t'il une erreur ?
45
-	 *
46
-	 * @var bool
47
-	 */
48
-	protected $err = false;
49
-
50
-	// Extension SPIP des iterateurs PHP
51
-	/**
52
-	 * type de l'iterateur.
53
-	 *
54
-	 * @var string
55
-	 */
56
-	protected $type;
57
-
58
-	/**
59
-	 * position courante de l'iterateur.
60
-	 *
61
-	 * @var int
62
-	 */
63
-	protected $pos = 0;
64
-
65
-	/**
66
-	 * nombre total resultats dans l'iterateur.
67
-	 *
68
-	 * @var int
69
-	 */
70
-	protected $total;
71
-
72
-	/**
73
-	 * nombre maximal de recherche pour $total
74
-	 * si l'iterateur n'implemente pas de fonction specifique.
75
-	 */
76
-	protected $max = 100000;
77
-
78
-	/**
79
-	 * Liste des champs a inserer dans les $row
80
-	 * retournes par ->fetch().
81
-	 */
82
-	protected $select = [];
83
-	private readonly Iterator $iter;
84
-
85
-	public function __construct(
86
-		Iterator $iter,
87
-		/** Parametres de l'iterateur */
88
-		protected array $command,
89
-		/** Infos du compilateur */
90
-		protected array $info
91
-	) {
92
-		parent::__construct($iter);
93
-		parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator)
94
-
95
-		// recuperer l'iterateur transmis
96
-		$this->iter = $this->getInnerIterator();
97
-
98
-		// chercher la liste des champs a retourner par
99
-		// fetch si l'objet ne les calcule pas tout seul
100
-		if (!method_exists($this->iter, 'fetch')) {
101
-			$this->calculer_select();
102
-			$this->calculer_filtres();
103
-		}
104
-
105
-		// emptyIterator critere {si} faux n'a pas d'erreur !
106
-		if (property_exists($this->iter, 'err') && $this->iter->err !== null) {
107
-			$this->err = $this->iter->err;
108
-		}
109
-
110
-		// pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite)
111
-		//$this->total = $this->count();
112
-	}
113
-
114
-	/**
115
-	 * Drapeau a activer en cas d'echec
116
-	 * (select SQL errone, non chargement des DATA, etc).
117
-	 */
118
-	public function err() {
119
-		if (method_exists($this->iter, 'err')) {
120
-			return $this->iter->err();
121
-		}
122
-		if (property_exists($this->iter, 'err')) {
123
-			return $this->iter->err;
124
-		}
125
-
126
-		return false;
127
-	}
128
-
129
-	// recuperer la valeur d'une balise #X
130
-	// en fonction des methodes
131
-	// et proprietes disponibles
132
-	public function get_select($nom) {
133
-		if (is_object($this->iter) && method_exists($this->iter, $nom)) {
134
-			try {
135
-				return $this->iter->{$nom}();
136
-			} catch (Exception) {
137
-				// #GETCHILDREN sur un fichier de DirectoryIterator ...
138
-				spip_log("Methode {$nom} en echec sur " . $this->iter::class);
139
-				spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode");
140
-
141
-				return '';
142
-			}
143
-		}
144
-		/*
11
+    /**
12
+     * Conditions de filtrage
13
+     * ie criteres de selection.
14
+     *
15
+     * @var array
16
+     */
17
+    protected $filtre = [];
18
+
19
+    /**
20
+     * Fonction de filtrage compilee a partir des criteres de filtre.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $func_filtre;
25
+
26
+    /**
27
+     * Critere {offset, limit}.
28
+     *
29
+     * @var int
30
+     * @var int
31
+     */
32
+    protected $offset;
33
+    protected $limit;
34
+
35
+    /**
36
+     * nombre d'elements recuperes depuis la position 0,
37
+     * en tenant compte des filtres.
38
+     *
39
+     * @var int
40
+     */
41
+    protected $fetched = 0;
42
+
43
+    /**
44
+     * Y a t'il une erreur ?
45
+     *
46
+     * @var bool
47
+     */
48
+    protected $err = false;
49
+
50
+    // Extension SPIP des iterateurs PHP
51
+    /**
52
+     * type de l'iterateur.
53
+     *
54
+     * @var string
55
+     */
56
+    protected $type;
57
+
58
+    /**
59
+     * position courante de l'iterateur.
60
+     *
61
+     * @var int
62
+     */
63
+    protected $pos = 0;
64
+
65
+    /**
66
+     * nombre total resultats dans l'iterateur.
67
+     *
68
+     * @var int
69
+     */
70
+    protected $total;
71
+
72
+    /**
73
+     * nombre maximal de recherche pour $total
74
+     * si l'iterateur n'implemente pas de fonction specifique.
75
+     */
76
+    protected $max = 100000;
77
+
78
+    /**
79
+     * Liste des champs a inserer dans les $row
80
+     * retournes par ->fetch().
81
+     */
82
+    protected $select = [];
83
+    private readonly Iterator $iter;
84
+
85
+    public function __construct(
86
+        Iterator $iter,
87
+        /** Parametres de l'iterateur */
88
+        protected array $command,
89
+        /** Infos du compilateur */
90
+        protected array $info
91
+    ) {
92
+        parent::__construct($iter);
93
+        parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator)
94
+
95
+        // recuperer l'iterateur transmis
96
+        $this->iter = $this->getInnerIterator();
97
+
98
+        // chercher la liste des champs a retourner par
99
+        // fetch si l'objet ne les calcule pas tout seul
100
+        if (!method_exists($this->iter, 'fetch')) {
101
+            $this->calculer_select();
102
+            $this->calculer_filtres();
103
+        }
104
+
105
+        // emptyIterator critere {si} faux n'a pas d'erreur !
106
+        if (property_exists($this->iter, 'err') && $this->iter->err !== null) {
107
+            $this->err = $this->iter->err;
108
+        }
109
+
110
+        // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite)
111
+        //$this->total = $this->count();
112
+    }
113
+
114
+    /**
115
+     * Drapeau a activer en cas d'echec
116
+     * (select SQL errone, non chargement des DATA, etc).
117
+     */
118
+    public function err() {
119
+        if (method_exists($this->iter, 'err')) {
120
+            return $this->iter->err();
121
+        }
122
+        if (property_exists($this->iter, 'err')) {
123
+            return $this->iter->err;
124
+        }
125
+
126
+        return false;
127
+    }
128
+
129
+    // recuperer la valeur d'une balise #X
130
+    // en fonction des methodes
131
+    // et proprietes disponibles
132
+    public function get_select($nom) {
133
+        if (is_object($this->iter) && method_exists($this->iter, $nom)) {
134
+            try {
135
+                return $this->iter->{$nom}();
136
+            } catch (Exception) {
137
+                // #GETCHILDREN sur un fichier de DirectoryIterator ...
138
+                spip_log("Methode {$nom} en echec sur " . $this->iter::class);
139
+                spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode");
140
+
141
+                return '';
142
+            }
143
+        }
144
+        /*
145 145
 		if (property_exists($this->iter, $nom)) {
146 146
 			return $this->iter->$nom;
147 147
 		}*/
148
-		// cle et valeur par defaut
149
-		// ICI PLANTAGE SI ON NE CONTROLE PAS $nom
150
-		if (
151
-			in_array($nom, ['cle', 'valeur'])
152
-			&& method_exists($this, $nom)
153
-		) {
154
-			return $this->{$nom}();
155
-		}
156
-
157
-		// Par defaut chercher en xpath dans la valeur()
158
-		return table_valeur($this->valeur(), $nom, null);
159
-	}
160
-
161
-	public function next(): void {
162
-		++$this->pos;
163
-		parent::next();
164
-	}
165
-
166
-	/**
167
-	 * revient au depart.
168
-	 */
169
-	public function rewind(): void {
170
-		$this->pos = 0;
171
-		$this->fetched = 0;
172
-		parent::rewind();
173
-	}
174
-
175
-	/**
176
-	 * aller a la position absolue n,
177
-	 * comptee depuis le debut.
178
-	 *
179
-	 * @param int    $n
180
-	 *                         absolute pos
181
-	 * @param string $continue
182
-	 *                         param for sql_ api
183
-	 *
184
-	 * @return bool
185
-	 *              success or fail if not implemented
186
-	 */
187
-	public function seek($n = 0, $continue = null) {
188
-		if ($this->func_filtre || !method_exists($this->iter, 'seek') || !$this->iter->seek($n)) {
189
-			$this->seek_loop($n);
190
-		}
191
-		$this->pos = $n;
192
-		$this->fetched = $n;
193
-
194
-		return true;
195
-	}
196
-
197
-	/**
198
-	 * Avancer de $saut pas.
199
-	 *
200
-	 * @param int $saut
201
-	 * @param int|null $max
202
-	 *
203
-	 * @return int
204
-	 */
205
-	public function skip($saut, $max = null) {
206
-		// pas de saut en arriere autorise pour cette fonction
207
-		if (($saut = (int) $saut) <= 0) {
208
-			return $this->pos;
209
-		}
210
-		$seek = $this->pos + $saut;
211
-		// si le saut fait depasser le maxi, on libere la resource
212
-		// et on sort
213
-		if (is_null($max)) {
214
-			$max = $this->count();
215
-		}
216
-
217
-		if ($seek >= $max || $seek >= $this->count()) {
218
-			// sortie plus rapide que de faire next() jusqu'a la fin !
219
-			$this->free();
220
-
221
-			return $max;
222
-		}
223
-
224
-		$this->seek($seek);
225
-
226
-		return $this->pos;
227
-	}
228
-
229
-	/**
230
-	 * Renvoyer un tableau des donnees correspondantes
231
-	 * a la position courante de l'iterateur
232
-	 * en controlant si on respecte le filtre
233
-	 * Appliquer aussi le critere {offset,limit}.
234
-	 *
235
-	 * @return array|bool
236
-	 */
237
-	public function fetch() {
238
-		if (method_exists($this->iter, 'fetch')) {
239
-			return $this->iter->fetch();
240
-		}
241
-		while (
242
-				$this->valid()
243
-				&& (!$this->accept() || $this->offset !== null && $this->fetched++ < $this->offset)
244
-		) {
245
-			$this->next();
246
-		}
247
-
248
-		if (!$this->valid()) {
249
-			return false;
250
-		}
251
-
252
-		if (
253
-				$this->limit !== null
254
-				&& $this->fetched > $this->offset + $this->limit
255
-		) {
256
-			return false;
257
-		}
258
-
259
-		$r = [];
260
-		foreach ($this->select as $nom) {
261
-			$r[$nom] = $this->get_select($nom);
262
-		}
263
-		$this->next();
264
-
265
-		return $r;
266
-	}
267
-
268
-	// retourner la cle pour #CLE
269
-	public function cle() {
270
-		return $this->key();
271
-	}
272
-
273
-	// retourner la valeur pour #VALEUR
274
-	public function valeur() {
275
-		return $this->current();
276
-	}
277
-
278
-	/**
279
-	 * Accepte-t-on l'entree courante lue ?
280
-	 * On execute les filtres pour le savoir.
281
-	 */
282
-	public function accept(): bool {
283
-		if ($f = $this->func_filtre) {
284
-			return $f();
285
-		}
286
-
287
-		return true;
288
-	}
289
-
290
-	/**
291
-	 * liberer la ressource.
292
-	 *
293
-	 * @return bool
294
-	 */
295
-	public function free() {
296
-		if (method_exists($this->iter, 'free')) {
297
-			$this->iter->free();
298
-		}
299
-		$this->pos = $this->total = 0;
300
-
301
-		return true;
302
-	}
303
-
304
-	/**
305
-	 * Compter le nombre total de resultats
306
-	 * pour #TOTAL_BOUCLE.
307
-	 *
308
-	 * @return int
309
-	 */
310
-	public function count() {
311
-		if (is_null($this->total)) {
312
-			if (
313
-				method_exists($this->iter, 'count')
314
-				&& !$this->func_filtre
315
-			) {
316
-				return $this->total = $this->iter->count();
317
-			}
318
-			// compter les lignes et rembobiner
319
-			$total = 0;
320
-			$pos = $this->pos; // sauver la position
321
-			$this->rewind();
322
-			while ($this->fetch() && $total < $this->max) {
323
-				++$total;
324
-			}
325
-			$this->seek($pos);
326
-			$this->total = $total;
327
-		}
328
-
329
-		return $this->total;
330
-	}
331
-
332
-	/**
333
-	 * Assembler le tableau de filtres traduits depuis les conditions SQL
334
-	 * les filtres vides ou null sont ignores.
335
-	 *
336
-	 * @param array $filtres
337
-	 * @param string $operateur
338
-	 *
339
-	 * @return null|string
340
-	 */
341
-	protected function assembler_filtres($filtres, $operateur = 'AND') {
342
-		$filtres_string = [];
343
-		foreach ($filtres as $k => $v) {
344
-			// si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine
345
-			if (is_array($v) && in_array(reset($v), ['OR', 'AND'])) {
346
-				$op = array_shift($v);
347
-				$v = $this->assembler_filtres($v, $op);
348
-			}
349
-			if (is_null($v) || !is_string($v) || empty($v)) {
350
-				continue;
351
-			}
352
-			$filtres_string[] = $v;
353
-		}
354
-
355
-		if ($filtres_string === []) {
356
-			return null;
357
-		}
358
-
359
-		return '(' . implode(") {$operateur} (", $filtres_string) . ')';
360
-	}
361
-
362
-	/**
363
-	 * Traduire un element du tableau where SQL en un filtre.
364
-	 *
365
-	 * @param array|string $v
366
-	 *
367
-	 * @return null|array|string
368
-	 */
369
-	protected function traduire_condition_sql_en_filtre($v) {
370
-		if (is_array($v)) {
371
-			if ((count($v) >= 2) && ('REGEXP' == $v[0]) && ("'.*'" == $v[2])) {
372
-				return 'true';
373
-			}
374
-			if ((count($v) >= 2) && ('LIKE' == $v[0]) && ("'%'" == $v[2])) {
375
-				return 'true';
376
-			}
377
-			$op = $v[0] ?: $v;
378
-		} else {
379
-			$op = $v;
380
-		}
381
-		if (!$op || 1 == $op || '0=0' == $op) {
382
-			return 'true';
383
-		}
384
-		if ('0=1' === $op) {
385
-			return 'false';
386
-		}
387
-		// traiter {cle IN a,b} ou {valeur !IN a,b}
388
-		if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', (string) $op, $regs)) {
389
-			return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]);
390
-		}
391
-
392
-		// 3 possibilites : count($v) =
393
-		// * 1 : {x y} ; on recoit $v[0] = y
394
-		// * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y}
395
-		// * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y
396
-
397
-		// 1 : forcement traite par un critere, on passe
398
-		if (!$v || !is_array($v) || 1 == count($v)) {
399
-			return null; // sera ignore
400
-		}
401
-		if (2 == count($v) && is_array($v[1])) {
402
-			return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT');
403
-		}
404
-		if (3 == count($v)) {
405
-			// traiter le OR/AND suivi de 2 valeurs
406
-			if (in_array($op, ['OR', 'AND'])) {
407
-				array_shift($v);
408
-				foreach (array_keys($v) as $k) {
409
-					$v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]);
410
-					if (null === $v[$k]) {
411
-						unset($v[$k]);
412
-					} elseif ('true' === $v[$k]) {
413
-						if ('OR' === $op) {
414
-							return 'true';
415
-						}
416
-						if ('AND' === $op) {
417
-							unset($v[$k]);
418
-						}
419
-					} elseif ('false' === $v[$k]) {
420
-						if ('OR' === $op) {
421
-							unset($v[$k]);
422
-						}
423
-						if ('AND' === $op) {
424
-							return 'false';
425
-						}
426
-					}
427
-				}
428
-				if ($v === []) {
429
-					return null;
430
-				}
431
-				if (1 === count($v)) {
432
-					return reset($v);
433
-				}
434
-				array_unshift($v, $op);
435
-
436
-				return $v;
437
-			}
438
-
439
-			return $this->composer_filtre($v[1], $v[0], $v[2]);
440
-		}
441
-
442
-		return null;  // sera ignore
443
-	}
444
-
445
-	/**
446
-	 * Calculer un filtre sur un champ du tableau.
447
-	 *
448
-	 * @param string $cle
449
-	 * @param string $op
450
-	 * @param string $valeur
451
-	 * @param bool $not
452
-	 *
453
-	 * @return null|string
454
-	 */
455
-	protected function composer_filtre($cle, $op, $valeur, $not = false) {
456
-		if (
457
-			method_exists($this->iter, 'exception_des_criteres')
458
-			&& in_array($cle, $this->iter->exception_des_criteres())
459
-		) {
460
-			return null;
461
-		}
462
-		// TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ?
463
-		// mais c'est normalement deja opere par calculer_critere_infixe()
464
-		// qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1}
465
-		// ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present.
466
-		// il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir...
467
-
468
-		// if (!in_array($cle, array('cle', 'valeur')))
469
-		//	return;
470
-
471
-		$a = '$this->get_select(\'' . $cle . '\')';
472
-
473
-		$filtre = '';
474
-
475
-		if ('REGEXP' == $op) {
476
-			$filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', (string) $valeur) . ')';
477
-			$op = '';
478
-		} else {
479
-			if ('LIKE' == $op) {
480
-				$valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote((string) $valeur));
481
-				$filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')';
482
-				$op = '';
483
-			} else {
484
-				if ('=' == $op) {
485
-					$op = '==';
486
-				} else {
487
-					if ('IN' == $op) {
488
-						$filtre = 'in_array(' . $a . ', array' . $valeur . ')';
489
-						$op = '';
490
-					} else {
491
-						if (!in_array($op, ['<', '<=', '>', '>='])) {
492
-							spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette
493
-							$op = '';
494
-						}
495
-					}
496
-				}
497
-			}
498
-		}
499
-
500
-		if ($op) {
501
-			$filtre = $a . $op . str_replace('\"', '"', (string) $valeur);
502
-		}
503
-
504
-		if ($not) {
505
-			$filtre = "!({$filtre})";
506
-		}
507
-
508
-		return $filtre;
509
-	}
510
-
511
-	// calcule les elements a retournes par fetch()
512
-	// enleve les elements inutiles du select()
513
-	//
514
-	private function calculer_select() {
515
-		if ($select = &$this->command['select']) {
516
-			foreach ($select as $s) {
517
-				// /!\ $s = '.nom'
518
-				if ('.' == $s[0]) {
519
-					$s = substr((string) $s, 1);
520
-				}
521
-				$this->select[] = $s;
522
-			}
523
-		}
524
-	}
525
-
526
-	private function calculer_filtres() {
527
-		// Issu de calculer_select() de public/composer L.519
528
-		// TODO: externaliser...
529
-		//
530
-		// retirer les criteres vides:
531
-		// {X ?} avec X absent de l'URL
532
-		// {par #ENV{X}} avec X absent de l'URL
533
-		// IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil)
534
-		if ($where = &$this->command['where']) {
535
-			foreach ($where as $k => $v) {
536
-				$this->filtre[] = $this->traduire_condition_sql_en_filtre($v);
537
-			}
538
-		}
539
-
540
-		// critere {2,7}
541
-		if (isset($this->command['limit']) && $this->command['limit']) {
542
-			$limit = explode(',', (string) $this->command['limit']);
543
-			$this->offset = $limit[0];
544
-			$this->limit = $limit[1];
545
-		}
546
-
547
-		// Creer la fonction de filtrage sur $this
548
-		if ($this->filtre) {
549
-			if ($filtres = $this->assembler_filtres($this->filtre)) {
550
-				$filtres = 'return ' . $filtres . ';';
551
-				$this->func_filtre = fn () => eval($filtres);
552
-			} else {
553
-				$this->func_filtre = null;
554
-			}
555
-		}
556
-	}
557
-
558
-	/*
148
+        // cle et valeur par defaut
149
+        // ICI PLANTAGE SI ON NE CONTROLE PAS $nom
150
+        if (
151
+            in_array($nom, ['cle', 'valeur'])
152
+            && method_exists($this, $nom)
153
+        ) {
154
+            return $this->{$nom}();
155
+        }
156
+
157
+        // Par defaut chercher en xpath dans la valeur()
158
+        return table_valeur($this->valeur(), $nom, null);
159
+    }
160
+
161
+    public function next(): void {
162
+        ++$this->pos;
163
+        parent::next();
164
+    }
165
+
166
+    /**
167
+     * revient au depart.
168
+     */
169
+    public function rewind(): void {
170
+        $this->pos = 0;
171
+        $this->fetched = 0;
172
+        parent::rewind();
173
+    }
174
+
175
+    /**
176
+     * aller a la position absolue n,
177
+     * comptee depuis le debut.
178
+     *
179
+     * @param int    $n
180
+     *                         absolute pos
181
+     * @param string $continue
182
+     *                         param for sql_ api
183
+     *
184
+     * @return bool
185
+     *              success or fail if not implemented
186
+     */
187
+    public function seek($n = 0, $continue = null) {
188
+        if ($this->func_filtre || !method_exists($this->iter, 'seek') || !$this->iter->seek($n)) {
189
+            $this->seek_loop($n);
190
+        }
191
+        $this->pos = $n;
192
+        $this->fetched = $n;
193
+
194
+        return true;
195
+    }
196
+
197
+    /**
198
+     * Avancer de $saut pas.
199
+     *
200
+     * @param int $saut
201
+     * @param int|null $max
202
+     *
203
+     * @return int
204
+     */
205
+    public function skip($saut, $max = null) {
206
+        // pas de saut en arriere autorise pour cette fonction
207
+        if (($saut = (int) $saut) <= 0) {
208
+            return $this->pos;
209
+        }
210
+        $seek = $this->pos + $saut;
211
+        // si le saut fait depasser le maxi, on libere la resource
212
+        // et on sort
213
+        if (is_null($max)) {
214
+            $max = $this->count();
215
+        }
216
+
217
+        if ($seek >= $max || $seek >= $this->count()) {
218
+            // sortie plus rapide que de faire next() jusqu'a la fin !
219
+            $this->free();
220
+
221
+            return $max;
222
+        }
223
+
224
+        $this->seek($seek);
225
+
226
+        return $this->pos;
227
+    }
228
+
229
+    /**
230
+     * Renvoyer un tableau des donnees correspondantes
231
+     * a la position courante de l'iterateur
232
+     * en controlant si on respecte le filtre
233
+     * Appliquer aussi le critere {offset,limit}.
234
+     *
235
+     * @return array|bool
236
+     */
237
+    public function fetch() {
238
+        if (method_exists($this->iter, 'fetch')) {
239
+            return $this->iter->fetch();
240
+        }
241
+        while (
242
+                $this->valid()
243
+                && (!$this->accept() || $this->offset !== null && $this->fetched++ < $this->offset)
244
+        ) {
245
+            $this->next();
246
+        }
247
+
248
+        if (!$this->valid()) {
249
+            return false;
250
+        }
251
+
252
+        if (
253
+                $this->limit !== null
254
+                && $this->fetched > $this->offset + $this->limit
255
+        ) {
256
+            return false;
257
+        }
258
+
259
+        $r = [];
260
+        foreach ($this->select as $nom) {
261
+            $r[$nom] = $this->get_select($nom);
262
+        }
263
+        $this->next();
264
+
265
+        return $r;
266
+    }
267
+
268
+    // retourner la cle pour #CLE
269
+    public function cle() {
270
+        return $this->key();
271
+    }
272
+
273
+    // retourner la valeur pour #VALEUR
274
+    public function valeur() {
275
+        return $this->current();
276
+    }
277
+
278
+    /**
279
+     * Accepte-t-on l'entree courante lue ?
280
+     * On execute les filtres pour le savoir.
281
+     */
282
+    public function accept(): bool {
283
+        if ($f = $this->func_filtre) {
284
+            return $f();
285
+        }
286
+
287
+        return true;
288
+    }
289
+
290
+    /**
291
+     * liberer la ressource.
292
+     *
293
+     * @return bool
294
+     */
295
+    public function free() {
296
+        if (method_exists($this->iter, 'free')) {
297
+            $this->iter->free();
298
+        }
299
+        $this->pos = $this->total = 0;
300
+
301
+        return true;
302
+    }
303
+
304
+    /**
305
+     * Compter le nombre total de resultats
306
+     * pour #TOTAL_BOUCLE.
307
+     *
308
+     * @return int
309
+     */
310
+    public function count() {
311
+        if (is_null($this->total)) {
312
+            if (
313
+                method_exists($this->iter, 'count')
314
+                && !$this->func_filtre
315
+            ) {
316
+                return $this->total = $this->iter->count();
317
+            }
318
+            // compter les lignes et rembobiner
319
+            $total = 0;
320
+            $pos = $this->pos; // sauver la position
321
+            $this->rewind();
322
+            while ($this->fetch() && $total < $this->max) {
323
+                ++$total;
324
+            }
325
+            $this->seek($pos);
326
+            $this->total = $total;
327
+        }
328
+
329
+        return $this->total;
330
+    }
331
+
332
+    /**
333
+     * Assembler le tableau de filtres traduits depuis les conditions SQL
334
+     * les filtres vides ou null sont ignores.
335
+     *
336
+     * @param array $filtres
337
+     * @param string $operateur
338
+     *
339
+     * @return null|string
340
+     */
341
+    protected function assembler_filtres($filtres, $operateur = 'AND') {
342
+        $filtres_string = [];
343
+        foreach ($filtres as $k => $v) {
344
+            // si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine
345
+            if (is_array($v) && in_array(reset($v), ['OR', 'AND'])) {
346
+                $op = array_shift($v);
347
+                $v = $this->assembler_filtres($v, $op);
348
+            }
349
+            if (is_null($v) || !is_string($v) || empty($v)) {
350
+                continue;
351
+            }
352
+            $filtres_string[] = $v;
353
+        }
354
+
355
+        if ($filtres_string === []) {
356
+            return null;
357
+        }
358
+
359
+        return '(' . implode(") {$operateur} (", $filtres_string) . ')';
360
+    }
361
+
362
+    /**
363
+     * Traduire un element du tableau where SQL en un filtre.
364
+     *
365
+     * @param array|string $v
366
+     *
367
+     * @return null|array|string
368
+     */
369
+    protected function traduire_condition_sql_en_filtre($v) {
370
+        if (is_array($v)) {
371
+            if ((count($v) >= 2) && ('REGEXP' == $v[0]) && ("'.*'" == $v[2])) {
372
+                return 'true';
373
+            }
374
+            if ((count($v) >= 2) && ('LIKE' == $v[0]) && ("'%'" == $v[2])) {
375
+                return 'true';
376
+            }
377
+            $op = $v[0] ?: $v;
378
+        } else {
379
+            $op = $v;
380
+        }
381
+        if (!$op || 1 == $op || '0=0' == $op) {
382
+            return 'true';
383
+        }
384
+        if ('0=1' === $op) {
385
+            return 'false';
386
+        }
387
+        // traiter {cle IN a,b} ou {valeur !IN a,b}
388
+        if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', (string) $op, $regs)) {
389
+            return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]);
390
+        }
391
+
392
+        // 3 possibilites : count($v) =
393
+        // * 1 : {x y} ; on recoit $v[0] = y
394
+        // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y}
395
+        // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y
396
+
397
+        // 1 : forcement traite par un critere, on passe
398
+        if (!$v || !is_array($v) || 1 == count($v)) {
399
+            return null; // sera ignore
400
+        }
401
+        if (2 == count($v) && is_array($v[1])) {
402
+            return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT');
403
+        }
404
+        if (3 == count($v)) {
405
+            // traiter le OR/AND suivi de 2 valeurs
406
+            if (in_array($op, ['OR', 'AND'])) {
407
+                array_shift($v);
408
+                foreach (array_keys($v) as $k) {
409
+                    $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]);
410
+                    if (null === $v[$k]) {
411
+                        unset($v[$k]);
412
+                    } elseif ('true' === $v[$k]) {
413
+                        if ('OR' === $op) {
414
+                            return 'true';
415
+                        }
416
+                        if ('AND' === $op) {
417
+                            unset($v[$k]);
418
+                        }
419
+                    } elseif ('false' === $v[$k]) {
420
+                        if ('OR' === $op) {
421
+                            unset($v[$k]);
422
+                        }
423
+                        if ('AND' === $op) {
424
+                            return 'false';
425
+                        }
426
+                    }
427
+                }
428
+                if ($v === []) {
429
+                    return null;
430
+                }
431
+                if (1 === count($v)) {
432
+                    return reset($v);
433
+                }
434
+                array_unshift($v, $op);
435
+
436
+                return $v;
437
+            }
438
+
439
+            return $this->composer_filtre($v[1], $v[0], $v[2]);
440
+        }
441
+
442
+        return null;  // sera ignore
443
+    }
444
+
445
+    /**
446
+     * Calculer un filtre sur un champ du tableau.
447
+     *
448
+     * @param string $cle
449
+     * @param string $op
450
+     * @param string $valeur
451
+     * @param bool $not
452
+     *
453
+     * @return null|string
454
+     */
455
+    protected function composer_filtre($cle, $op, $valeur, $not = false) {
456
+        if (
457
+            method_exists($this->iter, 'exception_des_criteres')
458
+            && in_array($cle, $this->iter->exception_des_criteres())
459
+        ) {
460
+            return null;
461
+        }
462
+        // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ?
463
+        // mais c'est normalement deja opere par calculer_critere_infixe()
464
+        // qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1}
465
+        // ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present.
466
+        // il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir...
467
+
468
+        // if (!in_array($cle, array('cle', 'valeur')))
469
+        //	return;
470
+
471
+        $a = '$this->get_select(\'' . $cle . '\')';
472
+
473
+        $filtre = '';
474
+
475
+        if ('REGEXP' == $op) {
476
+            $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', (string) $valeur) . ')';
477
+            $op = '';
478
+        } else {
479
+            if ('LIKE' == $op) {
480
+                $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote((string) $valeur));
481
+                $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')';
482
+                $op = '';
483
+            } else {
484
+                if ('=' == $op) {
485
+                    $op = '==';
486
+                } else {
487
+                    if ('IN' == $op) {
488
+                        $filtre = 'in_array(' . $a . ', array' . $valeur . ')';
489
+                        $op = '';
490
+                    } else {
491
+                        if (!in_array($op, ['<', '<=', '>', '>='])) {
492
+                            spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette
493
+                            $op = '';
494
+                        }
495
+                    }
496
+                }
497
+            }
498
+        }
499
+
500
+        if ($op) {
501
+            $filtre = $a . $op . str_replace('\"', '"', (string) $valeur);
502
+        }
503
+
504
+        if ($not) {
505
+            $filtre = "!({$filtre})";
506
+        }
507
+
508
+        return $filtre;
509
+    }
510
+
511
+    // calcule les elements a retournes par fetch()
512
+    // enleve les elements inutiles du select()
513
+    //
514
+    private function calculer_select() {
515
+        if ($select = &$this->command['select']) {
516
+            foreach ($select as $s) {
517
+                // /!\ $s = '.nom'
518
+                if ('.' == $s[0]) {
519
+                    $s = substr((string) $s, 1);
520
+                }
521
+                $this->select[] = $s;
522
+            }
523
+        }
524
+    }
525
+
526
+    private function calculer_filtres() {
527
+        // Issu de calculer_select() de public/composer L.519
528
+        // TODO: externaliser...
529
+        //
530
+        // retirer les criteres vides:
531
+        // {X ?} avec X absent de l'URL
532
+        // {par #ENV{X}} avec X absent de l'URL
533
+        // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil)
534
+        if ($where = &$this->command['where']) {
535
+            foreach ($where as $k => $v) {
536
+                $this->filtre[] = $this->traduire_condition_sql_en_filtre($v);
537
+            }
538
+        }
539
+
540
+        // critere {2,7}
541
+        if (isset($this->command['limit']) && $this->command['limit']) {
542
+            $limit = explode(',', (string) $this->command['limit']);
543
+            $this->offset = $limit[0];
544
+            $this->limit = $limit[1];
545
+        }
546
+
547
+        // Creer la fonction de filtrage sur $this
548
+        if ($this->filtre) {
549
+            if ($filtres = $this->assembler_filtres($this->filtre)) {
550
+                $filtres = 'return ' . $filtres . ';';
551
+                $this->func_filtre = fn () => eval($filtres);
552
+            } else {
553
+                $this->func_filtre = null;
554
+            }
555
+        }
556
+    }
557
+
558
+    /*
559 559
 	 * aller a la position $n en parcourant
560 560
 	 * un par un tous les elements
561 561
 	 */
562
-	private function seek_loop($n) {
563
-		if ($this->pos > $n) {
564
-			$this->rewind();
565
-		}
562
+    private function seek_loop($n) {
563
+        if ($this->pos > $n) {
564
+            $this->rewind();
565
+        }
566 566
 
567
-		while ($this->pos < $n && $this->valid()) {
568
-			$this->next();
569
-		}
567
+        while ($this->pos < $n && $this->valid()) {
568
+            $this->next();
569
+        }
570 570
 
571
-		return true;
572
-	}
571
+        return true;
572
+    }
573 573
 }
Please login to merge, or discard this patch.
ecrire/auth/sha256.inc.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,6 +12,6 @@
 block discarded – undo
12 12
  * @return string Le SHA de la chaîne
13 13
  */
14 14
 function spip_sha256($str) {
15
-	trigger_deprecation('spip', '5.0', 'Using "%s" is deprecated, use "%s" instead.', 'spip_sha256($str)', 'hash(\'sha256\', $str)');
16
-	return hash('sha256', $str);
15
+    trigger_deprecation('spip', '5.0', 'Using "%s" is deprecated, use "%s" instead.', 'spip_sha256($str)', 'hash(\'sha256\', $str)');
16
+    return hash('sha256', $str);
17 17
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres_dates.php 2 patches
Indentation   +562 added lines, -562 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Filtres
16 16
  **/
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 /**
@@ -36,29 +36,29 @@  discard block
 block discarded – undo
36 36
  *     - une chaîne vide si la date est considérée nulle
37 37
  **/
38 38
 function normaliser_date($date, $forcer_jour = false): string {
39
-	$date = vider_date($date);
40
-	if ($date) {
41
-		if (preg_match('/^\d{8,10}$/', $date)) {
42
-			$date = date('Y-m-d H:i:s', $date);
43
-		}
44
-		if (preg_match('#^([12]\d{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
45
-			$regs = array_pad($regs, 4, null); // eviter notice php
46
-			$date = $regs[1] . '-00-00' . $regs[3];
47
-		} else {
48
-			if (preg_match('#^([12]\d{3}[-/][01]?\d)([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
49
-				$regs = array_pad($regs, 4, null); // eviter notice php
50
-				$date = preg_replace('@/@', '-', (string) $regs[1]) . '-00' . $regs[3];
51
-			} else {
52
-				$date = date('Y-m-d H:i:s', strtotime($date));
53
-			}
54
-		}
55
-
56
-		if ($forcer_jour) {
57
-			$date = str_replace('-00', '-01', $date);
58
-		}
59
-	}
60
-
61
-	return $date;
39
+    $date = vider_date($date);
40
+    if ($date) {
41
+        if (preg_match('/^\d{8,10}$/', $date)) {
42
+            $date = date('Y-m-d H:i:s', $date);
43
+        }
44
+        if (preg_match('#^([12]\d{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
45
+            $regs = array_pad($regs, 4, null); // eviter notice php
46
+            $date = $regs[1] . '-00-00' . $regs[3];
47
+        } else {
48
+            if (preg_match('#^([12]\d{3}[-/][01]?\d)([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
49
+                $regs = array_pad($regs, 4, null); // eviter notice php
50
+                $date = preg_replace('@/@', '-', (string) $regs[1]) . '-00' . $regs[3];
51
+            } else {
52
+                $date = date('Y-m-d H:i:s', strtotime($date));
53
+            }
54
+        }
55
+
56
+        if ($forcer_jour) {
57
+            $date = str_replace('-00', '-01', $date);
58
+        }
59
+    }
60
+
61
+    return $date;
62 62
 }
63 63
 
64 64
 /**
@@ -71,22 +71,22 @@  discard block
 block discarded – undo
71 71
  *     - Une chaine vide
72 72
  **/
73 73
 function vider_date($letexte, $verif_format_date = false): string {
74
-	$letexte ??= '';
75
-	if (
76
-		!$verif_format_date
77
-		|| in_array(strlen($letexte), [10,19]) && preg_match('/^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}:\d{2})?$/', $letexte)
78
-	) {
79
-		if (strncmp('0000-00-00', $letexte, 10) == 0) {
80
-			return '';
81
-		}
82
-		if (strncmp('0001-01-01', $letexte, 10) == 0) {
83
-			return '';
84
-		}
85
-		if (strncmp('1970-01-01', $letexte, 10) == 0) {
86
-			return '';
87
-		}  // eviter le bug GMT-1
88
-	}
89
-	return $letexte;
74
+    $letexte ??= '';
75
+    if (
76
+        !$verif_format_date
77
+        || in_array(strlen($letexte), [10,19]) && preg_match('/^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}:\d{2})?$/', $letexte)
78
+    ) {
79
+        if (strncmp('0000-00-00', $letexte, 10) == 0) {
80
+            return '';
81
+        }
82
+        if (strncmp('0001-01-01', $letexte, 10) == 0) {
83
+            return '';
84
+        }
85
+        if (strncmp('1970-01-01', $letexte, 10) == 0) {
86
+            return '';
87
+        }  // eviter le bug GMT-1
88
+    }
89
+    return $letexte;
90 90
 }
91 91
 
92 92
 /**
@@ -102,17 +102,17 @@  discard block
 block discarded – undo
102 102
  **/
103 103
 function recup_heure($date): array {
104 104
 
105
-	if (preg_match('#(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?#', $date, $elements)) {
106
-		array_shift($elements);
107
-		if (!isset($elements[2])) {
108
-			$elements[2] = 0;
109
-		}
110
-		$heure = $elements;
111
-	} else {
112
-		$heure = [0, 0, 0];
113
-	}
114
-
115
-	return $heure;
105
+    if (preg_match('#(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?#', $date, $elements)) {
106
+        array_shift($elements);
107
+        if (!isset($elements[2])) {
108
+            $elements[2] = 0;
109
+        }
110
+        $heure = $elements;
111
+    } else {
112
+        $heure = [0, 0, 0];
113
+    }
114
+
115
+    return $heure;
116 116
 }
117 117
 
118 118
 /**
@@ -126,13 +126,13 @@  discard block
 block discarded – undo
126 126
  * @return string heures, sinon 0
127 127
  **/
128 128
 function heures($numdate): string {
129
-	$heures = null;
130
-	$date_array = recup_heure($numdate);
131
-	if ($date_array) {
132
-		[$heures, $minutes, $secondes] = $date_array;
133
-	}
129
+    $heures = null;
130
+    $date_array = recup_heure($numdate);
131
+    if ($date_array) {
132
+        [$heures, $minutes, $secondes] = $date_array;
133
+    }
134 134
 
135
-	return $heures;
135
+    return $heures;
136 136
 }
137 137
 
138 138
 /**
@@ -146,13 +146,13 @@  discard block
 block discarded – undo
146 146
  * @return string minutes, sinon 0
147 147
  **/
148 148
 function minutes($numdate): string {
149
-	$minutes = null;
150
-	$date_array = recup_heure($numdate);
151
-	if ($date_array) {
152
-		[$heures, $minutes, $secondes] = $date_array;
153
-	}
149
+    $minutes = null;
150
+    $date_array = recup_heure($numdate);
151
+    if ($date_array) {
152
+        [$heures, $minutes, $secondes] = $date_array;
153
+    }
154 154
 
155
-	return $minutes;
155
+    return $minutes;
156 156
 }
157 157
 
158 158
 /**
@@ -166,13 +166,13 @@  discard block
 block discarded – undo
166 166
  * @return string secondes, sinon 0
167 167
  **/
168 168
 function secondes($numdate): string {
169
-	$secondes = null;
170
-	$date_array = recup_heure($numdate);
171
-	if ($date_array) {
172
-		[$heures, $minutes, $secondes] = $date_array;
173
-	}
169
+    $secondes = null;
170
+    $date_array = recup_heure($numdate);
171
+    if ($date_array) {
172
+        [$heures, $minutes, $secondes] = $date_array;
173
+    }
174 174
 
175
-	return $secondes;
175
+    return $secondes;
176 176
 }
177 177
 
178 178
 /**
@@ -191,11 +191,11 @@  discard block
 block discarded – undo
191 191
  * @return string L'heure formatée dans la langue en cours.
192 192
  **/
193 193
 function heures_minutes($numdate, $forme = ''): string {
194
-	if ($forme !== 'abbr') {
195
-		return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]);
196
-	} else {
197
-		return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]);
198
-	}
194
+    if ($forme !== 'abbr') {
195
+        return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]);
196
+    } else {
197
+        return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]);
198
+    }
199 199
 }
200 200
 
201 201
 /**
@@ -220,57 +220,57 @@  discard block
 block discarded – undo
220 220
  * @return array [année, mois, jour, heures, minutes, secondes] ou []
221 221
  **/
222 222
 function recup_date($numdate, $forcer_jour = true): array {
223
-	if (!$numdate) {
224
-		return [];
225
-	}
226
-	$heures = $minutes = $secondes = 0;
227
-	if (preg_match('#(\d{1,2})/(\d{1,2})/(\d{4}|\d{1,2})#', $numdate, $regs)) {
228
-		$jour = $regs[1];
229
-		$mois = $regs[2];
230
-		$annee = $regs[3];
231
-		if ($annee < 90) {
232
-			$annee = 2000 + $annee;
233
-		} elseif ($annee < 100) {
234
-			$annee = 1900 + $annee;
235
-		}
236
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
237
-	} elseif (preg_match('#(\d{4})-(\d{1,2})-(\d{1,2})#', $numdate, $regs)) {
238
-		$annee = $regs[1];
239
-		$mois = $regs[2];
240
-		$jour = $regs[3];
241
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
242
-	} elseif (preg_match('#(\d{4})-(\d{2})#', $numdate, $regs)) {
243
-		$annee = $regs[1];
244
-		$mois = $regs[2];
245
-		$jour = '';
246
-		[$heures, $minutes, $secondes] = recup_heure($numdate);
247
-	} elseif (preg_match('#^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$#', $numdate, $regs)) {
248
-		$annee = $regs[1];
249
-		$mois = $regs[2];
250
-		$jour = $regs[3];
251
-		$heures = $regs[4];
252
-		$minutes = $regs[5];
253
-		$secondes = $regs[6];
254
-	} else {
255
-		$annee = $mois = $jour = '';
256
-	}
257
-	if ($annee > 4000) {
258
-		$annee -= 9000;
259
-	}
260
-	if (strlen($jour) && str_starts_with($jour, '0')) {
261
-		$jour = substr($jour, 1);
262
-	}
263
-
264
-	if ($forcer_jour && $jour == '0') {
265
-		$jour = '1';
266
-	}
267
-	if ($forcer_jour && $mois == '0') {
268
-		$mois = '1';
269
-	}
270
-	if ($annee || $mois || $jour || $heures || $minutes || $secondes) {
271
-		return [$annee, $mois, $jour, $heures, $minutes, $secondes];
272
-	}
273
-	return [];
223
+    if (!$numdate) {
224
+        return [];
225
+    }
226
+    $heures = $minutes = $secondes = 0;
227
+    if (preg_match('#(\d{1,2})/(\d{1,2})/(\d{4}|\d{1,2})#', $numdate, $regs)) {
228
+        $jour = $regs[1];
229
+        $mois = $regs[2];
230
+        $annee = $regs[3];
231
+        if ($annee < 90) {
232
+            $annee = 2000 + $annee;
233
+        } elseif ($annee < 100) {
234
+            $annee = 1900 + $annee;
235
+        }
236
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
237
+    } elseif (preg_match('#(\d{4})-(\d{1,2})-(\d{1,2})#', $numdate, $regs)) {
238
+        $annee = $regs[1];
239
+        $mois = $regs[2];
240
+        $jour = $regs[3];
241
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
242
+    } elseif (preg_match('#(\d{4})-(\d{2})#', $numdate, $regs)) {
243
+        $annee = $regs[1];
244
+        $mois = $regs[2];
245
+        $jour = '';
246
+        [$heures, $minutes, $secondes] = recup_heure($numdate);
247
+    } elseif (preg_match('#^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$#', $numdate, $regs)) {
248
+        $annee = $regs[1];
249
+        $mois = $regs[2];
250
+        $jour = $regs[3];
251
+        $heures = $regs[4];
252
+        $minutes = $regs[5];
253
+        $secondes = $regs[6];
254
+    } else {
255
+        $annee = $mois = $jour = '';
256
+    }
257
+    if ($annee > 4000) {
258
+        $annee -= 9000;
259
+    }
260
+    if (strlen($jour) && str_starts_with($jour, '0')) {
261
+        $jour = substr($jour, 1);
262
+    }
263
+
264
+    if ($forcer_jour && $jour == '0') {
265
+        $jour = '1';
266
+    }
267
+    if ($forcer_jour && $mois == '0') {
268
+        $mois = '1';
269
+    }
270
+    if ($annee || $mois || $jour || $heures || $minutes || $secondes) {
271
+        return [$annee, $mois, $jour, $heures, $minutes, $secondes];
272
+    }
273
+    return [];
274 274
 }
275 275
 
276 276
 /**
@@ -297,10 +297,10 @@  discard block
 block discarded – undo
297 297
  *     La date relative ou complète
298 298
  **/
299 299
 function date_interface($date, $decalage_maxi = 43200 /* 12*3600 */): string {
300
-	return sinon(
301
-		date_relative($date, $decalage_maxi),
302
-		affdate_heure($date)
303
-	);
300
+    return sinon(
301
+        date_relative($date, $decalage_maxi),
302
+        affdate_heure($date)
303
+    );
304 304
 }
305 305
 
306 306
 /**
@@ -333,72 +333,72 @@  discard block
 block discarded – undo
333 333
  **/
334 334
 function date_relative($date, $decalage_maxi = 0, $ref_date = null): string {
335 335
 
336
-	if (!$date) {
337
-		return '';
338
-	}
339
-
340
-	$ref_time = is_null($ref_date) ? time() : strtotime($ref_date);
341
-
342
-	$decal = date('U', $ref_time) - date('U', strtotime($date));
343
-
344
-	if ($decalage_maxi && ($decal > $decalage_maxi || $decal < 0)) {
345
-		return '';
346
-	}
347
-
348
-	if ($decal < 0) {
349
-		$il_y_a = 'date_dans';
350
-		$decal = -1 * $decal;
351
-	} else {
352
-		$il_y_a = 'date_il_y_a';
353
-	}
354
-
355
-	if ($decal > 3600 * 24 * 30 * 6) {
356
-		return affdate_court($date);
357
-	}
358
-
359
-	if ($decal > 3600 * 24 * 30) {
360
-		$mois = floor($decal / (3600 * 24 * 30));
361
-		$delai = $mois < 2
362
-			? "$mois " . _T('date_un_mois')
363
-			: "$mois " . _T('date_mois');
364
-	} else {
365
-		if ($decal > 3600 * 24 * 7) {
366
-			$semaines = floor($decal / (3600 * 24 * 7));
367
-			$delai = $semaines < 2
368
-				? "$semaines " . _T('date_une_semaine')
369
-				: "$semaines " . _T('date_semaines');
370
-		} else {
371
-			if ($decal > 3600 * 24) {
372
-				$jours = floor($decal / (3600 * 24));
373
-				if ($jours < 2) {
374
-					return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
375
-				} else {
376
-					$delai = "$jours " . _T('date_jours');
377
-				}
378
-			} else {
379
-				if ($decal >= 3600) {
380
-					$heures = floor($decal / 3600);
381
-					$delai = $heures < 2
382
-						? "$heures " . _T('date_une_heure')
383
-						: "$heures " . _T('date_heures');
384
-				} else {
385
-					if ($decal >= 60) {
386
-						$minutes = floor($decal / 60);
387
-						$delai = $minutes < 2
388
-							? "$minutes " . _T('date_une_minute')
389
-							: "$minutes " . _T('date_minutes');
390
-					} else {
391
-						$secondes = ceil($decal);
392
-						$delai = $secondes < 2
393
-							? "$secondes " . _T('date_une_seconde')
394
-							: "$secondes " . _T('date_secondes');
395
-					}
396
-				}
397
-			}
398
-		}
399
-	}
400
-
401
-	return _T($il_y_a, ['delai' => $delai]);
336
+    if (!$date) {
337
+        return '';
338
+    }
339
+
340
+    $ref_time = is_null($ref_date) ? time() : strtotime($ref_date);
341
+
342
+    $decal = date('U', $ref_time) - date('U', strtotime($date));
343
+
344
+    if ($decalage_maxi && ($decal > $decalage_maxi || $decal < 0)) {
345
+        return '';
346
+    }
347
+
348
+    if ($decal < 0) {
349
+        $il_y_a = 'date_dans';
350
+        $decal = -1 * $decal;
351
+    } else {
352
+        $il_y_a = 'date_il_y_a';
353
+    }
354
+
355
+    if ($decal > 3600 * 24 * 30 * 6) {
356
+        return affdate_court($date);
357
+    }
358
+
359
+    if ($decal > 3600 * 24 * 30) {
360
+        $mois = floor($decal / (3600 * 24 * 30));
361
+        $delai = $mois < 2
362
+            ? "$mois " . _T('date_un_mois')
363
+            : "$mois " . _T('date_mois');
364
+    } else {
365
+        if ($decal > 3600 * 24 * 7) {
366
+            $semaines = floor($decal / (3600 * 24 * 7));
367
+            $delai = $semaines < 2
368
+                ? "$semaines " . _T('date_une_semaine')
369
+                : "$semaines " . _T('date_semaines');
370
+        } else {
371
+            if ($decal > 3600 * 24) {
372
+                $jours = floor($decal / (3600 * 24));
373
+                if ($jours < 2) {
374
+                    return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
375
+                } else {
376
+                    $delai = "$jours " . _T('date_jours');
377
+                }
378
+            } else {
379
+                if ($decal >= 3600) {
380
+                    $heures = floor($decal / 3600);
381
+                    $delai = $heures < 2
382
+                        ? "$heures " . _T('date_une_heure')
383
+                        : "$heures " . _T('date_heures');
384
+                } else {
385
+                    if ($decal >= 60) {
386
+                        $minutes = floor($decal / 60);
387
+                        $delai = $minutes < 2
388
+                            ? "$minutes " . _T('date_une_minute')
389
+                            : "$minutes " . _T('date_minutes');
390
+                    } else {
391
+                        $secondes = ceil($decal);
392
+                        $delai = $secondes < 2
393
+                            ? "$secondes " . _T('date_une_seconde')
394
+                            : "$secondes " . _T('date_secondes');
395
+                    }
396
+                }
397
+            }
398
+        }
399
+    }
400
+
401
+    return _T($il_y_a, ['delai' => $delai]);
402 402
 }
403 403
 
404 404
 
@@ -424,30 +424,30 @@  discard block
 block discarded – undo
424 424
  **/
425 425
 function date_relativecourt($date, $decalage_maxi = 0): string {
426 426
 
427
-	if (!$date) {
428
-		return '';
429
-	}
430
-	$decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
431
-
432
-	if ($decalage_maxi && ($decal > $decalage_maxi || $decal < 0)) {
433
-		return '';
434
-	}
435
-
436
-	if ($decal < -24 * 3600) {
437
-		$retour = date_relative($date, $decalage_maxi);
438
-	} elseif ($decal < 0) {
439
-		$retour = _T('date_demain');
440
-	} else {
441
-		if ($decal < (3600 * 24)) {
442
-			$retour = _T('date_aujourdhui');
443
-		} else {
444
-			$retour = $decal < (3600 * 24 * 2)
445
-				? _T('date_hier')
446
-				: date_relative($date, $decalage_maxi);
447
-		}
448
-	}
449
-
450
-	return $retour;
427
+    if (!$date) {
428
+        return '';
429
+    }
430
+    $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
431
+
432
+    if ($decalage_maxi && ($decal > $decalage_maxi || $decal < 0)) {
433
+        return '';
434
+    }
435
+
436
+    if ($decal < -24 * 3600) {
437
+        $retour = date_relative($date, $decalage_maxi);
438
+    } elseif ($decal < 0) {
439
+        $retour = _T('date_demain');
440
+    } else {
441
+        if ($decal < (3600 * 24)) {
442
+            $retour = _T('date_aujourdhui');
443
+        } else {
444
+            $retour = $decal < (3600 * 24 * 2)
445
+                ? _T('date_hier')
446
+                : date_relative($date, $decalage_maxi);
447
+        }
448
+    }
449
+
450
+    return $retour;
451 451
 }
452 452
 
453 453
 /**
@@ -464,173 +464,173 @@  discard block
 block discarded – undo
464 464
  * @return string
465 465
  */
466 466
 function affdate_base($numdate, $vue, $options = []): string {
467
-	if (is_string($options)) {
468
-		$options = ['param' => $options];
469
-	}
470
-	$date_array = recup_date($numdate, false);
471
-	if (!$date_array) {
472
-		return '';
473
-	}
474
-	[$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
475
-
476
-	// 1er, 21st, etc.
477
-	$journum = $jour;
478
-
479
-	if ($jour == 0) {
480
-		$jour = '';
481
-		$njour = 0;
482
-	} else {
483
-		$njour = (int) $jour;
484
-		if ($jourth = _T('date_jnum' . $jour)) {
485
-			$jour = $jourth;
486
-		}
487
-	}
488
-
489
-	$mois = (int) $mois;
490
-	if ($mois > 0 && $mois < 13) {
491
-		/* Traiter le cas "abbr" pour les noms de mois */
492
-		$param = ((isset($options['param']) && $options['param'] === 'abbr') ? '_' . $options['param'] : '');
493
-		$nommois = _T('date_mois_' . $mois . $param);
494
-		$jourmois = $jour
495
-			? _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois])
496
-			: $nommois;
497
-	} else {
498
-		$nommois = '';
499
-		$jourmois = '';
500
-	}
501
-
502
-	if ($annee < 0) {
503
-		$annee = -$annee . ' ' . _T('date_avant_jc');
504
-		$avjc = true;
505
-	} else {
506
-		$avjc = false;
507
-	}
508
-
509
-	switch ($vue) {
510
-		case 'saison':
511
-		case 'saison_annee':
512
-			$saison = '';
513
-			if ($mois > 0) {
514
-				$saison = ($options['param'] == 'sud') ? 3 : 1;
515
-				if ($mois == 3 && $jour >= 21 || $mois > 3) {
516
-					$saison = ($options['param'] == 'sud') ? 4 : 2;
517
-				}
518
-				if ($mois == 6 && $jour >= 21 || $mois > 6) {
519
-					$saison = ($options['param'] == 'sud') ? 1 : 3;
520
-				}
521
-				if ($mois == 9 && $jour >= 21 || $mois > 9) {
522
-					$saison = ($options['param'] == 'sud') ? 2 : 4;
523
-				}
524
-				if ($mois == 12 && $jour >= 21 || $mois > 12) {
525
-					$saison = ($options['param'] == 'sud') ? 3 : 1;
526
-				}
527
-			}
528
-			if ($vue == 'saison') {
529
-				return $saison ? _T('date_saison_' . $saison) : '';
530
-			} else {
531
-				return $saison ? trim((string) _T(
532
-					'date_fmt_saison_annee',
533
-					['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
534
-				)) : '';
535
-			}
536
-
537
-		case 'court':
538
-			if ($avjc) {
539
-				return $annee;
540
-			}
541
-			$a = ((isset($options['annee_courante']) && $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
542
-			if ($annee < ($a - 100) || $annee > ($a + 100)) {
543
-				return $annee;
544
-			}
545
-			if ($annee != $a) {
546
-				return _T(
547
-					'date_fmt_mois_annee',
548
-					['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee]
549
-				);
550
-			}
551
-
552
-			return _T(
553
-				'date_fmt_jour_mois',
554
-				['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
555
-			);
556
-
557
-		case 'jourcourt':
558
-			if ($avjc) {
559
-				return $annee;
560
-			}
561
-			$a = ((isset($options['annee_courante']) && $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
562
-			if ($annee < ($a - 100) || $annee > ($a + 100)) {
563
-				return $annee;
564
-			}
565
-			if ($annee != $a) {
566
-				return _T(
567
-					'date_fmt_jour_mois_annee',
568
-					['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
569
-				);
570
-			}
571
-
572
-			return _T(
573
-				'date_fmt_jour_mois',
574
-				['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
575
-			);
576
-
577
-		case 'entier':
578
-			if ($avjc) {
579
-				return $annee;
580
-			}
581
-			if ($jour) {
582
-				return _T(
583
-					'date_fmt_jour_mois_annee',
584
-					['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
585
-				);
586
-			} elseif ($mois) {
587
-				return trim((string) _T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
588
-			} else {
589
-				return $annee;
590
-			}
591
-
592
-		case 'nom_mois':
593
-			return $nommois;
594
-
595
-		case 'mois':
596
-			return sprintf('%02s', $mois);
597
-
598
-		case 'jour':
599
-			return $jour;
600
-
601
-		case 'journum':
602
-			return $journum;
603
-
604
-		case 'nom_jour':
605
-			if (!$mois || !$njour) {
606
-				return '';
607
-			}
608
-			$nom = mktime(1, 1, 1, $mois, $njour, $annee);
609
-			$nom = 1 + (int) date('w', $nom);
610
-			$param = ((isset($options['param']) && $options['param']) ? '_' . $options['param'] : '');
611
-
612
-			return _T('date_jour_' . $nom . $param);
613
-
614
-		case 'mois_annee':
615
-			if ($avjc) {
616
-				return $annee;
617
-			}
618
-
619
-			return trim((string) _T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
620
-
621
-		case 'annee':
622
-			return $annee;
623
-
624
-		// Cas d'une vue non definie : retomber sur le format
625
-		// de date propose par http://www.php.net/date
626
-		default:
627
-			[$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
628
-			// il faut envoyer jour = 1 si jour pas défini, c'est le comportement qu'on avait historiquement en envoyant ''
629
-			if (!$time = mktime($heures, $minutes, $secondes, $mois, is_numeric($jour) ? $jour : 1, $annee)) {
630
-				$time = strtotime($numdate);
631
-			}
632
-			return date($vue, $time);
633
-	}
467
+    if (is_string($options)) {
468
+        $options = ['param' => $options];
469
+    }
470
+    $date_array = recup_date($numdate, false);
471
+    if (!$date_array) {
472
+        return '';
473
+    }
474
+    [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
475
+
476
+    // 1er, 21st, etc.
477
+    $journum = $jour;
478
+
479
+    if ($jour == 0) {
480
+        $jour = '';
481
+        $njour = 0;
482
+    } else {
483
+        $njour = (int) $jour;
484
+        if ($jourth = _T('date_jnum' . $jour)) {
485
+            $jour = $jourth;
486
+        }
487
+    }
488
+
489
+    $mois = (int) $mois;
490
+    if ($mois > 0 && $mois < 13) {
491
+        /* Traiter le cas "abbr" pour les noms de mois */
492
+        $param = ((isset($options['param']) && $options['param'] === 'abbr') ? '_' . $options['param'] : '');
493
+        $nommois = _T('date_mois_' . $mois . $param);
494
+        $jourmois = $jour
495
+            ? _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois])
496
+            : $nommois;
497
+    } else {
498
+        $nommois = '';
499
+        $jourmois = '';
500
+    }
501
+
502
+    if ($annee < 0) {
503
+        $annee = -$annee . ' ' . _T('date_avant_jc');
504
+        $avjc = true;
505
+    } else {
506
+        $avjc = false;
507
+    }
508
+
509
+    switch ($vue) {
510
+        case 'saison':
511
+        case 'saison_annee':
512
+            $saison = '';
513
+            if ($mois > 0) {
514
+                $saison = ($options['param'] == 'sud') ? 3 : 1;
515
+                if ($mois == 3 && $jour >= 21 || $mois > 3) {
516
+                    $saison = ($options['param'] == 'sud') ? 4 : 2;
517
+                }
518
+                if ($mois == 6 && $jour >= 21 || $mois > 6) {
519
+                    $saison = ($options['param'] == 'sud') ? 1 : 3;
520
+                }
521
+                if ($mois == 9 && $jour >= 21 || $mois > 9) {
522
+                    $saison = ($options['param'] == 'sud') ? 2 : 4;
523
+                }
524
+                if ($mois == 12 && $jour >= 21 || $mois > 12) {
525
+                    $saison = ($options['param'] == 'sud') ? 3 : 1;
526
+                }
527
+            }
528
+            if ($vue == 'saison') {
529
+                return $saison ? _T('date_saison_' . $saison) : '';
530
+            } else {
531
+                return $saison ? trim((string) _T(
532
+                    'date_fmt_saison_annee',
533
+                    ['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
534
+                )) : '';
535
+            }
536
+
537
+        case 'court':
538
+            if ($avjc) {
539
+                return $annee;
540
+            }
541
+            $a = ((isset($options['annee_courante']) && $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
542
+            if ($annee < ($a - 100) || $annee > ($a + 100)) {
543
+                return $annee;
544
+            }
545
+            if ($annee != $a) {
546
+                return _T(
547
+                    'date_fmt_mois_annee',
548
+                    ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee]
549
+                );
550
+            }
551
+
552
+            return _T(
553
+                'date_fmt_jour_mois',
554
+                ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
555
+            );
556
+
557
+        case 'jourcourt':
558
+            if ($avjc) {
559
+                return $annee;
560
+            }
561
+            $a = ((isset($options['annee_courante']) && $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
562
+            if ($annee < ($a - 100) || $annee > ($a + 100)) {
563
+                return $annee;
564
+            }
565
+            if ($annee != $a) {
566
+                return _T(
567
+                    'date_fmt_jour_mois_annee',
568
+                    ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
569
+                );
570
+            }
571
+
572
+            return _T(
573
+                'date_fmt_jour_mois',
574
+                ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
575
+            );
576
+
577
+        case 'entier':
578
+            if ($avjc) {
579
+                return $annee;
580
+            }
581
+            if ($jour) {
582
+                return _T(
583
+                    'date_fmt_jour_mois_annee',
584
+                    ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]
585
+                );
586
+            } elseif ($mois) {
587
+                return trim((string) _T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
588
+            } else {
589
+                return $annee;
590
+            }
591
+
592
+        case 'nom_mois':
593
+            return $nommois;
594
+
595
+        case 'mois':
596
+            return sprintf('%02s', $mois);
597
+
598
+        case 'jour':
599
+            return $jour;
600
+
601
+        case 'journum':
602
+            return $journum;
603
+
604
+        case 'nom_jour':
605
+            if (!$mois || !$njour) {
606
+                return '';
607
+            }
608
+            $nom = mktime(1, 1, 1, $mois, $njour, $annee);
609
+            $nom = 1 + (int) date('w', $nom);
610
+            $param = ((isset($options['param']) && $options['param']) ? '_' . $options['param'] : '');
611
+
612
+            return _T('date_jour_' . $nom . $param);
613
+
614
+        case 'mois_annee':
615
+            if ($avjc) {
616
+                return $annee;
617
+            }
618
+
619
+            return trim((string) _T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee]));
620
+
621
+        case 'annee':
622
+            return $annee;
623
+
624
+        // Cas d'une vue non definie : retomber sur le format
625
+        // de date propose par http://www.php.net/date
626
+        default:
627
+            [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array;
628
+            // il faut envoyer jour = 1 si jour pas défini, c'est le comportement qu'on avait historiquement en envoyant ''
629
+            if (!$time = mktime($heures, $minutes, $secondes, $mois, is_numeric($jour) ? $jour : 1, $annee)) {
630
+                $time = strtotime($numdate);
631
+            }
632
+            return date($vue, $time);
633
+    }
634 634
 }
635 635
 
636 636
 
@@ -657,11 +657,11 @@  discard block
 block discarded – undo
657 657
  *     Nom du jour
658 658
  **/
659 659
 function nom_jour($numdate, $forme = ''): string {
660
-	if ($forme !== 'abbr' && $forme !== 'initiale') {
661
-		$forme = '';
662
-	}
660
+    if ($forme !== 'abbr' && $forme !== 'initiale') {
661
+        $forme = '';
662
+    }
663 663
 
664
-	return affdate_base($numdate, 'nom_jour', ['param' => $forme]);
664
+    return affdate_base($numdate, 'nom_jour', ['param' => $forme]);
665 665
 }
666 666
 
667 667
 /**
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
  *     Numéro du jour
684 684
  **/
685 685
 function jour($numdate): string {
686
-	return affdate_base($numdate, 'jour');
686
+    return affdate_base($numdate, 'jour');
687 687
 }
688 688
 
689 689
 /**
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
  *     Numéro du jour
702 702
  **/
703 703
 function journum($numdate): string {
704
-	return affdate_base($numdate, 'journum');
704
+    return affdate_base($numdate, 'journum');
705 705
 }
706 706
 
707 707
 /**
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
  *     Numéro du mois (sur 2 chiffres)
720 720
  **/
721 721
 function mois($numdate): string {
722
-	return  affdate_base($numdate, 'mois');
722
+    return  affdate_base($numdate, 'mois');
723 723
 }
724 724
 
725 725
 /**
@@ -743,11 +743,11 @@  discard block
 block discarded – undo
743 743
  *     Nom du mois
744 744
  **/
745 745
 function nom_mois($numdate, $forme = ''): string {
746
-	if ($forme !== 'abbr') {
747
-		$forme = '';
748
-	}
746
+    if ($forme !== 'abbr') {
747
+        $forme = '';
748
+    }
749 749
 
750
-	return affdate_base($numdate, 'nom_mois', ['param' => $forme]);
750
+    return affdate_base($numdate, 'nom_mois', ['param' => $forme]);
751 751
 }
752 752
 
753 753
 /**
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
  *     Année (sur 4 chiffres)
766 766
  **/
767 767
 function annee($numdate): string {
768
-	return affdate_base($numdate, 'annee');
768
+    return affdate_base($numdate, 'annee');
769 769
 }
770 770
 
771 771
 
@@ -795,11 +795,11 @@  discard block
 block discarded – undo
795 795
  *     La date formatée
796 796
  **/
797 797
 function saison($numdate, $hemisphere = 'nord'): string {
798
-	if ($hemisphere !== 'sud') {
799
-		$hemisphere = 'nord';
800
-	}
798
+    if ($hemisphere !== 'sud') {
799
+        $hemisphere = 'nord';
800
+    }
801 801
 
802
-	return affdate_base($numdate, 'saison', ['param' => $hemisphere]);
802
+    return affdate_base($numdate, 'saison', ['param' => $hemisphere]);
803 803
 }
804 804
 
805 805
 
@@ -828,11 +828,11 @@  discard block
 block discarded – undo
828 828
  *     La date formatée
829 829
  **/
830 830
 function saison_annee($numdate, $hemisphere = 'nord'): string {
831
-	if ($hemisphere !== 'sud') {
832
-		$hemisphere = 'nord';
833
-	}
831
+    if ($hemisphere !== 'sud') {
832
+        $hemisphere = 'nord';
833
+    }
834 834
 
835
-	return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]);
835
+    return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]);
836 836
 }
837 837
 
838 838
 /**
@@ -860,7 +860,7 @@  discard block
 block discarded – undo
860 860
  *     La date formatée
861 861
  **/
862 862
 function affdate($numdate, $format = 'entier'): string {
863
-	return affdate_base($numdate, $format);
863
+    return affdate_base($numdate, $format);
864 864
 }
865 865
 
866 866
 
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
  *     La date formatée
888 888
  **/
889 889
 function affdate_court($numdate, $annee_courante = null): string {
890
-	return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]);
890
+    return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]);
891 891
 }
892 892
 
893 893
 
@@ -914,7 +914,7 @@  discard block
 block discarded – undo
914 914
  *     La date formatée
915 915
  **/
916 916
 function affdate_jourcourt($numdate, $annee_courante = null): string {
917
-	return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]);
917
+    return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]);
918 918
 }
919 919
 
920 920
 /**
@@ -932,7 +932,7 @@  discard block
 block discarded – undo
932 932
  *     La date formatée
933 933
  **/
934 934
 function affdate_mois_annee($numdate): string {
935
-	return affdate_base($numdate, 'mois_annee');
935
+    return affdate_base($numdate, 'mois_annee');
936 936
 }
937 937
 
938 938
 /**
@@ -950,16 +950,16 @@  discard block
 block discarded – undo
950 950
  *     La date formatée, sinon ''
951 951
  **/
952 952
 function affdate_heure($numdate): string {
953
-	$date_array = recup_date($numdate);
954
-	if (!$date_array) {
955
-		return '';
956
-	}
957
-	[$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array;
958
-
959
-	return _T('date_fmt_jour_heure', [
960
-		'jour' => affdate($numdate),
961
-		'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes])
962
-	]);
953
+    $date_array = recup_date($numdate);
954
+    if (!$date_array) {
955
+        return '';
956
+    }
957
+    [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array;
958
+
959
+    return _T('date_fmt_jour_heure', [
960
+        'jour' => affdate($numdate),
961
+        'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes])
962
+    ]);
963 963
 }
964 964
 
965 965
 /**
@@ -991,113 +991,113 @@  discard block
 block discarded – undo
991 991
  *     texte de la date
992 992
  */
993 993
 function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = ''): string {
994
-	$abbr = $jour = '';
995
-	$affdate = 'affdate_jourcourt';
996
-	if (str_contains($forme, 'abbr')) {
997
-		$abbr = 'abbr';
998
-	}
999
-	if (str_contains($forme, 'annee')) {
1000
-		$affdate = 'affdate';
1001
-	}
1002
-	if (str_contains($forme, 'jour')) {
1003
-		$jour = 'jour';
1004
-	}
1005
-
1006
-	$dtstart = $dtend = $dtabbr = '';
1007
-	if (str_contains($forme, 'hcal')) {
1008
-		$dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1009
-		$dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1010
-		$dtabbr = '</abbr>';
1011
-	}
1012
-
1013
-	$date_debut = strtotime($date_debut);
1014
-	$date_fin = strtotime($date_fin);
1015
-	$d = date('Y-m-d', $date_debut);
1016
-	$f = date('Y-m-d', $date_fin);
1017
-	$h = ($horaire === 'oui' || $horaire === true);
1018
-	$hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]);
1019
-	$hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]);
1020
-
1021
-	if ($d === $f) { // meme jour
1022
-		$nomjour = nom_jour($d, $abbr);
1023
-		$s = $affdate($d);
1024
-		$s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]);
1025
-		if ($h) {
1026
-			if ($hd === $hf) {
1027
-				// Lundi 20 fevrier a 18h25
1028
-				$s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd]));
1029
-				$s = "$dtstart$s$dtabbr";
1030
-			} else {
1031
-				// Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1032
-				if ($dtabbr && $dtstart && $dtend) {
1033
-					$s = _T(
1034
-						'date_fmt_jour_heure_debut_fin_abbr',
1035
-						[
1036
-						'jour' => spip_ucfirst($s),
1037
-						'heure_debut' => $hd,
1038
-						'heure_fin' => $hf,
1039
-						'dtstart' => $dtstart,
1040
-						'dtend' => $dtend,
1041
-						'dtabbr' => $dtabbr
1042
-						],
1043
-						[
1044
-							'sanitize' => false
1045
-						]
1046
-					);
1047
-				} // Le lundi 20 fevrier de 18h00 a 20h00
1048
-				else {
1049
-					$s = spip_ucfirst(_T(
1050
-						'date_fmt_jour_heure_debut_fin',
1051
-						['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf]
1052
-					));
1053
-				}
1054
-			}
1055
-		} else {
1056
-			$s = $dtabbr && $dtstart
1057
-				? $dtstart . spip_ucfirst($s) . $dtabbr
1058
-				: spip_ucfirst($s);
1059
-		}
1060
-	} else {
1061
-		if (date('Y-m', $date_debut) === date('Y-m', $date_fin)) { // meme annee et mois, jours differents
1062
-			$date_debut = $h
1063
-				? affdate_jourcourt($d, date('Y', $date_fin))
1064
-				: jour($d);
1065
-			$date_fin = $affdate($f);
1066
-			if ($jour) {
1067
-				$nomjour_debut = nom_jour($d, $abbr);
1068
-				$date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1069
-				$nomjour_fin = nom_jour($f, $abbr);
1070
-				$date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1071
-			}
1072
-			if ($h) {
1073
-				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1074
-				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1075
-			}
1076
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1077
-			$date_fin = $dtend . $date_fin . $dtabbr;
1078
-
1079
-			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1080
-		} else {
1081
-			$date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1082
-			$date_fin = $affdate($f);
1083
-			if ($jour) {
1084
-				$nomjour_debut = nom_jour($d, $abbr);
1085
-				$date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1086
-				$nomjour_fin = nom_jour($f, $abbr);
1087
-				$date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1088
-			}
1089
-			if ($h) {
1090
-				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1091
-				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1092
-			}
1093
-
1094
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1095
-			$date_fin = $dtend . $date_fin . $dtabbr;
1096
-			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1097
-		}
1098
-	}
1099
-
1100
-	return $s;
994
+    $abbr = $jour = '';
995
+    $affdate = 'affdate_jourcourt';
996
+    if (str_contains($forme, 'abbr')) {
997
+        $abbr = 'abbr';
998
+    }
999
+    if (str_contains($forme, 'annee')) {
1000
+        $affdate = 'affdate';
1001
+    }
1002
+    if (str_contains($forme, 'jour')) {
1003
+        $jour = 'jour';
1004
+    }
1005
+
1006
+    $dtstart = $dtend = $dtabbr = '';
1007
+    if (str_contains($forme, 'hcal')) {
1008
+        $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1009
+        $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1010
+        $dtabbr = '</abbr>';
1011
+    }
1012
+
1013
+    $date_debut = strtotime($date_debut);
1014
+    $date_fin = strtotime($date_fin);
1015
+    $d = date('Y-m-d', $date_debut);
1016
+    $f = date('Y-m-d', $date_fin);
1017
+    $h = ($horaire === 'oui' || $horaire === true);
1018
+    $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]);
1019
+    $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]);
1020
+
1021
+    if ($d === $f) { // meme jour
1022
+        $nomjour = nom_jour($d, $abbr);
1023
+        $s = $affdate($d);
1024
+        $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]);
1025
+        if ($h) {
1026
+            if ($hd === $hf) {
1027
+                // Lundi 20 fevrier a 18h25
1028
+                $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd]));
1029
+                $s = "$dtstart$s$dtabbr";
1030
+            } else {
1031
+                // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1032
+                if ($dtabbr && $dtstart && $dtend) {
1033
+                    $s = _T(
1034
+                        'date_fmt_jour_heure_debut_fin_abbr',
1035
+                        [
1036
+                        'jour' => spip_ucfirst($s),
1037
+                        'heure_debut' => $hd,
1038
+                        'heure_fin' => $hf,
1039
+                        'dtstart' => $dtstart,
1040
+                        'dtend' => $dtend,
1041
+                        'dtabbr' => $dtabbr
1042
+                        ],
1043
+                        [
1044
+                            'sanitize' => false
1045
+                        ]
1046
+                    );
1047
+                } // Le lundi 20 fevrier de 18h00 a 20h00
1048
+                else {
1049
+                    $s = spip_ucfirst(_T(
1050
+                        'date_fmt_jour_heure_debut_fin',
1051
+                        ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf]
1052
+                    ));
1053
+                }
1054
+            }
1055
+        } else {
1056
+            $s = $dtabbr && $dtstart
1057
+                ? $dtstart . spip_ucfirst($s) . $dtabbr
1058
+                : spip_ucfirst($s);
1059
+        }
1060
+    } else {
1061
+        if (date('Y-m', $date_debut) === date('Y-m', $date_fin)) { // meme annee et mois, jours differents
1062
+            $date_debut = $h
1063
+                ? affdate_jourcourt($d, date('Y', $date_fin))
1064
+                : jour($d);
1065
+            $date_fin = $affdate($f);
1066
+            if ($jour) {
1067
+                $nomjour_debut = nom_jour($d, $abbr);
1068
+                $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1069
+                $nomjour_fin = nom_jour($f, $abbr);
1070
+                $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1071
+            }
1072
+            if ($h) {
1073
+                $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1074
+                $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1075
+            }
1076
+            $date_debut = $dtstart . $date_debut . $dtabbr;
1077
+            $date_fin = $dtend . $date_fin . $dtabbr;
1078
+
1079
+            $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1080
+        } else {
1081
+            $date_debut = affdate_jourcourt($d, date('Y', $date_fin));
1082
+            $date_fin = $affdate($f);
1083
+            if ($jour) {
1084
+                $nomjour_debut = nom_jour($d, $abbr);
1085
+                $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]);
1086
+                $nomjour_fin = nom_jour($f, $abbr);
1087
+                $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]);
1088
+            }
1089
+            if ($h) {
1090
+                $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1091
+                $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1092
+            }
1093
+
1094
+            $date_debut = $dtstart . $date_debut . $dtabbr;
1095
+            $date_fin = $dtend . $date_fin . $dtabbr;
1096
+            $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1097
+        }
1098
+    }
1099
+
1100
+    return $s;
1101 1101
 }
1102 1102
 
1103 1103
 /**
@@ -1118,10 +1118,10 @@  discard block
 block discarded – undo
1118 1118
  *     Date au format ical
1119 1119
  **/
1120 1120
 function date_ical($date, $addminutes = 0): string {
1121
-	[$heures, $minutes, $secondes] = recup_heure($date);
1122
-	[$annee, $mois, $jour] = recup_date($date);
1121
+    [$heures, $minutes, $secondes] = recup_heure($date);
1122
+    [$annee, $mois, $jour] = recup_date($date);
1123 1123
 
1124
-	return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1124
+    return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1125 1125
 }
1126 1126
 
1127 1127
 
@@ -1145,14 +1145,14 @@  discard block
 block discarded – undo
1145 1145
  *     La date formatée
1146 1146
  **/
1147 1147
 function date_iso($date_heure): string {
1148
-	$date = recup_date($date_heure);
1149
-	$annee = $date[0] ?? null;
1150
-	$mois = $date[1] ?? null;
1151
-	$jour = $date[2] ?? null;
1152
-	[$heures, $minutes, $secondes] = recup_heure($date_heure);
1153
-	$time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1154
-
1155
-	return gmdate('Y-m-d\TH:i:s\Z', $time);
1148
+    $date = recup_date($date_heure);
1149
+    $annee = $date[0] ?? null;
1150
+    $mois = $date[1] ?? null;
1151
+    $jour = $date[2] ?? null;
1152
+    [$heures, $minutes, $secondes] = recup_heure($date_heure);
1153
+    $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1154
+
1155
+    return gmdate('Y-m-d\TH:i:s\Z', $time);
1156 1156
 }
1157 1157
 
1158 1158
 /**
@@ -1175,11 +1175,11 @@  discard block
 block discarded – undo
1175 1175
  *     La date formatée
1176 1176
  **/
1177 1177
 function date_822($date_heure): string {
1178
-	[$annee, $mois, $jour] = recup_date($date_heure);
1179
-	[$heures, $minutes, $secondes] = recup_heure($date_heure);
1180
-	$time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1178
+    [$annee, $mois, $jour] = recup_date($date_heure);
1179
+    [$heures, $minutes, $secondes] = recup_heure($date_heure);
1180
+    $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1181 1181
 
1182
-	return date('r', $time);
1182
+    return date('r', $time);
1183 1183
 }
1184 1184
 
1185 1185
 /**
@@ -1195,11 +1195,11 @@  discard block
 block discarded – undo
1195 1195
  *     Date au format `Ymd`
1196 1196
  **/
1197 1197
 function date_anneemoisjour($d): string {
1198
-	if (!$d) {
1199
-		$d = date('Y-m-d');
1200
-	}
1198
+    if (!$d) {
1199
+        $d = date('Y-m-d');
1200
+    }
1201 1201
 
1202
-	return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1202
+    return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1203 1203
 }
1204 1204
 
1205 1205
 /**
@@ -1215,11 +1215,11 @@  discard block
 block discarded – undo
1215 1215
  *     Date au format `Ym`
1216 1216
  **/
1217 1217
 function date_anneemois($d): string {
1218
-	if (!$d) {
1219
-		$d = date('Y-m-d');
1220
-	}
1218
+    if (!$d) {
1219
+        $d = date('Y-m-d');
1220
+    }
1221 1221
 
1222
-	return substr($d, 0, 4) . substr($d, 5, 2);
1222
+    return substr($d, 0, 4) . substr($d, 5, 2);
1223 1223
 }
1224 1224
 
1225 1225
 /**
@@ -1235,13 +1235,13 @@  discard block
 block discarded – undo
1235 1235
  *     Date au lundi de la même semaine au format `Ymd`
1236 1236
  **/
1237 1237
 function date_debut_semaine($annee, $mois, $jour): string {
1238
-	$w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1239
-	if ($w_day == 0) {
1240
-		$w_day = 7;
1241
-	} // Gaffe: le dimanche est zero
1242
-	$debut = $jour - $w_day + 1;
1238
+    $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1239
+    if ($w_day == 0) {
1240
+        $w_day = 7;
1241
+    } // Gaffe: le dimanche est zero
1242
+    $debut = $jour - $w_day + 1;
1243 1243
 
1244
-	return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee));
1244
+    return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee));
1245 1245
 }
1246 1246
 
1247 1247
 /**
@@ -1257,11 +1257,11 @@  discard block
 block discarded – undo
1257 1257
  *     Date au dimanche de la même semaine au format `Ymd`
1258 1258
  **/
1259 1259
 function date_fin_semaine($annee, $mois, $jour): string {
1260
-	$w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1261
-	if ($w_day == 0) {
1262
-		$w_day = 7;
1263
-	} // Gaffe: le dimanche est zero
1264
-	$debut = $jour - $w_day + 1;
1260
+    $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee));
1261
+    if ($w_day == 0) {
1262
+        $w_day = 7;
1263
+    } // Gaffe: le dimanche est zero
1264
+    $debut = $jour - $w_day + 1;
1265 1265
 
1266
-	return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee));
1266
+    return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee));
1267 1267
 }
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
 		}
44 44
 		if (preg_match('#^([12]\d{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
45 45
 			$regs = array_pad($regs, 4, null); // eviter notice php
46
-			$date = $regs[1] . '-00-00' . $regs[3];
46
+			$date = $regs[1].'-00-00'.$regs[3];
47 47
 		} else {
48 48
 			if (preg_match('#^([12]\d{3}[-/][01]?\d)([-/]00)?( [-0-9:]+)?$#', $date, $regs)) {
49 49
 				$regs = array_pad($regs, 4, null); // eviter notice php
50
-				$date = preg_replace('@/@', '-', (string) $regs[1]) . '-00' . $regs[3];
50
+				$date = preg_replace('@/@', '-', (string) $regs[1]).'-00'.$regs[3];
51 51
 			} else {
52 52
 				$date = date('Y-m-d H:i:s', strtotime($date));
53 53
 			}
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	$letexte ??= '';
75 75
 	if (
76 76
 		!$verif_format_date
77
-		|| in_array(strlen($letexte), [10,19]) && preg_match('/^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}:\d{2})?$/', $letexte)
77
+		|| in_array(strlen($letexte), [10, 19]) && preg_match('/^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}:\d{2})?$/', $letexte)
78 78
 	) {
79 79
 		if (strncmp('0000-00-00', $letexte, 10) == 0) {
80 80
 			return '';
@@ -359,39 +359,39 @@  discard block
 block discarded – undo
359 359
 	if ($decal > 3600 * 24 * 30) {
360 360
 		$mois = floor($decal / (3600 * 24 * 30));
361 361
 		$delai = $mois < 2
362
-			? "$mois " . _T('date_un_mois')
363
-			: "$mois " . _T('date_mois');
362
+			? "$mois "._T('date_un_mois')
363
+			: "$mois "._T('date_mois');
364 364
 	} else {
365 365
 		if ($decal > 3600 * 24 * 7) {
366 366
 			$semaines = floor($decal / (3600 * 24 * 7));
367 367
 			$delai = $semaines < 2
368
-				? "$semaines " . _T('date_une_semaine')
369
-				: "$semaines " . _T('date_semaines');
368
+				? "$semaines "._T('date_une_semaine')
369
+				: "$semaines "._T('date_semaines');
370 370
 		} else {
371 371
 			if ($decal > 3600 * 24) {
372 372
 				$jours = floor($decal / (3600 * 24));
373 373
 				if ($jours < 2) {
374 374
 					return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier');
375 375
 				} else {
376
-					$delai = "$jours " . _T('date_jours');
376
+					$delai = "$jours "._T('date_jours');
377 377
 				}
378 378
 			} else {
379 379
 				if ($decal >= 3600) {
380 380
 					$heures = floor($decal / 3600);
381 381
 					$delai = $heures < 2
382
-						? "$heures " . _T('date_une_heure')
383
-						: "$heures " . _T('date_heures');
382
+						? "$heures "._T('date_une_heure')
383
+						: "$heures "._T('date_heures');
384 384
 				} else {
385 385
 					if ($decal >= 60) {
386 386
 						$minutes = floor($decal / 60);
387 387
 						$delai = $minutes < 2
388
-							? "$minutes " . _T('date_une_minute')
389
-							: "$minutes " . _T('date_minutes');
388
+							? "$minutes "._T('date_une_minute')
389
+							: "$minutes "._T('date_minutes');
390 390
 					} else {
391 391
 						$secondes = ceil($decal);
392 392
 						$delai = $secondes < 2
393
-							? "$secondes " . _T('date_une_seconde')
394
-							: "$secondes " . _T('date_secondes');
393
+							? "$secondes "._T('date_une_seconde')
394
+							: "$secondes "._T('date_secondes');
395 395
 					}
396 396
 				}
397 397
 			}
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 		$njour = 0;
482 482
 	} else {
483 483
 		$njour = (int) $jour;
484
-		if ($jourth = _T('date_jnum' . $jour)) {
484
+		if ($jourth = _T('date_jnum'.$jour)) {
485 485
 			$jour = $jourth;
486 486
 		}
487 487
 	}
@@ -489,10 +489,10 @@  discard block
 block discarded – undo
489 489
 	$mois = (int) $mois;
490 490
 	if ($mois > 0 && $mois < 13) {
491 491
 		/* Traiter le cas "abbr" pour les noms de mois */
492
-		$param = ((isset($options['param']) && $options['param'] === 'abbr') ? '_' . $options['param'] : '');
493
-		$nommois = _T('date_mois_' . $mois . $param);
492
+		$param = ((isset($options['param']) && $options['param'] === 'abbr') ? '_'.$options['param'] : '');
493
+		$nommois = _T('date_mois_'.$mois.$param);
494 494
 		$jourmois = $jour
495
-			? _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois])
495
+			? _T('date_de_mois_'.$mois, ['j' => $jour, 'nommois' => $nommois])
496 496
 			: $nommois;
497 497
 	} else {
498 498
 		$nommois = '';
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 	}
501 501
 
502 502
 	if ($annee < 0) {
503
-		$annee = -$annee . ' ' . _T('date_avant_jc');
503
+		$annee = -$annee.' '._T('date_avant_jc');
504 504
 		$avjc = true;
505 505
 	} else {
506 506
 		$avjc = false;
@@ -526,11 +526,11 @@  discard block
 block discarded – undo
526 526
 				}
527 527
 			}
528 528
 			if ($vue == 'saison') {
529
-				return $saison ? _T('date_saison_' . $saison) : '';
529
+				return $saison ? _T('date_saison_'.$saison) : '';
530 530
 			} else {
531 531
 				return $saison ? trim((string) _T(
532 532
 					'date_fmt_saison_annee',
533
-					['saison' => _T('date_saison_' . $saison), 'annee' => $annee]
533
+					['saison' => _T('date_saison_'.$saison), 'annee' => $annee]
534 534
 				)) : '';
535 535
 			}
536 536
 
@@ -607,9 +607,9 @@  discard block
 block discarded – undo
607 607
 			}
608 608
 			$nom = mktime(1, 1, 1, $mois, $njour, $annee);
609 609
 			$nom = 1 + (int) date('w', $nom);
610
-			$param = ((isset($options['param']) && $options['param']) ? '_' . $options['param'] : '');
610
+			$param = ((isset($options['param']) && $options['param']) ? '_'.$options['param'] : '');
611 611
 
612
-			return _T('date_jour_' . $nom . $param);
612
+			return _T('date_jour_'.$nom.$param);
613 613
 
614 614
 		case 'mois_annee':
615 615
 			if ($avjc) {
@@ -1005,8 +1005,8 @@  discard block
 block discarded – undo
1005 1005
 
1006 1006
 	$dtstart = $dtend = $dtabbr = '';
1007 1007
 	if (str_contains($forme, 'hcal')) {
1008
-		$dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>";
1009
-		$dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>";
1008
+		$dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>";
1009
+		$dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>";
1010 1010
 		$dtabbr = '</abbr>';
1011 1011
 	}
1012 1012
 
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
 			}
1055 1055
 		} else {
1056 1056
 			$s = $dtabbr && $dtstart
1057
-				? $dtstart . spip_ucfirst($s) . $dtabbr
1057
+				? $dtstart.spip_ucfirst($s).$dtabbr
1058 1058
 				: spip_ucfirst($s);
1059 1059
 		}
1060 1060
 	} else {
@@ -1073,8 +1073,8 @@  discard block
 block discarded – undo
1073 1073
 				$date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]);
1074 1074
 				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1075 1075
 			}
1076
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1077
-			$date_fin = $dtend . $date_fin . $dtabbr;
1076
+			$date_debut = $dtstart.$date_debut.$dtabbr;
1077
+			$date_fin = $dtend.$date_fin.$dtabbr;
1078 1078
 
1079 1079
 			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1080 1080
 		} else {
@@ -1091,8 +1091,8 @@  discard block
 block discarded – undo
1091 1091
 				$date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]);
1092 1092
 			}
1093 1093
 
1094
-			$date_debut = $dtstart . $date_debut . $dtabbr;
1095
-			$date_fin = $dtend . $date_fin . $dtabbr;
1094
+			$date_debut = $dtstart.$date_debut.$dtabbr;
1095
+			$date_fin = $dtend.$date_fin.$dtabbr;
1096 1096
 			$s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]);
1097 1097
 		}
1098 1098
 	}
@@ -1199,7 +1199,7 @@  discard block
 block discarded – undo
1199 1199
 		$d = date('Y-m-d');
1200 1200
 	}
1201 1201
 
1202
-	return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2);
1202
+	return substr($d, 0, 4).substr($d, 5, 2).substr($d, 8, 2);
1203 1203
 }
1204 1204
 
1205 1205
 /**
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
 		$d = date('Y-m-d');
1220 1220
 	}
1221 1221
 
1222
-	return substr($d, 0, 4) . substr($d, 5, 2);
1222
+	return substr($d, 0, 4).substr($d, 5, 2);
1223 1223
 }
1224 1224
 
1225 1225
 /**
Please login to merge, or discard this patch.
ecrire/inc/chercher_logo.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Logos
16 16
  **/
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 /**
@@ -34,23 +34,23 @@  discard block
 block discarded – undo
34 34
  **/
35 35
 function inc_chercher_logo_dist(int $id, string $_id_objet, string $mode = 'on', bool $compat_old_logos = false): array {
36 36
 
37
-	$mode = preg_replace(',\W,', '', $mode);
38
-	if ($mode) {
39
-		// chercher dans la base
40
-		$mode_document = 'logo' . $mode;
41
-		$objet = objet_type($_id_objet);
42
-		$doc = sql_fetsel(
43
-			'D.*',
44
-			'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document',
45
-			'D.mode=' . sql_quote($mode_document) . ' AND L.objet=' . sql_quote($objet) . ' AND id_objet=' . $id
46
-		);
47
-		if ($doc) {
48
-			include_spip('inc/documents');
49
-			$d = get_spip_doc($doc['fichier']);
50
-			return [$d, _DIR_IMG, basename($d), $doc['extension'], @filemtime($d), $doc];
51
-		}
52
-	}
37
+    $mode = preg_replace(',\W,', '', $mode);
38
+    if ($mode) {
39
+        // chercher dans la base
40
+        $mode_document = 'logo' . $mode;
41
+        $objet = objet_type($_id_objet);
42
+        $doc = sql_fetsel(
43
+            'D.*',
44
+            'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document',
45
+            'D.mode=' . sql_quote($mode_document) . ' AND L.objet=' . sql_quote($objet) . ' AND id_objet=' . $id
46
+        );
47
+        if ($doc) {
48
+            include_spip('inc/documents');
49
+            $d = get_spip_doc($doc['fichier']);
50
+            return [$d, _DIR_IMG, basename($d), $doc['extension'], @filemtime($d), $doc];
51
+        }
52
+    }
53 53
 
54
-	# coherence de type pour servir comme filtre (formulaire_login)
55
-	return [];
54
+    # coherence de type pour servir comme filtre (formulaire_login)
55
+    return [];
56 56
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,12 +37,12 @@
 block discarded – undo
37 37
 	$mode = preg_replace(',\W,', '', $mode);
38 38
 	if ($mode) {
39 39
 		// chercher dans la base
40
-		$mode_document = 'logo' . $mode;
40
+		$mode_document = 'logo'.$mode;
41 41
 		$objet = objet_type($_id_objet);
42 42
 		$doc = sql_fetsel(
43 43
 			'D.*',
44 44
 			'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document',
45
-			'D.mode=' . sql_quote($mode_document) . ' AND L.objet=' . sql_quote($objet) . ' AND id_objet=' . $id
45
+			'D.mode='.sql_quote($mode_document).' AND L.objet='.sql_quote($objet).' AND id_objet='.$id
46 46
 		);
47 47
 		if ($doc) {
48 48
 			include_spip('inc/documents');
Please login to merge, or discard this patch.