Completed
Push — master ( a5da4e...51674a )
by cam
01:27
created
ecrire/base/connect_sql.php 3 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -87,8 +87,7 @@  discard block
 block discarded – undo
87 87
 			if (!isset($GLOBALS['db_ok'])) {
88 88
 				spip_log("spip_connect: fichier de connexion '$f' OK mais echec connexion au serveur", _LOG_HS);
89 89
 			}
90
-		}
91
-		else {
90
+		} else {
92 91
 			spip_log("spip_connect: fichier de connexion '$f' non trouve, pas de connexion serveur", _LOG_HS);
93 92
 		}
94 93
 		if (!isset($GLOBALS['db_ok'])) {
@@ -453,8 +452,7 @@  discard block
 block discarded – undo
453 452
 					&& strpos($query_echappees, $part . $next, $currentpos) === $nextpos
454 453
 				) {
455 454
 					$part .= array_shift($textes);
456
-				}
457
-				else {
455
+				} else {
458 456
 					break;
459 457
 				}
460 458
 			}
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18 18
 	return;
19 19
 }
20
-require_once _ROOT_RESTREINT . 'base/objets.php';
20
+require_once _ROOT_RESTREINT.'base/objets.php';
21 21
 
22 22
 
23 23
 /**
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 				defined('_DIR_CONNECT')
63 63
 				&& preg_match('/^[\w\.]*$/', $serveur)
64 64
 			) {
65
-				$f = _DIR_CONNECT . $serveur . '.php';
65
+				$f = _DIR_CONNECT.$serveur.'.php';
66 66
 				if (!is_readable($f) && !$install) {
67 67
 					// chercher une declaration de serveur dans le path
68 68
 					// qui peut servir à des plugins à declarer des connexions à une base sqlite
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
 	// chargement de la version du jeu de fonctions
111 111
 	// si pas dans le fichier par defaut
112 112
 	$type = $GLOBALS['db_ok']['type'];
113
-	$jeu = 'spip_' . $type . '_functions_' . $version;
114
-	if (!isset($GLOBALS[$jeu]) && !find_in_path($type . '_' . $version . '.php', 'req/', true)) {
113
+	$jeu = 'spip_'.$type.'_functions_'.$version;
114
+	if (!isset($GLOBALS[$jeu]) && !find_in_path($type.'_'.$version.'.php', 'req/', true)) {
115 115
 		spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS);
116 116
 		// ne plus reessayer
117 117
 		return $GLOBALS['connexions'][$index][$version] = [];
@@ -171,9 +171,9 @@  discard block
 block discarded – undo
171 171
 	$connexion = spip_connect($serveur);
172 172
 	$e = sql_errno($serveur);
173 173
 	$t = ($connexion['type'] ?? 'sql');
174
-	$m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim((string) $connexion['last']);
175
-	$f = $t . $serveur;
176
-	spip_log($m, $f . '.' . _LOG_ERREUR);
174
+	$m = "Erreur $e de $t: ".sql_error($serveur)."\nin ".sql_error_backtrace()."\n".trim((string) $connexion['last']);
175
+	$f = $t.$serveur;
176
+	spip_log($m, $f.'.'._LOG_ERREUR);
177 177
 }
178 178
 
179 179
 /**
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	// si en cours d'installation ou si db=@test@ on ne pose rien
260 260
 	// car c'est un test de connexion
261 261
 	if (!defined('_ECRIRE_INSTALL') && $db !== '@test@') {
262
-		$f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out';
262
+		$f = _DIR_TMP.$type.'.'.substr(md5($host.$port.$db), 0, 8).'.out';
263 263
 	} elseif ($db == '@test@') {
264 264
 		$db = '';
265 265
 	}
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 	// En cas d'indisponibilite du serveur, eviter de le bombarder
299 299
 	if ($f) {
300 300
 		@touch($f);
301
-		spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS);
301
+		spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type.'.'._LOG_HS);
302 302
 	}
303 303
 	return null;
304 304
 }
@@ -395,11 +395,11 @@  discard block
 block discarded – undo
395 395
 	} elseif (is_array($a)) {
396 396
 		return implode(',', array_map('_q', $a));
397 397
 	} elseif (is_scalar($a)) {
398
-		return ("'" . addslashes($a) . "'");
398
+		return ("'".addslashes($a)."'");
399 399
 	} elseif ($a === null) {
400 400
 		return "''";
401 401
 	}
402
-	throw new \RuntimeException('Can’t use _q with ' . gettype($a));
402
+	throw new \RuntimeException('Can’t use _q with '.gettype($a));
403 403
 }
404 404
 
405 405
 /**
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
 				$next = reset($textes);
451 451
 				if (
452 452
 					str_starts_with((string) $next, "'")
453
-					&& strpos($query_echappees, $part . $next, $currentpos) === $nextpos
453
+					&& strpos($query_echappees, $part.$next, $currentpos) === $nextpos
454 454
 				) {
455 455
 					$part .= array_shift($textes);
456 456
 				}
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 			$parts[$k] = [
463 463
 				'texte' => $part,
464 464
 				'position' => $nextpos,
465
-				'placeholder' => '%' . $k . '$s',
465
+				'placeholder' => '%'.$k.'$s',
466 466
 			];
467 467
 			$currentpos = $nextpos + strlen((string) $part);
468 468
 		}
Please login to merge, or discard this patch.
Indentation   +319 added lines, -319 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\SQL
16 16
  **/
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 require_once _ROOT_RESTREINT . 'base/objets.php';
21 21
 
@@ -41,125 +41,125 @@  discard block
 block discarded – undo
41 41
  **/
42 42
 function spip_connect($serveur = '', $version = '') {
43 43
 
44
-	$serveur = is_string($serveur) ? strtolower($serveur) : '';
45
-	$index = $serveur ?: 0;
46
-	if (!$version) {
47
-		$version = $GLOBALS['spip_sql_version'];
48
-	}
49
-	if (isset($GLOBALS['connexions'][$index][$version])) {
50
-		return $GLOBALS['connexions'][$index];
51
-	}
52
-
53
-	include_spip('base/abstract_sql');
54
-	$install = (_request('exec') == 'install');
55
-
56
-	// Premiere connexion ?
57
-	if (!($old = isset($GLOBALS['connexions'][$index]))) {
58
-		$f = '';
59
-		if ($serveur) {
60
-			// serveur externe et nom de serveur bien ecrit ?
61
-			if (
62
-				defined('_DIR_CONNECT')
63
-				&& preg_match('/^[\w\.]*$/', $serveur)
64
-			) {
65
-				$f = _DIR_CONNECT . $serveur . '.php';
66
-				if (!is_readable($f) && !$install) {
67
-					// chercher une declaration de serveur dans le path
68
-					// qui peut servir à des plugins à declarer des connexions à une base sqlite
69
-					// Ex: sert aux boucles POUR et au plugin-dist dump pour se connecter sur le sqlite du dump
70
-					$f = find_in_path("$serveur.php", 'connect/');
71
-				}
72
-			}
73
-		} else {
74
-			if (defined('_FILE_CONNECT') && _FILE_CONNECT) {
75
-				// init du serveur principal
76
-				$f = _FILE_CONNECT;
77
-			} elseif ($install && defined('_FILE_CONNECT_TMP')) {
78
-				// installation en cours
79
-				$f = _FILE_CONNECT_TMP;
80
-			}
81
-		}
82
-
83
-		unset($GLOBALS['db_ok']);
84
-		unset($GLOBALS['spip_connect_version']);
85
-		if ($f && is_readable($f)) {
86
-			include($f);
87
-			if (!isset($GLOBALS['db_ok'])) {
88
-				spip_log("spip_connect: fichier de connexion '$f' OK mais echec connexion au serveur", _LOG_HS);
89
-			}
90
-		}
91
-		else {
92
-			spip_log("spip_connect: fichier de connexion '$f' non trouve, pas de connexion serveur", _LOG_HS);
93
-		}
94
-		if (!isset($GLOBALS['db_ok'])) {
95
-			// fera mieux la prochaine fois
96
-			if ($install) {
97
-				return false;
98
-			}
99
-			// ne plus reessayer si ce n'est pas l'install
100
-			return $GLOBALS['connexions'][$index] = false;
101
-		}
102
-		$GLOBALS['connexions'][$index] = $GLOBALS['db_ok'];
103
-	}
104
-	// si la connexion a deja ete tentee mais a echoue, le dire!
105
-	if (!$GLOBALS['connexions'][$index]) {
106
-		return false;
107
-	}
108
-
109
-	// la connexion a reussi ou etait deja faite.
110
-	// chargement de la version du jeu de fonctions
111
-	// si pas dans le fichier par defaut
112
-	$type = $GLOBALS['db_ok']['type'];
113
-	$jeu = 'spip_' . $type . '_functions_' . $version;
114
-	if (!isset($GLOBALS[$jeu]) && !find_in_path($type . '_' . $version . '.php', 'req/', true)) {
115
-		spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS);
116
-		// ne plus reessayer
117
-		return $GLOBALS['connexions'][$index][$version] = [];
118
-	}
119
-	$GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu];
120
-	if ($old) {
121
-		return $GLOBALS['connexions'][$index];
122
-	}
123
-
124
-	$GLOBALS['connexions'][$index]['spip_connect_version'] = $GLOBALS['spip_connect_version'] ?? 0;
125
-
126
-	// initialisation de l'alphabet utilise dans les connexions SQL
127
-	// si l'installation l'a determine.
128
-	// Celui du serveur principal l'impose aux serveurs secondaires
129
-	// s'ils le connaissent
130
-
131
-	if (!$serveur) {
132
-		$charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']);
133
-		if (!$charset) {
134
-			unset($GLOBALS['connexions'][$index]);
135
-			spip_log('spip_connect: absence de charset', _LOG_AVERTISSEMENT);
136
-
137
-			return false;
138
-		}
139
-	} else {
140
-		if ($GLOBALS['db_ok']['charset']) {
141
-			$charset = $GLOBALS['db_ok']['charset'];
142
-		}
143
-		// spip_meta n'existe pas toujours dans la base
144
-		// C'est le cas d'un dump sqlite par exemple
145
-		elseif (
146
-			$GLOBALS['connexions'][$index]['spip_connect_version']
147
-			&& sql_showtable('spip_meta', true, $serveur)
148
-			&& ($r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur))
149
-		) {
150
-			$charset = $r;
151
-		} else {
152
-			$charset = -1;
153
-		}
154
-	}
155
-	if ($charset != -1) {
156
-		$f = $GLOBALS[$jeu]['set_charset'];
157
-		if (function_exists($f)) {
158
-			$f($charset, $serveur);
159
-		}
160
-	}
161
-
162
-	return $GLOBALS['connexions'][$index];
44
+    $serveur = is_string($serveur) ? strtolower($serveur) : '';
45
+    $index = $serveur ?: 0;
46
+    if (!$version) {
47
+        $version = $GLOBALS['spip_sql_version'];
48
+    }
49
+    if (isset($GLOBALS['connexions'][$index][$version])) {
50
+        return $GLOBALS['connexions'][$index];
51
+    }
52
+
53
+    include_spip('base/abstract_sql');
54
+    $install = (_request('exec') == 'install');
55
+
56
+    // Premiere connexion ?
57
+    if (!($old = isset($GLOBALS['connexions'][$index]))) {
58
+        $f = '';
59
+        if ($serveur) {
60
+            // serveur externe et nom de serveur bien ecrit ?
61
+            if (
62
+                defined('_DIR_CONNECT')
63
+                && preg_match('/^[\w\.]*$/', $serveur)
64
+            ) {
65
+                $f = _DIR_CONNECT . $serveur . '.php';
66
+                if (!is_readable($f) && !$install) {
67
+                    // chercher une declaration de serveur dans le path
68
+                    // qui peut servir à des plugins à declarer des connexions à une base sqlite
69
+                    // Ex: sert aux boucles POUR et au plugin-dist dump pour se connecter sur le sqlite du dump
70
+                    $f = find_in_path("$serveur.php", 'connect/');
71
+                }
72
+            }
73
+        } else {
74
+            if (defined('_FILE_CONNECT') && _FILE_CONNECT) {
75
+                // init du serveur principal
76
+                $f = _FILE_CONNECT;
77
+            } elseif ($install && defined('_FILE_CONNECT_TMP')) {
78
+                // installation en cours
79
+                $f = _FILE_CONNECT_TMP;
80
+            }
81
+        }
82
+
83
+        unset($GLOBALS['db_ok']);
84
+        unset($GLOBALS['spip_connect_version']);
85
+        if ($f && is_readable($f)) {
86
+            include($f);
87
+            if (!isset($GLOBALS['db_ok'])) {
88
+                spip_log("spip_connect: fichier de connexion '$f' OK mais echec connexion au serveur", _LOG_HS);
89
+            }
90
+        }
91
+        else {
92
+            spip_log("spip_connect: fichier de connexion '$f' non trouve, pas de connexion serveur", _LOG_HS);
93
+        }
94
+        if (!isset($GLOBALS['db_ok'])) {
95
+            // fera mieux la prochaine fois
96
+            if ($install) {
97
+                return false;
98
+            }
99
+            // ne plus reessayer si ce n'est pas l'install
100
+            return $GLOBALS['connexions'][$index] = false;
101
+        }
102
+        $GLOBALS['connexions'][$index] = $GLOBALS['db_ok'];
103
+    }
104
+    // si la connexion a deja ete tentee mais a echoue, le dire!
105
+    if (!$GLOBALS['connexions'][$index]) {
106
+        return false;
107
+    }
108
+
109
+    // la connexion a reussi ou etait deja faite.
110
+    // chargement de la version du jeu de fonctions
111
+    // si pas dans le fichier par defaut
112
+    $type = $GLOBALS['db_ok']['type'];
113
+    $jeu = 'spip_' . $type . '_functions_' . $version;
114
+    if (!isset($GLOBALS[$jeu]) && !find_in_path($type . '_' . $version . '.php', 'req/', true)) {
115
+        spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS);
116
+        // ne plus reessayer
117
+        return $GLOBALS['connexions'][$index][$version] = [];
118
+    }
119
+    $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu];
120
+    if ($old) {
121
+        return $GLOBALS['connexions'][$index];
122
+    }
123
+
124
+    $GLOBALS['connexions'][$index]['spip_connect_version'] = $GLOBALS['spip_connect_version'] ?? 0;
125
+
126
+    // initialisation de l'alphabet utilise dans les connexions SQL
127
+    // si l'installation l'a determine.
128
+    // Celui du serveur principal l'impose aux serveurs secondaires
129
+    // s'ils le connaissent
130
+
131
+    if (!$serveur) {
132
+        $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']);
133
+        if (!$charset) {
134
+            unset($GLOBALS['connexions'][$index]);
135
+            spip_log('spip_connect: absence de charset', _LOG_AVERTISSEMENT);
136
+
137
+            return false;
138
+        }
139
+    } else {
140
+        if ($GLOBALS['db_ok']['charset']) {
141
+            $charset = $GLOBALS['db_ok']['charset'];
142
+        }
143
+        // spip_meta n'existe pas toujours dans la base
144
+        // C'est le cas d'un dump sqlite par exemple
145
+        elseif (
146
+            $GLOBALS['connexions'][$index]['spip_connect_version']
147
+            && sql_showtable('spip_meta', true, $serveur)
148
+            && ($r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur))
149
+        ) {
150
+            $charset = $r;
151
+        } else {
152
+            $charset = -1;
153
+        }
154
+    }
155
+    if ($charset != -1) {
156
+        $f = $GLOBALS[$jeu]['set_charset'];
157
+        if (function_exists($f)) {
158
+            $f($charset, $serveur);
159
+        }
160
+    }
161
+
162
+    return $GLOBALS['connexions'][$index];
163 163
 }
164 164
 
165 165
 /**
@@ -168,12 +168,12 @@  discard block
 block discarded – undo
168 168
  * @param string $serveur Nom du connecteur de bdd utilisé
169 169
  **/
170 170
 function spip_sql_erreur($serveur = '') {
171
-	$connexion = spip_connect($serveur);
172
-	$e = sql_errno($serveur);
173
-	$t = ($connexion['type'] ?? 'sql');
174
-	$m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim((string) $connexion['last']);
175
-	$f = $t . $serveur;
176
-	spip_log($m, $f . '.' . _LOG_ERREUR);
171
+    $connexion = spip_connect($serveur);
172
+    $e = sql_errno($serveur);
173
+    $t = ($connexion['type'] ?? 'sql');
174
+    $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim((string) $connexion['last']);
175
+    $f = $t . $serveur;
176
+    spip_log($m, $f . '.' . _LOG_ERREUR);
177 177
 }
178 178
 
179 179
 /**
@@ -195,23 +195,23 @@  discard block
 block discarded – undo
195 195
  *     - array : description de la connexion, si l'instruction sql est indisponible pour cette connexion
196 196
  **/
197 197
 function spip_connect_sql($version, $ins = '', $serveur = '', $continue = false) {
198
-	$desc = spip_connect($serveur, $version);
199
-	if (
200
-		$desc
201
-		&& ($f = ($desc[$version][$ins] ?? ''))
202
-		&& function_exists($f)
203
-	) {
204
-		return $f;
205
-	}
206
-	if ($continue) {
207
-		return $desc;
208
-	}
209
-	if ($ins) {
210
-		spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR);
211
-	}
212
-	include_spip('inc/minipres');
213
-	echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]);
214
-	exit;
198
+    $desc = spip_connect($serveur, $version);
199
+    if (
200
+        $desc
201
+        && ($f = ($desc[$version][$ins] ?? ''))
202
+        && function_exists($f)
203
+    ) {
204
+        return $f;
205
+    }
206
+    if ($continue) {
207
+        return $desc;
208
+    }
209
+    if ($ins) {
210
+        spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR);
211
+    }
212
+    include_spip('inc/minipres');
213
+    echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]);
214
+    exit;
215 215
 }
216 216
 
217 217
 /**
@@ -237,70 +237,70 @@  discard block
 block discarded – undo
237 237
  * @return array|null Description de la connexion
238 238
  */
239 239
 function spip_connect_db(
240
-	$host,
241
-	$port,
242
-	$login,
243
-	#[\SensitiveParameter] $pass,
244
-	$db = '',
245
-	$type = 'mysql',
246
-	$prefixe = '',
247
-	$auth = '',
248
-	$charset = ''
240
+    $host,
241
+    $port,
242
+    $login,
243
+    #[\SensitiveParameter] $pass,
244
+    $db = '',
245
+    $type = 'mysql',
246
+    $prefixe = '',
247
+    $auth = '',
248
+    $charset = ''
249 249
 ) {
250
-	// temps avant nouvelle tentative de connexion
251
-	// suite a une connection echouee
252
-	if (!defined('_CONNECT_RETRY_DELAY')) {
253
-		define('_CONNECT_RETRY_DELAY', 30);
254
-	}
255
-
256
-	$f = '';
257
-	// un fichier de identifiant par combinaison (type,host,port,db)
258
-	// pour ne pas declarer tout indisponible d'un coup
259
-	// si en cours d'installation ou si db=@test@ on ne pose rien
260
-	// car c'est un test de connexion
261
-	if (!defined('_ECRIRE_INSTALL') && $db !== '@test@') {
262
-		$f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out';
263
-	} elseif ($db == '@test@') {
264
-		$db = '';
265
-	}
266
-
267
-	if (
268
-		$f
269
-		&& @file_exists($f)
270
-		&& (time() - @filemtime($f) < _CONNECT_RETRY_DELAY)
271
-	) {
272
-		spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS);
273
-
274
-		return null;
275
-	}
276
-
277
-	if (!$prefixe) {
278
-		$prefixe = $GLOBALS['table_prefix'] ?? $db;
279
-	}
280
-	$h = charger_fonction($type, 'req', true);
281
-	if (!$h) {
282
-		spip_log("les requetes $type ne sont pas fournies", _LOG_HS);
283
-
284
-		return null;
285
-	}
286
-	if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) {
287
-		if (!is_array($auth)) {
288
-			// compatibilite version 0.7 initiale
289
-			$g['ldap'] = $auth;
290
-			$auth = ['ldap' => $auth];
291
-		}
292
-		$g['authentification'] = $auth;
293
-		$g['type'] = $type;
294
-		$g['charset'] = $charset;
295
-
296
-		return $GLOBALS['db_ok'] = $g;
297
-	}
298
-	// En cas d'indisponibilite du serveur, eviter de le bombarder
299
-	if ($f) {
300
-		@touch($f);
301
-		spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS);
302
-	}
303
-	return null;
250
+    // temps avant nouvelle tentative de connexion
251
+    // suite a une connection echouee
252
+    if (!defined('_CONNECT_RETRY_DELAY')) {
253
+        define('_CONNECT_RETRY_DELAY', 30);
254
+    }
255
+
256
+    $f = '';
257
+    // un fichier de identifiant par combinaison (type,host,port,db)
258
+    // pour ne pas declarer tout indisponible d'un coup
259
+    // si en cours d'installation ou si db=@test@ on ne pose rien
260
+    // car c'est un test de connexion
261
+    if (!defined('_ECRIRE_INSTALL') && $db !== '@test@') {
262
+        $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out';
263
+    } elseif ($db == '@test@') {
264
+        $db = '';
265
+    }
266
+
267
+    if (
268
+        $f
269
+        && @file_exists($f)
270
+        && (time() - @filemtime($f) < _CONNECT_RETRY_DELAY)
271
+    ) {
272
+        spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS);
273
+
274
+        return null;
275
+    }
276
+
277
+    if (!$prefixe) {
278
+        $prefixe = $GLOBALS['table_prefix'] ?? $db;
279
+    }
280
+    $h = charger_fonction($type, 'req', true);
281
+    if (!$h) {
282
+        spip_log("les requetes $type ne sont pas fournies", _LOG_HS);
283
+
284
+        return null;
285
+    }
286
+    if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) {
287
+        if (!is_array($auth)) {
288
+            // compatibilite version 0.7 initiale
289
+            $g['ldap'] = $auth;
290
+            $auth = ['ldap' => $auth];
291
+        }
292
+        $g['authentification'] = $auth;
293
+        $g['type'] = $type;
294
+        $g['charset'] = $charset;
295
+
296
+        return $GLOBALS['db_ok'] = $g;
297
+    }
298
+    // En cas d'indisponibilite du serveur, eviter de le bombarder
299
+    if ($f) {
300
+        @touch($f);
301
+        spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS);
302
+    }
303
+    return null;
304 304
 }
305 305
 
306 306
 
@@ -332,32 +332,32 @@  discard block
 block discarded – undo
332 332
  *     - nom du charset sinon
333 333
  **/
334 334
 function spip_connect_main($connexion, $charset_sql_connexion = '') {
335
-	if ($GLOBALS['spip_connect_version'] < 0.1 && _DIR_RESTREINT) {
336
-		include_spip('inc/headers');
337
-		redirige_url_ecrire('upgrade', 'reinstall=oui');
338
-	}
339
-
340
-	if (!($f = $connexion['select'])) {
341
-		return false;
342
-	}
343
-	// si le charset est fourni, l'utiliser
344
-	if ($charset_sql_connexion) {
345
-		return $charset_sql_connexion;
346
-	}
347
-	// sinon on regarde la table spip_meta
348
-	// en cas d'erreur select retourne la requette (is_string=true donc)
349
-	if (
350
-		!($r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'"))
351
-		|| is_string($r)
352
-	) {
353
-		return false;
354
-	}
355
-	if (!($f = $connexion['fetch'])) {
356
-		return false;
357
-	}
358
-	$r = $f($r);
359
-
360
-	return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1;
335
+    if ($GLOBALS['spip_connect_version'] < 0.1 && _DIR_RESTREINT) {
336
+        include_spip('inc/headers');
337
+        redirige_url_ecrire('upgrade', 'reinstall=oui');
338
+    }
339
+
340
+    if (!($f = $connexion['select'])) {
341
+        return false;
342
+    }
343
+    // si le charset est fourni, l'utiliser
344
+    if ($charset_sql_connexion) {
345
+        return $charset_sql_connexion;
346
+    }
347
+    // sinon on regarde la table spip_meta
348
+    // en cas d'erreur select retourne la requette (is_string=true donc)
349
+    if (
350
+        !($r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'"))
351
+        || is_string($r)
352
+    ) {
353
+        return false;
354
+    }
355
+    if (!($f = $connexion['fetch'])) {
356
+        return false;
357
+    }
358
+    $r = $f($r);
359
+
360
+    return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1;
361 361
 }
362 362
 
363 363
 /**
@@ -373,16 +373,16 @@  discard block
 block discarded – undo
373 373
  * @return string Valeur échappée.
374 374
  **/
375 375
 function _q($a): string {
376
-	if (is_numeric($a)) {
377
-		return (string) $a;
378
-	} elseif (is_array($a)) {
379
-		return implode(',', array_map('_q', $a));
380
-	} elseif (is_scalar($a)) {
381
-		return ("'" . addslashes($a) . "'");
382
-	} elseif ($a === null) {
383
-		return "''";
384
-	}
385
-	throw new \RuntimeException('Can’t use _q with ' . gettype($a));
376
+    if (is_numeric($a)) {
377
+        return (string) $a;
378
+    } elseif (is_array($a)) {
379
+        return implode(',', array_map('_q', $a));
380
+    } elseif (is_scalar($a)) {
381
+        return ("'" . addslashes($a) . "'");
382
+    } elseif ($a === null) {
383
+        return "''";
384
+    }
385
+    throw new \RuntimeException('Can’t use _q with ' . gettype($a));
386 386
 }
387 387
 
388 388
 /**
@@ -398,75 +398,75 @@  discard block
 block discarded – undo
398 398
  * @return array
399 399
  */
400 400
 function query_echappe_textes($query, $uniqid = null) {
401
-	static $codeEchappements = null;
402
-	if (is_null($codeEchappements) || $uniqid) {
403
-		if (is_null($uniqid)) {
404
-			$uniqid = uniqid();
405
-		}
406
-		$uniqid = substr(md5((string) $uniqid), 0, 4);
407
-		$codeEchappements = ['\\\\' => "\x1@#{$uniqid}#@\x1", "\\'" => "\x2@#{$uniqid}#@\x2", '\\"' => "\x3@#{$uniqid}#@\x3", '%' => "\x4@#{$uniqid}#@\x4"];
408
-	}
409
-	if ($query === null) {
410
-		return $codeEchappements;
411
-	}
412
-
413
-	// si la query contient deja des codes d'echappement on va s'emmeler les pinceaux et donc on ne touche a rien
414
-	// ce n'est pas un cas legitime
415
-	foreach ($codeEchappements as $codeEchappement) {
416
-		if (str_contains($query, (string) $codeEchappement)) {
417
-			return [$query, []];
418
-		}
419
-	}
420
-
421
-	$query_echappees = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query);
422
-	if (preg_match_all("/('[^']*')|(\"[^\"]*\")/S", $query_echappees, $textes)) {
423
-		$textes = reset($textes);
424
-
425
-		$parts = [];
426
-		$currentpos = 0;
427
-		$k = 0;
428
-		while (count($textes)) {
429
-			$part = array_shift($textes);
430
-			$nextpos = strpos($query_echappees, (string) $part, $currentpos);
431
-			// si besoin recoller ensemble les doubles '' de sqlite (echappement des ')
432
-			while (count($textes) && str_ends_with((string) $part, "'")) {
433
-				$next = reset($textes);
434
-				if (
435
-					str_starts_with((string) $next, "'")
436
-					&& strpos($query_echappees, $part . $next, $currentpos) === $nextpos
437
-				) {
438
-					$part .= array_shift($textes);
439
-				}
440
-				else {
441
-					break;
442
-				}
443
-			}
444
-			$k++;
445
-			$parts[$k] = [
446
-				'texte' => $part,
447
-				'position' => $nextpos,
448
-				'placeholder' => '%' . $k . '$s',
449
-			];
450
-			$currentpos = $nextpos + strlen((string) $part);
451
-		}
452
-
453
-		// et on replace les parts une par une en commencant par la fin
454
-		while ($k > 0) {
455
-			$query_echappees = substr_replace($query_echappees, $parts[$k]['placeholder'], $parts[$k]['position'], strlen((string) $parts[$k]['texte']));
456
-			$k--;
457
-		}
458
-		$textes = array_column($parts, 'texte');
459
-	} else {
460
-		$textes = [];
461
-	}
462
-
463
-	// si il reste des quotes simples ou doubles, c'est qu'on s'est emmelle les pinceaux
464
-	// dans le doute on ne touche a rien
465
-	if (strpbrk($query_echappees, "'\"") !== false) {
466
-		return [$query, []];
467
-	}
468
-
469
-	return [$query_echappees, $textes];
401
+    static $codeEchappements = null;
402
+    if (is_null($codeEchappements) || $uniqid) {
403
+        if (is_null($uniqid)) {
404
+            $uniqid = uniqid();
405
+        }
406
+        $uniqid = substr(md5((string) $uniqid), 0, 4);
407
+        $codeEchappements = ['\\\\' => "\x1@#{$uniqid}#@\x1", "\\'" => "\x2@#{$uniqid}#@\x2", '\\"' => "\x3@#{$uniqid}#@\x3", '%' => "\x4@#{$uniqid}#@\x4"];
408
+    }
409
+    if ($query === null) {
410
+        return $codeEchappements;
411
+    }
412
+
413
+    // si la query contient deja des codes d'echappement on va s'emmeler les pinceaux et donc on ne touche a rien
414
+    // ce n'est pas un cas legitime
415
+    foreach ($codeEchappements as $codeEchappement) {
416
+        if (str_contains($query, (string) $codeEchappement)) {
417
+            return [$query, []];
418
+        }
419
+    }
420
+
421
+    $query_echappees = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query);
422
+    if (preg_match_all("/('[^']*')|(\"[^\"]*\")/S", $query_echappees, $textes)) {
423
+        $textes = reset($textes);
424
+
425
+        $parts = [];
426
+        $currentpos = 0;
427
+        $k = 0;
428
+        while (count($textes)) {
429
+            $part = array_shift($textes);
430
+            $nextpos = strpos($query_echappees, (string) $part, $currentpos);
431
+            // si besoin recoller ensemble les doubles '' de sqlite (echappement des ')
432
+            while (count($textes) && str_ends_with((string) $part, "'")) {
433
+                $next = reset($textes);
434
+                if (
435
+                    str_starts_with((string) $next, "'")
436
+                    && strpos($query_echappees, $part . $next, $currentpos) === $nextpos
437
+                ) {
438
+                    $part .= array_shift($textes);
439
+                }
440
+                else {
441
+                    break;
442
+                }
443
+            }
444
+            $k++;
445
+            $parts[$k] = [
446
+                'texte' => $part,
447
+                'position' => $nextpos,
448
+                'placeholder' => '%' . $k . '$s',
449
+            ];
450
+            $currentpos = $nextpos + strlen((string) $part);
451
+        }
452
+
453
+        // et on replace les parts une par une en commencant par la fin
454
+        while ($k > 0) {
455
+            $query_echappees = substr_replace($query_echappees, $parts[$k]['placeholder'], $parts[$k]['position'], strlen((string) $parts[$k]['texte']));
456
+            $k--;
457
+        }
458
+        $textes = array_column($parts, 'texte');
459
+    } else {
460
+        $textes = [];
461
+    }
462
+
463
+    // si il reste des quotes simples ou doubles, c'est qu'on s'est emmelle les pinceaux
464
+    // dans le doute on ne touche a rien
465
+    if (strpbrk($query_echappees, "'\"") !== false) {
466
+        return [$query, []];
467
+    }
468
+
469
+    return [$query_echappees, $textes];
470 470
 }
471 471
 
472 472
 /**
@@ -480,14 +480,14 @@  discard block
 block discarded – undo
480 480
  * @return string
481 481
  */
482 482
 function query_reinjecte_textes($query, $textes) {
483
-	// recuperer les codes echappements
484
-	$codeEchappements = query_echappe_textes(null);
483
+    // recuperer les codes echappements
484
+    $codeEchappements = query_echappe_textes(null);
485 485
 
486
-	if (!empty($textes)) {
487
-		$query = sprintf($query, ...$textes);
488
-	}
486
+    if (!empty($textes)) {
487
+        $query = sprintf($query, ...$textes);
488
+    }
489 489
 
490
-	return str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query);
490
+    return str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query);
491 491
 }
492 492
 
493 493
 
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
  **/
507 507
 function spip_query($query, $serveur = '') {
508 508
 
509
-	$f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true);
509
+    $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true);
510 510
 
511
-	return function_exists($f) ? $f($query, $serveur) : false;
511
+    return function_exists($f) ? $f($query, $serveur) : false;
512 512
 }
Please login to merge, or discard this patch.
ecrire/balise/id_logo_.php 2 patches
Indentation   +51 added lines, -51 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
 
@@ -48,38 +48,38 @@  discard block
 block discarded – undo
48 48
  */
49 49
 function balise_ID_LOGO__dist($p) {
50 50
 
51
-	preg_match(',^ID_LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs);
52
-	$type = strtolower($regs[1]);
53
-	$suite_logo = $regs[2];
54
-
55
-	// cas de #ID_LOGO_SITE_SPIP
56
-	if ($type == 'site_spip') {
57
-		$type = 'site';
58
-		$_id_objet = "\"'0'\"";
59
-	}
60
-
61
-	$id_objet = id_table_objet($type);
62
-	if (!isset($_id_objet)) {
63
-		$_id_objet = champ_sql($id_objet, $p);
64
-	}
65
-
66
-	$connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : '';
67
-	if ($type == 'document') {
68
-		$qconnect = _q($connect);
69
-		$doc = "quete_document($_id_objet, $qconnect)";
70
-		$code = "table_valeur($doc, 'id_vignette')";
71
-	} elseif ($connect) {
72
-		$code = "''";
73
-		spip_log('Les logos distants ne sont pas prevus');
74
-	} else {
75
-		$champ_logo = 'id';
76
-		$code = generer_code_logo($id_objet, $_id_objet, $type, '', "''", $p, $suite_logo, $champ_logo);
77
-	}
78
-
79
-	$p->code = $code;
80
-	$p->interdire_scripts = false;
81
-
82
-	return $p;
51
+    preg_match(',^ID_LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs);
52
+    $type = strtolower($regs[1]);
53
+    $suite_logo = $regs[2];
54
+
55
+    // cas de #ID_LOGO_SITE_SPIP
56
+    if ($type == 'site_spip') {
57
+        $type = 'site';
58
+        $_id_objet = "\"'0'\"";
59
+    }
60
+
61
+    $id_objet = id_table_objet($type);
62
+    if (!isset($_id_objet)) {
63
+        $_id_objet = champ_sql($id_objet, $p);
64
+    }
65
+
66
+    $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : '';
67
+    if ($type == 'document') {
68
+        $qconnect = _q($connect);
69
+        $doc = "quete_document($_id_objet, $qconnect)";
70
+        $code = "table_valeur($doc, 'id_vignette')";
71
+    } elseif ($connect) {
72
+        $code = "''";
73
+        spip_log('Les logos distants ne sont pas prevus');
74
+    } else {
75
+        $champ_logo = 'id';
76
+        $code = generer_code_logo($id_objet, $_id_objet, $type, '', "''", $p, $suite_logo, $champ_logo);
77
+    }
78
+
79
+    $p->code = $code;
80
+    $p->interdire_scripts = false;
81
+
82
+    return $p;
83 83
 }
84 84
 
85 85
 /**
@@ -108,28 +108,28 @@  discard block
 block discarded – undo
108 108
  *     Code compilé retournant le chemin du logo ou le code HTML du logo.
109 109
  **/
110 110
 function generer_code_logo($id_objet, $_id_objet, $type, $align, $_lien, $p, $suite, string $champ = ''): string {
111
-	$onoff = 'ON';
112
-	$_id_rubrique = "''";
111
+    $onoff = 'ON';
112
+    $_id_rubrique = "''";
113 113
 
114
-	if ($type === 'rubrique') {
115
-		$_id_rubrique = "quete_parent($_id_objet)";
116
-	}
114
+    if ($type === 'rubrique') {
115
+        $_id_rubrique = "quete_parent($_id_objet)";
116
+    }
117 117
 
118
-	if ($suite === '_SURVOL') {
119
-		$onoff = 'off';
120
-	} elseif ($suite === '_NORMAL') {
121
-		$onoff = 'on';
122
-	} elseif ($suite === '_RUBRIQUE') {
123
-		$_id_rubrique = champ_sql('id_rubrique', $p);
124
-	}
118
+    if ($suite === '_SURVOL') {
119
+        $onoff = 'off';
120
+    } elseif ($suite === '_NORMAL') {
121
+        $onoff = 'on';
122
+    } elseif ($suite === '_RUBRIQUE') {
123
+        $_id_rubrique = champ_sql('id_rubrique', $p);
124
+    }
125 125
 
126
-	$code = "quete_logo('$id_objet', '$onoff', $_id_objet, $_id_rubrique)";
126
+    $code = "quete_logo('$id_objet', '$onoff', $_id_objet, $_id_rubrique)";
127 127
 
128
-	if ($champ) {
129
-		return "table_valeur($code, '" . addslashes($champ) . "')";
130
-	}
128
+    if ($champ) {
129
+        return "table_valeur($code, '" . addslashes($champ) . "')";
130
+    }
131 131
 
132
-	$align = preg_replace(',\W,', '', $align);
132
+    $align = preg_replace(',\W,', '', $align);
133 133
 
134
-	return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')';
134
+    return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')';
135 135
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -126,10 +126,10 @@
 block discarded – undo
126 126
 	$code = "quete_logo('$id_objet', '$onoff', $_id_objet, $_id_rubrique)";
127 127
 
128 128
 	if ($champ) {
129
-		return "table_valeur($code, '" . addslashes($champ) . "')";
129
+		return "table_valeur($code, '".addslashes($champ)."')";
130 130
 	}
131 131
 
132 132
 	$align = preg_replace(',\W,', '', $align);
133 133
 
134
-	return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')';
134
+	return "quete_html_logo($code, '$align', ".($_lien ?: "''").')';
135 135
 }
Please login to merge, or discard this patch.
ecrire/balise/formulaire_inscription.php 3 patches
Indentation   +14 added lines, -14 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/abstract_sql');
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
  *     Pile complétée du code compilé
44 44
  **/
45 45
 function balise_FORMULAIRE_INSCRIPTION($p) {
46
-	return calculer_balise_dynamique($p, 'FORMULAIRE_INSCRIPTION', []);
46
+    return calculer_balise_dynamique($p, 'FORMULAIRE_INSCRIPTION', []);
47 47
 }
48 48
 
49 49
 /**
@@ -73,19 +73,19 @@  discard block
 block discarded – undo
73 73
  *   - chaîne vide sinon.
74 74
  */
75 75
 function balise_FORMULAIRE_INSCRIPTION_stat($args, $context_compil) {
76
-	[$mode, $id_ou_options, $retour] = array_pad($args, 3, null);
76
+    [$mode, $id_ou_options, $retour] = array_pad($args, 3, null);
77 77
 
78
-	// Compatibilité avec l'ancien param "id" dans les deux sens
79
-	if (!is_array($id_ou_options)) {
80
-		$options = ['id' => (int) $id_ou_options];
81
-		$id = $options['id'];
82
-	}else {
83
-		$options = $id_ou_options;
84
-		$id = (int) ($id_ou_options['id'] ?? 0);
85
-	}
78
+    // Compatibilité avec l'ancien param "id" dans les deux sens
79
+    if (!is_array($id_ou_options)) {
80
+        $options = ['id' => (int) $id_ou_options];
81
+        $id = $options['id'];
82
+    }else {
83
+        $options = $id_ou_options;
84
+        $id = (int) ($id_ou_options['id'] ?? 0);
85
+    }
86 86
 
87
-	include_spip('action/inscrire_auteur');
88
-	$mode = tester_statut_inscription($mode, $id);
87
+    include_spip('action/inscrire_auteur');
88
+    $mode = tester_statut_inscription($mode, $id);
89 89
 
90
-	return $mode ? [$mode, $options, $retour] : '';
90
+    return $mode ? [$mode, $options, $retour] : '';
91 91
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@
 block discarded – undo
79 79
 	if (!is_array($id_ou_options)) {
80 80
 		$options = ['id' => (int) $id_ou_options];
81 81
 		$id = $options['id'];
82
-	}else {
82
+	} else {
83 83
 		$options = $id_ou_options;
84 84
 		$id = (int) ($id_ou_options['id'] ?? 0);
85 85
 	}
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@
 block discarded – undo
79 79
 	if (!is_array($id_ou_options)) {
80 80
 		$options = ['id' => (int) $id_ou_options];
81 81
 		$id = $options['id'];
82
-	}else {
82
+	} else {
83 83
 		$options = $id_ou_options;
84 84
 		$id = (int) ($id_ou_options['id'] ?? 0);
85 85
 	}
Please login to merge, or discard this patch.
ecrire/maj/legacy/v31.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -17,12 +17,12 @@  discard block
 block discarded – undo
17 17
  * @package SPIP\Core\SQL\Upgrade
18 18
  **/
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
24 24
 $GLOBALS['maj'][21676] = [
25
-	['ranger_cache_gd2'],
25
+    ['ranger_cache_gd2'],
26 26
 ];
27 27
 
28 28
 /**
@@ -31,29 +31,29 @@  discard block
 block discarded – undo
31 31
  * https://core.spip.net/issues/3277
32 32
  */
33 33
 function ranger_cache_gd2() {
34
-	spip_log('ranger_cache_gd2');
35
-	$base = _DIR_VAR . 'cache-gd2/';
36
-	if (is_dir($base) && is_readable($base) && ($dir = opendir($base))) {
37
-		while (($f = readdir($dir)) !== false) {
38
-			if (
39
-				!is_dir($base . $f)
40
-				&& !str_starts_with($f, '.')
41
-				&& preg_match(',[0-9a-f]{32}\.\w+,', $f)
42
-			) {
43
-				$sub = substr($f, 0, 2);
44
-				$sub = sous_repertoire($base, $sub);
45
-				@rename($base . $f, $sub . substr($f, 2));
46
-				@unlink($base . $f); // au cas ou le rename a foire (collision)
47
-			}
48
-			if (time() >= _TIME_OUT) {
49
-				return;
50
-			}
51
-		}
52
-	}
34
+    spip_log('ranger_cache_gd2');
35
+    $base = _DIR_VAR . 'cache-gd2/';
36
+    if (is_dir($base) && is_readable($base) && ($dir = opendir($base))) {
37
+        while (($f = readdir($dir)) !== false) {
38
+            if (
39
+                !is_dir($base . $f)
40
+                && !str_starts_with($f, '.')
41
+                && preg_match(',[0-9a-f]{32}\.\w+,', $f)
42
+            ) {
43
+                $sub = substr($f, 0, 2);
44
+                $sub = sous_repertoire($base, $sub);
45
+                @rename($base . $f, $sub . substr($f, 2));
46
+                @unlink($base . $f); // au cas ou le rename a foire (collision)
47
+            }
48
+            if (time() >= _TIME_OUT) {
49
+                return;
50
+            }
51
+        }
52
+    }
53 53
 }
54 54
 
55 55
 
56 56
 $GLOBALS['maj'][21742] = [
57
-	['sql_alter', "TABLE spip_articles CHANGE url_site url_site text DEFAULT '' NOT NULL"],
58
-	['sql_alter', "TABLE spip_articles CHANGE virtuel virtuel text DEFAULT '' NOT NULL"],
57
+    ['sql_alter', "TABLE spip_articles CHANGE url_site url_site text DEFAULT '' NOT NULL"],
58
+    ['sql_alter', "TABLE spip_articles CHANGE virtuel virtuel text DEFAULT '' NOT NULL"],
59 59
 ];
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,18 +32,18 @@
 block discarded – undo
32 32
  */
33 33
 function ranger_cache_gd2() {
34 34
 	spip_log('ranger_cache_gd2');
35
-	$base = _DIR_VAR . 'cache-gd2/';
35
+	$base = _DIR_VAR.'cache-gd2/';
36 36
 	if (is_dir($base) && is_readable($base) && ($dir = opendir($base))) {
37 37
 		while (($f = readdir($dir)) !== false) {
38 38
 			if (
39
-				!is_dir($base . $f)
39
+				!is_dir($base.$f)
40 40
 				&& !str_starts_with($f, '.')
41 41
 				&& preg_match(',[0-9a-f]{32}\.\w+,', $f)
42 42
 			) {
43 43
 				$sub = substr($f, 0, 2);
44 44
 				$sub = sous_repertoire($base, $sub);
45
-				@rename($base . $f, $sub . substr($f, 2));
46
-				@unlink($base . $f); // au cas ou le rename a foire (collision)
45
+				@rename($base.$f, $sub.substr($f, 2));
46
+				@unlink($base.$f); // au cas ou le rename a foire (collision)
47 47
 			}
48 48
 			if (time() >= _TIME_OUT) {
49 49
 				return;
Please login to merge, or discard this patch.
ecrire/xml/sax.php 2 patches
Indentation   +244 added lines, -244 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('inc/charsets');
@@ -23,215 +23,215 @@  discard block
 block discarded – undo
23 23
  * @return string
24 24
  */
25 25
 function xml_entites_html($texte) {
26
-	if (!is_string($texte) || !$texte || strpbrk($texte, "&\"'<>") == false) {
27
-		return $texte;
28
-	}
26
+    if (!is_string($texte) || !$texte || strpbrk($texte, "&\"'<>") == false) {
27
+        return $texte;
28
+    }
29 29
 
30
-	if (!function_exists('spip_htmlspecialchars')) {
31
-		include_spip('inc/filtres_mini');
32
-	}
30
+    if (!function_exists('spip_htmlspecialchars')) {
31
+        include_spip('inc/filtres_mini');
32
+    }
33 33
 
34
-	return spip_htmlspecialchars($texte, ENT_QUOTES);
34
+    return spip_htmlspecialchars($texte, ENT_QUOTES);
35 35
 }
36 36
 
37 37
 function xml_debutElement($phraseur, $name, $attrs) {
38
-	$depth = $phraseur->depth;
39
-
40
-	$t = $phraseur->ouvrant[$depth] ?? ' ';
41
-	// espace initial signifie: deja integree au resultat
42
-	if ($t[0] != ' ') {
43
-		$phraseur->res .= '<' . $t . '>';
44
-		$phraseur->ouvrant[$depth] = ' ' . $t;
45
-	}
46
-	$t = $phraseur->contenu[$depth];
47
-	// n'indenter que s'il y a un separateur avant
48
-	$phraseur->res .= preg_replace("/[\n\t ]+$/", "\n$depth", $t);
49
-	$phraseur->contenu[$depth] = '';
50
-	$att = '';
51
-	$sep = ' ';
52
-	foreach ($attrs as $k => $v) {
53
-		$delim = str_contains($v, "'") ? '"' : "'";
54
-		$val = xml_entites_html($v);
55
-		$att .= $sep . $k . '=' . $delim
56
-			. ($delim !== '"' ? str_replace('&quot;', '"', $val) : $val)
57
-			. $delim;
58
-		$sep = "\n $depth";
59
-	}
60
-	$phraseur->depth .= '  ';
61
-	$phraseur->contenu[$phraseur->depth] = '';
62
-	$phraseur->ouvrant[$phraseur->depth] = $name . $att;
63
-	$phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax);
38
+    $depth = $phraseur->depth;
39
+
40
+    $t = $phraseur->ouvrant[$depth] ?? ' ';
41
+    // espace initial signifie: deja integree au resultat
42
+    if ($t[0] != ' ') {
43
+        $phraseur->res .= '<' . $t . '>';
44
+        $phraseur->ouvrant[$depth] = ' ' . $t;
45
+    }
46
+    $t = $phraseur->contenu[$depth];
47
+    // n'indenter que s'il y a un separateur avant
48
+    $phraseur->res .= preg_replace("/[\n\t ]+$/", "\n$depth", $t);
49
+    $phraseur->contenu[$depth] = '';
50
+    $att = '';
51
+    $sep = ' ';
52
+    foreach ($attrs as $k => $v) {
53
+        $delim = str_contains($v, "'") ? '"' : "'";
54
+        $val = xml_entites_html($v);
55
+        $att .= $sep . $k . '=' . $delim
56
+            . ($delim !== '"' ? str_replace('&quot;', '"', $val) : $val)
57
+            . $delim;
58
+        $sep = "\n $depth";
59
+    }
60
+    $phraseur->depth .= '  ';
61
+    $phraseur->contenu[$phraseur->depth] = '';
62
+    $phraseur->ouvrant[$phraseur->depth] = $name . $att;
63
+    $phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax);
64 64
 }
65 65
 
66 66
 function xml_finElement($phraseur, $name, $fusion_bal = false) {
67
-	$ouv = $phraseur->ouvrant[$phraseur->depth];
68
-
69
-	if ($ouv[0] != ' ') {
70
-		$phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv;
71
-	} else {
72
-		$ouv = '';
73
-	}
74
-	$t = $phraseur->contenu[$phraseur->depth];
75
-	$phraseur->depth = substr($phraseur->depth, 2);
76
-	$t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t);
77
-
78
-	// fusion <balise></balise> en <balise />.
79
-	// ATTENTION,  certains clients http croient que fusion ==> pas d'atttributs
80
-	// en particulier pour les balises Script et A.
81
-	// en presence d'attributs ne le faire que si la DTD est dispo et d'accord
82
-	// (param fusion_bal)
83
-
84
-	if ($t || ($ouv != $name && !$fusion_bal)) {
85
-		$phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . '</' . $name . '>';
86
-	} else {
87
-		$phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ('</' . $name . '>'));
88
-	}
67
+    $ouv = $phraseur->ouvrant[$phraseur->depth];
68
+
69
+    if ($ouv[0] != ' ') {
70
+        $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv;
71
+    } else {
72
+        $ouv = '';
73
+    }
74
+    $t = $phraseur->contenu[$phraseur->depth];
75
+    $phraseur->depth = substr($phraseur->depth, 2);
76
+    $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t);
77
+
78
+    // fusion <balise></balise> en <balise />.
79
+    // ATTENTION,  certains clients http croient que fusion ==> pas d'atttributs
80
+    // en particulier pour les balises Script et A.
81
+    // en presence d'attributs ne le faire que si la DTD est dispo et d'accord
82
+    // (param fusion_bal)
83
+
84
+    if ($t || ($ouv != $name && !$fusion_bal)) {
85
+        $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . '</' . $name . '>';
86
+    } else {
87
+        $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ('</' . $name . '>'));
88
+    }
89 89
 }
90 90
 
91 91
 function xml_textElement($phraseur, $data) {
92
-	$depth = $phraseur->depth;
93
-	$phraseur->contenu[$depth] .= preg_match('/^script/', $phraseur->ouvrant[$depth])
94
-		? $data
95
-		: xml_entites_html($data);
92
+    $depth = $phraseur->depth;
93
+    $phraseur->contenu[$depth] .= preg_match('/^script/', $phraseur->ouvrant[$depth])
94
+        ? $data
95
+        : xml_entites_html($data);
96 96
 }
97 97
 
98 98
 function xml_piElement($phraseur, $target, $data) {
99
-	$depth = $phraseur->depth;
100
-
101
-	if (strtolower($target) != 'php') {
102
-		$phraseur->contenu[$depth] .= $data;
103
-	} else {
104
-		ob_start();
105
-		eval($data);
106
-		$data = ob_get_contents();
107
-		ob_end_clean();
108
-		$phraseur->contenu[$depth] .= $data;
109
-	}
99
+    $depth = $phraseur->depth;
100
+
101
+    if (strtolower($target) != 'php') {
102
+        $phraseur->contenu[$depth] .= $data;
103
+    } else {
104
+        ob_start();
105
+        eval($data);
106
+        $data = ob_get_contents();
107
+        ob_end_clean();
108
+        $phraseur->contenu[$depth] .= $data;
109
+    }
110 110
 }
111 111
 
112 112
 
113 113
 function xml_defaultElement($phraseur, $data) {
114
-	$depth = $phraseur->depth;
114
+    $depth = $phraseur->depth;
115 115
 
116
-	if (!isset($phraseur->contenu[$depth])) {
117
-		$phraseur->contenu[$depth] = '';
118
-	}
119
-	$phraseur->contenu[$depth] .= $data;
116
+    if (!isset($phraseur->contenu[$depth])) {
117
+        $phraseur->contenu[$depth] = '';
118
+    }
119
+    $phraseur->contenu[$depth] .= $data;
120 120
 }
121 121
 
122 122
 function xml_parsestring($phraseur, $data) {
123
-	$phraseur->contenu[$phraseur->depth] = '';
124
-
125
-	if (!xml_parse($phraseur->sax, $data, true)) {
126
-		coordonnees_erreur(
127
-			$phraseur,
128
-			xml_error_string(xml_get_error_code($phraseur->sax))
129
-			. "<br />\n" .
130
-			($phraseur->depth
131
-				? '(' .
132
-					_T('erreur_balise_non_fermee') .
133
-					' <tt>' .
134
-					$phraseur->ouvrant[$phraseur->depth] .
135
-					'</tt> ' .
136
-					_T('ligne') .
137
-					' ' .
138
-					$phraseur->reperes[$phraseur->depth] .
139
-					") <br />\n"
140
-				: '')
141
-		);
142
-	}
123
+    $phraseur->contenu[$phraseur->depth] = '';
124
+
125
+    if (!xml_parse($phraseur->sax, $data, true)) {
126
+        coordonnees_erreur(
127
+            $phraseur,
128
+            xml_error_string(xml_get_error_code($phraseur->sax))
129
+            . "<br />\n" .
130
+            ($phraseur->depth
131
+                ? '(' .
132
+                    _T('erreur_balise_non_fermee') .
133
+                    ' <tt>' .
134
+                    $phraseur->ouvrant[$phraseur->depth] .
135
+                    '</tt> ' .
136
+                    _T('ligne') .
137
+                    ' ' .
138
+                    $phraseur->reperes[$phraseur->depth] .
139
+                    ") <br />\n"
140
+                : '')
141
+        );
142
+    }
143 143
 }
144 144
 
145 145
 function coordonnees_erreur($phraseur, $msg) {
146
-	$entete_length = substr_count($phraseur->entete, "\n");
147
-	$phraseur->err[] = [
148
-		$msg,
149
-		xml_get_current_line_number($phraseur->sax) + $entete_length,
150
-		xml_get_current_column_number($phraseur->sax)
151
-	];
146
+    $entete_length = substr_count($phraseur->entete, "\n");
147
+    $phraseur->err[] = [
148
+        $msg,
149
+        xml_get_current_line_number($phraseur->sax) + $entete_length,
150
+        xml_get_current_column_number($phraseur->sax)
151
+    ];
152 152
 }
153 153
 
154 154
 function xml_sax_dist($page, $apply = false, $phraseur = null, $doctype = '', $charset = null) {
155
-	if (is_null($charset)) {
156
-		$charset = $GLOBALS['meta']['charset'];
157
-	}
158
-	if ($apply) {
159
-		ob_start();
160
-		$r = is_array($apply) ? $page(...$apply) : $page();
161
-		$page = ob_get_contents();
162
-		ob_end_clean();
163
-		// fonction sans aucun "echo", ca doit etre le resultat
164
-		if (!$page) {
165
-			$page = $r;
166
-		}
167
-	}
168
-
169
-	if (!$page) {
170
-		return '';
171
-	}
172
-	// charger la DTD et transcoder les entites,
173
-	// et escamoter le doctype que sax mange en php5 mais pas en  php4
174
-	if (!$doctype) {
175
-		if (!$r = analyser_doctype($page)) {
176
-			$page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE
177
-				. preg_replace(_REGEXP_DOCTYPE, '', $page);
178
-			$r = analyser_doctype($page);
179
-		}
180
-		[$entete, $avail, $grammaire, $rotlvl] = array_pad($r, 4, null);
181
-		$page = substr($page, strlen($entete));
182
-	} else {
183
-		$avail = 'SYSTEM';
184
-		$grammaire = $doctype;
185
-		$rotlvl = basename($grammaire);
186
-	}
187
-
188
-	include_spip('xml/analyser_dtd');
189
-	$dtc = charger_dtd($grammaire, $avail, $rotlvl);
190
-	$page = sax_bug($page, $dtc, $charset);
191
-
192
-	// compatibilite Tidy espace public
193
-	if (!$phraseur) {
194
-		$indenter_xml = charger_fonction('indenter', 'xml');
195
-
196
-		return $indenter_xml($page, $apply);
197
-	}
198
-
199
-	$xml_parser = xml_parser_create($charset);
200
-
201
-	xml_set_element_handler(
202
-		$xml_parser,
203
-		[$phraseur, 'debutElement'],
204
-		[$phraseur, 'finElement']
205
-	);
206
-
207
-	xml_set_character_data_handler(
208
-		$xml_parser,
209
-		[$phraseur, 'textElement']
210
-	);
211
-
212
-	xml_set_processing_instruction_handler(
213
-		$xml_parser,
214
-		[$phraseur, 'piElement']
215
-	);
216
-
217
-	xml_set_default_handler(
218
-		$xml_parser,
219
-		[$phraseur, 'defaultElement']
220
-	);
221
-
222
-	xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
223
-
224
-	$phraseur->sax = $xml_parser;
225
-	if (isset($entete)) {
226
-		$phraseur->entete = $entete;
227
-	}
228
-	$phraseur->page = $page;
229
-	$phraseur->dtc = $dtc;
230
-	$phraseur->phraserTout($xml_parser, $page);
231
-	xml_parser_free($xml_parser);
232
-	$phraseur->sax = '';
233
-
234
-	return $phraseur;
155
+    if (is_null($charset)) {
156
+        $charset = $GLOBALS['meta']['charset'];
157
+    }
158
+    if ($apply) {
159
+        ob_start();
160
+        $r = is_array($apply) ? $page(...$apply) : $page();
161
+        $page = ob_get_contents();
162
+        ob_end_clean();
163
+        // fonction sans aucun "echo", ca doit etre le resultat
164
+        if (!$page) {
165
+            $page = $r;
166
+        }
167
+    }
168
+
169
+    if (!$page) {
170
+        return '';
171
+    }
172
+    // charger la DTD et transcoder les entites,
173
+    // et escamoter le doctype que sax mange en php5 mais pas en  php4
174
+    if (!$doctype) {
175
+        if (!$r = analyser_doctype($page)) {
176
+            $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE
177
+                . preg_replace(_REGEXP_DOCTYPE, '', $page);
178
+            $r = analyser_doctype($page);
179
+        }
180
+        [$entete, $avail, $grammaire, $rotlvl] = array_pad($r, 4, null);
181
+        $page = substr($page, strlen($entete));
182
+    } else {
183
+        $avail = 'SYSTEM';
184
+        $grammaire = $doctype;
185
+        $rotlvl = basename($grammaire);
186
+    }
187
+
188
+    include_spip('xml/analyser_dtd');
189
+    $dtc = charger_dtd($grammaire, $avail, $rotlvl);
190
+    $page = sax_bug($page, $dtc, $charset);
191
+
192
+    // compatibilite Tidy espace public
193
+    if (!$phraseur) {
194
+        $indenter_xml = charger_fonction('indenter', 'xml');
195
+
196
+        return $indenter_xml($page, $apply);
197
+    }
198
+
199
+    $xml_parser = xml_parser_create($charset);
200
+
201
+    xml_set_element_handler(
202
+        $xml_parser,
203
+        [$phraseur, 'debutElement'],
204
+        [$phraseur, 'finElement']
205
+    );
206
+
207
+    xml_set_character_data_handler(
208
+        $xml_parser,
209
+        [$phraseur, 'textElement']
210
+    );
211
+
212
+    xml_set_processing_instruction_handler(
213
+        $xml_parser,
214
+        [$phraseur, 'piElement']
215
+    );
216
+
217
+    xml_set_default_handler(
218
+        $xml_parser,
219
+        [$phraseur, 'defaultElement']
220
+    );
221
+
222
+    xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
223
+
224
+    $phraseur->sax = $xml_parser;
225
+    if (isset($entete)) {
226
+        $phraseur->entete = $entete;
227
+    }
228
+    $phraseur->page = $page;
229
+    $phraseur->dtc = $dtc;
230
+    $phraseur->phraserTout($xml_parser, $page);
231
+    xml_parser_free($xml_parser);
232
+    $phraseur->sax = '';
233
+
234
+    return $phraseur;
235 235
 }
236 236
 
237 237
 // SAX ne dit pas si une Entite est dans un attribut ou non.
@@ -242,24 +242,24 @@  discard block
 block discarded – undo
242 242
 // sinon on se rabat sur ce qu'en connait SPIP en standard.
243 243
 
244 244
 function sax_bug($data, $dtc, $charset = null) {
245
-	if (is_null($charset)) {
246
-		$charset = $GLOBALS['meta']['charset'];
247
-	}
248
-
249
-	if ($dtc) {
250
-		$trans = [];
251
-
252
-		foreach ($dtc->entites as $k => $v) {
253
-			if (!strpos(' amp lt gt quot ', (string) $k)) {
254
-				$trans["&$k;"] = $v;
255
-			}
256
-		}
257
-		$data = strtr($data, $trans);
258
-	} else {
259
-		$data = html2unicode($data, true);
260
-	}
261
-
262
-	return unicode2charset($data, $charset);
245
+    if (is_null($charset)) {
246
+        $charset = $GLOBALS['meta']['charset'];
247
+    }
248
+
249
+    if ($dtc) {
250
+        $trans = [];
251
+
252
+        foreach ($dtc->entites as $k => $v) {
253
+            if (!strpos(' amp lt gt quot ', (string) $k)) {
254
+                $trans["&$k;"] = $v;
255
+            }
256
+        }
257
+        $data = strtr($data, $trans);
258
+    } else {
259
+        $data = html2unicode($data, true);
260
+    }
261
+
262
+    return unicode2charset($data, $charset);
263 263
 }
264 264
 
265 265
 // Retirer < ? xml... ? > et autre PI, ainsi que les commentaires en debut
@@ -269,48 +269,48 @@  discard block
 block discarded – undo
269 269
 // les autres formats RSS n'ont pas de DTD,
270 270
 // mais un XML Schema que SPIP ne fait pas encore lire.
271 271
 function analyser_doctype($data) {
272
-	if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) {
273
-		if (preg_match(_REGEXP_XML, $data, $page)) {
274
-			[, $entete, $topelement] = $page;
275
-			if ($topelement == 'rss') {
276
-				return [
277
-					$entete,
278
-					'PUBLIC',
279
-					_DOCTYPE_RSS,
280
-					'rss-0.91.dtd'
281
-				];
282
-			} else {
283
-				$dtd = $topelement . '.dtd';
284
-				$f = find_in_path($dtd);
285
-				if (file_exists($f)) {
286
-					return [$entete, 'SYSTEM', $f, $dtd];
287
-				}
288
-			}
289
-		}
290
-		spip_log('Dtd pas vu pour ' . substr($data, 0, 100));
291
-
292
-		return [];
293
-	}
294
-	[$entete, , $topelement, $avail, $suite] = $page;
295
-
296
-	if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r) && !preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) {
297
-		return [];
298
-	}
299
-	[, $rotlvl, $suite] = $r;
300
-
301
-	if (!$suite) {
302
-		if ($avail != 'SYSTEM') {
303
-			return [];
304
-		}
305
-		$grammaire = $rotlvl;
306
-		$rotlvl = '';
307
-	} else {
308
-		if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r) && !preg_match("/^'([^']*)'\s*$/", $suite, $r)) {
309
-			return [];
310
-		}
311
-
312
-		$grammaire = $r[1];
313
-	}
314
-
315
-	return [$entete, $avail, $grammaire, $rotlvl];
272
+    if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) {
273
+        if (preg_match(_REGEXP_XML, $data, $page)) {
274
+            [, $entete, $topelement] = $page;
275
+            if ($topelement == 'rss') {
276
+                return [
277
+                    $entete,
278
+                    'PUBLIC',
279
+                    _DOCTYPE_RSS,
280
+                    'rss-0.91.dtd'
281
+                ];
282
+            } else {
283
+                $dtd = $topelement . '.dtd';
284
+                $f = find_in_path($dtd);
285
+                if (file_exists($f)) {
286
+                    return [$entete, 'SYSTEM', $f, $dtd];
287
+                }
288
+            }
289
+        }
290
+        spip_log('Dtd pas vu pour ' . substr($data, 0, 100));
291
+
292
+        return [];
293
+    }
294
+    [$entete, , $topelement, $avail, $suite] = $page;
295
+
296
+    if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r) && !preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) {
297
+        return [];
298
+    }
299
+    [, $rotlvl, $suite] = $r;
300
+
301
+    if (!$suite) {
302
+        if ($avail != 'SYSTEM') {
303
+            return [];
304
+        }
305
+        $grammaire = $rotlvl;
306
+        $rotlvl = '';
307
+    } else {
308
+        if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r) && !preg_match("/^'([^']*)'\s*$/", $suite, $r)) {
309
+            return [];
310
+        }
311
+
312
+        $grammaire = $r[1];
313
+    }
314
+
315
+    return [$entete, $avail, $grammaire, $rotlvl];
316 316
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
 	$t = $phraseur->ouvrant[$depth] ?? ' ';
41 41
 	// espace initial signifie: deja integree au resultat
42 42
 	if ($t[0] != ' ') {
43
-		$phraseur->res .= '<' . $t . '>';
44
-		$phraseur->ouvrant[$depth] = ' ' . $t;
43
+		$phraseur->res .= '<'.$t.'>';
44
+		$phraseur->ouvrant[$depth] = ' '.$t;
45 45
 	}
46 46
 	$t = $phraseur->contenu[$depth];
47 47
 	// n'indenter que s'il y a un separateur avant
@@ -52,14 +52,14 @@  discard block
 block discarded – undo
52 52
 	foreach ($attrs as $k => $v) {
53 53
 		$delim = str_contains($v, "'") ? '"' : "'";
54 54
 		$val = xml_entites_html($v);
55
-		$att .= $sep . $k . '=' . $delim
55
+		$att .= $sep.$k.'='.$delim
56 56
 			. ($delim !== '"' ? str_replace('&quot;', '"', $val) : $val)
57 57
 			. $delim;
58 58
 		$sep = "\n $depth";
59 59
 	}
60 60
 	$phraseur->depth .= '  ';
61 61
 	$phraseur->contenu[$phraseur->depth] = '';
62
-	$phraseur->ouvrant[$phraseur->depth] = $name . $att;
62
+	$phraseur->ouvrant[$phraseur->depth] = $name.$att;
63 63
 	$phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax);
64 64
 }
65 65
 
@@ -67,13 +67,13 @@  discard block
 block discarded – undo
67 67
 	$ouv = $phraseur->ouvrant[$phraseur->depth];
68 68
 
69 69
 	if ($ouv[0] != ' ') {
70
-		$phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv;
70
+		$phraseur->ouvrant[$phraseur->depth] = ' '.$ouv;
71 71
 	} else {
72 72
 		$ouv = '';
73 73
 	}
74 74
 	$t = $phraseur->contenu[$phraseur->depth];
75 75
 	$phraseur->depth = substr($phraseur->depth, 2);
76
-	$t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t);
76
+	$t = preg_replace("/[\n\t ]+$/", "\n".$phraseur->depth, $t);
77 77
 
78 78
 	// fusion <balise></balise> en <balise />.
79 79
 	// ATTENTION,  certains clients http croient que fusion ==> pas d'atttributs
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
 	// (param fusion_bal)
83 83
 
84 84
 	if ($t || ($ouv != $name && !$fusion_bal)) {
85
-		$phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . '</' . $name . '>';
85
+		$phraseur->res .= ($ouv ? ('<'.$ouv.'>') : '').$t.'</'.$name.'>';
86 86
 	} else {
87
-		$phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ('</' . $name . '>'));
87
+		$phraseur->res .= ($ouv ? ('<'.$ouv.' />') : ('</'.$name.'>'));
88 88
 	}
89 89
 }
90 90
 
@@ -126,16 +126,16 @@  discard block
 block discarded – undo
126 126
 		coordonnees_erreur(
127 127
 			$phraseur,
128 128
 			xml_error_string(xml_get_error_code($phraseur->sax))
129
-			. "<br />\n" .
129
+			. "<br />\n".
130 130
 			($phraseur->depth
131
-				? '(' .
132
-					_T('erreur_balise_non_fermee') .
133
-					' <tt>' .
134
-					$phraseur->ouvrant[$phraseur->depth] .
135
-					'</tt> ' .
136
-					_T('ligne') .
137
-					' ' .
138
-					$phraseur->reperes[$phraseur->depth] .
131
+				? '('.
132
+					_T('erreur_balise_non_fermee').
133
+					' <tt>'.
134
+					$phraseur->ouvrant[$phraseur->depth].
135
+					'</tt> '.
136
+					_T('ligne').
137
+					' '.
138
+					$phraseur->reperes[$phraseur->depth].
139 139
 					") <br />\n"
140 140
 				: '')
141 141
 		);
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 	// et escamoter le doctype que sax mange en php5 mais pas en  php4
174 174
 	if (!$doctype) {
175 175
 		if (!$r = analyser_doctype($page)) {
176
-			$page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE
176
+			$page = _MESSAGE_DOCTYPE._DOCTYPE_ECRIRE
177 177
 				. preg_replace(_REGEXP_DOCTYPE, '', $page);
178 178
 			$r = analyser_doctype($page);
179 179
 		}
@@ -280,18 +280,18 @@  discard block
 block discarded – undo
280 280
 					'rss-0.91.dtd'
281 281
 				];
282 282
 			} else {
283
-				$dtd = $topelement . '.dtd';
283
+				$dtd = $topelement.'.dtd';
284 284
 				$f = find_in_path($dtd);
285 285
 				if (file_exists($f)) {
286 286
 					return [$entete, 'SYSTEM', $f, $dtd];
287 287
 				}
288 288
 			}
289 289
 		}
290
-		spip_log('Dtd pas vu pour ' . substr($data, 0, 100));
290
+		spip_log('Dtd pas vu pour '.substr($data, 0, 100));
291 291
 
292 292
 		return [];
293 293
 	}
294
-	[$entete, , $topelement, $avail, $suite] = $page;
294
+	[$entete,, $topelement, $avail, $suite] = $page;
295 295
 
296 296
 	if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r) && !preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) {
297 297
 		return [];
Please login to merge, or discard this patch.
ecrire/req/sqlite_fonctions.php 2 patches
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
  */
22 22
 
23 23
 if (!defined('_ECRIRE_INC_VERSION')) {
24
-	return;
24
+    return;
25 25
 }
26 26
 
27 27
 /**
@@ -42,90 +42,90 @@  discard block
 block discarded – undo
42 42
  */
43 43
 function _sqlite_init_functions(&$sqlite) {
44 44
 
45
-	if (!$sqlite) {
46
-		return false;
47
-	}
45
+    if (!$sqlite) {
46
+        return false;
47
+    }
48 48
 
49 49
 
50
-	$fonctions = [
51
-		// A
52
-		'ACOS'  => ['acos', 1],
53
-		'ASIN'  => ['asin', 1],
54
-		'ATAN'  => ['atan', 1], // mysql accepte 2 params comme atan2… hum ?
55
-		'ATAN2' => ['atan2', 2],
50
+    $fonctions = [
51
+        // A
52
+        'ACOS'  => ['acos', 1],
53
+        'ASIN'  => ['asin', 1],
54
+        'ATAN'  => ['atan', 1], // mysql accepte 2 params comme atan2… hum ?
55
+        'ATAN2' => ['atan2', 2],
56 56
 
57
-		// C
58
-		'CEIL'   => ['_sqlite_func_ceil', 1],
59
-		'CONCAT' => ['_sqlite_func_concat', -1],
60
-		'COS'    => ['cos', 1],
57
+        // C
58
+        'CEIL'   => ['_sqlite_func_ceil', 1],
59
+        'CONCAT' => ['_sqlite_func_concat', -1],
60
+        'COS'    => ['cos', 1],
61 61
 
62
-		// D
63
-		'DATE_FORMAT' => ['_sqlite_func_date_format', 2], // équivalent a strftime avec args inversés
64
-		'DAYOFMONTH'  => ['_sqlite_func_dayofmonth', 1],
65
-		'DEGREES'     => ['rad2deg', 1],
62
+        // D
63
+        'DATE_FORMAT' => ['_sqlite_func_date_format', 2], // équivalent a strftime avec args inversés
64
+        'DAYOFMONTH'  => ['_sqlite_func_dayofmonth', 1],
65
+        'DEGREES'     => ['rad2deg', 1],
66 66
 
67
-		// E
68
-		'EXTRAIRE_MULTI' => ['_sqlite_func_extraire_multi', 2], // specifique a SPIP/sql_multi()
69
-		'EXP'            => ['exp', 1],
67
+        // E
68
+        'EXTRAIRE_MULTI' => ['_sqlite_func_extraire_multi', 2], // specifique a SPIP/sql_multi()
69
+        'EXP'            => ['exp', 1],
70 70
 
71
-		// F
72
-		'FIND_IN_SET' => ['_sqlite_func_find_in_set', 2],
73
-		'FLOOR'       => ['_sqlite_func_floor', 1],
71
+        // F
72
+        'FIND_IN_SET' => ['_sqlite_func_find_in_set', 2],
73
+        'FLOOR'       => ['_sqlite_func_floor', 1],
74 74
 
75
-		// G
76
-		'GREATEST' => ['_sqlite_func_greatest', -1],
75
+        // G
76
+        'GREATEST' => ['_sqlite_func_greatest', -1],
77 77
 
78
-		// I
79
-		'IF'     => ['_sqlite_func_if', 3],
80
-		'INSERT' => ['_sqlite_func_insert', 4],
81
-		'INSTR'  => ['_sqlite_func_instr', 2],
78
+        // I
79
+        'IF'     => ['_sqlite_func_if', 3],
80
+        'INSERT' => ['_sqlite_func_insert', 4],
81
+        'INSTR'  => ['_sqlite_func_instr', 2],
82 82
 
83
-		// L
84
-		'LEAST'  => ['_sqlite_func_least', -1],
85
-		'_LEFT'  => ['_sqlite_func_left', 2],
83
+        // L
84
+        'LEAST'  => ['_sqlite_func_least', -1],
85
+        '_LEFT'  => ['_sqlite_func_left', 2],
86 86
 
87
-		// N
88
-		'NOW' => ['_sqlite_func_now', 0],
87
+        // N
88
+        'NOW' => ['_sqlite_func_now', 0],
89 89
 
90
-		// M
91
-		'MD5'   => ['md5', 1],
92
-		'MONTH' => ['_sqlite_func_month', 1],
90
+        // M
91
+        'MD5'   => ['md5', 1],
92
+        'MONTH' => ['_sqlite_func_month', 1],
93 93
 
94
-		// P
95
-		'PREG_REPLACE' => ['_sqlite_func_preg_replace', 3],
94
+        // P
95
+        'PREG_REPLACE' => ['_sqlite_func_preg_replace', 3],
96 96
 
97
-		// R
98
-		'RADIANS' => ['deg2rad', 1],
99
-		'RAND'    => ['_sqlite_func_rand', 0], // sinon random() v2.4
100
-		'REGEXP'  => ['_sqlite_func_regexp_match', 2], // critere REGEXP supporte a partir de v3.3.2
101
-		'RIGHT'   => ['_sqlite_func_right', 2],
97
+        // R
98
+        'RADIANS' => ['deg2rad', 1],
99
+        'RAND'    => ['_sqlite_func_rand', 0], // sinon random() v2.4
100
+        'REGEXP'  => ['_sqlite_func_regexp_match', 2], // critere REGEXP supporte a partir de v3.3.2
101
+        'RIGHT'   => ['_sqlite_func_right', 2],
102 102
 
103
-		// S
104
-		'SETTYPE'   => ['settype', 2], // CAST present en v3.2.3
105
-		'SIN'       => ['sin', 1],
106
-		'SQRT'      => ['sqrt', 1],
107
-		'SUBSTRING' => ['_sqlite_func_substring' /*, 3*/], // peut etre appelee avec 2 ou 3 arguments, index base 1 et non 0
103
+        // S
104
+        'SETTYPE'   => ['settype', 2], // CAST present en v3.2.3
105
+        'SIN'       => ['sin', 1],
106
+        'SQRT'      => ['sqrt', 1],
107
+        'SUBSTRING' => ['_sqlite_func_substring' /*, 3*/], // peut etre appelee avec 2 ou 3 arguments, index base 1 et non 0
108 108
 
109
-		// T
110
-		'TAN'           => ['tan', 1],
111
-		'TIMESTAMPDIFF' => ['_sqlite_timestampdiff'    /*, 3*/],
112
-		'TO_DAYS'       => ['_sqlite_func_to_days', 1],
109
+        // T
110
+        'TAN'           => ['tan', 1],
111
+        'TIMESTAMPDIFF' => ['_sqlite_timestampdiff'    /*, 3*/],
112
+        'TO_DAYS'       => ['_sqlite_func_to_days', 1],
113 113
 
114
-		// U
115
-		'UNIX_TIMESTAMP' => ['_sqlite_func_unix_timestamp', 1],
114
+        // U
115
+        'UNIX_TIMESTAMP' => ['_sqlite_func_unix_timestamp', 1],
116 116
 
117
-		// V
118
-		'VIDE' => ['_sqlite_func_vide', 0], // du vide pour SELECT 0 as x ... ORDER BY x -> ORDER BY vide()
117
+        // V
118
+        'VIDE' => ['_sqlite_func_vide', 0], // du vide pour SELECT 0 as x ... ORDER BY x -> ORDER BY vide()
119 119
 
120
-		// Y
121
-		'YEAR' => ['_sqlite_func_year', 1]
122
-	];
120
+        // Y
121
+        'YEAR' => ['_sqlite_func_year', 1]
122
+    ];
123 123
 
124
-	foreach ($fonctions as $f => $r) {
125
-		_sqlite_add_function($sqlite, $f, $r);
126
-	}
124
+    foreach ($fonctions as $f => $r) {
125
+        _sqlite_add_function($sqlite, $f, $r);
126
+    }
127 127
 
128
-	#spip_log('functions sqlite chargees ','sqlite.'._LOG_DEBUG);
128
+    #spip_log('functions sqlite chargees ','sqlite.'._LOG_DEBUG);
129 129
 }
130 130
 
131 131
 
@@ -146,9 +146,9 @@  discard block
 block discarded – undo
146 146
  *
147 147
 **/
148 148
 function _sqlite_add_function(&$sqlite, &$f, &$r) {
149
-	isset($r[1])
150
-		? $sqlite->sqliteCreateFunction($f, $r[0], $r[1])
151
-		: $sqlite->sqliteCreateFunction($f, $r[0]);
149
+    isset($r[1])
150
+        ? $sqlite->sqliteCreateFunction($f, $r[0], $r[1])
151
+        : $sqlite->sqliteCreateFunction($f, $r[0]);
152 152
 }
153 153
 
154 154
 /**
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
  * @return int
159 159
  */
160 160
 function _sqlite_func_ceil($a) {
161
-	return ceil($a);
161
+    return ceil($a);
162 162
 }
163 163
 
164 164
 /**
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
  * @return string
169 169
  */
170 170
 function _sqlite_func_concat(...$args) {
171
-	return implode('', $args);
171
+    return implode('', $args);
172 172
 }
173 173
 
174 174
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
  * @return string
182 182
  */
183 183
 function _sqlite_func_dayofmonth($d) {
184
-	return _sqlite_func_date('d', $d);
184
+    return _sqlite_func_date('d', $d);
185 185
 }
186 186
 
187 187
 
@@ -193,15 +193,15 @@  discard block
 block discarded – undo
193 193
  * @return int
194 194
  */
195 195
 function _sqlite_func_find_in_set($num, $set) {
196
-	$rank = 0;
197
-	foreach (explode(',', $set) as $v) {
198
-		if ($v == $num) {
199
-			return (++$rank);
200
-		}
201
-		$rank++;
202
-	}
203
-
204
-	return 0;
196
+    $rank = 0;
197
+    foreach (explode(',', $set) as $v) {
198
+        if ($v == $num) {
199
+            return (++$rank);
200
+        }
201
+        $rank++;
202
+    }
203
+
204
+    return 0;
205 205
 }
206 206
 
207 207
 /**
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
  * @return int
212 212
  */
213 213
 function _sqlite_func_floor($a) {
214
-	return floor($a);
214
+    return floor($a);
215 215
 }
216 216
 
217 217
 
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
  * @return mixed
225 225
  */
226 226
 function _sqlite_func_if($bool, $oui, $non) {
227
-	return ($bool) ? $oui : $non;
227
+    return ($bool) ? $oui : $non;
228 228
 }
229 229
 
230 230
 
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
  * @return string
242 242
  */
243 243
 function _sqlite_func_insert($s, $index, $longueur, $chaine) {
244
-	return
245
-		substr($s, 0, $index)
246
-		. $chaine
247
-		. substr(substr($s, $index), $longueur);
244
+    return
245
+        substr($s, 0, $index)
246
+        . $chaine
247
+        . substr(substr($s, $index), $longueur);
248 248
 }
249 249
 
250 250
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
  * @return int
257 257
  */
258 258
 function _sqlite_func_instr($s, $search) {
259
-	return strpos($s, $search);
259
+    return strpos($s, $search);
260 260
 }
261 261
 
262 262
 
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
  * @return int
268 268
  */
269 269
 function _sqlite_func_least(...$args) {
270
-	return min($args);
270
+    return min($args);
271 271
 }
272 272
 
273 273
 
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
  * @return int
279 279
  */
280 280
 function _sqlite_func_greatest(...$args) {
281
-	return max($args);
281
+    return max($args);
282 282
 }
283 283
 
284 284
 
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
  * @return string
291 291
  */
292 292
 function _sqlite_func_left($s, $lenght) {
293
-	return substr($s, $lenght);
293
+    return substr($s, $lenght);
294 294
 }
295 295
 
296 296
 /**
@@ -300,13 +300,13 @@  discard block
 block discarded – undo
300 300
  * @return string
301 301
  */
302 302
 function _sqlite_func_now($force_refresh = false) {
303
-	static $now = null;
304
-	if (is_null($now) || $force_refresh) {
305
-		$now = date('Y-m-d H:i:s');
306
-	}
303
+    static $now = null;
304
+    if (is_null($now) || $force_refresh) {
305
+        $now = date('Y-m-d H:i:s');
306
+    }
307 307
 
308
-	#spip_log("Passage avec NOW : $now | ".time(),'sqlite.'._LOG_DEBUG);
309
-	return $now;
308
+    #spip_log("Passage avec NOW : $now | ".time(),'sqlite.'._LOG_DEBUG);
309
+    return $now;
310 310
 }
311 311
 
312 312
 
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
  * @return string
320 320
  */
321 321
 function _sqlite_func_month($d) {
322
-	return _sqlite_func_date('m', $d);
322
+    return _sqlite_func_date('m', $d);
323 323
 }
324 324
 
325 325
 
@@ -332,8 +332,8 @@  discard block
 block discarded – undo
332 332
  * @return string
333 333
  */
334 334
 function _sqlite_func_preg_replace($quoi, $cherche, $remplace) {
335
-	#spip_log("preg_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG);
336
-	return preg_replace('%' . $cherche . '%', $remplace, $quoi);
335
+    #spip_log("preg_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG);
336
+    return preg_replace('%' . $cherche . '%', $remplace, $quoi);
337 337
 }
338 338
 
339 339
 /**
@@ -346,13 +346,13 @@  discard block
 block discarded – undo
346 346
  * @return string, l'extrait trouve.
347 347
  **/
348 348
 function _sqlite_func_extraire_multi($quoi, $lang) {
349
-	if (str_contains($quoi, '<')) {
350
-		include_spip('src/Texte/Collecteur/AbstractCollecteur');
351
-		include_spip('src/Texte/Collecteur/Multis');
352
-		$collecteurMultis = new Spip\Texte\Collecteur\Multis();
353
-		$quoi = $collecteurMultis->traiter($quoi, ['lang' => $lang, 'appliquer_typo' => false]);
354
-	}
355
-	return $quoi;
349
+    if (str_contains($quoi, '<')) {
350
+        include_spip('src/Texte/Collecteur/AbstractCollecteur');
351
+        include_spip('src/Texte/Collecteur/Multis');
352
+        $collecteurMultis = new Spip\Texte\Collecteur\Multis();
353
+        $quoi = $collecteurMultis->traiter($quoi, ['lang' => $lang, 'appliquer_typo' => false]);
354
+    }
355
+    return $quoi;
356 356
 }
357 357
 
358 358
 
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
  * @return float
363 363
  */
364 364
 function _sqlite_func_rand() {
365
-	return random_int(0, mt_getrandmax());
365
+    return random_int(0, mt_getrandmax());
366 366
 }
367 367
 
368 368
 
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
  * @return string
375 375
  */
376 376
 function _sqlite_func_right($s, $length) {
377
-	return substr($s, 0 - $length);
377
+    return substr($s, 0 - $length);
378 378
 }
379 379
 
380 380
 
@@ -386,16 +386,16 @@  discard block
 block discarded – undo
386 386
  * @return bool
387 387
  */
388 388
 function _sqlite_func_regexp_match($cherche, $quoi) {
389
-	// optimiser un cas tres courant avec les requetes en base
390
-	if (!$quoi && !strlen($quoi)) {
391
-		return false;
392
-	}
393
-	// il faut enlever un niveau d'echappement pour être homogène à mysql
394
-	$cherche = str_replace('\\\\', '\\', $cherche);
395
-	$u = $GLOBALS['meta']['pcre_u'] ?? 'u';
396
-
397
-	#spip_log("regexp_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG);
398
-	return preg_match('%' . $cherche . '%imsS' . $u, $quoi);
389
+    // optimiser un cas tres courant avec les requetes en base
390
+    if (!$quoi && !strlen($quoi)) {
391
+        return false;
392
+    }
393
+    // il faut enlever un niveau d'echappement pour être homogène à mysql
394
+    $cherche = str_replace('\\\\', '\\', $cherche);
395
+    $u = $GLOBALS['meta']['pcre_u'] ?? 'u';
396
+
397
+    #spip_log("regexp_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG);
398
+    return preg_match('%' . $cherche . '%imsS' . $u, $quoi);
399 399
 }
400 400
 
401 401
 
@@ -410,8 +410,8 @@  discard block
 block discarded – undo
410 410
  * @return string
411 411
  */
412 412
 function _sqlite_func_date_format($date, $conv) {
413
-	$conv = _sqlite_func_strftime_format_converter($conv);
414
-	return strftime($conv, is_int($date) ? $date : strtotime($date));
413
+    $conv = _sqlite_func_strftime_format_converter($conv);
414
+    return strftime($conv, is_int($date) ? $date : strtotime($date));
415 415
 }
416 416
 
417 417
 /**
@@ -427,28 +427,28 @@  discard block
 block discarded – undo
427 427
  * @return void
428 428
  */
429 429
 function _sqlite_func_strftime_format_converter(string $conv): string {
430
-	// ok : %a %b %d %e %H %I %l %j %k %m %p %r %S %T %w %y %Y
431
-	// on ne sait pas en gérer certains...
432
-	static $mysql_to_strftime_not_ok = ['%c', '%D', '%f', '%U', '%V', '%W', '%X'];
433
-	static $mysql_to_strftime = [
434
-		'%h' => '%I',
435
-		'%i' => '%M',
436
-		'%M' => '%B',
437
-		'%s' => '%S',
438
-		'%u' => '%U',
439
-		'%v' => '%V',
440
-		'%x' => '%G',
441
-	];
442
-	static $to_strftime = [];
443
-	if (!isset($to_strftime[$conv])) {
444
-		$count = 0;
445
-		str_replace($mysql_to_strftime_not_ok, '', $conv, $count);
446
-		if ($count > 0) {
447
-			spip_log("DATE_FORMAT : At least one parameter can't be parsed by strftime with format '$conv'", 'sqlite.' . _LOG_ERREUR);
448
-		}
449
-		$to_strftime[$conv] = str_replace(array_keys($mysql_to_strftime), $mysql_to_strftime, $conv);
450
-	}
451
-	return $to_strftime[$conv];
430
+    // ok : %a %b %d %e %H %I %l %j %k %m %p %r %S %T %w %y %Y
431
+    // on ne sait pas en gérer certains...
432
+    static $mysql_to_strftime_not_ok = ['%c', '%D', '%f', '%U', '%V', '%W', '%X'];
433
+    static $mysql_to_strftime = [
434
+        '%h' => '%I',
435
+        '%i' => '%M',
436
+        '%M' => '%B',
437
+        '%s' => '%S',
438
+        '%u' => '%U',
439
+        '%v' => '%V',
440
+        '%x' => '%G',
441
+    ];
442
+    static $to_strftime = [];
443
+    if (!isset($to_strftime[$conv])) {
444
+        $count = 0;
445
+        str_replace($mysql_to_strftime_not_ok, '', $conv, $count);
446
+        if ($count > 0) {
447
+            spip_log("DATE_FORMAT : At least one parameter can't be parsed by strftime with format '$conv'", 'sqlite.' . _LOG_ERREUR);
448
+        }
449
+        $to_strftime[$conv] = str_replace(array_keys($mysql_to_strftime), $mysql_to_strftime, $conv);
450
+    }
451
+    return $to_strftime[$conv];
452 452
 }
453 453
 
454 454
 /**
@@ -462,11 +462,11 @@  discard block
 block discarded – undo
462 462
  * @return int
463 463
  */
464 464
 function _sqlite_func_to_days($d) {
465
-	static $offset = 719528; // nb de jour entre 0000-00-00 et timestamp 0=1970-01-01
466
-	$result = $offset + (int)ceil(_sqlite_func_unix_timestamp($d) / (24 * 3600));
465
+    static $offset = 719528; // nb de jour entre 0000-00-00 et timestamp 0=1970-01-01
466
+    $result = $offset + (int)ceil(_sqlite_func_unix_timestamp($d) / (24 * 3600));
467 467
 
468
-	#spip_log("Passage avec TO_DAYS : $d, $result",'sqlite.'._LOG_DEBUG);
469
-	return $result;
468
+    #spip_log("Passage avec TO_DAYS : $d, $result",'sqlite.'._LOG_DEBUG);
469
+    return $result;
470 470
 }
471 471
 
472 472
 /**
@@ -478,13 +478,13 @@  discard block
 block discarded – undo
478 478
  * @return string
479 479
  */
480 480
 function _sqlite_func_substring($string, $start, $len = null) {
481
-	// SQL compte a partir de 1, php a partir de 0
482
-	$start = ($start > 0) ? $start - 1 : $start;
483
-	if (is_null($len)) {
484
-		return substr($string, $start);
485
-	} else {
486
-		return substr($string, $start, $len);
487
-	}
481
+    // SQL compte a partir de 1, php a partir de 0
482
+    $start = ($start > 0) ? $start - 1 : $start;
483
+    if (is_null($len)) {
484
+        return substr($string, $start);
485
+    } else {
486
+        return substr($string, $start, $len);
487
+    }
488 488
 }
489 489
 
490 490
 /**
@@ -500,22 +500,22 @@  discard block
 block discarded – undo
500 500
  * @return int
501 501
  */
502 502
 function _sqlite_timestampdiff($unit, $date1, $date2) {
503
-	$d1 = date_create($date1);
504
-	$d2 = date_create($date2);
505
-	$diff = date_diff($d1, $d2);
506
-	$inv = $diff->invert ? -1 : 1;
507
-	return match ($unit) {
508
-		'YEAR' => $inv * $diff->y,
509
-		'QUARTER' => $inv * (4 * $diff->y + (int) floor($diff->m / 3)),
510
-		'MONTH' => $inv * (12 * $diff->y + $diff->m),
511
-		'WEEK' => $inv * (int) floor($diff->days / 7),
512
-		'DAY' => $inv * $diff->days,
513
-		'HOUR' => $inv * (24 * $diff->days + $diff->h),
514
-		'MINUTE' => $inv * ((24 * $diff->days + $diff->h) * 60 + $diff->i),
515
-		'SECOND' => $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s),
516
-		'MICROSECOND' => $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s) * 1_000_000,
517
-		default => 0,
518
-	};
503
+    $d1 = date_create($date1);
504
+    $d2 = date_create($date2);
505
+    $diff = date_diff($d1, $d2);
506
+    $inv = $diff->invert ? -1 : 1;
507
+    return match ($unit) {
508
+        'YEAR' => $inv * $diff->y,
509
+        'QUARTER' => $inv * (4 * $diff->y + (int) floor($diff->m / 3)),
510
+        'MONTH' => $inv * (12 * $diff->y + $diff->m),
511
+        'WEEK' => $inv * (int) floor($diff->days / 7),
512
+        'DAY' => $inv * $diff->days,
513
+        'HOUR' => $inv * (24 * $diff->days + $diff->h),
514
+        'MINUTE' => $inv * ((24 * $diff->days + $diff->h) * 60 + $diff->i),
515
+        'SECOND' => $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s),
516
+        'MICROSECOND' => $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s) * 1_000_000,
517
+        default => 0,
518
+    };
519 519
 }
520 520
 
521 521
 /**
@@ -525,24 +525,24 @@  discard block
 block discarded – undo
525 525
  * @return int
526 526
  */
527 527
 function _sqlite_func_unix_timestamp($d) {
528
-	static $mem = [];
529
-	static $n = 0;
530
-	if (isset($mem[$d])) {
531
-		return $mem[$d];
532
-	}
533
-	if ($n++ > 100) {
534
-		$mem = [];
535
-		$n = 0;
536
-	}
537
-
538
-	//2005-12-02 20:53:53
539
-	#spip_log("Passage avec UNIX_TIMESTAMP : $d",'sqlite.'._LOG_DEBUG);
540
-	if (!$d) {
541
-		return $mem[$d] = time();
542
-	}
543
-
544
-	// une pile plus grosse n'accelere pas le calcul
545
-	return $mem[$d] = strtotime($d);
528
+    static $mem = [];
529
+    static $n = 0;
530
+    if (isset($mem[$d])) {
531
+        return $mem[$d];
532
+    }
533
+    if ($n++ > 100) {
534
+        $mem = [];
535
+        $n = 0;
536
+    }
537
+
538
+    //2005-12-02 20:53:53
539
+    #spip_log("Passage avec UNIX_TIMESTAMP : $d",'sqlite.'._LOG_DEBUG);
540
+    if (!$d) {
541
+        return $mem[$d] = time();
542
+    }
543
+
544
+    // une pile plus grosse n'accelere pas le calcul
545
+    return $mem[$d] = strtotime($d);
546 546
 }
547 547
 
548 548
 
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
  * @return string
556 556
  */
557 557
 function _sqlite_func_year($d) {
558
-	return _sqlite_func_date('Y', $d);
558
+    return _sqlite_func_date('Y', $d);
559 559
 }
560 560
 
561 561
 /**
@@ -568,20 +568,20 @@  discard block
 block discarded – undo
568 568
  * @return string
569 569
  */
570 570
 function _sqlite_func_date($quoi, $d) {
571
-	static $mem = [];
572
-	static $n = 0;
573
-	if (isset($mem[$d])) {
574
-		return $mem[$d][$quoi];
575
-	}
576
-	if ($n++ > 100) {
577
-		$mem = [];
578
-		$n = 0;
579
-	}
580
-
581
-	$dec = date('Y-m-d', _sqlite_func_unix_timestamp($d));
582
-	$mem[$d] = ['Y' => substr($dec, 0, 4), 'm' => substr($dec, 5, 2), 'd' => substr($dec, 8, 2)];
583
-
584
-	return $mem[$d][$quoi];
571
+    static $mem = [];
572
+    static $n = 0;
573
+    if (isset($mem[$d])) {
574
+        return $mem[$d][$quoi];
575
+    }
576
+    if ($n++ > 100) {
577
+        $mem = [];
578
+        $n = 0;
579
+    }
580
+
581
+    $dec = date('Y-m-d', _sqlite_func_unix_timestamp($d));
582
+    $mem[$d] = ['Y' => substr($dec, 0, 4), 'm' => substr($dec, 5, 2), 'd' => substr($dec, 8, 2)];
583
+
584
+    return $mem[$d][$quoi];
585 585
 }
586 586
 
587 587
 /**
@@ -590,5 +590,5 @@  discard block
 block discarded – undo
590 590
  * @return void
591 591
  */
592 592
 function _sqlite_func_vide() {
593
-	return;
593
+    return;
594 594
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
  */
334 334
 function _sqlite_func_preg_replace($quoi, $cherche, $remplace) {
335 335
 	#spip_log("preg_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG);
336
-	return preg_replace('%' . $cherche . '%', $remplace, $quoi);
336
+	return preg_replace('%'.$cherche.'%', $remplace, $quoi);
337 337
 }
338 338
 
339 339
 /**
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
 	$u = $GLOBALS['meta']['pcre_u'] ?? 'u';
396 396
 
397 397
 	#spip_log("regexp_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG);
398
-	return preg_match('%' . $cherche . '%imsS' . $u, $quoi);
398
+	return preg_match('%'.$cherche.'%imsS'.$u, $quoi);
399 399
 }
400 400
 
401 401
 
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
 		$count = 0;
445 445
 		str_replace($mysql_to_strftime_not_ok, '', $conv, $count);
446 446
 		if ($count > 0) {
447
-			spip_log("DATE_FORMAT : At least one parameter can't be parsed by strftime with format '$conv'", 'sqlite.' . _LOG_ERREUR);
447
+			spip_log("DATE_FORMAT : At least one parameter can't be parsed by strftime with format '$conv'", 'sqlite.'._LOG_ERREUR);
448 448
 		}
449 449
 		$to_strftime[$conv] = str_replace(array_keys($mysql_to_strftime), $mysql_to_strftime, $conv);
450 450
 	}
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
  */
464 464
 function _sqlite_func_to_days($d) {
465 465
 	static $offset = 719528; // nb de jour entre 0000-00-00 et timestamp 0=1970-01-01
466
-	$result = $offset + (int)ceil(_sqlite_func_unix_timestamp($d) / (24 * 3600));
466
+	$result = $offset + (int) ceil(_sqlite_func_unix_timestamp($d) / (24 * 3600));
467 467
 
468 468
 	#spip_log("Passage avec TO_DAYS : $d, $result",'sqlite.'._LOG_DEBUG);
469 469
 	return $result;
Please login to merge, or discard this patch.
ecrire/inc/filtres_selecteur_generique.php 3 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 		$type = reset($objets);
160 160
 		$type = objet_type($type);
161 161
 		$id = (int) $ref;
162
-		$ref = $type . $ref;
162
+		$ref = $type.$ref;
163 163
 	}
164 164
 	else {
165 165
 		// Si la référence ne correspond à rien, c'est fini
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 			return json_export(false);
168 168
 		}
169 169
 		// Sinon on récupère les infos utiles
170
-		[$type, , $id, , , , ] = array_pad($match, 7, null);
170
+		[$type,, $id,,,,] = array_pad($match, 7, null);
171 171
 
172 172
 		// On regarde si le type trouvé fait partie des objets sélectionnables
173 173
 		if (!in_array(table_objet($type), $objets)) {
@@ -213,8 +213,8 @@  discard block
 block discarded – undo
213 213
 		$types = (is_array($types) ? array_filter($types) : []);
214 214
 
215 215
 		// recuperer tous les freres et soeurs de la rubrique visee
216
-		$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique);
217
-		$fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent);
216
+		$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique='.(int) $id_rubrique);
217
+		$fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent='.(int) $id_parent);
218 218
 		$fratrie = array_column($fratrie, 'id_rubrique');
219 219
 		$has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie));
220 220
 		$has = array_column($has, 'id_parent');
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -160,8 +160,7 @@
 block discarded – undo
160 160
 		$type = objet_type($type);
161 161
 		$id = (int) $ref;
162 162
 		$ref = $type . $ref;
163
-	}
164
-	else {
163
+	} else {
165 164
 		// Si la référence ne correspond à rien, c'est fini
166 165
 		if (!($match = typer_raccourci($ref))) {
167 166
 			return json_export(false);
Please login to merge, or discard this patch.
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  **/
8 8
 
9 9
 if (!defined('_ECRIRE_INC_VERSION')) {
10
-	return;
10
+    return;
11 11
 }
12 12
 
13 13
 /**
@@ -28,49 +28,49 @@  discard block
 block discarded – undo
28 28
  *     - afficher : tableau des objets à afficher (mais pas forcément sélectionnables)
29 29
  */
30 30
 function selecteur_lister_objets($includelist = [], $excludelist = []) {
31
-	static $liste_selecteurs, $liste_parents;
32
-
33
-	if (!$liste_selecteurs) {
34
-		$liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$');
35
-	}
36
-	$objets_selectionner = [];
37
-	foreach ($liste_selecteurs as $fichier => $chemin) {
38
-		$objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', (string) $fichier);
39
-	}
40
-
41
-	// S'il y a une whitelist on ne garde que ce qui est dedans
42
-	if (!empty($includelist)) {
43
-		$includelist = array_map('table_objet', $includelist);
44
-		$objets_selectionner = array_intersect($objets_selectionner, $includelist);
45
-	}
46
-	// On supprime ce qui est dans la liste d’exclusion
47
-	$excludelist = array_map('table_objet', $excludelist);
48
-	// On enlève toujours la racine
49
-	$excludelist[] = 'racine';
50
-	$objets_selectionner = array_diff($objets_selectionner, $excludelist);
51
-
52
-	// Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner
53
-	$objets_afficher = $objets_selectionner;
54
-
55
-	// Il faut alors chercher d'éventuels parents obligatoires en plus :
56
-	// lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules"
57
-	if (!$liste_parents) {
58
-		$liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$');
59
-	}
60
-	foreach ($liste_parents as $fichier => $chemin) {
61
-		preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', (string) $fichier, $captures);
62
-		$parent = $captures[1];
63
-		$type = $captures[2];
64
-		// Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage
65
-		if (in_array($type, $objets_afficher)) {
66
-			$objets_afficher[] = $parent;
67
-		}
68
-	}
69
-
70
-	return [
71
-		'selectionner' => array_unique($objets_selectionner),
72
-		'afficher' => array_unique($objets_afficher),
73
-	];
31
+    static $liste_selecteurs, $liste_parents;
32
+
33
+    if (!$liste_selecteurs) {
34
+        $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$');
35
+    }
36
+    $objets_selectionner = [];
37
+    foreach ($liste_selecteurs as $fichier => $chemin) {
38
+        $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', (string) $fichier);
39
+    }
40
+
41
+    // S'il y a une whitelist on ne garde que ce qui est dedans
42
+    if (!empty($includelist)) {
43
+        $includelist = array_map('table_objet', $includelist);
44
+        $objets_selectionner = array_intersect($objets_selectionner, $includelist);
45
+    }
46
+    // On supprime ce qui est dans la liste d’exclusion
47
+    $excludelist = array_map('table_objet', $excludelist);
48
+    // On enlève toujours la racine
49
+    $excludelist[] = 'racine';
50
+    $objets_selectionner = array_diff($objets_selectionner, $excludelist);
51
+
52
+    // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner
53
+    $objets_afficher = $objets_selectionner;
54
+
55
+    // Il faut alors chercher d'éventuels parents obligatoires en plus :
56
+    // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules"
57
+    if (!$liste_parents) {
58
+        $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$');
59
+    }
60
+    foreach ($liste_parents as $fichier => $chemin) {
61
+        preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', (string) $fichier, $captures);
62
+        $parent = $captures[1];
63
+        $type = $captures[2];
64
+        // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage
65
+        if (in_array($type, $objets_afficher)) {
66
+            $objets_afficher[] = $parent;
67
+        }
68
+    }
69
+
70
+    return [
71
+        'selectionner' => array_unique($objets_selectionner),
72
+        'afficher' => array_unique($objets_afficher),
73
+    ];
74 74
 }
75 75
 
76 76
 /**
@@ -97,31 +97,31 @@  discard block
 block discarded – undo
97 97
  *     liste des couples (objets => id_objet) ou liste des identifiants d'un type d'objet.
98 98
  **/
99 99
 function picker_selected($selected, $type = '') {
100
-	$select = [];
101
-	$type = preg_replace(',\W,', '', $type);
102
-
103
-	if ($selected && !is_array($selected)) {
104
-		$selected = explode(',', $selected);
105
-	}
106
-
107
-	if (is_array($selected)) {
108
-		foreach ($selected as $value) {
109
-			// Si c'est le bon format déjà
110
-			if (preg_match('/^([\w]+)[|](\d+)$/', (string) $value, $captures)) {
111
-				$objet = $captures[1];
112
-				$id_objet = (int) $captures[2];
113
-
114
-				// Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants
115
-				if (is_string($type) && $type == $objet && ($id_objet || in_array($objet, ['racine', 'rubrique']))) {
116
-					$select[] = $id_objet;
117
-				} elseif (!$type && ($id_objet || in_array($objet, ['racine', 'rubrique']))) {
118
-					$select[] = ['objet' => $objet, 'id_objet' => $id_objet];
119
-				}
120
-			}
121
-		}
122
-	}
123
-
124
-	return $select;
100
+    $select = [];
101
+    $type = preg_replace(',\W,', '', $type);
102
+
103
+    if ($selected && !is_array($selected)) {
104
+        $selected = explode(',', $selected);
105
+    }
106
+
107
+    if (is_array($selected)) {
108
+        foreach ($selected as $value) {
109
+            // Si c'est le bon format déjà
110
+            if (preg_match('/^([\w]+)[|](\d+)$/', (string) $value, $captures)) {
111
+                $objet = $captures[1];
112
+                $id_objet = (int) $captures[2];
113
+
114
+                // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants
115
+                if (is_string($type) && $type == $objet && ($id_objet || in_array($objet, ['racine', 'rubrique']))) {
116
+                    $select[] = $id_objet;
117
+                } elseif (!$type && ($id_objet || in_array($objet, ['racine', 'rubrique']))) {
118
+                    $select[] = ['objet' => $objet, 'id_objet' => $id_objet];
119
+                }
120
+            }
121
+        }
122
+    }
123
+
124
+    return $select;
125 125
 }
126 126
 
127 127
 /**
@@ -138,53 +138,53 @@  discard block
 block discarded – undo
138 138
  *     Booléen indiquant si les articles sont sélectionnables
139 139
  */
140 140
 function picker_identifie_id_rapide($ref, $rubriques_ou_objets = false, $articles = false) {
141
-	include_spip('inc/json');
142
-	include_spip('inc/lien');
143
-
144
-	// On construit un tableau des objets sélectionnables suivant les paramètres
145
-	$objets = [];
146
-	if ($rubriques_ou_objets && is_array($rubriques_ou_objets)) {
147
-		$objets = $rubriques_ou_objets;
148
-	} else {
149
-		if ($rubriques_ou_objets) {
150
-			$objets[] = 'rubriques';
151
-		}
152
-		if ($articles) {
153
-			$objets[] = 'articles';
154
-		}
155
-	}
156
-
157
-	// si id numerique et un seul objet possible, pas d'ambiguite
158
-	if (is_numeric($ref) && count($objets) === 1) {
159
-		$type = reset($objets);
160
-		$type = objet_type($type);
161
-		$id = (int) $ref;
162
-		$ref = $type . $ref;
163
-	}
164
-	else {
165
-		// Si la référence ne correspond à rien, c'est fini
166
-		if (!($match = typer_raccourci($ref))) {
167
-			return json_export(false);
168
-		}
169
-		// Sinon on récupère les infos utiles
170
-		[$type, , $id, , , , ] = array_pad($match, 7, null);
171
-
172
-		// On regarde si le type trouvé fait partie des objets sélectionnables
173
-		if (!in_array(table_objet($type), $objets)) {
174
-			return json_export(false);
175
-		}
176
-	}
177
-
178
-	// Maintenant que tout est bon, on cherche les informations sur cet objet
179
-	include_spip('inc/filtres');
180
-	if (!$titre = generer_objet_info($id, $type, 'titre')) {
181
-		return json_export(false);
182
-	}
183
-
184
-	// On simplifie le texte
185
-	$titre = attribut_html($titre);
186
-
187
-	return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]);
141
+    include_spip('inc/json');
142
+    include_spip('inc/lien');
143
+
144
+    // On construit un tableau des objets sélectionnables suivant les paramètres
145
+    $objets = [];
146
+    if ($rubriques_ou_objets && is_array($rubriques_ou_objets)) {
147
+        $objets = $rubriques_ou_objets;
148
+    } else {
149
+        if ($rubriques_ou_objets) {
150
+            $objets[] = 'rubriques';
151
+        }
152
+        if ($articles) {
153
+            $objets[] = 'articles';
154
+        }
155
+    }
156
+
157
+    // si id numerique et un seul objet possible, pas d'ambiguite
158
+    if (is_numeric($ref) && count($objets) === 1) {
159
+        $type = reset($objets);
160
+        $type = objet_type($type);
161
+        $id = (int) $ref;
162
+        $ref = $type . $ref;
163
+    }
164
+    else {
165
+        // Si la référence ne correspond à rien, c'est fini
166
+        if (!($match = typer_raccourci($ref))) {
167
+            return json_export(false);
168
+        }
169
+        // Sinon on récupère les infos utiles
170
+        [$type, , $id, , , , ] = array_pad($match, 7, null);
171
+
172
+        // On regarde si le type trouvé fait partie des objets sélectionnables
173
+        if (!in_array(table_objet($type), $objets)) {
174
+            return json_export(false);
175
+        }
176
+    }
177
+
178
+    // Maintenant que tout est bon, on cherche les informations sur cet objet
179
+    include_spip('inc/filtres');
180
+    if (!$titre = generer_objet_info($id, $type, 'titre')) {
181
+        return json_export(false);
182
+    }
183
+
184
+    // On simplifie le texte
185
+    $titre = attribut_html($titre);
186
+
187
+    return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]);
188 188
 }
189 189
 
190 190
 /**
@@ -207,34 +207,34 @@  discard block
 block discarded – undo
207 207
  *     Comme le filtre `oui` : espace (` `) si rubrique à afficher, chaîne vide sinon.
208 208
  */
209 209
 function test_enfants_rubrique($id_rubrique, $types = []) {
210
-	static $has_child = [];
211
-
212
-	if (!isset($has_child[$id_rubrique])) {
213
-		$types = (is_array($types) ? array_filter($types) : []);
214
-
215
-		// recuperer tous les freres et soeurs de la rubrique visee
216
-		$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique);
217
-		$fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent);
218
-		$fratrie = array_column($fratrie, 'id_rubrique');
219
-		$has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie));
220
-		$has = array_column($has, 'id_parent');
221
-		$fratrie = array_diff($fratrie, $has);
222
-
223
-		while (count($fratrie) && is_array($types) && count($types)) {
224
-			$type = array_shift($types);
225
-			$h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie));
226
-			$h = array_column($h, 'id_rubrique');
227
-			$has = [...$has, ...$h];
228
-			$fratrie = array_diff($fratrie, $h);
229
-		}
230
-
231
-		if ($has !== []) {
232
-			$has_child += array_combine($has, array_pad([], count($has), true));
233
-		}
234
-		if ($fratrie !== []) {
235
-			$has_child += array_combine($fratrie, array_pad([], count($fratrie), false));
236
-		}
237
-	}
238
-
239
-	return $has_child[$id_rubrique] ? ' ' : '';
210
+    static $has_child = [];
211
+
212
+    if (!isset($has_child[$id_rubrique])) {
213
+        $types = (is_array($types) ? array_filter($types) : []);
214
+
215
+        // recuperer tous les freres et soeurs de la rubrique visee
216
+        $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique);
217
+        $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent);
218
+        $fratrie = array_column($fratrie, 'id_rubrique');
219
+        $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie));
220
+        $has = array_column($has, 'id_parent');
221
+        $fratrie = array_diff($fratrie, $has);
222
+
223
+        while (count($fratrie) && is_array($types) && count($types)) {
224
+            $type = array_shift($types);
225
+            $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie));
226
+            $h = array_column($h, 'id_rubrique');
227
+            $has = [...$has, ...$h];
228
+            $fratrie = array_diff($fratrie, $h);
229
+        }
230
+
231
+        if ($has !== []) {
232
+            $has_child += array_combine($has, array_pad([], count($has), true));
233
+        }
234
+        if ($fratrie !== []) {
235
+            $has_child += array_combine($fratrie, array_pad([], count($fratrie), false));
236
+        }
237
+    }
238
+
239
+    return $has_child[$id_rubrique] ? ' ' : '';
240 240
 }
Please login to merge, or discard this patch.
ecrire/inc/genie.php 1 patch
Indentation   +89 added lines, -89 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
 /**
@@ -74,28 +74,28 @@  discard block
 block discarded – undo
74 74
  * @return
75 75
  **/
76 76
 function inc_genie_dist($taches = []) {
77
-	include_spip('inc/queue');
78
-
79
-	if (_request('exec') == 'job_queue') {
80
-		return false;
81
-	}
82
-
83
-	$force_jobs = [];
84
-	// l'ancienne facon de lancer une tache cron immediatement
85
-	// etait de la passer en parametre a ing_genie_dist
86
-	// on reroute en ajoutant simplement le job a la queue, ASAP
87
-	foreach ($taches as $function => $period) {
88
-		$force_jobs[] = queue_add_job(
89
-			$function,
90
-			_T('tache_cron_asap', ['function' => $function]),
91
-			[time() - abs($period)],
92
-			'genie/'
93
-		);
94
-	}
95
-
96
-	// et on passe la main a la gestion de la queue !
97
-	// en forcant eventuellement les jobs ajoute a l'instant
98
-	return queue_schedule(count($force_jobs) ? $force_jobs : null);
77
+    include_spip('inc/queue');
78
+
79
+    if (_request('exec') == 'job_queue') {
80
+        return false;
81
+    }
82
+
83
+    $force_jobs = [];
84
+    // l'ancienne facon de lancer une tache cron immediatement
85
+    // etait de la passer en parametre a ing_genie_dist
86
+    // on reroute en ajoutant simplement le job a la queue, ASAP
87
+    foreach ($taches as $function => $period) {
88
+        $force_jobs[] = queue_add_job(
89
+            $function,
90
+            _T('tache_cron_asap', ['function' => $function]),
91
+            [time() - abs($period)],
92
+            'genie/'
93
+        );
94
+    }
95
+
96
+    // et on passe la main a la gestion de la queue !
97
+    // en forcant eventuellement les jobs ajoute a l'instant
98
+    return queue_schedule(count($force_jobs) ? $force_jobs : null);
99 99
 }
100 100
 
101 101
 //
@@ -108,34 +108,34 @@  discard block
 block discarded – undo
108 108
 //
109 109
 function taches_generales($taches_generales = []) {
110 110
 
111
-	// verifier que toutes les taches cron sont planifiees
112
-	// c'est une tache cron !
113
-	$taches_generales['queue_watch'] = 3600 * 24;
111
+    // verifier que toutes les taches cron sont planifiees
112
+    // c'est une tache cron !
113
+    $taches_generales['queue_watch'] = 3600 * 24;
114 114
 
115
-	// MAJ des rubriques publiques (cas de la publication post-datee)
116
-	// est fait au coup par coup a present
117
-	//	$taches_generales['rubriques'] = 3600;
115
+    // MAJ des rubriques publiques (cas de la publication post-datee)
116
+    // est fait au coup par coup a present
117
+    //	$taches_generales['rubriques'] = 3600;
118 118
 
119
-	// Optimisation de la base
120
-	$taches_generales['optimiser'] = 3600 * 48;
119
+    // Optimisation de la base
120
+    $taches_generales['optimiser'] = 3600 * 48;
121 121
 
122
-	// nouveautes
123
-	if (
124
-		isset($GLOBALS['meta']['adresse_neuf'])
125
-		&& $GLOBALS['meta']['adresse_neuf']
126
-		&& $GLOBALS['meta']['jours_neuf']
127
-		&& $GLOBALS['meta']['quoi_de_neuf'] == 'oui'
128
-	) {
129
-		$taches_generales['mail'] = 3600 * 24 * $GLOBALS['meta']['jours_neuf'];
130
-	}
122
+    // nouveautes
123
+    if (
124
+        isset($GLOBALS['meta']['adresse_neuf'])
125
+        && $GLOBALS['meta']['adresse_neuf']
126
+        && $GLOBALS['meta']['jours_neuf']
127
+        && $GLOBALS['meta']['quoi_de_neuf'] == 'oui'
128
+    ) {
129
+        $taches_generales['mail'] = 3600 * 24 * $GLOBALS['meta']['jours_neuf'];
130
+    }
131 131
 
132
-	// maintenance (ajax, verifications diverses)
133
-	$taches_generales['maintenance'] = 3600 * 2;
132
+    // maintenance (ajax, verifications diverses)
133
+    $taches_generales['maintenance'] = 3600 * 2;
134 134
 
135
-	// verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement)
136
-	$taches_generales['mise_a_jour'] = 3 * 24 * 3600;
135
+    // verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement)
136
+    $taches_generales['mise_a_jour'] = 3 * 24 * 3600;
137 137
 
138
-	return pipeline('taches_generales_cron', $taches_generales);
138
+    return pipeline('taches_generales_cron', $taches_generales);
139 139
 }
140 140
 
141 141
 /**
@@ -151,22 +151,22 @@  discard block
 block discarded – undo
151 151
  * @return int
152 152
  */
153 153
 function genie_queue_watch_dist() {
154
-	static $deja_la = false;
155
-	if ($deja_la) {
156
-		return;
157
-	} // re-entrance si l'insertion des jobs echoue (pas de table spip_jobs a l'upgrade par exemple)
158
-	$deja_la = true;
159
-	$taches = taches_generales();
160
-	$programmees = sql_allfetsel('fonction', 'spip_jobs', sql_in('fonction', array_keys($taches)));
161
-	$programmees = array_column($programmees, 'fonction');
162
-	foreach ($taches as $tache => $periode) {
163
-		if (!in_array($tache, $programmees)) {
164
-			queue_genie_replan_job($tache, $periode, time() - round(random_int(1, $periode)), 0);
165
-		}
166
-	}
167
-	$deja_la = false;
168
-
169
-	return 1;
154
+    static $deja_la = false;
155
+    if ($deja_la) {
156
+        return;
157
+    } // re-entrance si l'insertion des jobs echoue (pas de table spip_jobs a l'upgrade par exemple)
158
+    $deja_la = true;
159
+    $taches = taches_generales();
160
+    $programmees = sql_allfetsel('fonction', 'spip_jobs', sql_in('fonction', array_keys($taches)));
161
+    $programmees = array_column($programmees, 'fonction');
162
+    foreach ($taches as $tache => $periode) {
163
+        if (!in_array($tache, $programmees)) {
164
+            queue_genie_replan_job($tache, $periode, time() - round(random_int(1, $periode)), 0);
165
+        }
166
+    }
167
+    $deja_la = false;
168
+
169
+    return 1;
170 170
 }
171 171
 
172 172
 /**
@@ -187,32 +187,32 @@  discard block
 block discarded – undo
187 187
  * @return void
188 188
  */
189 189
 function queue_genie_replan_job($function, $period, $last = 0, $time = null, $priority = 0) {
190
-	static $done = [];
191
-	if (isset($done[$function])) {
192
-		return;
193
-	}
194
-	$done[$function] = true;
195
-	if (is_null($time)) {
196
-		$time = time();
197
-		if ($last) {
198
-			$time = max($last + $period, $time);
199
-		}
200
-	}
201
-	if (!$last) {
202
-		$last = $time - $period;
203
-	}
204
-	spip_log("replan_job $function $period $last $time $priority", 'queue');
205
-	include_spip('inc/queue');
206
-	// on replanifie un job cron
207
-	// uniquement si il n'y en a pas deja un avec le meme nom
208
-	// independament de l'argument
209
-	queue_add_job(
210
-		$function,
211
-		_T('tache_cron_secondes', ['function' => $function, 'nb' => $period]),
212
-		[$last],
213
-		'genie/',
214
-		'function_only',
215
-		$time,
216
-		$priority
217
-	);
190
+    static $done = [];
191
+    if (isset($done[$function])) {
192
+        return;
193
+    }
194
+    $done[$function] = true;
195
+    if (is_null($time)) {
196
+        $time = time();
197
+        if ($last) {
198
+            $time = max($last + $period, $time);
199
+        }
200
+    }
201
+    if (!$last) {
202
+        $last = $time - $period;
203
+    }
204
+    spip_log("replan_job $function $period $last $time $priority", 'queue');
205
+    include_spip('inc/queue');
206
+    // on replanifie un job cron
207
+    // uniquement si il n'y en a pas deja un avec le meme nom
208
+    // independament de l'argument
209
+    queue_add_job(
210
+        $function,
211
+        _T('tache_cron_secondes', ['function' => $function, 'nb' => $period]),
212
+        [$last],
213
+        'genie/',
214
+        'function_only',
215
+        $time,
216
+        $priority
217
+    );
218 218
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres_ecrire.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 		// confirmation du deplacement
117 117
 		if (
118 118
 			sql_table_exists('spip_breves')
119
-			&& ($contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . (int) $id_objet))
119
+			&& ($contient_breves = sql_countsel('spip_breves', 'id_rubrique='.(int) $id_objet))
120 120
 			&& $contient_breves > 0
121 121
 		) {
122 122
 			// FIXME: utiliser singulier_ou_pluriel, migrer dans plugin Brèves
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 			);
131 131
 			$confirm .= "\n<div class='confirmer_deplacement verdana2'>"
132 132
 				. "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>"
133
-				. $scb .
133
+				. $scb.
134 134
 				"</label></div></div>\n";
135 135
 		} else {
136 136
 			$confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n";
@@ -139,11 +139,11 @@  discard block
 block discarded – undo
139 139
 	$form .= $confirm;
140 140
 	if ($actionable) {
141 141
 		if (str_contains($form, '<select')) {
142
-			$form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>"
143
-				. '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>'
142
+			$form .= "<div style='text-align: ".$GLOBALS['spip_lang_right'].";'>"
143
+				. '<input class="fondo submit btn" type="submit" value="'._T('bouton_choisir').'"/>'
144 144
 				. '</div>';
145 145
 		}
146
-		$form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form;
146
+		$form = "<input type='hidden' name='editer_$objet' value='oui' />\n".$form;
147 147
 		if ($action = charger_fonction("editer_$objet", 'action', true)) {
148 148
 			$form = generer_action_auteur(
149 149
 				"editer_$objet",
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 
170 170
 	include_spip('inc/presentation');
171 171
 
172
-	return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur();
172
+	return debut_cadre_couleur($logo, true, '', $titre).$form.fin_cadre_couleur();
173 173
 }
174 174
 
175 175
 
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 	if ($statut == 'nouveau') {
246 246
 		if ($attente) {
247 247
 			$statut = $attente;
248
-			$plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')';
248
+			$plus = ' ('._T('info_statut_auteur_a_confirmer').')';
249 249
 		} else {
250 250
 			return _T('info_statut_auteur_a_confirmer');
251 251
 		}
@@ -258,16 +258,16 @@  discard block
 block discarded – undo
258 258
 		'5poubelle' => _T('texte_statut_poubelle'), // bouh
259 259
 	];
260 260
 	if (isset($recom[$statut])) {
261
-		return $recom[$statut] . $plus;
261
+		return $recom[$statut].$plus;
262 262
 	}
263 263
 
264 264
 	// retrouver directement par le statut sinon
265 265
 	if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) {
266 266
 		if (isset($recom[$t])) {
267
-			return $recom[$t] . $plus;
267
+			return $recom[$t].$plus;
268 268
 		}
269 269
 
270
-		return _T($t) . $plus;
270
+		return _T($t).$plus;
271 271
 	}
272 272
 
273 273
 	// si on a pas reussi a le traduire, retournons la chaine telle quelle
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
 
388 388
 	if (!$id_rubrique && defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') && _CHOIX_RUBRIQUE_PAR_DEFAUT) {
389 389
 		$in = (is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0)
390
-			? ' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique'])
390
+			? ' AND '.sql_in('id_rubrique', $GLOBALS['connect_id_rubrique'])
391 391
 			: '';
392 392
 
393 393
 		// on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
 		return '';
423 423
 	}
424 424
 
425
-	return propre('[->' . $virtuel . ']');
425
+	return propre('[->'.$virtuel.']');
426 426
 }
427 427
 
428 428
 
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
 	$clic = http_img_pack('rss-16.png', 'RSS', '', $title);
450 450
 
451 451
 	$url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true);
452
-	return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>";
452
+	return "<a style='float: ".$GLOBALS['spip_lang_right'].";' href='$url'>$clic</a>";
453 453
 }
454 454
 
455 455
 
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 	);
522 522
 
523 523
 	if ($alertes = array_filter($alertes)) {
524
-		return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" .
524
+		return "<div class='wrap-messages-alertes'><div class='messages-alertes'>".
525 525
 		implode(' | ', $alertes)
526 526
 		. '</div></div>';
527 527
 	}
@@ -557,13 +557,13 @@  discard block
 block discarded – undo
557 557
  */
558 558
 function afficher_plus_info($lien, $titre = '+', $titre_lien = '') {
559 559
 	$titre = attribut_html($titre);
560
-	$icone = "\n<a href='$lien' title='$titre' class='plus_info'>" .
561
-		http_img_pack('information-16.png', $titre) . '</a>';
560
+	$icone = "\n<a href='$lien' title='$titre' class='plus_info'>".
561
+		http_img_pack('information-16.png', $titre).'</a>';
562 562
 
563 563
 	if (!$titre_lien) {
564 564
 		return $icone;
565 565
 	} else {
566
-		return $icone . "\n<a href='$lien'>$titre_lien</a>";
566
+		return $icone."\n<a href='$lien'>$titre_lien</a>";
567 567
 	}
568 568
 }
569 569
 
Please login to merge, or discard this patch.
Indentation   +358 added lines, -358 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Filtres
16 16
  */
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 include_spip('inc/filtres_boites');
@@ -40,25 +40,25 @@  discard block
 block discarded – undo
40 40
  */
41 41
 function parametres_css_prive() {
42 42
 
43
-	$args = [];
44
-	$args['v'] = $GLOBALS['spip_version_code'];
45
-	$args['p'] = substr(md5((string) $GLOBALS['meta']['plugin']), 0, 4);
46
-	$args['themes'] = implode(',', lister_themes_prives());
47
-	$args['ltr'] = $GLOBALS['spip_lang_left'];
48
-	// un md5 des menus : si un menu change il faut maj la css
49
-	$args['md5b'] = (function_exists('md5_boutons_plugins') ? md5_boutons_plugins() : '');
43
+    $args = [];
44
+    $args['v'] = $GLOBALS['spip_version_code'];
45
+    $args['p'] = substr(md5((string) $GLOBALS['meta']['plugin']), 0, 4);
46
+    $args['themes'] = implode(',', lister_themes_prives());
47
+    $args['ltr'] = $GLOBALS['spip_lang_left'];
48
+    // un md5 des menus : si un menu change il faut maj la css
49
+    $args['md5b'] = (function_exists('md5_boutons_plugins') ? md5_boutons_plugins() : '');
50 50
 
51
-	$c = $GLOBALS['visiteur_session']['prefs']['couleur'] ?? 2;
51
+    $c = $GLOBALS['visiteur_session']['prefs']['couleur'] ?? 2;
52 52
 
53
-	$couleurs = charger_fonction('couleurs', 'inc');
54
-	parse_str((string) $couleurs($c), $c);
55
-	$args = array_merge($args, $c);
53
+    $couleurs = charger_fonction('couleurs', 'inc');
54
+    parse_str((string) $couleurs($c), $c);
55
+    $args = array_merge($args, $c);
56 56
 
57
-	if (_request('var_mode') == 'recalcul' || defined('_VAR_MODE') && _VAR_MODE == 'recalcul') {
58
-		$args['var_mode'] = 'recalcul';
59
-	}
57
+    if (_request('var_mode') == 'recalcul' || defined('_VAR_MODE') && _VAR_MODE == 'recalcul') {
58
+        $args['var_mode'] = 'recalcul';
59
+    }
60 60
 
61
-	return http_build_query($args);
61
+    return http_build_query($args);
62 62
 }
63 63
 
64 64
 
@@ -81,95 +81,95 @@  discard block
 block discarded – undo
81 81
  * @return string
82 82
  */
83 83
 function chercher_rubrique(
84
-	$titre,
85
-	$id_objet,
86
-	$id_parent,
87
-	$objet,
88
-	$id_secteur,
89
-	$restreint,
90
-	$actionable = false,
91
-	$retour_sans_cadre = false
84
+    $titre,
85
+    $id_objet,
86
+    $id_parent,
87
+    $objet,
88
+    $id_secteur,
89
+    $restreint,
90
+    $actionable = false,
91
+    $retour_sans_cadre = false
92 92
 ) {
93 93
 
94
-	include_spip('inc/autoriser');
95
-	if ((int) $id_objet && !autoriser('modifier', $objet, $id_objet)) {
96
-		return '';
97
-	}
98
-	if (!sql_countsel('spip_rubriques')) {
99
-		return '';
100
-	}
101
-	$chercher_rubrique = charger_fonction('chercher_rubrique', 'inc');
102
-	$form = $chercher_rubrique($id_parent, $objet, $restreint, ($objet == 'rubrique') ? $id_objet : 0);
103
-
104
-	if ($id_parent == 0) {
105
-		$logo = 'racine-24.png';
106
-	} elseif ($id_secteur == $id_parent) {
107
-		$logo = 'secteur-24.png';
108
-	} else {
109
-		$logo = 'rubrique-24.png';
110
-	}
111
-
112
-	$confirm = '';
113
-	if ($objet == 'rubrique') {
114
-		// FIXME: Migration plus adapté vers le plugin Brèves ?
115
-		// si c'est une rubrique-secteur contenant des breves, demander la
116
-		// confirmation du deplacement
117
-		if (
118
-			sql_table_exists('spip_breves')
119
-			&& ($contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . (int) $id_objet))
120
-			&& $contient_breves > 0
121
-		) {
122
-			// FIXME: utiliser singulier_ou_pluriel, migrer dans plugin Brèves
123
-			$scb = ($contient_breves > 1 ? 's' : '');
124
-			$scb = _T(
125
-				'avis_deplacement_rubrique',
126
-				[
127
-					'contient_breves' => $contient_breves,
128
-					'scb' => $scb
129
-				]
130
-			);
131
-			$confirm .= "\n<div class='confirmer_deplacement verdana2'>"
132
-				. "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>"
133
-				. $scb .
134
-				"</label></div></div>\n";
135
-		} else {
136
-			$confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n";
137
-		}
138
-	}
139
-	$form .= $confirm;
140
-	if ($actionable) {
141
-		if (str_contains($form, '<select')) {
142
-			$form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>"
143
-				. '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>'
144
-				. '</div>';
145
-		}
146
-		$form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form;
147
-		if ($action = charger_fonction("editer_$objet", 'action', true)) {
148
-			$form = generer_action_auteur(
149
-				"editer_$objet",
150
-				$id_objet,
151
-				self(),
152
-				$form,
153
-				" method='post' class='submit_plongeur'"
154
-			);
155
-		} else {
156
-			$form = generer_action_auteur(
157
-				'editer_objet',
158
-				"$objet/$id_objet",
159
-				self(),
160
-				$form,
161
-				" method='post' class='submit_plongeur'"
162
-			);
163
-		}
164
-	}
165
-
166
-	if ($retour_sans_cadre) {
167
-		return $form;
168
-	}
169
-
170
-	include_spip('inc/presentation');
171
-
172
-	return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur();
94
+    include_spip('inc/autoriser');
95
+    if ((int) $id_objet && !autoriser('modifier', $objet, $id_objet)) {
96
+        return '';
97
+    }
98
+    if (!sql_countsel('spip_rubriques')) {
99
+        return '';
100
+    }
101
+    $chercher_rubrique = charger_fonction('chercher_rubrique', 'inc');
102
+    $form = $chercher_rubrique($id_parent, $objet, $restreint, ($objet == 'rubrique') ? $id_objet : 0);
103
+
104
+    if ($id_parent == 0) {
105
+        $logo = 'racine-24.png';
106
+    } elseif ($id_secteur == $id_parent) {
107
+        $logo = 'secteur-24.png';
108
+    } else {
109
+        $logo = 'rubrique-24.png';
110
+    }
111
+
112
+    $confirm = '';
113
+    if ($objet == 'rubrique') {
114
+        // FIXME: Migration plus adapté vers le plugin Brèves ?
115
+        // si c'est une rubrique-secteur contenant des breves, demander la
116
+        // confirmation du deplacement
117
+        if (
118
+            sql_table_exists('spip_breves')
119
+            && ($contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . (int) $id_objet))
120
+            && $contient_breves > 0
121
+        ) {
122
+            // FIXME: utiliser singulier_ou_pluriel, migrer dans plugin Brèves
123
+            $scb = ($contient_breves > 1 ? 's' : '');
124
+            $scb = _T(
125
+                'avis_deplacement_rubrique',
126
+                [
127
+                    'contient_breves' => $contient_breves,
128
+                    'scb' => $scb
129
+                ]
130
+            );
131
+            $confirm .= "\n<div class='confirmer_deplacement verdana2'>"
132
+                . "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>"
133
+                . $scb .
134
+                "</label></div></div>\n";
135
+        } else {
136
+            $confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n";
137
+        }
138
+    }
139
+    $form .= $confirm;
140
+    if ($actionable) {
141
+        if (str_contains($form, '<select')) {
142
+            $form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>"
143
+                . '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>'
144
+                . '</div>';
145
+        }
146
+        $form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form;
147
+        if ($action = charger_fonction("editer_$objet", 'action', true)) {
148
+            $form = generer_action_auteur(
149
+                "editer_$objet",
150
+                $id_objet,
151
+                self(),
152
+                $form,
153
+                " method='post' class='submit_plongeur'"
154
+            );
155
+        } else {
156
+            $form = generer_action_auteur(
157
+                'editer_objet',
158
+                "$objet/$id_objet",
159
+                self(),
160
+                $form,
161
+                " method='post' class='submit_plongeur'"
162
+            );
163
+        }
164
+    }
165
+
166
+    if ($retour_sans_cadre) {
167
+        return $form;
168
+    }
169
+
170
+    include_spip('inc/presentation');
171
+
172
+    return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur();
173 173
 }
174 174
 
175 175
 
@@ -183,24 +183,24 @@  discard block
 block discarded – undo
183 183
  * @return bool
184 184
  */
185 185
 function avoir_visiteurs($past = false, $accepter = true) {
186
-	if ($GLOBALS['meta']['forums_publics'] == 'abo') {
187
-		return true;
188
-	}
189
-	if ($accepter && $GLOBALS['meta']['accepter_visiteurs'] != 'non') {
190
-		return true;
191
-	}
192
-	if (sql_countsel('spip_articles', "accepter_forum='abo'")) {
193
-		return true;
194
-	}
195
-	if (!$past) {
196
-		return false;
197
-	}
198
-
199
-	return sql_countsel(
200
-		'spip_auteurs',
201
-		"statut NOT IN ('0minirezo','1comite', '5poubelle')
186
+    if ($GLOBALS['meta']['forums_publics'] == 'abo') {
187
+        return true;
188
+    }
189
+    if ($accepter && $GLOBALS['meta']['accepter_visiteurs'] != 'non') {
190
+        return true;
191
+    }
192
+    if (sql_countsel('spip_articles', "accepter_forum='abo'")) {
193
+        return true;
194
+    }
195
+    if (!$past) {
196
+        return false;
197
+    }
198
+
199
+    return sql_countsel(
200
+        'spip_auteurs',
201
+        "statut NOT IN ('0minirezo','1comite', '5poubelle')
202 202
 	                    AND (statut<>'nouveau' OR prefs NOT IN ('0minirezo','1comite', '5poubelle'))"
203
-	);
203
+    );
204 204
 }
205 205
 
206 206
 /**
@@ -216,18 +216,18 @@  discard block
 block discarded – undo
216 216
  * @return array
217 217
  */
218 218
 function statuts_articles_visibles($statut_auteur) {
219
-	static $auth = [];
220
-	if (!isset($auth[$statut_auteur])) {
221
-		$auth[$statut_auteur] = [];
222
-		$statuts = array_column(sql_allfetsel('distinct statut', 'spip_articles'), 'statut');
223
-		foreach ($statuts as $s) {
224
-			if (autoriser('voir', 'article', 0, ['statut' => $statut_auteur], ['statut' => $s])) {
225
-				$auth[$statut_auteur][] = $s;
226
-			}
227
-		}
228
-	}
229
-
230
-	return $auth[$statut_auteur];
219
+    static $auth = [];
220
+    if (!isset($auth[$statut_auteur])) {
221
+        $auth[$statut_auteur] = [];
222
+        $statuts = array_column(sql_allfetsel('distinct statut', 'spip_articles'), 'statut');
223
+        foreach ($statuts as $s) {
224
+            if (autoriser('voir', 'article', 0, ['statut' => $statut_auteur], ['statut' => $s])) {
225
+                $auth[$statut_auteur][] = $s;
226
+            }
227
+        }
228
+    }
229
+
230
+    return $auth[$statut_auteur];
231 231
 }
232 232
 
233 233
 /**
@@ -241,38 +241,38 @@  discard block
 block discarded – undo
241 241
  * @return string
242 242
  */
243 243
 function traduire_statut_auteur($statut, $attente = '') {
244
-	$plus = '';
245
-	if ($statut == 'nouveau') {
246
-		if ($attente) {
247
-			$statut = $attente;
248
-			$plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')';
249
-		} else {
250
-			return _T('info_statut_auteur_a_confirmer');
251
-		}
252
-	}
253
-
254
-	$recom = [
255
-		'info_administrateurs' => _T('item_administrateur_2'),
256
-		'info_redacteurs' => _T('intem_redacteur'),
257
-		'info_visiteurs' => _T('item_visiteur'),
258
-		'5poubelle' => _T('texte_statut_poubelle'), // bouh
259
-	];
260
-	if (isset($recom[$statut])) {
261
-		return $recom[$statut] . $plus;
262
-	}
263
-
264
-	// retrouver directement par le statut sinon
265
-	if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) {
266
-		if (isset($recom[$t])) {
267
-			return $recom[$t] . $plus;
268
-		}
269
-
270
-		return _T($t) . $plus;
271
-	}
272
-
273
-	// si on a pas reussi a le traduire, retournons la chaine telle quelle
274
-	// c'est toujours plus informatif que rien du tout
275
-	return $statut;
244
+    $plus = '';
245
+    if ($statut == 'nouveau') {
246
+        if ($attente) {
247
+            $statut = $attente;
248
+            $plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')';
249
+        } else {
250
+            return _T('info_statut_auteur_a_confirmer');
251
+        }
252
+    }
253
+
254
+    $recom = [
255
+        'info_administrateurs' => _T('item_administrateur_2'),
256
+        'info_redacteurs' => _T('intem_redacteur'),
257
+        'info_visiteurs' => _T('item_visiteur'),
258
+        '5poubelle' => _T('texte_statut_poubelle'), // bouh
259
+    ];
260
+    if (isset($recom[$statut])) {
261
+        return $recom[$statut] . $plus;
262
+    }
263
+
264
+    // retrouver directement par le statut sinon
265
+    if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) {
266
+        if (isset($recom[$t])) {
267
+            return $recom[$t] . $plus;
268
+        }
269
+
270
+        return _T($t) . $plus;
271
+    }
272
+
273
+    // si on a pas reussi a le traduire, retournons la chaine telle quelle
274
+    // c'est toujours plus informatif que rien du tout
275
+    return $statut;
276 276
 }
277 277
 
278 278
 /**
@@ -283,29 +283,29 @@  discard block
 block discarded – undo
283 283
  * @return string
284 284
  */
285 285
 function afficher_qui_edite($id_objet, $objet): string {
286
-	static $qui = [];
287
-	if (isset($qui[$objet][$id_objet])) {
288
-		return $qui[$objet][$id_objet];
289
-	}
290
-
291
-	include_spip('inc/config');
292
-	if (lire_config('articles_modif', 'non') === 'non') {
293
-		return $qui[$objet][$id_objet] = '';
294
-	}
295
-
296
-	include_spip('inc/drapeau_edition');
297
-	$modif = mention_qui_edite($id_objet, $objet);
298
-	if (!$modif) {
299
-		return $qui[$objet][$id_objet] = '';
300
-	}
301
-
302
-	include_spip('base/objets');
303
-	$infos = lister_tables_objets_sql(table_objet_sql($objet));
304
-	if (isset($infos['texte_signale_edition'])) {
305
-		return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif);
306
-	}
307
-
308
-	return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif);
286
+    static $qui = [];
287
+    if (isset($qui[$objet][$id_objet])) {
288
+        return $qui[$objet][$id_objet];
289
+    }
290
+
291
+    include_spip('inc/config');
292
+    if (lire_config('articles_modif', 'non') === 'non') {
293
+        return $qui[$objet][$id_objet] = '';
294
+    }
295
+
296
+    include_spip('inc/drapeau_edition');
297
+    $modif = mention_qui_edite($id_objet, $objet);
298
+    if (!$modif) {
299
+        return $qui[$objet][$id_objet] = '';
300
+    }
301
+
302
+    include_spip('base/objets');
303
+    $infos = lister_tables_objets_sql(table_objet_sql($objet));
304
+    if (isset($infos['texte_signale_edition'])) {
305
+        return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif);
306
+    }
307
+
308
+    return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif);
309 309
 }
310 310
 
311 311
 /**
@@ -323,53 +323,53 @@  discard block
 block discarded – undo
323 323
  * @return array
324 324
  */
325 325
 function auteurs_lister_statuts($quoi = 'tous', $en_base = true): array {
326
-	if (!defined('AUTEURS_MIN_REDAC')) {
327
-		define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle');
328
-	}
329
-
330
-	switch ($quoi) {
331
-		case 'redacteurs':
332
-			$statut = AUTEURS_MIN_REDAC;
333
-			$statut = explode(',', (string) $statut);
334
-			if ($en_base) {
335
-				$check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut');
336
-				$retire = array_diff($statut, $check);
337
-				$statut = array_diff($statut, $retire);
338
-			}
339
-
340
-			return array_unique($statut);
341
-
342
-		case 'visiteurs':
343
-			$statut = [];
344
-			$exclus = AUTEURS_MIN_REDAC;
345
-			$exclus = explode(',', (string) $exclus);
346
-			if (!$en_base) {
347
-				// prendre aussi les statuts de la table des status qui ne sont pas dans le define
348
-				$statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus);
349
-			}
350
-			$s_complement = array_column(
351
-				sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')),
352
-				'statut'
353
-			);
354
-
355
-			return array_unique([...$statut, ...$s_complement]);
356
-
357
-		default:
358
-		case 'tous':
359
-			$statut = array_values($GLOBALS['liste_des_statuts']);
360
-			$s_complement = array_column(
361
-				sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')),
362
-				'statut'
363
-			);
364
-			$statut = [...$statut, ...$s_complement];
365
-			if ($en_base) {
366
-				$check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut');
367
-				$retire = array_diff($statut, $check);
368
-				$statut = array_diff($statut, $retire);
369
-			}
370
-
371
-			return array_unique($statut);
372
-	}
326
+    if (!defined('AUTEURS_MIN_REDAC')) {
327
+        define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle');
328
+    }
329
+
330
+    switch ($quoi) {
331
+        case 'redacteurs':
332
+            $statut = AUTEURS_MIN_REDAC;
333
+            $statut = explode(',', (string) $statut);
334
+            if ($en_base) {
335
+                $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut');
336
+                $retire = array_diff($statut, $check);
337
+                $statut = array_diff($statut, $retire);
338
+            }
339
+
340
+            return array_unique($statut);
341
+
342
+        case 'visiteurs':
343
+            $statut = [];
344
+            $exclus = AUTEURS_MIN_REDAC;
345
+            $exclus = explode(',', (string) $exclus);
346
+            if (!$en_base) {
347
+                // prendre aussi les statuts de la table des status qui ne sont pas dans le define
348
+                $statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus);
349
+            }
350
+            $s_complement = array_column(
351
+                sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')),
352
+                'statut'
353
+            );
354
+
355
+            return array_unique([...$statut, ...$s_complement]);
356
+
357
+        default:
358
+        case 'tous':
359
+            $statut = array_values($GLOBALS['liste_des_statuts']);
360
+            $s_complement = array_column(
361
+                sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')),
362
+                'statut'
363
+            );
364
+            $statut = [...$statut, ...$s_complement];
365
+            if ($en_base) {
366
+                $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut');
367
+                $retire = array_diff($statut, $check);
368
+                $statut = array_diff($statut, $retire);
369
+            }
370
+
371
+            return array_unique($statut);
372
+    }
373 373
 }
374 374
 
375 375
 /**
@@ -385,28 +385,28 @@  discard block
 block discarded – undo
385 385
  */
386 386
 function trouver_rubrique_creer_objet($id_rubrique, $objet) {
387 387
 
388
-	if (!$id_rubrique && defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') && _CHOIX_RUBRIQUE_PAR_DEFAUT) {
389
-		$in = (is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0)
390
-			? ' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique'])
391
-			: '';
392
-
393
-		// on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement
394
-		if ($objet == 'rubrique') {
395
-			$id_rubrique = 0;
396
-		} else {
397
-			$id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1);
398
-		}
399
-
400
-		if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) {
401
-			// manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises
402
-			$res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0');
403
-			while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) {
404
-				$id_rubrique = $row_rub['id_rubrique'];
405
-			}
406
-		}
407
-	}
408
-
409
-	return $id_rubrique;
388
+    if (!$id_rubrique && defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') && _CHOIX_RUBRIQUE_PAR_DEFAUT) {
389
+        $in = (is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0)
390
+            ? ' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique'])
391
+            : '';
392
+
393
+        // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement
394
+        if ($objet == 'rubrique') {
395
+            $id_rubrique = 0;
396
+        } else {
397
+            $id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1);
398
+        }
399
+
400
+        if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) {
401
+            // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises
402
+            $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0');
403
+            while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) {
404
+                $id_rubrique = $row_rub['id_rubrique'];
405
+            }
406
+        }
407
+    }
408
+
409
+    return $id_rubrique;
410 410
 }
411 411
 
412 412
 /**
@@ -417,12 +417,12 @@  discard block
 block discarded – undo
417 417
  * @return string
418 418
  */
419 419
 function lien_article_virtuel($virtuel) {
420
-	include_spip('inc/lien');
421
-	if (!$virtuel = virtuel_redirige($virtuel)) {
422
-		return '';
423
-	}
420
+    include_spip('inc/lien');
421
+    if (!$virtuel = virtuel_redirige($virtuel)) {
422
+        return '';
423
+    }
424 424
 
425
-	return propre('[->' . $virtuel . ']');
425
+    return propre('[->' . $virtuel . ']');
426 426
 }
427 427
 
428 428
 
@@ -445,11 +445,11 @@  discard block
 block discarded – undo
445 445
  * @filtre
446 446
  */
447 447
 function bouton_spip_rss($op, $args = [], $lang = '', $title = 'RSS') {
448
-	include_spip('inc/acces');
449
-	$clic = http_img_pack('rss-16.png', 'RSS', '', $title);
448
+    include_spip('inc/acces');
449
+    $clic = http_img_pack('rss-16.png', 'RSS', '', $title);
450 450
 
451
-	$url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true);
452
-	return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>";
451
+    $url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true);
452
+    return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>";
453 453
 }
454 454
 
455 455
 
@@ -461,72 +461,72 @@  discard block
 block discarded – undo
461 461
  */
462 462
 function alertes_auteur($id_auteur): string {
463 463
 
464
-	$alertes = [];
465
-
466
-	if (
467
-		isset($GLOBALS['meta']['message_crash_tables'])
468
-		&& autoriser('detruire', null, null, $id_auteur)
469
-	) {
470
-		include_spip('genie/maintenance');
471
-		if ($msg = message_crash_tables()) {
472
-			$alertes[] = $msg;
473
-		}
474
-	}
475
-
476
-	if (
477
-		isset($GLOBALS['meta']['message_crash_plugins'])
478
-		&& $GLOBALS['meta']['message_crash_plugins']
479
-		&& autoriser('configurer', '_plugins', null, $id_auteur)
480
-		&& is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins']))
481
-	) {
482
-		$msg = implode(', ', array_map('joli_repertoire', array_keys($msg)));
483
-		$alertes[] = _T('plugins_erreur', ['plugins' => $msg]);
484
-	}
485
-
486
-	$a = $GLOBALS['meta']['message_alertes_auteurs'] ?? '';
487
-	if ($a && is_array($a = unserialize($a)) && count($a)) {
488
-		$update = false;
489
-		if (isset($a[$GLOBALS['visiteur_session']['statut']])) {
490
-			$alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]);
491
-			unset($a[$GLOBALS['visiteur_session']['statut']]);
492
-			$update = true;
493
-		}
494
-		if (isset($a[''])) {
495
-			$alertes = array_merge($alertes, $a['']);
496
-			unset($a['']);
497
-			$update = true;
498
-		}
499
-		if ($update) {
500
-			ecrire_meta('message_alertes_auteurs', serialize($a));
501
-		}
502
-	}
503
-
504
-	if (
505
-		isset($GLOBALS['meta']['plugin_erreur_activation'])
506
-		&& autoriser('configurer', '_plugins', null, $id_auteur)
507
-	) {
508
-		include_spip('inc/plugin');
509
-		$alertes[] = plugin_donne_erreurs();
510
-	}
511
-
512
-	$alertes = pipeline(
513
-		'alertes_auteur',
514
-		[
515
-			'args' => [
516
-				'id_auteur' => $id_auteur,
517
-				'exec' => _request('exec'),
518
-			],
519
-			'data' => $alertes
520
-		]
521
-	);
522
-
523
-	if ($alertes = array_filter($alertes)) {
524
-		return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" .
525
-		implode(' | ', $alertes)
526
-		. '</div></div>';
527
-	}
528
-
529
-	return '';
464
+    $alertes = [];
465
+
466
+    if (
467
+        isset($GLOBALS['meta']['message_crash_tables'])
468
+        && autoriser('detruire', null, null, $id_auteur)
469
+    ) {
470
+        include_spip('genie/maintenance');
471
+        if ($msg = message_crash_tables()) {
472
+            $alertes[] = $msg;
473
+        }
474
+    }
475
+
476
+    if (
477
+        isset($GLOBALS['meta']['message_crash_plugins'])
478
+        && $GLOBALS['meta']['message_crash_plugins']
479
+        && autoriser('configurer', '_plugins', null, $id_auteur)
480
+        && is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins']))
481
+    ) {
482
+        $msg = implode(', ', array_map('joli_repertoire', array_keys($msg)));
483
+        $alertes[] = _T('plugins_erreur', ['plugins' => $msg]);
484
+    }
485
+
486
+    $a = $GLOBALS['meta']['message_alertes_auteurs'] ?? '';
487
+    if ($a && is_array($a = unserialize($a)) && count($a)) {
488
+        $update = false;
489
+        if (isset($a[$GLOBALS['visiteur_session']['statut']])) {
490
+            $alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]);
491
+            unset($a[$GLOBALS['visiteur_session']['statut']]);
492
+            $update = true;
493
+        }
494
+        if (isset($a[''])) {
495
+            $alertes = array_merge($alertes, $a['']);
496
+            unset($a['']);
497
+            $update = true;
498
+        }
499
+        if ($update) {
500
+            ecrire_meta('message_alertes_auteurs', serialize($a));
501
+        }
502
+    }
503
+
504
+    if (
505
+        isset($GLOBALS['meta']['plugin_erreur_activation'])
506
+        && autoriser('configurer', '_plugins', null, $id_auteur)
507
+    ) {
508
+        include_spip('inc/plugin');
509
+        $alertes[] = plugin_donne_erreurs();
510
+    }
511
+
512
+    $alertes = pipeline(
513
+        'alertes_auteur',
514
+        [
515
+            'args' => [
516
+                'id_auteur' => $id_auteur,
517
+                'exec' => _request('exec'),
518
+            ],
519
+            'data' => $alertes
520
+        ]
521
+    );
522
+
523
+    if ($alertes = array_filter($alertes)) {
524
+        return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" .
525
+        implode(' | ', $alertes)
526
+        . '</div></div>';
527
+    }
528
+
529
+    return '';
530 530
 }
531 531
 
532 532
 /**
@@ -536,9 +536,9 @@  discard block
 block discarded – undo
536 536
  * @return string
537 537
  */
538 538
 function filtre_afficher_enfant_rub_dist($id_rubrique) {
539
-	include_spip('inc/presenter_enfants');
539
+    include_spip('inc/presenter_enfants');
540 540
 
541
-	return afficher_enfant_rub((int) $id_rubrique);
541
+    return afficher_enfant_rub((int) $id_rubrique);
542 542
 }
543 543
 
544 544
 /**
@@ -556,15 +556,15 @@  discard block
 block discarded – undo
556 556
  * @return string
557 557
  */
558 558
 function afficher_plus_info($lien, $titre = '+', $titre_lien = '') {
559
-	$titre = attribut_html($titre);
560
-	$icone = "\n<a href='$lien' title='$titre' class='plus_info'>" .
561
-		http_img_pack('information-16.png', $titre) . '</a>';
562
-
563
-	if (!$titre_lien) {
564
-		return $icone;
565
-	} else {
566
-		return $icone . "\n<a href='$lien'>$titre_lien</a>";
567
-	}
559
+    $titre = attribut_html($titre);
560
+    $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" .
561
+        http_img_pack('information-16.png', $titre) . '</a>';
562
+
563
+    if (!$titre_lien) {
564
+        return $icone;
565
+    } else {
566
+        return $icone . "\n<a href='$lien'>$titre_lien</a>";
567
+    }
568 568
 }
569 569
 
570 570
 
@@ -583,20 +583,20 @@  discard block
 block discarded – undo
583 583
  * @return array
584 584
  */
585 585
 function lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien) {
586
-	$res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien);
587
-	if (!(is_countable($res) ? count($res) : 0)) {
588
-		return [];
589
-	}
590
-	$r = reset($res);
591
-	$colonne_id = ($objet_source == $objet_lien ? id_table_objet($objet_source) : 'id_objet');
592
-	if (isset($r['rang_lien'])) {
593
-		$l = array_column($res, 'rang_lien', $colonne_id);
594
-		asort($l);
595
-		$l = array_keys($l);
596
-	} else {
597
-		// Si les liens qu'on cherche sont ceux de la table de lien, l'info est dans la clé de l'objet
598
-		// Sinon c'est dans "id_objet"
599
-		$l = array_column($res, $colonne_id);
600
-	}
601
-	return $l;
586
+    $res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien);
587
+    if (!(is_countable($res) ? count($res) : 0)) {
588
+        return [];
589
+    }
590
+    $r = reset($res);
591
+    $colonne_id = ($objet_source == $objet_lien ? id_table_objet($objet_source) : 'id_objet');
592
+    if (isset($r['rang_lien'])) {
593
+        $l = array_column($res, 'rang_lien', $colonne_id);
594
+        asort($l);
595
+        $l = array_keys($l);
596
+    } else {
597
+        // Si les liens qu'on cherche sont ceux de la table de lien, l'info est dans la clé de l'objet
598
+        // Sinon c'est dans "id_objet"
599
+        $l = array_column($res, $colonne_id);
600
+    }
601
+    return $l;
602 602
 }
Please login to merge, or discard this patch.