Completed
Push — master ( fb0017...92433c )
by cam
01:14
created
ecrire/inc/log.php 2 patches
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -11,109 +11,109 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 function inc_log_dist($message, $logname = null, $logdir = null, $logsuf = null) {
18
-	static $test_repertoire = [];
19
-	static $compteur = [];
20
-	static $debugverb = ''; // pour ne pas le recalculer au reappel
21
-
22
-	if (is_null($logname) or !is_string($logname)) {
23
-		$logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip';
24
-	}
25
-	if (!isset($compteur[$logname])) {
26
-		$compteur[$logname] = 0;
27
-	}
28
-	if (
29
-		$logname != 'maj'
30
-		and defined('_MAX_LOG')
31
-		and (
32
-			$compteur[$logname]++ > _MAX_LOG
33
-			or !$GLOBALS['nombre_de_logs']
34
-			or !$GLOBALS['taille_des_logs']
35
-		)
36
-	) {
37
-		return;
38
-	}
39
-
40
-	// si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies
41
-	$logfile =
42
-		($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES))
43
-		. $logname
44
-		. ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log'));
45
-
46
-	if (!isset($test_repertoire[$d = dirname($logfile)])) {
47
-		$test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire
48
-		$test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire(
49
-			$d,
50
-			'',
51
-			false,
52
-			true
53
-		) : false));
54
-	}
55
-
56
-	// Si le repertoire défini n'existe pas, poser dans tmp/
57
-	if (!$test_repertoire[$d]) {
58
-		$logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log';
59
-	}
60
-
61
-	$rotate = 0;
62
-	$pid = '(pid ' . @getmypid() . ')';
63
-
64
-	// accepter spip_log( Array )
65
-	if (!is_string($message)) {
66
-		$message = var_export($message, true);
67
-	}
68
-
69
-	if (!$debugverb and defined('_LOG_FILELINE') and _LOG_FILELINE) {
70
-		$debug = debug_backtrace();
71
-		$l = $debug[1]['line'];
72
-		$fi = $debug[1]['file'];
73
-		if (strncmp($fi, _ROOT_RACINE, strlen(_ROOT_RACINE)) == 0) {
74
-			$fi = substr($fi, strlen(_ROOT_RACINE));
75
-		}
76
-		$fu = $debug[2]['function'] ?? '';
77
-		$debugverb = "$fi:L$l:$fu" . '():';
78
-	}
79
-
80
-	$m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' '
81
-		//distinguer les logs prives et publics dans les grep
82
-		. $debugverb
83
-		. (test_espace_prive() ? ':Pri:' : ':Pub:')
84
-		. preg_replace("/\n*$/", "\n", $message);
85
-
86
-
87
-	if (
88
-		@is_readable($logfile)
89
-		and (!$s = @filesize($logfile) or $s > $GLOBALS['taille_des_logs'] * 1024)
90
-	) {
91
-		$rotate = $GLOBALS['nombre_de_logs'];
92
-		$m .= "[-- rotate --]\n";
93
-	}
94
-
95
-	$f = @fopen($logfile, 'ab');
96
-	if ($f) {
97
-		fputs($f, (defined('_LOG_BRUT') and _LOG_BRUT) ? $m : str_replace('<', '&lt;', $m));
98
-		fclose($f);
99
-	}
100
-
101
-	if (
102
-		$rotate-- > 0
103
-		and function_exists('spip_unlink')
104
-	) {
105
-		spip_unlink($logfile . '.' . $rotate);
106
-		while ($rotate--) {
107
-			@rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1));
108
-		}
109
-	}
110
-
111
-	// Dupliquer les erreurs specifiques dans le log general
112
-	if (
113
-		defined('_FILE_LOG')
114
-		and ($logname !== _FILE_LOG)
115
-	) {
116
-		inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message);
117
-	}
118
-	$debugverb = '';
18
+    static $test_repertoire = [];
19
+    static $compteur = [];
20
+    static $debugverb = ''; // pour ne pas le recalculer au reappel
21
+
22
+    if (is_null($logname) or !is_string($logname)) {
23
+        $logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip';
24
+    }
25
+    if (!isset($compteur[$logname])) {
26
+        $compteur[$logname] = 0;
27
+    }
28
+    if (
29
+        $logname != 'maj'
30
+        and defined('_MAX_LOG')
31
+        and (
32
+            $compteur[$logname]++ > _MAX_LOG
33
+            or !$GLOBALS['nombre_de_logs']
34
+            or !$GLOBALS['taille_des_logs']
35
+        )
36
+    ) {
37
+        return;
38
+    }
39
+
40
+    // si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies
41
+    $logfile =
42
+        ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES))
43
+        . $logname
44
+        . ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log'));
45
+
46
+    if (!isset($test_repertoire[$d = dirname($logfile)])) {
47
+        $test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire
48
+        $test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire(
49
+            $d,
50
+            '',
51
+            false,
52
+            true
53
+        ) : false));
54
+    }
55
+
56
+    // Si le repertoire défini n'existe pas, poser dans tmp/
57
+    if (!$test_repertoire[$d]) {
58
+        $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log';
59
+    }
60
+
61
+    $rotate = 0;
62
+    $pid = '(pid ' . @getmypid() . ')';
63
+
64
+    // accepter spip_log( Array )
65
+    if (!is_string($message)) {
66
+        $message = var_export($message, true);
67
+    }
68
+
69
+    if (!$debugverb and defined('_LOG_FILELINE') and _LOG_FILELINE) {
70
+        $debug = debug_backtrace();
71
+        $l = $debug[1]['line'];
72
+        $fi = $debug[1]['file'];
73
+        if (strncmp($fi, _ROOT_RACINE, strlen(_ROOT_RACINE)) == 0) {
74
+            $fi = substr($fi, strlen(_ROOT_RACINE));
75
+        }
76
+        $fu = $debug[2]['function'] ?? '';
77
+        $debugverb = "$fi:L$l:$fu" . '():';
78
+    }
79
+
80
+    $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' '
81
+        //distinguer les logs prives et publics dans les grep
82
+        . $debugverb
83
+        . (test_espace_prive() ? ':Pri:' : ':Pub:')
84
+        . preg_replace("/\n*$/", "\n", $message);
85
+
86
+
87
+    if (
88
+        @is_readable($logfile)
89
+        and (!$s = @filesize($logfile) or $s > $GLOBALS['taille_des_logs'] * 1024)
90
+    ) {
91
+        $rotate = $GLOBALS['nombre_de_logs'];
92
+        $m .= "[-- rotate --]\n";
93
+    }
94
+
95
+    $f = @fopen($logfile, 'ab');
96
+    if ($f) {
97
+        fputs($f, (defined('_LOG_BRUT') and _LOG_BRUT) ? $m : str_replace('<', '&lt;', $m));
98
+        fclose($f);
99
+    }
100
+
101
+    if (
102
+        $rotate-- > 0
103
+        and function_exists('spip_unlink')
104
+    ) {
105
+        spip_unlink($logfile . '.' . $rotate);
106
+        while ($rotate--) {
107
+            @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1));
108
+        }
109
+    }
110
+
111
+    // Dupliquer les erreurs specifiques dans le log general
112
+    if (
113
+        defined('_FILE_LOG')
114
+        and ($logname !== _FILE_LOG)
115
+    ) {
116
+        inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message);
117
+    }
118
+    $debugverb = '';
119 119
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 
40 40
 	// si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies
41 41
 	$logfile =
42
-		($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES))
42
+		($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES))
43 43
 		. $logname
44 44
 		. ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log'));
45 45
 
@@ -55,11 +55,11 @@  discard block
 block discarded – undo
55 55
 
56 56
 	// Si le repertoire défini n'existe pas, poser dans tmp/
57 57
 	if (!$test_repertoire[$d]) {
58
-		$logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log';
58
+		$logfile = _DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES.$logname.'.log';
59 59
 	}
60 60
 
61 61
 	$rotate = 0;
62
-	$pid = '(pid ' . @getmypid() . ')';
62
+	$pid = '(pid '.@getmypid().')';
63 63
 
64 64
 	// accepter spip_log( Array )
65 65
 	if (!is_string($message)) {
@@ -74,10 +74,10 @@  discard block
 block discarded – undo
74 74
 			$fi = substr($fi, strlen(_ROOT_RACINE));
75 75
 		}
76 76
 		$fu = $debug[2]['function'] ?? '';
77
-		$debugverb = "$fi:L$l:$fu" . '():';
77
+		$debugverb = "$fi:L$l:$fu".'():';
78 78
 	}
79 79
 
80
-	$m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' '
80
+	$m = date('Y-m-d H:i:s').' '.($GLOBALS['ip'] ?? '').' '.$pid.' '
81 81
 		//distinguer les logs prives et publics dans les grep
82 82
 		. $debugverb
83 83
 		. (test_espace_prive() ? ':Pri:' : ':Pub:')
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 		$rotate-- > 0
103 103
 		and function_exists('spip_unlink')
104 104
 	) {
105
-		spip_unlink($logfile . '.' . $rotate);
105
+		spip_unlink($logfile.'.'.$rotate);
106 106
 		while ($rotate--) {
107
-			@rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1));
107
+			@rename($logfile.($rotate ? '.'.$rotate : ''), $logfile.'.'.($rotate + 1));
108 108
 		}
109 109
 	}
110 110
 
Please login to merge, or discard this patch.
ecrire/inc/filtres_mini.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -45,10 +45,10 @@  discard block
 block discarded – undo
45 45
 	}
46 46
 
47 47
 	if ($query) {
48
-		$url .= '?' . $query;
48
+		$url .= '?'.$query;
49 49
 	}
50 50
 
51
-	return '/' . preg_replace(',^/,S', '', $url);
51
+	return '/'.preg_replace(',^/,S', '', $url);
52 52
 }
53 53
 
54 54
 
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) {
79 79
 		$r = array_pad($r, 3, '');
80 80
 
81
-		return $r[1] . resolve_path($r[2]);
81
+		return $r[1].resolve_path($r[2]);
82 82
 	}
83 83
 
84 84
 	# L'url site spip est un lien absolu aussi
@@ -99,13 +99,13 @@  discard block
 block discarded – undo
99 99
 	}
100 100
 	switch (substr($lien, 0, 1)) {
101 101
 		case '/':
102
-			return $debut . resolve_path($lien);
102
+			return $debut.resolve_path($lien);
103 103
 		case '#':
104
-			return $debut . resolve_path($dir . $mot . $get . $lien);
104
+			return $debut.resolve_path($dir.$mot.$get.$lien);
105 105
 		case '':
106
-			return $debut . resolve_path($dir . $mot . $get . $hash);
106
+			return $debut.resolve_path($dir.$mot.$get.$hash);
107 107
 		default:
108
-			return $debut . resolve_path($dir . $lien);
108
+			return $debut.resolve_path($dir.$lien);
109 109
 	}
110 110
 }
111 111
 
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 		return '';
134 134
 	}
135 135
 	if (!$base) {
136
-		$base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : '');
136
+		$base = url_de_base().(_DIR_RACINE ? _DIR_RESTREINT_ABS : '');
137 137
 	}
138 138
 
139 139
 	return suivre_lien($base, $url);
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
  * @param array $protocoles_autorises
157 157
  * @return bool
158 158
  */
159
-function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) {
159
+function protocole_verifier($url_absolue, $protocoles_autorises = ['http', 'https']) {
160 160
 
161 161
 	if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) {
162 162
 		$protocole = $m[1];
Please login to merge, or discard this patch.
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -35,20 +35,20 @@  discard block
 block discarded – undo
35 35
  * @return string URL nettoyée
36 36
  **/
37 37
 function resolve_path($url) {
38
-	[$url, $query] = array_pad(explode('?', $url, 2), 2, null);
39
-	while (
40
-		preg_match(',/\.?/,', $url, $regs)    # supprime // et /./
41
-		or preg_match(',/[^/]*/\.\./,S', $url, $regs)  # supprime /toto/../
42
-		or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut
43
-	) {
44
-		$url = str_replace($regs[0], '/', $url);
45
-	}
38
+    [$url, $query] = array_pad(explode('?', $url, 2), 2, null);
39
+    while (
40
+        preg_match(',/\.?/,', $url, $regs)    # supprime // et /./
41
+        or preg_match(',/[^/]*/\.\./,S', $url, $regs)  # supprime /toto/../
42
+        or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut
43
+    ) {
44
+        $url = str_replace($regs[0], '/', $url);
45
+    }
46 46
 
47
-	if ($query) {
48
-		$url .= '?' . $query;
49
-	}
47
+    if ($query) {
48
+        $url .= '?' . $query;
49
+    }
50 50
 
51
-	return '/' . preg_replace(',^/,S', '', $url);
51
+    return '/' . preg_replace(',^/,S', '', $url);
52 52
 }
53 53
 
54 54
 
@@ -69,44 +69,44 @@  discard block
 block discarded – undo
69 69
  **/
70 70
 function suivre_lien($url, $lien) {
71 71
 
72
-	$mot = null;
73
-	$get = null;
74
-	$hash = null;
75
-	if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) {
76
-		return $lien;
77
-	}
78
-	if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) {
79
-		$r = array_pad($r, 3, '');
72
+    $mot = null;
73
+    $get = null;
74
+    $hash = null;
75
+    if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) {
76
+        return $lien;
77
+    }
78
+    if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) {
79
+        $r = array_pad($r, 3, '');
80 80
 
81
-		return $r[1] . resolve_path($r[2]);
82
-	}
81
+        return $r[1] . resolve_path($r[2]);
82
+    }
83 83
 
84
-	# L'url site spip est un lien absolu aussi
85
-	if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) {
86
-		return $lien;
87
-	}
84
+    # L'url site spip est un lien absolu aussi
85
+    if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) {
86
+        return $lien;
87
+    }
88 88
 
89
-	# lien relatif, il faut verifier l'url de base
90
-	# commencer par virer la chaine de get de l'url de base
91
-	$dir = '/';
92
-	$debut = '';
93
-	if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) {
94
-		$debut = $regs[1];
95
-		$dir = !strlen($regs[2]) ? '/' : $regs[2];
96
-		$mot = $regs[3];
97
-		$get = $regs[4] ?? '';
98
-		$hash = $regs[5] ?? '';
99
-	}
100
-	switch (substr($lien, 0, 1)) {
101
-		case '/':
102
-			return $debut . resolve_path($lien);
103
-		case '#':
104
-			return $debut . resolve_path($dir . $mot . $get . $lien);
105
-		case '':
106
-			return $debut . resolve_path($dir . $mot . $get . $hash);
107
-		default:
108
-			return $debut . resolve_path($dir . $lien);
109
-	}
89
+    # lien relatif, il faut verifier l'url de base
90
+    # commencer par virer la chaine de get de l'url de base
91
+    $dir = '/';
92
+    $debut = '';
93
+    if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) {
94
+        $debut = $regs[1];
95
+        $dir = !strlen($regs[2]) ? '/' : $regs[2];
96
+        $mot = $regs[3];
97
+        $get = $regs[4] ?? '';
98
+        $hash = $regs[5] ?? '';
99
+    }
100
+    switch (substr($lien, 0, 1)) {
101
+        case '/':
102
+            return $debut . resolve_path($lien);
103
+        case '#':
104
+            return $debut . resolve_path($dir . $mot . $get . $lien);
105
+        case '':
106
+            return $debut . resolve_path($dir . $mot . $get . $hash);
107
+        default:
108
+            return $debut . resolve_path($dir . $lien);
109
+    }
110 110
 }
111 111
 
112 112
 
@@ -129,15 +129,15 @@  discard block
 block discarded – undo
129 129
  * @return string texte ou URL (en absolus)
130 130
  **/
131 131
 function url_absolue($url, $base = '') {
132
-	$url = trim((string) $url);
133
-	if (strlen($url = trim($url)) == 0) {
134
-		return '';
135
-	}
136
-	if (!$base) {
137
-		$base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : '');
138
-	}
132
+    $url = trim((string) $url);
133
+    if (strlen($url = trim($url)) == 0) {
134
+        return '';
135
+    }
136
+    if (!$base) {
137
+        $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : '');
138
+    }
139 139
 
140
-	return suivre_lien($base, $url);
140
+    return suivre_lien($base, $url);
141 141
 }
142 142
 
143 143
 /**
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
  * @return string
149 149
  */
150 150
 function protocole_implicite($url_absolue) {
151
-	return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue);
151
+    return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue);
152 152
 }
153 153
 
154 154
 /**
@@ -159,16 +159,16 @@  discard block
 block discarded – undo
159 159
  */
160 160
 function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) {
161 161
 
162
-	if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) {
163
-		$protocole = $m[1];
164
-		if (
165
-			in_array($protocole, $protocoles_autorises)
166
-			or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises))
167
-		) {
168
-			return true;
169
-		}
170
-	}
171
-	return false;
162
+    if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) {
163
+        $protocole = $m[1];
164
+        if (
165
+            in_array($protocole, $protocoles_autorises)
166
+            or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises))
167
+        ) {
168
+            return true;
169
+        }
170
+    }
171
+    return false;
172 172
 }
173 173
 
174 174
 /**
@@ -185,27 +185,27 @@  discard block
 block discarded – undo
185 185
  * @return string texte avec des URLs absolues
186 186
  **/
187 187
 function liens_absolus($texte, $base = '') {
188
-	if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) {
189
-		if (!function_exists('extraire_attribut')) {
190
-			include_spip('inc/filtres');
191
-		}
192
-		foreach ($liens as $lien) {
193
-			foreach (['href', 'src'] as $attr) {
194
-				$href = extraire_attribut($lien[0], $attr) ?? '';
195
-				if (strlen($href) > 0) {
196
-					if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) {
197
-						$abs = url_absolue($href, $base);
198
-						if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) {
199
-							$texte_lien = inserer_attribut($lien[0], $attr, $abs);
200
-							$texte = str_replace($lien[0], $texte_lien, $texte);
201
-						}
202
-					}
203
-				}
204
-			}
205
-		}
206
-	}
188
+    if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) {
189
+        if (!function_exists('extraire_attribut')) {
190
+            include_spip('inc/filtres');
191
+        }
192
+        foreach ($liens as $lien) {
193
+            foreach (['href', 'src'] as $attr) {
194
+                $href = extraire_attribut($lien[0], $attr) ?? '';
195
+                if (strlen($href) > 0) {
196
+                    if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) {
197
+                        $abs = url_absolue($href, $base);
198
+                        if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) {
199
+                            $texte_lien = inserer_attribut($lien[0], $attr, $abs);
200
+                            $texte = str_replace($lien[0], $texte_lien, $texte);
201
+                        }
202
+                    }
203
+                }
204
+            }
205
+        }
206
+    }
207 207
 
208
-	return $texte;
208
+    return $texte;
209 209
 }
210 210
 
211 211
 
@@ -221,11 +221,11 @@  discard block
 block discarded – undo
221 221
  * @return string texte ou URL (en absolus)
222 222
  **/
223 223
 function abs_url($texte, $base = '') {
224
-	if ($GLOBALS['mode_abs_url'] == 'url') {
225
-		return url_absolue($texte, $base);
226
-	} else {
227
-		return liens_absolus($texte, $base);
228
-	}
224
+    if ($GLOBALS['mode_abs_url'] == 'url') {
225
+        return url_absolue($texte, $base);
226
+    } else {
227
+        return liens_absolus($texte, $base);
228
+    }
229 229
 }
230 230
 
231 231
 /**
@@ -238,11 +238,11 @@  discard block
 block discarded – undo
238 238
  * @return string
239 239
  */
240 240
 function spip_htmlspecialchars($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) {
241
-	if (is_null($flags)) {
242
-		$flags = ENT_COMPAT | ENT_HTML401;
243
-	}
241
+    if (is_null($flags)) {
242
+        $flags = ENT_COMPAT | ENT_HTML401;
243
+    }
244 244
 
245
-	return htmlspecialchars($string, $flags, $encoding, $double_encode);
245
+    return htmlspecialchars($string, $flags, $encoding, $double_encode);
246 246
 }
247 247
 
248 248
 /**
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
  * @return string
256 256
  */
257 257
 function spip_htmlentities($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) {
258
-	if (is_null($flags)) {
259
-		$flags = ENT_COMPAT | ENT_HTML401;
260
-	}
258
+    if (is_null($flags)) {
259
+        $flags = ENT_COMPAT | ENT_HTML401;
260
+    }
261 261
 
262
-	return htmlentities($string, $flags, $encoding, $double_encode);
262
+    return htmlentities($string, $flags, $encoding, $double_encode);
263 263
 }
Please login to merge, or discard this patch.
ecrire/src/Chiffrer/Chiffrement.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -19,78 +19,78 @@
 block discarded – undo
19 19
  * @link https://www.php.net/manual/fr/book.sodium.php
20 20
  */
21 21
 class Chiffrement {
22
-	/** Chiffre un message en utilisant une clé ou un mot de passe */
23
-	public static function chiffrer(
24
-		string $message,
25
-		#[\SensitiveParameter]
26
-		string $key
27
-	): ?string {
28
-		// create a random salt for key derivation
29
-		$salt = random_bytes(SODIUM_CRYPTO_PWHASH_SALTBYTES);
30
-		$key = self::deriveKeyFromPassword($key, $salt);
31
-		$nonce = random_bytes(\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
32
-		$padded_message = sodium_pad($message, 16);
33
-		$encrypted = sodium_crypto_secretbox($padded_message, $nonce, $key);
34
-		$encoded = base64_encode($salt . $nonce . $encrypted);
35
-		sodium_memzero($key);
36
-		sodium_memzero($nonce);
37
-		sodium_memzero($salt);
38
-		#spip_log("chiffrer($message)=$encoded", 'chiffrer' . _LOG_DEBUG);
39
-		return $encoded;
40
-	}
22
+    /** Chiffre un message en utilisant une clé ou un mot de passe */
23
+    public static function chiffrer(
24
+        string $message,
25
+        #[\SensitiveParameter]
26
+        string $key
27
+    ): ?string {
28
+        // create a random salt for key derivation
29
+        $salt = random_bytes(SODIUM_CRYPTO_PWHASH_SALTBYTES);
30
+        $key = self::deriveKeyFromPassword($key, $salt);
31
+        $nonce = random_bytes(\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
32
+        $padded_message = sodium_pad($message, 16);
33
+        $encrypted = sodium_crypto_secretbox($padded_message, $nonce, $key);
34
+        $encoded = base64_encode($salt . $nonce . $encrypted);
35
+        sodium_memzero($key);
36
+        sodium_memzero($nonce);
37
+        sodium_memzero($salt);
38
+        #spip_log("chiffrer($message)=$encoded", 'chiffrer' . _LOG_DEBUG);
39
+        return $encoded;
40
+    }
41 41
 
42
-	/** Déchiffre un message en utilisant une clé ou un mot de passe */
43
-	public static function dechiffrer(
44
-		string $encoded,
45
-		#[\SensitiveParameter]
46
-		string $key
47
-	): ?string {
48
-		$decoded = base64_decode($encoded);
49
-		$salt = substr($decoded, 0, \SODIUM_CRYPTO_PWHASH_SALTBYTES);
50
-		$nonce = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES, \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
51
-		$encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES + \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
52
-		$key = self::deriveKeyFromPassword($key, $salt);
53
-		$padded_message = sodium_crypto_secretbox_open($encrypted, $nonce, $key);
54
-		sodium_memzero($key);
55
-		sodium_memzero($nonce);
56
-		sodium_memzero($salt);
57
-		if ($padded_message === false) {
58
-			spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer' . _LOG_DEBUG);
59
-			return null;
60
-		}
61
-		$message = sodium_unpad($padded_message, 16);
62
-		#spip_log("dechiffrer($encoded)=$message", 'chiffrer' . _LOG_DEBUG);
63
-		return $message;
64
-	}
42
+    /** Déchiffre un message en utilisant une clé ou un mot de passe */
43
+    public static function dechiffrer(
44
+        string $encoded,
45
+        #[\SensitiveParameter]
46
+        string $key
47
+    ): ?string {
48
+        $decoded = base64_decode($encoded);
49
+        $salt = substr($decoded, 0, \SODIUM_CRYPTO_PWHASH_SALTBYTES);
50
+        $nonce = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES, \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
51
+        $encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES + \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
52
+        $key = self::deriveKeyFromPassword($key, $salt);
53
+        $padded_message = sodium_crypto_secretbox_open($encrypted, $nonce, $key);
54
+        sodium_memzero($key);
55
+        sodium_memzero($nonce);
56
+        sodium_memzero($salt);
57
+        if ($padded_message === false) {
58
+            spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer' . _LOG_DEBUG);
59
+            return null;
60
+        }
61
+        $message = sodium_unpad($padded_message, 16);
62
+        #spip_log("dechiffrer($encoded)=$message", 'chiffrer' . _LOG_DEBUG);
63
+        return $message;
64
+    }
65 65
 
66
-	/** Génère une clé de la taille attendue pour le chiffrement */
67
-	public static function keygen(): string {
68
-		return sodium_crypto_secretbox_keygen();
69
-	}
66
+    /** Génère une clé de la taille attendue pour le chiffrement */
67
+    public static function keygen(): string {
68
+        return sodium_crypto_secretbox_keygen();
69
+    }
70 70
 
71
-	/**
72
-	 * Retourne une clé de la taille attendue pour le chiffrement
73
-	 *
74
-	 * Notamment si on utilise un mot de passe comme clé, il faut le hacher
75
-	 * pour servir de clé à la taille correspondante.
76
-	 */
77
-	private static function deriveKeyFromPassword(
78
-		#[\SensitiveParameter]
79
-		string $password,
80
-		string $salt
81
-	): string {
82
-		if (strlen($password) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
83
-			return $password;
84
-		}
85
-		$key = sodium_crypto_pwhash(
86
-			\SODIUM_CRYPTO_SECRETBOX_KEYBYTES,
87
-			$password,
88
-			$salt,
89
-			\SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
90
-			\SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
91
-		);
92
-		sodium_memzero($password);
71
+    /**
72
+     * Retourne une clé de la taille attendue pour le chiffrement
73
+     *
74
+     * Notamment si on utilise un mot de passe comme clé, il faut le hacher
75
+     * pour servir de clé à la taille correspondante.
76
+     */
77
+    private static function deriveKeyFromPassword(
78
+        #[\SensitiveParameter]
79
+        string $password,
80
+        string $salt
81
+    ): string {
82
+        if (strlen($password) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
83
+            return $password;
84
+        }
85
+        $key = sodium_crypto_pwhash(
86
+            \SODIUM_CRYPTO_SECRETBOX_KEYBYTES,
87
+            $password,
88
+            $salt,
89
+            \SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
90
+            \SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
91
+        );
92
+        sodium_memzero($password);
93 93
 
94
-		return $key;
95
-	}
94
+        return $key;
95
+    }
96 96
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 		$nonce = random_bytes(\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
32 32
 		$padded_message = sodium_pad($message, 16);
33 33
 		$encrypted = sodium_crypto_secretbox($padded_message, $nonce, $key);
34
-		$encoded = base64_encode($salt . $nonce . $encrypted);
34
+		$encoded = base64_encode($salt.$nonce.$encrypted);
35 35
 		sodium_memzero($key);
36 36
 		sodium_memzero($nonce);
37 37
 		sodium_memzero($salt);
@@ -48,14 +48,14 @@  discard block
 block discarded – undo
48 48
 		$decoded = base64_decode($encoded);
49 49
 		$salt = substr($decoded, 0, \SODIUM_CRYPTO_PWHASH_SALTBYTES);
50 50
 		$nonce = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES, \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
51
-		$encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES + \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
51
+		$encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES +\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
52 52
 		$key = self::deriveKeyFromPassword($key, $salt);
53 53
 		$padded_message = sodium_crypto_secretbox_open($encrypted, $nonce, $key);
54 54
 		sodium_memzero($key);
55 55
 		sodium_memzero($nonce);
56 56
 		sodium_memzero($salt);
57 57
 		if ($padded_message === false) {
58
-			spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer' . _LOG_DEBUG);
58
+			spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer'._LOG_DEBUG);
59 59
 			return null;
60 60
 		}
61 61
 		$message = sodium_unpad($padded_message, 16);
Please login to merge, or discard this patch.
ecrire/inc/drapeau_edition.php 1 patch
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
  * @package SPIP\Core\Drapeaux\Edition
31 31
  **/
32 32
 if (!defined('_ECRIRE_INC_VERSION')) {
33
-	return;
33
+    return;
34 34
 }
35 35
 
36 36
 
@@ -45,46 +45,46 @@  discard block
 block discarded – undo
45 45
  *     `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()`
46 46
  **/
47 47
 function lire_tableau_edition() {
48
-	$edition = @unserialize($GLOBALS['meta']['drapeau_edition']);
49
-	if (!$edition) {
50
-		return [];
51
-	}
52
-	$changed = false;
48
+    $edition = @unserialize($GLOBALS['meta']['drapeau_edition']);
49
+    if (!$edition) {
50
+        return [];
51
+    }
52
+    $changed = false;
53 53
 
54
-	$bon_pour_le_service = time() - 3600;
55
-	// parcourir le tableau et virer les vieux
56
-	foreach ($edition as $objet => $data) {
57
-		if (!is_array($data)) {
58
-			unset($edition[$objet]);
59
-		} // vieille version
60
-		else {
61
-			foreach ($data as $id => $tab) {
62
-				if (!is_array($tab)) {
63
-					unset($edition[$objet][$tab]);
64
-				} // vieille version
65
-				else {
66
-					foreach ($tab as $n => $duo) {
67
-						if (current($duo) < $bon_pour_le_service) {
68
-							unset($edition[$objet][$id][$n]);
69
-							$changed = true;
70
-						}
71
-					}
72
-				}
73
-				if (!$edition[$objet][$id]) {
74
-					unset($edition[$objet][$id]);
75
-				}
76
-			}
77
-		}
78
-		if (!$edition[$objet]) {
79
-			unset($edition[$objet]);
80
-		}
81
-	}
54
+    $bon_pour_le_service = time() - 3600;
55
+    // parcourir le tableau et virer les vieux
56
+    foreach ($edition as $objet => $data) {
57
+        if (!is_array($data)) {
58
+            unset($edition[$objet]);
59
+        } // vieille version
60
+        else {
61
+            foreach ($data as $id => $tab) {
62
+                if (!is_array($tab)) {
63
+                    unset($edition[$objet][$tab]);
64
+                } // vieille version
65
+                else {
66
+                    foreach ($tab as $n => $duo) {
67
+                        if (current($duo) < $bon_pour_le_service) {
68
+                            unset($edition[$objet][$id][$n]);
69
+                            $changed = true;
70
+                        }
71
+                    }
72
+                }
73
+                if (!$edition[$objet][$id]) {
74
+                    unset($edition[$objet][$id]);
75
+                }
76
+            }
77
+        }
78
+        if (!$edition[$objet]) {
79
+            unset($edition[$objet]);
80
+        }
81
+    }
82 82
 
83
-	if ($changed) {
84
-		ecrire_tableau_edition($edition);
85
-	}
83
+    if ($changed) {
84
+        ecrire_tableau_edition($edition);
85
+    }
86 86
 
87
-	return $edition;
87
+    return $edition;
88 88
 }
89 89
 
90 90
 /**
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
  *     `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()`
98 98
  **/
99 99
 function ecrire_tableau_edition($edition) {
100
-	ecrire_meta('drapeau_edition', serialize($edition));
100
+    ecrire_meta('drapeau_edition', serialize($edition));
101 101
 }
102 102
 
103 103
 /**
@@ -117,22 +117,22 @@  discard block
 block discarded – undo
117 117
  *     Type d'objet édité
118 118
  */
119 119
 function signale_edition($id, $auteur, $type = 'article') {
120
-	include_spip('base/objets');
121
-	include_spip('inc/filtres');
122
-	if (objet_info($type, 'editable') !== 'oui') {
123
-		return;
124
-	}
120
+    include_spip('base/objets');
121
+    include_spip('inc/filtres');
122
+    if (objet_info($type, 'editable') !== 'oui') {
123
+        return;
124
+    }
125 125
 
126
-	$edition = lire_tableau_edition();
126
+    $edition = lire_tableau_edition();
127 127
 	
128
-	$nom = $auteur['nom'] ?? $GLOBALS['ip'];
129
-	$id_a = $auteur['id_auteur'] ?? $GLOBALS['ip'];
128
+    $nom = $auteur['nom'] ?? $GLOBALS['ip'];
129
+    $id_a = $auteur['id_auteur'] ?? $GLOBALS['ip'];
130 130
 
131
-	if (!isset($edition[$type][$id]) or !is_array($edition[$type][$id])) {
132
-		$edition[$type][$id] = [];
133
-	}
134
-	$edition[$type][$id][$id_a][$nom] = time();
135
-	ecrire_tableau_edition($edition);
131
+    if (!isset($edition[$type][$id]) or !is_array($edition[$type][$id])) {
132
+        $edition[$type][$id] = [];
133
+    }
134
+    $edition[$type][$id][$id_a][$nom] = time();
135
+    ecrire_tableau_edition($edition);
136 136
 }
137 137
 
138 138
 /**
@@ -149,9 +149,9 @@  discard block
 block discarded – undo
149 149
  */
150 150
 function qui_edite($id, $type = 'article') {
151 151
 
152
-	$edition = lire_tableau_edition();
152
+    $edition = lire_tableau_edition();
153 153
 
154
-	return empty($edition[$type][$id]) ? [] : $edition[$type][$id];
154
+    return empty($edition[$type][$id]) ? [] : $edition[$type][$id];
155 155
 }
156 156
 
157 157
 /**
@@ -165,23 +165,23 @@  discard block
 block discarded – undo
165 165
  *     Liste de tableaux `['nom_auteur_modif' => x|y|z, 'date_diff' => n]`
166 166
  */
167 167
 function mention_qui_edite($id, $type = 'article'): array {
168
-	$modif = qui_edite($id, $type);
169
-	unset($modif[$GLOBALS['visiteur_session']['id_auteur']]);
168
+    $modif = qui_edite($id, $type);
169
+    unset($modif[$GLOBALS['visiteur_session']['id_auteur']]);
170 170
 
171
-	if ($modif) {
172
-		$quand = 0;
173
-		foreach ($modif as $duo) {
174
-			$auteurs[] = typo(key($duo));
175
-			$quand = max($quand, current($duo));
176
-		}
171
+    if ($modif) {
172
+        $quand = 0;
173
+        foreach ($modif as $duo) {
174
+            $auteurs[] = typo(key($duo));
175
+            $quand = max($quand, current($duo));
176
+        }
177 177
 
178
-		// format lie a la chaine de langue 'avis_article_modifie'
179
-		return [
180
-			'nom_auteur_modif' => join(' | ', $auteurs),
181
-			'date_diff' => ceil((time() - $quand) / 60)
182
-		];
183
-	}
184
-	return [];
178
+        // format lie a la chaine de langue 'avis_article_modifie'
179
+        return [
180
+            'nom_auteur_modif' => join(' | ', $auteurs),
181
+            'date_diff' => ceil((time() - $quand) / 60)
182
+        ];
183
+    }
184
+    return [];
185 185
 }
186 186
 
187 187
 /**
@@ -195,25 +195,25 @@  discard block
 block discarded – undo
195 195
  *     Liste de tableaux `['objet' => x, 'id_objet' => n]`
196 196
  */
197 197
 function liste_drapeau_edition($id_auteur) {
198
-	$edition = lire_tableau_edition();
199
-	$objets_ouverts = [];
198
+    $edition = lire_tableau_edition();
199
+    $objets_ouverts = [];
200 200
 
201
-	foreach ($edition as $objet => $data) {
202
-		foreach ($data as $id => $auteurs) {
203
-			if (
204
-				isset($auteurs[$id_auteur])
205
-				and is_array($auteurs[$id_auteur]) // precaution
206
-				and (array_pop($auteurs[$id_auteur]) > time() - 3600)
207
-			) {
208
-				$objets_ouverts[] = [
209
-					'objet' => $objet,
210
-					'id_objet' => $id,
211
-				];
212
-			}
213
-		}
214
-	}
201
+    foreach ($edition as $objet => $data) {
202
+        foreach ($data as $id => $auteurs) {
203
+            if (
204
+                isset($auteurs[$id_auteur])
205
+                and is_array($auteurs[$id_auteur]) // precaution
206
+                and (array_pop($auteurs[$id_auteur]) > time() - 3600)
207
+            ) {
208
+                $objets_ouverts[] = [
209
+                    'objet' => $objet,
210
+                    'id_objet' => $id,
211
+                ];
212
+            }
213
+        }
214
+    }
215 215
 
216
-	return $objets_ouverts;
216
+    return $objets_ouverts;
217 217
 }
218 218
 
219 219
 /**
@@ -226,15 +226,15 @@  discard block
 block discarded – undo
226 226
  * @return void
227 227
  */
228 228
 function debloquer_tous($id_auteur) {
229
-	$edition = lire_tableau_edition();
230
-	foreach ($edition as $objet => $data) {
231
-		foreach ($data as $id => $auteurs) {
232
-			if (isset($auteurs[$id_auteur])) {
233
-				unset($edition[$objet][$id][$id_auteur]);
234
-				ecrire_tableau_edition($edition);
235
-			}
236
-		}
237
-	}
229
+    $edition = lire_tableau_edition();
230
+    foreach ($edition as $objet => $data) {
231
+        foreach ($data as $id => $auteurs) {
232
+            if (isset($auteurs[$id_auteur])) {
233
+                unset($edition[$objet][$id][$id_auteur]);
234
+                ecrire_tableau_edition($edition);
235
+            }
236
+        }
237
+    }
238 238
 }
239 239
 
240 240
 /**
@@ -252,19 +252,19 @@  discard block
 block discarded – undo
252 252
  * @return void
253 253
  */
254 254
 function debloquer_edition($id_auteur, $id_objet, $type = 'article') {
255
-	$edition = lire_tableau_edition();
255
+    $edition = lire_tableau_edition();
256 256
 
257
-	foreach ($edition as $objet => $data) {
258
-		if ($objet == $type) {
259
-			foreach ($data as $id => $auteurs) {
260
-				if (
261
-					$id == $id_objet
262
-					and isset($auteurs[$id_auteur])
263
-				) {
264
-					unset($edition[$objet][$id][$id_auteur]);
265
-					ecrire_tableau_edition($edition);
266
-				}
267
-			}
268
-		}
269
-	}
257
+    foreach ($edition as $objet => $data) {
258
+        if ($objet == $type) {
259
+            foreach ($data as $id => $auteurs) {
260
+                if (
261
+                    $id == $id_objet
262
+                    and isset($auteurs[$id_auteur])
263
+                ) {
264
+                    unset($edition[$objet][$id][$id_auteur]);
265
+                    ecrire_tableau_edition($edition);
266
+                }
267
+            }
268
+        }
269
+    }
270 270
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres.php 3 patches
Braces   +10 added lines, -20 removed lines patch added patch discarded remove patch
@@ -648,8 +648,7 @@  discard block
 block discarded – undo
648 648
 			if (!$srcSize) {
649 649
 				$poids_img[$src] = filesize($src);
650 650
 			}
651
-		}
652
-		elseif (strpos($src, '<svg') !== false) {
651
+		} elseif (strpos($src, '<svg') !== false) {
653 652
 			include_spip('inc/svg');
654 653
 			if ($attrs = svg_lire_attributs($src)) {
655 654
 				[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
@@ -3507,8 +3506,7 @@  discard block
 block discarded – undo
3507 3506
 	) {
3508 3507
 		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3509 3508
 			$img_file = $variante_svg_size;
3510
-		}
3511
-		else {
3509
+		} else {
3512 3510
 			$img_file = $variante_svg_generique;
3513 3511
 		}
3514 3512
 	}
@@ -3540,8 +3538,7 @@  discard block
 block discarded – undo
3540 3538
 	}
3541 3539
 	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3542 3540
 		$img_file = chemin_image($img);
3543
-	}
3544
-	else {
3541
+	} else {
3545 3542
 		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3546 3543
 			$img_file = http_img_variante_svg_si_possible($img_file);
3547 3544
 		}
@@ -3571,11 +3568,9 @@  discard block
 block discarded – undo
3571 3568
 	}
3572 3569
 	if ($alt === false) {
3573 3570
 		$alt = '';
3574
-	}
3575
-	elseif ($alt or $alt === '') {
3571
+	} elseif ($alt or $alt === '') {
3576 3572
 		$alt = " alt='" . attribut_html($alt) . "'";
3577
-	}
3578
-	else {
3573
+	} else {
3579 3574
 		$alt = " alt='" . attribut_html($title) . "'";
3580 3575
 	}
3581 3576
 	return "<img src='" . attribut_html($img_file) . "'$alt"
@@ -3702,13 +3697,11 @@  discard block
 block discarded – undo
3702 3697
 		if (!is_null($class)) {
3703 3698
 			if (strlen($class)) {
3704 3699
 				$img = inserer_attribut($img, 'class', $class);
3705
-			}
3706
-			else {
3700
+			} else {
3707 3701
 				$img = vider_attribut($img, 'class');
3708 3702
 			}
3709 3703
 		}
3710
-	}
3711
-	else {
3704
+	} else {
3712 3705
 		$img = http_img_pack(
3713 3706
 			$img,
3714 3707
 			$alt,
@@ -3806,8 +3799,7 @@  discard block
 block discarded – undo
3806 3799
 	if (!is_null($class)) {
3807 3800
 		if (strlen($class)) {
3808 3801
 			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3809
-		}
3810
-		else {
3802
+		} else {
3811 3803
 			$balise_svg = vider_attribut($balise_svg, 'class');
3812 3804
 		}
3813 3805
 	}
@@ -3819,8 +3811,7 @@  discard block
 block discarded – undo
3819 3811
 		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3820 3812
 		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3821 3813
 		$balise_svg .= $title;
3822
-	}
3823
-	else {
3814
+	} else {
3824 3815
 		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3825 3816
 	}
3826 3817
 
@@ -5231,8 +5222,7 @@  discard block
 block discarded – undo
5231 5222
 	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5232 5223
 	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5233 5224
 		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5234
-	}
5235
-	else {
5225
+	} else {
5236 5226
 		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5237 5227
 		ksort($contexte);
5238 5228
 		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
Please login to merge, or discard this patch.
Spacing   +122 added lines, -123 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	}
97 97
 
98 98
 	include_fichiers_fonctions();
99
-	foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
99
+	foreach (['filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc] as $f) {
100 100
 		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101 101
 		if (is_callable($f)) {
102 102
 			return $f;
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 	// affichage "GIT [master: abcdef]"
232 232
 	$commit = $desc['commit_short'] ?? $desc['commit'];
233 233
 	if ($desc['branch']) {
234
-		$commit = $desc['branch'] . ': ' . $commit;
234
+		$commit = $desc['branch'].': '.$commit;
235 235
 	}
236 236
 	return "{$desc['vcs']} [$commit]";
237 237
 }
@@ -250,9 +250,9 @@  discard block
 block discarded – undo
250 250
 	}
251 251
 
252 252
 	// version installee par GIT
253
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
253
+	if (lire_fichier($dir.'/.git/HEAD', $c)) {
254 254
 		$currentHead = trim(substr($c, 4));
255
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
255
+		if (lire_fichier($dir.'/.git/'.$currentHead, $hash)) {
256 256
 			return [
257 257
 				'vcs' => 'GIT',
258 258
 				'branch' => basename($currentHead),
@@ -267,12 +267,12 @@  discard block
 block discarded – undo
267 267
 
268 268
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
269 269
 // et laisser passer les fonctions personnelles baptisees image_...
270
-$GLOBALS['spip_matrice']['image_graver'] = true;//'inc/filtres_images_mini.php';
271
-$GLOBALS['spip_matrice']['image_select'] = true;//'inc/filtres_images_mini.php';
272
-$GLOBALS['spip_matrice']['image_reduire'] = true;//'inc/filtres_images_mini.php';
273
-$GLOBALS['spip_matrice']['image_reduire_par'] = true;//'inc/filtres_images_mini.php';
274
-$GLOBALS['spip_matrice']['image_passe_partout'] = true;//'inc/filtres_images_mini.php';
275
-$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true;//'inc/filtres_images_mini.php';
270
+$GLOBALS['spip_matrice']['image_graver'] = true; //'inc/filtres_images_mini.php';
271
+$GLOBALS['spip_matrice']['image_select'] = true; //'inc/filtres_images_mini.php';
272
+$GLOBALS['spip_matrice']['image_reduire'] = true; //'inc/filtres_images_mini.php';
273
+$GLOBALS['spip_matrice']['image_reduire_par'] = true; //'inc/filtres_images_mini.php';
274
+$GLOBALS['spip_matrice']['image_passe_partout'] = true; //'inc/filtres_images_mini.php';
275
+$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true; //'inc/filtres_images_mini.php';
276 276
 
277 277
 $GLOBALS['spip_matrice']['couleur_html_to_hex'] = 'inc/filtres_images_mini.php';
278 278
 $GLOBALS['spip_matrice']['couleur_hex_to_hsl'] = 'inc/filtres_images_mini.php';
@@ -431,8 +431,8 @@  discard block
 block discarded – undo
431 431
  */
432 432
 function filtre_debug($val, $key = null) {
433 433
 	$debug = (
434
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
435
-		) . var_export($val, true);
434
+		is_null($key) ? '' : (var_export($key, true).' = ')
435
+		).var_export($val, true);
436 436
 
437 437
 	include_spip('inc/autoriser');
438 438
 	if (autoriser('webmestre')) {
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 		$is_file = false;
489 489
 	}
490 490
 	if ($is_file) {
491
-		$is_local_file = function ($path) {
491
+		$is_local_file = function($path) {
492 492
 			if (strpos($path, '?') !== false) {
493 493
 				$path = supprimer_timestamp($path);
494 494
 				// remove ?24px added by find_in_theme on .svg files
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
 					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
538 538
 						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
539 539
 							$srcover = $match[1];
540
-							$srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
540
+							$srcover_filter = $filtre("<img src='".$match[1]."' />", ...$args);
541 541
 							$srcover_filter = extraire_attribut($srcover_filter, 'src');
542 542
 							$reduit = str_replace($srcover, $srcover_filter, $reduit);
543 543
 						}
@@ -942,7 +942,7 @@  discard block
 block discarded – undo
942 942
 	// " -> &quot; et tout ce genre de choses
943 943
 	$u = $GLOBALS['meta']['pcre_u'];
944 944
 	$texte = str_replace('&nbsp;', ' ', $texte);
945
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
945
+	$texte = preg_replace('/\s{2,}/S'.$u, ' ', $texte);
946 946
 	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
947 947
 	$texte = entites_html($texte, false, false);
948 948
 	// mais bien echapper les double quotes !
@@ -1004,7 +1004,7 @@  discard block
 block discarded – undo
1004 1004
 		return '';
1005 1005
 	}
1006 1006
 	return preg_replace(
1007
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1007
+		',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S',
1008 1008
 		'',
1009 1009
 		$texte
1010 1010
 	);
@@ -1033,7 +1033,7 @@  discard block
 block discarded – undo
1033 1033
 	if (
1034 1034
 		$texte and
1035 1035
 		preg_match(
1036
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1036
+			',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S',
1037 1037
 			$texte,
1038 1038
 			$regs
1039 1039
 		)
@@ -1124,8 +1124,8 @@  discard block
 block discarded – undo
1124 1124
  **/
1125 1125
 function textebrut($texte) {
1126 1126
 	$u = $GLOBALS['meta']['pcre_u'];
1127
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1128
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1127
+	$texte = preg_replace('/\s+/S'.$u, ' ', $texte);
1128
+	$texte = preg_replace('/<(p|br)( [^>]*)?'.'>/iS', "\n\n", $texte);
1129 1129
 	$texte = preg_replace("/^\n+/", '', $texte);
1130 1130
 	$texte = preg_replace("/\n+$/", '', $texte);
1131 1131
 	$texte = preg_replace("/\n +/", "\n", $texte);
@@ -1159,7 +1159,7 @@  discard block
 block discarded – undo
1159 1159
 		)
1160 1160
 	) {
1161 1161
 		foreach ($liens[0] as $a) {
1162
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1162
+			$rel = 'noopener noreferrer '.extraire_attribut($a, 'rel');
1163 1163
 			$ablank = inserer_attribut($a, 'rel', $rel);
1164 1164
 			$ablank = inserer_attribut($ablank, 'target', '_blank');
1165 1165
 			$texte = str_replace($a, $ablank, $texte);
@@ -1184,7 +1184,7 @@  discard block
 block discarded – undo
1184 1184
 		foreach ($regs[0] as $a) {
1185 1185
 			$rel = extraire_attribut($a, 'rel') ?? '';
1186 1186
 			if (strpos($rel, 'nofollow') === false) {
1187
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1187
+				$rel = 'nofollow'.($rel ? " $rel" : '');
1188 1188
 				$anofollow = inserer_attribut($a, 'rel', $rel);
1189 1189
 				$texte = str_replace($a, $anofollow, $texte);
1190 1190
 			}
@@ -1213,7 +1213,7 @@  discard block
 block discarded – undo
1213 1213
 	$u = $GLOBALS['meta']['pcre_u'];
1214 1214
 	$texte = preg_replace('@</p>@iS', "\n", $texte);
1215 1215
 	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1216
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1216
+	$texte = preg_replace('@^\s*<br />@S'.$u, '', $texte);
1217 1217
 
1218 1218
 	return $texte;
1219 1219
 }
@@ -1244,7 +1244,7 @@  discard block
 block discarded – undo
1244 1244
 		return $texte;
1245 1245
 	}
1246 1246
 	include_spip('inc/texte');
1247
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1247
+	$tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ?
1248 1248
 		'div' : 'span';
1249 1249
 
1250 1250
 	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
@@ -1335,7 +1335,7 @@  discard block
 block discarded – undo
1335 1335
 
1336 1336
 		// Calcul de la taille et choix de l'unité
1337 1337
 		$affichage = _T(
1338
-			'spip:taille_' . $unites[$puissance] . $suffixe_item,
1338
+			'spip:taille_'.$unites[$puissance].$suffixe_item,
1339 1339
 			[
1340 1340
 				'taille' => round($octets / pow($kilo, $puissance), $precisions[$puissance])
1341 1341
 			]
@@ -1369,7 +1369,7 @@  discard block
 block discarded – undo
1369 1369
 	}
1370 1370
 	$u = $GLOBALS['meta']['pcre_u'];
1371 1371
 	if ($textebrut) {
1372
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1372
+		$texte = preg_replace([",\n,", ',\s(?=\s),msS'.$u], [' ', ''], textebrut($texte));
1373 1373
 	}
1374 1374
 	$texte = texte_backend($texte);
1375 1375
 	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
@@ -1404,7 +1404,7 @@  discard block
 block discarded – undo
1404 1404
 	# un message pour abs_url
1405 1405
 	$GLOBALS['mode_abs_url'] = 'url';
1406 1406
 	$url = trim($url);
1407
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1407
+	$r = ',^(?:'._PROTOCOLES_STD.'):?/?/?$,iS';
1408 1408
 
1409 1409
 	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1410 1410
 }
@@ -1610,7 +1610,7 @@  discard block
 block discarded – undo
1610 1610
 
1611 1611
 	$debut = '';
1612 1612
 	$suite = $texte;
1613
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1613
+	while ($t = strpos('-'.$suite, "\n", 1)) {
1614 1614
 		$debut .= substr($suite, 0, $t - 1);
1615 1615
 		$suite = substr($suite, $t);
1616 1616
 		$car = substr($suite, 0, 1);
@@ -1628,7 +1628,7 @@  discard block
 block discarded – undo
1628 1628
 			$suite = substr($suite, strlen($regs[0]));
1629 1629
 		}
1630 1630
 	}
1631
-	$texte = $debut . $suite;
1631
+	$texte = $debut.$suite;
1632 1632
 
1633 1633
 	if ($collecteurModeles) {
1634 1634
 		$texte = $collecteurModeles->retablir($texte);
@@ -1636,7 +1636,7 @@  discard block
 block discarded – undo
1636 1636
 
1637 1637
 	$texte = echappe_retour($texte);
1638 1638
 
1639
-	return $texte . $fin;
1639
+	return $texte.$fin;
1640 1640
 }
1641 1641
 
1642 1642
 
@@ -1912,7 +1912,7 @@  discard block
 block discarded – undo
1912 1912
 	if (is_array($balise)) {
1913 1913
 		array_walk(
1914 1914
 			$balise,
1915
-			function (&$a, $key, $t) {
1915
+			function(&$a, $key, $t) {
1916 1916
 				$a = extraire_attribut($a, $t);
1917 1917
 			},
1918 1918
 			$attribut
@@ -2010,14 +2010,14 @@  discard block
 block discarded – undo
2010 2010
 
2011 2011
 	if ($old !== null) {
2012 2012
 		// Remplacer l'ancien attribut du meme nom
2013
-		$balise = $r[1] . $insert . $r[5];
2013
+		$balise = $r[1].$insert.$r[5];
2014 2014
 	} else {
2015 2015
 		// preferer une balise " />" (comme <img />)
2016 2016
 		if (preg_match(',/>,', $balise)) {
2017
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2017
+			$balise = preg_replace(',\s?/>,S', $insert.' />', $balise, 1);
2018 2018
 		} // sinon une balise <a ...> ... </a>
2019 2019
 		else {
2020
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2020
+			$balise = preg_replace(',\s?>,S', $insert.'>', $balise, 1);
2021 2021
 		}
2022 2022
 	}
2023 2023
 
@@ -2075,7 +2075,7 @@  discard block
 block discarded – undo
2075 2075
 			in_array($operation, ['ajouter', 'commuter'])
2076 2076
 			and !$is_class_presente
2077 2077
 		) {
2078
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2078
+			$class_new = ltrim(rtrim($class_new ?? '').' '.$c);
2079 2079
 		} elseif (
2080 2080
 			in_array($operation, ['supprimer', 'commuter'])
2081 2081
 			and $is_class_presente
@@ -2145,7 +2145,7 @@  discard block
 block discarded – undo
2145 2145
 // Quelques fonctions de calcul arithmetique
2146 2146
 //
2147 2147
 function floatstr($a) {
2148
- return str_replace(',', '.', (string)floatval($a));
2148
+ return str_replace(',', '.', (string) floatval($a));
2149 2149
 }
2150 2150
 function strize($f, $a, $b) {
2151 2151
  return floatstr($f(floatstr($a), floatstr($b)));
@@ -2286,13 +2286,13 @@  discard block
 block discarded – undo
2286 2286
 	if (!defined('_TAGS_NOM_AUTEUR')) {
2287 2287
 		define('_TAGS_NOM_AUTEUR', '');
2288 2288
 	}
2289
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2289
+	$tags_acceptes = array_unique(explode(',', 'multi,'._TAGS_NOM_AUTEUR));
2290 2290
 	foreach ($tags_acceptes as $tag) {
2291 2291
 		if (strlen($tag)) {
2292
-			$remp1[] = '<' . trim($tag) . '>';
2293
-			$remp1[] = '</' . trim($tag) . '>';
2294
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2295
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2292
+			$remp1[] = '<'.trim($tag).'>';
2293
+			$remp1[] = '</'.trim($tag).'>';
2294
+			$remp2[] = '\x60'.trim($tag).'\x61';
2295
+			$remp2[] = '\x60/'.trim($tag).'\x61';
2296 2296
 		}
2297 2297
 	}
2298 2298
 	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
@@ -2412,10 +2412,10 @@  discard block
 block discarded – undo
2412 2412
 	$fichier = basename($url);
2413 2413
 
2414 2414
 	return '<a rel="enclosure"'
2415
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2416
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2417
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2418
-	. '>' . $fichier . '</a>';
2415
+	. ($url ? ' href="'.spip_htmlspecialchars($url).'"' : '')
2416
+	. ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '')
2417
+	. ($length ? ' title="'.spip_htmlspecialchars($length).'"' : '')
2418
+	. '>'.$fichier.'</a>';
2419 2419
 }
2420 2420
 
2421 2421
 /**
@@ -2443,9 +2443,9 @@  discard block
 block discarded – undo
2443 2443
 			} # vieux data
2444 2444
 			$fichier = basename($url);
2445 2445
 			$enclosures[] = '<enclosure'
2446
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2447
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2448
-				. ($length ? ' length="' . $length . '"' : '')
2446
+				. ($url ? ' url="'.spip_htmlspecialchars($url).'"' : '')
2447
+				. ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '')
2448
+				. ($length ? ' length="'.$length.'"' : '')
2449 2449
 				. ' />';
2450 2450
 		}
2451 2451
 	}
@@ -2471,7 +2471,7 @@  discard block
 block discarded – undo
2471 2471
 		if (extraire_attribut($e, 'rel') == 'tag') {
2472 2472
 			$subjects .= '<dc:subject>'
2473 2473
 				. texte_backend(textebrut($e))
2474
-				. '</dc:subject>' . "\n";
2474
+				. '</dc:subject>'."\n";
2475 2475
 		}
2476 2476
 	}
2477 2477
 
@@ -2507,7 +2507,7 @@  discard block
 block discarded – undo
2507 2507
 	if (is_array($texte)) {
2508 2508
 		array_walk(
2509 2509
 			$texte,
2510
-			function (&$a, $key, $t) {
2510
+			function(&$a, $key, $t) {
2511 2511
 				$a = extraire_balise($a, $t);
2512 2512
 			},
2513 2513
 			$tag
@@ -2555,7 +2555,7 @@  discard block
 block discarded – undo
2555 2555
 	if (is_array($texte)) {
2556 2556
 		array_walk(
2557 2557
 			$texte,
2558
-			function (&$a, $key, $t) {
2558
+			function(&$a, $key, $t) {
2559 2559
 				$a = extraire_balises($a, $t);
2560 2560
 			},
2561 2561
 			$tag
@@ -2688,7 +2688,7 @@  discard block
 block discarded – undo
2688 2688
 		if ($fond != '404') {
2689 2689
 			$contexte = array_shift($p);
2690 2690
 			$contexte['page'] = $fond;
2691
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2691
+			$action = preg_replace('/([?]'.preg_quote($fond).'[^&=]*[0-9]+)(&|$)/', '?&', $action);
2692 2692
 		}
2693 2693
 	}
2694 2694
 	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
@@ -2743,9 +2743,9 @@  discard block
 block discarded – undo
2743 2743
 			. '"'
2744 2744
 			. (is_null($val)
2745 2745
 				? ''
2746
-				: ' value="' . entites_html($val) . '"'
2746
+				: ' value="'.entites_html($val).'"'
2747 2747
 			)
2748
-			. ' type="hidden"' . "\n/>";
2748
+			. ' type="hidden"'."\n/>";
2749 2749
 	}
2750 2750
 
2751 2751
 	return join('', $hidden);
@@ -2855,7 +2855,7 @@  discard block
 block discarded – undo
2855 2855
 
2856 2856
 	return preg_replace_callback(
2857 2857
 		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2858
-		fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2858
+		fn($x) => "url('".suivre_lien($path, $x[1])."')",
2859 2859
 		$contenu
2860 2860
 	);
2861 2861
 }
@@ -2916,14 +2916,14 @@  discard block
 block discarded – undo
2916 2916
 	) {
2917 2917
 		$distant = true;
2918 2918
 		$cssf = parse_url($css);
2919
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2919
+		$cssf = $cssf['path'].($cssf['query'] ? '?'.$cssf['query'] : '');
2920 2920
 		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2921 2921
 	} else {
2922 2922
 		$distant = false;
2923 2923
 		$cssf = $css;
2924 2924
 		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2925 2925
 		//propose (rien a faire dans ce cas)
2926
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2926
+		$f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css);
2927 2927
 		if (@file_exists($f)) {
2928 2928
 			return $f;
2929 2929
 		}
@@ -2933,7 +2933,7 @@  discard block
 block discarded – undo
2933 2933
 	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2934 2934
 	$f = $dir_var
2935 2935
 		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2936
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2936
+		. '.'.substr(md5($cssf), 0, 4).'_'.$ndir.'.css';
2937 2937
 
2938 2938
 	// la css peut etre distante (url absolue !)
2939 2939
 	if ($distant) {
@@ -2979,8 +2979,8 @@  discard block
 block discarded – undo
2979 2979
 		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2980 2980
 		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2981 2981
 			$css_direction = substr($css_direction, strlen($dir_var));
2982
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
2983
-			$css_direction = '/@@@@@@/' . $css_direction;
2982
+			$src_faux_abs['/@@@@@@/'.$css_direction] = $css_direction;
2983
+			$css_direction = '/@@@@@@/'.$css_direction;
2984 2984
 		}
2985 2985
 		$src[] = $regs[0][$k];
2986 2986
 		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
@@ -3029,7 +3029,7 @@  discard block
 block discarded – undo
3029 3029
 
3030 3030
 	$f = basename($css, '.css');
3031 3031
 	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3032
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3032
+		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-".substr(md5("$css-urlabs"), 0, 4)."\\2", $f)
3033 3033
 		. '.css';
3034 3034
 
3035 3035
 	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
@@ -3039,7 +3039,7 @@  discard block
 block discarded – undo
3039 3039
 	if ($url_absolue_css == $css) {
3040 3040
 		if (
3041 3041
 			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3042
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3042
+			or !lire_fichier(_DIR_RACINE.substr($css, $l), $contenu)
3043 3043
 		) {
3044 3044
 			include_spip('inc/distant');
3045 3045
 			$contenu = recuperer_url($css);
@@ -3151,7 +3151,7 @@  discard block
 block discarded – undo
3151 3151
 	$expression = str_replace('\/', '/', $expression);
3152 3152
 	$expression = str_replace('/', '\/', $expression);
3153 3153
 
3154
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3154
+	if (preg_match('/'.$expression.'/'.$modif, $texte ?? '', $r)) {
3155 3155
 		if (isset($r[$capte])) {
3156 3156
 			return $r[$capte];
3157 3157
 		} else {
@@ -3193,7 +3193,7 @@  discard block
 block discarded – undo
3193 3193
 	$expression = str_replace('\/', '/', $expression);
3194 3194
 	$expression = str_replace('/', '\/', $expression);
3195 3195
 
3196
-	return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3196
+	return (string) preg_replace('/'.$expression.'/'.$modif, $replace, $texte);
3197 3197
 }
3198 3198
 
3199 3199
 
@@ -3212,7 +3212,7 @@  discard block
 block discarded – undo
3212 3212
 function traiter_doublons_documents(&$doublons, $letexte) {
3213 3213
 
3214 3214
 	// Verifier dans le texte & les notes (pas beau, helas)
3215
-	$t = $letexte . $GLOBALS['les_notes'];
3215
+	$t = $letexte.$GLOBALS['les_notes'];
3216 3216
 
3217 3217
 	if (
3218 3218
 		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
@@ -3226,7 +3226,7 @@  discard block
 block discarded – undo
3226 3226
 		if (!isset($doublons['documents'])) {
3227 3227
 			$doublons['documents'] = '';
3228 3228
 		}
3229
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3229
+		$doublons['documents'] .= ','.join(',', $matches[1]);
3230 3230
 	}
3231 3231
 
3232 3232
 	return $letexte;
@@ -3283,7 +3283,7 @@  discard block
 block discarded – undo
3283 3283
 	if ($env) {
3284 3284
 		foreach ($env as $i => $j) {
3285 3285
 			if (is_string($j) and !in_array($i, $ignore_params)) {
3286
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3286
+				$texte .= "<param name='".attribut_html($i)."'\n\tvalue='".attribut_html($j)."' />";
3287 3287
 			}
3288 3288
 		}
3289 3289
 	}
@@ -3322,7 +3322,7 @@  discard block
 block discarded – undo
3322 3322
 	if ($env) {
3323 3323
 		foreach ($env as $i => $j) {
3324 3324
 			if (is_string($j) and !in_array($i, $ignore_params)) {
3325
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3325
+				$texte .= attribut_html($i)."='".attribut_html($j)."' ";
3326 3326
 			}
3327 3327
 		}
3328 3328
 	}
@@ -3396,10 +3396,10 @@  discard block
 block discarded – undo
3396 3396
 	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3397 3397
 	if (
3398 3398
 		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3399
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3399
+		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])).'-xx.svg'
3400 3400
 		and file_exists($variante_svg_generique)
3401 3401
 	) {
3402
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3402
+		if ($variante_svg_size = substr($variante_svg_generique, 0, -6).$m[1].'.svg' and file_exists($variante_svg_size)) {
3403 3403
 			$img_file = $variante_svg_size;
3404 3404
 		}
3405 3405
 		else {
@@ -3457,7 +3457,7 @@  discard block
 block discarded – undo
3457 3457
 				return '';
3458 3458
 			}
3459 3459
 		}
3460
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3460
+		$atts .= " width='".$largeur."' height='".$hauteur."'";
3461 3461
 	}
3462 3462
 
3463 3463
 	if (file_exists($img_file)) {
@@ -3467,14 +3467,14 @@  discard block
 block discarded – undo
3467 3467
 		$alt = '';
3468 3468
 	}
3469 3469
 	elseif ($alt or $alt === '') {
3470
-		$alt = " alt='" . attribut_html($alt) . "'";
3470
+		$alt = " alt='".attribut_html($alt)."'";
3471 3471
 	}
3472 3472
 	else {
3473
-		$alt = " alt='" . attribut_html($title) . "'";
3473
+		$alt = " alt='".attribut_html($title)."'";
3474 3474
 	}
3475
-	return "<img src='" . attribut_html($img_file) . "'$alt"
3476
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3477
-	. ' ' . ltrim($atts)
3475
+	return "<img src='".attribut_html($img_file)."'$alt"
3476
+	. ($title ? ' title="'.attribut_html($title).'"' : '')
3477
+	. ' '.ltrim($atts)
3478 3478
 	. ' />';
3479 3479
 }
3480 3480
 
@@ -3488,10 +3488,10 @@  discard block
 block discarded – undo
3488 3488
  */
3489 3489
 function http_style_background($img, $att = '', $size = null) {
3490 3490
 	if ($size and is_numeric($size)) {
3491
-		$size = trim($size) . 'px';
3491
+		$size = trim($size).'px';
3492 3492
 	}
3493
-	return " style='background" .
3494
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3493
+	return " style='background".
3494
+		($att ? '' : '-image').': url("'.chemin_image($img).'")'.($att ? (' '.$att) : '').';'
3495 3495
 		. ($size ? "background-size:{$size};" : '')
3496 3496
 		. "'";
3497 3497
 }
@@ -3606,7 +3606,7 @@  discard block
 block discarded – undo
3606 3606
 		$img = http_img_pack(
3607 3607
 			$img,
3608 3608
 			$alt,
3609
-			$class ? " class='" . attribut_html($class) . "'" : '',
3609
+			$class ? " class='".attribut_html($class)."'" : '',
3610 3610
 			'',
3611 3611
 			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3612 3612
 		);
@@ -3691,7 +3691,7 @@  discard block
 block discarded – undo
3691 3691
 	$balise_svg_source = $balise_svg;
3692 3692
 
3693 3693
 	// entete XML à supprimer
3694
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3694
+	$svg = preg_replace(',^\s*<\?xml[^>]*\?'.'>,', '', $svg);
3695 3695
 
3696 3696
 	// IE est toujours mon ami
3697 3697
 	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
@@ -3709,9 +3709,9 @@  discard block
 block discarded – undo
3709 3709
 	// regler le alt
3710 3710
 	if ($alt) {
3711 3711
 		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3712
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3712
+		$id = 'img-svg-title-'.substr(md5("$img_file:$svg:$alt"), 0, 4);
3713 3713
 		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3714
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3714
+		$title = "<title id=\"$id\">".entites_html($alt)."</title>\n";
3715 3715
 		$balise_svg .= $title;
3716 3716
 	}
3717 3717
 	else {
@@ -3759,7 +3759,7 @@  discard block
 block discarded – undo
3759 3759
 	if (is_array($tableau)) {
3760 3760
 		foreach ($tableau as $k => $v) {
3761 3761
 			$res = recuperer_fond(
3762
-				'modeles/' . $modele,
3762
+				'modeles/'.$modele,
3763 3763
 				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3764 3764
 			);
3765 3765
 			$texte .= $res;
@@ -3944,7 +3944,7 @@  discard block
 block discarded – undo
3944 3944
 	}
3945 3945
 
3946 3946
 	$c = serialize($c);
3947
-	$cle = calculer_cle_action($form . $c);
3947
+	$cle = calculer_cle_action($form.$c);
3948 3948
 	$c = "$cle:$c";
3949 3949
 
3950 3950
 	// on ne stocke pas les contextes dans des fichiers en cache
@@ -4002,15 +4002,15 @@  discard block
 block discarded – undo
4002 4002
 	}
4003 4003
 	// toujours encoder l'url source dans le bloc ajax
4004 4004
 	$r = self();
4005
-	$r = ' data-origin="' . $r . '"';
4005
+	$r = ' data-origin="'.$r.'"';
4006 4006
 	$class = 'ajaxbloc';
4007 4007
 	if ($ajaxid and is_string($ajaxid)) {
4008 4008
 		// ajaxid est normalement conforme a un nom de classe css
4009 4009
 		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4010
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4010
+		$class .= ' ajax-id-'.entites_html($ajaxid);
4011 4011
 	}
4012 4012
 
4013
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4013
+	return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4014 4014
 }
4015 4015
 
4016 4016
 /**
@@ -4054,7 +4054,7 @@  discard block
 block discarded – undo
4054 4054
 		$cle = substr($c, 0, $p);
4055 4055
 		$c = substr($c, $p + 1);
4056 4056
 
4057
-		if ($cle == calculer_cle_action($form . $c)) {
4057
+		if ($cle == calculer_cle_action($form.$c)) {
4058 4058
 			$env = @unserialize($c);
4059 4059
 			return $env;
4060 4060
 		}
@@ -4175,13 +4175,13 @@  discard block
 block discarded – undo
4175 4175
 				}
4176 4176
 			}
4177 4177
 		}
4178
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4178
+		$att .= 'class="'.($class ? attribut_html($class).' ' : '').(defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on').'"';
4179 4179
 	} else {
4180 4180
 		$bal = 'a';
4181 4181
 		$att = "href='$url'"
4182
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4183
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4184
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4182
+			. ($title ? " title='".attribut_html($title)."'" : '')
4183
+			. ($class ? " class='".attribut_html($class)."'" : '')
4184
+			. ($rel ? " rel='".attribut_html($rel)."'" : '')
4185 4185
 			. $evt;
4186 4186
 	}
4187 4187
 	if ($libelle === null) {
@@ -4320,7 +4320,7 @@  discard block
 block discarded – undo
4320 4320
 
4321 4321
 	// Icône
4322 4322
 	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4323
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4323
+	$icone = '<span class="icone-image'.($fonction ? " icone-fonction icone-fonction-$fonction" : '')."\">$icone</span>";
4324 4324
 
4325 4325
 	// Markup final
4326 4326
 	if ($type == 'lien') {
@@ -4595,20 +4595,20 @@  discard block
 block discarded – undo
4595 4595
 		$class_form = 'ajax';
4596 4596
 		$class = str_replace('ajax', '', $class);
4597 4597
 	}
4598
-	$class_btn = 'submit ' . trim($class);
4598
+	$class_btn = 'submit '.trim($class);
4599 4599
 
4600 4600
 	if ($confirm) {
4601
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4601
+		$confirm = 'confirm("'.attribut_html($confirm).'")';
4602 4602
 		if ($callback) {
4603 4603
 			$callback = "$confirm?($callback):false";
4604 4604
 		} else {
4605 4605
 			$callback = $confirm;
4606 4606
 		}
4607 4607
 	}
4608
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4608
+	$onclick = $callback ? " onclick='return ".addcslashes($callback, "'")."'" : '';
4609 4609
 	$title = $title ? " title='$title'" : '';
4610 4610
 
4611
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4611
+	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>".form_hidden($url)
4612 4612
 	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4613 4613
 }
4614 4614
 
@@ -4673,14 +4673,14 @@  discard block
 block discarded – undo
4673 4673
 		$champ_titre = '';
4674 4674
 		if ($demande_titre) {
4675 4675
 			// si pas de titre declare mais champ titre, il sera peuple par le select *
4676
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4676
+			$champ_titre = (!empty($desc['titre'])) ? ', '.$desc['titre'] : '';
4677 4677
 		}
4678 4678
 		include_spip('base/abstract_sql');
4679 4679
 		include_spip('base/connect_sql');
4680 4680
 		$objets[$type_objet][$id_objet] = sql_fetsel(
4681
-			'*' . $champ_titre,
4681
+			'*'.$champ_titre,
4682 4682
 			$desc['table_sql'],
4683
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4683
+			id_table_objet($type_objet).' = '.intval($id_objet)
4684 4684
 		);
4685 4685
 
4686 4686
 		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
@@ -4773,8 +4773,7 @@  discard block
 block discarded – undo
4773 4773
 	if (isset($ligne_sql['chapo'])) {
4774 4774
 		$chapo = $ligne_sql['chapo'];
4775 4775
 		$texte = strlen($descriptif) ?
4776
-			'' :
4777
-			"$chapo \n\n $texte";
4776
+			'' : "$chapo \n\n $texte";
4778 4777
 	}
4779 4778
 
4780 4779
 	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
@@ -4849,7 +4848,7 @@  discard block
 block discarded – undo
4849 4848
 		return $texte;
4850 4849
 	}
4851 4850
 
4852
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4851
+	$traitement = str_replace('%s', "'".texte_script($texte)."'", $traitement);
4853 4852
 
4854 4853
 	// signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4855 4854
 	if (test_espace_prive()) {
@@ -4888,7 +4887,7 @@  discard block
 block discarded – undo
4888 4887
 	}
4889 4888
 	$url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4890 4889
 
4891
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4890
+	return "<a href='$url' class='$objet'>".couper($titre, $longueur).'</a>';
4892 4891
 }
4893 4892
 
4894 4893
 /**
@@ -4914,10 +4913,10 @@  discard block
 block discarded – undo
4914 4913
 function wrap($texte, $wrap) {
4915 4914
 	$balises = extraire_balises($wrap);
4916 4915
 	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4917
-		$texte = $wrap . $texte;
4916
+		$texte = $wrap.$texte;
4918 4917
 		$regs = array_reverse($regs[1]);
4919
-		$wrap = '</' . implode('></', $regs) . '>';
4920
-		$texte = $texte . $wrap;
4918
+		$wrap = '</'.implode('></', $regs).'>';
4919
+		$texte = $texte.$wrap;
4921 4920
 	}
4922 4921
 
4923 4922
 	return $texte;
@@ -4948,7 +4947,7 @@  discard block
 block discarded – undo
4948 4947
 
4949 4948
 	// caster $u en array si besoin
4950 4949
 	if (is_object($u)) {
4951
-		$u = (array)$u;
4950
+		$u = (array) $u;
4952 4951
 	}
4953 4952
 
4954 4953
 	if (is_array($u)) {
@@ -4970,7 +4969,7 @@  discard block
 block discarded – undo
4970 4969
 		// sinon on passe a la ligne et on indente
4971 4970
 		$i_str = str_pad('', $indent, ' ');
4972 4971
 		foreach ($u as $k => $v) {
4973
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4972
+			$out .= $join.$i_str."$k: ".filtre_print_dist($v, $join, $indent + 2);
4974 4973
 		}
4975 4974
 
4976 4975
 		return $out;
@@ -5024,7 +5023,7 @@  discard block
 block discarded – undo
5024 5023
  * @return string
5025 5024
  */
5026 5025
 function objet_icone($objet, $taille = 24, $class = '') {
5027
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5026
+	$icone = objet_info($objet, 'icone_objet').'-'.$taille.'.png';
5028 5027
 	$icone = chemin_image($icone);
5029 5028
 	$balise_img = charger_filtre('balise_img');
5030 5029
 
@@ -5050,7 +5049,7 @@  discard block
 block discarded – undo
5050 5049
  */
5051 5050
 function objet_T($objet, $chaine, $args = [], $options = []) {
5052 5051
 	$chaine = explode(':', $chaine);
5053
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5052
+	if ($t = _T($objet.':'.end($chaine), $args, array_merge($options, ['force' => false]))) {
5054 5053
 		return $t;
5055 5054
 	}
5056 5055
 	$chaine = implode(':', $chaine);
@@ -5116,7 +5115,7 @@  discard block
 block discarded – undo
5116 5115
 	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5117 5116
 
5118 5117
 	// calculer le nom de la css
5119
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5118
+	$dir_var = sous_repertoire(_DIR_VAR, 'cache-'.$extension);
5120 5119
 	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5121 5120
 	$contexte_implicite = calculer_contexte_implicite();
5122 5121
 
@@ -5124,14 +5123,14 @@  discard block
 block discarded – undo
5124 5123
 	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5125 5124
 	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5126 5125
 	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5127
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5126
+		$hash = md5($contexte_implicite['host'].'::'.$cache);
5128 5127
 	}
5129 5128
 	else {
5130 5129
 		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5131 5130
 		ksort($contexte);
5132
-		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5131
+		$hash = md5($fond.json_encode($contexte_implicite, JSON_THROW_ON_ERROR).json_encode($contexte, JSON_THROW_ON_ERROR).$connect);
5133 5132
 	}
5134
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5133
+	$filename = $dir_var.$extension."dyn-$nom_safe-".substr($hash, 0, 8).".$extension";
5135 5134
 
5136 5135
 	// mettre a jour le fichier si il n'existe pas
5137 5136
 	// ou trop ancien
@@ -5139,8 +5138,8 @@  discard block
 block discarded – undo
5139 5138
 	// et recopie sur le fichier cible uniquement si il change
5140 5139
 	if (
5141 5140
 		!file_exists($filename)
5142
-		or !file_exists($filename . '.last')
5143
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5141
+		or !file_exists($filename.'.last')
5142
+		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename.'.last') < $cache['lastmodified'])
5144 5143
 		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5145 5144
 	) {
5146 5145
 		$contenu = $cache['texte'];
@@ -5164,10 +5163,10 @@  discard block
 block discarded – undo
5164 5163
 			}
5165 5164
 			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5166 5165
 			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5167
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5166
+			$comment .= "}\n   md5:".md5($contenu)." */\n";
5168 5167
 		}
5169 5168
 		// et ecrire le fichier si il change
5170
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5169
+		ecrire_fichier_calcule_si_modifie($filename, $comment.$contenu, false, true);
5171 5170
 	}
5172 5171
 
5173 5172
 	return timestamp($filename);
@@ -5400,7 +5399,7 @@  discard block
 block discarded – undo
5400 5399
 	if ($e > 0 and strlen($mid) > 8) {
5401 5400
 		$mid = '***...***';
5402 5401
 	}
5403
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5402
+	return substr($passe, 0, $e).$mid.($e > 0 ? substr($passe, -$e) : '');
5404 5403
 }
5405 5404
 
5406 5405
 
@@ -5462,7 +5461,7 @@  discard block
 block discarded – undo
5462 5461
 		case 'id':
5463 5462
 		case 'anchor':
5464 5463
 			if (preg_match(',^\d,', $texte)) {
5465
-				$texte = substr($type, 0, 1) . $texte;
5464
+				$texte = substr($type, 0, 1).$texte;
5466 5465
 			}
5467 5466
 	}
5468 5467
 
@@ -5472,9 +5471,9 @@  discard block
 block discarded – undo
5472 5471
 
5473 5472
 	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5474 5473
 		if (preg_match(',^\d,', $texte)) {
5475
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5474
+			$texte = ($type ? substr($type, 0, 1) : 's').$texte;
5476 5475
 		}
5477
-		$texte .= $separateur . md5($original);
5476
+		$texte .= $separateur.md5($original);
5478 5477
 		$texte = substr($texte, 0, $longueur_mini);
5479 5478
 	}
5480 5479
 
Please login to merge, or discard this patch.
Indentation   +2413 added lines, -2413 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/charsets');
@@ -41,8 +41,8 @@  discard block
 block discarded – undo
41 41
  * @return string Fonction PHP correspondante du filtre
42 42
  */
43 43
 function charger_filtre($fonc, $default = 'filtre_identite_dist') {
44
-	include_fichiers_fonctions(); // inclure les fichiers fonctions
45
-	return chercher_filtre($fonc, $default);
44
+    include_fichiers_fonctions(); // inclure les fichiers fonctions
45
+    return chercher_filtre($fonc, $default);
46 46
 }
47 47
 
48 48
 /**
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
  * @return string texte
53 53
  **/
54 54
 function filtre_identite_dist($texte) {
55
- return $texte;
55
+    return $texte;
56 56
 }
57 57
 
58 58
 /**
@@ -76,33 +76,33 @@  discard block
 block discarded – undo
76 76
  *     Fonction PHP correspondante du filtre demandé
77 77
  */
78 78
 function chercher_filtre($fonc, $default = null) {
79
-	if (!$fonc) {
80
-		return $default;
81
-	}
82
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
83
-	// Foo::Bar
84
-	// qui peuvent etre avec un namespace : space\Foo::Bar
85
-	if (preg_match(',^[\w]+/,', $fonc)) {
86
-		$nom = preg_replace(',\W,', '_', $fonc);
87
-		$f = chercher_filtre($nom);
88
-		// cas du sous-type MIME sans filtre associe, passer au type:
89
-		// si filtre_text_plain pas defini, passe a filtre_text
90
-		if (!$f and $nom !== $fonc) {
91
-			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
92
-		}
93
-
94
-		return $f;
95
-	}
96
-
97
-	include_fichiers_fonctions();
98
-	foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
99
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
100
-		if (is_callable($f)) {
101
-			return $f;
102
-		}
103
-	}
104
-
105
-	return $default;
79
+    if (!$fonc) {
80
+        return $default;
81
+    }
82
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
83
+    // Foo::Bar
84
+    // qui peuvent etre avec un namespace : space\Foo::Bar
85
+    if (preg_match(',^[\w]+/,', $fonc)) {
86
+        $nom = preg_replace(',\W,', '_', $fonc);
87
+        $f = chercher_filtre($nom);
88
+        // cas du sous-type MIME sans filtre associe, passer au type:
89
+        // si filtre_text_plain pas defini, passe a filtre_text
90
+        if (!$f and $nom !== $fonc) {
91
+            $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
92
+        }
93
+
94
+        return $f;
95
+    }
96
+
97
+    include_fichiers_fonctions();
98
+    foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
99
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
100
+        if (is_callable($f)) {
101
+            return $f;
102
+        }
103
+    }
104
+
105
+    return $default;
106 106
 }
107 107
 
108 108
 /**
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
  *     Chaîne vide sinon.
147 147
  **/
148 148
 function appliquer_filtre($arg, $filtre) {
149
-	$args = func_get_args();
150
-	return appliquer_filtre_sinon($arg, $filtre, $args, '');
149
+    $args = func_get_args();
150
+    return appliquer_filtre_sinon($arg, $filtre, $args, '');
151 151
 }
152 152
 
153 153
 /**
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
  *     texte d'origine sinon
173 173
  **/
174 174
 function appliquer_si_filtre($arg, $filtre) {
175
-	$args = func_get_args();
176
-	return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
175
+    $args = func_get_args();
176
+    return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
177 177
 }
178 178
 
179 179
 /**
@@ -189,12 +189,12 @@  discard block
 block discarded – undo
189 189
  *     Version de SPIP
190 190
  **/
191 191
 function spip_version() {
192
-	$version = $GLOBALS['spip_version_affichee'];
193
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
194
-		$version .= " $vcs_version";
195
-	}
192
+    $version = $GLOBALS['spip_version_affichee'];
193
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
194
+        $version .= " $vcs_version";
195
+    }
196 196
 
197
-	return $version;
197
+    return $version;
198 198
 }
199 199
 
200 200
 /**
@@ -206,11 +206,11 @@  discard block
 block discarded – undo
206 206
  * @return string
207 207
  */
208 208
 function header_silencieux($version): string {
209
-	if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) {
210
-		$version = '';
211
-	}
209
+    if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) {
210
+        $version = '';
211
+    }
212 212
 
213
-	return (string) $version;
213
+    return (string) $version;
214 214
 }
215 215
 
216 216
 /**
@@ -223,16 +223,16 @@  discard block
 block discarded – undo
223 223
  *    - string|null si $raw = false
224 224
  */
225 225
 function version_vcs_courante($dir, $raw = false) {
226
-	$desc = decrire_version_git($dir);
227
-	if ($desc === null or $raw) {
228
-		return $desc;
229
-	}
230
-	// affichage "GIT [master: abcdef]"
231
-	$commit = $desc['commit_short'] ?? $desc['commit'];
232
-	if ($desc['branch']) {
233
-		$commit = $desc['branch'] . ': ' . $commit;
234
-	}
235
-	return "{$desc['vcs']} [$commit]";
226
+    $desc = decrire_version_git($dir);
227
+    if ($desc === null or $raw) {
228
+        return $desc;
229
+    }
230
+    // affichage "GIT [master: abcdef]"
231
+    $commit = $desc['commit_short'] ?? $desc['commit'];
232
+    if ($desc['branch']) {
233
+        $commit = $desc['branch'] . ': ' . $commit;
234
+    }
235
+    return "{$desc['vcs']} [$commit]";
236 236
 }
237 237
 
238 238
 /**
@@ -244,24 +244,24 @@  discard block
 block discarded – undo
244 244
  *      array ['branch' => xx, 'commit' => yy] sinon.
245 245
  **/
246 246
 function decrire_version_git($dir) {
247
-	if (!$dir) {
248
-		$dir = '.';
249
-	}
250
-
251
-	// version installee par GIT
252
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
253
-		$currentHead = trim(substr($c, 4));
254
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
255
-			return [
256
-				'vcs' => 'GIT',
257
-				'branch' => basename($currentHead),
258
-				'commit' => trim($hash),
259
-				'commit_short' => substr(trim($hash), 0, 8),
260
-			];
261
-		}
262
-	}
263
-
264
-	return null;
247
+    if (!$dir) {
248
+        $dir = '.';
249
+    }
250
+
251
+    // version installee par GIT
252
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
253
+        $currentHead = trim(substr($c, 4));
254
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
255
+            return [
256
+                'vcs' => 'GIT',
257
+                'branch' => basename($currentHead),
258
+                'commit' => trim($hash),
259
+                'commit_short' => substr(trim($hash), 0, 8),
260
+            ];
261
+        }
262
+    }
263
+
264
+    return null;
265 265
 }
266 266
 
267 267
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -308,18 +308,18 @@  discard block
 block discarded – undo
308 308
  *     Code HTML retourné par le filtre
309 309
  **/
310 310
 function filtrer($filtre) {
311
-	$tous = func_get_args();
312
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
313
-		return image_filtrer($tous);
314
-	} elseif ($f = chercher_filtre($filtre)) {
315
-		array_shift($tous);
316
-		return $f(...$tous);
317
-	} else {
318
-		// le filtre n'existe pas, on provoque une erreur
319
-		$msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
320
-		erreur_squelette($msg);
321
-		return '';
322
-	}
311
+    $tous = func_get_args();
312
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
313
+        return image_filtrer($tous);
314
+    } elseif ($f = chercher_filtre($filtre)) {
315
+        array_shift($tous);
316
+        return $f(...$tous);
317
+    } else {
318
+        // le filtre n'existe pas, on provoque une erreur
319
+        $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
320
+        erreur_squelette($msg);
321
+        return '';
322
+    }
323 323
 }
324 324
 
325 325
 /**
@@ -336,11 +336,11 @@  discard block
 block discarded – undo
336 336
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
337 337
  */
338 338
 function trouver_filtre_matrice($filtre) {
339
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
340
-		find_in_path($f, '', true);
341
-		$GLOBALS['spip_matrice'][$filtre] = true;
342
-	}
343
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
339
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
340
+        find_in_path($f, '', true);
341
+        $GLOBALS['spip_matrice'][$filtre] = true;
342
+    }
343
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
344 344
 }
345 345
 
346 346
 
@@ -368,8 +368,8 @@  discard block
 block discarded – undo
368 368
  * @return mixed
369 369
  */
370 370
 function filtre_set(&$Pile, $val, $key, $continue = null) {
371
-	$Pile['vars'][$key] = $val;
372
-	return $continue ? $val : '';
371
+    $Pile['vars'][$key] = $val;
372
+    return $continue ? $val : '';
373 373
 }
374 374
 
375 375
 /**
@@ -395,8 +395,8 @@  discard block
 block discarded – undo
395 395
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
396 396
  */
397 397
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
398
-	$Pile[0][$key] = $val;
399
-	return $continue ? $val : '';
398
+    $Pile[0][$key] = $val;
399
+    return $continue ? $val : '';
400 400
 }
401 401
 
402 402
 /**
@@ -405,8 +405,8 @@  discard block
 block discarded – undo
405 405
  * @return string
406 406
  */
407 407
 function filtre_sanitize_env(&$Pile, $keys) {
408
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
409
-	return '';
408
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
409
+    return '';
410 410
 }
411 411
 
412 412
 
@@ -429,18 +429,18 @@  discard block
 block discarded – undo
429 429
  * @return mixed Retourne la valeur (sans la modifier).
430 430
  */
431 431
 function filtre_debug($val, $key = null) {
432
-	$debug = (
433
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
434
-		) . var_export($val, true);
432
+    $debug = (
433
+        is_null($key) ? '' : (var_export($key, true) . ' = ')
434
+        ) . var_export($val, true);
435 435
 
436
-	include_spip('inc/autoriser');
437
-	if (autoriser('webmestre')) {
438
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
439
-	}
436
+    include_spip('inc/autoriser');
437
+    if (autoriser('webmestre')) {
438
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
439
+    }
440 440
 
441
-	spip_log($debug, 'debug');
441
+    spip_log($debug, 'debug');
442 442
 
443
-	return $val;
443
+    return $val;
444 444
 }
445 445
 
446 446
 
@@ -470,84 +470,84 @@  discard block
 block discarded – undo
470 470
  *     texte qui a reçu les filtres
471 471
  **/
472 472
 function image_filtrer($args) {
473
-	$filtre = array_shift($args); # enlever $filtre
474
-	$texte = array_shift($args);
475
-	if ($texte === null || !strlen($texte)) {
476
-		return '';
477
-	}
478
-	find_in_path('filtres_images_mini.php', 'inc/', true);
479
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
480
-	// Cas du nom de fichier local
481
-	$is_file = trim($texte);
482
-	if (
483
-		strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
484
-		  or strpbrk($is_file, "<>\n\r\t") !== false
485
-		  or strpos($is_file, '/') === 0
486
-	) {
487
-		$is_file = false;
488
-	}
489
-	if ($is_file) {
490
-		$is_local_file = function ($path) {
491
-			if (strpos($path, '?') !== false) {
492
-				$path = supprimer_timestamp($path);
493
-				// remove ?24px added by find_in_theme on .svg files
494
-				$path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
495
-			}
496
-			return file_exists($path);
497
-		};
498
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
499
-			$res = $filtre("<img src='$is_file' />", ...$args);
500
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
501
-			return $res;
502
-		}
503
-	}
504
-
505
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
506
-	if (
507
-		preg_match_all(
508
-			',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
509
-			$texte,
510
-			$tags,
511
-			PREG_SET_ORDER
512
-		)
513
-	) {
514
-		foreach ($tags as $tag) {
515
-			$class = extraire_attribut($tag[3], 'class');
516
-			if (
517
-				!$class or
518
-				(strpos($class, 'filtre_inactif') === false
519
-					// compat historique a virer en 3.2
520
-					and !str_contains($class, 'no_image_filtrer'))
521
-			) {
522
-				if ($reduit = $filtre($tag[3], ...$args)) {
523
-					// En cas de span spip_documents, modifier le style=...width:
524
-					if ($tag[1]) {
525
-						$w = extraire_attribut($reduit, 'width');
526
-						if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
527
-							$w = $regs[1];
528
-						}
529
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
530
-							$style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style);
531
-							$replace = inserer_attribut($tag[1], 'style', $style);
532
-							$texte = str_replace($tag[1], $replace, $texte);
533
-						}
534
-					}
535
-					// traiter aussi un eventuel mouseover
536
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
537
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
538
-							$srcover = $match[1];
539
-							$srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
540
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
541
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
542
-						}
543
-					}
544
-					$texte = str_replace($tag[3], $reduit, $texte);
545
-				}
546
-			}
547
-		}
548
-	}
549
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
550
-	return $texte;
473
+    $filtre = array_shift($args); # enlever $filtre
474
+    $texte = array_shift($args);
475
+    if ($texte === null || !strlen($texte)) {
476
+        return '';
477
+    }
478
+    find_in_path('filtres_images_mini.php', 'inc/', true);
479
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
480
+    // Cas du nom de fichier local
481
+    $is_file = trim($texte);
482
+    if (
483
+        strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
484
+          or strpbrk($is_file, "<>\n\r\t") !== false
485
+          or strpos($is_file, '/') === 0
486
+    ) {
487
+        $is_file = false;
488
+    }
489
+    if ($is_file) {
490
+        $is_local_file = function ($path) {
491
+            if (strpos($path, '?') !== false) {
492
+                $path = supprimer_timestamp($path);
493
+                // remove ?24px added by find_in_theme on .svg files
494
+                $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
495
+            }
496
+            return file_exists($path);
497
+        };
498
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
499
+            $res = $filtre("<img src='$is_file' />", ...$args);
500
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
501
+            return $res;
502
+        }
503
+    }
504
+
505
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
506
+    if (
507
+        preg_match_all(
508
+            ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
509
+            $texte,
510
+            $tags,
511
+            PREG_SET_ORDER
512
+        )
513
+    ) {
514
+        foreach ($tags as $tag) {
515
+            $class = extraire_attribut($tag[3], 'class');
516
+            if (
517
+                !$class or
518
+                (strpos($class, 'filtre_inactif') === false
519
+                    // compat historique a virer en 3.2
520
+                    and !str_contains($class, 'no_image_filtrer'))
521
+            ) {
522
+                if ($reduit = $filtre($tag[3], ...$args)) {
523
+                    // En cas de span spip_documents, modifier le style=...width:
524
+                    if ($tag[1]) {
525
+                        $w = extraire_attribut($reduit, 'width');
526
+                        if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
527
+                            $w = $regs[1];
528
+                        }
529
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
530
+                            $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style);
531
+                            $replace = inserer_attribut($tag[1], 'style', $style);
532
+                            $texte = str_replace($tag[1], $replace, $texte);
533
+                        }
534
+                    }
535
+                    // traiter aussi un eventuel mouseover
536
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
537
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
538
+                            $srcover = $match[1];
539
+                            $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
540
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
541
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
542
+                        }
543
+                    }
544
+                    $texte = str_replace($tag[3], $reduit, $texte);
545
+                }
546
+            }
547
+        }
548
+    }
549
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
550
+    return $texte;
551 551
 }
552 552
 
553 553
 /**
@@ -564,94 +564,94 @@  discard block
 block discarded – undo
564 564
  **/
565 565
 function infos_image($img, $force_refresh = false) {
566 566
 
567
-	static $largeur_img = [], $hauteur_img = [], $poids_img = [];
568
-	$srcWidth = 0;
569
-	$srcHeight = 0;
570
-	$srcSize = null;
571
-
572
-	$src = extraire_attribut($img, 'src');
573
-
574
-	if (!$src) {
575
-		$src = $img;
576
-	} else {
577
-		$srcWidth = extraire_attribut($img, 'width');
578
-		$srcHeight = extraire_attribut($img, 'height');
579
-		if (!ctype_digit(strval($srcWidth)) or !ctype_digit(strval($srcHeight))) {
580
-			$srcWidth = $srcHeight = 0;
581
-		}
582
-	}
583
-
584
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
585
-	// la copie locale a toutes les chances d'etre la ou de resservir
586
-	if (tester_url_absolue($src)) {
587
-		include_spip('inc/distant');
588
-		$fichier = copie_locale($src);
589
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
590
-	}
591
-	if (($p = strpos($src, '?')) !== false) {
592
-		$src = substr($src, 0, $p);
593
-	}
594
-
595
-	$imagesize = false;
596
-	if (isset($largeur_img[$src]) and !$force_refresh) {
597
-		$srcWidth = $largeur_img[$src];
598
-	}
599
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
600
-		$srcHeight = $hauteur_img[$src];
601
-	}
602
-	if (isset($poids_img[$src]) and !$force_refresh) {
603
-		$srcSize = $poids_img[$src];
604
-	}
605
-	if (!$srcWidth or !$srcHeight or is_null($srcSize)) {
606
-		if (
607
-			file_exists($src)
608
-			and $imagesize = spip_getimagesize($src)
609
-		) {
610
-			if (!$srcWidth) {
611
-				$largeur_img[$src] = $srcWidth = $imagesize[0];
612
-			}
613
-			if (!$srcHeight) {
614
-				$hauteur_img[$src] = $srcHeight = $imagesize[1];
615
-			}
616
-			if (!$srcSize) {
617
-				$poids_img[$src] = filesize($src);
618
-			}
619
-		}
620
-		elseif (strpos($src, '<svg') !== false) {
621
-			include_spip('inc/svg');
622
-			if ($attrs = svg_lire_attributs($src)) {
623
-				[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
624
-				if (!$srcWidth) {
625
-					$largeur_img[$src] = $srcWidth = $width;
626
-				}
627
-				if (!$srcHeight) {
628
-					$hauteur_img[$src] = $srcHeight = $height;
629
-				}
630
-				if (!$srcSize) {
631
-					$poids_img[$src] = $srcSize = strlen($src);
632
-				}
633
-			}
634
-		}
635
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
636
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
637
-		elseif (
638
-			@file_exists($f = "$src.src")
639
-			and lire_fichier($f, $valeurs)
640
-			and $valeurs = unserialize($valeurs)
641
-		) {
642
-			if (!$srcWidth) {
643
-				$largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
644
-			}
645
-			if (!$srcHeight) {
646
-				$hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
647
-			}
648
-			if (!$srcSize) {
649
-				$poids_img[$src] = $srcSize = 0;
650
-			}
651
-		}
652
-	}
653
-
654
-	return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
567
+    static $largeur_img = [], $hauteur_img = [], $poids_img = [];
568
+    $srcWidth = 0;
569
+    $srcHeight = 0;
570
+    $srcSize = null;
571
+
572
+    $src = extraire_attribut($img, 'src');
573
+
574
+    if (!$src) {
575
+        $src = $img;
576
+    } else {
577
+        $srcWidth = extraire_attribut($img, 'width');
578
+        $srcHeight = extraire_attribut($img, 'height');
579
+        if (!ctype_digit(strval($srcWidth)) or !ctype_digit(strval($srcHeight))) {
580
+            $srcWidth = $srcHeight = 0;
581
+        }
582
+    }
583
+
584
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
585
+    // la copie locale a toutes les chances d'etre la ou de resservir
586
+    if (tester_url_absolue($src)) {
587
+        include_spip('inc/distant');
588
+        $fichier = copie_locale($src);
589
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
590
+    }
591
+    if (($p = strpos($src, '?')) !== false) {
592
+        $src = substr($src, 0, $p);
593
+    }
594
+
595
+    $imagesize = false;
596
+    if (isset($largeur_img[$src]) and !$force_refresh) {
597
+        $srcWidth = $largeur_img[$src];
598
+    }
599
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
600
+        $srcHeight = $hauteur_img[$src];
601
+    }
602
+    if (isset($poids_img[$src]) and !$force_refresh) {
603
+        $srcSize = $poids_img[$src];
604
+    }
605
+    if (!$srcWidth or !$srcHeight or is_null($srcSize)) {
606
+        if (
607
+            file_exists($src)
608
+            and $imagesize = spip_getimagesize($src)
609
+        ) {
610
+            if (!$srcWidth) {
611
+                $largeur_img[$src] = $srcWidth = $imagesize[0];
612
+            }
613
+            if (!$srcHeight) {
614
+                $hauteur_img[$src] = $srcHeight = $imagesize[1];
615
+            }
616
+            if (!$srcSize) {
617
+                $poids_img[$src] = filesize($src);
618
+            }
619
+        }
620
+        elseif (strpos($src, '<svg') !== false) {
621
+            include_spip('inc/svg');
622
+            if ($attrs = svg_lire_attributs($src)) {
623
+                [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
624
+                if (!$srcWidth) {
625
+                    $largeur_img[$src] = $srcWidth = $width;
626
+                }
627
+                if (!$srcHeight) {
628
+                    $hauteur_img[$src] = $srcHeight = $height;
629
+                }
630
+                if (!$srcSize) {
631
+                    $poids_img[$src] = $srcSize = strlen($src);
632
+                }
633
+            }
634
+        }
635
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
636
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
637
+        elseif (
638
+            @file_exists($f = "$src.src")
639
+            and lire_fichier($f, $valeurs)
640
+            and $valeurs = unserialize($valeurs)
641
+        ) {
642
+            if (!$srcWidth) {
643
+                $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
644
+            }
645
+            if (!$srcHeight) {
646
+                $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
647
+            }
648
+            if (!$srcSize) {
649
+                $poids_img[$src] = $srcSize = 0;
650
+            }
651
+        }
652
+    }
653
+
654
+    return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
655 655
 }
656 656
 
657 657
 /**
@@ -667,13 +667,13 @@  discard block
 block discarded – undo
667 667
  *     poids
668 668
  **/
669 669
 function poids_image($img, $force_refresh = false) {
670
-	$infos = infos_image($img, $force_refresh);
671
-	return $infos['poids'];
670
+    $infos = infos_image($img, $force_refresh);
671
+    return $infos['poids'];
672 672
 }
673 673
 
674 674
 function taille_image($img, $force_refresh = false) {
675
-	$infos = infos_image($img, $force_refresh);
676
-	return [$infos['hauteur'], $infos['largeur']];
675
+    $infos = infos_image($img, $force_refresh);
676
+    return [$infos['hauteur'], $infos['largeur']];
677 677
 }
678 678
 
679 679
 /**
@@ -690,12 +690,12 @@  discard block
 block discarded – undo
690 690
  *     Largeur en pixels, NULL ou 0 si aucune image.
691 691
  **/
692 692
 function largeur($img) {
693
-	if (!$img) {
694
-		return;
695
-	}
696
-	[$h, $l] = taille_image($img);
693
+    if (!$img) {
694
+        return;
695
+    }
696
+    [$h, $l] = taille_image($img);
697 697
 
698
-	return $l;
698
+    return $l;
699 699
 }
700 700
 
701 701
 /**
@@ -712,12 +712,12 @@  discard block
 block discarded – undo
712 712
  *     Hauteur en pixels, NULL ou 0 si aucune image.
713 713
  **/
714 714
 function hauteur($img) {
715
-	if (!$img) {
716
-		return;
717
-	}
718
-	[$h, $l] = taille_image($img);
715
+    if (!$img) {
716
+        return;
717
+    }
718
+    [$h, $l] = taille_image($img);
719 719
 
720
-	return $h;
720
+    return $h;
721 721
 }
722 722
 
723 723
 
@@ -737,11 +737,11 @@  discard block
 block discarded – undo
737 737
  * @return string
738 738
  **/
739 739
 function corriger_entites_html($texte) {
740
-	if (strpos($texte, '&amp;') === false) {
741
-		return $texte;
742
-	}
740
+    if (strpos($texte, '&amp;') === false) {
741
+        return $texte;
742
+    }
743 743
 
744
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
744
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
745 745
 }
746 746
 
747 747
 /**
@@ -756,11 +756,11 @@  discard block
 block discarded – undo
756 756
  * @return string
757 757
  **/
758 758
 function corriger_toutes_entites_html($texte) {
759
-	if (strpos($texte, '&amp;') === false) {
760
-		return $texte;
761
-	}
759
+    if (strpos($texte, '&amp;') === false) {
760
+        return $texte;
761
+    }
762 762
 
763
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
763
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
764 764
 }
765 765
 
766 766
 /**
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
  * @return string
771 771
  **/
772 772
 function proteger_amp($texte) {
773
-	return str_replace('&', '&amp;', $texte);
773
+    return str_replace('&', '&amp;', $texte);
774 774
 }
775 775
 
776 776
 
@@ -801,21 +801,21 @@  discard block
 block discarded – undo
801 801
  * @return mixed|string
802 802
  */
803 803
 function entites_html($texte, $tout = false, $quote = true) {
804
-	if (
805
-		!is_string($texte) or !$texte
806
-		or strpbrk($texte, "&\"'<>") == false
807
-	) {
808
-		return $texte;
809
-	}
810
-	include_spip('inc/texte');
811
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
812
-	$flags |= ENT_HTML401;
813
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
814
-	if ($tout) {
815
-		return corriger_toutes_entites_html($texte);
816
-	} else {
817
-		return corriger_entites_html($texte);
818
-	}
804
+    if (
805
+        !is_string($texte) or !$texte
806
+        or strpbrk($texte, "&\"'<>") == false
807
+    ) {
808
+        return $texte;
809
+    }
810
+    include_spip('inc/texte');
811
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
812
+    $flags |= ENT_HTML401;
813
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
814
+    if ($tout) {
815
+        return corriger_toutes_entites_html($texte);
816
+    } else {
817
+        return corriger_entites_html($texte);
818
+    }
819 819
 }
820 820
 
821 821
 /**
@@ -834,38 +834,38 @@  discard block
 block discarded – undo
834 834
  *     texte converti
835 835
  **/
836 836
 function filtrer_entites(?string $texte): string {
837
-	$texte ??= '';
838
-	if (strpos($texte, '&') === false) {
839
-		return $texte;
840
-	}
841
-	// filtrer
842
-	$texte = html2unicode($texte);
843
-	// remettre le tout dans le charset cible
844
-	$texte = unicode2charset($texte);
845
-	// cas particulier des " et ' qu'il faut filtrer aussi
846
-	// (on le faisait deja avec un &quot;)
847
-	if (strpos($texte, '&#') !== false) {
848
-		$texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
849
-	}
837
+    $texte ??= '';
838
+    if (strpos($texte, '&') === false) {
839
+        return $texte;
840
+    }
841
+    // filtrer
842
+    $texte = html2unicode($texte);
843
+    // remettre le tout dans le charset cible
844
+    $texte = unicode2charset($texte);
845
+    // cas particulier des " et ' qu'il faut filtrer aussi
846
+    // (on le faisait deja avec un &quot;)
847
+    if (strpos($texte, '&#') !== false) {
848
+        $texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
849
+    }
850 850
 
851
-	return $texte;
851
+    return $texte;
852 852
 }
853 853
 
854 854
 
855 855
 if (!function_exists('filtre_filtrer_entites_dist')) {
856
-	/**
857
-	 * Version sécurisée de filtrer_entites
858
-	 *
859
-	 * @uses interdire_scripts()
860
-	 * @uses filtrer_entites()
861
-	 *
862
-	 * @param string $t
863
-	 * @return string
864
-	 */
865
-	function filtre_filtrer_entites_dist($t) {
866
-		include_spip('inc/texte');
867
-		return interdire_scripts(filtrer_entites($t));
868
-	}
856
+    /**
857
+     * Version sécurisée de filtrer_entites
858
+     *
859
+     * @uses interdire_scripts()
860
+     * @uses filtrer_entites()
861
+     *
862
+     * @param string $t
863
+     * @return string
864
+     */
865
+    function filtre_filtrer_entites_dist($t) {
866
+        include_spip('inc/texte');
867
+        return interdire_scripts(filtrer_entites($t));
868
+    }
869 869
 }
870 870
 
871 871
 
@@ -880,18 +880,18 @@  discard block
 block discarded – undo
880 880
  * @return string|array
881 881
  **/
882 882
 function supprimer_caracteres_illegaux($texte) {
883
-	static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
884
-	static $to = null;
883
+    static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
884
+    static $to = null;
885 885
 
886
-	if (is_array($texte)) {
887
-		return array_map('supprimer_caracteres_illegaux', $texte);
888
-	}
886
+    if (is_array($texte)) {
887
+        return array_map('supprimer_caracteres_illegaux', $texte);
888
+    }
889 889
 
890
-	if (!$to) {
891
-		$to = str_repeat('-', strlen($from));
892
-	}
890
+    if (!$to) {
891
+        $to = str_repeat('-', strlen($from));
892
+    }
893 893
 
894
-	return strtr($texte, $from, $to);
894
+    return strtr($texte, $from, $to);
895 895
 }
896 896
 
897 897
 /**
@@ -903,10 +903,10 @@  discard block
 block discarded – undo
903 903
  * @return string|array
904 904
  **/
905 905
 function corriger_caracteres($texte) {
906
-	$texte = corriger_caracteres_windows($texte);
907
-	$texte = supprimer_caracteres_illegaux($texte);
906
+    $texte = corriger_caracteres_windows($texte);
907
+    $texte = supprimer_caracteres_illegaux($texte);
908 908
 
909
-	return $texte;
909
+    return $texte;
910 910
 }
911 911
 
912 912
 /**
@@ -923,44 +923,44 @@  discard block
 block discarded – undo
923 923
  *     texte encodé pour XML
924 924
  */
925 925
 function texte_backend(string $texte): string {
926
-	if ($texte === '') {
927
-		return '';
928
-	}
926
+    if ($texte === '') {
927
+        return '';
928
+    }
929 929
 
930
-	static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
930
+    static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
931 931
 
932
-	// si on a des liens ou des images, les passer en absolu
933
-	$texte = liens_absolus($texte);
932
+    // si on a des liens ou des images, les passer en absolu
933
+    $texte = liens_absolus($texte);
934 934
 
935
-	// echapper les tags &gt; &lt;
936
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
935
+    // echapper les tags &gt; &lt;
936
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
937 937
 
938
-	// importer les &eacute;
939
-	$texte = filtrer_entites($texte);
938
+    // importer les &eacute;
939
+    $texte = filtrer_entites($texte);
940 940
 
941
-	// " -> &quot; et tout ce genre de choses
942
-	$u = $GLOBALS['meta']['pcre_u'];
943
-	$texte = str_replace('&nbsp;', ' ', $texte);
944
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
945
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
946
-	$texte = entites_html($texte, false, false);
947
-	// mais bien echapper les double quotes !
948
-	$texte = str_replace('"', '&#034;', $texte);
941
+    // " -> &quot; et tout ce genre de choses
942
+    $u = $GLOBALS['meta']['pcre_u'];
943
+    $texte = str_replace('&nbsp;', ' ', $texte);
944
+    $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
945
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
946
+    $texte = entites_html($texte, false, false);
947
+    // mais bien echapper les double quotes !
948
+    $texte = str_replace('"', '&#034;', $texte);
949 949
 
950
-	// verifier le charset
951
-	$texte = charset2unicode($texte);
950
+    // verifier le charset
951
+    $texte = charset2unicode($texte);
952 952
 
953
-	// Caracteres problematiques en iso-latin 1
954
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
955
-		$texte = str_replace(chr(156), '&#156;', $texte);
956
-		$texte = str_replace(chr(140), '&#140;', $texte);
957
-		$texte = str_replace(chr(159), '&#159;', $texte);
958
-	}
953
+    // Caracteres problematiques en iso-latin 1
954
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
955
+        $texte = str_replace(chr(156), '&#156;', $texte);
956
+        $texte = str_replace(chr(140), '&#140;', $texte);
957
+        $texte = str_replace(chr(159), '&#159;', $texte);
958
+    }
959 959
 
960
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
961
-	// et le caractere apostrophe alourdit les squelettes avec PHP
962
-	// ==> on les remplace par l'entite HTML
963
-	return str_replace($apostrophe, "'", $texte);
960
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
961
+    // et le caractere apostrophe alourdit les squelettes avec PHP
962
+    // ==> on les remplace par l'entite HTML
963
+    return str_replace($apostrophe, "'", $texte);
964 964
 }
965 965
 
966 966
 /**
@@ -977,7 +977,7 @@  discard block
 block discarded – undo
977 977
  *     texte encodé et quote pour XML
978 978
  */
979 979
 function texte_backendq(string $texte): string {
980
-	return addslashes(texte_backend($texte));
980
+    return addslashes(texte_backend($texte));
981 981
 }
982 982
 
983 983
 
@@ -999,14 +999,14 @@  discard block
 block discarded – undo
999 999
  *     Texte sans son numéro éventuel
1000 1000
  **/
1001 1001
 function supprimer_numero(?string $texte): string {
1002
-	if ($texte === null) {
1003
-		return '';
1004
-	}
1005
-	return preg_replace(
1006
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1007
-		'',
1008
-		$texte
1009
-	);
1002
+    if ($texte === null) {
1003
+        return '';
1004
+    }
1005
+    return preg_replace(
1006
+        ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1007
+        '',
1008
+        $texte
1009
+    );
1010 1010
 }
1011 1011
 
1012 1012
 /**
@@ -1029,18 +1029,18 @@  discard block
 block discarded – undo
1029 1029
  *     Numéro de titre, sinon chaîne vide
1030 1030
  **/
1031 1031
 function recuperer_numero(?string $texte): string {
1032
-	if (
1033
-		$texte and
1034
-		preg_match(
1035
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1036
-			$texte,
1037
-			$regs
1038
-		)
1039
-	) {
1040
-		return strval($regs[1]);
1041
-	} else {
1042
-		return '';
1043
-	}
1032
+    if (
1033
+        $texte and
1034
+        preg_match(
1035
+            ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1036
+            $texte,
1037
+            $regs
1038
+        )
1039
+    ) {
1040
+        return strval($regs[1]);
1041
+    } else {
1042
+        return '';
1043
+    }
1044 1044
 }
1045 1045
 
1046 1046
 /**
@@ -1067,16 +1067,16 @@  discard block
 block discarded – undo
1067 1067
  *     texte ou tableau de textes converti
1068 1068
  **/
1069 1069
 function supprimer_tags($texte, $rempl = '') {
1070
-	if ($texte === null) {
1071
-		return '';
1072
-	}
1073
-	$texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1074
-	// ne pas oublier un < final non ferme car coupe
1075
-	$texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1076
-	// mais qui peut aussi etre un simple signe plus petit que
1077
-	$texte = str_replace('<', '&lt;', $texte);
1070
+    if ($texte === null) {
1071
+        return '';
1072
+    }
1073
+    $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1074
+    // ne pas oublier un < final non ferme car coupe
1075
+    $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1076
+    // mais qui peut aussi etre un simple signe plus petit que
1077
+    $texte = str_replace('<', '&lt;', $texte);
1078 1078
 
1079
-	return $texte;
1079
+    return $texte;
1080 1080
 }
1081 1081
 
1082 1082
 /**
@@ -1099,9 +1099,9 @@  discard block
 block discarded – undo
1099 1099
  *     texte converti
1100 1100
  **/
1101 1101
 function echapper_tags($texte, $rempl = '') {
1102
-	$texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1102
+    $texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1103 1103
 
1104
-	return $texte;
1104
+    return $texte;
1105 1105
 }
1106 1106
 
1107 1107
 /**
@@ -1122,18 +1122,18 @@  discard block
 block discarded – undo
1122 1122
  *     texte converti
1123 1123
  **/
1124 1124
 function textebrut($texte) {
1125
-	$u = $GLOBALS['meta']['pcre_u'];
1126
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1127
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1128
-	$texte = preg_replace("/^\n+/", '', $texte);
1129
-	$texte = preg_replace("/\n+$/", '', $texte);
1130
-	$texte = preg_replace("/\n +/", "\n", $texte);
1131
-	$texte = supprimer_tags($texte);
1132
-	$texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1133
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1134
-	$texte = str_replace('&#8217;', "'", $texte);
1125
+    $u = $GLOBALS['meta']['pcre_u'];
1126
+    $texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1127
+    $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1128
+    $texte = preg_replace("/^\n+/", '', $texte);
1129
+    $texte = preg_replace("/\n+$/", '', $texte);
1130
+    $texte = preg_replace("/\n +/", "\n", $texte);
1131
+    $texte = supprimer_tags($texte);
1132
+    $texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1133
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1134
+    $texte = str_replace('&#8217;', "'", $texte);
1135 1135
 
1136
-	return $texte;
1136
+    return $texte;
1137 1137
 }
1138 1138
 
1139 1139
 
@@ -1149,23 +1149,23 @@  discard block
 block discarded – undo
1149 1149
  *     texte avec liens ouvrants
1150 1150
  **/
1151 1151
 function liens_ouvrants($texte) {
1152
-	if (
1153
-		preg_match_all(
1154
-			",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1155
-			$texte,
1156
-			$liens,
1157
-			PREG_PATTERN_ORDER
1158
-		)
1159
-	) {
1160
-		foreach ($liens[0] as $a) {
1161
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1162
-			$ablank = inserer_attribut($a, 'rel', $rel);
1163
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1164
-			$texte = str_replace($a, $ablank, $texte);
1165
-		}
1166
-	}
1167
-
1168
-	return $texte;
1152
+    if (
1153
+        preg_match_all(
1154
+            ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1155
+            $texte,
1156
+            $liens,
1157
+            PREG_PATTERN_ORDER
1158
+        )
1159
+    ) {
1160
+        foreach ($liens[0] as $a) {
1161
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1162
+            $ablank = inserer_attribut($a, 'rel', $rel);
1163
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1164
+            $texte = str_replace($a, $ablank, $texte);
1165
+        }
1166
+    }
1167
+
1168
+    return $texte;
1169 1169
 }
1170 1170
 
1171 1171
 /**
@@ -1175,22 +1175,22 @@  discard block
 block discarded – undo
1175 1175
  * @return string
1176 1176
  */
1177 1177
 function liens_nofollow($texte) {
1178
-	if (stripos($texte, '<a') === false) {
1179
-		return $texte;
1180
-	}
1178
+    if (stripos($texte, '<a') === false) {
1179
+        return $texte;
1180
+    }
1181 1181
 
1182
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1183
-		foreach ($regs[0] as $a) {
1184
-			$rel = extraire_attribut($a, 'rel') ?? '';
1185
-			if (strpos($rel, 'nofollow') === false) {
1186
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1187
-				$anofollow = inserer_attribut($a, 'rel', $rel);
1188
-				$texte = str_replace($a, $anofollow, $texte);
1189
-			}
1190
-		}
1191
-	}
1182
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1183
+        foreach ($regs[0] as $a) {
1184
+            $rel = extraire_attribut($a, 'rel') ?? '';
1185
+            if (strpos($rel, 'nofollow') === false) {
1186
+                $rel = 'nofollow' . ($rel ? " $rel" : '');
1187
+                $anofollow = inserer_attribut($a, 'rel', $rel);
1188
+                $texte = str_replace($a, $anofollow, $texte);
1189
+            }
1190
+        }
1191
+    }
1192 1192
 
1193
-	return $texte;
1193
+    return $texte;
1194 1194
 }
1195 1195
 
1196 1196
 /**
@@ -1209,12 +1209,12 @@  discard block
 block discarded – undo
1209 1209
  *     texte sans paraghaphes
1210 1210
  **/
1211 1211
 function PtoBR($texte) {
1212
-	$u = $GLOBALS['meta']['pcre_u'];
1213
-	$texte = preg_replace('@</p>@iS', "\n", $texte);
1214
-	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1215
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1212
+    $u = $GLOBALS['meta']['pcre_u'];
1213
+    $texte = preg_replace('@</p>@iS', "\n", $texte);
1214
+    $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1215
+    $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1216 1216
 
1217
-	return $texte;
1217
+    return $texte;
1218 1218
 }
1219 1219
 
1220 1220
 
@@ -1239,19 +1239,19 @@  discard block
 block discarded – undo
1239 1239
  * @return string texte encadré du style CSS
1240 1240
  */
1241 1241
 function lignes_longues($texte) {
1242
-	trigger_error(
1243
-		sprintf('Usage of function or filter \'%s\' is deprecated. Use CSS instead.', __FUNCTION__),
1244
-		\E_USER_DEPRECATED
1245
-	);
1242
+    trigger_error(
1243
+        sprintf('Usage of function or filter \'%s\' is deprecated. Use CSS instead.', __FUNCTION__),
1244
+        \E_USER_DEPRECATED
1245
+    );
1246 1246
 
1247
-	if (!strlen(trim($texte))) {
1248
-		return $texte;
1249
-	}
1250
-	include_spip('inc/texte');
1251
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1252
-		'div' : 'span';
1247
+    if (!strlen(trim($texte))) {
1248
+        return $texte;
1249
+    }
1250
+    include_spip('inc/texte');
1251
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1252
+        'div' : 'span';
1253 1253
 
1254
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1254
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1255 1255
 }
1256 1256
 
1257 1257
 /**
@@ -1270,30 +1270,30 @@  discard block
 block discarded – undo
1270 1270
  * @return string texte en majuscule
1271 1271
  */
1272 1272
 function majuscules($texte) {
1273
-	if (!strlen($texte)) {
1274
-		return '';
1275
-	}
1273
+    if (!strlen($texte)) {
1274
+        return '';
1275
+    }
1276 1276
 
1277
-	// Cas du turc
1278
-	if ($GLOBALS['spip_lang'] == 'tr') {
1279
-		# remplacer hors des tags et des entites
1280
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1281
-			foreach ($regs as $n => $match) {
1282
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1283
-			}
1284
-		}
1277
+    // Cas du turc
1278
+    if ($GLOBALS['spip_lang'] == 'tr') {
1279
+        # remplacer hors des tags et des entites
1280
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1281
+            foreach ($regs as $n => $match) {
1282
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1283
+            }
1284
+        }
1285 1285
 
1286
-		$texte = str_replace('i', '&#304;', $texte);
1286
+        $texte = str_replace('i', '&#304;', $texte);
1287 1287
 
1288
-		if ($regs) {
1289
-			foreach ($regs as $n => $match) {
1290
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1291
-			}
1292
-		}
1293
-	}
1288
+        if ($regs) {
1289
+            foreach ($regs as $n => $match) {
1290
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1291
+            }
1292
+        }
1293
+    }
1294 1294
 
1295
-	// Cas general
1296
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1295
+    // Cas general
1296
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1297 1297
 }
1298 1298
 
1299 1299
 /**
@@ -1315,38 +1315,38 @@  discard block
 block discarded – undo
1315 1315
  */
1316 1316
 function taille_en_octets($octets, $systeme = 'BI') {
1317 1317
 
1318
-	// Texte à afficher pour la taille
1319
-	$affichage = '';
1318
+    // Texte à afficher pour la taille
1319
+    $affichage = '';
1320 1320
 
1321
-	static $unites = ['octets', 'ko', 'mo', 'go'];
1322
-	static $precisions = [0, 1, 1, 2];
1321
+    static $unites = ['octets', 'ko', 'mo', 'go'];
1322
+    static $precisions = [0, 1, 1, 2];
1323 1323
 
1324
-	if ($octets >= 1) {
1325
-		// Déterminer le nombre d'octets représentant le kilo en fonction du système choisi
1326
-		$systeme = strtolower($systeme);
1327
-		if ($systeme === 'bi') {
1328
-			$kilo = 1024;
1329
-			$suffixe_item = "_$systeme";
1330
-		} elseif ($systeme === 'si') {
1331
-			$kilo = 1000;
1332
-			$suffixe_item = '';
1333
-		} else {
1334
-			return $affichage;
1335
-		}
1324
+    if ($octets >= 1) {
1325
+        // Déterminer le nombre d'octets représentant le kilo en fonction du système choisi
1326
+        $systeme = strtolower($systeme);
1327
+        if ($systeme === 'bi') {
1328
+            $kilo = 1024;
1329
+            $suffixe_item = "_$systeme";
1330
+        } elseif ($systeme === 'si') {
1331
+            $kilo = 1000;
1332
+            $suffixe_item = '';
1333
+        } else {
1334
+            return $affichage;
1335
+        }
1336 1336
 
1337
-		// Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée
1338
-		$puissance = floor(log($octets, $kilo));
1337
+        // Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée
1338
+        $puissance = floor(log($octets, $kilo));
1339 1339
 
1340
-		// Calcul de la taille et choix de l'unité
1341
-		$affichage = _T(
1342
-			'spip:taille_' . $unites[$puissance] . $suffixe_item,
1343
-			[
1344
-				'taille' => round($octets / pow($kilo, $puissance), $precisions[$puissance])
1345
-			]
1346
-		);
1347
-	}
1340
+        // Calcul de la taille et choix de l'unité
1341
+        $affichage = _T(
1342
+            'spip:taille_' . $unites[$puissance] . $suffixe_item,
1343
+            [
1344
+                'taille' => round($octets / pow($kilo, $puissance), $precisions[$puissance])
1345
+            ]
1346
+        );
1347
+    }
1348 1348
 
1349
-	return $affichage;
1349
+    return $affichage;
1350 1350
 }
1351 1351
 
1352 1352
 
@@ -1368,21 +1368,21 @@  discard block
 block discarded – undo
1368 1368
  *     texte prêt pour être utilisé en attribut HTML
1369 1369
  **/
1370 1370
 function attribut_html(?string $texte, $textebrut = true): string {
1371
-	if ($texte === null) {
1372
-		return '';
1373
-	}
1374
-	$u = $GLOBALS['meta']['pcre_u'];
1375
-	if ($textebrut) {
1376
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1377
-	}
1378
-	$texte = texte_backend($texte);
1379
-	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1371
+    if ($texte === null) {
1372
+        return '';
1373
+    }
1374
+    $u = $GLOBALS['meta']['pcre_u'];
1375
+    if ($textebrut) {
1376
+        $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1377
+    }
1378
+    $texte = texte_backend($texte);
1379
+    $texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1380 1380
 
1381
-	return preg_replace(
1382
-		['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1383
-		['&', '&#38;'],
1384
-		$texte
1385
-	);
1381
+    return preg_replace(
1382
+        ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1383
+        ['&', '&#38;'],
1384
+        $texte
1385
+    );
1386 1386
 }
1387 1387
 
1388 1388
 
@@ -1402,15 +1402,15 @@  discard block
 block discarded – undo
1402 1402
  *     URL ou chaîne vide
1403 1403
  **/
1404 1404
 function vider_url(?string $url, $entites = true): string {
1405
-	if ($url === null) {
1406
-		return '';
1407
-	}
1408
-	# un message pour abs_url
1409
-	$GLOBALS['mode_abs_url'] = 'url';
1410
-	$url = trim($url);
1411
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1405
+    if ($url === null) {
1406
+        return '';
1407
+    }
1408
+    # un message pour abs_url
1409
+    $GLOBALS['mode_abs_url'] = 'url';
1410
+    $url = trim($url);
1411
+    $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1412 1412
 
1413
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1413
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1414 1414
 }
1415 1415
 
1416 1416
 
@@ -1425,10 +1425,10 @@  discard block
 block discarded – undo
1425 1425
  * @return string Adresse email maquillée
1426 1426
  **/
1427 1427
 function antispam($texte) {
1428
-	include_spip('inc/acces');
1429
-	$masque = creer_pass_aleatoire(3);
1428
+    include_spip('inc/acces');
1429
+    $masque = creer_pass_aleatoire(3);
1430 1430
 
1431
-	return preg_replace('/@/', " $masque ", $texte);
1431
+    return preg_replace('/@/', " $masque ", $texte);
1432 1432
 }
1433 1433
 
1434 1434
 /**
@@ -1460,8 +1460,8 @@  discard block
 block discarded – undo
1460 1460
  *     True si on a le droit d'accès, false sinon.
1461 1461
  **/
1462 1462
 function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') {
1463
-	include_spip('inc/acces');
1464
-	return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1463
+    include_spip('inc/acces');
1464
+    return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1465 1465
 }
1466 1466
 
1467 1467
 /**
@@ -1485,13 +1485,13 @@  discard block
 block discarded – undo
1485 1485
  *     Retourne $texte, sinon $sinon.
1486 1486
  **/
1487 1487
 function sinon($texte, $sinon = '') {
1488
-	if ($texte) {
1489
-		return $texte;
1490
-	} elseif (is_scalar($texte) and strlen($texte)) {
1491
-		return $texte;
1492
-	} else {
1493
-		return $sinon;
1494
-	}
1488
+    if ($texte) {
1489
+        return $texte;
1490
+    } elseif (is_scalar($texte) and strlen($texte)) {
1491
+        return $texte;
1492
+    } else {
1493
+        return $sinon;
1494
+    }
1495 1495
 }
1496 1496
 
1497 1497
 /**
@@ -1515,7 +1515,7 @@  discard block
 block discarded – undo
1515 1515
  * @return mixed
1516 1516
  **/
1517 1517
 function choixsivide($a, $vide, $pasvide) {
1518
-	return $a ? $pasvide : $vide;
1518
+    return $a ? $pasvide : $vide;
1519 1519
 }
1520 1520
 
1521 1521
 /**
@@ -1539,7 +1539,7 @@  discard block
 block discarded – undo
1539 1539
  * @return mixed
1540 1540
  **/
1541 1541
 function choixsiegal($a1, $a2, $v, $f) {
1542
-	return ($a1 == $a2) ? $v : $f;
1542
+    return ($a1 == $a2) ? $v : $f;
1543 1543
 }
1544 1544
 
1545 1545
 //
@@ -1558,13 +1558,13 @@  discard block
 block discarded – undo
1558 1558
  * @return string
1559 1559
  **/
1560 1560
 function filtrer_ical($texte) {
1561
-	#include_spip('inc/charsets');
1562
-	$texte = html2unicode($texte);
1563
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1564
-	$texte = preg_replace("/\n/", ' ', $texte);
1565
-	$texte = preg_replace('/,/', '\,', $texte);
1561
+    #include_spip('inc/charsets');
1562
+    $texte = html2unicode($texte);
1563
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1564
+    $texte = preg_replace("/\n/", ' ', $texte);
1565
+    $texte = preg_replace('/,/', '\,', $texte);
1566 1566
 
1567
-	return $texte;
1567
+    return $texte;
1568 1568
 }
1569 1569
 
1570 1570
 
@@ -1589,58 +1589,58 @@  discard block
 block discarded – undo
1589 1589
  * @return string
1590 1590
  **/
1591 1591
 function post_autobr($texte, $delim = "\n_ ") {
1592
-	if (!function_exists('echappe_html')) {
1593
-		include_spip('inc/texte_mini');
1594
-	}
1595
-	$texte = str_replace("\r\n", "\r", $texte);
1596
-	$texte = str_replace("\r", "\n", $texte);
1597
-
1598
-	if (preg_match(",\n+$,", $texte, $fin)) {
1599
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1600
-	} else {
1601
-		$fin = '';
1602
-	}
1603
-
1604
-	$texte = echappe_html($texte, '', true);
1605
-
1606
-	// echapper les modeles
1607
-	$collecteurModeles = null;
1608
-	if (strpos($texte, '<') !== false) {
1609
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
1610
-		include_spip("src/Texte/Collecteur/Modeles");
1611
-		$collecteurModeles = new Spip\Texte\Collecteur\Modeles();
1612
-		$texte = $collecteurModeles->echapper($texte);
1613
-	}
1614
-
1615
-	$debut = '';
1616
-	$suite = $texte;
1617
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1618
-		$debut .= substr($suite, 0, $t - 1);
1619
-		$suite = substr($suite, $t);
1620
-		$car = substr($suite, 0, 1);
1621
-		if (
1622
-			($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1623
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1624
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1625
-		) {
1626
-			$debut .= $delim;
1627
-		} else {
1628
-			$debut .= "\n";
1629
-		}
1630
-		if (preg_match(",^\n+,", $suite, $regs)) {
1631
-			$debut .= $regs[0];
1632
-			$suite = substr($suite, strlen($regs[0]));
1633
-		}
1634
-	}
1635
-	$texte = $debut . $suite;
1636
-
1637
-	if ($collecteurModeles) {
1638
-		$texte = $collecteurModeles->retablir($texte);
1639
-	}
1640
-
1641
-	$texte = echappe_retour($texte);
1642
-
1643
-	return $texte . $fin;
1592
+    if (!function_exists('echappe_html')) {
1593
+        include_spip('inc/texte_mini');
1594
+    }
1595
+    $texte = str_replace("\r\n", "\r", $texte);
1596
+    $texte = str_replace("\r", "\n", $texte);
1597
+
1598
+    if (preg_match(",\n+$,", $texte, $fin)) {
1599
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1600
+    } else {
1601
+        $fin = '';
1602
+    }
1603
+
1604
+    $texte = echappe_html($texte, '', true);
1605
+
1606
+    // echapper les modeles
1607
+    $collecteurModeles = null;
1608
+    if (strpos($texte, '<') !== false) {
1609
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
1610
+        include_spip("src/Texte/Collecteur/Modeles");
1611
+        $collecteurModeles = new Spip\Texte\Collecteur\Modeles();
1612
+        $texte = $collecteurModeles->echapper($texte);
1613
+    }
1614
+
1615
+    $debut = '';
1616
+    $suite = $texte;
1617
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1618
+        $debut .= substr($suite, 0, $t - 1);
1619
+        $suite = substr($suite, $t);
1620
+        $car = substr($suite, 0, 1);
1621
+        if (
1622
+            ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1623
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1624
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1625
+        ) {
1626
+            $debut .= $delim;
1627
+        } else {
1628
+            $debut .= "\n";
1629
+        }
1630
+        if (preg_match(",^\n+,", $suite, $regs)) {
1631
+            $debut .= $regs[0];
1632
+            $suite = substr($suite, strlen($regs[0]));
1633
+        }
1634
+    }
1635
+    $texte = $debut . $suite;
1636
+
1637
+    if ($collecteurModeles) {
1638
+        $texte = $collecteurModeles->retablir($texte);
1639
+    }
1640
+
1641
+    $texte = echappe_retour($texte);
1642
+
1643
+    return $texte . $fin;
1644 1644
 }
1645 1645
 
1646 1646
 
@@ -1675,30 +1675,30 @@  discard block
 block discarded – undo
1675 1675
  **/
1676 1676
 function extraire_idiome($letexte, $lang = null, $options = []) {
1677 1677
 
1678
-	if (
1679
-		$letexte
1680
-		and strpos($letexte, '<:') !== false
1681
-	) {
1682
-		if (!$lang) {
1683
-			$lang = $GLOBALS['spip_lang'];
1684
-		}
1685
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1686
-		if (is_bool($options)) {
1687
-			$options = ['echappe_span' => $options];
1688
-		}
1689
-		if (!isset($options['echappe_span'])) {
1690
-			$options = array_merge($options, ['echappe_span' => false]);
1691
-		}
1692
-		$options['lang'] = $lang;
1678
+    if (
1679
+        $letexte
1680
+        and strpos($letexte, '<:') !== false
1681
+    ) {
1682
+        if (!$lang) {
1683
+            $lang = $GLOBALS['spip_lang'];
1684
+        }
1685
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1686
+        if (is_bool($options)) {
1687
+            $options = ['echappe_span' => $options];
1688
+        }
1689
+        if (!isset($options['echappe_span'])) {
1690
+            $options = array_merge($options, ['echappe_span' => false]);
1691
+        }
1692
+        $options['lang'] = $lang;
1693 1693
 
1694
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
1695
-		include_spip("src/Texte/Collecteur/Idiomes");
1696
-		$collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes();
1694
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
1695
+        include_spip("src/Texte/Collecteur/Idiomes");
1696
+        $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes();
1697 1697
 
1698
-		$letexte = $collecteurIdiomes->traiter($letexte, $options);
1698
+        $letexte = $collecteurIdiomes->traiter($letexte, $options);
1699 1699
 
1700
-	}
1701
-	return $letexte;
1700
+    }
1701
+    return $letexte;
1702 1702
 }
1703 1703
 
1704 1704
 /**
@@ -1736,34 +1736,34 @@  discard block
 block discarded – undo
1736 1736
  **/
1737 1737
 function extraire_multi($letexte, $lang = null, $options = []) {
1738 1738
 
1739
-	if (
1740
-		$letexte
1741
-		and stripos($letexte, '<multi') !== false
1742
-	) {
1743
-		if (!$lang) {
1744
-			$lang = $GLOBALS['spip_lang'];
1745
-		}
1739
+    if (
1740
+        $letexte
1741
+        and stripos($letexte, '<multi') !== false
1742
+    ) {
1743
+        if (!$lang) {
1744
+            $lang = $GLOBALS['spip_lang'];
1745
+        }
1746 1746
 
1747
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1748
-		if (is_bool($options)) {
1749
-			$options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1750
-		}
1751
-		if (!isset($options['echappe_span'])) {
1752
-			$options = array_merge($options, ['echappe_span' => false]);
1753
-		}
1754
-		if (!isset($options['lang_defaut'])) {
1755
-			$options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1756
-		}
1757
-		$options['lang'] = $lang;
1747
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1748
+        if (is_bool($options)) {
1749
+            $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1750
+        }
1751
+        if (!isset($options['echappe_span'])) {
1752
+            $options = array_merge($options, ['echappe_span' => false]);
1753
+        }
1754
+        if (!isset($options['lang_defaut'])) {
1755
+            $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1756
+        }
1757
+        $options['lang'] = $lang;
1758 1758
 
1759
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
1760
-		include_spip("src/Texte/Collecteur/Multis");
1761
-		$collecteurMultis = new Spip\Texte\Collecteur\Multis();
1759
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
1760
+        include_spip("src/Texte/Collecteur/Multis");
1761
+        $collecteurMultis = new Spip\Texte\Collecteur\Multis();
1762 1762
 
1763
-		$letexte = $collecteurMultis->traiter($letexte, $options);
1764
-	}
1763
+        $letexte = $collecteurMultis->traiter($letexte, $options);
1764
+    }
1765 1765
 
1766
-	return $letexte;
1766
+    return $letexte;
1767 1767
 }
1768 1768
 
1769 1769
 /**
@@ -1773,7 +1773,7 @@  discard block
 block discarded – undo
1773 1773
  * @return string L'initiale en majuscule
1774 1774
  */
1775 1775
 function filtre_initiale($nom) {
1776
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1776
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1777 1777
 }
1778 1778
 
1779 1779
 
@@ -1818,33 +1818,33 @@  discard block
 block discarded – undo
1818 1818
  *      - null (interne) : si on empile
1819 1819
  **/
1820 1820
 function unique($donnee, $famille = '', $cpt = false) {
1821
-	static $mem = [];
1822
-	// permettre de vider la pile et de la restaurer
1823
-	// pour le calcul de introduction...
1824
-	if ($famille == '_spip_raz_') {
1825
-		$tmp = $mem;
1826
-		$mem = [];
1827
-
1828
-		return $tmp;
1829
-	} elseif ($famille == '_spip_set_') {
1830
-		$mem = $donnee;
1831
-
1832
-		return;
1833
-	}
1834
-	// eviter une notice
1835
-	if (!isset($mem[$famille])) {
1836
-		$mem[$famille] = [];
1837
-	}
1838
-	if ($cpt) {
1839
-		return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1840
-	}
1841
-	// eviter une notice
1842
-	if (!isset($mem[$famille][$donnee])) {
1843
-		$mem[$famille][$donnee] = 0;
1844
-	}
1845
-	if (!($mem[$famille][$donnee]++)) {
1846
-		return $donnee;
1847
-	}
1821
+    static $mem = [];
1822
+    // permettre de vider la pile et de la restaurer
1823
+    // pour le calcul de introduction...
1824
+    if ($famille == '_spip_raz_') {
1825
+        $tmp = $mem;
1826
+        $mem = [];
1827
+
1828
+        return $tmp;
1829
+    } elseif ($famille == '_spip_set_') {
1830
+        $mem = $donnee;
1831
+
1832
+        return;
1833
+    }
1834
+    // eviter une notice
1835
+    if (!isset($mem[$famille])) {
1836
+        $mem[$famille] = [];
1837
+    }
1838
+    if ($cpt) {
1839
+        return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1840
+    }
1841
+    // eviter une notice
1842
+    if (!isset($mem[$famille][$donnee])) {
1843
+        $mem[$famille][$donnee] = 0;
1844
+    }
1845
+    if (!($mem[$famille][$donnee]++)) {
1846
+        return $donnee;
1847
+    }
1848 1848
 }
1849 1849
 
1850 1850
 
@@ -1874,20 +1874,20 @@  discard block
 block discarded – undo
1874 1874
  *     Une des valeurs en fonction du compteur.
1875 1875
  **/
1876 1876
 function alterner($i, ...$args) {
1877
-	// recuperer les arguments (attention fonctions un peu space)
1878
-	$num = count($args);
1877
+    // recuperer les arguments (attention fonctions un peu space)
1878
+    $num = count($args);
1879 1879
 
1880
-	if ($num === 1 && is_array($args[0])) {
1881
-		// un tableau de valeur dont les cles sont numerotees de 0 a num
1882
-		$args = array_values($args[0]);
1883
-		$num = count($args);
1884
-	}
1880
+    if ($num === 1 && is_array($args[0])) {
1881
+        // un tableau de valeur dont les cles sont numerotees de 0 a num
1882
+        $args = array_values($args[0]);
1883
+        $num = count($args);
1884
+    }
1885 1885
 
1886
-	// un index compris entre 0 et num exclus
1887
-	$i = ((intval($i) - 1) % $num); // dans ]-$num;$num[
1888
-	$i = ($i + $num) % $num; // dans [0;$num[
1889
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1890
-	return $args[$i];
1886
+    // un index compris entre 0 et num exclus
1887
+    $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[
1888
+    $i = ($i + $num) % $num; // dans [0;$num[
1889
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1890
+    return $args[$i];
1891 1891
 }
1892 1892
 
1893 1893
 
@@ -1913,52 +1913,52 @@  discard block
 block discarded – undo
1913 1913
  *     - null lorsque l’attribut n’existe pas.
1914 1914
  **/
1915 1915
 function extraire_attribut($balise, $attribut, $complet = false) {
1916
-	if (is_array($balise)) {
1917
-		array_walk(
1918
-			$balise,
1919
-			function (&$a, $key, $t) {
1920
-				$a = extraire_attribut($a, $t);
1921
-			},
1922
-			$attribut
1923
-		);
1924
-
1925
-		return $balise;
1926
-	}
1927
-	if (
1928
-		$balise
1929
-		&& stripos($balise, $attribut) !== false
1930
-		&& preg_match(
1931
-			',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1932
-			. $attribut
1933
-			. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1934
-			$balise,
1935
-			$r
1936
-		)
1937
-	) {
1938
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1939
-			$r[4] = substr($r[3], 1, -1);
1940
-			$r[3] = $r[3][0];
1941
-		} elseif ($r[3] !== '') {
1942
-			$r[4] = $r[3];
1943
-			$r[3] = '';
1944
-		} else {
1945
-			$r[4] = trim($r[2]);
1946
-		}
1947
-		$att = $r[4];
1948
-		if (strpos($att, '&#') !== false) {
1949
-			$att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1950
-		}
1951
-		$att = filtrer_entites($att);
1952
-	} else {
1953
-		$att = null;
1954
-		$r = [];
1955
-	}
1956
-
1957
-	if ($complet) {
1958
-		return [$att, $r];
1959
-	} else {
1960
-		return $att;
1961
-	}
1916
+    if (is_array($balise)) {
1917
+        array_walk(
1918
+            $balise,
1919
+            function (&$a, $key, $t) {
1920
+                $a = extraire_attribut($a, $t);
1921
+            },
1922
+            $attribut
1923
+        );
1924
+
1925
+        return $balise;
1926
+    }
1927
+    if (
1928
+        $balise
1929
+        && stripos($balise, $attribut) !== false
1930
+        && preg_match(
1931
+            ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1932
+            . $attribut
1933
+            . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1934
+            $balise,
1935
+            $r
1936
+        )
1937
+    ) {
1938
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1939
+            $r[4] = substr($r[3], 1, -1);
1940
+            $r[3] = $r[3][0];
1941
+        } elseif ($r[3] !== '') {
1942
+            $r[4] = $r[3];
1943
+            $r[3] = '';
1944
+        } else {
1945
+            $r[4] = trim($r[2]);
1946
+        }
1947
+        $att = $r[4];
1948
+        if (strpos($att, '&#') !== false) {
1949
+            $att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1950
+        }
1951
+        $att = filtrer_entites($att);
1952
+    } else {
1953
+        $att = null;
1954
+        $r = [];
1955
+    }
1956
+
1957
+    if ($complet) {
1958
+        return [$att, $r];
1959
+    } else {
1960
+        return $att;
1961
+    }
1962 1962
 }
1963 1963
 
1964 1964
 /**
@@ -1991,41 +1991,41 @@  discard block
 block discarded – undo
1991 1991
  **/
1992 1992
 function inserer_attribut(?string $balise, string $attribut, ?string $val, bool $proteger = true, bool $vider = false): string {
1993 1993
 
1994
-	if ($balise === null or $balise === '') {
1995
-		return '';
1996
-	}
1994
+    if ($balise === null or $balise === '') {
1995
+        return '';
1996
+    }
1997 1997
 
1998
-	// preparer l'attribut
1999
-	// supprimer les &nbsp; etc mais pas les balises html
2000
-	// qui ont un sens dans un attribut value d'un input
2001
-	if ($proteger) {
2002
-		$val = attribut_html($val, false);
2003
-	}
1998
+    // preparer l'attribut
1999
+    // supprimer les &nbsp; etc mais pas les balises html
2000
+    // qui ont un sens dans un attribut value d'un input
2001
+    if ($proteger) {
2002
+        $val = attribut_html($val, false);
2003
+    }
2004 2004
 
2005
-	// echapper les ' pour eviter tout bug
2006
-	$val = str_replace("'", '&#039;', $val ?? '');
2007
-	if ($vider and strlen($val) === 0) {
2008
-		$insert = '';
2009
-	} else {
2010
-		$insert = " $attribut='$val'";
2011
-	}
2005
+    // echapper les ' pour eviter tout bug
2006
+    $val = str_replace("'", '&#039;', $val ?? '');
2007
+    if ($vider and strlen($val) === 0) {
2008
+        $insert = '';
2009
+    } else {
2010
+        $insert = " $attribut='$val'";
2011
+    }
2012 2012
 
2013
-	[$old, $r] = extraire_attribut($balise, $attribut, true);
2013
+    [$old, $r] = extraire_attribut($balise, $attribut, true);
2014 2014
 
2015
-	if ($old !== null) {
2016
-		// Remplacer l'ancien attribut du meme nom
2017
-		$balise = $r[1] . $insert . $r[5];
2018
-	} else {
2019
-		// preferer une balise " />" (comme <img />)
2020
-		if (preg_match(',/>,', $balise)) {
2021
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2022
-		} // sinon une balise <a ...> ... </a>
2023
-		else {
2024
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2025
-		}
2026
-	}
2015
+    if ($old !== null) {
2016
+        // Remplacer l'ancien attribut du meme nom
2017
+        $balise = $r[1] . $insert . $r[5];
2018
+    } else {
2019
+        // preferer une balise " />" (comme <img />)
2020
+        if (preg_match(',/>,', $balise)) {
2021
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2022
+        } // sinon une balise <a ...> ... </a>
2023
+        else {
2024
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2025
+        }
2026
+    }
2027 2027
 
2028
-	return $balise;
2028
+    return $balise;
2029 2029
 }
2030 2030
 
2031 2031
 /**
@@ -2043,7 +2043,7 @@  discard block
 block discarded – undo
2043 2043
  * @return string Code HTML sans l'attribut
2044 2044
  **/
2045 2045
 function vider_attribut(?string $balise, string $attribut): string {
2046
-	return inserer_attribut($balise, $attribut, '', false, true);
2046
+    return inserer_attribut($balise, $attribut, '', false, true);
2047 2047
 }
2048 2048
 
2049 2049
 /**
@@ -2055,50 +2055,50 @@  discard block
 block discarded – undo
2055 2055
  * @return string
2056 2056
  */
2057 2057
 function modifier_class($balise, $class, $operation = 'ajouter') {
2058
-	if (is_string($class)) {
2059
-		$class = explode(' ', trim($class));
2060
-	}
2061
-	$class = array_filter($class);
2062
-	$class = array_unique($class);
2063
-	if (!$class) {
2064
-		return $balise;
2065
-	}
2066
-
2067
-	$class_courante = extraire_attribut($balise, 'class');
2068
-	$class_new = $class_courante;
2069
-	foreach ($class as $c) {
2070
-		$is_class_presente = false;
2071
-		if (
2072
-			$class_courante
2073
-			and str_contains($class_courante, (string) $c)
2074
-			and in_array($c, preg_split(",\s+,", $class_courante))
2075
-		) {
2076
-			$is_class_presente = true;
2077
-		}
2078
-		if (
2079
-			in_array($operation, ['ajouter', 'commuter'])
2080
-			and !$is_class_presente
2081
-		) {
2082
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2083
-		} elseif (
2084
-			in_array($operation, ['supprimer', 'commuter'])
2085
-			and $is_class_presente
2086
-		) {
2087
-			$class_new = preg_split(",\s+,", $class_new);
2088
-			$class_new = array_diff($class_new, [$c]);
2089
-			$class_new = implode(' ', $class_new);
2090
-		}
2091
-	}
2092
-
2093
-	if ($class_new !== $class_courante) {
2094
-		if (strlen($class_new)) {
2095
-			$balise = inserer_attribut($balise, 'class', $class_new);
2096
-		} elseif ($class_courante) {
2097
-			$balise = vider_attribut($balise, 'class');
2098
-		}
2099
-	}
2100
-
2101
-	return $balise;
2058
+    if (is_string($class)) {
2059
+        $class = explode(' ', trim($class));
2060
+    }
2061
+    $class = array_filter($class);
2062
+    $class = array_unique($class);
2063
+    if (!$class) {
2064
+        return $balise;
2065
+    }
2066
+
2067
+    $class_courante = extraire_attribut($balise, 'class');
2068
+    $class_new = $class_courante;
2069
+    foreach ($class as $c) {
2070
+        $is_class_presente = false;
2071
+        if (
2072
+            $class_courante
2073
+            and str_contains($class_courante, (string) $c)
2074
+            and in_array($c, preg_split(",\s+,", $class_courante))
2075
+        ) {
2076
+            $is_class_presente = true;
2077
+        }
2078
+        if (
2079
+            in_array($operation, ['ajouter', 'commuter'])
2080
+            and !$is_class_presente
2081
+        ) {
2082
+            $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2083
+        } elseif (
2084
+            in_array($operation, ['supprimer', 'commuter'])
2085
+            and $is_class_presente
2086
+        ) {
2087
+            $class_new = preg_split(",\s+,", $class_new);
2088
+            $class_new = array_diff($class_new, [$c]);
2089
+            $class_new = implode(' ', $class_new);
2090
+        }
2091
+    }
2092
+
2093
+    if ($class_new !== $class_courante) {
2094
+        if (strlen($class_new)) {
2095
+            $balise = inserer_attribut($balise, 'class', $class_new);
2096
+        } elseif ($class_courante) {
2097
+            $balise = vider_attribut($balise, 'class');
2098
+        }
2099
+    }
2100
+
2101
+    return $balise;
2102 2102
 }
2103 2103
 
2104 2104
 /**
@@ -2108,7 +2108,7 @@  discard block
 block discarded – undo
2108 2108
  * @return string
2109 2109
  */
2110 2110
 function ajouter_class($balise, $class) {
2111
-	return modifier_class($balise, $class, 'ajouter');
2111
+    return modifier_class($balise, $class, 'ajouter');
2112 2112
 }
2113 2113
 
2114 2114
 /**
@@ -2118,7 +2118,7 @@  discard block
 block discarded – undo
2118 2118
  * @return string
2119 2119
  */
2120 2120
 function supprimer_class($balise, $class) {
2121
-	return modifier_class($balise, $class, 'supprimer');
2121
+    return modifier_class($balise, $class, 'supprimer');
2122 2122
 }
2123 2123
 
2124 2124
 /**
@@ -2129,7 +2129,7 @@  discard block
 block discarded – undo
2129 2129
  * @return string
2130 2130
  */
2131 2131
 function commuter_class($balise, $class) {
2132
-	return modifier_class($balise, $class, 'commuter');
2132
+    return modifier_class($balise, $class, 'commuter');
2133 2133
 }
2134 2134
 
2135 2135
 /**
@@ -2140,19 +2140,19 @@  discard block
 block discarded – undo
2140 2140
  * @return string
2141 2141
  */
2142 2142
 function tester_config($id, $mode = '') {
2143
-	include_spip('action/inscrire_auteur');
2143
+    include_spip('action/inscrire_auteur');
2144 2144
 
2145
-	return tester_statut_inscription($mode, $id);
2145
+    return tester_statut_inscription($mode, $id);
2146 2146
 }
2147 2147
 
2148 2148
 //
2149 2149
 // Quelques fonctions de calcul arithmetique
2150 2150
 //
2151 2151
 function floatstr($a) {
2152
- return str_replace(',', '.', (string)floatval($a));
2152
+    return str_replace(',', '.', (string)floatval($a));
2153 2153
 }
2154 2154
 function strize($f, $a, $b) {
2155
- return floatstr($f(floatstr($a), floatstr($b)));
2155
+    return floatstr($f(floatstr($a), floatstr($b)));
2156 2156
 }
2157 2157
 
2158 2158
 /**
@@ -2171,11 +2171,11 @@  discard block
 block discarded – undo
2171 2171
  * @return int $a+$b
2172 2172
  **/
2173 2173
 function plus($a, $b) {
2174
-	return $a + $b;
2174
+    return $a + $b;
2175 2175
 }
2176 2176
 
2177 2177
 function strplus($a, $b) {
2178
-	return strize('plus', $a, $b);
2178
+    return strize('plus', $a, $b);
2179 2179
 }
2180 2180
 
2181 2181
 /**
@@ -2194,11 +2194,11 @@  discard block
 block discarded – undo
2194 2194
  * @return int $a-$b
2195 2195
  **/
2196 2196
 function moins($a, $b) {
2197
-	return $a - $b;
2197
+    return $a - $b;
2198 2198
 }
2199 2199
 
2200 2200
 function strmoins($a, $b) {
2201
-	return strize('moins', $a, $b);
2201
+    return strize('moins', $a, $b);
2202 2202
 }
2203 2203
 
2204 2204
 /**
@@ -2218,11 +2218,11 @@  discard block
 block discarded – undo
2218 2218
  * @return int $a*$b
2219 2219
  **/
2220 2220
 function mult($a, $b) {
2221
-	return $a * $b;
2221
+    return $a * $b;
2222 2222
 }
2223 2223
 
2224 2224
 function strmult($a, $b) {
2225
-	return strize('mult', $a, $b);
2225
+    return strize('mult', $a, $b);
2226 2226
 }
2227 2227
 
2228 2228
 /**
@@ -2242,11 +2242,11 @@  discard block
 block discarded – undo
2242 2242
  * @return int $a/$b (ou 0 si $b est nul)
2243 2243
  **/
2244 2244
 function div($a, $b) {
2245
-	return $b ? $a / $b : 0;
2245
+    return $b ? $a / $b : 0;
2246 2246
 }
2247 2247
 
2248 2248
 function strdiv($a, $b) {
2249
-	return strize('div', $a, $b);
2249
+    return strize('div', $a, $b);
2250 2250
 }
2251 2251
 
2252 2252
 /**
@@ -2267,7 +2267,7 @@  discard block
 block discarded – undo
2267 2267
  * @return int ($nb % $mod) + $add
2268 2268
  **/
2269 2269
 function modulo($nb, $mod, $add = 0) {
2270
-	return ($mod ? $nb % $mod : 0) + $add;
2270
+    return ($mod ? $nb % $mod : 0) + $add;
2271 2271
 }
2272 2272
 
2273 2273
 
@@ -2282,26 +2282,26 @@  discard block
 block discarded – undo
2282 2282
  *      - true sinon
2283 2283
  **/
2284 2284
 function nom_acceptable($nom) {
2285
-	$remp2 = [];
2286
-	$remp1 = [];
2287
-	if (!is_string($nom)) {
2288
-		return false;
2289
-	}
2290
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2291
-		define('_TAGS_NOM_AUTEUR', '');
2292
-	}
2293
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2294
-	foreach ($tags_acceptes as $tag) {
2295
-		if (strlen($tag)) {
2296
-			$remp1[] = '<' . trim($tag) . '>';
2297
-			$remp1[] = '</' . trim($tag) . '>';
2298
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2299
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2300
-		}
2301
-	}
2302
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2303
-
2304
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2285
+    $remp2 = [];
2286
+    $remp1 = [];
2287
+    if (!is_string($nom)) {
2288
+        return false;
2289
+    }
2290
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2291
+        define('_TAGS_NOM_AUTEUR', '');
2292
+    }
2293
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2294
+    foreach ($tags_acceptes as $tag) {
2295
+        if (strlen($tag)) {
2296
+            $remp1[] = '<' . trim($tag) . '>';
2297
+            $remp1[] = '</' . trim($tag) . '>';
2298
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2299
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2300
+        }
2301
+    }
2302
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2303
+
2304
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2305 2305
 }
2306 2306
 
2307 2307
 
@@ -2317,14 +2317,14 @@  discard block
 block discarded – undo
2317 2317
  *      - renvoie un tableau si l'entree est un tableau
2318 2318
  **/
2319 2319
 function email_valide($adresses) {
2320
-	if (is_array($adresses)) {
2321
-		$adresses = array_map('email_valide', $adresses);
2322
-		$adresses = array_filter($adresses);
2323
-		return $adresses;
2324
-	}
2320
+    if (is_array($adresses)) {
2321
+        $adresses = array_map('email_valide', $adresses);
2322
+        $adresses = array_filter($adresses);
2323
+        return $adresses;
2324
+    }
2325 2325
 
2326
-	$email_valide = charger_fonction('email_valide', 'inc');
2327
-	return $email_valide($adresses);
2326
+    $email_valide = charger_fonction('email_valide', 'inc');
2327
+    return $email_valide($adresses);
2328 2328
 }
2329 2329
 
2330 2330
 /**
@@ -2338,29 +2338,29 @@  discard block
 block discarded – undo
2338 2338
  * @return string texte
2339 2339
  **/
2340 2340
 function afficher_enclosures($tags) {
2341
-	$s = [];
2342
-	foreach (extraire_balises($tags, 'a') as $tag) {
2343
-		if (
2344
-			extraire_attribut($tag, 'rel') == 'enclosure'
2345
-			and $t = extraire_attribut($tag, 'href')
2346
-		) {
2347
-			$s[] = preg_replace(
2348
-				',>[^<]+</a>,S',
2349
-				'>'
2350
-				. http_img_pack(
2351
-					'attachment-16.png',
2352
-					$t,
2353
-					'',
2354
-					$t,
2355
-					['utiliser_suffixe_size' => true]
2356
-				)
2357
-				. '</a>',
2358
-				$tag
2359
-			);
2360
-		}
2361
-	}
2362
-
2363
-	return join('&nbsp;', $s);
2341
+    $s = [];
2342
+    foreach (extraire_balises($tags, 'a') as $tag) {
2343
+        if (
2344
+            extraire_attribut($tag, 'rel') == 'enclosure'
2345
+            and $t = extraire_attribut($tag, 'href')
2346
+        ) {
2347
+            $s[] = preg_replace(
2348
+                ',>[^<]+</a>,S',
2349
+                '>'
2350
+                . http_img_pack(
2351
+                    'attachment-16.png',
2352
+                    $t,
2353
+                    '',
2354
+                    $t,
2355
+                    ['utiliser_suffixe_size' => true]
2356
+                )
2357
+                . '</a>',
2358
+                $tag
2359
+            );
2360
+        }
2361
+    }
2362
+
2363
+    return join('&nbsp;', $s);
2364 2364
 }
2365 2365
 
2366 2366
 /**
@@ -2375,15 +2375,15 @@  discard block
 block discarded – undo
2375 2375
  * @return string Liens trouvés
2376 2376
  **/
2377 2377
 function afficher_tags($tags, $rels = 'tag,directory') {
2378
-	$s = [];
2379
-	foreach (extraire_balises($tags, 'a') as $tag) {
2380
-		$rel = extraire_attribut($tag, 'rel');
2381
-		if (strstr(",$rels,", (string) ",$rel,")) {
2382
-			$s[] = $tag;
2383
-		}
2384
-	}
2378
+    $s = [];
2379
+    foreach (extraire_balises($tags, 'a') as $tag) {
2380
+        $rel = extraire_attribut($tag, 'rel');
2381
+        if (strstr(",$rels,", (string) ",$rel,")) {
2382
+            $s[] = $tag;
2383
+        }
2384
+    }
2385 2385
 
2386
-	return join(', ', $s);
2386
+    return join(', ', $s);
2387 2387
 }
2388 2388
 
2389 2389
 
@@ -2405,21 +2405,21 @@  discard block
 block discarded – undo
2405 2405
  * @return string Tag HTML `<a>` avec microformat.
2406 2406
  **/
2407 2407
 function enclosure2microformat($e) {
2408
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) {
2409
-		$url = filtrer_entites(extraire_attribut($e, 'href') ?? '');
2410
-	}
2411
-	$type = extraire_attribut($e, 'type');
2412
-	if (!$length = extraire_attribut($e, 'length')) {
2413
-		# <media:content : longeur dans fileSize. On tente.
2414
-		$length = extraire_attribut($e, 'fileSize');
2415
-	}
2416
-	$fichier = basename($url);
2408
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) {
2409
+        $url = filtrer_entites(extraire_attribut($e, 'href') ?? '');
2410
+    }
2411
+    $type = extraire_attribut($e, 'type');
2412
+    if (!$length = extraire_attribut($e, 'length')) {
2413
+        # <media:content : longeur dans fileSize. On tente.
2414
+        $length = extraire_attribut($e, 'fileSize');
2415
+    }
2416
+    $fichier = basename($url);
2417 2417
 
2418
-	return '<a rel="enclosure"'
2419
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2420
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2421
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2422
-	. '>' . $fichier . '</a>';
2418
+    return '<a rel="enclosure"'
2419
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2420
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2421
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2422
+    . '>' . $fichier . '</a>';
2423 2423
 }
2424 2424
 
2425 2425
 /**
@@ -2437,24 +2437,24 @@  discard block
 block discarded – undo
2437 2437
  * @return string Tags RSS `<enclosure>`.
2438 2438
  **/
2439 2439
 function microformat2enclosure($tags) {
2440
-	$enclosures = [];
2441
-	foreach (extraire_balises($tags, 'a') as $e) {
2442
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2443
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2444
-			$type = extraire_attribut($e, 'type');
2445
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2446
-				$length = intval(extraire_attribut($e, 'length'));
2447
-			} # vieux data
2448
-			$fichier = basename($url);
2449
-			$enclosures[] = '<enclosure'
2450
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2451
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2452
-				. ($length ? ' length="' . $length . '"' : '')
2453
-				. ' />';
2454
-		}
2455
-	}
2440
+    $enclosures = [];
2441
+    foreach (extraire_balises($tags, 'a') as $e) {
2442
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2443
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2444
+            $type = extraire_attribut($e, 'type');
2445
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2446
+                $length = intval(extraire_attribut($e, 'length'));
2447
+            } # vieux data
2448
+            $fichier = basename($url);
2449
+            $enclosures[] = '<enclosure'
2450
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2451
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2452
+                . ($length ? ' length="' . $length . '"' : '')
2453
+                . ' />';
2454
+        }
2455
+    }
2456 2456
 
2457
-	return join("\n", $enclosures);
2457
+    return join("\n", $enclosures);
2458 2458
 }
2459 2459
 
2460 2460
 
@@ -2470,16 +2470,16 @@  discard block
 block discarded – undo
2470 2470
  * @return string Tags RSS Atom `<dc:subject>`.
2471 2471
  **/
2472 2472
 function tags2dcsubject($tags) {
2473
-	$subjects = '';
2474
-	foreach (extraire_balises($tags, 'a') as $e) {
2475
-		if (extraire_attribut($e, 'rel') == 'tag') {
2476
-			$subjects .= '<dc:subject>'
2477
-				. texte_backend(textebrut($e))
2478
-				. '</dc:subject>' . "\n";
2479
-		}
2480
-	}
2473
+    $subjects = '';
2474
+    foreach (extraire_balises($tags, 'a') as $e) {
2475
+        if (extraire_attribut($e, 'rel') == 'tag') {
2476
+            $subjects .= '<dc:subject>'
2477
+                . texte_backend(textebrut($e))
2478
+                . '</dc:subject>' . "\n";
2479
+        }
2480
+    }
2481 2481
 
2482
-	return $subjects;
2482
+    return $subjects;
2483 2483
 }
2484 2484
 
2485 2485
 /**
@@ -2508,27 +2508,27 @@  discard block
 block discarded – undo
2508 2508
  *     - Tableau de résultats, si tableau en entrée.
2509 2509
  **/
2510 2510
 function extraire_balise($texte, $tag = 'a') {
2511
-	if (is_array($texte)) {
2512
-		array_walk(
2513
-			$texte,
2514
-			function (&$a, $key, $t) {
2515
-				$a = extraire_balise($a, $t);
2516
-			},
2517
-			$tag
2518
-		);
2519
-
2520
-		return $texte;
2521
-	}
2522
-
2523
-	if (
2524
-		preg_match(
2525
-			",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2526
-			$texte,
2527
-			$regs
2528
-		)
2529
-	) {
2530
-		return $regs[0];
2531
-	}
2511
+    if (is_array($texte)) {
2512
+        array_walk(
2513
+            $texte,
2514
+            function (&$a, $key, $t) {
2515
+                $a = extraire_balise($a, $t);
2516
+            },
2517
+            $tag
2518
+        );
2519
+
2520
+        return $texte;
2521
+    }
2522
+
2523
+    if (
2524
+        preg_match(
2525
+            ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2526
+            $texte,
2527
+            $regs
2528
+        )
2529
+    ) {
2530
+        return $regs[0];
2531
+    }
2532 2532
 }
2533 2533
 
2534 2534
 /**
@@ -2556,30 +2556,30 @@  discard block
 block discarded – undo
2556 2556
  *     - Tableau de résultats, si tableau en entrée.
2557 2557
  **/
2558 2558
 function extraire_balises($texte, $tag = 'a') {
2559
-	if (is_array($texte)) {
2560
-		array_walk(
2561
-			$texte,
2562
-			function (&$a, $key, $t) {
2563
-				$a = extraire_balises($a, $t);
2564
-			},
2565
-			$tag
2566
-		);
2567
-
2568
-		return $texte;
2569
-	}
2570
-
2571
-	if (
2572
-		preg_match_all(
2573
-			",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS",
2574
-			$texte,
2575
-			$regs,
2576
-			PREG_PATTERN_ORDER
2577
-		)
2578
-	) {
2579
-		return $regs[0];
2580
-	} else {
2581
-		return [];
2582
-	}
2559
+    if (is_array($texte)) {
2560
+        array_walk(
2561
+            $texte,
2562
+            function (&$a, $key, $t) {
2563
+                $a = extraire_balises($a, $t);
2564
+            },
2565
+            $tag
2566
+        );
2567
+
2568
+        return $texte;
2569
+    }
2570
+
2571
+    if (
2572
+        preg_match_all(
2573
+            ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS",
2574
+            $texte,
2575
+            $regs,
2576
+            PREG_PATTERN_ORDER
2577
+        )
2578
+    ) {
2579
+        return $regs[0];
2580
+    } else {
2581
+        return [];
2582
+    }
2583 2583
 }
2584 2584
 
2585 2585
 /**
@@ -2608,11 +2608,11 @@  discard block
 block discarded – undo
2608 2608
  *     - `$def` si on n'a pas transmis de tableau
2609 2609
  **/
2610 2610
 function in_any($val, $vals, $def = '') {
2611
-	if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2612
-		$vals = $v;
2613
-	}
2611
+    if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2612
+        $vals = $v;
2613
+    }
2614 2614
 
2615
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2615
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2616 2616
 }
2617 2617
 
2618 2618
 
@@ -2633,12 +2633,12 @@  discard block
 block discarded – undo
2633 2633
  *     Résultat du calcul
2634 2634
  **/
2635 2635
 function valeur_numerique($expr) {
2636
-	$a = 0;
2637
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2638
-		eval("\$a = $expr;");
2639
-	}
2636
+    $a = 0;
2637
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2638
+        eval("\$a = $expr;");
2639
+    }
2640 2640
 
2641
-	return intval($a);
2641
+    return intval($a);
2642 2642
 }
2643 2643
 
2644 2644
 /**
@@ -2657,7 +2657,7 @@  discard block
 block discarded – undo
2657 2657
  *      Retourne `$a*$b/$c`
2658 2658
  **/
2659 2659
 function regledetrois($a, $b, $c) {
2660
-	return round($a * $b / $c);
2660
+    return round($a * $b / $c);
2661 2661
 }
2662 2662
 
2663 2663
 
@@ -2680,79 +2680,79 @@  discard block
 block discarded – undo
2680 2680
  * @return string Suite de champs input hidden
2681 2681
  **/
2682 2682
 function form_hidden(?string $action = ''): string {
2683
-	$action ??= '';
2684
-
2685
-	$contexte = [];
2686
-	include_spip('inc/urls');
2687
-	if (
2688
-		$p = urls_decoder_url($action, '')
2689
-		and reset($p)
2690
-	) {
2691
-		$fond = array_shift($p);
2692
-		if ($fond != '404') {
2693
-			$contexte = array_shift($p);
2694
-			$contexte['page'] = $fond;
2695
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2696
-		}
2697
-	}
2698
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2699
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2700
-		unset($contexte['type']);
2701
-	}
2702
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2703
-		unset($contexte['type-page']);
2704
-	}
2705
-
2706
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2707
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2708
-	$values = [];
2709
-
2710
-	// d'abord avec celles de l'url
2711
-	if (false !== ($p = strpos($action, '?'))) {
2712
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2713
-			$c = explode('=', $c, 2);
2714
-			$var = array_shift($c);
2715
-			$val = array_shift($c) ?? '';
2716
-			if ($var) {
2717
-				$val = rawurldecode($val);
2718
-				$var = rawurldecode($var); // decoder les [] eventuels
2719
-				if (preg_match(',\[\]$,S', $var)) {
2720
-					$values[] = [$var, $val];
2721
-				} else {
2722
-					if (!isset($values[$var])) {
2723
-						$values[$var] = [$var, $val];
2724
-					}
2725
-				}
2726
-			}
2727
-		}
2728
-	}
2729
-
2730
-	// ensuite avec celles du contexte, sans doublonner !
2731
-	foreach ($contexte as $var => $val) {
2732
-		if (preg_match(',\[\]$,S', $var)) {
2733
-			$values[] = [$var, $val];
2734
-		} else {
2735
-			if (!isset($values[$var])) {
2736
-				$values[$var] = [$var, $val];
2737
-			}
2738
-		}
2739
-	}
2740
-
2741
-	// puis on rassemble le tout
2742
-	$hidden = [];
2743
-	foreach ($values as $value) {
2744
-		[$var, $val] = $value;
2745
-		$hidden[] = '<input name="'
2746
-			. entites_html($var)
2747
-			. '"'
2748
-			. (is_null($val)
2749
-				? ''
2750
-				: ' value="' . entites_html($val) . '"'
2751
-			)
2752
-			. ' type="hidden"' . "\n/>";
2753
-	}
2754
-
2755
-	return join('', $hidden);
2683
+    $action ??= '';
2684
+
2685
+    $contexte = [];
2686
+    include_spip('inc/urls');
2687
+    if (
2688
+        $p = urls_decoder_url($action, '')
2689
+        and reset($p)
2690
+    ) {
2691
+        $fond = array_shift($p);
2692
+        if ($fond != '404') {
2693
+            $contexte = array_shift($p);
2694
+            $contexte['page'] = $fond;
2695
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2696
+        }
2697
+    }
2698
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2699
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2700
+        unset($contexte['type']);
2701
+    }
2702
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2703
+        unset($contexte['type-page']);
2704
+    }
2705
+
2706
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2707
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2708
+    $values = [];
2709
+
2710
+    // d'abord avec celles de l'url
2711
+    if (false !== ($p = strpos($action, '?'))) {
2712
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2713
+            $c = explode('=', $c, 2);
2714
+            $var = array_shift($c);
2715
+            $val = array_shift($c) ?? '';
2716
+            if ($var) {
2717
+                $val = rawurldecode($val);
2718
+                $var = rawurldecode($var); // decoder les [] eventuels
2719
+                if (preg_match(',\[\]$,S', $var)) {
2720
+                    $values[] = [$var, $val];
2721
+                } else {
2722
+                    if (!isset($values[$var])) {
2723
+                        $values[$var] = [$var, $val];
2724
+                    }
2725
+                }
2726
+            }
2727
+        }
2728
+    }
2729
+
2730
+    // ensuite avec celles du contexte, sans doublonner !
2731
+    foreach ($contexte as $var => $val) {
2732
+        if (preg_match(',\[\]$,S', $var)) {
2733
+            $values[] = [$var, $val];
2734
+        } else {
2735
+            if (!isset($values[$var])) {
2736
+                $values[$var] = [$var, $val];
2737
+            }
2738
+        }
2739
+    }
2740
+
2741
+    // puis on rassemble le tout
2742
+    $hidden = [];
2743
+    foreach ($values as $value) {
2744
+        [$var, $val] = $value;
2745
+        $hidden[] = '<input name="'
2746
+            . entites_html($var)
2747
+            . '"'
2748
+            . (is_null($val)
2749
+                ? ''
2750
+                : ' value="' . entites_html($val) . '"'
2751
+            )
2752
+            . ' type="hidden"' . "\n/>";
2753
+    }
2754
+
2755
+    return join('', $hidden);
2756 2756
 }
2757 2757
 
2758 2758
 
@@ -2774,7 +2774,7 @@  discard block
 block discarded – undo
2774 2774
  *    - la première valeur du tableau sinon.
2775 2775
  **/
2776 2776
 function filtre_reset($array) {
2777
-	return !is_array($array) ? null : reset($array);
2777
+    return !is_array($array) ? null : reset($array);
2778 2778
 }
2779 2779
 
2780 2780
 /**
@@ -2795,7 +2795,7 @@  discard block
 block discarded – undo
2795 2795
  *    - la dernière valeur du tableau sinon.
2796 2796
  **/
2797 2797
 function filtre_end($array) {
2798
-	return !is_array($array) ? null : end($array);
2798
+    return !is_array($array) ? null : end($array);
2799 2799
 }
2800 2800
 
2801 2801
 /**
@@ -2815,11 +2815,11 @@  discard block
 block discarded – undo
2815 2815
  *
2816 2816
  **/
2817 2817
 function filtre_push($array, $val) {
2818
-	if (!is_array($array) or !array_push($array, $val)) {
2819
-		return '';
2820
-	}
2818
+    if (!is_array($array) or !array_push($array, $val)) {
2819
+        return '';
2820
+    }
2821 2821
 
2822
-	return $array;
2822
+    return $array;
2823 2823
 }
2824 2824
 
2825 2825
 /**
@@ -2838,7 +2838,7 @@  discard block
 block discarded – undo
2838 2838
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2839 2839
  **/
2840 2840
 function filtre_find($array, $val) {
2841
-	return (is_array($array) and in_array($val, $array));
2841
+    return (is_array($array) and in_array($val, $array));
2842 2842
 }
2843 2843
 
2844 2844
 
@@ -2855,13 +2855,13 @@  discard block
 block discarded – undo
2855 2855
  *     Contenu avec urls en absolus
2856 2856
  **/
2857 2857
 function urls_absolues_css($contenu, $source) {
2858
-	$path = suivre_lien(url_absolue($source), './');
2858
+    $path = suivre_lien(url_absolue($source), './');
2859 2859
 
2860
-	return preg_replace_callback(
2861
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2862
-		fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2863
-		$contenu
2864
-	);
2860
+    return preg_replace_callback(
2861
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2862
+        fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2863
+        $contenu
2864
+    );
2865 2865
 }
2866 2866
 
2867 2867
 
@@ -2890,119 +2890,119 @@  discard block
 block discarded – undo
2890 2890
  *     Chemin du fichier CSS inversé
2891 2891
  **/
2892 2892
 function direction_css($css, $voulue = '') {
2893
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2894
-		return $css;
2895
-	}
2896
-	include_spip('inc/lang');
2897
-	// si on a precise le sens voulu en argument, le prendre en compte
2898
-	if ($voulue = strtolower($voulue)) {
2899
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2900
-			$voulue = lang_dir($voulue);
2901
-		}
2902
-	} else {
2903
-		$voulue = lang_dir();
2904
-	}
2905
-
2906
-	$r = count($r) > 1;
2907
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2908
-	$dir = $r ? 'rtl' : 'ltr';
2909
-	$ndir = $r ? 'ltr' : 'rtl';
2910
-
2911
-	if ($voulue == $dir) {
2912
-		return $css;
2913
-	}
2914
-
2915
-	if (
2916
-		// url absolue
2917
-		preg_match(',^https?:,i', $css)
2918
-		// ou qui contient un ?
2919
-		or (($p = strpos($css, '?')) !== false)
2920
-	) {
2921
-		$distant = true;
2922
-		$cssf = parse_url($css);
2923
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2924
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2925
-	} else {
2926
-		$distant = false;
2927
-		$cssf = $css;
2928
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2929
-		//propose (rien a faire dans ce cas)
2930
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2931
-		if (@file_exists($f)) {
2932
-			return $f;
2933
-		}
2934
-	}
2935
-
2936
-	// 2.
2937
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2938
-	$f = $dir_var
2939
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2940
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2941
-
2942
-	// la css peut etre distante (url absolue !)
2943
-	if ($distant) {
2944
-		include_spip('inc/distant');
2945
-		$res = recuperer_url($css);
2946
-		if (!$res or !$contenu = $res['page']) {
2947
-			return $css;
2948
-		}
2949
-	} else {
2950
-		if (
2951
-			(@filemtime($f) > @filemtime($css))
2952
-			and (_VAR_MODE != 'recalcul')
2953
-		) {
2954
-			return $f;
2955
-		}
2956
-		if (!lire_fichier($css, $contenu)) {
2957
-			return $css;
2958
-		}
2959
-	}
2960
-
2961
-
2962
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2963
-	include_spip('lib/csstidy/class.csstidy');
2964
-	$parser = new csstidy();
2965
-	$parser->set_cfg('optimise_shorthands', 0);
2966
-	$parser->set_cfg('reverse_left_and_right', true);
2967
-	$parser->parse($contenu);
2968
-
2969
-	$contenu = $parser->print->plain();
2970
-
2971
-
2972
-	// reperer les @import auxquels il faut propager le direction_css
2973
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2974
-	$src = [];
2975
-	$src_direction_css = [];
2976
-	$src_faux_abs = [];
2977
-	$d = dirname($css);
2978
-	foreach ($regs[1] as $k => $import_css) {
2979
-		$css_direction = direction_css("$d/$import_css", $voulue);
2980
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2981
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2982
-			$css_direction = substr($css_direction, strlen($d) + 1);
2983
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2984
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2985
-			$css_direction = substr($css_direction, strlen($dir_var));
2986
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
2987
-			$css_direction = '/@@@@@@/' . $css_direction;
2988
-		}
2989
-		$src[] = $regs[0][$k];
2990
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2991
-	}
2992
-	$contenu = str_replace($src, $src_direction_css, $contenu);
2993
-
2994
-	$contenu = urls_absolues_css($contenu, $css);
2995
-
2996
-	// virer les fausses url absolues que l'on a mis dans les import
2997
-	if (count($src_faux_abs)) {
2998
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2999
-	}
3000
-
3001
-	if (!ecrire_fichier($f, $contenu)) {
3002
-		return $css;
3003
-	}
3004
-
3005
-	return $f;
2893
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2894
+        return $css;
2895
+    }
2896
+    include_spip('inc/lang');
2897
+    // si on a precise le sens voulu en argument, le prendre en compte
2898
+    if ($voulue = strtolower($voulue)) {
2899
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2900
+            $voulue = lang_dir($voulue);
2901
+        }
2902
+    } else {
2903
+        $voulue = lang_dir();
2904
+    }
2905
+
2906
+    $r = count($r) > 1;
2907
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2908
+    $dir = $r ? 'rtl' : 'ltr';
2909
+    $ndir = $r ? 'ltr' : 'rtl';
2910
+
2911
+    if ($voulue == $dir) {
2912
+        return $css;
2913
+    }
2914
+
2915
+    if (
2916
+        // url absolue
2917
+        preg_match(',^https?:,i', $css)
2918
+        // ou qui contient un ?
2919
+        or (($p = strpos($css, '?')) !== false)
2920
+    ) {
2921
+        $distant = true;
2922
+        $cssf = parse_url($css);
2923
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2924
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
2925
+    } else {
2926
+        $distant = false;
2927
+        $cssf = $css;
2928
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2929
+        //propose (rien a faire dans ce cas)
2930
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2931
+        if (@file_exists($f)) {
2932
+            return $f;
2933
+        }
2934
+    }
2935
+
2936
+    // 2.
2937
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2938
+    $f = $dir_var
2939
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2940
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2941
+
2942
+    // la css peut etre distante (url absolue !)
2943
+    if ($distant) {
2944
+        include_spip('inc/distant');
2945
+        $res = recuperer_url($css);
2946
+        if (!$res or !$contenu = $res['page']) {
2947
+            return $css;
2948
+        }
2949
+    } else {
2950
+        if (
2951
+            (@filemtime($f) > @filemtime($css))
2952
+            and (_VAR_MODE != 'recalcul')
2953
+        ) {
2954
+            return $f;
2955
+        }
2956
+        if (!lire_fichier($css, $contenu)) {
2957
+            return $css;
2958
+        }
2959
+    }
2960
+
2961
+
2962
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2963
+    include_spip('lib/csstidy/class.csstidy');
2964
+    $parser = new csstidy();
2965
+    $parser->set_cfg('optimise_shorthands', 0);
2966
+    $parser->set_cfg('reverse_left_and_right', true);
2967
+    $parser->parse($contenu);
2968
+
2969
+    $contenu = $parser->print->plain();
2970
+
2971
+
2972
+    // reperer les @import auxquels il faut propager le direction_css
2973
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2974
+    $src = [];
2975
+    $src_direction_css = [];
2976
+    $src_faux_abs = [];
2977
+    $d = dirname($css);
2978
+    foreach ($regs[1] as $k => $import_css) {
2979
+        $css_direction = direction_css("$d/$import_css", $voulue);
2980
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2981
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2982
+            $css_direction = substr($css_direction, strlen($d) + 1);
2983
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
2984
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2985
+            $css_direction = substr($css_direction, strlen($dir_var));
2986
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
2987
+            $css_direction = '/@@@@@@/' . $css_direction;
2988
+        }
2989
+        $src[] = $regs[0][$k];
2990
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2991
+    }
2992
+    $contenu = str_replace($src, $src_direction_css, $contenu);
2993
+
2994
+    $contenu = urls_absolues_css($contenu, $css);
2995
+
2996
+    // virer les fausses url absolues que l'on a mis dans les import
2997
+    if (count($src_faux_abs)) {
2998
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2999
+    }
3000
+
3001
+    if (!ecrire_fichier($f, $contenu)) {
3002
+        return $css;
3003
+    }
3004
+
3005
+    return $f;
3006 3006
 }
3007 3007
 
3008 3008
 
@@ -3025,46 +3025,46 @@  discard block
 block discarded – undo
3025 3025
  *     - Chemin ou URL du fichier CSS source sinon.
3026 3026
  **/
3027 3027
 function url_absolue_css($css) {
3028
-	if (!preg_match(',\.css$,i', $css, $r)) {
3029
-		return $css;
3030
-	}
3028
+    if (!preg_match(',\.css$,i', $css, $r)) {
3029
+        return $css;
3030
+    }
3031 3031
 
3032
-	$url_absolue_css = url_absolue($css);
3032
+    $url_absolue_css = url_absolue($css);
3033 3033
 
3034
-	$f = basename($css, '.css');
3035
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3036
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3037
-		. '.css';
3034
+    $f = basename($css, '.css');
3035
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3036
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3037
+        . '.css';
3038 3038
 
3039
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3040
-		return $f;
3041
-	}
3039
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3040
+        return $f;
3041
+    }
3042 3042
 
3043
-	if ($url_absolue_css == $css) {
3044
-		if (
3045
-			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3046
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3047
-		) {
3048
-			include_spip('inc/distant');
3049
-			$contenu = recuperer_url($css);
3050
-			$contenu = $contenu['page'] ?? '';
3051
-			if (!$contenu) {
3052
-				return $css;
3053
-			}
3054
-		}
3055
-	} elseif (!lire_fichier($css, $contenu)) {
3056
-		return $css;
3057
-	}
3043
+    if ($url_absolue_css == $css) {
3044
+        if (
3045
+            strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3046
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3047
+        ) {
3048
+            include_spip('inc/distant');
3049
+            $contenu = recuperer_url($css);
3050
+            $contenu = $contenu['page'] ?? '';
3051
+            if (!$contenu) {
3052
+                return $css;
3053
+            }
3054
+        }
3055
+    } elseif (!lire_fichier($css, $contenu)) {
3056
+        return $css;
3057
+    }
3058 3058
 
3059
-	// passer les url relatives a la css d'origine en url absolues
3060
-	$contenu = urls_absolues_css($contenu, $css);
3059
+    // passer les url relatives a la css d'origine en url absolues
3060
+    $contenu = urls_absolues_css($contenu, $css);
3061 3061
 
3062
-	// ecrire la css
3063
-	if (!ecrire_fichier($f, $contenu)) {
3064
-		return $css;
3065
-	}
3062
+    // ecrire la css
3063
+    if (!ecrire_fichier($f, $contenu)) {
3064
+        return $css;
3065
+    }
3066 3066
 
3067
-	return $f;
3067
+    return $f;
3068 3068
 }
3069 3069
 
3070 3070
 
@@ -3098,24 +3098,24 @@  discard block
 block discarded – undo
3098 3098
  *     Valeur trouvée ou valeur par défaut.
3099 3099
  **/
3100 3100
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3101
-	foreach (explode('/', $cle) as $k) {
3102
-		$table = (is_string($table) ? @unserialize($table) : $table);
3101
+    foreach (explode('/', $cle) as $k) {
3102
+        $table = (is_string($table) ? @unserialize($table) : $table);
3103 3103
 
3104
-		if (is_object($table)) {
3105
-			$table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3106
-		} elseif (is_array($table)) {
3107
-			if ($conserver_null) {
3108
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3109
-			} else {
3110
-				$table = ($table[$k] ?? $defaut);
3111
-			}
3112
-		} else {
3113
-			$table = $defaut;
3114
-			break;
3115
-		}
3116
-	}
3104
+        if (is_object($table)) {
3105
+            $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3106
+        } elseif (is_array($table)) {
3107
+            if ($conserver_null) {
3108
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3109
+            } else {
3110
+                $table = ($table[$k] ?? $defaut);
3111
+            }
3112
+        } else {
3113
+            $table = $defaut;
3114
+            break;
3115
+        }
3116
+    }
3117 3117
 
3118
-	return $table;
3118
+    return $table;
3119 3119
 }
3120 3120
 
3121 3121
 /**
@@ -3148,22 +3148,22 @@  discard block
 block discarded – undo
3148 3148
  *     - string : expression trouvée.
3149 3149
  **/
3150 3150
 function filtre_match_dist(?string $texte, $expression, $modif = 'UuimsS', $capte = 0) {
3151
-	if (intval($modif) and $capte == 0) {
3152
-		$capte = $modif;
3153
-		$modif = 'UuimsS';
3154
-	}
3155
-	$expression = str_replace('\/', '/', $expression);
3156
-	$expression = str_replace('/', '\/', $expression);
3151
+    if (intval($modif) and $capte == 0) {
3152
+        $capte = $modif;
3153
+        $modif = 'UuimsS';
3154
+    }
3155
+    $expression = str_replace('\/', '/', $expression);
3156
+    $expression = str_replace('/', '\/', $expression);
3157 3157
 
3158
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3159
-		if (isset($r[$capte])) {
3160
-			return $r[$capte];
3161
-		} else {
3162
-			return true;
3163
-		}
3164
-	}
3158
+    if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3159
+        if (isset($r[$capte])) {
3160
+            return $r[$capte];
3161
+        } else {
3162
+            return true;
3163
+        }
3164
+    }
3165 3165
 
3166
-	return false;
3166
+    return false;
3167 3167
 }
3168 3168
 
3169 3169
 
@@ -3190,14 +3190,14 @@  discard block
 block discarded – undo
3190 3190
  *     Texte
3191 3191
  **/
3192 3192
 function replace(?string $texte, string $expression, string $replace = '', string $modif = 'UimsS'): string {
3193
-	if (null === $texte) {
3194
-		return '';
3195
-	}
3193
+    if (null === $texte) {
3194
+        return '';
3195
+    }
3196 3196
 
3197
-	$expression = str_replace('\/', '/', $expression);
3198
-	$expression = str_replace('/', '\/', $expression);
3197
+    $expression = str_replace('\/', '/', $expression);
3198
+    $expression = str_replace('/', '\/', $expression);
3199 3199
 
3200
-	return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3200
+    return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3201 3201
 }
3202 3202
 
3203 3203
 
@@ -3215,25 +3215,25 @@  discard block
 block discarded – undo
3215 3215
  **/
3216 3216
 function traiter_doublons_documents(&$doublons, $letexte) {
3217 3217
 
3218
-	// Verifier dans le texte & les notes (pas beau, helas)
3219
-	$t = $letexte . $GLOBALS['les_notes'];
3218
+    // Verifier dans le texte & les notes (pas beau, helas)
3219
+    $t = $letexte . $GLOBALS['les_notes'];
3220 3220
 
3221
-	if (
3222
-		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3223
-		and preg_match_all(
3224
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3225
-			$t,
3226
-			$matches,
3227
-			PREG_PATTERN_ORDER
3228
-		)
3229
-	) {
3230
-		if (!isset($doublons['documents'])) {
3231
-			$doublons['documents'] = '';
3232
-		}
3233
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3234
-	}
3221
+    if (
3222
+        strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3223
+        and preg_match_all(
3224
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3225
+            $t,
3226
+            $matches,
3227
+            PREG_PATTERN_ORDER
3228
+        )
3229
+    ) {
3230
+        if (!isset($doublons['documents'])) {
3231
+            $doublons['documents'] = '';
3232
+        }
3233
+        $doublons['documents'] .= ',' . join(',', $matches[1]);
3234
+    }
3235 3235
 
3236
-	return $letexte;
3236
+    return $letexte;
3237 3237
 }
3238 3238
 
3239 3239
 /**
@@ -3247,7 +3247,7 @@  discard block
 block discarded – undo
3247 3247
  * @return string Chaîne vide
3248 3248
  **/
3249 3249
 function vide($texte) {
3250
-	return '';
3250
+    return '';
3251 3251
 }
3252 3252
 
3253 3253
 //
@@ -3276,23 +3276,23 @@  discard block
 block discarded – undo
3276 3276
  *      Code HTML résultant
3277 3277
  **/
3278 3278
 function env_to_params($env, $ignore_params = []) {
3279
-	$ignore_params = array_merge(
3280
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3281
-		$ignore_params
3282
-	);
3283
-	if (!is_array($env)) {
3284
-		$env = unserialize($env);
3285
-	}
3286
-	$texte = '';
3287
-	if ($env) {
3288
-		foreach ($env as $i => $j) {
3289
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3290
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3291
-			}
3292
-		}
3293
-	}
3294
-
3295
-	return $texte;
3279
+    $ignore_params = array_merge(
3280
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3281
+        $ignore_params
3282
+    );
3283
+    if (!is_array($env)) {
3284
+        $env = unserialize($env);
3285
+    }
3286
+    $texte = '';
3287
+    if ($env) {
3288
+        foreach ($env as $i => $j) {
3289
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3290
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3291
+            }
3292
+        }
3293
+    }
3294
+
3295
+    return $texte;
3296 3296
 }
3297 3297
 
3298 3298
 /**
@@ -3315,23 +3315,23 @@  discard block
 block discarded – undo
3315 3315
  *      Code HTML résultant
3316 3316
  **/
3317 3317
 function env_to_attributs($env, $ignore_params = []) {
3318
-	$ignore_params = array_merge(
3319
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3320
-		$ignore_params
3321
-	);
3322
-	if (!is_array($env)) {
3323
-		$env = unserialize($env);
3324
-	}
3325
-	$texte = '';
3326
-	if ($env) {
3327
-		foreach ($env as $i => $j) {
3328
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3329
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3330
-			}
3331
-		}
3332
-	}
3318
+    $ignore_params = array_merge(
3319
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3320
+        $ignore_params
3321
+    );
3322
+    if (!is_array($env)) {
3323
+        $env = unserialize($env);
3324
+    }
3325
+    $texte = '';
3326
+    if ($env) {
3327
+        foreach ($env as $i => $j) {
3328
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3329
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3330
+            }
3331
+        }
3332
+    }
3333 3333
 
3334
-	return $texte;
3334
+    return $texte;
3335 3335
 }
3336 3336
 
3337 3337
 
@@ -3349,7 +3349,7 @@  discard block
 block discarded – undo
3349 3349
  * @return string Chaînes concaténés
3350 3350
  **/
3351 3351
 function concat(...$args): string {
3352
-	return join('', $args);
3352
+    return join('', $args);
3353 3353
 }
3354 3354
 
3355 3355
 
@@ -3369,23 +3369,23 @@  discard block
 block discarded – undo
3369 3369
  *     Contenu du ou des fichiers, concaténé
3370 3370
  **/
3371 3371
 function charge_scripts($files, $script = true) {
3372
-	$flux = '';
3373
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3374
-		if (!is_string($file)) {
3375
-			continue;
3376
-		}
3377
-		if ($script) {
3378
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3379
-		}
3380
-		if ($file) {
3381
-			$path = find_in_path($file);
3382
-			if ($path) {
3383
-				$flux .= spip_file_get_contents($path);
3384
-			}
3385
-		}
3386
-	}
3387
-
3388
-	return $flux;
3372
+    $flux = '';
3373
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3374
+        if (!is_string($file)) {
3375
+            continue;
3376
+        }
3377
+        if ($script) {
3378
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3379
+        }
3380
+        if ($file) {
3381
+            $path = find_in_path($file);
3382
+            if ($path) {
3383
+                $flux .= spip_file_get_contents($path);
3384
+            }
3385
+        }
3386
+    }
3387
+
3388
+    return $flux;
3389 3389
 }
3390 3390
 
3391 3391
 /**
@@ -3396,22 +3396,22 @@  discard block
 block discarded – undo
3396 3396
  * @return string
3397 3397
  */
3398 3398
 function http_img_variante_svg_si_possible($img_file) {
3399
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3400
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3401
-	if (
3402
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3403
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3404
-		and file_exists($variante_svg_generique)
3405
-	) {
3406
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3407
-			$img_file = $variante_svg_size;
3408
-		}
3409
-		else {
3410
-			$img_file = $variante_svg_generique;
3411
-		}
3412
-	}
3399
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3400
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3401
+    if (
3402
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3403
+        and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3404
+        and file_exists($variante_svg_generique)
3405
+    ) {
3406
+        if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3407
+            $img_file = $variante_svg_size;
3408
+        }
3409
+        else {
3410
+            $img_file = $variante_svg_generique;
3411
+        }
3412
+    }
3413 3413
 
3414
-	return $img_file;
3414
+    return $img_file;
3415 3415
 }
3416 3416
 
3417 3417
 /**
@@ -3432,54 +3432,54 @@  discard block
 block discarded – undo
3432 3432
  */
3433 3433
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3434 3434
 
3435
-	$img_file = $img;
3436
-	if ($p = strpos($img_file, '?')) {
3437
-		$img_file = substr($img_file, 0, $p);
3438
-	}
3439
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3440
-		$img_file = chemin_image($img);
3441
-	}
3442
-	else {
3443
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3444
-			$img_file = http_img_variante_svg_si_possible($img_file);
3445
-		}
3446
-	}
3447
-	if (stripos($atts, 'width') === false) {
3448
-		// utiliser directement l'info de taille presente dans le nom
3449
-		if (
3450
-			(!isset($options['utiliser_suffixe_size'])
3451
-				or $options['utiliser_suffixe_size'] == true
3452
-				or str_contains($img_file, '-xx.svg'))
3453
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3454
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3455
-		) {
3456
-			$largeur = $hauteur = intval($regs[1]);
3457
-		} else {
3458
-			$taille = taille_image($img_file);
3459
-			[$hauteur, $largeur] = $taille;
3460
-			if (!$hauteur or !$largeur) {
3461
-				return '';
3462
-			}
3463
-		}
3464
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3465
-	}
3466
-
3467
-	if (file_exists($img_file)) {
3468
-		$img_file = timestamp($img_file);
3469
-	}
3470
-	if ($alt === false) {
3471
-		$alt = '';
3472
-	}
3473
-	elseif ($alt or $alt === '') {
3474
-		$alt = " alt='" . attribut_html($alt) . "'";
3475
-	}
3476
-	else {
3477
-		$alt = " alt='" . attribut_html($title) . "'";
3478
-	}
3479
-	return "<img src='" . attribut_html($img_file) . "'$alt"
3480
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3481
-	. ' ' . ltrim($atts)
3482
-	. ' />';
3435
+    $img_file = $img;
3436
+    if ($p = strpos($img_file, '?')) {
3437
+        $img_file = substr($img_file, 0, $p);
3438
+    }
3439
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3440
+        $img_file = chemin_image($img);
3441
+    }
3442
+    else {
3443
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3444
+            $img_file = http_img_variante_svg_si_possible($img_file);
3445
+        }
3446
+    }
3447
+    if (stripos($atts, 'width') === false) {
3448
+        // utiliser directement l'info de taille presente dans le nom
3449
+        if (
3450
+            (!isset($options['utiliser_suffixe_size'])
3451
+                or $options['utiliser_suffixe_size'] == true
3452
+                or str_contains($img_file, '-xx.svg'))
3453
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3454
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3455
+        ) {
3456
+            $largeur = $hauteur = intval($regs[1]);
3457
+        } else {
3458
+            $taille = taille_image($img_file);
3459
+            [$hauteur, $largeur] = $taille;
3460
+            if (!$hauteur or !$largeur) {
3461
+                return '';
3462
+            }
3463
+        }
3464
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3465
+    }
3466
+
3467
+    if (file_exists($img_file)) {
3468
+        $img_file = timestamp($img_file);
3469
+    }
3470
+    if ($alt === false) {
3471
+        $alt = '';
3472
+    }
3473
+    elseif ($alt or $alt === '') {
3474
+        $alt = " alt='" . attribut_html($alt) . "'";
3475
+    }
3476
+    else {
3477
+        $alt = " alt='" . attribut_html($title) . "'";
3478
+    }
3479
+    return "<img src='" . attribut_html($img_file) . "'$alt"
3480
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3481
+    . ' ' . ltrim($atts)
3482
+    . ' />';
3483 3483
 }
3484 3484
 
3485 3485
 /**
@@ -3491,70 +3491,70 @@  discard block
 block discarded – undo
3491 3491
  * @return string
3492 3492
  */
3493 3493
 function http_style_background($img, $att = '', $size = null) {
3494
-	if ($size and is_numeric($size)) {
3495
-		$size = trim($size) . 'px';
3496
-	}
3497
-	return " style='background" .
3498
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3499
-		. ($size ? "background-size:{$size};" : '')
3500
-		. "'";
3494
+    if ($size and is_numeric($size)) {
3495
+        $size = trim($size) . 'px';
3496
+    }
3497
+    return " style='background" .
3498
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3499
+        . ($size ? "background-size:{$size};" : '')
3500
+        . "'";
3501 3501
 }
3502 3502
 
3503 3503
 
3504 3504
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3505
-	$args = [$alt_or_size, $class_or_size, $size];
3506
-	while (is_null(end($args)) and count($args)) {
3507
-		array_pop($args);
3508
-	}
3509
-	if (!count($args)) {
3510
-		return [null, null, null];
3511
-	}
3512
-	if (count($args) < 3) {
3513
-		$maybe_size = array_pop($args);
3514
-		// @2x
3515
-		// @1.5x
3516
-		// 512
3517
-		// 512x*
3518
-		// 512x300
3519
-		if (
3520
-			!strlen($maybe_size)
3521
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3522
-		) {
3523
-			$args[] = $maybe_size;
3524
-			$maybe_size = null;
3525
-		}
3526
-		while (count($args) < 2) {
3527
-			$args[] = null; // default alt or class
3528
-		}
3529
-		$args[] = $maybe_size;
3530
-	}
3531
-	return $args;
3505
+    $args = [$alt_or_size, $class_or_size, $size];
3506
+    while (is_null(end($args)) and count($args)) {
3507
+        array_pop($args);
3508
+    }
3509
+    if (!count($args)) {
3510
+        return [null, null, null];
3511
+    }
3512
+    if (count($args) < 3) {
3513
+        $maybe_size = array_pop($args);
3514
+        // @2x
3515
+        // @1.5x
3516
+        // 512
3517
+        // 512x*
3518
+        // 512x300
3519
+        if (
3520
+            !strlen($maybe_size)
3521
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3522
+        ) {
3523
+            $args[] = $maybe_size;
3524
+            $maybe_size = null;
3525
+        }
3526
+        while (count($args) < 2) {
3527
+            $args[] = null; // default alt or class
3528
+        }
3529
+        $args[] = $maybe_size;
3530
+    }
3531
+    return $args;
3532 3532
 }
3533 3533
 
3534 3534
 function helper_filtre_balise_img_svg_size($img, $size) {
3535
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3536
-	if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3537
-		$coef = floatval(substr($size, 1, -1));
3538
-		[$h, $w] = taille_image($img);
3539
-		$height = intval(round($h / $coef));
3540
-		$width = intval(round($w / $coef));
3541
-	}
3542
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3543
-	else {
3544
-		$size = explode('x', $size, 2);
3545
-		$size = array_map('trim', $size);
3546
-		$height = $width = intval(array_shift($size));
3547
-
3548
-		if (count($size) and reset($size)) {
3549
-			$height = array_shift($size);
3550
-			if ($height === '*') {
3551
-				[$h, $w] = taille_image($img);
3552
-				$height = intval(round($h * $width / $w));
3553
-			}
3554
-		}
3555
-	}
3556
-
3557
-	return [$width, $height];
3535
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3536
+    if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3537
+        $coef = floatval(substr($size, 1, -1));
3538
+        [$h, $w] = taille_image($img);
3539
+        $height = intval(round($h / $coef));
3540
+        $width = intval(round($w / $coef));
3541
+    }
3542
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3543
+    else {
3544
+        $size = explode('x', $size, 2);
3545
+        $size = array_map('trim', $size);
3546
+        $height = $width = intval(array_shift($size));
3547
+
3548
+        if (count($size) and reset($size)) {
3549
+            $height = array_shift($size);
3550
+            if ($height === '*') {
3551
+                [$h, $w] = taille_image($img);
3552
+                $height = intval(round($h * $width / $w));
3553
+            }
3554
+        }
3555
+    }
3556
+
3557
+    return [$width, $height];
3558 3558
 }
3559 3559
 
3560 3560
 /**
@@ -3590,43 +3590,43 @@  discard block
 block discarded – undo
3590 3590
  */
3591 3591
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3592 3592
 
3593
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3594
-
3595
-	$img = trim((string) $img);
3596
-	if (strpos($img, '<img') === 0) {
3597
-		if (!is_null($alt)) {
3598
-			$img = inserer_attribut($img, 'alt', $alt);
3599
-		}
3600
-		if (!is_null($class)) {
3601
-			if (strlen($class)) {
3602
-				$img = inserer_attribut($img, 'class', $class);
3603
-			}
3604
-			else {
3605
-				$img = vider_attribut($img, 'class');
3606
-			}
3607
-		}
3608
-	}
3609
-	else {
3610
-		$img = http_img_pack(
3611
-			$img,
3612
-			$alt,
3613
-			$class ? " class='" . attribut_html($class) . "'" : '',
3614
-			'',
3615
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3616
-		);
3617
-		if (is_null($alt)) {
3618
-			$img = vider_attribut($img, 'alt');
3619
-		}
3620
-	}
3621
-
3622
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3623
-		[$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3624
-
3625
-		$img = inserer_attribut($img, 'width', $width);
3626
-		$img = inserer_attribut($img, 'height', $height);
3627
-	}
3628
-
3629
-	return $img;
3593
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3594
+
3595
+    $img = trim((string) $img);
3596
+    if (strpos($img, '<img') === 0) {
3597
+        if (!is_null($alt)) {
3598
+            $img = inserer_attribut($img, 'alt', $alt);
3599
+        }
3600
+        if (!is_null($class)) {
3601
+            if (strlen($class)) {
3602
+                $img = inserer_attribut($img, 'class', $class);
3603
+            }
3604
+            else {
3605
+                $img = vider_attribut($img, 'class');
3606
+            }
3607
+        }
3608
+    }
3609
+    else {
3610
+        $img = http_img_pack(
3611
+            $img,
3612
+            $alt,
3613
+            $class ? " class='" . attribut_html($class) . "'" : '',
3614
+            '',
3615
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3616
+        );
3617
+        if (is_null($alt)) {
3618
+            $img = vider_attribut($img, 'alt');
3619
+        }
3620
+    }
3621
+
3622
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3623
+        [$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3624
+
3625
+        $img = inserer_attribut($img, 'width', $width);
3626
+        $img = inserer_attribut($img, 'height', $height);
3627
+    }
3628
+
3629
+    return $img;
3630 3630
 }
3631 3631
 
3632 3632
 
@@ -3660,80 +3660,80 @@  discard block
 block discarded – undo
3660 3660
  */
3661 3661
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3662 3662
 
3663
-	$svg = null;
3664
-	$img = trim($img);
3665
-	$img_file = $img;
3666
-	if (strpos($img, '<svg') === false) {
3667
-		if ($p = strpos($img_file, '?')) {
3668
-			$img_file = substr($img_file, 0, $p);
3669
-		}
3670
-
3671
-		// ne jamais operer directement sur une image distante pour des raisons de perfo
3672
-		// la copie locale a toutes les chances d'etre la ou de resservir
3673
-		if (tester_url_absolue($img_file)) {
3674
-			include_spip('inc/distant');
3675
-			$fichier = copie_locale($img_file);
3676
-			$img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3677
-		}
3678
-
3679
-		if (
3680
-			!$img_file
3681
-			or !file_exists($img_file)
3682
-			or !$svg = file_get_contents($img_file)
3683
-		) {
3684
-			return '';
3685
-		}
3686
-	}
3687
-
3688
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3689
-		return '';
3690
-	}
3691
-
3692
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3693
-
3694
-	$balise_svg = $match[0];
3695
-	$balise_svg_source = $balise_svg;
3696
-
3697
-	// entete XML à supprimer
3698
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3699
-
3700
-	// IE est toujours mon ami
3701
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3702
-
3703
-	// regler la classe
3704
-	if (!is_null($class)) {
3705
-		if (strlen($class)) {
3706
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3707
-		}
3708
-		else {
3709
-			$balise_svg = vider_attribut($balise_svg, 'class');
3710
-		}
3711
-	}
3712
-
3713
-	// regler le alt
3714
-	if ($alt) {
3715
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3716
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3717
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3718
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3719
-		$balise_svg .= $title;
3720
-	}
3721
-	else {
3722
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3723
-	}
3724
-
3725
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3726
-
3727
-	if (!is_null($size) and strlen($size = trim($size))) {
3728
-		[$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3729
-
3730
-		if (!function_exists('svg_redimensionner')) {
3731
-			include_spip('inc/svg');
3732
-		}
3733
-		$svg = svg_redimensionner($svg, $width, $height);
3734
-	}
3735
-
3736
-	return $svg;
3663
+    $svg = null;
3664
+    $img = trim($img);
3665
+    $img_file = $img;
3666
+    if (strpos($img, '<svg') === false) {
3667
+        if ($p = strpos($img_file, '?')) {
3668
+            $img_file = substr($img_file, 0, $p);
3669
+        }
3670
+
3671
+        // ne jamais operer directement sur une image distante pour des raisons de perfo
3672
+        // la copie locale a toutes les chances d'etre la ou de resservir
3673
+        if (tester_url_absolue($img_file)) {
3674
+            include_spip('inc/distant');
3675
+            $fichier = copie_locale($img_file);
3676
+            $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3677
+        }
3678
+
3679
+        if (
3680
+            !$img_file
3681
+            or !file_exists($img_file)
3682
+            or !$svg = file_get_contents($img_file)
3683
+        ) {
3684
+            return '';
3685
+        }
3686
+    }
3687
+
3688
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3689
+        return '';
3690
+    }
3691
+
3692
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3693
+
3694
+    $balise_svg = $match[0];
3695
+    $balise_svg_source = $balise_svg;
3696
+
3697
+    // entete XML à supprimer
3698
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3699
+
3700
+    // IE est toujours mon ami
3701
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3702
+
3703
+    // regler la classe
3704
+    if (!is_null($class)) {
3705
+        if (strlen($class)) {
3706
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3707
+        }
3708
+        else {
3709
+            $balise_svg = vider_attribut($balise_svg, 'class');
3710
+        }
3711
+    }
3712
+
3713
+    // regler le alt
3714
+    if ($alt) {
3715
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3716
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3717
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3718
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3719
+        $balise_svg .= $title;
3720
+    }
3721
+    else {
3722
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3723
+    }
3724
+
3725
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3726
+
3727
+    if (!is_null($size) and strlen($size = trim($size))) {
3728
+        [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3729
+
3730
+        if (!function_exists('svg_redimensionner')) {
3731
+            include_spip('inc/svg');
3732
+        }
3733
+        $svg = svg_redimensionner($svg, $width, $height);
3734
+    }
3735
+
3736
+    return $svg;
3737 3737
 }
3738 3738
 
3739 3739
 
@@ -3759,18 +3759,18 @@  discard block
 block discarded – undo
3759 3759
  *     Code HTML résultant
3760 3760
  **/
3761 3761
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3762
-	$texte = '';
3763
-	if (is_array($tableau)) {
3764
-		foreach ($tableau as $k => $v) {
3765
-			$res = recuperer_fond(
3766
-				'modeles/' . $modele,
3767
-				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3768
-			);
3769
-			$texte .= $res;
3770
-		}
3771
-	}
3762
+    $texte = '';
3763
+    if (is_array($tableau)) {
3764
+        foreach ($tableau as $k => $v) {
3765
+            $res = recuperer_fond(
3766
+                'modeles/' . $modele,
3767
+                array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3768
+            );
3769
+            $texte .= $res;
3770
+        }
3771
+    }
3772 3772
 
3773
-	return $texte;
3773
+    return $texte;
3774 3774
 }
3775 3775
 
3776 3776
 
@@ -3795,37 +3795,37 @@  discard block
 block discarded – undo
3795 3795
  *         - tout : retourne toutes les informations du plugin actif
3796 3796
  **/
3797 3797
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3798
-	include_spip('inc/plugin');
3799
-	$plugin = strtoupper($plugin);
3800
-	$plugins_actifs = liste_plugin_actifs();
3801
-
3802
-	if (!$plugin) {
3803
-		return serialize(array_keys($plugins_actifs));
3804
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3805
-		return '';
3806
-	} elseif (($type_info == 'est_actif') and !$reload) {
3807
-		return $plugins_actifs[$plugin] ? 1 : 0;
3808
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3809
-		return $plugins_actifs[$plugin][$type_info];
3810
-	} else {
3811
-		$get_infos = charger_fonction('get_infos', 'plugins');
3812
-		// On prend en compte les extensions
3813
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3814
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3815
-		} else {
3816
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3817
-		}
3818
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3819
-			return '';
3820
-		}
3821
-		if ($type_info == 'tout') {
3822
-			return $infos;
3823
-		} elseif ($type_info == 'est_actif') {
3824
-			return $infos ? 1 : 0;
3825
-		} else {
3826
-			return strval($infos[$type_info]);
3827
-		}
3828
-	}
3798
+    include_spip('inc/plugin');
3799
+    $plugin = strtoupper($plugin);
3800
+    $plugins_actifs = liste_plugin_actifs();
3801
+
3802
+    if (!$plugin) {
3803
+        return serialize(array_keys($plugins_actifs));
3804
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3805
+        return '';
3806
+    } elseif (($type_info == 'est_actif') and !$reload) {
3807
+        return $plugins_actifs[$plugin] ? 1 : 0;
3808
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3809
+        return $plugins_actifs[$plugin][$type_info];
3810
+    } else {
3811
+        $get_infos = charger_fonction('get_infos', 'plugins');
3812
+        // On prend en compte les extensions
3813
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3814
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3815
+        } else {
3816
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3817
+        }
3818
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3819
+            return '';
3820
+        }
3821
+        if ($type_info == 'tout') {
3822
+            return $infos;
3823
+        } elseif ($type_info == 'est_actif') {
3824
+            return $infos ? 1 : 0;
3825
+        } else {
3826
+            return strval($infos[$type_info]);
3827
+        }
3828
+    }
3829 3829
 }
3830 3830
 
3831 3831
 
@@ -3852,9 +3852,9 @@  discard block
 block discarded – undo
3852 3852
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3853 3853
  */
3854 3854
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3855
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3855
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3856 3856
 
3857
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3857
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3858 3858
 }
3859 3859
 
3860 3860
 
@@ -3884,19 +3884,19 @@  discard block
 block discarded – undo
3884 3884
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3885 3885
  */
3886 3886
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3887
-	static $puce_statut = null;
3888
-	if (!$puce_statut) {
3889
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3890
-	}
3887
+    static $puce_statut = null;
3888
+    if (!$puce_statut) {
3889
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3890
+    }
3891 3891
 
3892
-	return $puce_statut(
3893
-		$id_objet,
3894
-		$statut,
3895
-		$id_parent,
3896
-		$objet,
3897
-		false,
3898
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3899
-	);
3892
+    return $puce_statut(
3893
+        $id_objet,
3894
+        $statut,
3895
+        $id_parent,
3896
+        $objet,
3897
+        false,
3898
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3899
+    );
3900 3900
 }
3901 3901
 
3902 3902
 
@@ -3923,98 +3923,98 @@  discard block
 block discarded – undo
3923 3923
  *   hash du contexte
3924 3924
  */
3925 3925
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3926
-	$env = null;
3927
-	if (
3928
-		is_string($c)
3929
-		and @unserialize($c) !== false
3930
-	) {
3931
-		$c = unserialize($c);
3932
-	}
3933
-
3934
-	// supprimer les parametres debut_x
3935
-	// pour que la pagination ajax ne soit pas plantee
3936
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3937
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3938
-	if (is_array($c)) {
3939
-		foreach ($c as $k => $v) {
3940
-			if (strpos($k, 'debut_') === 0) {
3941
-				unset($c[$k]);
3942
-			}
3943
-		}
3944
-	}
3945
-
3946
-	if (!function_exists('calculer_cle_action')) {
3947
-		include_spip('inc/securiser_action');
3948
-	}
3949
-
3950
-	$c = serialize($c);
3951
-	$cle = calculer_cle_action($form . $c);
3952
-	$c = "$cle:$c";
3953
-
3954
-	// on ne stocke pas les contextes dans des fichiers en cache
3955
-	// par defaut, sauf si cette configuration a été forcée
3956
-	// OU que la longueur de l’argument géneré est plus long
3957
-	// que ce qui est toléré.
3958
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3959
-	if (!$cache_contextes_ajax) {
3960
-		$env = $c;
3961
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3962
-			$env = gzdeflate($env);
3963
-		}
3964
-		$env = _xor($env);
3965
-		$env = base64_encode($env);
3966
-		$len = strlen($env);
3967
-		// Si l’url est trop longue pour le navigateur
3968
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3969
-		if ($len > $max_len) {
3970
-			$cache_contextes_ajax = true;
3971
-			spip_log(
3972
-				'Contextes AJAX forces en fichiers !'
3973
-				. ' Cela arrive lorsque la valeur du contexte'
3974
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3975
-				_LOG_AVERTISSEMENT
3976
-			);
3977
-		}
3978
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3979
-		elseif (
3980
-			$max_len = @ini_get('suhosin.get.max_value_length')
3981
-			and $max_len < $len
3982
-		) {
3983
-			$cache_contextes_ajax = true;
3984
-			spip_log('Contextes AJAX forces en fichiers !'
3985
-				. ' Cela arrive lorsque la valeur du contexte'
3986
-				. ' depasse la longueur maximale autorisee par Suhosin'
3987
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3988
-				. ' Vous devriez modifier les parametres de Suhosin'
3989
-				. ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
3990
-		}
3991
-	}
3992
-
3993
-	if ($cache_contextes_ajax) {
3994
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
3995
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
3996
-		$md5 = md5($c);
3997
-		ecrire_fichier("$dir/c$md5", $c);
3998
-		$env = $md5;
3999
-	}
4000
-
4001
-	if ($emboite === null) {
4002
-		return $env;
4003
-	}
4004
-	if (!trim($emboite)) {
4005
-		return '';
4006
-	}
4007
-	// toujours encoder l'url source dans le bloc ajax
4008
-	$r = self();
4009
-	$r = ' data-origin="' . $r . '"';
4010
-	$class = 'ajaxbloc';
4011
-	if ($ajaxid and is_string($ajaxid)) {
4012
-		// ajaxid est normalement conforme a un nom de classe css
4013
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4014
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4015
-	}
4016
-
4017
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3926
+    $env = null;
3927
+    if (
3928
+        is_string($c)
3929
+        and @unserialize($c) !== false
3930
+    ) {
3931
+        $c = unserialize($c);
3932
+    }
3933
+
3934
+    // supprimer les parametres debut_x
3935
+    // pour que la pagination ajax ne soit pas plantee
3936
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3937
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3938
+    if (is_array($c)) {
3939
+        foreach ($c as $k => $v) {
3940
+            if (strpos($k, 'debut_') === 0) {
3941
+                unset($c[$k]);
3942
+            }
3943
+        }
3944
+    }
3945
+
3946
+    if (!function_exists('calculer_cle_action')) {
3947
+        include_spip('inc/securiser_action');
3948
+    }
3949
+
3950
+    $c = serialize($c);
3951
+    $cle = calculer_cle_action($form . $c);
3952
+    $c = "$cle:$c";
3953
+
3954
+    // on ne stocke pas les contextes dans des fichiers en cache
3955
+    // par defaut, sauf si cette configuration a été forcée
3956
+    // OU que la longueur de l’argument géneré est plus long
3957
+    // que ce qui est toléré.
3958
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3959
+    if (!$cache_contextes_ajax) {
3960
+        $env = $c;
3961
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3962
+            $env = gzdeflate($env);
3963
+        }
3964
+        $env = _xor($env);
3965
+        $env = base64_encode($env);
3966
+        $len = strlen($env);
3967
+        // Si l’url est trop longue pour le navigateur
3968
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3969
+        if ($len > $max_len) {
3970
+            $cache_contextes_ajax = true;
3971
+            spip_log(
3972
+                'Contextes AJAX forces en fichiers !'
3973
+                . ' Cela arrive lorsque la valeur du contexte'
3974
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3975
+                _LOG_AVERTISSEMENT
3976
+            );
3977
+        }
3978
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3979
+        elseif (
3980
+            $max_len = @ini_get('suhosin.get.max_value_length')
3981
+            and $max_len < $len
3982
+        ) {
3983
+            $cache_contextes_ajax = true;
3984
+            spip_log('Contextes AJAX forces en fichiers !'
3985
+                . ' Cela arrive lorsque la valeur du contexte'
3986
+                . ' depasse la longueur maximale autorisee par Suhosin'
3987
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3988
+                . ' Vous devriez modifier les parametres de Suhosin'
3989
+                . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
3990
+        }
3991
+    }
3992
+
3993
+    if ($cache_contextes_ajax) {
3994
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
3995
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
3996
+        $md5 = md5($c);
3997
+        ecrire_fichier("$dir/c$md5", $c);
3998
+        $env = $md5;
3999
+    }
4000
+
4001
+    if ($emboite === null) {
4002
+        return $env;
4003
+    }
4004
+    if (!trim($emboite)) {
4005
+        return '';
4006
+    }
4007
+    // toujours encoder l'url source dans le bloc ajax
4008
+    $r = self();
4009
+    $r = ' data-origin="' . $r . '"';
4010
+    $class = 'ajaxbloc';
4011
+    if ($ajaxid and is_string($ajaxid)) {
4012
+        // ajaxid est normalement conforme a un nom de classe css
4013
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4014
+        $class .= ' ajax-id-' . entites_html($ajaxid);
4015
+    }
4016
+
4017
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4018 4018
 }
4019 4019
 
4020 4020
 /**
@@ -4034,37 +4034,37 @@  discard block
 block discarded – undo
4034 4034
  *   - false : erreur de décodage
4035 4035
  */
4036 4036
 function decoder_contexte_ajax($c, $form = '') {
4037
-	if (!function_exists('calculer_cle_action')) {
4038
-		include_spip('inc/securiser_action');
4039
-	}
4040
-	if (
4041
-		((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4042
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4043
-		and lire_fichier("$dir/c$c", $contexte)
4044
-	) {
4045
-		$c = $contexte;
4046
-	} else {
4047
-		$c = @base64_decode($c);
4048
-		$c = _xor($c);
4049
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4050
-			$c = @gzinflate($c);
4051
-		}
4052
-	}
4053
-
4054
-	// extraire la signature en debut de contexte
4055
-	// et la verifier avant de deserializer
4056
-	// format : signature:donneesserializees
4057
-	if ($p = strpos($c, ':')) {
4058
-		$cle = substr($c, 0, $p);
4059
-		$c = substr($c, $p + 1);
4060
-
4061
-		if ($cle == calculer_cle_action($form . $c)) {
4062
-			$env = @unserialize($c);
4063
-			return $env;
4064
-		}
4065
-	}
4066
-
4067
-	return false;
4037
+    if (!function_exists('calculer_cle_action')) {
4038
+        include_spip('inc/securiser_action');
4039
+    }
4040
+    if (
4041
+        ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4042
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4043
+        and lire_fichier("$dir/c$c", $contexte)
4044
+    ) {
4045
+        $c = $contexte;
4046
+    } else {
4047
+        $c = @base64_decode($c);
4048
+        $c = _xor($c);
4049
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4050
+            $c = @gzinflate($c);
4051
+        }
4052
+    }
4053
+
4054
+    // extraire la signature en debut de contexte
4055
+    // et la verifier avant de deserializer
4056
+    // format : signature:donneesserializees
4057
+    if ($p = strpos($c, ':')) {
4058
+        $cle = substr($c, 0, $p);
4059
+        $c = substr($c, $p + 1);
4060
+
4061
+        if ($cle == calculer_cle_action($form . $c)) {
4062
+            $env = @unserialize($c);
4063
+            return $env;
4064
+        }
4065
+    }
4066
+
4067
+    return false;
4068 4068
 }
4069 4069
 
4070 4070
 
@@ -4082,20 +4082,20 @@  discard block
 block discarded – undo
4082 4082
  *    Message décrypté ou encrypté
4083 4083
  **/
4084 4084
 function _xor($message, $key = null) {
4085
-	if (is_null($key)) {
4086
-		if (!function_exists('calculer_cle_action')) {
4087
-			include_spip('inc/securiser_action');
4088
-		}
4089
-		$key = pack('H*', calculer_cle_action('_xor'));
4090
-	}
4085
+    if (is_null($key)) {
4086
+        if (!function_exists('calculer_cle_action')) {
4087
+            include_spip('inc/securiser_action');
4088
+        }
4089
+        $key = pack('H*', calculer_cle_action('_xor'));
4090
+    }
4091 4091
 
4092
-	$keylen = strlen($key);
4093
-	$messagelen = strlen($message);
4094
-	for ($i = 0; $i < $messagelen; $i++) {
4095
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4096
-	}
4092
+    $keylen = strlen($key);
4093
+    $messagelen = strlen($message);
4094
+    for ($i = 0; $i < $messagelen; $i++) {
4095
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4096
+    }
4097 4097
 
4098
-	return $message;
4098
+    return $message;
4099 4099
 }
4100 4100
 
4101 4101
 /**
@@ -4109,7 +4109,7 @@  discard block
 block discarded – undo
4109 4109
  * @return string
4110 4110
  */
4111 4111
 function url_reponse_forum($texte) {
4112
- return $texte;
4112
+    return $texte;
4113 4113
 }
4114 4114
 
4115 4115
 /**
@@ -4123,7 +4123,7 @@  discard block
 block discarded – undo
4123 4123
  * @return string
4124 4124
  */
4125 4125
 function url_rss_forum($texte) {
4126
- return $texte;
4126
+    return $texte;
4127 4127
 }
4128 4128
 
4129 4129
 
@@ -4162,37 +4162,37 @@  discard block
 block discarded – undo
4162 4162
  *   Code HTML
4163 4163
  */
4164 4164
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4165
-	if ($on) {
4166
-		$bal = 'strong';
4167
-		$class = '';
4168
-		$att = '';
4169
-		// si $on passe la balise et optionnelement une ou ++classe
4170
-		// a.active span.selected.active etc....
4171
-		if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4172
-			$on = explode('.', $on);
4173
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4174
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4175
-				$bal = array_shift($on);
4176
-				$class = implode(' ', $on);
4177
-				if ($bal == 'a') {
4178
-					$att = 'href="#" ';
4179
-				}
4180
-			}
4181
-		}
4182
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4183
-	} else {
4184
-		$bal = 'a';
4185
-		$att = "href='$url'"
4186
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4187
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4188
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4189
-			. $evt;
4190
-	}
4191
-	if ($libelle === null) {
4192
-		$libelle = $url;
4193
-	}
4194
-
4195
-	return "<$bal $att>$libelle</$bal>";
4165
+    if ($on) {
4166
+        $bal = 'strong';
4167
+        $class = '';
4168
+        $att = '';
4169
+        // si $on passe la balise et optionnelement une ou ++classe
4170
+        // a.active span.selected.active etc....
4171
+        if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4172
+            $on = explode('.', $on);
4173
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4174
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4175
+                $bal = array_shift($on);
4176
+                $class = implode(' ', $on);
4177
+                if ($bal == 'a') {
4178
+                    $att = 'href="#" ';
4179
+                }
4180
+            }
4181
+        }
4182
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4183
+    } else {
4184
+        $bal = 'a';
4185
+        $att = "href='$url'"
4186
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4187
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4188
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4189
+            . $evt;
4190
+    }
4191
+    if ($libelle === null) {
4192
+        $libelle = $url;
4193
+    }
4194
+
4195
+    return "<$bal $att>$libelle</$bal>";
4196 4196
 }
4197 4197
 
4198 4198
 
@@ -4209,39 +4209,39 @@  discard block
 block discarded – undo
4209 4209
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4210 4210
  */
4211 4211
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4212
-	static $local_singulier_ou_pluriel = [];
4213
-
4214
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4215
-	if (!is_numeric($nb) or $nb == 0) {
4216
-		return '';
4217
-	}
4218
-	if (!is_array($vars)) {
4219
-		return '';
4220
-	}
4221
-
4222
-	$langue = $GLOBALS['spip_lang'];
4223
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4224
-		$local_singulier_ou_pluriel[$langue] = false;
4225
-		if (
4226
-			$f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)
4227
-			or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4228
-		) {
4229
-			$local_singulier_ou_pluriel[$langue] = $f;
4230
-		}
4231
-	}
4232
-
4233
-	// si on a une surcharge on l'utilise
4234
-	if ($local_singulier_ou_pluriel[$langue]) {
4235
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4236
-	}
4237
-
4238
-	// sinon traitement par defaut
4239
-	$vars[$var] = $nb;
4240
-	if ($nb >= 2) {
4241
-		return _T($chaine_plusieurs, $vars);
4242
-	} else {
4243
-		return _T($chaine_un, $vars);
4244
-	}
4212
+    static $local_singulier_ou_pluriel = [];
4213
+
4214
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4215
+    if (!is_numeric($nb) or $nb == 0) {
4216
+        return '';
4217
+    }
4218
+    if (!is_array($vars)) {
4219
+        return '';
4220
+    }
4221
+
4222
+    $langue = $GLOBALS['spip_lang'];
4223
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4224
+        $local_singulier_ou_pluriel[$langue] = false;
4225
+        if (
4226
+            $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)
4227
+            or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4228
+        ) {
4229
+            $local_singulier_ou_pluriel[$langue] = $f;
4230
+        }
4231
+    }
4232
+
4233
+    // si on a une surcharge on l'utilise
4234
+    if ($local_singulier_ou_pluriel[$langue]) {
4235
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4236
+    }
4237
+
4238
+    // sinon traitement par defaut
4239
+    $vars[$var] = $nb;
4240
+    if ($nb >= 2) {
4241
+        return _T($chaine_plusieurs, $vars);
4242
+    } else {
4243
+        return _T($chaine_un, $vars);
4244
+    }
4245 4245
 }
4246 4246
 
4247 4247
 
@@ -4269,73 +4269,73 @@  discard block
 block discarded – undo
4269 4269
  */
4270 4270
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4271 4271
 
4272
-	$class_lien = $class_bouton = $class;
4273
-
4274
-	// Normaliser la fonction et compléter la classe en fonction
4275
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4276
-		$class_lien .= ' danger';
4277
-		$class_bouton .= ' btn_danger';
4278
-	} elseif ($fonction == 'rien.gif') {
4279
-		$fonction = '';
4280
-	} elseif ($fonction == 'delsafe') {
4281
-		$fonction = 'del';
4282
-	}
4283
-
4284
-	$fond_origine = $fond;
4285
-	// Remappage des icone : article-24.png+new => article-new-24.png
4286
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4287
-		[$fond, $fonction] = $icone_renommer($fond, $fonction);
4288
-	}
4289
-
4290
-	// Ajouter le type d'objet dans la classe
4291
-	$objet_type = substr(basename($fond), 0, -4);
4292
-	$class_lien .= " $objet_type";
4293
-	$class_bouton .= " $objet_type";
4294
-
4295
-	// texte
4296
-	$alt = attribut_html($texte);
4297
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4298
-
4299
-	// Liens : préparer les classes ajax
4300
-	$ajax = '';
4301
-	if ($type === 'lien') {
4302
-		if (strpos($class_lien, 'ajax') !== false) {
4303
-			$ajax = 'ajax';
4304
-			if (strpos($class_lien, 'preload') !== false) {
4305
-				$ajax .= ' preload';
4306
-			}
4307
-			if (strpos($class_lien, 'nocache') !== false) {
4308
-				$ajax .= ' nocache';
4309
-			}
4310
-			$ajax = " class='$ajax'";
4311
-		}
4312
-	}
4313
-
4314
-	// Repérer la taille et l'ajouter dans la classe
4315
-	$size = 24;
4316
-	if (
4317
-		preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4318
-		or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4319
-	) {
4320
-		$size = $match[1];
4321
-	}
4322
-	$class_lien .= " s$size";
4323
-	$class_bouton .= " s$size";
4324
-
4325
-	// Icône
4326
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4327
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4328
-
4329
-	// Markup final
4330
-	if ($type == 'lien') {
4331
-		return "<span class='icone $class_lien'>"
4332
-		. "<a href='$lien'$title$ajax$javascript>"
4333
-		. $icone
4334
-		. "<b>$texte</b>"
4335
-		. "</a></span>\n";
4336
-	} else {
4337
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4338
-	}
4272
+    $class_lien = $class_bouton = $class;
4273
+
4274
+    // Normaliser la fonction et compléter la classe en fonction
4275
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4276
+        $class_lien .= ' danger';
4277
+        $class_bouton .= ' btn_danger';
4278
+    } elseif ($fonction == 'rien.gif') {
4279
+        $fonction = '';
4280
+    } elseif ($fonction == 'delsafe') {
4281
+        $fonction = 'del';
4282
+    }
4283
+
4284
+    $fond_origine = $fond;
4285
+    // Remappage des icone : article-24.png+new => article-new-24.png
4286
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4287
+        [$fond, $fonction] = $icone_renommer($fond, $fonction);
4288
+    }
4289
+
4290
+    // Ajouter le type d'objet dans la classe
4291
+    $objet_type = substr(basename($fond), 0, -4);
4292
+    $class_lien .= " $objet_type";
4293
+    $class_bouton .= " $objet_type";
4294
+
4295
+    // texte
4296
+    $alt = attribut_html($texte);
4297
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4298
+
4299
+    // Liens : préparer les classes ajax
4300
+    $ajax = '';
4301
+    if ($type === 'lien') {
4302
+        if (strpos($class_lien, 'ajax') !== false) {
4303
+            $ajax = 'ajax';
4304
+            if (strpos($class_lien, 'preload') !== false) {
4305
+                $ajax .= ' preload';
4306
+            }
4307
+            if (strpos($class_lien, 'nocache') !== false) {
4308
+                $ajax .= ' nocache';
4309
+            }
4310
+            $ajax = " class='$ajax'";
4311
+        }
4312
+    }
4313
+
4314
+    // Repérer la taille et l'ajouter dans la classe
4315
+    $size = 24;
4316
+    if (
4317
+        preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4318
+        or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4319
+    ) {
4320
+        $size = $match[1];
4321
+    }
4322
+    $class_lien .= " s$size";
4323
+    $class_bouton .= " s$size";
4324
+
4325
+    // Icône
4326
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4327
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4328
+
4329
+    // Markup final
4330
+    if ($type == 'lien') {
4331
+        return "<span class='icone $class_lien'>"
4332
+        . "<a href='$lien'$title$ajax$javascript>"
4333
+        . $icone
4334
+        . "<b>$texte</b>"
4335
+        . "</a></span>\n";
4336
+    } else {
4337
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4338
+    }
4339 4339
 }
4340 4340
 
4341 4341
 /**
@@ -4359,7 +4359,7 @@  discard block
 block discarded – undo
4359 4359
  *     Code HTML du lien
4360 4360
  **/
4361 4361
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4362
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4362
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4363 4363
 }
4364 4364
 
4365 4365
 /**
@@ -4394,7 +4394,7 @@  discard block
 block discarded – undo
4394 4394
  *     Code HTML du lien
4395 4395
  **/
4396 4396
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4397
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4397
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4398 4398
 }
4399 4399
 
4400 4400
 /**
@@ -4439,7 +4439,7 @@  discard block
 block discarded – undo
4439 4439
  *     Code HTML du lien
4440 4440
  **/
4441 4441
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4442
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4442
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4443 4443
 }
4444 4444
 
4445 4445
 /**
@@ -4470,7 +4470,7 @@  discard block
 block discarded – undo
4470 4470
  *     Code HTML du lien
4471 4471
  **/
4472 4472
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4473
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4473
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4474 4474
 }
4475 4475
 
4476 4476
 /**
@@ -4501,7 +4501,7 @@  discard block
 block discarded – undo
4501 4501
  *     Code HTML du lien
4502 4502
  */
4503 4503
 function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') {
4504
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4504
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4505 4505
 }
4506 4506
 
4507 4507
 
@@ -4523,7 +4523,7 @@  discard block
 block discarded – undo
4523 4523
  * @return array Liste des éléments
4524 4524
  */
4525 4525
 function filtre_explode_dist($a, $b) {
4526
-	return explode($b, (string) $a);
4526
+    return explode($b, (string) $a);
4527 4527
 }
4528 4528
 
4529 4529
 /**
@@ -4544,7 +4544,7 @@  discard block
 block discarded – undo
4544 4544
  * @return string texte
4545 4545
  */
4546 4546
 function filtre_implode_dist($a, $b) {
4547
-	return is_array($a) ? implode($b, $a) : $a;
4547
+    return is_array($a) ? implode($b, $a) : $a;
4548 4548
 }
4549 4549
 
4550 4550
 /**
@@ -4553,22 +4553,22 @@  discard block
 block discarded – undo
4553 4553
  * @return string Code CSS
4554 4554
  */
4555 4555
 function bando_images_background() {
4556
-	include_spip('inc/bandeau');
4557
-	// recuperer tous les boutons et leurs images
4558
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4556
+    include_spip('inc/bandeau');
4557
+    // recuperer tous les boutons et leurs images
4558
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4559 4559
 
4560
-	$res = '';
4561
-	foreach ($boutons as $page => $detail) {
4562
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4563
-		foreach ($detail->sousmenu as $souspage => $sousdetail) {
4564
-			if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4565
-				$img = http_img_variante_svg_si_possible($sousdetail->icone);
4566
-				$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4567
-			}
4568
-		}
4569
-	}
4560
+    $res = '';
4561
+    foreach ($boutons as $page => $detail) {
4562
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4563
+        foreach ($detail->sousmenu as $souspage => $sousdetail) {
4564
+            if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4565
+                $img = http_img_variante_svg_si_possible($sousdetail->icone);
4566
+                $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4567
+            }
4568
+        }
4569
+    }
4570 4570
 
4571
-	return $res;
4571
+    return $res;
4572 4572
 }
4573 4573
 
4574 4574
 /**
@@ -4593,27 +4593,27 @@  discard block
 block discarded – undo
4593 4593
  */
4594 4594
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4595 4595
 
4596
-	// Classes : dispatcher `ajax` sur le formulaire
4597
-	$class_form = '';
4598
-	if (strpos($class, 'ajax') !== false) {
4599
-		$class_form = 'ajax';
4600
-		$class = str_replace('ajax', '', $class);
4601
-	}
4602
-	$class_btn = 'submit ' . trim($class);
4596
+    // Classes : dispatcher `ajax` sur le formulaire
4597
+    $class_form = '';
4598
+    if (strpos($class, 'ajax') !== false) {
4599
+        $class_form = 'ajax';
4600
+        $class = str_replace('ajax', '', $class);
4601
+    }
4602
+    $class_btn = 'submit ' . trim($class);
4603 4603
 
4604
-	if ($confirm) {
4605
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4606
-		if ($callback) {
4607
-			$callback = "$confirm?($callback):false";
4608
-		} else {
4609
-			$callback = $confirm;
4610
-		}
4611
-	}
4612
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4613
-	$title = $title ? " title='$title'" : '';
4604
+    if ($confirm) {
4605
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4606
+        if ($callback) {
4607
+            $callback = "$confirm?($callback):false";
4608
+        } else {
4609
+            $callback = $confirm;
4610
+        }
4611
+    }
4612
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4613
+    $title = $title ? " title='$title'" : '';
4614 4614
 
4615
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4616
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4615
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4616
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4617 4617
 }
4618 4618
 
4619 4619
 /**
@@ -4636,101 +4636,101 @@  discard block
 block discarded – undo
4636 4636
  * @return string
4637 4637
  */
4638 4638
 function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string {
4639
-	static $trouver_table = null;
4640
-	static $objets;
4641
-
4642
-	// On verifie qu'on a tout ce qu'il faut
4643
-	$id_objet = intval($id_objet);
4644
-	if (!($id_objet and $type_objet and $info)) {
4645
-		return '';
4646
-	}
4647
-
4648
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4649
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4650
-		return '';
4651
-	}
4652
-
4653
-	// Si on demande l'url, on retourne direct la fonction
4654
-	if ($info == 'url') {
4655
-		return generer_objet_url($id_objet, $type_objet, ...$params);
4656
-	}
4657
-
4658
-	// Sinon on va tout chercher dans la table et on garde en memoire
4659
-	$demande_titre = ($info === 'titre');
4660
-	$demande_introduction = ($info === 'introduction');
4661
-
4662
-	// On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore
4663
-	if (
4664
-		!isset($objets[$type_objet][$id_objet])
4665
-		or
4666
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4667
-	) {
4668
-		if (!$trouver_table) {
4669
-			$trouver_table = charger_fonction('trouver_table', 'base');
4670
-		}
4671
-		$desc = $trouver_table(table_objet_sql($type_objet));
4672
-		if (!$desc) {
4673
-			return $objets[$type_objet] = false;
4674
-		}
4675
-
4676
-		// Si on demande le titre, on le gere en interne
4677
-		$champ_titre = '';
4678
-		if ($demande_titre) {
4679
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4680
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4681
-		}
4682
-		include_spip('base/abstract_sql');
4683
-		include_spip('base/connect_sql');
4684
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4685
-			'*' . $champ_titre,
4686
-			$desc['table_sql'],
4687
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4688
-		);
4689
-
4690
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4691
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4692
-	}
4693
-
4694
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4695
-	// ajouter la longueur au début des params supplémentaires
4696
-	if ($demande_introduction) {
4697
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4698
-		array_unshift($params, $introduction_longueur);
4699
-	}
4700
-
4701
-	// Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4702
-	if (
4703
-		$generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)
4704
-		// @deprecated 4.1 generer_TRUC_TYPE
4705
-		or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)
4706
-	) {
4707
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4708
-	}
4709
-	// Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4710
-	elseif (
4711
-		$generer = charger_fonction("generer_objet_{$info}", '', true)
4712
-		// @deprecated 4.1 generer_TRUC_entite
4713
-		or $generer = charger_fonction("generer_{$info}_entite", '', true)
4714
-	) {
4715
-		$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4716
-	} // Sinon on prend directement le champ SQL tel quel
4717
-	else {
4718
-		$info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4719
-	}
4720
-
4721
-	// On va ensuite appliquer les traitements automatiques si besoin
4722
-	if (!$etoile) {
4723
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4724
-		// mais ce fonctionnement est a ameliorer !
4725
-		$info_generee = appliquer_traitement_champ(
4726
-			$info_generee,
4727
-			$info,
4728
-			table_objet($type_objet),
4729
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4730
-		);
4731
-	}
4732
-
4733
-	return $info_generee;
4639
+    static $trouver_table = null;
4640
+    static $objets;
4641
+
4642
+    // On verifie qu'on a tout ce qu'il faut
4643
+    $id_objet = intval($id_objet);
4644
+    if (!($id_objet and $type_objet and $info)) {
4645
+        return '';
4646
+    }
4647
+
4648
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4649
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4650
+        return '';
4651
+    }
4652
+
4653
+    // Si on demande l'url, on retourne direct la fonction
4654
+    if ($info == 'url') {
4655
+        return generer_objet_url($id_objet, $type_objet, ...$params);
4656
+    }
4657
+
4658
+    // Sinon on va tout chercher dans la table et on garde en memoire
4659
+    $demande_titre = ($info === 'titre');
4660
+    $demande_introduction = ($info === 'introduction');
4661
+
4662
+    // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore
4663
+    if (
4664
+        !isset($objets[$type_objet][$id_objet])
4665
+        or
4666
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4667
+    ) {
4668
+        if (!$trouver_table) {
4669
+            $trouver_table = charger_fonction('trouver_table', 'base');
4670
+        }
4671
+        $desc = $trouver_table(table_objet_sql($type_objet));
4672
+        if (!$desc) {
4673
+            return $objets[$type_objet] = false;
4674
+        }
4675
+
4676
+        // Si on demande le titre, on le gere en interne
4677
+        $champ_titre = '';
4678
+        if ($demande_titre) {
4679
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4680
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4681
+        }
4682
+        include_spip('base/abstract_sql');
4683
+        include_spip('base/connect_sql');
4684
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4685
+            '*' . $champ_titre,
4686
+            $desc['table_sql'],
4687
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4688
+        );
4689
+
4690
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4691
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4692
+    }
4693
+
4694
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4695
+    // ajouter la longueur au début des params supplémentaires
4696
+    if ($demande_introduction) {
4697
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4698
+        array_unshift($params, $introduction_longueur);
4699
+    }
4700
+
4701
+    // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4702
+    if (
4703
+        $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)
4704
+        // @deprecated 4.1 generer_TRUC_TYPE
4705
+        or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)
4706
+    ) {
4707
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4708
+    }
4709
+    // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4710
+    elseif (
4711
+        $generer = charger_fonction("generer_objet_{$info}", '', true)
4712
+        // @deprecated 4.1 generer_TRUC_entite
4713
+        or $generer = charger_fonction("generer_{$info}_entite", '', true)
4714
+    ) {
4715
+        $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4716
+    } // Sinon on prend directement le champ SQL tel quel
4717
+    else {
4718
+        $info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4719
+    }
4720
+
4721
+    // On va ensuite appliquer les traitements automatiques si besoin
4722
+    if (!$etoile) {
4723
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4724
+        // mais ce fonctionnement est a ameliorer !
4725
+        $info_generee = appliquer_traitement_champ(
4726
+            $info_generee,
4727
+            $info,
4728
+            table_objet($type_objet),
4729
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4730
+        );
4731
+    }
4732
+
4733
+    return $info_generee;
4734 4734
 }
4735 4735
 
4736 4736
 /**
@@ -4738,7 +4738,7 @@  discard block
 block discarded – undo
4738 4738
  * @see generer_objet_info
4739 4739
  */
4740 4740
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) {
4741
-	return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4741
+    return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4742 4742
 }
4743 4743
 
4744 4744
 /**
@@ -4771,36 +4771,36 @@  discard block
 block discarded – undo
4771 4771
  */
4772 4772
 function generer_objet_introduction(int $id_objet, string $type_objet, array $ligne_sql, ?int $introduction_longueur = null, $longueur_ou_suite = null, ?string $suite = null, string $connect = ''): string {
4773 4773
 
4774
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4775
-	$texte = $ligne_sql['texte'] ?? '';
4776
-	// En absence de descriptif, on se rabat sur chapo + texte
4777
-	if (isset($ligne_sql['chapo'])) {
4778
-		$chapo = $ligne_sql['chapo'];
4779
-		$texte = strlen($descriptif) ?
4780
-			'' :
4781
-			"$chapo \n\n $texte";
4782
-	}
4774
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4775
+    $texte = $ligne_sql['texte'] ?? '';
4776
+    // En absence de descriptif, on se rabat sur chapo + texte
4777
+    if (isset($ligne_sql['chapo'])) {
4778
+        $chapo = $ligne_sql['chapo'];
4779
+        $texte = strlen($descriptif) ?
4780
+            '' :
4781
+            "$chapo \n\n $texte";
4782
+    }
4783 4783
 
4784
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4785
-	if (!intval($longueur_ou_suite)) {
4786
-		$longueur = intval($introduction_longueur ?: 600);
4787
-	} else {
4788
-		$longueur = intval($longueur_ou_suite);
4789
-	}
4784
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4785
+    if (!intval($longueur_ou_suite)) {
4786
+        $longueur = intval($introduction_longueur ?: 600);
4787
+    } else {
4788
+        $longueur = intval($longueur_ou_suite);
4789
+    }
4790 4790
 
4791
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4792
-	// Ex : #INTRODUCTION{...}
4793
-	if (
4794
-		is_null($suite)
4795
-		and !intval($longueur_ou_suite)
4796
-	) {
4797
-		$suite = $longueur_ou_suite;
4798
-	}
4791
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4792
+    // Ex : #INTRODUCTION{...}
4793
+    if (
4794
+        is_null($suite)
4795
+        and !intval($longueur_ou_suite)
4796
+    ) {
4797
+        $suite = $longueur_ou_suite;
4798
+    }
4799 4799
 
4800
-	$f = chercher_filtre('introduction');
4801
-	$introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4800
+    $f = chercher_filtre('introduction');
4801
+    $introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4802 4802
 
4803
-	return $introduction;
4803
+    return $introduction;
4804 4804
 }
4805 4805
 
4806 4806
 /**
@@ -4808,7 +4808,7 @@  discard block
 block discarded – undo
4808 4808
  * @see generer_objet_introduction
4809 4809
  */
4810 4810
 function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') {
4811
-	return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4811
+    return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4812 4812
 }
4813 4813
 
4814 4814
 /**
@@ -4822,49 +4822,49 @@  discard block
 block discarded – undo
4822 4822
  * @return string
4823 4823
  */
4824 4824
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') {
4825
-	if (!$champ) {
4826
-		return $texte;
4827
-	}
4825
+    if (!$champ) {
4826
+        return $texte;
4827
+    }
4828 4828
 
4829
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4830
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4831
-	include_fichiers_fonctions();
4829
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4830
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4831
+    include_fichiers_fonctions();
4832 4832
 
4833
-	$champ = strtoupper($champ);
4834
-	$traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4835
-	if (!$traitements or !is_array($traitements)) {
4836
-		return $texte;
4837
-	}
4833
+    $champ = strtoupper($champ);
4834
+    $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4835
+    if (!$traitements or !is_array($traitements)) {
4836
+        return $texte;
4837
+    }
4838 4838
 
4839
-	$traitement = '';
4840
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4841
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4842
-		$table_objet = table_objet($table_objet);
4843
-		if (isset($traitements[$table_objet])) {
4844
-			$traitement = $traitements[$table_objet];
4845
-		}
4846
-	}
4847
-	if (!$traitement and isset($traitements[0])) {
4848
-		$traitement = $traitements[0];
4849
-	}
4850
-	// (sinon prendre le premier de la liste par defaut ?)
4839
+    $traitement = '';
4840
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4841
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4842
+        $table_objet = table_objet($table_objet);
4843
+        if (isset($traitements[$table_objet])) {
4844
+            $traitement = $traitements[$table_objet];
4845
+        }
4846
+    }
4847
+    if (!$traitement and isset($traitements[0])) {
4848
+        $traitement = $traitements[0];
4849
+    }
4850
+    // (sinon prendre le premier de la liste par defaut ?)
4851 4851
 
4852
-	if (!$traitement) {
4853
-		return $texte;
4854
-	}
4852
+    if (!$traitement) {
4853
+        return $texte;
4854
+    }
4855 4855
 
4856
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4856
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4857 4857
 
4858
-	// signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4859
-	if (test_espace_prive()) {
4860
-		$env['espace_prive'] = 1;
4861
-	}
4858
+    // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4859
+    if (test_espace_prive()) {
4860
+        $env['espace_prive'] = 1;
4861
+    }
4862 4862
 
4863
-	// Fournir $connect et $Pile[0] au traitement si besoin
4864
-	$Pile = [0 => $env];
4865
-	eval("\$texte = $traitement;");
4863
+    // Fournir $connect et $Pile[0] au traitement si besoin
4864
+    $Pile = [0 => $env];
4865
+    eval("\$texte = $traitement;");
4866 4866
 
4867
-	return $texte;
4867
+    return $texte;
4868 4868
 }
4869 4869
 
4870 4870
 
@@ -4878,21 +4878,21 @@  discard block
 block discarded – undo
4878 4878
  * @return string
4879 4879
  */
4880 4880
 function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string {
4881
-	include_spip('inc/liens');
4882
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4883
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4884
-	// le raccourcis n'est plus valide
4885
-	$titre = typo($titre['titre'] ?? '');
4886
-	// on essaye avec generer_info_entite ?
4887
-	if (!strlen($titre) and !$connect) {
4888
-		$titre = generer_objet_info($id_objet, $objet, 'titre');
4889
-	}
4890
-	if (!strlen($titre)) {
4891
-		$titre = _T('info_sans_titre');
4892
-	}
4893
-	$url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4881
+    include_spip('inc/liens');
4882
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4883
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4884
+    // le raccourcis n'est plus valide
4885
+    $titre = typo($titre['titre'] ?? '');
4886
+    // on essaye avec generer_info_entite ?
4887
+    if (!strlen($titre) and !$connect) {
4888
+        $titre = generer_objet_info($id_objet, $objet, 'titre');
4889
+    }
4890
+    if (!strlen($titre)) {
4891
+        $titre = _T('info_sans_titre');
4892
+    }
4893
+    $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4894 4894
 
4895
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4895
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4896 4896
 }
4897 4897
 
4898 4898
 /**
@@ -4900,7 +4900,7 @@  discard block
 block discarded – undo
4900 4900
  * @see generer_objet_lien
4901 4901
  */
4902 4902
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4903
-	return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
4903
+    return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
4904 4904
 }
4905 4905
 
4906 4906
 /**
@@ -4916,15 +4916,15 @@  discard block
 block discarded – undo
4916 4916
  * @return string
4917 4917
  */
4918 4918
 function wrap($texte, $wrap) {
4919
-	$balises = extraire_balises($wrap);
4920
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4921
-		$texte = $wrap . $texte;
4922
-		$regs = array_reverse($regs[1]);
4923
-		$wrap = '</' . implode('></', $regs) . '>';
4924
-		$texte = $texte . $wrap;
4925
-	}
4919
+    $balises = extraire_balises($wrap);
4920
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4921
+        $texte = $wrap . $texte;
4922
+        $regs = array_reverse($regs[1]);
4923
+        $wrap = '</' . implode('></', $regs) . '>';
4924
+        $texte = $texte . $wrap;
4925
+    }
4926 4926
 
4927
-	return $texte;
4927
+    return $texte;
4928 4928
 }
4929 4929
 
4930 4930
 
@@ -4944,44 +4944,44 @@  discard block
 block discarded – undo
4944 4944
  * @return array|mixed|string
4945 4945
  */
4946 4946
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
4947
-	if (is_string($u)) {
4948
-		$u = typo($u);
4947
+    if (is_string($u)) {
4948
+        $u = typo($u);
4949 4949
 
4950
-		return $u;
4951
-	}
4950
+        return $u;
4951
+    }
4952 4952
 
4953
-	// caster $u en array si besoin
4954
-	if (is_object($u)) {
4955
-		$u = (array)$u;
4956
-	}
4953
+    // caster $u en array si besoin
4954
+    if (is_object($u)) {
4955
+        $u = (array)$u;
4956
+    }
4957 4957
 
4958
-	if (is_array($u)) {
4959
-		$out = '';
4960
-		// toutes les cles sont numeriques ?
4961
-		// et aucun enfant n'est un tableau
4962
-		// liste simple separee par des virgules
4963
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4964
-		$array_values = array_map('is_array', $u);
4965
-		$object_values = array_map('is_object', $u);
4966
-		if (
4967
-			array_sum($numeric_keys) == count($numeric_keys)
4968
-			and !array_sum($array_values)
4969
-			and !array_sum($object_values)
4970
-		) {
4971
-			return join(', ', array_map('filtre_print_dist', $u));
4972
-		}
4958
+    if (is_array($u)) {
4959
+        $out = '';
4960
+        // toutes les cles sont numeriques ?
4961
+        // et aucun enfant n'est un tableau
4962
+        // liste simple separee par des virgules
4963
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4964
+        $array_values = array_map('is_array', $u);
4965
+        $object_values = array_map('is_object', $u);
4966
+        if (
4967
+            array_sum($numeric_keys) == count($numeric_keys)
4968
+            and !array_sum($array_values)
4969
+            and !array_sum($object_values)
4970
+        ) {
4971
+            return join(', ', array_map('filtre_print_dist', $u));
4972
+        }
4973 4973
 
4974
-		// sinon on passe a la ligne et on indente
4975
-		$i_str = str_pad('', $indent, ' ');
4976
-		foreach ($u as $k => $v) {
4977
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4978
-		}
4974
+        // sinon on passe a la ligne et on indente
4975
+        $i_str = str_pad('', $indent, ' ');
4976
+        foreach ($u as $k => $v) {
4977
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4978
+        }
4979 4979
 
4980
-		return $out;
4981
-	}
4980
+        return $out;
4981
+    }
4982 4982
 
4983
-	// on sait pas quoi faire...
4984
-	return $u;
4983
+    // on sait pas quoi faire...
4984
+    return $u;
4985 4985
 }
4986 4986
 
4987 4987
 
@@ -4994,10 +4994,10 @@  discard block
 block discarded – undo
4994 4994
  * @return string|array
4995 4995
  */
4996 4996
 function objet_info($objet, $info) {
4997
-	$table = table_objet_sql($objet);
4998
-	$infos = lister_tables_objets_sql($table);
4997
+    $table = table_objet_sql($objet);
4998
+    $infos = lister_tables_objets_sql($table);
4999 4999
 
5000
-	return ($infos[$info] ?? '');
5000
+    return ($infos[$info] ?? '');
5001 5001
 }
5002 5002
 
5003 5003
 /**
@@ -5012,11 +5012,11 @@  discard block
 block discarded – undo
5012 5012
  *     texte traduit du comptage, tel que '3 articles'
5013 5013
  */
5014 5014
 function objet_afficher_nb($nb, $objet) {
5015
-	if (!$nb) {
5016
-		return _T(objet_info($objet, 'info_aucun_objet'));
5017
-	} else {
5018
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5019
-	}
5015
+    if (!$nb) {
5016
+        return _T(objet_info($objet, 'info_aucun_objet'));
5017
+    } else {
5018
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5019
+    }
5020 5020
 }
5021 5021
 
5022 5022
 /**
@@ -5028,11 +5028,11 @@  discard block
 block discarded – undo
5028 5028
  * @return string
5029 5029
  */
5030 5030
 function objet_icone($objet, $taille = 24, $class = '') {
5031
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5032
-	$icone = chemin_image($icone);
5033
-	$balise_img = charger_filtre('balise_img');
5031
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5032
+    $icone = chemin_image($icone);
5033
+    $balise_img = charger_filtre('balise_img');
5034 5034
 
5035
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5035
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5036 5036
 }
5037 5037
 
5038 5038
 /**
@@ -5053,12 +5053,12 @@  discard block
 block discarded – undo
5053 5053
  * @return string
5054 5054
  */
5055 5055
 function objet_T($objet, $chaine, $args = [], $options = []) {
5056
-	$chaine = explode(':', $chaine);
5057
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5058
-		return $t;
5059
-	}
5060
-	$chaine = implode(':', $chaine);
5061
-	return _T($chaine, $args, $options);
5056
+    $chaine = explode(':', $chaine);
5057
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5058
+        return $t;
5059
+    }
5060
+    $chaine = implode(':', $chaine);
5061
+    return _T($chaine, $args, $options);
5062 5062
 }
5063 5063
 
5064 5064
 /**
@@ -5072,18 +5072,18 @@  discard block
 block discarded – undo
5072 5072
  * @return string      Code HTML
5073 5073
  */
5074 5074
 function insert_head_css_conditionnel($flux) {
5075
-	if (
5076
-		strpos($flux, '<!-- insert_head_css -->') === false
5077
-		and $p = strpos($flux, '<!-- insert_head -->')
5078
-	) {
5079
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
5080
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5081
-			$p = $p1;
5082
-		}
5083
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5084
-	}
5075
+    if (
5076
+        strpos($flux, '<!-- insert_head_css -->') === false
5077
+        and $p = strpos($flux, '<!-- insert_head -->')
5078
+    ) {
5079
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
5080
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5081
+            $p = $p1;
5082
+        }
5083
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5084
+    }
5085 5085
 
5086
-	return $flux;
5086
+    return $flux;
5087 5087
 }
5088 5088
 
5089 5089
 /**
@@ -5106,75 +5106,75 @@  discard block
 block discarded – undo
5106 5106
  * @return string
5107 5107
  */
5108 5108
 function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') {
5109
-	if (isset($contexte['format'])) {
5110
-		$extension = $contexte['format'];
5111
-		unset($contexte['format']);
5112
-	} else {
5113
-		$extension = 'html';
5114
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5115
-			$extension = $m[1];
5116
-		}
5117
-	}
5118
-	// recuperer le contenu produit par le squelette
5119
-	$options['raw'] = true;
5120
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5121
-
5122
-	// calculer le nom de la css
5123
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5124
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5125
-	$contexte_implicite = calculer_contexte_implicite();
5126
-
5127
-	// par defaut on hash selon les contextes qui sont a priori moins variables
5128
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5129
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5130
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5131
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5132
-	}
5133
-	else {
5134
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5135
-		ksort($contexte);
5136
-		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5137
-	}
5138
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5139
-
5140
-	// mettre a jour le fichier si il n'existe pas
5141
-	// ou trop ancien
5142
-	// le dernier fichier produit est toujours suffixe par .last
5143
-	// et recopie sur le fichier cible uniquement si il change
5144
-	if (
5145
-		!file_exists($filename)
5146
-		or !file_exists($filename . '.last')
5147
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5148
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5149
-	) {
5150
-		$contenu = $cache['texte'];
5151
-		// passer les urls en absolu si c'est une css
5152
-		if ($extension == 'css') {
5153
-			$contenu = urls_absolues_css(
5154
-				$contenu,
5155
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5156
-			);
5157
-		}
5158
-
5159
-		$comment = '';
5160
-		// ne pas insérer de commentaire sur certains formats
5161
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
5162
-			$comment = "/* #PRODUIRE{fond=$fond";
5163
-			foreach ($contexte as $k => $v) {
5164
-				if (is_array($v)) {
5165
-					$v = var_export($v, true);
5166
-				}
5167
-				$comment .= ",$k=$v";
5168
-			}
5169
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5170
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5171
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5172
-		}
5173
-		// et ecrire le fichier si il change
5174
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5175
-	}
5176
-
5177
-	return timestamp($filename);
5109
+    if (isset($contexte['format'])) {
5110
+        $extension = $contexte['format'];
5111
+        unset($contexte['format']);
5112
+    } else {
5113
+        $extension = 'html';
5114
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5115
+            $extension = $m[1];
5116
+        }
5117
+    }
5118
+    // recuperer le contenu produit par le squelette
5119
+    $options['raw'] = true;
5120
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
5121
+
5122
+    // calculer le nom de la css
5123
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5124
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5125
+    $contexte_implicite = calculer_contexte_implicite();
5126
+
5127
+    // par defaut on hash selon les contextes qui sont a priori moins variables
5128
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5129
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5130
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5131
+        $hash = md5($contexte_implicite['host'] . '::' . $cache);
5132
+    }
5133
+    else {
5134
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5135
+        ksort($contexte);
5136
+        $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5137
+    }
5138
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5139
+
5140
+    // mettre a jour le fichier si il n'existe pas
5141
+    // ou trop ancien
5142
+    // le dernier fichier produit est toujours suffixe par .last
5143
+    // et recopie sur le fichier cible uniquement si il change
5144
+    if (
5145
+        !file_exists($filename)
5146
+        or !file_exists($filename . '.last')
5147
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5148
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5149
+    ) {
5150
+        $contenu = $cache['texte'];
5151
+        // passer les urls en absolu si c'est une css
5152
+        if ($extension == 'css') {
5153
+            $contenu = urls_absolues_css(
5154
+                $contenu,
5155
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5156
+            );
5157
+        }
5158
+
5159
+        $comment = '';
5160
+        // ne pas insérer de commentaire sur certains formats
5161
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
5162
+            $comment = "/* #PRODUIRE{fond=$fond";
5163
+            foreach ($contexte as $k => $v) {
5164
+                if (is_array($v)) {
5165
+                    $v = var_export($v, true);
5166
+                }
5167
+                $comment .= ",$k=$v";
5168
+            }
5169
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5170
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5171
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
5172
+        }
5173
+        // et ecrire le fichier si il change
5174
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5175
+    }
5176
+
5177
+    return timestamp($filename);
5178 5178
 }
5179 5179
 
5180 5180
 /**
@@ -5187,15 +5187,15 @@  discard block
 block discarded – undo
5187 5187
  *    $fichier auquel on a ajouté le timestamp
5188 5188
  */
5189 5189
 function timestamp($fichier) {
5190
-	if (
5191
-		!$fichier
5192
-		or !file_exists($fichier)
5193
-		or !$m = filemtime($fichier)
5194
-	) {
5195
-		return $fichier;
5196
-	}
5190
+    if (
5191
+        !$fichier
5192
+        or !file_exists($fichier)
5193
+        or !$m = filemtime($fichier)
5194
+    ) {
5195
+        return $fichier;
5196
+    }
5197 5197
 
5198
-	return "$fichier?$m";
5198
+    return "$fichier?$m";
5199 5199
 }
5200 5200
 
5201 5201
 /**
@@ -5205,11 +5205,11 @@  discard block
 block discarded – undo
5205 5205
  * @return string
5206 5206
  */
5207 5207
 function supprimer_timestamp($url) {
5208
-	if (strpos($url, '?') === false) {
5209
-		return $url;
5210
-	}
5208
+    if (strpos($url, '?') === false) {
5209
+        return $url;
5210
+    }
5211 5211
 
5212
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5212
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5213 5213
 }
5214 5214
 
5215 5215
 /**
@@ -5224,15 +5224,15 @@  discard block
 block discarded – undo
5224 5224
  * @return string
5225 5225
  */
5226 5226
 function filtre_nettoyer_titre_email_dist($titre) {
5227
-	include_spip('inc/envoyer_mail');
5227
+    include_spip('inc/envoyer_mail');
5228 5228
 
5229
-	$titre = nettoyer_titre_email($titre);
5230
-	// on est dans un squelette : securiser le retour
5231
-	if (strpos($titre, '<') !== false) {
5232
-		$titre = interdire_scripts($titre);
5233
-	}
5229
+    $titre = nettoyer_titre_email($titre);
5230
+    // on est dans un squelette : securiser le retour
5231
+    if (strpos($titre, '<') !== false) {
5232
+        $titre = interdire_scripts($titre);
5233
+    }
5234 5234
 
5235
-	return $titre;
5235
+    return $titre;
5236 5236
 }
5237 5237
 
5238 5238
 /**
@@ -5254,27 +5254,27 @@  discard block
 block discarded – undo
5254 5254
  * @return string
5255 5255
  */
5256 5256
 function filtre_chercher_rubrique_dist(
5257
-	$titre,
5258
-	$id_objet,
5259
-	$id_parent,
5260
-	$objet,
5261
-	$id_secteur,
5262
-	$restreint,
5263
-	$actionable = false,
5264
-	$retour_sans_cadre = false
5257
+    $titre,
5258
+    $id_objet,
5259
+    $id_parent,
5260
+    $objet,
5261
+    $id_secteur,
5262
+    $restreint,
5263
+    $actionable = false,
5264
+    $retour_sans_cadre = false
5265 5265
 ) {
5266
-	include_spip('inc/filtres_ecrire');
5266
+    include_spip('inc/filtres_ecrire');
5267 5267
 
5268
-	return chercher_rubrique(
5269
-		$titre,
5270
-		$id_objet,
5271
-		$id_parent,
5272
-		$objet,
5273
-		$id_secteur,
5274
-		$restreint,
5275
-		$actionable,
5276
-		$retour_sans_cadre
5277
-	);
5268
+    return chercher_rubrique(
5269
+        $titre,
5270
+        $id_objet,
5271
+        $id_parent,
5272
+        $objet,
5273
+        $id_secteur,
5274
+        $restreint,
5275
+        $actionable,
5276
+        $retour_sans_cadre
5277
+    );
5278 5278
 }
5279 5279
 
5280 5280
 /**
@@ -5303,56 +5303,56 @@  discard block
 block discarded – undo
5303 5303
  *     Chaîne vide si l'accès est autorisé
5304 5304
  */
5305 5305
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5306
-	if ($ok) {
5307
-		return '';
5308
-	}
5309
-
5310
-	// Vider tous les tampons
5311
-	$level = @ob_get_level();
5312
-	while ($level--) {
5313
-		@ob_end_clean();
5314
-	}
5315
-
5316
-	include_spip('inc/headers');
5317
-
5318
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5319
-	if ($url) {
5320
-		redirige_par_entete($url, '', $statut);
5321
-	}
5322
-
5323
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5324
-	if (!is_numeric($statut) and is_null($message)) {
5325
-		$message = $statut;
5326
-		$statut = 0;
5327
-	}
5328
-	if (!$message) {
5329
-		$message = '';
5330
-	}
5331
-	$statut = intval($statut);
5332
-
5333
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5334
-	if (test_espace_prive()) {
5335
-		if (!$statut or !in_array($statut, [404, 403])) {
5336
-			$statut = 403;
5337
-		}
5338
-		http_response_code(403);
5339
-		$echec = charger_fonction('403', 'exec');
5340
-		$echec($message);
5341
-	} else {
5342
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5343
-		if (!$statut) {
5344
-			$statut = 404;
5345
-		}
5346
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5347
-		http_response_code($statut);
5348
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5349
-		if ($statut >= 400) {
5350
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5351
-		}
5352
-	}
5353
-
5354
-
5355
-	exit;
5306
+    if ($ok) {
5307
+        return '';
5308
+    }
5309
+
5310
+    // Vider tous les tampons
5311
+    $level = @ob_get_level();
5312
+    while ($level--) {
5313
+        @ob_end_clean();
5314
+    }
5315
+
5316
+    include_spip('inc/headers');
5317
+
5318
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5319
+    if ($url) {
5320
+        redirige_par_entete($url, '', $statut);
5321
+    }
5322
+
5323
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5324
+    if (!is_numeric($statut) and is_null($message)) {
5325
+        $message = $statut;
5326
+        $statut = 0;
5327
+    }
5328
+    if (!$message) {
5329
+        $message = '';
5330
+    }
5331
+    $statut = intval($statut);
5332
+
5333
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5334
+    if (test_espace_prive()) {
5335
+        if (!$statut or !in_array($statut, [404, 403])) {
5336
+            $statut = 403;
5337
+        }
5338
+        http_response_code(403);
5339
+        $echec = charger_fonction('403', 'exec');
5340
+        $echec($message);
5341
+    } else {
5342
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5343
+        if (!$statut) {
5344
+            $statut = 404;
5345
+        }
5346
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5347
+        http_response_code($statut);
5348
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5349
+        if ($statut >= 400) {
5350
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5351
+        }
5352
+    }
5353
+
5354
+
5355
+    exit;
5356 5356
 }
5357 5357
 
5358 5358
 /**
@@ -5363,11 +5363,11 @@  discard block
 block discarded – undo
5363 5363
  * @return string
5364 5364
  */
5365 5365
 function filtre_compacte_dist($source, $format = null) {
5366
-	if (function_exists('minifier')) {
5367
-		return minifier($source, $format);
5368
-	}
5366
+    if (function_exists('minifier')) {
5367
+        return minifier($source, $format);
5368
+    }
5369 5369
 
5370
-	return $source;
5370
+    return $source;
5371 5371
 }
5372 5372
 
5373 5373
 
@@ -5379,32 +5379,32 @@  discard block
 block discarded – undo
5379 5379
  * @return string
5380 5380
  */
5381 5381
 function spip_affiche_mot_de_passe_masque(#[\SensitiveParameter] ?string $passe, bool $afficher_partiellement = false, ?int $portion_pourcent = null): string {
5382
-	$passe ??= '';
5383
-	$l = strlen($passe);
5384
-
5385
-	if ($l <= 8 or !$afficher_partiellement) {
5386
-		if (!$l) {
5387
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5388
-		}
5389
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5390
-	}
5391
-
5392
-	if (is_null($portion_pourcent)) {
5393
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5394
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5395
-		}
5396
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5397
-	}
5398
-	if ($portion_pourcent >= 100) {
5399
-		return $passe;
5400
-	}
5401
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5402
-	$e = max($e, 0);
5403
-	$mid = str_pad('', $l - 2 * $e, '*');
5404
-	if ($e > 0 and strlen($mid) > 8) {
5405
-		$mid = '***...***';
5406
-	}
5407
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5382
+    $passe ??= '';
5383
+    $l = strlen($passe);
5384
+
5385
+    if ($l <= 8 or !$afficher_partiellement) {
5386
+        if (!$l) {
5387
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5388
+        }
5389
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5390
+    }
5391
+
5392
+    if (is_null($portion_pourcent)) {
5393
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5394
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5395
+        }
5396
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5397
+    }
5398
+    if ($portion_pourcent >= 100) {
5399
+        return $passe;
5400
+    }
5401
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5402
+    $e = max($e, 0);
5403
+    $mid = str_pad('', $l - 2 * $e, '*');
5404
+    if ($e > 0 and strlen($mid) > 8) {
5405
+        $mid = '***...***';
5406
+    }
5407
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5408 5408
 }
5409 5409
 
5410 5410
 
@@ -5425,64 +5425,64 @@  discard block
 block discarded – undo
5425 5425
  */
5426 5426
 function identifiant_slug($texte, $type = '', $options = []) {
5427 5427
 
5428
-	$original = $texte;
5429
-	$separateur = ($options['separateur'] ?? '_');
5430
-	$longueur_maxi = ($options['longueur_maxi'] ?? 60);
5431
-	$longueur_mini = ($options['longueur_mini'] ?? 0);
5428
+    $original = $texte;
5429
+    $separateur = ($options['separateur'] ?? '_');
5430
+    $longueur_maxi = ($options['longueur_maxi'] ?? 60);
5431
+    $longueur_mini = ($options['longueur_mini'] ?? 0);
5432 5432
 
5433
-	if (!function_exists('translitteration')) {
5434
-		include_spip('inc/charsets');
5435
-	}
5433
+    if (!function_exists('translitteration')) {
5434
+        include_spip('inc/charsets');
5435
+    }
5436 5436
 
5437
-	// pas de balise html
5438
-	if (strpos($texte, '<') !== false) {
5439
-		$texte = strip_tags($texte);
5440
-	}
5441
-	if (strpos($texte, '&') !== false) {
5442
-		$texte = unicode2charset($texte);
5443
-	}
5444
-	// On enlève les espaces indésirables
5445
-	$texte = trim($texte);
5437
+    // pas de balise html
5438
+    if (strpos($texte, '<') !== false) {
5439
+        $texte = strip_tags($texte);
5440
+    }
5441
+    if (strpos($texte, '&') !== false) {
5442
+        $texte = unicode2charset($texte);
5443
+    }
5444
+    // On enlève les espaces indésirables
5445
+    $texte = trim($texte);
5446 5446
 
5447
-	// On enlève les accents et cie
5448
-	$texte = translitteration($texte);
5447
+    // On enlève les accents et cie
5448
+    $texte = translitteration($texte);
5449 5449
 
5450
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5451
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5450
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5451
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5452 5452
 
5453
-	// nettoyer les doubles occurences du separateur si besoin
5454
-	while (strpos($texte, (string) "$separateur$separateur") !== false) {
5455
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5456
-	}
5453
+    // nettoyer les doubles occurences du separateur si besoin
5454
+    while (strpos($texte, (string) "$separateur$separateur") !== false) {
5455
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5456
+    }
5457 5457
 
5458
-	// pas de separateur au debut ni a la fin
5459
-	$texte = trim($texte, $separateur);
5458
+    // pas de separateur au debut ni a la fin
5459
+    $texte = trim($texte, $separateur);
5460 5460
 
5461
-	// en minuscules
5462
-	$texte = strtolower($texte);
5461
+    // en minuscules
5462
+    $texte = strtolower($texte);
5463 5463
 
5464
-	switch ($type) {
5465
-		case 'class':
5466
-		case 'id':
5467
-		case 'anchor':
5468
-			if (preg_match(',^\d,', $texte)) {
5469
-				$texte = substr($type, 0, 1) . $texte;
5470
-			}
5471
-	}
5464
+    switch ($type) {
5465
+        case 'class':
5466
+        case 'id':
5467
+        case 'anchor':
5468
+            if (preg_match(',^\d,', $texte)) {
5469
+                $texte = substr($type, 0, 1) . $texte;
5470
+            }
5471
+    }
5472 5472
 
5473
-	if (strlen($texte) > $longueur_maxi) {
5474
-		$texte = substr($texte, 0, $longueur_maxi);
5475
-	}
5473
+    if (strlen($texte) > $longueur_maxi) {
5474
+        $texte = substr($texte, 0, $longueur_maxi);
5475
+    }
5476 5476
 
5477
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5478
-		if (preg_match(',^\d,', $texte)) {
5479
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5480
-		}
5481
-		$texte .= $separateur . md5($original);
5482
-		$texte = substr($texte, 0, $longueur_mini);
5483
-	}
5477
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5478
+        if (preg_match(',^\d,', $texte)) {
5479
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5480
+        }
5481
+        $texte .= $separateur . md5($original);
5482
+        $texte = substr($texte, 0, $longueur_mini);
5483
+    }
5484 5484
 
5485
-	return $texte;
5485
+    return $texte;
5486 5486
 }
5487 5487
 
5488 5488
 
@@ -5503,11 +5503,11 @@  discard block
 block discarded – undo
5503 5503
  * @exemple `<:info_maximum|label_nettoyer:>`
5504 5504
  */
5505 5505
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5506
-	$label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5507
-	if ($ucfirst) {
5508
-		$label = spip_ucfirst($label);
5509
-	}
5510
-	return $label;
5506
+    $label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5507
+    if ($ucfirst) {
5508
+        $label = spip_ucfirst($label);
5509
+    }
5510
+    return $label;
5511 5511
 }
5512 5512
 
5513 5513
 /**
@@ -5520,8 +5520,8 @@  discard block
 block discarded – undo
5520 5520
  * @exemple `<:info_maximum|label_ponctuer:>`
5521 5521
  */
5522 5522
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5523
-	$label = label_nettoyer($text, $ucfirst);
5524
-	return _T('label_ponctuer', ['label' => $label]);
5523
+    $label = label_nettoyer($text, $ucfirst);
5524
+    return _T('label_ponctuer', ['label' => $label]);
5525 5525
 }
5526 5526
 
5527 5527
 
@@ -5534,19 +5534,19 @@  discard block
 block discarded – undo
5534 5534
  * @return array
5535 5535
  */
5536 5536
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5537
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5538
-		return [];
5539
-	}
5537
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5538
+        return [];
5539
+    }
5540 5540
 
5541
-	// compatibilite signature inversee
5542
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5543
-		[$objet, $id_objet] = [$id_objet, $objet];
5544
-	}
5541
+    // compatibilite signature inversee
5542
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5543
+        [$objet, $id_objet] = [$id_objet, $objet];
5544
+    }
5545 5545
 
5546
-	if (!function_exists($fonction)) {
5547
-		include_spip('base/objets');
5548
-	}
5549
-	return $fonction($objet, $id_objet);
5546
+    if (!function_exists($fonction)) {
5547
+        include_spip('base/objets');
5548
+    }
5549
+    return $fonction($objet, $id_objet);
5550 5550
 }
5551 5551
 
5552 5552
 
@@ -5561,7 +5561,7 @@  discard block
 block discarded – undo
5561 5561
  * @return array
5562 5562
  */
5563 5563
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5564
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5564
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5565 5565
 }
5566 5566
 
5567 5567
 /**
@@ -5575,7 +5575,7 @@  discard block
 block discarded – undo
5575 5575
  * @return array
5576 5576
  */
5577 5577
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5578
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5578
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5579 5579
 }
5580 5580
 
5581 5581
 /**
@@ -5589,7 +5589,7 @@  discard block
 block discarded – undo
5589 5589
  * @return array
5590 5590
  */
5591 5591
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5592
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5592
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5593 5593
 }
5594 5594
 
5595 5595
 /**
@@ -5603,5 +5603,5 @@  discard block
 block discarded – undo
5603 5603
  * @return array
5604 5604
  */
5605 5605
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5606
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5606
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5607 5607
 }
Please login to merge, or discard this patch.
ecrire/src/Chiffrer/SpipCles.php 2 patches
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -14,171 +14,171 @@
 block discarded – undo
14 14
 
15 15
 /** Gestion des clés d’authentification / chiffrement de SPIP */
16 16
 final class SpipCles {
17
-	private static array $instances = [];
18
-
19
-	private string $file = _DIR_ETC . 'cles.php';
20
-	private Cles $cles;
21
-
22
-	public static function instance(string $file = ''): self {
23
-		if (empty(self::$instances[$file])) {
24
-			self::$instances[$file] = new self($file);
25
-		}
26
-		return self::$instances[$file];
27
-	}
28
-
29
-	/**
30
-	 * Retourne le secret du site (shorthand)
31
-	 * @uses self::getSecretSite()
32
-	 */
33
-	public static function secret_du_site(): ?string {
34
-		return (self::instance())->getSecretSite();
35
-	}
36
-
37
-	private function __construct(string $file = '') {
38
-		if ($file) {
39
-			$this->file = $file;
40
-		}
41
-		$this->cles = new Cles($this->read());
42
-	}
43
-
44
-	/**
45
-	 * Renvoyer le secret du site
46
-	 *
47
-	 * Le secret du site doit rester aussi secret que possible, et est eternel
48
-	 * On ne doit pas l'exporter
49
-	 *
50
-	 * Le secret est partagé entre une clé disque et une clé bdd
51
-	 *
52
-	 * @return string
53
-	 */
54
-	public function getSecretSite(bool $autoInit = true): ?string {
55
-		$key = $this->getKey('secret_du_site', $autoInit);
56
-		$meta = $this->getMetaKey('secret_du_site', $autoInit);
57
-		// conserve la même longeur.
58
-		return $key ^ $meta;
59
-	}
60
-
61
-	/** Renvoyer le secret des authentifications */
62
-	public function getSecretAuth(bool $autoInit = false): ?string {
63
-		return $this->getKey('secret_des_auth', $autoInit);
64
-	}
65
-	public function save(): bool {
66
-		return ecrire_fichier_securise($this->file, $this->cles->toJson());
67
-	}
68
-
69
-	/**
70
-	 * Fournir une sauvegarde chiffree des cles (a l'aide d'une autre clé, comme le pass d'un auteur)
71
-	 *
72
-	 * @param string $withKey Clé de chiffrage de la sauvegarde
73
-	 * @return string Contenu de la sauvegarde chiffrée générée
74
-	 */
75
-	public function backup(
76
-		#[\SensitiveParameter]
77
-		string $withKey
78
-	): string {
79
-		if (count($this->cles)) {
80
-			return Chiffrement::chiffrer($this->cles->toJson(), $withKey);
81
-		}
82
-		return '';
83
-	}
84
-
85
-	/**
86
-	 * Restaurer les cles manquantes depuis une sauvegarde chiffree des cles
87
-	 * (si la sauvegarde est bien valide)
88
-	 *
89
-	 * @param string $backup Sauvegarde chiffrée (générée par backup())
90
-	 * @param int $id_auteur
91
-	 * @param string $pass
92
-	 * @return void
93
-	 */
94
-	public function restore(
95
-		string $backup,
96
-		#[\SensitiveParameter]
97
-		string $password_clair,
98
-		#[\SensitiveParameter]
99
-		string $password_hash,
100
-		int $id_auteur
101
-	): bool {
102
-		if (empty($backup)) {
103
-			return false;
104
-		}
105
-
106
-		$sauvegarde = Chiffrement::dechiffrer($backup, $password_clair);
107
-		$json = json_decode($sauvegarde, true);
108
-		if (!$json) {
109
-			return false;
110
-		}
111
-
112
-		// cela semble une sauvegarde valide
113
-		$cles_potentielles = array_map('base64_decode', $json);
114
-
115
-		// il faut faire une double verif sur secret_des_auth
116
-		// pour s'assurer qu'elle permet bien de decrypter le pass de l'auteur qui fournit la sauvegarde
117
-		// et par extension tous les passwords
118
-		if (!empty($cles_potentielles['secret_des_auth'])) {
119
-			if (!Password::verifier($password_clair, $password_hash, $cles_potentielles['secret_des_auth'])) {
120
-				spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer' . _LOG_INFO_IMPORTANTE);
121
-				unset($cles_potentielles['secret_des_auth']);
122
-			}
123
-		}
124
-
125
-		// on merge les cles pour recuperer les cles manquantes
126
-		$restauration = false;
127
-		foreach ($cles_potentielles as $name => $key) {
128
-			if (!$this->cles->has($name)) {
129
-				$this->cles->set($name, $key);
130
-				spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer' . _LOG_INFO_IMPORTANTE);
131
-				$restauration = true;
132
-			}
133
-		}
134
-		return $restauration;
135
-	}
136
-
137
-	private function getKey(string $name, bool $autoInit): ?string {
138
-		if ($this->cles->has($name)) {
139
-			return $this->cles->get($name);
140
-		}
141
-		if ($autoInit) {
142
-			$this->cles->generate($name);
143
-			// si l'ecriture de fichier a bien marche on peut utiliser la cle
144
-			if ($this->save()) {
145
-				return $this->cles->get($name);
146
-			}
147
-			// sinon loger et annule la cle generee car il ne faut pas l'utiliser
148
-			spip_log('Echec ecriture du fichier cle ' . $this->file . " ; impossible de generer une cle $name", 'chiffrer' . _LOG_ERREUR);
149
-			$this->cles->delete($name);
150
-		}
151
-		return null;
152
-	}
153
-
154
-	private function getMetaKey(string $name, bool $autoInit = true): ?string {
155
-		if (!isset($GLOBALS['meta'][$name])) {
156
-			include_spip('base/abstract_sql');
157
-			$GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = ' . sql_quote($name, '', 'string'));
158
-		}
159
-		$key = base64_decode($GLOBALS['meta'][$name] ?? '');
160
-		if (strlen($key) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
161
-			return $key;
162
-		}
163
-		if (!$autoInit) {
164
-			return null;
165
-		}
166
-		$key = Chiffrement::keygen();
167
-		ecrire_meta($name, base64_encode($key), 'non');
168
-		lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas
169
-
170
-		return $key;
171
-	}
172
-
173
-	private function read(): array {
174
-		lire_fichier_securise($this->file, $json);
175
-		if (
176
-			$json
177
-			and $json = \json_decode($json, true)
178
-			and is_array($json)
179
-		) {
180
-			return array_map('base64_decode', $json);
181
-		}
182
-		return [];
183
-	}
17
+    private static array $instances = [];
18
+
19
+    private string $file = _DIR_ETC . 'cles.php';
20
+    private Cles $cles;
21
+
22
+    public static function instance(string $file = ''): self {
23
+        if (empty(self::$instances[$file])) {
24
+            self::$instances[$file] = new self($file);
25
+        }
26
+        return self::$instances[$file];
27
+    }
28
+
29
+    /**
30
+     * Retourne le secret du site (shorthand)
31
+     * @uses self::getSecretSite()
32
+     */
33
+    public static function secret_du_site(): ?string {
34
+        return (self::instance())->getSecretSite();
35
+    }
36
+
37
+    private function __construct(string $file = '') {
38
+        if ($file) {
39
+            $this->file = $file;
40
+        }
41
+        $this->cles = new Cles($this->read());
42
+    }
43
+
44
+    /**
45
+     * Renvoyer le secret du site
46
+     *
47
+     * Le secret du site doit rester aussi secret que possible, et est eternel
48
+     * On ne doit pas l'exporter
49
+     *
50
+     * Le secret est partagé entre une clé disque et une clé bdd
51
+     *
52
+     * @return string
53
+     */
54
+    public function getSecretSite(bool $autoInit = true): ?string {
55
+        $key = $this->getKey('secret_du_site', $autoInit);
56
+        $meta = $this->getMetaKey('secret_du_site', $autoInit);
57
+        // conserve la même longeur.
58
+        return $key ^ $meta;
59
+    }
60
+
61
+    /** Renvoyer le secret des authentifications */
62
+    public function getSecretAuth(bool $autoInit = false): ?string {
63
+        return $this->getKey('secret_des_auth', $autoInit);
64
+    }
65
+    public function save(): bool {
66
+        return ecrire_fichier_securise($this->file, $this->cles->toJson());
67
+    }
68
+
69
+    /**
70
+     * Fournir une sauvegarde chiffree des cles (a l'aide d'une autre clé, comme le pass d'un auteur)
71
+     *
72
+     * @param string $withKey Clé de chiffrage de la sauvegarde
73
+     * @return string Contenu de la sauvegarde chiffrée générée
74
+     */
75
+    public function backup(
76
+        #[\SensitiveParameter]
77
+        string $withKey
78
+    ): string {
79
+        if (count($this->cles)) {
80
+            return Chiffrement::chiffrer($this->cles->toJson(), $withKey);
81
+        }
82
+        return '';
83
+    }
84
+
85
+    /**
86
+     * Restaurer les cles manquantes depuis une sauvegarde chiffree des cles
87
+     * (si la sauvegarde est bien valide)
88
+     *
89
+     * @param string $backup Sauvegarde chiffrée (générée par backup())
90
+     * @param int $id_auteur
91
+     * @param string $pass
92
+     * @return void
93
+     */
94
+    public function restore(
95
+        string $backup,
96
+        #[\SensitiveParameter]
97
+        string $password_clair,
98
+        #[\SensitiveParameter]
99
+        string $password_hash,
100
+        int $id_auteur
101
+    ): bool {
102
+        if (empty($backup)) {
103
+            return false;
104
+        }
105
+
106
+        $sauvegarde = Chiffrement::dechiffrer($backup, $password_clair);
107
+        $json = json_decode($sauvegarde, true);
108
+        if (!$json) {
109
+            return false;
110
+        }
111
+
112
+        // cela semble une sauvegarde valide
113
+        $cles_potentielles = array_map('base64_decode', $json);
114
+
115
+        // il faut faire une double verif sur secret_des_auth
116
+        // pour s'assurer qu'elle permet bien de decrypter le pass de l'auteur qui fournit la sauvegarde
117
+        // et par extension tous les passwords
118
+        if (!empty($cles_potentielles['secret_des_auth'])) {
119
+            if (!Password::verifier($password_clair, $password_hash, $cles_potentielles['secret_des_auth'])) {
120
+                spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer' . _LOG_INFO_IMPORTANTE);
121
+                unset($cles_potentielles['secret_des_auth']);
122
+            }
123
+        }
124
+
125
+        // on merge les cles pour recuperer les cles manquantes
126
+        $restauration = false;
127
+        foreach ($cles_potentielles as $name => $key) {
128
+            if (!$this->cles->has($name)) {
129
+                $this->cles->set($name, $key);
130
+                spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer' . _LOG_INFO_IMPORTANTE);
131
+                $restauration = true;
132
+            }
133
+        }
134
+        return $restauration;
135
+    }
136
+
137
+    private function getKey(string $name, bool $autoInit): ?string {
138
+        if ($this->cles->has($name)) {
139
+            return $this->cles->get($name);
140
+        }
141
+        if ($autoInit) {
142
+            $this->cles->generate($name);
143
+            // si l'ecriture de fichier a bien marche on peut utiliser la cle
144
+            if ($this->save()) {
145
+                return $this->cles->get($name);
146
+            }
147
+            // sinon loger et annule la cle generee car il ne faut pas l'utiliser
148
+            spip_log('Echec ecriture du fichier cle ' . $this->file . " ; impossible de generer une cle $name", 'chiffrer' . _LOG_ERREUR);
149
+            $this->cles->delete($name);
150
+        }
151
+        return null;
152
+    }
153
+
154
+    private function getMetaKey(string $name, bool $autoInit = true): ?string {
155
+        if (!isset($GLOBALS['meta'][$name])) {
156
+            include_spip('base/abstract_sql');
157
+            $GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = ' . sql_quote($name, '', 'string'));
158
+        }
159
+        $key = base64_decode($GLOBALS['meta'][$name] ?? '');
160
+        if (strlen($key) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
161
+            return $key;
162
+        }
163
+        if (!$autoInit) {
164
+            return null;
165
+        }
166
+        $key = Chiffrement::keygen();
167
+        ecrire_meta($name, base64_encode($key), 'non');
168
+        lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas
169
+
170
+        return $key;
171
+    }
172
+
173
+    private function read(): array {
174
+        lire_fichier_securise($this->file, $json);
175
+        if (
176
+            $json
177
+            and $json = \json_decode($json, true)
178
+            and is_array($json)
179
+        ) {
180
+            return array_map('base64_decode', $json);
181
+        }
182
+        return [];
183
+    }
184 184
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 final class SpipCles {
17 17
 	private static array $instances = [];
18 18
 
19
-	private string $file = _DIR_ETC . 'cles.php';
19
+	private string $file = _DIR_ETC.'cles.php';
20 20
 	private Cles $cles;
21 21
 
22 22
 	public static function instance(string $file = ''): self {
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 		// et par extension tous les passwords
118 118
 		if (!empty($cles_potentielles['secret_des_auth'])) {
119 119
 			if (!Password::verifier($password_clair, $password_hash, $cles_potentielles['secret_des_auth'])) {
120
-				spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer' . _LOG_INFO_IMPORTANTE);
120
+				spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer'._LOG_INFO_IMPORTANTE);
121 121
 				unset($cles_potentielles['secret_des_auth']);
122 122
 			}
123 123
 		}
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 		foreach ($cles_potentielles as $name => $key) {
128 128
 			if (!$this->cles->has($name)) {
129 129
 				$this->cles->set($name, $key);
130
-				spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer' . _LOG_INFO_IMPORTANTE);
130
+				spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer'._LOG_INFO_IMPORTANTE);
131 131
 				$restauration = true;
132 132
 			}
133 133
 		}
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 				return $this->cles->get($name);
146 146
 			}
147 147
 			// sinon loger et annule la cle generee car il ne faut pas l'utiliser
148
-			spip_log('Echec ecriture du fichier cle ' . $this->file . " ; impossible de generer une cle $name", 'chiffrer' . _LOG_ERREUR);
148
+			spip_log('Echec ecriture du fichier cle '.$this->file." ; impossible de generer une cle $name", 'chiffrer'._LOG_ERREUR);
149 149
 			$this->cles->delete($name);
150 150
 		}
151 151
 		return null;
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	private function getMetaKey(string $name, bool $autoInit = true): ?string {
155 155
 		if (!isset($GLOBALS['meta'][$name])) {
156 156
 			include_spip('base/abstract_sql');
157
-			$GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = ' . sql_quote($name, '', 'string'));
157
+			$GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = '.sql_quote($name, '', 'string'));
158 158
 		}
159 159
 		$key = base64_decode($GLOBALS['meta'][$name] ?? '');
160 160
 		if (strlen($key) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
Please login to merge, or discard this patch.
ecrire/inc/modifier.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 
114 114
 	// Appels incomplets (sans $c)
115 115
 	if (!is_array($c)) {
116
-		spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c');
116
+		spip_log('erreur appel objet_modifier_champs('.$objet.'), manque $c');
117 117
 
118 118
 		return _T('erreur_technique_enregistrement_impossible');
119 119
 	}
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 	// N'accepter que les champs qui existent dans la table
141 141
 	$champs = array_intersect_key($c, $desc['field']);
142 142
 	// et dont la valeur n'est pas null
143
-	$champs = array_filter($champs, static function ($var) {
143
+	$champs = array_filter($champs, static function($var) {
144 144
 		return $var !== null;
145 145
 	});
146 146
 	// TODO: ici aussi on peut valider les contenus
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	$champs = array_map('corriger_caracteres', $champs);
151 151
 
152 152
 	// On récupère l'état avant toute modification
153
-	$row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet);
153
+	$row = sql_fetsel('*', $spip_table_objet, $id_table_objet.'='.$id_objet);
154 154
 
155 155
 	// Envoyer aux plugins
156 156
 	$champs = pipeline(
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 				$id_rubrique = 0;
206 206
 				if (isset($desc['field']['id_rubrique'])) {
207 207
 					$parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique';
208
-					$id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet));
208
+					$id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=".intval($id_objet));
209 209
 				}
210 210
 				$instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action');
211 211
 				$champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur);
@@ -227,13 +227,13 @@  discard block
 block discarded – undo
227 227
 		}
228 228
 
229 229
 		// allez on commit la modif
230
-		sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur);
230
+		sql_updateq($spip_table_objet, $champs, "$id_table_objet=".intval($id_objet), [], $serveur);
231 231
 
232 232
 		// on verifie si elle est bien passee
233 233
 		$moof = sql_fetsel(
234 234
 			array_keys($champs),
235 235
 			$spip_table_objet,
236
-			"$id_table_objet=" . intval($id_objet),
236
+			"$id_table_objet=".intval($id_objet),
237 237
 			[],
238 238
 			[],
239 239
 			'',
@@ -269,13 +269,13 @@  discard block
 block discarded – undo
269 269
 			// c'est un cas exceptionnel
270 270
 			if (count($liste)) {
271 271
 				spip_log(
272
-					"Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true),
273
-					'modifier.' . _LOG_CRITIQUE
272
+					"Erreur enregistrement en base $objet/$id_objet champs :".var_export($conflits, true),
273
+					'modifier.'._LOG_CRITIQUE
274 274
 				);
275 275
 
276 276
 				return _T(
277 277
 					'erreur_technique_enregistrement_champs',
278
-					['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"]
278
+					['champs' => "<i>'".implode("'</i>,<i>'", $liste)."'</i>"]
279 279
 				);
280 280
 			}
281 281
 		}
@@ -317,18 +317,18 @@  discard block
 block discarded – undo
317 317
 	include_spip('inc/filtres_mini');
318 318
 	$qui = '';
319 319
 	if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
320
-		$qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#';
320
+		$qui .= ' #id_auteur:'.$GLOBALS['visiteur_session']['id_auteur'].'#';
321 321
 	}
322 322
 	if (!empty($GLOBALS['visiteur_session']['nom'])) {
323
-		$qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#';
323
+		$qui .= ' #nom:'.$GLOBALS['visiteur_session']['nom'].'#';
324 324
 	}
325 325
 	if ($qui == '') {
326
-		$qui = '#ip:' . $GLOBALS['ip'] . '#';
326
+		$qui = '#ip:'.$GLOBALS['ip'].'#';
327 327
 	}
328
-	journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join(
328
+	journal(_L($qui.' a édité '.$objet.' '.$id_objet.' ('.join(
329 329
 		'+',
330 330
 		array_diff(array_keys($champs), ['date_modif'])
331
-	) . ')'), [
331
+	).')'), [
332 332
 		'faire' => 'modifier',
333 333
 		'quoi' => $objet,
334 334
 		'id' => $id_objet
Please login to merge, or discard this patch.
Indentation   +280 added lines, -280 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -39,28 +39,28 @@  discard block
 block discarded – undo
39 39
  *     Tableau des champs et valeurs collectées
40 40
  */
41 41
 function collecter_requests($include_list, $exclude_list = [], $set = null, $tous = false) {
42
-	$c = $set;
43
-	if (!$c) {
44
-		$c = [];
45
-		foreach ($include_list as $champ) {
46
-			// on ne collecte que les champs reellement envoyes par defaut.
47
-			// le cas d'un envoi de valeur NULL peut du coup poser probleme.
48
-			$val = _request($champ);
49
-			if ($tous or $val !== null) {
50
-				$c[$champ] = $val;
51
-			}
52
-		}
53
-		// on ajoute toujours la lang en saisie possible
54
-		// meme si pas prevu au depart pour l'objet concerne
55
-		if ($l = _request('changer_lang')) {
56
-			$c['lang'] = $l;
57
-		}
58
-	}
59
-	foreach ($exclude_list as $champ) {
60
-		unset($c[$champ]);
61
-	}
62
-
63
-	return $c;
42
+    $c = $set;
43
+    if (!$c) {
44
+        $c = [];
45
+        foreach ($include_list as $champ) {
46
+            // on ne collecte que les champs reellement envoyes par defaut.
47
+            // le cas d'un envoi de valeur NULL peut du coup poser probleme.
48
+            $val = _request($champ);
49
+            if ($tous or $val !== null) {
50
+                $c[$champ] = $val;
51
+            }
52
+        }
53
+        // on ajoute toujours la lang en saisie possible
54
+        // meme si pas prevu au depart pour l'objet concerne
55
+        if ($l = _request('changer_lang')) {
56
+            $c['lang'] = $l;
57
+        }
58
+    }
59
+    foreach ($exclude_list as $champ) {
60
+        unset($c[$champ]);
61
+    }
62
+
63
+    return $c;
64 64
 }
65 65
 
66 66
 /**
@@ -97,262 +97,262 @@  discard block
 block discarded – undo
97 97
  *     - chaîne : texte d'un message d'erreur
98 98
  */
99 99
 function objet_modifier_champs($objet, $id_objet, $options, $c = null, $serveur = '') {
100
-	if (!$id_objet = intval($id_objet)) {
101
-		spip_log('Erreur $id_objet non defini', 'warn');
102
-
103
-		return _T('erreur_technique_enregistrement_impossible');
104
-	}
105
-
106
-	include_spip('inc/filtres');
107
-
108
-	$table_objet = table_objet($objet, $serveur);
109
-	$spip_table_objet = table_objet_sql($objet, $serveur);
110
-	$id_table_objet = id_table_objet($objet, $serveur);
111
-	$trouver_table = charger_fonction('trouver_table', 'base');
112
-	$desc = $trouver_table($spip_table_objet, $serveur);
113
-
114
-	// Appels incomplets (sans $c)
115
-	if (!is_array($c)) {
116
-		spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c');
117
-
118
-		return _T('erreur_technique_enregistrement_impossible');
119
-	}
120
-
121
-	// Securite : certaines variables ne sont jamais acceptees ici
122
-	// car elles ne relevent pas de autoriser(xxx, modifier) ;
123
-	// il faut passer par instituer_XX()
124
-	// TODO: faut-il passer ces variables interdites
125
-	// dans un fichier de description separe ?
126
-	unset($c['statut']);
127
-	unset($c['id_parent']);
128
-	unset($c['id_rubrique']);
129
-	unset($c['id_secteur']);
130
-
131
-	// Gerer les champs non vides
132
-	if (isset($options['nonvide']) and is_array($options['nonvide'])) {
133
-		foreach ($options['nonvide'] as $champ => $sinon) {
134
-			if (isset($c[$champ]) and $c[$champ] === '') {
135
-				$c[$champ] = $sinon;
136
-			}
137
-		}
138
-	}
139
-
140
-	// N'accepter que les champs qui existent dans la table
141
-	$champs = array_intersect_key($c, $desc['field']);
142
-	// et dont la valeur n'est pas null
143
-	$champs = array_filter($champs, static function ($var) {
144
-		return $var !== null;
145
-	});
146
-	// TODO: ici aussi on peut valider les contenus
147
-	// en fonction du type
148
-
149
-	// Nettoyer les valeurs
150
-	$champs = array_map('corriger_caracteres', $champs);
151
-
152
-	// On récupère l'état avant toute modification
153
-	$row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet);
154
-
155
-	// Envoyer aux plugins
156
-	$champs = pipeline(
157
-		'pre_edition',
158
-		[
159
-			'args' => [
160
-				'table' => $spip_table_objet, // compatibilite
161
-				'table_objet' => $table_objet,
162
-				'spip_table_objet' => $spip_table_objet,
163
-				'desc' => $desc,
164
-				'type' => $objet,
165
-				'id_objet' => $id_objet,
166
-				'data' => $options['data'] ?? null,
167
-				'champs' => $options['champs'] ?? [], // [doc] c'est quoi ?
168
-				'champs_anciens' => $row, // état du contenu avant modif
169
-				'serveur' => $serveur,
170
-				'action' => $options['action'] ?? 'modifier'
171
-			],
172
-			'data' => $champs
173
-		]
174
-	);
175
-
176
-	if (!$champs) {
177
-		return false;
178
-	}
179
-
180
-
181
-	// marquer le fait que l'objet est travaille par toto a telle date
182
-	include_spip('inc/config');
183
-	if (lire_config('articles_modif', 'non') !== 'non') {
184
-		include_spip('inc/drapeau_edition');
185
-		signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet);
186
-	}
187
-
188
-	// Verifier si les mises a jour sont pertinentes, datees, en conflit etc
189
-	include_spip('inc/editer');
190
-	if (!isset($options['data']) or is_null($options['data'])) {
191
-		$options['data'] = &$_POST;
192
-	}
193
-	$conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur);
194
-	// cas hypothetique : normalement inc/editer verifie en amont le conflit edition
195
-	// et gere l'interface
196
-	// ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme
197
-	if ($conflits) {
198
-		return _T('titre_conflit_edition');
199
-	}
200
-
201
-	if ($champs) {
202
-		// cas particulier de la langue : passer par instituer_langue_objet
203
-		if (isset($champs['lang'])) {
204
-			if ($changer_lang = $champs['lang']) {
205
-				$id_rubrique = 0;
206
-				if (isset($desc['field']['id_rubrique'])) {
207
-					$parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique';
208
-					$id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet));
209
-				}
210
-				$instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action');
211
-				$champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur);
212
-			}
213
-			// on laisse 'lang' dans $champs,
214
-			// ca permet de passer dans le pipeline post_edition et de journaliser
215
-			// et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir
216
-			// deja pris en compte
217
-		}
218
-
219
-		// la modif peut avoir lieu
220
-
221
-		// faut-il ajouter date_modif ?
222
-		if (
223
-			!empty($options['date_modif'])
224
-			and !isset($champs[$options['date_modif']])
225
-		) {
226
-			$champs[$options['date_modif']] = date('Y-m-d H:i:s');
227
-		}
228
-
229
-		// allez on commit la modif
230
-		sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur);
231
-
232
-		// on verifie si elle est bien passee
233
-		$moof = sql_fetsel(
234
-			array_keys($champs),
235
-			$spip_table_objet,
236
-			"$id_table_objet=" . intval($id_objet),
237
-			[],
238
-			[],
239
-			'',
240
-			[],
241
-			$serveur
242
-		);
243
-		// si difference entre les champs, reperer les champs mal enregistres
244
-		if ($moof != $champs) {
245
-			$liste = [];
246
-			foreach ($moof as $k => $v) {
247
-				if (
248
-					$v !== $champs[$k]
249
-					// ne pas alerter si le champ est numerique est que les valeurs sont equivalentes
250
-					and (!is_numeric($v) or intval($v) !== intval($champs[$k]))
251
-					// ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle
252
-					and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00']))
253
-				) {
254
-					$liste[] = $k;
255
-					$conflits[$k]['post'] = $champs[$k];
256
-					$conflits[$k]['save'] = $v;
257
-
258
-					// cas specifique MySQL+emoji : si l'un est la
259
-					// conversion utf8_noplanes de l'autre alors c'est OK
260
-					if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) {
261
-						include_spip('inc/charsets');
262
-						if ($v == utf8_noplanes($champs[$k])) {
263
-							array_pop($liste);
264
-						}
265
-					}
266
-				}
267
-			}
268
-			// si un champ n'a pas ete correctement enregistre, loger et retourner une erreur
269
-			// c'est un cas exceptionnel
270
-			if (count($liste)) {
271
-				spip_log(
272
-					"Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true),
273
-					'modifier.' . _LOG_CRITIQUE
274
-				);
275
-
276
-				return _T(
277
-					'erreur_technique_enregistrement_champs',
278
-					['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"]
279
-				);
280
-			}
281
-		}
282
-
283
-		// Invalider les caches
284
-		if (isset($options['invalideur']) and $options['invalideur']) {
285
-			include_spip('inc/invalideur');
286
-			if (is_array($options['invalideur'])) {
287
-				array_map('suivre_invalideur', $options['invalideur']);
288
-			} else {
289
-				suivre_invalideur($options['invalideur']);
290
-			}
291
-		}
292
-
293
-		// Notifications, gestion des revisions...
294
-		// en standard, appelle |nouvelle_revision ci-dessous
295
-		pipeline(
296
-			'post_edition',
297
-			[
298
-				'args' => [
299
-					'table' => $spip_table_objet,
300
-					'table_objet' => $table_objet,
301
-					'spip_table_objet' => $spip_table_objet,
302
-					'desc' => $desc,
303
-					'type' => $objet,
304
-					'id_objet' => $id_objet,
305
-					'champs' => $options['champs'] ?? [], // [doc] kesako ?
306
-					'champs_anciens' => $row, // état du contenu avant modif
307
-					'serveur' => $serveur,
308
-					'action' => $options['action'] ?? 'modifier'
309
-				],
310
-				'data' => $champs
311
-			]
312
-		);
313
-	}
100
+    if (!$id_objet = intval($id_objet)) {
101
+        spip_log('Erreur $id_objet non defini', 'warn');
102
+
103
+        return _T('erreur_technique_enregistrement_impossible');
104
+    }
105
+
106
+    include_spip('inc/filtres');
107
+
108
+    $table_objet = table_objet($objet, $serveur);
109
+    $spip_table_objet = table_objet_sql($objet, $serveur);
110
+    $id_table_objet = id_table_objet($objet, $serveur);
111
+    $trouver_table = charger_fonction('trouver_table', 'base');
112
+    $desc = $trouver_table($spip_table_objet, $serveur);
113
+
114
+    // Appels incomplets (sans $c)
115
+    if (!is_array($c)) {
116
+        spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c');
117
+
118
+        return _T('erreur_technique_enregistrement_impossible');
119
+    }
120
+
121
+    // Securite : certaines variables ne sont jamais acceptees ici
122
+    // car elles ne relevent pas de autoriser(xxx, modifier) ;
123
+    // il faut passer par instituer_XX()
124
+    // TODO: faut-il passer ces variables interdites
125
+    // dans un fichier de description separe ?
126
+    unset($c['statut']);
127
+    unset($c['id_parent']);
128
+    unset($c['id_rubrique']);
129
+    unset($c['id_secteur']);
130
+
131
+    // Gerer les champs non vides
132
+    if (isset($options['nonvide']) and is_array($options['nonvide'])) {
133
+        foreach ($options['nonvide'] as $champ => $sinon) {
134
+            if (isset($c[$champ]) and $c[$champ] === '') {
135
+                $c[$champ] = $sinon;
136
+            }
137
+        }
138
+    }
139
+
140
+    // N'accepter que les champs qui existent dans la table
141
+    $champs = array_intersect_key($c, $desc['field']);
142
+    // et dont la valeur n'est pas null
143
+    $champs = array_filter($champs, static function ($var) {
144
+        return $var !== null;
145
+    });
146
+    // TODO: ici aussi on peut valider les contenus
147
+    // en fonction du type
148
+
149
+    // Nettoyer les valeurs
150
+    $champs = array_map('corriger_caracteres', $champs);
151
+
152
+    // On récupère l'état avant toute modification
153
+    $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet);
154
+
155
+    // Envoyer aux plugins
156
+    $champs = pipeline(
157
+        'pre_edition',
158
+        [
159
+            'args' => [
160
+                'table' => $spip_table_objet, // compatibilite
161
+                'table_objet' => $table_objet,
162
+                'spip_table_objet' => $spip_table_objet,
163
+                'desc' => $desc,
164
+                'type' => $objet,
165
+                'id_objet' => $id_objet,
166
+                'data' => $options['data'] ?? null,
167
+                'champs' => $options['champs'] ?? [], // [doc] c'est quoi ?
168
+                'champs_anciens' => $row, // état du contenu avant modif
169
+                'serveur' => $serveur,
170
+                'action' => $options['action'] ?? 'modifier'
171
+            ],
172
+            'data' => $champs
173
+        ]
174
+    );
175
+
176
+    if (!$champs) {
177
+        return false;
178
+    }
179
+
180
+
181
+    // marquer le fait que l'objet est travaille par toto a telle date
182
+    include_spip('inc/config');
183
+    if (lire_config('articles_modif', 'non') !== 'non') {
184
+        include_spip('inc/drapeau_edition');
185
+        signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet);
186
+    }
187
+
188
+    // Verifier si les mises a jour sont pertinentes, datees, en conflit etc
189
+    include_spip('inc/editer');
190
+    if (!isset($options['data']) or is_null($options['data'])) {
191
+        $options['data'] = &$_POST;
192
+    }
193
+    $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur);
194
+    // cas hypothetique : normalement inc/editer verifie en amont le conflit edition
195
+    // et gere l'interface
196
+    // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme
197
+    if ($conflits) {
198
+        return _T('titre_conflit_edition');
199
+    }
200
+
201
+    if ($champs) {
202
+        // cas particulier de la langue : passer par instituer_langue_objet
203
+        if (isset($champs['lang'])) {
204
+            if ($changer_lang = $champs['lang']) {
205
+                $id_rubrique = 0;
206
+                if (isset($desc['field']['id_rubrique'])) {
207
+                    $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique';
208
+                    $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet));
209
+                }
210
+                $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action');
211
+                $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur);
212
+            }
213
+            // on laisse 'lang' dans $champs,
214
+            // ca permet de passer dans le pipeline post_edition et de journaliser
215
+            // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir
216
+            // deja pris en compte
217
+        }
218
+
219
+        // la modif peut avoir lieu
220
+
221
+        // faut-il ajouter date_modif ?
222
+        if (
223
+            !empty($options['date_modif'])
224
+            and !isset($champs[$options['date_modif']])
225
+        ) {
226
+            $champs[$options['date_modif']] = date('Y-m-d H:i:s');
227
+        }
228
+
229
+        // allez on commit la modif
230
+        sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur);
231
+
232
+        // on verifie si elle est bien passee
233
+        $moof = sql_fetsel(
234
+            array_keys($champs),
235
+            $spip_table_objet,
236
+            "$id_table_objet=" . intval($id_objet),
237
+            [],
238
+            [],
239
+            '',
240
+            [],
241
+            $serveur
242
+        );
243
+        // si difference entre les champs, reperer les champs mal enregistres
244
+        if ($moof != $champs) {
245
+            $liste = [];
246
+            foreach ($moof as $k => $v) {
247
+                if (
248
+                    $v !== $champs[$k]
249
+                    // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes
250
+                    and (!is_numeric($v) or intval($v) !== intval($champs[$k]))
251
+                    // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle
252
+                    and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00']))
253
+                ) {
254
+                    $liste[] = $k;
255
+                    $conflits[$k]['post'] = $champs[$k];
256
+                    $conflits[$k]['save'] = $v;
257
+
258
+                    // cas specifique MySQL+emoji : si l'un est la
259
+                    // conversion utf8_noplanes de l'autre alors c'est OK
260
+                    if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) {
261
+                        include_spip('inc/charsets');
262
+                        if ($v == utf8_noplanes($champs[$k])) {
263
+                            array_pop($liste);
264
+                        }
265
+                    }
266
+                }
267
+            }
268
+            // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur
269
+            // c'est un cas exceptionnel
270
+            if (count($liste)) {
271
+                spip_log(
272
+                    "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true),
273
+                    'modifier.' . _LOG_CRITIQUE
274
+                );
275
+
276
+                return _T(
277
+                    'erreur_technique_enregistrement_champs',
278
+                    ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"]
279
+                );
280
+            }
281
+        }
282
+
283
+        // Invalider les caches
284
+        if (isset($options['invalideur']) and $options['invalideur']) {
285
+            include_spip('inc/invalideur');
286
+            if (is_array($options['invalideur'])) {
287
+                array_map('suivre_invalideur', $options['invalideur']);
288
+            } else {
289
+                suivre_invalideur($options['invalideur']);
290
+            }
291
+        }
292
+
293
+        // Notifications, gestion des revisions...
294
+        // en standard, appelle |nouvelle_revision ci-dessous
295
+        pipeline(
296
+            'post_edition',
297
+            [
298
+                'args' => [
299
+                    'table' => $spip_table_objet,
300
+                    'table_objet' => $table_objet,
301
+                    'spip_table_objet' => $spip_table_objet,
302
+                    'desc' => $desc,
303
+                    'type' => $objet,
304
+                    'id_objet' => $id_objet,
305
+                    'champs' => $options['champs'] ?? [], // [doc] kesako ?
306
+                    'champs_anciens' => $row, // état du contenu avant modif
307
+                    'serveur' => $serveur,
308
+                    'action' => $options['action'] ?? 'modifier'
309
+                ],
310
+                'data' => $champs
311
+            ]
312
+        );
313
+    }
314 314
 	
315
-	// Appeler une notification
316
-	if ($notifications = charger_fonction('notifications', 'inc')) {
317
-		$notifications(
318
-			"{$objet}_modifier",
319
-			$id_objet,
320
-			[
321
-				'champs' => $champs,
322
-			]
323
-		);
324
-		$notifications(
325
-			'objet_modifier',
326
-			$id_objet,
327
-			[
328
-				'objet' => $objet,
329
-				'id_objet' => $id_objet,
330
-				'champs' => $champs,
331
-			]
332
-		);
333
-	}
334
-
335
-	// journaliser l'affaire
336
-	// message a affiner :-)
337
-	include_spip('inc/filtres_mini');
338
-	$qui = '';
339
-	if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
340
-		$qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#';
341
-	}
342
-	if (!empty($GLOBALS['visiteur_session']['nom'])) {
343
-		$qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#';
344
-	}
345
-	if ($qui == '') {
346
-		$qui = '#ip:' . $GLOBALS['ip'] . '#';
347
-	}
348
-	journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join(
349
-		'+',
350
-		array_diff(array_keys($champs), ['date_modif'])
351
-	) . ')'), [
352
-		'faire' => 'modifier',
353
-		'quoi' => $objet,
354
-		'id' => $id_objet
355
-	]);
356
-
357
-	return '';
315
+    // Appeler une notification
316
+    if ($notifications = charger_fonction('notifications', 'inc')) {
317
+        $notifications(
318
+            "{$objet}_modifier",
319
+            $id_objet,
320
+            [
321
+                'champs' => $champs,
322
+            ]
323
+        );
324
+        $notifications(
325
+            'objet_modifier',
326
+            $id_objet,
327
+            [
328
+                'objet' => $objet,
329
+                'id_objet' => $id_objet,
330
+                'champs' => $champs,
331
+            ]
332
+        );
333
+    }
334
+
335
+    // journaliser l'affaire
336
+    // message a affiner :-)
337
+    include_spip('inc/filtres_mini');
338
+    $qui = '';
339
+    if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
340
+        $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#';
341
+    }
342
+    if (!empty($GLOBALS['visiteur_session']['nom'])) {
343
+        $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#';
344
+    }
345
+    if ($qui == '') {
346
+        $qui = '#ip:' . $GLOBALS['ip'] . '#';
347
+    }
348
+    journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join(
349
+        '+',
350
+        array_diff(array_keys($champs), ['date_modif'])
351
+    ) . ')'), [
352
+        'faire' => 'modifier',
353
+        'quoi' => $objet,
354
+        'id' => $id_objet
355
+    ]);
356
+
357
+    return '';
358 358
 }
Please login to merge, or discard this patch.
ecrire/auth/spip.php 3 patches
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 		$row = sql_fetsel(
50 50
 			'*',
51 51
 			'spip_auteurs',
52
-			'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'",
52
+			'login='.sql_quote($login, $serveur, 'text')." AND statut<>'5poubelle'",
53 53
 			'',
54 54
 			'',
55 55
 			'',
@@ -77,20 +77,20 @@  discard block
 block discarded – undo
77 77
 		// legacy = md5 ou sha256
78 78
 		case 32:
79 79
 			// tres anciens mots de passe encodes en md5(alea.pass)
80
-			$hash = md5($row['alea_actuel'] . $pass);
80
+			$hash = md5($row['alea_actuel'].$pass);
81 81
 			$methode = 'md5';
82 82
 		case 64:
83 83
 			if (empty($hash)) {
84 84
 				// anciens mots de passe encodes en sha256(alea.pass)
85 85
 				include_spip('auth/sha256.inc');
86
-				$hash = spip_sha256($row['alea_actuel'] . $pass);
86
+				$hash = spip_sha256($row['alea_actuel'].$pass);
87 87
 				$methode = 'sha256';
88 88
 			}
89 89
 			if ($row['pass'] === $hash) {
90
-				spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode", 'auth' . _LOG_DEBUG);
90
+				spip_log("validation du mot de passe pour l'auteur #".$row['id_auteur']." $login via $methode", 'auth'._LOG_DEBUG);
91 91
 				// ce n'est pas cense arriver, mais si jamais c'est un backup inutilisable, il faut le nettoyer pour ne pas bloquer la creation d'une nouvelle cle d'auth
92 92
 				if (!empty($row['backup_cles'])) {
93
-					sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur']));
93
+					sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur='.intval($row['id_auteur']));
94 94
 				}
95 95
 				break;
96 96
 			}
@@ -108,19 +108,19 @@  discard block
 block discarded – undo
108 108
 				and !empty($row['backup_cles'])
109 109
 			) {
110 110
 				if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) {
111
-					spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE);
111
+					spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #'.$row['id_auteur'], 'auth'._LOG_INFO_IMPORTANTE);
112 112
 					if ($cles->save()) {
113 113
 						$secret = $cles->getSecretAuth();
114 114
 					}
115 115
 					else {
116
-						spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR);
116
+						spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth'._LOG_ERREUR);
117 117
 						// et on echoue car on ne veut pas que la situation reste telle quelle
118
-						raler_fichier(_DIR_ETC . 'cles.php');
118
+						raler_fichier(_DIR_ETC.'cles.php');
119 119
 					}
120 120
 				}
121 121
 				else {
122
-					spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR);
123
-					sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur']));
122
+					spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #'.$row['id_auteur']." n'est pas valide", 'auth'._LOG_ERREUR);
123
+					sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur='.intval($row['id_auteur']));
124 124
 				}
125 125
 			}
126 126
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 				unset($row);
129 129
 			}
130 130
 			else {
131
-				spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG);
131
+				spip_log("validation du mot de passe pour l'auteur #".$row['id_auteur']." $login via Password::verifier", 'auth'._LOG_DEBUG);
132 132
 			}
133 133
 			break;
134 134
 	}
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 			@sql_update(
176 176
 				'spip_auteurs',
177 177
 				$set,
178
-				'id_auteur=' . intval($row['id_auteur']) . ' AND pass=' . sql_quote(
178
+				'id_auteur='.intval($row['id_auteur']).' AND pass='.sql_quote(
179 179
 					$row['pass'],
180 180
 					$serveur,
181 181
 					'text'
@@ -223,24 +223,24 @@  discard block
 block discarded – undo
223 223
 
224 224
 	// si force, on ne verifie pas la presence d'un backup chez un webmestre
225 225
 	if ($force) {
226
-		spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE);
226
+		spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth'._LOG_INFO_IMPORTANTE);
227 227
 		$secret = $cles->getSecretAuth(true);
228 228
 		return true;
229 229
 	}
230 230
 
231
-	$has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''");
231
+	$has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut='.sql_quote('0minirezo').' AND webmestre='.sql_quote('oui')." AND backup_cles!=''");
232 232
 	$has_backup = array_column($has_backup, 'id_auteur');
233 233
 	if (empty($has_backup)) {
234
-		spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE);
234
+		spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth'._LOG_INFO_IMPORTANTE);
235 235
 		if ($secret = $cles->getSecretAuth(true)) {
236 236
 			return true;
237 237
 		}
238
-		spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR);
238
+		spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth'._LOG_ERREUR);
239 239
 		// et on echoue car on ne veut pas que la situation reste telle quelle
240
-		raler_fichier(_DIR_ETC . 'cles.php');
240
+		raler_fichier(_DIR_ETC.'cles.php');
241 241
 	}
242 242
 	else {
243
-		spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR);
243
+		spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #'.implode(', #', $has_backup).' doit se connecter pour restaurer son backup des cles', 'auth'._LOG_ERREUR);
244 244
 	}
245 245
 	return false;
246 246
 }
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
 	$flux['data'] .=
258 258
 		  '<script type="text/javascript">/*<![CDATA[*/'
259 259
 		. "$js\n"
260
-		. "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "',"
261
-		. "'page_auteur': '" . generer_url_public('informer_auteur') . "',"
260
+		. "var login_info={'login':'".$flux['args']['contexte']['var_login']."',"
261
+		. "'page_auteur': '".generer_url_public('informer_auteur')."',"
262 262
 		. "'informe_auteur_en_cours':false,"
263 263
 		. "'attente_informe':0};"
264 264
 		. "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});"
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 		} else {
302 302
 			$n = sql_countsel(
303 303
 				'spip_auteurs',
304
-				'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'",
304
+				'login='.sql_quote($new_login).' AND id_auteur!='.intval($id_auteur)." AND statut!='5poubelle'",
305 305
 				'',
306 306
 				'',
307 307
 				$serveur
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 	}
330 330
 	if (
331 331
 		!$id_auteur = intval($id_auteur)
332
-		or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur)
332
+		or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur='.intval($id_auteur), '', '', '', '', $serveur)
333 333
 	) {
334 334
 		return false;
335 335
 	}
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 		$anciens = sql_allfetsel(
345 345
 			'id_auteur',
346 346
 			'spip_auteurs',
347
-			'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'",
347
+			'login='.sql_quote($new_login, $serveur, 'text')." AND statut='5poubelle'",
348 348
 			'',
349 349
 			'',
350 350
 			'',
@@ -378,8 +378,8 @@  discard block
 block discarded – undo
378 378
 		$r = sql_getfetsel(
379 379
 			'login',
380 380
 			'spip_auteurs',
381
-			"statut<>'5poubelle'" .
382
-			' AND (length(pass)>0)' .
381
+			"statut<>'5poubelle'".
382
+			' AND (length(pass)>0)'.
383 383
 			" AND (login=$l)",
384 384
 			'',
385 385
 			'',
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
 		return sql_getfetsel(
399 399
 			'login',
400 400
 			'spip_auteurs',
401
-			"statut<>'5poubelle'" .
402
-			' AND (length(pass)>0)' .
401
+			"statut<>'5poubelle'".
402
+			' AND (length(pass)>0)'.
403 403
 			" AND (login<>'' AND (nom=$l OR email=$l))",
404 404
 			'',
405 405
 			'',
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
 
469 469
 	if (
470 470
 		!$id_auteur = intval($id_auteur)
471
-		or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur)
471
+		or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur='.intval($id_auteur), '', '', '', '', $serveur)
472 472
 	) {
473 473
 		return false;
474 474
 	}
@@ -529,8 +529,8 @@  discard block
 block discarded – undo
529 529
 		or isset($champs['statut'])
530 530
 		or (isset($options['all']) and $options['all'])
531 531
 	) {
532
-		$htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
533
-		$htpasswd = _DIR_TMP . _AUTH_USER_FILE;
532
+		$htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME;
533
+		$htpasswd = _DIR_TMP._AUTH_USER_FILE;
534 534
 
535 535
 		// Cette variable de configuration peut etre posee par un plugin
536 536
 		// par exemple acces_restreint ;
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
 			and !@file_exists($htaccess)
541 541
 		) {
542 542
 			spip_unlink($htpasswd);
543
-			spip_unlink($htpasswd . '-admin');
543
+			spip_unlink($htpasswd.'-admin');
544 544
 
545 545
 			return;
546 546
 		}
@@ -558,16 +558,16 @@  discard block
 block discarded – undo
558 558
 		);
559 559
 		while ($t = sql_fetch($s)) {
560 560
 			if (strlen($t['login']) and strlen($t['htpass'])) {
561
-				$p1 .= $t['login'] . ':' . $t['htpass'] . "\n";
561
+				$p1 .= $t['login'].':'.$t['htpass']."\n";
562 562
 				if ($t['statut'] == '0minirezo') {
563
-					$p2 .= $t['login'] . ':' . $t['htpass'] . "\n";
563
+					$p2 .= $t['login'].':'.$t['htpass']."\n";
564 564
 				}
565 565
 			}
566 566
 		}
567 567
 		sql_free($s);
568 568
 		if ($p1) {
569 569
 			ecrire_fichier($htpasswd, $p1);
570
-			ecrire_fichier($htpasswd . '-admin', $p2);
570
+			ecrire_fichier($htpasswd.'-admin', $p2);
571 571
 			spip_log("Ecriture de $htpasswd et $htpasswd-admin");
572 572
 		}
573 573
 	}
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -111,14 +111,12 @@  discard block
 block discarded – undo
111 111
 					spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE);
112 112
 					if ($cles->save()) {
113 113
 						$secret = $cles->getSecretAuth();
114
-					}
115
-					else {
114
+					} else {
116 115
 						spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR);
117 116
 						// et on echoue car on ne veut pas que la situation reste telle quelle
118 117
 						raler_fichier(_DIR_ETC . 'cles.php');
119 118
 					}
120
-				}
121
-				else {
119
+				} else {
122 120
 					spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR);
123 121
 					sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur']));
124 122
 				}
@@ -126,8 +124,7 @@  discard block
 block discarded – undo
126 124
 
127 125
 			if (!$secret or !Password::verifier($pass, $row['pass'], $secret)) {
128 126
 				unset($row);
129
-			}
130
-			else {
127
+			} else {
131 128
 				spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG);
132 129
 			}
133 130
 			break;
@@ -238,8 +235,7 @@  discard block
 block discarded – undo
238 235
 		spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR);
239 236
 		// et on echoue car on ne veut pas que la situation reste telle quelle
240 237
 		raler_fichier(_DIR_ETC . 'cles.php');
241
-	}
242
-	else {
238
+	} else {
243 239
 		spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR);
244 240
 	}
245 241
 	return false;
@@ -479,8 +475,7 @@  discard block
 block discarded – undo
479 475
 	if (!$secret) {
480 476
 		if (auth_spip_initialiser_secret()) {
481 477
 			$secret = $cles->getSecretAuth();
482
-		}
483
-		else {
478
+		} else {
484 479
 			return false;
485 480
 		}
486 481
 	}
Please login to merge, or discard this patch.
Indentation   +409 added lines, -409 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 use Spip\Chiffrer\SpipCles;
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 
24 24
 /**
@@ -33,169 +33,169 @@  discard block
 block discarded – undo
33 33
  */
34 34
 function auth_spip_dist($login, #[\SensitiveParameter] $pass, $serveur = '', $phpauth = false) {
35 35
 
36
-	// retrouver le login
37
-	$login = auth_spip_retrouver_login($login);
38
-	// login inconnu, n'allons pas plus loin
39
-	if (!$login) {
40
-		return [];
41
-	}
42
-
43
-	$md5pass = '';
44
-	$shapass = $shanext = '';
45
-	$auteur_peut_sauver_cles = false;
46
-
47
-	if ($pass) {
48
-		$row = sql_fetsel(
49
-			'*',
50
-			'spip_auteurs',
51
-			'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'",
52
-			'',
53
-			'',
54
-			'',
55
-			'',
56
-			$serveur
57
-		);
58
-
59
-		// lever un flag si cet auteur peut sauver les cles
60
-		if ($row['statut'] === '0minirezo' and $row['webmestre'] === 'oui' and isset($row['backup_cles'])) {
61
-			$auteur_peut_sauver_cles = true;
62
-		}
63
-	}
64
-
65
-	// login inexistant ou mot de passe vide
66
-	if (!$pass or !$row) {
67
-		return [];
68
-	}
69
-
70
-	$cles = SpipCles::instance();
71
-	$secret = $cles->getSecretAuth();
72
-
73
-	$hash = null;
74
-	switch (strlen($row['pass'])) {
75
-		// legacy = md5 ou sha256
76
-		case 32:
77
-			// tres anciens mots de passe encodes en md5(alea.pass)
78
-			$hash = md5($row['alea_actuel'] . $pass);
79
-			$methode = 'md5';
80
-		case 64:
81
-			if (empty($hash)) {
82
-				// anciens mots de passe encodes en sha256(alea.pass)
83
-				include_spip('auth/sha256.inc');
84
-				$hash = spip_sha256($row['alea_actuel'] . $pass);
85
-				$methode = 'sha256';
86
-			}
87
-			if ($row['pass'] === $hash) {
88
-				spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode", 'auth' . _LOG_DEBUG);
89
-				// ce n'est pas cense arriver, mais si jamais c'est un backup inutilisable, il faut le nettoyer pour ne pas bloquer la creation d'une nouvelle cle d'auth
90
-				if (!empty($row['backup_cles'])) {
91
-					sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur']));
92
-				}
93
-				break;
94
-			}
95
-
96
-		// on teste la methode par defaut, au cas ou ce serait un pass moderne qui a la malchance d'etre en 64char de long
97
-
98
-		case 60:
99
-		case 98:
100
-		default:
101
-			// doit-on restaurer un backup des cles ?
102
-			// si on a le bon pass on peut decoder le backup, retrouver la cle, et du coup valider le pass
103
-			if (
104
-				!$secret
105
-				and $auteur_peut_sauver_cles
106
-				and !empty($row['backup_cles'])
107
-			) {
108
-				if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) {
109
-					spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE);
110
-					if ($cles->save()) {
111
-						$secret = $cles->getSecretAuth();
112
-					}
113
-					else {
114
-						spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR);
115
-						// et on echoue car on ne veut pas que la situation reste telle quelle
116
-						raler_fichier(_DIR_ETC . 'cles.php');
117
-					}
118
-				}
119
-				else {
120
-					spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR);
121
-					sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur']));
122
-				}
123
-			}
124
-
125
-			if (!$secret or !Password::verifier($pass, $row['pass'], $secret)) {
126
-				unset($row);
127
-			}
128
-			else {
129
-				spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG);
130
-			}
131
-			break;
132
-	}
133
-
134
-	// Migration depuis ancienne version : si on a pas encore de cle
135
-	// ET si c'est le login d'un auteur qui peut sauver la cle
136
-	// créer la clé (en s'assurant bien que personne n'a de backup d'un precedent fichier cle.php)
137
-	// si c'est un auteur normal, on ne fait rien, il garde son ancien pass hashé en sha256 en attendant le login d'un webmestre
138
-	if (!$secret and $auteur_peut_sauver_cles) {
139
-		if (auth_spip_initialiser_secret()) {
140
-			$secret = $cles->getSecretAuth();
141
-		}
142
-	}
143
-
144
-	// login/mot de passe incorrect
145
-	if (empty($row)) {
146
-		return [];
147
-	}
148
-
149
-	// fait tourner le codage du pass dans la base
150
-	// sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action()
151
-	if (!$phpauth and $secret) {
152
-		include_spip('inc/acces'); // pour creer_uniqid et verifier_htaccess
153
-		$pass_hash_next = Password::hacher($pass, $secret);
154
-		if ($pass_hash_next) {
155
-			$set = [
156
-				'alea_actuel' => 'alea_futur', // @deprecated 4.1
157
-				'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text'), // @deprecated 4.1
158
-				'pass' => sql_quote($pass_hash_next, $serveur, 'text'),
159
-			];
160
-
161
-			// regenerer un htpass si on a active/desactive le plugin htpasswd
162
-			// et/ou que l'algo a change - pour etre certain de toujours utiliser le bon algo
163
-			$htpass = generer_htpass($pass);
164
-			if (strlen($htpass) !== strlen($row['htpass'])) {
165
-				$set['htpass'] = sql_quote($htpass, $serveur, 'text');
166
-			}
167
-
168
-			// a chaque login de webmestre : sauvegarde chiffree des clés du site (avec les pass du webmestre)
169
-			if ($auteur_peut_sauver_cles) {
170
-				$set['backup_cles'] = sql_quote($cles->backup($pass), $serveur, 'text');
171
-			}
172
-
173
-			@sql_update(
174
-				'spip_auteurs',
175
-				$set,
176
-				'id_auteur=' . intval($row['id_auteur']) . ' AND pass=' . sql_quote(
177
-					$row['pass'],
178
-					$serveur,
179
-					'text'
180
-				),
181
-				[],
182
-				$serveur
183
-			);
184
-
185
-			// si on a change le htpass car changement d'algo, regenerer les fichiers htpasswd
186
-			if (isset($set['htpass'])) {
187
-				ecrire_acces();
188
-			}
189
-		}
190
-
191
-		// En profiter pour verifier la securite de tmp/
192
-		// Si elle ne fonctionne pas a l'installation, prevenir
193
-		if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) {
194
-			return false;
195
-		}
196
-	}
197
-
198
-	return $row;
36
+    // retrouver le login
37
+    $login = auth_spip_retrouver_login($login);
38
+    // login inconnu, n'allons pas plus loin
39
+    if (!$login) {
40
+        return [];
41
+    }
42
+
43
+    $md5pass = '';
44
+    $shapass = $shanext = '';
45
+    $auteur_peut_sauver_cles = false;
46
+
47
+    if ($pass) {
48
+        $row = sql_fetsel(
49
+            '*',
50
+            'spip_auteurs',
51
+            'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'",
52
+            '',
53
+            '',
54
+            '',
55
+            '',
56
+            $serveur
57
+        );
58
+
59
+        // lever un flag si cet auteur peut sauver les cles
60
+        if ($row['statut'] === '0minirezo' and $row['webmestre'] === 'oui' and isset($row['backup_cles'])) {
61
+            $auteur_peut_sauver_cles = true;
62
+        }
63
+    }
64
+
65
+    // login inexistant ou mot de passe vide
66
+    if (!$pass or !$row) {
67
+        return [];
68
+    }
69
+
70
+    $cles = SpipCles::instance();
71
+    $secret = $cles->getSecretAuth();
72
+
73
+    $hash = null;
74
+    switch (strlen($row['pass'])) {
75
+        // legacy = md5 ou sha256
76
+        case 32:
77
+            // tres anciens mots de passe encodes en md5(alea.pass)
78
+            $hash = md5($row['alea_actuel'] . $pass);
79
+            $methode = 'md5';
80
+        case 64:
81
+            if (empty($hash)) {
82
+                // anciens mots de passe encodes en sha256(alea.pass)
83
+                include_spip('auth/sha256.inc');
84
+                $hash = spip_sha256($row['alea_actuel'] . $pass);
85
+                $methode = 'sha256';
86
+            }
87
+            if ($row['pass'] === $hash) {
88
+                spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode", 'auth' . _LOG_DEBUG);
89
+                // ce n'est pas cense arriver, mais si jamais c'est un backup inutilisable, il faut le nettoyer pour ne pas bloquer la creation d'une nouvelle cle d'auth
90
+                if (!empty($row['backup_cles'])) {
91
+                    sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur']));
92
+                }
93
+                break;
94
+            }
95
+
96
+        // on teste la methode par defaut, au cas ou ce serait un pass moderne qui a la malchance d'etre en 64char de long
97
+
98
+        case 60:
99
+        case 98:
100
+        default:
101
+            // doit-on restaurer un backup des cles ?
102
+            // si on a le bon pass on peut decoder le backup, retrouver la cle, et du coup valider le pass
103
+            if (
104
+                !$secret
105
+                and $auteur_peut_sauver_cles
106
+                and !empty($row['backup_cles'])
107
+            ) {
108
+                if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) {
109
+                    spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE);
110
+                    if ($cles->save()) {
111
+                        $secret = $cles->getSecretAuth();
112
+                    }
113
+                    else {
114
+                        spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR);
115
+                        // et on echoue car on ne veut pas que la situation reste telle quelle
116
+                        raler_fichier(_DIR_ETC . 'cles.php');
117
+                    }
118
+                }
119
+                else {
120
+                    spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR);
121
+                    sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur']));
122
+                }
123
+            }
124
+
125
+            if (!$secret or !Password::verifier($pass, $row['pass'], $secret)) {
126
+                unset($row);
127
+            }
128
+            else {
129
+                spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG);
130
+            }
131
+            break;
132
+    }
133
+
134
+    // Migration depuis ancienne version : si on a pas encore de cle
135
+    // ET si c'est le login d'un auteur qui peut sauver la cle
136
+    // créer la clé (en s'assurant bien que personne n'a de backup d'un precedent fichier cle.php)
137
+    // si c'est un auteur normal, on ne fait rien, il garde son ancien pass hashé en sha256 en attendant le login d'un webmestre
138
+    if (!$secret and $auteur_peut_sauver_cles) {
139
+        if (auth_spip_initialiser_secret()) {
140
+            $secret = $cles->getSecretAuth();
141
+        }
142
+    }
143
+
144
+    // login/mot de passe incorrect
145
+    if (empty($row)) {
146
+        return [];
147
+    }
148
+
149
+    // fait tourner le codage du pass dans la base
150
+    // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action()
151
+    if (!$phpauth and $secret) {
152
+        include_spip('inc/acces'); // pour creer_uniqid et verifier_htaccess
153
+        $pass_hash_next = Password::hacher($pass, $secret);
154
+        if ($pass_hash_next) {
155
+            $set = [
156
+                'alea_actuel' => 'alea_futur', // @deprecated 4.1
157
+                'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text'), // @deprecated 4.1
158
+                'pass' => sql_quote($pass_hash_next, $serveur, 'text'),
159
+            ];
160
+
161
+            // regenerer un htpass si on a active/desactive le plugin htpasswd
162
+            // et/ou que l'algo a change - pour etre certain de toujours utiliser le bon algo
163
+            $htpass = generer_htpass($pass);
164
+            if (strlen($htpass) !== strlen($row['htpass'])) {
165
+                $set['htpass'] = sql_quote($htpass, $serveur, 'text');
166
+            }
167
+
168
+            // a chaque login de webmestre : sauvegarde chiffree des clés du site (avec les pass du webmestre)
169
+            if ($auteur_peut_sauver_cles) {
170
+                $set['backup_cles'] = sql_quote($cles->backup($pass), $serveur, 'text');
171
+            }
172
+
173
+            @sql_update(
174
+                'spip_auteurs',
175
+                $set,
176
+                'id_auteur=' . intval($row['id_auteur']) . ' AND pass=' . sql_quote(
177
+                    $row['pass'],
178
+                    $serveur,
179
+                    'text'
180
+                ),
181
+                [],
182
+                $serveur
183
+            );
184
+
185
+            // si on a change le htpass car changement d'algo, regenerer les fichiers htpasswd
186
+            if (isset($set['htpass'])) {
187
+                ecrire_acces();
188
+            }
189
+        }
190
+
191
+        // En profiter pour verifier la securite de tmp/
192
+        // Si elle ne fonctionne pas a l'installation, prevenir
193
+        if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) {
194
+            return false;
195
+        }
196
+    }
197
+
198
+    return $row;
199 199
 }
200 200
 
201 201
 /**
@@ -210,36 +210,36 @@  discard block
 block discarded – undo
210 210
  * @return bool
211 211
  */
212 212
 function auth_spip_initialiser_secret(bool $force = false): bool {
213
-	$cles = SpipCles::instance();
214
-	$secret = $cles->getSecretAuth();
215
-
216
-	// on ne fait rien si on a un secret dispo
217
-	if ($secret) {
218
-		return false;
219
-	}
220
-
221
-	// si force, on ne verifie pas la presence d'un backup chez un webmestre
222
-	if ($force) {
223
-		spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE);
224
-		$secret = $cles->getSecretAuth(true);
225
-		return true;
226
-	}
227
-
228
-	$has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''");
229
-	$has_backup = array_column($has_backup, 'id_auteur');
230
-	if (empty($has_backup)) {
231
-		spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE);
232
-		if ($secret = $cles->getSecretAuth(true)) {
233
-			return true;
234
-		}
235
-		spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR);
236
-		// et on echoue car on ne veut pas que la situation reste telle quelle
237
-		raler_fichier(_DIR_ETC . 'cles.php');
238
-	}
239
-	else {
240
-		spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR);
241
-	}
242
-	return false;
213
+    $cles = SpipCles::instance();
214
+    $secret = $cles->getSecretAuth();
215
+
216
+    // on ne fait rien si on a un secret dispo
217
+    if ($secret) {
218
+        return false;
219
+    }
220
+
221
+    // si force, on ne verifie pas la presence d'un backup chez un webmestre
222
+    if ($force) {
223
+        spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE);
224
+        $secret = $cles->getSecretAuth(true);
225
+        return true;
226
+    }
227
+
228
+    $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''");
229
+    $has_backup = array_column($has_backup, 'id_auteur');
230
+    if (empty($has_backup)) {
231
+        spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE);
232
+        if ($secret = $cles->getSecretAuth(true)) {
233
+            return true;
234
+        }
235
+        spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR);
236
+        // et on echoue car on ne veut pas que la situation reste telle quelle
237
+        raler_fichier(_DIR_ETC . 'cles.php');
238
+    }
239
+    else {
240
+        spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR);
241
+    }
242
+    return false;
243 243
 }
244 244
 
245 245
 /**
@@ -249,19 +249,19 @@  discard block
 block discarded – undo
249 249
  * @return array
250 250
  */
251 251
 function auth_spip_formulaire_login($flux) {
252
-	// javascript qui gere la securite du login en evitant de faire circuler le pass en clair
253
-	$js = file_get_contents(find_in_path('prive/javascript/login.js'));
254
-	$flux['data'] .=
255
-		  '<script type="text/javascript">/*<![CDATA[*/'
256
-		. "$js\n"
257
-		. "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "',"
258
-		. "'page_auteur': '" . generer_url_public('informer_auteur') . "',"
259
-		. "'informe_auteur_en_cours':false,"
260
-		. "'attente_informe':0};"
261
-		. "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});"
262
-		. '/*]]>*/</script>';
263
-
264
-	return $flux;
252
+    // javascript qui gere la securite du login en evitant de faire circuler le pass en clair
253
+    $js = file_get_contents(find_in_path('prive/javascript/login.js'));
254
+    $flux['data'] .=
255
+            '<script type="text/javascript">/*<![CDATA[*/'
256
+        . "$js\n"
257
+        . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "',"
258
+        . "'page_auteur': '" . generer_url_public('informer_auteur') . "',"
259
+        . "'informe_auteur_en_cours':false,"
260
+        . "'attente_informe':0};"
261
+        . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});"
262
+        . '/*]]>*/</script>';
263
+
264
+    return $flux;
265 265
 }
266 266
 
267 267
 
@@ -273,11 +273,11 @@  discard block
 block discarded – undo
273 273
  *   toujours true pour un auteur cree dans SPIP
274 274
  */
275 275
 function auth_spip_autoriser_modifier_login(string $serveur = ''): bool {
276
-	// les fonctions d'ecriture sur base distante sont encore incompletes
277
-	if (strlen($serveur)) {
278
-		return false;
279
-	}
280
-	return true;
276
+    // les fonctions d'ecriture sur base distante sont encore incompletes
277
+    if (strlen($serveur)) {
278
+        return false;
279
+    }
280
+    return true;
281 281
 }
282 282
 
283 283
 /**
@@ -291,25 +291,25 @@  discard block
 block discarded – undo
291 291
  *  message d'erreur si login non valide, chaine vide sinon
292 292
  */
293 293
 function auth_spip_verifier_login($new_login, $id_auteur = 0, $serveur = '') {
294
-	// login et mot de passe
295
-	if (strlen($new_login)) {
296
-		if (strlen($new_login) < _LOGIN_TROP_COURT) {
297
-			return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]);
298
-		} else {
299
-			$n = sql_countsel(
300
-				'spip_auteurs',
301
-				'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'",
302
-				'',
303
-				'',
304
-				$serveur
305
-			);
306
-			if ($n) {
307
-				return _T('info_login_existant');
308
-			}
309
-		}
310
-	}
311
-
312
-	return '';
294
+    // login et mot de passe
295
+    if (strlen($new_login)) {
296
+        if (strlen($new_login) < _LOGIN_TROP_COURT) {
297
+            return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]);
298
+        } else {
299
+            $n = sql_countsel(
300
+                'spip_auteurs',
301
+                'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'",
302
+                '',
303
+                '',
304
+                $serveur
305
+            );
306
+            if ($n) {
307
+                return _T('info_login_existant');
308
+            }
309
+        }
310
+    }
311
+
312
+    return '';
313 313
 }
314 314
 
315 315
 /**
@@ -321,41 +321,41 @@  discard block
 block discarded – undo
321 321
  * @return bool
322 322
  */
323 323
 function auth_spip_modifier_login($new_login, $id_auteur, $serveur = '') {
324
-	if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') {
325
-		return false;
326
-	}
327
-	if (
328
-		!$id_auteur = intval($id_auteur)
329
-		or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur)
330
-	) {
331
-		return false;
332
-	}
333
-	if ($new_login == $auteur['login']) {
334
-		return true;
335
-	} // on a rien fait mais c'est bon !
336
-
337
-	include_spip('action/editer_auteur');
338
-
339
-	// vider le login des auteurs a la poubelle qui avaient ce meme login
340
-	if (strlen($new_login)) {
341
-		$anciens = sql_allfetsel(
342
-			'id_auteur',
343
-			'spip_auteurs',
344
-			'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'",
345
-			'',
346
-			'',
347
-			'',
348
-			'',
349
-			$serveur
350
-		);
351
-		while ($row = array_pop($anciens)) {
352
-			auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur
353
-		}
354
-	}
355
-
356
-	auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur
357
-
358
-	return true;
324
+    if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') {
325
+        return false;
326
+    }
327
+    if (
328
+        !$id_auteur = intval($id_auteur)
329
+        or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur)
330
+    ) {
331
+        return false;
332
+    }
333
+    if ($new_login == $auteur['login']) {
334
+        return true;
335
+    } // on a rien fait mais c'est bon !
336
+
337
+    include_spip('action/editer_auteur');
338
+
339
+    // vider le login des auteurs a la poubelle qui avaient ce meme login
340
+    if (strlen($new_login)) {
341
+        $anciens = sql_allfetsel(
342
+            'id_auteur',
343
+            'spip_auteurs',
344
+            'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'",
345
+            '',
346
+            '',
347
+            '',
348
+            '',
349
+            $serveur
350
+        );
351
+        while ($row = array_pop($anciens)) {
352
+            auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur
353
+        }
354
+    }
355
+
356
+    auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur
357
+
358
+    return true;
359 359
 }
360 360
 
361 361
 /**
@@ -367,44 +367,44 @@  discard block
 block discarded – undo
367 367
  * @return string
368 368
  */
369 369
 function auth_spip_retrouver_login($login, $serveur = '') {
370
-	if (!strlen($login)) {
371
-		return null;
372
-	} // pas la peine de requeter
373
-	$l = sql_quote($login, $serveur, 'text');
374
-	if (
375
-		$r = sql_getfetsel(
376
-			'login',
377
-			'spip_auteurs',
378
-			"statut<>'5poubelle'" .
379
-			' AND (length(pass)>0)' .
380
-			" AND (login=$l)",
381
-			'',
382
-			'',
383
-			'',
384
-			'',
385
-			$serveur
386
-		)
387
-	) {
388
-		return $r;
389
-	}
390
-	// Si pas d'auteur avec ce login
391
-	// regarder s'il a saisi son nom ou son mail.
392
-	// Ne pas fusionner avec la requete precedente
393
-	// car un nom peut etre homonyme d'un autre login
394
-	else {
395
-		return sql_getfetsel(
396
-			'login',
397
-			'spip_auteurs',
398
-			"statut<>'5poubelle'" .
399
-			' AND (length(pass)>0)' .
400
-			" AND (login<>'' AND (nom=$l OR email=$l))",
401
-			'',
402
-			'',
403
-			'',
404
-			'',
405
-			$serveur
406
-		);
407
-	}
370
+    if (!strlen($login)) {
371
+        return null;
372
+    } // pas la peine de requeter
373
+    $l = sql_quote($login, $serveur, 'text');
374
+    if (
375
+        $r = sql_getfetsel(
376
+            'login',
377
+            'spip_auteurs',
378
+            "statut<>'5poubelle'" .
379
+            ' AND (length(pass)>0)' .
380
+            " AND (login=$l)",
381
+            '',
382
+            '',
383
+            '',
384
+            '',
385
+            $serveur
386
+        )
387
+    ) {
388
+        return $r;
389
+    }
390
+    // Si pas d'auteur avec ce login
391
+    // regarder s'il a saisi son nom ou son mail.
392
+    // Ne pas fusionner avec la requete precedente
393
+    // car un nom peut etre homonyme d'un autre login
394
+    else {
395
+        return sql_getfetsel(
396
+            'login',
397
+            'spip_auteurs',
398
+            "statut<>'5poubelle'" .
399
+            ' AND (length(pass)>0)' .
400
+            " AND (login<>'' AND (nom=$l OR email=$l))",
401
+            '',
402
+            '',
403
+            '',
404
+            '',
405
+            $serveur
406
+        );
407
+    }
408 408
 }
409 409
 
410 410
 /**
@@ -415,11 +415,11 @@  discard block
 block discarded – undo
415 415
  *  toujours true pour un auteur cree dans SPIP
416 416
  */
417 417
 function auth_spip_autoriser_modifier_pass(string $serveur = ''): bool {
418
-	// les fonctions d'ecriture sur base distante sont encore incompletes
419
-	if (strlen($serveur)) {
420
-		return false;
421
-	}
422
-	return true;
418
+    // les fonctions d'ecriture sur base distante sont encore incompletes
419
+    if (strlen($serveur)) {
420
+        return false;
421
+    }
422
+    return true;
423 423
 }
424 424
 
425 425
 
@@ -440,12 +440,12 @@  discard block
 block discarded – undo
440 440
  *  message d'erreur si login non valide, chaine vide sinon
441 441
  */
442 442
 function auth_spip_verifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur = 0, $serveur = '') {
443
-	// login et mot de passe
444
-	if (strlen($new_pass) < _PASS_LONGUEUR_MINI) {
445
-		return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]);
446
-	}
443
+    // login et mot de passe
444
+    if (strlen($new_pass) < _PASS_LONGUEUR_MINI) {
445
+        return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]);
446
+    }
447 447
 
448
-	return '';
448
+    return '';
449 449
 }
450 450
 
451 451
 /**
@@ -459,47 +459,47 @@  discard block
 block discarded – undo
459 459
  * @return bool
460 460
  */
461 461
 function auth_spip_modifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur, $serveur = '') {
462
-	if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') {
463
-		return false;
464
-	}
465
-
466
-	if (
467
-		!$id_auteur = intval($id_auteur)
468
-		or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur)
469
-	) {
470
-		return false;
471
-	}
472
-
473
-	$cles = SpipCles::instance();
474
-	$secret = $cles->getSecretAuth();
475
-	if (!$secret) {
476
-		if (auth_spip_initialiser_secret()) {
477
-			$secret = $cles->getSecretAuth();
478
-		}
479
-		else {
480
-			return false;
481
-		}
482
-	}
483
-
484
-
485
-	include_spip('inc/acces');
486
-	$set = [
487
-		'pass' => Password::hacher($new_pass, $secret),
488
-		'htpass' => generer_htpass($new_pass),
489
-		'alea_actuel' => creer_uniqid(), // @deprecated 4.1
490
-		'alea_futur' => creer_uniqid(), // @deprecated 4.1
491
-		'low_sec' => '',
492
-	];
493
-
494
-	// si c'est un webmestre, on met a jour son backup des cles
495
-	if ($auteur['statut'] === '0minirezo' and $auteur['webmestre'] === 'oui') {
496
-		$set['backup_cles'] = $cles->backup($new_pass);
497
-	}
498
-
499
-	include_spip('action/editer_auteur');
500
-	auteur_modifier($id_auteur, $set, true); // manque la gestion de $serveur
501
-
502
-	return true; // on a bien modifie le pass
462
+    if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') {
463
+        return false;
464
+    }
465
+
466
+    if (
467
+        !$id_auteur = intval($id_auteur)
468
+        or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur)
469
+    ) {
470
+        return false;
471
+    }
472
+
473
+    $cles = SpipCles::instance();
474
+    $secret = $cles->getSecretAuth();
475
+    if (!$secret) {
476
+        if (auth_spip_initialiser_secret()) {
477
+            $secret = $cles->getSecretAuth();
478
+        }
479
+        else {
480
+            return false;
481
+        }
482
+    }
483
+
484
+
485
+    include_spip('inc/acces');
486
+    $set = [
487
+        'pass' => Password::hacher($new_pass, $secret),
488
+        'htpass' => generer_htpass($new_pass),
489
+        'alea_actuel' => creer_uniqid(), // @deprecated 4.1
490
+        'alea_futur' => creer_uniqid(), // @deprecated 4.1
491
+        'low_sec' => '',
492
+    ];
493
+
494
+    // si c'est un webmestre, on met a jour son backup des cles
495
+    if ($auteur['statut'] === '0minirezo' and $auteur['webmestre'] === 'oui') {
496
+        $set['backup_cles'] = $cles->backup($new_pass);
497
+    }
498
+
499
+    include_spip('action/editer_auteur');
500
+    auteur_modifier($id_auteur, $set, true); // manque la gestion de $serveur
501
+
502
+    return true; // on a bien modifie le pass
503 503
 }
504 504
 
505 505
 /**
@@ -513,58 +513,58 @@  discard block
 block discarded – undo
513 513
  * @return void
514 514
  */
515 515
 function auth_spip_synchroniser_distant($id_auteur, $champs, $options = [], string $serveur = ''): void {
516
-	// ne rien faire pour une base distante : on ne sait pas regenerer les htaccess
517
-	if (strlen($serveur)) {
518
-		return;
519
-	}
520
-	// si un login, pass ou statut a ete modifie
521
-	// regenerer les fichier htpass
522
-	if (
523
-		isset($champs['login'])
524
-		or isset($champs['pass'])
525
-		or isset($champs['statut'])
526
-		or (isset($options['all']) and $options['all'])
527
-	) {
528
-		$htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
529
-		$htpasswd = _DIR_TMP . _AUTH_USER_FILE;
530
-
531
-		// Cette variable de configuration peut etre posee par un plugin
532
-		// par exemple acces_restreint ;
533
-		// si .htaccess existe, outrepasser spip_meta
534
-		if (
535
-			(!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui'))
536
-			and !@file_exists($htaccess)
537
-		) {
538
-			spip_unlink($htpasswd);
539
-			spip_unlink($htpasswd . '-admin');
540
-
541
-			return;
542
-		}
543
-
544
-		# remarque : ici on laisse passer les "nouveau" de maniere a leur permettre
545
-		# de devenir redacteur le cas echeant (auth http)... a nettoyer
546
-		// attention, il faut au prealable se connecter a la base (necessaire car utilise par install)
547
-
548
-		$p1 = ''; // login:htpass pour tous
549
-		$p2 = ''; // login:htpass pour les admins
550
-		$s = sql_select(
551
-			'login, htpass, statut',
552
-			'spip_auteurs',
553
-			sql_in('statut', ['1comite', '0minirezo', 'nouveau'])
554
-		);
555
-		while ($t = sql_fetch($s)) {
556
-			if (strlen($t['login']) and strlen($t['htpass'])) {
557
-				$p1 .= $t['login'] . ':' . $t['htpass'] . "\n";
558
-				if ($t['statut'] == '0minirezo') {
559
-					$p2 .= $t['login'] . ':' . $t['htpass'] . "\n";
560
-				}
561
-			}
562
-		}
563
-		sql_free($s);
564
-		if ($p1) {
565
-			ecrire_fichier($htpasswd, $p1);
566
-			ecrire_fichier($htpasswd . '-admin', $p2);
567
-			spip_log("Ecriture de $htpasswd et $htpasswd-admin");
568
-		}
569
-	}
516
+    // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess
517
+    if (strlen($serveur)) {
518
+        return;
519
+    }
520
+    // si un login, pass ou statut a ete modifie
521
+    // regenerer les fichier htpass
522
+    if (
523
+        isset($champs['login'])
524
+        or isset($champs['pass'])
525
+        or isset($champs['statut'])
526
+        or (isset($options['all']) and $options['all'])
527
+    ) {
528
+        $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME;
529
+        $htpasswd = _DIR_TMP . _AUTH_USER_FILE;
530
+
531
+        // Cette variable de configuration peut etre posee par un plugin
532
+        // par exemple acces_restreint ;
533
+        // si .htaccess existe, outrepasser spip_meta
534
+        if (
535
+            (!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui'))
536
+            and !@file_exists($htaccess)
537
+        ) {
538
+            spip_unlink($htpasswd);
539
+            spip_unlink($htpasswd . '-admin');
540
+
541
+            return;
542
+        }
543
+
544
+        # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre
545
+        # de devenir redacteur le cas echeant (auth http)... a nettoyer
546
+        // attention, il faut au prealable se connecter a la base (necessaire car utilise par install)
547
+
548
+        $p1 = ''; // login:htpass pour tous
549
+        $p2 = ''; // login:htpass pour les admins
550
+        $s = sql_select(
551
+            'login, htpass, statut',
552
+            'spip_auteurs',
553
+            sql_in('statut', ['1comite', '0minirezo', 'nouveau'])
554
+        );
555
+        while ($t = sql_fetch($s)) {
556
+            if (strlen($t['login']) and strlen($t['htpass'])) {
557
+                $p1 .= $t['login'] . ':' . $t['htpass'] . "\n";
558
+                if ($t['statut'] == '0minirezo') {
559
+                    $p2 .= $t['login'] . ':' . $t['htpass'] . "\n";
560
+                }
561
+            }
562
+        }
563
+        sql_free($s);
564
+        if ($p1) {
565
+            ecrire_fichier($htpasswd, $p1);
566
+            ecrire_fichier($htpasswd . '-admin', $p2);
567
+            spip_log("Ecriture de $htpasswd et $htpasswd-admin");
568
+        }
569
+    }
570 570
 }
Please login to merge, or discard this patch.
ecrire/inc/informer.php 2 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -11,77 +11,77 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 # Les information d'une rubrique selectionnee dans le mini navigateur
18 18
 
19 19
 function inc_informer_dist($id, $col, $exclus, $rac, $type, $do = 'aff') {
20
-	include_spip('inc/texte');
21
-	$titre = $descriptif = '';
22
-	if ($type === 'rubrique') {
23
-		$row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id));
24
-		if ($row) {
25
-			$titre = typo($row['titre']);
26
-			$descriptif = propre($row['descriptif']);
27
-		} else {
28
-			$titre = _T('info_racine_site');
29
-		}
30
-	}
20
+    include_spip('inc/texte');
21
+    $titre = $descriptif = '';
22
+    if ($type === 'rubrique') {
23
+        $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id));
24
+        if ($row) {
25
+            $titre = typo($row['titre']);
26
+            $descriptif = propre($row['descriptif']);
27
+        } else {
28
+            $titre = _T('info_racine_site');
29
+        }
30
+    }
31 31
 
32
-	$res = '';
33
-	if (
34
-		$type === 'rubrique'
35
-		and intval($GLOBALS['visiteur_session']['prefs']['display'] ?? 0) !== 1
36
-		and isset($GLOBALS['meta']['image_process'])
37
-	) {
38
-		if ($GLOBALS['meta']['image_process'] !== 'non') {
39
-			$chercher_logo = charger_fonction('chercher_logo', 'inc');
40
-			if ($res = $chercher_logo($id, 'id_rubrique', 'on')) {
41
-				[$fid, $dir, $nom, $format] = $res;
42
-				include_spip('inc/filtres_images_mini');
43
-				$res = image_reduire("<img src='$fid' alt='' />", 100, 48);
44
-				if ($res) {
45
-					$res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>";
46
-				}
47
-			}
48
-		}
49
-	}
32
+    $res = '';
33
+    if (
34
+        $type === 'rubrique'
35
+        and intval($GLOBALS['visiteur_session']['prefs']['display'] ?? 0) !== 1
36
+        and isset($GLOBALS['meta']['image_process'])
37
+    ) {
38
+        if ($GLOBALS['meta']['image_process'] !== 'non') {
39
+            $chercher_logo = charger_fonction('chercher_logo', 'inc');
40
+            if ($res = $chercher_logo($id, 'id_rubrique', 'on')) {
41
+                [$fid, $dir, $nom, $format] = $res;
42
+                include_spip('inc/filtres_images_mini');
43
+                $res = image_reduire("<img src='$fid' alt='' />", 100, 48);
44
+                if ($res) {
45
+                    $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>";
46
+                }
47
+            }
48
+        }
49
+    }
50 50
 
51
-	$rac = spip_htmlentities($rac, ENT_QUOTES);
52
-	$do = spip_htmlentities($do, ENT_QUOTES);
53
-	$id = intval($id);
51
+    $rac = spip_htmlentities($rac, ENT_QUOTES);
52
+    $do = spip_htmlentities($do, ENT_QUOTES);
53
+    $id = intval($id);
54 54
 
55 55
 # ce lien provoque la selection (directe) de la rubrique cliquee
56 56
 # et l'affichage de son titre dans le bandeau
57
-	$titre = strtr(
58
-		str_replace(
59
-			"'",
60
-			'&#8217;',
61
-			str_replace('"', '&#34;', textebrut($titre))
62
-		),
63
-		"\n\r",
64
-		'  '
65
-	);
57
+    $titre = strtr(
58
+        str_replace(
59
+            "'",
60
+            '&#8217;',
61
+            str_replace('"', '&#34;', textebrut($titre))
62
+        ),
63
+        "\n\r",
64
+        '  '
65
+    );
66 66
 
67
-	$js_func = $do . '_selection_titre';
67
+    $js_func = $do . '_selection_titre';
68 68
 
69
-	return "<div style='display: none;'>"
70
-	. "<input type='text' id='" . $rac . "_sel' value='$id' />"
71
-	. "<input type='text' id='" . $rac . "_sel2' value=\""
72
-	. entites_html($titre)
73
-	. '" />'
74
-	. '</div>'
75
-	. "<div class='informer' style='padding: 5px; border-top: 0px;'>"
76
-	. '<div class="informer__item">'
77
-	. (!$res ? '' : $res)
78
-	. "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>'
79
-	. (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>')
80
-	. '</div>'
81
-	. "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>"
82
-	. "<input type='submit' class='fondo btn submit' value='"
83
-	. _T('bouton_choisir')
84
-	. "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />"
85
-	. '</div>'
86
-	. '</div>';
69
+    return "<div style='display: none;'>"
70
+    . "<input type='text' id='" . $rac . "_sel' value='$id' />"
71
+    . "<input type='text' id='" . $rac . "_sel2' value=\""
72
+    . entites_html($titre)
73
+    . '" />'
74
+    . '</div>'
75
+    . "<div class='informer' style='padding: 5px; border-top: 0px;'>"
76
+    . '<div class="informer__item">'
77
+    . (!$res ? '' : $res)
78
+    . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>'
79
+    . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>')
80
+    . '</div>'
81
+    . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>"
82
+    . "<input type='submit' class='fondo btn submit' value='"
83
+    . _T('bouton_choisir')
84
+    . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />"
85
+    . '</div>'
86
+    . '</div>';
87 87
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	include_spip('inc/texte');
21 21
 	$titre = $descriptif = '';
22 22
 	if ($type === 'rubrique') {
23
-		$row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id));
23
+		$row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = '.intval($id));
24 24
 		if ($row) {
25 25
 			$titre = typo($row['titre']);
26 26
 			$descriptif = propre($row['descriptif']);
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 				include_spip('inc/filtres_images_mini');
43 43
 				$res = image_reduire("<img src='$fid' alt='' />", 100, 48);
44 44
 				if ($res) {
45
-					$res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>";
45
+					$res = "<div class='informer__media' style='float: ".$GLOBALS['spip_lang_right'].'; margin-'.$GLOBALS['spip_lang_right'].": -5px; margin-top: -5px;'>$res</div>";
46 46
 				}
47 47
 			}
48 48
 		}
@@ -64,21 +64,21 @@  discard block
 block discarded – undo
64 64
 		'  '
65 65
 	);
66 66
 
67
-	$js_func = $do . '_selection_titre';
67
+	$js_func = $do.'_selection_titre';
68 68
 
69 69
 	return "<div style='display: none;'>"
70
-	. "<input type='text' id='" . $rac . "_sel' value='$id' />"
71
-	. "<input type='text' id='" . $rac . "_sel2' value=\""
70
+	. "<input type='text' id='".$rac."_sel' value='$id' />"
71
+	. "<input type='text' id='".$rac."_sel2' value=\""
72 72
 	. entites_html($titre)
73 73
 	. '" />'
74 74
 	. '</div>'
75 75
 	. "<div class='informer' style='padding: 5px; border-top: 0px;'>"
76 76
 	. '<div class="informer__item">'
77 77
 	. (!$res ? '' : $res)
78
-	. "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>'
79
-	. (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>')
78
+	. "<p class='informer__titre'><b>".safehtml($titre).'</b></p>'
79
+	. (!$descriptif ? '' : "<div class='informer__descriptif'>".safehtml($descriptif).'</div>')
80 80
 	. '</div>'
81
-	. "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>"
81
+	. "<div class='informer__action' style='clear:both; text-align: ".$GLOBALS['spip_lang_right'].";'>"
82 82
 	. "<input type='submit' class='fondo btn submit' value='"
83 83
 	. _T('bouton_choisir')
84 84
 	. "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />"
Please login to merge, or discard this patch.