Completed
Push — master ( cacd66...717daf )
by cam
02:37 queued 21s
created
prive/formulaires/login.php 1 patch
Indentation   +249 added lines, -249 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
 include_spip('base/abstract_sql');
@@ -31,11 +31,11 @@  discard block
 block discarded – undo
31 31
  *     true si espace privé, false sinon.
32 32
  **/
33 33
 function is_url_prive($cible) {
34
-	include_spip('inc/filtres_mini');
35
-	$path = parse_url(tester_url_absolue($cible) ? $cible : url_absolue($cible));
36
-	$path = ($path['path'] ?? '');
34
+    include_spip('inc/filtres_mini');
35
+    $path = parse_url(tester_url_absolue($cible) ? $cible : url_absolue($cible));
36
+    $path = ($path['path'] ?? '');
37 37
 
38
-	return strncmp(substr($path, -strlen(_DIR_RESTREINT_ABS)), _DIR_RESTREINT_ABS, strlen(_DIR_RESTREINT_ABS)) == 0;
38
+    return strncmp(substr($path, -strlen(_DIR_RESTREINT_ABS)), _DIR_RESTREINT_ABS, strlen(_DIR_RESTREINT_ABS)) == 0;
39 39
 }
40 40
 
41 41
 /**
@@ -60,111 +60,111 @@  discard block
 block discarded – undo
60 60
  *     Environnement du formulaire
61 61
  **/
62 62
 function formulaires_login_charger_dist($cible = '', $options = [], $deprecated = null) {
63
-	$erreur = _request('var_erreur');
64
-
65
-	if (!is_array($options)) {
66
-		$options = [
67
-			'login' => $options,
68
-			'prive' => $deprecated
69
-		];
70
-	}
71
-
72
-	$login = (empty($options['login']) ? '' : $options['login']);
73
-	$prive = (empty($options['prive']) ? null : $options['prive']);
74
-	// conserver le fonctionnement historique
75
-	if (!isset($options['autofocus'])) {
76
-		$options['autofocus'] = true;
77
-	}
78
-
79
-	if (!$login) {
80
-		$login = strval(_request('var_login'));
81
-	}
82
-	// si on est deja identifie
83
-	if (!$login and isset($GLOBALS['visiteur_session']['email'])) {
84
-		$login = $GLOBALS['visiteur_session']['email'];
85
-	}
86
-	if (!$login and isset($GLOBALS['visiteur_session']['login'])) {
87
-		$login = $GLOBALS['visiteur_session']['login'];
88
-	}
89
-	// ou si on a un cookie admin
90
-	if (!$login) {
91
-		if (
92
-			isset($_COOKIE['spip_admin'])
93
-			and preg_match(',^@(.*)$,', $_COOKIE['spip_admin'], $regs)
94
-		) {
95
-			$login = $regs[1];
96
-		}
97
-	}
98
-
99
-	$lang = $GLOBALS['spip_lang'];
100
-	include_spip('inc/auth');
101
-	$row = auth_informer_login($login);
102
-
103
-	// retablir la langue de l'URL si forcee (on ignore la langue de l'auteur dans ce cas)
104
-	if (_request('lang') === $lang and $GLOBALS['spip_lang'] !== $lang) {
105
-		changer_langue($lang);
106
-	}
107
-
108
-	// Construire l'environnement du squelette
109
-	// Ne pas proposer de "rester connecte quelques jours"
110
-	// si la duree de l'alea est inferieure a 12 h (valeur par defaut)
111
-
112
-	$valeurs = [
113
-		'var_login' => $login,
114
-		'editable' => !$row,
115
-		'cnx' => $row['cnx'] ?? '0',
116
-		'auth_http' => login_auth_http(),
117
-		'rester_connecte' => ((_RENOUVELLE_ALEA < 12 * 3600) ? '' : ' '),
118
-		'_logo' => $row['logo'] ?? '',
119
-		'_alea_actuel' => $row['alea_actuel'] ?? '',
120
-		'_alea_futur' => $row['alea_futur'] ?? '',
121
-		'_pipeline' => 'affiche_formulaire_login', // faire passer le formulaire dans un pipe dedie pour les methodes auth
122
-		'_autofocus' => ($options['autofocus'] and $options['autofocus'] !== 'non') ? ' ' : '',
123
-	];
124
-
125
-	if ($erreur or !isset($GLOBALS['visiteur_session']['id_auteur']) or !$GLOBALS['visiteur_session']['id_auteur']) {
126
-		$valeurs['editable'] = true;
127
-	}
128
-
129
-	if (is_null($prive) ? is_url_prive($cible) : $prive) {
130
-		include_spip('inc/autoriser');
131
-		$loge = autoriser('ecrire');
132
-	} else {
133
-		$loge = (isset($GLOBALS['visiteur_session']['auth']) and $GLOBALS['visiteur_session']['auth'] != '');
134
-	}
135
-
136
-	// Si on est connecte, appeler traiter()
137
-	// et lancer la redirection si besoin
138
-	if (!$valeurs['editable'] and $loge and _request('formulaire_action') !== 'login') {
139
-		$traiter = charger_fonction('traiter', 'formulaires/login');
140
-		$res = $traiter($cible, $login, $prive);
141
-		$valeurs = array_merge($valeurs, $res);
142
-
143
-		if (isset($res['redirect']) and $res['redirect']) {
144
-			include_spip('inc/headers');
145
-			# preparer un lien pour quand redirige_formulaire ne fonctionne pas
146
-			$m = redirige_formulaire($res['redirect']);
147
-			$valeurs['_deja_loge'] = inserer_attribut(
148
-				'<a>' . _T('login_par_ici') . "</a>$m",
149
-				'href',
150
-				$res['redirect']
151
-			);
152
-		}
153
-	}
154
-	// en cas d'echec de cookie, inc_auth a renvoye vers le script de
155
-	// pose de cookie ; s'il n'est pas la, c'est echec cookie
156
-	// s'il est la, c'est probablement un bookmark sur bonjour=oui,
157
-	// et pas un echec cookie.
158
-	if ($erreur == 'cookie') {
159
-		$valeurs['echec_cookie'] = ' ';
160
-	} elseif ($erreur) {
161
-		// une erreur d'un SSO indique dans la redirection vers ici
162
-		// mais il faut se proteger de toute tentative d'injection malveilante
163
-		include_spip('inc/filtres');
164
-		$valeurs['message_erreur'] = textebrut($erreur);
165
-	}
166
-
167
-	return $valeurs;
63
+    $erreur = _request('var_erreur');
64
+
65
+    if (!is_array($options)) {
66
+        $options = [
67
+            'login' => $options,
68
+            'prive' => $deprecated
69
+        ];
70
+    }
71
+
72
+    $login = (empty($options['login']) ? '' : $options['login']);
73
+    $prive = (empty($options['prive']) ? null : $options['prive']);
74
+    // conserver le fonctionnement historique
75
+    if (!isset($options['autofocus'])) {
76
+        $options['autofocus'] = true;
77
+    }
78
+
79
+    if (!$login) {
80
+        $login = strval(_request('var_login'));
81
+    }
82
+    // si on est deja identifie
83
+    if (!$login and isset($GLOBALS['visiteur_session']['email'])) {
84
+        $login = $GLOBALS['visiteur_session']['email'];
85
+    }
86
+    if (!$login and isset($GLOBALS['visiteur_session']['login'])) {
87
+        $login = $GLOBALS['visiteur_session']['login'];
88
+    }
89
+    // ou si on a un cookie admin
90
+    if (!$login) {
91
+        if (
92
+            isset($_COOKIE['spip_admin'])
93
+            and preg_match(',^@(.*)$,', $_COOKIE['spip_admin'], $regs)
94
+        ) {
95
+            $login = $regs[1];
96
+        }
97
+    }
98
+
99
+    $lang = $GLOBALS['spip_lang'];
100
+    include_spip('inc/auth');
101
+    $row = auth_informer_login($login);
102
+
103
+    // retablir la langue de l'URL si forcee (on ignore la langue de l'auteur dans ce cas)
104
+    if (_request('lang') === $lang and $GLOBALS['spip_lang'] !== $lang) {
105
+        changer_langue($lang);
106
+    }
107
+
108
+    // Construire l'environnement du squelette
109
+    // Ne pas proposer de "rester connecte quelques jours"
110
+    // si la duree de l'alea est inferieure a 12 h (valeur par defaut)
111
+
112
+    $valeurs = [
113
+        'var_login' => $login,
114
+        'editable' => !$row,
115
+        'cnx' => $row['cnx'] ?? '0',
116
+        'auth_http' => login_auth_http(),
117
+        'rester_connecte' => ((_RENOUVELLE_ALEA < 12 * 3600) ? '' : ' '),
118
+        '_logo' => $row['logo'] ?? '',
119
+        '_alea_actuel' => $row['alea_actuel'] ?? '',
120
+        '_alea_futur' => $row['alea_futur'] ?? '',
121
+        '_pipeline' => 'affiche_formulaire_login', // faire passer le formulaire dans un pipe dedie pour les methodes auth
122
+        '_autofocus' => ($options['autofocus'] and $options['autofocus'] !== 'non') ? ' ' : '',
123
+    ];
124
+
125
+    if ($erreur or !isset($GLOBALS['visiteur_session']['id_auteur']) or !$GLOBALS['visiteur_session']['id_auteur']) {
126
+        $valeurs['editable'] = true;
127
+    }
128
+
129
+    if (is_null($prive) ? is_url_prive($cible) : $prive) {
130
+        include_spip('inc/autoriser');
131
+        $loge = autoriser('ecrire');
132
+    } else {
133
+        $loge = (isset($GLOBALS['visiteur_session']['auth']) and $GLOBALS['visiteur_session']['auth'] != '');
134
+    }
135
+
136
+    // Si on est connecte, appeler traiter()
137
+    // et lancer la redirection si besoin
138
+    if (!$valeurs['editable'] and $loge and _request('formulaire_action') !== 'login') {
139
+        $traiter = charger_fonction('traiter', 'formulaires/login');
140
+        $res = $traiter($cible, $login, $prive);
141
+        $valeurs = array_merge($valeurs, $res);
142
+
143
+        if (isset($res['redirect']) and $res['redirect']) {
144
+            include_spip('inc/headers');
145
+            # preparer un lien pour quand redirige_formulaire ne fonctionne pas
146
+            $m = redirige_formulaire($res['redirect']);
147
+            $valeurs['_deja_loge'] = inserer_attribut(
148
+                '<a>' . _T('login_par_ici') . "</a>$m",
149
+                'href',
150
+                $res['redirect']
151
+            );
152
+        }
153
+    }
154
+    // en cas d'echec de cookie, inc_auth a renvoye vers le script de
155
+    // pose de cookie ; s'il n'est pas la, c'est echec cookie
156
+    // s'il est la, c'est probablement un bookmark sur bonjour=oui,
157
+    // et pas un echec cookie.
158
+    if ($erreur == 'cookie') {
159
+        $valeurs['echec_cookie'] = ' ';
160
+    } elseif ($erreur) {
161
+        // une erreur d'un SSO indique dans la redirection vers ici
162
+        // mais il faut se proteger de toute tentative d'injection malveilante
163
+        include_spip('inc/filtres');
164
+        $valeurs['message_erreur'] = textebrut($erreur);
165
+    }
166
+
167
+    return $valeurs;
168 168
 }
169 169
 
170 170
 
@@ -179,20 +179,20 @@  discard block
 block discarded – undo
179 179
  *     - chaîne vide sinon.
180 180
  **/
181 181
 function login_auth_http() {
182
-	if (
183
-		!$GLOBALS['ignore_auth_http']
184
-		and _request('var_erreur') == 'cookie'
185
-		and (!isset($_COOKIE['spip_session']) or $_COOKIE['spip_session'] != 'test_echec_cookie')
186
-		and (preg_match(',apache,', \PHP_SAPI)
187
-			or preg_match(',^Apache.* PHP,', $_SERVER['SERVER_SOFTWARE']))
188
-		// Attention dans le cas 'intranet' la proposition de se loger
189
-		// par auth_http peut conduire a l'echec.
190
-		and !(isset($_SERVER['PHP_AUTH_USER']) and isset($_SERVER['PHP_AUTH_PW']))
191
-	) {
192
-		return generer_url_action('cookie', '', false, true);
193
-	} else {
194
-		return '';
195
-	}
182
+    if (
183
+        !$GLOBALS['ignore_auth_http']
184
+        and _request('var_erreur') == 'cookie'
185
+        and (!isset($_COOKIE['spip_session']) or $_COOKIE['spip_session'] != 'test_echec_cookie')
186
+        and (preg_match(',apache,', \PHP_SAPI)
187
+            or preg_match(',^Apache.* PHP,', $_SERVER['SERVER_SOFTWARE']))
188
+        // Attention dans le cas 'intranet' la proposition de se loger
189
+        // par auth_http peut conduire a l'echec.
190
+        and !(isset($_SERVER['PHP_AUTH_USER']) and isset($_SERVER['PHP_AUTH_PW']))
191
+    ) {
192
+        return generer_url_action('cookie', '', false, true);
193
+    } else {
194
+        return '';
195
+    }
196 196
 }
197 197
 
198 198
 
@@ -218,65 +218,65 @@  discard block
 block discarded – undo
218 218
  **/
219 219
 function formulaires_login_verifier_dist($cible = '', $options = [], $deprecated = null) {
220 220
 
221
-	$erreurs = [];
222
-	if (!is_array($options)) {
223
-		$options = [
224
-			'login' => $options,
225
-			'prive' => $deprecated
226
-		];
227
-	}
228
-
229
-	$prive = (empty($options['prive']) ? null : $options['prive']);
230
-
231
-	$session_login = _request('var_login');
232
-	$session_password = _request('password');
233
-	$session_remember = _request('session_remember');
234
-
235
-	if (!$session_login) {
236
-		# pas de login saisi !
237
-		return ['var_login' => _T('info_obligatoire')];
238
-	}
239
-
240
-	// appeler auth_identifier_login qui va :
241
-	// - renvoyer un string si echec (message d'erreur)
242
-	// - un array decrivant l'auteur identifie si possible
243
-	// - rediriger vers un SSO qui renverra in fine sur action/auth qui finira l'authentification
244
-	include_spip('inc/auth');
245
-	$auteur = auth_identifier_login($session_login, $session_password);
246
-	// on arrive ici si on ne s'est pas identifie avec un SSO
247
-	if (!is_array($auteur)) {
248
-		$erreurs = [];
249
-		if (is_string($auteur) and strlen($auteur)) {
250
-			$erreurs['var_login'] = $auteur;
251
-		}
252
-		include_spip('inc/cookie');
253
-		spip_setcookie('spip_admin', '', time() - 3600);
254
-		if (strlen($session_password)) {
255
-			$erreurs['password'] = _T('login_erreur_pass');
256
-		} else {
257
-			// sinon c'est un login en deux passe old style (ou js en panne)
258
-			// pas de message d'erreur
259
-			$erreurs['password'] = ' ';
260
-			$erreurs['message_erreur'] = '';
261
-		}
262
-
263
-		return
264
-			$erreurs;
265
-	}
266
-	// on a ete authentifie, construire la session
267
-	// en gerant la duree demandee pour son cookie
268
-	if ($session_remember !== null) {
269
-		$auteur['cookie'] = $session_remember;
270
-	}
271
-	// si la connexion est refusee on renvoi un message erreur de mot de passe
272
-	// car en donnant plus de detail on renseignerait un assaillant sur l'existence d'un compte
273
-	if (auth_loger($auteur) === false) {
274
-		$erreurs['message_erreur'] = _T('login_erreur_pass');
275
-		return $erreurs;
276
-	}
277
-
278
-	return (is_null($prive) ? is_url_prive($cible) : $prive)
279
-		? login_autoriser() : [];
221
+    $erreurs = [];
222
+    if (!is_array($options)) {
223
+        $options = [
224
+            'login' => $options,
225
+            'prive' => $deprecated
226
+        ];
227
+    }
228
+
229
+    $prive = (empty($options['prive']) ? null : $options['prive']);
230
+
231
+    $session_login = _request('var_login');
232
+    $session_password = _request('password');
233
+    $session_remember = _request('session_remember');
234
+
235
+    if (!$session_login) {
236
+        # pas de login saisi !
237
+        return ['var_login' => _T('info_obligatoire')];
238
+    }
239
+
240
+    // appeler auth_identifier_login qui va :
241
+    // - renvoyer un string si echec (message d'erreur)
242
+    // - un array decrivant l'auteur identifie si possible
243
+    // - rediriger vers un SSO qui renverra in fine sur action/auth qui finira l'authentification
244
+    include_spip('inc/auth');
245
+    $auteur = auth_identifier_login($session_login, $session_password);
246
+    // on arrive ici si on ne s'est pas identifie avec un SSO
247
+    if (!is_array($auteur)) {
248
+        $erreurs = [];
249
+        if (is_string($auteur) and strlen($auteur)) {
250
+            $erreurs['var_login'] = $auteur;
251
+        }
252
+        include_spip('inc/cookie');
253
+        spip_setcookie('spip_admin', '', time() - 3600);
254
+        if (strlen($session_password)) {
255
+            $erreurs['password'] = _T('login_erreur_pass');
256
+        } else {
257
+            // sinon c'est un login en deux passe old style (ou js en panne)
258
+            // pas de message d'erreur
259
+            $erreurs['password'] = ' ';
260
+            $erreurs['message_erreur'] = '';
261
+        }
262
+
263
+        return
264
+            $erreurs;
265
+    }
266
+    // on a ete authentifie, construire la session
267
+    // en gerant la duree demandee pour son cookie
268
+    if ($session_remember !== null) {
269
+        $auteur['cookie'] = $session_remember;
270
+    }
271
+    // si la connexion est refusee on renvoi un message erreur de mot de passe
272
+    // car en donnant plus de detail on renseignerait un assaillant sur l'existence d'un compte
273
+    if (auth_loger($auteur) === false) {
274
+        $erreurs['message_erreur'] = _T('login_erreur_pass');
275
+        return $erreurs;
276
+    }
277
+
278
+    return (is_null($prive) ? is_url_prive($cible) : $prive)
279
+        ? login_autoriser() : [];
280 280
 }
281 281
 
282 282
 /**
@@ -291,21 +291,21 @@  discard block
 block discarded – undo
291 291
  *     - tableau vide sinon.
292 292
  **/
293 293
 function login_autoriser() {
294
-	include_spip('inc/autoriser');
295
-	if (!autoriser('ecrire')) {
296
-		$h = generer_url_action('logout', 'logout=prive&url=' . urlencode(self()));
297
-
298
-		return [
299
-			'message_erreur' => '<h1>'
300
-				. _T('avis_erreur_visiteur')
301
-				. '</h1><p>'
302
-				. _T('texte_erreur_visiteur')
303
-				. "</p><p class='retour'>[<a href='$h'>"
304
-				. _T('icone_deconnecter') . '</a>]</p>'
305
-		];
306
-	}
307
-
308
-	return [];
294
+    include_spip('inc/autoriser');
295
+    if (!autoriser('ecrire')) {
296
+        $h = generer_url_action('logout', 'logout=prive&url=' . urlencode(self()));
297
+
298
+        return [
299
+            'message_erreur' => '<h1>'
300
+                . _T('avis_erreur_visiteur')
301
+                . '</h1><p>'
302
+                . _T('texte_erreur_visiteur')
303
+                . "</p><p class='retour'>[<a href='$h'>"
304
+                . _T('icone_deconnecter') . '</a>]</p>'
305
+        ];
306
+    }
307
+
308
+    return [];
309 309
 }
310 310
 
311 311
 /**
@@ -326,55 +326,55 @@  discard block
 block discarded – undo
326 326
  *     Retours du traitement
327 327
  **/
328 328
 function formulaires_login_traiter_dist($cible = '', $options = [], $deprecated = null) {
329
-	$res = [];
330
-
331
-	if (!is_array($options)) {
332
-		$options = [
333
-			'login' => $options,
334
-			'prive' => $deprecated
335
-		];
336
-	}
337
-
338
-	$login = (empty($options['login']) ? '' : $options['login']);
339
-	$prive = (empty($options['prive']) ? null : $options['prive']);
340
-
341
-	// Si on se connecte dans l'espace prive,
342
-	// ajouter "bonjour" (repere a peu pres les cookies desactives)
343
-	if (is_null($prive) ? is_url_prive($cible) : $prive) {
344
-		$cible = parametre_url($cible, 'bonjour', 'oui', '&');
345
-	}
346
-	if ($cible == '@page_auteur') {
347
-		$cible = generer_objet_url($GLOBALS['auteur_session']['id_auteur'], 'auteur');
348
-	}
349
-
350
-	if ($cible) {
351
-		$cible = parametre_url($cible, 'var_login', '', '&');
352
-
353
-		// transformer la cible absolue en cible relative
354
-		// pour pas echouer quand la meta adresse_site est foireuse
355
-		if (strncmp($cible, $u = url_de_base(), strlen($u)) == 0) {
356
-			$cible = './' . substr($cible, strlen($u));
357
-		} elseif (tester_url_absolue($cible) and !defined('_AUTORISER_LOGIN_ABS_REDIRECT')) {
358
-			// si c'est une url absolue, refuser la redirection
359
-			// sauf si cette securite est levee volontairement par le webmestre
360
-			$cible = '';
361
-		}
362
-	}
363
-
364
-	// Si on est connecte, envoyer vers la destination
365
-	if ($cible and ($cible != self('&')) and ($cible != self())) {
366
-		$res['redirect'] = $cible;
367
-		$res['message_ok'] = inserer_attribut(
368
-			'<a>' . _T('login_par_ici') . '</a>',
369
-			'href',
370
-			$cible
371
-		);
372
-	}
373
-
374
-	// avant de rediriger il faut mettre a jour les sessions sur le disque si on a charge une session
375
-	if (function_exists('terminer_actualiser_sessions')) {
376
-		terminer_actualiser_sessions();
377
-	}
378
-
379
-	return $res;
329
+    $res = [];
330
+
331
+    if (!is_array($options)) {
332
+        $options = [
333
+            'login' => $options,
334
+            'prive' => $deprecated
335
+        ];
336
+    }
337
+
338
+    $login = (empty($options['login']) ? '' : $options['login']);
339
+    $prive = (empty($options['prive']) ? null : $options['prive']);
340
+
341
+    // Si on se connecte dans l'espace prive,
342
+    // ajouter "bonjour" (repere a peu pres les cookies desactives)
343
+    if (is_null($prive) ? is_url_prive($cible) : $prive) {
344
+        $cible = parametre_url($cible, 'bonjour', 'oui', '&');
345
+    }
346
+    if ($cible == '@page_auteur') {
347
+        $cible = generer_objet_url($GLOBALS['auteur_session']['id_auteur'], 'auteur');
348
+    }
349
+
350
+    if ($cible) {
351
+        $cible = parametre_url($cible, 'var_login', '', '&');
352
+
353
+        // transformer la cible absolue en cible relative
354
+        // pour pas echouer quand la meta adresse_site est foireuse
355
+        if (strncmp($cible, $u = url_de_base(), strlen($u)) == 0) {
356
+            $cible = './' . substr($cible, strlen($u));
357
+        } elseif (tester_url_absolue($cible) and !defined('_AUTORISER_LOGIN_ABS_REDIRECT')) {
358
+            // si c'est une url absolue, refuser la redirection
359
+            // sauf si cette securite est levee volontairement par le webmestre
360
+            $cible = '';
361
+        }
362
+    }
363
+
364
+    // Si on est connecte, envoyer vers la destination
365
+    if ($cible and ($cible != self('&')) and ($cible != self())) {
366
+        $res['redirect'] = $cible;
367
+        $res['message_ok'] = inserer_attribut(
368
+            '<a>' . _T('login_par_ici') . '</a>',
369
+            'href',
370
+            $cible
371
+        );
372
+    }
373
+
374
+    // avant de rediriger il faut mettre a jour les sessions sur le disque si on a charge une session
375
+    if (function_exists('terminer_actualiser_sessions')) {
376
+        terminer_actualiser_sessions();
377
+    }
378
+
379
+    return $res;
380 380
 }
Please login to merge, or discard this patch.
ecrire/install/etape_chmod.php 1 patch
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -11,11 +11,11 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 if (defined('_TEST_DIRS')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 define('_TEST_DIRS', '1');
21 21
 
@@ -26,42 +26,42 @@  discard block
 block discarded – undo
26 26
 // Tente d'ecrire
27 27
 //
28 28
 function test_ecrire($my_dir) {
29
-	static $chmod = 0;
30
-
31
-	$ok = false;
32
-	$script = @file_exists('spip_loader.php') ? 'spip_loader.php' : $_SERVER['PHP_SELF'];
33
-	$self = basename($script);
34
-	$uid = @fileowner('.');
35
-	$uid2 = @fileowner($self);
36
-	$gid = @filegroup('.');
37
-	$gid2 = @filegroup($self);
38
-	$perms = @fileperms($self);
39
-
40
-	// Comparer l'appartenance d'un fichier cree par PHP
41
-	// avec celle du script et du repertoire courant
42
-	if (!$chmod) {
43
-		@rmdir('test');
44
-		spip_unlink('test'); // effacer au cas ou
45
-		@touch('test');
46
-		if ($uid > 0 && $uid == $uid2 && @fileowner('test') == $uid) {
47
-			$chmod = 0700;
48
-		} else {
49
-			if ($gid > 0 && $gid == $gid2 && @filegroup('test') == $gid) {
50
-				$chmod = 0770;
51
-			} else {
52
-				$chmod = 0777;
53
-			}
54
-		}
55
-		// Appliquer de plus les droits d'acces du script
56
-		if ($perms > 0) {
57
-			$perms = ($perms & 0777) | (($perms & 0444) >> 2);
58
-			$chmod |= $perms;
59
-		}
60
-		spip_unlink('test');
61
-	}
62
-	$ok = is_dir($my_dir) && is_writable($my_dir);
63
-
64
-	return $ok ? $chmod : false;
29
+    static $chmod = 0;
30
+
31
+    $ok = false;
32
+    $script = @file_exists('spip_loader.php') ? 'spip_loader.php' : $_SERVER['PHP_SELF'];
33
+    $self = basename($script);
34
+    $uid = @fileowner('.');
35
+    $uid2 = @fileowner($self);
36
+    $gid = @filegroup('.');
37
+    $gid2 = @filegroup($self);
38
+    $perms = @fileperms($self);
39
+
40
+    // Comparer l'appartenance d'un fichier cree par PHP
41
+    // avec celle du script et du repertoire courant
42
+    if (!$chmod) {
43
+        @rmdir('test');
44
+        spip_unlink('test'); // effacer au cas ou
45
+        @touch('test');
46
+        if ($uid > 0 && $uid == $uid2 && @fileowner('test') == $uid) {
47
+            $chmod = 0700;
48
+        } else {
49
+            if ($gid > 0 && $gid == $gid2 && @filegroup('test') == $gid) {
50
+                $chmod = 0770;
51
+            } else {
52
+                $chmod = 0777;
53
+            }
54
+        }
55
+        // Appliquer de plus les droits d'acces du script
56
+        if ($perms > 0) {
57
+            $perms = ($perms & 0777) | (($perms & 0444) >> 2);
58
+            $chmod |= $perms;
59
+        }
60
+        spip_unlink('test');
61
+    }
62
+    $ok = is_dir($my_dir) && is_writable($my_dir);
63
+
64
+    return $ok ? $chmod : false;
65 65
 }
66 66
 
67 67
 //
@@ -71,84 +71,84 @@  discard block
 block discarded – undo
71 71
 
72 72
 function install_etape_chmod_dist() {
73 73
 
74
-	$continuer = null;
75
-	$test_dir = _request('test_dir');
76
-	$chmod = 0;
77
-
78
-	if ($test_dir and strpos($test_dir, '..') === false) {
79
-		if (substr($test_dir, -1) !== '/') {
80
-			$test_dir .= '/';
81
-		}
82
-		if (!in_array($test_dir, $GLOBALS['test_dirs'])) {
83
-			$GLOBALS['test_dirs'][] = _DIR_RACINE . $test_dir;
84
-		}
85
-	} else {
86
-		if (!_FILE_CONNECT) {
87
-			$GLOBALS['test_dirs'][] = _DIR_CONNECT;
88
-			$GLOBALS['test_dirs'][] = _DIR_CHMOD;
89
-		}
90
-	}
91
-
92
-	$bad_dirs = [];
93
-	$absent_dirs = [];
94
-
95
-	foreach ($GLOBALS['test_dirs'] as $i => $my_dir) {
96
-		$test = test_ecrire($my_dir);
97
-		if (!$test) {
98
-			$m = preg_replace(',^' . _DIR_RACINE . ',', '', $my_dir);
99
-			if (@file_exists($my_dir)) {
100
-				$bad_dirs['<li>' . $m . '</li>'] = 1;
101
-			} else {
102
-				$absent_dirs['<li>' . $m . '</li>'] = 1;
103
-			}
104
-		} else {
105
-			$chmod = max($chmod, $test);
106
-		}
107
-	}
108
-
109
-	if ($bad_dirs or $absent_dirs) {
110
-		if (!_FILE_CONNECT) {
111
-			$titre = _T('dirs_preliminaire');
112
-			$continuer = ' ' . _T('dirs_commencer') . '.';
113
-		} else {
114
-			$titre = _T('dirs_probleme_droits');
115
-		}
116
-
117
-
118
-		$res = "<div align='right'>" . menu_langues('var_lang_ecrire') . "</div>\n";
119
-
120
-		if ($bad_dirs) {
121
-			$res .=
122
-				_T(
123
-					'dirs_repertoires_suivants',
124
-					['bad_dirs' => join("\n", array_keys($bad_dirs))]
125
-				) .
126
-				'<b>' . _T('login_recharger') . '</b>.';
127
-		}
128
-
129
-		if ($absent_dirs) {
130
-			$res .=
131
-				_T(
132
-					'dirs_repertoires_absents',
133
-					['bad_dirs' => join("\n", array_keys($absent_dirs))]
134
-				) .
135
-				'<b>' . _T('login_recharger') . '</b>.';
136
-		}
137
-		$res = '<p>' . $continuer . $res . aider('install0', true) . '</p>';
138
-
139
-		$t = _T('login_recharger');
140
-		$t = (!$test_dir ? '' :
141
-				"<input type='hidden' name='test_dir' value='" . spip_htmlspecialchars($test_dir, ENT_QUOTES) . "' />")
142
-			. "<input type='hidden' name='etape' value='chmod' />"
143
-			. "<div style='text-align: right'><input type='submit' value='" . attribut_html($t) . "' /></div>";
144
-
145
-		echo minipres($titre, $res . generer_form_ecrire('install', $t));
146
-	} else {
147
-		$deja = (_FILE_CONNECT and analyse_fichier_connection(_FILE_CONNECT));
148
-		if (!$deja) {
149
-			redirige_url_ecrire('install', 'etape=1&chmod=' . $chmod);
150
-		} else {
151
-			redirige_url_ecrire();
152
-		}
153
-	}
74
+    $continuer = null;
75
+    $test_dir = _request('test_dir');
76
+    $chmod = 0;
77
+
78
+    if ($test_dir and strpos($test_dir, '..') === false) {
79
+        if (substr($test_dir, -1) !== '/') {
80
+            $test_dir .= '/';
81
+        }
82
+        if (!in_array($test_dir, $GLOBALS['test_dirs'])) {
83
+            $GLOBALS['test_dirs'][] = _DIR_RACINE . $test_dir;
84
+        }
85
+    } else {
86
+        if (!_FILE_CONNECT) {
87
+            $GLOBALS['test_dirs'][] = _DIR_CONNECT;
88
+            $GLOBALS['test_dirs'][] = _DIR_CHMOD;
89
+        }
90
+    }
91
+
92
+    $bad_dirs = [];
93
+    $absent_dirs = [];
94
+
95
+    foreach ($GLOBALS['test_dirs'] as $i => $my_dir) {
96
+        $test = test_ecrire($my_dir);
97
+        if (!$test) {
98
+            $m = preg_replace(',^' . _DIR_RACINE . ',', '', $my_dir);
99
+            if (@file_exists($my_dir)) {
100
+                $bad_dirs['<li>' . $m . '</li>'] = 1;
101
+            } else {
102
+                $absent_dirs['<li>' . $m . '</li>'] = 1;
103
+            }
104
+        } else {
105
+            $chmod = max($chmod, $test);
106
+        }
107
+    }
108
+
109
+    if ($bad_dirs or $absent_dirs) {
110
+        if (!_FILE_CONNECT) {
111
+            $titre = _T('dirs_preliminaire');
112
+            $continuer = ' ' . _T('dirs_commencer') . '.';
113
+        } else {
114
+            $titre = _T('dirs_probleme_droits');
115
+        }
116
+
117
+
118
+        $res = "<div align='right'>" . menu_langues('var_lang_ecrire') . "</div>\n";
119
+
120
+        if ($bad_dirs) {
121
+            $res .=
122
+                _T(
123
+                    'dirs_repertoires_suivants',
124
+                    ['bad_dirs' => join("\n", array_keys($bad_dirs))]
125
+                ) .
126
+                '<b>' . _T('login_recharger') . '</b>.';
127
+        }
128
+
129
+        if ($absent_dirs) {
130
+            $res .=
131
+                _T(
132
+                    'dirs_repertoires_absents',
133
+                    ['bad_dirs' => join("\n", array_keys($absent_dirs))]
134
+                ) .
135
+                '<b>' . _T('login_recharger') . '</b>.';
136
+        }
137
+        $res = '<p>' . $continuer . $res . aider('install0', true) . '</p>';
138
+
139
+        $t = _T('login_recharger');
140
+        $t = (!$test_dir ? '' :
141
+                "<input type='hidden' name='test_dir' value='" . spip_htmlspecialchars($test_dir, ENT_QUOTES) . "' />")
142
+            . "<input type='hidden' name='etape' value='chmod' />"
143
+            . "<div style='text-align: right'><input type='submit' value='" . attribut_html($t) . "' /></div>";
144
+
145
+        echo minipres($titre, $res . generer_form_ecrire('install', $t));
146
+    } else {
147
+        $deja = (_FILE_CONNECT and analyse_fichier_connection(_FILE_CONNECT));
148
+        if (!$deja) {
149
+            redirige_url_ecrire('install', 'etape=1&chmod=' . $chmod);
150
+        } else {
151
+            redirige_url_ecrire();
152
+        }
153
+    }
154 154
 }
Please login to merge, or discard this patch.
ecrire/inc/texte_mini.php 1 patch
Indentation   +389 added lines, -389 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
 include_spip('inc/filtres');
23 23
 include_spip('inc/lang');
@@ -39,21 +39,21 @@  discard block
 block discarded – undo
39 39
  **/
40 40
 function definir_puce() {
41 41
 
42
-	// Attention au sens, qui n'est pas defini de la meme facon dans
43
-	// l'espace prive (spip_lang est la langue de l'interface, lang_dir
44
-	// celle du texte) et public (spip_lang est la langue du texte)
45
-	$dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']);
42
+    // Attention au sens, qui n'est pas defini de la meme facon dans
43
+    // l'espace prive (spip_lang est la langue de l'interface, lang_dir
44
+    // celle du texte) et public (spip_lang est la langue du texte)
45
+    $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']);
46 46
 
47
-	$p = 'puce' . (test_espace_prive() ? '_prive' : '');
48
-	if ($dir == 'rtl') {
49
-		$p .= '_rtl';
50
-	}
47
+    $p = 'puce' . (test_espace_prive() ? '_prive' : '');
48
+    if ($dir == 'rtl') {
49
+        $p .= '_rtl';
50
+    }
51 51
 
52
-	if (!isset($GLOBALS[$p])) {
53
-		$GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>';
54
-	}
52
+    if (!isset($GLOBALS[$p])) {
53
+        $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>';
54
+    }
55 55
 
56
-	return $GLOBALS[$p];
56
+    return $GLOBALS[$p];
57 57
 }
58 58
 
59 59
 
@@ -61,14 +61,14 @@  discard block
 block discarded – undo
61 61
 // dont on souhaite qu'ils provoquent un saut de paragraphe
62 62
 
63 63
 if (!defined('_BALISES_BLOCS')) {
64
-	define(
65
-		'_BALISES_BLOCS',
66
-		'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style'
67
-	);
64
+    define(
65
+        '_BALISES_BLOCS',
66
+        'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style'
67
+    );
68 68
 }
69 69
 
70 70
 if (!defined('_BALISES_BLOCS_REGEXP')) {
71
-	define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS');
71
+    define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS');
72 72
 }
73 73
 
74 74
 //
@@ -79,106 +79,106 @@  discard block
 block discarded – undo
79 79
 // une $source differente ; le script detecte automagiquement si ce qu'on
80 80
 // echappe est un div ou un span
81 81
 function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) {
82
-	if (!strlen($rempl)) {
83
-		return '';
84
-	}
85
-
86
-	// Tester si on echappe en span ou en div
87
-	if (is_null($mode) or !in_array($mode, ['div', 'span'])) {
88
-		$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span';
89
-	}
90
-
91
-	// Decouper en morceaux, base64 a des probleme selon la taille de la pile
92
-	$taille = 30000;
93
-	$return = '';
94
-	for ($i = 0; $i < strlen($rempl); $i += $taille) {
95
-		// Convertir en base64 et cacher dans un attribut
96
-		// utiliser les " pour eviter le re-encodage de ' et &#8217
97
-		$base64 = base64_encode(substr($rempl, $i, $taille));
98
-		$return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>";
99
-	}
100
-
101
-	return $return;
82
+    if (!strlen($rempl)) {
83
+        return '';
84
+    }
85
+
86
+    // Tester si on echappe en span ou en div
87
+    if (is_null($mode) or !in_array($mode, ['div', 'span'])) {
88
+        $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span';
89
+    }
90
+
91
+    // Decouper en morceaux, base64 a des probleme selon la taille de la pile
92
+    $taille = 30000;
93
+    $return = '';
94
+    for ($i = 0; $i < strlen($rempl); $i += $taille) {
95
+        // Convertir en base64 et cacher dans un attribut
96
+        // utiliser les " pour eviter le re-encodage de ' et &#8217
97
+        $base64 = base64_encode(substr($rempl, $i, $taille));
98
+        $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>";
99
+    }
100
+
101
+    return $return;
102 102
 }
103 103
 
104 104
 
105 105
 // Echapper les <html>...</ html>
106 106
 function traiter_echap_html_dist($regs) {
107
-	return $regs[3];
107
+    return $regs[3];
108 108
 }
109 109
 
110 110
 // Echapper les <pre>...</ pre>
111 111
 function traiter_echap_pre_dist($regs) {
112
-	// echapper les <code> dans <pre>
113
-	$pre = $regs[3];
114
-
115
-	// echapper les < dans <code>
116
-	// on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code>
117
-	if (
118
-		strpos($pre, '<') !== false
119
-		and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER)
120
-	) {
121
-		foreach ($matches as $m) {
122
-			if ($m[1] === 'code') {
123
-				$code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>';
124
-				$pre = str_replace($m[0], $code, $pre);
125
-			}
126
-		}
127
-	}
128
-	return "<pre>$pre</pre>";
112
+    // echapper les <code> dans <pre>
113
+    $pre = $regs[3];
114
+
115
+    // echapper les < dans <code>
116
+    // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code>
117
+    if (
118
+        strpos($pre, '<') !== false
119
+        and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER)
120
+    ) {
121
+        foreach ($matches as $m) {
122
+            if ($m[1] === 'code') {
123
+                $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>';
124
+                $pre = str_replace($m[0], $code, $pre);
125
+            }
126
+        }
127
+    }
128
+    return "<pre>$pre</pre>";
129 129
 }
130 130
 
131 131
 // Echapper les <code>...</ code>
132 132
 function traiter_echap_code_dist($regs) {
133
-	[, , $att, $corps] = $regs;
134
-	$echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code !
135
-
136
-	// ne pas mettre le <div...> s'il n'y a qu'une ligne
137
-	if (is_int(strpos($echap, "\n"))) {
138
-		// supprimer les sauts de ligne debut/fin
139
-		// (mais pas les espaces => ascii art).
140
-		$echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $echap);
141
-		$echap = nl2br($echap);
142
-		$echap = "<div style='text-align: left;' "
143
-			. "class='spip_code' dir='ltr'><code$att>"
144
-			. $echap . '</code></div>';
145
-	} else {
146
-		$echap = "<code$att class='spip_code' dir='ltr'>" . $echap . '</code>';
147
-	}
148
-
149
-	$echap = str_replace("\t", '&nbsp; &nbsp; &nbsp; &nbsp; ', $echap);
150
-	$echap = str_replace('  ', ' &nbsp;', $echap);
151
-
152
-	return $echap;
133
+    [, , $att, $corps] = $regs;
134
+    $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code !
135
+
136
+    // ne pas mettre le <div...> s'il n'y a qu'une ligne
137
+    if (is_int(strpos($echap, "\n"))) {
138
+        // supprimer les sauts de ligne debut/fin
139
+        // (mais pas les espaces => ascii art).
140
+        $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $echap);
141
+        $echap = nl2br($echap);
142
+        $echap = "<div style='text-align: left;' "
143
+            . "class='spip_code' dir='ltr'><code$att>"
144
+            . $echap . '</code></div>';
145
+    } else {
146
+        $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . '</code>';
147
+    }
148
+
149
+    $echap = str_replace("\t", '&nbsp; &nbsp; &nbsp; &nbsp; ', $echap);
150
+    $echap = str_replace('  ', ' &nbsp;', $echap);
151
+
152
+    return $echap;
153 153
 }
154 154
 
155 155
 // Echapper les <cadre>...</ cadre> aka <frame>...</ frame>
156 156
 function traiter_echap_cadre_dist($regs) {
157
-	$echap = trim(entites_html($regs[3]));
158
-	// compter les lignes un peu plus finement qu'avec les \n
159
-	$lignes = explode("\n", trim($echap));
160
-	$n = 0;
161
-	foreach ($lignes as $l) {
162
-		$n += floor(strlen($l) / 60) + 1;
163
-	}
164
-	$n = max($n, 2);
165
-	$echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>";
166
-
167
-	return $echap;
157
+    $echap = trim(entites_html($regs[3]));
158
+    // compter les lignes un peu plus finement qu'avec les \n
159
+    $lignes = explode("\n", trim($echap));
160
+    $n = 0;
161
+    foreach ($lignes as $l) {
162
+        $n += floor(strlen($l) / 60) + 1;
163
+    }
164
+    $n = max($n, 2);
165
+    $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>";
166
+
167
+    return $echap;
168 168
 }
169 169
 
170 170
 function traiter_echap_frame_dist($regs) {
171
-	return traiter_echap_cadre_dist($regs);
171
+    return traiter_echap_cadre_dist($regs);
172 172
 }
173 173
 
174 174
 function traiter_echap_script_dist($regs) {
175
-	// rendre joli (et inactif) si c'est un script language=php
176
-	if (preg_match(',<script\b[^>]+php,ims', $regs[0])) {
177
-		return highlight_string($regs[0], true);
178
-	}
175
+    // rendre joli (et inactif) si c'est un script language=php
176
+    if (preg_match(',<script\b[^>]+php,ims', $regs[0])) {
177
+        return highlight_string($regs[0], true);
178
+    }
179 179
 
180
-	// Cas normal : le script passe tel quel
181
-	return $regs[0];
180
+    // Cas normal : le script passe tel quel
181
+    return $regs[0];
182 182
 }
183 183
 
184 184
 define('_PROTEGE_BLOCS', ',<(html|pre|code|cadre|frame|script|style)(\b[^>]*)?>(.*)</\1>,UimsS');
@@ -196,67 +196,67 @@  discard block
 block discarded – undo
196 196
  * @return string|string[]
197 197
  */
198 198
 function echappe_html(
199
-	$letexte,
200
-	$source = '',
201
-	$no_transform = false,
202
-	$preg = '',
203
-	$callback_prefix = ''
199
+    $letexte,
200
+    $source = '',
201
+    $no_transform = false,
202
+    $preg = '',
203
+    $callback_prefix = ''
204 204
 ) {
205
-	if (!is_string($letexte) or !strlen($letexte)) {
206
-		return $letexte;
207
-	}
208
-
209
-	if (
210
-		($preg or strpos($letexte, '<') !== false)
211
-		and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER)
212
-	) {
213
-		foreach ($matches as $regs) {
214
-			// echappements tels quels ?
215
-			if ($no_transform) {
216
-				$echap = $regs[0];
217
-			} // sinon les traiter selon le cas
218
-			else {
219
-				if (
220
-					function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1]))
221
-					or function_exists($f = $f . '_dist')
222
-				) {
223
-					$echap = $f($regs);
224
-				}
225
-			}
226
-
227
-			$p = strpos($letexte, (string) $regs[0]);
228
-			$letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0]));
229
-		}
230
-	}
231
-
232
-	if ($no_transform) {
233
-		return $letexte;
234
-	}
235
-
236
-	// Echapper le php pour faire joli (ici, c'est pas pour la securite)
237
-	// seulement si on a echappe les <script>
238
-	// (derogatoire car on ne peut pas faire passer < ? ... ? >
239
-	// dans une callback autonommee
240
-	if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) {
241
-		if (
242
-			strpos($letexte, '<' . '?') !== false and preg_match_all(
243
-				',<[?].*($|[?]>),UisS',
244
-				$letexte,
245
-				$matches,
246
-				PREG_SET_ORDER
247
-			)
248
-		) {
249
-			foreach ($matches as $regs) {
250
-				$letexte = str_replace(
251
-					$regs[0],
252
-					code_echappement(highlight_string($regs[0], true), $source),
253
-					$letexte
254
-				);
255
-			}
256
-		}
257
-	}
258
-
259
-	return $letexte;
205
+    if (!is_string($letexte) or !strlen($letexte)) {
206
+        return $letexte;
207
+    }
208
+
209
+    if (
210
+        ($preg or strpos($letexte, '<') !== false)
211
+        and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER)
212
+    ) {
213
+        foreach ($matches as $regs) {
214
+            // echappements tels quels ?
215
+            if ($no_transform) {
216
+                $echap = $regs[0];
217
+            } // sinon les traiter selon le cas
218
+            else {
219
+                if (
220
+                    function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1]))
221
+                    or function_exists($f = $f . '_dist')
222
+                ) {
223
+                    $echap = $f($regs);
224
+                }
225
+            }
226
+
227
+            $p = strpos($letexte, (string) $regs[0]);
228
+            $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0]));
229
+        }
230
+    }
231
+
232
+    if ($no_transform) {
233
+        return $letexte;
234
+    }
235
+
236
+    // Echapper le php pour faire joli (ici, c'est pas pour la securite)
237
+    // seulement si on a echappe les <script>
238
+    // (derogatoire car on ne peut pas faire passer < ? ... ? >
239
+    // dans une callback autonommee
240
+    if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) {
241
+        if (
242
+            strpos($letexte, '<' . '?') !== false and preg_match_all(
243
+                ',<[?].*($|[?]>),UisS',
244
+                $letexte,
245
+                $matches,
246
+                PREG_SET_ORDER
247
+            )
248
+        ) {
249
+            foreach ($matches as $regs) {
250
+                $letexte = str_replace(
251
+                    $regs[0],
252
+                    code_echappement(highlight_string($regs[0], true), $source),
253
+                    $letexte
254
+                );
255
+            }
256
+        }
257
+    }
258
+
259
+    return $letexte;
260 260
 }
261 261
 
262 262
 //
@@ -264,57 +264,57 @@  discard block
 block discarded – undo
264 264
 // Rq: $source sert a faire des echappements "a soi" qui ne sont pas nettoyes
265 265
 // par propre() : exemple dans multi et dans typo()
266 266
 function echappe_retour($letexte, $source = '', $filtre = '') {
267
-	if (strpos($letexte, (string) "base64$source")) {
268
-		# spip_log(spip_htmlspecialchars($letexte));  ## pour les curieux
269
-		$max_prof = 5;
270
-		while (
271
-			strpos($letexte, '<') !== false
272
-			and
273
-			preg_match_all(
274
-				',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS',
275
-				$letexte,
276
-				$regs,
277
-				PREG_SET_ORDER
278
-			)
279
-			and $max_prof--
280
-		) {
281
-			foreach ($regs as $reg) {
282
-				$rempl = base64_decode(extraire_attribut($reg[0], 'title'));
283
-				// recherche d'attributs supplementaires
284
-				$at = [];
285
-				foreach (['lang', 'dir'] as $attr) {
286
-					if ($a = extraire_attribut($reg[0], $attr)) {
287
-						$at[$attr] = $a;
288
-					}
289
-				}
290
-				if ($at) {
291
-					$rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>';
292
-					foreach ($at as $attr => $a) {
293
-						$rempl = inserer_attribut($rempl, $attr, $a);
294
-					}
295
-				}
296
-				if ($filtre) {
297
-					$rempl = $filtre($rempl);
298
-				}
299
-				$letexte = str_replace($reg[0], $rempl, $letexte);
300
-			}
301
-		}
302
-	}
303
-
304
-	return $letexte;
267
+    if (strpos($letexte, (string) "base64$source")) {
268
+        # spip_log(spip_htmlspecialchars($letexte));  ## pour les curieux
269
+        $max_prof = 5;
270
+        while (
271
+            strpos($letexte, '<') !== false
272
+            and
273
+            preg_match_all(
274
+                ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS',
275
+                $letexte,
276
+                $regs,
277
+                PREG_SET_ORDER
278
+            )
279
+            and $max_prof--
280
+        ) {
281
+            foreach ($regs as $reg) {
282
+                $rempl = base64_decode(extraire_attribut($reg[0], 'title'));
283
+                // recherche d'attributs supplementaires
284
+                $at = [];
285
+                foreach (['lang', 'dir'] as $attr) {
286
+                    if ($a = extraire_attribut($reg[0], $attr)) {
287
+                        $at[$attr] = $a;
288
+                    }
289
+                }
290
+                if ($at) {
291
+                    $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>';
292
+                    foreach ($at as $attr => $a) {
293
+                        $rempl = inserer_attribut($rempl, $attr, $a);
294
+                    }
295
+                }
296
+                if ($filtre) {
297
+                    $rempl = $filtre($rempl);
298
+                }
299
+                $letexte = str_replace($reg[0], $rempl, $letexte);
300
+            }
301
+        }
302
+    }
303
+
304
+    return $letexte;
305 305
 }
306 306
 
307 307
 // Reinserer le javascript de confiance (venant des modeles)
308 308
 
309 309
 function echappe_retour_modeles($letexte, $interdire_scripts = false) {
310
-	$letexte = echappe_retour($letexte);
310
+    $letexte = echappe_retour($letexte);
311 311
 
312
-	// Dans les appels directs hors squelette, securiser aussi ici
313
-	if ($interdire_scripts) {
314
-		$letexte = interdire_scripts($letexte);
315
-	}
312
+    // Dans les appels directs hors squelette, securiser aussi ici
313
+    if ($interdire_scripts) {
314
+        $letexte = interdire_scripts($letexte);
315
+    }
316 316
 
317
-	return trim($letexte);
317
+    return trim($letexte);
318 318
 }
319 319
 
320 320
 
@@ -342,131 +342,131 @@  discard block
 block discarded – undo
342 342
  *     Texte coupé
343 343
  **/
344 344
 function couper($texte, $taille = 50, $suite = null) {
345
-	if (!($length = strlen($texte)) or $taille <= 0) {
346
-		return '';
347
-	}
348
-	$offset = 400 + 2 * $taille;
349
-	while (
350
-		$offset < $length
351
-		and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille
352
-	) {
353
-		$offset = 2 * $offset;
354
-	}
355
-	if (
356
-		$offset < $length
357
-		&& ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null
358
-	) {
359
-		$p_tag_fermant = strpos($texte, '>', $offset);
360
-		if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) {
361
-			$offset = $p_tag_fermant + 1;
362
-		} // prolonger la coupe jusqu'au tag fermant suivant eventuel
363
-	}
364
-	$texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */
365
-
366
-	if (!function_exists('nettoyer_raccourcis_typo')) {
367
-		include_spip('inc/lien');
368
-	}
369
-	$texte = nettoyer_raccourcis_typo($texte);
370
-
371
-	// balises de sauts de ligne et paragraphe
372
-	$texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte);
373
-	$texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte);
374
-
375
-	// on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier
376
-	$texte = str_replace("\n\n", "\r", $texte);
377
-
378
-	// supprimer les tags
379
-	$texte = supprimer_tags($texte);
380
-	$texte = trim(str_replace("\n", ' ', $texte));
381
-	$texte .= "\n";  // marquer la fin
382
-
383
-	// corriger la longueur de coupe
384
-	// en fonction de la presence de caracteres utf
385
-	if ($GLOBALS['meta']['charset'] == 'utf-8') {
386
-		$long = charset2unicode($texte);
387
-		$long = spip_substr($long, 0, max($taille, 1));
388
-		$nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches);
389
-		$taille += $nbcharutf;
390
-	}
391
-
392
-
393
-	// couper au mot precedent
394
-	$long = spip_substr($texte, 0, max($taille - 4, 1));
395
-	$u = $GLOBALS['meta']['pcre_u'];
396
-	$court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
397
-	if (is_null($suite)) {
398
-		$suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : '&nbsp;(...)');
399
-	}
400
-	$points = $suite;
401
-
402
-	// trop court ? ne pas faire de (...)
403
-	if (spip_strlen($court) < max(0.75 * $taille, 2)) {
404
-		$points = '';
405
-		$long = spip_substr($texte, 0, $taille);
406
-		$texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
407
-		// encore trop court ? couper au caractere
408
-		if (spip_strlen($texte) < 0.75 * $taille) {
409
-			$texte = $long;
410
-		}
411
-	} else {
412
-		$texte = $court;
413
-	}
414
-
415
-	if (strpos($texte, "\n")) {  // la fin est encore la : c'est qu'on n'a pas de texte de suite
416
-	$points = '';
417
-	}
418
-
419
-	// remettre les paragraphes
420
-	$texte = preg_replace("/\r+/", "\n\n", $texte);
421
-
422
-	// supprimer l'eventuelle entite finale mal coupee
423
-	$texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte);
424
-
425
-	return quote_amp(trim($texte)) . $points;
345
+    if (!($length = strlen($texte)) or $taille <= 0) {
346
+        return '';
347
+    }
348
+    $offset = 400 + 2 * $taille;
349
+    while (
350
+        $offset < $length
351
+        and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille
352
+    ) {
353
+        $offset = 2 * $offset;
354
+    }
355
+    if (
356
+        $offset < $length
357
+        && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null
358
+    ) {
359
+        $p_tag_fermant = strpos($texte, '>', $offset);
360
+        if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) {
361
+            $offset = $p_tag_fermant + 1;
362
+        } // prolonger la coupe jusqu'au tag fermant suivant eventuel
363
+    }
364
+    $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */
365
+
366
+    if (!function_exists('nettoyer_raccourcis_typo')) {
367
+        include_spip('inc/lien');
368
+    }
369
+    $texte = nettoyer_raccourcis_typo($texte);
370
+
371
+    // balises de sauts de ligne et paragraphe
372
+    $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte);
373
+    $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte);
374
+
375
+    // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier
376
+    $texte = str_replace("\n\n", "\r", $texte);
377
+
378
+    // supprimer les tags
379
+    $texte = supprimer_tags($texte);
380
+    $texte = trim(str_replace("\n", ' ', $texte));
381
+    $texte .= "\n";  // marquer la fin
382
+
383
+    // corriger la longueur de coupe
384
+    // en fonction de la presence de caracteres utf
385
+    if ($GLOBALS['meta']['charset'] == 'utf-8') {
386
+        $long = charset2unicode($texte);
387
+        $long = spip_substr($long, 0, max($taille, 1));
388
+        $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches);
389
+        $taille += $nbcharutf;
390
+    }
391
+
392
+
393
+    // couper au mot precedent
394
+    $long = spip_substr($texte, 0, max($taille - 4, 1));
395
+    $u = $GLOBALS['meta']['pcre_u'];
396
+    $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
397
+    if (is_null($suite)) {
398
+        $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : '&nbsp;(...)');
399
+    }
400
+    $points = $suite;
401
+
402
+    // trop court ? ne pas faire de (...)
403
+    if (spip_strlen($court) < max(0.75 * $taille, 2)) {
404
+        $points = '';
405
+        $long = spip_substr($texte, 0, $taille);
406
+        $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long);
407
+        // encore trop court ? couper au caractere
408
+        if (spip_strlen($texte) < 0.75 * $taille) {
409
+            $texte = $long;
410
+        }
411
+    } else {
412
+        $texte = $court;
413
+    }
414
+
415
+    if (strpos($texte, "\n")) {  // la fin est encore la : c'est qu'on n'a pas de texte de suite
416
+    $points = '';
417
+    }
418
+
419
+    // remettre les paragraphes
420
+    $texte = preg_replace("/\r+/", "\n\n", $texte);
421
+
422
+    // supprimer l'eventuelle entite finale mal coupee
423
+    $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte);
424
+
425
+    return quote_amp(trim($texte)) . $points;
426 426
 }
427 427
 
428 428
 
429 429
 function protege_js_modeles($t) {
430
-	if (isset($GLOBALS['visiteur_session'])) {
431
-		if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) {
432
-			if (!defined('_PROTEGE_JS_MODELES')) {
433
-				include_spip('inc/acces');
434
-				define('_PROTEGE_JS_MODELES', creer_uniqid());
435
-			}
436
-			foreach ($r as $regs) {
437
-				$t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t);
438
-			}
439
-		}
440
-		if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) {
441
-			if (!defined('_PROTEGE_PHP_MODELES')) {
442
-				include_spip('inc/acces');
443
-				define('_PROTEGE_PHP_MODELES', creer_uniqid());
444
-			}
445
-			foreach ($r as $regs) {
446
-				$t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t);
447
-			}
448
-		}
449
-	}
450
-
451
-	return $t;
430
+    if (isset($GLOBALS['visiteur_session'])) {
431
+        if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) {
432
+            if (!defined('_PROTEGE_JS_MODELES')) {
433
+                include_spip('inc/acces');
434
+                define('_PROTEGE_JS_MODELES', creer_uniqid());
435
+            }
436
+            foreach ($r as $regs) {
437
+                $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t);
438
+            }
439
+        }
440
+        if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) {
441
+            if (!defined('_PROTEGE_PHP_MODELES')) {
442
+                include_spip('inc/acces');
443
+                define('_PROTEGE_PHP_MODELES', creer_uniqid());
444
+            }
445
+            foreach ($r as $regs) {
446
+                $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t);
447
+            }
448
+        }
449
+    }
450
+
451
+    return $t;
452 452
 }
453 453
 
454 454
 
455 455
 function echapper_faux_tags($letexte) {
456
-	if (strpos($letexte, '<') === false) {
457
-		return $letexte;
458
-	}
459
-	$textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE);
460
-
461
-	$letexte = '';
462
-	while (is_countable($textMatches) ? count($textMatches) : 0) {
463
-		// un texte a echapper
464
-		$letexte .= str_replace('<', '&lt;', array_shift($textMatches));
465
-		// un tag html qui a servit a faite le split
466
-		$letexte .= array_shift($textMatches);
467
-	}
468
-
469
-	return $letexte;
456
+    if (strpos($letexte, '<') === false) {
457
+        return $letexte;
458
+    }
459
+    $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE);
460
+
461
+    $letexte = '';
462
+    while (is_countable($textMatches) ? count($textMatches) : 0) {
463
+        // un texte a echapper
464
+        $letexte .= str_replace('<', '&lt;', array_shift($textMatches));
465
+        // un tag html qui a servit a faite le split
466
+        $letexte .= array_shift($textMatches);
467
+    }
468
+
469
+    return $letexte;
470 470
 }
471 471
 
472 472
 /**
@@ -479,47 +479,47 @@  discard block
 block discarded – undo
479 479
  * @return string
480 480
  */
481 481
 function echapper_html_suspect($texte, $strict = true) {
482
-	static $echapper_html_suspect;
483
-	if (!$texte or !is_string($texte)) {
484
-		return $texte;
485
-	}
486
-
487
-	if (!isset($echapper_html_suspect)) {
488
-		$echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true);
489
-	}
490
-	// si fonction personalisee, on delegue
491
-	if ($echapper_html_suspect) {
492
-		return $echapper_html_suspect($texte, $strict);
493
-	}
494
-
495
-	if (
496
-		strpos($texte, '<') === false
497
-		or strpos($texte, '=') === false
498
-	) {
499
-		return $texte;
500
-	}
501
-
502
-	// quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx=
503
-	// car sinon on declenche sur les modeles ou ressources
504
-	if (
505
-		!$strict and
506
-		(strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte))
507
-	) {
508
-		return $texte;
509
-	}
510
-
511
-	// on teste sur strlen car safehtml supprime le contenu dangereux
512
-	// mais il peut aussi changer des ' en " sur les attributs html,
513
-	// donc un test d'egalite est trop strict
514
-	if (strlen(safehtml($texte)) !== strlen($texte)) {
515
-		$texte = str_replace('<', '&lt;', $texte);
516
-		if (!function_exists('attribut_html')) {
517
-			include_spip('inc/filtres');
518
-		}
519
-		$texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte;
520
-	}
521
-
522
-	return $texte;
482
+    static $echapper_html_suspect;
483
+    if (!$texte or !is_string($texte)) {
484
+        return $texte;
485
+    }
486
+
487
+    if (!isset($echapper_html_suspect)) {
488
+        $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true);
489
+    }
490
+    // si fonction personalisee, on delegue
491
+    if ($echapper_html_suspect) {
492
+        return $echapper_html_suspect($texte, $strict);
493
+    }
494
+
495
+    if (
496
+        strpos($texte, '<') === false
497
+        or strpos($texte, '=') === false
498
+    ) {
499
+        return $texte;
500
+    }
501
+
502
+    // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx=
503
+    // car sinon on declenche sur les modeles ou ressources
504
+    if (
505
+        !$strict and
506
+        (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte))
507
+    ) {
508
+        return $texte;
509
+    }
510
+
511
+    // on teste sur strlen car safehtml supprime le contenu dangereux
512
+    // mais il peut aussi changer des ' en " sur les attributs html,
513
+    // donc un test d'egalite est trop strict
514
+    if (strlen(safehtml($texte)) !== strlen($texte)) {
515
+        $texte = str_replace('<', '&lt;', $texte);
516
+        if (!function_exists('attribut_html')) {
517
+            include_spip('inc/filtres');
518
+        }
519
+        $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte;
520
+    }
521
+
522
+    return $texte;
523 523
 }
524 524
 
525 525
 
@@ -540,30 +540,30 @@  discard block
 block discarded – undo
540 540
  *      Texte sécurisé
541 541
  **/
542 542
 function safehtml($t) {
543
-	static $safehtml;
544
-
545
-	if (!$t or !is_string($t)) {
546
-		return $t;
547
-	}
548
-	# attention safehtml nettoie deux ou trois caracteres de plus. A voir
549
-	if (strpos($t, '<') === false) {
550
-		return str_replace("\x00", '', $t);
551
-	}
552
-
553
-	if (!function_exists('interdire_scripts')) {
554
-		include_spip('inc/texte');
555
-	}
556
-	$t = interdire_scripts($t); // jolifier le php
557
-	$t = echappe_js($t);
558
-
559
-	if (!isset($safehtml)) {
560
-		$safehtml = charger_fonction('safehtml', 'inc', true);
561
-	}
562
-	if ($safehtml) {
563
-		$t = $safehtml($t);
564
-	}
565
-
566
-	return interdire_scripts($t); // interdire le php (2 precautions)
543
+    static $safehtml;
544
+
545
+    if (!$t or !is_string($t)) {
546
+        return $t;
547
+    }
548
+    # attention safehtml nettoie deux ou trois caracteres de plus. A voir
549
+    if (strpos($t, '<') === false) {
550
+        return str_replace("\x00", '', $t);
551
+    }
552
+
553
+    if (!function_exists('interdire_scripts')) {
554
+        include_spip('inc/texte');
555
+    }
556
+    $t = interdire_scripts($t); // jolifier le php
557
+    $t = echappe_js($t);
558
+
559
+    if (!isset($safehtml)) {
560
+        $safehtml = charger_fonction('safehtml', 'inc', true);
561
+    }
562
+    if ($safehtml) {
563
+        $t = $safehtml($t);
564
+    }
565
+
566
+    return interdire_scripts($t); // interdire le php (2 precautions)
567 567
 }
568 568
 
569 569
 
@@ -585,13 +585,13 @@  discard block
 block discarded – undo
585 585
  *     Texte sans les modèles d'image
586 586
  **/
587 587
 function supprime_img($letexte, $message = null) {
588
-	if ($message === null) {
589
-		$message = '(' . _T('img_indisponible') . ')';
590
-	}
591
-
592
-	return preg_replace(
593
-		',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i',
594
-		$message,
595
-		$letexte
596
-	);
588
+    if ($message === null) {
589
+        $message = '(' . _T('img_indisponible') . ')';
590
+    }
591
+
592
+    return preg_replace(
593
+        ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i',
594
+        $message,
595
+        $letexte
596
+    );
597 597
 }
Please login to merge, or discard this patch.
ecrire/inc/cookie.php 1 patch
Indentation   +97 added lines, -97 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
 
@@ -52,68 +52,68 @@  discard block
 block discarded – undo
52 52
  *     cookie sécurisé ou non ?
53 53
  **/
54 54
 function spip_setcookie($name = '', $value = '', $options = []) {
55
-	static $to_secure_list = ['spip_session'];
56
-	if (defined('_COOKIE_SECURE_LIST') and is_array(_COOKIE_SECURE_LIST)) {
57
-		$to_secure_list = array_merge($to_secure_list, _COOKIE_SECURE_LIST);
58
-	}
59
-
60
-	if (!is_array($options)) {
61
-		// anciens paramètres :
62
-		# spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '')
63
-		$opt = func_get_args();
64
-		$opt = array_slice($opt, 2);
65
-		$options = []; # /!\ après le func_get_args (sinon $opt[0] référence la nouvelle valeur de $options !);
66
-		if (isset($opt[0])) {
67
-			$options['expires'] = $opt[0];
68
-		}
69
-		if (isset($opt[1])) {
70
-			$options['path'] = $opt[1];
71
-		}
72
-		if (isset($opt[2])) {
73
-			$options['domain'] = $opt[2];
74
-		}
75
-		if (isset($opt[3])) {
76
-			$options['secure'] = $opt[3];
77
-		}
78
-	}
79
-
80
-	// expires
81
-	if (!isset($options['expires'])) {
82
-		$options['expires'] = 0;
83
-	}
84
-	if (!isset($options['path']) or $options['path'] === 'AUTO') {
85
-		if (defined('_COOKIE_PATH')) {
86
-			$options['path'] = _COOKIE_PATH;
87
-		} else {
88
-			$options['path'] = preg_replace(',^\w+://[^/]*,', '', url_de_base());
89
-		}
90
-	}
91
-	if (empty($options['domain']) and defined('_COOKIE_DOMAIN') and _COOKIE_DOMAIN) {
92
-		$options['domain'] = _COOKIE_DOMAIN;
93
-	}
94
-	if (in_array($name, $to_secure_list)) {
95
-		if (empty($options['secure']) and defined('_COOKIE_SECURE') and _COOKIE_SECURE) {
96
-			$options['secure'] = true;
97
-		}
98
-		if (empty($options['httponly'])) {
99
-			$options['httponly'] = true;
100
-		}
101
-	}
102
-	if (empty($options['samesite'])) {
103
-		$options['samesite'] = 'Lax';
104
-	}
105
-
106
-	// in fine renommer le prefixe si besoin
107
-	if (strpos($name, 'spip_') === 0) {
108
-		$name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5);
109
-	}
110
-
111
-	#spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies");
112
-	$a = @setcookie($name, $value, $options);
113
-
114
-	spip_cookie_envoye(true);
115
-
116
-	return $a;
55
+    static $to_secure_list = ['spip_session'];
56
+    if (defined('_COOKIE_SECURE_LIST') and is_array(_COOKIE_SECURE_LIST)) {
57
+        $to_secure_list = array_merge($to_secure_list, _COOKIE_SECURE_LIST);
58
+    }
59
+
60
+    if (!is_array($options)) {
61
+        // anciens paramètres :
62
+        # spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '')
63
+        $opt = func_get_args();
64
+        $opt = array_slice($opt, 2);
65
+        $options = []; # /!\ après le func_get_args (sinon $opt[0] référence la nouvelle valeur de $options !);
66
+        if (isset($opt[0])) {
67
+            $options['expires'] = $opt[0];
68
+        }
69
+        if (isset($opt[1])) {
70
+            $options['path'] = $opt[1];
71
+        }
72
+        if (isset($opt[2])) {
73
+            $options['domain'] = $opt[2];
74
+        }
75
+        if (isset($opt[3])) {
76
+            $options['secure'] = $opt[3];
77
+        }
78
+    }
79
+
80
+    // expires
81
+    if (!isset($options['expires'])) {
82
+        $options['expires'] = 0;
83
+    }
84
+    if (!isset($options['path']) or $options['path'] === 'AUTO') {
85
+        if (defined('_COOKIE_PATH')) {
86
+            $options['path'] = _COOKIE_PATH;
87
+        } else {
88
+            $options['path'] = preg_replace(',^\w+://[^/]*,', '', url_de_base());
89
+        }
90
+    }
91
+    if (empty($options['domain']) and defined('_COOKIE_DOMAIN') and _COOKIE_DOMAIN) {
92
+        $options['domain'] = _COOKIE_DOMAIN;
93
+    }
94
+    if (in_array($name, $to_secure_list)) {
95
+        if (empty($options['secure']) and defined('_COOKIE_SECURE') and _COOKIE_SECURE) {
96
+            $options['secure'] = true;
97
+        }
98
+        if (empty($options['httponly'])) {
99
+            $options['httponly'] = true;
100
+        }
101
+    }
102
+    if (empty($options['samesite'])) {
103
+        $options['samesite'] = 'Lax';
104
+    }
105
+
106
+    // in fine renommer le prefixe si besoin
107
+    if (strpos($name, 'spip_') === 0) {
108
+        $name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5);
109
+    }
110
+
111
+    #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies");
112
+    $a = @setcookie($name, $value, $options);
113
+
114
+    spip_cookie_envoye(true);
115
+
116
+    return $a;
117 117
 }
118 118
 
119 119
 /**
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
  * @return bool
130 130
  **/
131 131
 function spip_cookie_envoye($set = '') {
132
-	static $envoye = false;
133
-	if ($set) {
134
-		$envoye = true;
135
-	}
132
+    static $envoye = false;
133
+    if ($set) {
134
+        $envoye = true;
135
+    }
136 136
 
137
-	return $envoye;
137
+    return $envoye;
138 138
 }
139 139
 
140 140
 /**
@@ -153,21 +153,21 @@  discard block
 block discarded – undo
153 153
  *     Préfixe des cookies de SPIP
154 154
  **/
155 155
 function recuperer_cookies_spip($cookie_prefix) {
156
-	$prefix_long = strlen($cookie_prefix);
157
-
158
-	foreach ($_COOKIE as $name => $value) {
159
-		if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) {
160
-			unset($_COOKIE[$name]);
161
-			unset($GLOBALS[$name]);
162
-		}
163
-	}
164
-	foreach ($_COOKIE as $name => $value) {
165
-		if (substr($name, 0, $prefix_long) == $cookie_prefix) {
166
-			$spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name);
167
-			$_COOKIE[$spipname] = $value;
168
-			$GLOBALS[$spipname] = $value;
169
-		}
170
-	}
156
+    $prefix_long = strlen($cookie_prefix);
157
+
158
+    foreach ($_COOKIE as $name => $value) {
159
+        if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) {
160
+            unset($_COOKIE[$name]);
161
+            unset($GLOBALS[$name]);
162
+        }
163
+    }
164
+    foreach ($_COOKIE as $name => $value) {
165
+        if (substr($name, 0, $prefix_long) == $cookie_prefix) {
166
+            $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name);
167
+            $_COOKIE[$spipname] = $value;
168
+            $GLOBALS[$spipname] = $value;
169
+        }
170
+    }
171 171
 }
172 172
 
173 173
 
@@ -186,18 +186,18 @@  discard block
 block discarded – undo
186 186
  *
187 187
  **/
188 188
 function exec_test_ajax_dist() {
189
-	switch (_request('js')) {
190
-		// on est appele par <noscript>
191
-		case -1:
192
-			spip_setcookie('spip_accepte_ajax', -1);
193
-			include_spip('inc/headers');
194
-			redirige_par_entete(chemin_image('erreur-xx.svg'));
195
-			break;
196
-
197
-		// ou par ajax
198
-		case 1:
199
-		default:
200
-			spip_setcookie('spip_accepte_ajax', 1);
201
-			break;
202
-	}
189
+    switch (_request('js')) {
190
+        // on est appele par <noscript>
191
+        case -1:
192
+            spip_setcookie('spip_accepte_ajax', -1);
193
+            include_spip('inc/headers');
194
+            redirige_par_entete(chemin_image('erreur-xx.svg'));
195
+            break;
196
+
197
+        // ou par ajax
198
+        case 1:
199
+        default:
200
+            spip_setcookie('spip_accepte_ajax', 1);
201
+            break;
202
+    }
203 203
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres_ecrire.php 1 patch
Indentation   +360 added lines, -360 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Filtres
17 17
  */
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/filtres_boites');
@@ -41,25 +41,25 @@  discard block
 block discarded – undo
41 41
  */
42 42
 function parametres_css_prive() {
43 43
 
44
-	$args = [];
45
-	$args['v'] = $GLOBALS['spip_version_code'];
46
-	$args['p'] = substr(md5($GLOBALS['meta']['plugin']), 0, 4);
47
-	$args['themes'] = implode(',', lister_themes_prives());
48
-	$args['ltr'] = $GLOBALS['spip_lang_left'];
49
-	// un md5 des menus : si un menu change il faut maj la css
50
-	$args['md5b'] = (function_exists('md5_boutons_plugins') ? md5_boutons_plugins() : '');
44
+    $args = [];
45
+    $args['v'] = $GLOBALS['spip_version_code'];
46
+    $args['p'] = substr(md5($GLOBALS['meta']['plugin']), 0, 4);
47
+    $args['themes'] = implode(',', lister_themes_prives());
48
+    $args['ltr'] = $GLOBALS['spip_lang_left'];
49
+    // un md5 des menus : si un menu change il faut maj la css
50
+    $args['md5b'] = (function_exists('md5_boutons_plugins') ? md5_boutons_plugins() : '');
51 51
 
52
-	$c = $GLOBALS['visiteur_session']['prefs']['couleur'] ?? 2;
52
+    $c = $GLOBALS['visiteur_session']['prefs']['couleur'] ?? 2;
53 53
 
54
-	$couleurs = charger_fonction('couleurs', 'inc');
55
-	parse_str($couleurs($c), $c);
56
-	$args = array_merge($args, $c);
54
+    $couleurs = charger_fonction('couleurs', 'inc');
55
+    parse_str($couleurs($c), $c);
56
+    $args = array_merge($args, $c);
57 57
 
58
-	if (_request('var_mode') == 'recalcul' or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')) {
59
-		$args['var_mode'] = 'recalcul';
60
-	}
58
+    if (_request('var_mode') == 'recalcul' or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')) {
59
+        $args['var_mode'] = 'recalcul';
60
+    }
61 61
 
62
-	return http_build_query($args);
62
+    return http_build_query($args);
63 63
 }
64 64
 
65 65
 
@@ -82,91 +82,91 @@  discard block
 block discarded – undo
82 82
  * @return string
83 83
  */
84 84
 function chercher_rubrique(
85
-	$titre,
86
-	$id_objet,
87
-	$id_parent,
88
-	$objet,
89
-	$id_secteur,
90
-	$restreint,
91
-	$actionable = false,
92
-	$retour_sans_cadre = false
85
+    $titre,
86
+    $id_objet,
87
+    $id_parent,
88
+    $objet,
89
+    $id_secteur,
90
+    $restreint,
91
+    $actionable = false,
92
+    $retour_sans_cadre = false
93 93
 ) {
94 94
 
95
-	include_spip('inc/autoriser');
96
-	if (intval($id_objet) && !autoriser('modifier', $objet, $id_objet)) {
97
-		return '';
98
-	}
99
-	if (!sql_countsel('spip_rubriques')) {
100
-		return '';
101
-	}
102
-	$chercher_rubrique = charger_fonction('chercher_rubrique', 'inc');
103
-	$form = $chercher_rubrique($id_parent, $objet, $restreint, ($objet == 'rubrique') ? $id_objet : 0);
104
-
105
-	if ($id_parent == 0) {
106
-		$logo = 'racine-24.png';
107
-	} elseif ($id_secteur == $id_parent) {
108
-		$logo = 'secteur-24.png';
109
-	} else {
110
-		$logo = 'rubrique-24.png';
111
-	}
112
-
113
-	$confirm = '';
114
-	if ($objet == 'rubrique') {
115
-		// si c'est une rubrique-secteur contenant des breves, demander la
116
-		// confirmation du deplacement
117
-		$contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . intval($id_objet));
118
-
119
-		if ($contient_breves > 0) {
120
-			$scb = ($contient_breves > 1 ? 's' : '');
121
-			$scb = _T(
122
-				'avis_deplacement_rubrique',
123
-				[
124
-					'contient_breves' => $contient_breves,
125
-					'scb' => $scb
126
-				]
127
-			);
128
-			$confirm .= "\n<div class='confirmer_deplacement verdana2'>"
129
-				. "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>"
130
-				. $scb .
131
-				"</label></div></div>\n";
132
-		} else {
133
-			$confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n";
134
-		}
135
-	}
136
-	$form .= $confirm;
137
-	if ($actionable) {
138
-		if (strpos($form, '<select') !== false) {
139
-			$form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>"
140
-				. '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>'
141
-				. '</div>';
142
-		}
143
-		$form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form;
144
-		if ($action = charger_fonction("editer_$objet", 'action', true)) {
145
-			$form = generer_action_auteur(
146
-				"editer_$objet",
147
-				$id_objet,
148
-				self(),
149
-				$form,
150
-				" method='post' class='submit_plongeur'"
151
-			);
152
-		} else {
153
-			$form = generer_action_auteur(
154
-				'editer_objet',
155
-				"$objet/$id_objet",
156
-				self(),
157
-				$form,
158
-				" method='post' class='submit_plongeur'"
159
-			);
160
-		}
161
-	}
162
-
163
-	if ($retour_sans_cadre) {
164
-		return $form;
165
-	}
166
-
167
-	include_spip('inc/presentation');
168
-
169
-	return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur();
95
+    include_spip('inc/autoriser');
96
+    if (intval($id_objet) && !autoriser('modifier', $objet, $id_objet)) {
97
+        return '';
98
+    }
99
+    if (!sql_countsel('spip_rubriques')) {
100
+        return '';
101
+    }
102
+    $chercher_rubrique = charger_fonction('chercher_rubrique', 'inc');
103
+    $form = $chercher_rubrique($id_parent, $objet, $restreint, ($objet == 'rubrique') ? $id_objet : 0);
104
+
105
+    if ($id_parent == 0) {
106
+        $logo = 'racine-24.png';
107
+    } elseif ($id_secteur == $id_parent) {
108
+        $logo = 'secteur-24.png';
109
+    } else {
110
+        $logo = 'rubrique-24.png';
111
+    }
112
+
113
+    $confirm = '';
114
+    if ($objet == 'rubrique') {
115
+        // si c'est une rubrique-secteur contenant des breves, demander la
116
+        // confirmation du deplacement
117
+        $contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . intval($id_objet));
118
+
119
+        if ($contient_breves > 0) {
120
+            $scb = ($contient_breves > 1 ? 's' : '');
121
+            $scb = _T(
122
+                'avis_deplacement_rubrique',
123
+                [
124
+                    'contient_breves' => $contient_breves,
125
+                    'scb' => $scb
126
+                ]
127
+            );
128
+            $confirm .= "\n<div class='confirmer_deplacement verdana2'>"
129
+                . "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>"
130
+                . $scb .
131
+                "</label></div></div>\n";
132
+        } else {
133
+            $confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n";
134
+        }
135
+    }
136
+    $form .= $confirm;
137
+    if ($actionable) {
138
+        if (strpos($form, '<select') !== false) {
139
+            $form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>"
140
+                . '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>'
141
+                . '</div>';
142
+        }
143
+        $form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form;
144
+        if ($action = charger_fonction("editer_$objet", 'action', true)) {
145
+            $form = generer_action_auteur(
146
+                "editer_$objet",
147
+                $id_objet,
148
+                self(),
149
+                $form,
150
+                " method='post' class='submit_plongeur'"
151
+            );
152
+        } else {
153
+            $form = generer_action_auteur(
154
+                'editer_objet',
155
+                "$objet/$id_objet",
156
+                self(),
157
+                $form,
158
+                " method='post' class='submit_plongeur'"
159
+            );
160
+        }
161
+    }
162
+
163
+    if ($retour_sans_cadre) {
164
+        return $form;
165
+    }
166
+
167
+    include_spip('inc/presentation');
168
+
169
+    return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur();
170 170
 }
171 171
 
172 172
 
@@ -180,24 +180,24 @@  discard block
 block discarded – undo
180 180
  * @return bool
181 181
  */
182 182
 function avoir_visiteurs($past = false, $accepter = true) {
183
-	if ($GLOBALS['meta']['forums_publics'] == 'abo') {
184
-		return true;
185
-	}
186
-	if ($accepter and $GLOBALS['meta']['accepter_visiteurs'] <> 'non') {
187
-		return true;
188
-	}
189
-	if (sql_countsel('spip_articles', "accepter_forum='abo'")) {
190
-		return true;
191
-	}
192
-	if (!$past) {
193
-		return false;
194
-	}
195
-
196
-	return sql_countsel(
197
-		'spip_auteurs',
198
-		"statut NOT IN ('0minirezo','1comite', '5poubelle')
183
+    if ($GLOBALS['meta']['forums_publics'] == 'abo') {
184
+        return true;
185
+    }
186
+    if ($accepter and $GLOBALS['meta']['accepter_visiteurs'] <> 'non') {
187
+        return true;
188
+    }
189
+    if (sql_countsel('spip_articles', "accepter_forum='abo'")) {
190
+        return true;
191
+    }
192
+    if (!$past) {
193
+        return false;
194
+    }
195
+
196
+    return sql_countsel(
197
+        'spip_auteurs',
198
+        "statut NOT IN ('0minirezo','1comite', '5poubelle')
199 199
 	                    AND (statut<>'nouveau' OR prefs NOT IN ('0minirezo','1comite', '5poubelle'))"
200
-	);
200
+    );
201 201
 }
202 202
 
203 203
 /**
@@ -213,18 +213,18 @@  discard block
 block discarded – undo
213 213
  * @return array
214 214
  */
215 215
 function statuts_articles_visibles($statut_auteur) {
216
-	static $auth = [];
217
-	if (!isset($auth[$statut_auteur])) {
218
-		$auth[$statut_auteur] = [];
219
-		$statuts = array_column(sql_allfetsel('distinct statut', 'spip_articles'), 'statut');
220
-		foreach ($statuts as $s) {
221
-			if (autoriser('voir', 'article', 0, ['statut' => $statut_auteur], ['statut' => $s])) {
222
-				$auth[$statut_auteur][] = $s;
223
-			}
224
-		}
225
-	}
226
-
227
-	return $auth[$statut_auteur];
216
+    static $auth = [];
217
+    if (!isset($auth[$statut_auteur])) {
218
+        $auth[$statut_auteur] = [];
219
+        $statuts = array_column(sql_allfetsel('distinct statut', 'spip_articles'), 'statut');
220
+        foreach ($statuts as $s) {
221
+            if (autoriser('voir', 'article', 0, ['statut' => $statut_auteur], ['statut' => $s])) {
222
+                $auth[$statut_auteur][] = $s;
223
+            }
224
+        }
225
+    }
226
+
227
+    return $auth[$statut_auteur];
228 228
 }
229 229
 
230 230
 /**
@@ -238,38 +238,38 @@  discard block
 block discarded – undo
238 238
  * @return string
239 239
  */
240 240
 function traduire_statut_auteur($statut, $attente = '') {
241
-	$plus = '';
242
-	if ($statut == 'nouveau') {
243
-		if ($attente) {
244
-			$statut = $attente;
245
-			$plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')';
246
-		} else {
247
-			return _T('info_statut_auteur_a_confirmer');
248
-		}
249
-	}
250
-
251
-	$recom = [
252
-		'info_administrateurs' => _T('item_administrateur_2'),
253
-		'info_redacteurs' => _T('intem_redacteur'),
254
-		'info_visiteurs' => _T('item_visiteur'),
255
-		'5poubelle' => _T('texte_statut_poubelle'), // bouh
256
-	];
257
-	if (isset($recom[$statut])) {
258
-		return $recom[$statut] . $plus;
259
-	}
260
-
261
-	// retrouver directement par le statut sinon
262
-	if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) {
263
-		if (isset($recom[$t])) {
264
-			return $recom[$t] . $plus;
265
-		}
266
-
267
-		return _T($t) . $plus;
268
-	}
269
-
270
-	// si on a pas reussi a le traduire, retournons la chaine telle quelle
271
-	// c'est toujours plus informatif que rien du tout
272
-	return $statut;
241
+    $plus = '';
242
+    if ($statut == 'nouveau') {
243
+        if ($attente) {
244
+            $statut = $attente;
245
+            $plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')';
246
+        } else {
247
+            return _T('info_statut_auteur_a_confirmer');
248
+        }
249
+    }
250
+
251
+    $recom = [
252
+        'info_administrateurs' => _T('item_administrateur_2'),
253
+        'info_redacteurs' => _T('intem_redacteur'),
254
+        'info_visiteurs' => _T('item_visiteur'),
255
+        '5poubelle' => _T('texte_statut_poubelle'), // bouh
256
+    ];
257
+    if (isset($recom[$statut])) {
258
+        return $recom[$statut] . $plus;
259
+    }
260
+
261
+    // retrouver directement par le statut sinon
262
+    if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) {
263
+        if (isset($recom[$t])) {
264
+            return $recom[$t] . $plus;
265
+        }
266
+
267
+        return _T($t) . $plus;
268
+    }
269
+
270
+    // si on a pas reussi a le traduire, retournons la chaine telle quelle
271
+    // c'est toujours plus informatif que rien du tout
272
+    return $statut;
273 273
 }
274 274
 
275 275
 /**
@@ -280,29 +280,29 @@  discard block
 block discarded – undo
280 280
  * @return string
281 281
  */
282 282
 function afficher_qui_edite($id_objet, $objet): string {
283
-	static $qui = [];
284
-	if (isset($qui[$objet][$id_objet])) {
285
-		return $qui[$objet][$id_objet];
286
-	}
287
-
288
-	include_spip('inc/config');
289
-	if (lire_config('articles_modif', 'non') === 'non') {
290
-		return $qui[$objet][$id_objet] = '';
291
-	}
292
-
293
-	include_spip('inc/drapeau_edition');
294
-	$modif = mention_qui_edite($id_objet, $objet);
295
-	if (!$modif) {
296
-		return $qui[$objet][$id_objet] = '';
297
-	}
298
-
299
-	include_spip('base/objets');
300
-	$infos = lister_tables_objets_sql(table_objet_sql($objet));
301
-	if (isset($infos['texte_signale_edition'])) {
302
-		return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif);
303
-	}
304
-
305
-	return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif);
283
+    static $qui = [];
284
+    if (isset($qui[$objet][$id_objet])) {
285
+        return $qui[$objet][$id_objet];
286
+    }
287
+
288
+    include_spip('inc/config');
289
+    if (lire_config('articles_modif', 'non') === 'non') {
290
+        return $qui[$objet][$id_objet] = '';
291
+    }
292
+
293
+    include_spip('inc/drapeau_edition');
294
+    $modif = mention_qui_edite($id_objet, $objet);
295
+    if (!$modif) {
296
+        return $qui[$objet][$id_objet] = '';
297
+    }
298
+
299
+    include_spip('base/objets');
300
+    $infos = lister_tables_objets_sql(table_objet_sql($objet));
301
+    if (isset($infos['texte_signale_edition'])) {
302
+        return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif);
303
+    }
304
+
305
+    return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif);
306 306
 }
307 307
 
308 308
 /**
@@ -320,53 +320,53 @@  discard block
 block discarded – undo
320 320
  * @return array
321 321
  */
322 322
 function auteurs_lister_statuts($quoi = 'tous', $en_base = true): array {
323
-	if (!defined('AUTEURS_MIN_REDAC')) {
324
-		define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle');
325
-	}
326
-
327
-	switch ($quoi) {
328
-		case 'redacteurs':
329
-			$statut = AUTEURS_MIN_REDAC;
330
-			$statut = explode(',', $statut);
331
-			if ($en_base) {
332
-				$check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut');
333
-				$retire = array_diff($statut, $check);
334
-				$statut = array_diff($statut, $retire);
335
-			}
336
-
337
-			return array_unique($statut);
338
-
339
-		case 'visiteurs':
340
-			$statut = [];
341
-			$exclus = AUTEURS_MIN_REDAC;
342
-			$exclus = explode(',', $exclus);
343
-			if (!$en_base) {
344
-				// prendre aussi les statuts de la table des status qui ne sont pas dans le define
345
-				$statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus);
346
-			}
347
-			$s_complement = array_column(
348
-				sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')),
349
-				'statut'
350
-			);
351
-
352
-			return array_unique(array_merge($statut, $s_complement));
353
-
354
-		default:
355
-		case 'tous':
356
-			$statut = array_values($GLOBALS['liste_des_statuts']);
357
-			$s_complement = array_column(
358
-				sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')),
359
-				'statut'
360
-			);
361
-			$statut = array_merge($statut, $s_complement);
362
-			if ($en_base) {
363
-				$check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut');
364
-				$retire = array_diff($statut, $check);
365
-				$statut = array_diff($statut, $retire);
366
-			}
367
-
368
-			return array_unique($statut);
369
-	}
323
+    if (!defined('AUTEURS_MIN_REDAC')) {
324
+        define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle');
325
+    }
326
+
327
+    switch ($quoi) {
328
+        case 'redacteurs':
329
+            $statut = AUTEURS_MIN_REDAC;
330
+            $statut = explode(',', $statut);
331
+            if ($en_base) {
332
+                $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut');
333
+                $retire = array_diff($statut, $check);
334
+                $statut = array_diff($statut, $retire);
335
+            }
336
+
337
+            return array_unique($statut);
338
+
339
+        case 'visiteurs':
340
+            $statut = [];
341
+            $exclus = AUTEURS_MIN_REDAC;
342
+            $exclus = explode(',', $exclus);
343
+            if (!$en_base) {
344
+                // prendre aussi les statuts de la table des status qui ne sont pas dans le define
345
+                $statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus);
346
+            }
347
+            $s_complement = array_column(
348
+                sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')),
349
+                'statut'
350
+            );
351
+
352
+            return array_unique(array_merge($statut, $s_complement));
353
+
354
+        default:
355
+        case 'tous':
356
+            $statut = array_values($GLOBALS['liste_des_statuts']);
357
+            $s_complement = array_column(
358
+                sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')),
359
+                'statut'
360
+            );
361
+            $statut = array_merge($statut, $s_complement);
362
+            if ($en_base) {
363
+                $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut');
364
+                $retire = array_diff($statut, $check);
365
+                $statut = array_diff($statut, $retire);
366
+            }
367
+
368
+            return array_unique($statut);
369
+    }
370 370
 }
371 371
 
372 372
 /**
@@ -382,28 +382,28 @@  discard block
 block discarded – undo
382 382
  */
383 383
 function trouver_rubrique_creer_objet($id_rubrique, $objet) {
384 384
 
385
-	if (!$id_rubrique and defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') and _CHOIX_RUBRIQUE_PAR_DEFAUT) {
386
-		$in = !(is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0)
387
-			? ''
388
-			: (' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique']));
389
-
390
-		// on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement
391
-		if ($objet == 'rubrique') {
392
-			$id_rubrique = 0;
393
-		} else {
394
-			$id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1);
395
-		}
396
-
397
-		if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) {
398
-			// manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises
399
-			$res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0');
400
-			while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) {
401
-				$id_rubrique = $row_rub['id_rubrique'];
402
-			}
403
-		}
404
-	}
405
-
406
-	return $id_rubrique;
385
+    if (!$id_rubrique and defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') and _CHOIX_RUBRIQUE_PAR_DEFAUT) {
386
+        $in = !(is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0)
387
+            ? ''
388
+            : (' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique']));
389
+
390
+        // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement
391
+        if ($objet == 'rubrique') {
392
+            $id_rubrique = 0;
393
+        } else {
394
+            $id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1);
395
+        }
396
+
397
+        if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) {
398
+            // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises
399
+            $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0');
400
+            while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) {
401
+                $id_rubrique = $row_rub['id_rubrique'];
402
+            }
403
+        }
404
+    }
405
+
406
+    return $id_rubrique;
407 407
 }
408 408
 
409 409
 /**
@@ -414,12 +414,12 @@  discard block
 block discarded – undo
414 414
  * @return string
415 415
  */
416 416
 function lien_article_virtuel($virtuel) {
417
-	include_spip('inc/lien');
418
-	if (!$virtuel = virtuel_redirige($virtuel)) {
419
-		return '';
420
-	}
417
+    include_spip('inc/lien');
418
+    if (!$virtuel = virtuel_redirige($virtuel)) {
419
+        return '';
420
+    }
421 421
 
422
-	return propre('[->' . $virtuel . ']');
422
+    return propre('[->' . $virtuel . ']');
423 423
 }
424 424
 
425 425
 
@@ -442,11 +442,11 @@  discard block
 block discarded – undo
442 442
  * @filtre
443 443
  */
444 444
 function bouton_spip_rss($op, $args = [], $lang = '', $title = 'RSS') {
445
-	include_spip('inc/acces');
446
-	$clic = http_img_pack('rss-16.png', 'RSS', '', $title);
445
+    include_spip('inc/acces');
446
+    $clic = http_img_pack('rss-16.png', 'RSS', '', $title);
447 447
 
448
-	$url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true);
449
-	return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>";
448
+    $url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true);
449
+    return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>";
450 450
 }
451 451
 
452 452
 
@@ -458,76 +458,76 @@  discard block
 block discarded – undo
458 458
  */
459 459
 function alertes_auteur($id_auteur): string {
460 460
 
461
-	$alertes = [];
462
-
463
-	if (
464
-		isset($GLOBALS['meta']['message_crash_tables'])
465
-		and autoriser('detruire', null, null, $id_auteur)
466
-	) {
467
-		include_spip('genie/maintenance');
468
-		if ($msg = message_crash_tables()) {
469
-			$alertes[] = $msg;
470
-		}
471
-	}
472
-
473
-	if (
474
-		isset($GLOBALS['meta']['message_crash_plugins'])
475
-		and $GLOBALS['meta']['message_crash_plugins']
476
-		and autoriser('configurer', '_plugins', null, $id_auteur)
477
-		and is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins']))
478
-	) {
479
-		$msg = implode(', ', array_map('joli_repertoire', array_keys($msg)));
480
-		$alertes[] = _T('plugins_erreur', ['plugins' => $msg]);
481
-	}
482
-
483
-	$a = $GLOBALS['meta']['message_alertes_auteurs'] ?? '';
484
-	if (
485
-		$a
486
-		and is_array($a = unserialize($a))
487
-		and count($a)
488
-	) {
489
-		$update = false;
490
-		if (isset($a[$GLOBALS['visiteur_session']['statut']])) {
491
-			$alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]);
492
-			unset($a[$GLOBALS['visiteur_session']['statut']]);
493
-			$update = true;
494
-		}
495
-		if (isset($a[''])) {
496
-			$alertes = array_merge($alertes, $a['']);
497
-			unset($a['']);
498
-			$update = true;
499
-		}
500
-		if ($update) {
501
-			ecrire_meta('message_alertes_auteurs', serialize($a));
502
-		}
503
-	}
504
-
505
-	if (
506
-		isset($GLOBALS['meta']['plugin_erreur_activation'])
507
-		and autoriser('configurer', '_plugins', null, $id_auteur)
508
-	) {
509
-		include_spip('inc/plugin');
510
-		$alertes[] = plugin_donne_erreurs();
511
-	}
512
-
513
-	$alertes = pipeline(
514
-		'alertes_auteur',
515
-		[
516
-			'args' => [
517
-				'id_auteur' => $id_auteur,
518
-				'exec' => _request('exec'),
519
-			],
520
-			'data' => $alertes
521
-		]
522
-	);
523
-
524
-	if ($alertes = array_filter($alertes)) {
525
-		return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" .
526
-		join(' | ', $alertes)
527
-		. '</div></div>';
528
-	}
529
-
530
-	return '';
461
+    $alertes = [];
462
+
463
+    if (
464
+        isset($GLOBALS['meta']['message_crash_tables'])
465
+        and autoriser('detruire', null, null, $id_auteur)
466
+    ) {
467
+        include_spip('genie/maintenance');
468
+        if ($msg = message_crash_tables()) {
469
+            $alertes[] = $msg;
470
+        }
471
+    }
472
+
473
+    if (
474
+        isset($GLOBALS['meta']['message_crash_plugins'])
475
+        and $GLOBALS['meta']['message_crash_plugins']
476
+        and autoriser('configurer', '_plugins', null, $id_auteur)
477
+        and is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins']))
478
+    ) {
479
+        $msg = implode(', ', array_map('joli_repertoire', array_keys($msg)));
480
+        $alertes[] = _T('plugins_erreur', ['plugins' => $msg]);
481
+    }
482
+
483
+    $a = $GLOBALS['meta']['message_alertes_auteurs'] ?? '';
484
+    if (
485
+        $a
486
+        and is_array($a = unserialize($a))
487
+        and count($a)
488
+    ) {
489
+        $update = false;
490
+        if (isset($a[$GLOBALS['visiteur_session']['statut']])) {
491
+            $alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]);
492
+            unset($a[$GLOBALS['visiteur_session']['statut']]);
493
+            $update = true;
494
+        }
495
+        if (isset($a[''])) {
496
+            $alertes = array_merge($alertes, $a['']);
497
+            unset($a['']);
498
+            $update = true;
499
+        }
500
+        if ($update) {
501
+            ecrire_meta('message_alertes_auteurs', serialize($a));
502
+        }
503
+    }
504
+
505
+    if (
506
+        isset($GLOBALS['meta']['plugin_erreur_activation'])
507
+        and autoriser('configurer', '_plugins', null, $id_auteur)
508
+    ) {
509
+        include_spip('inc/plugin');
510
+        $alertes[] = plugin_donne_erreurs();
511
+    }
512
+
513
+    $alertes = pipeline(
514
+        'alertes_auteur',
515
+        [
516
+            'args' => [
517
+                'id_auteur' => $id_auteur,
518
+                'exec' => _request('exec'),
519
+            ],
520
+            'data' => $alertes
521
+        ]
522
+    );
523
+
524
+    if ($alertes = array_filter($alertes)) {
525
+        return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" .
526
+        join(' | ', $alertes)
527
+        . '</div></div>';
528
+    }
529
+
530
+    return '';
531 531
 }
532 532
 
533 533
 /**
@@ -537,9 +537,9 @@  discard block
 block discarded – undo
537 537
  * @return string
538 538
  */
539 539
 function filtre_afficher_enfant_rub_dist($id_rubrique) {
540
-	include_spip('inc/presenter_enfants');
540
+    include_spip('inc/presenter_enfants');
541 541
 
542
-	return afficher_enfant_rub(intval($id_rubrique));
542
+    return afficher_enfant_rub(intval($id_rubrique));
543 543
 }
544 544
 
545 545
 /**
@@ -557,15 +557,15 @@  discard block
 block discarded – undo
557 557
  * @return string
558 558
  */
559 559
 function afficher_plus_info($lien, $titre = '+', $titre_lien = '') {
560
-	$titre = attribut_html($titre);
561
-	$icone = "\n<a href='$lien' title='$titre' class='plus_info'>" .
562
-		http_img_pack('information-16.png', $titre) . '</a>';
563
-
564
-	if (!$titre_lien) {
565
-		return $icone;
566
-	} else {
567
-		return $icone . "\n<a href='$lien'>$titre_lien</a>";
568
-	}
560
+    $titre = attribut_html($titre);
561
+    $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" .
562
+        http_img_pack('information-16.png', $titre) . '</a>';
563
+
564
+    if (!$titre_lien) {
565
+        return $icone;
566
+    } else {
567
+        return $icone . "\n<a href='$lien'>$titre_lien</a>";
568
+    }
569 569
 }
570 570
 
571 571
 
@@ -584,22 +584,22 @@  discard block
 block discarded – undo
584 584
  * @return array
585 585
  */
586 586
 function lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien) {
587
-	$res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien);
588
-	if (!(is_countable($res) ? count($res) : 0)) {
589
-		return [];
590
-	}
591
-	$r = reset($res);
592
-	if (isset($r['rang_lien'])) {
593
-		$l = array_column($res, 'rang_lien', $objet_source);
594
-		asort($l);
595
-		$l = array_keys($l);
596
-	} else {
597
-		// Si les liens qu'on cherche sont ceux de la table de lien, l'info est dans la clé de l'objet
598
-		// Sinon c'est dans "id_objet"
599
-		$l = array_column(
600
-			$res,
601
-			$objet_source == $objet_lien ? id_table_objet($objet_source) : 'id_objet'
602
-		);
603
-	}
604
-	return $l;
587
+    $res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien);
588
+    if (!(is_countable($res) ? count($res) : 0)) {
589
+        return [];
590
+    }
591
+    $r = reset($res);
592
+    if (isset($r['rang_lien'])) {
593
+        $l = array_column($res, 'rang_lien', $objet_source);
594
+        asort($l);
595
+        $l = array_keys($l);
596
+    } else {
597
+        // Si les liens qu'on cherche sont ceux de la table de lien, l'info est dans la clé de l'objet
598
+        // Sinon c'est dans "id_objet"
599
+        $l = array_column(
600
+            $res,
601
+            $objet_source == $objet_lien ? id_table_objet($objet_source) : 'id_objet'
602
+        );
603
+    }
604
+    return $l;
605 605
 }
Please login to merge, or discard this patch.
ecrire/inc/presentation_mini.php 1 patch
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Affichage
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  * @return string Code HTML
26 26
  */
27 27
 function debut_grand_cadre() {
28
- return "\n<div class = 'table_page'>\n";
28
+    return "\n<div class = 'table_page'>\n";
29 29
 }
30 30
 
31 31
 /**
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
  * @return string Code HTML
35 35
  */
36 36
 function fin_grand_cadre() {
37
- return "\n</div>";
37
+    return "\n</div>";
38 38
 }
39 39
 
40 40
 // Debut de la colonne de gauche
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
  * @return string Code HTML
50 50
  */
51 51
 function debut_gauche() {
52
-	return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n";
52
+    return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n";
53 53
 }
54 54
 
55 55
 /**
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
  * @return string Code HTML
59 59
  */
60 60
 function fin_gauche() {
61
- return "</div></div><br class = 'nettoyeur' />";
61
+    return "</div></div><br class = 'nettoyeur' />";
62 62
 }
63 63
 
64 64
 /**
@@ -67,13 +67,13 @@  discard block
 block discarded – undo
67 67
  * @return string Code HTML
68 68
  */
69 69
 function creer_colonne_droite() {
70
-	static $deja_colonne_droite;
71
-	if ($deja_colonne_droite) {
72
-		return '';
73
-	}
74
-	$deja_colonne_droite = true;
70
+    static $deja_colonne_droite;
71
+    if ($deja_colonne_droite) {
72
+        return '';
73
+    }
74
+    $deja_colonne_droite = true;
75 75
 
76
-	return "\n</div><div id='extra' class='lat' role='complementary'>";
76
+    return "\n</div><div id='extra' class='lat' role='complementary'>";
77 77
 }
78 78
 
79 79
 /**
@@ -82,10 +82,10 @@  discard block
 block discarded – undo
82 82
  * @return string Code HTML
83 83
  */
84 84
 function debut_droite() {
85
-	return liste_objets_bloques(_request('exec'))
86
-	. creer_colonne_droite()
87
-	. '</div>'
88
-	. "\n<div id='contenu'>";
85
+    return liste_objets_bloques(_request('exec'))
86
+    . creer_colonne_droite()
87
+    . '</div>'
88
+    . "\n<div id='contenu'>";
89 89
 }
90 90
 
91 91
 /**
@@ -107,32 +107,32 @@  discard block
 block discarded – undo
107 107
  *     Code HTML
108 108
  **/
109 109
 function liste_objets_bloques($exec, $contexte = [], $auteur = null): string {
110
-	$res = '';
111
-	include_spip('inc/config');
112
-	if (lire_config('articles_modif', 'non') !== 'non') {
113
-		include_spip('inc/drapeau_edition');
114
-		if (is_null($auteur)) {
115
-			$auteur = $GLOBALS['visiteur_session'];
116
-		}
117
-		if (
118
-			$en_cours = trouver_objet_exec($exec)
119
-			and $en_cours['edition']
120
-			and $type = $en_cours['type']
121
-			and ((isset($contexte[$en_cours['id_table_objet']]) and $id = $contexte[$en_cours['id_table_objet']])
122
-				or $id = _request($en_cours['id_table_objet']))
123
-		) {
124
-			// marquer le fait que l'objet est ouvert en edition par toto
125
-			// a telle date ; une alerte sera donnee aux autres redacteurs
126
-			signale_edition($id, $auteur, $type);
127
-		}
128
-
129
-		$objets_ouverts = liste_drapeau_edition($auteur['id_auteur']);
130
-		if (count($objets_ouverts)) {
131
-			$res .= recuperer_fond('prive/objets/liste/objets-en-edition', [], ['ajax' => true]);
132
-		}
133
-	}
134
-
135
-	return $res;
110
+    $res = '';
111
+    include_spip('inc/config');
112
+    if (lire_config('articles_modif', 'non') !== 'non') {
113
+        include_spip('inc/drapeau_edition');
114
+        if (is_null($auteur)) {
115
+            $auteur = $GLOBALS['visiteur_session'];
116
+        }
117
+        if (
118
+            $en_cours = trouver_objet_exec($exec)
119
+            and $en_cours['edition']
120
+            and $type = $en_cours['type']
121
+            and ((isset($contexte[$en_cours['id_table_objet']]) and $id = $contexte[$en_cours['id_table_objet']])
122
+                or $id = _request($en_cours['id_table_objet']))
123
+        ) {
124
+            // marquer le fait que l'objet est ouvert en edition par toto
125
+            // a telle date ; une alerte sera donnee aux autres redacteurs
126
+            signale_edition($id, $auteur, $type);
127
+        }
128
+
129
+        $objets_ouverts = liste_drapeau_edition($auteur['id_auteur']);
130
+        if (count($objets_ouverts)) {
131
+            $res .= recuperer_fond('prive/objets/liste/objets-en-edition', [], ['ajax' => true]);
132
+        }
133
+    }
134
+
135
+    return $res;
136 136
 }
137 137
 
138 138
 
@@ -146,20 +146,20 @@  discard block
 block discarded – undo
146 146
  * @return string Code HTML
147 147
  **/
148 148
 function fin_page() {
149
-	include_spip('inc/pipelines');
150
-	// avec &var_profile=1 on a le tableau de mesures SQL
151
-	$debug = ((_request('exec') !== 'valider_xml')
152
-		and ((_request('var_mode') == 'debug')
153
-			or (isset($GLOBALS['tableau_des_temps']) and $GLOBALS['tableau_des_temps'])
154
-			and isset($_COOKIE['spip_admin'])));
155
-	$t = '</div><div id="pied"><div class="largeur">'
156
-		. recuperer_fond('prive/squelettes/inclure/pied')
157
-		. '</div>'
158
-		. '</div></div>' // cf. div#page et div.largeur ouvertes dans conmmencer_page()
159
-		. ($debug ? erreur_squelette() : '')
160
-		. "</body></html>\n";
161
-
162
-	return f_queue($t);
149
+    include_spip('inc/pipelines');
150
+    // avec &var_profile=1 on a le tableau de mesures SQL
151
+    $debug = ((_request('exec') !== 'valider_xml')
152
+        and ((_request('var_mode') == 'debug')
153
+            or (isset($GLOBALS['tableau_des_temps']) and $GLOBALS['tableau_des_temps'])
154
+            and isset($_COOKIE['spip_admin'])));
155
+    $t = '</div><div id="pied"><div class="largeur">'
156
+        . recuperer_fond('prive/squelettes/inclure/pied')
157
+        . '</div>'
158
+        . '</div></div>' // cf. div#page et div.largeur ouvertes dans conmmencer_page()
159
+        . ($debug ? erreur_squelette() : '')
160
+        . "</body></html>\n";
161
+
162
+    return f_queue($t);
163 163
 }
164 164
 
165 165
 /**
@@ -174,22 +174,22 @@  discard block
 block discarded – undo
174 174
  * @return string Code HTML
175 175
  **/
176 176
 function html_tests_js() {
177
-	if (_SPIP_AJAX and !defined('_TESTER_NOSCRIPT')) {
178
-		// pour le pied de page (deja defini si on est validation XML)
179
-		define(
180
-			'_TESTER_NOSCRIPT',
181
-			"<noscript>\n<div style='display:none;'><img src='"
182
-			. generer_url_ecrire('test_ajax', 'js=-1')
183
-			. "' width='1' height='1' alt='' /></div></noscript>\n"
184
-		);
185
-	}
186
-
187
-	$rejouer = '';
188
-	if (defined('_SESSION_REJOUER')) {
189
-		$rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER;
190
-	}
191
-
192
-	return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : '');
177
+    if (_SPIP_AJAX and !defined('_TESTER_NOSCRIPT')) {
178
+        // pour le pied de page (deja defini si on est validation XML)
179
+        define(
180
+            '_TESTER_NOSCRIPT',
181
+            "<noscript>\n<div style='display:none;'><img src='"
182
+            . generer_url_ecrire('test_ajax', 'js=-1')
183
+            . "' width='1' height='1' alt='' /></div></noscript>\n"
184
+        );
185
+    }
186
+
187
+    $rejouer = '';
188
+    if (defined('_SESSION_REJOUER')) {
189
+        $rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER;
190
+    }
191
+
192
+    return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : '');
193 193
 }
194 194
 
195 195
 /**
@@ -199,25 +199,25 @@  discard block
 block discarded – undo
199 199
  **/
200 200
 function info_maj_spip() {
201 201
 
202
-	$maj = $GLOBALS['meta']['info_maj_spip'] ?? null;
203
-	if (!$maj) {
204
-		return '';
205
-	}
202
+    $maj = $GLOBALS['meta']['info_maj_spip'] ?? null;
203
+    if (!$maj) {
204
+        return '';
205
+    }
206 206
 
207
-	$maj = explode('|', $maj);
208
-	// c'est une ancienne notif, on a fait la maj depuis !
209
-	if ($GLOBALS['spip_version_branche'] !== reset($maj)) {
210
-		return '';
211
-	}
207
+    $maj = explode('|', $maj);
208
+    // c'est une ancienne notif, on a fait la maj depuis !
209
+    if ($GLOBALS['spip_version_branche'] !== reset($maj)) {
210
+        return '';
211
+    }
212 212
 
213
-	if (!autoriser('webmestre')) {
214
-		return '';
215
-	}
213
+    if (!autoriser('webmestre')) {
214
+        return '';
215
+    }
216 216
 
217
-	array_shift($maj);
218
-	$maj = implode('|', $maj);
217
+    array_shift($maj);
218
+    $maj = implode('|', $maj);
219 219
 
220
-	return "$maj<br />";
220
+    return "$maj<br />";
221 221
 }
222 222
 
223 223
 /**
@@ -228,47 +228,47 @@  discard block
 block discarded – undo
228 228
  **/
229 229
 function info_copyright() {
230 230
 
231
-	$version = $GLOBALS['spip_version_affichee'];
232
-
233
-	//
234
-	// Mention, le cas echeant, de la revision SVN courante
235
-	//
236
-	if ($vcs = version_vcs_courante(_DIR_RACINE, true)) {
237
-		if ($vcs['vcs'] === 'GIT') {
238
-			$url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit'];
239
-		} elseif ($vcs['vcs'] === 'SVN') {
240
-			$url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit'];
241
-		} else {
242
-			$url = '';
243
-		}
244
-		// affichage "GIT [master: abcdef]"
245
-		$commit = $vcs['commit_short'] ?? $vcs['commit'];
246
-		if ($url) {
247
-			$commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>";
248
-		}
249
-		if ($vcs['branch']) {
250
-			$commit = $vcs['branch'] . ': ' . $commit;
251
-		}
252
-		$version .= " {$vcs['vcs']} [$commit]";
253
-	}
254
-
255
-	// et la version de l'ecran de securite
256
-	$secu = defined('_ECRAN_SECURITE')
257
-		? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE])
258
-		: '';
259
-
260
-	return _T(
261
-		'info_copyright',
262
-		[
263
-			'spip' => "<b>SPIP $version</b> ",
264
-			'lien_gpl' =>
265
-				"<a href='" . generer_url_ecrire(
266
-					'aide',
267
-					'aide=licence&var_lang=' . $GLOBALS['spip_lang']
268
-				) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>'
269
-		]
270
-	)
271
-	. $secu;
231
+    $version = $GLOBALS['spip_version_affichee'];
232
+
233
+    //
234
+    // Mention, le cas echeant, de la revision SVN courante
235
+    //
236
+    if ($vcs = version_vcs_courante(_DIR_RACINE, true)) {
237
+        if ($vcs['vcs'] === 'GIT') {
238
+            $url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit'];
239
+        } elseif ($vcs['vcs'] === 'SVN') {
240
+            $url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit'];
241
+        } else {
242
+            $url = '';
243
+        }
244
+        // affichage "GIT [master: abcdef]"
245
+        $commit = $vcs['commit_short'] ?? $vcs['commit'];
246
+        if ($url) {
247
+            $commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>";
248
+        }
249
+        if ($vcs['branch']) {
250
+            $commit = $vcs['branch'] . ': ' . $commit;
251
+        }
252
+        $version .= " {$vcs['vcs']} [$commit]";
253
+    }
254
+
255
+    // et la version de l'ecran de securite
256
+    $secu = defined('_ECRAN_SECURITE')
257
+        ? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE])
258
+        : '';
259
+
260
+    return _T(
261
+        'info_copyright',
262
+        [
263
+            'spip' => "<b>SPIP $version</b> ",
264
+            'lien_gpl' =>
265
+                "<a href='" . generer_url_ecrire(
266
+                    'aide',
267
+                    'aide=licence&var_lang=' . $GLOBALS['spip_lang']
268
+                ) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>'
269
+        ]
270
+    )
271
+    . $secu;
272 272
 }
273 273
 
274 274
 /**
@@ -283,17 +283,17 @@  discard block
 block discarded – undo
283 283
  * @return string             Code HTML
284 284
  **/
285 285
 function formulaire_recherche($page, $complement = '') {
286
-	$recherche = _request('recherche');
287
-	$recherche_aff = entites_html($recherche);
288
-	if (!strlen($recherche)) {
289
-		$recherche_aff = _T('info_rechercher');
290
-		$onfocus = " onfocus=\"this.value='';\"";
291
-	} else {
292
-		$onfocus = '';
293
-	}
294
-
295
-	$form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />';
296
-	$form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />";
297
-
298
-	return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>';
286
+    $recherche = _request('recherche');
287
+    $recherche_aff = entites_html($recherche);
288
+    if (!strlen($recherche)) {
289
+        $recherche_aff = _T('info_rechercher');
290
+        $onfocus = " onfocus=\"this.value='';\"";
291
+    } else {
292
+        $onfocus = '';
293
+    }
294
+
295
+    $form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />';
296
+    $form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />";
297
+
298
+    return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>';
299 299
 }
Please login to merge, or discard this patch.
ecrire/inc/autoriser.php 1 patch
Indentation   +680 added lines, -680 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Autorisations
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('base/abstract_sql');
@@ -38,89 +38,89 @@  discard block
 block discarded – undo
38 38
 
39 39
 
40 40
 if (!function_exists('autoriser')) {
41
-	/**
42
-	 * Autoriser une action
43
-	 *
44
-	 * Teste si une personne (par défaut le visiteur en cours) peut effectuer
45
-	 * une certaine action. Cette fonction est le point d'entrée de toutes
46
-	 * les autorisations.
47
-	 *
48
-	 * La fonction se charge d'appeler des fonctions d'autorisations spécifiques
49
-	 * aux actions demandées si elles existent. Elle cherche donc les fonctions
50
-	 * dans cet ordre :
51
-	 *
52
-	 * - autoriser_{type}_{faire}, sinon avec _dist
53
-	 * - autoriser_{type}, sinon avec _dist
54
-	 * - autoriser_{faire}, sinon avec _dist
55
-	 * - autoriser_{defaut}, sinon avec _dist
56
-	 *
57
-	 * Seul le premier argument est obligatoire.
58
-	 *
59
-	 * @note
60
-	 *     Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre,
61
-	 *     la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser
62
-	 *     cette valeur.
63
-	 *
64
-	 *     Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple
65
-	 *     'statistiques', un souligné avant le terme est ajouté afin d'indiquer
66
-	 *     explicitement à la fonction autoriser de ne pas transformer la chaîne en type
67
-	 *     d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')`
68
-	 *
69
-	 * @note
70
-	 *     Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer
71
-	 *     tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart`
72
-	 *     et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet
73
-	 *     d'éviter une possible confusion si une fonction `autoriser_livre_art` existait :
74
-	 *     quel serait le type, quel serait l'action ?
75
-	 *
76
-	 *     Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art',
77
-	 *     la fonction d'autorisation correspondante ne l'aura pas.
78
-	 *     Exemple : `function autoriser_livreart_modifier_dist(...){...}`
79
-	 *
80
-	 * @api
81
-	 * @see autoriser_dist()
82
-	 * @see objet_type()
83
-	 *
84
-	 * @param string $faire
85
-	 *   une action ('modifier', 'publier'...)
86
-	 * @param string|null $type
87
-	 *   Type d’objet ou élément sur lequel appliquer l’action.
88
-	 *   - null: indifférent à tout type d’élément ou objet éditorial
89
-	 *   - string: objet éditorial (objet_type() est appliqué pour homogénéiser l’entrée)
90
-	 *   - _string: autre élément (avec un souligné en premier caractère, désactive objet_type()).
91
-	 *   Les soulignés seront retirés (cf. la note).
92
-	 * @param string|int|null $id
93
-	 *   id de l'objet ou élément sur lequel on veut agir, si pertinent.
94
-	 *   - null: non utile pour l’autorisation
95
-	 *   - int: identifiant numérique (cas de tous les objets éditoriaux de SPIP)
96
-	 *   - string: identifiant textuel
97
-	 * @param null|int|array $qui
98
-	 *   - si null on prend alors visiteur_session
99
-	 *   - un id_auteur (on regarde dans la base)
100
-	 *   - un tableau auteur complet, y compris [restreint]
101
-	 * @param array $opt
102
-	 *   options sous forme de tableau associatif
103
-	 * @return bool
104
-	 *   true si la personne peut effectuer l'action
105
-	 */
106
-	function autoriser(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool {
107
-		// Charger les fonctions d'autorisation supplementaires
108
-		static $pipe;
109
-		if (!isset($pipe)) {
110
-			$pipe = 1;
111
-			pipeline('autoriser');
112
-		}
113
-
114
-		return autoriser_dist($faire, $type, $id, $qui, $opt);
115
-	}
41
+    /**
42
+     * Autoriser une action
43
+     *
44
+     * Teste si une personne (par défaut le visiteur en cours) peut effectuer
45
+     * une certaine action. Cette fonction est le point d'entrée de toutes
46
+     * les autorisations.
47
+     *
48
+     * La fonction se charge d'appeler des fonctions d'autorisations spécifiques
49
+     * aux actions demandées si elles existent. Elle cherche donc les fonctions
50
+     * dans cet ordre :
51
+     *
52
+     * - autoriser_{type}_{faire}, sinon avec _dist
53
+     * - autoriser_{type}, sinon avec _dist
54
+     * - autoriser_{faire}, sinon avec _dist
55
+     * - autoriser_{defaut}, sinon avec _dist
56
+     *
57
+     * Seul le premier argument est obligatoire.
58
+     *
59
+     * @note
60
+     *     Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre,
61
+     *     la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser
62
+     *     cette valeur.
63
+     *
64
+     *     Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple
65
+     *     'statistiques', un souligné avant le terme est ajouté afin d'indiquer
66
+     *     explicitement à la fonction autoriser de ne pas transformer la chaîne en type
67
+     *     d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')`
68
+     *
69
+     * @note
70
+     *     Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer
71
+     *     tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart`
72
+     *     et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet
73
+     *     d'éviter une possible confusion si une fonction `autoriser_livre_art` existait :
74
+     *     quel serait le type, quel serait l'action ?
75
+     *
76
+     *     Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art',
77
+     *     la fonction d'autorisation correspondante ne l'aura pas.
78
+     *     Exemple : `function autoriser_livreart_modifier_dist(...){...}`
79
+     *
80
+     * @api
81
+     * @see autoriser_dist()
82
+     * @see objet_type()
83
+     *
84
+     * @param string $faire
85
+     *   une action ('modifier', 'publier'...)
86
+     * @param string|null $type
87
+     *   Type d’objet ou élément sur lequel appliquer l’action.
88
+     *   - null: indifférent à tout type d’élément ou objet éditorial
89
+     *   - string: objet éditorial (objet_type() est appliqué pour homogénéiser l’entrée)
90
+     *   - _string: autre élément (avec un souligné en premier caractère, désactive objet_type()).
91
+     *   Les soulignés seront retirés (cf. la note).
92
+     * @param string|int|null $id
93
+     *   id de l'objet ou élément sur lequel on veut agir, si pertinent.
94
+     *   - null: non utile pour l’autorisation
95
+     *   - int: identifiant numérique (cas de tous les objets éditoriaux de SPIP)
96
+     *   - string: identifiant textuel
97
+     * @param null|int|array $qui
98
+     *   - si null on prend alors visiteur_session
99
+     *   - un id_auteur (on regarde dans la base)
100
+     *   - un tableau auteur complet, y compris [restreint]
101
+     * @param array $opt
102
+     *   options sous forme de tableau associatif
103
+     * @return bool
104
+     *   true si la personne peut effectuer l'action
105
+     */
106
+    function autoriser(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool {
107
+        // Charger les fonctions d'autorisation supplementaires
108
+        static $pipe;
109
+        if (!isset($pipe)) {
110
+            $pipe = 1;
111
+            pipeline('autoriser');
112
+        }
113
+
114
+        return autoriser_dist($faire, $type, $id, $qui, $opt);
115
+    }
116 116
 }
117 117
 
118 118
 
119 119
 // mes_fonctions peut aussi declarer des autorisations, il faut donc le charger
120 120
 // mais apres la fonction autoriser()
121 121
 if ($f = find_in_path('mes_fonctions.php')) {
122
-	global $dossier_squelettes;
123
-	include_once(_ROOT_CWD . $f);
122
+    global $dossier_squelettes;
123
+    include_once(_ROOT_CWD . $f);
124 124
 }
125 125
 
126 126
 
@@ -151,82 +151,82 @@  discard block
 block discarded – undo
151 151
  */
152 152
 function autoriser_dist(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool {
153 153
 
154
-	$a = null;
155
-	if ($type === null) {
156
-		$type = '';
157
-	}
158
-
159
-	// Qui ? visiteur_session ?
160
-	// si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge
161
-	if ($qui === null or $qui === '') {
162
-		$qui = $GLOBALS['visiteur_session'] ?: [];
163
-		$qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui);
164
-	} elseif (is_numeric($qui)) {
165
-		$qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui);
166
-	}
167
-
168
-	// Admins restreints, on construit ici (pas generique mais...)
169
-	// le tableau de toutes leurs rubriques (y compris les sous-rubriques)
170
-	if (_ADMINS_RESTREINTS and is_array($qui)) {
171
-		$qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : [];
172
-	}
173
-
174
-	spip_log(
175
-		"autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?',
176
-		'autoriser' . _LOG_DEBUG
177
-	);
178
-
179
-	// passer par objet_type pour avoir les alias
180
-	// sauf si _ est le premier caractère.
181
-	if ($type and $type[0] !== '_') {
182
-		$type = objet_type($type, false);
183
-	}
184
-	// et supprimer les _
185
-	$type = str_replace('_', '', (string) $type);
186
-
187
-	// Si une exception a ete decretee plus haut dans le code, l'appliquer
188
-	if (
189
-		(isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) and autoriser_exception($faire, $type, $id, 'verifier'))
190
-		or (isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) and autoriser_exception($faire, $type, '*', 'verifier'))
191
-	) {
192
-		spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG);
193
-		return true;
194
-	}
195
-
196
-	// Chercher une fonction d'autorisation
197
-	// Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist],
198
-	// autoriser_faire[_dist], autoriser_defaut[_dist]
199
-	$fonctions = $type
200
-		? [
201
-			'autoriser_' . $type . '_' . $faire,
202
-			'autoriser_' . $type . '_' . $faire . '_dist',
203
-			'autoriser_' . $type,
204
-			'autoriser_' . $type . '_dist',
205
-			'autoriser_' . $faire,
206
-			'autoriser_' . $faire . '_dist',
207
-			'autoriser_defaut',
208
-			'autoriser_defaut_dist'
209
-		]
210
-		: [
211
-			'autoriser_' . $faire,
212
-			'autoriser_' . $faire . '_dist',
213
-			'autoriser_defaut',
214
-			'autoriser_defaut_dist'
215
-		];
216
-
217
-	foreach ($fonctions as $f) {
218
-		if (function_exists($f)) {
219
-			$a = $f($faire, $type, $id, $qui, $opt);
220
-			break;
221
-		}
222
-	}
223
-
224
-	spip_log(
225
-		"$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'),
226
-		'autoriser' . _LOG_DEBUG
227
-	);
228
-
229
-	return $a;
154
+    $a = null;
155
+    if ($type === null) {
156
+        $type = '';
157
+    }
158
+
159
+    // Qui ? visiteur_session ?
160
+    // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge
161
+    if ($qui === null or $qui === '') {
162
+        $qui = $GLOBALS['visiteur_session'] ?: [];
163
+        $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui);
164
+    } elseif (is_numeric($qui)) {
165
+        $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui);
166
+    }
167
+
168
+    // Admins restreints, on construit ici (pas generique mais...)
169
+    // le tableau de toutes leurs rubriques (y compris les sous-rubriques)
170
+    if (_ADMINS_RESTREINTS and is_array($qui)) {
171
+        $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : [];
172
+    }
173
+
174
+    spip_log(
175
+        "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?',
176
+        'autoriser' . _LOG_DEBUG
177
+    );
178
+
179
+    // passer par objet_type pour avoir les alias
180
+    // sauf si _ est le premier caractère.
181
+    if ($type and $type[0] !== '_') {
182
+        $type = objet_type($type, false);
183
+    }
184
+    // et supprimer les _
185
+    $type = str_replace('_', '', (string) $type);
186
+
187
+    // Si une exception a ete decretee plus haut dans le code, l'appliquer
188
+    if (
189
+        (isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) and autoriser_exception($faire, $type, $id, 'verifier'))
190
+        or (isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) and autoriser_exception($faire, $type, '*', 'verifier'))
191
+    ) {
192
+        spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG);
193
+        return true;
194
+    }
195
+
196
+    // Chercher une fonction d'autorisation
197
+    // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist],
198
+    // autoriser_faire[_dist], autoriser_defaut[_dist]
199
+    $fonctions = $type
200
+        ? [
201
+            'autoriser_' . $type . '_' . $faire,
202
+            'autoriser_' . $type . '_' . $faire . '_dist',
203
+            'autoriser_' . $type,
204
+            'autoriser_' . $type . '_dist',
205
+            'autoriser_' . $faire,
206
+            'autoriser_' . $faire . '_dist',
207
+            'autoriser_defaut',
208
+            'autoriser_defaut_dist'
209
+        ]
210
+        : [
211
+            'autoriser_' . $faire,
212
+            'autoriser_' . $faire . '_dist',
213
+            'autoriser_defaut',
214
+            'autoriser_defaut_dist'
215
+        ];
216
+
217
+    foreach ($fonctions as $f) {
218
+        if (function_exists($f)) {
219
+            $a = $f($faire, $type, $id, $qui, $opt);
220
+            break;
221
+        }
222
+    }
223
+
224
+    spip_log(
225
+        "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'),
226
+        'autoriser' . _LOG_DEBUG
227
+    );
228
+
229
+    return $a;
230 230
 }
231 231
 
232 232
 // une globale pour aller au plus vite dans la fonction generique ci dessus
@@ -246,33 +246,33 @@  discard block
 block discarded – undo
246 246
  * @return bool
247 247
  */
248 248
 function autoriser_exception(string $faire, ?string $type = '', $id = null, $autoriser = true): bool {
249
-	// une static innaccessible par url pour verifier que la globale est positionnee a bon escient
250
-	static $autorisation;
251
-	// Tolérance avec certains appels
252
-	if ($type === null) {
253
-		$type = '';
254
-	}
255
-	if ($id === null) {
256
-		$id = 0;
257
-	}
258
-	if ($autoriser === 'verifier') {
259
-		return isset($autorisation[$faire][$type][$id]);
260
-	}
261
-	if ($autoriser === true) {
262
-		$GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true;
263
-	}
264
-	if ($autoriser === false) {
265
-		if ($id === '*') {
266
-			unset($GLOBALS['autoriser_exception'][$faire][$type]);
267
-			unset($autorisation[$faire][$type]);
268
-		}
269
-		else {
270
-			unset($GLOBALS['autoriser_exception'][$faire][$type][$id]);
271
-			unset($autorisation[$faire][$type][$id]);
272
-		}
273
-	}
274
-
275
-	return false;
249
+    // une static innaccessible par url pour verifier que la globale est positionnee a bon escient
250
+    static $autorisation;
251
+    // Tolérance avec certains appels
252
+    if ($type === null) {
253
+        $type = '';
254
+    }
255
+    if ($id === null) {
256
+        $id = 0;
257
+    }
258
+    if ($autoriser === 'verifier') {
259
+        return isset($autorisation[$faire][$type][$id]);
260
+    }
261
+    if ($autoriser === true) {
262
+        $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true;
263
+    }
264
+    if ($autoriser === false) {
265
+        if ($id === '*') {
266
+            unset($GLOBALS['autoriser_exception'][$faire][$type]);
267
+            unset($autorisation[$faire][$type]);
268
+        }
269
+        else {
270
+            unset($GLOBALS['autoriser_exception'][$faire][$type][$id]);
271
+            unset($autorisation[$faire][$type][$id]);
272
+        }
273
+    }
274
+
275
+    return false;
276 276
 }
277 277
 
278 278
 
@@ -291,9 +291,9 @@  discard block
 block discarded – undo
291 291
  * @return bool true s'il a le droit, false sinon
292 292
  **/
293 293
 function autoriser_defaut_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
294
-	return
295
-		$qui['statut'] === '0minirezo'
296
-		and !$qui['restreint'];
294
+    return
295
+        $qui['statut'] === '0minirezo'
296
+        and !$qui['restreint'];
297 297
 }
298 298
 
299 299
 /**
@@ -313,10 +313,10 @@  discard block
 block discarded – undo
313 313
  * @return bool true s'il a le droit, false sinon
314 314
  */
315 315
 function autoriser_loger_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
316
-	if ($qui['statut'] === '5poubelle') {
317
-		return false;
318
-	}
319
-	return true;
316
+    if ($qui['statut'] === '5poubelle') {
317
+        return false;
318
+    }
319
+    return true;
320 320
 }
321 321
 
322 322
 /**
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
  * @return bool true s'il a le droit, false sinon
333 333
  **/
334 334
 function autoriser_ecrire_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
335
-	return isset($qui['statut']) and in_array($qui['statut'], ['0minirezo', '1comite']);
335
+    return isset($qui['statut']) and in_array($qui['statut'], ['0minirezo', '1comite']);
336 336
 }
337 337
 
338 338
 /**
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
  * @return bool true s'il a le droit, false sinon
352 352
  **/
353 353
 function autoriser_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
354
-	return in_array($qui['statut'], ['0minirezo', '1comite']);
354
+    return in_array($qui['statut'], ['0minirezo', '1comite']);
355 355
 }
356 356
 
357 357
 /**
@@ -371,18 +371,18 @@  discard block
 block discarded – undo
371 371
  **/
372 372
 function autoriser_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
373 373
 
374
-	// Le visiteur a-t-il un statut prevu par la config ?
375
-	if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) {
376
-		return test_previsualiser_objet_champ($type, $id, $qui, $opt);
377
-	}
374
+    // Le visiteur a-t-il un statut prevu par la config ?
375
+    if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) {
376
+        return test_previsualiser_objet_champ($type, $id, $qui, $opt);
377
+    }
378 378
 
379
-	// A-t-on un token de prévisualisation valable ?
380
-	include_spip('inc/securiser_action');
381
-	if (decrire_token_previsu()) {
382
-		return true;
383
-	}
379
+    // A-t-on un token de prévisualisation valable ?
380
+    include_spip('inc/securiser_action');
381
+    if (decrire_token_previsu()) {
382
+        return true;
383
+    }
384 384
 
385
-	return false;
385
+    return false;
386 386
 }
387 387
 
388 388
 /**
@@ -411,58 +411,58 @@  discard block
 block discarded – undo
411 411
  */
412 412
 function test_previsualiser_objet_champ(string $type = '', $id = null, array $qui = [], array $opt = []): bool {
413 413
 
414
-	// si pas de type et statut fourni, c'est une autorisation generale => OK
415
-	if (!$type) {
416
-		return true;
417
-	}
418
-
419
-	include_spip('base/objets');
420
-	$infos = lister_tables_objets_sql(table_objet_sql($type));
421
-	if (isset($infos['statut'])) {
422
-		foreach ($infos['statut'] as $c) {
423
-			if (isset($c['publie'])) {
424
-				if (!isset($c['previsu'])) {
425
-					return false;
426
-				} // pas de previsu definie => NIET
427
-				$champ = $c['champ'];
428
-				if (!isset($opt[$champ])) {
429
-					return false;
430
-				} // pas de champ passe a la demande => NIET
431
-				$previsu = explode(',', $c['previsu']);
432
-				// regarder si ce statut est autorise pour l'auteur
433
-				if (in_array($opt[$champ] . '/auteur', $previsu)) {
434
-					// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
435
-					// sinon l’auteur en session
436
-					include_spip('inc/securiser_action');
437
-					if ($desc = decrire_token_previsu()) {
438
-						$id_auteur = $desc['id_auteur'];
439
-					} elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
440
-						$id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
441
-					} else {
442
-						$id_auteur = null;
443
-					}
444
-
445
-					if (!$id_auteur) {
446
-						return false;
447
-					} elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) {
448
-						// dans ce cas (admin en general), pas de filtrage sur ce statut
449
-					} elseif (
450
-						!sql_countsel(
451
-							'spip_auteurs_liens',
452
-							'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id)
453
-						)
454
-					) {
455
-						return false;
456
-					} // pas auteur de cet objet => NIET
457
-				} elseif (!in_array($opt[$champ], $previsu)) {
458
-					// le statut n'est pas dans ceux definis par la previsu => NIET
459
-					return false;
460
-				}
461
-			}
462
-		}
463
-	}
464
-
465
-	return true;
414
+    // si pas de type et statut fourni, c'est une autorisation generale => OK
415
+    if (!$type) {
416
+        return true;
417
+    }
418
+
419
+    include_spip('base/objets');
420
+    $infos = lister_tables_objets_sql(table_objet_sql($type));
421
+    if (isset($infos['statut'])) {
422
+        foreach ($infos['statut'] as $c) {
423
+            if (isset($c['publie'])) {
424
+                if (!isset($c['previsu'])) {
425
+                    return false;
426
+                } // pas de previsu definie => NIET
427
+                $champ = $c['champ'];
428
+                if (!isset($opt[$champ])) {
429
+                    return false;
430
+                } // pas de champ passe a la demande => NIET
431
+                $previsu = explode(',', $c['previsu']);
432
+                // regarder si ce statut est autorise pour l'auteur
433
+                if (in_array($opt[$champ] . '/auteur', $previsu)) {
434
+                    // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
435
+                    // sinon l’auteur en session
436
+                    include_spip('inc/securiser_action');
437
+                    if ($desc = decrire_token_previsu()) {
438
+                        $id_auteur = $desc['id_auteur'];
439
+                    } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
440
+                        $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
441
+                    } else {
442
+                        $id_auteur = null;
443
+                    }
444
+
445
+                    if (!$id_auteur) {
446
+                        return false;
447
+                    } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) {
448
+                        // dans ce cas (admin en general), pas de filtrage sur ce statut
449
+                    } elseif (
450
+                        !sql_countsel(
451
+                            'spip_auteurs_liens',
452
+                            'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id)
453
+                        )
454
+                    ) {
455
+                        return false;
456
+                    } // pas auteur de cet objet => NIET
457
+                } elseif (!in_array($opt[$champ], $previsu)) {
458
+                    // le statut n'est pas dans ceux definis par la previsu => NIET
459
+                    return false;
460
+                }
461
+            }
462
+        }
463
+    }
464
+
465
+    return true;
466 466
 }
467 467
 
468 468
 /**
@@ -478,51 +478,51 @@  discard block
 block discarded – undo
478 478
  * @return bool true s'il a le droit, false sinon
479 479
  **/
480 480
 function autoriser_changerlangue_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
481
-	$multi_objets = explode(',', lire_config('multi_objets'));
482
-	$gerer_trad_objets = explode(',', lire_config('gerer_trad_objets'));
483
-	$table = table_objet_sql($type);
484
-	if (
485
-		in_array($table, $multi_objets)
486
-		or in_array($table, $gerer_trad_objets)
487
-	) { // affichage du formulaire si la configuration l'accepte
488
-		$multi_secteurs = lire_config('multi_secteurs');
489
-		$champs = objet_info($type, 'field');
490
-		if (
491
-			$multi_secteurs === 'oui'
492
-			and array_key_exists('id_rubrique', $champs)
493
-		) {
494
-			// multilinguisme par secteur et objet rattaché à une rubrique
495
-			$primary = id_table_objet($type);
496
-			if ($table != 'spip_rubriques') {
497
-				$id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id));
498
-			} else {
499
-				$id_rubrique = $id;
500
-			}
501
-			$id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
502
-			if (!$id_secteur > 0) {
503
-				$id_secteur = $id_rubrique;
504
-			}
505
-			$langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur));
506
-			$langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id));
507
-			if ($langue_secteur != $langue_objet) {
508
-				// configuration incohérente, on laisse l'utilisateur corriger la situation
509
-				return true;
510
-			}
511
-			if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques
512
-				return false;
513
-			} else {
514
-				$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id));
515
-				if ($id_parent != 0) {
516
-					// sous-rubriques : pas de choix de langue
517
-					return false;
518
-				}
519
-			}
520
-		}
521
-	} else {
522
-		return false;
523
-	}
524
-
525
-	return autoriser('modifier', $type, $id, $qui, $opt);
481
+    $multi_objets = explode(',', lire_config('multi_objets'));
482
+    $gerer_trad_objets = explode(',', lire_config('gerer_trad_objets'));
483
+    $table = table_objet_sql($type);
484
+    if (
485
+        in_array($table, $multi_objets)
486
+        or in_array($table, $gerer_trad_objets)
487
+    ) { // affichage du formulaire si la configuration l'accepte
488
+        $multi_secteurs = lire_config('multi_secteurs');
489
+        $champs = objet_info($type, 'field');
490
+        if (
491
+            $multi_secteurs === 'oui'
492
+            and array_key_exists('id_rubrique', $champs)
493
+        ) {
494
+            // multilinguisme par secteur et objet rattaché à une rubrique
495
+            $primary = id_table_objet($type);
496
+            if ($table != 'spip_rubriques') {
497
+                $id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id));
498
+            } else {
499
+                $id_rubrique = $id;
500
+            }
501
+            $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
502
+            if (!$id_secteur > 0) {
503
+                $id_secteur = $id_rubrique;
504
+            }
505
+            $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur));
506
+            $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id));
507
+            if ($langue_secteur != $langue_objet) {
508
+                // configuration incohérente, on laisse l'utilisateur corriger la situation
509
+                return true;
510
+            }
511
+            if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques
512
+                return false;
513
+            } else {
514
+                $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id));
515
+                if ($id_parent != 0) {
516
+                    // sous-rubriques : pas de choix de langue
517
+                    return false;
518
+                }
519
+            }
520
+        }
521
+    } else {
522
+        return false;
523
+    }
524
+
525
+    return autoriser('modifier', $type, $id, $qui, $opt);
526 526
 }
527 527
 
528 528
 /**
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
  * @return bool true s'il a le droit, false sinon
539 539
  **/
540 540
 function autoriser_changertraduction_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
541
-	return autoriser('modifier', $type, $id, $qui, $opt);
541
+    return autoriser('modifier', $type, $id, $qui, $opt);
542 542
 }
543 543
 
544 544
 /**
@@ -554,41 +554,41 @@  discard block
 block discarded – undo
554 554
  * @return bool true s'il a le droit, false sinon
555 555
  **/
556 556
 function autoriser_dater_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
557
-	$table = table_objet($type);
558
-	$trouver_table = charger_fonction('trouver_table', 'base');
559
-	$desc = $trouver_table($table);
560
-	if (!$desc) {
561
-		return false;
562
-	}
563
-
564
-	if (!isset($opt['statut'])) {
565
-		if (isset($desc['field']['statut'])) {
566
-			$statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id));
567
-		} else {
568
-			$statut = 'publie';
569
-		} // pas de statut => publie
570
-	} else {
571
-		$statut = $opt['statut'];
572
-	}
573
-
574
-	// Liste des statuts publiés pour cet objet
575
-	if (isset($desc['statut'][0]['publie'])) {
576
-		$statuts_publies = explode(',', $desc['statut'][0]['publie']);
577
-	}
578
-	// Sinon en dur le statut "publie"
579
-	else {
580
-		$statuts_publies = ['publie'];
581
-	}
582
-
583
-	if (
584
-		in_array($statut, $statuts_publies)
585
-		// Ou cas particulier géré en dur ici pour les articles
586
-		or ($statut === 'prop' and $type === 'article' and $GLOBALS['meta']['post_dates'] === 'non')
587
-	) {
588
-		return autoriser('modifier', $type, $id);
589
-	}
590
-
591
-	return false;
557
+    $table = table_objet($type);
558
+    $trouver_table = charger_fonction('trouver_table', 'base');
559
+    $desc = $trouver_table($table);
560
+    if (!$desc) {
561
+        return false;
562
+    }
563
+
564
+    if (!isset($opt['statut'])) {
565
+        if (isset($desc['field']['statut'])) {
566
+            $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id));
567
+        } else {
568
+            $statut = 'publie';
569
+        } // pas de statut => publie
570
+    } else {
571
+        $statut = $opt['statut'];
572
+    }
573
+
574
+    // Liste des statuts publiés pour cet objet
575
+    if (isset($desc['statut'][0]['publie'])) {
576
+        $statuts_publies = explode(',', $desc['statut'][0]['publie']);
577
+    }
578
+    // Sinon en dur le statut "publie"
579
+    else {
580
+        $statuts_publies = ['publie'];
581
+    }
582
+
583
+    if (
584
+        in_array($statut, $statuts_publies)
585
+        // Ou cas particulier géré en dur ici pour les articles
586
+        or ($statut === 'prop' and $type === 'article' and $GLOBALS['meta']['post_dates'] === 'non')
587
+    ) {
588
+        return autoriser('modifier', $type, $id);
589
+    }
590
+
591
+    return false;
592 592
 }
593 593
 
594 594
 /**
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
  * @return bool true s'il a le droit, false sinon
608 608
  **/
609 609
 function autoriser_instituer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
610
-	return autoriser('modifier', $type, $id, $qui, $opt);
610
+    return autoriser('modifier', $type, $id, $qui, $opt);
611 611
 }
612 612
 
613 613
 /**
@@ -625,12 +625,12 @@  discard block
 block discarded – undo
625 625
  * @return bool true s'il a le droit, false sinon
626 626
  **/
627 627
 function autoriser_rubrique_publierdans_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
628
-	return
629
-		($qui['statut'] === '0minirezo')
630
-		and (
631
-			!$qui['restreint'] or !$id
632
-			or in_array($id, $qui['restreint'])
633
-		);
628
+    return
629
+        ($qui['statut'] === '0minirezo')
630
+        and (
631
+            !$qui['restreint'] or !$id
632
+            or in_array($id, $qui['restreint'])
633
+        );
634 634
 }
635 635
 
636 636
 /**
@@ -648,12 +648,12 @@  discard block
 block discarded – undo
648 648
  * @return bool true s'il a le droit, false sinon
649 649
  **/
650 650
 function autoriser_rubrique_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
651
-	if (!empty($opt['id_parent'])) {
652
-		return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui);
653
-	}
654
-	else {
655
-		return autoriser('defaut', null, 0, $qui, $opt);
656
-	}
651
+    if (!empty($opt['id_parent'])) {
652
+        return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui);
653
+    }
654
+    else {
655
+        return autoriser('defaut', null, 0, $qui, $opt);
656
+    }
657 657
 }
658 658
 
659 659
 /**
@@ -671,10 +671,10 @@  discard block
 block discarded – undo
671 671
  * @return bool true s'il a le droit, false sinon
672 672
  **/
673 673
 function autoriser_rubrique_creerrubriquedans_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
674
-	return
675
-		($id or ($qui['statut'] === '0minirezo' and !$qui['restreint']))
676
-		and autoriser('voir', 'rubrique', $id)
677
-		and autoriser('publierdans', 'rubrique', $id);
674
+    return
675
+        ($id or ($qui['statut'] === '0minirezo' and !$qui['restreint']))
676
+        and autoriser('voir', 'rubrique', $id)
677
+        and autoriser('publierdans', 'rubrique', $id);
678 678
 }
679 679
 
680 680
 /**
@@ -692,10 +692,10 @@  discard block
 block discarded – undo
692 692
  * @return bool true s'il a le droit, false sinon
693 693
  **/
694 694
 function autoriser_rubrique_creerarticledans_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
695
-	return
696
-		$id
697
-		and autoriser('voir', 'rubrique', $id)
698
-		and autoriser('creer', 'article');
695
+    return
696
+        $id
697
+        and autoriser('voir', 'rubrique', $id)
698
+        and autoriser('creer', 'article');
699 699
 }
700 700
 
701 701
 
@@ -714,8 +714,8 @@  discard block
 block discarded – undo
714 714
  * @return bool true s'il a le droit, false sinon
715 715
  **/
716 716
 function autoriser_rubrique_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
717
-	return
718
-		autoriser('publierdans', 'rubrique', $id, $qui, $opt);
717
+    return
718
+        autoriser('publierdans', 'rubrique', $id, $qui, $opt);
719 719
 }
720 720
 
721 721
 /**
@@ -733,29 +733,29 @@  discard block
 block discarded – undo
733 733
  * @return bool true s'il a le droit, false sinon
734 734
  **/
735 735
 function autoriser_rubrique_supprimer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
736
-	if (!$id = intval($id)) {
737
-		return false;
738
-	}
736
+    if (!$id = intval($id)) {
737
+        return false;
738
+    }
739 739
 
740
-	if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) {
741
-		return false;
742
-	}
740
+    if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) {
741
+        return false;
742
+    }
743 743
 
744
-	if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) {
745
-		return false;
746
-	}
744
+    if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) {
745
+        return false;
746
+    }
747 747
 
748
-	$compte = pipeline(
749
-		'objet_compte_enfants',
750
-		['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []]
751
-	);
752
-	foreach ($compte as $objet => $n) {
753
-		if ($n) {
754
-			return false;
755
-		}
756
-	}
748
+    $compte = pipeline(
749
+        'objet_compte_enfants',
750
+        ['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []]
751
+    );
752
+    foreach ($compte as $objet => $n) {
753
+        if ($n) {
754
+            return false;
755
+        }
756
+    }
757 757
 
758
-	return autoriser('modifier', 'rubrique', $id);
758
+    return autoriser('modifier', 'rubrique', $id);
759 759
 }
760 760
 
761 761
 
@@ -775,23 +775,23 @@  discard block
 block discarded – undo
775 775
  * @return bool true s'il a le droit, false sinon
776 776
  **/
777 777
 function autoriser_article_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
778
-	if (!$id) {
779
-		return false;
780
-	}
781
-	$r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id));
782
-
783
-	return
784
-		$r
785
-		and
786
-		(
787
-			autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt)
788
-			or (
789
-				(!isset($opt['statut']) or !in_array($opt['statut'], ['publie', 'refuse'], true))
790
-				and in_array($qui['statut'], ['0minirezo', '1comite'])
791
-				and in_array($r['statut'], ['prop', 'prepa', 'poubelle'])
792
-				and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])
793
-			)
794
-		);
778
+    if (!$id) {
779
+        return false;
780
+    }
781
+    $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id));
782
+
783
+    return
784
+        $r
785
+        and
786
+        (
787
+            autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt)
788
+            or (
789
+                (!isset($opt['statut']) or !in_array($opt['statut'], ['publie', 'refuse'], true))
790
+                and in_array($qui['statut'], ['0minirezo', '1comite'])
791
+                and in_array($r['statut'], ['prop', 'prepa', 'poubelle'])
792
+                and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])
793
+            )
794
+        );
795 795
 }
796 796
 
797 797
 /**
@@ -809,13 +809,13 @@  discard block
 block discarded – undo
809 809
  * @return bool true s'il a le droit, false sinon
810 810
  **/
811 811
 function autoriser_article_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
812
-	if (!empty($opt['id_parent'])) {
813
-		// creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi
814
-		return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui);
815
-	}
816
-	else {
817
-		return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], ['0minirezo', '1comite']));
818
-	}
812
+    if (!empty($opt['id_parent'])) {
813
+        // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi
814
+        return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui);
815
+    }
816
+    else {
817
+        return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], ['0minirezo', '1comite']));
818
+    }
819 819
 }
820 820
 
821 821
 /**
@@ -837,28 +837,28 @@  discard block
 block discarded – undo
837 837
  * @return bool true s'il a le droit, false sinon
838 838
  */
839 839
 function autoriser_article_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
840
-	if ($qui['statut'] === '0minirezo') {
841
-		return true;
842
-	}
843
-	// cas des articles : depend du statut de l'article et de l'auteur
844
-	if (isset($opt['statut'])) {
845
-		$statut = $opt['statut'];
846
-	} else {
847
-		if (!$id) {
848
-			return false;
849
-		}
850
-		$statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id));
851
-	}
852
-
853
-	return
854
-		// si on est pas auteur de l'article,
855
-		// seuls les propose et publies sont visibles
856
-		in_array($statut, ['prop', 'publie'])
857
-		// sinon si on est auteur, on a le droit de le voir, evidemment !
858
-		or
859
-		($id
860
-			and $qui['id_auteur']
861
-			and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']));
840
+    if ($qui['statut'] === '0minirezo') {
841
+        return true;
842
+    }
843
+    // cas des articles : depend du statut de l'article et de l'auteur
844
+    if (isset($opt['statut'])) {
845
+        $statut = $opt['statut'];
846
+    } else {
847
+        if (!$id) {
848
+            return false;
849
+        }
850
+        $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id));
851
+    }
852
+
853
+    return
854
+        // si on est pas auteur de l'article,
855
+        // seuls les propose et publies sont visibles
856
+        in_array($statut, ['prop', 'publie'])
857
+        // sinon si on est auteur, on a le droit de le voir, evidemment !
858
+        or
859
+        ($id
860
+            and $qui['id_auteur']
861
+            and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']));
862 862
 }
863 863
 
864 864
 
@@ -877,24 +877,24 @@  discard block
 block discarded – undo
877 877
  * @return bool true s'il a le droit, false sinon
878 878
  **/
879 879
 function autoriser_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
880
-	# securite, mais on aurait pas du arriver ici !
881
-	if (
882
-		function_exists($f = 'autoriser_' . $type . '_voir')
883
-		or function_exists($f = 'autoriser_' . $type . '_voir_dist')
884
-	) {
885
-		return $f($faire, $type, $id, $qui, $opt);
886
-	}
880
+    # securite, mais on aurait pas du arriver ici !
881
+    if (
882
+        function_exists($f = 'autoriser_' . $type . '_voir')
883
+        or function_exists($f = 'autoriser_' . $type . '_voir_dist')
884
+    ) {
885
+        return $f($faire, $type, $id, $qui, $opt);
886
+    }
887 887
 
888
-	if ($qui['statut'] === '0minirezo') {
889
-		return true;
890
-	}
891
-	// admins et redacteurs peuvent voir un auteur
892
-	if ($type === 'auteur') {
893
-		return in_array($qui['statut'], ['0minirezo', '1comite']);
894
-	}
895
-	// sinon par defaut tout est visible
896
-	// sauf cas particuliers traites separemment (ie article)
897
-	return true;
888
+    if ($qui['statut'] === '0minirezo') {
889
+        return true;
890
+    }
891
+    // admins et redacteurs peuvent voir un auteur
892
+    if ($type === 'auteur') {
893
+        return in_array($qui['statut'], ['0minirezo', '1comite']);
894
+    }
895
+    // sinon par defaut tout est visible
896
+    // sauf cas particuliers traites separemment (ie article)
897
+    return true;
898 898
 }
899 899
 
900 900
 
@@ -917,12 +917,12 @@  discard block
 block discarded – undo
917 917
  * @return bool true s'il a le droit, false sinon
918 918
  **/
919 919
 function autoriser_webmestre_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
920
-	return
921
-		(defined('_ID_WEBMESTRES') ?
922
-			in_array($qui['id_auteur'], explode(':', _ID_WEBMESTRES))
923
-			: $qui['webmestre'] === 'oui')
924
-		and $qui['statut'] === '0minirezo'
925
-		and !$qui['restreint'];
920
+    return
921
+        (defined('_ID_WEBMESTRES') ?
922
+            in_array($qui['id_auteur'], explode(':', _ID_WEBMESTRES))
923
+            : $qui['webmestre'] === 'oui')
924
+        and $qui['statut'] === '0minirezo'
925
+        and !$qui['restreint'];
926 926
 }
927 927
 
928 928
 /**
@@ -940,9 +940,9 @@  discard block
 block discarded – undo
940 940
  * @return bool true s'il a le droit, false sinon
941 941
  **/
942 942
 function autoriser_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
943
-	return
944
-		$qui['statut'] === '0minirezo'
945
-		and !$qui['restreint'];
943
+    return
944
+        $qui['statut'] === '0minirezo'
945
+        and !$qui['restreint'];
946 946
 }
947 947
 
948 948
 /**
@@ -960,8 +960,8 @@  discard block
 block discarded – undo
960 960
  * @return bool true s'il a le droit, false sinon
961 961
  **/
962 962
 function autoriser_sauvegarder_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
963
-	return
964
-		$qui['statut'] === '0minirezo';
963
+    return
964
+        $qui['statut'] === '0minirezo';
965 965
 }
966 966
 
967 967
 /**
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
  * @return bool true s'il a le droit, false sinon
980 980
  **/
981 981
 function autoriser_detruire_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
982
-	return autoriser('webmestre', null, 0, $qui, $opt);
982
+    return autoriser('webmestre', null, 0, $qui, $opt);
983 983
 }
984 984
 
985 985
 /**
@@ -998,23 +998,23 @@  discard block
 block discarded – undo
998 998
  * @return bool true s'il a le droit, false sinon
999 999
  **/
1000 1000
 function autoriser_auteur_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1001
-	// les admins peuvent "previsualiser" une page auteur
1002
-	if (
1003
-		$qui['statut'] === '0minirezo'
1004
-		and !$qui['restreint']
1005
-	) {
1006
-		return true;
1007
-	} elseif ($id === 0) {
1008
-		return false;
1009
-	}
1010
-	// "Voir en ligne" si l'auteur a un article publie
1011
-	$n = sql_fetsel(
1012
-		'A.id_article',
1013
-		'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)',
1014
-		"A.statut='publie' AND L.id_auteur=" . sql_quote($id)
1015
-	);
1001
+    // les admins peuvent "previsualiser" une page auteur
1002
+    if (
1003
+        $qui['statut'] === '0minirezo'
1004
+        and !$qui['restreint']
1005
+    ) {
1006
+        return true;
1007
+    } elseif ($id === 0) {
1008
+        return false;
1009
+    }
1010
+    // "Voir en ligne" si l'auteur a un article publie
1011
+    $n = sql_fetsel(
1012
+        'A.id_article',
1013
+        'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)',
1014
+        "A.statut='publie' AND L.id_auteur=" . sql_quote($id)
1015
+    );
1016 1016
 
1017
-	return $n ? true : false;
1017
+    return $n ? true : false;
1018 1018
 }
1019 1019
 
1020 1020
 
@@ -1043,7 +1043,7 @@  discard block
 block discarded – undo
1043 1043
  * @return bool true s'il a le droit, false sinon
1044 1044
  **/
1045 1045
 function autoriser_auteur_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1046
-	return ($qui['statut'] === '0minirezo');
1046
+    return ($qui['statut'] === '0minirezo');
1047 1047
 }
1048 1048
 
1049 1049
 
@@ -1064,75 +1064,75 @@  discard block
 block discarded – undo
1064 1064
  * @return bool true s'il a le droit, false sinon
1065 1065
  **/
1066 1066
 function autoriser_auteur_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1067
-	$id = intval($id);
1068
-
1069
-	// Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login
1070
-	// la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca
1071
-	if (!in_array($qui['statut'], ['0minirezo'])) {
1072
-		if (
1073
-			$id == $qui['id_auteur']
1074
-			&& empty($opt['statut'])
1075
-			&& empty($opt['webmestre'])
1076
-			&& empty($opt['restreintes'])
1077
-			&& empty($opt['login'])
1078
-		) {
1079
-			return true;
1080
-		}
1081
-		return false;
1082
-	}
1083
-
1084
-	// Un admin restreint peut modifier/creer un auteur non-admin mais il
1085
-	// n'a le droit ni de le promouvoir admin, ni de changer les rubriques
1086
-	if ($qui['restreint']) {
1087
-		if (isset($opt['webmestre']) and $opt['webmestre']) {
1088
-			return false;
1089
-		} elseif (
1090
-			(isset($opt['statut']) and ($opt['statut'] === '0minirezo'))
1091
-			or (isset($opt['restreintes']) and $opt['restreintes'])
1092
-		) {
1093
-			return false;
1094
-		} else {
1095
-			if ($id == $qui['id_auteur']) {
1096
-				if (isset($opt['statut']) and $opt['statut']) {
1097
-					return false;
1098
-				} else {
1099
-					return true;
1100
-				}
1101
-			} else {
1102
-				if ($id_auteur = intval($id)) {
1103
-					$t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur");
1104
-					if ($t and $t['statut'] != '0minirezo') {
1105
-						return true;
1106
-					} else {
1107
-						return false;
1108
-					}
1109
-				} // id = 0 => creation
1110
-				else {
1111
-					return true;
1112
-				}
1113
-			}
1114
-		}
1115
-	}
1116
-
1117
-	// Un admin complet fait ce qu'il veut
1118
-	// sauf se degrader
1119
-	if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) {
1120
-		return false;
1121
-	} elseif (
1122
-		isset($opt['webmestre'])
1123
-				and $opt['webmestre']
1124
-				and (defined('_ID_WEBMESTRES')
1125
-				or !autoriser('webmestre'))
1126
-	) {
1127
-		// et toucher au statut webmestre si il ne l'est pas lui meme
1128
-		// ou si les webmestres sont fixes par constante (securite)
1129
-		return false;
1130
-	} // et modifier un webmestre si il ne l'est pas lui meme
1131
-	elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) {
1132
-		return false;
1133
-	} else {
1134
-		return true;
1135
-	}
1067
+    $id = intval($id);
1068
+
1069
+    // Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login
1070
+    // la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca
1071
+    if (!in_array($qui['statut'], ['0minirezo'])) {
1072
+        if (
1073
+            $id == $qui['id_auteur']
1074
+            && empty($opt['statut'])
1075
+            && empty($opt['webmestre'])
1076
+            && empty($opt['restreintes'])
1077
+            && empty($opt['login'])
1078
+        ) {
1079
+            return true;
1080
+        }
1081
+        return false;
1082
+    }
1083
+
1084
+    // Un admin restreint peut modifier/creer un auteur non-admin mais il
1085
+    // n'a le droit ni de le promouvoir admin, ni de changer les rubriques
1086
+    if ($qui['restreint']) {
1087
+        if (isset($opt['webmestre']) and $opt['webmestre']) {
1088
+            return false;
1089
+        } elseif (
1090
+            (isset($opt['statut']) and ($opt['statut'] === '0minirezo'))
1091
+            or (isset($opt['restreintes']) and $opt['restreintes'])
1092
+        ) {
1093
+            return false;
1094
+        } else {
1095
+            if ($id == $qui['id_auteur']) {
1096
+                if (isset($opt['statut']) and $opt['statut']) {
1097
+                    return false;
1098
+                } else {
1099
+                    return true;
1100
+                }
1101
+            } else {
1102
+                if ($id_auteur = intval($id)) {
1103
+                    $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur");
1104
+                    if ($t and $t['statut'] != '0minirezo') {
1105
+                        return true;
1106
+                    } else {
1107
+                        return false;
1108
+                    }
1109
+                } // id = 0 => creation
1110
+                else {
1111
+                    return true;
1112
+                }
1113
+            }
1114
+        }
1115
+    }
1116
+
1117
+    // Un admin complet fait ce qu'il veut
1118
+    // sauf se degrader
1119
+    if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) {
1120
+        return false;
1121
+    } elseif (
1122
+        isset($opt['webmestre'])
1123
+                and $opt['webmestre']
1124
+                and (defined('_ID_WEBMESTRES')
1125
+                or !autoriser('webmestre'))
1126
+    ) {
1127
+        // et toucher au statut webmestre si il ne l'est pas lui meme
1128
+        // ou si les webmestres sont fixes par constante (securite)
1129
+        return false;
1130
+    } // et modifier un webmestre si il ne l'est pas lui meme
1131
+    elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) {
1132
+        return false;
1133
+    } else {
1134
+        return true;
1135
+    }
1136 1136
 }
1137 1137
 
1138 1138
 
@@ -1151,7 +1151,7 @@  discard block
 block discarded – undo
1151 1151
  * @return bool true s'il a le droit, false sinon
1152 1152
  **/
1153 1153
 function autoriser_associerauteurs_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1154
-	return autoriser('modifier', $type, $id, $qui, $opt);
1154
+    return autoriser('modifier', $type, $id, $qui, $opt);
1155 1155
 }
1156 1156
 
1157 1157
 
@@ -1170,7 +1170,7 @@  discard block
 block discarded – undo
1170 1170
  * @return bool true s'il a le droit, false sinon
1171 1171
  **/
1172 1172
 function autoriser_chargerftp_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1173
-	return $qui['statut'] === '0minirezo';
1173
+    return $qui['statut'] === '0minirezo';
1174 1174
 }
1175 1175
 
1176 1176
 /**
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
  * @return bool true s'il a le droit, false sinon
1189 1189
  **/
1190 1190
 function autoriser_debug_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1191
-	return $qui['statut'] === '0minirezo';
1191
+    return $qui['statut'] === '0minirezo';
1192 1192
 }
1193 1193
 
1194 1194
 /**
@@ -1205,54 +1205,54 @@  discard block
 block discarded – undo
1205 1205
  * @return array          Liste des rubriques
1206 1206
  **/
1207 1207
 function liste_rubriques_auteur($id_auteur, $raz = false) {
1208
-	static $restreint = [];
1209
-
1210
-	if (!$id_auteur = intval($id_auteur)) {
1211
-		return [];
1212
-	}
1213
-	if ($raz) {
1214
-		unset($restreint[$id_auteur]);
1215
-	} elseif (isset($restreint[$id_auteur])) {
1216
-		return $restreint[$id_auteur];
1217
-	}
1218
-
1219
-	$rubriques = [];
1220
-	if (
1221
-		(!isset($GLOBALS['meta']['version_installee'])
1222
-		or $GLOBALS['meta']['version_installee'] > 16428)
1223
-		and $r = sql_allfetsel(
1224
-			'id_objet',
1225
-			'spip_auteurs_liens',
1226
-			'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0"
1227
-		)
1228
-		and is_countable($r) ? count($r) : 0
1229
-	) {
1230
-		$r = array_column($r, 'id_objet');
1231
-
1232
-		// recuperer toute la branche, au format chaine enumeration
1233
-		include_spip('inc/rubriques');
1234
-		$r = calcul_branche_in($r);
1235
-		$r = explode(',', $r);
1236
-
1237
-		// passer les rubriques en index, elimine les doublons
1238
-		$r = array_flip($r);
1239
-		// recuperer les index seuls
1240
-		$r = array_keys($r);
1241
-		// combiner pour avoir un tableau id_rubrique=>id_rubrique
1242
-		// est-ce vraiment utile ? (on preserve la forme donnee par le code precedent)
1243
-		$rubriques = array_combine($r, $r);
1244
-	}
1245
-
1246
-	// Affecter l'auteur session le cas echeant
1247
-	if (
1248
-		isset($GLOBALS['visiteur_session']['id_auteur'])
1249
-		and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur
1250
-	) {
1251
-		$GLOBALS['visiteur_session']['restreint'] = $rubriques;
1252
-	}
1253
-
1254
-
1255
-	return $restreint[$id_auteur] = $rubriques;
1208
+    static $restreint = [];
1209
+
1210
+    if (!$id_auteur = intval($id_auteur)) {
1211
+        return [];
1212
+    }
1213
+    if ($raz) {
1214
+        unset($restreint[$id_auteur]);
1215
+    } elseif (isset($restreint[$id_auteur])) {
1216
+        return $restreint[$id_auteur];
1217
+    }
1218
+
1219
+    $rubriques = [];
1220
+    if (
1221
+        (!isset($GLOBALS['meta']['version_installee'])
1222
+        or $GLOBALS['meta']['version_installee'] > 16428)
1223
+        and $r = sql_allfetsel(
1224
+            'id_objet',
1225
+            'spip_auteurs_liens',
1226
+            'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0"
1227
+        )
1228
+        and is_countable($r) ? count($r) : 0
1229
+    ) {
1230
+        $r = array_column($r, 'id_objet');
1231
+
1232
+        // recuperer toute la branche, au format chaine enumeration
1233
+        include_spip('inc/rubriques');
1234
+        $r = calcul_branche_in($r);
1235
+        $r = explode(',', $r);
1236
+
1237
+        // passer les rubriques en index, elimine les doublons
1238
+        $r = array_flip($r);
1239
+        // recuperer les index seuls
1240
+        $r = array_keys($r);
1241
+        // combiner pour avoir un tableau id_rubrique=>id_rubrique
1242
+        // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent)
1243
+        $rubriques = array_combine($r, $r);
1244
+    }
1245
+
1246
+    // Affecter l'auteur session le cas echeant
1247
+    if (
1248
+        isset($GLOBALS['visiteur_session']['id_auteur'])
1249
+        and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur
1250
+    ) {
1251
+        $GLOBALS['visiteur_session']['restreint'] = $rubriques;
1252
+    }
1253
+
1254
+
1255
+    return $restreint[$id_auteur] = $rubriques;
1256 1256
 }
1257 1257
 
1258 1258
 /**
@@ -1270,7 +1270,7 @@  discard block
 block discarded – undo
1270 1270
  * @return bool true s'il a le droit, false sinon
1271 1271
  **/
1272 1272
 function autoriser_rubrique_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1273
-	return autoriser('previsualiser');
1273
+    return autoriser('previsualiser');
1274 1274
 }
1275 1275
 
1276 1276
 /**
@@ -1288,7 +1288,7 @@  discard block
 block discarded – undo
1288 1288
  * @return bool true s'il a le droit, false sinon
1289 1289
  **/
1290 1290
 function autoriser_rubrique_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1291
-	return autoriser('publierdans', 'rubrique', $id, $qui, $opt);
1291
+    return autoriser('publierdans', 'rubrique', $id, $qui, $opt);
1292 1292
 }
1293 1293
 
1294 1294
 /**
@@ -1306,9 +1306,9 @@  discard block
 block discarded – undo
1306 1306
  * @return bool true s'il a le droit, false sinon
1307 1307
  **/
1308 1308
 function autoriser_auteur_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1309
-	$id = intval($id);
1310
-	return (($id == $qui['id_auteur']) or
1311
-		(($qui['statut'] === '0minirezo') and !$qui['restreint']));
1309
+    $id = intval($id);
1310
+    return (($id == $qui['id_auteur']) or
1311
+        (($qui['statut'] === '0minirezo') and !$qui['restreint']));
1312 1312
 }
1313 1313
 
1314 1314
 /**
@@ -1326,8 +1326,8 @@  discard block
 block discarded – undo
1326 1326
  * @return bool true s'il a le droit, false sinon
1327 1327
  **/
1328 1328
 function autoriser_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1329
-	// par defaut, on a le droit d'iconifier si on a le droit de modifier
1330
-	return autoriser('modifier', $type, $id, $qui, $opt);
1329
+    // par defaut, on a le droit d'iconifier si on a le droit de modifier
1330
+    return autoriser('modifier', $type, $id, $qui, $opt);
1331 1331
 }
1332 1332
 
1333 1333
 
@@ -1347,7 +1347,7 @@  discard block
 block discarded – undo
1347 1347
  * @return true
1348 1348
  **/
1349 1349
 function autoriser_ok_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1350
-	return true;
1350
+    return true;
1351 1351
 }
1352 1352
 
1353 1353
 /**
@@ -1366,7 +1366,7 @@  discard block
 block discarded – undo
1366 1366
  * @return false
1367 1367
  **/
1368 1368
 function autoriser_niet_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1369
-	return false;
1369
+    return false;
1370 1370
 }
1371 1371
 
1372 1372
 /**
@@ -1384,11 +1384,11 @@  discard block
 block discarded – undo
1384 1384
  * @return bool true s'il a le droit, false sinon
1385 1385
  **/
1386 1386
 function autoriser_base_reparer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1387
-	if (!autoriser('detruire') or _request('reinstall')) {
1388
-		return false;
1389
-	}
1387
+    if (!autoriser('detruire') or _request('reinstall')) {
1388
+        return false;
1389
+    }
1390 1390
 
1391
-	return true;
1391
+    return true;
1392 1392
 }
1393 1393
 
1394 1394
 /**
@@ -1406,7 +1406,7 @@  discard block
 block discarded – undo
1406 1406
  * @return true
1407 1407
  **/
1408 1408
 function autoriser_infosperso_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1409
-	return true;
1409
+    return true;
1410 1410
 }
1411 1411
 
1412 1412
 /**
@@ -1424,7 +1424,7 @@  discard block
 block discarded – undo
1424 1424
  * @return true
1425 1425
  **/
1426 1426
 function autoriser_langage_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1427
-	return true;
1427
+    return true;
1428 1428
 }
1429 1429
 
1430 1430
 /**
@@ -1442,7 +1442,7 @@  discard block
 block discarded – undo
1442 1442
  * @return bool true s'il a le droit, false sinon
1443 1443
  **/
1444 1444
 function autoriser_configurerlangage_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1445
-	return autoriser('configurer', '_langage', $id, $qui, $opt);
1445
+    return autoriser('configurer', '_langage', $id, $qui, $opt);
1446 1446
 }
1447 1447
 
1448 1448
 /**
@@ -1460,7 +1460,7 @@  discard block
 block discarded – undo
1460 1460
  * @return true
1461 1461
  **/
1462 1462
 function autoriser_preferences_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1463
-	return true;
1463
+    return true;
1464 1464
 }
1465 1465
 
1466 1466
 /**
@@ -1478,7 +1478,7 @@  discard block
 block discarded – undo
1478 1478
  * @return bool true s'il a le droit, false sinon
1479 1479
  **/
1480 1480
 function autoriser_configurerpreferences_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1481
-	return autoriser('configurer', '_preferences', $id, $qui, $opt);
1481
+    return autoriser('configurer', '_preferences', $id, $qui, $opt);
1482 1482
 }
1483 1483
 
1484 1484
 /**
@@ -1496,8 +1496,8 @@  discard block
 block discarded – undo
1496 1496
  * @return bool true s'il a le droit, false sinon
1497 1497
  **/
1498 1498
 function autoriser_menudeveloppement_menugrandeentree_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1499
-	return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev'])
1500
-		and $GLOBALS['visiteur_session']['prefs']['activer_menudev'] === 'oui');
1499
+    return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev'])
1500
+        and $GLOBALS['visiteur_session']['prefs']['activer_menudev'] === 'oui');
1501 1501
 }
1502 1502
 
1503 1503
 /**
@@ -1516,7 +1516,7 @@  discard block
 block discarded – undo
1516 1516
  * @return true
1517 1517
  **/
1518 1518
 function autoriser_menugrandeentree_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1519
-	return true;
1519
+    return true;
1520 1520
 }
1521 1521
 
1522 1522
 /**
@@ -1534,7 +1534,7 @@  discard block
 block discarded – undo
1534 1534
  * @return true
1535 1535
  **/
1536 1536
 function autoriser_auteurs_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1537
-	return true;
1537
+    return true;
1538 1538
 }
1539 1539
 
1540 1540
 /**
@@ -1552,7 +1552,7 @@  discard block
 block discarded – undo
1552 1552
  * @return bool true s'il a le droit, false sinon
1553 1553
  **/
1554 1554
 function autoriser_auteurs_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1555
-	return autoriser('voir', '_auteurs', $id, $qui, $opt);
1555
+    return autoriser('voir', '_auteurs', $id, $qui, $opt);
1556 1556
 }
1557 1557
 
1558 1558
 /**
@@ -1570,7 +1570,7 @@  discard block
 block discarded – undo
1570 1570
  * @return true
1571 1571
  **/
1572 1572
 function autoriser_articles_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1573
-	return true;
1573
+    return true;
1574 1574
 }
1575 1575
 
1576 1576
 /**
@@ -1588,7 +1588,7 @@  discard block
 block discarded – undo
1588 1588
  * @return bool true s'il a le droit, false sinon
1589 1589
  **/
1590 1590
 function autoriser_articles_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1591
-	return autoriser('voir', '_articles', $id, $qui, $opt);
1591
+    return autoriser('voir', '_articles', $id, $qui, $opt);
1592 1592
 }
1593 1593
 
1594 1594
 /**
@@ -1606,7 +1606,7 @@  discard block
 block discarded – undo
1606 1606
  * @return true
1607 1607
  **/
1608 1608
 function autoriser_rubriques_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1609
-	return true;
1609
+    return true;
1610 1610
 }
1611 1611
 
1612 1612
 /**
@@ -1624,7 +1624,7 @@  discard block
 block discarded – undo
1624 1624
  * @return bool true s'il a le droit, false sinon
1625 1625
  **/
1626 1626
 function autoriser_rubriques_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1627
-	return autoriser('voir', '_rubriques', $id, $qui, $opt);
1627
+    return autoriser('voir', '_rubriques', $id, $qui, $opt);
1628 1628
 }
1629 1629
 
1630 1630
 /**
@@ -1642,7 +1642,7 @@  discard block
 block discarded – undo
1642 1642
  * @return bool true s'il a le droit, false sinon
1643 1643
  **/
1644 1644
 function autoriser_articlecreer_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1645
-	return verifier_table_non_vide();
1645
+    return verifier_table_non_vide();
1646 1646
 }
1647 1647
 
1648 1648
 
@@ -1663,7 +1663,7 @@  discard block
 block discarded – undo
1663 1663
  * @return bool true s'il a le droit, false sinon
1664 1664
  **/
1665 1665
 function autoriser_auteurcreer_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1666
-	return autoriser('creer', 'auteur', $id, $qui, $opt);
1666
+    return autoriser('creer', 'auteur', $id, $qui, $opt);
1667 1667
 }
1668 1668
 
1669 1669
 /**
@@ -1681,13 +1681,13 @@  discard block
 block discarded – undo
1681 1681
  * @return bool true s'il a le droit, false sinon
1682 1682
  **/
1683 1683
 function autoriser_visiteurs_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1684
-	include_spip('base/abstract_sql');
1685
-	return
1686
-		$qui['statut'] === '0minirezo' and !$qui['restreint']
1687
-		and (
1688
-			$GLOBALS['meta']['accepter_visiteurs'] != 'non'
1689
-			or sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0
1690
-		);
1684
+    include_spip('base/abstract_sql');
1685
+    return
1686
+        $qui['statut'] === '0minirezo' and !$qui['restreint']
1687
+        and (
1688
+            $GLOBALS['meta']['accepter_visiteurs'] != 'non'
1689
+            or sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0
1690
+        );
1691 1691
 }
1692 1692
 
1693 1693
 /**
@@ -1705,7 +1705,7 @@  discard block
 block discarded – undo
1705 1705
  * @return bool true s'il a le droit, false sinon
1706 1706
  **/
1707 1707
 function autoriser_suiviedito_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1708
-	return $qui['statut'] === '0minirezo';
1708
+    return $qui['statut'] === '0minirezo';
1709 1709
 }
1710 1710
 
1711 1711
 /**
@@ -1723,7 +1723,7 @@  discard block
 block discarded – undo
1723 1723
  * @return bool true s'il a le droit, false sinon
1724 1724
  **/
1725 1725
 function autoriser_synchro_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1726
-	return $qui['statut'] === '0minirezo';
1726
+    return $qui['statut'] === '0minirezo';
1727 1727
 }
1728 1728
 
1729 1729
 /**
@@ -1741,7 +1741,7 @@  discard block
 block discarded – undo
1741 1741
  * @return bool true s'il a le droit, false sinon
1742 1742
  **/
1743 1743
 function autoriser_configurerinteractions_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1744
-	return autoriser('configurer', '_interactions', $id, $qui, $opt);
1744
+    return autoriser('configurer', '_interactions', $id, $qui, $opt);
1745 1745
 }
1746 1746
 
1747 1747
 /**
@@ -1759,7 +1759,7 @@  discard block
 block discarded – undo
1759 1759
  * @return bool true s'il a le droit, false sinon
1760 1760
  **/
1761 1761
 function autoriser_configurerlangue_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1762
-	return autoriser('configurer', '_langue', $id, $qui, $opt);
1762
+    return autoriser('configurer', '_langue', $id, $qui, $opt);
1763 1763
 }
1764 1764
 
1765 1765
 /**
@@ -1777,7 +1777,7 @@  discard block
 block discarded – undo
1777 1777
  * @return bool true s'il a le droit, false sinon
1778 1778
  **/
1779 1779
 function autoriser_configurermultilinguisme_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1780
-	return autoriser('configurer', '_multilinguisme', $id, $qui, $opt);
1780
+    return autoriser('configurer', '_multilinguisme', $id, $qui, $opt);
1781 1781
 }
1782 1782
 
1783 1783
 /**
@@ -1795,7 +1795,7 @@  discard block
 block discarded – undo
1795 1795
  * @return bool true s'il a le droit, false sinon
1796 1796
  **/
1797 1797
 function autoriser_configurercontenu_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1798
-	return autoriser('configurer', '_contenu', $id, $qui, $opt);
1798
+    return autoriser('configurer', '_contenu', $id, $qui, $opt);
1799 1799
 }
1800 1800
 
1801 1801
 /**
@@ -1813,7 +1813,7 @@  discard block
 block discarded – undo
1813 1813
  * @return bool true s'il a le droit, false sinon
1814 1814
  **/
1815 1815
 function autoriser_configureravancees_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1816
-	return autoriser('configurer', '_avancees', $id, $qui, $opt);
1816
+    return autoriser('configurer', '_avancees', $id, $qui, $opt);
1817 1817
 }
1818 1818
 
1819 1819
 /**
@@ -1831,7 +1831,7 @@  discard block
 block discarded – undo
1831 1831
  * @return bool true s'il a le droit, false sinon
1832 1832
  **/
1833 1833
 function autoriser_adminplugin_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1834
-	return autoriser('configurer', '_plugins', $id, $qui, $opt);
1834
+    return autoriser('configurer', '_plugins', $id, $qui, $opt);
1835 1835
 }
1836 1836
 
1837 1837
 /**
@@ -1849,7 +1849,7 @@  discard block
 block discarded – undo
1849 1849
  * @return bool true s'il a le droit, false sinon
1850 1850
  **/
1851 1851
 function autoriser_admintech_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1852
-	return autoriser('detruire', $type, $id, $qui, $opt);
1852
+    return autoriser('detruire', $type, $id, $qui, $opt);
1853 1853
 }
1854 1854
 
1855 1855
 /**
@@ -1867,7 +1867,7 @@  discard block
 block discarded – undo
1867 1867
  * @return bool true s'il a le droit, false sinon
1868 1868
  **/
1869 1869
 function autoriser_queue_purger_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1870
-	return autoriser('webmestre');
1870
+    return autoriser('webmestre');
1871 1871
 }
1872 1872
 
1873 1873
 
@@ -1887,11 +1887,11 @@  discard block
 block discarded – undo
1887 1887
  * @return bool true s'il a le droit, false sinon
1888 1888
  **/
1889 1889
 function autoriser_echafauder_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
1890
-	if (test_espace_prive()) {
1891
-		return intval($qui['id_auteur']) ? true : false;
1892
-	} else {
1893
-		return autoriser('webmestre', '', $id, $qui, $opt);
1894
-	}
1890
+    if (test_espace_prive()) {
1891
+        return intval($qui['id_auteur']) ? true : false;
1892
+    } else {
1893
+        return autoriser('webmestre', '', $id, $qui, $opt);
1894
+    }
1895 1895
 }
1896 1896
 
1897 1897
 
@@ -1906,27 +1906,27 @@  discard block
 block discarded – undo
1906 1906
  *     Identifiants d'auteurs
1907 1907
  */
1908 1908
 function auteurs_objet($objet, $id_objet, $cond = '') {
1909
-	$objet = objet_type($objet);
1910
-	$where = [
1911
-		'objet=' . sql_quote($objet),
1912
-		'id_objet=' . intval($id_objet)
1913
-	];
1914
-	if (!empty($cond)) {
1915
-		if (is_array($cond)) {
1916
-			$where = array_merge($where, $cond);
1917
-		} else {
1918
-			$where[] = $cond;
1919
-		}
1920
-	}
1921
-	$auteurs = sql_allfetsel(
1922
-		'id_auteur',
1923
-		'spip_auteurs_liens',
1924
-		$where
1925
-	);
1926
-	if (is_array($auteurs)) {
1927
-		return array_column($auteurs, 'id_auteur');
1928
-	}
1929
-	return [];
1909
+    $objet = objet_type($objet);
1910
+    $where = [
1911
+        'objet=' . sql_quote($objet),
1912
+        'id_objet=' . intval($id_objet)
1913
+    ];
1914
+    if (!empty($cond)) {
1915
+        if (is_array($cond)) {
1916
+            $where = array_merge($where, $cond);
1917
+        } else {
1918
+            $where[] = $cond;
1919
+        }
1920
+    }
1921
+    $auteurs = sql_allfetsel(
1922
+        'id_auteur',
1923
+        'spip_auteurs_liens',
1924
+        $where
1925
+    );
1926
+    if (is_array($auteurs)) {
1927
+        return array_column($auteurs, 'id_auteur');
1928
+    }
1929
+    return [];
1930 1930
 }
1931 1931
 
1932 1932
 /**
@@ -1941,11 +1941,11 @@  discard block
 block discarded – undo
1941 1941
  *     - false : serveur SQL indisponible
1942 1942
  */
1943 1943
 function auteurs_article($id_article, $cond = '') {
1944
-	return sql_allfetsel(
1945
-		'id_auteur',
1946
-		'spip_auteurs_liens',
1947
-		"objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '')
1948
-	);
1944
+    return sql_allfetsel(
1945
+        'id_auteur',
1946
+        'spip_auteurs_liens',
1947
+        "objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '')
1948
+    );
1949 1949
 }
1950 1950
 
1951 1951
 
@@ -1959,7 +1959,7 @@  discard block
 block discarded – undo
1959 1959
  */
1960 1960
 function acces_restreint_rubrique($id_rubrique) {
1961 1961
 
1962
-	return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique]));
1962
+    return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique]));
1963 1963
 }
1964 1964
 
1965 1965
 
@@ -1972,12 +1972,12 @@  discard block
 block discarded – undo
1972 1972
  * @return bool             true si un parent existe
1973 1973
  */
1974 1974
 function verifier_table_non_vide($table = 'spip_rubriques') {
1975
-	static $done = [];
1976
-	if (!isset($done[$table])) {
1977
-		$done[$table] = sql_countsel($table) > 0;
1978
-	}
1975
+    static $done = [];
1976
+    if (!isset($done[$table])) {
1977
+        $done[$table] = sql_countsel($table) > 0;
1978
+    }
1979 1979
 
1980
-	return $done[$table];
1980
+    return $done[$table];
1981 1981
 }
1982 1982
 
1983 1983
 /**
@@ -2004,15 +2004,15 @@  discard block
 block discarded – undo
2004 2004
  */
2005 2005
 function autoriser_inscrireauteur_dist($faire, $quoi, $id, $qui, $opt) {
2006 2006
 
2007
-	$s = array_search($quoi, $GLOBALS['liste_des_statuts']);
2008
-	switch ($s) {
2009
-		case 'info_redacteurs':
2010
-			return ($GLOBALS['meta']['accepter_inscriptions'] === 'oui');
2011
-		case 'info_visiteurs':
2012
-			return ($GLOBALS['meta']['accepter_visiteurs'] === 'oui' or $GLOBALS['meta']['forums_publics'] === 'abo');
2013
-	}
2007
+    $s = array_search($quoi, $GLOBALS['liste_des_statuts']);
2008
+    switch ($s) {
2009
+        case 'info_redacteurs':
2010
+            return ($GLOBALS['meta']['accepter_inscriptions'] === 'oui');
2011
+        case 'info_visiteurs':
2012
+            return ($GLOBALS['meta']['accepter_visiteurs'] === 'oui' or $GLOBALS['meta']['forums_publics'] === 'abo');
2013
+    }
2014 2014
 
2015
-	return false;
2015
+    return false;
2016 2016
 }
2017 2017
 
2018 2018
 /**
@@ -2030,7 +2030,7 @@  discard block
 block discarded – undo
2030 2030
  * @return bool true s'il a le droit, false sinon
2031 2031
  **/
2032 2032
 function autoriser_inscription_relancer_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
2033
-	return $qui['statut'] === '0minirezo' and !$qui['restreint'];
2033
+    return $qui['statut'] === '0minirezo' and !$qui['restreint'];
2034 2034
 }
2035 2035
 
2036 2036
 /**
@@ -2048,5 +2048,5 @@  discard block
 block discarded – undo
2048 2048
  * @return bool true s'il a le droit, false sinon
2049 2049
  **/
2050 2050
 function autoriser_phpinfos_dist(string $faire, string $type, $id, array $qui, array $opt): bool {
2051
-	return autoriser('webmestre');
2051
+    return autoriser('webmestre');
2052 2052
 }
Please login to merge, or discard this patch.
ecrire/balise/formulaire_.php 1 patch
Indentation   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Formulaires
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/filtres');
@@ -35,22 +35,22 @@  discard block
 block discarded – undo
35 35
  *     Saisie protégée
36 36
  **/
37 37
 function protege_champ($texte) {
38
-	if (is_array($texte)) {
39
-		return array_map('protege_champ', $texte);
40
-	} elseif ($texte === null) {
41
-		return $texte;
42
-	} elseif (is_bool($texte)) {
43
-		return $texte ? '1' : '';
44
-	} elseif (is_string($texte) and $texte) {
45
-		if (preg_match(',^[abis]:\d+[:;],', $texte) and @unserialize($texte) !== false) {
46
-			// ne pas corrompre une valeur serialize
47
-			return $texte;
48
-		} elseif (strpbrk($texte, "&\"'<>") !== false) {
49
-			return spip_htmlspecialchars($texte, ENT_QUOTES);
50
-		}
51
-	}
52
-
53
-	return $texte;
38
+    if (is_array($texte)) {
39
+        return array_map('protege_champ', $texte);
40
+    } elseif ($texte === null) {
41
+        return $texte;
42
+    } elseif (is_bool($texte)) {
43
+        return $texte ? '1' : '';
44
+    } elseif (is_string($texte) and $texte) {
45
+        if (preg_match(',^[abis]:\d+[:;],', $texte) and @unserialize($texte) !== false) {
46
+            // ne pas corrompre une valeur serialize
47
+            return $texte;
48
+        } elseif (strpbrk($texte, "&\"'<>") !== false) {
49
+            return spip_htmlspecialchars($texte, ENT_QUOTES);
50
+        }
51
+    }
52
+
53
+    return $texte;
54 54
 }
55 55
 
56 56
 /**
@@ -64,17 +64,17 @@  discard block
 block discarded – undo
64 64
  *     - false : pas de squelette trouvé
65 65
  **/
66 66
 function existe_formulaire($form) {
67
-	if (substr($form, 0, 11) == 'FORMULAIRE_') {
68
-		$form = strtolower(substr($form, 11));
69
-	} else {
70
-		$form = strtolower($form);
71
-	}
67
+    if (substr($form, 0, 11) == 'FORMULAIRE_') {
68
+        $form = strtolower(substr($form, 11));
69
+    } else {
70
+        $form = strtolower($form);
71
+    }
72 72
 
73
-	if (!$form) {
74
-		return '';
75
-	} // on ne sait pas, le nom du formulaire n'est pas fourni ici
73
+    if (!$form) {
74
+        return '';
75
+    } // on ne sait pas, le nom du formulaire n'est pas fourni ici
76 76
 
77
-	return trouver_fond($form, 'formulaires/') ? $form : false;
77
+    return trouver_fond($form, 'formulaires/') ? $form : false;
78 78
 }
79 79
 
80 80
 /**
@@ -83,31 +83,31 @@  discard block
 block discarded – undo
83 83
  * @return false|array
84 84
  */
85 85
 function test_formulaire_inclus_par_modele() {
86
-	$trace = debug_backtrace(0, 20);
87
-	$trace_fonctions = array_column($trace, 'function');
88
-	$trace_fonctions = array_map('strtolower', $trace_fonctions);
89
-
90
-	// regarder si un flag a ete leve juste avant l'appel de balise_FORMULAIRE_dyn
91
-	if (
92
-		function_exists('arguments_balise_dyn_depuis_modele')
93
-		and $form = arguments_balise_dyn_depuis_modele(null, 'read')
94
-	) {
95
-		if (in_array('balise_formulaire__dyn', $trace_fonctions)) {
96
-			$k = array_search('balise_formulaire__dyn', $trace_fonctions);
97
-			if ($trace[$k]['args'][0] === $form) {
98
-				return $trace[$k]['args'];
99
-			}
100
-		}
101
-	}
102
-
103
-	// fallback qui ne repose pas sur le flag lie a l'analyse de contexte_compil,
104
-	// mais ne marche pas si executer_balise_dynamique est appelee via du php dans le squelette
105
-	if (in_array('eval', $trace_fonctions) and in_array('inclure_modele', $trace_fonctions)) {
106
-		$k = array_search('inclure_modele', $trace_fonctions);
107
-		// les arguments de recuperer_fond() passes par inclure_modele()
108
-		return $trace[$k - 1]['args'][1]['args'];
109
-	}
110
-	return false;
86
+    $trace = debug_backtrace(0, 20);
87
+    $trace_fonctions = array_column($trace, 'function');
88
+    $trace_fonctions = array_map('strtolower', $trace_fonctions);
89
+
90
+    // regarder si un flag a ete leve juste avant l'appel de balise_FORMULAIRE_dyn
91
+    if (
92
+        function_exists('arguments_balise_dyn_depuis_modele')
93
+        and $form = arguments_balise_dyn_depuis_modele(null, 'read')
94
+    ) {
95
+        if (in_array('balise_formulaire__dyn', $trace_fonctions)) {
96
+            $k = array_search('balise_formulaire__dyn', $trace_fonctions);
97
+            if ($trace[$k]['args'][0] === $form) {
98
+                return $trace[$k]['args'];
99
+            }
100
+        }
101
+    }
102
+
103
+    // fallback qui ne repose pas sur le flag lie a l'analyse de contexte_compil,
104
+    // mais ne marche pas si executer_balise_dynamique est appelee via du php dans le squelette
105
+    if (in_array('eval', $trace_fonctions) and in_array('inclure_modele', $trace_fonctions)) {
106
+        $k = array_search('inclure_modele', $trace_fonctions);
107
+        // les arguments de recuperer_fond() passes par inclure_modele()
108
+        return $trace[$k - 1]['args'][1]['args'];
109
+    }
110
+    return false;
111 111
 }
112 112
 
113 113
 /**
@@ -122,32 +122,32 @@  discard block
 block discarded – undo
122 122
  **/
123 123
 function balise_FORMULAIRE__dist($p) {
124 124
 
125
-	// Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide.
126
-	// mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer
127
-	if (existe_formulaire($p->nom_champ) === false) {
128
-		$p->code = "''";
129
-		$p->interdire_scripts = false;
130
-
131
-		return $p;
132
-	}
133
-
134
-	// sinon renvoyer un code php dynamique
135
-	$p = calculer_balise_dynamique($p, $p->nom_champ, []);
136
-
137
-	if (
138
-		!test_espace_prive()
139
-		and !empty($p->descr['sourcefile'])
140
-		and $f = $p->descr['sourcefile']
141
-		and basename(dirname($f)) === 'modeles'
142
-	) {
143
-		// un modele est toujours inséré en texte dans son contenant
144
-		// donc si on est dans le public avec un cache on va perdre le dynamisme
145
-		// et on risque de mettre en cache les valeurs pre-remplies du formulaire
146
-		// on injecte donc le PHP qui va appeler la fonction pour generer le formulaire au lieu de directement la fonction
147
-		$p->code = "'<'.'?php echo (" . texte_script($p->code) . "); ?'.'>'";
148
-		// dans l'espace prive on a pas de cache, donc pas de soucis (et un leak serait moins grave)
149
-	}
150
-	return $p;
125
+    // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide.
126
+    // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer
127
+    if (existe_formulaire($p->nom_champ) === false) {
128
+        $p->code = "''";
129
+        $p->interdire_scripts = false;
130
+
131
+        return $p;
132
+    }
133
+
134
+    // sinon renvoyer un code php dynamique
135
+    $p = calculer_balise_dynamique($p, $p->nom_champ, []);
136
+
137
+    if (
138
+        !test_espace_prive()
139
+        and !empty($p->descr['sourcefile'])
140
+        and $f = $p->descr['sourcefile']
141
+        and basename(dirname($f)) === 'modeles'
142
+    ) {
143
+        // un modele est toujours inséré en texte dans son contenant
144
+        // donc si on est dans le public avec un cache on va perdre le dynamisme
145
+        // et on risque de mettre en cache les valeurs pre-remplies du formulaire
146
+        // on injecte donc le PHP qui va appeler la fonction pour generer le formulaire au lieu de directement la fonction
147
+        $p->code = "'<'.'?php echo (" . texte_script($p->code) . "); ?'.'>'";
148
+        // dans l'espace prive on a pas de cache, donc pas de soucis (et un leak serait moins grave)
149
+    }
150
+    return $p;
151 151
 }
152 152
 
153 153
 /**
@@ -167,17 +167,17 @@  discard block
 block discarded – undo
167 167
  *     - string : texte à afficher directement
168 168
  */
169 169
 function balise_FORMULAIRE__dyn($form, ...$args) {
170
-	$form = existe_formulaire($form);
171
-	if (!$form) {
172
-		return '';
173
-	}
170
+    $form = existe_formulaire($form);
171
+    if (!$form) {
172
+        return '';
173
+    }
174 174
 
175
-	$contexte = balise_FORMULAIRE__contexte($form, $args);
176
-	if (!is_array($contexte)) {
177
-		return $contexte;
178
-	}
175
+    $contexte = balise_FORMULAIRE__contexte($form, $args);
176
+    if (!is_array($contexte)) {
177
+        return $contexte;
178
+    }
179 179
 
180
-	return ["formulaires/$form", 3600, $contexte];
180
+    return ["formulaires/$form", 3600, $contexte];
181 181
 }
182 182
 
183 183
 /**
@@ -192,85 +192,85 @@  discard block
 block discarded – undo
192 192
  *     string: Formulaire non applicable (message d’explication)
193 193
  **/
194 194
 function balise_FORMULAIRE__contexte($form, $args) {
195
-	// tester si ce formulaire vient d'etre poste (memes arguments)
196
-	// pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page
197
-	// si poste, on recupere les erreurs
198
-
199
-	$je_suis_poste = false;
200
-	if (
201
-		$post_form = _request('formulaire_action')
202
-		and $post_form == $form
203
-		and $p = _request('formulaire_action_args')
204
-		and is_array($p = decoder_contexte_ajax($p, $post_form))
205
-	) {
206
-		// enlever le faux attribut de langue masque
207
-		array_shift($p);
208
-		if (formulaire__identifier($form, $args, $p)) {
209
-			$je_suis_poste = true;
210
-		}
211
-	}
212
-
213
-	$editable = true;
214
-	$erreurs = $post = [];
215
-	if ($je_suis_poste) {
216
-		$post = traiter_formulaires_dynamiques(true);
217
-		$e = "erreurs_$form";
218
-		$erreurs = $post[$e] ?? [];
219
-		$editable = "editable_$form";
220
-		$editable = (!isset($post[$e]))
221
-			|| (is_countable($erreurs) ? count($erreurs) : 0)
222
-			|| (isset($post[$editable]) && $post[$editable]);
223
-	}
224
-
225
-	$valeurs = formulaire__charger($form, $args, $je_suis_poste);
226
-
227
-	// si $valeurs n'est pas un tableau, le formulaire n'est pas applicable
228
-	// C'est plus fort qu'editable qui est gere par le squelette
229
-	// Idealement $valeur doit etre alors un message explicatif.
230
-	if (!is_array($valeurs)) {
231
-		return is_string($valeurs) ? $valeurs : '';
232
-	}
233
-
234
-	// charger peut passer une action si le formulaire ne tourne pas sur self()
235
-	// ou une action vide si elle ne sert pas
236
-	$action = $valeurs['action'] ?? self('&amp;', true);
237
-	// bug IEx : si action finit par /
238
-	// IE croit que le <form ... action=../ > est autoferme
239
-	if (substr($action, -1) == '/') {
240
-		// on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un /
241
-		$action .= '#';
242
-	}
243
-
244
-	// recuperer la saisie en cours si erreurs
245
-	// seulement si c'est ce formulaire qui est poste
246
-	// ou si on le demande explicitement par le parametre _forcer_request = true
247
-	$dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request']));
248
-	foreach (array_keys($valeurs) as $champ) {
249
-		if ($champ[0] !== '_' and !in_array($champ, ['message_ok', 'message_erreur', 'editable'])) {
250
-			if ($dispo and (($v = _request($champ)) !== null)) {
251
-				$valeurs[$champ] = $v;
252
-			}
253
-			// nettoyer l'url des champs qui vont etre saisis
254
-			if ($action) {
255
-				$action = parametre_url($action, $champ, '');
256
-			}
257
-			// proteger les ' et les " dans les champs que l'on va injecter
258
-			$valeurs[$champ] = protege_champ($valeurs[$champ]);
259
-		}
260
-	}
261
-
262
-	if ($action) {
263
-		// nettoyer l'url
264
-		$action = parametre_url($action, 'formulaire_action', '');
265
-		$action = parametre_url($action, 'formulaire_action_args', '');
266
-		$action = parametre_url($action, 'formulaire_action_sign', '');
267
-	}
268
-
269
-	/**
270
-	 * @deprecated 4.0
271
-	 * servait pour poster sur les actions de type editer_xxx() qui ne prenaient pas d'argument autrement que par _request('arg') et pour lesquelles il fallait donc passer un hash valide
272
-	 */
273
-	/*
195
+    // tester si ce formulaire vient d'etre poste (memes arguments)
196
+    // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page
197
+    // si poste, on recupere les erreurs
198
+
199
+    $je_suis_poste = false;
200
+    if (
201
+        $post_form = _request('formulaire_action')
202
+        and $post_form == $form
203
+        and $p = _request('formulaire_action_args')
204
+        and is_array($p = decoder_contexte_ajax($p, $post_form))
205
+    ) {
206
+        // enlever le faux attribut de langue masque
207
+        array_shift($p);
208
+        if (formulaire__identifier($form, $args, $p)) {
209
+            $je_suis_poste = true;
210
+        }
211
+    }
212
+
213
+    $editable = true;
214
+    $erreurs = $post = [];
215
+    if ($je_suis_poste) {
216
+        $post = traiter_formulaires_dynamiques(true);
217
+        $e = "erreurs_$form";
218
+        $erreurs = $post[$e] ?? [];
219
+        $editable = "editable_$form";
220
+        $editable = (!isset($post[$e]))
221
+            || (is_countable($erreurs) ? count($erreurs) : 0)
222
+            || (isset($post[$editable]) && $post[$editable]);
223
+    }
224
+
225
+    $valeurs = formulaire__charger($form, $args, $je_suis_poste);
226
+
227
+    // si $valeurs n'est pas un tableau, le formulaire n'est pas applicable
228
+    // C'est plus fort qu'editable qui est gere par le squelette
229
+    // Idealement $valeur doit etre alors un message explicatif.
230
+    if (!is_array($valeurs)) {
231
+        return is_string($valeurs) ? $valeurs : '';
232
+    }
233
+
234
+    // charger peut passer une action si le formulaire ne tourne pas sur self()
235
+    // ou une action vide si elle ne sert pas
236
+    $action = $valeurs['action'] ?? self('&amp;', true);
237
+    // bug IEx : si action finit par /
238
+    // IE croit que le <form ... action=../ > est autoferme
239
+    if (substr($action, -1) == '/') {
240
+        // on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un /
241
+        $action .= '#';
242
+    }
243
+
244
+    // recuperer la saisie en cours si erreurs
245
+    // seulement si c'est ce formulaire qui est poste
246
+    // ou si on le demande explicitement par le parametre _forcer_request = true
247
+    $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request']));
248
+    foreach (array_keys($valeurs) as $champ) {
249
+        if ($champ[0] !== '_' and !in_array($champ, ['message_ok', 'message_erreur', 'editable'])) {
250
+            if ($dispo and (($v = _request($champ)) !== null)) {
251
+                $valeurs[$champ] = $v;
252
+            }
253
+            // nettoyer l'url des champs qui vont etre saisis
254
+            if ($action) {
255
+                $action = parametre_url($action, $champ, '');
256
+            }
257
+            // proteger les ' et les " dans les champs que l'on va injecter
258
+            $valeurs[$champ] = protege_champ($valeurs[$champ]);
259
+        }
260
+    }
261
+
262
+    if ($action) {
263
+        // nettoyer l'url
264
+        $action = parametre_url($action, 'formulaire_action', '');
265
+        $action = parametre_url($action, 'formulaire_action_args', '');
266
+        $action = parametre_url($action, 'formulaire_action_sign', '');
267
+    }
268
+
269
+    /**
270
+     * @deprecated 4.0
271
+     * servait pour poster sur les actions de type editer_xxx() qui ne prenaient pas d'argument autrement que par _request('arg') et pour lesquelles il fallait donc passer un hash valide
272
+     */
273
+    /*
274 274
 	if (isset($valeurs['_action'])) {
275 275
 		$securiser_action = charger_fonction('securiser_action', 'inc');
276 276
 		$secu = $securiser_action(reset($valeurs['_action']), end($valeurs['_action']), '', -1);
@@ -280,59 +280,59 @@  discard block
 block discarded – undo
280 280
 	}
281 281
 	*/
282 282
 
283
-	// empiler la lang en tant que premier argument implicite du CVT
284
-	// pour permettre de la restaurer au moment du Verifier et du Traiter
285
-	array_unshift($args, $GLOBALS['spip_lang']);
286
-
287
-	$valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form);
288
-	$valeurs['erreurs'] = $erreurs;
289
-	$valeurs['action'] = $action;
290
-	$valeurs['form'] = $form;
291
-
292
-	$valeurs['formulaire_sign'] = '';
293
-	if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
294
-		$securiser_action = charger_fonction('securiser_action', 'inc');
295
-		$secu = $securiser_action($valeurs['form'], $valeurs['formulaire_args'], '', -1);
296
-		$valeurs['formulaire_sign'] = $secu['hash'];
297
-	}
298
-
299
-	if (!isset($valeurs['id'])) {
300
-		$valeurs['id'] = 'new';
301
-	}
302
-	// editable peut venir de charger() ou de traiter() sinon
303
-	if (!isset($valeurs['editable'])) {
304
-		$valeurs['editable'] = $editable;
305
-	}
306
-	// dans tous les cas, renvoyer un espace ou vide (et pas un booleen)
307
-	$valeurs['editable'] = ($valeurs['editable'] ? ' ' : '');
308
-
309
-	if ($je_suis_poste) {
310
-		$valeurs['message_erreur'] = '';
311
-		if (isset($erreurs['message_erreur'])) {
312
-			$valeurs['message_erreur'] = $erreurs['message_erreur'];
313
-		}
314
-
315
-		$valeurs['message_ok'] = '';
316
-		if (isset($post["message_ok_$form"])) {
317
-			$valeurs['message_ok'] = $post["message_ok_$form"];
318
-		} elseif (isset($erreurs['message_ok'])) {
319
-			$valeurs['message_ok'] = $erreurs['message_ok'];
320
-		}
321
-
322
-		// accessibilite : encapsuler toutes les erreurs dans un role='alert'
323
-		// uniquement si c'est une string et au premier niveau (on ne touche pas au tableaux)
324
-		// et si $k ne commence pas par un _ (c'est bien une vrai erreur sur un vrai champ)
325
-		if (html5_permis()) {
326
-			foreach ($erreurs as $k => $v) {
327
-				if (is_string($v) and strlen(trim($v)) and strpos($k, '_') !== 0) {
328
-					// on encapsule dans un span car ces messages sont en general simple, juste du texte, et deja dans un span dans le form
329
-					$valeurs['erreurs'][$k] = "<span role='alert'>" . $erreurs[$k] . '</span>';
330
-				}
331
-			}
332
-		}
333
-	}
334
-
335
-	return $valeurs;
283
+    // empiler la lang en tant que premier argument implicite du CVT
284
+    // pour permettre de la restaurer au moment du Verifier et du Traiter
285
+    array_unshift($args, $GLOBALS['spip_lang']);
286
+
287
+    $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form);
288
+    $valeurs['erreurs'] = $erreurs;
289
+    $valeurs['action'] = $action;
290
+    $valeurs['form'] = $form;
291
+
292
+    $valeurs['formulaire_sign'] = '';
293
+    if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
294
+        $securiser_action = charger_fonction('securiser_action', 'inc');
295
+        $secu = $securiser_action($valeurs['form'], $valeurs['formulaire_args'], '', -1);
296
+        $valeurs['formulaire_sign'] = $secu['hash'];
297
+    }
298
+
299
+    if (!isset($valeurs['id'])) {
300
+        $valeurs['id'] = 'new';
301
+    }
302
+    // editable peut venir de charger() ou de traiter() sinon
303
+    if (!isset($valeurs['editable'])) {
304
+        $valeurs['editable'] = $editable;
305
+    }
306
+    // dans tous les cas, renvoyer un espace ou vide (et pas un booleen)
307
+    $valeurs['editable'] = ($valeurs['editable'] ? ' ' : '');
308
+
309
+    if ($je_suis_poste) {
310
+        $valeurs['message_erreur'] = '';
311
+        if (isset($erreurs['message_erreur'])) {
312
+            $valeurs['message_erreur'] = $erreurs['message_erreur'];
313
+        }
314
+
315
+        $valeurs['message_ok'] = '';
316
+        if (isset($post["message_ok_$form"])) {
317
+            $valeurs['message_ok'] = $post["message_ok_$form"];
318
+        } elseif (isset($erreurs['message_ok'])) {
319
+            $valeurs['message_ok'] = $erreurs['message_ok'];
320
+        }
321
+
322
+        // accessibilite : encapsuler toutes les erreurs dans un role='alert'
323
+        // uniquement si c'est une string et au premier niveau (on ne touche pas au tableaux)
324
+        // et si $k ne commence pas par un _ (c'est bien une vrai erreur sur un vrai champ)
325
+        if (html5_permis()) {
326
+            foreach ($erreurs as $k => $v) {
327
+                if (is_string($v) and strlen(trim($v)) and strpos($k, '_') !== 0) {
328
+                    // on encapsule dans un span car ces messages sont en general simple, juste du texte, et deja dans un span dans le form
329
+                    $valeurs['erreurs'][$k] = "<span role='alert'>" . $erreurs[$k] . '</span>';
330
+                }
331
+            }
332
+        }
333
+    }
334
+
335
+    return $valeurs;
336 336
 }
337 337
 
338 338
 /**
@@ -344,51 +344,51 @@  discard block
 block discarded – undo
344 344
  * @return array
345 345
  */
346 346
 function formulaire__charger($form, $args, $poste) {
347
-	if ($charger_valeurs = charger_fonction('charger', "formulaires/$form", true)) {
348
-		$valeurs = $charger_valeurs(...$args);
349
-	} else {
350
-		$valeurs = [];
351
-	}
352
-
353
-	$valeurs = pipeline(
354
-		'formulaire_charger',
355
-		[
356
-			'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste],
357
-			'data' => $valeurs
358
-		]
359
-	);
360
-
361
-	// prise en charge CVT multi etape
362
-	if (is_array($valeurs) and isset($valeurs['_etapes'])) {
363
-		include_spip('inc/cvt_multietapes');
364
-		$valeurs = cvtmulti_formulaire_charger_etapes(
365
-			['form' => $form, 'args' => $args, 'je_suis_poste' => $poste],
366
-			$valeurs
367
-		);
368
-	}
369
-
370
-	// si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline !
371
-	if (is_array($valeurs)) {
372
-		if (!isset($valeurs['_pipelines'])) {
373
-			$valeurs['_pipelines'] = [];
374
-		}
375
-		// l'ancien argument _pipeline devient maintenant _pipelines
376
-		// reinjectons le vieux _pipeline au debut de _pipelines
377
-		if (isset($valeurs['_pipeline'])) {
378
-			$pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline'];
379
-			$args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : [];
380
-
381
-			$pipelines = [$pipe => $args];
382
-			$valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']);
383
-		}
384
-
385
-		// et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire
386
-		// qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond
387
-		// (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes)
388
-		$valeurs['_pipelines']['formulaire_fond'] = ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste];
389
-	}
390
-
391
-	return $valeurs;
347
+    if ($charger_valeurs = charger_fonction('charger', "formulaires/$form", true)) {
348
+        $valeurs = $charger_valeurs(...$args);
349
+    } else {
350
+        $valeurs = [];
351
+    }
352
+
353
+    $valeurs = pipeline(
354
+        'formulaire_charger',
355
+        [
356
+            'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste],
357
+            'data' => $valeurs
358
+        ]
359
+    );
360
+
361
+    // prise en charge CVT multi etape
362
+    if (is_array($valeurs) and isset($valeurs['_etapes'])) {
363
+        include_spip('inc/cvt_multietapes');
364
+        $valeurs = cvtmulti_formulaire_charger_etapes(
365
+            ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste],
366
+            $valeurs
367
+        );
368
+    }
369
+
370
+    // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline !
371
+    if (is_array($valeurs)) {
372
+        if (!isset($valeurs['_pipelines'])) {
373
+            $valeurs['_pipelines'] = [];
374
+        }
375
+        // l'ancien argument _pipeline devient maintenant _pipelines
376
+        // reinjectons le vieux _pipeline au debut de _pipelines
377
+        if (isset($valeurs['_pipeline'])) {
378
+            $pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline'];
379
+            $args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : [];
380
+
381
+            $pipelines = [$pipe => $args];
382
+            $valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']);
383
+        }
384
+
385
+        // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire
386
+        // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond
387
+        // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes)
388
+        $valeurs['_pipelines']['formulaire_fond'] = ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste];
389
+    }
390
+
391
+    return $valeurs;
392 392
 }
393 393
 
394 394
 /**
@@ -407,9 +407,9 @@  discard block
 block discarded – undo
407 407
  * @return bool
408 408
  */
409 409
 function formulaire__identifier($form, $args, $p) {
410
-	if ($identifier_args = charger_fonction('identifier', "formulaires/$form", true)) {
411
-		return $identifier_args(...$args) === $identifier_args(...$p);
412
-	}
410
+    if ($identifier_args = charger_fonction('identifier', "formulaires/$form", true)) {
411
+        return $identifier_args(...$args) === $identifier_args(...$p);
412
+    }
413 413
 
414
-	return $args === $p;
414
+    return $args === $p;
415 415
 }
Please login to merge, or discard this patch.
ecrire/inc/livrer_fichier.php 1 patch
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Fichier
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -36,28 +36,28 @@  discard block
 block discarded – undo
36 36
  */
37 37
 function spip_livrer_fichier($fichier, $content_type = 'application/octet-stream', $options = []) {
38 38
 
39
-	$defaut = [
40
-		'attachment' => false,
41
-		'expires' => 3600,
42
-		'range' => null
43
-	];
44
-	$options = array_merge($defaut, $options);
45
-	if (is_numeric($options['expires']) and $options['expires'] > 0) {
46
-		$options['expires'] = gmdate('D, d M Y H:i:s', time() + $options['expires']) . ' GMT';
47
-	}
48
-
49
-	if (is_null($options) and isset($_SERVER['HTTP_RANGE'])) {
50
-		$options['range'] = $_SERVER['HTTP_RANGE'];
51
-	}
52
-
53
-	spip_livrer_fichier_entetes($fichier, $content_type, $options['attachment'] && !$options['range'], $options['expires']);
54
-
55
-	if (!is_null($options['range'])) {
56
-		spip_livrer_fichier_partie($fichier, $options['range']);
57
-	}
58
-	else {
59
-		spip_livrer_fichier_entier($fichier);
60
-	}
39
+    $defaut = [
40
+        'attachment' => false,
41
+        'expires' => 3600,
42
+        'range' => null
43
+    ];
44
+    $options = array_merge($defaut, $options);
45
+    if (is_numeric($options['expires']) and $options['expires'] > 0) {
46
+        $options['expires'] = gmdate('D, d M Y H:i:s', time() + $options['expires']) . ' GMT';
47
+    }
48
+
49
+    if (is_null($options) and isset($_SERVER['HTTP_RANGE'])) {
50
+        $options['range'] = $_SERVER['HTTP_RANGE'];
51
+    }
52
+
53
+    spip_livrer_fichier_entetes($fichier, $content_type, $options['attachment'] && !$options['range'], $options['expires']);
54
+
55
+    if (!is_null($options['range'])) {
56
+        spip_livrer_fichier_partie($fichier, $options['range']);
57
+    }
58
+    else {
59
+        spip_livrer_fichier_entier($fichier);
60
+    }
61 61
 }
62 62
 
63 63
 /**
@@ -70,28 +70,28 @@  discard block
 block discarded – undo
70 70
  * @param int|string $expires
71 71
  */
72 72
 function spip_livrer_fichier_entetes($fichier, $content_type = 'application/octet-stream', $attachment = false, $expires = 0) {
73
-	// toujours envoyer un content type, meme vide !
74
-	header('Accept-Ranges: bytes');
75
-	header('Content-Type: ' . $content_type);
76
-
77
-	if ($attachment) {
78
-		$f = basename($fichier);
79
-		// ce content-type est necessaire pour eviter des corruptions de zip dans ie6
80
-		header('Content-Type: application/octet-stream');
81
-
82
-		header("Content-Disposition: attachment; filename=\"$f\";");
83
-		header('Content-Transfer-Encoding: binary');
84
-
85
-		// fix for IE caching or PHP bug issue
86
-		header('Expires: 0'); // set expiration time
87
-		header('Pragma: public');
88
-		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
89
-	}
90
-	else {
91
-		$f = basename($fichier);
92
-		header("Content-Disposition: inline; filename=\"$f\";");
93
-		header('Expires: ' . $expires); // set expiration time
94
-	}
73
+    // toujours envoyer un content type, meme vide !
74
+    header('Accept-Ranges: bytes');
75
+    header('Content-Type: ' . $content_type);
76
+
77
+    if ($attachment) {
78
+        $f = basename($fichier);
79
+        // ce content-type est necessaire pour eviter des corruptions de zip dans ie6
80
+        header('Content-Type: application/octet-stream');
81
+
82
+        header("Content-Disposition: attachment; filename=\"$f\";");
83
+        header('Content-Transfer-Encoding: binary');
84
+
85
+        // fix for IE caching or PHP bug issue
86
+        header('Expires: 0'); // set expiration time
87
+        header('Pragma: public');
88
+        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
89
+    }
90
+    else {
91
+        $f = basename($fichier);
92
+        header("Content-Disposition: inline; filename=\"$f\";");
93
+        header('Expires: ' . $expires); // set expiration time
94
+    }
95 95
 }
96 96
 
97 97
 /**
@@ -99,20 +99,20 @@  discard block
 block discarded – undo
99 99
  * @param string $fichier
100 100
  */
101 101
 function spip_livrer_fichier_entier($fichier) {
102
-	if (!file_exists($fichier)) {
103
-		throw new \Exception(sprintf('File not found: %s', $fichier));
104
-	}
102
+    if (!file_exists($fichier)) {
103
+        throw new \Exception(sprintf('File not found: %s', $fichier));
104
+    }
105 105
 
106
-	if (!is_readable($fichier)) {
107
-		throw new \Exception(sprintf('File not readable: %s', $fichier));
108
-	}
106
+    if (!is_readable($fichier)) {
107
+        throw new \Exception(sprintf('File not readable: %s', $fichier));
108
+    }
109 109
 
110
-	if ($size = filesize($fichier)) {
111
-		header(sprintf('Content-Length: %d', $size));
112
-	}
110
+    if ($size = filesize($fichier)) {
111
+        header(sprintf('Content-Length: %d', $size));
112
+    }
113 113
 
114
-	readfile($fichier);
115
-	exit();
114
+    readfile($fichier);
115
+    exit();
116 116
 }
117 117
 
118 118
 /**
@@ -125,98 +125,98 @@  discard block
 block discarded – undo
125 125
  * @throws Exception
126 126
  */
127 127
 function spip_livrer_fichier_partie($fichier, $range = null) {
128
-	if (!file_exists($fichier)) {
129
-		throw new \Exception(sprintf('File not found: %s', $fichier));
130
-	}
128
+    if (!file_exists($fichier)) {
129
+        throw new \Exception(sprintf('File not found: %s', $fichier));
130
+    }
131 131
 
132
-	if (!is_readable($fichier)) {
133
-		throw new \Exception(sprintf('File not readable: %s', $fichier));
134
-	}
132
+    if (!is_readable($fichier)) {
133
+        throw new \Exception(sprintf('File not readable: %s', $fichier));
134
+    }
135 135
 
136 136
 
137
-	// Par defaut on envoie tout
138
-	$byteOffset = 0;
139
-	$byteLength = $fileSize = filesize($fichier);
137
+    // Par defaut on envoie tout
138
+    $byteOffset = 0;
139
+    $byteLength = $fileSize = filesize($fichier);
140 140
 
141 141
 
142
-	// Parse Content-Range header for byte offsets, looks like "bytes=11525-" OR "bytes=11525-12451"
143
-	if ($range and preg_match('%bytes=(\d+)-(\d+)?%i', $range, $match)) {
144
-		### Offset signifies where we should begin to read the file
145
-		$byteOffset = (int)$match[1];
142
+    // Parse Content-Range header for byte offsets, looks like "bytes=11525-" OR "bytes=11525-12451"
143
+    if ($range and preg_match('%bytes=(\d+)-(\d+)?%i', $range, $match)) {
144
+        ### Offset signifies where we should begin to read the file
145
+        $byteOffset = (int)$match[1];
146 146
 
147 147
 
148
-		### Length is for how long we should read the file according to the browser, and can never go beyond the file size
149
-		if (isset($match[2])) {
150
-			$finishBytes = (int)$match[2];
151
-			$byteLength = $finishBytes + 1;
152
-		} else {
153
-			$finishBytes = $fileSize - 1;
154
-		}
148
+        ### Length is for how long we should read the file according to the browser, and can never go beyond the file size
149
+        if (isset($match[2])) {
150
+            $finishBytes = (int)$match[2];
151
+            $byteLength = $finishBytes + 1;
152
+        } else {
153
+            $finishBytes = $fileSize - 1;
154
+        }
155 155
 
156
-		$cr_header = sprintf('Content-Range: bytes %d-%d/%d', $byteOffset, $finishBytes, $fileSize);
157
-	}
158
-	else {
159
-		// si pas de range valide, on delegue a la methode d'envoi complet
160
-		spip_livrer_fichier_entier($fichier);
161
-		// redondant, mais facilite la comprehension du code
162
-		exit();
163
-	}
156
+        $cr_header = sprintf('Content-Range: bytes %d-%d/%d', $byteOffset, $finishBytes, $fileSize);
157
+    }
158
+    else {
159
+        // si pas de range valide, on delegue a la methode d'envoi complet
160
+        spip_livrer_fichier_entier($fichier);
161
+        // redondant, mais facilite la comprehension du code
162
+        exit();
163
+    }
164 164
 
165
-	// Remove headers that might unnecessarily clutter up the output
166
-	header_remove('Cache-Control');
167
-	header_remove('Pragma');
165
+    // Remove headers that might unnecessarily clutter up the output
166
+    header_remove('Cache-Control');
167
+    header_remove('Pragma');
168 168
 
169
-	// partial content
170
-	header('HTTP/1.1 206 Partial content');
171
-	header($cr_header);  ### Decrease by 1 on byte-length since this definition is zero-based index of bytes being sent
169
+    // partial content
170
+    header('HTTP/1.1 206 Partial content');
171
+    header($cr_header);  ### Decrease by 1 on byte-length since this definition is zero-based index of bytes being sent
172 172
 
173 173
 
174
-	$byteRange = $byteLength - $byteOffset;
174
+    $byteRange = $byteLength - $byteOffset;
175 175
 
176
-	header(sprintf('Content-Length: %d', $byteRange));
176
+    header(sprintf('Content-Length: %d', $byteRange));
177 177
 
178
-	// Variable containing the buffer
179
-	$buffer = '';
180
-	// Just a reasonable buffer size
181
-	$bufferSize = 512 * 16;
182
-	// Contains how much is left to read of the byteRange
183
-	$bytePool = $byteRange;
178
+    // Variable containing the buffer
179
+    $buffer = '';
180
+    // Just a reasonable buffer size
181
+    $bufferSize = 512 * 16;
182
+    // Contains how much is left to read of the byteRange
183
+    $bytePool = $byteRange;
184 184
 
185
-	if (!$handle = fopen($fichier, 'r')) {
186
-		throw new \Exception(sprintf('Could not get handle for file %s', $fichier));
187
-	}
185
+    if (!$handle = fopen($fichier, 'r')) {
186
+        throw new \Exception(sprintf('Could not get handle for file %s', $fichier));
187
+    }
188 188
 
189
-	if (fseek($handle, $byteOffset, SEEK_SET) == -1) {
190
-		throw new \Exception(sprintf('Could not seek to byte offset %d', $byteOffset));
191
-	}
189
+    if (fseek($handle, $byteOffset, SEEK_SET) == -1) {
190
+        throw new \Exception(sprintf('Could not seek to byte offset %d', $byteOffset));
191
+    }
192 192
 
193 193
 
194
-	while ($bytePool > 0) {
195
-		// How many bytes we request on this iteration
196
-		$chunkSizeRequested = min($bufferSize, $bytePool);
194
+    while ($bytePool > 0) {
195
+        // How many bytes we request on this iteration
196
+        $chunkSizeRequested = min($bufferSize, $bytePool);
197 197
 
198
-		// Try readin $chunkSizeRequested bytes from $handle and put data in $buffer
199
-		$buffer = fread($handle, $chunkSizeRequested);
198
+        // Try readin $chunkSizeRequested bytes from $handle and put data in $buffer
199
+        $buffer = fread($handle, $chunkSizeRequested);
200 200
 
201
-		// Store how many bytes were actually read
202
-		$chunkSizeActual = strlen($buffer);
201
+        // Store how many bytes were actually read
202
+        $chunkSizeActual = strlen($buffer);
203 203
 
204
-		// If we didn't get any bytes that means something unexpected has happened since $bytePool should be zero already
205
-		if ($chunkSizeActual == 0) {
206
-			// For production servers this should go in your php error log, since it will break the output
207
-			trigger_error('Chunksize became 0', E_USER_WARNING);
208
-			break;
209
-		}
204
+        // If we didn't get any bytes that means something unexpected has happened since $bytePool should be zero already
205
+        if ($chunkSizeActual == 0) {
206
+            // For production servers this should go in your php error log, since it will break the output
207
+            trigger_error('Chunksize became 0', E_USER_WARNING);
208
+            break;
209
+        }
210 210
 
211
-		// Decrease byte pool with amount of bytes that were read during this iteration
212
-		$bytePool -= $chunkSizeActual;
211
+        // Decrease byte pool with amount of bytes that were read during this iteration
212
+        $bytePool -= $chunkSizeActual;
213 213
 
214
-		// Write the buffer to output
215
-		print $buffer;
214
+        // Write the buffer to output
215
+        print $buffer;
216 216
 
217
-		// Try to output the data to the client immediately
218
-		flush();
219
-	}
217
+        // Try to output the data to the client immediately
218
+        flush();
219
+    }
220 220
 
221
-	exit();
221
+    exit();
222 222
 }
Please login to merge, or discard this patch.