Completed
Push — master ( 230805...a75156 )
by cam
05:02
created
ecrire/inc/filtres_images_lib_mini.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
  *
88 88
  * @param bool|string $stat
89 89
  *     true, false ou le statut déjà défini si traitements enchaînés.
90
- * @return bool
90
+ * @return false|null
91 91
  *     true si il faut supprimer le fichier temporaire ; false sinon.
92 92
  */
93 93
 function statut_effacer_images_temporaires($stat) {
@@ -1582,7 +1582,7 @@  discard block
 block discarded – undo
1582 1582
 	/**
1583 1583
 	 * Transforme une ressource GD en image au format ICO
1584 1584
 	 *
1585
-	 * @param array $gd_image_array
1585
+	 * @param Ressource[] $gd_image_array
1586 1586
 	 *     Tableau de ressources d'images GD
1587 1587
 	 * @return string
1588 1588
 	 *     Image au format ICO
Please login to merge, or discard this patch.
Indentation   +1153 added lines, -1153 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 include_spip('inc/filtres'); // par precaution
25 25
 include_spip('inc/filtres_images_mini'); // par precaution
@@ -39,21 +39,21 @@  discard block
 block discarded – undo
39 39
  *     Le code de la couleur en hexadécimal.
40 40
  */
41 41
 function _couleur_dec_to_hex($red, $green, $blue) {
42
-	$red = dechex($red);
43
-	$green = dechex($green);
44
-	$blue = dechex($blue);
45
-
46
-	if (strlen($red) == 1) {
47
-		$red = "0" . $red;
48
-	}
49
-	if (strlen($green) == 1) {
50
-		$green = "0" . $green;
51
-	}
52
-	if (strlen($blue) == 1) {
53
-		$blue = "0" . $blue;
54
-	}
55
-
56
-	return "$red$green$blue";
42
+    $red = dechex($red);
43
+    $green = dechex($green);
44
+    $blue = dechex($blue);
45
+
46
+    if (strlen($red) == 1) {
47
+        $red = "0" . $red;
48
+    }
49
+    if (strlen($green) == 1) {
50
+        $green = "0" . $green;
51
+    }
52
+    if (strlen($blue) == 1) {
53
+        $blue = "0" . $blue;
54
+    }
55
+
56
+    return "$red$green$blue";
57 57
 }
58 58
 
59 59
 /**
@@ -65,16 +65,16 @@  discard block
 block discarded – undo
65 65
  *     Un tableau des 3 éléments : rouge, vert, bleu.
66 66
  */
67 67
 function _couleur_hex_to_dec($couleur) {
68
-	$couleur = couleur_html_to_hex($couleur);
69
-	$couleur = ltrim($couleur, '#');
70
-	if (strlen($couleur) === 3) {
71
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
72
-	}
73
-	$retour["red"] = hexdec(substr($couleur, 0, 2));
74
-	$retour["green"] = hexdec(substr($couleur, 2, 2));
75
-	$retour["blue"] = hexdec(substr($couleur, 4, 2));
76
-
77
-	return $retour;
68
+    $couleur = couleur_html_to_hex($couleur);
69
+    $couleur = ltrim($couleur, '#');
70
+    if (strlen($couleur) === 3) {
71
+        $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
72
+    }
73
+    $retour["red"] = hexdec(substr($couleur, 0, 2));
74
+    $retour["green"] = hexdec(substr($couleur, 2, 2));
75
+    $retour["blue"] = hexdec(substr($couleur, 4, 2));
76
+
77
+    return $retour;
78 78
 }
79 79
 
80 80
 /**
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
  *     true si il faut supprimer le fichier temporaire ; false sinon.
92 92
  */
93 93
 function statut_effacer_images_temporaires($stat) {
94
-	static $statut = false; // par defaut on grave toute les images
95
-	if ($stat === 'get') {
96
-		return $statut;
97
-	}
98
-	$statut = $stat ? true : false;
94
+    static $statut = false; // par defaut on grave toute les images
95
+    if ($stat === 'get') {
96
+        return $statut;
97
+    }
98
+    $statut = $stat ? true : false;
99 99
 }
100 100
 
101 101
 
@@ -145,226 +145,226 @@  discard block
 block discarded – undo
145 145
  *     - array : tableau décrivant de l'image
146 146
  */
147 147
 function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) {
148
-	static $images_recalcul = array();
149
-	if (strlen($img) == 0) {
150
-		return false;
151
-	}
152
-
153
-	$source = trim(extraire_attribut($img, 'src'));
154
-	if (strlen($source) < 1) {
155
-		$source = $img;
156
-		$img = "<img src='$source' />";
157
-	} # gerer img src="data:....base64"
158
-	elseif (preg_match('@^data:image/(jpe?g|png|gif|svg+xml);base64,(.*)$@isS', $source, $regs)) {
159
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . str_replace('jpeg', 'jpg', $regs[1]);
160
-		if (!file_exists($local)) {
161
-			ecrire_fichier($local, base64_decode($regs[2]));
162
-		}
163
-		$source = $local;
164
-		$img = inserer_attribut($img, 'src', $source);
165
-		# eviter les mauvaises surprises lors de conversions de format
166
-		$img = inserer_attribut($img, 'width', '');
167
-		$img = inserer_attribut($img, 'height', '');
168
-	}
169
-
170
-	// les protocoles web prennent au moins 3 lettres
171
-	if (tester_url_absolue($source)) {
172
-		include_spip('inc/distant');
173
-		$fichier = _DIR_RACINE . copie_locale($source);
174
-		if (!$fichier) {
175
-			return "";
176
-		}
177
-	} else {
178
-		// enlever le timestamp eventuel
179
-		if (strpos($source, "?") !== false) {
180
-			$source = preg_replace(',[?][0-9]+$,', '', $source);
181
-		}
182
-		if (strpos($source, "?") !== false
183
-			and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
184
-			and file_exists($f = preg_replace(',[?].*$,', '', $source))
185
-		) {
186
-			$source = $f;
187
-		}
188
-		$fichier = $source;
189
-	}
190
-
191
-	$terminaison_dest = "";
192
-	if ($terminaison = _image_trouver_extension($fichier)) {
193
-		$terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
194
-	}
195
-
196
-	if ($forcer_format !== false
197
-		// ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image
198
-		and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format,['png','gif','jpg']))) {
199
-		$terminaison_dest = $forcer_format;
200
-	}
201
-
202
-	if (!$terminaison_dest) {
203
-		return false;
204
-	}
205
-
206
-	$nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
207
-	$fichier_dest = $nom_fichier;
208
-	if (($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
209
-		or @file_exists($f = $fichier)
210
-	) {
211
-		// on passe la balise img a taille image qui exraira les attributs si possible
212
-		// au lieu de faire un acces disque sur le fichier
213
-		list($ret["hauteur"], $ret["largeur"]) = taille_image($find_in_path ? $f : $img);
214
-		$date_src = @filemtime($f);
215
-	} elseif (@file_exists($f = "$fichier.src")
216
-		and lire_fichier($f, $valeurs)
217
-		and $valeurs = unserialize($valeurs)
218
-		and isset($valeurs["hauteur_dest"])
219
-		and isset($valeurs["largeur_dest"])
220
-	) {
221
-		$ret["hauteur"] = $valeurs["hauteur_dest"];
222
-		$ret["largeur"] = $valeurs["largeur_dest"];
223
-		$date_src = $valeurs["date"];
224
-	} // pas de fichier source par la
225
-	else {
226
-		return false;
227
-	}
228
-
229
-	// pas de taille mesurable
230
-	if (!($ret["hauteur"] or $ret["largeur"])) {
231
-		return false;
232
-	}
233
-
234
-	// les images calculees dependent du chemin du fichier source
235
-	// pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
236
-	// ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
237
-	// qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
238
-	// la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
239
-	// alors que ca concerne peu de site au final
240
-	// la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
241
-	$identifiant = $fichier;
242
-
243
-	// cas general :
244
-	// on a un dossier cache commun et un nom de fichier qui varie avec l'effet
245
-	// cas particulier de reduire :
246
-	// un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
247
-	$cache = "cache-gd2";
248
-	if (substr($effet, 0, 7) == 'reduire') {
249
-		list(, $maxWidth, $maxHeight) = explode('-', $effet);
250
-		list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
251
-		$ret['largeur_dest'] = $destWidth;
252
-		$ret['hauteur_dest'] = $destHeight;
253
-		$effet = "L{$destWidth}xH$destHeight";
254
-		$cache = "cache-vignettes";
255
-		$fichier_dest = basename($fichier_dest);
256
-		if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
257
-			// on garde la terminaison initiale car image simplement copiee
258
-			// et on postfixe son nom avec un md5 du path
259
-			$terminaison_dest = $terminaison;
260
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
261
-		} else {
262
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
263
-		}
264
-		$cache = sous_repertoire(_DIR_VAR, $cache);
265
-		$cache = sous_repertoire($cache, $effet);
266
-		# cherche un cache existant
267
-		/*foreach (array('gif','jpg','png') as $fmt)
148
+    static $images_recalcul = array();
149
+    if (strlen($img) == 0) {
150
+        return false;
151
+    }
152
+
153
+    $source = trim(extraire_attribut($img, 'src'));
154
+    if (strlen($source) < 1) {
155
+        $source = $img;
156
+        $img = "<img src='$source' />";
157
+    } # gerer img src="data:....base64"
158
+    elseif (preg_match('@^data:image/(jpe?g|png|gif|svg+xml);base64,(.*)$@isS', $source, $regs)) {
159
+        $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . str_replace('jpeg', 'jpg', $regs[1]);
160
+        if (!file_exists($local)) {
161
+            ecrire_fichier($local, base64_decode($regs[2]));
162
+        }
163
+        $source = $local;
164
+        $img = inserer_attribut($img, 'src', $source);
165
+        # eviter les mauvaises surprises lors de conversions de format
166
+        $img = inserer_attribut($img, 'width', '');
167
+        $img = inserer_attribut($img, 'height', '');
168
+    }
169
+
170
+    // les protocoles web prennent au moins 3 lettres
171
+    if (tester_url_absolue($source)) {
172
+        include_spip('inc/distant');
173
+        $fichier = _DIR_RACINE . copie_locale($source);
174
+        if (!$fichier) {
175
+            return "";
176
+        }
177
+    } else {
178
+        // enlever le timestamp eventuel
179
+        if (strpos($source, "?") !== false) {
180
+            $source = preg_replace(',[?][0-9]+$,', '', $source);
181
+        }
182
+        if (strpos($source, "?") !== false
183
+            and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
184
+            and file_exists($f = preg_replace(',[?].*$,', '', $source))
185
+        ) {
186
+            $source = $f;
187
+        }
188
+        $fichier = $source;
189
+    }
190
+
191
+    $terminaison_dest = "";
192
+    if ($terminaison = _image_trouver_extension($fichier)) {
193
+        $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
194
+    }
195
+
196
+    if ($forcer_format !== false
197
+        // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image
198
+        and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format,['png','gif','jpg']))) {
199
+        $terminaison_dest = $forcer_format;
200
+    }
201
+
202
+    if (!$terminaison_dest) {
203
+        return false;
204
+    }
205
+
206
+    $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
207
+    $fichier_dest = $nom_fichier;
208
+    if (($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
209
+        or @file_exists($f = $fichier)
210
+    ) {
211
+        // on passe la balise img a taille image qui exraira les attributs si possible
212
+        // au lieu de faire un acces disque sur le fichier
213
+        list($ret["hauteur"], $ret["largeur"]) = taille_image($find_in_path ? $f : $img);
214
+        $date_src = @filemtime($f);
215
+    } elseif (@file_exists($f = "$fichier.src")
216
+        and lire_fichier($f, $valeurs)
217
+        and $valeurs = unserialize($valeurs)
218
+        and isset($valeurs["hauteur_dest"])
219
+        and isset($valeurs["largeur_dest"])
220
+    ) {
221
+        $ret["hauteur"] = $valeurs["hauteur_dest"];
222
+        $ret["largeur"] = $valeurs["largeur_dest"];
223
+        $date_src = $valeurs["date"];
224
+    } // pas de fichier source par la
225
+    else {
226
+        return false;
227
+    }
228
+
229
+    // pas de taille mesurable
230
+    if (!($ret["hauteur"] or $ret["largeur"])) {
231
+        return false;
232
+    }
233
+
234
+    // les images calculees dependent du chemin du fichier source
235
+    // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
236
+    // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
237
+    // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
238
+    // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
239
+    // alors que ca concerne peu de site au final
240
+    // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
241
+    $identifiant = $fichier;
242
+
243
+    // cas general :
244
+    // on a un dossier cache commun et un nom de fichier qui varie avec l'effet
245
+    // cas particulier de reduire :
246
+    // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
247
+    $cache = "cache-gd2";
248
+    if (substr($effet, 0, 7) == 'reduire') {
249
+        list(, $maxWidth, $maxHeight) = explode('-', $effet);
250
+        list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
251
+        $ret['largeur_dest'] = $destWidth;
252
+        $ret['hauteur_dest'] = $destHeight;
253
+        $effet = "L{$destWidth}xH$destHeight";
254
+        $cache = "cache-vignettes";
255
+        $fichier_dest = basename($fichier_dest);
256
+        if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
257
+            // on garde la terminaison initiale car image simplement copiee
258
+            // et on postfixe son nom avec un md5 du path
259
+            $terminaison_dest = $terminaison;
260
+            $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
261
+        } else {
262
+            $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
263
+        }
264
+        $cache = sous_repertoire(_DIR_VAR, $cache);
265
+        $cache = sous_repertoire($cache, $effet);
266
+        # cherche un cache existant
267
+        /*foreach (array('gif','jpg','png') as $fmt)
268 268
 			if (@file_exists($cache . $fichier_dest . '.' . $fmt)) {
269 269
 				$terminaison_dest = $fmt;
270 270
 			}*/
271
-	} else {
272
-		$fichier_dest = md5("$identifiant-$effet");
273
-		$cache = sous_repertoire(_DIR_VAR, $cache);
274
-		$cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
275
-		$fichier_dest = substr($fichier_dest, 2);
276
-	}
277
-
278
-	$fichier_dest = $cache . $fichier_dest . "." . $terminaison_dest;
279
-
280
-	$GLOBALS["images_calculees"][] = $fichier_dest;
281
-
282
-	$creer = true;
283
-	// si recalcul des images demande, recalculer chaque image une fois
284
-	if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
285
-		$images_recalcul[$fichier_dest] = true;
286
-	} else {
287
-		if (@file_exists($f = $fichier_dest)) {
288
-			if (filemtime($f) >= $date_src) {
289
-				$creer = false;
290
-			}
291
-		} else {
292
-			if (@file_exists($f = "$fichier_dest.src")
293
-				and lire_fichier($f, $valeurs)
294
-				and $valeurs = unserialize($valeurs)
295
-				and $valeurs["date"] >= $date_src
296
-			) {
297
-				$creer = false;
298
-			}
299
-		}
300
-	}
301
-	if ($creer) {
302
-		if (!@file_exists($fichier)) {
303
-			if (!@file_exists("$fichier.src")) {
304
-				spip_log("Image absente : $fichier");
305
-
306
-				return false;
307
-			}
308
-			# on reconstruit l'image source absente a partir de la chaine des .src
309
-			reconstruire_image_intermediaire($fichier);
310
-		}
311
-	}
312
-
313
-	if ($creer) {
314
-		spip_log("filtre image " . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
315
-			"images" . _LOG_DEBUG);
316
-	}
317
-
318
-	$term_fonction = _image_trouver_extension_pertinente($fichier);
319
-	$ret["fonction_imagecreatefrom"] = "_imagecreatefrom" . $term_fonction;
320
-	$ret["fichier"] = $fichier;
321
-	$ret["fonction_image"] = "_image_image" . $terminaison_dest;
322
-	$ret["fichier_dest"] = $fichier_dest;
323
-	$ret["format_source"] = ($terminaison != 'jpeg' ? $terminaison : 'jpg');
324
-	$ret["format_dest"] = $terminaison_dest;
325
-	$ret["date_src"] = $date_src;
326
-	$ret["creer"] = $creer;
327
-	$ret["class"] = extraire_attribut($img, 'class');
328
-	$ret["alt"] = extraire_attribut($img, 'alt');
329
-	$ret["style"] = extraire_attribut($img, 'style');
330
-	$ret["tag"] = $img;
331
-	if ($fonction_creation) {
332
-		$ret["reconstruction"] = $fonction_creation;
333
-		# ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement 
334
-		# cas de image_reduire qui finalement ne reduit pas l'image source
335
-		# ca evite d'essayer de le creer au prochain hit si il n'est pas la
336
-		#ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
337
-	}
338
-
339
-	$ret = pipeline('image_preparer_filtre', array(
340
-			'args' => array(
341
-				'img' => $img,
342
-				'effet' => $effet,
343
-				'forcer_format' => $forcer_format,
344
-				'fonction_creation' => $fonction_creation,
345
-				'find_in_path' => $find_in_path,
346
-			),
347
-			'data' => $ret
348
-		)
349
-	);
350
-
351
-	// une globale pour le debug en cas de crash memoire
352
-	$GLOBALS["derniere_image_calculee"] = $ret;
353
-
354
-	// traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
355
-	if ($term_fonction === 'svg') {
356
-		if ($creer and !$support_svg) {
357
-			process_image_svg_identite($ret);
358
-			$ret['creer'] = false;
359
-		}
360
-	}
361
-	else {
362
-		if (!function_exists($ret["fonction_imagecreatefrom"])) {
363
-			return false;
364
-		}
365
-	}
366
-
367
-	return $ret;
271
+    } else {
272
+        $fichier_dest = md5("$identifiant-$effet");
273
+        $cache = sous_repertoire(_DIR_VAR, $cache);
274
+        $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
275
+        $fichier_dest = substr($fichier_dest, 2);
276
+    }
277
+
278
+    $fichier_dest = $cache . $fichier_dest . "." . $terminaison_dest;
279
+
280
+    $GLOBALS["images_calculees"][] = $fichier_dest;
281
+
282
+    $creer = true;
283
+    // si recalcul des images demande, recalculer chaque image une fois
284
+    if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
285
+        $images_recalcul[$fichier_dest] = true;
286
+    } else {
287
+        if (@file_exists($f = $fichier_dest)) {
288
+            if (filemtime($f) >= $date_src) {
289
+                $creer = false;
290
+            }
291
+        } else {
292
+            if (@file_exists($f = "$fichier_dest.src")
293
+                and lire_fichier($f, $valeurs)
294
+                and $valeurs = unserialize($valeurs)
295
+                and $valeurs["date"] >= $date_src
296
+            ) {
297
+                $creer = false;
298
+            }
299
+        }
300
+    }
301
+    if ($creer) {
302
+        if (!@file_exists($fichier)) {
303
+            if (!@file_exists("$fichier.src")) {
304
+                spip_log("Image absente : $fichier");
305
+
306
+                return false;
307
+            }
308
+            # on reconstruit l'image source absente a partir de la chaine des .src
309
+            reconstruire_image_intermediaire($fichier);
310
+        }
311
+    }
312
+
313
+    if ($creer) {
314
+        spip_log("filtre image " . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
315
+            "images" . _LOG_DEBUG);
316
+    }
317
+
318
+    $term_fonction = _image_trouver_extension_pertinente($fichier);
319
+    $ret["fonction_imagecreatefrom"] = "_imagecreatefrom" . $term_fonction;
320
+    $ret["fichier"] = $fichier;
321
+    $ret["fonction_image"] = "_image_image" . $terminaison_dest;
322
+    $ret["fichier_dest"] = $fichier_dest;
323
+    $ret["format_source"] = ($terminaison != 'jpeg' ? $terminaison : 'jpg');
324
+    $ret["format_dest"] = $terminaison_dest;
325
+    $ret["date_src"] = $date_src;
326
+    $ret["creer"] = $creer;
327
+    $ret["class"] = extraire_attribut($img, 'class');
328
+    $ret["alt"] = extraire_attribut($img, 'alt');
329
+    $ret["style"] = extraire_attribut($img, 'style');
330
+    $ret["tag"] = $img;
331
+    if ($fonction_creation) {
332
+        $ret["reconstruction"] = $fonction_creation;
333
+        # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement 
334
+        # cas de image_reduire qui finalement ne reduit pas l'image source
335
+        # ca evite d'essayer de le creer au prochain hit si il n'est pas la
336
+        #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
337
+    }
338
+
339
+    $ret = pipeline('image_preparer_filtre', array(
340
+            'args' => array(
341
+                'img' => $img,
342
+                'effet' => $effet,
343
+                'forcer_format' => $forcer_format,
344
+                'fonction_creation' => $fonction_creation,
345
+                'find_in_path' => $find_in_path,
346
+            ),
347
+            'data' => $ret
348
+        )
349
+    );
350
+
351
+    // une globale pour le debug en cas de crash memoire
352
+    $GLOBALS["derniere_image_calculee"] = $ret;
353
+
354
+    // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
355
+    if ($term_fonction === 'svg') {
356
+        if ($creer and !$support_svg) {
357
+            process_image_svg_identite($ret);
358
+            $ret['creer'] = false;
359
+        }
360
+    }
361
+    else {
362
+        if (!function_exists($ret["fonction_imagecreatefrom"])) {
363
+            return false;
364
+        }
365
+    }
366
+
367
+    return $ret;
368 368
 }
369 369
 
370 370
 /**
@@ -373,11 +373,11 @@  discard block
 block discarded – undo
373 373
  * @return string
374 374
  */
375 375
 function _image_trouver_extension($path) {
376
-	if (preg_match(",\.(gif|jpe?g|png|svg)($|[?]),i", $path, $regs)) {
377
-		$terminaison = strtolower($regs[1]);
378
-		return $terminaison;
379
-	}
380
-	return '';
376
+    if (preg_match(",\.(gif|jpe?g|png|svg)($|[?]),i", $path, $regs)) {
377
+        $terminaison = strtolower($regs[1]);
378
+        return $terminaison;
379
+    }
380
+    return '';
381 381
 }
382 382
 
383 383
 /**
@@ -388,60 +388,60 @@  discard block
 block discarded – undo
388 388
  * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple)
389 389
  */
390 390
 function _image_trouver_extension_pertinente($path) {
391
-	$path = supprimer_timestamp($path);
392
-	$terminaison = _image_trouver_extension($path);
393
-	if ($terminaison == 'jpg') {
394
-		$terminaison = 'jpeg';
395
-	}
396
-
397
-	if (!file_exists($path)) {
398
-		return $terminaison;
399
-	}
400
-
401
-	if (!$info = @spip_getimagesize($path)) {
402
-		return $terminaison;
403
-	}
404
-
405
-	if (isset($info['mime'])) {
406
-		$mime = $info['mime'];
407
-	}
408
-	else {
409
-		$mime = image_type_to_mime_type($info[2]);
410
-	}
411
-
412
-	switch (strtolower($mime)) {
413
-		case 'image/png':
414
-		case 'image/x-png':
415
-			$_terminaison = 'png';
416
-			break;
417
-
418
-		case 'image/jpg':
419
-		case 'image/jpeg':
420
-		case 'image/pjpeg':
421
-			$_terminaison = 'jpeg';
422
-			break;
423
-
424
-		case 'image/gif':
425
-			$_terminaison = 'gif';
426
-			break;
427
-
428
-		case 'image/webp':
429
-		case 'image/x-webp':
430
-			$_terminaison = 'webp';
431
-			break;
432
-
433
-		case 'image/svg+xml':
434
-			$_terminaison = 'svg';
435
-			break;
436
-
437
-		default:
438
-			$_terminaison = '';
439
-	}
440
-	if ($_terminaison and $_terminaison !== $terminaison) {
441
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", "images." . _LOG_INFO_IMPORTANTE);
442
-		$terminaison = $_terminaison;
443
-	}
444
-	return $terminaison;
391
+    $path = supprimer_timestamp($path);
392
+    $terminaison = _image_trouver_extension($path);
393
+    if ($terminaison == 'jpg') {
394
+        $terminaison = 'jpeg';
395
+    }
396
+
397
+    if (!file_exists($path)) {
398
+        return $terminaison;
399
+    }
400
+
401
+    if (!$info = @spip_getimagesize($path)) {
402
+        return $terminaison;
403
+    }
404
+
405
+    if (isset($info['mime'])) {
406
+        $mime = $info['mime'];
407
+    }
408
+    else {
409
+        $mime = image_type_to_mime_type($info[2]);
410
+    }
411
+
412
+    switch (strtolower($mime)) {
413
+        case 'image/png':
414
+        case 'image/x-png':
415
+            $_terminaison = 'png';
416
+            break;
417
+
418
+        case 'image/jpg':
419
+        case 'image/jpeg':
420
+        case 'image/pjpeg':
421
+            $_terminaison = 'jpeg';
422
+            break;
423
+
424
+        case 'image/gif':
425
+            $_terminaison = 'gif';
426
+            break;
427
+
428
+        case 'image/webp':
429
+        case 'image/x-webp':
430
+            $_terminaison = 'webp';
431
+            break;
432
+
433
+        case 'image/svg+xml':
434
+            $_terminaison = 'svg';
435
+            break;
436
+
437
+        default:
438
+            $_terminaison = '';
439
+    }
440
+    if ($_terminaison and $_terminaison !== $terminaison) {
441
+        spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", "images." . _LOG_INFO_IMPORTANTE);
442
+        $terminaison = $_terminaison;
443
+    }
444
+    return $terminaison;
445 445
 }
446 446
 
447 447
 /**
@@ -456,14 +456,14 @@  discard block
 block discarded – undo
456 456
  *     Une ressource de type Image GD.
457 457
  */
458 458
 function _imagecreatefromjpeg($filename) {
459
-	$img = @imagecreatefromjpeg($filename);
460
-	if (!$img) {
461
-		spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
462
-		erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
463
-		$img = imagecreate(10, 10);
464
-	}
465
-
466
-	return $img;
459
+    $img = @imagecreatefromjpeg($filename);
460
+    if (!$img) {
461
+        spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
462
+        erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
463
+        $img = imagecreate(10, 10);
464
+    }
465
+
466
+    return $img;
467 467
 }
468 468
 
469 469
 /**
@@ -478,14 +478,14 @@  discard block
 block discarded – undo
478 478
  *     Une ressource de type Image GD.
479 479
  */
480 480
 function _imagecreatefrompng($filename) {
481
-	$img = @imagecreatefrompng($filename);
482
-	if (!$img) {
483
-		spip_log("Erreur lecture imagecreatefrompng $filename", _LOG_CRITIQUE);
484
-		erreur_squelette("Erreur lecture imagecreatefrompng $filename");
485
-		$img = imagecreate(10, 10);
486
-	}
487
-
488
-	return $img;
481
+    $img = @imagecreatefrompng($filename);
482
+    if (!$img) {
483
+        spip_log("Erreur lecture imagecreatefrompng $filename", _LOG_CRITIQUE);
484
+        erreur_squelette("Erreur lecture imagecreatefrompng $filename");
485
+        $img = imagecreate(10, 10);
486
+    }
487
+
488
+    return $img;
489 489
 }
490 490
 
491 491
 /**
@@ -500,14 +500,14 @@  discard block
 block discarded – undo
500 500
  *     Une ressource de type Image GD.
501 501
  */
502 502
 function _imagecreatefromgif($filename) {
503
-	$img = @imagecreatefromgif($filename);
504
-	if (!$img) {
505
-		spip_log("Erreur lecture imagecreatefromgif $filename", _LOG_CRITIQUE);
506
-		erreur_squelette("Erreur lecture imagecreatefromgif $filename");
507
-		$img = imagecreate(10, 10);
508
-	}
509
-
510
-	return $img;
503
+    $img = @imagecreatefromgif($filename);
504
+    if (!$img) {
505
+        spip_log("Erreur lecture imagecreatefromgif $filename", _LOG_CRITIQUE);
506
+        erreur_squelette("Erreur lecture imagecreatefromgif $filename");
507
+        $img = imagecreate(10, 10);
508
+    }
509
+
510
+    return $img;
511 511
 }
512 512
 
513 513
 /**
@@ -525,24 +525,24 @@  discard block
 block discarded – undo
525 525
  *     - true si une image est bien retournée.
526 526
  */
527 527
 function _image_imagepng($img, $fichier) {
528
-	if (!function_exists('imagepng')) {
529
-		return false;
530
-	}
531
-	$tmp = $fichier . ".tmp";
532
-	$ret = imagepng($img, $tmp);
533
-	if (file_exists($tmp)) {
534
-		$taille_test = getimagesize($tmp);
535
-		if ($taille_test[0] < 1) {
536
-			return false;
537
-		}
538
-
539
-		spip_unlink($fichier); // le fichier peut deja exister
540
-		@rename($tmp, $fichier);
541
-
542
-		return $ret;
543
-	}
544
-
545
-	return false;
528
+    if (!function_exists('imagepng')) {
529
+        return false;
530
+    }
531
+    $tmp = $fichier . ".tmp";
532
+    $ret = imagepng($img, $tmp);
533
+    if (file_exists($tmp)) {
534
+        $taille_test = getimagesize($tmp);
535
+        if ($taille_test[0] < 1) {
536
+            return false;
537
+        }
538
+
539
+        spip_unlink($fichier); // le fichier peut deja exister
540
+        @rename($tmp, $fichier);
541
+
542
+        return $ret;
543
+    }
544
+
545
+    return false;
546 546
 }
547 547
 
548 548
 /**
@@ -560,24 +560,24 @@  discard block
 block discarded – undo
560 560
  *     - true si une image est bien retournée.
561 561
  */
562 562
 function _image_imagegif($img, $fichier) {
563
-	if (!function_exists('imagegif')) {
564
-		return false;
565
-	}
566
-	$tmp = $fichier . ".tmp";
567
-	$ret = imagegif($img, $tmp);
568
-	if (file_exists($tmp)) {
569
-		$taille_test = getimagesize($tmp);
570
-		if ($taille_test[0] < 1) {
571
-			return false;
572
-		}
573
-
574
-		spip_unlink($fichier); // le fichier peut deja exister
575
-		@rename($tmp, $fichier);
576
-
577
-		return $ret;
578
-	}
579
-
580
-	return false;
563
+    if (!function_exists('imagegif')) {
564
+        return false;
565
+    }
566
+    $tmp = $fichier . ".tmp";
567
+    $ret = imagegif($img, $tmp);
568
+    if (file_exists($tmp)) {
569
+        $taille_test = getimagesize($tmp);
570
+        if ($taille_test[0] < 1) {
571
+            return false;
572
+        }
573
+
574
+        spip_unlink($fichier); // le fichier peut deja exister
575
+        @rename($tmp, $fichier);
576
+
577
+        return $ret;
578
+    }
579
+
580
+    return false;
581 581
 }
582 582
 
583 583
 /**
@@ -600,29 +600,29 @@  discard block
 block discarded – undo
600 600
  *     - true si une image est bien retournée.
601 601
  */
602 602
 function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) {
603
-	if (!function_exists('imagejpeg')) {
604
-		return false;
605
-	}
606
-	$tmp = $fichier . ".tmp";
603
+    if (!function_exists('imagejpeg')) {
604
+        return false;
605
+    }
606
+    $tmp = $fichier . ".tmp";
607 607
 
608
-	// Enable interlancing
609
-	imageinterlace($img, true);
608
+    // Enable interlancing
609
+    imageinterlace($img, true);
610 610
 
611
-	$ret = imagejpeg($img, $tmp, $qualite);
611
+    $ret = imagejpeg($img, $tmp, $qualite);
612 612
 
613
-	if (file_exists($tmp)) {
614
-		$taille_test = getimagesize($tmp);
615
-		if ($taille_test[0] < 1) {
616
-			return false;
617
-		}
613
+    if (file_exists($tmp)) {
614
+        $taille_test = getimagesize($tmp);
615
+        if ($taille_test[0] < 1) {
616
+            return false;
617
+        }
618 618
 
619
-		spip_unlink($fichier); // le fichier peut deja exister
620
-		@rename($tmp, $fichier);
619
+        spip_unlink($fichier); // le fichier peut deja exister
620
+        @rename($tmp, $fichier);
621 621
 
622
-		return $ret;
623
-	}
622
+        return $ret;
623
+    }
624 624
 
625
-	return false;
625
+    return false;
626 626
 }
627 627
 
628 628
 /**
@@ -640,9 +640,9 @@  discard block
 block discarded – undo
640 640
  *     true si le fichier a bien été créé ; false sinon.
641 641
  */
642 642
 function _image_imageico($img, $fichier) {
643
-	$gd_image_array = array($img);
643
+    $gd_image_array = array($img);
644 644
 
645
-	return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
645
+    return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
646 646
 }
647 647
 
648 648
 
@@ -663,35 +663,35 @@  discard block
 block discarded – undo
663 663
  */
664 664
 function _image_imagesvg($img, $fichier) {
665 665
 
666
-	$tmp = $fichier . ".tmp";
667
-	if (strpos($img, "<") === false) {
668
-		$img = supprimer_timestamp($img);
669
-		if (!file_exists($img)) {
670
-			return false;
671
-		}
672
-		@copy($img, $tmp);
673
-		if (filesize($tmp) == filesize($img)) {
674
-			spip_unlink($fichier); // le fichier peut deja exister
675
-			@rename($tmp, $fichier);
676
-			return true;
677
-		}
678
-		return false;
679
-	}
680
-
681
-	file_put_contents($tmp, $img);
682
-	if (file_exists($tmp)) {
683
-		$taille_test = spip_getimagesize($tmp);
684
-		if ($taille_test[0] < 1) {
685
-			return false;
686
-		}
687
-
688
-		spip_unlink($fichier); // le fichier peut deja exister
689
-		@rename($tmp, $fichier);
690
-
691
-		return true;
692
-	}
693
-
694
-	return false;
666
+    $tmp = $fichier . ".tmp";
667
+    if (strpos($img, "<") === false) {
668
+        $img = supprimer_timestamp($img);
669
+        if (!file_exists($img)) {
670
+            return false;
671
+        }
672
+        @copy($img, $tmp);
673
+        if (filesize($tmp) == filesize($img)) {
674
+            spip_unlink($fichier); // le fichier peut deja exister
675
+            @rename($tmp, $fichier);
676
+            return true;
677
+        }
678
+        return false;
679
+    }
680
+
681
+    file_put_contents($tmp, $img);
682
+    if (file_exists($tmp)) {
683
+        $taille_test = spip_getimagesize($tmp);
684
+        if ($taille_test[0] < 1) {
685
+            return false;
686
+        }
687
+
688
+        spip_unlink($fichier); // le fichier peut deja exister
689
+        @rename($tmp, $fichier);
690
+
691
+        return true;
692
+    }
693
+
694
+    return false;
695 695
 }
696 696
 
697 697
 
@@ -719,27 +719,27 @@  discard block
 block discarded – undo
719 719
  *     - false sinon.
720 720
  */
721 721
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE) {
722
-	$fonction = "_image_image" . $valeurs['format_dest'];
723
-	$ret = false;
724
-	#un flag pour reperer les images gravees
725
-	$lock =
726
-		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
727
-	or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
728
-	if (
729
-		function_exists($fonction)
730
-		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
731
-		&& isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
732
-		&& !$lock
733
-	) {
734
-		if (@file_exists($valeurs['fichier_dest'])) {
735
-			// dans tous les cas mettre a jour la taille de l'image finale
736
-			list($valeurs["hauteur_dest"], $valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']);
737
-			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
738
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
739
-		}
740
-	}
741
-
742
-	return $ret;
722
+    $fonction = "_image_image" . $valeurs['format_dest'];
723
+    $ret = false;
724
+    #un flag pour reperer les images gravees
725
+    $lock =
726
+        !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
727
+    or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
728
+    if (
729
+        function_exists($fonction)
730
+        && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
731
+        && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
732
+        && !$lock
733
+    ) {
734
+        if (@file_exists($valeurs['fichier_dest'])) {
735
+            // dans tous les cas mettre a jour la taille de l'image finale
736
+            list($valeurs["hauteur_dest"], $valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']);
737
+            $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
738
+            ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
739
+        }
740
+    }
741
+
742
+    return $ret;
743 743
 }
744 744
 
745 745
 /**
@@ -752,26 +752,26 @@  discard block
 block discarded – undo
752 752
  *     Chemin vers le fichier manquant
753 753
  **/
754 754
 function reconstruire_image_intermediaire($fichier_manquant) {
755
-	$reconstruire = array();
756
-	$fichier = $fichier_manquant;
757
-	while (strpos($fichier,"://")===false
758
-		and !@file_exists($fichier)
759
-		and lire_fichier($src = "$fichier.src", $source)
760
-		and $valeurs = unserialize($source)
761
-		and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
762
-	) {
763
-		spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
764
-		$reconstruire[] = $valeurs['reconstruction'];
765
-	}
766
-	while (count($reconstruire)) {
767
-		$r = array_pop($reconstruire);
768
-		$fonction = $r[0];
769
-		$args = $r[1];
770
-		call_user_func_array($fonction, $args);
771
-	}
772
-	// cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
773
-	// mais l'on peut nettoyer les miettes de sa creation
774
-	ramasse_miettes($fichier_manquant);
755
+    $reconstruire = array();
756
+    $fichier = $fichier_manquant;
757
+    while (strpos($fichier,"://")===false
758
+        and !@file_exists($fichier)
759
+        and lire_fichier($src = "$fichier.src", $source)
760
+        and $valeurs = unserialize($source)
761
+        and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
762
+    ) {
763
+        spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
764
+        $reconstruire[] = $valeurs['reconstruction'];
765
+    }
766
+    while (count($reconstruire)) {
767
+        $r = array_pop($reconstruire);
768
+        $fonction = $r[0];
769
+        $args = $r[1];
770
+        call_user_func_array($fonction, $args);
771
+    }
772
+    // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
773
+    // mais l'on peut nettoyer les miettes de sa creation
774
+    ramasse_miettes($fichier_manquant);
775 775
 }
776 776
 
777 777
 /**
@@ -791,25 +791,25 @@  discard block
 block discarded – undo
791 791
  *     Chemin du fichier d'image calculé
792 792
  **/
793 793
 function ramasse_miettes($fichier) {
794
-	if (strpos($fichier,"://")!==false
795
-		or !lire_fichier($src = "$fichier.src", $source)
796
-		or !$valeurs = unserialize($source)
797
-	) {
798
-		return;
799
-	}
800
-	spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
801
-	while (
802
-		($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
803
-		and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
804
-		and (lire_fichier($src = "$fichier.src",
805
-			$source)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
806
-		and ($valeurs = unserialize($source))  # et valide
807
-	) {
808
-		# on efface le fichier
809
-		spip_unlink($fichier);
810
-		# mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
811
-		#spip_unlink($src);
812
-	}
794
+    if (strpos($fichier,"://")!==false
795
+        or !lire_fichier($src = "$fichier.src", $source)
796
+        or !$valeurs = unserialize($source)
797
+    ) {
798
+        return;
799
+    }
800
+    spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
801
+    while (
802
+        ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
803
+        and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
804
+        and (lire_fichier($src = "$fichier.src",
805
+            $source)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
806
+        and ($valeurs = unserialize($source))  # et valide
807
+    ) {
808
+        # on efface le fichier
809
+        spip_unlink($fichier);
810
+        # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
811
+        #spip_unlink($src);
812
+    }
813 813
 }
814 814
 
815 815
 
@@ -834,71 +834,71 @@  discard block
 block discarded – undo
834 834
  *     Code HTML de l'image
835 835
  **/
836 836
 function image_graver($img) {
837
-	// appeler le filtre post_image_filtrer qui permet de faire
838
-	// des traitements auto a la fin d'une serie de filtres
839
-	$img = pipeline('post_image_filtrer', $img);
840
-
841
-	$fichier_ori = $fichier = extraire_attribut($img, 'src');
842
-	if (($p = strpos($fichier, '?')) !== false) {
843
-		$fichier = substr($fichier, 0, $p);
844
-	}
845
-	if (strlen($fichier) < 1) {
846
-		$fichier = $img;
847
-	}
848
-	# si jamais le fichier final n'a pas ete calcule car suppose temporaire
849
-	# et qu'il ne s'agit pas d'une URL
850
-	if (strpos($fichier,"://")===false and !@file_exists($fichier)) {
851
-		reconstruire_image_intermediaire($fichier);
852
-	}
853
-	ramasse_miettes($fichier);
854
-
855
-	// ajouter le timestamp si besoin
856
-	if (strpos($fichier_ori, "?") === false) {
857
-		// on utilise str_replace pour attraper le onmouseover des logo si besoin
858
-		$img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
859
-	}
860
-
861
-	return $img;
837
+    // appeler le filtre post_image_filtrer qui permet de faire
838
+    // des traitements auto a la fin d'une serie de filtres
839
+    $img = pipeline('post_image_filtrer', $img);
840
+
841
+    $fichier_ori = $fichier = extraire_attribut($img, 'src');
842
+    if (($p = strpos($fichier, '?')) !== false) {
843
+        $fichier = substr($fichier, 0, $p);
844
+    }
845
+    if (strlen($fichier) < 1) {
846
+        $fichier = $img;
847
+    }
848
+    # si jamais le fichier final n'a pas ete calcule car suppose temporaire
849
+    # et qu'il ne s'agit pas d'une URL
850
+    if (strpos($fichier,"://")===false and !@file_exists($fichier)) {
851
+        reconstruire_image_intermediaire($fichier);
852
+    }
853
+    ramasse_miettes($fichier);
854
+
855
+    // ajouter le timestamp si besoin
856
+    if (strpos($fichier_ori, "?") === false) {
857
+        // on utilise str_replace pour attraper le onmouseover des logo si besoin
858
+        $img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
859
+    }
860
+
861
+    return $img;
862 862
 }
863 863
 
864 864
 
865 865
 if (!function_exists("imagepalettetotruecolor")) {
866
-	/**
867
-	 * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB
868
-	 *
869
-	 * @note Pour compatibilité avec PHP < 5.5
870
-	 *
871
-	 * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php
872
-	 *
873
-	 * @param ressource $img
874
-	 * @return bool
875
-	 *     - true si l'image est déjà en vrai RGB ou peut être transformée
876
-	 *     - false si la transformation ne peut être faite.
877
-	 **/
878
-	function imagepalettetotruecolor(&$img) {
879
-		if (!$img or !function_exists('imagecreatetruecolor')) {
880
-			return false;
881
-		} elseif (!imageistruecolor($img)) {
882
-			$w = imagesx($img);
883
-			$h = imagesy($img);
884
-			$img1 = imagecreatetruecolor($w, $h);
885
-			//Conserver la transparence si possible
886
-			if (function_exists('ImageCopyResampled')) {
887
-				if (function_exists("imageAntiAlias")) {
888
-					imageAntiAlias($img1, true);
889
-				}
890
-				@imagealphablending($img1, false);
891
-				@imagesavealpha($img1, true);
892
-				@ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
893
-			} else {
894
-				imagecopy($img1, $img, 0, 0, 0, 0, $w, $h);
895
-			}
896
-
897
-			$img = $img1;
898
-		}
899
-
900
-		return true;
901
-	}
866
+    /**
867
+     * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB
868
+     *
869
+     * @note Pour compatibilité avec PHP < 5.5
870
+     *
871
+     * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php
872
+     *
873
+     * @param ressource $img
874
+     * @return bool
875
+     *     - true si l'image est déjà en vrai RGB ou peut être transformée
876
+     *     - false si la transformation ne peut être faite.
877
+     **/
878
+    function imagepalettetotruecolor(&$img) {
879
+        if (!$img or !function_exists('imagecreatetruecolor')) {
880
+            return false;
881
+        } elseif (!imageistruecolor($img)) {
882
+            $w = imagesx($img);
883
+            $h = imagesy($img);
884
+            $img1 = imagecreatetruecolor($w, $h);
885
+            //Conserver la transparence si possible
886
+            if (function_exists('ImageCopyResampled')) {
887
+                if (function_exists("imageAntiAlias")) {
888
+                    imageAntiAlias($img1, true);
889
+                }
890
+                @imagealphablending($img1, false);
891
+                @imagesavealpha($img1, true);
892
+                @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
893
+            } else {
894
+                imagecopy($img1, $img, 0, 0, 0, 0, $w, $h);
895
+            }
896
+
897
+            $img = $img1;
898
+        }
899
+
900
+        return true;
901
+    }
902 902
 }
903 903
 
904 904
 /**
@@ -925,32 +925,32 @@  discard block
 block discarded – undo
925 925
  *     Code html modifié de la balise.
926 926
  **/
927 927
 function _image_tag_changer_taille($tag, $width, $height, $style = false) {
928
-	if ($style === false) {
929
-		$style = extraire_attribut($tag, 'style');
930
-	}
931
-
932
-	// enlever le width et height du style
933
-	$style = preg_replace(",(^|;)\s*(width|height)\s*:\s*[^;]+,ims", "", $style);
934
-	if ($style and $style{0} == ';') {
935
-		$style = substr($style, 1);
936
-	}
937
-
938
-	// mettre des attributs de width et height sur les images, 
939
-	// ca accelere le rendu du navigateur
940
-	// ca permet aux navigateurs de reserver la bonne taille 
941
-	// quand on a desactive l'affichage des images.
942
-	$tag = inserer_attribut($tag, 'width', round($width));
943
-	$tag = inserer_attribut($tag, 'height', round($height));
944
-
945
-	// attributs deprecies. Transformer en CSS
946
-	if ($espace = extraire_attribut($tag, 'hspace')) {
947
-		$style = "margin:${espace}px;" . $style;
948
-		$tag = inserer_attribut($tag, 'hspace', '');
949
-	}
950
-
951
-	$tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true);
952
-
953
-	return $tag;
928
+    if ($style === false) {
929
+        $style = extraire_attribut($tag, 'style');
930
+    }
931
+
932
+    // enlever le width et height du style
933
+    $style = preg_replace(",(^|;)\s*(width|height)\s*:\s*[^;]+,ims", "", $style);
934
+    if ($style and $style{0} == ';') {
935
+        $style = substr($style, 1);
936
+    }
937
+
938
+    // mettre des attributs de width et height sur les images, 
939
+    // ca accelere le rendu du navigateur
940
+    // ca permet aux navigateurs de reserver la bonne taille 
941
+    // quand on a desactive l'affichage des images.
942
+    $tag = inserer_attribut($tag, 'width', round($width));
943
+    $tag = inserer_attribut($tag, 'height', round($height));
944
+
945
+    // attributs deprecies. Transformer en CSS
946
+    if ($espace = extraire_attribut($tag, 'hspace')) {
947
+        $style = "margin:${espace}px;" . $style;
948
+        $tag = inserer_attribut($tag, 'hspace', '');
949
+    }
950
+
951
+    $tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true);
952
+
953
+    return $tag;
954 954
 }
955 955
 
956 956
 
@@ -976,71 +976,71 @@  discard block
 block discarded – undo
976 976
  *     Retourne le code HTML de l'image
977 977
  **/
978 978
 function _image_ecrire_tag($valeurs, $surcharge = array()) {
979
-	$valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
980
-
981
-	// fermer les tags img pas bien fermes;
982
-	$tag = str_replace(">", "/>", str_replace("/>", ">", $valeurs['tag']));
983
-
984
-	// le style
985
-	$style = $valeurs['style'];
986
-	if (isset($surcharge['style'])) {
987
-		$style = $surcharge['style'];
988
-		unset($surcharge['style']);
989
-	}
990
-
991
-	// traiter specifiquement la largeur et la hauteur
992
-	$width = $valeurs['largeur'];
993
-	if (isset($surcharge['width'])) {
994
-		$width = $surcharge['width'];
995
-		unset($surcharge['width']);
996
-	}
997
-	$height = $valeurs['hauteur'];
998
-	if (isset($surcharge['height'])) {
999
-		$height = $surcharge['height'];
1000
-		unset($surcharge['height']);
1001
-	}
1002
-
1003
-	$tag = _image_tag_changer_taille($tag, $width, $height, $style);
1004
-	// traiter specifiquement le src qui peut etre repris dans un onmouseout
1005
-	// on remplace toute les ref a src dans le tag
1006
-	$src = extraire_attribut($tag, 'src');
1007
-	if (isset($surcharge['src'])) {
1008
-		$tag = str_replace($src, $surcharge['src'], $tag);
1009
-		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
1010
-		// pas garanti comme methode, mais mieux que rien
1011
-		if (strpos($src, '&') !== false) {
1012
-			$tag = str_replace(str_replace("&", "&amp;", $src), $surcharge['src'], $tag);
1013
-		}
1014
-		$src = $surcharge['src'];
1015
-		unset($surcharge['src']);
1016
-	}
1017
-
1018
-	$class = $valeurs['class'];
1019
-	if (isset($surcharge['class'])) {
1020
-		$class = $surcharge['class'];
1021
-		unset($surcharge['class']);
1022
-	}
1023
-	if (strlen($class)) {
1024
-		$tag = inserer_attribut($tag, 'class', $class);
1025
-	}
1026
-
1027
-	if (count($surcharge)) {
1028
-		foreach ($surcharge as $attribut => $valeur) {
1029
-			$tag = inserer_attribut($tag, $attribut, $valeur);
1030
-		}
1031
-	}
1032
-
1033
-	$tag = pipeline('image_ecrire_tag_finir',
1034
-		array(
1035
-			'args' => array(
1036
-				'valeurs' => $valeurs,
1037
-				'surcharge' => $surcharge,
1038
-			),
1039
-			'data' => $tag
1040
-		)
1041
-	);
1042
-
1043
-	return $tag;
979
+    $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
980
+
981
+    // fermer les tags img pas bien fermes;
982
+    $tag = str_replace(">", "/>", str_replace("/>", ">", $valeurs['tag']));
983
+
984
+    // le style
985
+    $style = $valeurs['style'];
986
+    if (isset($surcharge['style'])) {
987
+        $style = $surcharge['style'];
988
+        unset($surcharge['style']);
989
+    }
990
+
991
+    // traiter specifiquement la largeur et la hauteur
992
+    $width = $valeurs['largeur'];
993
+    if (isset($surcharge['width'])) {
994
+        $width = $surcharge['width'];
995
+        unset($surcharge['width']);
996
+    }
997
+    $height = $valeurs['hauteur'];
998
+    if (isset($surcharge['height'])) {
999
+        $height = $surcharge['height'];
1000
+        unset($surcharge['height']);
1001
+    }
1002
+
1003
+    $tag = _image_tag_changer_taille($tag, $width, $height, $style);
1004
+    // traiter specifiquement le src qui peut etre repris dans un onmouseout
1005
+    // on remplace toute les ref a src dans le tag
1006
+    $src = extraire_attribut($tag, 'src');
1007
+    if (isset($surcharge['src'])) {
1008
+        $tag = str_replace($src, $surcharge['src'], $tag);
1009
+        // si il y a des & dans src, alors ils peuvent provenir d'un &amp
1010
+        // pas garanti comme methode, mais mieux que rien
1011
+        if (strpos($src, '&') !== false) {
1012
+            $tag = str_replace(str_replace("&", "&amp;", $src), $surcharge['src'], $tag);
1013
+        }
1014
+        $src = $surcharge['src'];
1015
+        unset($surcharge['src']);
1016
+    }
1017
+
1018
+    $class = $valeurs['class'];
1019
+    if (isset($surcharge['class'])) {
1020
+        $class = $surcharge['class'];
1021
+        unset($surcharge['class']);
1022
+    }
1023
+    if (strlen($class)) {
1024
+        $tag = inserer_attribut($tag, 'class', $class);
1025
+    }
1026
+
1027
+    if (count($surcharge)) {
1028
+        foreach ($surcharge as $attribut => $valeur) {
1029
+            $tag = inserer_attribut($tag, $attribut, $valeur);
1030
+        }
1031
+    }
1032
+
1033
+    $tag = pipeline('image_ecrire_tag_finir',
1034
+        array(
1035
+            'args' => array(
1036
+                'valeurs' => $valeurs,
1037
+                'surcharge' => $surcharge,
1038
+            ),
1039
+            'data' => $tag
1040
+        )
1041
+    );
1042
+
1043
+    return $tag;
1044 1044
 }
1045 1045
 
1046 1046
 /**
@@ -1063,248 +1063,248 @@  discard block
 block discarded – undo
1063 1063
  *     Description de l'image, sinon null.
1064 1064
  **/
1065 1065
 function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) {
1066
-	// ordre de preference des formats graphiques pour creer les vignettes
1067
-	// le premier format disponible, selon la methode demandee, est utilise
1068
-	$image = $valeurs['fichier'];
1069
-	$format = $valeurs['format_source'];
1070
-	$destdir = dirname($valeurs['fichier_dest']);
1071
-	$destfile = basename($valeurs['fichier_dest'], "." . $valeurs["format_dest"]);
1072
-
1073
-	$format_sortie = $valeurs['format_dest'];
1074
-
1075
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1076
-		$process = $GLOBALS['meta']['image_process'];
1077
-	}
1078
-
1079
-	// si le doc n'est pas une image, refuser
1080
-	if (!$force and !in_array($format, formats_image_acceptables())) {
1081
-		return;
1082
-	}
1083
-	$destination = "$destdir/$destfile";
1084
-
1085
-	// calculer la taille
1086
-	if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1087
-		if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1088
-			list($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight);
1089
-		}
1090
-	} elseif ($process == 'convert' or $process == 'imagick') {
1091
-		$destWidth = $maxWidth;
1092
-		$destHeight = $maxHeight;
1093
-	} else {
1094
-		spip_log("echec $process sur $image");
1095
-
1096
-		return;
1097
-	}
1098
-
1099
-	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1100
-	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1101
-		$vignette = $destination . '.' . $format;
1102
-		@copy($image, $vignette);
1103
-	}
1104
-
1105
-	elseif ($valeurs["format_source"] === 'svg') {
1106
-		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)){
1107
-			$format_sortie = 'svg';
1108
-			$vignette = $destination . "." . $format_sortie;
1109
-			$valeurs['fichier_dest'] = $vignette;
1110
-			_image_gd_output($svg, $valeurs);
1111
-		}
1112
-	}
1113
-
1114
-	// imagemagick en ligne de commande
1115
-	elseif ($process == 'convert') {
1116
-		if (!defined('_CONVERT_COMMAND')) {
1117
-			define('_CONVERT_COMMAND', 'convert');
1118
-		} // Securite : mes_options.php peut preciser le chemin absolu
1119
-		if (!defined('_RESIZE_COMMAND')) {
1120
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1121
-		}
1122
-		$vignette = $destination . "." . $format_sortie;
1123
-		$commande = str_replace(
1124
-			array('%x', '%y', '%src', '%dest'),
1125
-			array(
1126
-				$destWidth,
1127
-				$destHeight,
1128
-				escapeshellcmd($image),
1129
-				escapeshellcmd($vignette)
1130
-			),
1131
-			_RESIZE_COMMAND);
1132
-		spip_log($commande);
1133
-		exec($commande);
1134
-		if (!@file_exists($vignette)) {
1135
-			spip_log("echec convert sur $vignette");
1136
-
1137
-			return;  // echec commande
1138
-		}
1139
-	}
1140
-
1141
-	// php5 imagemagick
1142
-	elseif ($process == 'imagick') {
1143
-		$vignette = "$destination." . $format_sortie;
1144
-
1145
-		if (!class_exists('Imagick')) {
1146
-			spip_log("Classe Imagick absente !", _LOG_ERREUR);
1147
-
1148
-			return;
1149
-		}
1150
-		$imagick = new Imagick();
1151
-		$imagick->readImage($image);
1152
-		$imagick->resizeImage($destWidth, $destHeight, Imagick::FILTER_LANCZOS,
1153
-			1);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1154
-		$imagick->writeImage($vignette);
1155
-
1156
-		if (!@file_exists($vignette)) {
1157
-			spip_log("echec imagick sur $vignette");
1158
-
1159
-			return;
1160
-		}
1161
-	}
1162
-
1163
-	// netpbm
1164
-	elseif ($process == "netpbm") {
1165
-		if (!defined('_PNMSCALE_COMMAND')) {
1166
-			define('_PNMSCALE_COMMAND', 'pnmscale');
1167
-		} // Securite : mes_options.php peut preciser le chemin absolu
1168
-		if (_PNMSCALE_COMMAND == '') {
1169
-			return;
1170
-		}
1171
-		$vignette = $destination . "." . $format_sortie;
1172
-		$pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND);
1173
-		if ($format == "jpg") {
1174
-
1175
-			$jpegtopnm_command = str_replace("pnmscale", "jpegtopnm", _PNMSCALE_COMMAND);
1176
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1177
-			if (!($s = @filesize($vignette))) {
1178
-				spip_unlink($vignette);
1179
-			}
1180
-			if (!@file_exists($vignette)) {
1181
-				spip_log("echec netpbm-jpg sur $vignette");
1182
-
1183
-				return;
1184
-			}
1185
-		} else {
1186
-			if ($format == "gif") {
1187
-				$giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND);
1188
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1189
-				if (!($s = @filesize($vignette))) {
1190
-					spip_unlink($vignette);
1191
-				}
1192
-				if (!@file_exists($vignette)) {
1193
-					spip_log("echec netpbm-gif sur $vignette");
1194
-
1195
-					return;
1196
-				}
1197
-			} else {
1198
-				if ($format == "png") {
1199
-					$pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND);
1200
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1201
-					if (!($s = @filesize($vignette))) {
1202
-						spip_unlink($vignette);
1203
-					}
1204
-					if (!@file_exists($vignette)) {
1205
-						spip_log("echec netpbm-png sur $vignette");
1206
-
1207
-						return;
1208
-					}
1209
-				}
1210
-			}
1211
-		}
1212
-	}
1213
-
1214
-	// gd ou gd2
1215
-	elseif ($process == 'gd1' or $process == 'gd2') {
1216
-		if (!function_exists('gd_info')) {
1217
-			spip_log("Librairie GD absente !", _LOG_ERREUR);
1218
-
1219
-			return;
1220
-		}
1221
-		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1222
-			spip_log("vignette gd1/gd2 impossible : " . $srcWidth * $srcHeight . "pixels");
1223
-
1224
-			return;
1225
-		}
1226
-		$destFormat = $format_sortie;
1227
-		if (!$destFormat) {
1228
-			spip_log("pas de format pour $image");
1229
-
1230
-			return;
1231
-		}
1232
-
1233
-		$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1234
-		if (!function_exists($fonction_imagecreatefrom)) {
1235
-			return '';
1236
-		}
1237
-		$srcImage = @$fonction_imagecreatefrom($image);
1238
-		if (!$srcImage) {
1239
-			spip_log("echec gd1/gd2");
1240
-
1241
-			return;
1242
-		}
1243
-
1244
-		// Initialisation de l'image destination
1245
-		$destImage = null;
1246
-		if ($process == 'gd2' and $destFormat != "gif") {
1247
-			$destImage = ImageCreateTrueColor($destWidth, $destHeight);
1248
-		}
1249
-		if (!$destImage) {
1250
-			$destImage = ImageCreate($destWidth, $destHeight);
1251
-		}
1252
-
1253
-		// Recopie de l'image d'origine avec adaptation de la taille 
1254
-		$ok = false;
1255
-		if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1256
-			if ($format == "gif") {
1257
-				// Si un GIF est transparent, 
1258
-				// fabriquer un PNG transparent  
1259
-				$transp = imagecolortransparent($srcImage);
1260
-				if ($transp > 0) {
1261
-					$destFormat = "png";
1262
-				}
1263
-			}
1264
-			if ($destFormat == "png") {
1265
-				// Conserver la transparence 
1266
-				if (function_exists("imageAntiAlias")) {
1267
-					imageAntiAlias($destImage, true);
1268
-				}
1269
-				@imagealphablending($destImage, false);
1270
-				@imagesavealpha($destImage, true);
1271
-			}
1272
-			$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1273
-		}
1274
-		if (!$ok) {
1275
-			$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1276
-		}
1277
-
1278
-		// Sauvegarde de l'image destination
1279
-		$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1280
-		$valeurs['format_dest'] = $format = $destFormat;
1281
-		_image_gd_output($destImage, $valeurs);
1282
-
1283
-		if ($srcImage) {
1284
-			ImageDestroy($srcImage);
1285
-		}
1286
-		ImageDestroy($destImage);
1287
-	}
1288
-
1289
-	$size = @spip_getimagesize($vignette);
1290
-	// Gaffe: en safe mode, pas d'acces a la vignette,
1291
-	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1292
-	if ($size[0] < 1) {
1293
-		$size[0] = $destWidth;
1294
-	}
1295
-	if ($size[1] < 1) {
1296
-		$size[1] = $destHeight;
1297
-	}
1298
-
1299
-	$retour['width'] = $largeur = $size[0];
1300
-	$retour['height'] = $hauteur = $size[1];
1301
-
1302
-	$retour['fichier'] = $vignette;
1303
-	$retour['format'] = $format;
1304
-	$retour['date'] = @filemtime($vignette);
1305
-
1306
-	// renvoyer l'image
1307
-	return $retour;
1066
+    // ordre de preference des formats graphiques pour creer les vignettes
1067
+    // le premier format disponible, selon la methode demandee, est utilise
1068
+    $image = $valeurs['fichier'];
1069
+    $format = $valeurs['format_source'];
1070
+    $destdir = dirname($valeurs['fichier_dest']);
1071
+    $destfile = basename($valeurs['fichier_dest'], "." . $valeurs["format_dest"]);
1072
+
1073
+    $format_sortie = $valeurs['format_dest'];
1074
+
1075
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1076
+        $process = $GLOBALS['meta']['image_process'];
1077
+    }
1078
+
1079
+    // si le doc n'est pas une image, refuser
1080
+    if (!$force and !in_array($format, formats_image_acceptables())) {
1081
+        return;
1082
+    }
1083
+    $destination = "$destdir/$destfile";
1084
+
1085
+    // calculer la taille
1086
+    if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1087
+        if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1088
+            list($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight);
1089
+        }
1090
+    } elseif ($process == 'convert' or $process == 'imagick') {
1091
+        $destWidth = $maxWidth;
1092
+        $destHeight = $maxHeight;
1093
+    } else {
1094
+        spip_log("echec $process sur $image");
1095
+
1096
+        return;
1097
+    }
1098
+
1099
+    // Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1100
+    if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1101
+        $vignette = $destination . '.' . $format;
1102
+        @copy($image, $vignette);
1103
+    }
1104
+
1105
+    elseif ($valeurs["format_source"] === 'svg') {
1106
+        if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)){
1107
+            $format_sortie = 'svg';
1108
+            $vignette = $destination . "." . $format_sortie;
1109
+            $valeurs['fichier_dest'] = $vignette;
1110
+            _image_gd_output($svg, $valeurs);
1111
+        }
1112
+    }
1113
+
1114
+    // imagemagick en ligne de commande
1115
+    elseif ($process == 'convert') {
1116
+        if (!defined('_CONVERT_COMMAND')) {
1117
+            define('_CONVERT_COMMAND', 'convert');
1118
+        } // Securite : mes_options.php peut preciser le chemin absolu
1119
+        if (!defined('_RESIZE_COMMAND')) {
1120
+            define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1121
+        }
1122
+        $vignette = $destination . "." . $format_sortie;
1123
+        $commande = str_replace(
1124
+            array('%x', '%y', '%src', '%dest'),
1125
+            array(
1126
+                $destWidth,
1127
+                $destHeight,
1128
+                escapeshellcmd($image),
1129
+                escapeshellcmd($vignette)
1130
+            ),
1131
+            _RESIZE_COMMAND);
1132
+        spip_log($commande);
1133
+        exec($commande);
1134
+        if (!@file_exists($vignette)) {
1135
+            spip_log("echec convert sur $vignette");
1136
+
1137
+            return;  // echec commande
1138
+        }
1139
+    }
1140
+
1141
+    // php5 imagemagick
1142
+    elseif ($process == 'imagick') {
1143
+        $vignette = "$destination." . $format_sortie;
1144
+
1145
+        if (!class_exists('Imagick')) {
1146
+            spip_log("Classe Imagick absente !", _LOG_ERREUR);
1147
+
1148
+            return;
1149
+        }
1150
+        $imagick = new Imagick();
1151
+        $imagick->readImage($image);
1152
+        $imagick->resizeImage($destWidth, $destHeight, Imagick::FILTER_LANCZOS,
1153
+            1);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1154
+        $imagick->writeImage($vignette);
1155
+
1156
+        if (!@file_exists($vignette)) {
1157
+            spip_log("echec imagick sur $vignette");
1158
+
1159
+            return;
1160
+        }
1161
+    }
1162
+
1163
+    // netpbm
1164
+    elseif ($process == "netpbm") {
1165
+        if (!defined('_PNMSCALE_COMMAND')) {
1166
+            define('_PNMSCALE_COMMAND', 'pnmscale');
1167
+        } // Securite : mes_options.php peut preciser le chemin absolu
1168
+        if (_PNMSCALE_COMMAND == '') {
1169
+            return;
1170
+        }
1171
+        $vignette = $destination . "." . $format_sortie;
1172
+        $pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND);
1173
+        if ($format == "jpg") {
1174
+
1175
+            $jpegtopnm_command = str_replace("pnmscale", "jpegtopnm", _PNMSCALE_COMMAND);
1176
+            exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1177
+            if (!($s = @filesize($vignette))) {
1178
+                spip_unlink($vignette);
1179
+            }
1180
+            if (!@file_exists($vignette)) {
1181
+                spip_log("echec netpbm-jpg sur $vignette");
1182
+
1183
+                return;
1184
+            }
1185
+        } else {
1186
+            if ($format == "gif") {
1187
+                $giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND);
1188
+                exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1189
+                if (!($s = @filesize($vignette))) {
1190
+                    spip_unlink($vignette);
1191
+                }
1192
+                if (!@file_exists($vignette)) {
1193
+                    spip_log("echec netpbm-gif sur $vignette");
1194
+
1195
+                    return;
1196
+                }
1197
+            } else {
1198
+                if ($format == "png") {
1199
+                    $pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND);
1200
+                    exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1201
+                    if (!($s = @filesize($vignette))) {
1202
+                        spip_unlink($vignette);
1203
+                    }
1204
+                    if (!@file_exists($vignette)) {
1205
+                        spip_log("echec netpbm-png sur $vignette");
1206
+
1207
+                        return;
1208
+                    }
1209
+                }
1210
+            }
1211
+        }
1212
+    }
1213
+
1214
+    // gd ou gd2
1215
+    elseif ($process == 'gd1' or $process == 'gd2') {
1216
+        if (!function_exists('gd_info')) {
1217
+            spip_log("Librairie GD absente !", _LOG_ERREUR);
1218
+
1219
+            return;
1220
+        }
1221
+        if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1222
+            spip_log("vignette gd1/gd2 impossible : " . $srcWidth * $srcHeight . "pixels");
1223
+
1224
+            return;
1225
+        }
1226
+        $destFormat = $format_sortie;
1227
+        if (!$destFormat) {
1228
+            spip_log("pas de format pour $image");
1229
+
1230
+            return;
1231
+        }
1232
+
1233
+        $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1234
+        if (!function_exists($fonction_imagecreatefrom)) {
1235
+            return '';
1236
+        }
1237
+        $srcImage = @$fonction_imagecreatefrom($image);
1238
+        if (!$srcImage) {
1239
+            spip_log("echec gd1/gd2");
1240
+
1241
+            return;
1242
+        }
1243
+
1244
+        // Initialisation de l'image destination
1245
+        $destImage = null;
1246
+        if ($process == 'gd2' and $destFormat != "gif") {
1247
+            $destImage = ImageCreateTrueColor($destWidth, $destHeight);
1248
+        }
1249
+        if (!$destImage) {
1250
+            $destImage = ImageCreate($destWidth, $destHeight);
1251
+        }
1252
+
1253
+        // Recopie de l'image d'origine avec adaptation de la taille 
1254
+        $ok = false;
1255
+        if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1256
+            if ($format == "gif") {
1257
+                // Si un GIF est transparent, 
1258
+                // fabriquer un PNG transparent  
1259
+                $transp = imagecolortransparent($srcImage);
1260
+                if ($transp > 0) {
1261
+                    $destFormat = "png";
1262
+                }
1263
+            }
1264
+            if ($destFormat == "png") {
1265
+                // Conserver la transparence 
1266
+                if (function_exists("imageAntiAlias")) {
1267
+                    imageAntiAlias($destImage, true);
1268
+                }
1269
+                @imagealphablending($destImage, false);
1270
+                @imagesavealpha($destImage, true);
1271
+            }
1272
+            $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1273
+        }
1274
+        if (!$ok) {
1275
+            $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1276
+        }
1277
+
1278
+        // Sauvegarde de l'image destination
1279
+        $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1280
+        $valeurs['format_dest'] = $format = $destFormat;
1281
+        _image_gd_output($destImage, $valeurs);
1282
+
1283
+        if ($srcImage) {
1284
+            ImageDestroy($srcImage);
1285
+        }
1286
+        ImageDestroy($destImage);
1287
+    }
1288
+
1289
+    $size = @spip_getimagesize($vignette);
1290
+    // Gaffe: en safe mode, pas d'acces a la vignette,
1291
+    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1292
+    if ($size[0] < 1) {
1293
+        $size[0] = $destWidth;
1294
+    }
1295
+    if ($size[1] < 1) {
1296
+        $size[1] = $destHeight;
1297
+    }
1298
+
1299
+    $retour['width'] = $largeur = $size[0];
1300
+    $retour['height'] = $hauteur = $size[1];
1301
+
1302
+    $retour['fichier'] = $vignette;
1303
+    $retour['format'] = $format;
1304
+    $retour['date'] = @filemtime($vignette);
1305
+
1306
+    // renvoyer l'image
1307
+    return $retour;
1308 1308
 }
1309 1309
 
1310 1310
 /**
@@ -1324,25 +1324,25 @@  discard block
 block discarded – undo
1324 1324
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1325 1325
  **/
1326 1326
 function _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
1327
-	$ratioWidth = $srcWidth / $maxWidth;
1328
-	$ratioHeight = $srcHeight / $maxHeight;
1329
-
1330
-	if ($ratioWidth <= 1 and $ratioHeight <= 1) {
1331
-		$destWidth = $srcWidth;
1332
-		$destHeight = $srcHeight;
1333
-	} elseif ($ratioWidth < $ratioHeight) {
1334
-		$destWidth = $srcWidth / $ratioHeight;
1335
-		$destHeight = $maxHeight;
1336
-	} else {
1337
-		$destWidth = $maxWidth;
1338
-		$destHeight = $srcHeight / $ratioWidth;
1339
-	}
1340
-
1341
-	return array(
1342
-		ceil($destWidth),
1343
-		ceil($destHeight),
1344
-		max($ratioWidth, $ratioHeight)
1345
-	);
1327
+    $ratioWidth = $srcWidth / $maxWidth;
1328
+    $ratioHeight = $srcHeight / $maxHeight;
1329
+
1330
+    if ($ratioWidth <= 1 and $ratioHeight <= 1) {
1331
+        $destWidth = $srcWidth;
1332
+        $destHeight = $srcHeight;
1333
+    } elseif ($ratioWidth < $ratioHeight) {
1334
+        $destWidth = $srcWidth / $ratioHeight;
1335
+        $destHeight = $maxHeight;
1336
+    } else {
1337
+        $destWidth = $maxWidth;
1338
+        $destHeight = $srcHeight / $ratioWidth;
1339
+    }
1340
+
1341
+    return array(
1342
+        ceil($destWidth),
1343
+        ceil($destHeight),
1344
+        max($ratioWidth, $ratioHeight)
1345
+    );
1346 1346
 }
1347 1347
 
1348 1348
 /**
@@ -1362,25 +1362,25 @@  discard block
 block discarded – undo
1362 1362
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1363 1363
  **/
1364 1364
 function ratio_passe_partout($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
1365
-	$ratioWidth = $srcWidth / $maxWidth;
1366
-	$ratioHeight = $srcHeight / $maxHeight;
1367
-
1368
-	if ($ratioWidth <= 1 and $ratioHeight <= 1) {
1369
-		$destWidth = $srcWidth;
1370
-		$destHeight = $srcHeight;
1371
-	} elseif ($ratioWidth > $ratioHeight) {
1372
-		$destWidth = $srcWidth / $ratioHeight;
1373
-		$destHeight = $maxHeight;
1374
-	} else {
1375
-		$destWidth = $maxWidth;
1376
-		$destHeight = $srcHeight / $ratioWidth;
1377
-	}
1378
-
1379
-	return array(
1380
-		ceil($destWidth),
1381
-		ceil($destHeight),
1382
-		min($ratioWidth, $ratioHeight)
1383
-	);
1365
+    $ratioWidth = $srcWidth / $maxWidth;
1366
+    $ratioHeight = $srcHeight / $maxHeight;
1367
+
1368
+    if ($ratioWidth <= 1 and $ratioHeight <= 1) {
1369
+        $destWidth = $srcWidth;
1370
+        $destHeight = $srcHeight;
1371
+    } elseif ($ratioWidth > $ratioHeight) {
1372
+        $destWidth = $srcWidth / $ratioHeight;
1373
+        $destHeight = $maxHeight;
1374
+    } else {
1375
+        $destWidth = $maxWidth;
1376
+        $destHeight = $srcHeight / $ratioWidth;
1377
+    }
1378
+
1379
+    return array(
1380
+        ceil($destWidth),
1381
+        ceil($destHeight),
1382
+        min($ratioWidth, $ratioHeight)
1383
+    );
1384 1384
 }
1385 1385
 
1386 1386
 
@@ -1393,12 +1393,12 @@  discard block
 block discarded – undo
1393 1393
  * @return string
1394 1394
  */
1395 1395
 function process_image_svg_identite($image) {
1396
-	if ($image['creer']) {
1397
-		$source = $image['fichier'];
1398
-		_image_gd_output($source, $image);
1399
-	}
1396
+    if ($image['creer']) {
1397
+        $source = $image['fichier'];
1398
+        _image_gd_output($source, $image);
1399
+    }
1400 1400
 
1401
-	return _image_ecrire_tag($image, array('src' => $image['fichier_dest']));
1401
+    return _image_ecrire_tag($image, array('src' => $image['fichier_dest']));
1402 1402
 }
1403 1403
 
1404 1404
 
@@ -1431,107 +1431,107 @@  discard block
 block discarded – undo
1431 1431
  *     Code HTML de la balise img produite
1432 1432
  **/
1433 1433
 function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') {
1434
-	$image = false;
1435
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1436
-		$process = $GLOBALS['meta']['image_process'];
1437
-	}
1438
-	# determiner le format de sortie
1439
-	$format_sortie = false; // le choix par defaut sera bon
1440
-	if ($process == "netpbm") {
1441
-		$format_sortie = "jpg";
1442
-	} elseif ($process == 'gd1' or $process == 'gd2') {
1443
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1444
-
1445
-		// on verifie que l'extension choisie est bonne (en principe oui)
1446
-		$gd_formats = formats_image_acceptables(true);
1447
-		if (is_array($image)
1448
-			and (!in_array($image['format_dest'], $gd_formats)
1449
-				or ($image['format_dest'] == 'gif' and !function_exists('ImageGif'))
1450
-			)
1451
-		) {
1452
-			if ($image['format_source'] == 'jpg') {
1453
-				$formats_sortie = array('jpg', 'png', 'gif');
1454
-			} else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1455
-			{
1456
-				$formats_sortie = array('png', 'jpg', 'gif');
1457
-			}
1458
-			// Choisir le format destination
1459
-			// - on sauve de preference en JPEG (meilleure compression)
1460
-			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1461
-			# bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1462
-			# pas *ecrire*
1463
-			$format_sortie = "";
1464
-			foreach ($formats_sortie as $fmt) {
1465
-				if (in_array($fmt, $gd_formats)) {
1466
-					if ($fmt <> "gif" or function_exists('ImageGif')) {
1467
-						$format_sortie = $fmt;
1468
-					}
1469
-					break;
1470
-				}
1471
-			}
1472
-			$image = false;
1473
-		}
1474
-	}
1475
-
1476
-	if (!is_array($image)) {
1477
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1478
-	}
1479
-
1480
-	if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1481
-		spip_log("image_reduire_src:pas de version locale de $img");
1482
-		// on peut resizer en mode html si on dispose des elements
1483
-		if ($srcw = extraire_attribut($img, 'width')
1484
-			and $srch = extraire_attribut($img, 'height')
1485
-		) {
1486
-			list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y);
1487
-
1488
-			return _image_tag_changer_taille($img, $w, $h);
1489
-		}
1490
-		// la on n'a pas d'infos sur l'image source... on refile le truc a css
1491
-		// sous la forme style='max-width: NNpx;'
1492
-		return inserer_attribut($img, 'style',
1493
-			"max-width: ${taille}px; max-height: ${taille_y}px");
1494
-	}
1495
-
1496
-	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1497
-	if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1498
-		if ($image['creer']) {
1499
-			@copy($image['fichier'], $image['fichier_dest']);
1500
-		}
1501
-
1502
-		return _image_ecrire_tag($image, array('src' => $image['fichier_dest']));
1503
-	}
1504
-
1505
-	if ($image['creer'] == false && !$force) {
1506
-		return _image_ecrire_tag($image,
1507
-			array('src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']));
1508
-	}
1509
-
1510
-	if (in_array($image["format_source"], formats_image_acceptables())) {
1511
-		$destWidth = $image['largeur_dest'];
1512
-		$destHeight = $image['hauteur_dest'];
1513
-		$logo = $image['fichier'];
1514
-		$date = $image["date_src"];
1515
-		$preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1516
-
1517
-		if ($preview && $preview['fichier']) {
1518
-			$logo = $preview['fichier'];
1519
-			$destWidth = $preview['width'];
1520
-			$destHeight = $preview['height'];
1521
-			$date = $preview['date'];
1522
-		}
1523
-		// dans l'espace prive mettre un timestamp sur l'adresse 
1524
-		// de l'image, de facon a tromper le cache du navigateur
1525
-		// quand on fait supprimer/reuploader un logo
1526
-		// (pas de filemtime si SAFE MODE)
1527
-		$date = test_espace_prive() ? ('?' . $date) : '';
1528
-
1529
-		return _image_ecrire_tag($image, array('src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight));
1530
-	}
1531
-	else {
1532
-		# BMP, tiff ... les redacteurs osent tout!
1533
-		return $img;
1534
-	}
1434
+    $image = false;
1435
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1436
+        $process = $GLOBALS['meta']['image_process'];
1437
+    }
1438
+    # determiner le format de sortie
1439
+    $format_sortie = false; // le choix par defaut sera bon
1440
+    if ($process == "netpbm") {
1441
+        $format_sortie = "jpg";
1442
+    } elseif ($process == 'gd1' or $process == 'gd2') {
1443
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1444
+
1445
+        // on verifie que l'extension choisie est bonne (en principe oui)
1446
+        $gd_formats = formats_image_acceptables(true);
1447
+        if (is_array($image)
1448
+            and (!in_array($image['format_dest'], $gd_formats)
1449
+                or ($image['format_dest'] == 'gif' and !function_exists('ImageGif'))
1450
+            )
1451
+        ) {
1452
+            if ($image['format_source'] == 'jpg') {
1453
+                $formats_sortie = array('jpg', 'png', 'gif');
1454
+            } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1455
+            {
1456
+                $formats_sortie = array('png', 'jpg', 'gif');
1457
+            }
1458
+            // Choisir le format destination
1459
+            // - on sauve de preference en JPEG (meilleure compression)
1460
+            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1461
+            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1462
+            # pas *ecrire*
1463
+            $format_sortie = "";
1464
+            foreach ($formats_sortie as $fmt) {
1465
+                if (in_array($fmt, $gd_formats)) {
1466
+                    if ($fmt <> "gif" or function_exists('ImageGif')) {
1467
+                        $format_sortie = $fmt;
1468
+                    }
1469
+                    break;
1470
+                }
1471
+            }
1472
+            $image = false;
1473
+        }
1474
+    }
1475
+
1476
+    if (!is_array($image)) {
1477
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1478
+    }
1479
+
1480
+    if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1481
+        spip_log("image_reduire_src:pas de version locale de $img");
1482
+        // on peut resizer en mode html si on dispose des elements
1483
+        if ($srcw = extraire_attribut($img, 'width')
1484
+            and $srch = extraire_attribut($img, 'height')
1485
+        ) {
1486
+            list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y);
1487
+
1488
+            return _image_tag_changer_taille($img, $w, $h);
1489
+        }
1490
+        // la on n'a pas d'infos sur l'image source... on refile le truc a css
1491
+        // sous la forme style='max-width: NNpx;'
1492
+        return inserer_attribut($img, 'style',
1493
+            "max-width: ${taille}px; max-height: ${taille_y}px");
1494
+    }
1495
+
1496
+    // si l'image est plus petite que la cible retourner une copie cachee de l'image
1497
+    if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1498
+        if ($image['creer']) {
1499
+            @copy($image['fichier'], $image['fichier_dest']);
1500
+        }
1501
+
1502
+        return _image_ecrire_tag($image, array('src' => $image['fichier_dest']));
1503
+    }
1504
+
1505
+    if ($image['creer'] == false && !$force) {
1506
+        return _image_ecrire_tag($image,
1507
+            array('src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']));
1508
+    }
1509
+
1510
+    if (in_array($image["format_source"], formats_image_acceptables())) {
1511
+        $destWidth = $image['largeur_dest'];
1512
+        $destHeight = $image['hauteur_dest'];
1513
+        $logo = $image['fichier'];
1514
+        $date = $image["date_src"];
1515
+        $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1516
+
1517
+        if ($preview && $preview['fichier']) {
1518
+            $logo = $preview['fichier'];
1519
+            $destWidth = $preview['width'];
1520
+            $destHeight = $preview['height'];
1521
+            $date = $preview['date'];
1522
+        }
1523
+        // dans l'espace prive mettre un timestamp sur l'adresse 
1524
+        // de l'image, de facon a tromper le cache du navigateur
1525
+        // quand on fait supprimer/reuploader un logo
1526
+        // (pas de filemtime si SAFE MODE)
1527
+        $date = test_espace_prive() ? ('?' . $date) : '';
1528
+
1529
+        return _image_ecrire_tag($image, array('src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight));
1530
+    }
1531
+    else {
1532
+        # BMP, tiff ... les redacteurs osent tout!
1533
+        return $img;
1534
+    }
1535 1535
 }
1536 1536
 
1537 1537
 /**
@@ -1546,145 +1546,145 @@  discard block
 block discarded – undo
1546 1546
  */
1547 1547
 class phpthumb_functions {
1548 1548
 
1549
-	/**
1550
-	 * Retourne la couleur d'un pixel dans une image
1551
-	 *
1552
-	 * @param ressource $img
1553
-	 * @param int $x
1554
-	 * @param int $y
1555
-	 * @return array|bool
1556
-	 */
1557
-	public static function GetPixelColor(&$img, $x, $y) {
1558
-		if (!is_resource($img)) {
1559
-			return false;
1560
-		}
1561
-
1562
-		return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1563
-	}
1564
-
1565
-	/**
1566
-	 * Retourne un nombre dans une représentation en Little Endian
1567
-	 *
1568
-	 * @param int $number
1569
-	 * @param int $minbytes
1570
-	 * @return string
1571
-	 */
1572
-	public static function LittleEndian2String($number, $minbytes = 1) {
1573
-		$intstring = '';
1574
-		while ($number > 0) {
1575
-			$intstring = $intstring . chr($number & 255);
1576
-			$number >>= 8;
1577
-		}
1578
-
1579
-		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1580
-	}
1581
-
1582
-	/**
1583
-	 * Transforme une ressource GD en image au format ICO
1584
-	 *
1585
-	 * @param array $gd_image_array
1586
-	 *     Tableau de ressources d'images GD
1587
-	 * @return string
1588
-	 *     Image au format ICO
1589
-	 */
1590
-	public static function GD2ICOstring(&$gd_image_array) {
1591
-		foreach ($gd_image_array as $key => $gd_image) {
1592
-
1593
-			$ImageWidths[$key] = ImageSX($gd_image);
1594
-			$ImageHeights[$key] = ImageSY($gd_image);
1595
-			$bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1596
-			$totalcolors[$key] = ImageColorsTotal($gd_image);
1597
-
1598
-			$icXOR[$key] = '';
1599
-			for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1600
-				for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1601
-					$argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1602
-					$a = round(255 * ((127 - $argb['alpha']) / 127));
1603
-					$r = $argb['red'];
1604
-					$g = $argb['green'];
1605
-					$b = $argb['blue'];
1606
-
1607
-					if ($bpp[$key] == 32) {
1608
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1609
-					} elseif ($bpp[$key] == 24) {
1610
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1611
-					}
1612
-
1613
-					if ($a < 128) {
1614
-						@$icANDmask[$key][$y] .= '1';
1615
-					} else {
1616
-						@$icANDmask[$key][$y] .= '0';
1617
-					}
1618
-				}
1619
-				// mask bits are 32-bit aligned per scanline
1620
-				while (strlen($icANDmask[$key][$y]) % 32) {
1621
-					$icANDmask[$key][$y] .= '0';
1622
-				}
1623
-			}
1624
-			$icAND[$key] = '';
1625
-			foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1626
-				for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1627
-					$icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1628
-				}
1629
-			}
1630
-
1631
-		}
1632
-
1633
-		foreach ($gd_image_array as $key => $gd_image) {
1634
-			$biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1635
-
1636
-			// BITMAPINFOHEADER - 40 bytes
1637
-			$BitmapInfoHeader[$key] = '';
1638
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1639
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1640
-			// The biHeight member specifies the combined
1641
-			// height of the XOR and AND masks.
1642
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1643
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1644
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1645
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1646
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1647
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1648
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1649
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1650
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1651
-		}
1652
-
1653
-
1654
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1655
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1656
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1657
-
1658
-		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1659
-		foreach ($gd_image_array as $key => $gd_image) {
1660
-			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1661
-
1662
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1663
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1664
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1665
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1666
-
1667
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1668
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1669
-
1670
-			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1671
-			$icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes,
1672
-				4);     // dwBytesInRes;	// How many bytes in this resource?
1673
-
1674
-			$icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset,
1675
-				4);    // dwImageOffset;   // Where in the file is this image?
1676
-			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1677
-			$dwImageOffset += strlen($icXOR[$key]);
1678
-			$dwImageOffset += strlen($icAND[$key]);
1679
-		}
1680
-
1681
-		foreach ($gd_image_array as $key => $gd_image) {
1682
-			$icondata .= $BitmapInfoHeader[$key];
1683
-			$icondata .= $icXOR[$key];
1684
-			$icondata .= $icAND[$key];
1685
-		}
1686
-
1687
-		return $icondata;
1688
-	}
1549
+    /**
1550
+     * Retourne la couleur d'un pixel dans une image
1551
+     *
1552
+     * @param ressource $img
1553
+     * @param int $x
1554
+     * @param int $y
1555
+     * @return array|bool
1556
+     */
1557
+    public static function GetPixelColor(&$img, $x, $y) {
1558
+        if (!is_resource($img)) {
1559
+            return false;
1560
+        }
1561
+
1562
+        return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1563
+    }
1564
+
1565
+    /**
1566
+     * Retourne un nombre dans une représentation en Little Endian
1567
+     *
1568
+     * @param int $number
1569
+     * @param int $minbytes
1570
+     * @return string
1571
+     */
1572
+    public static function LittleEndian2String($number, $minbytes = 1) {
1573
+        $intstring = '';
1574
+        while ($number > 0) {
1575
+            $intstring = $intstring . chr($number & 255);
1576
+            $number >>= 8;
1577
+        }
1578
+
1579
+        return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1580
+    }
1581
+
1582
+    /**
1583
+     * Transforme une ressource GD en image au format ICO
1584
+     *
1585
+     * @param array $gd_image_array
1586
+     *     Tableau de ressources d'images GD
1587
+     * @return string
1588
+     *     Image au format ICO
1589
+     */
1590
+    public static function GD2ICOstring(&$gd_image_array) {
1591
+        foreach ($gd_image_array as $key => $gd_image) {
1592
+
1593
+            $ImageWidths[$key] = ImageSX($gd_image);
1594
+            $ImageHeights[$key] = ImageSY($gd_image);
1595
+            $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1596
+            $totalcolors[$key] = ImageColorsTotal($gd_image);
1597
+
1598
+            $icXOR[$key] = '';
1599
+            for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1600
+                for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1601
+                    $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1602
+                    $a = round(255 * ((127 - $argb['alpha']) / 127));
1603
+                    $r = $argb['red'];
1604
+                    $g = $argb['green'];
1605
+                    $b = $argb['blue'];
1606
+
1607
+                    if ($bpp[$key] == 32) {
1608
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1609
+                    } elseif ($bpp[$key] == 24) {
1610
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r);
1611
+                    }
1612
+
1613
+                    if ($a < 128) {
1614
+                        @$icANDmask[$key][$y] .= '1';
1615
+                    } else {
1616
+                        @$icANDmask[$key][$y] .= '0';
1617
+                    }
1618
+                }
1619
+                // mask bits are 32-bit aligned per scanline
1620
+                while (strlen($icANDmask[$key][$y]) % 32) {
1621
+                    $icANDmask[$key][$y] .= '0';
1622
+                }
1623
+            }
1624
+            $icAND[$key] = '';
1625
+            foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1626
+                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1627
+                    $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1628
+                }
1629
+            }
1630
+
1631
+        }
1632
+
1633
+        foreach ($gd_image_array as $key => $gd_image) {
1634
+            $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1635
+
1636
+            // BITMAPINFOHEADER - 40 bytes
1637
+            $BitmapInfoHeader[$key] = '';
1638
+            $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1639
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1640
+            // The biHeight member specifies the combined
1641
+            // height of the XOR and AND masks.
1642
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1643
+            $BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1644
+            $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1645
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1646
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1647
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1648
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1649
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1650
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1651
+        }
1652
+
1653
+
1654
+        $icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1655
+        $icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1656
+        $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1657
+
1658
+        $dwImageOffset = 6 + (count($gd_image_array) * 16);
1659
+        foreach ($gd_image_array as $key => $gd_image) {
1660
+            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1661
+
1662
+            $icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1663
+            $icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1664
+            $icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1665
+            $icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1666
+
1667
+            $icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1668
+            $icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1669
+
1670
+            $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1671
+            $icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes,
1672
+                4);     // dwBytesInRes;	// How many bytes in this resource?
1673
+
1674
+            $icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset,
1675
+                4);    // dwImageOffset;   // Where in the file is this image?
1676
+            $dwImageOffset += strlen($BitmapInfoHeader[$key]);
1677
+            $dwImageOffset += strlen($icXOR[$key]);
1678
+            $dwImageOffset += strlen($icAND[$key]);
1679
+        }
1680
+
1681
+        foreach ($gd_image_array as $key => $gd_image) {
1682
+            $icondata .= $BitmapInfoHeader[$key];
1683
+            $icondata .= $icXOR[$key];
1684
+            $icondata .= $icAND[$key];
1685
+        }
1686
+
1687
+        return $icondata;
1688
+    }
1689 1689
 
1690 1690
 }
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	$blue = dechex($blue);
45 45
 
46 46
 	if (strlen($red) == 1) {
47
-		$red = "0" . $red;
47
+		$red = "0".$red;
48 48
 	}
49 49
 	if (strlen($green) == 1) {
50
-		$green = "0" . $green;
50
+		$green = "0".$green;
51 51
 	}
52 52
 	if (strlen($blue) == 1) {
53
-		$blue = "0" . $blue;
53
+		$blue = "0".$blue;
54 54
 	}
55 55
 
56 56
 	return "$red$green$blue";
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	$couleur = couleur_html_to_hex($couleur);
69 69
 	$couleur = ltrim($couleur, '#');
70 70
 	if (strlen($couleur) === 3) {
71
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
71
+		$couleur = $couleur[0].$couleur[0].$couleur[1].$couleur[1].$couleur[2].$couleur[2];
72 72
 	}
73 73
 	$retour["red"] = hexdec(substr($couleur, 0, 2));
74 74
 	$retour["green"] = hexdec(substr($couleur, 2, 2));
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 		$img = "<img src='$source' />";
157 157
 	} # gerer img src="data:....base64"
158 158
 	elseif (preg_match('@^data:image/(jpe?g|png|gif|svg+xml);base64,(.*)$@isS', $source, $regs)) {
159
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . str_replace('jpeg', 'jpg', $regs[1]);
159
+		$local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'.str_replace('jpeg', 'jpg', $regs[1]);
160 160
 		if (!file_exists($local)) {
161 161
 			ecrire_fichier($local, base64_decode($regs[2]));
162 162
 		}
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	// les protocoles web prennent au moins 3 lettres
171 171
 	if (tester_url_absolue($source)) {
172 172
 		include_spip('inc/distant');
173
-		$fichier = _DIR_RACINE . copie_locale($source);
173
+		$fichier = _DIR_RACINE.copie_locale($source);
174 174
 		if (!$fichier) {
175 175
 			return "";
176 176
 		}
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 
196 196
 	if ($forcer_format !== false
197 197
 		// ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image
198
-		and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format,['png','gif','jpg']))) {
198
+		and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, ['png', 'gif', 'jpg']))) {
199 199
 		$terminaison_dest = $forcer_format;
200 200
 	}
201 201
 
@@ -257,9 +257,9 @@  discard block
 block discarded – undo
257 257
 			// on garde la terminaison initiale car image simplement copiee
258 258
 			// et on postfixe son nom avec un md5 du path
259 259
 			$terminaison_dest = $terminaison;
260
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
260
+			$fichier_dest .= '-'.substr(md5("$identifiant"), 0, 5);
261 261
 		} else {
262
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
262
+			$fichier_dest .= '-'.substr(md5("$identifiant-$effet"), 0, 5);
263 263
 		}
264 264
 		$cache = sous_repertoire(_DIR_VAR, $cache);
265 265
 		$cache = sous_repertoire($cache, $effet);
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 		$fichier_dest = substr($fichier_dest, 2);
276 276
 	}
277 277
 
278
-	$fichier_dest = $cache . $fichier_dest . "." . $terminaison_dest;
278
+	$fichier_dest = $cache.$fichier_dest.".".$terminaison_dest;
279 279
 
280 280
 	$GLOBALS["images_calculees"][] = $fichier_dest;
281 281
 
@@ -311,14 +311,14 @@  discard block
 block discarded – undo
311 311
 	}
312 312
 
313 313
 	if ($creer) {
314
-		spip_log("filtre image " . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
315
-			"images" . _LOG_DEBUG);
314
+		spip_log("filtre image ".($fonction_creation ? reset($fonction_creation) : '')."[$effet] sur $fichier",
315
+			"images"._LOG_DEBUG);
316 316
 	}
317 317
 
318 318
 	$term_fonction = _image_trouver_extension_pertinente($fichier);
319
-	$ret["fonction_imagecreatefrom"] = "_imagecreatefrom" . $term_fonction;
319
+	$ret["fonction_imagecreatefrom"] = "_imagecreatefrom".$term_fonction;
320 320
 	$ret["fichier"] = $fichier;
321
-	$ret["fonction_image"] = "_image_image" . $terminaison_dest;
321
+	$ret["fonction_image"] = "_image_image".$terminaison_dest;
322 322
 	$ret["fichier_dest"] = $fichier_dest;
323 323
 	$ret["format_source"] = ($terminaison != 'jpeg' ? $terminaison : 'jpg');
324 324
 	$ret["format_dest"] = $terminaison_dest;
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
 			$_terminaison = '';
439 439
 	}
440 440
 	if ($_terminaison and $_terminaison !== $terminaison) {
441
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", "images." . _LOG_INFO_IMPORTANTE);
441
+		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", "images."._LOG_INFO_IMPORTANTE);
442 442
 		$terminaison = $_terminaison;
443 443
 	}
444 444
 	return $terminaison;
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
 	if (!function_exists('imagepng')) {
529 529
 		return false;
530 530
 	}
531
-	$tmp = $fichier . ".tmp";
531
+	$tmp = $fichier.".tmp";
532 532
 	$ret = imagepng($img, $tmp);
533 533
 	if (file_exists($tmp)) {
534 534
 		$taille_test = getimagesize($tmp);
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
 	if (!function_exists('imagegif')) {
564 564
 		return false;
565 565
 	}
566
-	$tmp = $fichier . ".tmp";
566
+	$tmp = $fichier.".tmp";
567 567
 	$ret = imagegif($img, $tmp);
568 568
 	if (file_exists($tmp)) {
569 569
 		$taille_test = getimagesize($tmp);
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
 	if (!function_exists('imagejpeg')) {
604 604
 		return false;
605 605
 	}
606
-	$tmp = $fichier . ".tmp";
606
+	$tmp = $fichier.".tmp";
607 607
 
608 608
 	// Enable interlancing
609 609
 	imageinterlace($img, true);
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
  */
664 664
 function _image_imagesvg($img, $fichier) {
665 665
 
666
-	$tmp = $fichier . ".tmp";
666
+	$tmp = $fichier.".tmp";
667 667
 	if (strpos($img, "<") === false) {
668 668
 		$img = supprimer_timestamp($img);
669 669
 		if (!file_exists($img)) {
@@ -719,12 +719,12 @@  discard block
 block discarded – undo
719 719
  *     - false sinon.
720 720
  */
721 721
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE) {
722
-	$fonction = "_image_image" . $valeurs['format_dest'];
722
+	$fonction = "_image_image".$valeurs['format_dest'];
723 723
 	$ret = false;
724 724
 	#un flag pour reperer les images gravees
725 725
 	$lock =
726 726
 		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
727
-	or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
727
+	or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'].'.src'));
728 728
 	if (
729 729
 		function_exists($fonction)
730 730
 		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
 			// dans tous les cas mettre a jour la taille de l'image finale
736 736
 			list($valeurs["hauteur_dest"], $valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']);
737 737
 			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
738
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
738
+			ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true);
739 739
 		}
740 740
 	}
741 741
 
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
 function reconstruire_image_intermediaire($fichier_manquant) {
755 755
 	$reconstruire = array();
756 756
 	$fichier = $fichier_manquant;
757
-	while (strpos($fichier,"://")===false
757
+	while (strpos($fichier, "://") === false
758 758
 		and !@file_exists($fichier)
759 759
 		and lire_fichier($src = "$fichier.src", $source)
760 760
 		and $valeurs = unserialize($source)
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
  *     Chemin du fichier d'image calculé
792 792
  **/
793 793
 function ramasse_miettes($fichier) {
794
-	if (strpos($fichier,"://")!==false
794
+	if (strpos($fichier, "://") !== false
795 795
 		or !lire_fichier($src = "$fichier.src", $source)
796 796
 		or !$valeurs = unserialize($source)
797 797
 	) {
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
 	}
848 848
 	# si jamais le fichier final n'a pas ete calcule car suppose temporaire
849 849
 	# et qu'il ne s'agit pas d'une URL
850
-	if (strpos($fichier,"://")===false and !@file_exists($fichier)) {
850
+	if (strpos($fichier, "://") === false and !@file_exists($fichier)) {
851 851
 		reconstruire_image_intermediaire($fichier);
852 852
 	}
853 853
 	ramasse_miettes($fichier);
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
 
945 945
 	// attributs deprecies. Transformer en CSS
946 946
 	if ($espace = extraire_attribut($tag, 'hspace')) {
947
-		$style = "margin:${espace}px;" . $style;
947
+		$style = "margin:${espace}px;".$style;
948 948
 		$tag = inserer_attribut($tag, 'hspace', '');
949 949
 	}
950 950
 
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
 	$image = $valeurs['fichier'];
1069 1069
 	$format = $valeurs['format_source'];
1070 1070
 	$destdir = dirname($valeurs['fichier_dest']);
1071
-	$destfile = basename($valeurs['fichier_dest'], "." . $valeurs["format_dest"]);
1071
+	$destfile = basename($valeurs['fichier_dest'], ".".$valeurs["format_dest"]);
1072 1072
 
1073 1073
 	$format_sortie = $valeurs['format_dest'];
1074 1074
 
@@ -1098,14 +1098,14 @@  discard block
 block discarded – undo
1098 1098
 
1099 1099
 	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1100 1100
 	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1101
-		$vignette = $destination . '.' . $format;
1101
+		$vignette = $destination.'.'.$format;
1102 1102
 		@copy($image, $vignette);
1103 1103
 	}
1104 1104
 
1105 1105
 	elseif ($valeurs["format_source"] === 'svg') {
1106
-		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)){
1106
+		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1107 1107
 			$format_sortie = 'svg';
1108
-			$vignette = $destination . "." . $format_sortie;
1108
+			$vignette = $destination.".".$format_sortie;
1109 1109
 			$valeurs['fichier_dest'] = $vignette;
1110 1110
 			_image_gd_output($svg, $valeurs);
1111 1111
 		}
@@ -1117,9 +1117,9 @@  discard block
 block discarded – undo
1117 1117
 			define('_CONVERT_COMMAND', 'convert');
1118 1118
 		} // Securite : mes_options.php peut preciser le chemin absolu
1119 1119
 		if (!defined('_RESIZE_COMMAND')) {
1120
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1120
+			define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -resize %xx%y! %src %dest');
1121 1121
 		}
1122
-		$vignette = $destination . "." . $format_sortie;
1122
+		$vignette = $destination.".".$format_sortie;
1123 1123
 		$commande = str_replace(
1124 1124
 			array('%x', '%y', '%src', '%dest'),
1125 1125
 			array(
@@ -1134,13 +1134,13 @@  discard block
 block discarded – undo
1134 1134
 		if (!@file_exists($vignette)) {
1135 1135
 			spip_log("echec convert sur $vignette");
1136 1136
 
1137
-			return;  // echec commande
1137
+			return; // echec commande
1138 1138
 		}
1139 1139
 	}
1140 1140
 
1141 1141
 	// php5 imagemagick
1142 1142
 	elseif ($process == 'imagick') {
1143
-		$vignette = "$destination." . $format_sortie;
1143
+		$vignette = "$destination.".$format_sortie;
1144 1144
 
1145 1145
 		if (!class_exists('Imagick')) {
1146 1146
 			spip_log("Classe Imagick absente !", _LOG_ERREUR);
@@ -1150,7 +1150,7 @@  discard block
 block discarded – undo
1150 1150
 		$imagick = new Imagick();
1151 1151
 		$imagick->readImage($image);
1152 1152
 		$imagick->resizeImage($destWidth, $destHeight, Imagick::FILTER_LANCZOS,
1153
-			1);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1153
+			1); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1154 1154
 		$imagick->writeImage($vignette);
1155 1155
 
1156 1156
 		if (!@file_exists($vignette)) {
@@ -1168,12 +1168,12 @@  discard block
 block discarded – undo
1168 1168
 		if (_PNMSCALE_COMMAND == '') {
1169 1169
 			return;
1170 1170
 		}
1171
-		$vignette = $destination . "." . $format_sortie;
1171
+		$vignette = $destination.".".$format_sortie;
1172 1172
 		$pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND);
1173 1173
 		if ($format == "jpg") {
1174 1174
 
1175 1175
 			$jpegtopnm_command = str_replace("pnmscale", "jpegtopnm", _PNMSCALE_COMMAND);
1176
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1176
+			exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1177 1177
 			if (!($s = @filesize($vignette))) {
1178 1178
 				spip_unlink($vignette);
1179 1179
 			}
@@ -1185,7 +1185,7 @@  discard block
 block discarded – undo
1185 1185
 		} else {
1186 1186
 			if ($format == "gif") {
1187 1187
 				$giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND);
1188
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1188
+				exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1189 1189
 				if (!($s = @filesize($vignette))) {
1190 1190
 					spip_unlink($vignette);
1191 1191
 				}
@@ -1197,7 +1197,7 @@  discard block
 block discarded – undo
1197 1197
 			} else {
1198 1198
 				if ($format == "png") {
1199 1199
 					$pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND);
1200
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1200
+					exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1201 1201
 					if (!($s = @filesize($vignette))) {
1202 1202
 						spip_unlink($vignette);
1203 1203
 					}
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
 			return;
1220 1220
 		}
1221 1221
 		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1222
-			spip_log("vignette gd1/gd2 impossible : " . $srcWidth * $srcHeight . "pixels");
1222
+			spip_log("vignette gd1/gd2 impossible : ".$srcWidth * $srcHeight."pixels");
1223 1223
 
1224 1224
 			return;
1225 1225
 		}
@@ -1524,7 +1524,7 @@  discard block
 block discarded – undo
1524 1524
 		// de l'image, de facon a tromper le cache du navigateur
1525 1525
 		// quand on fait supprimer/reuploader un logo
1526 1526
 		// (pas de filemtime si SAFE MODE)
1527
-		$date = test_espace_prive() ? ('?' . $date) : '';
1527
+		$date = test_espace_prive() ? ('?'.$date) : '';
1528 1528
 
1529 1529
 		return _image_ecrire_tag($image, array('src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight));
1530 1530
 	}
@@ -1572,7 +1572,7 @@  discard block
 block discarded – undo
1572 1572
 	public static function LittleEndian2String($number, $minbytes = 1) {
1573 1573
 		$intstring = '';
1574 1574
 		while ($number > 0) {
1575
-			$intstring = $intstring . chr($number & 255);
1575
+			$intstring = $intstring.chr($number & 255);
1576 1576
 			$number >>= 8;
1577 1577
 		}
1578 1578
 
@@ -1605,9 +1605,9 @@  discard block
 block discarded – undo
1605 1605
 					$b = $argb['blue'];
1606 1606
 
1607 1607
 					if ($bpp[$key] == 32) {
1608
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1608
+						$icXOR[$key] .= chr($b).chr($g).chr($r).chr($a);
1609 1609
 					} elseif ($bpp[$key] == 24) {
1610
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1610
+						$icXOR[$key] .= chr($b).chr($g).chr($r);
1611 1611
 					}
1612 1612
 
1613 1613
 					if ($a < 128) {
@@ -1635,44 +1635,44 @@  discard block
 block discarded – undo
1635 1635
 
1636 1636
 			// BITMAPINFOHEADER - 40 bytes
1637 1637
 			$BitmapInfoHeader[$key] = '';
1638
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1639
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1638
+			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD  biSize;
1639
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG   biWidth;
1640 1640
 			// The biHeight member specifies the combined
1641 1641
 			// height of the XOR and AND masks.
1642 1642
 			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1643
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1644
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1645
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1646
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1647
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1648
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1649
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1650
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1643
+			$BitmapInfoHeader[$key] .= "\x01\x00"; // WORD   biPlanes;
1644
+			$BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount;
1645
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biCompression;
1646
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD  biSizeImage;
1647
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biXPelsPerMeter;
1648
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biYPelsPerMeter;
1649
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrUsed;
1650
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrImportant;
1651 1651
 		}
1652 1652
 
1653 1653
 
1654
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1655
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1656
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1654
+		$icondata = "\x00\x00"; // idReserved;   // Reserved (must be 0)
1655
+		$icondata .= "\x01\x00"; // idType;	   // Resource Type (1 for icons)
1656
+		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount;	  // How many images?
1657 1657
 
1658 1658
 		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1659 1659
 		foreach ($gd_image_array as $key => $gd_image) {
1660 1660
 			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1661 1661
 
1662
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1663
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1664
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1665
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1662
+			$icondata .= chr($ImageWidths[$key]); // bWidth;		  // Width, in pixels, of the image
1663
+			$icondata .= chr($ImageHeights[$key]); // bHeight;		 // Height, in pixels, of the image
1664
+			$icondata .= chr($totalcolors[$key]); // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1665
+			$icondata .= "\x00"; // bReserved;	   // Reserved ( must be 0)
1666 1666
 
1667
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1668
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1667
+			$icondata .= "\x01\x00"; // wPlanes;		 // Color Planes
1668
+			$icondata .= chr($bpp[$key])."\x00"; // wBitCount;	   // Bits per pixel
1669 1669
 
1670 1670
 			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1671 1671
 			$icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes,
1672
-				4);     // dwBytesInRes;	// How many bytes in this resource?
1672
+				4); // dwBytesInRes;	// How many bytes in this resource?
1673 1673
 
1674 1674
 			$icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset,
1675
-				4);    // dwImageOffset;   // Where in the file is this image?
1675
+				4); // dwImageOffset;   // Where in the file is this image?
1676 1676
 			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1677 1677
 			$dwImageOffset += strlen($icXOR[$key]);
1678 1678
 			$dwImageOffset += strlen($icAND[$key]);
Please login to merge, or discard this patch.
Braces   +4 added lines, -9 removed lines patch added patch discarded remove patch
@@ -357,8 +357,7 @@  discard block
 block discarded – undo
357 357
 			process_image_svg_identite($ret);
358 358
 			$ret['creer'] = false;
359 359
 		}
360
-	}
361
-	else {
360
+	} else {
362 361
 		if (!function_exists($ret["fonction_imagecreatefrom"])) {
363 362
 			return false;
364 363
 		}
@@ -404,8 +403,7 @@  discard block
 block discarded – undo
404 403
 
405 404
 	if (isset($info['mime'])) {
406 405
 		$mime = $info['mime'];
407
-	}
408
-	else {
406
+	} else {
409 407
 		$mime = image_type_to_mime_type($info[2]);
410 408
 	}
411 409
 
@@ -1100,9 +1098,7 @@  discard block
 block discarded – undo
1100 1098
 	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1101 1099
 		$vignette = $destination . '.' . $format;
1102 1100
 		@copy($image, $vignette);
1103
-	}
1104
-
1105
-	elseif ($valeurs["format_source"] === 'svg') {
1101
+	} elseif ($valeurs["format_source"] === 'svg') {
1106 1102
 		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)){
1107 1103
 			$format_sortie = 'svg';
1108 1104
 			$vignette = $destination . "." . $format_sortie;
@@ -1527,8 +1523,7 @@  discard block
 block discarded – undo
1527 1523
 		$date = test_espace_prive() ? ('?' . $date) : '';
1528 1524
 
1529 1525
 		return _image_ecrire_tag($image, array('src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight));
1530
-	}
1531
-	else {
1526
+	} else {
1532 1527
 		# BMP, tiff ... les redacteurs osent tout!
1533 1528
 		return $img;
1534 1529
 	}
Please login to merge, or discard this patch.
ecrire/inc/svg.php 4 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 
323 323
 /**
324 324
  * Extract all colors in SVG
325
- * @param $img
325
+ * @param string $img
326 326
  * @return array|mixed
327 327
  */
328 328
 function svg_extract_couleurs($img) {
@@ -396,8 +396,8 @@  discard block
 block discarded – undo
396 396
 
397 397
 /**
398 398
  * Ajouter un background au SVG : un rect pleine taille avec la bonne couleur
399
- * @param $img
400
- * @param $background_color
399
+ * @param string $img
400
+ * @param string $background_color
401 401
  * @return bool|string
402 402
  */
403 403
 function svg_ajouter_background($img, $background_color) {
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 
455 455
 /**
456 456
  * Ajouter un background au SVG : un rect pleine taille avec la bonne couleur
457
- * @param $img
457
+ * @param string $img
458 458
  * @array $attributs
459 459
  * @return bool|string
460 460
  */
Please login to merge, or discard this patch.
Indentation   +358 added lines, -358 removed lines patch added patch discarded remove patch
@@ -17,13 +17,13 @@  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
 if (!defined('IMG_SVG')) {
24
-	// complete 	IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP
25
-	define('IMG_SVG',128);
26
-	define('IMAGETYPE_SVG', 19);
24
+    // complete 	IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP
25
+    define('IMG_SVG',128);
26
+    define('IMAGETYPE_SVG', 19);
27 27
 }
28 28
 
29 29
 /**
@@ -39,41 +39,41 @@  discard block
 block discarded – undo
39 39
  *   false si on a pas pu charger l'image
40 40
  */
41 41
 function svg_charger($fichier, $maxlen=null) {
42
-	if (strpos($fichier, "data:image/svg+xml") === 0) {
43
-		$image = explode(";", $fichier, 2);
44
-		$image = end($image);
45
-		if (strpos($image, "base64,") === 0) {
46
-			$image = base64_decode(substr($image, 7));
47
-		}
48
-		if (strpos($image, "<svg") !== false) {
49
-			return $image;
50
-		}
51
-		var_dump('fail1');
52
-		// encodage inconnu ou autre format d'image ?
53
-		return false;
54
-	}
55
-	// c'est peut etre deja une image svg ?
56
-	if (strpos($fichier, "<svg") !== false) {
57
-		return $fichier;
58
-	}
59
-	if (!file_exists($fichier)) {
60
-		$fichier  = supprimer_timestamp($fichier);
61
-		if (!file_exists($fichier)) {
62
-			var_dump('fail2');
63
-			return false;
64
-		}
65
-	}
66
-	if (is_null($maxlen)) {
67
-		$image = file_get_contents($fichier);
68
-	}
69
-	else {
70
-		$image = file_get_contents($fichier, false,null,0, $maxlen);
71
-	}
72
-	// est-ce bien une image svg ?
73
-	if (strpos($image, "<svg") !== false) {
74
-		return $image;
75
-	}
76
-	return false;
42
+    if (strpos($fichier, "data:image/svg+xml") === 0) {
43
+        $image = explode(";", $fichier, 2);
44
+        $image = end($image);
45
+        if (strpos($image, "base64,") === 0) {
46
+            $image = base64_decode(substr($image, 7));
47
+        }
48
+        if (strpos($image, "<svg") !== false) {
49
+            return $image;
50
+        }
51
+        var_dump('fail1');
52
+        // encodage inconnu ou autre format d'image ?
53
+        return false;
54
+    }
55
+    // c'est peut etre deja une image svg ?
56
+    if (strpos($fichier, "<svg") !== false) {
57
+        return $fichier;
58
+    }
59
+    if (!file_exists($fichier)) {
60
+        $fichier  = supprimer_timestamp($fichier);
61
+        if (!file_exists($fichier)) {
62
+            var_dump('fail2');
63
+            return false;
64
+        }
65
+    }
66
+    if (is_null($maxlen)) {
67
+        $image = file_get_contents($fichier);
68
+    }
69
+    else {
70
+        $image = file_get_contents($fichier, false,null,0, $maxlen);
71
+    }
72
+    // est-ce bien une image svg ?
73
+    if (strpos($image, "<svg") !== false) {
74
+        return $image;
75
+    }
76
+    return false;
77 77
 }
78 78
 
79 79
 /**
@@ -82,29 +82,29 @@  discard block
 block discarded – undo
82 82
  * @return array|bool
83 83
  */
84 84
 function svg_lire_balise_svg($fichier) {
85
-	if (!$debut_fichier = svg_charger($fichier, 4096)) {
86
-		return false;
87
-	}
85
+    if (!$debut_fichier = svg_charger($fichier, 4096)) {
86
+        return false;
87
+    }
88 88
 
89
-	if (($ps = stripos($debut_fichier, "<svg")) !== false) {
89
+    if (($ps = stripos($debut_fichier, "<svg")) !== false) {
90 90
 
91
-		$pe = stripos($debut_fichier, ">", $ps);
92
-		$balise_svg = substr($debut_fichier, $ps, $pe - $ps +1);
91
+        $pe = stripos($debut_fichier, ">", $ps);
92
+        $balise_svg = substr($debut_fichier, $ps, $pe - $ps +1);
93 93
 
94
-		if (preg_match_all(",([\w\-]+)=,Uims", $balise_svg, $matches)) {
95
-			if (!function_exists('extraire_attribut')) {
96
-				include_spip('inc/filtres');
97
-			}
98
-			$attributs = [];
99
-			foreach ($matches[1] as $att) {
100
-				$attributs[$att] = extraire_attribut($balise_svg, $att);
101
-			}
94
+        if (preg_match_all(",([\w\-]+)=,Uims", $balise_svg, $matches)) {
95
+            if (!function_exists('extraire_attribut')) {
96
+                include_spip('inc/filtres');
97
+            }
98
+            $attributs = [];
99
+            foreach ($matches[1] as $att) {
100
+                $attributs[$att] = extraire_attribut($balise_svg, $att);
101
+            }
102 102
 
103
-			return [$balise_svg, $attributs];
104
-		}
105
-	}
103
+            return [$balise_svg, $attributs];
104
+        }
105
+    }
106 106
 
107
-	return false;
107
+    return false;
108 108
 }
109 109
 
110 110
 /**
@@ -114,12 +114,12 @@  discard block
 block discarded – undo
114 114
  */
115 115
 function svg_lire_attributs($img) {
116 116
 
117
-	if ($svg_infos = svg_lire_balise_svg($img)) {
118
-		list($balise_svg, $attributs) = $svg_infos;
119
-		return $attributs;
120
-	}
117
+    if ($svg_infos = svg_lire_balise_svg($img)) {
118
+        list($balise_svg, $attributs) = $svg_infos;
119
+        return $attributs;
120
+    }
121 121
 
122
-	return false;
122
+    return false;
123 123
 }
124 124
 
125 125
 /**
@@ -129,38 +129,38 @@  discard block
 block discarded – undo
129 129
  * @return bool|float|int
130 130
  */
131 131
 function svg_dimension_to_pixels($dimension) {
132
-	if (preg_match(',^(-?\d+)([^\d]*),i', trim($dimension), $m)){
133
-		switch (strtolower($m[2])) {
134
-			case '%':
135
-				// on ne sait pas faire :(
136
-				return false;
137
-				break;
138
-			case 'em':
139
-				return intval($m[1])*16; // 16px font-size par defaut
140
-				break;
141
-			case 'ex':
142
-				return intval($m[1])*16; // 16px font-size par defaut
143
-				break;
144
-			case 'pc':
145
-				return intval($m[1])*16; // 1/6 inch = 96px/6 in CSS
146
-				break;
147
-			case 'cm':
148
-				return intval(round($m[1]*96/2.54)); // 96px / 2.54cm;
149
-				break;
150
-			case 'mm':
151
-				return intval(round($m[1]*96/25.4)); // 96px / 25.4mm;
152
-				break;
153
-			case 'in':
154
-				return intval($m[1])*96; // 1 inch = 96px in CSS
155
-				break;
156
-			case 'px':
157
-			case 'pt':
158
-			default:
159
-				return intval($m[1]);
160
-				break;
161
-		}
162
-	}
163
-	return false;
132
+    if (preg_match(',^(-?\d+)([^\d]*),i', trim($dimension), $m)){
133
+        switch (strtolower($m[2])) {
134
+            case '%':
135
+                // on ne sait pas faire :(
136
+                return false;
137
+                break;
138
+            case 'em':
139
+                return intval($m[1])*16; // 16px font-size par defaut
140
+                break;
141
+            case 'ex':
142
+                return intval($m[1])*16; // 16px font-size par defaut
143
+                break;
144
+            case 'pc':
145
+                return intval($m[1])*16; // 1/6 inch = 96px/6 in CSS
146
+                break;
147
+            case 'cm':
148
+                return intval(round($m[1]*96/2.54)); // 96px / 2.54cm;
149
+                break;
150
+            case 'mm':
151
+                return intval(round($m[1]*96/25.4)); // 96px / 25.4mm;
152
+                break;
153
+            case 'in':
154
+                return intval($m[1])*96; // 1 inch = 96px in CSS
155
+                break;
156
+            case 'px':
157
+            case 'pt':
158
+            default:
159
+                return intval($m[1]);
160
+                break;
161
+        }
162
+    }
163
+    return false;
164 164
 }
165 165
 
166 166
 /**
@@ -171,15 +171,15 @@  discard block
 block discarded – undo
171 171
  * @return string
172 172
  */
173 173
 function svg_change_balise_svg($svg, $old_balise_svg, $attributs) {
174
-	$new_balise_svg = "<svg";
175
-	foreach ($attributs as $k=>$v) {
176
-		$new_balise_svg .= " $k=\"".entites_html($v)."\"";
177
-	}
178
-	$new_balise_svg .= ">";
179
-
180
-	$p = strpos($svg, $old_balise_svg);
181
-	$svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg));
182
-	return $svg;
174
+    $new_balise_svg = "<svg";
175
+    foreach ($attributs as $k=>$v) {
176
+        $new_balise_svg .= " $k=\"".entites_html($v)."\"";
177
+    }
178
+    $new_balise_svg .= ">";
179
+
180
+    $p = strpos($svg, $old_balise_svg);
181
+    $svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg));
182
+    return $svg;
183 183
 }
184 184
 
185 185
 /**
@@ -191,15 +191,15 @@  discard block
 block discarded – undo
191 191
  */
192 192
 function svg_insert_shapes($svg, $shapes, $start=true) {
193 193
 
194
-	if ($start === false or $start === 'end') {
195
-		$svg = str_replace("</svg>", $shapes . "</svg>", $svg);
196
-	}
197
-	else {
198
-		$p = stripos($svg, "<svg");
199
-		$p = strpos($svg, ">", $p);
200
-		$svg = substr_replace($svg, $shapes, $p+1, 0);
201
-	}
202
-	return $svg;
194
+    if ($start === false or $start === 'end') {
195
+        $svg = str_replace("</svg>", $shapes . "</svg>", $svg);
196
+    }
197
+    else {
198
+        $p = stripos($svg, "<svg");
199
+        $p = strpos($svg, ">", $p);
200
+        $svg = substr_replace($svg, $shapes, $p+1, 0);
201
+    }
202
+    return $svg;
203 203
 }
204 204
 
205 205
 /**
@@ -212,13 +212,13 @@  discard block
 block discarded – undo
212 212
  * @return string
213 213
  */
214 214
 function svg_clip_in_box($svg, $x, $y, $width, $height) {
215
-	$rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
216
-	$id = 'clip-'.substr(md5($rect . strlen($svg)),0,8);
217
-	$clippath = "<clipPath id=\"$id\">$rect</clipPath>";
218
-	$g = "<g clip-path=\"url(#$id)\">";
219
-	$svg = svg_insert_shapes($svg, $clippath . $g);
220
-	$svg = svg_insert_shapes($svg, "</g>", false);
221
-	return $svg;
215
+    $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
216
+    $id = 'clip-'.substr(md5($rect . strlen($svg)),0,8);
217
+    $clippath = "<clipPath id=\"$id\">$rect</clipPath>";
218
+    $g = "<g clip-path=\"url(#$id)\">";
219
+    $svg = svg_insert_shapes($svg, $clippath . $g);
220
+    $svg = svg_insert_shapes($svg, "</g>", false);
221
+    return $svg;
222 222
 }
223 223
 
224 224
 /**
@@ -229,21 +229,21 @@  discard block
 block discarded – undo
229 229
  * @return bool|string
230 230
  */
231 231
 function svg_redimensionner($img, $new_width, $new_height) {
232
-	if ($svg = svg_charger($img)
233
-	  and $svg_infos = svg_lire_balise_svg($svg)) {
232
+    if ($svg = svg_charger($img)
233
+      and $svg_infos = svg_lire_balise_svg($svg)) {
234 234
 
235
-		list($balise_svg, $attributs) = $svg_infos;
236
-		if (!isset($attributs['viewBox'])) {
237
-			$attributs['viewBox'] = "0 0 " . $attributs['width'] . " " . $attributs['height'];
238
-		}
239
-		$attributs['width'] = strval($new_width);
240
-		$attributs['height'] = strval($new_height);
235
+        list($balise_svg, $attributs) = $svg_infos;
236
+        if (!isset($attributs['viewBox'])) {
237
+            $attributs['viewBox'] = "0 0 " . $attributs['width'] . " " . $attributs['height'];
238
+        }
239
+        $attributs['width'] = strval($new_width);
240
+        $attributs['height'] = strval($new_height);
241 241
 
242
-		$svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
243
-		return $svg;
244
-	}
242
+        $svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
243
+        return $svg;
244
+    }
245 245
 
246
-	return $img;
246
+    return $img;
247 247
 }
248 248
 
249 249
 /**
@@ -252,15 +252,15 @@  discard block
 block discarded – undo
252 252
  * @return string
253 253
  */
254 254
 function svg_couleur_to_hexa($couleur) {
255
-	if (strpos($couleur, "rgb(")===0) {
256
-		$c = explode(',', substr($couleur, 4));
257
-		$couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2]));
258
-	}
259
-	else {
260
-		$couleur = couleur_html_to_hex($couleur);
261
-	}
262
-	$couleur = '#'.ltrim($couleur,'#');
263
-	return $couleur;
255
+    if (strpos($couleur, "rgb(")===0) {
256
+        $c = explode(',', substr($couleur, 4));
257
+        $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2]));
258
+    }
259
+    else {
260
+        $couleur = couleur_html_to_hex($couleur);
261
+    }
262
+    $couleur = '#'.ltrim($couleur,'#');
263
+    return $couleur;
264 264
 }
265 265
 
266 266
 /**
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
  * @return array
270 270
  */
271 271
 function svg_couleur_to_rgb($couleur) {
272
-	if (strpos($couleur, "rgb(")===0) {
273
-		$c = explode(',', substr($couleur, 4));
274
-		return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])];
275
-	}
276
-	return _couleur_hex_to_dec($couleur);
272
+    if (strpos($couleur, "rgb(")===0) {
273
+        $c = explode(',', substr($couleur, 4));
274
+        return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])];
275
+    }
276
+    return _couleur_hex_to_dec($couleur);
277 277
 }
278 278
 
279 279
 
@@ -289,35 +289,35 @@  discard block
 block discarded – undo
289 289
  * @return string
290 290
  */
291 291
 function svg_force_viewBox_px($img) {
292
-	if ($svg = svg_charger($img)
293
-	  and $svg_infos = svg_lire_balise_svg($svg)){
294
-
295
-		list($balise_svg, $attributs) = $svg_infos;
296
-
297
-		// il nous faut une viewBox
298
-		if (!isset($attributs['viewBox'])) {
299
-			$viewBox = "0 0 " . $attributs['width'] . " " . $attributs['height'];
300
-		}
301
-		else {
302
-			$viewBox = $attributs['viewBox'];
303
-		}
304
-		// et on la convertit en px
305
-		$viewBox = explode(' ', $viewBox);
306
-		$viewBox = array_map('svg_dimension_to_pixels', $viewBox);
307
-		$viewBox = array_map('intval', $viewBox);
308
-		if (!$viewBox[2]) {
309
-			$viewBox[2] = '300';
310
-		}
311
-		if (!$viewBox[3]) {
312
-			$viewBox[3] = '150';
313
-		}
314
-
315
-		$attributs['viewBox'] = implode(' ', $viewBox);
316
-
317
-		$svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
318
-		return $svg;
319
-	}
320
-	return $img;
292
+    if ($svg = svg_charger($img)
293
+      and $svg_infos = svg_lire_balise_svg($svg)){
294
+
295
+        list($balise_svg, $attributs) = $svg_infos;
296
+
297
+        // il nous faut une viewBox
298
+        if (!isset($attributs['viewBox'])) {
299
+            $viewBox = "0 0 " . $attributs['width'] . " " . $attributs['height'];
300
+        }
301
+        else {
302
+            $viewBox = $attributs['viewBox'];
303
+        }
304
+        // et on la convertit en px
305
+        $viewBox = explode(' ', $viewBox);
306
+        $viewBox = array_map('svg_dimension_to_pixels', $viewBox);
307
+        $viewBox = array_map('intval', $viewBox);
308
+        if (!$viewBox[2]) {
309
+            $viewBox[2] = '300';
310
+        }
311
+        if (!$viewBox[3]) {
312
+            $viewBox[3] = '150';
313
+        }
314
+
315
+        $attributs['viewBox'] = implode(' ', $viewBox);
316
+
317
+        $svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
318
+        return $svg;
319
+    }
320
+    return $img;
321 321
 }
322 322
 
323 323
 /**
@@ -326,12 +326,12 @@  discard block
 block discarded – undo
326 326
  * @return array|mixed
327 327
  */
328 328
 function svg_extract_couleurs($img) {
329
-	if ($svg = svg_charger($img)) {
330
-		if (preg_match_all("/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS", $svg, $matches)) {
331
-			return $matches[0];
332
-		}
333
-	}
334
-	return [];
329
+    if ($svg = svg_charger($img)) {
330
+        if (preg_match_all("/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS", $svg, $matches)) {
331
+            return $matches[0];
332
+        }
333
+    }
334
+    return [];
335 335
 }
336 336
 
337 337
 /**
@@ -342,56 +342,56 @@  discard block
 block discarded – undo
342 342
  * @return bool|string
343 343
  */
344 344
 function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color='') {
345
-	if ($svg = svg_force_viewBox_px($img)
346
-	  and $svg_infos = svg_lire_balise_svg($svg)) {
347
-
348
-		list($balise_svg, $attributs) = $svg_infos;
349
-		$viewBox = explode(' ', $attributs['viewBox']);
350
-
351
-		$viewport_w = $new_width;
352
-		$viewport_h = $new_height;
353
-		$viewport_ox = $offset_width;
354
-		$viewport_oy = $offset_height;
355
-
356
-		// si on a un width/height qui rescale, il faut rescaler
357
-		if (isset ($attributs['width'])
358
-		  and $w = svg_dimension_to_pixels($attributs['width'])
359
-		  and isset ($attributs['height'])
360
-		  and $h = svg_dimension_to_pixels($attributs['height'])) {
361
-
362
-			$xscale = $viewBox[2] / $w;
363
-			$viewport_w = intval(round($viewport_w * $xscale));
364
-			$viewport_ox = intval(round($viewport_ox * $xscale));
365
-			$yscale = $viewBox[3] / $h;
366
-			$viewport_h = intval(round($viewport_h * $yscale));
367
-			$viewport_oy = intval(round($viewport_oy * $yscale));
368
-		}
369
-
370
-		if ($viewport_w>$viewBox[2] or $viewport_h>$viewBox[3]) {
371
-			$svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]);
372
-		}
373
-
374
-		// maintenant on redefinit la viewBox
375
-		$viewBox[0] += $viewport_ox;
376
-		$viewBox[1] += $viewport_oy;
377
-		$viewBox[2] = $viewport_w;
378
-		$viewBox[3] = $viewport_h;
379
-
380
-		$attributs['viewBox'] = implode(' ', $viewBox);
381
-		$attributs['width'] = strval($new_width);
382
-		$attributs['height'] = strval($new_height);
383
-
384
-		$svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
385
-
386
-		// ajouter un background
387
-		if ($background_color and $background_color!=='transparent') {
388
-			$svg = svg_ajouter_background($svg, $background_color);
389
-		}
390
-
391
-		return $svg;
392
-	}
393
-
394
-	return $img;
345
+    if ($svg = svg_force_viewBox_px($img)
346
+      and $svg_infos = svg_lire_balise_svg($svg)) {
347
+
348
+        list($balise_svg, $attributs) = $svg_infos;
349
+        $viewBox = explode(' ', $attributs['viewBox']);
350
+
351
+        $viewport_w = $new_width;
352
+        $viewport_h = $new_height;
353
+        $viewport_ox = $offset_width;
354
+        $viewport_oy = $offset_height;
355
+
356
+        // si on a un width/height qui rescale, il faut rescaler
357
+        if (isset ($attributs['width'])
358
+          and $w = svg_dimension_to_pixels($attributs['width'])
359
+          and isset ($attributs['height'])
360
+          and $h = svg_dimension_to_pixels($attributs['height'])) {
361
+
362
+            $xscale = $viewBox[2] / $w;
363
+            $viewport_w = intval(round($viewport_w * $xscale));
364
+            $viewport_ox = intval(round($viewport_ox * $xscale));
365
+            $yscale = $viewBox[3] / $h;
366
+            $viewport_h = intval(round($viewport_h * $yscale));
367
+            $viewport_oy = intval(round($viewport_oy * $yscale));
368
+        }
369
+
370
+        if ($viewport_w>$viewBox[2] or $viewport_h>$viewBox[3]) {
371
+            $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]);
372
+        }
373
+
374
+        // maintenant on redefinit la viewBox
375
+        $viewBox[0] += $viewport_ox;
376
+        $viewBox[1] += $viewport_oy;
377
+        $viewBox[2] = $viewport_w;
378
+        $viewBox[3] = $viewport_h;
379
+
380
+        $attributs['viewBox'] = implode(' ', $viewBox);
381
+        $attributs['width'] = strval($new_width);
382
+        $attributs['height'] = strval($new_height);
383
+
384
+        $svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
385
+
386
+        // ajouter un background
387
+        if ($background_color and $background_color!=='transparent') {
388
+            $svg = svg_ajouter_background($svg, $background_color);
389
+        }
390
+
391
+        return $svg;
392
+    }
393
+
394
+    return $img;
395 395
 }
396 396
 
397 397
 /**
@@ -401,25 +401,25 @@  discard block
 block discarded – undo
401 401
  * @return bool|string
402 402
  */
403 403
 function svg_ajouter_background($img, $background_color) {
404
-	if ($svg = svg_charger($img)
405
-	  and $svg_infos = svg_lire_balise_svg($svg)){
406
-
407
-		if ($background_color and $background_color!=='transparent') {
408
-			list($balise_svg, $attributs) = $svg_infos;
409
-
410
-			$background_color = svg_couleur_to_hexa($background_color);
411
-			if (isset($attributs['viewBox'])) {
412
-				$viewBox = explode(' ', $attributs['viewBox']);
413
-				$rect = "<rect x=\"".$viewBox[0]."\" y=\"".$viewBox[1]."\" width=\"".$viewBox[2]."\" height=\"".$viewBox[3]."\" fill=\"$background_color\"/>";
414
-			}
415
-			else {
416
-				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
417
-			}
418
-			$svg = svg_insert_shapes($svg, $rect);
419
-		}
420
-		return $svg;
421
-	}
422
-	return $img;
404
+    if ($svg = svg_charger($img)
405
+      and $svg_infos = svg_lire_balise_svg($svg)){
406
+
407
+        if ($background_color and $background_color!=='transparent') {
408
+            list($balise_svg, $attributs) = $svg_infos;
409
+
410
+            $background_color = svg_couleur_to_hexa($background_color);
411
+            if (isset($attributs['viewBox'])) {
412
+                $viewBox = explode(' ', $attributs['viewBox']);
413
+                $rect = "<rect x=\"".$viewBox[0]."\" y=\"".$viewBox[1]."\" width=\"".$viewBox[2]."\" height=\"".$viewBox[3]."\" fill=\"$background_color\"/>";
414
+            }
415
+            else {
416
+                $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
417
+            }
418
+            $svg = svg_insert_shapes($svg, $rect);
419
+        }
420
+        return $svg;
421
+    }
422
+    return $img;
423 423
 }
424 424
 
425 425
 
@@ -430,25 +430,25 @@  discard block
 block discarded – undo
430 430
  * @return bool|string
431 431
  */
432 432
 function svg_ajouter_voile($img, $background_color, $opacity) {
433
-	if ($svg = svg_charger($img)
434
-	  and $svg_infos = svg_lire_balise_svg($svg)){
435
-
436
-		if ($background_color and $background_color!=='transparent') {
437
-			list($balise_svg, $attributs) = $svg_infos;
438
-
439
-			$background_color = svg_couleur_to_hexa($background_color);
440
-			if (isset($attributs['viewBox'])) {
441
-				$viewBox = explode(' ', $attributs['viewBox']);
442
-				$rect = "<rect x=\"".$viewBox[0]."\" y=\"".$viewBox[1]."\" width=\"".$viewBox[2]."\" height=\"".$viewBox[3]."\" fill=\"$background_color\" opacity=\"$opacity\"/>";
443
-			}
444
-			else {
445
-				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
446
-			}
447
-			$svg = svg_insert_shapes($svg, $rect, false);
448
-		}
449
-		return $svg;
450
-	}
451
-	return $img;
433
+    if ($svg = svg_charger($img)
434
+      and $svg_infos = svg_lire_balise_svg($svg)){
435
+
436
+        if ($background_color and $background_color!=='transparent') {
437
+            list($balise_svg, $attributs) = $svg_infos;
438
+
439
+            $background_color = svg_couleur_to_hexa($background_color);
440
+            if (isset($attributs['viewBox'])) {
441
+                $viewBox = explode(' ', $attributs['viewBox']);
442
+                $rect = "<rect x=\"".$viewBox[0]."\" y=\"".$viewBox[1]."\" width=\"".$viewBox[2]."\" height=\"".$viewBox[3]."\" fill=\"$background_color\" opacity=\"$opacity\"/>";
443
+            }
444
+            else {
445
+                $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
446
+            }
447
+            $svg = svg_insert_shapes($svg, $rect, false);
448
+        }
449
+        return $svg;
450
+    }
451
+    return $img;
452 452
 }
453 453
 
454 454
 
@@ -459,26 +459,26 @@  discard block
 block discarded – undo
459 459
  * @return bool|string
460 460
  */
461 461
 function svg_transformer($img, $attributs) {
462
-	if ($svg = svg_charger($img)
463
-	  and $svg_infos = svg_lire_balise_svg($svg)){
464
-
465
-		if ($attributs) {
466
-			list($balise_svg, ) = $svg_infos;
467
-			$g = "<g";
468
-			foreach ($attributs as $k=>$v) {
469
-				if (strlen($v)) {
470
-					$g .= " $k=\"".attribut_html($v)."\"";
471
-				}
472
-			}
473
-			if (strlen($g) > 2) {
474
-				$g .= ">";
475
-				$svg = svg_insert_shapes($svg, $g);
476
-				$svg = svg_insert_shapes($svg, "</g>", false);
477
-			}
478
-		}
479
-		return $svg;
480
-	}
481
-	return $img;
462
+    if ($svg = svg_charger($img)
463
+      and $svg_infos = svg_lire_balise_svg($svg)){
464
+
465
+        if ($attributs) {
466
+            list($balise_svg, ) = $svg_infos;
467
+            $g = "<g";
468
+            foreach ($attributs as $k=>$v) {
469
+                if (strlen($v)) {
470
+                    $g .= " $k=\"".attribut_html($v)."\"";
471
+                }
472
+            }
473
+            if (strlen($g) > 2) {
474
+                $g .= ">";
475
+                $svg = svg_insert_shapes($svg, $g);
476
+                $svg = svg_insert_shapes($svg, "</g>", false);
477
+            }
478
+        }
479
+        return $svg;
480
+    }
481
+    return $img;
482 482
 }
483 483
 
484 484
 
@@ -489,30 +489,30 @@  discard block
 block discarded – undo
489 489
  * @return bool|string
490 490
  */
491 491
 function svg_flip($img, $HorV) {
492
-	if ($svg = svg_force_viewBox_px($img)
493
-	  and $svg_infos = svg_lire_balise_svg($svg)){
494
-
495
-		list($balise_svg, $atts) = $svg_infos;
496
-		$viewBox = explode(' ', $atts['viewBox']);
497
-
498
-		if (!in_array($HorV, ['h', 'H'])) {
499
-			$transform = "scale(-1,1)";
500
-
501
-			$x = intval($viewBox[0]) + intval($viewBox[2]/2);
502
-			$mx = -$x;
503
-			$transform = "translate($x, 0) $transform translate($mx, 0)";
504
-		}
505
-		else {
506
-			$transform = "scale(1,-1)";
507
-
508
-			$y = intval($viewBox[1]) + intval($viewBox[3]/2);
509
-			$my = -$y;
510
-			$transform = "translate(0, $y) $transform translate(0, $my)";
511
-		}
512
-		$svg = svg_transformer($svg, ['transform' => $transform]);
513
-		return $svg;
514
-	}
515
-	return $img;
492
+    if ($svg = svg_force_viewBox_px($img)
493
+      and $svg_infos = svg_lire_balise_svg($svg)){
494
+
495
+        list($balise_svg, $atts) = $svg_infos;
496
+        $viewBox = explode(' ', $atts['viewBox']);
497
+
498
+        if (!in_array($HorV, ['h', 'H'])) {
499
+            $transform = "scale(-1,1)";
500
+
501
+            $x = intval($viewBox[0]) + intval($viewBox[2]/2);
502
+            $mx = -$x;
503
+            $transform = "translate($x, 0) $transform translate($mx, 0)";
504
+        }
505
+        else {
506
+            $transform = "scale(1,-1)";
507
+
508
+            $y = intval($viewBox[1]) + intval($viewBox[3]/2);
509
+            $my = -$y;
510
+            $transform = "translate(0, $y) $transform translate(0, $my)";
511
+        }
512
+        $svg = svg_transformer($svg, ['transform' => $transform]);
513
+        return $svg;
514
+    }
515
+    return $img;
516 516
 }
517 517
 
518 518
 /**
@@ -526,19 +526,19 @@  discard block
 block discarded – undo
526 526
  * @return bool|string
527 527
  */
528 528
 function svg_rotate($img, $angle, $center_x, $center_y) {
529
-	if ($svg = svg_force_viewBox_px($img)
530
-		and $svg_infos = svg_lire_balise_svg($svg)){
529
+    if ($svg = svg_force_viewBox_px($img)
530
+        and $svg_infos = svg_lire_balise_svg($svg)){
531 531
 
532
-		list($balise_svg, $atts) = $svg_infos;
533
-		$viewBox = explode(' ', $atts['viewBox']);
532
+        list($balise_svg, $atts) = $svg_infos;
533
+        $viewBox = explode(' ', $atts['viewBox']);
534 534
 
535
-		$center_x = round($viewBox[0] + $center_x * $viewBox[2]);
536
-		$center_y = round($viewBox[1] + $center_y * $viewBox[3]);
537
-		$svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]);
535
+        $center_x = round($viewBox[0] + $center_x * $viewBox[2]);
536
+        $center_y = round($viewBox[1] + $center_y * $viewBox[3]);
537
+        $svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]);
538 538
 
539
-		return $svg;
540
-	}
541
-	return $img;
539
+        return $svg;
540
+    }
541
+    return $img;
542 542
 }
543 543
 
544 544
 /**
@@ -550,40 +550,40 @@  discard block
 block discarded – undo
550 550
  * @return bool|mixed|string
551 551
  */
552 552
 function svg_filtrer_couleurs($img, $callback_filter) {
553
-	if ($svg = svg_force_viewBox_px($img)
554
-	  and $colors = svg_extract_couleurs($svg)) {
555
-
556
-		$colors = array_unique($colors);
557
-
558
-		$short = [];
559
-		$long = [];
560
-		while (count($colors)) {
561
-			$c = array_shift($colors);
562
-			if (strlen($c) == 4) {
563
-				$short[] = $c;
564
-			}
565
-			else {
566
-				$long[] = $c;
567
-			}
568
-		}
569
-
570
-		$colors = array_merge($long, $short);
571
-		$new_colors = [];
572
-		$colors = array_flip($colors);
573
-		foreach ($colors as $c => $k) {
574
-			$colors[$c] = "@@@COLOR$$k$@@@";
575
-		}
576
-
577
-
578
-		foreach ($colors as $original => $replace) {
579
-			$new = svg_couleur_to_hexa($original);
580
-			$new_colors[$replace] = $callback_filter($new);
581
-		}
582
-
583
-		$svg = str_replace(array_keys($colors), array_values($colors), $svg);
584
-		$svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg);
585
-
586
-		return $svg;
587
-	}
588
-	return $img;
553
+    if ($svg = svg_force_viewBox_px($img)
554
+      and $colors = svg_extract_couleurs($svg)) {
555
+
556
+        $colors = array_unique($colors);
557
+
558
+        $short = [];
559
+        $long = [];
560
+        while (count($colors)) {
561
+            $c = array_shift($colors);
562
+            if (strlen($c) == 4) {
563
+                $short[] = $c;
564
+            }
565
+            else {
566
+                $long[] = $c;
567
+            }
568
+        }
569
+
570
+        $colors = array_merge($long, $short);
571
+        $new_colors = [];
572
+        $colors = array_flip($colors);
573
+        foreach ($colors as $c => $k) {
574
+            $colors[$c] = "@@@COLOR$$k$@@@";
575
+        }
576
+
577
+
578
+        foreach ($colors as $original => $replace) {
579
+            $new = svg_couleur_to_hexa($original);
580
+            $new_colors[$replace] = $callback_filter($new);
581
+        }
582
+
583
+        $svg = str_replace(array_keys($colors), array_values($colors), $svg);
584
+        $svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg);
585
+
586
+        return $svg;
587
+    }
588
+    return $img;
589 589
 }
590 590
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 if (!defined('IMG_SVG')) {
24 24
 	// complete 	IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP
25
-	define('IMG_SVG',128);
25
+	define('IMG_SVG', 128);
26 26
 	define('IMAGETYPE_SVG', 19);
27 27
 }
28 28
 
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
  * @return bool|string
39 39
  *   false si on a pas pu charger l'image
40 40
  */
41
-function svg_charger($fichier, $maxlen=null) {
41
+function svg_charger($fichier, $maxlen = null) {
42 42
 	if (strpos($fichier, "data:image/svg+xml") === 0) {
43 43
 		$image = explode(";", $fichier, 2);
44 44
 		$image = end($image);
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		return $fichier;
58 58
 	}
59 59
 	if (!file_exists($fichier)) {
60
-		$fichier  = supprimer_timestamp($fichier);
60
+		$fichier = supprimer_timestamp($fichier);
61 61
 		if (!file_exists($fichier)) {
62 62
 			var_dump('fail2');
63 63
 			return false;
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 		$image = file_get_contents($fichier);
68 68
 	}
69 69
 	else {
70
-		$image = file_get_contents($fichier, false,null,0, $maxlen);
70
+		$image = file_get_contents($fichier, false, null, 0, $maxlen);
71 71
 	}
72 72
 	// est-ce bien une image svg ?
73 73
 	if (strpos($image, "<svg") !== false) {
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	if (($ps = stripos($debut_fichier, "<svg")) !== false) {
90 90
 
91 91
 		$pe = stripos($debut_fichier, ">", $ps);
92
-		$balise_svg = substr($debut_fichier, $ps, $pe - $ps +1);
92
+		$balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1);
93 93
 
94 94
 		if (preg_match_all(",([\w\-]+)=,Uims", $balise_svg, $matches)) {
95 95
 			if (!function_exists('extraire_attribut')) {
@@ -129,29 +129,29 @@  discard block
 block discarded – undo
129 129
  * @return bool|float|int
130 130
  */
131 131
 function svg_dimension_to_pixels($dimension) {
132
-	if (preg_match(',^(-?\d+)([^\d]*),i', trim($dimension), $m)){
132
+	if (preg_match(',^(-?\d+)([^\d]*),i', trim($dimension), $m)) {
133 133
 		switch (strtolower($m[2])) {
134 134
 			case '%':
135 135
 				// on ne sait pas faire :(
136 136
 				return false;
137 137
 				break;
138 138
 			case 'em':
139
-				return intval($m[1])*16; // 16px font-size par defaut
139
+				return intval($m[1]) * 16; // 16px font-size par defaut
140 140
 				break;
141 141
 			case 'ex':
142
-				return intval($m[1])*16; // 16px font-size par defaut
142
+				return intval($m[1]) * 16; // 16px font-size par defaut
143 143
 				break;
144 144
 			case 'pc':
145
-				return intval($m[1])*16; // 1/6 inch = 96px/6 in CSS
145
+				return intval($m[1]) * 16; // 1/6 inch = 96px/6 in CSS
146 146
 				break;
147 147
 			case 'cm':
148
-				return intval(round($m[1]*96/2.54)); // 96px / 2.54cm;
148
+				return intval(round($m[1] * 96 / 2.54)); // 96px / 2.54cm;
149 149
 				break;
150 150
 			case 'mm':
151
-				return intval(round($m[1]*96/25.4)); // 96px / 25.4mm;
151
+				return intval(round($m[1] * 96 / 25.4)); // 96px / 25.4mm;
152 152
 				break;
153 153
 			case 'in':
154
-				return intval($m[1])*96; // 1 inch = 96px in CSS
154
+				return intval($m[1]) * 96; // 1 inch = 96px in CSS
155 155
 				break;
156 156
 			case 'px':
157 157
 			case 'pt':
@@ -189,15 +189,15 @@  discard block
 block discarded – undo
189 189
  *   inserer au debut (true) ou a la fin (false)
190 190
  * @return string
191 191
  */
192
-function svg_insert_shapes($svg, $shapes, $start=true) {
192
+function svg_insert_shapes($svg, $shapes, $start = true) {
193 193
 
194 194
 	if ($start === false or $start === 'end') {
195
-		$svg = str_replace("</svg>", $shapes . "</svg>", $svg);
195
+		$svg = str_replace("</svg>", $shapes."</svg>", $svg);
196 196
 	}
197 197
 	else {
198 198
 		$p = stripos($svg, "<svg");
199 199
 		$p = strpos($svg, ">", $p);
200
-		$svg = substr_replace($svg, $shapes, $p+1, 0);
200
+		$svg = substr_replace($svg, $shapes, $p + 1, 0);
201 201
 	}
202 202
 	return $svg;
203 203
 }
@@ -213,10 +213,10 @@  discard block
 block discarded – undo
213 213
  */
214 214
 function svg_clip_in_box($svg, $x, $y, $width, $height) {
215 215
 	$rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
216
-	$id = 'clip-'.substr(md5($rect . strlen($svg)),0,8);
216
+	$id = 'clip-'.substr(md5($rect.strlen($svg)), 0, 8);
217 217
 	$clippath = "<clipPath id=\"$id\">$rect</clipPath>";
218 218
 	$g = "<g clip-path=\"url(#$id)\">";
219
-	$svg = svg_insert_shapes($svg, $clippath . $g);
219
+	$svg = svg_insert_shapes($svg, $clippath.$g);
220 220
 	$svg = svg_insert_shapes($svg, "</g>", false);
221 221
 	return $svg;
222 222
 }
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 
235 235
 		list($balise_svg, $attributs) = $svg_infos;
236 236
 		if (!isset($attributs['viewBox'])) {
237
-			$attributs['viewBox'] = "0 0 " . $attributs['width'] . " " . $attributs['height'];
237
+			$attributs['viewBox'] = "0 0 ".$attributs['width']." ".$attributs['height'];
238 238
 		}
239 239
 		$attributs['width'] = strval($new_width);
240 240
 		$attributs['height'] = strval($new_height);
@@ -252,14 +252,14 @@  discard block
 block discarded – undo
252 252
  * @return string
253 253
  */
254 254
 function svg_couleur_to_hexa($couleur) {
255
-	if (strpos($couleur, "rgb(")===0) {
255
+	if (strpos($couleur, "rgb(") === 0) {
256 256
 		$c = explode(',', substr($couleur, 4));
257 257
 		$couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2]));
258 258
 	}
259 259
 	else {
260 260
 		$couleur = couleur_html_to_hex($couleur);
261 261
 	}
262
-	$couleur = '#'.ltrim($couleur,'#');
262
+	$couleur = '#'.ltrim($couleur, '#');
263 263
 	return $couleur;
264 264
 }
265 265
 
@@ -269,9 +269,9 @@  discard block
 block discarded – undo
269 269
  * @return array
270 270
  */
271 271
 function svg_couleur_to_rgb($couleur) {
272
-	if (strpos($couleur, "rgb(")===0) {
272
+	if (strpos($couleur, "rgb(") === 0) {
273 273
 		$c = explode(',', substr($couleur, 4));
274
-		return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])];
274
+		return ['red' => intval($c[0]), 'green' => intval($c[1]), 'blue' => intval($c[2])];
275 275
 	}
276 276
 	return _couleur_hex_to_dec($couleur);
277 277
 }
@@ -290,13 +290,13 @@  discard block
 block discarded – undo
290 290
  */
291 291
 function svg_force_viewBox_px($img) {
292 292
 	if ($svg = svg_charger($img)
293
-	  and $svg_infos = svg_lire_balise_svg($svg)){
293
+	  and $svg_infos = svg_lire_balise_svg($svg)) {
294 294
 
295 295
 		list($balise_svg, $attributs) = $svg_infos;
296 296
 
297 297
 		// il nous faut une viewBox
298 298
 		if (!isset($attributs['viewBox'])) {
299
-			$viewBox = "0 0 " . $attributs['width'] . " " . $attributs['height'];
299
+			$viewBox = "0 0 ".$attributs['width']." ".$attributs['height'];
300 300
 		}
301 301
 		else {
302 302
 			$viewBox = $attributs['viewBox'];
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
  * @param $new_height
342 342
  * @return bool|string
343 343
  */
344
-function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color='') {
344
+function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color = '') {
345 345
 	if ($svg = svg_force_viewBox_px($img)
346 346
 	  and $svg_infos = svg_lire_balise_svg($svg)) {
347 347
 
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 			$viewport_oy = intval(round($viewport_oy * $yscale));
368 368
 		}
369 369
 
370
-		if ($viewport_w>$viewBox[2] or $viewport_h>$viewBox[3]) {
370
+		if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) {
371 371
 			$svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]);
372 372
 		}
373 373
 
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
 		$svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
385 385
 
386 386
 		// ajouter un background
387
-		if ($background_color and $background_color!=='transparent') {
387
+		if ($background_color and $background_color !== 'transparent') {
388 388
 			$svg = svg_ajouter_background($svg, $background_color);
389 389
 		}
390 390
 
@@ -402,9 +402,9 @@  discard block
 block discarded – undo
402 402
  */
403 403
 function svg_ajouter_background($img, $background_color) {
404 404
 	if ($svg = svg_charger($img)
405
-	  and $svg_infos = svg_lire_balise_svg($svg)){
405
+	  and $svg_infos = svg_lire_balise_svg($svg)) {
406 406
 
407
-		if ($background_color and $background_color!=='transparent') {
407
+		if ($background_color and $background_color !== 'transparent') {
408 408
 			list($balise_svg, $attributs) = $svg_infos;
409 409
 
410 410
 			$background_color = svg_couleur_to_hexa($background_color);
@@ -431,9 +431,9 @@  discard block
 block discarded – undo
431 431
  */
432 432
 function svg_ajouter_voile($img, $background_color, $opacity) {
433 433
 	if ($svg = svg_charger($img)
434
-	  and $svg_infos = svg_lire_balise_svg($svg)){
434
+	  and $svg_infos = svg_lire_balise_svg($svg)) {
435 435
 
436
-		if ($background_color and $background_color!=='transparent') {
436
+		if ($background_color and $background_color !== 'transparent') {
437 437
 			list($balise_svg, $attributs) = $svg_infos;
438 438
 
439 439
 			$background_color = svg_couleur_to_hexa($background_color);
@@ -460,10 +460,10 @@  discard block
 block discarded – undo
460 460
  */
461 461
 function svg_transformer($img, $attributs) {
462 462
 	if ($svg = svg_charger($img)
463
-	  and $svg_infos = svg_lire_balise_svg($svg)){
463
+	  and $svg_infos = svg_lire_balise_svg($svg)) {
464 464
 
465 465
 		if ($attributs) {
466
-			list($balise_svg, ) = $svg_infos;
466
+			list($balise_svg,) = $svg_infos;
467 467
 			$g = "<g";
468 468
 			foreach ($attributs as $k=>$v) {
469 469
 				if (strlen($v)) {
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
  */
491 491
 function svg_flip($img, $HorV) {
492 492
 	if ($svg = svg_force_viewBox_px($img)
493
-	  and $svg_infos = svg_lire_balise_svg($svg)){
493
+	  and $svg_infos = svg_lire_balise_svg($svg)) {
494 494
 
495 495
 		list($balise_svg, $atts) = $svg_infos;
496 496
 		$viewBox = explode(' ', $atts['viewBox']);
@@ -498,14 +498,14 @@  discard block
 block discarded – undo
498 498
 		if (!in_array($HorV, ['h', 'H'])) {
499 499
 			$transform = "scale(-1,1)";
500 500
 
501
-			$x = intval($viewBox[0]) + intval($viewBox[2]/2);
501
+			$x = intval($viewBox[0]) + intval($viewBox[2] / 2);
502 502
 			$mx = -$x;
503 503
 			$transform = "translate($x, 0) $transform translate($mx, 0)";
504 504
 		}
505 505
 		else {
506 506
 			$transform = "scale(1,-1)";
507 507
 
508
-			$y = intval($viewBox[1]) + intval($viewBox[3]/2);
508
+			$y = intval($viewBox[1]) + intval($viewBox[3] / 2);
509 509
 			$my = -$y;
510 510
 			$transform = "translate(0, $y) $transform translate(0, $my)";
511 511
 		}
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
  */
528 528
 function svg_rotate($img, $angle, $center_x, $center_y) {
529 529
 	if ($svg = svg_force_viewBox_px($img)
530
-		and $svg_infos = svg_lire_balise_svg($svg)){
530
+		and $svg_infos = svg_lire_balise_svg($svg)) {
531 531
 
532 532
 		list($balise_svg, $atts) = $svg_infos;
533 533
 		$viewBox = explode(' ', $atts['viewBox']);
Please login to merge, or discard this patch.
Braces   +8 added lines, -16 removed lines patch added patch discarded remove patch
@@ -65,8 +65,7 @@  discard block
 block discarded – undo
65 65
 	}
66 66
 	if (is_null($maxlen)) {
67 67
 		$image = file_get_contents($fichier);
68
-	}
69
-	else {
68
+	} else {
70 69
 		$image = file_get_contents($fichier, false,null,0, $maxlen);
71 70
 	}
72 71
 	// est-ce bien une image svg ?
@@ -193,8 +192,7 @@  discard block
 block discarded – undo
193 192
 
194 193
 	if ($start === false or $start === 'end') {
195 194
 		$svg = str_replace("</svg>", $shapes . "</svg>", $svg);
196
-	}
197
-	else {
195
+	} else {
198 196
 		$p = stripos($svg, "<svg");
199 197
 		$p = strpos($svg, ">", $p);
200 198
 		$svg = substr_replace($svg, $shapes, $p+1, 0);
@@ -255,8 +253,7 @@  discard block
 block discarded – undo
255 253
 	if (strpos($couleur, "rgb(")===0) {
256 254
 		$c = explode(',', substr($couleur, 4));
257 255
 		$couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2]));
258
-	}
259
-	else {
256
+	} else {
260 257
 		$couleur = couleur_html_to_hex($couleur);
261 258
 	}
262 259
 	$couleur = '#'.ltrim($couleur,'#');
@@ -297,8 +294,7 @@  discard block
 block discarded – undo
297 294
 		// il nous faut une viewBox
298 295
 		if (!isset($attributs['viewBox'])) {
299 296
 			$viewBox = "0 0 " . $attributs['width'] . " " . $attributs['height'];
300
-		}
301
-		else {
297
+		} else {
302 298
 			$viewBox = $attributs['viewBox'];
303 299
 		}
304 300
 		// et on la convertit en px
@@ -411,8 +407,7 @@  discard block
 block discarded – undo
411 407
 			if (isset($attributs['viewBox'])) {
412 408
 				$viewBox = explode(' ', $attributs['viewBox']);
413 409
 				$rect = "<rect x=\"".$viewBox[0]."\" y=\"".$viewBox[1]."\" width=\"".$viewBox[2]."\" height=\"".$viewBox[3]."\" fill=\"$background_color\"/>";
414
-			}
415
-			else {
410
+			} else {
416 411
 				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
417 412
 			}
418 413
 			$svg = svg_insert_shapes($svg, $rect);
@@ -440,8 +435,7 @@  discard block
 block discarded – undo
440 435
 			if (isset($attributs['viewBox'])) {
441 436
 				$viewBox = explode(' ', $attributs['viewBox']);
442 437
 				$rect = "<rect x=\"".$viewBox[0]."\" y=\"".$viewBox[1]."\" width=\"".$viewBox[2]."\" height=\"".$viewBox[3]."\" fill=\"$background_color\" opacity=\"$opacity\"/>";
443
-			}
444
-			else {
438
+			} else {
445 439
 				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
446 440
 			}
447 441
 			$svg = svg_insert_shapes($svg, $rect, false);
@@ -501,8 +495,7 @@  discard block
 block discarded – undo
501 495
 			$x = intval($viewBox[0]) + intval($viewBox[2]/2);
502 496
 			$mx = -$x;
503 497
 			$transform = "translate($x, 0) $transform translate($mx, 0)";
504
-		}
505
-		else {
498
+		} else {
506 499
 			$transform = "scale(1,-1)";
507 500
 
508 501
 			$y = intval($viewBox[1]) + intval($viewBox[3]/2);
@@ -561,8 +554,7 @@  discard block
 block discarded – undo
561 554
 			$c = array_shift($colors);
562 555
 			if (strlen($c) == 4) {
563 556
 				$short[] = $c;
564
-			}
565
-			else {
557
+			} else {
566 558
 				$long[] = $c;
567 559
 			}
568 560
 		}
Please login to merge, or discard this patch.
ecrire/inc/math.php 2 patches
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 
14 14
 //
15 15
 if (!defined('_ECRIRE_INC_VERSION')) {
16
-	return;
16
+    return;
17 17
 }
18 18
 
19 19
 //
@@ -23,56 +23,56 @@  discard block
 block discarded – undo
23 23
 // http://code.spip.net/@image_math
24 24
 function produire_image_math($tex) {
25 25
 
26
-	switch ($GLOBALS['traiter_math']) {
27
-		// Attention: mathml desactiv'e pour l'instant
28
-		case 'mathml':
29
-			$ext = '.xhtml';
30
-			$server = $GLOBALS['mathml_server'];
31
-			break;
32
-		case 'tex':
33
-			$ext = '.png';
34
-			$server = $GLOBALS['tex_server'];
35
-			break;
36
-		default:
37
-			return $tex;
38
-	}
39
-
40
-	// Regarder dans le repertoire local des images TeX et blocs MathML
41
-	if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) {
42
-		@mkdir($dir_tex, _SPIP_CHMOD);
43
-	}
44
-	$fichier = $dir_tex . md5(trim($tex)) . $ext;
45
-
46
-
47
-	if (!@file_exists($fichier)) {
48
-		// Aller chercher l'image sur le serveur
49
-		if ($server) {
50
-			spip_log($url = $server . '?' . rawurlencode($tex));
51
-			include_spip('inc/distant');
52
-			recuperer_page($url, $fichier);
53
-		}
54
-	}
55
-
56
-
57
-	// Composer la reponse selon presence ou non de l'image
58
-	$tex = entites_html($tex);
59
-	if (@file_exists($fichier)) {
60
-
61
-		// MathML
62
-		if ($GLOBALS['traiter_math'] == 'mathml') {
63
-			return join(file("$fichier"), "");
64
-		} // TeX
65
-		else {
66
-			list(, , , $size) = @spip_getimagesize($fichier);
67
-			$alt = "alt=\"$tex\" title=\"$tex\"";
68
-
69
-			return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />";
70
-		}
71
-
72
-	} else // pas de fichier
73
-	{
74
-		return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>";
75
-	}
26
+    switch ($GLOBALS['traiter_math']) {
27
+        // Attention: mathml desactiv'e pour l'instant
28
+        case 'mathml':
29
+            $ext = '.xhtml';
30
+            $server = $GLOBALS['mathml_server'];
31
+            break;
32
+        case 'tex':
33
+            $ext = '.png';
34
+            $server = $GLOBALS['tex_server'];
35
+            break;
36
+        default:
37
+            return $tex;
38
+    }
39
+
40
+    // Regarder dans le repertoire local des images TeX et blocs MathML
41
+    if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) {
42
+        @mkdir($dir_tex, _SPIP_CHMOD);
43
+    }
44
+    $fichier = $dir_tex . md5(trim($tex)) . $ext;
45
+
46
+
47
+    if (!@file_exists($fichier)) {
48
+        // Aller chercher l'image sur le serveur
49
+        if ($server) {
50
+            spip_log($url = $server . '?' . rawurlencode($tex));
51
+            include_spip('inc/distant');
52
+            recuperer_page($url, $fichier);
53
+        }
54
+    }
55
+
56
+
57
+    // Composer la reponse selon presence ou non de l'image
58
+    $tex = entites_html($tex);
59
+    if (@file_exists($fichier)) {
60
+
61
+        // MathML
62
+        if ($GLOBALS['traiter_math'] == 'mathml') {
63
+            return join(file("$fichier"), "");
64
+        } // TeX
65
+        else {
66
+            list(, , , $size) = @spip_getimagesize($fichier);
67
+            $alt = "alt=\"$tex\" title=\"$tex\"";
68
+
69
+            return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />";
70
+        }
71
+
72
+    } else // pas de fichier
73
+    {
74
+        return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>";
75
+    }
76 76
 
77 77
 }
78 78
 
@@ -108,46 +108,46 @@  discard block
 block discarded – undo
108 108
  */
109 109
 function traiter_math($letexte, $source = '', $defaire_amp = false) {
110 110
 
111
-	$texte_a_voir = $letexte;
112
-	while (($debut = strpos($texte_a_voir, "<math>")) !== false) {
113
-		if (!$fin = strpos($texte_a_voir, "</math>")) {
114
-			$fin = strlen($texte_a_voir);
115
-		}
116
-
117
-		$texte_debut = substr($texte_a_voir, 0, $debut);
118
-		$texte_milieu = substr($texte_a_voir,
119
-			$debut + strlen("<math>"), $fin - $debut - strlen("<math>"));
120
-		$texte_fin = substr($texte_a_voir,
121
-			$fin + strlen("</math>"), strlen($texte_a_voir));
122
-
123
-		// Les doubles $$x^2$$ en mode 'div'
124
-		while ((preg_match(",[$][$]([^$]+)[$][$],", $texte_milieu, $regs))) {
125
-			$expression = $regs[1];
126
-			if ($defaire_amp) {
127
-				$expression = str_replace('&amp;', '&', $expression);
128
-			}
129
-			$echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n";
130
-			$pos = strpos($texte_milieu, $regs[0]);
131
-			$texte_milieu = substr($texte_milieu, 0, $pos)
132
-				. code_echappement($echap, $source)
133
-				. substr($texte_milieu, $pos + strlen($regs[0]));
134
-		}
135
-
136
-		// Les simples $x^2$ en mode 'span'
137
-		while ((preg_match(",[$]([^$]+)[$],", $texte_milieu, $regs))) {
138
-			$expression = $regs[1];
139
-			if ($defaire_amp) {
140
-				$expression = str_replace('&amp;', '&', $expression);
141
-			}
142
-			$echap = produire_image_math($expression);
143
-			$pos = strpos($texte_milieu, $regs[0]);
144
-			$texte_milieu = substr($texte_milieu, 0, $pos)
145
-				. code_echappement($echap, $source)
146
-				. substr($texte_milieu, $pos + strlen($regs[0]));
147
-		}
148
-
149
-		$texte_a_voir = $texte_debut . $texte_milieu . $texte_fin;
150
-	}
151
-
152
-	return $texte_a_voir;
111
+    $texte_a_voir = $letexte;
112
+    while (($debut = strpos($texte_a_voir, "<math>")) !== false) {
113
+        if (!$fin = strpos($texte_a_voir, "</math>")) {
114
+            $fin = strlen($texte_a_voir);
115
+        }
116
+
117
+        $texte_debut = substr($texte_a_voir, 0, $debut);
118
+        $texte_milieu = substr($texte_a_voir,
119
+            $debut + strlen("<math>"), $fin - $debut - strlen("<math>"));
120
+        $texte_fin = substr($texte_a_voir,
121
+            $fin + strlen("</math>"), strlen($texte_a_voir));
122
+
123
+        // Les doubles $$x^2$$ en mode 'div'
124
+        while ((preg_match(",[$][$]([^$]+)[$][$],", $texte_milieu, $regs))) {
125
+            $expression = $regs[1];
126
+            if ($defaire_amp) {
127
+                $expression = str_replace('&amp;', '&', $expression);
128
+            }
129
+            $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n";
130
+            $pos = strpos($texte_milieu, $regs[0]);
131
+            $texte_milieu = substr($texte_milieu, 0, $pos)
132
+                . code_echappement($echap, $source)
133
+                . substr($texte_milieu, $pos + strlen($regs[0]));
134
+        }
135
+
136
+        // Les simples $x^2$ en mode 'span'
137
+        while ((preg_match(",[$]([^$]+)[$],", $texte_milieu, $regs))) {
138
+            $expression = $regs[1];
139
+            if ($defaire_amp) {
140
+                $expression = str_replace('&amp;', '&', $expression);
141
+            }
142
+            $echap = produire_image_math($expression);
143
+            $pos = strpos($texte_milieu, $regs[0]);
144
+            $texte_milieu = substr($texte_milieu, 0, $pos)
145
+                . code_echappement($echap, $source)
146
+                . substr($texte_milieu, $pos + strlen($regs[0]));
147
+        }
148
+
149
+        $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin;
150
+    }
151
+
152
+    return $texte_a_voir;
153 153
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -38,16 +38,16 @@  discard block
 block discarded – undo
38 38
 	}
39 39
 
40 40
 	// Regarder dans le repertoire local des images TeX et blocs MathML
41
-	if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) {
41
+	if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/')) {
42 42
 		@mkdir($dir_tex, _SPIP_CHMOD);
43 43
 	}
44
-	$fichier = $dir_tex . md5(trim($tex)) . $ext;
44
+	$fichier = $dir_tex.md5(trim($tex)).$ext;
45 45
 
46 46
 
47 47
 	if (!@file_exists($fichier)) {
48 48
 		// Aller chercher l'image sur le serveur
49 49
 		if ($server) {
50
-			spip_log($url = $server . '?' . rawurlencode($tex));
50
+			spip_log($url = $server.'?'.rawurlencode($tex));
51 51
 			include_spip('inc/distant');
52 52
 			recuperer_page($url, $fichier);
53 53
 		}
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 			return join(file("$fichier"), "");
64 64
 		} // TeX
65 65
 		else {
66
-			list(, , , $size) = @spip_getimagesize($fichier);
66
+			list(,,, $size) = @spip_getimagesize($fichier);
67 67
 			$alt = "alt=\"$tex\" title=\"$tex\"";
68 68
 
69 69
 			return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />";
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 			if ($defaire_amp) {
127 127
 				$expression = str_replace('&amp;', '&', $expression);
128 128
 			}
129
-			$echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n";
129
+			$echap = "\n<p class=\"spip\" style=\"text-align: center;\">".produire_image_math($expression)."</p>\n";
130 130
 			$pos = strpos($texte_milieu, $regs[0]);
131 131
 			$texte_milieu = substr($texte_milieu, 0, $pos)
132 132
 				. code_echappement($echap, $source)
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 				. substr($texte_milieu, $pos + strlen($regs[0]));
147 147
 		}
148 148
 
149
-		$texte_a_voir = $texte_debut . $texte_milieu . $texte_fin;
149
+		$texte_a_voir = $texte_debut.$texte_milieu.$texte_fin;
150 150
 	}
151 151
 
152 152
 	return $texte_a_voir;
Please login to merge, or discard this patch.
ecrire/inc/utils.php 2 patches
Indentation   +2176 added lines, -2177 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
 
@@ -48,63 +48,63 @@  discard block
 block discarded – undo
48 48
  *     Nom de la fonction, ou false.
49 49
  */
50 50
 function charger_fonction($nom, $dossier = 'exec', $continue = false) {
51
-	static $echecs = array();
52
-
53
-	if (strlen($dossier) and substr($dossier, -1) != '/') {
54
-		$dossier .= '/';
55
-	}
56
-	$f = str_replace('/', '_', $dossier) . $nom;
57
-
58
-	if (function_exists($f)) {
59
-		return $f;
60
-	}
61
-	if (function_exists($g = $f . '_dist')) {
62
-		return $g;
63
-	}
64
-
65
-	if (isset($echecs[$f])) {
66
-		return $echecs[$f];
67
-	}
68
-	// Sinon charger le fichier de declaration si plausible
69
-
70
-	if (!preg_match(',^\w+$,', $f)) {
71
-		if ($continue) {
72
-			return false;
73
-		} //appel interne, on passe
74
-		include_spip('inc/minipres');
75
-		echo minipres();
76
-		exit;
77
-	}
78
-
79
-	// passer en minuscules (cf les balises de formulaires)
80
-	// et inclure le fichier
81
-	if (!$inc = include_spip($dossier . ($d = strtolower($nom)))
82
-		// si le fichier truc/machin/nom.php n'existe pas,
83
-		// la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
84
-		and strlen(dirname($dossier)) and dirname($dossier) != '.'
85
-	) {
86
-		include_spip(substr($dossier, 0, -1));
87
-	}
88
-	if (function_exists($f)) {
89
-		return $f;
90
-	}
91
-	if (function_exists($g)) {
92
-		return $g;
93
-	}
94
-
95
-	if ($continue) {
96
-		return $echecs[$f] = false;
97
-	}
98
-
99
-	// Echec : message d'erreur
100
-	spip_log("fonction $nom ($f ou $g) indisponible" .
101
-		($inc ? "" : " (fichier $d absent de $dossier)"));
102
-
103
-	include_spip('inc/minipres');
104
-	echo minipres(_T('forum_titre_erreur'),
105
-		_T('fichier_introuvable', array('fichier' => '<b>' . spip_htmlentities($d) . '</b>')),
106
-		array('all_inline'=>true,'status'=>404));
107
-	exit;
51
+    static $echecs = array();
52
+
53
+    if (strlen($dossier) and substr($dossier, -1) != '/') {
54
+        $dossier .= '/';
55
+    }
56
+    $f = str_replace('/', '_', $dossier) . $nom;
57
+
58
+    if (function_exists($f)) {
59
+        return $f;
60
+    }
61
+    if (function_exists($g = $f . '_dist')) {
62
+        return $g;
63
+    }
64
+
65
+    if (isset($echecs[$f])) {
66
+        return $echecs[$f];
67
+    }
68
+    // Sinon charger le fichier de declaration si plausible
69
+
70
+    if (!preg_match(',^\w+$,', $f)) {
71
+        if ($continue) {
72
+            return false;
73
+        } //appel interne, on passe
74
+        include_spip('inc/minipres');
75
+        echo minipres();
76
+        exit;
77
+    }
78
+
79
+    // passer en minuscules (cf les balises de formulaires)
80
+    // et inclure le fichier
81
+    if (!$inc = include_spip($dossier . ($d = strtolower($nom)))
82
+        // si le fichier truc/machin/nom.php n'existe pas,
83
+        // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
84
+        and strlen(dirname($dossier)) and dirname($dossier) != '.'
85
+    ) {
86
+        include_spip(substr($dossier, 0, -1));
87
+    }
88
+    if (function_exists($f)) {
89
+        return $f;
90
+    }
91
+    if (function_exists($g)) {
92
+        return $g;
93
+    }
94
+
95
+    if ($continue) {
96
+        return $echecs[$f] = false;
97
+    }
98
+
99
+    // Echec : message d'erreur
100
+    spip_log("fonction $nom ($f ou $g) indisponible" .
101
+        ($inc ? "" : " (fichier $d absent de $dossier)"));
102
+
103
+    include_spip('inc/minipres');
104
+    echo minipres(_T('forum_titre_erreur'),
105
+        _T('fichier_introuvable', array('fichier' => '<b>' . spip_htmlentities($d) . '</b>')),
106
+        array('all_inline'=>true,'status'=>404));
107
+    exit;
108 108
 }
109 109
 
110 110
 /**
@@ -114,17 +114,17 @@  discard block
 block discarded – undo
114 114
  * @return bool
115 115
  */
116 116
 function include_once_check($file) {
117
-	if (file_exists($file)) {
118
-		include_once $file;
117
+    if (file_exists($file)) {
118
+        include_once $file;
119 119
 
120
-		return true;
121
-	}
122
-	$crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
123
-	$crash = ($crash ? $crash : array());
124
-	$crash[$file] = true;
125
-	ecrire_meta('message_crash_plugins', serialize($crash));
120
+        return true;
121
+    }
122
+    $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
123
+    $crash = ($crash ? $crash : array());
124
+    $crash[$file] = true;
125
+    ecrire_meta('message_crash_plugins', serialize($crash));
126 126
 
127
-	return false;
127
+    return false;
128 128
 }
129 129
 
130 130
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
  *     - string : chemin du fichier trouvé
149 149
  **/
150 150
 function include_spip($f, $include = true) {
151
-	return find_in_path($f . '.php', '', $include);
151
+    return find_in_path($f . '.php', '', $include);
152 152
 }
153 153
 
154 154
 /**
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
  *     - string : chemin du fichier trouvé
169 169
  **/
170 170
 function require_spip($f) {
171
-	return find_in_path($f . '.php', '', 'required');
171
+    return find_in_path($f . '.php', '', 'required');
172 172
 }
173 173
 
174 174
 /**
@@ -194,22 +194,22 @@  discard block
 block discarded – undo
194 194
  *     Les paramètres du pipeline modifiés
195 195
  **/
196 196
 function minipipe($fonc, &$val) {
197
-	// fonction
198
-	if (function_exists($fonc)) {
199
-		$val = call_user_func($fonc, $val);
200
-	} // Class::Methode
201
-	else {
202
-		if (preg_match("/^(\w*)::(\w*)$/S", $fonc, $regs)
203
-			and $methode = array($regs[1], $regs[2])
204
-			and is_callable($methode)
205
-		) {
206
-			$val = call_user_func($methode, $val);
207
-		} else {
208
-			spip_log("Erreur - '$fonc' non definie !");
209
-		}
210
-	}
197
+    // fonction
198
+    if (function_exists($fonc)) {
199
+        $val = call_user_func($fonc, $val);
200
+    } // Class::Methode
201
+    else {
202
+        if (preg_match("/^(\w*)::(\w*)$/S", $fonc, $regs)
203
+            and $methode = array($regs[1], $regs[2])
204
+            and is_callable($methode)
205
+        ) {
206
+            $val = call_user_func($methode, $val);
207
+        } else {
208
+            spip_log("Erreur - '$fonc' non definie !");
209
+        }
210
+    }
211 211
 
212
-	return $val;
212
+    return $val;
213 213
 }
214 214
 
215 215
 /**
@@ -240,45 +240,45 @@  discard block
 block discarded – undo
240 240
  *     Résultat
241 241
  */
242 242
 function pipeline($action, $val = null) {
243
-	static $charger;
244
-
245
-	// chargement initial des fonctions mises en cache, ou generation du cache
246
-	if (!$charger) {
247
-		if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
248
-			include_spip('inc/plugin');
249
-			// generer les fichiers php precompiles
250
-			// de chargement des plugins et des pipelines
251
-			actualise_plugins_actifs();
252
-			if (!($ok = @is_readable($charger))) {
253
-				spip_log("fichier $charger pas cree");
254
-			}
255
-		}
256
-
257
-		if ($ok) {
258
-			include_once $charger;
259
-		}
260
-	}
261
-
262
-	// appliquer notre fonction si elle existe
263
-	$fonc = 'execute_pipeline_' . strtolower($action);
264
-	if (function_exists($fonc)) {
265
-		$val = $fonc($val);
266
-	} // plantage ?
267
-	else {
268
-		spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
269
-	}
270
-
271
-	// si le flux est une table avec 2 cle args&data
272
-	// on ne ressort du pipe que les donnees dans 'data'
273
-	// array_key_exists pour php 4.1.0
274
-	if (is_array($val)
275
-		and count($val) == 2
276
-		and (array_key_exists('data', $val))
277
-	) {
278
-		$val = $val['data'];
279
-	}
280
-
281
-	return $val;
243
+    static $charger;
244
+
245
+    // chargement initial des fonctions mises en cache, ou generation du cache
246
+    if (!$charger) {
247
+        if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
248
+            include_spip('inc/plugin');
249
+            // generer les fichiers php precompiles
250
+            // de chargement des plugins et des pipelines
251
+            actualise_plugins_actifs();
252
+            if (!($ok = @is_readable($charger))) {
253
+                spip_log("fichier $charger pas cree");
254
+            }
255
+        }
256
+
257
+        if ($ok) {
258
+            include_once $charger;
259
+        }
260
+    }
261
+
262
+    // appliquer notre fonction si elle existe
263
+    $fonc = 'execute_pipeline_' . strtolower($action);
264
+    if (function_exists($fonc)) {
265
+        $val = $fonc($val);
266
+    } // plantage ?
267
+    else {
268
+        spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
269
+    }
270
+
271
+    // si le flux est une table avec 2 cle args&data
272
+    // on ne ressort du pipe que les donnees dans 'data'
273
+    // array_key_exists pour php 4.1.0
274
+    if (is_array($val)
275
+        and count($val) == 2
276
+        and (array_key_exists('data', $val))
277
+    ) {
278
+        $val = $val['data'];
279
+    }
280
+
281
+    return $val;
282 282
 }
283 283
 
284 284
 /**
@@ -322,35 +322,35 @@  discard block
 block discarded – undo
322 322
  *     paramètre est planté pour cause de compatibilité ascendante.
323 323
  */
324 324
 function spip_log($message = null, $name = null) {
325
-	static $pre = array();
326
-	static $log;
327
-	preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
328
-	if (!isset($regs[1]) or !$logname = $regs[1]) {
329
-		$logname = null;
330
-	}
331
-	if (!isset($regs[2]) or !$niveau = $regs[2]) {
332
-		$niveau = _LOG_INFO;
333
-	}
334
-
335
-	if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
336
-		if (!$pre) {
337
-			$pre = array(
338
-				_LOG_HS => 'HS:',
339
-				_LOG_ALERTE_ROUGE => 'ALERTE:',
340
-				_LOG_CRITIQUE => 'CRITIQUE:',
341
-				_LOG_ERREUR => 'ERREUR:',
342
-				_LOG_AVERTISSEMENT => 'WARNING:',
343
-				_LOG_INFO_IMPORTANTE => '!INFO:',
344
-				_LOG_INFO => 'info:',
345
-				_LOG_DEBUG => 'debug:'
346
-			);
347
-			$log = charger_fonction('log', 'inc');
348
-		}
349
-		if (!is_string($message)) {
350
-			$message = print_r($message, true);
351
-		}
352
-		$log($pre[$niveau] . ' ' . $message, $logname);
353
-	}
325
+    static $pre = array();
326
+    static $log;
327
+    preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
328
+    if (!isset($regs[1]) or !$logname = $regs[1]) {
329
+        $logname = null;
330
+    }
331
+    if (!isset($regs[2]) or !$niveau = $regs[2]) {
332
+        $niveau = _LOG_INFO;
333
+    }
334
+
335
+    if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
336
+        if (!$pre) {
337
+            $pre = array(
338
+                _LOG_HS => 'HS:',
339
+                _LOG_ALERTE_ROUGE => 'ALERTE:',
340
+                _LOG_CRITIQUE => 'CRITIQUE:',
341
+                _LOG_ERREUR => 'ERREUR:',
342
+                _LOG_AVERTISSEMENT => 'WARNING:',
343
+                _LOG_INFO_IMPORTANTE => '!INFO:',
344
+                _LOG_INFO => 'info:',
345
+                _LOG_DEBUG => 'debug:'
346
+            );
347
+            $log = charger_fonction('log', 'inc');
348
+        }
349
+        if (!is_string($message)) {
350
+            $message = print_r($message, true);
351
+        }
352
+        $log($pre[$niveau] . ' ' . $message, $logname);
353
+    }
354 354
 }
355 355
 
356 356
 /**
@@ -361,8 +361,8 @@  discard block
 block discarded – undo
361 361
  * @param array $opt Tableau d'options
362 362
  **/
363 363
 function journal($phrase, $opt = array()) {
364
-	$journal = charger_fonction('journal', 'inc');
365
-	$journal($phrase, $opt);
364
+    $journal = charger_fonction('journal', 'inc');
365
+    $journal($phrase, $opt);
366 366
 }
367 367
 
368 368
 
@@ -381,36 +381,36 @@  discard block
 block discarded – undo
381 381
  **/
382 382
 function _request($var, $c = false) {
383 383
 
384
-	if (is_array($c)) {
385
-		return isset($c[$var]) ? $c[$var] : null;
386
-	}
384
+    if (is_array($c)) {
385
+        return isset($c[$var]) ? $c[$var] : null;
386
+    }
387 387
 
388
-	if (isset($_GET[$var])) {
389
-		$a = $_GET[$var];
390
-	} elseif (isset($_POST[$var])) {
391
-		$a = $_POST[$var];
392
-	} else {
393
-		return null;
394
-	}
388
+    if (isset($_GET[$var])) {
389
+        $a = $_GET[$var];
390
+    } elseif (isset($_POST[$var])) {
391
+        $a = $_POST[$var];
392
+    } else {
393
+        return null;
394
+    }
395 395
 
396
-	// Si on est en ajax et en POST tout a ete encode
397
-	// via encodeURIComponent, il faut donc repasser
398
-	// dans le charset local...
399
-	if (defined('_AJAX')
400
-		and _AJAX
401
-		and isset($GLOBALS['meta']['charset'])
402
-		and $GLOBALS['meta']['charset'] != 'utf-8'
403
-		and is_string($a)
404
-		// check rapide mais pas fiable
405
-		and preg_match(',[\x80-\xFF],', $a)
406
-		// check fiable
407
-		and include_spip('inc/charsets')
408
-		and is_utf8($a)
409
-	) {
410
-		return importer_charset($a, 'utf-8');
411
-	}
396
+    // Si on est en ajax et en POST tout a ete encode
397
+    // via encodeURIComponent, il faut donc repasser
398
+    // dans le charset local...
399
+    if (defined('_AJAX')
400
+        and _AJAX
401
+        and isset($GLOBALS['meta']['charset'])
402
+        and $GLOBALS['meta']['charset'] != 'utf-8'
403
+        and is_string($a)
404
+        // check rapide mais pas fiable
405
+        and preg_match(',[\x80-\xFF],', $a)
406
+        // check fiable
407
+        and include_spip('inc/charsets')
408
+        and is_utf8($a)
409
+    ) {
410
+        return importer_charset($a, 'utf-8');
411
+    }
412 412
 
413
-	return $a;
413
+    return $a;
414 414
 }
415 415
 
416 416
 
@@ -428,22 +428,22 @@  discard block
 block discarded – undo
428 428
  *     - false sinon
429 429
  **/
430 430
 function set_request($var, $val = null, $c = false) {
431
-	if (is_array($c)) {
432
-		unset($c[$var]);
433
-		if ($val !== null) {
434
-			$c[$var] = $val;
435
-		}
431
+    if (is_array($c)) {
432
+        unset($c[$var]);
433
+        if ($val !== null) {
434
+            $c[$var] = $val;
435
+        }
436 436
 
437
-		return $c;
438
-	}
437
+        return $c;
438
+    }
439 439
 
440
-	unset($_GET[$var]);
441
-	unset($_POST[$var]);
442
-	if ($val !== null) {
443
-		$_GET[$var] = $val;
444
-	}
440
+    unset($_GET[$var]);
441
+    unset($_POST[$var]);
442
+    if ($val !== null) {
443
+        $_GET[$var] = $val;
444
+    }
445 445
 
446
-	return false; # n'affecte pas $c
446
+    return false; # n'affecte pas $c
447 447
 }
448 448
 
449 449
 
@@ -452,23 +452,22 @@  discard block
 block discarded – undo
452 452
  * 
453 453
  * On est sur le web, on exclut certains protocoles, 
454 454
  * notamment 'file://', 'php://' et d'autres…
455
-
456 455
  * @param string $url
457 456
  * @return bool
458 457
  */
459 458
 function tester_url_absolue($url) {
460
-	$url = trim($url);
461
-	if (preg_match(";^([a-z]{3,7}:)?//;Uims", $url, $m)) {
462
-		if (
463
-			isset($m[1])
464
-			and $p = strtolower(rtrim($m[1], ':'))
465
-			and in_array($p, array('file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'))
466
-		  ) {
467
-			return false;
468
-		}
469
-		return true;
470
-	}
471
-	return false;
459
+    $url = trim($url);
460
+    if (preg_match(";^([a-z]{3,7}:)?//;Uims", $url, $m)) {
461
+        if (
462
+            isset($m[1])
463
+            and $p = strtolower(rtrim($m[1], ':'))
464
+            and in_array($p, array('file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'))
465
+            ) {
466
+            return false;
467
+        }
468
+        return true;
469
+    }
470
+    return false;
472 471
 }
473 472
 
474 473
 /**
@@ -490,94 +489,94 @@  discard block
 block discarded – undo
490 489
  * @return string URL
491 490
  */
492 491
 function parametre_url($url, $c, $v = null, $sep = '&amp;') {
493
-	// requete erronnee : plusieurs variable dans $c et aucun $v
494
-	if (strpos($c, "|") !== false and is_null($v)) {
495
-		return null;
496
-	}
497
-
498
-	// lever l'#ancre
499
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
500
-		$url = $r[1];
501
-		$ancre = $r[2];
502
-	} else {
503
-		$ancre = '';
504
-	}
505
-
506
-	// eclater
507
-	$url = preg_split(',[?]|&amp;|&,', $url);
508
-
509
-	// recuperer la base
510
-	$a = array_shift($url);
511
-	if (!$a) {
512
-		$a = './';
513
-	}
514
-
515
-	$regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,';
516
-	$ajouts = array_flip(explode('|', $c));
517
-	$u = is_array($v) ? $v : rawurlencode($v);
518
-	$testv = (is_array($v) ? count($v) : strlen($v));
519
-	$v_read = null;
520
-	// lire les variables et agir
521
-	foreach ($url as $n => $val) {
522
-		if (preg_match($regexp, urldecode($val), $r)) {
523
-			$r = array_pad($r, 3, null);
524
-			if ($v === null) {
525
-				// c'est un tableau, on memorise les valeurs
526
-				if (substr($r[1], -2) == "[]") {
527
-					if (!$v_read) {
528
-						$v_read = array();
529
-					}
530
-					$v_read[] = $r[2] ? substr($r[2], 1) : '';
531
-				} // c'est un scalaire, on retourne direct
532
-				else {
533
-					return $r[2] ? substr($r[2], 1) : '';
534
-				}
535
-			} // suppression
536
-			elseif (!$testv) {
537
-				unset($url[$n]);
538
-			}
539
-			// Ajout. Pour une variable, remplacer au meme endroit,
540
-			// pour un tableau ce sera fait dans la prochaine boucle
541
-			elseif (substr($r[1], -2) != '[]') {
542
-				$url[$n] = $r[1] . '=' . $u;
543
-				unset($ajouts[$r[1]]);
544
-			}
545
-			// Pour les tableaux on laisse tomber les valeurs de
546
-			// départ, on remplira à l'étape suivante
547
-			else {
548
-				unset($url[$n]);
549
-			}
550
-		}
551
-	}
552
-
553
-	// traiter les parametres pas encore trouves
554
-	if ($v === null
555
-		and $args = func_get_args()
556
-		and count($args) == 2
557
-	) {
558
-		return $v_read; // rien trouve ou un tableau
559
-	} elseif ($testv) {
560
-		foreach ($ajouts as $k => $n) {
561
-			if (!is_array($v)) {
562
-				$url[] = $k . '=' . $u;
563
-			} else {
564
-				$id = (substr($k, -2) == '[]') ? $k : ($k . "[]");
565
-				foreach ($v as $w) {
566
-					$url[] = $id . '=' . (is_array($w) ? 'Array' : $w);
567
-				}
568
-			}
569
-		}
570
-	}
571
-
572
-	// eliminer les vides
573
-	$url = array_filter($url);
574
-
575
-	// recomposer l'adresse
576
-	if ($url) {
577
-		$a .= '?' . join($sep, $url);
578
-	}
579
-
580
-	return $a . $ancre;
492
+    // requete erronnee : plusieurs variable dans $c et aucun $v
493
+    if (strpos($c, "|") !== false and is_null($v)) {
494
+        return null;
495
+    }
496
+
497
+    // lever l'#ancre
498
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
499
+        $url = $r[1];
500
+        $ancre = $r[2];
501
+    } else {
502
+        $ancre = '';
503
+    }
504
+
505
+    // eclater
506
+    $url = preg_split(',[?]|&amp;|&,', $url);
507
+
508
+    // recuperer la base
509
+    $a = array_shift($url);
510
+    if (!$a) {
511
+        $a = './';
512
+    }
513
+
514
+    $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,';
515
+    $ajouts = array_flip(explode('|', $c));
516
+    $u = is_array($v) ? $v : rawurlencode($v);
517
+    $testv = (is_array($v) ? count($v) : strlen($v));
518
+    $v_read = null;
519
+    // lire les variables et agir
520
+    foreach ($url as $n => $val) {
521
+        if (preg_match($regexp, urldecode($val), $r)) {
522
+            $r = array_pad($r, 3, null);
523
+            if ($v === null) {
524
+                // c'est un tableau, on memorise les valeurs
525
+                if (substr($r[1], -2) == "[]") {
526
+                    if (!$v_read) {
527
+                        $v_read = array();
528
+                    }
529
+                    $v_read[] = $r[2] ? substr($r[2], 1) : '';
530
+                } // c'est un scalaire, on retourne direct
531
+                else {
532
+                    return $r[2] ? substr($r[2], 1) : '';
533
+                }
534
+            } // suppression
535
+            elseif (!$testv) {
536
+                unset($url[$n]);
537
+            }
538
+            // Ajout. Pour une variable, remplacer au meme endroit,
539
+            // pour un tableau ce sera fait dans la prochaine boucle
540
+            elseif (substr($r[1], -2) != '[]') {
541
+                $url[$n] = $r[1] . '=' . $u;
542
+                unset($ajouts[$r[1]]);
543
+            }
544
+            // Pour les tableaux on laisse tomber les valeurs de
545
+            // départ, on remplira à l'étape suivante
546
+            else {
547
+                unset($url[$n]);
548
+            }
549
+        }
550
+    }
551
+
552
+    // traiter les parametres pas encore trouves
553
+    if ($v === null
554
+        and $args = func_get_args()
555
+        and count($args) == 2
556
+    ) {
557
+        return $v_read; // rien trouve ou un tableau
558
+    } elseif ($testv) {
559
+        foreach ($ajouts as $k => $n) {
560
+            if (!is_array($v)) {
561
+                $url[] = $k . '=' . $u;
562
+            } else {
563
+                $id = (substr($k, -2) == '[]') ? $k : ($k . "[]");
564
+                foreach ($v as $w) {
565
+                    $url[] = $id . '=' . (is_array($w) ? 'Array' : $w);
566
+                }
567
+            }
568
+        }
569
+    }
570
+
571
+    // eliminer les vides
572
+    $url = array_filter($url);
573
+
574
+    // recomposer l'adresse
575
+    if ($url) {
576
+        $a .= '?' . join($sep, $url);
577
+    }
578
+
579
+    return $a . $ancre;
581 580
 }
582 581
 
583 582
 /**
@@ -595,21 +594,21 @@  discard block
 block discarded – undo
595 594
  * @return string
596 595
  */
597 596
 function ancre_url($url, $ancre) {
598
-	// lever l'#ancre
599
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
600
-		$url = $r[1];
601
-	}
602
-	if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
603
-		if (!function_exists('translitteration')) {
604
-			include_spip('inc/charsets');
605
-		}
606
-		$ancre = preg_replace(
607
-			array('/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'),
608
-			array('', '-'),
609
-			translitteration($ancre)
610
-		);
611
-	}
612
-	return $url . (strlen($ancre) ? '#' . $ancre : '');
597
+    // lever l'#ancre
598
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
599
+        $url = $r[1];
600
+    }
601
+    if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
602
+        if (!function_exists('translitteration')) {
603
+            include_spip('inc/charsets');
604
+        }
605
+        $ancre = preg_replace(
606
+            array('/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'),
607
+            array('', '-'),
608
+            translitteration($ancre)
609
+        );
610
+    }
611
+    return $url . (strlen($ancre) ? '#' . $ancre : '');
613 612
 }
614 613
 
615 614
 /**
@@ -619,16 +618,16 @@  discard block
 block discarded – undo
619 618
  * @return string
620 619
  */
621 620
 function nettoyer_uri($reset = null) {
622
-	static $done = false;
623
-	static $propre = '';
624
-	if (!is_null($reset)) {
625
-		return $propre = $reset;
626
-	}
627
-	if ($done) {
628
-		return $propre;
629
-	}
630
-	$done = true;
631
-	return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
621
+    static $done = false;
622
+    static $propre = '';
623
+    if (!is_null($reset)) {
624
+        return $propre = $reset;
625
+    }
626
+    if ($done) {
627
+        return $propre;
628
+    }
629
+    $done = true;
630
+    return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
632 631
 }
633 632
 
634 633
 /**
@@ -640,13 +639,13 @@  discard block
 block discarded – undo
640 639
  * @return string
641 640
  */
642 641
 function nettoyer_uri_var($request_uri) {
643
-	$uri1 = $request_uri;
644
-	do {
645
-		$uri = $uri1;
646
-		$uri1 = preg_replace(',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
647
-			'\1', $uri);
648
-	} while ($uri <> $uri1);
649
-	return preg_replace(',[?&]$,', '', $uri1);
642
+    $uri1 = $request_uri;
643
+    do {
644
+        $uri = $uri1;
645
+        $uri1 = preg_replace(',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
646
+            '\1', $uri);
647
+    } while ($uri <> $uri1);
648
+    return preg_replace(',[?&]$,', '', $uri1);
650 649
 }
651 650
 
652 651
 
@@ -660,47 +659,47 @@  discard block
 block discarded – undo
660 659
  *    URL vers soi-même
661 660
  **/
662 661
 function self($amp = '&amp;', $root = false) {
663
-	$url = nettoyer_uri();
664
-	if (!$root
665
-		and (
666
-			// si pas de profondeur on peut tronquer
667
-			$GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
668
-			// sinon c'est OK si _SET_HTML_BASE a ete force a false
669
-			or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
670
-	) {
671
-		$url = preg_replace(',^[^?]*/,', '', $url);
672
-	}
673
-	// ajouter le cas echeant les variables _POST['id_...']
674
-	foreach ($_POST as $v => $c) {
675
-		if (substr($v, 0, 3) == 'id_') {
676
-			$url = parametre_url($url, $v, $c, '&');
677
-		}
678
-	}
679
-
680
-	// supprimer les variables sans interet
681
-	if (test_espace_prive()) {
682
-		$url = preg_replace(',([?&])('
683
-			. 'lang|show_docs|'
684
-			. 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
685
-		$url = preg_replace(',([?&])[&]+,', '\1', $url);
686
-		$url = preg_replace(',[&]$,', '\1', $url);
687
-	}
688
-
689
-	// eviter les hacks
690
-	include_spip('inc/filtres_mini');
691
-	$url = spip_htmlspecialchars($url);
662
+    $url = nettoyer_uri();
663
+    if (!$root
664
+        and (
665
+            // si pas de profondeur on peut tronquer
666
+            $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
667
+            // sinon c'est OK si _SET_HTML_BASE a ete force a false
668
+            or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
669
+    ) {
670
+        $url = preg_replace(',^[^?]*/,', '', $url);
671
+    }
672
+    // ajouter le cas echeant les variables _POST['id_...']
673
+    foreach ($_POST as $v => $c) {
674
+        if (substr($v, 0, 3) == 'id_') {
675
+            $url = parametre_url($url, $v, $c, '&');
676
+        }
677
+    }
678
+
679
+    // supprimer les variables sans interet
680
+    if (test_espace_prive()) {
681
+        $url = preg_replace(',([?&])('
682
+            . 'lang|show_docs|'
683
+            . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
684
+        $url = preg_replace(',([?&])[&]+,', '\1', $url);
685
+        $url = preg_replace(',[&]$,', '\1', $url);
686
+    }
687
+
688
+    // eviter les hacks
689
+    include_spip('inc/filtres_mini');
690
+    $url = spip_htmlspecialchars($url);
692 691
 	
693
-	$url = str_replace(array("'", '"', '<', '[', ']', ':'), array('%27', '%22', '%3C', '%5B', '%5D', '%3A'), $url);
692
+    $url = str_replace(array("'", '"', '<', '[', ']', ':'), array('%27', '%22', '%3C', '%5B', '%5D', '%3A'), $url);
694 693
 
695
-	// &amp; ?
696
-	if ($amp != '&amp;') {
697
-		$url = str_replace('&amp;', $amp, $url);
698
-	}
694
+    // &amp; ?
695
+    if ($amp != '&amp;') {
696
+        $url = str_replace('&amp;', $amp, $url);
697
+    }
699 698
 
700
-	// Si ca demarre par ? ou vide, donner './'
701
-	$url = preg_replace(',^([?].*)?$,', './\1', $url);
699
+    // Si ca demarre par ? ou vide, donner './'
700
+    $url = preg_replace(',^([?].*)?$,', './\1', $url);
702 701
 
703
-	return $url;
702
+    return $url;
704 703
 }
705 704
 
706 705
 
@@ -711,7 +710,7 @@  discard block
 block discarded – undo
711 710
  *     true si c'est le cas, false sinon.
712 711
  */
713 712
 function test_espace_prive() {
714
-	return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
713
+    return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
715 714
 }
716 715
 
717 716
 /**
@@ -721,7 +720,7 @@  discard block
 block discarded – undo
721 720
  * @return bool
722 721
  */
723 722
 function test_plugin_actif($plugin) {
724
-	return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
723
+    return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
725 724
 }
726 725
 
727 726
 /**
@@ -752,51 +751,51 @@  discard block
 block discarded – undo
752 751
  *     Texte
753 752
  */
754 753
 function _T($texte, $args = array(), $options = array()) {
755
-	static $traduire = false;
756
-	$o = array('class' => '', 'force' => true, 'sanitize' => true);
757
-	if ($options) {
758
-		// support de l'ancien argument $class
759
-		if (is_string($options)) {
760
-			$options = array('class' => $options);
761
-		}
762
-		$o = array_merge($o, $options);
763
-	}
754
+    static $traduire = false;
755
+    $o = array('class' => '', 'force' => true, 'sanitize' => true);
756
+    if ($options) {
757
+        // support de l'ancien argument $class
758
+        if (is_string($options)) {
759
+            $options = array('class' => $options);
760
+        }
761
+        $o = array_merge($o, $options);
762
+    }
764 763
 
765
-	if (!$traduire) {
766
-		$traduire = charger_fonction('traduire', 'inc');
767
-		include_spip('inc/lang');
768
-	}
764
+    if (!$traduire) {
765
+        $traduire = charger_fonction('traduire', 'inc');
766
+        include_spip('inc/lang');
767
+    }
769 768
 
770
-	// On peut passer explicitement la langue dans le tableau
771
-	// On utilise le même nom de variable que la globale
772
-	if (isset($args['spip_lang'])) {
773
-		$lang = $args['spip_lang'];
774
-		// On l'enleve pour ne pas le passer au remplacement
775
-		unset($args['spip_lang']);
776
-	} // Sinon on prend la langue du contexte
777
-	else {
778
-		$lang = $GLOBALS['spip_lang'];
779
-	}
780
-	$text = $traduire($texte, $lang);
769
+    // On peut passer explicitement la langue dans le tableau
770
+    // On utilise le même nom de variable que la globale
771
+    if (isset($args['spip_lang'])) {
772
+        $lang = $args['spip_lang'];
773
+        // On l'enleve pour ne pas le passer au remplacement
774
+        unset($args['spip_lang']);
775
+    } // Sinon on prend la langue du contexte
776
+    else {
777
+        $lang = $GLOBALS['spip_lang'];
778
+    }
779
+    $text = $traduire($texte, $lang);
781 780
 
782
-	if (!strlen($text)) {
783
-		if (!$o['force']) {
784
-			return '';
785
-		}
781
+    if (!strlen($text)) {
782
+        if (!$o['force']) {
783
+            return '';
784
+        }
786 785
 
787
-		$text = $texte;
786
+        $text = $texte;
788 787
 
789
-		// pour les chaines non traduites, assurer un service minimum
790
-		if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
791
-			$text = str_replace('_', ' ',
792
-				(($n = strpos($text, ':')) === false ? $texte :
793
-					substr($texte, $n + 1)));
794
-		}
795
-		$o['class'] = null;
788
+        // pour les chaines non traduites, assurer un service minimum
789
+        if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
790
+            $text = str_replace('_', ' ',
791
+                (($n = strpos($text, ':')) === false ? $texte :
792
+                    substr($texte, $n + 1)));
793
+        }
794
+        $o['class'] = null;
796 795
 
797
-	}
796
+    }
798 797
 
799
-	return _L($text, $args, $o);
798
+    return _L($text, $args, $o);
800 799
 
801 800
 }
802 801
 
@@ -824,54 +823,54 @@  discard block
 block discarded – undo
824 823
  *     Texte
825 824
  */
826 825
 function _L($text, $args = array(), $options = array()) {
827
-	$f = $text;
828
-	$defaut_options = array(
829
-		'class' => null,
830
-		'sanitize' => true,
831
-	);
832
-	// support de l'ancien argument $class
833
-	if ($options and is_string($options)) {
834
-		$options = array('class' => $options);
835
-	}
836
-	if (is_array($options)) {
837
-		$options += $defaut_options;
838
-	} else {
839
-		$options = $defaut_options;
840
-	}
841
-
842
-	if (is_array($args)) {
843
-		if (!function_exists('interdire_scripts')) {
844
-			include_spip('inc/texte');
845
-		}
846
-		if (!function_exists('echapper_html_suspect')) {
847
-			include_spip('inc/texte_mini');
848
-		}
849
-		foreach ($args as $name => $value) {
850
-			if ($options['sanitize']) {
851
-				$value = echapper_html_suspect($value);
852
-				$value = interdire_scripts($value, -1);
853
-			}
854
-			if (!empty($options['class'])) {
855
-				$value = "<span class='".$options['class']."'>$value</span>";
856
-			}
857
-			$t = str_replace("@$name@", $value, $text);
858
-			if ($text !== $t) {
859
-				unset($args[$name]);
860
-				$text = $t;
861
-			}
862
-		}
863
-		// Si des variables n'ont pas ete inserees, le signaler
864
-		// (chaines de langues pas a jour)
865
-		if ($args) {
866
-			spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
867
-		}
868
-	}
869
-
870
-	if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
871
-		return "<span class=debug-traduction-erreur>$text</span>";
872
-	} else {
873
-		return $text;
874
-	}
826
+    $f = $text;
827
+    $defaut_options = array(
828
+        'class' => null,
829
+        'sanitize' => true,
830
+    );
831
+    // support de l'ancien argument $class
832
+    if ($options and is_string($options)) {
833
+        $options = array('class' => $options);
834
+    }
835
+    if (is_array($options)) {
836
+        $options += $defaut_options;
837
+    } else {
838
+        $options = $defaut_options;
839
+    }
840
+
841
+    if (is_array($args)) {
842
+        if (!function_exists('interdire_scripts')) {
843
+            include_spip('inc/texte');
844
+        }
845
+        if (!function_exists('echapper_html_suspect')) {
846
+            include_spip('inc/texte_mini');
847
+        }
848
+        foreach ($args as $name => $value) {
849
+            if ($options['sanitize']) {
850
+                $value = echapper_html_suspect($value);
851
+                $value = interdire_scripts($value, -1);
852
+            }
853
+            if (!empty($options['class'])) {
854
+                $value = "<span class='".$options['class']."'>$value</span>";
855
+            }
856
+            $t = str_replace("@$name@", $value, $text);
857
+            if ($text !== $t) {
858
+                unset($args[$name]);
859
+                $text = $t;
860
+            }
861
+        }
862
+        // Si des variables n'ont pas ete inserees, le signaler
863
+        // (chaines de langues pas a jour)
864
+        if ($args) {
865
+            spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
866
+        }
867
+    }
868
+
869
+    if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
870
+        return "<span class=debug-traduction-erreur>$text</span>";
871
+    } else {
872
+        return $text;
873
+    }
875 874
 }
876 875
 
877 876
 
@@ -885,13 +884,13 @@  discard block
 block discarded – undo
885 884
  * @return string
886 885
  */
887 886
 function joli_repertoire($rep) {
888
-	$a = substr($rep, 0, 1);
889
-	if ($a <> '.' and $a <> '/') {
890
-		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
891
-	}
892
-	$rep = preg_replace(',(^\.\.\/),', '', $rep);
887
+    $a = substr($rep, 0, 1);
888
+    if ($a <> '.' and $a <> '/') {
889
+        $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
890
+    }
891
+    $rep = preg_replace(',(^\.\.\/),', '', $rep);
893 892
 
894
-	return $rep;
893
+    return $rep;
895 894
 }
896 895
 
897 896
 
@@ -916,33 +915,33 @@  discard block
 block discarded – undo
916 915
  * @return float|int|string|void
917 916
  */
918 917
 function spip_timer($t = 'rien', $raw = false) {
919
-	static $time;
920
-	$a = time();
921
-	$b = microtime();
922
-	// microtime peut contenir les microsecondes et le temps
923
-	$b = explode(' ', $b);
924
-	if (count($b) == 2) {
925
-		$a = end($b);
926
-	} // plus precis !
927
-	$b = reset($b);
928
-	if (!isset($time[$t])) {
929
-		$time[$t] = $a + $b;
930
-	} else {
931
-		$p = ($a + $b - $time[$t]) * 1000;
932
-		unset($time[$t]);
918
+    static $time;
919
+    $a = time();
920
+    $b = microtime();
921
+    // microtime peut contenir les microsecondes et le temps
922
+    $b = explode(' ', $b);
923
+    if (count($b) == 2) {
924
+        $a = end($b);
925
+    } // plus precis !
926
+    $b = reset($b);
927
+    if (!isset($time[$t])) {
928
+        $time[$t] = $a + $b;
929
+    } else {
930
+        $p = ($a + $b - $time[$t]) * 1000;
931
+        unset($time[$t]);
933 932
 #			echo "'$p'";exit;
934
-		if ($raw) {
935
-			return $p;
936
-		}
937
-		if ($p < 1000) {
938
-			$s = '';
939
-		} else {
940
-			$s = sprintf("%d ", $x = floor($p / 1000));
941
-			$p -= ($x * 1000);
942
-		}
933
+        if ($raw) {
934
+            return $p;
935
+        }
936
+        if ($p < 1000) {
937
+            $s = '';
938
+        } else {
939
+            $s = sprintf("%d ", $x = floor($p / 1000));
940
+            $p -= ($x * 1000);
941
+        }
943 942
 
944
-		return $s . sprintf($s ? "%07.3f ms" : "%.3f ms", $p);
945
-	}
943
+        return $s . sprintf($s ? "%07.3f ms" : "%.3f ms", $p);
944
+    }
946 945
 }
947 946
 
948 947
 
@@ -950,21 +949,21 @@  discard block
 block discarded – undo
950 949
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
951 950
 // http://code.spip.net/@spip_touch
952 951
 function spip_touch($fichier, $duree = 0, $touch = true) {
953
-	if ($duree) {
954
-		clearstatcache();
955
-		if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
956
-			return false;
957
-		}
958
-	}
959
-	if ($touch !== false) {
960
-		if (!@touch($fichier)) {
961
-			spip_unlink($fichier);
962
-			@touch($fichier);
963
-		};
964
-		@chmod($fichier, _SPIP_CHMOD & ~0111);
965
-	}
952
+    if ($duree) {
953
+        clearstatcache();
954
+        if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
955
+            return false;
956
+        }
957
+    }
958
+    if ($touch !== false) {
959
+        if (!@touch($fichier)) {
960
+            spip_unlink($fichier);
961
+            @touch($fichier);
962
+        };
963
+        @chmod($fichier, _SPIP_CHMOD & ~0111);
964
+    }
966 965
 
967
-	return true;
966
+    return true;
968 967
 }
969 968
 
970 969
 
@@ -976,11 +975,11 @@  discard block
 block discarded – undo
976 975
  * @uses cron()
977 976
  **/
978 977
 function action_cron() {
979
-	include_spip('inc/headers');
980
-	http_status(204); // No Content
981
-	header("Connection: close");
982
-	define('_DIRECT_CRON_FORCE', true);
983
-	cron();
978
+    include_spip('inc/headers');
979
+    http_status(204); // No Content
980
+    header("Connection: close");
981
+    define('_DIRECT_CRON_FORCE', true);
982
+    cron();
984 983
 }
985 984
 
986 985
 /**
@@ -996,26 +995,26 @@  discard block
 block discarded – undo
996 995
  *     True si la tache a pu être effectuée
997 996
  */
998 997
 function cron($taches = array(), $taches_old = array()) {
999
-	// si pas en mode cron force, laisser tomber.
1000
-	if (!defined('_DIRECT_CRON_FORCE')) {
1001
-		return false;
1002
-	}
1003
-	if (!is_array($taches)) {
1004
-		$taches = $taches_old;
1005
-	} // compat anciens appels
1006
-	// si taches a inserer en base et base inaccessible, laisser tomber
1007
-	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1008
-	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1009
-	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1010
-	if ($taches and count($taches) and !spip_connect()) {
1011
-		return false;
1012
-	}
1013
-	spip_log("cron !", 'jq' . _LOG_DEBUG);
1014
-	if ($genie = charger_fonction('genie', 'inc', true)) {
1015
-		return $genie($taches);
1016
-	}
1017
-
1018
-	return false;
998
+    // si pas en mode cron force, laisser tomber.
999
+    if (!defined('_DIRECT_CRON_FORCE')) {
1000
+        return false;
1001
+    }
1002
+    if (!is_array($taches)) {
1003
+        $taches = $taches_old;
1004
+    } // compat anciens appels
1005
+    // si taches a inserer en base et base inaccessible, laisser tomber
1006
+    // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1007
+    // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1008
+    // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1009
+    if ($taches and count($taches) and !spip_connect()) {
1010
+        return false;
1011
+    }
1012
+    spip_log("cron !", 'jq' . _LOG_DEBUG);
1013
+    if ($genie = charger_fonction('genie', 'inc', true)) {
1014
+        return $genie($taches);
1015
+    }
1016
+
1017
+    return false;
1019 1018
 }
1020 1019
 
1021 1020
 /**
@@ -1047,17 +1046,17 @@  discard block
 block discarded – undo
1047 1046
  *     Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté.
1048 1047
  */
1049 1048
 function job_queue_add(
1050
-	$function,
1051
-	$description,
1052
-	$arguments = array(),
1053
-	$file = '',
1054
-	$no_duplicate = false,
1055
-	$time = 0,
1056
-	$priority = 0
1049
+    $function,
1050
+    $description,
1051
+    $arguments = array(),
1052
+    $file = '',
1053
+    $no_duplicate = false,
1054
+    $time = 0,
1055
+    $priority = 0
1057 1056
 ) {
1058
-	include_spip('inc/queue');
1057
+    include_spip('inc/queue');
1059 1058
 
1060
-	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1059
+    return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1061 1060
 }
1062 1061
 
1063 1062
 /**
@@ -1068,9 +1067,9 @@  discard block
 block discarded – undo
1068 1067
  * @return bool
1069 1068
  */
1070 1069
 function job_queue_remove($id_job) {
1071
-	include_spip('inc/queue');
1070
+    include_spip('inc/queue');
1072 1071
 
1073
-	return queue_remove_job($id_job);
1072
+    return queue_remove_job($id_job);
1074 1073
 }
1075 1074
 
1076 1075
 /**
@@ -1083,9 +1082,9 @@  discard block
 block discarded – undo
1083 1082
  *     or an array of simple array to link multiples objet in one time
1084 1083
  */
1085 1084
 function job_queue_link($id_job, $objets) {
1086
-	include_spip('inc/queue');
1085
+    include_spip('inc/queue');
1087 1086
 
1088
-	return queue_link_job($id_job, $objets);
1087
+    return queue_link_job($id_job, $objets);
1089 1088
 }
1090 1089
 
1091 1090
 
@@ -1105,36 +1104,36 @@  discard block
 block discarded – undo
1105 1104
  *  - `null` si la queue n'est pas encore initialisée
1106 1105
  */
1107 1106
 function queue_sleep_time_to_next_job($force = null) {
1108
-	static $queue_next_job_time = -1;
1109
-	if ($force === true) {
1110
-		$queue_next_job_time = -1;
1111
-	} elseif ($force) {
1112
-		$queue_next_job_time = $force;
1113
-	}
1114
-
1115
-	if ($queue_next_job_time == -1) {
1116
-		if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1117
-			define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . "job_queue_next.txt");
1118
-		}
1119
-		// utiliser un cache memoire si dispo
1120
-		if (function_exists("cache_get") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1121
-			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1122
-		} else {
1123
-			$queue_next_job_time = null;
1124
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1125
-				$queue_next_job_time = intval($contenu);
1126
-			}
1127
-		}
1128
-	}
1129
-
1130
-	if (is_null($queue_next_job_time)) {
1131
-		return null;
1132
-	}
1133
-	if (!$_SERVER['REQUEST_TIME']) {
1134
-		$_SERVER['REQUEST_TIME'] = time();
1135
-	}
1136
-
1137
-	return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1107
+    static $queue_next_job_time = -1;
1108
+    if ($force === true) {
1109
+        $queue_next_job_time = -1;
1110
+    } elseif ($force) {
1111
+        $queue_next_job_time = $force;
1112
+    }
1113
+
1114
+    if ($queue_next_job_time == -1) {
1115
+        if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1116
+            define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . "job_queue_next.txt");
1117
+        }
1118
+        // utiliser un cache memoire si dispo
1119
+        if (function_exists("cache_get") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1120
+            $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1121
+        } else {
1122
+            $queue_next_job_time = null;
1123
+            if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1124
+                $queue_next_job_time = intval($contenu);
1125
+            }
1126
+        }
1127
+    }
1128
+
1129
+    if (is_null($queue_next_job_time)) {
1130
+        return null;
1131
+    }
1132
+    if (!$_SERVER['REQUEST_TIME']) {
1133
+        $_SERVER['REQUEST_TIME'] = time();
1134
+    }
1135
+
1136
+    return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1138 1137
 }
1139 1138
 
1140 1139
 
@@ -1146,9 +1145,9 @@  discard block
 block discarded – undo
1146 1145
  * @return string
1147 1146
  */
1148 1147
 function quote_amp($u) {
1149
-	return preg_replace(
1150
-		"/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i",
1151
-		"&amp;", $u);
1148
+    return preg_replace(
1149
+        "/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i",
1150
+        "&amp;", $u);
1152 1151
 }
1153 1152
 
1154 1153
 
@@ -1171,27 +1170,27 @@  discard block
 block discarded – undo
1171 1170
  *     Balise HTML `<script>` et son contenu
1172 1171
  **/
1173 1172
 function http_script($script, $src = '', $noscript = '') {
1174
-	static $done = array();
1173
+    static $done = array();
1175 1174
 
1176
-	if ($src && !isset($done[$src])) {
1177
-		$done[$src] = true;
1178
-		$src = find_in_path($src, _JAVASCRIPT);
1179
-		$src = " src='$src'";
1180
-	} else {
1181
-		$src = '';
1182
-	}
1183
-	if ($script) {
1184
-		$script = ("/*<![CDATA[*/\n" .
1185
-			preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1186
-			"/*]]>*/");
1187
-	}
1188
-	if ($noscript) {
1189
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1190
-	}
1175
+    if ($src && !isset($done[$src])) {
1176
+        $done[$src] = true;
1177
+        $src = find_in_path($src, _JAVASCRIPT);
1178
+        $src = " src='$src'";
1179
+    } else {
1180
+        $src = '';
1181
+    }
1182
+    if ($script) {
1183
+        $script = ("/*<![CDATA[*/\n" .
1184
+            preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1185
+            "/*]]>*/");
1186
+    }
1187
+    if ($noscript) {
1188
+        $noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1189
+    }
1191 1190
 
1192
-	return ($src or $script or $noscript)
1193
-		? "<script type='text/javascript'$src>$script</script>$noscript"
1194
-		: '';
1191
+    return ($src or $script or $noscript)
1192
+        ? "<script type='text/javascript'$src>$script</script>$noscript"
1193
+        : '';
1195 1194
 }
1196 1195
 
1197 1196
 
@@ -1226,7 +1225,7 @@  discard block
 block discarded – undo
1226 1225
  *     Texte échappé
1227 1226
  **/
1228 1227
 function texte_script($texte) {
1229
-	return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1228
+    return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1230 1229
 }
1231 1230
 
1232 1231
 
@@ -1263,69 +1262,69 @@  discard block
 block discarded – undo
1263 1262
  *     Liste des chemins, par ordre de priorité.
1264 1263
  **/
1265 1264
 function _chemin($dir_path = null) {
1266
-	static $path_base = null;
1267
-	static $path_full = null;
1268
-	if ($path_base == null) {
1269
-		// Chemin standard depuis l'espace public
1270
-		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
1271
-			_DIR_RACINE . ':' .
1272
-			_DIR_RACINE . 'squelettes-dist/:' .
1273
-			_DIR_RACINE . 'prive/:' .
1274
-			_DIR_RESTREINT;
1275
-		// Ajouter squelettes/
1276
-		if (@is_dir(_DIR_RACINE . 'squelettes')) {
1277
-			$path = _DIR_RACINE . 'squelettes/:' . $path;
1278
-		}
1279
-		foreach (explode(':', $path) as $dir) {
1280
-			if (strlen($dir) and substr($dir, -1) != '/') {
1281
-				$dir .= "/";
1282
-			}
1283
-			$path_base[] = $dir;
1284
-		}
1285
-		$path_full = $path_base;
1286
-		// Et le(s) dossier(s) des squelettes nommes
1287
-		if (strlen($GLOBALS['dossier_squelettes'])) {
1288
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1289
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1290
-			}
1291
-		}
1292
-		$GLOBALS['path_sig'] = md5(serialize($path_full));
1293
-	}
1294
-	if ($dir_path === null) {
1295
-		return $path_full;
1296
-	}
1297
-
1298
-	if (strlen($dir_path)) {
1299
-		$tete = "";
1300
-		if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1301
-			$tete = array_shift($path_base);
1302
-		}
1303
-		$dirs = array_reverse(explode(':', $dir_path));
1304
-		foreach ($dirs as $dir_path) {
1305
-			#if ($dir_path{0}!='/')
1306
-			#	$dir_path = $dir_path;
1307
-			if (substr($dir_path, -1) != '/') {
1308
-				$dir_path .= "/";
1309
-			}
1310
-			if (!in_array($dir_path, $path_base)) {
1311
-				array_unshift($path_base, $dir_path);
1312
-			}
1313
-		}
1314
-		if (strlen($tete)) {
1315
-			array_unshift($path_base, $tete);
1316
-		}
1317
-	}
1318
-	$path_full = $path_base;
1319
-	// Et le(s) dossier(s) des squelettes nommes
1320
-	if (strlen($GLOBALS['dossier_squelettes'])) {
1321
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1322
-			array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1323
-		}
1324
-	}
1325
-
1326
-	$GLOBALS['path_sig'] = md5(serialize($path_full));
1327
-
1328
-	return $path_full;
1265
+    static $path_base = null;
1266
+    static $path_full = null;
1267
+    if ($path_base == null) {
1268
+        // Chemin standard depuis l'espace public
1269
+        $path = defined('_SPIP_PATH') ? _SPIP_PATH :
1270
+            _DIR_RACINE . ':' .
1271
+            _DIR_RACINE . 'squelettes-dist/:' .
1272
+            _DIR_RACINE . 'prive/:' .
1273
+            _DIR_RESTREINT;
1274
+        // Ajouter squelettes/
1275
+        if (@is_dir(_DIR_RACINE . 'squelettes')) {
1276
+            $path = _DIR_RACINE . 'squelettes/:' . $path;
1277
+        }
1278
+        foreach (explode(':', $path) as $dir) {
1279
+            if (strlen($dir) and substr($dir, -1) != '/') {
1280
+                $dir .= "/";
1281
+            }
1282
+            $path_base[] = $dir;
1283
+        }
1284
+        $path_full = $path_base;
1285
+        // Et le(s) dossier(s) des squelettes nommes
1286
+        if (strlen($GLOBALS['dossier_squelettes'])) {
1287
+            foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1288
+                array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1289
+            }
1290
+        }
1291
+        $GLOBALS['path_sig'] = md5(serialize($path_full));
1292
+    }
1293
+    if ($dir_path === null) {
1294
+        return $path_full;
1295
+    }
1296
+
1297
+    if (strlen($dir_path)) {
1298
+        $tete = "";
1299
+        if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1300
+            $tete = array_shift($path_base);
1301
+        }
1302
+        $dirs = array_reverse(explode(':', $dir_path));
1303
+        foreach ($dirs as $dir_path) {
1304
+            #if ($dir_path{0}!='/')
1305
+            #	$dir_path = $dir_path;
1306
+            if (substr($dir_path, -1) != '/') {
1307
+                $dir_path .= "/";
1308
+            }
1309
+            if (!in_array($dir_path, $path_base)) {
1310
+                array_unshift($path_base, $dir_path);
1311
+            }
1312
+        }
1313
+        if (strlen($tete)) {
1314
+            array_unshift($path_base, $tete);
1315
+        }
1316
+    }
1317
+    $path_full = $path_base;
1318
+    // Et le(s) dossier(s) des squelettes nommes
1319
+    if (strlen($GLOBALS['dossier_squelettes'])) {
1320
+        foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1321
+            array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1322
+        }
1323
+    }
1324
+
1325
+    $GLOBALS['path_sig'] = md5(serialize($path_full));
1326
+
1327
+    return $path_full;
1329 1328
 }
1330 1329
 
1331 1330
 /**
@@ -1338,63 +1337,63 @@  discard block
 block discarded – undo
1338 1337
  * @return array Liste de chemins
1339 1338
  **/
1340 1339
 function creer_chemin() {
1341
-	$path_a = _chemin();
1342
-	static $c = '';
1340
+    $path_a = _chemin();
1341
+    static $c = '';
1343 1342
 
1344
-	// on calcule le chemin si le dossier skel a change
1345
-	if ($c != $GLOBALS['dossier_squelettes']) {
1346
-		// assurer le non plantage lors de la montee de version :
1347
-		$c = $GLOBALS['dossier_squelettes'];
1348
-		$path_a = _chemin(''); // forcer un recalcul du chemin
1349
-	}
1343
+    // on calcule le chemin si le dossier skel a change
1344
+    if ($c != $GLOBALS['dossier_squelettes']) {
1345
+        // assurer le non plantage lors de la montee de version :
1346
+        $c = $GLOBALS['dossier_squelettes'];
1347
+        $path_a = _chemin(''); // forcer un recalcul du chemin
1348
+    }
1350 1349
 
1351
-	return $path_a;
1350
+    return $path_a;
1352 1351
 }
1353 1352
 
1354 1353
 
1355 1354
 function lister_themes_prives() {
1356
-	static $themes = null;
1357
-	if (is_null($themes)) {
1358
-		// si pas encore definie
1359
-		if (!defined('_SPIP_THEME_PRIVE')) {
1360
-			define('_SPIP_THEME_PRIVE', 'spip');
1361
-		}
1362
-		$themes = array(_SPIP_THEME_PRIVE);
1363
-		// lors d'une installation neuve, prefs n'est pas definie.
1364
-		if (isset($GLOBALS['visiteur_session']['prefs'])) {
1365
-			$prefs = $GLOBALS['visiteur_session']['prefs'];
1366
-		} else {
1367
-			$prefs = array();
1368
-		}
1369
-		if (is_string($prefs)) {
1370
-			$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1371
-		}
1372
-		if (
1373
-			((isset($prefs['theme']) and $theme = $prefs['theme'])
1374
-				or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1375
-			and $theme != _SPIP_THEME_PRIVE
1376
-		) {
1377
-			array_unshift($themes, $theme);
1378
-		} // placer le theme choisi en tete
1379
-	}
1380
-
1381
-	return $themes;
1355
+    static $themes = null;
1356
+    if (is_null($themes)) {
1357
+        // si pas encore definie
1358
+        if (!defined('_SPIP_THEME_PRIVE')) {
1359
+            define('_SPIP_THEME_PRIVE', 'spip');
1360
+        }
1361
+        $themes = array(_SPIP_THEME_PRIVE);
1362
+        // lors d'une installation neuve, prefs n'est pas definie.
1363
+        if (isset($GLOBALS['visiteur_session']['prefs'])) {
1364
+            $prefs = $GLOBALS['visiteur_session']['prefs'];
1365
+        } else {
1366
+            $prefs = array();
1367
+        }
1368
+        if (is_string($prefs)) {
1369
+            $prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1370
+        }
1371
+        if (
1372
+            ((isset($prefs['theme']) and $theme = $prefs['theme'])
1373
+                or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1374
+            and $theme != _SPIP_THEME_PRIVE
1375
+        ) {
1376
+            array_unshift($themes, $theme);
1377
+        } // placer le theme choisi en tete
1378
+    }
1379
+
1380
+    return $themes;
1382 1381
 }
1383 1382
 
1384 1383
 function find_in_theme($file, $subdir = '', $include = false) {
1385
-	static $themefiles = array();
1386
-	if (isset($themefiles["$subdir$file"])) {
1387
-		return $themefiles["$subdir$file"];
1388
-	}
1389
-	$themes = lister_themes_prives();
1390
-	foreach ($themes as $theme) {
1391
-		if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1392
-			return $themefiles["$subdir$file"] = $f;
1393
-		}
1394
-	}
1395
-	spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1384
+    static $themefiles = array();
1385
+    if (isset($themefiles["$subdir$file"])) {
1386
+        return $themefiles["$subdir$file"];
1387
+    }
1388
+    $themes = lister_themes_prives();
1389
+    foreach ($themes as $theme) {
1390
+        if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1391
+            return $themefiles["$subdir$file"] = $f;
1392
+        }
1393
+    }
1394
+    spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1396 1395
 
1397
-	return $themefiles["$subdir$file"] = "";
1396
+    return $themefiles["$subdir$file"] = "";
1398 1397
 }
1399 1398
 
1400 1399
 
@@ -1418,28 +1417,28 @@  discard block
 block discarded – undo
1418 1417
  *     sinon chaîne vide.
1419 1418
  **/
1420 1419
 function chemin_image($icone) {
1421
-	static $icone_renommer;
1422
-	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
1423
-	if (strpos($icone, "/") !== false and file_exists($icone)) {
1424
-		return $icone;
1425
-	}
1426
-
1427
-	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1428
-	if (preg_match(',[.](png|gif|jpg|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1429
-		return $f;
1430
-	}
1431
-	// sinon passer par le module de renommage
1432
-	if (is_null($icone_renommer)) {
1433
-		$icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1434
-	}
1435
-	if ($icone_renommer) {
1436
-		list($icone, $fonction) = $icone_renommer($icone, "");
1437
-		if (file_exists($icone)) {
1438
-			return $icone;
1439
-		}
1440
-	}
1441
-
1442
-	return find_in_path($icone, _NOM_IMG_PACK);
1420
+    static $icone_renommer;
1421
+    // gerer le cas d'un double appel en evitant de refaire le travail inutilement
1422
+    if (strpos($icone, "/") !== false and file_exists($icone)) {
1423
+        return $icone;
1424
+    }
1425
+
1426
+    // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1427
+    if (preg_match(',[.](png|gif|jpg|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1428
+        return $f;
1429
+    }
1430
+    // sinon passer par le module de renommage
1431
+    if (is_null($icone_renommer)) {
1432
+        $icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1433
+    }
1434
+    if ($icone_renommer) {
1435
+        list($icone, $fonction) = $icone_renommer($icone, "");
1436
+        if (file_exists($icone)) {
1437
+            return $icone;
1438
+        }
1439
+    }
1440
+
1441
+    return find_in_path($icone, _NOM_IMG_PACK);
1443 1442
 }
1444 1443
 
1445 1444
 //
@@ -1477,123 +1476,123 @@  discard block
 block discarded – undo
1477 1476
  *     - false : fichier introuvable
1478 1477
  **/
1479 1478
 function find_in_path($file, $dirname = '', $include = false) {
1480
-	static $dirs = array();
1481
-	static $inc = array(); # cf http://trac.rezo.net/trac/spip/changeset/14743
1482
-	static $c = '';
1483
-
1484
-	// on calcule le chemin si le dossier skel a change
1485
-	if ($c != $GLOBALS['dossier_squelettes']) {
1486
-		// assurer le non plantage lors de la montee de version :
1487
-		$c = $GLOBALS['dossier_squelettes'];
1488
-		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1489
-	}
1490
-
1491
-	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1492
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1493
-			return false;
1494
-		}
1495
-		if ($include and !isset($inc[$dirname][$file])) {
1496
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1497
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1498
-		}
1499
-
1500
-		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1501
-	}
1502
-
1503
-	$a = strrpos($file, '/');
1504
-	if ($a !== false) {
1505
-		$dirname .= substr($file, 0, ++$a);
1506
-		$file = substr($file, $a);
1507
-	}
1508
-
1509
-	foreach (creer_chemin() as $dir) {
1510
-		if (!isset($dirs[$a = $dir . $dirname])) {
1511
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1512
-		}
1513
-		if ($dirs[$a]) {
1514
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
1515
-				if ($include and !isset($inc[$dirname][$file])) {
1516
-					include_once _ROOT_CWD . $a;
1517
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1518
-				}
1519
-				if (!defined('_SAUVER_CHEMIN')) {
1520
-					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1521
-					if (is_null($GLOBALS['path_files'])) {
1522
-						return $a;
1523
-					}
1524
-					define('_SAUVER_CHEMIN', true);
1525
-				}
1526
-
1527
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1528
-			}
1529
-		}
1530
-	}
1531
-
1532
-	if ($include) {
1533
-		spip_log("include_spip $dirname$file non trouve");
1534
-		if ($include === 'required') {
1535
-			echo '<pre>',
1536
-			"<strong>Erreur Fatale</strong><br />";
1537
-			if (function_exists('debug_print_backtrace')) {
1538
-				echo debug_print_backtrace();
1539
-			}
1540
-			echo '</pre>';
1541
-			die("Erreur interne: ne peut inclure $dirname$file");
1542
-		}
1543
-	}
1544
-
1545
-	if (!defined('_SAUVER_CHEMIN')) {
1546
-		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1547
-		if (is_null($GLOBALS['path_files'])) {
1548
-			return false;
1549
-		}
1550
-		define('_SAUVER_CHEMIN', true);
1551
-	}
1552
-
1553
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1479
+    static $dirs = array();
1480
+    static $inc = array(); # cf http://trac.rezo.net/trac/spip/changeset/14743
1481
+    static $c = '';
1482
+
1483
+    // on calcule le chemin si le dossier skel a change
1484
+    if ($c != $GLOBALS['dossier_squelettes']) {
1485
+        // assurer le non plantage lors de la montee de version :
1486
+        $c = $GLOBALS['dossier_squelettes'];
1487
+        creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1488
+    }
1489
+
1490
+    if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1491
+        if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1492
+            return false;
1493
+        }
1494
+        if ($include and !isset($inc[$dirname][$file])) {
1495
+            include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1496
+            $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1497
+        }
1498
+
1499
+        return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1500
+    }
1501
+
1502
+    $a = strrpos($file, '/');
1503
+    if ($a !== false) {
1504
+        $dirname .= substr($file, 0, ++$a);
1505
+        $file = substr($file, $a);
1506
+    }
1507
+
1508
+    foreach (creer_chemin() as $dir) {
1509
+        if (!isset($dirs[$a = $dir . $dirname])) {
1510
+            $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1511
+        }
1512
+        if ($dirs[$a]) {
1513
+            if (file_exists(_ROOT_CWD . ($a .= $file))) {
1514
+                if ($include and !isset($inc[$dirname][$file])) {
1515
+                    include_once _ROOT_CWD . $a;
1516
+                    $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1517
+                }
1518
+                if (!defined('_SAUVER_CHEMIN')) {
1519
+                    // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1520
+                    if (is_null($GLOBALS['path_files'])) {
1521
+                        return $a;
1522
+                    }
1523
+                    define('_SAUVER_CHEMIN', true);
1524
+                }
1525
+
1526
+                return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1527
+            }
1528
+        }
1529
+    }
1530
+
1531
+    if ($include) {
1532
+        spip_log("include_spip $dirname$file non trouve");
1533
+        if ($include === 'required') {
1534
+            echo '<pre>',
1535
+            "<strong>Erreur Fatale</strong><br />";
1536
+            if (function_exists('debug_print_backtrace')) {
1537
+                echo debug_print_backtrace();
1538
+            }
1539
+            echo '</pre>';
1540
+            die("Erreur interne: ne peut inclure $dirname$file");
1541
+        }
1542
+    }
1543
+
1544
+    if (!defined('_SAUVER_CHEMIN')) {
1545
+        // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1546
+        if (is_null($GLOBALS['path_files'])) {
1547
+            return false;
1548
+        }
1549
+        define('_SAUVER_CHEMIN', true);
1550
+    }
1551
+
1552
+    return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1554 1553
 }
1555 1554
 
1556 1555
 function clear_path_cache() {
1557
-	$GLOBALS['path_files'] = array();
1558
-	spip_unlink(_CACHE_CHEMIN);
1556
+    $GLOBALS['path_files'] = array();
1557
+    spip_unlink(_CACHE_CHEMIN);
1559 1558
 }
1560 1559
 
1561 1560
 function load_path_cache() {
1562
-	// charger le path des plugins
1563
-	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1564
-		include_once(_CACHE_PLUGINS_PATH);
1565
-	}
1566
-	$GLOBALS['path_files'] = array();
1567
-	// si le visiteur est admin,
1568
-	// on ne recharge pas le cache pour forcer sa mise a jour
1569
-	if (
1570
-		// la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1571
-		//AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1572
-		// utiliser le cookie est un pis aller qui marche 'en general'
1573
-		// on blinde par un second test au moment de la lecture de la session
1574
-		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1575
-		// et en ignorant ce cache en cas de recalcul explicite
1576
-	!_request('var_mode')
1577
-	) {
1578
-		// on essaye de lire directement sans verrou pour aller plus vite
1579
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1580
-			// mais si semble corrompu on relit avec un verrou
1581
-			if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1582
-				lire_fichier(_CACHE_CHEMIN, $contenu);
1583
-				if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1584
-					$GLOBALS['path_files'] = array();
1585
-				}
1586
-			}
1587
-		}
1588
-	}
1561
+    // charger le path des plugins
1562
+    if (@is_readable(_CACHE_PLUGINS_PATH)) {
1563
+        include_once(_CACHE_PLUGINS_PATH);
1564
+    }
1565
+    $GLOBALS['path_files'] = array();
1566
+    // si le visiteur est admin,
1567
+    // on ne recharge pas le cache pour forcer sa mise a jour
1568
+    if (
1569
+        // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1570
+        //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1571
+        // utiliser le cookie est un pis aller qui marche 'en general'
1572
+        // on blinde par un second test au moment de la lecture de la session
1573
+        // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1574
+        // et en ignorant ce cache en cas de recalcul explicite
1575
+    !_request('var_mode')
1576
+    ) {
1577
+        // on essaye de lire directement sans verrou pour aller plus vite
1578
+        if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1579
+            // mais si semble corrompu on relit avec un verrou
1580
+            if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1581
+                lire_fichier(_CACHE_CHEMIN, $contenu);
1582
+                if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1583
+                    $GLOBALS['path_files'] = array();
1584
+                }
1585
+            }
1586
+        }
1587
+    }
1589 1588
 }
1590 1589
 
1591 1590
 function save_path_cache() {
1592
-	if (defined('_SAUVER_CHEMIN')
1593
-		and _SAUVER_CHEMIN
1594
-	) {
1595
-		ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1596
-	}
1591
+    if (defined('_SAUVER_CHEMIN')
1592
+        and _SAUVER_CHEMIN
1593
+    ) {
1594
+        ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1595
+    }
1597 1596
 }
1598 1597
 
1599 1598
 
@@ -1613,33 +1612,33 @@  discard block
 block discarded – undo
1613 1612
  * @return array
1614 1613
  */
1615 1614
 function find_all_in_path($dir, $pattern, $recurs = false) {
1616
-	$liste_fichiers = array();
1617
-	$maxfiles = 10000;
1618
-
1619
-	// cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1620
-	// on a pas encore inclus flock.php
1621
-	if (!function_exists('preg_files')) {
1622
-		include_once _ROOT_RESTREINT . 'inc/flock.php';
1623
-	}
1624
-
1625
-	// Parcourir le chemin
1626
-	foreach (creer_chemin() as $d) {
1627
-		$f = $d . $dir;
1628
-		if (@is_dir($f)) {
1629
-			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? array() : $recurs);
1630
-			foreach ($liste as $chemin) {
1631
-				$nom = basename($chemin);
1632
-				// ne prendre que les fichiers pas deja trouves
1633
-				// car find_in_path prend le premier qu'il trouve,
1634
-				// les autres sont donc masques
1635
-				if (!isset($liste_fichiers[$nom])) {
1636
-					$liste_fichiers[$nom] = $chemin;
1637
-				}
1638
-			}
1639
-		}
1640
-	}
1641
-
1642
-	return $liste_fichiers;
1615
+    $liste_fichiers = array();
1616
+    $maxfiles = 10000;
1617
+
1618
+    // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1619
+    // on a pas encore inclus flock.php
1620
+    if (!function_exists('preg_files')) {
1621
+        include_once _ROOT_RESTREINT . 'inc/flock.php';
1622
+    }
1623
+
1624
+    // Parcourir le chemin
1625
+    foreach (creer_chemin() as $d) {
1626
+        $f = $d . $dir;
1627
+        if (@is_dir($f)) {
1628
+            $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? array() : $recurs);
1629
+            foreach ($liste as $chemin) {
1630
+                $nom = basename($chemin);
1631
+                // ne prendre que les fichiers pas deja trouves
1632
+                // car find_in_path prend le premier qu'il trouve,
1633
+                // les autres sont donc masques
1634
+                if (!isset($liste_fichiers[$nom])) {
1635
+                    $liste_fichiers[$nom] = $chemin;
1636
+                }
1637
+            }
1638
+        }
1639
+    }
1640
+
1641
+    return $liste_fichiers;
1643 1642
 }
1644 1643
 
1645 1644
 /**
@@ -1648,10 +1647,10 @@  discard block
 block discarded – undo
1648 1647
  * @return bool
1649 1648
  */
1650 1649
 function autoriser_sans_cookie($nom) {
1651
-	static $autsanscookie = array('install', 'base_repair');
1652
-	$nom = preg_replace('/.php[3]?$/', '', basename($nom));
1650
+    static $autsanscookie = array('install', 'base_repair');
1651
+    $nom = preg_replace('/.php[3]?$/', '', basename($nom));
1653 1652
 
1654
-	return in_array($nom, $autsanscookie);
1653
+    return in_array($nom, $autsanscookie);
1655 1654
 }
1656 1655
 
1657 1656
 /**
@@ -1677,99 +1676,99 @@  discard block
 block discarded – undo
1677 1676
  *           (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_url_spip et une fonction generer_url_ecrire_spip)
1678 1677
  */
1679 1678
 function generer_url_entite($id = '', $entite = '', $args = '', $ancre = '', $public = null, $type = null) {
1680
-	if ($public === null) {
1681
-		$public = !test_espace_prive();
1682
-	}
1683
-	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1684
-
1685
-	if (!$public) {
1686
-		if (!$entite) {
1687
-			return '';
1688
-		}
1689
-		if (!function_exists('generer_url_ecrire_objet')) {
1690
-			include_spip('inc/urls');
1691
-		}
1692
-		$res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false);
1693
-	} else {
1694
-		if ($type === null) {
1695
-			$type = (isset($GLOBALS['type_urls']))
1696
-				? $GLOBALS['type_urls'] // pour surcharge via fichier d'options
1697
-				: ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues
1698
-					? ($GLOBALS['meta']['type_urls']) : "page"); // sinon type "page" par défaut
1699
-		}
1700
-
1701
-		$f = charger_fonction($type, 'urls', true);
1702
-		// se rabattre sur les urls page si les urls perso non dispo
1703
-		if (!$f) {
1704
-			$f = charger_fonction('page', 'urls', true);
1705
-		}
1706
-
1707
-		// si $entite='', on veut la fonction de passage URL ==> id
1708
-		// sinon on veut effectuer le passage id ==> URL
1709
-		if (!$entite) {
1710
-			return $f;
1711
-		}
1712
-
1713
-		// mais d'abord il faut tester le cas des urls sur une
1714
-		// base distante
1715
-		if (is_string($public)
1716
-			and $g = charger_fonction('connect', 'urls', true)
1717
-		) {
1718
-			$f = $g;
1719
-		}
1720
-
1721
-		$res = $f(intval($id), $entite, $args, $ancre, $public);
1722
-
1723
-	}
1724
-	if ($res) {
1725
-		return $res;
1726
-	}
1727
-	// Sinon c'est un raccourci ou compat SPIP < 2
1728
-	if (!function_exists($f = 'generer_url_' . $entite)) {
1729
-		if (!function_exists($f .= '_dist')) {
1730
-			$f = '';
1731
-		}
1732
-	}
1733
-	if ($f) {
1734
-		$url = $f($id, $args, $ancre);
1735
-		if (strlen($args)) {
1736
-			$url .= strstr($url, '?')
1737
-				? '&amp;' . $args
1738
-				: '?' . $args;
1739
-		}
1740
-
1741
-		return $url;
1742
-	}
1743
-	// On a ete gentil mais la ....
1744
-	spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public");
1745
-
1746
-	return '';
1679
+    if ($public === null) {
1680
+        $public = !test_espace_prive();
1681
+    }
1682
+    $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1683
+
1684
+    if (!$public) {
1685
+        if (!$entite) {
1686
+            return '';
1687
+        }
1688
+        if (!function_exists('generer_url_ecrire_objet')) {
1689
+            include_spip('inc/urls');
1690
+        }
1691
+        $res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false);
1692
+    } else {
1693
+        if ($type === null) {
1694
+            $type = (isset($GLOBALS['type_urls']))
1695
+                ? $GLOBALS['type_urls'] // pour surcharge via fichier d'options
1696
+                : ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues
1697
+                    ? ($GLOBALS['meta']['type_urls']) : "page"); // sinon type "page" par défaut
1698
+        }
1699
+
1700
+        $f = charger_fonction($type, 'urls', true);
1701
+        // se rabattre sur les urls page si les urls perso non dispo
1702
+        if (!$f) {
1703
+            $f = charger_fonction('page', 'urls', true);
1704
+        }
1705
+
1706
+        // si $entite='', on veut la fonction de passage URL ==> id
1707
+        // sinon on veut effectuer le passage id ==> URL
1708
+        if (!$entite) {
1709
+            return $f;
1710
+        }
1711
+
1712
+        // mais d'abord il faut tester le cas des urls sur une
1713
+        // base distante
1714
+        if (is_string($public)
1715
+            and $g = charger_fonction('connect', 'urls', true)
1716
+        ) {
1717
+            $f = $g;
1718
+        }
1719
+
1720
+        $res = $f(intval($id), $entite, $args, $ancre, $public);
1721
+
1722
+    }
1723
+    if ($res) {
1724
+        return $res;
1725
+    }
1726
+    // Sinon c'est un raccourci ou compat SPIP < 2
1727
+    if (!function_exists($f = 'generer_url_' . $entite)) {
1728
+        if (!function_exists($f .= '_dist')) {
1729
+            $f = '';
1730
+        }
1731
+    }
1732
+    if ($f) {
1733
+        $url = $f($id, $args, $ancre);
1734
+        if (strlen($args)) {
1735
+            $url .= strstr($url, '?')
1736
+                ? '&amp;' . $args
1737
+                : '?' . $args;
1738
+        }
1739
+
1740
+        return $url;
1741
+    }
1742
+    // On a ete gentil mais la ....
1743
+    spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public");
1744
+
1745
+    return '';
1747 1746
 }
1748 1747
 
1749 1748
 function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') {
1750
-	$exec = objet_info($entite, 'url_edit');
1751
-	$url = generer_url_ecrire($exec, $args);
1752
-	if (intval($id)) {
1753
-		$url = parametre_url($url, id_table_objet($entite), $id);
1754
-	} else {
1755
-		$url = parametre_url($url, 'new', 'oui');
1756
-	}
1757
-	if ($ancre) {
1758
-		$url = ancre_url($url, $ancre);
1759
-	}
1749
+    $exec = objet_info($entite, 'url_edit');
1750
+    $url = generer_url_ecrire($exec, $args);
1751
+    if (intval($id)) {
1752
+        $url = parametre_url($url, id_table_objet($entite), $id);
1753
+    } else {
1754
+        $url = parametre_url($url, 'new', 'oui');
1755
+    }
1756
+    if ($ancre) {
1757
+        $url = ancre_url($url, $ancre);
1758
+    }
1760 1759
 
1761
-	return $url;
1760
+    return $url;
1762 1761
 }
1763 1762
 
1764 1763
 // http://code.spip.net/@urls_connect_dist
1765 1764
 function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) {
1766
-	include_spip('base/connect_sql');
1767
-	$id_type = id_table_objet($entite, $public);
1765
+    include_spip('base/connect_sql');
1766
+    $id_type = id_table_objet($entite, $public);
1768 1767
 
1769
-	return _DIR_RACINE . get_spip_script('./')
1770
-	. "?" . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1771
-	. (!$args ? '' : "&$args")
1772
-	. (!$ancre ? '' : "#$ancre");
1768
+    return _DIR_RACINE . get_spip_script('./')
1769
+    . "?" . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1770
+    . (!$args ? '' : "&$args")
1771
+    . (!$ancre ? '' : "#$ancre");
1773 1772
 }
1774 1773
 
1775 1774
 
@@ -1780,32 +1779,32 @@  discard block
 block discarded – undo
1780 1779
  * @return string
1781 1780
  */
1782 1781
 function urlencode_1738($url) {
1783
-	if (preg_match(',[^\x00-\x7E],sS', $url)) {
1784
-		$uri = '';
1785
-		for ($i = 0; $i < strlen($url); $i++) {
1786
-			if (ord($a = $url[$i]) > 127) {
1787
-				$a = rawurlencode($a);
1788
-			}
1789
-			$uri .= $a;
1790
-		}
1791
-		$url = $uri;
1792
-	}
1782
+    if (preg_match(',[^\x00-\x7E],sS', $url)) {
1783
+        $uri = '';
1784
+        for ($i = 0; $i < strlen($url); $i++) {
1785
+            if (ord($a = $url[$i]) > 127) {
1786
+                $a = rawurlencode($a);
1787
+            }
1788
+            $uri .= $a;
1789
+        }
1790
+        $url = $uri;
1791
+    }
1793 1792
 
1794
-	return quote_amp($url);
1793
+    return quote_amp($url);
1795 1794
 }
1796 1795
 
1797 1796
 // http://code.spip.net/@generer_url_entite_absolue
1798 1797
 function generer_url_entite_absolue($id = '', $entite = '', $args = '', $ancre = '', $connect = null) {
1799
-	if (!$connect) {
1800
-		$connect = true;
1801
-	}
1802
-	$h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1803
-	if (!preg_match(',^\w+:,', $h)) {
1804
-		include_spip('inc/filtres_mini');
1805
-		$h = url_absolue($h);
1806
-	}
1798
+    if (!$connect) {
1799
+        $connect = true;
1800
+    }
1801
+    $h = generer_url_entite($id, $entite, $args, $ancre, $connect);
1802
+    if (!preg_match(',^\w+:,', $h)) {
1803
+        include_spip('inc/filtres_mini');
1804
+        $h = url_absolue($h);
1805
+    }
1807 1806
 
1808
-	return $h;
1807
+    return $h;
1809 1808
 }
1810 1809
 
1811 1810
 
@@ -1821,11 +1820,11 @@  discard block
 block discarded – undo
1821 1820
  *     true si la valeur est considérée active ; false sinon.
1822 1821
  **/
1823 1822
 function test_valeur_serveur($truc) {
1824
-	if (!$truc) {
1825
-		return false;
1826
-	}
1823
+    if (!$truc) {
1824
+        return false;
1825
+    }
1827 1826
 
1828
-	return (strtolower($truc) !== 'off');
1827
+    return (strtolower($truc) !== 'off');
1829 1828
 }
1830 1829
 
1831 1830
 //
@@ -1853,80 +1852,80 @@  discard block
 block discarded – undo
1853 1852
  */
1854 1853
 function url_de_base($profondeur = null) {
1855 1854
 
1856
-	static $url = array();
1857
-	if (is_array($profondeur)) {
1858
-		return $url = $profondeur;
1859
-	}
1860
-	if ($profondeur === false) {
1861
-		return $url;
1862
-	}
1863
-
1864
-	if (is_null($profondeur)) {
1865
-		$profondeur = $GLOBALS['profondeur_url'];
1866
-	}
1867
-
1868
-	if (isset($url[$profondeur])) {
1869
-		return $url[$profondeur];
1870
-	}
1871
-
1872
-	$http = 'http';
1873
-
1874
-	if (
1875
-		isset($_SERVER["SCRIPT_URI"])
1876
-		and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https'
1877
-	) {
1878
-		$http = 'https';
1879
-	} elseif (
1880
-		isset($_SERVER['HTTPS'])
1881
-		and test_valeur_serveur($_SERVER['HTTPS'])
1882
-	) {
1883
-		$http = 'https';
1884
-	}
1885
-
1886
-	// note : HTTP_HOST contient le :port si necessaire
1887
-	$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
1888
-	// si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
1889
-	if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
1890
-		$host = $GLOBALS['meta']['adresse_site'];
1891
-		if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
1892
-			$http = $scheme;
1893
-			$host = str_replace("{$scheme}://", '', $host);
1894
-		}
1895
-	}
1896
-	if (isset($_SERVER['SERVER_PORT'])
1897
-		and $port = $_SERVER['SERVER_PORT']
1898
-		and strpos($host, ":") == false
1899
-	) {
1900
-		if (!defined('_PORT_HTTP_STANDARD')) {
1901
-			define('_PORT_HTTP_STANDARD', '80');
1902
-		}
1903
-		if (!defined('_PORT_HTTPS_STANDARD')) {
1904
-			define('_PORT_HTTPS_STANDARD', '443');
1905
-		}
1906
-		if ($http == "http" and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
1907
-			$host .= ":$port";
1908
-		}
1909
-		if ($http == "https" and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
1910
-			$host .= ":$port";
1911
-		}
1912
-	}
1913
-
1914
-	if (!$GLOBALS['REQUEST_URI']) {
1915
-		if (isset($_SERVER['REQUEST_URI'])) {
1916
-			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1917
-		} else {
1918
-			$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
1919
-			if (!empty($_SERVER['QUERY_STRING'])
1920
-				and !strpos($_SERVER['REQUEST_URI'], '?')
1921
-			) {
1922
-				$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
1923
-			}
1924
-		}
1925
-	}
1926
-
1927
-	$url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
1928
-
1929
-	return $url[$profondeur];
1855
+    static $url = array();
1856
+    if (is_array($profondeur)) {
1857
+        return $url = $profondeur;
1858
+    }
1859
+    if ($profondeur === false) {
1860
+        return $url;
1861
+    }
1862
+
1863
+    if (is_null($profondeur)) {
1864
+        $profondeur = $GLOBALS['profondeur_url'];
1865
+    }
1866
+
1867
+    if (isset($url[$profondeur])) {
1868
+        return $url[$profondeur];
1869
+    }
1870
+
1871
+    $http = 'http';
1872
+
1873
+    if (
1874
+        isset($_SERVER["SCRIPT_URI"])
1875
+        and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https'
1876
+    ) {
1877
+        $http = 'https';
1878
+    } elseif (
1879
+        isset($_SERVER['HTTPS'])
1880
+        and test_valeur_serveur($_SERVER['HTTPS'])
1881
+    ) {
1882
+        $http = 'https';
1883
+    }
1884
+
1885
+    // note : HTTP_HOST contient le :port si necessaire
1886
+    $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
1887
+    // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
1888
+    if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
1889
+        $host = $GLOBALS['meta']['adresse_site'];
1890
+        if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
1891
+            $http = $scheme;
1892
+            $host = str_replace("{$scheme}://", '', $host);
1893
+        }
1894
+    }
1895
+    if (isset($_SERVER['SERVER_PORT'])
1896
+        and $port = $_SERVER['SERVER_PORT']
1897
+        and strpos($host, ":") == false
1898
+    ) {
1899
+        if (!defined('_PORT_HTTP_STANDARD')) {
1900
+            define('_PORT_HTTP_STANDARD', '80');
1901
+        }
1902
+        if (!defined('_PORT_HTTPS_STANDARD')) {
1903
+            define('_PORT_HTTPS_STANDARD', '443');
1904
+        }
1905
+        if ($http == "http" and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
1906
+            $host .= ":$port";
1907
+        }
1908
+        if ($http == "https" and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
1909
+            $host .= ":$port";
1910
+        }
1911
+    }
1912
+
1913
+    if (!$GLOBALS['REQUEST_URI']) {
1914
+        if (isset($_SERVER['REQUEST_URI'])) {
1915
+            $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
1916
+        } else {
1917
+            $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
1918
+            if (!empty($_SERVER['QUERY_STRING'])
1919
+                and !strpos($_SERVER['REQUEST_URI'], '?')
1920
+            ) {
1921
+                $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
1922
+            }
1923
+        }
1924
+    }
1925
+
1926
+    $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
1927
+
1928
+    return $url[$profondeur];
1930 1929
 }
1931 1930
 
1932 1931
 /**
@@ -1939,26 +1938,26 @@  discard block
 block discarded – undo
1939 1938
  * @return string
1940 1939
  */
1941 1940
 function url_de_($http, $host, $request, $prof = 0) {
1942
-	$prof = max($prof, 0);
1941
+    $prof = max($prof, 0);
1943 1942
 
1944
-	$myself = ltrim($request, '/');
1945
-	# supprimer la chaine de GET
1946
-	list($myself) = explode('?', $myself);
1947
-	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
1948
-	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
1949
-	if (strpos($myself,'://') !== false) {
1950
-		$myself = explode('://',$myself);
1951
-		array_shift($myself);
1952
-		$myself = implode('://',$myself);
1953
-		$myself = explode('/',$myself);
1954
-		array_shift($myself);
1955
-		$myself = implode('/',$myself);
1956
-	}
1957
-	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
1943
+    $myself = ltrim($request, '/');
1944
+    # supprimer la chaine de GET
1945
+    list($myself) = explode('?', $myself);
1946
+    // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
1947
+    // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
1948
+    if (strpos($myself,'://') !== false) {
1949
+        $myself = explode('://',$myself);
1950
+        array_shift($myself);
1951
+        $myself = implode('://',$myself);
1952
+        $myself = explode('/',$myself);
1953
+        array_shift($myself);
1954
+        $myself = implode('/',$myself);
1955
+    }
1956
+    $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
1958 1957
 
1959
-	$url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
1958
+    $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
1960 1959
 
1961
-	return $url;
1960
+    return $url;
1962 1961
 }
1963 1962
 
1964 1963
 
@@ -1993,26 +1992,26 @@  discard block
 block discarded – undo
1993 1992
  * @return string URL
1994 1993
  **/
1995 1994
 function generer_url_ecrire($script = '', $args = "", $no_entities = false, $rel = false) {
1996
-	if (!$rel) {
1997
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
1998
-	} else {
1999
-		if (!is_string($rel)) {
2000
-			$rel = _DIR_RESTREINT ? _DIR_RESTREINT :
2001
-				('./' . _SPIP_ECRIRE_SCRIPT);
2002
-		}
2003
-	}
2004
-
2005
-	list($script, $ancre) = array_pad(explode('#', $script), 2, null);
2006
-	if ($script and ($script <> 'accueil' or $rel)) {
2007
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
2008
-	} elseif ($args) {
2009
-		$args = "?$args";
2010
-	}
2011
-	if ($ancre) {
2012
-		$args .= "#$ancre";
2013
-	}
2014
-
2015
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
1995
+    if (!$rel) {
1996
+        $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
1997
+    } else {
1998
+        if (!is_string($rel)) {
1999
+            $rel = _DIR_RESTREINT ? _DIR_RESTREINT :
2000
+                ('./' . _SPIP_ECRIRE_SCRIPT);
2001
+        }
2002
+    }
2003
+
2004
+    list($script, $ancre) = array_pad(explode('#', $script), 2, null);
2005
+    if ($script and ($script <> 'accueil' or $rel)) {
2006
+        $args = "?exec=$script" . (!$args ? '' : "&$args");
2007
+    } elseif ($args) {
2008
+        $args = "?$args";
2009
+    }
2010
+    if ($ancre) {
2011
+        $args .= "#$ancre";
2012
+    }
2013
+
2014
+    return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2016 2015
 }
2017 2016
 
2018 2017
 //
@@ -2034,12 +2033,12 @@  discard block
 block discarded – undo
2034 2033
  *     Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut
2035 2034
  **/
2036 2035
 function get_spip_script($default = '') {
2037
-	# cas define('_SPIP_SCRIPT', '');
2038
-	if (_SPIP_SCRIPT) {
2039
-		return _SPIP_SCRIPT;
2040
-	} else {
2041
-		return $default;
2042
-	}
2036
+    # cas define('_SPIP_SCRIPT', '');
2037
+    if (_SPIP_SCRIPT) {
2038
+        return _SPIP_SCRIPT;
2039
+    } else {
2040
+        return $default;
2041
+    }
2043 2042
 }
2044 2043
 
2045 2044
 /**
@@ -2068,39 +2067,39 @@  discard block
 block discarded – undo
2068 2067
  * @return string URL
2069 2068
  **/
2070 2069
 function generer_url_public($script = '', $args = "", $no_entities = false, $rel = true, $action = '') {
2071
-	// si le script est une action (spip_pass, spip_inscription),
2072
-	// standardiser vers la nouvelle API
2073
-
2074
-	if (!$action) {
2075
-		$action = get_spip_script();
2076
-	}
2077
-	if ($script) {
2078
-		$action = parametre_url($action, _SPIP_PAGE, $script, '&');
2079
-	}
2080
-
2081
-	if ($args) {
2082
-		if (is_array($args)) {
2083
-			$r = '';
2084
-			foreach ($args as $k => $v) {
2085
-				$r .= '&' . $k . '=' . $v;
2086
-			}
2087
-			$args = substr($r, 1);
2088
-		}
2089
-		$action .=
2090
-			(strpos($action, '?') !== false ? '&' : '?') . $args;
2091
-	}
2092
-	if (!$no_entities) {
2093
-		$action = quote_amp($action);
2094
-	}
2095
-
2096
-	// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2097
-	return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(",^/[.]/,", "/", "/$action"));
2070
+    // si le script est une action (spip_pass, spip_inscription),
2071
+    // standardiser vers la nouvelle API
2072
+
2073
+    if (!$action) {
2074
+        $action = get_spip_script();
2075
+    }
2076
+    if ($script) {
2077
+        $action = parametre_url($action, _SPIP_PAGE, $script, '&');
2078
+    }
2079
+
2080
+    if ($args) {
2081
+        if (is_array($args)) {
2082
+            $r = '';
2083
+            foreach ($args as $k => $v) {
2084
+                $r .= '&' . $k . '=' . $v;
2085
+            }
2086
+            $args = substr($r, 1);
2087
+        }
2088
+        $action .=
2089
+            (strpos($action, '?') !== false ? '&' : '?') . $args;
2090
+    }
2091
+    if (!$no_entities) {
2092
+        $action = quote_amp($action);
2093
+    }
2094
+
2095
+    // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2096
+    return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(",^/[.]/,", "/", "/$action"));
2098 2097
 }
2099 2098
 
2100 2099
 // http://code.spip.net/@generer_url_prive
2101 2100
 function generer_url_prive($script, $args = "", $no_entities = false) {
2102 2101
 
2103
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2102
+    return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2104 2103
 }
2105 2104
 
2106 2105
 // Pour les formulaires en methode POST,
@@ -2125,19 +2124,19 @@  discard block
 block discarded – undo
2125 2124
  **/
2126 2125
 function generer_form_ecrire($script, $corps, $atts = '', $submit = '') {
2127 2126
 
2128
-	$script1 = explode('&', $script);
2129
-	$script1 = reset($script1);
2127
+    $script1 = explode('&', $script);
2128
+    $script1 = reset($script1);
2130 2129
 
2131
-	return "<form action='"
2132
-	. ($script ? generer_url_ecrire($script) : '')
2133
-	. "' "
2134
-	. ($atts ? $atts : " method='post'")
2135
-	. "><div>\n"
2136
-	. "<input type='hidden' name='exec' value='$script1' />"
2137
-	. $corps
2138
-	. (!$submit ? '' :
2139
-		("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo' type='submit' value=\"" . entites_html($submit) . "\" /></div>"))
2140
-	. "</div></form>\n";
2130
+    return "<form action='"
2131
+    . ($script ? generer_url_ecrire($script) : '')
2132
+    . "' "
2133
+    . ($atts ? $atts : " method='post'")
2134
+    . "><div>\n"
2135
+    . "<input type='hidden' name='exec' value='$script1' />"
2136
+    . $corps
2137
+    . (!$submit ? '' :
2138
+        ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo' type='submit' value=\"" . entites_html($submit) . "\" /></div>"))
2139
+    . "</div></form>\n";
2141 2140
 }
2142 2141
 
2143 2142
 /**
@@ -2154,22 +2153,22 @@  discard block
 block discarded – undo
2154 2153
  * @return string
2155 2154
  */
2156 2155
 function generer_form_action($script, $corps, $atts = '', $public = false) {
2157
-	// si l'on est dans l'espace prive, on garde dans l'url
2158
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2159
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2160
-	$h = (_DIR_RACINE and !$public)
2161
-		? generer_url_ecrire(_request('exec'))
2162
-		: generer_url_public();
2156
+    // si l'on est dans l'espace prive, on garde dans l'url
2157
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2158
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2159
+    $h = (_DIR_RACINE and !$public)
2160
+        ? generer_url_ecrire(_request('exec'))
2161
+        : generer_url_public();
2163 2162
 
2164
-	return "\n<form action='" .
2165
-	$h .
2166
-	"'" .
2167
-	$atts .
2168
-	">\n" .
2169
-	"<div>" .
2170
-	"\n<input type='hidden' name='action' value='$script' />" .
2171
-	$corps .
2172
-	"</div></form>";
2163
+    return "\n<form action='" .
2164
+    $h .
2165
+    "'" .
2166
+    $atts .
2167
+    ">\n" .
2168
+    "<div>" .
2169
+    "\n<input type='hidden' name='action' value='$script' />" .
2170
+    $corps .
2171
+    "</div></form>";
2173 2172
 }
2174 2173
 
2175 2174
 /**
@@ -2188,22 +2187,22 @@  discard block
 block discarded – undo
2188 2187
  *     URL
2189 2188
  */
2190 2189
 function generer_url_action($script, $args = "", $no_entities = false, $public = false) {
2191
-	// si l'on est dans l'espace prive, on garde dans l'url
2192
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2193
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2194
-	$url = (_DIR_RACINE and !$public)
2195
-		? generer_url_ecrire(_request('exec'))
2196
-		: generer_url_public('', '', false, false);
2197
-	$url = parametre_url($url, 'action', $script);
2198
-	if ($args) {
2199
-		$url .= quote_amp('&' . $args);
2200
-	}
2190
+    // si l'on est dans l'espace prive, on garde dans l'url
2191
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2192
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2193
+    $url = (_DIR_RACINE and !$public)
2194
+        ? generer_url_ecrire(_request('exec'))
2195
+        : generer_url_public('', '', false, false);
2196
+    $url = parametre_url($url, 'action', $script);
2197
+    if ($args) {
2198
+        $url .= quote_amp('&' . $args);
2199
+    }
2201 2200
 
2202
-	if ($no_entities) {
2203
-		$url = str_replace('&amp;', '&', $url);
2204
-	}
2201
+    if ($no_entities) {
2202
+        $url = str_replace('&amp;', '&', $url);
2203
+    }
2205 2204
 
2206
-	return $url;
2205
+    return $url;
2207 2206
 }
2208 2207
 
2209 2208
 
@@ -2216,8 +2215,8 @@  discard block
 block discarded – undo
2216 2215
  * @param string $ta Répertoire temporaire accessible
2217 2216
  */
2218 2217
 function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) {
2219
-	spip_initialisation_core($pi, $pa, $ti, $ta);
2220
-	spip_initialisation_suite();
2218
+    spip_initialisation_core($pi, $pa, $ti, $ta);
2219
+    spip_initialisation_suite();
2221 2220
 }
2222 2221
 
2223 2222
 /**
@@ -2237,315 +2236,315 @@  discard block
 block discarded – undo
2237 2236
  * @param string $ta Répertoire temporaire accessible
2238 2237
  */
2239 2238
 function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) {
2240
-	static $too_late = 0;
2241
-	if ($too_late++) {
2242
-		return;
2243
-	}
2244
-
2245
-	// Declaration des repertoires
2246
-
2247
-	// le nom du repertoire plugins/ activables/desactivables
2248
-	if (!defined('_DIR_PLUGINS')) {
2249
-		define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
2250
-	}
2251
-
2252
-	// le nom du repertoire des extensions/ permanentes du core, toujours actives
2253
-	if (!defined('_DIR_PLUGINS_DIST')) {
2254
-		define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
2255
-	}
2256
-
2257
-	// le nom du repertoire des librairies
2258
-	if (!defined('_DIR_LIB')) {
2259
-		define('_DIR_LIB', _DIR_RACINE . "lib/");
2260
-	}
2261
-
2262
-	if (!defined('_DIR_IMG')) {
2263
-		define('_DIR_IMG', $pa);
2264
-	}
2265
-	if (!defined('_DIR_LOGOS')) {
2266
-		define('_DIR_LOGOS', $pa);
2267
-	}
2268
-	if (!defined('_DIR_IMG_ICONES')) {
2269
-		define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
2270
-	}
2271
-
2272
-	if (!defined('_DIR_DUMP')) {
2273
-		define('_DIR_DUMP', $ti . "dump/");
2274
-	}
2275
-	if (!defined('_DIR_SESSIONS')) {
2276
-		define('_DIR_SESSIONS', $ti . "sessions/");
2277
-	}
2278
-	if (!defined('_DIR_TRANSFERT')) {
2279
-		define('_DIR_TRANSFERT', $ti . "upload/");
2280
-	}
2281
-	if (!defined('_DIR_CACHE')) {
2282
-		define('_DIR_CACHE', $ti . "cache/");
2283
-	}
2284
-	if (!defined('_DIR_CACHE_XML')) {
2285
-		define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
2286
-	}
2287
-	if (!defined('_DIR_SKELS')) {
2288
-		define('_DIR_SKELS', _DIR_CACHE . "skel/");
2289
-	}
2290
-	if (!defined('_DIR_AIDE')) {
2291
-		define('_DIR_AIDE', _DIR_CACHE . "aide/");
2292
-	}
2293
-	if (!defined('_DIR_TMP')) {
2294
-		define('_DIR_TMP', $ti);
2295
-	}
2296
-
2297
-	if (!defined('_DIR_VAR')) {
2298
-		define('_DIR_VAR', $ta);
2299
-	}
2300
-
2301
-	if (!defined('_DIR_ETC')) {
2302
-		define('_DIR_ETC', $pi);
2303
-	}
2304
-	if (!defined('_DIR_CONNECT')) {
2305
-		define('_DIR_CONNECT', $pi);
2306
-	}
2307
-	if (!defined('_DIR_CHMOD')) {
2308
-		define('_DIR_CHMOD', $pi);
2309
-	}
2310
-
2311
-	if (!isset($GLOBALS['test_dirs']))
2312
-		// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2313
-		// il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2314
-	{
2315
-		$GLOBALS['test_dirs'] = array($pa, $ti, $ta);
2316
-	}
2317
-
2318
-	// Declaration des fichiers
2319
-
2320
-	if (!defined('_CACHE_PLUGINS_PATH')) {
2321
-		define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
2322
-	}
2323
-	if (!defined('_CACHE_PLUGINS_OPT')) {
2324
-		define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
2325
-	}
2326
-	if (!defined('_CACHE_PLUGINS_FCT')) {
2327
-		define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
2328
-	}
2329
-	if (!defined('_CACHE_PIPELINES')) {
2330
-		define('_CACHE_PIPELINES', _DIR_CACHE . "charger_pipelines.php");
2331
-	}
2332
-	if (!defined('_CACHE_CHEMIN')) {
2333
-		define('_CACHE_CHEMIN', _DIR_CACHE . "chemin.txt");
2334
-	}
2335
-
2336
-	# attention .php obligatoire pour ecrire_fichier_securise
2337
-	if (!defined('_FILE_META')) {
2338
-		define('_FILE_META', $ti . 'meta_cache.php');
2339
-	}
2340
-	if (!defined('_DIR_LOG')) {
2341
-		define('_DIR_LOG', _DIR_TMP . 'log/');
2342
-	}
2343
-	if (!defined('_FILE_LOG')) {
2344
-		define('_FILE_LOG', 'spip');
2345
-	}
2346
-	if (!defined('_FILE_LOG_SUFFIX')) {
2347
-		define('_FILE_LOG_SUFFIX', '.log');
2348
-	}
2349
-
2350
-	// Le fichier de connexion a la base de donnees
2351
-	// tient compte des anciennes versions (inc_connect...)
2352
-	if (!defined('_FILE_CONNECT_INS')) {
2353
-		define('_FILE_CONNECT_INS', 'connect');
2354
-	}
2355
-	if (!defined('_FILE_CONNECT')) {
2356
-		define('_FILE_CONNECT',
2357
-		(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2358
-			: (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2359
-				: false)));
2360
-	}
2361
-
2362
-	// Le fichier de reglages des droits
2363
-	if (!defined('_FILE_CHMOD_INS')) {
2364
-		define('_FILE_CHMOD_INS', 'chmod');
2365
-	}
2366
-	if (!defined('_FILE_CHMOD')) {
2367
-		define('_FILE_CHMOD',
2368
-		(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2369
-			: false));
2370
-	}
2371
-
2372
-	if (!defined('_FILE_LDAP')) {
2373
-		define('_FILE_LDAP', 'ldap.php');
2374
-	}
2375
-
2376
-	if (!defined('_FILE_TMP_SUFFIX')) {
2377
-		define('_FILE_TMP_SUFFIX', '.tmp.php');
2378
-	}
2379
-	if (!defined('_FILE_CONNECT_TMP')) {
2380
-		define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2381
-	}
2382
-	if (!defined('_FILE_CHMOD_TMP')) {
2383
-		define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2384
-	}
2385
-
2386
-	// Definition des droits d'acces en ecriture
2387
-	if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2388
-		include_once _FILE_CHMOD;
2389
-	}
2390
-
2391
-	// Se mefier des fichiers mal remplis!
2392
-	if (!defined('_SPIP_CHMOD')) {
2393
-		define('_SPIP_CHMOD', 0777);
2394
-	}
2395
-
2396
-	if (!defined('_DEFAULT_CHARSET')) {
2397
-		/** Le charset par défaut lors de l'installation */
2398
-		define('_DEFAULT_CHARSET', 'utf-8');
2399
-	}
2400
-	if (!defined('_ROOT_PLUGINS')) {
2401
-		define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
2402
-	}
2403
-	if (!defined('_ROOT_PLUGINS_DIST')) {
2404
-		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
2405
-	}
2406
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2407
-		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2408
-	}
2409
-
2410
-	// La taille des Log
2411
-	if (!defined('_MAX_LOG')) {
2412
-		define('_MAX_LOG', 100);
2413
-	}
2414
-
2415
-	// Sommes-nous dans l'empire du Mal ?
2416
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
2417
-	if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2418
-		if (!defined('_OS_SERVEUR')) {
2419
-			define('_OS_SERVEUR', 'windows');
2420
-		}
2421
-		if (!defined('_SPIP_LOCK_MODE')) {
2422
-			define('_SPIP_LOCK_MODE', 1);
2423
-		} // utiliser le flock php
2424
-	} else {
2425
-		if (!defined('_OS_SERVEUR')) {
2426
-			define('_OS_SERVEUR', '');
2427
-		}
2428
-		if (!defined('_SPIP_LOCK_MODE')) {
2429
-			define('_SPIP_LOCK_MODE', 1);
2430
-		} // utiliser le flock php
2431
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2432
-	}
2433
-
2434
-	// Langue par defaut
2435
-	if (!defined('_LANGUE_PAR_DEFAUT')) {
2436
-		define('_LANGUE_PAR_DEFAUT', 'fr');
2437
-	}
2438
-
2439
-	//
2440
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
2441
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
2442
-	// pour le rendre surchargeable, on va provoquer un reecriture
2443
-	// systematique du noyau ou une baisse de perfs => a etudier)
2444
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
2445
-
2446
-	// charger tout de suite le path et son cache
2447
-	load_path_cache();
2448
-
2449
-	// *********** traiter les variables ************
2450
-
2451
-	//
2452
-	// Securite
2453
-	//
2454
-
2455
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2456
-	if (isset($_REQUEST['GLOBALS'])) {
2457
-		die();
2458
-	}
2459
-	// nettoyer les magic quotes \' et les caracteres nuls %00
2460
-	spip_desinfecte($_GET);
2461
-	spip_desinfecte($_POST);
2462
-	spip_desinfecte($_COOKIE);
2463
-	spip_desinfecte($_REQUEST);
2464
-
2465
-	// appliquer le cookie_prefix
2466
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
2467
-		include_spip('inc/cookie');
2468
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2469
-	}
2470
-
2471
-	//
2472
-	// Capacites php (en fonction de la version)
2473
-	//
2474
-	$GLOBALS['flag_ob'] = (function_exists("ob_start")
2475
-		&& function_exists("ini_get")
2476
-		&& !strstr(@ini_get('disable_functions'), 'ob_'));
2477
-	$GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name");
2478
-	$GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != "");
2479
-	$GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2480
-		(get_cfg_var('upload_max_filesize') > 0));
2481
-
2482
-
2483
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2484
-	if (isset($_SERVER['REQUEST_URI'])) {
2485
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2486
-	} else {
2487
-		$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2488
-		if (!empty($_SERVER['QUERY_STRING'])
2489
-			and !strpos($_SERVER['REQUEST_URI'], '?')
2490
-		) {
2491
-			$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2492
-		}
2493
-	}
2494
-
2495
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2496
-	if (!defined('_RENOUVELLE_ALEA')) {
2497
-		define('_RENOUVELLE_ALEA', 12 * 3600);
2498
-	}
2499
-	if (!defined('_DUREE_COOKIE_ADMIN')) {
2500
-		define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2501
-	}
2502
-
2503
-	// charger les meta si possible et renouveller l'alea au besoin
2504
-	// charge aussi effacer_meta et ecrire_meta
2505
-	$inc_meta = charger_fonction('meta', 'inc');
2506
-	$inc_meta();
2507
-
2508
-	// nombre de repertoires depuis la racine
2509
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2510
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2511
-	// le calcul est faux)
2512
-	if (!_DIR_RESTREINT) {
2513
-		$GLOBALS['profondeur_url'] = 1;
2514
-	} else {
2515
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2516
-		$uri_ref = $_SERVER["SCRIPT_NAME"];
2517
-		if (!$uri_ref
2518
-			// si on est appele avec un autre ti, on est sans doute en mutu
2519
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2520
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2521
-			// s'en remettre a l'adresse du site. alea jacta est.
2522
-			or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2523
-		) {
2524
-
2525
-			if (isset($GLOBALS['meta']['adresse_site'])) {
2526
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2527
-				$uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/';
2528
-			} else {
2529
-				$uri_ref = "";
2530
-			}
2531
-		}
2532
-		if (!$uri or !$uri_ref) {
2533
-			$GLOBALS['profondeur_url'] = 0;
2534
-		} else {
2535
-			$GLOBALS['profondeur_url'] = max(0,
2536
-				substr_count($uri[0], '/')
2537
-				- substr_count($uri_ref, '/'));
2538
-		}
2539
-	}
2540
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2541
-	if (_FILE_CONNECT) {
2542
-		if (verifier_visiteur() == '0minirezo'
2543
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2544
-			and !isset($_COOKIE['spip_admin'])
2545
-		) {
2546
-			clear_path_cache();
2547
-		}
2548
-	}
2239
+    static $too_late = 0;
2240
+    if ($too_late++) {
2241
+        return;
2242
+    }
2243
+
2244
+    // Declaration des repertoires
2245
+
2246
+    // le nom du repertoire plugins/ activables/desactivables
2247
+    if (!defined('_DIR_PLUGINS')) {
2248
+        define('_DIR_PLUGINS', _DIR_RACINE . "plugins/");
2249
+    }
2250
+
2251
+    // le nom du repertoire des extensions/ permanentes du core, toujours actives
2252
+    if (!defined('_DIR_PLUGINS_DIST')) {
2253
+        define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/");
2254
+    }
2255
+
2256
+    // le nom du repertoire des librairies
2257
+    if (!defined('_DIR_LIB')) {
2258
+        define('_DIR_LIB', _DIR_RACINE . "lib/");
2259
+    }
2260
+
2261
+    if (!defined('_DIR_IMG')) {
2262
+        define('_DIR_IMG', $pa);
2263
+    }
2264
+    if (!defined('_DIR_LOGOS')) {
2265
+        define('_DIR_LOGOS', $pa);
2266
+    }
2267
+    if (!defined('_DIR_IMG_ICONES')) {
2268
+        define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/");
2269
+    }
2270
+
2271
+    if (!defined('_DIR_DUMP')) {
2272
+        define('_DIR_DUMP', $ti . "dump/");
2273
+    }
2274
+    if (!defined('_DIR_SESSIONS')) {
2275
+        define('_DIR_SESSIONS', $ti . "sessions/");
2276
+    }
2277
+    if (!defined('_DIR_TRANSFERT')) {
2278
+        define('_DIR_TRANSFERT', $ti . "upload/");
2279
+    }
2280
+    if (!defined('_DIR_CACHE')) {
2281
+        define('_DIR_CACHE', $ti . "cache/");
2282
+    }
2283
+    if (!defined('_DIR_CACHE_XML')) {
2284
+        define('_DIR_CACHE_XML', _DIR_CACHE . "xml/");
2285
+    }
2286
+    if (!defined('_DIR_SKELS')) {
2287
+        define('_DIR_SKELS', _DIR_CACHE . "skel/");
2288
+    }
2289
+    if (!defined('_DIR_AIDE')) {
2290
+        define('_DIR_AIDE', _DIR_CACHE . "aide/");
2291
+    }
2292
+    if (!defined('_DIR_TMP')) {
2293
+        define('_DIR_TMP', $ti);
2294
+    }
2295
+
2296
+    if (!defined('_DIR_VAR')) {
2297
+        define('_DIR_VAR', $ta);
2298
+    }
2299
+
2300
+    if (!defined('_DIR_ETC')) {
2301
+        define('_DIR_ETC', $pi);
2302
+    }
2303
+    if (!defined('_DIR_CONNECT')) {
2304
+        define('_DIR_CONNECT', $pi);
2305
+    }
2306
+    if (!defined('_DIR_CHMOD')) {
2307
+        define('_DIR_CHMOD', $pi);
2308
+    }
2309
+
2310
+    if (!isset($GLOBALS['test_dirs']))
2311
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
2312
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2313
+    {
2314
+        $GLOBALS['test_dirs'] = array($pa, $ti, $ta);
2315
+    }
2316
+
2317
+    // Declaration des fichiers
2318
+
2319
+    if (!defined('_CACHE_PLUGINS_PATH')) {
2320
+        define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php");
2321
+    }
2322
+    if (!defined('_CACHE_PLUGINS_OPT')) {
2323
+        define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php");
2324
+    }
2325
+    if (!defined('_CACHE_PLUGINS_FCT')) {
2326
+        define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php");
2327
+    }
2328
+    if (!defined('_CACHE_PIPELINES')) {
2329
+        define('_CACHE_PIPELINES', _DIR_CACHE . "charger_pipelines.php");
2330
+    }
2331
+    if (!defined('_CACHE_CHEMIN')) {
2332
+        define('_CACHE_CHEMIN', _DIR_CACHE . "chemin.txt");
2333
+    }
2334
+
2335
+    # attention .php obligatoire pour ecrire_fichier_securise
2336
+    if (!defined('_FILE_META')) {
2337
+        define('_FILE_META', $ti . 'meta_cache.php');
2338
+    }
2339
+    if (!defined('_DIR_LOG')) {
2340
+        define('_DIR_LOG', _DIR_TMP . 'log/');
2341
+    }
2342
+    if (!defined('_FILE_LOG')) {
2343
+        define('_FILE_LOG', 'spip');
2344
+    }
2345
+    if (!defined('_FILE_LOG_SUFFIX')) {
2346
+        define('_FILE_LOG_SUFFIX', '.log');
2347
+    }
2348
+
2349
+    // Le fichier de connexion a la base de donnees
2350
+    // tient compte des anciennes versions (inc_connect...)
2351
+    if (!defined('_FILE_CONNECT_INS')) {
2352
+        define('_FILE_CONNECT_INS', 'connect');
2353
+    }
2354
+    if (!defined('_FILE_CONNECT')) {
2355
+        define('_FILE_CONNECT',
2356
+        (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2357
+            : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2358
+                : false)));
2359
+    }
2360
+
2361
+    // Le fichier de reglages des droits
2362
+    if (!defined('_FILE_CHMOD_INS')) {
2363
+        define('_FILE_CHMOD_INS', 'chmod');
2364
+    }
2365
+    if (!defined('_FILE_CHMOD')) {
2366
+        define('_FILE_CHMOD',
2367
+        (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2368
+            : false));
2369
+    }
2370
+
2371
+    if (!defined('_FILE_LDAP')) {
2372
+        define('_FILE_LDAP', 'ldap.php');
2373
+    }
2374
+
2375
+    if (!defined('_FILE_TMP_SUFFIX')) {
2376
+        define('_FILE_TMP_SUFFIX', '.tmp.php');
2377
+    }
2378
+    if (!defined('_FILE_CONNECT_TMP')) {
2379
+        define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2380
+    }
2381
+    if (!defined('_FILE_CHMOD_TMP')) {
2382
+        define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2383
+    }
2384
+
2385
+    // Definition des droits d'acces en ecriture
2386
+    if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2387
+        include_once _FILE_CHMOD;
2388
+    }
2389
+
2390
+    // Se mefier des fichiers mal remplis!
2391
+    if (!defined('_SPIP_CHMOD')) {
2392
+        define('_SPIP_CHMOD', 0777);
2393
+    }
2394
+
2395
+    if (!defined('_DEFAULT_CHARSET')) {
2396
+        /** Le charset par défaut lors de l'installation */
2397
+        define('_DEFAULT_CHARSET', 'utf-8');
2398
+    }
2399
+    if (!defined('_ROOT_PLUGINS')) {
2400
+        define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/");
2401
+    }
2402
+    if (!defined('_ROOT_PLUGINS_DIST')) {
2403
+        define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/");
2404
+    }
2405
+    if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2406
+        define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2407
+    }
2408
+
2409
+    // La taille des Log
2410
+    if (!defined('_MAX_LOG')) {
2411
+        define('_MAX_LOG', 100);
2412
+    }
2413
+
2414
+    // Sommes-nous dans l'empire du Mal ?
2415
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
2416
+    if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2417
+        if (!defined('_OS_SERVEUR')) {
2418
+            define('_OS_SERVEUR', 'windows');
2419
+        }
2420
+        if (!defined('_SPIP_LOCK_MODE')) {
2421
+            define('_SPIP_LOCK_MODE', 1);
2422
+        } // utiliser le flock php
2423
+    } else {
2424
+        if (!defined('_OS_SERVEUR')) {
2425
+            define('_OS_SERVEUR', '');
2426
+        }
2427
+        if (!defined('_SPIP_LOCK_MODE')) {
2428
+            define('_SPIP_LOCK_MODE', 1);
2429
+        } // utiliser le flock php
2430
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2431
+    }
2432
+
2433
+    // Langue par defaut
2434
+    if (!defined('_LANGUE_PAR_DEFAUT')) {
2435
+        define('_LANGUE_PAR_DEFAUT', 'fr');
2436
+    }
2437
+
2438
+    //
2439
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
2440
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
2441
+    // pour le rendre surchargeable, on va provoquer un reecriture
2442
+    // systematique du noyau ou une baisse de perfs => a etudier)
2443
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
2444
+
2445
+    // charger tout de suite le path et son cache
2446
+    load_path_cache();
2447
+
2448
+    // *********** traiter les variables ************
2449
+
2450
+    //
2451
+    // Securite
2452
+    //
2453
+
2454
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2455
+    if (isset($_REQUEST['GLOBALS'])) {
2456
+        die();
2457
+    }
2458
+    // nettoyer les magic quotes \' et les caracteres nuls %00
2459
+    spip_desinfecte($_GET);
2460
+    spip_desinfecte($_POST);
2461
+    spip_desinfecte($_COOKIE);
2462
+    spip_desinfecte($_REQUEST);
2463
+
2464
+    // appliquer le cookie_prefix
2465
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
2466
+        include_spip('inc/cookie');
2467
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2468
+    }
2469
+
2470
+    //
2471
+    // Capacites php (en fonction de la version)
2472
+    //
2473
+    $GLOBALS['flag_ob'] = (function_exists("ob_start")
2474
+        && function_exists("ini_get")
2475
+        && !strstr(@ini_get('disable_functions'), 'ob_'));
2476
+    $GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name");
2477
+    $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != "");
2478
+    $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] ||
2479
+        (get_cfg_var('upload_max_filesize') > 0));
2480
+
2481
+
2482
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2483
+    if (isset($_SERVER['REQUEST_URI'])) {
2484
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2485
+    } else {
2486
+        $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2487
+        if (!empty($_SERVER['QUERY_STRING'])
2488
+            and !strpos($_SERVER['REQUEST_URI'], '?')
2489
+        ) {
2490
+            $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2491
+        }
2492
+    }
2493
+
2494
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2495
+    if (!defined('_RENOUVELLE_ALEA')) {
2496
+        define('_RENOUVELLE_ALEA', 12 * 3600);
2497
+    }
2498
+    if (!defined('_DUREE_COOKIE_ADMIN')) {
2499
+        define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2500
+    }
2501
+
2502
+    // charger les meta si possible et renouveller l'alea au besoin
2503
+    // charge aussi effacer_meta et ecrire_meta
2504
+    $inc_meta = charger_fonction('meta', 'inc');
2505
+    $inc_meta();
2506
+
2507
+    // nombre de repertoires depuis la racine
2508
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2509
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2510
+    // le calcul est faux)
2511
+    if (!_DIR_RESTREINT) {
2512
+        $GLOBALS['profondeur_url'] = 1;
2513
+    } else {
2514
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2515
+        $uri_ref = $_SERVER["SCRIPT_NAME"];
2516
+        if (!$uri_ref
2517
+            // si on est appele avec un autre ti, on est sans doute en mutu
2518
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2519
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2520
+            // s'en remettre a l'adresse du site. alea jacta est.
2521
+            or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2522
+        ) {
2523
+
2524
+            if (isset($GLOBALS['meta']['adresse_site'])) {
2525
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2526
+                $uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/';
2527
+            } else {
2528
+                $uri_ref = "";
2529
+            }
2530
+        }
2531
+        if (!$uri or !$uri_ref) {
2532
+            $GLOBALS['profondeur_url'] = 0;
2533
+        } else {
2534
+            $GLOBALS['profondeur_url'] = max(0,
2535
+                substr_count($uri[0], '/')
2536
+                - substr_count($uri_ref, '/'));
2537
+        }
2538
+    }
2539
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2540
+    if (_FILE_CONNECT) {
2541
+        if (verifier_visiteur() == '0minirezo'
2542
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2543
+            and !isset($_COOKIE['spip_admin'])
2544
+        ) {
2545
+            clear_path_cache();
2546
+        }
2547
+    }
2549 2548
 
2550 2549
 }
2551 2550
 
@@ -2555,174 +2554,174 @@  discard block
 block discarded – undo
2555 2554
  *
2556 2555
  */
2557 2556
 function spip_initialisation_suite() {
2558
-	static $too_late = 0;
2559
-	if ($too_late++) {
2560
-		return;
2561
-	}
2562
-
2563
-	// taille mini des login
2564
-	if (!defined('_LOGIN_TROP_COURT')) {
2565
-		define('_LOGIN_TROP_COURT', 4);
2566
-	}
2567
-
2568
-	// la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2569
-	#if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2570
-	#if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2571
-	#if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2572
-
2573
-	// la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2574
-	#if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2575
-	#if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2576
-	#if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2577
-	#if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2578
-
2579
-	if (!defined('_PASS_LONGUEUR_MINI')) {
2580
-		define('_PASS_LONGUEUR_MINI', 6);
2581
-	}
2582
-
2583
-
2584
-	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2585
-	if (!defined('_IMG_QUALITE')) {
2586
-		define('_IMG_QUALITE', 85);
2587
-	} # valeur par defaut
2588
-	if (!defined('_IMG_GD_QUALITE')) {
2589
-		define('_IMG_GD_QUALITE', _IMG_QUALITE);
2590
-	} # surcharge pour la lib GD
2591
-	if (!defined('_IMG_CONVERT_QUALITE')) {
2592
-		define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2593
-	} # surcharge pour imagick en ligne de commande
2594
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2595
-	if (!defined('_IMG_IMAGICK_QUALITE')) {
2596
-		define('_IMG_IMAGICK_QUALITE', 75);
2597
-	} # surcharge pour imagick en PHP
2598
-
2599
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2600
-		define('_COPIE_LOCALE_MAX_SIZE', 33554432);
2601
-	} // poids en octet
2602
-
2603
-	// qq chaines standard
2604
-	if (!defined('_ACCESS_FILE_NAME')) {
2605
-		define('_ACCESS_FILE_NAME', '.htaccess');
2606
-	}
2607
-	if (!defined('_AUTH_USER_FILE')) {
2608
-		define('_AUTH_USER_FILE', '.htpasswd');
2609
-	}
2610
-	if (!defined('_SPIP_DUMP')) {
2611
-		define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2612
-	}
2613
-	if (!defined('_CACHE_RUBRIQUES')) {
2614
-		/** Fichier cache pour le navigateur de rubrique du bandeau */
2615
-		define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2616
-	}
2617
-	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2618
-		/** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2619
-		define('_CACHE_RUBRIQUES_MAX', 500);
2620
-	}
2621
-
2622
-	if (!defined('_EXTENSION_SQUELETTES')) {
2623
-		define('_EXTENSION_SQUELETTES', 'html');
2624
-	}
2625
-
2626
-	if (!defined('_DOCTYPE_ECRIRE')) {
2627
-		/** Définit le doctype de l’espace privé */
2628
-		define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2629
-	}
2630
-	if (!defined('_DOCTYPE_AIDE')) {
2631
-		/** Définit le doctype de l’aide en ligne */
2632
-		define('_DOCTYPE_AIDE',
2633
-		"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
2634
-	}
2635
-
2636
-	if (!defined('_SPIP_SCRIPT')) {
2637
-		/** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2638
-		 * le script de l'espace public, alias index.php */
2639
-		define('_SPIP_SCRIPT', 'spip.php');
2640
-	}
2641
-	if (!defined('_SPIP_PAGE')) {
2642
-		/** Argument page, personalisable en cas de conflit avec un autre script */
2643
-		define('_SPIP_PAGE', 'page');
2644
-	}
2645
-
2646
-	// le script de l'espace prive
2647
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2648
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2649
-	// meme pb sur thttpd cf. http://forum.spip.net/fr_184153.html
2650
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2651
-		if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2652
-			define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2653
-		} else {
2654
-			define('_SPIP_ECRIRE_SCRIPT', '');
2655
-		}
2656
-	}
2657
-
2658
-
2659
-	if (!defined('_SPIP_AJAX')) {
2660
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2661
-			? 1
2662
-			: (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2663
-	}
2664
-
2665
-	// La requete est-elle en ajax ?
2666
-	if (!defined('_AJAX')) {
2667
-		define('_AJAX',
2668
-			(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2669
-				or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2670
-				or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2671
-				or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2672
-			)
2673
-			and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient
2674
-		);
2675
-	}
2676
-
2677
-	# nombre de pixels maxi pour calcul de la vignette avec gd
2678
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2679
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2680
-	if (!defined('_IMG_GD_MAX_PIXELS')) {
2681
-		define('_IMG_GD_MAX_PIXELS',
2682
-		(isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2683
-			? $GLOBALS['meta']['max_taille_vignettes']
2684
-			: 0);
2685
-	}
2686
-
2687
-	if (!defined('_MEMORY_LIMIT_MIN')) {
2688
-		define('_MEMORY_LIMIT_MIN', 16);
2689
-	} // en Mo
2690
-	// si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2691
-	// on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2692
-	// il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2693
-	if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2694
-		if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2695
-			$unit = strtolower(substr($memory, -1));
2696
-			$memory = substr($memory, 0, -1);
2697
-			switch ($unit) {
2698
-				// Le modifieur 'G' est disponible depuis PHP 5.1.0
2699
-				case 'g':
2700
-					$memory *= 1024;
2701
-				case 'm':
2702
-					$memory *= 1024;
2703
-				case 'k':
2704
-					$memory *= 1024;
2705
-			}
2706
-			if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2707
-				@ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2708
-				if (trim(ini_get('memory_limit')) != $m) {
2709
-					if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2710
-						define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2711
-					} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2712
-				}
2713
-			}
2714
-		} else {
2715
-			if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2716
-				define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2717
-			}
2718
-		} // evite une page blanche car on ne saura pas calculer la css dans ce hit
2719
-	}
2720
-	// Protocoles a normaliser dans les chaines de langues
2721
-	if (!defined('_PROTOCOLES_STD')) {
2722
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2723
-	}
2724
-
2725
-	init_var_mode();
2557
+    static $too_late = 0;
2558
+    if ($too_late++) {
2559
+        return;
2560
+    }
2561
+
2562
+    // taille mini des login
2563
+    if (!defined('_LOGIN_TROP_COURT')) {
2564
+        define('_LOGIN_TROP_COURT', 4);
2565
+    }
2566
+
2567
+    // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2568
+    #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2569
+    #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2570
+    #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2571
+
2572
+    // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2573
+    #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2574
+    #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2575
+    #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2576
+    #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2577
+
2578
+    if (!defined('_PASS_LONGUEUR_MINI')) {
2579
+        define('_PASS_LONGUEUR_MINI', 6);
2580
+    }
2581
+
2582
+
2583
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2584
+    if (!defined('_IMG_QUALITE')) {
2585
+        define('_IMG_QUALITE', 85);
2586
+    } # valeur par defaut
2587
+    if (!defined('_IMG_GD_QUALITE')) {
2588
+        define('_IMG_GD_QUALITE', _IMG_QUALITE);
2589
+    } # surcharge pour la lib GD
2590
+    if (!defined('_IMG_CONVERT_QUALITE')) {
2591
+        define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2592
+    } # surcharge pour imagick en ligne de commande
2593
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2594
+    if (!defined('_IMG_IMAGICK_QUALITE')) {
2595
+        define('_IMG_IMAGICK_QUALITE', 75);
2596
+    } # surcharge pour imagick en PHP
2597
+
2598
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2599
+        define('_COPIE_LOCALE_MAX_SIZE', 33554432);
2600
+    } // poids en octet
2601
+
2602
+    // qq chaines standard
2603
+    if (!defined('_ACCESS_FILE_NAME')) {
2604
+        define('_ACCESS_FILE_NAME', '.htaccess');
2605
+    }
2606
+    if (!defined('_AUTH_USER_FILE')) {
2607
+        define('_AUTH_USER_FILE', '.htpasswd');
2608
+    }
2609
+    if (!defined('_SPIP_DUMP')) {
2610
+        define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2611
+    }
2612
+    if (!defined('_CACHE_RUBRIQUES')) {
2613
+        /** Fichier cache pour le navigateur de rubrique du bandeau */
2614
+        define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2615
+    }
2616
+    if (!defined('_CACHE_RUBRIQUES_MAX')) {
2617
+        /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2618
+        define('_CACHE_RUBRIQUES_MAX', 500);
2619
+    }
2620
+
2621
+    if (!defined('_EXTENSION_SQUELETTES')) {
2622
+        define('_EXTENSION_SQUELETTES', 'html');
2623
+    }
2624
+
2625
+    if (!defined('_DOCTYPE_ECRIRE')) {
2626
+        /** Définit le doctype de l’espace privé */
2627
+        define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2628
+    }
2629
+    if (!defined('_DOCTYPE_AIDE')) {
2630
+        /** Définit le doctype de l’aide en ligne */
2631
+        define('_DOCTYPE_AIDE',
2632
+        "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>");
2633
+    }
2634
+
2635
+    if (!defined('_SPIP_SCRIPT')) {
2636
+        /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2637
+         * le script de l'espace public, alias index.php */
2638
+        define('_SPIP_SCRIPT', 'spip.php');
2639
+    }
2640
+    if (!defined('_SPIP_PAGE')) {
2641
+        /** Argument page, personalisable en cas de conflit avec un autre script */
2642
+        define('_SPIP_PAGE', 'page');
2643
+    }
2644
+
2645
+    // le script de l'espace prive
2646
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2647
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2648
+    // meme pb sur thttpd cf. http://forum.spip.net/fr_184153.html
2649
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2650
+        if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2651
+            define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2652
+        } else {
2653
+            define('_SPIP_ECRIRE_SCRIPT', '');
2654
+        }
2655
+    }
2656
+
2657
+
2658
+    if (!defined('_SPIP_AJAX')) {
2659
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2660
+            ? 1
2661
+            : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2662
+    }
2663
+
2664
+    // La requete est-elle en ajax ?
2665
+    if (!defined('_AJAX')) {
2666
+        define('_AJAX',
2667
+            (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2668
+                or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2669
+                or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2670
+                or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2671
+            )
2672
+            and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient
2673
+        );
2674
+    }
2675
+
2676
+    # nombre de pixels maxi pour calcul de la vignette avec gd
2677
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2678
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2679
+    if (!defined('_IMG_GD_MAX_PIXELS')) {
2680
+        define('_IMG_GD_MAX_PIXELS',
2681
+        (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2682
+            ? $GLOBALS['meta']['max_taille_vignettes']
2683
+            : 0);
2684
+    }
2685
+
2686
+    if (!defined('_MEMORY_LIMIT_MIN')) {
2687
+        define('_MEMORY_LIMIT_MIN', 16);
2688
+    } // en Mo
2689
+    // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard)
2690
+    // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche
2691
+    // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche
2692
+    if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) {
2693
+        if ($memory = trim(ini_get('memory_limit')) and $memory != -1) {
2694
+            $unit = strtolower(substr($memory, -1));
2695
+            $memory = substr($memory, 0, -1);
2696
+            switch ($unit) {
2697
+                // Le modifieur 'G' est disponible depuis PHP 5.1.0
2698
+                case 'g':
2699
+                    $memory *= 1024;
2700
+                case 'm':
2701
+                    $memory *= 1024;
2702
+                case 'k':
2703
+                    $memory *= 1024;
2704
+            }
2705
+            if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) {
2706
+                @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M');
2707
+                if (trim(ini_get('memory_limit')) != $m) {
2708
+                    if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2709
+                        define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2710
+                    } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2711
+                }
2712
+            }
2713
+        } else {
2714
+            if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) {
2715
+                define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true);
2716
+            }
2717
+        } // evite une page blanche car on ne saura pas calculer la css dans ce hit
2718
+    }
2719
+    // Protocoles a normaliser dans les chaines de langues
2720
+    if (!defined('_PROTOCOLES_STD')) {
2721
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2722
+    }
2723
+
2724
+    init_var_mode();
2726 2725
 }
2727 2726
 
2728 2727
 /**
@@ -2756,129 +2755,129 @@  discard block
 block discarded – undo
2756 2755
  * `   var_mode` (calcul ou recalcul).
2757 2756
  */
2758 2757
 function init_var_mode() {
2759
-	static $done = false;
2760
-	if (!$done) {
2761
-
2762
-		if (isset($_GET['var_mode'])) {
2763
-			$var_mode = explode(',', $_GET['var_mode']);
2764
-			// tout le monde peut calcul/recalcul
2765
-			if (!defined('_VAR_MODE')) {
2766
-				if (in_array('recalcul', $var_mode)) {
2767
-					define('_VAR_MODE', 'recalcul');
2768
-				} elseif (in_array('calcul', $var_mode)) {
2769
-					define('_VAR_MODE', 'calcul');
2770
-				}
2771
-			}
2772
-			$var_mode = array_diff($var_mode, array('calcul', 'recalcul'));
2773
-			if ($var_mode) {
2774
-				include_spip('inc/autoriser');
2775
-				// autoriser preview si preview seulement, et sinon autoriser debug
2776
-				if (autoriser(
2777
-					($_GET['var_mode'] == 'preview')
2778
-						? 'previsualiser'
2779
-						: 'debug'
2780
-				)) {
2781
-					if (in_array('traduction', $var_mode)) {
2782
-						// forcer le calcul pour passer dans traduire
2783
-						if (!defined('_VAR_MODE')) {
2784
-							define('_VAR_MODE', 'calcul');
2785
-						}
2786
-						// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
2787
-						if (!defined('_VAR_NOCACHE')) {
2788
-							define('_VAR_NOCACHE', true);
2789
-						}
2790
-						$var_mode = array_diff($var_mode, array('traduction'));
2791
-					}
2792
-					if (in_array('preview', $var_mode)) {
2793
-						// basculer sur les criteres de preview dans les boucles
2794
-						if (!defined('_VAR_PREVIEW')) {
2795
-							define('_VAR_PREVIEW', true);
2796
-						}
2797
-						// forcer le calcul
2798
-						if (!defined('_VAR_MODE')) {
2799
-							define('_VAR_MODE', 'calcul');
2800
-						}
2801
-						// et ne pas enregistrer de cache
2802
-						if (!defined('_VAR_NOCACHE')) {
2803
-							define('_VAR_NOCACHE', true);
2804
-						}
2805
-						$var_mode = array_diff($var_mode, array('preview'));
2806
-					}
2807
-					if (in_array('inclure', $var_mode)) {
2808
-						// forcer le compilo et ignorer les caches existants
2809
-						if (!defined('_VAR_MODE')) {
2810
-							define('_VAR_MODE', 'calcul');
2811
-						}
2812
-						if (!defined('_VAR_INCLURE')) {
2813
-							define('_VAR_INCLURE', true);
2814
-						}
2815
-						// et ne pas enregistrer de cache
2816
-						if (!defined('_VAR_NOCACHE')) {
2817
-							define('_VAR_NOCACHE', true);
2818
-						}
2819
-						$var_mode = array_diff($var_mode, array('inclure'));
2820
-					}
2821
-					if (in_array('urls', $var_mode)) {
2822
-						// forcer le compilo et ignorer les caches existants
2823
-						if (!defined('_VAR_MODE')) {
2824
-							define('_VAR_MODE', 'calcul');
2825
-						}
2826
-						if (!defined('_VAR_URLS')) {
2827
-							define('_VAR_URLS', true);
2828
-						}
2829
-						$var_mode = array_diff($var_mode, array('urls'));
2830
-					}
2831
-					if (in_array('images', $var_mode)) {
2832
-						// forcer le compilo et ignorer les caches existants
2833
-						if (!defined('_VAR_MODE')) {
2834
-							define('_VAR_MODE', 'calcul');
2835
-						}
2836
-						// indiquer qu'on doit recalculer les images
2837
-						if (!defined('_VAR_IMAGES')) {
2838
-							define('_VAR_IMAGES', true);
2839
-						}
2840
-						$var_mode = array_diff($var_mode, array('images'));
2841
-					}
2842
-					if (in_array('debug', $var_mode)) {
2843
-						if (!defined('_VAR_MODE')) {
2844
-							define('_VAR_MODE', 'debug');
2845
-						}
2846
-						// et ne pas enregistrer de cache
2847
-						if (!defined('_VAR_NOCACHE')) {
2848
-							define('_VAR_NOCACHE', true);
2849
-						}
2850
-						$var_mode = array_diff($var_mode, array('debug'));
2851
-					}
2852
-					if (count($var_mode) and !defined('_VAR_MODE')) {
2853
-						define('_VAR_MODE', reset($var_mode));
2854
-					}
2855
-					if (isset($GLOBALS['visiteur_session']['nom'])) {
2856
-						spip_log($GLOBALS['visiteur_session']['nom']
2857
-							. " " . _VAR_MODE);
2858
-					}
2859
-				} // pas autorise ?
2860
-				else {
2861
-					// si on n'est pas connecte on se redirige
2862
-					if (!$GLOBALS['visiteur_session']) {
2863
-						include_spip('inc/headers');
2864
-						redirige_par_entete(generer_url_public('login',
2865
-							'url=' . rawurlencode(
2866
-								parametre_url(self(), 'var_mode', $_GET['var_mode'], '&')
2867
-							), true));
2868
-					}
2869
-					// sinon tant pis
2870
-				}
2871
-			}
2872
-		}
2873
-		if (!defined('_VAR_MODE')) {
2874
-			/**
2875
-			 * Indique le mode de calcul ou d'affichage de la page.
2876
-			 * @see init_var_mode()
2877
-			 */
2878
-			define('_VAR_MODE', false);
2879
-		}
2880
-		$done = true;
2881
-	}
2758
+    static $done = false;
2759
+    if (!$done) {
2760
+
2761
+        if (isset($_GET['var_mode'])) {
2762
+            $var_mode = explode(',', $_GET['var_mode']);
2763
+            // tout le monde peut calcul/recalcul
2764
+            if (!defined('_VAR_MODE')) {
2765
+                if (in_array('recalcul', $var_mode)) {
2766
+                    define('_VAR_MODE', 'recalcul');
2767
+                } elseif (in_array('calcul', $var_mode)) {
2768
+                    define('_VAR_MODE', 'calcul');
2769
+                }
2770
+            }
2771
+            $var_mode = array_diff($var_mode, array('calcul', 'recalcul'));
2772
+            if ($var_mode) {
2773
+                include_spip('inc/autoriser');
2774
+                // autoriser preview si preview seulement, et sinon autoriser debug
2775
+                if (autoriser(
2776
+                    ($_GET['var_mode'] == 'preview')
2777
+                        ? 'previsualiser'
2778
+                        : 'debug'
2779
+                )) {
2780
+                    if (in_array('traduction', $var_mode)) {
2781
+                        // forcer le calcul pour passer dans traduire
2782
+                        if (!defined('_VAR_MODE')) {
2783
+                            define('_VAR_MODE', 'calcul');
2784
+                        }
2785
+                        // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
2786
+                        if (!defined('_VAR_NOCACHE')) {
2787
+                            define('_VAR_NOCACHE', true);
2788
+                        }
2789
+                        $var_mode = array_diff($var_mode, array('traduction'));
2790
+                    }
2791
+                    if (in_array('preview', $var_mode)) {
2792
+                        // basculer sur les criteres de preview dans les boucles
2793
+                        if (!defined('_VAR_PREVIEW')) {
2794
+                            define('_VAR_PREVIEW', true);
2795
+                        }
2796
+                        // forcer le calcul
2797
+                        if (!defined('_VAR_MODE')) {
2798
+                            define('_VAR_MODE', 'calcul');
2799
+                        }
2800
+                        // et ne pas enregistrer de cache
2801
+                        if (!defined('_VAR_NOCACHE')) {
2802
+                            define('_VAR_NOCACHE', true);
2803
+                        }
2804
+                        $var_mode = array_diff($var_mode, array('preview'));
2805
+                    }
2806
+                    if (in_array('inclure', $var_mode)) {
2807
+                        // forcer le compilo et ignorer les caches existants
2808
+                        if (!defined('_VAR_MODE')) {
2809
+                            define('_VAR_MODE', 'calcul');
2810
+                        }
2811
+                        if (!defined('_VAR_INCLURE')) {
2812
+                            define('_VAR_INCLURE', true);
2813
+                        }
2814
+                        // et ne pas enregistrer de cache
2815
+                        if (!defined('_VAR_NOCACHE')) {
2816
+                            define('_VAR_NOCACHE', true);
2817
+                        }
2818
+                        $var_mode = array_diff($var_mode, array('inclure'));
2819
+                    }
2820
+                    if (in_array('urls', $var_mode)) {
2821
+                        // forcer le compilo et ignorer les caches existants
2822
+                        if (!defined('_VAR_MODE')) {
2823
+                            define('_VAR_MODE', 'calcul');
2824
+                        }
2825
+                        if (!defined('_VAR_URLS')) {
2826
+                            define('_VAR_URLS', true);
2827
+                        }
2828
+                        $var_mode = array_diff($var_mode, array('urls'));
2829
+                    }
2830
+                    if (in_array('images', $var_mode)) {
2831
+                        // forcer le compilo et ignorer les caches existants
2832
+                        if (!defined('_VAR_MODE')) {
2833
+                            define('_VAR_MODE', 'calcul');
2834
+                        }
2835
+                        // indiquer qu'on doit recalculer les images
2836
+                        if (!defined('_VAR_IMAGES')) {
2837
+                            define('_VAR_IMAGES', true);
2838
+                        }
2839
+                        $var_mode = array_diff($var_mode, array('images'));
2840
+                    }
2841
+                    if (in_array('debug', $var_mode)) {
2842
+                        if (!defined('_VAR_MODE')) {
2843
+                            define('_VAR_MODE', 'debug');
2844
+                        }
2845
+                        // et ne pas enregistrer de cache
2846
+                        if (!defined('_VAR_NOCACHE')) {
2847
+                            define('_VAR_NOCACHE', true);
2848
+                        }
2849
+                        $var_mode = array_diff($var_mode, array('debug'));
2850
+                    }
2851
+                    if (count($var_mode) and !defined('_VAR_MODE')) {
2852
+                        define('_VAR_MODE', reset($var_mode));
2853
+                    }
2854
+                    if (isset($GLOBALS['visiteur_session']['nom'])) {
2855
+                        spip_log($GLOBALS['visiteur_session']['nom']
2856
+                            . " " . _VAR_MODE);
2857
+                    }
2858
+                } // pas autorise ?
2859
+                else {
2860
+                    // si on n'est pas connecte on se redirige
2861
+                    if (!$GLOBALS['visiteur_session']) {
2862
+                        include_spip('inc/headers');
2863
+                        redirige_par_entete(generer_url_public('login',
2864
+                            'url=' . rawurlencode(
2865
+                                parametre_url(self(), 'var_mode', $_GET['var_mode'], '&')
2866
+                            ), true));
2867
+                    }
2868
+                    // sinon tant pis
2869
+                }
2870
+            }
2871
+        }
2872
+        if (!defined('_VAR_MODE')) {
2873
+            /**
2874
+             * Indique le mode de calcul ou d'affichage de la page.
2875
+             * @see init_var_mode()
2876
+             */
2877
+            define('_VAR_MODE', false);
2878
+        }
2879
+        $done = true;
2880
+    }
2882 2881
 }
2883 2882
 
2884 2883
 // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ;
@@ -2886,93 +2885,93 @@  discard block
 block discarded – undo
2886 2885
 // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal')
2887 2886
 // http://code.spip.net/@spip_desinfecte
2888 2887
 function spip_desinfecte(&$t, $deep = true) {
2889
-	static $magic_quotes;
2890
-	if (!isset($magic_quotes)) {
2891
-		$magic_quotes = @get_magic_quotes_gpc();
2892
-	}
2893
-
2894
-	foreach ($t as $key => $val) {
2895
-		if (is_string($t[$key])) {
2896
-			if ($magic_quotes) {
2897
-				$t[$key] = stripslashes($t[$key]);
2898
-			}
2899
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
2900
-		} // traiter aussi les "texte_plus" de article_edit
2901
-		else {
2902
-			if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
2903
-				spip_desinfecte($t[$key], $deep);
2904
-			}
2905
-		}
2906
-	}
2888
+    static $magic_quotes;
2889
+    if (!isset($magic_quotes)) {
2890
+        $magic_quotes = @get_magic_quotes_gpc();
2891
+    }
2892
+
2893
+    foreach ($t as $key => $val) {
2894
+        if (is_string($t[$key])) {
2895
+            if ($magic_quotes) {
2896
+                $t[$key] = stripslashes($t[$key]);
2897
+            }
2898
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
2899
+        } // traiter aussi les "texte_plus" de article_edit
2900
+        else {
2901
+            if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
2902
+                spip_desinfecte($t[$key], $deep);
2903
+            }
2904
+        }
2905
+    }
2907 2906
 }
2908 2907
 
2909 2908
 //  retourne le statut du visiteur s'il s'annonce
2910 2909
 
2911 2910
 // http://code.spip.net/@verifier_visiteur
2912 2911
 function verifier_visiteur() {
2913
-	// Rq: pour que cette fonction marche depuis mes_options
2914
-	// il faut forcer l'init si ce n'est fait
2915
-	// mais on risque de perturber des plugins en initialisant trop tot
2916
-	// certaines constantes
2917
-	@spip_initialisation_core(
2918
-		(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
2919
-		(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
2920
-		(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
2921
-		(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
2922
-	);
2923
-
2924
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
2925
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
2926
-	// Attention on separe bien session_nom et nom, pour eviter
2927
-	// les melanges entre donnees SQL et variables plus aleatoires
2928
-	$variables_session = array('session_nom', 'session_email');
2929
-	foreach ($variables_session as $var) {
2930
-		if (_request($var) !== null) {
2931
-			$init = true;
2932
-			break;
2933
-		}
2934
-	}
2935
-	if (isset($init)) {
2936
-		#@spip_initialisation_suite();
2937
-		$session = charger_fonction('session', 'inc');
2938
-		$session();
2939
-		include_spip('inc/texte');
2940
-		foreach ($variables_session as $var) {
2941
-			if (($a = _request($var)) !== null) {
2942
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
2943
-			}
2944
-		}
2945
-		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
2946
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
2947
-		}
2948
-		$session($GLOBALS['visiteur_session']);
2949
-
2950
-		return 0;
2951
-	}
2952
-
2953
-	$h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
2954
-	if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
2955
-
2956
-		$session = charger_fonction('session', 'inc');
2957
-		if ($session()) {
2958
-			return $GLOBALS['visiteur_session']['statut'];
2959
-		}
2960
-		if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
2961
-			include_spip('inc/auth');
2962
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
2963
-		}
2964
-		if ($h) {
2965
-			$GLOBALS['visiteur_session'] = $h;
2966
-
2967
-			return $GLOBALS['visiteur_session']['statut'];
2968
-		}
2969
-	}
2970
-
2971
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
2972
-	include_spip('inc/lang');
2973
-	utiliser_langue_visiteur();
2974
-
2975
-	return false;
2912
+    // Rq: pour que cette fonction marche depuis mes_options
2913
+    // il faut forcer l'init si ce n'est fait
2914
+    // mais on risque de perturber des plugins en initialisant trop tot
2915
+    // certaines constantes
2916
+    @spip_initialisation_core(
2917
+        (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
2918
+        (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
2919
+        (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
2920
+        (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
2921
+    );
2922
+
2923
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
2924
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
2925
+    // Attention on separe bien session_nom et nom, pour eviter
2926
+    // les melanges entre donnees SQL et variables plus aleatoires
2927
+    $variables_session = array('session_nom', 'session_email');
2928
+    foreach ($variables_session as $var) {
2929
+        if (_request($var) !== null) {
2930
+            $init = true;
2931
+            break;
2932
+        }
2933
+    }
2934
+    if (isset($init)) {
2935
+        #@spip_initialisation_suite();
2936
+        $session = charger_fonction('session', 'inc');
2937
+        $session();
2938
+        include_spip('inc/texte');
2939
+        foreach ($variables_session as $var) {
2940
+            if (($a = _request($var)) !== null) {
2941
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
2942
+            }
2943
+        }
2944
+        if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
2945
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
2946
+        }
2947
+        $session($GLOBALS['visiteur_session']);
2948
+
2949
+        return 0;
2950
+    }
2951
+
2952
+    $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
2953
+    if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
2954
+
2955
+        $session = charger_fonction('session', 'inc');
2956
+        if ($session()) {
2957
+            return $GLOBALS['visiteur_session']['statut'];
2958
+        }
2959
+        if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
2960
+            include_spip('inc/auth');
2961
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
2962
+        }
2963
+        if ($h) {
2964
+            $GLOBALS['visiteur_session'] = $h;
2965
+
2966
+            return $GLOBALS['visiteur_session']['statut'];
2967
+        }
2968
+    }
2969
+
2970
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
2971
+    include_spip('inc/lang');
2972
+    utiliser_langue_visiteur();
2973
+
2974
+    return false;
2976 2975
 }
2977 2976
 
2978 2977
 
@@ -2995,21 +2994,21 @@  discard block
 block discarded – undo
2995 2994
  *     - string Langue utilisée.
2996 2995
  **/
2997 2996
 function lang_select($lang = null) {
2998
-	static $pile_langues = array();
2999
-	if (!function_exists('changer_langue')) {
3000
-		include_spip('inc/lang');
3001
-	}
3002
-	if ($lang === null) {
3003
-		$lang = array_pop($pile_langues);
3004
-	} else {
3005
-		array_push($pile_langues, $GLOBALS['spip_lang']);
3006
-	}
3007
-	if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3008
-		return $lang;
3009
-	}
3010
-	changer_langue($lang);
2997
+    static $pile_langues = array();
2998
+    if (!function_exists('changer_langue')) {
2999
+        include_spip('inc/lang');
3000
+    }
3001
+    if ($lang === null) {
3002
+        $lang = array_pop($pile_langues);
3003
+    } else {
3004
+        array_push($pile_langues, $GLOBALS['spip_lang']);
3005
+    }
3006
+    if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3007
+        return $lang;
3008
+    }
3009
+    changer_langue($lang);
3011 3010
 
3012
-	return $lang;
3011
+    return $lang;
3013 3012
 }
3014 3013
 
3015 3014
 /**
@@ -3026,19 +3025,19 @@  discard block
 block discarded – undo
3026 3025
  *     Identifiant de la session
3027 3026
  **/
3028 3027
 function spip_session($force = false) {
3029
-	static $session;
3030
-	if ($force or !isset($session)) {
3031
-		$s = pipeline('definir_session',
3032
-			$GLOBALS['visiteur_session']
3033
-				? serialize($GLOBALS['visiteur_session'])
3034
-				. '_' . @$_COOKIE['spip_session']
3035
-				: ''
3036
-		);
3037
-		$session = $s ? substr(md5($s), 0, 8) : '';
3038
-	}
3028
+    static $session;
3029
+    if ($force or !isset($session)) {
3030
+        $s = pipeline('definir_session',
3031
+            $GLOBALS['visiteur_session']
3032
+                ? serialize($GLOBALS['visiteur_session'])
3033
+                . '_' . @$_COOKIE['spip_session']
3034
+                : ''
3035
+        );
3036
+        $session = $s ? substr(md5($s), 0, 8) : '';
3037
+    }
3039 3038
 
3040
-	#spip_log('session: '.$session);
3041
-	return $session;
3039
+    #spip_log('session: '.$session);
3040
+    return $session;
3042 3041
 }
3043 3042
 
3044 3043
 
@@ -3057,9 +3056,9 @@  discard block
 block discarded – undo
3057 3056
  *    Lien sur une icone d'aide
3058 3057
  **/
3059 3058
 function aider($aide = '', $distante = false) {
3060
-	$aider = charger_fonction('aide', 'inc', true);
3059
+    $aider = charger_fonction('aide', 'inc', true);
3061 3060
 
3062
-	return $aider ? $aider($aide, '', array(), $distante) : '';
3061
+    return $aider ? $aider($aide, '', array(), $distante) : '';
3063 3062
 }
3064 3063
 
3065 3064
 /**
@@ -3069,13 +3068,13 @@  discard block
 block discarded – undo
3069 3068
  */
3070 3069
 function exec_info_dist() {
3071 3070
 
3072
-	include_spip('inc/autoriser');
3073
-	if (autoriser('webmestre')) {
3074
-		phpinfo();
3075
-	} else {
3076
-		include_spip('inc/filtres');
3077
-		sinon_interdire_acces();
3078
-	}
3071
+    include_spip('inc/autoriser');
3072
+    if (autoriser('webmestre')) {
3073
+        phpinfo();
3074
+    } else {
3075
+        include_spip('inc/filtres');
3076
+        sinon_interdire_acces();
3077
+    }
3079 3078
 }
3080 3079
 
3081 3080
 /**
@@ -3095,13 +3094,13 @@  discard block
 block discarded – undo
3095 3094
  *     - string si $message à false.
3096 3095
  **/
3097 3096
 function erreur_squelette($message = '', $lieu = '') {
3098
-	$debusquer = charger_fonction('debusquer', 'public');
3099
-	if (is_array($lieu)) {
3100
-		include_spip('public/compiler');
3101
-		$lieu = reconstruire_contexte_compil($lieu);
3102
-	}
3097
+    $debusquer = charger_fonction('debusquer', 'public');
3098
+    if (is_array($lieu)) {
3099
+        include_spip('public/compiler');
3100
+        $lieu = reconstruire_contexte_compil($lieu);
3101
+    }
3103 3102
 
3104
-	return $debusquer($message, $lieu);
3103
+    return $debusquer($message, $lieu);
3105 3104
 }
3106 3105
 
3107 3106
 /**
@@ -3138,109 +3137,109 @@  discard block
 block discarded – undo
3138 3137
  *     - ou tableau d'information sur le squelette.
3139 3138
  */
3140 3139
 function recuperer_fond($fond, $contexte = array(), $options = array(), $connect = '') {
3141
-	if (!function_exists('evaluer_fond')) {
3142
-		include_spip('public/assembler');
3143
-	}
3144
-	// assurer la compat avec l'ancienne syntaxe
3145
-	// (trim etait le 3eme argument, par defaut a true)
3146
-	if (!is_array($options)) {
3147
-		$options = array('trim' => $options);
3148
-	}
3149
-	if (!isset($options['trim'])) {
3150
-		$options['trim'] = true;
3151
-	}
3152
-
3153
-	if (isset($contexte['connect'])) {
3154
-		$connect = $contexte['connect'];
3155
-		unset($contexte['connect']);
3156
-	}
3157
-
3158
-	$texte = "";
3159
-	$pages = array();
3160
-	$lang_select = '';
3161
-	if (!isset($options['etoile']) or !$options['etoile']) {
3162
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
3163
-		if (!isset($contexte['lang'])) {
3164
-			$contexte['lang'] = $GLOBALS['spip_lang'];
3165
-		}
3166
-
3167
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3168
-			$lang_select = lang_select($contexte['lang']);
3169
-		}
3170
-	}
3171
-
3172
-	if (!isset($GLOBALS['_INC_PUBLIC'])) {
3173
-		$GLOBALS['_INC_PUBLIC'] = 0;
3174
-	}
3175
-
3176
-	$GLOBALS['_INC_PUBLIC']++;
3177
-
3178
-	// fix #4235
3179
-	$cache_utilise_session_appelant	= (isset($GLOBALS['cache_utilise_session']) ? $GLOBALS['cache_utilise_session'] : null);
3180
-
3181
-
3182
-	foreach (is_array($fond) ? $fond : array($fond) as $f) {
3140
+    if (!function_exists('evaluer_fond')) {
3141
+        include_spip('public/assembler');
3142
+    }
3143
+    // assurer la compat avec l'ancienne syntaxe
3144
+    // (trim etait le 3eme argument, par defaut a true)
3145
+    if (!is_array($options)) {
3146
+        $options = array('trim' => $options);
3147
+    }
3148
+    if (!isset($options['trim'])) {
3149
+        $options['trim'] = true;
3150
+    }
3151
+
3152
+    if (isset($contexte['connect'])) {
3153
+        $connect = $contexte['connect'];
3154
+        unset($contexte['connect']);
3155
+    }
3156
+
3157
+    $texte = "";
3158
+    $pages = array();
3159
+    $lang_select = '';
3160
+    if (!isset($options['etoile']) or !$options['etoile']) {
3161
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
3162
+        if (!isset($contexte['lang'])) {
3163
+            $contexte['lang'] = $GLOBALS['spip_lang'];
3164
+        }
3165
+
3166
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3167
+            $lang_select = lang_select($contexte['lang']);
3168
+        }
3169
+    }
3170
+
3171
+    if (!isset($GLOBALS['_INC_PUBLIC'])) {
3172
+        $GLOBALS['_INC_PUBLIC'] = 0;
3173
+    }
3174
+
3175
+    $GLOBALS['_INC_PUBLIC']++;
3176
+
3177
+    // fix #4235
3178
+    $cache_utilise_session_appelant	= (isset($GLOBALS['cache_utilise_session']) ? $GLOBALS['cache_utilise_session'] : null);
3179
+
3180
+
3181
+    foreach (is_array($fond) ? $fond : array($fond) as $f) {
3183 3182
 		
3184
-		unset($GLOBALS['cache_utilise_session']);	// fix #4235
3185
-
3186
-		$page = evaluer_fond($f, $contexte, $connect);
3187
-		if ($page === '') {
3188
-			$c = isset($options['compil']) ? $options['compil'] : '';
3189
-			$a = array('fichier' => $f);
3190
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3191
-			erreur_squelette($erreur, $c);
3192
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3193
-			$page = array('texte' => '', 'erreur' => $erreur);
3194
-		}
3195
-
3196
-		$page = pipeline('recuperer_fond', array(
3197
-			'args' => array('fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect),
3198
-			'data' => $page
3199
-		));
3200
-		if (isset($options['ajax']) and $options['ajax']) {
3201
-			if (!function_exists('encoder_contexte_ajax')) {
3202
-				include_spip('inc/filtres');
3203
-			}
3204
-			$page['texte'] = encoder_contexte_ajax(
3205
-				array_merge(
3206
-					$contexte,
3207
-					array('fond' => $f),
3208
-					($connect ? array('connect' => $connect) : array())
3209
-				),
3210
-				'',
3211
-				$page['texte'],
3212
-				$options['ajax']
3213
-			);
3214
-		}
3215
-
3216
-		if (isset($options['raw']) and $options['raw']) {
3217
-			$pages[] = $page;
3218
-		} else {
3219
-			$texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
3220
-		}
3183
+        unset($GLOBALS['cache_utilise_session']);	// fix #4235
3184
+
3185
+        $page = evaluer_fond($f, $contexte, $connect);
3186
+        if ($page === '') {
3187
+            $c = isset($options['compil']) ? $options['compil'] : '';
3188
+            $a = array('fichier' => $f);
3189
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3190
+            erreur_squelette($erreur, $c);
3191
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3192
+            $page = array('texte' => '', 'erreur' => $erreur);
3193
+        }
3194
+
3195
+        $page = pipeline('recuperer_fond', array(
3196
+            'args' => array('fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect),
3197
+            'data' => $page
3198
+        ));
3199
+        if (isset($options['ajax']) and $options['ajax']) {
3200
+            if (!function_exists('encoder_contexte_ajax')) {
3201
+                include_spip('inc/filtres');
3202
+            }
3203
+            $page['texte'] = encoder_contexte_ajax(
3204
+                array_merge(
3205
+                    $contexte,
3206
+                    array('fond' => $f),
3207
+                    ($connect ? array('connect' => $connect) : array())
3208
+                ),
3209
+                '',
3210
+                $page['texte'],
3211
+                $options['ajax']
3212
+            );
3213
+        }
3214
+
3215
+        if (isset($options['raw']) and $options['raw']) {
3216
+            $pages[] = $page;
3217
+        } else {
3218
+            $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte'];
3219
+        }
3221 3220
 		
3222
-		// contamination de la session appelante, pour les inclusions statiques
3223
-		if (isset($page['invalideurs']['session'])){
3224
-			$cache_utilise_session_appelant = $page['invalideurs']['session'];
3225
-		}
3226
-	}
3221
+        // contamination de la session appelante, pour les inclusions statiques
3222
+        if (isset($page['invalideurs']['session'])){
3223
+            $cache_utilise_session_appelant = $page['invalideurs']['session'];
3224
+        }
3225
+    }
3227 3226
 
3228
-	// restaurer le sessionnement du contexte appelant, 
3229
-	// éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3230
-	if (isset($cache_utilise_session_appelant)) {
3231
-		$GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3232
-	}
3227
+    // restaurer le sessionnement du contexte appelant, 
3228
+    // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3229
+    if (isset($cache_utilise_session_appelant)) {
3230
+        $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3231
+    }
3233 3232
 
3234
-	$GLOBALS['_INC_PUBLIC']--;
3233
+    $GLOBALS['_INC_PUBLIC']--;
3235 3234
 
3236
-	if ($lang_select) {
3237
-		lang_select();
3238
-	}
3239
-	if (isset($options['raw']) and $options['raw']) {
3240
-		return is_array($fond) ? $pages : reset($pages);
3241
-	} else {
3242
-		return $options['trim'] ? ltrim($texte) : $texte;
3243
-	}
3235
+    if ($lang_select) {
3236
+        lang_select();
3237
+    }
3238
+    if (isset($options['raw']) and $options['raw']) {
3239
+        return is_array($fond) ? $pages : reset($pages);
3240
+    } else {
3241
+        return $options['trim'] ? ltrim($texte) : $texte;
3242
+    }
3244 3243
 }
3245 3244
 
3246 3245
 /**
@@ -3250,7 +3249,7 @@  discard block
 block discarded – undo
3250 3249
  * @return string
3251 3250
  */
3252 3251
 function trouve_modele($nom) {
3253
-	return trouver_fond($nom, 'modeles/');
3252
+    return trouver_fond($nom, 'modeles/');
3254 3253
 }
3255 3254
 
3256 3255
 /**
@@ -3266,21 +3265,21 @@  discard block
 block discarded – undo
3266 3265
  * @return array|string
3267 3266
  */
3268 3267
 function trouver_fond($nom, $dir = '', $pathinfo = false) {
3269
-	$f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3270
-	if (!$pathinfo) {
3271
-		return $f;
3272
-	}
3273
-	// renvoyer un tableau detaille si $pathinfo==true
3274
-	$p = pathinfo($f);
3275
-	if (!isset($p['extension']) or !$p['extension']) {
3276
-		$p['extension'] = _EXTENSION_SQUELETTES;
3277
-	}
3278
-	if (!isset($p['extension']) or !$p['filename']) {
3279
-		$p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3280
-	}
3281
-	$p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3268
+    $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3269
+    if (!$pathinfo) {
3270
+        return $f;
3271
+    }
3272
+    // renvoyer un tableau detaille si $pathinfo==true
3273
+    $p = pathinfo($f);
3274
+    if (!isset($p['extension']) or !$p['extension']) {
3275
+        $p['extension'] = _EXTENSION_SQUELETTES;
3276
+    }
3277
+    if (!isset($p['extension']) or !$p['filename']) {
3278
+        $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3279
+    }
3280
+    $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3282 3281
 
3283
-	return $p;
3282
+    return $p;
3284 3283
 }
3285 3284
 
3286 3285
 /**
@@ -3301,24 +3300,24 @@  discard block
 block discarded – undo
3301 3300
  *     Nom de l'exec, sinon chaîne vide.
3302 3301
  **/
3303 3302
 function tester_url_ecrire($nom) {
3304
-	static $exec = array();
3305
-	if (isset($exec[$nom])) {
3306
-		return $exec[$nom];
3307
-	}
3308
-	// tester si c'est une page en squelette
3309
-	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3310
-		return $exec[$nom] = 'fond';
3311
-	} // compat skels orthogonaux version precedente
3312
-	elseif (trouver_fond($nom, 'prive/exec/')) {
3313
-		return $exec[$nom] = 'fond_monobloc';
3314
-	} // echafaudage d'un fond !
3315
-	elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3316
-		return $exec[$nom] = 'fond';
3317
-	}
3318
-	// attention, il ne faut pas inclure l'exec ici
3319
-	// car sinon #URL_ECRIRE provoque des inclusions
3320
-	// et des define intrusifs potentiels
3321
-	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3303
+    static $exec = array();
3304
+    if (isset($exec[$nom])) {
3305
+        return $exec[$nom];
3306
+    }
3307
+    // tester si c'est une page en squelette
3308
+    if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3309
+        return $exec[$nom] = 'fond';
3310
+    } // compat skels orthogonaux version precedente
3311
+    elseif (trouver_fond($nom, 'prive/exec/')) {
3312
+        return $exec[$nom] = 'fond_monobloc';
3313
+    } // echafaudage d'un fond !
3314
+    elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3315
+        return $exec[$nom] = 'fond';
3316
+    }
3317
+    // attention, il ne faut pas inclure l'exec ici
3318
+    // car sinon #URL_ECRIRE provoque des inclusions
3319
+    // et des define intrusifs potentiels
3320
+    return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3322 3321
 }
3323 3322
 
3324 3323
 
@@ -3334,10 +3333,10 @@  discard block
 block discarded – undo
3334 3333
  * @return bool true si le module est chargé
3335 3334
  **/
3336 3335
 function charger_php_extension($module) {
3337
-	if (extension_loaded($module)) {
3338
-		return true;
3339
-	}
3340
-	return false;
3336
+    if (extension_loaded($module)) {
3337
+        return true;
3338
+    }
3339
+    return false;
3341 3340
 }
3342 3341
 
3343 3342
 
@@ -3348,8 +3347,8 @@  discard block
 block discarded – undo
3348 3347
  *     true si et seulement si la configuration autorise le code HTML5 sur le site public
3349 3348
  **/
3350 3349
 function html5_permis() {
3351
-	return (isset($GLOBALS['meta']['version_html_max'])
3352
-		and ('html5' == $GLOBALS['meta']['version_html_max']));
3350
+    return (isset($GLOBALS['meta']['version_html_max'])
3351
+        and ('html5' == $GLOBALS['meta']['version_html_max']));
3353 3352
 }
3354 3353
 
3355 3354
 /**
@@ -3359,17 +3358,17 @@  discard block
 block discarded – undo
3359 3358
  * @return array
3360 3359
  */
3361 3360
 function formats_image_acceptables($gd = false, $svg_allowed = true) {
3362
-	$config = ($gd ? "gd_formats" : "formats_graphiques");
3363
-	$formats = (isset($GLOBALS['meta'][$config]) ? $GLOBALS['meta'][$config] : 'png,gif,jpg');
3364
-	$formats = explode(',', $formats);
3365
-	$formats = array_filter($formats);
3366
-	$formats = array_map('trim', $formats);
3361
+    $config = ($gd ? "gd_formats" : "formats_graphiques");
3362
+    $formats = (isset($GLOBALS['meta'][$config]) ? $GLOBALS['meta'][$config] : 'png,gif,jpg');
3363
+    $formats = explode(',', $formats);
3364
+    $formats = array_filter($formats);
3365
+    $formats = array_map('trim', $formats);
3367 3366
 
3368
-	if ($svg_allowed) {
3369
-		$formats[] = 'svg';
3370
-	}
3367
+    if ($svg_allowed) {
3368
+        $formats[] = 'svg';
3369
+    }
3371 3370
 
3372
-	return $formats;
3371
+    return $formats;
3373 3372
 }
3374 3373
 
3375 3374
 /**
@@ -3378,40 +3377,40 @@  discard block
 block discarded – undo
3378 3377
  * @return array|bool
3379 3378
  */
3380 3379
 function spip_getimagesize($fichier) {
3381
-	if (!$imagesize = @getimagesize($fichier)) {
3382
-
3383
-		include_spip("inc/svg");
3384
-		if ($attrs = svg_lire_attributs($fichier)) {
3385
-			$width = 350; // default width
3386
-			$height = 150; // default height
3387
-			if (isset($attrs['width'])
3388
-			  and $w = svg_dimension_to_pixels($attrs['width'])
3389
-				and isset($attrs['height'])
3390
-			  and $h = svg_dimension_to_pixels($attrs['height'])) {
3391
-				$width = $w;
3392
-				$height = $h;
3393
-			}
3394
-			elseif (isset($attrs['viewBox'])) {
3395
-				$viewbox = trim($attrs['viewBox']);
3396
-				$viewbox = preg_replace(",\s+,", " ", $viewbox);
3397
-				$viewbox = explode(" ", $viewbox);
3398
-				if (count($viewbox) === 4
3399
-				  and $w = svg_dimension_to_pixels($viewbox[2])
3400
-				  and $h = svg_dimension_to_pixels($viewbox[3])) {
3401
-					$width = $w;
3402
-					$height = $h;
3403
-				}
3404
-			}
3405
-			$imagesize = [
3406
-				$width,
3407
-				$height,
3408
-				IMAGETYPE_SVG,
3409
-				"width=\"{$width}\" height=\"{$height}\"",
3410
-				"mime" => "image/svg+xml"
3411
-			];
3412
-		}
3413
-	}
3414
-	return $imagesize;
3380
+    if (!$imagesize = @getimagesize($fichier)) {
3381
+
3382
+        include_spip("inc/svg");
3383
+        if ($attrs = svg_lire_attributs($fichier)) {
3384
+            $width = 350; // default width
3385
+            $height = 150; // default height
3386
+            if (isset($attrs['width'])
3387
+              and $w = svg_dimension_to_pixels($attrs['width'])
3388
+                and isset($attrs['height'])
3389
+              and $h = svg_dimension_to_pixels($attrs['height'])) {
3390
+                $width = $w;
3391
+                $height = $h;
3392
+            }
3393
+            elseif (isset($attrs['viewBox'])) {
3394
+                $viewbox = trim($attrs['viewBox']);
3395
+                $viewbox = preg_replace(",\s+,", " ", $viewbox);
3396
+                $viewbox = explode(" ", $viewbox);
3397
+                if (count($viewbox) === 4
3398
+                  and $w = svg_dimension_to_pixels($viewbox[2])
3399
+                  and $h = svg_dimension_to_pixels($viewbox[3])) {
3400
+                    $width = $w;
3401
+                    $height = $h;
3402
+                }
3403
+            }
3404
+            $imagesize = [
3405
+                $width,
3406
+                $height,
3407
+                IMAGETYPE_SVG,
3408
+                "width=\"{$width}\" height=\"{$height}\"",
3409
+                "mime" => "image/svg+xml"
3410
+            ];
3411
+        }
3412
+    }
3413
+    return $imagesize;
3415 3414
 }
3416 3415
 
3417 3416
 
@@ -3431,7 +3430,7 @@  discard block
 block discarded – undo
3431 3430
  * @return mixed Valeur de la meta.
3432 3431
  **/
3433 3432
 function lire_meta($nom) {
3434
-	return isset($GLOBALS['meta'][$nom]) ? $GLOBALS['meta'][$nom] : null;
3433
+    return isset($GLOBALS['meta'][$nom]) ? $GLOBALS['meta'][$nom] : null;
3435 3434
 }
3436 3435
 
3437 3436
 
@@ -3453,128 +3452,128 @@  discard block
 block discarded – undo
3453 3452
  * @param string $statut
3454 3453
  */
3455 3454
 function avertir_auteurs($nom, $message, $statut = '') {
3456
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3457
-	if (!$alertes
3458
-		or !is_array($alertes = unserialize($alertes))
3459
-	) {
3460
-		$alertes = array();
3461
-	}
3455
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3456
+    if (!$alertes
3457
+        or !is_array($alertes = unserialize($alertes))
3458
+    ) {
3459
+        $alertes = array();
3460
+    }
3462 3461
 
3463
-	if (!isset($alertes[$statut])) {
3464
-		$alertes[$statut] = array();
3465
-	}
3466
-	$alertes[$statut][$nom] = $message;
3467
-	ecrire_meta("message_alertes_auteurs", serialize($alertes));
3462
+    if (!isset($alertes[$statut])) {
3463
+        $alertes[$statut] = array();
3464
+    }
3465
+    $alertes[$statut][$nom] = $message;
3466
+    ecrire_meta("message_alertes_auteurs", serialize($alertes));
3468 3467
 }
3469 3468
 
3470 3469
 if (PHP_VERSION_ID < 50500) {
3471
-	if (!function_exists('array_column')) {
3472
-		/**
3473
-		 * Returns the values from a single column of the input array, identified by
3474
-		 * the $columnKey.
3475
-		 *
3476
-		 * Optionally, you may provide an $indexKey to index the values in the returned
3477
-		 * array by the values from the $indexKey column in the input array.
3478
-		 *
3479
-		 * @link http://php.net/manual/fr/function.array-column.php
3480
-		 * @link https://github.com/ramsey/array_column/blob/master/src/array_column.php
3481
-		 * @copyright Copyright (c) Ben Ramsey (http://benramsey.com)
3482
-		 * @license http://opensource.org/licenses/MIT MIT
3483
-		 *
3484
-		 * @param array $input A multi-dimensional array (record set) from which to pull
3485
-		 *                     a column of values.
3486
-		 * @param mixed $columnKey The column of values to return. This value may be the
3487
-		 *                         integer key of the column you wish to retrieve, or it
3488
-		 *                         may be the string key name for an associative array.
3489
-		 * @param mixed $indexKey (Optional.) The column to use as the index/keys for
3490
-		 *                        the returned array. This value may be the integer key
3491
-		 *                        of the column, or it may be the string key name.
3492
-		 * @return array
3493
-		 */
3494
-		function array_column($input = null, $columnKey = null, $indexKey = null)
3495
-		{
3496
-			// Using func_get_args() in order to check for proper number of
3497
-			// parameters and trigger errors exactly as the built-in array_column()
3498
-			// does in PHP 5.5.
3499
-			$argc = func_num_args();
3500
-			$params = func_get_args();
3501
-
3502
-			if ($argc < 2) {
3503
-				trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING);
3504
-				return null;
3505
-			}
3506
-
3507
-			if (!is_array($params[0])) {
3508
-				trigger_error(
3509
-					'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given',
3510
-					E_USER_WARNING
3511
-				);
3512
-				return null;
3513
-			}
3514
-
3515
-			if (!is_int($params[1])
3516
-				&& !is_float($params[1])
3517
-				&& !is_string($params[1])
3518
-				&& $params[1] !== null
3519
-				&& !(is_object($params[1]) && method_exists($params[1], '__toString'))
3520
-			) {
3521
-				trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
3522
-				return false;
3523
-			}
3524
-
3525
-			if (isset($params[2])
3526
-				&& !is_int($params[2])
3527
-				&& !is_float($params[2])
3528
-				&& !is_string($params[2])
3529
-				&& !(is_object($params[2]) && method_exists($params[2], '__toString'))
3530
-			) {
3531
-				trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
3532
-				return false;
3533
-			}
3534
-
3535
-			$paramsInput = $params[0];
3536
-			$paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null;
3537
-
3538
-			$paramsIndexKey = null;
3539
-			if (isset($params[2])) {
3540
-				if (is_float($params[2]) || is_int($params[2])) {
3541
-					$paramsIndexKey = (int) $params[2];
3542
-				} else {
3543
-					$paramsIndexKey = (string) $params[2];
3544
-				}
3545
-			}
3546
-
3547
-			$resultArray = array();
3548
-
3549
-			foreach ($paramsInput as $row) {
3550
-				$key = $value = null;
3551
-				$keySet = $valueSet = false;
3552
-
3553
-				if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) {
3554
-					$keySet = true;
3555
-					$key = (string) $row[$paramsIndexKey];
3556
-				}
3557
-
3558
-				if ($paramsColumnKey === null) {
3559
-					$valueSet = true;
3560
-					$value = $row;
3561
-				} elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) {
3562
-					$valueSet = true;
3563
-					$value = $row[$paramsColumnKey];
3564
-				}
3565
-
3566
-				if ($valueSet) {
3567
-					if ($keySet) {
3568
-						$resultArray[$key] = $value;
3569
-					} else {
3570
-						$resultArray[] = $value;
3571
-					}
3572
-				}
3573
-
3574
-			}
3575
-
3576
-			return $resultArray;
3577
-		}
3578
-
3579
-	}
3470
+    if (!function_exists('array_column')) {
3471
+        /**
3472
+         * Returns the values from a single column of the input array, identified by
3473
+         * the $columnKey.
3474
+         *
3475
+         * Optionally, you may provide an $indexKey to index the values in the returned
3476
+         * array by the values from the $indexKey column in the input array.
3477
+         *
3478
+         * @link http://php.net/manual/fr/function.array-column.php
3479
+         * @link https://github.com/ramsey/array_column/blob/master/src/array_column.php
3480
+         * @copyright Copyright (c) Ben Ramsey (http://benramsey.com)
3481
+         * @license http://opensource.org/licenses/MIT MIT
3482
+         *
3483
+         * @param array $input A multi-dimensional array (record set) from which to pull
3484
+         *                     a column of values.
3485
+         * @param mixed $columnKey The column of values to return. This value may be the
3486
+         *                         integer key of the column you wish to retrieve, or it
3487
+         *                         may be the string key name for an associative array.
3488
+         * @param mixed $indexKey (Optional.) The column to use as the index/keys for
3489
+         *                        the returned array. This value may be the integer key
3490
+         *                        of the column, or it may be the string key name.
3491
+         * @return array
3492
+         */
3493
+        function array_column($input = null, $columnKey = null, $indexKey = null)
3494
+        {
3495
+            // Using func_get_args() in order to check for proper number of
3496
+            // parameters and trigger errors exactly as the built-in array_column()
3497
+            // does in PHP 5.5.
3498
+            $argc = func_num_args();
3499
+            $params = func_get_args();
3500
+
3501
+            if ($argc < 2) {
3502
+                trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING);
3503
+                return null;
3504
+            }
3505
+
3506
+            if (!is_array($params[0])) {
3507
+                trigger_error(
3508
+                    'array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given',
3509
+                    E_USER_WARNING
3510
+                );
3511
+                return null;
3512
+            }
3513
+
3514
+            if (!is_int($params[1])
3515
+                && !is_float($params[1])
3516
+                && !is_string($params[1])
3517
+                && $params[1] !== null
3518
+                && !(is_object($params[1]) && method_exists($params[1], '__toString'))
3519
+            ) {
3520
+                trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING);
3521
+                return false;
3522
+            }
3523
+
3524
+            if (isset($params[2])
3525
+                && !is_int($params[2])
3526
+                && !is_float($params[2])
3527
+                && !is_string($params[2])
3528
+                && !(is_object($params[2]) && method_exists($params[2], '__toString'))
3529
+            ) {
3530
+                trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING);
3531
+                return false;
3532
+            }
3533
+
3534
+            $paramsInput = $params[0];
3535
+            $paramsColumnKey = ($params[1] !== null) ? (string) $params[1] : null;
3536
+
3537
+            $paramsIndexKey = null;
3538
+            if (isset($params[2])) {
3539
+                if (is_float($params[2]) || is_int($params[2])) {
3540
+                    $paramsIndexKey = (int) $params[2];
3541
+                } else {
3542
+                    $paramsIndexKey = (string) $params[2];
3543
+                }
3544
+            }
3545
+
3546
+            $resultArray = array();
3547
+
3548
+            foreach ($paramsInput as $row) {
3549
+                $key = $value = null;
3550
+                $keySet = $valueSet = false;
3551
+
3552
+                if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) {
3553
+                    $keySet = true;
3554
+                    $key = (string) $row[$paramsIndexKey];
3555
+                }
3556
+
3557
+                if ($paramsColumnKey === null) {
3558
+                    $valueSet = true;
3559
+                    $value = $row;
3560
+                } elseif (is_array($row) && array_key_exists($paramsColumnKey, $row)) {
3561
+                    $valueSet = true;
3562
+                    $value = $row[$paramsColumnKey];
3563
+                }
3564
+
3565
+                if ($valueSet) {
3566
+                    if ($keySet) {
3567
+                        $resultArray[$key] = $value;
3568
+                    } else {
3569
+                        $resultArray[] = $value;
3570
+                    }
3571
+                }
3572
+
3573
+            }
3574
+
3575
+            return $resultArray;
3576
+        }
3577
+
3578
+    }
3580 3579
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -2308,12 +2308,13 @@  discard block
 block discarded – undo
2308 2308
 		define('_DIR_CHMOD', $pi);
2309 2309
 	}
2310 2310
 
2311
-	if (!isset($GLOBALS['test_dirs']))
2312
-		// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2311
+	if (!isset($GLOBALS['test_dirs'])) {
2312
+			// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2313 2313
 		// il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2314 2314
 	{
2315 2315
 		$GLOBALS['test_dirs'] = array($pa, $ti, $ta);
2316 2316
 	}
2317
+	}
2317 2318
 
2318 2319
 	// Declaration des fichiers
2319 2320
 
@@ -3390,8 +3391,7 @@  discard block
 block discarded – undo
3390 3391
 			  and $h = svg_dimension_to_pixels($attrs['height'])) {
3391 3392
 				$width = $w;
3392 3393
 				$height = $h;
3393
-			}
3394
-			elseif (isset($attrs['viewBox'])) {
3394
+			} elseif (isset($attrs['viewBox'])) {
3395 3395
 				$viewbox = trim($attrs['viewBox']);
3396 3396
 				$viewbox = preg_replace(",\s+,", " ", $viewbox);
3397 3397
 				$viewbox = explode(" ", $viewbox);
Please login to merge, or discard this patch.
ecrire/inc/filtres.php 1 patch
Indentation   +1979 added lines, -1979 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Filtres
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/charsets');
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
  * @return string Fonction PHP correspondante du filtre
43 43
  */
44 44
 function charger_filtre($fonc, $default = 'filtre_identite_dist') {
45
-	include_spip('public/parametrer'); // inclure les fichiers fonctions
46
-	return chercher_filtre($fonc, $default);
45
+    include_spip('public/parametrer'); // inclure les fichiers fonctions
46
+    return chercher_filtre($fonc, $default);
47 47
 }
48 48
 
49 49
 /**
@@ -75,36 +75,36 @@  discard block
 block discarded – undo
75 75
  *     Fonction PHP correspondante du filtre demandé
76 76
  */
77 77
 function chercher_filtre($fonc, $default = null) {
78
-	if (!$fonc) {
79
-		return $default;
80
-	}
81
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
82
-	// Foo::Bar
83
-	// qui peuvent etre avec un namespace : space\Foo::Bar
84
-	if (preg_match(',^[\w]+/,', $fonc)) {
85
-		$nom = preg_replace(',\W,', '_', $fonc);
86
-		$f = chercher_filtre($nom);
87
-		// cas du sous-type MIME sans filtre associe, passer au type:
88
-		// si filtre_text_plain pas defini, passe a filtre_text
89
-		if (!$f and $nom !== $fonc) {
90
-			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
91
-		}
92
-
93
-		return $f;
94
-	}
95
-	foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
96
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
97
-		// fonction ou name\space\fonction
98
-		if (is_callable($f)) {
99
-			return $f;
100
-		}
101
-		// méthode statique d'une classe Classe::methode ou name\space\Classe::methode
102
-		elseif (false === strpos($f, '::') and is_callable(array($f))) {
103
-			return $f;
104
-		}
105
-	}
106
-
107
-	return $default;
78
+    if (!$fonc) {
79
+        return $default;
80
+    }
81
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
82
+    // Foo::Bar
83
+    // qui peuvent etre avec un namespace : space\Foo::Bar
84
+    if (preg_match(',^[\w]+/,', $fonc)) {
85
+        $nom = preg_replace(',\W,', '_', $fonc);
86
+        $f = chercher_filtre($nom);
87
+        // cas du sous-type MIME sans filtre associe, passer au type:
88
+        // si filtre_text_plain pas defini, passe a filtre_text
89
+        if (!$f and $nom !== $fonc) {
90
+            $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
91
+        }
92
+
93
+        return $f;
94
+    }
95
+    foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
96
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
97
+        // fonction ou name\space\fonction
98
+        if (is_callable($f)) {
99
+            return $f;
100
+        }
101
+        // méthode statique d'une classe Classe::methode ou name\space\Classe::methode
102
+        elseif (false === strpos($f, '::') and is_callable(array($f))) {
103
+            return $f;
104
+        }
105
+    }
106
+
107
+    return $default;
108 108
 }
109 109
 
110 110
 /**
@@ -128,20 +128,20 @@  discard block
 block discarded – undo
128 128
  *     Chaîne vide sinon (filtre introuvable).
129 129
  **/
130 130
 function appliquer_filtre($arg, $filtre, $force = null) {
131
-	$f = chercher_filtre($filtre);
132
-	if (!$f) {
133
-		if (!$force) {
134
-			return '';
135
-		} else {
136
-			return $arg;
137
-		}
138
-	}
131
+    $f = chercher_filtre($filtre);
132
+    if (!$f) {
133
+        if (!$force) {
134
+            return '';
135
+        } else {
136
+            return $arg;
137
+        }
138
+    }
139 139
 
140
-	$args = func_get_args();
141
-	array_shift($args); // enlever $arg
142
-	array_shift($args); // enlever $filtre
143
-	array_unshift($args, $arg); // remettre $arg
144
-	return call_user_func_array($f, $args);
140
+    $args = func_get_args();
141
+    array_shift($args); // enlever $arg
142
+    array_shift($args); // enlever $filtre
143
+    array_unshift($args, $arg); // remettre $arg
144
+    return call_user_func_array($f, $args);
145 145
 }
146 146
 
147 147
 /**
@@ -157,12 +157,12 @@  discard block
 block discarded – undo
157 157
  *     Version de SPIP
158 158
  **/
159 159
 function spip_version() {
160
-	$version = $GLOBALS['spip_version_affichee'];
161
-	if ($svn_revision = version_svn_courante(_DIR_RACINE)) {
162
-		$version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']';
163
-	}
160
+    $version = $GLOBALS['spip_version_affichee'];
161
+    if ($svn_revision = version_svn_courante(_DIR_RACINE)) {
162
+        $version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']';
163
+    }
164 164
 
165
-	return $version;
165
+    return $version;
166 166
 }
167 167
 
168 168
 
@@ -181,43 +181,43 @@  discard block
 block discarded – undo
181 181
  *
182 182
  **/
183 183
 function version_svn_courante($dir) {
184
-	if (!$dir) {
185
-		$dir = '.';
186
-	}
187
-
188
-	// version installee par paquet ZIP
189
-	if (lire_fichier($dir . '/svn.revision', $c)
190
-		and preg_match(',Revision: (\d+),', $c, $d)
191
-	) {
192
-		return intval($d[1]);
193
-	}
194
-
195
-	// version installee par SVN
196
-	if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
197
-		$db = new SQLite3($dir . '/.svn/wc.db');
198
-		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
199
-		if ($result) {
200
-			$row = $result->fetchArray();
201
-			if ($row['changed_revision'] != "") {
202
-				return -$row['changed_revision'];
203
-			}
204
-		}
205
-	} else if (lire_fichier($dir . '/.svn/entries', $c)
206
-		and (
207
-			(preg_match_all(
208
-					',committed-rev="([0-9]+)",', $c, $r1, PREG_PATTERN_ORDER)
209
-				and $v = max($r1[1])
210
-			)
211
-			or
212
-			(preg_match(',^\d.*dir[\r\n]+(\d+),ms', $c, $r1) # svn >= 1.4
213
-				and $v = $r1[1]
214
-			))
215
-	) {
216
-		return -$v;
217
-	}
218
-
219
-	// Bug ou paquet fait main
220
-	return 0;
184
+    if (!$dir) {
185
+        $dir = '.';
186
+    }
187
+
188
+    // version installee par paquet ZIP
189
+    if (lire_fichier($dir . '/svn.revision', $c)
190
+        and preg_match(',Revision: (\d+),', $c, $d)
191
+    ) {
192
+        return intval($d[1]);
193
+    }
194
+
195
+    // version installee par SVN
196
+    if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
197
+        $db = new SQLite3($dir . '/.svn/wc.db');
198
+        $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
199
+        if ($result) {
200
+            $row = $result->fetchArray();
201
+            if ($row['changed_revision'] != "") {
202
+                return -$row['changed_revision'];
203
+            }
204
+        }
205
+    } else if (lire_fichier($dir . '/.svn/entries', $c)
206
+        and (
207
+            (preg_match_all(
208
+                    ',committed-rev="([0-9]+)",', $c, $r1, PREG_PATTERN_ORDER)
209
+                and $v = max($r1[1])
210
+            )
211
+            or
212
+            (preg_match(',^\d.*dir[\r\n]+(\d+),ms', $c, $r1) # svn >= 1.4
213
+                and $v = $r1[1]
214
+            ))
215
+    ) {
216
+        return -$v;
217
+    }
218
+
219
+    // Bug ou paquet fait main
220
+    return 0;
221 221
 }
222 222
 
223 223
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -261,18 +261,18 @@  discard block
 block discarded – undo
261 261
  *     Code HTML retourné par le filtre
262 262
  **/
263 263
 function filtrer($filtre) {
264
-	$tous = func_get_args();
265
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
266
-		return image_filtrer($tous);
267
-	} elseif ($f = chercher_filtre($filtre)) {
268
-		array_shift($tous);
269
-		return call_user_func_array($f, $tous);
270
-	} else {
271
-		// le filtre n'existe pas, on provoque une erreur
272
-		$msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre)));
273
-		erreur_squelette($msg);
274
-		return '';
275
-	}
264
+    $tous = func_get_args();
265
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
266
+        return image_filtrer($tous);
267
+    } elseif ($f = chercher_filtre($filtre)) {
268
+        array_shift($tous);
269
+        return call_user_func_array($f, $tous);
270
+    } else {
271
+        // le filtre n'existe pas, on provoque une erreur
272
+        $msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre)));
273
+        erreur_squelette($msg);
274
+        return '';
275
+    }
276 276
 }
277 277
 
278 278
 /**
@@ -289,11 +289,11 @@  discard block
 block discarded – undo
289 289
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
290 290
  */
291 291
 function trouver_filtre_matrice($filtre) {
292
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
293
-		find_in_path($f, '', true);
294
-		$GLOBALS['spip_matrice'][$filtre] = true;
295
-	}
296
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
292
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
293
+        find_in_path($f, '', true);
294
+        $GLOBALS['spip_matrice'][$filtre] = true;
295
+    }
296
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
297 297
 }
298 298
 
299 299
 
@@ -321,8 +321,8 @@  discard block
 block discarded – undo
321 321
  * @return mixed
322 322
  */
323 323
 function filtre_set(&$Pile, $val, $key, $continue = null) {
324
-	$Pile['vars'][$key] = $val;
325
-	return $continue ? $val : '';
324
+    $Pile['vars'][$key] = $val;
325
+    return $continue ? $val : '';
326 326
 }
327 327
 
328 328
 /**
@@ -348,8 +348,8 @@  discard block
 block discarded – undo
348 348
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
349 349
  */
350 350
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
351
-	$Pile[0][$key] = $val;
352
-	return $continue ? $val : '';
351
+    $Pile[0][$key] = $val;
352
+    return $continue ? $val : '';
353 353
 }
354 354
 
355 355
 /**
@@ -371,18 +371,18 @@  discard block
 block discarded – undo
371 371
  * @return mixed Retourne la valeur (sans la modifier).
372 372
  */
373 373
 function filtre_debug($val, $key = null) {
374
-	$debug = (
375
-		is_null($key) ? '' : (var_export($key, true) . " = ")
376
-		) . var_export($val, true);
374
+    $debug = (
375
+        is_null($key) ? '' : (var_export($key, true) . " = ")
376
+        ) . var_export($val, true);
377 377
 
378
-	include_spip('inc/autoriser');
379
-	if (autoriser('webmestre')) {
380
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
381
-	}
378
+    include_spip('inc/autoriser');
379
+    if (autoriser('webmestre')) {
380
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
381
+    }
382 382
 
383
-	spip_log($debug, 'debug');
383
+    spip_log($debug, 'debug');
384 384
 
385
-	return $val;
385
+    return $val;
386 386
 }
387 387
 
388 388
 
@@ -410,71 +410,71 @@  discard block
 block discarded – undo
410 410
  *     Texte qui a reçu les filtres
411 411
  **/
412 412
 function image_filtrer($args) {
413
-	$filtre = array_shift($args); # enlever $filtre
414
-	$texte = array_shift($args);
415
-	if (!strlen($texte)) {
416
-		return;
417
-	}
418
-	find_in_path('filtres_images_mini.php', 'inc/', true);
419
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
420
-	// Cas du nom de fichier local
421
-	if (strpos(substr($texte, strlen(_DIR_RACINE)), '..') === false
422
-		and !preg_match(',^/|[<>]|\s,S', $texte)
423
-		and (
424
-			file_exists(preg_replace(',[?].*$,', '', $texte))
425
-			or tester_url_absolue($texte)
426
-		)
427
-	) {
428
-		array_unshift($args, "<img src='$texte' />");
429
-		$res = call_user_func_array($filtre, $args);
430
-		statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
431
-		return $res;
432
-	}
433
-
434
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
435
-	if (preg_match_all(
436
-		',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
437
-		$texte, $tags, PREG_SET_ORDER)) {
438
-		foreach ($tags as $tag) {
439
-			$class = extraire_attribut($tag[3], 'class');
440
-			if (!$class or
441
-				(strpos($class, 'filtre_inactif') === false
442
-					// compat historique a virer en 3.2
443
-					and strpos($class, 'no_image_filtrer') === false)
444
-			) {
445
-				array_unshift($args, $tag[3]);
446
-				if ($reduit = call_user_func_array($filtre, $args)) {
447
-					// En cas de span spip_documents, modifier le style=...width:
448
-					if ($tag[1]) {
449
-						$w = extraire_attribut($reduit, 'width');
450
-						if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) {
451
-							$w = $regs[1];
452
-						}
453
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
454
-							$style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
455
-							$replace = inserer_attribut($tag[1], 'style', $style);
456
-							$texte = str_replace($tag[1], $replace, $texte);
457
-						}
458
-					}
459
-					// traiter aussi un eventuel mouseover
460
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
461
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
462
-							$srcover = $match[1];
463
-							array_shift($args);
464
-							array_unshift($args, "<img src='" . $match[1] . "' />");
465
-							$srcover_filter = call_user_func_array($filtre, $args);
466
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
467
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
468
-						}
469
-					}
470
-					$texte = str_replace($tag[3], $reduit, $texte);
471
-				}
472
-				array_shift($args);
473
-			}
474
-		}
475
-	}
476
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
477
-	return $texte;
413
+    $filtre = array_shift($args); # enlever $filtre
414
+    $texte = array_shift($args);
415
+    if (!strlen($texte)) {
416
+        return;
417
+    }
418
+    find_in_path('filtres_images_mini.php', 'inc/', true);
419
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
420
+    // Cas du nom de fichier local
421
+    if (strpos(substr($texte, strlen(_DIR_RACINE)), '..') === false
422
+        and !preg_match(',^/|[<>]|\s,S', $texte)
423
+        and (
424
+            file_exists(preg_replace(',[?].*$,', '', $texte))
425
+            or tester_url_absolue($texte)
426
+        )
427
+    ) {
428
+        array_unshift($args, "<img src='$texte' />");
429
+        $res = call_user_func_array($filtre, $args);
430
+        statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
431
+        return $res;
432
+    }
433
+
434
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
435
+    if (preg_match_all(
436
+        ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
437
+        $texte, $tags, PREG_SET_ORDER)) {
438
+        foreach ($tags as $tag) {
439
+            $class = extraire_attribut($tag[3], 'class');
440
+            if (!$class or
441
+                (strpos($class, 'filtre_inactif') === false
442
+                    // compat historique a virer en 3.2
443
+                    and strpos($class, 'no_image_filtrer') === false)
444
+            ) {
445
+                array_unshift($args, $tag[3]);
446
+                if ($reduit = call_user_func_array($filtre, $args)) {
447
+                    // En cas de span spip_documents, modifier le style=...width:
448
+                    if ($tag[1]) {
449
+                        $w = extraire_attribut($reduit, 'width');
450
+                        if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) {
451
+                            $w = $regs[1];
452
+                        }
453
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
454
+                            $style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
455
+                            $replace = inserer_attribut($tag[1], 'style', $style);
456
+                            $texte = str_replace($tag[1], $replace, $texte);
457
+                        }
458
+                    }
459
+                    // traiter aussi un eventuel mouseover
460
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
461
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
462
+                            $srcover = $match[1];
463
+                            array_shift($args);
464
+                            array_unshift($args, "<img src='" . $match[1] . "' />");
465
+                            $srcover_filter = call_user_func_array($filtre, $args);
466
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
467
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
468
+                        }
469
+                    }
470
+                    $texte = str_replace($tag[3], $reduit, $texte);
471
+                }
472
+                array_shift($args);
473
+            }
474
+        }
475
+    }
476
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
477
+    return $texte;
478 478
 }
479 479
 
480 480
 /**
@@ -489,65 +489,65 @@  discard block
 block discarded – undo
489 489
  **/
490 490
 function taille_image($img) {
491 491
 
492
-	static $largeur_img = array(), $hauteur_img = array();
493
-	$srcWidth = 0;
494
-	$srcHeight = 0;
495
-
496
-	$src = extraire_attribut($img, 'src');
497
-
498
-	if (!$src) {
499
-		$src = $img;
500
-	} else {
501
-		$srcWidth = extraire_attribut($img, 'width');
502
-		$srcHeight = extraire_attribut($img, 'height');
503
-	}
504
-
505
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
506
-	// la copie locale a toutes les chances d'etre la ou de resservir
507
-	if (tester_url_absolue($src)) {
508
-		include_spip('inc/distant');
509
-		$fichier = copie_locale($src);
510
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
511
-	}
512
-	if (($p = strpos($src, '?')) !== false) {
513
-		$src = substr($src, 0, $p);
514
-	}
515
-
516
-	$srcsize = false;
517
-	if (isset($largeur_img[$src])) {
518
-		$srcWidth = $largeur_img[$src];
519
-	}
520
-	if (isset($hauteur_img[$src])) {
521
-		$srcHeight = $hauteur_img[$src];
522
-	}
523
-	if (!$srcWidth or !$srcHeight) {
524
-
525
-		if (file_exists($src)
526
-			and $srcsize = spip_getimagesize($src)
527
-		) {
528
-			if (!$srcWidth) {
529
-				$largeur_img[$src] = $srcWidth = $srcsize[0];
530
-			}
531
-			if (!$srcHeight) {
532
-				$hauteur_img[$src] = $srcHeight = $srcsize[1];
533
-			}
534
-		}
535
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
536
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
537
-		elseif (@file_exists($f = "$src.src")
538
-			and lire_fichier($f, $valeurs)
539
-			and $valeurs = unserialize($valeurs)
540
-		) {
541
-			if (!$srcWidth) {
542
-				$largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"];
543
-			}
544
-			if (!$srcHeight) {
545
-				$hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"];
546
-			}
547
-		}
548
-	}
549
-
550
-	return array($srcHeight, $srcWidth);
492
+    static $largeur_img = array(), $hauteur_img = array();
493
+    $srcWidth = 0;
494
+    $srcHeight = 0;
495
+
496
+    $src = extraire_attribut($img, 'src');
497
+
498
+    if (!$src) {
499
+        $src = $img;
500
+    } else {
501
+        $srcWidth = extraire_attribut($img, 'width');
502
+        $srcHeight = extraire_attribut($img, 'height');
503
+    }
504
+
505
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
506
+    // la copie locale a toutes les chances d'etre la ou de resservir
507
+    if (tester_url_absolue($src)) {
508
+        include_spip('inc/distant');
509
+        $fichier = copie_locale($src);
510
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
511
+    }
512
+    if (($p = strpos($src, '?')) !== false) {
513
+        $src = substr($src, 0, $p);
514
+    }
515
+
516
+    $srcsize = false;
517
+    if (isset($largeur_img[$src])) {
518
+        $srcWidth = $largeur_img[$src];
519
+    }
520
+    if (isset($hauteur_img[$src])) {
521
+        $srcHeight = $hauteur_img[$src];
522
+    }
523
+    if (!$srcWidth or !$srcHeight) {
524
+
525
+        if (file_exists($src)
526
+            and $srcsize = spip_getimagesize($src)
527
+        ) {
528
+            if (!$srcWidth) {
529
+                $largeur_img[$src] = $srcWidth = $srcsize[0];
530
+            }
531
+            if (!$srcHeight) {
532
+                $hauteur_img[$src] = $srcHeight = $srcsize[1];
533
+            }
534
+        }
535
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
536
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
537
+        elseif (@file_exists($f = "$src.src")
538
+            and lire_fichier($f, $valeurs)
539
+            and $valeurs = unserialize($valeurs)
540
+        ) {
541
+            if (!$srcWidth) {
542
+                $largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"];
543
+            }
544
+            if (!$srcHeight) {
545
+                $hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"];
546
+            }
547
+        }
548
+    }
549
+
550
+    return array($srcHeight, $srcWidth);
551 551
 }
552 552
 
553 553
 
@@ -565,12 +565,12 @@  discard block
 block discarded – undo
565 565
  *     Largeur en pixels, NULL ou 0 si aucune image.
566 566
  **/
567 567
 function largeur($img) {
568
-	if (!$img) {
569
-		return;
570
-	}
571
-	list($h, $l) = taille_image($img);
568
+    if (!$img) {
569
+        return;
570
+    }
571
+    list($h, $l) = taille_image($img);
572 572
 
573
-	return $l;
573
+    return $l;
574 574
 }
575 575
 
576 576
 /**
@@ -587,12 +587,12 @@  discard block
 block discarded – undo
587 587
  *     Hauteur en pixels, NULL ou 0 si aucune image.
588 588
  **/
589 589
 function hauteur($img) {
590
-	if (!$img) {
591
-		return;
592
-	}
593
-	list($h, $l) = taille_image($img);
590
+    if (!$img) {
591
+        return;
592
+    }
593
+    list($h, $l) = taille_image($img);
594 594
 
595
-	return $h;
595
+    return $h;
596 596
 }
597 597
 
598 598
 
@@ -612,11 +612,11 @@  discard block
 block discarded – undo
612 612
  * @return string
613 613
  **/
614 614
 function corriger_entites_html($texte) {
615
-	if (strpos($texte, '&amp;') === false) {
616
-		return $texte;
617
-	}
615
+    if (strpos($texte, '&amp;') === false) {
616
+        return $texte;
617
+    }
618 618
 
619
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
619
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
620 620
 }
621 621
 
622 622
 /**
@@ -631,11 +631,11 @@  discard block
 block discarded – undo
631 631
  * @return string
632 632
  **/
633 633
 function corriger_toutes_entites_html($texte) {
634
-	if (strpos($texte, '&amp;') === false) {
635
-		return $texte;
636
-	}
634
+    if (strpos($texte, '&amp;') === false) {
635
+        return $texte;
636
+    }
637 637
 
638
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
638
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
639 639
 }
640 640
 
641 641
 /**
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
  * @return string
646 646
  **/
647 647
 function proteger_amp($texte) {
648
-	return str_replace('&', '&amp;', $texte);
648
+    return str_replace('&', '&amp;', $texte);
649 649
 }
650 650
 
651 651
 
@@ -676,20 +676,20 @@  discard block
 block discarded – undo
676 676
  * @return mixed|string
677 677
  */
678 678
 function entites_html($texte, $tout = false, $quote = true) {
679
-	if (!is_string($texte) or !$texte
680
-		or strpbrk($texte, "&\"'<>") == false
681
-	) {
682
-		return $texte;
683
-	}
684
-	include_spip('inc/texte');
685
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
686
-	$flags |= ENT_HTML401;
687
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
688
-	if ($tout) {
689
-		return corriger_toutes_entites_html($texte);
690
-	} else {
691
-		return corriger_entites_html($texte);
692
-	}
679
+    if (!is_string($texte) or !$texte
680
+        or strpbrk($texte, "&\"'<>") == false
681
+    ) {
682
+        return $texte;
683
+    }
684
+    include_spip('inc/texte');
685
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
686
+    $flags |= ENT_HTML401;
687
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
688
+    if ($tout) {
689
+        return corriger_toutes_entites_html($texte);
690
+    } else {
691
+        return corriger_entites_html($texte);
692
+    }
693 693
 }
694 694
 
695 695
 /**
@@ -708,37 +708,37 @@  discard block
 block discarded – undo
708 708
  *     Texte converti
709 709
  **/
710 710
 function filtrer_entites($texte) {
711
-	if (strpos($texte, '&') === false) {
712
-		return $texte;
713
-	}
714
-	// filtrer
715
-	$texte = html2unicode($texte);
716
-	// remettre le tout dans le charset cible
717
-	$texte = unicode2charset($texte);
718
-	// cas particulier des " et ' qu'il faut filtrer aussi
719
-	// (on le faisait deja avec un &quot;)
720
-	if (strpos($texte, "&#") !== false) {
721
-		$texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
722
-	}
711
+    if (strpos($texte, '&') === false) {
712
+        return $texte;
713
+    }
714
+    // filtrer
715
+    $texte = html2unicode($texte);
716
+    // remettre le tout dans le charset cible
717
+    $texte = unicode2charset($texte);
718
+    // cas particulier des " et ' qu'il faut filtrer aussi
719
+    // (on le faisait deja avec un &quot;)
720
+    if (strpos($texte, "&#") !== false) {
721
+        $texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
722
+    }
723 723
 
724
-	return $texte;
724
+    return $texte;
725 725
 }
726 726
 
727 727
 
728 728
 if (!function_exists('filtre_filtrer_entites_dist')) {
729
-	/**
730
-	 * Version sécurisée de filtrer_entites
731
-	 * 
732
-	 * @uses interdire_scripts()
733
-	 * @uses filtrer_entites()
734
-	 * 
735
-	 * @param string $t
736
-	 * @return string
737
-	 */
738
-	function filtre_filtrer_entites_dist($t) {
739
-		include_spip('inc/texte');
740
-		return interdire_scripts(filtrer_entites($t));
741
-	}
729
+    /**
730
+     * Version sécurisée de filtrer_entites
731
+     * 
732
+     * @uses interdire_scripts()
733
+     * @uses filtrer_entites()
734
+     * 
735
+     * @param string $t
736
+     * @return string
737
+     */
738
+    function filtre_filtrer_entites_dist($t) {
739
+        include_spip('inc/texte');
740
+        return interdire_scripts(filtrer_entites($t));
741
+    }
742 742
 }
743 743
 
744 744
 
@@ -753,18 +753,18 @@  discard block
 block discarded – undo
753 753
  * @return string|array
754 754
  **/
755 755
 function supprimer_caracteres_illegaux($texte) {
756
-	static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
757
-	static $to = null;
756
+    static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
757
+    static $to = null;
758 758
 
759
-	if (is_array($texte)) {
760
-		return array_map('supprimer_caracteres_illegaux', $texte);
761
-	}
759
+    if (is_array($texte)) {
760
+        return array_map('supprimer_caracteres_illegaux', $texte);
761
+    }
762 762
 
763
-	if (!$to) {
764
-		$to = str_repeat('-', strlen($from));
765
-	}
763
+    if (!$to) {
764
+        $to = str_repeat('-', strlen($from));
765
+    }
766 766
 
767
-	return strtr($texte, $from, $to);
767
+    return strtr($texte, $from, $to);
768 768
 }
769 769
 
770 770
 /**
@@ -776,10 +776,10 @@  discard block
 block discarded – undo
776 776
  * @return string|array
777 777
  **/
778 778
 function corriger_caracteres($texte) {
779
-	$texte = corriger_caracteres_windows($texte);
780
-	$texte = supprimer_caracteres_illegaux($texte);
779
+    $texte = corriger_caracteres_windows($texte);
780
+    $texte = supprimer_caracteres_illegaux($texte);
781 781
 
782
-	return $texte;
782
+    return $texte;
783 783
 }
784 784
 
785 785
 /**
@@ -797,40 +797,40 @@  discard block
 block discarded – undo
797 797
  */
798 798
 function texte_backend($texte) {
799 799
 
800
-	static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
800
+    static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
801 801
 
802
-	// si on a des liens ou des images, les passer en absolu
803
-	$texte = liens_absolus($texte);
802
+    // si on a des liens ou des images, les passer en absolu
803
+    $texte = liens_absolus($texte);
804 804
 
805
-	// echapper les tags &gt; &lt;
806
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
805
+    // echapper les tags &gt; &lt;
806
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
807 807
 
808
-	// importer les &eacute;
809
-	$texte = filtrer_entites($texte);
808
+    // importer les &eacute;
809
+    $texte = filtrer_entites($texte);
810 810
 
811
-	// " -> &quot; et tout ce genre de choses
812
-	$u = $GLOBALS['meta']['pcre_u'];
813
-	$texte = str_replace("&nbsp;", " ", $texte);
814
-	$texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
815
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
816
-	$texte = entites_html($texte, false, false);
817
-	// mais bien echapper les double quotes !
818
-	$texte = str_replace('"', '&#034;', $texte);
811
+    // " -> &quot; et tout ce genre de choses
812
+    $u = $GLOBALS['meta']['pcre_u'];
813
+    $texte = str_replace("&nbsp;", " ", $texte);
814
+    $texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
815
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
816
+    $texte = entites_html($texte, false, false);
817
+    // mais bien echapper les double quotes !
818
+    $texte = str_replace('"', '&#034;', $texte);
819 819
 
820
-	// verifier le charset
821
-	$texte = charset2unicode($texte);
820
+    // verifier le charset
821
+    $texte = charset2unicode($texte);
822 822
 
823
-	// Caracteres problematiques en iso-latin 1
824
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
825
-		$texte = str_replace(chr(156), '&#156;', $texte);
826
-		$texte = str_replace(chr(140), '&#140;', $texte);
827
-		$texte = str_replace(chr(159), '&#159;', $texte);
828
-	}
823
+    // Caracteres problematiques en iso-latin 1
824
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
825
+        $texte = str_replace(chr(156), '&#156;', $texte);
826
+        $texte = str_replace(chr(140), '&#140;', $texte);
827
+        $texte = str_replace(chr(159), '&#159;', $texte);
828
+    }
829 829
 
830
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
831
-	// et le caractere apostrophe alourdit les squelettes avec PHP
832
-	// ==> on les remplace par l'entite HTML
833
-	return str_replace($apostrophe, "'", $texte);
830
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
831
+    // et le caractere apostrophe alourdit les squelettes avec PHP
832
+    // ==> on les remplace par l'entite HTML
833
+    return str_replace($apostrophe, "'", $texte);
834 834
 }
835 835
 
836 836
 /**
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
  *     Texte encodé et quote pour XML
848 848
  */
849 849
 function texte_backendq($texte) {
850
-	return addslashes(texte_backend($texte));
850
+    return addslashes(texte_backend($texte));
851 851
 }
852 852
 
853 853
 
@@ -870,9 +870,9 @@  discard block
 block discarded – undo
870 870
  *     Numéro de titre, sinon chaîne vide
871 871
  **/
872 872
 function supprimer_numero($texte) {
873
-	return preg_replace(
874
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
875
-		"", $texte);
873
+    return preg_replace(
874
+        ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
875
+        "", $texte);
876 876
 }
877 877
 
878 878
 /**
@@ -895,13 +895,13 @@  discard block
 block discarded – undo
895 895
  *     Numéro de titre, sinon chaîne vide
896 896
  **/
897 897
 function recuperer_numero($texte) {
898
-	if (preg_match(
899
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
900
-		$texte, $regs)) {
901
-		return strval($regs[1]);
902
-	} else {
903
-		return '';
904
-	}
898
+    if (preg_match(
899
+        ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
900
+        $texte, $regs)) {
901
+        return strval($regs[1]);
902
+    } else {
903
+        return '';
904
+    }
905 905
 }
906 906
 
907 907
 /**
@@ -928,13 +928,13 @@  discard block
 block discarded – undo
928 928
  *     Texte converti
929 929
  **/
930 930
 function supprimer_tags($texte, $rempl = "") {
931
-	$texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte);
932
-	// ne pas oublier un < final non ferme car coupe
933
-	$texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte);
934
-	// mais qui peut aussi etre un simple signe plus petit que
935
-	$texte = str_replace('<', '&lt;', $texte);
931
+    $texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte);
932
+    // ne pas oublier un < final non ferme car coupe
933
+    $texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte);
934
+    // mais qui peut aussi etre un simple signe plus petit que
935
+    $texte = str_replace('<', '&lt;', $texte);
936 936
 
937
-	return $texte;
937
+    return $texte;
938 938
 }
939 939
 
940 940
 /**
@@ -957,9 +957,9 @@  discard block
 block discarded – undo
957 957
  *     Texte converti
958 958
  **/
959 959
 function echapper_tags($texte, $rempl = "") {
960
-	$texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
960
+    $texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
961 961
 
962
-	return $texte;
962
+    return $texte;
963 963
 }
964 964
 
965 965
 /**
@@ -980,18 +980,18 @@  discard block
 block discarded – undo
980 980
  *     Texte converti
981 981
  **/
982 982
 function textebrut($texte) {
983
-	$u = $GLOBALS['meta']['pcre_u'];
984
-	$texte = preg_replace('/\s+/S' . $u, " ", $texte);
985
-	$texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
986
-	$texte = preg_replace("/^\n+/", "", $texte);
987
-	$texte = preg_replace("/\n+$/", "", $texte);
988
-	$texte = preg_replace("/\n +/", "\n", $texte);
989
-	$texte = supprimer_tags($texte);
990
-	$texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
991
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
992
-	$texte = str_replace("&#8217;", "'", $texte);
983
+    $u = $GLOBALS['meta']['pcre_u'];
984
+    $texte = preg_replace('/\s+/S' . $u, " ", $texte);
985
+    $texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
986
+    $texte = preg_replace("/^\n+/", "", $texte);
987
+    $texte = preg_replace("/\n+$/", "", $texte);
988
+    $texte = preg_replace("/\n +/", "\n", $texte);
989
+    $texte = supprimer_tags($texte);
990
+    $texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
991
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
992
+    $texte = str_replace("&#8217;", "'", $texte);
993 993
 
994
-	return $texte;
994
+    return $texte;
995 995
 }
996 996
 
997 997
 
@@ -1007,17 +1007,17 @@  discard block
 block discarded – undo
1007 1007
  *     Texte avec liens ouvrants
1008 1008
  **/
1009 1009
 function liens_ouvrants($texte) {
1010
-	if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1011
-		$texte, $liens, PREG_PATTERN_ORDER)) {
1012
-		foreach ($liens[0] as $a) {
1013
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1014
-			$ablank = inserer_attribut($a, 'rel', $rel);
1015
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1016
-			$texte = str_replace($a, $ablank, $texte);
1017
-		}
1018
-	}
1010
+    if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1011
+        $texte, $liens, PREG_PATTERN_ORDER)) {
1012
+        foreach ($liens[0] as $a) {
1013
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1014
+            $ablank = inserer_attribut($a, 'rel', $rel);
1015
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1016
+            $texte = str_replace($a, $ablank, $texte);
1017
+        }
1018
+    }
1019 1019
 
1020
-	return $texte;
1020
+    return $texte;
1021 1021
 }
1022 1022
 
1023 1023
 /**
@@ -1027,22 +1027,22 @@  discard block
 block discarded – undo
1027 1027
  * @return string
1028 1028
  */
1029 1029
 function liens_nofollow($texte) {
1030
-	if (stripos($texte, "<a") === false) {
1031
-		return $texte;
1032
-	}
1030
+    if (stripos($texte, "<a") === false) {
1031
+        return $texte;
1032
+    }
1033 1033
 
1034
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1035
-		foreach ($regs[0] as $a) {
1036
-			$rel = extraire_attribut($a, "rel");
1037
-			if (strpos($rel, "nofollow") === false) {
1038
-				$rel = "nofollow" . ($rel ? " $rel" : "");
1039
-				$anofollow = inserer_attribut($a, "rel", $rel);
1040
-				$texte = str_replace($a, $anofollow, $texte);
1041
-			}
1042
-		}
1043
-	}
1034
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1035
+        foreach ($regs[0] as $a) {
1036
+            $rel = extraire_attribut($a, "rel");
1037
+            if (strpos($rel, "nofollow") === false) {
1038
+                $rel = "nofollow" . ($rel ? " $rel" : "");
1039
+                $anofollow = inserer_attribut($a, "rel", $rel);
1040
+                $texte = str_replace($a, $anofollow, $texte);
1041
+            }
1042
+        }
1043
+    }
1044 1044
 
1045
-	return $texte;
1045
+    return $texte;
1046 1046
 }
1047 1047
 
1048 1048
 /**
@@ -1061,12 +1061,12 @@  discard block
 block discarded – undo
1061 1061
  *     Texte sans paraghaphes
1062 1062
  **/
1063 1063
 function PtoBR($texte) {
1064
-	$u = $GLOBALS['meta']['pcre_u'];
1065
-	$texte = preg_replace("@</p>@iS", "\n", $texte);
1066
-	$texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1067
-	$texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1064
+    $u = $GLOBALS['meta']['pcre_u'];
1065
+    $texte = preg_replace("@</p>@iS", "\n", $texte);
1066
+    $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1067
+    $texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1068 1068
 
1069
-	return $texte;
1069
+    return $texte;
1070 1070
 }
1071 1071
 
1072 1072
 
@@ -1090,14 +1090,14 @@  discard block
 block discarded – undo
1090 1090
  * @return string Texte encadré du style CSS
1091 1091
  */
1092 1092
 function lignes_longues($texte) {
1093
-	if (!strlen(trim($texte))) {
1094
-		return $texte;
1095
-	}
1096
-	include_spip('inc/texte');
1097
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1098
-		'div' : 'span';
1093
+    if (!strlen(trim($texte))) {
1094
+        return $texte;
1095
+    }
1096
+    include_spip('inc/texte');
1097
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1098
+        'div' : 'span';
1099 1099
 
1100
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1100
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1101 1101
 }
1102 1102
 
1103 1103
 /**
@@ -1116,30 +1116,30 @@  discard block
 block discarded – undo
1116 1116
  * @return string Texte en majuscule
1117 1117
  */
1118 1118
 function majuscules($texte) {
1119
-	if (!strlen($texte)) {
1120
-		return '';
1121
-	}
1119
+    if (!strlen($texte)) {
1120
+        return '';
1121
+    }
1122 1122
 
1123
-	// Cas du turc
1124
-	if ($GLOBALS['spip_lang'] == 'tr') {
1125
-		# remplacer hors des tags et des entites
1126
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1127
-			foreach ($regs as $n => $match) {
1128
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1129
-			}
1130
-		}
1123
+    // Cas du turc
1124
+    if ($GLOBALS['spip_lang'] == 'tr') {
1125
+        # remplacer hors des tags et des entites
1126
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1127
+            foreach ($regs as $n => $match) {
1128
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1129
+            }
1130
+        }
1131 1131
 
1132
-		$texte = str_replace('i', '&#304;', $texte);
1132
+        $texte = str_replace('i', '&#304;', $texte);
1133 1133
 
1134
-		if ($regs) {
1135
-			foreach ($regs as $n => $match) {
1136
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1137
-			}
1138
-		}
1139
-	}
1134
+        if ($regs) {
1135
+            foreach ($regs as $n => $match) {
1136
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1137
+            }
1138
+        }
1139
+    }
1140 1140
 
1141
-	// Cas general
1142
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1141
+    // Cas general
1142
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1143 1143
 }
1144 1144
 
1145 1145
 /**
@@ -1157,29 +1157,29 @@  discard block
 block discarded – undo
1157 1157
  * @return string
1158 1158
  **/
1159 1159
 function taille_en_octets($taille) {
1160
-	if (!defined('_KILOBYTE')) {
1161
-		/**
1162
-		 * Définit le nombre d'octets dans un Kilobyte
1163
-		 *
1164
-		 * @var int
1165
-		 **/
1166
-		define('_KILOBYTE', 1024);
1167
-	}
1160
+    if (!defined('_KILOBYTE')) {
1161
+        /**
1162
+         * Définit le nombre d'octets dans un Kilobyte
1163
+         *
1164
+         * @var int
1165
+         **/
1166
+        define('_KILOBYTE', 1024);
1167
+    }
1168 1168
 
1169
-	if ($taille < 1) {
1170
-		return '';
1171
-	}
1172
-	if ($taille < _KILOBYTE) {
1173
-		$taille = _T('taille_octets', array('taille' => $taille));
1174
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1175
-		$taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1)));
1176
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1177
-		$taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)));
1178
-	} else {
1179
-		$taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)));
1180
-	}
1169
+    if ($taille < 1) {
1170
+        return '';
1171
+    }
1172
+    if ($taille < _KILOBYTE) {
1173
+        $taille = _T('taille_octets', array('taille' => $taille));
1174
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1175
+        $taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1)));
1176
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1177
+        $taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)));
1178
+    } else {
1179
+        $taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)));
1180
+    }
1181 1181
 
1182
-	return $taille;
1182
+    return $taille;
1183 1183
 }
1184 1184
 
1185 1185
 
@@ -1201,15 +1201,15 @@  discard block
 block discarded – undo
1201 1201
  *     Texte prêt pour être utilisé en attribut HTML
1202 1202
  **/
1203 1203
 function attribut_html($texte, $textebrut = true) {
1204
-	$u = $GLOBALS['meta']['pcre_u'];
1205
-	if ($textebrut) {
1206
-		$texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1207
-	}
1208
-	$texte = texte_backend($texte);
1209
-	$texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
1204
+    $u = $GLOBALS['meta']['pcre_u'];
1205
+    if ($textebrut) {
1206
+        $texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1207
+    }
1208
+    $texte = texte_backend($texte);
1209
+    $texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
1210 1210
 
1211
-	return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"),
1212
-		$texte);
1211
+    return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"),
1212
+        $texte);
1213 1213
 }
1214 1214
 
1215 1215
 
@@ -1229,12 +1229,12 @@  discard block
 block discarded – undo
1229 1229
  *     URL ou chaîne vide
1230 1230
  **/
1231 1231
 function vider_url($url, $entites = true) {
1232
-	# un message pour abs_url
1233
-	$GLOBALS['mode_abs_url'] = 'url';
1234
-	$url = trim($url);
1235
-	$r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1232
+    # un message pour abs_url
1233
+    $GLOBALS['mode_abs_url'] = 'url';
1234
+    $url = trim($url);
1235
+    $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1236 1236
 
1237
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1237
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1238 1238
 }
1239 1239
 
1240 1240
 
@@ -1249,10 +1249,10 @@  discard block
 block discarded – undo
1249 1249
  * @return string Adresse email maquillée
1250 1250
  **/
1251 1251
 function antispam($texte) {
1252
-	include_spip('inc/acces');
1253
-	$masque = creer_pass_aleatoire(3);
1252
+    include_spip('inc/acces');
1253
+    $masque = creer_pass_aleatoire(3);
1254 1254
 
1255
-	return preg_replace("/@/", " $masque ", $texte);
1255
+    return preg_replace("/@/", " $masque ", $texte);
1256 1256
 }
1257 1257
 
1258 1258
 /**
@@ -1284,12 +1284,12 @@  discard block
 block discarded – undo
1284 1284
  *     True si on a le droit d'accès, false sinon.
1285 1285
  **/
1286 1286
 function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') {
1287
-	include_spip('inc/acces');
1288
-	if ($op) {
1289
-		$dir .= " $op $args";
1290
-	}
1287
+    include_spip('inc/acces');
1288
+    if ($op) {
1289
+        $dir .= " $op $args";
1290
+    }
1291 1291
 
1292
-	return verifier_low_sec($id_auteur, $cle, $dir);
1292
+    return verifier_low_sec($id_auteur, $cle, $dir);
1293 1293
 }
1294 1294
 
1295 1295
 /**
@@ -1314,11 +1314,11 @@  discard block
 block discarded – undo
1314 1314
  *     Retourne $texte, sinon $sinon.
1315 1315
  **/
1316 1316
 function sinon($texte, $sinon = '') {
1317
-	if ($texte or (!is_array($texte) and strlen($texte))) {
1318
-		return $texte;
1319
-	} else {
1320
-		return $sinon;
1321
-	}
1317
+    if ($texte or (!is_array($texte) and strlen($texte))) {
1318
+        return $texte;
1319
+    } else {
1320
+        return $sinon;
1321
+    }
1322 1322
 }
1323 1323
 
1324 1324
 /**
@@ -1342,7 +1342,7 @@  discard block
 block discarded – undo
1342 1342
  * @return mixed
1343 1343
  **/
1344 1344
 function choixsivide($a, $vide, $pasvide) {
1345
-	return $a ? $pasvide : $vide;
1345
+    return $a ? $pasvide : $vide;
1346 1346
 }
1347 1347
 
1348 1348
 /**
@@ -1366,7 +1366,7 @@  discard block
 block discarded – undo
1366 1366
  * @return mixed
1367 1367
  **/
1368 1368
 function choixsiegal($a1, $a2, $v, $f) {
1369
-	return ($a1 == $a2) ? $v : $f;
1369
+    return ($a1 == $a2) ? $v : $f;
1370 1370
 }
1371 1371
 
1372 1372
 //
@@ -1385,13 +1385,13 @@  discard block
 block discarded – undo
1385 1385
  * @return string
1386 1386
  **/
1387 1387
 function filtrer_ical($texte) {
1388
-	#include_spip('inc/charsets');
1389
-	$texte = html2unicode($texte);
1390
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1391
-	$texte = preg_replace("/\n/", " ", $texte);
1392
-	$texte = preg_replace("/,/", "\,", $texte);
1388
+    #include_spip('inc/charsets');
1389
+    $texte = html2unicode($texte);
1390
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1391
+    $texte = preg_replace("/\n/", " ", $texte);
1392
+    $texte = preg_replace("/,/", "\,", $texte);
1393 1393
 
1394
-	return $texte;
1394
+    return $texte;
1395 1395
 }
1396 1396
 
1397 1397
 
@@ -1416,53 +1416,53 @@  discard block
 block discarded – undo
1416 1416
  * @return string
1417 1417
  **/
1418 1418
 function post_autobr($texte, $delim = "\n_ ") {
1419
-	if (!function_exists('echappe_html')) {
1420
-		include_spip('inc/texte_mini');
1421
-	}
1422
-	$texte = str_replace("\r\n", "\r", $texte);
1423
-	$texte = str_replace("\r", "\n", $texte);
1424
-
1425
-	if (preg_match(",\n+$,", $texte, $fin)) {
1426
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1427
-	} else {
1428
-		$fin = '';
1429
-	}
1430
-
1431
-	$texte = echappe_html($texte, '', true);
1432
-
1433
-	// echapper les modeles
1434
-	if (strpos($texte, "<") !== false) {
1435
-		include_spip('inc/lien');
1436
-		if (defined('_PREG_MODELE')) {
1437
-			$preg_modeles = "@" . _PREG_MODELE . "@imsS";
1438
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1439
-		}
1440
-	}
1441
-
1442
-	$debut = '';
1443
-	$suite = $texte;
1444
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1445
-		$debut .= substr($suite, 0, $t - 1);
1446
-		$suite = substr($suite, $t);
1447
-		$car = substr($suite, 0, 1);
1448
-		if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}")
1449
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1450
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1451
-		) {
1452
-			$debut .= $delim;
1453
-		} else {
1454
-			$debut .= "\n";
1455
-		}
1456
-		if (preg_match(",^\n+,", $suite, $regs)) {
1457
-			$debut .= $regs[0];
1458
-			$suite = substr($suite, strlen($regs[0]));
1459
-		}
1460
-	}
1461
-	$texte = $debut . $suite;
1462
-
1463
-	$texte = echappe_retour($texte);
1464
-
1465
-	return $texte . $fin;
1419
+    if (!function_exists('echappe_html')) {
1420
+        include_spip('inc/texte_mini');
1421
+    }
1422
+    $texte = str_replace("\r\n", "\r", $texte);
1423
+    $texte = str_replace("\r", "\n", $texte);
1424
+
1425
+    if (preg_match(",\n+$,", $texte, $fin)) {
1426
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1427
+    } else {
1428
+        $fin = '';
1429
+    }
1430
+
1431
+    $texte = echappe_html($texte, '', true);
1432
+
1433
+    // echapper les modeles
1434
+    if (strpos($texte, "<") !== false) {
1435
+        include_spip('inc/lien');
1436
+        if (defined('_PREG_MODELE')) {
1437
+            $preg_modeles = "@" . _PREG_MODELE . "@imsS";
1438
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1439
+        }
1440
+    }
1441
+
1442
+    $debut = '';
1443
+    $suite = $texte;
1444
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1445
+        $debut .= substr($suite, 0, $t - 1);
1446
+        $suite = substr($suite, $t);
1447
+        $car = substr($suite, 0, 1);
1448
+        if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}")
1449
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1450
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1451
+        ) {
1452
+            $debut .= $delim;
1453
+        } else {
1454
+            $debut .= "\n";
1455
+        }
1456
+        if (preg_match(",^\n+,", $suite, $regs)) {
1457
+            $debut .= $regs[0];
1458
+            $suite = substr($suite, strlen($regs[0]));
1459
+        }
1460
+    }
1461
+    $texte = $debut . $suite;
1462
+
1463
+    $texte = echappe_retour($texte);
1464
+
1465
+    return $texte . $fin;
1466 1466
 }
1467 1467
 
1468 1468
 
@@ -1503,46 +1503,46 @@  discard block
 block discarded – undo
1503 1503
  * @return string
1504 1504
  **/
1505 1505
 function extraire_idiome($letexte, $lang = null, $options = array()) {
1506
-	static $traduire = false;
1507
-	if ($letexte
1508
-		and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1509
-	) {
1510
-		if (!$traduire) {
1511
-			$traduire = charger_fonction('traduire', 'inc');
1512
-			include_spip('inc/lang');
1513
-		}
1514
-		if (!$lang) {
1515
-			$lang = $GLOBALS['spip_lang'];
1516
-		}
1517
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1518
-		if (is_bool($options)) {
1519
-			$options = array('echappe_span' => $options);
1520
-		}
1521
-		if (!isset($options['echappe_span'])) {
1522
-			$options = array_merge($options, array('echappe_span' => false));
1523
-		}
1524
-
1525
-		foreach ($regs as $reg) {
1526
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1527
-			$desc = $traduire($cle, $lang, true);
1528
-			$l = $desc->langue;
1529
-			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1530
-			if (strlen($desc->texte)) {
1531
-				$trad = code_echappement($desc->texte, 'idiome', false);
1532
-				if ($l !== $lang) {
1533
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1534
-				}
1535
-				if (lang_dir($l) !== lang_dir($lang)) {
1536
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1537
-				}
1538
-				if (!$options['echappe_span']) {
1539
-					$trad = echappe_retour($trad, 'idiome');
1540
-				}
1541
-				$letexte = str_replace($reg[0], $trad, $letexte);
1542
-			}
1543
-		}
1544
-	}
1545
-	return $letexte;
1506
+    static $traduire = false;
1507
+    if ($letexte
1508
+        and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1509
+    ) {
1510
+        if (!$traduire) {
1511
+            $traduire = charger_fonction('traduire', 'inc');
1512
+            include_spip('inc/lang');
1513
+        }
1514
+        if (!$lang) {
1515
+            $lang = $GLOBALS['spip_lang'];
1516
+        }
1517
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1518
+        if (is_bool($options)) {
1519
+            $options = array('echappe_span' => $options);
1520
+        }
1521
+        if (!isset($options['echappe_span'])) {
1522
+            $options = array_merge($options, array('echappe_span' => false));
1523
+        }
1524
+
1525
+        foreach ($regs as $reg) {
1526
+            $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1527
+            $desc = $traduire($cle, $lang, true);
1528
+            $l = $desc->langue;
1529
+            // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1530
+            if (strlen($desc->texte)) {
1531
+                $trad = code_echappement($desc->texte, 'idiome', false);
1532
+                if ($l !== $lang) {
1533
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1534
+                }
1535
+                if (lang_dir($l) !== lang_dir($lang)) {
1536
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1537
+                }
1538
+                if (!$options['echappe_span']) {
1539
+                    $trad = echappe_retour($trad, 'idiome');
1540
+                }
1541
+                $letexte = str_replace($reg[0], $trad, $letexte);
1542
+            }
1543
+        }
1544
+    }
1545
+    return $letexte;
1546 1546
 }
1547 1547
 
1548 1548
 /**
@@ -1594,64 +1594,64 @@  discard block
 block discarded – undo
1594 1594
  **/
1595 1595
 function extraire_multi($letexte, $lang = null, $options = array()) {
1596 1596
 
1597
-	if ($letexte
1598
-		and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1599
-	) {
1600
-		if (!$lang) {
1601
-			$lang = $GLOBALS['spip_lang'];
1602
-		}
1603
-
1604
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1605
-		if (is_bool($options)) {
1606
-			$options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
1607
-		}
1608
-		if (!isset($options['echappe_span'])) {
1609
-			$options = array_merge($options, array('echappe_span' => false));
1610
-		}
1611
-		if (!isset($options['lang_defaut'])) {
1612
-			$options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
1613
-		}
1614
-
1615
-		include_spip('inc/lang');
1616
-		foreach ($regs as $reg) {
1617
-			// chercher la version de la langue courante
1618
-			$trads = extraire_trads($reg[1]);
1619
-			if ($l = approcher_langue($trads, $lang)) {
1620
-				$trad = $trads[$l];
1621
-			} else {
1622
-				if ($options['lang_defaut'] == 'aucune') {
1623
-					$trad = '';
1624
-				} else {
1625
-					// langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1626
-					// ou la premiere dispo
1627
-					// mais typographier le texte selon les regles de celle-ci
1628
-					// Attention aux blocs multi sur plusieurs lignes
1629
-					if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1630
-						$l = key($trads);
1631
-					}
1632
-					$trad = $trads[$l];
1633
-					$typographie = charger_fonction(lang_typo($l), 'typographie');
1634
-					$trad = $typographie($trad);
1635
-					// Tester si on echappe en span ou en div
1636
-					// il ne faut pas echapper en div si propre produit un seul paragraphe
1637
-					include_spip('inc/texte');
1638
-					$trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1639
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1640
-					$trad = code_echappement($trad, 'multi', false, $mode);
1641
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1642
-					if (lang_dir($l) !== lang_dir($lang)) {
1643
-						$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1644
-					}
1645
-					if (!$options['echappe_span']) {
1646
-						$trad = echappe_retour($trad, 'multi');
1647
-					}
1648
-				}
1649
-			}
1650
-			$letexte = str_replace($reg[0], $trad, $letexte);
1651
-		}
1652
-	}
1653
-
1654
-	return $letexte;
1597
+    if ($letexte
1598
+        and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1599
+    ) {
1600
+        if (!$lang) {
1601
+            $lang = $GLOBALS['spip_lang'];
1602
+        }
1603
+
1604
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1605
+        if (is_bool($options)) {
1606
+            $options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
1607
+        }
1608
+        if (!isset($options['echappe_span'])) {
1609
+            $options = array_merge($options, array('echappe_span' => false));
1610
+        }
1611
+        if (!isset($options['lang_defaut'])) {
1612
+            $options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
1613
+        }
1614
+
1615
+        include_spip('inc/lang');
1616
+        foreach ($regs as $reg) {
1617
+            // chercher la version de la langue courante
1618
+            $trads = extraire_trads($reg[1]);
1619
+            if ($l = approcher_langue($trads, $lang)) {
1620
+                $trad = $trads[$l];
1621
+            } else {
1622
+                if ($options['lang_defaut'] == 'aucune') {
1623
+                    $trad = '';
1624
+                } else {
1625
+                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1626
+                    // ou la premiere dispo
1627
+                    // mais typographier le texte selon les regles de celle-ci
1628
+                    // Attention aux blocs multi sur plusieurs lignes
1629
+                    if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1630
+                        $l = key($trads);
1631
+                    }
1632
+                    $trad = $trads[$l];
1633
+                    $typographie = charger_fonction(lang_typo($l), 'typographie');
1634
+                    $trad = $typographie($trad);
1635
+                    // Tester si on echappe en span ou en div
1636
+                    // il ne faut pas echapper en div si propre produit un seul paragraphe
1637
+                    include_spip('inc/texte');
1638
+                    $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1639
+                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1640
+                    $trad = code_echappement($trad, 'multi', false, $mode);
1641
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1642
+                    if (lang_dir($l) !== lang_dir($lang)) {
1643
+                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1644
+                    }
1645
+                    if (!$options['echappe_span']) {
1646
+                        $trad = echappe_retour($trad, 'multi');
1647
+                    }
1648
+                }
1649
+            }
1650
+            $letexte = str_replace($reg[0], $trad, $letexte);
1651
+        }
1652
+    }
1653
+
1654
+    return $letexte;
1655 1655
 }
1656 1656
 
1657 1657
 /**
@@ -1667,20 +1667,20 @@  discard block
 block discarded – undo
1667 1667
  *     Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué.
1668 1668
  **/
1669 1669
 function extraire_trads($bloc) {
1670
-	$lang = '';
1670
+    $lang = '';
1671 1671
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1672 1672
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1673
-	while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1674
-		$texte = trim($regs[1]);
1675
-		if ($texte or $lang) {
1676
-			$trads[$lang] = $texte;
1677
-		}
1678
-		$bloc = substr($bloc, strlen($regs[0]));
1679
-		$lang = $regs[2];
1680
-	}
1681
-	$trads[$lang] = $bloc;
1673
+    while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1674
+        $texte = trim($regs[1]);
1675
+        if ($texte or $lang) {
1676
+            $trads[$lang] = $texte;
1677
+        }
1678
+        $bloc = substr($bloc, strlen($regs[0]));
1679
+        $lang = $regs[2];
1680
+    }
1681
+    $trads[$lang] = $bloc;
1682 1682
 
1683
-	return $trads;
1683
+    return $trads;
1684 1684
 }
1685 1685
 
1686 1686
 
@@ -1691,7 +1691,7 @@  discard block
 block discarded – undo
1691 1691
  * @return string L'initiale en majuscule
1692 1692
  */
1693 1693
 function filtre_initiale($nom) {
1694
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1694
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1695 1695
 }
1696 1696
 
1697 1697
 
@@ -1736,33 +1736,33 @@  discard block
 block discarded – undo
1736 1736
  *      - null (interne) : si on empile
1737 1737
  **/
1738 1738
 function unique($donnee, $famille = '', $cpt = false) {
1739
-	static $mem = array();
1740
-	// permettre de vider la pile et de la restaurer
1741
-	// pour le calcul de introduction...
1742
-	if ($famille == '_spip_raz_') {
1743
-		$tmp = $mem;
1744
-		$mem = array();
1745
-
1746
-		return $tmp;
1747
-	} elseif ($famille == '_spip_set_') {
1748
-		$mem = $donnee;
1749
-
1750
-		return;
1751
-	}
1752
-	// eviter une notice
1753
-	if (!isset($mem[$famille])) {
1754
-		$mem[$famille] = array();
1755
-	}
1756
-	if ($cpt) {
1757
-		return count($mem[$famille]);
1758
-	}
1759
-	// eviter une notice
1760
-	if (!isset($mem[$famille][$donnee])) {
1761
-		$mem[$famille][$donnee] = 0;
1762
-	}
1763
-	if (!($mem[$famille][$donnee]++)) {
1764
-		return $donnee;
1765
-	}
1739
+    static $mem = array();
1740
+    // permettre de vider la pile et de la restaurer
1741
+    // pour le calcul de introduction...
1742
+    if ($famille == '_spip_raz_') {
1743
+        $tmp = $mem;
1744
+        $mem = array();
1745
+
1746
+        return $tmp;
1747
+    } elseif ($famille == '_spip_set_') {
1748
+        $mem = $donnee;
1749
+
1750
+        return;
1751
+    }
1752
+    // eviter une notice
1753
+    if (!isset($mem[$famille])) {
1754
+        $mem[$famille] = array();
1755
+    }
1756
+    if ($cpt) {
1757
+        return count($mem[$famille]);
1758
+    }
1759
+    // eviter une notice
1760
+    if (!isset($mem[$famille][$donnee])) {
1761
+        $mem[$famille][$donnee] = 0;
1762
+    }
1763
+    if (!($mem[$famille][$donnee]++)) {
1764
+        return $donnee;
1765
+    }
1766 1766
 }
1767 1767
 
1768 1768
 
@@ -1790,18 +1790,18 @@  discard block
 block discarded – undo
1790 1790
  *     Une des valeurs en fonction du compteur.
1791 1791
  **/
1792 1792
 function alterner($i) {
1793
-	// recuperer les arguments (attention fonctions un peu space)
1794
-	$num = func_num_args();
1795
-	$args = func_get_args();
1793
+    // recuperer les arguments (attention fonctions un peu space)
1794
+    $num = func_num_args();
1795
+    $args = func_get_args();
1796 1796
 
1797
-	if ($num == 2 && is_array($args[1])) {
1798
-		$args = $args[1];
1799
-		array_unshift($args, '');
1800
-		$num = count($args);
1801
-	}
1797
+    if ($num == 2 && is_array($args[1])) {
1798
+        $args = $args[1];
1799
+        array_unshift($args, '');
1800
+        $num = count($args);
1801
+    }
1802 1802
 
1803
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1804
-	return $args[(intval($i) - 1) % ($num - 1) + 1];
1803
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1804
+    return $args[(intval($i) - 1) % ($num - 1) + 1];
1805 1805
 }
1806 1806
 
1807 1807
 
@@ -1826,46 +1826,46 @@  discard block
 block discarded – undo
1826 1826
  *     - Tableau complet (si 2e argument)
1827 1827
  **/
1828 1828
 function extraire_attribut($balise, $attribut, $complet = false) {
1829
-	if (is_array($balise)) {
1830
-		array_walk(
1831
-			$balise,
1832
-			function(&$a, $key, $t){
1833
-				$a = extraire_attribut($a, $t);
1834
-			},
1835
-			$attribut
1836
-		);
1837
-
1838
-		return $balise;
1839
-	}
1840
-	if (preg_match(
1841
-		',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1842
-		. $attribut
1843
-		. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1844
-
1845
-		$balise, $r)) {
1846
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1847
-			$r[4] = substr($r[3], 1, -1);
1848
-			$r[3] = $r[3][0];
1849
-		} elseif ($r[3] !== '') {
1850
-			$r[4] = $r[3];
1851
-			$r[3] = '';
1852
-		} else {
1853
-			$r[4] = trim($r[2]);
1854
-		}
1855
-		$att = $r[4];
1856
-		if (strpos($att, "&#") !== false) {
1857
-			$att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1858
-		}
1859
-		$att = filtrer_entites($att);
1860
-	} else {
1861
-		$att = null;
1862
-	}
1863
-
1864
-	if ($complet) {
1865
-		return array($att, $r);
1866
-	} else {
1867
-		return $att;
1868
-	}
1829
+    if (is_array($balise)) {
1830
+        array_walk(
1831
+            $balise,
1832
+            function(&$a, $key, $t){
1833
+                $a = extraire_attribut($a, $t);
1834
+            },
1835
+            $attribut
1836
+        );
1837
+
1838
+        return $balise;
1839
+    }
1840
+    if (preg_match(
1841
+        ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1842
+        . $attribut
1843
+        . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1844
+
1845
+        $balise, $r)) {
1846
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1847
+            $r[4] = substr($r[3], 1, -1);
1848
+            $r[3] = $r[3][0];
1849
+        } elseif ($r[3] !== '') {
1850
+            $r[4] = $r[3];
1851
+            $r[3] = '';
1852
+        } else {
1853
+            $r[4] = trim($r[2]);
1854
+        }
1855
+        $att = $r[4];
1856
+        if (strpos($att, "&#") !== false) {
1857
+            $att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1858
+        }
1859
+        $att = filtrer_entites($att);
1860
+    } else {
1861
+        $att = null;
1862
+    }
1863
+
1864
+    if ($complet) {
1865
+        return array($att, $r);
1866
+    } else {
1867
+        return $att;
1868
+    }
1869 1869
 }
1870 1870
 
1871 1871
 /**
@@ -1897,37 +1897,37 @@  discard block
 block discarded – undo
1897 1897
  *     Code html modifié
1898 1898
  **/
1899 1899
 function inserer_attribut($balise, $attribut, $val, $proteger = true, $vider = false) {
1900
-	// preparer l'attribut
1901
-	// supprimer les &nbsp; etc mais pas les balises html
1902
-	// qui ont un sens dans un attribut value d'un input
1903
-	if ($proteger) {
1904
-		$val = attribut_html($val, false);
1905
-	}
1906
-
1907
-	// echapper les ' pour eviter tout bug
1908
-	$val = str_replace("'", "&#039;", $val);
1909
-	if ($vider and strlen($val) == 0) {
1910
-		$insert = '';
1911
-	} else {
1912
-		$insert = " $attribut='$val'";
1913
-	}
1914
-
1915
-	list($old, $r) = extraire_attribut($balise, $attribut, true);
1916
-
1917
-	if ($old !== null) {
1918
-		// Remplacer l'ancien attribut du meme nom
1919
-		$balise = $r[1] . $insert . $r[5];
1920
-	} else {
1921
-		// preferer une balise " />" (comme <img />)
1922
-		if (preg_match(',/>,', $balise)) {
1923
-			$balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
1924
-		} // sinon une balise <a ...> ... </a>
1925
-		else {
1926
-			$balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
1927
-		}
1928
-	}
1929
-
1930
-	return $balise;
1900
+    // preparer l'attribut
1901
+    // supprimer les &nbsp; etc mais pas les balises html
1902
+    // qui ont un sens dans un attribut value d'un input
1903
+    if ($proteger) {
1904
+        $val = attribut_html($val, false);
1905
+    }
1906
+
1907
+    // echapper les ' pour eviter tout bug
1908
+    $val = str_replace("'", "&#039;", $val);
1909
+    if ($vider and strlen($val) == 0) {
1910
+        $insert = '';
1911
+    } else {
1912
+        $insert = " $attribut='$val'";
1913
+    }
1914
+
1915
+    list($old, $r) = extraire_attribut($balise, $attribut, true);
1916
+
1917
+    if ($old !== null) {
1918
+        // Remplacer l'ancien attribut du meme nom
1919
+        $balise = $r[1] . $insert . $r[5];
1920
+    } else {
1921
+        // preferer une balise " />" (comme <img />)
1922
+        if (preg_match(',/>,', $balise)) {
1923
+            $balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
1924
+        } // sinon une balise <a ...> ... </a>
1925
+        else {
1926
+            $balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
1927
+        }
1928
+    }
1929
+
1930
+    return $balise;
1931 1931
 }
1932 1932
 
1933 1933
 /**
@@ -1945,7 +1945,7 @@  discard block
 block discarded – undo
1945 1945
  * @return string Code HTML sans l'attribut
1946 1946
  **/
1947 1947
 function vider_attribut($balise, $attribut) {
1948
-	return inserer_attribut($balise, $attribut, '', false, true);
1948
+    return inserer_attribut($balise, $attribut, '', false, true);
1949 1949
 }
1950 1950
 
1951 1951
 
@@ -1957,9 +1957,9 @@  discard block
 block discarded – undo
1957 1957
  * @return string
1958 1958
  */
1959 1959
 function tester_config($id, $mode = '') {
1960
-	include_spip('action/inscrire_auteur');
1960
+    include_spip('action/inscrire_auteur');
1961 1961
 
1962
-	return tester_statut_inscription($mode, $id);
1962
+    return tester_statut_inscription($mode, $id);
1963 1963
 }
1964 1964
 
1965 1965
 //
@@ -1984,7 +1984,7 @@  discard block
 block discarded – undo
1984 1984
  * @return int $a+$b
1985 1985
  **/
1986 1986
 function plus($a, $b) {
1987
-	return $a + $b;
1987
+    return $a + $b;
1988 1988
 }
1989 1989
 function strplus($a, $b) {return strize('plus', $a, $b);}
1990 1990
 /**
@@ -2003,7 +2003,7 @@  discard block
 block discarded – undo
2003 2003
  * @return int $a-$b
2004 2004
  **/
2005 2005
 function moins($a, $b) {
2006
-	return $a - $b;
2006
+    return $a - $b;
2007 2007
 }
2008 2008
 function strmoins($a, $b) {return strize('moins', $a, $b);}
2009 2009
 
@@ -2024,7 +2024,7 @@  discard block
 block discarded – undo
2024 2024
  * @return int $a*$b
2025 2025
  **/
2026 2026
 function mult($a, $b) {
2027
-	return $a * $b;
2027
+    return $a * $b;
2028 2028
 }
2029 2029
 function strmult($a, $b) {return strize('mult', $a, $b);}
2030 2030
 
@@ -2045,7 +2045,7 @@  discard block
 block discarded – undo
2045 2045
  * @return int $a/$b (ou 0 si $b est nul)
2046 2046
  **/
2047 2047
 function div($a, $b) {
2048
-	return $b ? $a / $b : 0;
2048
+    return $b ? $a / $b : 0;
2049 2049
 }
2050 2050
 function strdiv($a, $b) {return strize('div', $a, $b);}
2051 2051
 
@@ -2067,7 +2067,7 @@  discard block
 block discarded – undo
2067 2067
  * @return int ($nb % $mod) + $add
2068 2068
  **/
2069 2069
 function modulo($nb, $mod, $add = 0) {
2070
-	return ($mod ? $nb % $mod : 0) + $add;
2070
+    return ($mod ? $nb % $mod : 0) + $add;
2071 2071
 }
2072 2072
 
2073 2073
 
@@ -2082,24 +2082,24 @@  discard block
 block discarded – undo
2082 2082
  *      - true sinon
2083 2083
  **/
2084 2084
 function nom_acceptable($nom) {
2085
-	if (!is_string($nom)) {
2086
-		return false;
2087
-	}
2088
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2089
-		define('_TAGS_NOM_AUTEUR', '');
2090
-	}
2091
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2092
-	foreach ($tags_acceptes as $tag) {
2093
-		if (strlen($tag)) {
2094
-			$remp1[] = '<' . trim($tag) . '>';
2095
-			$remp1[] = '</' . trim($tag) . '>';
2096
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2097
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2098
-		}
2099
-	}
2100
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2085
+    if (!is_string($nom)) {
2086
+        return false;
2087
+    }
2088
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2089
+        define('_TAGS_NOM_AUTEUR', '');
2090
+    }
2091
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2092
+    foreach ($tags_acceptes as $tag) {
2093
+        if (strlen($tag)) {
2094
+            $remp1[] = '<' . trim($tag) . '>';
2095
+            $remp1[] = '</' . trim($tag) . '>';
2096
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2097
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2098
+        }
2099
+    }
2100
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2101 2101
 
2102
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2102
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2103 2103
 }
2104 2104
 
2105 2105
 
@@ -2113,29 +2113,29 @@  discard block
 block discarded – undo
2113 2113
  *      - la normalisation de la dernière adresse donnée sinon
2114 2114
  **/
2115 2115
 function email_valide($adresses) {
2116
-	// eviter d'injecter n'importe quoi dans preg_match
2117
-	if (!is_string($adresses)) {
2118
-		return false;
2119
-	}
2116
+    // eviter d'injecter n'importe quoi dans preg_match
2117
+    if (!is_string($adresses)) {
2118
+        return false;
2119
+    }
2120 2120
 
2121
-	// Si c'est un spammeur autant arreter tout de suite
2122
-	if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) {
2123
-		spip_log("Tentative d'injection de mail : $adresses");
2121
+    // Si c'est un spammeur autant arreter tout de suite
2122
+    if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) {
2123
+        spip_log("Tentative d'injection de mail : $adresses");
2124 2124
 
2125
-		return false;
2126
-	}
2125
+        return false;
2126
+    }
2127 2127
 
2128
-	foreach (explode(',', $adresses) as $v) {
2129
-		// nettoyer certains formats
2130
-		// "Marie Toto <[email protected]>"
2131
-		$adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v));
2132
-		// RFC 822
2133
-		if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) {
2134
-			return false;
2135
-		}
2136
-	}
2128
+    foreach (explode(',', $adresses) as $v) {
2129
+        // nettoyer certains formats
2130
+        // "Marie Toto <[email protected]>"
2131
+        $adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v));
2132
+        // RFC 822
2133
+        if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) {
2134
+            return false;
2135
+        }
2136
+    }
2137 2137
 
2138
-	return $adresse;
2138
+    return $adresse;
2139 2139
 }
2140 2140
 
2141 2141
 /**
@@ -2149,20 +2149,20 @@  discard block
 block discarded – undo
2149 2149
  * @return string Texte
2150 2150
  **/
2151 2151
 function afficher_enclosures($tags) {
2152
-	$s = array();
2153
-	foreach (extraire_balises($tags, 'a') as $tag) {
2154
-		if (extraire_attribut($tag, 'rel') == 'enclosure'
2155
-			and $t = extraire_attribut($tag, 'href')
2156
-		) {
2157
-			$s[] = preg_replace(',>[^<]+</a>,S',
2158
-				'>'
2159
-				. http_img_pack('attachment-16.png', $t,
2160
-					'title="' . attribut_html($t) . '"')
2161
-				. '</a>', $tag);
2162
-		}
2163
-	}
2152
+    $s = array();
2153
+    foreach (extraire_balises($tags, 'a') as $tag) {
2154
+        if (extraire_attribut($tag, 'rel') == 'enclosure'
2155
+            and $t = extraire_attribut($tag, 'href')
2156
+        ) {
2157
+            $s[] = preg_replace(',>[^<]+</a>,S',
2158
+                '>'
2159
+                . http_img_pack('attachment-16.png', $t,
2160
+                    'title="' . attribut_html($t) . '"')
2161
+                . '</a>', $tag);
2162
+        }
2163
+    }
2164 2164
 
2165
-	return join('&nbsp;', $s);
2165
+    return join('&nbsp;', $s);
2166 2166
 }
2167 2167
 
2168 2168
 /**
@@ -2177,15 +2177,15 @@  discard block
 block discarded – undo
2177 2177
  * @return string Liens trouvés
2178 2178
  **/
2179 2179
 function afficher_tags($tags, $rels = 'tag,directory') {
2180
-	$s = array();
2181
-	foreach (extraire_balises($tags, 'a') as $tag) {
2182
-		$rel = extraire_attribut($tag, 'rel');
2183
-		if (strstr(",$rels,", ",$rel,")) {
2184
-			$s[] = $tag;
2185
-		}
2186
-	}
2180
+    $s = array();
2181
+    foreach (extraire_balises($tags, 'a') as $tag) {
2182
+        $rel = extraire_attribut($tag, 'rel');
2183
+        if (strstr(",$rels,", ",$rel,")) {
2184
+            $s[] = $tag;
2185
+        }
2186
+    }
2187 2187
 
2188
-	return join(', ', $s);
2188
+    return join(', ', $s);
2189 2189
 }
2190 2190
 
2191 2191
 
@@ -2207,21 +2207,21 @@  discard block
 block discarded – undo
2207 2207
  * @return string Tag HTML `<a>` avec microformat.
2208 2208
  **/
2209 2209
 function enclosure2microformat($e) {
2210
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2211
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2212
-	}
2213
-	$type = extraire_attribut($e, 'type');
2214
-	if (!$length = extraire_attribut($e, 'length')) {
2215
-		# <media:content : longeur dans fileSize. On tente.
2216
-		$length = extraire_attribut($e, 'fileSize');
2217
-	}
2218
-	$fichier = basename($url);
2210
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2211
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2212
+    }
2213
+    $type = extraire_attribut($e, 'type');
2214
+    if (!$length = extraire_attribut($e, 'length')) {
2215
+        # <media:content : longeur dans fileSize. On tente.
2216
+        $length = extraire_attribut($e, 'fileSize');
2217
+    }
2218
+    $fichier = basename($url);
2219 2219
 
2220
-	return '<a rel="enclosure"'
2221
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2222
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2223
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2224
-	. '>' . $fichier . '</a>';
2220
+    return '<a rel="enclosure"'
2221
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2222
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2223
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2224
+    . '>' . $fichier . '</a>';
2225 2225
 }
2226 2226
 
2227 2227
 /**
@@ -2239,24 +2239,24 @@  discard block
 block discarded – undo
2239 2239
  * @return string Tags RSS `<enclosure>`.
2240 2240
  **/
2241 2241
 function microformat2enclosure($tags) {
2242
-	$enclosures = array();
2243
-	foreach (extraire_balises($tags, 'a') as $e) {
2244
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2245
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2246
-			$type = extraire_attribut($e, 'type');
2247
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2248
-				$length = intval(extraire_attribut($e, 'length'));
2249
-			} # vieux data
2250
-			$fichier = basename($url);
2251
-			$enclosures[] = '<enclosure'
2252
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2253
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2254
-				. ($length ? ' length="' . $length . '"' : '')
2255
-				. ' />';
2256
-		}
2257
-	}
2242
+    $enclosures = array();
2243
+    foreach (extraire_balises($tags, 'a') as $e) {
2244
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2245
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2246
+            $type = extraire_attribut($e, 'type');
2247
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2248
+                $length = intval(extraire_attribut($e, 'length'));
2249
+            } # vieux data
2250
+            $fichier = basename($url);
2251
+            $enclosures[] = '<enclosure'
2252
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2253
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2254
+                . ($length ? ' length="' . $length . '"' : '')
2255
+                . ' />';
2256
+        }
2257
+    }
2258 2258
 
2259
-	return join("\n", $enclosures);
2259
+    return join("\n", $enclosures);
2260 2260
 }
2261 2261
 
2262 2262
 
@@ -2272,16 +2272,16 @@  discard block
 block discarded – undo
2272 2272
  * @return string Tags RSS Atom `<dc:subject>`.
2273 2273
  **/
2274 2274
 function tags2dcsubject($tags) {
2275
-	$subjects = '';
2276
-	foreach (extraire_balises($tags, 'a') as $e) {
2277
-		if (extraire_attribut($e, rel) == 'tag') {
2278
-			$subjects .= '<dc:subject>'
2279
-				. texte_backend(textebrut($e))
2280
-				. '</dc:subject>' . "\n";
2281
-		}
2282
-	}
2275
+    $subjects = '';
2276
+    foreach (extraire_balises($tags, 'a') as $e) {
2277
+        if (extraire_attribut($e, rel) == 'tag') {
2278
+            $subjects .= '<dc:subject>'
2279
+                . texte_backend(textebrut($e))
2280
+                . '</dc:subject>' . "\n";
2281
+        }
2282
+    }
2283 2283
 
2284
-	return $subjects;
2284
+    return $subjects;
2285 2285
 }
2286 2286
 
2287 2287
 /**
@@ -2310,23 +2310,23 @@  discard block
 block discarded – undo
2310 2310
  *     - Tableau de résultats, si tableau en entrée.
2311 2311
  **/
2312 2312
 function extraire_balise($texte, $tag = 'a') {
2313
-	if (is_array($texte)) {
2314
-		array_walk(
2315
-			$texte,
2316
-			function(&$a, $key, $t){
2317
-				$a = extraire_balise($a, $t);
2318
-			},
2319
-			$tag
2320
-		);
2313
+    if (is_array($texte)) {
2314
+        array_walk(
2315
+            $texte,
2316
+            function(&$a, $key, $t){
2317
+                $a = extraire_balise($a, $t);
2318
+            },
2319
+            $tag
2320
+        );
2321 2321
 
2322
-		return $texte;
2323
-	}
2322
+        return $texte;
2323
+    }
2324 2324
 
2325
-	if (preg_match(
2326
-		",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2327
-		$texte, $regs)) {
2328
-		return $regs[0];
2329
-	}
2325
+    if (preg_match(
2326
+        ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2327
+        $texte, $regs)) {
2328
+        return $regs[0];
2329
+    }
2330 2330
 }
2331 2331
 
2332 2332
 /**
@@ -2354,25 +2354,25 @@  discard block
 block discarded – undo
2354 2354
  *     - Tableau de résultats, si tableau en entrée.
2355 2355
  **/
2356 2356
 function extraire_balises($texte, $tag = 'a') {
2357
-	if (is_array($texte)) {
2358
-		array_walk(
2359
-			$texte,
2360
-			function(&$a, $key, $t){
2361
-				$a = extraire_balises($a, $t);
2362
-			},
2363
-			$tag
2364
-		);
2357
+    if (is_array($texte)) {
2358
+        array_walk(
2359
+            $texte,
2360
+            function(&$a, $key, $t){
2361
+                $a = extraire_balises($a, $t);
2362
+            },
2363
+            $tag
2364
+        );
2365 2365
 
2366
-		return $texte;
2367
-	}
2366
+        return $texte;
2367
+    }
2368 2368
 
2369
-	if (preg_match_all(
2370
-		",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2371
-		$texte, $regs, PREG_PATTERN_ORDER)) {
2372
-		return $regs[0];
2373
-	} else {
2374
-		return array();
2375
-	}
2369
+    if (preg_match_all(
2370
+        ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2371
+        $texte, $regs, PREG_PATTERN_ORDER)) {
2372
+        return $regs[0];
2373
+    } else {
2374
+        return array();
2375
+    }
2376 2376
 }
2377 2377
 
2378 2378
 /**
@@ -2401,11 +2401,11 @@  discard block
 block discarded – undo
2401 2401
  *     - `$def` si on n'a pas transmis de tableau
2402 2402
  **/
2403 2403
 function in_any($val, $vals, $def = '') {
2404
-	if (!is_array($vals) and $v = unserialize($vals)) {
2405
-		$vals = $v;
2406
-	}
2404
+    if (!is_array($vals) and $v = unserialize($vals)) {
2405
+        $vals = $v;
2406
+    }
2407 2407
 
2408
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2408
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2409 2409
 }
2410 2410
 
2411 2411
 
@@ -2426,12 +2426,12 @@  discard block
 block discarded – undo
2426 2426
  *     Résultat du calcul
2427 2427
  **/
2428 2428
 function valeur_numerique($expr) {
2429
-	$a = 0;
2430
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2431
-		eval("\$a = $expr;");
2432
-	}
2429
+    $a = 0;
2430
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2431
+        eval("\$a = $expr;");
2432
+    }
2433 2433
 
2434
-	return intval($a);
2434
+    return intval($a);
2435 2435
 }
2436 2436
 
2437 2437
 /**
@@ -2450,7 +2450,7 @@  discard block
 block discarded – undo
2450 2450
  *      Retourne `$a*$b/$c`
2451 2451
  **/
2452 2452
 function regledetrois($a, $b, $c) {
2453
-	return round($a * $b / $c);
2453
+    return round($a * $b / $c);
2454 2454
 }
2455 2455
 
2456 2456
 
@@ -2474,76 +2474,76 @@  discard block
 block discarded – undo
2474 2474
  **/
2475 2475
 function form_hidden($action) {
2476 2476
 
2477
-	$contexte = array();
2478
-	include_spip('inc/urls');
2479
-	if ($p = urls_decoder_url($action, '')
2480
-		and reset($p)
2481
-	) {
2482
-		$fond = array_shift($p);
2483
-		if ($fond != '404') {
2484
-			$contexte = array_shift($p);
2485
-			$contexte['page'] = $fond;
2486
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2487
-		}
2488
-	}
2489
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2490
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2491
-		unset($contexte['type']);
2492
-	}
2493
-	if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) {
2494
-		unset($contexte['type-page']);
2495
-	}
2496
-
2497
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2498
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2499
-	$values = array();
2500
-
2501
-	// d'abord avec celles de l'url
2502
-	if (false !== ($p = strpos($action, '?'))) {
2503
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2504
-			$c = explode('=', $c, 2);
2505
-			$var = array_shift($c);
2506
-			$val = array_shift($c);
2507
-			if ($var) {
2508
-				$val = rawurldecode($val);
2509
-				$var = rawurldecode($var); // decoder les [] eventuels
2510
-				if (preg_match(',\[\]$,S', $var)) {
2511
-					$values[] = array($var, $val);
2512
-				} else {
2513
-					if (!isset($values[$var])) {
2514
-						$values[$var] = array($var, $val);
2515
-					}
2516
-				}
2517
-			}
2518
-		}
2519
-	}
2520
-
2521
-	// ensuite avec celles du contexte, sans doublonner !
2522
-	foreach ($contexte as $var => $val) {
2523
-		if (preg_match(',\[\]$,S', $var)) {
2524
-			$values[] = array($var, $val);
2525
-		} else {
2526
-			if (!isset($values[$var])) {
2527
-				$values[$var] = array($var, $val);
2528
-			}
2529
-		}
2530
-	}
2531
-
2532
-	// puis on rassemble le tout
2533
-	$hidden = array();
2534
-	foreach ($values as $value) {
2535
-		list($var, $val) = $value;
2536
-		$hidden[] = '<input name="'
2537
-			. entites_html($var)
2538
-			. '"'
2539
-			. (is_null($val)
2540
-				? ''
2541
-				: ' value="' . entites_html($val) . '"'
2542
-			)
2543
-			. ' type="hidden"' . "\n/>";
2544
-	}
2545
-
2546
-	return join("", $hidden);
2477
+    $contexte = array();
2478
+    include_spip('inc/urls');
2479
+    if ($p = urls_decoder_url($action, '')
2480
+        and reset($p)
2481
+    ) {
2482
+        $fond = array_shift($p);
2483
+        if ($fond != '404') {
2484
+            $contexte = array_shift($p);
2485
+            $contexte['page'] = $fond;
2486
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2487
+        }
2488
+    }
2489
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2490
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2491
+        unset($contexte['type']);
2492
+    }
2493
+    if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) {
2494
+        unset($contexte['type-page']);
2495
+    }
2496
+
2497
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2498
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2499
+    $values = array();
2500
+
2501
+    // d'abord avec celles de l'url
2502
+    if (false !== ($p = strpos($action, '?'))) {
2503
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2504
+            $c = explode('=', $c, 2);
2505
+            $var = array_shift($c);
2506
+            $val = array_shift($c);
2507
+            if ($var) {
2508
+                $val = rawurldecode($val);
2509
+                $var = rawurldecode($var); // decoder les [] eventuels
2510
+                if (preg_match(',\[\]$,S', $var)) {
2511
+                    $values[] = array($var, $val);
2512
+                } else {
2513
+                    if (!isset($values[$var])) {
2514
+                        $values[$var] = array($var, $val);
2515
+                    }
2516
+                }
2517
+            }
2518
+        }
2519
+    }
2520
+
2521
+    // ensuite avec celles du contexte, sans doublonner !
2522
+    foreach ($contexte as $var => $val) {
2523
+        if (preg_match(',\[\]$,S', $var)) {
2524
+            $values[] = array($var, $val);
2525
+        } else {
2526
+            if (!isset($values[$var])) {
2527
+                $values[$var] = array($var, $val);
2528
+            }
2529
+        }
2530
+    }
2531
+
2532
+    // puis on rassemble le tout
2533
+    $hidden = array();
2534
+    foreach ($values as $value) {
2535
+        list($var, $val) = $value;
2536
+        $hidden[] = '<input name="'
2537
+            . entites_html($var)
2538
+            . '"'
2539
+            . (is_null($val)
2540
+                ? ''
2541
+                : ' value="' . entites_html($val) . '"'
2542
+            )
2543
+            . ' type="hidden"' . "\n/>";
2544
+    }
2545
+
2546
+    return join("", $hidden);
2547 2547
 }
2548 2548
 
2549 2549
 /**
@@ -2561,15 +2561,15 @@  discard block
 block discarded – undo
2561 2561
  *     Liste (première page, dernière page).
2562 2562
  **/
2563 2563
 function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) {
2564
-	if ($max <= 0 or $max >= $nombre) {
2565
-		return array(1, $nombre);
2566
-	}
2564
+    if ($max <= 0 or $max >= $nombre) {
2565
+        return array(1, $nombre);
2566
+    }
2567 2567
 
2568
-	$premiere = max(1, $courante - floor(($max - 1) / 2));
2569
-	$derniere = min($nombre, $premiere + $max - 2);
2570
-	$premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
2568
+    $premiere = max(1, $courante - floor(($max - 1) / 2));
2569
+    $derniere = min($nombre, $premiere + $max - 2);
2570
+    $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
2571 2571
 
2572
-	return array($premiere, $derniere);
2572
+    return array($premiere, $derniere);
2573 2573
 }
2574 2574
 
2575 2575
 
@@ -2591,7 +2591,7 @@  discard block
 block discarded – undo
2591 2591
  *    - la première valeur du tableau sinon.
2592 2592
  **/
2593 2593
 function filtre_reset($array) {
2594
-	return !is_array($array) ? null : reset($array);
2594
+    return !is_array($array) ? null : reset($array);
2595 2595
 }
2596 2596
 
2597 2597
 /**
@@ -2612,7 +2612,7 @@  discard block
 block discarded – undo
2612 2612
  *    - la dernière valeur du tableau sinon.
2613 2613
  **/
2614 2614
 function filtre_end($array) {
2615
-	return !is_array($array) ? null : end($array);
2615
+    return !is_array($array) ? null : end($array);
2616 2616
 }
2617 2617
 
2618 2618
 /**
@@ -2632,11 +2632,11 @@  discard block
 block discarded – undo
2632 2632
  *
2633 2633
  **/
2634 2634
 function filtre_push($array, $val) {
2635
-	if (!is_array($array) or !array_push($array, $val)) {
2636
-		return '';
2637
-	}
2635
+    if (!is_array($array) or !array_push($array, $val)) {
2636
+        return '';
2637
+    }
2638 2638
 
2639
-	return $array;
2639
+    return $array;
2640 2640
 }
2641 2641
 
2642 2642
 /**
@@ -2655,7 +2655,7 @@  discard block
 block discarded – undo
2655 2655
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2656 2656
  **/
2657 2657
 function filtre_find($array, $val) {
2658
-	return (is_array($array) and in_array($val, $array));
2658
+    return (is_array($array) and in_array($val, $array));
2659 2659
 }
2660 2660
 
2661 2661
 
@@ -2690,58 +2690,58 @@  discard block
 block discarded – undo
2690 2690
  *     Code HTML de la pagination
2691 2691
  **/
2692 2692
 function filtre_pagination_dist(
2693
-	$total,
2694
-	$nom,
2695
-	$position,
2696
-	$pas,
2697
-	$liste = true,
2698
-	$modele = '',
2699
-	$connect = '',
2700
-	$env = array()
2693
+    $total,
2694
+    $nom,
2695
+    $position,
2696
+    $pas,
2697
+    $liste = true,
2698
+    $modele = '',
2699
+    $connect = '',
2700
+    $env = array()
2701 2701
 ) {
2702
-	static $ancres = array();
2703
-	if ($pas < 1) {
2704
-		return '';
2705
-	}
2706
-	$ancre = 'pagination' . $nom; // #pagination_articles
2707
-	$debut = 'debut' . $nom; // 'debut_articles'
2708
-
2709
-	// n'afficher l'ancre qu'une fois
2710
-	if (!isset($ancres[$ancre])) {
2711
-		$bloc_ancre = $ancres[$ancre] = "<a name='" . $ancre . "' id='" . $ancre . "'></a>";
2712
-	} else {
2713
-		$bloc_ancre = '';
2714
-	}
2715
-	// liste = false : on ne veut que l'ancre
2716
-	if (!$liste) {
2717
-		return $ancres[$ancre];
2718
-	}
2719
-
2720
-	$pagination = array(
2721
-		'debut' => $debut,
2722
-		'url' => parametre_url(self(), 'fragment', ''), // nettoyer l'id ahah eventuel
2723
-		'total' => $total,
2724
-		'position' => intval($position),
2725
-		'pas' => $pas,
2726
-		'nombre_pages' => floor(($total - 1) / $pas) + 1,
2727
-		'page_courante' => floor(intval($position) / $pas) + 1,
2728
-		'ancre' => $ancre,
2729
-		'bloc_ancre' => $bloc_ancre
2730
-	);
2731
-	if (is_array($env)) {
2732
-		$pagination = array_merge($env, $pagination);
2733
-	}
2734
-
2735
-	// Pas de pagination
2736
-	if ($pagination['nombre_pages'] <= 1) {
2737
-		return '';
2738
-	}
2739
-
2740
-	if ($modele) {
2741
-		$modele = '_' . $modele;
2742
-	}
2743
-
2744
-	return recuperer_fond("modeles/pagination$modele", $pagination, array('trim' => true), $connect);
2702
+    static $ancres = array();
2703
+    if ($pas < 1) {
2704
+        return '';
2705
+    }
2706
+    $ancre = 'pagination' . $nom; // #pagination_articles
2707
+    $debut = 'debut' . $nom; // 'debut_articles'
2708
+
2709
+    // n'afficher l'ancre qu'une fois
2710
+    if (!isset($ancres[$ancre])) {
2711
+        $bloc_ancre = $ancres[$ancre] = "<a name='" . $ancre . "' id='" . $ancre . "'></a>";
2712
+    } else {
2713
+        $bloc_ancre = '';
2714
+    }
2715
+    // liste = false : on ne veut que l'ancre
2716
+    if (!$liste) {
2717
+        return $ancres[$ancre];
2718
+    }
2719
+
2720
+    $pagination = array(
2721
+        'debut' => $debut,
2722
+        'url' => parametre_url(self(), 'fragment', ''), // nettoyer l'id ahah eventuel
2723
+        'total' => $total,
2724
+        'position' => intval($position),
2725
+        'pas' => $pas,
2726
+        'nombre_pages' => floor(($total - 1) / $pas) + 1,
2727
+        'page_courante' => floor(intval($position) / $pas) + 1,
2728
+        'ancre' => $ancre,
2729
+        'bloc_ancre' => $bloc_ancre
2730
+    );
2731
+    if (is_array($env)) {
2732
+        $pagination = array_merge($env, $pagination);
2733
+    }
2734
+
2735
+    // Pas de pagination
2736
+    if ($pagination['nombre_pages'] <= 1) {
2737
+        return '';
2738
+    }
2739
+
2740
+    if ($modele) {
2741
+        $modele = '_' . $modele;
2742
+    }
2743
+
2744
+    return recuperer_fond("modeles/pagination$modele", $pagination, array('trim' => true), $connect);
2745 2745
 }
2746 2746
 
2747 2747
 
@@ -2758,15 +2758,15 @@  discard block
 block discarded – undo
2758 2758
  *     Contenu avec urls en absolus
2759 2759
  **/
2760 2760
 function urls_absolues_css($contenu, $source) {
2761
-	$path = suivre_lien(url_absolue($source), './');
2761
+    $path = suivre_lien(url_absolue($source), './');
2762 2762
 
2763
-	return preg_replace_callback(
2764
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2765
-		function($x) use ($path) {
2766
-			return "url('" . suivre_lien($path, $x[1]) . "')";
2767
-		},
2768
-		$contenu
2769
-	);
2763
+    return preg_replace_callback(
2764
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2765
+        function($x) use ($path) {
2766
+            return "url('" . suivre_lien($path, $x[1]) . "')";
2767
+        },
2768
+        $contenu
2769
+    );
2770 2770
 }
2771 2771
 
2772 2772
 
@@ -2795,118 +2795,118 @@  discard block
 block discarded – undo
2795 2795
  *     Chemin du fichier CSS inversé
2796 2796
  **/
2797 2797
 function direction_css($css, $voulue = '') {
2798
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2799
-		return $css;
2800
-	}
2801
-
2802
-	// si on a precise le sens voulu en argument, le prendre en compte
2803
-	if ($voulue = strtolower($voulue)) {
2804
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2805
-			$voulue = lang_dir($voulue);
2806
-		}
2807
-	} else {
2808
-		$voulue = lang_dir();
2809
-	}
2810
-
2811
-	$r = count($r) > 1;
2812
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2813
-	$dir = $r ? 'rtl' : 'ltr';
2814
-	$ndir = $r ? 'ltr' : 'rtl';
2815
-
2816
-	if ($voulue == $dir) {
2817
-		return $css;
2818
-	}
2819
-
2820
-	if (
2821
-		// url absolue
2822
-		preg_match(",^https?:,i", $css)
2823
-		// ou qui contient un ?
2824
-		or (($p = strpos($css, '?')) !== false)
2825
-	) {
2826
-		$distant = true;
2827
-		$cssf = parse_url($css);
2828
-		$cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2829
-		$cssf = preg_replace(',[?:&=],', "_", $cssf);
2830
-	} else {
2831
-		$distant = false;
2832
-		$cssf = $css;
2833
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2834
-		//propose (rien a faire dans ce cas)
2835
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2836
-		if (@file_exists($f)) {
2837
-			return $f;
2838
-		}
2839
-	}
2840
-
2841
-	// 2.
2842
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2843
-	$f = $dir_var
2844
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2845
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2846
-
2847
-	// la css peut etre distante (url absolue !)
2848
-	if ($distant) {
2849
-		include_spip('inc/distant');
2850
-		$res = recuperer_url($css);
2851
-		if (!$res or !$contenu = $res['page']) {
2852
-			return $css;
2853
-		}
2854
-	} else {
2855
-		if ((@filemtime($f) > @filemtime($css))
2856
-			and (_VAR_MODE != 'recalcul')
2857
-		) {
2858
-			return $f;
2859
-		}
2860
-		if (!lire_fichier($css, $contenu)) {
2861
-			return $css;
2862
-		}
2863
-	}
2864
-
2865
-
2866
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2867
-	include_spip("lib/csstidy/class.csstidy");
2868
-	$parser = new csstidy();
2869
-	$parser->set_cfg('optimise_shorthands', 0);
2870
-	$parser->set_cfg('reverse_left_and_right', true);
2871
-	$parser->parse($contenu);
2872
-
2873
-	$contenu = $parser->print->plain();
2874
-
2875
-
2876
-	// reperer les @import auxquels il faut propager le direction_css
2877
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2878
-	$src = array();
2879
-	$src_direction_css = array();
2880
-	$src_faux_abs = array();
2881
-	$d = dirname($css);
2882
-	foreach ($regs[1] as $k => $import_css) {
2883
-		$css_direction = direction_css("$d/$import_css", $voulue);
2884
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2885
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2886
-			$css_direction = substr($css_direction, strlen($d) + 1);
2887
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2888
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2889
-			$css_direction = substr($css_direction, strlen($dir_var));
2890
-			$src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2891
-			$css_direction = "/@@@@@@/" . $css_direction;
2892
-		}
2893
-		$src[] = $regs[0][$k];
2894
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2895
-	}
2896
-	$contenu = str_replace($src, $src_direction_css, $contenu);
2897
-
2898
-	$contenu = urls_absolues_css($contenu, $css);
2899
-
2900
-	// virer les fausses url absolues que l'on a mis dans les import
2901
-	if (count($src_faux_abs)) {
2902
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2903
-	}
2904
-
2905
-	if (!ecrire_fichier($f, $contenu)) {
2906
-		return $css;
2907
-	}
2908
-
2909
-	return $f;
2798
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2799
+        return $css;
2800
+    }
2801
+
2802
+    // si on a precise le sens voulu en argument, le prendre en compte
2803
+    if ($voulue = strtolower($voulue)) {
2804
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2805
+            $voulue = lang_dir($voulue);
2806
+        }
2807
+    } else {
2808
+        $voulue = lang_dir();
2809
+    }
2810
+
2811
+    $r = count($r) > 1;
2812
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2813
+    $dir = $r ? 'rtl' : 'ltr';
2814
+    $ndir = $r ? 'ltr' : 'rtl';
2815
+
2816
+    if ($voulue == $dir) {
2817
+        return $css;
2818
+    }
2819
+
2820
+    if (
2821
+        // url absolue
2822
+        preg_match(",^https?:,i", $css)
2823
+        // ou qui contient un ?
2824
+        or (($p = strpos($css, '?')) !== false)
2825
+    ) {
2826
+        $distant = true;
2827
+        $cssf = parse_url($css);
2828
+        $cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2829
+        $cssf = preg_replace(',[?:&=],', "_", $cssf);
2830
+    } else {
2831
+        $distant = false;
2832
+        $cssf = $css;
2833
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2834
+        //propose (rien a faire dans ce cas)
2835
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2836
+        if (@file_exists($f)) {
2837
+            return $f;
2838
+        }
2839
+    }
2840
+
2841
+    // 2.
2842
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2843
+    $f = $dir_var
2844
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2845
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2846
+
2847
+    // la css peut etre distante (url absolue !)
2848
+    if ($distant) {
2849
+        include_spip('inc/distant');
2850
+        $res = recuperer_url($css);
2851
+        if (!$res or !$contenu = $res['page']) {
2852
+            return $css;
2853
+        }
2854
+    } else {
2855
+        if ((@filemtime($f) > @filemtime($css))
2856
+            and (_VAR_MODE != 'recalcul')
2857
+        ) {
2858
+            return $f;
2859
+        }
2860
+        if (!lire_fichier($css, $contenu)) {
2861
+            return $css;
2862
+        }
2863
+    }
2864
+
2865
+
2866
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2867
+    include_spip("lib/csstidy/class.csstidy");
2868
+    $parser = new csstidy();
2869
+    $parser->set_cfg('optimise_shorthands', 0);
2870
+    $parser->set_cfg('reverse_left_and_right', true);
2871
+    $parser->parse($contenu);
2872
+
2873
+    $contenu = $parser->print->plain();
2874
+
2875
+
2876
+    // reperer les @import auxquels il faut propager le direction_css
2877
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2878
+    $src = array();
2879
+    $src_direction_css = array();
2880
+    $src_faux_abs = array();
2881
+    $d = dirname($css);
2882
+    foreach ($regs[1] as $k => $import_css) {
2883
+        $css_direction = direction_css("$d/$import_css", $voulue);
2884
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2885
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2886
+            $css_direction = substr($css_direction, strlen($d) + 1);
2887
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
2888
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2889
+            $css_direction = substr($css_direction, strlen($dir_var));
2890
+            $src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2891
+            $css_direction = "/@@@@@@/" . $css_direction;
2892
+        }
2893
+        $src[] = $regs[0][$k];
2894
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2895
+    }
2896
+    $contenu = str_replace($src, $src_direction_css, $contenu);
2897
+
2898
+    $contenu = urls_absolues_css($contenu, $css);
2899
+
2900
+    // virer les fausses url absolues que l'on a mis dans les import
2901
+    if (count($src_faux_abs)) {
2902
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2903
+    }
2904
+
2905
+    if (!ecrire_fichier($f, $contenu)) {
2906
+        return $css;
2907
+    }
2908
+
2909
+    return $f;
2910 2910
 }
2911 2911
 
2912 2912
 
@@ -2929,43 +2929,43 @@  discard block
 block discarded – undo
2929 2929
  *     - Chemin ou URL du fichier CSS source sinon.
2930 2930
  **/
2931 2931
 function url_absolue_css($css) {
2932
-	if (!preg_match(',\.css$,i', $css, $r)) {
2933
-		return $css;
2934
-	}
2932
+    if (!preg_match(',\.css$,i', $css, $r)) {
2933
+        return $css;
2934
+    }
2935 2935
 
2936
-	$url_absolue_css = url_absolue($css);
2936
+    $url_absolue_css = url_absolue($css);
2937 2937
 
2938
-	$f = basename($css, '.css');
2939
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
2940
-		. preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
2941
-		. '.css';
2938
+    $f = basename($css, '.css');
2939
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
2940
+        . preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
2941
+        . '.css';
2942 2942
 
2943
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
2944
-		return $f;
2945
-	}
2943
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
2944
+        return $f;
2945
+    }
2946 2946
 
2947
-	if ($url_absolue_css == $css) {
2948
-		if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
2949
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
2950
-		) {
2951
-			include_spip('inc/distant');
2952
-			if (!$contenu = recuperer_page($css)) {
2953
-				return $css;
2954
-			}
2955
-		}
2956
-	} elseif (!lire_fichier($css, $contenu)) {
2957
-		return $css;
2958
-	}
2947
+    if ($url_absolue_css == $css) {
2948
+        if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
2949
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
2950
+        ) {
2951
+            include_spip('inc/distant');
2952
+            if (!$contenu = recuperer_page($css)) {
2953
+                return $css;
2954
+            }
2955
+        }
2956
+    } elseif (!lire_fichier($css, $contenu)) {
2957
+        return $css;
2958
+    }
2959 2959
 
2960
-	// passer les url relatives a la css d'origine en url absolues
2961
-	$contenu = urls_absolues_css($contenu, $css);
2960
+    // passer les url relatives a la css d'origine en url absolues
2961
+    $contenu = urls_absolues_css($contenu, $css);
2962 2962
 
2963
-	// ecrire la css
2964
-	if (!ecrire_fichier($f, $contenu)) {
2965
-		return $css;
2966
-	}
2963
+    // ecrire la css
2964
+    if (!ecrire_fichier($f, $contenu)) {
2965
+        return $css;
2966
+    }
2967 2967
 
2968
-	return $f;
2968
+    return $f;
2969 2969
 }
2970 2970
 
2971 2971
 
@@ -2999,24 +2999,24 @@  discard block
 block discarded – undo
2999 2999
  *     Valeur trouvée ou valeur par défaut.
3000 3000
  **/
3001 3001
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3002
-	foreach (explode('/', $cle) as $k) {
3002
+    foreach (explode('/', $cle) as $k) {
3003 3003
 
3004
-		$table = is_string($table) ? @unserialize($table) : $table;
3004
+        $table = is_string($table) ? @unserialize($table) : $table;
3005 3005
 
3006
-		if (is_object($table)) {
3007
-			$table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
3008
-		} elseif (is_array($table)) {
3009
-			if ($conserver_null) {
3010
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3011
-			} else {
3012
-				$table = isset($table[$k]) ? $table[$k] : $defaut;
3013
-			}
3014
-		} else {
3015
-			$table = $defaut;
3016
-		}
3017
-	}
3006
+        if (is_object($table)) {
3007
+            $table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
3008
+        } elseif (is_array($table)) {
3009
+            if ($conserver_null) {
3010
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3011
+            } else {
3012
+                $table = isset($table[$k]) ? $table[$k] : $defaut;
3013
+            }
3014
+        } else {
3015
+            $table = $defaut;
3016
+        }
3017
+    }
3018 3018
 
3019
-	return $table;
3019
+    return $table;
3020 3020
 }
3021 3021
 
3022 3022
 /**
@@ -3049,22 +3049,22 @@  discard block
 block discarded – undo
3049 3049
  *     - string : expression trouvée.
3050 3050
  **/
3051 3051
 function match($texte, $expression, $modif = "UimsS", $capte = 0) {
3052
-	if (intval($modif) and $capte == 0) {
3053
-		$capte = $modif;
3054
-		$modif = "UimsS";
3055
-	}
3056
-	$expression = str_replace("\/", "/", $expression);
3057
-	$expression = str_replace("/", "\/", $expression);
3052
+    if (intval($modif) and $capte == 0) {
3053
+        $capte = $modif;
3054
+        $modif = "UimsS";
3055
+    }
3056
+    $expression = str_replace("\/", "/", $expression);
3057
+    $expression = str_replace("/", "\/", $expression);
3058 3058
 
3059
-	if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3060
-		if (isset($r[$capte])) {
3061
-			return $r[$capte];
3062
-		} else {
3063
-			return true;
3064
-		}
3065
-	}
3059
+    if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3060
+        if (isset($r[$capte])) {
3061
+            return $r[$capte];
3062
+        } else {
3063
+            return true;
3064
+        }
3065
+    }
3066 3066
 
3067
-	return false;
3067
+    return false;
3068 3068
 }
3069 3069
 
3070 3070
 
@@ -3091,10 +3091,10 @@  discard block
 block discarded – undo
3091 3091
  *     Texte
3092 3092
  **/
3093 3093
 function replace($texte, $expression, $replace = '', $modif = "UimsS") {
3094
-	$expression = str_replace("\/", "/", $expression);
3095
-	$expression = str_replace("/", "\/", $expression);
3094
+    $expression = str_replace("\/", "/", $expression);
3095
+    $expression = str_replace("/", "\/", $expression);
3096 3096
 
3097
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3097
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3098 3098
 }
3099 3099
 
3100 3100
 
@@ -3112,21 +3112,21 @@  discard block
 block discarded – undo
3112 3112
  **/
3113 3113
 function traiter_doublons_documents(&$doublons, $letexte) {
3114 3114
 
3115
-	// Verifier dans le texte & les notes (pas beau, helas)
3116
-	$t = $letexte . $GLOBALS['les_notes'];
3115
+    // Verifier dans le texte & les notes (pas beau, helas)
3116
+    $t = $letexte . $GLOBALS['les_notes'];
3117 3117
 
3118
-	if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3119
-		and preg_match_all(
3120
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3121
-			$t, $matches, PREG_PATTERN_ORDER)
3122
-	) {
3123
-		if (!isset($doublons['documents'])) {
3124
-			$doublons['documents'] = "";
3125
-		}
3126
-		$doublons['documents'] .= "," . join(',', $matches[1]);
3127
-	}
3118
+    if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3119
+        and preg_match_all(
3120
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3121
+            $t, $matches, PREG_PATTERN_ORDER)
3122
+    ) {
3123
+        if (!isset($doublons['documents'])) {
3124
+            $doublons['documents'] = "";
3125
+        }
3126
+        $doublons['documents'] .= "," . join(',', $matches[1]);
3127
+    }
3128 3128
 
3129
-	return $letexte;
3129
+    return $letexte;
3130 3130
 }
3131 3131
 
3132 3132
 /**
@@ -3140,7 +3140,7 @@  discard block
 block discarded – undo
3140 3140
  * @return string Chaîne vide
3141 3141
  **/
3142 3142
 function vide($texte) {
3143
-	return "";
3143
+    return "";
3144 3144
 }
3145 3145
 
3146 3146
 //
@@ -3169,23 +3169,23 @@  discard block
 block discarded – undo
3169 3169
  *      Code HTML résultant
3170 3170
  **/
3171 3171
 function env_to_params($env, $ignore_params = array()) {
3172
-	$ignore_params = array_merge(
3173
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3174
-		$ignore_params
3175
-	);
3176
-	if (!is_array($env)) {
3177
-		$env = unserialize($env);
3178
-	}
3179
-	$texte = "";
3180
-	if ($env) {
3181
-		foreach ($env as $i => $j) {
3182
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3183
-				$texte .= "<param name='" . $i . "'\n\tvalue='" . $j . "' />";
3184
-			}
3185
-		}
3186
-	}
3187
-
3188
-	return $texte;
3172
+    $ignore_params = array_merge(
3173
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3174
+        $ignore_params
3175
+    );
3176
+    if (!is_array($env)) {
3177
+        $env = unserialize($env);
3178
+    }
3179
+    $texte = "";
3180
+    if ($env) {
3181
+        foreach ($env as $i => $j) {
3182
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3183
+                $texte .= "<param name='" . $i . "'\n\tvalue='" . $j . "' />";
3184
+            }
3185
+        }
3186
+    }
3187
+
3188
+    return $texte;
3189 3189
 }
3190 3190
 
3191 3191
 /**
@@ -3208,23 +3208,23 @@  discard block
 block discarded – undo
3208 3208
  *      Code HTML résultant
3209 3209
  **/
3210 3210
 function env_to_attributs($env, $ignore_params = array()) {
3211
-	$ignore_params = array_merge(
3212
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3213
-		$ignore_params
3214
-	);
3215
-	if (!is_array($env)) {
3216
-		$env = unserialize($env);
3217
-	}
3218
-	$texte = "";
3219
-	if ($env) {
3220
-		foreach ($env as $i => $j) {
3221
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3222
-				$texte .= $i . "='" . $j . "' ";
3223
-			}
3224
-		}
3225
-	}
3211
+    $ignore_params = array_merge(
3212
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3213
+        $ignore_params
3214
+    );
3215
+    if (!is_array($env)) {
3216
+        $env = unserialize($env);
3217
+    }
3218
+    $texte = "";
3219
+    if ($env) {
3220
+        foreach ($env as $i => $j) {
3221
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3222
+                $texte .= $i . "='" . $j . "' ";
3223
+            }
3224
+        }
3225
+    }
3226 3226
 
3227
-	return $texte;
3227
+    return $texte;
3228 3228
 }
3229 3229
 
3230 3230
 
@@ -3241,9 +3241,9 @@  discard block
 block discarded – undo
3241 3241
  * @return string Chaînes concaténés
3242 3242
  **/
3243 3243
 function concat() {
3244
-	$args = func_get_args();
3244
+    $args = func_get_args();
3245 3245
 
3246
-	return join('', $args);
3246
+    return join('', $args);
3247 3247
 }
3248 3248
 
3249 3249
 
@@ -3263,23 +3263,23 @@  discard block
 block discarded – undo
3263 3263
  *     Contenu du ou des fichiers, concaténé
3264 3264
  **/
3265 3265
 function charge_scripts($files, $script = true) {
3266
-	$flux = "";
3267
-	foreach (is_array($files) ? $files : explode("|", $files) as $file) {
3268
-		if (!is_string($file)) {
3269
-			continue;
3270
-		}
3271
-		if ($script) {
3272
-			$file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
3273
-		}
3274
-		if ($file) {
3275
-			$path = find_in_path($file);
3276
-			if ($path) {
3277
-				$flux .= spip_file_get_contents($path);
3278
-			}
3279
-		}
3280
-	}
3266
+    $flux = "";
3267
+    foreach (is_array($files) ? $files : explode("|", $files) as $file) {
3268
+        if (!is_string($file)) {
3269
+            continue;
3270
+        }
3271
+        if ($script) {
3272
+            $file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
3273
+        }
3274
+        if ($file) {
3275
+            $path = find_in_path($file);
3276
+            if ($path) {
3277
+                $flux .= spip_file_get_contents($path);
3278
+            }
3279
+        }
3280
+    }
3281 3281
 
3282
-	return $flux;
3282
+    return $flux;
3283 3283
 }
3284 3284
 
3285 3285
 
@@ -3299,29 +3299,29 @@  discard block
 block discarded – undo
3299 3299
  * @return string
3300 3300
  */
3301 3301
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = array()) {
3302
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3303
-		$img = chemin_image($img);
3304
-	}
3305
-	if (stripos($atts, 'width') === false) {
3306
-		// utiliser directement l'info de taille presente dans le nom
3307
-		if ((!isset($options['utiliser_suffixe_size']) or $options['utiliser_suffixe_size'] == true)
3308
-			and preg_match(',-([0-9]+)[.](png|gif)$,', $img, $regs)
3309
-		) {
3310
-			$largeur = $hauteur = intval($regs[1]);
3311
-		} else {
3312
-			$taille = taille_image($img);
3313
-			list($hauteur, $largeur) = $taille;
3314
-			if (!$hauteur or !$largeur) {
3315
-				return "";
3316
-			}
3317
-		}
3318
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3319
-	}
3320
-
3321
-	return "<img src='$img' alt='" . attribut_html($alt ? $alt : $title) . "'"
3322
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3323
-	. " " . ltrim($atts)
3324
-	. " />";
3302
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3303
+        $img = chemin_image($img);
3304
+    }
3305
+    if (stripos($atts, 'width') === false) {
3306
+        // utiliser directement l'info de taille presente dans le nom
3307
+        if ((!isset($options['utiliser_suffixe_size']) or $options['utiliser_suffixe_size'] == true)
3308
+            and preg_match(',-([0-9]+)[.](png|gif)$,', $img, $regs)
3309
+        ) {
3310
+            $largeur = $hauteur = intval($regs[1]);
3311
+        } else {
3312
+            $taille = taille_image($img);
3313
+            list($hauteur, $largeur) = $taille;
3314
+            if (!$hauteur or !$largeur) {
3315
+                return "";
3316
+            }
3317
+        }
3318
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3319
+    }
3320
+
3321
+    return "<img src='$img' alt='" . attribut_html($alt ? $alt : $title) . "'"
3322
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3323
+    . " " . ltrim($atts)
3324
+    . " />";
3325 3325
 }
3326 3326
 
3327 3327
 /**
@@ -3332,7 +3332,7 @@  discard block
 block discarded – undo
3332 3332
  * @return string
3333 3333
  */
3334 3334
 function http_style_background($img, $att = '') {
3335
-	return " style='background" . ($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";'";
3335
+    return " style='background" . ($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";'";
3336 3336
 }
3337 3337
 
3338 3338
 /**
@@ -3347,8 +3347,8 @@  discard block
 block discarded – undo
3347 3347
  *     Code HTML de la balise IMG
3348 3348
  */
3349 3349
 function filtre_balise_img_dist($img, $alt = "", $class = "") {
3350
-	return http_img_pack($img, $alt, $class ? " class='" . attribut_html($class) . "'" : '', '',
3351
-		array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3350
+    return http_img_pack($img, $alt, $class ? " class='" . attribut_html($class) . "'" : '', '',
3351
+        array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3352 3352
 }
3353 3353
 
3354 3354
 
@@ -3364,34 +3364,34 @@  discard block
 block discarded – undo
3364 3364
  * @return string
3365 3365
  */
3366 3366
 function filtre_balise_svg_dist($img, $alt = "", $class = "") {
3367
-	if (!$file = find_in_path($img)
3368
-	  or !$svg = file_get_contents($file)) {
3369
-		return '';
3370
-	}
3371
-
3372
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3373
-		return '';
3374
-	}
3375
-	$balise_svg = $match[0];
3376
-	$balise_svg_source = $balise_svg;
3377
-	// IE est toujours mon ami
3378
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3379
-	if ($class) {
3380
-		$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3381
-	}
3382
-	if ($alt){
3383
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3384
-		$id = "img-svg-title-" . substr(md5("$file:$svg:$alt"),0,4);
3385
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3386
-		$title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3387
-		$balise_svg .= $title;
3388
-	}
3389
-	else {
3390
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3391
-	}
3392
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3393
-
3394
-	return $svg;
3367
+    if (!$file = find_in_path($img)
3368
+      or !$svg = file_get_contents($file)) {
3369
+        return '';
3370
+    }
3371
+
3372
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3373
+        return '';
3374
+    }
3375
+    $balise_svg = $match[0];
3376
+    $balise_svg_source = $balise_svg;
3377
+    // IE est toujours mon ami
3378
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3379
+    if ($class) {
3380
+        $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3381
+    }
3382
+    if ($alt){
3383
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3384
+        $id = "img-svg-title-" . substr(md5("$file:$svg:$alt"),0,4);
3385
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3386
+        $title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3387
+        $balise_svg .= $title;
3388
+    }
3389
+    else {
3390
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3391
+    }
3392
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3393
+
3394
+    return $svg;
3395 3395
 }
3396 3396
 
3397 3397
 
@@ -3414,17 +3414,17 @@  discard block
 block discarded – undo
3414 3414
  *     Code HTML résultant
3415 3415
  **/
3416 3416
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3417
-	$texte = '';
3418
-	if (is_array($tableau)) {
3419
-		foreach ($tableau as $k => $v) {
3420
-			$res = recuperer_fond('modeles/' . $modele,
3421
-				array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3422
-			);
3423
-			$texte .= $res;
3424
-		}
3425
-	}
3417
+    $texte = '';
3418
+    if (is_array($tableau)) {
3419
+        foreach ($tableau as $k => $v) {
3420
+            $res = recuperer_fond('modeles/' . $modele,
3421
+                array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3422
+            );
3423
+            $texte .= $res;
3424
+        }
3425
+    }
3426 3426
 
3427
-	return $texte;
3427
+    return $texte;
3428 3428
 }
3429 3429
 
3430 3430
 
@@ -3449,37 +3449,37 @@  discard block
 block discarded – undo
3449 3449
  *         - tout : retourne toutes les informations du plugin actif
3450 3450
  **/
3451 3451
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3452
-	include_spip('inc/plugin');
3453
-	$plugin = strtoupper($plugin);
3454
-	$plugins_actifs = liste_plugin_actifs();
3455
-
3456
-	if (!$plugin) {
3457
-		return serialize(array_keys($plugins_actifs));
3458
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3459
-		return '';
3460
-	} elseif (($type_info == 'est_actif') and !$reload) {
3461
-		return $plugins_actifs[$plugin] ? 1 : 0;
3462
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3463
-		return $plugins_actifs[$plugin][$type_info];
3464
-	} else {
3465
-		$get_infos = charger_fonction('get_infos', 'plugins');
3466
-		// On prend en compte les extensions
3467
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3468
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3469
-		} else {
3470
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3471
-		}
3472
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3473
-			return '';
3474
-		}
3475
-		if ($type_info == 'tout') {
3476
-			return $infos;
3477
-		} elseif ($type_info == 'est_actif') {
3478
-			return $infos ? 1 : 0;
3479
-		} else {
3480
-			return strval($infos[$type_info]);
3481
-		}
3482
-	}
3452
+    include_spip('inc/plugin');
3453
+    $plugin = strtoupper($plugin);
3454
+    $plugins_actifs = liste_plugin_actifs();
3455
+
3456
+    if (!$plugin) {
3457
+        return serialize(array_keys($plugins_actifs));
3458
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3459
+        return '';
3460
+    } elseif (($type_info == 'est_actif') and !$reload) {
3461
+        return $plugins_actifs[$plugin] ? 1 : 0;
3462
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3463
+        return $plugins_actifs[$plugin][$type_info];
3464
+    } else {
3465
+        $get_infos = charger_fonction('get_infos', 'plugins');
3466
+        // On prend en compte les extensions
3467
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3468
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3469
+        } else {
3470
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3471
+        }
3472
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3473
+            return '';
3474
+        }
3475
+        if ($type_info == 'tout') {
3476
+            return $infos;
3477
+        } elseif ($type_info == 'est_actif') {
3478
+            return $infos ? 1 : 0;
3479
+        } else {
3480
+            return strval($infos[$type_info]);
3481
+        }
3482
+    }
3483 3483
 }
3484 3484
 
3485 3485
 
@@ -3506,9 +3506,9 @@  discard block
 block discarded – undo
3506 3506
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3507 3507
  */
3508 3508
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3509
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3509
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3510 3510
 
3511
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3511
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3512 3512
 }
3513 3513
 
3514 3514
 
@@ -3538,13 +3538,13 @@  discard block
 block discarded – undo
3538 3538
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3539 3539
  */
3540 3540
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3541
-	static $puce_statut = null;
3542
-	if (!$puce_statut) {
3543
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3544
-	}
3541
+    static $puce_statut = null;
3542
+    if (!$puce_statut) {
3543
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3544
+    }
3545 3545
 
3546
-	return $puce_statut($id_objet, $statut, $id_parent, $objet, false,
3547
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false);
3546
+    return $puce_statut($id_objet, $statut, $id_parent, $objet, false,
3547
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false);
3548 3548
 }
3549 3549
 
3550 3550
 
@@ -3571,88 +3571,88 @@  discard block
 block discarded – undo
3571 3571
  *   hash du contexte
3572 3572
  */
3573 3573
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3574
-	if (is_string($c)
3575
-		and @unserialize($c) !== false
3576
-	) {
3577
-		$c = unserialize($c);
3578
-	}
3579
-
3580
-	// supprimer les parametres debut_x
3581
-	// pour que la pagination ajax ne soit pas plantee
3582
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3583
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3584
-	if (is_array($c)) {
3585
-		foreach ($c as $k => $v) {
3586
-			if (strpos($k, 'debut_') === 0) {
3587
-				unset($c[$k]);
3588
-			}
3589
-		}
3590
-	}
3591
-
3592
-	if (!function_exists('calculer_cle_action')) {
3593
-		include_spip("inc/securiser_action");
3594
-	}
3595
-
3596
-	$c = serialize($c);
3597
-	$cle = calculer_cle_action($form . $c);
3598
-	$c = "$cle:$c";
3599
-
3600
-	// on ne stocke pas les contextes dans des fichiers caches
3601
-	// par defaut, sauf si cette configuration a ete forcee
3602
-	// OU que la longueur de l''argument generee est plus long
3603
-	// que ce que telere Suhosin.
3604
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3605
-	if (!$cache_contextes_ajax) {
3606
-		$env = $c;
3607
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3608
-			$env = gzdeflate($env);
3609
-			// http://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287
3610
-			if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) {
3611
-				$cache_contextes_ajax = true;
3612
-				spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT);
3613
-			}
3614
-		}
3615
-		$env = _xor($env);
3616
-		$env = base64_encode($env);
3617
-		// tester Suhosin et la valeur maximale des variables en GET...
3618
-		if ($max_len = @ini_get('suhosin.get.max_value_length')
3619
-			and $max_len < ($len = strlen($env))
3620
-		) {
3621
-			$cache_contextes_ajax = true;
3622
-			spip_log("Contextes AJAX forces en fichiers !"
3623
-				. " Cela arrive lorsque la valeur du contexte"
3624
-				. " depasse la longueur maximale autorisee par Suhosin"
3625
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3626
-				. " Vous devriez modifier les parametres de Suhosin"
3627
-				. " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
3628
-		}
3629
-	}
3630
-
3631
-	if ($cache_contextes_ajax) {
3632
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
3633
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
3634
-		$md5 = md5($c);
3635
-		ecrire_fichier("$dir/c$md5", $c);
3636
-		$env = $md5;
3637
-	}
3638
-
3639
-	if ($emboite === null) {
3640
-		return $env;
3641
-	}
3642
-	if (!trim($emboite)) {
3643
-		return "";
3644
-	}
3645
-	// toujours encoder l'url source dans le bloc ajax
3646
-	$r = self();
3647
-	$r = ' data-origin="' . $r . '"';
3648
-	$class = 'ajaxbloc';
3649
-	if ($ajaxid and is_string($ajaxid)) {
3650
-		// ajaxid est normalement conforme a un nom de classe css
3651
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3652
-		$class .= ' ajax-id-' . entites_html($ajaxid);
3653
-	}
3654
-
3655
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3574
+    if (is_string($c)
3575
+        and @unserialize($c) !== false
3576
+    ) {
3577
+        $c = unserialize($c);
3578
+    }
3579
+
3580
+    // supprimer les parametres debut_x
3581
+    // pour que la pagination ajax ne soit pas plantee
3582
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3583
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3584
+    if (is_array($c)) {
3585
+        foreach ($c as $k => $v) {
3586
+            if (strpos($k, 'debut_') === 0) {
3587
+                unset($c[$k]);
3588
+            }
3589
+        }
3590
+    }
3591
+
3592
+    if (!function_exists('calculer_cle_action')) {
3593
+        include_spip("inc/securiser_action");
3594
+    }
3595
+
3596
+    $c = serialize($c);
3597
+    $cle = calculer_cle_action($form . $c);
3598
+    $c = "$cle:$c";
3599
+
3600
+    // on ne stocke pas les contextes dans des fichiers caches
3601
+    // par defaut, sauf si cette configuration a ete forcee
3602
+    // OU que la longueur de l''argument generee est plus long
3603
+    // que ce que telere Suhosin.
3604
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3605
+    if (!$cache_contextes_ajax) {
3606
+        $env = $c;
3607
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3608
+            $env = gzdeflate($env);
3609
+            // http://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287
3610
+            if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) {
3611
+                $cache_contextes_ajax = true;
3612
+                spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT);
3613
+            }
3614
+        }
3615
+        $env = _xor($env);
3616
+        $env = base64_encode($env);
3617
+        // tester Suhosin et la valeur maximale des variables en GET...
3618
+        if ($max_len = @ini_get('suhosin.get.max_value_length')
3619
+            and $max_len < ($len = strlen($env))
3620
+        ) {
3621
+            $cache_contextes_ajax = true;
3622
+            spip_log("Contextes AJAX forces en fichiers !"
3623
+                . " Cela arrive lorsque la valeur du contexte"
3624
+                . " depasse la longueur maximale autorisee par Suhosin"
3625
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3626
+                . " Vous devriez modifier les parametres de Suhosin"
3627
+                . " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
3628
+        }
3629
+    }
3630
+
3631
+    if ($cache_contextes_ajax) {
3632
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
3633
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
3634
+        $md5 = md5($c);
3635
+        ecrire_fichier("$dir/c$md5", $c);
3636
+        $env = $md5;
3637
+    }
3638
+
3639
+    if ($emboite === null) {
3640
+        return $env;
3641
+    }
3642
+    if (!trim($emboite)) {
3643
+        return "";
3644
+    }
3645
+    // toujours encoder l'url source dans le bloc ajax
3646
+    $r = self();
3647
+    $r = ' data-origin="' . $r . '"';
3648
+    $class = 'ajaxbloc';
3649
+    if ($ajaxid and is_string($ajaxid)) {
3650
+        // ajaxid est normalement conforme a un nom de classe css
3651
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3652
+        $class .= ' ajax-id-' . entites_html($ajaxid);
3653
+    }
3654
+
3655
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3656 3656
 }
3657 3657
 
3658 3658
 /**
@@ -3672,36 +3672,36 @@  discard block
 block discarded – undo
3672 3672
  *   - false : erreur de décodage
3673 3673
  */
3674 3674
 function decoder_contexte_ajax($c, $form = '') {
3675
-	if (!function_exists('calculer_cle_action')) {
3676
-		include_spip("inc/securiser_action");
3677
-	}
3678
-	if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
3679
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
3680
-		and lire_fichier("$dir/c$c", $contexte)
3681
-	) {
3682
-		$c = $contexte;
3683
-	} else {
3684
-		$c = @base64_decode($c);
3685
-		$c = _xor($c);
3686
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3687
-			$c = @gzinflate($c);
3688
-		}
3689
-	}
3690
-
3691
-	// extraire la signature en debut de contexte
3692
-	// et la verifier avant de deserializer
3693
-	// format : signature:donneesserializees
3694
-	if ($p = strpos($c,":")){
3695
-		$cle = substr($c,0,$p);
3696
-		$c = substr($c,$p+1);
3697
-
3698
-		if ($cle == calculer_cle_action($form . $c)) {
3699
-			$env = @unserialize($c);
3700
-			return $env;
3701
-		}
3702
-	}
3703
-
3704
-	return false;
3675
+    if (!function_exists('calculer_cle_action')) {
3676
+        include_spip("inc/securiser_action");
3677
+    }
3678
+    if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
3679
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
3680
+        and lire_fichier("$dir/c$c", $contexte)
3681
+    ) {
3682
+        $c = $contexte;
3683
+    } else {
3684
+        $c = @base64_decode($c);
3685
+        $c = _xor($c);
3686
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3687
+            $c = @gzinflate($c);
3688
+        }
3689
+    }
3690
+
3691
+    // extraire la signature en debut de contexte
3692
+    // et la verifier avant de deserializer
3693
+    // format : signature:donneesserializees
3694
+    if ($p = strpos($c,":")){
3695
+        $cle = substr($c,0,$p);
3696
+        $c = substr($c,$p+1);
3697
+
3698
+        if ($cle == calculer_cle_action($form . $c)) {
3699
+            $env = @unserialize($c);
3700
+            return $env;
3701
+        }
3702
+    }
3703
+
3704
+    return false;
3705 3705
 }
3706 3706
 
3707 3707
 
@@ -3719,20 +3719,20 @@  discard block
 block discarded – undo
3719 3719
  *    Message décrypté ou encrypté
3720 3720
  **/
3721 3721
 function _xor($message, $key = null) {
3722
-	if (is_null($key)) {
3723
-		if (!function_exists('calculer_cle_action')) {
3724
-			include_spip("inc/securiser_action");
3725
-		}
3726
-		$key = pack("H*", calculer_cle_action('_xor'));
3727
-	}
3722
+    if (is_null($key)) {
3723
+        if (!function_exists('calculer_cle_action')) {
3724
+            include_spip("inc/securiser_action");
3725
+        }
3726
+        $key = pack("H*", calculer_cle_action('_xor'));
3727
+    }
3728 3728
 
3729
-	$keylen = strlen($key);
3730
-	$messagelen = strlen($message);
3731
-	for ($i = 0; $i < $messagelen; $i++) {
3732
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
3733
-	}
3729
+    $keylen = strlen($key);
3730
+    $messagelen = strlen($message);
3731
+    for ($i = 0; $i < $messagelen; $i++) {
3732
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
3733
+    }
3734 3734
 
3735
-	return $message;
3735
+    return $message;
3736 3736
 }
3737 3737
 
3738 3738
 /**
@@ -3790,22 +3790,22 @@  discard block
 block discarded – undo
3790 3790
  *   Code HTML
3791 3791
  */
3792 3792
 function lien_ou_expose($url, $libelle = null, $on = false, $class = "", $title = "", $rel = "", $evt = '') {
3793
-	if ($on) {
3794
-		$bal = "strong";
3795
-		$att = "class='on'";
3796
-	} else {
3797
-		$bal = 'a';
3798
-		$att = "href='$url'"
3799
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
3800
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
3801
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
3802
-			. $evt;
3803
-	}
3804
-	if ($libelle === null) {
3805
-		$libelle = $url;
3806
-	}
3793
+    if ($on) {
3794
+        $bal = "strong";
3795
+        $att = "class='on'";
3796
+    } else {
3797
+        $bal = 'a';
3798
+        $att = "href='$url'"
3799
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
3800
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
3801
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
3802
+            . $evt;
3803
+    }
3804
+    if ($libelle === null) {
3805
+        $libelle = $url;
3806
+    }
3807 3807
 
3808
-	return "<$bal $att>$libelle</$bal>";
3808
+    return "<$bal $att>$libelle</$bal>";
3809 3809
 }
3810 3810
 
3811 3811
 
@@ -3822,18 +3822,18 @@  discard block
 block discarded – undo
3822 3822
  * @return string : la chaine de langue finale en utilisant la fonction _T()
3823 3823
  */
3824 3824
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = array()) {
3825
-	if (!$nb = intval($nb)) {
3826
-		return "";
3827
-	}
3828
-	if (!is_array($vars)) {
3829
-		return "";
3830
-	}
3831
-	$vars[$var] = $nb;
3832
-	if ($nb > 1) {
3833
-		return _T($chaine_plusieurs, $vars);
3834
-	} else {
3835
-		return _T($chaine_un, $vars);
3836
-	}
3825
+    if (!$nb = intval($nb)) {
3826
+        return "";
3827
+    }
3828
+    if (!is_array($vars)) {
3829
+        return "";
3830
+    }
3831
+    $vars[$var] = $nb;
3832
+    if ($nb > 1) {
3833
+        return _T($chaine_plusieurs, $vars);
3834
+    } else {
3835
+        return _T($chaine_un, $vars);
3836
+    }
3837 3837
 }
3838 3838
 
3839 3839
 
@@ -3858,60 +3858,60 @@  discard block
 block discarded – undo
3858 3858
  * @return string
3859 3859
  */
3860 3860
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
3861
-	if (in_array($fonction, array("del", "supprimer.gif"))) {
3862
-		$class .= ' danger';
3863
-	} elseif ($fonction == "rien.gif") {
3864
-		$fonction = "";
3865
-	} elseif ($fonction == "delsafe") {
3866
-		$fonction = "del";
3867
-	}
3868
-
3869
-	// remappage des icone : article-24.png+new => article-new-24.png
3870
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
3871
-		list($fond, $fonction) = $icone_renommer($fond, $fonction);
3872
-	}
3873
-
3874
-	// ajouter le type d'objet dans la class de l'icone
3875
-	$class .= " " . substr(basename($fond), 0, -4);
3876
-
3877
-	$alt = attribut_html($texte);
3878
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
3879
-
3880
-	$ajax = "";
3881
-	if (strpos($class, "ajax") !== false) {
3882
-		$ajax = "ajax";
3883
-		if (strpos($class, "preload") !== false) {
3884
-			$ajax .= " preload";
3885
-		}
3886
-		if (strpos($class, "nocache") !== false) {
3887
-			$ajax .= " nocache";
3888
-		}
3889
-		$ajax = " class='$ajax'";
3890
-	}
3891
-
3892
-	$size = 24;
3893
-	if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i", $fond, $match)) {
3894
-		$size = $match[1];
3895
-	}
3896
-
3897
-	if ($fonction) {
3898
-		// 2 images pour composer l'icone : le fond (article) en background,
3899
-		// la fonction (new) en image
3900
-		$icone = http_img_pack($fonction, $alt, "width='$size' height='$size'\n" .
3901
-			http_style_background($fond));
3902
-	} else {
3903
-		$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
3904
-	}
3905
-
3906
-	if ($type == 'lien') {
3907
-		return "<span class='icone s$size $class'>"
3908
-		. "<a href='$lien'$title$ajax$javascript>"
3909
-		. $icone
3910
-		. "<b>$texte</b>"
3911
-		. "</a></span>\n";
3912
-	} else {
3913
-		return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt);
3914
-	}
3861
+    if (in_array($fonction, array("del", "supprimer.gif"))) {
3862
+        $class .= ' danger';
3863
+    } elseif ($fonction == "rien.gif") {
3864
+        $fonction = "";
3865
+    } elseif ($fonction == "delsafe") {
3866
+        $fonction = "del";
3867
+    }
3868
+
3869
+    // remappage des icone : article-24.png+new => article-new-24.png
3870
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
3871
+        list($fond, $fonction) = $icone_renommer($fond, $fonction);
3872
+    }
3873
+
3874
+    // ajouter le type d'objet dans la class de l'icone
3875
+    $class .= " " . substr(basename($fond), 0, -4);
3876
+
3877
+    $alt = attribut_html($texte);
3878
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
3879
+
3880
+    $ajax = "";
3881
+    if (strpos($class, "ajax") !== false) {
3882
+        $ajax = "ajax";
3883
+        if (strpos($class, "preload") !== false) {
3884
+            $ajax .= " preload";
3885
+        }
3886
+        if (strpos($class, "nocache") !== false) {
3887
+            $ajax .= " nocache";
3888
+        }
3889
+        $ajax = " class='$ajax'";
3890
+    }
3891
+
3892
+    $size = 24;
3893
+    if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i", $fond, $match)) {
3894
+        $size = $match[1];
3895
+    }
3896
+
3897
+    if ($fonction) {
3898
+        // 2 images pour composer l'icone : le fond (article) en background,
3899
+        // la fonction (new) en image
3900
+        $icone = http_img_pack($fonction, $alt, "width='$size' height='$size'\n" .
3901
+            http_style_background($fond));
3902
+    } else {
3903
+        $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
3904
+    }
3905
+
3906
+    if ($type == 'lien') {
3907
+        return "<span class='icone s$size $class'>"
3908
+        . "<a href='$lien'$title$ajax$javascript>"
3909
+        . $icone
3910
+        . "<b>$texte</b>"
3911
+        . "</a></span>\n";
3912
+    } else {
3913
+        return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt);
3914
+    }
3915 3915
 }
3916 3916
 
3917 3917
 /**
@@ -3935,7 +3935,7 @@  discard block
 block discarded – undo
3935 3935
  *     Code HTML du lien
3936 3936
  **/
3937 3937
 function icone_base($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
3938
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
3938
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
3939 3939
 }
3940 3940
 
3941 3941
 /**
@@ -3970,7 +3970,7 @@  discard block
 block discarded – undo
3970 3970
  *     Code HTML du lien
3971 3971
  **/
3972 3972
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
3973
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
3973
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
3974 3974
 }
3975 3975
 
3976 3976
 /**
@@ -4015,7 +4015,7 @@  discard block
 block discarded – undo
4015 4015
  *     Code HTML du lien
4016 4016
  **/
4017 4017
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4018
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4018
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4019 4019
 }
4020 4020
 
4021 4021
 /**
@@ -4046,7 +4046,7 @@  discard block
 block discarded – undo
4046 4046
  *     Code HTML du lien
4047 4047
  **/
4048 4048
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = "", $class = "", $confirm = "") {
4049
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm);
4049
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm);
4050 4050
 }
4051 4051
 
4052 4052
 /**
@@ -4076,7 +4076,7 @@  discard block
 block discarded – undo
4076 4076
  *     Code HTML du lien
4077 4077
  */
4078 4078
 function filtre_icone_dist($lien, $texte, $fond, $align = "", $fonction = "", $class = "", $javascript = "") {
4079
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4079
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4080 4080
 }
4081 4081
 
4082 4082
 
@@ -4124,26 +4124,26 @@  discard block
 block discarded – undo
4124 4124
  * @return string Code CSS
4125 4125
  */
4126 4126
 function bando_images_background() {
4127
-	include_spip('inc/bandeau');
4128
-	// recuperer tous les boutons et leurs images
4129
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4127
+    include_spip('inc/bandeau');
4128
+    // recuperer tous les boutons et leurs images
4129
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4130 4130
 
4131
-	$res = "";
4132
-	foreach ($boutons as $page => $detail) {
4133
-		if ($detail->icone and strlen(trim($detail->icone))) {
4134
-			$res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}";
4135
-		}
4136
-		$selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4137
-		if (is_array($detail->sousmenu)) {
4138
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4139
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4140
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4141
-				}
4142
-			}
4143
-		}
4144
-	}
4131
+    $res = "";
4132
+    foreach ($boutons as $page => $detail) {
4133
+        if ($detail->icone and strlen(trim($detail->icone))) {
4134
+            $res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}";
4135
+        }
4136
+        $selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4137
+        if (is_array($detail->sousmenu)) {
4138
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4139
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4140
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4141
+                }
4142
+            }
4143
+        }
4144
+    }
4145 4145
 
4146
-	return $res;
4146
+    return $res;
4147 4147
 }
4148 4148
 
4149 4149
 /**
@@ -4162,19 +4162,19 @@  discard block
 block discarded – undo
4162 4162
  * @return string
4163 4163
  */
4164 4164
 function bouton_action($libelle, $url, $class = "", $confirm = "", $title = "", $callback = "") {
4165
-	if ($confirm) {
4166
-		$confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4167
-		if ($callback) {
4168
-			$callback = "$confirm?($callback):false";
4169
-		} else {
4170
-			$callback = $confirm;
4171
-		}
4172
-	}
4173
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4174
-	$title = $title ? " title='$title'" : "";
4165
+    if ($confirm) {
4166
+        $confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4167
+        if ($callback) {
4168
+            $callback = "$confirm?($callback):false";
4169
+        } else {
4170
+            $callback = $confirm;
4171
+        }
4172
+    }
4173
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4174
+    $title = $title ? " title='$title'" : "";
4175 4175
 
4176
-	return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url)
4177
-	. "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
4176
+    return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url)
4177
+    . "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
4178 4178
 }
4179 4179
 
4180 4180
 
@@ -4186,7 +4186,7 @@  discard block
 block discarded – undo
4186 4186
  * @return string
4187 4187
  */
4188 4188
 function tri_protege_champ($t) {
4189
-	return preg_replace(',[^\s\w.+],', '', $t);
4189
+    return preg_replace(',[^\s\w.+],', '', $t);
4190 4190
 }
4191 4191
 
4192 4192
 /**
@@ -4199,34 +4199,34 @@  discard block
 block discarded – undo
4199 4199
  * @return string
4200 4200
  */
4201 4201
 function tri_champ_order($t, $from = null) {
4202
-	if (strncmp($t, 'multi ', 6) == 0) {
4203
-		return "multi";
4204
-	}
4205
-
4206
-	$champ = $t;
4207
-
4208
-	if (strncmp($t, 'num ', 4) == 0) {
4209
-		$champ = substr($t, 4);
4210
-	}
4211
-	// enlever les autres espaces non evacues par tri_protege_champ
4212
-	$champ = preg_replace(',\s,', '', $champ);
4213
-
4214
-	if (is_array($from)) {
4215
-		$trouver_table = charger_fonction('trouver_table', 'base');
4216
-		foreach ($from as $idt => $table_sql) {
4217
-			if ($desc = $trouver_table($table_sql)
4218
-				and isset($desc['field'][$champ])
4219
-			) {
4220
-				$champ = "$idt.$champ";
4221
-				break;
4222
-			}
4223
-		}
4224
-	}
4225
-	if (strncmp($t, 'num ', 4) == 0) {
4226
-		return "0+$champ";
4227
-	} else {
4228
-		return $champ;
4229
-	}
4202
+    if (strncmp($t, 'multi ', 6) == 0) {
4203
+        return "multi";
4204
+    }
4205
+
4206
+    $champ = $t;
4207
+
4208
+    if (strncmp($t, 'num ', 4) == 0) {
4209
+        $champ = substr($t, 4);
4210
+    }
4211
+    // enlever les autres espaces non evacues par tri_protege_champ
4212
+    $champ = preg_replace(',\s,', '', $champ);
4213
+
4214
+    if (is_array($from)) {
4215
+        $trouver_table = charger_fonction('trouver_table', 'base');
4216
+        foreach ($from as $idt => $table_sql) {
4217
+            if ($desc = $trouver_table($table_sql)
4218
+                and isset($desc['field'][$champ])
4219
+            ) {
4220
+                $champ = "$idt.$champ";
4221
+                break;
4222
+            }
4223
+        }
4224
+    }
4225
+    if (strncmp($t, 'num ', 4) == 0) {
4226
+        return "0+$champ";
4227
+    } else {
4228
+        return $champ;
4229
+    }
4230 4230
 }
4231 4231
 
4232 4232
 /**
@@ -4240,18 +4240,18 @@  discard block
 block discarded – undo
4240 4240
  * @return string
4241 4241
  */
4242 4242
 function tri_champ_select($t) {
4243
-	if (strncmp($t, 'multi ', 6) == 0) {
4244
-		$t = substr($t, 6);
4245
-		$t = preg_replace(',\s,', '', $t);
4246
-		$t = sql_multi($t, $GLOBALS['spip_lang']);
4243
+    if (strncmp($t, 'multi ', 6) == 0) {
4244
+        $t = substr($t, 6);
4245
+        $t = preg_replace(',\s,', '', $t);
4246
+        $t = sql_multi($t, $GLOBALS['spip_lang']);
4247 4247
 
4248
-		return $t;
4249
-	}
4250
-	if (trim($t) == 'hasard') {
4251
-		return 'rand() AS hasard';
4252
-	}
4248
+        return $t;
4249
+    }
4250
+    if (trim($t) == 'hasard') {
4251
+        return 'rand() AS hasard';
4252
+    }
4253 4253
 
4254
-	return "''";
4254
+    return "''";
4255 4255
 }
4256 4256
 
4257 4257
 
@@ -4273,78 +4273,78 @@  discard block
 block discarded – undo
4273 4273
  * @return string
4274 4274
  */
4275 4275
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = "") {
4276
-	static $trouver_table = null;
4277
-	static $objets;
4278
-
4279
-	// On verifie qu'on a tout ce qu'il faut
4280
-	$id_objet = intval($id_objet);
4281
-	if (!($id_objet and $type_objet and $info)) {
4282
-		return '';
4283
-	}
4284
-
4285
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4286
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4287
-		return '';
4288
-	}
4289
-
4290
-	// Si on demande l'url, on retourne direct la fonction
4291
-	if ($info == 'url') {
4292
-		return generer_url_entite($id_objet, $type_objet);
4293
-	}
4294
-
4295
-	// Sinon on va tout chercher dans la table et on garde en memoire
4296
-	$demande_titre = ($info == 'titre');
4297
-
4298
-	// On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore
4299
-	if (!isset($objets[$type_objet][$id_objet])
4300
-		or
4301
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4302
-	) {
4303
-		if (!$trouver_table) {
4304
-			$trouver_table = charger_fonction('trouver_table', 'base');
4305
-		}
4306
-		$desc = $trouver_table(table_objet_sql($type_objet));
4307
-		if (!$desc) {
4308
-			return $objets[$type_objet] = false;
4309
-		}
4310
-
4311
-		// Si on demande le titre, on le gere en interne
4312
-		$champ_titre = "";
4313
-		if ($demande_titre) {
4314
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4315
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4316
-		}
4317
-		include_spip('base/abstract_sql');
4318
-		include_spip('base/connect_sql');
4319
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4320
-			'*' . $champ_titre,
4321
-			$desc['table_sql'],
4322
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4323
-		);
4324
-	}
4325
-
4326
-	// Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4327
-	if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4328
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
4329
-	} // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4330
-	else {
4331
-		if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4332
-			$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
4333
-		} // Sinon on prend directement le champ SQL tel quel
4334
-		else {
4335
-			$info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4336
-		}
4337
-	}
4338
-
4339
-	// On va ensuite appliquer les traitements automatiques si besoin
4340
-	if (!$etoile) {
4341
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4342
-		// mais ce fonctionnement est a ameliorer !
4343
-		$info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet),
4344
-			array('id_objet' => $id_objet, 'objet' => $type_objet, ''));
4345
-	}
4346
-
4347
-	return $info_generee;
4276
+    static $trouver_table = null;
4277
+    static $objets;
4278
+
4279
+    // On verifie qu'on a tout ce qu'il faut
4280
+    $id_objet = intval($id_objet);
4281
+    if (!($id_objet and $type_objet and $info)) {
4282
+        return '';
4283
+    }
4284
+
4285
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4286
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4287
+        return '';
4288
+    }
4289
+
4290
+    // Si on demande l'url, on retourne direct la fonction
4291
+    if ($info == 'url') {
4292
+        return generer_url_entite($id_objet, $type_objet);
4293
+    }
4294
+
4295
+    // Sinon on va tout chercher dans la table et on garde en memoire
4296
+    $demande_titre = ($info == 'titre');
4297
+
4298
+    // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore
4299
+    if (!isset($objets[$type_objet][$id_objet])
4300
+        or
4301
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4302
+    ) {
4303
+        if (!$trouver_table) {
4304
+            $trouver_table = charger_fonction('trouver_table', 'base');
4305
+        }
4306
+        $desc = $trouver_table(table_objet_sql($type_objet));
4307
+        if (!$desc) {
4308
+            return $objets[$type_objet] = false;
4309
+        }
4310
+
4311
+        // Si on demande le titre, on le gere en interne
4312
+        $champ_titre = "";
4313
+        if ($demande_titre) {
4314
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4315
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4316
+        }
4317
+        include_spip('base/abstract_sql');
4318
+        include_spip('base/connect_sql');
4319
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4320
+            '*' . $champ_titre,
4321
+            $desc['table_sql'],
4322
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4323
+        );
4324
+    }
4325
+
4326
+    // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4327
+    if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4328
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
4329
+    } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4330
+    else {
4331
+        if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4332
+            $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
4333
+        } // Sinon on prend directement le champ SQL tel quel
4334
+        else {
4335
+            $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4336
+        }
4337
+    }
4338
+
4339
+    // On va ensuite appliquer les traitements automatiques si besoin
4340
+    if (!$etoile) {
4341
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4342
+        // mais ce fonctionnement est a ameliorer !
4343
+        $info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet),
4344
+            array('id_objet' => $id_objet, 'objet' => $type_objet, ''));
4345
+    }
4346
+
4347
+    return $info_generee;
4348 4348
 }
4349 4349
 
4350 4350
 /**
@@ -4358,44 +4358,44 @@  discard block
 block discarded – undo
4358 4358
  * @return string
4359 4359
  */
4360 4360
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = array(), $connect = '') {
4361
-	if (!$champ) {
4362
-		return $texte;
4363
-	}
4361
+    if (!$champ) {
4362
+        return $texte;
4363
+    }
4364 4364
 	
4365
-	// On charge toujours les filtres de texte car la majorité des traitements les utilisent
4366
-	// et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4367
-	include_spip('inc/texte');
4365
+    // On charge toujours les filtres de texte car la majorité des traitements les utilisent
4366
+    // et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4367
+    include_spip('inc/texte');
4368 4368
 	
4369
-	$champ = strtoupper($champ);
4370
-	$traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4371
-	if (!$traitements or !is_array($traitements)) {
4372
-		return $texte;
4373
-	}
4369
+    $champ = strtoupper($champ);
4370
+    $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4371
+    if (!$traitements or !is_array($traitements)) {
4372
+        return $texte;
4373
+    }
4374 4374
 
4375
-	$traitement = '';
4376
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4377
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4378
-		$table_objet = table_objet($table_objet);
4379
-		if (isset($traitements[$table_objet])) {
4380
-			$traitement = $traitements[$table_objet];
4381
-		}
4382
-	}
4383
-	if (!$traitement and isset($traitements[0])) {
4384
-		$traitement = $traitements[0];
4385
-	}
4386
-	// (sinon prendre le premier de la liste par defaut ?)
4375
+    $traitement = '';
4376
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4377
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4378
+        $table_objet = table_objet($table_objet);
4379
+        if (isset($traitements[$table_objet])) {
4380
+            $traitement = $traitements[$table_objet];
4381
+        }
4382
+    }
4383
+    if (!$traitement and isset($traitements[0])) {
4384
+        $traitement = $traitements[0];
4385
+    }
4386
+    // (sinon prendre le premier de la liste par defaut ?)
4387 4387
 
4388
-	if (!$traitement) {
4389
-		return $texte;
4390
-	}
4388
+    if (!$traitement) {
4389
+        return $texte;
4390
+    }
4391 4391
 
4392
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4392
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4393 4393
 
4394
-	// Fournir $connect et $Pile[0] au traitement si besoin
4395
-	$Pile = array(0 => $env);
4396
-	eval("\$texte = $traitement;");
4394
+    // Fournir $connect et $Pile[0] au traitement si besoin
4395
+    $Pile = array(0 => $env);
4396
+    eval("\$texte = $traitement;");
4397 4397
 
4398
-	return $texte;
4398
+    return $texte;
4399 4399
 }
4400 4400
 
4401 4401
 
@@ -4409,21 +4409,21 @@  discard block
 block discarded – undo
4409 4409
  * @return string
4410 4410
  */
4411 4411
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4412
-	include_spip('inc/liens');
4413
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4414
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4415
-	// le raccourcis n'est plus valide
4416
-	$titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4417
-	// on essaye avec generer_info_entite ?
4418
-	if (!strlen($titre) and !$connect) {
4419
-		$titre = generer_info_entite($id_objet, $objet, 'titre');
4420
-	}
4421
-	if (!strlen($titre)) {
4422
-		$titre = _T('info_sans_titre');
4423
-	}
4424
-	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4412
+    include_spip('inc/liens');
4413
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4414
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4415
+    // le raccourcis n'est plus valide
4416
+    $titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4417
+    // on essaye avec generer_info_entite ?
4418
+    if (!strlen($titre) and !$connect) {
4419
+        $titre = generer_info_entite($id_objet, $objet, 'titre');
4420
+    }
4421
+    if (!strlen($titre)) {
4422
+        $titre = _T('info_sans_titre');
4423
+    }
4424
+    $url = generer_url_entite($id_objet, $objet, '', '', $connect);
4425 4425
 
4426
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4426
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4427 4427
 }
4428 4428
 
4429 4429
 
@@ -4440,15 +4440,15 @@  discard block
 block discarded – undo
4440 4440
  * @return string
4441 4441
  */
4442 4442
 function wrap($texte, $wrap) {
4443
-	$balises = extraire_balises($wrap);
4444
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4445
-		$texte = $wrap . $texte;
4446
-		$regs = array_reverse($regs[1]);
4447
-		$wrap = "</" . implode("></", $regs) . ">";
4448
-		$texte = $texte . $wrap;
4449
-	}
4443
+    $balises = extraire_balises($wrap);
4444
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4445
+        $texte = $wrap . $texte;
4446
+        $regs = array_reverse($regs[1]);
4447
+        $wrap = "</" . implode("></", $regs) . ">";
4448
+        $texte = $texte . $wrap;
4449
+    }
4450 4450
 
4451
-	return $texte;
4451
+    return $texte;
4452 4452
 }
4453 4453
 
4454 4454
 
@@ -4468,43 +4468,43 @@  discard block
 block discarded – undo
4468 4468
  * @return array|mixed|string
4469 4469
  */
4470 4470
 function filtre_print_dist($u, $join = "<br />", $indent = 0) {
4471
-	if (is_string($u)) {
4472
-		$u = typo($u);
4471
+    if (is_string($u)) {
4472
+        $u = typo($u);
4473 4473
 
4474
-		return $u;
4475
-	}
4474
+        return $u;
4475
+    }
4476 4476
 
4477
-	// caster $u en array si besoin
4478
-	if (is_object($u)) {
4479
-		$u = (array)$u;
4480
-	}
4477
+    // caster $u en array si besoin
4478
+    if (is_object($u)) {
4479
+        $u = (array)$u;
4480
+    }
4481 4481
 
4482
-	if (is_array($u)) {
4483
-		$out = "";
4484
-		// toutes les cles sont numeriques ?
4485
-		// et aucun enfant n'est un tableau
4486
-		// liste simple separee par des virgules
4487
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4488
-		$array_values = array_map('is_array', $u);
4489
-		$object_values = array_map('is_object', $u);
4490
-		if (array_sum($numeric_keys) == count($numeric_keys)
4491
-			and !array_sum($array_values)
4492
-			and !array_sum($object_values)
4493
-		) {
4494
-			return join(", ", array_map('filtre_print_dist', $u));
4495
-		}
4482
+    if (is_array($u)) {
4483
+        $out = "";
4484
+        // toutes les cles sont numeriques ?
4485
+        // et aucun enfant n'est un tableau
4486
+        // liste simple separee par des virgules
4487
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4488
+        $array_values = array_map('is_array', $u);
4489
+        $object_values = array_map('is_object', $u);
4490
+        if (array_sum($numeric_keys) == count($numeric_keys)
4491
+            and !array_sum($array_values)
4492
+            and !array_sum($object_values)
4493
+        ) {
4494
+            return join(", ", array_map('filtre_print_dist', $u));
4495
+        }
4496 4496
 
4497
-		// sinon on passe a la ligne et on indente
4498
-		$i_str = str_pad("", $indent, " ");
4499
-		foreach ($u as $k => $v) {
4500
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4501
-		}
4497
+        // sinon on passe a la ligne et on indente
4498
+        $i_str = str_pad("", $indent, " ");
4499
+        foreach ($u as $k => $v) {
4500
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4501
+        }
4502 4502
 
4503
-		return $out;
4504
-	}
4503
+        return $out;
4504
+    }
4505 4505
 
4506
-	// on sait pas quoi faire...
4507
-	return $u;
4506
+    // on sait pas quoi faire...
4507
+    return $u;
4508 4508
 }
4509 4509
 
4510 4510
 
@@ -4517,10 +4517,10 @@  discard block
 block discarded – undo
4517 4517
  * @return string
4518 4518
  */
4519 4519
 function objet_info($objet, $info) {
4520
-	$table = table_objet_sql($objet);
4521
-	$infos = lister_tables_objets_sql($table);
4520
+    $table = table_objet_sql($objet);
4521
+    $infos = lister_tables_objets_sql($table);
4522 4522
 
4523
-	return (isset($infos[$info]) ? $infos[$info] : '');
4523
+    return (isset($infos[$info]) ? $infos[$info] : '');
4524 4524
 }
4525 4525
 
4526 4526
 /**
@@ -4535,11 +4535,11 @@  discard block
 block discarded – undo
4535 4535
  *     Texte traduit du comptage, tel que '3 articles'
4536 4536
  */
4537 4537
 function objet_afficher_nb($nb, $objet) {
4538
-	if (!$nb) {
4539
-		return _T(objet_info($objet, 'info_aucun_objet'));
4540
-	} else {
4541
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb));
4542
-	}
4538
+    if (!$nb) {
4539
+        return _T(objet_info($objet, 'info_aucun_objet'));
4540
+    } else {
4541
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb));
4542
+    }
4543 4543
 }
4544 4544
 
4545 4545
 /**
@@ -4550,11 +4550,11 @@  discard block
 block discarded – undo
4550 4550
  * @return string
4551 4551
  */
4552 4552
 function objet_icone($objet, $taille = 24) {
4553
-	$icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4554
-	$icone = chemin_image($icone);
4555
-	$balise_img = charger_filtre('balise_img');
4553
+    $icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4554
+    $icone = chemin_image($icone);
4555
+    $balise_img = charger_filtre('balise_img');
4556 4556
 
4557
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet'))) : '';
4557
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet'))) : '';
4558 4558
 }
4559 4559
 
4560 4560
 /**
@@ -4575,12 +4575,12 @@  discard block
 block discarded – undo
4575 4575
  * @return string
4576 4576
  */
4577 4577
 function objet_T($objet, $chaine, $args = array(), $options = array()){
4578
-	$chaine = explode(':',$chaine);
4579
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4580
-		return $t;
4581
-	}
4582
-	$chaine = implode(':',$chaine);
4583
-	return _T($chaine, $args, $options);
4578
+    $chaine = explode(':',$chaine);
4579
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4580
+        return $t;
4581
+    }
4582
+    $chaine = implode(':',$chaine);
4583
+    return _T($chaine, $args, $options);
4584 4584
 }
4585 4585
 
4586 4586
 /**
@@ -4594,17 +4594,17 @@  discard block
 block discarded – undo
4594 4594
  * @return string      Code HTML
4595 4595
  */
4596 4596
 function insert_head_css_conditionnel($flux) {
4597
-	if (strpos($flux, '<!-- insert_head_css -->') === false
4598
-		and $p = strpos($flux, '<!-- insert_head -->')
4599
-	) {
4600
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
4601
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
4602
-			$p = $p1;
4603
-		}
4604
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4605
-	}
4597
+    if (strpos($flux, '<!-- insert_head_css -->') === false
4598
+        and $p = strpos($flux, '<!-- insert_head -->')
4599
+    ) {
4600
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
4601
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
4602
+            $p = $p1;
4603
+        }
4604
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4605
+    }
4606 4606
 
4607
-	return $flux;
4607
+    return $flux;
4608 4608
 }
4609 4609
 
4610 4610
 /**
@@ -4625,66 +4625,66 @@  discard block
 block discarded – undo
4625 4625
  * @return string
4626 4626
  */
4627 4627
 function produire_fond_statique($fond, $contexte = array(), $options = array(), $connect = '') {
4628
-	if (isset($contexte['format'])) {
4629
-		$extension = $contexte['format'];
4630
-		unset($contexte['format']);
4631
-	} else {
4632
-		$extension = "html";
4633
-		if (preg_match(',[.](css|js|json)$,', $fond, $m)) {
4634
-			$extension = $m[1];
4635
-		}
4636
-	}
4637
-	// recuperer le contenu produit par le squelette
4638
-	$options['raw'] = true;
4639
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
4640
-
4641
-	// calculer le nom de la css
4642
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4643
-	$nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4644
-	$contexte_implicite = calculer_contexte_implicite();
4645
-	$filename = $dir_var . $extension . "dyn-$nom_safe-"
4646
-		. substr(md5($fond . serialize($contexte_implicite) . serialize($contexte) . $connect), 0, 8)
4647
-		. ".$extension";
4648
-
4649
-	// mettre a jour le fichier si il n'existe pas
4650
-	// ou trop ancien
4651
-	// le dernier fichier produit est toujours suffixe par .last
4652
-	// et recopie sur le fichier cible uniquement si il change
4653
-	if (!file_exists($filename)
4654
-		or !file_exists($filename . ".last")
4655
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4656
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4657
-	) {
4658
-		$contenu = $cache['texte'];
4659
-		// passer les urls en absolu si c'est une css
4660
-		if ($extension == "css") {
4661
-			$contenu = urls_absolues_css($contenu,
4662
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond));
4663
-		}
4664
-
4665
-		$comment = '';
4666
-		// ne pas insérer de commentaire si c'est du json
4667
-		if ($extension != "json") {
4668
-			$comment = "/* #PRODUIRE{fond=$fond";
4669
-			foreach ($contexte as $k => $v) {
4670
-				$comment .= ",$k=$v";
4671
-			}
4672
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4673
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4674
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
4675
-		}
4676
-		// et ecrire le fichier
4677
-		ecrire_fichier($filename . ".last", $comment . $contenu);
4678
-		// regarder si on recopie
4679
-		if (!file_exists($filename)
4680
-			or md5_file($filename) !== md5_file($filename . ".last")
4681
-		) {
4682
-			@copy($filename . ".last", $filename);
4683
-			clearstatcache(true, $filename); // eviter que PHP ne reserve le vieux timestamp
4684
-		}
4685
-	}
4686
-
4687
-	return timestamp($filename);
4628
+    if (isset($contexte['format'])) {
4629
+        $extension = $contexte['format'];
4630
+        unset($contexte['format']);
4631
+    } else {
4632
+        $extension = "html";
4633
+        if (preg_match(',[.](css|js|json)$,', $fond, $m)) {
4634
+            $extension = $m[1];
4635
+        }
4636
+    }
4637
+    // recuperer le contenu produit par le squelette
4638
+    $options['raw'] = true;
4639
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
4640
+
4641
+    // calculer le nom de la css
4642
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4643
+    $nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4644
+    $contexte_implicite = calculer_contexte_implicite();
4645
+    $filename = $dir_var . $extension . "dyn-$nom_safe-"
4646
+        . substr(md5($fond . serialize($contexte_implicite) . serialize($contexte) . $connect), 0, 8)
4647
+        . ".$extension";
4648
+
4649
+    // mettre a jour le fichier si il n'existe pas
4650
+    // ou trop ancien
4651
+    // le dernier fichier produit est toujours suffixe par .last
4652
+    // et recopie sur le fichier cible uniquement si il change
4653
+    if (!file_exists($filename)
4654
+        or !file_exists($filename . ".last")
4655
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4656
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4657
+    ) {
4658
+        $contenu = $cache['texte'];
4659
+        // passer les urls en absolu si c'est une css
4660
+        if ($extension == "css") {
4661
+            $contenu = urls_absolues_css($contenu,
4662
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond));
4663
+        }
4664
+
4665
+        $comment = '';
4666
+        // ne pas insérer de commentaire si c'est du json
4667
+        if ($extension != "json") {
4668
+            $comment = "/* #PRODUIRE{fond=$fond";
4669
+            foreach ($contexte as $k => $v) {
4670
+                $comment .= ",$k=$v";
4671
+            }
4672
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4673
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4674
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
4675
+        }
4676
+        // et ecrire le fichier
4677
+        ecrire_fichier($filename . ".last", $comment . $contenu);
4678
+        // regarder si on recopie
4679
+        if (!file_exists($filename)
4680
+            or md5_file($filename) !== md5_file($filename . ".last")
4681
+        ) {
4682
+            @copy($filename . ".last", $filename);
4683
+            clearstatcache(true, $filename); // eviter que PHP ne reserve le vieux timestamp
4684
+        }
4685
+    }
4686
+
4687
+    return timestamp($filename);
4688 4688
 }
4689 4689
 
4690 4690
 /**
@@ -4697,14 +4697,14 @@  discard block
 block discarded – undo
4697 4697
  *    $fichier auquel on a ajouté le timestamp
4698 4698
  */
4699 4699
 function timestamp($fichier) {
4700
-	if (!$fichier
4701
-		or !file_exists($fichier)
4702
-		or !$m = filemtime($fichier)
4703
-	) {
4704
-		return $fichier;
4705
-	}
4700
+    if (!$fichier
4701
+        or !file_exists($fichier)
4702
+        or !$m = filemtime($fichier)
4703
+    ) {
4704
+        return $fichier;
4705
+    }
4706 4706
 
4707
-	return "$fichier?$m";
4707
+    return "$fichier?$m";
4708 4708
 }
4709 4709
 
4710 4710
 /**
@@ -4714,11 +4714,11 @@  discard block
 block discarded – undo
4714 4714
  * @return string
4715 4715
  */
4716 4716
 function supprimer_timestamp($url) {
4717
-	if (strpos($url, "?") === false) {
4718
-		return $url;
4719
-	}
4717
+    if (strpos($url, "?") === false) {
4718
+        return $url;
4719
+    }
4720 4720
 
4721
-	return preg_replace(",\?[[:digit:]]+$,", "", $url);
4721
+    return preg_replace(",\?[[:digit:]]+$,", "", $url);
4722 4722
 }
4723 4723
 
4724 4724
 /**
@@ -4733,9 +4733,9 @@  discard block
 block discarded – undo
4733 4733
  * @return string
4734 4734
  */
4735 4735
 function filtre_nettoyer_titre_email_dist($titre) {
4736
-	include_spip('inc/envoyer_mail');
4736
+    include_spip('inc/envoyer_mail');
4737 4737
 
4738
-	return nettoyer_titre_email($titre);
4738
+    return nettoyer_titre_email($titre);
4739 4739
 }
4740 4740
 
4741 4741
 /**
@@ -4757,19 +4757,19 @@  discard block
 block discarded – undo
4757 4757
  * @return string
4758 4758
  */
4759 4759
 function filtre_chercher_rubrique_dist(
4760
-	$titre,
4761
-	$id_objet,
4762
-	$id_parent,
4763
-	$objet,
4764
-	$id_secteur,
4765
-	$restreint,
4766
-	$actionable = false,
4767
-	$retour_sans_cadre = false
4760
+    $titre,
4761
+    $id_objet,
4762
+    $id_parent,
4763
+    $objet,
4764
+    $id_secteur,
4765
+    $restreint,
4766
+    $actionable = false,
4767
+    $retour_sans_cadre = false
4768 4768
 ) {
4769
-	include_spip('inc/filtres_ecrire');
4769
+    include_spip('inc/filtres_ecrire');
4770 4770
 
4771
-	return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable,
4772
-		$retour_sans_cadre);
4771
+    return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable,
4772
+        $retour_sans_cadre);
4773 4773
 }
4774 4774
 
4775 4775
 /**
@@ -4798,56 +4798,56 @@  discard block
 block discarded – undo
4798 4798
  *     Chaîne vide si l'accès est autorisé
4799 4799
  */
4800 4800
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
4801
-	if ($ok) {
4802
-		return '';
4803
-	}
4804
-
4805
-	// Vider tous les tampons
4806
-	$level = @ob_get_level();
4807
-	while ($level--) {
4808
-		@ob_end_clean();
4809
-	}
4810
-
4811
-	include_spip('inc/headers');
4812
-
4813
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
4814
-	if ($url) {
4815
-		redirige_par_entete($url, '', $statut);
4816
-	}
4817
-
4818
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
4819
-	if (!is_numeric($statut) and is_null($message)) {
4820
-		$message = $statut;
4821
-		$statut = 0;
4822
-	}
4823
-	if (!$message) {
4824
-		$message = '';
4825
-	}
4826
-	$statut = intval($statut);
4827
-
4828
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
4829
-	if (test_espace_prive()) {
4830
-		if (!$statut or !in_array($statut, array(404, 403))) {
4831
-			$statut = 403;
4832
-		}
4833
-		http_status(403);
4834
-		$echec = charger_fonction('403', 'exec');
4835
-		$echec($message);
4836
-	} else {
4837
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
4838
-		if (!$statut) {
4839
-			$statut = 404;
4840
-		}
4841
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
4842
-		http_status($statut);
4843
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
4844
-		if ($statut >= 400) {
4845
-			echo recuperer_fond("$statut", array('erreur' => $message));
4846
-		}
4847
-	}
4848
-
4849
-
4850
-	exit;
4801
+    if ($ok) {
4802
+        return '';
4803
+    }
4804
+
4805
+    // Vider tous les tampons
4806
+    $level = @ob_get_level();
4807
+    while ($level--) {
4808
+        @ob_end_clean();
4809
+    }
4810
+
4811
+    include_spip('inc/headers');
4812
+
4813
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
4814
+    if ($url) {
4815
+        redirige_par_entete($url, '', $statut);
4816
+    }
4817
+
4818
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
4819
+    if (!is_numeric($statut) and is_null($message)) {
4820
+        $message = $statut;
4821
+        $statut = 0;
4822
+    }
4823
+    if (!$message) {
4824
+        $message = '';
4825
+    }
4826
+    $statut = intval($statut);
4827
+
4828
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
4829
+    if (test_espace_prive()) {
4830
+        if (!$statut or !in_array($statut, array(404, 403))) {
4831
+            $statut = 403;
4832
+        }
4833
+        http_status(403);
4834
+        $echec = charger_fonction('403', 'exec');
4835
+        $echec($message);
4836
+    } else {
4837
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
4838
+        if (!$statut) {
4839
+            $statut = 404;
4840
+        }
4841
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
4842
+        http_status($statut);
4843
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
4844
+        if ($statut >= 400) {
4845
+            echo recuperer_fond("$statut", array('erreur' => $message));
4846
+        }
4847
+    }
4848
+
4849
+
4850
+    exit;
4851 4851
 }
4852 4852
 
4853 4853
 /**
@@ -4858,9 +4858,9 @@  discard block
 block discarded – undo
4858 4858
  * @return string
4859 4859
  */
4860 4860
 function filtre_compacte_dist($source, $format = null) {
4861
-	if (function_exists('compacte')) {
4862
-		return compacte($source, $format);
4863
-	}
4861
+    if (function_exists('compacte')) {
4862
+        return compacte($source, $format);
4863
+    }
4864 4864
 
4865
-	return $source;
4865
+    return $source;
4866 4866
 }
Please login to merge, or discard this patch.
ecrire/inc/distant.php 2 patches
Indentation   +1070 added lines, -1070 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'], _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');
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'], _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');
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
 /**
@@ -253,86 +253,86 @@  discard block
 block discarded – undo
253 253
  */
254 254
 function prepare_donnees_post($donnees, $boundary = '') {
255 255
 
256
-	// permettre a la fonction qui a demande le post de formater elle meme ses donnees
257
-	// pour un appel soap par exemple
258
-	// l'entete est separe des donnees par un double retour a la ligne
259
-	// on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
260
-	if (is_string($donnees) && strlen($donnees)) {
261
-		$entete = '';
262
-		// on repasse tous les \r\n et \r en simples \n
263
-		$donnees = str_replace("\r\n", "\n", $donnees);
264
-		$donnees = str_replace("\r", "\n", $donnees);
265
-		// un double retour a la ligne signifie la fin de l'entete et le debut des donnees
266
-		$p = strpos($donnees, "\n\n");
267
-		if ($p !== false) {
268
-			$entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
269
-			$donnees = substr($donnees, $p + 2);
270
-		}
271
-		$chaine = str_replace("\n", "\r\n", $donnees);
272
-	} else {
273
-		/* boundary automatique */
274
-		// Si on a plus de 500 octects de donnees, on "boundarise"
275
-		if ($boundary === '') {
276
-			$taille = 0;
277
-			foreach ($donnees as $cle => $valeur) {
278
-				if (is_array($valeur)) {
279
-					foreach ($valeur as $val2) {
280
-						$taille += strlen($val2);
281
-					}
282
-				} else {
283
-					// faut-il utiliser spip_strlen() dans inc/charsets ?
284
-					$taille += strlen($valeur);
285
-				}
286
-			}
287
-			if ($taille > 500) {
288
-				$boundary = substr(md5(rand() . 'spip'), 0, 8);
289
-			}
290
-		}
291
-
292
-		if (is_string($boundary) and strlen($boundary)) {
293
-			// fabrique une chaine HTTP pour un POST avec boundary
294
-			$entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
295
-			$chaine = '';
296
-			if (is_array($donnees)) {
297
-				foreach ($donnees as $cle => $valeur) {
298
-					if (is_array($valeur)) {
299
-						foreach ($valeur as $val2) {
300
-							$chaine .= "\r\n--$boundary\r\n";
301
-							$chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
302
-							$chaine .= "\r\n";
303
-							$chaine .= $val2;
304
-						}
305
-					} else {
306
-						$chaine .= "\r\n--$boundary\r\n";
307
-						$chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
308
-						$chaine .= "\r\n";
309
-						$chaine .= $valeur;
310
-					}
311
-				}
312
-				$chaine .= "\r\n--$boundary\r\n";
313
-			}
314
-		} else {
315
-			// fabrique une chaine HTTP simple pour un POST
316
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
317
-			$chaine = array();
318
-			if (is_array($donnees)) {
319
-				foreach ($donnees as $cle => $valeur) {
320
-					if (is_array($valeur)) {
321
-						foreach ($valeur as $val2) {
322
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
323
-						}
324
-					} else {
325
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
326
-					}
327
-				}
328
-				$chaine = implode('&', $chaine);
329
-			} else {
330
-				$chaine = $donnees;
331
-			}
332
-		}
333
-	}
334
-
335
-	return array($entete, $chaine);
256
+    // permettre a la fonction qui a demande le post de formater elle meme ses donnees
257
+    // pour un appel soap par exemple
258
+    // l'entete est separe des donnees par un double retour a la ligne
259
+    // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
260
+    if (is_string($donnees) && strlen($donnees)) {
261
+        $entete = '';
262
+        // on repasse tous les \r\n et \r en simples \n
263
+        $donnees = str_replace("\r\n", "\n", $donnees);
264
+        $donnees = str_replace("\r", "\n", $donnees);
265
+        // un double retour a la ligne signifie la fin de l'entete et le debut des donnees
266
+        $p = strpos($donnees, "\n\n");
267
+        if ($p !== false) {
268
+            $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
269
+            $donnees = substr($donnees, $p + 2);
270
+        }
271
+        $chaine = str_replace("\n", "\r\n", $donnees);
272
+    } else {
273
+        /* boundary automatique */
274
+        // Si on a plus de 500 octects de donnees, on "boundarise"
275
+        if ($boundary === '') {
276
+            $taille = 0;
277
+            foreach ($donnees as $cle => $valeur) {
278
+                if (is_array($valeur)) {
279
+                    foreach ($valeur as $val2) {
280
+                        $taille += strlen($val2);
281
+                    }
282
+                } else {
283
+                    // faut-il utiliser spip_strlen() dans inc/charsets ?
284
+                    $taille += strlen($valeur);
285
+                }
286
+            }
287
+            if ($taille > 500) {
288
+                $boundary = substr(md5(rand() . 'spip'), 0, 8);
289
+            }
290
+        }
291
+
292
+        if (is_string($boundary) and strlen($boundary)) {
293
+            // fabrique une chaine HTTP pour un POST avec boundary
294
+            $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
295
+            $chaine = '';
296
+            if (is_array($donnees)) {
297
+                foreach ($donnees as $cle => $valeur) {
298
+                    if (is_array($valeur)) {
299
+                        foreach ($valeur as $val2) {
300
+                            $chaine .= "\r\n--$boundary\r\n";
301
+                            $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
302
+                            $chaine .= "\r\n";
303
+                            $chaine .= $val2;
304
+                        }
305
+                    } else {
306
+                        $chaine .= "\r\n--$boundary\r\n";
307
+                        $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
308
+                        $chaine .= "\r\n";
309
+                        $chaine .= $valeur;
310
+                    }
311
+                }
312
+                $chaine .= "\r\n--$boundary\r\n";
313
+            }
314
+        } else {
315
+            // fabrique une chaine HTTP simple pour un POST
316
+            $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
317
+            $chaine = array();
318
+            if (is_array($donnees)) {
319
+                foreach ($donnees as $cle => $valeur) {
320
+                    if (is_array($valeur)) {
321
+                        foreach ($valeur as $val2) {
322
+                            $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
323
+                        }
324
+                    } else {
325
+                        $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
326
+                    }
327
+                }
328
+                $chaine = implode('&', $chaine);
329
+            } else {
330
+                $chaine = $donnees;
331
+            }
332
+        }
333
+    }
334
+
335
+    return array($entete, $chaine);
336 336
 }
337 337
 
338 338
 /**
@@ -346,18 +346,18 @@  discard block
 block discarded – undo
346 346
  */
347 347
 function url_to_ascii($url_idn) {
348 348
 
349
-	if ($parts = parse_url($url_idn)) {
350
-		$host = $parts['host'];
351
-		if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
352
-			include_spip('inc/idna_convert.class');
353
-			$IDN = new idna_convert();
354
-			$host_ascii = $IDN->encode($host);
355
-			$url_idn = explode($host, $url_idn, 2);
356
-			$url_idn = implode($host_ascii, $url_idn);
357
-		}
358
-	}
359
-
360
-	return $url_idn;
349
+    if ($parts = parse_url($url_idn)) {
350
+        $host = $parts['host'];
351
+        if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
352
+            include_spip('inc/idna_convert.class');
353
+            $IDN = new idna_convert();
354
+            $host_ascii = $IDN->encode($host);
355
+            $url_idn = explode($host, $url_idn, 2);
356
+            $url_idn = implode($host_ascii, $url_idn);
357
+        }
358
+    }
359
+
360
+    return $url_idn;
361 361
 }
362 362
 
363 363
 /**
@@ -396,175 +396,175 @@  discard block
 block discarded – undo
396 396
  *     string file : nom du fichier si enregistre dans un fichier
397 397
  */
398 398
 function recuperer_url($url, $options = array()) {
399
-	$default = array(
400
-		'transcoder' => false,
401
-		'methode' => 'GET',
402
-		'taille_max' => null,
403
-		'datas' => '',
404
-		'boundary' => '',
405
-		'refuser_gz' => false,
406
-		'if_modified_since' => '',
407
-		'uri_referer' => '',
408
-		'file' => '',
409
-		'follow_location' => 10,
410
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
411
-	);
412
-	$options = array_merge($default, $options);
413
-	// copier directement dans un fichier ?
414
-	$copy = $options['file'];
415
-
416
-	if ($options['methode'] == 'HEAD') {
417
-		$options['taille_max'] = 0;
418
-	}
419
-	if (is_null($options['taille_max'])) {
420
-		$options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
421
-	}
422
-
423
-	if (!empty($options['datas'])) {
424
-		list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
425
-		if (stripos($head, 'Content-Length:') === false) {
426
-			$head .= 'Content-Length: ' . strlen($postdata);
427
-		}
428
-		$options['datas'] = $head . "\r\n\r\n" . $postdata;
429
-		if (strlen($postdata)) {
430
-			$options['methode'] = 'POST';
431
-		}
432
-	}
433
-
434
-	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
435
-	$url = preg_replace(',^feed://,i', 'http://', $url);
436
-	if (!tester_url_absolue($url)) {
437
-		$url = 'http://' . $url;
438
-	} elseif (strncmp($url, '//', 2) == 0) {
439
-		$url = 'http:' . $url;
440
-	}
441
-
442
-	$url = url_to_ascii($url);
443
-
444
-	$result = array(
445
-		'status' => 0,
446
-		'headers' => '',
447
-		'page' => '',
448
-		'length' => 0,
449
-		'last_modified' => '',
450
-		'location' => '',
451
-		'url' => $url
452
-	);
453
-
454
-	// si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
455
-	$refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
456
-
457
-	// ouvrir la connexion et envoyer la requete et ses en-tetes
458
-	list($handle, $fopen) = init_http(
459
-		$options['methode'],
460
-		$url,
461
-		$refuser_gz,
462
-		$options['uri_referer'],
463
-		$options['datas'],
464
-		$options['version_http'],
465
-		$options['if_modified_since']
466
-	);
467
-	if (!$handle) {
468
-		spip_log("ECHEC init_http $url");
469
-
470
-		return false;
471
-	}
472
-
473
-	// Sauf en fopen, envoyer le flux d'entree
474
-	// et recuperer les en-tetes de reponses
475
-	if (!$fopen) {
476
-		$res = recuperer_entetes_complets($handle, $options['if_modified_since']);
477
-		if (!$res) {
478
-			fclose($handle);
479
-			$t = @parse_url($url);
480
-			$host = $t['host'];
481
-			// Chinoisierie inexplicable pour contrer
482
-			// les actions liberticides de l'empire du milieu
483
-			if (!need_proxy($host)
484
-				and $res = @file_get_contents($url)
485
-			) {
486
-				$result['length'] = strlen($res);
487
-				if ($copy) {
488
-					ecrire_fichier($copy, $res);
489
-					$result['file'] = $copy;
490
-				} else {
491
-					$result['page'] = $res;
492
-				}
493
-				$res = array(
494
-					'status' => 200,
495
-				);
496
-			} else {
497
-				return false;
498
-			}
499
-		} elseif ($res['location'] and $options['follow_location']) {
500
-			$options['follow_location']--;
501
-			fclose($handle);
502
-			include_spip('inc/filtres');
503
-			$url = suivre_lien($url, $res['location']);
504
-			spip_log("recuperer_url recommence sur $url");
505
-
506
-			return recuperer_url($url, $options);
507
-		} elseif ($res['status'] !== 200) {
508
-			spip_log('HTTP status ' . $res['status'] . " pour $url");
509
-		}
510
-		$result['status'] = $res['status'];
511
-		if (isset($res['headers'])) {
512
-			$result['headers'] = $res['headers'];
513
-		}
514
-		if (isset($res['last_modified'])) {
515
-			$result['last_modified'] = $res['last_modified'];
516
-		}
517
-		if (isset($res['location'])) {
518
-			$result['location'] = $res['location'];
519
-		}
520
-	}
521
-
522
-	// on ne veut que les entetes
523
-	if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
524
-		return $result;
525
-	}
526
-
527
-
528
-	// s'il faut deballer, le faire via un fichier temporaire
529
-	// sinon la memoire explose pour les gros flux
530
-
531
-	$gz = false;
532
-	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
533
-		$gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
534
-	}
535
-
536
-	// si on a pas deja recuperer le contenu par une methode detournee
537
-	if (!$result['length']) {
538
-		$res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy);
539
-		fclose($handle);
540
-		if ($copy) {
541
-			$result['length'] = $res;
542
-			$result['file'] = $copy;
543
-		} elseif ($res) {
544
-			$result['page'] = &$res;
545
-			$result['length'] = strlen($result['page']);
546
-		}
547
-		if (!$result['status']) {
548
-			$result['status'] = 200; // on a reussi, donc !
549
-		}
550
-	}
551
-	if (!$result['page']) {
552
-		return $result;
553
-	}
554
-
555
-	// Decompresser au besoin
556
-	if ($gz) {
557
-		$result['page'] = implode('', gzfile($gz));
558
-		supprimer_fichier($gz);
559
-	}
560
-
561
-	// Faut-il l'importer dans notre charset local ?
562
-	if ($options['transcoder']) {
563
-		include_spip('inc/charsets');
564
-		$result['page'] = transcoder_page($result['page'], $result['headers']);
565
-	}
566
-
567
-	return $result;
399
+    $default = array(
400
+        'transcoder' => false,
401
+        'methode' => 'GET',
402
+        'taille_max' => null,
403
+        'datas' => '',
404
+        'boundary' => '',
405
+        'refuser_gz' => false,
406
+        'if_modified_since' => '',
407
+        'uri_referer' => '',
408
+        'file' => '',
409
+        'follow_location' => 10,
410
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
411
+    );
412
+    $options = array_merge($default, $options);
413
+    // copier directement dans un fichier ?
414
+    $copy = $options['file'];
415
+
416
+    if ($options['methode'] == 'HEAD') {
417
+        $options['taille_max'] = 0;
418
+    }
419
+    if (is_null($options['taille_max'])) {
420
+        $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
421
+    }
422
+
423
+    if (!empty($options['datas'])) {
424
+        list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
425
+        if (stripos($head, 'Content-Length:') === false) {
426
+            $head .= 'Content-Length: ' . strlen($postdata);
427
+        }
428
+        $options['datas'] = $head . "\r\n\r\n" . $postdata;
429
+        if (strlen($postdata)) {
430
+            $options['methode'] = 'POST';
431
+        }
432
+    }
433
+
434
+    // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
435
+    $url = preg_replace(',^feed://,i', 'http://', $url);
436
+    if (!tester_url_absolue($url)) {
437
+        $url = 'http://' . $url;
438
+    } elseif (strncmp($url, '//', 2) == 0) {
439
+        $url = 'http:' . $url;
440
+    }
441
+
442
+    $url = url_to_ascii($url);
443
+
444
+    $result = array(
445
+        'status' => 0,
446
+        'headers' => '',
447
+        'page' => '',
448
+        'length' => 0,
449
+        'last_modified' => '',
450
+        'location' => '',
451
+        'url' => $url
452
+    );
453
+
454
+    // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
455
+    $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
456
+
457
+    // ouvrir la connexion et envoyer la requete et ses en-tetes
458
+    list($handle, $fopen) = init_http(
459
+        $options['methode'],
460
+        $url,
461
+        $refuser_gz,
462
+        $options['uri_referer'],
463
+        $options['datas'],
464
+        $options['version_http'],
465
+        $options['if_modified_since']
466
+    );
467
+    if (!$handle) {
468
+        spip_log("ECHEC init_http $url");
469
+
470
+        return false;
471
+    }
472
+
473
+    // Sauf en fopen, envoyer le flux d'entree
474
+    // et recuperer les en-tetes de reponses
475
+    if (!$fopen) {
476
+        $res = recuperer_entetes_complets($handle, $options['if_modified_since']);
477
+        if (!$res) {
478
+            fclose($handle);
479
+            $t = @parse_url($url);
480
+            $host = $t['host'];
481
+            // Chinoisierie inexplicable pour contrer
482
+            // les actions liberticides de l'empire du milieu
483
+            if (!need_proxy($host)
484
+                and $res = @file_get_contents($url)
485
+            ) {
486
+                $result['length'] = strlen($res);
487
+                if ($copy) {
488
+                    ecrire_fichier($copy, $res);
489
+                    $result['file'] = $copy;
490
+                } else {
491
+                    $result['page'] = $res;
492
+                }
493
+                $res = array(
494
+                    'status' => 200,
495
+                );
496
+            } else {
497
+                return false;
498
+            }
499
+        } elseif ($res['location'] and $options['follow_location']) {
500
+            $options['follow_location']--;
501
+            fclose($handle);
502
+            include_spip('inc/filtres');
503
+            $url = suivre_lien($url, $res['location']);
504
+            spip_log("recuperer_url recommence sur $url");
505
+
506
+            return recuperer_url($url, $options);
507
+        } elseif ($res['status'] !== 200) {
508
+            spip_log('HTTP status ' . $res['status'] . " pour $url");
509
+        }
510
+        $result['status'] = $res['status'];
511
+        if (isset($res['headers'])) {
512
+            $result['headers'] = $res['headers'];
513
+        }
514
+        if (isset($res['last_modified'])) {
515
+            $result['last_modified'] = $res['last_modified'];
516
+        }
517
+        if (isset($res['location'])) {
518
+            $result['location'] = $res['location'];
519
+        }
520
+    }
521
+
522
+    // on ne veut que les entetes
523
+    if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
524
+        return $result;
525
+    }
526
+
527
+
528
+    // s'il faut deballer, le faire via un fichier temporaire
529
+    // sinon la memoire explose pour les gros flux
530
+
531
+    $gz = false;
532
+    if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
533
+        $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
534
+    }
535
+
536
+    // si on a pas deja recuperer le contenu par une methode detournee
537
+    if (!$result['length']) {
538
+        $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy);
539
+        fclose($handle);
540
+        if ($copy) {
541
+            $result['length'] = $res;
542
+            $result['file'] = $copy;
543
+        } elseif ($res) {
544
+            $result['page'] = &$res;
545
+            $result['length'] = strlen($result['page']);
546
+        }
547
+        if (!$result['status']) {
548
+            $result['status'] = 200; // on a reussi, donc !
549
+        }
550
+    }
551
+    if (!$result['page']) {
552
+        return $result;
553
+    }
554
+
555
+    // Decompresser au besoin
556
+    if ($gz) {
557
+        $result['page'] = implode('', gzfile($gz));
558
+        supprimer_fichier($gz);
559
+    }
560
+
561
+    // Faut-il l'importer dans notre charset local ?
562
+    if ($options['transcoder']) {
563
+        include_spip('inc/charsets');
564
+        $result['page'] = transcoder_page($result['page'], $result['headers']);
565
+    }
566
+
567
+    return $result;
568 568
 }
569 569
 
570 570
 /**
@@ -580,72 +580,72 @@  discard block
 block discarded – undo
580 580
  * @return array|bool|mixed
581 581
  */
582 582
 function recuperer_url_cache($url, $options = array()) {
583
-	if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
584
-		define('_DELAI_RECUPERER_URL_CACHE', 3600);
585
-	}
586
-	$default = array(
587
-		'transcoder' => false,
588
-		'methode' => 'GET',
589
-		'taille_max' => null,
590
-		'datas' => '',
591
-		'boundary' => '',
592
-		'refuser_gz' => false,
593
-		'if_modified_since' => '',
594
-		'uri_referer' => '',
595
-		'file' => '',
596
-		'follow_location' => 10,
597
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
598
-		'delai_cache' => _DELAI_RECUPERER_URL_CACHE,
599
-	);
600
-	$options = array_merge($default, $options);
601
-
602
-	// cas ou il n'est pas possible de cacher
603
-	if (!empty($options['data']) or $options['methode'] == 'POST') {
604
-		return recuperer_url($url, $options);
605
-	}
606
-
607
-	// ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
608
-	static $errors = array();
609
-	if (isset($errors[$url])) {
610
-		return $errors[$url];
611
-	}
612
-
613
-	$sig = $options;
614
-	unset($sig['if_modified_since']);
615
-	unset($sig['delai_cache']);
616
-	$sig['url'] = $url;
617
-
618
-	$dir = sous_repertoire(_DIR_CACHE, 'curl');
619
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
620
-	$sub = sous_repertoire($dir, substr($cache, 0, 2));
621
-	$cache = "$sub$cache";
622
-
623
-	$res = false;
624
-	$is_cached = file_exists($cache);
625
-	if ($is_cached
626
-		and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
627
-	) {
628
-		lire_fichier($cache, $res);
629
-		if ($res = unserialize($res)) {
630
-			// mettre le last_modified et le status=304 ?
631
-		}
632
-	}
633
-	if (!$res) {
634
-		$res = recuperer_url($url, $options);
635
-		// ne pas recharger cette url non cachee dans le meme hit puisque non disponible
636
-		if (!$res) {
637
-			if ($is_cached) {
638
-				// on a pas reussi a recuperer mais on avait un cache : l'utiliser
639
-				lire_fichier($cache, $res);
640
-				$res = unserialize($res);
641
-			}
642
-
643
-			return $errors[$url] = $res;
644
-		}
645
-		ecrire_fichier($cache, serialize($res));
646
-	}
647
-
648
-	return $res;
583
+    if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
584
+        define('_DELAI_RECUPERER_URL_CACHE', 3600);
585
+    }
586
+    $default = array(
587
+        'transcoder' => false,
588
+        'methode' => 'GET',
589
+        'taille_max' => null,
590
+        'datas' => '',
591
+        'boundary' => '',
592
+        'refuser_gz' => false,
593
+        'if_modified_since' => '',
594
+        'uri_referer' => '',
595
+        'file' => '',
596
+        'follow_location' => 10,
597
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
598
+        'delai_cache' => _DELAI_RECUPERER_URL_CACHE,
599
+    );
600
+    $options = array_merge($default, $options);
601
+
602
+    // cas ou il n'est pas possible de cacher
603
+    if (!empty($options['data']) or $options['methode'] == 'POST') {
604
+        return recuperer_url($url, $options);
605
+    }
606
+
607
+    // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
608
+    static $errors = array();
609
+    if (isset($errors[$url])) {
610
+        return $errors[$url];
611
+    }
612
+
613
+    $sig = $options;
614
+    unset($sig['if_modified_since']);
615
+    unset($sig['delai_cache']);
616
+    $sig['url'] = $url;
617
+
618
+    $dir = sous_repertoire(_DIR_CACHE, 'curl');
619
+    $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
620
+    $sub = sous_repertoire($dir, substr($cache, 0, 2));
621
+    $cache = "$sub$cache";
622
+
623
+    $res = false;
624
+    $is_cached = file_exists($cache);
625
+    if ($is_cached
626
+        and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
627
+    ) {
628
+        lire_fichier($cache, $res);
629
+        if ($res = unserialize($res)) {
630
+            // mettre le last_modified et le status=304 ?
631
+        }
632
+    }
633
+    if (!$res) {
634
+        $res = recuperer_url($url, $options);
635
+        // ne pas recharger cette url non cachee dans le meme hit puisque non disponible
636
+        if (!$res) {
637
+            if ($is_cached) {
638
+                // on a pas reussi a recuperer mais on avait un cache : l'utiliser
639
+                lire_fichier($cache, $res);
640
+                $res = unserialize($res);
641
+            }
642
+
643
+            return $errors[$url] = $res;
644
+        }
645
+        ecrire_fichier($cache, serialize($res));
646
+    }
647
+
648
+    return $res;
649 649
 }
650 650
 
651 651
 /**
@@ -683,52 +683,52 @@  discard block
 block discarded – undo
683 683
  *     - false si la page n'a pu être récupérée (status different de 200)
684 684
  **/
685 685
 function recuperer_page(
686
-	$url,
687
-	$trans = false,
688
-	$get_headers = false,
689
-	$taille_max = null,
690
-	$datas = '',
691
-	$boundary = '',
692
-	$refuser_gz = false,
693
-	$date_verif = '',
694
-	$uri_referer = ''
686
+    $url,
687
+    $trans = false,
688
+    $get_headers = false,
689
+    $taille_max = null,
690
+    $datas = '',
691
+    $boundary = '',
692
+    $refuser_gz = false,
693
+    $date_verif = '',
694
+    $uri_referer = ''
695 695
 ) {
696
-	// $copy = copier le fichier ?
697
-	$copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
698
-
699
-	if (!is_null($taille_max) and ($taille_max == 0)) {
700
-		$get = 'HEAD';
701
-	} else {
702
-		$get = 'GET';
703
-	}
704
-
705
-	$options = array(
706
-		'transcoder' => $trans === true,
707
-		'methode' => $get,
708
-		'datas' => $datas,
709
-		'boundary' => $boundary,
710
-		'refuser_gz' => $refuser_gz,
711
-		'if_modified_since' => $date_verif,
712
-		'uri_referer' => $uri_referer,
713
-		'file' => $copy ? $trans : '',
714
-		'follow_location' => 10,
715
-	);
716
-	if (!is_null($taille_max)) {
717
-		$options['taille_max'] = $taille_max;
718
-	}
719
-	// dix tentatives maximum en cas d'entetes 301...
720
-	$res = recuperer_url($url, $options);
721
-	if (!$res) {
722
-		return false;
723
-	}
724
-	if ($res['status'] !== 200) {
725
-		return false;
726
-	}
727
-	if ($get_headers) {
728
-		return $res['headers'] . "\n" . $res['page'];
729
-	}
730
-
731
-	return $res['page'];
696
+    // $copy = copier le fichier ?
697
+    $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
698
+
699
+    if (!is_null($taille_max) and ($taille_max == 0)) {
700
+        $get = 'HEAD';
701
+    } else {
702
+        $get = 'GET';
703
+    }
704
+
705
+    $options = array(
706
+        'transcoder' => $trans === true,
707
+        'methode' => $get,
708
+        'datas' => $datas,
709
+        'boundary' => $boundary,
710
+        'refuser_gz' => $refuser_gz,
711
+        'if_modified_since' => $date_verif,
712
+        'uri_referer' => $uri_referer,
713
+        'file' => $copy ? $trans : '',
714
+        'follow_location' => 10,
715
+    );
716
+    if (!is_null($taille_max)) {
717
+        $options['taille_max'] = $taille_max;
718
+    }
719
+    // dix tentatives maximum en cas d'entetes 301...
720
+    $res = recuperer_url($url, $options);
721
+    if (!$res) {
722
+        return false;
723
+    }
724
+    if ($res['status'] !== 200) {
725
+        return false;
726
+    }
727
+    if ($get_headers) {
728
+        return $res['headers'] . "\n" . $res['page'];
729
+    }
730
+
731
+    return $res['page'];
732 732
 }
733 733
 
734 734
 
@@ -765,48 +765,48 @@  discard block
 block discarded – undo
765 765
  *     - false sinon
766 766
  **/
767 767
 function recuperer_lapage(
768
-	$url,
769
-	$trans = false,
770
-	$get = 'GET',
771
-	$taille_max = 1048576,
772
-	$datas = '',
773
-	$refuser_gz = false,
774
-	$date_verif = '',
775
-	$uri_referer = ''
768
+    $url,
769
+    $trans = false,
770
+    $get = 'GET',
771
+    $taille_max = 1048576,
772
+    $datas = '',
773
+    $refuser_gz = false,
774
+    $date_verif = '',
775
+    $uri_referer = ''
776 776
 ) {
777
-	// $copy = copier le fichier ?
778
-	$copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
779
-
780
-	// si on ecrit directement dans un fichier, pour ne pas manipuler
781
-	// en memoire refuser gz
782
-	if ($copy) {
783
-		$refuser_gz = true;
784
-	}
785
-
786
-	$options = array(
787
-		'transcoder' => $trans === true,
788
-		'methode' => $get,
789
-		'datas' => $datas,
790
-		'refuser_gz' => $refuser_gz,
791
-		'if_modified_since' => $date_verif,
792
-		'uri_referer' => $uri_referer,
793
-		'file' => $copy ? $trans : '',
794
-		'follow_location' => false,
795
-	);
796
-	if (!is_null($taille_max)) {
797
-		$options['taille_max'] = $taille_max;
798
-	}
799
-	// dix tentatives maximum en cas d'entetes 301...
800
-	$res = recuperer_url($url, $options);
801
-
802
-	if (!$res) {
803
-		return false;
804
-	}
805
-	if ($res['status'] !== 200) {
806
-		return false;
807
-	}
808
-
809
-	return array($res['headers'], $res['page']);
777
+    // $copy = copier le fichier ?
778
+    $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
779
+
780
+    // si on ecrit directement dans un fichier, pour ne pas manipuler
781
+    // en memoire refuser gz
782
+    if ($copy) {
783
+        $refuser_gz = true;
784
+    }
785
+
786
+    $options = array(
787
+        'transcoder' => $trans === true,
788
+        'methode' => $get,
789
+        'datas' => $datas,
790
+        'refuser_gz' => $refuser_gz,
791
+        'if_modified_since' => $date_verif,
792
+        'uri_referer' => $uri_referer,
793
+        'file' => $copy ? $trans : '',
794
+        'follow_location' => false,
795
+    );
796
+    if (!is_null($taille_max)) {
797
+        $options['taille_max'] = $taille_max;
798
+    }
799
+    // dix tentatives maximum en cas d'entetes 301...
800
+    $res = recuperer_url($url, $options);
801
+
802
+    if (!$res) {
803
+        return false;
804
+    }
805
+    if ($res['status'] !== 200) {
806
+        return false;
807
+    }
808
+
809
+    return array($res['headers'], $res['page']);
810 810
 }
811 811
 
812 812
 /**
@@ -824,41 +824,41 @@  discard block
 block discarded – undo
824 824
  *   string contenu de la resource
825 825
  */
826 826
 function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') {
827
-	$taille = 0;
828
-	$result = '';
829
-	$fp = false;
830
-	if ($fichier) {
831
-		include_spip('inc/acces');
832
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
833
-		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
834
-		if (!$fp and file_exists($fichier)) {
835
-			return filesize($fichier);
836
-		}
837
-		if (!$fp) {
838
-			return false;
839
-		}
840
-		$result = 0; // on renvoie la taille du fichier
841
-	}
842
-	while (!feof($handle) and $taille < $taille_max) {
843
-		$res = fread($handle, 16384);
844
-		$taille += strlen($res);
845
-		if ($fp) {
846
-			fwrite($fp, $res);
847
-			$result = $taille;
848
-		} else {
849
-			$result .= $res;
850
-		}
851
-	}
852
-	if ($fp) {
853
-		spip_fclose_unlock($fp);
854
-		spip_unlink($fichier);
855
-		@rename($tmpfile, $fichier);
856
-		if (!file_exists($fichier)) {
857
-			return false;
858
-		}
859
-	}
860
-
861
-	return $result;
827
+    $taille = 0;
828
+    $result = '';
829
+    $fp = false;
830
+    if ($fichier) {
831
+        include_spip('inc/acces');
832
+        $tmpfile = "$fichier." . creer_uniqid() . '.tmp';
833
+        $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
834
+        if (!$fp and file_exists($fichier)) {
835
+            return filesize($fichier);
836
+        }
837
+        if (!$fp) {
838
+            return false;
839
+        }
840
+        $result = 0; // on renvoie la taille du fichier
841
+    }
842
+    while (!feof($handle) and $taille < $taille_max) {
843
+        $res = fread($handle, 16384);
844
+        $taille += strlen($res);
845
+        if ($fp) {
846
+            fwrite($fp, $res);
847
+            $result = $taille;
848
+        } else {
849
+            $result .= $res;
850
+        }
851
+    }
852
+    if ($fp) {
853
+        spip_fclose_unlock($fp);
854
+        spip_unlink($fichier);
855
+        @rename($tmpfile, $fichier);
856
+        if (!file_exists($fichier)) {
857
+            return false;
858
+        }
859
+    }
860
+
861
+    return $result;
862 862
 }
863 863
 
864 864
 /**
@@ -880,34 +880,34 @@  discard block
 block discarded – undo
880 880
  *   string location
881 881
  */
882 882
 function recuperer_entetes_complets($handle, $if_modified_since = false) {
883
-	$result = array('status' => 0, 'headers' => array(), 'last_modified' => 0, 'location' => '');
884
-
885
-	$s = @trim(fgets($handle, 16384));
886
-	if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
887
-		return false;
888
-	}
889
-	$result['status'] = intval($r[1]);
890
-	while ($s = trim(fgets($handle, 16384))) {
891
-		$result['headers'][] = $s . "\n";
892
-		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
893
-		list(, $d, $v) = $r;
894
-		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
895
-			$result['location'] = $v;
896
-		} elseif ($d == 'Last-Modified') {
897
-			$result['last_modified'] = strtotime($v);
898
-		}
899
-	}
900
-	if ($if_modified_since
901
-		and $result['last_modified']
902
-		and $if_modified_since > $result['last_modified']
903
-		and $result['status'] == 200
904
-	) {
905
-		$result['status'] = 304;
906
-	}
907
-
908
-	$result['headers'] = implode('', $result['headers']);
909
-
910
-	return $result;
883
+    $result = array('status' => 0, 'headers' => array(), 'last_modified' => 0, 'location' => '');
884
+
885
+    $s = @trim(fgets($handle, 16384));
886
+    if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
887
+        return false;
888
+    }
889
+    $result['status'] = intval($r[1]);
890
+    while ($s = trim(fgets($handle, 16384))) {
891
+        $result['headers'][] = $s . "\n";
892
+        preg_match(',^([^:]*): *(.*)$,i', $s, $r);
893
+        list(, $d, $v) = $r;
894
+        if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
895
+            $result['location'] = $v;
896
+        } elseif ($d == 'Last-Modified') {
897
+            $result['last_modified'] = strtotime($v);
898
+        }
899
+    }
900
+    if ($if_modified_since
901
+        and $result['last_modified']
902
+        and $if_modified_since > $result['last_modified']
903
+        and $result['status'] == 200
904
+    ) {
905
+        $result['status'] = 304;
906
+    }
907
+
908
+    $result['headers'] = implode('', $result['headers']);
909
+
910
+    return $result;
911 911
 }
912 912
 
913 913
 /**
@@ -929,20 +929,20 @@  discard block
 block discarded – undo
929 929
  *     - le tableau des entetes dans tous les autres cas
930 930
  **/
931 931
 function recuperer_entetes($f, $date_verif = '') {
932
-	//Cas ou la page distante n'a pas bouge depuis
933
-	//la derniere visite
934
-	$res = recuperer_entetes_complets($f, $date_verif);
935
-	if (!$res) {
936
-		return false;
937
-	}
938
-	if ($res['location']) {
939
-		return $res['location'];
940
-	}
941
-	if ($res['status'] != 200) {
942
-		return $res['status'];
943
-	}
944
-
945
-	return explode("\n", $res['headers']);
932
+    //Cas ou la page distante n'a pas bouge depuis
933
+    //la derniere visite
934
+    $res = recuperer_entetes_complets($f, $date_verif);
935
+    if (!$res) {
936
+        return false;
937
+    }
938
+    if ($res['location']) {
939
+        return $res['location'];
940
+    }
941
+    if ($res['status'] != 200) {
942
+        return $res['status'];
943
+    }
944
+
945
+    return explode("\n", $res['headers']);
946 946
 }
947 947
 
948 948
 /**
@@ -964,22 +964,22 @@  discard block
 block discarded – undo
964 964
  *     Nom du fichier pour copie locale
965 965
  **/
966 966
 function nom_fichier_copie_locale($source, $extension) {
967
-	include_spip('inc/documents');
967
+    include_spip('inc/documents');
968 968
 
969
-	$d = creer_repertoire_documents('distant'); # IMG/distant/
970
-	$d = sous_repertoire($d, $extension); # IMG/distant/pdf/
969
+    $d = creer_repertoire_documents('distant'); # IMG/distant/
970
+    $d = sous_repertoire($d, $extension); # IMG/distant/pdf/
971 971
 
972
-	// on se place tout le temps comme si on etait a la racine
973
-	if (_DIR_RACINE) {
974
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
975
-	}
972
+    // on se place tout le temps comme si on etait a la racine
973
+    if (_DIR_RACINE) {
974
+        $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
975
+    }
976 976
 
977
-	$m = md5($source);
977
+    $m = md5($source);
978 978
 
979
-	return $d
980
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
981
-	. substr($m, 0, 4)
982
-	. ".$extension";
979
+    return $d
980
+    . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
981
+    . substr($m, 0, 4)
982
+    . ".$extension";
983 983
 }
984 984
 
985 985
 /**
@@ -997,68 +997,68 @@  discard block
 block discarded – undo
997 997
  *      Nom du fichier calculé
998 998
  **/
999 999
 function fichier_copie_locale($source) {
1000
-	// Si c'est deja local pas de souci
1001
-	if (!tester_url_absolue($source)) {
1002
-		if (_DIR_RACINE) {
1003
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
1004
-		}
1005
-
1006
-		return $source;
1007
-	}
1008
-
1009
-	// optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
1010
-	// a deja ete copie en local avec cette extension
1011
-	// dans ce cas elle est fiable, pas la peine de requeter en base
1012
-	$path_parts = pathinfo($source);
1013
-	if (!isset($path_parts['extension'])) {
1014
-		$path_parts['extension'] = '';
1015
-	}
1016
-	$ext = $path_parts ? $path_parts['extension'] : '';
1017
-	if ($ext
1018
-		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
1019
-		and $f = nom_fichier_copie_locale($source, $ext)
1020
-		and file_exists(_DIR_RACINE . $f)
1021
-	) {
1022
-		return $f;
1023
-	}
1024
-
1025
-
1026
-	// Si c'est deja dans la table des documents,
1027
-	// ramener le nom de sa copie potentielle
1028
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
1029
-
1030
-	if ($ext) {
1031
-		return nom_fichier_copie_locale($source, $ext);
1032
-	}
1033
-
1034
-	// voir si l'extension indiquee dans le nom du fichier est ok
1035
-	// et si il n'aurait pas deja ete rapatrie
1036
-
1037
-	$ext = $path_parts ? $path_parts['extension'] : '';
1038
-
1039
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1040
-		$f = nom_fichier_copie_locale($source, $ext);
1041
-		if (file_exists(_DIR_RACINE . $f)) {
1042
-			return $f;
1043
-		}
1044
-	}
1045
-
1046
-	// Ping  pour voir si son extension est connue et autorisee
1047
-	// avec mise en cache du resultat du ping
1048
-
1049
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
1050
-	if (!@file_exists($cache)
1051
-		or !$path_parts = @unserialize(spip_file_get_contents($cache))
1052
-		or _request('var_mode') == 'recalcul'
1053
-	) {
1054
-		$path_parts = recuperer_infos_distantes($source, 0, false);
1055
-		ecrire_fichier($cache, serialize($path_parts));
1056
-	}
1057
-	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
1058
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1059
-		return nom_fichier_copie_locale($source, $ext);
1060
-	}
1061
-	spip_log("pas de copie locale pour $source");
1000
+    // Si c'est deja local pas de souci
1001
+    if (!tester_url_absolue($source)) {
1002
+        if (_DIR_RACINE) {
1003
+            $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
1004
+        }
1005
+
1006
+        return $source;
1007
+    }
1008
+
1009
+    // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
1010
+    // a deja ete copie en local avec cette extension
1011
+    // dans ce cas elle est fiable, pas la peine de requeter en base
1012
+    $path_parts = pathinfo($source);
1013
+    if (!isset($path_parts['extension'])) {
1014
+        $path_parts['extension'] = '';
1015
+    }
1016
+    $ext = $path_parts ? $path_parts['extension'] : '';
1017
+    if ($ext
1018
+        and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
1019
+        and $f = nom_fichier_copie_locale($source, $ext)
1020
+        and file_exists(_DIR_RACINE . $f)
1021
+    ) {
1022
+        return $f;
1023
+    }
1024
+
1025
+
1026
+    // Si c'est deja dans la table des documents,
1027
+    // ramener le nom de sa copie potentielle
1028
+    $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
1029
+
1030
+    if ($ext) {
1031
+        return nom_fichier_copie_locale($source, $ext);
1032
+    }
1033
+
1034
+    // voir si l'extension indiquee dans le nom du fichier est ok
1035
+    // et si il n'aurait pas deja ete rapatrie
1036
+
1037
+    $ext = $path_parts ? $path_parts['extension'] : '';
1038
+
1039
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1040
+        $f = nom_fichier_copie_locale($source, $ext);
1041
+        if (file_exists(_DIR_RACINE . $f)) {
1042
+            return $f;
1043
+        }
1044
+    }
1045
+
1046
+    // Ping  pour voir si son extension est connue et autorisee
1047
+    // avec mise en cache du resultat du ping
1048
+
1049
+    $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
1050
+    if (!@file_exists($cache)
1051
+        or !$path_parts = @unserialize(spip_file_get_contents($cache))
1052
+        or _request('var_mode') == 'recalcul'
1053
+    ) {
1054
+        $path_parts = recuperer_infos_distantes($source, 0, false);
1055
+        ecrire_fichier($cache, serialize($path_parts));
1056
+    }
1057
+    $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
1058
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1059
+        return nom_fichier_copie_locale($source, $ext);
1060
+    }
1061
+    spip_log("pas de copie locale pour $source");
1062 1062
 }
1063 1063
 
1064 1064
 
@@ -1086,140 +1086,140 @@  discard block
 block discarded – undo
1086 1086
  **/
1087 1087
 function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true) {
1088 1088
 
1089
-	// pas la peine de perdre son temps
1090
-	if (!tester_url_absolue($source)) {
1091
-		return false;
1092
-	}
1093
-
1094
-	# charger les alias des types mime
1095
-	include_spip('base/typedoc');
1096
-
1097
-	$a = array();
1098
-	$mime_type = '';
1099
-	// On va directement charger le debut des images et des fichiers html,
1100
-	// de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
1101
-	// ca echoue l'utilisateur devra les entrer...
1102
-	if ($headers = recuperer_page($source, false, true, $max, '', '', true)) {
1103
-		list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2);
1104
-
1105
-		if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1106
-			$mime_type = (trim($regs[1]));
1107
-		} else {
1108
-			$mime_type = '';
1109
-		} // inconnu
1110
-
1111
-		// Appliquer les alias
1112
-		while (isset($GLOBALS['mime_alias'][$mime_type])) {
1113
-			$mime_type = $GLOBALS['mime_alias'][$mime_type];
1114
-		}
1115
-
1116
-		// Si on a un mime-type insignifiant
1117
-		// text/plain,application/octet-stream ou vide
1118
-		// c'est peut-etre que le serveur ne sait pas
1119
-		// ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1120
-		// ou le Content-Disposition: attachment; filename=...
1121
-		$t = null;
1122
-		if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) {
1123
-			if (!$t
1124
-				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1125
-			) {
1126
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1127
-			}
1128
-			if (!$t
1129
-				and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1130
-				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1131
-			) {
1132
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1133
-			}
1134
-		}
1135
-
1136
-		// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1137
-		if (!$t) {
1138
-			$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1139
-		}
1140
-
1141
-		// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1142
-		// On essaie de nouveau avec l'extension
1143
-		if (!$t
1144
-			and $mime_type != 'text/plain'
1145
-			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1146
-		) {
1147
-			# eviter xxx.3 => 3gp (> SPIP 3)
1148
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1149
-		}
1150
-
1151
-		if ($t) {
1152
-			spip_log("mime-type $mime_type ok, extension " . $t['extension']);
1153
-			$a['extension'] = $t['extension'];
1154
-		} else {
1155
-			# par defaut on retombe sur '.bin' si c'est autorise
1156
-			spip_log("mime-type $mime_type inconnu");
1157
-			$t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1158
-			if (!$t) {
1159
-				return false;
1160
-			}
1161
-			$a['extension'] = $t['extension'];
1162
-		}
1163
-
1164
-		if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
1165
-			$a['taille'] = intval($regs[1]);
1166
-		}
1167
-	}
1168
-
1169
-	// Echec avec HEAD, on tente avec GET
1170
-	if (!$a and !$max) {
1171
-		spip_log("tenter GET $source");
1172
-		$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1173
-	}
1174
-
1175
-	// si on a rien trouve pas la peine d'insister
1176
-	if (!$a) {
1177
-		return false;
1178
-	}
1179
-
1180
-	// S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1181
-	// recharger le document en GET et recuperer des donnees supplementaires...
1182
-	if (preg_match(',^image/(jpeg|gif|png|swf|svg),', $mime_type)) {
1183
-		if ($max == 0
1184
-			and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1185
-			and in_array($a['extension'], formats_image_acceptables())
1186
-			and $charger_si_petite_image
1187
-		) {
1188
-			$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1189
-		} else {
1190
-			if ($a['body']) {
1191
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $a['extension']);
1192
-				ecrire_fichier($a['fichier'], $a['body']);
1193
-				$size_image = @spip_getimagesize($a['fichier']);
1194
-				$a['largeur'] = intval($size_image[0]);
1195
-				$a['hauteur'] = intval($size_image[1]);
1196
-				$a['type_image'] = true;
1197
-			}
1198
-		}
1199
-	}
1200
-
1201
-	// Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1202
-	// ce sera mieux que 0x0
1203
-	if ($a and isset($a['extension']) and $a['extension'] == 'swf'
1204
-		and empty($a['largeur'])
1205
-	) {
1206
-		$a['largeur'] = 425;
1207
-		$a['hauteur'] = 350;
1208
-	}
1209
-
1210
-	if ($mime_type == 'text/html') {
1211
-		include_spip('inc/filtres');
1212
-		$page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE);
1213
-		if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1214
-			$a['titre'] = corriger_caracteres(trim($regs[1]));
1215
-		}
1216
-		if (!isset($a['taille']) or !$a['taille']) {
1217
-			$a['taille'] = strlen($page); # a peu pres
1218
-		}
1219
-	}
1220
-	$a['mime_type'] = $mime_type;
1221
-
1222
-	return $a;
1089
+    // pas la peine de perdre son temps
1090
+    if (!tester_url_absolue($source)) {
1091
+        return false;
1092
+    }
1093
+
1094
+    # charger les alias des types mime
1095
+    include_spip('base/typedoc');
1096
+
1097
+    $a = array();
1098
+    $mime_type = '';
1099
+    // On va directement charger le debut des images et des fichiers html,
1100
+    // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
1101
+    // ca echoue l'utilisateur devra les entrer...
1102
+    if ($headers = recuperer_page($source, false, true, $max, '', '', true)) {
1103
+        list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2);
1104
+
1105
+        if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1106
+            $mime_type = (trim($regs[1]));
1107
+        } else {
1108
+            $mime_type = '';
1109
+        } // inconnu
1110
+
1111
+        // Appliquer les alias
1112
+        while (isset($GLOBALS['mime_alias'][$mime_type])) {
1113
+            $mime_type = $GLOBALS['mime_alias'][$mime_type];
1114
+        }
1115
+
1116
+        // Si on a un mime-type insignifiant
1117
+        // text/plain,application/octet-stream ou vide
1118
+        // c'est peut-etre que le serveur ne sait pas
1119
+        // ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1120
+        // ou le Content-Disposition: attachment; filename=...
1121
+        $t = null;
1122
+        if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) {
1123
+            if (!$t
1124
+                and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1125
+            ) {
1126
+                $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1127
+            }
1128
+            if (!$t
1129
+                and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1130
+                and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1131
+            ) {
1132
+                $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1133
+            }
1134
+        }
1135
+
1136
+        // Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1137
+        if (!$t) {
1138
+            $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1139
+        }
1140
+
1141
+        // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1142
+        // On essaie de nouveau avec l'extension
1143
+        if (!$t
1144
+            and $mime_type != 'text/plain'
1145
+            and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1146
+        ) {
1147
+            # eviter xxx.3 => 3gp (> SPIP 3)
1148
+            $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1149
+        }
1150
+
1151
+        if ($t) {
1152
+            spip_log("mime-type $mime_type ok, extension " . $t['extension']);
1153
+            $a['extension'] = $t['extension'];
1154
+        } else {
1155
+            # par defaut on retombe sur '.bin' si c'est autorise
1156
+            spip_log("mime-type $mime_type inconnu");
1157
+            $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1158
+            if (!$t) {
1159
+                return false;
1160
+            }
1161
+            $a['extension'] = $t['extension'];
1162
+        }
1163
+
1164
+        if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
1165
+            $a['taille'] = intval($regs[1]);
1166
+        }
1167
+    }
1168
+
1169
+    // Echec avec HEAD, on tente avec GET
1170
+    if (!$a and !$max) {
1171
+        spip_log("tenter GET $source");
1172
+        $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1173
+    }
1174
+
1175
+    // si on a rien trouve pas la peine d'insister
1176
+    if (!$a) {
1177
+        return false;
1178
+    }
1179
+
1180
+    // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1181
+    // recharger le document en GET et recuperer des donnees supplementaires...
1182
+    if (preg_match(',^image/(jpeg|gif|png|swf|svg),', $mime_type)) {
1183
+        if ($max == 0
1184
+            and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1185
+            and in_array($a['extension'], formats_image_acceptables())
1186
+            and $charger_si_petite_image
1187
+        ) {
1188
+            $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1189
+        } else {
1190
+            if ($a['body']) {
1191
+                $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $a['extension']);
1192
+                ecrire_fichier($a['fichier'], $a['body']);
1193
+                $size_image = @spip_getimagesize($a['fichier']);
1194
+                $a['largeur'] = intval($size_image[0]);
1195
+                $a['hauteur'] = intval($size_image[1]);
1196
+                $a['type_image'] = true;
1197
+            }
1198
+        }
1199
+    }
1200
+
1201
+    // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1202
+    // ce sera mieux que 0x0
1203
+    if ($a and isset($a['extension']) and $a['extension'] == 'swf'
1204
+        and empty($a['largeur'])
1205
+    ) {
1206
+        $a['largeur'] = 425;
1207
+        $a['hauteur'] = 350;
1208
+    }
1209
+
1210
+    if ($mime_type == 'text/html') {
1211
+        include_spip('inc/filtres');
1212
+        $page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE);
1213
+        if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1214
+            $a['titre'] = corriger_caracteres(trim($regs[1]));
1215
+        }
1216
+        if (!isset($a['taille']) or !$a['taille']) {
1217
+            $a['taille'] = strlen($page); # a peu pres
1218
+        }
1219
+    }
1220
+    $a['mime_type'] = $mime_type;
1221
+
1222
+    return $a;
1223 1223
 }
1224 1224
 
1225 1225
 
@@ -1235,45 +1235,45 @@  discard block
 block discarded – undo
1235 1235
  * @return string
1236 1236
  */
1237 1237
 function need_proxy($host, $http_proxy = null, $http_noproxy = null) {
1238
-	if (is_null($http_proxy)) {
1239
-		$http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null;
1240
-	}
1241
-	// rien a faire si pas de proxy :)
1242
-	if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1243
-		return '';
1244
-	}
1245
-
1246
-	if (is_null($http_noproxy)) {
1247
-		$http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null;
1248
-	}
1249
-	// si pas d'exception, on retourne le proxy
1250
-	if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1251
-		return $http_proxy;
1252
-	}
1253
-
1254
-	// si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1255
-	// $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1256
-	$http_noproxy = str_replace("\n", " ", $http_noproxy);
1257
-	$http_noproxy = str_replace("\r", " ", $http_noproxy);
1258
-	$http_noproxy = " $http_noproxy ";
1259
-	$domain = $host;
1260
-	// si le domaine exact www.example.org est dans les exceptions
1261
-	if (strpos($http_noproxy, " $domain ") !== false)
1262
-		return '';
1263
-
1264
-	while (strpos($domain, '.') !== false) {
1265
-		$domain = explode('.', $domain);
1266
-		array_shift($domain);
1267
-		$domain = implode('.', $domain);
1268
-
1269
-		// ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1270
-		if (strpos($http_noproxy, " .$domain ") !== false) {
1271
-			return '';
1272
-		}
1273
-	}
1274
-
1275
-	// ok c'est pas une exception
1276
-	return $http_proxy;
1238
+    if (is_null($http_proxy)) {
1239
+        $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null;
1240
+    }
1241
+    // rien a faire si pas de proxy :)
1242
+    if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1243
+        return '';
1244
+    }
1245
+
1246
+    if (is_null($http_noproxy)) {
1247
+        $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null;
1248
+    }
1249
+    // si pas d'exception, on retourne le proxy
1250
+    if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1251
+        return $http_proxy;
1252
+    }
1253
+
1254
+    // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1255
+    // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1256
+    $http_noproxy = str_replace("\n", " ", $http_noproxy);
1257
+    $http_noproxy = str_replace("\r", " ", $http_noproxy);
1258
+    $http_noproxy = " $http_noproxy ";
1259
+    $domain = $host;
1260
+    // si le domaine exact www.example.org est dans les exceptions
1261
+    if (strpos($http_noproxy, " $domain ") !== false)
1262
+        return '';
1263
+
1264
+    while (strpos($domain, '.') !== false) {
1265
+        $domain = explode('.', $domain);
1266
+        array_shift($domain);
1267
+        $domain = implode('.', $domain);
1268
+
1269
+        // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1270
+        if (strpos($http_noproxy, " .$domain ") !== false) {
1271
+            return '';
1272
+        }
1273
+    }
1274
+
1275
+    // ok c'est pas une exception
1276
+    return $http_proxy;
1277 1277
 }
1278 1278
 
1279 1279
 
@@ -1296,58 +1296,58 @@  discard block
 block discarded – undo
1296 1296
  * @return array
1297 1297
  */
1298 1298
 function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') {
1299
-	$user = $via_proxy = $proxy_user = '';
1300
-	$fopen = false;
1301
-
1302
-	$t = @parse_url($url);
1303
-	$host = $t['host'];
1304
-	if ($t['scheme'] == 'http') {
1305
-		$scheme = 'http';
1306
-		$noproxy = '';
1307
-	} elseif ($t['scheme'] == 'https') {
1308
-		$scheme = 'ssl';
1309
-		$noproxy = 'ssl://';
1310
-		if (!isset($t['port']) || !($port = $t['port'])) {
1311
-			$t['port'] = 443;
1312
-		}
1313
-	} else {
1314
-		$scheme = $t['scheme'];
1315
-		$noproxy = $scheme . '://';
1316
-	}
1317
-	if (isset($t['user'])) {
1318
-		$user = array($t['user'], $t['pass']);
1319
-	}
1320
-
1321
-	if (!isset($t['port']) || !($port = $t['port'])) {
1322
-		$port = 80;
1323
-	}
1324
-	if (!isset($t['path']) || !($path = $t['path'])) {
1325
-		$path = '/';
1326
-	}
1327
-
1328
-	if (!empty($t['query'])) {
1329
-		$path .= '?' . $t['query'];
1330
-	}
1331
-
1332
-	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1333
-	if (!$f or !is_resource($f)) {
1334
-		// fallback : fopen si on a pas fait timeout dans lance_requete
1335
-		// ce qui correspond a $f===110
1336
-		if ($f !== 110
1337
-			and !need_proxy($host)
1338
-			and !_request('tester_proxy')
1339
-			and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1340
-		) {
1341
-			$f = @fopen($url, 'rb');
1342
-			spip_log("connexion vers $url par simple fopen");
1343
-			$fopen = true;
1344
-		} else {
1345
-			// echec total
1346
-			$f = false;
1347
-		}
1348
-	}
1349
-
1350
-	return array($f, $fopen);
1299
+    $user = $via_proxy = $proxy_user = '';
1300
+    $fopen = false;
1301
+
1302
+    $t = @parse_url($url);
1303
+    $host = $t['host'];
1304
+    if ($t['scheme'] == 'http') {
1305
+        $scheme = 'http';
1306
+        $noproxy = '';
1307
+    } elseif ($t['scheme'] == 'https') {
1308
+        $scheme = 'ssl';
1309
+        $noproxy = 'ssl://';
1310
+        if (!isset($t['port']) || !($port = $t['port'])) {
1311
+            $t['port'] = 443;
1312
+        }
1313
+    } else {
1314
+        $scheme = $t['scheme'];
1315
+        $noproxy = $scheme . '://';
1316
+    }
1317
+    if (isset($t['user'])) {
1318
+        $user = array($t['user'], $t['pass']);
1319
+    }
1320
+
1321
+    if (!isset($t['port']) || !($port = $t['port'])) {
1322
+        $port = 80;
1323
+    }
1324
+    if (!isset($t['path']) || !($path = $t['path'])) {
1325
+        $path = '/';
1326
+    }
1327
+
1328
+    if (!empty($t['query'])) {
1329
+        $path .= '?' . $t['query'];
1330
+    }
1331
+
1332
+    $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1333
+    if (!$f or !is_resource($f)) {
1334
+        // fallback : fopen si on a pas fait timeout dans lance_requete
1335
+        // ce qui correspond a $f===110
1336
+        if ($f !== 110
1337
+            and !need_proxy($host)
1338
+            and !_request('tester_proxy')
1339
+            and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1340
+        ) {
1341
+            $f = @fopen($url, 'rb');
1342
+            spip_log("connexion vers $url par simple fopen");
1343
+            $fopen = true;
1344
+        } else {
1345
+            // echec total
1346
+            $f = false;
1347
+        }
1348
+    }
1349
+
1350
+    return array($f, $fopen);
1351 1351
 }
1352 1352
 
1353 1353
 /**
@@ -1382,127 +1382,127 @@  discard block
 block discarded – undo
1382 1382
  *   resource socket vers l'url demandee
1383 1383
  */
1384 1384
 function lance_requete(
1385
-	$method,
1386
-	$scheme,
1387
-	$user,
1388
-	$host,
1389
-	$path,
1390
-	$port,
1391
-	$noproxy,
1392
-	$refuse_gz = false,
1393
-	$referer = '',
1394
-	$datas = '',
1395
-	$vers = 'HTTP/1.0',
1396
-	$date = ''
1385
+    $method,
1386
+    $scheme,
1387
+    $user,
1388
+    $host,
1389
+    $path,
1390
+    $port,
1391
+    $noproxy,
1392
+    $refuse_gz = false,
1393
+    $referer = '',
1394
+    $datas = '',
1395
+    $vers = 'HTTP/1.0',
1396
+    $date = ''
1397 1397
 ) {
1398 1398
 
1399
-	$proxy_user = '';
1400
-	$http_proxy = need_proxy($host);
1401
-	if ($user) {
1402
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1403
-	}
1404
-
1405
-	$connect = '';
1406
-	if ($http_proxy) {
1407
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) {
1408
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1409
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1410
-				. "Host: $path_host\r\n"
1411
-				. "Proxy-Connection: Keep-Alive\r\n";
1412
-		} else {
1413
-			$path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://")
1414
-				. (!$user ? '' : "$user@")
1415
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1416
-		}
1417
-		$t2 = @parse_url($http_proxy);
1418
-		$first_host = $t2['host'];
1419
-		if (!($port = $t2['port'])) {
1420
-			$port = 80;
1421
-		}
1422
-		if ($t2['user']) {
1423
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1424
-		}
1425
-	} else {
1426
-		$first_host = $noproxy . $host;
1427
-	}
1428
-
1429
-	if ($connect) {
1430
-		$streamContext = stream_context_create(array(
1431
-			'ssl' => array(
1432
-				'verify_peer' => false,
1433
-				'allow_self_signed' => true,
1434
-				'SNI_enabled' => true,
1435
-				'peer_name' => $host,
1436
-			)
1437
-		));
1438
-		if (version_compare(phpversion(), '5.6', '<')) {
1439
-			stream_context_set_option($streamContext, 'ssl', 'SNI_server_name', $host);
1440
-		}
1441
-		$f = @stream_socket_client(
1442
-			"tcp://$first_host:$port",
1443
-			$errno,
1444
-			$errstr,
1445
-			_INC_DISTANT_CONNECT_TIMEOUT,
1446
-			STREAM_CLIENT_CONNECT,
1447
-			$streamContext
1448
-		);
1449
-		spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1450
-		if (!$f) {
1451
-			spip_log("Erreur connexion $errno $errstr", _LOG_ERREUR);
1452
-			return $errno;
1453
-		}
1454
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1455
-
1456
-		fputs($f, $connect);
1457
-		fputs($f, "\r\n");
1458
-		$res = fread($f, 1024);
1459
-		if (!$res
1460
-			or !count($res = explode(' ', $res))
1461
-			or $res[1] !== '200'
1462
-		) {
1463
-			spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1464
-			fclose($f);
1465
-
1466
-			return false;
1467
-		}
1468
-		// important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1469
-		stream_set_blocking($f, true);
1470
-		// envoyer le handshake
1471
-		stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1472
-		spip_log("OK CONNECT sur $first_host:$port", 'connect');
1473
-	} else {
1474
-		$ntry = 3;
1475
-		do {
1476
-			$f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1477
-		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1478
-		spip_log("Recuperer $path sur $first_host:$port par $f");
1479
-		if (!$f) {
1480
-			spip_log("Erreur connexion $errno $errstr", _LOG_ERREUR);
1481
-
1482
-			return $errno;
1483
-		}
1484
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1485
-	}
1486
-
1487
-	$site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1488
-
1489
-	$host_port = $host;
1490
-	if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) {
1491
-		$host_port .= ":$port";
1492
-	}
1493
-	$req = "$method $path $vers\r\n"
1494
-		. "Host: $host_port\r\n"
1495
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1496
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1497
-		. (!$site ? '' : "Referer: $site/$referer\r\n")
1498
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1499
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1500
-		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1501
-		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1399
+    $proxy_user = '';
1400
+    $http_proxy = need_proxy($host);
1401
+    if ($user) {
1402
+        $user = urlencode($user[0]) . ':' . urlencode($user[1]);
1403
+    }
1404
+
1405
+    $connect = '';
1406
+    if ($http_proxy) {
1407
+        if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) {
1408
+            $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1409
+            $connect = 'CONNECT ' . $path_host . " $vers\r\n"
1410
+                . "Host: $path_host\r\n"
1411
+                . "Proxy-Connection: Keep-Alive\r\n";
1412
+        } else {
1413
+            $path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://")
1414
+                . (!$user ? '' : "$user@")
1415
+                . "$host" . (($port != 80) ? ":$port" : '') . $path;
1416
+        }
1417
+        $t2 = @parse_url($http_proxy);
1418
+        $first_host = $t2['host'];
1419
+        if (!($port = $t2['port'])) {
1420
+            $port = 80;
1421
+        }
1422
+        if ($t2['user']) {
1423
+            $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1424
+        }
1425
+    } else {
1426
+        $first_host = $noproxy . $host;
1427
+    }
1428
+
1429
+    if ($connect) {
1430
+        $streamContext = stream_context_create(array(
1431
+            'ssl' => array(
1432
+                'verify_peer' => false,
1433
+                'allow_self_signed' => true,
1434
+                'SNI_enabled' => true,
1435
+                'peer_name' => $host,
1436
+            )
1437
+        ));
1438
+        if (version_compare(phpversion(), '5.6', '<')) {
1439
+            stream_context_set_option($streamContext, 'ssl', 'SNI_server_name', $host);
1440
+        }
1441
+        $f = @stream_socket_client(
1442
+            "tcp://$first_host:$port",
1443
+            $errno,
1444
+            $errstr,
1445
+            _INC_DISTANT_CONNECT_TIMEOUT,
1446
+            STREAM_CLIENT_CONNECT,
1447
+            $streamContext
1448
+        );
1449
+        spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1450
+        if (!$f) {
1451
+            spip_log("Erreur connexion $errno $errstr", _LOG_ERREUR);
1452
+            return $errno;
1453
+        }
1454
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1455
+
1456
+        fputs($f, $connect);
1457
+        fputs($f, "\r\n");
1458
+        $res = fread($f, 1024);
1459
+        if (!$res
1460
+            or !count($res = explode(' ', $res))
1461
+            or $res[1] !== '200'
1462
+        ) {
1463
+            spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1464
+            fclose($f);
1465
+
1466
+            return false;
1467
+        }
1468
+        // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1469
+        stream_set_blocking($f, true);
1470
+        // envoyer le handshake
1471
+        stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1472
+        spip_log("OK CONNECT sur $first_host:$port", 'connect');
1473
+    } else {
1474
+        $ntry = 3;
1475
+        do {
1476
+            $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1477
+        } while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1478
+        spip_log("Recuperer $path sur $first_host:$port par $f");
1479
+        if (!$f) {
1480
+            spip_log("Erreur connexion $errno $errstr", _LOG_ERREUR);
1481
+
1482
+            return $errno;
1483
+        }
1484
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1485
+    }
1486
+
1487
+    $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1488
+
1489
+    $host_port = $host;
1490
+    if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) {
1491
+        $host_port .= ":$port";
1492
+    }
1493
+    $req = "$method $path $vers\r\n"
1494
+        . "Host: $host_port\r\n"
1495
+        . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1496
+        . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1497
+        . (!$site ? '' : "Referer: $site/$referer\r\n")
1498
+        . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1499
+        . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1500
+        . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1501
+        . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1502 1502
 
1503 1503
 #	spip_log("Requete\n$req");
1504
-	fputs($f, $req);
1505
-	fputs($f, $datas ? $datas : "\r\n");
1504
+    fputs($f, $req);
1505
+    fputs($f, $datas ? $datas : "\r\n");
1506 1506
 
1507
-	return $f;
1507
+    return $f;
1508 1508
 }
Please login to merge, or discard this patch.
Spacing   +57 added lines, -57 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'], _LOG_INFO_IMPORTANTE);
118
+			spip_log("copie_locale : Echec recuperation $source sur $localrac status : ".$res['status'], _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');
124
+		spip_log("copie_locale : recuperation $source sur $localrac taille ".$res['length'].' OK');
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);
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
 
506 506
 			return recuperer_url($url, $options);
507 507
 		} elseif ($res['status'] !== 200) {
508
-			spip_log('HTTP status ' . $res['status'] . " pour $url");
508
+			spip_log('HTTP status '.$res['status']." pour $url");
509 509
 		}
510 510
 		$result['status'] = $res['status'];
511 511
 		if (isset($res['headers'])) {
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
 
531 531
 	$gz = false;
532 532
 	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
533
-		$gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
533
+		$gz = (_DIR_TMP.md5(uniqid(mt_rand())).'.tmp.gz');
534 534
 	}
535 535
 
536 536
 	// si on a pas deja recuperer le contenu par une methode detournee
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
 	$sig['url'] = $url;
617 617
 
618 618
 	$dir = sous_repertoire(_DIR_CACHE, 'curl');
619
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
619
+	$cache = md5(serialize($sig)).'-'.substr(preg_replace(',\W+,', '_', $url), 0, 80);
620 620
 	$sub = sous_repertoire($dir, substr($cache, 0, 2));
621 621
 	$cache = "$sub$cache";
622 622
 
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
 		return false;
726 726
 	}
727 727
 	if ($get_headers) {
728
-		return $res['headers'] . "\n" . $res['page'];
728
+		return $res['headers']."\n".$res['page'];
729 729
 	}
730 730
 
731 731
 	return $res['page'];
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
 	$fp = false;
830 830
 	if ($fichier) {
831 831
 		include_spip('inc/acces');
832
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
832
+		$tmpfile = "$fichier.".creer_uniqid().'.tmp';
833 833
 		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
834 834
 		if (!$fp and file_exists($fichier)) {
835 835
 			return filesize($fichier);
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
 	}
889 889
 	$result['status'] = intval($r[1]);
890 890
 	while ($s = trim(fgets($handle, 16384))) {
891
-		$result['headers'][] = $s . "\n";
891
+		$result['headers'][] = $s."\n";
892 892
 		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
893 893
 		list(, $d, $v) = $r;
894 894
 		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
@@ -971,13 +971,13 @@  discard block
 block discarded – undo
971 971
 
972 972
 	// on se place tout le temps comme si on etait a la racine
973 973
 	if (_DIR_RACINE) {
974
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
974
+		$d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d);
975 975
 	}
976 976
 
977 977
 	$m = md5($source);
978 978
 
979 979
 	return $d
980
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
980
+	. substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12)
981 981
 	. substr($m, 0, 4)
982 982
 	. ".$extension";
983 983
 }
@@ -1000,7 +1000,7 @@  discard block
 block discarded – undo
1000 1000
 	// Si c'est deja local pas de souci
1001 1001
 	if (!tester_url_absolue($source)) {
1002 1002
 		if (_DIR_RACINE) {
1003
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
1003
+			$source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source);
1004 1004
 		}
1005 1005
 
1006 1006
 		return $source;
@@ -1017,7 +1017,7 @@  discard block
 block discarded – undo
1017 1017
 	if ($ext
1018 1018
 		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
1019 1019
 		and $f = nom_fichier_copie_locale($source, $ext)
1020
-		and file_exists(_DIR_RACINE . $f)
1020
+		and file_exists(_DIR_RACINE.$f)
1021 1021
 	) {
1022 1022
 		return $f;
1023 1023
 	}
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
 
1026 1026
 	// Si c'est deja dans la table des documents,
1027 1027
 	// ramener le nom de sa copie potentielle
1028
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
1028
+	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier='.sql_quote($source)." AND distant='oui' AND extension <> ''");
1029 1029
 
1030 1030
 	if ($ext) {
1031 1031
 		return nom_fichier_copie_locale($source, $ext);
@@ -1036,9 +1036,9 @@  discard block
 block discarded – undo
1036 1036
 
1037 1037
 	$ext = $path_parts ? $path_parts['extension'] : '';
1038 1038
 
1039
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1039
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
1040 1040
 		$f = nom_fichier_copie_locale($source, $ext);
1041
-		if (file_exists(_DIR_RACINE . $f)) {
1041
+		if (file_exists(_DIR_RACINE.$f)) {
1042 1042
 			return $f;
1043 1043
 		}
1044 1044
 	}
@@ -1046,7 +1046,7 @@  discard block
 block discarded – undo
1046 1046
 	// Ping  pour voir si son extension est connue et autorisee
1047 1047
 	// avec mise en cache du resultat du ping
1048 1048
 
1049
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
1049
+	$cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source);
1050 1050
 	if (!@file_exists($cache)
1051 1051
 		or !$path_parts = @unserialize(spip_file_get_contents($cache))
1052 1052
 		or _request('var_mode') == 'recalcul'
@@ -1055,7 +1055,7 @@  discard block
 block discarded – undo
1055 1055
 		ecrire_fichier($cache, serialize($path_parts));
1056 1056
 	}
1057 1057
 	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
1058
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1058
+	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) {
1059 1059
 		return nom_fichier_copie_locale($source, $ext);
1060 1060
 	}
1061 1061
 	spip_log("pas de copie locale pour $source");
@@ -1123,19 +1123,19 @@  discard block
 block discarded – undo
1123 1123
 			if (!$t
1124 1124
 				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1125 1125
 			) {
1126
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1126
+				$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text'));
1127 1127
 			}
1128 1128
 			if (!$t
1129 1129
 				and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1130 1130
 				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1131 1131
 			) {
1132
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1132
+				$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text'));
1133 1133
 			}
1134 1134
 		}
1135 1135
 
1136 1136
 		// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1137 1137
 		if (!$t) {
1138
-			$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1138
+			$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type='.sql_quote($mime_type));
1139 1139
 		}
1140 1140
 
1141 1141
 		// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
@@ -1145,11 +1145,11 @@  discard block
 block discarded – undo
1145 1145
 			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1146 1146
 		) {
1147 1147
 			# eviter xxx.3 => 3gp (> SPIP 3)
1148
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1148
+			$t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text'));
1149 1149
 		}
1150 1150
 
1151 1151
 		if ($t) {
1152
-			spip_log("mime-type $mime_type ok, extension " . $t['extension']);
1152
+			spip_log("mime-type $mime_type ok, extension ".$t['extension']);
1153 1153
 			$a['extension'] = $t['extension'];
1154 1154
 		} else {
1155 1155
 			# par defaut on retombe sur '.bin' si c'est autorise
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
 			$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1189 1189
 		} else {
1190 1190
 			if ($a['body']) {
1191
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $a['extension']);
1191
+				$a['fichier'] = _DIR_RACINE.nom_fichier_copie_locale($source, $a['extension']);
1192 1192
 				ecrire_fichier($a['fichier'], $a['body']);
1193 1193
 				$size_image = @spip_getimagesize($a['fichier']);
1194 1194
 				$a['largeur'] = intval($size_image[0]);
@@ -1312,7 +1312,7 @@  discard block
 block discarded – undo
1312 1312
 		}
1313 1313
 	} else {
1314 1314
 		$scheme = $t['scheme'];
1315
-		$noproxy = $scheme . '://';
1315
+		$noproxy = $scheme.'://';
1316 1316
 	}
1317 1317
 	if (isset($t['user'])) {
1318 1318
 		$user = array($t['user'], $t['pass']);
@@ -1326,7 +1326,7 @@  discard block
 block discarded – undo
1326 1326
 	}
1327 1327
 
1328 1328
 	if (!empty($t['query'])) {
1329
-		$path .= '?' . $t['query'];
1329
+		$path .= '?'.$t['query'];
1330 1330
 	}
1331 1331
 
1332 1332
 	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
@@ -1399,20 +1399,20 @@  discard block
 block discarded – undo
1399 1399
 	$proxy_user = '';
1400 1400
 	$http_proxy = need_proxy($host);
1401 1401
 	if ($user) {
1402
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1402
+		$user = urlencode($user[0]).':'.urlencode($user[1]);
1403 1403
 	}
1404 1404
 
1405 1405
 	$connect = '';
1406 1406
 	if ($http_proxy) {
1407
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) {
1408
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1409
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1407
+		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, array('tls', 'ssl'))) {
1408
+			$path_host = (!$user ? '' : "$user@").$host.(($port != 80) ? ":$port" : '');
1409
+			$connect = 'CONNECT '.$path_host." $vers\r\n"
1410 1410
 				. "Host: $path_host\r\n"
1411 1411
 				. "Proxy-Connection: Keep-Alive\r\n";
1412 1412
 		} else {
1413
-			$path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://")
1413
+			$path = (in_array($scheme, array('tls', 'ssl')) ? 'https://' : "$scheme://")
1414 1414
 				. (!$user ? '' : "$user@")
1415
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1415
+				. "$host".(($port != 80) ? ":$port" : '').$path;
1416 1416
 		}
1417 1417
 		$t2 = @parse_url($http_proxy);
1418 1418
 		$first_host = $t2['host'];
@@ -1420,10 +1420,10 @@  discard block
 block discarded – undo
1420 1420
 			$port = 80;
1421 1421
 		}
1422 1422
 		if ($t2['user']) {
1423
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1423
+			$proxy_user = base64_encode($t2['user'].':'.$t2['pass']);
1424 1424
 		}
1425 1425
 	} else {
1426
-		$first_host = $noproxy . $host;
1426
+		$first_host = $noproxy.$host;
1427 1427
 	}
1428 1428
 
1429 1429
 	if ($connect) {
@@ -1460,7 +1460,7 @@  discard block
 block discarded – undo
1460 1460
 			or !count($res = explode(' ', $res))
1461 1461
 			or $res[1] !== '200'
1462 1462
 		) {
1463
-			spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1463
+			spip_log("Echec CONNECT sur $first_host:$port", 'connect'._LOG_INFO_IMPORTANTE);
1464 1464
 			fclose($f);
1465 1465
 
1466 1466
 			return false;
@@ -1487,16 +1487,16 @@  discard block
 block discarded – undo
1487 1487
 	$site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1488 1488
 
1489 1489
 	$host_port = $host;
1490
-	if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) {
1490
+	if ($port != (in_array($scheme, array('tls', 'ssl')) ? 443 : 80)) {
1491 1491
 		$host_port .= ":$port";
1492 1492
 	}
1493 1493
 	$req = "$method $path $vers\r\n"
1494 1494
 		. "Host: $host_port\r\n"
1495
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1496
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1495
+		. 'User-Agent: '._INC_DISTANT_USER_AGENT."\r\n"
1496
+		. ($refuse_gz ? '' : ('Accept-Encoding: '._INC_DISTANT_CONTENT_ENCODING."\r\n"))
1497 1497
 		. (!$site ? '' : "Referer: $site/$referer\r\n")
1498
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1499
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1498
+		. (!$date ? '' : 'If-Modified-Since: '.(gmdate('D, d M Y H:i:s', $date)." GMT\r\n"))
1499
+		. (!$user ? '' : ('Authorization: Basic '.base64_encode($user)."\r\n"))
1500 1500
 		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1501 1501
 		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1502 1502
 
Please login to merge, or discard this patch.
ecrire/public/quete.php 1 patch
Indentation   +387 added lines, -387 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  **/
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 
@@ -33,16 +33,16 @@  discard block
 block discarded – undo
33 33
  * @return array|bool|null
34 34
  */
35 35
 function quete_virtuel($id_article, $connect) {
36
-	return sql_getfetsel(
37
-		'virtuel',
38
-		'spip_articles',
39
-		array('id_article=' . intval($id_article), "statut='publie'"),
40
-		'',
41
-		'',
42
-		'',
43
-		'',
44
-		$connect
45
-	);
36
+    return sql_getfetsel(
37
+        'virtuel',
38
+        'spip_articles',
39
+        array('id_article=' . intval($id_article), "statut='publie'"),
40
+        '',
41
+        '',
42
+        '',
43
+        '',
44
+        $connect
45
+    );
46 46
 }
47 47
 
48 48
 /**
@@ -57,38 +57,38 @@  discard block
 block discarded – undo
57 57
  * @return array
58 58
  */
59 59
 function quete_parent_lang($table, $id, $connect = '') {
60
-	static $cache_quete = array();
61
-
62
-	if (!isset($cache_quete[$connect][$table][$id])) {
63
-		if (!isset($cache_quete[$connect][$table]['_select'])) {
64
-			$trouver_table = charger_fonction('trouver_table', 'base');
65
-			if (!$desc = $trouver_table($table,
66
-					$connect) or !isset($desc['field']['id_rubrique'])
67
-			) {
68
-				// pas de parent rubrique, on passe
69
-				$cache_quete[$connect][$table]['_select'] = false;
70
-			} else {
71
-				$select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique');
72
-				$select .= isset($desc['field']['lang']) ? ', lang' : '';
73
-				$cache_quete[$connect][$table]['_select'] = $select;
74
-				$cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table));
75
-			}
76
-		}
77
-		if ($cache_quete[$connect][$table]['_select']) {
78
-			$cache_quete[$connect][$table][$id] = sql_fetsel(
79
-				$cache_quete[$connect][$table]['_select'],
80
-				$table,
81
-				$cache_quete[$connect][$table]['_id'] . '=' . intval($id),
82
-				'',
83
-				'',
84
-				'',
85
-				'',
86
-				$connect
87
-			);
88
-		}
89
-	}
90
-
91
-	return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null;
60
+    static $cache_quete = array();
61
+
62
+    if (!isset($cache_quete[$connect][$table][$id])) {
63
+        if (!isset($cache_quete[$connect][$table]['_select'])) {
64
+            $trouver_table = charger_fonction('trouver_table', 'base');
65
+            if (!$desc = $trouver_table($table,
66
+                    $connect) or !isset($desc['field']['id_rubrique'])
67
+            ) {
68
+                // pas de parent rubrique, on passe
69
+                $cache_quete[$connect][$table]['_select'] = false;
70
+            } else {
71
+                $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique');
72
+                $select .= isset($desc['field']['lang']) ? ', lang' : '';
73
+                $cache_quete[$connect][$table]['_select'] = $select;
74
+                $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table));
75
+            }
76
+        }
77
+        if ($cache_quete[$connect][$table]['_select']) {
78
+            $cache_quete[$connect][$table][$id] = sql_fetsel(
79
+                $cache_quete[$connect][$table]['_select'],
80
+                $table,
81
+                $cache_quete[$connect][$table]['_id'] . '=' . intval($id),
82
+                '',
83
+                '',
84
+                '',
85
+                '',
86
+                $connect
87
+            );
88
+        }
89
+    }
90
+
91
+    return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null;
92 92
 }
93 93
 
94 94
 
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
  * @return int
106 106
  */
107 107
 function quete_parent($id_rubrique, $connect = '') {
108
-	if (!$id_rubrique = intval($id_rubrique)) {
109
-		return 0;
110
-	}
111
-	$id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect);
108
+    if (!$id_rubrique = intval($id_rubrique)) {
109
+        return 0;
110
+    }
111
+    $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect);
112 112
 
113
-	return $id_parent['id_parent'];
113
+    return $id_parent['id_parent'];
114 114
 }
115 115
 
116 116
 /**
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
  * @return int
127 127
  */
128 128
 function quete_rubrique($id_article, $serveur) {
129
-	$id_parent = quete_parent_lang('spip_articles', $id_article, $serveur);
129
+    $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur);
130 130
 
131
-	return $id_parent['id_rubrique'];
131
+    return $id_parent['id_rubrique'];
132 132
 }
133 133
 
134 134
 
@@ -142,13 +142,13 @@  discard block
 block discarded – undo
142 142
  * @return int
143 143
  */
144 144
 function quete_profondeur($id, $connect = '') {
145
-	$n = 0;
146
-	while ($id) {
147
-		$n++;
148
-		$id = quete_parent($id, $connect);
149
-	}
145
+    $n = 0;
146
+    while ($id) {
147
+        $n++;
148
+        $id = quete_parent($id, $connect);
149
+    }
150 150
 
151
-	return $n;
151
+    return $n;
152 152
 }
153 153
 
154 154
 
@@ -164,15 +164,15 @@  discard block
 block discarded – undo
164 164
  *     Morceau de la requête SQL testant la date
165 165
  */
166 166
 function quete_condition_postdates($champ_date, $serveur = '', $ignore_previsu = false) {
167
-	if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
168
-		return '1=1';
169
-	}
170
-
171
-	return
172
-		(isset($GLOBALS['meta']['date_prochain_postdate'])
173
-			and $GLOBALS['meta']['date_prochain_postdate'] > time())
174
-			? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur)
175
-			: '1=1';
167
+    if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
168
+        return '1=1';
169
+    }
170
+
171
+    return
172
+        (isset($GLOBALS['meta']['date_prochain_postdate'])
173
+            and $GLOBALS['meta']['date_prochain_postdate'] > time())
174
+            ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur)
175
+            : '1=1';
176 176
 }
177 177
 
178 178
 
@@ -192,100 +192,100 @@  discard block
 block discarded – undo
192 192
  * @return array|string
193 193
  */
194 194
 function quete_condition_statut($mstatut, $previsu, $publie, $serveur = '', $ignore_previsu = false) {
195
-	static $cond = array();
196
-	$key = func_get_args();
197
-	$key = implode('-', $key);
198
-	if (isset($cond[$key])) {
199
-		return $cond[$key];
200
-	}
201
-
202
-	$liste_statuts = $publie;
203
-	if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
204
-		$liste_statuts = $previsu;
205
-	}
206
-	$not = false;
207
-	if (strncmp($liste_statuts, '!', 1) == 0) {
208
-		$not = true;
209
-		$liste_statuts = substr($liste_statuts, 1);
210
-	}
211
-	// '' => ne rien afficher, '!'=> ne rien filtrer
212
-	if (!strlen($liste_statuts)) {
213
-		return $cond[$key] = ($not ? '1=1' : '0=1');
214
-	}
215
-
216
-	$liste_statuts = explode(',', $liste_statuts);
217
-	$where = array();
218
-	foreach ($liste_statuts as $k => $v) {
219
-		// filtrage /auteur pour limiter les objets d'un statut (prepa en general)
220
-		// a ceux de l'auteur identifie
221
-		if (strpos($v, '/') !== false) {
222
-			$v = explode('/', $v);
223
-			$filtre = end($v);
224
-			$v = reset($v);
225
-			$v = preg_replace(',\W,', '', $v);
226
-			if ($filtre == 'auteur'
227
-				and (strpos($mstatut, '.') !== false)
228
-				and $objet = explode('.', $mstatut)
229
-				and $id_table = reset($objet)
230
-				and $objet = objet_type($id_table)
231
-			) {
232
-				$w = "$mstatut<>" . sql_quote($v);
233
-
234
-				// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
235
-				// sinon l’auteur en session
236
-				include_spip('inc/securiser_action');
237
-				if ($desc = decrire_token_previsu()) {
238
-					$id_auteur = $desc['id_auteur'];
239
-				} elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
240
-					$id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
241
-				} else {
242
-					$id_auteur = null;
243
-				}
244
-
245
-				// dans ce cas (admin en general), pas de filtrage sur ce statut
246
-				if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) {
247
-					// si pas d'auteur identifie pas de sous-requete car pas d'article qui matche
248
-					if (!$id_auteur) {
249
-						$where[] = $w;
250
-					} else {
251
-						$primary = id_table_objet($objet);
252
-						$where[] = "($w OR $id_table.$primary IN (" . sql_get_select(
253
-								'ssss.id_objet',
254
-								'spip_auteurs_liens AS ssss',
255
-								'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur),
256
-								'',
257
-								'',
258
-								'',
259
-								'',
260
-								$serveur
261
-							) . '))';
262
-					}
263
-				}
264
-			} // ignorer ce statut si on ne sait pas comment le filtrer
265
-			else {
266
-				$v = '';
267
-			}
268
-		}
269
-		// securite
270
-		$liste_statuts[$k] = preg_replace(',\W,', '', $v);
271
-	}
272
-	$liste_statuts = array_filter($liste_statuts);
273
-	if (count($liste_statuts) == 1) {
274
-		$where[] = array('=', $mstatut, sql_quote(reset($liste_statuts), $serveur));
275
-	} else {
276
-		$where[] = sql_in($mstatut, $liste_statuts, $not, $serveur);
277
-	}
278
-
279
-	while (count($where) > 1) {
280
-		$and = array('AND', array_pop($where), array_pop($where));
281
-		$where[] = $and;
282
-	}
283
-	$cond[$key] = reset($where);
284
-	if ($not) {
285
-		$cond[$key] = array('NOT', $cond[$key]);
286
-	}
287
-
288
-	return $cond[$key];
195
+    static $cond = array();
196
+    $key = func_get_args();
197
+    $key = implode('-', $key);
198
+    if (isset($cond[$key])) {
199
+        return $cond[$key];
200
+    }
201
+
202
+    $liste_statuts = $publie;
203
+    if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) {
204
+        $liste_statuts = $previsu;
205
+    }
206
+    $not = false;
207
+    if (strncmp($liste_statuts, '!', 1) == 0) {
208
+        $not = true;
209
+        $liste_statuts = substr($liste_statuts, 1);
210
+    }
211
+    // '' => ne rien afficher, '!'=> ne rien filtrer
212
+    if (!strlen($liste_statuts)) {
213
+        return $cond[$key] = ($not ? '1=1' : '0=1');
214
+    }
215
+
216
+    $liste_statuts = explode(',', $liste_statuts);
217
+    $where = array();
218
+    foreach ($liste_statuts as $k => $v) {
219
+        // filtrage /auteur pour limiter les objets d'un statut (prepa en general)
220
+        // a ceux de l'auteur identifie
221
+        if (strpos($v, '/') !== false) {
222
+            $v = explode('/', $v);
223
+            $filtre = end($v);
224
+            $v = reset($v);
225
+            $v = preg_replace(',\W,', '', $v);
226
+            if ($filtre == 'auteur'
227
+                and (strpos($mstatut, '.') !== false)
228
+                and $objet = explode('.', $mstatut)
229
+                and $id_table = reset($objet)
230
+                and $objet = objet_type($id_table)
231
+            ) {
232
+                $w = "$mstatut<>" . sql_quote($v);
233
+
234
+                // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
235
+                // sinon l’auteur en session
236
+                include_spip('inc/securiser_action');
237
+                if ($desc = decrire_token_previsu()) {
238
+                    $id_auteur = $desc['id_auteur'];
239
+                } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
240
+                    $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
241
+                } else {
242
+                    $id_auteur = null;
243
+                }
244
+
245
+                // dans ce cas (admin en general), pas de filtrage sur ce statut
246
+                if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) {
247
+                    // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche
248
+                    if (!$id_auteur) {
249
+                        $where[] = $w;
250
+                    } else {
251
+                        $primary = id_table_objet($objet);
252
+                        $where[] = "($w OR $id_table.$primary IN (" . sql_get_select(
253
+                                'ssss.id_objet',
254
+                                'spip_auteurs_liens AS ssss',
255
+                                'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur),
256
+                                '',
257
+                                '',
258
+                                '',
259
+                                '',
260
+                                $serveur
261
+                            ) . '))';
262
+                    }
263
+                }
264
+            } // ignorer ce statut si on ne sait pas comment le filtrer
265
+            else {
266
+                $v = '';
267
+            }
268
+        }
269
+        // securite
270
+        $liste_statuts[$k] = preg_replace(',\W,', '', $v);
271
+    }
272
+    $liste_statuts = array_filter($liste_statuts);
273
+    if (count($liste_statuts) == 1) {
274
+        $where[] = array('=', $mstatut, sql_quote(reset($liste_statuts), $serveur));
275
+    } else {
276
+        $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur);
277
+    }
278
+
279
+    while (count($where) > 1) {
280
+        $and = array('AND', array_pop($where), array_pop($where));
281
+        $where[] = $and;
282
+    }
283
+    $cond[$key] = reset($where);
284
+    if ($not) {
285
+        $cond[$key] = array('NOT', $cond[$key]);
286
+    }
287
+
288
+    return $cond[$key];
289 289
 }
290 290
 
291 291
 /**
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
  * @return array|bool|null
297 297
  */
298 298
 function quete_fichier($id_document, $serveur = '') {
299
-	return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur);
299
+    return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur);
300 300
 }
301 301
 
302 302
 /**
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
  * @return array|bool
308 308
  */
309 309
 function quete_document($id_document, $serveur = '') {
310
-	return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur);
310
+    return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur);
311 311
 }
312 312
 
313 313
 /**
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
  * @return array|bool|null
319 319
  */
320 320
 function quete_meta($nom, $serveur) {
321
-	return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur);
321
+    return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur);
322 322
 }
323 323
 
324 324
 /**
@@ -344,64 +344,64 @@  discard block
 block discarded – undo
344 344
  *     Retourne soit un tableau, soit le chemin du fichier.
345 345
  */
346 346
 function quete_logo($cle_objet, $onoff, $id, $id_rubrique, $flag) {
347
-	include_spip('base/objets');
348
-	$nom = strtolower($onoff);
349
-
350
-	while (1) {
351
-		$objet = objet_type($cle_objet);
352
-
353
-		$on = quete_logo_objet($id, $objet, $nom);
354
-
355
-		if ($on) {
356
-			if ($flag) {
357
-				return basename($on['chemin']);
358
-			} else {
359
-				$taille = @spip_getimagesize($on['chemin']);
360
-
361
-				// Si on a déjà demandé un survol directement ($onoff = off)
362
-				// ou qu'on a demandé uniquement le normal ($onoff = on)
363
-				// alors on ne cherche pas du tout le survol ici
364
-				if ($onoff != 'ON') {
365
-					$off = '';
366
-				} else {
367
-					// Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol
368
-					$off = quete_logo_objet($id, $objet, 'off');
369
-				}
370
-
371
-				// on retourne une url du type IMG/artonXX?timestamp
372
-				// qui permet de distinguer le changement de logo
373
-				// et placer un expire sur le dossier IMG/
374
-				$res = array(
375
-					$on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''),
376
-					($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''),
377
-					(!$taille ? '' : (' ' . $taille[3]))
378
-				);
379
-				$res['src'] = $res[0];
380
-				$res['logo_on'] = $res[0];
381
-				$res['logo_off'] = $res[1];
382
-				$res['width'] = ($taille ? $taille[0] : '');
383
-				$res['height'] = ($taille ? $taille[1] : '');
384
-
385
-				return $res;
386
-			}
387
-		} else {
388
-			if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) {
389
-				return '';
390
-			} else {
391
-				if ($id_rubrique) {
392
-					$cle_objet = 'id_rubrique';
393
-					$id = $id_rubrique;
394
-					$id_rubrique = 0;
395
-				} else {
396
-					if ($id and $cle_objet == 'id_rubrique') {
397
-						$id = quete_parent($id);
398
-					} else {
399
-						return '';
400
-					}
401
-				}
402
-			}
403
-		}
404
-	}
347
+    include_spip('base/objets');
348
+    $nom = strtolower($onoff);
349
+
350
+    while (1) {
351
+        $objet = objet_type($cle_objet);
352
+
353
+        $on = quete_logo_objet($id, $objet, $nom);
354
+
355
+        if ($on) {
356
+            if ($flag) {
357
+                return basename($on['chemin']);
358
+            } else {
359
+                $taille = @spip_getimagesize($on['chemin']);
360
+
361
+                // Si on a déjà demandé un survol directement ($onoff = off)
362
+                // ou qu'on a demandé uniquement le normal ($onoff = on)
363
+                // alors on ne cherche pas du tout le survol ici
364
+                if ($onoff != 'ON') {
365
+                    $off = '';
366
+                } else {
367
+                    // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol
368
+                    $off = quete_logo_objet($id, $objet, 'off');
369
+                }
370
+
371
+                // on retourne une url du type IMG/artonXX?timestamp
372
+                // qui permet de distinguer le changement de logo
373
+                // et placer un expire sur le dossier IMG/
374
+                $res = array(
375
+                    $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''),
376
+                    ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''),
377
+                    (!$taille ? '' : (' ' . $taille[3]))
378
+                );
379
+                $res['src'] = $res[0];
380
+                $res['logo_on'] = $res[0];
381
+                $res['logo_off'] = $res[1];
382
+                $res['width'] = ($taille ? $taille[0] : '');
383
+                $res['height'] = ($taille ? $taille[1] : '');
384
+
385
+                return $res;
386
+            }
387
+        } else {
388
+            if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) {
389
+                return '';
390
+            } else {
391
+                if ($id_rubrique) {
392
+                    $cle_objet = 'id_rubrique';
393
+                    $id = $id_rubrique;
394
+                    $id_rubrique = 0;
395
+                } else {
396
+                    if ($id and $cle_objet == 'id_rubrique') {
397
+                        $id = quete_parent($id);
398
+                    } else {
399
+                        return '';
400
+                    }
401
+                }
402
+            }
403
+        }
404
+    }
405 405
 }
406 406
 
407 407
 /**
@@ -415,37 +415,37 @@  discard block
 block discarded – undo
415 415
  * 		"on" ou "off" suivant le logo normal ou survol
416 416
  **/
417 417
 function quete_logo_objet($id_objet, $objet, $mode) {
418
-	static $chercher_logo;
419
-	if (is_null($chercher_logo)) {
420
-		$chercher_logo = charger_fonction('chercher_logo', 'inc');
421
-	}
422
-	$cle_objet = id_table_objet($objet);
423
-
424
-	// On cherche pas la méthode classique
425
-	$infos_logo = $chercher_logo($id_objet, $cle_objet, $mode);
426
-	// Si la méthode classique a trouvé quelque chose, on utilise le nouveau format
427
-	if (!empty($infos_logo)) {
428
-		$infos_logo = array(
429
-			'chemin' => $infos_logo[0],
430
-			'timestamp' => $infos_logo[4],
431
-		);
432
-	}
433
-
434
-	// On passe cette recherche de logo dans un pipeline
435
-	$infos_logo = pipeline(
436
-		'quete_logo_objet',
437
-		array(
438
-			'args' => array(
439
-				'id_objet' => $id_objet,
440
-				'objet' => $objet,
441
-				'cle_objet' => $cle_objet,
442
-				'mode' => $mode,
443
-			),
444
-			'data' => $infos_logo,
445
-		)
446
-	);
447
-
448
-	return $infos_logo;
418
+    static $chercher_logo;
419
+    if (is_null($chercher_logo)) {
420
+        $chercher_logo = charger_fonction('chercher_logo', 'inc');
421
+    }
422
+    $cle_objet = id_table_objet($objet);
423
+
424
+    // On cherche pas la méthode classique
425
+    $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode);
426
+    // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format
427
+    if (!empty($infos_logo)) {
428
+        $infos_logo = array(
429
+            'chemin' => $infos_logo[0],
430
+            'timestamp' => $infos_logo[4],
431
+        );
432
+    }
433
+
434
+    // On passe cette recherche de logo dans un pipeline
435
+    $infos_logo = pipeline(
436
+        'quete_logo_objet',
437
+        array(
438
+            'args' => array(
439
+                'id_objet' => $id_objet,
440
+                'objet' => $objet,
441
+                'cle_objet' => $cle_objet,
442
+                'mode' => $mode,
443
+            ),
444
+            'data' => $infos_logo,
445
+        )
446
+    );
447
+
448
+    return $infos_logo;
449 449
 }
450 450
 
451 451
 /**
@@ -458,24 +458,24 @@  discard block
 block discarded – undo
458 458
  * @return bool|string
459 459
  */
460 460
 function quete_logo_file($row, $connect = null) {
461
-	include_spip('inc/documents');
462
-	$logo = vignette_logo_document($row, $connect);
463
-	if (!$logo) {
464
-		$logo = image_du_document($row, $connect);
465
-	}
466
-	if (!$logo) {
467
-		$f = charger_fonction('vignette', 'inc');
468
-		$logo = $f($row['extension'], false);
469
-	}
470
-	// si c'est une vignette type doc, la renvoyer direct
471
-	if (strcmp($logo, _DIR_PLUGINS) == 0
472
-		or strcmp($logo, _DIR_PLUGINS_DIST) == 0
473
-		or strcmp($logo, _DIR_RACINE . 'prive/') == 0
474
-	) {
475
-		return $logo;
476
-	}
477
-
478
-	return get_spip_doc($logo);
461
+    include_spip('inc/documents');
462
+    $logo = vignette_logo_document($row, $connect);
463
+    if (!$logo) {
464
+        $logo = image_du_document($row, $connect);
465
+    }
466
+    if (!$logo) {
467
+        $f = charger_fonction('vignette', 'inc');
468
+        $logo = $f($row['extension'], false);
469
+    }
470
+    // si c'est une vignette type doc, la renvoyer direct
471
+    if (strcmp($logo, _DIR_PLUGINS) == 0
472
+        or strcmp($logo, _DIR_PLUGINS_DIST) == 0
473
+        or strcmp($logo, _DIR_RACINE . 'prive/') == 0
474
+    ) {
475
+        return $logo;
476
+    }
477
+
478
+    return get_spip_doc($logo);
479 479
 }
480 480
 
481 481
 /**
@@ -503,20 +503,20 @@  discard block
 block discarded – undo
503 503
  */
504 504
 function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, $connect = null) {
505 505
 
506
-	include_spip('inc/documents');
507
-	$logo = '';
508
-	if (!in_array($mode_logo, array('icone', 'apercu'))) {
509
-		$logo = vignette_logo_document($row, $connect);
510
-	}
511
-	// si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas
512
-	if ($mode_logo == 'vignette' and !$logo) {
513
-		return '';
514
-	}
515
-	if ($mode_logo == 'icone') {
516
-		$row['fichier'] = '';
517
-	}
518
-
519
-	return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect);
506
+    include_spip('inc/documents');
507
+    $logo = '';
508
+    if (!in_array($mode_logo, array('icone', 'apercu'))) {
509
+        $logo = vignette_logo_document($row, $connect);
510
+    }
511
+    // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas
512
+    if ($mode_logo == 'vignette' and !$logo) {
513
+        return '';
514
+    }
515
+    if ($mode_logo == 'icone') {
516
+        $row['fichier'] = '';
517
+    }
518
+
519
+    return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect);
520 520
 }
521 521
 
522 522
 /**
@@ -530,14 +530,14 @@  discard block
 block discarded – undo
530 530
  * @return string|false
531 531
  */
532 532
 function document_spip_externe($fichier, $connect) {
533
-	if ($connect) {
534
-		$site = quete_meta('adresse_site', $connect);
535
-		if ($site) {
536
-			$dir = quete_meta('dir_img', $connect);
537
-			return "$site/$dir$fichier";
538
-		}
539
-	}
540
-	return false;
533
+    if ($connect) {
534
+        $site = quete_meta('adresse_site', $connect);
535
+        if ($site) {
536
+            $dir = quete_meta('dir_img', $connect);
537
+            return "$site/$dir$fichier";
538
+        }
539
+    }
540
+    return false;
541 541
 }
542 542
 
543 543
 /**
@@ -550,23 +550,23 @@  discard block
 block discarded – undo
550 550
  * @return string
551 551
  */
552 552
 function vignette_logo_document($row, $connect = '') {
553
-	if (!$row['id_vignette']) {
554
-		return '';
555
-	}
556
-	$fichier = quete_fichier($row['id_vignette'], $connect);
557
-	if ($url = document_spip_externe($fichier, $connect)) {
558
-		return $url;
559
-	}
560
-
561
-	$f = get_spip_doc($fichier);
562
-	if ($f and @file_exists($f)) {
563
-		return $f;
564
-	}
565
-	if ($row['mode'] !== 'vignette') {
566
-		return '';
567
-	}
568
-
569
-	return generer_url_entite($row['id_document'], 'document', '', '', $connect);
553
+    if (!$row['id_vignette']) {
554
+        return '';
555
+    }
556
+    $fichier = quete_fichier($row['id_vignette'], $connect);
557
+    if ($url = document_spip_externe($fichier, $connect)) {
558
+        return $url;
559
+    }
560
+
561
+    $f = get_spip_doc($fichier);
562
+    if ($f and @file_exists($f)) {
563
+        return $f;
564
+    }
565
+    if ($row['mode'] !== 'vignette') {
566
+        return '';
567
+    }
568
+
569
+    return generer_url_entite($row['id_document'], 'document', '', '', $connect);
570 570
 }
571 571
 
572 572
 /**
@@ -582,68 +582,68 @@  discard block
 block discarded – undo
582 582
  * @return bool|string
583 583
  */
584 584
 function calcul_exposer($id, $prim, $reference, $parent, $type, $connect = '') {
585
-	static $exposer = array();
586
-
587
-	// Que faut-il exposer ? Tous les elements de $reference
588
-	// ainsi que leur hierarchie ; on ne fait donc ce calcul
589
-	// qu'une fois (par squelette) et on conserve le resultat
590
-	// en static.
591
-	if (!isset($exposer[$m = md5(serialize($reference))][$prim])) {
592
-		$principal = isset($reference[$type]) ? $reference[$type] :
593
-			// cas de la pagination indecte @xx qui positionne la page avec l'id xx
594
-			// et donne la reference dynamique @type=xx dans le contexte
595
-			(isset($reference["@$type"]) ? $reference["@$type"] : '');
596
-		// le parent fournit en argument est le parent de $id, pas celui de $principal
597
-		// il n'est donc pas utile
598
-		$parent = 0;
599
-		if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant
600
-			$enfants = array('id_rubrique' => array('id_article'), 'id_groupe' => array('id_mot'));
601
-			if (isset($enfants[$type])) {
602
-				foreach ($enfants[$type] as $t) {
603
-					if (isset($reference[$t])
604
-						// cas de la reference donnee dynamiquement par la pagination
605
-						or isset($reference["@$t"])
606
-					) {
607
-						$type = $t;
608
-						$principal = isset($reference[$type]) ? $reference[$type] : $reference["@$type"];
609
-						continue;
610
-					}
611
-				}
612
-			}
613
-		}
614
-		$exposer[$m][$type] = array();
615
-		if ($principal) {
616
-			$principaux = is_array($principal) ? $principal : array($principal);
617
-			foreach ($principaux as $principal) {
618
-				$exposer[$m][$type][$principal] = true;
619
-				if ($type == 'id_mot') {
620
-					if (!$parent) {
621
-						$parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect);
622
-					}
623
-					if ($parent) {
624
-						$exposer[$m]['id_groupe'][$parent] = true;
625
-					}
626
-				} else {
627
-					if ($type != 'id_groupe') {
628
-						if (!$parent) {
629
-							if ($type == 'id_rubrique') {
630
-								$parent = $principal;
631
-							}
632
-							if ($type == 'id_article') {
633
-								$parent = quete_rubrique($principal, $connect);
634
-							}
635
-						}
636
-						do {
637
-							$exposer[$m]['id_rubrique'][$parent] = true;
638
-						} while ($parent = quete_parent($parent, $connect));
639
-					}
640
-				}
641
-			}
642
-		}
643
-	}
644
-
645
-	// And the winner is...
646
-	return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : '';
585
+    static $exposer = array();
586
+
587
+    // Que faut-il exposer ? Tous les elements de $reference
588
+    // ainsi que leur hierarchie ; on ne fait donc ce calcul
589
+    // qu'une fois (par squelette) et on conserve le resultat
590
+    // en static.
591
+    if (!isset($exposer[$m = md5(serialize($reference))][$prim])) {
592
+        $principal = isset($reference[$type]) ? $reference[$type] :
593
+            // cas de la pagination indecte @xx qui positionne la page avec l'id xx
594
+            // et donne la reference dynamique @type=xx dans le contexte
595
+            (isset($reference["@$type"]) ? $reference["@$type"] : '');
596
+        // le parent fournit en argument est le parent de $id, pas celui de $principal
597
+        // il n'est donc pas utile
598
+        $parent = 0;
599
+        if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant
600
+            $enfants = array('id_rubrique' => array('id_article'), 'id_groupe' => array('id_mot'));
601
+            if (isset($enfants[$type])) {
602
+                foreach ($enfants[$type] as $t) {
603
+                    if (isset($reference[$t])
604
+                        // cas de la reference donnee dynamiquement par la pagination
605
+                        or isset($reference["@$t"])
606
+                    ) {
607
+                        $type = $t;
608
+                        $principal = isset($reference[$type]) ? $reference[$type] : $reference["@$type"];
609
+                        continue;
610
+                    }
611
+                }
612
+            }
613
+        }
614
+        $exposer[$m][$type] = array();
615
+        if ($principal) {
616
+            $principaux = is_array($principal) ? $principal : array($principal);
617
+            foreach ($principaux as $principal) {
618
+                $exposer[$m][$type][$principal] = true;
619
+                if ($type == 'id_mot') {
620
+                    if (!$parent) {
621
+                        $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect);
622
+                    }
623
+                    if ($parent) {
624
+                        $exposer[$m]['id_groupe'][$parent] = true;
625
+                    }
626
+                } else {
627
+                    if ($type != 'id_groupe') {
628
+                        if (!$parent) {
629
+                            if ($type == 'id_rubrique') {
630
+                                $parent = $principal;
631
+                            }
632
+                            if ($type == 'id_article') {
633
+                                $parent = quete_rubrique($principal, $connect);
634
+                            }
635
+                        }
636
+                        do {
637
+                            $exposer[$m]['id_rubrique'][$parent] = true;
638
+                        } while ($parent = quete_parent($parent, $connect));
639
+                    }
640
+                }
641
+            }
642
+        }
643
+    }
644
+
645
+    // And the winner is...
646
+    return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : '';
647 647
 }
648 648
 
649 649
 /**
@@ -658,21 +658,21 @@  discard block
 block discarded – undo
658 658
  * @return int
659 659
  */
660 660
 function quete_debut_pagination($primary, $valeur, $pas, $iter) {
661
-	// on ne devrait pas arriver ici si la cle primaire est inexistante
662
-	// ou composee, mais verifions
663
-	if (!$primary or preg_match('/[,\s]/', $primary)) {
664
-		return 0;
665
-	}
666
-
667
-	$pos = 0;
668
-	while ($row = $iter->fetch() and $row[$primary] != $valeur) {
669
-		$pos++;
670
-	}
671
-	// si on a pas trouve
672
-	if ($row[$primary] != $valeur) {
673
-		return 0;
674
-	}
675
-
676
-	// sinon, calculer le bon numero de page
677
-	return floor($pos / $pas) * $pas;
661
+    // on ne devrait pas arriver ici si la cle primaire est inexistante
662
+    // ou composee, mais verifions
663
+    if (!$primary or preg_match('/[,\s]/', $primary)) {
664
+        return 0;
665
+    }
666
+
667
+    $pos = 0;
668
+    while ($row = $iter->fetch() and $row[$primary] != $valeur) {
669
+        $pos++;
670
+    }
671
+    // si on a pas trouve
672
+    if ($row[$primary] != $valeur) {
673
+        return 0;
674
+    }
675
+
676
+    // sinon, calculer le bon numero de page
677
+    return floor($pos / $pas) * $pas;
678 678
 }
Please login to merge, or discard this patch.
ecrire/action/editer_logo.php 2 patches
Indentation   +162 added lines, -162 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
 
@@ -30,16 +30,16 @@  discard block
 block discarded – undo
30 30
  *     `on` ou `off`
31 31
  */
32 32
 function logo_supprimer($objet, $id_objet, $etat) {
33
-	$chercher_logo = charger_fonction('chercher_logo', 'inc');
34
-	$objet = objet_type($objet);
35
-	$primary = id_table_objet($objet);
36
-	include_spip('inc/chercher_logo');
37
-
38
-	// existe-t-il deja un logo ?
39
-	$logo = $chercher_logo($id_objet, $primary, $etat);
40
-	if ($logo) {
41
-		spip_unlink($logo[0]);
42
-	}
33
+    $chercher_logo = charger_fonction('chercher_logo', 'inc');
34
+    $objet = objet_type($objet);
35
+    $primary = id_table_objet($objet);
36
+    include_spip('inc/chercher_logo');
37
+
38
+    // existe-t-il deja un logo ?
39
+    $logo = $chercher_logo($id_objet, $primary, $etat);
40
+    if ($logo) {
41
+        spip_unlink($logo[0]);
42
+    }
43 43
 }
44 44
 
45 45
 /**
@@ -56,134 +56,134 @@  discard block
 block discarded – undo
56 56
  *     Erreur, sinon ''
57 57
  */
58 58
 function logo_modifier($objet, $id_objet, $etat, $source) {
59
-	$chercher_logo = charger_fonction('chercher_logo', 'inc');
60
-	$objet = objet_type($objet);
61
-	$primary = id_table_objet($objet);
62
-	include_spip('inc/chercher_logo');
63
-	$type = type_du_logo($primary);
64
-
65
-	// nom du logo
66
-	$nom = $type . $etat . $id_objet;
67
-
68
-	// supprimer le logo eventueel existant
69
-	logo_supprimer($objet, $id_objet, $etat);
70
-
71
-	include_spip('inc/documents');
72
-	$erreur = '';
73
-
74
-	if (!$source) {
75
-		spip_log('spip_image_ajouter : source inconnue');
76
-		$erreur = 'source inconnue';
77
-
78
-		return $erreur;
79
-	}
80
-
81
-	$file_tmp = _DIR_LOGOS . $nom . '.tmp';
82
-
83
-	$ok = false;
84
-	// fichier dans upload/
85
-	if (is_string($source)) {
86
-		if (file_exists($source)) {
87
-			$ok = @copy($source, $file_tmp);
88
-		} elseif (file_exists($f = determine_upload() . $source)) {
89
-			$ok = @copy($f, $file_tmp);
90
-		}
91
-	} elseif (!$erreur = check_upload_error($source['error'], '', true)) {
92
-		// Intercepter une erreur a l'envoi
93
-		// analyse le type de l'image (on ne fait pas confiance au nom de
94
-		// fichier envoye par le browser : pour les Macs c'est plus sur)
95
-		$ok = deplacer_fichier_upload($source['tmp_name'], $file_tmp);
96
-	}
97
-
98
-	if ($erreur) {
99
-		return $erreur;
100
-	}
101
-	if (!$ok or !file_exists($file_tmp)) {
102
-		spip_log($erreur = "probleme de copie pour $file_tmp ");
103
-
104
-		return $erreur;
105
-	}
106
-
107
-	if ($size = @spip_getimagesize($file_tmp)
108
-	  and $extension = logo_decoder_type_image($size[2])
109
-		and in_array($extension, $GLOBALS['formats_logos'])) {
110
-		@rename($file_tmp, $file_tmp . ".$extension");
111
-		$file_tmp = $file_tmp . ".$extension";
112
-		$poids = filesize($file_tmp);
113
-
114
-		if (defined('_LOGO_MAX_WIDTH') or defined('_LOGO_MAX_HEIGHT')) {
115
-			if ((defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH and $size[0] > _LOGO_MAX_WIDTH)
116
-				or (defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT and $size[1] > _LOGO_MAX_HEIGHT)
117
-			) {
118
-				$max_width = (defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH) ? _LOGO_MAX_WIDTH : '*';
119
-				$max_height = (defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT) ? _LOGO_MAX_HEIGHT : '*';
120
-
121
-				// pas la peine d'embeter le redacteur avec ca si on a active le calcul des miniatures
122
-				// on met directement a la taille maxi a la volee
123
-				if (isset($GLOBALS['meta']['creer_preview']) and $GLOBALS['meta']['creer_preview'] == 'oui') {
124
-					include_spip('inc/filtres');
125
-					$img = filtrer('image_reduire', $file_tmp, $max_width, $max_height);
126
-					$img = extraire_attribut($img, 'src');
127
-					$img = supprimer_timestamp($img);
128
-					if (@file_exists($img) and $img !== $file_tmp) {
129
-						spip_unlink($file_tmp);
130
-						@rename($img, $file_tmp);
131
-						$size = @spip_getimagesize($file_tmp);
132
-					}
133
-				}
134
-				// verifier au cas ou image_reduire a echoue
135
-				if ((defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH and $size[0] > _LOGO_MAX_WIDTH)
136
-					or (defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT and $size[1] > _LOGO_MAX_HEIGHT)
137
-				) {
138
-					spip_unlink($file_tmp);
139
-					$erreur = _T(
140
-						'info_logo_max_poids',
141
-						array(
142
-							'maxi' =>
143
-								_T(
144
-									'info_largeur_vignette',
145
-									array(
146
-										'largeur_vignette' => $max_width,
147
-										'hauteur_vignette' => $max_height
148
-									)
149
-								),
150
-							'actuel' =>
151
-								_T(
152
-									'info_largeur_vignette',
153
-									array(
154
-										'largeur_vignette' => $size[0],
155
-										'hauteur_vignette' => $size[1]
156
-									)
157
-								)
158
-						)
159
-					);
160
-				}
161
-			}
162
-		}
163
-
164
-		if (!$erreur and defined('_LOGO_MAX_SIZE') and _LOGO_MAX_SIZE and $poids > _LOGO_MAX_SIZE * 1024) {
165
-			spip_unlink($file_tmp);
166
-			$erreur = _T(
167
-				'info_logo_max_poids',
168
-				array(
169
-					'maxi' => taille_en_octets(_LOGO_MAX_SIZE * 1024),
170
-					'actuel' => taille_en_octets($poids)
171
-				)
172
-			);
173
-		}
174
-
175
-		if (!$erreur) {
176
-			@rename($file_tmp, _DIR_LOGOS . $nom . ".$extension");
177
-		}
178
-	} else {
179
-		spip_unlink($file_tmp);
180
-		$erreur = _T(
181
-			'info_logo_format_interdit',
182
-			array('formats' => join(', ', $GLOBALS['formats_logos']))
183
-		);
184
-	}
185
-
186
-	return $erreur;
59
+    $chercher_logo = charger_fonction('chercher_logo', 'inc');
60
+    $objet = objet_type($objet);
61
+    $primary = id_table_objet($objet);
62
+    include_spip('inc/chercher_logo');
63
+    $type = type_du_logo($primary);
64
+
65
+    // nom du logo
66
+    $nom = $type . $etat . $id_objet;
67
+
68
+    // supprimer le logo eventueel existant
69
+    logo_supprimer($objet, $id_objet, $etat);
70
+
71
+    include_spip('inc/documents');
72
+    $erreur = '';
73
+
74
+    if (!$source) {
75
+        spip_log('spip_image_ajouter : source inconnue');
76
+        $erreur = 'source inconnue';
77
+
78
+        return $erreur;
79
+    }
80
+
81
+    $file_tmp = _DIR_LOGOS . $nom . '.tmp';
82
+
83
+    $ok = false;
84
+    // fichier dans upload/
85
+    if (is_string($source)) {
86
+        if (file_exists($source)) {
87
+            $ok = @copy($source, $file_tmp);
88
+        } elseif (file_exists($f = determine_upload() . $source)) {
89
+            $ok = @copy($f, $file_tmp);
90
+        }
91
+    } elseif (!$erreur = check_upload_error($source['error'], '', true)) {
92
+        // Intercepter une erreur a l'envoi
93
+        // analyse le type de l'image (on ne fait pas confiance au nom de
94
+        // fichier envoye par le browser : pour les Macs c'est plus sur)
95
+        $ok = deplacer_fichier_upload($source['tmp_name'], $file_tmp);
96
+    }
97
+
98
+    if ($erreur) {
99
+        return $erreur;
100
+    }
101
+    if (!$ok or !file_exists($file_tmp)) {
102
+        spip_log($erreur = "probleme de copie pour $file_tmp ");
103
+
104
+        return $erreur;
105
+    }
106
+
107
+    if ($size = @spip_getimagesize($file_tmp)
108
+      and $extension = logo_decoder_type_image($size[2])
109
+        and in_array($extension, $GLOBALS['formats_logos'])) {
110
+        @rename($file_tmp, $file_tmp . ".$extension");
111
+        $file_tmp = $file_tmp . ".$extension";
112
+        $poids = filesize($file_tmp);
113
+
114
+        if (defined('_LOGO_MAX_WIDTH') or defined('_LOGO_MAX_HEIGHT')) {
115
+            if ((defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH and $size[0] > _LOGO_MAX_WIDTH)
116
+                or (defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT and $size[1] > _LOGO_MAX_HEIGHT)
117
+            ) {
118
+                $max_width = (defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH) ? _LOGO_MAX_WIDTH : '*';
119
+                $max_height = (defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT) ? _LOGO_MAX_HEIGHT : '*';
120
+
121
+                // pas la peine d'embeter le redacteur avec ca si on a active le calcul des miniatures
122
+                // on met directement a la taille maxi a la volee
123
+                if (isset($GLOBALS['meta']['creer_preview']) and $GLOBALS['meta']['creer_preview'] == 'oui') {
124
+                    include_spip('inc/filtres');
125
+                    $img = filtrer('image_reduire', $file_tmp, $max_width, $max_height);
126
+                    $img = extraire_attribut($img, 'src');
127
+                    $img = supprimer_timestamp($img);
128
+                    if (@file_exists($img) and $img !== $file_tmp) {
129
+                        spip_unlink($file_tmp);
130
+                        @rename($img, $file_tmp);
131
+                        $size = @spip_getimagesize($file_tmp);
132
+                    }
133
+                }
134
+                // verifier au cas ou image_reduire a echoue
135
+                if ((defined('_LOGO_MAX_WIDTH') and _LOGO_MAX_WIDTH and $size[0] > _LOGO_MAX_WIDTH)
136
+                    or (defined('_LOGO_MAX_HEIGHT') and _LOGO_MAX_HEIGHT and $size[1] > _LOGO_MAX_HEIGHT)
137
+                ) {
138
+                    spip_unlink($file_tmp);
139
+                    $erreur = _T(
140
+                        'info_logo_max_poids',
141
+                        array(
142
+                            'maxi' =>
143
+                                _T(
144
+                                    'info_largeur_vignette',
145
+                                    array(
146
+                                        'largeur_vignette' => $max_width,
147
+                                        'hauteur_vignette' => $max_height
148
+                                    )
149
+                                ),
150
+                            'actuel' =>
151
+                                _T(
152
+                                    'info_largeur_vignette',
153
+                                    array(
154
+                                        'largeur_vignette' => $size[0],
155
+                                        'hauteur_vignette' => $size[1]
156
+                                    )
157
+                                )
158
+                        )
159
+                    );
160
+                }
161
+            }
162
+        }
163
+
164
+        if (!$erreur and defined('_LOGO_MAX_SIZE') and _LOGO_MAX_SIZE and $poids > _LOGO_MAX_SIZE * 1024) {
165
+            spip_unlink($file_tmp);
166
+            $erreur = _T(
167
+                'info_logo_max_poids',
168
+                array(
169
+                    'maxi' => taille_en_octets(_LOGO_MAX_SIZE * 1024),
170
+                    'actuel' => taille_en_octets($poids)
171
+                )
172
+            );
173
+        }
174
+
175
+        if (!$erreur) {
176
+            @rename($file_tmp, _DIR_LOGOS . $nom . ".$extension");
177
+        }
178
+    } else {
179
+        spip_unlink($file_tmp);
180
+        $erreur = _T(
181
+            'info_logo_format_interdit',
182
+            array('formats' => join(', ', $GLOBALS['formats_logos']))
183
+        );
184
+    }
185
+
186
+    return $erreur;
187 187
 }
188 188
 
189 189
 
@@ -198,27 +198,27 @@  discard block
 block discarded – undo
198 198
  */
199 199
 // https://code.spip.net/@decoder_type_image
200 200
 function logo_decoder_type_image($type, $strict = false) {
201
-	switch ($type) {
202
-		case IMAGETYPE_GIF:
203
-			return 'gif';
204
-		case IMAGETYPE_JPEG:
205
-			return 'jpg';
206
-		case IMAGETYPE_PNG:
207
-			return 'png';
208
-		case IMAGETYPE_SWF:
209
-			return $strict ? '' : 'swf';
210
-		case IMAGETYPE_PSD:
211
-			return 'psd';
212
-		case IMAGETYPE_BMP:
213
-			return 'bmp';
214
-		case IMAGETYPE_TIFF_II:
215
-		case IMAGETYPE_TIFF_MM:
216
-			return 'tif';
217
-		case IMAGETYPE_WEBP:
218
-			return 'webp';
219
-		case IMAGETYPE_SVG:
220
-			return $strict ? '' : 'svg';
221
-		default:
222
-			return '';
223
-	}
201
+    switch ($type) {
202
+        case IMAGETYPE_GIF:
203
+            return 'gif';
204
+        case IMAGETYPE_JPEG:
205
+            return 'jpg';
206
+        case IMAGETYPE_PNG:
207
+            return 'png';
208
+        case IMAGETYPE_SWF:
209
+            return $strict ? '' : 'swf';
210
+        case IMAGETYPE_PSD:
211
+            return 'psd';
212
+        case IMAGETYPE_BMP:
213
+            return 'bmp';
214
+        case IMAGETYPE_TIFF_II:
215
+        case IMAGETYPE_TIFF_MM:
216
+            return 'tif';
217
+        case IMAGETYPE_WEBP:
218
+            return 'webp';
219
+        case IMAGETYPE_SVG:
220
+            return $strict ? '' : 'svg';
221
+        default:
222
+            return '';
223
+    }
224 224
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	$type = type_du_logo($primary);
64 64
 
65 65
 	// nom du logo
66
-	$nom = $type . $etat . $id_objet;
66
+	$nom = $type.$etat.$id_objet;
67 67
 
68 68
 	// supprimer le logo eventueel existant
69 69
 	logo_supprimer($objet, $id_objet, $etat);
@@ -78,14 +78,14 @@  discard block
 block discarded – undo
78 78
 		return $erreur;
79 79
 	}
80 80
 
81
-	$file_tmp = _DIR_LOGOS . $nom . '.tmp';
81
+	$file_tmp = _DIR_LOGOS.$nom.'.tmp';
82 82
 
83 83
 	$ok = false;
84 84
 	// fichier dans upload/
85 85
 	if (is_string($source)) {
86 86
 		if (file_exists($source)) {
87 87
 			$ok = @copy($source, $file_tmp);
88
-		} elseif (file_exists($f = determine_upload() . $source)) {
88
+		} elseif (file_exists($f = determine_upload().$source)) {
89 89
 			$ok = @copy($f, $file_tmp);
90 90
 		}
91 91
 	} elseif (!$erreur = check_upload_error($source['error'], '', true)) {
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 	if ($size = @spip_getimagesize($file_tmp)
108 108
 	  and $extension = logo_decoder_type_image($size[2])
109 109
 		and in_array($extension, $GLOBALS['formats_logos'])) {
110
-		@rename($file_tmp, $file_tmp . ".$extension");
111
-		$file_tmp = $file_tmp . ".$extension";
110
+		@rename($file_tmp, $file_tmp.".$extension");
111
+		$file_tmp = $file_tmp.".$extension";
112 112
 		$poids = filesize($file_tmp);
113 113
 
114 114
 		if (defined('_LOGO_MAX_WIDTH') or defined('_LOGO_MAX_HEIGHT')) {
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 		}
174 174
 
175 175
 		if (!$erreur) {
176
-			@rename($file_tmp, _DIR_LOGOS . $nom . ".$extension");
176
+			@rename($file_tmp, _DIR_LOGOS.$nom.".$extension");
177 177
 		}
178 178
 	} else {
179 179
 		spip_unlink($file_tmp);
Please login to merge, or discard this patch.
prive/formulaires/editer_logo.php 2 patches
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
  **/
31 31
 
32 32
 if (!defined('_ECRIRE_INC_VERSION')) {
33
-	return;
33
+    return;
34 34
 }
35 35
 
36 36
 global $logo_libelles;
@@ -49,89 +49,89 @@  discard block
 block discarded – undo
49 49
  * @return array               Variables d'environnement pour le fond
50 50
  */
51 51
 function formulaires_editer_logo_charger_dist($objet, $id_objet, $retour = '', $options = array()) {
52
-	// pas dans une boucle ? formulaire pour le logo du site
53
-	// dans ce cas, il faut chercher un 'siteon0.ext'
54
-	if (!$objet) {
55
-		$objet = 'site';
56
-	}
52
+    // pas dans une boucle ? formulaire pour le logo du site
53
+    // dans ce cas, il faut chercher un 'siteon0.ext'
54
+    if (!$objet) {
55
+        $objet = 'site';
56
+    }
57 57
 
58
-	$objet = objet_type($objet);
59
-	$_id_objet = id_table_objet($objet);
58
+    $objet = objet_type($objet);
59
+    $_id_objet = id_table_objet($objet);
60 60
 
61
-	if (!is_array($options)) {
62
-		$options = unserialize($options);
63
-	}
61
+    if (!is_array($options)) {
62
+        $options = unserialize($options);
63
+    }
64 64
 
65
-	if (!isset($options['titre'])) {
66
-		$balise_img = chercher_filtre('balise_img');
67
-		$img = $balise_img(chemin_image('image-24.png'),'', 'cadre-icone');
68
-		$libelles = pipeline('libeller_logo', $GLOBALS['logo_libelles']);
69
-		$libelle = (($id_objet or $objet != 'rubrique') ? $objet : 'racine');
70
-		if (isset($libelles[$libelle])) {
71
-			$libelle = $libelles[$libelle];
72
-		} elseif ($libelle = objet_info($objet, 'texte_logo_objet')) {
73
-			$libelle = _T($libelle);
74
-		} else {
75
-			$libelle = _L('Logo');
76
-		}
77
-		switch ($objet) {
78
-			case 'article':
79
-				$libelle .= ' ' . aider('logoart');
80
-				break;
81
-			case 'breve':
82
-				$libelle .= ' ' . aider('breveslogo');
83
-				break;
84
-			case 'rubrique':
85
-				$libelle .= ' ' . aider('rublogo');
86
-				break;
87
-			default:
88
-				break;
89
-		}
65
+    if (!isset($options['titre'])) {
66
+        $balise_img = chercher_filtre('balise_img');
67
+        $img = $balise_img(chemin_image('image-24.png'),'', 'cadre-icone');
68
+        $libelles = pipeline('libeller_logo', $GLOBALS['logo_libelles']);
69
+        $libelle = (($id_objet or $objet != 'rubrique') ? $objet : 'racine');
70
+        if (isset($libelles[$libelle])) {
71
+            $libelle = $libelles[$libelle];
72
+        } elseif ($libelle = objet_info($objet, 'texte_logo_objet')) {
73
+            $libelle = _T($libelle);
74
+        } else {
75
+            $libelle = _L('Logo');
76
+        }
77
+        switch ($objet) {
78
+            case 'article':
79
+                $libelle .= ' ' . aider('logoart');
80
+                break;
81
+            case 'breve':
82
+                $libelle .= ' ' . aider('breveslogo');
83
+                break;
84
+            case 'rubrique':
85
+                $libelle .= ' ' . aider('rublogo');
86
+                break;
87
+            default:
88
+                break;
89
+        }
90 90
 
91
-		$options['titre'] = $img . $libelle;
92
-	}
93
-	if (!isset($options['editable'])) {
94
-		include_spip('inc/autoriser');
95
-		$options['editable'] = autoriser('iconifier', $objet, $id_objet);
96
-	}
91
+        $options['titre'] = $img . $libelle;
92
+    }
93
+    if (!isset($options['editable'])) {
94
+        include_spip('inc/autoriser');
95
+        $options['editable'] = autoriser('iconifier', $objet, $id_objet);
96
+    }
97 97
 
98
-	$res = array(
99
-		'editable' => ($GLOBALS['meta']['activer_logos'] == 'oui' ? ' ' : '') && (!isset($options['editable']) or $options['editable']),
100
-		'logo_survol' => ($GLOBALS['meta']['activer_logos_survol'] == 'oui' ? ' ' : ''),
101
-		'objet' => $objet,
102
-		'id_objet' => $id_objet,
103
-		'_options' => $options,
104
-		'_show_upload_off' => '',
105
-	);
98
+    $res = array(
99
+        'editable' => ($GLOBALS['meta']['activer_logos'] == 'oui' ? ' ' : '') && (!isset($options['editable']) or $options['editable']),
100
+        'logo_survol' => ($GLOBALS['meta']['activer_logos_survol'] == 'oui' ? ' ' : ''),
101
+        'objet' => $objet,
102
+        'id_objet' => $id_objet,
103
+        '_options' => $options,
104
+        '_show_upload_off' => '',
105
+    );
106 106
 
107
-	// rechercher le logo de l'objet
108
-	// la fonction prend un parametre '_id_objet' etrange :
109
-	// le nom de la cle primaire (et non le nom de la table)
110
-	// ou directement le nom du raccourcis a chercher
111
-	$chercher_logo = charger_fonction('chercher_logo', 'inc');
112
-	$etats = $res['logo_survol'] ? array('on', 'off') : array('on');
113
-	foreach ($etats as $etat) {
114
-		$logo = $chercher_logo($id_objet, $_id_objet, $etat);
115
-		if ($logo) {
116
-			$res['logo_' . $etat] = $logo[0];
117
-		}
118
-	}
119
-	// pas de logo_on -> pas de formulaire pour le survol
120
-	if (!isset($res['logo_on'])) {
121
-		$res['logo_survol'] = '';
122
-	} elseif (!isset($res['logo_off']) and _request('logo_up')) {
123
-		$res['_show_upload_off'] = ' ';
124
-	}
107
+    // rechercher le logo de l'objet
108
+    // la fonction prend un parametre '_id_objet' etrange :
109
+    // le nom de la cle primaire (et non le nom de la table)
110
+    // ou directement le nom du raccourcis a chercher
111
+    $chercher_logo = charger_fonction('chercher_logo', 'inc');
112
+    $etats = $res['logo_survol'] ? array('on', 'off') : array('on');
113
+    foreach ($etats as $etat) {
114
+        $logo = $chercher_logo($id_objet, $_id_objet, $etat);
115
+        if ($logo) {
116
+            $res['logo_' . $etat] = $logo[0];
117
+        }
118
+    }
119
+    // pas de logo_on -> pas de formulaire pour le survol
120
+    if (!isset($res['logo_on'])) {
121
+        $res['logo_survol'] = '';
122
+    } elseif (!isset($res['logo_off']) and _request('logo_up')) {
123
+        $res['_show_upload_off'] = ' ';
124
+    }
125 125
 
126
-	// si le logo n'est pas editable et qu'il n'y en a pas, on affiche pas du tout le formulaire
127
-	if (!$res['editable']
128
-		and !isset($res['logo_off'])
129
-		and !isset($res['logo_on'])
130
-	) {
131
-		return false;
132
-	}
126
+    // si le logo n'est pas editable et qu'il n'y en a pas, on affiche pas du tout le formulaire
127
+    if (!$res['editable']
128
+        and !isset($res['logo_off'])
129
+        and !isset($res['logo_on'])
130
+    ) {
131
+        return false;
132
+    }
133 133
 
134
-	return $res;
134
+    return $res;
135 135
 }
136 136
 
137 137
 /**
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
  * @return string              Hash du formulaire
146 146
  */
147 147
 function formulaires_editer_logo_identifier_dist($objet, $id_objet, $retour = '', $options = array()) {
148
-	return serialize(array($objet, $id_objet));
148
+    return serialize(array($objet, $id_objet));
149 149
 }
150 150
 
151 151
 /**
@@ -161,29 +161,29 @@  discard block
 block discarded – undo
161 161
  * @return array               Erreurs du formulaire
162 162
  */
163 163
 function formulaires_editer_logo_verifier_dist($objet, $id_objet, $retour = '', $options = array()) {
164
-	$erreurs = array();
165
-	// verifier les extensions
166
-	$sources = formulaire_editer_logo_get_sources();
167
-	include_spip('action/editer_logo');
168
-	$extensions_possibles = $GLOBALS['formats_logos'];
169
-	if (in_array('jpg', $extensions_possibles)) {
170
-		$extensions_possibles[] = 'jpeg';
171
-	}
172
-	foreach ($sources as $etat => $file) {
173
-		// seulement si une reception correcte a eu lieu
174
-		if ($file and $file['error'] == 0) {
175
-			if (!in_array(
176
-				strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)),
177
-				$extensions_possibles
178
-			)) {
179
-				$erreurs['logo_' . $etat] = _L('Extension non reconnue');
180
-			}
181
-		} elseif ($file and $file['error'] != 0 and isset($file['msg'])) {
182
-			$erreurs['message_erreur'] = $file['msg'];
183
-		}
184
-	}
164
+    $erreurs = array();
165
+    // verifier les extensions
166
+    $sources = formulaire_editer_logo_get_sources();
167
+    include_spip('action/editer_logo');
168
+    $extensions_possibles = $GLOBALS['formats_logos'];
169
+    if (in_array('jpg', $extensions_possibles)) {
170
+        $extensions_possibles[] = 'jpeg';
171
+    }
172
+    foreach ($sources as $etat => $file) {
173
+        // seulement si une reception correcte a eu lieu
174
+        if ($file and $file['error'] == 0) {
175
+            if (!in_array(
176
+                strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)),
177
+                $extensions_possibles
178
+            )) {
179
+                $erreurs['logo_' . $etat] = _L('Extension non reconnue');
180
+            }
181
+        } elseif ($file and $file['error'] != 0 and isset($file['msg'])) {
182
+            $erreurs['message_erreur'] = $file['msg'];
183
+        }
184
+    }
185 185
 
186
-	return $erreurs;
186
+    return $erreurs;
187 187
 }
188 188
 
189 189
 /**
@@ -199,47 +199,47 @@  discard block
 block discarded – undo
199 199
  * @return array               Retour des traitements
200 200
  */
201 201
 function formulaires_editer_logo_traiter_dist($objet, $id_objet, $retour = '', $options = array()) {
202
-	$res = array('editable' => ' ');
202
+    $res = array('editable' => ' ');
203 203
 
204
-	// pas dans une boucle ? formulaire pour le logo du site
205
-	// dans ce cas, il faut chercher un 'siteon0.ext'
206
-	if (!$objet) {
207
-		$objet = 'site';
208
-	}
204
+    // pas dans une boucle ? formulaire pour le logo du site
205
+    // dans ce cas, il faut chercher un 'siteon0.ext'
206
+    if (!$objet) {
207
+        $objet = 'site';
208
+    }
209 209
 
210
-	include_spip('action/editer_logo');
210
+    include_spip('action/editer_logo');
211 211
 
212
-	// effectuer la suppression si demandee d'un logo
213
-	$on = _request('supprimer_logo_on');
214
-	if ($on or _request('supprimer_logo_off')) {
215
-		logo_supprimer($objet, $id_objet, $on ? 'on' : 'off');
216
-		$res['message_ok'] = ''; // pas besoin de message : la validation est visuelle
217
-		set_request('logo_up', ' ');
218
-	} // sinon supprimer ancien logo puis copier le nouveau
219
-	else {
220
-		$sources = formulaire_editer_logo_get_sources();
221
-		foreach ($sources as $etat => $file) {
222
-			if ($file and $file['error'] == 0) {
223
-				if ($err = logo_modifier($objet, $id_objet, $etat, $file)) {
224
-					$res['message_erreur'] = $err;
225
-				} else {
226
-					$res['message_ok'] = '';
227
-				} // pas besoin de message : la validation est visuelle
228
-				set_request('logo_up', ' ');
229
-			}
230
-		}
231
-	}
212
+    // effectuer la suppression si demandee d'un logo
213
+    $on = _request('supprimer_logo_on');
214
+    if ($on or _request('supprimer_logo_off')) {
215
+        logo_supprimer($objet, $id_objet, $on ? 'on' : 'off');
216
+        $res['message_ok'] = ''; // pas besoin de message : la validation est visuelle
217
+        set_request('logo_up', ' ');
218
+    } // sinon supprimer ancien logo puis copier le nouveau
219
+    else {
220
+        $sources = formulaire_editer_logo_get_sources();
221
+        foreach ($sources as $etat => $file) {
222
+            if ($file and $file['error'] == 0) {
223
+                if ($err = logo_modifier($objet, $id_objet, $etat, $file)) {
224
+                    $res['message_erreur'] = $err;
225
+                } else {
226
+                    $res['message_ok'] = '';
227
+                } // pas besoin de message : la validation est visuelle
228
+                set_request('logo_up', ' ');
229
+            }
230
+        }
231
+    }
232 232
 
233
-	// Invalider les caches de l'objet
234
-	include_spip('inc/invalideur');
235
-	suivre_invalideur("id='$objet/$id_objet'");
233
+    // Invalider les caches de l'objet
234
+    include_spip('inc/invalideur');
235
+    suivre_invalideur("id='$objet/$id_objet'");
236 236
 
237 237
 
238
-	if ($retour) {
239
-		$res['redirect'] = $retour;
240
-	}
238
+    if ($retour) {
239
+        $res['redirect'] = $retour;
240
+    }
241 241
 
242
-	return $res;
242
+    return $res;
243 243
 }
244 244
 
245 245
 
@@ -251,29 +251,29 @@  discard block
 block discarded – undo
251 251
  *     Sources des fichiers dans les clés `on` ou `off`
252 252
  */
253 253
 function formulaire_editer_logo_get_sources() {
254
-	if (!$_FILES) {
255
-		$_FILES = isset($GLOBALS['HTTP_POST_FILES']) ? $GLOBALS['HTTP_POST_FILES'] : array();
256
-	}
257
-	if (!is_array($_FILES)) {
258
-		return array();
259
-	}
254
+    if (!$_FILES) {
255
+        $_FILES = isset($GLOBALS['HTTP_POST_FILES']) ? $GLOBALS['HTTP_POST_FILES'] : array();
256
+    }
257
+    if (!is_array($_FILES)) {
258
+        return array();
259
+    }
260 260
 
261
-	include_spip('inc/documents');
262
-	$sources = array();
263
-	foreach (array('on', 'off') as $etat) {
264
-		$logo = 'logo_' . $etat;
265
-		if (isset($_FILES[$logo])) {
266
-			if ($_FILES[$logo]['error'] == 0) {
267
-				$sources[$etat] = $_FILES[$logo];
268
-			} elseif ($_FILES[$logo]['error'] != 0) {
269
-				$msg = check_upload_error($_FILES[$logo]['error'], false, true);
270
-				if ($msg and is_string($msg)) {
271
-					$sources[$etat] = $_FILES[$logo];
272
-					$sources[$etat]['msg'] = $msg;
273
-				}
274
-			}
275
-		}
276
-	}
261
+    include_spip('inc/documents');
262
+    $sources = array();
263
+    foreach (array('on', 'off') as $etat) {
264
+        $logo = 'logo_' . $etat;
265
+        if (isset($_FILES[$logo])) {
266
+            if ($_FILES[$logo]['error'] == 0) {
267
+                $sources[$etat] = $_FILES[$logo];
268
+            } elseif ($_FILES[$logo]['error'] != 0) {
269
+                $msg = check_upload_error($_FILES[$logo]['error'], false, true);
270
+                if ($msg and is_string($msg)) {
271
+                    $sources[$etat] = $_FILES[$logo];
272
+                    $sources[$etat]['msg'] = $msg;
273
+                }
274
+            }
275
+        }
276
+    }
277 277
 
278
-	return $sources;
278
+    return $sources;
279 279
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 
65 65
 	if (!isset($options['titre'])) {
66 66
 		$balise_img = chercher_filtre('balise_img');
67
-		$img = $balise_img(chemin_image('image-24.png'),'', 'cadre-icone');
67
+		$img = $balise_img(chemin_image('image-24.png'), '', 'cadre-icone');
68 68
 		$libelles = pipeline('libeller_logo', $GLOBALS['logo_libelles']);
69 69
 		$libelle = (($id_objet or $objet != 'rubrique') ? $objet : 'racine');
70 70
 		if (isset($libelles[$libelle])) {
@@ -76,19 +76,19 @@  discard block
 block discarded – undo
76 76
 		}
77 77
 		switch ($objet) {
78 78
 			case 'article':
79
-				$libelle .= ' ' . aider('logoart');
79
+				$libelle .= ' '.aider('logoart');
80 80
 				break;
81 81
 			case 'breve':
82
-				$libelle .= ' ' . aider('breveslogo');
82
+				$libelle .= ' '.aider('breveslogo');
83 83
 				break;
84 84
 			case 'rubrique':
85
-				$libelle .= ' ' . aider('rublogo');
85
+				$libelle .= ' '.aider('rublogo');
86 86
 				break;
87 87
 			default:
88 88
 				break;
89 89
 		}
90 90
 
91
-		$options['titre'] = $img . $libelle;
91
+		$options['titre'] = $img.$libelle;
92 92
 	}
93 93
 	if (!isset($options['editable'])) {
94 94
 		include_spip('inc/autoriser');
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	foreach ($etats as $etat) {
114 114
 		$logo = $chercher_logo($id_objet, $_id_objet, $etat);
115 115
 		if ($logo) {
116
-			$res['logo_' . $etat] = $logo[0];
116
+			$res['logo_'.$etat] = $logo[0];
117 117
 		}
118 118
 	}
119 119
 	// pas de logo_on -> pas de formulaire pour le survol
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 				strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)),
177 177
 				$extensions_possibles
178 178
 			)) {
179
-				$erreurs['logo_' . $etat] = _L('Extension non reconnue');
179
+				$erreurs['logo_'.$etat] = _L('Extension non reconnue');
180 180
 			}
181 181
 		} elseif ($file and $file['error'] != 0 and isset($file['msg'])) {
182 182
 			$erreurs['message_erreur'] = $file['msg'];
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 	include_spip('inc/documents');
262 262
 	$sources = array();
263 263
 	foreach (array('on', 'off') as $etat) {
264
-		$logo = 'logo_' . $etat;
264
+		$logo = 'logo_'.$etat;
265 265
 		if (isset($_FILES[$logo])) {
266 266
 			if ($_FILES[$logo]['error'] == 0) {
267 267
 				$sources[$etat] = $_FILES[$logo];
Please login to merge, or discard this patch.