Completed
Push — master ( 20ee8f...15f754 )
by cam
01:46
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/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.
ecrire/base/objets.php 3 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1391,8 +1391,7 @@
 block discarded – undo
1391 1391
 							'champ' 	=> $parent_methode['champ'],
1392 1392
 							'table'    => $table,
1393 1393
 						];
1394
-					}
1395
-					elseif (isset($parent_methode['champ_type'])) {
1394
+					} elseif (isset($parent_methode['champ_type'])) {
1396 1395
 						$parent = [
1397 1396
 							'objet' 	 => $ligne[$parent_methode['champ_type']],
1398 1397
 							'id_objet' 	 => (int) $ligne[$parent_methode['champ']],
Please login to merge, or discard this patch.
Indentation   +1240 added lines, -1240 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
 /**
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
  * @return void
34 34
  **/
35 35
 function array_set_merge(&$table, $index, $valeur) {
36
-	$table[$index] = isset($table[$index]) ? array_merge($table[$index], $valeur) : $valeur;
36
+    $table[$index] = isset($table[$index]) ? array_merge($table[$index], $valeur) : $valeur;
37 37
 }
38 38
 
39 39
 /**
@@ -52,441 +52,441 @@  discard block
 block discarded – undo
52 52
  *   - string (interne) si table '::md5' retourne un hash
53 53
  */
54 54
 function lister_tables_objets_sql(?string $table_sql = null, $desc = []) {
55
-	static $deja_la = false;
56
-	static $infos_tables = null;
57
-	static $md5 = null;
58
-	static $plugin_hash = null;
59
-
60
-	// plugins hash connu ? non si _CACHE_PLUGINS_OPT est pas encore chargé.
61
-	$_PLUGINS_HASH = defined('_PLUGINS_HASH') ? _PLUGINS_HASH : '!_CACHE_PLUGINS_OPT';
62
-
63
-	// prealablement recuperer les tables_principales
64
-	if (is_null($infos_tables) || $plugin_hash !== $_PLUGINS_HASH) {
65
-		// pas de reentrance (cas base/serial)
66
-		if ($deja_la) {
67
-			spip_log('Re-entrance anormale sur lister_tables_objets_sql : '
68
-				. var_export(debug_backtrace(), true), _LOG_CRITIQUE);
69
-
70
-			return ($table_sql === '::md5' ? $md5 : []);
71
-		}
72
-		$deja_la = true;
73
-		$plugin_hash = $_PLUGINS_HASH; // avant de lancer les pipelines
74
-
75
-		// recuperer les declarations explicites ancienne mode
76
-		// qui servent a completer declarer_tables_objets_sql
77
-		base_serial($GLOBALS['tables_principales']);
78
-		base_auxiliaires($GLOBALS['tables_auxiliaires']);
79
-		$infos_tables = [
80
-			'spip_articles' => [
81
-				'page' => 'article',
82
-				'texte_retour' => 'icone_retour_article',
83
-				'texte_modifier' => 'icone_modifier_article',
84
-				'texte_creer' => 'icone_ecrire_article',
85
-				'texte_objets' => 'public:articles',
86
-				'texte_objet' => 'public:article',
87
-				'texte_signale_edition' => 'texte_travail_article',
88
-				'info_aucun_objet' => 'info_aucun_article',
89
-				'info_1_objet' => 'info_1_article',
90
-				'info_nb_objets' => 'info_nb_articles',
91
-				'texte_logo_objet' => 'logo_article',
92
-				'texte_langue_objet' => 'titre_langue_article',
93
-				'texte_definir_comme_traduction_objet' => 'trad_lier',
94
-				'titre' => 'titre, lang',
95
-				'date' => 'date',
96
-				'principale' => 'oui',
97
-				'introduction_longueur' => '500',
98
-				'champs_editables' => [
99
-					'surtitre',
100
-					'titre',
101
-					'soustitre',
102
-					'descriptif',
103
-					'nom_site',
104
-					'url_site',
105
-					'chapo',
106
-					'texte',
107
-					'ps',
108
-					'virtuel'
109
-				],
110
-				'champs_versionnes' => [
111
-					'id_rubrique',
112
-					'surtitre',
113
-					'titre',
114
-					'soustitre',
115
-					'jointure_auteurs',
116
-					'descriptif',
117
-					'nom_site',
118
-					'url_site',
119
-					'chapo',
120
-					'texte',
121
-					'ps'
122
-				],
123
-				'field' => [
124
-					'id_article' => 'bigint(21) NOT NULL',
125
-					'surtitre' => "text DEFAULT '' NOT NULL",
126
-					'titre' => "text DEFAULT '' NOT NULL",
127
-					'soustitre' => "text DEFAULT '' NOT NULL",
128
-					'id_rubrique' => "bigint(21) DEFAULT '0' NOT NULL",
129
-					'descriptif' => "text DEFAULT '' NOT NULL",
130
-					'chapo' => "mediumtext DEFAULT '' NOT NULL",
131
-					'texte' => "longtext DEFAULT '' NOT NULL",
132
-					'ps' => "mediumtext DEFAULT '' NOT NULL",
133
-					'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
134
-					'statut' => "varchar(10) DEFAULT '0' NOT NULL",
135
-					'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL",
136
-					'maj' => 'TIMESTAMP',
137
-					'export' => "VARCHAR(10) DEFAULT 'oui'",
138
-					'date_redac' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
139
-					'visites' => "integer DEFAULT '0' NOT NULL",
140
-					'referers' => "integer DEFAULT '0' NOT NULL",
141
-					'popularite' => "DOUBLE DEFAULT '0' NOT NULL",
142
-					'accepter_forum' => "CHAR(3) DEFAULT '' NOT NULL",
143
-					'date_modif' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
144
-					'lang' => "VARCHAR(10) DEFAULT '' NOT NULL",
145
-					'langue_choisie' => "VARCHAR(3) DEFAULT 'non'",
146
-					'id_trad' => "bigint(21) DEFAULT '0' NOT NULL",
147
-					'nom_site' => "tinytext DEFAULT '' NOT NULL",
148
-					'url_site' => "text DEFAULT '' NOT NULL",
149
-					'virtuel' => "text DEFAULT '' NOT NULL",
150
-				],
151
-				'key' => [
152
-					'PRIMARY KEY' => 'id_article',
153
-					'KEY id_rubrique' => 'id_rubrique',
154
-					'KEY id_secteur' => 'id_secteur',
155
-					'KEY id_trad' => 'id_trad',
156
-					'KEY lang' => 'lang',
157
-					'KEY statut' => 'statut, date',
158
-				],
159
-				'join' => [
160
-					'id_article' => 'id_article',
161
-					'id_rubrique' => 'id_rubrique'
162
-				],
163
-				'parent' => [
164
-					['type' => 'rubrique', 'champ' => 'id_rubrique']
165
-				],
166
-				'rechercher_champs' => [
167
-					'surtitre' => 5,
168
-					'titre' => 8,
169
-					'soustitre' => 5,
170
-					'chapo' => 3,
171
-					'texte' => 1,
172
-					'ps' => 1,
173
-					'nom_site' => 1,
174
-					'url_site' => 1,
175
-					'descriptif' => 4
176
-				],
177
-				'rechercher_jointures' => [
178
-					'auteur' => ['nom' => 10],
179
-				],
180
-				'statut' => [
181
-					[
182
-						'champ' => 'statut',
183
-						'publie' => 'publie',
184
-						'previsu' => 'publie,prop,prepa/auteur',
185
-						'post_date' => 'date',
186
-						'exception' => ['statut', 'tout']
187
-					]
188
-				],
189
-				'statut_titres' => [
190
-					'prepa' => 'info_article_redaction',
191
-					'prop' => 'info_article_propose',
192
-					'publie' => 'info_article_publie',
193
-					'refuse' => 'info_article_refuse',
194
-					'poubelle' => 'info_article_supprime'
195
-				],
196
-				'statut_textes_instituer' => [
197
-					'prepa' => 'texte_statut_en_cours_redaction',
198
-					'prop' => 'texte_statut_propose_evaluation',
199
-					'publie' => 'texte_statut_publie',
200
-					'refuse' => 'texte_statut_refuse',
201
-					'poubelle' => 'texte_statut_poubelle',
202
-				],
203
-				'texte_changer_statut' => 'texte_article_statut',
204
-				'aide_changer_statut' => 'artstatut',
205
-				'tables_jointures' => [
206
-					'profondeur' => 'rubriques',
207
-					#'id_auteur' => 'auteurs_liens' // declaration generique plus bas
208
-				],
209
-			],
210
-			'spip_auteurs' => [
211
-				'page' => 'auteur',
212
-				'texte_retour' => 'icone_retour',
213
-				'texte_ajouter' => 'titre_ajouter_un_auteur',
214
-				'texte_modifier' => 'admin_modifier_auteur',
215
-				'texte_objets' => 'icone_auteurs',
216
-				'texte_objet' => 'public:auteur',
217
-				'info_aucun_objet' => 'info_aucun_auteur',
218
-				'info_1_objet' => 'info_1_auteur',
219
-				'info_nb_objets' => 'info_nb_auteurs',
220
-				'texte_logo_objet' => 'logo_auteur',
221
-				'texte_creer_associer' => 'creer_et_associer_un_auteur',
222
-				'titre' => "nom AS titre, '' AS lang",
223
-				'date' => 'date',
224
-				'principale' => 'oui',
225
-				'champs_editables' => ['nom', 'email', 'lang', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'],
226
-				'champs_versionnes' => ['nom', 'bio', 'lang', 'email', 'nom_site', 'url_site', 'login'],
227
-				'field' => [
228
-					'id_auteur' => 'bigint(21) NOT NULL',
229
-					'nom' => "text DEFAULT '' NOT NULL",
230
-					'bio' => "text DEFAULT '' NOT NULL",
231
-					'email' => "tinytext DEFAULT '' NOT NULL",
232
-					'nom_site' => "tinytext DEFAULT '' NOT NULL",
233
-					'url_site' => "text DEFAULT '' NOT NULL",
234
-					'login' => 'VARCHAR(255) BINARY',
235
-					'pass' => "tinytext DEFAULT '' NOT NULL",
236
-					'low_sec' => "tinytext DEFAULT '' NOT NULL",
237
-					'statut' => "varchar(255)  DEFAULT '0' NOT NULL",
238
-					'webmestre' => "varchar(3)  DEFAULT 'non' NOT NULL",
239
-					'maj' => 'TIMESTAMP',
240
-					'pgp' => "TEXT DEFAULT '' NOT NULL",
241
-					'htpass' => "tinytext DEFAULT '' NOT NULL",
242
-					'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
243
-					'alea_actuel' => 'tinytext',
244
-					'alea_futur' => 'tinytext',
245
-					'prefs' => 'text',
246
-					'cookie_oubli' => 'tinytext',
247
-					'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL",
248
-					'lang' => "VARCHAR(10) DEFAULT '' NOT NULL",
249
-					'imessage' => "VARCHAR(3) DEFAULT '' NOT NULL",
250
-					'backup_cles' => "mediumtext DEFAULT '' NOT NULL",
251
-				],
252
-				'key' => [
253
-					'PRIMARY KEY' => 'id_auteur',
254
-					'KEY login' => 'login',
255
-					'KEY statut' => 'statut',
256
-					'KEY en_ligne' => 'en_ligne',
257
-				],
258
-				'join' => [
259
-					'id_auteur' => 'id_auteur',
260
-					'login' => 'login'
261
-				],
262
-				'rechercher_champs' => [
263
-					'nom' => 5,
264
-					'bio' => 1,
265
-					'email' => 1,
266
-					'nom_site' => 1,
267
-					'url_site' => 1,
268
-					'login' => 1
269
-				],
270
-				// 2 conditions pour les auteurs : statut!=poubelle,
271
-				// et avoir des articles publies
272
-				'statut' => [
273
-					[
274
-						'champ' => 'statut',
275
-						'publie' => '!5poubelle',
276
-						'previsu' => '!5poubelle',
277
-						'exception' => 'statut'
278
-					],
279
-					[
280
-						'champ' => [
281
-							['spip_auteurs_liens', 'id_auteur'],
282
-							[
283
-								'spip_articles',
284
-								['id_objet', 'id_article', 'objet', 'article']
285
-							],
286
-							'statut'
287
-						],
288
-						'publie' => 'publie',
289
-						'previsu' => '!',
290
-						'post_date' => 'date',
291
-						'exception' => ['statut', 'lien', 'tout']
292
-					],
293
-				],
294
-				'statut_images' => [
295
-					'auteur-6forum-16.png',
296
-					'0minirezo' => 'auteur-0minirezo-16.png',
297
-					'1comite' => 'auteur-1comite-16.png',
298
-					'6forum' => 'auteur-6forum-16.png',
299
-					'5poubelle' => 'auteur-5poubelle-16.png',
300
-					'nouveau' => ''
301
-				],
302
-				'statut_titres' => [
303
-					'titre_image_visiteur',
304
-					'0minirezo' => 'titre_image_administrateur',
305
-					'1comite' => 'titre_image_redacteur_02',
306
-					'6forum' => 'titre_image_visiteur',
307
-					'5poubelle' => 'titre_image_auteur_supprime',
308
-				],
309
-				'tables_jointures' => [#'auteurs_liens' // declaration generique plus bas
310
-				],
311
-			],
312
-			'spip_rubriques' => [
313
-				'page' => 'rubrique',
314
-				'url_voir' => 'rubrique',
315
-				'url_edit' => 'rubrique_edit',
316
-				'texte_retour' => 'icone_retour',
317
-				'texte_objets' => 'public:rubriques',
318
-				'texte_objet' => 'public:rubrique',
319
-				'texte_modifier' => 'icone_modifier_rubrique',
320
-				'texte_creer' => 'icone_creer_rubrique',
321
-				'texte_ajouter' => 'titre_ajouter_une_rubrique',
322
-				'texte_creer_associer' => 'creer_et_associer_une_rubrique',
323
-				'info_aucun_objet' => 'info_aucun_rubrique',
324
-				'info_1_objet' => 'info_1_rubrique',
325
-				'info_nb_objets' => 'info_nb_rubriques',
326
-				'texte_logo_objet' => 'logo_rubrique',
327
-				'texte_langue_objet' => 'titre_langue_rubrique',
328
-				'texte_definir_comme_traduction_objet' => 'texte_definir_comme_traduction_rubrique',
329
-				'titre' => 'titre, lang',
330
-				'date' => 'date',
331
-				'principale' => 'oui',
332
-				'introduction_longueur' => '600',
333
-				'champs_editables' => ['titre', 'texte', 'descriptif', 'extra'],
334
-				'champs_versionnes' => ['titre', 'descriptif', 'texte'],
335
-				'field' => [
336
-					'id_rubrique' => 'bigint(21) NOT NULL',
337
-					'id_parent' => "bigint(21) DEFAULT '0' NOT NULL",
338
-					'titre' => "text DEFAULT '' NOT NULL",
339
-					'descriptif' => "text DEFAULT '' NOT NULL",
340
-					'texte' => "longtext DEFAULT '' NOT NULL",
341
-					'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL",
342
-					'maj' => 'TIMESTAMP',
343
-					'statut' => "varchar(10) DEFAULT '0' NOT NULL",
344
-					'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
345
-					'lang' => "VARCHAR(10) DEFAULT '' NOT NULL",
346
-					'langue_choisie' => "VARCHAR(3) DEFAULT 'non'",
347
-					'statut_tmp' => "varchar(10) DEFAULT '0' NOT NULL",
348
-					'date_tmp' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
349
-					'profondeur' => "smallint(5) DEFAULT '0' NOT NULL"
350
-				],
351
-				'key' => [
352
-					'PRIMARY KEY' => 'id_rubrique',
353
-					'KEY lang' => 'lang',
354
-					'KEY id_parent' => 'id_parent',
355
-				],
356
-				'parent' => [
357
-					['type' => 'rubrique', 'champ' => 'id_parent']
358
-				],
359
-				'rechercher_champs' => [
360
-					'titre' => 8,
361
-					'descriptif' => 5,
362
-					'texte' => 1
363
-				],
364
-				'statut' => [
365
-					[
366
-						'champ' => 'statut',
367
-						'publie' => 'publie',
368
-						'previsu' => '!',
369
-						'exception' => ['statut', 'tout']
370
-					],
371
-				],
372
-				'tables_jointures' => [#'id_auteur' => 'auteurs_liens' // declaration generique plus bas
373
-				],
374
-			],
375
-			// toutes les tables ont le droit a une jointure sur les auteurs
376
-			['tables_jointures' => ['id_auteur' => 'auteurs_liens']]
377
-		];
378
-
379
-		// avant d'appeller les pipeline qui peuvent generer une reentrance a l'install
380
-		// initialiser la signature
381
-		$md5 = md5(serialize($infos_tables));
382
-
383
-		$GLOBALS['tables_principales'] = pipeline('declarer_tables_principales', $GLOBALS['tables_principales']);
384
-		$GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires', $GLOBALS['tables_auxiliaires']);
385
-		$infos_tables = pipeline('declarer_tables_objets_sql', $infos_tables);
386
-
387
-		// completer les informations manquantes ou implicites
388
-		$all = [];
389
-		foreach (array_keys($infos_tables) as $t) {
390
-			// les cles numeriques servent a declarer
391
-			// les proprietes applicables a tous les objets
392
-			// on les mets de cote
393
-			if (is_numeric($t)) {
394
-				$all = array_merge_recursive($all, $infos_tables[$t]);
395
-				unset($infos_tables[$t]);
396
-			} else {
397
-				$infos_tables[$t] = renseigner_table_objet_sql($t, $infos_tables[$t]);
398
-			}
399
-		}
400
-
401
-		// repercuter les proprietes generales communes a tous les objets
402
-		foreach (array_keys($infos_tables) as $t) {
403
-			foreach (array_keys($all) as $i) {
404
-				if (in_array($i, ['tables_jointures', 'champs_versionnes'])) {
405
-					$add = $all[$i];
406
-					// eviter les doublons de declaration de table jointure (ex des mots sur auteurs)
407
-					// pour les declarations generiques avec cles numeriques
408
-					if ($i == 'tables_jointures' && isset($infos_tables[$t][$i]) && (is_countable($infos_tables[$t][$i]) ? count($infos_tables[$t][$i]) : 0)) {
409
-						$doublons = array_intersect($infos_tables[$t][$i], $add);
410
-						foreach ($doublons as $d) {
411
-							if (
412
-								is_numeric(array_search($d, $infos_tables[$t][$i]))
413
-								&& is_numeric($k = array_search($d, $add))
414
-							) {
415
-								unset($add[$k]);
416
-							}
417
-						}
418
-					}
419
-					$infos_tables[$t][$i] = array_merge($infos_tables[$t][$i] ?? [], $add);
420
-				} else {
421
-					$infos_tables[$t][$i] = array_merge_recursive(
422
-						$infos_tables[$t][$i] ?? [],
423
-						$all[$i]
424
-					);
425
-				}
426
-			}
427
-		}
428
-
429
-		// completer les tables principales et auxiliaires
430
-		// avec celles declarees uniquement dans declarer_table_objets_sql
431
-		// pour assurer la compat en transition
432
-		foreach ($infos_tables as $table => $infos) {
433
-			$principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires');
434
-			// memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx
435
-			// qui a ete appelle avant
436
-			$mem = ($GLOBALS[$principale_ou_auxiliaire][$table] ?? []);
437
-			// l'ajouter au tableau
438
-			$GLOBALS[$principale_ou_auxiliaire][$table] = [];
439
-			if (isset($infos['field']) && isset($infos['key'])) {
440
-				foreach (['field', 'key', 'join'] as $k) {
441
-					if (isset($infos_tables[$table][$k])) {
442
-						$GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k];
443
-					}
444
-				}
445
-			} else {
446
-				// ici on ne renvoie que les declarations, donc RIEN
447
-				// pour avoir la vrai description en base, il faut passer par trouver_table
448
-				$GLOBALS[$principale_ou_auxiliaire][$table] = [];
449
-			}
450
-			if (is_countable($mem) ? count($mem) : 0) {
451
-				foreach (array_keys($mem) as $k) {
452
-					if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) {
453
-						$GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge(
454
-							$GLOBALS[$principale_ou_auxiliaire][$table][$k],
455
-							$mem[$k]
456
-						);
457
-					} else {
458
-						$GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k];
459
-					}
460
-				}
461
-			}
462
-		}
463
-
464
-		// recuperer les interfaces (table_titre, table_date)
465
-		// on ne le fait que dans un second temps pour que table_objet soit fonctionnel
466
-		// dans le pipeline de declarer_tables_interfaces
467
-		include_spip('public/interfaces');
468
-		foreach (array_keys($infos_tables) as $t) {
469
-			$infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]);
470
-		}
471
-
472
-		$deja_la = false;
473
-		// signature
474
-		$md5 = md5(serialize($infos_tables));
475
-	}
476
-	if ($table_sql === '::md5') {
477
-		return $md5;
478
-	}
479
-	if ($table_sql && !isset($infos_tables[$table_sql])) {
480
-		#$desc = renseigner_table_objet_sql($table_sql,$desc);
481
-		$desc = renseigner_table_objet_interfaces($table_sql, $desc);
482
-
483
-		return $desc;
484
-	}
485
-	if ($table_sql) {
486
-		return $infos_tables[$table_sql] ?? [];
487
-	}
488
-
489
-	return $infos_tables;
55
+    static $deja_la = false;
56
+    static $infos_tables = null;
57
+    static $md5 = null;
58
+    static $plugin_hash = null;
59
+
60
+    // plugins hash connu ? non si _CACHE_PLUGINS_OPT est pas encore chargé.
61
+    $_PLUGINS_HASH = defined('_PLUGINS_HASH') ? _PLUGINS_HASH : '!_CACHE_PLUGINS_OPT';
62
+
63
+    // prealablement recuperer les tables_principales
64
+    if (is_null($infos_tables) || $plugin_hash !== $_PLUGINS_HASH) {
65
+        // pas de reentrance (cas base/serial)
66
+        if ($deja_la) {
67
+            spip_log('Re-entrance anormale sur lister_tables_objets_sql : '
68
+                . var_export(debug_backtrace(), true), _LOG_CRITIQUE);
69
+
70
+            return ($table_sql === '::md5' ? $md5 : []);
71
+        }
72
+        $deja_la = true;
73
+        $plugin_hash = $_PLUGINS_HASH; // avant de lancer les pipelines
74
+
75
+        // recuperer les declarations explicites ancienne mode
76
+        // qui servent a completer declarer_tables_objets_sql
77
+        base_serial($GLOBALS['tables_principales']);
78
+        base_auxiliaires($GLOBALS['tables_auxiliaires']);
79
+        $infos_tables = [
80
+            'spip_articles' => [
81
+                'page' => 'article',
82
+                'texte_retour' => 'icone_retour_article',
83
+                'texte_modifier' => 'icone_modifier_article',
84
+                'texte_creer' => 'icone_ecrire_article',
85
+                'texte_objets' => 'public:articles',
86
+                'texte_objet' => 'public:article',
87
+                'texte_signale_edition' => 'texte_travail_article',
88
+                'info_aucun_objet' => 'info_aucun_article',
89
+                'info_1_objet' => 'info_1_article',
90
+                'info_nb_objets' => 'info_nb_articles',
91
+                'texte_logo_objet' => 'logo_article',
92
+                'texte_langue_objet' => 'titre_langue_article',
93
+                'texte_definir_comme_traduction_objet' => 'trad_lier',
94
+                'titre' => 'titre, lang',
95
+                'date' => 'date',
96
+                'principale' => 'oui',
97
+                'introduction_longueur' => '500',
98
+                'champs_editables' => [
99
+                    'surtitre',
100
+                    'titre',
101
+                    'soustitre',
102
+                    'descriptif',
103
+                    'nom_site',
104
+                    'url_site',
105
+                    'chapo',
106
+                    'texte',
107
+                    'ps',
108
+                    'virtuel'
109
+                ],
110
+                'champs_versionnes' => [
111
+                    'id_rubrique',
112
+                    'surtitre',
113
+                    'titre',
114
+                    'soustitre',
115
+                    'jointure_auteurs',
116
+                    'descriptif',
117
+                    'nom_site',
118
+                    'url_site',
119
+                    'chapo',
120
+                    'texte',
121
+                    'ps'
122
+                ],
123
+                'field' => [
124
+                    'id_article' => 'bigint(21) NOT NULL',
125
+                    'surtitre' => "text DEFAULT '' NOT NULL",
126
+                    'titre' => "text DEFAULT '' NOT NULL",
127
+                    'soustitre' => "text DEFAULT '' NOT NULL",
128
+                    'id_rubrique' => "bigint(21) DEFAULT '0' NOT NULL",
129
+                    'descriptif' => "text DEFAULT '' NOT NULL",
130
+                    'chapo' => "mediumtext DEFAULT '' NOT NULL",
131
+                    'texte' => "longtext DEFAULT '' NOT NULL",
132
+                    'ps' => "mediumtext DEFAULT '' NOT NULL",
133
+                    'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
134
+                    'statut' => "varchar(10) DEFAULT '0' NOT NULL",
135
+                    'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL",
136
+                    'maj' => 'TIMESTAMP',
137
+                    'export' => "VARCHAR(10) DEFAULT 'oui'",
138
+                    'date_redac' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
139
+                    'visites' => "integer DEFAULT '0' NOT NULL",
140
+                    'referers' => "integer DEFAULT '0' NOT NULL",
141
+                    'popularite' => "DOUBLE DEFAULT '0' NOT NULL",
142
+                    'accepter_forum' => "CHAR(3) DEFAULT '' NOT NULL",
143
+                    'date_modif' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
144
+                    'lang' => "VARCHAR(10) DEFAULT '' NOT NULL",
145
+                    'langue_choisie' => "VARCHAR(3) DEFAULT 'non'",
146
+                    'id_trad' => "bigint(21) DEFAULT '0' NOT NULL",
147
+                    'nom_site' => "tinytext DEFAULT '' NOT NULL",
148
+                    'url_site' => "text DEFAULT '' NOT NULL",
149
+                    'virtuel' => "text DEFAULT '' NOT NULL",
150
+                ],
151
+                'key' => [
152
+                    'PRIMARY KEY' => 'id_article',
153
+                    'KEY id_rubrique' => 'id_rubrique',
154
+                    'KEY id_secteur' => 'id_secteur',
155
+                    'KEY id_trad' => 'id_trad',
156
+                    'KEY lang' => 'lang',
157
+                    'KEY statut' => 'statut, date',
158
+                ],
159
+                'join' => [
160
+                    'id_article' => 'id_article',
161
+                    'id_rubrique' => 'id_rubrique'
162
+                ],
163
+                'parent' => [
164
+                    ['type' => 'rubrique', 'champ' => 'id_rubrique']
165
+                ],
166
+                'rechercher_champs' => [
167
+                    'surtitre' => 5,
168
+                    'titre' => 8,
169
+                    'soustitre' => 5,
170
+                    'chapo' => 3,
171
+                    'texte' => 1,
172
+                    'ps' => 1,
173
+                    'nom_site' => 1,
174
+                    'url_site' => 1,
175
+                    'descriptif' => 4
176
+                ],
177
+                'rechercher_jointures' => [
178
+                    'auteur' => ['nom' => 10],
179
+                ],
180
+                'statut' => [
181
+                    [
182
+                        'champ' => 'statut',
183
+                        'publie' => 'publie',
184
+                        'previsu' => 'publie,prop,prepa/auteur',
185
+                        'post_date' => 'date',
186
+                        'exception' => ['statut', 'tout']
187
+                    ]
188
+                ],
189
+                'statut_titres' => [
190
+                    'prepa' => 'info_article_redaction',
191
+                    'prop' => 'info_article_propose',
192
+                    'publie' => 'info_article_publie',
193
+                    'refuse' => 'info_article_refuse',
194
+                    'poubelle' => 'info_article_supprime'
195
+                ],
196
+                'statut_textes_instituer' => [
197
+                    'prepa' => 'texte_statut_en_cours_redaction',
198
+                    'prop' => 'texte_statut_propose_evaluation',
199
+                    'publie' => 'texte_statut_publie',
200
+                    'refuse' => 'texte_statut_refuse',
201
+                    'poubelle' => 'texte_statut_poubelle',
202
+                ],
203
+                'texte_changer_statut' => 'texte_article_statut',
204
+                'aide_changer_statut' => 'artstatut',
205
+                'tables_jointures' => [
206
+                    'profondeur' => 'rubriques',
207
+                    #'id_auteur' => 'auteurs_liens' // declaration generique plus bas
208
+                ],
209
+            ],
210
+            'spip_auteurs' => [
211
+                'page' => 'auteur',
212
+                'texte_retour' => 'icone_retour',
213
+                'texte_ajouter' => 'titre_ajouter_un_auteur',
214
+                'texte_modifier' => 'admin_modifier_auteur',
215
+                'texte_objets' => 'icone_auteurs',
216
+                'texte_objet' => 'public:auteur',
217
+                'info_aucun_objet' => 'info_aucun_auteur',
218
+                'info_1_objet' => 'info_1_auteur',
219
+                'info_nb_objets' => 'info_nb_auteurs',
220
+                'texte_logo_objet' => 'logo_auteur',
221
+                'texte_creer_associer' => 'creer_et_associer_un_auteur',
222
+                'titre' => "nom AS titre, '' AS lang",
223
+                'date' => 'date',
224
+                'principale' => 'oui',
225
+                'champs_editables' => ['nom', 'email', 'lang', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'],
226
+                'champs_versionnes' => ['nom', 'bio', 'lang', 'email', 'nom_site', 'url_site', 'login'],
227
+                'field' => [
228
+                    'id_auteur' => 'bigint(21) NOT NULL',
229
+                    'nom' => "text DEFAULT '' NOT NULL",
230
+                    'bio' => "text DEFAULT '' NOT NULL",
231
+                    'email' => "tinytext DEFAULT '' NOT NULL",
232
+                    'nom_site' => "tinytext DEFAULT '' NOT NULL",
233
+                    'url_site' => "text DEFAULT '' NOT NULL",
234
+                    'login' => 'VARCHAR(255) BINARY',
235
+                    'pass' => "tinytext DEFAULT '' NOT NULL",
236
+                    'low_sec' => "tinytext DEFAULT '' NOT NULL",
237
+                    'statut' => "varchar(255)  DEFAULT '0' NOT NULL",
238
+                    'webmestre' => "varchar(3)  DEFAULT 'non' NOT NULL",
239
+                    'maj' => 'TIMESTAMP',
240
+                    'pgp' => "TEXT DEFAULT '' NOT NULL",
241
+                    'htpass' => "tinytext DEFAULT '' NOT NULL",
242
+                    'en_ligne' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
243
+                    'alea_actuel' => 'tinytext',
244
+                    'alea_futur' => 'tinytext',
245
+                    'prefs' => 'text',
246
+                    'cookie_oubli' => 'tinytext',
247
+                    'source' => "VARCHAR(10) DEFAULT 'spip' NOT NULL",
248
+                    'lang' => "VARCHAR(10) DEFAULT '' NOT NULL",
249
+                    'imessage' => "VARCHAR(3) DEFAULT '' NOT NULL",
250
+                    'backup_cles' => "mediumtext DEFAULT '' NOT NULL",
251
+                ],
252
+                'key' => [
253
+                    'PRIMARY KEY' => 'id_auteur',
254
+                    'KEY login' => 'login',
255
+                    'KEY statut' => 'statut',
256
+                    'KEY en_ligne' => 'en_ligne',
257
+                ],
258
+                'join' => [
259
+                    'id_auteur' => 'id_auteur',
260
+                    'login' => 'login'
261
+                ],
262
+                'rechercher_champs' => [
263
+                    'nom' => 5,
264
+                    'bio' => 1,
265
+                    'email' => 1,
266
+                    'nom_site' => 1,
267
+                    'url_site' => 1,
268
+                    'login' => 1
269
+                ],
270
+                // 2 conditions pour les auteurs : statut!=poubelle,
271
+                // et avoir des articles publies
272
+                'statut' => [
273
+                    [
274
+                        'champ' => 'statut',
275
+                        'publie' => '!5poubelle',
276
+                        'previsu' => '!5poubelle',
277
+                        'exception' => 'statut'
278
+                    ],
279
+                    [
280
+                        'champ' => [
281
+                            ['spip_auteurs_liens', 'id_auteur'],
282
+                            [
283
+                                'spip_articles',
284
+                                ['id_objet', 'id_article', 'objet', 'article']
285
+                            ],
286
+                            'statut'
287
+                        ],
288
+                        'publie' => 'publie',
289
+                        'previsu' => '!',
290
+                        'post_date' => 'date',
291
+                        'exception' => ['statut', 'lien', 'tout']
292
+                    ],
293
+                ],
294
+                'statut_images' => [
295
+                    'auteur-6forum-16.png',
296
+                    '0minirezo' => 'auteur-0minirezo-16.png',
297
+                    '1comite' => 'auteur-1comite-16.png',
298
+                    '6forum' => 'auteur-6forum-16.png',
299
+                    '5poubelle' => 'auteur-5poubelle-16.png',
300
+                    'nouveau' => ''
301
+                ],
302
+                'statut_titres' => [
303
+                    'titre_image_visiteur',
304
+                    '0minirezo' => 'titre_image_administrateur',
305
+                    '1comite' => 'titre_image_redacteur_02',
306
+                    '6forum' => 'titre_image_visiteur',
307
+                    '5poubelle' => 'titre_image_auteur_supprime',
308
+                ],
309
+                'tables_jointures' => [#'auteurs_liens' // declaration generique plus bas
310
+                ],
311
+            ],
312
+            'spip_rubriques' => [
313
+                'page' => 'rubrique',
314
+                'url_voir' => 'rubrique',
315
+                'url_edit' => 'rubrique_edit',
316
+                'texte_retour' => 'icone_retour',
317
+                'texte_objets' => 'public:rubriques',
318
+                'texte_objet' => 'public:rubrique',
319
+                'texte_modifier' => 'icone_modifier_rubrique',
320
+                'texte_creer' => 'icone_creer_rubrique',
321
+                'texte_ajouter' => 'titre_ajouter_une_rubrique',
322
+                'texte_creer_associer' => 'creer_et_associer_une_rubrique',
323
+                'info_aucun_objet' => 'info_aucun_rubrique',
324
+                'info_1_objet' => 'info_1_rubrique',
325
+                'info_nb_objets' => 'info_nb_rubriques',
326
+                'texte_logo_objet' => 'logo_rubrique',
327
+                'texte_langue_objet' => 'titre_langue_rubrique',
328
+                'texte_definir_comme_traduction_objet' => 'texte_definir_comme_traduction_rubrique',
329
+                'titre' => 'titre, lang',
330
+                'date' => 'date',
331
+                'principale' => 'oui',
332
+                'introduction_longueur' => '600',
333
+                'champs_editables' => ['titre', 'texte', 'descriptif', 'extra'],
334
+                'champs_versionnes' => ['titre', 'descriptif', 'texte'],
335
+                'field' => [
336
+                    'id_rubrique' => 'bigint(21) NOT NULL',
337
+                    'id_parent' => "bigint(21) DEFAULT '0' NOT NULL",
338
+                    'titre' => "text DEFAULT '' NOT NULL",
339
+                    'descriptif' => "text DEFAULT '' NOT NULL",
340
+                    'texte' => "longtext DEFAULT '' NOT NULL",
341
+                    'id_secteur' => "bigint(21) DEFAULT '0' NOT NULL",
342
+                    'maj' => 'TIMESTAMP',
343
+                    'statut' => "varchar(10) DEFAULT '0' NOT NULL",
344
+                    'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
345
+                    'lang' => "VARCHAR(10) DEFAULT '' NOT NULL",
346
+                    'langue_choisie' => "VARCHAR(3) DEFAULT 'non'",
347
+                    'statut_tmp' => "varchar(10) DEFAULT '0' NOT NULL",
348
+                    'date_tmp' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
349
+                    'profondeur' => "smallint(5) DEFAULT '0' NOT NULL"
350
+                ],
351
+                'key' => [
352
+                    'PRIMARY KEY' => 'id_rubrique',
353
+                    'KEY lang' => 'lang',
354
+                    'KEY id_parent' => 'id_parent',
355
+                ],
356
+                'parent' => [
357
+                    ['type' => 'rubrique', 'champ' => 'id_parent']
358
+                ],
359
+                'rechercher_champs' => [
360
+                    'titre' => 8,
361
+                    'descriptif' => 5,
362
+                    'texte' => 1
363
+                ],
364
+                'statut' => [
365
+                    [
366
+                        'champ' => 'statut',
367
+                        'publie' => 'publie',
368
+                        'previsu' => '!',
369
+                        'exception' => ['statut', 'tout']
370
+                    ],
371
+                ],
372
+                'tables_jointures' => [#'id_auteur' => 'auteurs_liens' // declaration generique plus bas
373
+                ],
374
+            ],
375
+            // toutes les tables ont le droit a une jointure sur les auteurs
376
+            ['tables_jointures' => ['id_auteur' => 'auteurs_liens']]
377
+        ];
378
+
379
+        // avant d'appeller les pipeline qui peuvent generer une reentrance a l'install
380
+        // initialiser la signature
381
+        $md5 = md5(serialize($infos_tables));
382
+
383
+        $GLOBALS['tables_principales'] = pipeline('declarer_tables_principales', $GLOBALS['tables_principales']);
384
+        $GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires', $GLOBALS['tables_auxiliaires']);
385
+        $infos_tables = pipeline('declarer_tables_objets_sql', $infos_tables);
386
+
387
+        // completer les informations manquantes ou implicites
388
+        $all = [];
389
+        foreach (array_keys($infos_tables) as $t) {
390
+            // les cles numeriques servent a declarer
391
+            // les proprietes applicables a tous les objets
392
+            // on les mets de cote
393
+            if (is_numeric($t)) {
394
+                $all = array_merge_recursive($all, $infos_tables[$t]);
395
+                unset($infos_tables[$t]);
396
+            } else {
397
+                $infos_tables[$t] = renseigner_table_objet_sql($t, $infos_tables[$t]);
398
+            }
399
+        }
400
+
401
+        // repercuter les proprietes generales communes a tous les objets
402
+        foreach (array_keys($infos_tables) as $t) {
403
+            foreach (array_keys($all) as $i) {
404
+                if (in_array($i, ['tables_jointures', 'champs_versionnes'])) {
405
+                    $add = $all[$i];
406
+                    // eviter les doublons de declaration de table jointure (ex des mots sur auteurs)
407
+                    // pour les declarations generiques avec cles numeriques
408
+                    if ($i == 'tables_jointures' && isset($infos_tables[$t][$i]) && (is_countable($infos_tables[$t][$i]) ? count($infos_tables[$t][$i]) : 0)) {
409
+                        $doublons = array_intersect($infos_tables[$t][$i], $add);
410
+                        foreach ($doublons as $d) {
411
+                            if (
412
+                                is_numeric(array_search($d, $infos_tables[$t][$i]))
413
+                                && is_numeric($k = array_search($d, $add))
414
+                            ) {
415
+                                unset($add[$k]);
416
+                            }
417
+                        }
418
+                    }
419
+                    $infos_tables[$t][$i] = array_merge($infos_tables[$t][$i] ?? [], $add);
420
+                } else {
421
+                    $infos_tables[$t][$i] = array_merge_recursive(
422
+                        $infos_tables[$t][$i] ?? [],
423
+                        $all[$i]
424
+                    );
425
+                }
426
+            }
427
+        }
428
+
429
+        // completer les tables principales et auxiliaires
430
+        // avec celles declarees uniquement dans declarer_table_objets_sql
431
+        // pour assurer la compat en transition
432
+        foreach ($infos_tables as $table => $infos) {
433
+            $principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires');
434
+            // memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx
435
+            // qui a ete appelle avant
436
+            $mem = ($GLOBALS[$principale_ou_auxiliaire][$table] ?? []);
437
+            // l'ajouter au tableau
438
+            $GLOBALS[$principale_ou_auxiliaire][$table] = [];
439
+            if (isset($infos['field']) && isset($infos['key'])) {
440
+                foreach (['field', 'key', 'join'] as $k) {
441
+                    if (isset($infos_tables[$table][$k])) {
442
+                        $GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k];
443
+                    }
444
+                }
445
+            } else {
446
+                // ici on ne renvoie que les declarations, donc RIEN
447
+                // pour avoir la vrai description en base, il faut passer par trouver_table
448
+                $GLOBALS[$principale_ou_auxiliaire][$table] = [];
449
+            }
450
+            if (is_countable($mem) ? count($mem) : 0) {
451
+                foreach (array_keys($mem) as $k) {
452
+                    if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) {
453
+                        $GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge(
454
+                            $GLOBALS[$principale_ou_auxiliaire][$table][$k],
455
+                            $mem[$k]
456
+                        );
457
+                    } else {
458
+                        $GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k];
459
+                    }
460
+                }
461
+            }
462
+        }
463
+
464
+        // recuperer les interfaces (table_titre, table_date)
465
+        // on ne le fait que dans un second temps pour que table_objet soit fonctionnel
466
+        // dans le pipeline de declarer_tables_interfaces
467
+        include_spip('public/interfaces');
468
+        foreach (array_keys($infos_tables) as $t) {
469
+            $infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]);
470
+        }
471
+
472
+        $deja_la = false;
473
+        // signature
474
+        $md5 = md5(serialize($infos_tables));
475
+    }
476
+    if ($table_sql === '::md5') {
477
+        return $md5;
478
+    }
479
+    if ($table_sql && !isset($infos_tables[$table_sql])) {
480
+        #$desc = renseigner_table_objet_sql($table_sql,$desc);
481
+        $desc = renseigner_table_objet_interfaces($table_sql, $desc);
482
+
483
+        return $desc;
484
+    }
485
+    if ($table_sql) {
486
+        return $infos_tables[$table_sql] ?? [];
487
+    }
488
+
489
+    return $infos_tables;
490 490
 }
491 491
 
492 492
 
@@ -501,27 +501,27 @@  discard block
 block discarded – undo
501 501
  **/
502 502
 function base_serial(&$tables_principales) {
503 503
 
504
-	$spip_jobs = [
505
-		'id_job' => 'bigint(21) NOT NULL',
506
-		'descriptif' => "text DEFAULT '' NOT NULL",
507
-		'fonction' => 'varchar(255) NOT NULL', //nom de la fonction
508
-		'args' => "longblob DEFAULT '' NOT NULL", // arguments
509
-		'md5args' => "char(32) NOT NULL default ''", // signature des arguments
510
-		'inclure' => 'varchar(255) NOT NULL', // fichier a inclure ou path/ pour charger_fonction
511
-		'priorite' => 'smallint(6) NOT NULL default 0',
512
-		'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", // date au plus tot
513
-		'status' => 'tinyint NOT NULL default 1',
514
-	];
515
-
516
-	$spip_jobs_key = [
517
-		'PRIMARY KEY' => 'id_job',
518
-		'KEY date' => 'date',
519
-		'KEY status' => 'status',
520
-	];
521
-
522
-	/// Attention: mes_fonctions peut avoir deja defini cette variable
523
-	/// il faut donc rajouter, mais pas reinitialiser
524
-	$tables_principales['spip_jobs'] = ['field' => &$spip_jobs, 'key' => &$spip_jobs_key];
504
+    $spip_jobs = [
505
+        'id_job' => 'bigint(21) NOT NULL',
506
+        'descriptif' => "text DEFAULT '' NOT NULL",
507
+        'fonction' => 'varchar(255) NOT NULL', //nom de la fonction
508
+        'args' => "longblob DEFAULT '' NOT NULL", // arguments
509
+        'md5args' => "char(32) NOT NULL default ''", // signature des arguments
510
+        'inclure' => 'varchar(255) NOT NULL', // fichier a inclure ou path/ pour charger_fonction
511
+        'priorite' => 'smallint(6) NOT NULL default 0',
512
+        'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL", // date au plus tot
513
+        'status' => 'tinyint NOT NULL default 1',
514
+    ];
515
+
516
+    $spip_jobs_key = [
517
+        'PRIMARY KEY' => 'id_job',
518
+        'KEY date' => 'date',
519
+        'KEY status' => 'status',
520
+    ];
521
+
522
+    /// Attention: mes_fonctions peut avoir deja defini cette variable
523
+    /// il faut donc rajouter, mais pas reinitialiser
524
+    $tables_principales['spip_jobs'] = ['field' => &$spip_jobs, 'key' => &$spip_jobs_key];
525 525
 }
526 526
 
527 527
 
@@ -533,71 +533,71 @@  discard block
 block discarded – undo
533 533
  * @return void
534 534
  **/
535 535
 function base_auxiliaires(&$tables_auxiliaires) {
536
-	$spip_resultats = [
537
-		'recherche' => "char(16) DEFAULT '' NOT NULL",
538
-		'id' => 'INT UNSIGNED NOT NULL',
539
-		'points' => "INT UNSIGNED DEFAULT '0' NOT NULL",
540
-		'table_objet' => "varchar(30) DEFAULT '' NOT NULL",
541
-		'serveur' => "char(16) DEFAULT '' NOT NULL", // hash md5 partiel du serveur de base ('' pour le serveur principal)
542
-		'maj' => 'TIMESTAMP'
543
-	];
544
-
545
-	$spip_resultats_key = [// pas de cle ni index, ca fait des insertions plus rapides et les requetes jointes utilisees en recheche ne sont pas plus lentes ...
546
-	];
547
-
548
-	$spip_auteurs_liens = [
549
-		'id_auteur' => "bigint(21) DEFAULT '0' NOT NULL",
550
-		'id_objet' => "bigint(21) DEFAULT '0' NOT NULL",
551
-		'objet' => "VARCHAR (25) DEFAULT '' NOT NULL",
552
-		'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL"
553
-	];
554
-
555
-	$spip_auteurs_liens_key = [
556
-		'PRIMARY KEY' => 'id_auteur,id_objet,objet',
557
-		'KEY id_auteur' => 'id_auteur',
558
-		'KEY id_objet' => 'id_objet',
559
-		'KEY objet' => 'objet',
560
-	];
561
-
562
-	$spip_meta = [
563
-		'nom' => 'VARCHAR (255) NOT NULL',
564
-		'valeur' => "text DEFAULT ''",
565
-		'impt' => "ENUM('non', 'oui') DEFAULT 'oui' NOT NULL",
566
-		'maj' => 'TIMESTAMP'
567
-	];
568
-
569
-	$spip_meta_key = [
570
-		'PRIMARY KEY' => 'nom'
571
-	];
572
-
573
-	$spip_jobs_liens = [
574
-		'id_job' => "bigint(21) DEFAULT '0' NOT NULL",
575
-		'id_objet' => "bigint(21) DEFAULT '0' NOT NULL",
576
-		'objet' => "VARCHAR (25) DEFAULT '' NOT NULL",
577
-	];
578
-
579
-	$spip_jobs_liens_key = [
580
-		'PRIMARY KEY' => 'id_job,id_objet,objet',
581
-		'KEY id_job' => 'id_job'
582
-	];
583
-
584
-	$tables_auxiliaires['spip_auteurs_liens'] = [
585
-		'field' => &$spip_auteurs_liens,
586
-		'key' => &$spip_auteurs_liens_key
587
-	];
588
-
589
-	$tables_auxiliaires['spip_meta'] = [
590
-		'field' => &$spip_meta,
591
-		'key' => &$spip_meta_key
592
-	];
593
-	$tables_auxiliaires['spip_resultats'] = [
594
-		'field' => &$spip_resultats,
595
-		'key' => &$spip_resultats_key
596
-	];
597
-	$tables_auxiliaires['spip_jobs_liens'] = [
598
-		'field' => &$spip_jobs_liens,
599
-		'key' => &$spip_jobs_liens_key
600
-	];
536
+    $spip_resultats = [
537
+        'recherche' => "char(16) DEFAULT '' NOT NULL",
538
+        'id' => 'INT UNSIGNED NOT NULL',
539
+        'points' => "INT UNSIGNED DEFAULT '0' NOT NULL",
540
+        'table_objet' => "varchar(30) DEFAULT '' NOT NULL",
541
+        'serveur' => "char(16) DEFAULT '' NOT NULL", // hash md5 partiel du serveur de base ('' pour le serveur principal)
542
+        'maj' => 'TIMESTAMP'
543
+    ];
544
+
545
+    $spip_resultats_key = [// pas de cle ni index, ca fait des insertions plus rapides et les requetes jointes utilisees en recheche ne sont pas plus lentes ...
546
+    ];
547
+
548
+    $spip_auteurs_liens = [
549
+        'id_auteur' => "bigint(21) DEFAULT '0' NOT NULL",
550
+        'id_objet' => "bigint(21) DEFAULT '0' NOT NULL",
551
+        'objet' => "VARCHAR (25) DEFAULT '' NOT NULL",
552
+        'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL"
553
+    ];
554
+
555
+    $spip_auteurs_liens_key = [
556
+        'PRIMARY KEY' => 'id_auteur,id_objet,objet',
557
+        'KEY id_auteur' => 'id_auteur',
558
+        'KEY id_objet' => 'id_objet',
559
+        'KEY objet' => 'objet',
560
+    ];
561
+
562
+    $spip_meta = [
563
+        'nom' => 'VARCHAR (255) NOT NULL',
564
+        'valeur' => "text DEFAULT ''",
565
+        'impt' => "ENUM('non', 'oui') DEFAULT 'oui' NOT NULL",
566
+        'maj' => 'TIMESTAMP'
567
+    ];
568
+
569
+    $spip_meta_key = [
570
+        'PRIMARY KEY' => 'nom'
571
+    ];
572
+
573
+    $spip_jobs_liens = [
574
+        'id_job' => "bigint(21) DEFAULT '0' NOT NULL",
575
+        'id_objet' => "bigint(21) DEFAULT '0' NOT NULL",
576
+        'objet' => "VARCHAR (25) DEFAULT '' NOT NULL",
577
+    ];
578
+
579
+    $spip_jobs_liens_key = [
580
+        'PRIMARY KEY' => 'id_job,id_objet,objet',
581
+        'KEY id_job' => 'id_job'
582
+    ];
583
+
584
+    $tables_auxiliaires['spip_auteurs_liens'] = [
585
+        'field' => &$spip_auteurs_liens,
586
+        'key' => &$spip_auteurs_liens_key
587
+    ];
588
+
589
+    $tables_auxiliaires['spip_meta'] = [
590
+        'field' => &$spip_meta,
591
+        'key' => &$spip_meta_key
592
+    ];
593
+    $tables_auxiliaires['spip_resultats'] = [
594
+        'field' => &$spip_resultats,
595
+        'key' => &$spip_resultats_key
596
+    ];
597
+    $tables_auxiliaires['spip_jobs_liens'] = [
598
+        'field' => &$spip_jobs_liens,
599
+        'key' => &$spip_jobs_liens_key
600
+    ];
601 601
 }
602 602
 
603 603
 
@@ -654,129 +654,129 @@  discard block
 block discarded – undo
654 654
  * @return array
655 655
  */
656 656
 function renseigner_table_objet_sql($table_sql, &$infos) {
657
-	if (!isset($infos['type'])) {
658
-		// si on arrive de base/trouver_table, on a la cle primaire :
659
-		// s'en servir pour extrapoler le type
660
-		if (isset($infos['key']['PRIMARY KEY'])) {
661
-			$primary = $infos['key']['PRIMARY KEY'];
662
-			$primary = explode(',', (string) $primary);
663
-			$primary = reset($primary);
664
-			$infos['type'] = preg_replace(',^spip_|^id_|s$,', '', $primary);
665
-		} else {
666
-			$infos['type'] = preg_replace(',^spip_|s$,', '', $table_sql);
667
-		}
668
-	}
669
-	if (!isset($infos['type_surnoms'])) {
670
-		$infos['type_surnoms'] = [];
671
-	}
672
-
673
-	if (!isset($infos['table_objet'])) {
674
-		$infos['table_objet'] = preg_replace(',^spip_,', '', $table_sql);
675
-	}
676
-	if (!isset($infos['table_objet_surnoms'])) {
677
-		$infos['table_objet_surnoms'] = [];
678
-	}
679
-
680
-	if (!isset($infos['principale'])) {
681
-		$infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql]) ? 'oui' : false);
682
-	}
683
-
684
-	// normaliser pour pouvoir tester en php $infos['principale']?
685
-	// et dans une boucle {principale=oui}
686
-	$infos['principale'] = (($infos['principale'] && $infos['principale'] != 'non') ? 'oui' : false);
687
-
688
-	// declarer et normaliser pour pouvoir tester en php $infos['editable']?
689
-	// et dans une boucle {editable=oui}
690
-	if (!isset($infos['editable'])) {
691
-		$infos['editable'] = 'oui';
692
-	}
693
-
694
-	$infos['editable'] = (($infos['editable'] && $infos['editable'] != 'non') ? 'oui' : false);
695
-
696
-	// les urls publiques sont par defaut page=type pour les tables principales, et rien pour les autres
697
-	// seules les exceptions sont donc a declarer
698
-	if (!isset($infos['page'])) {
699
-		$infos['page'] = ($infos['principale'] ? $infos['type'] : '');
700
-	}
701
-
702
-	if (!isset($infos['url_voir'])) {
703
-		$infos['url_voir'] = $infos['type'];
704
-	}
705
-	if (!isset($infos['url_edit'])) {
706
-		$infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : '');
707
-	}
708
-	if (!isset($infos['icone_objet'])) {
709
-		$infos['icone_objet'] = $infos['type'];
710
-	}
711
-
712
-	// chaines de langue
713
-	// par defaut : objet:icone_xxx_objet
714
-	if (!isset($infos['texte_retour'])) {
715
-		$infos['texte_retour'] = 'icone_retour';
716
-	}
717
-	if (!isset($infos['texte_modifier'])) {
718
-		$infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type'];
719
-	}
720
-	if (!isset($infos['texte_creer'])) {
721
-		$infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type'];
722
-	}
723
-	if (!isset($infos['texte_creer_associer'])) {
724
-		$infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type'];
725
-	}
726
-	if (!isset($infos['texte_ajouter'])) {
727
-		// Ajouter un X
728
-		$infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type'];
729
-	}
730
-	if (!isset($infos['texte_objets'])) {
731
-		$infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet'];
732
-	}
733
-	if (!isset($infos['texte_objet'])) {
734
-		$infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type'];
735
-	}
736
-	if (!isset($infos['texte_logo_objet'])) {
737
-		// objet:titre_logo_objet "Logo de ce X"
738
-		$infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type'];
739
-	}
740
-	if (!isset($infos['texte_langue_objet'])) {
741
-		// objet:texte_langue_objet "Langue de ce X"
742
-		$infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type'];
743
-	}
744
-	if (!isset($infos['texte_definir_comme_traduction_objet'])) {
745
-		// "Ce X est une traduction du X numéro :"
746
-		$infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type'];
747
-	}
748
-
749
-	// objet:info_aucun_objet
750
-	if (!isset($infos['info_aucun_objet'])) {
751
-		$infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type'];
752
-	}
753
-	// objet:info_1_objet
754
-	if (!isset($infos['info_1_objet'])) {
755
-		$infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type'];
756
-	}
757
-	// objet:info_nb_objets
758
-	if (!isset($infos['info_nb_objets'])) {
759
-		$infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet'];
760
-	}
761
-
762
-	if (!isset($infos['champs_editables'])) {
763
-		$infos['champs_editables'] = [];
764
-	}
765
-	if (!isset($infos['champs_versionnes'])) {
766
-		$infos['champs_versionnes'] = [];
767
-	}
768
-	if (!isset($infos['rechercher_champs'])) {
769
-		$infos['rechercher_champs'] = [];
770
-	}
771
-	if (!isset($infos['rechercher_jointures'])) {
772
-		$infos['rechercher_jointures'] = [];
773
-	}
774
-
775
-	if (!isset($infos['modeles'])) {
776
-		$infos['modeles'] = [$infos['type']];
777
-	}
778
-
779
-	return $infos;
657
+    if (!isset($infos['type'])) {
658
+        // si on arrive de base/trouver_table, on a la cle primaire :
659
+        // s'en servir pour extrapoler le type
660
+        if (isset($infos['key']['PRIMARY KEY'])) {
661
+            $primary = $infos['key']['PRIMARY KEY'];
662
+            $primary = explode(',', (string) $primary);
663
+            $primary = reset($primary);
664
+            $infos['type'] = preg_replace(',^spip_|^id_|s$,', '', $primary);
665
+        } else {
666
+            $infos['type'] = preg_replace(',^spip_|s$,', '', $table_sql);
667
+        }
668
+    }
669
+    if (!isset($infos['type_surnoms'])) {
670
+        $infos['type_surnoms'] = [];
671
+    }
672
+
673
+    if (!isset($infos['table_objet'])) {
674
+        $infos['table_objet'] = preg_replace(',^spip_,', '', $table_sql);
675
+    }
676
+    if (!isset($infos['table_objet_surnoms'])) {
677
+        $infos['table_objet_surnoms'] = [];
678
+    }
679
+
680
+    if (!isset($infos['principale'])) {
681
+        $infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql]) ? 'oui' : false);
682
+    }
683
+
684
+    // normaliser pour pouvoir tester en php $infos['principale']?
685
+    // et dans une boucle {principale=oui}
686
+    $infos['principale'] = (($infos['principale'] && $infos['principale'] != 'non') ? 'oui' : false);
687
+
688
+    // declarer et normaliser pour pouvoir tester en php $infos['editable']?
689
+    // et dans une boucle {editable=oui}
690
+    if (!isset($infos['editable'])) {
691
+        $infos['editable'] = 'oui';
692
+    }
693
+
694
+    $infos['editable'] = (($infos['editable'] && $infos['editable'] != 'non') ? 'oui' : false);
695
+
696
+    // les urls publiques sont par defaut page=type pour les tables principales, et rien pour les autres
697
+    // seules les exceptions sont donc a declarer
698
+    if (!isset($infos['page'])) {
699
+        $infos['page'] = ($infos['principale'] ? $infos['type'] : '');
700
+    }
701
+
702
+    if (!isset($infos['url_voir'])) {
703
+        $infos['url_voir'] = $infos['type'];
704
+    }
705
+    if (!isset($infos['url_edit'])) {
706
+        $infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : '');
707
+    }
708
+    if (!isset($infos['icone_objet'])) {
709
+        $infos['icone_objet'] = $infos['type'];
710
+    }
711
+
712
+    // chaines de langue
713
+    // par defaut : objet:icone_xxx_objet
714
+    if (!isset($infos['texte_retour'])) {
715
+        $infos['texte_retour'] = 'icone_retour';
716
+    }
717
+    if (!isset($infos['texte_modifier'])) {
718
+        $infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type'];
719
+    }
720
+    if (!isset($infos['texte_creer'])) {
721
+        $infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type'];
722
+    }
723
+    if (!isset($infos['texte_creer_associer'])) {
724
+        $infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type'];
725
+    }
726
+    if (!isset($infos['texte_ajouter'])) {
727
+        // Ajouter un X
728
+        $infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type'];
729
+    }
730
+    if (!isset($infos['texte_objets'])) {
731
+        $infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet'];
732
+    }
733
+    if (!isset($infos['texte_objet'])) {
734
+        $infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type'];
735
+    }
736
+    if (!isset($infos['texte_logo_objet'])) {
737
+        // objet:titre_logo_objet "Logo de ce X"
738
+        $infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type'];
739
+    }
740
+    if (!isset($infos['texte_langue_objet'])) {
741
+        // objet:texte_langue_objet "Langue de ce X"
742
+        $infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type'];
743
+    }
744
+    if (!isset($infos['texte_definir_comme_traduction_objet'])) {
745
+        // "Ce X est une traduction du X numéro :"
746
+        $infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type'];
747
+    }
748
+
749
+    // objet:info_aucun_objet
750
+    if (!isset($infos['info_aucun_objet'])) {
751
+        $infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type'];
752
+    }
753
+    // objet:info_1_objet
754
+    if (!isset($infos['info_1_objet'])) {
755
+        $infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type'];
756
+    }
757
+    // objet:info_nb_objets
758
+    if (!isset($infos['info_nb_objets'])) {
759
+        $infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet'];
760
+    }
761
+
762
+    if (!isset($infos['champs_editables'])) {
763
+        $infos['champs_editables'] = [];
764
+    }
765
+    if (!isset($infos['champs_versionnes'])) {
766
+        $infos['champs_versionnes'] = [];
767
+    }
768
+    if (!isset($infos['rechercher_champs'])) {
769
+        $infos['rechercher_champs'] = [];
770
+    }
771
+    if (!isset($infos['rechercher_jointures'])) {
772
+        $infos['rechercher_jointures'] = [];
773
+    }
774
+
775
+    if (!isset($infos['modeles'])) {
776
+        $infos['modeles'] = [$infos['type']];
777
+    }
778
+
779
+    return $infos;
780 780
 }
781 781
 
782 782
 /**
@@ -793,30 +793,30 @@  discard block
 block discarded – undo
793 793
  * @return array
794 794
  */
795 795
 function renseigner_table_objet_interfaces($table_sql, &$infos) {
796
-	if (!isset($infos['titre'])) {
797
-		if (isset($infos['table_objet']) && isset($GLOBALS['table_titre'][$infos['table_objet']])) {
798
-			$infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']];
799
-		} else {
800
-			$infos['titre'] = ((isset($infos['field']['titre'])) ? 'titre,' : "'' as titre,");
801
-			$infos['titre'] .= ((isset($infos['field']['lang'])) ? 'lang' : "'' as lang");
802
-		}
803
-	}
804
-	if (!isset($infos['date'])) {
805
-		if (isset($infos['table_objet']) && isset($GLOBALS['table_date'][$infos['table_objet']])) {
806
-			$infos['date'] = $GLOBALS['table_date'][$infos['table_objet']];
807
-		} else {
808
-			$infos['date'] = ((isset($infos['field']['date'])) ? 'date' : '');
809
-		}
810
-	}
811
-
812
-	$infos['statut'] ??= $GLOBALS['table_statut'][$table_sql] ?? '';
813
-	$infos['tables_jointures'] ??= [];
814
-
815
-	if (isset($GLOBALS['tables_jointures'][$table_sql])) {
816
-		$infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]);
817
-	}
818
-
819
-	return $infos;
796
+    if (!isset($infos['titre'])) {
797
+        if (isset($infos['table_objet']) && isset($GLOBALS['table_titre'][$infos['table_objet']])) {
798
+            $infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']];
799
+        } else {
800
+            $infos['titre'] = ((isset($infos['field']['titre'])) ? 'titre,' : "'' as titre,");
801
+            $infos['titre'] .= ((isset($infos['field']['lang'])) ? 'lang' : "'' as lang");
802
+        }
803
+    }
804
+    if (!isset($infos['date'])) {
805
+        if (isset($infos['table_objet']) && isset($GLOBALS['table_date'][$infos['table_objet']])) {
806
+            $infos['date'] = $GLOBALS['table_date'][$infos['table_objet']];
807
+        } else {
808
+            $infos['date'] = ((isset($infos['field']['date'])) ? 'date' : '');
809
+        }
810
+    }
811
+
812
+    $infos['statut'] ??= $GLOBALS['table_statut'][$table_sql] ?? '';
813
+    $infos['tables_jointures'] ??= [];
814
+
815
+    if (isset($GLOBALS['tables_jointures'][$table_sql])) {
816
+        $infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]);
817
+    }
818
+
819
+    return $infos;
820 820
 }
821 821
 
822 822
 /**
@@ -827,13 +827,13 @@  discard block
 block discarded – undo
827 827
  *     Liste et descriptions des tables principales
828 828
  **/
829 829
 function lister_tables_principales() {
830
-	static $done = false;
831
-	if (!$done || !(is_countable($GLOBALS['tables_principales']) ? count($GLOBALS['tables_principales']) : 0)) {
832
-		lister_tables_objets_sql();
833
-		$done = true;
834
-	}
830
+    static $done = false;
831
+    if (!$done || !(is_countable($GLOBALS['tables_principales']) ? count($GLOBALS['tables_principales']) : 0)) {
832
+        lister_tables_objets_sql();
833
+        $done = true;
834
+    }
835 835
 
836
-	return $GLOBALS['tables_principales'];
836
+    return $GLOBALS['tables_principales'];
837 837
 }
838 838
 
839 839
 /**
@@ -844,13 +844,13 @@  discard block
 block discarded – undo
844 844
  *     Liste et descriptions des tables auxiliaires
845 845
  **/
846 846
 function lister_tables_auxiliaires() {
847
-	static $done = false;
848
-	if (!$done || !(is_countable($GLOBALS['tables_auxiliaires']) ? count($GLOBALS['tables_auxiliaires']) : 0)) {
849
-		lister_tables_objets_sql();
850
-		$done = true;
851
-	}
847
+    static $done = false;
848
+    if (!$done || !(is_countable($GLOBALS['tables_auxiliaires']) ? count($GLOBALS['tables_auxiliaires']) : 0)) {
849
+        lister_tables_objets_sql();
850
+        $done = true;
851
+    }
852 852
 
853
-	return $GLOBALS['tables_auxiliaires'];
853
+    return $GLOBALS['tables_auxiliaires'];
854 854
 }
855 855
 
856 856
 /**
@@ -859,44 +859,44 @@  discard block
 block discarded – undo
859 859
  * @return array
860 860
  */
861 861
 function lister_tables_objets_surnoms() {
862
-	static $surnoms = null;
863
-	static $md5 = null;
864
-	if (
865
-		!$surnoms || $md5 != lister_tables_objets_sql('::md5')
866
-	) {
867
-		// passer dans un pipeline qui permet aux plugins de declarer leurs exceptions
868
-		// pour compatibilite, car il faut dorenavent utiliser
869
-		// declarer_table_objets_sql
870
-		$surnoms = pipeline(
871
-			'declarer_tables_objets_surnoms',
872
-			[
873
-				# pour les modeles
874
-				# a enlever ?
875
-				'doc' => 'documents',
876
-				'img' => 'documents',
877
-				'emb' => 'documents',
878
-			]
879
-		);
880
-		$infos_tables = lister_tables_objets_sql();
881
-		foreach ($infos_tables as $t => $infos) {
882
-			// cas de base type=>table
883
-			// et preg_replace(',^spip_|^id_|s$,',table)=>table
884
-			if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide
885
-				// optimisations pour table_objet
886
-				//$surnoms[$infos['type']] = $infos['table_objet'];
887
-				$surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['table_objet'])] = $infos['table_objet'];
888
-				$surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['type'])] = $infos['table_objet'];
889
-				if (is_array($infos['table_objet_surnoms']) && count($infos['table_objet_surnoms'])) {
890
-					foreach ($infos['table_objet_surnoms'] as $surnom) {
891
-						$surnoms[$surnom] = $infos['table_objet'];
892
-					}
893
-				}
894
-			}
895
-		}
896
-		$md5 = lister_tables_objets_sql('::md5');
897
-	}
898
-
899
-	return $surnoms;
862
+    static $surnoms = null;
863
+    static $md5 = null;
864
+    if (
865
+        !$surnoms || $md5 != lister_tables_objets_sql('::md5')
866
+    ) {
867
+        // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions
868
+        // pour compatibilite, car il faut dorenavent utiliser
869
+        // declarer_table_objets_sql
870
+        $surnoms = pipeline(
871
+            'declarer_tables_objets_surnoms',
872
+            [
873
+                # pour les modeles
874
+                # a enlever ?
875
+                'doc' => 'documents',
876
+                'img' => 'documents',
877
+                'emb' => 'documents',
878
+            ]
879
+        );
880
+        $infos_tables = lister_tables_objets_sql();
881
+        foreach ($infos_tables as $t => $infos) {
882
+            // cas de base type=>table
883
+            // et preg_replace(',^spip_|^id_|s$,',table)=>table
884
+            if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide
885
+                // optimisations pour table_objet
886
+                //$surnoms[$infos['type']] = $infos['table_objet'];
887
+                $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['table_objet'])] = $infos['table_objet'];
888
+                $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['type'])] = $infos['table_objet'];
889
+                if (is_array($infos['table_objet_surnoms']) && count($infos['table_objet_surnoms'])) {
890
+                    foreach ($infos['table_objet_surnoms'] as $surnom) {
891
+                        $surnoms[$surnom] = $infos['table_objet'];
892
+                    }
893
+                }
894
+            }
895
+        }
896
+        $md5 = lister_tables_objets_sql('::md5');
897
+    }
898
+
899
+    return $surnoms;
900 900
 }
901 901
 
902 902
 /**
@@ -905,34 +905,34 @@  discard block
 block discarded – undo
905 905
  * @return array
906 906
  */
907 907
 function lister_types_surnoms() {
908
-	static $surnoms = null;
909
-	static $md5 = null;
910
-	if (
911
-		!$surnoms || $md5 != lister_tables_objets_sql('::md5')
912
-	) {
913
-		// passer dans un pipeline qui permet aux plugins de declarer leurs exceptions
914
-		// pour compatibilite, car il faut dorenavent utiliser
915
-		// declarer_table_objets_sql
916
-		$surnoms = pipeline('declarer_type_surnoms', ['racine-site' => 'site']);
917
-		$infos_tables = lister_tables_objets_sql();
918
-		foreach ($infos_tables as $t => $infos) {
919
-			if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide
920
-				// optimisations pour objet_type
921
-				//$surnoms[$infos['type']] = $infos['type'];
922
-				$surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['table_objet'])] = $infos['type'];
923
-				$surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['type'])] = $infos['type'];
924
-				// surnoms declares
925
-				if (is_array($infos['type_surnoms']) && count($infos['type_surnoms'])) {
926
-					foreach ($infos['type_surnoms'] as $surnom) {
927
-						$surnoms[$surnom] = $infos['type'];
928
-					}
929
-				}
930
-			}
931
-		}
932
-		$md5 = lister_tables_objets_sql('::md5');
933
-	}
934
-
935
-	return $surnoms;
908
+    static $surnoms = null;
909
+    static $md5 = null;
910
+    if (
911
+        !$surnoms || $md5 != lister_tables_objets_sql('::md5')
912
+    ) {
913
+        // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions
914
+        // pour compatibilite, car il faut dorenavent utiliser
915
+        // declarer_table_objets_sql
916
+        $surnoms = pipeline('declarer_type_surnoms', ['racine-site' => 'site']);
917
+        $infos_tables = lister_tables_objets_sql();
918
+        foreach ($infos_tables as $t => $infos) {
919
+            if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide
920
+                // optimisations pour objet_type
921
+                //$surnoms[$infos['type']] = $infos['type'];
922
+                $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['table_objet'])] = $infos['type'];
923
+                $surnoms[preg_replace(',^spip_|^id_|s$,', '', (string) $infos['type'])] = $infos['type'];
924
+                // surnoms declares
925
+                if (is_array($infos['type_surnoms']) && count($infos['type_surnoms'])) {
926
+                    foreach ($infos['type_surnoms'] as $surnom) {
927
+                        $surnoms[$surnom] = $infos['type'];
928
+                    }
929
+                }
930
+            }
931
+        }
932
+        $md5 = lister_tables_objets_sql('::md5');
933
+    }
934
+
935
+    return $surnoms;
936 936
 }
937 937
 
938 938
 /**
@@ -946,22 +946,22 @@  discard block
 block discarded – undo
946 946
  *     Couples (nom de la table SQL => même nom, sans 'spip_' devant)
947 947
  **/
948 948
 function lister_tables_spip($serveur = '') {
949
-	static $tables = [];
950
-	if (!isset($tables[$serveur])) {
951
-		$tables[$serveur] = [];
952
-		if (!function_exists('sql_alltable')) {
953
-			include_spip('base/abstract_sql');
954
-		}
955
-		$ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso)
956
-		$connexion = $GLOBALS['connexions'][$serveur ?: 0];
957
-		$spip = $connexion['prefixe'] . '_';
958
-		foreach ($ts as $t) {
959
-			$t = substr((string) $t, strlen($spip));
960
-			$tables[$serveur]["spip_$t"] = $t;
961
-		}
962
-	}
963
-
964
-	return $tables[$serveur];
949
+    static $tables = [];
950
+    if (!isset($tables[$serveur])) {
951
+        $tables[$serveur] = [];
952
+        if (!function_exists('sql_alltable')) {
953
+            include_spip('base/abstract_sql');
954
+        }
955
+        $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso)
956
+        $connexion = $GLOBALS['connexions'][$serveur ?: 0];
957
+        $spip = $connexion['prefixe'] . '_';
958
+        foreach ($ts as $t) {
959
+            $t = substr((string) $t, strlen($spip));
960
+            $tables[$serveur]["spip_$t"] = $t;
961
+        }
962
+    }
963
+
964
+    return $tables[$serveur];
965 965
 }
966 966
 
967 967
 
@@ -976,18 +976,18 @@  discard block
 block discarded – undo
976 976
  *     Couples (nom de la table SQL => même nom)
977 977
  **/
978 978
 function lister_toutes_tables($serveur) {
979
-	static $tables = [];
980
-	if (!isset($tables[$serveur])) {
981
-		$tables[$serveur] = [];
982
-		if (!function_exists('sql_alltable')) {
983
-			include_spip('base/abstract_sql');
984
-		}
985
-		$ts = sql_alltable('%', $serveur); // toutes les tables
986
-		foreach ($ts as $t) {
987
-			$tables[$serveur][$t] = $t;
988
-		}
989
-	}
990
-	return $tables[$serveur];
979
+    static $tables = [];
980
+    if (!isset($tables[$serveur])) {
981
+        $tables[$serveur] = [];
982
+        if (!function_exists('sql_alltable')) {
983
+            include_spip('base/abstract_sql');
984
+        }
985
+        $ts = sql_alltable('%', $serveur); // toutes les tables
986
+        foreach ($ts as $t) {
987
+            $tables[$serveur][$t] = $t;
988
+        }
989
+    }
990
+    return $tables[$serveur];
991 991
 }
992 992
 
993 993
 /**
@@ -1009,37 +1009,37 @@  discard block
 block discarded – undo
1009 1009
  **/
1010 1010
 function table_objet(string $type, string|false $serveur = ''): string {
1011 1011
 
1012
-	if ($type) {
1013
-		$type = preg_replace(',^spip_|^id_|s$,', '', $type);
1014
-	}
1015
-	if (!strlen($type)) {
1016
-		return '';
1017
-	}
1018
-
1019
-	$surnoms = lister_tables_objets_surnoms();
1020
-	if (isset($surnoms[$type])) {
1021
-		return $surnoms[$type];
1022
-	}
1023
-
1024
-	if ($serveur !== false) {
1025
-		$t = lister_tables_spip($serveur);
1026
-		$trouver_table = charger_fonction('trouver_table', 'base');
1027
-		$typetrim = rtrim($type, 's') . 's';
1028
-		if (
1029
-			(isset($t[$typetrim]) || in_array($typetrim, $t)) && ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur))
1030
-		) {
1031
-			return $desc['id_table'];
1032
-		} elseif (
1033
-			(isset($t[$type]) || in_array($type, $t)) && ($desc = $trouver_table($type, $serveur))
1034
-		) {
1035
-			return $desc['id_table'];
1036
-		}
1037
-
1038
-		spip_log('table_objet(' . $type . ') calculee sans verification');
1039
-		#spip_log(debug_backtrace(),'db');
1040
-	}
1041
-
1042
-	return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false
1012
+    if ($type) {
1013
+        $type = preg_replace(',^spip_|^id_|s$,', '', $type);
1014
+    }
1015
+    if (!strlen($type)) {
1016
+        return '';
1017
+    }
1018
+
1019
+    $surnoms = lister_tables_objets_surnoms();
1020
+    if (isset($surnoms[$type])) {
1021
+        return $surnoms[$type];
1022
+    }
1023
+
1024
+    if ($serveur !== false) {
1025
+        $t = lister_tables_spip($serveur);
1026
+        $trouver_table = charger_fonction('trouver_table', 'base');
1027
+        $typetrim = rtrim($type, 's') . 's';
1028
+        if (
1029
+            (isset($t[$typetrim]) || in_array($typetrim, $t)) && ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur))
1030
+        ) {
1031
+            return $desc['id_table'];
1032
+        } elseif (
1033
+            (isset($t[$type]) || in_array($type, $t)) && ($desc = $trouver_table($type, $serveur))
1034
+        ) {
1035
+            return $desc['id_table'];
1036
+        }
1037
+
1038
+        spip_log('table_objet(' . $type . ') calculee sans verification');
1039
+        #spip_log(debug_backtrace(),'db');
1040
+    }
1041
+
1042
+    return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false
1043 1043
 }
1044 1044
 
1045 1045
 /**
@@ -1060,33 +1060,33 @@  discard block
 block discarded – undo
1060 1060
  *     Nom de la table SQL
1061 1061
  **/
1062 1062
 function table_objet_sql(string $type, string|false $serveur = ''): string {
1063
-	$nom = table_objet($type, $serveur);
1064
-	if (!strlen($nom)) {
1065
-		return '';
1066
-	}
1067
-	if (!isset($GLOBALS['table_des_tables']['articles'])) {
1068
-		// eviter de multiples inclusions
1069
-		include_spip('public/interfaces');
1070
-	}
1071
-	if (isset($GLOBALS['table_des_tables'][$nom])) {
1072
-		$nom = $GLOBALS['table_des_tables'][$nom];
1073
-		$nom = "spip_$nom";
1074
-	} else {
1075
-		$infos_tables = lister_tables_objets_sql();
1076
-		if (isset($infos_tables["spip_$nom"])) {
1077
-			$nom = "spip_$nom";
1078
-		} elseif ($serveur !== false) {
1079
-			$t = lister_tables_spip($serveur);
1080
-			if (isset($t[$nom]) || in_array($nom, $t)) {
1081
-				$trouver_table = charger_fonction('trouver_table', 'base');
1082
-				if ($desc = $trouver_table($nom, $serveur)) {
1083
-					return $desc['table_sql'];
1084
-				}
1085
-			}
1086
-		}
1087
-	}
1088
-
1089
-	return $nom;
1063
+    $nom = table_objet($type, $serveur);
1064
+    if (!strlen($nom)) {
1065
+        return '';
1066
+    }
1067
+    if (!isset($GLOBALS['table_des_tables']['articles'])) {
1068
+        // eviter de multiples inclusions
1069
+        include_spip('public/interfaces');
1070
+    }
1071
+    if (isset($GLOBALS['table_des_tables'][$nom])) {
1072
+        $nom = $GLOBALS['table_des_tables'][$nom];
1073
+        $nom = "spip_$nom";
1074
+    } else {
1075
+        $infos_tables = lister_tables_objets_sql();
1076
+        if (isset($infos_tables["spip_$nom"])) {
1077
+            $nom = "spip_$nom";
1078
+        } elseif ($serveur !== false) {
1079
+            $t = lister_tables_spip($serveur);
1080
+            if (isset($t[$nom]) || in_array($nom, $t)) {
1081
+                $trouver_table = charger_fonction('trouver_table', 'base');
1082
+                if ($desc = $trouver_table($nom, $serveur)) {
1083
+                    return $desc['table_sql'];
1084
+                }
1085
+            }
1086
+        }
1087
+    }
1088
+
1089
+    return $nom;
1090 1090
 }
1091 1091
 
1092 1092
 /**
@@ -1105,34 +1105,34 @@  discard block
 block discarded – undo
1105 1105
  *     Nom de la clé primaire
1106 1106
  **/
1107 1107
 function id_table_objet(string $type, string $serveur = ''): ?string {
1108
-	static $trouver_table = null;
1109
-	$type = objet_type($type, $serveur);
1110
-	if (!$type) {
1111
-		return null;
1112
-	}
1113
-	$t = table_objet($type);
1114
-	if (!$trouver_table) {
1115
-		$trouver_table = charger_fonction('trouver_table', 'base');
1116
-	}
1117
-
1118
-	$ts = lister_tables_spip($serveur);
1119
-	if (
1120
-		in_array($t, $ts) || in_array($t, lister_toutes_tables($serveur))
1121
-	) {
1122
-		$desc = $trouver_table($t, $serveur);
1123
-		if (isset($desc['key']['PRIMARY KEY'])) {
1124
-			return $desc['key']['PRIMARY KEY'];
1125
-		}
1126
-		if (!$desc || isset($desc['field']["id_$type"])) {
1127
-			return "id_$type";
1128
-		}
1129
-		// sinon renvoyer le premier champ de la table...
1130
-		$keys = array_keys($desc['field']);
1131
-
1132
-		return array_shift($keys);
1133
-	}
1134
-
1135
-	return "id_$type";
1108
+    static $trouver_table = null;
1109
+    $type = objet_type($type, $serveur);
1110
+    if (!$type) {
1111
+        return null;
1112
+    }
1113
+    $t = table_objet($type);
1114
+    if (!$trouver_table) {
1115
+        $trouver_table = charger_fonction('trouver_table', 'base');
1116
+    }
1117
+
1118
+    $ts = lister_tables_spip($serveur);
1119
+    if (
1120
+        in_array($t, $ts) || in_array($t, lister_toutes_tables($serveur))
1121
+    ) {
1122
+        $desc = $trouver_table($t, $serveur);
1123
+        if (isset($desc['key']['PRIMARY KEY'])) {
1124
+            return $desc['key']['PRIMARY KEY'];
1125
+        }
1126
+        if (!$desc || isset($desc['field']["id_$type"])) {
1127
+            return "id_$type";
1128
+        }
1129
+        // sinon renvoyer le premier champ de la table...
1130
+        $keys = array_keys($desc['field']);
1131
+
1132
+        return array_shift($keys);
1133
+    }
1134
+
1135
+    return "id_$type";
1136 1136
 }
1137 1137
 
1138 1138
 /**
@@ -1152,60 +1152,60 @@  discard block
 block discarded – undo
1152 1152
  *     Type de l'objet
1153 1153
  **/
1154 1154
 function objet_type(string $table_objet, string|false $serveur = ''): ?string {
1155
-	if (!$table_objet) {
1156
-		return null;
1157
-	}
1158
-	$surnoms = lister_types_surnoms();
1159
-
1160
-	// scenario de base
1161
-	// le type est decline a partir du nom de la table en enlevant le prefixe eventuel
1162
-	// et la marque du pluriel
1163
-	// on accepte id_xx en entree aussi
1164
-	$type = preg_replace(',^spip_|^id_|s$,', '', $table_objet);
1165
-	if (isset($surnoms[$type])) {
1166
-		return $surnoms[$type];
1167
-	}
1168
-
1169
-	// securite : eliminer les caracteres non \w
1170
-	$type = preg_replace(',[^\w-],', '', $type);
1171
-
1172
-	// si le type redonne bien la table c'est bon
1173
-	// oui si table_objet ressemblait deja a un type
1174
-	if (
1175
-		$type == $table_objet
1176
-		|| table_objet($type, $serveur) === $table_objet
1177
-		|| table_objet_sql($type, $serveur) === $table_objet
1178
-	) {
1179
-		return $type;
1180
-	}
1181
-
1182
-	// si on ne veut pas chercher en base
1183
-	if ($serveur === false) {
1184
-		return $type;
1185
-	}
1186
-
1187
-	// sinon on passe par la cle primaire id_xx pour trouver le type
1188
-	// car le s a la fin est incertain
1189
-	// notamment en cas de pluriel derogatoire
1190
-	// id_jeu/spip_jeux id_journal/spip_journaux qui necessitent tout deux
1191
-	// une declaration jeu => jeux, journal => journaux
1192
-	// dans le pipeline declarer_tables_objets_surnoms
1193
-	$trouver_table = charger_fonction('trouver_table', 'base');
1194
-	$ts = lister_tables_spip($serveur);
1195
-	$desc = false;
1196
-	if (in_array($table_objet, $ts)) {
1197
-		$desc = $trouver_table($table_objet);
1198
-	}
1199
-	if (!$desc && in_array($table_objet = table_objet($type, $serveur), $ts)) {
1200
-		$desc = $trouver_table($table_objet, $serveur);
1201
-	}
1202
-	// si le type est declare : bingo !
1203
-	if ($desc && isset($desc['type'])) {
1204
-		return $desc['type'];
1205
-	}
1206
-
1207
-	// on a fait ce qu'on a pu
1208
-	return $type;
1155
+    if (!$table_objet) {
1156
+        return null;
1157
+    }
1158
+    $surnoms = lister_types_surnoms();
1159
+
1160
+    // scenario de base
1161
+    // le type est decline a partir du nom de la table en enlevant le prefixe eventuel
1162
+    // et la marque du pluriel
1163
+    // on accepte id_xx en entree aussi
1164
+    $type = preg_replace(',^spip_|^id_|s$,', '', $table_objet);
1165
+    if (isset($surnoms[$type])) {
1166
+        return $surnoms[$type];
1167
+    }
1168
+
1169
+    // securite : eliminer les caracteres non \w
1170
+    $type = preg_replace(',[^\w-],', '', $type);
1171
+
1172
+    // si le type redonne bien la table c'est bon
1173
+    // oui si table_objet ressemblait deja a un type
1174
+    if (
1175
+        $type == $table_objet
1176
+        || table_objet($type, $serveur) === $table_objet
1177
+        || table_objet_sql($type, $serveur) === $table_objet
1178
+    ) {
1179
+        return $type;
1180
+    }
1181
+
1182
+    // si on ne veut pas chercher en base
1183
+    if ($serveur === false) {
1184
+        return $type;
1185
+    }
1186
+
1187
+    // sinon on passe par la cle primaire id_xx pour trouver le type
1188
+    // car le s a la fin est incertain
1189
+    // notamment en cas de pluriel derogatoire
1190
+    // id_jeu/spip_jeux id_journal/spip_journaux qui necessitent tout deux
1191
+    // une declaration jeu => jeux, journal => journaux
1192
+    // dans le pipeline declarer_tables_objets_surnoms
1193
+    $trouver_table = charger_fonction('trouver_table', 'base');
1194
+    $ts = lister_tables_spip($serveur);
1195
+    $desc = false;
1196
+    if (in_array($table_objet, $ts)) {
1197
+        $desc = $trouver_table($table_objet);
1198
+    }
1199
+    if (!$desc && in_array($table_objet = table_objet($type, $serveur), $ts)) {
1200
+        $desc = $trouver_table($table_objet, $serveur);
1201
+    }
1202
+    // si le type est declare : bingo !
1203
+    if ($desc && isset($desc['type'])) {
1204
+        return $desc['type'];
1205
+    }
1206
+
1207
+    // on a fait ce qu'on a pu
1208
+    return $type;
1209 1209
 }
1210 1210
 
1211 1211
 /**
@@ -1221,58 +1221,58 @@  discard block
 block discarded – undo
1221 1221
  * @return bool
1222 1222
  */
1223 1223
 function objet_test_si_publie($objet, $id_objet, $serveur = '') {
1224
-	// voir si une fonction est definie pour faire le boulot
1225
-	// elle a la priorite dans ce cas
1226
-	if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) {
1227
-		return $f($objet, $id_objet, $serveur);
1228
-	}
1229
-
1230
-	// sinon on se fie a la declaration de l'objet si presente
1231
-	$id_table = $table_objet = table_objet($objet);
1232
-	$id_table_objet = id_table_objet($objet, $serveur);
1233
-	$trouver_table = charger_fonction('trouver_table', 'base');
1234
-	if (
1235
-		($desc = $trouver_table($table_objet, $serveur))
1236
-		&& isset($desc['statut'])
1237
-		&& $desc['statut']
1238
-	) {
1239
-		$boucle = new Boucle();
1240
-		$boucle->show = $desc;
1241
-		$boucle->nom = 'objet_test_si_publie';
1242
-		$boucle->id_boucle = $id_table;
1243
-		$boucle->id_table = $id_table;
1244
-		$boucle->primary = $desc['key']['PRIMARY KEY'] ?? '';
1245
-		$boucle->sql_serveur = $serveur;
1246
-		$boucle->select[] = $id_table_objet;
1247
-		$boucle->from[$table_objet] = table_objet_sql($objet, $serveur);
1248
-		$boucle->where[] = $id_table . '.' . $id_table_objet . '=' . (int) $id_objet;
1249
-
1250
-		$boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php
1251
-		$boucle->descr['sourcefile'] = 'internal';
1252
-		$boucle->descr['gram'] = 'html';
1253
-
1254
-		include_spip('public/compiler');
1255
-		include_spip('public/composer');
1256
-		instituer_boucle($boucle, false, true);
1257
-		$res = calculer_select(
1258
-			$boucle->select,
1259
-			$boucle->from,
1260
-			$boucle->from_type,
1261
-			$boucle->where,
1262
-			$boucle->join,
1263
-			$boucle->group,
1264
-			$boucle->order,
1265
-			$boucle->limit,
1266
-			$boucle->having,
1267
-			$table_objet,
1268
-			$id_table,
1269
-			$serveur
1270
-		);
1271
-		return (bool) sql_fetch($res);
1272
-	}
1273
-
1274
-	// si pas d'info statut ni de fonction : l'objet est publie
1275
-	return true;
1224
+    // voir si une fonction est definie pour faire le boulot
1225
+    // elle a la priorite dans ce cas
1226
+    if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) {
1227
+        return $f($objet, $id_objet, $serveur);
1228
+    }
1229
+
1230
+    // sinon on se fie a la declaration de l'objet si presente
1231
+    $id_table = $table_objet = table_objet($objet);
1232
+    $id_table_objet = id_table_objet($objet, $serveur);
1233
+    $trouver_table = charger_fonction('trouver_table', 'base');
1234
+    if (
1235
+        ($desc = $trouver_table($table_objet, $serveur))
1236
+        && isset($desc['statut'])
1237
+        && $desc['statut']
1238
+    ) {
1239
+        $boucle = new Boucle();
1240
+        $boucle->show = $desc;
1241
+        $boucle->nom = 'objet_test_si_publie';
1242
+        $boucle->id_boucle = $id_table;
1243
+        $boucle->id_table = $id_table;
1244
+        $boucle->primary = $desc['key']['PRIMARY KEY'] ?? '';
1245
+        $boucle->sql_serveur = $serveur;
1246
+        $boucle->select[] = $id_table_objet;
1247
+        $boucle->from[$table_objet] = table_objet_sql($objet, $serveur);
1248
+        $boucle->where[] = $id_table . '.' . $id_table_objet . '=' . (int) $id_objet;
1249
+
1250
+        $boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php
1251
+        $boucle->descr['sourcefile'] = 'internal';
1252
+        $boucle->descr['gram'] = 'html';
1253
+
1254
+        include_spip('public/compiler');
1255
+        include_spip('public/composer');
1256
+        instituer_boucle($boucle, false, true);
1257
+        $res = calculer_select(
1258
+            $boucle->select,
1259
+            $boucle->from,
1260
+            $boucle->from_type,
1261
+            $boucle->where,
1262
+            $boucle->join,
1263
+            $boucle->group,
1264
+            $boucle->order,
1265
+            $boucle->limit,
1266
+            $boucle->having,
1267
+            $table_objet,
1268
+            $id_table,
1269
+            $serveur
1270
+        );
1271
+        return (bool) sql_fetch($res);
1272
+    }
1273
+
1274
+    // si pas d'info statut ni de fonction : l'objet est publie
1275
+    return true;
1276 1276
 }
1277 1277
 
1278 1278
 
@@ -1307,124 +1307,124 @@  discard block
 block discarded – undo
1307 1307
  *     Retourne un tableau décrivant les parents trouvés
1308 1308
  */
1309 1309
 function objet_lister_parents($objet, $id_objet, $parent_direct_seulement = false) {
1310
-	$parents = [];
1311
-
1312
-	// Si on trouve une ou des méthodes de parent
1313
-	if ($parent_methodes = objet_type_decrire_infos_parents($objet)) {
1314
-		// On identifie les informations sur l'objet source dont on cherche le parent.
1315
-		include_spip('base/abstract_sql');
1316
-		$table_objet = table_objet_sql($objet);
1317
-		$cle_objet = id_table_objet($objet);
1318
-		$id_objet = (int) $id_objet;
1319
-
1320
-		// On teste chacun méthode dans l'ordre, et dès qu'on a trouvé un parent on s'arrête
1321
-		foreach ($parent_methodes as $parent_methode) {
1322
-			// Champ identifiant le parent (id et éventuellement le type)
1323
-			// -- cette identification ne dépend pas du fait que le parent soit stocké dans une table de différente
1324
-			//    de celle de l'objet source
1325
-			$select = [];
1326
-			if (isset($parent_methode['champ'])) {
1327
-				$select[] = $parent_methode['champ'];
1328
-			}
1329
-			if (isset($parent_methode['champ_type'])) {
1330
-				$select[] = $parent_methode['champ_type'];
1331
-			}
1332
-
1333
-			// Détermination de la table du parent et des conditions sur l'objet source et le parent.
1334
-			$condition_objet_invalide = false;
1335
-			$where = [];
1336
-			if (!isset($parent_methode['table'])) {
1337
-				// Le parent est stocké dans la même table que l'objet source :
1338
-				// -- toutes les conditions s'appliquent à la table source.
1339
-				$table = $table_objet;
1340
-				$where = ["$cle_objet = $id_objet"];
1341
-				// -- Condition supplémentaire sur la détection du parent
1342
-				if (isset($parent_methode['condition'])) {
1343
-					$where[] = $parent_methode['condition'];
1344
-				}
1345
-			} elseif (!$parent_direct_seulement) {
1346
-				// Le parent est stocké dans une table différente de l'objet source.
1347
-				// -- on vérifie d'emblée si il y a une condition sur l'objet source et si celle-ci est vérifiée
1348
-				//    Si non, on peut arrêter le traitement.
1349
-				if (isset($parent_methode['condition'])) {
1350
-					$where = [
1351
-						"$cle_objet = $id_objet",
1352
-						$parent_methode['condition']
1353
-					];
1354
-					if (!sql_countsel($table_objet, $where)) {
1355
-						$condition_objet_invalide = true;
1356
-					}
1357
-				}
1358
-
1359
-				// Si pas de condition sur l'objet source ou que la condition est vérifiée, on peut construire
1360
-				// la requête sur la table qui accueille le parent.
1361
-				if (!$condition_objet_invalide) {
1362
-					$table = $parent_methode['table'];
1363
-					// On construit les conditions en fonction de l'identification de l'objet source
1364
-					$where = [];
1365
-					// -- si le champ_source de l'id n'est pas précisé c'est qu'il est déjà connu et donc que c'est
1366
-					//    le même que celui de l'objet source.
1367
-					$where[] = isset($parent_methode['source_champ'])
1368
-						? "{$parent_methode['source_champ']} = $id_objet"
1369
-						: "$cle_objet = $id_objet";
1370
-					if (isset($parent_methode['source_champ_type'])) {
1371
-						$where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet);
1372
-					}
1373
-					// -- Condition supplémentaire sur la détection du parent
1374
-					if (isset($parent_methode['table_condition'])) {
1375
-						$where[] = $parent_methode['table_condition'];
1376
-					}
1377
-				}
1378
-			}
1379
-
1380
-			// On lance la requête de récupération du parent
1381
-			$is_table_lien = (str_contains((string) $table, '_liens') && str_ends_with((string) $table, '_liens'));
1382
-			if (
1383
-				!$condition_objet_invalide
1384
-				&& $where
1385
-				&& ($lignes = sql_allfetsel($is_table_lien ? '*' : $select, $table, $where))
1386
-			) {
1387
-				foreach ($lignes as $ligne) {
1388
-					// Si le type est fixe
1389
-					if (isset($parent_methode['type'])) {
1390
-						$parent = [
1391
-							'objet' 	=> $parent_methode['type'],
1392
-							'id_objet'	=> (int) $ligne[$parent_methode['champ']],
1393
-							'champ' 	=> $parent_methode['champ'],
1394
-							'table'    => $table,
1395
-						];
1396
-					}
1397
-					elseif (isset($parent_methode['champ_type'])) {
1398
-						$parent = [
1399
-							'objet' 	 => $ligne[$parent_methode['champ_type']],
1400
-							'id_objet' 	 => (int) $ligne[$parent_methode['champ']],
1401
-							'champ' 	 => $parent_methode['champ'],
1402
-							'champ_type' => $parent_methode['champ_type'],
1403
-							'table'    => $table,
1404
-						];
1405
-					}
1406
-					if ($is_table_lien) {
1407
-						$parent['lien'] = $ligne;
1408
-					}
1409
-					$parents[] = $parent;
1410
-				}
1411
-			}
1412
-		}
1413
-	}
1414
-
1415
-	// On passe par un pipeline avant de retourner
1416
-	$parents = pipeline(
1417
-		'objet_lister_parents',
1418
-		[
1419
-			'args' => [
1420
-				'objet' => $objet,
1421
-				'id_objet' => $id_objet,
1422
-			],
1423
-			'data' => $parents,
1424
-		]
1425
-	);
1426
-
1427
-	return $parents;
1310
+    $parents = [];
1311
+
1312
+    // Si on trouve une ou des méthodes de parent
1313
+    if ($parent_methodes = objet_type_decrire_infos_parents($objet)) {
1314
+        // On identifie les informations sur l'objet source dont on cherche le parent.
1315
+        include_spip('base/abstract_sql');
1316
+        $table_objet = table_objet_sql($objet);
1317
+        $cle_objet = id_table_objet($objet);
1318
+        $id_objet = (int) $id_objet;
1319
+
1320
+        // On teste chacun méthode dans l'ordre, et dès qu'on a trouvé un parent on s'arrête
1321
+        foreach ($parent_methodes as $parent_methode) {
1322
+            // Champ identifiant le parent (id et éventuellement le type)
1323
+            // -- cette identification ne dépend pas du fait que le parent soit stocké dans une table de différente
1324
+            //    de celle de l'objet source
1325
+            $select = [];
1326
+            if (isset($parent_methode['champ'])) {
1327
+                $select[] = $parent_methode['champ'];
1328
+            }
1329
+            if (isset($parent_methode['champ_type'])) {
1330
+                $select[] = $parent_methode['champ_type'];
1331
+            }
1332
+
1333
+            // Détermination de la table du parent et des conditions sur l'objet source et le parent.
1334
+            $condition_objet_invalide = false;
1335
+            $where = [];
1336
+            if (!isset($parent_methode['table'])) {
1337
+                // Le parent est stocké dans la même table que l'objet source :
1338
+                // -- toutes les conditions s'appliquent à la table source.
1339
+                $table = $table_objet;
1340
+                $where = ["$cle_objet = $id_objet"];
1341
+                // -- Condition supplémentaire sur la détection du parent
1342
+                if (isset($parent_methode['condition'])) {
1343
+                    $where[] = $parent_methode['condition'];
1344
+                }
1345
+            } elseif (!$parent_direct_seulement) {
1346
+                // Le parent est stocké dans une table différente de l'objet source.
1347
+                // -- on vérifie d'emblée si il y a une condition sur l'objet source et si celle-ci est vérifiée
1348
+                //    Si non, on peut arrêter le traitement.
1349
+                if (isset($parent_methode['condition'])) {
1350
+                    $where = [
1351
+                        "$cle_objet = $id_objet",
1352
+                        $parent_methode['condition']
1353
+                    ];
1354
+                    if (!sql_countsel($table_objet, $where)) {
1355
+                        $condition_objet_invalide = true;
1356
+                    }
1357
+                }
1358
+
1359
+                // Si pas de condition sur l'objet source ou que la condition est vérifiée, on peut construire
1360
+                // la requête sur la table qui accueille le parent.
1361
+                if (!$condition_objet_invalide) {
1362
+                    $table = $parent_methode['table'];
1363
+                    // On construit les conditions en fonction de l'identification de l'objet source
1364
+                    $where = [];
1365
+                    // -- si le champ_source de l'id n'est pas précisé c'est qu'il est déjà connu et donc que c'est
1366
+                    //    le même que celui de l'objet source.
1367
+                    $where[] = isset($parent_methode['source_champ'])
1368
+                        ? "{$parent_methode['source_champ']} = $id_objet"
1369
+                        : "$cle_objet = $id_objet";
1370
+                    if (isset($parent_methode['source_champ_type'])) {
1371
+                        $where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet);
1372
+                    }
1373
+                    // -- Condition supplémentaire sur la détection du parent
1374
+                    if (isset($parent_methode['table_condition'])) {
1375
+                        $where[] = $parent_methode['table_condition'];
1376
+                    }
1377
+                }
1378
+            }
1379
+
1380
+            // On lance la requête de récupération du parent
1381
+            $is_table_lien = (str_contains((string) $table, '_liens') && str_ends_with((string) $table, '_liens'));
1382
+            if (
1383
+                !$condition_objet_invalide
1384
+                && $where
1385
+                && ($lignes = sql_allfetsel($is_table_lien ? '*' : $select, $table, $where))
1386
+            ) {
1387
+                foreach ($lignes as $ligne) {
1388
+                    // Si le type est fixe
1389
+                    if (isset($parent_methode['type'])) {
1390
+                        $parent = [
1391
+                            'objet' 	=> $parent_methode['type'],
1392
+                            'id_objet'	=> (int) $ligne[$parent_methode['champ']],
1393
+                            'champ' 	=> $parent_methode['champ'],
1394
+                            'table'    => $table,
1395
+                        ];
1396
+                    }
1397
+                    elseif (isset($parent_methode['champ_type'])) {
1398
+                        $parent = [
1399
+                            'objet' 	 => $ligne[$parent_methode['champ_type']],
1400
+                            'id_objet' 	 => (int) $ligne[$parent_methode['champ']],
1401
+                            'champ' 	 => $parent_methode['champ'],
1402
+                            'champ_type' => $parent_methode['champ_type'],
1403
+                            'table'    => $table,
1404
+                        ];
1405
+                    }
1406
+                    if ($is_table_lien) {
1407
+                        $parent['lien'] = $ligne;
1408
+                    }
1409
+                    $parents[] = $parent;
1410
+                }
1411
+            }
1412
+        }
1413
+    }
1414
+
1415
+    // On passe par un pipeline avant de retourner
1416
+    $parents = pipeline(
1417
+        'objet_lister_parents',
1418
+        [
1419
+            'args' => [
1420
+                'objet' => $objet,
1421
+                'id_objet' => $id_objet,
1422
+            ],
1423
+            'data' => $parents,
1424
+        ]
1425
+    );
1426
+
1427
+    return $parents;
1428 1428
 }
1429 1429
 
1430 1430
 /**
@@ -1436,17 +1436,17 @@  discard block
 block discarded – undo
1436 1436
  * @return array
1437 1437
  */
1438 1438
 function objet_lister_parents_par_type($objet, $id_objet) {
1439
-	$parents = objet_lister_parents($objet, $id_objet);
1439
+    $parents = objet_lister_parents($objet, $id_objet);
1440 1440
 
1441
-	$parents_par_type = [];
1442
-	foreach ($parents as $parent) {
1443
-		if (!isset($parents_par_type[$parent['objet']])) {
1444
-			$parents_par_type[$parent['objet']] = [];
1445
-		}
1446
-		$parents_par_type[$parent['objet']][] = $parent['id_objet'];
1447
-	}
1441
+    $parents_par_type = [];
1442
+    foreach ($parents as $parent) {
1443
+        if (!isset($parents_par_type[$parent['objet']])) {
1444
+            $parents_par_type[$parent['objet']] = [];
1445
+        }
1446
+        $parents_par_type[$parent['objet']][] = $parent['id_objet'];
1447
+    }
1448 1448
 
1449
-	return $parents_par_type;
1449
+    return $parents_par_type;
1450 1450
 }
1451 1451
 
1452 1452
 
@@ -1479,85 +1479,85 @@  discard block
 block discarded – undo
1479 1479
  *     Retourne un tableau de tableaux, avec comme clés les types des objets, et dans chacun un tableau des identifiants trouvés
1480 1480
  */
1481 1481
 function objet_lister_enfants($objet, $id_objet) {
1482
-	$enfants = [];
1483
-
1484
-	// Si on trouve des types d'enfants et leurs méthodes
1485
-	if ($enfants_methodes = objet_type_decrire_infos_enfants($objet)) {
1486
-		include_spip('base/abstract_sql');
1487
-		$id_objet = (int) $id_objet;
1488
-
1489
-		// On parcourt tous les types d'enfants trouvés
1490
-		foreach ($enfants_methodes as $objet_enfant => $_methode_parent) {
1491
-			// On construit les conditions d'identification du parent
1492
-			$where = [];
1493
-			// -- L'identifiant du parent
1494
-			if (isset($_methode_parent['champ'])) {
1495
-				$where[] = $_methode_parent['champ'] . ' = ' . $id_objet;
1496
-			}
1497
-			// -- Si le parent est variable
1498
-			if (isset($_methode_parent['champ_type'])) {
1499
-				$where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet);
1500
-			}
1501
-
1502
-			// On détermine la table, le champ id des enfants et on complète éventuellement les conditions
1503
-			if (!isset($_methode_parent['table'])) {
1504
-				// Les enfants sont stockés dans la même table que l'objet parent :
1505
-				$table_enfant = table_objet_sql($objet_enfant);
1506
-				$cle_objet_enfant = id_table_objet($objet_enfant);
1507
-
1508
-				// S'il y a une condition supplémentaire
1509
-				if (isset($_methode_parent['condition'])) {
1510
-					$where[] = $_methode_parent['condition'];
1511
-				}
1512
-			} else {
1513
-				// Les enfants sont stockés dans une table différente de l'objet parent.
1514
-				$table_enfant = $_methode_parent['table'];
1515
-				$cle_objet_enfant = $_methode_parent['source_champ'] ?? id_table_objet($objet_enfant);
1516
-
1517
-				// S'il y a une condition supplémentaire
1518
-				if (isset($_methode_parent['table_condition'])) {
1519
-					$where[] = $_methode_parent['table_condition'];
1520
-				}
1521
-			}
1522
-
1523
-			// On lance la requête
1524
-			$is_table_lien = (str_contains((string) $table_enfant, '_liens') && str_ends_with((string) $table_enfant, '_liens'));
1525
-			if ($rows = sql_allfetsel($is_table_lien ? '*' : $cle_objet_enfant, $table_enfant, $where)) {
1526
-				$enfant = [
1527
-					'objet' => $objet_enfant,
1528
-					'id_objet' => 0,
1529
-					'table' => $table_enfant
1530
-				];
1531
-				if (isset($_methode_parent['champ'])) {
1532
-					$enfant['champ'] = $_methode_parent['champ'];
1533
-				}
1534
-				if (isset($_methode_parent['champ_type'])) {
1535
-					$enfant['champ_type'] = $_methode_parent['champ_type'];
1536
-				}
1537
-				foreach ($rows as $row) {
1538
-					$enfant['id_objet'] = (int) $row[$cle_objet_enfant];
1539
-					if ($is_table_lien) {
1540
-						$enfant['lien'] = $row;
1541
-					}
1542
-					$enfants[] = $enfant;
1543
-				}
1544
-			}
1545
-		}
1546
-	}
1547
-
1548
-	// On passe par un pipeline avant de retourner
1549
-	$enfants = pipeline(
1550
-		'objet_lister_enfants',
1551
-		[
1552
-			'args' => [
1553
-				'objet' => $objet,
1554
-				'id_objet' => $id_objet,
1555
-			],
1556
-			'data' => $enfants,
1557
-		]
1558
-	);
1559
-
1560
-	return $enfants;
1482
+    $enfants = [];
1483
+
1484
+    // Si on trouve des types d'enfants et leurs méthodes
1485
+    if ($enfants_methodes = objet_type_decrire_infos_enfants($objet)) {
1486
+        include_spip('base/abstract_sql');
1487
+        $id_objet = (int) $id_objet;
1488
+
1489
+        // On parcourt tous les types d'enfants trouvés
1490
+        foreach ($enfants_methodes as $objet_enfant => $_methode_parent) {
1491
+            // On construit les conditions d'identification du parent
1492
+            $where = [];
1493
+            // -- L'identifiant du parent
1494
+            if (isset($_methode_parent['champ'])) {
1495
+                $where[] = $_methode_parent['champ'] . ' = ' . $id_objet;
1496
+            }
1497
+            // -- Si le parent est variable
1498
+            if (isset($_methode_parent['champ_type'])) {
1499
+                $where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet);
1500
+            }
1501
+
1502
+            // On détermine la table, le champ id des enfants et on complète éventuellement les conditions
1503
+            if (!isset($_methode_parent['table'])) {
1504
+                // Les enfants sont stockés dans la même table que l'objet parent :
1505
+                $table_enfant = table_objet_sql($objet_enfant);
1506
+                $cle_objet_enfant = id_table_objet($objet_enfant);
1507
+
1508
+                // S'il y a une condition supplémentaire
1509
+                if (isset($_methode_parent['condition'])) {
1510
+                    $where[] = $_methode_parent['condition'];
1511
+                }
1512
+            } else {
1513
+                // Les enfants sont stockés dans une table différente de l'objet parent.
1514
+                $table_enfant = $_methode_parent['table'];
1515
+                $cle_objet_enfant = $_methode_parent['source_champ'] ?? id_table_objet($objet_enfant);
1516
+
1517
+                // S'il y a une condition supplémentaire
1518
+                if (isset($_methode_parent['table_condition'])) {
1519
+                    $where[] = $_methode_parent['table_condition'];
1520
+                }
1521
+            }
1522
+
1523
+            // On lance la requête
1524
+            $is_table_lien = (str_contains((string) $table_enfant, '_liens') && str_ends_with((string) $table_enfant, '_liens'));
1525
+            if ($rows = sql_allfetsel($is_table_lien ? '*' : $cle_objet_enfant, $table_enfant, $where)) {
1526
+                $enfant = [
1527
+                    'objet' => $objet_enfant,
1528
+                    'id_objet' => 0,
1529
+                    'table' => $table_enfant
1530
+                ];
1531
+                if (isset($_methode_parent['champ'])) {
1532
+                    $enfant['champ'] = $_methode_parent['champ'];
1533
+                }
1534
+                if (isset($_methode_parent['champ_type'])) {
1535
+                    $enfant['champ_type'] = $_methode_parent['champ_type'];
1536
+                }
1537
+                foreach ($rows as $row) {
1538
+                    $enfant['id_objet'] = (int) $row[$cle_objet_enfant];
1539
+                    if ($is_table_lien) {
1540
+                        $enfant['lien'] = $row;
1541
+                    }
1542
+                    $enfants[] = $enfant;
1543
+                }
1544
+            }
1545
+        }
1546
+    }
1547
+
1548
+    // On passe par un pipeline avant de retourner
1549
+    $enfants = pipeline(
1550
+        'objet_lister_enfants',
1551
+        [
1552
+            'args' => [
1553
+                'objet' => $objet,
1554
+                'id_objet' => $id_objet,
1555
+            ],
1556
+            'data' => $enfants,
1557
+        ]
1558
+    );
1559
+
1560
+    return $enfants;
1561 1561
 }
1562 1562
 
1563 1563
 /**
@@ -1569,17 +1569,17 @@  discard block
 block discarded – undo
1569 1569
  * @return array
1570 1570
  */
1571 1571
 function objet_lister_enfants_par_type($objet, $id_objet) {
1572
-	$enfants = objet_lister_enfants($objet, $id_objet);
1572
+    $enfants = objet_lister_enfants($objet, $id_objet);
1573 1573
 
1574
-	$enfants_par_type = [];
1575
-	foreach ($enfants as $enfant) {
1576
-		if (!isset($enfants_par_type[$enfant['objet']])) {
1577
-			$enfants_par_type[$enfant['objet']] = [];
1578
-		}
1579
-		$enfants_par_type[$enfant['objet']][] = $enfant['id_objet'];
1580
-	}
1574
+    $enfants_par_type = [];
1575
+    foreach ($enfants as $enfant) {
1576
+        if (!isset($enfants_par_type[$enfant['objet']])) {
1577
+            $enfants_par_type[$enfant['objet']] = [];
1578
+        }
1579
+        $enfants_par_type[$enfant['objet']][] = $enfant['id_objet'];
1580
+    }
1581 1581
 
1582
-	return $enfants_par_type;
1582
+    return $enfants_par_type;
1583 1583
 }
1584 1584
 
1585 1585
 /**
@@ -1591,31 +1591,31 @@  discard block
 block discarded – undo
1591 1591
  *     Retourne un tableau de tableau contenant les informations de type et de champ pour trouver le parent ou false sinon
1592 1592
  */
1593 1593
 function objet_type_decrire_infos_parents($objet) {
1594
-	static $parents = [];
1595
-
1596
-	// Si on ne l'a pas encore cherché pour cet objet
1597
-	if (!isset($parents[$objet])) {
1598
-		$parents[$objet] = false;
1599
-		$table = table_objet_sql($objet);
1600
-
1601
-		// Si on trouve bien la description de cet objet
1602
-		if ($infos = lister_tables_objets_sql($table)) {
1603
-			if (isset($infos['parent']) && is_array($infos['parent'])) {
1604
-				// S'il y a une description explicite de parent, c'est prioritaire
1605
-				// -- on traite les cas où il y a une ou plusieurs description mais on renvoie toujours un tableau
1606
-				//    de description
1607
-				$parents[$objet] = isset($infos['parent'][0]) ? $infos['parent'] : [$infos['parent']];
1608
-			} elseif (isset($infos['field']['id_rubrique'])) {
1609
-				// Sinon on cherche des cas courants connus magiquement, à commencer par id_rubrique
1610
-				$parents[$objet] = [['type' => 'rubrique', 'champ' => 'id_rubrique']];
1611
-			} elseif (isset($infos['field']['id_parent'])) {
1612
-				// Sinon on cherche un champ id_parent, ce qui signifie que l'objet est parent de lui-même
1613
-				$parents[$objet] = [['type' => $objet, 'champ' => 'id_parent']];
1614
-			}
1615
-		}
1616
-	}
1617
-
1618
-	return $parents[$objet];
1594
+    static $parents = [];
1595
+
1596
+    // Si on ne l'a pas encore cherché pour cet objet
1597
+    if (!isset($parents[$objet])) {
1598
+        $parents[$objet] = false;
1599
+        $table = table_objet_sql($objet);
1600
+
1601
+        // Si on trouve bien la description de cet objet
1602
+        if ($infos = lister_tables_objets_sql($table)) {
1603
+            if (isset($infos['parent']) && is_array($infos['parent'])) {
1604
+                // S'il y a une description explicite de parent, c'est prioritaire
1605
+                // -- on traite les cas où il y a une ou plusieurs description mais on renvoie toujours un tableau
1606
+                //    de description
1607
+                $parents[$objet] = isset($infos['parent'][0]) ? $infos['parent'] : [$infos['parent']];
1608
+            } elseif (isset($infos['field']['id_rubrique'])) {
1609
+                // Sinon on cherche des cas courants connus magiquement, à commencer par id_rubrique
1610
+                $parents[$objet] = [['type' => 'rubrique', 'champ' => 'id_rubrique']];
1611
+            } elseif (isset($infos['field']['id_parent'])) {
1612
+                // Sinon on cherche un champ id_parent, ce qui signifie que l'objet est parent de lui-même
1613
+                $parents[$objet] = [['type' => $objet, 'champ' => 'id_parent']];
1614
+            }
1615
+        }
1616
+    }
1617
+
1618
+    return $parents[$objet];
1619 1619
 }
1620 1620
 
1621 1621
 /**
@@ -1627,36 +1627,36 @@  discard block
 block discarded – undo
1627 1627
  *     Retourne un tableau de tableaux contenant chacun les informations d'un type d'enfant
1628 1628
  */
1629 1629
 function objet_type_decrire_infos_enfants($objet) {
1630
-	static $enfants = [];
1631
-
1632
-	// Si on a déjà fait la recherche pour ce type d'objet
1633
-	if (!isset($enfants[$objet])) {
1634
-		$enfants[$objet] = [];
1635
-		$tables = lister_tables_objets_sql();
1636
-
1637
-		// On parcourt toutes les tables d'objet, et on cherche si chacune peut être enfant
1638
-		foreach ($tables as $table => $infos) {
1639
-			$objet_enfant = objet_type($table);
1640
-
1641
-			// On ne va pas refaire les tests des différents cas, on réutilise
1642
-			if ($parent_methodes = objet_type_decrire_infos_parents($objet_enfant)) {
1643
-				// On parcourt les différents cas possible, si certains peuvent concerner l'objet demandé
1644
-				foreach ($parent_methodes as $parent_methode) {
1645
-					// Si la méthode qu'on teste n'exclut pas le parent demandé
1646
-					if (!isset($parent_methode['exclus']) || !in_array($objet, $parent_methode['exclus'])) {
1647
-						// Si le type du parent est fixe et directement l'objet demandé
1648
-						if (isset($parent_methode['type']) && isset($parent_methode['champ']) && $parent_methode['type'] == $objet) {
1649
-							$enfants[$objet][$objet_enfant] = $parent_methode;
1650
-						}
1651
-						// Si le type est variable, alors l'objet demandé peut forcément être parent
1652
-						elseif (isset($parent_methode['champ_type']) && isset($parent_methode['champ'])) {
1653
-							$enfants[$objet][$objet_enfant] = $parent_methode;
1654
-						}
1655
-					}
1656
-				}
1657
-			}
1658
-		}
1659
-	}
1660
-
1661
-	return $enfants[$objet];
1630
+    static $enfants = [];
1631
+
1632
+    // Si on a déjà fait la recherche pour ce type d'objet
1633
+    if (!isset($enfants[$objet])) {
1634
+        $enfants[$objet] = [];
1635
+        $tables = lister_tables_objets_sql();
1636
+
1637
+        // On parcourt toutes les tables d'objet, et on cherche si chacune peut être enfant
1638
+        foreach ($tables as $table => $infos) {
1639
+            $objet_enfant = objet_type($table);
1640
+
1641
+            // On ne va pas refaire les tests des différents cas, on réutilise
1642
+            if ($parent_methodes = objet_type_decrire_infos_parents($objet_enfant)) {
1643
+                // On parcourt les différents cas possible, si certains peuvent concerner l'objet demandé
1644
+                foreach ($parent_methodes as $parent_methode) {
1645
+                    // Si la méthode qu'on teste n'exclut pas le parent demandé
1646
+                    if (!isset($parent_methode['exclus']) || !in_array($objet, $parent_methode['exclus'])) {
1647
+                        // Si le type du parent est fixe et directement l'objet demandé
1648
+                        if (isset($parent_methode['type']) && isset($parent_methode['champ']) && $parent_methode['type'] == $objet) {
1649
+                            $enfants[$objet][$objet_enfant] = $parent_methode;
1650
+                        }
1651
+                        // Si le type est variable, alors l'objet demandé peut forcément être parent
1652
+                        elseif (isset($parent_methode['champ_type']) && isset($parent_methode['champ'])) {
1653
+                            $enfants[$objet][$objet_enfant] = $parent_methode;
1654
+                        }
1655
+                    }
1656
+                }
1657
+            }
1658
+        }
1659
+    }
1660
+
1661
+    return $enfants[$objet];
1662 1662
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 		$infos['url_voir'] = $infos['type'];
704 704
 	}
705 705
 	if (!isset($infos['url_edit'])) {
706
-		$infos['url_edit'] = $infos['url_voir'] . ($infos['editable'] ? '_edit' : '');
706
+		$infos['url_edit'] = $infos['url_voir'].($infos['editable'] ? '_edit' : '');
707 707
 	}
708 708
 	if (!isset($infos['icone_objet'])) {
709 709
 		$infos['icone_objet'] = $infos['type'];
@@ -715,48 +715,48 @@  discard block
 block discarded – undo
715 715
 		$infos['texte_retour'] = 'icone_retour';
716 716
 	}
717 717
 	if (!isset($infos['texte_modifier'])) {
718
-		$infos['texte_modifier'] = $infos['type'] . ':' . 'icone_modifier_' . $infos['type'];
718
+		$infos['texte_modifier'] = $infos['type'].':'.'icone_modifier_'.$infos['type'];
719 719
 	}
720 720
 	if (!isset($infos['texte_creer'])) {
721
-		$infos['texte_creer'] = $infos['type'] . ':' . 'icone_creer_' . $infos['type'];
721
+		$infos['texte_creer'] = $infos['type'].':'.'icone_creer_'.$infos['type'];
722 722
 	}
723 723
 	if (!isset($infos['texte_creer_associer'])) {
724
-		$infos['texte_creer_associer'] = $infos['type'] . ':' . 'texte_creer_associer_' . $infos['type'];
724
+		$infos['texte_creer_associer'] = $infos['type'].':'.'texte_creer_associer_'.$infos['type'];
725 725
 	}
726 726
 	if (!isset($infos['texte_ajouter'])) {
727 727
 		// Ajouter un X
728
-		$infos['texte_ajouter'] = $infos['type'] . ':' . 'texte_ajouter_' . $infos['type'];
728
+		$infos['texte_ajouter'] = $infos['type'].':'.'texte_ajouter_'.$infos['type'];
729 729
 	}
730 730
 	if (!isset($infos['texte_objets'])) {
731
-		$infos['texte_objets'] = $infos['type'] . ':' . 'titre_' . $infos['table_objet'];
731
+		$infos['texte_objets'] = $infos['type'].':'.'titre_'.$infos['table_objet'];
732 732
 	}
733 733
 	if (!isset($infos['texte_objet'])) {
734
-		$infos['texte_objet'] = $infos['type'] . ':' . 'titre_' . $infos['type'];
734
+		$infos['texte_objet'] = $infos['type'].':'.'titre_'.$infos['type'];
735 735
 	}
736 736
 	if (!isset($infos['texte_logo_objet'])) {
737 737
 		// objet:titre_logo_objet "Logo de ce X"
738
-		$infos['texte_logo_objet'] = $infos['type'] . ':' . 'titre_logo_' . $infos['type'];
738
+		$infos['texte_logo_objet'] = $infos['type'].':'.'titre_logo_'.$infos['type'];
739 739
 	}
740 740
 	if (!isset($infos['texte_langue_objet'])) {
741 741
 		// objet:texte_langue_objet "Langue de ce X"
742
-		$infos['texte_langue_objet'] = $infos['type'] . ':' . 'titre_langue_' . $infos['type'];
742
+		$infos['texte_langue_objet'] = $infos['type'].':'.'titre_langue_'.$infos['type'];
743 743
 	}
744 744
 	if (!isset($infos['texte_definir_comme_traduction_objet'])) {
745 745
 		// "Ce X est une traduction du X numéro :"
746
-		$infos['texte_definir_comme_traduction_objet'] = $infos['type'] . ':' . 'texte_definir_comme_traduction_' . $infos['type'];
746
+		$infos['texte_definir_comme_traduction_objet'] = $infos['type'].':'.'texte_definir_comme_traduction_'.$infos['type'];
747 747
 	}
748 748
 
749 749
 	// objet:info_aucun_objet
750 750
 	if (!isset($infos['info_aucun_objet'])) {
751
-		$infos['info_aucun_objet'] = $infos['type'] . ':' . 'info_aucun_' . $infos['type'];
751
+		$infos['info_aucun_objet'] = $infos['type'].':'.'info_aucun_'.$infos['type'];
752 752
 	}
753 753
 	// objet:info_1_objet
754 754
 	if (!isset($infos['info_1_objet'])) {
755
-		$infos['info_1_objet'] = $infos['type'] . ':' . 'info_1_' . $infos['type'];
755
+		$infos['info_1_objet'] = $infos['type'].':'.'info_1_'.$infos['type'];
756 756
 	}
757 757
 	// objet:info_nb_objets
758 758
 	if (!isset($infos['info_nb_objets'])) {
759
-		$infos['info_nb_objets'] = $infos['type'] . ':' . 'info_nb_' . $infos['table_objet'];
759
+		$infos['info_nb_objets'] = $infos['type'].':'.'info_nb_'.$infos['table_objet'];
760 760
 	}
761 761
 
762 762
 	if (!isset($infos['champs_editables'])) {
@@ -954,7 +954,7 @@  discard block
 block discarded – undo
954 954
 		}
955 955
 		$ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso)
956 956
 		$connexion = $GLOBALS['connexions'][$serveur ?: 0];
957
-		$spip = $connexion['prefixe'] . '_';
957
+		$spip = $connexion['prefixe'].'_';
958 958
 		foreach ($ts as $t) {
959 959
 			$t = substr((string) $t, strlen($spip));
960 960
 			$tables[$serveur]["spip_$t"] = $t;
@@ -1007,7 +1007,7 @@  discard block
 block discarded – undo
1007 1007
  * @return string
1008 1008
  *     Nom de l'objet
1009 1009
  **/
1010
-function table_objet(string $type, string|false $serveur = ''): string {
1010
+function table_objet(string $type, string | false $serveur = ''): string {
1011 1011
 
1012 1012
 	if ($type) {
1013 1013
 		$type = preg_replace(',^spip_|^id_|s$,', '', $type);
@@ -1024,9 +1024,9 @@  discard block
 block discarded – undo
1024 1024
 	if ($serveur !== false) {
1025 1025
 		$t = lister_tables_spip($serveur);
1026 1026
 		$trouver_table = charger_fonction('trouver_table', 'base');
1027
-		$typetrim = rtrim($type, 's') . 's';
1027
+		$typetrim = rtrim($type, 's').'s';
1028 1028
 		if (
1029
-			(isset($t[$typetrim]) || in_array($typetrim, $t)) && ($desc = $trouver_table(rtrim($type, 's') . 's', $serveur))
1029
+			(isset($t[$typetrim]) || in_array($typetrim, $t)) && ($desc = $trouver_table(rtrim($type, 's').'s', $serveur))
1030 1030
 		) {
1031 1031
 			return $desc['id_table'];
1032 1032
 		} elseif (
@@ -1035,11 +1035,11 @@  discard block
 block discarded – undo
1035 1035
 			return $desc['id_table'];
1036 1036
 		}
1037 1037
 
1038
-		spip_log('table_objet(' . $type . ') calculee sans verification');
1038
+		spip_log('table_objet('.$type.') calculee sans verification');
1039 1039
 		#spip_log(debug_backtrace(),'db');
1040 1040
 	}
1041 1041
 
1042
-	return rtrim($type, 's') . 's'; # cas historique ne devant plus servir, sauf si $serveur=false
1042
+	return rtrim($type, 's').'s'; # cas historique ne devant plus servir, sauf si $serveur=false
1043 1043
 }
1044 1044
 
1045 1045
 /**
@@ -1059,7 +1059,7 @@  discard block
 block discarded – undo
1059 1059
  * @return string
1060 1060
  *     Nom de la table SQL
1061 1061
  **/
1062
-function table_objet_sql(string $type, string|false $serveur = ''): string {
1062
+function table_objet_sql(string $type, string | false $serveur = ''): string {
1063 1063
 	$nom = table_objet($type, $serveur);
1064 1064
 	if (!strlen($nom)) {
1065 1065
 		return '';
@@ -1151,7 +1151,7 @@  discard block
 block discarded – undo
1151 1151
  * @return string|null
1152 1152
  *     Type de l'objet
1153 1153
  **/
1154
-function objet_type(string $table_objet, string|false $serveur = ''): ?string {
1154
+function objet_type(string $table_objet, string | false $serveur = ''): ?string {
1155 1155
 	if (!$table_objet) {
1156 1156
 		return null;
1157 1157
 	}
@@ -1223,7 +1223,7 @@  discard block
 block discarded – undo
1223 1223
 function objet_test_si_publie($objet, $id_objet, $serveur = '') {
1224 1224
 	// voir si une fonction est definie pour faire le boulot
1225 1225
 	// elle a la priorite dans ce cas
1226
-	if ($f = charger_fonction($objet . '_test_si_publie', 'base', true)) {
1226
+	if ($f = charger_fonction($objet.'_test_si_publie', 'base', true)) {
1227 1227
 		return $f($objet, $id_objet, $serveur);
1228 1228
 	}
1229 1229
 
@@ -1245,7 +1245,7 @@  discard block
 block discarded – undo
1245 1245
 		$boucle->sql_serveur = $serveur;
1246 1246
 		$boucle->select[] = $id_table_objet;
1247 1247
 		$boucle->from[$table_objet] = table_objet_sql($objet, $serveur);
1248
-		$boucle->where[] = $id_table . '.' . $id_table_objet . '=' . (int) $id_objet;
1248
+		$boucle->where[] = $id_table.'.'.$id_table_objet.'='.(int) $id_objet;
1249 1249
 
1250 1250
 		$boucle->descr['nom'] = 'objet_test_si_publie'; // eviter notice php
1251 1251
 		$boucle->descr['sourcefile'] = 'internal';
@@ -1368,7 +1368,7 @@  discard block
 block discarded – undo
1368 1368
 						? "{$parent_methode['source_champ']} = $id_objet"
1369 1369
 						: "$cle_objet = $id_objet";
1370 1370
 					if (isset($parent_methode['source_champ_type'])) {
1371
-						$where[] = "{$parent_methode['source_champ_type']} = " . sql_quote($objet);
1371
+						$where[] = "{$parent_methode['source_champ_type']} = ".sql_quote($objet);
1372 1372
 					}
1373 1373
 					// -- Condition supplémentaire sur la détection du parent
1374 1374
 					if (isset($parent_methode['table_condition'])) {
@@ -1492,11 +1492,11 @@  discard block
 block discarded – undo
1492 1492
 			$where = [];
1493 1493
 			// -- L'identifiant du parent
1494 1494
 			if (isset($_methode_parent['champ'])) {
1495
-				$where[] = $_methode_parent['champ'] . ' = ' . $id_objet;
1495
+				$where[] = $_methode_parent['champ'].' = '.$id_objet;
1496 1496
 			}
1497 1497
 			// -- Si le parent est variable
1498 1498
 			if (isset($_methode_parent['champ_type'])) {
1499
-				$where[] = $_methode_parent['champ_type'] . ' = ' . sql_quote($objet);
1499
+				$where[] = $_methode_parent['champ_type'].' = '.sql_quote($objet);
1500 1500
 			}
1501 1501
 
1502 1502
 			// On détermine la table, le champ id des enfants et on complète éventuellement les conditions
Please login to merge, or discard this patch.