Completed
Push — master ( ad4f09...6d727b )
by cam
01:02 queued 13s
created
ecrire/action/session.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
 		&& $_SERVER['REQUEST_METHOD'] == 'POST'
38 38
 	) {
39 39
 		include_spip('inc/session');
40
-		session_set('session_' . $var, $val = _request('val'));
40
+		session_set('session_'.$var, $val = _request('val'));
41 41
 		#spip_log("autosave:$var:$val",'autosave');
42 42
 	}
43 43
 
Please login to merge, or discard this patch.
Indentation   +12 added lines, -12 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
 /**
@@ -31,16 +31,16 @@  discard block
 block discarded – undo
31 31
  *   Envoyer en réponse : json contenant toutes les variables publiques de la session
32 32
  **/
33 33
 function action_session_dist() {
34
-	if (
35
-		($var = _request('var'))
36
-		&& preg_match(',^[a-z_0-9-]+$,i', (string) $var)
37
-		&& $_SERVER['REQUEST_METHOD'] == 'POST'
38
-	) {
39
-		include_spip('inc/session');
40
-		session_set('session_' . $var, $val = _request('val'));
41
-		#spip_log("autosave:$var:$val",'autosave');
42
-	}
34
+    if (
35
+        ($var = _request('var'))
36
+        && preg_match(',^[a-z_0-9-]+$,i', (string) $var)
37
+        && $_SERVER['REQUEST_METHOD'] == 'POST'
38
+    ) {
39
+        include_spip('inc/session');
40
+        session_set('session_' . $var, $val = _request('val'));
41
+        #spip_log("autosave:$var:$val",'autosave');
42
+    }
43 43
 
44
-	# TODO: mode lecture de session ; n'afficher que ce qu'il faut
45
-	#echo json_encode($GLOBALS['visiteur_session']);
44
+    # TODO: mode lecture de session ; n'afficher que ce qu'il faut
45
+    #echo json_encode($GLOBALS['visiteur_session']);
46 46
 }
Please login to merge, or discard this patch.
ecrire/action/relancer_inscription.php 1 patch
Indentation   +18 added lines, -18 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
 /**
@@ -25,22 +25,22 @@  discard block
 block discarded – undo
25 25
  * @return void
26 26
  */
27 27
 function action_relancer_inscription_dist() {
28
-	$securiser_action = charger_fonction('securiser_action', 'inc');
29
-	$id_auteur = $securiser_action();
28
+    $securiser_action = charger_fonction('securiser_action', 'inc');
29
+    $id_auteur = $securiser_action();
30 30
 
31
-	if ((int) $id_auteur && autoriser('relancer', 'inscription')) {
32
-		$auteur = sql_fetsel('prefs, email, nom, statut', 'spip_auteurs', "id_auteur=$id_auteur");
33
-		if ($auteur['statut'] == 'nouveau') {
34
-			include_spip('action/inscrire_auteur');
35
-			action_inscrire_auteur_dist($auteur['prefs'], $auteur['email'], $auteur['nom'], ['force_nouveau' => true]);
36
-		}
37
-	} elseif ($id_auteur === '*' && autoriser('relancer', 'inscription')) {
38
-		$auteurs = sql_allfetsel('prefs, email, nom', 'spip_auteurs', "statut='nouveau'");
39
-		if (is_array($auteurs)) {
40
-			include_spip('action/inscrire_auteur');
41
-			while ($row = array_pop($auteurs)) {
42
-				action_inscrire_auteur_dist($row['prefs'], $row['email'], $row['nom'], ['force_nouveau' => true]);
43
-			}
44
-		}
45
-	}
31
+    if ((int) $id_auteur && autoriser('relancer', 'inscription')) {
32
+        $auteur = sql_fetsel('prefs, email, nom, statut', 'spip_auteurs', "id_auteur=$id_auteur");
33
+        if ($auteur['statut'] == 'nouveau') {
34
+            include_spip('action/inscrire_auteur');
35
+            action_inscrire_auteur_dist($auteur['prefs'], $auteur['email'], $auteur['nom'], ['force_nouveau' => true]);
36
+        }
37
+    } elseif ($id_auteur === '*' && autoriser('relancer', 'inscription')) {
38
+        $auteurs = sql_allfetsel('prefs, email, nom', 'spip_auteurs', "statut='nouveau'");
39
+        if (is_array($auteurs)) {
40
+            include_spip('action/inscrire_auteur');
41
+            while ($row = array_pop($auteurs)) {
42
+                action_inscrire_auteur_dist($row['prefs'], $row['email'], $row['nom'], ['force_nouveau' => true]);
43
+            }
44
+        }
45
+    }
46 46
 }
Please login to merge, or discard this patch.
ecrire/urls/page.php 2 patches
Indentation   +31 added lines, -31 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
 defined('URLS_PAGE_EXEMPLE') || define('URLS_PAGE_EXEMPLE', 'spip.php?article12');
@@ -29,23 +29,23 @@  discard block
 block discarded – undo
29 29
  */
30 30
 function urls_page_generer_url_objet_dist(int $id, string $objet, string $args = '', string $ancre = ''): string {
31 31
 
32
-	if ($generer_url_externe = charger_fonction_url($objet, 'defaut')) {
33
-		$url = $generer_url_externe($id, $args, $ancre);
34
-		// une url === null indique "je ne traite pas cette url, appliquez le calcul standard"
35
-		// une url vide est une url vide, ne rien faire de plus
36
-		if (!is_null($url)) {
37
-			return $url;
38
-		}
39
-	}
32
+    if ($generer_url_externe = charger_fonction_url($objet, 'defaut')) {
33
+        $url = $generer_url_externe($id, $args, $ancre);
34
+        // une url === null indique "je ne traite pas cette url, appliquez le calcul standard"
35
+        // une url vide est une url vide, ne rien faire de plus
36
+        if (!is_null($url)) {
37
+            return $url;
38
+        }
39
+    }
40 40
 
41
-	$url = \_debut_urls_page . $objet . \_separateur_urls_page
42
-		. $id . \_terminaison_urls_page;
41
+    $url = \_debut_urls_page . $objet . \_separateur_urls_page
42
+        . $id . \_terminaison_urls_page;
43 43
 
44
-	if ($args) {
45
-		$args = strpos($url, '?') ? "&$args" : "?$args";
46
-	}
44
+    if ($args) {
45
+        $args = strpos($url, '?') ? "&$args" : "?$args";
46
+    }
47 47
 
48
-	return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : '');
48
+    return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : '');
49 49
 }
50 50
 
51 51
 /**
@@ -61,27 +61,27 @@  discard block
 block discarded – undo
61 61
  */
62 62
 function urls_page_decoder_url_dist(string $url, string $entite, array $contexte = []): array {
63 63
 
64
-	// traiter les injections du type domaine.org/spip.php/cestnimportequoi/ou/encore/plus/rubrique23
65
-	if ($GLOBALS['profondeur_url'] > 0 && $entite == 'sommaire') {
66
-		return [[], '404'];
67
-	}
64
+    // traiter les injections du type domaine.org/spip.php/cestnimportequoi/ou/encore/plus/rubrique23
65
+    if ($GLOBALS['profondeur_url'] > 0 && $entite == 'sommaire') {
66
+        return [[], '404'];
67
+    }
68 68
 
69
-	include_spip('inc/urls');
70
-	$r = nettoyer_url_page($url, $contexte);
71
-	if ($r) {
72
-		array_pop($r); // nettoyer_url_page renvoie un argument de plus inutile ici
73
-		return $r;
74
-	}
69
+    include_spip('inc/urls');
70
+    $r = nettoyer_url_page($url, $contexte);
71
+    if ($r) {
72
+        array_pop($r); // nettoyer_url_page renvoie un argument de plus inutile ici
73
+        return $r;
74
+    }
75 75
 
76
-	/*
76
+    /*
77 77
 	 * Le bloc qui suit sert a faciliter les transitions depuis
78 78
 	 * le mode 'urls-propres' vers les modes 'urls-standard' et 'url-html'
79 79
 	 * Il est inutile de le recopier si vous personnalisez vos URLs
80 80
 	 * et votre .htaccess
81 81
 	 */
82
-	// Si on est revenu en mode html, mais c'est une ancienne url_propre
83
-	// on ne redirige pas, on assume le nouveau contexte (si possible)
84
-	$url_propre = $url ?? $_SERVER['REDIRECT_url_propre'] ?? $_ENV['url_propre'] ?? '';
85
-	return urls_transition_retrouver_anciennes_url_propres($url_propre, $entite, $contexte);
86
-	/* Fin du bloc compatibilite url-propres */
82
+    // Si on est revenu en mode html, mais c'est une ancienne url_propre
83
+    // on ne redirige pas, on assume le nouveau contexte (si possible)
84
+    $url_propre = $url ?? $_SERVER['REDIRECT_url_propre'] ?? $_ENV['url_propre'] ?? '';
85
+    return urls_transition_retrouver_anciennes_url_propres($url_propre, $entite, $contexte);
86
+    /* Fin du bloc compatibilite url-propres */
87 87
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 # attention toutefois seuls '' et '=' figurent dans les modes de compatibilite
23 23
 define('_separateur_urls_page', '');
24 24
 # on peut indiquer '' si on a installe le .htaccess
25
-define('_debut_urls_page', get_spip_script('./') . '?');
25
+define('_debut_urls_page', get_spip_script('./').'?');
26 26
 #######
27 27
 /**
28 28
  * Generer l'url d'un objet SPIP
@@ -38,14 +38,14 @@  discard block
 block discarded – undo
38 38
 		}
39 39
 	}
40 40
 
41
-	$url = \_debut_urls_page . $objet . \_separateur_urls_page
42
-		. $id . \_terminaison_urls_page;
41
+	$url = \_debut_urls_page.$objet.\_separateur_urls_page
42
+		. $id.\_terminaison_urls_page;
43 43
 
44 44
 	if ($args) {
45 45
 		$args = strpos($url, '?') ? "&$args" : "?$args";
46 46
 	}
47 47
 
48
-	return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : '');
48
+	return _DIR_RACINE.$url.$args.($ancre ? "#$ancre" : '');
49 49
 }
50 50
 
51 51
 /**
Please login to merge, or discard this patch.
ecrire/prive.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -19,18 +19,18 @@
 block discarded – undo
19 19
 $var_auth = $auth();
20 20
 
21 21
 if ($var_auth !== '' && !is_int($var_auth)) {
22
-	// si l'authentifie' n'a pas acces a l'espace de redac
23
-	// c'est qu'on voulait forcer sa reconnaissance en tant que visiteur.
24
-	// On reexecute pour deboucher sur le include public.
25
-	// autrement on insiste
26
-	if (is_array($var_auth)) {
27
-			$var_auth = '../?' . $_SERVER['QUERY_STRING'];
28
-			spip_setcookie('spip_session', $_COOKIE['spip_session'], [
29
-				'expires' => time() + 3600 * 24 * 14
30
-			]);
31
-	}
32
-	include_spip('inc/headers');
33
-	redirige_formulaire($var_auth);
22
+    // si l'authentifie' n'a pas acces a l'espace de redac
23
+    // c'est qu'on voulait forcer sa reconnaissance en tant que visiteur.
24
+    // On reexecute pour deboucher sur le include public.
25
+    // autrement on insiste
26
+    if (is_array($var_auth)) {
27
+            $var_auth = '../?' . $_SERVER['QUERY_STRING'];
28
+            spip_setcookie('spip_session', $_COOKIE['spip_session'], [
29
+                'expires' => time() + 3600 * 24 * 14
30
+            ]);
31
+    }
32
+    include_spip('inc/headers');
33
+    redirige_formulaire($var_auth);
34 34
 }
35 35
 
36 36
 // En somme, est prive' ce qui est publiquement nomme'...
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
 // Script pour appeler un squelette apres s'etre authentifie
13 13
 
14
-include_once __DIR__ . '/inc_version.php';
14
+include_once __DIR__.'/inc_version.php';
15 15
 
16 16
 include_spip('inc/cookie');
17 17
 
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	// On reexecute pour deboucher sur le include public.
25 25
 	// autrement on insiste
26 26
 	if (is_array($var_auth)) {
27
-			$var_auth = '../?' . $_SERVER['QUERY_STRING'];
27
+			$var_auth = '../?'.$_SERVER['QUERY_STRING'];
28 28
 			spip_setcookie('spip_session', $_COOKIE['spip_session'], [
29 29
 				'expires' => time() + 3600 * 24 * 14
30 30
 			]);
@@ -34,4 +34,4 @@  discard block
 block discarded – undo
34 34
 }
35 35
 
36 36
 // En somme, est prive' ce qui est publiquement nomme'...
37
-include __DIR__ . '/public.php';
37
+include __DIR__.'/public.php';
Please login to merge, or discard this patch.
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.
Indentation   +321 added lines, -321 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,8 +373,8 @@  discard block
 block discarded – undo
373 373
  * @return array
374 374
  */
375 375
 function spip_connect_ldap($serveur = '') {
376
-	include_spip('auth/ldap');
377
-	return auth_ldap_connect($serveur);
376
+    include_spip('auth/ldap');
377
+    return auth_ldap_connect($serveur);
378 378
 }
379 379
 
380 380
 /**
@@ -390,16 +390,16 @@  discard block
 block discarded – undo
390 390
  * @return string Valeur échappée.
391 391
  **/
392 392
 function _q($a): string {
393
-	if (is_numeric($a)) {
394
-		return (string) $a;
395
-	} elseif (is_array($a)) {
396
-		return implode(',', array_map('_q', $a));
397
-	} elseif (is_scalar($a)) {
398
-		return ("'" . addslashes($a) . "'");
399
-	} elseif ($a === null) {
400
-		return "''";
401
-	}
402
-	throw new \RuntimeException('Can’t use _q with ' . gettype($a));
393
+    if (is_numeric($a)) {
394
+        return (string) $a;
395
+    } elseif (is_array($a)) {
396
+        return implode(',', array_map('_q', $a));
397
+    } elseif (is_scalar($a)) {
398
+        return ("'" . addslashes($a) . "'");
399
+    } elseif ($a === null) {
400
+        return "''";
401
+    }
402
+    throw new \RuntimeException('Can’t use _q with ' . gettype($a));
403 403
 }
404 404
 
405 405
 /**
@@ -415,75 +415,75 @@  discard block
 block discarded – undo
415 415
  * @return array
416 416
  */
417 417
 function query_echappe_textes($query, $uniqid = null) {
418
-	static $codeEchappements = null;
419
-	if (is_null($codeEchappements) || $uniqid) {
420
-		if (is_null($uniqid)) {
421
-			$uniqid = uniqid();
422
-		}
423
-		$uniqid = substr(md5((string) $uniqid), 0, 4);
424
-		$codeEchappements = ['\\\\' => "\x1@#{$uniqid}#@\x1", "\\'" => "\x2@#{$uniqid}#@\x2", '\\"' => "\x3@#{$uniqid}#@\x3", '%' => "\x4@#{$uniqid}#@\x4"];
425
-	}
426
-	if ($query === null) {
427
-		return $codeEchappements;
428
-	}
429
-
430
-	// si la query contient deja des codes d'echappement on va s'emmeler les pinceaux et donc on ne touche a rien
431
-	// ce n'est pas un cas legitime
432
-	foreach ($codeEchappements as $codeEchappement) {
433
-		if (str_contains($query, (string) $codeEchappement)) {
434
-			return [$query, []];
435
-		}
436
-	}
437
-
438
-	$query_echappees = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query);
439
-	if (preg_match_all("/('[^']*')|(\"[^\"]*\")/S", $query_echappees, $textes)) {
440
-		$textes = reset($textes);
441
-
442
-		$parts = [];
443
-		$currentpos = 0;
444
-		$k = 0;
445
-		while (count($textes)) {
446
-			$part = array_shift($textes);
447
-			$nextpos = strpos($query_echappees, (string) $part, $currentpos);
448
-			// si besoin recoller ensemble les doubles '' de sqlite (echappement des ')
449
-			while (count($textes) && str_ends_with((string) $part, "'")) {
450
-				$next = reset($textes);
451
-				if (
452
-					str_starts_with((string) $next, "'")
453
-					&& strpos($query_echappees, $part . $next, $currentpos) === $nextpos
454
-				) {
455
-					$part .= array_shift($textes);
456
-				}
457
-				else {
458
-					break;
459
-				}
460
-			}
461
-			$k++;
462
-			$parts[$k] = [
463
-				'texte' => $part,
464
-				'position' => $nextpos,
465
-				'placeholder' => '%' . $k . '$s',
466
-			];
467
-			$currentpos = $nextpos + strlen((string) $part);
468
-		}
469
-
470
-		// et on replace les parts une par une en commencant par la fin
471
-		while ($k > 0) {
472
-			$query_echappees = substr_replace($query_echappees, $parts[$k]['placeholder'], $parts[$k]['position'], strlen((string) $parts[$k]['texte']));
473
-			$k--;
474
-		}
475
-		$textes = array_column($parts, 'texte');
476
-	} else {
477
-		$textes = [];
478
-	}
479
-
480
-	// si il reste des quotes simples ou doubles, c'est qu'on s'est emmelle les pinceaux
481
-	// dans le doute on ne touche a rien
482
-	if (strpbrk($query_echappees, "'\"") !== false) {
483
-		return [$query, []];
484
-	}
485
-
486
-	return [$query_echappees, $textes];
418
+    static $codeEchappements = null;
419
+    if (is_null($codeEchappements) || $uniqid) {
420
+        if (is_null($uniqid)) {
421
+            $uniqid = uniqid();
422
+        }
423
+        $uniqid = substr(md5((string) $uniqid), 0, 4);
424
+        $codeEchappements = ['\\\\' => "\x1@#{$uniqid}#@\x1", "\\'" => "\x2@#{$uniqid}#@\x2", '\\"' => "\x3@#{$uniqid}#@\x3", '%' => "\x4@#{$uniqid}#@\x4"];
425
+    }
426
+    if ($query === null) {
427
+        return $codeEchappements;
428
+    }
429
+
430
+    // si la query contient deja des codes d'echappement on va s'emmeler les pinceaux et donc on ne touche a rien
431
+    // ce n'est pas un cas legitime
432
+    foreach ($codeEchappements as $codeEchappement) {
433
+        if (str_contains($query, (string) $codeEchappement)) {
434
+            return [$query, []];
435
+        }
436
+    }
437
+
438
+    $query_echappees = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query);
439
+    if (preg_match_all("/('[^']*')|(\"[^\"]*\")/S", $query_echappees, $textes)) {
440
+        $textes = reset($textes);
441
+
442
+        $parts = [];
443
+        $currentpos = 0;
444
+        $k = 0;
445
+        while (count($textes)) {
446
+            $part = array_shift($textes);
447
+            $nextpos = strpos($query_echappees, (string) $part, $currentpos);
448
+            // si besoin recoller ensemble les doubles '' de sqlite (echappement des ')
449
+            while (count($textes) && str_ends_with((string) $part, "'")) {
450
+                $next = reset($textes);
451
+                if (
452
+                    str_starts_with((string) $next, "'")
453
+                    && strpos($query_echappees, $part . $next, $currentpos) === $nextpos
454
+                ) {
455
+                    $part .= array_shift($textes);
456
+                }
457
+                else {
458
+                    break;
459
+                }
460
+            }
461
+            $k++;
462
+            $parts[$k] = [
463
+                'texte' => $part,
464
+                'position' => $nextpos,
465
+                'placeholder' => '%' . $k . '$s',
466
+            ];
467
+            $currentpos = $nextpos + strlen((string) $part);
468
+        }
469
+
470
+        // et on replace les parts une par une en commencant par la fin
471
+        while ($k > 0) {
472
+            $query_echappees = substr_replace($query_echappees, $parts[$k]['placeholder'], $parts[$k]['position'], strlen((string) $parts[$k]['texte']));
473
+            $k--;
474
+        }
475
+        $textes = array_column($parts, 'texte');
476
+    } else {
477
+        $textes = [];
478
+    }
479
+
480
+    // si il reste des quotes simples ou doubles, c'est qu'on s'est emmelle les pinceaux
481
+    // dans le doute on ne touche a rien
482
+    if (strpbrk($query_echappees, "'\"") !== false) {
483
+        return [$query, []];
484
+    }
485
+
486
+    return [$query_echappees, $textes];
487 487
 }
488 488
 
489 489
 /**
@@ -497,14 +497,14 @@  discard block
 block discarded – undo
497 497
  * @return string
498 498
  */
499 499
 function query_reinjecte_textes($query, $textes) {
500
-	// recuperer les codes echappements
501
-	$codeEchappements = query_echappe_textes(null);
500
+    // recuperer les codes echappements
501
+    $codeEchappements = query_echappe_textes(null);
502 502
 
503
-	if (!empty($textes)) {
504
-		$query = sprintf($query, ...$textes);
505
-	}
503
+    if (!empty($textes)) {
504
+        $query = sprintf($query, ...$textes);
505
+    }
506 506
 
507
-	return str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query);
507
+    return str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query);
508 508
 }
509 509
 
510 510
 
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
  **/
524 524
 function spip_query($query, $serveur = '') {
525 525
 
526
-	$f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true);
526
+    $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true);
527 527
 
528
-	return function_exists($f) ? $f($query, $serveur) : false;
528
+    return function_exists($f) ? $f($query, $serveur) : false;
529 529
 }
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.
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.