Completed
Push — master ( 9b54d2...c65e43 )
by cam
01:57
created
ecrire/inc/envoyer_mail.php 2 patches
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Mail
16 16
  **/
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 include_spip('inc/charsets');
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
  * @return string
32 32
  */
33 33
 function nettoyer_titre_email($titre) {
34
-	return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre))));
34
+    return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre))));
35 35
 }
36 36
 
37 37
 /**
@@ -47,21 +47,21 @@  discard block
 block discarded – undo
47 47
  */
48 48
 function nettoyer_caracteres_mail($t) {
49 49
 
50
-	$t = filtrer_entites($t);
51
-
52
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
53
-		$t = str_replace(
54
-			['’', '“', '”'],
55
-			["'", '"', '"'],
56
-			$t
57
-		);
58
-	}
59
-
60
-	return str_replace(
61
-		['—', '&endash;'],
62
-		['--', '-'],
63
-		$t
64
-	);
50
+    $t = filtrer_entites($t);
51
+
52
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
53
+        $t = str_replace(
54
+            ['’', '“', '”'],
55
+            ["'", '"', '"'],
56
+            $t
57
+        );
58
+    }
59
+
60
+    return str_replace(
61
+        ['—', '&endash;'],
62
+        ['--', '-'],
63
+        $t
64
+    );
65 65
 }
66 66
 
67 67
 /**
@@ -94,87 +94,87 @@  discard block
 block discarded – undo
94 94
  */
95 95
 function inc_envoyer_mail_dist($destinataire, $sujet, $corps, $from = '', $headers = '') {
96 96
 
97
-	if (!email_valide($destinataire)) {
98
-		return false;
99
-	}
100
-	if ($destinataire == _T('info_mail_fournisseur')) {
101
-		return false;
102
-	} // tres fort
103
-
104
-	// Fournir si possible un Message-Id: conforme au RFC1036,
105
-	// sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
106
-
107
-	$email_envoi = $GLOBALS['meta']['email_envoi'];
108
-	if (!email_valide($email_envoi)) {
109
-		spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.');
110
-		$email_envoi = $destinataire;
111
-	}
112
-
113
-	$parts = '';
114
-	if (is_array($corps)) {
115
-		$texte = $corps['texte'];
116
-		$from = ($corps['from'] ?? $from);
117
-		$headers = ($corps['headers'] ?? $headers);
118
-		if (is_array($headers)) {
119
-			$headers = implode("\n", $headers);
120
-		}
121
-		if (isset($corps['pieces_jointes']) && function_exists('mail_embarquer_pieces_jointes')) {
122
-			$parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
123
-		}
124
-	} else {
125
-		$texte = $corps;
126
-	}
127
-
128
-	if (!$from) {
129
-		$from = $email_envoi;
130
-	}
131
-
132
-	// ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
133
-	if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', (string) $from)) {
134
-		$from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', (string) $from))) . ')';
135
-	}
136
-
137
-	// nettoyer les &eacute; &#8217, &emdash; etc...
138
-	// les 'cliquer ici' etc sont a eviter;  voir:
139
-	// http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf
140
-	$texte = nettoyer_caracteres_mail($texte);
141
-	$sujet = nettoyer_caracteres_mail($sujet);
142
-
143
-	// encoder le sujet si possible selon la RFC
144
-	if (init_mb_string()) {
145
-		# un bug de mb_string casse mb_encode_mimeheader si l'encoding interne
146
-		# est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian)
147
-		$charset = $GLOBALS['meta']['charset'];
148
-		mb_internal_encoding($charset);
149
-		$sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n");
150
-		mb_internal_encoding('utf-8');
151
-	}
152
-
153
-	$headers ??= '';
154
-	if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', (string) $headers) == 0)) {
155
-		$texte = wordwrap($texte);
156
-	}
157
-
158
-	[$headers, $texte] = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
159
-
160
-	if (_OS_SERVEUR == 'windows') {
161
-		$texte = preg_replace("@\r*\n@", "\r\n", (string) $texte);
162
-		$headers = preg_replace("@\r*\n@", "\r\n", (string) $headers);
163
-		$sujet = preg_replace("@\r*\n@", "\r\n", $sujet);
164
-	}
165
-
166
-	spip_log("mail $destinataire\n$sujet\n$headers", 'mails');
167
-	// mode TEST : forcer l'email
168
-	if (defined('_TEST_EMAIL_DEST')) {
169
-		if (!_TEST_EMAIL_DEST) {
170
-			return false;
171
-		} else {
172
-			$texte = "Dest : $destinataire\r\n" . $texte;
173
-			$destinataire = _TEST_EMAIL_DEST;
174
-		}
175
-	}
176
-
177
-	return @mail((string) $destinataire, $sujet, (string) $texte, $headers);
97
+    if (!email_valide($destinataire)) {
98
+        return false;
99
+    }
100
+    if ($destinataire == _T('info_mail_fournisseur')) {
101
+        return false;
102
+    } // tres fort
103
+
104
+    // Fournir si possible un Message-Id: conforme au RFC1036,
105
+    // sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER
106
+
107
+    $email_envoi = $GLOBALS['meta']['email_envoi'];
108
+    if (!email_valide($email_envoi)) {
109
+        spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.');
110
+        $email_envoi = $destinataire;
111
+    }
112
+
113
+    $parts = '';
114
+    if (is_array($corps)) {
115
+        $texte = $corps['texte'];
116
+        $from = ($corps['from'] ?? $from);
117
+        $headers = ($corps['headers'] ?? $headers);
118
+        if (is_array($headers)) {
119
+            $headers = implode("\n", $headers);
120
+        }
121
+        if (isset($corps['pieces_jointes']) && function_exists('mail_embarquer_pieces_jointes')) {
122
+            $parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']);
123
+        }
124
+    } else {
125
+        $texte = $corps;
126
+    }
127
+
128
+    if (!$from) {
129
+        $from = $email_envoi;
130
+    }
131
+
132
+    // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
133
+    if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', (string) $from)) {
134
+        $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', (string) $from))) . ')';
135
+    }
136
+
137
+    // nettoyer les &eacute; &#8217, &emdash; etc...
138
+    // les 'cliquer ici' etc sont a eviter;  voir:
139
+    // http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf
140
+    $texte = nettoyer_caracteres_mail($texte);
141
+    $sujet = nettoyer_caracteres_mail($sujet);
142
+
143
+    // encoder le sujet si possible selon la RFC
144
+    if (init_mb_string()) {
145
+        # un bug de mb_string casse mb_encode_mimeheader si l'encoding interne
146
+        # est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian)
147
+        $charset = $GLOBALS['meta']['charset'];
148
+        mb_internal_encoding($charset);
149
+        $sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n");
150
+        mb_internal_encoding('utf-8');
151
+    }
152
+
153
+    $headers ??= '';
154
+    if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', (string) $headers) == 0)) {
155
+        $texte = wordwrap($texte);
156
+    }
157
+
158
+    [$headers, $texte] = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts);
159
+
160
+    if (_OS_SERVEUR == 'windows') {
161
+        $texte = preg_replace("@\r*\n@", "\r\n", (string) $texte);
162
+        $headers = preg_replace("@\r*\n@", "\r\n", (string) $headers);
163
+        $sujet = preg_replace("@\r*\n@", "\r\n", $sujet);
164
+    }
165
+
166
+    spip_log("mail $destinataire\n$sujet\n$headers", 'mails');
167
+    // mode TEST : forcer l'email
168
+    if (defined('_TEST_EMAIL_DEST')) {
169
+        if (!_TEST_EMAIL_DEST) {
170
+            return false;
171
+        } else {
172
+            $texte = "Dest : $destinataire\r\n" . $texte;
173
+            $destinataire = _TEST_EMAIL_DEST;
174
+        }
175
+    }
176
+
177
+    return @mail((string) $destinataire, $sujet, (string) $texte, $headers);
178 178
 }
179 179
 
180 180
 /**
@@ -188,53 +188,53 @@  discard block
 block discarded – undo
188 188
  * @return array
189 189
  */
190 190
 function mail_normaliser_headers($headers, $from, $to, $texte, $parts = '') {
191
-	$charset = $GLOBALS['meta']['charset'];
192
-
193
-	// Ajouter le Content-Type et consort s'il n'y est pas deja
194
-	if (!str_contains($headers, 'Content-Type: ')) {
195
-		$type =
196
-			"Content-Type: text/plain;charset=\"$charset\";\n" .
197
-			"Content-Transfer-Encoding: 8bit\n";
198
-	} else {
199
-		$type = '';
200
-	}
201
-
202
-	// calculer un identifiant unique
203
-	// Marie Toto <[email protected]> => @toto.com
204
-	$domain = preg_match('/@[^\s>]+/', $from, $domain) ? $domain[0] : '@unknown-' . md5($from) . '.org';
205
-	$uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain;
206
-
207
-	// Si multi-part, s'en servir comme borne ...
208
-	if ($parts) {
209
-		$texte = "--$uniq\n$type\n" . $texte . "\n";
210
-		foreach ($parts as $part) {
211
-			$n = strlen((string) $part[1]) . ($part[0] ? "\n" : '');
212
-			$e = implode("\n", $part[0]);
213
-			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
214
-		}
215
-		$texte .= "\n\n--$uniq--\n";
216
-		// Si boundary n'est pas entre guillemets,
217
-		// elle est comprise mais le charset est ignoree !
218
-		$type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n";
219
-	}
220
-
221
-	// .. et s'en servir pour plaire a SpamAssassin
222
-
223
-	$mid = 'Message-Id: <' . $uniq . '>';
224
-
225
-	// indispensable pour les sites qui collent d'office From: serveur-http
226
-	// sauf si deja mis par l'envoyeur
227
-	$rep = (str_contains($headers, 'Reply-To:')) ? '' : "Reply-To: $from\n";
228
-
229
-	// Nettoyer les en-tetes envoyees
230
-	// Ajouter le \n final
231
-	if (strlen($headers = trim($headers))) {
232
-		$headers .= "\n";
233
-	}
234
-
235
-	// Et mentionner l'indeboulonable nomenclature ratee
236
-
237
-	$headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n";
238
-
239
-	return [$headers, $texte];
191
+    $charset = $GLOBALS['meta']['charset'];
192
+
193
+    // Ajouter le Content-Type et consort s'il n'y est pas deja
194
+    if (!str_contains($headers, 'Content-Type: ')) {
195
+        $type =
196
+            "Content-Type: text/plain;charset=\"$charset\";\n" .
197
+            "Content-Transfer-Encoding: 8bit\n";
198
+    } else {
199
+        $type = '';
200
+    }
201
+
202
+    // calculer un identifiant unique
203
+    // Marie Toto <[email protected]> => @toto.com
204
+    $domain = preg_match('/@[^\s>]+/', $from, $domain) ? $domain[0] : '@unknown-' . md5($from) . '.org';
205
+    $uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain;
206
+
207
+    // Si multi-part, s'en servir comme borne ...
208
+    if ($parts) {
209
+        $texte = "--$uniq\n$type\n" . $texte . "\n";
210
+        foreach ($parts as $part) {
211
+            $n = strlen((string) $part[1]) . ($part[0] ? "\n" : '');
212
+            $e = implode("\n", $part[0]);
213
+            $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
214
+        }
215
+        $texte .= "\n\n--$uniq--\n";
216
+        // Si boundary n'est pas entre guillemets,
217
+        // elle est comprise mais le charset est ignoree !
218
+        $type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n";
219
+    }
220
+
221
+    // .. et s'en servir pour plaire a SpamAssassin
222
+
223
+    $mid = 'Message-Id: <' . $uniq . '>';
224
+
225
+    // indispensable pour les sites qui collent d'office From: serveur-http
226
+    // sauf si deja mis par l'envoyeur
227
+    $rep = (str_contains($headers, 'Reply-To:')) ? '' : "Reply-To: $from\n";
228
+
229
+    // Nettoyer les en-tetes envoyees
230
+    // Ajouter le \n final
231
+    if (strlen($headers = trim($headers))) {
232
+        $headers .= "\n";
233
+    }
234
+
235
+    // Et mentionner l'indeboulonable nomenclature ratee
236
+
237
+    $headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n";
238
+
239
+    return [$headers, $texte];
240 240
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 
132 132
 	// ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin
133 133
 	if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', (string) $from)) {
134
-		$from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', (string) $from))) . ')';
134
+		$from .= ' ('.str_replace(')', '', translitteration(str_replace('@', ' at ', (string) $from))).')';
135 135
 	}
136 136
 
137 137
 	// nettoyer les &eacute; &#8217, &emdash; etc...
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 		if (!_TEST_EMAIL_DEST) {
170 170
 			return false;
171 171
 		} else {
172
-			$texte = "Dest : $destinataire\r\n" . $texte;
172
+			$texte = "Dest : $destinataire\r\n".$texte;
173 173
 			$destinataire = _TEST_EMAIL_DEST;
174 174
 		}
175 175
 	}
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 	// Ajouter le Content-Type et consort s'il n'y est pas deja
194 194
 	if (!str_contains($headers, 'Content-Type: ')) {
195 195
 		$type =
196
-			"Content-Type: text/plain;charset=\"$charset\";\n" .
196
+			"Content-Type: text/plain;charset=\"$charset\";\n".
197 197
 			"Content-Transfer-Encoding: 8bit\n";
198 198
 	} else {
199 199
 		$type = '';
@@ -201,16 +201,16 @@  discard block
 block discarded – undo
201 201
 
202 202
 	// calculer un identifiant unique
203 203
 	// Marie Toto <[email protected]> => @toto.com
204
-	$domain = preg_match('/@[^\s>]+/', $from, $domain) ? $domain[0] : '@unknown-' . md5($from) . '.org';
205
-	$uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain;
204
+	$domain = preg_match('/@[^\s>]+/', $from, $domain) ? $domain[0] : '@unknown-'.md5($from).'.org';
205
+	$uniq = random_int(0, mt_getrandmax()).'_'.md5($to.$texte).$domain;
206 206
 
207 207
 	// Si multi-part, s'en servir comme borne ...
208 208
 	if ($parts) {
209
-		$texte = "--$uniq\n$type\n" . $texte . "\n";
209
+		$texte = "--$uniq\n$type\n".$texte."\n";
210 210
 		foreach ($parts as $part) {
211
-			$n = strlen((string) $part[1]) . ($part[0] ? "\n" : '');
211
+			$n = strlen((string) $part[1]).($part[0] ? "\n" : '');
212 212
 			$e = implode("\n", $part[0]);
213
-			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1];
213
+			$texte .= "\n--$uniq\nContent-Length: $n$e\n\n".$part[1];
214 214
 		}
215 215
 		$texte .= "\n\n--$uniq--\n";
216 216
 		// Si boundary n'est pas entre guillemets,
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 
221 221
 	// .. et s'en servir pour plaire a SpamAssassin
222 222
 
223
-	$mid = 'Message-Id: <' . $uniq . '>';
223
+	$mid = 'Message-Id: <'.$uniq.'>';
224 224
 
225 225
 	// indispensable pour les sites qui collent d'office From: serveur-http
226 226
 	// sauf si deja mis par l'envoyeur
Please login to merge, or discard this patch.
ecrire/inc/lien_court.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 /*
@@ -21,12 +21,12 @@  discard block
 block discarded – undo
21 21
  * http://zoumzamzouilam/truc/chose/machin..."
22 22
  */
23 23
 function inc_lien_court($url) {
24
-	$long_url = defined('_MAX_LONG_URL') ? _MAX_LONG_URL : 40;
25
-	$coupe_url = defined('_MAX_COUPE_URL') ? _MAX_COUPE_URL : 35;
24
+    $long_url = defined('_MAX_LONG_URL') ? _MAX_LONG_URL : 40;
25
+    $coupe_url = defined('_MAX_COUPE_URL') ? _MAX_COUPE_URL : 35;
26 26
 
27
-	if (strlen((string) $url) > $long_url) {
28
-		$url = substr((string) $url, 0, $coupe_url) . '...';
29
-	}
27
+    if (strlen((string) $url) > $long_url) {
28
+        $url = substr((string) $url, 0, $coupe_url) . '...';
29
+    }
30 30
 
31
-	return $url;
31
+    return $url;
32 32
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
 	$coupe_url = defined('_MAX_COUPE_URL') ? _MAX_COUPE_URL : 35;
26 26
 
27 27
 	if (strlen((string) $url) > $long_url) {
28
-		$url = substr((string) $url, 0, $coupe_url) . '...';
28
+		$url = substr((string) $url, 0, $coupe_url).'...';
29 29
 	}
30 30
 
31 31
 	return $url;
Please login to merge, or discard this patch.
ecrire/inc/lien.php 2 patches
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 \***************************************************************************/
11 11
 
12 12
 if (!defined('_ECRIRE_INC_VERSION')) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 include_spip('base/abstract_sql');
@@ -36,42 +36,42 @@  discard block
 block discarded – undo
36 36
  * @return string
37 37
  */
38 38
 function inc_lien_dist(
39
-	$lien,
40
-	$texte = '',
41
-	$class = '',
42
-	$title = '',
43
-	$hlang = '',
44
-	$rel = '',
45
-	string $connect = '',
46
-	$env = []
39
+    $lien,
40
+    $texte = '',
41
+    $class = '',
42
+    $title = '',
43
+    $hlang = '',
44
+    $rel = '',
45
+    string $connect = '',
46
+    $env = []
47 47
 ) {
48
-	return $lien;
48
+    return $lien;
49 49
 }
50 50
 
51 51
 function expanser_liens($t, string $connect = '', $env = []) {
52 52
 
53
-	$t = pipeline('pre_liens', $t);
53
+    $t = pipeline('pre_liens', $t);
54 54
 
55
-	// on passe a traiter_modeles la liste des liens reperes pour lui permettre
56
-	// de remettre le texte d'origine dans les parametres du modele
57
-	$t = traiter_modeles($t, false, false, $connect);
55
+    // on passe a traiter_modeles la liste des liens reperes pour lui permettre
56
+    // de remettre le texte d'origine dans les parametres du modele
57
+    $t = traiter_modeles($t, false, false, $connect);
58 58
 
59
-	return $t;
59
+    return $t;
60 60
 }
61 61
 
62 62
 // Meme analyse mais pour eliminer les liens
63 63
 // et ne laisser que leur titre, a expliciter si ce n'est fait
64 64
 function nettoyer_raccourcis_typo($texte, string $connect = '') {
65
-	return $texte;
65
+    return $texte;
66 66
 }
67 67
 
68 68
 // Repere dans la partie texte d'un raccourci [texte->...]
69 69
 // la langue et la bulle eventuelles
70 70
 function traiter_raccourci_lien_atts($texte) {
71
-	$bulle = '';
72
-	$hlang = '';
71
+    $bulle = '';
72
+    $hlang = '';
73 73
 
74
-	return [trim((string) $texte), $bulle, $hlang];
74
+    return [trim((string) $texte), $bulle, $hlang];
75 75
 }
76 76
 
77 77
 define('_RACCOURCI_CHAPO', '/^(\W*)(\W*)(\w*\d+([?#].*)?)$/');
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
  * @return string
88 88
  */
89 89
 function virtuel_redirige($virtuel, $url = false) {
90
-	return $virtuel;
90
+    return $virtuel;
91 91
 }
92 92
 
93 93
 // Cherche un lien du type [->raccourci 123]
@@ -100,56 +100,56 @@  discard block
 block discarded – undo
100 100
 // 'url':   seulement U  (i.e. generer_url_RACCOURCI)
101 101
 
102 102
 function calculer_url($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) {
103
-	$r = traiter_lien_implicite($ref, $texte, $pour, $connect);
103
+    $r = traiter_lien_implicite($ref, $texte, $pour, $connect);
104 104
 
105
-	return $r ?: traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo);
105
+    return $r ?: traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo);
106 106
 }
107 107
 
108 108
 define('_EXTRAIRE_LIEN', ',^\s*(?:' . _PROTOCOLES_STD . '):?/?/?\s*$,iS');
109 109
 
110 110
 function traiter_lien_explicite($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) {
111
-	if (preg_match(_EXTRAIRE_LIEN, (string) $ref)) {
112
-		return ($pour != 'tout') ? '' : ['', '', '', ''];
113
-	}
114
-
115
-	$lien = entites_html(trim((string) $ref));
116
-
117
-	// Liens explicites
118
-	if (!$texte) {
119
-		$texte = str_replace('"', '', (string) $lien);
120
-		// evite l'affichage de trops longues urls.
121
-		$lien_court = charger_fonction('lien_court', 'inc');
122
-		$texte = $lien_court($texte);
123
-		if ($echappe_typo) {
124
-			$texte = '<html>' . quote_amp($texte) . '</html>';
125
-		}
126
-	}
127
-
128
-	// petites corrections d'URL
129
-	if (preg_match('/^www\.[^@]+$/S', (string) $lien)) {
130
-		$lien = 'http://' . $lien;
131
-	} else {
132
-		if (strpos((string) $lien, '@') && email_valide($lien)) {
133
-			if (!$texte) {
134
-				$texte = $lien;
135
-			}
136
-			$lien = 'mailto:' . $lien;
137
-		}
138
-	}
139
-
140
-	if ($pour == 'url') {
141
-		return $lien;
142
-	}
143
-
144
-	if ($pour == 'titre') {
145
-		return $texte;
146
-	}
147
-
148
-	return ['url' => $lien, 'titre' => $texte];
111
+    if (preg_match(_EXTRAIRE_LIEN, (string) $ref)) {
112
+        return ($pour != 'tout') ? '' : ['', '', '', ''];
113
+    }
114
+
115
+    $lien = entites_html(trim((string) $ref));
116
+
117
+    // Liens explicites
118
+    if (!$texte) {
119
+        $texte = str_replace('"', '', (string) $lien);
120
+        // evite l'affichage de trops longues urls.
121
+        $lien_court = charger_fonction('lien_court', 'inc');
122
+        $texte = $lien_court($texte);
123
+        if ($echappe_typo) {
124
+            $texte = '<html>' . quote_amp($texte) . '</html>';
125
+        }
126
+    }
127
+
128
+    // petites corrections d'URL
129
+    if (preg_match('/^www\.[^@]+$/S', (string) $lien)) {
130
+        $lien = 'http://' . $lien;
131
+    } else {
132
+        if (strpos((string) $lien, '@') && email_valide($lien)) {
133
+            if (!$texte) {
134
+                $texte = $lien;
135
+            }
136
+            $lien = 'mailto:' . $lien;
137
+        }
138
+    }
139
+
140
+    if ($pour == 'url') {
141
+        return $lien;
142
+    }
143
+
144
+    if ($pour == 'titre') {
145
+        return $texte;
146
+    }
147
+
148
+    return ['url' => $lien, 'titre' => $texte];
149 149
 }
150 150
 
151 151
 function liens_implicite_glose_dist($texte, $id, $type, $args, $ancre, string $connect = '') {
152
-	return function_exists($f = 'glossaire_' . $ancre) ? $f($texte, $id) : glossaire_std($texte);
152
+    return function_exists($f = 'glossaire_' . $ancre) ? $f($texte, $id) : glossaire_std($texte);
153 153
 }
154 154
 
155 155
 /**
@@ -171,73 +171,73 @@  discard block
 block discarded – undo
171 171
  * @return array|bool|string
172 172
  */
173 173
 function traiter_lien_implicite($ref, $texte = '', $pour = 'url', $connect = '') {
174
-	$cible = $GLOBALS['lien_implicite_cible_public'] ?? null;
175
-	if (!($match = typer_raccourci($ref))) {
176
-		return false;
177
-	}
178
-
179
-	[$type, , $id, , $args, , $ancre] = array_pad($match, 7, null);
180
-
181
-	# attention dans le cas des sites le lien doit pointer non pas sur
182
-	# la page locale du site, mais directement sur le site lui-meme
183
-	$url = '';
184
-	if ($f = charger_fonction("implicite_$type", 'liens', true)) {
185
-		$url = $f($texte, $id, $type, $args, $ancre, $connect);
186
-	}
187
-
188
-	if (!$url) {
189
-		$url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', $cible, '', $connect ?? '');
190
-	}
191
-
192
-	if (!$url) {
193
-		return false;
194
-	}
195
-
196
-	if (is_array($url)) {
197
-		[$type, $id] = array_pad($url, 2, null);
198
-		$url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', $cible, '', $connect ?? '');
199
-	}
200
-
201
-	if ($pour === 'url') {
202
-		return $url;
203
-	}
204
-
205
-	$r = traiter_raccourci_titre($id, $type, $connect);
206
-	if ($r) {
207
-		$r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in';
208
-	}
209
-
210
-	if ($texte = trim($texte)) {
211
-		$r['titre'] = $texte;
212
-	}
213
-
214
-	if (!@$r['titre']) {
215
-		$r['titre'] = _T($type) . " $id";
216
-	}
217
-
218
-	if ($pour == 'titre') {
219
-		return $r['titre'];
220
-	}
221
-
222
-	$r['url'] = $url;
223
-
224
-	// dans le cas d'un lien vers un doc, ajouter le type='mime/type'
225
-	if (
226
-		$type == 'document' && ($mime = sql_getfetsel(
227
-			'mime_type',
228
-			'spip_types_documents',
229
-			'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')',
230
-			'',
231
-			'',
232
-			'',
233
-			'',
234
-			$connect
235
-		))
236
-	) {
237
-		$r['mime'] = $mime;
238
-	}
239
-
240
-	return $r;
174
+    $cible = $GLOBALS['lien_implicite_cible_public'] ?? null;
175
+    if (!($match = typer_raccourci($ref))) {
176
+        return false;
177
+    }
178
+
179
+    [$type, , $id, , $args, , $ancre] = array_pad($match, 7, null);
180
+
181
+    # attention dans le cas des sites le lien doit pointer non pas sur
182
+    # la page locale du site, mais directement sur le site lui-meme
183
+    $url = '';
184
+    if ($f = charger_fonction("implicite_$type", 'liens', true)) {
185
+        $url = $f($texte, $id, $type, $args, $ancre, $connect);
186
+    }
187
+
188
+    if (!$url) {
189
+        $url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', $cible, '', $connect ?? '');
190
+    }
191
+
192
+    if (!$url) {
193
+        return false;
194
+    }
195
+
196
+    if (is_array($url)) {
197
+        [$type, $id] = array_pad($url, 2, null);
198
+        $url = generer_objet_url($id, $type, $args ?? '', $ancre ?? '', $cible, '', $connect ?? '');
199
+    }
200
+
201
+    if ($pour === 'url') {
202
+        return $url;
203
+    }
204
+
205
+    $r = traiter_raccourci_titre($id, $type, $connect);
206
+    if ($r) {
207
+        $r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in';
208
+    }
209
+
210
+    if ($texte = trim($texte)) {
211
+        $r['titre'] = $texte;
212
+    }
213
+
214
+    if (!@$r['titre']) {
215
+        $r['titre'] = _T($type) . " $id";
216
+    }
217
+
218
+    if ($pour == 'titre') {
219
+        return $r['titre'];
220
+    }
221
+
222
+    $r['url'] = $url;
223
+
224
+    // dans le cas d'un lien vers un doc, ajouter le type='mime/type'
225
+    if (
226
+        $type == 'document' && ($mime = sql_getfetsel(
227
+            'mime_type',
228
+            'spip_types_documents',
229
+            'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')',
230
+            '',
231
+            '',
232
+            '',
233
+            '',
234
+            $connect
235
+        ))
236
+    ) {
237
+        $r['mime'] = $mime;
238
+    }
239
+
240
+    return $r;
241 241
 }
242 242
 
243 243
 // analyse des raccourcis issus de [TITRE->RACCOURCInnn] et connexes
@@ -245,43 +245,43 @@  discard block
 block discarded – undo
245 245
 define('_RACCOURCI_URL', '/^\s*(\w*?)\s*(\d+)(\?(.*?))?(#([^\s]*))?\s*$/S');
246 246
 
247 247
 function typer_raccourci($lien) {
248
-	if (!preg_match(_RACCOURCI_URL, (string) $lien, $match)) {
249
-		return [];
250
-	}
251
-
252
-	$f = $match[1];
253
-	// valeur par defaut et alias historiques
254
-	if (!$f) {
255
-		$f = 'article';
256
-	} else {
257
-		if ($f == 'art') {
258
-			$f = 'article';
259
-		} else {
260
-			if ($f == 'br') {
261
-				$f = 'breve';
262
-			} else {
263
-				if ($f == 'rub') {
264
-					$f = 'rubrique';
265
-				} else {
266
-					if ($f == 'aut') {
267
-						$f = 'auteur';
268
-					} else {
269
-						if ($f == 'doc' || $f == 'im' || $f == 'img' || $f == 'image' || $f == 'emb') {
270
-							$f = 'document';
271
-						} else {
272
-							if (preg_match('/^br..?ve$/S', $f)) {
273
-								$f = 'breve'; # accents :(
274
-							}
275
-						}
276
-					}
277
-				}
278
-			}
279
-		}
280
-	}
281
-
282
-	$match[0] = $f;
283
-
284
-	return $match;
248
+    if (!preg_match(_RACCOURCI_URL, (string) $lien, $match)) {
249
+        return [];
250
+    }
251
+
252
+    $f = $match[1];
253
+    // valeur par defaut et alias historiques
254
+    if (!$f) {
255
+        $f = 'article';
256
+    } else {
257
+        if ($f == 'art') {
258
+            $f = 'article';
259
+        } else {
260
+            if ($f == 'br') {
261
+                $f = 'breve';
262
+            } else {
263
+                if ($f == 'rub') {
264
+                    $f = 'rubrique';
265
+                } else {
266
+                    if ($f == 'aut') {
267
+                        $f = 'auteur';
268
+                    } else {
269
+                        if ($f == 'doc' || $f == 'im' || $f == 'img' || $f == 'image' || $f == 'emb') {
270
+                            $f = 'document';
271
+                        } else {
272
+                            if (preg_match('/^br..?ve$/S', $f)) {
273
+                                $f = 'breve'; # accents :(
274
+                            }
275
+                        }
276
+                    }
277
+                }
278
+            }
279
+        }
280
+    }
281
+
282
+    $match[0] = $f;
283
+
284
+    return $match;
285 285
 }
286 286
 
287 287
 /**
@@ -296,44 +296,44 @@  discard block
 block discarded – undo
296 296
  * }
297 297
  **/
298 298
 function traiter_raccourci_titre($id, $type, $connect = null) {
299
-	$trouver_table = charger_fonction('trouver_table', 'base');
300
-	$desc = $trouver_table(table_objet($type));
299
+    $trouver_table = charger_fonction('trouver_table', 'base');
300
+    $desc = $trouver_table(table_objet($type));
301 301
 
302
-	if (!($desc && ($s = $desc['titre']))) {
303
-		return [];
304
-	}
302
+    if (!($desc && ($s = $desc['titre']))) {
303
+        return [];
304
+    }
305 305
 
306
-	$_id = $desc['key']['PRIMARY KEY'];
307
-	$r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect);
306
+    $_id = $desc['key']['PRIMARY KEY'];
307
+    $r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect);
308 308
 
309
-	if (!$r) {
310
-		return [];
311
-	}
309
+    if (!$r) {
310
+        return [];
311
+    }
312 312
 
313
-	$r['titre'] = supprimer_numero($r['titre']);
313
+    $r['titre'] = supprimer_numero($r['titre']);
314 314
 
315
-	if (!$r['titre'] && !empty($r['surnom'])) {
316
-		$r['titre'] = $r['surnom'];
317
-	}
315
+    if (!$r['titre'] && !empty($r['surnom'])) {
316
+        $r['titre'] = $r['surnom'];
317
+    }
318 318
 
319
-	if (!isset($r['lang'])) {
320
-		$r['lang'] = '';
321
-	}
319
+    if (!isset($r['lang'])) {
320
+        $r['lang'] = '';
321
+    }
322 322
 
323
-	return $r;
323
+    return $r;
324 324
 }
325 325
 
326 326
 //
327 327
 // Raccourcis ancre [#ancre<-]
328 328
 //
329 329
 function traiter_raccourci_ancre($letexte) {
330
-	return $letexte;
330
+    return $letexte;
331 331
 }
332 332
 
333 333
 function traiter_raccourci_glossaire($texte) {
334
-	return $texte;
334
+    return $texte;
335 335
 }
336 336
 
337 337
 function glossaire_std($terme) {
338
-	return $terme;
338
+    return $terme;
339 339
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	return $r ?: traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo);
106 106
 }
107 107
 
108
-define('_EXTRAIRE_LIEN', ',^\s*(?:' . _PROTOCOLES_STD . '):?/?/?\s*$,iS');
108
+define('_EXTRAIRE_LIEN', ',^\s*(?:'._PROTOCOLES_STD.'):?/?/?\s*$,iS');
109 109
 
110 110
 function traiter_lien_explicite($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) {
111 111
 	if (preg_match(_EXTRAIRE_LIEN, (string) $ref)) {
@@ -121,19 +121,19 @@  discard block
 block discarded – undo
121 121
 		$lien_court = charger_fonction('lien_court', 'inc');
122 122
 		$texte = $lien_court($texte);
123 123
 		if ($echappe_typo) {
124
-			$texte = '<html>' . quote_amp($texte) . '</html>';
124
+			$texte = '<html>'.quote_amp($texte).'</html>';
125 125
 		}
126 126
 	}
127 127
 
128 128
 	// petites corrections d'URL
129 129
 	if (preg_match('/^www\.[^@]+$/S', (string) $lien)) {
130
-		$lien = 'http://' . $lien;
130
+		$lien = 'http://'.$lien;
131 131
 	} else {
132 132
 		if (strpos((string) $lien, '@') && email_valide($lien)) {
133 133
 			if (!$texte) {
134 134
 				$texte = $lien;
135 135
 			}
136
-			$lien = 'mailto:' . $lien;
136
+			$lien = 'mailto:'.$lien;
137 137
 		}
138 138
 	}
139 139
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 }
150 150
 
151 151
 function liens_implicite_glose_dist($texte, $id, $type, $args, $ancre, string $connect = '') {
152
-	return function_exists($f = 'glossaire_' . $ancre) ? $f($texte, $id) : glossaire_std($texte);
152
+	return function_exists($f = 'glossaire_'.$ancre) ? $f($texte, $id) : glossaire_std($texte);
153 153
 }
154 154
 
155 155
 /**
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 		return false;
177 177
 	}
178 178
 
179
-	[$type, , $id, , $args, , $ancre] = array_pad($match, 7, null);
179
+	[$type,, $id,, $args,, $ancre] = array_pad($match, 7, null);
180 180
 
181 181
 	# attention dans le cas des sites le lien doit pointer non pas sur
182 182
 	# la page locale du site, mais directement sur le site lui-meme
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 	}
213 213
 
214 214
 	if (!@$r['titre']) {
215
-		$r['titre'] = _T($type) . " $id";
215
+		$r['titre'] = _T($type)." $id";
216 216
 	}
217 217
 
218 218
 	if ($pour == 'titre') {
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 		$type == 'document' && ($mime = sql_getfetsel(
227 227
 			'mime_type',
228 228
 			'spip_types_documents',
229
-			'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')',
229
+			'extension IN ('.sql_get_select('extension', 'spip_documents', 'id_document='.sql_quote($id)).')',
230 230
 			'',
231 231
 			'',
232 232
 			'',
Please login to merge, or discard this patch.
ecrire/inc/boutons.php 2 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  */
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 
24 24
 /**
@@ -34,35 +34,35 @@  discard block
 block discarded – undo
34 34
  */
35 35
 function definir_barre_onglets($script) {
36 36
 
37
-	$onglets = [];
38
-	$liste_onglets = [];
37
+    $onglets = [];
38
+    $liste_onglets = [];
39 39
 
40
-	// ajouter les onglets issus des plugin via paquet.xml
41
-	if (function_exists('onglets_plugins')) {
42
-		$liste_onglets = onglets_plugins();
43
-	}
40
+    // ajouter les onglets issus des plugin via paquet.xml
41
+    if (function_exists('onglets_plugins')) {
42
+        $liste_onglets = onglets_plugins();
43
+    }
44 44
 
45 45
 
46
-	foreach ($liste_onglets as $id => $infos) {
47
-		if (
48
-			($parent = $infos['parent'])
49
-			&& $parent == $script
50
-			&& autoriser('onglet', "_$id")
51
-		) {
52
-			$onglets[$id] = new Bouton(
53
-				isset($infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
54
-				$infos['titre'],  // titre
55
-				(isset($infos['action']) && $infos['action'])
56
-					? generer_url_ecrire(
57
-						$infos['action'],
58
-						(isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : ''
59
-					)
60
-					: null
61
-			);
62
-		}
63
-	}
46
+    foreach ($liste_onglets as $id => $infos) {
47
+        if (
48
+            ($parent = $infos['parent'])
49
+            && $parent == $script
50
+            && autoriser('onglet', "_$id")
51
+        ) {
52
+            $onglets[$id] = new Bouton(
53
+                isset($infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
54
+                $infos['titre'],  // titre
55
+                (isset($infos['action']) && $infos['action'])
56
+                    ? generer_url_ecrire(
57
+                        $infos['action'],
58
+                        (isset($infos['parametres']) && $infos['parametres']) ? $infos['parametres'] : ''
59
+                    )
60
+                    : null
61
+            );
62
+        }
63
+    }
64 64
 
65
-	return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]);
65
+    return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]);
66 66
 }
67 67
 
68 68
 /**
@@ -80,14 +80,14 @@  discard block
 block discarded – undo
80 80
  * @return string
81 81
  */
82 82
 function barre_onglets($rubrique, $ongletCourant, $class = 'barre_onglet') {
83
-	include_spip('inc/presentation');
83
+    include_spip('inc/presentation');
84 84
 
85
-	$res = '';
85
+    $res = '';
86 86
 
87
-	foreach (definir_barre_onglets($rubrique) as $exec => $onglet) {
88
-		$url = $onglet->url ?: generer_url_ecrire($exec);
89
-		$res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone);
90
-	}
87
+    foreach (definir_barre_onglets($rubrique) as $exec => $onglet) {
88
+        $url = $onglet->url ?: generer_url_ecrire($exec);
89
+        $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone);
90
+    }
91 91
 
92
-	return $res ? debut_onglet($class) . $res . fin_onglet() : ('');
92
+    return $res ? debut_onglet($class) . $res . fin_onglet() : ('');
93 93
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 			&& autoriser('onglet', "_$id")
51 51
 		) {
52 52
 			$onglets[$id] = new Bouton(
53
-				isset($infos['icone']) ? find_in_theme($infos['icone']) : '',  // icone
54
-				$infos['titre'],  // titre
53
+				isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone
54
+				$infos['titre'], // titre
55 55
 				(isset($infos['action']) && $infos['action'])
56 56
 					? generer_url_ecrire(
57 57
 						$infos['action'],
@@ -89,5 +89,5 @@  discard block
 block discarded – undo
89 89
 		$res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone);
90 90
 	}
91 91
 
92
-	return $res ? debut_onglet($class) . $res . fin_onglet() : ('');
92
+	return $res ? debut_onglet($class).$res.fin_onglet() : ('');
93 93
 }
Please login to merge, or discard this patch.
ecrire/inc/invalideur.php 2 patches
Indentation   +137 added lines, -137 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('base/serial');
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
  * en droit de l'éliminer
27 27
  */
28 28
 if (!defined('_AGE_CACHE_ATIME')) {
29
-	define('_AGE_CACHE_ATIME', 3600);
29
+    define('_AGE_CACHE_ATIME', 3600);
30 30
 }
31 31
 
32 32
 
@@ -39,31 +39,31 @@  discard block
 block discarded – undo
39 39
  * @return int Taille approximative en octets
40 40
  **/
41 41
 function taille_du_cache() {
42
-	# check dirs until we reach > 500 files
43
-	$t = 0;
44
-	$n = 0;
45
-	$time = $GLOBALS['meta']['cache_mark'] ?? 0;
46
-	for ($i = 0; $i < 256; $i++) {
47
-		$dir = _DIR_CACHE . sprintf('%02s', dechex($i));
48
-		if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) {
49
-			while (($f = readdir($d)) !== false) {
50
-				if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) && ($a = stat("$dir/$f"))) {
51
-					$n++;
52
-					if ($a['mtime'] >= $time) {
53
-						if ($a['blocks'] > 0) {
54
-							$t += 512 * $a['blocks'];
55
-						} else {
56
-							$t += $a['size'];
57
-						}
58
-					}
59
-				}
60
-			}
61
-		}
62
-		if ($n > 500) {
63
-			return (int) (256 * $t / (1 + $i));
64
-		}
65
-	}
66
-	return $t;
42
+    # check dirs until we reach > 500 files
43
+    $t = 0;
44
+    $n = 0;
45
+    $time = $GLOBALS['meta']['cache_mark'] ?? 0;
46
+    for ($i = 0; $i < 256; $i++) {
47
+        $dir = _DIR_CACHE . sprintf('%02s', dechex($i));
48
+        if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) {
49
+            while (($f = readdir($d)) !== false) {
50
+                if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) && ($a = stat("$dir/$f"))) {
51
+                    $n++;
52
+                    if ($a['mtime'] >= $time) {
53
+                        if ($a['blocks'] > 0) {
54
+                            $t += 512 * $a['blocks'];
55
+                        } else {
56
+                            $t += $a['size'];
57
+                        }
58
+                    }
59
+                }
60
+            }
61
+        }
62
+        if ($n > 500) {
63
+            return (int) (256 * $t / (1 + $i));
64
+        }
65
+    }
66
+    return $t;
67 67
 }
68 68
 
69 69
 
@@ -90,30 +90,30 @@  discard block
 block discarded – undo
90 90
  *     Inutilisé
91 91
  **/
92 92
 function inc_suivre_invalideur_dist($cond, $modif = true) {
93
-	if (!$modif) {
94
-		return;
95
-	}
96
-
97
-	// determiner l'objet modifie : forum, article, etc
98
-	if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) {
99
-		$objet = objet_type($r[1]);
100
-	}
101
-
102
-	// stocker la date_modif_$objet (ne sert a rien pour le moment)
103
-	if (isset($objet)) {
104
-		ecrire_meta('derniere_modif_' . $objet, time());
105
-	}
106
-
107
-	// si $derniere_modif_invalide est un array('article', 'rubrique')
108
-	// n'affecter la meta que si un de ces objets est modifie
109
-	if (is_array($GLOBALS['derniere_modif_invalide'])) {
110
-		if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) {
111
-			ecrire_meta('derniere_modif', time());
112
-		}
113
-	} // sinon, cas standard, toujours affecter la meta
114
-	else {
115
-		ecrire_meta('derniere_modif', time());
116
-	}
93
+    if (!$modif) {
94
+        return;
95
+    }
96
+
97
+    // determiner l'objet modifie : forum, article, etc
98
+    if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) {
99
+        $objet = objet_type($r[1]);
100
+    }
101
+
102
+    // stocker la date_modif_$objet (ne sert a rien pour le moment)
103
+    if (isset($objet)) {
104
+        ecrire_meta('derniere_modif_' . $objet, time());
105
+    }
106
+
107
+    // si $derniere_modif_invalide est un array('article', 'rubrique')
108
+    // n'affecter la meta que si un de ces objets est modifie
109
+    if (is_array($GLOBALS['derniere_modif_invalide'])) {
110
+        if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) {
111
+            ecrire_meta('derniere_modif', time());
112
+        }
113
+    } // sinon, cas standard, toujours affecter la meta
114
+    else {
115
+        ecrire_meta('derniere_modif', time());
116
+    }
117 117
 }
118 118
 
119 119
 
@@ -138,56 +138,56 @@  discard block
 block discarded – undo
138 138
  *     Nombre de fichiers supprimés
139 139
  **/
140 140
 function purger_repertoire($dir, $options = []) {
141
-	if (!is_dir($dir) || !is_readable($dir)) {
142
-		return 0;
143
-	}
144
-
145
-	// sur certains sites on veut absolument garder certains caches référencés dans un CDN
146
-	// on peut donc inhiber la purge de ces répertoires pour eviter tout probleme
147
-	if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) {
148
-		return 0;
149
-	}
150
-
151
-	$handle = opendir($dir);
152
-	if (!$handle) {
153
-		return 0;
154
-	}
155
-
156
-	$total = 0;
157
-
158
-	while (($fichier = @readdir($handle)) !== false) {
159
-		// Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG
160
-		if ($fichier[0] == '.' || $fichier == 'CACHEDIR.TAG') {
161
-			continue;
162
-		}
163
-		$chemin = "$dir/$fichier";
164
-		if (is_file($chemin)) {
165
-			if (
166
-				(!isset($options['atime']) || @fileatime($chemin) < $options['atime']) && (!isset($options['mtime']) || @filemtime($chemin) < $options['mtime'])
167
-			) {
168
-				supprimer_fichier($chemin);
169
-				$total++;
170
-			}
171
-		} else {
172
-			if (is_dir($chemin)) {
173
-				$opts = $options;
174
-				if (isset($options['limit'])) {
175
-					$opts['limit'] = $options['limit'] - $total;
176
-				}
177
-				$total += purger_repertoire($chemin, $opts);
178
-				if (isset($options['subdir']) && $options['subdir']) {
179
-					spip_unlink($chemin);
180
-				}
181
-			}
182
-		}
183
-
184
-		if (isset($options['limit']) && $total >= $options['limit']) {
185
-			break;
186
-		}
187
-	}
188
-	closedir($handle);
189
-
190
-	return $total;
141
+    if (!is_dir($dir) || !is_readable($dir)) {
142
+        return 0;
143
+    }
144
+
145
+    // sur certains sites on veut absolument garder certains caches référencés dans un CDN
146
+    // on peut donc inhiber la purge de ces répertoires pour eviter tout probleme
147
+    if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) {
148
+        return 0;
149
+    }
150
+
151
+    $handle = opendir($dir);
152
+    if (!$handle) {
153
+        return 0;
154
+    }
155
+
156
+    $total = 0;
157
+
158
+    while (($fichier = @readdir($handle)) !== false) {
159
+        // Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG
160
+        if ($fichier[0] == '.' || $fichier == 'CACHEDIR.TAG') {
161
+            continue;
162
+        }
163
+        $chemin = "$dir/$fichier";
164
+        if (is_file($chemin)) {
165
+            if (
166
+                (!isset($options['atime']) || @fileatime($chemin) < $options['atime']) && (!isset($options['mtime']) || @filemtime($chemin) < $options['mtime'])
167
+            ) {
168
+                supprimer_fichier($chemin);
169
+                $total++;
170
+            }
171
+        } else {
172
+            if (is_dir($chemin)) {
173
+                $opts = $options;
174
+                if (isset($options['limit'])) {
175
+                    $opts['limit'] = $options['limit'] - $total;
176
+                }
177
+                $total += purger_repertoire($chemin, $opts);
178
+                if (isset($options['subdir']) && $options['subdir']) {
179
+                    spip_unlink($chemin);
180
+                }
181
+            }
182
+        }
183
+
184
+        if (isset($options['limit']) && $total >= $options['limit']) {
185
+            break;
186
+        }
187
+    }
188
+    closedir($handle);
189
+
190
+    return $total;
191 191
 }
192 192
 
193 193
 
@@ -198,26 +198,26 @@  discard block
 block discarded – undo
198 198
 // Securite : est sur que c'est un cache
199 199
 function retire_cache($cache) {
200 200
 
201
-	if (
202
-		preg_match(
203
-			',^([0-9a-f]/)?(\d+/)?[0-9a-f]+\.cache(\.gz)?$,i',
204
-			(string) $cache
205
-		)
206
-	) {
207
-		// supprimer le fichier (de facon propre)
208
-		supprimer_fichier(_DIR_CACHE . $cache);
209
-	} else {
210
-		spip_log("Nom de fichier cache incorrect : $cache");
211
-	}
201
+    if (
202
+        preg_match(
203
+            ',^([0-9a-f]/)?(\d+/)?[0-9a-f]+\.cache(\.gz)?$,i',
204
+            (string) $cache
205
+        )
206
+    ) {
207
+        // supprimer le fichier (de facon propre)
208
+        supprimer_fichier(_DIR_CACHE . $cache);
209
+    } else {
210
+        spip_log("Nom de fichier cache incorrect : $cache");
211
+    }
212 212
 }
213 213
 
214 214
 // Supprimer les caches marques "x"
215 215
 // A priori dans cette version la fonction ne sera pas appelee, car
216 216
 // la meta est toujours false ; mais evitons un bug si elle est appellee
217 217
 function inc_retire_caches_dist($chemin = '') {
218
-	if (isset($GLOBALS['meta']['invalider_caches'])) {
219
-		effacer_meta('invalider_caches');
220
-	} # concurrence
218
+    if (isset($GLOBALS['meta']['invalider_caches'])) {
219
+        effacer_meta('invalider_caches');
220
+    } # concurrence
221 221
 }
222 222
 
223 223
 #######################################################################
@@ -228,9 +228,9 @@  discard block
 block discarded – undo
228 228
 ##
229 229
 
230 230
 function retire_caches($chemin = '') {
231
-	if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) {
232
-		return $retire_caches($chemin);
233
-	}
231
+    if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) {
232
+        return $retire_caches($chemin);
233
+    }
234 234
 }
235 235
 
236 236
 
@@ -238,10 +238,10 @@  discard block
 block discarded – undo
238 238
 // (note: si absente, n'est pas appellee)
239 239
 
240 240
 function calcul_invalideurs($corps, $primary, &$boucles, $id_boucle) {
241
-	if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) {
242
-		return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle);
243
-	}
244
-	return $corps;
241
+    if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) {
242
+        return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle);
243
+    }
244
+    return $corps;
245 245
 }
246 246
 
247 247
 
@@ -250,41 +250,41 @@  discard block
 block discarded – undo
250 250
 // invoquee quand on vide tout le cache en bloc (action/purger)
251 251
 //
252 252
 function supprime_invalideurs() {
253
-	if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) {
254
-		return $supprime_invalideurs();
255
-	}
253
+    if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) {
254
+        return $supprime_invalideurs();
255
+    }
256 256
 }
257 257
 
258 258
 
259 259
 // Calcul des pages : noter dans la base les liens d'invalidation
260 260
 function maj_invalideurs($fichier, &$page) {
261
-	if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) {
262
-		return $maj_invalideurs($fichier, $page);
263
-	}
261
+    if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) {
262
+        return $maj_invalideurs($fichier, $page);
263
+    }
264 264
 }
265 265
 
266 266
 
267 267
 // les invalideurs sont de la forme "objet/id_objet"
268 268
 function insere_invalideur($inval, $fichier) {
269
-	if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) {
270
-		return $insere_invalideur($inval, $fichier);
271
-	}
269
+    if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) {
270
+        return $insere_invalideur($inval, $fichier);
271
+    }
272 272
 }
273 273
 
274 274
 //
275 275
 // Marquer les fichiers caches invalides comme etant a supprimer
276 276
 //
277 277
 function applique_invalideur($depart) {
278
-	if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) {
279
-		return $applique_invalideur($depart);
280
-	}
278
+    if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) {
279
+        return $applique_invalideur($depart);
280
+    }
281 281
 }
282 282
 
283 283
 //
284 284
 // Invalider les caches liés à telle condition
285 285
 //
286 286
 function suivre_invalideur($cond, $modif = true) {
287
-	if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) {
288
-		return $suivre_invalideur($cond, $modif);
289
-	}
287
+    if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) {
288
+        return $suivre_invalideur($cond, $modif);
289
+    }
290 290
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	$n = 0;
45 45
 	$time = $GLOBALS['meta']['cache_mark'] ?? 0;
46 46
 	for ($i = 0; $i < 256; $i++) {
47
-		$dir = _DIR_CACHE . sprintf('%02s', dechex($i));
47
+		$dir = _DIR_CACHE.sprintf('%02s', dechex($i));
48 48
 		if (@is_dir($dir) && is_readable($dir) && ($d = opendir($dir))) {
49 49
 			while (($f = readdir($d)) !== false) {
50 50
 				if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) && ($a = stat("$dir/$f"))) {
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 
102 102
 	// stocker la date_modif_$objet (ne sert a rien pour le moment)
103 103
 	if (isset($objet)) {
104
-		ecrire_meta('derniere_modif_' . $objet, time());
104
+		ecrire_meta('derniere_modif_'.$objet, time());
105 105
 	}
106 106
 
107 107
 	// si $derniere_modif_invalide est un array('article', 'rubrique')
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 
145 145
 	// sur certains sites on veut absolument garder certains caches référencés dans un CDN
146 146
 	// on peut donc inhiber la purge de ces répertoires pour eviter tout probleme
147
-	if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) {
147
+	if (file_exists(rtrim($dir, '/').'/inhib_purger_repertoire.txt')) {
148 148
 		return 0;
149 149
 	}
150 150
 
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 		)
206 206
 	) {
207 207
 		// supprimer le fichier (de facon propre)
208
-		supprimer_fichier(_DIR_CACHE . $cache);
208
+		supprimer_fichier(_DIR_CACHE.$cache);
209 209
 	} else {
210 210
 		spip_log("Nom de fichier cache incorrect : $cache");
211 211
 	}
Please login to merge, or discard this patch.
ecrire/inc/charsets.php 2 patches
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 		$charset = 'cp1256';
90 90
 	}
91 91
 
92
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
92
+	if (find_in_path($charset.'.php', 'charsets/', true)) {
93 93
 		return $charset;
94 94
 	} else {
95 95
 		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
@@ -190,38 +190,38 @@  discard block
 block discarded – undo
190 190
 
191 191
 	if (!isset($trans[$charset][$charset_cible])) {
192 192
 		$trans[$charset][$charset_cible] = [
193
-			$p . chr(128) => '&#8364;',
194
-			$p . chr(129) => ' ', # pas affecte
195
-			$p . chr(130) => '&#8218;',
196
-			$p . chr(131) => '&#402;',
197
-			$p . chr(132) => '&#8222;',
198
-			$p . chr(133) => '&#8230;',
199
-			$p . chr(134) => '&#8224;',
200
-			$p . chr(135) => '&#8225;',
201
-			$p . chr(136) => '&#710;',
202
-			$p . chr(137) => '&#8240;',
203
-			$p . chr(138) => '&#352;',
204
-			$p . chr(139) => '&#8249;',
205
-			$p . chr(140) => '&#338;',
206
-			$p . chr(141) => ' ', # pas affecte
207
-			$p . chr(142) => '&#381;',
208
-			$p . chr(143) => ' ', # pas affecte
209
-			$p . chr(144) => ' ', # pas affecte
210
-			$p . chr(145) => '&#8216;',
211
-			$p . chr(146) => '&#8217;',
212
-			$p . chr(147) => '&#8220;',
213
-			$p . chr(148) => '&#8221;',
214
-			$p . chr(149) => '&#8226;',
215
-			$p . chr(150) => '&#8211;',
216
-			$p . chr(151) => '&#8212;',
217
-			$p . chr(152) => '&#732;',
218
-			$p . chr(153) => '&#8482;',
219
-			$p . chr(154) => '&#353;',
220
-			$p . chr(155) => '&#8250;',
221
-			$p . chr(156) => '&#339;',
222
-			$p . chr(157) => ' ', # pas affecte
223
-			$p . chr(158) => '&#382;',
224
-			$p . chr(159) => '&#376;',
193
+			$p.chr(128) => '&#8364;',
194
+			$p.chr(129) => ' ', # pas affecte
195
+			$p.chr(130) => '&#8218;',
196
+			$p.chr(131) => '&#402;',
197
+			$p.chr(132) => '&#8222;',
198
+			$p.chr(133) => '&#8230;',
199
+			$p.chr(134) => '&#8224;',
200
+			$p.chr(135) => '&#8225;',
201
+			$p.chr(136) => '&#710;',
202
+			$p.chr(137) => '&#8240;',
203
+			$p.chr(138) => '&#352;',
204
+			$p.chr(139) => '&#8249;',
205
+			$p.chr(140) => '&#338;',
206
+			$p.chr(141) => ' ', # pas affecte
207
+			$p.chr(142) => '&#381;',
208
+			$p.chr(143) => ' ', # pas affecte
209
+			$p.chr(144) => ' ', # pas affecte
210
+			$p.chr(145) => '&#8216;',
211
+			$p.chr(146) => '&#8217;',
212
+			$p.chr(147) => '&#8220;',
213
+			$p.chr(148) => '&#8221;',
214
+			$p.chr(149) => '&#8226;',
215
+			$p.chr(150) => '&#8211;',
216
+			$p.chr(151) => '&#8212;',
217
+			$p.chr(152) => '&#732;',
218
+			$p.chr(153) => '&#8482;',
219
+			$p.chr(154) => '&#353;',
220
+			$p.chr(155) => '&#8250;',
221
+			$p.chr(156) => '&#339;',
222
+			$p.chr(157) => ' ', # pas affecte
223
+			$p.chr(158) => '&#382;',
224
+			$p.chr(159) => '&#376;',
225 225
 		];
226 226
 		if ($charset_cible != 'unicode') {
227 227
 			foreach ($trans[$charset][$charset_cible] as $k => $c) {
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 			// Sinon, peut-etre connaissons-nous ce charset ?
359 359
 			if (!isset($trans[$charset]) && (($cset = load_charset($charset)) && is_array($GLOBALS['CHARSET'][$cset]))) {
360 360
 				foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
361
-					$trans[$charset][chr($key)] = '&#' . $val . ';';
361
+					$trans[$charset][chr($key)] = '&#'.$val.';';
362 362
 				}
363 363
 			}
364 364
 			if (isset($trans[$charset]) && (is_countable($trans[$charset]) ? count($trans[$charset]) : 0)) {
@@ -423,11 +423,11 @@  discard block
 block discarded – undo
423 423
 					$h = dechex($e);
424 424
 					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
425 425
 						$s = $CHARSET_REVERSE[$charset][$e];
426
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
427
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
426
+						$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($s);
427
+						$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($s);
428 428
 					} else {
429
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
430
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
429
+						$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($e);
430
+						$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($e);
431 431
 					}
432 432
 				}
433 433
 			}
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
 			&& is_array($GLOBALS['CHARSET'][$cset]))
474 474
 		) {
475 475
 			foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
476
-				$trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
476
+				$trans[$charset][chr($key)] = unicode2charset('&#'.$val.';');
477 477
 			}
478 478
 		}
479 479
 		if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) {
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
 				}
580 580
 				$thisPos++;
581 581
 			}
582
-			$encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';';
582
+			$encodedLetter = '&#'.preg_replace('/^0+/', '', $decimalCode).';';
583 583
 			$encodedString .= $encodedLetter;
584 584
 		}
585 585
 	}
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
 			} // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
623 623
 			else {
624 624
 				if ($word != 65279) {
625
-					$texte .= '&#' . $word . ';';
625
+					$texte .= '&#'.$word.';';
626 626
 				}
627 627
 			}
628 628
 		}
@@ -650,13 +650,13 @@  discard block
 block discarded – undo
650 650
 		return chr($num);
651 651
 	}
652 652
 	if ($num < 2048) {
653
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
653
+		return chr(($num >> 6) + 192).chr(($num & 63) + 128);
654 654
 	}
655 655
 	if ($num < 65536) {
656
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
656
+		return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
657 657
 	}
658 658
 	if ($num < 1_114_112) {
659
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
659
+		return chr(($num >> 18) + 240).chr((($num >> 12) & 63) + 128).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
660 660
 	}
661 661
 
662 662
 	return '';
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
 	while (preg_match(',&#0*(\d+);,S', $texte, $regs) && !isset($vu[$regs[1]])) {
724 724
 		$num = $regs[1];
725 725
 		$vu[$num] = true;
726
-		$s = '\u' . sprintf('%04x', $num);
726
+		$s = '\u'.sprintf('%04x', $num);
727 727
 		$texte = str_replace($regs[0], $s, $texte);
728 728
 	}
729 729
 
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
  **/
741 741
 function javascript_to_unicode($texte) {
742 742
 	while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) {
743
-		$texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte);
743
+		$texte = str_replace($regs[0], '&#'.hexdec($regs[1]).';', $texte);
744 744
 	}
745 745
 
746 746
 	return $texte;
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
 		return $texte;
786 786
 	}
787 787
 
788
-	$table_translit = 'translit' . $complexe;
788
+	$table_translit = 'translit'.$complexe;
789 789
 
790 790
 	// 2. Translitterer grace a la table predefinie
791 791
 	if (!isset($trans[$complexe])) {
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
  *    true s'il a un BOM
877 877
  **/
878 878
 function bom_utf8($texte): bool {
879
-	return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF));
879
+	return (substr($texte, 0, 3) === chr(0xEF).chr(0xBB).chr(0xBF));
880 880
 }
881 881
 
882 882
 /**
@@ -1043,7 +1043,7 @@  discard block
 block discarded – undo
1043 1043
 
1044 1044
 	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1045 1045
 
1046
-	return $lettre1 . spip_substr($c, 1);
1046
+	return $lettre1.spip_substr($c, 1);
1047 1047
 }
1048 1048
 
1049 1049
 /**
Please login to merge, or discard this patch.
Indentation   +624 added lines, -624 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 
22 22
 // securité
23 23
 if (!defined('_ECRIRE_INC_VERSION')) {
24
-	return;
24
+    return;
25 25
 }
26 26
 
27 27
 // se faciliter la lecture du charset
@@ -31,19 +31,19 @@  discard block
 block discarded – undo
31 31
  * Initialisation
32 32
  */
33 33
 function init_charset(): void {
34
-	// Initialisation
35
-	$GLOBALS['CHARSET'] = [];
36
-
37
-	// noter a l'occasion dans la meta pcre_u notre capacite a utiliser le flag /u
38
-	// dans les preg_replace pour ne pas casser certaines lettres accentuees :
39
-	// en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp
40
-	if (
41
-		!isset($GLOBALS['meta']['pcre_u'])
42
-		|| isset($_GET['var_mode']) && !isset($_GET['var_profile'])
43
-	) {
44
-		include_spip('inc/meta');
45
-		ecrire_meta('pcre_u', (lire_config('charset', _DEFAULT_CHARSET) === 'utf-8') ? 'u' : '');
46
-	}
34
+    // Initialisation
35
+    $GLOBALS['CHARSET'] = [];
36
+
37
+    // noter a l'occasion dans la meta pcre_u notre capacite a utiliser le flag /u
38
+    // dans les preg_replace pour ne pas casser certaines lettres accentuees :
39
+    // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp
40
+    if (
41
+        !isset($GLOBALS['meta']['pcre_u'])
42
+        || isset($_GET['var_mode']) && !isset($_GET['var_profile'])
43
+    ) {
44
+        include_spip('inc/meta');
45
+        ecrire_meta('pcre_u', (lire_config('charset', _DEFAULT_CHARSET) === 'utf-8') ? 'u' : '');
46
+    }
47 47
 }
48 48
 
49 49
 // TODO: code d’exécution en dehors du fichier.
@@ -64,39 +64,39 @@  discard block
 block discarded – undo
64 64
  *     - false si le charset n'est pas décrit dans le répertoire charsets/
65 65
  **/
66 66
 function load_charset($charset = 'AUTO') {
67
-	if ($charset == 'AUTO') {
68
-		$charset = $GLOBALS['meta']['charset'];
69
-	}
70
-	$charset = trim(strtolower((string) $charset));
71
-	if (isset($GLOBALS['CHARSET'][$charset])) {
72
-		return $charset;
73
-	}
74
-
75
-	if ($charset == 'utf-8') {
76
-		$GLOBALS['CHARSET'][$charset] = [];
77
-
78
-		return $charset;
79
-	}
80
-
81
-	// Quelques synonymes
82
-	if ($charset === '') {
83
-		$charset = 'iso-8859-1';
84
-	} elseif ($charset === 'windows-1250') {
85
-		$charset = 'cp1250';
86
-	} elseif ($charset === 'windows-1251') {
87
-		$charset = 'cp1251';
88
-	} elseif ($charset === 'windows-1256') {
89
-		$charset = 'cp1256';
90
-	}
91
-
92
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
93
-		return $charset;
94
-	} else {
95
-		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
96
-		$GLOBALS['CHARSET'][$charset] = [];
97
-
98
-		return false;
99
-	}
67
+    if ($charset == 'AUTO') {
68
+        $charset = $GLOBALS['meta']['charset'];
69
+    }
70
+    $charset = trim(strtolower((string) $charset));
71
+    if (isset($GLOBALS['CHARSET'][$charset])) {
72
+        return $charset;
73
+    }
74
+
75
+    if ($charset == 'utf-8') {
76
+        $GLOBALS['CHARSET'][$charset] = [];
77
+
78
+        return $charset;
79
+    }
80
+
81
+    // Quelques synonymes
82
+    if ($charset === '') {
83
+        $charset = 'iso-8859-1';
84
+    } elseif ($charset === 'windows-1250') {
85
+        $charset = 'cp1250';
86
+    } elseif ($charset === 'windows-1251') {
87
+        $charset = 'cp1251';
88
+    } elseif ($charset === 'windows-1256') {
89
+        $charset = 'cp1256';
90
+    }
91
+
92
+    if (find_in_path($charset . '.php', 'charsets/', true)) {
93
+        return $charset;
94
+    } else {
95
+        spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
96
+        $GLOBALS['CHARSET'][$charset] = [];
97
+
98
+        return false;
99
+    }
100 100
 }
101 101
 
102 102
 
@@ -109,19 +109,19 @@  discard block
 block discarded – undo
109 109
  *     true si notre charset est utilisable par mb_strsing
110 110
  **/
111 111
 function init_mb_string(): bool {
112
-	static $mb;
113
-
114
-	// verifier que le charset interne est connu de mb_string
115
-	if (!$mb) {
116
-		if (mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))) {
117
-			mb_internal_encoding('utf-8');
118
-			$mb = 1;
119
-		} else {
120
-			$mb = -1;
121
-		}
122
-	}
123
-
124
-	return ($mb === 1);
112
+    static $mb;
113
+
114
+    // verifier que le charset interne est connu de mb_string
115
+    if (!$mb) {
116
+        if (mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))) {
117
+            mb_internal_encoding('utf-8');
118
+            $mb = 1;
119
+        } else {
120
+            $mb = -1;
121
+        }
122
+    }
123
+
124
+    return ($mb === 1);
125 125
 }
126 126
 
127 127
 /**
@@ -136,17 +136,17 @@  discard block
 block discarded – undo
136 136
  *     true si iconv fonctionne correctement
137 137
  **/
138 138
 function test_iconv(): bool {
139
-	static $iconv_ok;
139
+    static $iconv_ok;
140 140
 
141
-	if (!$iconv_ok) {
142
-		if (!function_exists('iconv')) {
143
-			$iconv_ok = -1;
144
-		} else {
145
-			$iconv_ok = utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) === 'chaine de test' ? 1 : -1;
146
-		}
147
-	}
141
+    if (!$iconv_ok) {
142
+        if (!function_exists('iconv')) {
143
+            $iconv_ok = -1;
144
+        } else {
145
+            $iconv_ok = utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) === 'chaine de test' ? 1 : -1;
146
+        }
147
+    }
148 148
 
149
-	return ($iconv_ok === 1);
149
+    return ($iconv_ok === 1);
150 150
 }
151 151
 
152 152
 /**
@@ -166,75 +166,75 @@  discard block
 block discarded – undo
166 166
  *     texte corrigé
167 167
  **/
168 168
 function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') {
169
-	static $trans;
170
-
171
-	if (is_array($texte)) {
172
-		return array_map('corriger_caracteres_windows', $texte);
173
-	}
174
-
175
-	if ($charset == 'AUTO') {
176
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
177
-	}
178
-	if ($charset == 'utf-8') {
179
-		$p = chr(194);
180
-		if (!str_contains($texte, $p)) {
181
-			return $texte;
182
-		}
183
-	} else {
184
-		if ($charset == 'iso-8859-1') {
185
-			$p = '';
186
-		} else {
187
-			return $texte;
188
-		}
189
-	}
190
-
191
-	if (!isset($trans[$charset][$charset_cible])) {
192
-		$trans[$charset][$charset_cible] = [
193
-			$p . chr(128) => '&#8364;',
194
-			$p . chr(129) => ' ', # pas affecte
195
-			$p . chr(130) => '&#8218;',
196
-			$p . chr(131) => '&#402;',
197
-			$p . chr(132) => '&#8222;',
198
-			$p . chr(133) => '&#8230;',
199
-			$p . chr(134) => '&#8224;',
200
-			$p . chr(135) => '&#8225;',
201
-			$p . chr(136) => '&#710;',
202
-			$p . chr(137) => '&#8240;',
203
-			$p . chr(138) => '&#352;',
204
-			$p . chr(139) => '&#8249;',
205
-			$p . chr(140) => '&#338;',
206
-			$p . chr(141) => ' ', # pas affecte
207
-			$p . chr(142) => '&#381;',
208
-			$p . chr(143) => ' ', # pas affecte
209
-			$p . chr(144) => ' ', # pas affecte
210
-			$p . chr(145) => '&#8216;',
211
-			$p . chr(146) => '&#8217;',
212
-			$p . chr(147) => '&#8220;',
213
-			$p . chr(148) => '&#8221;',
214
-			$p . chr(149) => '&#8226;',
215
-			$p . chr(150) => '&#8211;',
216
-			$p . chr(151) => '&#8212;',
217
-			$p . chr(152) => '&#732;',
218
-			$p . chr(153) => '&#8482;',
219
-			$p . chr(154) => '&#353;',
220
-			$p . chr(155) => '&#8250;',
221
-			$p . chr(156) => '&#339;',
222
-			$p . chr(157) => ' ', # pas affecte
223
-			$p . chr(158) => '&#382;',
224
-			$p . chr(159) => '&#376;',
225
-		];
226
-		if ($charset_cible != 'unicode') {
227
-			foreach ($trans[$charset][$charset_cible] as $k => $c) {
228
-				$trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
229
-			}
230
-		}
231
-	}
232
-
233
-	return @str_replace(
234
-		array_keys($trans[$charset][$charset_cible]),
235
-		array_values($trans[$charset][$charset_cible]),
236
-		$texte
237
-	);
169
+    static $trans;
170
+
171
+    if (is_array($texte)) {
172
+        return array_map('corriger_caracteres_windows', $texte);
173
+    }
174
+
175
+    if ($charset == 'AUTO') {
176
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
177
+    }
178
+    if ($charset == 'utf-8') {
179
+        $p = chr(194);
180
+        if (!str_contains($texte, $p)) {
181
+            return $texte;
182
+        }
183
+    } else {
184
+        if ($charset == 'iso-8859-1') {
185
+            $p = '';
186
+        } else {
187
+            return $texte;
188
+        }
189
+    }
190
+
191
+    if (!isset($trans[$charset][$charset_cible])) {
192
+        $trans[$charset][$charset_cible] = [
193
+            $p . chr(128) => '&#8364;',
194
+            $p . chr(129) => ' ', # pas affecte
195
+            $p . chr(130) => '&#8218;',
196
+            $p . chr(131) => '&#402;',
197
+            $p . chr(132) => '&#8222;',
198
+            $p . chr(133) => '&#8230;',
199
+            $p . chr(134) => '&#8224;',
200
+            $p . chr(135) => '&#8225;',
201
+            $p . chr(136) => '&#710;',
202
+            $p . chr(137) => '&#8240;',
203
+            $p . chr(138) => '&#352;',
204
+            $p . chr(139) => '&#8249;',
205
+            $p . chr(140) => '&#338;',
206
+            $p . chr(141) => ' ', # pas affecte
207
+            $p . chr(142) => '&#381;',
208
+            $p . chr(143) => ' ', # pas affecte
209
+            $p . chr(144) => ' ', # pas affecte
210
+            $p . chr(145) => '&#8216;',
211
+            $p . chr(146) => '&#8217;',
212
+            $p . chr(147) => '&#8220;',
213
+            $p . chr(148) => '&#8221;',
214
+            $p . chr(149) => '&#8226;',
215
+            $p . chr(150) => '&#8211;',
216
+            $p . chr(151) => '&#8212;',
217
+            $p . chr(152) => '&#732;',
218
+            $p . chr(153) => '&#8482;',
219
+            $p . chr(154) => '&#353;',
220
+            $p . chr(155) => '&#8250;',
221
+            $p . chr(156) => '&#339;',
222
+            $p . chr(157) => ' ', # pas affecte
223
+            $p . chr(158) => '&#382;',
224
+            $p . chr(159) => '&#376;',
225
+        ];
226
+        if ($charset_cible != 'unicode') {
227
+            foreach ($trans[$charset][$charset_cible] as $k => $c) {
228
+                $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
229
+            }
230
+        }
231
+    }
232
+
233
+    return @str_replace(
234
+        array_keys($trans[$charset][$charset_cible]),
235
+        array_values($trans[$charset][$charset_cible]),
236
+        $texte
237
+    );
238 238
 }
239 239
 
240 240
 
@@ -251,26 +251,26 @@  discard block
 block discarded – undo
251 251
  *     texte converti
252 252
  **/
253 253
 function html2unicode($texte, $secure = false) {
254
-	if (!str_contains($texte, '&')) {
255
-		return $texte;
256
-	}
257
-	static $trans = [];
258
-	if (!$trans) {
259
-		load_charset('html');
260
-		foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
261
-			$trans["&$key;"] = $val;
262
-		}
263
-	}
264
-
265
-	$texte = str_replace(array_keys($trans), array_values($trans), $texte);
266
-	if (!$secure) {
267
-		$texte = str_replace(
268
-			['&amp;', '&quot;', '&lt;', '&gt;'],
269
-			['&', '"', '<', '>'],
270
-			$texte
271
-		);
272
-	}
273
-	return $texte;
254
+    if (!str_contains($texte, '&')) {
255
+        return $texte;
256
+    }
257
+    static $trans = [];
258
+    if (!$trans) {
259
+        load_charset('html');
260
+        foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
261
+            $trans["&$key;"] = $val;
262
+        }
263
+    }
264
+
265
+    $texte = str_replace(array_keys($trans), array_values($trans), $texte);
266
+    if (!$secure) {
267
+        $texte = str_replace(
268
+            ['&amp;', '&quot;', '&lt;', '&gt;'],
269
+            ['&', '"', '<', '>'],
270
+            $texte
271
+        );
272
+    }
273
+    return $texte;
274 274
 }
275 275
 
276 276
 
@@ -285,16 +285,16 @@  discard block
 block discarded – undo
285 285
  *     texte converti
286 286
  **/
287 287
 function mathml2unicode($texte) {
288
-	static $trans;
289
-	if (!$trans) {
290
-		load_charset('mathml');
288
+    static $trans;
289
+    if (!$trans) {
290
+        load_charset('mathml');
291 291
 
292
-		foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
293
-			$trans["&$key;"] = $val;
294
-		}
295
-	}
292
+        foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
293
+            $trans["&$key;"] = $val;
294
+        }
295
+    }
296 296
 
297
-	return str_replace(array_keys($trans), array_values($trans), $texte);
297
+    return str_replace(array_keys($trans), array_values($trans), $texte);
298 298
 }
299 299
 
300 300
 
@@ -316,74 +316,74 @@  discard block
 block discarded – undo
316 316
  *     texte converti en unicode
317 317
  **/
318 318
 function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) {
319
-	static $trans;
320
-
321
-	if ($texte === null || $texte === '') {
322
-		return '';
323
-	}
324
-
325
-	if ($charset === 'AUTO') {
326
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
327
-	}
328
-
329
-	if ($charset === '') {
330
-		$charset = 'iso-8859-1';
331
-	}
332
-	$charset = strtolower((string) $charset);
333
-
334
-	switch ($charset) {
335
-		case 'utf-8':
336
-		case 'utf8':
337
-			return utf_8_to_unicode($texte);
338
-
339
-		case 'iso-8859-1':
340
-			$texte = corriger_caracteres_windows($texte, 'iso-8859-1');
341
-		// pas de break; ici, on suit sur default:
342
-
343
-		default:
344
-			// mbstring presente ?
345
-			if (init_mb_string()) {
346
-				$order = mb_detect_order();
347
-				try {
348
-					# mb_string connait-il $charset?
349
-					if ($order && mb_detect_order($charset)) {
350
-						$s = mb_convert_encoding($texte, 'utf-8', $charset);
351
-						if ($s && $s != $texte) {
352
-							return utf_8_to_unicode($s);
353
-						}
354
-					}
355
-				} catch (\Error) {
356
-					// Le charset n'existe probablement pas
357
-				} finally {
358
-					mb_detect_order($order); # remettre comme precedemment
359
-				}
360
-			}
361
-
362
-			// Sinon, peut-etre connaissons-nous ce charset ?
363
-			if (!isset($trans[$charset]) && (($cset = load_charset($charset)) && is_array($GLOBALS['CHARSET'][$cset]))) {
364
-				foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
365
-					$trans[$charset][chr($key)] = '&#' . $val . ';';
366
-				}
367
-			}
368
-			if (isset($trans[$charset]) && (is_countable($trans[$charset]) ? count($trans[$charset]) : 0)) {
369
-				return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
370
-			}
371
-
372
-			// Sinon demander a iconv (malgre le fait qu'il coupe quand un
373
-			// caractere n'appartient pas au charset, mais c'est un probleme
374
-			// surtout en utf-8, gere ci-dessus)
375
-			if (test_iconv()) {
376
-				$s = iconv($charset, 'utf-32le', $texte);
377
-				if ($s) {
378
-					return utf_32_to_unicode($s);
379
-				}
380
-			}
381
-
382
-			// Au pire ne rien faire
383
-			spip_log("erreur charset '$charset' non supporte");
384
-
385
-			return $texte;
386
-	}
319
+    static $trans;
320
+
321
+    if ($texte === null || $texte === '') {
322
+        return '';
323
+    }
324
+
325
+    if ($charset === 'AUTO') {
326
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
327
+    }
328
+
329
+    if ($charset === '') {
330
+        $charset = 'iso-8859-1';
331
+    }
332
+    $charset = strtolower((string) $charset);
333
+
334
+    switch ($charset) {
335
+        case 'utf-8':
336
+        case 'utf8':
337
+            return utf_8_to_unicode($texte);
338
+
339
+        case 'iso-8859-1':
340
+            $texte = corriger_caracteres_windows($texte, 'iso-8859-1');
341
+        // pas de break; ici, on suit sur default:
342
+
343
+        default:
344
+            // mbstring presente ?
345
+            if (init_mb_string()) {
346
+                $order = mb_detect_order();
347
+                try {
348
+                    # mb_string connait-il $charset?
349
+                    if ($order && mb_detect_order($charset)) {
350
+                        $s = mb_convert_encoding($texte, 'utf-8', $charset);
351
+                        if ($s && $s != $texte) {
352
+                            return utf_8_to_unicode($s);
353
+                        }
354
+                    }
355
+                } catch (\Error) {
356
+                    // Le charset n'existe probablement pas
357
+                } finally {
358
+                    mb_detect_order($order); # remettre comme precedemment
359
+                }
360
+            }
361
+
362
+            // Sinon, peut-etre connaissons-nous ce charset ?
363
+            if (!isset($trans[$charset]) && (($cset = load_charset($charset)) && is_array($GLOBALS['CHARSET'][$cset]))) {
364
+                foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
365
+                    $trans[$charset][chr($key)] = '&#' . $val . ';';
366
+                }
367
+            }
368
+            if (isset($trans[$charset]) && (is_countable($trans[$charset]) ? count($trans[$charset]) : 0)) {
369
+                return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
370
+            }
371
+
372
+            // Sinon demander a iconv (malgre le fait qu'il coupe quand un
373
+            // caractere n'appartient pas au charset, mais c'est un probleme
374
+            // surtout en utf-8, gere ci-dessus)
375
+            if (test_iconv()) {
376
+                $s = iconv($charset, 'utf-32le', $texte);
377
+                if ($s) {
378
+                    return utf_32_to_unicode($s);
379
+                }
380
+            }
381
+
382
+            // Au pire ne rien faire
383
+            spip_log("erreur charset '$charset' non supporte");
384
+
385
+            return $texte;
386
+    }
387 387
 }
388 388
 
389 389
 
@@ -402,42 +402,42 @@  discard block
 block discarded – undo
402 402
  *     texte transformé dans le charset souhaité
403 403
  **/
404 404
 function unicode2charset($texte, $charset = 'AUTO') {
405
-	static $CHARSET_REVERSE = [];
406
-	static $trans = [];
407
-
408
-	if ($charset == 'AUTO') {
409
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
410
-	}
411
-
412
-	switch ($charset) {
413
-		case 'utf-8':
414
-			return unicode_to_utf_8($texte);
415
-
416
-		default:
417
-			$charset = load_charset($charset);
418
-
419
-			if (empty($CHARSET_REVERSE[$charset])) {
420
-				$CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
421
-			}
422
-
423
-			if (!isset($trans[$charset])) {
424
-				$trans[$charset] = [];
425
-				$t = &$trans[$charset];
426
-				for ($e = 128; $e < 255; $e++) {
427
-					$h = dechex($e);
428
-					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
429
-						$s = $CHARSET_REVERSE[$charset][$e];
430
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
431
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
432
-					} else {
433
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
434
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
435
-					}
436
-				}
437
-			}
438
-
439
-			return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
440
-	}
405
+    static $CHARSET_REVERSE = [];
406
+    static $trans = [];
407
+
408
+    if ($charset == 'AUTO') {
409
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
410
+    }
411
+
412
+    switch ($charset) {
413
+        case 'utf-8':
414
+            return unicode_to_utf_8($texte);
415
+
416
+        default:
417
+            $charset = load_charset($charset);
418
+
419
+            if (empty($CHARSET_REVERSE[$charset])) {
420
+                $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
421
+            }
422
+
423
+            if (!isset($trans[$charset])) {
424
+                $trans[$charset] = [];
425
+                $t = &$trans[$charset];
426
+                for ($e = 128; $e < 255; $e++) {
427
+                    $h = dechex($e);
428
+                    if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
429
+                        $s = $CHARSET_REVERSE[$charset][$e];
430
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
431
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
432
+                    } else {
433
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
434
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
435
+                    }
436
+                }
437
+            }
438
+
439
+            return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
440
+    }
441 441
 }
442 442
 
443 443
 
@@ -455,39 +455,39 @@  discard block
 block discarded – undo
455 455
  *     texte transformé dans le charset site
456 456
  **/
457 457
 function importer_charset($texte, $charset = 'AUTO') {
458
-	$s = null;
459
-	static $trans = [];
460
-	// on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
461
-	if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
462
-		$texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
463
-		if (init_mb_string()) {
464
-			if (
465
-				($order = mb_detect_order())
466
-				&& mb_detect_order($charset)
467
-			) {
468
-				$s = mb_convert_encoding($texte, 'utf-8', $charset);
469
-			}
470
-			mb_detect_order($order); # remettre comme precedemment
471
-			return $s;
472
-		}
473
-		// Sinon, peut-etre connaissons-nous ce charset ?
474
-		if (
475
-			!isset($trans[$charset])
476
-			&& (($cset = load_charset($charset))
477
-			&& is_array($GLOBALS['CHARSET'][$cset]))
478
-		) {
479
-			foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
480
-				$trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
481
-			}
482
-		}
483
-		if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) {
484
-			return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
485
-		}
486
-
487
-		return $texte;
488
-	}
489
-
490
-	return unicode2charset(charset2unicode($texte, $charset));
458
+    $s = null;
459
+    static $trans = [];
460
+    // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
461
+    if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
462
+        $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
463
+        if (init_mb_string()) {
464
+            if (
465
+                ($order = mb_detect_order())
466
+                && mb_detect_order($charset)
467
+            ) {
468
+                $s = mb_convert_encoding($texte, 'utf-8', $charset);
469
+            }
470
+            mb_detect_order($order); # remettre comme precedemment
471
+            return $s;
472
+        }
473
+        // Sinon, peut-etre connaissons-nous ce charset ?
474
+        if (
475
+            !isset($trans[$charset])
476
+            && (($cset = load_charset($charset))
477
+            && is_array($GLOBALS['CHARSET'][$cset]))
478
+        ) {
479
+            foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
480
+                $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
481
+            }
482
+        }
483
+        if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) {
484
+            return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
485
+        }
486
+
487
+        return $texte;
488
+    }
489
+
490
+    return unicode2charset(charset2unicode($texte, $charset));
491 491
 }
492 492
 
493 493
 
@@ -503,92 +503,92 @@  discard block
 block discarded – undo
503 503
  **/
504 504
 function utf_8_to_unicode($source) {
505 505
 
506
-	// mb_string : methode rapide
507
-	if (init_mb_string()) {
508
-		$convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
509
-
510
-		return mb_encode_numericentity($source, $convmap, 'UTF-8');
511
-	}
512
-
513
-	// Sinon methode pas a pas
514
-	static $decrement;
515
-	static $shift;
516
-
517
-	// Cf. php.net, par Ronen. Adapte pour compatibilite < php4
518
-	if (!is_array($decrement)) {
519
-		// array used to figure what number to decrement from character order value
520
-		// according to number of characters used to map unicode to ascii by utf-8
521
-		$decrement[4] = 240;
522
-		$decrement[3] = 224;
523
-		$decrement[2] = 192;
524
-		$decrement[1] = 0;
525
-		// the number of bits to shift each charNum by
526
-		$shift[1][0] = 0;
527
-		$shift[2][0] = 6;
528
-		$shift[2][1] = 0;
529
-		$shift[3][0] = 12;
530
-		$shift[3][1] = 6;
531
-		$shift[3][2] = 0;
532
-		$shift[4][0] = 18;
533
-		$shift[4][1] = 12;
534
-		$shift[4][2] = 6;
535
-		$shift[4][3] = 0;
536
-	}
537
-
538
-	$pos = 0;
539
-	$len = strlen($source);
540
-	$encodedString = '';
541
-	while ($pos < $len) {
542
-		$char = '';
543
-		$ischar = false;
544
-		$asciiPos = ord(substr($source, $pos, 1));
545
-		if (($asciiPos >= 240) && ($asciiPos <= 255)) {
546
-			// 4 chars representing one unicode character
547
-			$thisLetter = substr($source, $pos, 4);
548
-			$pos += 4;
549
-		} else {
550
-			if (($asciiPos >= 224) && ($asciiPos <= 239)) {
551
-				// 3 chars representing one unicode character
552
-				$thisLetter = substr($source, $pos, 3);
553
-				$pos += 3;
554
-			} else {
555
-				if (($asciiPos >= 192) && ($asciiPos <= 223)) {
556
-					// 2 chars representing one unicode character
557
-					$thisLetter = substr($source, $pos, 2);
558
-					$pos += 2;
559
-				} else {
560
-					// 1 char (lower ascii)
561
-					$thisLetter = substr($source, $pos, 1);
562
-					$pos += 1;
563
-					$char = $thisLetter;
564
-					$ischar = true;
565
-				}
566
-			}
567
-		}
568
-
569
-		if ($ischar) {
570
-			$encodedString .= $char;
571
-		} else {  // process the string representing the letter to a unicode entity
572
-			$thisLen = strlen($thisLetter);
573
-			$thisPos = 0;
574
-			$decimalCode = 0;
575
-			while ($thisPos < $thisLen) {
576
-				$thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
577
-				if ($thisPos == 0) {
578
-					$charNum = (int) ($thisCharOrd - $decrement[$thisLen]);
579
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
580
-				} else {
581
-					$charNum = (int) ($thisCharOrd - 128);
582
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
583
-				}
584
-				$thisPos++;
585
-			}
586
-			$encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';';
587
-			$encodedString .= $encodedLetter;
588
-		}
589
-	}
590
-
591
-	return $encodedString;
506
+    // mb_string : methode rapide
507
+    if (init_mb_string()) {
508
+        $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
509
+
510
+        return mb_encode_numericentity($source, $convmap, 'UTF-8');
511
+    }
512
+
513
+    // Sinon methode pas a pas
514
+    static $decrement;
515
+    static $shift;
516
+
517
+    // Cf. php.net, par Ronen. Adapte pour compatibilite < php4
518
+    if (!is_array($decrement)) {
519
+        // array used to figure what number to decrement from character order value
520
+        // according to number of characters used to map unicode to ascii by utf-8
521
+        $decrement[4] = 240;
522
+        $decrement[3] = 224;
523
+        $decrement[2] = 192;
524
+        $decrement[1] = 0;
525
+        // the number of bits to shift each charNum by
526
+        $shift[1][0] = 0;
527
+        $shift[2][0] = 6;
528
+        $shift[2][1] = 0;
529
+        $shift[3][0] = 12;
530
+        $shift[3][1] = 6;
531
+        $shift[3][2] = 0;
532
+        $shift[4][0] = 18;
533
+        $shift[4][1] = 12;
534
+        $shift[4][2] = 6;
535
+        $shift[4][3] = 0;
536
+    }
537
+
538
+    $pos = 0;
539
+    $len = strlen($source);
540
+    $encodedString = '';
541
+    while ($pos < $len) {
542
+        $char = '';
543
+        $ischar = false;
544
+        $asciiPos = ord(substr($source, $pos, 1));
545
+        if (($asciiPos >= 240) && ($asciiPos <= 255)) {
546
+            // 4 chars representing one unicode character
547
+            $thisLetter = substr($source, $pos, 4);
548
+            $pos += 4;
549
+        } else {
550
+            if (($asciiPos >= 224) && ($asciiPos <= 239)) {
551
+                // 3 chars representing one unicode character
552
+                $thisLetter = substr($source, $pos, 3);
553
+                $pos += 3;
554
+            } else {
555
+                if (($asciiPos >= 192) && ($asciiPos <= 223)) {
556
+                    // 2 chars representing one unicode character
557
+                    $thisLetter = substr($source, $pos, 2);
558
+                    $pos += 2;
559
+                } else {
560
+                    // 1 char (lower ascii)
561
+                    $thisLetter = substr($source, $pos, 1);
562
+                    $pos += 1;
563
+                    $char = $thisLetter;
564
+                    $ischar = true;
565
+                }
566
+            }
567
+        }
568
+
569
+        if ($ischar) {
570
+            $encodedString .= $char;
571
+        } else {  // process the string representing the letter to a unicode entity
572
+            $thisLen = strlen($thisLetter);
573
+            $thisPos = 0;
574
+            $decimalCode = 0;
575
+            while ($thisPos < $thisLen) {
576
+                $thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
577
+                if ($thisPos == 0) {
578
+                    $charNum = (int) ($thisCharOrd - $decrement[$thisLen]);
579
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
580
+                } else {
581
+                    $charNum = (int) ($thisCharOrd - 128);
582
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
583
+                }
584
+                $thisPos++;
585
+            }
586
+            $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';';
587
+            $encodedString .= $encodedLetter;
588
+        }
589
+    }
590
+
591
+    return $encodedString;
592 592
 }
593 593
 
594 594
 /**
@@ -607,32 +607,32 @@  discard block
 block discarded – undo
607 607
  **/
608 608
 function utf_32_to_unicode($source) {
609 609
 
610
-	// mb_string : methode rapide
611
-	if (init_mb_string()) {
612
-		$convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
613
-		$source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
614
-
615
-		return str_replace(chr(0), '', $source);
616
-	}
617
-
618
-	// Sinon methode lente
619
-	$texte = '';
620
-	while ($source) {
621
-		$words = unpack('V*', substr($source, 0, 1024));
622
-		$source = substr($source, 1024);
623
-		foreach ($words as $word) {
624
-			if ($word < 128) {
625
-				$texte .= chr($word);
626
-			} // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
627
-			else {
628
-				if ($word != 65279) {
629
-					$texte .= '&#' . $word . ';';
630
-				}
631
-			}
632
-		}
633
-	}
634
-
635
-	return $texte;
610
+    // mb_string : methode rapide
611
+    if (init_mb_string()) {
612
+        $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
613
+        $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
614
+
615
+        return str_replace(chr(0), '', $source);
616
+    }
617
+
618
+    // Sinon methode lente
619
+    $texte = '';
620
+    while ($source) {
621
+        $words = unpack('V*', substr($source, 0, 1024));
622
+        $source = substr($source, 1024);
623
+        foreach ($words as $word) {
624
+            if ($word < 128) {
625
+                $texte .= chr($word);
626
+            } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
627
+            else {
628
+                if ($word != 65279) {
629
+                    $texte .= '&#' . $word . ';';
630
+                }
631
+            }
632
+        }
633
+    }
634
+
635
+    return $texte;
636 636
 }
637 637
 
638 638
 
@@ -649,21 +649,21 @@  discard block
 block discarded – undo
649 649
  *    Caractère utf8 si trouvé, '' sinon
650 650
  **/
651 651
 function caractere_utf_8($num) {
652
-	$num = (int) $num;
653
-	if ($num < 128) {
654
-		return chr($num);
655
-	}
656
-	if ($num < 2048) {
657
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
658
-	}
659
-	if ($num < 65536) {
660
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
661
-	}
662
-	if ($num < 1_114_112) {
663
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
664
-	}
665
-
666
-	return '';
652
+    $num = (int) $num;
653
+    if ($num < 128) {
654
+        return chr($num);
655
+    }
656
+    if ($num < 2048) {
657
+        return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
658
+    }
659
+    if ($num < 65536) {
660
+        return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
661
+    }
662
+    if ($num < 1_114_112) {
663
+        return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
664
+    }
665
+
666
+    return '';
667 667
 }
668 668
 
669 669
 /**
@@ -676,42 +676,42 @@  discard block
 block discarded – undo
676 676
  **/
677 677
 function unicode_to_utf_8($texte) {
678 678
 
679
-	// 1. Entites &#128; et suivantes
680
-	$vu = [];
681
-	if (
682
-		preg_match_all(
683
-			',&#0*([1-9]\d\d+);,S',
684
-			$texte,
685
-			$regs,
686
-			PREG_SET_ORDER
687
-		)
688
-	) {
689
-		foreach ($regs as $reg) {
690
-			if ($reg[1] > 127 && !isset($vu[$reg[0]])) {
691
-				$vu[$reg[0]] = caractere_utf_8($reg[1]);
692
-			}
693
-		}
694
-	}
695
-	//$texte = str_replace(array_keys($vu), array_values($vu), $texte);
696
-
697
-	// 2. Entites > &#xFF;
698
-	//$vu = array();
699
-	if (
700
-		preg_match_all(
701
-			',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
702
-			$texte,
703
-			$regs,
704
-			PREG_SET_ORDER
705
-		)
706
-	) {
707
-		foreach ($regs as $reg) {
708
-			if (!isset($vu[$reg[0]])) {
709
-				$vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
710
-			}
711
-		}
712
-	}
713
-
714
-	return str_replace(array_keys($vu), array_values($vu), $texte);
679
+    // 1. Entites &#128; et suivantes
680
+    $vu = [];
681
+    if (
682
+        preg_match_all(
683
+            ',&#0*([1-9]\d\d+);,S',
684
+            $texte,
685
+            $regs,
686
+            PREG_SET_ORDER
687
+        )
688
+    ) {
689
+        foreach ($regs as $reg) {
690
+            if ($reg[1] > 127 && !isset($vu[$reg[0]])) {
691
+                $vu[$reg[0]] = caractere_utf_8($reg[1]);
692
+            }
693
+        }
694
+    }
695
+    //$texte = str_replace(array_keys($vu), array_values($vu), $texte);
696
+
697
+    // 2. Entites > &#xFF;
698
+    //$vu = array();
699
+    if (
700
+        preg_match_all(
701
+            ',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
702
+            $texte,
703
+            $regs,
704
+            PREG_SET_ORDER
705
+        )
706
+    ) {
707
+        foreach ($regs as $reg) {
708
+            if (!isset($vu[$reg[0]])) {
709
+                $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
710
+            }
711
+        }
712
+    }
713
+
714
+    return str_replace(array_keys($vu), array_values($vu), $texte);
715 715
 }
716 716
 
717 717
 /**
@@ -723,15 +723,15 @@  discard block
 block discarded – undo
723 723
  *     texte converti
724 724
  **/
725 725
 function unicode_to_javascript($texte) {
726
-	$vu = [];
727
-	while (preg_match(',&#0*(\d+);,S', $texte, $regs) && !isset($vu[$regs[1]])) {
728
-		$num = $regs[1];
729
-		$vu[$num] = true;
730
-		$s = '\u' . sprintf('%04x', $num);
731
-		$texte = str_replace($regs[0], $s, $texte);
732
-	}
733
-
734
-	return $texte;
726
+    $vu = [];
727
+    while (preg_match(',&#0*(\d+);,S', $texte, $regs) && !isset($vu[$regs[1]])) {
728
+        $num = $regs[1];
729
+        $vu[$num] = true;
730
+        $s = '\u' . sprintf('%04x', $num);
731
+        $texte = str_replace($regs[0], $s, $texte);
732
+    }
733
+
734
+    return $texte;
735 735
 }
736 736
 
737 737
 /**
@@ -743,11 +743,11 @@  discard block
 block discarded – undo
743 743
  *     texte converti
744 744
  **/
745 745
 function javascript_to_unicode($texte) {
746
-	while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) {
747
-		$texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte);
748
-	}
746
+    while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) {
747
+        $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte);
748
+    }
749 749
 
750
-	return $texte;
750
+    return $texte;
751 751
 }
752 752
 
753 753
 /**
@@ -759,11 +759,11 @@  discard block
 block discarded – undo
759 759
  *     texte converti
760 760
  **/
761 761
 function javascript_to_binary($texte) {
762
-	while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) {
763
-		$texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
764
-	}
762
+    while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) {
763
+        $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
764
+    }
765 765
 
766
-	return $texte;
766
+    return $texte;
767 767
 }
768 768
 
769 769
 
@@ -781,26 +781,26 @@  discard block
 block discarded – undo
781 781
  * @return string
782 782
  */
783 783
 function translitteration_rapide($texte, $charset = 'AUTO', $complexe = ''): string {
784
-	static $trans = [];
785
-	if ($charset == 'AUTO') {
786
-		$charset = $GLOBALS['meta']['charset'];
787
-	}
788
-	if (!strlen($texte)) {
789
-		return $texte;
790
-	}
791
-
792
-	$table_translit = 'translit' . $complexe;
793
-
794
-	// 2. Translitterer grace a la table predefinie
795
-	if (!isset($trans[$complexe])) {
796
-		$trans[$complexe] = [];
797
-		load_charset($table_translit);
798
-		foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
799
-			$trans[$complexe][caractere_utf_8($key)] = $val;
800
-		}
801
-	}
802
-
803
-	return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
784
+    static $trans = [];
785
+    if ($charset == 'AUTO') {
786
+        $charset = $GLOBALS['meta']['charset'];
787
+    }
788
+    if (!strlen($texte)) {
789
+        return $texte;
790
+    }
791
+
792
+    $table_translit = 'translit' . $complexe;
793
+
794
+    // 2. Translitterer grace a la table predefinie
795
+    if (!isset($trans[$complexe])) {
796
+        $trans[$complexe] = [];
797
+        load_charset($table_translit);
798
+        foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
799
+            $trans[$complexe][caractere_utf_8($key)] = $val;
800
+        }
801
+    }
802
+
803
+    return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
804 804
 }
805 805
 
806 806
 /**
@@ -823,14 +823,14 @@  discard block
 block discarded – undo
823 823
  * @return string
824 824
  */
825 825
 function translitteration($texte, $charset = 'AUTO', $complexe = ''): string {
826
-	// 0. Supprimer les caracteres illegaux
827
-	include_spip('inc/filtres');
828
-	$texte = corriger_caracteres($texte);
826
+    // 0. Supprimer les caracteres illegaux
827
+    include_spip('inc/filtres');
828
+    $texte = corriger_caracteres($texte);
829 829
 
830
-	// 1. Passer le charset et les &eacute en utf-8
831
-	$texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset)));
830
+    // 1. Passer le charset et les &eacute en utf-8
831
+    $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset)));
832 832
 
833
-	return translitteration_rapide($texte, $charset, $complexe);
833
+    return translitteration_rapide($texte, $charset, $complexe);
834 834
 }
835 835
 
836 836
 /**
@@ -845,17 +845,17 @@  discard block
 block discarded – undo
845 845
  * @return string
846 846
  */
847 847
 function translitteration_complexe($texte, $chiffres = false): string {
848
-	$texte = translitteration($texte, 'AUTO', 'complexe');
848
+    $texte = translitteration($texte, 'AUTO', 'complexe');
849 849
 
850
-	if ($chiffres) {
851
-		$texte = preg_replace_callback(
852
-			"/[aeiuoyd]['`?~.^+(-]{1,2}/S",
853
-			fn($m) => translitteration_chiffree($m[0]),
854
-			$texte
855
-		);
856
-	}
850
+    if ($chiffres) {
851
+        $texte = preg_replace_callback(
852
+            "/[aeiuoyd]['`?~.^+(-]{1,2}/S",
853
+            fn($m) => translitteration_chiffree($m[0]),
854
+            $texte
855
+        );
856
+    }
857 857
 
858
-	return $texte;
858
+    return $texte;
859 859
 }
860 860
 
861 861
 /**
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
  * @return string
868 868
  */
869 869
 function translitteration_chiffree($car): string {
870
-	return strtr($car, "'`?~.^+(-", '123456789');
870
+    return strtr($car, "'`?~.^+(-", '123456789');
871 871
 }
872 872
 
873 873
 
@@ -880,7 +880,7 @@  discard block
 block discarded – undo
880 880
  *    true s'il a un BOM
881 881
  **/
882 882
 function bom_utf8($texte): bool {
883
-	return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF));
883
+    return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF));
884 884
 }
885 885
 
886 886
 /**
@@ -897,21 +897,21 @@  discard block
 block discarded – undo
897 897
  *     true si c'est le cas
898 898
  **/
899 899
 function is_utf8($string): bool {
900
-	return !strlen(
901
-		preg_replace(
902
-			',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
903
-			. '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
904
-			. '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
905
-			. '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
906
-			. '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
907
-			. '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
908
-			. '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
909
-			. '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
910
-			. ',sS',
911
-			'',
912
-			$string
913
-		)
914
-	);
900
+    return !strlen(
901
+        preg_replace(
902
+            ',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
903
+            . '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
904
+            . '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
905
+            . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
906
+            . '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
907
+            . '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
908
+            . '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
909
+            . '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
910
+            . ',sS',
911
+            '',
912
+            $string
913
+        )
914
+    );
915 915
 }
916 916
 
917 917
 /**
@@ -923,13 +923,13 @@  discard block
 block discarded – undo
923 923
  *     true si c'est le cas
924 924
  **/
925 925
 function is_ascii($string): bool {
926
-	return !strlen(
927
-		preg_replace(
928
-			',[\x09\x0A\x0D\x20-\x7E],sS',
929
-			'',
930
-			$string
931
-		)
932
-	);
926
+    return !strlen(
927
+        preg_replace(
928
+            ',[\x09\x0A\x0D\x20-\x7E],sS',
929
+            '',
930
+            $string
931
+        )
932
+    );
933 933
 }
934 934
 
935 935
 /**
@@ -948,50 +948,50 @@  discard block
 block discarded – undo
948 948
  **/
949 949
 function transcoder_page($texte, $headers = ''): string {
950 950
 
951
-	// Si tout est < 128 pas la peine d'aller plus loin
952
-	if (is_ascii($texte)) {
953
-		#spip_log('charset: ascii');
954
-		return $texte;
955
-	}
956
-
957
-	if (bom_utf8($texte)) {
958
-		// Reconnaitre le BOM utf-8 (0xEFBBBF)
959
-		$charset = 'utf-8';
960
-		$texte = substr($texte, 3);
961
-	} elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
962
-		// charset precise par le contenu (xml)
963
-		$charset = trim(strtolower($regs[1]));
964
-	} elseif (
965
-		// charset precise par le contenu (html)
966
-		preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs)
967
-		# eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette
968
-
969
-		&& !str_contains($regs[2], '#')
970
-		&& ($tmp = trim(strtolower($regs[2])))
971
-	) {
972
-		$charset = $tmp;
973
-	} elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
974
-		// charset de la reponse http
975
-		$charset = trim(strtolower($regs[1]));
976
-	} else {
977
-		$charset = '';
978
-	}
979
-
980
-
981
-	// normaliser les noms du shif-jis japonais
982
-	if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
983
-		$charset = 'shift-jis';
984
-	}
985
-
986
-	if ($charset) {
987
-		spip_log("charset: $charset");
988
-	} else {
989
-		// valeur par defaut
990
-		$charset = is_utf8($texte) ? 'utf-8' : 'iso-8859-1';
991
-		spip_log("charset probable: $charset");
992
-	}
993
-
994
-	return importer_charset($texte, $charset);
951
+    // Si tout est < 128 pas la peine d'aller plus loin
952
+    if (is_ascii($texte)) {
953
+        #spip_log('charset: ascii');
954
+        return $texte;
955
+    }
956
+
957
+    if (bom_utf8($texte)) {
958
+        // Reconnaitre le BOM utf-8 (0xEFBBBF)
959
+        $charset = 'utf-8';
960
+        $texte = substr($texte, 3);
961
+    } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
962
+        // charset precise par le contenu (xml)
963
+        $charset = trim(strtolower($regs[1]));
964
+    } elseif (
965
+        // charset precise par le contenu (html)
966
+        preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs)
967
+        # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette
968
+
969
+        && !str_contains($regs[2], '#')
970
+        && ($tmp = trim(strtolower($regs[2])))
971
+    ) {
972
+        $charset = $tmp;
973
+    } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
974
+        // charset de la reponse http
975
+        $charset = trim(strtolower($regs[1]));
976
+    } else {
977
+        $charset = '';
978
+    }
979
+
980
+
981
+    // normaliser les noms du shif-jis japonais
982
+    if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
983
+        $charset = 'shift-jis';
984
+    }
985
+
986
+    if ($charset) {
987
+        spip_log("charset: $charset");
988
+    } else {
989
+        // valeur par defaut
990
+        $charset = is_utf8($texte) ? 'utf-8' : 'iso-8859-1';
991
+        spip_log("charset probable: $charset");
992
+    }
993
+
994
+    return importer_charset($texte, $charset);
995 995
 }
996 996
 
997 997
 
@@ -1015,19 +1015,19 @@  discard block
 block discarded – undo
1015 1015
  *     Le texte coupé
1016 1016
  **/
1017 1017
 function spip_substr($c, $start = 0, $length = null) {
1018
-	if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1019
-		if ($length) {
1020
-			return substr($c, $start, $length);
1021
-		} else {
1022
-			return substr($c, $start);
1023
-		}
1024
-	}
1025
-
1026
-	if ($length) {
1027
-		return mb_substr($c, $start, $length);
1028
-	} else {
1029
-		return mb_substr($c, $start);
1030
-	}
1018
+    if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1019
+        if ($length) {
1020
+            return substr($c, $start, $length);
1021
+        } else {
1022
+            return substr($c, $start);
1023
+        }
1024
+    }
1025
+
1026
+    if ($length) {
1027
+        return mb_substr($c, $start, $length);
1028
+    } else {
1029
+        return mb_substr($c, $start);
1030
+    }
1031 1031
 }
1032 1032
 
1033 1033
 /**
@@ -1041,13 +1041,13 @@  discard block
 block discarded – undo
1041 1041
  *     La chaîne avec une majuscule sur le premier mot
1042 1042
  */
1043 1043
 function spip_ucfirst($c) {
1044
-	if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1045
-		return ucfirst($c);
1046
-	}
1044
+    if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1045
+        return ucfirst($c);
1046
+    }
1047 1047
 
1048
-	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1048
+    $lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1049 1049
 
1050
-	return $lettre1 . spip_substr($c, 1);
1050
+    return $lettre1 . spip_substr($c, 1);
1051 1051
 }
1052 1052
 
1053 1053
 /**
@@ -1061,11 +1061,11 @@  discard block
 block discarded – undo
1061 1061
  *     La chaîne en minuscules
1062 1062
  */
1063 1063
 function spip_strtolower($c) {
1064
-	if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1065
-		return strtolower($c);
1066
-	}
1064
+    if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1065
+        return strtolower($c);
1066
+    }
1067 1067
 
1068
-	return mb_strtolower($c);
1068
+    return mb_strtolower($c);
1069 1069
 }
1070 1070
 
1071 1071
 /**
@@ -1079,15 +1079,15 @@  discard block
 block discarded – undo
1079 1079
  *     Longueur de la chaîne
1080 1080
  */
1081 1081
 function spip_strlen($c) {
1082
-	// On transforme les sauts de ligne pour ne pas compter deux caractères
1083
-	$c = str_replace("\r\n", "\n", $c);
1082
+    // On transforme les sauts de ligne pour ne pas compter deux caractères
1083
+    $c = str_replace("\r\n", "\n", $c);
1084 1084
 
1085
-	// Si ce n'est pas utf-8, utiliser strlen
1086
-	if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1087
-		return strlen($c);
1088
-	}
1085
+    // Si ce n'est pas utf-8, utiliser strlen
1086
+    if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1087
+        return strlen($c);
1088
+    }
1089 1089
 
1090
-	return mb_strlen($c);
1090
+    return mb_strlen($c);
1091 1091
 }
1092 1092
 
1093 1093
 /**
@@ -1102,17 +1102,17 @@  discard block
 block discarded – undo
1102 1102
  *     en unicode : &#128169;
1103 1103
  */
1104 1104
 function utf8_noplanes($x): string {
1105
-	$regexp_utf8_4bytes = '/(
1105
+    $regexp_utf8_4bytes = '/(
1106 1106
       \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
1107 1107
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
1108 1108
    |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
1109 1109
 )/xS';
1110
-	if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1111
-		foreach ($z[0] as $k) {
1112
-			$ku = utf_8_to_unicode($k);
1113
-			$x = str_replace($k, $ku, $x);
1114
-		}
1115
-	}
1116
-
1117
-	return $x;
1110
+    if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1111
+        foreach ($z[0] as $k) {
1112
+            $ku = utf_8_to_unicode($k);
1113
+            $x = str_replace($k, $ku, $x);
1114
+        }
1115
+    }
1116
+
1117
+    return $x;
1118 1118
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres_alertes.php 2 patches
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -42,22 +42,22 @@  discard block
 block discarded – undo
42 42
  *     Pile complétée par le code à générer
43 43
  */
44 44
 function balise_ALERTE_MESSAGE_dist($p) {
45
-	$_texte = interprete_argument_balise(1, $p);
46
-	$_titre = interprete_argument_balise(2, $p);
47
-	$_class = interprete_argument_balise(3, $p);
48
-	$_role  = interprete_argument_balise(4, $p);
49
-	$_id    = interprete_argument_balise(5, $p);
50
-	$_texte = ($_texte ?: "''");
51
-	$_titre = ($_titre ? ", $_titre" : ', null');
52
-	$_class = ($_class ? ", $_class" : ', null');
53
-	$_role  = ($_role  ? ", $_role"  : ', null');
54
-	$_id    = ($_id    ? ", $_id"    : ', null');
45
+    $_texte = interprete_argument_balise(1, $p);
46
+    $_titre = interprete_argument_balise(2, $p);
47
+    $_class = interprete_argument_balise(3, $p);
48
+    $_role  = interprete_argument_balise(4, $p);
49
+    $_id    = interprete_argument_balise(5, $p);
50
+    $_texte = ($_texte ?: "''");
51
+    $_titre = ($_titre ? ", $_titre" : ', null');
52
+    $_class = ($_class ? ", $_class" : ', null');
53
+    $_role  = ($_role  ? ", $_role"  : ', null');
54
+    $_id    = ($_id    ? ", $_id"    : ', null');
55 55
 
56
-	$f = chercher_filtre('message_alerte');
57
-	$p->code = "$f($_texte$_titre$_class$_role$_id)";
58
-	$p->interdire_scripts = false;
56
+    $f = chercher_filtre('message_alerte');
57
+    $p->code = "$f($_texte$_titre$_class$_role$_id)";
58
+    $p->interdire_scripts = false;
59 59
 
60
-	return $p;
60
+    return $p;
61 61
 }
62 62
 
63 63
 /**
@@ -85,20 +85,20 @@  discard block
 block discarded – undo
85 85
  *     Pile complétée par le code à générer
86 86
  */
87 87
 function balise_ALERTE_OUVRIR_dist($p) {
88
-	$_titre = interprete_argument_balise(1, $p);
89
-	$_class = interprete_argument_balise(2, $p);
90
-	$_role  = interprete_argument_balise(3, $p);
91
-	$_id    = interprete_argument_balise(4, $p);
92
-	$_titre = ($_titre ? "$_titre"   : 'null');
93
-	$_class = ($_class ? ", $_class" : ', null');
94
-	$_role  = ($_role  ? ", $_role"  : ', null');
95
-	$_id    = ($_id    ? ", $_id"    : ', null');
88
+    $_titre = interprete_argument_balise(1, $p);
89
+    $_class = interprete_argument_balise(2, $p);
90
+    $_role  = interprete_argument_balise(3, $p);
91
+    $_id    = interprete_argument_balise(4, $p);
92
+    $_titre = ($_titre ? "$_titre"   : 'null');
93
+    $_class = ($_class ? ", $_class" : ', null');
94
+    $_role  = ($_role  ? ", $_role"  : ', null');
95
+    $_id    = ($_id    ? ", $_id"    : ', null');
96 96
 
97
-	$f = chercher_filtre('message_alerte_ouvrir');
98
-	$p->code = "$f($_titre$_class$_role$_id)";
99
-	$p->interdire_scripts = false;
97
+    $f = chercher_filtre('message_alerte_ouvrir');
98
+    $p->code = "$f($_titre$_class$_role$_id)";
99
+    $p->interdire_scripts = false;
100 100
 
101
-	return $p;
101
+    return $p;
102 102
 }
103 103
 
104 104
 /**
@@ -120,11 +120,11 @@  discard block
 block discarded – undo
120 120
  *     Pile complétée par le code à générer
121 121
  */
122 122
 function balise_ALERTE_FERMER_dist($p) {
123
-	$f = chercher_filtre('message_alerte_fermer');
124
-	$p->code = "$f()";
125
-	$p->interdire_scripts = false;
123
+    $f = chercher_filtre('message_alerte_fermer');
124
+    $p->code = "$f()";
125
+    $p->interdire_scripts = false;
126 126
 
127
-	return $p;
127
+    return $p;
128 128
 }
129 129
 
130 130
 /**
@@ -159,12 +159,12 @@  discard block
 block discarded – undo
159 159
  */
160 160
 function message_alerte(string $texte, ?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string {
161 161
 
162
-	$message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir');
163
-	$message_alerte_fermer = chercher_filtre('message_alerte_fermer');
162
+    $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir');
163
+    $message_alerte_fermer = chercher_filtre('message_alerte_fermer');
164 164
 
165
-	return $message_alerte_ouvrir($titre, $class, $role, $id) .
166
-		$texte .
167
-		$message_alerte_fermer();
165
+    return $message_alerte_ouvrir($titre, $class, $role, $id) .
166
+        $texte .
167
+        $message_alerte_fermer();
168 168
 }
169 169
 
170 170
 /**
@@ -195,53 +195,53 @@  discard block
 block discarded – undo
195 195
  */
196 196
 function message_alerte_ouvrir(?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string {
197 197
 
198
-	$prive = test_espace_prive();
198
+    $prive = test_espace_prive();
199 199
 
200
-	// Valeurs par défaut
201
-	$titre = trim($titre ?? '');
202
-	$role ??= 'alert'; // fallback uniquement si null
203
-	$class ??= 'notice'; // fallback uniquement si null
200
+    // Valeurs par défaut
201
+    $titre = trim($titre ?? '');
202
+    $role ??= 'alert'; // fallback uniquement si null
203
+    $class ??= 'notice'; // fallback uniquement si null
204 204
 
205
-	// Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter
206
-	$types = [
207
-		'notice',
208
-		'error',
209
-		'success',
210
-		'info',
211
-	];
212
-	$type  = array_intersect(explode(' ', $class), $types);
213
-	$type  = reset($type);
214
-	$class = trim(str_replace($types, '', $class) . " $type");
205
+    // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter
206
+    $types = [
207
+        'notice',
208
+        'error',
209
+        'success',
210
+        'info',
211
+    ];
212
+    $type  = array_intersect(explode(' ', $class), $types);
213
+    $type  = reset($type);
214
+    $class = trim(str_replace($types, '', $class) . " $type");
215 215
 
216
-	// Classes
217
-	$class_racine = 'msg-alert';
218
-	$clearfix     = ($prive ? 'clearfix' : '');
219
-	$class_alerte = "$class_racine $class";
220
-	$class_texte  = "{$class_racine}__text $clearfix";
221
-	$class_titre  = "{$class_racine}__heading";
216
+    // Classes
217
+    $class_racine = 'msg-alert';
218
+    $clearfix     = ($prive ? 'clearfix' : '');
219
+    $class_alerte = "$class_racine $class";
220
+    $class_texte  = "{$class_racine}__text $clearfix";
221
+    $class_titre  = "{$class_racine}__heading";
222 222
 
223
-	// Titre : markup
224
-	$titre = trim($titre);
225
-	if (strlen($titre)) {
226
-		include_spip('inc/filtres');
227
-		// Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon.
228
-		$cherche_tag = ($prive ? '<h' : '<');
229
-		$wrap_tag    = ($prive ? '<h3>' : '<div>');
230
-		if (!str_starts_with($titre, $cherche_tag)) {
231
-			$titre = wrap($titre, $wrap_tag);
232
-		}
233
-		// puis on ajoute la classe
234
-		$titre = ajouter_class($titre, $class_titre);
235
-	}
223
+    // Titre : markup
224
+    $titre = trim($titre);
225
+    if (strlen($titre)) {
226
+        include_spip('inc/filtres');
227
+        // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon.
228
+        $cherche_tag = ($prive ? '<h' : '<');
229
+        $wrap_tag    = ($prive ? '<h3>' : '<div>');
230
+        if (!str_starts_with($titre, $cherche_tag)) {
231
+            $titre = wrap($titre, $wrap_tag);
232
+        }
233
+        // puis on ajoute la classe
234
+        $titre = ajouter_class($titre, $class_titre);
235
+    }
236 236
 
237
-	// Attributs
238
-	$attr_role = ($role ? "role=\"$role\"" : '');
239
-	$attr_id   = ($id   ? "id=\"$id\"" : '');
240
-	$attr_data = ($type ? "data-alert=\"$type\"" : '');
237
+    // Attributs
238
+    $attr_role = ($role ? "role=\"$role\"" : '');
239
+    $attr_id   = ($id   ? "id=\"$id\"" : '');
240
+    $attr_data = ($type ? "data-alert=\"$type\"" : '');
241 241
 
242
-	return "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>"
243
-			. $titre
244
-			. "<div class=\"$class_texte\">";
242
+    return "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>"
243
+            . $titre
244
+            . "<div class=\"$class_texte\">";
245 245
 }
246 246
 
247 247
 /**
@@ -255,5 +255,5 @@  discard block
 block discarded – undo
255 255
  *     HTML de fin de l'alerte
256 256
  */
257 257
 function message_alerte_fermer(): string {
258
-	return '</div></div>';
258
+    return '</div></div>';
259 259
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 	$_texte = ($_texte ?: "''");
51 51
 	$_titre = ($_titre ? ", $_titre" : ', null');
52 52
 	$_class = ($_class ? ", $_class" : ', null');
53
-	$_role  = ($_role  ? ", $_role"  : ', null');
54
-	$_id    = ($_id    ? ", $_id"    : ', null');
53
+	$_role  = ($_role ? ", $_role" : ', null');
54
+	$_id    = ($_id ? ", $_id" : ', null');
55 55
 
56 56
 	$f = chercher_filtre('message_alerte');
57 57
 	$p->code = "$f($_texte$_titre$_class$_role$_id)";
@@ -89,10 +89,10 @@  discard block
 block discarded – undo
89 89
 	$_class = interprete_argument_balise(2, $p);
90 90
 	$_role  = interprete_argument_balise(3, $p);
91 91
 	$_id    = interprete_argument_balise(4, $p);
92
-	$_titre = ($_titre ? "$_titre"   : 'null');
92
+	$_titre = ($_titre ? "$_titre" : 'null');
93 93
 	$_class = ($_class ? ", $_class" : ', null');
94
-	$_role  = ($_role  ? ", $_role"  : ', null');
95
-	$_id    = ($_id    ? ", $_id"    : ', null');
94
+	$_role  = ($_role ? ", $_role" : ', null');
95
+	$_id    = ($_id ? ", $_id" : ', null');
96 96
 
97 97
 	$f = chercher_filtre('message_alerte_ouvrir');
98 98
 	$p->code = "$f($_titre$_class$_role$_id)";
@@ -162,8 +162,8 @@  discard block
 block discarded – undo
162 162
 	$message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir');
163 163
 	$message_alerte_fermer = chercher_filtre('message_alerte_fermer');
164 164
 
165
-	return $message_alerte_ouvrir($titre, $class, $role, $id) .
166
-		$texte .
165
+	return $message_alerte_ouvrir($titre, $class, $role, $id).
166
+		$texte.
167 167
 		$message_alerte_fermer();
168 168
 }
169 169
 
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 	];
212 212
 	$type  = array_intersect(explode(' ', $class), $types);
213 213
 	$type  = reset($type);
214
-	$class = trim(str_replace($types, '', $class) . " $type");
214
+	$class = trim(str_replace($types, '', $class)." $type");
215 215
 
216 216
 	// Classes
217 217
 	$class_racine = 'msg-alert';
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 
237 237
 	// Attributs
238 238
 	$attr_role = ($role ? "role=\"$role\"" : '');
239
-	$attr_id   = ($id   ? "id=\"$id\"" : '');
239
+	$attr_id   = ($id ? "id=\"$id\"" : '');
240 240
 	$attr_data = ($type ? "data-alert=\"$type\"" : '');
241 241
 
242 242
 	return "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>"
Please login to merge, or discard this patch.
ecrire/inc/cvt_configurer.php 2 patches
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  */
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 include_spip('inc/config');
@@ -31,31 +31,31 @@  discard block
 block discarded – undo
31 31
  * @return array|false
32 32
  */
33 33
 function cvtconf_formulaire_charger($flux) {
34
-	if (
35
-		($form = $flux['args']['form'])
36
-		&& str_starts_with((string) $form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX
37
-	) {
38
-		// Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé
39
-		include_spip('inc/autoriser');
40
-		if (!autoriser('configurer', '_' . substr((string) $form, 11))) {
41
-			return false;
42
-		}
34
+    if (
35
+        ($form = $flux['args']['form'])
36
+        && str_starts_with((string) $form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX
37
+    ) {
38
+        // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé
39
+        include_spip('inc/autoriser');
40
+        if (!autoriser('configurer', '_' . substr((string) $form, 11))) {
41
+            return false;
42
+        }
43 43
 
44
-		// S'il n'y a pas de fonction charger(), on génère un contexte automatiquement
45
-		if (!charger_fonction('charger', "formulaires/$form/", true)) {
46
-			$flux['data'] = cvtconf_formulaires_configurer_recense($form);
47
-			$flux['data']['editable'] = true;
48
-			if (_request('var_mode') == 'configurer' && autoriser('webmestre')) {
49
-				if (!_AJAX) {
50
-					var_dump($flux['data']);
51
-				}
52
-				// reinjecter pour la trace au traitement
53
-				$flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />";
54
-			}
55
-		}
56
-	}
44
+        // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement
45
+        if (!charger_fonction('charger', "formulaires/$form/", true)) {
46
+            $flux['data'] = cvtconf_formulaires_configurer_recense($form);
47
+            $flux['data']['editable'] = true;
48
+            if (_request('var_mode') == 'configurer' && autoriser('webmestre')) {
49
+                if (!_AJAX) {
50
+                    var_dump($flux['data']);
51
+                }
52
+                // reinjecter pour la trace au traitement
53
+                $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />";
54
+            }
55
+        }
56
+    }
57 57
 
58
-	return $flux;
58
+    return $flux;
59 59
 }
60 60
 
61 61
 /**
@@ -65,16 +65,16 @@  discard block
 block discarded – undo
65 65
  * @return array
66 66
  */
67 67
 function cvtconf_formulaire_traiter($flux) {
68
-	if (
69
-		($form = $flux['args']['form'])
70
-		&& str_starts_with((string) $form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX
71
-		&& !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter()
72
-	) {
73
-		$trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']);
74
-		$flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true];
75
-	}
68
+    if (
69
+        ($form = $flux['args']['form'])
70
+        && str_starts_with((string) $form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX
71
+        && !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter()
72
+    ) {
73
+        $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']);
74
+        $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true];
75
+    }
76 76
 
77
-	return $flux;
77
+    return $flux;
78 78
 }
79 79
 
80 80
 /**
@@ -90,32 +90,32 @@  discard block
 block discarded – undo
90 90
  * @return string
91 91
  */
92 92
 function cvtconf_formulaires_configurer_enregistre($form, $args) {
93
-	$valeurs = [];
94
-	// charger les valeurs
95
-	// ce qui permet de prendre en charge une fonction charger() existante
96
-	// qui prend alors la main sur l'auto detection
97
-	if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) {
98
-		$valeurs = $charger_valeurs(...$args);
99
-	}
100
-	$valeurs = pipeline(
101
-		'formulaire_charger',
102
-		[
103
-			'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false],
104
-			'data' => $valeurs
105
-		]
106
-	);
107
-	// ne pas stocker editable !
108
-	unset($valeurs['editable']);
93
+    $valeurs = [];
94
+    // charger les valeurs
95
+    // ce qui permet de prendre en charge une fonction charger() existante
96
+    // qui prend alors la main sur l'auto detection
97
+    if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) {
98
+        $valeurs = $charger_valeurs(...$args);
99
+    }
100
+    $valeurs = pipeline(
101
+        'formulaire_charger',
102
+        [
103
+            'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false],
104
+            'data' => $valeurs
105
+        ]
106
+    );
107
+    // ne pas stocker editable !
108
+    unset($valeurs['editable']);
109 109
 
110
-	// recuperer les valeurs postees
111
-	$store = [];
112
-	foreach ($valeurs as $k => $v) {
113
-		if (!str_starts_with((string) $k, '_')) {
114
-			$store[$k] = _request($k);
115
-		}
116
-	}
110
+    // recuperer les valeurs postees
111
+    $store = [];
112
+    foreach ($valeurs as $k => $v) {
113
+        if (!str_starts_with((string) $k, '_')) {
114
+            $store[$k] = _request($k);
115
+        }
116
+    }
117 117
 
118
-	return cvtconf_configurer_stocker($form, $valeurs, $store);
118
+    return cvtconf_configurer_stocker($form, $valeurs, $store);
119 119
 }
120 120
 
121 121
 /**
@@ -131,31 +131,31 @@  discard block
 block discarded – undo
131 131
  * @return array
132 132
  */
133 133
 function cvtconf_definir_configurer_conteneur($form, $valeurs) {
134
-	// stocker en base
135
-	// par defaut, dans un casier serialize dans spip_meta (idem CFG)
136
-	$casier = substr($form, 11);
137
-	$table = 'meta';
138
-	$prefixe = '';
139
-	$stockage = '';
134
+    // stocker en base
135
+    // par defaut, dans un casier serialize dans spip_meta (idem CFG)
136
+    $casier = substr($form, 11);
137
+    $table = 'meta';
138
+    $prefixe = '';
139
+    $stockage = '';
140 140
 
141
-	if (isset($valeurs['_meta_casier'])) {
142
-		$casier = $valeurs['_meta_casier'];
143
-	}
144
-	if (isset($valeurs['_meta_prefixe'])) {
145
-		$prefixe = $valeurs['_meta_prefixe'];
146
-	}
147
-	if (isset($valeurs['_meta_stockage'])) {
148
-		$stockage = $valeurs['_meta_stockage'] . '::';
149
-	}
141
+    if (isset($valeurs['_meta_casier'])) {
142
+        $casier = $valeurs['_meta_casier'];
143
+    }
144
+    if (isset($valeurs['_meta_prefixe'])) {
145
+        $prefixe = $valeurs['_meta_prefixe'];
146
+    }
147
+    if (isset($valeurs['_meta_stockage'])) {
148
+        $stockage = $valeurs['_meta_stockage'] . '::';
149
+    }
150 150
 
151
-	// si on indique juste une table, il faut vider les autres proprietes
152
-	// car par defaut on utilise ni casier ni prefixe dans ce cas
153
-	if (isset($valeurs['_meta_table'])) {
154
-		$table = $valeurs['_meta_table'];
155
-		$casier = ($valeurs['_meta_casier'] ?? '');
156
-	}
151
+    // si on indique juste une table, il faut vider les autres proprietes
152
+    // car par defaut on utilise ni casier ni prefixe dans ce cas
153
+    if (isset($valeurs['_meta_table'])) {
154
+        $table = $valeurs['_meta_table'];
155
+        $casier = ($valeurs['_meta_casier'] ?? '');
156
+    }
157 157
 
158
-	return [$table, $casier, $prefixe, $stockage];
158
+    return [$table, $casier, $prefixe, $stockage];
159 159
 }
160 160
 
161 161
 /**
@@ -166,49 +166,49 @@  discard block
 block discarded – undo
166 166
  * @return array
167 167
  */
168 168
 function cvtconf_formulaires_configurer_recense($form) {
169
-	$contenu = null;
170
-	$valeurs = ['editable' => ' '];
169
+    $contenu = null;
170
+    $valeurs = ['editable' => ' '];
171 171
 
172
-	// sinon cas analyse du squelette
173
-	if (
174
-		($f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/'))
175
-		&& lire_fichier($f, $contenu)
176
-	) {
177
-		for ($i = 0; $i < 2; $i++) {
178
-			// a la seconde iteration, evaluer le fond avec les valeurs deja trouvees
179
-			// permet de trouver aussi les name="#GET{truc}"
180
-			if ($i == 1) {
181
-				$contenu = recuperer_fond("formulaires/$form", $valeurs);
182
-			}
172
+    // sinon cas analyse du squelette
173
+    if (
174
+        ($f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/'))
175
+        && lire_fichier($f, $contenu)
176
+    ) {
177
+        for ($i = 0; $i < 2; $i++) {
178
+            // a la seconde iteration, evaluer le fond avec les valeurs deja trouvees
179
+            // permet de trouver aussi les name="#GET{truc}"
180
+            if ($i == 1) {
181
+                $contenu = recuperer_fond("formulaires/$form", $valeurs);
182
+            }
183 183
 
184
-			$balises = array_merge(
185
-				extraire_balises($contenu, 'input'),
186
-				extraire_balises($contenu, 'textarea'),
187
-				extraire_balises($contenu, 'select')
188
-			);
184
+            $balises = array_merge(
185
+                extraire_balises($contenu, 'input'),
186
+                extraire_balises($contenu, 'textarea'),
187
+                extraire_balises($contenu, 'select')
188
+            );
189 189
 
190
-			foreach ($balises as $b) {
191
-				if (
192
-					($n = extraire_attribut($b, 'name'))
193
-					&& preg_match(',^([\w\-]+)(\[\w*\])?$,', (string) $n, $r)
194
-					&& !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign'])
195
-					&& extraire_attribut($b, 'type') !== 'submit'
196
-				) {
197
-					$valeurs[$r[1]] = '';
198
-					// recuperer les valeurs _meta_xx qui peuvent etre fournies
199
-					// en input hidden dans le squelette
200
-					if (str_starts_with($r[1], '_meta_')) {
201
-						$valeurs[$r[1]] = extraire_attribut($b, 'value');
202
-					}
203
-				}
204
-			}
205
-		}
206
-	}
190
+            foreach ($balises as $b) {
191
+                if (
192
+                    ($n = extraire_attribut($b, 'name'))
193
+                    && preg_match(',^([\w\-]+)(\[\w*\])?$,', (string) $n, $r)
194
+                    && !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign'])
195
+                    && extraire_attribut($b, 'type') !== 'submit'
196
+                ) {
197
+                    $valeurs[$r[1]] = '';
198
+                    // recuperer les valeurs _meta_xx qui peuvent etre fournies
199
+                    // en input hidden dans le squelette
200
+                    if (str_starts_with($r[1], '_meta_')) {
201
+                        $valeurs[$r[1]] = extraire_attribut($b, 'value');
202
+                    }
203
+                }
204
+            }
205
+        }
206
+    }
207 207
 
208 208
 
209
-	cvtconf_configurer_lire_meta($form, $valeurs);
209
+    cvtconf_configurer_lire_meta($form, $valeurs);
210 210
 
211
-	return $valeurs;
211
+    return $valeurs;
212 212
 }
213 213
 
214 214
 /**
@@ -220,26 +220,26 @@  discard block
 block discarded – undo
220 220
  * @return string
221 221
  */
222 222
 function cvtconf_configurer_stocker($form, $valeurs, $store) {
223
-	$trace = '';
224
-	[$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs);
225
-	// stocker en base
226
-	// par defaut, dans un casier serialize dans spip_meta (idem CFG)
227
-	if (!isset($GLOBALS[$table])) {
228
-		lire_metas($table);
229
-	}
223
+    $trace = '';
224
+    [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs);
225
+    // stocker en base
226
+    // par defaut, dans un casier serialize dans spip_meta (idem CFG)
227
+    if (!isset($GLOBALS[$table])) {
228
+        lire_metas($table);
229
+    }
230 230
 
231
-	$prefixe = ($prefixe ? $prefixe . '_' : '');
232
-	$table = ($table) ? "/$table/" : '';
233
-	$casier = ($casier) ? rtrim((string) $casier, '/') . '/' : ''; // slash final, sinon rien
231
+    $prefixe = ($prefixe ? $prefixe . '_' : '');
232
+    $table = ($table) ? "/$table/" : '';
233
+    $casier = ($casier) ? rtrim((string) $casier, '/') . '/' : ''; // slash final, sinon rien
234 234
 
235
-	foreach ($store as $k => $v) {
236
-		ecrire_config("$stockage$table$prefixe$casier$k", $v);
237
-		if (_request('var_mode') == 'configurer' && autoriser('webmestre')) {
238
-			$trace .= "<br />table $table : " . $prefixe . $k . " = $v;";
239
-		}
240
-	}
235
+    foreach ($store as $k => $v) {
236
+        ecrire_config("$stockage$table$prefixe$casier$k", $v);
237
+        if (_request('var_mode') == 'configurer' && autoriser('webmestre')) {
238
+            $trace .= "<br />table $table : " . $prefixe . $k . " = $v;";
239
+        }
240
+    }
241 241
 
242
-	return $trace;
242
+    return $trace;
243 243
 }
244 244
 
245 245
 /**
@@ -249,21 +249,21 @@  discard block
 block discarded – undo
249 249
  * @param array $valeurs
250 250
  */
251 251
 function cvtconf_configurer_lire_meta($form, &$valeurs) {
252
-	[$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs);
252
+    [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs);
253 253
 
254
-	$table = ($table) ? "/$table/" : '';
255
-	$prefixe = ($prefixe ? $prefixe . '_' : '');
256
-	if ($casier) {
257
-		$meta = lire_config("$stockage$table$prefixe$casier");
258
-		$prefixe = '';
259
-	} else {
260
-		$table = rtrim($table, '/');
261
-		$meta = lire_config("$stockage$table");
262
-	}
254
+    $table = ($table) ? "/$table/" : '';
255
+    $prefixe = ($prefixe ? $prefixe . '_' : '');
256
+    if ($casier) {
257
+        $meta = lire_config("$stockage$table$prefixe$casier");
258
+        $prefixe = '';
259
+    } else {
260
+        $table = rtrim($table, '/');
261
+        $meta = lire_config("$stockage$table");
262
+    }
263 263
 
264
-	foreach (array_keys($valeurs) as $k) {
265
-		if (!str_starts_with($k, '_')) {
266
-			$valeurs[$k] = ($meta[$prefixe . $k] ?? null);
267
-		}
268
-	}
264
+    foreach (array_keys($valeurs) as $k) {
265
+        if (!str_starts_with($k, '_')) {
266
+            $valeurs[$k] = ($meta[$prefixe . $k] ?? null);
267
+        }
268
+    }
269 269
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	) {
38 38
 		// Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé
39 39
 		include_spip('inc/autoriser');
40
-		if (!autoriser('configurer', '_' . substr((string) $form, 11))) {
40
+		if (!autoriser('configurer', '_'.substr((string) $form, 11))) {
41 41
 			return false;
42 42
 		}
43 43
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 		&& !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter()
72 72
 	) {
73 73
 		$trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']);
74
-		$flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true];
74
+		$flux['data'] = ['message_ok' => _T('config_info_enregistree').$trace, 'editable' => true];
75 75
 	}
76 76
 
77 77
 	return $flux;
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 		$prefixe = $valeurs['_meta_prefixe'];
146 146
 	}
147 147
 	if (isset($valeurs['_meta_stockage'])) {
148
-		$stockage = $valeurs['_meta_stockage'] . '::';
148
+		$stockage = $valeurs['_meta_stockage'].'::';
149 149
 	}
150 150
 
151 151
 	// si on indique juste une table, il faut vider les autres proprietes
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 
172 172
 	// sinon cas analyse du squelette
173 173
 	if (
174
-		($f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/'))
174
+		($f = find_in_path($form.'.'._EXTENSION_SQUELETTES, 'formulaires/'))
175 175
 		&& lire_fichier($f, $contenu)
176 176
 	) {
177 177
 		for ($i = 0; $i < 2; $i++) {
@@ -228,14 +228,14 @@  discard block
 block discarded – undo
228 228
 		lire_metas($table);
229 229
 	}
230 230
 
231
-	$prefixe = ($prefixe ? $prefixe . '_' : '');
231
+	$prefixe = ($prefixe ? $prefixe.'_' : '');
232 232
 	$table = ($table) ? "/$table/" : '';
233
-	$casier = ($casier) ? rtrim((string) $casier, '/') . '/' : ''; // slash final, sinon rien
233
+	$casier = ($casier) ? rtrim((string) $casier, '/').'/' : ''; // slash final, sinon rien
234 234
 
235 235
 	foreach ($store as $k => $v) {
236 236
 		ecrire_config("$stockage$table$prefixe$casier$k", $v);
237 237
 		if (_request('var_mode') == 'configurer' && autoriser('webmestre')) {
238
-			$trace .= "<br />table $table : " . $prefixe . $k . " = $v;";
238
+			$trace .= "<br />table $table : ".$prefixe.$k." = $v;";
239 239
 		}
240 240
 	}
241 241
 
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 	[$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs);
253 253
 
254 254
 	$table = ($table) ? "/$table/" : '';
255
-	$prefixe = ($prefixe ? $prefixe . '_' : '');
255
+	$prefixe = ($prefixe ? $prefixe.'_' : '');
256 256
 	if ($casier) {
257 257
 		$meta = lire_config("$stockage$table$prefixe$casier");
258 258
 		$prefixe = '';
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 
264 264
 	foreach (array_keys($valeurs) as $k) {
265 265
 		if (!str_starts_with($k, '_')) {
266
-			$valeurs[$k] = ($meta[$prefixe . $k] ?? null);
266
+			$valeurs[$k] = ($meta[$prefixe.$k] ?? null);
267 267
 		}
268 268
 	}
269 269
 }
Please login to merge, or discard this patch.
ecrire/base/repair.php 2 patches
Indentation   +63 added lines, -63 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
 /**
@@ -35,20 +35,20 @@  discard block
 block discarded – undo
35 35
  **/
36 36
 function base_repair_dist($titre = '', $reprise = '') {
37 37
 
38
-	$res = admin_repair_tables();
39
-	if (!$res) {
40
-		$res = "<div class='error'>" . _T('avis_erreur_mysql') . ' ' . sql_errno() . ': ' . sql_error() . "</div>\n";
41
-	} else {
42
-		include_spip('inc/rubriques');
43
-		calculer_rubriques();
44
-		propager_les_secteurs();
45
-	}
46
-	include_spip('inc/minipres');
47
-	$res .= pipeline('base_admin_repair', $res);
48
-	echo minipres(
49
-		_T('texte_tentative_recuperation'),
50
-		$res . generer_form_ecrire('accueil', '', '', _T('public:accueil_site'))
51
-	);
38
+    $res = admin_repair_tables();
39
+    if (!$res) {
40
+        $res = "<div class='error'>" . _T('avis_erreur_mysql') . ' ' . sql_errno() . ': ' . sql_error() . "</div>\n";
41
+    } else {
42
+        include_spip('inc/rubriques');
43
+        calculer_rubriques();
44
+        propager_les_secteurs();
45
+    }
46
+    include_spip('inc/minipres');
47
+    $res .= pipeline('base_admin_repair', $res);
48
+    echo minipres(
49
+        _T('texte_tentative_recuperation'),
50
+        $res . generer_form_ecrire('accueil', '', '', _T('public:accueil_site'))
51
+    );
52 52
 }
53 53
 
54 54
 /**
@@ -62,60 +62,60 @@  discard block
 block discarded – undo
62 62
  **/
63 63
 function admin_repair_tables() {
64 64
 
65
-	$repair = sql_serveur('repair', '', true);
65
+    $repair = sql_serveur('repair', '', true);
66 66
 
67
-	// recreer les tables manquantes eventuelles
68
-	include_spip('base/create');
69
-	creer_base();
70
-	$tables = sql_alltable();
67
+    // recreer les tables manquantes eventuelles
68
+    include_spip('base/create');
69
+    creer_base();
70
+    $tables = sql_alltable();
71 71
 
72
-	$res = '';
73
-	foreach ($tables as $tab) {
74
-		$class = '';
75
-		$m = "<strong>$tab</strong> ";
76
-		spip_log("Repare $tab", _LOG_INFO_IMPORTANTE);
77
-		// supprimer la meta avant de lancer la reparation
78
-		// car le repair peut etre long ; on ne veut pas boucler
79
-		effacer_meta('admin_repair');
80
-		if ($repair) {
81
-			$result_repair = sql_repair($tab);
82
-			if (!$result_repair) {
83
-				return false;
84
-			}
85
-		}
72
+    $res = '';
73
+    foreach ($tables as $tab) {
74
+        $class = '';
75
+        $m = "<strong>$tab</strong> ";
76
+        spip_log("Repare $tab", _LOG_INFO_IMPORTANTE);
77
+        // supprimer la meta avant de lancer la reparation
78
+        // car le repair peut etre long ; on ne veut pas boucler
79
+        effacer_meta('admin_repair');
80
+        if ($repair) {
81
+            $result_repair = sql_repair($tab);
82
+            if (!$result_repair) {
83
+                return false;
84
+            }
85
+        }
86 86
 
87
-		// essayer de maj la table (creation de champs manquants)
88
-		maj_tables($tab);
87
+        // essayer de maj la table (creation de champs manquants)
88
+        maj_tables($tab);
89 89
 
90
-		$count = sql_countsel($tab);
90
+        $count = sql_countsel($tab);
91 91
 
92
-		if ($count > 1) {
93
-			$m .= '(' . _T('texte_compte_elements', ['count' => $count]) . ")\n";
94
-		} else {
95
-			if ($count == 1) {
96
-				$m .= '(' . _T('texte_compte_element', ['count' => $count]) . ")\n";
97
-			} else {
98
-				$m .= '(' . _T('texte_vide') . ")\n";
99
-			}
100
-		}
92
+        if ($count > 1) {
93
+            $m .= '(' . _T('texte_compte_elements', ['count' => $count]) . ")\n";
94
+        } else {
95
+            if ($count == 1) {
96
+                $m .= '(' . _T('texte_compte_element', ['count' => $count]) . ")\n";
97
+            } else {
98
+                $m .= '(' . _T('texte_vide') . ")\n";
99
+            }
100
+        }
101 101
 
102
-		if (
103
-			$repair
104
-			&& $result_repair
105
-			&& ($msg = implode(
106
-				' ',
107
-				(is_resource($result_repair) || is_object($result_repair)) ? sql_fetch($result_repair) : $result_repair
108
-			) . ' ')
109
-			&& !str_contains($msg, ' OK ')
110
-		) {
111
-			$class = " class='notice'";
112
-			$m .= '<br /><tt>' . spip_htmlentities($msg) . "</tt>\n";
113
-		} else {
114
-			$m .= ' ' . _T('texte_table_ok');
115
-		}
102
+        if (
103
+            $repair
104
+            && $result_repair
105
+            && ($msg = implode(
106
+                ' ',
107
+                (is_resource($result_repair) || is_object($result_repair)) ? sql_fetch($result_repair) : $result_repair
108
+            ) . ' ')
109
+            && !str_contains($msg, ' OK ')
110
+        ) {
111
+            $class = " class='notice'";
112
+            $m .= '<br /><tt>' . spip_htmlentities($msg) . "</tt>\n";
113
+        } else {
114
+            $m .= ' ' . _T('texte_table_ok');
115
+        }
116 116
 
117
-		$res .= "<div$class>$m</div>";
118
-	}
117
+        $res .= "<div$class>$m</div>";
118
+    }
119 119
 
120
-	return $res;
120
+    return $res;
121 121
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 
38 38
 	$res = admin_repair_tables();
39 39
 	if (!$res) {
40
-		$res = "<div class='error'>" . _T('avis_erreur_mysql') . ' ' . sql_errno() . ': ' . sql_error() . "</div>\n";
40
+		$res = "<div class='error'>"._T('avis_erreur_mysql').' '.sql_errno().': '.sql_error()."</div>\n";
41 41
 	} else {
42 42
 		include_spip('inc/rubriques');
43 43
 		calculer_rubriques();
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	$res .= pipeline('base_admin_repair', $res);
48 48
 	echo minipres(
49 49
 		_T('texte_tentative_recuperation'),
50
-		$res . generer_form_ecrire('accueil', '', '', _T('public:accueil_site'))
50
+		$res.generer_form_ecrire('accueil', '', '', _T('public:accueil_site'))
51 51
 	);
52 52
 }
53 53
 
@@ -90,12 +90,12 @@  discard block
 block discarded – undo
90 90
 		$count = sql_countsel($tab);
91 91
 
92 92
 		if ($count > 1) {
93
-			$m .= '(' . _T('texte_compte_elements', ['count' => $count]) . ")\n";
93
+			$m .= '('._T('texte_compte_elements', ['count' => $count]).")\n";
94 94
 		} else {
95 95
 			if ($count == 1) {
96
-				$m .= '(' . _T('texte_compte_element', ['count' => $count]) . ")\n";
96
+				$m .= '('._T('texte_compte_element', ['count' => $count]).")\n";
97 97
 			} else {
98
-				$m .= '(' . _T('texte_vide') . ")\n";
98
+				$m .= '('._T('texte_vide').")\n";
99 99
 			}
100 100
 		}
101 101
 
@@ -105,13 +105,13 @@  discard block
 block discarded – undo
105 105
 			&& ($msg = implode(
106 106
 				' ',
107 107
 				(is_resource($result_repair) || is_object($result_repair)) ? sql_fetch($result_repair) : $result_repair
108
-			) . ' ')
108
+			).' ')
109 109
 			&& !str_contains($msg, ' OK ')
110 110
 		) {
111 111
 			$class = " class='notice'";
112
-			$m .= '<br /><tt>' . spip_htmlentities($msg) . "</tt>\n";
112
+			$m .= '<br /><tt>'.spip_htmlentities($msg)."</tt>\n";
113 113
 		} else {
114
-			$m .= ' ' . _T('texte_table_ok');
114
+			$m .= ' '._T('texte_table_ok');
115 115
 		}
116 116
 
117 117
 		$res .= "<div$class>$m</div>";
Please login to merge, or discard this patch.