Completed
Push — master ( bd6ae7...aaa036 )
by cam
04:19
created
ecrire/balise/formulaire_.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@
 block discarded – undo
60 60
  * @see trouver_fond()
61 61
  * @param string $form
62 62
  *     Nom du formulaire
63
- * @return string|bool
63
+ * @return string|false
64 64
  *     - string : chemin du squelette
65 65
  *     - false : pas de squelette trouvé
66 66
  **/
Please login to merge, or discard this patch.
Indentation   +244 added lines, -244 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @package SPIP\Core\Formulaires
16 16
  **/
17 17
 if (!defined('_ECRIRE_INC_VERSION')) {
18
-	return;
18
+    return;
19 19
 }
20 20
 
21 21
 include_spip('inc/filtres');
@@ -34,24 +34,24 @@  discard block
 block discarded – undo
34 34
  *     Saisie protégée
35 35
  **/
36 36
 function protege_champ($texte) {
37
-	if (is_array($texte)) {
38
-		$texte = array_map('protege_champ', $texte);
39
-	} else {
40
-		// ne pas corrompre une valeur serialize
41
-		if ((preg_match(",^[abis]:\d+[:;],", $texte) and @unserialize($texte) != false) or is_null($texte)) {
42
-			return $texte;
43
-		}
44
-		if (is_string($texte)
45
-			and $texte
46
-			and strpbrk($texte, "&\"'<>") !== false
47
-		) {
48
-			$texte = spip_htmlspecialchars($texte, ENT_QUOTES);
49
-		} elseif (is_bool($texte)) {
50
-			$texte = ($texte ? '1' : '');
51
-		}
52
-	}
53
-
54
-	return $texte;
37
+    if (is_array($texte)) {
38
+        $texte = array_map('protege_champ', $texte);
39
+    } else {
40
+        // ne pas corrompre une valeur serialize
41
+        if ((preg_match(",^[abis]:\d+[:;],", $texte) and @unserialize($texte) != false) or is_null($texte)) {
42
+            return $texte;
43
+        }
44
+        if (is_string($texte)
45
+            and $texte
46
+            and strpbrk($texte, "&\"'<>") !== false
47
+        ) {
48
+            $texte = spip_htmlspecialchars($texte, ENT_QUOTES);
49
+        } elseif (is_bool($texte)) {
50
+            $texte = ($texte ? '1' : '');
51
+        }
52
+    }
53
+
54
+    return $texte;
55 55
 }
56 56
 
57 57
 /**
@@ -65,17 +65,17 @@  discard block
 block discarded – undo
65 65
  *     - false : pas de squelette trouvé
66 66
  **/
67 67
 function existe_formulaire($form) {
68
-	if (substr($form, 0, 11) == "FORMULAIRE_") {
69
-		$form = strtolower(substr($form, 11));
70
-	} else {
71
-		$form = strtolower($form);
72
-	}
68
+    if (substr($form, 0, 11) == "FORMULAIRE_") {
69
+        $form = strtolower(substr($form, 11));
70
+    } else {
71
+        $form = strtolower($form);
72
+    }
73 73
 
74
-	if (!$form) {
75
-		return '';
76
-	} // on ne sait pas, le nom du formulaire n'est pas fourni ici
74
+    if (!$form) {
75
+        return '';
76
+    } // on ne sait pas, le nom du formulaire n'est pas fourni ici
77 77
 
78
-	return trouver_fond($form, 'formulaires/') ? $form : false;
78
+    return trouver_fond($form, 'formulaires/') ? $form : false;
79 79
 }
80 80
 
81 81
 /**
@@ -84,29 +84,29 @@  discard block
 block discarded – undo
84 84
  * @return false|array
85 85
  */
86 86
 function test_formulaire_inclus_par_modele() {
87
-	$trace = debug_backtrace(null, 20);
88
-	$trace_fonctions = array_column($trace, 'function');
89
-	$trace_fonctions = array_map('strtolower', $trace_fonctions);
90
-
91
-	// regarder si un flag a ete leve juste avant l'appel de balise_FORMULAIRE_dyn
92
-	if (function_exists('arguments_balise_dyn_depuis_modele')
93
-		and $form = arguments_balise_dyn_depuis_modele(null, 'read')) {
94
-		if (in_array('balise_formulaire__dyn', $trace_fonctions)) {
95
-			$k = array_search('balise_formulaire__dyn', $trace_fonctions);
96
-			if ($trace[$k]['args'][0] === $form) {
97
-				return $trace[$k]['args'];
98
-			}
99
-		}
100
-	}
101
-
102
-	// fallback qui ne repose pas sur le flag lie a l'analyse de contexte_compil,
103
-	// mais ne marche pas si executer_balise_dynamique est appelee via du php dans le squelette
104
-	if (in_array('eval', $trace_fonctions) and in_array('inclure_modele', $trace_fonctions)) {
105
-		$k = array_search('inclure_modele', $trace_fonctions);
106
-		// les arguments de recuperer_fond() passes par inclure_modele()
107
-		return $trace[$k-1]['args'][1]['args'];
108
-	}
109
-	return false;
87
+    $trace = debug_backtrace(null, 20);
88
+    $trace_fonctions = array_column($trace, 'function');
89
+    $trace_fonctions = array_map('strtolower', $trace_fonctions);
90
+
91
+    // regarder si un flag a ete leve juste avant l'appel de balise_FORMULAIRE_dyn
92
+    if (function_exists('arguments_balise_dyn_depuis_modele')
93
+        and $form = arguments_balise_dyn_depuis_modele(null, 'read')) {
94
+        if (in_array('balise_formulaire__dyn', $trace_fonctions)) {
95
+            $k = array_search('balise_formulaire__dyn', $trace_fonctions);
96
+            if ($trace[$k]['args'][0] === $form) {
97
+                return $trace[$k]['args'];
98
+            }
99
+        }
100
+    }
101
+
102
+    // fallback qui ne repose pas sur le flag lie a l'analyse de contexte_compil,
103
+    // mais ne marche pas si executer_balise_dynamique est appelee via du php dans le squelette
104
+    if (in_array('eval', $trace_fonctions) and in_array('inclure_modele', $trace_fonctions)) {
105
+        $k = array_search('inclure_modele', $trace_fonctions);
106
+        // les arguments de recuperer_fond() passes par inclure_modele()
107
+        return $trace[$k-1]['args'][1]['args'];
108
+    }
109
+    return false;
110 110
 }
111 111
 
112 112
 /**
@@ -121,17 +121,17 @@  discard block
 block discarded – undo
121 121
  **/
122 122
 function balise_FORMULAIRE__dist($p) {
123 123
 
124
-	// Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide.
125
-	// mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer
126
-	if (existe_formulaire($p->nom_champ) === false) {
127
-		$p->code = "''";
128
-		$p->interdire_scripts = false;
124
+    // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide.
125
+    // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer
126
+    if (existe_formulaire($p->nom_champ) === false) {
127
+        $p->code = "''";
128
+        $p->interdire_scripts = false;
129 129
 
130
-		return $p;
131
-	}
130
+        return $p;
131
+    }
132 132
 
133
-	// sinon renvoyer un code php dynamique
134
-	return calculer_balise_dynamique($p, $p->nom_champ, array());
133
+    // sinon renvoyer un code php dynamique
134
+    return calculer_balise_dynamique($p, $p->nom_champ, array());
135 135
 }
136 136
 
137 137
 /**
@@ -151,17 +151,17 @@  discard block
 block discarded – undo
151 151
  *     - string : texte à afficher directement
152 152
  */
153 153
 function balise_FORMULAIRE__dyn($form, ...$args) {
154
-	$form = existe_formulaire($form);
155
-	if (!$form) {
156
-		return '';
157
-	}
154
+    $form = existe_formulaire($form);
155
+    if (!$form) {
156
+        return '';
157
+    }
158 158
 
159
-	$contexte = balise_FORMULAIRE__contexte($form, $args);
160
-	if (!is_array($contexte)) {
161
-		return $contexte;
162
-	}
159
+    $contexte = balise_FORMULAIRE__contexte($form, $args);
160
+    if (!is_array($contexte)) {
161
+        return $contexte;
162
+    }
163 163
 
164
-	return array("formulaires/$form", 3600, $contexte);
164
+    return array("formulaires/$form", 3600, $contexte);
165 165
 }
166 166
 
167 167
 /**
@@ -175,132 +175,132 @@  discard block
 block discarded – undo
175 175
  *     Contexte d'environnement à envoyer au squelette
176 176
  **/
177 177
 function balise_FORMULAIRE__contexte($form, $args) {
178
-	// tester si ce formulaire vient d'etre poste (memes arguments)
179
-	// pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page
180
-	// si poste, on recupere les erreurs
181
-
182
-	$je_suis_poste = false;
183
-	if ($post_form = _request('formulaire_action')
184
-		and $post_form == $form
185
-		and $p = _request('formulaire_action_args')
186
-		and is_array($p = decoder_contexte_ajax($p, $post_form))
187
-	) {
188
-		// enlever le faux attribut de langue masque
189
-		array_shift($p);
190
-		if (formulaire__identifier($form, $args, $p)) {
191
-			$je_suis_poste = true;
192
-		}
193
-	}
194
-
195
-	$editable = true;
196
-	$erreurs = $post = array();
197
-	if ($je_suis_poste) {
198
-		$post = traiter_formulaires_dynamiques(true);
199
-		$e = "erreurs_$form";
200
-		$erreurs = isset($post[$e]) ? $post[$e] : array();
201
-		$editable = "editable_$form";
202
-		$editable = (!isset($post[$e]))
203
-			|| count($erreurs)
204
-			|| (isset($post[$editable]) && $post[$editable]);
205
-	}
206
-
207
-	$valeurs = formulaire__charger($form, $args, $je_suis_poste);
208
-
209
-	// si $valeurs n'est pas un tableau, le formulaire n'est pas applicable
210
-	// C'est plus fort qu'editable qui est gere par le squelette 
211
-	// Idealement $valeur doit etre alors un message explicatif.
212
-	if (!is_array($valeurs)) {
213
-		return is_string($valeurs) ? $valeurs : '';
214
-	}
215
-
216
-	// charger peut passer une action si le formulaire ne tourne pas sur self()
217
-	// ou une action vide si elle ne sert pas
218
-	$action = (isset($valeurs['action'])) ? $valeurs['action'] : self('&amp;', true);
219
-	// bug IEx : si action finit par / 
220
-	// IE croit que le <form ... action=../ > est autoferme
221
-	if (substr($action, -1) == '/') {
222
-		// on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un /
223
-		$action .= '#';
224
-	}
225
-
226
-	// recuperer la saisie en cours si erreurs
227
-	// seulement si c'est ce formulaire qui est poste
228
-	// ou si on le demande explicitement par le parametre _forcer_request = true
229
-	$dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request']));
230
-	foreach (array_keys($valeurs) as $champ) {
231
-		if ($champ[0] !== '_' and !in_array($champ, array('message_ok', 'message_erreur', 'editable'))) {
232
-			if ($dispo and (($v = _request($champ)) !== null)) {
233
-				$valeurs[$champ] = $v;
234
-			}
235
-			// nettoyer l'url des champs qui vont etre saisis
236
-			if ($action) {
237
-				$action = parametre_url($action, $champ, '');
238
-			}
239
-			// proteger les ' et les " dans les champs que l'on va injecter
240
-			$valeurs[$champ] = protege_champ($valeurs[$champ]);
241
-		}
242
-	}
243
-
244
-	if ($action) {
245
-		// nettoyer l'url
246
-		$action = parametre_url($action, 'formulaire_action', '');
247
-		$action = parametre_url($action, 'formulaire_action_args', '');
248
-	}
249
-
250
-	if (isset($valeurs['_action'])) {
251
-		$securiser_action = charger_fonction('securiser_action', 'inc');
252
-		$secu = $securiser_action(reset($valeurs['_action']), end($valeurs['_action']), '', -1);
253
-		$valeurs['_hidden'] = (isset($valeurs['_hidden']) ? $valeurs['_hidden'] : '') .
254
-			"<input type='hidden' name='arg' value='" . $secu['arg'] . "' />"
255
-			. "<input type='hidden' name='hash' value='" . $secu['hash'] . "' />";
256
-	}
257
-
258
-	// empiler la lang en tant que premier argument implicite du CVT
259
-	// pour permettre de la restaurer au moment du Verifier et du Traiter
260
-	array_unshift($args, $GLOBALS['spip_lang']);
261
-
262
-	$valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form);
263
-	$valeurs['erreurs'] = $erreurs;
264
-	$valeurs['action'] = $action;
265
-	$valeurs['form'] = $form;
266
-
267
-	if (!isset($valeurs['id'])) {
268
-		$valeurs['id'] = 'new';
269
-	}
270
-	// editable peut venir de charger() ou de traiter() sinon
271
-	if (!isset($valeurs['editable'])) {
272
-		$valeurs['editable'] = $editable;
273
-	}
274
-	// dans tous les cas, renvoyer un espace ou vide (et pas un booleen)
275
-	$valeurs['editable'] = ($valeurs['editable'] ? ' ' : '');
276
-
277
-	if ($je_suis_poste) {
278
-		$valeurs['message_erreur'] = "";
279
-		if (isset($erreurs['message_erreur'])) {
280
-			$valeurs['message_erreur'] = $erreurs['message_erreur'];
281
-		}
282
-
283
-		$valeurs['message_ok'] = "";
284
-		if (isset($post["message_ok_$form"])) {
285
-			$valeurs['message_ok'] = $post["message_ok_$form"];
286
-		} elseif (isset($erreurs['message_ok'])) {
287
-			$valeurs['message_ok'] = $erreurs["message_ok"];
288
-		}
289
-
290
-		// accessibilite : encapsuler toutes les erreurs dans un role='alert'
291
-		// uniquement si c'est une string et au premier niveau (on ne touche pas au tableaux)
292
-		// et si $k ne commence pas par un _ (c'est bien une vrai erreur sur un vrai champ)
293
-		if (html5_permis()) {
294
-			foreach ($erreurs as $k => $v) {
295
-				if (is_string($v) and strlen(trim($v)) and strpos($k,'_') !== 0) {
296
-					// on encapsule dans un span car ces messages sont en general simple, juste du texte, et deja dans un span dans le form
297
-					$valeurs['erreurs'][$k] = "<span role='alert'>".$erreurs[$k]."</span>";
298
-				}
299
-			}
300
-		}
301
-	}
302
-
303
-	return $valeurs;
178
+    // tester si ce formulaire vient d'etre poste (memes arguments)
179
+    // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page
180
+    // si poste, on recupere les erreurs
181
+
182
+    $je_suis_poste = false;
183
+    if ($post_form = _request('formulaire_action')
184
+        and $post_form == $form
185
+        and $p = _request('formulaire_action_args')
186
+        and is_array($p = decoder_contexte_ajax($p, $post_form))
187
+    ) {
188
+        // enlever le faux attribut de langue masque
189
+        array_shift($p);
190
+        if (formulaire__identifier($form, $args, $p)) {
191
+            $je_suis_poste = true;
192
+        }
193
+    }
194
+
195
+    $editable = true;
196
+    $erreurs = $post = array();
197
+    if ($je_suis_poste) {
198
+        $post = traiter_formulaires_dynamiques(true);
199
+        $e = "erreurs_$form";
200
+        $erreurs = isset($post[$e]) ? $post[$e] : array();
201
+        $editable = "editable_$form";
202
+        $editable = (!isset($post[$e]))
203
+            || count($erreurs)
204
+            || (isset($post[$editable]) && $post[$editable]);
205
+    }
206
+
207
+    $valeurs = formulaire__charger($form, $args, $je_suis_poste);
208
+
209
+    // si $valeurs n'est pas un tableau, le formulaire n'est pas applicable
210
+    // C'est plus fort qu'editable qui est gere par le squelette 
211
+    // Idealement $valeur doit etre alors un message explicatif.
212
+    if (!is_array($valeurs)) {
213
+        return is_string($valeurs) ? $valeurs : '';
214
+    }
215
+
216
+    // charger peut passer une action si le formulaire ne tourne pas sur self()
217
+    // ou une action vide si elle ne sert pas
218
+    $action = (isset($valeurs['action'])) ? $valeurs['action'] : self('&amp;', true);
219
+    // bug IEx : si action finit par / 
220
+    // IE croit que le <form ... action=../ > est autoferme
221
+    if (substr($action, -1) == '/') {
222
+        // on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un /
223
+        $action .= '#';
224
+    }
225
+
226
+    // recuperer la saisie en cours si erreurs
227
+    // seulement si c'est ce formulaire qui est poste
228
+    // ou si on le demande explicitement par le parametre _forcer_request = true
229
+    $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request']));
230
+    foreach (array_keys($valeurs) as $champ) {
231
+        if ($champ[0] !== '_' and !in_array($champ, array('message_ok', 'message_erreur', 'editable'))) {
232
+            if ($dispo and (($v = _request($champ)) !== null)) {
233
+                $valeurs[$champ] = $v;
234
+            }
235
+            // nettoyer l'url des champs qui vont etre saisis
236
+            if ($action) {
237
+                $action = parametre_url($action, $champ, '');
238
+            }
239
+            // proteger les ' et les " dans les champs que l'on va injecter
240
+            $valeurs[$champ] = protege_champ($valeurs[$champ]);
241
+        }
242
+    }
243
+
244
+    if ($action) {
245
+        // nettoyer l'url
246
+        $action = parametre_url($action, 'formulaire_action', '');
247
+        $action = parametre_url($action, 'formulaire_action_args', '');
248
+    }
249
+
250
+    if (isset($valeurs['_action'])) {
251
+        $securiser_action = charger_fonction('securiser_action', 'inc');
252
+        $secu = $securiser_action(reset($valeurs['_action']), end($valeurs['_action']), '', -1);
253
+        $valeurs['_hidden'] = (isset($valeurs['_hidden']) ? $valeurs['_hidden'] : '') .
254
+            "<input type='hidden' name='arg' value='" . $secu['arg'] . "' />"
255
+            . "<input type='hidden' name='hash' value='" . $secu['hash'] . "' />";
256
+    }
257
+
258
+    // empiler la lang en tant que premier argument implicite du CVT
259
+    // pour permettre de la restaurer au moment du Verifier et du Traiter
260
+    array_unshift($args, $GLOBALS['spip_lang']);
261
+
262
+    $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form);
263
+    $valeurs['erreurs'] = $erreurs;
264
+    $valeurs['action'] = $action;
265
+    $valeurs['form'] = $form;
266
+
267
+    if (!isset($valeurs['id'])) {
268
+        $valeurs['id'] = 'new';
269
+    }
270
+    // editable peut venir de charger() ou de traiter() sinon
271
+    if (!isset($valeurs['editable'])) {
272
+        $valeurs['editable'] = $editable;
273
+    }
274
+    // dans tous les cas, renvoyer un espace ou vide (et pas un booleen)
275
+    $valeurs['editable'] = ($valeurs['editable'] ? ' ' : '');
276
+
277
+    if ($je_suis_poste) {
278
+        $valeurs['message_erreur'] = "";
279
+        if (isset($erreurs['message_erreur'])) {
280
+            $valeurs['message_erreur'] = $erreurs['message_erreur'];
281
+        }
282
+
283
+        $valeurs['message_ok'] = "";
284
+        if (isset($post["message_ok_$form"])) {
285
+            $valeurs['message_ok'] = $post["message_ok_$form"];
286
+        } elseif (isset($erreurs['message_ok'])) {
287
+            $valeurs['message_ok'] = $erreurs["message_ok"];
288
+        }
289
+
290
+        // accessibilite : encapsuler toutes les erreurs dans un role='alert'
291
+        // uniquement si c'est une string et au premier niveau (on ne touche pas au tableaux)
292
+        // et si $k ne commence pas par un _ (c'est bien une vrai erreur sur un vrai champ)
293
+        if (html5_permis()) {
294
+            foreach ($erreurs as $k => $v) {
295
+                if (is_string($v) and strlen(trim($v)) and strpos($k,'_') !== 0) {
296
+                    // on encapsule dans un span car ces messages sont en general simple, juste du texte, et deja dans un span dans le form
297
+                    $valeurs['erreurs'][$k] = "<span role='alert'>".$erreurs[$k]."</span>";
298
+                }
299
+            }
300
+        }
301
+    }
302
+
303
+    return $valeurs;
304 304
 }
305 305
 
306 306
 /**
@@ -312,51 +312,51 @@  discard block
 block discarded – undo
312 312
  * @return array
313 313
  */
314 314
 function formulaire__charger($form, $args, $poste) {
315
-	if ($charger_valeurs = charger_fonction("charger", "formulaires/$form", true)) {
316
-		$valeurs = call_user_func_array($charger_valeurs, $args);
317
-	} else {
318
-		$valeurs = array();
319
-	}
320
-
321
-	$valeurs = pipeline(
322
-		'formulaire_charger',
323
-		array(
324
-			'args' => array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste),
325
-			'data' => $valeurs
326
-		)
327
-	);
328
-
329
-	// prise en charge CVT multi etape
330
-	if (is_array($valeurs) and isset($valeurs['_etapes'])) {
331
-		include_spip('inc/cvt_multietapes');
332
-		$valeurs = cvtmulti_formulaire_charger_etapes(
333
-			array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste), 
334
-			$valeurs
335
-		);
336
-	}
337
-
338
-	// si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline !
339
-	if (is_array($valeurs)) {
340
-		if (!isset($valeurs['_pipelines'])) {
341
-			$valeurs['_pipelines'] = array();
342
-		}
343
-		// l'ancien argument _pipeline devient maintenant _pipelines
344
-		// reinjectons le vieux _pipeline au debut de _pipelines
345
-		if (isset($valeurs['_pipeline'])) {
346
-			$pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline'];
347
-			$args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : array();
348
-
349
-			$pipelines = array($pipe => $args);
350
-			$valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']);
351
-		}
352
-
353
-		// et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire
354
-		// qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond
355
-		// (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes)
356
-		$valeurs['_pipelines']['formulaire_fond'] = array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste);
357
-	}
358
-
359
-	return $valeurs;
315
+    if ($charger_valeurs = charger_fonction("charger", "formulaires/$form", true)) {
316
+        $valeurs = call_user_func_array($charger_valeurs, $args);
317
+    } else {
318
+        $valeurs = array();
319
+    }
320
+
321
+    $valeurs = pipeline(
322
+        'formulaire_charger',
323
+        array(
324
+            'args' => array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste),
325
+            'data' => $valeurs
326
+        )
327
+    );
328
+
329
+    // prise en charge CVT multi etape
330
+    if (is_array($valeurs) and isset($valeurs['_etapes'])) {
331
+        include_spip('inc/cvt_multietapes');
332
+        $valeurs = cvtmulti_formulaire_charger_etapes(
333
+            array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste), 
334
+            $valeurs
335
+        );
336
+    }
337
+
338
+    // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline !
339
+    if (is_array($valeurs)) {
340
+        if (!isset($valeurs['_pipelines'])) {
341
+            $valeurs['_pipelines'] = array();
342
+        }
343
+        // l'ancien argument _pipeline devient maintenant _pipelines
344
+        // reinjectons le vieux _pipeline au debut de _pipelines
345
+        if (isset($valeurs['_pipeline'])) {
346
+            $pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline'];
347
+            $args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : array();
348
+
349
+            $pipelines = array($pipe => $args);
350
+            $valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']);
351
+        }
352
+
353
+        // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire
354
+        // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond
355
+        // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes)
356
+        $valeurs['_pipelines']['formulaire_fond'] = array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste);
357
+    }
358
+
359
+    return $valeurs;
360 360
 }
361 361
 
362 362
 /**
@@ -375,9 +375,9 @@  discard block
 block discarded – undo
375 375
  * @return bool
376 376
  */
377 377
 function formulaire__identifier($form, $args, $p) {
378
-	if ($identifier_args = charger_fonction("identifier", "formulaires/$form", true)) {
379
-		return call_user_func_array($identifier_args, $args) === call_user_func_array($identifier_args, $p);
380
-	}
378
+    if ($identifier_args = charger_fonction("identifier", "formulaires/$form", true)) {
379
+        return call_user_func_array($identifier_args, $args) === call_user_func_array($identifier_args, $p);
380
+    }
381 381
 
382
-	return $args === $p;
382
+    return $args === $p;
383 383
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	if (in_array('eval', $trace_fonctions) and in_array('inclure_modele', $trace_fonctions)) {
105 105
 		$k = array_search('inclure_modele', $trace_fonctions);
106 106
 		// les arguments de recuperer_fond() passes par inclure_modele()
107
-		return $trace[$k-1]['args'][1]['args'];
107
+		return $trace[$k - 1]['args'][1]['args'];
108 108
 	}
109 109
 	return false;
110 110
 }
@@ -250,9 +250,9 @@  discard block
 block discarded – undo
250 250
 	if (isset($valeurs['_action'])) {
251 251
 		$securiser_action = charger_fonction('securiser_action', 'inc');
252 252
 		$secu = $securiser_action(reset($valeurs['_action']), end($valeurs['_action']), '', -1);
253
-		$valeurs['_hidden'] = (isset($valeurs['_hidden']) ? $valeurs['_hidden'] : '') .
254
-			"<input type='hidden' name='arg' value='" . $secu['arg'] . "' />"
255
-			. "<input type='hidden' name='hash' value='" . $secu['hash'] . "' />";
253
+		$valeurs['_hidden'] = (isset($valeurs['_hidden']) ? $valeurs['_hidden'] : '').
254
+			"<input type='hidden' name='arg' value='".$secu['arg']."' />"
255
+			. "<input type='hidden' name='hash' value='".$secu['hash']."' />";
256 256
 	}
257 257
 
258 258
 	// empiler la lang en tant que premier argument implicite du CVT
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 		// et si $k ne commence pas par un _ (c'est bien une vrai erreur sur un vrai champ)
293 293
 		if (html5_permis()) {
294 294
 			foreach ($erreurs as $k => $v) {
295
-				if (is_string($v) and strlen(trim($v)) and strpos($k,'_') !== 0) {
295
+				if (is_string($v) and strlen(trim($v)) and strpos($k, '_') !== 0) {
296 296
 					// on encapsule dans un span car ces messages sont en general simple, juste du texte, et deja dans un span dans le form
297 297
 					$valeurs['erreurs'][$k] = "<span role='alert'>".$erreurs[$k]."</span>";
298 298
 				}
Please login to merge, or discard this patch.
ecrire/base/connect_sql.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@
 block discarded – undo
36 36
  *
37 37
  * @param string $serveur Nom du connecteur
38 38
  * @param string $version Version de l'API SQL
39
- * @return bool|array
39
+ * @return string
40 40
  *     - false si la connexion a échouée,
41 41
  *     - tableau décrivant la connexion sinon
42 42
  **/
Please login to merge, or discard this patch.
Spacing   +11 added lines, -12 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19 19
 	return;
20 20
 }
21
-require_once _ROOT_RESTREINT . 'base/objets.php';
21
+require_once _ROOT_RESTREINT.'base/objets.php';
22 22
 
23 23
 
24 24
 /**
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 		$f = (!preg_match('/^[\w\.]*$/', $serveur))
60 60
 			? '' // nom de serveur mal ecrit
61 61
 			: ($serveur ?
62
-				(_DIR_CONNECT . $serveur . '.php') // serveur externe
62
+				(_DIR_CONNECT.$serveur.'.php') // serveur externe
63 63
 				: (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok
64 64
 					: ($install ? _FILE_CONNECT_TMP // init du serveur principal
65 65
 						: ''))); // installation pas faite
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 	// chargement de la version du jeu de fonctions
103 103
 	// si pas dans le fichier par defaut
104 104
 	$type = $GLOBALS['db_ok']['type'];
105
-	$jeu = 'spip_' . $type . '_functions_' . $version;
105
+	$jeu = 'spip_'.$type.'_functions_'.$version;
106 106
 	if (!isset($GLOBALS[$jeu])) {
107
-		if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) {
107
+		if (!find_in_path($type.'_'.$version.'.php', 'req/', true)) {
108 108
 			spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS);
109 109
 
110 110
 			// ne plus reessayer
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
 	$connexion = spip_connect($serveur);
166 166
 	$e = sql_errno($serveur);
167 167
 	$t = (isset($connexion['type']) ? $connexion['type'] : 'sql');
168
-	$m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']);
169
-	$f = $t . $serveur;
170
-	spip_log($m, $f . '.' . _LOG_ERREUR);
168
+	$m = "Erreur $e de $t: ".sql_error($serveur)."\nin ".sql_error_backtrace()."\n".trim($connexion['last']);
169
+	$f = $t.$serveur;
170
+	spip_log($m, $f.'.'._LOG_ERREUR);
171 171
 }
172 172
 
173 173
 /**
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 	// si en cours d'installation ou si db=@test@ on ne pose rien
250 250
 	// car c'est un test de connexion
251 251
 	if (!defined('_ECRIRE_INSTALL') and $db !== "@test@") {
252
-		$f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out';
252
+		$f = _DIR_TMP.$type.'.'.substr(md5($host.$port.$db), 0, 8).'.out';
253 253
 	} elseif ($db == '@test@') {
254 254
 		$db = '';
255 255
 	}
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 	// En cas d'indisponibilite du serveur, eviter de le bombarder
290 290
 	if ($f) {
291 291
 		@touch($f);
292
-		spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS);
292
+		spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type.'.'._LOG_HS);
293 293
 	}
294 294
 }
295 295
 
@@ -379,8 +379,7 @@  discard block
 block discarded – undo
379 379
  * @return string Valeur échappée.
380 380
  **/
381 381
 function _q($a) {
382
-	return (is_numeric($a)) ? strval($a) :
383
-		(!is_array($a) ? ("'" . addslashes($a) . "'")
382
+	return (is_numeric($a)) ? strval($a) : (!is_array($a) ? ("'".addslashes($a)."'")
384 383
 			: join(",", array_map('_q', $a)));
385 384
 }
386 385
 
@@ -452,7 +451,7 @@  discard block
 block discarded – undo
452 451
 				break;
453 452
 			default:
454 453
 				$replace = range(1, count($textes));
455
-				$replace = '%' . implode('$s,%', $replace) . '$s';
454
+				$replace = '%'.implode('$s,%', $replace).'$s';
456 455
 				$replace = explode(',', $replace);
457 456
 				break;
458 457
 		}
Please login to merge, or discard this patch.
Indentation   +309 added lines, -309 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\SQL
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 require_once _ROOT_RESTREINT . 'base/objets.php';
22 22
 
@@ -42,118 +42,118 @@  discard block
 block discarded – undo
42 42
  **/
43 43
 function spip_connect($serveur = '', $version = '') {
44 44
 
45
-	$serveur = !is_string($serveur) ? '' : strtolower($serveur);
46
-	$index = $serveur ? $serveur : 0;
47
-	if (!$version) {
48
-		$version = $GLOBALS['spip_sql_version'];
49
-	}
50
-	if (isset($GLOBALS['connexions'][$index][$version])) {
51
-		return $GLOBALS['connexions'][$index];
52
-	}
53
-
54
-	include_spip('base/abstract_sql');
55
-	$install = (_request('exec') == 'install');
56
-
57
-	// Premiere connexion ?
58
-	if (!($old = isset($GLOBALS['connexions'][$index]))) {
59
-		$f = (!preg_match('/^[\w\.]*$/', $serveur))
60
-			? '' // nom de serveur mal ecrit
61
-			: ($serveur ?
62
-				(_DIR_CONNECT . $serveur . '.php') // serveur externe
63
-				: (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok
64
-					: ($install ? _FILE_CONNECT_TMP // init du serveur principal
65
-						: ''))); // installation pas faite
66
-
67
-		unset($GLOBALS['db_ok']);
68
-		unset($GLOBALS['spip_connect_version']);
69
-		if ($f) {
70
-			if (is_readable($f)) {
71
-				include($f);
72
-			} elseif ($serveur and !$install) {
73
-				// chercher une declaration de serveur dans le path
74
-				// qui pourra un jour servir a declarer des bases sqlite
75
-				// par des plugins. Et sert aussi aux boucles POUR.
76
-				find_in_path("$serveur.php", 'connect/', true);
77
-			}
78
-		}
79
-		if (!isset($GLOBALS['db_ok'])) {
80
-			// fera mieux la prochaine fois
81
-			if ($install) {
82
-				return false;
83
-			}
84
-			if ($f and is_readable($f)) {
85
-				spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE);
86
-			} else {
87
-				spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE);
88
-			}
89
-			spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS);
90
-
91
-			// ne plus reessayer si ce n'est pas l'install
92
-			return $GLOBALS['connexions'][$index] = false;
93
-		}
94
-		$GLOBALS['connexions'][$index] = $GLOBALS['db_ok'];
95
-	}
96
-	// si la connexion a deja ete tentee mais a echoue, le dire!
97
-	if (!$GLOBALS['connexions'][$index]) {
98
-		return false;
99
-	}
100
-
101
-	// la connexion a reussi ou etait deja faite.
102
-	// chargement de la version du jeu de fonctions
103
-	// si pas dans le fichier par defaut
104
-	$type = $GLOBALS['db_ok']['type'];
105
-	$jeu = 'spip_' . $type . '_functions_' . $version;
106
-	if (!isset($GLOBALS[$jeu])) {
107
-		if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) {
108
-			spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS);
109
-
110
-			// ne plus reessayer
111
-			return $GLOBALS['connexions'][$index][$version] = array();
112
-		}
113
-	}
114
-	$GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu];
115
-	if ($old) {
116
-		return $GLOBALS['connexions'][$index];
117
-	}
118
-
119
-	$GLOBALS['connexions'][$index]['spip_connect_version'] = isset($GLOBALS['spip_connect_version']) ? $GLOBALS['spip_connect_version'] : 0;
120
-
121
-	// initialisation de l'alphabet utilise dans les connexions SQL
122
-	// si l'installation l'a determine.
123
-	// Celui du serveur principal l'impose aux serveurs secondaires
124
-	// s'ils le connaissent
125
-
126
-	if (!$serveur) {
127
-		$charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']);
128
-		if (!$charset) {
129
-			unset($GLOBALS['connexions'][$index]);
130
-			spip_log("spip_connect: absence de charset", _LOG_AVERTISSEMENT);
131
-
132
-			return false;
133
-		}
134
-	} else {
135
-		if ($GLOBALS['db_ok']['charset']) {
136
-			$charset = $GLOBALS['db_ok']['charset'];
137
-		}
138
-		// spip_meta n'existe pas toujours dans la base
139
-		// C'est le cas d'un dump sqlite par exemple 
140
-		elseif ($GLOBALS['connexions'][$index]['spip_connect_version']
141
-			and sql_showtable('spip_meta', true, $serveur)
142
-			and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur)
143
-		) {
144
-			$charset = $r;
145
-		} else {
146
-			$charset = -1;
147
-		}
148
-	}
149
-	if ($charset != -1) {
150
-		$f = $GLOBALS[$jeu]['set_charset'];
151
-		if (function_exists($f)) {
152
-			$f($charset, $serveur);
153
-		}
154
-	}
155
-
156
-	return $GLOBALS['connexions'][$index];
45
+    $serveur = !is_string($serveur) ? '' : strtolower($serveur);
46
+    $index = $serveur ? $serveur : 0;
47
+    if (!$version) {
48
+        $version = $GLOBALS['spip_sql_version'];
49
+    }
50
+    if (isset($GLOBALS['connexions'][$index][$version])) {
51
+        return $GLOBALS['connexions'][$index];
52
+    }
53
+
54
+    include_spip('base/abstract_sql');
55
+    $install = (_request('exec') == 'install');
56
+
57
+    // Premiere connexion ?
58
+    if (!($old = isset($GLOBALS['connexions'][$index]))) {
59
+        $f = (!preg_match('/^[\w\.]*$/', $serveur))
60
+            ? '' // nom de serveur mal ecrit
61
+            : ($serveur ?
62
+                (_DIR_CONNECT . $serveur . '.php') // serveur externe
63
+                : (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok
64
+                    : ($install ? _FILE_CONNECT_TMP // init du serveur principal
65
+                        : ''))); // installation pas faite
66
+
67
+        unset($GLOBALS['db_ok']);
68
+        unset($GLOBALS['spip_connect_version']);
69
+        if ($f) {
70
+            if (is_readable($f)) {
71
+                include($f);
72
+            } elseif ($serveur and !$install) {
73
+                // chercher une declaration de serveur dans le path
74
+                // qui pourra un jour servir a declarer des bases sqlite
75
+                // par des plugins. Et sert aussi aux boucles POUR.
76
+                find_in_path("$serveur.php", 'connect/', true);
77
+            }
78
+        }
79
+        if (!isset($GLOBALS['db_ok'])) {
80
+            // fera mieux la prochaine fois
81
+            if ($install) {
82
+                return false;
83
+            }
84
+            if ($f and is_readable($f)) {
85
+                spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE);
86
+            } else {
87
+                spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE);
88
+            }
89
+            spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS);
90
+
91
+            // ne plus reessayer si ce n'est pas l'install
92
+            return $GLOBALS['connexions'][$index] = false;
93
+        }
94
+        $GLOBALS['connexions'][$index] = $GLOBALS['db_ok'];
95
+    }
96
+    // si la connexion a deja ete tentee mais a echoue, le dire!
97
+    if (!$GLOBALS['connexions'][$index]) {
98
+        return false;
99
+    }
100
+
101
+    // la connexion a reussi ou etait deja faite.
102
+    // chargement de la version du jeu de fonctions
103
+    // si pas dans le fichier par defaut
104
+    $type = $GLOBALS['db_ok']['type'];
105
+    $jeu = 'spip_' . $type . '_functions_' . $version;
106
+    if (!isset($GLOBALS[$jeu])) {
107
+        if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) {
108
+            spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS);
109
+
110
+            // ne plus reessayer
111
+            return $GLOBALS['connexions'][$index][$version] = array();
112
+        }
113
+    }
114
+    $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu];
115
+    if ($old) {
116
+        return $GLOBALS['connexions'][$index];
117
+    }
118
+
119
+    $GLOBALS['connexions'][$index]['spip_connect_version'] = isset($GLOBALS['spip_connect_version']) ? $GLOBALS['spip_connect_version'] : 0;
120
+
121
+    // initialisation de l'alphabet utilise dans les connexions SQL
122
+    // si l'installation l'a determine.
123
+    // Celui du serveur principal l'impose aux serveurs secondaires
124
+    // s'ils le connaissent
125
+
126
+    if (!$serveur) {
127
+        $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']);
128
+        if (!$charset) {
129
+            unset($GLOBALS['connexions'][$index]);
130
+            spip_log("spip_connect: absence de charset", _LOG_AVERTISSEMENT);
131
+
132
+            return false;
133
+        }
134
+    } else {
135
+        if ($GLOBALS['db_ok']['charset']) {
136
+            $charset = $GLOBALS['db_ok']['charset'];
137
+        }
138
+        // spip_meta n'existe pas toujours dans la base
139
+        // C'est le cas d'un dump sqlite par exemple 
140
+        elseif ($GLOBALS['connexions'][$index]['spip_connect_version']
141
+            and sql_showtable('spip_meta', true, $serveur)
142
+            and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur)
143
+        ) {
144
+            $charset = $r;
145
+        } else {
146
+            $charset = -1;
147
+        }
148
+    }
149
+    if ($charset != -1) {
150
+        $f = $GLOBALS[$jeu]['set_charset'];
151
+        if (function_exists($f)) {
152
+            $f($charset, $serveur);
153
+        }
154
+    }
155
+
156
+    return $GLOBALS['connexions'][$index];
157 157
 }
158 158
 
159 159
 /**
@@ -162,12 +162,12 @@  discard block
 block discarded – undo
162 162
  * @param string $serveur Nom du connecteur de bdd utilisé
163 163
  **/
164 164
 function spip_sql_erreur($serveur = '') {
165
-	$connexion = spip_connect($serveur);
166
-	$e = sql_errno($serveur);
167
-	$t = (isset($connexion['type']) ? $connexion['type'] : 'sql');
168
-	$m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']);
169
-	$f = $t . $serveur;
170
-	spip_log($m, $f . '.' . _LOG_ERREUR);
165
+    $connexion = spip_connect($serveur);
166
+    $e = sql_errno($serveur);
167
+    $t = (isset($connexion['type']) ? $connexion['type'] : 'sql');
168
+    $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']);
169
+    $f = $t . $serveur;
170
+    spip_log($m, $f . '.' . _LOG_ERREUR);
171 171
 }
172 172
 
173 173
 /**
@@ -189,19 +189,19 @@  discard block
 block discarded – undo
189 189
  *     - array : description de la connexion, si l'instruction sql est indisponible pour cette connexion
190 190
  **/
191 191
 function spip_connect_sql($version, $ins = '', $serveur = '', $continue = false) {
192
-	$desc = spip_connect($serveur, $version);
193
-	if (function_exists($f = @$desc[$version][$ins])) {
194
-		return $f;
195
-	}
196
-	if ($continue) {
197
-		return $desc;
198
-	}
199
-	if ($ins) {
200
-		spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR);
201
-	}
202
-	include_spip('inc/minipres');
203
-	echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), array('status' => 503));
204
-	exit;
192
+    $desc = spip_connect($serveur, $version);
193
+    if (function_exists($f = @$desc[$version][$ins])) {
194
+        return $f;
195
+    }
196
+    if ($continue) {
197
+        return $desc;
198
+    }
199
+    if ($ins) {
200
+        spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR);
201
+    }
202
+    include_spip('inc/minipres');
203
+    echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), array('status' => 503));
204
+    exit;
205 205
 }
206 206
 
207 207
 /**
@@ -227,70 +227,70 @@  discard block
 block discarded – undo
227 227
  * @return array          Description de la connexion
228 228
  */
229 229
 function spip_connect_db(
230
-	$host,
231
-	$port,
232
-	$login,
233
-	$pass,
234
-	$db = '',
235
-	$type = 'mysql',
236
-	$prefixe = '',
237
-	$auth = '',
238
-	$charset = ''
230
+    $host,
231
+    $port,
232
+    $login,
233
+    $pass,
234
+    $db = '',
235
+    $type = 'mysql',
236
+    $prefixe = '',
237
+    $auth = '',
238
+    $charset = ''
239 239
 ) {
240
-	// temps avant nouvelle tentative de connexion
241
-	// suite a une connection echouee
242
-	if (!defined('_CONNECT_RETRY_DELAY')) {
243
-		define('_CONNECT_RETRY_DELAY', 30);
244
-	}
245
-
246
-	$f = "";
247
-	// un fichier de identifiant par combinaison (type,host,port,db)
248
-	// pour ne pas declarer tout indisponible d'un coup
249
-	// si en cours d'installation ou si db=@test@ on ne pose rien
250
-	// car c'est un test de connexion
251
-	if (!defined('_ECRIRE_INSTALL') and $db !== "@test@") {
252
-		$f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out';
253
-	} elseif ($db == '@test@') {
254
-		$db = '';
255
-	}
256
-
257
-	if ($f
258
-		and @file_exists($f)
259
-		and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY)
260
-	) {
261
-		spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS);
262
-
263
-		return;
264
-	}
265
-
266
-	if (!$prefixe) {
267
-		$prefixe = isset($GLOBALS['table_prefix'])
268
-			? $GLOBALS['table_prefix'] : $db;
269
-	}
270
-	$h = charger_fonction($type, 'req', true);
271
-	if (!$h) {
272
-		spip_log("les requetes $type ne sont pas fournies", _LOG_HS);
273
-
274
-		return;
275
-	}
276
-	if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) {
277
-
278
-		if (!is_array($auth)) {
279
-			// compatibilite version 0.7 initiale
280
-			$g['ldap'] = $auth;
281
-			$auth = array('ldap' => $auth);
282
-		}
283
-		$g['authentification'] = $auth;
284
-		$g['type'] = $type;
285
-		$g['charset'] = $charset;
286
-
287
-		return $GLOBALS['db_ok'] = $g;
288
-	}
289
-	// En cas d'indisponibilite du serveur, eviter de le bombarder
290
-	if ($f) {
291
-		@touch($f);
292
-		spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS);
293
-	}
240
+    // temps avant nouvelle tentative de connexion
241
+    // suite a une connection echouee
242
+    if (!defined('_CONNECT_RETRY_DELAY')) {
243
+        define('_CONNECT_RETRY_DELAY', 30);
244
+    }
245
+
246
+    $f = "";
247
+    // un fichier de identifiant par combinaison (type,host,port,db)
248
+    // pour ne pas declarer tout indisponible d'un coup
249
+    // si en cours d'installation ou si db=@test@ on ne pose rien
250
+    // car c'est un test de connexion
251
+    if (!defined('_ECRIRE_INSTALL') and $db !== "@test@") {
252
+        $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out';
253
+    } elseif ($db == '@test@') {
254
+        $db = '';
255
+    }
256
+
257
+    if ($f
258
+        and @file_exists($f)
259
+        and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY)
260
+    ) {
261
+        spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS);
262
+
263
+        return;
264
+    }
265
+
266
+    if (!$prefixe) {
267
+        $prefixe = isset($GLOBALS['table_prefix'])
268
+            ? $GLOBALS['table_prefix'] : $db;
269
+    }
270
+    $h = charger_fonction($type, 'req', true);
271
+    if (!$h) {
272
+        spip_log("les requetes $type ne sont pas fournies", _LOG_HS);
273
+
274
+        return;
275
+    }
276
+    if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) {
277
+
278
+        if (!is_array($auth)) {
279
+            // compatibilite version 0.7 initiale
280
+            $g['ldap'] = $auth;
281
+            $auth = array('ldap' => $auth);
282
+        }
283
+        $g['authentification'] = $auth;
284
+        $g['type'] = $type;
285
+        $g['charset'] = $charset;
286
+
287
+        return $GLOBALS['db_ok'] = $g;
288
+    }
289
+    // En cas d'indisponibilite du serveur, eviter de le bombarder
290
+    if ($f) {
291
+        @touch($f);
292
+        spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS);
293
+    }
294 294
 }
295 295
 
296 296
 
@@ -322,31 +322,31 @@  discard block
 block discarded – undo
322 322
  *     - nom du charset sinon
323 323
  **/
324 324
 function spip_connect_main($connexion, $charset_sql_connexion = '') {
325
-	if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) {
326
-		include_spip('inc/headers');
327
-		redirige_url_ecrire('upgrade', 'reinstall=oui');
328
-	}
329
-
330
-	if (!($f = $connexion['select'])) {
331
-		return false;
332
-	}
333
-	// si le charset est fourni, l'utiliser
334
-	if ($charset_sql_connexion) {
335
-		return $charset_sql_connexion;
336
-	}
337
-	// sinon on regarde la table spip_meta
338
-	// en cas d'erreur select retourne la requette (is_string=true donc)
339
-	if (!$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'")
340
-		or is_string($r)
341
-	) {
342
-		return false;
343
-	}
344
-	if (!($f = $connexion['fetch'])) {
345
-		return false;
346
-	}
347
-	$r = $f($r);
348
-
349
-	return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1;
325
+    if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) {
326
+        include_spip('inc/headers');
327
+        redirige_url_ecrire('upgrade', 'reinstall=oui');
328
+    }
329
+
330
+    if (!($f = $connexion['select'])) {
331
+        return false;
332
+    }
333
+    // si le charset est fourni, l'utiliser
334
+    if ($charset_sql_connexion) {
335
+        return $charset_sql_connexion;
336
+    }
337
+    // sinon on regarde la table spip_meta
338
+    // en cas d'erreur select retourne la requette (is_string=true donc)
339
+    if (!$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'")
340
+        or is_string($r)
341
+    ) {
342
+        return false;
343
+    }
344
+    if (!($f = $connexion['fetch'])) {
345
+        return false;
346
+    }
347
+    $r = $f($r);
348
+
349
+    return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1;
350 350
 }
351 351
 
352 352
 /**
@@ -361,9 +361,9 @@  discard block
 block discarded – undo
361 361
  * @return array
362 362
  */
363 363
 function spip_connect_ldap($serveur = '') {
364
-	include_spip('auth/ldap');
364
+    include_spip('auth/ldap');
365 365
 
366
-	return auth_ldap_connect($serveur);
366
+    return auth_ldap_connect($serveur);
367 367
 }
368 368
 
369 369
 /**
@@ -379,9 +379,9 @@  discard block
 block discarded – undo
379 379
  * @return string Valeur échappée.
380 380
  **/
381 381
 function _q($a) {
382
-	return (is_numeric($a)) ? strval($a) :
383
-		(!is_array($a) ? ("'" . addslashes($a) . "'")
384
-			: join(",", array_map('_q', $a)));
382
+    return (is_numeric($a)) ? strval($a) :
383
+        (!is_array($a) ? ("'" . addslashes($a) . "'")
384
+            : join(",", array_map('_q', $a)));
385 385
 }
386 386
 
387 387
 
@@ -399,19 +399,19 @@  discard block
 block discarded – undo
399 399
  *     - chaîne vide si non trouvé.
400 400
  **/
401 401
 function table_jointure($x, $y) {
402
-	$trouver_table = charger_fonction('trouver_table', 'base');
403
-	$xdesc = $trouver_table(table_objet($x));
404
-	$ydesc = $trouver_table(table_objet($y));
405
-	$ix = @$xdesc['key']["PRIMARY KEY"];
406
-	$iy = @$ydesc['key']["PRIMARY KEY"];
407
-	if ($table = $ydesc['tables_jointures'][$ix]) {
408
-		return $table;
409
-	}
410
-	if ($table = $xdesc['tables_jointures'][$iy]) {
411
-		return $table;
412
-	}
413
-
414
-	return '';
402
+    $trouver_table = charger_fonction('trouver_table', 'base');
403
+    $xdesc = $trouver_table(table_objet($x));
404
+    $ydesc = $trouver_table(table_objet($y));
405
+    $ix = @$xdesc['key']["PRIMARY KEY"];
406
+    $iy = @$ydesc['key']["PRIMARY KEY"];
407
+    if ($table = $ydesc['tables_jointures'][$ix]) {
408
+        return $table;
409
+    }
410
+    if ($table = $xdesc['tables_jointures'][$iy]) {
411
+        return $table;
412
+    }
413
+
414
+    return '';
415 415
 }
416 416
 
417 417
 /**
@@ -427,41 +427,41 @@  discard block
 block discarded – undo
427 427
  * @return array
428 428
  */
429 429
 function query_echappe_textes($query) {
430
-	static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3");
431
-	$query = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query);
432
-	if (preg_match_all("/((['])[^']*(\\2))|(([\"])[^\"]*(\\5))/S", $query, $textes)) {
433
-		$textes = reset($textes); // indice 0 du match
434
-		switch (count($textes)) {
435
-			case 0:
436
-				$replace = array();
437
-				break;
438
-			case 1:
439
-				$replace = array('%1$s');
440
-				break;
441
-			case 2:
442
-				$replace = array('%1$s', '%2$s');
443
-				break;
444
-			case 3:
445
-				$replace = array('%1$s', '%2$s', '%3$s');
446
-				break;
447
-			case 4:
448
-				$replace = array('%1$s', '%2$s', '%3$s', '%4$s');
449
-				break;
450
-			case 5:
451
-				$replace = array('%1$s', '%2$s', '%3$s', '%4$s', '%5$s');
452
-				break;
453
-			default:
454
-				$replace = range(1, count($textes));
455
-				$replace = '%' . implode('$s,%', $replace) . '$s';
456
-				$replace = explode(',', $replace);
457
-				break;
458
-		}
459
-		$query = str_replace($textes, $replace, $query);
460
-	} else {
461
-		$textes = array();
462
-	}
463
-
464
-	return array($query, $textes);
430
+    static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3");
431
+    $query = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query);
432
+    if (preg_match_all("/((['])[^']*(\\2))|(([\"])[^\"]*(\\5))/S", $query, $textes)) {
433
+        $textes = reset($textes); // indice 0 du match
434
+        switch (count($textes)) {
435
+            case 0:
436
+                $replace = array();
437
+                break;
438
+            case 1:
439
+                $replace = array('%1$s');
440
+                break;
441
+            case 2:
442
+                $replace = array('%1$s', '%2$s');
443
+                break;
444
+            case 3:
445
+                $replace = array('%1$s', '%2$s', '%3$s');
446
+                break;
447
+            case 4:
448
+                $replace = array('%1$s', '%2$s', '%3$s', '%4$s');
449
+                break;
450
+            case 5:
451
+                $replace = array('%1$s', '%2$s', '%3$s', '%4$s', '%5$s');
452
+                break;
453
+            default:
454
+                $replace = range(1, count($textes));
455
+                $replace = '%' . implode('$s,%', $replace) . '$s';
456
+                $replace = explode(',', $replace);
457
+                break;
458
+        }
459
+        $query = str_replace($textes, $replace, $query);
460
+    } else {
461
+        $textes = array();
462
+    }
463
+
464
+    return array($query, $textes);
465 465
 }
466 466
 
467 467
 /**
@@ -475,40 +475,40 @@  discard block
 block discarded – undo
475 475
  * @return string
476 476
  */
477 477
 function query_reinjecte_textes($query, $textes) {
478
-	static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3");
479
-	# debug de la substitution
480
-	#if (($c1=substr_count($query,"%"))!=($c2=count($textes))){
481
-	#	spip_log("$c1 ::". $query,"tradquery"._LOG_ERREUR);
482
-	#	spip_log("$c2 ::". var_export($textes,1),"tradquery"._LOG_ERREUR);
483
-	#	spip_log("ini ::". $qi,"tradquery"._LOG_ERREUR);
484
-	#}
485
-	switch (count($textes)) {
486
-		case 0:
487
-			break;
488
-		case 1:
489
-			$query = sprintf($query, $textes[0]);
490
-			break;
491
-		case 2:
492
-			$query = sprintf($query, $textes[0], $textes[1]);
493
-			break;
494
-		case 3:
495
-			$query = sprintf($query, $textes[0], $textes[1], $textes[2]);
496
-			break;
497
-		case 4:
498
-			$query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3]);
499
-			break;
500
-		case 5:
501
-			$query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3], $textes[4]);
502
-			break;
503
-		default:
504
-			array_unshift($textes, $query);
505
-			$query = call_user_func_array('sprintf', $textes);
506
-			break;
507
-	}
508
-
509
-	$query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query);
510
-
511
-	return $query;
478
+    static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3");
479
+    # debug de la substitution
480
+    #if (($c1=substr_count($query,"%"))!=($c2=count($textes))){
481
+    #	spip_log("$c1 ::". $query,"tradquery"._LOG_ERREUR);
482
+    #	spip_log("$c2 ::". var_export($textes,1),"tradquery"._LOG_ERREUR);
483
+    #	spip_log("ini ::". $qi,"tradquery"._LOG_ERREUR);
484
+    #}
485
+    switch (count($textes)) {
486
+        case 0:
487
+            break;
488
+        case 1:
489
+            $query = sprintf($query, $textes[0]);
490
+            break;
491
+        case 2:
492
+            $query = sprintf($query, $textes[0], $textes[1]);
493
+            break;
494
+        case 3:
495
+            $query = sprintf($query, $textes[0], $textes[1], $textes[2]);
496
+            break;
497
+        case 4:
498
+            $query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3]);
499
+            break;
500
+        case 5:
501
+            $query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3], $textes[4]);
502
+            break;
503
+        default:
504
+            array_unshift($textes, $query);
505
+            $query = call_user_func_array('sprintf', $textes);
506
+            break;
507
+    }
508
+
509
+    $query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query);
510
+
511
+    return $query;
512 512
 }
513 513
 
514 514
 
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
  **/
528 528
 function spip_query($query, $serveur = '') {
529 529
 
530
-	$f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true);
530
+    $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true);
531 531
 
532
-	return function_exists($f) ? $f($query, $serveur) : false;
532
+    return function_exists($f) ? $f($query, $serveur) : false;
533 533
 }
Please login to merge, or discard this patch.
ecrire/exec/rechercher.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@
 block discarded – undo
52 52
  *
53 53
  * @param int $id
54 54
  * @param string $type
55
- * @param string|int|array $exclus
55
+ * @param integer $exclus
56 56
  * @param string|bool $rac
57 57
  * @param string $do
58 58
  * @return string
Please login to merge, or discard this patch.
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  **/
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 
24 24
 include_spip('inc/actions');
@@ -31,17 +31,17 @@  discard block
 block discarded – undo
31 31
  * @uses ajax_retour()
32 32
  **/
33 33
 function exec_rechercher_dist() {
34
-	$id = intval(_request('id'));
35
-	$exclus = intval(_request('exclus'));
36
-	$rac = spip_htmlentities(_request('rac'));
37
-	$type = _request('type');
38
-	$do = _request('do');
39
-	if (preg_match('/^\w*$/', $do)) {
40
-		$r = exec_rechercher_args($id, $type, $exclus, $rac, $do);
41
-	} else {
42
-		$r = '';
43
-	}
44
-	ajax_retour($r);
34
+    $id = intval(_request('id'));
35
+    $exclus = intval(_request('exclus'));
36
+    $rac = spip_htmlentities(_request('rac'));
37
+    $type = _request('type');
38
+    $do = _request('do');
39
+    if (preg_match('/^\w*$/', $do)) {
40
+        $r = exec_rechercher_args($id, $type, $exclus, $rac, $do);
41
+    } else {
42
+        $r = '';
43
+    }
44
+    ajax_retour($r);
45 45
 }
46 46
 
47 47
 /**
@@ -58,59 +58,59 @@  discard block
 block discarded – undo
58 58
  * @return string
59 59
  **/
60 60
 function exec_rechercher_args($id, $type, $exclus, $rac, $do) {
61
-	if (!$do) {
62
-		$do = 'aff';
63
-	}
64
-
65
-	$points = $rub = array();
66
-
67
-	$where = preg_split(",\s+,", $type);
68
-	if ($where) {
69
-		foreach ($where as $k => $v) {
70
-			$where[$k] = "'%" . substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1) . "%'";
71
-		}
72
-		$where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")");
73
-		$where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")");
74
-		$where_id = ("(id_rubrique = " . intval($type) . ")");
75
-
76
-		if ($exclus) {
77
-			include_spip('inc/rubriques');
78
-			$where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT');
79
-		} else {
80
-			$where_exclus = '';
81
-		}
82
-
83
-		foreach (array(
84
-			3 => $where_titre,
85
-			2 => $where_desc,
86
-			1 => $where_id,
87
-		) as $point => $recherche) {
88
-			$res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$recherche$where_exclus");
89
-			while ($row = sql_fetch($res)) {
90
-				$id_rubrique = $row["id_rubrique"];
91
-				if (!isset($rub[$id_rubrique])) {
92
-					$rub[$id_rubrique] = array();
93
-				}
94
-				$rub[$id_rubrique]["titre"] = typo($row["titre"]);
95
-				$rub[$id_rubrique]["id_parent"] = $row["id_parent"];
96
-				if (!isset($points[$id_rubrique])) {
97
-					$points[$id_rubrique] = 0;
98
-				}
99
-				$points[$id_rubrique] = $points[$id_rubrique] + $point;
100
-			}
101
-		}
102
-	}
103
-
104
-	if ($points) {
105
-		arsort($points);
106
-		$style = " style='background-image: url(" . chemin_image('secteur-12.png') . ")'";
107
-		foreach ($rub as $k => $v) {
108
-			$rub[$k]['atts'] = ($v["id_parent"] ? $style : '')
109
-				. " class='petite-rubrique'";
110
-		}
111
-	}
112
-
113
-	return (proposer_item($points, $rub, $rac, $type, $do));
61
+    if (!$do) {
62
+        $do = 'aff';
63
+    }
64
+
65
+    $points = $rub = array();
66
+
67
+    $where = preg_split(",\s+,", $type);
68
+    if ($where) {
69
+        foreach ($where as $k => $v) {
70
+            $where[$k] = "'%" . substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1) . "%'";
71
+        }
72
+        $where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")");
73
+        $where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")");
74
+        $where_id = ("(id_rubrique = " . intval($type) . ")");
75
+
76
+        if ($exclus) {
77
+            include_spip('inc/rubriques');
78
+            $where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT');
79
+        } else {
80
+            $where_exclus = '';
81
+        }
82
+
83
+        foreach (array(
84
+            3 => $where_titre,
85
+            2 => $where_desc,
86
+            1 => $where_id,
87
+        ) as $point => $recherche) {
88
+            $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$recherche$where_exclus");
89
+            while ($row = sql_fetch($res)) {
90
+                $id_rubrique = $row["id_rubrique"];
91
+                if (!isset($rub[$id_rubrique])) {
92
+                    $rub[$id_rubrique] = array();
93
+                }
94
+                $rub[$id_rubrique]["titre"] = typo($row["titre"]);
95
+                $rub[$id_rubrique]["id_parent"] = $row["id_parent"];
96
+                if (!isset($points[$id_rubrique])) {
97
+                    $points[$id_rubrique] = 0;
98
+                }
99
+                $points[$id_rubrique] = $points[$id_rubrique] + $point;
100
+            }
101
+        }
102
+    }
103
+
104
+    if ($points) {
105
+        arsort($points);
106
+        $style = " style='background-image: url(" . chemin_image('secteur-12.png') . ")'";
107
+        foreach ($rub as $k => $v) {
108
+            $rub[$k]['atts'] = ($v["id_parent"] ? $style : '')
109
+                . " class='petite-rubrique'";
110
+        }
111
+    }
112
+
113
+    return (proposer_item($points, $rub, $rac, $type, $do));
114 114
 }
115 115
 
116 116
 
@@ -133,35 +133,35 @@  discard block
 block discarded – undo
133 133
  **/
134 134
 function proposer_item($ids, $titles, $rac, $type, $do) {
135 135
 
136
-	if (!$ids) {
137
-		return "<br /><br /><div style='padding: 5px; color: red;'><b>"
138
-		. spip_htmlentities($type)
139
-		. "</b> :  " . _T('avis_aucun_resultat') . "</div>";
140
-	}
136
+    if (!$ids) {
137
+        return "<br /><br /><div style='padding: 5px; color: red;'><b>"
138
+        . spip_htmlentities($type)
139
+        . "</b> :  " . _T('avis_aucun_resultat') . "</div>";
140
+    }
141 141
 
142
-	$ret = '';
143
-	$info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id=");
142
+    $ret = '';
143
+    $info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id=");
144 144
 
145
-	$onClick = "aff_selection(this.firstChild.title,'$rac" . "_selection','$info', event)";
145
+    $onClick = "aff_selection(this.firstChild.title,'$rac" . "_selection','$info', event)";
146 146
 
147
-	$ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');";
147
+    $ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');";
148 148
 
149
-	foreach ($ids as $id => $bof) {
149
+    foreach ($ids as $id => $bof) {
150 150
 
151
-		$titre = strtr(str_replace("'", "&#8217;", str_replace('"', "&#34;", textebrut($titles[$id]["titre"]))), "\n\r",
152
-			"  ");
151
+        $titre = strtr(str_replace("'", "&#8217;", str_replace('"', "&#34;", textebrut($titles[$id]["titre"]))), "\n\r",
152
+            "  ");
153 153
 
154
-		$ret .= "<div class='highlight off'\nonclick=\"changerhighlight(this); "
155
-			. $onClick
156
-			. "\"\nondblclick=\""
157
-			. $ondbClick
158
-			. $onClick
159
-			. " \"><div"
160
-			. $titles[$id]["atts"]
161
-			. " title='$id'>&nbsp; "
162
-			. $titre
163
-			. "</div></div>";
164
-	}
154
+        $ret .= "<div class='highlight off'\nonclick=\"changerhighlight(this); "
155
+            . $onClick
156
+            . "\"\nondblclick=\""
157
+            . $ondbClick
158
+            . $onClick
159
+            . " \"><div"
160
+            . $titles[$id]["atts"]
161
+            . " title='$id'>&nbsp; "
162
+            . $titre
163
+            . "</div></div>";
164
+    }
165 165
 
166
-	return $ret;
166
+    return $ret;
167 167
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -67,15 +67,15 @@  discard block
 block discarded – undo
67 67
 	$where = preg_split(",\s+,", $type);
68 68
 	if ($where) {
69 69
 		foreach ($where as $k => $v) {
70
-			$where[$k] = "'%" . substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1) . "%'";
70
+			$where[$k] = "'%".substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1)."%'";
71 71
 		}
72
-		$where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")");
73
-		$where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")");
74
-		$where_id = ("(id_rubrique = " . intval($type) . ")");
72
+		$where_titre = ("(titre LIKE ".join(" AND titre LIKE ", $where).")");
73
+		$where_desc = ("(descriptif LIKE ".join(" AND descriptif LIKE ", $where).")");
74
+		$where_id = ("(id_rubrique = ".intval($type).")");
75 75
 
76 76
 		if ($exclus) {
77 77
 			include_spip('inc/rubriques');
78
-			$where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT');
78
+			$where_exclus = " AND ".sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT');
79 79
 		} else {
80 80
 			$where_exclus = '';
81 81
 		}
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 
104 104
 	if ($points) {
105 105
 		arsort($points);
106
-		$style = " style='background-image: url(" . chemin_image('secteur-12.png') . ")'";
106
+		$style = " style='background-image: url(".chemin_image('secteur-12.png').")'";
107 107
 		foreach ($rub as $k => $v) {
108 108
 			$rub[$k]['atts'] = ($v["id_parent"] ? $style : '')
109 109
 				. " class='petite-rubrique'";
@@ -136,13 +136,13 @@  discard block
 block discarded – undo
136 136
 	if (!$ids) {
137 137
 		return "<br /><br /><div style='padding: 5px; color: red;'><b>"
138 138
 		. spip_htmlentities($type)
139
-		. "</b> :  " . _T('avis_aucun_resultat') . "</div>";
139
+		. "</b> :  "._T('avis_aucun_resultat')."</div>";
140 140
 	}
141 141
 
142 142
 	$ret = '';
143 143
 	$info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id=");
144 144
 
145
-	$onClick = "aff_selection(this.firstChild.title,'$rac" . "_selection','$info', event)";
145
+	$onClick = "aff_selection(this.firstChild.title,'$rac"."_selection','$info', event)";
146 146
 
147 147
 	$ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');";
148 148
 
Please login to merge, or discard this patch.
ecrire/genie/maintenance.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@
 block discarded – undo
31 31
  * @uses verifier_crash_tables()
32 32
  *
33 33
  * @param object $t
34
- * @return bool Toujours à true.
34
+ * @return integer Toujours à true.
35 35
  */
36 36
 function genie_maintenance_dist($t) {
37 37
 
Please login to merge, or discard this patch.
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -35,18 +35,18 @@  discard block
 block discarded – undo
35 35
  */
36 36
 function genie_maintenance_dist($t) {
37 37
 
38
-	// (re)mettre .htaccess avec deny from all
39
-	// dans les deux repertoires dits inaccessibles par http
40
-	include_spip('inc/acces');
41
-	verifier_htaccess(_DIR_ETC);
42
-	verifier_htaccess(_DIR_TMP);
38
+    // (re)mettre .htaccess avec deny from all
39
+    // dans les deux repertoires dits inaccessibles par http
40
+    include_spip('inc/acces');
41
+    verifier_htaccess(_DIR_ETC);
42
+    verifier_htaccess(_DIR_TMP);
43 43
 
44
-	// Verifier qu'aucune table n'est crashee
45
-	if (!_request('reinstall')) {
46
-		verifier_crash_tables();
47
-	}
44
+    // Verifier qu'aucune table n'est crashee
45
+    if (!_request('reinstall')) {
46
+        verifier_crash_tables();
47
+    }
48 48
 
49
-	return 1;
49
+    return 1;
50 50
 }
51 51
 
52 52
 
@@ -63,33 +63,33 @@  discard block
 block discarded – undo
63 63
  *     des tables qui ont crashé.
64 64
  */
65 65
 function verifier_crash_tables() {
66
-	if (spip_connect()) {
67
-		include_spip('base/serial');
68
-		include_spip('base/auxiliaires');
69
-		$crash = array();
70
-		foreach (array('tables_principales', 'tables_auxiliaires') as $com) {
71
-			foreach ($GLOBALS[$com] as $table => $desc) {
72
-				if (!sql_select('*', $table, '', '', '', 1)
73
-					and !defined('spip_interdire_cache')
74
-				) # cas "LOST CONNECTION"
75
-				{
76
-					$crash[] = $table;
77
-				}
78
-			}
79
-		}
80
-		#$crash[] = 'test';
81
-		if ($crash) {
82
-			ecrire_meta('message_crash_tables', serialize($crash));
83
-			spip_log('crash des tables', 'err');
84
-			spip_log($crash, 'err');
85
-		} else {
86
-			effacer_meta('message_crash_tables');
87
-		}
66
+    if (spip_connect()) {
67
+        include_spip('base/serial');
68
+        include_spip('base/auxiliaires');
69
+        $crash = array();
70
+        foreach (array('tables_principales', 'tables_auxiliaires') as $com) {
71
+            foreach ($GLOBALS[$com] as $table => $desc) {
72
+                if (!sql_select('*', $table, '', '', '', 1)
73
+                    and !defined('spip_interdire_cache')
74
+                ) # cas "LOST CONNECTION"
75
+                {
76
+                    $crash[] = $table;
77
+                }
78
+            }
79
+        }
80
+        #$crash[] = 'test';
81
+        if ($crash) {
82
+            ecrire_meta('message_crash_tables', serialize($crash));
83
+            spip_log('crash des tables', 'err');
84
+            spip_log($crash, 'err');
85
+        } else {
86
+            effacer_meta('message_crash_tables');
87
+        }
88 88
 
89
-		return $crash;
90
-	}
89
+        return $crash;
90
+    }
91 91
 
92
-	return false;
92
+    return false;
93 93
 }
94 94
 
95 95
 /**
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
  * @return string
106 106
  */
107 107
 function message_crash_tables() {
108
-	if ($crash = verifier_crash_tables()) {
109
-		return
110
-			'<strong>' . _T('texte_recuperer_base') . '</strong><br />'
111
-			. ' <tt>' . join(', ', $crash) . '</tt><br />'
112
-			. generer_form_ecrire('base_repair',
113
-				_T('texte_crash_base'), '',
114
-				_T('bouton_tenter_recuperation'));
115
-	}
108
+    if ($crash = verifier_crash_tables()) {
109
+        return
110
+            '<strong>' . _T('texte_recuperer_base') . '</strong><br />'
111
+            . ' <tt>' . join(', ', $crash) . '</tt><br />'
112
+            . generer_form_ecrire('base_repair',
113
+                _T('texte_crash_base'), '',
114
+                _T('bouton_tenter_recuperation'));
115
+    }
116 116
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -107,8 +107,8 @@
 block discarded – undo
107 107
 function message_crash_tables() {
108 108
 	if ($crash = verifier_crash_tables()) {
109 109
 		return
110
-			'<strong>' . _T('texte_recuperer_base') . '</strong><br />'
111
-			. ' <tt>' . join(', ', $crash) . '</tt><br />'
110
+			'<strong>'._T('texte_recuperer_base').'</strong><br />'
111
+			. ' <tt>'.join(', ', $crash).'</tt><br />'
112 112
 			. generer_form_ecrire('base_repair',
113 113
 				_T('texte_crash_base'), '',
114 114
 				_T('bouton_tenter_recuperation'));
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -71,10 +71,12 @@
 block discarded – undo
71 71
 			foreach ($GLOBALS[$com] as $table => $desc) {
72 72
 				if (!sql_select('*', $table, '', '', '', 1)
73 73
 					and !defined('spip_interdire_cache')
74
-				) # cas "LOST CONNECTION"
74
+				) {
75
+				    # cas "LOST CONNECTION"
75 76
 				{
76 77
 					$crash[] = $table;
77 78
 				}
79
+				}
78 80
 			}
79 81
 		}
80 82
 		#$crash[] = 'test';
Please login to merge, or discard this patch.
ecrire/inc/autoriser.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1654,7 +1654,7 @@
 block discarded – undo
1654 1654
  *
1655 1655
  * @param string $objet
1656 1656
  * @param int $id_objet
1657
- * @param string|array $cond
1657
+ * @param string $cond
1658 1658
  *     Condition(s) supplémentaire(s) pour le where de la requête
1659 1659
  * @return int[]
1660 1660
  *     Identifiants d'auteurs
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 // mais apres la fonction autoriser()
115 115
 if ($f = find_in_path('mes_fonctions.php')) {
116 116
 	global $dossier_squelettes;
117
-	include_once(_ROOT_CWD . $f);
117
+	include_once(_ROOT_CWD.$f);
118 118
 }
119 119
 
120 120
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 		$qui = $GLOBALS['visiteur_session'] ? $GLOBALS['visiteur_session'] : array();
149 149
 		$qui = array_merge(array('statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'), $qui);
150 150
 	} elseif (is_numeric($qui)) {
151
-		$qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui);
151
+		$qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur='.$qui);
152 152
 	}
153 153
 
154 154
 	// Admins restreints, on construit ici (pas generique mais...)
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
 	}
159 159
 
160 160
 	spip_log(
161
-		"autoriser $faire $type $id (" . (isset($qui['nom']) ? $qui['nom'] : '') . ') ?',
162
-		'autoriser' . _LOG_DEBUG
161
+		"autoriser $faire $type $id (".(isset($qui['nom']) ? $qui['nom'] : '').') ?',
162
+		'autoriser'._LOG_DEBUG
163 163
 	);
164 164
 
165 165
 	// passer par objet_type pour avoir les alias
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	if ((isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) and autoriser_exception($faire, $type, $id, 'verifier'))
171 171
 	  or (isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) and autoriser_exception($faire, $type, '*', 'verifier'))
172 172
 	) {
173
-		spip_log("autoriser ($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG);
173
+		spip_log("autoriser ($faire, $type, $id, ".(isset($qui['nom']) ? $qui['nom'] : '').') : OK Exception', 'autoriser'._LOG_DEBUG);
174 174
 		return true;
175 175
 	}
176 176
 
@@ -179,18 +179,18 @@  discard block
 block discarded – undo
179 179
 	// autoriser_faire[_dist], autoriser_defaut[_dist]
180 180
 	$fonctions = $type
181 181
 		? array(
182
-			'autoriser_' . $type . '_' . $faire,
183
-			'autoriser_' . $type . '_' . $faire . '_dist',
184
-			'autoriser_' . $type,
185
-			'autoriser_' . $type . '_dist',
186
-			'autoriser_' . $faire,
187
-			'autoriser_' . $faire . '_dist',
182
+			'autoriser_'.$type.'_'.$faire,
183
+			'autoriser_'.$type.'_'.$faire.'_dist',
184
+			'autoriser_'.$type,
185
+			'autoriser_'.$type.'_dist',
186
+			'autoriser_'.$faire,
187
+			'autoriser_'.$faire.'_dist',
188 188
 			'autoriser_defaut',
189 189
 			'autoriser_defaut_dist'
190 190
 		)
191 191
 		: array(
192
-			'autoriser_' . $faire,
193
-			'autoriser_' . $faire . '_dist',
192
+			'autoriser_'.$faire,
193
+			'autoriser_'.$faire.'_dist',
194 194
 			'autoriser_defaut',
195 195
 			'autoriser_defaut_dist'
196 196
 		);
@@ -203,8 +203,8 @@  discard block
 block discarded – undo
203 203
 	}
204 204
 
205 205
 	spip_log(
206
-		"$f($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : ' . ($a ? 'OK' : 'niet'),
207
-		'autoriser' . _LOG_DEBUG
206
+		"$f($faire, $type, $id, ".(isset($qui['nom']) ? $qui['nom'] : '').') : '.($a ? 'OK' : 'niet'),
207
+		'autoriser'._LOG_DEBUG
208 208
 	);
209 209
 
210 210
 	return $a;
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 function autoriser_previsualiser_dist($faire, $type, $id, $qui, $opt) {
333 333
 
334 334
 	// Le visiteur a-t-il un statut prevu par la config ?
335
-	if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) {
335
+	if (strpos($GLOBALS['meta']['preview'], ','.$qui['statut'].',') !== false) {
336 336
 		return test_previsualiser_objet_champ($type, $id, $qui, $opt);
337 337
 	}
338 338
 
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
 				} // pas de champ passe a la demande => NIET
390 390
 				$previsu = explode(',', $c['previsu']);
391 391
 				// regarder si ce statut est autorise pour l'auteur
392
-				if (in_array($opt[$champ] . '/auteur', $previsu)) {
392
+				if (in_array($opt[$champ].'/auteur', $previsu)) {
393 393
 
394 394
 					// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
395 395
 					// sinon l’auteur en session
@@ -404,11 +404,11 @@  discard block
 block discarded – undo
404 404
 
405 405
 					if (!$id_auteur) {
406 406
 						return false;
407
-					} elseif(autoriser('previsualiser' . $opt[$champ], $type, '', $id_auteur)) {
407
+					} elseif (autoriser('previsualiser'.$opt[$champ], $type, '', $id_auteur)) {
408 408
 						// dans ce cas (admin en general), pas de filtrage sur ce statut
409 409
 					} elseif (!sql_countsel(
410 410
 						'spip_auteurs_liens',
411
-						'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id)
411
+						'id_auteur='.intval($id_auteur).' AND objet='.sql_quote($type).' AND id_objet='.intval($id)
412 412
 					)) {
413 413
 						return false;
414 414
 					} // pas auteur de cet objet => NIET
@@ -446,16 +446,16 @@  discard block
 block discarded – undo
446 446
 			// multilinguisme par secteur et objet rattaché à une rubrique
447 447
 			$primary = id_table_objet($type);
448 448
 			if ($table != 'spip_rubriques') {
449
-				$id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id));
449
+				$id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=".intval($id));
450 450
 			} else {
451 451
 				$id_rubrique = $id;
452 452
 			}
453
-			$id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
453
+			$id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique='.intval($id_rubrique));
454 454
 			if (!$id_secteur > 0) {
455 455
 				$id_secteur = $id_rubrique;
456 456
 			}
457
-			$langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur));
458
-			$langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id));
457
+			$langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique='.intval($id_secteur));
458
+			$langue_objet = sql_getfetsel('lang', "$table", "$primary=".intval($id));
459 459
 			if ($langue_secteur != $langue_objet) {
460 460
 				// configuration incohérente, on laisse l'utilisateur corriger la situation
461 461
 				return true;
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
 			if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques
464 464
 				return false;
465 465
 			} else {
466
-				$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id));
466
+				$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique='.intval($id));
467 467
 				if ($id_parent != 0) {
468 468
 					// sous-rubriques : pas de choix de langue
469 469
 					return false;
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 	
512 512
 	if (!isset($opt['statut'])) {
513 513
 		if (isset($desc['field']['statut'])) {
514
-			$statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id));
514
+			$statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type).'='.intval($id));
515 515
 		} else {
516 516
 			$statut = 'publie';
517 517
 		} // pas de statut => publie
@@ -669,11 +669,11 @@  discard block
 block discarded – undo
669 669
 		return false;
670 670
 	}
671 671
 
672
-	if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) {
672
+	if (sql_countsel('spip_rubriques', 'id_parent='.intval($id))) {
673 673
 		return false;
674 674
 	}
675 675
 
676
-	if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) {
676
+	if (sql_countsel('spip_articles', 'id_rubrique='.intval($id)." AND (statut<>'poubelle')")) {
677 677
 		return false;
678 678
 	}
679 679
 
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
  * @return bool          true s'il a le droit, false sinon
706 706
  **/
707 707
 function autoriser_article_modifier_dist($faire, $type, $id, $qui, $opt) {
708
-	$r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id));
708
+	$r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article='.sql_quote($id));
709 709
 
710 710
 	return
711 711
 		$r
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
 				(!isset($opt['statut']) or $opt['statut'] !== 'publie')
717 717
 				and in_array($qui['statut'], array('0minirezo', '1comite'))
718 718
 				and in_array($r['statut'], array('prop', 'prepa', 'poubelle'))
719
-				and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])
719
+				and auteurs_objet('article', $id, 'id_auteur='.$qui['id_auteur'])
720 720
 			)
721 721
 		);
722 722
 }
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
 		if (!$id) {
765 765
 			return false;
766 766
 		}
767
-		$statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id));
767
+		$statut = sql_getfetsel('statut', 'spip_articles', 'id_article='.intval($id));
768 768
 	}
769 769
 
770 770
 	return
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
 		or
776 776
 		($id
777 777
 			and $qui['id_auteur']
778
-			and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']));
778
+			and auteurs_objet('article', $id, 'id_auteur='.$qui['id_auteur']));
779 779
 }
780 780
 
781 781
 
@@ -793,8 +793,8 @@  discard block
 block discarded – undo
793 793
  **/
794 794
 function autoriser_voir_dist($faire, $type, $id, $qui, $opt) {
795 795
 	# securite, mais on aurait pas du arriver ici !
796
-	if (function_exists($f = 'autoriser_' . $type . '_voir')
797
-		or function_exists($f = 'autoriser_' . $type . '_voir_dist')) {
796
+	if (function_exists($f = 'autoriser_'.$type.'_voir')
797
+		or function_exists($f = 'autoriser_'.$type.'_voir_dist')) {
798 798
 		return $f($faire, $type, $id, $qui, $opt);
799 799
 	}
800 800
 
@@ -912,7 +912,7 @@  discard block
 block discarded – undo
912 912
 	$n = sql_fetsel(
913 913
 		'A.id_article',
914 914
 		'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)',
915
-		"A.statut='publie' AND L.id_auteur=" . sql_quote($id)
915
+		"A.statut='publie' AND L.id_auteur=".sql_quote($id)
916 916
 	);
917 917
 
918 918
 	return $n ? true : false;
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
 		and $r = sql_allfetsel(
1119 1119
 			'id_objet',
1120 1120
 			'spip_auteurs_liens',
1121
-			'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0"
1121
+			'id_auteur='.intval($id_auteur)." AND objet='rubrique' AND id_objet!=0"
1122 1122
 		)
1123 1123
 		and count($r)
1124 1124
 	) {
@@ -1733,8 +1733,8 @@  discard block
 block discarded – undo
1733 1733
 function auteurs_objet($objet, $id_objet, $cond = '') {
1734 1734
 	$objet = objet_type($objet);
1735 1735
 	$where = array(
1736
-		'objet=' . sql_quote($objet),
1737
-		'id_objet=' . intval($id_objet)
1736
+		'objet='.sql_quote($objet),
1737
+		'id_objet='.intval($id_objet)
1738 1738
 	);
1739 1739
 	if (!empty($cond)) {
1740 1740
 		if (is_array($cond)) {
@@ -1768,7 +1768,7 @@  discard block
 block discarded – undo
1768 1768
 	return sql_allfetsel(
1769 1769
 		'id_auteur',
1770 1770
 		'spip_auteurs_liens',
1771
-		"objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '')
1771
+		"objet='article' AND id_objet=".intval($id_article).($cond ? " AND $cond" : '')
1772 1772
 	);
1773 1773
 }
1774 1774
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -237,8 +237,7 @@  discard block
 block discarded – undo
237 237
 		if ($id === '*') {
238 238
 			unset($GLOBALS['autoriser_exception'][$faire][$type]);
239 239
 			unset($autorisation[$faire][$type]);
240
-		}
241
-		else {
240
+		} else {
242 241
 			unset($GLOBALS['autoriser_exception'][$faire][$type][$id]);
243 242
 			unset($autorisation[$faire][$type][$id]);
244 243
 		}
@@ -592,8 +591,7 @@  discard block
 block discarded – undo
592 591
 function autoriser_rubrique_creer_dist($faire, $type, $id, $qui, $opt) {
593 592
 	if (!empty($opt['id_parent'])) {
594 593
 		return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui);
595
-	}
596
-	else {
594
+	} else {
597 595
 		return autoriser('defaut', null, null, $qui, $opt);
598 596
 	}
599 597
 }
@@ -739,8 +737,7 @@  discard block
 block discarded – undo
739 737
 	if (!empty($opt['id_parent'])) {
740 738
 		// creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi
741 739
 		return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui);
742
-	}
743
-	else {
740
+	} else {
744 741
 		return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], array('0minirezo', '1comite')));
745 742
 	}
746 743
 }
Please login to merge, or discard this patch.
Indentation   +624 added lines, -624 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,83 +38,83 @@  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
-	 *
83
-	 * @param string $faire
84
-	 *   une action ('modifier', 'publier'...)
85
-	 * @param string $type
86
-	 *   type d'objet ou nom de table ('article')
87
-	 * @param int $id
88
-	 *   id de l'objet sur lequel on veut agir
89
-	 * @param null|int|array $qui
90
-	 *   - si null on prend alors visiteur_session
91
-	 *   - un id_auteur (on regarde dans la base)
92
-	 *   - un tableau auteur complet, y compris [restreint]
93
-	 * @param null|array $opt
94
-	 *   options sous forme de tableau associatif
95
-	 * @return bool
96
-	 *   true si la personne peut effectuer l'action
97
-	 */
98
-	function autoriser($faire, $type = '', $id = 0, $qui = null, $opt = null) {
99
-		// Charger les fonctions d'autorisation supplementaires
100
-		static $pipe;
101
-		if (!isset($pipe)) {
102
-			$pipe = 1;
103
-			pipeline('autoriser');
104
-		}
105
-
106
-		$args = func_get_args();
107
-
108
-		return call_user_func_array('autoriser_dist', $args);
109
-	}
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
+     *
83
+     * @param string $faire
84
+     *   une action ('modifier', 'publier'...)
85
+     * @param string $type
86
+     *   type d'objet ou nom de table ('article')
87
+     * @param int $id
88
+     *   id de l'objet sur lequel on veut agir
89
+     * @param null|int|array $qui
90
+     *   - si null on prend alors visiteur_session
91
+     *   - un id_auteur (on regarde dans la base)
92
+     *   - un tableau auteur complet, y compris [restreint]
93
+     * @param null|array $opt
94
+     *   options sous forme de tableau associatif
95
+     * @return bool
96
+     *   true si la personne peut effectuer l'action
97
+     */
98
+    function autoriser($faire, $type = '', $id = 0, $qui = null, $opt = null) {
99
+        // Charger les fonctions d'autorisation supplementaires
100
+        static $pipe;
101
+        if (!isset($pipe)) {
102
+            $pipe = 1;
103
+            pipeline('autoriser');
104
+        }
105
+
106
+        $args = func_get_args();
107
+
108
+        return call_user_func_array('autoriser_dist', $args);
109
+    }
110 110
 }
111 111
 
112 112
 
113 113
 // mes_fonctions peut aussi declarer des autorisations, il faut donc le charger
114 114
 // mais apres la fonction autoriser()
115 115
 if ($f = find_in_path('mes_fonctions.php')) {
116
-	global $dossier_squelettes;
117
-	include_once(_ROOT_CWD . $f);
116
+    global $dossier_squelettes;
117
+    include_once(_ROOT_CWD . $f);
118 118
 }
119 119
 
120 120
 
@@ -142,72 +142,72 @@  discard block
 block discarded – undo
142 142
  */
143 143
 function autoriser_dist($faire, $type = '', $id = 0, $qui = null, $opt = null) {
144 144
 
145
-	// Qui ? visiteur_session ?
146
-	// si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge
147
-	if ($qui === null or $qui === '') {
148
-		$qui = $GLOBALS['visiteur_session'] ? $GLOBALS['visiteur_session'] : array();
149
-		$qui = array_merge(array('statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'), $qui);
150
-	} elseif (is_numeric($qui)) {
151
-		$qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui);
152
-	}
153
-
154
-	// Admins restreints, on construit ici (pas generique mais...)
155
-	// le tableau de toutes leurs rubriques (y compris les sous-rubriques)
156
-	if (_ADMINS_RESTREINTS and is_array($qui)) {
157
-		$qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : array();
158
-	}
159
-
160
-	spip_log(
161
-		"autoriser $faire $type $id (" . (isset($qui['nom']) ? $qui['nom'] : '') . ') ?',
162
-		'autoriser' . _LOG_DEBUG
163
-	);
164
-
165
-	// passer par objet_type pour avoir les alias
166
-	// et supprimer les _
167
-	$type = str_replace('_', '', strncmp($type, '_', 1) == 0 ? $type : objet_type($type, false));
168
-
169
-	// Si une exception a ete decretee plus haut dans le code, l'appliquer
170
-	if ((isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) and autoriser_exception($faire, $type, $id, 'verifier'))
171
-	  or (isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) and autoriser_exception($faire, $type, '*', 'verifier'))
172
-	) {
173
-		spip_log("autoriser ($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG);
174
-		return true;
175
-	}
176
-
177
-	// Chercher une fonction d'autorisation
178
-	// Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist],
179
-	// autoriser_faire[_dist], autoriser_defaut[_dist]
180
-	$fonctions = $type
181
-		? array(
182
-			'autoriser_' . $type . '_' . $faire,
183
-			'autoriser_' . $type . '_' . $faire . '_dist',
184
-			'autoriser_' . $type,
185
-			'autoriser_' . $type . '_dist',
186
-			'autoriser_' . $faire,
187
-			'autoriser_' . $faire . '_dist',
188
-			'autoriser_defaut',
189
-			'autoriser_defaut_dist'
190
-		)
191
-		: array(
192
-			'autoriser_' . $faire,
193
-			'autoriser_' . $faire . '_dist',
194
-			'autoriser_defaut',
195
-			'autoriser_defaut_dist'
196
-		);
197
-
198
-	foreach ($fonctions as $f) {
199
-		if (function_exists($f)) {
200
-			$a = $f($faire, $type, $id, $qui, $opt);
201
-			break;
202
-		}
203
-	}
204
-
205
-	spip_log(
206
-		"$f($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : ' . ($a ? 'OK' : 'niet'),
207
-		'autoriser' . _LOG_DEBUG
208
-	);
209
-
210
-	return $a;
145
+    // Qui ? visiteur_session ?
146
+    // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge
147
+    if ($qui === null or $qui === '') {
148
+        $qui = $GLOBALS['visiteur_session'] ? $GLOBALS['visiteur_session'] : array();
149
+        $qui = array_merge(array('statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'), $qui);
150
+    } elseif (is_numeric($qui)) {
151
+        $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui);
152
+    }
153
+
154
+    // Admins restreints, on construit ici (pas generique mais...)
155
+    // le tableau de toutes leurs rubriques (y compris les sous-rubriques)
156
+    if (_ADMINS_RESTREINTS and is_array($qui)) {
157
+        $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : array();
158
+    }
159
+
160
+    spip_log(
161
+        "autoriser $faire $type $id (" . (isset($qui['nom']) ? $qui['nom'] : '') . ') ?',
162
+        'autoriser' . _LOG_DEBUG
163
+    );
164
+
165
+    // passer par objet_type pour avoir les alias
166
+    // et supprimer les _
167
+    $type = str_replace('_', '', strncmp($type, '_', 1) == 0 ? $type : objet_type($type, false));
168
+
169
+    // Si une exception a ete decretee plus haut dans le code, l'appliquer
170
+    if ((isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) and autoriser_exception($faire, $type, $id, 'verifier'))
171
+      or (isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) and autoriser_exception($faire, $type, '*', 'verifier'))
172
+    ) {
173
+        spip_log("autoriser ($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG);
174
+        return true;
175
+    }
176
+
177
+    // Chercher une fonction d'autorisation
178
+    // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist],
179
+    // autoriser_faire[_dist], autoriser_defaut[_dist]
180
+    $fonctions = $type
181
+        ? array(
182
+            'autoriser_' . $type . '_' . $faire,
183
+            'autoriser_' . $type . '_' . $faire . '_dist',
184
+            'autoriser_' . $type,
185
+            'autoriser_' . $type . '_dist',
186
+            'autoriser_' . $faire,
187
+            'autoriser_' . $faire . '_dist',
188
+            'autoriser_defaut',
189
+            'autoriser_defaut_dist'
190
+        )
191
+        : array(
192
+            'autoriser_' . $faire,
193
+            'autoriser_' . $faire . '_dist',
194
+            'autoriser_defaut',
195
+            'autoriser_defaut_dist'
196
+        );
197
+
198
+    foreach ($fonctions as $f) {
199
+        if (function_exists($f)) {
200
+            $a = $f($faire, $type, $id, $qui, $opt);
201
+            break;
202
+        }
203
+    }
204
+
205
+    spip_log(
206
+        "$f($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : ' . ($a ? 'OK' : 'niet'),
207
+        'autoriser' . _LOG_DEBUG
208
+    );
209
+
210
+    return $a;
211 211
 }
212 212
 
213 213
 // une globale pour aller au plus vite dans la fonction generique ci dessus
@@ -225,26 +225,26 @@  discard block
 block discarded – undo
225 225
  * @return bool
226 226
  */
227 227
 function autoriser_exception($faire, $type, $id, $autoriser = true) {
228
-	// une static innaccessible par url pour verifier que la globale est positionnee a bon escient
229
-	static $autorisation;
230
-	if ($autoriser === 'verifier') {
231
-		return isset($autorisation[$faire][$type][$id]);
232
-	}
233
-	if ($autoriser === true) {
234
-		$GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true;
235
-	}
236
-	if ($autoriser === false) {
237
-		if ($id === '*') {
238
-			unset($GLOBALS['autoriser_exception'][$faire][$type]);
239
-			unset($autorisation[$faire][$type]);
240
-		}
241
-		else {
242
-			unset($GLOBALS['autoriser_exception'][$faire][$type][$id]);
243
-			unset($autorisation[$faire][$type][$id]);
244
-		}
245
-	}
246
-
247
-	return false;
228
+    // une static innaccessible par url pour verifier que la globale est positionnee a bon escient
229
+    static $autorisation;
230
+    if ($autoriser === 'verifier') {
231
+        return isset($autorisation[$faire][$type][$id]);
232
+    }
233
+    if ($autoriser === true) {
234
+        $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true;
235
+    }
236
+    if ($autoriser === false) {
237
+        if ($id === '*') {
238
+            unset($GLOBALS['autoriser_exception'][$faire][$type]);
239
+            unset($autorisation[$faire][$type]);
240
+        }
241
+        else {
242
+            unset($GLOBALS['autoriser_exception'][$faire][$type][$id]);
243
+            unset($autorisation[$faire][$type][$id]);
244
+        }
245
+    }
246
+
247
+    return false;
248 248
 }
249 249
 
250 250
 
@@ -261,9 +261,9 @@  discard block
 block discarded – undo
261 261
  * @return bool          true s'il a le droit, false sinon
262 262
  **/
263 263
 function autoriser_defaut_dist($faire, $type, $id, $qui, $opt) {
264
-	return
265
-		$qui['statut'] == '0minirezo'
266
-		and !$qui['restreint'];
264
+    return
265
+        $qui['statut'] == '0minirezo'
266
+        and !$qui['restreint'];
267 267
 }
268 268
 
269 269
 /**
@@ -279,10 +279,10 @@  discard block
 block discarded – undo
279 279
  * @return bool
280 280
  */
281 281
 function autoriser_loger_dist($faire, $type, $id, $qui, $opt) {
282
-	if ($qui['statut'] == '5poubelle') {
283
-		return false;
284
-	}
285
-	return true;
282
+    if ($qui['statut'] == '5poubelle') {
283
+        return false;
284
+    }
285
+    return true;
286 286
 }
287 287
 
288 288
 /**
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
  * @return bool          true s'il a le droit, false sinon
297 297
  **/
298 298
 function autoriser_ecrire_dist($faire, $type, $id, $qui, $opt) {
299
-	return isset($qui['statut']) and in_array($qui['statut'], array('0minirezo', '1comite'));
299
+    return isset($qui['statut']) and in_array($qui['statut'], array('0minirezo', '1comite'));
300 300
 }
301 301
 
302 302
 /**
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
  * @return bool          true s'il a le droit, false sinon
314 314
  **/
315 315
 function autoriser_creer_dist($faire, $type, $id, $qui, $opt) {
316
-	return in_array($qui['statut'], array('0minirezo', '1comite'));
316
+    return in_array($qui['statut'], array('0minirezo', '1comite'));
317 317
 }
318 318
 
319 319
 /**
@@ -331,18 +331,18 @@  discard block
 block discarded – undo
331 331
  **/
332 332
 function autoriser_previsualiser_dist($faire, $type, $id, $qui, $opt) {
333 333
 
334
-	// Le visiteur a-t-il un statut prevu par la config ?
335
-	if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) {
336
-		return test_previsualiser_objet_champ($type, $id, $qui, $opt);
337
-	}
334
+    // Le visiteur a-t-il un statut prevu par la config ?
335
+    if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) {
336
+        return test_previsualiser_objet_champ($type, $id, $qui, $opt);
337
+    }
338 338
 
339
-	// A-t-on un token de prévisualisation valable ?
340
-	include_spip('inc/securiser_action');
341
-	if (decrire_token_previsu()) {
342
-		return true;
343
-	}
339
+    // A-t-on un token de prévisualisation valable ?
340
+    include_spip('inc/securiser_action');
341
+    if (decrire_token_previsu()) {
342
+        return true;
343
+    }
344 344
 
345
-	return false;
345
+    return false;
346 346
 }
347 347
 
348 348
 /**
@@ -370,57 +370,57 @@  discard block
 block discarded – undo
370 370
  */
371 371
 function test_previsualiser_objet_champ($type = null, $id = 0, $qui = array(), $opt = array()) {
372 372
 
373
-	// si pas de type et statut fourni, c'est une autorisation generale => OK
374
-	if (!$type) {
375
-		return true;
376
-	}
377
-
378
-	include_spip('base/objets');
379
-	$infos = lister_tables_objets_sql(table_objet_sql($type));
380
-	if (isset($infos['statut'])) {
381
-		foreach ($infos['statut'] as $c) {
382
-			if (isset($c['publie'])) {
383
-				if (!isset($c['previsu'])) {
384
-					return false;
385
-				} // pas de previsu definie => NIET
386
-				$champ = $c['champ'];
387
-				if (!isset($opt[$champ])) {
388
-					return false;
389
-				} // pas de champ passe a la demande => NIET
390
-				$previsu = explode(',', $c['previsu']);
391
-				// regarder si ce statut est autorise pour l'auteur
392
-				if (in_array($opt[$champ] . '/auteur', $previsu)) {
393
-
394
-					// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
395
-					// sinon l’auteur en session
396
-					include_spip('inc/securiser_action');
397
-					if ($desc = decrire_token_previsu()) {
398
-						$id_auteur = $desc['id_auteur'];
399
-					} elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
400
-						$id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
401
-					} else {
402
-						$id_auteur = null;
403
-					}
404
-
405
-					if (!$id_auteur) {
406
-						return false;
407
-					} elseif(autoriser('previsualiser' . $opt[$champ], $type, '', $id_auteur)) {
408
-						// dans ce cas (admin en general), pas de filtrage sur ce statut
409
-					} elseif (!sql_countsel(
410
-						'spip_auteurs_liens',
411
-						'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id)
412
-					)) {
413
-						return false;
414
-					} // pas auteur de cet objet => NIET
415
-				} elseif (!in_array($opt[$champ], $previsu)) {
416
-					// le statut n'est pas dans ceux definis par la previsu => NIET
417
-					return false;
418
-				}
419
-			}
420
-		}
421
-	}
422
-
423
-	return true;
373
+    // si pas de type et statut fourni, c'est une autorisation generale => OK
374
+    if (!$type) {
375
+        return true;
376
+    }
377
+
378
+    include_spip('base/objets');
379
+    $infos = lister_tables_objets_sql(table_objet_sql($type));
380
+    if (isset($infos['statut'])) {
381
+        foreach ($infos['statut'] as $c) {
382
+            if (isset($c['publie'])) {
383
+                if (!isset($c['previsu'])) {
384
+                    return false;
385
+                } // pas de previsu definie => NIET
386
+                $champ = $c['champ'];
387
+                if (!isset($opt[$champ])) {
388
+                    return false;
389
+                } // pas de champ passe a la demande => NIET
390
+                $previsu = explode(',', $c['previsu']);
391
+                // regarder si ce statut est autorise pour l'auteur
392
+                if (in_array($opt[$champ] . '/auteur', $previsu)) {
393
+
394
+                    // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
395
+                    // sinon l’auteur en session
396
+                    include_spip('inc/securiser_action');
397
+                    if ($desc = decrire_token_previsu()) {
398
+                        $id_auteur = $desc['id_auteur'];
399
+                    } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
400
+                        $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
401
+                    } else {
402
+                        $id_auteur = null;
403
+                    }
404
+
405
+                    if (!$id_auteur) {
406
+                        return false;
407
+                    } elseif(autoriser('previsualiser' . $opt[$champ], $type, '', $id_auteur)) {
408
+                        // dans ce cas (admin en general), pas de filtrage sur ce statut
409
+                    } elseif (!sql_countsel(
410
+                        'spip_auteurs_liens',
411
+                        'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id)
412
+                    )) {
413
+                        return false;
414
+                    } // pas auteur de cet objet => NIET
415
+                } elseif (!in_array($opt[$champ], $previsu)) {
416
+                    // le statut n'est pas dans ceux definis par la previsu => NIET
417
+                    return false;
418
+                }
419
+            }
420
+        }
421
+    }
422
+
423
+    return true;
424 424
 }
425 425
 
426 426
 /**
@@ -434,47 +434,47 @@  discard block
 block discarded – undo
434 434
  * @return bool          true s'il a le droit, false sinon
435 435
  **/
436 436
 function autoriser_changerlangue_dist($faire, $type, $id, $qui, $opt) {
437
-	$multi_objets = explode(',', lire_config('multi_objets'));
438
-	$gerer_trad_objets = explode(',', lire_config('gerer_trad_objets'));
439
-	$table = table_objet_sql($type);
440
-	if (in_array($table, $multi_objets)
441
-		or in_array($table, $gerer_trad_objets)) { // affichage du formulaire si la configuration l'accepte
442
-		$multi_secteurs = lire_config('multi_secteurs');
443
-		$champs = objet_info($type, 'field');
444
-		if ($multi_secteurs == 'oui'
445
-			and array_key_exists('id_rubrique', $champs)) {
446
-			// multilinguisme par secteur et objet rattaché à une rubrique
447
-			$primary = id_table_objet($type);
448
-			if ($table != 'spip_rubriques') {
449
-				$id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id));
450
-			} else {
451
-				$id_rubrique = $id;
452
-			}
453
-			$id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
454
-			if (!$id_secteur > 0) {
455
-				$id_secteur = $id_rubrique;
456
-			}
457
-			$langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur));
458
-			$langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id));
459
-			if ($langue_secteur != $langue_objet) {
460
-				// configuration incohérente, on laisse l'utilisateur corriger la situation
461
-				return true;
462
-			}
463
-			if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques
464
-				return false;
465
-			} else {
466
-				$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id));
467
-				if ($id_parent != 0) {
468
-					// sous-rubriques : pas de choix de langue
469
-					return false;
470
-				}
471
-			}
472
-		}
473
-	} else {
474
-		return false;
475
-	}
476
-
477
-	return autoriser('modifier', $type, $id, $qui, $opt);
437
+    $multi_objets = explode(',', lire_config('multi_objets'));
438
+    $gerer_trad_objets = explode(',', lire_config('gerer_trad_objets'));
439
+    $table = table_objet_sql($type);
440
+    if (in_array($table, $multi_objets)
441
+        or in_array($table, $gerer_trad_objets)) { // affichage du formulaire si la configuration l'accepte
442
+        $multi_secteurs = lire_config('multi_secteurs');
443
+        $champs = objet_info($type, 'field');
444
+        if ($multi_secteurs == 'oui'
445
+            and array_key_exists('id_rubrique', $champs)) {
446
+            // multilinguisme par secteur et objet rattaché à une rubrique
447
+            $primary = id_table_objet($type);
448
+            if ($table != 'spip_rubriques') {
449
+                $id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id));
450
+            } else {
451
+                $id_rubrique = $id;
452
+            }
453
+            $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
454
+            if (!$id_secteur > 0) {
455
+                $id_secteur = $id_rubrique;
456
+            }
457
+            $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur));
458
+            $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id));
459
+            if ($langue_secteur != $langue_objet) {
460
+                // configuration incohérente, on laisse l'utilisateur corriger la situation
461
+                return true;
462
+            }
463
+            if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques
464
+                return false;
465
+            } else {
466
+                $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id));
467
+                if ($id_parent != 0) {
468
+                    // sous-rubriques : pas de choix de langue
469
+                    return false;
470
+                }
471
+            }
472
+        }
473
+    } else {
474
+        return false;
475
+    }
476
+
477
+    return autoriser('modifier', $type, $id, $qui, $opt);
478 478
 }
479 479
 
480 480
 /**
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
  * @return bool          true s'il a le droit, false sinon
489 489
  **/
490 490
 function autoriser_changertraduction_dist($faire, $type, $id, $qui, $opt) {
491
-	return autoriser('modifier', $type, $id, $qui, $opt);
491
+    return autoriser('modifier', $type, $id, $qui, $opt);
492 492
 }
493 493
 
494 494
 /**
@@ -502,41 +502,41 @@  discard block
 block discarded – undo
502 502
  * @return bool          true s'il a le droit, false sinon
503 503
  **/
504 504
 function autoriser_dater_dist($faire, $type, $id, $qui, $opt) {
505
-	$table = table_objet($type);
506
-	$trouver_table = charger_fonction('trouver_table', 'base');
507
-	$desc = $trouver_table($table);
508
-	if (!$desc) {
509
-		return false;
510
-	}
505
+    $table = table_objet($type);
506
+    $trouver_table = charger_fonction('trouver_table', 'base');
507
+    $desc = $trouver_table($table);
508
+    if (!$desc) {
509
+        return false;
510
+    }
511 511
 	
512
-	if (!isset($opt['statut'])) {
513
-		if (isset($desc['field']['statut'])) {
514
-			$statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id));
515
-		} else {
516
-			$statut = 'publie';
517
-		} // pas de statut => publie
518
-	} else {
519
-		$statut = $opt['statut'];
520
-	}
512
+    if (!isset($opt['statut'])) {
513
+        if (isset($desc['field']['statut'])) {
514
+            $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id));
515
+        } else {
516
+            $statut = 'publie';
517
+        } // pas de statut => publie
518
+    } else {
519
+        $statut = $opt['statut'];
520
+    }
521 521
 	
522
-	// Liste des statuts publiés pour cet objet
523
-	if (isset($desc['statut'][0]['publie'])) {
524
-		$statuts_publies = explode(',', $desc['statut'][0]['publie']);
525
-	}
526
-	// Sinon en dur le statut "publie"
527
-	else {
528
-		$statuts_publies = array('publie');
529
-	}
522
+    // Liste des statuts publiés pour cet objet
523
+    if (isset($desc['statut'][0]['publie'])) {
524
+        $statuts_publies = explode(',', $desc['statut'][0]['publie']);
525
+    }
526
+    // Sinon en dur le statut "publie"
527
+    else {
528
+        $statuts_publies = array('publie');
529
+    }
530 530
 	
531
-	if (
532
-		in_array($statut, $statuts_publies)
533
-		// Ou cas particulier géré en dur ici pour les articles
534
-		or ($statut == 'prop' and $type == 'article' and $GLOBALS['meta']['post_dates'] == 'non')
535
-	) {
536
-		return autoriser('modifier', $type, $id);
537
-	}
531
+    if (
532
+        in_array($statut, $statuts_publies)
533
+        // Ou cas particulier géré en dur ici pour les articles
534
+        or ($statut == 'prop' and $type == 'article' and $GLOBALS['meta']['post_dates'] == 'non')
535
+    ) {
536
+        return autoriser('modifier', $type, $id);
537
+    }
538 538
 
539
-	return false;
539
+    return false;
540 540
 }
541 541
 
542 542
 /**
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
  * @return bool          true s'il a le droit, false sinon
554 554
  **/
555 555
 function autoriser_instituer_dist($faire, $type, $id, $qui, $opt) {
556
-	return autoriser('modifier', $type, $id, $qui, $opt);
556
+    return autoriser('modifier', $type, $id, $qui, $opt);
557 557
 }
558 558
 
559 559
 /**
@@ -569,12 +569,12 @@  discard block
 block discarded – undo
569 569
  * @return bool          true s'il a le droit, false sinon
570 570
  **/
571 571
 function autoriser_rubrique_publierdans_dist($faire, $type, $id, $qui, $opt) {
572
-	return
573
-		($qui['statut'] == '0minirezo')
574
-		and (
575
-			!$qui['restreint'] or !$id
576
-			or in_array($id, $qui['restreint'])
577
-		);
572
+    return
573
+        ($qui['statut'] == '0minirezo')
574
+        and (
575
+            !$qui['restreint'] or !$id
576
+            or in_array($id, $qui['restreint'])
577
+        );
578 578
 }
579 579
 
580 580
 /**
@@ -590,12 +590,12 @@  discard block
 block discarded – undo
590 590
  * @return bool          true s'il a le droit, false sinon
591 591
  **/
592 592
 function autoriser_rubrique_creer_dist($faire, $type, $id, $qui, $opt) {
593
-	if (!empty($opt['id_parent'])) {
594
-		return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui);
595
-	}
596
-	else {
597
-		return autoriser('defaut', null, null, $qui, $opt);
598
-	}
593
+    if (!empty($opt['id_parent'])) {
594
+        return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui);
595
+    }
596
+    else {
597
+        return autoriser('defaut', null, null, $qui, $opt);
598
+    }
599 599
 }
600 600
 
601 601
 /**
@@ -611,10 +611,10 @@  discard block
 block discarded – undo
611 611
  * @return bool          true s'il a le droit, false sinon
612 612
  **/
613 613
 function autoriser_rubrique_creerrubriquedans_dist($faire, $type, $id, $qui, $opt) {
614
-	return
615
-		($id or ($qui['statut'] == '0minirezo' and !$qui['restreint']))
616
-		and autoriser('voir', 'rubrique', $id)
617
-		and autoriser('publierdans', 'rubrique', $id);
614
+    return
615
+        ($id or ($qui['statut'] == '0minirezo' and !$qui['restreint']))
616
+        and autoriser('voir', 'rubrique', $id)
617
+        and autoriser('publierdans', 'rubrique', $id);
618 618
 }
619 619
 
620 620
 /**
@@ -630,10 +630,10 @@  discard block
 block discarded – undo
630 630
  * @return bool          true s'il a le droit, false sinon
631 631
  **/
632 632
 function autoriser_rubrique_creerarticledans_dist($faire, $type, $id, $qui, $opt) {
633
-	return
634
-		$id
635
-		and autoriser('voir', 'rubrique', $id)
636
-		and autoriser('creer', 'article');
633
+    return
634
+        $id
635
+        and autoriser('voir', 'rubrique', $id)
636
+        and autoriser('creer', 'article');
637 637
 }
638 638
 
639 639
 
@@ -650,8 +650,8 @@  discard block
 block discarded – undo
650 650
  * @return bool          true s'il a le droit, false sinon
651 651
  **/
652 652
 function autoriser_rubrique_modifier_dist($faire, $type, $id, $qui, $opt) {
653
-	return
654
-		autoriser('publierdans', 'rubrique', $id, $qui, $opt);
653
+    return
654
+        autoriser('publierdans', 'rubrique', $id, $qui, $opt);
655 655
 }
656 656
 
657 657
 /**
@@ -667,29 +667,29 @@  discard block
 block discarded – undo
667 667
  * @return bool          true s'il a le droit, false sinon
668 668
  **/
669 669
 function autoriser_rubrique_supprimer_dist($faire, $type, $id, $qui, $opt) {
670
-	if (!$id = intval($id)) {
671
-		return false;
672
-	}
670
+    if (!$id = intval($id)) {
671
+        return false;
672
+    }
673 673
 
674
-	if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) {
675
-		return false;
676
-	}
674
+    if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) {
675
+        return false;
676
+    }
677 677
 
678
-	if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) {
679
-		return false;
680
-	}
678
+    if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) {
679
+        return false;
680
+    }
681 681
 
682
-	$compte = pipeline(
683
-		'objet_compte_enfants',
684
-		array('args' => array('objet' => 'rubrique', 'id_objet' => $id), 'data' => array())
685
-	);
686
-	foreach ($compte as $objet => $n) {
687
-		if ($n) {
688
-			return false;
689
-		}
690
-	}
682
+    $compte = pipeline(
683
+        'objet_compte_enfants',
684
+        array('args' => array('objet' => 'rubrique', 'id_objet' => $id), 'data' => array())
685
+    );
686
+    foreach ($compte as $objet => $n) {
687
+        if ($n) {
688
+            return false;
689
+        }
690
+    }
691 691
 
692
-	return autoriser('modifier', 'rubrique', $id);
692
+    return autoriser('modifier', 'rubrique', $id);
693 693
 }
694 694
 
695 695
 
@@ -707,20 +707,20 @@  discard block
 block discarded – undo
707 707
  * @return bool          true s'il a le droit, false sinon
708 708
  **/
709 709
 function autoriser_article_modifier_dist($faire, $type, $id, $qui, $opt) {
710
-	$r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id));
710
+    $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id));
711 711
 
712
-	return
713
-		$r
714
-		and
715
-		(
716
-			autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt)
717
-			or (
718
-				(!isset($opt['statut']) or $opt['statut'] !== 'publie')
719
-				and in_array($qui['statut'], array('0minirezo', '1comite'))
720
-				and in_array($r['statut'], array('prop', 'prepa', 'poubelle'))
721
-				and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])
722
-			)
723
-		);
712
+    return
713
+        $r
714
+        and
715
+        (
716
+            autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt)
717
+            or (
718
+                (!isset($opt['statut']) or $opt['statut'] !== 'publie')
719
+                and in_array($qui['statut'], array('0minirezo', '1comite'))
720
+                and in_array($r['statut'], array('prop', 'prepa', 'poubelle'))
721
+                and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])
722
+            )
723
+        );
724 724
 }
725 725
 
726 726
 /**
@@ -736,13 +736,13 @@  discard block
 block discarded – undo
736 736
  * @return bool          true s'il a le droit, false sinon
737 737
  **/
738 738
 function autoriser_article_creer_dist($faire, $type, $id, $qui, $opt) {
739
-	if (!empty($opt['id_parent'])) {
740
-		// creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi
741
-		return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui);
742
-	}
743
-	else {
744
-		return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], array('0minirezo', '1comite')));
745
-	}
739
+    if (!empty($opt['id_parent'])) {
740
+        // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi
741
+        return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui);
742
+    }
743
+    else {
744
+        return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], array('0minirezo', '1comite')));
745
+    }
746 746
 }
747 747
 
748 748
 /**
@@ -762,28 +762,28 @@  discard block
 block discarded – undo
762 762
  * @return bool          true s'il a le droit, false sinon
763 763
  */
764 764
 function autoriser_article_voir_dist($faire, $type, $id, $qui, $opt) {
765
-	if ($qui['statut'] == '0minirezo') {
766
-		return true;
767
-	}
768
-	// cas des articles : depend du statut de l'article et de l'auteur
769
-	if (isset($opt['statut'])) {
770
-		$statut = $opt['statut'];
771
-	} else {
772
-		if (!$id) {
773
-			return false;
774
-		}
775
-		$statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id));
776
-	}
777
-
778
-	return
779
-		// si on est pas auteur de l'article,
780
-		// seuls les propose et publies sont visibles
781
-		in_array($statut, array('prop', 'publie'))
782
-		// sinon si on est auteur, on a le droit de le voir, evidemment !
783
-		or
784
-		($id
785
-			and $qui['id_auteur']
786
-			and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']));
765
+    if ($qui['statut'] == '0minirezo') {
766
+        return true;
767
+    }
768
+    // cas des articles : depend du statut de l'article et de l'auteur
769
+    if (isset($opt['statut'])) {
770
+        $statut = $opt['statut'];
771
+    } else {
772
+        if (!$id) {
773
+            return false;
774
+        }
775
+        $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id));
776
+    }
777
+
778
+    return
779
+        // si on est pas auteur de l'article,
780
+        // seuls les propose et publies sont visibles
781
+        in_array($statut, array('prop', 'publie'))
782
+        // sinon si on est auteur, on a le droit de le voir, evidemment !
783
+        or
784
+        ($id
785
+            and $qui['id_auteur']
786
+            and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']));
787 787
 }
788 788
 
789 789
 
@@ -800,22 +800,22 @@  discard block
 block discarded – undo
800 800
  * @return bool          true s'il a le droit, false sinon
801 801
  **/
802 802
 function autoriser_voir_dist($faire, $type, $id, $qui, $opt) {
803
-	# securite, mais on aurait pas du arriver ici !
804
-	if (function_exists($f = 'autoriser_' . $type . '_voir')
805
-		or function_exists($f = 'autoriser_' . $type . '_voir_dist')) {
806
-		return $f($faire, $type, $id, $qui, $opt);
807
-	}
803
+    # securite, mais on aurait pas du arriver ici !
804
+    if (function_exists($f = 'autoriser_' . $type . '_voir')
805
+        or function_exists($f = 'autoriser_' . $type . '_voir_dist')) {
806
+        return $f($faire, $type, $id, $qui, $opt);
807
+    }
808 808
 
809
-	if ($qui['statut'] == '0minirezo') {
810
-		return true;
811
-	}
812
-	// admins et redacteurs peuvent voir un auteur
813
-	if ($type == 'auteur') {
814
-		return in_array($qui['statut'], array('0minirezo', '1comite'));
815
-	}
816
-	// sinon par defaut tout est visible
817
-	// sauf cas particuliers traites separemment (ie article)
818
-	return true;
809
+    if ($qui['statut'] == '0minirezo') {
810
+        return true;
811
+    }
812
+    // admins et redacteurs peuvent voir un auteur
813
+    if ($type == 'auteur') {
814
+        return in_array($qui['statut'], array('0minirezo', '1comite'));
815
+    }
816
+    // sinon par defaut tout est visible
817
+    // sauf cas particuliers traites separemment (ie article)
818
+    return true;
819 819
 }
820 820
 
821 821
 
@@ -836,12 +836,12 @@  discard block
 block discarded – undo
836 836
  * @return bool          true s'il a le droit, false sinon
837 837
  **/
838 838
 function autoriser_webmestre_dist($faire, $type, $id, $qui, $opt) {
839
-	return
840
-		(defined('_ID_WEBMESTRES') ?
841
-			in_array($qui['id_auteur'], explode(':', _ID_WEBMESTRES))
842
-			: $qui['webmestre'] == 'oui')
843
-		and $qui['statut'] == '0minirezo'
844
-		and !$qui['restreint'];
839
+    return
840
+        (defined('_ID_WEBMESTRES') ?
841
+            in_array($qui['id_auteur'], explode(':', _ID_WEBMESTRES))
842
+            : $qui['webmestre'] == 'oui')
843
+        and $qui['statut'] == '0minirezo'
844
+        and !$qui['restreint'];
845 845
 }
846 846
 
847 847
 /**
@@ -857,9 +857,9 @@  discard block
 block discarded – undo
857 857
  * @return bool          true s'il a le droit, false sinon
858 858
  **/
859 859
 function autoriser_configurer_dist($faire, $type, $id, $qui, $opt) {
860
-	return
861
-		$qui['statut'] == '0minirezo'
862
-		and !$qui['restreint'];
860
+    return
861
+        $qui['statut'] == '0minirezo'
862
+        and !$qui['restreint'];
863 863
 }
864 864
 
865 865
 /**
@@ -875,8 +875,8 @@  discard block
 block discarded – undo
875 875
  * @return bool          true s'il a le droit, false sinon
876 876
  **/
877 877
 function autoriser_sauvegarder_dist($faire, $type, $id, $qui, $opt) {
878
-	return
879
-		$qui['statut'] == '0minirezo';
878
+    return
879
+        $qui['statut'] == '0minirezo';
880 880
 }
881 881
 
882 882
 /**
@@ -892,8 +892,8 @@  discard block
 block discarded – undo
892 892
  * @return bool          true s'il a le droit, false sinon
893 893
  **/
894 894
 function autoriser_detruire_dist($faire, $type, $id, $qui, $opt) {
895
-	return
896
-		autoriser('webmestre', null, null, $qui, $opt);
895
+    return
896
+        autoriser('webmestre', null, null, $qui, $opt);
897 897
 }
898 898
 
899 899
 /**
@@ -910,20 +910,20 @@  discard block
 block discarded – undo
910 910
  * @return bool          true s'il a le droit, false sinon
911 911
  **/
912 912
 function autoriser_auteur_previsualiser_dist($faire, $type, $id, $qui, $opt) {
913
-	// les admins peuvent "previsualiser" une page auteur
914
-	if ($qui['statut'] == '0minirezo'
915
-		and !$qui['restreint']
916
-	) {
917
-		return true;
918
-	}
919
-	// "Voir en ligne" si l'auteur a un article publie
920
-	$n = sql_fetsel(
921
-		'A.id_article',
922
-		'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)',
923
-		"A.statut='publie' AND L.id_auteur=" . sql_quote($id)
924
-	);
913
+    // les admins peuvent "previsualiser" une page auteur
914
+    if ($qui['statut'] == '0minirezo'
915
+        and !$qui['restreint']
916
+    ) {
917
+        return true;
918
+    }
919
+    // "Voir en ligne" si l'auteur a un article publie
920
+    $n = sql_fetsel(
921
+        'A.id_article',
922
+        'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)',
923
+        "A.statut='publie' AND L.id_auteur=" . sql_quote($id)
924
+    );
925 925
 
926
-	return $n ? true : false;
926
+    return $n ? true : false;
927 927
 }
928 928
 
929 929
 
@@ -951,7 +951,7 @@  discard block
 block discarded – undo
951 951
  * @return bool          true s'il a le droit, false sinon
952 952
  **/
953 953
 function autoriser_auteur_creer_dist($faire, $type, $id, $qui, $opt) {
954
-	return ($qui['statut'] == '0minirezo');
954
+    return ($qui['statut'] == '0minirezo');
955 955
 }
956 956
 
957 957
 
@@ -971,69 +971,69 @@  discard block
 block discarded – undo
971 971
  **/
972 972
 function autoriser_auteur_modifier_dist($faire, $type, $id, $qui, $opt) {
973 973
 
974
-	// Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login
975
-	// la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca
976
-	if (!in_array($qui['statut'], array('0minirezo'))) {
977
-		if ($id == $qui['id_auteur']
978
-			&& empty($opt['statut'])
979
-			&& empty($opt['webmestre'])
980
-			&& empty($opt['restreintes'])
981
-			&& empty($opt['login'])
982
-		) {
983
-			return true;
984
-		}
985
-		return false;
986
-	}
987
-
988
-	// Un admin restreint peut modifier/creer un auteur non-admin mais il
989
-	// n'a le droit ni de le promouvoir admin, ni de changer les rubriques
990
-	if ($qui['restreint']) {
991
-		if (isset($opt['webmestre']) and $opt['webmestre']) {
992
-			return false;
993
-		} elseif ((isset($opt['statut']) and ($opt['statut'] == '0minirezo'))
994
-			or (isset($opt['restreintes']) and $opt['restreintes'])
995
-		) {
996
-			return false;
997
-		} else {
998
-			if ($id == $qui['id_auteur']) {
999
-				if (isset($opt['statut']) and $opt['statut']) {
1000
-					return false;
1001
-				} else {
1002
-					return true;
1003
-				}
1004
-			} else {
1005
-				if ($id_auteur = intval($id)) {
1006
-					$t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur");
1007
-					if ($t and $t['statut'] != '0minirezo') {
1008
-						return true;
1009
-					} else {
1010
-						return false;
1011
-					}
1012
-				} // id = 0 => creation
1013
-				else {
1014
-					return true;
1015
-				}
1016
-			}
1017
-		}
1018
-	}
1019
-
1020
-	// Un admin complet fait ce qu'il veut
1021
-	// sauf se degrader
1022
-	if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) {
1023
-		return false;
1024
-	} elseif (isset($opt['webmestre'])
1025
-				and $opt['webmestre']
1026
-				and (defined('_ID_WEBMESTRES')
1027
-				or !autoriser('webmestre'))) {
1028
-		// et toucher au statut webmestre si il ne l'est pas lui meme
1029
-		// ou si les webmestres sont fixes par constante (securite)
1030
-		return false;
1031
-	} // et modifier un webmestre si il ne l'est pas lui meme
1032
-	elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) {
1033
-		return false;
1034
-	} else {
1035
-		return true;
1036
-	}
974
+    // Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login
975
+    // la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca
976
+    if (!in_array($qui['statut'], array('0minirezo'))) {
977
+        if ($id == $qui['id_auteur']
978
+            && empty($opt['statut'])
979
+            && empty($opt['webmestre'])
980
+            && empty($opt['restreintes'])
981
+            && empty($opt['login'])
982
+        ) {
983
+            return true;
984
+        }
985
+        return false;
986
+    }
987
+
988
+    // Un admin restreint peut modifier/creer un auteur non-admin mais il
989
+    // n'a le droit ni de le promouvoir admin, ni de changer les rubriques
990
+    if ($qui['restreint']) {
991
+        if (isset($opt['webmestre']) and $opt['webmestre']) {
992
+            return false;
993
+        } elseif ((isset($opt['statut']) and ($opt['statut'] == '0minirezo'))
994
+            or (isset($opt['restreintes']) and $opt['restreintes'])
995
+        ) {
996
+            return false;
997
+        } else {
998
+            if ($id == $qui['id_auteur']) {
999
+                if (isset($opt['statut']) and $opt['statut']) {
1000
+                    return false;
1001
+                } else {
1002
+                    return true;
1003
+                }
1004
+            } else {
1005
+                if ($id_auteur = intval($id)) {
1006
+                    $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur");
1007
+                    if ($t and $t['statut'] != '0minirezo') {
1008
+                        return true;
1009
+                    } else {
1010
+                        return false;
1011
+                    }
1012
+                } // id = 0 => creation
1013
+                else {
1014
+                    return true;
1015
+                }
1016
+            }
1017
+        }
1018
+    }
1019
+
1020
+    // Un admin complet fait ce qu'il veut
1021
+    // sauf se degrader
1022
+    if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) {
1023
+        return false;
1024
+    } elseif (isset($opt['webmestre'])
1025
+                and $opt['webmestre']
1026
+                and (defined('_ID_WEBMESTRES')
1027
+                or !autoriser('webmestre'))) {
1028
+        // et toucher au statut webmestre si il ne l'est pas lui meme
1029
+        // ou si les webmestres sont fixes par constante (securite)
1030
+        return false;
1031
+    } // et modifier un webmestre si il ne l'est pas lui meme
1032
+    elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) {
1033
+        return false;
1034
+    } else {
1035
+        return true;
1036
+    }
1037 1037
 }
1038 1038
 
1039 1039
 
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
  * @return bool          true s'il a le droit, false sinon
1051 1051
  **/
1052 1052
 function autoriser_associerauteurs_dist($faire, $type, $id, $qui, $opt) {
1053
-	return autoriser('modifier', $type, $id, $qui, $opt);
1053
+    return autoriser('modifier', $type, $id, $qui, $opt);
1054 1054
 }
1055 1055
 
1056 1056
 
@@ -1067,7 +1067,7 @@  discard block
 block discarded – undo
1067 1067
  * @return bool          true s'il a le droit, false sinon
1068 1068
  **/
1069 1069
 function autoriser_chargerftp_dist($faire, $type, $id, $qui, $opt) {
1070
-	return $qui['statut'] == '0minirezo';
1070
+    return $qui['statut'] == '0minirezo';
1071 1071
 }
1072 1072
 
1073 1073
 /**
@@ -1083,7 +1083,7 @@  discard block
 block discarded – undo
1083 1083
  * @return bool          true s'il a le droit, false sinon
1084 1084
  **/
1085 1085
 function autoriser_debug_dist($faire, $type, $id, $qui, $opt) {
1086
-	return $qui['statut'] == '0minirezo';
1086
+    return $qui['statut'] == '0minirezo';
1087 1087
 }
1088 1088
 
1089 1089
 /**
@@ -1100,52 +1100,52 @@  discard block
 block discarded – undo
1100 1100
  * @return array          Liste des rubriques
1101 1101
  **/
1102 1102
 function liste_rubriques_auteur($id_auteur, $raz = false) {
1103
-	static $restreint = array();
1104
-
1105
-	if (!$id_auteur = intval($id_auteur)) {
1106
-		return array();
1107
-	}
1108
-	if ($raz) {
1109
-		unset($restreint[$id_auteur]);
1110
-	} elseif (isset($restreint[$id_auteur])) {
1111
-		return $restreint[$id_auteur];
1112
-	}
1113
-
1114
-	$rubriques = array();
1115
-	if ((!isset($GLOBALS['meta']['version_installee'])
1116
-		or $GLOBALS['meta']['version_installee'] > 16428)
1117
-		and $r = sql_allfetsel(
1118
-			'id_objet',
1119
-			'spip_auteurs_liens',
1120
-			'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0"
1121
-		)
1122
-		and count($r)
1123
-	) {
1124
-		$r = array_column($r, 'id_objet');
1125
-
1126
-		// recuperer toute la branche, au format chaine enumeration
1127
-		include_spip('inc/rubriques');
1128
-		$r = calcul_branche_in($r);
1129
-		$r = explode(',', $r);
1130
-
1131
-		// passer les rubriques en index, elimine les doublons
1132
-		$r = array_flip($r);
1133
-		// recuperer les index seuls
1134
-		$r = array_keys($r);
1135
-		// combiner pour avoir un tableau id_rubrique=>id_rubrique
1136
-		// est-ce vraiment utile ? (on preserve la forme donnee par le code precedent)
1137
-		$rubriques = array_combine($r, $r);
1138
-	}
1139
-
1140
-	// Affecter l'auteur session le cas echeant
1141
-	if (isset($GLOBALS['visiteur_session']['id_auteur'])
1142
-		and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur
1143
-	) {
1144
-		$GLOBALS['visiteur_session']['restreint'] = $rubriques;
1145
-	}
1146
-
1147
-
1148
-	return $restreint[$id_auteur] = $rubriques;
1103
+    static $restreint = array();
1104
+
1105
+    if (!$id_auteur = intval($id_auteur)) {
1106
+        return array();
1107
+    }
1108
+    if ($raz) {
1109
+        unset($restreint[$id_auteur]);
1110
+    } elseif (isset($restreint[$id_auteur])) {
1111
+        return $restreint[$id_auteur];
1112
+    }
1113
+
1114
+    $rubriques = array();
1115
+    if ((!isset($GLOBALS['meta']['version_installee'])
1116
+        or $GLOBALS['meta']['version_installee'] > 16428)
1117
+        and $r = sql_allfetsel(
1118
+            'id_objet',
1119
+            'spip_auteurs_liens',
1120
+            'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0"
1121
+        )
1122
+        and count($r)
1123
+    ) {
1124
+        $r = array_column($r, 'id_objet');
1125
+
1126
+        // recuperer toute la branche, au format chaine enumeration
1127
+        include_spip('inc/rubriques');
1128
+        $r = calcul_branche_in($r);
1129
+        $r = explode(',', $r);
1130
+
1131
+        // passer les rubriques en index, elimine les doublons
1132
+        $r = array_flip($r);
1133
+        // recuperer les index seuls
1134
+        $r = array_keys($r);
1135
+        // combiner pour avoir un tableau id_rubrique=>id_rubrique
1136
+        // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent)
1137
+        $rubriques = array_combine($r, $r);
1138
+    }
1139
+
1140
+    // Affecter l'auteur session le cas echeant
1141
+    if (isset($GLOBALS['visiteur_session']['id_auteur'])
1142
+        and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur
1143
+    ) {
1144
+        $GLOBALS['visiteur_session']['restreint'] = $rubriques;
1145
+    }
1146
+
1147
+
1148
+    return $restreint[$id_auteur] = $rubriques;
1149 1149
 }
1150 1150
 
1151 1151
 /**
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
  * @return bool          true s'il a le droit, false sinon
1162 1162
  **/
1163 1163
 function autoriser_rubrique_previsualiser_dist($faire, $type, $id, $qui, $opt) {
1164
-	return autoriser('previsualiser');
1164
+    return autoriser('previsualiser');
1165 1165
 }
1166 1166
 
1167 1167
 /**
@@ -1177,7 +1177,7 @@  discard block
 block discarded – undo
1177 1177
  * @return bool          true s'il a le droit, false sinon
1178 1178
  **/
1179 1179
 function autoriser_rubrique_iconifier_dist($faire, $type, $id, $qui, $opt) {
1180
-	return autoriser('publierdans', 'rubrique', $id, $qui, $opt);
1180
+    return autoriser('publierdans', 'rubrique', $id, $qui, $opt);
1181 1181
 }
1182 1182
 
1183 1183
 /**
@@ -1193,8 +1193,8 @@  discard block
 block discarded – undo
1193 1193
  * @return bool          true s'il a le droit, false sinon
1194 1194
  **/
1195 1195
 function autoriser_auteur_iconifier_dist($faire, $type, $id, $qui, $opt) {
1196
-	return (($id == $qui['id_auteur']) or
1197
-		(($qui['statut'] == '0minirezo') and !$qui['restreint']));
1196
+    return (($id == $qui['id_auteur']) or
1197
+        (($qui['statut'] == '0minirezo') and !$qui['restreint']));
1198 1198
 }
1199 1199
 
1200 1200
 /**
@@ -1210,8 +1210,8 @@  discard block
 block discarded – undo
1210 1210
  * @return bool          true s'il a le droit, false sinon
1211 1211
  **/
1212 1212
 function autoriser_iconifier_dist($faire, $type, $id, $qui, $opt) {
1213
-	// par defaut, on a le droit d'iconifier si on a le droit de modifier
1214
-	return autoriser('modifier', $type, $id, $qui, $opt);
1213
+    // par defaut, on a le droit d'iconifier si on a le droit de modifier
1214
+    return autoriser('modifier', $type, $id, $qui, $opt);
1215 1215
 }
1216 1216
 
1217 1217
 
@@ -1229,7 +1229,7 @@  discard block
 block discarded – undo
1229 1229
  * @return bool          true
1230 1230
  **/
1231 1231
 function autoriser_ok_dist($faire, $type, $id, $qui, $opt) {
1232
-	return true;
1232
+    return true;
1233 1233
 }
1234 1234
 
1235 1235
 /**
@@ -1246,7 +1246,7 @@  discard block
 block discarded – undo
1246 1246
  * @return bool          false
1247 1247
  **/
1248 1248
 function autoriser_niet_dist($faire, $type, $id, $qui, $opt) {
1249
-	return false;
1249
+    return false;
1250 1250
 }
1251 1251
 
1252 1252
 /**
@@ -1262,11 +1262,11 @@  discard block
 block discarded – undo
1262 1262
  * @return bool          false
1263 1263
  **/
1264 1264
 function autoriser_base_reparer_dist($faire, $type, $id, $qui, $opt) {
1265
-	if (!autoriser('detruire') or _request('reinstall')) {
1266
-		return false;
1267
-	}
1265
+    if (!autoriser('detruire') or _request('reinstall')) {
1266
+        return false;
1267
+    }
1268 1268
 
1269
-	return true;
1269
+    return true;
1270 1270
 }
1271 1271
 
1272 1272
 /**
@@ -1282,7 +1282,7 @@  discard block
 block discarded – undo
1282 1282
  * @return bool          true s'il a le droit, false sinon
1283 1283
  **/
1284 1284
 function autoriser_infosperso_dist($faire, $type, $id, $qui, $opt) {
1285
-	return true;
1285
+    return true;
1286 1286
 }
1287 1287
 
1288 1288
 /**
@@ -1298,7 +1298,7 @@  discard block
 block discarded – undo
1298 1298
  * @return bool          true s'il a le droit, false sinon
1299 1299
  **/
1300 1300
 function autoriser_langage_configurer_dist($faire, $type, $id, $qui, $opt) {
1301
-	return true;
1301
+    return true;
1302 1302
 }
1303 1303
 
1304 1304
 /**
@@ -1314,7 +1314,7 @@  discard block
 block discarded – undo
1314 1314
  * @return bool          true s'il a le droit, false sinon
1315 1315
  **/
1316 1316
 function autoriser_configurerlangage_dist($faire, $type, $id, $qui, $opt) {
1317
-	return autoriser('configurer', '_langage', $id, $qui, $opt);
1317
+    return autoriser('configurer', '_langage', $id, $qui, $opt);
1318 1318
 }
1319 1319
 
1320 1320
 /**
@@ -1330,7 +1330,7 @@  discard block
 block discarded – undo
1330 1330
  * @return bool          true s'il a le droit, false sinon
1331 1331
  **/
1332 1332
 function autoriser_preferences_configurer_dist($faire, $type, $id, $qui, $opt) {
1333
-	return true;
1333
+    return true;
1334 1334
 }
1335 1335
 
1336 1336
 /**
@@ -1346,7 +1346,7 @@  discard block
 block discarded – undo
1346 1346
  * @return bool          true s'il a le droit, false sinon
1347 1347
  **/
1348 1348
 function autoriser_configurerpreferences_dist($faire, $type, $id, $qui, $opt) {
1349
-	return autoriser('configurer', '_preferences', $id, $qui, $opt);
1349
+    return autoriser('configurer', '_preferences', $id, $qui, $opt);
1350 1350
 }
1351 1351
 
1352 1352
 /**
@@ -1362,8 +1362,8 @@  discard block
 block discarded – undo
1362 1362
  * @return bool          true s'il a le droit, false sinon
1363 1363
  **/
1364 1364
 function autoriser_menudeveloppement_menugrandeentree_dist($faire, $type, $id, $qui, $opt) {
1365
-	return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev'])
1366
-		and $GLOBALS['visiteur_session']['prefs']['activer_menudev'] == 'oui');
1365
+    return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev'])
1366
+        and $GLOBALS['visiteur_session']['prefs']['activer_menudev'] == 'oui');
1367 1367
 }
1368 1368
 
1369 1369
 /**
@@ -1380,7 +1380,7 @@  discard block
 block discarded – undo
1380 1380
  * @return bool          true s'il a le droit, false sinon
1381 1381
  **/
1382 1382
 function autoriser_menugrandeentree_dist($faire, $type, $id, $qui, $opt) {
1383
-	return true;
1383
+    return true;
1384 1384
 }
1385 1385
 
1386 1386
 /**
@@ -1396,7 +1396,7 @@  discard block
 block discarded – undo
1396 1396
  * @return bool          true s'il a le droit, false sinon
1397 1397
  **/
1398 1398
 function autoriser_auteurs_voir_dist($faire, $type, $id, $qui, $opt) {
1399
-	return true;
1399
+    return true;
1400 1400
 }
1401 1401
 
1402 1402
 /**
@@ -1412,7 +1412,7 @@  discard block
 block discarded – undo
1412 1412
  * @return bool          true s'il a le droit, false sinon
1413 1413
  **/
1414 1414
 function autoriser_auteurs_menu_dist($faire, $type, $id, $qui, $opt) {
1415
-	return autoriser('voir', '_auteurs', $id, $qui, $opt);
1415
+    return autoriser('voir', '_auteurs', $id, $qui, $opt);
1416 1416
 }
1417 1417
 
1418 1418
 /**
@@ -1428,7 +1428,7 @@  discard block
 block discarded – undo
1428 1428
  * @return bool          true s'il a le droit, false sinon
1429 1429
  **/
1430 1430
 function autoriser_articles_voir_dist($faire, $type, $id, $qui, $opt) {
1431
-	return true;
1431
+    return true;
1432 1432
 }
1433 1433
 
1434 1434
 /**
@@ -1444,7 +1444,7 @@  discard block
 block discarded – undo
1444 1444
  * @return bool          true s'il a le droit, false sinon
1445 1445
  **/
1446 1446
 function autoriser_articles_menu_dist($faire, $type, $id, $qui, $opt) {
1447
-	return autoriser('voir', '_articles', $id, $qui, $opt);
1447
+    return autoriser('voir', '_articles', $id, $qui, $opt);
1448 1448
 }
1449 1449
 
1450 1450
 /**
@@ -1460,7 +1460,7 @@  discard block
 block discarded – undo
1460 1460
  * @return bool          true s'il a le droit, false sinon
1461 1461
  **/
1462 1462
 function autoriser_rubriques_voir_dist($faire, $type, $id, $qui, $opt) {
1463
-	return true;
1463
+    return true;
1464 1464
 }
1465 1465
 
1466 1466
 /**
@@ -1476,7 +1476,7 @@  discard block
 block discarded – undo
1476 1476
  * @return bool          true s'il a le droit, false sinon
1477 1477
  **/
1478 1478
 function autoriser_rubriques_menu_dist($faire, $type, $id, $qui, $opt) {
1479
-	return autoriser('voir', '_rubriques', $id, $qui, $opt);
1479
+    return autoriser('voir', '_rubriques', $id, $qui, $opt);
1480 1480
 }
1481 1481
 
1482 1482
 /**
@@ -1492,7 +1492,7 @@  discard block
 block discarded – undo
1492 1492
  * @return bool          true s'il a le droit, false sinon
1493 1493
  **/
1494 1494
 function autoriser_articlecreer_menu_dist($faire, $type, $id, $qui, $opt) {
1495
-	return verifier_table_non_vide();
1495
+    return verifier_table_non_vide();
1496 1496
 }
1497 1497
 
1498 1498
 
@@ -1511,7 +1511,7 @@  discard block
 block discarded – undo
1511 1511
  * @return bool          true s'il a le droit, false sinon
1512 1512
  **/
1513 1513
 function autoriser_auteurcreer_menu_dist($faire, $type, $id, $qui, $opt) {
1514
-	return autoriser('creer', 'auteur', $id, $qui, $opt);
1514
+    return autoriser('creer', 'auteur', $id, $qui, $opt);
1515 1515
 }
1516 1516
 
1517 1517
 /**
@@ -1527,13 +1527,13 @@  discard block
 block discarded – undo
1527 1527
  * @return bool          true s'il a le droit, false sinon
1528 1528
  **/
1529 1529
 function autoriser_visiteurs_menu_dist($faire, $type, $id, $qui, $opt) {
1530
-	include_spip('base/abstract_sql');
1531
-	return 
1532
-		$qui['statut'] == '0minirezo' and !$qui['restreint']
1533
-		and (
1534
-			$GLOBALS['meta']["accepter_visiteurs"] != 'non'
1535
-			or sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0
1536
-		);
1530
+    include_spip('base/abstract_sql');
1531
+    return 
1532
+        $qui['statut'] == '0minirezo' and !$qui['restreint']
1533
+        and (
1534
+            $GLOBALS['meta']["accepter_visiteurs"] != 'non'
1535
+            or sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0
1536
+        );
1537 1537
 }
1538 1538
 
1539 1539
 /**
@@ -1549,7 +1549,7 @@  discard block
 block discarded – undo
1549 1549
  * @return bool          true s'il a le droit, false sinon
1550 1550
  **/
1551 1551
 function autoriser_suiviedito_menu_dist($faire, $type, $id, $qui, $opt) {
1552
-	return $qui['statut'] == '0minirezo';
1552
+    return $qui['statut'] == '0minirezo';
1553 1553
 }
1554 1554
 
1555 1555
 /**
@@ -1565,7 +1565,7 @@  discard block
 block discarded – undo
1565 1565
  * @return bool          true s'il a le droit, false sinon
1566 1566
  **/
1567 1567
 function autoriser_synchro_menu_dist($faire, $type, $id, $qui, $opt) {
1568
-	return $qui['statut'] == '0minirezo';
1568
+    return $qui['statut'] == '0minirezo';
1569 1569
 }
1570 1570
 
1571 1571
 /**
@@ -1693,7 +1693,7 @@  discard block
 block discarded – undo
1693 1693
  * @return bool          true s'il a le droit, false sinon
1694 1694
  **/
1695 1695
 function autoriser_queue_purger_dist($faire, $type, $id, $qui, $opt) {
1696
-	return autoriser('webmestre');
1696
+    return autoriser('webmestre');
1697 1697
 }
1698 1698
 
1699 1699
 
@@ -1711,11 +1711,11 @@  discard block
 block discarded – undo
1711 1711
  * @return bool          true s'il a le droit, false sinon
1712 1712
  **/
1713 1713
 function autoriser_echafauder_dist($faire, $type, $id, $qui, $opt) {
1714
-	if (test_espace_prive()) {
1715
-		return intval($qui['id_auteur']) ? true : false;
1716
-	} else {
1717
-		return autoriser('webmestre', '', $id, $qui, $opt);
1718
-	}
1714
+    if (test_espace_prive()) {
1715
+        return intval($qui['id_auteur']) ? true : false;
1716
+    } else {
1717
+        return autoriser('webmestre', '', $id, $qui, $opt);
1718
+    }
1719 1719
 }
1720 1720
 
1721 1721
 
@@ -1730,27 +1730,27 @@  discard block
 block discarded – undo
1730 1730
  *     Identifiants d'auteurs
1731 1731
  */
1732 1732
 function auteurs_objet($objet, $id_objet, $cond = '') {
1733
-	$objet = objet_type($objet);
1734
-	$where = array(
1735
-		'objet=' . sql_quote($objet),
1736
-		'id_objet=' . intval($id_objet)
1737
-	);
1738
-	if (!empty($cond)) {
1739
-		if (is_array($cond)) {
1740
-			$where = array_merge($where, $cond);
1741
-		} else {
1742
-			$where[] = $cond;
1743
-		}
1744
-	}
1745
-	$auteurs = sql_allfetsel(
1746
-		'id_auteur',
1747
-		'spip_auteurs_liens',
1748
-		$where
1749
-	);
1750
-	if (is_array($auteurs)) {
1751
-		return array_column($auteurs, 'id_auteur');
1752
-	}
1753
-	return array();
1733
+    $objet = objet_type($objet);
1734
+    $where = array(
1735
+        'objet=' . sql_quote($objet),
1736
+        'id_objet=' . intval($id_objet)
1737
+    );
1738
+    if (!empty($cond)) {
1739
+        if (is_array($cond)) {
1740
+            $where = array_merge($where, $cond);
1741
+        } else {
1742
+            $where[] = $cond;
1743
+        }
1744
+    }
1745
+    $auteurs = sql_allfetsel(
1746
+        'id_auteur',
1747
+        'spip_auteurs_liens',
1748
+        $where
1749
+    );
1750
+    if (is_array($auteurs)) {
1751
+        return array_column($auteurs, 'id_auteur');
1752
+    }
1753
+    return array();
1754 1754
 }
1755 1755
 
1756 1756
 /**
@@ -1764,11 +1764,11 @@  discard block
 block discarded – undo
1764 1764
  *     - false : serveur SQL indisponible
1765 1765
  */
1766 1766
 function auteurs_article($id_article, $cond = '') {
1767
-	return sql_allfetsel(
1768
-		'id_auteur',
1769
-		'spip_auteurs_liens',
1770
-		"objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '')
1771
-	);
1767
+    return sql_allfetsel(
1768
+        'id_auteur',
1769
+        'spip_auteurs_liens',
1770
+        "objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '')
1771
+    );
1772 1772
 }
1773 1773
 
1774 1774
 
@@ -1782,7 +1782,7 @@  discard block
 block discarded – undo
1782 1782
  */
1783 1783
 function acces_restreint_rubrique($id_rubrique) {
1784 1784
 
1785
-	return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique]));
1785
+    return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique]));
1786 1786
 }
1787 1787
 
1788 1788
 
@@ -1795,12 +1795,12 @@  discard block
 block discarded – undo
1795 1795
  * @return bool             true si un parent existe
1796 1796
  */
1797 1797
 function verifier_table_non_vide($table = 'spip_rubriques') {
1798
-	static $done = array();
1799
-	if (!isset($done[$table])) {
1800
-		$done[$table] = sql_countsel($table) > 0;
1801
-	}
1798
+    static $done = array();
1799
+    if (!isset($done[$table])) {
1800
+        $done[$table] = sql_countsel($table) > 0;
1801
+    }
1802 1802
 
1803
-	return $done[$table];
1803
+    return $done[$table];
1804 1804
 }
1805 1805
 
1806 1806
 /**
@@ -1825,15 +1825,15 @@  discard block
 block discarded – undo
1825 1825
  */
1826 1826
 function autoriser_inscrireauteur_dist($faire, $quoi, $id, $qui, $opt) {
1827 1827
 
1828
-	$s = array_search($quoi, $GLOBALS['liste_des_statuts']);
1829
-	switch ($s) {
1830
-		case 'info_redacteurs':
1831
-			return ($GLOBALS['meta']['accepter_inscriptions'] == 'oui');
1832
-		case 'info_visiteurs':
1833
-			return ($GLOBALS['meta']['accepter_visiteurs'] == 'oui' or $GLOBALS['meta']['forums_publics'] == 'abo');
1834
-	}
1828
+    $s = array_search($quoi, $GLOBALS['liste_des_statuts']);
1829
+    switch ($s) {
1830
+        case 'info_redacteurs':
1831
+            return ($GLOBALS['meta']['accepter_inscriptions'] == 'oui');
1832
+        case 'info_visiteurs':
1833
+            return ($GLOBALS['meta']['accepter_visiteurs'] == 'oui' or $GLOBALS['meta']['forums_publics'] == 'abo');
1834
+    }
1835 1835
 
1836
-	return false;
1836
+    return false;
1837 1837
 }
1838 1838
 
1839 1839
 /**
@@ -1849,7 +1849,7 @@  discard block
 block discarded – undo
1849 1849
  * @return bool          false
1850 1850
  **/
1851 1851
 function autoriser_inscription_relancer_dist($faire, $type, $id, $qui, $opt) {
1852
-	return $qui['statut'] == '0minirezo' and !$qui['restreint'];
1852
+    return $qui['statut'] == '0minirezo' and !$qui['restreint'];
1853 1853
 }
1854 1854
 
1855 1855
 /**
@@ -1865,5 +1865,5 @@  discard block
 block discarded – undo
1865 1865
  * @return bool          true s'il a le droit, false sinon
1866 1866
  **/
1867 1867
 function autoriser_phpinfos_dist($faire, $type, $id, $qui, $opt) {
1868
-	return autoriser('webmestre');
1868
+    return autoriser('webmestre');
1869 1869
 }
Please login to merge, or discard this patch.
ecrire/inc/charsets.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
  * @param string $charset
38 38
  *     Charset à charger.
39 39
  *     Par défaut (AUTO), utilise le charset du site
40
- * @return string|bool
40
+ * @return string|false
41 41
  *     - Nom du charset
42 42
  *     - false si le charset n'est pas décrit dans le répertoire charsets/
43 43
  **/
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
  *
707 707
  * @param int $num
708 708
  *    Numéro de l'entité unicode
709
- * @return char
709
+ * @return string
710 710
  *    Caractère utf8 si trouvé, '' sinon
711 711
  **/
712 712
 function caractere_utf_8($num) {
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		}
74 74
 	}
75 75
 
76
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
76
+	if (find_in_path($charset.'.php', 'charsets/', true)) {
77 77
 		return $charset;
78 78
 	} else {
79 79
 		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	static $pcre_ok = 0;
160 160
 
161 161
 	if (!$pcre_ok) {
162
-		$s = " " . chr(195) . chr(169) . "t" . chr(195) . chr(169) . " ";
162
+		$s = " ".chr(195).chr(169)."t".chr(195).chr(169)." ";
163 163
 		if (preg_match(',\W...\W,u', $s)) {
164 164
 			$pcre_ok = 1;
165 165
 		} else {
@@ -260,38 +260,38 @@  discard block
 block discarded – undo
260 260
 
261 261
 	if (!isset($trans[$charset][$charset_cible])) {
262 262
 		$trans[$charset][$charset_cible] = array(
263
-			$p . chr(128) => "&#8364;",
264
-			$p . chr(129) => ' ', # pas affecte
265
-			$p . chr(130) => "&#8218;",
266
-			$p . chr(131) => "&#402;",
267
-			$p . chr(132) => "&#8222;",
268
-			$p . chr(133) => "&#8230;",
269
-			$p . chr(134) => "&#8224;",
270
-			$p . chr(135) => "&#8225;",
271
-			$p . chr(136) => "&#710;",
272
-			$p . chr(137) => "&#8240;",
273
-			$p . chr(138) => "&#352;",
274
-			$p . chr(139) => "&#8249;",
275
-			$p . chr(140) => "&#338;",
276
-			$p . chr(141) => ' ', # pas affecte
277
-			$p . chr(142) => "&#381;",
278
-			$p . chr(143) => ' ', # pas affecte
279
-			$p . chr(144) => ' ', # pas affecte
280
-			$p . chr(145) => "&#8216;",
281
-			$p . chr(146) => "&#8217;",
282
-			$p . chr(147) => "&#8220;",
283
-			$p . chr(148) => "&#8221;",
284
-			$p . chr(149) => "&#8226;",
285
-			$p . chr(150) => "&#8211;",
286
-			$p . chr(151) => "&#8212;",
287
-			$p . chr(152) => "&#732;",
288
-			$p . chr(153) => "&#8482;",
289
-			$p . chr(154) => "&#353;",
290
-			$p . chr(155) => "&#8250;",
291
-			$p . chr(156) => "&#339;",
292
-			$p . chr(157) => ' ', # pas affecte
293
-			$p . chr(158) => "&#382;",
294
-			$p . chr(159) => "&#376;",
263
+			$p.chr(128) => "&#8364;",
264
+			$p.chr(129) => ' ', # pas affecte
265
+			$p.chr(130) => "&#8218;",
266
+			$p.chr(131) => "&#402;",
267
+			$p.chr(132) => "&#8222;",
268
+			$p.chr(133) => "&#8230;",
269
+			$p.chr(134) => "&#8224;",
270
+			$p.chr(135) => "&#8225;",
271
+			$p.chr(136) => "&#710;",
272
+			$p.chr(137) => "&#8240;",
273
+			$p.chr(138) => "&#352;",
274
+			$p.chr(139) => "&#8249;",
275
+			$p.chr(140) => "&#338;",
276
+			$p.chr(141) => ' ', # pas affecte
277
+			$p.chr(142) => "&#381;",
278
+			$p.chr(143) => ' ', # pas affecte
279
+			$p.chr(144) => ' ', # pas affecte
280
+			$p.chr(145) => "&#8216;",
281
+			$p.chr(146) => "&#8217;",
282
+			$p.chr(147) => "&#8220;",
283
+			$p.chr(148) => "&#8221;",
284
+			$p.chr(149) => "&#8226;",
285
+			$p.chr(150) => "&#8211;",
286
+			$p.chr(151) => "&#8212;",
287
+			$p.chr(152) => "&#732;",
288
+			$p.chr(153) => "&#8482;",
289
+			$p.chr(154) => "&#353;",
290
+			$p.chr(155) => "&#8250;",
291
+			$p.chr(156) => "&#339;",
292
+			$p.chr(157) => ' ', # pas affecte
293
+			$p.chr(158) => "&#382;",
294
+			$p.chr(159) => "&#376;",
295 295
 		);
296 296
 		if ($charset_cible != 'unicode') {
297 297
 			foreach ($trans[$charset][$charset_cible] as $k => $c) {
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 					and is_array($GLOBALS['CHARSET'][$cset])
422 422
 				) {
423 423
 					foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
424
-						$trans[$charset][chr($key)] = '&#' . $val . ';';
424
+						$trans[$charset][chr($key)] = '&#'.$val.';';
425 425
 					}
426 426
 				}
427 427
 			}
@@ -488,11 +488,11 @@  discard block
 block discarded – undo
488 488
 					$h = dechex($e);
489 489
 					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
490 490
 						$s = $CHARSET_REVERSE[$charset][$e];
491
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
492
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
491
+						$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($s);
492
+						$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($s);
493 493
 					} else {
494
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
495
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
494
+						$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($e);
495
+						$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($e);
496 496
 					}
497 497
 				}
498 498
 			}
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
 				and is_array($GLOBALS['CHARSET'][$cset])
537 537
 			) {
538 538
 				foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
539
-					$trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
539
+					$trans[$charset][chr($key)] = unicode2charset('&#'.$val.';');
540 540
 				}
541 541
 			}
542 542
 		}
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
 				}
644 644
 				$thisPos++;
645 645
 			}
646
-			$encodedLetter = "&#" . preg_replace('/^0+/', '', $decimalCode) . ';';
646
+			$encodedLetter = "&#".preg_replace('/^0+/', '', $decimalCode).';';
647 647
 			$encodedString .= $encodedLetter;
648 648
 		}
649 649
 	}
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
 			} // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
687 687
 			else {
688 688
 				if ($word != 65279) {
689
-					$texte .= '&#' . $word . ';';
689
+					$texte .= '&#'.$word.';';
690 690
 				}
691 691
 			}
692 692
 		}
@@ -715,13 +715,13 @@  discard block
 block discarded – undo
715 715
 		return chr($num);
716 716
 	}
717 717
 	if ($num < 2048) {
718
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
718
+		return chr(($num >> 6) + 192).chr(($num & 63) + 128);
719 719
 	}
720 720
 	if ($num < 65536) {
721
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
721
+		return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
722 722
 	}
723 723
 	if ($num < 1114112) {
724
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
724
+		return chr(($num >> 18) + 240).chr((($num >> 12) & 63) + 128).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
725 725
 	}
726 726
 
727 727
 	return '';
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
 	while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
778 778
 		$num = $regs[1];
779 779
 		$vu[$num] = true;
780
-		$s = '\u' . sprintf("%04x", $num);
780
+		$s = '\u'.sprintf("%04x", $num);
781 781
 		$texte = str_replace($regs[0], $s, $texte);
782 782
 	}
783 783
 
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
  **/
795 795
 function javascript_to_unicode($texte) {
796 796
 	while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs)) {
797
-		$texte = str_replace($regs[0], "&#" . hexdec($regs[1]) . ";", $texte);
797
+		$texte = str_replace($regs[0], "&#".hexdec($regs[1]).";", $texte);
798 798
 	}
799 799
 
800 800
 	return $texte;
@@ -839,7 +839,7 @@  discard block
 block discarded – undo
839 839
 		return $texte;
840 840
 	}
841 841
 
842
-	$table_translit = 'translit' . $complexe;
842
+	$table_translit = 'translit'.$complexe;
843 843
 
844 844
 	// 2. Translitterer grace a la table predefinie
845 845
 	if (!isset($trans[$complexe])) {
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
  *    true s'il a un BOM
931 931
  **/
932 932
 function bom_utf8($texte) {
933
-	return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
933
+	return (substr($texte, 0, 3) == chr(0xEF).chr(0xBB).chr(0xBF));
934 934
 }
935 935
 
936 936
 /**
@@ -1125,7 +1125,7 @@  discard block
 block discarded – undo
1125 1125
 		// on prend n fois la longueur desiree, pour etre surs d'avoir tout
1126 1126
 		// (un caractere utf-8 prenant au maximum n bytes)
1127 1127
 		$n = 0;
1128
-		while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1128
+		while (preg_match(',[\x80-\xBF]{'.(++$n).'},', $c)) {
1129 1129
 			;
1130 1130
 		}
1131 1131
 		$c = substr($c, 0, $n * $length);
@@ -1159,7 +1159,7 @@  discard block
 block discarded – undo
1159 1159
 
1160 1160
 	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1161 1161
 
1162
-	return $lettre1 . spip_substr($c, 1);
1162
+	return $lettre1.spip_substr($c, 1);
1163 1163
 }
1164 1164
 
1165 1165
 /**
Please login to merge, or discard this patch.
Indentation   +704 added lines, -704 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 // securité
24 24
 if (!defined('_ECRIRE_INC_VERSION')) {
25
-	return;
25
+    return;
26 26
 }
27 27
 
28 28
 // se faciliter la lecture du charset
@@ -42,45 +42,45 @@  discard block
 block discarded – undo
42 42
  *     - false si le charset n'est pas décrit dans le répertoire charsets/
43 43
  **/
44 44
 function load_charset($charset = 'AUTO') {
45
-	if ($charset == 'AUTO') {
46
-		$charset = $GLOBALS['meta']['charset'];
47
-	}
48
-	$charset = trim(strtolower($charset));
49
-	if (isset($GLOBALS['CHARSET'][$charset])) {
50
-		return $charset;
51
-	}
52
-
53
-	if ($charset == 'utf-8') {
54
-		$GLOBALS['CHARSET'][$charset] = array();
55
-
56
-		return $charset;
57
-	}
58
-
59
-	// Quelques synonymes
60
-	if ($charset == '') {
61
-		$charset = 'iso-8859-1';
62
-	} else {
63
-		if ($charset == 'windows-1250') {
64
-			$charset = 'cp1250';
65
-		} else {
66
-			if ($charset == 'windows-1251') {
67
-				$charset = 'cp1251';
68
-			} else {
69
-				if ($charset == 'windows-1256') {
70
-					$charset = 'cp1256';
71
-				}
72
-			}
73
-		}
74
-	}
75
-
76
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
77
-		return $charset;
78
-	} else {
79
-		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
80
-		$GLOBALS['CHARSET'][$charset] = array();
81
-
82
-		return false;
83
-	}
45
+    if ($charset == 'AUTO') {
46
+        $charset = $GLOBALS['meta']['charset'];
47
+    }
48
+    $charset = trim(strtolower($charset));
49
+    if (isset($GLOBALS['CHARSET'][$charset])) {
50
+        return $charset;
51
+    }
52
+
53
+    if ($charset == 'utf-8') {
54
+        $GLOBALS['CHARSET'][$charset] = array();
55
+
56
+        return $charset;
57
+    }
58
+
59
+    // Quelques synonymes
60
+    if ($charset == '') {
61
+        $charset = 'iso-8859-1';
62
+    } else {
63
+        if ($charset == 'windows-1250') {
64
+            $charset = 'cp1250';
65
+        } else {
66
+            if ($charset == 'windows-1251') {
67
+                $charset = 'cp1251';
68
+            } else {
69
+                if ($charset == 'windows-1256') {
70
+                    $charset = 'cp1256';
71
+                }
72
+            }
73
+        }
74
+    }
75
+
76
+    if (find_in_path($charset . '.php', 'charsets/', true)) {
77
+        return $charset;
78
+    } else {
79
+        spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
80
+        $GLOBALS['CHARSET'][$charset] = array();
81
+
82
+        return false;
83
+    }
84 84
 }
85 85
 
86 86
 
@@ -91,30 +91,30 @@  discard block
 block discarded – undo
91 91
  *     true si toutes les fonctions mb nécessaires sont présentes
92 92
  **/
93 93
 function init_mb_string() {
94
-	static $mb;
95
-
96
-	// verifier que tout est present (fonctions mb_string pour php >= 4.0.6)
97
-	// et que le charset interne est connu de mb_string
98
-	if (!$mb) {
99
-		if (function_exists('mb_internal_encoding')
100
-			and function_exists('mb_detect_order')
101
-			and function_exists('mb_substr')
102
-			and function_exists('mb_strlen')
103
-			and function_exists('mb_strtolower')
104
-			and function_exists('mb_strtoupper')
105
-			and function_exists('mb_encode_mimeheader')
106
-			and function_exists('mb_encode_numericentity')
107
-			and function_exists('mb_decode_numericentity')
108
-			and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))
109
-		) {
110
-			mb_internal_encoding('utf-8');
111
-			$mb = 1;
112
-		} else {
113
-			$mb = -1;
114
-		}
115
-	}
116
-
117
-	return ($mb == 1);
94
+    static $mb;
95
+
96
+    // verifier que tout est present (fonctions mb_string pour php >= 4.0.6)
97
+    // et que le charset interne est connu de mb_string
98
+    if (!$mb) {
99
+        if (function_exists('mb_internal_encoding')
100
+            and function_exists('mb_detect_order')
101
+            and function_exists('mb_substr')
102
+            and function_exists('mb_strlen')
103
+            and function_exists('mb_strtolower')
104
+            and function_exists('mb_strtoupper')
105
+            and function_exists('mb_encode_mimeheader')
106
+            and function_exists('mb_encode_numericentity')
107
+            and function_exists('mb_decode_numericentity')
108
+            and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))
109
+        ) {
110
+            mb_internal_encoding('utf-8');
111
+            $mb = 1;
112
+        } else {
113
+            $mb = -1;
114
+        }
115
+    }
116
+
117
+    return ($mb == 1);
118 118
 }
119 119
 
120 120
 /**
@@ -129,21 +129,21 @@  discard block
 block discarded – undo
129 129
  *     true si iconv fonctionne correctement
130 130
  **/
131 131
 function test_iconv() {
132
-	static $iconv_ok;
133
-
134
-	if (!$iconv_ok) {
135
-		if (!function_exists('iconv')) {
136
-			$iconv_ok = -1;
137
-		} else {
138
-			if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') {
139
-				$iconv_ok = 1;
140
-			} else {
141
-				$iconv_ok = -1;
142
-			}
143
-		}
144
-	}
145
-
146
-	return ($iconv_ok == 1);
132
+    static $iconv_ok;
133
+
134
+    if (!$iconv_ok) {
135
+        if (!function_exists('iconv')) {
136
+            $iconv_ok = -1;
137
+        } else {
138
+            if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') {
139
+                $iconv_ok = 1;
140
+            } else {
141
+                $iconv_ok = -1;
142
+            }
143
+        }
144
+    }
145
+
146
+    return ($iconv_ok == 1);
147 147
 }
148 148
 
149 149
 
@@ -156,18 +156,18 @@  discard block
 block discarded – undo
156 156
  *     true si PCRE supporte l'UTF-8 correctement
157 157
  **/
158 158
 function test_pcre_unicode() {
159
-	static $pcre_ok = 0;
160
-
161
-	if (!$pcre_ok) {
162
-		$s = " " . chr(195) . chr(169) . "t" . chr(195) . chr(169) . " ";
163
-		if (preg_match(',\W...\W,u', $s)) {
164
-			$pcre_ok = 1;
165
-		} else {
166
-			$pcre_ok = -1;
167
-		}
168
-	}
169
-
170
-	return $pcre_ok == 1;
159
+    static $pcre_ok = 0;
160
+
161
+    if (!$pcre_ok) {
162
+        $s = " " . chr(195) . chr(169) . "t" . chr(195) . chr(169) . " ";
163
+        if (preg_match(',\W...\W,u', $s)) {
164
+            $pcre_ok = 1;
165
+        } else {
166
+            $pcre_ok = -1;
167
+        }
168
+    }
169
+
170
+    return $pcre_ok == 1;
171 171
 }
172 172
 
173 173
 /**
@@ -183,22 +183,22 @@  discard block
 block discarded – undo
183 183
  *    Plage de caractères
184 184
  **/
185 185
 function pcre_lettres_unicode() {
186
-	static $plage_unicode;
187
-
188
-	if (!$plage_unicode) {
189
-		if (test_pcre_unicode()) {
190
-			// cf. http://www.unicode.org/charts/
191
-			$plage_unicode = '\w' // iso-latin
192
-				. '\x{100}-\x{24f}' // europeen etendu
193
-				. '\x{300}-\x{1cff}' // des tas de trucs
194
-			;
195
-		} else {
196
-			// fallback a trois sous
197
-			$plage_unicode = '\w';
198
-		}
199
-	}
200
-
201
-	return $plage_unicode;
186
+    static $plage_unicode;
187
+
188
+    if (!$plage_unicode) {
189
+        if (test_pcre_unicode()) {
190
+            // cf. http://www.unicode.org/charts/
191
+            $plage_unicode = '\w' // iso-latin
192
+                . '\x{100}-\x{24f}' // europeen etendu
193
+                . '\x{300}-\x{1cff}' // des tas de trucs
194
+            ;
195
+        } else {
196
+            // fallback a trois sous
197
+            $plage_unicode = '\w';
198
+        }
199
+    }
200
+
201
+    return $plage_unicode;
202 202
 }
203 203
 
204 204
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
  *    Plage de caractères
217 217
  **/
218 218
 function plage_punct_unicode() {
219
-	return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])';
219
+    return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])';
220 220
 }
221 221
 
222 222
 /**
@@ -236,72 +236,72 @@  discard block
 block discarded – undo
236 236
  *     Texte corrigé
237 237
  **/
238 238
 function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') {
239
-	static $trans;
240
-
241
-	if (is_array($texte)) {
242
-		return array_map('corriger_caracteres_windows', $texte);
243
-	}
244
-
245
-	if ($charset == 'AUTO') {
246
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
247
-	}
248
-	if ($charset == 'utf-8') {
249
-		$p = chr(194);
250
-		if (strpos($texte, $p) == false) {
251
-			return $texte;
252
-		}
253
-	} else {
254
-		if ($charset == 'iso-8859-1') {
255
-			$p = '';
256
-		} else {
257
-			return $texte;
258
-		}
259
-	}
260
-
261
-	if (!isset($trans[$charset][$charset_cible])) {
262
-		$trans[$charset][$charset_cible] = array(
263
-			$p . chr(128) => "&#8364;",
264
-			$p . chr(129) => ' ', # pas affecte
265
-			$p . chr(130) => "&#8218;",
266
-			$p . chr(131) => "&#402;",
267
-			$p . chr(132) => "&#8222;",
268
-			$p . chr(133) => "&#8230;",
269
-			$p . chr(134) => "&#8224;",
270
-			$p . chr(135) => "&#8225;",
271
-			$p . chr(136) => "&#710;",
272
-			$p . chr(137) => "&#8240;",
273
-			$p . chr(138) => "&#352;",
274
-			$p . chr(139) => "&#8249;",
275
-			$p . chr(140) => "&#338;",
276
-			$p . chr(141) => ' ', # pas affecte
277
-			$p . chr(142) => "&#381;",
278
-			$p . chr(143) => ' ', # pas affecte
279
-			$p . chr(144) => ' ', # pas affecte
280
-			$p . chr(145) => "&#8216;",
281
-			$p . chr(146) => "&#8217;",
282
-			$p . chr(147) => "&#8220;",
283
-			$p . chr(148) => "&#8221;",
284
-			$p . chr(149) => "&#8226;",
285
-			$p . chr(150) => "&#8211;",
286
-			$p . chr(151) => "&#8212;",
287
-			$p . chr(152) => "&#732;",
288
-			$p . chr(153) => "&#8482;",
289
-			$p . chr(154) => "&#353;",
290
-			$p . chr(155) => "&#8250;",
291
-			$p . chr(156) => "&#339;",
292
-			$p . chr(157) => ' ', # pas affecte
293
-			$p . chr(158) => "&#382;",
294
-			$p . chr(159) => "&#376;",
295
-		);
296
-		if ($charset_cible != 'unicode') {
297
-			foreach ($trans[$charset][$charset_cible] as $k => $c) {
298
-				$trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
299
-			}
300
-		}
301
-	}
302
-
303
-	return @str_replace(array_keys($trans[$charset][$charset_cible]),
304
-		array_values($trans[$charset][$charset_cible]), $texte);
239
+    static $trans;
240
+
241
+    if (is_array($texte)) {
242
+        return array_map('corriger_caracteres_windows', $texte);
243
+    }
244
+
245
+    if ($charset == 'AUTO') {
246
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
247
+    }
248
+    if ($charset == 'utf-8') {
249
+        $p = chr(194);
250
+        if (strpos($texte, $p) == false) {
251
+            return $texte;
252
+        }
253
+    } else {
254
+        if ($charset == 'iso-8859-1') {
255
+            $p = '';
256
+        } else {
257
+            return $texte;
258
+        }
259
+    }
260
+
261
+    if (!isset($trans[$charset][$charset_cible])) {
262
+        $trans[$charset][$charset_cible] = array(
263
+            $p . chr(128) => "&#8364;",
264
+            $p . chr(129) => ' ', # pas affecte
265
+            $p . chr(130) => "&#8218;",
266
+            $p . chr(131) => "&#402;",
267
+            $p . chr(132) => "&#8222;",
268
+            $p . chr(133) => "&#8230;",
269
+            $p . chr(134) => "&#8224;",
270
+            $p . chr(135) => "&#8225;",
271
+            $p . chr(136) => "&#710;",
272
+            $p . chr(137) => "&#8240;",
273
+            $p . chr(138) => "&#352;",
274
+            $p . chr(139) => "&#8249;",
275
+            $p . chr(140) => "&#338;",
276
+            $p . chr(141) => ' ', # pas affecte
277
+            $p . chr(142) => "&#381;",
278
+            $p . chr(143) => ' ', # pas affecte
279
+            $p . chr(144) => ' ', # pas affecte
280
+            $p . chr(145) => "&#8216;",
281
+            $p . chr(146) => "&#8217;",
282
+            $p . chr(147) => "&#8220;",
283
+            $p . chr(148) => "&#8221;",
284
+            $p . chr(149) => "&#8226;",
285
+            $p . chr(150) => "&#8211;",
286
+            $p . chr(151) => "&#8212;",
287
+            $p . chr(152) => "&#732;",
288
+            $p . chr(153) => "&#8482;",
289
+            $p . chr(154) => "&#353;",
290
+            $p . chr(155) => "&#8250;",
291
+            $p . chr(156) => "&#339;",
292
+            $p . chr(157) => ' ', # pas affecte
293
+            $p . chr(158) => "&#382;",
294
+            $p . chr(159) => "&#376;",
295
+        );
296
+        if ($charset_cible != 'unicode') {
297
+            foreach ($trans[$charset][$charset_cible] as $k => $c) {
298
+                $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
299
+            }
300
+        }
301
+    }
302
+
303
+    return @str_replace(array_keys($trans[$charset][$charset_cible]),
304
+        array_values($trans[$charset][$charset_cible]), $texte);
305 305
 }
306 306
 
307 307
 
@@ -318,24 +318,24 @@  discard block
 block discarded – undo
318 318
  *     Texte converti
319 319
  **/
320 320
 function html2unicode($texte, $secure = false) {
321
-	if (strpos($texte, '&') === false) {
322
-		return $texte;
323
-	}
324
-	static $trans = array();
325
-	if (!$trans) {
326
-		load_charset('html');
327
-		foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
328
-			$trans["&$key;"] = $val;
329
-		}
330
-	}
331
-
332
-	if ($secure) {
333
-		return str_replace(array_keys($trans), array_values($trans), $texte);
334
-	} else {
335
-		return str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'),
336
-			str_replace(array_keys($trans), array_values($trans), $texte)
337
-		);
338
-	}
321
+    if (strpos($texte, '&') === false) {
322
+        return $texte;
323
+    }
324
+    static $trans = array();
325
+    if (!$trans) {
326
+        load_charset('html');
327
+        foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
328
+            $trans["&$key;"] = $val;
329
+        }
330
+    }
331
+
332
+    if ($secure) {
333
+        return str_replace(array_keys($trans), array_values($trans), $texte);
334
+    } else {
335
+        return str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'),
336
+            str_replace(array_keys($trans), array_values($trans), $texte)
337
+        );
338
+    }
339 339
 }
340 340
 
341 341
 
@@ -350,16 +350,16 @@  discard block
 block discarded – undo
350 350
  *     Texte converti
351 351
  **/
352 352
 function mathml2unicode($texte) {
353
-	static $trans;
354
-	if (!$trans) {
355
-		load_charset('mathml');
353
+    static $trans;
354
+    if (!$trans) {
355
+        load_charset('mathml');
356 356
 
357
-		foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
358
-			$trans["&$key;"] = $val;
359
-		}
360
-	}
357
+        foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
358
+            $trans["&$key;"] = $val;
359
+        }
360
+    }
361 361
 
362
-	return str_replace(array_keys($trans), array_values($trans), $texte);
362
+    return str_replace(array_keys($trans), array_values($trans), $texte);
363 363
 }
364 364
 
365 365
 
@@ -381,76 +381,76 @@  discard block
 block discarded – undo
381 381
  *     Texte converti en unicode
382 382
  **/
383 383
 function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) {
384
-	static $trans;
385
-
386
-	if ($charset == 'AUTO') {
387
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
388
-	}
389
-
390
-	if ($charset == '') {
391
-		$charset = 'iso-8859-1';
392
-	}
393
-	$charset = strtolower($charset);
394
-
395
-	switch ($charset) {
396
-		case 'utf-8':
397
-		case 'utf8':
398
-			return utf_8_to_unicode($texte);
399
-
400
-		case 'iso-8859-1':
401
-			$texte = corriger_caracteres_windows($texte, 'iso-8859-1');
402
-		// pas de break; ici, on suit sur default:
403
-
404
-		default:
405
-			// mbstring presente ?
406
-			if (init_mb_string()) {
407
-				$order = mb_detect_order();
408
-				try {
409
-					# mb_string connait-il $charset?
410
-					if ($order and mb_detect_order($charset)) {
411
-						$s = mb_convert_encoding($texte, 'utf-8', $charset);
412
-						if ($s && $s != $texte) {
413
-							return utf_8_to_unicode($s);
414
-						}
415
-					}
384
+    static $trans;
385
+
386
+    if ($charset == 'AUTO') {
387
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
388
+    }
389
+
390
+    if ($charset == '') {
391
+        $charset = 'iso-8859-1';
392
+    }
393
+    $charset = strtolower($charset);
394
+
395
+    switch ($charset) {
396
+        case 'utf-8':
397
+        case 'utf8':
398
+            return utf_8_to_unicode($texte);
399
+
400
+        case 'iso-8859-1':
401
+            $texte = corriger_caracteres_windows($texte, 'iso-8859-1');
402
+        // pas de break; ici, on suit sur default:
403
+
404
+        default:
405
+            // mbstring presente ?
406
+            if (init_mb_string()) {
407
+                $order = mb_detect_order();
408
+                try {
409
+                    # mb_string connait-il $charset?
410
+                    if ($order and mb_detect_order($charset)) {
411
+                        $s = mb_convert_encoding($texte, 'utf-8', $charset);
412
+                        if ($s && $s != $texte) {
413
+                            return utf_8_to_unicode($s);
414
+                        }
415
+                    }
416 416
 					
417
-				} catch (\Error $e) {
418
-					// Le charset n'existe probablement pas
419
-				} finally {
420
-					mb_detect_order($order); # remettre comme precedemment
421
-				}
422
-			}
423
-
424
-			// Sinon, peut-etre connaissons-nous ce charset ?
425
-			if (!isset($trans[$charset])) {
426
-				if (
427
-					$cset = load_charset($charset)
428
-					and is_array($GLOBALS['CHARSET'][$cset])
429
-				) {
430
-					foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
431
-						$trans[$charset][chr($key)] = '&#' . $val . ';';
432
-					}
433
-				}
434
-			}
435
-			if (isset($trans[$charset]) and count($trans[$charset])) {
436
-				return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
437
-			}
438
-
439
-			// Sinon demander a iconv (malgre le fait qu'il coupe quand un
440
-			// caractere n'appartient pas au charset, mais c'est un probleme
441
-			// surtout en utf-8, gere ci-dessus)
442
-			if (test_iconv()) {
443
-				$s = iconv($charset, 'utf-32le', $texte);
444
-				if ($s) {
445
-					return utf_32_to_unicode($s);
446
-				}
447
-			}
448
-
449
-			// Au pire ne rien faire
450
-			spip_log("erreur charset '$charset' non supporte");
451
-
452
-			return $texte;
453
-	}
417
+                } catch (\Error $e) {
418
+                    // Le charset n'existe probablement pas
419
+                } finally {
420
+                    mb_detect_order($order); # remettre comme precedemment
421
+                }
422
+            }
423
+
424
+            // Sinon, peut-etre connaissons-nous ce charset ?
425
+            if (!isset($trans[$charset])) {
426
+                if (
427
+                    $cset = load_charset($charset)
428
+                    and is_array($GLOBALS['CHARSET'][$cset])
429
+                ) {
430
+                    foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
431
+                        $trans[$charset][chr($key)] = '&#' . $val . ';';
432
+                    }
433
+                }
434
+            }
435
+            if (isset($trans[$charset]) and count($trans[$charset])) {
436
+                return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
437
+            }
438
+
439
+            // Sinon demander a iconv (malgre le fait qu'il coupe quand un
440
+            // caractere n'appartient pas au charset, mais c'est un probleme
441
+            // surtout en utf-8, gere ci-dessus)
442
+            if (test_iconv()) {
443
+                $s = iconv($charset, 'utf-32le', $texte);
444
+                if ($s) {
445
+                    return utf_32_to_unicode($s);
446
+                }
447
+            }
448
+
449
+            // Au pire ne rien faire
450
+            spip_log("erreur charset '$charset' non supporte");
451
+
452
+            return $texte;
453
+    }
454 454
 }
455 455
 
456 456
 
@@ -469,44 +469,44 @@  discard block
 block discarded – undo
469 469
  *     Texte transformé dans le charset souhaité
470 470
  **/
471 471
 function unicode2charset($texte, $charset = 'AUTO') {
472
-	static $CHARSET_REVERSE = array();
473
-	static $trans = array();
474
-
475
-	if ($charset == 'AUTO') {
476
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
477
-	}
478
-
479
-	switch ($charset) {
480
-		case 'utf-8':
481
-			return unicode_to_utf_8($texte);
482
-			break;
483
-
484
-		default:
485
-			$charset = load_charset($charset);
486
-
487
-			if (empty($CHARSET_REVERSE[$charset])) {
488
-				$CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
489
-			}
490
-
491
-			if (!isset($trans[$charset])) {
492
-				$trans[$charset] = array();
493
-				$t = &$trans[$charset];
494
-				for ($e = 128; $e < 255; $e++) {
495
-					$h = dechex($e);
496
-					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
497
-						$s = $CHARSET_REVERSE[$charset][$e];
498
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
499
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
500
-					} else {
501
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
502
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
503
-					}
504
-				}
505
-			}
506
-			$texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
507
-
508
-			return $texte;
509
-	}
472
+    static $CHARSET_REVERSE = array();
473
+    static $trans = array();
474
+
475
+    if ($charset == 'AUTO') {
476
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
477
+    }
478
+
479
+    switch ($charset) {
480
+        case 'utf-8':
481
+            return unicode_to_utf_8($texte);
482
+            break;
483
+
484
+        default:
485
+            $charset = load_charset($charset);
486
+
487
+            if (empty($CHARSET_REVERSE[$charset])) {
488
+                $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
489
+            }
490
+
491
+            if (!isset($trans[$charset])) {
492
+                $trans[$charset] = array();
493
+                $t = &$trans[$charset];
494
+                for ($e = 128; $e < 255; $e++) {
495
+                    $h = dechex($e);
496
+                    if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
497
+                        $s = $CHARSET_REVERSE[$charset][$e];
498
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
499
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
500
+                    } else {
501
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
502
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
503
+                    }
504
+                }
505
+            }
506
+            $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
507
+
508
+            return $texte;
509
+    }
510 510
 }
511 511
 
512 512
 
@@ -524,37 +524,37 @@  discard block
 block discarded – undo
524 524
  *     Texte transformé dans le charset site
525 525
  **/
526 526
 function importer_charset($texte, $charset = 'AUTO') {
527
-	static $trans = array();
528
-	// on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
529
-	if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
530
-		$texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
531
-		if (init_mb_string()) {
532
-			if ($order = mb_detect_order() # mb_string connait-il $charset?
533
-				and mb_detect_order($charset)
534
-			) {
535
-				$s = mb_convert_encoding($texte, 'utf-8', $charset);
536
-			}
537
-			mb_detect_order($order); # remettre comme precedemment
538
-			return $s;
539
-		}
540
-		// Sinon, peut-etre connaissons-nous ce charset ?
541
-		if (!isset($trans[$charset])) {
542
-			if ($cset = load_charset($charset)
543
-				and is_array($GLOBALS['CHARSET'][$cset])
544
-			) {
545
-				foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
546
-					$trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
547
-				}
548
-			}
549
-		}
550
-		if (count($trans[$charset])) {
551
-			return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
552
-		}
553
-
554
-		return $texte;
555
-	}
556
-
557
-	return unicode2charset(charset2unicode($texte, $charset));
527
+    static $trans = array();
528
+    // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
529
+    if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
530
+        $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
531
+        if (init_mb_string()) {
532
+            if ($order = mb_detect_order() # mb_string connait-il $charset?
533
+                and mb_detect_order($charset)
534
+            ) {
535
+                $s = mb_convert_encoding($texte, 'utf-8', $charset);
536
+            }
537
+            mb_detect_order($order); # remettre comme precedemment
538
+            return $s;
539
+        }
540
+        // Sinon, peut-etre connaissons-nous ce charset ?
541
+        if (!isset($trans[$charset])) {
542
+            if ($cset = load_charset($charset)
543
+                and is_array($GLOBALS['CHARSET'][$cset])
544
+            ) {
545
+                foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
546
+                    $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
547
+                }
548
+            }
549
+        }
550
+        if (count($trans[$charset])) {
551
+            return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
552
+        }
553
+
554
+        return $texte;
555
+    }
556
+
557
+    return unicode2charset(charset2unicode($texte, $charset));
558 558
 }
559 559
 
560 560
 
@@ -570,92 +570,92 @@  discard block
 block discarded – undo
570 570
  **/
571 571
 function utf_8_to_unicode($source) {
572 572
 
573
-	// mb_string : methode rapide
574
-	if (init_mb_string()) {
575
-		$convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
576
-
577
-		return mb_encode_numericentity($source, $convmap, 'UTF-8');
578
-	}
579
-
580
-	// Sinon methode pas a pas
581
-	static $decrement;
582
-	static $shift;
583
-
584
-	// Cf. php.net, par Ronen. Adapte pour compatibilite < php4
585
-	if (!is_array($decrement)) {
586
-		// array used to figure what number to decrement from character order value
587
-		// according to number of characters used to map unicode to ascii by utf-8
588
-		$decrement[4] = 240;
589
-		$decrement[3] = 224;
590
-		$decrement[2] = 192;
591
-		$decrement[1] = 0;
592
-		// the number of bits to shift each charNum by
593
-		$shift[1][0] = 0;
594
-		$shift[2][0] = 6;
595
-		$shift[2][1] = 0;
596
-		$shift[3][0] = 12;
597
-		$shift[3][1] = 6;
598
-		$shift[3][2] = 0;
599
-		$shift[4][0] = 18;
600
-		$shift[4][1] = 12;
601
-		$shift[4][2] = 6;
602
-		$shift[4][3] = 0;
603
-	}
604
-
605
-	$pos = 0;
606
-	$len = strlen($source);
607
-	$encodedString = '';
608
-	while ($pos < $len) {
609
-		$char = '';
610
-		$ischar = false;
611
-		$asciiPos = ord(substr($source, $pos, 1));
612
-		if (($asciiPos >= 240) && ($asciiPos <= 255)) {
613
-			// 4 chars representing one unicode character
614
-			$thisLetter = substr($source, $pos, 4);
615
-			$pos += 4;
616
-		} else {
617
-			if (($asciiPos >= 224) && ($asciiPos <= 239)) {
618
-				// 3 chars representing one unicode character
619
-				$thisLetter = substr($source, $pos, 3);
620
-				$pos += 3;
621
-			} else {
622
-				if (($asciiPos >= 192) && ($asciiPos <= 223)) {
623
-					// 2 chars representing one unicode character
624
-					$thisLetter = substr($source, $pos, 2);
625
-					$pos += 2;
626
-				} else {
627
-					// 1 char (lower ascii)
628
-					$thisLetter = substr($source, $pos, 1);
629
-					$pos += 1;
630
-					$char = $thisLetter;
631
-					$ischar = true;
632
-				}
633
-			}
634
-		}
635
-
636
-		if ($ischar) {
637
-			$encodedString .= $char;
638
-		} else {  // process the string representing the letter to a unicode entity
639
-			$thisLen = strlen($thisLetter);
640
-			$thisPos = 0;
641
-			$decimalCode = 0;
642
-			while ($thisPos < $thisLen) {
643
-				$thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
644
-				if ($thisPos == 0) {
645
-					$charNum = intval($thisCharOrd - $decrement[$thisLen]);
646
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
647
-				} else {
648
-					$charNum = intval($thisCharOrd - 128);
649
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
650
-				}
651
-				$thisPos++;
652
-			}
653
-			$encodedLetter = "&#" . preg_replace('/^0+/', '', $decimalCode) . ';';
654
-			$encodedString .= $encodedLetter;
655
-		}
656
-	}
657
-
658
-	return $encodedString;
573
+    // mb_string : methode rapide
574
+    if (init_mb_string()) {
575
+        $convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
576
+
577
+        return mb_encode_numericentity($source, $convmap, 'UTF-8');
578
+    }
579
+
580
+    // Sinon methode pas a pas
581
+    static $decrement;
582
+    static $shift;
583
+
584
+    // Cf. php.net, par Ronen. Adapte pour compatibilite < php4
585
+    if (!is_array($decrement)) {
586
+        // array used to figure what number to decrement from character order value
587
+        // according to number of characters used to map unicode to ascii by utf-8
588
+        $decrement[4] = 240;
589
+        $decrement[3] = 224;
590
+        $decrement[2] = 192;
591
+        $decrement[1] = 0;
592
+        // the number of bits to shift each charNum by
593
+        $shift[1][0] = 0;
594
+        $shift[2][0] = 6;
595
+        $shift[2][1] = 0;
596
+        $shift[3][0] = 12;
597
+        $shift[3][1] = 6;
598
+        $shift[3][2] = 0;
599
+        $shift[4][0] = 18;
600
+        $shift[4][1] = 12;
601
+        $shift[4][2] = 6;
602
+        $shift[4][3] = 0;
603
+    }
604
+
605
+    $pos = 0;
606
+    $len = strlen($source);
607
+    $encodedString = '';
608
+    while ($pos < $len) {
609
+        $char = '';
610
+        $ischar = false;
611
+        $asciiPos = ord(substr($source, $pos, 1));
612
+        if (($asciiPos >= 240) && ($asciiPos <= 255)) {
613
+            // 4 chars representing one unicode character
614
+            $thisLetter = substr($source, $pos, 4);
615
+            $pos += 4;
616
+        } else {
617
+            if (($asciiPos >= 224) && ($asciiPos <= 239)) {
618
+                // 3 chars representing one unicode character
619
+                $thisLetter = substr($source, $pos, 3);
620
+                $pos += 3;
621
+            } else {
622
+                if (($asciiPos >= 192) && ($asciiPos <= 223)) {
623
+                    // 2 chars representing one unicode character
624
+                    $thisLetter = substr($source, $pos, 2);
625
+                    $pos += 2;
626
+                } else {
627
+                    // 1 char (lower ascii)
628
+                    $thisLetter = substr($source, $pos, 1);
629
+                    $pos += 1;
630
+                    $char = $thisLetter;
631
+                    $ischar = true;
632
+                }
633
+            }
634
+        }
635
+
636
+        if ($ischar) {
637
+            $encodedString .= $char;
638
+        } else {  // process the string representing the letter to a unicode entity
639
+            $thisLen = strlen($thisLetter);
640
+            $thisPos = 0;
641
+            $decimalCode = 0;
642
+            while ($thisPos < $thisLen) {
643
+                $thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
644
+                if ($thisPos == 0) {
645
+                    $charNum = intval($thisCharOrd - $decrement[$thisLen]);
646
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
647
+                } else {
648
+                    $charNum = intval($thisCharOrd - 128);
649
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
650
+                }
651
+                $thisPos++;
652
+            }
653
+            $encodedLetter = "&#" . preg_replace('/^0+/', '', $decimalCode) . ';';
654
+            $encodedString .= $encodedLetter;
655
+        }
656
+    }
657
+
658
+    return $encodedString;
659 659
 }
660 660
 
661 661
 /**
@@ -674,32 +674,32 @@  discard block
 block discarded – undo
674 674
  **/
675 675
 function utf_32_to_unicode($source) {
676 676
 
677
-	// mb_string : methode rapide
678
-	if (init_mb_string()) {
679
-		$convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
680
-		$source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
681
-
682
-		return str_replace(chr(0), '', $source);
683
-	}
684
-
685
-	// Sinon methode lente
686
-	$texte = '';
687
-	while ($source) {
688
-		$words = unpack("V*", substr($source, 0, 1024));
689
-		$source = substr($source, 1024);
690
-		foreach ($words as $word) {
691
-			if ($word < 128) {
692
-				$texte .= chr($word);
693
-			} // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
694
-			else {
695
-				if ($word != 65279) {
696
-					$texte .= '&#' . $word . ';';
697
-				}
698
-			}
699
-		}
700
-	}
701
-
702
-	return $texte;
677
+    // mb_string : methode rapide
678
+    if (init_mb_string()) {
679
+        $convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
680
+        $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
681
+
682
+        return str_replace(chr(0), '', $source);
683
+    }
684
+
685
+    // Sinon methode lente
686
+    $texte = '';
687
+    while ($source) {
688
+        $words = unpack("V*", substr($source, 0, 1024));
689
+        $source = substr($source, 1024);
690
+        foreach ($words as $word) {
691
+            if ($word < 128) {
692
+                $texte .= chr($word);
693
+            } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
694
+            else {
695
+                if ($word != 65279) {
696
+                    $texte .= '&#' . $word . ';';
697
+                }
698
+            }
699
+        }
700
+    }
701
+
702
+    return $texte;
703 703
 
704 704
 }
705 705
 
@@ -717,21 +717,21 @@  discard block
 block discarded – undo
717 717
  *    Caractère utf8 si trouvé, '' sinon
718 718
  **/
719 719
 function caractere_utf_8($num) {
720
-	$num = intval($num);
721
-	if ($num < 128) {
722
-		return chr($num);
723
-	}
724
-	if ($num < 2048) {
725
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
726
-	}
727
-	if ($num < 65536) {
728
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
729
-	}
730
-	if ($num < 1114112) {
731
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
732
-	}
733
-
734
-	return '';
720
+    $num = intval($num);
721
+    if ($num < 128) {
722
+        return chr($num);
723
+    }
724
+    if ($num < 2048) {
725
+        return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
726
+    }
727
+    if ($num < 65536) {
728
+        return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
729
+    }
730
+    if ($num < 1114112) {
731
+        return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
732
+    }
733
+
734
+    return '';
735 735
 }
736 736
 
737 737
 /**
@@ -744,30 +744,30 @@  discard block
 block discarded – undo
744 744
  **/
745 745
 function unicode_to_utf_8($texte) {
746 746
 
747
-	// 1. Entites &#128; et suivantes
748
-	$vu = array();
749
-	if (preg_match_all(',&#0*([1-9][0-9][0-9]+);,S',
750
-		$texte, $regs, PREG_SET_ORDER)) {
751
-		foreach ($regs as $reg) {
752
-			if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
753
-				$vu[$reg[0]] = caractere_utf_8($reg[1]);
754
-			}
755
-		}
756
-	}
757
-	//$texte = str_replace(array_keys($vu), array_values($vu), $texte);
758
-
759
-	// 2. Entites > &#xFF;
760
-	//$vu = array();
761
-	if (preg_match_all(',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
762
-		$texte, $regs, PREG_SET_ORDER)) {
763
-		foreach ($regs as $reg) {
764
-			if (!isset($vu[$reg[0]])) {
765
-				$vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
766
-			}
767
-		}
768
-	}
769
-
770
-	return str_replace(array_keys($vu), array_values($vu), $texte);
747
+    // 1. Entites &#128; et suivantes
748
+    $vu = array();
749
+    if (preg_match_all(',&#0*([1-9][0-9][0-9]+);,S',
750
+        $texte, $regs, PREG_SET_ORDER)) {
751
+        foreach ($regs as $reg) {
752
+            if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
753
+                $vu[$reg[0]] = caractere_utf_8($reg[1]);
754
+            }
755
+        }
756
+    }
757
+    //$texte = str_replace(array_keys($vu), array_values($vu), $texte);
758
+
759
+    // 2. Entites > &#xFF;
760
+    //$vu = array();
761
+    if (preg_match_all(',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
762
+        $texte, $regs, PREG_SET_ORDER)) {
763
+        foreach ($regs as $reg) {
764
+            if (!isset($vu[$reg[0]])) {
765
+                $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
766
+            }
767
+        }
768
+    }
769
+
770
+    return str_replace(array_keys($vu), array_values($vu), $texte);
771 771
 
772 772
 }
773 773
 
@@ -780,15 +780,15 @@  discard block
 block discarded – undo
780 780
  *     Texte converti
781 781
  **/
782 782
 function unicode_to_javascript($texte) {
783
-	$vu = array();
784
-	while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
785
-		$num = $regs[1];
786
-		$vu[$num] = true;
787
-		$s = '\u' . sprintf("%04x", $num);
788
-		$texte = str_replace($regs[0], $s, $texte);
789
-	}
790
-
791
-	return $texte;
783
+    $vu = array();
784
+    while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
785
+        $num = $regs[1];
786
+        $vu[$num] = true;
787
+        $s = '\u' . sprintf("%04x", $num);
788
+        $texte = str_replace($regs[0], $s, $texte);
789
+    }
790
+
791
+    return $texte;
792 792
 }
793 793
 
794 794
 /**
@@ -800,11 +800,11 @@  discard block
 block discarded – undo
800 800
  *     Texte converti
801 801
  **/
802 802
 function javascript_to_unicode($texte) {
803
-	while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs)) {
804
-		$texte = str_replace($regs[0], "&#" . hexdec($regs[1]) . ";", $texte);
805
-	}
803
+    while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs)) {
804
+        $texte = str_replace($regs[0], "&#" . hexdec($regs[1]) . ";", $texte);
805
+    }
806 806
 
807
-	return $texte;
807
+    return $texte;
808 808
 }
809 809
 
810 810
 /**
@@ -816,11 +816,11 @@  discard block
 block discarded – undo
816 816
  *     Texte converti
817 817
  **/
818 818
 function javascript_to_binary($texte) {
819
-	while (preg_match(",%([0-9A-F][0-9A-F]),", $texte, $regs)) {
820
-		$texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
821
-	}
819
+    while (preg_match(",%([0-9A-F][0-9A-F]),", $texte, $regs)) {
820
+        $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
821
+    }
822 822
 
823
-	return $texte;
823
+    return $texte;
824 824
 }
825 825
 
826 826
 
@@ -838,26 +838,26 @@  discard block
 block discarded – undo
838 838
  * @return string
839 839
  */
840 840
 function translitteration_rapide($texte, $charset = 'AUTO', $complexe = '') {
841
-	static $trans = [];
842
-	if ($charset == 'AUTO') {
843
-		$charset = $GLOBALS['meta']['charset'];
844
-	}
845
-	if (!strlen($texte)) {
846
-		return $texte;
847
-	}
848
-
849
-	$table_translit = 'translit' . $complexe;
850
-
851
-	// 2. Translitterer grace a la table predefinie
852
-	if (!isset($trans[$complexe])) {
853
-		$trans[$complexe] = [];
854
-		load_charset($table_translit);
855
-		foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
856
-			$trans[$complexe][caractere_utf_8($key)] = $val;
857
-		}
858
-	}
859
-
860
-	return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
841
+    static $trans = [];
842
+    if ($charset == 'AUTO') {
843
+        $charset = $GLOBALS['meta']['charset'];
844
+    }
845
+    if (!strlen($texte)) {
846
+        return $texte;
847
+    }
848
+
849
+    $table_translit = 'translit' . $complexe;
850
+
851
+    // 2. Translitterer grace a la table predefinie
852
+    if (!isset($trans[$complexe])) {
853
+        $trans[$complexe] = [];
854
+        load_charset($table_translit);
855
+        foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
856
+            $trans[$complexe][caractere_utf_8($key)] = $val;
857
+        }
858
+    }
859
+
860
+    return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
861 861
 }
862 862
 
863 863
 /**
@@ -880,14 +880,14 @@  discard block
 block discarded – undo
880 880
  * @return string
881 881
  */
882 882
 function translitteration($texte, $charset = 'AUTO', $complexe = '') {
883
-	// 0. Supprimer les caracteres illegaux
884
-	include_spip('inc/filtres');
885
-	$texte = corriger_caracteres($texte);
883
+    // 0. Supprimer les caracteres illegaux
884
+    include_spip('inc/filtres');
885
+    $texte = corriger_caracteres($texte);
886 886
 
887
-	// 1. Passer le charset et les &eacute en utf-8
888
-	$texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
887
+    // 1. Passer le charset et les &eacute en utf-8
888
+    $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
889 889
 
890
-	return translitteration_rapide($texte, $charset, $complexe);
890
+    return translitteration_rapide($texte, $charset, $complexe);
891 891
 }
892 892
 
893 893
 /**
@@ -902,17 +902,17 @@  discard block
 block discarded – undo
902 902
  * @return string
903 903
  */
904 904
 function translitteration_complexe($texte, $chiffres = false) {
905
-	$texte = translitteration($texte, 'AUTO', 'complexe');
905
+    $texte = translitteration($texte, 'AUTO', 'complexe');
906 906
 
907
-	if ($chiffres) {
908
-		$texte = preg_replace_callback(
909
-			"/[aeiuoyd]['`?~.^+(-]{1,2}/S",
910
-			function($m) { return translitteration_chiffree($m[0]); },
911
-			$texte
912
-		);
913
-	}
907
+    if ($chiffres) {
908
+        $texte = preg_replace_callback(
909
+            "/[aeiuoyd]['`?~.^+(-]{1,2}/S",
910
+            function($m) { return translitteration_chiffree($m[0]); },
911
+            $texte
912
+        );
913
+    }
914 914
 
915
-	return $texte;
915
+    return $texte;
916 916
 }
917 917
 
918 918
 /**
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
  * @return string
925 925
  */
926 926
 function translitteration_chiffree($car) {
927
-	return strtr($car, "'`?~.^+(-", "123456789");
927
+    return strtr($car, "'`?~.^+(-", "123456789");
928 928
 }
929 929
 
930 930
 
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
  *    true s'il a un BOM
938 938
  **/
939 939
 function bom_utf8($texte) {
940
-	return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
940
+    return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
941 941
 }
942 942
 
943 943
 /**
@@ -954,18 +954,18 @@  discard block
 block discarded – undo
954 954
  *     true si c'est le cas
955 955
  **/
956 956
 function is_utf8($string) {
957
-	return !strlen(
958
-		preg_replace(
959
-			',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
960
-			. '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
961
-			. '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
962
-			. '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
963
-			. '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
964
-			. '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
965
-			. '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
966
-			. '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
967
-			. ',sS',
968
-			'', $string));
957
+    return !strlen(
958
+        preg_replace(
959
+            ',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
960
+            . '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
961
+            . '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
962
+            . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
963
+            . '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
964
+            . '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
965
+            . '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
966
+            . '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
967
+            . ',sS',
968
+            '', $string));
969 969
 }
970 970
 
971 971
 /**
@@ -977,10 +977,10 @@  discard block
 block discarded – undo
977 977
  *     true si c'est le cas
978 978
  **/
979 979
 function is_ascii($string) {
980
-	return !strlen(
981
-		preg_replace(
982
-			',[\x09\x0A\x0D\x20-\x7E],sS',
983
-			'', $string));
980
+    return !strlen(
981
+        preg_replace(
982
+            ',[\x09\x0A\x0D\x20-\x7E],sS',
983
+            '', $string));
984 984
 }
985 985
 
986 986
 /**
@@ -999,53 +999,53 @@  discard block
 block discarded – undo
999 999
  **/
1000 1000
 function transcoder_page($texte, $headers = '') {
1001 1001
 
1002
-	// Si tout est < 128 pas la peine d'aller plus loin
1003
-	if (is_ascii($texte)) {
1004
-		#spip_log('charset: ascii');
1005
-		return $texte;
1006
-	}
1007
-
1008
-	if (bom_utf8($texte)) {
1009
-		// Reconnaitre le BOM utf-8 (0xEFBBBF)
1010
-		$charset = 'utf-8';
1011
-		$texte = substr($texte, 3);
1012
-	} elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
1013
-		// charset precise par le contenu (xml)
1014
-		$charset = trim(strtolower($regs[1]));
1015
-	} elseif (
1016
-		// charset precise par le contenu (html)
1017
-		preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs)
1018
-		# eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette
1019
-		and false === strpos($regs[2], '#')
1020
-		and $tmp = trim(strtolower($regs[2]))
1021
-	) {
1022
-		$charset = $tmp;
1023
-	} elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
1024
-		// charset de la reponse http
1025
-		$charset = trim(strtolower($regs[1]));
1026
-	} else {
1027
-		$charset = '';
1028
-	}
1029
-
1030
-
1031
-	// normaliser les noms du shif-jis japonais
1032
-	if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
1033
-		$charset = 'shift-jis';
1034
-	}
1035
-
1036
-	if ($charset) {
1037
-		spip_log("charset: $charset");
1038
-	} else {
1039
-		// valeur par defaut
1040
-		if (is_utf8($texte)) {
1041
-			$charset = 'utf-8';
1042
-		} else {
1043
-			$charset = 'iso-8859-1';
1044
-		}
1045
-		spip_log("charset probable: $charset");
1046
-	}
1047
-
1048
-	return importer_charset($texte, $charset);
1002
+    // Si tout est < 128 pas la peine d'aller plus loin
1003
+    if (is_ascii($texte)) {
1004
+        #spip_log('charset: ascii');
1005
+        return $texte;
1006
+    }
1007
+
1008
+    if (bom_utf8($texte)) {
1009
+        // Reconnaitre le BOM utf-8 (0xEFBBBF)
1010
+        $charset = 'utf-8';
1011
+        $texte = substr($texte, 3);
1012
+    } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
1013
+        // charset precise par le contenu (xml)
1014
+        $charset = trim(strtolower($regs[1]));
1015
+    } elseif (
1016
+        // charset precise par le contenu (html)
1017
+        preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs)
1018
+        # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette
1019
+        and false === strpos($regs[2], '#')
1020
+        and $tmp = trim(strtolower($regs[2]))
1021
+    ) {
1022
+        $charset = $tmp;
1023
+    } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
1024
+        // charset de la reponse http
1025
+        $charset = trim(strtolower($regs[1]));
1026
+    } else {
1027
+        $charset = '';
1028
+    }
1029
+
1030
+
1031
+    // normaliser les noms du shif-jis japonais
1032
+    if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
1033
+        $charset = 'shift-jis';
1034
+    }
1035
+
1036
+    if ($charset) {
1037
+        spip_log("charset: $charset");
1038
+    } else {
1039
+        // valeur par defaut
1040
+        if (is_utf8($texte)) {
1041
+            $charset = 'utf-8';
1042
+        } else {
1043
+            $charset = 'iso-8859-1';
1044
+        }
1045
+        spip_log("charset probable: $charset");
1046
+    }
1047
+
1048
+    return importer_charset($texte, $charset);
1049 1049
 }
1050 1050
 
1051 1051
 
@@ -1069,26 +1069,26 @@  discard block
 block discarded – undo
1069 1069
  *     Le texte coupé
1070 1070
  **/
1071 1071
 function spip_substr($c, $start = 0, $length = null) {
1072
-	// Si ce n'est pas utf-8, utiliser substr
1073
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1074
-		if ($length) {
1075
-			return substr($c, $start, $length);
1076
-		} else {
1077
-			substr($c, $start);
1078
-		}
1079
-	}
1080
-
1081
-	// Si utf-8, voir si on dispose de mb_string
1082
-	if (init_mb_string()) {
1083
-		if ($length) {
1084
-			return mb_substr($c, $start, $length);
1085
-		} else {
1086
-			return mb_substr($c, $start);
1087
-		}
1088
-	}
1089
-
1090
-	// Version manuelle (cf. ci-dessous)
1091
-	return spip_substr_manuelle($c, $start, $length);
1072
+    // Si ce n'est pas utf-8, utiliser substr
1073
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
1074
+        if ($length) {
1075
+            return substr($c, $start, $length);
1076
+        } else {
1077
+            substr($c, $start);
1078
+        }
1079
+    }
1080
+
1081
+    // Si utf-8, voir si on dispose de mb_string
1082
+    if (init_mb_string()) {
1083
+        if ($length) {
1084
+            return mb_substr($c, $start, $length);
1085
+        } else {
1086
+            return mb_substr($c, $start);
1087
+        }
1088
+    }
1089
+
1090
+    // Version manuelle (cf. ci-dessous)
1091
+    return spip_substr_manuelle($c, $start, $length);
1092 1092
 }
1093 1093
 
1094 1094
 
@@ -1107,40 +1107,40 @@  discard block
 block discarded – undo
1107 1107
  **/
1108 1108
 function spip_substr_manuelle($c, $start, $length = null) {
1109 1109
 
1110
-	// Cas pathologique
1111
-	if ($length === 0) {
1112
-		return '';
1113
-	}
1114
-
1115
-	// S'il y a un demarrage, on se positionne
1116
-	if ($start > 0) {
1117
-		$c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1118
-	} elseif ($start < 0) {
1119
-		return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
1120
-	}
1121
-
1122
-	if (!$length) {
1123
-		return $c;
1124
-	}
1125
-
1126
-	if ($length > 0) {
1127
-		// on prend n fois la longueur desiree, pour etre surs d'avoir tout
1128
-		// (un caractere utf-8 prenant au maximum n bytes)
1129
-		$n = 0;
1130
-		while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1131
-			;
1132
-		}
1133
-		$c = substr($c, 0, $n * $length);
1134
-		// puis, tant qu'on est trop long, on coupe...
1135
-		while (($l = spip_strlen($c)) > $length) {
1136
-			$c = substr($c, 0, $length - $l);
1137
-		}
1138
-
1139
-		return $c;
1140
-	}
1141
-
1142
-	// $length < 0
1143
-	return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
1110
+    // Cas pathologique
1111
+    if ($length === 0) {
1112
+        return '';
1113
+    }
1114
+
1115
+    // S'il y a un demarrage, on se positionne
1116
+    if ($start > 0) {
1117
+        $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1118
+    } elseif ($start < 0) {
1119
+        return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
1120
+    }
1121
+
1122
+    if (!$length) {
1123
+        return $c;
1124
+    }
1125
+
1126
+    if ($length > 0) {
1127
+        // on prend n fois la longueur desiree, pour etre surs d'avoir tout
1128
+        // (un caractere utf-8 prenant au maximum n bytes)
1129
+        $n = 0;
1130
+        while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1131
+            ;
1132
+        }
1133
+        $c = substr($c, 0, $n * $length);
1134
+        // puis, tant qu'on est trop long, on coupe...
1135
+        while (($l = spip_strlen($c)) > $length) {
1136
+            $c = substr($c, 0, $length - $l);
1137
+        }
1138
+
1139
+        return $c;
1140
+    }
1141
+
1142
+    // $length < 0
1143
+    return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
1144 1144
 }
1145 1145
 
1146 1146
 /**
@@ -1154,14 +1154,14 @@  discard block
 block discarded – undo
1154 1154
  *     La chaîne avec une majuscule sur le premier mot
1155 1155
  */
1156 1156
 function spip_ucfirst($c) {
1157
-	// Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst
1158
-	if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1159
-		return ucfirst($c);
1160
-	}
1157
+    // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst
1158
+    if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1159
+        return ucfirst($c);
1160
+    }
1161 1161
 
1162
-	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1162
+    $lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1163 1163
 
1164
-	return $lettre1 . spip_substr($c, 1);
1164
+    return $lettre1 . spip_substr($c, 1);
1165 1165
 }
1166 1166
 
1167 1167
 /**
@@ -1175,12 +1175,12 @@  discard block
 block discarded – undo
1175 1175
  *     La chaîne en minuscules
1176 1176
  */
1177 1177
 function spip_strtolower($c) {
1178
-	// Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower 
1179
-	if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1180
-		return strtolower($c);
1181
-	}
1178
+    // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower 
1179
+    if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1180
+        return strtolower($c);
1181
+    }
1182 1182
 
1183
-	return mb_strtolower($c);
1183
+    return mb_strtolower($c);
1184 1184
 }
1185 1185
 
1186 1186
 /**
@@ -1194,23 +1194,23 @@  discard block
 block discarded – undo
1194 1194
  *     Longueur de la chaîne
1195 1195
  */
1196 1196
 function spip_strlen($c) {
1197
-	// On transforme les sauts de ligne pour ne pas compter deux caractères
1198
-	$c = str_replace("\r\n", "\n", $c);
1199
-
1200
-	// Si ce n'est pas utf-8, utiliser strlen
1201
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1202
-		return strlen($c);
1203
-	}
1204
-
1205
-	// Sinon, utiliser mb_strlen() si disponible
1206
-	if (init_mb_string()) {
1207
-		return mb_strlen($c);
1208
-	}
1209
-
1210
-	// Methode manuelle : on supprime les bytes 10......,
1211
-	// on compte donc les ascii (0.......) et les demarrages
1212
-	// de caracteres utf-8 (11......)
1213
-	return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1197
+    // On transforme les sauts de ligne pour ne pas compter deux caractères
1198
+    $c = str_replace("\r\n", "\n", $c);
1199
+
1200
+    // Si ce n'est pas utf-8, utiliser strlen
1201
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
1202
+        return strlen($c);
1203
+    }
1204
+
1205
+    // Sinon, utiliser mb_strlen() si disponible
1206
+    if (init_mb_string()) {
1207
+        return mb_strlen($c);
1208
+    }
1209
+
1210
+    // Methode manuelle : on supprime les bytes 10......,
1211
+    // on compte donc les ascii (0.......) et les demarrages
1212
+    // de caracteres utf-8 (11......)
1213
+    return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1214 1214
 }
1215 1215
 
1216 1216
 // Initialisation
@@ -1220,14 +1220,14 @@  discard block
 block discarded – undo
1220 1220
 // dans les preg_replace pour ne pas casser certaines lettres accentuees :
1221 1221
 // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp
1222 1222
 if (!isset($GLOBALS['meta']['pcre_u'])
1223
-	or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
1223
+    or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
1224 1224
 ) {
1225
-	include_spip('inc/meta');
1226
-	ecrire_meta('pcre_u',
1227
-		$u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8'
1228
-			and test_pcre_unicode())
1229
-			? 'u' : ''
1230
-	);
1225
+    include_spip('inc/meta');
1226
+    ecrire_meta('pcre_u',
1227
+        $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8'
1228
+            and test_pcre_unicode())
1229
+            ? 'u' : ''
1230
+    );
1231 1231
 }
1232 1232
 
1233 1233
 
@@ -1243,17 +1243,17 @@  discard block
 block discarded – undo
1243 1243
  *     en unicode : &#128169;
1244 1244
  */
1245 1245
 function utf8_noplanes($x) {
1246
-	$regexp_utf8_4bytes = '/(
1246
+    $regexp_utf8_4bytes = '/(
1247 1247
       \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
1248 1248
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
1249 1249
    |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
1250 1250
 )/xS';
1251
-	if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1252
-		foreach ($z[0] as $k) {
1253
-			$ku = utf_8_to_unicode($k);
1254
-			$x = str_replace($k, $ku, $x);
1255
-		}
1256
-	}
1257
-
1258
-	return $x;
1251
+    if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1252
+        foreach ($z[0] as $k) {
1253
+            $ku = utf_8_to_unicode($k);
1254
+            $x = str_replace($k, $ku, $x);
1255
+        }
1256
+    }
1257
+
1258
+    return $x;
1259 1259
 }
Please login to merge, or discard this patch.
ecrire/inc/cvt_autosave.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
 /**
24 24
  * Nettoyer les échappements
25 25
  *
26
- * @param $val
26
+ * @param string $val
27 27
  * @return string
28 28
  */
29 29
 function autosave_clean_value($val) {
Please login to merge, or discard this patch.
Indentation   +57 added lines, -57 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
 /**
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
  * @return string
28 28
  */
29 29
 function autosave_clean_value($val) {
30
-	return stripslashes(urldecode($val));
30
+    return stripslashes(urldecode($val));
31 31
 }
32 32
 
33 33
 /**
@@ -38,42 +38,42 @@  discard block
 block discarded – undo
38 38
  * @return array
39 39
  */
40 40
 function cvtautosave_formulaire_charger($flux) {
41
-	if (is_array($flux['data'])
42
-		and isset($flux['data']['_autosave_id'])
43
-		and $cle_autosave = $flux['data']['_autosave_id']
44
-	) {
41
+    if (is_array($flux['data'])
42
+        and isset($flux['data']['_autosave_id'])
43
+        and $cle_autosave = $flux['data']['_autosave_id']
44
+    ) {
45 45
 
46
-		$form = $flux['args']['form'];
47
-		$je_suis_poste = $flux['args']['je_suis_poste'];
46
+        $form = $flux['args']['form'];
47
+        $je_suis_poste = $flux['args']['je_suis_poste'];
48 48
 
49
-		$cle_autosave = serialize($cle_autosave);
50
-		$cle_autosave = $form . "_" . md5($cle_autosave);
49
+        $cle_autosave = serialize($cle_autosave);
50
+        $cle_autosave = $form . "_" . md5($cle_autosave);
51 51
 
52
-		// si on a un backup en session et qu'on est au premier chargement, non poste
53
-		// on restitue les donnees
54
-		if (isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave])
55
-			and !$je_suis_poste
56
-		) {
57
-			parse_str($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave], $vars);
58
-			foreach ($vars as $key => $val) {
59
-				if (isset($flux['data'][$key])) {
60
-					$flux['data'][$key] = (is_string($val) ? autosave_clean_value($val) : array_map('autosave_clean_value',
61
-						$val));
62
-				}
63
-			}
64
-		}
52
+        // si on a un backup en session et qu'on est au premier chargement, non poste
53
+        // on restitue les donnees
54
+        if (isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave])
55
+            and !$je_suis_poste
56
+        ) {
57
+            parse_str($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave], $vars);
58
+            foreach ($vars as $key => $val) {
59
+                if (isset($flux['data'][$key])) {
60
+                    $flux['data'][$key] = (is_string($val) ? autosave_clean_value($val) : array_map('autosave_clean_value',
61
+                        $val));
62
+                }
63
+            }
64
+        }
65 65
 
66
-		/**
67
-		 * Envoyer le input hidden et le bout de js qui l'utilisera
68
-		 */
69
-		$flux['data']['_hidden'] .= "<input type='hidden' name='autosave' class='autosaveactive' value='$cle_autosave' />"
70
-			. '<script type="text/javascript">/*<![CDATA[*/if (window.jQuery) jQuery(function(){
66
+        /**
67
+         * Envoyer le input hidden et le bout de js qui l'utilisera
68
+         */
69
+        $flux['data']['_hidden'] .= "<input type='hidden' name='autosave' class='autosaveactive' value='$cle_autosave' />"
70
+            . '<script type="text/javascript">/*<![CDATA[*/if (window.jQuery) jQuery(function(){
71 71
 		  $("input.autosaveactive").closest("form:not(.autosaveon)").autosave({url:"' . $GLOBALS['meta']['adresse_site'] . '/"}).addClass("autosaveon");
72 72
 			});/*]]>*/</script>';
73 73
 
74
-	}
74
+    }
75 75
 
76
-	return $flux;
76
+    return $flux;
77 77
 }
78 78
 
79 79
 /**
@@ -87,33 +87,33 @@  discard block
 block discarded – undo
87 87
  * @return array
88 88
  */
89 89
 function cvtautosave_formulaire_traiter($flux) {
90
-	// si on poste 'autosave' c'est qu'on n'a plus besoin de sauvegarder :
91
-	// on elimine les donnees de la session
92
-	if ($cle_autosave = _request('autosave')) {
93
-		include_spip('inc/session');
94
-		session_set('session_autosave_' . $cle_autosave, null);
95
-	}
90
+    // si on poste 'autosave' c'est qu'on n'a plus besoin de sauvegarder :
91
+    // on elimine les donnees de la session
92
+    if ($cle_autosave = _request('autosave')) {
93
+        include_spip('inc/session');
94
+        session_set('session_autosave_' . $cle_autosave, null);
95
+    }
96 96
 
97
-	if (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']) {
98
-		// delai par defaut avant purge d'un backup de form : 72H
99
-		if (!defined('_AUTOSAVE_GB_DELAY')) {
100
-			define('_AUTOSAVE_GB_DELAY', 72 * 3600);
101
-		}
102
-		$time_too_old = time() - _AUTOSAVE_GB_DELAY;
103
-		// purger aussi toutes les vieilles autosave
104
-		$session = $GLOBALS['visiteur_session'];
105
-		foreach ($session as $k => $v) {
106
-			if (strncmp($k, 'session_autosave_', 17) == 0) {
107
-				$timestamp = 0;
108
-				if (preg_match(",&__timestamp=(\d+)$,", $v, $m)) {
109
-					$timestamp = intval($m[1]);
110
-				}
111
-				if ($timestamp < $time_too_old) {
112
-					session_set($k, null);
113
-				}
114
-			}
115
-		}
116
-	}
97
+    if (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']) {
98
+        // delai par defaut avant purge d'un backup de form : 72H
99
+        if (!defined('_AUTOSAVE_GB_DELAY')) {
100
+            define('_AUTOSAVE_GB_DELAY', 72 * 3600);
101
+        }
102
+        $time_too_old = time() - _AUTOSAVE_GB_DELAY;
103
+        // purger aussi toutes les vieilles autosave
104
+        $session = $GLOBALS['visiteur_session'];
105
+        foreach ($session as $k => $v) {
106
+            if (strncmp($k, 'session_autosave_', 17) == 0) {
107
+                $timestamp = 0;
108
+                if (preg_match(",&__timestamp=(\d+)$,", $v, $m)) {
109
+                    $timestamp = intval($m[1]);
110
+                }
111
+                if ($timestamp < $time_too_old) {
112
+                    session_set($k, null);
113
+                }
114
+            }
115
+        }
116
+    }
117 117
 
118
-	return $flux;
118
+    return $flux;
119 119
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -47,14 +47,14 @@  discard block
 block discarded – undo
47 47
 		$je_suis_poste = $flux['args']['je_suis_poste'];
48 48
 
49 49
 		$cle_autosave = serialize($cle_autosave);
50
-		$cle_autosave = $form . "_" . md5($cle_autosave);
50
+		$cle_autosave = $form."_".md5($cle_autosave);
51 51
 
52 52
 		// si on a un backup en session et qu'on est au premier chargement, non poste
53 53
 		// on restitue les donnees
54
-		if (isset($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave])
54
+		if (isset($GLOBALS['visiteur_session']['session_autosave_'.$cle_autosave])
55 55
 			and !$je_suis_poste
56 56
 		) {
57
-			parse_str($GLOBALS['visiteur_session']['session_autosave_' . $cle_autosave], $vars);
57
+			parse_str($GLOBALS['visiteur_session']['session_autosave_'.$cle_autosave], $vars);
58 58
 			foreach ($vars as $key => $val) {
59 59
 				if (isset($flux['data'][$key])) {
60 60
 					$flux['data'][$key] = (is_string($val) ? autosave_clean_value($val) : array_map('autosave_clean_value',
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		 */
69 69
 		$flux['data']['_hidden'] .= "<input type='hidden' name='autosave' class='autosaveactive' value='$cle_autosave' />"
70 70
 			. '<script type="text/javascript">/*<![CDATA[*/if (window.jQuery) jQuery(function(){
71
-		  $("input.autosaveactive").closest("form:not(.autosaveon)").autosave({url:"' . $GLOBALS['meta']['adresse_site'] . '/"}).addClass("autosaveon");
71
+		  $("input.autosaveactive").closest("form:not(.autosaveon)").autosave({url:"' . $GLOBALS['meta']['adresse_site'].'/"}).addClass("autosaveon");
72 72
 			});/*]]>*/</script>';
73 73
 
74 74
 	}
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	// on elimine les donnees de la session
92 92
 	if ($cle_autosave = _request('autosave')) {
93 93
 		include_spip('inc/session');
94
-		session_set('session_autosave_' . $cle_autosave, null);
94
+		session_set('session_autosave_'.$cle_autosave, null);
95 95
 	}
96 96
 
97 97
 	if (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']) {
Please login to merge, or discard this patch.
ecrire/inc/distant.php 4 patches
Doc Comments   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
  *   permet de specifier le nom du fichier local (stockage d'un cache par exemple, et non document IMG)
65 65
  * @param int $taille_max
66 66
  *   taille maxi de la copie local, par defaut _COPIE_LOCALE_MAX_SIZE
67
- * @return bool|string
67
+ * @return string|false
68 68
  */
69 69
 function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null) {
70 70
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
  * La fonction PHP idn_to_ascii depend d'un package php5-intl et est rarement disponible
247 247
  *
248 248
  * @param string $url_idn
249
- * @return array|string
249
+ * @return string|boolean
250 250
  */
251 251
 function url_to_ascii($url_idn) {
252 252
 
@@ -642,13 +642,13 @@  discard block
 block discarded – undo
642 642
  *
643 643
  * @param string $url
644 644
  *     URL de la page à récupérer
645
- * @param bool|null|string $trans
645
+ * @param boolean $trans
646 646
  *     - chaîne longue : c'est un nom de fichier (nom pour sa copie locale)
647 647
  *     - true : demande d'encodage/charset
648 648
  *     - null : ne retourner que les headers
649 649
  * @param string $get
650 650
  *     Type de requête HTTP à faire (HEAD, GET ou POST)
651
- * @param int|bool $taille_max
651
+ * @param integer $taille_max
652 652
  *     Arrêter le contenu au-delà (0 = seulement les entetes ==> requête HEAD).
653 653
  *     Par defaut taille_max = 1Mo.
654 654
  * @param string|array $datas
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
  *
775 775
  * @param resource $handle
776 776
  * @param int|bool $if_modified_since
777
- * @return bool|array
777
+ * @return string
778 778
  *   int status
779 779
  *   string headers
780 780
  *   int last_modified
@@ -1251,9 +1251,9 @@  discard block
 block discarded – undo
1251 1251
  *   donnees postees
1252 1252
  * @param string $vers
1253 1253
  *   version HTTP
1254
- * @param int|string $date
1254
+ * @param string $date
1255 1255
  *   timestamp pour entente If-Modified-Since
1256
- * @return bool|resource
1256
+ * @return string
1257 1257
  *   false|int si echec
1258 1258
  *   resource socket vers l'url demandee
1259 1259
  */
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1256,8 +1256,9 @@
 block discarded – undo
1256 1256
 	$http_noproxy = " $http_noproxy ";
1257 1257
 	$domain = $host;
1258 1258
 	// si le domaine exact www.example.org est dans les exceptions
1259
-	if (strpos($http_noproxy, " $domain ") !== false)
1260
-		return '';
1259
+	if (strpos($http_noproxy, " $domain ") !== false) {
1260
+			return '';
1261
+	}
1261 1262
 
1262 1263
 	while (strpos($domain, '.') !== false) {
1263 1264
 		$domain = explode('.', $domain);
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
27 27
 }
28 28
 if (!defined('_INC_DISTANT_USER_AGENT')) {
29
-	define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
29
+	define('_INC_DISTANT_USER_AGENT', 'SPIP-'.$GLOBALS['spip_version_affichee'].' ('.$GLOBALS['home_server'].')');
30 30
 }
31 31
 if (!defined('_INC_DISTANT_MAX_SIZE')) {
32 32
 	define('_INC_DISTANT_MAX_SIZE', 2097152);
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
36 36
 }
37 37
 
38
-define('_REGEXP_COPIE_LOCALE', ',' 	.
38
+define('_REGEXP_COPIE_LOCALE', ','.
39 39
 	preg_replace(
40 40
 		'@^https?:@',
41 41
 		'https?:',
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 
71 71
 	// si c'est la protection de soi-meme, retourner le path
72 72
 	if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
73
-		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
73
+		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)).urldecode($match[1]);
74 74
 
75 75
 		return @file_exists($source) ? $source : false;
76 76
 	}
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 		return false;
91 91
 	}
92 92
 
93
-	$localrac = _DIR_RACINE . $local;
93
+	$localrac = _DIR_RACINE.$local;
94 94
 	$t = ($mode == 'force') ? false : @file_exists($localrac);
95 95
 
96 96
 	// test d'existence du fichier
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
 			array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '')
116 116
 		);
117 117
 		if (!$res or (!$res['length'] and $res['status'] != 304)) {
118
-			spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE);
118
+			spip_log("copie_locale : Echec recuperation $source sur $localrac status : ".$res['status'], 'distant'._LOG_INFO_IMPORTANTE);
119 119
 		}
120 120
 		if (!$res['length']) {
121 121
 			// si $t c'est sans doute juste un not-modified-since
122 122
 			return $t ? $local : false;
123 123
 		}
124
-		spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant');
124
+		spip_log("copie_locale : recuperation $source sur $localrac taille ".$res['length'].' OK', 'distant');
125 125
 
126 126
 		// pour une eventuelle indexation
127 127
 		pipeline(
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
  *   url ou false en cas d'echec
154 154
  */
155 155
 function valider_url_distante($url, $known_hosts = array()) {
156
-	if (!function_exists('protocole_verifier')){
156
+	if (!function_exists('protocole_verifier')) {
157 157
 		include_spip('inc/filtres_mini');
158 158
 	}
159 159
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	}
163 163
 	
164 164
 	$parsed_url = parse_url($url);
165
-	if (!$parsed_url or empty($parsed_url['host']) ) {
165
+	if (!$parsed_url or empty($parsed_url['host'])) {
166 166
 		return false;
167 167
 	}
168 168
 
@@ -203,10 +203,10 @@  discard block
 block discarded – undo
203 203
 			}
204 204
 		}
205 205
 		if ($ip) {
206
-			$parts = array_map('intval', explode( '.', $ip ));
206
+			$parts = array_map('intval', explode('.', $ip));
207 207
 			if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0]
208
-			  or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] )
209
-			  or ( 192 === $parts[0] && 168 === $parts[1] )
208
+			  or (172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1])
209
+			  or (192 === $parts[0] && 168 === $parts[1])
210 210
 			) {
211 211
 				return false;
212 212
 			}
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 	}
219 219
 
220 220
 	$port = $parsed_url['port'];
221
-	if ($port === 80  or $port === 443  or $port === 8080) {
221
+	if ($port === 80 or $port === 443 or $port === 8080) {
222 222
 		return $url;
223 223
 	}
224 224
 
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 				}
286 286
 			}
287 287
 			if ($taille > 500) {
288
-				$boundary = substr(md5(rand() . 'spip'), 0, 8);
288
+				$boundary = substr(md5(rand().'spip'), 0, 8);
289 289
 			}
290 290
 		}
291 291
 
@@ -313,16 +313,16 @@  discard block
 block discarded – undo
313 313
 			}
314 314
 		} else {
315 315
 			// fabrique une chaine HTTP simple pour un POST
316
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
316
+			$entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n";
317 317
 			$chaine = array();
318 318
 			if (is_array($donnees)) {
319 319
 				foreach ($donnees as $cle => $valeur) {
320 320
 					if (is_array($valeur)) {
321 321
 						foreach ($valeur as $val2) {
322
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
322
+							$chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2);
323 323
 						}
324 324
 					} else {
325
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
325
+						$chaine[] = rawurlencode($cle).'='.rawurlencode($valeur);
326 326
 					}
327 327
 				}
328 328
 				$chaine = implode('&', $chaine);
@@ -423,9 +423,9 @@  discard block
 block discarded – undo
423 423
 	if (!empty($options['datas'])) {
424 424
 		list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
425 425
 		if (stripos($head, 'Content-Length:') === false) {
426
-			$head .= 'Content-Length: ' . strlen($postdata);
426
+			$head .= 'Content-Length: '.strlen($postdata);
427 427
 		}
428
-		$options['datas'] = $head . "\r\n\r\n" . $postdata;
428
+		$options['datas'] = $head."\r\n\r\n".$postdata;
429 429
 		if (strlen($postdata)) {
430 430
 			$options['methode'] = 'POST';
431 431
 		}
@@ -434,9 +434,9 @@  discard block
 block discarded – undo
434 434
 	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
435 435
 	$url = preg_replace(',^feed://,i', 'http://', $url);
436 436
 	if (!tester_url_absolue($url)) {
437
-		$url = 'http://' . $url;
437
+		$url = 'http://'.$url;
438 438
 	} elseif (strncmp($url, '//', 2) == 0) {
439
-		$url = 'http:' . $url;
439
+		$url = 'http:'.$url;
440 440
 	}
441 441
 
442 442
 	$url = url_to_ascii($url);
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
 		$options['if_modified_since']
466 466
 	);
467 467
 	if (!$handle) {
468
-		spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
468
+		spip_log("ECHEC init_http $url", 'distant'._LOG_ERREUR);
469 469
 
470 470
 		return false;
471 471
 	}
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
 					'status' => 200,
495 495
 				);
496 496
 			} else {
497
-				spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
497
+				spip_log("ECHEC chinoiserie $url", 'distant'._LOG_ERREUR);
498 498
 				return false;
499 499
 			}
500 500
 		} elseif ($res['location'] and $options['follow_location']) {
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
 
507 507
 			return recuperer_url($url, $options);
508 508
 		} elseif ($res['status'] !== 200) {
509
-			spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
509
+			spip_log('HTTP status '.$res['status']." pour $url", 'distant');
510 510
 		}
511 511
 		$result['status'] = $res['status'];
512 512
 		if (isset($res['headers'])) {
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 
532 532
 	$gz = false;
533 533
 	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
534
-		$gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
534
+		$gz = (_DIR_TMP.md5(uniqid(mt_rand())).'.tmp.gz');
535 535
 	}
536 536
 
537 537
 	// si on a pas deja recuperer le contenu par une methode detournee
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
 	$sig['url'] = $url;
618 618
 
619 619
 	$dir = sous_repertoire(_DIR_CACHE, 'curl');
620
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
620
+	$cache = md5(serialize($sig)).'-'.substr(preg_replace(',\W+,', '_', $url), 0, 80);
621 621
 	$sub = sous_repertoire($dir, substr($cache, 0, 2));
622 622
 	$cache = "$sub$cache";
623 623
 
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 		return false;
727 727
 	}
728 728
 	if ($get_headers) {
729
-		return $res['headers'] . "\n" . $res['page'];
729
+		return $res['headers']."\n".$res['page'];
730 730
 	}
731 731
 
732 732
 	return $res['page'];
@@ -830,7 +830,7 @@  discard block
 block discarded – undo
830 830
 	$fp = false;
831 831
 	if ($fichier) {
832 832
 		include_spip('inc/acces');
833
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
833
+		$tmpfile = "$fichier.".creer_uniqid().'.tmp';
834 834
 		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
835 835
 		if (!$fp and file_exists($fichier)) {
836 836
 			return filesize($fichier);
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
 	}
890 890
 	$result['status'] = intval($r[1]);
891 891
 	while ($s = trim(fgets($handle, 16384))) {
892
-		$result['headers'][] = $s . "\n";
892
+		$result['headers'][] = $s."\n";
893 893
 		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
894 894
 		list(, $d, $v) = $r;
895 895
 		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
@@ -972,13 +972,13 @@  discard block
 block discarded – undo
972 972
 
973 973
 	// on se place tout le temps comme si on etait a la racine
974 974
 	if (_DIR_RACINE) {
975
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
975
+		$d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d);
976 976
 	}
977 977
 
978 978
 	$m = md5($source);
979 979
 
980 980
 	return $d
981
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
981
+	. substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12)
982 982
 	. substr($m, 0, 4)
983 983
 	. ".$extension";
984 984
 }
@@ -1001,7 +1001,7 @@  discard block
 block discarded – undo
1001 1001
 	// Si c'est deja local pas de souci
1002 1002
 	if (!tester_url_absolue($source)) {
1003 1003
 		if (_DIR_RACINE) {
1004
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
1004
+			$source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source);
1005 1005
 		}
1006 1006
 
1007 1007
 		return $source;
@@ -1018,7 +1018,7 @@  discard block
 block discarded – undo
1018 1018
 	if ($ext
1019 1019
 		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
1020 1020
 		and $f = nom_fichier_copie_locale($source, $ext)
1021
-		and file_exists(_DIR_RACINE . $f)
1021
+		and file_exists(_DIR_RACINE.$f)
1022 1022
 	) {
1023 1023
 		return $f;
1024 1024
 	}
@@ -1026,7 +1026,7 @@  discard block
 block discarded – undo
1026 1026
 
1027 1027
 	// Si c'est deja dans la table des documents,
1028 1028
 	// ramener le nom de sa copie potentielle
1029
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
1029
+	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier='.sql_quote($source)." AND distant='oui' AND extension <> ''");
1030 1030
 
1031 1031
 	if ($ext) {
1032 1032
 		return nom_fichier_copie_locale($source, $ext);
@@ -1037,9 +1037,9 @@  discard block
 block discarded – undo
1037 1037
 
1038 1038
 	$ext = $path_parts ? $path_parts['extension'] : '';
1039 1039
 
1040
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1040
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
1041 1041
 		$f = nom_fichier_copie_locale($source, $ext);
1042
-		if (file_exists(_DIR_RACINE . $f)) {
1042
+		if (file_exists(_DIR_RACINE.$f)) {
1043 1043
 			return $f;
1044 1044
 		}
1045 1045
 	}
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
 	// Ping  pour voir si son extension est connue et autorisee
1048 1048
 	// avec mise en cache du resultat du ping
1049 1049
 
1050
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
1050
+	$cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source);
1051 1051
 	if (!@file_exists($cache)
1052 1052
 		or !$path_parts = @unserialize(spip_file_get_contents($cache))
1053 1053
 		or _request('var_mode') == 'recalcul'
@@ -1056,10 +1056,10 @@  discard block
 block discarded – undo
1056 1056
 		ecrire_fichier($cache, serialize($path_parts));
1057 1057
 	}
1058 1058
 	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
1059
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1059
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
1060 1060
 		return nom_fichier_copie_locale($source, $ext);
1061 1061
 	}
1062
-	spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
1062
+	spip_log("pas de copie locale pour $source", 'distant'._LOG_ERREUR);
1063 1063
 }
1064 1064
 
1065 1065
 
@@ -1124,19 +1124,19 @@  discard block
 block discarded – undo
1124 1124
 			if (!$t
1125 1125
 				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1126 1126
 			) {
1127
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1127
+				$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text'));
1128 1128
 			}
1129 1129
 			if (!$t
1130 1130
 				and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1131 1131
 				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1132 1132
 			) {
1133
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1133
+				$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text'));
1134 1134
 			}
1135 1135
 		}
1136 1136
 
1137 1137
 		// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1138 1138
 		if (!$t) {
1139
-			$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1139
+			$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type='.sql_quote($mime_type));
1140 1140
 		}
1141 1141
 
1142 1142
 		// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
@@ -1146,11 +1146,11 @@  discard block
 block discarded – undo
1146 1146
 			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1147 1147
 		) {
1148 1148
 			# eviter xxx.3 => 3gp (> SPIP 3)
1149
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1149
+			$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text'));
1150 1150
 		}
1151 1151
 
1152 1152
 		if ($t) {
1153
-			spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1153
+			spip_log("mime-type $mime_type ok, extension ".$t['extension'], 'distant');
1154 1154
 			$a['extension'] = $t['extension'];
1155 1155
 		} else {
1156 1156
 			# par defaut on retombe sur '.bin' si c'est autorise
@@ -1192,7 +1192,7 @@  discard block
 block discarded – undo
1192 1192
 		} else {
1193 1193
 			if ($a['body']) {
1194 1194
 				$a['extension'] = $extension;
1195
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1195
+				$a['fichier'] = _DIR_RACINE.nom_fichier_copie_locale($source, $extension);
1196 1196
 				ecrire_fichier($a['fichier'], $a['body']);
1197 1197
 				$size_image = @spip_getimagesize($a['fichier']);
1198 1198
 				$a['largeur'] = intval($size_image[0]);
@@ -1317,7 +1317,7 @@  discard block
 block discarded – undo
1317 1317
 		}
1318 1318
 	} else {
1319 1319
 		$scheme = $t['scheme'];
1320
-		$noproxy = $scheme . '://';
1320
+		$noproxy = $scheme.'://';
1321 1321
 	}
1322 1322
 	if (isset($t['user'])) {
1323 1323
 		$user = array($t['user'], $t['pass']);
@@ -1331,7 +1331,7 @@  discard block
 block discarded – undo
1331 1331
 	}
1332 1332
 
1333 1333
 	if (!empty($t['query'])) {
1334
-		$path .= '?' . $t['query'];
1334
+		$path .= '?'.$t['query'];
1335 1335
 	}
1336 1336
 
1337 1337
 	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
@@ -1404,20 +1404,20 @@  discard block
 block discarded – undo
1404 1404
 	$proxy_user = '';
1405 1405
 	$http_proxy = need_proxy($host);
1406 1406
 	if ($user) {
1407
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1407
+		$user = urlencode($user[0]).':'.urlencode($user[1]);
1408 1408
 	}
1409 1409
 
1410 1410
 	$connect = '';
1411 1411
 	if ($http_proxy) {
1412
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) {
1413
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1414
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1412
+		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, array('tls', 'ssl'))) {
1413
+			$path_host = (!$user ? '' : "$user@").$host.(($port != 80) ? ":$port" : '');
1414
+			$connect = 'CONNECT '.$path_host." $vers\r\n"
1415 1415
 				. "Host: $path_host\r\n"
1416 1416
 				. "Proxy-Connection: Keep-Alive\r\n";
1417 1417
 		} else {
1418
-			$path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://")
1418
+			$path = (in_array($scheme, array('tls', 'ssl')) ? 'https://' : "$scheme://")
1419 1419
 				. (!$user ? '' : "$user@")
1420
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1420
+				. "$host".(($port != 80) ? ":$port" : '').$path;
1421 1421
 		}
1422 1422
 		$t2 = @parse_url($http_proxy);
1423 1423
 		$first_host = $t2['host'];
@@ -1425,10 +1425,10 @@  discard block
 block discarded – undo
1425 1425
 			$port = 80;
1426 1426
 		}
1427 1427
 		if ($t2['user']) {
1428
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1428
+			$proxy_user = base64_encode($t2['user'].':'.$t2['pass']);
1429 1429
 		}
1430 1430
 	} else {
1431
-		$first_host = $noproxy . $host;
1431
+		$first_host = $noproxy.$host;
1432 1432
 	}
1433 1433
 
1434 1434
 	if ($connect) {
@@ -1453,7 +1453,7 @@  discard block
 block discarded – undo
1453 1453
 		);
1454 1454
 		spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1455 1455
 		if (!$f) {
1456
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1456
+			spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR);
1457 1457
 			return $errno;
1458 1458
 		}
1459 1459
 		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
@@ -1465,7 +1465,7 @@  discard block
 block discarded – undo
1465 1465
 			or !count($res = explode(' ', $res))
1466 1466
 			or $res[1] !== '200'
1467 1467
 		) {
1468
-			spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1468
+			spip_log("Echec CONNECT sur $first_host:$port", 'connect'._LOG_INFO_IMPORTANTE);
1469 1469
 			fclose($f);
1470 1470
 
1471 1471
 			return false;
@@ -1482,7 +1482,7 @@  discard block
 block discarded – undo
1482 1482
 		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1483 1483
 		spip_log("Recuperer $path sur $first_host:$port par $f");
1484 1484
 		if (!$f) {
1485
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1485
+			spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR);
1486 1486
 
1487 1487
 			return $errno;
1488 1488
 		}
@@ -1492,16 +1492,16 @@  discard block
 block discarded – undo
1492 1492
 	$site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1493 1493
 
1494 1494
 	$host_port = $host;
1495
-	if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) {
1495
+	if ($port != (in_array($scheme, array('tls', 'ssl')) ? 443 : 80)) {
1496 1496
 		$host_port .= ":$port";
1497 1497
 	}
1498 1498
 	$req = "$method $path $vers\r\n"
1499 1499
 		. "Host: $host_port\r\n"
1500
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1501
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1500
+		. 'User-Agent: '._INC_DISTANT_USER_AGENT."\r\n"
1501
+		. ($refuse_gz ? '' : ('Accept-Encoding: '._INC_DISTANT_CONTENT_ENCODING."\r\n"))
1502 1502
 		. (!$site ? '' : "Referer: $site/$referer\r\n")
1503
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1504
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1503
+		. (!$date ? '' : 'If-Modified-Since: '.(gmdate('D, d M Y H:i:s', $date)." GMT\r\n"))
1504
+		. (!$user ? '' : ('Authorization: Basic '.base64_encode($user)."\r\n"))
1505 1505
 		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1506 1506
 		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1507 1507
 
Please login to merge, or discard this patch.
Indentation   +1074 added lines, -1074 removed lines patch added patch discarded remove patch
@@ -16,32 +16,32 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Distant
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 if (!defined('_INC_DISTANT_VERSION_HTTP')) {
23
-	define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
23
+    define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
24 24
 }
25 25
 if (!defined('_INC_DISTANT_CONTENT_ENCODING')) {
26
-	define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
26
+    define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
27 27
 }
28 28
 if (!defined('_INC_DISTANT_USER_AGENT')) {
29
-	define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
29
+    define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
30 30
 }
31 31
 if (!defined('_INC_DISTANT_MAX_SIZE')) {
32
-	define('_INC_DISTANT_MAX_SIZE', 2097152);
32
+    define('_INC_DISTANT_MAX_SIZE', 2097152);
33 33
 }
34 34
 if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) {
35
-	define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
35
+    define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
36 36
 }
37 37
 
38 38
 define('_REGEXP_COPIE_LOCALE', ',' 	.
39
-	preg_replace(
40
-		'@^https?:@',
41
-		'https?:',
42
-		(isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '')
43
-	)
44
-	. '/?spip.php[?]action=acceder_document.*file=(.*)$,');
39
+    preg_replace(
40
+        '@^https?:@',
41
+        'https?:',
42
+        (isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '')
43
+    )
44
+    . '/?spip.php[?]action=acceder_document.*file=(.*)$,');
45 45
 
46 46
 //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait)
47 47
 
@@ -68,77 +68,77 @@  discard block
 block discarded – undo
68 68
  */
69 69
 function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null) {
70 70
 
71
-	// si c'est la protection de soi-meme, retourner le path
72
-	if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
73
-		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
74
-
75
-		return @file_exists($source) ? $source : false;
76
-	}
77
-
78
-	if (is_null($local)) {
79
-		$local = fichier_copie_locale($source);
80
-	} else {
81
-		if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) {
82
-			$local = substr($local, strlen(_DIR_RACINE));
83
-		}
84
-	}
85
-
86
-	// si $local = '' c'est un fichier refuse par fichier_copie_locale(),
87
-	// par exemple un fichier qui ne figure pas dans nos documents ;
88
-	// dans ce cas on n'essaie pas de le telecharger pour ensuite echouer
89
-	if (!$local) {
90
-		return false;
91
-	}
92
-
93
-	$localrac = _DIR_RACINE . $local;
94
-	$t = ($mode == 'force') ? false : @file_exists($localrac);
95
-
96
-	// test d'existence du fichier
97
-	if ($mode == 'test') {
98
-		return $t ? $local : '';
99
-	}
100
-
101
-	// sinon voir si on doit/peut le telecharger
102
-	if ($local == $source or !tester_url_absolue($source)) {
103
-		return $local;
104
-	}
105
-
106
-	if ($mode == 'modif' or !$t) {
107
-		// passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
108
-		// et des eventuelles recuperations concurantes
109
-		include_spip('inc/acces');
110
-		if (!$taille_max) {
111
-			$taille_max = _COPIE_LOCALE_MAX_SIZE;
112
-		}
113
-		$res = recuperer_url(
114
-			$source,
115
-			array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '')
116
-		);
117
-		if (!$res or (!$res['length'] and $res['status'] != 304)) {
118
-			spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE);
119
-		}
120
-		if (!$res['length']) {
121
-			// si $t c'est sans doute juste un not-modified-since
122
-			return $t ? $local : false;
123
-		}
124
-		spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant');
125
-
126
-		// pour une eventuelle indexation
127
-		pipeline(
128
-			'post_edition',
129
-			array(
130
-				'args' => array(
131
-					'operation' => 'copie_locale',
132
-					'source' => $source,
133
-					'fichier' => $local,
134
-					'http_res' => $res['length'],
135
-				),
136
-				'data' => null
137
-			)
138
-		);
139
-	}
140
-
141
-	return $local;
71
+    // si c'est la protection de soi-meme, retourner le path
72
+    if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
73
+        $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
74
+
75
+        return @file_exists($source) ? $source : false;
76
+    }
77
+
78
+    if (is_null($local)) {
79
+        $local = fichier_copie_locale($source);
80
+    } else {
81
+        if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) {
82
+            $local = substr($local, strlen(_DIR_RACINE));
83
+        }
84
+    }
85
+
86
+    // si $local = '' c'est un fichier refuse par fichier_copie_locale(),
87
+    // par exemple un fichier qui ne figure pas dans nos documents ;
88
+    // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer
89
+    if (!$local) {
90
+        return false;
91
+    }
92
+
93
+    $localrac = _DIR_RACINE . $local;
94
+    $t = ($mode == 'force') ? false : @file_exists($localrac);
95
+
96
+    // test d'existence du fichier
97
+    if ($mode == 'test') {
98
+        return $t ? $local : '';
99
+    }
100
+
101
+    // sinon voir si on doit/peut le telecharger
102
+    if ($local == $source or !tester_url_absolue($source)) {
103
+        return $local;
104
+    }
105
+
106
+    if ($mode == 'modif' or !$t) {
107
+        // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
108
+        // et des eventuelles recuperations concurantes
109
+        include_spip('inc/acces');
110
+        if (!$taille_max) {
111
+            $taille_max = _COPIE_LOCALE_MAX_SIZE;
112
+        }
113
+        $res = recuperer_url(
114
+            $source,
115
+            array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '')
116
+        );
117
+        if (!$res or (!$res['length'] and $res['status'] != 304)) {
118
+            spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE);
119
+        }
120
+        if (!$res['length']) {
121
+            // si $t c'est sans doute juste un not-modified-since
122
+            return $t ? $local : false;
123
+        }
124
+        spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant');
125
+
126
+        // pour une eventuelle indexation
127
+        pipeline(
128
+            'post_edition',
129
+            array(
130
+                'args' => array(
131
+                    'operation' => 'copie_locale',
132
+                    'source' => $source,
133
+                    'fichier' => $local,
134
+                    'http_res' => $res['length'],
135
+                ),
136
+                'data' => null
137
+            )
138
+        );
139
+    }
140
+
141
+    return $local;
142 142
 }
143 143
 
144 144
 /**
@@ -153,88 +153,88 @@  discard block
 block discarded – undo
153 153
  *   url ou false en cas d'echec
154 154
  */
155 155
 function valider_url_distante($url, $known_hosts = array()) {
156
-	if (!function_exists('protocole_verifier')){
157
-		include_spip('inc/filtres_mini');
158
-	}
156
+    if (!function_exists('protocole_verifier')){
157
+        include_spip('inc/filtres_mini');
158
+    }
159 159
 
160
-	if (!protocole_verifier($url, array('http', 'https'))) {
161
-		return false;
162
-	}
160
+    if (!protocole_verifier($url, array('http', 'https'))) {
161
+        return false;
162
+    }
163 163
 	
164
-	$parsed_url = parse_url($url);
165
-	if (!$parsed_url or empty($parsed_url['host']) ) {
166
-		return false;
167
-	}
168
-
169
-	if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
170
-		return false;
171
-	}
172
-
173
-	if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
174
-		return false;
175
-	}
176
-
177
-	if (!is_array($known_hosts)) {
178
-		$known_hosts = array($known_hosts);
179
-	}
180
-	$known_hosts[] = $GLOBALS['meta']['adresse_site'];
181
-	$known_hosts[] = url_de_base();
182
-	$known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
183
-
184
-	$is_known_host = false;
185
-	foreach ($known_hosts as $known_host) {
186
-		$parse_known = parse_url($known_host);
187
-		if ($parse_known
188
-		  and strtolower($parse_known['host']) === strtolower($parsed_url['host'])) {
189
-			$is_known_host = true;
190
-			break;
191
-		}
192
-	}
193
-
194
-	if (!$is_known_host) {
195
-		$host = trim($parsed_url['host'], '.');
196
-		if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) {
197
-			$ip = $host;
198
-		} else {
199
-			$ip = gethostbyname($host);
200
-			if ($ip === $host) {
201
-				// Error condition for gethostbyname()
202
-				$ip = false;
203
-			}
204
-		}
205
-		if ($ip) {
206
-			$parts = array_map('intval', explode( '.', $ip ));
207
-			if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0]
208
-			  or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] )
209
-			  or ( 192 === $parts[0] && 168 === $parts[1] )
210
-			) {
211
-				return false;
212
-			}
213
-		}
214
-	}
215
-
216
-	if (empty($parsed_url['port'])) {
217
-		return $url;
218
-	}
219
-
220
-	$port = $parsed_url['port'];
221
-	if ($port === 80  or $port === 443  or $port === 8080) {
222
-		return $url;
223
-	}
224
-
225
-	if ($is_known_host) {
226
-		foreach ($known_hosts as $known_host) {
227
-			$parse_known = parse_url($known_host);
228
-			if ($parse_known
229
-				and !empty($parse_known['port'])
230
-			  and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
231
-			  and $parse_known['port'] == $port) {
232
-				return $url;
233
-			}
234
-		}
235
-	}
236
-
237
-	return false;
164
+    $parsed_url = parse_url($url);
165
+    if (!$parsed_url or empty($parsed_url['host']) ) {
166
+        return false;
167
+    }
168
+
169
+    if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
170
+        return false;
171
+    }
172
+
173
+    if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
174
+        return false;
175
+    }
176
+
177
+    if (!is_array($known_hosts)) {
178
+        $known_hosts = array($known_hosts);
179
+    }
180
+    $known_hosts[] = $GLOBALS['meta']['adresse_site'];
181
+    $known_hosts[] = url_de_base();
182
+    $known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
183
+
184
+    $is_known_host = false;
185
+    foreach ($known_hosts as $known_host) {
186
+        $parse_known = parse_url($known_host);
187
+        if ($parse_known
188
+          and strtolower($parse_known['host']) === strtolower($parsed_url['host'])) {
189
+            $is_known_host = true;
190
+            break;
191
+        }
192
+    }
193
+
194
+    if (!$is_known_host) {
195
+        $host = trim($parsed_url['host'], '.');
196
+        if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) {
197
+            $ip = $host;
198
+        } else {
199
+            $ip = gethostbyname($host);
200
+            if ($ip === $host) {
201
+                // Error condition for gethostbyname()
202
+                $ip = false;
203
+            }
204
+        }
205
+        if ($ip) {
206
+            $parts = array_map('intval', explode( '.', $ip ));
207
+            if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0]
208
+              or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] )
209
+              or ( 192 === $parts[0] && 168 === $parts[1] )
210
+            ) {
211
+                return false;
212
+            }
213
+        }
214
+    }
215
+
216
+    if (empty($parsed_url['port'])) {
217
+        return $url;
218
+    }
219
+
220
+    $port = $parsed_url['port'];
221
+    if ($port === 80  or $port === 443  or $port === 8080) {
222
+        return $url;
223
+    }
224
+
225
+    if ($is_known_host) {
226
+        foreach ($known_hosts as $known_host) {
227
+            $parse_known = parse_url($known_host);
228
+            if ($parse_known
229
+                and !empty($parse_known['port'])
230
+              and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
231
+              and $parse_known['port'] == $port) {
232
+                return $url;
233
+            }
234
+        }
235
+    }
236
+
237
+    return false;
238 238
 }
239 239
 
240 240
 /**
@@ -254,86 +254,86 @@  discard block
 block discarded – undo
254 254
  */
255 255
 function prepare_donnees_post($donnees, $boundary = '') {
256 256
 
257
-	// permettre a la fonction qui a demande le post de formater elle meme ses donnees
258
-	// pour un appel soap par exemple
259
-	// l'entete est separe des donnees par un double retour a la ligne
260
-	// on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
261
-	if (is_string($donnees) && strlen($donnees)) {
262
-		$entete = '';
263
-		// on repasse tous les \r\n et \r en simples \n
264
-		$donnees = str_replace("\r\n", "\n", $donnees);
265
-		$donnees = str_replace("\r", "\n", $donnees);
266
-		// un double retour a la ligne signifie la fin de l'entete et le debut des donnees
267
-		$p = strpos($donnees, "\n\n");
268
-		if ($p !== false) {
269
-			$entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
270
-			$donnees = substr($donnees, $p + 2);
271
-		}
272
-		$chaine = str_replace("\n", "\r\n", $donnees);
273
-	} else {
274
-		/* boundary automatique */
275
-		// Si on a plus de 500 octects de donnees, on "boundarise"
276
-		if ($boundary === '') {
277
-			$taille = 0;
278
-			foreach ($donnees as $cle => $valeur) {
279
-				if (is_array($valeur)) {
280
-					foreach ($valeur as $val2) {
281
-						$taille += strlen($val2);
282
-					}
283
-				} else {
284
-					// faut-il utiliser spip_strlen() dans inc/charsets ?
285
-					$taille += strlen($valeur);
286
-				}
287
-			}
288
-			if ($taille > 500) {
289
-				$boundary = substr(md5(rand() . 'spip'), 0, 8);
290
-			}
291
-		}
292
-
293
-		if (is_string($boundary) and strlen($boundary)) {
294
-			// fabrique une chaine HTTP pour un POST avec boundary
295
-			$entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
296
-			$chaine = '';
297
-			if (is_array($donnees)) {
298
-				foreach ($donnees as $cle => $valeur) {
299
-					if (is_array($valeur)) {
300
-						foreach ($valeur as $val2) {
301
-							$chaine .= "\r\n--$boundary\r\n";
302
-							$chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
303
-							$chaine .= "\r\n";
304
-							$chaine .= $val2;
305
-						}
306
-					} else {
307
-						$chaine .= "\r\n--$boundary\r\n";
308
-						$chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
309
-						$chaine .= "\r\n";
310
-						$chaine .= $valeur;
311
-					}
312
-				}
313
-				$chaine .= "\r\n--$boundary\r\n";
314
-			}
315
-		} else {
316
-			// fabrique une chaine HTTP simple pour un POST
317
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
318
-			$chaine = array();
319
-			if (is_array($donnees)) {
320
-				foreach ($donnees as $cle => $valeur) {
321
-					if (is_array($valeur)) {
322
-						foreach ($valeur as $val2) {
323
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
324
-						}
325
-					} else {
326
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
327
-					}
328
-				}
329
-				$chaine = implode('&', $chaine);
330
-			} else {
331
-				$chaine = $donnees;
332
-			}
333
-		}
334
-	}
335
-
336
-	return array($entete, $chaine);
257
+    // permettre a la fonction qui a demande le post de formater elle meme ses donnees
258
+    // pour un appel soap par exemple
259
+    // l'entete est separe des donnees par un double retour a la ligne
260
+    // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
261
+    if (is_string($donnees) && strlen($donnees)) {
262
+        $entete = '';
263
+        // on repasse tous les \r\n et \r en simples \n
264
+        $donnees = str_replace("\r\n", "\n", $donnees);
265
+        $donnees = str_replace("\r", "\n", $donnees);
266
+        // un double retour a la ligne signifie la fin de l'entete et le debut des donnees
267
+        $p = strpos($donnees, "\n\n");
268
+        if ($p !== false) {
269
+            $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
270
+            $donnees = substr($donnees, $p + 2);
271
+        }
272
+        $chaine = str_replace("\n", "\r\n", $donnees);
273
+    } else {
274
+        /* boundary automatique */
275
+        // Si on a plus de 500 octects de donnees, on "boundarise"
276
+        if ($boundary === '') {
277
+            $taille = 0;
278
+            foreach ($donnees as $cle => $valeur) {
279
+                if (is_array($valeur)) {
280
+                    foreach ($valeur as $val2) {
281
+                        $taille += strlen($val2);
282
+                    }
283
+                } else {
284
+                    // faut-il utiliser spip_strlen() dans inc/charsets ?
285
+                    $taille += strlen($valeur);
286
+                }
287
+            }
288
+            if ($taille > 500) {
289
+                $boundary = substr(md5(rand() . 'spip'), 0, 8);
290
+            }
291
+        }
292
+
293
+        if (is_string($boundary) and strlen($boundary)) {
294
+            // fabrique une chaine HTTP pour un POST avec boundary
295
+            $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
296
+            $chaine = '';
297
+            if (is_array($donnees)) {
298
+                foreach ($donnees as $cle => $valeur) {
299
+                    if (is_array($valeur)) {
300
+                        foreach ($valeur as $val2) {
301
+                            $chaine .= "\r\n--$boundary\r\n";
302
+                            $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
303
+                            $chaine .= "\r\n";
304
+                            $chaine .= $val2;
305
+                        }
306
+                    } else {
307
+                        $chaine .= "\r\n--$boundary\r\n";
308
+                        $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
309
+                        $chaine .= "\r\n";
310
+                        $chaine .= $valeur;
311
+                    }
312
+                }
313
+                $chaine .= "\r\n--$boundary\r\n";
314
+            }
315
+        } else {
316
+            // fabrique une chaine HTTP simple pour un POST
317
+            $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
318
+            $chaine = array();
319
+            if (is_array($donnees)) {
320
+                foreach ($donnees as $cle => $valeur) {
321
+                    if (is_array($valeur)) {
322
+                        foreach ($valeur as $val2) {
323
+                            $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
324
+                        }
325
+                    } else {
326
+                        $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
327
+                    }
328
+                }
329
+                $chaine = implode('&', $chaine);
330
+            } else {
331
+                $chaine = $donnees;
332
+            }
333
+        }
334
+    }
335
+
336
+    return array($entete, $chaine);
337 337
 }
338 338
 
339 339
 /**
@@ -347,20 +347,20 @@  discard block
 block discarded – undo
347 347
  */
348 348
 function url_to_ascii($url_idn) {
349 349
 
350
-	if ($parts = parse_url($url_idn)) {
351
-		$host = $parts['host'];
352
-		if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
353
-			include_spip('inc/idna_convert.class');
354
-			$IDN = new idna_convert();
355
-			$host_ascii = $IDN->encode($host);
356
-			$url_idn = explode($host, $url_idn, 2);
357
-			$url_idn = implode($host_ascii, $url_idn);
358
-		}
359
-		// et on urlencode les char utf si besoin dans le path
360
-		$url_idn = preg_replace_callback('/[^\x20-\x7f]/', function($match) { return urlencode($match[0]); }, $url_idn);
361
-	}
362
-
363
-	return $url_idn;
350
+    if ($parts = parse_url($url_idn)) {
351
+        $host = $parts['host'];
352
+        if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
353
+            include_spip('inc/idna_convert.class');
354
+            $IDN = new idna_convert();
355
+            $host_ascii = $IDN->encode($host);
356
+            $url_idn = explode($host, $url_idn, 2);
357
+            $url_idn = implode($host_ascii, $url_idn);
358
+        }
359
+        // et on urlencode les char utf si besoin dans le path
360
+        $url_idn = preg_replace_callback('/[^\x20-\x7f]/', function($match) { return urlencode($match[0]); }, $url_idn);
361
+    }
362
+
363
+    return $url_idn;
364 364
 }
365 365
 
366 366
 /**
@@ -400,176 +400,176 @@  discard block
 block discarded – undo
400 400
  *     string file : nom du fichier si enregistre dans un fichier
401 401
  */
402 402
 function recuperer_url($url, $options = array()) {
403
-	$default = array(
404
-		'transcoder' => false,
405
-		'methode' => 'GET',
406
-		'taille_max' => null,
407
-		'datas' => '',
408
-		'boundary' => '',
409
-		'refuser_gz' => false,
410
-		'if_modified_since' => '',
411
-		'uri_referer' => '',
412
-		'file' => '',
413
-		'follow_location' => 10,
414
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
415
-	);
416
-	$options = array_merge($default, $options);
417
-	// copier directement dans un fichier ?
418
-	$copy = $options['file'];
419
-
420
-	if ($options['methode'] == 'HEAD') {
421
-		$options['taille_max'] = 0;
422
-	}
423
-	if (is_null($options['taille_max'])) {
424
-		$options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
425
-	}
426
-
427
-	if (!empty($options['datas'])) {
428
-		list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
429
-		if (stripos($head, 'Content-Length:') === false) {
430
-			$head .= 'Content-Length: ' . strlen($postdata);
431
-		}
432
-		$options['datas'] = $head . "\r\n\r\n" . $postdata;
433
-		if (strlen($postdata)) {
434
-			$options['methode'] = 'POST';
435
-		}
436
-	}
437
-
438
-	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
439
-	$url = preg_replace(',^feed://,i', 'http://', $url);
440
-	if (!tester_url_absolue($url)) {
441
-		$url = 'http://' . $url;
442
-	} elseif (strncmp($url, '//', 2) == 0) {
443
-		$url = 'http:' . $url;
444
-	}
445
-
446
-	$url = url_to_ascii($url);
447
-
448
-	$result = array(
449
-		'status' => 0,
450
-		'headers' => '',
451
-		'page' => '',
452
-		'length' => 0,
453
-		'last_modified' => '',
454
-		'location' => '',
455
-		'url' => $url
456
-	);
457
-
458
-	// si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
459
-	$refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
460
-
461
-	// ouvrir la connexion et envoyer la requete et ses en-tetes
462
-	list($handle, $fopen) = init_http(
463
-		$options['methode'],
464
-		$url,
465
-		$refuser_gz,
466
-		$options['uri_referer'],
467
-		$options['datas'],
468
-		$options['version_http'],
469
-		$options['if_modified_since']
470
-	);
471
-	if (!$handle) {
472
-		spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
473
-
474
-		return false;
475
-	}
476
-
477
-	// Sauf en fopen, envoyer le flux d'entree
478
-	// et recuperer les en-tetes de reponses
479
-	if (!$fopen) {
480
-		$res = recuperer_entetes_complets($handle, $options['if_modified_since']);
481
-		if (!$res) {
482
-			fclose($handle);
483
-			$t = @parse_url($url);
484
-			$host = $t['host'];
485
-			// Chinoisierie inexplicable pour contrer
486
-			// les actions liberticides de l'empire du milieu
487
-			if (!need_proxy($host)
488
-				and $res = @file_get_contents($url)
489
-			) {
490
-				$result['length'] = strlen($res);
491
-				if ($copy) {
492
-					ecrire_fichier($copy, $res);
493
-					$result['file'] = $copy;
494
-				} else {
495
-					$result['page'] = $res;
496
-				}
497
-				$res = array(
498
-					'status' => 200,
499
-				);
500
-			} else {
501
-				spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
502
-				return false;
503
-			}
504
-		} elseif ($res['location'] and $options['follow_location']) {
505
-			$options['follow_location']--;
506
-			fclose($handle);
507
-			include_spip('inc/filtres');
508
-			$url = suivre_lien($url, $res['location']);
509
-			spip_log("recuperer_url recommence sur $url", 'distant');
510
-
511
-			return recuperer_url($url, $options);
512
-		} elseif ($res['status'] !== 200) {
513
-			spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
514
-		}
515
-		$result['status'] = $res['status'];
516
-		if (isset($res['headers'])) {
517
-			$result['headers'] = $res['headers'];
518
-		}
519
-		if (isset($res['last_modified'])) {
520
-			$result['last_modified'] = $res['last_modified'];
521
-		}
522
-		if (isset($res['location'])) {
523
-			$result['location'] = $res['location'];
524
-		}
525
-	}
526
-
527
-	// on ne veut que les entetes
528
-	if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
529
-		return $result;
530
-	}
531
-
532
-
533
-	// s'il faut deballer, le faire via un fichier temporaire
534
-	// sinon la memoire explose pour les gros flux
535
-
536
-	$gz = false;
537
-	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
538
-		$gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
539
-	}
540
-
541
-	// si on a pas deja recuperer le contenu par une methode detournee
542
-	if (!$result['length']) {
543
-		$res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy);
544
-		fclose($handle);
545
-		if ($copy) {
546
-			$result['length'] = $res;
547
-			$result['file'] = $copy;
548
-		} elseif ($res) {
549
-			$result['page'] = &$res;
550
-			$result['length'] = strlen($result['page']);
551
-		}
552
-		if (!$result['status']) {
553
-			$result['status'] = 200; // on a reussi, donc !
554
-		}
555
-	}
556
-	if (!$result['page']) {
557
-		return $result;
558
-	}
559
-
560
-	// Decompresser au besoin
561
-	if ($gz) {
562
-		$result['page'] = implode('', gzfile($gz));
563
-		supprimer_fichier($gz);
564
-	}
565
-
566
-	// Faut-il l'importer dans notre charset local ?
567
-	if ($options['transcoder']) {
568
-		include_spip('inc/charsets');
569
-		$result['page'] = transcoder_page($result['page'], $result['headers']);
570
-	}
571
-
572
-	return $result;
403
+    $default = array(
404
+        'transcoder' => false,
405
+        'methode' => 'GET',
406
+        'taille_max' => null,
407
+        'datas' => '',
408
+        'boundary' => '',
409
+        'refuser_gz' => false,
410
+        'if_modified_since' => '',
411
+        'uri_referer' => '',
412
+        'file' => '',
413
+        'follow_location' => 10,
414
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
415
+    );
416
+    $options = array_merge($default, $options);
417
+    // copier directement dans un fichier ?
418
+    $copy = $options['file'];
419
+
420
+    if ($options['methode'] == 'HEAD') {
421
+        $options['taille_max'] = 0;
422
+    }
423
+    if (is_null($options['taille_max'])) {
424
+        $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
425
+    }
426
+
427
+    if (!empty($options['datas'])) {
428
+        list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
429
+        if (stripos($head, 'Content-Length:') === false) {
430
+            $head .= 'Content-Length: ' . strlen($postdata);
431
+        }
432
+        $options['datas'] = $head . "\r\n\r\n" . $postdata;
433
+        if (strlen($postdata)) {
434
+            $options['methode'] = 'POST';
435
+        }
436
+    }
437
+
438
+    // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
439
+    $url = preg_replace(',^feed://,i', 'http://', $url);
440
+    if (!tester_url_absolue($url)) {
441
+        $url = 'http://' . $url;
442
+    } elseif (strncmp($url, '//', 2) == 0) {
443
+        $url = 'http:' . $url;
444
+    }
445
+
446
+    $url = url_to_ascii($url);
447
+
448
+    $result = array(
449
+        'status' => 0,
450
+        'headers' => '',
451
+        'page' => '',
452
+        'length' => 0,
453
+        'last_modified' => '',
454
+        'location' => '',
455
+        'url' => $url
456
+    );
457
+
458
+    // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
459
+    $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
460
+
461
+    // ouvrir la connexion et envoyer la requete et ses en-tetes
462
+    list($handle, $fopen) = init_http(
463
+        $options['methode'],
464
+        $url,
465
+        $refuser_gz,
466
+        $options['uri_referer'],
467
+        $options['datas'],
468
+        $options['version_http'],
469
+        $options['if_modified_since']
470
+    );
471
+    if (!$handle) {
472
+        spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
473
+
474
+        return false;
475
+    }
476
+
477
+    // Sauf en fopen, envoyer le flux d'entree
478
+    // et recuperer les en-tetes de reponses
479
+    if (!$fopen) {
480
+        $res = recuperer_entetes_complets($handle, $options['if_modified_since']);
481
+        if (!$res) {
482
+            fclose($handle);
483
+            $t = @parse_url($url);
484
+            $host = $t['host'];
485
+            // Chinoisierie inexplicable pour contrer
486
+            // les actions liberticides de l'empire du milieu
487
+            if (!need_proxy($host)
488
+                and $res = @file_get_contents($url)
489
+            ) {
490
+                $result['length'] = strlen($res);
491
+                if ($copy) {
492
+                    ecrire_fichier($copy, $res);
493
+                    $result['file'] = $copy;
494
+                } else {
495
+                    $result['page'] = $res;
496
+                }
497
+                $res = array(
498
+                    'status' => 200,
499
+                );
500
+            } else {
501
+                spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
502
+                return false;
503
+            }
504
+        } elseif ($res['location'] and $options['follow_location']) {
505
+            $options['follow_location']--;
506
+            fclose($handle);
507
+            include_spip('inc/filtres');
508
+            $url = suivre_lien($url, $res['location']);
509
+            spip_log("recuperer_url recommence sur $url", 'distant');
510
+
511
+            return recuperer_url($url, $options);
512
+        } elseif ($res['status'] !== 200) {
513
+            spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
514
+        }
515
+        $result['status'] = $res['status'];
516
+        if (isset($res['headers'])) {
517
+            $result['headers'] = $res['headers'];
518
+        }
519
+        if (isset($res['last_modified'])) {
520
+            $result['last_modified'] = $res['last_modified'];
521
+        }
522
+        if (isset($res['location'])) {
523
+            $result['location'] = $res['location'];
524
+        }
525
+    }
526
+
527
+    // on ne veut que les entetes
528
+    if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
529
+        return $result;
530
+    }
531
+
532
+
533
+    // s'il faut deballer, le faire via un fichier temporaire
534
+    // sinon la memoire explose pour les gros flux
535
+
536
+    $gz = false;
537
+    if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
538
+        $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
539
+    }
540
+
541
+    // si on a pas deja recuperer le contenu par une methode detournee
542
+    if (!$result['length']) {
543
+        $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy);
544
+        fclose($handle);
545
+        if ($copy) {
546
+            $result['length'] = $res;
547
+            $result['file'] = $copy;
548
+        } elseif ($res) {
549
+            $result['page'] = &$res;
550
+            $result['length'] = strlen($result['page']);
551
+        }
552
+        if (!$result['status']) {
553
+            $result['status'] = 200; // on a reussi, donc !
554
+        }
555
+    }
556
+    if (!$result['page']) {
557
+        return $result;
558
+    }
559
+
560
+    // Decompresser au besoin
561
+    if ($gz) {
562
+        $result['page'] = implode('', gzfile($gz));
563
+        supprimer_fichier($gz);
564
+    }
565
+
566
+    // Faut-il l'importer dans notre charset local ?
567
+    if ($options['transcoder']) {
568
+        include_spip('inc/charsets');
569
+        $result['page'] = transcoder_page($result['page'], $result['headers']);
570
+    }
571
+
572
+    return $result;
573 573
 }
574 574
 
575 575
 /**
@@ -585,72 +585,72 @@  discard block
 block discarded – undo
585 585
  * @return array|bool|mixed
586 586
  */
587 587
 function recuperer_url_cache($url, $options = array()) {
588
-	if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
589
-		define('_DELAI_RECUPERER_URL_CACHE', 3600);
590
-	}
591
-	$default = array(
592
-		'transcoder' => false,
593
-		'methode' => 'GET',
594
-		'taille_max' => null,
595
-		'datas' => '',
596
-		'boundary' => '',
597
-		'refuser_gz' => false,
598
-		'if_modified_since' => '',
599
-		'uri_referer' => '',
600
-		'file' => '',
601
-		'follow_location' => 10,
602
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
603
-		'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE,
604
-	);
605
-	$options = array_merge($default, $options);
606
-
607
-	// cas ou il n'est pas possible de cacher
608
-	if (!empty($options['data']) or $options['methode'] == 'POST') {
609
-		return recuperer_url($url, $options);
610
-	}
611
-
612
-	// ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
613
-	static $errors = array();
614
-	if (isset($errors[$url])) {
615
-		return $errors[$url];
616
-	}
617
-
618
-	$sig = $options;
619
-	unset($sig['if_modified_since']);
620
-	unset($sig['delai_cache']);
621
-	$sig['url'] = $url;
622
-
623
-	$dir = sous_repertoire(_DIR_CACHE, 'curl');
624
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
625
-	$sub = sous_repertoire($dir, substr($cache, 0, 2));
626
-	$cache = "$sub$cache";
627
-
628
-	$res = false;
629
-	$is_cached = file_exists($cache);
630
-	if ($is_cached
631
-		and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
632
-	) {
633
-		lire_fichier($cache, $res);
634
-		if ($res = unserialize($res)) {
635
-			// mettre le last_modified et le status=304 ?
636
-		}
637
-	}
638
-	if (!$res) {
639
-		$res = recuperer_url($url, $options);
640
-		// ne pas recharger cette url non cachee dans le meme hit puisque non disponible
641
-		if (!$res) {
642
-			if ($is_cached) {
643
-				// on a pas reussi a recuperer mais on avait un cache : l'utiliser
644
-				lire_fichier($cache, $res);
645
-				$res = unserialize($res);
646
-			}
647
-
648
-			return $errors[$url] = $res;
649
-		}
650
-		ecrire_fichier($cache, serialize($res));
651
-	}
652
-
653
-	return $res;
588
+    if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
589
+        define('_DELAI_RECUPERER_URL_CACHE', 3600);
590
+    }
591
+    $default = array(
592
+        'transcoder' => false,
593
+        'methode' => 'GET',
594
+        'taille_max' => null,
595
+        'datas' => '',
596
+        'boundary' => '',
597
+        'refuser_gz' => false,
598
+        'if_modified_since' => '',
599
+        'uri_referer' => '',
600
+        'file' => '',
601
+        'follow_location' => 10,
602
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
603
+        'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE,
604
+    );
605
+    $options = array_merge($default, $options);
606
+
607
+    // cas ou il n'est pas possible de cacher
608
+    if (!empty($options['data']) or $options['methode'] == 'POST') {
609
+        return recuperer_url($url, $options);
610
+    }
611
+
612
+    // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
613
+    static $errors = array();
614
+    if (isset($errors[$url])) {
615
+        return $errors[$url];
616
+    }
617
+
618
+    $sig = $options;
619
+    unset($sig['if_modified_since']);
620
+    unset($sig['delai_cache']);
621
+    $sig['url'] = $url;
622
+
623
+    $dir = sous_repertoire(_DIR_CACHE, 'curl');
624
+    $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
625
+    $sub = sous_repertoire($dir, substr($cache, 0, 2));
626
+    $cache = "$sub$cache";
627
+
628
+    $res = false;
629
+    $is_cached = file_exists($cache);
630
+    if ($is_cached
631
+        and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
632
+    ) {
633
+        lire_fichier($cache, $res);
634
+        if ($res = unserialize($res)) {
635
+            // mettre le last_modified et le status=304 ?
636
+        }
637
+    }
638
+    if (!$res) {
639
+        $res = recuperer_url($url, $options);
640
+        // ne pas recharger cette url non cachee dans le meme hit puisque non disponible
641
+        if (!$res) {
642
+            if ($is_cached) {
643
+                // on a pas reussi a recuperer mais on avait un cache : l'utiliser
644
+                lire_fichier($cache, $res);
645
+                $res = unserialize($res);
646
+            }
647
+
648
+            return $errors[$url] = $res;
649
+        }
650
+        ecrire_fichier($cache, serialize($res));
651
+    }
652
+
653
+    return $res;
654 654
 }
655 655
 
656 656
 /**
@@ -688,52 +688,52 @@  discard block
 block discarded – undo
688 688
  *     - false si la page n'a pu être récupérée (status different de 200)
689 689
  **/
690 690
 function recuperer_page(
691
-	$url,
692
-	$trans = false,
693
-	$get_headers = false,
694
-	$taille_max = null,
695
-	$datas = '',
696
-	$boundary = '',
697
-	$refuser_gz = false,
698
-	$date_verif = '',
699
-	$uri_referer = ''
691
+    $url,
692
+    $trans = false,
693
+    $get_headers = false,
694
+    $taille_max = null,
695
+    $datas = '',
696
+    $boundary = '',
697
+    $refuser_gz = false,
698
+    $date_verif = '',
699
+    $uri_referer = ''
700 700
 ) {
701
-	// $copy = copier le fichier ?
702
-	$copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
703
-
704
-	if (!is_null($taille_max) and ($taille_max == 0)) {
705
-		$get = 'HEAD';
706
-	} else {
707
-		$get = 'GET';
708
-	}
709
-
710
-	$options = array(
711
-		'transcoder' => $trans === true,
712
-		'methode' => $get,
713
-		'datas' => $datas,
714
-		'boundary' => $boundary,
715
-		'refuser_gz' => $refuser_gz,
716
-		'if_modified_since' => $date_verif,
717
-		'uri_referer' => $uri_referer,
718
-		'file' => $copy ? $trans : '',
719
-		'follow_location' => 10,
720
-	);
721
-	if (!is_null($taille_max)) {
722
-		$options['taille_max'] = $taille_max;
723
-	}
724
-	// dix tentatives maximum en cas d'entetes 301...
725
-	$res = recuperer_url($url, $options);
726
-	if (!$res) {
727
-		return false;
728
-	}
729
-	if ($res['status'] !== 200) {
730
-		return false;
731
-	}
732
-	if ($get_headers) {
733
-		return $res['headers'] . "\n" . $res['page'];
734
-	}
735
-
736
-	return $res['page'];
701
+    // $copy = copier le fichier ?
702
+    $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
703
+
704
+    if (!is_null($taille_max) and ($taille_max == 0)) {
705
+        $get = 'HEAD';
706
+    } else {
707
+        $get = 'GET';
708
+    }
709
+
710
+    $options = array(
711
+        'transcoder' => $trans === true,
712
+        'methode' => $get,
713
+        'datas' => $datas,
714
+        'boundary' => $boundary,
715
+        'refuser_gz' => $refuser_gz,
716
+        'if_modified_since' => $date_verif,
717
+        'uri_referer' => $uri_referer,
718
+        'file' => $copy ? $trans : '',
719
+        'follow_location' => 10,
720
+    );
721
+    if (!is_null($taille_max)) {
722
+        $options['taille_max'] = $taille_max;
723
+    }
724
+    // dix tentatives maximum en cas d'entetes 301...
725
+    $res = recuperer_url($url, $options);
726
+    if (!$res) {
727
+        return false;
728
+    }
729
+    if ($res['status'] !== 200) {
730
+        return false;
731
+    }
732
+    if ($get_headers) {
733
+        return $res['headers'] . "\n" . $res['page'];
734
+    }
735
+
736
+    return $res['page'];
737 737
 }
738 738
 
739 739
 
@@ -770,48 +770,48 @@  discard block
 block discarded – undo
770 770
  *     - false sinon
771 771
  **/
772 772
 function recuperer_lapage(
773
-	$url,
774
-	$trans = false,
775
-	$get = 'GET',
776
-	$taille_max = 1048576,
777
-	$datas = '',
778
-	$refuser_gz = false,
779
-	$date_verif = '',
780
-	$uri_referer = ''
773
+    $url,
774
+    $trans = false,
775
+    $get = 'GET',
776
+    $taille_max = 1048576,
777
+    $datas = '',
778
+    $refuser_gz = false,
779
+    $date_verif = '',
780
+    $uri_referer = ''
781 781
 ) {
782
-	// $copy = copier le fichier ?
783
-	$copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
784
-
785
-	// si on ecrit directement dans un fichier, pour ne pas manipuler
786
-	// en memoire refuser gz
787
-	if ($copy) {
788
-		$refuser_gz = true;
789
-	}
790
-
791
-	$options = array(
792
-		'transcoder' => $trans === true,
793
-		'methode' => $get,
794
-		'datas' => $datas,
795
-		'refuser_gz' => $refuser_gz,
796
-		'if_modified_since' => $date_verif,
797
-		'uri_referer' => $uri_referer,
798
-		'file' => $copy ? $trans : '',
799
-		'follow_location' => false,
800
-	);
801
-	if (!is_null($taille_max)) {
802
-		$options['taille_max'] = $taille_max;
803
-	}
804
-	// dix tentatives maximum en cas d'entetes 301...
805
-	$res = recuperer_url($url, $options);
806
-
807
-	if (!$res) {
808
-		return false;
809
-	}
810
-	if ($res['status'] !== 200) {
811
-		return false;
812
-	}
813
-
814
-	return array($res['headers'], $res['page']);
782
+    // $copy = copier le fichier ?
783
+    $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
784
+
785
+    // si on ecrit directement dans un fichier, pour ne pas manipuler
786
+    // en memoire refuser gz
787
+    if ($copy) {
788
+        $refuser_gz = true;
789
+    }
790
+
791
+    $options = array(
792
+        'transcoder' => $trans === true,
793
+        'methode' => $get,
794
+        'datas' => $datas,
795
+        'refuser_gz' => $refuser_gz,
796
+        'if_modified_since' => $date_verif,
797
+        'uri_referer' => $uri_referer,
798
+        'file' => $copy ? $trans : '',
799
+        'follow_location' => false,
800
+    );
801
+    if (!is_null($taille_max)) {
802
+        $options['taille_max'] = $taille_max;
803
+    }
804
+    // dix tentatives maximum en cas d'entetes 301...
805
+    $res = recuperer_url($url, $options);
806
+
807
+    if (!$res) {
808
+        return false;
809
+    }
810
+    if ($res['status'] !== 200) {
811
+        return false;
812
+    }
813
+
814
+    return array($res['headers'], $res['page']);
815 815
 }
816 816
 
817 817
 /**
@@ -829,41 +829,41 @@  discard block
 block discarded – undo
829 829
  *   string contenu de la resource
830 830
  */
831 831
 function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') {
832
-	$taille = 0;
833
-	$result = '';
834
-	$fp = false;
835
-	if ($fichier) {
836
-		include_spip('inc/acces');
837
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
838
-		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
839
-		if (!$fp and file_exists($fichier)) {
840
-			return filesize($fichier);
841
-		}
842
-		if (!$fp) {
843
-			return false;
844
-		}
845
-		$result = 0; // on renvoie la taille du fichier
846
-	}
847
-	while (!feof($handle) and $taille < $taille_max) {
848
-		$res = fread($handle, 16384);
849
-		$taille += strlen($res);
850
-		if ($fp) {
851
-			fwrite($fp, $res);
852
-			$result = $taille;
853
-		} else {
854
-			$result .= $res;
855
-		}
856
-	}
857
-	if ($fp) {
858
-		spip_fclose_unlock($fp);
859
-		spip_unlink($fichier);
860
-		@rename($tmpfile, $fichier);
861
-		if (!file_exists($fichier)) {
862
-			return false;
863
-		}
864
-	}
865
-
866
-	return $result;
832
+    $taille = 0;
833
+    $result = '';
834
+    $fp = false;
835
+    if ($fichier) {
836
+        include_spip('inc/acces');
837
+        $tmpfile = "$fichier." . creer_uniqid() . '.tmp';
838
+        $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
839
+        if (!$fp and file_exists($fichier)) {
840
+            return filesize($fichier);
841
+        }
842
+        if (!$fp) {
843
+            return false;
844
+        }
845
+        $result = 0; // on renvoie la taille du fichier
846
+    }
847
+    while (!feof($handle) and $taille < $taille_max) {
848
+        $res = fread($handle, 16384);
849
+        $taille += strlen($res);
850
+        if ($fp) {
851
+            fwrite($fp, $res);
852
+            $result = $taille;
853
+        } else {
854
+            $result .= $res;
855
+        }
856
+    }
857
+    if ($fp) {
858
+        spip_fclose_unlock($fp);
859
+        spip_unlink($fichier);
860
+        @rename($tmpfile, $fichier);
861
+        if (!file_exists($fichier)) {
862
+            return false;
863
+        }
864
+    }
865
+
866
+    return $result;
867 867
 }
868 868
 
869 869
 /**
@@ -885,34 +885,34 @@  discard block
 block discarded – undo
885 885
  *   string location
886 886
  */
887 887
 function recuperer_entetes_complets($handle, $if_modified_since = false) {
888
-	$result = array('status' => 0, 'headers' => array(), 'last_modified' => 0, 'location' => '');
889
-
890
-	$s = @trim(fgets($handle, 16384));
891
-	if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
892
-		return false;
893
-	}
894
-	$result['status'] = intval($r[1]);
895
-	while ($s = trim(fgets($handle, 16384))) {
896
-		$result['headers'][] = $s . "\n";
897
-		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
898
-		list(, $d, $v) = $r;
899
-		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
900
-			$result['location'] = $v;
901
-		} elseif ($d == 'Last-Modified') {
902
-			$result['last_modified'] = strtotime($v);
903
-		}
904
-	}
905
-	if ($if_modified_since
906
-		and $result['last_modified']
907
-		and $if_modified_since > $result['last_modified']
908
-		and $result['status'] == 200
909
-	) {
910
-		$result['status'] = 304;
911
-	}
912
-
913
-	$result['headers'] = implode('', $result['headers']);
914
-
915
-	return $result;
888
+    $result = array('status' => 0, 'headers' => array(), 'last_modified' => 0, 'location' => '');
889
+
890
+    $s = @trim(fgets($handle, 16384));
891
+    if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
892
+        return false;
893
+    }
894
+    $result['status'] = intval($r[1]);
895
+    while ($s = trim(fgets($handle, 16384))) {
896
+        $result['headers'][] = $s . "\n";
897
+        preg_match(',^([^:]*): *(.*)$,i', $s, $r);
898
+        list(, $d, $v) = $r;
899
+        if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
900
+            $result['location'] = $v;
901
+        } elseif ($d == 'Last-Modified') {
902
+            $result['last_modified'] = strtotime($v);
903
+        }
904
+    }
905
+    if ($if_modified_since
906
+        and $result['last_modified']
907
+        and $if_modified_since > $result['last_modified']
908
+        and $result['status'] == 200
909
+    ) {
910
+        $result['status'] = 304;
911
+    }
912
+
913
+    $result['headers'] = implode('', $result['headers']);
914
+
915
+    return $result;
916 916
 }
917 917
 
918 918
 /**
@@ -934,20 +934,20 @@  discard block
 block discarded – undo
934 934
  *     - le tableau des entetes dans tous les autres cas
935 935
  **/
936 936
 function recuperer_entetes($f, $date_verif = '') {
937
-	//Cas ou la page distante n'a pas bouge depuis
938
-	//la derniere visite
939
-	$res = recuperer_entetes_complets($f, $date_verif);
940
-	if (!$res) {
941
-		return false;
942
-	}
943
-	if ($res['location']) {
944
-		return $res['location'];
945
-	}
946
-	if ($res['status'] != 200) {
947
-		return $res['status'];
948
-	}
949
-
950
-	return explode("\n", $res['headers']);
937
+    //Cas ou la page distante n'a pas bouge depuis
938
+    //la derniere visite
939
+    $res = recuperer_entetes_complets($f, $date_verif);
940
+    if (!$res) {
941
+        return false;
942
+    }
943
+    if ($res['location']) {
944
+        return $res['location'];
945
+    }
946
+    if ($res['status'] != 200) {
947
+        return $res['status'];
948
+    }
949
+
950
+    return explode("\n", $res['headers']);
951 951
 }
952 952
 
953 953
 /**
@@ -969,22 +969,22 @@  discard block
 block discarded – undo
969 969
  *     Nom du fichier pour copie locale
970 970
  **/
971 971
 function nom_fichier_copie_locale($source, $extension) {
972
-	include_spip('inc/documents');
972
+    include_spip('inc/documents');
973 973
 
974
-	$d = creer_repertoire_documents('distant'); # IMG/distant/
975
-	$d = sous_repertoire($d, $extension); # IMG/distant/pdf/
974
+    $d = creer_repertoire_documents('distant'); # IMG/distant/
975
+    $d = sous_repertoire($d, $extension); # IMG/distant/pdf/
976 976
 
977
-	// on se place tout le temps comme si on etait a la racine
978
-	if (_DIR_RACINE) {
979
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
980
-	}
977
+    // on se place tout le temps comme si on etait a la racine
978
+    if (_DIR_RACINE) {
979
+        $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
980
+    }
981 981
 
982
-	$m = md5($source);
982
+    $m = md5($source);
983 983
 
984
-	return $d
985
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
986
-	. substr($m, 0, 4)
987
-	. ".$extension";
984
+    return $d
985
+    . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
986
+    . substr($m, 0, 4)
987
+    . ".$extension";
988 988
 }
989 989
 
990 990
 /**
@@ -1002,68 +1002,68 @@  discard block
 block discarded – undo
1002 1002
  *      Nom du fichier calculé
1003 1003
  **/
1004 1004
 function fichier_copie_locale($source) {
1005
-	// Si c'est deja local pas de souci
1006
-	if (!tester_url_absolue($source)) {
1007
-		if (_DIR_RACINE) {
1008
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
1009
-		}
1010
-
1011
-		return $source;
1012
-	}
1013
-
1014
-	// optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
1015
-	// a deja ete copie en local avec cette extension
1016
-	// dans ce cas elle est fiable, pas la peine de requeter en base
1017
-	$path_parts = pathinfo($source);
1018
-	if (!isset($path_parts['extension'])) {
1019
-		$path_parts['extension'] = '';
1020
-	}
1021
-	$ext = $path_parts ? $path_parts['extension'] : '';
1022
-	if ($ext
1023
-		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
1024
-		and $f = nom_fichier_copie_locale($source, $ext)
1025
-		and file_exists(_DIR_RACINE . $f)
1026
-	) {
1027
-		return $f;
1028
-	}
1029
-
1030
-
1031
-	// Si c'est deja dans la table des documents,
1032
-	// ramener le nom de sa copie potentielle
1033
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
1034
-
1035
-	if ($ext) {
1036
-		return nom_fichier_copie_locale($source, $ext);
1037
-	}
1038
-
1039
-	// voir si l'extension indiquee dans le nom du fichier est ok
1040
-	// et si il n'aurait pas deja ete rapatrie
1041
-
1042
-	$ext = $path_parts ? $path_parts['extension'] : '';
1043
-
1044
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1045
-		$f = nom_fichier_copie_locale($source, $ext);
1046
-		if (file_exists(_DIR_RACINE . $f)) {
1047
-			return $f;
1048
-		}
1049
-	}
1050
-
1051
-	// Ping  pour voir si son extension est connue et autorisee
1052
-	// avec mise en cache du resultat du ping
1053
-
1054
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
1055
-	if (!@file_exists($cache)
1056
-		or !$path_parts = @unserialize(spip_file_get_contents($cache))
1057
-		or _request('var_mode') == 'recalcul'
1058
-	) {
1059
-		$path_parts = recuperer_infos_distantes($source, 0, false);
1060
-		ecrire_fichier($cache, serialize($path_parts));
1061
-	}
1062
-	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
1063
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1064
-		return nom_fichier_copie_locale($source, $ext);
1065
-	}
1066
-	spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
1005
+    // Si c'est deja local pas de souci
1006
+    if (!tester_url_absolue($source)) {
1007
+        if (_DIR_RACINE) {
1008
+            $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
1009
+        }
1010
+
1011
+        return $source;
1012
+    }
1013
+
1014
+    // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
1015
+    // a deja ete copie en local avec cette extension
1016
+    // dans ce cas elle est fiable, pas la peine de requeter en base
1017
+    $path_parts = pathinfo($source);
1018
+    if (!isset($path_parts['extension'])) {
1019
+        $path_parts['extension'] = '';
1020
+    }
1021
+    $ext = $path_parts ? $path_parts['extension'] : '';
1022
+    if ($ext
1023
+        and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
1024
+        and $f = nom_fichier_copie_locale($source, $ext)
1025
+        and file_exists(_DIR_RACINE . $f)
1026
+    ) {
1027
+        return $f;
1028
+    }
1029
+
1030
+
1031
+    // Si c'est deja dans la table des documents,
1032
+    // ramener le nom de sa copie potentielle
1033
+    $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
1034
+
1035
+    if ($ext) {
1036
+        return nom_fichier_copie_locale($source, $ext);
1037
+    }
1038
+
1039
+    // voir si l'extension indiquee dans le nom du fichier est ok
1040
+    // et si il n'aurait pas deja ete rapatrie
1041
+
1042
+    $ext = $path_parts ? $path_parts['extension'] : '';
1043
+
1044
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1045
+        $f = nom_fichier_copie_locale($source, $ext);
1046
+        if (file_exists(_DIR_RACINE . $f)) {
1047
+            return $f;
1048
+        }
1049
+    }
1050
+
1051
+    // Ping  pour voir si son extension est connue et autorisee
1052
+    // avec mise en cache du resultat du ping
1053
+
1054
+    $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
1055
+    if (!@file_exists($cache)
1056
+        or !$path_parts = @unserialize(spip_file_get_contents($cache))
1057
+        or _request('var_mode') == 'recalcul'
1058
+    ) {
1059
+        $path_parts = recuperer_infos_distantes($source, 0, false);
1060
+        ecrire_fichier($cache, serialize($path_parts));
1061
+    }
1062
+    $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
1063
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1064
+        return nom_fichier_copie_locale($source, $ext);
1065
+    }
1066
+    spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
1067 1067
 }
1068 1068
 
1069 1069
 
@@ -1091,144 +1091,144 @@  discard block
 block discarded – undo
1091 1091
  **/
1092 1092
 function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true) {
1093 1093
 
1094
-	// pas la peine de perdre son temps
1095
-	if (!tester_url_absolue($source)) {
1096
-		return false;
1097
-	}
1098
-
1099
-	# charger les alias des types mime
1100
-	include_spip('base/typedoc');
1101
-
1102
-	$a = array();
1103
-	$mime_type = '';
1104
-	// On va directement charger le debut des images et des fichiers html,
1105
-	// de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
1106
-	// ca echoue l'utilisateur devra les entrer...
1107
-	if ($headers = recuperer_page($source, false, true, $max, '', '', true)) {
1108
-		list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2);
1109
-
1110
-		if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1111
-			$mime_type = (trim($regs[1]));
1112
-		} else {
1113
-			$mime_type = '';
1114
-		} // inconnu
1115
-
1116
-		// Appliquer les alias
1117
-		while (isset($GLOBALS['mime_alias'][$mime_type])) {
1118
-			$mime_type = $GLOBALS['mime_alias'][$mime_type];
1119
-		}
1120
-
1121
-		// Si on a un mime-type insignifiant
1122
-		// text/plain,application/octet-stream ou vide
1123
-		// c'est peut-etre que le serveur ne sait pas
1124
-		// ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1125
-		// ou le Content-Disposition: attachment; filename=...
1126
-		$t = null;
1127
-		if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) {
1128
-			if (!$t
1129
-				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1130
-			) {
1131
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1132
-			}
1133
-			if (!$t
1134
-				and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1135
-				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1136
-			) {
1137
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1138
-			}
1139
-		}
1140
-
1141
-		// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1142
-		if (!$t) {
1143
-			$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1144
-		}
1145
-
1146
-		// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1147
-		// On essaie de nouveau avec l'extension
1148
-		if (!$t
1149
-			and $mime_type != 'text/plain'
1150
-			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1151
-		) {
1152
-			# eviter xxx.3 => 3gp (> SPIP 3)
1153
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1154
-		}
1155
-
1156
-		if ($t) {
1157
-			spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1158
-			$a['extension'] = $t['extension'];
1159
-		} else {
1160
-			# par defaut on retombe sur '.bin' si c'est autorise
1161
-			spip_log("mime-type $mime_type inconnu", 'distant');
1162
-			$t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1163
-			if (!$t) {
1164
-				return false;
1165
-			}
1166
-			$a['extension'] = $t['extension'];
1167
-		}
1168
-
1169
-		if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
1170
-			$a['taille'] = intval($regs[1]);
1171
-		}
1172
-	}
1173
-
1174
-	// Echec avec HEAD, on tente avec GET
1175
-	if (!$a and !$max) {
1176
-		spip_log("tenter GET $source", 'distant');
1177
-		$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1178
-	}
1179
-
1180
-	// si on a rien trouve pas la peine d'insister
1181
-	if (!$a) {
1182
-		return false;
1183
-	}
1184
-
1185
-	// S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1186
-	// recharger le document en GET et recuperer des donnees supplementaires...
1187
-	include_spip('inc/filtres_images_lib_mini');
1188
-	if (strpos($mime_type, "image/") === 0
1189
-	  and $extension = _image_trouver_extension_depuis_mime($mime_type)) {
1190
-		if ($max == 0
1191
-			and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1192
-			and in_array($extension, formats_image_acceptables())
1193
-			and $charger_si_petite_image
1194
-		) {
1195
-			$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1196
-		} else {
1197
-			if ($a['body']) {
1198
-				$a['extension'] = $extension;
1199
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1200
-				ecrire_fichier($a['fichier'], $a['body']);
1201
-				$size_image = @spip_getimagesize($a['fichier']);
1202
-				$a['largeur'] = intval($size_image[0]);
1203
-				$a['hauteur'] = intval($size_image[1]);
1204
-				$a['type_image'] = true;
1205
-			}
1206
-		}
1207
-	}
1208
-
1209
-	// Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1210
-	// ce sera mieux que 0x0
1211
-	// Flash is dead!
1212
-	if ($a and isset($a['extension']) and $a['extension'] == 'swf'
1213
-		and empty($a['largeur'])
1214
-	) {
1215
-		$a['largeur'] = 425;
1216
-		$a['hauteur'] = 350;
1217
-	}
1218
-
1219
-	if ($mime_type == 'text/html') {
1220
-		include_spip('inc/filtres');
1221
-		$page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE);
1222
-		if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1223
-			$a['titre'] = corriger_caracteres(trim($regs[1]));
1224
-		}
1225
-		if (!isset($a['taille']) or !$a['taille']) {
1226
-			$a['taille'] = strlen($page); # a peu pres
1227
-		}
1228
-	}
1229
-	$a['mime_type'] = $mime_type;
1230
-
1231
-	return $a;
1094
+    // pas la peine de perdre son temps
1095
+    if (!tester_url_absolue($source)) {
1096
+        return false;
1097
+    }
1098
+
1099
+    # charger les alias des types mime
1100
+    include_spip('base/typedoc');
1101
+
1102
+    $a = array();
1103
+    $mime_type = '';
1104
+    // On va directement charger le debut des images et des fichiers html,
1105
+    // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
1106
+    // ca echoue l'utilisateur devra les entrer...
1107
+    if ($headers = recuperer_page($source, false, true, $max, '', '', true)) {
1108
+        list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2);
1109
+
1110
+        if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1111
+            $mime_type = (trim($regs[1]));
1112
+        } else {
1113
+            $mime_type = '';
1114
+        } // inconnu
1115
+
1116
+        // Appliquer les alias
1117
+        while (isset($GLOBALS['mime_alias'][$mime_type])) {
1118
+            $mime_type = $GLOBALS['mime_alias'][$mime_type];
1119
+        }
1120
+
1121
+        // Si on a un mime-type insignifiant
1122
+        // text/plain,application/octet-stream ou vide
1123
+        // c'est peut-etre que le serveur ne sait pas
1124
+        // ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1125
+        // ou le Content-Disposition: attachment; filename=...
1126
+        $t = null;
1127
+        if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) {
1128
+            if (!$t
1129
+                and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1130
+            ) {
1131
+                $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1132
+            }
1133
+            if (!$t
1134
+                and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1135
+                and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1136
+            ) {
1137
+                $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1138
+            }
1139
+        }
1140
+
1141
+        // Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1142
+        if (!$t) {
1143
+            $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1144
+        }
1145
+
1146
+        // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1147
+        // On essaie de nouveau avec l'extension
1148
+        if (!$t
1149
+            and $mime_type != 'text/plain'
1150
+            and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1151
+        ) {
1152
+            # eviter xxx.3 => 3gp (> SPIP 3)
1153
+            $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1154
+        }
1155
+
1156
+        if ($t) {
1157
+            spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1158
+            $a['extension'] = $t['extension'];
1159
+        } else {
1160
+            # par defaut on retombe sur '.bin' si c'est autorise
1161
+            spip_log("mime-type $mime_type inconnu", 'distant');
1162
+            $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1163
+            if (!$t) {
1164
+                return false;
1165
+            }
1166
+            $a['extension'] = $t['extension'];
1167
+        }
1168
+
1169
+        if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
1170
+            $a['taille'] = intval($regs[1]);
1171
+        }
1172
+    }
1173
+
1174
+    // Echec avec HEAD, on tente avec GET
1175
+    if (!$a and !$max) {
1176
+        spip_log("tenter GET $source", 'distant');
1177
+        $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1178
+    }
1179
+
1180
+    // si on a rien trouve pas la peine d'insister
1181
+    if (!$a) {
1182
+        return false;
1183
+    }
1184
+
1185
+    // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1186
+    // recharger le document en GET et recuperer des donnees supplementaires...
1187
+    include_spip('inc/filtres_images_lib_mini');
1188
+    if (strpos($mime_type, "image/") === 0
1189
+      and $extension = _image_trouver_extension_depuis_mime($mime_type)) {
1190
+        if ($max == 0
1191
+            and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1192
+            and in_array($extension, formats_image_acceptables())
1193
+            and $charger_si_petite_image
1194
+        ) {
1195
+            $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1196
+        } else {
1197
+            if ($a['body']) {
1198
+                $a['extension'] = $extension;
1199
+                $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1200
+                ecrire_fichier($a['fichier'], $a['body']);
1201
+                $size_image = @spip_getimagesize($a['fichier']);
1202
+                $a['largeur'] = intval($size_image[0]);
1203
+                $a['hauteur'] = intval($size_image[1]);
1204
+                $a['type_image'] = true;
1205
+            }
1206
+        }
1207
+    }
1208
+
1209
+    // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1210
+    // ce sera mieux que 0x0
1211
+    // Flash is dead!
1212
+    if ($a and isset($a['extension']) and $a['extension'] == 'swf'
1213
+        and empty($a['largeur'])
1214
+    ) {
1215
+        $a['largeur'] = 425;
1216
+        $a['hauteur'] = 350;
1217
+    }
1218
+
1219
+    if ($mime_type == 'text/html') {
1220
+        include_spip('inc/filtres');
1221
+        $page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE);
1222
+        if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1223
+            $a['titre'] = corriger_caracteres(trim($regs[1]));
1224
+        }
1225
+        if (!isset($a['taille']) or !$a['taille']) {
1226
+            $a['taille'] = strlen($page); # a peu pres
1227
+        }
1228
+    }
1229
+    $a['mime_type'] = $mime_type;
1230
+
1231
+    return $a;
1232 1232
 }
1233 1233
 
1234 1234
 
@@ -1244,45 +1244,45 @@  discard block
 block discarded – undo
1244 1244
  * @return string
1245 1245
  */
1246 1246
 function need_proxy($host, $http_proxy = null, $http_noproxy = null) {
1247
-	if (is_null($http_proxy)) {
1248
-		$http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null;
1249
-	}
1250
-	// rien a faire si pas de proxy :)
1251
-	if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1252
-		return '';
1253
-	}
1254
-
1255
-	if (is_null($http_noproxy)) {
1256
-		$http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null;
1257
-	}
1258
-	// si pas d'exception, on retourne le proxy
1259
-	if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1260
-		return $http_proxy;
1261
-	}
1262
-
1263
-	// si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1264
-	// $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1265
-	$http_noproxy = str_replace("\n", " ", $http_noproxy);
1266
-	$http_noproxy = str_replace("\r", " ", $http_noproxy);
1267
-	$http_noproxy = " $http_noproxy ";
1268
-	$domain = $host;
1269
-	// si le domaine exact www.example.org est dans les exceptions
1270
-	if (strpos($http_noproxy, " $domain ") !== false)
1271
-		return '';
1272
-
1273
-	while (strpos($domain, '.') !== false) {
1274
-		$domain = explode('.', $domain);
1275
-		array_shift($domain);
1276
-		$domain = implode('.', $domain);
1277
-
1278
-		// ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1279
-		if (strpos($http_noproxy, " .$domain ") !== false) {
1280
-			return '';
1281
-		}
1282
-	}
1283
-
1284
-	// ok c'est pas une exception
1285
-	return $http_proxy;
1247
+    if (is_null($http_proxy)) {
1248
+        $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null;
1249
+    }
1250
+    // rien a faire si pas de proxy :)
1251
+    if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1252
+        return '';
1253
+    }
1254
+
1255
+    if (is_null($http_noproxy)) {
1256
+        $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null;
1257
+    }
1258
+    // si pas d'exception, on retourne le proxy
1259
+    if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1260
+        return $http_proxy;
1261
+    }
1262
+
1263
+    // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1264
+    // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1265
+    $http_noproxy = str_replace("\n", " ", $http_noproxy);
1266
+    $http_noproxy = str_replace("\r", " ", $http_noproxy);
1267
+    $http_noproxy = " $http_noproxy ";
1268
+    $domain = $host;
1269
+    // si le domaine exact www.example.org est dans les exceptions
1270
+    if (strpos($http_noproxy, " $domain ") !== false)
1271
+        return '';
1272
+
1273
+    while (strpos($domain, '.') !== false) {
1274
+        $domain = explode('.', $domain);
1275
+        array_shift($domain);
1276
+        $domain = implode('.', $domain);
1277
+
1278
+        // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1279
+        if (strpos($http_noproxy, " .$domain ") !== false) {
1280
+            return '';
1281
+        }
1282
+    }
1283
+
1284
+    // ok c'est pas une exception
1285
+    return $http_proxy;
1286 1286
 }
1287 1287
 
1288 1288
 
@@ -1305,58 +1305,58 @@  discard block
 block discarded – undo
1305 1305
  * @return array
1306 1306
  */
1307 1307
 function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') {
1308
-	$user = $via_proxy = $proxy_user = '';
1309
-	$fopen = false;
1310
-
1311
-	$t = @parse_url($url);
1312
-	$host = $t['host'];
1313
-	if ($t['scheme'] == 'http') {
1314
-		$scheme = 'http';
1315
-		$noproxy = '';
1316
-	} elseif ($t['scheme'] == 'https') {
1317
-		$scheme = 'ssl';
1318
-		$noproxy = 'ssl://';
1319
-		if (!isset($t['port']) || !($port = $t['port'])) {
1320
-			$t['port'] = 443;
1321
-		}
1322
-	} else {
1323
-		$scheme = $t['scheme'];
1324
-		$noproxy = $scheme . '://';
1325
-	}
1326
-	if (isset($t['user'])) {
1327
-		$user = array($t['user'], $t['pass']);
1328
-	}
1329
-
1330
-	if (!isset($t['port']) || !($port = $t['port'])) {
1331
-		$port = 80;
1332
-	}
1333
-	if (!isset($t['path']) || !($path = $t['path'])) {
1334
-		$path = '/';
1335
-	}
1336
-
1337
-	if (!empty($t['query'])) {
1338
-		$path .= '?' . $t['query'];
1339
-	}
1340
-
1341
-	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1342
-	if (!$f or !is_resource($f)) {
1343
-		// fallback : fopen si on a pas fait timeout dans lance_requete
1344
-		// ce qui correspond a $f===110
1345
-		if ($f !== 110
1346
-			and !need_proxy($host)
1347
-			and !_request('tester_proxy')
1348
-			and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1349
-		) {
1350
-			$f = @fopen($url, 'rb');
1351
-			spip_log("connexion vers $url par simple fopen", 'distant');
1352
-			$fopen = true;
1353
-		} else {
1354
-			// echec total
1355
-			$f = false;
1356
-		}
1357
-	}
1358
-
1359
-	return array($f, $fopen);
1308
+    $user = $via_proxy = $proxy_user = '';
1309
+    $fopen = false;
1310
+
1311
+    $t = @parse_url($url);
1312
+    $host = $t['host'];
1313
+    if ($t['scheme'] == 'http') {
1314
+        $scheme = 'http';
1315
+        $noproxy = '';
1316
+    } elseif ($t['scheme'] == 'https') {
1317
+        $scheme = 'ssl';
1318
+        $noproxy = 'ssl://';
1319
+        if (!isset($t['port']) || !($port = $t['port'])) {
1320
+            $t['port'] = 443;
1321
+        }
1322
+    } else {
1323
+        $scheme = $t['scheme'];
1324
+        $noproxy = $scheme . '://';
1325
+    }
1326
+    if (isset($t['user'])) {
1327
+        $user = array($t['user'], $t['pass']);
1328
+    }
1329
+
1330
+    if (!isset($t['port']) || !($port = $t['port'])) {
1331
+        $port = 80;
1332
+    }
1333
+    if (!isset($t['path']) || !($path = $t['path'])) {
1334
+        $path = '/';
1335
+    }
1336
+
1337
+    if (!empty($t['query'])) {
1338
+        $path .= '?' . $t['query'];
1339
+    }
1340
+
1341
+    $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1342
+    if (!$f or !is_resource($f)) {
1343
+        // fallback : fopen si on a pas fait timeout dans lance_requete
1344
+        // ce qui correspond a $f===110
1345
+        if ($f !== 110
1346
+            and !need_proxy($host)
1347
+            and !_request('tester_proxy')
1348
+            and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1349
+        ) {
1350
+            $f = @fopen($url, 'rb');
1351
+            spip_log("connexion vers $url par simple fopen", 'distant');
1352
+            $fopen = true;
1353
+        } else {
1354
+            // echec total
1355
+            $f = false;
1356
+        }
1357
+    }
1358
+
1359
+    return array($f, $fopen);
1360 1360
 }
1361 1361
 
1362 1362
 /**
@@ -1391,124 +1391,124 @@  discard block
 block discarded – undo
1391 1391
  *   resource socket vers l'url demandee
1392 1392
  */
1393 1393
 function lance_requete(
1394
-	$method,
1395
-	$scheme,
1396
-	$user,
1397
-	$host,
1398
-	$path,
1399
-	$port,
1400
-	$noproxy,
1401
-	$refuse_gz = false,
1402
-	$referer = '',
1403
-	$datas = '',
1404
-	$vers = 'HTTP/1.0',
1405
-	$date = ''
1394
+    $method,
1395
+    $scheme,
1396
+    $user,
1397
+    $host,
1398
+    $path,
1399
+    $port,
1400
+    $noproxy,
1401
+    $refuse_gz = false,
1402
+    $referer = '',
1403
+    $datas = '',
1404
+    $vers = 'HTTP/1.0',
1405
+    $date = ''
1406 1406
 ) {
1407 1407
 
1408
-	$proxy_user = '';
1409
-	$http_proxy = need_proxy($host);
1410
-	if ($user) {
1411
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1412
-	}
1413
-
1414
-	$connect = '';
1415
-	if ($http_proxy) {
1416
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) {
1417
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1418
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1419
-				. "Host: $path_host\r\n"
1420
-				. "Proxy-Connection: Keep-Alive\r\n";
1421
-		} else {
1422
-			$path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://")
1423
-				. (!$user ? '' : "$user@")
1424
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1425
-		}
1426
-		$t2 = @parse_url($http_proxy);
1427
-		$first_host = $t2['host'];
1428
-		if (!($port = $t2['port'])) {
1429
-			$port = 80;
1430
-		}
1431
-		if ($t2['user']) {
1432
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1433
-		}
1434
-	} else {
1435
-		$first_host = $noproxy . $host;
1436
-	}
1437
-
1438
-	if ($connect) {
1439
-		$streamContext = stream_context_create(array(
1440
-			'ssl' => array(
1441
-				'verify_peer' => false,
1442
-				'allow_self_signed' => true,
1443
-				'SNI_enabled' => true,
1444
-				'peer_name' => $host,
1445
-			)
1446
-		));
1447
-		$f = @stream_socket_client(
1448
-			"tcp://$first_host:$port",
1449
-			$errno,
1450
-			$errstr,
1451
-			_INC_DISTANT_CONNECT_TIMEOUT,
1452
-			STREAM_CLIENT_CONNECT,
1453
-			$streamContext
1454
-		);
1455
-		spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1456
-		if (!$f) {
1457
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1458
-			return $errno;
1459
-		}
1460
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1461
-
1462
-		fputs($f, $connect);
1463
-		fputs($f, "\r\n");
1464
-		$res = fread($f, 1024);
1465
-		if (!$res
1466
-			or !count($res = explode(' ', $res))
1467
-			or $res[1] !== '200'
1468
-		) {
1469
-			spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1470
-			fclose($f);
1471
-
1472
-			return false;
1473
-		}
1474
-		// important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1475
-		stream_set_blocking($f, true);
1476
-		// envoyer le handshake
1477
-		stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1478
-		spip_log("OK CONNECT sur $first_host:$port", 'connect');
1479
-	} else {
1480
-		$ntry = 3;
1481
-		do {
1482
-			$f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1483
-		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1484
-		spip_log("Recuperer $path sur $first_host:$port par $f");
1485
-		if (!$f) {
1486
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1487
-
1488
-			return $errno;
1489
-		}
1490
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1491
-	}
1492
-
1493
-	$site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1494
-
1495
-	$host_port = $host;
1496
-	if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) {
1497
-		$host_port .= ":$port";
1498
-	}
1499
-	$req = "$method $path $vers\r\n"
1500
-		. "Host: $host_port\r\n"
1501
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1502
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1503
-		. (!$site ? '' : "Referer: $site/$referer\r\n")
1504
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1505
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1506
-		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1507
-		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1408
+    $proxy_user = '';
1409
+    $http_proxy = need_proxy($host);
1410
+    if ($user) {
1411
+        $user = urlencode($user[0]) . ':' . urlencode($user[1]);
1412
+    }
1413
+
1414
+    $connect = '';
1415
+    if ($http_proxy) {
1416
+        if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) {
1417
+            $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1418
+            $connect = 'CONNECT ' . $path_host . " $vers\r\n"
1419
+                . "Host: $path_host\r\n"
1420
+                . "Proxy-Connection: Keep-Alive\r\n";
1421
+        } else {
1422
+            $path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://")
1423
+                . (!$user ? '' : "$user@")
1424
+                . "$host" . (($port != 80) ? ":$port" : '') . $path;
1425
+        }
1426
+        $t2 = @parse_url($http_proxy);
1427
+        $first_host = $t2['host'];
1428
+        if (!($port = $t2['port'])) {
1429
+            $port = 80;
1430
+        }
1431
+        if ($t2['user']) {
1432
+            $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1433
+        }
1434
+    } else {
1435
+        $first_host = $noproxy . $host;
1436
+    }
1437
+
1438
+    if ($connect) {
1439
+        $streamContext = stream_context_create(array(
1440
+            'ssl' => array(
1441
+                'verify_peer' => false,
1442
+                'allow_self_signed' => true,
1443
+                'SNI_enabled' => true,
1444
+                'peer_name' => $host,
1445
+            )
1446
+        ));
1447
+        $f = @stream_socket_client(
1448
+            "tcp://$first_host:$port",
1449
+            $errno,
1450
+            $errstr,
1451
+            _INC_DISTANT_CONNECT_TIMEOUT,
1452
+            STREAM_CLIENT_CONNECT,
1453
+            $streamContext
1454
+        );
1455
+        spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1456
+        if (!$f) {
1457
+            spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1458
+            return $errno;
1459
+        }
1460
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1461
+
1462
+        fputs($f, $connect);
1463
+        fputs($f, "\r\n");
1464
+        $res = fread($f, 1024);
1465
+        if (!$res
1466
+            or !count($res = explode(' ', $res))
1467
+            or $res[1] !== '200'
1468
+        ) {
1469
+            spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1470
+            fclose($f);
1471
+
1472
+            return false;
1473
+        }
1474
+        // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1475
+        stream_set_blocking($f, true);
1476
+        // envoyer le handshake
1477
+        stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1478
+        spip_log("OK CONNECT sur $first_host:$port", 'connect');
1479
+    } else {
1480
+        $ntry = 3;
1481
+        do {
1482
+            $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1483
+        } while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1484
+        spip_log("Recuperer $path sur $first_host:$port par $f");
1485
+        if (!$f) {
1486
+            spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1487
+
1488
+            return $errno;
1489
+        }
1490
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1491
+    }
1492
+
1493
+    $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1494
+
1495
+    $host_port = $host;
1496
+    if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) {
1497
+        $host_port .= ":$port";
1498
+    }
1499
+    $req = "$method $path $vers\r\n"
1500
+        . "Host: $host_port\r\n"
1501
+        . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1502
+        . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1503
+        . (!$site ? '' : "Referer: $site/$referer\r\n")
1504
+        . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1505
+        . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1506
+        . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1507
+        . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1508 1508
 
1509 1509
 #	spip_log("Requete\n$req", 'distant');
1510
-	fputs($f, $req);
1511
-	fputs($f, $datas ? $datas : "\r\n");
1510
+    fputs($f, $req);
1511
+    fputs($f, $datas ? $datas : "\r\n");
1512 1512
 
1513
-	return $f;
1513
+    return $f;
1514 1514
 }
Please login to merge, or discard this patch.
ecrire/inc/editer.php 4 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
  * utile pour les textes > 32ko
315 315
  *
316 316
  * @param  string $texte
317
- * @return array
317
+ * @return string[]
318 318
  */
319 319
 function coupe_trop_long($texte) {
320 320
 	$aider = charger_fonction('aider', 'inc');
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
  *
348 348
  * @param string $texte
349 349
  * @param string $att_text
350
- * @return array
350
+ * @return string[]
351 351
  */
352 352
 function editer_texte_recolle($texte, $att_text) {
353 353
 	if ((strlen($texte) < 29 * 1024)
@@ -373,8 +373,8 @@  discard block
 block discarded – undo
373 373
 /**
374 374
  * auto-renseigner le titre si il n'existe pas
375 375
  *
376
- * @param $champ_titre
377
- * @param $champs_contenu
376
+ * @param string $champ_titre
377
+ * @param string[] $champs_contenu
378 378
  * @param int $longueur
379 379
  */
380 380
 function titre_automatique($champ_titre, $champs_contenu, $longueur = null) {
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -329,8 +329,7 @@
 block discarded – undo
329 329
 		if (!autoriser('modifier', $type, intval($id))){
330 330
 			$valeurs['editable'] = '';
331 331
 		}
332
-	}
333
-	else {
332
+	} else {
334 333
 		if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) {
335 334
 			$valeurs['editable'] = '';
336 335
 		}
Please login to merge, or discard this patch.
Indentation   +486 added lines, -486 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('base/abstract_sql');
23 23
 
@@ -59,56 +59,56 @@  discard block
 block discarded – undo
59 59
  *     Retour des traitements.
60 60
  **/
61 61
 function formulaires_editer_objet_traiter(
62
-	$type,
63
-	$id = 'new',
64
-	$id_parent = 0,
65
-	$lier_trad = 0,
66
-	$retour = '',
67
-	$config_fonc = 'articles_edit_config',
68
-	$row = array(),
69
-	$hidden = ''
62
+    $type,
63
+    $id = 'new',
64
+    $id_parent = 0,
65
+    $lier_trad = 0,
66
+    $retour = '',
67
+    $config_fonc = 'articles_edit_config',
68
+    $row = array(),
69
+    $hidden = ''
70 70
 ) {
71 71
 
72
-	$res = array();
73
-	// eviter la redirection forcee par l'action...
74
-	set_request('redirect');
75
-	if ($action_editer = charger_fonction("editer_$type", 'action', true)) {
76
-		list($id, $err) = $action_editer($id);
77
-	} else {
78
-		$action_editer = charger_fonction('editer_objet', 'action');
79
-		list($id, $err) = $action_editer($id, $type);
80
-	}
81
-	$id_table_objet = id_table_objet($type);
82
-	$res[$id_table_objet] = $id;
83
-	if ($err or !$id) {
84
-		$res['message_erreur'] = ($err ? $err : _T('erreur'));
85
-	} else {
86
-		// Un lien de trad a prendre en compte
87
-		if ($lier_trad) {
88
-			// referencer la traduction
89
-			$referencer_traduction = charger_fonction('referencer_traduction', 'action');
90
-			$referencer_traduction($type, $id, $lier_trad);
91
-			// actions de recopie de champs / liens sur le nouvel objet créé
92
-			$completer_traduction = charger_fonction('completer_traduction', 'inc');
93
-			$err = $completer_traduction($type, $id, $lier_trad);
94
-			if ($err) {
95
-				$res['message_erreur'] = $err;
96
-				return $res;
97
-			}
98
-		}
99
-
100
-		$res['message_ok'] = _T('info_modification_enregistree');
101
-		if ($retour) {
102
-			if (strncmp($retour, 'javascript:', 11) == 0) {
103
-				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
104
-				$res['editable'] = true;
105
-			} else {
106
-				$res['redirect'] = parametre_url($retour, $id_table_objet, $id);
107
-			}
108
-		}
109
-	}
110
-
111
-	return $res;
72
+    $res = array();
73
+    // eviter la redirection forcee par l'action...
74
+    set_request('redirect');
75
+    if ($action_editer = charger_fonction("editer_$type", 'action', true)) {
76
+        list($id, $err) = $action_editer($id);
77
+    } else {
78
+        $action_editer = charger_fonction('editer_objet', 'action');
79
+        list($id, $err) = $action_editer($id, $type);
80
+    }
81
+    $id_table_objet = id_table_objet($type);
82
+    $res[$id_table_objet] = $id;
83
+    if ($err or !$id) {
84
+        $res['message_erreur'] = ($err ? $err : _T('erreur'));
85
+    } else {
86
+        // Un lien de trad a prendre en compte
87
+        if ($lier_trad) {
88
+            // referencer la traduction
89
+            $referencer_traduction = charger_fonction('referencer_traduction', 'action');
90
+            $referencer_traduction($type, $id, $lier_trad);
91
+            // actions de recopie de champs / liens sur le nouvel objet créé
92
+            $completer_traduction = charger_fonction('completer_traduction', 'inc');
93
+            $err = $completer_traduction($type, $id, $lier_trad);
94
+            if ($err) {
95
+                $res['message_erreur'] = $err;
96
+                return $res;
97
+            }
98
+        }
99
+
100
+        $res['message_ok'] = _T('info_modification_enregistree');
101
+        if ($retour) {
102
+            if (strncmp($retour, 'javascript:', 11) == 0) {
103
+                $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
104
+                $res['editable'] = true;
105
+            } else {
106
+                $res['redirect'] = parametre_url($retour, $id_table_objet, $id);
107
+            }
108
+        }
109
+    }
110
+
111
+    return $res;
112 112
 }
113 113
 
114 114
 /**
@@ -132,29 +132,29 @@  discard block
 block discarded – undo
132 132
  *     Tableau des erreurs
133 133
  **/
134 134
 function formulaires_editer_objet_verifier($type, $id = 'new', $oblis = array()) {
135
-	$erreurs = array();
136
-	if (intval($id)) {
137
-		$conflits = controler_contenu($type, $id);
138
-		if ($conflits and count($conflits)) {
139
-			foreach ($conflits as $champ => $conflit) {
140
-				if (!isset($erreurs[$champ])) {
141
-					$erreurs[$champ] = '';
142
-				}
143
-				$erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>';
144
-			}
145
-		}
146
-	}
147
-	foreach ($oblis as $obli) {
148
-		$value = _request($obli);
149
-		if (is_null($value) or !(is_array($value) ? count($value) : strlen($value))) {
150
-			if (!isset($erreurs[$obli])) {
151
-				$erreurs[$obli] = '';
152
-			}
153
-			$erreurs[$obli] .= _T('info_obligatoire');
154
-		}
155
-	}
156
-
157
-	return $erreurs;
135
+    $erreurs = array();
136
+    if (intval($id)) {
137
+        $conflits = controler_contenu($type, $id);
138
+        if ($conflits and count($conflits)) {
139
+            foreach ($conflits as $champ => $conflit) {
140
+                if (!isset($erreurs[$champ])) {
141
+                    $erreurs[$champ] = '';
142
+                }
143
+                $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>';
144
+            }
145
+        }
146
+    }
147
+    foreach ($oblis as $obli) {
148
+        $value = _request($obli);
149
+        if (is_null($value) or !(is_array($value) ? count($value) : strlen($value))) {
150
+            if (!isset($erreurs[$obli])) {
151
+                $erreurs[$obli] = '';
152
+            }
153
+            $erreurs[$obli] .= _T('info_obligatoire');
154
+        }
155
+    }
156
+
157
+    return $erreurs;
158 158
 }
159 159
 
160 160
 /**
@@ -198,145 +198,145 @@  discard block
 block discarded – undo
198 198
  *     Environnement du formulaire.
199 199
  **/
200 200
 function formulaires_editer_objet_charger(
201
-	$type,
202
-	$id = 'new',
203
-	$id_parent = 0,
204
-	$lier_trad = 0,
205
-	$retour = '',
206
-	$config_fonc = 'articles_edit_config',
207
-	$row = array(),
208
-	$hidden = ''
201
+    $type,
202
+    $id = 'new',
203
+    $id_parent = 0,
204
+    $lier_trad = 0,
205
+    $retour = '',
206
+    $config_fonc = 'articles_edit_config',
207
+    $row = array(),
208
+    $hidden = ''
209 209
 ) {
210 210
 
211
-	$table_objet = table_objet($type);
212
-	$table_objet_sql = table_objet_sql($type);
213
-	$id_table_objet = id_table_objet($type);
214
-
215
-	// on accepte pas une fonction de config inconnue si elle vient d'un modele
216
-	if ($config_fonc
217
-	  and !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config'])
218
-	  and $config_fonc !== $table_objet . '_edit_config') {
219
-		if ($args = test_formulaire_inclus_par_modele()
220
-		  and in_array($config_fonc, $args)) {
221
-			$config_fonc = '';
222
-		}
223
-	}
224
-
225
-	$new = !is_numeric($id);
226
-	$lang_default = '';
227
-	// Appel direct dans un squelette
228
-	if (!$row) {
229
-		if (!$new or $lier_trad) {
230
-			if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
231
-				$row = $select($id, $id_parent, $lier_trad);
232
-				// si on a une fonction precharger, elle pu faire un reglage de langue
233
-				$lang_default = (!empty($row['lang']) ? $row['lang'] : null);
234
-			} else {
235
-				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id));
236
-			}
237
-			if (!$new) {
238
-				$md5 = controles_md5($row);
239
-			}
240
-		}
241
-		if (!$row) {
242
-			$row = array();
243
-			$trouver_table = charger_fonction('trouver_table', 'base');
244
-			if ($desc = $trouver_table($table_objet)) {
245
-				foreach ($desc['field'] as $k => $v) {
246
-					$row[$k] = '';
247
-				}
248
-			}
249
-		}
250
-	}
251
-
252
-	// Gaffe: sans ceci, on ecrase systematiquement l'article d'origine
253
-	// (et donc: pas de lien de traduction)
254
-	$id = ($new or $lier_trad)
255
-		? 'oui'
256
-		: $row[$id_table_objet];
257
-	$row[$id_table_objet] = $id;
258
-
259
-	$contexte = $row;
260
-	if (strlen($id_parent) && is_numeric($id_parent) && (!isset($contexte['id_parent']) or $new)) {
261
-		if (!isset($contexte['id_parent'])) {
262
-			unset($contexte['id_rubrique']);
263
-		}
264
-		$contexte['id_parent'] = $id_parent;
265
-	} elseif (!isset($contexte['id_parent'])) {
266
-		// id_rubrique dans id_parent si possible
267
-		if (isset($contexte['id_rubrique'])) {
268
-			$contexte['id_parent'] = $contexte['id_rubrique'];
269
-			unset($contexte['id_rubrique']);
270
-		} else {
271
-			$contexte['id_parent'] = '';
272
-		}
273
-		if (!$contexte['id_parent']
274
-			and $preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)
275
-		) {
276
-			$contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row);
277
-		}
278
-	}
279
-
280
-	$config = array();
281
-	if ($config_fonc) {
282
-		$contexte['config'] = $config = $config_fonc($contexte);
283
-		if (!$lang_default) {
284
-			$lang_default = $config['langue'] ?? session_get('lang') ;
285
-		}
286
-	}
287
-	$config = $config + array(
288
-		'lignes' => 0,
289
-		'langue' => '',
290
-	);
291
-
292
-	$att_text = " class='textarea' "
293
-		. " rows='"
294
-		. ($config['lignes'] + 15)
295
-		. "' cols='40'";
296
-	if (isset($contexte['texte'])) {
297
-		list($contexte['texte'], $contexte['_texte_trop_long']) = editer_texte_recolle($contexte['texte'], $att_text);
298
-	}
299
-
300
-	// on veut conserver la langue de l'interface ;
301
-	// on passe cette donnee sous un autre nom, au cas ou le squelette
302
-	// voudrait l'exploiter
303
-	if (isset($contexte['lang'])) {
304
-		$contexte['langue'] = $contexte['lang'];
305
-		unset($contexte['lang']);
306
-	}
307
-
308
-	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
309
-		(!$lier_trad ? '' :
310
-			("\n<input type='hidden' name='lier_trad' value='" .
311
-				$lier_trad .
312
-				"' />" .
313
-				"\n<input type='hidden' name='changer_lang' value='" .
314
-				$lang_default .
315
-				"' />"))
316
-		. $hidden
317
-		. (isset($md5) ? $md5 : '');
318
-
319
-	// preciser que le formulaire doit passer dans un pipeline
320
-	$contexte['_pipeline'] = array('editer_contenu_objet', array('type' => $type, 'id' => $id));
321
-
322
-	// preciser que le formulaire doit etre securise auteur/action
323
-	// n'est plus utile lorsque l'action accepte l'id en argument direct
324
-	// on le garde pour compat
325
-	$contexte['_action'] = array("editer_$type", $id);
326
-
327
-	// et in fine placer l'autorisation
328
-	if (intval($id)){
329
-		if (!autoriser('modifier', $type, intval($id))){
330
-			$valeurs['editable'] = '';
331
-		}
332
-	}
333
-	else {
334
-		if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) {
335
-			$valeurs['editable'] = '';
336
-		}
337
-	}
338
-
339
-	return $contexte;
211
+    $table_objet = table_objet($type);
212
+    $table_objet_sql = table_objet_sql($type);
213
+    $id_table_objet = id_table_objet($type);
214
+
215
+    // on accepte pas une fonction de config inconnue si elle vient d'un modele
216
+    if ($config_fonc
217
+      and !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config'])
218
+      and $config_fonc !== $table_objet . '_edit_config') {
219
+        if ($args = test_formulaire_inclus_par_modele()
220
+          and in_array($config_fonc, $args)) {
221
+            $config_fonc = '';
222
+        }
223
+    }
224
+
225
+    $new = !is_numeric($id);
226
+    $lang_default = '';
227
+    // Appel direct dans un squelette
228
+    if (!$row) {
229
+        if (!$new or $lier_trad) {
230
+            if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
231
+                $row = $select($id, $id_parent, $lier_trad);
232
+                // si on a une fonction precharger, elle pu faire un reglage de langue
233
+                $lang_default = (!empty($row['lang']) ? $row['lang'] : null);
234
+            } else {
235
+                $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id));
236
+            }
237
+            if (!$new) {
238
+                $md5 = controles_md5($row);
239
+            }
240
+        }
241
+        if (!$row) {
242
+            $row = array();
243
+            $trouver_table = charger_fonction('trouver_table', 'base');
244
+            if ($desc = $trouver_table($table_objet)) {
245
+                foreach ($desc['field'] as $k => $v) {
246
+                    $row[$k] = '';
247
+                }
248
+            }
249
+        }
250
+    }
251
+
252
+    // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine
253
+    // (et donc: pas de lien de traduction)
254
+    $id = ($new or $lier_trad)
255
+        ? 'oui'
256
+        : $row[$id_table_objet];
257
+    $row[$id_table_objet] = $id;
258
+
259
+    $contexte = $row;
260
+    if (strlen($id_parent) && is_numeric($id_parent) && (!isset($contexte['id_parent']) or $new)) {
261
+        if (!isset($contexte['id_parent'])) {
262
+            unset($contexte['id_rubrique']);
263
+        }
264
+        $contexte['id_parent'] = $id_parent;
265
+    } elseif (!isset($contexte['id_parent'])) {
266
+        // id_rubrique dans id_parent si possible
267
+        if (isset($contexte['id_rubrique'])) {
268
+            $contexte['id_parent'] = $contexte['id_rubrique'];
269
+            unset($contexte['id_rubrique']);
270
+        } else {
271
+            $contexte['id_parent'] = '';
272
+        }
273
+        if (!$contexte['id_parent']
274
+            and $preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)
275
+        ) {
276
+            $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row);
277
+        }
278
+    }
279
+
280
+    $config = array();
281
+    if ($config_fonc) {
282
+        $contexte['config'] = $config = $config_fonc($contexte);
283
+        if (!$lang_default) {
284
+            $lang_default = $config['langue'] ?? session_get('lang') ;
285
+        }
286
+    }
287
+    $config = $config + array(
288
+        'lignes' => 0,
289
+        'langue' => '',
290
+    );
291
+
292
+    $att_text = " class='textarea' "
293
+        . " rows='"
294
+        . ($config['lignes'] + 15)
295
+        . "' cols='40'";
296
+    if (isset($contexte['texte'])) {
297
+        list($contexte['texte'], $contexte['_texte_trop_long']) = editer_texte_recolle($contexte['texte'], $att_text);
298
+    }
299
+
300
+    // on veut conserver la langue de l'interface ;
301
+    // on passe cette donnee sous un autre nom, au cas ou le squelette
302
+    // voudrait l'exploiter
303
+    if (isset($contexte['lang'])) {
304
+        $contexte['langue'] = $contexte['lang'];
305
+        unset($contexte['lang']);
306
+    }
307
+
308
+    $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
309
+        (!$lier_trad ? '' :
310
+            ("\n<input type='hidden' name='lier_trad' value='" .
311
+                $lier_trad .
312
+                "' />" .
313
+                "\n<input type='hidden' name='changer_lang' value='" .
314
+                $lang_default .
315
+                "' />"))
316
+        . $hidden
317
+        . (isset($md5) ? $md5 : '');
318
+
319
+    // preciser que le formulaire doit passer dans un pipeline
320
+    $contexte['_pipeline'] = array('editer_contenu_objet', array('type' => $type, 'id' => $id));
321
+
322
+    // preciser que le formulaire doit etre securise auteur/action
323
+    // n'est plus utile lorsque l'action accepte l'id en argument direct
324
+    // on le garde pour compat
325
+    $contexte['_action'] = array("editer_$type", $id);
326
+
327
+    // et in fine placer l'autorisation
328
+    if (intval($id)){
329
+        if (!autoriser('modifier', $type, intval($id))){
330
+            $valeurs['editable'] = '';
331
+        }
332
+    }
333
+    else {
334
+        if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) {
335
+            $valeurs['editable'] = '';
336
+        }
337
+    }
338
+
339
+    return $contexte;
340 340
 }
341 341
 
342 342
 /**
@@ -347,29 +347,29 @@  discard block
 block discarded – undo
347 347
  * @return array
348 348
  */
349 349
 function coupe_trop_long($texte) {
350
-	$aider = charger_fonction('aider', 'inc');
351
-	if (strlen($texte) > 28 * 1024) {
352
-		$texte = str_replace("\r\n", "\n", $texte);
353
-		$pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
354
-		if ($pos > 0 and $pos < 32 * 1024) {
355
-			$debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
356
-			$suite = substr($texte, $pos + 2);
357
-		} else {
358
-			$pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
359
-			if (!($pos > 0 and $pos < 32 * 1024)) {
360
-				$pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
361
-				$decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
362
-			} else {
363
-				$decalage = 1;
364
-			}
365
-			$debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un
366
-			$suite = substr($texte, $pos + $decalage);
367
-		}
368
-
369
-		return (array($debut, $suite));
370
-	} else {
371
-		return (array($texte, ''));
372
-	}
350
+    $aider = charger_fonction('aider', 'inc');
351
+    if (strlen($texte) > 28 * 1024) {
352
+        $texte = str_replace("\r\n", "\n", $texte);
353
+        $pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
354
+        if ($pos > 0 and $pos < 32 * 1024) {
355
+            $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
356
+            $suite = substr($texte, $pos + 2);
357
+        } else {
358
+            $pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
359
+            if (!($pos > 0 and $pos < 32 * 1024)) {
360
+                $pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
361
+                $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
362
+            } else {
363
+                $decalage = 1;
364
+            }
365
+            $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un
366
+            $suite = substr($texte, $pos + $decalage);
367
+        }
368
+
369
+        return (array($debut, $suite));
370
+    } else {
371
+        return (array($texte, ''));
372
+    }
373 373
 }
374 374
 
375 375
 /**
@@ -380,24 +380,24 @@  discard block
 block discarded – undo
380 380
  * @return array
381 381
  */
382 382
 function editer_texte_recolle($texte, $att_text) {
383
-	if ((strlen($texte) < 29 * 1024)
384
-		or (include_spip('inc/layer') and ($GLOBALS['browser_name'] != 'MSIE'))
385
-	) {
386
-		return array($texte, '');
387
-	}
388
-
389
-	include_spip('inc/barre');
390
-	$textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
391
-	$nombre = 0;
392
-
393
-	while (strlen($texte) > 29 * 1024) {
394
-		$nombre++;
395
-		list($texte1, $texte) = coupe_trop_long($texte);
396
-		$textes_supplement .= '<br />' .
397
-			"<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
398
-	}
399
-
400
-	return array($texte, $textes_supplement);
383
+    if ((strlen($texte) < 29 * 1024)
384
+        or (include_spip('inc/layer') and ($GLOBALS['browser_name'] != 'MSIE'))
385
+    ) {
386
+        return array($texte, '');
387
+    }
388
+
389
+    include_spip('inc/barre');
390
+    $textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
391
+    $nombre = 0;
392
+
393
+    while (strlen($texte) > 29 * 1024) {
394
+        $nombre++;
395
+        list($texte1, $texte) = coupe_trop_long($texte);
396
+        $textes_supplement .= '<br />' .
397
+            "<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
398
+    }
399
+
400
+    return array($texte, $textes_supplement);
401 401
 }
402 402
 
403 403
 /**
@@ -408,17 +408,17 @@  discard block
 block discarded – undo
408 408
  * @param int $longueur
409 409
  */
410 410
 function titre_automatique($champ_titre, $champs_contenu, $longueur = null) {
411
-	if (!_request($champ_titre)) {
412
-		$titrer_contenu = charger_fonction('titrer_contenu', 'inc');
413
-		if (!is_null($longueur)) {
414
-			$t = $titrer_contenu($champs_contenu, null, $longueur);
415
-		} else {
416
-			$t = $titrer_contenu($champs_contenu);
417
-		}
418
-		if ($t) {
419
-			set_request($champ_titre, $t);
420
-		}
421
-	}
411
+    if (!_request($champ_titre)) {
412
+        $titrer_contenu = charger_fonction('titrer_contenu', 'inc');
413
+        if (!is_null($longueur)) {
414
+            $t = $titrer_contenu($champs_contenu, null, $longueur);
415
+        } else {
416
+            $t = $titrer_contenu($champs_contenu);
417
+        }
418
+        if ($t) {
419
+            set_request($champ_titre, $t);
420
+        }
421
+    }
422 422
 }
423 423
 
424 424
 /**
@@ -438,20 +438,20 @@  discard block
 block discarded – undo
438 438
  * @return string
439 439
  */
440 440
 function inc_titrer_contenu_dist($champs_contenu, $c = null, $longueur = 50) {
441
-	// trouver un champ texte non vide
442
-	$t = '';
443
-	foreach ($champs_contenu as $champ) {
444
-		if ($t = _request($champ, $c)) {
445
-			break;
446
-		}
447
-	}
448
-
449
-	if ($t) {
450
-		include_spip('inc/texte_mini');
451
-		$t = couper($t, $longueur, '...');
452
-	}
453
-
454
-	return $t;
441
+    // trouver un champ texte non vide
442
+    $t = '';
443
+    foreach ($champs_contenu as $champ) {
444
+        if ($t = _request($champ, $c)) {
445
+            break;
446
+        }
447
+    }
448
+
449
+    if ($t) {
450
+        include_spip('inc/texte_mini');
451
+        $t = couper($t, $longueur, '...');
452
+    }
453
+
454
+    return $t;
455 455
 }
456 456
 
457 457
 /**
@@ -474,30 +474,30 @@  discard block
 block discarded – undo
474 474
  *      - array sinon couples ('$prefixe$colonne => md5)
475 475
  **/
476 476
 function controles_md5($data, $prefixe = 'ctr_', $format = 'html') {
477
-	if (!is_array($data)) {
478
-		return false;
479
-	}
480
-
481
-	$ctr = array();
482
-	foreach ($data as $key => $val) {
483
-		$m = md5($val);
484
-		$k = $prefixe . $key;
485
-
486
-		switch ($format) {
487
-			case 'html':
488
-				$ctr[$k] = "<input type='hidden' value='$m' name='$k' />";
489
-				break;
490
-			default:
491
-				$ctr[$k] = $m;
492
-				break;
493
-		}
494
-	}
495
-
496
-	if ($format == 'html') {
497
-		return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n";
498
-	} else {
499
-		return $ctr;
500
-	}
477
+    if (!is_array($data)) {
478
+        return false;
479
+    }
480
+
481
+    $ctr = array();
482
+    foreach ($data as $key => $val) {
483
+        $m = md5($val);
484
+        $k = $prefixe . $key;
485
+
486
+        switch ($format) {
487
+            case 'html':
488
+                $ctr[$k] = "<input type='hidden' value='$m' name='$k' />";
489
+                break;
490
+            default:
491
+                $ctr[$k] = $m;
492
+                break;
493
+        }
494
+    }
495
+
496
+    if ($format == 'html') {
497
+        return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n";
498
+    } else {
499
+        return $ctr;
500
+    }
501 501
 }
502 502
 
503 503
 /**
@@ -536,79 +536,79 @@  discard block
 block discarded – undo
536 536
  *     - post : le contenu posté
537 537
  **/
538 538
 function controler_contenu($type, $id, $options = array(), $c = false, $serveur = '') {
539
-	include_spip('inc/filtres');
540
-
541
-	$table_objet = table_objet($type);
542
-	$spip_table_objet = table_objet_sql($type);
543
-	$trouver_table = charger_fonction('trouver_table', 'base');
544
-	$desc = $trouver_table($table_objet, $serveur);
545
-
546
-	// Appels incomplets (sans $c)
547
-	if (!is_array($c)) {
548
-		foreach ($desc['field'] as $champ => $ignore) {
549
-			if (_request($champ)) {
550
-				$c[$champ] = _request($champ);
551
-			}
552
-		}
553
-	}
554
-
555
-	// Securite : certaines variables ne sont jamais acceptees ici
556
-	// car elles ne relevent pas de autoriser(article, modifier) ;
557
-	// il faut passer par instituer_XX()
558
-	// TODO: faut-il passer ces variables interdites
559
-	// dans un fichier de description separe ?
560
-	unset($c['statut']);
561
-	unset($c['id_parent']);
562
-	unset($c['id_rubrique']);
563
-	unset($c['id_secteur']);
564
-
565
-	// Gerer les champs non vides
566
-	if (isset($options['nonvide']) and is_array($options['nonvide'])) {
567
-		foreach ($options['nonvide'] as $champ => $sinon) {
568
-			if ($c[$champ] === '') {
569
-				$c[$champ] = $sinon;
570
-			}
571
-		}
572
-	}
573
-
574
-	// N'accepter que les champs qui existent
575
-	// [TODO] ici aussi on peut valider les contenus en fonction du type
576
-	$champs = array();
577
-	foreach ($desc['field'] as $champ => $ignore) {
578
-		if (isset($c[$champ])) {
579
-			$champs[$champ] = $c[$champ];
580
-		}
581
-	}
582
-
583
-	// Nettoyer les valeurs
584
-	$champs = array_map('corriger_caracteres', $champs);
585
-
586
-	// Envoyer aux plugins
587
-	$champs = pipeline(
588
-		'pre_edition',
589
-		array(
590
-			'args' => array(
591
-				'table' => $spip_table_objet, // compatibilite
592
-				'table_objet' => $table_objet,
593
-				'spip_table_objet' => $spip_table_objet,
594
-				'type' => $type,
595
-				'id_objet' => $id,
596
-				'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ?
597
-				'action' => 'controler',
598
-				'serveur' => $serveur,
599
-			),
600
-			'data' => $champs
601
-		)
602
-	);
603
-
604
-	if (!$champs) {
605
-		return false;
606
-	}
607
-
608
-	// Verifier si les mises a jour sont pertinentes, datees, en conflit etc
609
-	$conflits = controler_md5($champs, $_POST, $type, $id, $serveur, isset($options['prefix']) ? $options['prefix'] : 'ctr_');
610
-
611
-	return $conflits;
539
+    include_spip('inc/filtres');
540
+
541
+    $table_objet = table_objet($type);
542
+    $spip_table_objet = table_objet_sql($type);
543
+    $trouver_table = charger_fonction('trouver_table', 'base');
544
+    $desc = $trouver_table($table_objet, $serveur);
545
+
546
+    // Appels incomplets (sans $c)
547
+    if (!is_array($c)) {
548
+        foreach ($desc['field'] as $champ => $ignore) {
549
+            if (_request($champ)) {
550
+                $c[$champ] = _request($champ);
551
+            }
552
+        }
553
+    }
554
+
555
+    // Securite : certaines variables ne sont jamais acceptees ici
556
+    // car elles ne relevent pas de autoriser(article, modifier) ;
557
+    // il faut passer par instituer_XX()
558
+    // TODO: faut-il passer ces variables interdites
559
+    // dans un fichier de description separe ?
560
+    unset($c['statut']);
561
+    unset($c['id_parent']);
562
+    unset($c['id_rubrique']);
563
+    unset($c['id_secteur']);
564
+
565
+    // Gerer les champs non vides
566
+    if (isset($options['nonvide']) and is_array($options['nonvide'])) {
567
+        foreach ($options['nonvide'] as $champ => $sinon) {
568
+            if ($c[$champ] === '') {
569
+                $c[$champ] = $sinon;
570
+            }
571
+        }
572
+    }
573
+
574
+    // N'accepter que les champs qui existent
575
+    // [TODO] ici aussi on peut valider les contenus en fonction du type
576
+    $champs = array();
577
+    foreach ($desc['field'] as $champ => $ignore) {
578
+        if (isset($c[$champ])) {
579
+            $champs[$champ] = $c[$champ];
580
+        }
581
+    }
582
+
583
+    // Nettoyer les valeurs
584
+    $champs = array_map('corriger_caracteres', $champs);
585
+
586
+    // Envoyer aux plugins
587
+    $champs = pipeline(
588
+        'pre_edition',
589
+        array(
590
+            'args' => array(
591
+                'table' => $spip_table_objet, // compatibilite
592
+                'table_objet' => $table_objet,
593
+                'spip_table_objet' => $spip_table_objet,
594
+                'type' => $type,
595
+                'id_objet' => $id,
596
+                'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ?
597
+                'action' => 'controler',
598
+                'serveur' => $serveur,
599
+            ),
600
+            'data' => $champs
601
+        )
602
+    );
603
+
604
+    if (!$champs) {
605
+        return false;
606
+    }
607
+
608
+    // Verifier si les mises a jour sont pertinentes, datees, en conflit etc
609
+    $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, isset($options['prefix']) ? $options['prefix'] : 'ctr_');
610
+
611
+    return $conflits;
612 612
 }
613 613
 
614 614
 
@@ -638,63 +638,63 @@  discard block
 block discarded – undo
638 638
  *     - post : le contenu posté
639 639
  **/
640 640
 function controler_md5(&$champs, $ctr, $type, $id, $serveur, $prefix = 'ctr_') {
641
-	$spip_table_objet = table_objet_sql($type);
642
-	$id_table_objet = id_table_objet($type);
643
-
644
-	// Controle des MD5 envoyes
645
-	// On elimine les donnees non modifiees par le formulaire (mais
646
-	// potentiellement modifiees entre temps par un autre utilisateur)
647
-	foreach ($champs as $key => $val) {
648
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
649
-			if (is_scalar($val) and $m == md5($val)) {
650
-				unset($champs[$key]);
651
-			}
652
-		}
653
-	}
654
-	if (!$champs) {
655
-		return;
656
-	}
657
-
658
-	// On veut savoir si notre modif va avoir un impact
659
-	// par rapport aux donnees contenues dans la base
660
-	// (qui peuvent etre differentes de celles ayant servi a calculer le ctr)
661
-	$s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur);
662
-	$intact = true;
663
-	foreach ($champs as $ch => $val) {
664
-		$intact &= ($s[$ch] == $val);
665
-	}
666
-	if ($intact) {
667
-		return;
668
-	}
669
-
670
-	// Detection de conflits :
671
-	// On verifie si notre modif ne provient pas d'un formulaire
672
-	// genere a partir de donnees modifiees dans l'intervalle ; ici
673
-	// on compare a ce qui est dans la base, et on bloque en cas
674
-	// de conflit.
675
-	$ctrh = $ctrq = $conflits = array();
676
-	foreach (array_keys($champs) as $key) {
677
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
678
-			$ctrh[$key] = $m;
679
-			$ctrq[] = $key;
680
-		}
681
-	}
682
-	if ($ctrq) {
683
-		$ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur);
684
-		foreach ($ctrh as $key => $m) {
685
-			if ($m != md5($ctrq[$key])
686
-				and $champs[$key] !== $ctrq[$key]
687
-			) {
688
-				$conflits[$key] = array(
689
-					'base' => $ctrq[$key],
690
-					'post' => $champs[$key]
691
-				);
692
-				unset($champs[$key]); # stocker quand meme les modifs ?
693
-			}
694
-		}
695
-	}
696
-
697
-	return $conflits;
641
+    $spip_table_objet = table_objet_sql($type);
642
+    $id_table_objet = id_table_objet($type);
643
+
644
+    // Controle des MD5 envoyes
645
+    // On elimine les donnees non modifiees par le formulaire (mais
646
+    // potentiellement modifiees entre temps par un autre utilisateur)
647
+    foreach ($champs as $key => $val) {
648
+        if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
649
+            if (is_scalar($val) and $m == md5($val)) {
650
+                unset($champs[$key]);
651
+            }
652
+        }
653
+    }
654
+    if (!$champs) {
655
+        return;
656
+    }
657
+
658
+    // On veut savoir si notre modif va avoir un impact
659
+    // par rapport aux donnees contenues dans la base
660
+    // (qui peuvent etre differentes de celles ayant servi a calculer le ctr)
661
+    $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur);
662
+    $intact = true;
663
+    foreach ($champs as $ch => $val) {
664
+        $intact &= ($s[$ch] == $val);
665
+    }
666
+    if ($intact) {
667
+        return;
668
+    }
669
+
670
+    // Detection de conflits :
671
+    // On verifie si notre modif ne provient pas d'un formulaire
672
+    // genere a partir de donnees modifiees dans l'intervalle ; ici
673
+    // on compare a ce qui est dans la base, et on bloque en cas
674
+    // de conflit.
675
+    $ctrh = $ctrq = $conflits = array();
676
+    foreach (array_keys($champs) as $key) {
677
+        if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
678
+            $ctrh[$key] = $m;
679
+            $ctrq[] = $key;
680
+        }
681
+    }
682
+    if ($ctrq) {
683
+        $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur);
684
+        foreach ($ctrh as $key => $m) {
685
+            if ($m != md5($ctrq[$key])
686
+                and $champs[$key] !== $ctrq[$key]
687
+            ) {
688
+                $conflits[$key] = array(
689
+                    'base' => $ctrq[$key],
690
+                    'post' => $champs[$key]
691
+                );
692
+                unset($champs[$key]); # stocker quand meme les modifs ?
693
+            }
694
+        }
695
+    }
696
+
697
+    return $conflits;
698 698
 }
699 699
 
700 700
 /**
@@ -706,11 +706,11 @@  discard block
 block discarded – undo
706 706
  * @return string
707 707
  */
708 708
 function display_conflit_champ($x) {
709
-	if (strstr($x, "\n") or strlen($x) > 80) {
710
-		return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
711
-	} else {
712
-		return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
713
-	}
709
+    if (strstr($x, "\n") or strlen($x) > 80) {
710
+        return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
711
+    } else {
712
+        return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
713
+    }
714 714
 }
715 715
 
716 716
 /**
@@ -728,57 +728,57 @@  discard block
 block discarded – undo
728 728
  * @return string
729 729
  */
730 730
 function signaler_conflits_edition($conflits, $redirect = '') {
731
-	include_spip('inc/minipres');
732
-	include_spip('inc/revisions');
733
-	include_spip('afficher_diff/champ');
734
-	include_spip('inc/suivi_versions');
735
-	include_spip('inc/diff');
736
-	$diffs = array();
737
-	foreach ($conflits as $champ => $a) {
738
-		// probleme de stockage ou conflit d'edition ?
739
-		$base = isset($a['save']) ? $a['save'] : $a['base'];
740
-
741
-		$diff = new Diff(new DiffTexte);
742
-		$n = preparer_diff($a['post']);
743
-		$o = preparer_diff($base);
744
-		$d = propre_diff(afficher_para_modifies(afficher_diff($diff->comparer($n, $o))));
745
-
746
-		$titre = isset($a['save']) ? _L(
747
-			'Echec lors de l\'enregistrement du champ @champ@',
748
-			array('champ' => $champ)
749
-		) : $champ;
750
-
751
-		$diffs[] = "<h2>$titre</h2>\n"
752
-			. '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n"
753
-			. "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n"
754
-			. '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>'
755
-			. display_conflit_champ($a['post'])
756
-			. '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>'
757
-			. display_conflit_champ($base);
758
-	}
759
-
760
-	if ($redirect) {
761
-		$id = uniqid(rand());
762
-		$redirect = "<form action='$redirect' method='get'
731
+    include_spip('inc/minipres');
732
+    include_spip('inc/revisions');
733
+    include_spip('afficher_diff/champ');
734
+    include_spip('inc/suivi_versions');
735
+    include_spip('inc/diff');
736
+    $diffs = array();
737
+    foreach ($conflits as $champ => $a) {
738
+        // probleme de stockage ou conflit d'edition ?
739
+        $base = isset($a['save']) ? $a['save'] : $a['base'];
740
+
741
+        $diff = new Diff(new DiffTexte);
742
+        $n = preparer_diff($a['post']);
743
+        $o = preparer_diff($base);
744
+        $d = propre_diff(afficher_para_modifies(afficher_diff($diff->comparer($n, $o))));
745
+
746
+        $titre = isset($a['save']) ? _L(
747
+            'Echec lors de l\'enregistrement du champ @champ@',
748
+            array('champ' => $champ)
749
+        ) : $champ;
750
+
751
+        $diffs[] = "<h2>$titre</h2>\n"
752
+            . '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n"
753
+            . "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n"
754
+            . '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>'
755
+            . display_conflit_champ($a['post'])
756
+            . '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>'
757
+            . display_conflit_champ($base);
758
+    }
759
+
760
+    if ($redirect) {
761
+        $id = uniqid(rand());
762
+        $redirect = "<form action='$redirect' method='get'
763 763
 			id='$id'
764 764
 			style='float:" . $GLOBALS['spip_lang_right'] . "; margin-top:2em;'>\n"
765
-			. form_hidden($redirect)
766
-			. "<input type='submit' value='" . _T('icone_retour') . "' />
765
+            . form_hidden($redirect)
766
+            . "<input type='submit' value='" . _T('icone_retour') . "' />
767 767
 		</form>\n";
768 768
 
769
-		// pour les documents, on est probablement en ajax : il faut ajaxer
770
-		if (_AJAX) {
771
-			$redirect .= '<script type="text/javascript">'
772
-				. 'setTimeout(function(){$("#' . $id . '")
769
+        // pour les documents, on est probablement en ajax : il faut ajaxer
770
+        if (_AJAX) {
771
+            $redirect .= '<script type="text/javascript">'
772
+                . 'setTimeout(function(){$("#' . $id . '")
773 773
 			.ajaxForm({target:$("#' . $id . '").parent()});
774 774
 			}, 200);'
775
-				. "</script>\n";
776
-		}
777
-	}
775
+                . "</script>\n";
776
+        }
777
+    }
778 778
 
779
-	echo minipres(
780
-		_T('titre_conflit_edition'),
781
-		'<style>
779
+    echo minipres(
780
+        _T('titre_conflit_edition'),
781
+        '<style>
782 782
 .diff-para-deplace { background: #e8e8ff; }
783 783
 .diff-para-ajoute { background: #d0ffc0; color: #000; }
784 784
 .diff-para-supprime { background: #ffd0c0; color: #904040; text-decoration: line-through; }
@@ -789,12 +789,12 @@  discard block
 block discarded – undo
789 789
 .diff-para-deplace .diff-supprime { background: #ffb8b8; border: 1px solid #808080; }
790 790
 .diff-para-deplace .diff-deplace { background: #b8b8ff; border: 1px solid #808080; }
791 791
 </style>'
792
-		. '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>'
793
-		. '<p>' . _T('texte_conflit_edition_correction') . '</p>'
794
-		. "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>"
795
-		. join("\n", $diffs)
796
-		. "</div>\n"
797
-
798
-		. $redirect
799
-	);
792
+        . '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>'
793
+        . '<p>' . _T('texte_conflit_edition_correction') . '</p>'
794
+        . "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>"
795
+        . join("\n", $diffs)
796
+        . "</div>\n"
797
+
798
+        . $redirect
799
+    );
800 800
 }
Please login to merge, or discard this patch.
Spacing   +37 added lines, -38 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 		$res['message_ok'] = _T('info_modification_enregistree');
101 101
 		if ($retour) {
102 102
 			if (strncmp($retour, 'javascript:', 11) == 0) {
103
-				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>';
103
+				$res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/'.substr($retour, 11).'/*]]>*/</script>';
104 104
 				$res['editable'] = true;
105 105
 			} else {
106 106
 				$res['redirect'] = parametre_url($retour, $id_table_objet, $id);
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 				if (!isset($erreurs[$champ])) {
141 141
 					$erreurs[$champ] = '';
142 142
 				}
143
-				$erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>';
143
+				$erreurs[$champ] .= _T('alerte_modif_info_concourante')."<br /><textarea readonly='readonly' class='forml'>".entites_html($conflit['base']).'</textarea>';
144 144
 			}
145 145
 		}
146 146
 	}
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	// on accepte pas une fonction de config inconnue si elle vient d'un modele
216 216
 	if ($config_fonc
217 217
 	  and !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config'])
218
-	  and $config_fonc !== $table_objet . '_edit_config') {
218
+	  and $config_fonc !== $table_objet.'_edit_config') {
219 219
 		if ($args = test_formulaire_inclus_par_modele()
220 220
 		  and in_array($config_fonc, $args)) {
221 221
 			$config_fonc = '';
@@ -227,12 +227,12 @@  discard block
 block discarded – undo
227 227
 	// Appel direct dans un squelette
228 228
 	if (!$row) {
229 229
 		if (!$new or $lier_trad) {
230
-			if ($select = charger_fonction('precharger_' . $type, 'inc', true)) {
230
+			if ($select = charger_fonction('precharger_'.$type, 'inc', true)) {
231 231
 				$row = $select($id, $id_parent, $lier_trad);
232 232
 				// si on a une fonction precharger, elle pu faire un reglage de langue
233 233
 				$lang_default = (!empty($row['lang']) ? $row['lang'] : null);
234 234
 			} else {
235
-				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id));
235
+				$row = sql_fetsel('*', $table_objet_sql, $id_table_objet.'='.intval($id));
236 236
 			}
237 237
 			if (!$new) {
238 238
 				$md5 = controles_md5($row);
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 	if ($config_fonc) {
282 282
 		$contexte['config'] = $config = $config_fonc($contexte);
283 283
 		if (!$lang_default) {
284
-			$lang_default = $config['langue'] ?? session_get('lang') ;
284
+			$lang_default = $config['langue'] ?? session_get('lang');
285 285
 		}
286 286
 	}
287 287
 	$config = $config + array(
@@ -305,13 +305,12 @@  discard block
 block discarded – undo
305 305
 		unset($contexte['lang']);
306 306
 	}
307 307
 
308
-	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" .
309
-		(!$lier_trad ? '' :
310
-			("\n<input type='hidden' name='lier_trad' value='" .
311
-				$lier_trad .
312
-				"' />" .
313
-				"\n<input type='hidden' name='changer_lang' value='" .
314
-				$lang_default .
308
+	$contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n".
309
+		(!$lier_trad ? '' : ("\n<input type='hidden' name='lier_trad' value='".
310
+				$lier_trad.
311
+				"' />".
312
+				"\n<input type='hidden' name='changer_lang' value='".
313
+				$lang_default.
315 314
 				"' />"))
316 315
 		. $hidden
317 316
 		. (isset($md5) ? $md5 : '');
@@ -325,8 +324,8 @@  discard block
 block discarded – undo
325 324
 	$contexte['_action'] = array("editer_$type", $id);
326 325
 
327 326
 	// et in fine placer l'autorisation
328
-	if (intval($id)){
329
-		if (!autoriser('modifier', $type, intval($id))){
327
+	if (intval($id)) {
328
+		if (!autoriser('modifier', $type, intval($id))) {
330 329
 			$valeurs['editable'] = '';
331 330
 		}
332 331
 	}
@@ -350,14 +349,14 @@  discard block
 block discarded – undo
350 349
 	$aider = charger_fonction('aider', 'inc');
351 350
 	if (strlen($texte) > 28 * 1024) {
352 351
 		$texte = str_replace("\r\n", "\n", $texte);
353
-		$pos = strpos($texte, "\n\n", 28 * 1024);  // coupe para > 28 ko
352
+		$pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko
354 353
 		if ($pos > 0 and $pos < 32 * 1024) {
355
-			$debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n";
354
+			$debut = substr($texte, 0, $pos)."\n\n<!--SPIP-->\n";
356 355
 			$suite = substr($texte, $pos + 2);
357 356
 		} else {
358
-			$pos = strpos($texte, ' ', 28 * 1024);  // sinon coupe espace
357
+			$pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace
359 358
 			if (!($pos > 0 and $pos < 32 * 1024)) {
360
-				$pos = 28 * 1024;  // au pire (pas d'espace trouv'e)
359
+				$pos = 28 * 1024; // au pire (pas d'espace trouv'e)
361 360
 				$decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere
362 361
 			} else {
363 362
 				$decalage = 1;
@@ -387,13 +386,13 @@  discard block
 block discarded – undo
387 386
 	}
388 387
 
389 388
 	include_spip('inc/barre');
390
-	$textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n";
389
+	$textes_supplement = "<br /><span style='color: red'>"._T('info_texte_long')."</span>\n";
391 390
 	$nombre = 0;
392 391
 
393 392
 	while (strlen($texte) > 29 * 1024) {
394 393
 		$nombre++;
395 394
 		list($texte1, $texte) = coupe_trop_long($texte);
396
-		$textes_supplement .= '<br />' .
395
+		$textes_supplement .= '<br />'.
397 396
 			"<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n";
398 397
 	}
399 398
 
@@ -481,7 +480,7 @@  discard block
 block discarded – undo
481 480
 	$ctr = array();
482 481
 	foreach ($data as $key => $val) {
483 482
 		$m = md5($val);
484
-		$k = $prefixe . $key;
483
+		$k = $prefixe.$key;
485 484
 
486 485
 		switch ($format) {
487 486
 			case 'html':
@@ -494,7 +493,7 @@  discard block
 block discarded – undo
494 493
 	}
495 494
 
496 495
 	if ($format == 'html') {
497
-		return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n";
496
+		return "\n\n<!-- controles md5 -->\n".join("\n", $ctr)."\n\n";
498 497
 	} else {
499 498
 		return $ctr;
500 499
 	}
@@ -645,7 +644,7 @@  discard block
 block discarded – undo
645 644
 	// On elimine les donnees non modifiees par le formulaire (mais
646 645
 	// potentiellement modifiees entre temps par un autre utilisateur)
647 646
 	foreach ($champs as $key => $val) {
648
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
647
+		if (isset($ctr[$prefix.$key]) and $m = $ctr[$prefix.$key]) {
649 648
 			if (is_scalar($val) and $m == md5($val)) {
650 649
 				unset($champs[$key]);
651 650
 			}
@@ -674,7 +673,7 @@  discard block
 block discarded – undo
674 673
 	// de conflit.
675 674
 	$ctrh = $ctrq = $conflits = array();
676 675
 	foreach (array_keys($champs) as $key) {
677
-		if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) {
676
+		if (isset($ctr[$prefix.$key]) and $m = $ctr[$prefix.$key]) {
678 677
 			$ctrh[$key] = $m;
679 678
 			$ctrq[] = $key;
680 679
 		}
@@ -707,9 +706,9 @@  discard block
 block discarded – undo
707 706
  */
708 707
 function display_conflit_champ($x) {
709 708
 	if (strstr($x, "\n") or strlen($x) > 80) {
710
-		return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n";
709
+		return "<textarea style='width:99%; height:10em;'>".entites_html($x)."</textarea>\n";
711 710
 	} else {
712
-		return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n";
711
+		return "<input type='text' size='40' style='width:99%' value=\"".entites_html($x)."\" />\n";
713 712
 	}
714 713
 }
715 714
 
@@ -749,11 +748,11 @@  discard block
 block discarded – undo
749 748
 		) : $champ;
750 749
 
751 750
 		$diffs[] = "<h2>$titre</h2>\n"
752
-			. '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n"
753
-			. "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n"
754
-			. '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>'
751
+			. '<h3>'._T('info_conflit_edition_differences')."</h3>\n"
752
+			. "<div style='max-height:8em; overflow: auto; width:99%;'>".$d."</div>\n"
753
+			. '<h4>'._T('info_conflit_edition_votre_version').'</h4>'
755 754
 			. display_conflit_champ($a['post'])
756
-			. '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>'
755
+			. '<h4>'._T('info_conflit_edition_version_enregistree').'</h4>'
757 756
 			. display_conflit_champ($base);
758 757
 	}
759 758
 
@@ -761,16 +760,16 @@  discard block
 block discarded – undo
761 760
 		$id = uniqid(rand());
762 761
 		$redirect = "<form action='$redirect' method='get'
763 762
 			id='$id'
764
-			style='float:" . $GLOBALS['spip_lang_right'] . "; margin-top:2em;'>\n"
763
+			style='float:".$GLOBALS['spip_lang_right']."; margin-top:2em;'>\n"
765 764
 			. form_hidden($redirect)
766
-			. "<input type='submit' value='" . _T('icone_retour') . "' />
765
+			. "<input type='submit' value='"._T('icone_retour')."' />
767 766
 		</form>\n";
768 767
 
769 768
 		// pour les documents, on est probablement en ajax : il faut ajaxer
770 769
 		if (_AJAX) {
771 770
 			$redirect .= '<script type="text/javascript">'
772
-				. 'setTimeout(function(){$("#' . $id . '")
773
-			.ajaxForm({target:$("#' . $id . '").parent()});
771
+				. 'setTimeout(function(){$("#'.$id.'")
772
+			.ajaxForm({target:$("#' . $id.'").parent()});
774 773
 			}, 200);'
775 774
 				. "</script>\n";
776 775
 		}
@@ -789,9 +788,9 @@  discard block
 block discarded – undo
789 788
 .diff-para-deplace .diff-supprime { background: #ffb8b8; border: 1px solid #808080; }
790 789
 .diff-para-deplace .diff-deplace { background: #b8b8ff; border: 1px solid #808080; }
791 790
 </style>'
792
-		. '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>'
793
-		. '<p>' . _T('texte_conflit_edition_correction') . '</p>'
794
-		. "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>"
791
+		. '<p>'._T('info_conflit_edition_avis_non_sauvegarde').'</p>'
792
+		. '<p>'._T('texte_conflit_edition_correction').'</p>'
793
+		. "<div style='text-align:".$GLOBALS['spip_lang_left'].";'>"
795 794
 		. join("\n", $diffs)
796 795
 		. "</div>\n"
797 796
 
Please login to merge, or discard this patch.