Completed
Push — spip-3.0 ( cd2822...016705 )
by cam
08:31
created
ecrire/inc/filtres.php 5 patches
Doc Comments   +52 added lines, -3 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
  * http://doc.spip.org/@chercher_filtre
38 38
  *
39 39
  * @param string $fonc
40
- * @param null $default
40
+ * @param string $default
41 41
  * @return string
42 42
  */
43 43
 function chercher_filtre($fonc, $default=NULL) {
@@ -117,6 +117,9 @@  discard block
 block discarded – undo
117 117
 // (numero non garanti pour l'espace public et en cas de mutualisation)
118 118
 // on est negatif si on est sur .svn, et positif si on utilise svn.revision
119 119
 // http://doc.spip.org/@version_svn_courante
120
+/**
121
+ * @param string $dir
122
+ */
120 123
 function version_svn_courante($dir) {
121 124
 	if (!$dir) $dir = '.';
122 125
 
@@ -169,6 +172,9 @@  discard block
 block discarded – undo
169 172
 
170 173
 // charge les fonctions graphiques et applique celle demandee
171 174
 // http://doc.spip.org/@filtrer
175
+/**
176
+ * @param string $filtre
177
+ */
172 178
 function filtrer($filtre) {
173 179
 	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])){
174 180
 		find_in_path($f,'', true);
@@ -363,12 +369,18 @@  discard block
 block discarded – undo
363 369
 // preserver des echappements de caracteres "bas" (par exemple [ ou ")
364 370
 // et au cas particulier de & qui devient & dans les url
365 371
 // http://doc.spip.org/@corriger_entites_html
372
+/**
373
+ * @param string $texte
374
+ */
366 375
 function corriger_entites_html($texte) {
367 376
 	if (strpos($texte,'&') === false) return $texte;
368 377
 	return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
369 378
 }
370 379
 // idem mais corriger aussi les é en é
371 380
 // http://doc.spip.org/@corriger_toutes_entites_html
381
+/**
382
+ * @param string $texte
383
+ */
372 384
 function corriger_toutes_entites_html($texte) {
373 385
 	if (strpos($texte,'&') === false) return $texte;
374 386
 	return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte);
@@ -434,6 +446,9 @@  discard block
 block discarded – undo
434 446
 
435 447
 // caracteres de controle - http://www.w3.org/TR/REC-xml/#charsets
436 448
 // http://doc.spip.org/@supprimer_caracteres_illegaux
449
+/**
450
+ * @param string $texte
451
+ */
437 452
 function supprimer_caracteres_illegaux($texte) {
438 453
 	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";
439 454
 	static $to = null;
@@ -461,7 +476,7 @@  discard block
 block discarded – undo
461 476
  * http://doc.spip.org/@texte_backend
462 477
  *
463 478
  * @param $texte
464
- * @return mixed
479
+ * @return string
465 480
  */
466 481
 function texte_backend($texte) {
467 482
 
@@ -591,6 +606,9 @@  discard block
 block discarded – undo
591 606
 
592 607
 // Transformer les sauts de paragraphe en simples passages a la ligne
593 608
 // http://doc.spip.org/@PtoBR
609
+/**
610
+ * @param string $texte
611
+ */
594 612
 function PtoBR($texte){
595 613
 	$u = $GLOBALS['meta']['pcre_u'];
596 614
 	$texte = preg_replace("@</p>@iS", "\n", $texte);
@@ -649,6 +667,9 @@  discard block
 block discarded – undo
649 667
 
650 668
 // "127.4 ko" ou "3.1 Mo"
651 669
 // http://doc.spip.org/@taille_en_octets
670
+/**
671
+ * @param integer $taille
672
+ */
652 673
 function taille_en_octets ($taille) {
653 674
 	if ($taille < 1) return '';
654 675
 	if ($taille < 1024) {$taille = _T('taille_octets', array('taille' => $taille));}
@@ -753,6 +774,9 @@  discard block
 block discarded – undo
753 774
 
754 775
 // on normalise la date, si elle vient du contexte (public/parametrer.php), on force le jour
755 776
 // http://doc.spip.org/@normaliser_date
777
+/**
778
+ * @param string $date
779
+ */
756 780
 function normaliser_date($date, $forcer_jour = false) {
757 781
 	$date = vider_date($date);
758 782
 	if ($date) {
@@ -979,7 +1003,7 @@  discard block
 block discarded – undo
979 1003
  * http://doc.spip.org/@affdate_base
980 1004
  *
981 1005
  * @param $numdate
982
- * @param $vue
1006
+ * @param string $vue
983 1007
  * @param array $options
984 1008
  *   param : 'abbr' ou 'initiale' permet d'afficher les jours au format court ou initiale
985 1009
  *   annee_courante : permet de definir l'annee de reference pour l'affichage des dates courtes
@@ -1096,12 +1120,18 @@  discard block
 block discarded – undo
1096 1120
 }
1097 1121
 
1098 1122
 // http://doc.spip.org/@nom_jour
1123
+/**
1124
+ * @param string $numdate
1125
+ */
1099 1126
 function nom_jour($numdate, $forme = '') {
1100 1127
 	if(!($forme == 'abbr' OR $forme == 'initiale')) $forme = '';
1101 1128
 	return affdate_base($numdate, 'nom_jour', $forme);
1102 1129
 }
1103 1130
 
1104 1131
 // http://doc.spip.org/@jour
1132
+/**
1133
+ * @param string $numdate
1134
+ */
1105 1135
 function jour($numdate) {
1106 1136
 	return affdate_base($numdate, 'jour');
1107 1137
 }
@@ -1148,6 +1178,10 @@  discard block
 block discarded – undo
1148 1178
 }
1149 1179
 
1150 1180
 // http://doc.spip.org/@affdate_jourcourt
1181
+/**
1182
+ * @param string $numdate
1183
+ * @param string $annee_courante
1184
+ */
1151 1185
 function affdate_jourcourt($numdate, $annee_courante=null) {
1152 1186
 	return affdate_base($numdate, 'jourcourt', array('annee_courante'=>$annee_courante));
1153 1187
 }
@@ -1342,6 +1376,9 @@  discard block
 block discarded – undo
1342 1376
 // date_iso retourne la date au format "RFC 3339" / "ISO 8601"
1343 1377
 // voir http://www.php.net/manual/fr/ref.datetime.php#datetime.constants
1344 1378
 // http://doc.spip.org/@date_iso
1379
+/**
1380
+ * @param string $date_heure
1381
+ */
1345 1382
 function date_iso($date_heure) {
1346 1383
 	list($annee, $mois, $jour) = recup_date($date_heure);
1347 1384
 	list($heures, $minutes, $secondes) = recup_heure($date_heure);
@@ -1451,6 +1488,9 @@  discard block
 block discarded – undo
1451 1488
 // Extraire et transformer les blocs multi ; on indique la langue courante
1452 1489
 // pour ne pas mettre de span@lang=fr si on est deja en fr
1453 1490
 // http://doc.spip.org/@extraire_multi
1491
+/**
1492
+ * @param string $lang
1493
+ */
1454 1494
 function extraire_multi($letexte, $lang=null, $echappe_span=false) {
1455 1495
 	if (preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)) {
1456 1496
 		if (!$lang) $lang = $GLOBALS['spip_lang'];
@@ -1490,6 +1530,9 @@  discard block
 block discarded – undo
1490 1530
 
1491 1531
 // convertit le contenu d'une balise multi en un tableau
1492 1532
 // http://doc.spip.org/@extraire_trad
1533
+/**
1534
+ * @param string $bloc
1535
+ */
1493 1536
 function extraire_trads($bloc) {
1494 1537
 	$lang = '';
1495 1538
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
@@ -1555,6 +1598,9 @@  discard block
 block discarded – undo
1555 1598
 // Exemple [(#COMPTEUR_BOUCLE|alterner{'bleu','vert','rouge'})]
1556 1599
 //
1557 1600
 // http://doc.spip.org/@alterner
1601
+/**
1602
+ * @param integer $i
1603
+ */
1558 1604
 function alterner($i) {
1559 1605
 	// recuperer les arguments (attention fonctions un peu space)
1560 1606
 	$num = func_num_args();
@@ -1897,6 +1943,9 @@  discard block
 block discarded – undo
1897 1943
 // l'URL donnee en argument, compatible avec les types_urls depuis [14447].
1898 1944
 // cf. tests/filtres/form_hidden.html
1899 1945
 // http://doc.spip.org/@form_hidden
1946
+/**
1947
+ * @param string $action
1948
+ */
1900 1949
 function form_hidden($action) {
1901 1950
 
1902 1951
 	$contexte = array();
Please login to merge, or discard this patch.
Indentation   +1915 added lines, -1915 removed lines patch added patch discarded remove patch
@@ -27,8 +27,8 @@  discard block
 block discarded – undo
27 27
  * @return string
28 28
  */
29 29
 function charger_filtre($fonc, $default='filtre_identite_dist') {
30
-	include_spip('public/parametrer'); // inclure les fichiers fonctions
31
-	return chercher_filtre($fonc, $default);
30
+    include_spip('public/parametrer'); // inclure les fichiers fonctions
31
+    return chercher_filtre($fonc, $default);
32 32
 }
33 33
 
34 34
 function filtre_identite_dist($texte){return $texte;}
@@ -41,31 +41,31 @@  discard block
 block discarded – undo
41 41
  * @return string
42 42
  */
43 43
 function chercher_filtre($fonc, $default=NULL) {
44
-	if (!$fonc) return $default;
45
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
46
-	// Foo::Bar
47
-	// qui peuvent etre avec un namespace : space\Foo::Bar
48
-	if (preg_match(',^[\w]+/,',$fonc)){
49
-		$nom = preg_replace(',\W,','_', $fonc);
50
-		$f = chercher_filtre($nom);
51
-		// cas du sous-type MIME sans filtre associe, passer au type:
52
-		// si filtre_text_plain pas defini, passe a filtre_text
53
-		if (!$f AND $nom!==$fonc)
54
-			$f = chercher_filtre(preg_replace(',\W.*$,','', $fonc));
55
-		return $f;
56
-	}
57
-	foreach (
58
-	array('filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc) as $f){
59
-		if (isset( $GLOBALS['spip_matrice'][$f]) AND is_string($g = $GLOBALS['spip_matrice'][$f]))
60
-			find_in_path($g,'', true);
61
-		if (function_exists($f)
62
-		OR (preg_match("/^(\w*)::(\w*)$/", $f, $regs)
63
-			AND is_callable(array($regs[1], $regs[2]))
64
-		)) {
65
-			return $f;
66
-		}
67
-	}
68
-	return $default;
44
+    if (!$fonc) return $default;
45
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
46
+    // Foo::Bar
47
+    // qui peuvent etre avec un namespace : space\Foo::Bar
48
+    if (preg_match(',^[\w]+/,',$fonc)){
49
+        $nom = preg_replace(',\W,','_', $fonc);
50
+        $f = chercher_filtre($nom);
51
+        // cas du sous-type MIME sans filtre associe, passer au type:
52
+        // si filtre_text_plain pas defini, passe a filtre_text
53
+        if (!$f AND $nom!==$fonc)
54
+            $f = chercher_filtre(preg_replace(',\W.*$,','', $fonc));
55
+        return $f;
56
+    }
57
+    foreach (
58
+    array('filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc) as $f){
59
+        if (isset( $GLOBALS['spip_matrice'][$f]) AND is_string($g = $GLOBALS['spip_matrice'][$f]))
60
+            find_in_path($g,'', true);
61
+        if (function_exists($f)
62
+        OR (preg_match("/^(\w*)::(\w*)$/", $f, $regs)
63
+            AND is_callable(array($regs[1], $regs[2]))
64
+        )) {
65
+            return $f;
66
+        }
67
+    }
68
+    return $default;
69 69
 }
70 70
 
71 71
 /**
@@ -90,25 +90,25 @@  discard block
 block discarded – undo
90 90
  *     Chaîne vide si le filtre n'a pas été trouvé et que $force a été fourni.
91 91
 **/
92 92
 function appliquer_filtre($arg, $filtre, $force=NULL) {
93
-	$f = chercher_filtre($filtre);
94
-	if (!$f) {
95
-		if (!$force) return '';
96
-		else return $arg;
97
-	}
93
+    $f = chercher_filtre($filtre);
94
+    if (!$f) {
95
+        if (!$force) return '';
96
+        else return $arg;
97
+    }
98 98
 
99
-	$args = func_get_args();
100
-	array_shift($args); // enlever $arg
101
-	array_shift($args); // enlever $filtre
102
-	array_unshift($args, $arg); // remettre $arg
103
-	return call_user_func_array($f,$args);
99
+    $args = func_get_args();
100
+    array_shift($args); // enlever $arg
101
+    array_shift($args); // enlever $filtre
102
+    array_unshift($args, $arg); // remettre $arg
103
+    return call_user_func_array($f,$args);
104 104
 }
105 105
 
106 106
 // http://doc.spip.org/@spip_version
107 107
 function spip_version() {
108
-	$version = $GLOBALS['spip_version_affichee'];
109
-	if ($svn_revision = version_svn_courante(_DIR_RACINE))
110
-		$version .= ($svn_revision<0 ? ' SVN':'').' ['.abs($svn_revision).']';
111
-	return $version;
108
+    $version = $GLOBALS['spip_version_affichee'];
109
+    if ($svn_revision = version_svn_courante(_DIR_RACINE))
110
+        $version .= ($svn_revision<0 ? ' SVN':'').' ['.abs($svn_revision).']';
111
+    return $version;
112 112
 }
113 113
 
114 114
 
@@ -118,28 +118,28 @@  discard block
 block discarded – undo
118 118
 // on est negatif si on est sur .svn, et positif si on utilise svn.revision
119 119
 // http://doc.spip.org/@version_svn_courante
120 120
 function version_svn_courante($dir) {
121
-	if (!$dir) $dir = '.';
122
-
123
-	// version installee par paquet ZIP
124
-	if (lire_fichier($dir.'/svn.revision', $c)
125
-	AND preg_match(',Revision: (\d+),', $c, $d))
126
-		return intval($d[1]);
127
-
128
-	// version installee par SVN
129
-	if (lire_fichier($dir . '/.svn/entries', $c)
130
-	AND (
131
-	(preg_match_all(
132
-	',committed-rev="([0-9]+)",', $c, $r1, PREG_PATTERN_ORDER)
133
-	AND $v = max($r1[1])
134
-	)
135
-	OR
136
-	(preg_match(',^\d.*dir[\r\n]+(\d+),ms', $c, $r1) # svn >= 1.4
137
-	AND $v = $r1[1]
138
-	)))
139
-		return -$v;
140
-
141
-	// Bug ou paquet fait main
142
-	return 0;
121
+    if (!$dir) $dir = '.';
122
+
123
+    // version installee par paquet ZIP
124
+    if (lire_fichier($dir.'/svn.revision', $c)
125
+    AND preg_match(',Revision: (\d+),', $c, $d))
126
+        return intval($d[1]);
127
+
128
+    // version installee par SVN
129
+    if (lire_fichier($dir . '/.svn/entries', $c)
130
+    AND (
131
+    (preg_match_all(
132
+    ',committed-rev="([0-9]+)",', $c, $r1, PREG_PATTERN_ORDER)
133
+    AND $v = max($r1[1])
134
+    )
135
+    OR
136
+    (preg_match(',^\d.*dir[\r\n]+(\d+),ms', $c, $r1) # svn >= 1.4
137
+    AND $v = $r1[1]
138
+    )))
139
+        return -$v;
140
+
141
+    // Bug ou paquet fait main
142
+    return 0;
143 143
 }
144 144
 
145 145
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -170,23 +170,23 @@  discard block
 block discarded – undo
170 170
 // charge les fonctions graphiques et applique celle demandee
171 171
 // http://doc.spip.org/@filtrer
172 172
 function filtrer($filtre) {
173
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])){
174
-		find_in_path($f,'', true);
175
-		$GLOBALS['spip_matrice'][$filtre] = true;
176
-	}
177
-	$tous = func_get_args();
178
-	if (substr($filtre,0,6)=='image_' && $GLOBALS['spip_matrice'][$filtre])
179
-		return image_filtrer($tous);
180
-	elseif($f = chercher_filtre($filtre)) {
181
-		array_shift($tous);
182
-		return call_user_func_array($f, $tous);
183
-	}
184
-	else {
185
-		// le filtre n'existe pas, on provoque une erreur
186
-		$msg = array('zbug_erreur_filtre', array('filtre'=>texte_script($filtre)));
187
-		erreur_squelette($msg);
188
-		return '';
189
-	}
173
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])){
174
+        find_in_path($f,'', true);
175
+        $GLOBALS['spip_matrice'][$filtre] = true;
176
+    }
177
+    $tous = func_get_args();
178
+    if (substr($filtre,0,6)=='image_' && $GLOBALS['spip_matrice'][$filtre])
179
+        return image_filtrer($tous);
180
+    elseif($f = chercher_filtre($filtre)) {
181
+        array_shift($tous);
182
+        return call_user_func_array($f, $tous);
183
+    }
184
+    else {
185
+        // le filtre n'existe pas, on provoque une erreur
186
+        $msg = array('zbug_erreur_filtre', array('filtre'=>texte_script($filtre)));
187
+        erreur_squelette($msg);
188
+        return '';
189
+    }
190 190
 }
191 191
 
192 192
 /*
@@ -199,8 +199,8 @@  discard block
 block discarded – undo
199 199
  *
200 200
  */
201 201
 function filtre_set(&$Pile, $val, $key, $continue = null) {
202
-	$Pile['vars'][$key] = $val;
203
-	return $continue ? $val : '';
202
+    $Pile['vars'][$key] = $val;
203
+    return $continue ? $val : '';
204 204
 }
205 205
 
206 206
 /*
@@ -208,17 +208,17 @@  discard block
 block discarded – undo
208 208
  *   la valeur de #TRUC avant et après le calcul
209 209
  */
210 210
 function filtre_debug($val, $key=null) {
211
-	$debug = (
212
-		is_null($key) ? '' :  (var_export($key,true)." = ")
213
-	) . var_export($val, true);
211
+    $debug = (
212
+        is_null($key) ? '' :  (var_export($key,true)." = ")
213
+    ) . var_export($val, true);
214 214
 
215
-	include_spip('inc/autoriser');
216
-	if (autoriser('webmestre'))
217
-		echo "<div class='spip_debug'>\n",$debug,"</div>\n";
215
+    include_spip('inc/autoriser');
216
+    if (autoriser('webmestre'))
217
+        echo "<div class='spip_debug'>\n",$debug,"</div>\n";
218 218
 
219
-	spip_log($debug, 'debug');
219
+    spip_log($debug, 'debug');
220 220
 
221
-	return $val;
221
+    return $val;
222 222
 }
223 223
 
224 224
 
@@ -230,63 +230,63 @@  discard block
 block discarded – undo
230 230
 
231 231
 // http://doc.spip.org/@image_filtrer
232 232
 function image_filtrer($args){
233
-	$filtre = array_shift($args); # enlever $filtre
234
-	$texte = array_shift($args);
235
-	if (!strlen($texte)) return;
236
-	find_in_path('filtres_images_mini.php','inc/', true);
237
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
238
-	// Cas du nom de fichier local
239
-	if ( strpos(substr($texte,strlen(_DIR_RACINE)),'..')===FALSE
240
-	AND !preg_match(',^/|[<>]|\s,S', $texte)
241
-	AND (
242
-		file_exists(preg_replace(',[?].*$,','',$texte))
243
-		OR preg_match(';^(\w{3,7}://);', $texte) 
244
-		)) {
245
-		array_unshift($args,"<img src='$texte' />");
246
-		$res = call_user_func_array($filtre, $args);
247
-		statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
248
-		return $res;
249
-	}
250
-
251
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
252
-	if (preg_match_all(
253
-		',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
254
-		$texte, $tags, PREG_SET_ORDER)) {
255
-		foreach ($tags as $tag) {
256
-			$class = extraire_attribut($tag[3],'class');
257
-			if (!$class || (strpos($class,'no_image_filtrer')===FALSE)){
258
-				array_unshift($args,$tag[3]);
259
-				if ($reduit = call_user_func_array($filtre, $args)) {
260
-					// En cas de span spip_documents, modifier le style=...width:
261
-					if($tag[1]){
262
-						$w = extraire_attribut($reduit, 'width');
263
-						if (!$w AND preg_match(",width:\s*(\d+)px,S",extraire_attribut($reduit,'style'),$regs))
264
-							$w = $regs[1];
265
-						if ($w AND ($style = extraire_attribut($tag[1], 'style'))){
266
-							$style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
267
-							$replace = inserer_attribut($tag[1], 'style', $style);
268
-							$texte = str_replace($tag[1], $replace, $texte);
269
-						}
270
-					}
271
-					// traiter aussi un eventuel mouseover
272
-					if ($mouseover = extraire_attribut($reduit,'onmouseover')){
273
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)){
274
-							$srcover = $match[1];
275
-							array_shift($args);
276
-							array_unshift($args,"<img src='".$match[1]."' />");
277
-							$srcover_filter = call_user_func_array($filtre, $args);
278
-							$srcover_filter = extraire_attribut($srcover_filter,'src');
279
-							$reduit = str_replace($srcover,$srcover_filter,$reduit);
280
-						}
281
-					}
282
-					$texte = str_replace($tag[3], $reduit, $texte);
283
-				}
284
-				array_shift($args);
285
-			}
286
-		}
287
-	}
288
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
289
-	return $texte;
233
+    $filtre = array_shift($args); # enlever $filtre
234
+    $texte = array_shift($args);
235
+    if (!strlen($texte)) return;
236
+    find_in_path('filtres_images_mini.php','inc/', true);
237
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
238
+    // Cas du nom de fichier local
239
+    if ( strpos(substr($texte,strlen(_DIR_RACINE)),'..')===FALSE
240
+    AND !preg_match(',^/|[<>]|\s,S', $texte)
241
+    AND (
242
+        file_exists(preg_replace(',[?].*$,','',$texte))
243
+        OR preg_match(';^(\w{3,7}://);', $texte) 
244
+        )) {
245
+        array_unshift($args,"<img src='$texte' />");
246
+        $res = call_user_func_array($filtre, $args);
247
+        statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
248
+        return $res;
249
+    }
250
+
251
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
252
+    if (preg_match_all(
253
+        ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
254
+        $texte, $tags, PREG_SET_ORDER)) {
255
+        foreach ($tags as $tag) {
256
+            $class = extraire_attribut($tag[3],'class');
257
+            if (!$class || (strpos($class,'no_image_filtrer')===FALSE)){
258
+                array_unshift($args,$tag[3]);
259
+                if ($reduit = call_user_func_array($filtre, $args)) {
260
+                    // En cas de span spip_documents, modifier le style=...width:
261
+                    if($tag[1]){
262
+                        $w = extraire_attribut($reduit, 'width');
263
+                        if (!$w AND preg_match(",width:\s*(\d+)px,S",extraire_attribut($reduit,'style'),$regs))
264
+                            $w = $regs[1];
265
+                        if ($w AND ($style = extraire_attribut($tag[1], 'style'))){
266
+                            $style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
267
+                            $replace = inserer_attribut($tag[1], 'style', $style);
268
+                            $texte = str_replace($tag[1], $replace, $texte);
269
+                        }
270
+                    }
271
+                    // traiter aussi un eventuel mouseover
272
+                    if ($mouseover = extraire_attribut($reduit,'onmouseover')){
273
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)){
274
+                            $srcover = $match[1];
275
+                            array_shift($args);
276
+                            array_unshift($args,"<img src='".$match[1]."' />");
277
+                            $srcover_filter = call_user_func_array($filtre, $args);
278
+                            $srcover_filter = extraire_attribut($srcover_filter,'src');
279
+                            $reduit = str_replace($srcover,$srcover_filter,$reduit);
280
+                        }
281
+                    }
282
+                    $texte = str_replace($tag[3], $reduit, $texte);
283
+                }
284
+                array_shift($args);
285
+            }
286
+        }
287
+    }
288
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
289
+    return $texte;
290 290
 }
291 291
 
292 292
 //
@@ -296,61 +296,61 @@  discard block
 block discarded – undo
296 296
 // http://doc.spip.org/@taille_image
297 297
 function taille_image($img) {
298 298
 
299
-	static $largeur_img =array(), $hauteur_img= array();
300
-	$srcWidth = 0;
301
-	$srcHeight = 0;
302
-
303
-	$logo = extraire_attribut($img,'src');
304
-
305
-	if (!$logo) $logo = $img;
306
-	else {
307
-		$srcWidth = extraire_attribut($img,'width');
308
-		$srcHeight = extraire_attribut($img,'height');
309
-	}
310
-
311
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
312
-	// la copie locale a toutes les chances d'etre la ou de resservir
313
-	if (preg_match(';^(\w{3,7}://);', $logo)){
314
-		include_spip('inc/distant');
315
-		$fichier = copie_locale($logo);
316
-		$logo = $fichier ? _DIR_RACINE . $fichier : $logo;
317
-	}
318
-	if (($p=strpos($logo,'?'))!==FALSE)
319
-		$logo=substr($logo,0,$p);
320
-
321
-	$srcsize = false;
322
-	if (isset($largeur_img[$logo]))
323
-		$srcWidth = $largeur_img[$logo];
324
-	if (isset($hauteur_img[$logo]))
325
-		$srcHeight = $hauteur_img[$logo];
326
-	if (!$srcWidth OR !$srcHeight){
327
-		if (file_exists($logo)
328
-			AND $srcsize = @getimagesize($logo)){
329
-			if (!$srcWidth)	$largeur_img[$logo] = $srcWidth = $srcsize[0];
330
-			if (!$srcHeight)	$hauteur_img[$logo] = $srcHeight = $srcsize[1];
331
-		}
332
-		// $logo peut etre une reference a une image temporaire dont a n'a que le log .src
333
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
334
-		elseif(@file_exists($f = "$logo.src")
335
-		  AND lire_fichier($f,$valeurs)
336
-		  AND $valeurs=unserialize($valeurs)) {
337
-			if (!$srcWidth)	$largeur_img[$logo] = $srcWidth = $valeurs["largeur_dest"];
338
-			if (!$srcHeight)	$hauteur_img[$logo] = $srcHeight = $valeurs["hauteur_dest"];
339
-	  }
340
-	}
341
-	return array($srcHeight, $srcWidth);
299
+    static $largeur_img =array(), $hauteur_img= array();
300
+    $srcWidth = 0;
301
+    $srcHeight = 0;
302
+
303
+    $logo = extraire_attribut($img,'src');
304
+
305
+    if (!$logo) $logo = $img;
306
+    else {
307
+        $srcWidth = extraire_attribut($img,'width');
308
+        $srcHeight = extraire_attribut($img,'height');
309
+    }
310
+
311
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
312
+    // la copie locale a toutes les chances d'etre la ou de resservir
313
+    if (preg_match(';^(\w{3,7}://);', $logo)){
314
+        include_spip('inc/distant');
315
+        $fichier = copie_locale($logo);
316
+        $logo = $fichier ? _DIR_RACINE . $fichier : $logo;
317
+    }
318
+    if (($p=strpos($logo,'?'))!==FALSE)
319
+        $logo=substr($logo,0,$p);
320
+
321
+    $srcsize = false;
322
+    if (isset($largeur_img[$logo]))
323
+        $srcWidth = $largeur_img[$logo];
324
+    if (isset($hauteur_img[$logo]))
325
+        $srcHeight = $hauteur_img[$logo];
326
+    if (!$srcWidth OR !$srcHeight){
327
+        if (file_exists($logo)
328
+            AND $srcsize = @getimagesize($logo)){
329
+            if (!$srcWidth)	$largeur_img[$logo] = $srcWidth = $srcsize[0];
330
+            if (!$srcHeight)	$hauteur_img[$logo] = $srcHeight = $srcsize[1];
331
+        }
332
+        // $logo peut etre une reference a une image temporaire dont a n'a que le log .src
333
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
334
+        elseif(@file_exists($f = "$logo.src")
335
+          AND lire_fichier($f,$valeurs)
336
+          AND $valeurs=unserialize($valeurs)) {
337
+            if (!$srcWidth)	$largeur_img[$logo] = $srcWidth = $valeurs["largeur_dest"];
338
+            if (!$srcHeight)	$hauteur_img[$logo] = $srcHeight = $valeurs["hauteur_dest"];
339
+        }
340
+    }
341
+    return array($srcHeight, $srcWidth);
342 342
 }
343 343
 // http://doc.spip.org/@largeur
344 344
 function largeur($img) {
345
-	if (!$img) return;
346
-	list ($h,$l) = taille_image($img);
347
-	return $l;
345
+    if (!$img) return;
346
+    list ($h,$l) = taille_image($img);
347
+    return $l;
348 348
 }
349 349
 // http://doc.spip.org/@hauteur
350 350
 function hauteur($img) {
351
-	if (!$img) return;
352
-	list ($h,$l) = taille_image($img);
353
-	return $h;
351
+    if (!$img) return;
352
+    list ($h,$l) = taille_image($img);
353
+    return $h;
354 354
 }
355 355
 
356 356
 
@@ -364,19 +364,19 @@  discard block
 block discarded – undo
364 364
 // et au cas particulier de &amp; qui devient &amp;amp; dans les url
365 365
 // http://doc.spip.org/@corriger_entites_html
366 366
 function corriger_entites_html($texte) {
367
-	if (strpos($texte,'&amp;') === false) return $texte;
368
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
367
+    if (strpos($texte,'&amp;') === false) return $texte;
368
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
369 369
 }
370 370
 // idem mais corriger aussi les &amp;eacute; en &eacute;
371 371
 // http://doc.spip.org/@corriger_toutes_entites_html
372 372
 function corriger_toutes_entites_html($texte) {
373
-	if (strpos($texte,'&amp;') === false) return $texte;
374
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
373
+    if (strpos($texte,'&amp;') === false) return $texte;
374
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
375 375
 }
376 376
 
377 377
 // http://doc.spip.org/@proteger_amp
378 378
 function proteger_amp($texte){
379
-	return str_replace('&','&amp;',$texte);
379
+    return str_replace('&','&amp;',$texte);
380 380
 }
381 381
 
382 382
 //
@@ -392,31 +392,31 @@  discard block
 block discarded – undo
392 392
  * @return mixed|string
393 393
  */
394 394
 function entites_html($texte, $tout=false, $quote=true) {
395
-	if (!is_string($texte) OR !$texte
396
-	OR strpbrk($texte, "&\"'<>")==false
397
-	) return $texte;
398
-	include_spip('inc/texte');
399
-	$flags = !defined('PHP_VERSION_ID') OR PHP_VERSION_ID < 50400 ? ENT_COMPAT : ENT_COMPAT|ENT_HTML401;
400
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $quote?ENT_QUOTES:$flags);
401
-	if ($tout)
402
-		return corriger_toutes_entites_html($texte);
403
-	else
404
-		return corriger_entites_html($texte);
395
+    if (!is_string($texte) OR !$texte
396
+    OR strpbrk($texte, "&\"'<>")==false
397
+    ) return $texte;
398
+    include_spip('inc/texte');
399
+    $flags = !defined('PHP_VERSION_ID') OR PHP_VERSION_ID < 50400 ? ENT_COMPAT : ENT_COMPAT|ENT_HTML401;
400
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $quote?ENT_QUOTES:$flags);
401
+    if ($tout)
402
+        return corriger_toutes_entites_html($texte);
403
+    else
404
+        return corriger_entites_html($texte);
405 405
 }
406 406
 
407 407
 // Transformer les &eacute; dans le charset local
408 408
 // http://doc.spip.org/@filtrer_entites
409 409
 function filtrer_entites($texte) {
410
-	if (strpos($texte,'&') === false) return $texte;
411
-	// filtrer
412
-	$texte = html2unicode($texte);
413
-	// remettre le tout dans le charset cible
414
-	$texte = unicode2charset($texte);
415
-	// cas particulier des " et ' qu'il faut filtrer aussi
416
-	// (on le faisait deja avec un &quot;)
417
-	if (strpos($texte,"&#")!==false)
418
-		$texte = str_replace(array("&#039;","&#39;","&#034;","&#34;"), array("'","'",'"','"'), $texte);
419
-	return $texte;
410
+    if (strpos($texte,'&') === false) return $texte;
411
+    // filtrer
412
+    $texte = html2unicode($texte);
413
+    // remettre le tout dans le charset cible
414
+    $texte = unicode2charset($texte);
415
+    // cas particulier des " et ' qu'il faut filtrer aussi
416
+    // (on le faisait deja avec un &quot;)
417
+    if (strpos($texte,"&#")!==false)
418
+        $texte = str_replace(array("&#039;","&#39;","&#034;","&#34;"), array("'","'",'"','"'), $texte);
419
+    return $texte;
420 420
 }
421 421
 
422 422
 /**
@@ -425,33 +425,33 @@  discard block
 block discarded – undo
425 425
  * @return string
426 426
  */
427 427
 if (!function_exists('filtre_filtrer_entites_dist')) {
428
-	function filtre_filtrer_entites_dist($t) {
429
-		include_spip('inc/texte');
430
-		return interdire_scripts(filtrer_entites($t));
431
-	}
428
+    function filtre_filtrer_entites_dist($t) {
429
+        include_spip('inc/texte');
430
+        return interdire_scripts(filtrer_entites($t));
431
+    }
432 432
 }
433 433
 
434 434
 
435 435
 // caracteres de controle - http://www.w3.org/TR/REC-xml/#charsets
436 436
 // http://doc.spip.org/@supprimer_caracteres_illegaux
437 437
 function supprimer_caracteres_illegaux($texte) {
438
-	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";
439
-	static $to = null;
438
+    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";
439
+    static $to = null;
440 440
 	
441
-	if (is_array($texte)) {
442
-		return array_map('supprimer_caracteres_illegaux', $texte);
443
-	}
441
+    if (is_array($texte)) {
442
+        return array_map('supprimer_caracteres_illegaux', $texte);
443
+    }
444 444
 	
445
-	if (!$to) $to = str_repeat('-', strlen($from));
446
-	return strtr($texte, $from, $to);
445
+    if (!$to) $to = str_repeat('-', strlen($from));
446
+    return strtr($texte, $from, $to);
447 447
 }
448 448
 
449 449
 // Supprimer caracteres windows et les caracteres de controle ILLEGAUX
450 450
 // http://doc.spip.org/@corriger_caracteres
451 451
 function corriger_caracteres ($texte) {
452
-	$texte = corriger_caracteres_windows($texte);
453
-	$texte = supprimer_caracteres_illegaux($texte);
454
-	return $texte;
452
+    $texte = corriger_caracteres_windows($texte);
453
+    $texte = supprimer_caracteres_illegaux($texte);
454
+    return $texte;
455 455
 }
456 456
 
457 457
 /**
@@ -465,105 +465,105 @@  discard block
 block discarded – undo
465 465
  */
466 466
 function texte_backend($texte) {
467 467
 
468
-	static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
468
+    static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
469 469
 
470
-	// si on a des liens ou des images, les passer en absolu
471
-	$texte = liens_absolus($texte);
470
+    // si on a des liens ou des images, les passer en absolu
471
+    $texte = liens_absolus($texte);
472 472
 
473
-	// echapper les tags &gt; &lt;
474
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
473
+    // echapper les tags &gt; &lt;
474
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
475 475
 
476
-	// importer les &eacute;
477
-	$texte = filtrer_entites($texte);
476
+    // importer les &eacute;
477
+    $texte = filtrer_entites($texte);
478 478
 
479
-	// " -> &quot; et tout ce genre de choses
480
-	$u = $GLOBALS['meta']['pcre_u'];
481
-	$texte = str_replace("&nbsp;", " ", $texte);
482
-	$texte = preg_replace('/\s{2,}/S'.$u, " ", $texte);
483
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
484
-	$texte = entites_html($texte, false, false);
485
-	// mais bien echapper les double quotes !
486
-	$texte = str_replace('"','&#034;',$texte);
479
+    // " -> &quot; et tout ce genre de choses
480
+    $u = $GLOBALS['meta']['pcre_u'];
481
+    $texte = str_replace("&nbsp;", " ", $texte);
482
+    $texte = preg_replace('/\s{2,}/S'.$u, " ", $texte);
483
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
484
+    $texte = entites_html($texte, false, false);
485
+    // mais bien echapper les double quotes !
486
+    $texte = str_replace('"','&#034;',$texte);
487 487
 
488
-	// verifier le charset
489
-	$texte = charset2unicode($texte);
488
+    // verifier le charset
489
+    $texte = charset2unicode($texte);
490 490
 
491
-	// Caracteres problematiques en iso-latin 1
492
-	if ($GLOBALS['meta']['charset'] == 'iso-8859-1') {
493
-		$texte = str_replace(chr(156), '&#156;', $texte);
494
-		$texte = str_replace(chr(140), '&#140;', $texte);
495
-		$texte = str_replace(chr(159), '&#159;', $texte);
496
-	}
491
+    // Caracteres problematiques en iso-latin 1
492
+    if ($GLOBALS['meta']['charset'] == 'iso-8859-1') {
493
+        $texte = str_replace(chr(156), '&#156;', $texte);
494
+        $texte = str_replace(chr(140), '&#140;', $texte);
495
+        $texte = str_replace(chr(159), '&#159;', $texte);
496
+    }
497 497
 
498
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
499
-	// et le caractere apostrophe alourdit les squelettes avec PHP
500
-	// ==> on les remplace par l'entite HTML
501
-	return str_replace($apostrophe, "'", $texte);
498
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
499
+    // et le caractere apostrophe alourdit les squelettes avec PHP
500
+    // ==> on les remplace par l'entite HTML
501
+    return str_replace($apostrophe, "'", $texte);
502 502
 }
503 503
 
504 504
 // Comme ci-dessus, mais avec addslashes final pour squelettes avec PHP (rss)
505 505
 
506 506
 function texte_backendq($texte) {
507
-	return addslashes(texte_backend($texte));
507
+    return addslashes(texte_backend($texte));
508 508
 }
509 509
 
510 510
 // Enleve le numero des titres numerotes ("1. Titre" -> "Titre")
511 511
 // http://doc.spip.org/@supprimer_numero
512 512
 function supprimer_numero($texte) {
513
-	return preg_replace(
514
-	",^[[:space:]]*([0-9]+)([.)]|".chr(194).'?'.chr(176).")[[:space:]]+,S",
515
-	"", $texte);
513
+    return preg_replace(
514
+    ",^[[:space:]]*([0-9]+)([.)]|".chr(194).'?'.chr(176).")[[:space:]]+,S",
515
+    "", $texte);
516 516
 }
517 517
 
518 518
 // et la fonction inverse
519 519
 // http://doc.spip.org/@recuperer_numero
520 520
 function recuperer_numero($texte) {
521
-	if (preg_match(
522
-	",^[[:space:]]*([0-9]+)([.)]|".chr(194).'?'.chr(176).")[[:space:]]+,S",
523
-	$texte, $regs))
524
-		return strval($regs[1]);
525
-	else
526
-		return '';
521
+    if (preg_match(
522
+    ",^[[:space:]]*([0-9]+)([.)]|".chr(194).'?'.chr(176).")[[:space:]]+,S",
523
+    $texte, $regs))
524
+        return strval($regs[1]);
525
+    else
526
+        return '';
527 527
 }
528 528
 
529 529
 // Suppression basique et brutale de tous les <...>
530 530
 // http://doc.spip.org/@supprimer_tags
531 531
 function supprimer_tags($texte, $rempl = "") {
532
-	$texte = preg_replace(",<[^>]*>,US", $rempl, $texte);
533
-	// ne pas oublier un < final non ferme
534
-	// mais qui peut aussi etre un simple signe plus petit que
535
-	$texte = str_replace('<', ' ', $texte);
536
-	return $texte;
532
+    $texte = preg_replace(",<[^>]*>,US", $rempl, $texte);
533
+    // ne pas oublier un < final non ferme
534
+    // mais qui peut aussi etre un simple signe plus petit que
535
+    $texte = str_replace('<', ' ', $texte);
536
+    return $texte;
537 537
 }
538 538
 
539 539
 // Convertit les <...> en la version lisible en HTML
540 540
 // http://doc.spip.org/@echapper_tags
541 541
 function echapper_tags($texte, $rempl = "") {
542
-	$texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
543
-	return $texte;
542
+    $texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
543
+    return $texte;
544 544
 }
545 545
 
546 546
 // Convertit un texte HTML en texte brut
547 547
 // http://doc.spip.org/@textebrut
548 548
 function textebrut($texte) {
549
-	$u = $GLOBALS['meta']['pcre_u'];
550
-	$texte = preg_replace('/\s+/S'.$u, " ", $texte);
551
-	$texte = preg_replace("/<(p|br)( [^>]*)?".">/iS", "\n\n", $texte);
552
-	$texte = preg_replace("/^\n+/", "", $texte);
553
-	$texte = preg_replace("/\n+$/", "", $texte);
554
-	$texte = preg_replace("/\n +/", "\n", $texte);
555
-	$texte = supprimer_tags($texte);
556
-	$texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
557
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
558
-	$texte = str_replace("&#8217;","'",$texte);
559
-	return $texte;
549
+    $u = $GLOBALS['meta']['pcre_u'];
550
+    $texte = preg_replace('/\s+/S'.$u, " ", $texte);
551
+    $texte = preg_replace("/<(p|br)( [^>]*)?".">/iS", "\n\n", $texte);
552
+    $texte = preg_replace("/^\n+/", "", $texte);
553
+    $texte = preg_replace("/\n+$/", "", $texte);
554
+    $texte = preg_replace("/\n +/", "\n", $texte);
555
+    $texte = supprimer_tags($texte);
556
+    $texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
557
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
558
+    $texte = str_replace("&#8217;","'",$texte);
559
+    return $texte;
560 560
 }
561 561
 
562 562
 // Remplace les liens SPIP en liens ouvrant dans une nouvelle fenetre (target=blank)
563 563
 // http://doc.spip.org/@liens_ouvrants
564 564
 function liens_ouvrants ($texte) {
565
-	return preg_replace(",<a\s+([^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+)>,",
566
-		"<a \\1 target=\"_blank\">", $texte);
565
+    return preg_replace(",<a\s+([^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+)>,",
566
+        "<a \\1 target=\"_blank\">", $texte);
567 567
 }
568 568
 
569 569
 /**
@@ -572,31 +572,31 @@  discard block
 block discarded – undo
572 572
  * @return string
573 573
  */
574 574
 function liens_nofollow($texte) {
575
-	if (stripos($texte,"<a")===false)
576
-		return $texte;
575
+    if (stripos($texte,"<a")===false)
576
+        return $texte;
577 577
 
578
-	if (preg_match_all(",<a\b[^>]*>,UimsS",$texte, $regs, PREG_PATTERN_ORDER)){
579
-		foreach($regs[0] as $a){
580
-			$rel = extraire_attribut($a,"rel");
581
-			if (strpos($rel,"nofollow")===false){
582
-				$rel = "nofollow" . ($rel?" $rel":"");
583
-				$anofollow = inserer_attribut($a,"rel",$rel);
584
-				$texte = str_replace($a,$anofollow,$texte);
585
-			}
586
-		}
587
-	}
578
+    if (preg_match_all(",<a\b[^>]*>,UimsS",$texte, $regs, PREG_PATTERN_ORDER)){
579
+        foreach($regs[0] as $a){
580
+            $rel = extraire_attribut($a,"rel");
581
+            if (strpos($rel,"nofollow")===false){
582
+                $rel = "nofollow" . ($rel?" $rel":"");
583
+                $anofollow = inserer_attribut($a,"rel",$rel);
584
+                $texte = str_replace($a,$anofollow,$texte);
585
+            }
586
+        }
587
+    }
588 588
 
589
-	return $texte;
589
+    return $texte;
590 590
 }
591 591
 
592 592
 // Transformer les sauts de paragraphe en simples passages a la ligne
593 593
 // http://doc.spip.org/@PtoBR
594 594
 function PtoBR($texte){
595
-	$u = $GLOBALS['meta']['pcre_u'];
596
-	$texte = preg_replace("@</p>@iS", "\n", $texte);
597
-	$texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
598
-	$texte = preg_replace("@^\s*<br />@S".$u, "", $texte);
599
-	return $texte;
595
+    $u = $GLOBALS['meta']['pcre_u'];
596
+    $texte = preg_replace("@</p>@iS", "\n", $texte);
597
+    $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
598
+    $texte = preg_replace("@^\s*<br />@S".$u, "", $texte);
599
+    return $texte;
600 600
 }
601 601
 
602 602
 
@@ -616,98 +616,98 @@  discard block
 block discarded – undo
616 616
  * @return string
617 617
  */
618 618
 function lignes_longues($texte) {
619
-	if (!strlen(trim($texte))) return $texte;
620
-	include_spip('inc/texte');
621
-	$tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ?
622
-		'div' : 'span';
619
+    if (!strlen(trim($texte))) return $texte;
620
+    include_spip('inc/texte');
621
+    $tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ?
622
+        'div' : 'span';
623 623
 
624
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
624
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
625 625
 }
626 626
 
627 627
 // Majuscules y compris accents, en HTML
628 628
 // http://doc.spip.org/@majuscules
629 629
 function majuscules($texte) {
630
-	if (!strlen($texte)) return '';
630
+    if (!strlen($texte)) return '';
631 631
 
632
-	// Cas du turc
633
-	if ($GLOBALS['spip_lang'] == 'tr') {
634
-		# remplacer hors des tags et des entites
635
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER))
636
-			foreach ($regs as $n => $match)
637
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
632
+    // Cas du turc
633
+    if ($GLOBALS['spip_lang'] == 'tr') {
634
+        # remplacer hors des tags et des entites
635
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER))
636
+            foreach ($regs as $n => $match)
637
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
638 638
 
639
-		$texte = str_replace('i', '&#304;', $texte);
639
+        $texte = str_replace('i', '&#304;', $texte);
640 640
 
641
-		if ($regs)
642
-			foreach ($regs as $n => $match)
643
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
644
-	}
641
+        if ($regs)
642
+            foreach ($regs as $n => $match)
643
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
644
+    }
645 645
 
646
-	// Cas general
647
-	return "<span style='text-transform: uppercase;'>$texte</span>";
646
+    // Cas general
647
+    return "<span style='text-transform: uppercase;'>$texte</span>";
648 648
 }
649 649
 
650 650
 // "127.4 ko" ou "3.1 Mo"
651 651
 // http://doc.spip.org/@taille_en_octets
652 652
 function taille_en_octets ($taille) {
653
-	if ($taille < 1) return '';
654
-	if ($taille < 1024) {$taille = _T('taille_octets', array('taille' => $taille));}
655
-	else if ($taille < 1024*1024) {
656
-		$taille = _T('taille_ko', array('taille' => round($taille/1024, 1)));
657
-	} else if ($taille < 1024*1024*1024) {
658
-		$taille = _T('taille_mo', array('taille' => round($taille/1024/1024, 1)));
659
-	} else {
660
-		$taille = _T('taille_go', array('taille' => round($taille/1024/1024/1024, 2)));
661
-	}
662
-	return $taille;
653
+    if ($taille < 1) return '';
654
+    if ($taille < 1024) {$taille = _T('taille_octets', array('taille' => $taille));}
655
+    else if ($taille < 1024*1024) {
656
+        $taille = _T('taille_ko', array('taille' => round($taille/1024, 1)));
657
+    } else if ($taille < 1024*1024*1024) {
658
+        $taille = _T('taille_mo', array('taille' => round($taille/1024/1024, 1)));
659
+    } else {
660
+        $taille = _T('taille_go', array('taille' => round($taille/1024/1024/1024, 2)));
661
+    }
662
+    return $taille;
663 663
 }
664 664
 
665 665
 
666 666
 // Rend une chaine utilisable sans dommage comme attribut HTML
667 667
 // http://doc.spip.org/@attribut_html
668 668
 function attribut_html($texte,$textebrut = true) {
669
-	$u = $GLOBALS['meta']['pcre_u'];
670
-	if ($textebrut)
671
-		$texte = preg_replace(array(",\n,",",\s(?=\s),msS".$u),array(" ",""),textebrut($texte));
672
-	$texte = texte_backend($texte);
673
-	$texte = str_replace(array("'",'"'),array('&#039;', '&#034;'), $texte);
669
+    $u = $GLOBALS['meta']['pcre_u'];
670
+    if ($textebrut)
671
+        $texte = preg_replace(array(",\n,",",\s(?=\s),msS".$u),array(" ",""),textebrut($texte));
672
+    $texte = texte_backend($texte);
673
+    $texte = str_replace(array("'",'"'),array('&#039;', '&#034;'), $texte);
674 674
 	
675
-	return preg_replace(array("/&(amp;|#38;)/","/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"),array("&","&#38;") , $texte);
675
+    return preg_replace(array("/&(amp;|#38;)/","/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"),array("&","&#38;") , $texte);
676 676
 }
677 677
 
678 678
 // Vider les url nulles comme 'http://' ou 'mailto:'
679 679
 // et leur appliquer un htmlspecialchars() + gerer les &amp;
680 680
 // http://doc.spip.org/@vider_url
681 681
 function vider_url($url, $entites = true) {
682
-	# un message pour abs_url
683
-	$GLOBALS['mode_abs_url'] = 'url';
684
-	$url = trim($url);
685
-	$r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
686
-	return preg_match($r, $url) ? '': ($entites ? entites_html($url) : $url);
682
+    # un message pour abs_url
683
+    $GLOBALS['mode_abs_url'] = 'url';
684
+    $url = trim($url);
685
+    $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
686
+    return preg_match($r, $url) ? '': ($entites ? entites_html($url) : $url);
687 687
 }
688 688
 
689 689
 // Extraire une date de n'importe quel champ (a completer...)
690 690
 // http://doc.spip.org/@extraire_date
691 691
 function extraire_date($texte) {
692
-	// format = 2001-08
693
-	if (preg_match(",([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),",$texte,$regs))
694
-		return $regs[1]."-".sprintf("%02d", $regs[2])."-01";
692
+    // format = 2001-08
693
+    if (preg_match(",([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),",$texte,$regs))
694
+        return $regs[1]."-".sprintf("%02d", $regs[2])."-01";
695 695
 }
696 696
 
697 697
 // Maquiller une adresse e-mail
698 698
 // http://doc.spip.org/@antispam
699 699
 function antispam($texte) {
700
-	include_spip('inc/acces');
701
-	$masque = creer_pass_aleatoire(3);
702
-	return preg_replace("/@/", " $masque ", $texte);
700
+    include_spip('inc/acces');
701
+    $masque = creer_pass_aleatoire(3);
702
+    return preg_replace("/@/", " $masque ", $texte);
703 703
 }
704 704
 
705 705
 // http://doc.spip.org/@securiser_acces
706 706
 function securiser_acces($id_auteur, $cle, $dir, $op='', $args='')
707 707
 {
708
-	include_spip('inc/acces');
709
-	if ($op) $dir .= " $op $args";
710
-	return verifier_low_sec($id_auteur, $cle, $dir);
708
+    include_spip('inc/acces');
709
+    if ($op) $dir .= " $op $args";
710
+    return verifier_low_sec($id_auteur, $cle, $dir);
711 711
 }
712 712
 
713 713
 /**
@@ -728,22 +728,22 @@  discard block
 block discarded – undo
728 728
  * 		Retourne $texte, sinon $sinon.
729 729
 **/
730 730
 function sinon ($texte, $sinon='') {
731
-	if ($texte OR (!is_array($texte) AND strlen($texte)))
732
-		return $texte;
733
-	else
734
-		return $sinon;
731
+    if ($texte OR (!is_array($texte) AND strlen($texte)))
732
+        return $texte;
733
+    else
734
+        return $sinon;
735 735
 }
736 736
 
737 737
 // |choixsivide{vide,pasvide} affiche pasvide si la chaine n'est pas vide...
738 738
 // http://doc.spip.org/@choixsivide
739 739
 function choixsivide($a, $vide, $pasvide) {
740
-	return $a ? $pasvide : $vide;
740
+    return $a ? $pasvide : $vide;
741 741
 }
742 742
 
743 743
 // |choixsiegal{aquoi,oui,non} affiche oui si la chaine est egal a aquoi ...
744 744
 // http://doc.spip.org/@choixsiegal
745 745
 function choixsiegal($a1,$a2,$v,$f) {
746
-	return ($a1 == $a2) ? $v : $f;
746
+    return ($a1 == $a2) ? $v : $f;
747 747
 }
748 748
 
749 749
 
@@ -754,224 +754,224 @@  discard block
 block discarded – undo
754 754
 // on normalise la date, si elle vient du contexte (public/parametrer.php), on force le jour
755 755
 // http://doc.spip.org/@normaliser_date
756 756
 function normaliser_date($date, $forcer_jour = false) {
757
-	$date = vider_date($date);
758
-	if ($date) {
759
-		if (preg_match("/^[0-9]{8,10}$/", $date))
760
-			$date = date("Y-m-d H:i:s", $date);
761
-		if (preg_match("#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#", $date, $regs))
762
-			$date = $regs[1]."-00-00".$regs[3];
763
-		else if (preg_match("#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#", $date, $regs))
764
-			$date = preg_replace("@/@","-",$regs[1])."-00".$regs[3];
765
-		else
766
-			$date = date("Y-m-d H:i:s", strtotime($date));
767
-
768
-		if ($forcer_jour)
769
-			$date = str_replace('-00', '-01', $date);
770
-	}
771
-	return $date;
757
+    $date = vider_date($date);
758
+    if ($date) {
759
+        if (preg_match("/^[0-9]{8,10}$/", $date))
760
+            $date = date("Y-m-d H:i:s", $date);
761
+        if (preg_match("#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#", $date, $regs))
762
+            $date = $regs[1]."-00-00".$regs[3];
763
+        else if (preg_match("#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#", $date, $regs))
764
+            $date = preg_replace("@/@","-",$regs[1])."-00".$regs[3];
765
+        else
766
+            $date = date("Y-m-d H:i:s", strtotime($date));
767
+
768
+        if ($forcer_jour)
769
+            $date = str_replace('-00', '-01', $date);
770
+    }
771
+    return $date;
772 772
 }
773 773
 
774 774
 // http://doc.spip.org/@vider_date
775 775
 function vider_date($letexte) {
776
-	if (strncmp("0000-00-00", $letexte,10)==0) return '';
777
-	if (strncmp("0001-01-01", $letexte,10)==0) return '';
778
-	if (strncmp("1970-01-01", $letexte,10)==0) return '';	// eviter le bug GMT-1
779
-	return $letexte;
776
+    if (strncmp("0000-00-00", $letexte,10)==0) return '';
777
+    if (strncmp("0001-01-01", $letexte,10)==0) return '';
778
+    if (strncmp("1970-01-01", $letexte,10)==0) return '';	// eviter le bug GMT-1
779
+    return $letexte;
780 780
 }
781 781
 
782 782
 // http://doc.spip.org/@recup_heure
783 783
 function recup_heure($date){
784 784
 
785
-	static $d = array(0,0,0);
786
-	if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) 
787
-		return $d;
785
+    static $d = array(0,0,0);
786
+    if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) 
787
+        return $d;
788 788
 	
789
-	array_shift($r);
790
-	return $r;
789
+    array_shift($r);
790
+    return $r;
791 791
 }
792 792
 
793 793
 // http://doc.spip.org/@heures
794 794
 function heures($numdate) {
795
-	$date_array = recup_heure($numdate);
796
-	if ($date_array)
797
-		list($heures, $minutes, $secondes) = $date_array;
798
-	return $heures;
795
+    $date_array = recup_heure($numdate);
796
+    if ($date_array)
797
+        list($heures, $minutes, $secondes) = $date_array;
798
+    return $heures;
799 799
 }
800 800
 
801 801
 // http://doc.spip.org/@minutes
802 802
 function minutes($numdate) {
803
-	$date_array = recup_heure($numdate);
804
-	if ($date_array)
805
-		list($heures, $minutes, $secondes) = $date_array;
806
-	return $minutes;
803
+    $date_array = recup_heure($numdate);
804
+    if ($date_array)
805
+        list($heures, $minutes, $secondes) = $date_array;
806
+    return $minutes;
807 807
 }
808 808
 
809 809
 // http://doc.spip.org/@secondes
810 810
 function secondes($numdate) {
811
-	$date_array = recup_heure($numdate);
812
-	if ($date_array)
813
-		list($heures,$minutes,$secondes) = $date_array;
814
-	return $secondes;
811
+    $date_array = recup_heure($numdate);
812
+    if ($date_array)
813
+        list($heures,$minutes,$secondes) = $date_array;
814
+    return $secondes;
815 815
 }
816 816
 
817 817
 // http://doc.spip.org/@heures_minutes
818 818
 function heures_minutes($numdate) {
819
-	return _T('date_fmt_heures_minutes', array('h'=> heures($numdate), 'm'=> minutes($numdate)));
819
+    return _T('date_fmt_heures_minutes', array('h'=> heures($numdate), 'm'=> minutes($numdate)));
820 820
 }
821 821
 
822 822
 // http://doc.spip.org/@recup_date
823 823
 function recup_date($numdate, $forcer_jour = true){
824
-	if (!$numdate) return '';
825
-	$heures = $minutes = $secondes = 0;
826
-	if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) {
827
-		$jour = $regs[1];
828
-		$mois = $regs[2];
829
-		$annee = $regs[3];
830
-		if ($annee < 90){
831
-			$annee = 2000 + $annee;
832
-		} elseif ($annee<100) {
833
-			$annee = 1900 + $annee ;
834
-		}
835
-		list($heures, $minutes, $secondes) = recup_heure($numdate);
836
-
837
-	}
838
-	elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#',$numdate, $regs)) {
839
-		$annee = $regs[1];
840
-		$mois = $regs[2];
841
-		$jour = $regs[3];
842
-		list($heures, $minutes, $secondes) = recup_heure($numdate);
843
-	}
844
-	elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)){
845
-		$annee = $regs[1];
846
-		$mois = $regs[2];
847
-		$jour ='';
848
-		list($heures, $minutes, $secondes) = recup_heure($numdate);
849
-	}
850
-	elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)){
851
-		$annee = $regs[1];
852
-		$mois = $regs[2];
853
-		$jour = $regs[3];
854
-		$heures = $regs[4];
855
-		$minutes = $regs[5];
856
-		$secondes = $regs[6];
857
-	} else $annee = $mois =  $jour =''; 
858
-	if ($annee > 4000) $annee -= 9000;
859
-	if (substr($jour, 0, 1) == '0') $jour = substr($jour, 1);
860
-
861
-	if ($forcer_jour AND $jour == '0') $jour = '1';
862
-	if ($forcer_jour AND $mois == '0') $mois = '1';
863
-	if ($annee OR $mois OR $jour OR $heures OR $minutes OR $secondes)
864
-		return array($annee, $mois, $jour, $heures, $minutes, $secondes);
824
+    if (!$numdate) return '';
825
+    $heures = $minutes = $secondes = 0;
826
+    if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) {
827
+        $jour = $regs[1];
828
+        $mois = $regs[2];
829
+        $annee = $regs[3];
830
+        if ($annee < 90){
831
+            $annee = 2000 + $annee;
832
+        } elseif ($annee<100) {
833
+            $annee = 1900 + $annee ;
834
+        }
835
+        list($heures, $minutes, $secondes) = recup_heure($numdate);
836
+
837
+    }
838
+    elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#',$numdate, $regs)) {
839
+        $annee = $regs[1];
840
+        $mois = $regs[2];
841
+        $jour = $regs[3];
842
+        list($heures, $minutes, $secondes) = recup_heure($numdate);
843
+    }
844
+    elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)){
845
+        $annee = $regs[1];
846
+        $mois = $regs[2];
847
+        $jour ='';
848
+        list($heures, $minutes, $secondes) = recup_heure($numdate);
849
+    }
850
+    elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)){
851
+        $annee = $regs[1];
852
+        $mois = $regs[2];
853
+        $jour = $regs[3];
854
+        $heures = $regs[4];
855
+        $minutes = $regs[5];
856
+        $secondes = $regs[6];
857
+    } else $annee = $mois =  $jour =''; 
858
+    if ($annee > 4000) $annee -= 9000;
859
+    if (substr($jour, 0, 1) == '0') $jour = substr($jour, 1);
860
+
861
+    if ($forcer_jour AND $jour == '0') $jour = '1';
862
+    if ($forcer_jour AND $mois == '0') $mois = '1';
863
+    if ($annee OR $mois OR $jour OR $heures OR $minutes OR $secondes)
864
+        return array($annee, $mois, $jour, $heures, $minutes, $secondes);
865 865
 }
866 866
 
867 867
 // une date pour l'interface : utilise date_relative si le decalage
868 868
 // avec time() est de moins de douze heures, sinon la date complete
869 869
 // http://doc.spip.org/@date_interface
870 870
 function date_interface($date, $decalage_maxi = 43200/* 12*3600 */) {
871
-	return sinon(
872
-		date_relative($date, $decalage_maxi),
873
-		affdate_heure($date)
874
-	);
871
+    return sinon(
872
+        date_relative($date, $decalage_maxi),
873
+        affdate_heure($date)
874
+    );
875 875
 }
876 876
 
877 877
 // http://doc.spip.org/@date_relative
878 878
 function date_relative($date, $decalage_maxi=0,$ref_date=null) {
879 879
 	
880
-	if (is_null($ref_date))
881
-		$ref_time = time();
882
-	else
883
-		$ref_time = strtotime($ref_date);
880
+    if (is_null($ref_date))
881
+        $ref_time = time();
882
+    else
883
+        $ref_time = strtotime($ref_date);
884 884
 	
885
-	if (!$date) return;
886
-	$decal = date("U",$ref_time) - date("U", strtotime($date));
887
-
888
-	if ($decalage_maxi AND ($decal > $decalage_maxi OR $decal < 0))
889
-		return '';
890
-
891
-	if ($decal < 0) {
892
-		$il_y_a = "date_dans";
893
-		$decal = -1 * $decal;
894
-	} else {
895
-		$il_y_a = "date_il_y_a";
896
-	}
897
-
898
-	if ($decal > 3600 * 24 * 30 * 6)
899
-		return affdate_court($date);
900
-
901
-	if ($decal > 3600 * 24 * 30) {
902
-		$mois = floor ($decal / (3600 * 24 * 30));
903
-		if ($mois < 2)
904
-			$delai = "$mois "._T("date_un_mois");
905
-		else
906
-			$delai = "$mois "._T("date_mois");
907
-	}
908
-	else if ($decal > 3600 * 24 * 7) {
909
-		$semaines = floor ($decal / (3600 * 24 * 7));
910
-		if ($semaines < 2)
911
-			$delai = "$semaines "._T("date_une_semaine");
912
-		else
913
-			$delai = "$semaines "._T("date_semaines");
914
-	}
915
-	else if ($decal > 3600 * 24) {
916
-		$jours = floor ($decal / (3600 * 24));
917
-		if ($jours < 2)
918
-			return $il_y_a=="date_dans"?_T("date_demain"):_T("date_hier");
919
-		else
920
-			$delai = "$jours "._T("date_jours");
921
-	}
922
-	else if ($decal >= 3600) {
923
-		$heures = floor ($decal / 3600);
924
-		if ($heures < 2)
925
-			$delai = "$heures "._T("date_une_heure");
926
-		else
927
-			$delai = "$heures "._T("date_heures");
928
-	}
929
-	else if ($decal >= 60) {
930
-		$minutes = floor($decal / 60);
931
-		if ($minutes < 2)
932
-			$delai = "$minutes "._T("date_une_minute");
933
-		else
934
-			$delai = "$minutes "._T("date_minutes");
935
-	} else {
936
-		$secondes = ceil($decal);
937
-		if ($secondes < 2)
938
-			$delai = "$secondes "._T("date_une_seconde");
939
-		else
940
-			$delai = "$secondes "._T("date_secondes");
941
-	}
942
-
943
-	return _T($il_y_a, array("delai"=> $delai));
885
+    if (!$date) return;
886
+    $decal = date("U",$ref_time) - date("U", strtotime($date));
887
+
888
+    if ($decalage_maxi AND ($decal > $decalage_maxi OR $decal < 0))
889
+        return '';
890
+
891
+    if ($decal < 0) {
892
+        $il_y_a = "date_dans";
893
+        $decal = -1 * $decal;
894
+    } else {
895
+        $il_y_a = "date_il_y_a";
896
+    }
897
+
898
+    if ($decal > 3600 * 24 * 30 * 6)
899
+        return affdate_court($date);
900
+
901
+    if ($decal > 3600 * 24 * 30) {
902
+        $mois = floor ($decal / (3600 * 24 * 30));
903
+        if ($mois < 2)
904
+            $delai = "$mois "._T("date_un_mois");
905
+        else
906
+            $delai = "$mois "._T("date_mois");
907
+    }
908
+    else if ($decal > 3600 * 24 * 7) {
909
+        $semaines = floor ($decal / (3600 * 24 * 7));
910
+        if ($semaines < 2)
911
+            $delai = "$semaines "._T("date_une_semaine");
912
+        else
913
+            $delai = "$semaines "._T("date_semaines");
914
+    }
915
+    else if ($decal > 3600 * 24) {
916
+        $jours = floor ($decal / (3600 * 24));
917
+        if ($jours < 2)
918
+            return $il_y_a=="date_dans"?_T("date_demain"):_T("date_hier");
919
+        else
920
+            $delai = "$jours "._T("date_jours");
921
+    }
922
+    else if ($decal >= 3600) {
923
+        $heures = floor ($decal / 3600);
924
+        if ($heures < 2)
925
+            $delai = "$heures "._T("date_une_heure");
926
+        else
927
+            $delai = "$heures "._T("date_heures");
928
+    }
929
+    else if ($decal >= 60) {
930
+        $minutes = floor($decal / 60);
931
+        if ($minutes < 2)
932
+            $delai = "$minutes "._T("date_une_minute");
933
+        else
934
+            $delai = "$minutes "._T("date_minutes");
935
+    } else {
936
+        $secondes = ceil($decal);
937
+        if ($secondes < 2)
938
+            $delai = "$secondes "._T("date_une_seconde");
939
+        else
940
+            $delai = "$secondes "._T("date_secondes");
941
+    }
942
+
943
+    return _T($il_y_a, array("delai"=> $delai));
944 944
 }
945 945
 
946 946
 
947 947
 // http://doc.spip.org/@date_relativecourt
948 948
 function date_relativecourt($date, $decalage_maxi=0) {
949 949
 	
950
-	if (!$date) return;
951
-	$decal = date("U",strtotime(date('Y-m-d'))-strtotime(date('Y-m-d',strtotime($date))));
950
+    if (!$date) return;
951
+    $decal = date("U",strtotime(date('Y-m-d'))-strtotime(date('Y-m-d',strtotime($date))));
952 952
 
953
-	if ($decalage_maxi AND ($decal > $decalage_maxi OR $decal < 0))
954
-		return '';
953
+    if ($decalage_maxi AND ($decal > $decalage_maxi OR $decal < 0))
954
+        return '';
955 955
 
956
-	if ($decal < -24*3600) {
957
-		$retour = date_relative($date, $decalage_maxi);
958
-	}
959
-	elseif ($decal < 0) {
960
-		$retour = _T("date_demain");
961
-	}
962
-	else if ($decal < (3600 * 24) ) {
963
-		$retour = _T("date_aujourdhui");
964
-	}
965
-	else if ($decal < (3600 * 24 *2) ) {
966
-		$retour = _T("date_hier");
967
-	}
968
-	else {
969
-		$retour = date_relative($date, $decalage_maxi);
970
-	}
956
+    if ($decal < -24*3600) {
957
+        $retour = date_relative($date, $decalage_maxi);
958
+    }
959
+    elseif ($decal < 0) {
960
+        $retour = _T("date_demain");
961
+    }
962
+    else if ($decal < (3600 * 24) ) {
963
+        $retour = _T("date_aujourdhui");
964
+    }
965
+    else if ($decal < (3600 * 24 *2) ) {
966
+        $retour = _T("date_hier");
967
+    }
968
+    else {
969
+        $retour = date_relative($date, $decalage_maxi);
970
+    }
971 971
 
972 972
 
973 973
 
974
-	return $retour;
974
+    return $retour;
975 975
 }
976 976
 
977 977
 /**
@@ -986,183 +986,183 @@  discard block
 block discarded – undo
986 986
  * @return mixed|string
987 987
  */
988 988
 function affdate_base($numdate, $vue, $options = array()) {
989
-	if (is_string($options))
990
-		$options = array('param'=>$options);
991
-	$date_array = recup_date($numdate, false);
992
-	if (!$date_array) return;
993
-	list($annee, $mois, $jour, $heures, $minutes, $secondes)= $date_array;
994
-
995
-	// 1er, 21st, etc.
996
-	$journum = $jour;
997
-
998
-	if ($jour == 0) {
999
-		$jour = '';
1000
-	} else {
1001
-		$njour = intval($jour);
1002
-		if ($jourth = _T('date_jnum'.$jour))
1003
-			$jour = $jourth;
1004
-	}
1005
-
1006
-	$mois = intval($mois);
1007
-	if ($mois > 0 AND $mois < 13) {
1008
-		$nommois = _T('date_mois_'.$mois);
1009
-		if ($jour)
1010
-			$jourmois = _T('date_de_mois_'.$mois, array('j'=>$jour, 'nommois'=>$nommois));
1011
-		else
1012
-			$jourmois = $nommois;
1013
-	} else $nommois = '';
1014
-
1015
-	if ($annee < 0) {
1016
-		$annee = -$annee." "._T('date_avant_jc');
1017
-		$avjc = true;
1018
-	}
1019
-	else $avjc = false;
1020
-
1021
-	switch ($vue) {
1022
-	case 'saison':
1023
-	case 'saison_annee':
1024
-		$saison = '';
1025
-		if ($mois > 0){
1026
-			$saison = 1;
1027
-			if (($mois == 3 AND $jour >= 21) OR $mois > 3) $saison = 2;
1028
-			if (($mois == 6 AND $jour >= 21) OR $mois > 6) $saison = 3;
1029
-			if (($mois == 9 AND $jour >= 21) OR $mois > 9) $saison = 4;
1030
-			if (($mois == 12 AND $jour >= 21) OR $mois > 12) $saison = 1;
1031
-		}
1032
-		if($vue == 'saison')
1033
-			return $saison?_T('date_saison_'.$saison):'';
1034
-		else
1035
-			return $saison?trim(_T('date_fmt_saison_annee', array('saison'=>_T('date_saison_'.$saison), 'annee'=>$annee))) :'';
1036
-
1037
-	case 'court':
1038
-		if ($avjc) return $annee;
1039
-		$a = ((isset($options['annee_courante']) AND $options['annee_courante'])?$options['annee_courante']:date('Y'));
1040
-		if ($annee < ($a - 100) OR $annee > ($a + 100)) return $annee;
1041
-		if ($annee != $a) return _T('date_fmt_mois_annee', array ('mois'=>$mois, 'nommois'=>spip_ucfirst($nommois), 'annee'=>$annee));
1042
-		return _T('date_fmt_jour_mois', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1043
-
1044
-	case 'jourcourt':
1045
-		if ($avjc) return $annee;
1046
-		$a = ((isset($options['annee_courante']) AND $options['annee_courante'])?$options['annee_courante']:date('Y'));
1047
-		if ($annee < ($a - 100) OR $annee > ($a + 100)) return $annee;
1048
-		if ($annee != $a) return _T('date_fmt_jour_mois_annee', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1049
-		return _T('date_fmt_jour_mois', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1050
-
1051
-	case 'entier':
1052
-		if ($avjc) return $annee;
1053
-		if ($jour)
1054
-			return _T('date_fmt_jour_mois_annee', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1055
-		elseif ($mois)
1056
-			return trim(_T('date_fmt_mois_annee', array ('mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)));
1057
-		else
1058
-			return $annee;
1059
-
1060
-	case 'nom_mois':
1061
-		$param = ((isset($options['param']) AND $options['param']) ? '_'.$options['param'] : '');
1062
-		if ($param and $mois) {
1063
-			return _T('date_mois_'.$mois.$param);
1064
-		}
1065
-		return $nommois;
1066
-
1067
-	case 'mois':
1068
-		return sprintf("%02s",$mois);
1069
-
1070
-	case 'jour':
1071
-		return $jour;
1072
-
1073
-	case 'journum':
1074
-		return $journum;
1075
-
1076
-	case 'nom_jour':
1077
-		if (!$mois OR !$njour)
1078
-			return '';
1079
-		$nom = mktime(1,1,1,$mois,$njour,$annee);
1080
-		$nom = 1+date('w',$nom);
1081
-		$param = ((isset($options['param']) AND $options['param']) ? '_'.$options['param'] : '');
1082
-		return _T('date_jour_'.$nom.$param);
1083
-
1084
-	case 'mois_annee':
1085
-		if ($avjc) return $annee;
1086
-		return trim(_T('date_fmt_mois_annee', array('mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)));
1087
-
1088
-	case 'annee':
1089
-		return $annee;
1090
-
1091
-	// Cas d'une vue non definie : retomber sur le format
1092
-	// de date propose par http://www.php.net/date
1093
-	default:
1094
-		return date($vue, strtotime($numdate));
1095
-	}
989
+    if (is_string($options))
990
+        $options = array('param'=>$options);
991
+    $date_array = recup_date($numdate, false);
992
+    if (!$date_array) return;
993
+    list($annee, $mois, $jour, $heures, $minutes, $secondes)= $date_array;
994
+
995
+    // 1er, 21st, etc.
996
+    $journum = $jour;
997
+
998
+    if ($jour == 0) {
999
+        $jour = '';
1000
+    } else {
1001
+        $njour = intval($jour);
1002
+        if ($jourth = _T('date_jnum'.$jour))
1003
+            $jour = $jourth;
1004
+    }
1005
+
1006
+    $mois = intval($mois);
1007
+    if ($mois > 0 AND $mois < 13) {
1008
+        $nommois = _T('date_mois_'.$mois);
1009
+        if ($jour)
1010
+            $jourmois = _T('date_de_mois_'.$mois, array('j'=>$jour, 'nommois'=>$nommois));
1011
+        else
1012
+            $jourmois = $nommois;
1013
+    } else $nommois = '';
1014
+
1015
+    if ($annee < 0) {
1016
+        $annee = -$annee." "._T('date_avant_jc');
1017
+        $avjc = true;
1018
+    }
1019
+    else $avjc = false;
1020
+
1021
+    switch ($vue) {
1022
+    case 'saison':
1023
+    case 'saison_annee':
1024
+        $saison = '';
1025
+        if ($mois > 0){
1026
+            $saison = 1;
1027
+            if (($mois == 3 AND $jour >= 21) OR $mois > 3) $saison = 2;
1028
+            if (($mois == 6 AND $jour >= 21) OR $mois > 6) $saison = 3;
1029
+            if (($mois == 9 AND $jour >= 21) OR $mois > 9) $saison = 4;
1030
+            if (($mois == 12 AND $jour >= 21) OR $mois > 12) $saison = 1;
1031
+        }
1032
+        if($vue == 'saison')
1033
+            return $saison?_T('date_saison_'.$saison):'';
1034
+        else
1035
+            return $saison?trim(_T('date_fmt_saison_annee', array('saison'=>_T('date_saison_'.$saison), 'annee'=>$annee))) :'';
1036
+
1037
+    case 'court':
1038
+        if ($avjc) return $annee;
1039
+        $a = ((isset($options['annee_courante']) AND $options['annee_courante'])?$options['annee_courante']:date('Y'));
1040
+        if ($annee < ($a - 100) OR $annee > ($a + 100)) return $annee;
1041
+        if ($annee != $a) return _T('date_fmt_mois_annee', array ('mois'=>$mois, 'nommois'=>spip_ucfirst($nommois), 'annee'=>$annee));
1042
+        return _T('date_fmt_jour_mois', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1043
+
1044
+    case 'jourcourt':
1045
+        if ($avjc) return $annee;
1046
+        $a = ((isset($options['annee_courante']) AND $options['annee_courante'])?$options['annee_courante']:date('Y'));
1047
+        if ($annee < ($a - 100) OR $annee > ($a + 100)) return $annee;
1048
+        if ($annee != $a) return _T('date_fmt_jour_mois_annee', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1049
+        return _T('date_fmt_jour_mois', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1050
+
1051
+    case 'entier':
1052
+        if ($avjc) return $annee;
1053
+        if ($jour)
1054
+            return _T('date_fmt_jour_mois_annee', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1055
+        elseif ($mois)
1056
+            return trim(_T('date_fmt_mois_annee', array ('mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)));
1057
+        else
1058
+            return $annee;
1059
+
1060
+    case 'nom_mois':
1061
+        $param = ((isset($options['param']) AND $options['param']) ? '_'.$options['param'] : '');
1062
+        if ($param and $mois) {
1063
+            return _T('date_mois_'.$mois.$param);
1064
+        }
1065
+        return $nommois;
1066
+
1067
+    case 'mois':
1068
+        return sprintf("%02s",$mois);
1069
+
1070
+    case 'jour':
1071
+        return $jour;
1072
+
1073
+    case 'journum':
1074
+        return $journum;
1075
+
1076
+    case 'nom_jour':
1077
+        if (!$mois OR !$njour)
1078
+            return '';
1079
+        $nom = mktime(1,1,1,$mois,$njour,$annee);
1080
+        $nom = 1+date('w',$nom);
1081
+        $param = ((isset($options['param']) AND $options['param']) ? '_'.$options['param'] : '');
1082
+        return _T('date_jour_'.$nom.$param);
1083
+
1084
+    case 'mois_annee':
1085
+        if ($avjc) return $annee;
1086
+        return trim(_T('date_fmt_mois_annee', array('mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)));
1087
+
1088
+    case 'annee':
1089
+        return $annee;
1090
+
1091
+    // Cas d'une vue non definie : retomber sur le format
1092
+    // de date propose par http://www.php.net/date
1093
+    default:
1094
+        return date($vue, strtotime($numdate));
1095
+    }
1096 1096
 }
1097 1097
 
1098 1098
 // http://doc.spip.org/@nom_jour
1099 1099
 function nom_jour($numdate, $forme = '') {
1100
-	if(!($forme == 'abbr' OR $forme == 'initiale')) $forme = '';
1101
-	return affdate_base($numdate, 'nom_jour', $forme);
1100
+    if(!($forme == 'abbr' OR $forme == 'initiale')) $forme = '';
1101
+    return affdate_base($numdate, 'nom_jour', $forme);
1102 1102
 }
1103 1103
 
1104 1104
 // http://doc.spip.org/@jour
1105 1105
 function jour($numdate) {
1106
-	return affdate_base($numdate, 'jour');
1106
+    return affdate_base($numdate, 'jour');
1107 1107
 }
1108 1108
 
1109 1109
 // http://doc.spip.org/@journum
1110 1110
 function journum($numdate) {
1111
-	return affdate_base($numdate, 'journum');
1111
+    return affdate_base($numdate, 'journum');
1112 1112
 }
1113 1113
 
1114 1114
 // http://doc.spip.org/@mois
1115 1115
 function mois($numdate) {
1116
-	return affdate_base($numdate, 'mois');
1116
+    return affdate_base($numdate, 'mois');
1117 1117
 }
1118 1118
 
1119 1119
 // http://doc.spip.org/@nom_mois
1120 1120
 function nom_mois($numdate, $forme='') {
1121
-	if(!($forme == 'abbr')) $forme = '';
1122
-	return affdate_base($numdate, 'nom_mois', $forme);
1121
+    if(!($forme == 'abbr')) $forme = '';
1122
+    return affdate_base($numdate, 'nom_mois', $forme);
1123 1123
 }
1124 1124
 
1125 1125
 // http://doc.spip.org/@annee
1126 1126
 function annee($numdate) {
1127
-	return affdate_base($numdate, 'annee');
1127
+    return affdate_base($numdate, 'annee');
1128 1128
 }
1129 1129
 
1130 1130
 // http://doc.spip.org/@saison
1131 1131
 function saison($numdate) {
1132
-	return affdate_base($numdate, 'saison');
1132
+    return affdate_base($numdate, 'saison');
1133 1133
 }
1134 1134
 
1135 1135
 // http://doc.spip.org/@saison_annee
1136 1136
 function saison_annee($numdate) {
1137
-	return affdate_base($numdate, 'saison_annee');
1137
+    return affdate_base($numdate, 'saison_annee');
1138 1138
 }
1139 1139
 
1140 1140
 // http://doc.spip.org/@affdate
1141 1141
 function affdate($numdate, $format='entier') {
1142
-	return affdate_base($numdate, $format);
1142
+    return affdate_base($numdate, $format);
1143 1143
 }
1144 1144
 
1145 1145
 // http://doc.spip.org/@affdate_court
1146 1146
 function affdate_court($numdate, $annee_courante=null) {
1147
-	return affdate_base($numdate, 'court', array('annee_courante'=>$annee_courante));
1147
+    return affdate_base($numdate, 'court', array('annee_courante'=>$annee_courante));
1148 1148
 }
1149 1149
 
1150 1150
 // http://doc.spip.org/@affdate_jourcourt
1151 1151
 function affdate_jourcourt($numdate, $annee_courante=null) {
1152
-	return affdate_base($numdate, 'jourcourt', array('annee_courante'=>$annee_courante));
1152
+    return affdate_base($numdate, 'jourcourt', array('annee_courante'=>$annee_courante));
1153 1153
 }
1154 1154
 
1155 1155
 // http://doc.spip.org/@affdate_mois_annee
1156 1156
 function affdate_mois_annee($numdate) {
1157
-	return affdate_base($numdate, 'mois_annee');
1157
+    return affdate_base($numdate, 'mois_annee');
1158 1158
 }
1159 1159
 
1160 1160
 // http://doc.spip.org/@affdate_heure
1161 1161
 function affdate_heure($numdate) {
1162
-	$date_array = recup_date($numdate);
1163
-	if (!$date_array) return;
1164
-	list($annee, $mois, $jour, $heures, $minutes, $sec)= $date_array;
1165
-	return _T('date_fmt_jour_heure', array('jour' => affdate($numdate), 'heure' =>  _T('date_fmt_heures_minutes', array('h'=> $heures, 'm'=> $minutes))));
1162
+    $date_array = recup_date($numdate);
1163
+    if (!$date_array) return;
1164
+    list($annee, $mois, $jour, $heures, $minutes, $sec)= $date_array;
1165
+    return _T('date_fmt_jour_heure', array('jour' => affdate($numdate), 'heure' =>  _T('date_fmt_heures_minutes', array('h'=> $heures, 'm'=> $minutes))));
1166 1166
 }
1167 1167
 
1168 1168
 /**
@@ -1190,94 +1190,94 @@  discard block
 block discarded – undo
1190 1190
  * @return string
1191 1191
  */
1192 1192
 function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme=''){
1193
-	$abbr = $jour = '';
1194
-	$affdate = "affdate_jourcourt";
1195
-	if (strpos($forme,'abbr') !==false) $abbr = 'abbr';
1196
-	if (strpos($forme,'annee')!==false) $affdate = 'affdate';
1197
-	if (strpos($forme,'jour') !==false) $jour = 'jour';
1193
+    $abbr = $jour = '';
1194
+    $affdate = "affdate_jourcourt";
1195
+    if (strpos($forme,'abbr') !==false) $abbr = 'abbr';
1196
+    if (strpos($forme,'annee')!==false) $affdate = 'affdate';
1197
+    if (strpos($forme,'jour') !==false) $jour = 'jour';
1198 1198
 	
1199
-	$dtstart = $dtend = $dtabbr = "";
1200
-	if (strpos($forme,'hcal')!==false) {
1201
-		$dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>";
1202
-		$dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>";
1203
-		$dtabbr = "</abbr>";
1204
-	}
1205
-
1206
-	$date_debut = strtotime($date_debut);
1207
-	$date_fin = strtotime($date_fin);
1208
-	$d = date("Y-m-d", $date_debut);
1209
-	$f = date("Y-m-d", $date_fin);
1210
-	$h = ($horaire==='oui' OR $horaire===true);
1211
-	$hd = _T('date_fmt_heures_minutes_court', array('h'=> date("H",$date_debut), 'm'=> date("i",$date_debut)));
1212
-	$hf = _T('date_fmt_heures_minutes_court', array('h'=> date("H",$date_fin), 'm'=> date("i",$date_fin)));
1213
-
1214
-	if ($d==$f)
1215
-	{ // meme jour
1216
-		$nomjour = nom_jour($d,$abbr);
1217
-		$s = $affdate($d);
1218
-		$s = _T('date_fmt_jour',array('nomjour'=>$nomjour,'jour' => $s));
1219
-		if ($h){
1220
-			if ($hd==$hf){
1221
-				// Lundi 20 fevrier a 18h25
1222
-				$s = spip_ucfirst(_T('date_fmt_jour_heure',array('jour'=>$s,'heure'=>$hd)));
1223
-				$s = "$dtstart$s$dtabbr";
1224
-			}else{
1225
-				// Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1226
-				if($dtabbr && $dtstart && $dtend)
1227
-					$s = _T('date_fmt_jour_heure_debut_fin_abbr',array('jour'=>spip_ucfirst($s),'heure_debut'=>$hd,'heure_fin'=>$hf,'dtstart'=>$dtstart,'dtend'=>$dtend,'dtabbr'=>$dtabbr));
1228
-				// Le lundi 20 fevrier de 18h00 a 20h00
1229
-				else
1230
-					$s = spip_ucfirst(_T('date_fmt_jour_heure_debut_fin',array('jour'=>$s,'heure_debut'=>$hd,'heure_fin'=>$hf)));
1231
-			}
1232
-		}else{
1233
-			if($dtabbr && $dtstart)
1234
-				$s = $dtstart.spip_ucfirst($s).$dtabbr;
1235
-			else
1236
-				$s = spip_ucfirst($s);
1237
-		}
1238
-	}
1239
-	else if ((date("Y-m",$date_debut))==date("Y-m",$date_fin))
1240
-	{ // meme annee et mois, jours differents
1241
-		if(!$h)
1242
-			$date_debut = jour($d);
1243
-		else
1244
-			$date_debut = affdate_jourcourt($d,date("Y",$date_fin));
1245
-		$date_fin = $affdate($f);
1246
-		if($jour){
1247
-			$nomjour_debut = nom_jour($d,$abbr);
1248
-			$date_debut = _T('date_fmt_jour',array('nomjour'=>$nomjour_debut,'jour' => $date_debut));
1249
-			$nomjour_fin = nom_jour($f,$abbr);
1250
-			$date_fin = _T('date_fmt_jour',array('nomjour'=>$nomjour_fin,'jour' => $date_fin));
1251
-		}
1252
-		if ($h){
1253
-			$date_debut = _T('date_fmt_jour_heure',array('jour'=>$date_debut,'heure'=>$hd));
1254
-			$date_fin = _T('date_fmt_jour_heure',array('jour'=>$date_fin,'heure'=>$hf));
1255
-		}
1256
-		$date_debut = $dtstart.$date_debut.$dtabbr;
1257
-		$date_fin = $dtend.$date_fin.$dtabbr;
1199
+    $dtstart = $dtend = $dtabbr = "";
1200
+    if (strpos($forme,'hcal')!==false) {
1201
+        $dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>";
1202
+        $dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>";
1203
+        $dtabbr = "</abbr>";
1204
+    }
1205
+
1206
+    $date_debut = strtotime($date_debut);
1207
+    $date_fin = strtotime($date_fin);
1208
+    $d = date("Y-m-d", $date_debut);
1209
+    $f = date("Y-m-d", $date_fin);
1210
+    $h = ($horaire==='oui' OR $horaire===true);
1211
+    $hd = _T('date_fmt_heures_minutes_court', array('h'=> date("H",$date_debut), 'm'=> date("i",$date_debut)));
1212
+    $hf = _T('date_fmt_heures_minutes_court', array('h'=> date("H",$date_fin), 'm'=> date("i",$date_fin)));
1213
+
1214
+    if ($d==$f)
1215
+    { // meme jour
1216
+        $nomjour = nom_jour($d,$abbr);
1217
+        $s = $affdate($d);
1218
+        $s = _T('date_fmt_jour',array('nomjour'=>$nomjour,'jour' => $s));
1219
+        if ($h){
1220
+            if ($hd==$hf){
1221
+                // Lundi 20 fevrier a 18h25
1222
+                $s = spip_ucfirst(_T('date_fmt_jour_heure',array('jour'=>$s,'heure'=>$hd)));
1223
+                $s = "$dtstart$s$dtabbr";
1224
+            }else{
1225
+                // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1226
+                if($dtabbr && $dtstart && $dtend)
1227
+                    $s = _T('date_fmt_jour_heure_debut_fin_abbr',array('jour'=>spip_ucfirst($s),'heure_debut'=>$hd,'heure_fin'=>$hf,'dtstart'=>$dtstart,'dtend'=>$dtend,'dtabbr'=>$dtabbr));
1228
+                // Le lundi 20 fevrier de 18h00 a 20h00
1229
+                else
1230
+                    $s = spip_ucfirst(_T('date_fmt_jour_heure_debut_fin',array('jour'=>$s,'heure_debut'=>$hd,'heure_fin'=>$hf)));
1231
+            }
1232
+        }else{
1233
+            if($dtabbr && $dtstart)
1234
+                $s = $dtstart.spip_ucfirst($s).$dtabbr;
1235
+            else
1236
+                $s = spip_ucfirst($s);
1237
+        }
1238
+    }
1239
+    else if ((date("Y-m",$date_debut))==date("Y-m",$date_fin))
1240
+    { // meme annee et mois, jours differents
1241
+        if(!$h)
1242
+            $date_debut = jour($d);
1243
+        else
1244
+            $date_debut = affdate_jourcourt($d,date("Y",$date_fin));
1245
+        $date_fin = $affdate($f);
1246
+        if($jour){
1247
+            $nomjour_debut = nom_jour($d,$abbr);
1248
+            $date_debut = _T('date_fmt_jour',array('nomjour'=>$nomjour_debut,'jour' => $date_debut));
1249
+            $nomjour_fin = nom_jour($f,$abbr);
1250
+            $date_fin = _T('date_fmt_jour',array('nomjour'=>$nomjour_fin,'jour' => $date_fin));
1251
+        }
1252
+        if ($h){
1253
+            $date_debut = _T('date_fmt_jour_heure',array('jour'=>$date_debut,'heure'=>$hd));
1254
+            $date_fin = _T('date_fmt_jour_heure',array('jour'=>$date_fin,'heure'=>$hf));
1255
+        }
1256
+        $date_debut = $dtstart.$date_debut.$dtabbr;
1257
+        $date_fin = $dtend.$date_fin.$dtabbr;
1258 1258
 		
1259
-		$s = _T('date_fmt_periode',array('date_debut' => $date_debut,'date_fin'=>$date_fin));
1260
-	}
1261
-	else {
1262
-		$date_debut = affdate_jourcourt($d,date("Y",$date_fin));
1263
-		$date_fin = $affdate($f);
1264
-		if($jour){
1265
-			$nomjour_debut = nom_jour($d,$abbr);
1266
-			$date_debut = _T('date_fmt_jour',array('nomjour'=>$nomjour_debut,'jour' => $date_debut));
1267
-			$nomjour_fin = nom_jour($f,$abbr);
1268
-			$date_fin = _T('date_fmt_jour',array('nomjour'=>$nomjour_fin,'jour' => $date_fin));
1269
-		}
1270
-		if ($h){
1271
-			$date_debut = _T('date_fmt_jour_heure',array('jour'=>$date_debut,'heure'=>$hd)); 
1272
-			$date_fin = _T('date_fmt_jour_heure',array('jour'=>$date_fin,'heure'=>$hf));
1273
-		}
1259
+        $s = _T('date_fmt_periode',array('date_debut' => $date_debut,'date_fin'=>$date_fin));
1260
+    }
1261
+    else {
1262
+        $date_debut = affdate_jourcourt($d,date("Y",$date_fin));
1263
+        $date_fin = $affdate($f);
1264
+        if($jour){
1265
+            $nomjour_debut = nom_jour($d,$abbr);
1266
+            $date_debut = _T('date_fmt_jour',array('nomjour'=>$nomjour_debut,'jour' => $date_debut));
1267
+            $nomjour_fin = nom_jour($f,$abbr);
1268
+            $date_fin = _T('date_fmt_jour',array('nomjour'=>$nomjour_fin,'jour' => $date_fin));
1269
+        }
1270
+        if ($h){
1271
+            $date_debut = _T('date_fmt_jour_heure',array('jour'=>$date_debut,'heure'=>$hd)); 
1272
+            $date_fin = _T('date_fmt_jour_heure',array('jour'=>$date_fin,'heure'=>$hf));
1273
+        }
1274 1274
 		
1275
-		$date_debut = $dtstart.$date_debut.$dtabbr;
1276
-		$date_fin=$dtend.$date_fin.$dtabbr;
1277
-		$s = _T('date_fmt_periode',array('date_debut' => $date_debut,'date_fin'=>$date_fin));
1275
+        $date_debut = $dtstart.$date_debut.$dtabbr;
1276
+        $date_fin=$dtend.$date_fin.$dtabbr;
1277
+        $s = _T('date_fmt_periode',array('date_debut' => $date_debut,'date_fin'=>$date_fin));
1278 1278
 		
1279
-	}
1280
-	return $s;
1279
+    }
1280
+    return $s;
1281 1281
 }
1282 1282
 
1283 1283
 /**
@@ -1291,15 +1291,15 @@  discard block
 block discarded – undo
1291 1291
  * @return string
1292 1292
  */
1293 1293
 function aligner($letexte, $justif='') {
1294
-	$letexte = trim($letexte);
1295
-	if (!strlen($letexte)) return '';
1294
+    $letexte = trim($letexte);
1295
+    if (!strlen($letexte)) return '';
1296 1296
 
1297
-	// Paragrapher rapidement
1298
-	$letexte = "<div style='text-align:$justif'>"
1299
-		. $letexte
1300
-	  ."</div>";
1297
+    // Paragrapher rapidement
1298
+    $letexte = "<div style='text-align:$justif'>"
1299
+        . $letexte
1300
+        ."</div>";
1301 1301
 
1302
-	return $letexte;
1302
+    return $letexte;
1303 1303
 }
1304 1304
 // http://doc.spip.org/@justifier
1305 1305
 function justifier($letexte) { return aligner($letexte,'justify');}
@@ -1312,8 +1312,8 @@  discard block
 block discarded – undo
1312 1312
 
1313 1313
 // http://doc.spip.org/@style_align
1314 1314
 function style_align($bof) {
1315
-	global $spip_lang_left;
1316
-	return "text-align: $spip_lang_left";
1315
+    global $spip_lang_left;
1316
+    return "text-align: $spip_lang_left";
1317 1317
 }
1318 1318
 
1319 1319
 //
@@ -1322,69 +1322,69 @@  discard block
 block discarded – undo
1322 1322
 
1323 1323
 // http://doc.spip.org/@filtrer_ical
1324 1324
 function filtrer_ical($texte) {
1325
-	#include_spip('inc/charsets');
1326
-	$texte = html2unicode($texte);
1327
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1328
-	$texte = preg_replace("/\n/", " ", $texte);
1329
-	$texte = preg_replace("/,/", "\,", $texte);
1325
+    #include_spip('inc/charsets');
1326
+    $texte = html2unicode($texte);
1327
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1328
+    $texte = preg_replace("/\n/", " ", $texte);
1329
+    $texte = preg_replace("/,/", "\,", $texte);
1330 1330
 
1331
-	return $texte;
1331
+    return $texte;
1332 1332
 }
1333 1333
 
1334 1334
 // http://doc.spip.org/@date_ical
1335 1335
 function date_ical($date, $addminutes = 0) {
1336
-	list($heures, $minutes, $secondes) = recup_heure($date);
1337
-	list($annee, $mois, $jour) = recup_date($date);
1336
+    list($heures, $minutes, $secondes) = recup_heure($date);
1337
+    list($annee, $mois, $jour) = recup_date($date);
1338 1338
 
1339
-	return gmdate("Ymd\THis\Z", mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1339
+    return gmdate("Ymd\THis\Z", mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee));
1340 1340
 }
1341 1341
 
1342 1342
 // date_iso retourne la date au format "RFC 3339" / "ISO 8601"
1343 1343
 // voir http://www.php.net/manual/fr/ref.datetime.php#datetime.constants
1344 1344
 // http://doc.spip.org/@date_iso
1345 1345
 function date_iso($date_heure) {
1346
-	list($annee, $mois, $jour) = recup_date($date_heure);
1347
-	list($heures, $minutes, $secondes) = recup_heure($date_heure);
1348
-	$time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1349
-	return gmdate('Y-m-d\TH:i:s\Z', $time);
1346
+    list($annee, $mois, $jour) = recup_date($date_heure);
1347
+    list($heures, $minutes, $secondes) = recup_heure($date_heure);
1348
+    $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1349
+    return gmdate('Y-m-d\TH:i:s\Z', $time);
1350 1350
 }
1351 1351
 
1352 1352
 // date_822 retourne la date au format "RFC 822"
1353 1353
 // utilise pour <pubdate> dans certains feeds RSS
1354 1354
 // http://doc.spip.org/@date_822
1355 1355
 function date_822($date_heure) {
1356
-	list($annee, $mois, $jour) = recup_date($date_heure);
1357
-	list($heures, $minutes, $secondes) = recup_heure($date_heure);
1358
-	$time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1359
-	return date('r', $time);
1356
+    list($annee, $mois, $jour) = recup_date($date_heure);
1357
+    list($heures, $minutes, $secondes) = recup_heure($date_heure);
1358
+    $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee);
1359
+    return date('r', $time);
1360 1360
 }
1361 1361
 
1362 1362
 // http://doc.spip.org/@date_anneemoisjour
1363 1363
 function date_anneemoisjour($d)  {
1364
-	if (!$d) $d = date("Y-m-d");
1365
-	return  substr($d, 0, 4) . substr($d, 5, 2) .substr($d, 8, 2);
1364
+    if (!$d) $d = date("Y-m-d");
1365
+    return  substr($d, 0, 4) . substr($d, 5, 2) .substr($d, 8, 2);
1366 1366
 }
1367 1367
 
1368 1368
 // http://doc.spip.org/@date_anneemois
1369 1369
 function date_anneemois($d)  {
1370
-	if (!$d) $d = date("Y-m-d");
1371
-	return  substr($d, 0, 4) . substr($d, 5, 2);
1370
+    if (!$d) $d = date("Y-m-d");
1371
+    return  substr($d, 0, 4) . substr($d, 5, 2);
1372 1372
 }
1373 1373
 
1374 1374
 // http://doc.spip.org/@date_debut_semaine
1375 1375
 function date_debut_semaine($annee, $mois, $jour) {
1376
-  $w_day = date("w", mktime(0,0,0,$mois, $jour, $annee));
1377
-  if ($w_day == 0) $w_day = 7; // Gaffe: le dimanche est zero
1378
-  $debut = $jour-$w_day+1;
1379
-  return date("Ymd", mktime(0,0,0,$mois,$debut,$annee));
1376
+    $w_day = date("w", mktime(0,0,0,$mois, $jour, $annee));
1377
+    if ($w_day == 0) $w_day = 7; // Gaffe: le dimanche est zero
1378
+    $debut = $jour-$w_day+1;
1379
+    return date("Ymd", mktime(0,0,0,$mois,$debut,$annee));
1380 1380
 }
1381 1381
 
1382 1382
 // http://doc.spip.org/@date_fin_semaine
1383 1383
 function date_fin_semaine($annee, $mois, $jour) {
1384
-  $w_day = date("w", mktime(0,0,0,$mois, $jour, $annee));
1385
-  if ($w_day == 0) $w_day = 7; // Gaffe: le dimanche est zero
1386
-  $debut = $jour-$w_day+1;
1387
-  return date("Ymd", mktime(0,0,0,$mois,$debut+6,$annee));
1384
+    $w_day = date("w", mktime(0,0,0,$mois, $jour, $annee));
1385
+    if ($w_day == 0) $w_day = 7; // Gaffe: le dimanche est zero
1386
+    $debut = $jour-$w_day+1;
1387
+    return date("Ymd", mktime(0,0,0,$mois,$debut+6,$annee));
1388 1388
 }
1389 1389
 
1390 1390
 
@@ -1394,55 +1394,55 @@  discard block
 block discarded – undo
1394 1394
 //
1395 1395
 // http://doc.spip.org/@extra
1396 1396
 function extra($letexte, $champ) {
1397
-	$champs = unserialize($letexte);
1398
-	return $champs[$champ];
1397
+    $champs = unserialize($letexte);
1398
+    return $champs[$champ];
1399 1399
 }
1400 1400
 
1401 1401
 // postautobr : transforme les sauts de ligne en _
1402 1402
 // http://doc.spip.org/@post_autobr
1403 1403
 function post_autobr($texte, $delim="\n_ ") {
1404
-	if (!function_exists('echappe_html'))
1405
-		include_spip('inc/texte_mini');
1406
-	$texte = str_replace("\r\n", "\r", $texte);
1407
-	$texte = str_replace("\r", "\n", $texte);
1408
-
1409
-	if (preg_match(",\n+$,", $texte, $fin))
1410
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1411
-	else
1412
-		$fin = '';
1413
-
1414
-	$texte = echappe_html($texte, '', true);
1415
-
1416
-	// echapper les modeles
1417
-	if (strpos($texte,"<")!==false){
1418
-		include_spip('inc/lien');
1419
-		if (defined('_PREG_MODELE')){
1420
-			$preg_modeles = "@"._PREG_MODELE."@imsS";
1421
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1422
-		}
1423
-	}
1424
-
1425
-	$debut = '';
1426
-	$suite = $texte;
1427
-	while ($t = strpos('-'.$suite, "\n", 1)) {
1428
-		$debut .= substr($suite, 0, $t-1);
1429
-		$suite = substr($suite, $t);
1430
-		$car = substr($suite, 0, 1);
1431
-		if (($car<>'-') AND ($car<>'_') AND ($car<>"\n") AND ($car<>"|") AND ($car<>"}")
1432
-		AND !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S',($suite))
1433
-		AND !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)) {
1434
-			$debut .= $delim;
1435
-		} else
1436
-			$debut .= "\n";
1437
-		if (preg_match(",^\n+,", $suite, $regs)) {
1438
-			$debut.=$regs[0];
1439
-			$suite = substr($suite, strlen($regs[0]));
1440
-		}
1441
-	}
1442
-	$texte = $debut.$suite;
1443
-
1444
-	$texte = echappe_retour($texte);
1445
-	return $texte.$fin;
1404
+    if (!function_exists('echappe_html'))
1405
+        include_spip('inc/texte_mini');
1406
+    $texte = str_replace("\r\n", "\r", $texte);
1407
+    $texte = str_replace("\r", "\n", $texte);
1408
+
1409
+    if (preg_match(",\n+$,", $texte, $fin))
1410
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1411
+    else
1412
+        $fin = '';
1413
+
1414
+    $texte = echappe_html($texte, '', true);
1415
+
1416
+    // echapper les modeles
1417
+    if (strpos($texte,"<")!==false){
1418
+        include_spip('inc/lien');
1419
+        if (defined('_PREG_MODELE')){
1420
+            $preg_modeles = "@"._PREG_MODELE."@imsS";
1421
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1422
+        }
1423
+    }
1424
+
1425
+    $debut = '';
1426
+    $suite = $texte;
1427
+    while ($t = strpos('-'.$suite, "\n", 1)) {
1428
+        $debut .= substr($suite, 0, $t-1);
1429
+        $suite = substr($suite, $t);
1430
+        $car = substr($suite, 0, 1);
1431
+        if (($car<>'-') AND ($car<>'_') AND ($car<>"\n") AND ($car<>"|") AND ($car<>"}")
1432
+        AND !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S',($suite))
1433
+        AND !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)) {
1434
+            $debut .= $delim;
1435
+        } else
1436
+            $debut .= "\n";
1437
+        if (preg_match(",^\n+,", $suite, $regs)) {
1438
+            $debut.=$regs[0];
1439
+            $suite = substr($suite, strlen($regs[0]));
1440
+        }
1441
+    }
1442
+    $texte = $debut.$suite;
1443
+
1444
+    $texte = echappe_retour($texte);
1445
+    return $texte.$fin;
1446 1446
 }
1447 1447
 
1448 1448
 
@@ -1452,63 +1452,63 @@  discard block
 block discarded – undo
1452 1452
 // pour ne pas mettre de span@lang=fr si on est deja en fr
1453 1453
 // http://doc.spip.org/@extraire_multi
1454 1454
 function extraire_multi($letexte, $lang=null, $echappe_span=false) {
1455
-	if (preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)) {
1456
-		if (!$lang) $lang = $GLOBALS['spip_lang'];
1457
-
1458
-		foreach ($regs as $reg) {
1459
-			// chercher la version de la langue courante
1460
-			$trads = extraire_trads($reg[1]);
1461
-			if ($l = approcher_langue($trads, $lang)) {
1462
-				$trad = $trads[$l];
1463
-			} else {
1464
-				include_spip('inc/texte');
1465
-				// langue absente, prendre la premiere dispo
1466
-				// mais typographier le texte selon les regles de celle-ci
1467
-				// Attention aux blocs multi sur plusieurs lignes
1468
-				$l = key($trads);
1469
-				$trad = $trads[$l];
1470
-				$typographie = charger_fonction(lang_typo($l), 'typographie');
1471
-				$trad = $typographie($trad);
1472
-				include_spip('inc/texte');
1473
-				// Tester si on echappe en span ou en div
1474
-				// il ne faut pas echapper en div si propre produit un seul paragraphe
1475
-				$trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims","",propre($trad));
1476
-				$mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1477
-				$trad = code_echappement($trad, 'multi', false, $mode);
1478
-				$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1479
-				if (lang_dir($l) !== lang_dir($lang))
1480
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1481
-				if (!$echappe_span)
1482
-					$trad = echappe_retour($trad, 'multi');
1483
-			}
1484
-			$letexte = str_replace($reg[0], $trad, $letexte);
1485
-		}
1486
-	}
1487
-
1488
-	return $letexte;
1455
+    if (preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)) {
1456
+        if (!$lang) $lang = $GLOBALS['spip_lang'];
1457
+
1458
+        foreach ($regs as $reg) {
1459
+            // chercher la version de la langue courante
1460
+            $trads = extraire_trads($reg[1]);
1461
+            if ($l = approcher_langue($trads, $lang)) {
1462
+                $trad = $trads[$l];
1463
+            } else {
1464
+                include_spip('inc/texte');
1465
+                // langue absente, prendre la premiere dispo
1466
+                // mais typographier le texte selon les regles de celle-ci
1467
+                // Attention aux blocs multi sur plusieurs lignes
1468
+                $l = key($trads);
1469
+                $trad = $trads[$l];
1470
+                $typographie = charger_fonction(lang_typo($l), 'typographie');
1471
+                $trad = $typographie($trad);
1472
+                include_spip('inc/texte');
1473
+                // Tester si on echappe en span ou en div
1474
+                // il ne faut pas echapper en div si propre produit un seul paragraphe
1475
+                $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims","",propre($trad));
1476
+                $mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1477
+                $trad = code_echappement($trad, 'multi', false, $mode);
1478
+                $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1479
+                if (lang_dir($l) !== lang_dir($lang))
1480
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1481
+                if (!$echappe_span)
1482
+                    $trad = echappe_retour($trad, 'multi');
1483
+            }
1484
+            $letexte = str_replace($reg[0], $trad, $letexte);
1485
+        }
1486
+    }
1487
+
1488
+    return $letexte;
1489 1489
 }
1490 1490
 
1491 1491
 // convertit le contenu d'une balise multi en un tableau
1492 1492
 // http://doc.spip.org/@extraire_trad
1493 1493
 function extraire_trads($bloc) {
1494
-	$lang = '';
1494
+    $lang = '';
1495 1495
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1496 1496
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1497
-	while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1498
-		$texte = trim($regs[1]);
1499
-		if ($texte OR $lang)
1500
-			$trads[$lang] = $texte;
1501
-		$bloc = substr($bloc, strlen($regs[0]));
1502
-		$lang = $regs[2];
1503
-	}
1504
-	$trads[$lang] = $bloc;
1497
+    while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1498
+        $texte = trim($regs[1]);
1499
+        if ($texte OR $lang)
1500
+            $trads[$lang] = $texte;
1501
+        $bloc = substr($bloc, strlen($regs[0]));
1502
+        $lang = $regs[2];
1503
+    }
1504
+    $trads[$lang] = $bloc;
1505 1505
 
1506
-	return $trads;
1506
+    return $trads;
1507 1507
 }
1508 1508
 
1509 1509
 // Calculer l'initiale d'un nom
1510 1510
 function initiale($nom){
1511
-	return spip_substr(trim(strtoupper(extraire_multi($nom))),0,1);
1511
+    return spip_substr(trim(strtoupper(extraire_multi($nom))),0,1);
1512 1512
 }
1513 1513
 
1514 1514
 //
@@ -1522,31 +1522,31 @@  discard block
 block discarded – undo
1522 1522
 // http://www.spip.net/@unique
1523 1523
 // http://doc.spip.org/@unique
1524 1524
 function unique($donnee, $famille='', $cpt = false) {
1525
-	static $mem = array();
1526
-	// permettre de vider la pile et de la restaurer
1527
-	// pour le calcul de introduction...
1528
-	if ($famille=='_spip_raz_'){
1529
-		$tmp = $mem;
1530
-		$mem = array();
1531
-		return $tmp;
1532
-	} elseif ($famille=='_spip_set_'){
1533
-		$mem = $donnee;
1534
-		return;
1535
-	}
1536
-	// eviter une notice
1537
-	if (!isset($mem[$famille])) {
1538
-		$mem[$famille] = array();
1539
-	}
1540
-	if ($cpt) {
1541
-		return count($mem[$famille]);
1542
-	}
1543
-	// eviter une notice
1544
-	if (!isset($mem[$famille][$donnee])) {
1545
-		$mem[$famille][$donnee] = 0;
1546
-	}
1547
-	if (!($mem[$famille][$donnee]++)) {
1548
-		return $donnee;
1549
-	}
1525
+    static $mem = array();
1526
+    // permettre de vider la pile et de la restaurer
1527
+    // pour le calcul de introduction...
1528
+    if ($famille=='_spip_raz_'){
1529
+        $tmp = $mem;
1530
+        $mem = array();
1531
+        return $tmp;
1532
+    } elseif ($famille=='_spip_set_'){
1533
+        $mem = $donnee;
1534
+        return;
1535
+    }
1536
+    // eviter une notice
1537
+    if (!isset($mem[$famille])) {
1538
+        $mem[$famille] = array();
1539
+    }
1540
+    if ($cpt) {
1541
+        return count($mem[$famille]);
1542
+    }
1543
+    // eviter une notice
1544
+    if (!isset($mem[$famille][$donnee])) {
1545
+        $mem[$famille][$donnee] = 0;
1546
+    }
1547
+    if (!($mem[$famille][$donnee]++)) {
1548
+        return $donnee;
1549
+    }
1550 1550
 }
1551 1551
 
1552 1552
 //
@@ -1556,18 +1556,18 @@  discard block
 block discarded – undo
1556 1556
 //
1557 1557
 // http://doc.spip.org/@alterner
1558 1558
 function alterner($i) {
1559
-	// recuperer les arguments (attention fonctions un peu space)
1560
-	$num = func_num_args();
1561
-	$args = func_get_args();
1559
+    // recuperer les arguments (attention fonctions un peu space)
1560
+    $num = func_num_args();
1561
+    $args = func_get_args();
1562 1562
 
1563
-	if($num == 2 && is_array($args[1])) {
1563
+    if($num == 2 && is_array($args[1])) {
1564 1564
     $args = $args[1];
1565 1565
     array_unshift($args,'');
1566 1566
     $num = count($args);
1567
-  }
1567
+    }
1568 1568
 
1569
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1570
-	return $args[(intval($i)-1)%($num-1)+1];
1569
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1570
+    return $args[(intval($i)-1)%($num-1)+1];
1571 1571
 }
1572 1572
 
1573 1573
 // recuperer un attribut d'une balise html
@@ -1577,41 +1577,41 @@  discard block
 block discarded – undo
1577 1577
 // (dans ce cas l'option $complet n'est pas disponible)
1578 1578
 // http://doc.spip.org/@extraire_attribut
1579 1579
 function extraire_attribut($balise, $attribut, $complet = false) {
1580
-	if (is_array($balise)) {
1581
-		array_walk($balise,
1582
-			create_function('&$a,$key,$t',
1583
-				'$a = extraire_attribut($a,$t);'
1584
-			),
1585
-			$attribut);
1586
-		return $balise;
1587
-	}
1588
-	if (preg_match(
1589
-	',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1590
-	.$attribut
1591
-	.'(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()([^>]*>.*),isS',
1592
-
1593
-	$balise, $r)) {
1594
-		if ($r[3][0] == '"' || $r[3][0] == "'") {
1595
-			$r[4] = substr($r[3], 1, -1);
1596
-			$r[3] = $r[3][0];
1597
-		} elseif ($r[3]!=='') {
1598
-			$r[4] = $r[3]; 
1599
-			$r[3] = '';
1600
-		} else {
1601
-			$r[4] = trim($r[2]); 
1602
-		}
1603
-		$att = $r[4];
1604
-		if (strpos($att,"&#")!==false)
1605
-			$att = str_replace(array("&#039;","&#39;","&#034;","&#34;"), array("'","'",'"','"'), $att);
1606
-		$att = filtrer_entites($att);
1607
-	}
1608
-	else
1609
-		$att = NULL;
1610
-
1611
-	if ($complet)
1612
-		return array($att, $r);
1613
-	else
1614
-		return $att;
1580
+    if (is_array($balise)) {
1581
+        array_walk($balise,
1582
+            create_function('&$a,$key,$t',
1583
+                '$a = extraire_attribut($a,$t);'
1584
+            ),
1585
+            $attribut);
1586
+        return $balise;
1587
+    }
1588
+    if (preg_match(
1589
+    ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1590
+    .$attribut
1591
+    .'(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()([^>]*>.*),isS',
1592
+
1593
+    $balise, $r)) {
1594
+        if ($r[3][0] == '"' || $r[3][0] == "'") {
1595
+            $r[4] = substr($r[3], 1, -1);
1596
+            $r[3] = $r[3][0];
1597
+        } elseif ($r[3]!=='') {
1598
+            $r[4] = $r[3]; 
1599
+            $r[3] = '';
1600
+        } else {
1601
+            $r[4] = trim($r[2]); 
1602
+        }
1603
+        $att = $r[4];
1604
+        if (strpos($att,"&#")!==false)
1605
+            $att = str_replace(array("&#039;","&#39;","&#034;","&#34;"), array("'","'",'"','"'), $att);
1606
+        $att = filtrer_entites($att);
1607
+    }
1608
+    else
1609
+        $att = NULL;
1610
+
1611
+    if ($complet)
1612
+        return array($att, $r);
1613
+    else
1614
+        return $att;
1615 1615
 }
1616 1616
 
1617 1617
 /**
@@ -1627,39 +1627,39 @@  discard block
 block discarded – undo
1627 1627
  * @return string
1628 1628
  */
1629 1629
 function inserer_attribut($balise, $attribut, $val, $proteger=true, $vider=false) {
1630
-	// preparer l'attribut
1631
-	// supprimer les &nbsp; etc mais pas les balises html
1632
-	// qui ont un sens dans un attribut value d'un input
1633
-	if ($proteger) $val = attribut_html($val,false);
1634
-
1635
-	// echapper les ' pour eviter tout bug
1636
-	$val = str_replace("'", "&#039;", $val);
1637
-	if ($vider AND strlen($val)==0)
1638
-		$insert = '';
1639
-	else
1640
-		$insert = " $attribut='$val'";
1641
-
1642
-	list($old, $r) = extraire_attribut($balise, $attribut, true);
1643
-
1644
-	if ($old !== NULL) {
1645
-		// Remplacer l'ancien attribut du meme nom
1646
-		$balise = $r[1].$insert.$r[5];
1647
-	}
1648
-	else {
1649
-		// preferer une balise " />" (comme <img />)
1650
-		if (preg_match(',/>,', $balise))
1651
-			$balise = preg_replace(",\s?/>,S", $insert." />", $balise, 1);
1652
-		// sinon une balise <a ...> ... </a>
1653
-		else
1654
-			$balise = preg_replace(",\s?>,S", $insert.">", $balise, 1);
1655
-	}
1656
-
1657
-	return $balise;
1630
+    // preparer l'attribut
1631
+    // supprimer les &nbsp; etc mais pas les balises html
1632
+    // qui ont un sens dans un attribut value d'un input
1633
+    if ($proteger) $val = attribut_html($val,false);
1634
+
1635
+    // echapper les ' pour eviter tout bug
1636
+    $val = str_replace("'", "&#039;", $val);
1637
+    if ($vider AND strlen($val)==0)
1638
+        $insert = '';
1639
+    else
1640
+        $insert = " $attribut='$val'";
1641
+
1642
+    list($old, $r) = extraire_attribut($balise, $attribut, true);
1643
+
1644
+    if ($old !== NULL) {
1645
+        // Remplacer l'ancien attribut du meme nom
1646
+        $balise = $r[1].$insert.$r[5];
1647
+    }
1648
+    else {
1649
+        // preferer une balise " />" (comme <img />)
1650
+        if (preg_match(',/>,', $balise))
1651
+            $balise = preg_replace(",\s?/>,S", $insert." />", $balise, 1);
1652
+        // sinon une balise <a ...> ... </a>
1653
+        else
1654
+            $balise = preg_replace(",\s?>,S", $insert.">", $balise, 1);
1655
+    }
1656
+
1657
+    return $balise;
1658 1658
 }
1659 1659
 
1660 1660
 // http://doc.spip.org/@vider_attribut
1661 1661
 function vider_attribut ($balise, $attribut) {
1662
-	return inserer_attribut($balise, $attribut, '', false, true);
1662
+    return inserer_attribut($balise, $attribut, '', false, true);
1663 1663
 }
1664 1664
 
1665 1665
 
@@ -1671,8 +1671,8 @@  discard block
 block discarded – undo
1671 1671
  * @return string
1672 1672
  */
1673 1673
 function tester_config($id, $mode='') {
1674
-	include_spip('action/inscrire_auteur');
1675
-	return tester_statut_inscription($mode, $id);
1674
+    include_spip('action/inscrire_auteur');
1675
+    return tester_statut_inscription($mode, $id);
1676 1676
 }
1677 1677
 
1678 1678
 //
@@ -1680,23 +1680,23 @@  discard block
 block discarded – undo
1680 1680
 //
1681 1681
 // http://doc.spip.org/@plus
1682 1682
 function plus($a,$b) {
1683
-	return $a+$b;
1683
+    return $a+$b;
1684 1684
 }
1685 1685
 // http://doc.spip.org/@moins
1686 1686
 function moins($a,$b) {
1687
-	return $a-$b;
1687
+    return $a-$b;
1688 1688
 }
1689 1689
 // http://doc.spip.org/@mult
1690 1690
 function mult($a,$b) {
1691
-	return $a*$b;
1691
+    return $a*$b;
1692 1692
 }
1693 1693
 // http://doc.spip.org/@div
1694 1694
 function div($a,$b) {
1695
-	return $b?$a/$b:0;
1695
+    return $b?$a/$b:0;
1696 1696
 }
1697 1697
 // http://doc.spip.org/@modulo
1698 1698
 function modulo($nb, $mod, $add=0) {
1699
-	return ($mod?$nb%$mod:0)+$add;
1699
+    return ($mod?$nb%$mod:0)+$add;
1700 1700
 }
1701 1701
 
1702 1702
 
@@ -1711,72 +1711,72 @@  discard block
 block discarded – undo
1711 1711
  *      - true sinon
1712 1712
 **/
1713 1713
 function nom_acceptable($nom) {
1714
-	if (!is_string($nom)) {
1715
-		return false;
1716
-	}
1717
-	if (!defined('_TAGS_NOM_AUTEUR')) define('_TAGS_NOM_AUTEUR','');
1718
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
1719
-	foreach($tags_acceptes as $tag) {
1720
-		if (strlen($tag)) {
1721
-			$remp1[] = '<'.trim($tag).'>';
1722
-			$remp1[] = '</'.trim($tag).'>';
1723
-			$remp2[] = '\x60'.trim($tag).'\x61';
1724
-			$remp2[] = '\x60/'.trim($tag).'\x61';
1725
-		}
1726
-	}	
1727
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
1728
-	return str_replace('&lt;', '<', $v_nom) == $nom;
1714
+    if (!is_string($nom)) {
1715
+        return false;
1716
+    }
1717
+    if (!defined('_TAGS_NOM_AUTEUR')) define('_TAGS_NOM_AUTEUR','');
1718
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
1719
+    foreach($tags_acceptes as $tag) {
1720
+        if (strlen($tag)) {
1721
+            $remp1[] = '<'.trim($tag).'>';
1722
+            $remp1[] = '</'.trim($tag).'>';
1723
+            $remp2[] = '\x60'.trim($tag).'\x61';
1724
+            $remp2[] = '\x60/'.trim($tag).'\x61';
1725
+        }
1726
+    }	
1727
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
1728
+    return str_replace('&lt;', '<', $v_nom) == $nom;
1729 1729
 }
1730 1730
 
1731 1731
 // Verifier la conformite d'une ou plusieurs adresses email
1732 1732
 //  retourne false ou la  normalisation de la derniere adresse donnee
1733 1733
 // http://doc.spip.org/@email_valide
1734 1734
 function email_valide($adresses) {
1735
-	// eviter d'injecter n'importe quoi dans preg_match
1736
-	if (!is_string($adresses))
1737
-		return false;
1738
-
1739
-	// Si c'est un spammeur autant arreter tout de suite
1740
-	if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) {
1741
-		spip_log("Tentative d'injection de mail : $adresses");
1742
-		return false;
1743
-	}
1744
-
1745
-	foreach (explode(',', $adresses) as $v) {
1746
-		// nettoyer certains formats
1747
-		// "Marie Toto <[email protected]>"
1748
-		$adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v));
1749
-		// RFC 822
1750
-		if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse))
1751
-			return false;
1752
-	}
1753
-	return $adresse;
1735
+    // eviter d'injecter n'importe quoi dans preg_match
1736
+    if (!is_string($adresses))
1737
+        return false;
1738
+
1739
+    // Si c'est un spammeur autant arreter tout de suite
1740
+    if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) {
1741
+        spip_log("Tentative d'injection de mail : $adresses");
1742
+        return false;
1743
+    }
1744
+
1745
+    foreach (explode(',', $adresses) as $v) {
1746
+        // nettoyer certains formats
1747
+        // "Marie Toto <[email protected]>"
1748
+        $adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v));
1749
+        // RFC 822
1750
+        if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse))
1751
+            return false;
1752
+    }
1753
+    return $adresse;
1754 1754
 }
1755 1755
 
1756 1756
 // http://doc.spip.org/@afficher_enclosures
1757 1757
 function afficher_enclosures($tags) {
1758
-	$s = array();
1759
-	foreach (extraire_balises($tags, 'a') as $tag) {
1760
-		if (extraire_attribut($tag, 'rel') == 'enclosure'
1761
-		AND $t = extraire_attribut($tag, 'href')) {
1762
-			$s[] = preg_replace(',>[^<]+</a>,S', 
1763
-				'>'
1764
-				.http_img_pack('attachment-16.png', $t,
1765
-					'title="'.attribut_html($t).'"')
1766
-				.'</a>', $tag);
1767
-		}
1768
-	}
1769
-	return join('&nbsp;', $s);
1758
+    $s = array();
1759
+    foreach (extraire_balises($tags, 'a') as $tag) {
1760
+        if (extraire_attribut($tag, 'rel') == 'enclosure'
1761
+        AND $t = extraire_attribut($tag, 'href')) {
1762
+            $s[] = preg_replace(',>[^<]+</a>,S', 
1763
+                '>'
1764
+                .http_img_pack('attachment-16.png', $t,
1765
+                    'title="'.attribut_html($t).'"')
1766
+                .'</a>', $tag);
1767
+        }
1768
+    }
1769
+    return join('&nbsp;', $s);
1770 1770
 }
1771 1771
 // http://doc.spip.org/@afficher_tags
1772 1772
 function afficher_tags($tags, $rels='tag,directory') {
1773
-	$s = array();
1774
-	foreach (extraire_balises($tags, 'a') as $tag) {
1775
-		$rel = extraire_attribut($tag, 'rel');
1776
-		if (strstr(",$rels,", ",$rel,"))
1777
-			$s[] = $tag;
1778
-	}
1779
-	return join(', ', $s);
1773
+    $s = array();
1774
+    foreach (extraire_balises($tags, 'a') as $tag) {
1775
+        $rel = extraire_attribut($tag, 'rel');
1776
+        if (strstr(",$rels,", ",$rel,"))
1777
+            $s[] = $tag;
1778
+    }
1779
+    return join(', ', $s);
1780 1780
 }
1781 1781
 
1782 1782
 // Passe un <enclosure url="fichier" length="5588242" type="audio/mpeg"/>
@@ -1784,51 +1784,51 @@  discard block
 block discarded – undo
1784 1784
 // attention length="zz" devient title="zz", pour rester conforme
1785 1785
 // http://doc.spip.org/@enclosure2microformat
1786 1786
 function enclosure2microformat($e) {
1787
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url')))
1788
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
1789
-	$type = extraire_attribut($e, 'type');
1790
-	if (!$length = extraire_attribut($e, 'length')) {
1791
-		# <media:content : longeur dans fileSize. On tente.
1792
-		$length = extraire_attribut($e, 'fileSize');
1793
-	}
1794
-	$fichier = basename($url);
1795
-	return '<a rel="enclosure"'
1796
-		. ($url? ' href="'.spip_htmlspecialchars($url).'"' : '')
1797
-		. ($type? ' type="'.spip_htmlspecialchars($type).'"' : '')
1798
-		. ($length? ' title="'.spip_htmlspecialchars($length).'"' : '')
1799
-		. '>'.$fichier.'</a>';
1787
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url')))
1788
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
1789
+    $type = extraire_attribut($e, 'type');
1790
+    if (!$length = extraire_attribut($e, 'length')) {
1791
+        # <media:content : longeur dans fileSize. On tente.
1792
+        $length = extraire_attribut($e, 'fileSize');
1793
+    }
1794
+    $fichier = basename($url);
1795
+    return '<a rel="enclosure"'
1796
+        . ($url? ' href="'.spip_htmlspecialchars($url).'"' : '')
1797
+        . ($type? ' type="'.spip_htmlspecialchars($type).'"' : '')
1798
+        . ($length? ' title="'.spip_htmlspecialchars($length).'"' : '')
1799
+        . '>'.$fichier.'</a>';
1800 1800
 }
1801 1801
 // La fonction inverse
1802 1802
 // http://doc.spip.org/@microformat2enclosure
1803 1803
 function microformat2enclosure($tags) {
1804
-	$enclosures = array();
1805
-	foreach (extraire_balises($tags, 'a') as $e)
1806
-	if (extraire_attribut($e, 'rel') == 'enclosure') {
1807
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
1808
-		$type = extraire_attribut($e, 'type');
1809
-		if (!$length = intval(extraire_attribut($e, 'title')))
1810
-			$length = intval(extraire_attribut($e, 'length')); # vieux data
1811
-		$fichier = basename($url);
1812
-		$enclosures[] = '<enclosure'
1813
-			. ($url? ' url="'.spip_htmlspecialchars($url).'"' : '')
1814
-			. ($type? ' type="'.spip_htmlspecialchars($type).'"' : '')
1815
-			. ($length? ' length="'.$length.'"' : '')
1816
-			. ' />';
1817
-	}
1818
-	return join("\n", $enclosures);
1804
+    $enclosures = array();
1805
+    foreach (extraire_balises($tags, 'a') as $e)
1806
+    if (extraire_attribut($e, 'rel') == 'enclosure') {
1807
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
1808
+        $type = extraire_attribut($e, 'type');
1809
+        if (!$length = intval(extraire_attribut($e, 'title')))
1810
+            $length = intval(extraire_attribut($e, 'length')); # vieux data
1811
+        $fichier = basename($url);
1812
+        $enclosures[] = '<enclosure'
1813
+            . ($url? ' url="'.spip_htmlspecialchars($url).'"' : '')
1814
+            . ($type? ' type="'.spip_htmlspecialchars($type).'"' : '')
1815
+            . ($length? ' length="'.$length.'"' : '')
1816
+            . ' />';
1817
+    }
1818
+    return join("\n", $enclosures);
1819 1819
 }
1820 1820
 // Creer les elements ATOM <dc:subject> a partir des tags
1821 1821
 // http://doc.spip.org/@tags2dcsubject
1822 1822
 function tags2dcsubject($tags) {
1823
-	$subjects = '';
1824
-	foreach (extraire_balises($tags, 'a') as $e) {
1825
-		if (extraire_attribut($e, rel) == 'tag') {
1826
-			$subjects .= '<dc:subject>'
1827
-				. texte_backend(textebrut($e))
1828
-				. '</dc:subject>'."\n";
1829
-		}
1830
-	}
1831
-	return $subjects;
1823
+    $subjects = '';
1824
+    foreach (extraire_balises($tags, 'a') as $e) {
1825
+        if (extraire_attribut($e, rel) == 'tag') {
1826
+            $subjects .= '<dc:subject>'
1827
+                . texte_backend(textebrut($e))
1828
+                . '</dc:subject>'."\n";
1829
+        }
1830
+    }
1831
+    return $subjects;
1832 1832
 }
1833 1833
 
1834 1834
 // retourne la premiere balise du type demande
@@ -1836,36 +1836,36 @@  discard block
 block discarded – undo
1836 1836
 // Si on a passe un tableau de textes, renvoyer un tableau de resultats
1837 1837
 // http://doc.spip.org/@extraire_balise
1838 1838
 function extraire_balise($texte, $tag='a') {
1839
-	if (is_array($texte)) {
1840
-		array_walk($texte,
1841
-			create_function('&$a,$key,$t', '$a = extraire_balise($a,$t);'),
1842
-			$tag);
1843
-		return $texte;
1844
-	}
1839
+    if (is_array($texte)) {
1840
+        array_walk($texte,
1841
+            create_function('&$a,$key,$t', '$a = extraire_balise($a,$t);'),
1842
+            $tag);
1843
+        return $texte;
1844
+    }
1845 1845
 
1846
-	if (preg_match(
1847
-	",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
1848
-	$texte, $regs))
1849
-		return $regs[0];
1846
+    if (preg_match(
1847
+    ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
1848
+    $texte, $regs))
1849
+        return $regs[0];
1850 1850
 }
1851 1851
 
1852 1852
 // extraire toutes les balises du type demande, sous forme de tableau
1853 1853
 // Si on a passe un tableau de textes, renvoyer un tableau de resultats
1854 1854
 // http://doc.spip.org/@extraire_balises
1855 1855
 function extraire_balises($texte, $tag='a') {
1856
-	if (is_array($texte)) {
1857
-		array_walk($texte,
1858
-			create_function('&$a,$key,$t', '$a = extraire_balises($a,$t);'),
1859
-			$tag);
1860
-		return $texte;
1861
-	}
1856
+    if (is_array($texte)) {
1857
+        array_walk($texte,
1858
+            create_function('&$a,$key,$t', '$a = extraire_balises($a,$t);'),
1859
+            $tag);
1860
+        return $texte;
1861
+    }
1862 1862
 
1863
-	if (preg_match_all(
1864
-	",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
1865
-	$texte, $regs, PREG_PATTERN_ORDER))
1866
-		return $regs[0];
1867
-	else
1868
-		return array();
1863
+    if (preg_match_all(
1864
+    ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
1865
+    $texte, $regs, PREG_PATTERN_ORDER))
1866
+        return $regs[0];
1867
+    else
1868
+        return array();
1869 1869
 }
1870 1870
 
1871 1871
 // comme in_array mais renvoie son 3e arg si le 2er arg n'est pas un tableau
@@ -1873,24 +1873,24 @@  discard block
 block discarded – undo
1873 1873
 
1874 1874
 // http://doc.spip.org/@in_any
1875 1875
 function in_any($val, $vals, $def='') {
1876
-	if (!is_array($vals) AND $v=unserialize($vals)) $vals = $v;
1877
-  return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
1876
+    if (!is_array($vals) AND $v=unserialize($vals)) $vals = $v;
1877
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
1878 1878
 }
1879 1879
 
1880 1880
 // valeur_numerique("3*2") => 6
1881 1881
 // n'accepte que les *, + et - (a ameliorer si on l'utilise vraiment)
1882 1882
 // http://doc.spip.org/@valeur_numerique
1883 1883
 function valeur_numerique($expr) {
1884
-	$a = 0;
1885
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr)))
1886
-		eval("\$a = $expr;");
1887
-	return intval($a);
1884
+    $a = 0;
1885
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr)))
1886
+        eval("\$a = $expr;");
1887
+    return intval($a);
1888 1888
 }
1889 1889
 
1890 1890
 // http://doc.spip.org/@regledetrois
1891 1891
 function regledetrois($a,$b,$c)
1892 1892
 {
1893
-  return round($a*$b/$c);
1893
+    return round($a*$b/$c);
1894 1894
 }
1895 1895
 
1896 1896
 // Fournit la suite de Input-Hidden correspondant aux parametres de
@@ -1899,74 +1899,74 @@  discard block
 block discarded – undo
1899 1899
 // http://doc.spip.org/@form_hidden
1900 1900
 function form_hidden($action) {
1901 1901
 
1902
-	$contexte = array();
1903
-	include_spip('inc/urls');
1904
-	if ($p = urls_decoder_url($action, '')
1905
-		AND reset($p)) {
1906
-		$fond = array_shift($p);
1907
-		if ($fond!='404'){
1908
-			$contexte = array_shift($p);
1909
-			$contexte['page'] = $fond;
1910
-			$action = preg_replace('/([?]'.preg_quote($fond).'[^&=]*[0-9]+)(&|$)/', '?&', $action);
1911
-		}
1912
-	}
1913
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
1914
-	if (defined('_DEFINIR_CONTEXTE_TYPE') AND _DEFINIR_CONTEXTE_TYPE)
1915
-		unset($contexte['type']);
1916
-	if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') AND _DEFINIR_CONTEXTE_TYPE_PAGE)
1917
-		unset($contexte['type-page']);
1918
-
1919
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
1920
-	// ecraser les elements de la forme mots[]=1&mots[]=2
1921
-	$values = array();
1922
-
1923
-	// d'abord avec celles de l'url
1924
-	if (false !== ($p = strpos($action, '?'))) {
1925
-		foreach(preg_split('/&(amp;)?/S',substr($action,$p+1)) as $c){
1926
-			list($var,$val) = explode('=', $c, 2);
1927
-			if ($var) {
1928
-				$val =  rawurldecode($val);
1929
-				$var =  rawurldecode($var); // decoder les [] eventuels
1930
-				if (preg_match(',\[\]$,S', $var))
1931
-					$values[] = array($var, $val);
1932
-				else if (!isset($values[$var]))
1933
-					$values[$var] = array($var, $val);
1934
-			}
1935
-		}
1936
-	}
1937
-
1938
-	// ensuite avec celles du contexte, sans doublonner !
1939
-	foreach($contexte as $var=>$val)
1940
-		if (preg_match(',\[\]$,S', $var))
1941
-			$values[] = array($var, $val);
1942
-		else if (!isset($values[$var]))
1943
-			$values[$var] = array($var, $val);
1944
-
1945
-	// puis on rassemble le tout
1946
-	$hidden = array();
1947
-	foreach($values as $value) {
1948
-		list($var,$val) = $value;
1949
-		$hidden[] = '<input name="'
1950
-			. entites_html($var)
1951
-			.'"'
1952
-			. (is_null($val)
1953
-				? ''
1954
-				: ' value="'.entites_html($val).'"'
1955
-				)
1956
-			. ' type="hidden"'."\n/>";
1957
-	}
1958
-	return join("", $hidden);
1902
+    $contexte = array();
1903
+    include_spip('inc/urls');
1904
+    if ($p = urls_decoder_url($action, '')
1905
+        AND reset($p)) {
1906
+        $fond = array_shift($p);
1907
+        if ($fond!='404'){
1908
+            $contexte = array_shift($p);
1909
+            $contexte['page'] = $fond;
1910
+            $action = preg_replace('/([?]'.preg_quote($fond).'[^&=]*[0-9]+)(&|$)/', '?&', $action);
1911
+        }
1912
+    }
1913
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
1914
+    if (defined('_DEFINIR_CONTEXTE_TYPE') AND _DEFINIR_CONTEXTE_TYPE)
1915
+        unset($contexte['type']);
1916
+    if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') AND _DEFINIR_CONTEXTE_TYPE_PAGE)
1917
+        unset($contexte['type-page']);
1918
+
1919
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
1920
+    // ecraser les elements de la forme mots[]=1&mots[]=2
1921
+    $values = array();
1922
+
1923
+    // d'abord avec celles de l'url
1924
+    if (false !== ($p = strpos($action, '?'))) {
1925
+        foreach(preg_split('/&(amp;)?/S',substr($action,$p+1)) as $c){
1926
+            list($var,$val) = explode('=', $c, 2);
1927
+            if ($var) {
1928
+                $val =  rawurldecode($val);
1929
+                $var =  rawurldecode($var); // decoder les [] eventuels
1930
+                if (preg_match(',\[\]$,S', $var))
1931
+                    $values[] = array($var, $val);
1932
+                else if (!isset($values[$var]))
1933
+                    $values[$var] = array($var, $val);
1934
+            }
1935
+        }
1936
+    }
1937
+
1938
+    // ensuite avec celles du contexte, sans doublonner !
1939
+    foreach($contexte as $var=>$val)
1940
+        if (preg_match(',\[\]$,S', $var))
1941
+            $values[] = array($var, $val);
1942
+        else if (!isset($values[$var]))
1943
+            $values[$var] = array($var, $val);
1944
+
1945
+    // puis on rassemble le tout
1946
+    $hidden = array();
1947
+    foreach($values as $value) {
1948
+        list($var,$val) = $value;
1949
+        $hidden[] = '<input name="'
1950
+            . entites_html($var)
1951
+            .'"'
1952
+            . (is_null($val)
1953
+                ? ''
1954
+                : ' value="'.entites_html($val).'"'
1955
+                )
1956
+            . ' type="hidden"'."\n/>";
1957
+    }
1958
+    return join("", $hidden);
1959 1959
 }
1960 1960
 
1961 1961
 // http://doc.spip.org/@filtre_bornes_pagination_dist
1962 1962
 function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) {
1963
-	if($max<=0 OR $max>=$nombre)
1964
-		return array(1, $nombre);
1963
+    if($max<=0 OR $max>=$nombre)
1964
+        return array(1, $nombre);
1965 1965
 
1966
-	$premiere = max(1, $courante-floor(($max-1)/2));
1967
-	$derniere = min($nombre, $premiere+$max-2);
1968
-	$premiere = $derniere == $nombre ? $derniere-$max+1 : $premiere;
1969
-	return array($premiere, $derniere);
1966
+    $premiere = max(1, $courante-floor(($max-1)/2));
1967
+    $derniere = min($nombre, $premiere+$max-2);
1968
+    $premiere = $derniere == $nombre ? $derniere-$max+1 : $premiere;
1969
+    return array($premiere, $derniere);
1970 1970
 }
1971 1971
 
1972 1972
 
@@ -1975,29 +1975,29 @@  discard block
 block discarded – undo
1975 1975
 // pour la pagination (mais peut-etre a refaire plus simplement)
1976 1976
 // http://doc.spip.org/@filtre_valeur_tableau
1977 1977
 function filtre_valeur_tableau($array, $index) {
1978
-	if (!is_array($array)
1979
-	OR !isset($array[$index]))
1980
-		return null;
1981
-	return $array[$index];
1978
+    if (!is_array($array)
1979
+    OR !isset($array[$index]))
1980
+        return null;
1981
+    return $array[$index];
1982 1982
 }
1983 1983
 // http://doc.spip.org/@filtre_reset
1984 1984
 function filtre_reset($array) {
1985
-	return !is_array($array) ? null : reset($array);
1985
+    return !is_array($array) ? null : reset($array);
1986 1986
 }
1987 1987
 // http://doc.spip.org/@filtre_end
1988 1988
 function filtre_end($array) {
1989
-	return !is_array($array) ? null : end($array);
1989
+    return !is_array($array) ? null : end($array);
1990 1990
 }
1991 1991
 
1992 1992
 // http://doc.spip.org/@filtre_push
1993 1993
 function filtre_push($array, $val) {
1994
-	if($array == '' OR !array_push($array, $val)) return '';
1995
-	return $array;
1994
+    if($array == '' OR !array_push($array, $val)) return '';
1995
+    return $array;
1996 1996
 }
1997 1997
 
1998 1998
 // http://doc.spip.org/@filtre_find
1999 1999
 function filtre_find($array, $val) {
2000
-	return (is_array($array) AND in_array($val, $array));
2000
+    return (is_array($array) AND in_array($val, $array));
2001 2001
 }
2002 2002
 
2003 2003
 
@@ -2008,52 +2008,52 @@  discard block
 block discarded – undo
2008 2008
 
2009 2009
 // http://doc.spip.org/@filtre_pagination_dist
2010 2010
 function filtre_pagination_dist($total, $nom, $position, $pas, $liste = true, $modele='', $connect='', $env=array()) {
2011
-	static $ancres = array();
2012
-	if ($pas<1) return '';
2013
-	$ancre = 'pagination'.$nom; // #pagination_articles
2014
-	$debut = 'debut'.$nom; // 'debut_articles'
2015
-
2016
-	// n'afficher l'ancre qu'une fois
2017
-	if (!isset($ancres[$ancre]))
2018
-		$bloc_ancre = $ancres[$ancre] = "<a name='".$ancre."' id='".$ancre."'></a>";
2019
-	else $bloc_ancre = '';
2020
-	// liste = false : on ne veut que l'ancre
2021
-	if (!$liste)
2022
-		return $ancres[$ancre];
2023
-
2024
-	$pagination = array(
2025
-		'debut' => $debut,
2026
-		'url' => parametre_url(self(),'fragment',''), // nettoyer l'id ahah eventuel
2027
-		'total' => $total,
2028
-		'position' => intval($position),
2029
-		'pas' => $pas,
2030
-		'nombre_pages' => floor(($total-1)/$pas)+1,
2031
-		'page_courante' => floor(intval($position)/$pas)+1,
2032
-		'ancre' => $ancre,
2033
-		'bloc_ancre' => $bloc_ancre
2034
-	);
2035
-	if (is_array($env))
2036
-		$pagination = array_merge($env,$pagination);
2037
-
2038
-	// Pas de pagination
2039
-	if ($pagination['nombre_pages']<=1)
2040
-		return '';
2041
-
2042
-	if ($modele) $modele = '_'.$modele;
2043
-
2044
-	return recuperer_fond("modeles/pagination$modele", $pagination, array('trim'=>true), $connect);
2011
+    static $ancres = array();
2012
+    if ($pas<1) return '';
2013
+    $ancre = 'pagination'.$nom; // #pagination_articles
2014
+    $debut = 'debut'.$nom; // 'debut_articles'
2015
+
2016
+    // n'afficher l'ancre qu'une fois
2017
+    if (!isset($ancres[$ancre]))
2018
+        $bloc_ancre = $ancres[$ancre] = "<a name='".$ancre."' id='".$ancre."'></a>";
2019
+    else $bloc_ancre = '';
2020
+    // liste = false : on ne veut que l'ancre
2021
+    if (!$liste)
2022
+        return $ancres[$ancre];
2023
+
2024
+    $pagination = array(
2025
+        'debut' => $debut,
2026
+        'url' => parametre_url(self(),'fragment',''), // nettoyer l'id ahah eventuel
2027
+        'total' => $total,
2028
+        'position' => intval($position),
2029
+        'pas' => $pas,
2030
+        'nombre_pages' => floor(($total-1)/$pas)+1,
2031
+        'page_courante' => floor(intval($position)/$pas)+1,
2032
+        'ancre' => $ancre,
2033
+        'bloc_ancre' => $bloc_ancre
2034
+    );
2035
+    if (is_array($env))
2036
+        $pagination = array_merge($env,$pagination);
2037
+
2038
+    // Pas de pagination
2039
+    if ($pagination['nombre_pages']<=1)
2040
+        return '';
2041
+
2042
+    if ($modele) $modele = '_'.$modele;
2043
+
2044
+    return recuperer_fond("modeles/pagination$modele", $pagination, array('trim'=>true), $connect);
2045 2045
 }
2046 2046
 
2047 2047
 // passer les url relatives a la css d'origine en url absolues
2048 2048
 // http://doc.spip.org/@urls_absolues_css
2049 2049
 function urls_absolues_css($contenu, $source) {
2050
-	$path = suivre_lien(url_absolue($source),'./');
2050
+    $path = suivre_lien(url_absolue($source),'./');
2051 2051
 
2052
-	return preg_replace_callback(
2053
-		",url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims",
2054
-		create_function('$x',
2055
-			'return "url(\"".suivre_lien("'.$path.'",$x[1])."\")";'
2056
-		), $contenu);
2052
+    return preg_replace_callback(
2053
+        ",url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims",
2054
+        create_function('$x',
2055
+            'return "url(\"".suivre_lien("'.$path.'",$x[1])."\")";'
2056
+        ), $contenu);
2057 2057
 }
2058 2058
 
2059 2059
 // recuperere le chemin d'une css existante et :
@@ -2062,136 +2062,136 @@  discard block
 block discarded – undo
2062 2062
 // SI on lui donne a manger une feuille nommee _rtl.css il va faire l'inverse
2063 2063
 // http://doc.spip.org/@direction_css
2064 2064
 function direction_css ($css, $voulue='') {
2065
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) return $css;
2066
-
2067
-	// si on a precise le sens voulu en argument, le prendre en compte
2068
-	if ($voulue = strtolower($voulue)) {
2069
-		if ($voulue != 'rtl' AND $voulue != 'ltr')
2070
-			$voulue = lang_dir($voulue);
2071
-	}
2072
-	else
2073
-		$voulue =  lang_dir();
2074
-
2075
-	$r = count($r) > 1;
2076
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2077
-	$dir = $r ? 'rtl' : 'ltr';
2078
-	$ndir = $r ? 'ltr' : 'rtl';
2079
-
2080
-	if ($voulue == $dir)
2081
-		return $css;
2082
-
2083
-	if (
2084
-		// url absolue
2085
-		preg_match(",^http:,i",$css)
2086
-		// ou qui contient un ?
2087
-		OR (($p=strpos($css,'?'))!==FALSE)) {
2088
-		$distant = true;
2089
-		$cssf = parse_url($css);
2090
-		$cssf = $cssf['path'].($cssf['query']?"?".$cssf['query']:"");
2091
-		$cssf = preg_replace(',[?:&=],', "_", $cssf);
2092
-	}
2093
-	else {
2094
-		$distant = false;
2095
-		$cssf = $css;
2096
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2097
-		//propose (rien a faire dans ce cas)
2098
-		$f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css);
2099
-		if (@file_exists($f))
2100
-			return $f;
2101
-	}
2102
-
2103
-	// 2.
2104
-	$dir_var = sous_repertoire (_DIR_VAR, 'cache-css');
2105
-	$f = $dir_var
2106
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2107
-		. '.' . substr(md5($cssf), 0,4) . '_' . $ndir . '.css';
2108
-
2109
-	// la css peut etre distante (url absolue !)
2110
-	if ($distant){
2111
-		include_spip('inc/distant');
2112
-		$contenu = recuperer_page($css);
2113
-		if (!$contenu) return $css;
2114
-	}
2115
-	else {
2116
-		if ((@filemtime($f) > @filemtime($css))
2117
-			AND (_VAR_MODE != 'recalcul'))
2118
-			return $f;
2119
-		if (!lire_fichier($css, $contenu))
2120
-			return $css;
2121
-	}
2122
-
2123
-	$contenu = str_replace(
2124
-		array('right', 'left', '@@@@L E F T@@@@'),
2125
-		array('@@@@L E F T@@@@', 'right', 'left'),
2126
-		$contenu);
2065
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) return $css;
2066
+
2067
+    // si on a precise le sens voulu en argument, le prendre en compte
2068
+    if ($voulue = strtolower($voulue)) {
2069
+        if ($voulue != 'rtl' AND $voulue != 'ltr')
2070
+            $voulue = lang_dir($voulue);
2071
+    }
2072
+    else
2073
+        $voulue =  lang_dir();
2074
+
2075
+    $r = count($r) > 1;
2076
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2077
+    $dir = $r ? 'rtl' : 'ltr';
2078
+    $ndir = $r ? 'ltr' : 'rtl';
2079
+
2080
+    if ($voulue == $dir)
2081
+        return $css;
2082
+
2083
+    if (
2084
+        // url absolue
2085
+        preg_match(",^http:,i",$css)
2086
+        // ou qui contient un ?
2087
+        OR (($p=strpos($css,'?'))!==FALSE)) {
2088
+        $distant = true;
2089
+        $cssf = parse_url($css);
2090
+        $cssf = $cssf['path'].($cssf['query']?"?".$cssf['query']:"");
2091
+        $cssf = preg_replace(',[?:&=],', "_", $cssf);
2092
+    }
2093
+    else {
2094
+        $distant = false;
2095
+        $cssf = $css;
2096
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2097
+        //propose (rien a faire dans ce cas)
2098
+        $f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css);
2099
+        if (@file_exists($f))
2100
+            return $f;
2101
+    }
2102
+
2103
+    // 2.
2104
+    $dir_var = sous_repertoire (_DIR_VAR, 'cache-css');
2105
+    $f = $dir_var
2106
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2107
+        . '.' . substr(md5($cssf), 0,4) . '_' . $ndir . '.css';
2108
+
2109
+    // la css peut etre distante (url absolue !)
2110
+    if ($distant){
2111
+        include_spip('inc/distant');
2112
+        $contenu = recuperer_page($css);
2113
+        if (!$contenu) return $css;
2114
+    }
2115
+    else {
2116
+        if ((@filemtime($f) > @filemtime($css))
2117
+            AND (_VAR_MODE != 'recalcul'))
2118
+            return $f;
2119
+        if (!lire_fichier($css, $contenu))
2120
+            return $css;
2121
+    }
2122
+
2123
+    $contenu = str_replace(
2124
+        array('right', 'left', '@@@@L E F T@@@@'),
2125
+        array('@@@@L E F T@@@@', 'right', 'left'),
2126
+        $contenu);
2127 2127
 	
2128
-	// reperer les @import auxquels il faut propager le direction_css
2129
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims",$contenu,$regs);
2130
-	$src = array();$src_direction_css = array();$src_faux_abs=array();
2131
-	$d = dirname($css);
2132
-	foreach($regs[1] as $k=>$import_css){
2133
-		$css_direction = direction_css("$d/$import_css",$voulue);
2134
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2135
-		if (substr($css_direction,0,strlen($d)+1)=="$d/") $css_direction = substr($css_direction,strlen($d)+1);
2136
-		// si la css_direction commence par $dir_var on la fait passer pour une absolue
2137
-		elseif (substr($css_direction,0,strlen($dir_var))==$dir_var) {
2138
-			$css_direction = substr($css_direction,strlen($dir_var));
2139
-			$src_faux_abs["/@@@@@@/".$css_direction] = $css_direction;
2140
-			$css_direction = "/@@@@@@/".$css_direction;
2141
-		}
2142
-		$src[] = $regs[0][$k];
2143
-		$src_direction_css[] = str_replace($import_css,$css_direction,$regs[0][$k]);
2144
-	}
2145
-	$contenu = str_replace($src,$src_direction_css,$contenu);
2146
-
2147
-	$contenu = urls_absolues_css($contenu, $css);
2148
-
2149
-	// virer les fausses url absolues que l'on a mis dans les import
2150
-	if (count($src_faux_abs))
2151
-		$contenu = str_replace(array_keys($src_faux_abs),$src_faux_abs,$contenu);
2152
-
2153
-	if (!ecrire_fichier($f, $contenu))
2154
-		return $css;
2155
-
2156
-	return $f;
2128
+    // reperer les @import auxquels il faut propager le direction_css
2129
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims",$contenu,$regs);
2130
+    $src = array();$src_direction_css = array();$src_faux_abs=array();
2131
+    $d = dirname($css);
2132
+    foreach($regs[1] as $k=>$import_css){
2133
+        $css_direction = direction_css("$d/$import_css",$voulue);
2134
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2135
+        if (substr($css_direction,0,strlen($d)+1)=="$d/") $css_direction = substr($css_direction,strlen($d)+1);
2136
+        // si la css_direction commence par $dir_var on la fait passer pour une absolue
2137
+        elseif (substr($css_direction,0,strlen($dir_var))==$dir_var) {
2138
+            $css_direction = substr($css_direction,strlen($dir_var));
2139
+            $src_faux_abs["/@@@@@@/".$css_direction] = $css_direction;
2140
+            $css_direction = "/@@@@@@/".$css_direction;
2141
+        }
2142
+        $src[] = $regs[0][$k];
2143
+        $src_direction_css[] = str_replace($import_css,$css_direction,$regs[0][$k]);
2144
+    }
2145
+    $contenu = str_replace($src,$src_direction_css,$contenu);
2146
+
2147
+    $contenu = urls_absolues_css($contenu, $css);
2148
+
2149
+    // virer les fausses url absolues que l'on a mis dans les import
2150
+    if (count($src_faux_abs))
2151
+        $contenu = str_replace(array_keys($src_faux_abs),$src_faux_abs,$contenu);
2152
+
2153
+    if (!ecrire_fichier($f, $contenu))
2154
+        return $css;
2155
+
2156
+    return $f;
2157 2157
 }
2158 2158
 
2159 2159
 // recuperere le chemin d'une css existante et :
2160 2160
 // cree (ou recree) dans _DIR_VAR/cache_css/ une css dont les url relatives sont passees en url absolues
2161 2161
 // http://doc.spip.org/@url_absolue_css
2162 2162
 function url_absolue_css ($css) {
2163
-	if (!preg_match(',\.css$,i', $css, $r)) return $css;
2163
+    if (!preg_match(',\.css$,i', $css, $r)) return $css;
2164 2164
 
2165
-	$url_absolue_css = url_absolue($css);
2165
+    $url_absolue_css = url_absolue($css);
2166 2166
 
2167
-	$f = basename($css,'.css');
2168
-	$f = sous_repertoire (_DIR_VAR, 'cache-css') 
2169
-		. preg_replace(",(.*?)(_rtl|_ltr)?$,","\\1-urlabs-" . substr(md5("$css-urlabs"), 0,4) . "\\2",$f) 
2170
-		. '.css';
2167
+    $f = basename($css,'.css');
2168
+    $f = sous_repertoire (_DIR_VAR, 'cache-css') 
2169
+        . preg_replace(",(.*?)(_rtl|_ltr)?$,","\\1-urlabs-" . substr(md5("$css-urlabs"), 0,4) . "\\2",$f) 
2170
+        . '.css';
2171 2171
 
2172
-	if ((@filemtime($f) > @filemtime($css))
2173
-	AND (_VAR_MODE != 'recalcul'))
2174
-		return $f;
2172
+    if ((@filemtime($f) > @filemtime($css))
2173
+    AND (_VAR_MODE != 'recalcul'))
2174
+        return $f;
2175 2175
 
2176
-	if ($url_absolue_css==$css){
2177
-		if (strncmp($GLOBALS['meta']['adresse_site'],$css,$l=strlen($GLOBALS['meta']['adresse_site']))!=0
2178
-		 OR !lire_fichier(_DIR_RACINE . substr($css,$l), $contenu)){
2179
-		 		include_spip('inc/distant');
2180
-		 		if (!$contenu = recuperer_page($css))
2181
-					return $css;
2182
-		}
2183
-	}
2184
-	elseif (!lire_fichier($css, $contenu))
2185
-		return $css;
2176
+    if ($url_absolue_css==$css){
2177
+        if (strncmp($GLOBALS['meta']['adresse_site'],$css,$l=strlen($GLOBALS['meta']['adresse_site']))!=0
2178
+         OR !lire_fichier(_DIR_RACINE . substr($css,$l), $contenu)){
2179
+                    include_spip('inc/distant');
2180
+                    if (!$contenu = recuperer_page($css))
2181
+                    return $css;
2182
+        }
2183
+    }
2184
+    elseif (!lire_fichier($css, $contenu))
2185
+        return $css;
2186 2186
 
2187
-	// passer les url relatives a la css d'origine en url absolues
2188
-	$contenu = urls_absolues_css($contenu, $css);
2187
+    // passer les url relatives a la css d'origine en url absolues
2188
+    $contenu = urls_absolues_css($contenu, $css);
2189 2189
 
2190
-	// ecrire la css
2191
-	if (!ecrire_fichier($f, $contenu))
2192
-		return $css;
2190
+    // ecrire la css
2191
+    if (!ecrire_fichier($f, $contenu))
2192
+        return $css;
2193 2193
 
2194
-	return $f;
2194
+    return $f;
2195 2195
 }
2196 2196
 
2197 2197
 
@@ -2222,24 +2222,24 @@  discard block
 block discarded – undo
2222 2222
  * @return mixed Valeur trouvee ou valeur par defaut.
2223 2223
 **/
2224 2224
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
2225
-	foreach (explode('/', $cle) as $k) {
2225
+    foreach (explode('/', $cle) as $k) {
2226 2226
 
2227
-		$table = is_string($table) ? @unserialize($table) : $table;
2227
+        $table = is_string($table) ? @unserialize($table) : $table;
2228 2228
 
2229
-		if (is_object($table)) {
2230
-			$table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
2231
-		} elseif (is_array($table)) {
2232
-			if ($conserver_null) {
2233
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
2234
-			} else {
2235
-				$table = isset($table[$k]) ? $table[$k] : $defaut;
2236
-			}
2237
-		} else {
2238
-			$table = $defaut;
2239
-		}
2240
-	}
2229
+        if (is_object($table)) {
2230
+            $table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
2231
+        } elseif (is_array($table)) {
2232
+            if ($conserver_null) {
2233
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
2234
+            } else {
2235
+                $table = isset($table[$k]) ? $table[$k] : $defaut;
2236
+            }
2237
+        } else {
2238
+            $table = $defaut;
2239
+        }
2240
+    }
2241 2241
 
2242
-	return $table;
2242
+    return $table;
2243 2243
 }
2244 2244
 
2245 2245
 // filtre match pour faire des tests avec expression reguliere
@@ -2249,29 +2249,29 @@  discard block
 block discarded – undo
2249 2249
 // accepte egalement la syntaxe #TRUC|match{truc(...)$,1} ou le modificateur n'est pas passe en second argument
2250 2250
 // http://doc.spip.org/@match
2251 2251
 function match($texte, $expression, $modif="UimsS",$capte=0) {
2252
-	if (intval($modif) AND $capte==0){
2253
-		$capte = $modif;
2254
-		$modif = "UimsS";
2255
-	}
2256
-	$expression=str_replace("\/","/",$expression);
2257
-	$expression=str_replace("/","\/",$expression);
2258
-
2259
-	if (preg_match('/' . $expression . '/' . $modif,$texte, $r)) {
2260
-		if (isset($r[$capte]))
2261
-			return $r[$capte];
2262
-		else
2263
-			return true;
2264
-	}
2265
-	return false;
2252
+    if (intval($modif) AND $capte==0){
2253
+        $capte = $modif;
2254
+        $modif = "UimsS";
2255
+    }
2256
+    $expression=str_replace("\/","/",$expression);
2257
+    $expression=str_replace("/","\/",$expression);
2258
+
2259
+    if (preg_match('/' . $expression . '/' . $modif,$texte, $r)) {
2260
+        if (isset($r[$capte]))
2261
+            return $r[$capte];
2262
+        else
2263
+            return true;
2264
+    }
2265
+    return false;
2266 2266
 }
2267 2267
 
2268 2268
 // filtre replace pour faire des operations avec expression reguliere
2269 2269
 // [(#TEXTE|replace{^ceci$,cela,UimsS})]
2270 2270
 // http://doc.spip.org/@replace
2271 2271
 function replace($texte, $expression, $replace='', $modif="UimsS") {
2272
-	$expression=str_replace("\/","/", $expression);
2273
-	$expression=str_replace("/","\/",$expression);
2274
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
2272
+    $expression=str_replace("\/","/", $expression);
2273
+    $expression=str_replace("/","\/",$expression);
2274
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
2275 2275
 }
2276 2276
 
2277 2277
 
@@ -2281,22 +2281,22 @@  discard block
 block discarded – undo
2281 2281
 // http://doc.spip.org/@traiter_doublons_documents
2282 2282
 function traiter_doublons_documents(&$doublons, $letexte) {
2283 2283
 
2284
-	// Verifier dans le texte & les notes (pas beau, helas)
2285
-	$t = $letexte.$GLOBALS['les_notes'];
2284
+    // Verifier dans le texte & les notes (pas beau, helas)
2285
+    $t = $letexte.$GLOBALS['les_notes'];
2286 2286
 
2287
-	if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
2288
-	AND preg_match_all(
2289
-	',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
2290
-	$t, $matches, PREG_PATTERN_ORDER))
2291
-		$doublons['documents'] .= "," . join(',', $matches[1]);
2287
+    if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
2288
+    AND preg_match_all(
2289
+    ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
2290
+    $t, $matches, PREG_PATTERN_ORDER))
2291
+        $doublons['documents'] .= "," . join(',', $matches[1]);
2292 2292
 
2293
-	return $letexte;
2293
+    return $letexte;
2294 2294
 }
2295 2295
 
2296 2296
 // filtre vide qui ne renvoie rien
2297 2297
 // http://doc.spip.org/@vide
2298 2298
 function vide($texte){
2299
-	return "";
2299
+    return "";
2300 2300
 }
2301 2301
 
2302 2302
 //
@@ -2306,51 +2306,51 @@  discard block
 block discarded – undo
2306 2306
 // A partir d'un #ENV, retourne des <param ...>
2307 2307
 // http://doc.spip.org/@env_to_params
2308 2308
 function env_to_params ($texte, $ignore_params=array()) {
2309
-	$ignore_params = array_merge (
2310
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
2311
-	$ignore_params);
2312
-	$tableau = unserialize($texte);
2313
-	$texte = "";
2314
-	foreach ($tableau as $i => $j)
2315
-		if (is_string($j) AND !in_array($i,$ignore_params))
2316
-			$texte .= "<param name='".$i."'\n\tvalue='".$j."' />";
2317
-	return $texte;
2309
+    $ignore_params = array_merge (
2310
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
2311
+    $ignore_params);
2312
+    $tableau = unserialize($texte);
2313
+    $texte = "";
2314
+    foreach ($tableau as $i => $j)
2315
+        if (is_string($j) AND !in_array($i,$ignore_params))
2316
+            $texte .= "<param name='".$i."'\n\tvalue='".$j."' />";
2317
+    return $texte;
2318 2318
 }
2319 2319
 // A partir d'un #ENV, retourne des attributs
2320 2320
 // http://doc.spip.org/@env_to_attributs
2321 2321
 function env_to_attributs ($texte, $ignore_params=array()) {
2322
-	$ignore_params = array_merge (
2323
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
2324
-	$ignore_params);
2325
-	$tableau = unserialize($texte);
2326
-	$texte = "";
2327
-	foreach ($tableau as $i => $j)
2328
-		if (is_string($j) AND !in_array($i,$ignore_params))
2329
-			$texte .= $i."='".$j."' ";
2330
-	return $texte;
2322
+    $ignore_params = array_merge (
2323
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
2324
+    $ignore_params);
2325
+    $tableau = unserialize($texte);
2326
+    $texte = "";
2327
+    foreach ($tableau as $i => $j)
2328
+        if (is_string($j) AND !in_array($i,$ignore_params))
2329
+            $texte .= $i."='".$j."' ";
2330
+    return $texte;
2331 2331
 }
2332 2332
 
2333 2333
 // Concatener des chaines
2334 2334
 // #TEXTE|concat{texte1,texte2,...}
2335 2335
 // http://doc.spip.org/@concat
2336 2336
 function concat(){
2337
-	$args = func_get_args();
2338
-	return join('', $args);
2337
+    $args = func_get_args();
2338
+    return join('', $args);
2339 2339
 }
2340 2340
 
2341 2341
 
2342 2342
 // http://doc.spip.org/@charge_scripts
2343 2343
 // http://doc.spip.org/@charge_scripts
2344 2344
 function charge_scripts($files, $script = true) {
2345
-	$flux = "";
2346
-	foreach(is_array($files)?$files:explode("|",$files) as $file) {
2347
-		if (!is_string($file)) continue;
2348
-		if ($script)
2349
-			$file = preg_match(",^\w+$,",$file) ? "javascript/$file.js" : '';
2350
-		if ($file) $path = find_in_path($file);
2351
-		if ($path) $flux .= spip_file_get_contents($path);
2352
-	}
2353
-	return $flux;
2345
+    $flux = "";
2346
+    foreach(is_array($files)?$files:explode("|",$files) as $file) {
2347
+        if (!is_string($file)) continue;
2348
+        if ($script)
2349
+            $file = preg_match(",^\w+$,",$file) ? "javascript/$file.js" : '';
2350
+        if ($file) $path = find_in_path($file);
2351
+        if ($path) $flux .= spip_file_get_contents($path);
2352
+    }
2353
+    return $flux;
2354 2354
 }
2355 2355
 
2356 2356
 
@@ -2372,26 +2372,26 @@  discard block
 block discarded – undo
2372 2372
  * @return string
2373 2373
  */
2374 2374
 function http_img_pack($img, $alt, $atts='', $title='', $options = array()) {
2375
-	if (!isset($options['chemin_image']) OR $options['chemin_image']==true)
2376
-		$img = chemin_image($img);
2377
-	if (stripos($atts, 'width')===false){
2378
-		// utiliser directement l'info de taille presente dans le nom
2379
-		if ((!isset($options['utiliser_suffixe_size']) OR $options['utiliser_suffixe_size']==true)
2380
-		    AND preg_match(',-([0-9]+)[.](png|gif)$,',$img,$regs)){
2381
-			$largeur = $hauteur = intval($regs[1]);
2382
-		}
2383
-		else{
2384
-			$taille = taille_image($img);
2385
-			list($hauteur,$largeur) = $taille;
2386
-			if (!$hauteur OR !$largeur)
2387
-				return "";
2388
-		}
2389
-		$atts.=" width='".$largeur."' height='".$hauteur."'";
2390
-	}
2391
-	return  "<img src='$img' alt='" . attribut_html($alt ? $alt : $title) . "'"
2392
-	  . ($title ? ' title="'.attribut_html($title).'"' : '')
2393
-	  . " ".ltrim($atts)
2394
-	  . " />";
2375
+    if (!isset($options['chemin_image']) OR $options['chemin_image']==true)
2376
+        $img = chemin_image($img);
2377
+    if (stripos($atts, 'width')===false){
2378
+        // utiliser directement l'info de taille presente dans le nom
2379
+        if ((!isset($options['utiliser_suffixe_size']) OR $options['utiliser_suffixe_size']==true)
2380
+            AND preg_match(',-([0-9]+)[.](png|gif)$,',$img,$regs)){
2381
+            $largeur = $hauteur = intval($regs[1]);
2382
+        }
2383
+        else{
2384
+            $taille = taille_image($img);
2385
+            list($hauteur,$largeur) = $taille;
2386
+            if (!$hauteur OR !$largeur)
2387
+                return "";
2388
+        }
2389
+        $atts.=" width='".$largeur."' height='".$hauteur."'";
2390
+    }
2391
+    return  "<img src='$img' alt='" . attribut_html($alt ? $alt : $title) . "'"
2392
+        . ($title ? ' title="'.attribut_html($title).'"' : '')
2393
+        . " ".ltrim($atts)
2394
+        . " />";
2395 2395
 }
2396 2396
 
2397 2397
 /**
@@ -2404,7 +2404,7 @@  discard block
 block discarded – undo
2404 2404
  * @return string
2405 2405
  */
2406 2406
 function http_style_background($img, $att=''){
2407
-  return " style='background".($att?"":"-image").": url(\"".chemin_image($img)."\")" . ($att ? (' ' . $att) : '') . ";'";
2407
+    return " style='background".($att?"":"-image").": url(\"".chemin_image($img)."\")" . ($att ? (' ' . $att) : '') . ";'";
2408 2408
 }
2409 2409
 
2410 2410
 /**
@@ -2416,22 +2416,22 @@  discard block
 block discarded – undo
2416 2416
  * @return string
2417 2417
  */
2418 2418
 function filtre_balise_img_dist($img,$alt="",$class=""){
2419
-	return http_img_pack($img, $alt, $class?" class='".attribut_html($class)."'":'', '', array('chemin_image'=>false,'utiliser_suffixe_size'=>false));
2419
+    return http_img_pack($img, $alt, $class?" class='".attribut_html($class)."'":'', '', array('chemin_image'=>false,'utiliser_suffixe_size'=>false));
2420 2420
 }
2421 2421
 
2422 2422
 
2423 2423
 //[(#ENV*|unserialize|foreach)]
2424 2424
 // http://doc.spip.org/@filtre_foreach_dist
2425 2425
 function filtre_foreach_dist($balise_deserializee, $modele = 'foreach') {
2426
-	$texte = '';
2427
-	if(is_array($balise_deserializee))
2428
-		foreach($balise_deserializee as $k => $v) {
2429
-			$res = recuperer_fond('modeles/'.$modele,
2430
-				array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
2431
-			);
2432
-			$texte .= $res;
2433
-		}
2434
-	return $texte;
2426
+    $texte = '';
2427
+    if(is_array($balise_deserializee))
2428
+        foreach($balise_deserializee as $k => $v) {
2429
+            $res = recuperer_fond('modeles/'.$modele,
2430
+                array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
2431
+            );
2432
+            $texte .= $res;
2433
+        }
2434
+    return $texte;
2435 2435
 }
2436 2436
 
2437 2437
 // renvoie la liste des plugins actifs du site
@@ -2441,39 +2441,39 @@  discard block
 block discarded – undo
2441 2441
 // appelee par la balise #PLUGIN
2442 2442
 // http://doc.spip.org/@filtre_info_plugin_dist
2443 2443
 function filtre_info_plugin_dist($plugin, $type_info) {
2444
-	include_spip('inc/plugin');
2445
-	$plugin = strtoupper($plugin);
2446
-	$plugins_actifs = liste_plugin_actifs();
2447
-
2448
-	if (!$plugin)
2449
-		return serialize(array_keys($plugins_actifs));
2450
-	elseif (empty($plugins_actifs[$plugin]))
2451
-		return '';
2452
-	elseif ($type_info == 'est_actif')
2453
-		return $plugins_actifs[$plugin] ? 1 : 0;
2454
-	elseif (isset($plugins_actifs[$plugin][$type_info]))
2455
-		return $plugins_actifs[$plugin][$type_info];
2456
-	else {
2457
-		$get_infos = charger_fonction('get_infos','plugins');
2458
-		// On prend en compte les extensions
2459
-		if (!is_dir($plugins_actifs[$plugin]['dir_type']))
2460
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
2461
-		else
2462
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
2463
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], false, $dir_plugins))
2464
-			return '';
2465
-		if ($type_info == 'tout')
2466
-			return $infos;
2467
-		else
2468
-			return strval($infos[$type_info]);
2469
-	}
2444
+    include_spip('inc/plugin');
2445
+    $plugin = strtoupper($plugin);
2446
+    $plugins_actifs = liste_plugin_actifs();
2447
+
2448
+    if (!$plugin)
2449
+        return serialize(array_keys($plugins_actifs));
2450
+    elseif (empty($plugins_actifs[$plugin]))
2451
+        return '';
2452
+    elseif ($type_info == 'est_actif')
2453
+        return $plugins_actifs[$plugin] ? 1 : 0;
2454
+    elseif (isset($plugins_actifs[$plugin][$type_info]))
2455
+        return $plugins_actifs[$plugin][$type_info];
2456
+    else {
2457
+        $get_infos = charger_fonction('get_infos','plugins');
2458
+        // On prend en compte les extensions
2459
+        if (!is_dir($plugins_actifs[$plugin]['dir_type']))
2460
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
2461
+        else
2462
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
2463
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], false, $dir_plugins))
2464
+            return '';
2465
+        if ($type_info == 'tout')
2466
+            return $infos;
2467
+        else
2468
+            return strval($infos[$type_info]);
2469
+    }
2470 2470
 }
2471 2471
 
2472 2472
 
2473 2473
 // http://doc.spip.org/@puce_changement_statut
2474 2474
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax=false){
2475
-	$puce_statut = charger_fonction('puce_statut','inc');
2476
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
2475
+    $puce_statut = charger_fonction('puce_statut','inc');
2476
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
2477 2477
 }
2478 2478
 
2479 2479
 /**
@@ -2488,10 +2488,10 @@  discard block
 block discarded – undo
2488 2488
  * @return string
2489 2489
  */
2490 2490
 function filtre_puce_statut_dist($statut,$objet,$id_objet=0,$id_parent=0){
2491
-	static $puce_statut = null;
2492
-	if (!$puce_statut)
2493
-		$puce_statut = charger_fonction('puce_statut','inc');
2494
-	return $puce_statut($id_objet, $statut, $id_parent, $objet, false, objet_info($objet,'editable')?_ACTIVER_PUCE_RAPIDE:false);
2491
+    static $puce_statut = null;
2492
+    if (!$puce_statut)
2493
+        $puce_statut = charger_fonction('puce_statut','inc');
2494
+    return $puce_statut($id_objet, $statut, $id_parent, $objet, false, objet_info($objet,'editable')?_ACTIVER_PUCE_RAPIDE:false);
2495 2495
 }
2496 2496
 
2497 2497
 
@@ -2513,128 +2513,128 @@  discard block
 block discarded – undo
2513 2513
  * @return string
2514 2514
  */
2515 2515
 function encoder_contexte_ajax($c,$form='', $emboite=NULL, $ajaxid='') {
2516
-	if (is_string($c)
2517
-	AND !is_null(@unserialize($c))) {
2518
-		$c = unserialize($c);
2519
-	}
2520
-
2521
-	// supprimer les parametres debut_x
2522
-	// pour que la pagination ajax ne soit pas plantee
2523
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
2524
-	// le debut_x=0 n'existe pas, et on resterait sur 1
2525
-	foreach ($c as $k => $v) {
2526
-		if (strpos($k,'debut_') === 0) {
2527
-			unset($c[$k]);
2528
-		}
2529
-	}
2516
+    if (is_string($c)
2517
+    AND !is_null(@unserialize($c))) {
2518
+        $c = unserialize($c);
2519
+    }
2520
+
2521
+    // supprimer les parametres debut_x
2522
+    // pour que la pagination ajax ne soit pas plantee
2523
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
2524
+    // le debut_x=0 n'existe pas, et on resterait sur 1
2525
+    foreach ($c as $k => $v) {
2526
+        if (strpos($k,'debut_') === 0) {
2527
+            unset($c[$k]);
2528
+        }
2529
+    }
2530 2530
 	
2531
-	if (!function_exists('calculer_cle_action'))
2532
-		include_spip("inc/securiser_action");
2533
-
2534
-	$c = serialize($c);
2535
-	$cle = calculer_cle_action($form . $c);
2536
-	$c = "$cle:$c";
2537
-
2538
-	// on ne stocke pas les contextes dans des fichiers caches
2539
-	// par defaut, sauf si cette configuration a ete forcee
2540
-	// OU que la longueur de l''argument generee est plus long
2541
-	// que ce que telere Suhosin.
2542
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') AND _CACHE_CONTEXTES_AJAX);
2543
-	if (!$cache_contextes_ajax) {
2544
-		$env = $c;
2545
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
2546
-			$env = gzdeflate($env);
2547
-			// http://core.spip.org/issues/2667 | https://bugs.php.net/bug.php?id=61287
2548
-			if (substr(phpversion(),0,5) == '5.4.0' AND !@gzinflate($env)) {
2549
-				$cache_contextes_ajax = true;
2550
-				spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT);
2551
-			}
2552
-		}
2553
-		$env = _xor($env);
2554
-		$env = base64_encode($env);
2555
-		// tester Suhosin et la valeur maximale des variables en GET...
2556
-		if ($max_len = @ini_get('suhosin.get.max_value_length')
2557
-		and $max_len < ($len = strlen($env))) {
2558
-			$cache_contextes_ajax = true;
2559
-			spip_log("Contextes AJAX forces en fichiers !"
2560
-				. " Cela arrive lorsque la valeur du contexte"
2561
-				. " depasse la longueur maximale autorisee par Suhosin"
2562
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
2563
-				. " Vous devriez modifier les parametres de Suhosin"
2564
-				. " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
2565
-		}
2566
-	}
2531
+    if (!function_exists('calculer_cle_action'))
2532
+        include_spip("inc/securiser_action");
2533
+
2534
+    $c = serialize($c);
2535
+    $cle = calculer_cle_action($form . $c);
2536
+    $c = "$cle:$c";
2537
+
2538
+    // on ne stocke pas les contextes dans des fichiers caches
2539
+    // par defaut, sauf si cette configuration a ete forcee
2540
+    // OU que la longueur de l''argument generee est plus long
2541
+    // que ce que telere Suhosin.
2542
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') AND _CACHE_CONTEXTES_AJAX);
2543
+    if (!$cache_contextes_ajax) {
2544
+        $env = $c;
2545
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
2546
+            $env = gzdeflate($env);
2547
+            // http://core.spip.org/issues/2667 | https://bugs.php.net/bug.php?id=61287
2548
+            if (substr(phpversion(),0,5) == '5.4.0' AND !@gzinflate($env)) {
2549
+                $cache_contextes_ajax = true;
2550
+                spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT);
2551
+            }
2552
+        }
2553
+        $env = _xor($env);
2554
+        $env = base64_encode($env);
2555
+        // tester Suhosin et la valeur maximale des variables en GET...
2556
+        if ($max_len = @ini_get('suhosin.get.max_value_length')
2557
+        and $max_len < ($len = strlen($env))) {
2558
+            $cache_contextes_ajax = true;
2559
+            spip_log("Contextes AJAX forces en fichiers !"
2560
+                . " Cela arrive lorsque la valeur du contexte"
2561
+                . " depasse la longueur maximale autorisee par Suhosin"
2562
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
2563
+                . " Vous devriez modifier les parametres de Suhosin"
2564
+                . " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
2565
+        }
2566
+    }
2567 2567
 	
2568
-	if ($cache_contextes_ajax) {
2569
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
2570
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
2571
-		$md5 = md5($c);
2572
-		ecrire_fichier("$dir/c$md5",$c);
2573
-		$env = $md5;
2574
-	} 
2568
+    if ($cache_contextes_ajax) {
2569
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
2570
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
2571
+        $md5 = md5($c);
2572
+        ecrire_fichier("$dir/c$md5",$c);
2573
+        $env = $md5;
2574
+    } 
2575 2575
 	
2576
-	if ($emboite === NULL) return $env;
2577
-	if (!trim($emboite)) return "";
2578
-	// toujours encoder l'url source dans le bloc ajax
2579
-	$r = self();
2580
-	$r = ' data-origin="'.$r.'"';
2581
-	$class = 'ajaxbloc';
2582
-	if ($ajaxid and is_string($ajaxid)) {
2583
-		// ajaxid est normalement conforme a un nom de classe css
2584
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
2585
-		$class .= ' ajax-id-' . entites_html($ajaxid);
2586
-	}
2587
-	return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
2576
+    if ($emboite === NULL) return $env;
2577
+    if (!trim($emboite)) return "";
2578
+    // toujours encoder l'url source dans le bloc ajax
2579
+    $r = self();
2580
+    $r = ' data-origin="'.$r.'"';
2581
+    $class = 'ajaxbloc';
2582
+    if ($ajaxid and is_string($ajaxid)) {
2583
+        // ajaxid est normalement conforme a un nom de classe css
2584
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
2585
+        $class .= ' ajax-id-' . entites_html($ajaxid);
2586
+    }
2587
+    return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
2588 2588
 }
2589 2589
 
2590 2590
 // la procedure inverse de encoder_contexte_ajax()
2591 2591
 // http://doc.spip.org/@decoder_contexte_ajax
2592 2592
 function decoder_contexte_ajax($c,$form='') {
2593
-	if (!function_exists('calculer_cle_action'))
2594
-		include_spip("inc/securiser_action");
2595
-	if (( (defined('_CACHE_CONTEXTES_AJAX') AND _CACHE_CONTEXTES_AJAX) OR strlen($c)==32)
2596
-		AND $dir = sous_repertoire(_DIR_CACHE, 'contextes')
2597
-		AND lire_fichier("$dir/c$c",$contexte)) {
2598
-			$c = $contexte;
2599
-	} else {
2600
-		$c = @base64_decode($c);
2601
-		$c = _xor($c);
2602
-		if (function_exists('gzdeflate') && function_exists('gzinflate'))
2603
-			$c = @gzinflate($c);
2604
-	}
2605
-
2606
-	// extraire la signature en debut de contexte
2607
-	// et la verifier avant de deserializer
2608
-	// format : signature:donneesserializees
2609
-	if ($p = strpos($c,":")){
2610
-		$cle = substr($c,0,$p);
2611
-		$c = substr($c,$p+1);
2612
-
2613
-		if ($cle == calculer_cle_action($form . $c)) {
2614
-			$env = @unserialize($c);
2615
-			return $env;
2616
-		}
2617
-	}
2618
-
2619
-	return false;
2593
+    if (!function_exists('calculer_cle_action'))
2594
+        include_spip("inc/securiser_action");
2595
+    if (( (defined('_CACHE_CONTEXTES_AJAX') AND _CACHE_CONTEXTES_AJAX) OR strlen($c)==32)
2596
+        AND $dir = sous_repertoire(_DIR_CACHE, 'contextes')
2597
+        AND lire_fichier("$dir/c$c",$contexte)) {
2598
+            $c = $contexte;
2599
+    } else {
2600
+        $c = @base64_decode($c);
2601
+        $c = _xor($c);
2602
+        if (function_exists('gzdeflate') && function_exists('gzinflate'))
2603
+            $c = @gzinflate($c);
2604
+    }
2605
+
2606
+    // extraire la signature en debut de contexte
2607
+    // et la verifier avant de deserializer
2608
+    // format : signature:donneesserializees
2609
+    if ($p = strpos($c,":")){
2610
+        $cle = substr($c,0,$p);
2611
+        $c = substr($c,$p+1);
2612
+
2613
+        if ($cle == calculer_cle_action($form . $c)) {
2614
+            $env = @unserialize($c);
2615
+            return $env;
2616
+        }
2617
+    }
2618
+
2619
+    return false;
2620 2620
 }
2621 2621
 
2622 2622
 // encrypter/decrypter un message
2623 2623
 // http://www.php.net/manual/fr/language.operators.bitwise.php#81358
2624 2624
 // http://doc.spip.org/@_xor
2625 2625
 function _xor($message, $key=null){
2626
-	if (is_null($key)) {
2627
-		if (!function_exists('calculer_cle_action'))
2628
-			include_spip("inc/securiser_action");
2629
-		$key = pack("H*", calculer_cle_action('_xor'));
2630
-	}
2626
+    if (is_null($key)) {
2627
+        if (!function_exists('calculer_cle_action'))
2628
+            include_spip("inc/securiser_action");
2629
+        $key = pack("H*", calculer_cle_action('_xor'));
2630
+    }
2631 2631
 
2632
-	$keylen = strlen($key);
2633
-	$messagelen = strlen($message);
2634
-	for($i=0; $i<$messagelen; $i++)
2635
-		$message[$i] = ~($message[$i]^$key[$i%$keylen]);
2632
+    $keylen = strlen($key);
2633
+    $messagelen = strlen($message);
2634
+    for($i=0; $i<$messagelen; $i++)
2635
+        $message[$i] = ~($message[$i]^$key[$i%$keylen]);
2636 2636
 
2637
-	return $message;
2637
+    return $message;
2638 2638
 }
2639 2639
 
2640 2640
 // Les vrai fonctions sont dans le plugin forum, mais on evite ici une erreur du compilateur
@@ -2660,20 +2660,20 @@  discard block
 block discarded – undo
2660 2660
  * @return string
2661 2661
  */
2662 2662
 function lien_ou_expose($url,$libelle=NULL,$on=false,$class="",$title="",$rel="", $evt=''){
2663
-	if ($on) {
2664
-		$bal = "strong";
2665
-		$att = "class='on'";
2666
-	} else {
2667
-		$bal = 'a';
2668
-		$att = "href='$url'"
2669
-	  	.($title?" title='".attribut_html($title)."'":'')
2670
-	  	.($class?" class='".attribut_html($class)."'":'')
2671
-	  	.($rel?" rel='".attribut_html($rel)."'":'')
2672
-		.$evt;
2673
-	}
2674
-	if ($libelle === NULL)
2675
-		$libelle = $url;
2676
-	return "<$bal $att>$libelle</$bal>";
2663
+    if ($on) {
2664
+        $bal = "strong";
2665
+        $att = "class='on'";
2666
+    } else {
2667
+        $bal = 'a';
2668
+        $att = "href='$url'"
2669
+            .($title?" title='".attribut_html($title)."'":'')
2670
+            .($class?" class='".attribut_html($class)."'":'')
2671
+            .($rel?" rel='".attribut_html($rel)."'":'')
2672
+        .$evt;
2673
+    }
2674
+    if ($libelle === NULL)
2675
+        $libelle = $url;
2676
+    return "<$bal $att>$libelle</$bal>";
2677 2677
 }
2678 2678
 
2679 2679
 
@@ -2690,11 +2690,11 @@  discard block
 block discarded – undo
2690 2690
  * @return string : la chaine de langue finale en utilisant la fonction _T()
2691 2691
  */
2692 2692
 function singulier_ou_pluriel($nb,$chaine_un,$chaine_plusieurs,$var='nb',$vars=array()){
2693
-	if (!$nb=intval($nb)) return "";
2694
-	if (!is_array($vars)) return "";
2695
-	$vars[$var] = $nb;
2696
-	if ($nb>1) return _T($chaine_plusieurs, $vars);
2697
-	else return _T($chaine_un,$vars);
2693
+    if (!$nb=intval($nb)) return "";
2694
+    if (!is_array($vars)) return "";
2695
+    $vars[$var] = $nb;
2696
+    if ($nb>1) return _T($chaine_plusieurs, $vars);
2697
+    else return _T($chaine_un,$vars);
2698 2698
 }
2699 2699
 
2700 2700
 
@@ -2719,77 +2719,77 @@  discard block
 block discarded – undo
2719 2719
  * @return string 
2720 2720
  */
2721 2721
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction="", $class="",$javascript=""){
2722
-	if (in_array($fonction,array("del","supprimer.gif")))
2723
-		$class .= ' danger';
2724
-	elseif ($fonction == "rien.gif")
2725
-		$fonction = "";
2726
-	elseif ($fonction == "delsafe")
2727
-		$fonction = "del";
2728
-
2729
-	// remappage des icone : article-24.png+new => article-new-24.png
2730
-	if ($icone_renommer = charger_fonction('icone_renommer','inc',true))
2731
-		list($fond,$fonction) = $icone_renommer($fond,$fonction);
2732
-
2733
-	// ajouter le type d'objet dans la class de l'icone
2734
-	$class .= " " . substr(basename($fond),0,-4);
2735
-
2736
-	$alt = attribut_html($texte);
2737
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
2738
-
2739
-	$ajax = "";
2740
-	if (strpos($class,"ajax")!==false) {
2741
-			$ajax="ajax";
2742
-		if (strpos($class,"preload")!==false)
2743
-			$ajax.=" preload";
2744
-		if (strpos($class,"nocache")!==false)
2745
-			$ajax.=" nocache";
2746
-		$ajax=" class='$ajax'";
2747
-	}
2748
-
2749
-	$size = 24;
2750
-	if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i",$fond,$match))
2751
-		$size = $match[1];
2752
-
2753
-	if ($fonction){
2754
-		// 2 images pour composer l'icone : le fond (article) en background,
2755
-		// la fonction (new) en image
2756
-		$icone = http_img_pack($fonction, $alt, "width='$size' height='$size'\n" .
2757
-					http_style_background($fond));
2758
-	}
2759
-	else {
2760
-		$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
2761
-	}
2762
-
2763
-	if ($type=='lien')
2764
-		return "<span class='icone s$size $class'>"
2765
-		. "<a href='$lien'$title$ajax$javascript>"
2766
-		. $icone
2767
-		. "<b>$texte</b>"
2768
-		. "</a></span>\n";
2769
-
2770
-	else
2771
-		return bouton_action("$icone<b>$texte</b>",$lien,"icone s$size $class",$javascript,$alt);
2722
+    if (in_array($fonction,array("del","supprimer.gif")))
2723
+        $class .= ' danger';
2724
+    elseif ($fonction == "rien.gif")
2725
+        $fonction = "";
2726
+    elseif ($fonction == "delsafe")
2727
+        $fonction = "del";
2728
+
2729
+    // remappage des icone : article-24.png+new => article-new-24.png
2730
+    if ($icone_renommer = charger_fonction('icone_renommer','inc',true))
2731
+        list($fond,$fonction) = $icone_renommer($fond,$fonction);
2732
+
2733
+    // ajouter le type d'objet dans la class de l'icone
2734
+    $class .= " " . substr(basename($fond),0,-4);
2735
+
2736
+    $alt = attribut_html($texte);
2737
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
2738
+
2739
+    $ajax = "";
2740
+    if (strpos($class,"ajax")!==false) {
2741
+            $ajax="ajax";
2742
+        if (strpos($class,"preload")!==false)
2743
+            $ajax.=" preload";
2744
+        if (strpos($class,"nocache")!==false)
2745
+            $ajax.=" nocache";
2746
+        $ajax=" class='$ajax'";
2747
+    }
2748
+
2749
+    $size = 24;
2750
+    if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i",$fond,$match))
2751
+        $size = $match[1];
2752
+
2753
+    if ($fonction){
2754
+        // 2 images pour composer l'icone : le fond (article) en background,
2755
+        // la fonction (new) en image
2756
+        $icone = http_img_pack($fonction, $alt, "width='$size' height='$size'\n" .
2757
+                    http_style_background($fond));
2758
+    }
2759
+    else {
2760
+        $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
2761
+    }
2762
+
2763
+    if ($type=='lien')
2764
+        return "<span class='icone s$size $class'>"
2765
+        . "<a href='$lien'$title$ajax$javascript>"
2766
+        . $icone
2767
+        . "<b>$texte</b>"
2768
+        . "</a></span>\n";
2769
+
2770
+    else
2771
+        return bouton_action("$icone<b>$texte</b>",$lien,"icone s$size $class",$javascript,$alt);
2772 2772
 }
2773 2773
 
2774 2774
 function icone_base($lien, $texte, $fond, $fonction="", $class="",$javascript=""){
2775
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
2775
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
2776 2776
 }
2777 2777
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction="", $class="",$javascript=""){
2778
-	return icone_base($lien,$texte,$fond,$fonction,"verticale $class",$javascript);
2778
+    return icone_base($lien,$texte,$fond,$fonction,"verticale $class",$javascript);
2779 2779
 }
2780 2780
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction="", $class="",$javascript=""){
2781
-	return icone_base($lien,$texte,$fond,$fonction,"horizontale $class",$javascript);
2781
+    return icone_base($lien,$texte,$fond,$fonction,"horizontale $class",$javascript);
2782 2782
 }
2783 2783
 
2784 2784
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction="", $class="",$confirm=""){
2785
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm);
2785
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm);
2786 2786
 }
2787 2787
 /*
2788 2788
  * Filtre icone pour compatibilite
2789 2789
  * mappe sur icone_base
2790 2790
  */
2791 2791
 function filtre_icone_dist($lien, $texte, $fond, $align="", $fonction="", $class="",$javascript=""){
2792
-	return icone_base($lien,$texte,$fond,$fonction,"verticale $align $class",$javascript);
2792
+    return icone_base($lien,$texte,$fond,$fonction,"verticale $align $class",$javascript);
2793 2793
 }
2794 2794
 
2795 2795
 
@@ -2818,21 +2818,21 @@  discard block
 block discarded – undo
2818 2818
  * @return string
2819 2819
  */
2820 2820
 function bando_images_background(){
2821
-	include_spip('inc/bandeau');
2822
-	// recuperer tous les boutons et leurs images
2823
-	$boutons = definir_barre_boutons(definir_barre_contexte(),true,false);
2824
-
2825
-	$res = "";
2826
-	foreach($boutons as $page => $detail){
2827
-		if ($detail->icone AND strlen(trim($detail->icone)))
2828
-			$res .="\n.navigation_avec_icones #bando1_$page {background-image:url(".$detail->icone.");}";
2829
-		$selecteur = (in_array($page,array('outils_rapides','outils_collaboratifs'))?"":".navigation_avec_icones ");
2830
-		if (is_array($detail->sousmenu))
2831
-			foreach($detail->sousmenu as $souspage=>$sousdetail)
2832
-				if ($sousdetail->icone AND strlen(trim($sousdetail->icone)))
2833
-					$res .="\n$selecteur.bando2_$souspage {background-image:url(".$sousdetail->icone.");}";
2834
-	}
2835
-	return $res;
2821
+    include_spip('inc/bandeau');
2822
+    // recuperer tous les boutons et leurs images
2823
+    $boutons = definir_barre_boutons(definir_barre_contexte(),true,false);
2824
+
2825
+    $res = "";
2826
+    foreach($boutons as $page => $detail){
2827
+        if ($detail->icone AND strlen(trim($detail->icone)))
2828
+            $res .="\n.navigation_avec_icones #bando1_$page {background-image:url(".$detail->icone.");}";
2829
+        $selecteur = (in_array($page,array('outils_rapides','outils_collaboratifs'))?"":".navigation_avec_icones ");
2830
+        if (is_array($detail->sousmenu))
2831
+            foreach($detail->sousmenu as $souspage=>$sousdetail)
2832
+                if ($sousdetail->icone AND strlen(trim($sousdetail->icone)))
2833
+                    $res .="\n$selecteur.bando2_$souspage {background-image:url(".$sousdetail->icone.");}";
2834
+    }
2835
+    return $res;
2836 2836
 }
2837 2837
 
2838 2838
 /**
@@ -2851,17 +2851,17 @@  discard block
 block discarded – undo
2851 2851
  * @return string
2852 2852
  */
2853 2853
 function bouton_action($libelle, $url, $class="", $confirm="", $title="", $callback=""){
2854
-	if ($confirm) {
2855
-		$confirm = "confirm(\"" . attribut_html($confirm) . "\")";
2856
-	  if ($callback)
2857
-		  $callback = "$confirm?($callback):false";
2858
-	  else
2859
-		  $callback = $confirm;
2860
-	}
2861
-	$onclick = $callback?" onclick='return ".addcslashes($callback,"'")."'":"";
2862
-	$title = $title ? " title='$title'" : "";
2863
-	return "<form class='bouton_action_post $class' method='post' action='$url'><div>".form_hidden($url)
2864
-		."<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
2854
+    if ($confirm) {
2855
+        $confirm = "confirm(\"" . attribut_html($confirm) . "\")";
2856
+        if ($callback)
2857
+            $callback = "$confirm?($callback):false";
2858
+        else
2859
+            $callback = $confirm;
2860
+    }
2861
+    $onclick = $callback?" onclick='return ".addcslashes($callback,"'")."'":"";
2862
+    $title = $title ? " title='$title'" : "";
2863
+    return "<form class='bouton_action_post $class' method='post' action='$url'><div>".form_hidden($url)
2864
+        ."<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
2865 2865
 }
2866 2866
 
2867 2867
 
@@ -2872,7 +2872,7 @@  discard block
 block discarded – undo
2872 2872
  * @return string
2873 2873
  */
2874 2874
 function tri_protege_champ($t){
2875
-	return preg_replace(',[^\s\w.+],','',$t);
2875
+    return preg_replace(',[^\s\w.+],','',$t);
2876 2876
 }
2877 2877
 
2878 2878
 /**
@@ -2884,31 +2884,31 @@  discard block
 block discarded – undo
2884 2884
  * @return string
2885 2885
  */
2886 2886
 function tri_champ_order($t, $from=null){
2887
-	if(strncmp($t,'multi ',6)==0){
2888
-		return "multi";
2889
-	}
2890
-
2891
-	$champ = $t;
2892
-
2893
-	if (strncmp($t,'num ',4)==0)
2894
-		$champ = substr($t,4);
2895
-	// enlever les autres espaces non evacues par tri_protege_champ
2896
-	$champ = preg_replace(',\s,','',$champ);
2897
-
2898
-	if (is_array($from)){
2899
-		$trouver_table = charger_fonction('trouver_table','base');
2900
-		foreach($from as $idt=>$table_sql){
2901
-			if ($desc = $trouver_table($table_sql)
2902
-				AND isset($desc['field'][$champ])){
2903
-				$champ = "$idt.$champ";
2904
-				break;
2905
-			}
2906
-		}
2907
-	}
2908
-	if (strncmp($t,'num ',4)==0)
2909
-		return "0+$champ";
2910
-	else
2911
-		return $champ;
2887
+    if(strncmp($t,'multi ',6)==0){
2888
+        return "multi";
2889
+    }
2890
+
2891
+    $champ = $t;
2892
+
2893
+    if (strncmp($t,'num ',4)==0)
2894
+        $champ = substr($t,4);
2895
+    // enlever les autres espaces non evacues par tri_protege_champ
2896
+    $champ = preg_replace(',\s,','',$champ);
2897
+
2898
+    if (is_array($from)){
2899
+        $trouver_table = charger_fonction('trouver_table','base');
2900
+        foreach($from as $idt=>$table_sql){
2901
+            if ($desc = $trouver_table($table_sql)
2902
+                AND isset($desc['field'][$champ])){
2903
+                $champ = "$idt.$champ";
2904
+                break;
2905
+            }
2906
+        }
2907
+    }
2908
+    if (strncmp($t,'num ',4)==0)
2909
+        return "0+$champ";
2910
+    else
2911
+        return $champ;
2912 2912
 }
2913 2913
 
2914 2914
 /**
@@ -2922,16 +2922,16 @@  discard block
 block discarded – undo
2922 2922
  * @return string
2923 2923
  */
2924 2924
 function tri_champ_select($t){
2925
-	if(strncmp($t,'multi ',6)==0){
2926
-		$t = substr($t,6);
2927
-		$t = preg_replace(',\s,','',$t);
2928
-		$t = sql_multi($t,$GLOBALS['spip_lang']);
2929
-		return $t;
2930
-	}
2931
-	if(trim($t)=='hasard'){
2932
-		return 'rand() AS hasard';
2933
-	}
2934
-	return "''";
2925
+    if(strncmp($t,'multi ',6)==0){
2926
+        $t = substr($t,6);
2927
+        $t = preg_replace(',\s,','',$t);
2928
+        $t = sql_multi($t,$GLOBALS['spip_lang']);
2929
+        return $t;
2930
+    }
2931
+    if(trim($t)=='hasard'){
2932
+        return 'rand() AS hasard';
2933
+    }
2934
+    return "''";
2935 2935
 }
2936 2936
 
2937 2937
 
@@ -2953,80 +2953,80 @@  discard block
 block discarded – undo
2953 2953
  * @return string
2954 2954
  */
2955 2955
 function generer_info_entite($id_objet, $type_objet, $info, $etoile=""){
2956
-	global $table_des_traitements;
2957
-	static $trouver_table=null;
2958
-	static $objets;
2959
-
2960
-	// On verifie qu'on a tout ce qu'il faut
2961
-	$id_objet = intval($id_objet);
2962
-	if (!($id_objet and $type_objet and $info))
2963
-		return '';
2964
-
2965
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
2966
-	if (isset($objets[$type_objet]) AND $objets[$type_objet]===false)
2967
-		return '';
2968
-
2969
-	// Si on demande l'url, on retourne direct la fonction
2970
-	if ($info == 'url')
2971
-		return generer_url_entite($id_objet, $type_objet);
2972
-
2973
-	// Sinon on va tout chercher dans la table et on garde en memoire
2974
-	$demande_titre = ($info == 'titre');
2975
-
2976
-	// 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
2977
-	if (!isset($objets[$type_objet][$id_objet])
2978
-	  OR
2979
-	  ($demande_titre AND !isset($objets[$type_objet][$id_objet]['titre']))
2980
-	  ){
2981
-		if (!$trouver_table)
2982
-			$trouver_table = charger_fonction('trouver_table','base');
2983
-		$desc = $trouver_table(table_objet_sql($type_objet));
2984
-		if (!$desc)
2985
-			return $objets[$type_objet] = false;
2986
-
2987
-		// Si on demande le titre, on le gere en interne
2988
-		$champ_titre = "";
2989
-		if ($demande_titre){
2990
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
2991
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre']:'';
2992
-		}
2993
-		include_spip('base/abstract_sql');
2994
-		include_spip('base/connect_sql');
2995
-		$objets[$type_objet][$id_objet] = sql_fetsel(
2996
-			'*'.$champ_titre,
2997
-			$desc['table_sql'],
2998
-			id_table_objet($type_objet).' = '.intval($id_objet)
2999
-		);
3000
-	}
3001
-
3002
-	// Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
3003
-	if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true))
3004
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
3005
-	// Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
3006
-	else if ($generer = charger_fonction("generer_${info}_entite", '', true))
3007
-		$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
3008
-	// Sinon on prend directement le champ SQL tel quel
3009
-	else
3010
-		$info_generee = (isset($objets[$type_objet][$id_objet][$info])?$objets[$type_objet][$id_objet][$info]:'');
3011
-
3012
-	// On va ensuite chercher les traitements automatiques a faire
3013
-	$champ = strtoupper($info);
3014
-	$traitement = isset($table_des_traitements[$champ]) ? $table_des_traitements[$champ] : false;
3015
-	$table_sql = table_objet_sql($type_objet);
3016
-
3017
-	if (!$etoile
3018
-		AND is_array($traitement)
3019
-	  AND (isset($traitement[$table_sql]) OR isset($traitement[0]))){
3020
-	  	include_spip('inc/texte');
3021
-		$traitement = $traitement[isset($traitement[$table_sql]) ? $table_sql : 0];
3022
-		$traitement = str_replace('%s', "'".texte_script($info_generee)."'", $traitement);
3023
-		// FIXME: $connect et $Pile[0] font souvent partie des traitements.
3024
-		// on les definit pour eviter des notices, mais ce fonctionnement est a ameliorer !
3025
-		$connect = ""; $Pile = array(0 => array('id_objet'=>$id_objet,'objet'=>$type_objet));
3026
-		eval("\$info_generee = $traitement;");
3027
-	}
3028
-
3029
-	return $info_generee;
2956
+    global $table_des_traitements;
2957
+    static $trouver_table=null;
2958
+    static $objets;
2959
+
2960
+    // On verifie qu'on a tout ce qu'il faut
2961
+    $id_objet = intval($id_objet);
2962
+    if (!($id_objet and $type_objet and $info))
2963
+        return '';
2964
+
2965
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
2966
+    if (isset($objets[$type_objet]) AND $objets[$type_objet]===false)
2967
+        return '';
2968
+
2969
+    // Si on demande l'url, on retourne direct la fonction
2970
+    if ($info == 'url')
2971
+        return generer_url_entite($id_objet, $type_objet);
2972
+
2973
+    // Sinon on va tout chercher dans la table et on garde en memoire
2974
+    $demande_titre = ($info == 'titre');
2975
+
2976
+    // 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
2977
+    if (!isset($objets[$type_objet][$id_objet])
2978
+      OR
2979
+      ($demande_titre AND !isset($objets[$type_objet][$id_objet]['titre']))
2980
+        ){
2981
+        if (!$trouver_table)
2982
+            $trouver_table = charger_fonction('trouver_table','base');
2983
+        $desc = $trouver_table(table_objet_sql($type_objet));
2984
+        if (!$desc)
2985
+            return $objets[$type_objet] = false;
2986
+
2987
+        // Si on demande le titre, on le gere en interne
2988
+        $champ_titre = "";
2989
+        if ($demande_titre){
2990
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
2991
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre']:'';
2992
+        }
2993
+        include_spip('base/abstract_sql');
2994
+        include_spip('base/connect_sql');
2995
+        $objets[$type_objet][$id_objet] = sql_fetsel(
2996
+            '*'.$champ_titre,
2997
+            $desc['table_sql'],
2998
+            id_table_objet($type_objet).' = '.intval($id_objet)
2999
+        );
3000
+    }
3001
+
3002
+    // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
3003
+    if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true))
3004
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
3005
+    // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
3006
+    else if ($generer = charger_fonction("generer_${info}_entite", '', true))
3007
+        $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
3008
+    // Sinon on prend directement le champ SQL tel quel
3009
+    else
3010
+        $info_generee = (isset($objets[$type_objet][$id_objet][$info])?$objets[$type_objet][$id_objet][$info]:'');
3011
+
3012
+    // On va ensuite chercher les traitements automatiques a faire
3013
+    $champ = strtoupper($info);
3014
+    $traitement = isset($table_des_traitements[$champ]) ? $table_des_traitements[$champ] : false;
3015
+    $table_sql = table_objet_sql($type_objet);
3016
+
3017
+    if (!$etoile
3018
+        AND is_array($traitement)
3019
+      AND (isset($traitement[$table_sql]) OR isset($traitement[0]))){
3020
+            include_spip('inc/texte');
3021
+        $traitement = $traitement[isset($traitement[$table_sql]) ? $table_sql : 0];
3022
+        $traitement = str_replace('%s', "'".texte_script($info_generee)."'", $traitement);
3023
+        // FIXME: $connect et $Pile[0] font souvent partie des traitements.
3024
+        // on les definit pour eviter des notices, mais ce fonctionnement est a ameliorer !
3025
+        $connect = ""; $Pile = array(0 => array('id_objet'=>$id_objet,'objet'=>$type_objet));
3026
+        eval("\$info_generee = $traitement;");
3027
+    }
3028
+
3029
+    return $info_generee;
3030 3030
 }
3031 3031
 
3032 3032
 /**
@@ -3037,14 +3037,14 @@  discard block
 block discarded – undo
3037 3037
  * @return string
3038 3038
  */
3039 3039
 function wrap($texte,$wrap) {
3040
-	$balises = extraire_balises($wrap);
3041
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS",$wrap, $regs, PREG_PATTERN_ORDER)) {
3042
-		$texte = $wrap . $texte;
3043
-		$regs = array_reverse($regs[1]);
3044
-		$wrap = "</".implode("></",$regs).">";
3045
-		$texte = $texte . $wrap;
3046
-	}
3047
-	return $texte;
3040
+    $balises = extraire_balises($wrap);
3041
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS",$wrap, $regs, PREG_PATTERN_ORDER)) {
3042
+        $texte = $wrap . $texte;
3043
+        $regs = array_reverse($regs[1]);
3044
+        $wrap = "</".implode("></",$regs).">";
3045
+        $texte = $texte . $wrap;
3046
+    }
3047
+    return $texte;
3048 3048
 }
3049 3049
 
3050 3050
 
@@ -3064,39 +3064,39 @@  discard block
 block discarded – undo
3064 3064
  * @return array|mixed|string
3065 3065
  */
3066 3066
 function filtre_print_dist($u, $join="<br />", $indent=0) {
3067
-	if (is_string($u)){
3068
-		$u = typo($u);
3069
-		return $u;
3070
-	}
3071
-
3072
-	// caster $u en array si besoin
3073
-	if (is_object($u))
3074
-		$u = (array) $u;
3075
-
3076
-	if (is_array($u)){
3077
-		$out = "";
3078
-		// toutes les cles sont numeriques ?
3079
-		// et aucun enfant n'est un tableau
3080
-		// liste simple separee par des virgules
3081
-		$numeric_keys = array_map('is_numeric',array_keys($u));
3082
-		$array_values = array_map('is_array',$u);
3083
-		$object_values = array_map('is_object',$u);
3084
-		if (array_sum($numeric_keys)==count($numeric_keys)
3085
-		  AND !array_sum($array_values)
3086
-		  AND !array_sum($object_values)){
3087
-			return join(", ", array_map('filtre_print_dist', $u));
3088
-		}
3089
-
3090
-		// sinon on passe a la ligne et on indente
3091
-		$i_str = str_pad("",$indent," ");
3092
-		foreach($u as $k => $v){
3093
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v,$join,$indent+2);
3094
-		}
3095
-		return $out;
3096
-	}
3097
-
3098
-	// on sait pas quoi faire...
3099
-	return $u;
3067
+    if (is_string($u)){
3068
+        $u = typo($u);
3069
+        return $u;
3070
+    }
3071
+
3072
+    // caster $u en array si besoin
3073
+    if (is_object($u))
3074
+        $u = (array) $u;
3075
+
3076
+    if (is_array($u)){
3077
+        $out = "";
3078
+        // toutes les cles sont numeriques ?
3079
+        // et aucun enfant n'est un tableau
3080
+        // liste simple separee par des virgules
3081
+        $numeric_keys = array_map('is_numeric',array_keys($u));
3082
+        $array_values = array_map('is_array',$u);
3083
+        $object_values = array_map('is_object',$u);
3084
+        if (array_sum($numeric_keys)==count($numeric_keys)
3085
+          AND !array_sum($array_values)
3086
+          AND !array_sum($object_values)){
3087
+            return join(", ", array_map('filtre_print_dist', $u));
3088
+        }
3089
+
3090
+        // sinon on passe a la ligne et on indente
3091
+        $i_str = str_pad("",$indent," ");
3092
+        foreach($u as $k => $v){
3093
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v,$join,$indent+2);
3094
+        }
3095
+        return $out;
3096
+    }
3097
+
3098
+    // on sait pas quoi faire...
3099
+    return $u;
3100 3100
 }
3101 3101
 
3102 3102
 
@@ -3109,9 +3109,9 @@  discard block
 block discarded – undo
3109 3109
  * @return string
3110 3110
  */
3111 3111
 function objet_info($objet,$info){
3112
-	$table = table_objet_sql($objet);
3113
-	$infos = lister_tables_objets_sql($table);
3114
-	return (isset($infos[$info])?$infos[$info]:'');
3112
+    $table = table_objet_sql($objet);
3113
+    $infos = lister_tables_objets_sql($table);
3114
+    return (isset($infos[$info])?$infos[$info]:'');
3115 3115
 }
3116 3116
 
3117 3117
 /**
@@ -3122,10 +3122,10 @@  discard block
 block discarded – undo
3122 3122
  * @return mixed|string
3123 3123
  */
3124 3124
 function objet_afficher_nb($nb, $objet){
3125
-	if (!$nb)
3126
-		return _T(objet_info($objet,'info_aucun_objet'));
3127
-	else
3128
-		return _T(objet_info($objet,$nb==1?'info_1_objet':'info_nb_objets'),array('nb'=>$nb));
3125
+    if (!$nb)
3126
+        return _T(objet_info($objet,'info_aucun_objet'));
3127
+    else
3128
+        return _T(objet_info($objet,$nb==1?'info_1_objet':'info_nb_objets'),array('nb'=>$nb));
3129 3129
 }
3130 3130
 
3131 3131
 /**
@@ -3136,10 +3136,10 @@  discard block
 block discarded – undo
3136 3136
  * @return string
3137 3137
  */
3138 3138
 function objet_icone($objet,$taille=24){
3139
-	$icone = objet_info($objet,'icone_objet')."-".$taille.".png";
3140
-	$icone = chemin_image($icone);
3141
-	$balise_img = charger_filtre('balise_img');
3142
-	return $icone?$balise_img($icone,_T(objet_info($objet,'texte_objet'))):'';
3139
+    $icone = objet_info($objet,'icone_objet')."-".$taille.".png";
3140
+    $icone = chemin_image($icone);
3141
+    $balise_img = charger_filtre('balise_img');
3142
+    return $icone?$balise_img($icone,_T(objet_info($objet,'texte_objet'))):'';
3143 3143
 }
3144 3144
 
3145 3145
 /**
@@ -3153,14 +3153,14 @@  discard block
 block discarded – undo
3153 3153
  * @return string      Code HTML
3154 3154
  */
3155 3155
 function insert_head_css_conditionnel($flux){
3156
-	if (strpos($flux,'<!-- insert_head_css -->')===false
3157
-		AND $p=strpos($flux,'<!-- insert_head -->')){
3158
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
3159
-		if ($p1 = stripos($flux,'<script src=') AND $p1<$p)
3160
-			$p = $p1;
3161
-		$flux = substr_replace($flux,pipeline('insert_head_css','<!-- insert_head_css -->'),$p,0);
3162
-	}
3163
-	return $flux;
3156
+    if (strpos($flux,'<!-- insert_head_css -->')===false
3157
+        AND $p=strpos($flux,'<!-- insert_head -->')){
3158
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
3159
+        if ($p1 = stripos($flux,'<script src=') AND $p1<$p)
3160
+            $p = $p1;
3161
+        $flux = substr_replace($flux,pipeline('insert_head_css','<!-- insert_head_css -->'),$p,0);
3162
+    }
3163
+    return $flux;
3164 3164
 }
3165 3165
 
3166 3166
 /**
@@ -3178,57 +3178,57 @@  discard block
 block discarded – undo
3178 3178
  * @return string
3179 3179
  */
3180 3180
 function produire_fond_statique($fond, $contexte=array(), $options = array(), $connect=''){
3181
-	if (isset($contexte['format'])){
3182
-		$extension = $contexte['format'];
3183
-		unset($contexte['format']);
3184
-	}
3185
-	else {
3186
-		$extension = "html";
3187
-		if (preg_match(',[.](css|js|json)$,',$fond,$m))
3188
-			$extension = $m[1];
3189
-	}
3190
-	// recuperer le contenu produit par le squelette
3191
-	$options['raw'] = true;
3192
-	$cache = recuperer_fond($fond,$contexte,$options,$connect);
3181
+    if (isset($contexte['format'])){
3182
+        $extension = $contexte['format'];
3183
+        unset($contexte['format']);
3184
+    }
3185
+    else {
3186
+        $extension = "html";
3187
+        if (preg_match(',[.](css|js|json)$,',$fond,$m))
3188
+            $extension = $m[1];
3189
+    }
3190
+    // recuperer le contenu produit par le squelette
3191
+    $options['raw'] = true;
3192
+    $cache = recuperer_fond($fond,$contexte,$options,$connect);
3193 3193
 	
3194
-	// calculer le nom de la css
3195
-	$dir_var = sous_repertoire (_DIR_VAR, 'cache-'.$extension);
3196
-	$nom_safe = preg_replace(",\W,",'_',str_replace('.','_',$fond));
3197
-	$filename = $dir_var . $extension."dyn-$nom_safe-".substr(md5($fond.serialize($contexte).$connect),0,8) .".$extension";
3198
-
3199
-	// mettre a jour le fichier si il n'existe pas
3200
-	// ou trop ancien
3201
-	// le dernier fichier produit est toujours suffixe par .last
3202
-	// et recopie sur le fichier cible uniquement si il change
3203
-	if (!file_exists($filename)
3204
-		OR !file_exists($filename.".last")
3205
-		OR (isset($cache['lastmodified']) AND $cache['lastmodified'] AND filemtime($filename.".last")<$cache['lastmodified'])
3206
-		OR (defined('_VAR_MODE') AND _VAR_MODE=='recalcul')) {
3207
-		$contenu = $cache['texte'];
3208
-		// passer les urls en absolu si c'est une css
3209
-		if ($extension=="css")
3210
-			$contenu = urls_absolues_css($contenu, test_espace_prive()?generer_url_ecrire('accueil'):generer_url_public($fond));
3194
+    // calculer le nom de la css
3195
+    $dir_var = sous_repertoire (_DIR_VAR, 'cache-'.$extension);
3196
+    $nom_safe = preg_replace(",\W,",'_',str_replace('.','_',$fond));
3197
+    $filename = $dir_var . $extension."dyn-$nom_safe-".substr(md5($fond.serialize($contexte).$connect),0,8) .".$extension";
3198
+
3199
+    // mettre a jour le fichier si il n'existe pas
3200
+    // ou trop ancien
3201
+    // le dernier fichier produit est toujours suffixe par .last
3202
+    // et recopie sur le fichier cible uniquement si il change
3203
+    if (!file_exists($filename)
3204
+        OR !file_exists($filename.".last")
3205
+        OR (isset($cache['lastmodified']) AND $cache['lastmodified'] AND filemtime($filename.".last")<$cache['lastmodified'])
3206
+        OR (defined('_VAR_MODE') AND _VAR_MODE=='recalcul')) {
3207
+        $contenu = $cache['texte'];
3208
+        // passer les urls en absolu si c'est une css
3209
+        if ($extension=="css")
3210
+            $contenu = urls_absolues_css($contenu, test_espace_prive()?generer_url_ecrire('accueil'):generer_url_public($fond));
3211 3211
 		
3212
-		// ne pas insérer de commentaire si c'est du json
3213
-		if ($extension!="json") {
3214
-			$comment = "/* #PRODUIRE{fond=$fond";
3215
-			foreach($contexte as $k=>$v)
3216
-				$comment .= ",$k=$v";
3217
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
3218
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
3219
-			$comment .="}\n   md5:".md5($contenu)." */\n";
3220
-		}
3221
-		// et ecrire le fichier
3222
-		ecrire_fichier($filename.".last",$comment.$contenu);
3223
-		// regarder si on recopie
3224
-		if (!file_exists($filename)
3225
-		  OR md5_file($filename)!==md5_file($filename.".last")){
3226
-			@copy($filename.".last",$filename);
3227
-			spip_clearstatcache(true,$filename); // eviter que PHP ne reserve le vieux timestamp
3228
-		}
3229
-	}
3212
+        // ne pas insérer de commentaire si c'est du json
3213
+        if ($extension!="json") {
3214
+            $comment = "/* #PRODUIRE{fond=$fond";
3215
+            foreach($contexte as $k=>$v)
3216
+                $comment .= ",$k=$v";
3217
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
3218
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
3219
+            $comment .="}\n   md5:".md5($contenu)." */\n";
3220
+        }
3221
+        // et ecrire le fichier
3222
+        ecrire_fichier($filename.".last",$comment.$contenu);
3223
+        // regarder si on recopie
3224
+        if (!file_exists($filename)
3225
+          OR md5_file($filename)!==md5_file($filename.".last")){
3226
+            @copy($filename.".last",$filename);
3227
+            spip_clearstatcache(true,$filename); // eviter que PHP ne reserve le vieux timestamp
3228
+        }
3229
+    }
3230 3230
 	
3231
-	return $filename;
3231
+    return $filename;
3232 3232
 }
3233 3233
 
3234 3234
 /**
@@ -3239,9 +3239,9 @@  discard block
 block discarded – undo
3239 3239
  * @return string
3240 3240
  */
3241 3241
 function timestamp($fichier){
3242
-	if (!$fichier OR !file_exists($fichier)) return $fichier;
3243
-	$m = filemtime($fichier);
3244
-	return "$fichier?$m";
3242
+    if (!$fichier OR !file_exists($fichier)) return $fichier;
3243
+    $m = filemtime($fichier);
3244
+    return "$fichier?$m";
3245 3245
 }
3246 3246
 
3247 3247
 /**
@@ -3251,8 +3251,8 @@  discard block
 block discarded – undo
3251 3251
  * @return mixed
3252 3252
  */
3253 3253
 function filtre_nettoyer_titre_email_dist($titre){
3254
-	include_spip('inc/envoyer_mail');
3255
-	return nettoyer_titre_email($titre);
3254
+    include_spip('inc/envoyer_mail');
3255
+    return nettoyer_titre_email($titre);
3256 3256
 }
3257 3257
 
3258 3258
 /**
@@ -3272,8 +3272,8 @@  discard block
 block discarded – undo
3272 3272
  * @return string
3273 3273
  */
3274 3274
 function filtre_chercher_rubrique_dist($titre,$id_objet, $id_parent, $objet, $id_secteur, $restreint,$actionable = false, $retour_sans_cadre=false){
3275
-	include_spip('inc/filtres_ecrire');
3276
-	return chercher_rubrique($titre,$id_objet, $id_parent, $objet, $id_secteur, $restreint,$actionable, $retour_sans_cadre);
3275
+    include_spip('inc/filtres_ecrire');
3276
+    return chercher_rubrique($titre,$id_objet, $id_parent, $objet, $id_secteur, $restreint,$actionable, $retour_sans_cadre);
3277 3277
 }
3278 3278
 
3279 3279
 /**
@@ -3289,45 +3289,45 @@  discard block
 block discarded – undo
3289 3289
  * @return string
3290 3290
  */
3291 3291
 function sinon_interdire_acces($ok=false, $url='', $statut=0){
3292
-	if ($ok) return '';
3292
+    if ($ok) return '';
3293 3293
 	
3294
-	// Vider tous les tampons
3295
-	$level = @ob_get_level();
3296
-	while ($level--)
3297
-		@ob_end_clean();
3294
+    // Vider tous les tampons
3295
+    $level = @ob_get_level();
3296
+    while ($level--)
3297
+        @ob_end_clean();
3298 3298
 	
3299
-	include_spip('inc/headers');
3300
-	$statut = intval($statut);
3299
+    include_spip('inc/headers');
3300
+    $statut = intval($statut);
3301 3301
 	
3302
-	// Si aucun argument on essaye de deviner quoi faire par défaut
3303
-	if (!$url and !$statut){
3304
-		// Si on est dans l'espace privé, on génère du 403 Forbidden
3305
-		if (test_espace_prive()){
3306
-			http_status(403);
3307
-			$echec = charger_fonction('403','exec');
3308
-			$echec();
3309
-		}
3310
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
3311
-		else{
3312
-			$statut = 404;
3313
-		}
3314
-	}
3302
+    // Si aucun argument on essaye de deviner quoi faire par défaut
3303
+    if (!$url and !$statut){
3304
+        // Si on est dans l'espace privé, on génère du 403 Forbidden
3305
+        if (test_espace_prive()){
3306
+            http_status(403);
3307
+            $echec = charger_fonction('403','exec');
3308
+            $echec();
3309
+        }
3310
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
3311
+        else{
3312
+            $statut = 404;
3313
+        }
3314
+    }
3315 3315
 	
3316
-	// On suit les directives indiquées dans les deux arguments
3316
+    // On suit les directives indiquées dans les deux arguments
3317 3317
 	
3318
-	// S'il y a un statut
3319
-	if ($statut){
3320
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
3321
-		http_status($statut);
3322
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
3323
-		if ($statut >= 400 and !$url)
3324
-			echo recuperer_fond("$statut");
3325
-	}
3318
+    // S'il y a un statut
3319
+    if ($statut){
3320
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
3321
+        http_status($statut);
3322
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
3323
+        if ($statut >= 400 and !$url)
3324
+            echo recuperer_fond("$statut");
3325
+    }
3326 3326
 	
3327
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
3328
-	if ($url) redirige_par_entete($url, '', $statut);
3327
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
3328
+    if ($url) redirige_par_entete($url, '', $statut);
3329 3329
 	
3330
-	exit;
3330
+    exit;
3331 3331
 }
3332 3332
 
3333 3333
 /**
@@ -3337,9 +3337,9 @@  discard block
 block discarded – undo
3337 3337
  * @return string
3338 3338
  */
3339 3339
 function filtre_compacte_dist($source, $format = null){
3340
-	if (function_exists('compacte'))
3341
-		return compacte($source, $format);
3342
-	return $source;
3340
+    if (function_exists('compacte'))
3341
+        return compacte($source, $format);
3342
+    return $source;
3343 3343
 }
3344 3344
 
3345 3345
 ?>
Please login to merge, or discard this patch.
Switch Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -1019,79 +1019,79 @@
 block discarded – undo
1019 1019
 	else $avjc = false;
1020 1020
 
1021 1021
 	switch ($vue) {
1022
-	case 'saison':
1023
-	case 'saison_annee':
1024
-		$saison = '';
1025
-		if ($mois > 0){
1026
-			$saison = 1;
1027
-			if (($mois == 3 AND $jour >= 21) OR $mois > 3) $saison = 2;
1028
-			if (($mois == 6 AND $jour >= 21) OR $mois > 6) $saison = 3;
1029
-			if (($mois == 9 AND $jour >= 21) OR $mois > 9) $saison = 4;
1030
-			if (($mois == 12 AND $jour >= 21) OR $mois > 12) $saison = 1;
1031
-		}
1032
-		if($vue == 'saison')
1033
-			return $saison?_T('date_saison_'.$saison):'';
1034
-		else
1035
-			return $saison?trim(_T('date_fmt_saison_annee', array('saison'=>_T('date_saison_'.$saison), 'annee'=>$annee))) :'';
1036
-
1037
-	case 'court':
1038
-		if ($avjc) return $annee;
1039
-		$a = ((isset($options['annee_courante']) AND $options['annee_courante'])?$options['annee_courante']:date('Y'));
1040
-		if ($annee < ($a - 100) OR $annee > ($a + 100)) return $annee;
1041
-		if ($annee != $a) return _T('date_fmt_mois_annee', array ('mois'=>$mois, 'nommois'=>spip_ucfirst($nommois), 'annee'=>$annee));
1042
-		return _T('date_fmt_jour_mois', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1043
-
1044
-	case 'jourcourt':
1045
-		if ($avjc) return $annee;
1046
-		$a = ((isset($options['annee_courante']) AND $options['annee_courante'])?$options['annee_courante']:date('Y'));
1047
-		if ($annee < ($a - 100) OR $annee > ($a + 100)) return $annee;
1048
-		if ($annee != $a) return _T('date_fmt_jour_mois_annee', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1049
-		return _T('date_fmt_jour_mois', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1050
-
1051
-	case 'entier':
1052
-		if ($avjc) return $annee;
1053
-		if ($jour)
1054
-			return _T('date_fmt_jour_mois_annee', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1055
-		elseif ($mois)
1056
-			return trim(_T('date_fmt_mois_annee', array ('mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)));
1057
-		else
1058
-			return $annee;
1059
-
1060
-	case 'nom_mois':
1061
-		$param = ((isset($options['param']) AND $options['param']) ? '_'.$options['param'] : '');
1062
-		if ($param and $mois) {
1063
-			return _T('date_mois_'.$mois.$param);
1064
-		}
1065
-		return $nommois;
1066
-
1067
-	case 'mois':
1068
-		return sprintf("%02s",$mois);
1069
-
1070
-	case 'jour':
1071
-		return $jour;
1072
-
1073
-	case 'journum':
1074
-		return $journum;
1075
-
1076
-	case 'nom_jour':
1077
-		if (!$mois OR !$njour)
1078
-			return '';
1079
-		$nom = mktime(1,1,1,$mois,$njour,$annee);
1080
-		$nom = 1+date('w',$nom);
1081
-		$param = ((isset($options['param']) AND $options['param']) ? '_'.$options['param'] : '');
1082
-		return _T('date_jour_'.$nom.$param);
1083
-
1084
-	case 'mois_annee':
1085
-		if ($avjc) return $annee;
1086
-		return trim(_T('date_fmt_mois_annee', array('mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)));
1087
-
1088
-	case 'annee':
1089
-		return $annee;
1090
-
1091
-	// Cas d'une vue non definie : retomber sur le format
1092
-	// de date propose par http://www.php.net/date
1093
-	default:
1094
-		return date($vue, strtotime($numdate));
1022
+	    case 'saison':
1023
+	    case 'saison_annee':
1024
+		    $saison = '';
1025
+		    if ($mois > 0){
1026
+			    $saison = 1;
1027
+			    if (($mois == 3 AND $jour >= 21) OR $mois > 3) $saison = 2;
1028
+			    if (($mois == 6 AND $jour >= 21) OR $mois > 6) $saison = 3;
1029
+			    if (($mois == 9 AND $jour >= 21) OR $mois > 9) $saison = 4;
1030
+			    if (($mois == 12 AND $jour >= 21) OR $mois > 12) $saison = 1;
1031
+		    }
1032
+		    if($vue == 'saison')
1033
+			    return $saison?_T('date_saison_'.$saison):'';
1034
+		    else
1035
+			    return $saison?trim(_T('date_fmt_saison_annee', array('saison'=>_T('date_saison_'.$saison), 'annee'=>$annee))) :'';
1036
+
1037
+	    case 'court':
1038
+		    if ($avjc) return $annee;
1039
+		    $a = ((isset($options['annee_courante']) AND $options['annee_courante'])?$options['annee_courante']:date('Y'));
1040
+		    if ($annee < ($a - 100) OR $annee > ($a + 100)) return $annee;
1041
+		    if ($annee != $a) return _T('date_fmt_mois_annee', array ('mois'=>$mois, 'nommois'=>spip_ucfirst($nommois), 'annee'=>$annee));
1042
+		    return _T('date_fmt_jour_mois', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1043
+
1044
+	    case 'jourcourt':
1045
+		    if ($avjc) return $annee;
1046
+		    $a = ((isset($options['annee_courante']) AND $options['annee_courante'])?$options['annee_courante']:date('Y'));
1047
+		    if ($annee < ($a - 100) OR $annee > ($a + 100)) return $annee;
1048
+		    if ($annee != $a) return _T('date_fmt_jour_mois_annee', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1049
+		    return _T('date_fmt_jour_mois', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1050
+
1051
+	    case 'entier':
1052
+		    if ($avjc) return $annee;
1053
+		    if ($jour)
1054
+			    return _T('date_fmt_jour_mois_annee', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1055
+		    elseif ($mois)
1056
+			    return trim(_T('date_fmt_mois_annee', array ('mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)));
1057
+		    else
1058
+			    return $annee;
1059
+
1060
+	    case 'nom_mois':
1061
+		    $param = ((isset($options['param']) AND $options['param']) ? '_'.$options['param'] : '');
1062
+		    if ($param and $mois) {
1063
+			    return _T('date_mois_'.$mois.$param);
1064
+		    }
1065
+		    return $nommois;
1066
+
1067
+	    case 'mois':
1068
+		    return sprintf("%02s",$mois);
1069
+
1070
+	    case 'jour':
1071
+		    return $jour;
1072
+
1073
+	    case 'journum':
1074
+		    return $journum;
1075
+
1076
+	    case 'nom_jour':
1077
+		    if (!$mois OR !$njour)
1078
+			    return '';
1079
+		    $nom = mktime(1,1,1,$mois,$njour,$annee);
1080
+		    $nom = 1+date('w',$nom);
1081
+		    $param = ((isset($options['param']) AND $options['param']) ? '_'.$options['param'] : '');
1082
+		    return _T('date_jour_'.$nom.$param);
1083
+
1084
+	    case 'mois_annee':
1085
+		    if ($avjc) return $annee;
1086
+		    return trim(_T('date_fmt_mois_annee', array('mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)));
1087
+
1088
+	    case 'annee':
1089
+		    return $annee;
1090
+
1091
+	    // Cas d'une vue non definie : retomber sur le format
1092
+	    // de date propose par http://www.php.net/date
1093
+	    default:
1094
+		    return date($vue, strtotime($numdate));
1095 1095
 	}
1096 1096
 }
1097 1097
 
Please login to merge, or discard this patch.
Braces   +769 added lines, -492 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 include_spip('inc/charsets');
16 18
 include_spip('inc/filtres_mini');
@@ -41,7 +43,9 @@  discard block
 block discarded – undo
41 43
  * @return string
42 44
  */
43 45
 function chercher_filtre($fonc, $default=NULL) {
44
-	if (!$fonc) return $default;
46
+	if (!$fonc) {
47
+	    return $default;
48
+	}
45 49
 	// Cas des types mime, sans confondre avec les appels de fonction de classe
46 50
 	// Foo::Bar
47 51
 	// qui peuvent etre avec un namespace : space\Foo::Bar
@@ -50,14 +54,16 @@  discard block
 block discarded – undo
50 54
 		$f = chercher_filtre($nom);
51 55
 		// cas du sous-type MIME sans filtre associe, passer au type:
52 56
 		// si filtre_text_plain pas defini, passe a filtre_text
53
-		if (!$f AND $nom!==$fonc)
54
-			$f = chercher_filtre(preg_replace(',\W.*$,','', $fonc));
57
+		if (!$f AND $nom!==$fonc) {
58
+					$f = chercher_filtre(preg_replace(',\W.*$,','', $fonc));
59
+		}
55 60
 		return $f;
56 61
 	}
57 62
 	foreach (
58 63
 	array('filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc) as $f){
59
-		if (isset( $GLOBALS['spip_matrice'][$f]) AND is_string($g = $GLOBALS['spip_matrice'][$f]))
60
-			find_in_path($g,'', true);
64
+		if (isset( $GLOBALS['spip_matrice'][$f]) AND is_string($g = $GLOBALS['spip_matrice'][$f])) {
65
+					find_in_path($g,'', true);
66
+		}
61 67
 		if (function_exists($f)
62 68
 		OR (preg_match("/^(\w*)::(\w*)$/", $f, $regs)
63 69
 			AND is_callable(array($regs[1], $regs[2]))
@@ -92,8 +98,11 @@  discard block
 block discarded – undo
92 98
 function appliquer_filtre($arg, $filtre, $force=NULL) {
93 99
 	$f = chercher_filtre($filtre);
94 100
 	if (!$f) {
95
-		if (!$force) return '';
96
-		else return $arg;
101
+		if (!$force) {
102
+		    return '';
103
+		} else {
104
+		    return $arg;
105
+		}
97 106
 	}
98 107
 
99 108
 	$args = func_get_args();
@@ -106,8 +115,9 @@  discard block
 block discarded – undo
106 115
 // http://doc.spip.org/@spip_version
107 116
 function spip_version() {
108 117
 	$version = $GLOBALS['spip_version_affichee'];
109
-	if ($svn_revision = version_svn_courante(_DIR_RACINE))
110
-		$version .= ($svn_revision<0 ? ' SVN':'').' ['.abs($svn_revision).']';
118
+	if ($svn_revision = version_svn_courante(_DIR_RACINE)) {
119
+			$version .= ($svn_revision<0 ? ' SVN':'').' ['.abs($svn_revision).']';
120
+	}
111 121
 	return $version;
112 122
 }
113 123
 
@@ -118,12 +128,15 @@  discard block
 block discarded – undo
118 128
 // on est negatif si on est sur .svn, et positif si on utilise svn.revision
119 129
 // http://doc.spip.org/@version_svn_courante
120 130
 function version_svn_courante($dir) {
121
-	if (!$dir) $dir = '.';
131
+	if (!$dir) {
132
+	    $dir = '.';
133
+	}
122 134
 
123 135
 	// version installee par paquet ZIP
124 136
 	if (lire_fichier($dir.'/svn.revision', $c)
125
-	AND preg_match(',Revision: (\d+),', $c, $d))
126
-		return intval($d[1]);
137
+	AND preg_match(',Revision: (\d+),', $c, $d)) {
138
+			return intval($d[1]);
139
+	}
127 140
 
128 141
 	// version installee par SVN
129 142
 	if (lire_fichier($dir . '/.svn/entries', $c)
@@ -135,8 +148,9 @@  discard block
 block discarded – undo
135 148
 	OR
136 149
 	(preg_match(',^\d.*dir[\r\n]+(\d+),ms', $c, $r1) # svn >= 1.4
137 150
 	AND $v = $r1[1]
138
-	)))
139
-		return -$v;
151
+	))) {
152
+			return -$v;
153
+	}
140 154
 
141 155
 	// Bug ou paquet fait main
142 156
 	return 0;
@@ -175,13 +189,12 @@  discard block
 block discarded – undo
175 189
 		$GLOBALS['spip_matrice'][$filtre] = true;
176 190
 	}
177 191
 	$tous = func_get_args();
178
-	if (substr($filtre,0,6)=='image_' && $GLOBALS['spip_matrice'][$filtre])
179
-		return image_filtrer($tous);
180
-	elseif($f = chercher_filtre($filtre)) {
192
+	if (substr($filtre,0,6)=='image_' && $GLOBALS['spip_matrice'][$filtre]) {
193
+			return image_filtrer($tous);
194
+	} elseif($f = chercher_filtre($filtre)) {
181 195
 		array_shift($tous);
182 196
 		return call_user_func_array($f, $tous);
183
-	}
184
-	else {
197
+	} else {
185 198
 		// le filtre n'existe pas, on provoque une erreur
186 199
 		$msg = array('zbug_erreur_filtre', array('filtre'=>texte_script($filtre)));
187 200
 		erreur_squelette($msg);
@@ -213,8 +226,9 @@  discard block
 block discarded – undo
213 226
 	) . var_export($val, true);
214 227
 
215 228
 	include_spip('inc/autoriser');
216
-	if (autoriser('webmestre'))
217
-		echo "<div class='spip_debug'>\n",$debug,"</div>\n";
229
+	if (autoriser('webmestre')) {
230
+			echo "<div class='spip_debug'>\n",$debug,"</div>\n";
231
+	}
218 232
 
219 233
 	spip_log($debug, 'debug');
220 234
 
@@ -232,7 +246,9 @@  discard block
 block discarded – undo
232 246
 function image_filtrer($args){
233 247
 	$filtre = array_shift($args); # enlever $filtre
234 248
 	$texte = array_shift($args);
235
-	if (!strlen($texte)) return;
249
+	if (!strlen($texte)) {
250
+	    return;
251
+	}
236 252
 	find_in_path('filtres_images_mini.php','inc/', true);
237 253
 	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
238 254
 	// Cas du nom de fichier local
@@ -260,8 +276,9 @@  discard block
 block discarded – undo
260 276
 					// En cas de span spip_documents, modifier le style=...width:
261 277
 					if($tag[1]){
262 278
 						$w = extraire_attribut($reduit, 'width');
263
-						if (!$w AND preg_match(",width:\s*(\d+)px,S",extraire_attribut($reduit,'style'),$regs))
264
-							$w = $regs[1];
279
+						if (!$w AND preg_match(",width:\s*(\d+)px,S",extraire_attribut($reduit,'style'),$regs)) {
280
+													$w = $regs[1];
281
+						}
265 282
 						if ($w AND ($style = extraire_attribut($tag[1], 'style'))){
266 283
 							$style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
267 284
 							$replace = inserer_attribut($tag[1], 'style', $style);
@@ -302,8 +319,9 @@  discard block
 block discarded – undo
302 319
 
303 320
 	$logo = extraire_attribut($img,'src');
304 321
 
305
-	if (!$logo) $logo = $img;
306
-	else {
322
+	if (!$logo) {
323
+	    $logo = $img;
324
+	} else {
307 325
 		$srcWidth = extraire_attribut($img,'width');
308 326
 		$srcHeight = extraire_attribut($img,'height');
309 327
 	}
@@ -315,40 +333,55 @@  discard block
 block discarded – undo
315 333
 		$fichier = copie_locale($logo);
316 334
 		$logo = $fichier ? _DIR_RACINE . $fichier : $logo;
317 335
 	}
318
-	if (($p=strpos($logo,'?'))!==FALSE)
319
-		$logo=substr($logo,0,$p);
336
+	if (($p=strpos($logo,'?'))!==FALSE) {
337
+			$logo=substr($logo,0,$p);
338
+	}
320 339
 
321 340
 	$srcsize = false;
322
-	if (isset($largeur_img[$logo]))
323
-		$srcWidth = $largeur_img[$logo];
324
-	if (isset($hauteur_img[$logo]))
325
-		$srcHeight = $hauteur_img[$logo];
341
+	if (isset($largeur_img[$logo])) {
342
+			$srcWidth = $largeur_img[$logo];
343
+	}
344
+	if (isset($hauteur_img[$logo])) {
345
+			$srcHeight = $hauteur_img[$logo];
346
+	}
326 347
 	if (!$srcWidth OR !$srcHeight){
327 348
 		if (file_exists($logo)
328 349
 			AND $srcsize = @getimagesize($logo)){
329
-			if (!$srcWidth)	$largeur_img[$logo] = $srcWidth = $srcsize[0];
330
-			if (!$srcHeight)	$hauteur_img[$logo] = $srcHeight = $srcsize[1];
350
+			if (!$srcWidth) {
351
+			    $largeur_img[$logo] = $srcWidth = $srcsize[0];
352
+			}
353
+			if (!$srcHeight) {
354
+			    $hauteur_img[$logo] = $srcHeight = $srcsize[1];
355
+			}
331 356
 		}
332 357
 		// $logo peut etre une reference a une image temporaire dont a n'a que le log .src
333 358
 		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
334 359
 		elseif(@file_exists($f = "$logo.src")
335 360
 		  AND lire_fichier($f,$valeurs)
336 361
 		  AND $valeurs=unserialize($valeurs)) {
337
-			if (!$srcWidth)	$largeur_img[$logo] = $srcWidth = $valeurs["largeur_dest"];
338
-			if (!$srcHeight)	$hauteur_img[$logo] = $srcHeight = $valeurs["hauteur_dest"];
362
+			if (!$srcWidth) {
363
+			    $largeur_img[$logo] = $srcWidth = $valeurs["largeur_dest"];
364
+			}
365
+			if (!$srcHeight) {
366
+			    $hauteur_img[$logo] = $srcHeight = $valeurs["hauteur_dest"];
367
+			}
339 368
 	  }
340 369
 	}
341 370
 	return array($srcHeight, $srcWidth);
342 371
 }
343 372
 // http://doc.spip.org/@largeur
344 373
 function largeur($img) {
345
-	if (!$img) return;
374
+	if (!$img) {
375
+	    return;
376
+	}
346 377
 	list ($h,$l) = taille_image($img);
347 378
 	return $l;
348 379
 }
349 380
 // http://doc.spip.org/@hauteur
350 381
 function hauteur($img) {
351
-	if (!$img) return;
382
+	if (!$img) {
383
+	    return;
384
+	}
352 385
 	list ($h,$l) = taille_image($img);
353 386
 	return $h;
354 387
 }
@@ -364,13 +397,17 @@  discard block
 block discarded – undo
364 397
 // et au cas particulier de &amp; qui devient &amp;amp; dans les url
365 398
 // http://doc.spip.org/@corriger_entites_html
366 399
 function corriger_entites_html($texte) {
367
-	if (strpos($texte,'&amp;') === false) return $texte;
400
+	if (strpos($texte,'&amp;') === false) {
401
+	    return $texte;
402
+	}
368 403
 	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
369 404
 }
370 405
 // idem mais corriger aussi les &amp;eacute; en &eacute;
371 406
 // http://doc.spip.org/@corriger_toutes_entites_html
372 407
 function corriger_toutes_entites_html($texte) {
373
-	if (strpos($texte,'&amp;') === false) return $texte;
408
+	if (strpos($texte,'&amp;') === false) {
409
+	    return $texte;
410
+	}
374 411
 	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
375 412
 }
376 413
 
@@ -394,28 +431,34 @@  discard block
 block discarded – undo
394 431
 function entites_html($texte, $tout=false, $quote=true) {
395 432
 	if (!is_string($texte) OR !$texte
396 433
 	OR strpbrk($texte, "&\"'<>")==false
397
-	) return $texte;
434
+	) {
435
+	    return $texte;
436
+	}
398 437
 	include_spip('inc/texte');
399 438
 	$flags = !defined('PHP_VERSION_ID') OR PHP_VERSION_ID < 50400 ? ENT_COMPAT : ENT_COMPAT|ENT_HTML401;
400 439
 	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $quote?ENT_QUOTES:$flags);
401
-	if ($tout)
402
-		return corriger_toutes_entites_html($texte);
403
-	else
404
-		return corriger_entites_html($texte);
405
-}
440
+	if ($tout) {
441
+			return corriger_toutes_entites_html($texte);
442
+	} else {
443
+			return corriger_entites_html($texte);
444
+	}
445
+	}
406 446
 
407 447
 // Transformer les &eacute; dans le charset local
408 448
 // http://doc.spip.org/@filtrer_entites
409 449
 function filtrer_entites($texte) {
410
-	if (strpos($texte,'&') === false) return $texte;
450
+	if (strpos($texte,'&') === false) {
451
+	    return $texte;
452
+	}
411 453
 	// filtrer
412 454
 	$texte = html2unicode($texte);
413 455
 	// remettre le tout dans le charset cible
414 456
 	$texte = unicode2charset($texte);
415 457
 	// cas particulier des " et ' qu'il faut filtrer aussi
416 458
 	// (on le faisait deja avec un &quot;)
417
-	if (strpos($texte,"&#")!==false)
418
-		$texte = str_replace(array("&#039;","&#39;","&#034;","&#34;"), array("'","'",'"','"'), $texte);
459
+	if (strpos($texte,"&#")!==false) {
460
+			$texte = str_replace(array("&#039;","&#39;","&#034;","&#34;"), array("'","'",'"','"'), $texte);
461
+	}
419 462
 	return $texte;
420 463
 }
421 464
 
@@ -442,7 +485,9 @@  discard block
 block discarded – undo
442 485
 		return array_map('supprimer_caracteres_illegaux', $texte);
443 486
 	}
444 487
 	
445
-	if (!$to) $to = str_repeat('-', strlen($from));
488
+	if (!$to) {
489
+	    $to = str_repeat('-', strlen($from));
490
+	}
446 491
 	return strtr($texte, $from, $to);
447 492
 }
448 493
 
@@ -520,11 +565,12 @@  discard block
 block discarded – undo
520 565
 function recuperer_numero($texte) {
521 566
 	if (preg_match(
522 567
 	",^[[:space:]]*([0-9]+)([.)]|".chr(194).'?'.chr(176).")[[:space:]]+,S",
523
-	$texte, $regs))
524
-		return strval($regs[1]);
525
-	else
526
-		return '';
527
-}
568
+	$texte, $regs)) {
569
+			return strval($regs[1]);
570
+	} else {
571
+			return '';
572
+	}
573
+	}
528 574
 
529 575
 // Suppression basique et brutale de tous les <...>
530 576
 // http://doc.spip.org/@supprimer_tags
@@ -572,8 +618,9 @@  discard block
 block discarded – undo
572 618
  * @return string
573 619
  */
574 620
 function liens_nofollow($texte) {
575
-	if (stripos($texte,"<a")===false)
576
-		return $texte;
621
+	if (stripos($texte,"<a")===false) {
622
+			return $texte;
623
+	}
577 624
 
578 625
 	if (preg_match_all(",<a\b[^>]*>,UimsS",$texte, $regs, PREG_PATTERN_ORDER)){
579 626
 		foreach($regs[0] as $a){
@@ -616,7 +663,9 @@  discard block
 block discarded – undo
616 663
  * @return string
617 664
  */
618 665
 function lignes_longues($texte) {
619
-	if (!strlen(trim($texte))) return $texte;
666
+	if (!strlen(trim($texte))) {
667
+	    return $texte;
668
+	}
620 669
 	include_spip('inc/texte');
621 670
 	$tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ?
622 671
 		'div' : 'span';
@@ -627,20 +676,24 @@  discard block
 block discarded – undo
627 676
 // Majuscules y compris accents, en HTML
628 677
 // http://doc.spip.org/@majuscules
629 678
 function majuscules($texte) {
630
-	if (!strlen($texte)) return '';
679
+	if (!strlen($texte)) {
680
+	    return '';
681
+	}
631 682
 
632 683
 	// Cas du turc
633 684
 	if ($GLOBALS['spip_lang'] == 'tr') {
634 685
 		# remplacer hors des tags et des entites
635
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER))
636
-			foreach ($regs as $n => $match)
686
+		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
687
+					foreach ($regs as $n => $match)
637 688
 				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
689
+		}
638 690
 
639 691
 		$texte = str_replace('i', '&#304;', $texte);
640 692
 
641
-		if ($regs)
642
-			foreach ($regs as $n => $match)
693
+		if ($regs) {
694
+					foreach ($regs as $n => $match)
643 695
 				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
696
+		}
644 697
 	}
645 698
 
646 699
 	// Cas general
@@ -650,9 +703,10 @@  discard block
 block discarded – undo
650 703
 // "127.4 ko" ou "3.1 Mo"
651 704
 // http://doc.spip.org/@taille_en_octets
652 705
 function taille_en_octets ($taille) {
653
-	if ($taille < 1) return '';
654
-	if ($taille < 1024) {$taille = _T('taille_octets', array('taille' => $taille));}
655
-	else if ($taille < 1024*1024) {
706
+	if ($taille < 1) {
707
+	    return '';
708
+	}
709
+	if ($taille < 1024) {$taille = _T('taille_octets', array('taille' => $taille));} else if ($taille < 1024*1024) {
656 710
 		$taille = _T('taille_ko', array('taille' => round($taille/1024, 1)));
657 711
 	} else if ($taille < 1024*1024*1024) {
658 712
 		$taille = _T('taille_mo', array('taille' => round($taille/1024/1024, 1)));
@@ -667,8 +721,9 @@  discard block
 block discarded – undo
667 721
 // http://doc.spip.org/@attribut_html
668 722
 function attribut_html($texte,$textebrut = true) {
669 723
 	$u = $GLOBALS['meta']['pcre_u'];
670
-	if ($textebrut)
671
-		$texte = preg_replace(array(",\n,",",\s(?=\s),msS".$u),array(" ",""),textebrut($texte));
724
+	if ($textebrut) {
725
+			$texte = preg_replace(array(",\n,",",\s(?=\s),msS".$u),array(" ",""),textebrut($texte));
726
+	}
672 727
 	$texte = texte_backend($texte);
673 728
 	$texte = str_replace(array("'",'"'),array('&#039;', '&#034;'), $texte);
674 729
 	
@@ -690,9 +745,10 @@  discard block
 block discarded – undo
690 745
 // http://doc.spip.org/@extraire_date
691 746
 function extraire_date($texte) {
692 747
 	// format = 2001-08
693
-	if (preg_match(",([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),",$texte,$regs))
694
-		return $regs[1]."-".sprintf("%02d", $regs[2])."-01";
695
-}
748
+	if (preg_match(",([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),",$texte,$regs)) {
749
+			return $regs[1]."-".sprintf("%02d", $regs[2])."-01";
750
+	}
751
+	}
696 752
 
697 753
 // Maquiller une adresse e-mail
698 754
 // http://doc.spip.org/@antispam
@@ -706,7 +762,9 @@  discard block
 block discarded – undo
706 762
 function securiser_acces($id_auteur, $cle, $dir, $op='', $args='')
707 763
 {
708 764
 	include_spip('inc/acces');
709
-	if ($op) $dir .= " $op $args";
765
+	if ($op) {
766
+	    $dir .= " $op $args";
767
+	}
710 768
 	return verifier_low_sec($id_auteur, $cle, $dir);
711 769
 }
712 770
 
@@ -728,11 +786,12 @@  discard block
 block discarded – undo
728 786
  * 		Retourne $texte, sinon $sinon.
729 787
 **/
730 788
 function sinon ($texte, $sinon='') {
731
-	if ($texte OR (!is_array($texte) AND strlen($texte)))
732
-		return $texte;
733
-	else
734
-		return $sinon;
735
-}
789
+	if ($texte OR (!is_array($texte) AND strlen($texte))) {
790
+			return $texte;
791
+	} else {
792
+			return $sinon;
793
+	}
794
+	}
736 795
 
737 796
 // |choixsivide{vide,pasvide} affiche pasvide si la chaine n'est pas vide...
738 797
 // http://doc.spip.org/@choixsivide
@@ -756,26 +815,36 @@  discard block
 block discarded – undo
756 815
 function normaliser_date($date, $forcer_jour = false) {
757 816
 	$date = vider_date($date);
758 817
 	if ($date) {
759
-		if (preg_match("/^[0-9]{8,10}$/", $date))
760
-			$date = date("Y-m-d H:i:s", $date);
761
-		if (preg_match("#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#", $date, $regs))
762
-			$date = $regs[1]."-00-00".$regs[3];
763
-		else if (preg_match("#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#", $date, $regs))
764
-			$date = preg_replace("@/@","-",$regs[1])."-00".$regs[3];
765
-		else
766
-			$date = date("Y-m-d H:i:s", strtotime($date));
767
-
768
-		if ($forcer_jour)
769
-			$date = str_replace('-00', '-01', $date);
818
+		if (preg_match("/^[0-9]{8,10}$/", $date)) {
819
+					$date = date("Y-m-d H:i:s", $date);
820
+		}
821
+		if (preg_match("#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#", $date, $regs)) {
822
+					$date = $regs[1]."-00-00".$regs[3];
823
+		} else if (preg_match("#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#", $date, $regs)) {
824
+					$date = preg_replace("@/@","-",$regs[1])."-00".$regs[3];
825
+		} else {
826
+					$date = date("Y-m-d H:i:s", strtotime($date));
827
+		}
828
+
829
+		if ($forcer_jour) {
830
+					$date = str_replace('-00', '-01', $date);
831
+		}
770 832
 	}
771 833
 	return $date;
772 834
 }
773 835
 
774 836
 // http://doc.spip.org/@vider_date
775 837
 function vider_date($letexte) {
776
-	if (strncmp("0000-00-00", $letexte,10)==0) return '';
777
-	if (strncmp("0001-01-01", $letexte,10)==0) return '';
778
-	if (strncmp("1970-01-01", $letexte,10)==0) return '';	// eviter le bug GMT-1
838
+	if (strncmp("0000-00-00", $letexte,10)==0) {
839
+	    return '';
840
+	}
841
+	if (strncmp("0001-01-01", $letexte,10)==0) {
842
+	    return '';
843
+	}
844
+	if (strncmp("1970-01-01", $letexte,10)==0) {
845
+	    return '';
846
+	}
847
+	// eviter le bug GMT-1
779 848
 	return $letexte;
780 849
 }
781 850
 
@@ -783,8 +852,9 @@  discard block
 block discarded – undo
783 852
 function recup_heure($date){
784 853
 
785 854
 	static $d = array(0,0,0);
786
-	if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) 
787
-		return $d;
855
+	if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) {
856
+			return $d;
857
+	}
788 858
 	
789 859
 	array_shift($r);
790 860
 	return $r;
@@ -793,24 +863,27 @@  discard block
 block discarded – undo
793 863
 // http://doc.spip.org/@heures
794 864
 function heures($numdate) {
795 865
 	$date_array = recup_heure($numdate);
796
-	if ($date_array)
797
-		list($heures, $minutes, $secondes) = $date_array;
866
+	if ($date_array) {
867
+			list($heures, $minutes, $secondes) = $date_array;
868
+	}
798 869
 	return $heures;
799 870
 }
800 871
 
801 872
 // http://doc.spip.org/@minutes
802 873
 function minutes($numdate) {
803 874
 	$date_array = recup_heure($numdate);
804
-	if ($date_array)
805
-		list($heures, $minutes, $secondes) = $date_array;
875
+	if ($date_array) {
876
+			list($heures, $minutes, $secondes) = $date_array;
877
+	}
806 878
 	return $minutes;
807 879
 }
808 880
 
809 881
 // http://doc.spip.org/@secondes
810 882
 function secondes($numdate) {
811 883
 	$date_array = recup_heure($numdate);
812
-	if ($date_array)
813
-		list($heures,$minutes,$secondes) = $date_array;
884
+	if ($date_array) {
885
+			list($heures,$minutes,$secondes) = $date_array;
886
+	}
814 887
 	return $secondes;
815 888
 }
816 889
 
@@ -821,7 +894,9 @@  discard block
 block discarded – undo
821 894
 
822 895
 // http://doc.spip.org/@recup_date
823 896
 function recup_date($numdate, $forcer_jour = true){
824
-	if (!$numdate) return '';
897
+	if (!$numdate) {
898
+	    return '';
899
+	}
825 900
 	$heures = $minutes = $secondes = 0;
826 901
 	if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) {
827 902
 		$jour = $regs[1];
@@ -834,35 +909,43 @@  discard block
 block discarded – undo
834 909
 		}
835 910
 		list($heures, $minutes, $secondes) = recup_heure($numdate);
836 911
 
837
-	}
838
-	elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#',$numdate, $regs)) {
912
+	} elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#',$numdate, $regs)) {
839 913
 		$annee = $regs[1];
840 914
 		$mois = $regs[2];
841 915
 		$jour = $regs[3];
842 916
 		list($heures, $minutes, $secondes) = recup_heure($numdate);
843
-	}
844
-	elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)){
917
+	} elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)){
845 918
 		$annee = $regs[1];
846 919
 		$mois = $regs[2];
847 920
 		$jour ='';
848 921
 		list($heures, $minutes, $secondes) = recup_heure($numdate);
849
-	}
850
-	elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)){
922
+	} elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)){
851 923
 		$annee = $regs[1];
852 924
 		$mois = $regs[2];
853 925
 		$jour = $regs[3];
854 926
 		$heures = $regs[4];
855 927
 		$minutes = $regs[5];
856 928
 		$secondes = $regs[6];
857
-	} else $annee = $mois =  $jour =''; 
858
-	if ($annee > 4000) $annee -= 9000;
859
-	if (substr($jour, 0, 1) == '0') $jour = substr($jour, 1);
929
+	} else {
930
+	    $annee = $mois =  $jour ='';
931
+	}
932
+	if ($annee > 4000) {
933
+	    $annee -= 9000;
934
+	}
935
+	if (substr($jour, 0, 1) == '0') {
936
+	    $jour = substr($jour, 1);
937
+	}
860 938
 
861
-	if ($forcer_jour AND $jour == '0') $jour = '1';
862
-	if ($forcer_jour AND $mois == '0') $mois = '1';
863
-	if ($annee OR $mois OR $jour OR $heures OR $minutes OR $secondes)
864
-		return array($annee, $mois, $jour, $heures, $minutes, $secondes);
865
-}
939
+	if ($forcer_jour AND $jour == '0') {
940
+	    $jour = '1';
941
+	}
942
+	if ($forcer_jour AND $mois == '0') {
943
+	    $mois = '1';
944
+	}
945
+	if ($annee OR $mois OR $jour OR $heures OR $minutes OR $secondes) {
946
+			return array($annee, $mois, $jour, $heures, $minutes, $secondes);
947
+	}
948
+	}
866 949
 
867 950
 // une date pour l'interface : utilise date_relative si le decalage
868 951
 // avec time() est de moins de douze heures, sinon la date complete
@@ -877,16 +960,20 @@  discard block
 block discarded – undo
877 960
 // http://doc.spip.org/@date_relative
878 961
 function date_relative($date, $decalage_maxi=0,$ref_date=null) {
879 962
 	
880
-	if (is_null($ref_date))
881
-		$ref_time = time();
882
-	else
883
-		$ref_time = strtotime($ref_date);
963
+	if (is_null($ref_date)) {
964
+			$ref_time = time();
965
+	} else {
966
+			$ref_time = strtotime($ref_date);
967
+	}
884 968
 	
885
-	if (!$date) return;
969
+	if (!$date) {
970
+	    return;
971
+	}
886 972
 	$decal = date("U",$ref_time) - date("U", strtotime($date));
887 973
 
888
-	if ($decalage_maxi AND ($decal > $decalage_maxi OR $decal < 0))
889
-		return '';
974
+	if ($decalage_maxi AND ($decal > $decalage_maxi OR $decal < 0)) {
975
+			return '';
976
+	}
890 977
 
891 978
 	if ($decal < 0) {
892 979
 		$il_y_a = "date_dans";
@@ -895,49 +982,52 @@  discard block
 block discarded – undo
895 982
 		$il_y_a = "date_il_y_a";
896 983
 	}
897 984
 
898
-	if ($decal > 3600 * 24 * 30 * 6)
899
-		return affdate_court($date);
985
+	if ($decal > 3600 * 24 * 30 * 6) {
986
+			return affdate_court($date);
987
+	}
900 988
 
901 989
 	if ($decal > 3600 * 24 * 30) {
902 990
 		$mois = floor ($decal / (3600 * 24 * 30));
903
-		if ($mois < 2)
904
-			$delai = "$mois "._T("date_un_mois");
905
-		else
906
-			$delai = "$mois "._T("date_mois");
907
-	}
908
-	else if ($decal > 3600 * 24 * 7) {
991
+		if ($mois < 2) {
992
+					$delai = "$mois "._T("date_un_mois");
993
+		} else {
994
+					$delai = "$mois "._T("date_mois");
995
+		}
996
+	} else if ($decal > 3600 * 24 * 7) {
909 997
 		$semaines = floor ($decal / (3600 * 24 * 7));
910
-		if ($semaines < 2)
911
-			$delai = "$semaines "._T("date_une_semaine");
912
-		else
913
-			$delai = "$semaines "._T("date_semaines");
914
-	}
915
-	else if ($decal > 3600 * 24) {
998
+		if ($semaines < 2) {
999
+					$delai = "$semaines "._T("date_une_semaine");
1000
+		} else {
1001
+					$delai = "$semaines "._T("date_semaines");
1002
+		}
1003
+	} else if ($decal > 3600 * 24) {
916 1004
 		$jours = floor ($decal / (3600 * 24));
917
-		if ($jours < 2)
918
-			return $il_y_a=="date_dans"?_T("date_demain"):_T("date_hier");
919
-		else
920
-			$delai = "$jours "._T("date_jours");
921
-	}
922
-	else if ($decal >= 3600) {
1005
+		if ($jours < 2) {
1006
+					return $il_y_a=="date_dans"?_T("date_demain"):_T("date_hier");
1007
+		} else {
1008
+					$delai = "$jours "._T("date_jours");
1009
+		}
1010
+	} else if ($decal >= 3600) {
923 1011
 		$heures = floor ($decal / 3600);
924
-		if ($heures < 2)
925
-			$delai = "$heures "._T("date_une_heure");
926
-		else
927
-			$delai = "$heures "._T("date_heures");
928
-	}
929
-	else if ($decal >= 60) {
1012
+		if ($heures < 2) {
1013
+					$delai = "$heures "._T("date_une_heure");
1014
+		} else {
1015
+					$delai = "$heures "._T("date_heures");
1016
+		}
1017
+	} else if ($decal >= 60) {
930 1018
 		$minutes = floor($decal / 60);
931
-		if ($minutes < 2)
932
-			$delai = "$minutes "._T("date_une_minute");
933
-		else
934
-			$delai = "$minutes "._T("date_minutes");
1019
+		if ($minutes < 2) {
1020
+					$delai = "$minutes "._T("date_une_minute");
1021
+		} else {
1022
+					$delai = "$minutes "._T("date_minutes");
1023
+		}
935 1024
 	} else {
936 1025
 		$secondes = ceil($decal);
937
-		if ($secondes < 2)
938
-			$delai = "$secondes "._T("date_une_seconde");
939
-		else
940
-			$delai = "$secondes "._T("date_secondes");
1026
+		if ($secondes < 2) {
1027
+					$delai = "$secondes "._T("date_une_seconde");
1028
+		} else {
1029
+					$delai = "$secondes "._T("date_secondes");
1030
+		}
941 1031
 	}
942 1032
 
943 1033
 	return _T($il_y_a, array("delai"=> $delai));
@@ -947,25 +1037,24 @@  discard block
 block discarded – undo
947 1037
 // http://doc.spip.org/@date_relativecourt
948 1038
 function date_relativecourt($date, $decalage_maxi=0) {
949 1039
 	
950
-	if (!$date) return;
1040
+	if (!$date) {
1041
+	    return;
1042
+	}
951 1043
 	$decal = date("U",strtotime(date('Y-m-d'))-strtotime(date('Y-m-d',strtotime($date))));
952 1044
 
953
-	if ($decalage_maxi AND ($decal > $decalage_maxi OR $decal < 0))
954
-		return '';
1045
+	if ($decalage_maxi AND ($decal > $decalage_maxi OR $decal < 0)) {
1046
+			return '';
1047
+	}
955 1048
 
956 1049
 	if ($decal < -24*3600) {
957 1050
 		$retour = date_relative($date, $decalage_maxi);
958
-	}
959
-	elseif ($decal < 0) {
1051
+	} elseif ($decal < 0) {
960 1052
 		$retour = _T("date_demain");
961
-	}
962
-	else if ($decal < (3600 * 24) ) {
1053
+	} else if ($decal < (3600 * 24) ) {
963 1054
 		$retour = _T("date_aujourdhui");
964
-	}
965
-	else if ($decal < (3600 * 24 *2) ) {
1055
+	} else if ($decal < (3600 * 24 *2) ) {
966 1056
 		$retour = _T("date_hier");
967
-	}
968
-	else {
1057
+	} else {
969 1058
 		$retour = date_relative($date, $decalage_maxi);
970 1059
 	}
971 1060
 
@@ -986,10 +1075,13 @@  discard block
 block discarded – undo
986 1075
  * @return mixed|string
987 1076
  */
988 1077
 function affdate_base($numdate, $vue, $options = array()) {
989
-	if (is_string($options))
990
-		$options = array('param'=>$options);
1078
+	if (is_string($options)) {
1079
+			$options = array('param'=>$options);
1080
+	}
991 1081
 	$date_array = recup_date($numdate, false);
992
-	if (!$date_array) return;
1082
+	if (!$date_array) {
1083
+	    return;
1084
+	}
993 1085
 	list($annee, $mois, $jour, $heures, $minutes, $secondes)= $date_array;
994 1086
 
995 1087
 	// 1er, 21st, etc.
@@ -999,24 +1091,29 @@  discard block
 block discarded – undo
999 1091
 		$jour = '';
1000 1092
 	} else {
1001 1093
 		$njour = intval($jour);
1002
-		if ($jourth = _T('date_jnum'.$jour))
1003
-			$jour = $jourth;
1094
+		if ($jourth = _T('date_jnum'.$jour)) {
1095
+					$jour = $jourth;
1096
+		}
1004 1097
 	}
1005 1098
 
1006 1099
 	$mois = intval($mois);
1007 1100
 	if ($mois > 0 AND $mois < 13) {
1008 1101
 		$nommois = _T('date_mois_'.$mois);
1009
-		if ($jour)
1010
-			$jourmois = _T('date_de_mois_'.$mois, array('j'=>$jour, 'nommois'=>$nommois));
1011
-		else
1012
-			$jourmois = $nommois;
1013
-	} else $nommois = '';
1102
+		if ($jour) {
1103
+					$jourmois = _T('date_de_mois_'.$mois, array('j'=>$jour, 'nommois'=>$nommois));
1104
+		} else {
1105
+					$jourmois = $nommois;
1106
+		}
1107
+	} else {
1108
+	    $nommois = '';
1109
+	}
1014 1110
 
1015 1111
 	if ($annee < 0) {
1016 1112
 		$annee = -$annee." "._T('date_avant_jc');
1017 1113
 		$avjc = true;
1114
+	} else {
1115
+	    $avjc = false;
1018 1116
 	}
1019
-	else $avjc = false;
1020 1117
 
1021 1118
 	switch ($vue) {
1022 1119
 	case 'saison':
@@ -1024,38 +1121,62 @@  discard block
 block discarded – undo
1024 1121
 		$saison = '';
1025 1122
 		if ($mois > 0){
1026 1123
 			$saison = 1;
1027
-			if (($mois == 3 AND $jour >= 21) OR $mois > 3) $saison = 2;
1028
-			if (($mois == 6 AND $jour >= 21) OR $mois > 6) $saison = 3;
1029
-			if (($mois == 9 AND $jour >= 21) OR $mois > 9) $saison = 4;
1030
-			if (($mois == 12 AND $jour >= 21) OR $mois > 12) $saison = 1;
1124
+			if (($mois == 3 AND $jour >= 21) OR $mois > 3) {
1125
+			    $saison = 2;
1126
+			}
1127
+			if (($mois == 6 AND $jour >= 21) OR $mois > 6) {
1128
+			    $saison = 3;
1129
+			}
1130
+			if (($mois == 9 AND $jour >= 21) OR $mois > 9) {
1131
+			    $saison = 4;
1132
+			}
1133
+			if (($mois == 12 AND $jour >= 21) OR $mois > 12) {
1134
+			    $saison = 1;
1135
+			}
1136
+		}
1137
+		if($vue == 'saison') {
1138
+					return $saison?_T('date_saison_'.$saison):'';
1139
+		} else {
1140
+					return $saison?trim(_T('date_fmt_saison_annee', array('saison'=>_T('date_saison_'.$saison), 'annee'=>$annee))) :'';
1031 1141
 		}
1032
-		if($vue == 'saison')
1033
-			return $saison?_T('date_saison_'.$saison):'';
1034
-		else
1035
-			return $saison?trim(_T('date_fmt_saison_annee', array('saison'=>_T('date_saison_'.$saison), 'annee'=>$annee))) :'';
1036 1142
 
1037 1143
 	case 'court':
1038
-		if ($avjc) return $annee;
1144
+		if ($avjc) {
1145
+		    return $annee;
1146
+		}
1039 1147
 		$a = ((isset($options['annee_courante']) AND $options['annee_courante'])?$options['annee_courante']:date('Y'));
1040
-		if ($annee < ($a - 100) OR $annee > ($a + 100)) return $annee;
1041
-		if ($annee != $a) return _T('date_fmt_mois_annee', array ('mois'=>$mois, 'nommois'=>spip_ucfirst($nommois), 'annee'=>$annee));
1148
+		if ($annee < ($a - 100) OR $annee > ($a + 100)) {
1149
+		    return $annee;
1150
+		}
1151
+		if ($annee != $a) {
1152
+		    return _T('date_fmt_mois_annee', array ('mois'=>$mois, 'nommois'=>spip_ucfirst($nommois), 'annee'=>$annee));
1153
+		}
1042 1154
 		return _T('date_fmt_jour_mois', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1043 1155
 
1044 1156
 	case 'jourcourt':
1045
-		if ($avjc) return $annee;
1157
+		if ($avjc) {
1158
+		    return $annee;
1159
+		}
1046 1160
 		$a = ((isset($options['annee_courante']) AND $options['annee_courante'])?$options['annee_courante']:date('Y'));
1047
-		if ($annee < ($a - 100) OR $annee > ($a + 100)) return $annee;
1048
-		if ($annee != $a) return _T('date_fmt_jour_mois_annee', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1161
+		if ($annee < ($a - 100) OR $annee > ($a + 100)) {
1162
+		    return $annee;
1163
+		}
1164
+		if ($annee != $a) {
1165
+		    return _T('date_fmt_jour_mois_annee', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1166
+		}
1049 1167
 		return _T('date_fmt_jour_mois', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1050 1168
 
1051 1169
 	case 'entier':
1052
-		if ($avjc) return $annee;
1053
-		if ($jour)
1054
-			return _T('date_fmt_jour_mois_annee', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1055
-		elseif ($mois)
1056
-			return trim(_T('date_fmt_mois_annee', array ('mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)));
1057
-		else
1058
-			return $annee;
1170
+		if ($avjc) {
1171
+		    return $annee;
1172
+		}
1173
+		if ($jour) {
1174
+					return _T('date_fmt_jour_mois_annee', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1175
+		} elseif ($mois) {
1176
+					return trim(_T('date_fmt_mois_annee', array ('mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)));
1177
+		} else {
1178
+					return $annee;
1179
+		}
1059 1180
 
1060 1181
 	case 'nom_mois':
1061 1182
 		$param = ((isset($options['param']) AND $options['param']) ? '_'.$options['param'] : '');
@@ -1074,15 +1195,18 @@  discard block
 block discarded – undo
1074 1195
 		return $journum;
1075 1196
 
1076 1197
 	case 'nom_jour':
1077
-		if (!$mois OR !$njour)
1078
-			return '';
1198
+		if (!$mois OR !$njour) {
1199
+					return '';
1200
+		}
1079 1201
 		$nom = mktime(1,1,1,$mois,$njour,$annee);
1080 1202
 		$nom = 1+date('w',$nom);
1081 1203
 		$param = ((isset($options['param']) AND $options['param']) ? '_'.$options['param'] : '');
1082 1204
 		return _T('date_jour_'.$nom.$param);
1083 1205
 
1084 1206
 	case 'mois_annee':
1085
-		if ($avjc) return $annee;
1207
+		if ($avjc) {
1208
+		    return $annee;
1209
+		}
1086 1210
 		return trim(_T('date_fmt_mois_annee', array('mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)));
1087 1211
 
1088 1212
 	case 'annee':
@@ -1097,7 +1221,9 @@  discard block
 block discarded – undo
1097 1221
 
1098 1222
 // http://doc.spip.org/@nom_jour
1099 1223
 function nom_jour($numdate, $forme = '') {
1100
-	if(!($forme == 'abbr' OR $forme == 'initiale')) $forme = '';
1224
+	if(!($forme == 'abbr' OR $forme == 'initiale')) {
1225
+	    $forme = '';
1226
+	}
1101 1227
 	return affdate_base($numdate, 'nom_jour', $forme);
1102 1228
 }
1103 1229
 
@@ -1118,7 +1244,9 @@  discard block
 block discarded – undo
1118 1244
 
1119 1245
 // http://doc.spip.org/@nom_mois
1120 1246
 function nom_mois($numdate, $forme='') {
1121
-	if(!($forme == 'abbr')) $forme = '';
1247
+	if(!($forme == 'abbr')) {
1248
+	    $forme = '';
1249
+	}
1122 1250
 	return affdate_base($numdate, 'nom_mois', $forme);
1123 1251
 }
1124 1252
 
@@ -1160,7 +1288,9 @@  discard block
 block discarded – undo
1160 1288
 // http://doc.spip.org/@affdate_heure
1161 1289
 function affdate_heure($numdate) {
1162 1290
 	$date_array = recup_date($numdate);
1163
-	if (!$date_array) return;
1291
+	if (!$date_array) {
1292
+	    return;
1293
+	}
1164 1294
 	list($annee, $mois, $jour, $heures, $minutes, $sec)= $date_array;
1165 1295
 	return _T('date_fmt_jour_heure', array('jour' => affdate($numdate), 'heure' =>  _T('date_fmt_heures_minutes', array('h'=> $heures, 'm'=> $minutes))));
1166 1296
 }
@@ -1192,9 +1322,15 @@  discard block
 block discarded – undo
1192 1322
 function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme=''){
1193 1323
 	$abbr = $jour = '';
1194 1324
 	$affdate = "affdate_jourcourt";
1195
-	if (strpos($forme,'abbr') !==false) $abbr = 'abbr';
1196
-	if (strpos($forme,'annee')!==false) $affdate = 'affdate';
1197
-	if (strpos($forme,'jour') !==false) $jour = 'jour';
1325
+	if (strpos($forme,'abbr') !==false) {
1326
+	    $abbr = 'abbr';
1327
+	}
1328
+	if (strpos($forme,'annee')!==false) {
1329
+	    $affdate = 'affdate';
1330
+	}
1331
+	if (strpos($forme,'jour') !==false) {
1332
+	    $jour = 'jour';
1333
+	}
1198 1334
 	
1199 1335
 	$dtstart = $dtend = $dtabbr = "";
1200 1336
 	if (strpos($forme,'hcal')!==false) {
@@ -1221,27 +1357,30 @@  discard block
 block discarded – undo
1221 1357
 				// Lundi 20 fevrier a 18h25
1222 1358
 				$s = spip_ucfirst(_T('date_fmt_jour_heure',array('jour'=>$s,'heure'=>$hd)));
1223 1359
 				$s = "$dtstart$s$dtabbr";
1224
-			}else{
1360
+			} else{
1225 1361
 				// Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1226
-				if($dtabbr && $dtstart && $dtend)
1227
-					$s = _T('date_fmt_jour_heure_debut_fin_abbr',array('jour'=>spip_ucfirst($s),'heure_debut'=>$hd,'heure_fin'=>$hf,'dtstart'=>$dtstart,'dtend'=>$dtend,'dtabbr'=>$dtabbr));
1362
+				if($dtabbr && $dtstart && $dtend) {
1363
+									$s = _T('date_fmt_jour_heure_debut_fin_abbr',array('jour'=>spip_ucfirst($s),'heure_debut'=>$hd,'heure_fin'=>$hf,'dtstart'=>$dtstart,'dtend'=>$dtend,'dtabbr'=>$dtabbr));
1364
+				}
1228 1365
 				// Le lundi 20 fevrier de 18h00 a 20h00
1229
-				else
1230
-					$s = spip_ucfirst(_T('date_fmt_jour_heure_debut_fin',array('jour'=>$s,'heure_debut'=>$hd,'heure_fin'=>$hf)));
1366
+				else {
1367
+									$s = spip_ucfirst(_T('date_fmt_jour_heure_debut_fin',array('jour'=>$s,'heure_debut'=>$hd,'heure_fin'=>$hf)));
1368
+				}
1369
+			}
1370
+		} else{
1371
+			if($dtabbr && $dtstart) {
1372
+							$s = $dtstart.spip_ucfirst($s).$dtabbr;
1373
+			} else {
1374
+							$s = spip_ucfirst($s);
1231 1375
 			}
1232
-		}else{
1233
-			if($dtabbr && $dtstart)
1234
-				$s = $dtstart.spip_ucfirst($s).$dtabbr;
1235
-			else
1236
-				$s = spip_ucfirst($s);
1237 1376
 		}
1238
-	}
1239
-	else if ((date("Y-m",$date_debut))==date("Y-m",$date_fin))
1377
+	} else if ((date("Y-m",$date_debut))==date("Y-m",$date_fin))
1240 1378
 	{ // meme annee et mois, jours differents
1241
-		if(!$h)
1242
-			$date_debut = jour($d);
1243
-		else
1244
-			$date_debut = affdate_jourcourt($d,date("Y",$date_fin));
1379
+		if(!$h) {
1380
+					$date_debut = jour($d);
1381
+		} else {
1382
+					$date_debut = affdate_jourcourt($d,date("Y",$date_fin));
1383
+		}
1245 1384
 		$date_fin = $affdate($f);
1246 1385
 		if($jour){
1247 1386
 			$nomjour_debut = nom_jour($d,$abbr);
@@ -1257,8 +1396,7 @@  discard block
 block discarded – undo
1257 1396
 		$date_fin = $dtend.$date_fin.$dtabbr;
1258 1397
 		
1259 1398
 		$s = _T('date_fmt_periode',array('date_debut' => $date_debut,'date_fin'=>$date_fin));
1260
-	}
1261
-	else {
1399
+	} else {
1262 1400
 		$date_debut = affdate_jourcourt($d,date("Y",$date_fin));
1263 1401
 		$date_fin = $affdate($f);
1264 1402
 		if($jour){
@@ -1292,7 +1430,9 @@  discard block
 block discarded – undo
1292 1430
  */
1293 1431
 function aligner($letexte, $justif='') {
1294 1432
 	$letexte = trim($letexte);
1295
-	if (!strlen($letexte)) return '';
1433
+	if (!strlen($letexte)) {
1434
+	    return '';
1435
+	}
1296 1436
 
1297 1437
 	// Paragrapher rapidement
1298 1438
 	$letexte = "<div style='text-align:$justif'>"
@@ -1361,20 +1501,27 @@  discard block
 block discarded – undo
1361 1501
 
1362 1502
 // http://doc.spip.org/@date_anneemoisjour
1363 1503
 function date_anneemoisjour($d)  {
1364
-	if (!$d) $d = date("Y-m-d");
1504
+	if (!$d) {
1505
+	    $d = date("Y-m-d");
1506
+	}
1365 1507
 	return  substr($d, 0, 4) . substr($d, 5, 2) .substr($d, 8, 2);
1366 1508
 }
1367 1509
 
1368 1510
 // http://doc.spip.org/@date_anneemois
1369 1511
 function date_anneemois($d)  {
1370
-	if (!$d) $d = date("Y-m-d");
1512
+	if (!$d) {
1513
+	    $d = date("Y-m-d");
1514
+	}
1371 1515
 	return  substr($d, 0, 4) . substr($d, 5, 2);
1372 1516
 }
1373 1517
 
1374 1518
 // http://doc.spip.org/@date_debut_semaine
1375 1519
 function date_debut_semaine($annee, $mois, $jour) {
1376 1520
   $w_day = date("w", mktime(0,0,0,$mois, $jour, $annee));
1377
-  if ($w_day == 0) $w_day = 7; // Gaffe: le dimanche est zero
1521
+  if ($w_day == 0) {
1522
+      $w_day = 7;
1523
+  }
1524
+  // Gaffe: le dimanche est zero
1378 1525
   $debut = $jour-$w_day+1;
1379 1526
   return date("Ymd", mktime(0,0,0,$mois,$debut,$annee));
1380 1527
 }
@@ -1382,7 +1529,10 @@  discard block
 block discarded – undo
1382 1529
 // http://doc.spip.org/@date_fin_semaine
1383 1530
 function date_fin_semaine($annee, $mois, $jour) {
1384 1531
   $w_day = date("w", mktime(0,0,0,$mois, $jour, $annee));
1385
-  if ($w_day == 0) $w_day = 7; // Gaffe: le dimanche est zero
1532
+  if ($w_day == 0) {
1533
+      $w_day = 7;
1534
+  }
1535
+  // Gaffe: le dimanche est zero
1386 1536
   $debut = $jour-$w_day+1;
1387 1537
   return date("Ymd", mktime(0,0,0,$mois,$debut+6,$annee));
1388 1538
 }
@@ -1401,15 +1551,17 @@  discard block
 block discarded – undo
1401 1551
 // postautobr : transforme les sauts de ligne en _
1402 1552
 // http://doc.spip.org/@post_autobr
1403 1553
 function post_autobr($texte, $delim="\n_ ") {
1404
-	if (!function_exists('echappe_html'))
1405
-		include_spip('inc/texte_mini');
1554
+	if (!function_exists('echappe_html')) {
1555
+			include_spip('inc/texte_mini');
1556
+	}
1406 1557
 	$texte = str_replace("\r\n", "\r", $texte);
1407 1558
 	$texte = str_replace("\r", "\n", $texte);
1408 1559
 
1409
-	if (preg_match(",\n+$,", $texte, $fin))
1410
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1411
-	else
1412
-		$fin = '';
1560
+	if (preg_match(",\n+$,", $texte, $fin)) {
1561
+			$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1562
+	} else {
1563
+			$fin = '';
1564
+	}
1413 1565
 
1414 1566
 	$texte = echappe_html($texte, '', true);
1415 1567
 
@@ -1432,8 +1584,9 @@  discard block
 block discarded – undo
1432 1584
 		AND !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S',($suite))
1433 1585
 		AND !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)) {
1434 1586
 			$debut .= $delim;
1435
-		} else
1436
-			$debut .= "\n";
1587
+		} else {
1588
+					$debut .= "\n";
1589
+		}
1437 1590
 		if (preg_match(",^\n+,", $suite, $regs)) {
1438 1591
 			$debut.=$regs[0];
1439 1592
 			$suite = substr($suite, strlen($regs[0]));
@@ -1453,7 +1606,9 @@  discard block
 block discarded – undo
1453 1606
 // http://doc.spip.org/@extraire_multi
1454 1607
 function extraire_multi($letexte, $lang=null, $echappe_span=false) {
1455 1608
 	if (preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)) {
1456
-		if (!$lang) $lang = $GLOBALS['spip_lang'];
1609
+		if (!$lang) {
1610
+		    $lang = $GLOBALS['spip_lang'];
1611
+		}
1457 1612
 
1458 1613
 		foreach ($regs as $reg) {
1459 1614
 			// chercher la version de la langue courante
@@ -1476,10 +1631,12 @@  discard block
 block discarded – undo
1476 1631
 				$mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1477 1632
 				$trad = code_echappement($trad, 'multi', false, $mode);
1478 1633
 				$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1479
-				if (lang_dir($l) !== lang_dir($lang))
1480
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1481
-				if (!$echappe_span)
1482
-					$trad = echappe_retour($trad, 'multi');
1634
+				if (lang_dir($l) !== lang_dir($lang)) {
1635
+									$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1636
+				}
1637
+				if (!$echappe_span) {
1638
+									$trad = echappe_retour($trad, 'multi');
1639
+				}
1483 1640
 			}
1484 1641
 			$letexte = str_replace($reg[0], $trad, $letexte);
1485 1642
 		}
@@ -1496,8 +1653,9 @@  discard block
 block discarded – undo
1496 1653
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1497 1654
 	while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1498 1655
 		$texte = trim($regs[1]);
1499
-		if ($texte OR $lang)
1500
-			$trads[$lang] = $texte;
1656
+		if ($texte OR $lang) {
1657
+					$trads[$lang] = $texte;
1658
+		}
1501 1659
 		$bloc = substr($bloc, strlen($regs[0]));
1502 1660
 		$lang = $regs[2];
1503 1661
 	}
@@ -1601,18 +1759,20 @@  discard block
 block discarded – undo
1601 1759
 			$r[4] = trim($r[2]); 
1602 1760
 		}
1603 1761
 		$att = $r[4];
1604
-		if (strpos($att,"&#")!==false)
1605
-			$att = str_replace(array("&#039;","&#39;","&#034;","&#34;"), array("'","'",'"','"'), $att);
1762
+		if (strpos($att,"&#")!==false) {
1763
+					$att = str_replace(array("&#039;","&#39;","&#034;","&#34;"), array("'","'",'"','"'), $att);
1764
+		}
1606 1765
 		$att = filtrer_entites($att);
1766
+	} else {
1767
+			$att = NULL;
1607 1768
 	}
1608
-	else
1609
-		$att = NULL;
1610 1769
 
1611
-	if ($complet)
1612
-		return array($att, $r);
1613
-	else
1614
-		return $att;
1615
-}
1770
+	if ($complet) {
1771
+			return array($att, $r);
1772
+	} else {
1773
+			return $att;
1774
+	}
1775
+	}
1616 1776
 
1617 1777
 /**
1618 1778
  * modifier (ou inserer) un attribut html dans une balise
@@ -1630,28 +1790,32 @@  discard block
 block discarded – undo
1630 1790
 	// preparer l'attribut
1631 1791
 	// supprimer les &nbsp; etc mais pas les balises html
1632 1792
 	// qui ont un sens dans un attribut value d'un input
1633
-	if ($proteger) $val = attribut_html($val,false);
1793
+	if ($proteger) {
1794
+	    $val = attribut_html($val,false);
1795
+	}
1634 1796
 
1635 1797
 	// echapper les ' pour eviter tout bug
1636 1798
 	$val = str_replace("'", "&#039;", $val);
1637
-	if ($vider AND strlen($val)==0)
1638
-		$insert = '';
1639
-	else
1640
-		$insert = " $attribut='$val'";
1799
+	if ($vider AND strlen($val)==0) {
1800
+			$insert = '';
1801
+	} else {
1802
+			$insert = " $attribut='$val'";
1803
+	}
1641 1804
 
1642 1805
 	list($old, $r) = extraire_attribut($balise, $attribut, true);
1643 1806
 
1644 1807
 	if ($old !== NULL) {
1645 1808
 		// Remplacer l'ancien attribut du meme nom
1646 1809
 		$balise = $r[1].$insert.$r[5];
1647
-	}
1648
-	else {
1810
+	} else {
1649 1811
 		// preferer une balise " />" (comme <img />)
1650
-		if (preg_match(',/>,', $balise))
1651
-			$balise = preg_replace(",\s?/>,S", $insert." />", $balise, 1);
1812
+		if (preg_match(',/>,', $balise)) {
1813
+					$balise = preg_replace(",\s?/>,S", $insert." />", $balise, 1);
1814
+		}
1652 1815
 		// sinon une balise <a ...> ... </a>
1653
-		else
1654
-			$balise = preg_replace(",\s?>,S", $insert.">", $balise, 1);
1816
+		else {
1817
+					$balise = preg_replace(",\s?>,S", $insert.">", $balise, 1);
1818
+		}
1655 1819
 	}
1656 1820
 
1657 1821
 	return $balise;
@@ -1714,7 +1878,9 @@  discard block
 block discarded – undo
1714 1878
 	if (!is_string($nom)) {
1715 1879
 		return false;
1716 1880
 	}
1717
-	if (!defined('_TAGS_NOM_AUTEUR')) define('_TAGS_NOM_AUTEUR','');
1881
+	if (!defined('_TAGS_NOM_AUTEUR')) {
1882
+	    define('_TAGS_NOM_AUTEUR','');
1883
+	}
1718 1884
 	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
1719 1885
 	foreach($tags_acceptes as $tag) {
1720 1886
 		if (strlen($tag)) {
@@ -1733,8 +1899,9 @@  discard block
 block discarded – undo
1733 1899
 // http://doc.spip.org/@email_valide
1734 1900
 function email_valide($adresses) {
1735 1901
 	// eviter d'injecter n'importe quoi dans preg_match
1736
-	if (!is_string($adresses))
1737
-		return false;
1902
+	if (!is_string($adresses)) {
1903
+			return false;
1904
+	}
1738 1905
 
1739 1906
 	// Si c'est un spammeur autant arreter tout de suite
1740 1907
 	if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) {
@@ -1747,8 +1914,9 @@  discard block
 block discarded – undo
1747 1914
 		// "Marie Toto <[email protected]>"
1748 1915
 		$adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v));
1749 1916
 		// RFC 822
1750
-		if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse))
1751
-			return false;
1917
+		if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) {
1918
+					return false;
1919
+		}
1752 1920
 	}
1753 1921
 	return $adresse;
1754 1922
 }
@@ -1773,8 +1941,9 @@  discard block
 block discarded – undo
1773 1941
 	$s = array();
1774 1942
 	foreach (extraire_balises($tags, 'a') as $tag) {
1775 1943
 		$rel = extraire_attribut($tag, 'rel');
1776
-		if (strstr(",$rels,", ",$rel,"))
1777
-			$s[] = $tag;
1944
+		if (strstr(",$rels,", ",$rel,")) {
1945
+					$s[] = $tag;
1946
+		}
1778 1947
 	}
1779 1948
 	return join(', ', $s);
1780 1949
 }
@@ -1784,8 +1953,9 @@  discard block
 block discarded – undo
1784 1953
 // attention length="zz" devient title="zz", pour rester conforme
1785 1954
 // http://doc.spip.org/@enclosure2microformat
1786 1955
 function enclosure2microformat($e) {
1787
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url')))
1788
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
1956
+	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
1957
+			$url = filtrer_entites(extraire_attribut($e, 'href'));
1958
+	}
1789 1959
 	$type = extraire_attribut($e, 'type');
1790 1960
 	if (!$length = extraire_attribut($e, 'length')) {
1791 1961
 		# <media:content : longeur dans fileSize. On tente.
@@ -1802,12 +1972,15 @@  discard block
 block discarded – undo
1802 1972
 // http://doc.spip.org/@microformat2enclosure
1803 1973
 function microformat2enclosure($tags) {
1804 1974
 	$enclosures = array();
1805
-	foreach (extraire_balises($tags, 'a') as $e)
1806
-	if (extraire_attribut($e, 'rel') == 'enclosure') {
1975
+	foreach (extraire_balises($tags, 'a') as $e) {
1976
+		if (extraire_attribut($e, 'rel') == 'enclosure') {
1807 1977
 		$url = filtrer_entites(extraire_attribut($e, 'href'));
1978
+	}
1808 1979
 		$type = extraire_attribut($e, 'type');
1809
-		if (!$length = intval(extraire_attribut($e, 'title')))
1810
-			$length = intval(extraire_attribut($e, 'length')); # vieux data
1980
+		if (!$length = intval(extraire_attribut($e, 'title'))) {
1981
+					$length = intval(extraire_attribut($e, 'length'));
1982
+		}
1983
+		# vieux data
1811 1984
 		$fichier = basename($url);
1812 1985
 		$enclosures[] = '<enclosure'
1813 1986
 			. ($url? ' url="'.spip_htmlspecialchars($url).'"' : '')
@@ -1845,9 +2018,10 @@  discard block
 block discarded – undo
1845 2018
 
1846 2019
 	if (preg_match(
1847 2020
 	",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
1848
-	$texte, $regs))
1849
-		return $regs[0];
1850
-}
2021
+	$texte, $regs)) {
2022
+			return $regs[0];
2023
+	}
2024
+	}
1851 2025
 
1852 2026
 // extraire toutes les balises du type demande, sous forme de tableau
1853 2027
 // Si on a passe un tableau de textes, renvoyer un tableau de resultats
@@ -1862,18 +2036,21 @@  discard block
 block discarded – undo
1862 2036
 
1863 2037
 	if (preg_match_all(
1864 2038
 	",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
1865
-	$texte, $regs, PREG_PATTERN_ORDER))
1866
-		return $regs[0];
1867
-	else
1868
-		return array();
1869
-}
2039
+	$texte, $regs, PREG_PATTERN_ORDER)) {
2040
+			return $regs[0];
2041
+	} else {
2042
+			return array();
2043
+	}
2044
+	}
1870 2045
 
1871 2046
 // comme in_array mais renvoie son 3e arg si le 2er arg n'est pas un tableau
1872 2047
 // prend ' ' comme representant de vrai et '' de faux
1873 2048
 
1874 2049
 // http://doc.spip.org/@in_any
1875 2050
 function in_any($val, $vals, $def='') {
1876
-	if (!is_array($vals) AND $v=unserialize($vals)) $vals = $v;
2051
+	if (!is_array($vals) AND $v=unserialize($vals)) {
2052
+	    $vals = $v;
2053
+	}
1877 2054
   return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
1878 2055
 }
1879 2056
 
@@ -1882,8 +2059,9 @@  discard block
 block discarded – undo
1882 2059
 // http://doc.spip.org/@valeur_numerique
1883 2060
 function valeur_numerique($expr) {
1884 2061
 	$a = 0;
1885
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr)))
1886
-		eval("\$a = $expr;");
2062
+	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2063
+			eval("\$a = $expr;");
2064
+	}
1887 2065
 	return intval($a);
1888 2066
 }
1889 2067
 
@@ -1911,10 +2089,12 @@  discard block
 block discarded – undo
1911 2089
 		}
1912 2090
 	}
1913 2091
 	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
1914
-	if (defined('_DEFINIR_CONTEXTE_TYPE') AND _DEFINIR_CONTEXTE_TYPE)
1915
-		unset($contexte['type']);
1916
-	if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') AND _DEFINIR_CONTEXTE_TYPE_PAGE)
1917
-		unset($contexte['type-page']);
2092
+	if (defined('_DEFINIR_CONTEXTE_TYPE') AND _DEFINIR_CONTEXTE_TYPE) {
2093
+			unset($contexte['type']);
2094
+	}
2095
+	if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') AND _DEFINIR_CONTEXTE_TYPE_PAGE) {
2096
+			unset($contexte['type-page']);
2097
+	}
1918 2098
 
1919 2099
 	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
1920 2100
 	// ecraser les elements de la forme mots[]=1&mots[]=2
@@ -1927,20 +2107,23 @@  discard block
 block discarded – undo
1927 2107
 			if ($var) {
1928 2108
 				$val =  rawurldecode($val);
1929 2109
 				$var =  rawurldecode($var); // decoder les [] eventuels
1930
-				if (preg_match(',\[\]$,S', $var))
1931
-					$values[] = array($var, $val);
1932
-				else if (!isset($values[$var]))
1933
-					$values[$var] = array($var, $val);
2110
+				if (preg_match(',\[\]$,S', $var)) {
2111
+									$values[] = array($var, $val);
2112
+				} else if (!isset($values[$var])) {
2113
+									$values[$var] = array($var, $val);
2114
+				}
1934 2115
 			}
1935 2116
 		}
1936 2117
 	}
1937 2118
 
1938 2119
 	// ensuite avec celles du contexte, sans doublonner !
1939
-	foreach($contexte as $var=>$val)
1940
-		if (preg_match(',\[\]$,S', $var))
2120
+	foreach($contexte as $var=>$val) {
2121
+			if (preg_match(',\[\]$,S', $var))
1941 2122
 			$values[] = array($var, $val);
1942
-		else if (!isset($values[$var]))
1943
-			$values[$var] = array($var, $val);
2123
+	}
2124
+		else if (!isset($values[$var])) {
2125
+					$values[$var] = array($var, $val);
2126
+		}
1944 2127
 
1945 2128
 	// puis on rassemble le tout
1946 2129
 	$hidden = array();
@@ -1960,8 +2143,9 @@  discard block
 block discarded – undo
1960 2143
 
1961 2144
 // http://doc.spip.org/@filtre_bornes_pagination_dist
1962 2145
 function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) {
1963
-	if($max<=0 OR $max>=$nombre)
1964
-		return array(1, $nombre);
2146
+	if($max<=0 OR $max>=$nombre) {
2147
+			return array(1, $nombre);
2148
+	}
1965 2149
 
1966 2150
 	$premiere = max(1, $courante-floor(($max-1)/2));
1967 2151
 	$derniere = min($nombre, $premiere+$max-2);
@@ -1976,8 +2160,9 @@  discard block
 block discarded – undo
1976 2160
 // http://doc.spip.org/@filtre_valeur_tableau
1977 2161
 function filtre_valeur_tableau($array, $index) {
1978 2162
 	if (!is_array($array)
1979
-	OR !isset($array[$index]))
1980
-		return null;
2163
+	OR !isset($array[$index])) {
2164
+			return null;
2165
+	}
1981 2166
 	return $array[$index];
1982 2167
 }
1983 2168
 // http://doc.spip.org/@filtre_reset
@@ -1991,7 +2176,9 @@  discard block
 block discarded – undo
1991 2176
 
1992 2177
 // http://doc.spip.org/@filtre_push
1993 2178
 function filtre_push($array, $val) {
1994
-	if($array == '' OR !array_push($array, $val)) return '';
2179
+	if($array == '' OR !array_push($array, $val)) {
2180
+	    return '';
2181
+	}
1995 2182
 	return $array;
1996 2183
 }
1997 2184
 
@@ -2009,17 +2196,22 @@  discard block
 block discarded – undo
2009 2196
 // http://doc.spip.org/@filtre_pagination_dist
2010 2197
 function filtre_pagination_dist($total, $nom, $position, $pas, $liste = true, $modele='', $connect='', $env=array()) {
2011 2198
 	static $ancres = array();
2012
-	if ($pas<1) return '';
2199
+	if ($pas<1) {
2200
+	    return '';
2201
+	}
2013 2202
 	$ancre = 'pagination'.$nom; // #pagination_articles
2014 2203
 	$debut = 'debut'.$nom; // 'debut_articles'
2015 2204
 
2016 2205
 	// n'afficher l'ancre qu'une fois
2017
-	if (!isset($ancres[$ancre]))
2018
-		$bloc_ancre = $ancres[$ancre] = "<a name='".$ancre."' id='".$ancre."'></a>";
2019
-	else $bloc_ancre = '';
2206
+	if (!isset($ancres[$ancre])) {
2207
+			$bloc_ancre = $ancres[$ancre] = "<a name='".$ancre."' id='".$ancre."'></a>";
2208
+	} else {
2209
+	    $bloc_ancre = '';
2210
+	}
2020 2211
 	// liste = false : on ne veut que l'ancre
2021
-	if (!$liste)
2022
-		return $ancres[$ancre];
2212
+	if (!$liste) {
2213
+			return $ancres[$ancre];
2214
+	}
2023 2215
 
2024 2216
 	$pagination = array(
2025 2217
 		'debut' => $debut,
@@ -2032,14 +2224,18 @@  discard block
 block discarded – undo
2032 2224
 		'ancre' => $ancre,
2033 2225
 		'bloc_ancre' => $bloc_ancre
2034 2226
 	);
2035
-	if (is_array($env))
2036
-		$pagination = array_merge($env,$pagination);
2227
+	if (is_array($env)) {
2228
+			$pagination = array_merge($env,$pagination);
2229
+	}
2037 2230
 
2038 2231
 	// Pas de pagination
2039
-	if ($pagination['nombre_pages']<=1)
2040
-		return '';
2232
+	if ($pagination['nombre_pages']<=1) {
2233
+			return '';
2234
+	}
2041 2235
 
2042
-	if ($modele) $modele = '_'.$modele;
2236
+	if ($modele) {
2237
+	    $modele = '_'.$modele;
2238
+	}
2043 2239
 
2044 2240
 	return recuperer_fond("modeles/pagination$modele", $pagination, array('trim'=>true), $connect);
2045 2241
 }
@@ -2062,23 +2258,27 @@  discard block
 block discarded – undo
2062 2258
 // SI on lui donne a manger une feuille nommee _rtl.css il va faire l'inverse
2063 2259
 // http://doc.spip.org/@direction_css
2064 2260
 function direction_css ($css, $voulue='') {
2065
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) return $css;
2261
+	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2262
+	    return $css;
2263
+	}
2066 2264
 
2067 2265
 	// si on a precise le sens voulu en argument, le prendre en compte
2068 2266
 	if ($voulue = strtolower($voulue)) {
2069
-		if ($voulue != 'rtl' AND $voulue != 'ltr')
2070
-			$voulue = lang_dir($voulue);
2267
+		if ($voulue != 'rtl' AND $voulue != 'ltr') {
2268
+					$voulue = lang_dir($voulue);
2269
+		}
2270
+	} else {
2271
+			$voulue =  lang_dir();
2071 2272
 	}
2072
-	else
2073
-		$voulue =  lang_dir();
2074 2273
 
2075 2274
 	$r = count($r) > 1;
2076 2275
 	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2077 2276
 	$dir = $r ? 'rtl' : 'ltr';
2078 2277
 	$ndir = $r ? 'ltr' : 'rtl';
2079 2278
 
2080
-	if ($voulue == $dir)
2081
-		return $css;
2279
+	if ($voulue == $dir) {
2280
+			return $css;
2281
+	}
2082 2282
 
2083 2283
 	if (
2084 2284
 		// url absolue
@@ -2089,15 +2289,15 @@  discard block
 block discarded – undo
2089 2289
 		$cssf = parse_url($css);
2090 2290
 		$cssf = $cssf['path'].($cssf['query']?"?".$cssf['query']:"");
2091 2291
 		$cssf = preg_replace(',[?:&=],', "_", $cssf);
2092
-	}
2093
-	else {
2292
+	} else {
2094 2293
 		$distant = false;
2095 2294
 		$cssf = $css;
2096 2295
 		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2097 2296
 		//propose (rien a faire dans ce cas)
2098 2297
 		$f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css);
2099
-		if (@file_exists($f))
2100
-			return $f;
2298
+		if (@file_exists($f)) {
2299
+					return $f;
2300
+		}
2101 2301
 	}
2102 2302
 
2103 2303
 	// 2.
@@ -2110,14 +2310,17 @@  discard block
 block discarded – undo
2110 2310
 	if ($distant){
2111 2311
 		include_spip('inc/distant');
2112 2312
 		$contenu = recuperer_page($css);
2113
-		if (!$contenu) return $css;
2114
-	}
2115
-	else {
2313
+		if (!$contenu) {
2314
+		    return $css;
2315
+		}
2316
+	} else {
2116 2317
 		if ((@filemtime($f) > @filemtime($css))
2117
-			AND (_VAR_MODE != 'recalcul'))
2118
-			return $f;
2119
-		if (!lire_fichier($css, $contenu))
2120
-			return $css;
2318
+			AND (_VAR_MODE != 'recalcul')) {
2319
+					return $f;
2320
+		}
2321
+		if (!lire_fichier($css, $contenu)) {
2322
+					return $css;
2323
+		}
2121 2324
 	}
2122 2325
 
2123 2326
 	$contenu = str_replace(
@@ -2132,7 +2335,9 @@  discard block
 block discarded – undo
2132 2335
 	foreach($regs[1] as $k=>$import_css){
2133 2336
 		$css_direction = direction_css("$d/$import_css",$voulue);
2134 2337
 		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2135
-		if (substr($css_direction,0,strlen($d)+1)=="$d/") $css_direction = substr($css_direction,strlen($d)+1);
2338
+		if (substr($css_direction,0,strlen($d)+1)=="$d/") {
2339
+		    $css_direction = substr($css_direction,strlen($d)+1);
2340
+		}
2136 2341
 		// si la css_direction commence par $dir_var on la fait passer pour une absolue
2137 2342
 		elseif (substr($css_direction,0,strlen($dir_var))==$dir_var) {
2138 2343
 			$css_direction = substr($css_direction,strlen($dir_var));
@@ -2147,11 +2352,13 @@  discard block
 block discarded – undo
2147 2352
 	$contenu = urls_absolues_css($contenu, $css);
2148 2353
 
2149 2354
 	// virer les fausses url absolues que l'on a mis dans les import
2150
-	if (count($src_faux_abs))
2151
-		$contenu = str_replace(array_keys($src_faux_abs),$src_faux_abs,$contenu);
2355
+	if (count($src_faux_abs)) {
2356
+			$contenu = str_replace(array_keys($src_faux_abs),$src_faux_abs,$contenu);
2357
+	}
2152 2358
 
2153
-	if (!ecrire_fichier($f, $contenu))
2154
-		return $css;
2359
+	if (!ecrire_fichier($f, $contenu)) {
2360
+			return $css;
2361
+	}
2155 2362
 
2156 2363
 	return $f;
2157 2364
 }
@@ -2160,7 +2367,9 @@  discard block
 block discarded – undo
2160 2367
 // cree (ou recree) dans _DIR_VAR/cache_css/ une css dont les url relatives sont passees en url absolues
2161 2368
 // http://doc.spip.org/@url_absolue_css
2162 2369
 function url_absolue_css ($css) {
2163
-	if (!preg_match(',\.css$,i', $css, $r)) return $css;
2370
+	if (!preg_match(',\.css$,i', $css, $r)) {
2371
+	    return $css;
2372
+	}
2164 2373
 
2165 2374
 	$url_absolue_css = url_absolue($css);
2166 2375
 
@@ -2170,26 +2379,29 @@  discard block
 block discarded – undo
2170 2379
 		. '.css';
2171 2380
 
2172 2381
 	if ((@filemtime($f) > @filemtime($css))
2173
-	AND (_VAR_MODE != 'recalcul'))
2174
-		return $f;
2382
+	AND (_VAR_MODE != 'recalcul')) {
2383
+			return $f;
2384
+	}
2175 2385
 
2176 2386
 	if ($url_absolue_css==$css){
2177 2387
 		if (strncmp($GLOBALS['meta']['adresse_site'],$css,$l=strlen($GLOBALS['meta']['adresse_site']))!=0
2178 2388
 		 OR !lire_fichier(_DIR_RACINE . substr($css,$l), $contenu)){
2179 2389
 		 		include_spip('inc/distant');
2180
-		 		if (!$contenu = recuperer_page($css))
2181
-					return $css;
2390
+		 		if (!$contenu = recuperer_page($css)) {
2391
+		 							return $css;
2392
+		 		}
2182 2393
 		}
2394
+	} elseif (!lire_fichier($css, $contenu)) {
2395
+			return $css;
2183 2396
 	}
2184
-	elseif (!lire_fichier($css, $contenu))
2185
-		return $css;
2186 2397
 
2187 2398
 	// passer les url relatives a la css d'origine en url absolues
2188 2399
 	$contenu = urls_absolues_css($contenu, $css);
2189 2400
 
2190 2401
 	// ecrire la css
2191
-	if (!ecrire_fichier($f, $contenu))
2192
-		return $css;
2402
+	if (!ecrire_fichier($f, $contenu)) {
2403
+			return $css;
2404
+	}
2193 2405
 
2194 2406
 	return $f;
2195 2407
 }
@@ -2257,10 +2469,11 @@  discard block
 block discarded – undo
2257 2469
 	$expression=str_replace("/","\/",$expression);
2258 2470
 
2259 2471
 	if (preg_match('/' . $expression . '/' . $modif,$texte, $r)) {
2260
-		if (isset($r[$capte]))
2261
-			return $r[$capte];
2262
-		else
2263
-			return true;
2472
+		if (isset($r[$capte])) {
2473
+					return $r[$capte];
2474
+		} else {
2475
+					return true;
2476
+		}
2264 2477
 	}
2265 2478
 	return false;
2266 2479
 }
@@ -2287,8 +2500,9 @@  discard block
 block discarded – undo
2287 2500
 	if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
2288 2501
 	AND preg_match_all(
2289 2502
 	',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
2290
-	$t, $matches, PREG_PATTERN_ORDER))
2291
-		$doublons['documents'] .= "," . join(',', $matches[1]);
2503
+	$t, $matches, PREG_PATTERN_ORDER)) {
2504
+			$doublons['documents'] .= "," . join(',', $matches[1]);
2505
+	}
2292 2506
 
2293 2507
 	return $letexte;
2294 2508
 }
@@ -2311,9 +2525,10 @@  discard block
 block discarded – undo
2311 2525
 	$ignore_params);
2312 2526
 	$tableau = unserialize($texte);
2313 2527
 	$texte = "";
2314
-	foreach ($tableau as $i => $j)
2315
-		if (is_string($j) AND !in_array($i,$ignore_params))
2528
+	foreach ($tableau as $i => $j) {
2529
+			if (is_string($j) AND !in_array($i,$ignore_params))
2316 2530
 			$texte .= "<param name='".$i."'\n\tvalue='".$j."' />";
2531
+	}
2317 2532
 	return $texte;
2318 2533
 }
2319 2534
 // A partir d'un #ENV, retourne des attributs
@@ -2324,9 +2539,10 @@  discard block
 block discarded – undo
2324 2539
 	$ignore_params);
2325 2540
 	$tableau = unserialize($texte);
2326 2541
 	$texte = "";
2327
-	foreach ($tableau as $i => $j)
2328
-		if (is_string($j) AND !in_array($i,$ignore_params))
2542
+	foreach ($tableau as $i => $j) {
2543
+			if (is_string($j) AND !in_array($i,$ignore_params))
2329 2544
 			$texte .= $i."='".$j."' ";
2545
+	}
2330 2546
 	return $texte;
2331 2547
 }
2332 2548
 
@@ -2344,11 +2560,18 @@  discard block
 block discarded – undo
2344 2560
 function charge_scripts($files, $script = true) {
2345 2561
 	$flux = "";
2346 2562
 	foreach(is_array($files)?$files:explode("|",$files) as $file) {
2347
-		if (!is_string($file)) continue;
2348
-		if ($script)
2349
-			$file = preg_match(",^\w+$,",$file) ? "javascript/$file.js" : '';
2350
-		if ($file) $path = find_in_path($file);
2351
-		if ($path) $flux .= spip_file_get_contents($path);
2563
+		if (!is_string($file)) {
2564
+		    continue;
2565
+		}
2566
+		if ($script) {
2567
+					$file = preg_match(",^\w+$,",$file) ? "javascript/$file.js" : '';
2568
+		}
2569
+		if ($file) {
2570
+		    $path = find_in_path($file);
2571
+		}
2572
+		if ($path) {
2573
+		    $flux .= spip_file_get_contents($path);
2574
+		}
2352 2575
 	}
2353 2576
 	return $flux;
2354 2577
 }
@@ -2372,19 +2595,20 @@  discard block
 block discarded – undo
2372 2595
  * @return string
2373 2596
  */
2374 2597
 function http_img_pack($img, $alt, $atts='', $title='', $options = array()) {
2375
-	if (!isset($options['chemin_image']) OR $options['chemin_image']==true)
2376
-		$img = chemin_image($img);
2598
+	if (!isset($options['chemin_image']) OR $options['chemin_image']==true) {
2599
+			$img = chemin_image($img);
2600
+	}
2377 2601
 	if (stripos($atts, 'width')===false){
2378 2602
 		// utiliser directement l'info de taille presente dans le nom
2379 2603
 		if ((!isset($options['utiliser_suffixe_size']) OR $options['utiliser_suffixe_size']==true)
2380 2604
 		    AND preg_match(',-([0-9]+)[.](png|gif)$,',$img,$regs)){
2381 2605
 			$largeur = $hauteur = intval($regs[1]);
2382
-		}
2383
-		else{
2606
+		} else{
2384 2607
 			$taille = taille_image($img);
2385 2608
 			list($hauteur,$largeur) = $taille;
2386
-			if (!$hauteur OR !$largeur)
2387
-				return "";
2609
+			if (!$hauteur OR !$largeur) {
2610
+							return "";
2611
+			}
2388 2612
 		}
2389 2613
 		$atts.=" width='".$largeur."' height='".$hauteur."'";
2390 2614
 	}
@@ -2424,11 +2648,12 @@  discard block
 block discarded – undo
2424 2648
 // http://doc.spip.org/@filtre_foreach_dist
2425 2649
 function filtre_foreach_dist($balise_deserializee, $modele = 'foreach') {
2426 2650
 	$texte = '';
2427
-	if(is_array($balise_deserializee))
2428
-		foreach($balise_deserializee as $k => $v) {
2651
+	if(is_array($balise_deserializee)) {
2652
+			foreach($balise_deserializee as $k => $v) {
2429 2653
 			$res = recuperer_fond('modeles/'.$modele,
2430 2654
 				array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
2431 2655
 			);
2656
+	}
2432 2657
 			$texte .= $res;
2433 2658
 		}
2434 2659
 	return $texte;
@@ -2445,27 +2670,30 @@  discard block
 block discarded – undo
2445 2670
 	$plugin = strtoupper($plugin);
2446 2671
 	$plugins_actifs = liste_plugin_actifs();
2447 2672
 
2448
-	if (!$plugin)
2449
-		return serialize(array_keys($plugins_actifs));
2450
-	elseif (empty($plugins_actifs[$plugin]))
2451
-		return '';
2452
-	elseif ($type_info == 'est_actif')
2453
-		return $plugins_actifs[$plugin] ? 1 : 0;
2454
-	elseif (isset($plugins_actifs[$plugin][$type_info]))
2455
-		return $plugins_actifs[$plugin][$type_info];
2456
-	else {
2673
+	if (!$plugin) {
2674
+			return serialize(array_keys($plugins_actifs));
2675
+	} elseif (empty($plugins_actifs[$plugin])) {
2676
+			return '';
2677
+	} elseif ($type_info == 'est_actif') {
2678
+			return $plugins_actifs[$plugin] ? 1 : 0;
2679
+	} elseif (isset($plugins_actifs[$plugin][$type_info])) {
2680
+			return $plugins_actifs[$plugin][$type_info];
2681
+	} else {
2457 2682
 		$get_infos = charger_fonction('get_infos','plugins');
2458 2683
 		// On prend en compte les extensions
2459
-		if (!is_dir($plugins_actifs[$plugin]['dir_type']))
2460
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
2461
-		else
2462
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
2463
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], false, $dir_plugins))
2464
-			return '';
2465
-		if ($type_info == 'tout')
2466
-			return $infos;
2467
-		else
2468
-			return strval($infos[$type_info]);
2684
+		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
2685
+					$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
2686
+		} else {
2687
+					$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
2688
+		}
2689
+		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], false, $dir_plugins)) {
2690
+					return '';
2691
+		}
2692
+		if ($type_info == 'tout') {
2693
+					return $infos;
2694
+		} else {
2695
+					return strval($infos[$type_info]);
2696
+		}
2469 2697
 	}
2470 2698
 }
2471 2699
 
@@ -2489,8 +2717,9 @@  discard block
 block discarded – undo
2489 2717
  */
2490 2718
 function filtre_puce_statut_dist($statut,$objet,$id_objet=0,$id_parent=0){
2491 2719
 	static $puce_statut = null;
2492
-	if (!$puce_statut)
2493
-		$puce_statut = charger_fonction('puce_statut','inc');
2720
+	if (!$puce_statut) {
2721
+			$puce_statut = charger_fonction('puce_statut','inc');
2722
+	}
2494 2723
 	return $puce_statut($id_objet, $statut, $id_parent, $objet, false, objet_info($objet,'editable')?_ACTIVER_PUCE_RAPIDE:false);
2495 2724
 }
2496 2725
 
@@ -2528,8 +2757,9 @@  discard block
 block discarded – undo
2528 2757
 		}
2529 2758
 	}
2530 2759
 	
2531
-	if (!function_exists('calculer_cle_action'))
2532
-		include_spip("inc/securiser_action");
2760
+	if (!function_exists('calculer_cle_action')) {
2761
+			include_spip("inc/securiser_action");
2762
+	}
2533 2763
 
2534 2764
 	$c = serialize($c);
2535 2765
 	$cle = calculer_cle_action($form . $c);
@@ -2573,8 +2803,12 @@  discard block
 block discarded – undo
2573 2803
 		$env = $md5;
2574 2804
 	} 
2575 2805
 	
2576
-	if ($emboite === NULL) return $env;
2577
-	if (!trim($emboite)) return "";
2806
+	if ($emboite === NULL) {
2807
+	    return $env;
2808
+	}
2809
+	if (!trim($emboite)) {
2810
+	    return "";
2811
+	}
2578 2812
 	// toujours encoder l'url source dans le bloc ajax
2579 2813
 	$r = self();
2580 2814
 	$r = ' data-origin="'.$r.'"';
@@ -2590,8 +2824,9 @@  discard block
 block discarded – undo
2590 2824
 // la procedure inverse de encoder_contexte_ajax()
2591 2825
 // http://doc.spip.org/@decoder_contexte_ajax
2592 2826
 function decoder_contexte_ajax($c,$form='') {
2593
-	if (!function_exists('calculer_cle_action'))
2594
-		include_spip("inc/securiser_action");
2827
+	if (!function_exists('calculer_cle_action')) {
2828
+			include_spip("inc/securiser_action");
2829
+	}
2595 2830
 	if (( (defined('_CACHE_CONTEXTES_AJAX') AND _CACHE_CONTEXTES_AJAX) OR strlen($c)==32)
2596 2831
 		AND $dir = sous_repertoire(_DIR_CACHE, 'contextes')
2597 2832
 		AND lire_fichier("$dir/c$c",$contexte)) {
@@ -2599,8 +2834,9 @@  discard block
 block discarded – undo
2599 2834
 	} else {
2600 2835
 		$c = @base64_decode($c);
2601 2836
 		$c = _xor($c);
2602
-		if (function_exists('gzdeflate') && function_exists('gzinflate'))
2603
-			$c = @gzinflate($c);
2837
+		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
2838
+					$c = @gzinflate($c);
2839
+		}
2604 2840
 	}
2605 2841
 
2606 2842
 	// extraire la signature en debut de contexte
@@ -2624,15 +2860,17 @@  discard block
 block discarded – undo
2624 2860
 // http://doc.spip.org/@_xor
2625 2861
 function _xor($message, $key=null){
2626 2862
 	if (is_null($key)) {
2627
-		if (!function_exists('calculer_cle_action'))
2628
-			include_spip("inc/securiser_action");
2863
+		if (!function_exists('calculer_cle_action')) {
2864
+					include_spip("inc/securiser_action");
2865
+		}
2629 2866
 		$key = pack("H*", calculer_cle_action('_xor'));
2630 2867
 	}
2631 2868
 
2632 2869
 	$keylen = strlen($key);
2633 2870
 	$messagelen = strlen($message);
2634
-	for($i=0; $i<$messagelen; $i++)
2635
-		$message[$i] = ~($message[$i]^$key[$i%$keylen]);
2871
+	for($i=0; $i<$messagelen; $i++) {
2872
+			$message[$i] = ~($message[$i]^$key[$i%$keylen]);
2873
+	}
2636 2874
 
2637 2875
 	return $message;
2638 2876
 }
@@ -2671,8 +2909,9 @@  discard block
 block discarded – undo
2671 2909
 	  	.($rel?" rel='".attribut_html($rel)."'":'')
2672 2910
 		.$evt;
2673 2911
 	}
2674
-	if ($libelle === NULL)
2675
-		$libelle = $url;
2912
+	if ($libelle === NULL) {
2913
+			$libelle = $url;
2914
+	}
2676 2915
 	return "<$bal $att>$libelle</$bal>";
2677 2916
 }
2678 2917
 
@@ -2690,12 +2929,19 @@  discard block
 block discarded – undo
2690 2929
  * @return string : la chaine de langue finale en utilisant la fonction _T()
2691 2930
  */
2692 2931
 function singulier_ou_pluriel($nb,$chaine_un,$chaine_plusieurs,$var='nb',$vars=array()){
2693
-	if (!$nb=intval($nb)) return "";
2694
-	if (!is_array($vars)) return "";
2932
+	if (!$nb=intval($nb)) {
2933
+	    return "";
2934
+	}
2935
+	if (!is_array($vars)) {
2936
+	    return "";
2937
+	}
2695 2938
 	$vars[$var] = $nb;
2696
-	if ($nb>1) return _T($chaine_plusieurs, $vars);
2697
-	else return _T($chaine_un,$vars);
2698
-}
2939
+	if ($nb>1) {
2940
+	    return _T($chaine_plusieurs, $vars);
2941
+	} else {
2942
+	    return _T($chaine_un,$vars);
2943
+	}
2944
+	}
2699 2945
 
2700 2946
 
2701 2947
 /**
@@ -2719,16 +2965,18 @@  discard block
 block discarded – undo
2719 2965
  * @return string 
2720 2966
  */
2721 2967
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction="", $class="",$javascript=""){
2722
-	if (in_array($fonction,array("del","supprimer.gif")))
2723
-		$class .= ' danger';
2724
-	elseif ($fonction == "rien.gif")
2725
-		$fonction = "";
2726
-	elseif ($fonction == "delsafe")
2727
-		$fonction = "del";
2968
+	if (in_array($fonction,array("del","supprimer.gif"))) {
2969
+			$class .= ' danger';
2970
+	} elseif ($fonction == "rien.gif") {
2971
+			$fonction = "";
2972
+	} elseif ($fonction == "delsafe") {
2973
+			$fonction = "del";
2974
+	}
2728 2975
 
2729 2976
 	// remappage des icone : article-24.png+new => article-new-24.png
2730
-	if ($icone_renommer = charger_fonction('icone_renommer','inc',true))
2731
-		list($fond,$fonction) = $icone_renommer($fond,$fonction);
2977
+	if ($icone_renommer = charger_fonction('icone_renommer','inc',true)) {
2978
+			list($fond,$fonction) = $icone_renommer($fond,$fonction);
2979
+	}
2732 2980
 
2733 2981
 	// ajouter le type d'objet dans la class de l'icone
2734 2982
 	$class .= " " . substr(basename($fond),0,-4);
@@ -2739,37 +2987,39 @@  discard block
 block discarded – undo
2739 2987
 	$ajax = "";
2740 2988
 	if (strpos($class,"ajax")!==false) {
2741 2989
 			$ajax="ajax";
2742
-		if (strpos($class,"preload")!==false)
2743
-			$ajax.=" preload";
2744
-		if (strpos($class,"nocache")!==false)
2745
-			$ajax.=" nocache";
2990
+		if (strpos($class,"preload")!==false) {
2991
+					$ajax.=" preload";
2992
+		}
2993
+		if (strpos($class,"nocache")!==false) {
2994
+					$ajax.=" nocache";
2995
+		}
2746 2996
 		$ajax=" class='$ajax'";
2747 2997
 	}
2748 2998
 
2749 2999
 	$size = 24;
2750
-	if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i",$fond,$match))
2751
-		$size = $match[1];
3000
+	if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i",$fond,$match)) {
3001
+			$size = $match[1];
3002
+	}
2752 3003
 
2753 3004
 	if ($fonction){
2754 3005
 		// 2 images pour composer l'icone : le fond (article) en background,
2755 3006
 		// la fonction (new) en image
2756 3007
 		$icone = http_img_pack($fonction, $alt, "width='$size' height='$size'\n" .
2757 3008
 					http_style_background($fond));
2758
-	}
2759
-	else {
3009
+	} else {
2760 3010
 		$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
2761 3011
 	}
2762 3012
 
2763
-	if ($type=='lien')
2764
-		return "<span class='icone s$size $class'>"
3013
+	if ($type=='lien') {
3014
+			return "<span class='icone s$size $class'>"
2765 3015
 		. "<a href='$lien'$title$ajax$javascript>"
2766 3016
 		. $icone
2767 3017
 		. "<b>$texte</b>"
2768 3018
 		. "</a></span>\n";
2769
-
2770
-	else
2771
-		return bouton_action("$icone<b>$texte</b>",$lien,"icone s$size $class",$javascript,$alt);
2772
-}
3019
+	} else {
3020
+			return bouton_action("$icone<b>$texte</b>",$lien,"icone s$size $class",$javascript,$alt);
3021
+	}
3022
+	}
2773 3023
 
2774 3024
 function icone_base($lien, $texte, $fond, $fonction="", $class="",$javascript=""){
2775 3025
 	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
@@ -2824,13 +3074,15 @@  discard block
 block discarded – undo
2824 3074
 
2825 3075
 	$res = "";
2826 3076
 	foreach($boutons as $page => $detail){
2827
-		if ($detail->icone AND strlen(trim($detail->icone)))
2828
-			$res .="\n.navigation_avec_icones #bando1_$page {background-image:url(".$detail->icone.");}";
3077
+		if ($detail->icone AND strlen(trim($detail->icone))) {
3078
+					$res .="\n.navigation_avec_icones #bando1_$page {background-image:url(".$detail->icone.");}";
3079
+		}
2829 3080
 		$selecteur = (in_array($page,array('outils_rapides','outils_collaboratifs'))?"":".navigation_avec_icones ");
2830
-		if (is_array($detail->sousmenu))
2831
-			foreach($detail->sousmenu as $souspage=>$sousdetail)
3081
+		if (is_array($detail->sousmenu)) {
3082
+					foreach($detail->sousmenu as $souspage=>$sousdetail)
2832 3083
 				if ($sousdetail->icone AND strlen(trim($sousdetail->icone)))
2833 3084
 					$res .="\n$selecteur.bando2_$souspage {background-image:url(".$sousdetail->icone.");}";
3085
+		}
2834 3086
 	}
2835 3087
 	return $res;
2836 3088
 }
@@ -2853,10 +3105,11 @@  discard block
 block discarded – undo
2853 3105
 function bouton_action($libelle, $url, $class="", $confirm="", $title="", $callback=""){
2854 3106
 	if ($confirm) {
2855 3107
 		$confirm = "confirm(\"" . attribut_html($confirm) . "\")";
2856
-	  if ($callback)
2857
-		  $callback = "$confirm?($callback):false";
2858
-	  else
2859
-		  $callback = $confirm;
3108
+	  if ($callback) {
3109
+	  		  $callback = "$confirm?($callback):false";
3110
+	  } else {
3111
+	  		  $callback = $confirm;
3112
+	  }
2860 3113
 	}
2861 3114
 	$onclick = $callback?" onclick='return ".addcslashes($callback,"'")."'":"";
2862 3115
 	$title = $title ? " title='$title'" : "";
@@ -2890,8 +3143,9 @@  discard block
 block discarded – undo
2890 3143
 
2891 3144
 	$champ = $t;
2892 3145
 
2893
-	if (strncmp($t,'num ',4)==0)
2894
-		$champ = substr($t,4);
3146
+	if (strncmp($t,'num ',4)==0) {
3147
+			$champ = substr($t,4);
3148
+	}
2895 3149
 	// enlever les autres espaces non evacues par tri_protege_champ
2896 3150
 	$champ = preg_replace(',\s,','',$champ);
2897 3151
 
@@ -2905,11 +3159,12 @@  discard block
 block discarded – undo
2905 3159
 			}
2906 3160
 		}
2907 3161
 	}
2908
-	if (strncmp($t,'num ',4)==0)
2909
-		return "0+$champ";
2910
-	else
2911
-		return $champ;
2912
-}
3162
+	if (strncmp($t,'num ',4)==0) {
3163
+			return "0+$champ";
3164
+	} else {
3165
+			return $champ;
3166
+	}
3167
+	}
2913 3168
 
2914 3169
 /**
2915 3170
  * Interpreter les multi xxx et num xxx utilise comme tri
@@ -2959,16 +3214,19 @@  discard block
 block discarded – undo
2959 3214
 
2960 3215
 	// On verifie qu'on a tout ce qu'il faut
2961 3216
 	$id_objet = intval($id_objet);
2962
-	if (!($id_objet and $type_objet and $info))
2963
-		return '';
3217
+	if (!($id_objet and $type_objet and $info)) {
3218
+			return '';
3219
+	}
2964 3220
 
2965 3221
 	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
2966
-	if (isset($objets[$type_objet]) AND $objets[$type_objet]===false)
2967
-		return '';
3222
+	if (isset($objets[$type_objet]) AND $objets[$type_objet]===false) {
3223
+			return '';
3224
+	}
2968 3225
 
2969 3226
 	// Si on demande l'url, on retourne direct la fonction
2970
-	if ($info == 'url')
2971
-		return generer_url_entite($id_objet, $type_objet);
3227
+	if ($info == 'url') {
3228
+			return generer_url_entite($id_objet, $type_objet);
3229
+	}
2972 3230
 
2973 3231
 	// Sinon on va tout chercher dans la table et on garde en memoire
2974 3232
 	$demande_titre = ($info == 'titre');
@@ -2978,11 +3236,13 @@  discard block
 block discarded – undo
2978 3236
 	  OR
2979 3237
 	  ($demande_titre AND !isset($objets[$type_objet][$id_objet]['titre']))
2980 3238
 	  ){
2981
-		if (!$trouver_table)
2982
-			$trouver_table = charger_fonction('trouver_table','base');
3239
+		if (!$trouver_table) {
3240
+					$trouver_table = charger_fonction('trouver_table','base');
3241
+		}
2983 3242
 		$desc = $trouver_table(table_objet_sql($type_objet));
2984
-		if (!$desc)
2985
-			return $objets[$type_objet] = false;
3243
+		if (!$desc) {
3244
+					return $objets[$type_objet] = false;
3245
+		}
2986 3246
 
2987 3247
 		// Si on demande le titre, on le gere en interne
2988 3248
 		$champ_titre = "";
@@ -3000,14 +3260,17 @@  discard block
 block discarded – undo
3000 3260
 	}
3001 3261
 
3002 3262
 	// Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
3003
-	if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true))
3004
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
3263
+	if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
3264
+			$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
3265
+	}
3005 3266
 	// Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
3006
-	else if ($generer = charger_fonction("generer_${info}_entite", '', true))
3007
-		$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
3267
+	else if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
3268
+			$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
3269
+	}
3008 3270
 	// Sinon on prend directement le champ SQL tel quel
3009
-	else
3010
-		$info_generee = (isset($objets[$type_objet][$id_objet][$info])?$objets[$type_objet][$id_objet][$info]:'');
3271
+	else {
3272
+			$info_generee = (isset($objets[$type_objet][$id_objet][$info])?$objets[$type_objet][$id_objet][$info]:'');
3273
+	}
3011 3274
 
3012 3275
 	// On va ensuite chercher les traitements automatiques a faire
3013 3276
 	$champ = strtoupper($info);
@@ -3070,8 +3333,9 @@  discard block
 block discarded – undo
3070 3333
 	}
3071 3334
 
3072 3335
 	// caster $u en array si besoin
3073
-	if (is_object($u))
3074
-		$u = (array) $u;
3336
+	if (is_object($u)) {
3337
+			$u = (array) $u;
3338
+	}
3075 3339
 
3076 3340
 	if (is_array($u)){
3077 3341
 		$out = "";
@@ -3122,11 +3386,12 @@  discard block
 block discarded – undo
3122 3386
  * @return mixed|string
3123 3387
  */
3124 3388
 function objet_afficher_nb($nb, $objet){
3125
-	if (!$nb)
3126
-		return _T(objet_info($objet,'info_aucun_objet'));
3127
-	else
3128
-		return _T(objet_info($objet,$nb==1?'info_1_objet':'info_nb_objets'),array('nb'=>$nb));
3129
-}
3389
+	if (!$nb) {
3390
+			return _T(objet_info($objet,'info_aucun_objet'));
3391
+	} else {
3392
+			return _T(objet_info($objet,$nb==1?'info_1_objet':'info_nb_objets'),array('nb'=>$nb));
3393
+	}
3394
+	}
3130 3395
 
3131 3396
 /**
3132 3397
  * Filtre pour afficher l'img icone d'un objet
@@ -3156,8 +3421,9 @@  discard block
 block discarded – undo
3156 3421
 	if (strpos($flux,'<!-- insert_head_css -->')===false
3157 3422
 		AND $p=strpos($flux,'<!-- insert_head -->')){
3158 3423
 		// plutot avant le premier js externe (jquery) pour etre non bloquant
3159
-		if ($p1 = stripos($flux,'<script src=') AND $p1<$p)
3160
-			$p = $p1;
3424
+		if ($p1 = stripos($flux,'<script src=') AND $p1<$p) {
3425
+					$p = $p1;
3426
+		}
3161 3427
 		$flux = substr_replace($flux,pipeline('insert_head_css','<!-- insert_head_css -->'),$p,0);
3162 3428
 	}
3163 3429
 	return $flux;
@@ -3181,11 +3447,11 @@  discard block
 block discarded – undo
3181 3447
 	if (isset($contexte['format'])){
3182 3448
 		$extension = $contexte['format'];
3183 3449
 		unset($contexte['format']);
3184
-	}
3185
-	else {
3450
+	} else {
3186 3451
 		$extension = "html";
3187
-		if (preg_match(',[.](css|js|json)$,',$fond,$m))
3188
-			$extension = $m[1];
3452
+		if (preg_match(',[.](css|js|json)$,',$fond,$m)) {
3453
+					$extension = $m[1];
3454
+		}
3189 3455
 	}
3190 3456
 	// recuperer le contenu produit par le squelette
3191 3457
 	$options['raw'] = true;
@@ -3206,14 +3472,16 @@  discard block
 block discarded – undo
3206 3472
 		OR (defined('_VAR_MODE') AND _VAR_MODE=='recalcul')) {
3207 3473
 		$contenu = $cache['texte'];
3208 3474
 		// passer les urls en absolu si c'est une css
3209
-		if ($extension=="css")
3210
-			$contenu = urls_absolues_css($contenu, test_espace_prive()?generer_url_ecrire('accueil'):generer_url_public($fond));
3475
+		if ($extension=="css") {
3476
+					$contenu = urls_absolues_css($contenu, test_espace_prive()?generer_url_ecrire('accueil'):generer_url_public($fond));
3477
+		}
3211 3478
 		
3212 3479
 		// ne pas insérer de commentaire si c'est du json
3213 3480
 		if ($extension!="json") {
3214 3481
 			$comment = "/* #PRODUIRE{fond=$fond";
3215
-			foreach($contexte as $k=>$v)
3216
-				$comment .= ",$k=$v";
3482
+			foreach($contexte as $k=>$v) {
3483
+							$comment .= ",$k=$v";
3484
+			}
3217 3485
 			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
3218 3486
 			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
3219 3487
 			$comment .="}\n   md5:".md5($contenu)." */\n";
@@ -3239,7 +3507,9 @@  discard block
 block discarded – undo
3239 3507
  * @return string
3240 3508
  */
3241 3509
 function timestamp($fichier){
3242
-	if (!$fichier OR !file_exists($fichier)) return $fichier;
3510
+	if (!$fichier OR !file_exists($fichier)) {
3511
+	    return $fichier;
3512
+	}
3243 3513
 	$m = filemtime($fichier);
3244 3514
 	return "$fichier?$m";
3245 3515
 }
@@ -3289,12 +3559,15 @@  discard block
 block discarded – undo
3289 3559
  * @return string
3290 3560
  */
3291 3561
 function sinon_interdire_acces($ok=false, $url='', $statut=0){
3292
-	if ($ok) return '';
3562
+	if ($ok) {
3563
+	    return '';
3564
+	}
3293 3565
 	
3294 3566
 	// Vider tous les tampons
3295 3567
 	$level = @ob_get_level();
3296
-	while ($level--)
3297
-		@ob_end_clean();
3568
+	while ($level--) {
3569
+			@ob_end_clean();
3570
+	}
3298 3571
 	
3299 3572
 	include_spip('inc/headers');
3300 3573
 	$statut = intval($statut);
@@ -3320,12 +3593,15 @@  discard block
 block discarded – undo
3320 3593
 		// Dans tous les cas on modifie l'entité avec ce qui est demandé
3321 3594
 		http_status($statut);
3322 3595
 		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
3323
-		if ($statut >= 400 and !$url)
3324
-			echo recuperer_fond("$statut");
3596
+		if ($statut >= 400 and !$url) {
3597
+					echo recuperer_fond("$statut");
3598
+		}
3325 3599
 	}
3326 3600
 	
3327 3601
 	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
3328
-	if ($url) redirige_par_entete($url, '', $statut);
3602
+	if ($url) {
3603
+	    redirige_par_entete($url, '', $statut);
3604
+	}
3329 3605
 	
3330 3606
 	exit;
3331 3607
 }
@@ -3337,8 +3613,9 @@  discard block
 block discarded – undo
3337 3613
  * @return string
3338 3614
  */
3339 3615
 function filtre_compacte_dist($source, $format = null){
3340
-	if (function_exists('compacte'))
3341
-		return compacte($source, $format);
3616
+	if (function_exists('compacte')) {
3617
+			return compacte($source, $format);
3618
+	}
3342 3619
 	return $source;
3343 3620
 }
3344 3621
 
Please login to merge, or discard this patch.
Spacing   +494 added lines, -494 removed lines patch added patch discarded remove patch
@@ -26,12 +26,12 @@  discard block
 block discarded – undo
26 26
  * @param string $default
27 27
  * @return string
28 28
  */
29
-function charger_filtre($fonc, $default='filtre_identite_dist') {
29
+function charger_filtre($fonc, $default = 'filtre_identite_dist') {
30 30
 	include_spip('public/parametrer'); // inclure les fichiers fonctions
31 31
 	return chercher_filtre($fonc, $default);
32 32
 }
33 33
 
34
-function filtre_identite_dist($texte){return $texte;}
34
+function filtre_identite_dist($texte) {return $texte; }
35 35
 
36 36
 /**
37 37
  * http://doc.spip.org/@chercher_filtre
@@ -40,24 +40,24 @@  discard block
 block discarded – undo
40 40
  * @param null $default
41 41
  * @return string
42 42
  */
43
-function chercher_filtre($fonc, $default=NULL) {
43
+function chercher_filtre($fonc, $default = NULL) {
44 44
 	if (!$fonc) return $default;
45 45
 	// Cas des types mime, sans confondre avec les appels de fonction de classe
46 46
 	// Foo::Bar
47 47
 	// qui peuvent etre avec un namespace : space\Foo::Bar
48
-	if (preg_match(',^[\w]+/,',$fonc)){
49
-		$nom = preg_replace(',\W,','_', $fonc);
48
+	if (preg_match(',^[\w]+/,', $fonc)) {
49
+		$nom = preg_replace(',\W,', '_', $fonc);
50 50
 		$f = chercher_filtre($nom);
51 51
 		// cas du sous-type MIME sans filtre associe, passer au type:
52 52
 		// si filtre_text_plain pas defini, passe a filtre_text
53
-		if (!$f AND $nom!==$fonc)
54
-			$f = chercher_filtre(preg_replace(',\W.*$,','', $fonc));
53
+		if (!$f AND $nom !== $fonc)
54
+			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
55 55
 		return $f;
56 56
 	}
57 57
 	foreach (
58
-	array('filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc) as $f){
59
-		if (isset( $GLOBALS['spip_matrice'][$f]) AND is_string($g = $GLOBALS['spip_matrice'][$f]))
60
-			find_in_path($g,'', true);
58
+	array('filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc) as $f) {
59
+		if (isset($GLOBALS['spip_matrice'][$f]) AND is_string($g = $GLOBALS['spip_matrice'][$f]))
60
+			find_in_path($g, '', true);
61 61
 		if (function_exists($f)
62 62
 		OR (preg_match("/^(\w*)::(\w*)$/", $f, $regs)
63 63
 			AND is_callable(array($regs[1], $regs[2]))
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
  *       pas été fourni,
90 90
  *     Chaîne vide si le filtre n'a pas été trouvé et que $force a été fourni.
91 91
 **/
92
-function appliquer_filtre($arg, $filtre, $force=NULL) {
92
+function appliquer_filtre($arg, $filtre, $force = NULL) {
93 93
 	$f = chercher_filtre($filtre);
94 94
 	if (!$f) {
95 95
 		if (!$force) return '';
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
 	array_shift($args); // enlever $arg
101 101
 	array_shift($args); // enlever $filtre
102 102
 	array_unshift($args, $arg); // remettre $arg
103
-	return call_user_func_array($f,$args);
103
+	return call_user_func_array($f, $args);
104 104
 }
105 105
 
106 106
 // http://doc.spip.org/@spip_version
107 107
 function spip_version() {
108 108
 	$version = $GLOBALS['spip_version_affichee'];
109 109
 	if ($svn_revision = version_svn_courante(_DIR_RACINE))
110
-		$version .= ($svn_revision<0 ? ' SVN':'').' ['.abs($svn_revision).']';
110
+		$version .= ($svn_revision < 0 ? ' SVN' : '').' ['.abs($svn_revision).']';
111 111
 	return $version;
112 112
 }
113 113
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 		return intval($d[1]);
127 127
 
128 128
 	// version installee par SVN
129
-	if (lire_fichier($dir . '/.svn/entries', $c)
129
+	if (lire_fichier($dir.'/.svn/entries', $c)
130 130
 	AND (
131 131
 	(preg_match_all(
132 132
 	',committed-rev="([0-9]+)",', $c, $r1, PREG_PATTERN_ORDER)
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
 
145 145
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
146 146
 // et laisser passer les fonctions personnelles baptisees image_...
147
-$GLOBALS['spip_matrice']['image_graver'] = true;//'inc/filtres_images_mini.php';
148
-$GLOBALS['spip_matrice']['image_select'] = true;//'inc/filtres_images_mini.php';
149
-$GLOBALS['spip_matrice']['image_reduire'] = true;//'inc/filtres_images_mini.php';
150
-$GLOBALS['spip_matrice']['image_reduire_par'] = true;//'inc/filtres_images_mini.php';
151
-$GLOBALS['spip_matrice']['image_passe_partout'] = true;//'inc/filtres_images_mini.php';
147
+$GLOBALS['spip_matrice']['image_graver'] = true; //'inc/filtres_images_mini.php';
148
+$GLOBALS['spip_matrice']['image_select'] = true; //'inc/filtres_images_mini.php';
149
+$GLOBALS['spip_matrice']['image_reduire'] = true; //'inc/filtres_images_mini.php';
150
+$GLOBALS['spip_matrice']['image_reduire_par'] = true; //'inc/filtres_images_mini.php';
151
+$GLOBALS['spip_matrice']['image_passe_partout'] = true; //'inc/filtres_images_mini.php';
152 152
 
153 153
 $GLOBALS['spip_matrice']['couleur_html_to_hex'] = 'inc/filtres_images_mini.php';
154 154
 $GLOBALS['spip_matrice']['couleur_foncer'] = 'inc/filtres_images_mini.php';
@@ -170,14 +170,14 @@  discard block
 block discarded – undo
170 170
 // charge les fonctions graphiques et applique celle demandee
171 171
 // http://doc.spip.org/@filtrer
172 172
 function filtrer($filtre) {
173
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])){
174
-		find_in_path($f,'', true);
173
+	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
174
+		find_in_path($f, '', true);
175 175
 		$GLOBALS['spip_matrice'][$filtre] = true;
176 176
 	}
177 177
 	$tous = func_get_args();
178
-	if (substr($filtre,0,6)=='image_' && $GLOBALS['spip_matrice'][$filtre])
178
+	if (substr($filtre, 0, 6) == 'image_' && $GLOBALS['spip_matrice'][$filtre])
179 179
 		return image_filtrer($tous);
180
-	elseif($f = chercher_filtre($filtre)) {
180
+	elseif ($f = chercher_filtre($filtre)) {
181 181
 		array_shift($tous);
182 182
 		return call_user_func_array($f, $tous);
183 183
 	}
@@ -207,14 +207,14 @@  discard block
 block discarded – undo
207 207
  * [(#TRUC|debug{avant}|calcul|debug{apres}|etc)] affiche
208 208
  *   la valeur de #TRUC avant et après le calcul
209 209
  */
210
-function filtre_debug($val, $key=null) {
210
+function filtre_debug($val, $key = null) {
211 211
 	$debug = (
212
-		is_null($key) ? '' :  (var_export($key,true)." = ")
213
-	) . var_export($val, true);
212
+		is_null($key) ? '' : (var_export($key, true)." = ")
213
+	).var_export($val, true);
214 214
 
215 215
 	include_spip('inc/autoriser');
216 216
 	if (autoriser('webmestre'))
217
-		echo "<div class='spip_debug'>\n",$debug,"</div>\n";
217
+		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
218 218
 
219 219
 	spip_log($debug, 'debug');
220 220
 
@@ -229,20 +229,20 @@  discard block
 block discarded – undo
229 229
 // applique le filtre demande a chacune des occurrences
230 230
 
231 231
 // http://doc.spip.org/@image_filtrer
232
-function image_filtrer($args){
232
+function image_filtrer($args) {
233 233
 	$filtre = array_shift($args); # enlever $filtre
234 234
 	$texte = array_shift($args);
235 235
 	if (!strlen($texte)) return;
236
-	find_in_path('filtres_images_mini.php','inc/', true);
236
+	find_in_path('filtres_images_mini.php', 'inc/', true);
237 237
 	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
238 238
 	// Cas du nom de fichier local
239
-	if ( strpos(substr($texte,strlen(_DIR_RACINE)),'..')===FALSE
239
+	if (strpos(substr($texte, strlen(_DIR_RACINE)), '..') === FALSE
240 240
 	AND !preg_match(',^/|[<>]|\s,S', $texte)
241 241
 	AND (
242
-		file_exists(preg_replace(',[?].*$,','',$texte))
242
+		file_exists(preg_replace(',[?].*$,', '', $texte))
243 243
 		OR preg_match(';^(\w{3,7}://);', $texte) 
244 244
 		)) {
245
-		array_unshift($args,"<img src='$texte' />");
245
+		array_unshift($args, "<img src='$texte' />");
246 246
 		$res = call_user_func_array($filtre, $args);
247 247
 		statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
248 248
 		return $res;
@@ -253,30 +253,30 @@  discard block
 block discarded – undo
253 253
 		',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
254 254
 		$texte, $tags, PREG_SET_ORDER)) {
255 255
 		foreach ($tags as $tag) {
256
-			$class = extraire_attribut($tag[3],'class');
257
-			if (!$class || (strpos($class,'no_image_filtrer')===FALSE)){
258
-				array_unshift($args,$tag[3]);
256
+			$class = extraire_attribut($tag[3], 'class');
257
+			if (!$class || (strpos($class, 'no_image_filtrer') === FALSE)) {
258
+				array_unshift($args, $tag[3]);
259 259
 				if ($reduit = call_user_func_array($filtre, $args)) {
260 260
 					// En cas de span spip_documents, modifier le style=...width:
261
-					if($tag[1]){
261
+					if ($tag[1]) {
262 262
 						$w = extraire_attribut($reduit, 'width');
263
-						if (!$w AND preg_match(",width:\s*(\d+)px,S",extraire_attribut($reduit,'style'),$regs))
263
+						if (!$w AND preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs))
264 264
 							$w = $regs[1];
265
-						if ($w AND ($style = extraire_attribut($tag[1], 'style'))){
265
+						if ($w AND ($style = extraire_attribut($tag[1], 'style'))) {
266 266
 							$style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
267 267
 							$replace = inserer_attribut($tag[1], 'style', $style);
268 268
 							$texte = str_replace($tag[1], $replace, $texte);
269 269
 						}
270 270
 					}
271 271
 					// traiter aussi un eventuel mouseover
272
-					if ($mouseover = extraire_attribut($reduit,'onmouseover')){
273
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)){
272
+					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
273
+						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
274 274
 							$srcover = $match[1];
275 275
 							array_shift($args);
276
-							array_unshift($args,"<img src='".$match[1]."' />");
276
+							array_unshift($args, "<img src='".$match[1]."' />");
277 277
 							$srcover_filter = call_user_func_array($filtre, $args);
278
-							$srcover_filter = extraire_attribut($srcover_filter,'src');
279
-							$reduit = str_replace($srcover,$srcover_filter,$reduit);
278
+							$srcover_filter = extraire_attribut($srcover_filter, 'src');
279
+							$reduit = str_replace($srcover, $srcover_filter, $reduit);
280 280
 						}
281 281
 					}
282 282
 					$texte = str_replace($tag[3], $reduit, $texte);
@@ -296,44 +296,44 @@  discard block
 block discarded – undo
296 296
 // http://doc.spip.org/@taille_image
297 297
 function taille_image($img) {
298 298
 
299
-	static $largeur_img =array(), $hauteur_img= array();
299
+	static $largeur_img = array(), $hauteur_img = array();
300 300
 	$srcWidth = 0;
301 301
 	$srcHeight = 0;
302 302
 
303
-	$logo = extraire_attribut($img,'src');
303
+	$logo = extraire_attribut($img, 'src');
304 304
 
305 305
 	if (!$logo) $logo = $img;
306 306
 	else {
307
-		$srcWidth = extraire_attribut($img,'width');
308
-		$srcHeight = extraire_attribut($img,'height');
307
+		$srcWidth = extraire_attribut($img, 'width');
308
+		$srcHeight = extraire_attribut($img, 'height');
309 309
 	}
310 310
 
311 311
 	// ne jamais operer directement sur une image distante pour des raisons de perfo
312 312
 	// la copie locale a toutes les chances d'etre la ou de resservir
313
-	if (preg_match(';^(\w{3,7}://);', $logo)){
313
+	if (preg_match(';^(\w{3,7}://);', $logo)) {
314 314
 		include_spip('inc/distant');
315 315
 		$fichier = copie_locale($logo);
316 316
 		$logo = $fichier ? _DIR_RACINE . $fichier : $logo;
317 317
 	}
318
-	if (($p=strpos($logo,'?'))!==FALSE)
319
-		$logo=substr($logo,0,$p);
318
+	if (($p = strpos($logo, '?')) !== FALSE)
319
+		$logo = substr($logo, 0, $p);
320 320
 
321 321
 	$srcsize = false;
322 322
 	if (isset($largeur_img[$logo]))
323 323
 		$srcWidth = $largeur_img[$logo];
324 324
 	if (isset($hauteur_img[$logo]))
325 325
 		$srcHeight = $hauteur_img[$logo];
326
-	if (!$srcWidth OR !$srcHeight){
326
+	if (!$srcWidth OR !$srcHeight) {
327 327
 		if (file_exists($logo)
328
-			AND $srcsize = @getimagesize($logo)){
328
+			AND $srcsize = @getimagesize($logo)) {
329 329
 			if (!$srcWidth)	$largeur_img[$logo] = $srcWidth = $srcsize[0];
330 330
 			if (!$srcHeight)	$hauteur_img[$logo] = $srcHeight = $srcsize[1];
331 331
 		}
332 332
 		// $logo peut etre une reference a une image temporaire dont a n'a que le log .src
333 333
 		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
334
-		elseif(@file_exists($f = "$logo.src")
335
-		  AND lire_fichier($f,$valeurs)
336
-		  AND $valeurs=unserialize($valeurs)) {
334
+		elseif (@file_exists($f = "$logo.src")
335
+		  AND lire_fichier($f, $valeurs)
336
+		  AND $valeurs = unserialize($valeurs)) {
337 337
 			if (!$srcWidth)	$largeur_img[$logo] = $srcWidth = $valeurs["largeur_dest"];
338 338
 			if (!$srcHeight)	$hauteur_img[$logo] = $srcHeight = $valeurs["hauteur_dest"];
339 339
 	  }
@@ -343,13 +343,13 @@  discard block
 block discarded – undo
343 343
 // http://doc.spip.org/@largeur
344 344
 function largeur($img) {
345 345
 	if (!$img) return;
346
-	list ($h,$l) = taille_image($img);
346
+	list ($h, $l) = taille_image($img);
347 347
 	return $l;
348 348
 }
349 349
 // http://doc.spip.org/@hauteur
350 350
 function hauteur($img) {
351 351
 	if (!$img) return;
352
-	list ($h,$l) = taille_image($img);
352
+	list ($h, $l) = taille_image($img);
353 353
 	return $h;
354 354
 }
355 355
 
@@ -364,19 +364,19 @@  discard block
 block discarded – undo
364 364
 // et au cas particulier de &amp; qui devient &amp;amp; dans les url
365 365
 // http://doc.spip.org/@corriger_entites_html
366 366
 function corriger_entites_html($texte) {
367
-	if (strpos($texte,'&amp;') === false) return $texte;
367
+	if (strpos($texte, '&amp;') === false) return $texte;
368 368
 	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
369 369
 }
370 370
 // idem mais corriger aussi les &amp;eacute; en &eacute;
371 371
 // http://doc.spip.org/@corriger_toutes_entites_html
372 372
 function corriger_toutes_entites_html($texte) {
373
-	if (strpos($texte,'&amp;') === false) return $texte;
373
+	if (strpos($texte, '&amp;') === false) return $texte;
374 374
 	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
375 375
 }
376 376
 
377 377
 // http://doc.spip.org/@proteger_amp
378
-function proteger_amp($texte){
379
-	return str_replace('&','&amp;',$texte);
378
+function proteger_amp($texte) {
379
+	return str_replace('&', '&amp;', $texte);
380 380
 }
381 381
 
382 382
 //
@@ -391,13 +391,13 @@  discard block
 block discarded – undo
391 391
  *   echapper aussi les simples quotes en &#039;
392 392
  * @return mixed|string
393 393
  */
394
-function entites_html($texte, $tout=false, $quote=true) {
394
+function entites_html($texte, $tout = false, $quote = true) {
395 395
 	if (!is_string($texte) OR !$texte
396
-	OR strpbrk($texte, "&\"'<>")==false
396
+	OR strpbrk($texte, "&\"'<>") == false
397 397
 	) return $texte;
398 398
 	include_spip('inc/texte');
399
-	$flags = !defined('PHP_VERSION_ID') OR PHP_VERSION_ID < 50400 ? ENT_COMPAT : ENT_COMPAT|ENT_HTML401;
400
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $quote?ENT_QUOTES:$flags);
399
+	$flags = !defined('PHP_VERSION_ID') OR PHP_VERSION_ID < 50400 ? ENT_COMPAT : ENT_COMPAT | ENT_HTML401;
400
+	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $quote ?ENT_QUOTES:$flags);
401 401
 	if ($tout)
402 402
 		return corriger_toutes_entites_html($texte);
403 403
 	else
@@ -407,15 +407,15 @@  discard block
 block discarded – undo
407 407
 // Transformer les &eacute; dans le charset local
408 408
 // http://doc.spip.org/@filtrer_entites
409 409
 function filtrer_entites($texte) {
410
-	if (strpos($texte,'&') === false) return $texte;
410
+	if (strpos($texte, '&') === false) return $texte;
411 411
 	// filtrer
412 412
 	$texte = html2unicode($texte);
413 413
 	// remettre le tout dans le charset cible
414 414
 	$texte = unicode2charset($texte);
415 415
 	// cas particulier des " et ' qu'il faut filtrer aussi
416 416
 	// (on le faisait deja avec un &quot;)
417
-	if (strpos($texte,"&#")!==false)
418
-		$texte = str_replace(array("&#039;","&#39;","&#034;","&#34;"), array("'","'",'"','"'), $texte);
417
+	if (strpos($texte, "&#") !== false)
418
+		$texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
419 419
 	return $texte;
420 420
 }
421 421
 
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
 
449 449
 // Supprimer caracteres windows et les caracteres de controle ILLEGAUX
450 450
 // http://doc.spip.org/@corriger_caracteres
451
-function corriger_caracteres ($texte) {
451
+function corriger_caracteres($texte) {
452 452
 	$texte = corriger_caracteres_windows($texte);
453 453
 	$texte = supprimer_caracteres_illegaux($texte);
454 454
 	return $texte;
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
 	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
484 484
 	$texte = entites_html($texte, false, false);
485 485
 	// mais bien echapper les double quotes !
486
-	$texte = str_replace('"','&#034;',$texte);
486
+	$texte = str_replace('"', '&#034;', $texte);
487 487
 
488 488
 	// verifier le charset
489 489
 	$texte = charset2unicode($texte);
@@ -555,13 +555,13 @@  discard block
 block discarded – undo
555 555
 	$texte = supprimer_tags($texte);
556 556
 	$texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
557 557
 	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
558
-	$texte = str_replace("&#8217;","'",$texte);
558
+	$texte = str_replace("&#8217;", "'", $texte);
559 559
 	return $texte;
560 560
 }
561 561
 
562 562
 // Remplace les liens SPIP en liens ouvrant dans une nouvelle fenetre (target=blank)
563 563
 // http://doc.spip.org/@liens_ouvrants
564
-function liens_ouvrants ($texte) {
564
+function liens_ouvrants($texte) {
565 565
 	return preg_replace(",<a\s+([^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+)>,",
566 566
 		"<a \\1 target=\"_blank\">", $texte);
567 567
 }
@@ -572,16 +572,16 @@  discard block
 block discarded – undo
572 572
  * @return string
573 573
  */
574 574
 function liens_nofollow($texte) {
575
-	if (stripos($texte,"<a")===false)
575
+	if (stripos($texte, "<a") === false)
576 576
 		return $texte;
577 577
 
578
-	if (preg_match_all(",<a\b[^>]*>,UimsS",$texte, $regs, PREG_PATTERN_ORDER)){
579
-		foreach($regs[0] as $a){
580
-			$rel = extraire_attribut($a,"rel");
581
-			if (strpos($rel,"nofollow")===false){
582
-				$rel = "nofollow" . ($rel?" $rel":"");
583
-				$anofollow = inserer_attribut($a,"rel",$rel);
584
-				$texte = str_replace($a,$anofollow,$texte);
578
+	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
579
+		foreach ($regs[0] as $a) {
580
+			$rel = extraire_attribut($a, "rel");
581
+			if (strpos($rel, "nofollow") === false) {
582
+				$rel = "nofollow".($rel ? " $rel" : "");
583
+				$anofollow = inserer_attribut($a, "rel", $rel);
584
+				$texte = str_replace($a, $anofollow, $texte);
585 585
 			}
586 586
 		}
587 587
 	}
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
 
592 592
 // Transformer les sauts de paragraphe en simples passages a la ligne
593 593
 // http://doc.spip.org/@PtoBR
594
-function PtoBR($texte){
594
+function PtoBR($texte) {
595 595
 	$u = $GLOBALS['meta']['pcre_u'];
596 596
 	$texte = preg_replace("@</p>@iS", "\n", $texte);
597 597
 	$texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
@@ -649,15 +649,15 @@  discard block
 block discarded – undo
649 649
 
650 650
 // "127.4 ko" ou "3.1 Mo"
651 651
 // http://doc.spip.org/@taille_en_octets
652
-function taille_en_octets ($taille) {
652
+function taille_en_octets($taille) {
653 653
 	if ($taille < 1) return '';
654
-	if ($taille < 1024) {$taille = _T('taille_octets', array('taille' => $taille));}
655
-	else if ($taille < 1024*1024) {
656
-		$taille = _T('taille_ko', array('taille' => round($taille/1024, 1)));
657
-	} else if ($taille < 1024*1024*1024) {
658
-		$taille = _T('taille_mo', array('taille' => round($taille/1024/1024, 1)));
654
+	if ($taille < 1024) {$taille = _T('taille_octets', array('taille' => $taille)); }
655
+	else if ($taille < 1024 * 1024) {
656
+		$taille = _T('taille_ko', array('taille' => round($taille / 1024, 1)));
657
+	} else if ($taille < 1024 * 1024 * 1024) {
658
+		$taille = _T('taille_mo', array('taille' => round($taille / 1024 / 1024, 1)));
659 659
 	} else {
660
-		$taille = _T('taille_go', array('taille' => round($taille/1024/1024/1024, 2)));
660
+		$taille = _T('taille_go', array('taille' => round($taille / 1024 / 1024 / 1024, 2)));
661 661
 	}
662 662
 	return $taille;
663 663
 }
@@ -665,14 +665,14 @@  discard block
 block discarded – undo
665 665
 
666 666
 // Rend une chaine utilisable sans dommage comme attribut HTML
667 667
 // http://doc.spip.org/@attribut_html
668
-function attribut_html($texte,$textebrut = true) {
668
+function attribut_html($texte, $textebrut = true) {
669 669
 	$u = $GLOBALS['meta']['pcre_u'];
670 670
 	if ($textebrut)
671
-		$texte = preg_replace(array(",\n,",",\s(?=\s),msS".$u),array(" ",""),textebrut($texte));
671
+		$texte = preg_replace(array(",\n,", ",\s(?=\s),msS".$u), array(" ", ""), textebrut($texte));
672 672
 	$texte = texte_backend($texte);
673
-	$texte = str_replace(array("'",'"'),array('&#039;', '&#034;'), $texte);
673
+	$texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
674 674
 	
675
-	return preg_replace(array("/&(amp;|#38;)/","/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"),array("&","&#38;") , $texte);
675
+	return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"), $texte);
676 676
 }
677 677
 
678 678
 // Vider les url nulles comme 'http://' ou 'mailto:'
@@ -682,15 +682,15 @@  discard block
 block discarded – undo
682 682
 	# un message pour abs_url
683 683
 	$GLOBALS['mode_abs_url'] = 'url';
684 684
 	$url = trim($url);
685
-	$r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
686
-	return preg_match($r, $url) ? '': ($entites ? entites_html($url) : $url);
685
+	$r = ",^(?:"._PROTOCOLES_STD.'):?/?/?$,iS';
686
+	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
687 687
 }
688 688
 
689 689
 // Extraire une date de n'importe quel champ (a completer...)
690 690
 // http://doc.spip.org/@extraire_date
691 691
 function extraire_date($texte) {
692 692
 	// format = 2001-08
693
-	if (preg_match(",([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),",$texte,$regs))
693
+	if (preg_match(",([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),", $texte, $regs))
694 694
 		return $regs[1]."-".sprintf("%02d", $regs[2])."-01";
695 695
 }
696 696
 
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 }
704 704
 
705 705
 // http://doc.spip.org/@securiser_acces
706
-function securiser_acces($id_auteur, $cle, $dir, $op='', $args='')
706
+function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '')
707 707
 {
708 708
 	include_spip('inc/acces');
709 709
 	if ($op) $dir .= " $op $args";
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
  * @return mixed
728 728
  * 		Retourne $texte, sinon $sinon.
729 729
 **/
730
-function sinon ($texte, $sinon='') {
730
+function sinon($texte, $sinon = '') {
731 731
 	if ($texte OR (!is_array($texte) AND strlen($texte)))
732 732
 		return $texte;
733 733
 	else
@@ -742,7 +742,7 @@  discard block
 block discarded – undo
742 742
 
743 743
 // |choixsiegal{aquoi,oui,non} affiche oui si la chaine est egal a aquoi ...
744 744
 // http://doc.spip.org/@choixsiegal
745
-function choixsiegal($a1,$a2,$v,$f) {
745
+function choixsiegal($a1, $a2, $v, $f) {
746 746
 	return ($a1 == $a2) ? $v : $f;
747 747
 }
748 748
 
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
 		if (preg_match("#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#", $date, $regs))
762 762
 			$date = $regs[1]."-00-00".$regs[3];
763 763
 		else if (preg_match("#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#", $date, $regs))
764
-			$date = preg_replace("@/@","-",$regs[1])."-00".$regs[3];
764
+			$date = preg_replace("@/@", "-", $regs[1])."-00".$regs[3];
765 765
 		else
766 766
 			$date = date("Y-m-d H:i:s", strtotime($date));
767 767
 
@@ -773,16 +773,16 @@  discard block
 block discarded – undo
773 773
 
774 774
 // http://doc.spip.org/@vider_date
775 775
 function vider_date($letexte) {
776
-	if (strncmp("0000-00-00", $letexte,10)==0) return '';
777
-	if (strncmp("0001-01-01", $letexte,10)==0) return '';
778
-	if (strncmp("1970-01-01", $letexte,10)==0) return '';	// eviter le bug GMT-1
776
+	if (strncmp("0000-00-00", $letexte, 10) == 0) return '';
777
+	if (strncmp("0001-01-01", $letexte, 10) == 0) return '';
778
+	if (strncmp("1970-01-01", $letexte, 10) == 0) return ''; // eviter le bug GMT-1
779 779
 	return $letexte;
780 780
 }
781 781
 
782 782
 // http://doc.spip.org/@recup_heure
783
-function recup_heure($date){
783
+function recup_heure($date) {
784 784
 
785
-	static $d = array(0,0,0);
785
+	static $d = array(0, 0, 0);
786 786
 	if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) 
787 787
 		return $d;
788 788
 	
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
 function secondes($numdate) {
811 811
 	$date_array = recup_heure($numdate);
812 812
 	if ($date_array)
813
-		list($heures,$minutes,$secondes) = $date_array;
813
+		list($heures, $minutes, $secondes) = $date_array;
814 814
 	return $secondes;
815 815
 }
816 816
 
@@ -820,41 +820,41 @@  discard block
 block discarded – undo
820 820
 }
821 821
 
822 822
 // http://doc.spip.org/@recup_date
823
-function recup_date($numdate, $forcer_jour = true){
823
+function recup_date($numdate, $forcer_jour = true) {
824 824
 	if (!$numdate) return '';
825 825
 	$heures = $minutes = $secondes = 0;
826 826
 	if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) {
827 827
 		$jour = $regs[1];
828 828
 		$mois = $regs[2];
829 829
 		$annee = $regs[3];
830
-		if ($annee < 90){
830
+		if ($annee < 90) {
831 831
 			$annee = 2000 + $annee;
832
-		} elseif ($annee<100) {
833
-			$annee = 1900 + $annee ;
832
+		} elseif ($annee < 100) {
833
+			$annee = 1900 + $annee;
834 834
 		}
835 835
 		list($heures, $minutes, $secondes) = recup_heure($numdate);
836 836
 
837 837
 	}
838
-	elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#',$numdate, $regs)) {
838
+	elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) {
839 839
 		$annee = $regs[1];
840 840
 		$mois = $regs[2];
841 841
 		$jour = $regs[3];
842 842
 		list($heures, $minutes, $secondes) = recup_heure($numdate);
843 843
 	}
844
-	elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)){
844
+	elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) {
845 845
 		$annee = $regs[1];
846 846
 		$mois = $regs[2];
847
-		$jour ='';
847
+		$jour = '';
848 848
 		list($heures, $minutes, $secondes) = recup_heure($numdate);
849 849
 	}
850
-	elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)){
850
+	elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) {
851 851
 		$annee = $regs[1];
852 852
 		$mois = $regs[2];
853 853
 		$jour = $regs[3];
854 854
 		$heures = $regs[4];
855 855
 		$minutes = $regs[5];
856 856
 		$secondes = $regs[6];
857
-	} else $annee = $mois =  $jour =''; 
857
+	} else $annee = $mois = $jour = ''; 
858 858
 	if ($annee > 4000) $annee -= 9000;
859 859
 	if (substr($jour, 0, 1) == '0') $jour = substr($jour, 1);
860 860
 
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
 }
876 876
 
877 877
 // http://doc.spip.org/@date_relative
878
-function date_relative($date, $decalage_maxi=0,$ref_date=null) {
878
+function date_relative($date, $decalage_maxi = 0, $ref_date = null) {
879 879
 	
880 880
 	if (is_null($ref_date))
881 881
 		$ref_time = time();
@@ -883,7 +883,7 @@  discard block
 block discarded – undo
883 883
 		$ref_time = strtotime($ref_date);
884 884
 	
885 885
 	if (!$date) return;
886
-	$decal = date("U",$ref_time) - date("U", strtotime($date));
886
+	$decal = date("U", $ref_time) - date("U", strtotime($date));
887 887
 
888 888
 	if ($decalage_maxi AND ($decal > $decalage_maxi OR $decal < 0))
889 889
 		return '';
@@ -899,28 +899,28 @@  discard block
 block discarded – undo
899 899
 		return affdate_court($date);
900 900
 
901 901
 	if ($decal > 3600 * 24 * 30) {
902
-		$mois = floor ($decal / (3600 * 24 * 30));
902
+		$mois = floor($decal / (3600 * 24 * 30));
903 903
 		if ($mois < 2)
904 904
 			$delai = "$mois "._T("date_un_mois");
905 905
 		else
906 906
 			$delai = "$mois "._T("date_mois");
907 907
 	}
908 908
 	else if ($decal > 3600 * 24 * 7) {
909
-		$semaines = floor ($decal / (3600 * 24 * 7));
909
+		$semaines = floor($decal / (3600 * 24 * 7));
910 910
 		if ($semaines < 2)
911 911
 			$delai = "$semaines "._T("date_une_semaine");
912 912
 		else
913 913
 			$delai = "$semaines "._T("date_semaines");
914 914
 	}
915 915
 	else if ($decal > 3600 * 24) {
916
-		$jours = floor ($decal / (3600 * 24));
916
+		$jours = floor($decal / (3600 * 24));
917 917
 		if ($jours < 2)
918
-			return $il_y_a=="date_dans"?_T("date_demain"):_T("date_hier");
918
+			return $il_y_a == "date_dans" ?_T("date_demain") : _T("date_hier");
919 919
 		else
920 920
 			$delai = "$jours "._T("date_jours");
921 921
 	}
922 922
 	else if ($decal >= 3600) {
923
-		$heures = floor ($decal / 3600);
923
+		$heures = floor($decal / 3600);
924 924
 		if ($heures < 2)
925 925
 			$delai = "$heures "._T("date_une_heure");
926 926
 		else
@@ -945,24 +945,24 @@  discard block
 block discarded – undo
945 945
 
946 946
 
947 947
 // http://doc.spip.org/@date_relativecourt
948
-function date_relativecourt($date, $decalage_maxi=0) {
948
+function date_relativecourt($date, $decalage_maxi = 0) {
949 949
 	
950 950
 	if (!$date) return;
951
-	$decal = date("U",strtotime(date('Y-m-d'))-strtotime(date('Y-m-d',strtotime($date))));
951
+	$decal = date("U", strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date))));
952 952
 
953 953
 	if ($decalage_maxi AND ($decal > $decalage_maxi OR $decal < 0))
954 954
 		return '';
955 955
 
956
-	if ($decal < -24*3600) {
956
+	if ($decal < -24 * 3600) {
957 957
 		$retour = date_relative($date, $decalage_maxi);
958 958
 	}
959 959
 	elseif ($decal < 0) {
960 960
 		$retour = _T("date_demain");
961 961
 	}
962
-	else if ($decal < (3600 * 24) ) {
962
+	else if ($decal < (3600 * 24)) {
963 963
 		$retour = _T("date_aujourdhui");
964 964
 	}
965
-	else if ($decal < (3600 * 24 *2) ) {
965
+	else if ($decal < (3600 * 24 * 2)) {
966 966
 		$retour = _T("date_hier");
967 967
 	}
968 968
 	else {
@@ -990,7 +990,7 @@  discard block
 block discarded – undo
990 990
 		$options = array('param'=>$options);
991 991
 	$date_array = recup_date($numdate, false);
992 992
 	if (!$date_array) return;
993
-	list($annee, $mois, $jour, $heures, $minutes, $secondes)= $date_array;
993
+	list($annee, $mois, $jour, $heures, $minutes, $secondes) = $date_array;
994 994
 
995 995
 	// 1er, 21st, etc.
996 996
 	$journum = $jour;
@@ -1022,38 +1022,38 @@  discard block
 block discarded – undo
1022 1022
 	case 'saison':
1023 1023
 	case 'saison_annee':
1024 1024
 		$saison = '';
1025
-		if ($mois > 0){
1025
+		if ($mois > 0) {
1026 1026
 			$saison = 1;
1027 1027
 			if (($mois == 3 AND $jour >= 21) OR $mois > 3) $saison = 2;
1028 1028
 			if (($mois == 6 AND $jour >= 21) OR $mois > 6) $saison = 3;
1029 1029
 			if (($mois == 9 AND $jour >= 21) OR $mois > 9) $saison = 4;
1030 1030
 			if (($mois == 12 AND $jour >= 21) OR $mois > 12) $saison = 1;
1031 1031
 		}
1032
-		if($vue == 'saison')
1033
-			return $saison?_T('date_saison_'.$saison):'';
1032
+		if ($vue == 'saison')
1033
+			return $saison ?_T('date_saison_'.$saison) : '';
1034 1034
 		else
1035
-			return $saison?trim(_T('date_fmt_saison_annee', array('saison'=>_T('date_saison_'.$saison), 'annee'=>$annee))) :'';
1035
+			return $saison ?trim(_T('date_fmt_saison_annee', array('saison'=>_T('date_saison_'.$saison), 'annee'=>$annee))) : '';
1036 1036
 
1037 1037
 	case 'court':
1038 1038
 		if ($avjc) return $annee;
1039
-		$a = ((isset($options['annee_courante']) AND $options['annee_courante'])?$options['annee_courante']:date('Y'));
1039
+		$a = ((isset($options['annee_courante']) AND $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
1040 1040
 		if ($annee < ($a - 100) OR $annee > ($a + 100)) return $annee;
1041
-		if ($annee != $a) return _T('date_fmt_mois_annee', array ('mois'=>$mois, 'nommois'=>spip_ucfirst($nommois), 'annee'=>$annee));
1042
-		return _T('date_fmt_jour_mois', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1041
+		if ($annee != $a) return _T('date_fmt_mois_annee', array('mois'=>$mois, 'nommois'=>spip_ucfirst($nommois), 'annee'=>$annee));
1042
+		return _T('date_fmt_jour_mois', array('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1043 1043
 
1044 1044
 	case 'jourcourt':
1045 1045
 		if ($avjc) return $annee;
1046
-		$a = ((isset($options['annee_courante']) AND $options['annee_courante'])?$options['annee_courante']:date('Y'));
1046
+		$a = ((isset($options['annee_courante']) AND $options['annee_courante']) ? $options['annee_courante'] : date('Y'));
1047 1047
 		if ($annee < ($a - 100) OR $annee > ($a + 100)) return $annee;
1048
-		if ($annee != $a) return _T('date_fmt_jour_mois_annee', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1049
-		return _T('date_fmt_jour_mois', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1048
+		if ($annee != $a) return _T('date_fmt_jour_mois_annee', array('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1049
+		return _T('date_fmt_jour_mois', array('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1050 1050
 
1051 1051
 	case 'entier':
1052 1052
 		if ($avjc) return $annee;
1053 1053
 		if ($jour)
1054
-			return _T('date_fmt_jour_mois_annee', array ('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1054
+			return _T('date_fmt_jour_mois_annee', array('jourmois'=>$jourmois, 'jour'=>$jour, 'mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee));
1055 1055
 		elseif ($mois)
1056
-			return trim(_T('date_fmt_mois_annee', array ('mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)));
1056
+			return trim(_T('date_fmt_mois_annee', array('mois'=>$mois, 'nommois'=>$nommois, 'annee'=>$annee)));
1057 1057
 		else
1058 1058
 			return $annee;
1059 1059
 
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
 		return $nommois;
1066 1066
 
1067 1067
 	case 'mois':
1068
-		return sprintf("%02s",$mois);
1068
+		return sprintf("%02s", $mois);
1069 1069
 
1070 1070
 	case 'jour':
1071 1071
 		return $jour;
@@ -1076,8 +1076,8 @@  discard block
 block discarded – undo
1076 1076
 	case 'nom_jour':
1077 1077
 		if (!$mois OR !$njour)
1078 1078
 			return '';
1079
-		$nom = mktime(1,1,1,$mois,$njour,$annee);
1080
-		$nom = 1+date('w',$nom);
1079
+		$nom = mktime(1, 1, 1, $mois, $njour, $annee);
1080
+		$nom = 1 + date('w', $nom);
1081 1081
 		$param = ((isset($options['param']) AND $options['param']) ? '_'.$options['param'] : '');
1082 1082
 		return _T('date_jour_'.$nom.$param);
1083 1083
 
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
 
1098 1098
 // http://doc.spip.org/@nom_jour
1099 1099
 function nom_jour($numdate, $forme = '') {
1100
-	if(!($forme == 'abbr' OR $forme == 'initiale')) $forme = '';
1100
+	if (!($forme == 'abbr' OR $forme == 'initiale')) $forme = '';
1101 1101
 	return affdate_base($numdate, 'nom_jour', $forme);
1102 1102
 }
1103 1103
 
@@ -1117,8 +1117,8 @@  discard block
 block discarded – undo
1117 1117
 }
1118 1118
 
1119 1119
 // http://doc.spip.org/@nom_mois
1120
-function nom_mois($numdate, $forme='') {
1121
-	if(!($forme == 'abbr')) $forme = '';
1120
+function nom_mois($numdate, $forme = '') {
1121
+	if (!($forme == 'abbr')) $forme = '';
1122 1122
 	return affdate_base($numdate, 'nom_mois', $forme);
1123 1123
 }
1124 1124
 
@@ -1138,17 +1138,17 @@  discard block
 block discarded – undo
1138 1138
 }
1139 1139
 
1140 1140
 // http://doc.spip.org/@affdate
1141
-function affdate($numdate, $format='entier') {
1141
+function affdate($numdate, $format = 'entier') {
1142 1142
 	return affdate_base($numdate, $format);
1143 1143
 }
1144 1144
 
1145 1145
 // http://doc.spip.org/@affdate_court
1146
-function affdate_court($numdate, $annee_courante=null) {
1146
+function affdate_court($numdate, $annee_courante = null) {
1147 1147
 	return affdate_base($numdate, 'court', array('annee_courante'=>$annee_courante));
1148 1148
 }
1149 1149
 
1150 1150
 // http://doc.spip.org/@affdate_jourcourt
1151
-function affdate_jourcourt($numdate, $annee_courante=null) {
1151
+function affdate_jourcourt($numdate, $annee_courante = null) {
1152 1152
 	return affdate_base($numdate, 'jourcourt', array('annee_courante'=>$annee_courante));
1153 1153
 }
1154 1154
 
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
 function affdate_heure($numdate) {
1162 1162
 	$date_array = recup_date($numdate);
1163 1163
 	if (!$date_array) return;
1164
-	list($annee, $mois, $jour, $heures, $minutes, $sec)= $date_array;
1164
+	list($annee, $mois, $jour, $heures, $minutes, $sec) = $date_array;
1165 1165
 	return _T('date_fmt_jour_heure', array('jour' => affdate($numdate), 'heure' =>  _T('date_fmt_heures_minutes', array('h'=> $heures, 'm'=> $minutes))));
1166 1166
 }
1167 1167
 
@@ -1189,15 +1189,15 @@  discard block
 block discarded – undo
1189 1189
  *   hcal pour avoir un markup microformat abbr
1190 1190
  * @return string
1191 1191
  */
1192
-function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme=''){
1192
+function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = '') {
1193 1193
 	$abbr = $jour = '';
1194 1194
 	$affdate = "affdate_jourcourt";
1195
-	if (strpos($forme,'abbr') !==false) $abbr = 'abbr';
1196
-	if (strpos($forme,'annee')!==false) $affdate = 'affdate';
1197
-	if (strpos($forme,'jour') !==false) $jour = 'jour';
1195
+	if (strpos($forme, 'abbr') !== false) $abbr = 'abbr';
1196
+	if (strpos($forme, 'annee') !== false) $affdate = 'affdate';
1197
+	if (strpos($forme, 'jour') !== false) $jour = 'jour';
1198 1198
 	
1199 1199
 	$dtstart = $dtend = $dtabbr = "";
1200
-	if (strpos($forme,'hcal')!==false) {
1200
+	if (strpos($forme, 'hcal') !== false) {
1201 1201
 		$dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>";
1202 1202
 		$dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>";
1203 1203
 		$dtabbr = "</abbr>";
@@ -1207,74 +1207,74 @@  discard block
 block discarded – undo
1207 1207
 	$date_fin = strtotime($date_fin);
1208 1208
 	$d = date("Y-m-d", $date_debut);
1209 1209
 	$f = date("Y-m-d", $date_fin);
1210
-	$h = ($horaire==='oui' OR $horaire===true);
1211
-	$hd = _T('date_fmt_heures_minutes_court', array('h'=> date("H",$date_debut), 'm'=> date("i",$date_debut)));
1212
-	$hf = _T('date_fmt_heures_minutes_court', array('h'=> date("H",$date_fin), 'm'=> date("i",$date_fin)));
1210
+	$h = ($horaire === 'oui' OR $horaire === true);
1211
+	$hd = _T('date_fmt_heures_minutes_court', array('h'=> date("H", $date_debut), 'm'=> date("i", $date_debut)));
1212
+	$hf = _T('date_fmt_heures_minutes_court', array('h'=> date("H", $date_fin), 'm'=> date("i", $date_fin)));
1213 1213
 
1214
-	if ($d==$f)
1214
+	if ($d == $f)
1215 1215
 	{ // meme jour
1216
-		$nomjour = nom_jour($d,$abbr);
1216
+		$nomjour = nom_jour($d, $abbr);
1217 1217
 		$s = $affdate($d);
1218
-		$s = _T('date_fmt_jour',array('nomjour'=>$nomjour,'jour' => $s));
1219
-		if ($h){
1220
-			if ($hd==$hf){
1218
+		$s = _T('date_fmt_jour', array('nomjour'=>$nomjour, 'jour' => $s));
1219
+		if ($h) {
1220
+			if ($hd == $hf) {
1221 1221
 				// Lundi 20 fevrier a 18h25
1222
-				$s = spip_ucfirst(_T('date_fmt_jour_heure',array('jour'=>$s,'heure'=>$hd)));
1222
+				$s = spip_ucfirst(_T('date_fmt_jour_heure', array('jour'=>$s, 'heure'=>$hd)));
1223 1223
 				$s = "$dtstart$s$dtabbr";
1224
-			}else{
1224
+			} else {
1225 1225
 				// Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr>
1226
-				if($dtabbr && $dtstart && $dtend)
1227
-					$s = _T('date_fmt_jour_heure_debut_fin_abbr',array('jour'=>spip_ucfirst($s),'heure_debut'=>$hd,'heure_fin'=>$hf,'dtstart'=>$dtstart,'dtend'=>$dtend,'dtabbr'=>$dtabbr));
1226
+				if ($dtabbr && $dtstart && $dtend)
1227
+					$s = _T('date_fmt_jour_heure_debut_fin_abbr', array('jour'=>spip_ucfirst($s), 'heure_debut'=>$hd, 'heure_fin'=>$hf, 'dtstart'=>$dtstart, 'dtend'=>$dtend, 'dtabbr'=>$dtabbr));
1228 1228
 				// Le lundi 20 fevrier de 18h00 a 20h00
1229 1229
 				else
1230
-					$s = spip_ucfirst(_T('date_fmt_jour_heure_debut_fin',array('jour'=>$s,'heure_debut'=>$hd,'heure_fin'=>$hf)));
1230
+					$s = spip_ucfirst(_T('date_fmt_jour_heure_debut_fin', array('jour'=>$s, 'heure_debut'=>$hd, 'heure_fin'=>$hf)));
1231 1231
 			}
1232
-		}else{
1233
-			if($dtabbr && $dtstart)
1232
+		} else {
1233
+			if ($dtabbr && $dtstart)
1234 1234
 				$s = $dtstart.spip_ucfirst($s).$dtabbr;
1235 1235
 			else
1236 1236
 				$s = spip_ucfirst($s);
1237 1237
 		}
1238 1238
 	}
1239
-	else if ((date("Y-m",$date_debut))==date("Y-m",$date_fin))
1239
+	else if ((date("Y-m", $date_debut)) == date("Y-m", $date_fin))
1240 1240
 	{ // meme annee et mois, jours differents
1241
-		if(!$h)
1241
+		if (!$h)
1242 1242
 			$date_debut = jour($d);
1243 1243
 		else
1244
-			$date_debut = affdate_jourcourt($d,date("Y",$date_fin));
1244
+			$date_debut = affdate_jourcourt($d, date("Y", $date_fin));
1245 1245
 		$date_fin = $affdate($f);
1246
-		if($jour){
1247
-			$nomjour_debut = nom_jour($d,$abbr);
1248
-			$date_debut = _T('date_fmt_jour',array('nomjour'=>$nomjour_debut,'jour' => $date_debut));
1249
-			$nomjour_fin = nom_jour($f,$abbr);
1250
-			$date_fin = _T('date_fmt_jour',array('nomjour'=>$nomjour_fin,'jour' => $date_fin));
1246
+		if ($jour) {
1247
+			$nomjour_debut = nom_jour($d, $abbr);
1248
+			$date_debut = _T('date_fmt_jour', array('nomjour'=>$nomjour_debut, 'jour' => $date_debut));
1249
+			$nomjour_fin = nom_jour($f, $abbr);
1250
+			$date_fin = _T('date_fmt_jour', array('nomjour'=>$nomjour_fin, 'jour' => $date_fin));
1251 1251
 		}
1252
-		if ($h){
1253
-			$date_debut = _T('date_fmt_jour_heure',array('jour'=>$date_debut,'heure'=>$hd));
1254
-			$date_fin = _T('date_fmt_jour_heure',array('jour'=>$date_fin,'heure'=>$hf));
1252
+		if ($h) {
1253
+			$date_debut = _T('date_fmt_jour_heure', array('jour'=>$date_debut, 'heure'=>$hd));
1254
+			$date_fin = _T('date_fmt_jour_heure', array('jour'=>$date_fin, 'heure'=>$hf));
1255 1255
 		}
1256 1256
 		$date_debut = $dtstart.$date_debut.$dtabbr;
1257 1257
 		$date_fin = $dtend.$date_fin.$dtabbr;
1258 1258
 		
1259
-		$s = _T('date_fmt_periode',array('date_debut' => $date_debut,'date_fin'=>$date_fin));
1259
+		$s = _T('date_fmt_periode', array('date_debut' => $date_debut, 'date_fin'=>$date_fin));
1260 1260
 	}
1261 1261
 	else {
1262
-		$date_debut = affdate_jourcourt($d,date("Y",$date_fin));
1262
+		$date_debut = affdate_jourcourt($d, date("Y", $date_fin));
1263 1263
 		$date_fin = $affdate($f);
1264
-		if($jour){
1265
-			$nomjour_debut = nom_jour($d,$abbr);
1266
-			$date_debut = _T('date_fmt_jour',array('nomjour'=>$nomjour_debut,'jour' => $date_debut));
1267
-			$nomjour_fin = nom_jour($f,$abbr);
1268
-			$date_fin = _T('date_fmt_jour',array('nomjour'=>$nomjour_fin,'jour' => $date_fin));
1264
+		if ($jour) {
1265
+			$nomjour_debut = nom_jour($d, $abbr);
1266
+			$date_debut = _T('date_fmt_jour', array('nomjour'=>$nomjour_debut, 'jour' => $date_debut));
1267
+			$nomjour_fin = nom_jour($f, $abbr);
1268
+			$date_fin = _T('date_fmt_jour', array('nomjour'=>$nomjour_fin, 'jour' => $date_fin));
1269 1269
 		}
1270
-		if ($h){
1271
-			$date_debut = _T('date_fmt_jour_heure',array('jour'=>$date_debut,'heure'=>$hd)); 
1272
-			$date_fin = _T('date_fmt_jour_heure',array('jour'=>$date_fin,'heure'=>$hf));
1270
+		if ($h) {
1271
+			$date_debut = _T('date_fmt_jour_heure', array('jour'=>$date_debut, 'heure'=>$hd)); 
1272
+			$date_fin = _T('date_fmt_jour_heure', array('jour'=>$date_fin, 'heure'=>$hf));
1273 1273
 		}
1274 1274
 		
1275 1275
 		$date_debut = $dtstart.$date_debut.$dtabbr;
1276
-		$date_fin=$dtend.$date_fin.$dtabbr;
1277
-		$s = _T('date_fmt_periode',array('date_debut' => $date_debut,'date_fin'=>$date_fin));
1276
+		$date_fin = $dtend.$date_fin.$dtabbr;
1277
+		$s = _T('date_fmt_periode', array('date_debut' => $date_debut, 'date_fin'=>$date_fin));
1278 1278
 		
1279 1279
 	}
1280 1280
 	return $s;
@@ -1290,7 +1290,7 @@  discard block
 block discarded – undo
1290 1290
  * @param string $justif
1291 1291
  * @return string
1292 1292
  */
1293
-function aligner($letexte, $justif='') {
1293
+function aligner($letexte, $justif = '') {
1294 1294
 	$letexte = trim($letexte);
1295 1295
 	if (!strlen($letexte)) return '';
1296 1296
 
@@ -1302,13 +1302,13 @@  discard block
 block discarded – undo
1302 1302
 	return $letexte;
1303 1303
 }
1304 1304
 // http://doc.spip.org/@justifier
1305
-function justifier($letexte) { return aligner($letexte,'justify');}
1305
+function justifier($letexte) { return aligner($letexte, 'justify'); }
1306 1306
 // http://doc.spip.org/@aligner_droite
1307
-function aligner_droite($letexte) { return aligner($letexte,'right');}
1307
+function aligner_droite($letexte) { return aligner($letexte, 'right'); }
1308 1308
 // http://doc.spip.org/@aligner_gauche
1309
-function aligner_gauche($letexte) {return aligner($letexte,'left');}
1309
+function aligner_gauche($letexte) {return aligner($letexte, 'left'); }
1310 1310
 // http://doc.spip.org/@centrer
1311
-function centrer($letexte) {return aligner($letexte,'center');}
1311
+function centrer($letexte) {return aligner($letexte, 'center'); }
1312 1312
 
1313 1313
 // http://doc.spip.org/@style_align
1314 1314
 function style_align($bof) {
@@ -1360,31 +1360,31 @@  discard block
 block discarded – undo
1360 1360
 }
1361 1361
 
1362 1362
 // http://doc.spip.org/@date_anneemoisjour
1363
-function date_anneemoisjour($d)  {
1363
+function date_anneemoisjour($d) {
1364 1364
 	if (!$d) $d = date("Y-m-d");
1365
-	return  substr($d, 0, 4) . substr($d, 5, 2) .substr($d, 8, 2);
1365
+	return  substr($d, 0, 4).substr($d, 5, 2).substr($d, 8, 2);
1366 1366
 }
1367 1367
 
1368 1368
 // http://doc.spip.org/@date_anneemois
1369
-function date_anneemois($d)  {
1369
+function date_anneemois($d) {
1370 1370
 	if (!$d) $d = date("Y-m-d");
1371
-	return  substr($d, 0, 4) . substr($d, 5, 2);
1371
+	return  substr($d, 0, 4).substr($d, 5, 2);
1372 1372
 }
1373 1373
 
1374 1374
 // http://doc.spip.org/@date_debut_semaine
1375 1375
 function date_debut_semaine($annee, $mois, $jour) {
1376
-  $w_day = date("w", mktime(0,0,0,$mois, $jour, $annee));
1376
+  $w_day = date("w", mktime(0, 0, 0, $mois, $jour, $annee));
1377 1377
   if ($w_day == 0) $w_day = 7; // Gaffe: le dimanche est zero
1378
-  $debut = $jour-$w_day+1;
1379
-  return date("Ymd", mktime(0,0,0,$mois,$debut,$annee));
1378
+  $debut = $jour - $w_day + 1;
1379
+  return date("Ymd", mktime(0, 0, 0, $mois, $debut, $annee));
1380 1380
 }
1381 1381
 
1382 1382
 // http://doc.spip.org/@date_fin_semaine
1383 1383
 function date_fin_semaine($annee, $mois, $jour) {
1384
-  $w_day = date("w", mktime(0,0,0,$mois, $jour, $annee));
1384
+  $w_day = date("w", mktime(0, 0, 0, $mois, $jour, $annee));
1385 1385
   if ($w_day == 0) $w_day = 7; // Gaffe: le dimanche est zero
1386
-  $debut = $jour-$w_day+1;
1387
-  return date("Ymd", mktime(0,0,0,$mois,$debut+6,$annee));
1386
+  $debut = $jour - $w_day + 1;
1387
+  return date("Ymd", mktime(0, 0, 0, $mois, $debut + 6, $annee));
1388 1388
 }
1389 1389
 
1390 1390
 
@@ -1400,7 +1400,7 @@  discard block
 block discarded – undo
1400 1400
 
1401 1401
 // postautobr : transforme les sauts de ligne en _
1402 1402
 // http://doc.spip.org/@post_autobr
1403
-function post_autobr($texte, $delim="\n_ ") {
1403
+function post_autobr($texte, $delim = "\n_ ") {
1404 1404
 	if (!function_exists('echappe_html'))
1405 1405
 		include_spip('inc/texte_mini');
1406 1406
 	$texte = str_replace("\r\n", "\r", $texte);
@@ -1414,9 +1414,9 @@  discard block
 block discarded – undo
1414 1414
 	$texte = echappe_html($texte, '', true);
1415 1415
 
1416 1416
 	// echapper les modeles
1417
-	if (strpos($texte,"<")!==false){
1417
+	if (strpos($texte, "<") !== false) {
1418 1418
 		include_spip('inc/lien');
1419
-		if (defined('_PREG_MODELE')){
1419
+		if (defined('_PREG_MODELE')) {
1420 1420
 			$preg_modeles = "@"._PREG_MODELE."@imsS";
1421 1421
 			$texte = echappe_html($texte, '', true, $preg_modeles);
1422 1422
 		}
@@ -1425,17 +1425,17 @@  discard block
 block discarded – undo
1425 1425
 	$debut = '';
1426 1426
 	$suite = $texte;
1427 1427
 	while ($t = strpos('-'.$suite, "\n", 1)) {
1428
-		$debut .= substr($suite, 0, $t-1);
1428
+		$debut .= substr($suite, 0, $t - 1);
1429 1429
 		$suite = substr($suite, $t);
1430 1430
 		$car = substr($suite, 0, 1);
1431
-		if (($car<>'-') AND ($car<>'_') AND ($car<>"\n") AND ($car<>"|") AND ($car<>"}")
1432
-		AND !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S',($suite))
1431
+		if (($car <> '-') AND ($car <> '_') AND ($car <> "\n") AND ($car <> "|") AND ($car <> "}")
1432
+		AND !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1433 1433
 		AND !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)) {
1434 1434
 			$debut .= $delim;
1435 1435
 		} else
1436 1436
 			$debut .= "\n";
1437 1437
 		if (preg_match(",^\n+,", $suite, $regs)) {
1438
-			$debut.=$regs[0];
1438
+			$debut .= $regs[0];
1439 1439
 			$suite = substr($suite, strlen($regs[0]));
1440 1440
 		}
1441 1441
 	}
@@ -1451,7 +1451,7 @@  discard block
 block discarded – undo
1451 1451
 // Extraire et transformer les blocs multi ; on indique la langue courante
1452 1452
 // pour ne pas mettre de span@lang=fr si on est deja en fr
1453 1453
 // http://doc.spip.org/@extraire_multi
1454
-function extraire_multi($letexte, $lang=null, $echappe_span=false) {
1454
+function extraire_multi($letexte, $lang = null, $echappe_span = false) {
1455 1455
 	if (preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)) {
1456 1456
 		if (!$lang) $lang = $GLOBALS['spip_lang'];
1457 1457
 
@@ -1472,7 +1472,7 @@  discard block
 block discarded – undo
1472 1472
 				include_spip('inc/texte');
1473 1473
 				// Tester si on echappe en span ou en div
1474 1474
 				// il ne faut pas echapper en div si propre produit un seul paragraphe
1475
-				$trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims","",propre($trad));
1475
+				$trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1476 1476
 				$mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1477 1477
 				$trad = code_echappement($trad, 'multi', false, $mode);
1478 1478
 				$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
@@ -1507,8 +1507,8 @@  discard block
 block discarded – undo
1507 1507
 }
1508 1508
 
1509 1509
 // Calculer l'initiale d'un nom
1510
-function initiale($nom){
1511
-	return spip_substr(trim(strtoupper(extraire_multi($nom))),0,1);
1510
+function initiale($nom) {
1511
+	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1512 1512
 }
1513 1513
 
1514 1514
 //
@@ -1521,15 +1521,15 @@  discard block
 block discarded – undo
1521 1521
 //
1522 1522
 // http://www.spip.net/@unique
1523 1523
 // http://doc.spip.org/@unique
1524
-function unique($donnee, $famille='', $cpt = false) {
1524
+function unique($donnee, $famille = '', $cpt = false) {
1525 1525
 	static $mem = array();
1526 1526
 	// permettre de vider la pile et de la restaurer
1527 1527
 	// pour le calcul de introduction...
1528
-	if ($famille=='_spip_raz_'){
1528
+	if ($famille == '_spip_raz_') {
1529 1529
 		$tmp = $mem;
1530 1530
 		$mem = array();
1531 1531
 		return $tmp;
1532
-	} elseif ($famille=='_spip_set_'){
1532
+	} elseif ($famille == '_spip_set_') {
1533 1533
 		$mem = $donnee;
1534 1534
 		return;
1535 1535
 	}
@@ -1560,14 +1560,14 @@  discard block
 block discarded – undo
1560 1560
 	$num = func_num_args();
1561 1561
 	$args = func_get_args();
1562 1562
 
1563
-	if($num == 2 && is_array($args[1])) {
1563
+	if ($num == 2 && is_array($args[1])) {
1564 1564
     $args = $args[1];
1565
-    array_unshift($args,'');
1565
+    array_unshift($args, '');
1566 1566
     $num = count($args);
1567 1567
   }
1568 1568
 
1569 1569
 	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1570
-	return $args[(intval($i)-1)%($num-1)+1];
1570
+	return $args[(intval($i) - 1) % ($num - 1) + 1];
1571 1571
 }
1572 1572
 
1573 1573
 // recuperer un attribut d'une balise html
@@ -1594,15 +1594,15 @@  discard block
 block discarded – undo
1594 1594
 		if ($r[3][0] == '"' || $r[3][0] == "'") {
1595 1595
 			$r[4] = substr($r[3], 1, -1);
1596 1596
 			$r[3] = $r[3][0];
1597
-		} elseif ($r[3]!=='') {
1597
+		} elseif ($r[3] !== '') {
1598 1598
 			$r[4] = $r[3]; 
1599 1599
 			$r[3] = '';
1600 1600
 		} else {
1601 1601
 			$r[4] = trim($r[2]); 
1602 1602
 		}
1603 1603
 		$att = $r[4];
1604
-		if (strpos($att,"&#")!==false)
1605
-			$att = str_replace(array("&#039;","&#39;","&#034;","&#34;"), array("'","'",'"','"'), $att);
1604
+		if (strpos($att, "&#") !== false)
1605
+			$att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1606 1606
 		$att = filtrer_entites($att);
1607 1607
 	}
1608 1608
 	else
@@ -1626,15 +1626,15 @@  discard block
 block discarded – undo
1626 1626
  * @param bool $vider
1627 1627
  * @return string
1628 1628
  */
1629
-function inserer_attribut($balise, $attribut, $val, $proteger=true, $vider=false) {
1629
+function inserer_attribut($balise, $attribut, $val, $proteger = true, $vider = false) {
1630 1630
 	// preparer l'attribut
1631 1631
 	// supprimer les &nbsp; etc mais pas les balises html
1632 1632
 	// qui ont un sens dans un attribut value d'un input
1633
-	if ($proteger) $val = attribut_html($val,false);
1633
+	if ($proteger) $val = attribut_html($val, false);
1634 1634
 
1635 1635
 	// echapper les ' pour eviter tout bug
1636 1636
 	$val = str_replace("'", "&#039;", $val);
1637
-	if ($vider AND strlen($val)==0)
1637
+	if ($vider AND strlen($val) == 0)
1638 1638
 		$insert = '';
1639 1639
 	else
1640 1640
 		$insert = " $attribut='$val'";
@@ -1658,7 +1658,7 @@  discard block
 block discarded – undo
1658 1658
 }
1659 1659
 
1660 1660
 // http://doc.spip.org/@vider_attribut
1661
-function vider_attribut ($balise, $attribut) {
1661
+function vider_attribut($balise, $attribut) {
1662 1662
 	return inserer_attribut($balise, $attribut, '', false, true);
1663 1663
 }
1664 1664
 
@@ -1670,7 +1670,7 @@  discard block
 block discarded – undo
1670 1670
  * @param string $mode
1671 1671
  * @return string
1672 1672
  */
1673
-function tester_config($id, $mode='') {
1673
+function tester_config($id, $mode = '') {
1674 1674
 	include_spip('action/inscrire_auteur');
1675 1675
 	return tester_statut_inscription($mode, $id);
1676 1676
 }
@@ -1679,24 +1679,24 @@  discard block
 block discarded – undo
1679 1679
 // Quelques fonctions de calcul arithmetique
1680 1680
 //
1681 1681
 // http://doc.spip.org/@plus
1682
-function plus($a,$b) {
1683
-	return $a+$b;
1682
+function plus($a, $b) {
1683
+	return $a + $b;
1684 1684
 }
1685 1685
 // http://doc.spip.org/@moins
1686
-function moins($a,$b) {
1687
-	return $a-$b;
1686
+function moins($a, $b) {
1687
+	return $a - $b;
1688 1688
 }
1689 1689
 // http://doc.spip.org/@mult
1690
-function mult($a,$b) {
1691
-	return $a*$b;
1690
+function mult($a, $b) {
1691
+	return $a * $b;
1692 1692
 }
1693 1693
 // http://doc.spip.org/@div
1694
-function div($a,$b) {
1695
-	return $b?$a/$b:0;
1694
+function div($a, $b) {
1695
+	return $b ? $a / $b : 0;
1696 1696
 }
1697 1697
 // http://doc.spip.org/@modulo
1698
-function modulo($nb, $mod, $add=0) {
1699
-	return ($mod?$nb%$mod:0)+$add;
1698
+function modulo($nb, $mod, $add = 0) {
1699
+	return ($mod ? $nb % $mod : 0) + $add;
1700 1700
 }
1701 1701
 
1702 1702
 
@@ -1714,9 +1714,9 @@  discard block
 block discarded – undo
1714 1714
 	if (!is_string($nom)) {
1715 1715
 		return false;
1716 1716
 	}
1717
-	if (!defined('_TAGS_NOM_AUTEUR')) define('_TAGS_NOM_AUTEUR','');
1718
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
1719
-	foreach($tags_acceptes as $tag) {
1717
+	if (!defined('_TAGS_NOM_AUTEUR')) define('_TAGS_NOM_AUTEUR', '');
1718
+	$tags_acceptes = array_unique(explode(',', 'multi,'._TAGS_NOM_AUTEUR));
1719
+	foreach ($tags_acceptes as $tag) {
1720 1720
 		if (strlen($tag)) {
1721 1721
 			$remp1[] = '<'.trim($tag).'>';
1722 1722
 			$remp1[] = '</'.trim($tag).'>';
@@ -1769,7 +1769,7 @@  discard block
 block discarded – undo
1769 1769
 	return join('&nbsp;', $s);
1770 1770
 }
1771 1771
 // http://doc.spip.org/@afficher_tags
1772
-function afficher_tags($tags, $rels='tag,directory') {
1772
+function afficher_tags($tags, $rels = 'tag,directory') {
1773 1773
 	$s = array();
1774 1774
 	foreach (extraire_balises($tags, 'a') as $tag) {
1775 1775
 		$rel = extraire_attribut($tag, 'rel');
@@ -1793,9 +1793,9 @@  discard block
 block discarded – undo
1793 1793
 	}
1794 1794
 	$fichier = basename($url);
1795 1795
 	return '<a rel="enclosure"'
1796
-		. ($url? ' href="'.spip_htmlspecialchars($url).'"' : '')
1797
-		. ($type? ' type="'.spip_htmlspecialchars($type).'"' : '')
1798
-		. ($length? ' title="'.spip_htmlspecialchars($length).'"' : '')
1796
+		. ($url ? ' href="'.spip_htmlspecialchars($url).'"' : '')
1797
+		. ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '')
1798
+		. ($length ? ' title="'.spip_htmlspecialchars($length).'"' : '')
1799 1799
 		. '>'.$fichier.'</a>';
1800 1800
 }
1801 1801
 // La fonction inverse
@@ -1810,9 +1810,9 @@  discard block
 block discarded – undo
1810 1810
 			$length = intval(extraire_attribut($e, 'length')); # vieux data
1811 1811
 		$fichier = basename($url);
1812 1812
 		$enclosures[] = '<enclosure'
1813
-			. ($url? ' url="'.spip_htmlspecialchars($url).'"' : '')
1814
-			. ($type? ' type="'.spip_htmlspecialchars($type).'"' : '')
1815
-			. ($length? ' length="'.$length.'"' : '')
1813
+			. ($url ? ' url="'.spip_htmlspecialchars($url).'"' : '')
1814
+			. ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '')
1815
+			. ($length ? ' length="'.$length.'"' : '')
1816 1816
 			. ' />';
1817 1817
 	}
1818 1818
 	return join("\n", $enclosures);
@@ -1835,7 +1835,7 @@  discard block
 block discarded – undo
1835 1835
 // ex: [(#DESCRIPTIF|extraire_balise{img})]
1836 1836
 // Si on a passe un tableau de textes, renvoyer un tableau de resultats
1837 1837
 // http://doc.spip.org/@extraire_balise
1838
-function extraire_balise($texte, $tag='a') {
1838
+function extraire_balise($texte, $tag = 'a') {
1839 1839
 	if (is_array($texte)) {
1840 1840
 		array_walk($texte,
1841 1841
 			create_function('&$a,$key,$t', '$a = extraire_balise($a,$t);'),
@@ -1852,7 +1852,7 @@  discard block
 block discarded – undo
1852 1852
 // extraire toutes les balises du type demande, sous forme de tableau
1853 1853
 // Si on a passe un tableau de textes, renvoyer un tableau de resultats
1854 1854
 // http://doc.spip.org/@extraire_balises
1855
-function extraire_balises($texte, $tag='a') {
1855
+function extraire_balises($texte, $tag = 'a') {
1856 1856
 	if (is_array($texte)) {
1857 1857
 		array_walk($texte,
1858 1858
 			create_function('&$a,$key,$t', '$a = extraire_balises($a,$t);'),
@@ -1872,8 +1872,8 @@  discard block
 block discarded – undo
1872 1872
 // prend ' ' comme representant de vrai et '' de faux
1873 1873
 
1874 1874
 // http://doc.spip.org/@in_any
1875
-function in_any($val, $vals, $def='') {
1876
-	if (!is_array($vals) AND $v=unserialize($vals)) $vals = $v;
1875
+function in_any($val, $vals, $def = '') {
1876
+	if (!is_array($vals) AND $v = unserialize($vals)) $vals = $v;
1877 1877
   return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
1878 1878
 }
1879 1879
 
@@ -1888,9 +1888,9 @@  discard block
 block discarded – undo
1888 1888
 }
1889 1889
 
1890 1890
 // http://doc.spip.org/@regledetrois
1891
-function regledetrois($a,$b,$c)
1891
+function regledetrois($a, $b, $c)
1892 1892
 {
1893
-  return round($a*$b/$c);
1893
+  return round($a * $b / $c);
1894 1894
 }
1895 1895
 
1896 1896
 // Fournit la suite de Input-Hidden correspondant aux parametres de
@@ -1904,7 +1904,7 @@  discard block
 block discarded – undo
1904 1904
 	if ($p = urls_decoder_url($action, '')
1905 1905
 		AND reset($p)) {
1906 1906
 		$fond = array_shift($p);
1907
-		if ($fond!='404'){
1907
+		if ($fond != '404') {
1908 1908
 			$contexte = array_shift($p);
1909 1909
 			$contexte['page'] = $fond;
1910 1910
 			$action = preg_replace('/([?]'.preg_quote($fond).'[^&=]*[0-9]+)(&|$)/', '?&', $action);
@@ -1922,11 +1922,11 @@  discard block
 block discarded – undo
1922 1922
 
1923 1923
 	// d'abord avec celles de l'url
1924 1924
 	if (false !== ($p = strpos($action, '?'))) {
1925
-		foreach(preg_split('/&(amp;)?/S',substr($action,$p+1)) as $c){
1926
-			list($var,$val) = explode('=', $c, 2);
1925
+		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
1926
+			list($var, $val) = explode('=', $c, 2);
1927 1927
 			if ($var) {
1928
-				$val =  rawurldecode($val);
1929
-				$var =  rawurldecode($var); // decoder les [] eventuels
1928
+				$val = rawurldecode($val);
1929
+				$var = rawurldecode($var); // decoder les [] eventuels
1930 1930
 				if (preg_match(',\[\]$,S', $var))
1931 1931
 					$values[] = array($var, $val);
1932 1932
 				else if (!isset($values[$var]))
@@ -1936,7 +1936,7 @@  discard block
 block discarded – undo
1936 1936
 	}
1937 1937
 
1938 1938
 	// ensuite avec celles du contexte, sans doublonner !
1939
-	foreach($contexte as $var=>$val)
1939
+	foreach ($contexte as $var=>$val)
1940 1940
 		if (preg_match(',\[\]$,S', $var))
1941 1941
 			$values[] = array($var, $val);
1942 1942
 		else if (!isset($values[$var]))
@@ -1944,8 +1944,8 @@  discard block
 block discarded – undo
1944 1944
 
1945 1945
 	// puis on rassemble le tout
1946 1946
 	$hidden = array();
1947
-	foreach($values as $value) {
1948
-		list($var,$val) = $value;
1947
+	foreach ($values as $value) {
1948
+		list($var, $val) = $value;
1949 1949
 		$hidden[] = '<input name="'
1950 1950
 			. entites_html($var)
1951 1951
 			.'"'
@@ -1960,12 +1960,12 @@  discard block
 block discarded – undo
1960 1960
 
1961 1961
 // http://doc.spip.org/@filtre_bornes_pagination_dist
1962 1962
 function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) {
1963
-	if($max<=0 OR $max>=$nombre)
1963
+	if ($max <= 0 OR $max >= $nombre)
1964 1964
 		return array(1, $nombre);
1965 1965
 
1966
-	$premiere = max(1, $courante-floor(($max-1)/2));
1967
-	$derniere = min($nombre, $premiere+$max-2);
1968
-	$premiere = $derniere == $nombre ? $derniere-$max+1 : $premiere;
1966
+	$premiere = max(1, $courante - floor(($max - 1) / 2));
1967
+	$derniere = min($nombre, $premiere + $max - 2);
1968
+	$premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere;
1969 1969
 	return array($premiere, $derniere);
1970 1970
 }
1971 1971
 
@@ -1991,7 +1991,7 @@  discard block
 block discarded – undo
1991 1991
 
1992 1992
 // http://doc.spip.org/@filtre_push
1993 1993
 function filtre_push($array, $val) {
1994
-	if($array == '' OR !array_push($array, $val)) return '';
1994
+	if ($array == '' OR !array_push($array, $val)) return '';
1995 1995
 	return $array;
1996 1996
 }
1997 1997
 
@@ -2007,9 +2007,9 @@  discard block
 block discarded – undo
2007 2007
 //
2008 2008
 
2009 2009
 // http://doc.spip.org/@filtre_pagination_dist
2010
-function filtre_pagination_dist($total, $nom, $position, $pas, $liste = true, $modele='', $connect='', $env=array()) {
2010
+function filtre_pagination_dist($total, $nom, $position, $pas, $liste = true, $modele = '', $connect = '', $env = array()) {
2011 2011
 	static $ancres = array();
2012
-	if ($pas<1) return '';
2012
+	if ($pas < 1) return '';
2013 2013
 	$ancre = 'pagination'.$nom; // #pagination_articles
2014 2014
 	$debut = 'debut'.$nom; // 'debut_articles'
2015 2015
 
@@ -2023,20 +2023,20 @@  discard block
 block discarded – undo
2023 2023
 
2024 2024
 	$pagination = array(
2025 2025
 		'debut' => $debut,
2026
-		'url' => parametre_url(self(),'fragment',''), // nettoyer l'id ahah eventuel
2026
+		'url' => parametre_url(self(), 'fragment', ''), // nettoyer l'id ahah eventuel
2027 2027
 		'total' => $total,
2028 2028
 		'position' => intval($position),
2029 2029
 		'pas' => $pas,
2030
-		'nombre_pages' => floor(($total-1)/$pas)+1,
2031
-		'page_courante' => floor(intval($position)/$pas)+1,
2030
+		'nombre_pages' => floor(($total - 1) / $pas) + 1,
2031
+		'page_courante' => floor(intval($position) / $pas) + 1,
2032 2032
 		'ancre' => $ancre,
2033 2033
 		'bloc_ancre' => $bloc_ancre
2034 2034
 	);
2035 2035
 	if (is_array($env))
2036
-		$pagination = array_merge($env,$pagination);
2036
+		$pagination = array_merge($env, $pagination);
2037 2037
 
2038 2038
 	// Pas de pagination
2039
-	if ($pagination['nombre_pages']<=1)
2039
+	if ($pagination['nombre_pages'] <= 1)
2040 2040
 		return '';
2041 2041
 
2042 2042
 	if ($modele) $modele = '_'.$modele;
@@ -2047,7 +2047,7 @@  discard block
 block discarded – undo
2047 2047
 // passer les url relatives a la css d'origine en url absolues
2048 2048
 // http://doc.spip.org/@urls_absolues_css
2049 2049
 function urls_absolues_css($contenu, $source) {
2050
-	$path = suivre_lien(url_absolue($source),'./');
2050
+	$path = suivre_lien(url_absolue($source), './');
2051 2051
 
2052 2052
 	return preg_replace_callback(
2053 2053
 		",url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims",
@@ -2061,7 +2061,7 @@  discard block
 block discarded – undo
2061 2061
 // 2. sinon la cree (ou la recree) dans _DIR_VAR/cache_css/
2062 2062
 // SI on lui donne a manger une feuille nommee _rtl.css il va faire l'inverse
2063 2063
 // http://doc.spip.org/@direction_css
2064
-function direction_css ($css, $voulue='') {
2064
+function direction_css($css, $voulue = '') {
2065 2065
 	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) return $css;
2066 2066
 
2067 2067
 	// si on a precise le sens voulu en argument, le prendre en compte
@@ -2070,7 +2070,7 @@  discard block
 block discarded – undo
2070 2070
 			$voulue = lang_dir($voulue);
2071 2071
 	}
2072 2072
 	else
2073
-		$voulue =  lang_dir();
2073
+		$voulue = lang_dir();
2074 2074
 
2075 2075
 	$r = count($r) > 1;
2076 2076
 	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
@@ -2082,12 +2082,12 @@  discard block
 block discarded – undo
2082 2082
 
2083 2083
 	if (
2084 2084
 		// url absolue
2085
-		preg_match(",^http:,i",$css)
2085
+		preg_match(",^http:,i", $css)
2086 2086
 		// ou qui contient un ?
2087
-		OR (($p=strpos($css,'?'))!==FALSE)) {
2087
+		OR (($p = strpos($css, '?')) !== FALSE)) {
2088 2088
 		$distant = true;
2089 2089
 		$cssf = parse_url($css);
2090
-		$cssf = $cssf['path'].($cssf['query']?"?".$cssf['query']:"");
2090
+		$cssf = $cssf['path'].($cssf['query'] ? "?".$cssf['query'] : "");
2091 2091
 		$cssf = preg_replace(',[?:&=],', "_", $cssf);
2092 2092
 	}
2093 2093
 	else {
@@ -2101,13 +2101,13 @@  discard block
 block discarded – undo
2101 2101
 	}
2102 2102
 
2103 2103
 	// 2.
2104
-	$dir_var = sous_repertoire (_DIR_VAR, 'cache-css');
2104
+	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2105 2105
 	$f = $dir_var
2106 2106
 		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2107
-		. '.' . substr(md5($cssf), 0,4) . '_' . $ndir . '.css';
2107
+		. '.'.substr(md5($cssf), 0, 4).'_'.$ndir.'.css';
2108 2108
 
2109 2109
 	// la css peut etre distante (url absolue !)
2110
-	if ($distant){
2110
+	if ($distant) {
2111 2111
 		include_spip('inc/distant');
2112 2112
 		$contenu = recuperer_page($css);
2113 2113
 		if (!$contenu) return $css;
@@ -2126,29 +2126,29 @@  discard block
 block discarded – undo
2126 2126
 		$contenu);
2127 2127
 	
2128 2128
 	// reperer les @import auxquels il faut propager le direction_css
2129
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims",$contenu,$regs);
2130
-	$src = array();$src_direction_css = array();$src_faux_abs=array();
2129
+	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2130
+	$src = array(); $src_direction_css = array(); $src_faux_abs = array();
2131 2131
 	$d = dirname($css);
2132
-	foreach($regs[1] as $k=>$import_css){
2133
-		$css_direction = direction_css("$d/$import_css",$voulue);
2132
+	foreach ($regs[1] as $k=>$import_css) {
2133
+		$css_direction = direction_css("$d/$import_css", $voulue);
2134 2134
 		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2135
-		if (substr($css_direction,0,strlen($d)+1)=="$d/") $css_direction = substr($css_direction,strlen($d)+1);
2135
+		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") $css_direction = substr($css_direction, strlen($d) + 1);
2136 2136
 		// si la css_direction commence par $dir_var on la fait passer pour une absolue
2137
-		elseif (substr($css_direction,0,strlen($dir_var))==$dir_var) {
2138
-			$css_direction = substr($css_direction,strlen($dir_var));
2137
+		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2138
+			$css_direction = substr($css_direction, strlen($dir_var));
2139 2139
 			$src_faux_abs["/@@@@@@/".$css_direction] = $css_direction;
2140 2140
 			$css_direction = "/@@@@@@/".$css_direction;
2141 2141
 		}
2142 2142
 		$src[] = $regs[0][$k];
2143
-		$src_direction_css[] = str_replace($import_css,$css_direction,$regs[0][$k]);
2143
+		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2144 2144
 	}
2145
-	$contenu = str_replace($src,$src_direction_css,$contenu);
2145
+	$contenu = str_replace($src, $src_direction_css, $contenu);
2146 2146
 
2147 2147
 	$contenu = urls_absolues_css($contenu, $css);
2148 2148
 
2149 2149
 	// virer les fausses url absolues que l'on a mis dans les import
2150 2150
 	if (count($src_faux_abs))
2151
-		$contenu = str_replace(array_keys($src_faux_abs),$src_faux_abs,$contenu);
2151
+		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2152 2152
 
2153 2153
 	if (!ecrire_fichier($f, $contenu))
2154 2154
 		return $css;
@@ -2159,23 +2159,23 @@  discard block
 block discarded – undo
2159 2159
 // recuperere le chemin d'une css existante et :
2160 2160
 // cree (ou recree) dans _DIR_VAR/cache_css/ une css dont les url relatives sont passees en url absolues
2161 2161
 // http://doc.spip.org/@url_absolue_css
2162
-function url_absolue_css ($css) {
2162
+function url_absolue_css($css) {
2163 2163
 	if (!preg_match(',\.css$,i', $css, $r)) return $css;
2164 2164
 
2165 2165
 	$url_absolue_css = url_absolue($css);
2166 2166
 
2167
-	$f = basename($css,'.css');
2168
-	$f = sous_repertoire (_DIR_VAR, 'cache-css') 
2169
-		. preg_replace(",(.*?)(_rtl|_ltr)?$,","\\1-urlabs-" . substr(md5("$css-urlabs"), 0,4) . "\\2",$f) 
2167
+	$f = basename($css, '.css');
2168
+	$f = sous_repertoire(_DIR_VAR, 'cache-css') 
2169
+		. preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-".substr(md5("$css-urlabs"), 0, 4)."\\2", $f) 
2170 2170
 		. '.css';
2171 2171
 
2172 2172
 	if ((@filemtime($f) > @filemtime($css))
2173 2173
 	AND (_VAR_MODE != 'recalcul'))
2174 2174
 		return $f;
2175 2175
 
2176
-	if ($url_absolue_css==$css){
2177
-		if (strncmp($GLOBALS['meta']['adresse_site'],$css,$l=strlen($GLOBALS['meta']['adresse_site']))!=0
2178
-		 OR !lire_fichier(_DIR_RACINE . substr($css,$l), $contenu)){
2176
+	if ($url_absolue_css == $css) {
2177
+		if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
2178
+		 OR !lire_fichier(_DIR_RACINE.substr($css, $l), $contenu)) {
2179 2179
 		 		include_spip('inc/distant');
2180 2180
 		 		if (!$contenu = recuperer_page($css))
2181 2181
 					return $css;
@@ -2248,15 +2248,15 @@  discard block
 block discarded – undo
2248 2248
 // il est possible de passer en 3eme argument optionnel le numero de parenthese capturante
2249 2249
 // accepte egalement la syntaxe #TRUC|match{truc(...)$,1} ou le modificateur n'est pas passe en second argument
2250 2250
 // http://doc.spip.org/@match
2251
-function match($texte, $expression, $modif="UimsS",$capte=0) {
2252
-	if (intval($modif) AND $capte==0){
2251
+function match($texte, $expression, $modif = "UimsS", $capte = 0) {
2252
+	if (intval($modif) AND $capte == 0) {
2253 2253
 		$capte = $modif;
2254 2254
 		$modif = "UimsS";
2255 2255
 	}
2256
-	$expression=str_replace("\/","/",$expression);
2257
-	$expression=str_replace("/","\/",$expression);
2256
+	$expression = str_replace("\/", "/", $expression);
2257
+	$expression = str_replace("/", "\/", $expression);
2258 2258
 
2259
-	if (preg_match('/' . $expression . '/' . $modif,$texte, $r)) {
2259
+	if (preg_match('/'.$expression.'/'.$modif, $texte, $r)) {
2260 2260
 		if (isset($r[$capte]))
2261 2261
 			return $r[$capte];
2262 2262
 		else
@@ -2268,10 +2268,10 @@  discard block
 block discarded – undo
2268 2268
 // filtre replace pour faire des operations avec expression reguliere
2269 2269
 // [(#TEXTE|replace{^ceci$,cela,UimsS})]
2270 2270
 // http://doc.spip.org/@replace
2271
-function replace($texte, $expression, $replace='', $modif="UimsS") {
2272
-	$expression=str_replace("\/","/", $expression);
2273
-	$expression=str_replace("/","\/",$expression);
2274
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
2271
+function replace($texte, $expression, $replace = '', $modif = "UimsS") {
2272
+	$expression = str_replace("\/", "/", $expression);
2273
+	$expression = str_replace("/", "\/", $expression);
2274
+	return preg_replace('/'.$expression.'/'.$modif, $replace, $texte);
2275 2275
 }
2276 2276
 
2277 2277
 
@@ -2288,14 +2288,14 @@  discard block
 block discarded – undo
2288 2288
 	AND preg_match_all(
2289 2289
 	',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
2290 2290
 	$t, $matches, PREG_PATTERN_ORDER))
2291
-		$doublons['documents'] .= "," . join(',', $matches[1]);
2291
+		$doublons['documents'] .= ",".join(',', $matches[1]);
2292 2292
 
2293 2293
 	return $letexte;
2294 2294
 }
2295 2295
 
2296 2296
 // filtre vide qui ne renvoie rien
2297 2297
 // http://doc.spip.org/@vide
2298
-function vide($texte){
2298
+function vide($texte) {
2299 2299
 	return "";
2300 2300
 }
2301 2301
 
@@ -2305,27 +2305,27 @@  discard block
 block discarded – undo
2305 2305
 
2306 2306
 // A partir d'un #ENV, retourne des <param ...>
2307 2307
 // http://doc.spip.org/@env_to_params
2308
-function env_to_params ($texte, $ignore_params=array()) {
2309
-	$ignore_params = array_merge (
2308
+function env_to_params($texte, $ignore_params = array()) {
2309
+	$ignore_params = array_merge(
2310 2310
 		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
2311 2311
 	$ignore_params);
2312 2312
 	$tableau = unserialize($texte);
2313 2313
 	$texte = "";
2314 2314
 	foreach ($tableau as $i => $j)
2315
-		if (is_string($j) AND !in_array($i,$ignore_params))
2315
+		if (is_string($j) AND !in_array($i, $ignore_params))
2316 2316
 			$texte .= "<param name='".$i."'\n\tvalue='".$j."' />";
2317 2317
 	return $texte;
2318 2318
 }
2319 2319
 // A partir d'un #ENV, retourne des attributs
2320 2320
 // http://doc.spip.org/@env_to_attributs
2321
-function env_to_attributs ($texte, $ignore_params=array()) {
2322
-	$ignore_params = array_merge (
2321
+function env_to_attributs($texte, $ignore_params = array()) {
2322
+	$ignore_params = array_merge(
2323 2323
 		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
2324 2324
 	$ignore_params);
2325 2325
 	$tableau = unserialize($texte);
2326 2326
 	$texte = "";
2327 2327
 	foreach ($tableau as $i => $j)
2328
-		if (is_string($j) AND !in_array($i,$ignore_params))
2328
+		if (is_string($j) AND !in_array($i, $ignore_params))
2329 2329
 			$texte .= $i."='".$j."' ";
2330 2330
 	return $texte;
2331 2331
 }
@@ -2333,7 +2333,7 @@  discard block
 block discarded – undo
2333 2333
 // Concatener des chaines
2334 2334
 // #TEXTE|concat{texte1,texte2,...}
2335 2335
 // http://doc.spip.org/@concat
2336
-function concat(){
2336
+function concat() {
2337 2337
 	$args = func_get_args();
2338 2338
 	return join('', $args);
2339 2339
 }
@@ -2343,10 +2343,10 @@  discard block
 block discarded – undo
2343 2343
 // http://doc.spip.org/@charge_scripts
2344 2344
 function charge_scripts($files, $script = true) {
2345 2345
 	$flux = "";
2346
-	foreach(is_array($files)?$files:explode("|",$files) as $file) {
2346
+	foreach (is_array($files) ? $files : explode("|", $files) as $file) {
2347 2347
 		if (!is_string($file)) continue;
2348 2348
 		if ($script)
2349
-			$file = preg_match(",^\w+$,",$file) ? "javascript/$file.js" : '';
2349
+			$file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
2350 2350
 		if ($file) $path = find_in_path($file);
2351 2351
 		if ($path) $flux .= spip_file_get_contents($path);
2352 2352
 	}
@@ -2371,24 +2371,24 @@  discard block
 block discarded – undo
2371 2371
  *   sous forme -xx.png (pour les icones essentiellement) (oui par defaut)
2372 2372
  * @return string
2373 2373
  */
2374
-function http_img_pack($img, $alt, $atts='', $title='', $options = array()) {
2375
-	if (!isset($options['chemin_image']) OR $options['chemin_image']==true)
2374
+function http_img_pack($img, $alt, $atts = '', $title = '', $options = array()) {
2375
+	if (!isset($options['chemin_image']) OR $options['chemin_image'] == true)
2376 2376
 		$img = chemin_image($img);
2377
-	if (stripos($atts, 'width')===false){
2377
+	if (stripos($atts, 'width') === false) {
2378 2378
 		// utiliser directement l'info de taille presente dans le nom
2379
-		if ((!isset($options['utiliser_suffixe_size']) OR $options['utiliser_suffixe_size']==true)
2380
-		    AND preg_match(',-([0-9]+)[.](png|gif)$,',$img,$regs)){
2379
+		if ((!isset($options['utiliser_suffixe_size']) OR $options['utiliser_suffixe_size'] == true)
2380
+		    AND preg_match(',-([0-9]+)[.](png|gif)$,', $img, $regs)) {
2381 2381
 			$largeur = $hauteur = intval($regs[1]);
2382 2382
 		}
2383
-		else{
2383
+		else {
2384 2384
 			$taille = taille_image($img);
2385
-			list($hauteur,$largeur) = $taille;
2385
+			list($hauteur, $largeur) = $taille;
2386 2386
 			if (!$hauteur OR !$largeur)
2387 2387
 				return "";
2388 2388
 		}
2389
-		$atts.=" width='".$largeur."' height='".$hauteur."'";
2389
+		$atts .= " width='".$largeur."' height='".$hauteur."'";
2390 2390
 	}
2391
-	return  "<img src='$img' alt='" . attribut_html($alt ? $alt : $title) . "'"
2391
+	return  "<img src='$img' alt='".attribut_html($alt ? $alt : $title)."'"
2392 2392
 	  . ($title ? ' title="'.attribut_html($title).'"' : '')
2393 2393
 	  . " ".ltrim($atts)
2394 2394
 	  . " />";
@@ -2403,8 +2403,8 @@  discard block
 block discarded – undo
2403 2403
  * @param string $att
2404 2404
  * @return string
2405 2405
  */
2406
-function http_style_background($img, $att=''){
2407
-  return " style='background".($att?"":"-image").": url(\"".chemin_image($img)."\")" . ($att ? (' ' . $att) : '') . ";'";
2406
+function http_style_background($img, $att = '') {
2407
+  return " style='background".($att ? "" : "-image").": url(\"".chemin_image($img)."\")".($att ? (' '.$att) : '').";'";
2408 2408
 }
2409 2409
 
2410 2410
 /**
@@ -2415,8 +2415,8 @@  discard block
 block discarded – undo
2415 2415
  * @param string $class
2416 2416
  * @return string
2417 2417
  */
2418
-function filtre_balise_img_dist($img,$alt="",$class=""){
2419
-	return http_img_pack($img, $alt, $class?" class='".attribut_html($class)."'":'', '', array('chemin_image'=>false,'utiliser_suffixe_size'=>false));
2418
+function filtre_balise_img_dist($img, $alt = "", $class = "") {
2419
+	return http_img_pack($img, $alt, $class ? " class='".attribut_html($class)."'" : '', '', array('chemin_image'=>false, 'utiliser_suffixe_size'=>false));
2420 2420
 }
2421 2421
 
2422 2422
 
@@ -2424,8 +2424,8 @@  discard block
 block discarded – undo
2424 2424
 // http://doc.spip.org/@filtre_foreach_dist
2425 2425
 function filtre_foreach_dist($balise_deserializee, $modele = 'foreach') {
2426 2426
 	$texte = '';
2427
-	if(is_array($balise_deserializee))
2428
-		foreach($balise_deserializee as $k => $v) {
2427
+	if (is_array($balise_deserializee))
2428
+		foreach ($balise_deserializee as $k => $v) {
2429 2429
 			$res = recuperer_fond('modeles/'.$modele,
2430 2430
 				array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
2431 2431
 			);
@@ -2454,7 +2454,7 @@  discard block
 block discarded – undo
2454 2454
 	elseif (isset($plugins_actifs[$plugin][$type_info]))
2455 2455
 		return $plugins_actifs[$plugin][$type_info];
2456 2456
 	else {
2457
-		$get_infos = charger_fonction('get_infos','plugins');
2457
+		$get_infos = charger_fonction('get_infos', 'plugins');
2458 2458
 		// On prend en compte les extensions
2459 2459
 		if (!is_dir($plugins_actifs[$plugin]['dir_type']))
2460 2460
 			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
@@ -2471,8 +2471,8 @@  discard block
 block discarded – undo
2471 2471
 
2472 2472
 
2473 2473
 // http://doc.spip.org/@puce_changement_statut
2474
-function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax=false){
2475
-	$puce_statut = charger_fonction('puce_statut','inc');
2474
+function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
2475
+	$puce_statut = charger_fonction('puce_statut', 'inc');
2476 2476
 	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
2477 2477
 }
2478 2478
 
@@ -2487,11 +2487,11 @@  discard block
 block discarded – undo
2487 2487
  * @param int $id_parent
2488 2488
  * @return string
2489 2489
  */
2490
-function filtre_puce_statut_dist($statut,$objet,$id_objet=0,$id_parent=0){
2490
+function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
2491 2491
 	static $puce_statut = null;
2492 2492
 	if (!$puce_statut)
2493
-		$puce_statut = charger_fonction('puce_statut','inc');
2494
-	return $puce_statut($id_objet, $statut, $id_parent, $objet, false, objet_info($objet,'editable')?_ACTIVER_PUCE_RAPIDE:false);
2493
+		$puce_statut = charger_fonction('puce_statut', 'inc');
2494
+	return $puce_statut($id_objet, $statut, $id_parent, $objet, false, objet_info($objet, 'editable') ?_ACTIVER_PUCE_RAPIDE:false);
2495 2495
 }
2496 2496
 
2497 2497
 
@@ -2512,7 +2512,7 @@  discard block
 block discarded – undo
2512 2512
  *   ajaxid pour cibler le bloc et forcer sa mise a jour
2513 2513
  * @return string
2514 2514
  */
2515
-function encoder_contexte_ajax($c,$form='', $emboite=NULL, $ajaxid='') {
2515
+function encoder_contexte_ajax($c, $form = '', $emboite = NULL, $ajaxid = '') {
2516 2516
 	if (is_string($c)
2517 2517
 	AND !is_null(@unserialize($c))) {
2518 2518
 		$c = unserialize($c);
@@ -2523,7 +2523,7 @@  discard block
 block discarded – undo
2523 2523
 	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
2524 2524
 	// le debut_x=0 n'existe pas, et on resterait sur 1
2525 2525
 	foreach ($c as $k => $v) {
2526
-		if (strpos($k,'debut_') === 0) {
2526
+		if (strpos($k, 'debut_') === 0) {
2527 2527
 			unset($c[$k]);
2528 2528
 		}
2529 2529
 	}
@@ -2532,7 +2532,7 @@  discard block
 block discarded – undo
2532 2532
 		include_spip("inc/securiser_action");
2533 2533
 
2534 2534
 	$c = serialize($c);
2535
-	$cle = calculer_cle_action($form . $c);
2535
+	$cle = calculer_cle_action($form.$c);
2536 2536
 	$c = "$cle:$c";
2537 2537
 
2538 2538
 	// on ne stocke pas les contextes dans des fichiers caches
@@ -2545,7 +2545,7 @@  discard block
 block discarded – undo
2545 2545
 		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
2546 2546
 			$env = gzdeflate($env);
2547 2547
 			// http://core.spip.org/issues/2667 | https://bugs.php.net/bug.php?id=61287
2548
-			if (substr(phpversion(),0,5) == '5.4.0' AND !@gzinflate($env)) {
2548
+			if (substr(phpversion(), 0, 5) == '5.4.0' AND !@gzinflate($env)) {
2549 2549
 				$cache_contextes_ajax = true;
2550 2550
 				spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT);
2551 2551
 			}
@@ -2569,7 +2569,7 @@  discard block
 block discarded – undo
2569 2569
 		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
2570 2570
 		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
2571 2571
 		$md5 = md5($c);
2572
-		ecrire_fichier("$dir/c$md5",$c);
2572
+		ecrire_fichier("$dir/c$md5", $c);
2573 2573
 		$env = $md5;
2574 2574
 	} 
2575 2575
 	
@@ -2582,19 +2582,19 @@  discard block
 block discarded – undo
2582 2582
 	if ($ajaxid and is_string($ajaxid)) {
2583 2583
 		// ajaxid est normalement conforme a un nom de classe css
2584 2584
 		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
2585
-		$class .= ' ajax-id-' . entites_html($ajaxid);
2585
+		$class .= ' ajax-id-'.entites_html($ajaxid);
2586 2586
 	}
2587 2587
 	return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
2588 2588
 }
2589 2589
 
2590 2590
 // la procedure inverse de encoder_contexte_ajax()
2591 2591
 // http://doc.spip.org/@decoder_contexte_ajax
2592
-function decoder_contexte_ajax($c,$form='') {
2592
+function decoder_contexte_ajax($c, $form = '') {
2593 2593
 	if (!function_exists('calculer_cle_action'))
2594 2594
 		include_spip("inc/securiser_action");
2595
-	if (( (defined('_CACHE_CONTEXTES_AJAX') AND _CACHE_CONTEXTES_AJAX) OR strlen($c)==32)
2595
+	if (((defined('_CACHE_CONTEXTES_AJAX') AND _CACHE_CONTEXTES_AJAX) OR strlen($c) == 32)
2596 2596
 		AND $dir = sous_repertoire(_DIR_CACHE, 'contextes')
2597
-		AND lire_fichier("$dir/c$c",$contexte)) {
2597
+		AND lire_fichier("$dir/c$c", $contexte)) {
2598 2598
 			$c = $contexte;
2599 2599
 	} else {
2600 2600
 		$c = @base64_decode($c);
@@ -2606,11 +2606,11 @@  discard block
 block discarded – undo
2606 2606
 	// extraire la signature en debut de contexte
2607 2607
 	// et la verifier avant de deserializer
2608 2608
 	// format : signature:donneesserializees
2609
-	if ($p = strpos($c,":")){
2610
-		$cle = substr($c,0,$p);
2611
-		$c = substr($c,$p+1);
2609
+	if ($p = strpos($c, ":")) {
2610
+		$cle = substr($c, 0, $p);
2611
+		$c = substr($c, $p + 1);
2612 2612
 
2613
-		if ($cle == calculer_cle_action($form . $c)) {
2613
+		if ($cle == calculer_cle_action($form.$c)) {
2614 2614
 			$env = @unserialize($c);
2615 2615
 			return $env;
2616 2616
 		}
@@ -2622,7 +2622,7 @@  discard block
 block discarded – undo
2622 2622
 // encrypter/decrypter un message
2623 2623
 // http://www.php.net/manual/fr/language.operators.bitwise.php#81358
2624 2624
 // http://doc.spip.org/@_xor
2625
-function _xor($message, $key=null){
2625
+function _xor($message, $key = null) {
2626 2626
 	if (is_null($key)) {
2627 2627
 		if (!function_exists('calculer_cle_action'))
2628 2628
 			include_spip("inc/securiser_action");
@@ -2631,16 +2631,16 @@  discard block
 block discarded – undo
2631 2631
 
2632 2632
 	$keylen = strlen($key);
2633 2633
 	$messagelen = strlen($message);
2634
-	for($i=0; $i<$messagelen; $i++)
2635
-		$message[$i] = ~($message[$i]^$key[$i%$keylen]);
2634
+	for ($i = 0; $i < $messagelen; $i++)
2635
+		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
2636 2636
 
2637 2637
 	return $message;
2638 2638
 }
2639 2639
 
2640 2640
 // Les vrai fonctions sont dans le plugin forum, mais on evite ici une erreur du compilateur
2641 2641
 // en absence du plugin
2642
-function url_reponse_forum($texte){return $texte;}
2643
-function url_rss_forum($texte){return $texte;}
2642
+function url_reponse_forum($texte) {return $texte; }
2643
+function url_rss_forum($texte) {return $texte; }
2644 2644
 
2645 2645
 
2646 2646
 /**
@@ -2659,16 +2659,16 @@  discard block
 block discarded – undo
2659 2659
  *   complement a la balise a pour gerer un evenement javascript, de la forme " onclick='...'"
2660 2660
  * @return string
2661 2661
  */
2662
-function lien_ou_expose($url,$libelle=NULL,$on=false,$class="",$title="",$rel="", $evt=''){
2662
+function lien_ou_expose($url, $libelle = NULL, $on = false, $class = "", $title = "", $rel = "", $evt = '') {
2663 2663
 	if ($on) {
2664 2664
 		$bal = "strong";
2665 2665
 		$att = "class='on'";
2666 2666
 	} else {
2667 2667
 		$bal = 'a';
2668 2668
 		$att = "href='$url'"
2669
-	  	.($title?" title='".attribut_html($title)."'":'')
2670
-	  	.($class?" class='".attribut_html($class)."'":'')
2671
-	  	.($rel?" rel='".attribut_html($rel)."'":'')
2669
+	  	.($title ? " title='".attribut_html($title)."'" : '')
2670
+	  	.($class ? " class='".attribut_html($class)."'" : '')
2671
+	  	.($rel ? " rel='".attribut_html($rel)."'" : '')
2672 2672
 		.$evt;
2673 2673
 	}
2674 2674
 	if ($libelle === NULL)
@@ -2689,12 +2689,12 @@  discard block
 block discarded – undo
2689 2689
  * @param array $vars : Les autres variables nécessaires aux chaines de langues (facultatif)
2690 2690
  * @return string : la chaine de langue finale en utilisant la fonction _T()
2691 2691
  */
2692
-function singulier_ou_pluriel($nb,$chaine_un,$chaine_plusieurs,$var='nb',$vars=array()){
2693
-	if (!$nb=intval($nb)) return "";
2692
+function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = array()) {
2693
+	if (!$nb = intval($nb)) return "";
2694 2694
 	if (!is_array($vars)) return "";
2695 2695
 	$vars[$var] = $nb;
2696
-	if ($nb>1) return _T($chaine_plusieurs, $vars);
2697
-	else return _T($chaine_un,$vars);
2696
+	if ($nb > 1) return _T($chaine_plusieurs, $vars);
2697
+	else return _T($chaine_un, $vars);
2698 2698
 }
2699 2699
 
2700 2700
 
@@ -2718,8 +2718,8 @@  discard block
 block discarded – undo
2718 2718
  *  "onclick='...'" par exemple
2719 2719
  * @return string 
2720 2720
  */
2721
-function prepare_icone_base($type, $lien, $texte, $fond, $fonction="", $class="",$javascript=""){
2722
-	if (in_array($fonction,array("del","supprimer.gif")))
2721
+function prepare_icone_base($type, $lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
2722
+	if (in_array($fonction, array("del", "supprimer.gif")))
2723 2723
 		$class .= ' danger';
2724 2724
 	elseif ($fonction == "rien.gif")
2725 2725
 		$fonction = "";
@@ -2727,40 +2727,40 @@  discard block
 block discarded – undo
2727 2727
 		$fonction = "del";
2728 2728
 
2729 2729
 	// remappage des icone : article-24.png+new => article-new-24.png
2730
-	if ($icone_renommer = charger_fonction('icone_renommer','inc',true))
2731
-		list($fond,$fonction) = $icone_renommer($fond,$fonction);
2730
+	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true))
2731
+		list($fond, $fonction) = $icone_renommer($fond, $fonction);
2732 2732
 
2733 2733
 	// ajouter le type d'objet dans la class de l'icone
2734
-	$class .= " " . substr(basename($fond),0,-4);
2734
+	$class .= " ".substr(basename($fond), 0, -4);
2735 2735
 
2736 2736
 	$alt = attribut_html($texte);
2737 2737
 	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
2738 2738
 
2739 2739
 	$ajax = "";
2740
-	if (strpos($class,"ajax")!==false) {
2741
-			$ajax="ajax";
2742
-		if (strpos($class,"preload")!==false)
2743
-			$ajax.=" preload";
2744
-		if (strpos($class,"nocache")!==false)
2745
-			$ajax.=" nocache";
2746
-		$ajax=" class='$ajax'";
2740
+	if (strpos($class, "ajax") !== false) {
2741
+			$ajax = "ajax";
2742
+		if (strpos($class, "preload") !== false)
2743
+			$ajax .= " preload";
2744
+		if (strpos($class, "nocache") !== false)
2745
+			$ajax .= " nocache";
2746
+		$ajax = " class='$ajax'";
2747 2747
 	}
2748 2748
 
2749 2749
 	$size = 24;
2750
-	if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i",$fond,$match))
2750
+	if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i", $fond, $match))
2751 2751
 		$size = $match[1];
2752 2752
 
2753
-	if ($fonction){
2753
+	if ($fonction) {
2754 2754
 		// 2 images pour composer l'icone : le fond (article) en background,
2755 2755
 		// la fonction (new) en image
2756
-		$icone = http_img_pack($fonction, $alt, "width='$size' height='$size'\n" .
2756
+		$icone = http_img_pack($fonction, $alt, "width='$size' height='$size'\n".
2757 2757
 					http_style_background($fond));
2758 2758
 	}
2759 2759
 	else {
2760 2760
 		$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
2761 2761
 	}
2762 2762
 
2763
-	if ($type=='lien')
2763
+	if ($type == 'lien')
2764 2764
 		return "<span class='icone s$size $class'>"
2765 2765
 		. "<a href='$lien'$title$ajax$javascript>"
2766 2766
 		. $icone
@@ -2768,28 +2768,28 @@  discard block
 block discarded – undo
2768 2768
 		. "</a></span>\n";
2769 2769
 
2770 2770
 	else
2771
-		return bouton_action("$icone<b>$texte</b>",$lien,"icone s$size $class",$javascript,$alt);
2771
+		return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt);
2772 2772
 }
2773 2773
 
2774
-function icone_base($lien, $texte, $fond, $fonction="", $class="",$javascript=""){
2774
+function icone_base($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
2775 2775
 	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
2776 2776
 }
2777
-function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction="", $class="",$javascript=""){
2778
-	return icone_base($lien,$texte,$fond,$fonction,"verticale $class",$javascript);
2777
+function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
2778
+	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
2779 2779
 }
2780
-function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction="", $class="",$javascript=""){
2781
-	return icone_base($lien,$texte,$fond,$fonction,"horizontale $class",$javascript);
2780
+function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
2781
+	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
2782 2782
 }
2783 2783
 
2784
-function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction="", $class="",$confirm=""){
2784
+function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = "", $class = "", $confirm = "") {
2785 2785
 	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm);
2786 2786
 }
2787 2787
 /*
2788 2788
  * Filtre icone pour compatibilite
2789 2789
  * mappe sur icone_base
2790 2790
  */
2791
-function filtre_icone_dist($lien, $texte, $fond, $align="", $fonction="", $class="",$javascript=""){
2792
-	return icone_base($lien,$texte,$fond,$fonction,"verticale $align $class",$javascript);
2791
+function filtre_icone_dist($lien, $texte, $fond, $align = "", $fonction = "", $class = "", $javascript = "") {
2792
+	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
2793 2793
 }
2794 2794
 
2795 2795
 
@@ -2801,7 +2801,7 @@  discard block
 block discarded – undo
2801 2801
  * @param string $b
2802 2802
  * @return array
2803 2803
  */
2804
-function filtre_explode_dist($a,$b){return explode($b,$a);}
2804
+function filtre_explode_dist($a, $b) {return explode($b, $a); }
2805 2805
 
2806 2806
 /**
2807 2807
  * filtre implode pour les squelettes permettant d'ecrire
@@ -2811,26 +2811,26 @@  discard block
 block discarded – undo
2811 2811
  * @param string $b
2812 2812
  * @return string
2813 2813
  */
2814
-function filtre_implode_dist($a,$b){return is_array($a)?implode($b,$a):$a;}
2814
+function filtre_implode_dist($a, $b) {return is_array($a) ?implode($b, $a) : $a; }
2815 2815
 
2816 2816
 /**
2817 2817
  * Produire les styles prives qui associent item de menu avec icone en background
2818 2818
  * @return string
2819 2819
  */
2820
-function bando_images_background(){
2820
+function bando_images_background() {
2821 2821
 	include_spip('inc/bandeau');
2822 2822
 	// recuperer tous les boutons et leurs images
2823
-	$boutons = definir_barre_boutons(definir_barre_contexte(),true,false);
2823
+	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
2824 2824
 
2825 2825
 	$res = "";
2826
-	foreach($boutons as $page => $detail){
2826
+	foreach ($boutons as $page => $detail) {
2827 2827
 		if ($detail->icone AND strlen(trim($detail->icone)))
2828
-			$res .="\n.navigation_avec_icones #bando1_$page {background-image:url(".$detail->icone.");}";
2829
-		$selecteur = (in_array($page,array('outils_rapides','outils_collaboratifs'))?"":".navigation_avec_icones ");
2828
+			$res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(".$detail->icone.");}";
2829
+		$selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
2830 2830
 		if (is_array($detail->sousmenu))
2831
-			foreach($detail->sousmenu as $souspage=>$sousdetail)
2831
+			foreach ($detail->sousmenu as $souspage=>$sousdetail)
2832 2832
 				if ($sousdetail->icone AND strlen(trim($sousdetail->icone)))
2833
-					$res .="\n$selecteur.bando2_$souspage {background-image:url(".$sousdetail->icone.");}";
2833
+					$res .= "\n$selecteur.bando2_$souspage {background-image:url(".$sousdetail->icone.");}";
2834 2834
 	}
2835 2835
 	return $res;
2836 2836
 }
@@ -2850,15 +2850,15 @@  discard block
 block discarded – undo
2850 2850
  *   et avant execution de l'action. Si la callback renvoie false, elle annule le declenchement de l'action
2851 2851
  * @return string
2852 2852
  */
2853
-function bouton_action($libelle, $url, $class="", $confirm="", $title="", $callback=""){
2853
+function bouton_action($libelle, $url, $class = "", $confirm = "", $title = "", $callback = "") {
2854 2854
 	if ($confirm) {
2855
-		$confirm = "confirm(\"" . attribut_html($confirm) . "\")";
2855
+		$confirm = "confirm(\"".attribut_html($confirm)."\")";
2856 2856
 	  if ($callback)
2857 2857
 		  $callback = "$confirm?($callback):false";
2858 2858
 	  else
2859 2859
 		  $callback = $confirm;
2860 2860
 	}
2861
-	$onclick = $callback?" onclick='return ".addcslashes($callback,"'")."'":"";
2861
+	$onclick = $callback ? " onclick='return ".addcslashes($callback, "'")."'" : "";
2862 2862
 	$title = $title ? " title='$title'" : "";
2863 2863
 	return "<form class='bouton_action_post $class' method='post' action='$url'><div>".form_hidden($url)
2864 2864
 		."<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>";
@@ -2871,8 +2871,8 @@  discard block
 block discarded – undo
2871 2871
  * @param string $t
2872 2872
  * @return string
2873 2873
  */
2874
-function tri_protege_champ($t){
2875
-	return preg_replace(',[^\s\w.+],','',$t);
2874
+function tri_protege_champ($t) {
2875
+	return preg_replace(',[^\s\w.+],', '', $t);
2876 2876
 }
2877 2877
 
2878 2878
 /**
@@ -2883,29 +2883,29 @@  discard block
 block discarded – undo
2883 2883
  * @param array $from
2884 2884
  * @return string
2885 2885
  */
2886
-function tri_champ_order($t, $from=null){
2887
-	if(strncmp($t,'multi ',6)==0){
2886
+function tri_champ_order($t, $from = null) {
2887
+	if (strncmp($t, 'multi ', 6) == 0) {
2888 2888
 		return "multi";
2889 2889
 	}
2890 2890
 
2891 2891
 	$champ = $t;
2892 2892
 
2893
-	if (strncmp($t,'num ',4)==0)
2894
-		$champ = substr($t,4);
2893
+	if (strncmp($t, 'num ', 4) == 0)
2894
+		$champ = substr($t, 4);
2895 2895
 	// enlever les autres espaces non evacues par tri_protege_champ
2896
-	$champ = preg_replace(',\s,','',$champ);
2896
+	$champ = preg_replace(',\s,', '', $champ);
2897 2897
 
2898
-	if (is_array($from)){
2899
-		$trouver_table = charger_fonction('trouver_table','base');
2900
-		foreach($from as $idt=>$table_sql){
2898
+	if (is_array($from)) {
2899
+		$trouver_table = charger_fonction('trouver_table', 'base');
2900
+		foreach ($from as $idt=>$table_sql) {
2901 2901
 			if ($desc = $trouver_table($table_sql)
2902
-				AND isset($desc['field'][$champ])){
2902
+				AND isset($desc['field'][$champ])) {
2903 2903
 				$champ = "$idt.$champ";
2904 2904
 				break;
2905 2905
 			}
2906 2906
 		}
2907 2907
 	}
2908
-	if (strncmp($t,'num ',4)==0)
2908
+	if (strncmp($t, 'num ', 4) == 0)
2909 2909
 		return "0+$champ";
2910 2910
 	else
2911 2911
 		return $champ;
@@ -2921,14 +2921,14 @@  discard block
 block discarded – undo
2921 2921
  * @param string $t
2922 2922
  * @return string
2923 2923
  */
2924
-function tri_champ_select($t){
2925
-	if(strncmp($t,'multi ',6)==0){
2926
-		$t = substr($t,6);
2927
-		$t = preg_replace(',\s,','',$t);
2928
-		$t = sql_multi($t,$GLOBALS['spip_lang']);
2924
+function tri_champ_select($t) {
2925
+	if (strncmp($t, 'multi ', 6) == 0) {
2926
+		$t = substr($t, 6);
2927
+		$t = preg_replace(',\s,', '', $t);
2928
+		$t = sql_multi($t, $GLOBALS['spip_lang']);
2929 2929
 		return $t;
2930 2930
 	}
2931
-	if(trim($t)=='hasard'){
2931
+	if (trim($t) == 'hasard') {
2932 2932
 		return 'rand() AS hasard';
2933 2933
 	}
2934 2934
 	return "''";
@@ -2952,9 +2952,9 @@  discard block
 block discarded – undo
2952 2952
  * @param string $etoile
2953 2953
  * @return string
2954 2954
  */
2955
-function generer_info_entite($id_objet, $type_objet, $info, $etoile=""){
2955
+function generer_info_entite($id_objet, $type_objet, $info, $etoile = "") {
2956 2956
 	global $table_des_traitements;
2957
-	static $trouver_table=null;
2957
+	static $trouver_table = null;
2958 2958
 	static $objets;
2959 2959
 
2960 2960
 	// On verifie qu'on a tout ce qu'il faut
@@ -2963,7 +2963,7 @@  discard block
 block discarded – undo
2963 2963
 		return '';
2964 2964
 
2965 2965
 	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
2966
-	if (isset($objets[$type_objet]) AND $objets[$type_objet]===false)
2966
+	if (isset($objets[$type_objet]) AND $objets[$type_objet] === false)
2967 2967
 		return '';
2968 2968
 
2969 2969
 	// Si on demande l'url, on retourne direct la fonction
@@ -2977,18 +2977,18 @@  discard block
 block discarded – undo
2977 2977
 	if (!isset($objets[$type_objet][$id_objet])
2978 2978
 	  OR
2979 2979
 	  ($demande_titre AND !isset($objets[$type_objet][$id_objet]['titre']))
2980
-	  ){
2980
+	  ) {
2981 2981
 		if (!$trouver_table)
2982
-			$trouver_table = charger_fonction('trouver_table','base');
2982
+			$trouver_table = charger_fonction('trouver_table', 'base');
2983 2983
 		$desc = $trouver_table(table_objet_sql($type_objet));
2984 2984
 		if (!$desc)
2985 2985
 			return $objets[$type_objet] = false;
2986 2986
 
2987 2987
 		// Si on demande le titre, on le gere en interne
2988 2988
 		$champ_titre = "";
2989
-		if ($demande_titre){
2989
+		if ($demande_titre) {
2990 2990
 			// si pas de titre declare mais champ titre, il sera peuple par le select *
2991
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre']:'';
2991
+			$champ_titre = (!empty($desc['titre'])) ? ', '.$desc['titre'] : '';
2992 2992
 		}
2993 2993
 		include_spip('base/abstract_sql');
2994 2994
 		include_spip('base/connect_sql');
@@ -3007,7 +3007,7 @@  discard block
 block discarded – undo
3007 3007
 		$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
3008 3008
 	// Sinon on prend directement le champ SQL tel quel
3009 3009
 	else
3010
-		$info_generee = (isset($objets[$type_objet][$id_objet][$info])?$objets[$type_objet][$id_objet][$info]:'');
3010
+		$info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
3011 3011
 
3012 3012
 	// On va ensuite chercher les traitements automatiques a faire
3013 3013
 	$champ = strtoupper($info);
@@ -3016,13 +3016,13 @@  discard block
 block discarded – undo
3016 3016
 
3017 3017
 	if (!$etoile
3018 3018
 		AND is_array($traitement)
3019
-	  AND (isset($traitement[$table_sql]) OR isset($traitement[0]))){
3019
+	  AND (isset($traitement[$table_sql]) OR isset($traitement[0]))) {
3020 3020
 	  	include_spip('inc/texte');
3021 3021
 		$traitement = $traitement[isset($traitement[$table_sql]) ? $table_sql : 0];
3022 3022
 		$traitement = str_replace('%s', "'".texte_script($info_generee)."'", $traitement);
3023 3023
 		// FIXME: $connect et $Pile[0] font souvent partie des traitements.
3024 3024
 		// on les definit pour eviter des notices, mais ce fonctionnement est a ameliorer !
3025
-		$connect = ""; $Pile = array(0 => array('id_objet'=>$id_objet,'objet'=>$type_objet));
3025
+		$connect = ""; $Pile = array(0 => array('id_objet'=>$id_objet, 'objet'=>$type_objet));
3026 3026
 		eval("\$info_generee = $traitement;");
3027 3027
 	}
3028 3028
 
@@ -3036,13 +3036,13 @@  discard block
 block discarded – undo
3036 3036
  * @param string $wrap
3037 3037
  * @return string
3038 3038
  */
3039
-function wrap($texte,$wrap) {
3039
+function wrap($texte, $wrap) {
3040 3040
 	$balises = extraire_balises($wrap);
3041
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS",$wrap, $regs, PREG_PATTERN_ORDER)) {
3042
-		$texte = $wrap . $texte;
3041
+	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
3042
+		$texte = $wrap.$texte;
3043 3043
 		$regs = array_reverse($regs[1]);
3044
-		$wrap = "</".implode("></",$regs).">";
3045
-		$texte = $texte . $wrap;
3044
+		$wrap = "</".implode("></", $regs).">";
3045
+		$texte = $texte.$wrap;
3046 3046
 	}
3047 3047
 	return $texte;
3048 3048
 }
@@ -3063,8 +3063,8 @@  discard block
 block discarded – undo
3063 3063
  * @param int $indent
3064 3064
  * @return array|mixed|string
3065 3065
  */
3066
-function filtre_print_dist($u, $join="<br />", $indent=0) {
3067
-	if (is_string($u)){
3066
+function filtre_print_dist($u, $join = "<br />", $indent = 0) {
3067
+	if (is_string($u)) {
3068 3068
 		$u = typo($u);
3069 3069
 		return $u;
3070 3070
 	}
@@ -3073,24 +3073,24 @@  discard block
 block discarded – undo
3073 3073
 	if (is_object($u))
3074 3074
 		$u = (array) $u;
3075 3075
 
3076
-	if (is_array($u)){
3076
+	if (is_array($u)) {
3077 3077
 		$out = "";
3078 3078
 		// toutes les cles sont numeriques ?
3079 3079
 		// et aucun enfant n'est un tableau
3080 3080
 		// liste simple separee par des virgules
3081
-		$numeric_keys = array_map('is_numeric',array_keys($u));
3082
-		$array_values = array_map('is_array',$u);
3083
-		$object_values = array_map('is_object',$u);
3084
-		if (array_sum($numeric_keys)==count($numeric_keys)
3081
+		$numeric_keys = array_map('is_numeric', array_keys($u));
3082
+		$array_values = array_map('is_array', $u);
3083
+		$object_values = array_map('is_object', $u);
3084
+		if (array_sum($numeric_keys) == count($numeric_keys)
3085 3085
 		  AND !array_sum($array_values)
3086
-		  AND !array_sum($object_values)){
3086
+		  AND !array_sum($object_values)) {
3087 3087
 			return join(", ", array_map('filtre_print_dist', $u));
3088 3088
 		}
3089 3089
 
3090 3090
 		// sinon on passe a la ligne et on indente
3091
-		$i_str = str_pad("",$indent," ");
3092
-		foreach($u as $k => $v){
3093
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v,$join,$indent+2);
3091
+		$i_str = str_pad("", $indent, " ");
3092
+		foreach ($u as $k => $v) {
3093
+			$out .= $join.$i_str."$k: ".filtre_print_dist($v, $join, $indent + 2);
3094 3094
 		}
3095 3095
 		return $out;
3096 3096
 	}
@@ -3108,10 +3108,10 @@  discard block
 block discarded – undo
3108 3108
  * @param string $info
3109 3109
  * @return string
3110 3110
  */
3111
-function objet_info($objet,$info){
3111
+function objet_info($objet, $info) {
3112 3112
 	$table = table_objet_sql($objet);
3113 3113
 	$infos = lister_tables_objets_sql($table);
3114
-	return (isset($infos[$info])?$infos[$info]:'');
3114
+	return (isset($infos[$info]) ? $infos[$info] : '');
3115 3115
 }
3116 3116
 
3117 3117
 /**
@@ -3121,11 +3121,11 @@  discard block
 block discarded – undo
3121 3121
  * @param  $objet
3122 3122
  * @return mixed|string
3123 3123
  */
3124
-function objet_afficher_nb($nb, $objet){
3124
+function objet_afficher_nb($nb, $objet) {
3125 3125
 	if (!$nb)
3126
-		return _T(objet_info($objet,'info_aucun_objet'));
3126
+		return _T(objet_info($objet, 'info_aucun_objet'));
3127 3127
 	else
3128
-		return _T(objet_info($objet,$nb==1?'info_1_objet':'info_nb_objets'),array('nb'=>$nb));
3128
+		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb'=>$nb));
3129 3129
 }
3130 3130
 
3131 3131
 /**
@@ -3135,11 +3135,11 @@  discard block
 block discarded – undo
3135 3135
  * @param int $taille
3136 3136
  * @return string
3137 3137
  */
3138
-function objet_icone($objet,$taille=24){
3139
-	$icone = objet_info($objet,'icone_objet')."-".$taille.".png";
3138
+function objet_icone($objet, $taille = 24) {
3139
+	$icone = objet_info($objet, 'icone_objet')."-".$taille.".png";
3140 3140
 	$icone = chemin_image($icone);
3141 3141
 	$balise_img = charger_filtre('balise_img');
3142
-	return $icone?$balise_img($icone,_T(objet_info($objet,'texte_objet'))):'';
3142
+	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet'))) : '';
3143 3143
 }
3144 3144
 
3145 3145
 /**
@@ -3152,13 +3152,13 @@  discard block
 block discarded – undo
3152 3152
  * @param string $flux Code HTML
3153 3153
  * @return string      Code HTML
3154 3154
  */
3155
-function insert_head_css_conditionnel($flux){
3156
-	if (strpos($flux,'<!-- insert_head_css -->')===false
3157
-		AND $p=strpos($flux,'<!-- insert_head -->')){
3155
+function insert_head_css_conditionnel($flux) {
3156
+	if (strpos($flux, '<!-- insert_head_css -->') === false
3157
+		AND $p = strpos($flux, '<!-- insert_head -->')) {
3158 3158
 		// plutot avant le premier js externe (jquery) pour etre non bloquant
3159
-		if ($p1 = stripos($flux,'<script src=') AND $p1<$p)
3159
+		if ($p1 = stripos($flux, '<script src=') AND $p1 < $p)
3160 3160
 			$p = $p1;
3161
-		$flux = substr_replace($flux,pipeline('insert_head_css','<!-- insert_head_css -->'),$p,0);
3161
+		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
3162 3162
 	}
3163 3163
 	return $flux;
3164 3164
 }
@@ -3177,24 +3177,24 @@  discard block
 block discarded – undo
3177 3177
  * @param string $connect
3178 3178
  * @return string
3179 3179
  */
3180
-function produire_fond_statique($fond, $contexte=array(), $options = array(), $connect=''){
3181
-	if (isset($contexte['format'])){
3180
+function produire_fond_statique($fond, $contexte = array(), $options = array(), $connect = '') {
3181
+	if (isset($contexte['format'])) {
3182 3182
 		$extension = $contexte['format'];
3183 3183
 		unset($contexte['format']);
3184 3184
 	}
3185 3185
 	else {
3186 3186
 		$extension = "html";
3187
-		if (preg_match(',[.](css|js|json)$,',$fond,$m))
3187
+		if (preg_match(',[.](css|js|json)$,', $fond, $m))
3188 3188
 			$extension = $m[1];
3189 3189
 	}
3190 3190
 	// recuperer le contenu produit par le squelette
3191 3191
 	$options['raw'] = true;
3192
-	$cache = recuperer_fond($fond,$contexte,$options,$connect);
3192
+	$cache = recuperer_fond($fond, $contexte, $options, $connect);
3193 3193
 	
3194 3194
 	// calculer le nom de la css
3195
-	$dir_var = sous_repertoire (_DIR_VAR, 'cache-'.$extension);
3196
-	$nom_safe = preg_replace(",\W,",'_',str_replace('.','_',$fond));
3197
-	$filename = $dir_var . $extension."dyn-$nom_safe-".substr(md5($fond.serialize($contexte).$connect),0,8) .".$extension";
3195
+	$dir_var = sous_repertoire(_DIR_VAR, 'cache-'.$extension);
3196
+	$nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
3197
+	$filename = $dir_var.$extension."dyn-$nom_safe-".substr(md5($fond.serialize($contexte).$connect), 0, 8).".$extension";
3198 3198
 
3199 3199
 	// mettre a jour le fichier si il n'existe pas
3200 3200
 	// ou trop ancien
@@ -3202,29 +3202,29 @@  discard block
 block discarded – undo
3202 3202
 	// et recopie sur le fichier cible uniquement si il change
3203 3203
 	if (!file_exists($filename)
3204 3204
 		OR !file_exists($filename.".last")
3205
-		OR (isset($cache['lastmodified']) AND $cache['lastmodified'] AND filemtime($filename.".last")<$cache['lastmodified'])
3206
-		OR (defined('_VAR_MODE') AND _VAR_MODE=='recalcul')) {
3205
+		OR (isset($cache['lastmodified']) AND $cache['lastmodified'] AND filemtime($filename.".last") < $cache['lastmodified'])
3206
+		OR (defined('_VAR_MODE') AND _VAR_MODE == 'recalcul')) {
3207 3207
 		$contenu = $cache['texte'];
3208 3208
 		// passer les urls en absolu si c'est une css
3209
-		if ($extension=="css")
3210
-			$contenu = urls_absolues_css($contenu, test_espace_prive()?generer_url_ecrire('accueil'):generer_url_public($fond));
3209
+		if ($extension == "css")
3210
+			$contenu = urls_absolues_css($contenu, test_espace_prive() ?generer_url_ecrire('accueil') : generer_url_public($fond));
3211 3211
 		
3212 3212
 		// ne pas insérer de commentaire si c'est du json
3213
-		if ($extension!="json") {
3213
+		if ($extension != "json") {
3214 3214
 			$comment = "/* #PRODUIRE{fond=$fond";
3215
-			foreach($contexte as $k=>$v)
3215
+			foreach ($contexte as $k=>$v)
3216 3216
 				$comment .= ",$k=$v";
3217 3217
 			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
3218 3218
 			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
3219
-			$comment .="}\n   md5:".md5($contenu)." */\n";
3219
+			$comment .= "}\n   md5:".md5($contenu)." */\n";
3220 3220
 		}
3221 3221
 		// et ecrire le fichier
3222
-		ecrire_fichier($filename.".last",$comment.$contenu);
3222
+		ecrire_fichier($filename.".last", $comment.$contenu);
3223 3223
 		// regarder si on recopie
3224 3224
 		if (!file_exists($filename)
3225
-		  OR md5_file($filename)!==md5_file($filename.".last")){
3226
-			@copy($filename.".last",$filename);
3227
-			spip_clearstatcache(true,$filename); // eviter que PHP ne reserve le vieux timestamp
3225
+		  OR md5_file($filename) !== md5_file($filename.".last")) {
3226
+			@copy($filename.".last", $filename);
3227
+			spip_clearstatcache(true, $filename); // eviter que PHP ne reserve le vieux timestamp
3228 3228
 		}
3229 3229
 	}
3230 3230
 	
@@ -3238,7 +3238,7 @@  discard block
 block discarded – undo
3238 3238
  * @param string $fichier
3239 3239
  * @return string
3240 3240
  */
3241
-function timestamp($fichier){
3241
+function timestamp($fichier) {
3242 3242
 	if (!$fichier OR !file_exists($fichier)) return $fichier;
3243 3243
 	$m = filemtime($fichier);
3244 3244
 	return "$fichier?$m";
@@ -3250,7 +3250,7 @@  discard block
 block discarded – undo
3250 3250
  * @param  $titre
3251 3251
  * @return mixed
3252 3252
  */
3253
-function filtre_nettoyer_titre_email_dist($titre){
3253
+function filtre_nettoyer_titre_email_dist($titre) {
3254 3254
 	include_spip('inc/envoyer_mail');
3255 3255
 	return nettoyer_titre_email($titre);
3256 3256
 }
@@ -3271,9 +3271,9 @@  discard block
 block discarded – undo
3271 3271
  * @param bool $retour_sans_cadre
3272 3272
  * @return string
3273 3273
  */
3274
-function filtre_chercher_rubrique_dist($titre,$id_objet, $id_parent, $objet, $id_secteur, $restreint,$actionable = false, $retour_sans_cadre=false){
3274
+function filtre_chercher_rubrique_dist($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable = false, $retour_sans_cadre = false) {
3275 3275
 	include_spip('inc/filtres_ecrire');
3276
-	return chercher_rubrique($titre,$id_objet, $id_parent, $objet, $id_secteur, $restreint,$actionable, $retour_sans_cadre);
3276
+	return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable, $retour_sans_cadre);
3277 3277
 }
3278 3278
 
3279 3279
 /**
@@ -3288,7 +3288,7 @@  discard block
 block discarded – undo
3288 3288
  * @param int $statut Statut HTML avec lequel on redirigera
3289 3289
  * @return string
3290 3290
  */
3291
-function sinon_interdire_acces($ok=false, $url='', $statut=0){
3291
+function sinon_interdire_acces($ok = false, $url = '', $statut = 0) {
3292 3292
 	if ($ok) return '';
3293 3293
 	
3294 3294
 	// Vider tous les tampons
@@ -3300,15 +3300,15 @@  discard block
 block discarded – undo
3300 3300
 	$statut = intval($statut);
3301 3301
 	
3302 3302
 	// Si aucun argument on essaye de deviner quoi faire par défaut
3303
-	if (!$url and !$statut){
3303
+	if (!$url and !$statut) {
3304 3304
 		// Si on est dans l'espace privé, on génère du 403 Forbidden
3305
-		if (test_espace_prive()){
3305
+		if (test_espace_prive()) {
3306 3306
 			http_status(403);
3307
-			$echec = charger_fonction('403','exec');
3307
+			$echec = charger_fonction('403', 'exec');
3308 3308
 			$echec();
3309 3309
 		}
3310 3310
 		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
3311
-		else{
3311
+		else {
3312 3312
 			$statut = 404;
3313 3313
 		}
3314 3314
 	}
@@ -3316,7 +3316,7 @@  discard block
 block discarded – undo
3316 3316
 	// On suit les directives indiquées dans les deux arguments
3317 3317
 	
3318 3318
 	// S'il y a un statut
3319
-	if ($statut){
3319
+	if ($statut) {
3320 3320
 		// Dans tous les cas on modifie l'entité avec ce qui est demandé
3321 3321
 		http_status($statut);
3322 3322
 		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
@@ -3336,7 +3336,7 @@  discard block
 block discarded – undo
3336 3336
  * @param null|string $format
3337 3337
  * @return string
3338 3338
  */
3339
-function filtre_compacte_dist($source, $format = null){
3339
+function filtre_compacte_dist($source, $format = null) {
3340 3340
 	if (function_exists('compacte'))
3341 3341
 		return compacte($source, $format);
3342 3342
 	return $source;
Please login to merge, or discard this patch.
ecrire/inc/filtres_images_lib_mini.php 4 patches
Doc Comments   +8 added lines, -3 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
  *
75 75
  * @param bool|string $stat
76 76
  * 		true, false ou le statut déjà défini si traitements enchaînés.
77
- * @return bool
77
+ * @return false|null
78 78
  * 		true si il faut supprimer le fichier temporaire ; false sinon.
79 79
  */
80 80
 function statut_effacer_images_temporaires($stat){
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
  * Crée un fichier_image temporaire .src ou vérifie que le fichier_image
473 473
  * définitif a bien été créé.
474 474
  *
475
- * @param ressource $img
475
+ * @param resource $img
476 476
  * 		Une ressource de type Image GD.
477 477
  * @param array $valeurs
478 478
  * 		Un tableau des informations (tailles, traitement, path...) accompagnant
@@ -943,6 +943,11 @@  discard block
 block discarded – undo
943 943
 }
944 944
 
945 945
 // http://doc.spip.org/@process_image_reduire
946
+/**
947
+ * @param boolean $force
948
+ * @param boolean $cherche_image
949
+ * @param string $process
950
+ */
946 951
 function process_image_reduire($fonction,$img,$taille,$taille_y,$force,$cherche_image,$process){
947 952
 	$image = false;
948 953
 	if (($process == 'AUTO') AND isset($GLOBALS['meta']['image_process']))
@@ -1070,7 +1075,7 @@  discard block
 block discarded – undo
1070 1075
 	}
1071 1076
 
1072 1077
 	/**
1073
-	 * @param array $gd_image_array
1078
+	 * @param ressource[] $gd_image_array
1074 1079
 	 * @return string
1075 1080
 	 */
1076 1081
 	public static function GD2ICOstring(&$gd_image_array) {
Please login to merge, or discard this patch.
Indentation   +842 added lines, -842 removed lines patch added patch discarded remove patch
@@ -35,15 +35,15 @@  discard block
 block discarded – undo
35 35
  * 		le code de la couleur en hexadécimal.
36 36
  */
37 37
 function _couleur_dec_to_hex($red, $green, $blue) {
38
-	$red = dechex($red);
39
-	$green = dechex($green);
40
-	$blue = dechex($blue);
38
+    $red = dechex($red);
39
+    $green = dechex($green);
40
+    $blue = dechex($blue);
41 41
 	
42
-	if (strlen($red) == 1) $red = "0".$red;
43
-	if (strlen($green) == 1) $green = "0".$green;
44
-	if (strlen($blue) == 1) $blue = "0".$blue;
42
+    if (strlen($red) == 1) $red = "0".$red;
43
+    if (strlen($green) == 1) $green = "0".$green;
44
+    if (strlen($blue) == 1) $blue = "0".$blue;
45 45
 	
46
-	return "$red$green$blue";
46
+    return "$red$green$blue";
47 47
 }
48 48
 
49 49
 /**
@@ -55,13 +55,13 @@  discard block
 block discarded – undo
55 55
  * 		Un tableau des 3 éléments : rouge, vert, bleu.
56 56
  */
57 57
 function _couleur_hex_to_dec($couleur) {
58
-	$couleur = couleur_html_to_hex($couleur);
59
-	$couleur = preg_replace(",^#,","",$couleur);
60
-	$retour["red"] = hexdec(substr($couleur, 0, 2));
61
-	$retour["green"] = hexdec(substr($couleur, 2, 2));
62
-	$retour["blue"] = hexdec(substr($couleur, 4, 2));
58
+    $couleur = couleur_html_to_hex($couleur);
59
+    $couleur = preg_replace(",^#,","",$couleur);
60
+    $retour["red"] = hexdec(substr($couleur, 0, 2));
61
+    $retour["green"] = hexdec(substr($couleur, 2, 2));
62
+    $retour["blue"] = hexdec(substr($couleur, 4, 2));
63 63
 	
64
-	return $retour;
64
+    return $retour;
65 65
 }
66 66
 
67 67
 
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
  * 		true si il faut supprimer le fichier temporaire ; false sinon.
79 79
  */
80 80
 function statut_effacer_images_temporaires($stat){
81
-	static $statut = false; // par defaut on grave toute les images
82
-	if ($stat==='get') return $statut;
83
-	$statut = $stat?true:false;
81
+    static $statut = false; // par defaut on grave toute les images
82
+    if ($stat==='get') return $statut;
83
+    $statut = $stat?true:false;
84 84
 }
85 85
 
86 86
 
@@ -116,189 +116,189 @@  discard block
 block discarded – undo
116 116
  * 		l'appel à la fonction pipeline image_preparer_filtre.
117 117
  */
118 118
 function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = NULL, $find_in_path = false) {
119
-	static $images_recalcul = array();
120
-	if (strlen($img)==0) return false;
121
-
122
-	$source = trim(extraire_attribut($img, 'src'));
123
-	if (strlen($source) < 1){
124
-		$source = $img;
125
-		$img = "<img src='$source' />";
126
-	}
127
-	# gerer img src="data:....base64"
128
-	else if (preg_match('@^data:image/(jpe?g|png|gif);base64,(.*)$@isS', $source, $regs)) {
129
-		$local = sous_repertoire(_DIR_VAR,'image-data').md5($regs[2]).'.'.str_replace('jpeg', 'jpg', $regs[1]);
130
-		if (!file_exists($local)) {
131
-			ecrire_fichier($local, base64_decode($regs[2]));
132
-		}
133
-		$source = $local;
134
-		$img = inserer_attribut($img, 'src', $source);
135
-		# eviter les mauvaises surprises lors de conversions de format
136
-		$img = inserer_attribut($img, 'width', '');
137
-		$img = inserer_attribut($img, 'height', '');
138
-	}
139
-
140
-	// les protocoles web prennent au moins 3 lettres
141
-	if (preg_match(';^(\w{3,7}://);', $source)){
142
-		include_spip('inc/distant');
143
-		$fichier = _DIR_RACINE . copie_locale($source);
144
-		if (!$fichier) return "";
145
-	}	else {
146
-		// enlever le timestamp eventuel
147
-		$source=preg_replace(',[?][0-9]+$,','',$source);
148
-		if (strpos($source,"?")!==false
149
-			AND strncmp($source,_DIR_IMG,strlen(_DIR_IMG))==0
150
-			AND file_exists($f=preg_replace(',[?].*$,','',$source))){
151
-			$source = $f;
152
-		}
153
-		$fichier = $source;
154
-	}
155
-
156
-	$terminaison_dest = "";
157
-	if (preg_match(",\.(gif|jpe?g|png)($|[?]),i", $fichier, $regs)) {
158
-		$terminaison = strtolower($regs[1]);
159
-		$terminaison_dest = $terminaison;
119
+    static $images_recalcul = array();
120
+    if (strlen($img)==0) return false;
121
+
122
+    $source = trim(extraire_attribut($img, 'src'));
123
+    if (strlen($source) < 1){
124
+        $source = $img;
125
+        $img = "<img src='$source' />";
126
+    }
127
+    # gerer img src="data:....base64"
128
+    else if (preg_match('@^data:image/(jpe?g|png|gif);base64,(.*)$@isS', $source, $regs)) {
129
+        $local = sous_repertoire(_DIR_VAR,'image-data').md5($regs[2]).'.'.str_replace('jpeg', 'jpg', $regs[1]);
130
+        if (!file_exists($local)) {
131
+            ecrire_fichier($local, base64_decode($regs[2]));
132
+        }
133
+        $source = $local;
134
+        $img = inserer_attribut($img, 'src', $source);
135
+        # eviter les mauvaises surprises lors de conversions de format
136
+        $img = inserer_attribut($img, 'width', '');
137
+        $img = inserer_attribut($img, 'height', '');
138
+    }
139
+
140
+    // les protocoles web prennent au moins 3 lettres
141
+    if (preg_match(';^(\w{3,7}://);', $source)){
142
+        include_spip('inc/distant');
143
+        $fichier = _DIR_RACINE . copie_locale($source);
144
+        if (!$fichier) return "";
145
+    }	else {
146
+        // enlever le timestamp eventuel
147
+        $source=preg_replace(',[?][0-9]+$,','',$source);
148
+        if (strpos($source,"?")!==false
149
+            AND strncmp($source,_DIR_IMG,strlen(_DIR_IMG))==0
150
+            AND file_exists($f=preg_replace(',[?].*$,','',$source))){
151
+            $source = $f;
152
+        }
153
+        $fichier = $source;
154
+    }
155
+
156
+    $terminaison_dest = "";
157
+    if (preg_match(",\.(gif|jpe?g|png)($|[?]),i", $fichier, $regs)) {
158
+        $terminaison = strtolower($regs[1]);
159
+        $terminaison_dest = $terminaison;
160 160
 		
161
-		if ($terminaison == "gif") $terminaison_dest = "png";
162
-	}
163
-	if ($forcer_format!==false) $terminaison_dest = $forcer_format;
164
-
165
-	if (!$terminaison_dest) return false;
166
-
167
-	$term_fonction = $terminaison;
168
-	if ($term_fonction == "jpg") $term_fonction = "jpeg";
169
-
170
-	$nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
171
-	$fichier_dest = $nom_fichier;
172
-	if (($find_in_path AND $f=find_in_path($fichier) AND $fichier=$f)
173
-		OR @file_exists($f = $fichier)){
174
-		// on passe la balise img a taille image qui exraira les attributs si possible
175
-		// au lieu de faire un acces disque sur le fichier
176
-		list ($ret["hauteur"],$ret["largeur"]) = taille_image($find_in_path?$f:$img);
177
-		$date_src = @filemtime($f);
178
-	}
179
-	elseif (@file_exists($f = "$fichier.src")
180
-		AND lire_fichier($f,$valeurs)
181
-		AND $valeurs=unserialize($valeurs)
182
-		AND isset($valeurs["hauteur_dest"])
183
-		AND isset($valeurs["largeur_dest"])) {
184
-		$ret["hauteur"] = $valeurs["hauteur_dest"];
185
-		$ret["largeur"] = $valeurs["largeur_dest"];
186
-		$date_src = $valeurs["date"];
187
-	}
188
-	// pas de fichier source par la
189
-	else
190
-		return false;
191
-
192
-	// pas de taille mesurable
193
-	if (!($ret["hauteur"] OR $ret["largeur"]))
194
-		return false;
161
+        if ($terminaison == "gif") $terminaison_dest = "png";
162
+    }
163
+    if ($forcer_format!==false) $terminaison_dest = $forcer_format;
164
+
165
+    if (!$terminaison_dest) return false;
166
+
167
+    $term_fonction = $terminaison;
168
+    if ($term_fonction == "jpg") $term_fonction = "jpeg";
169
+
170
+    $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
171
+    $fichier_dest = $nom_fichier;
172
+    if (($find_in_path AND $f=find_in_path($fichier) AND $fichier=$f)
173
+        OR @file_exists($f = $fichier)){
174
+        // on passe la balise img a taille image qui exraira les attributs si possible
175
+        // au lieu de faire un acces disque sur le fichier
176
+        list ($ret["hauteur"],$ret["largeur"]) = taille_image($find_in_path?$f:$img);
177
+        $date_src = @filemtime($f);
178
+    }
179
+    elseif (@file_exists($f = "$fichier.src")
180
+        AND lire_fichier($f,$valeurs)
181
+        AND $valeurs=unserialize($valeurs)
182
+        AND isset($valeurs["hauteur_dest"])
183
+        AND isset($valeurs["largeur_dest"])) {
184
+        $ret["hauteur"] = $valeurs["hauteur_dest"];
185
+        $ret["largeur"] = $valeurs["largeur_dest"];
186
+        $date_src = $valeurs["date"];
187
+    }
188
+    // pas de fichier source par la
189
+    else
190
+        return false;
191
+
192
+    // pas de taille mesurable
193
+    if (!($ret["hauteur"] OR $ret["largeur"]))
194
+        return false;
195 195
 		
196 196
 
197
-	// cas general :
198
-	// on a un dossier cache commun et un nom de fichier qui varie avec l'effet
199
-	// cas particulier de reduire :
200
-	// un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
201
-	$cache = "cache-gd2";
202
-	if (substr($effet,0,7)=='reduire') {
203
-		list(,$maxWidth,$maxHeight) = explode('-',$effet);
204
-		list ($destWidth,$destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
205
-		$ret['largeur_dest'] = $destWidth;
206
-		$ret['hauteur_dest'] = $destHeight;
207
-		$effet = "L{$destWidth}xH$destHeight";
208
-		$cache = "cache-vignettes";
209
-		$fichier_dest = basename($fichier_dest);
210
-		if (($ret['largeur']<=$maxWidth)&&($ret['hauteur']<=$maxHeight)){
211
-			// on garde la terminaison initiale car image simplement copiee
212
-			// et on postfixe son nom avec un md5 du path
213
-			$terminaison_dest = $terminaison;
214
-			$fichier_dest .= '-'.substr(md5("$fichier"),0,5);
215
-		}
216
-		else
217
-			$fichier_dest .= '-'.substr(md5("$fichier-$effet"),0,5);
218
-		$cache = sous_repertoire(_DIR_VAR, $cache);
219
-		$cache = sous_repertoire($cache, $effet);
220
-		# cherche un cache existant
221
-		/*foreach (array('gif','jpg','png') as $fmt)
197
+    // cas general :
198
+    // on a un dossier cache commun et un nom de fichier qui varie avec l'effet
199
+    // cas particulier de reduire :
200
+    // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
201
+    $cache = "cache-gd2";
202
+    if (substr($effet,0,7)=='reduire') {
203
+        list(,$maxWidth,$maxHeight) = explode('-',$effet);
204
+        list ($destWidth,$destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
205
+        $ret['largeur_dest'] = $destWidth;
206
+        $ret['hauteur_dest'] = $destHeight;
207
+        $effet = "L{$destWidth}xH$destHeight";
208
+        $cache = "cache-vignettes";
209
+        $fichier_dest = basename($fichier_dest);
210
+        if (($ret['largeur']<=$maxWidth)&&($ret['hauteur']<=$maxHeight)){
211
+            // on garde la terminaison initiale car image simplement copiee
212
+            // et on postfixe son nom avec un md5 du path
213
+            $terminaison_dest = $terminaison;
214
+            $fichier_dest .= '-'.substr(md5("$fichier"),0,5);
215
+        }
216
+        else
217
+            $fichier_dest .= '-'.substr(md5("$fichier-$effet"),0,5);
218
+        $cache = sous_repertoire(_DIR_VAR, $cache);
219
+        $cache = sous_repertoire($cache, $effet);
220
+        # cherche un cache existant
221
+        /*foreach (array('gif','jpg','png') as $fmt)
222 222
 			if (@file_exists($cache . $fichier_dest . '.' . $fmt)) {
223 223
 				$terminaison_dest = $fmt;
224 224
 			}*/
225
-	}
226
-	else 	{
227
-		$fichier_dest = md5("$fichier-$effet");
228
-		$cache = sous_repertoire(_DIR_VAR, $cache);
229
-	}
225
+    }
226
+    else 	{
227
+        $fichier_dest = md5("$fichier-$effet");
228
+        $cache = sous_repertoire(_DIR_VAR, $cache);
229
+    }
230 230
 	
231
-	$fichier_dest = $cache . $fichier_dest . "." .$terminaison_dest;
231
+    $fichier_dest = $cache . $fichier_dest . "." .$terminaison_dest;
232 232
 	
233
-	$GLOBALS["images_calculees"][] =  $fichier_dest;
234
-
235
-	$creer = true;
236
-	// si recalcul des images demande, recalculer chaque image une fois
237
-	if (defined('_VAR_IMAGES') AND _VAR_IMAGES AND !isset($images_recalcul[$fichier_dest])){
238
-		$images_recalcul[$fichier_dest] = true;
239
-	}
240
-	else {
241
-		if (@file_exists($f = $fichier_dest)){
242
-			if (filemtime($f)>=$date_src)
243
-				$creer = false;
244
-		}
245
-		else if (@file_exists($f = "$fichier_dest.src")
246
-		  AND lire_fichier($f,$valeurs)
247
-		  AND $valeurs=unserialize($valeurs)
248
-			AND $valeurs["date"]>=$date_src)
249
-				$creer = false;
250
-	}
251
-	if ($creer) {
252
-		if (!@file_exists($fichier)) {
253
-			if (!@file_exists("$fichier.src")) {
254
-				spip_log("Image absente : $fichier");
255
-				return false;
256
-			}
257
-			# on reconstruit l'image source absente a partir de la chaine des .src
258
-			reconstruire_image_intermediaire($fichier);
259
-		}
260
-	}
261
-
262
-	if ($creer)
263
-		spip_log("filtre image ".($fonction_creation?reset($fonction_creation):'')."[$effet] sur $fichier","images"._LOG_DEBUG);
264
-
265
-	// TODO: si une image png est nommee .jpg, le reconnaitre avec le bon $f
266
-	$ret["fonction_imagecreatefrom"] = "_imagecreatefrom".$term_fonction;
267
-	$ret["fichier"] = $fichier;
268
-	$ret["fonction_image"] = "_image_image".$terminaison_dest;
269
-	$ret["fichier_dest"] = $fichier_dest;
270
-	$ret["format_source"] = ($terminaison != 'jpeg' ? $terminaison : 'jpg');
271
-	$ret["format_dest"] = $terminaison_dest;
272
-	$ret["date_src"] = $date_src;
273
-	$ret["creer"] = $creer;
274
-	$ret["class"] = extraire_attribut($img, 'class');
275
-	$ret["alt"] = extraire_attribut($img, 'alt');
276
-	$ret["style"] = extraire_attribut($img, 'style');
277
-	$ret["tag"] = $img;
278
-	if ($fonction_creation){
279
-		$ret["reconstruction"] = $fonction_creation;
280
-		# ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement 
281
-		# cas de image_reduire qui finalement ne reduit pas l'image source
282
-		# ca evite d'essayer de le creer au prochain hit si il n'est pas la
283
-		#ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
284
-	}
285
-
286
-	$ret = pipeline('image_preparer_filtre',array(
287
-			'args'=>array(
288
-				'img'=>$img,
289
-				'effet'=>$effet,
290
-				'forcer_format'=>$forcer_format,
291
-				'fonction_creation'=>$fonction_creation,
292
-				'find_in_path'=>$find_in_path,
293
-			),
294
-			'data'=>$ret)
295
-	);
296
-
297
-	// une globale pour le debug en cas de crash memoire
298
-	$GLOBALS["derniere_image_calculee"] = $ret;
299
-
300
-	if (!function_exists($ret["fonction_imagecreatefrom"])) return false;
301
-	return $ret;
233
+    $GLOBALS["images_calculees"][] =  $fichier_dest;
234
+
235
+    $creer = true;
236
+    // si recalcul des images demande, recalculer chaque image une fois
237
+    if (defined('_VAR_IMAGES') AND _VAR_IMAGES AND !isset($images_recalcul[$fichier_dest])){
238
+        $images_recalcul[$fichier_dest] = true;
239
+    }
240
+    else {
241
+        if (@file_exists($f = $fichier_dest)){
242
+            if (filemtime($f)>=$date_src)
243
+                $creer = false;
244
+        }
245
+        else if (@file_exists($f = "$fichier_dest.src")
246
+          AND lire_fichier($f,$valeurs)
247
+          AND $valeurs=unserialize($valeurs)
248
+            AND $valeurs["date"]>=$date_src)
249
+                $creer = false;
250
+    }
251
+    if ($creer) {
252
+        if (!@file_exists($fichier)) {
253
+            if (!@file_exists("$fichier.src")) {
254
+                spip_log("Image absente : $fichier");
255
+                return false;
256
+            }
257
+            # on reconstruit l'image source absente a partir de la chaine des .src
258
+            reconstruire_image_intermediaire($fichier);
259
+        }
260
+    }
261
+
262
+    if ($creer)
263
+        spip_log("filtre image ".($fonction_creation?reset($fonction_creation):'')."[$effet] sur $fichier","images"._LOG_DEBUG);
264
+
265
+    // TODO: si une image png est nommee .jpg, le reconnaitre avec le bon $f
266
+    $ret["fonction_imagecreatefrom"] = "_imagecreatefrom".$term_fonction;
267
+    $ret["fichier"] = $fichier;
268
+    $ret["fonction_image"] = "_image_image".$terminaison_dest;
269
+    $ret["fichier_dest"] = $fichier_dest;
270
+    $ret["format_source"] = ($terminaison != 'jpeg' ? $terminaison : 'jpg');
271
+    $ret["format_dest"] = $terminaison_dest;
272
+    $ret["date_src"] = $date_src;
273
+    $ret["creer"] = $creer;
274
+    $ret["class"] = extraire_attribut($img, 'class');
275
+    $ret["alt"] = extraire_attribut($img, 'alt');
276
+    $ret["style"] = extraire_attribut($img, 'style');
277
+    $ret["tag"] = $img;
278
+    if ($fonction_creation){
279
+        $ret["reconstruction"] = $fonction_creation;
280
+        # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement 
281
+        # cas de image_reduire qui finalement ne reduit pas l'image source
282
+        # ca evite d'essayer de le creer au prochain hit si il n'est pas la
283
+        #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
284
+    }
285
+
286
+    $ret = pipeline('image_preparer_filtre',array(
287
+            'args'=>array(
288
+                'img'=>$img,
289
+                'effet'=>$effet,
290
+                'forcer_format'=>$forcer_format,
291
+                'fonction_creation'=>$fonction_creation,
292
+                'find_in_path'=>$find_in_path,
293
+            ),
294
+            'data'=>$ret)
295
+    );
296
+
297
+    // une globale pour le debug en cas de crash memoire
298
+    $GLOBALS["derniere_image_calculee"] = $ret;
299
+
300
+    if (!function_exists($ret["fonction_imagecreatefrom"])) return false;
301
+    return $ret;
302 302
 }
303 303
 
304 304
 /**
@@ -312,13 +312,13 @@  discard block
 block discarded – undo
312 312
  * 		Une ressource de type Image GD.
313 313
  */
314 314
 function _imagecreatefromjpeg($filename){
315
-	$img = @imagecreatefromjpeg($filename);
316
-	if (!$img) {
317
-		spip_log("Erreur lecture imagecreatefromjpeg $filename",_LOG_CRITIQUE);
318
-		erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
319
-		$img = imagecreate(10,10);
320
-	}
321
-	return $img;
315
+    $img = @imagecreatefromjpeg($filename);
316
+    if (!$img) {
317
+        spip_log("Erreur lecture imagecreatefromjpeg $filename",_LOG_CRITIQUE);
318
+        erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
319
+        $img = imagecreate(10,10);
320
+    }
321
+    return $img;
322 322
 }
323 323
 
324 324
 /**
@@ -332,13 +332,13 @@  discard block
 block discarded – undo
332 332
  * 		Une ressource de type Image GD.
333 333
  */
334 334
 function _imagecreatefrompng($filename){
335
-	$img = @imagecreatefrompng($filename);
336
-	if (!$img) {
337
-		spip_log("Erreur lecture imagecreatefrompng $filename",_LOG_CRITIQUE);
338
-		erreur_squelette("Erreur lecture imagecreatefrompng $filename");
339
-		$img = imagecreate(10,10);
340
-	}
341
-	return $img;
335
+    $img = @imagecreatefrompng($filename);
336
+    if (!$img) {
337
+        spip_log("Erreur lecture imagecreatefrompng $filename",_LOG_CRITIQUE);
338
+        erreur_squelette("Erreur lecture imagecreatefrompng $filename");
339
+        $img = imagecreate(10,10);
340
+    }
341
+    return $img;
342 342
 }
343 343
 
344 344
 /**
@@ -352,13 +352,13 @@  discard block
 block discarded – undo
352 352
  * 		Une ressource de type Image GD.
353 353
  */
354 354
 function _imagecreatefromgif($filename){
355
-	$img = @imagecreatefromgif($filename);
356
-	if (!$img) {
357
-		spip_log("Erreur lecture imagecreatefromgif $filename",_LOG_CRITIQUE);
358
-		erreur_squelette("Erreur lecture imagecreatefromgif $filename");
359
-		$img = imagecreate(10,10);
360
-	}
361
-	return $img;
355
+    $img = @imagecreatefromgif($filename);
356
+    if (!$img) {
357
+        spip_log("Erreur lecture imagecreatefromgif $filename",_LOG_CRITIQUE);
358
+        erreur_squelette("Erreur lecture imagecreatefromgif $filename");
359
+        $img = imagecreate(10,10);
360
+    }
361
+    return $img;
362 362
 }
363 363
 
364 364
 /**
@@ -374,19 +374,19 @@  discard block
 block discarded – undo
374 374
  * 		true si une image est bien retournée.
375 375
  */
376 376
 function _image_imagepng($img, $fichier) {
377
-	if (!function_exists('imagepng')) return false;
378
-	$tmp = $fichier.".tmp";
379
-	$ret = imagepng($img,$tmp);
377
+    if (!function_exists('imagepng')) return false;
378
+    $tmp = $fichier.".tmp";
379
+    $ret = imagepng($img,$tmp);
380 380
 	
381
-	if(file_exists($tmp)){
382
-		$taille_test = getimagesize($tmp);
383
-		if ($taille_test[0] < 1) return false;
381
+    if(file_exists($tmp)){
382
+        $taille_test = getimagesize($tmp);
383
+        if ($taille_test[0] < 1) return false;
384 384
 	
385
-		spip_unlink($fichier); // le fichier peut deja exister
386
-		@rename($tmp, $fichier);
387
-		return $ret;
388
-	}
389
-	return false;
385
+        spip_unlink($fichier); // le fichier peut deja exister
386
+        @rename($tmp, $fichier);
387
+        return $ret;
388
+    }
389
+    return false;
390 390
 }
391 391
 
392 392
 /**
@@ -402,19 +402,19 @@  discard block
 block discarded – undo
402 402
  * 		true si une image est bien retournée.
403 403
  */
404 404
 function _image_imagegif($img,$fichier) {
405
-	if  (!function_exists('imagegif')) return false;
406
-	$tmp = $fichier.".tmp";
407
-	$ret = imagegif($img,$tmp);
405
+    if  (!function_exists('imagegif')) return false;
406
+    $tmp = $fichier.".tmp";
407
+    $ret = imagegif($img,$tmp);
408 408
 	
409
-	if(file_exists($tmp)){
410
-		$taille_test = getimagesize($tmp);
411
-		if ($taille_test[0] < 1) return false;
412
-
413
-		spip_unlink($fichier); // le fichier peut deja exister
414
-		@rename($tmp, $fichier);
415
-		return $ret;
416
-	}
417
-	return false;
409
+    if(file_exists($tmp)){
410
+        $taille_test = getimagesize($tmp);
411
+        if ($taille_test[0] < 1) return false;
412
+
413
+        spip_unlink($fichier); // le fichier peut deja exister
414
+        @rename($tmp, $fichier);
415
+        return $ret;
416
+    }
417
+    return false;
418 418
 }
419 419
 
420 420
 /**
@@ -435,19 +435,19 @@  discard block
 block discarded – undo
435 435
  * 		true si une image est bien retournée.
436 436
  */
437 437
 function _image_imagejpg($img,$fichier,$qualite=_IMG_GD_QUALITE) {
438
-	if (!function_exists('imagejpeg')) return false;
439
-	$tmp = $fichier.".tmp";
440
-	$ret = imagejpeg($img,$tmp, $qualite);
438
+    if (!function_exists('imagejpeg')) return false;
439
+    $tmp = $fichier.".tmp";
440
+    $ret = imagejpeg($img,$tmp, $qualite);
441 441
 	
442
-	if(file_exists($tmp)){
443
-		$taille_test = getimagesize($tmp);
444
-		if ($taille_test[0] < 1) return false;
442
+    if(file_exists($tmp)){
443
+        $taille_test = getimagesize($tmp);
444
+        if ($taille_test[0] < 1) return false;
445 445
 	
446
-		spip_unlink($fichier); // le fichier peut deja exister
447
-		@rename($tmp, $fichier);
448
-		return $ret;
449
-	}
450
-	return false;
446
+        spip_unlink($fichier); // le fichier peut deja exister
447
+        @rename($tmp, $fichier);
448
+        return $ret;
449
+    }
450
+    return false;
451 451
 }
452 452
 
453 453
 /**
@@ -462,9 +462,9 @@  discard block
 block discarded – undo
462 462
  * 		true si le fichier a bien été créé ; false sinon.
463 463
  */
464 464
 function _image_imageico($img, $fichier) {
465
-	$gd_image_array = array($img);
465
+    $gd_image_array = array($img);
466 466
 
467
-	return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
467
+    return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
468 468
 }
469 469
 
470 470
 /**
@@ -488,49 +488,49 @@  discard block
 block discarded – undo
488 488
  * 		false sinon.
489 489
  */
490 490
 function _image_gd_output($img,$valeurs, $qualite=_IMG_GD_QUALITE){
491
-	$fonction = "_image_image".$valeurs['format_dest'];
492
-	$ret = false;
493
-	#un flag pour reperer les images gravees
494
-	$lock = 
495
-		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
496
-	  OR (@file_exists($valeurs['fichier_dest']) AND !@file_exists($valeurs['fichier_dest'].'.src'));
497
-	if (
498
-	     function_exists($fonction) 
499
-			  && ($ret = $fonction($img,$valeurs['fichier_dest'],$qualite)) # on a reussi a creer l'image
500
-			  && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
501
-			  && !$lock
502
-	  )
503
-		if (@file_exists($valeurs['fichier_dest'])){
504
-			// dans tous les cas mettre a jour la taille de l'image finale
505
-			list ($valeurs["hauteur_dest"],$valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']);
506
-			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
507
-			ecrire_fichier($valeurs['fichier_dest'].'.src',serialize($valeurs),true);
508
-		}
509
-	return $ret;
491
+    $fonction = "_image_image".$valeurs['format_dest'];
492
+    $ret = false;
493
+    #un flag pour reperer les images gravees
494
+    $lock = 
495
+        !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
496
+      OR (@file_exists($valeurs['fichier_dest']) AND !@file_exists($valeurs['fichier_dest'].'.src'));
497
+    if (
498
+            function_exists($fonction) 
499
+              && ($ret = $fonction($img,$valeurs['fichier_dest'],$qualite)) # on a reussi a creer l'image
500
+              && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
501
+              && !$lock
502
+        )
503
+        if (@file_exists($valeurs['fichier_dest'])){
504
+            // dans tous les cas mettre a jour la taille de l'image finale
505
+            list ($valeurs["hauteur_dest"],$valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']);
506
+            $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
507
+            ecrire_fichier($valeurs['fichier_dest'].'.src',serialize($valeurs),true);
508
+        }
509
+    return $ret;
510 510
 }
511 511
 
512 512
 // http://doc.spip.org/@reconstruire_image_intermediaire
513 513
 function reconstruire_image_intermediaire($fichier_manquant){
514
-	$reconstruire = array();
515
-	$fichier = $fichier_manquant;
516
-	while (strpos($fichier,"://")===false
517
-		and !@file_exists($fichier)
518
-		AND lire_fichier($src = "$fichier.src",$source)
519
-		AND $valeurs=unserialize($source)
514
+    $reconstruire = array();
515
+    $fichier = $fichier_manquant;
516
+    while (strpos($fichier,"://")===false
517
+        and !@file_exists($fichier)
518
+        AND lire_fichier($src = "$fichier.src",$source)
519
+        AND $valeurs=unserialize($source)
520 520
     AND ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
521 521
     ) {
522
-			spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
523
-			$reconstruire[] = $valeurs['reconstruction'];
524
-   }
525
-	while (count($reconstruire)){
526
-		$r = array_pop($reconstruire);
527
-		$fonction = $r[0];
528
-		$args = $r[1];
529
-		call_user_func_array($fonction, $args);
530
-	}
531
-	// cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
532
-	// mais l'on peut nettoyer les miettes de sa creation
533
-	ramasse_miettes($fichier_manquant);
522
+            spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
523
+            $reconstruire[] = $valeurs['reconstruction'];
524
+    }
525
+    while (count($reconstruire)){
526
+        $r = array_pop($reconstruire);
527
+        $fonction = $r[0];
528
+        $args = $r[1];
529
+        call_user_func_array($fonction, $args);
530
+    }
531
+    // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
532
+    // mais l'on peut nettoyer les miettes de sa creation
533
+    ramasse_miettes($fichier_manquant);
534 534
 }
535 535
 
536 536
 /**
@@ -550,44 +550,44 @@  discard block
 block discarded – undo
550 550
  *     Chemin du fichier d'image calculé
551 551
  **/
552 552
 function ramasse_miettes($fichier) {
553
-	if (strpos($fichier,"://")!==false
554
-		or !lire_fichier($src = "$fichier.src", $source)
555
-		or !$valeurs = unserialize($source)
556
-	) {
557
-		return;
558
-	}
559
-	spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
560
-	while (
561
-	     ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
562
-		AND (substr($fichier,0,strlen(_DIR_VAR))==_DIR_VAR) # et est dans local
563
-		AND (lire_fichier($src = "$fichier.src",$source)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
564
-		AND ($valeurs=unserialize($source))  # et valide
565
-		) {
566
-		# on efface le fichier
567
-		spip_unlink($fichier);
568
-		# mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
569
-		#spip_unlink($src);
570
-	}
553
+    if (strpos($fichier,"://")!==false
554
+        or !lire_fichier($src = "$fichier.src", $source)
555
+        or !$valeurs = unserialize($source)
556
+    ) {
557
+        return;
558
+    }
559
+    spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
560
+    while (
561
+            ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
562
+        AND (substr($fichier,0,strlen(_DIR_VAR))==_DIR_VAR) # et est dans local
563
+        AND (lire_fichier($src = "$fichier.src",$source)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
564
+        AND ($valeurs=unserialize($source))  # et valide
565
+        ) {
566
+        # on efface le fichier
567
+        spip_unlink($fichier);
568
+        # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
569
+        #spip_unlink($src);
570
+    }
571 571
 }
572 572
 
573 573
 // http://doc.spip.org/@image_graver
574 574
 function image_graver($img){
575
-	// appeler le filtre post_image_filtrer qui permet de faire
576
-	// des traitements auto a la fin d'une serie de filtres
577
-	$img = pipeline('post_image_filtrer',$img);
578
-
579
-	$fichier = extraire_attribut($img, 'src');
580
-	if (($p=strpos($fichier,'?'))!==FALSE)
581
-		$fichier=substr($fichier,0,$p);
582
-	if (strlen($fichier) < 1)
583
-		$fichier = $img;
584
-	# si jamais le fichier final n'a pas ete calcule car suppose temporaire
585
-	# et qu'il ne s'agit pas d'une URL
586
-	if (strpos($fichier,"://")===false and !@file_exists($fichier)) {
587
-		reconstruire_image_intermediaire($fichier);
588
-	}
589
-	ramasse_miettes($fichier);
590
-	return $img; // on ne change rien
575
+    // appeler le filtre post_image_filtrer qui permet de faire
576
+    // des traitements auto a la fin d'une serie de filtres
577
+    $img = pipeline('post_image_filtrer',$img);
578
+
579
+    $fichier = extraire_attribut($img, 'src');
580
+    if (($p=strpos($fichier,'?'))!==FALSE)
581
+        $fichier=substr($fichier,0,$p);
582
+    if (strlen($fichier) < 1)
583
+        $fichier = $img;
584
+    # si jamais le fichier final n'a pas ete calcule car suppose temporaire
585
+    # et qu'il ne s'agit pas d'une URL
586
+    if (strpos($fichier,"://")===false and !@file_exists($fichier)) {
587
+        reconstruire_image_intermediaire($fichier);
588
+    }
589
+    ramasse_miettes($fichier);
590
+    return $img; // on ne change rien
591 591
 }
592 592
 
593 593
 // Transforme une image a palette indexee (256 couleurs max) en "vraies" couleurs RGB
@@ -595,441 +595,441 @@  discard block
 block discarded – undo
595 595
 // http://doc.spip.org/@imagepalettetotruecolor
596 596
 if (!function_exists("imagepalettetotruecolor")) {
597 597
 function imagepalettetotruecolor(&$img) {
598
-	if ($img AND !imageistruecolor($img) AND function_exists('imagecreatetruecolor')) {
599
-		$w = imagesx($img);
600
-		$h = imagesy($img);
601
-		$img1 = imagecreatetruecolor($w,$h);
602
-		//Conserver la transparence si possible
603
-		if(function_exists('ImageCopyResampled')) {
604
-			if (function_exists("imageAntiAlias")) imageAntiAlias($img1,true); 
605
-			@imagealphablending($img1, false); 
606
-			@imagesavealpha($img1,true); 
607
-			@ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
608
-		} else {
609
-			imagecopy($img1,$img,0,0,0,0,$w,$h);
610
-		}
611
-
612
-		$img = $img1;
613
-	}
598
+    if ($img AND !imageistruecolor($img) AND function_exists('imagecreatetruecolor')) {
599
+        $w = imagesx($img);
600
+        $h = imagesy($img);
601
+        $img1 = imagecreatetruecolor($w,$h);
602
+        //Conserver la transparence si possible
603
+        if(function_exists('ImageCopyResampled')) {
604
+            if (function_exists("imageAntiAlias")) imageAntiAlias($img1,true); 
605
+            @imagealphablending($img1, false); 
606
+            @imagesavealpha($img1,true); 
607
+            @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
608
+        } else {
609
+            imagecopy($img1,$img,0,0,0,0,$w,$h);
610
+        }
611
+
612
+        $img = $img1;
613
+    }
614 614
 }
615 615
 }
616 616
 
617 617
 // http://doc.spip.org/@image_tag_changer_taille
618 618
 function _image_tag_changer_taille($tag,$width,$height,$style=false){
619
-	if ($style===false) $style = extraire_attribut($tag,'style');
620
-	// enlever le width et height du style
621
-	$style = preg_replace(",(^|;)\s*(width|height)\s*:\s*[^;]+,ims","",$style);
622
-	if ($style AND $style{0}==';') $style=substr($style,1);
623
-	// mettre des attributs de width et height sur les images, 
624
-	// ca accelere le rendu du navigateur
625
-	// ca permet aux navigateurs de reserver la bonne taille 
626
-	// quand on a desactive l'affichage des images.
627
-	$tag = inserer_attribut($tag,'width',$width);
628
-	$tag = inserer_attribut($tag,'height',$height);
619
+    if ($style===false) $style = extraire_attribut($tag,'style');
620
+    // enlever le width et height du style
621
+    $style = preg_replace(",(^|;)\s*(width|height)\s*:\s*[^;]+,ims","",$style);
622
+    if ($style AND $style{0}==';') $style=substr($style,1);
623
+    // mettre des attributs de width et height sur les images, 
624
+    // ca accelere le rendu du navigateur
625
+    // ca permet aux navigateurs de reserver la bonne taille 
626
+    // quand on a desactive l'affichage des images.
627
+    $tag = inserer_attribut($tag,'width',$width);
628
+    $tag = inserer_attribut($tag,'height',$height);
629 629
 	
630
-	// Ancien style inline pour IE6 mais qui casse la possibilité de surcharger en CSS
631
-	//$style = "height:".$height."px;width:".$width."px;".$style;
630
+    // Ancien style inline pour IE6 mais qui casse la possibilité de surcharger en CSS
631
+    //$style = "height:".$height."px;width:".$width."px;".$style;
632 632
 	
633
-	// attributs deprecies. Transformer en CSS
634
-	if ($espace = extraire_attribut($tag, 'hspace')){
635
-		$style = "margin:${espace}px;".$style;
636
-		$tag = inserer_attribut($tag,'hspace','');
637
-	}
638
-	$tag = inserer_attribut($tag,'style',$style, true, $style ? false : true);
639
-	return $tag;
633
+    // attributs deprecies. Transformer en CSS
634
+    if ($espace = extraire_attribut($tag, 'hspace')){
635
+        $style = "margin:${espace}px;".$style;
636
+        $tag = inserer_attribut($tag,'hspace','');
637
+    }
638
+    $tag = inserer_attribut($tag,'style',$style, true, $style ? false : true);
639
+    return $tag;
640 640
 }
641 641
 
642 642
 // function d'ecriture du de la balise img en sortie des filtre image
643 643
 // reprend le tag initial et surcharge les tags modifies
644 644
 function _image_ecrire_tag($valeurs,$surcharge=array()){
645
-	$valeurs = pipeline('image_ecrire_tag_preparer',$valeurs);
645
+    $valeurs = pipeline('image_ecrire_tag_preparer',$valeurs);
646 646
 
647
-	$tag = 	str_replace(">","/>",str_replace("/>",">",$valeurs['tag'])); // fermer les tags img pas bien fermes;
647
+    $tag = 	str_replace(">","/>",str_replace("/>",">",$valeurs['tag'])); // fermer les tags img pas bien fermes;
648 648
 	
649
-	// le style
650
-	$style = $valeurs['style'];
651
-	if (isset($surcharge['style'])){
652
-		$style = $surcharge['style'];
653
-		unset($surcharge['style']);
654
-	}
649
+    // le style
650
+    $style = $valeurs['style'];
651
+    if (isset($surcharge['style'])){
652
+        $style = $surcharge['style'];
653
+        unset($surcharge['style']);
654
+    }
655 655
 	
656
-	// traiter specifiquement la largeur et la hauteur
657
-	$width = $valeurs['largeur'];
658
-	if (isset($surcharge['width'])){
659
-		$width = $surcharge['width'];
660
-		unset($surcharge['width']);
661
-	}
662
-	$height = $valeurs['hauteur'];
663
-	if (isset($surcharge['height'])){
664
-		$height = $surcharge['height'];
665
-		unset($surcharge['height']);
666
-	}
667
-
668
-	$tag = _image_tag_changer_taille($tag,$width,$height,$style);
669
-	// traiter specifiquement le src qui peut etre repris dans un onmouseout
670
-	// on remplace toute les ref a src dans le tag
671
-	$src = extraire_attribut($tag,'src');
672
-	if (isset($surcharge['src'])){
673
-		$tag = str_replace($src,$surcharge['src'],$tag);
674
-		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
675
-		// pas garanti comme methode, mais mieux que rien
676
-		if (strpos($src,'&') !== false)
677
-			$tag = str_replace(str_replace("&","&amp;",$src),$surcharge['src'],$tag);
678
-		$src = $surcharge['src'];
679
-		unset($surcharge['src']);
680
-	}
681
-
682
-	$class = $valeurs['class'];
683
-	if (isset($surcharge['class'])){
684
-		$class = $surcharge['class'];
685
-		unset($surcharge['class']);
686
-	}
687
-	if(strlen($class))
688
-		$tag = inserer_attribut($tag,'class',$class);
689
-
690
-	if (count($surcharge))
691
-		foreach($surcharge as $attribut=>$valeur)
692
-			$tag = inserer_attribut($tag,$attribut,$valeur);
656
+    // traiter specifiquement la largeur et la hauteur
657
+    $width = $valeurs['largeur'];
658
+    if (isset($surcharge['width'])){
659
+        $width = $surcharge['width'];
660
+        unset($surcharge['width']);
661
+    }
662
+    $height = $valeurs['hauteur'];
663
+    if (isset($surcharge['height'])){
664
+        $height = $surcharge['height'];
665
+        unset($surcharge['height']);
666
+    }
667
+
668
+    $tag = _image_tag_changer_taille($tag,$width,$height,$style);
669
+    // traiter specifiquement le src qui peut etre repris dans un onmouseout
670
+    // on remplace toute les ref a src dans le tag
671
+    $src = extraire_attribut($tag,'src');
672
+    if (isset($surcharge['src'])){
673
+        $tag = str_replace($src,$surcharge['src'],$tag);
674
+        // si il y a des & dans src, alors ils peuvent provenir d'un &amp
675
+        // pas garanti comme methode, mais mieux que rien
676
+        if (strpos($src,'&') !== false)
677
+            $tag = str_replace(str_replace("&","&amp;",$src),$surcharge['src'],$tag);
678
+        $src = $surcharge['src'];
679
+        unset($surcharge['src']);
680
+    }
681
+
682
+    $class = $valeurs['class'];
683
+    if (isset($surcharge['class'])){
684
+        $class = $surcharge['class'];
685
+        unset($surcharge['class']);
686
+    }
687
+    if(strlen($class))
688
+        $tag = inserer_attribut($tag,'class',$class);
689
+
690
+    if (count($surcharge))
691
+        foreach($surcharge as $attribut=>$valeur)
692
+            $tag = inserer_attribut($tag,$attribut,$valeur);
693 693
 	
694
-	$tag = pipeline('image_ecrire_tag_finir',
695
-		array(
696
-			'args' => array(
697
-				'valeurs' => $valeurs,
698
-				'surcharge' => $surcharge,
699
-			),
700
-			'data' => $tag
701
-		)
702
-	);
703
-
704
-	return $tag;
694
+    $tag = pipeline('image_ecrire_tag_finir',
695
+        array(
696
+            'args' => array(
697
+                'valeurs' => $valeurs,
698
+                'surcharge' => $surcharge,
699
+            ),
700
+            'data' => $tag
701
+        )
702
+    );
703
+
704
+    return $tag;
705 705
 }
706 706
 
707 707
 function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process='AUTO', $force=false, $test_cache_only = false) {
708
-	// ordre de preference des formats graphiques pour creer les vignettes
709
-	// le premier format disponible, selon la methode demandee, est utilise
710
-	$image = $valeurs['fichier'];
711
-	$format = $valeurs['format_source'];
712
-	$destdir = dirname($valeurs['fichier_dest']);
713
-	$destfile = basename($valeurs['fichier_dest'],".".$valeurs["format_dest"]);
708
+    // ordre de preference des formats graphiques pour creer les vignettes
709
+    // le premier format disponible, selon la methode demandee, est utilise
710
+    $image = $valeurs['fichier'];
711
+    $format = $valeurs['format_source'];
712
+    $destdir = dirname($valeurs['fichier_dest']);
713
+    $destfile = basename($valeurs['fichier_dest'],".".$valeurs["format_dest"]);
714 714
 	
715
-	$format_sortie = $valeurs['format_dest'];
715
+    $format_sortie = $valeurs['format_dest'];
716 716
 	
717
-	// liste des formats qu'on sait lire
718
-	$img = isset($GLOBALS['meta']['formats_graphiques'])
719
-	  ? (strpos($GLOBALS['meta']['formats_graphiques'], $format)!==false)
720
-	  : false;
721
-
722
-	// si le doc n'est pas une image, refuser
723
-	if (!$force AND !$img) return;
724
-	$destination = "$destdir/$destfile";
725
-
726
-	// chercher un cache
727
-	$vignette = '';
728
-	if ($test_cache_only AND !$vignette) return;
729
-
730
-	// utiliser le cache ?
731
-	if (!$test_cache_only)
732
-	if ($force OR !$vignette OR (@filemtime($vignette) < @filemtime($image))) {
733
-
734
-		$creation = true;
735
-		// calculer la taille
736
-		if (($srcWidth=$valeurs['largeur']) && ($srcHeight=$valeurs['hauteur'])){
737
-			if (!($destWidth=$valeurs['largeur_dest']) || !($destHeight=$valeurs['hauteur_dest']))
738
-				list ($destWidth,$destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight);
739
-		}
740
-		elseif ($process == 'convert' OR $process == 'imagick') {
741
-			$destWidth = $maxWidth;
742
-			$destHeight = $maxHeight;
743
-		} else {
744
-			spip_log("echec $process sur $image");
745
-			return;
746
-		}
747
-
748
-		// Si l'image est de la taille demandee (ou plus petite), simplement
749
-		// la retourner
750
-		if ($srcWidth
751
-		AND $srcWidth <= $maxWidth AND $srcHeight <= $maxHeight) {
752
-			$vignette = $destination.'.'.$format;
753
-			@copy($image, $vignette);
754
-		}
755
-		// imagemagick en ligne de commande
756
-		else if ($process == 'convert') {
757
-			define('_CONVERT_COMMAND', 'convert');
758
-			define ('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -resize %xx%y! %src %dest');
759
-			$vignette = $destination.".".$format_sortie;
760
-			$commande = str_replace(
761
-				array('%x', '%y', '%src', '%dest'),
762
-				array(
763
-					$destWidth,
764
-					$destHeight,
765
-					escapeshellcmd($image),
766
-					escapeshellcmd($vignette)
767
-				),
768
-				_RESIZE_COMMAND);
769
-			spip_log($commande);
770
-			exec($commande);
771
-			if (!@file_exists($vignette)) {
772
-				spip_log("echec convert sur $vignette");
773
-				return;	// echec commande
774
-			}
775
-		}
776
-		else
777
-		// imagick (php4-imagemagick)
778
-		if ($process == 'imagick') {
779
-
780
-			$vignette = "$destination.".$format_sortie;
781
-
782
-			$imagick = new Imagick();
783
-			$imagick->readImage($image);
784
-			$imagick->resizeImage($destWidth, $destHeight, Imagick::FILTER_LANCZOS, 1 );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
785
-			$imagick->writeImage($vignette);
786
-
787
-			if (!@file_exists($vignette)) {
788
-				spip_log("echec imagick sur $vignette");
789
-				return;
790
-			}
791
-		}
792
-		else
793
-		// netpbm
794
-		if ($process == "netpbm") {
795
-			define('_PNMSCALE_COMMAND', 'pnmscale'); // chemin a changer dans mes_options
796
-			if (_PNMSCALE_COMMAND == '') return;
797
-			$vignette = $destination.".".$format_sortie;
798
-			$pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND);
799
-			if ($format == "jpg") {
717
+    // liste des formats qu'on sait lire
718
+    $img = isset($GLOBALS['meta']['formats_graphiques'])
719
+      ? (strpos($GLOBALS['meta']['formats_graphiques'], $format)!==false)
720
+      : false;
721
+
722
+    // si le doc n'est pas une image, refuser
723
+    if (!$force AND !$img) return;
724
+    $destination = "$destdir/$destfile";
725
+
726
+    // chercher un cache
727
+    $vignette = '';
728
+    if ($test_cache_only AND !$vignette) return;
729
+
730
+    // utiliser le cache ?
731
+    if (!$test_cache_only)
732
+    if ($force OR !$vignette OR (@filemtime($vignette) < @filemtime($image))) {
733
+
734
+        $creation = true;
735
+        // calculer la taille
736
+        if (($srcWidth=$valeurs['largeur']) && ($srcHeight=$valeurs['hauteur'])){
737
+            if (!($destWidth=$valeurs['largeur_dest']) || !($destHeight=$valeurs['hauteur_dest']))
738
+                list ($destWidth,$destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight);
739
+        }
740
+        elseif ($process == 'convert' OR $process == 'imagick') {
741
+            $destWidth = $maxWidth;
742
+            $destHeight = $maxHeight;
743
+        } else {
744
+            spip_log("echec $process sur $image");
745
+            return;
746
+        }
747
+
748
+        // Si l'image est de la taille demandee (ou plus petite), simplement
749
+        // la retourner
750
+        if ($srcWidth
751
+        AND $srcWidth <= $maxWidth AND $srcHeight <= $maxHeight) {
752
+            $vignette = $destination.'.'.$format;
753
+            @copy($image, $vignette);
754
+        }
755
+        // imagemagick en ligne de commande
756
+        else if ($process == 'convert') {
757
+            define('_CONVERT_COMMAND', 'convert');
758
+            define ('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -resize %xx%y! %src %dest');
759
+            $vignette = $destination.".".$format_sortie;
760
+            $commande = str_replace(
761
+                array('%x', '%y', '%src', '%dest'),
762
+                array(
763
+                    $destWidth,
764
+                    $destHeight,
765
+                    escapeshellcmd($image),
766
+                    escapeshellcmd($vignette)
767
+                ),
768
+                _RESIZE_COMMAND);
769
+            spip_log($commande);
770
+            exec($commande);
771
+            if (!@file_exists($vignette)) {
772
+                spip_log("echec convert sur $vignette");
773
+                return;	// echec commande
774
+            }
775
+        }
776
+        else
777
+        // imagick (php4-imagemagick)
778
+        if ($process == 'imagick') {
779
+
780
+            $vignette = "$destination.".$format_sortie;
781
+
782
+            $imagick = new Imagick();
783
+            $imagick->readImage($image);
784
+            $imagick->resizeImage($destWidth, $destHeight, Imagick::FILTER_LANCZOS, 1 );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
785
+            $imagick->writeImage($vignette);
786
+
787
+            if (!@file_exists($vignette)) {
788
+                spip_log("echec imagick sur $vignette");
789
+                return;
790
+            }
791
+        }
792
+        else
793
+        // netpbm
794
+        if ($process == "netpbm") {
795
+            define('_PNMSCALE_COMMAND', 'pnmscale'); // chemin a changer dans mes_options
796
+            if (_PNMSCALE_COMMAND == '') return;
797
+            $vignette = $destination.".".$format_sortie;
798
+            $pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND);
799
+            if ($format == "jpg") {
800 800
 				
801
-				$jpegtopnm_command = str_replace("pnmscale", "jpegtopnm", _PNMSCALE_COMMAND);
802
-				exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
803
-				if (!($s = @filesize($vignette)))
804
-					spip_unlink($vignette);
805
-				if (!@file_exists($vignette)) {
806
-					spip_log("echec netpbm-jpg sur $vignette");
807
-					return;
808
-				}
809
-			} else if ($format == "gif") {
810
-				$giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND);
811
-				exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
812
-				if (!($s = @filesize($vignette)))
813
-					spip_unlink($vignette);
814
-				if (!@file_exists($vignette)) {
815
-					spip_log("echec netpbm-gif sur $vignette");
816
-					return;
817
-				}
818
-			} else if ($format == "png") {
819
-				$pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND);
820
-				exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
821
-				if (!($s = @filesize($vignette)))
822
-					spip_unlink($vignette);
823
-				if (!@file_exists($vignette)) {
824
-					spip_log("echec netpbm-png sur $vignette");
825
-					return;
826
-				}
827
-			}
828
-		}
829
-		// gd ou gd2
830
-		else if ($process == 'gd1' OR $process == 'gd2') {
831
-			if (_IMG_GD_MAX_PIXELS && $srcWidth*$srcHeight>_IMG_GD_MAX_PIXELS){
832
-				spip_log("vignette gd1/gd2 impossible : ".$srcWidth*$srcHeight."pixels");
833
-				return;
834
-			}
835
-			$destFormat = $format_sortie;
836
-			if (!$destFormat) {
837
-				spip_log("pas de format pour $image");
838
-				return;
839
-			}
840
-
841
-			$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
842
-			if (!function_exists($fonction_imagecreatefrom))
843
-				return '';
844
-			$srcImage = @$fonction_imagecreatefrom($image);
845
-			if (!$srcImage) { 
846
-				spip_log("echec gd1/gd2"); 
847
-				return; 
848
-			} 
849
-
850
-			// Initialisation de l'image destination 
851
-				if ($process == 'gd2' AND $destFormat != "gif") 
852
-				$destImage = ImageCreateTrueColor($destWidth, $destHeight); 
853
-			if (!$destImage) 
854
-				$destImage = ImageCreate($destWidth, $destHeight); 
855
-
856
-			// Recopie de l'image d'origine avec adaptation de la taille 
857
-			$ok = false; 
858
-			if (($process == 'gd2') AND function_exists('ImageCopyResampled')) { 
859
-				if ($format == "gif") { 
860
-					// Si un GIF est transparent, 
861
-					// fabriquer un PNG transparent  
862
-					$transp = imagecolortransparent($srcImage); 
863
-					if ($transp > 0) $destFormat = "png"; 
864
-				}
865
-				if ($destFormat == "png") { 
866
-					// Conserver la transparence 
867
-					if (function_exists("imageAntiAlias")) imageAntiAlias($destImage,true); 
868
-					@imagealphablending($destImage, false); 
869
-					@imagesavealpha($destImage,true); 
870
-				}
871
-				$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
872
-			}
873
-			if (!$ok)
874
-				$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
875
-
876
-			// Sauvegarde de l'image destination
877
-			$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
878
-			$valeurs['format_dest'] = $format = $destFormat;
879
-			_image_gd_output($destImage,$valeurs);
880
-
881
-			if ($srcImage)
882
-				ImageDestroy($srcImage);
883
-			ImageDestroy($destImage);
884
-		}
885
-	}
886
-	$size = @getimagesize($vignette);
887
-	// Gaffe: en safe mode, pas d'acces a la vignette,
888
-	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
889
-	if ($size[0] < 1) $size[0] = $destWidth;
890
-	if ($size[1] < 1) $size[1] = $destHeight;
801
+                $jpegtopnm_command = str_replace("pnmscale", "jpegtopnm", _PNMSCALE_COMMAND);
802
+                exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
803
+                if (!($s = @filesize($vignette)))
804
+                    spip_unlink($vignette);
805
+                if (!@file_exists($vignette)) {
806
+                    spip_log("echec netpbm-jpg sur $vignette");
807
+                    return;
808
+                }
809
+            } else if ($format == "gif") {
810
+                $giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND);
811
+                exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
812
+                if (!($s = @filesize($vignette)))
813
+                    spip_unlink($vignette);
814
+                if (!@file_exists($vignette)) {
815
+                    spip_log("echec netpbm-gif sur $vignette");
816
+                    return;
817
+                }
818
+            } else if ($format == "png") {
819
+                $pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND);
820
+                exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
821
+                if (!($s = @filesize($vignette)))
822
+                    spip_unlink($vignette);
823
+                if (!@file_exists($vignette)) {
824
+                    spip_log("echec netpbm-png sur $vignette");
825
+                    return;
826
+                }
827
+            }
828
+        }
829
+        // gd ou gd2
830
+        else if ($process == 'gd1' OR $process == 'gd2') {
831
+            if (_IMG_GD_MAX_PIXELS && $srcWidth*$srcHeight>_IMG_GD_MAX_PIXELS){
832
+                spip_log("vignette gd1/gd2 impossible : ".$srcWidth*$srcHeight."pixels");
833
+                return;
834
+            }
835
+            $destFormat = $format_sortie;
836
+            if (!$destFormat) {
837
+                spip_log("pas de format pour $image");
838
+                return;
839
+            }
840
+
841
+            $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
842
+            if (!function_exists($fonction_imagecreatefrom))
843
+                return '';
844
+            $srcImage = @$fonction_imagecreatefrom($image);
845
+            if (!$srcImage) { 
846
+                spip_log("echec gd1/gd2"); 
847
+                return; 
848
+            } 
849
+
850
+            // Initialisation de l'image destination 
851
+                if ($process == 'gd2' AND $destFormat != "gif") 
852
+                $destImage = ImageCreateTrueColor($destWidth, $destHeight); 
853
+            if (!$destImage) 
854
+                $destImage = ImageCreate($destWidth, $destHeight); 
855
+
856
+            // Recopie de l'image d'origine avec adaptation de la taille 
857
+            $ok = false; 
858
+            if (($process == 'gd2') AND function_exists('ImageCopyResampled')) { 
859
+                if ($format == "gif") { 
860
+                    // Si un GIF est transparent, 
861
+                    // fabriquer un PNG transparent  
862
+                    $transp = imagecolortransparent($srcImage); 
863
+                    if ($transp > 0) $destFormat = "png"; 
864
+                }
865
+                if ($destFormat == "png") { 
866
+                    // Conserver la transparence 
867
+                    if (function_exists("imageAntiAlias")) imageAntiAlias($destImage,true); 
868
+                    @imagealphablending($destImage, false); 
869
+                    @imagesavealpha($destImage,true); 
870
+                }
871
+                $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
872
+            }
873
+            if (!$ok)
874
+                $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
875
+
876
+            // Sauvegarde de l'image destination
877
+            $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
878
+            $valeurs['format_dest'] = $format = $destFormat;
879
+            _image_gd_output($destImage,$valeurs);
880
+
881
+            if ($srcImage)
882
+                ImageDestroy($srcImage);
883
+            ImageDestroy($destImage);
884
+        }
885
+    }
886
+    $size = @getimagesize($vignette);
887
+    // Gaffe: en safe mode, pas d'acces a la vignette,
888
+    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
889
+    if ($size[0] < 1) $size[0] = $destWidth;
890
+    if ($size[1] < 1) $size[1] = $destHeight;
891 891
 	
892
-	$retour['width'] = $largeur = $size[0];
893
-	$retour['height'] = $hauteur = $size[1];
892
+    $retour['width'] = $largeur = $size[0];
893
+    $retour['height'] = $hauteur = $size[1];
894 894
 	
895
-	$retour['fichier'] = $vignette;
896
-	$retour['format'] = $format;
897
-	$retour['date'] = @filemtime($vignette);
895
+    $retour['fichier'] = $vignette;
896
+    $retour['format'] = $format;
897
+    $retour['date'] = @filemtime($vignette);
898 898
 	
899
-	// renvoyer l'image
900
-	return $retour;
899
+    // renvoyer l'image
900
+    return $retour;
901 901
 }
902 902
 
903 903
 // Calculer le ratio
904 904
 // http://doc.spip.org/@image_ratio
905 905
 function _image_ratio ($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
906
-	$ratioWidth = $srcWidth/$maxWidth;
907
-	$ratioHeight = $srcHeight/$maxHeight;
906
+    $ratioWidth = $srcWidth/$maxWidth;
907
+    $ratioHeight = $srcHeight/$maxHeight;
908 908
 	
909
-	if ($ratioWidth <=1 AND $ratioHeight <=1) {
910
-		$destWidth = $srcWidth;
911
-		$destHeight = $srcHeight;
912
-	} else if ($ratioWidth < $ratioHeight) {
913
-		$destWidth = $srcWidth/$ratioHeight;
914
-		$destHeight = $maxHeight;
915
-	}
916
-	else {
917
-		$destWidth = $maxWidth;
918
-		$destHeight = $srcHeight/$ratioWidth;
919
-	}
920
-	return array (ceil($destWidth), ceil($destHeight),
921
-		max($ratioWidth,$ratioHeight));
909
+    if ($ratioWidth <=1 AND $ratioHeight <=1) {
910
+        $destWidth = $srcWidth;
911
+        $destHeight = $srcHeight;
912
+    } else if ($ratioWidth < $ratioHeight) {
913
+        $destWidth = $srcWidth/$ratioHeight;
914
+        $destHeight = $maxHeight;
915
+    }
916
+    else {
917
+        $destWidth = $maxWidth;
918
+        $destHeight = $srcHeight/$ratioWidth;
919
+    }
920
+    return array (ceil($destWidth), ceil($destHeight),
921
+        max($ratioWidth,$ratioHeight));
922 922
 }
923 923
 
924 924
 // Calculer le ratio ajuste sur la plus petite dimension
925 925
 // http://doc.spip.org/@ratio_passe_partout
926 926
 function ratio_passe_partout ($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
927
-	$ratioWidth = $srcWidth/$maxWidth;
928
-	$ratioHeight = $srcHeight/$maxHeight;
929
-
930
-	if ($ratioWidth <=1 AND $ratioHeight <=1) {
931
-		$destWidth = $srcWidth;
932
-		$destHeight = $srcHeight;
933
-	} else if ($ratioWidth > $ratioHeight) {
934
-		$destWidth = $srcWidth/$ratioHeight;
935
-		$destHeight = $maxHeight;
936
-	}
937
-	else {
938
-		$destWidth = $maxWidth;
939
-		$destHeight = $srcHeight/$ratioWidth;
940
-	}
941
-	return array (ceil($destWidth), ceil($destHeight),
942
-		min($ratioWidth,$ratioHeight));
927
+    $ratioWidth = $srcWidth/$maxWidth;
928
+    $ratioHeight = $srcHeight/$maxHeight;
929
+
930
+    if ($ratioWidth <=1 AND $ratioHeight <=1) {
931
+        $destWidth = $srcWidth;
932
+        $destHeight = $srcHeight;
933
+    } else if ($ratioWidth > $ratioHeight) {
934
+        $destWidth = $srcWidth/$ratioHeight;
935
+        $destHeight = $maxHeight;
936
+    }
937
+    else {
938
+        $destWidth = $maxWidth;
939
+        $destHeight = $srcHeight/$ratioWidth;
940
+    }
941
+    return array (ceil($destWidth), ceil($destHeight),
942
+        min($ratioWidth,$ratioHeight));
943 943
 }
944 944
 
945 945
 // http://doc.spip.org/@process_image_reduire
946 946
 function process_image_reduire($fonction,$img,$taille,$taille_y,$force,$cherche_image,$process){
947
-	$image = false;
948
-	if (($process == 'AUTO') AND isset($GLOBALS['meta']['image_process']))
949
-		$process = $GLOBALS['meta']['image_process'];
950
-	# determiner le format de sortie
951
-	$format_sortie = false; // le choix par defaut sera bon
952
-	if ($process == "netpbm") $format_sortie = "jpg";
953
-	else if ($process == 'gd1' OR $process == 'gd2') {
954
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}",$format_sortie,$fonction);
955
-
956
-		// on verifie que l'extension choisie est bonne (en principe oui)
957
-		$gd_formats = explode(',',$GLOBALS['meta']["gd_formats"]);
958
-		if (!in_array($image['format_dest'],$gd_formats)
959
-		  OR ($image['format_dest']=='gif' AND !function_exists('ImageGif'))
960
-		  ) {
961
-			if ($image['format_source'] == 'jpg')
962
-				$formats_sortie = array('jpg','png','gif');
963
-			else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
964
-				$formats_sortie = array('png','jpg','gif');
965
-			// Choisir le format destination
966
-			// - on sauve de preference en JPEG (meilleure compression)
967
-			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
968
-			# bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
969
-			# pas *ecrire*
970
-			$format_sortie = "";
971
-			foreach ($formats_sortie as $fmt) {
972
-				if (in_array($fmt, $gd_formats)) {
973
-					if ($fmt <> "gif" OR function_exists('ImageGif'))
974
-						$format_sortie = $fmt;
975
-					break;
976
-				}
977
-			}
978
-			$image = false;
979
-		}
980
-	}
981
-
982
-	if (!$image)
983
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}",$format_sortie,$fonction);
984
-
985
-	if (!$image OR !$image['largeur'] OR !$image['hauteur']){
986
-		spip_log("image_reduire_src:pas de version locale de $img");
987
-		// on peut resizer en mode html si on dispose des elements
988
-		if ($srcw = extraire_attribut($img, 'width')
989
-		AND $srch = extraire_attribut($img, 'height')) {
990
-			list($w,$h) = _image_ratio($srcw, $srch, $taille, $taille_y);
991
-			return _image_tag_changer_taille($img,$w,$h);
992
-		}
993
-		// la on n'a pas d'infos sur l'image source... on refile le truc a css
994
-		// sous la forme style='max-width: NNpx;'
995
-		return inserer_attribut($img, 'style',
996
-			"max-width: ${taille}px; max-height: ${taille_y}px");
997
-	}
998
-
999
-	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1000
-	if (($image['largeur']<=$taille)&&($image['hauteur']<=$taille_y)){
1001
-		if ($image['creer']){
1002
-			@copy($image['fichier'], $image['fichier_dest']);
1003
-		}
1004
-		return _image_ecrire_tag($image,array('src'=>$image['fichier_dest']));
1005
-	}
1006
-
1007
-	if ($image['creer']==false && !$force)
1008
-		return _image_ecrire_tag($image,array('src'=>$image['fichier_dest'],'width'=>$image['largeur_dest'],'height'=>$image['hauteur_dest']));
1009
-
1010
-	if (in_array($image["format_source"],array('jpg','gif','png'))){
1011
-		$destWidth = $image['largeur_dest'];
1012
-		$destHeight = $image['hauteur_dest'];
1013
-		$logo = $image['fichier'];
1014
-		$date = $image["date_src"];
1015
-		$preview = _image_creer_vignette($image, $taille, $taille_y,$process,$force);
1016
-
1017
-		if ($preview && $preview['fichier']) {
1018
-			$logo = $preview['fichier'];
1019
-			$destWidth = $preview['width'];
1020
-			$destHeight = $preview['height'];
1021
-			$date = $preview['date'];
1022
-		}
1023
-		// dans l'espace prive mettre un timestamp sur l'adresse 
1024
-		// de l'image, de facon a tromper le cache du navigateur
1025
-		// quand on fait supprimer/reuploader un logo
1026
-		// (pas de filemtime si SAFE MODE)
1027
-		$date = test_espace_prive() ? ('?'.$date) : '';
1028
-		return _image_ecrire_tag($image,array('src'=>"$logo$date",'width'=>$destWidth,'height'=>$destHeight));
1029
-	}
1030
-	else
1031
-		# SVG par exemple ? BMP, tiff ... les redacteurs osent tout!
1032
-		return $img;
947
+    $image = false;
948
+    if (($process == 'AUTO') AND isset($GLOBALS['meta']['image_process']))
949
+        $process = $GLOBALS['meta']['image_process'];
950
+    # determiner le format de sortie
951
+    $format_sortie = false; // le choix par defaut sera bon
952
+    if ($process == "netpbm") $format_sortie = "jpg";
953
+    else if ($process == 'gd1' OR $process == 'gd2') {
954
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}",$format_sortie,$fonction);
955
+
956
+        // on verifie que l'extension choisie est bonne (en principe oui)
957
+        $gd_formats = explode(',',$GLOBALS['meta']["gd_formats"]);
958
+        if (!in_array($image['format_dest'],$gd_formats)
959
+          OR ($image['format_dest']=='gif' AND !function_exists('ImageGif'))
960
+            ) {
961
+            if ($image['format_source'] == 'jpg')
962
+                $formats_sortie = array('jpg','png','gif');
963
+            else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
964
+                $formats_sortie = array('png','jpg','gif');
965
+            // Choisir le format destination
966
+            // - on sauve de preference en JPEG (meilleure compression)
967
+            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
968
+            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
969
+            # pas *ecrire*
970
+            $format_sortie = "";
971
+            foreach ($formats_sortie as $fmt) {
972
+                if (in_array($fmt, $gd_formats)) {
973
+                    if ($fmt <> "gif" OR function_exists('ImageGif'))
974
+                        $format_sortie = $fmt;
975
+                    break;
976
+                }
977
+            }
978
+            $image = false;
979
+        }
980
+    }
981
+
982
+    if (!$image)
983
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}",$format_sortie,$fonction);
984
+
985
+    if (!$image OR !$image['largeur'] OR !$image['hauteur']){
986
+        spip_log("image_reduire_src:pas de version locale de $img");
987
+        // on peut resizer en mode html si on dispose des elements
988
+        if ($srcw = extraire_attribut($img, 'width')
989
+        AND $srch = extraire_attribut($img, 'height')) {
990
+            list($w,$h) = _image_ratio($srcw, $srch, $taille, $taille_y);
991
+            return _image_tag_changer_taille($img,$w,$h);
992
+        }
993
+        // la on n'a pas d'infos sur l'image source... on refile le truc a css
994
+        // sous la forme style='max-width: NNpx;'
995
+        return inserer_attribut($img, 'style',
996
+            "max-width: ${taille}px; max-height: ${taille_y}px");
997
+    }
998
+
999
+    // si l'image est plus petite que la cible retourner une copie cachee de l'image
1000
+    if (($image['largeur']<=$taille)&&($image['hauteur']<=$taille_y)){
1001
+        if ($image['creer']){
1002
+            @copy($image['fichier'], $image['fichier_dest']);
1003
+        }
1004
+        return _image_ecrire_tag($image,array('src'=>$image['fichier_dest']));
1005
+    }
1006
+
1007
+    if ($image['creer']==false && !$force)
1008
+        return _image_ecrire_tag($image,array('src'=>$image['fichier_dest'],'width'=>$image['largeur_dest'],'height'=>$image['hauteur_dest']));
1009
+
1010
+    if (in_array($image["format_source"],array('jpg','gif','png'))){
1011
+        $destWidth = $image['largeur_dest'];
1012
+        $destHeight = $image['hauteur_dest'];
1013
+        $logo = $image['fichier'];
1014
+        $date = $image["date_src"];
1015
+        $preview = _image_creer_vignette($image, $taille, $taille_y,$process,$force);
1016
+
1017
+        if ($preview && $preview['fichier']) {
1018
+            $logo = $preview['fichier'];
1019
+            $destWidth = $preview['width'];
1020
+            $destHeight = $preview['height'];
1021
+            $date = $preview['date'];
1022
+        }
1023
+        // dans l'espace prive mettre un timestamp sur l'adresse 
1024
+        // de l'image, de facon a tromper le cache du navigateur
1025
+        // quand on fait supprimer/reuploader un logo
1026
+        // (pas de filemtime si SAFE MODE)
1027
+        $date = test_espace_prive() ? ('?'.$date) : '';
1028
+        return _image_ecrire_tag($image,array('src'=>"$logo$date",'width'=>$destWidth,'height'=>$destHeight));
1029
+    }
1030
+    else
1031
+        # SVG par exemple ? BMP, tiff ... les redacteurs osent tout!
1032
+        return $img;
1033 1033
 }
1034 1034
 
1035 1035
 /**
@@ -1042,134 +1042,134 @@  discard block
 block discarded – undo
1042 1042
  */
1043 1043
 class phpthumb_functions {
1044 1044
 
1045
-	/**
1046
-	 * @param ressource $img
1047
-	 * @param int $x
1048
-	 * @param int $y
1049
-	 * @return array|bool
1050
-	 */
1051
-	public static function GetPixelColor(&$img, $x, $y) {
1052
-		if (!is_resource($img)) {
1053
-			return false;
1054
-		}
1055
-		return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1056
-	}
1057
-
1058
-	/**
1059
-	 * @param int $number
1060
-	 * @param int $minbytes
1061
-	 * @return string
1062
-	 */
1063
-	public static function LittleEndian2String($number, $minbytes=1) {
1064
-		$intstring = '';
1065
-		while ($number > 0) {
1066
-			$intstring = $intstring.chr($number & 255);
1067
-			$number >>= 8;
1068
-		}
1069
-		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1070
-	}
1071
-
1072
-	/**
1073
-	 * @param array $gd_image_array
1074
-	 * @return string
1075
-	 */
1076
-	public static function GD2ICOstring(&$gd_image_array) {
1077
-		foreach ($gd_image_array as $key => $gd_image) {
1078
-
1079
-			$ImageWidths[$key]  = ImageSX($gd_image);
1080
-			$ImageHeights[$key] = ImageSY($gd_image);
1081
-			$bpp[$key]		  = ImageIsTrueColor($gd_image) ? 32 : 24;
1082
-			$totalcolors[$key]  = ImageColorsTotal($gd_image);
1083
-
1084
-			$icXOR[$key] = '';
1085
-			for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1086
-				for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1087
-					$argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1088
-					$a = round(255 * ((127 - $argb['alpha']) / 127));
1089
-					$r = $argb['red'];
1090
-					$g = $argb['green'];
1091
-					$b = $argb['blue'];
1092
-
1093
-					if ($bpp[$key] == 32) {
1094
-						$icXOR[$key] .= chr($b).chr($g).chr($r).chr($a);
1095
-					} elseif ($bpp[$key] == 24) {
1096
-						$icXOR[$key] .= chr($b).chr($g).chr($r);
1097
-					}
1098
-
1099
-					if ($a < 128) {
1100
-						@$icANDmask[$key][$y] .= '1';
1101
-					} else {
1102
-						@$icANDmask[$key][$y] .= '0';
1103
-					}
1104
-				}
1105
-				// mask bits are 32-bit aligned per scanline
1106
-				while (strlen($icANDmask[$key][$y]) % 32) {
1107
-					$icANDmask[$key][$y] .= '0';
1108
-				}
1109
-			}
1110
-			$icAND[$key] = '';
1111
-			foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1112
-				for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1113
-					$icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1114
-				}
1115
-			}
1116
-
1117
-		}
1118
-
1119
-		foreach ($gd_image_array as $key => $gd_image) {
1120
-			$biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1121
-
1122
-			// BITMAPINFOHEADER - 40 bytes
1123
-			$BitmapInfoHeader[$key]  = '';
1124
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";							  // DWORD  biSize;
1125
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);	  // LONG   biWidth;
1126
-			// The biHeight member specifies the combined
1127
-			// height of the XOR and AND masks.
1128
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1129
-			$BitmapInfoHeader[$key] .= "\x01\x00";									  // WORD   biPlanes;
1130
-			   $BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00";						  // wBitCount;
1131
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";							  // DWORD  biCompression;
1132
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);			// DWORD  biSizeImage;
1133
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";							  // LONG   biXPelsPerMeter;
1134
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";							  // LONG   biYPelsPerMeter;
1135
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";							  // DWORD  biClrUsed;
1136
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";							  // DWORD  biClrImportant;
1137
-		}
1138
-
1139
-
1140
-		$icondata  = "\x00\x00";									  // idReserved;   // Reserved (must be 0)
1141
-		$icondata .= "\x01\x00";									  // idType;	   // Resource Type (1 for icons)
1142
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1143
-
1144
-		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1145
-		foreach ($gd_image_array as $key => $gd_image) {
1146
-			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1147
-
1148
-			$icondata .= chr($ImageWidths[$key]);					 // bWidth;		  // Width, in pixels, of the image
1149
-			$icondata .= chr($ImageHeights[$key]);					// bHeight;		 // Height, in pixels, of the image
1150
-			$icondata .= chr($totalcolors[$key]);					 // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1151
-			$icondata .= "\x00";									  // bReserved;	   // Reserved ( must be 0)
1152
-
1153
-			$icondata .= "\x01\x00";								  // wPlanes;		 // Color Planes
1154
-			$icondata .= chr($bpp[$key])."\x00";					  // wBitCount;	   // Bits per pixel
1155
-
1156
-			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1157
-			$icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes, 4);	   // dwBytesInRes;	// How many bytes in this resource?
1158
-
1159
-			$icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset, 4);	  // dwImageOffset;   // Where in the file is this image?
1160
-			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1161
-			$dwImageOffset += strlen($icXOR[$key]);
1162
-			$dwImageOffset += strlen($icAND[$key]);
1163
-		}
1164
-
1165
-		foreach ($gd_image_array as $key => $gd_image) {
1166
-			$icondata .= $BitmapInfoHeader[$key];
1167
-			$icondata .= $icXOR[$key];
1168
-			$icondata .= $icAND[$key];
1169
-		}
1170
-
1171
-		return $icondata;
1172
-	}
1045
+    /**
1046
+     * @param ressource $img
1047
+     * @param int $x
1048
+     * @param int $y
1049
+     * @return array|bool
1050
+     */
1051
+    public static function GetPixelColor(&$img, $x, $y) {
1052
+        if (!is_resource($img)) {
1053
+            return false;
1054
+        }
1055
+        return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1056
+    }
1057
+
1058
+    /**
1059
+     * @param int $number
1060
+     * @param int $minbytes
1061
+     * @return string
1062
+     */
1063
+    public static function LittleEndian2String($number, $minbytes=1) {
1064
+        $intstring = '';
1065
+        while ($number > 0) {
1066
+            $intstring = $intstring.chr($number & 255);
1067
+            $number >>= 8;
1068
+        }
1069
+        return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1070
+    }
1071
+
1072
+    /**
1073
+     * @param array $gd_image_array
1074
+     * @return string
1075
+     */
1076
+    public static function GD2ICOstring(&$gd_image_array) {
1077
+        foreach ($gd_image_array as $key => $gd_image) {
1078
+
1079
+            $ImageWidths[$key]  = ImageSX($gd_image);
1080
+            $ImageHeights[$key] = ImageSY($gd_image);
1081
+            $bpp[$key]		  = ImageIsTrueColor($gd_image) ? 32 : 24;
1082
+            $totalcolors[$key]  = ImageColorsTotal($gd_image);
1083
+
1084
+            $icXOR[$key] = '';
1085
+            for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1086
+                for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1087
+                    $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1088
+                    $a = round(255 * ((127 - $argb['alpha']) / 127));
1089
+                    $r = $argb['red'];
1090
+                    $g = $argb['green'];
1091
+                    $b = $argb['blue'];
1092
+
1093
+                    if ($bpp[$key] == 32) {
1094
+                        $icXOR[$key] .= chr($b).chr($g).chr($r).chr($a);
1095
+                    } elseif ($bpp[$key] == 24) {
1096
+                        $icXOR[$key] .= chr($b).chr($g).chr($r);
1097
+                    }
1098
+
1099
+                    if ($a < 128) {
1100
+                        @$icANDmask[$key][$y] .= '1';
1101
+                    } else {
1102
+                        @$icANDmask[$key][$y] .= '0';
1103
+                    }
1104
+                }
1105
+                // mask bits are 32-bit aligned per scanline
1106
+                while (strlen($icANDmask[$key][$y]) % 32) {
1107
+                    $icANDmask[$key][$y] .= '0';
1108
+                }
1109
+            }
1110
+            $icAND[$key] = '';
1111
+            foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1112
+                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1113
+                    $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1114
+                }
1115
+            }
1116
+
1117
+        }
1118
+
1119
+        foreach ($gd_image_array as $key => $gd_image) {
1120
+            $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1121
+
1122
+            // BITMAPINFOHEADER - 40 bytes
1123
+            $BitmapInfoHeader[$key]  = '';
1124
+            $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";							  // DWORD  biSize;
1125
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);	  // LONG   biWidth;
1126
+            // The biHeight member specifies the combined
1127
+            // height of the XOR and AND masks.
1128
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1129
+            $BitmapInfoHeader[$key] .= "\x01\x00";									  // WORD   biPlanes;
1130
+                $BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00";						  // wBitCount;
1131
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";							  // DWORD  biCompression;
1132
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);			// DWORD  biSizeImage;
1133
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";							  // LONG   biXPelsPerMeter;
1134
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";							  // LONG   biYPelsPerMeter;
1135
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";							  // DWORD  biClrUsed;
1136
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";							  // DWORD  biClrImportant;
1137
+        }
1138
+
1139
+
1140
+        $icondata  = "\x00\x00";									  // idReserved;   // Reserved (must be 0)
1141
+        $icondata .= "\x01\x00";									  // idType;	   // Resource Type (1 for icons)
1142
+        $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1143
+
1144
+        $dwImageOffset = 6 + (count($gd_image_array) * 16);
1145
+        foreach ($gd_image_array as $key => $gd_image) {
1146
+            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1147
+
1148
+            $icondata .= chr($ImageWidths[$key]);					 // bWidth;		  // Width, in pixels, of the image
1149
+            $icondata .= chr($ImageHeights[$key]);					// bHeight;		 // Height, in pixels, of the image
1150
+            $icondata .= chr($totalcolors[$key]);					 // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1151
+            $icondata .= "\x00";									  // bReserved;	   // Reserved ( must be 0)
1152
+
1153
+            $icondata .= "\x01\x00";								  // wPlanes;		 // Color Planes
1154
+            $icondata .= chr($bpp[$key])."\x00";					  // wBitCount;	   // Bits per pixel
1155
+
1156
+            $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1157
+            $icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes, 4);	   // dwBytesInRes;	// How many bytes in this resource?
1158
+
1159
+            $icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset, 4);	  // dwImageOffset;   // Where in the file is this image?
1160
+            $dwImageOffset += strlen($BitmapInfoHeader[$key]);
1161
+            $dwImageOffset += strlen($icXOR[$key]);
1162
+            $dwImageOffset += strlen($icAND[$key]);
1163
+        }
1164
+
1165
+        foreach ($gd_image_array as $key => $gd_image) {
1166
+            $icondata .= $BitmapInfoHeader[$key];
1167
+            $icondata .= $icXOR[$key];
1168
+            $icondata .= $icAND[$key];
1169
+        }
1170
+
1171
+        return $icondata;
1172
+    }
1173 1173
 
1174 1174
 }
1175 1175
 
Please login to merge, or discard this patch.
Braces   +183 added lines, -108 removed lines patch added patch discarded remove patch
@@ -18,7 +18,9 @@  discard block
 block discarded – undo
18 18
  */
19 19
 
20 20
 
21
-if (!defined('_ECRIRE_INC_VERSION')) return;
21
+if (!defined('_ECRIRE_INC_VERSION')) {
22
+    return;
23
+}
22 24
 include_spip('inc/filtres'); // par precaution
23 25
 include_spip('inc/filtres_images_mini'); // par precaution
24 26
 
@@ -39,9 +41,15 @@  discard block
 block discarded – undo
39 41
 	$green = dechex($green);
40 42
 	$blue = dechex($blue);
41 43
 	
42
-	if (strlen($red) == 1) $red = "0".$red;
43
-	if (strlen($green) == 1) $green = "0".$green;
44
-	if (strlen($blue) == 1) $blue = "0".$blue;
44
+	if (strlen($red) == 1) {
45
+	    $red = "0".$red;
46
+	}
47
+	if (strlen($green) == 1) {
48
+	    $green = "0".$green;
49
+	}
50
+	if (strlen($blue) == 1) {
51
+	    $blue = "0".$blue;
52
+	}
45 53
 	
46 54
 	return "$red$green$blue";
47 55
 }
@@ -79,7 +87,9 @@  discard block
 block discarded – undo
79 87
  */
80 88
 function statut_effacer_images_temporaires($stat){
81 89
 	static $statut = false; // par defaut on grave toute les images
82
-	if ($stat==='get') return $statut;
90
+	if ($stat==='get') {
91
+	    return $statut;
92
+	}
83 93
 	$statut = $stat?true:false;
84 94
 }
85 95
 
@@ -117,7 +127,9 @@  discard block
 block discarded – undo
117 127
  */
118 128
 function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = NULL, $find_in_path = false) {
119 129
 	static $images_recalcul = array();
120
-	if (strlen($img)==0) return false;
130
+	if (strlen($img)==0) {
131
+	    return false;
132
+	}
121 133
 
122 134
 	$source = trim(extraire_attribut($img, 'src'));
123 135
 	if (strlen($source) < 1){
@@ -141,8 +153,10 @@  discard block
 block discarded – undo
141 153
 	if (preg_match(';^(\w{3,7}://);', $source)){
142 154
 		include_spip('inc/distant');
143 155
 		$fichier = _DIR_RACINE . copie_locale($source);
144
-		if (!$fichier) return "";
145
-	}	else {
156
+		if (!$fichier) {
157
+		    return "";
158
+		}
159
+	} else {
146 160
 		// enlever le timestamp eventuel
147 161
 		$source=preg_replace(',[?][0-9]+$,','',$source);
148 162
 		if (strpos($source,"?")!==false
@@ -158,14 +172,22 @@  discard block
 block discarded – undo
158 172
 		$terminaison = strtolower($regs[1]);
159 173
 		$terminaison_dest = $terminaison;
160 174
 		
161
-		if ($terminaison == "gif") $terminaison_dest = "png";
175
+		if ($terminaison == "gif") {
176
+		    $terminaison_dest = "png";
177
+		}
178
+	}
179
+	if ($forcer_format!==false) {
180
+	    $terminaison_dest = $forcer_format;
162 181
 	}
163
-	if ($forcer_format!==false) $terminaison_dest = $forcer_format;
164 182
 
165
-	if (!$terminaison_dest) return false;
183
+	if (!$terminaison_dest) {
184
+	    return false;
185
+	}
166 186
 
167 187
 	$term_fonction = $terminaison;
168
-	if ($term_fonction == "jpg") $term_fonction = "jpeg";
188
+	if ($term_fonction == "jpg") {
189
+	    $term_fonction = "jpeg";
190
+	}
169 191
 
170 192
 	$nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
171 193
 	$fichier_dest = $nom_fichier;
@@ -175,8 +197,7 @@  discard block
 block discarded – undo
175 197
 		// au lieu de faire un acces disque sur le fichier
176 198
 		list ($ret["hauteur"],$ret["largeur"]) = taille_image($find_in_path?$f:$img);
177 199
 		$date_src = @filemtime($f);
178
-	}
179
-	elseif (@file_exists($f = "$fichier.src")
200
+	} elseif (@file_exists($f = "$fichier.src")
180 201
 		AND lire_fichier($f,$valeurs)
181 202
 		AND $valeurs=unserialize($valeurs)
182 203
 		AND isset($valeurs["hauteur_dest"])
@@ -186,12 +207,14 @@  discard block
 block discarded – undo
186 207
 		$date_src = $valeurs["date"];
187 208
 	}
188 209
 	// pas de fichier source par la
189
-	else
190
-		return false;
210
+	else {
211
+			return false;
212
+	}
191 213
 
192 214
 	// pas de taille mesurable
193
-	if (!($ret["hauteur"] OR $ret["largeur"]))
194
-		return false;
215
+	if (!($ret["hauteur"] OR $ret["largeur"])) {
216
+			return false;
217
+	}
195 218
 		
196 219
 
197 220
 	// cas general :
@@ -212,9 +235,9 @@  discard block
 block discarded – undo
212 235
 			// et on postfixe son nom avec un md5 du path
213 236
 			$terminaison_dest = $terminaison;
214 237
 			$fichier_dest .= '-'.substr(md5("$fichier"),0,5);
238
+		} else {
239
+					$fichier_dest .= '-'.substr(md5("$fichier-$effet"),0,5);
215 240
 		}
216
-		else
217
-			$fichier_dest .= '-'.substr(md5("$fichier-$effet"),0,5);
218 241
 		$cache = sous_repertoire(_DIR_VAR, $cache);
219 242
 		$cache = sous_repertoire($cache, $effet);
220 243
 		# cherche un cache existant
@@ -222,8 +245,7 @@  discard block
 block discarded – undo
222 245
 			if (@file_exists($cache . $fichier_dest . '.' . $fmt)) {
223 246
 				$terminaison_dest = $fmt;
224 247
 			}*/
225
-	}
226
-	else 	{
248
+	} else 	{
227 249
 		$fichier_dest = md5("$fichier-$effet");
228 250
 		$cache = sous_repertoire(_DIR_VAR, $cache);
229 251
 	}
@@ -236,17 +258,17 @@  discard block
 block discarded – undo
236 258
 	// si recalcul des images demande, recalculer chaque image une fois
237 259
 	if (defined('_VAR_IMAGES') AND _VAR_IMAGES AND !isset($images_recalcul[$fichier_dest])){
238 260
 		$images_recalcul[$fichier_dest] = true;
239
-	}
240
-	else {
261
+	} else {
241 262
 		if (@file_exists($f = $fichier_dest)){
242
-			if (filemtime($f)>=$date_src)
243
-				$creer = false;
244
-		}
245
-		else if (@file_exists($f = "$fichier_dest.src")
263
+			if (filemtime($f)>=$date_src) {
264
+							$creer = false;
265
+			}
266
+		} else if (@file_exists($f = "$fichier_dest.src")
246 267
 		  AND lire_fichier($f,$valeurs)
247 268
 		  AND $valeurs=unserialize($valeurs)
248
-			AND $valeurs["date"]>=$date_src)
249
-				$creer = false;
269
+			AND $valeurs["date"]>=$date_src) {
270
+						$creer = false;
271
+		}
250 272
 	}
251 273
 	if ($creer) {
252 274
 		if (!@file_exists($fichier)) {
@@ -259,8 +281,9 @@  discard block
 block discarded – undo
259 281
 		}
260 282
 	}
261 283
 
262
-	if ($creer)
263
-		spip_log("filtre image ".($fonction_creation?reset($fonction_creation):'')."[$effet] sur $fichier","images"._LOG_DEBUG);
284
+	if ($creer) {
285
+			spip_log("filtre image ".($fonction_creation?reset($fonction_creation):'')."[$effet] sur $fichier","images"._LOG_DEBUG);
286
+	}
264 287
 
265 288
 	// TODO: si une image png est nommee .jpg, le reconnaitre avec le bon $f
266 289
 	$ret["fonction_imagecreatefrom"] = "_imagecreatefrom".$term_fonction;
@@ -297,7 +320,9 @@  discard block
 block discarded – undo
297 320
 	// une globale pour le debug en cas de crash memoire
298 321
 	$GLOBALS["derniere_image_calculee"] = $ret;
299 322
 
300
-	if (!function_exists($ret["fonction_imagecreatefrom"])) return false;
323
+	if (!function_exists($ret["fonction_imagecreatefrom"])) {
324
+	    return false;
325
+	}
301 326
 	return $ret;
302 327
 }
303 328
 
@@ -374,13 +399,17 @@  discard block
 block discarded – undo
374 399
  * 		true si une image est bien retournée.
375 400
  */
376 401
 function _image_imagepng($img, $fichier) {
377
-	if (!function_exists('imagepng')) return false;
402
+	if (!function_exists('imagepng')) {
403
+	    return false;
404
+	}
378 405
 	$tmp = $fichier.".tmp";
379 406
 	$ret = imagepng($img,$tmp);
380 407
 	
381 408
 	if(file_exists($tmp)){
382 409
 		$taille_test = getimagesize($tmp);
383
-		if ($taille_test[0] < 1) return false;
410
+		if ($taille_test[0] < 1) {
411
+		    return false;
412
+		}
384 413
 	
385 414
 		spip_unlink($fichier); // le fichier peut deja exister
386 415
 		@rename($tmp, $fichier);
@@ -402,13 +431,17 @@  discard block
 block discarded – undo
402 431
  * 		true si une image est bien retournée.
403 432
  */
404 433
 function _image_imagegif($img,$fichier) {
405
-	if  (!function_exists('imagegif')) return false;
434
+	if  (!function_exists('imagegif')) {
435
+	    return false;
436
+	}
406 437
 	$tmp = $fichier.".tmp";
407 438
 	$ret = imagegif($img,$tmp);
408 439
 	
409 440
 	if(file_exists($tmp)){
410 441
 		$taille_test = getimagesize($tmp);
411
-		if ($taille_test[0] < 1) return false;
442
+		if ($taille_test[0] < 1) {
443
+		    return false;
444
+		}
412 445
 
413 446
 		spip_unlink($fichier); // le fichier peut deja exister
414 447
 		@rename($tmp, $fichier);
@@ -435,13 +468,17 @@  discard block
 block discarded – undo
435 468
  * 		true si une image est bien retournée.
436 469
  */
437 470
 function _image_imagejpg($img,$fichier,$qualite=_IMG_GD_QUALITE) {
438
-	if (!function_exists('imagejpeg')) return false;
471
+	if (!function_exists('imagejpeg')) {
472
+	    return false;
473
+	}
439 474
 	$tmp = $fichier.".tmp";
440 475
 	$ret = imagejpeg($img,$tmp, $qualite);
441 476
 	
442 477
 	if(file_exists($tmp)){
443 478
 		$taille_test = getimagesize($tmp);
444
-		if ($taille_test[0] < 1) return false;
479
+		if ($taille_test[0] < 1) {
480
+		    return false;
481
+		}
445 482
 	
446 483
 		spip_unlink($fichier); // le fichier peut deja exister
447 484
 		@rename($tmp, $fichier);
@@ -499,10 +536,11 @@  discard block
 block discarded – undo
499 536
 			  && ($ret = $fonction($img,$valeurs['fichier_dest'],$qualite)) # on a reussi a creer l'image
500 537
 			  && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
501 538
 			  && !$lock
502
-	  )
503
-		if (@file_exists($valeurs['fichier_dest'])){
539
+	  ) {
540
+			if (@file_exists($valeurs['fichier_dest'])){
504 541
 			// dans tous les cas mettre a jour la taille de l'image finale
505 542
 			list ($valeurs["hauteur_dest"],$valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']);
543
+	}
506 544
 			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
507 545
 			ecrire_fichier($valeurs['fichier_dest'].'.src',serialize($valeurs),true);
508 546
 		}
@@ -577,10 +615,12 @@  discard block
 block discarded – undo
577 615
 	$img = pipeline('post_image_filtrer',$img);
578 616
 
579 617
 	$fichier = extraire_attribut($img, 'src');
580
-	if (($p=strpos($fichier,'?'))!==FALSE)
581
-		$fichier=substr($fichier,0,$p);
582
-	if (strlen($fichier) < 1)
583
-		$fichier = $img;
618
+	if (($p=strpos($fichier,'?'))!==FALSE) {
619
+			$fichier=substr($fichier,0,$p);
620
+	}
621
+	if (strlen($fichier) < 1) {
622
+			$fichier = $img;
623
+	}
584 624
 	# si jamais le fichier final n'a pas ete calcule car suppose temporaire
585 625
 	# et qu'il ne s'agit pas d'une URL
586 626
 	if (strpos($fichier,"://")===false and !@file_exists($fichier)) {
@@ -601,7 +641,9 @@  discard block
 block discarded – undo
601 641
 		$img1 = imagecreatetruecolor($w,$h);
602 642
 		//Conserver la transparence si possible
603 643
 		if(function_exists('ImageCopyResampled')) {
604
-			if (function_exists("imageAntiAlias")) imageAntiAlias($img1,true); 
644
+			if (function_exists("imageAntiAlias")) {
645
+			    imageAntiAlias($img1,true);
646
+			}
605 647
 			@imagealphablending($img1, false); 
606 648
 			@imagesavealpha($img1,true); 
607 649
 			@ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
@@ -616,10 +658,14 @@  discard block
 block discarded – undo
616 658
 
617 659
 // http://doc.spip.org/@image_tag_changer_taille
618 660
 function _image_tag_changer_taille($tag,$width,$height,$style=false){
619
-	if ($style===false) $style = extraire_attribut($tag,'style');
661
+	if ($style===false) {
662
+	    $style = extraire_attribut($tag,'style');
663
+	}
620 664
 	// enlever le width et height du style
621 665
 	$style = preg_replace(",(^|;)\s*(width|height)\s*:\s*[^;]+,ims","",$style);
622
-	if ($style AND $style{0}==';') $style=substr($style,1);
666
+	if ($style AND $style{0}==';') {
667
+	    $style=substr($style,1);
668
+	}
623 669
 	// mettre des attributs de width et height sur les images, 
624 670
 	// ca accelere le rendu du navigateur
625 671
 	// ca permet aux navigateurs de reserver la bonne taille 
@@ -673,8 +719,9 @@  discard block
 block discarded – undo
673 719
 		$tag = str_replace($src,$surcharge['src'],$tag);
674 720
 		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
675 721
 		// pas garanti comme methode, mais mieux que rien
676
-		if (strpos($src,'&') !== false)
677
-			$tag = str_replace(str_replace("&","&amp;",$src),$surcharge['src'],$tag);
722
+		if (strpos($src,'&') !== false) {
723
+					$tag = str_replace(str_replace("&","&amp;",$src),$surcharge['src'],$tag);
724
+		}
678 725
 		$src = $surcharge['src'];
679 726
 		unset($surcharge['src']);
680 727
 	}
@@ -684,12 +731,14 @@  discard block
 block discarded – undo
684 731
 		$class = $surcharge['class'];
685 732
 		unset($surcharge['class']);
686 733
 	}
687
-	if(strlen($class))
688
-		$tag = inserer_attribut($tag,'class',$class);
734
+	if(strlen($class)) {
735
+			$tag = inserer_attribut($tag,'class',$class);
736
+	}
689 737
 
690
-	if (count($surcharge))
691
-		foreach($surcharge as $attribut=>$valeur)
738
+	if (count($surcharge)) {
739
+			foreach($surcharge as $attribut=>$valeur)
692 740
 			$tag = inserer_attribut($tag,$attribut,$valeur);
741
+	}
693 742
 	
694 743
 	$tag = pipeline('image_ecrire_tag_finir',
695 744
 		array(
@@ -720,24 +769,29 @@  discard block
 block discarded – undo
720 769
 	  : false;
721 770
 
722 771
 	// si le doc n'est pas une image, refuser
723
-	if (!$force AND !$img) return;
772
+	if (!$force AND !$img) {
773
+	    return;
774
+	}
724 775
 	$destination = "$destdir/$destfile";
725 776
 
726 777
 	// chercher un cache
727 778
 	$vignette = '';
728
-	if ($test_cache_only AND !$vignette) return;
779
+	if ($test_cache_only AND !$vignette) {
780
+	    return;
781
+	}
729 782
 
730 783
 	// utiliser le cache ?
731
-	if (!$test_cache_only)
732
-	if ($force OR !$vignette OR (@filemtime($vignette) < @filemtime($image))) {
784
+	if (!$test_cache_only) {
785
+		if ($force OR !$vignette OR (@filemtime($vignette) < @filemtime($image))) {
733 786
 
734 787
 		$creation = true;
788
+	}
735 789
 		// calculer la taille
736 790
 		if (($srcWidth=$valeurs['largeur']) && ($srcHeight=$valeurs['hauteur'])){
737
-			if (!($destWidth=$valeurs['largeur_dest']) || !($destHeight=$valeurs['hauteur_dest']))
738
-				list ($destWidth,$destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight);
739
-		}
740
-		elseif ($process == 'convert' OR $process == 'imagick') {
791
+			if (!($destWidth=$valeurs['largeur_dest']) || !($destHeight=$valeurs['hauteur_dest'])) {
792
+							list ($destWidth,$destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight);
793
+			}
794
+		} elseif ($process == 'convert' OR $process == 'imagick') {
741 795
 			$destWidth = $maxWidth;
742 796
 			$destHeight = $maxHeight;
743 797
 		} else {
@@ -772,8 +826,7 @@  discard block
 block discarded – undo
772 826
 				spip_log("echec convert sur $vignette");
773 827
 				return;	// echec commande
774 828
 			}
775
-		}
776
-		else
829
+		} else
777 830
 		// imagick (php4-imagemagick)
778 831
 		if ($process == 'imagick') {
779 832
 
@@ -788,20 +841,22 @@  discard block
 block discarded – undo
788 841
 				spip_log("echec imagick sur $vignette");
789 842
 				return;
790 843
 			}
791
-		}
792
-		else
844
+		} else
793 845
 		// netpbm
794 846
 		if ($process == "netpbm") {
795 847
 			define('_PNMSCALE_COMMAND', 'pnmscale'); // chemin a changer dans mes_options
796
-			if (_PNMSCALE_COMMAND == '') return;
848
+			if (_PNMSCALE_COMMAND == '') {
849
+			    return;
850
+			}
797 851
 			$vignette = $destination.".".$format_sortie;
798 852
 			$pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND);
799 853
 			if ($format == "jpg") {
800 854
 				
801 855
 				$jpegtopnm_command = str_replace("pnmscale", "jpegtopnm", _PNMSCALE_COMMAND);
802 856
 				exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
803
-				if (!($s = @filesize($vignette)))
804
-					spip_unlink($vignette);
857
+				if (!($s = @filesize($vignette))) {
858
+									spip_unlink($vignette);
859
+				}
805 860
 				if (!@file_exists($vignette)) {
806 861
 					spip_log("echec netpbm-jpg sur $vignette");
807 862
 					return;
@@ -809,8 +864,9 @@  discard block
 block discarded – undo
809 864
 			} else if ($format == "gif") {
810 865
 				$giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND);
811 866
 				exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
812
-				if (!($s = @filesize($vignette)))
813
-					spip_unlink($vignette);
867
+				if (!($s = @filesize($vignette))) {
868
+									spip_unlink($vignette);
869
+				}
814 870
 				if (!@file_exists($vignette)) {
815 871
 					spip_log("echec netpbm-gif sur $vignette");
816 872
 					return;
@@ -818,8 +874,9 @@  discard block
 block discarded – undo
818 874
 			} else if ($format == "png") {
819 875
 				$pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND);
820 876
 				exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
821
-				if (!($s = @filesize($vignette)))
822
-					spip_unlink($vignette);
877
+				if (!($s = @filesize($vignette))) {
878
+									spip_unlink($vignette);
879
+				}
823 880
 				if (!@file_exists($vignette)) {
824 881
 					spip_log("echec netpbm-png sur $vignette");
825 882
 					return;
@@ -839,8 +896,9 @@  discard block
 block discarded – undo
839 896
 			}
840 897
 
841 898
 			$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
842
-			if (!function_exists($fonction_imagecreatefrom))
843
-				return '';
899
+			if (!function_exists($fonction_imagecreatefrom)) {
900
+							return '';
901
+			}
844 902
 			$srcImage = @$fonction_imagecreatefrom($image);
845 903
 			if (!$srcImage) { 
846 904
 				spip_log("echec gd1/gd2"); 
@@ -848,10 +906,12 @@  discard block
 block discarded – undo
848 906
 			} 
849 907
 
850 908
 			// Initialisation de l'image destination 
851
-				if ($process == 'gd2' AND $destFormat != "gif") 
852
-				$destImage = ImageCreateTrueColor($destWidth, $destHeight); 
853
-			if (!$destImage) 
854
-				$destImage = ImageCreate($destWidth, $destHeight); 
909
+				if ($process == 'gd2' AND $destFormat != "gif") {
910
+								$destImage = ImageCreateTrueColor($destWidth, $destHeight);
911
+				}
912
+			if (!$destImage) {
913
+							$destImage = ImageCreate($destWidth, $destHeight);
914
+			}
855 915
 
856 916
 			// Recopie de l'image d'origine avec adaptation de la taille 
857 917
 			$ok = false; 
@@ -860,34 +920,44 @@  discard block
 block discarded – undo
860 920
 					// Si un GIF est transparent, 
861 921
 					// fabriquer un PNG transparent  
862 922
 					$transp = imagecolortransparent($srcImage); 
863
-					if ($transp > 0) $destFormat = "png"; 
923
+					if ($transp > 0) {
924
+					    $destFormat = "png";
925
+					}
864 926
 				}
865 927
 				if ($destFormat == "png") { 
866 928
 					// Conserver la transparence 
867
-					if (function_exists("imageAntiAlias")) imageAntiAlias($destImage,true); 
929
+					if (function_exists("imageAntiAlias")) {
930
+					    imageAntiAlias($destImage,true);
931
+					}
868 932
 					@imagealphablending($destImage, false); 
869 933
 					@imagesavealpha($destImage,true); 
870 934
 				}
871 935
 				$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
872 936
 			}
873
-			if (!$ok)
874
-				$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
937
+			if (!$ok) {
938
+							$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
939
+			}
875 940
 
876 941
 			// Sauvegarde de l'image destination
877 942
 			$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
878 943
 			$valeurs['format_dest'] = $format = $destFormat;
879 944
 			_image_gd_output($destImage,$valeurs);
880 945
 
881
-			if ($srcImage)
882
-				ImageDestroy($srcImage);
946
+			if ($srcImage) {
947
+							ImageDestroy($srcImage);
948
+			}
883 949
 			ImageDestroy($destImage);
884 950
 		}
885 951
 	}
886 952
 	$size = @getimagesize($vignette);
887 953
 	// Gaffe: en safe mode, pas d'acces a la vignette,
888 954
 	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
889
-	if ($size[0] < 1) $size[0] = $destWidth;
890
-	if ($size[1] < 1) $size[1] = $destHeight;
955
+	if ($size[0] < 1) {
956
+	    $size[0] = $destWidth;
957
+	}
958
+	if ($size[1] < 1) {
959
+	    $size[1] = $destHeight;
960
+	}
891 961
 	
892 962
 	$retour['width'] = $largeur = $size[0];
893 963
 	$retour['height'] = $hauteur = $size[1];
@@ -912,8 +982,7 @@  discard block
 block discarded – undo
912 982
 	} else if ($ratioWidth < $ratioHeight) {
913 983
 		$destWidth = $srcWidth/$ratioHeight;
914 984
 		$destHeight = $maxHeight;
915
-	}
916
-	else {
985
+	} else {
917 986
 		$destWidth = $maxWidth;
918 987
 		$destHeight = $srcHeight/$ratioWidth;
919 988
 	}
@@ -933,8 +1002,7 @@  discard block
 block discarded – undo
933 1002
 	} else if ($ratioWidth > $ratioHeight) {
934 1003
 		$destWidth = $srcWidth/$ratioHeight;
935 1004
 		$destHeight = $maxHeight;
936
-	}
937
-	else {
1005
+	} else {
938 1006
 		$destWidth = $maxWidth;
939 1007
 		$destHeight = $srcHeight/$ratioWidth;
940 1008
 	}
@@ -945,12 +1013,14 @@  discard block
 block discarded – undo
945 1013
 // http://doc.spip.org/@process_image_reduire
946 1014
 function process_image_reduire($fonction,$img,$taille,$taille_y,$force,$cherche_image,$process){
947 1015
 	$image = false;
948
-	if (($process == 'AUTO') AND isset($GLOBALS['meta']['image_process']))
949
-		$process = $GLOBALS['meta']['image_process'];
1016
+	if (($process == 'AUTO') AND isset($GLOBALS['meta']['image_process'])) {
1017
+			$process = $GLOBALS['meta']['image_process'];
1018
+	}
950 1019
 	# determiner le format de sortie
951 1020
 	$format_sortie = false; // le choix par defaut sera bon
952
-	if ($process == "netpbm") $format_sortie = "jpg";
953
-	else if ($process == 'gd1' OR $process == 'gd2') {
1021
+	if ($process == "netpbm") {
1022
+	    $format_sortie = "jpg";
1023
+	} else if ($process == 'gd1' OR $process == 'gd2') {
954 1024
 		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}",$format_sortie,$fonction);
955 1025
 
956 1026
 		// on verifie que l'extension choisie est bonne (en principe oui)
@@ -958,10 +1028,12 @@  discard block
 block discarded – undo
958 1028
 		if (!in_array($image['format_dest'],$gd_formats)
959 1029
 		  OR ($image['format_dest']=='gif' AND !function_exists('ImageGif'))
960 1030
 		  ) {
961
-			if ($image['format_source'] == 'jpg')
962
-				$formats_sortie = array('jpg','png','gif');
963
-			else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1031
+			if ($image['format_source'] == 'jpg') {
1032
+							$formats_sortie = array('jpg','png','gif');
1033
+			} else {
1034
+			    // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
964 1035
 				$formats_sortie = array('png','jpg','gif');
1036
+			}
965 1037
 			// Choisir le format destination
966 1038
 			// - on sauve de preference en JPEG (meilleure compression)
967 1039
 			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
@@ -970,8 +1042,9 @@  discard block
 block discarded – undo
970 1042
 			$format_sortie = "";
971 1043
 			foreach ($formats_sortie as $fmt) {
972 1044
 				if (in_array($fmt, $gd_formats)) {
973
-					if ($fmt <> "gif" OR function_exists('ImageGif'))
974
-						$format_sortie = $fmt;
1045
+					if ($fmt <> "gif" OR function_exists('ImageGif')) {
1046
+											$format_sortie = $fmt;
1047
+					}
975 1048
 					break;
976 1049
 				}
977 1050
 			}
@@ -979,8 +1052,9 @@  discard block
 block discarded – undo
979 1052
 		}
980 1053
 	}
981 1054
 
982
-	if (!$image)
983
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}",$format_sortie,$fonction);
1055
+	if (!$image) {
1056
+			$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}",$format_sortie,$fonction);
1057
+	}
984 1058
 
985 1059
 	if (!$image OR !$image['largeur'] OR !$image['hauteur']){
986 1060
 		spip_log("image_reduire_src:pas de version locale de $img");
@@ -1004,8 +1078,9 @@  discard block
 block discarded – undo
1004 1078
 		return _image_ecrire_tag($image,array('src'=>$image['fichier_dest']));
1005 1079
 	}
1006 1080
 
1007
-	if ($image['creer']==false && !$force)
1008
-		return _image_ecrire_tag($image,array('src'=>$image['fichier_dest'],'width'=>$image['largeur_dest'],'height'=>$image['hauteur_dest']));
1081
+	if ($image['creer']==false && !$force) {
1082
+			return _image_ecrire_tag($image,array('src'=>$image['fichier_dest'],'width'=>$image['largeur_dest'],'height'=>$image['hauteur_dest']));
1083
+	}
1009 1084
 
1010 1085
 	if (in_array($image["format_source"],array('jpg','gif','png'))){
1011 1086
 		$destWidth = $image['largeur_dest'];
@@ -1026,11 +1101,11 @@  discard block
 block discarded – undo
1026 1101
 		// (pas de filemtime si SAFE MODE)
1027 1102
 		$date = test_espace_prive() ? ('?'.$date) : '';
1028 1103
 		return _image_ecrire_tag($image,array('src'=>"$logo$date",'width'=>$destWidth,'height'=>$destHeight));
1029
-	}
1030
-	else
1031
-		# SVG par exemple ? BMP, tiff ... les redacteurs osent tout!
1104
+	} else {
1105
+			# SVG par exemple ? BMP, tiff ... les redacteurs osent tout!
1032 1106
 		return $img;
1033
-}
1107
+	}
1108
+	}
1034 1109
 
1035 1110
 /**
1036 1111
  * Produire des fichiers au format .ico
Please login to merge, or discard this patch.
Spacing   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
  */
57 57
 function _couleur_hex_to_dec($couleur) {
58 58
 	$couleur = couleur_html_to_hex($couleur);
59
-	$couleur = preg_replace(",^#,","",$couleur);
59
+	$couleur = preg_replace(",^#,", "", $couleur);
60 60
 	$retour["red"] = hexdec(substr($couleur, 0, 2));
61 61
 	$retour["green"] = hexdec(substr($couleur, 2, 2));
62 62
 	$retour["blue"] = hexdec(substr($couleur, 4, 2));
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
  * @return bool
78 78
  * 		true si il faut supprimer le fichier temporaire ; false sinon.
79 79
  */
80
-function statut_effacer_images_temporaires($stat){
80
+function statut_effacer_images_temporaires($stat) {
81 81
 	static $statut = false; // par defaut on grave toute les images
82
-	if ($stat==='get') return $statut;
83
-	$statut = $stat?true:false;
82
+	if ($stat === 'get') return $statut;
83
+	$statut = $stat ?true:false;
84 84
 }
85 85
 
86 86
 
@@ -117,16 +117,16 @@  discard block
 block discarded – undo
117 117
  */
118 118
 function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = NULL, $find_in_path = false) {
119 119
 	static $images_recalcul = array();
120
-	if (strlen($img)==0) return false;
120
+	if (strlen($img) == 0) return false;
121 121
 
122 122
 	$source = trim(extraire_attribut($img, 'src'));
123
-	if (strlen($source) < 1){
123
+	if (strlen($source) < 1) {
124 124
 		$source = $img;
125 125
 		$img = "<img src='$source' />";
126 126
 	}
127 127
 	# gerer img src="data:....base64"
128 128
 	else if (preg_match('@^data:image/(jpe?g|png|gif);base64,(.*)$@isS', $source, $regs)) {
129
-		$local = sous_repertoire(_DIR_VAR,'image-data').md5($regs[2]).'.'.str_replace('jpeg', 'jpg', $regs[1]);
129
+		$local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'.str_replace('jpeg', 'jpg', $regs[1]);
130 130
 		if (!file_exists($local)) {
131 131
 			ecrire_fichier($local, base64_decode($regs[2]));
132 132
 		}
@@ -138,16 +138,16 @@  discard block
 block discarded – undo
138 138
 	}
139 139
 
140 140
 	// les protocoles web prennent au moins 3 lettres
141
-	if (preg_match(';^(\w{3,7}://);', $source)){
141
+	if (preg_match(';^(\w{3,7}://);', $source)) {
142 142
 		include_spip('inc/distant');
143
-		$fichier = _DIR_RACINE . copie_locale($source);
143
+		$fichier = _DIR_RACINE.copie_locale($source);
144 144
 		if (!$fichier) return "";
145
-	}	else {
145
+	} else {
146 146
 		// enlever le timestamp eventuel
147
-		$source=preg_replace(',[?][0-9]+$,','',$source);
148
-		if (strpos($source,"?")!==false
149
-			AND strncmp($source,_DIR_IMG,strlen(_DIR_IMG))==0
150
-			AND file_exists($f=preg_replace(',[?].*$,','',$source))){
147
+		$source = preg_replace(',[?][0-9]+$,', '', $source);
148
+		if (strpos($source, "?") !== false
149
+			AND strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
150
+			AND file_exists($f = preg_replace(',[?].*$,', '', $source))) {
151 151
 			$source = $f;
152 152
 		}
153 153
 		$fichier = $source;
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 		
161 161
 		if ($terminaison == "gif") $terminaison_dest = "png";
162 162
 	}
163
-	if ($forcer_format!==false) $terminaison_dest = $forcer_format;
163
+	if ($forcer_format !== false) $terminaison_dest = $forcer_format;
164 164
 
165 165
 	if (!$terminaison_dest) return false;
166 166
 
@@ -169,16 +169,16 @@  discard block
 block discarded – undo
169 169
 
170 170
 	$nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
171 171
 	$fichier_dest = $nom_fichier;
172
-	if (($find_in_path AND $f=find_in_path($fichier) AND $fichier=$f)
173
-		OR @file_exists($f = $fichier)){
172
+	if (($find_in_path AND $f = find_in_path($fichier) AND $fichier = $f)
173
+		OR @file_exists($f = $fichier)) {
174 174
 		// on passe la balise img a taille image qui exraira les attributs si possible
175 175
 		// au lieu de faire un acces disque sur le fichier
176
-		list ($ret["hauteur"],$ret["largeur"]) = taille_image($find_in_path?$f:$img);
176
+		list ($ret["hauteur"], $ret["largeur"]) = taille_image($find_in_path ? $f : $img);
177 177
 		$date_src = @filemtime($f);
178 178
 	}
179 179
 	elseif (@file_exists($f = "$fichier.src")
180
-		AND lire_fichier($f,$valeurs)
181
-		AND $valeurs=unserialize($valeurs)
180
+		AND lire_fichier($f, $valeurs)
181
+		AND $valeurs = unserialize($valeurs)
182 182
 		AND isset($valeurs["hauteur_dest"])
183 183
 		AND isset($valeurs["largeur_dest"])) {
184 184
 		$ret["hauteur"] = $valeurs["hauteur_dest"];
@@ -199,22 +199,22 @@  discard block
 block discarded – undo
199 199
 	// cas particulier de reduire :
200 200
 	// un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
201 201
 	$cache = "cache-gd2";
202
-	if (substr($effet,0,7)=='reduire') {
203
-		list(,$maxWidth,$maxHeight) = explode('-',$effet);
204
-		list ($destWidth,$destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
202
+	if (substr($effet, 0, 7) == 'reduire') {
203
+		list(,$maxWidth, $maxHeight) = explode('-', $effet);
204
+		list ($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
205 205
 		$ret['largeur_dest'] = $destWidth;
206 206
 		$ret['hauteur_dest'] = $destHeight;
207 207
 		$effet = "L{$destWidth}xH$destHeight";
208 208
 		$cache = "cache-vignettes";
209 209
 		$fichier_dest = basename($fichier_dest);
210
-		if (($ret['largeur']<=$maxWidth)&&($ret['hauteur']<=$maxHeight)){
210
+		if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
211 211
 			// on garde la terminaison initiale car image simplement copiee
212 212
 			// et on postfixe son nom avec un md5 du path
213 213
 			$terminaison_dest = $terminaison;
214
-			$fichier_dest .= '-'.substr(md5("$fichier"),0,5);
214
+			$fichier_dest .= '-'.substr(md5("$fichier"), 0, 5);
215 215
 		}
216 216
 		else
217
-			$fichier_dest .= '-'.substr(md5("$fichier-$effet"),0,5);
217
+			$fichier_dest .= '-'.substr(md5("$fichier-$effet"), 0, 5);
218 218
 		$cache = sous_repertoire(_DIR_VAR, $cache);
219 219
 		$cache = sous_repertoire($cache, $effet);
220 220
 		# cherche un cache existant
@@ -223,29 +223,29 @@  discard block
 block discarded – undo
223 223
 				$terminaison_dest = $fmt;
224 224
 			}*/
225 225
 	}
226
-	else 	{
226
+	else {
227 227
 		$fichier_dest = md5("$fichier-$effet");
228 228
 		$cache = sous_repertoire(_DIR_VAR, $cache);
229 229
 	}
230 230
 	
231
-	$fichier_dest = $cache . $fichier_dest . "." .$terminaison_dest;
231
+	$fichier_dest = $cache.$fichier_dest.".".$terminaison_dest;
232 232
 	
233
-	$GLOBALS["images_calculees"][] =  $fichier_dest;
233
+	$GLOBALS["images_calculees"][] = $fichier_dest;
234 234
 
235 235
 	$creer = true;
236 236
 	// si recalcul des images demande, recalculer chaque image une fois
237
-	if (defined('_VAR_IMAGES') AND _VAR_IMAGES AND !isset($images_recalcul[$fichier_dest])){
237
+	if (defined('_VAR_IMAGES') AND _VAR_IMAGES AND !isset($images_recalcul[$fichier_dest])) {
238 238
 		$images_recalcul[$fichier_dest] = true;
239 239
 	}
240 240
 	else {
241
-		if (@file_exists($f = $fichier_dest)){
242
-			if (filemtime($f)>=$date_src)
241
+		if (@file_exists($f = $fichier_dest)) {
242
+			if (filemtime($f) >= $date_src)
243 243
 				$creer = false;
244 244
 		}
245 245
 		else if (@file_exists($f = "$fichier_dest.src")
246
-		  AND lire_fichier($f,$valeurs)
247
-		  AND $valeurs=unserialize($valeurs)
248
-			AND $valeurs["date"]>=$date_src)
246
+		  AND lire_fichier($f, $valeurs)
247
+		  AND $valeurs = unserialize($valeurs)
248
+			AND $valeurs["date"] >= $date_src)
249 249
 				$creer = false;
250 250
 	}
251 251
 	if ($creer) {
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	}
261 261
 
262 262
 	if ($creer)
263
-		spip_log("filtre image ".($fonction_creation?reset($fonction_creation):'')."[$effet] sur $fichier","images"._LOG_DEBUG);
263
+		spip_log("filtre image ".($fonction_creation ?reset($fonction_creation) : '')."[$effet] sur $fichier", "images"._LOG_DEBUG);
264 264
 
265 265
 	// TODO: si une image png est nommee .jpg, le reconnaitre avec le bon $f
266 266
 	$ret["fonction_imagecreatefrom"] = "_imagecreatefrom".$term_fonction;
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 	$ret["alt"] = extraire_attribut($img, 'alt');
276 276
 	$ret["style"] = extraire_attribut($img, 'style');
277 277
 	$ret["tag"] = $img;
278
-	if ($fonction_creation){
278
+	if ($fonction_creation) {
279 279
 		$ret["reconstruction"] = $fonction_creation;
280 280
 		# ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement 
281 281
 		# cas de image_reduire qui finalement ne reduit pas l'image source
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 		#ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
284 284
 	}
285 285
 
286
-	$ret = pipeline('image_preparer_filtre',array(
286
+	$ret = pipeline('image_preparer_filtre', array(
287 287
 			'args'=>array(
288 288
 				'img'=>$img,
289 289
 				'effet'=>$effet,
@@ -311,12 +311,12 @@  discard block
 block discarded – undo
311 311
  * @return ressource
312 312
  * 		Une ressource de type Image GD.
313 313
  */
314
-function _imagecreatefromjpeg($filename){
314
+function _imagecreatefromjpeg($filename) {
315 315
 	$img = @imagecreatefromjpeg($filename);
316 316
 	if (!$img) {
317
-		spip_log("Erreur lecture imagecreatefromjpeg $filename",_LOG_CRITIQUE);
317
+		spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
318 318
 		erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
319
-		$img = imagecreate(10,10);
319
+		$img = imagecreate(10, 10);
320 320
 	}
321 321
 	return $img;
322 322
 }
@@ -331,12 +331,12 @@  discard block
 block discarded – undo
331 331
  * @return ressource
332 332
  * 		Une ressource de type Image GD.
333 333
  */
334
-function _imagecreatefrompng($filename){
334
+function _imagecreatefrompng($filename) {
335 335
 	$img = @imagecreatefrompng($filename);
336 336
 	if (!$img) {
337
-		spip_log("Erreur lecture imagecreatefrompng $filename",_LOG_CRITIQUE);
337
+		spip_log("Erreur lecture imagecreatefrompng $filename", _LOG_CRITIQUE);
338 338
 		erreur_squelette("Erreur lecture imagecreatefrompng $filename");
339
-		$img = imagecreate(10,10);
339
+		$img = imagecreate(10, 10);
340 340
 	}
341 341
 	return $img;
342 342
 }
@@ -351,12 +351,12 @@  discard block
 block discarded – undo
351 351
  * @return ressource
352 352
  * 		Une ressource de type Image GD.
353 353
  */
354
-function _imagecreatefromgif($filename){
354
+function _imagecreatefromgif($filename) {
355 355
 	$img = @imagecreatefromgif($filename);
356 356
 	if (!$img) {
357
-		spip_log("Erreur lecture imagecreatefromgif $filename",_LOG_CRITIQUE);
357
+		spip_log("Erreur lecture imagecreatefromgif $filename", _LOG_CRITIQUE);
358 358
 		erreur_squelette("Erreur lecture imagecreatefromgif $filename");
359
-		$img = imagecreate(10,10);
359
+		$img = imagecreate(10, 10);
360 360
 	}
361 361
 	return $img;
362 362
 }
@@ -376,9 +376,9 @@  discard block
 block discarded – undo
376 376
 function _image_imagepng($img, $fichier) {
377 377
 	if (!function_exists('imagepng')) return false;
378 378
 	$tmp = $fichier.".tmp";
379
-	$ret = imagepng($img,$tmp);
379
+	$ret = imagepng($img, $tmp);
380 380
 	
381
-	if(file_exists($tmp)){
381
+	if (file_exists($tmp)) {
382 382
 		$taille_test = getimagesize($tmp);
383 383
 		if ($taille_test[0] < 1) return false;
384 384
 	
@@ -401,12 +401,12 @@  discard block
 block discarded – undo
401 401
  * 		false si l'image créée a une largeur nulle ou n'existe pas;
402 402
  * 		true si une image est bien retournée.
403 403
  */
404
-function _image_imagegif($img,$fichier) {
405
-	if  (!function_exists('imagegif')) return false;
404
+function _image_imagegif($img, $fichier) {
405
+	if (!function_exists('imagegif')) return false;
406 406
 	$tmp = $fichier.".tmp";
407
-	$ret = imagegif($img,$tmp);
407
+	$ret = imagegif($img, $tmp);
408 408
 	
409
-	if(file_exists($tmp)){
409
+	if (file_exists($tmp)) {
410 410
 		$taille_test = getimagesize($tmp);
411 411
 		if ($taille_test[0] < 1) return false;
412 412
 
@@ -434,12 +434,12 @@  discard block
 block discarded – undo
434 434
  * 		false si l'image créée a une largeur nulle ou n'existe pas ;
435 435
  * 		true si une image est bien retournée.
436 436
  */
437
-function _image_imagejpg($img,$fichier,$qualite=_IMG_GD_QUALITE) {
437
+function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) {
438 438
 	if (!function_exists('imagejpeg')) return false;
439 439
 	$tmp = $fichier.".tmp";
440
-	$ret = imagejpeg($img,$tmp, $qualite);
440
+	$ret = imagejpeg($img, $tmp, $qualite);
441 441
 	
442
-	if(file_exists($tmp)){
442
+	if (file_exists($tmp)) {
443 443
 		$taille_test = getimagesize($tmp);
444 444
 		if ($taille_test[0] < 1) return false;
445 445
 	
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
  * 		true si le traitement GD s'est bien finalisé ;
488 488
  * 		false sinon.
489 489
  */
490
-function _image_gd_output($img,$valeurs, $qualite=_IMG_GD_QUALITE){
490
+function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE) {
491 491
 	$fonction = "_image_image".$valeurs['format_dest'];
492 492
 	$ret = false;
493 493
 	#un flag pour reperer les images gravees
@@ -496,33 +496,33 @@  discard block
 block discarded – undo
496 496
 	  OR (@file_exists($valeurs['fichier_dest']) AND !@file_exists($valeurs['fichier_dest'].'.src'));
497 497
 	if (
498 498
 	     function_exists($fonction) 
499
-			  && ($ret = $fonction($img,$valeurs['fichier_dest'],$qualite)) # on a reussi a creer l'image
499
+			  && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
500 500
 			  && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
501 501
 			  && !$lock
502 502
 	  )
503
-		if (@file_exists($valeurs['fichier_dest'])){
503
+		if (@file_exists($valeurs['fichier_dest'])) {
504 504
 			// dans tous les cas mettre a jour la taille de l'image finale
505
-			list ($valeurs["hauteur_dest"],$valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']);
505
+			list ($valeurs["hauteur_dest"], $valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']);
506 506
 			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
507
-			ecrire_fichier($valeurs['fichier_dest'].'.src',serialize($valeurs),true);
507
+			ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true);
508 508
 		}
509 509
 	return $ret;
510 510
 }
511 511
 
512 512
 // http://doc.spip.org/@reconstruire_image_intermediaire
513
-function reconstruire_image_intermediaire($fichier_manquant){
513
+function reconstruire_image_intermediaire($fichier_manquant) {
514 514
 	$reconstruire = array();
515 515
 	$fichier = $fichier_manquant;
516
-	while (strpos($fichier,"://")===false
516
+	while (strpos($fichier, "://") === false
517 517
 		and !@file_exists($fichier)
518
-		AND lire_fichier($src = "$fichier.src",$source)
519
-		AND $valeurs=unserialize($source)
518
+		AND lire_fichier($src = "$fichier.src", $source)
519
+		AND $valeurs = unserialize($source)
520 520
     AND ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
521 521
     ) {
522 522
 			spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
523 523
 			$reconstruire[] = $valeurs['reconstruction'];
524 524
    }
525
-	while (count($reconstruire)){
525
+	while (count($reconstruire)) {
526 526
 		$r = array_pop($reconstruire);
527 527
 		$fonction = $r[0];
528 528
 		$args = $r[1];
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
  *     Chemin du fichier d'image calculé
551 551
  **/
552 552
 function ramasse_miettes($fichier) {
553
-	if (strpos($fichier,"://")!==false
553
+	if (strpos($fichier, "://") !== false
554 554
 		or !lire_fichier($src = "$fichier.src", $source)
555 555
 		or !$valeurs = unserialize($source)
556 556
 	) {
@@ -559,9 +559,9 @@  discard block
 block discarded – undo
559 559
 	spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
560 560
 	while (
561 561
 	     ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
562
-		AND (substr($fichier,0,strlen(_DIR_VAR))==_DIR_VAR) # et est dans local
563
-		AND (lire_fichier($src = "$fichier.src",$source)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
564
-		AND ($valeurs=unserialize($source))  # et valide
562
+		AND (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
563
+		AND (lire_fichier($src = "$fichier.src", $source)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
564
+		AND ($valeurs = unserialize($source))  # et valide
565 565
 		) {
566 566
 		# on efface le fichier
567 567
 		spip_unlink($fichier);
@@ -571,19 +571,19 @@  discard block
 block discarded – undo
571 571
 }
572 572
 
573 573
 // http://doc.spip.org/@image_graver
574
-function image_graver($img){
574
+function image_graver($img) {
575 575
 	// appeler le filtre post_image_filtrer qui permet de faire
576 576
 	// des traitements auto a la fin d'une serie de filtres
577
-	$img = pipeline('post_image_filtrer',$img);
577
+	$img = pipeline('post_image_filtrer', $img);
578 578
 
579 579
 	$fichier = extraire_attribut($img, 'src');
580
-	if (($p=strpos($fichier,'?'))!==FALSE)
581
-		$fichier=substr($fichier,0,$p);
580
+	if (($p = strpos($fichier, '?')) !== FALSE)
581
+		$fichier = substr($fichier, 0, $p);
582 582
 	if (strlen($fichier) < 1)
583 583
 		$fichier = $img;
584 584
 	# si jamais le fichier final n'a pas ete calcule car suppose temporaire
585 585
 	# et qu'il ne s'agit pas d'une URL
586
-	if (strpos($fichier,"://")===false and !@file_exists($fichier)) {
586
+	if (strpos($fichier, "://") === false and !@file_exists($fichier)) {
587 587
 		reconstruire_image_intermediaire($fichier);
588 588
 	}
589 589
 	ramasse_miettes($fichier);
@@ -598,15 +598,15 @@  discard block
 block discarded – undo
598 598
 	if ($img AND !imageistruecolor($img) AND function_exists('imagecreatetruecolor')) {
599 599
 		$w = imagesx($img);
600 600
 		$h = imagesy($img);
601
-		$img1 = imagecreatetruecolor($w,$h);
601
+		$img1 = imagecreatetruecolor($w, $h);
602 602
 		//Conserver la transparence si possible
603
-		if(function_exists('ImageCopyResampled')) {
604
-			if (function_exists("imageAntiAlias")) imageAntiAlias($img1,true); 
603
+		if (function_exists('ImageCopyResampled')) {
604
+			if (function_exists("imageAntiAlias")) imageAntiAlias($img1, true); 
605 605
 			@imagealphablending($img1, false); 
606
-			@imagesavealpha($img1,true); 
606
+			@imagesavealpha($img1, true); 
607 607
 			@ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
608 608
 		} else {
609
-			imagecopy($img1,$img,0,0,0,0,$w,$h);
609
+			imagecopy($img1, $img, 0, 0, 0, 0, $w, $h);
610 610
 		}
611 611
 
612 612
 		$img = $img1;
@@ -615,81 +615,81 @@  discard block
 block discarded – undo
615 615
 }
616 616
 
617 617
 // http://doc.spip.org/@image_tag_changer_taille
618
-function _image_tag_changer_taille($tag,$width,$height,$style=false){
619
-	if ($style===false) $style = extraire_attribut($tag,'style');
618
+function _image_tag_changer_taille($tag, $width, $height, $style = false) {
619
+	if ($style === false) $style = extraire_attribut($tag, 'style');
620 620
 	// enlever le width et height du style
621
-	$style = preg_replace(",(^|;)\s*(width|height)\s*:\s*[^;]+,ims","",$style);
622
-	if ($style AND $style{0}==';') $style=substr($style,1);
621
+	$style = preg_replace(",(^|;)\s*(width|height)\s*:\s*[^;]+,ims", "", $style);
622
+	if ($style AND $style{0} == ';') $style = substr($style, 1);
623 623
 	// mettre des attributs de width et height sur les images, 
624 624
 	// ca accelere le rendu du navigateur
625 625
 	// ca permet aux navigateurs de reserver la bonne taille 
626 626
 	// quand on a desactive l'affichage des images.
627
-	$tag = inserer_attribut($tag,'width',$width);
628
-	$tag = inserer_attribut($tag,'height',$height);
627
+	$tag = inserer_attribut($tag, 'width', $width);
628
+	$tag = inserer_attribut($tag, 'height', $height);
629 629
 	
630 630
 	// Ancien style inline pour IE6 mais qui casse la possibilité de surcharger en CSS
631 631
 	//$style = "height:".$height."px;width:".$width."px;".$style;
632 632
 	
633 633
 	// attributs deprecies. Transformer en CSS
634
-	if ($espace = extraire_attribut($tag, 'hspace')){
634
+	if ($espace = extraire_attribut($tag, 'hspace')) {
635 635
 		$style = "margin:${espace}px;".$style;
636
-		$tag = inserer_attribut($tag,'hspace','');
636
+		$tag = inserer_attribut($tag, 'hspace', '');
637 637
 	}
638
-	$tag = inserer_attribut($tag,'style',$style, true, $style ? false : true);
638
+	$tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true);
639 639
 	return $tag;
640 640
 }
641 641
 
642 642
 // function d'ecriture du de la balise img en sortie des filtre image
643 643
 // reprend le tag initial et surcharge les tags modifies
644
-function _image_ecrire_tag($valeurs,$surcharge=array()){
645
-	$valeurs = pipeline('image_ecrire_tag_preparer',$valeurs);
644
+function _image_ecrire_tag($valeurs, $surcharge = array()) {
645
+	$valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
646 646
 
647
-	$tag = 	str_replace(">","/>",str_replace("/>",">",$valeurs['tag'])); // fermer les tags img pas bien fermes;
647
+	$tag = str_replace(">", "/>", str_replace("/>", ">", $valeurs['tag'])); // fermer les tags img pas bien fermes;
648 648
 	
649 649
 	// le style
650 650
 	$style = $valeurs['style'];
651
-	if (isset($surcharge['style'])){
651
+	if (isset($surcharge['style'])) {
652 652
 		$style = $surcharge['style'];
653 653
 		unset($surcharge['style']);
654 654
 	}
655 655
 	
656 656
 	// traiter specifiquement la largeur et la hauteur
657 657
 	$width = $valeurs['largeur'];
658
-	if (isset($surcharge['width'])){
658
+	if (isset($surcharge['width'])) {
659 659
 		$width = $surcharge['width'];
660 660
 		unset($surcharge['width']);
661 661
 	}
662 662
 	$height = $valeurs['hauteur'];
663
-	if (isset($surcharge['height'])){
663
+	if (isset($surcharge['height'])) {
664 664
 		$height = $surcharge['height'];
665 665
 		unset($surcharge['height']);
666 666
 	}
667 667
 
668
-	$tag = _image_tag_changer_taille($tag,$width,$height,$style);
668
+	$tag = _image_tag_changer_taille($tag, $width, $height, $style);
669 669
 	// traiter specifiquement le src qui peut etre repris dans un onmouseout
670 670
 	// on remplace toute les ref a src dans le tag
671
-	$src = extraire_attribut($tag,'src');
672
-	if (isset($surcharge['src'])){
673
-		$tag = str_replace($src,$surcharge['src'],$tag);
671
+	$src = extraire_attribut($tag, 'src');
672
+	if (isset($surcharge['src'])) {
673
+		$tag = str_replace($src, $surcharge['src'], $tag);
674 674
 		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
675 675
 		// pas garanti comme methode, mais mieux que rien
676
-		if (strpos($src,'&') !== false)
677
-			$tag = str_replace(str_replace("&","&amp;",$src),$surcharge['src'],$tag);
676
+		if (strpos($src, '&') !== false)
677
+			$tag = str_replace(str_replace("&", "&amp;", $src), $surcharge['src'], $tag);
678 678
 		$src = $surcharge['src'];
679 679
 		unset($surcharge['src']);
680 680
 	}
681 681
 
682 682
 	$class = $valeurs['class'];
683
-	if (isset($surcharge['class'])){
683
+	if (isset($surcharge['class'])) {
684 684
 		$class = $surcharge['class'];
685 685
 		unset($surcharge['class']);
686 686
 	}
687
-	if(strlen($class))
688
-		$tag = inserer_attribut($tag,'class',$class);
687
+	if (strlen($class))
688
+		$tag = inserer_attribut($tag, 'class', $class);
689 689
 
690 690
 	if (count($surcharge))
691
-		foreach($surcharge as $attribut=>$valeur)
692
-			$tag = inserer_attribut($tag,$attribut,$valeur);
691
+		foreach ($surcharge as $attribut=>$valeur)
692
+			$tag = inserer_attribut($tag, $attribut, $valeur);
693 693
 	
694 694
 	$tag = pipeline('image_ecrire_tag_finir',
695 695
 		array(
@@ -704,19 +704,19 @@  discard block
 block discarded – undo
704 704
 	return $tag;
705 705
 }
706 706
 
707
-function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process='AUTO', $force=false, $test_cache_only = false) {
707
+function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false, $test_cache_only = false) {
708 708
 	// ordre de preference des formats graphiques pour creer les vignettes
709 709
 	// le premier format disponible, selon la methode demandee, est utilise
710 710
 	$image = $valeurs['fichier'];
711 711
 	$format = $valeurs['format_source'];
712 712
 	$destdir = dirname($valeurs['fichier_dest']);
713
-	$destfile = basename($valeurs['fichier_dest'],".".$valeurs["format_dest"]);
713
+	$destfile = basename($valeurs['fichier_dest'], ".".$valeurs["format_dest"]);
714 714
 	
715 715
 	$format_sortie = $valeurs['format_dest'];
716 716
 	
717 717
 	// liste des formats qu'on sait lire
718 718
 	$img = isset($GLOBALS['meta']['formats_graphiques'])
719
-	  ? (strpos($GLOBALS['meta']['formats_graphiques'], $format)!==false)
719
+	  ? (strpos($GLOBALS['meta']['formats_graphiques'], $format) !== false)
720 720
 	  : false;
721 721
 
722 722
 	// si le doc n'est pas une image, refuser
@@ -733,9 +733,9 @@  discard block
 block discarded – undo
733 733
 
734 734
 		$creation = true;
735 735
 		// calculer la taille
736
-		if (($srcWidth=$valeurs['largeur']) && ($srcHeight=$valeurs['hauteur'])){
737
-			if (!($destWidth=$valeurs['largeur_dest']) || !($destHeight=$valeurs['hauteur_dest']))
738
-				list ($destWidth,$destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight);
736
+		if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
737
+			if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest']))
738
+				list ($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight);
739 739
 		}
740 740
 		elseif ($process == 'convert' OR $process == 'imagick') {
741 741
 			$destWidth = $maxWidth;
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
 		// imagemagick en ligne de commande
756 756
 		else if ($process == 'convert') {
757 757
 			define('_CONVERT_COMMAND', 'convert');
758
-			define ('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -resize %xx%y! %src %dest');
758
+			define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -resize %xx%y! %src %dest');
759 759
 			$vignette = $destination.".".$format_sortie;
760 760
 			$commande = str_replace(
761 761
 				array('%x', '%y', '%src', '%dest'),
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
 			exec($commande);
771 771
 			if (!@file_exists($vignette)) {
772 772
 				spip_log("echec convert sur $vignette");
773
-				return;	// echec commande
773
+				return; // echec commande
774 774
 			}
775 775
 		}
776 776
 		else
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
 
782 782
 			$imagick = new Imagick();
783 783
 			$imagick->readImage($image);
784
-			$imagick->resizeImage($destWidth, $destHeight, Imagick::FILTER_LANCZOS, 1 );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
784
+			$imagick->resizeImage($destWidth, $destHeight, Imagick::FILTER_LANCZOS, 1); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
785 785
 			$imagick->writeImage($vignette);
786 786
 
787 787
 			if (!@file_exists($vignette)) {
@@ -828,8 +828,8 @@  discard block
 block discarded – undo
828 828
 		}
829 829
 		// gd ou gd2
830 830
 		else if ($process == 'gd1' OR $process == 'gd2') {
831
-			if (_IMG_GD_MAX_PIXELS && $srcWidth*$srcHeight>_IMG_GD_MAX_PIXELS){
832
-				spip_log("vignette gd1/gd2 impossible : ".$srcWidth*$srcHeight."pixels");
831
+			if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
832
+				spip_log("vignette gd1/gd2 impossible : ".$srcWidth * $srcHeight."pixels");
833 833
 				return;
834 834
 			}
835 835
 			$destFormat = $format_sortie;
@@ -864,9 +864,9 @@  discard block
 block discarded – undo
864 864
 				}
865 865
 				if ($destFormat == "png") { 
866 866
 					// Conserver la transparence 
867
-					if (function_exists("imageAntiAlias")) imageAntiAlias($destImage,true); 
867
+					if (function_exists("imageAntiAlias")) imageAntiAlias($destImage, true); 
868 868
 					@imagealphablending($destImage, false); 
869
-					@imagesavealpha($destImage,true); 
869
+					@imagesavealpha($destImage, true); 
870 870
 				}
871 871
 				$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
872 872
 			}
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
 			// Sauvegarde de l'image destination
877 877
 			$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
878 878
 			$valeurs['format_dest'] = $format = $destFormat;
879
-			_image_gd_output($destImage,$valeurs);
879
+			_image_gd_output($destImage, $valeurs);
880 880
 
881 881
 			if ($srcImage)
882 882
 				ImageDestroy($srcImage);
@@ -902,48 +902,48 @@  discard block
 block discarded – undo
902 902
 
903 903
 // Calculer le ratio
904 904
 // http://doc.spip.org/@image_ratio
905
-function _image_ratio ($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
906
-	$ratioWidth = $srcWidth/$maxWidth;
907
-	$ratioHeight = $srcHeight/$maxHeight;
905
+function _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
906
+	$ratioWidth = $srcWidth / $maxWidth;
907
+	$ratioHeight = $srcHeight / $maxHeight;
908 908
 	
909
-	if ($ratioWidth <=1 AND $ratioHeight <=1) {
909
+	if ($ratioWidth <= 1 AND $ratioHeight <= 1) {
910 910
 		$destWidth = $srcWidth;
911 911
 		$destHeight = $srcHeight;
912 912
 	} else if ($ratioWidth < $ratioHeight) {
913
-		$destWidth = $srcWidth/$ratioHeight;
913
+		$destWidth = $srcWidth / $ratioHeight;
914 914
 		$destHeight = $maxHeight;
915 915
 	}
916 916
 	else {
917 917
 		$destWidth = $maxWidth;
918
-		$destHeight = $srcHeight/$ratioWidth;
918
+		$destHeight = $srcHeight / $ratioWidth;
919 919
 	}
920
-	return array (ceil($destWidth), ceil($destHeight),
921
-		max($ratioWidth,$ratioHeight));
920
+	return array(ceil($destWidth), ceil($destHeight),
921
+		max($ratioWidth, $ratioHeight));
922 922
 }
923 923
 
924 924
 // Calculer le ratio ajuste sur la plus petite dimension
925 925
 // http://doc.spip.org/@ratio_passe_partout
926
-function ratio_passe_partout ($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
927
-	$ratioWidth = $srcWidth/$maxWidth;
928
-	$ratioHeight = $srcHeight/$maxHeight;
926
+function ratio_passe_partout($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
927
+	$ratioWidth = $srcWidth / $maxWidth;
928
+	$ratioHeight = $srcHeight / $maxHeight;
929 929
 
930
-	if ($ratioWidth <=1 AND $ratioHeight <=1) {
930
+	if ($ratioWidth <= 1 AND $ratioHeight <= 1) {
931 931
 		$destWidth = $srcWidth;
932 932
 		$destHeight = $srcHeight;
933 933
 	} else if ($ratioWidth > $ratioHeight) {
934
-		$destWidth = $srcWidth/$ratioHeight;
934
+		$destWidth = $srcWidth / $ratioHeight;
935 935
 		$destHeight = $maxHeight;
936 936
 	}
937 937
 	else {
938 938
 		$destWidth = $maxWidth;
939
-		$destHeight = $srcHeight/$ratioWidth;
939
+		$destHeight = $srcHeight / $ratioWidth;
940 940
 	}
941
-	return array (ceil($destWidth), ceil($destHeight),
942
-		min($ratioWidth,$ratioHeight));
941
+	return array(ceil($destWidth), ceil($destHeight),
942
+		min($ratioWidth, $ratioHeight));
943 943
 }
944 944
 
945 945
 // http://doc.spip.org/@process_image_reduire
946
-function process_image_reduire($fonction,$img,$taille,$taille_y,$force,$cherche_image,$process){
946
+function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $cherche_image, $process) {
947 947
 	$image = false;
948 948
 	if (($process == 'AUTO') AND isset($GLOBALS['meta']['image_process']))
949 949
 		$process = $GLOBALS['meta']['image_process'];
@@ -951,17 +951,17 @@  discard block
 block discarded – undo
951 951
 	$format_sortie = false; // le choix par defaut sera bon
952 952
 	if ($process == "netpbm") $format_sortie = "jpg";
953 953
 	else if ($process == 'gd1' OR $process == 'gd2') {
954
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}",$format_sortie,$fonction);
954
+		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction);
955 955
 
956 956
 		// on verifie que l'extension choisie est bonne (en principe oui)
957
-		$gd_formats = explode(',',$GLOBALS['meta']["gd_formats"]);
958
-		if (!in_array($image['format_dest'],$gd_formats)
959
-		  OR ($image['format_dest']=='gif' AND !function_exists('ImageGif'))
957
+		$gd_formats = explode(',', $GLOBALS['meta']["gd_formats"]);
958
+		if (!in_array($image['format_dest'], $gd_formats)
959
+		  OR ($image['format_dest'] == 'gif' AND !function_exists('ImageGif'))
960 960
 		  ) {
961 961
 			if ($image['format_source'] == 'jpg')
962
-				$formats_sortie = array('jpg','png','gif');
962
+				$formats_sortie = array('jpg', 'png', 'gif');
963 963
 			else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
964
-				$formats_sortie = array('png','jpg','gif');
964
+				$formats_sortie = array('png', 'jpg', 'gif');
965 965
 			// Choisir le format destination
966 966
 			// - on sauve de preference en JPEG (meilleure compression)
967 967
 			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
@@ -980,15 +980,15 @@  discard block
 block discarded – undo
980 980
 	}
981 981
 
982 982
 	if (!$image)
983
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}",$format_sortie,$fonction);
983
+		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction);
984 984
 
985
-	if (!$image OR !$image['largeur'] OR !$image['hauteur']){
985
+	if (!$image OR !$image['largeur'] OR !$image['hauteur']) {
986 986
 		spip_log("image_reduire_src:pas de version locale de $img");
987 987
 		// on peut resizer en mode html si on dispose des elements
988 988
 		if ($srcw = extraire_attribut($img, 'width')
989 989
 		AND $srch = extraire_attribut($img, 'height')) {
990
-			list($w,$h) = _image_ratio($srcw, $srch, $taille, $taille_y);
991
-			return _image_tag_changer_taille($img,$w,$h);
990
+			list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y);
991
+			return _image_tag_changer_taille($img, $w, $h);
992 992
 		}
993 993
 		// la on n'a pas d'infos sur l'image source... on refile le truc a css
994 994
 		// sous la forme style='max-width: NNpx;'
@@ -997,22 +997,22 @@  discard block
 block discarded – undo
997 997
 	}
998 998
 
999 999
 	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1000
-	if (($image['largeur']<=$taille)&&($image['hauteur']<=$taille_y)){
1001
-		if ($image['creer']){
1000
+	if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1001
+		if ($image['creer']) {
1002 1002
 			@copy($image['fichier'], $image['fichier_dest']);
1003 1003
 		}
1004
-		return _image_ecrire_tag($image,array('src'=>$image['fichier_dest']));
1004
+		return _image_ecrire_tag($image, array('src'=>$image['fichier_dest']));
1005 1005
 	}
1006 1006
 
1007
-	if ($image['creer']==false && !$force)
1008
-		return _image_ecrire_tag($image,array('src'=>$image['fichier_dest'],'width'=>$image['largeur_dest'],'height'=>$image['hauteur_dest']));
1007
+	if ($image['creer'] == false && !$force)
1008
+		return _image_ecrire_tag($image, array('src'=>$image['fichier_dest'], 'width'=>$image['largeur_dest'], 'height'=>$image['hauteur_dest']));
1009 1009
 
1010
-	if (in_array($image["format_source"],array('jpg','gif','png'))){
1010
+	if (in_array($image["format_source"], array('jpg', 'gif', 'png'))) {
1011 1011
 		$destWidth = $image['largeur_dest'];
1012 1012
 		$destHeight = $image['hauteur_dest'];
1013 1013
 		$logo = $image['fichier'];
1014 1014
 		$date = $image["date_src"];
1015
-		$preview = _image_creer_vignette($image, $taille, $taille_y,$process,$force);
1015
+		$preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1016 1016
 
1017 1017
 		if ($preview && $preview['fichier']) {
1018 1018
 			$logo = $preview['fichier'];
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
 		// quand on fait supprimer/reuploader un logo
1026 1026
 		// (pas de filemtime si SAFE MODE)
1027 1027
 		$date = test_espace_prive() ? ('?'.$date) : '';
1028
-		return _image_ecrire_tag($image,array('src'=>"$logo$date",'width'=>$destWidth,'height'=>$destHeight));
1028
+		return _image_ecrire_tag($image, array('src'=>"$logo$date", 'width'=>$destWidth, 'height'=>$destHeight));
1029 1029
 	}
1030 1030
 	else
1031 1031
 		# SVG par exemple ? BMP, tiff ... les redacteurs osent tout!
@@ -1060,7 +1060,7 @@  discard block
 block discarded – undo
1060 1060
 	 * @param int $minbytes
1061 1061
 	 * @return string
1062 1062
 	 */
1063
-	public static function LittleEndian2String($number, $minbytes=1) {
1063
+	public static function LittleEndian2String($number, $minbytes = 1) {
1064 1064
 		$intstring = '';
1065 1065
 		while ($number > 0) {
1066 1066
 			$intstring = $intstring.chr($number & 255);
@@ -1078,7 +1078,7 @@  discard block
 block discarded – undo
1078 1078
 
1079 1079
 			$ImageWidths[$key]  = ImageSX($gd_image);
1080 1080
 			$ImageHeights[$key] = ImageSY($gd_image);
1081
-			$bpp[$key]		  = ImageIsTrueColor($gd_image) ? 32 : 24;
1081
+			$bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1082 1082
 			$totalcolors[$key]  = ImageColorsTotal($gd_image);
1083 1083
 
1084 1084
 			$icXOR[$key] = '';
@@ -1121,42 +1121,42 @@  discard block
 block discarded – undo
1121 1121
 
1122 1122
 			// BITMAPINFOHEADER - 40 bytes
1123 1123
 			$BitmapInfoHeader[$key]  = '';
1124
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";							  // DWORD  biSize;
1125
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);	  // LONG   biWidth;
1124
+			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD  biSize;
1125
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG   biWidth;
1126 1126
 			// The biHeight member specifies the combined
1127 1127
 			// height of the XOR and AND masks.
1128 1128
 			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1129
-			$BitmapInfoHeader[$key] .= "\x01\x00";									  // WORD   biPlanes;
1130
-			   $BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00";						  // wBitCount;
1131
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";							  // DWORD  biCompression;
1132
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);			// DWORD  biSizeImage;
1133
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";							  // LONG   biXPelsPerMeter;
1134
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";							  // LONG   biYPelsPerMeter;
1135
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";							  // DWORD  biClrUsed;
1136
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";							  // DWORD  biClrImportant;
1129
+			$BitmapInfoHeader[$key] .= "\x01\x00"; // WORD   biPlanes;
1130
+			   $BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount;
1131
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biCompression;
1132
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD  biSizeImage;
1133
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biXPelsPerMeter;
1134
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biYPelsPerMeter;
1135
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrUsed;
1136
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrImportant;
1137 1137
 		}
1138 1138
 
1139 1139
 
1140
-		$icondata  = "\x00\x00";									  // idReserved;   // Reserved (must be 0)
1141
-		$icondata .= "\x01\x00";									  // idType;	   // Resource Type (1 for icons)
1142
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1140
+		$icondata  = "\x00\x00"; // idReserved;   // Reserved (must be 0)
1141
+		$icondata .= "\x01\x00"; // idType;	   // Resource Type (1 for icons)
1142
+		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount;	  // How many images?
1143 1143
 
1144 1144
 		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1145 1145
 		foreach ($gd_image_array as $key => $gd_image) {
1146 1146
 			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1147 1147
 
1148
-			$icondata .= chr($ImageWidths[$key]);					 // bWidth;		  // Width, in pixels, of the image
1149
-			$icondata .= chr($ImageHeights[$key]);					// bHeight;		 // Height, in pixels, of the image
1150
-			$icondata .= chr($totalcolors[$key]);					 // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1151
-			$icondata .= "\x00";									  // bReserved;	   // Reserved ( must be 0)
1148
+			$icondata .= chr($ImageWidths[$key]); // bWidth;		  // Width, in pixels, of the image
1149
+			$icondata .= chr($ImageHeights[$key]); // bHeight;		 // Height, in pixels, of the image
1150
+			$icondata .= chr($totalcolors[$key]); // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1151
+			$icondata .= "\x00"; // bReserved;	   // Reserved ( must be 0)
1152 1152
 
1153
-			$icondata .= "\x01\x00";								  // wPlanes;		 // Color Planes
1154
-			$icondata .= chr($bpp[$key])."\x00";					  // wBitCount;	   // Bits per pixel
1153
+			$icondata .= "\x01\x00"; // wPlanes;		 // Color Planes
1154
+			$icondata .= chr($bpp[$key])."\x00"; // wBitCount;	   // Bits per pixel
1155 1155
 
1156 1156
 			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1157
-			$icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes, 4);	   // dwBytesInRes;	// How many bytes in this resource?
1157
+			$icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes, 4); // dwBytesInRes;	// How many bytes in this resource?
1158 1158
 
1159
-			$icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset, 4);	  // dwImageOffset;   // Where in the file is this image?
1159
+			$icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset, 4); // dwImageOffset;   // Where in the file is this image?
1160 1160
 			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1161 1161
 			$dwImageOffset += strlen($icXOR[$key]);
1162 1162
 			$dwImageOffset += strlen($icAND[$key]);
Please login to merge, or discard this patch.
ecrire/inc/flock.php 4 patches
Doc Comments   +9 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,6 +26,10 @@  discard block
 block discarded – undo
26 26
 
27 27
 $GLOBALS['liste_verrous'] = array();
28 28
 // http://doc.spip.org/@spip_fopen_lock
29
+/**
30
+ * @param string $mode
31
+ * @param integer $verrou
32
+ */
29 33
 function spip_fopen_lock($fichier,$mode,$verrou){
30 34
 	if (_SPIP_LOCK_MODE==1){
31 35
 		if ($fl = @fopen($fichier,$mode))
@@ -202,7 +206,7 @@  discard block
 block discarded – undo
202 206
  * Ecrire un contenu dans un fichier encapsule en php pour en empecher l'acces en l'absence
203 207
  * de htaccess
204 208
  * @param string $fichier
205
- * @param <type> $contenu
209
+ * @param string $contenu
206 210
  * @param <type> $ecrire_quand_meme
207 211
  * @param <type> $truncate 
208 212
  */
@@ -250,6 +254,9 @@  discard block
 block discarded – undo
250 254
 //
251 255
 
252 256
 // http://doc.spip.org/@jeune_fichier
257
+/**
258
+ * @param integer $n
259
+ */
253 260
 function jeune_fichier($fichier, $n)
254 261
 {
255 262
 	if (!file_exists($fichier)) return false;
@@ -292,7 +299,7 @@  discard block
 block discarded – undo
292 299
 /**
293 300
  * clearstatcache adapte a la version PHP
294 301
  * @param bool $clear_realpath_cache
295
- * @param null $filename
302
+ * @param string $filename
296 303
  */
297 304
 function spip_clearstatcache($clear_realpath_cache = false, $filename=null){
298 305
 	if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) {
Please login to merge, or discard this patch.
Indentation   +313 added lines, -313 removed lines patch added patch discarded remove patch
@@ -22,56 +22,56 @@  discard block
 block discarded – undo
22 22
 #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip
23 23
 
24 24
 if (_SPIP_LOCK_MODE==2)
25
-	include_spip('inc/nfslock');
25
+    include_spip('inc/nfslock');
26 26
 
27 27
 $GLOBALS['liste_verrous'] = array();
28 28
 // http://doc.spip.org/@spip_fopen_lock
29 29
 function spip_fopen_lock($fichier,$mode,$verrou){
30
-	if (_SPIP_LOCK_MODE==1){
31
-		if ($fl = @fopen($fichier,$mode))
32
-			// verrou
33
-			@flock($fl, $verrou);
34
-		return $fl;
35
-	}
36
-	elseif(_SPIP_LOCK_MODE==2) {
37
-		if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier,$mode))){
38
-			$GLOBALS['liste_verrous'][$fl] = array($fichier,$verrou);
39
-			return $fl;
40
-		}
41
-		else return false;
42
-	}
43
-	return @fopen($fichier,$mode);
30
+    if (_SPIP_LOCK_MODE==1){
31
+        if ($fl = @fopen($fichier,$mode))
32
+            // verrou
33
+            @flock($fl, $verrou);
34
+        return $fl;
35
+    }
36
+    elseif(_SPIP_LOCK_MODE==2) {
37
+        if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier,$mode))){
38
+            $GLOBALS['liste_verrous'][$fl] = array($fichier,$verrou);
39
+            return $fl;
40
+        }
41
+        else return false;
42
+    }
43
+    return @fopen($fichier,$mode);
44 44
 }
45 45
 // http://doc.spip.org/@spip_fclose_unlock
46 46
 function spip_fclose_unlock($handle){
47
-	if (_SPIP_LOCK_MODE==1){
48
-		@flock($handle, LOCK_UN);
49
-	}
50
-	elseif(_SPIP_LOCK_MODE==2) {
51
-		spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]),end($GLOBALS['liste_verrous'][$handle]));
52
-		unset($GLOBALS['liste_verrous'][$handle]);
53
-	}
54
-	return @fclose($handle);
47
+    if (_SPIP_LOCK_MODE==1){
48
+        @flock($handle, LOCK_UN);
49
+    }
50
+    elseif(_SPIP_LOCK_MODE==2) {
51
+        spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]),end($GLOBALS['liste_verrous'][$handle]));
52
+        unset($GLOBALS['liste_verrous'][$handle]);
53
+    }
54
+    return @fclose($handle);
55 55
 }
56 56
 
57 57
 
58 58
 // http://doc.spip.org/@spip_file_get_contents
59 59
 function spip_file_get_contents ($fichier) {
60
-	if (substr($fichier, -3) != '.gz') {
61
-		if (function_exists('file_get_contents')
62
-		AND ( 
63
-			// quand on est sous window on ne sait pas si file_get_contents marche
64
-			// on essaye : si ca retourne du contenu alors c'est bon
65
-			// sinon on fait un file() pour avoir le coeur net
66
-		  ($contenu = @file_get_contents ($fichier))
67
-		  OR _OS_SERVEUR != 'windows')
68
-		)
69
-			return $contenu;
70
-		else
71
-			$contenu = @file($fichier);
72
-	} else
73
-			$contenu = @gzfile($fichier);
74
-	return is_array($contenu)?join('', $contenu):(string)$contenu;
60
+    if (substr($fichier, -3) != '.gz') {
61
+        if (function_exists('file_get_contents')
62
+        AND ( 
63
+            // quand on est sous window on ne sait pas si file_get_contents marche
64
+            // on essaye : si ca retourne du contenu alors c'est bon
65
+            // sinon on fait un file() pour avoir le coeur net
66
+            ($contenu = @file_get_contents ($fichier))
67
+          OR _OS_SERVEUR != 'windows')
68
+        )
69
+            return $contenu;
70
+        else
71
+            $contenu = @file($fichier);
72
+    } else
73
+            $contenu = @gzfile($fichier);
74
+    return is_array($contenu)?join('', $contenu):(string)$contenu;
75 75
 }
76 76
 
77 77
 // options = array(
@@ -79,43 +79,43 @@  discard block
 block discarded – undo
79 79
 // dezippe automatiquement les fichiers .gz
80 80
 // http://doc.spip.org/@lire_fichier
81 81
 function lire_fichier ($fichier, &$contenu, $options=false) {
82
-	$contenu = '';
83
-	// inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres
84
-	// economisons donc les acces disque, sauf chez free qui rale pour un rien
85
-	if (_TEST_FILE_EXISTS AND !@file_exists($fichier))
86
-		return false;
87
-
88
-	#spip_timer('lire_fichier');
89
-
90
-	// pas de @ sur spip_fopen_lock qui est silencieux de toute facon
91
-	if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) {
92
-		// lire le fichier avant tout
93
-		$contenu = spip_file_get_contents($fichier);
94
-
95
-		// le fichier a-t-il ete supprime par le locker ?
96
-		// on ne verifie que si la tentative de lecture a echoue
97
-		// pour discriminer un contenu vide d'un fichier absent
98
-		// et eviter un acces disque
99
-		if (!$contenu AND !@file_exists($fichier)) {
100
-			spip_fclose_unlock($fl);
101
-			return false;
102
-		}
103
-
104
-		// liberer le verrou
105
-		spip_fclose_unlock($fl);
106
-
107
-		// Verifications
108
-		$ok = true;
109
-		if ($options['phpcheck'] == 'oui')
110
-			$ok &= (preg_match(",[?]>\n?$,", $contenu));
111
-
112
-		#spip_log("$fread $fichier ".spip_timer('lire_fichier'));
113
-		if (!$ok)
114
-			spip_log("echec lecture $fichier");
115
-
116
-		return $ok;
117
-	}
118
-	return false;
82
+    $contenu = '';
83
+    // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres
84
+    // economisons donc les acces disque, sauf chez free qui rale pour un rien
85
+    if (_TEST_FILE_EXISTS AND !@file_exists($fichier))
86
+        return false;
87
+
88
+    #spip_timer('lire_fichier');
89
+
90
+    // pas de @ sur spip_fopen_lock qui est silencieux de toute facon
91
+    if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) {
92
+        // lire le fichier avant tout
93
+        $contenu = spip_file_get_contents($fichier);
94
+
95
+        // le fichier a-t-il ete supprime par le locker ?
96
+        // on ne verifie que si la tentative de lecture a echoue
97
+        // pour discriminer un contenu vide d'un fichier absent
98
+        // et eviter un acces disque
99
+        if (!$contenu AND !@file_exists($fichier)) {
100
+            spip_fclose_unlock($fl);
101
+            return false;
102
+        }
103
+
104
+        // liberer le verrou
105
+        spip_fclose_unlock($fl);
106
+
107
+        // Verifications
108
+        $ok = true;
109
+        if ($options['phpcheck'] == 'oui')
110
+            $ok &= (preg_match(",[?]>\n?$,", $contenu));
111
+
112
+        #spip_log("$fread $fichier ".spip_timer('lire_fichier'));
113
+        if (!$ok)
114
+            spip_log("echec lecture $fichier");
115
+
116
+        return $ok;
117
+    }
118
+    return false;
119 119
 }
120 120
 
121 121
 //
@@ -125,77 +125,77 @@  discard block
 block discarded – undo
125 125
 // http://doc.spip.org/@ecrire_fichier
126 126
 function ecrire_fichier ($fichier, $contenu, $ignorer_echec = false, $truncate=true) {
127 127
 
128
-	#spip_timer('ecrire_fichier');
129
-
130
-	// verrouiller le fichier destination
131
-	if ($fp = spip_fopen_lock($fichier, 'a',LOCK_EX)) {
132
-	// ecrire les donnees, compressees le cas echeant
133
-	// (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage
134
-	// de le recreer si le locker qui nous precede l'avait supprime...)
135
-		if (substr($fichier, -3) == '.gz')
136
-			$contenu = gzencode($contenu);
137
-		// si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename
138
-		// pour etre sur d'avoir une operation atomique
139
-		// y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt
140
-		// sauf sous wintruc ou ca ne marche pas
141
-		$ok = false;
142
-		if ($truncate AND _OS_SERVEUR != 'windows'){
143
-			if (!function_exists('creer_uniqid'))
144
-				include_spip('inc/acces');
145
-			$id = creer_uniqid();
146
-			// on ouvre un pointeur sur un fichier temporaire en ecriture +raz
147
-			if ($fp2 = spip_fopen_lock("$fichier.$id", 'w',LOCK_EX)) {
148
-				$s = @fputs($fp2, $contenu, $a = strlen($contenu));
149
-				$ok = ($s == $a);
150
-				spip_fclose_unlock($fp2);
151
-				spip_fclose_unlock($fp);
152
-				// unlink direct et pas spip_unlink car on avait deja le verrou
153
-				// a priori pas besoin car rename ecrase la cible
154
-				// @unlink($fichier);
155
-				// le rename aussitot, atomique quand on est pas sous windows
156
-				// au pire on arrive en second en cas de concourance, et le rename echoue
157
-				// --> on a la version de l'autre process qui doit etre identique
158
-				@rename("$fichier.$id",$fichier);
159
-				// precaution en cas d'echec du rename
160
-				if (!_TEST_FILE_EXISTS OR @file_exists("$fichier.$id"))
161
-					@unlink("$fichier.$id");
162
-				if ($ok)
163
-					$ok = file_exists($fichier);
164
-			}
165
-			else
166
-				// echec mais penser a fermer ..
167
-				spip_fclose_unlock($fp);
168
-		}
169
-		// sinon ou si methode precedente a echoueee
170
-		// on se rabat sur la methode ancienne
171
-		if (!$ok){
172
-			// ici on est en ajout ou sous windows, cas desespere
173
-			if ($truncate)
174
-				@ftruncate($fp,0);
175
-			$s = @fputs($fp, $contenu, $a = strlen($contenu));
176
-
177
-			$ok = ($s == $a);
178
-			spip_fclose_unlock($fp);
179
-		}
180
-
181
-		// liberer le verrou et fermer le fichier
182
-		@chmod($fichier, _SPIP_CHMOD & 0666);
183
-		if ($ok) {
184
-			if (strpos($fichier,".php")!==false){
185
-				spip_clear_opcode_cache(realpath($fichier));
186
-			}
187
-			return $ok;
188
-		}
189
-	}
190
-
191
-	if (!$ignorer_echec){
192
-		include_spip('inc/autoriser');
193
-		if (autoriser('chargerftp'))
194
-			raler_fichier($fichier);
195
-		spip_unlink($fichier);
196
-	}
197
-	spip_log("Ecriture fichier $fichier impossible",_LOG_INFO_IMPORTANTE);
198
-	return false;
128
+    #spip_timer('ecrire_fichier');
129
+
130
+    // verrouiller le fichier destination
131
+    if ($fp = spip_fopen_lock($fichier, 'a',LOCK_EX)) {
132
+    // ecrire les donnees, compressees le cas echeant
133
+    // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage
134
+    // de le recreer si le locker qui nous precede l'avait supprime...)
135
+        if (substr($fichier, -3) == '.gz')
136
+            $contenu = gzencode($contenu);
137
+        // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename
138
+        // pour etre sur d'avoir une operation atomique
139
+        // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt
140
+        // sauf sous wintruc ou ca ne marche pas
141
+        $ok = false;
142
+        if ($truncate AND _OS_SERVEUR != 'windows'){
143
+            if (!function_exists('creer_uniqid'))
144
+                include_spip('inc/acces');
145
+            $id = creer_uniqid();
146
+            // on ouvre un pointeur sur un fichier temporaire en ecriture +raz
147
+            if ($fp2 = spip_fopen_lock("$fichier.$id", 'w',LOCK_EX)) {
148
+                $s = @fputs($fp2, $contenu, $a = strlen($contenu));
149
+                $ok = ($s == $a);
150
+                spip_fclose_unlock($fp2);
151
+                spip_fclose_unlock($fp);
152
+                // unlink direct et pas spip_unlink car on avait deja le verrou
153
+                // a priori pas besoin car rename ecrase la cible
154
+                // @unlink($fichier);
155
+                // le rename aussitot, atomique quand on est pas sous windows
156
+                // au pire on arrive en second en cas de concourance, et le rename echoue
157
+                // --> on a la version de l'autre process qui doit etre identique
158
+                @rename("$fichier.$id",$fichier);
159
+                // precaution en cas d'echec du rename
160
+                if (!_TEST_FILE_EXISTS OR @file_exists("$fichier.$id"))
161
+                    @unlink("$fichier.$id");
162
+                if ($ok)
163
+                    $ok = file_exists($fichier);
164
+            }
165
+            else
166
+                // echec mais penser a fermer ..
167
+                spip_fclose_unlock($fp);
168
+        }
169
+        // sinon ou si methode precedente a echoueee
170
+        // on se rabat sur la methode ancienne
171
+        if (!$ok){
172
+            // ici on est en ajout ou sous windows, cas desespere
173
+            if ($truncate)
174
+                @ftruncate($fp,0);
175
+            $s = @fputs($fp, $contenu, $a = strlen($contenu));
176
+
177
+            $ok = ($s == $a);
178
+            spip_fclose_unlock($fp);
179
+        }
180
+
181
+        // liberer le verrou et fermer le fichier
182
+        @chmod($fichier, _SPIP_CHMOD & 0666);
183
+        if ($ok) {
184
+            if (strpos($fichier,".php")!==false){
185
+                spip_clear_opcode_cache(realpath($fichier));
186
+            }
187
+            return $ok;
188
+        }
189
+    }
190
+
191
+    if (!$ignorer_echec){
192
+        include_spip('inc/autoriser');
193
+        if (autoriser('chargerftp'))
194
+            raler_fichier($fichier);
195
+        spip_unlink($fichier);
196
+    }
197
+    spip_log("Ecriture fichier $fichier impossible",_LOG_INFO_IMPORTANTE);
198
+    return false;
199 199
 }
200 200
 
201 201
 /**
@@ -207,10 +207,10 @@  discard block
 block discarded – undo
207 207
  * @param <type> $truncate 
208 208
  */
209 209
 function ecrire_fichier_securise ($fichier, $contenu, $ecrire_quand_meme = false, $truncate=true) {
210
-	if (substr($fichier,-4) !== '.php')
211
-		spip_log('Erreur de programmation: '.$fichier.' doit finir par .php');
212
-	$contenu = "<"."?php die ('Acces interdit'); ?".">\n" . $contenu;
213
-	return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate);
210
+    if (substr($fichier,-4) !== '.php')
211
+        spip_log('Erreur de programmation: '.$fichier.' doit finir par .php');
212
+    $contenu = "<"."?php die ('Acces interdit'); ?".">\n" . $contenu;
213
+    return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate);
214 214
 }
215 215
 
216 216
 /**
@@ -220,29 +220,29 @@  discard block
 block discarded – undo
220 220
  * @param <type> $options 
221 221
  */
222 222
 function lire_fichier_securise ($fichier, &$contenu, $options=false) {
223
-	if ($res = lire_fichier($fichier,$contenu,$options)){
224
-		$contenu = substr($contenu,strlen("<"."?php die ('Acces interdit'); ?".">\n"));
225
-	}
226
-	return $res;
223
+    if ($res = lire_fichier($fichier,$contenu,$options)){
224
+        $contenu = substr($contenu,strlen("<"."?php die ('Acces interdit'); ?".">\n"));
225
+    }
226
+    return $res;
227 227
 }
228 228
 
229 229
 // http://doc.spip.org/@raler_fichier
230 230
 function raler_fichier($fichier)
231 231
 {
232
-	include_spip('inc/minipres');
233
-	$dir = dirname($fichier);
234
-	http_status(401);
235
-	echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>"
236
-		. _T('texte_inc_meta_1', array('fichier' => $fichier))
237
-		. " <a href='"
238
-		. generer_url_ecrire('install', "etape=chmod&test_dir=$dir")
239
-		. "'>"
240
-		. _T('texte_inc_meta_2')
241
-		. "</a> "
242
-		. _T('texte_inc_meta_3',
243
-		     array('repertoire' => joli_repertoire($dir)))
244
-		. "</h4>\n");
245
-	exit;
232
+    include_spip('inc/minipres');
233
+    $dir = dirname($fichier);
234
+    http_status(401);
235
+    echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>"
236
+        . _T('texte_inc_meta_1', array('fichier' => $fichier))
237
+        . " <a href='"
238
+        . generer_url_ecrire('install', "etape=chmod&test_dir=$dir")
239
+        . "'>"
240
+        . _T('texte_inc_meta_2')
241
+        . "</a> "
242
+        . _T('texte_inc_meta_3',
243
+                array('repertoire' => joli_repertoire($dir)))
244
+        . "</h4>\n");
245
+    exit;
246 246
 }
247 247
 
248 248
 //
@@ -252,9 +252,9 @@  discard block
 block discarded – undo
252 252
 // http://doc.spip.org/@jeune_fichier
253 253
 function jeune_fichier($fichier, $n)
254 254
 {
255
-	if (!file_exists($fichier)) return false;
256
-	if (!$c = @filemtime($fichier)) return false;
257
-	return (time()-$n <= $c);
255
+    if (!file_exists($fichier)) return false;
256
+    if (!$c = @filemtime($fichier)) return false;
257
+    return (time()-$n <= $c);
258 258
 }
259 259
 
260 260
 //
@@ -262,31 +262,31 @@  discard block
 block discarded – undo
262 262
 //
263 263
 // http://doc.spip.org/@supprimer_fichier
264 264
 function supprimer_fichier($fichier, $lock=true) {
265
-	if (!@file_exists($fichier))
266
-		return true;
265
+    if (!@file_exists($fichier))
266
+        return true;
267 267
 
268
-	if ($lock) {
269
-		// verrouiller le fichier destination
270
-		if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX))
271
-			return false;
268
+    if ($lock) {
269
+        // verrouiller le fichier destination
270
+        if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX))
271
+            return false;
272 272
 	
273
-		// liberer le verrou
274
-		spip_fclose_unlock($fp);
275
-	}
273
+        // liberer le verrou
274
+        spip_fclose_unlock($fp);
275
+    }
276 276
 	
277
-	// supprimer
278
-	return @unlink($fichier);
277
+    // supprimer
278
+    return @unlink($fichier);
279 279
 }
280 280
 
281 281
 // Supprimer brutalement, si le fichier existe
282 282
 // http://doc.spip.org/@spip_unlink
283 283
 function spip_unlink($f) {
284
-	if (!is_dir($f))
285
-		supprimer_fichier($f,false);
286
-	else {
287
-		@unlink("$f/.ok");
288
-		@rmdir($f);
289
-	}
284
+    if (!is_dir($f))
285
+        supprimer_fichier($f,false);
286
+    else {
287
+        @unlink("$f/.ok");
288
+        @rmdir($f);
289
+    }
290 290
 }
291 291
 
292 292
 /**
@@ -295,13 +295,13 @@  discard block
 block discarded – undo
295 295
  * @param null $filename
296 296
  */
297 297
 function spip_clearstatcache($clear_realpath_cache = false, $filename=null){
298
-	if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) {
299
-   // Below PHP 5.3, clearstatcache does not accept any function parameters.
300
-   return clearstatcache();
301
- }
302
- else {
303
-	 return clearstatcache($clear_realpath_cache, $filename);
304
- }
298
+    if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) {
299
+    // Below PHP 5.3, clearstatcache does not accept any function parameters.
300
+    return clearstatcache();
301
+    }
302
+    else {
303
+        return clearstatcache($clear_realpath_cache, $filename);
304
+    }
305 305
 
306 306
 }
307 307
 
@@ -317,19 +317,19 @@  discard block
 block discarded – undo
317 317
  *   The absolute path of the PHP file to invalidate.
318 318
  */
319 319
 function spip_clear_opcode_cache($filepath) {
320
-	spip_clearstatcache(TRUE, $filepath);
320
+    spip_clearstatcache(TRUE, $filepath);
321 321
 
322
-  // Zend OPcache
323
-  if (function_exists('opcache_invalidate')) {
322
+    // Zend OPcache
323
+    if (function_exists('opcache_invalidate')) {
324 324
     opcache_invalidate($filepath, TRUE);
325
-  }
326
-  // APC.
327
-  if (function_exists('apc_delete_file')) {
325
+    }
326
+    // APC.
327
+    if (function_exists('apc_delete_file')) {
328 328
     // apc_delete_file() throws a PHP warning in case the specified file was
329 329
     // not compiled yet.
330 330
     // @see http://php.net/apc-delete-file
331 331
     @apc_delete_file($filepath);
332
-  }
332
+    }
333 333
 }
334 334
 
335 335
 /**
@@ -344,12 +344,12 @@  discard block
 block discarded – undo
344 344
  *
345 345
  */
346 346
 function spip_attend_invalidation_opcode_cache(){
347
-	if (function_exists('opcache_get_configuration')
348
-	  AND @ini_get('opcache.enable')
349
-	  AND @ini_get('opcache.validate_timestamps')
350
-	  AND $duree = @ini_get('opcache.revalidate_freq') ) {
351
-		sleep($duree+1);
352
-	}
347
+    if (function_exists('opcache_get_configuration')
348
+      AND @ini_get('opcache.enable')
349
+      AND @ini_get('opcache.validate_timestamps')
350
+      AND $duree = @ini_get('opcache.revalidate_freq') ) {
351
+        sleep($duree+1);
352
+    }
353 353
 }
354 354
 
355 355
 /**
@@ -361,18 +361,18 @@  discard block
 block discarded – undo
361 361
  * @return bool Suppression reussie.
362 362
  */
363 363
 function supprimer_repertoire($dir) {
364
-	if (!file_exists($dir)) return true;
365
-	if (!is_dir($dir) || is_link($dir)) return @unlink($dir);
364
+    if (!file_exists($dir)) return true;
365
+    if (!is_dir($dir) || is_link($dir)) return @unlink($dir);
366 366
 	
367
-	foreach (scandir($dir) as $item) {
368
-		if ($item == '.' || $item == '..') continue;
369
-		if (!supprimer_repertoire($dir . "/" . $item)) {
370
-			@chmod($dir . "/" . $item, 0777);
371
-			if (!supprimer_repertoire($dir . "/" . $item)) return false;
372
-		};
373
-	}
367
+    foreach (scandir($dir) as $item) {
368
+        if ($item == '.' || $item == '..') continue;
369
+        if (!supprimer_repertoire($dir . "/" . $item)) {
370
+            @chmod($dir . "/" . $item, 0777);
371
+            if (!supprimer_repertoire($dir . "/" . $item)) return false;
372
+        };
373
+    }
374 374
 	
375
-	return @rmdir($dir);
375
+    return @rmdir($dir);
376 376
 }
377 377
 
378 378
 	
@@ -384,61 +384,61 @@  discard block
 block discarded – undo
384 384
 //
385 385
 // http://doc.spip.org/@sous_repertoire
386 386
 function sous_repertoire($base, $subdir='', $nobase = false, $tantpis=false) {
387
-	static $dirs = array();
388
-
389
-	$base = str_replace("//", "/", $base);
390
-
391
-	# suppr le dernier caractere si c'est un / ou un _
392
-	$base = rtrim($base, '/_');
393
-
394
-	if (!strlen($subdir)) {
395
-		$n = strrpos($base, "/");
396
-		if ($n === false) return $nobase ? '' : ($base .'/');
397
-		$subdir = substr($base, $n+1);
398
-		$base = substr($base, 0, $n+1);
399
-	} else {
400
-		$base .= '/';
401
-		$subdir = str_replace("/", "", $subdir);
402
-	}
403
-
404
-	$baseaff = $nobase ? '' : $base;
405
-	if (isset($dirs[$base.$subdir]))
406
-		return $baseaff.$dirs[$base.$subdir];
407
-
408
-
409
-	if (_CREER_DIR_PLAT AND @file_exists("$base${subdir}.plat"))
410
-		return $baseaff.($dirs[$base.$subdir] = "${subdir}_");
411
-
412
-	$path = $base.$subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf'
413
-
414
-	if (file_exists("$path/.ok"))
415
-		return $baseaff.($dirs[$base.$subdir] = "$subdir/");
416
-
417
-	@mkdir($path, _SPIP_CHMOD);
418
-	@chmod($path, _SPIP_CHMOD);
419
-
420
-	if (is_dir($path) && is_writable($path)) {
421
-		@touch ("$path/.ok");
422
-		spip_log("creation $base$subdir/");
423
-		return $baseaff.($dirs[$base.$subdir] = "$subdir/");
424
-	}
425
-
426
-	// en cas d'echec c'est peut etre tout simplement que le disque est plein :
427
-	// l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu
428
-	// => sauf besoin express (define dans mes_options), ne pas creer le .plat
429
-	if (_CREER_DIR_PLAT
430
-	AND $f = @fopen("$base${subdir}.plat", "w"))
431
-		fclose($f);
432
-	else {
433
-		spip_log("echec creation $base${subdir}");
434
-		if ($tantpis) return '';
435
-		if (!_DIR_RESTREINT)
436
-			$base = preg_replace(',^' . _DIR_RACINE .',', '',$base);
437
-		$base .= $subdir;
438
-		raler_fichier($base . '/.plat');
439
-	}
440
-	spip_log("faux sous-repertoire $base${subdir}");
441
-	return $baseaff.($dirs[$base.$subdir] = "${subdir}_");
387
+    static $dirs = array();
388
+
389
+    $base = str_replace("//", "/", $base);
390
+
391
+    # suppr le dernier caractere si c'est un / ou un _
392
+    $base = rtrim($base, '/_');
393
+
394
+    if (!strlen($subdir)) {
395
+        $n = strrpos($base, "/");
396
+        if ($n === false) return $nobase ? '' : ($base .'/');
397
+        $subdir = substr($base, $n+1);
398
+        $base = substr($base, 0, $n+1);
399
+    } else {
400
+        $base .= '/';
401
+        $subdir = str_replace("/", "", $subdir);
402
+    }
403
+
404
+    $baseaff = $nobase ? '' : $base;
405
+    if (isset($dirs[$base.$subdir]))
406
+        return $baseaff.$dirs[$base.$subdir];
407
+
408
+
409
+    if (_CREER_DIR_PLAT AND @file_exists("$base${subdir}.plat"))
410
+        return $baseaff.($dirs[$base.$subdir] = "${subdir}_");
411
+
412
+    $path = $base.$subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf'
413
+
414
+    if (file_exists("$path/.ok"))
415
+        return $baseaff.($dirs[$base.$subdir] = "$subdir/");
416
+
417
+    @mkdir($path, _SPIP_CHMOD);
418
+    @chmod($path, _SPIP_CHMOD);
419
+
420
+    if (is_dir($path) && is_writable($path)) {
421
+        @touch ("$path/.ok");
422
+        spip_log("creation $base$subdir/");
423
+        return $baseaff.($dirs[$base.$subdir] = "$subdir/");
424
+    }
425
+
426
+    // en cas d'echec c'est peut etre tout simplement que le disque est plein :
427
+    // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu
428
+    // => sauf besoin express (define dans mes_options), ne pas creer le .plat
429
+    if (_CREER_DIR_PLAT
430
+    AND $f = @fopen("$base${subdir}.plat", "w"))
431
+        fclose($f);
432
+    else {
433
+        spip_log("echec creation $base${subdir}");
434
+        if ($tantpis) return '';
435
+        if (!_DIR_RESTREINT)
436
+            $base = preg_replace(',^' . _DIR_RACINE .',', '',$base);
437
+        $base .= $subdir;
438
+        raler_fichier($base . '/.plat');
439
+    }
440
+    spip_log("faux sous-repertoire $base${subdir}");
441
+    return $baseaff.($dirs[$base.$subdir] = "${subdir}_");
442 442
 }
443 443
 
444 444
 //
@@ -455,46 +455,46 @@  discard block
 block discarded – undo
455 455
 //
456 456
 // http://doc.spip.org/@preg_files
457 457
 function preg_files($dir, $pattern=-1 /* AUTO */, $maxfiles = 10000, $recurs=array()) {
458
-	$nbfiles = 0;
459
-	if ($pattern == -1)
460
-		$pattern = "^$dir";
461
-	$fichiers = array();
462
-	// revenir au repertoire racine si on a recu dossier/truc
463
-	// pour regarder dossier/truc/ ne pas oublier le / final
464
-	$dir = preg_replace(',/[^/]*$,', '', $dir);
465
-	if ($dir == '') $dir = '.';
466
-
467
-	if (@is_dir($dir) AND is_readable($dir) AND $d = @opendir($dir)) {
468
-		while (($f = readdir($d)) !== false && ($nbfiles<$maxfiles)) {
469
-			if ($f[0] != '.' # ignorer . .. .svn etc
470
-			AND $f != 'CVS'
471
-			AND $f != 'remove.txt'
472
-			AND is_readable($f = "$dir/$f")) {
473
-				if (is_file($f)) {
474
-					if (preg_match(";$pattern;iS", $f))
475
-					{
476
-						$fichiers[] = $f;
477
-						$nbfiles++;
478
-					}
479
-				} 
480
-				else if (is_dir($f) AND is_array($recurs)){
481
-					$rp = @realpath($f);
482
-					if (!is_string($rp) OR !strlen($rp)) $rp=$f; # realpath n'est peut etre pas autorise
483
-					if (!isset($recurs[$rp])) {
484
-						$recurs[$rp] = true;
485
-						$beginning = $fichiers;
486
-						$end = preg_files("$f/", $pattern,
487
-							$maxfiles-$nbfiles, $recurs);
488
-						$fichiers = array_merge((array)$beginning, (array)$end);
489
-						$nbfiles = count($fichiers);
490
-					}
491
-				}
492
-			}
493
-		}
494
-		closedir($d);
495
-	}
496
-	sort($fichiers);
497
-	return $fichiers;
458
+    $nbfiles = 0;
459
+    if ($pattern == -1)
460
+        $pattern = "^$dir";
461
+    $fichiers = array();
462
+    // revenir au repertoire racine si on a recu dossier/truc
463
+    // pour regarder dossier/truc/ ne pas oublier le / final
464
+    $dir = preg_replace(',/[^/]*$,', '', $dir);
465
+    if ($dir == '') $dir = '.';
466
+
467
+    if (@is_dir($dir) AND is_readable($dir) AND $d = @opendir($dir)) {
468
+        while (($f = readdir($d)) !== false && ($nbfiles<$maxfiles)) {
469
+            if ($f[0] != '.' # ignorer . .. .svn etc
470
+            AND $f != 'CVS'
471
+            AND $f != 'remove.txt'
472
+            AND is_readable($f = "$dir/$f")) {
473
+                if (is_file($f)) {
474
+                    if (preg_match(";$pattern;iS", $f))
475
+                    {
476
+                        $fichiers[] = $f;
477
+                        $nbfiles++;
478
+                    }
479
+                } 
480
+                else if (is_dir($f) AND is_array($recurs)){
481
+                    $rp = @realpath($f);
482
+                    if (!is_string($rp) OR !strlen($rp)) $rp=$f; # realpath n'est peut etre pas autorise
483
+                    if (!isset($recurs[$rp])) {
484
+                        $recurs[$rp] = true;
485
+                        $beginning = $fichiers;
486
+                        $end = preg_files("$f/", $pattern,
487
+                            $maxfiles-$nbfiles, $recurs);
488
+                        $fichiers = array_merge((array)$beginning, (array)$end);
489
+                        $nbfiles = count($fichiers);
490
+                    }
491
+                }
492
+            }
493
+        }
494
+        closedir($d);
495
+    }
496
+    sort($fichiers);
497
+    return $fichiers;
498 498
 }
499 499
 
500 500
 ?>
Please login to merge, or discard this patch.
Braces   +116 added lines, -73 removed lines patch added patch discarded remove patch
@@ -11,34 +11,40 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 
14
-if (!defined('_ECRIRE_INC_VERSION')) return;
14
+if (!defined('_ECRIRE_INC_VERSION')) {
15
+    return;
16
+}
15 17
 // ajouter define('_CREER_DIR_PLAT', true); dans mes_options pour restaurer
16 18
 // le fonctionnement des faux repertoires en .plat
17 19
 define('_CREER_DIR_PLAT', false);
18
-if (!defined('_TEST_FILE_EXISTS')) define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV["HTTP_HOST"]) ? $_ENV["HTTP_HOST"] : ""));
20
+if (!defined('_TEST_FILE_EXISTS')) {
21
+    define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV["HTTP_HOST"]) ? $_ENV["HTTP_HOST"] : ""));
22
+}
19 23
 
20 24
 #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille)
21 25
 #define('_SPIP_LOCK_MODE',1); // utiliser le flock php
22 26
 #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip
23 27
 
24
-if (_SPIP_LOCK_MODE==2)
28
+if (_SPIP_LOCK_MODE==2) {
25 29
 	include_spip('inc/nfslock');
30
+}
26 31
 
27 32
 $GLOBALS['liste_verrous'] = array();
28 33
 // http://doc.spip.org/@spip_fopen_lock
29 34
 function spip_fopen_lock($fichier,$mode,$verrou){
30 35
 	if (_SPIP_LOCK_MODE==1){
31
-		if ($fl = @fopen($fichier,$mode))
32
-			// verrou
36
+		if ($fl = @fopen($fichier,$mode)) {
37
+					// verrou
33 38
 			@flock($fl, $verrou);
39
+		}
34 40
 		return $fl;
35
-	}
36
-	elseif(_SPIP_LOCK_MODE==2) {
41
+	} elseif(_SPIP_LOCK_MODE==2) {
37 42
 		if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier,$mode))){
38 43
 			$GLOBALS['liste_verrous'][$fl] = array($fichier,$verrou);
39 44
 			return $fl;
45
+		} else {
46
+		    return false;
40 47
 		}
41
-		else return false;
42 48
 	}
43 49
 	return @fopen($fichier,$mode);
44 50
 }
@@ -46,8 +52,7 @@  discard block
 block discarded – undo
46 52
 function spip_fclose_unlock($handle){
47 53
 	if (_SPIP_LOCK_MODE==1){
48 54
 		@flock($handle, LOCK_UN);
49
-	}
50
-	elseif(_SPIP_LOCK_MODE==2) {
55
+	} elseif(_SPIP_LOCK_MODE==2) {
51 56
 		spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]),end($GLOBALS['liste_verrous'][$handle]));
52 57
 		unset($GLOBALS['liste_verrous'][$handle]);
53 58
 	}
@@ -65,12 +70,14 @@  discard block
 block discarded – undo
65 70
 			// sinon on fait un file() pour avoir le coeur net
66 71
 		  ($contenu = @file_get_contents ($fichier))
67 72
 		  OR _OS_SERVEUR != 'windows')
68
-		)
69
-			return $contenu;
70
-		else
71
-			$contenu = @file($fichier);
72
-	} else
73
-			$contenu = @gzfile($fichier);
73
+		) {
74
+					return $contenu;
75
+		} else {
76
+					$contenu = @file($fichier);
77
+		}
78
+	} else {
79
+				$contenu = @gzfile($fichier);
80
+	}
74 81
 	return is_array($contenu)?join('', $contenu):(string)$contenu;
75 82
 }
76 83
 
@@ -82,8 +89,9 @@  discard block
 block discarded – undo
82 89
 	$contenu = '';
83 90
 	// inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres
84 91
 	// economisons donc les acces disque, sauf chez free qui rale pour un rien
85
-	if (_TEST_FILE_EXISTS AND !@file_exists($fichier))
86
-		return false;
92
+	if (_TEST_FILE_EXISTS AND !@file_exists($fichier)) {
93
+			return false;
94
+	}
87 95
 
88 96
 	#spip_timer('lire_fichier');
89 97
 
@@ -106,12 +114,14 @@  discard block
 block discarded – undo
106 114
 
107 115
 		// Verifications
108 116
 		$ok = true;
109
-		if ($options['phpcheck'] == 'oui')
110
-			$ok &= (preg_match(",[?]>\n?$,", $contenu));
117
+		if ($options['phpcheck'] == 'oui') {
118
+					$ok &= (preg_match(",[?]>\n?$,", $contenu));
119
+		}
111 120
 
112 121
 		#spip_log("$fread $fichier ".spip_timer('lire_fichier'));
113
-		if (!$ok)
114
-			spip_log("echec lecture $fichier");
122
+		if (!$ok) {
123
+					spip_log("echec lecture $fichier");
124
+		}
115 125
 
116 126
 		return $ok;
117 127
 	}
@@ -132,16 +142,18 @@  discard block
 block discarded – undo
132 142
 	// ecrire les donnees, compressees le cas echeant
133 143
 	// (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage
134 144
 	// de le recreer si le locker qui nous precede l'avait supprime...)
135
-		if (substr($fichier, -3) == '.gz')
136
-			$contenu = gzencode($contenu);
145
+		if (substr($fichier, -3) == '.gz') {
146
+					$contenu = gzencode($contenu);
147
+		}
137 148
 		// si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename
138 149
 		// pour etre sur d'avoir une operation atomique
139 150
 		// y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt
140 151
 		// sauf sous wintruc ou ca ne marche pas
141 152
 		$ok = false;
142 153
 		if ($truncate AND _OS_SERVEUR != 'windows'){
143
-			if (!function_exists('creer_uniqid'))
144
-				include_spip('inc/acces');
154
+			if (!function_exists('creer_uniqid')) {
155
+							include_spip('inc/acces');
156
+			}
145 157
 			$id = creer_uniqid();
146 158
 			// on ouvre un pointeur sur un fichier temporaire en ecriture +raz
147 159
 			if ($fp2 = spip_fopen_lock("$fichier.$id", 'w',LOCK_EX)) {
@@ -157,21 +169,24 @@  discard block
 block discarded – undo
157 169
 				// --> on a la version de l'autre process qui doit etre identique
158 170
 				@rename("$fichier.$id",$fichier);
159 171
 				// precaution en cas d'echec du rename
160
-				if (!_TEST_FILE_EXISTS OR @file_exists("$fichier.$id"))
161
-					@unlink("$fichier.$id");
162
-				if ($ok)
163
-					$ok = file_exists($fichier);
164
-			}
165
-			else
166
-				// echec mais penser a fermer ..
172
+				if (!_TEST_FILE_EXISTS OR @file_exists("$fichier.$id")) {
173
+									@unlink("$fichier.$id");
174
+				}
175
+				if ($ok) {
176
+									$ok = file_exists($fichier);
177
+				}
178
+			} else {
179
+							// echec mais penser a fermer ..
167 180
 				spip_fclose_unlock($fp);
181
+			}
168 182
 		}
169 183
 		// sinon ou si methode precedente a echoueee
170 184
 		// on se rabat sur la methode ancienne
171 185
 		if (!$ok){
172 186
 			// ici on est en ajout ou sous windows, cas desespere
173
-			if ($truncate)
174
-				@ftruncate($fp,0);
187
+			if ($truncate) {
188
+							@ftruncate($fp,0);
189
+			}
175 190
 			$s = @fputs($fp, $contenu, $a = strlen($contenu));
176 191
 
177 192
 			$ok = ($s == $a);
@@ -190,8 +205,9 @@  discard block
 block discarded – undo
190 205
 
191 206
 	if (!$ignorer_echec){
192 207
 		include_spip('inc/autoriser');
193
-		if (autoriser('chargerftp'))
194
-			raler_fichier($fichier);
208
+		if (autoriser('chargerftp')) {
209
+					raler_fichier($fichier);
210
+		}
195 211
 		spip_unlink($fichier);
196 212
 	}
197 213
 	spip_log("Ecriture fichier $fichier impossible",_LOG_INFO_IMPORTANTE);
@@ -207,8 +223,9 @@  discard block
 block discarded – undo
207 223
  * @param <type> $truncate 
208 224
  */
209 225
 function ecrire_fichier_securise ($fichier, $contenu, $ecrire_quand_meme = false, $truncate=true) {
210
-	if (substr($fichier,-4) !== '.php')
211
-		spip_log('Erreur de programmation: '.$fichier.' doit finir par .php');
226
+	if (substr($fichier,-4) !== '.php') {
227
+			spip_log('Erreur de programmation: '.$fichier.' doit finir par .php');
228
+	}
212 229
 	$contenu = "<"."?php die ('Acces interdit'); ?".">\n" . $contenu;
213 230
 	return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate);
214 231
 }
@@ -252,8 +269,12 @@  discard block
 block discarded – undo
252 269
 // http://doc.spip.org/@jeune_fichier
253 270
 function jeune_fichier($fichier, $n)
254 271
 {
255
-	if (!file_exists($fichier)) return false;
256
-	if (!$c = @filemtime($fichier)) return false;
272
+	if (!file_exists($fichier)) {
273
+	    return false;
274
+	}
275
+	if (!$c = @filemtime($fichier)) {
276
+	    return false;
277
+	}
257 278
 	return (time()-$n <= $c);
258 279
 }
259 280
 
@@ -262,13 +283,15 @@  discard block
 block discarded – undo
262 283
 //
263 284
 // http://doc.spip.org/@supprimer_fichier
264 285
 function supprimer_fichier($fichier, $lock=true) {
265
-	if (!@file_exists($fichier))
266
-		return true;
286
+	if (!@file_exists($fichier)) {
287
+			return true;
288
+	}
267 289
 
268 290
 	if ($lock) {
269 291
 		// verrouiller le fichier destination
270
-		if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX))
271
-			return false;
292
+		if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
293
+					return false;
294
+		}
272 295
 	
273 296
 		// liberer le verrou
274 297
 		spip_fclose_unlock($fp);
@@ -281,9 +304,9 @@  discard block
 block discarded – undo
281 304
 // Supprimer brutalement, si le fichier existe
282 305
 // http://doc.spip.org/@spip_unlink
283 306
 function spip_unlink($f) {
284
-	if (!is_dir($f))
285
-		supprimer_fichier($f,false);
286
-	else {
307
+	if (!is_dir($f)) {
308
+			supprimer_fichier($f,false);
309
+	} else {
287 310
 		@unlink("$f/.ok");
288 311
 		@rmdir($f);
289 312
 	}
@@ -298,8 +321,7 @@  discard block
 block discarded – undo
298 321
 	if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) {
299 322
    // Below PHP 5.3, clearstatcache does not accept any function parameters.
300 323
    return clearstatcache();
301
- }
302
- else {
324
+ } else {
303 325
 	 return clearstatcache($clear_realpath_cache, $filename);
304 326
  }
305 327
 
@@ -361,14 +383,22 @@  discard block
 block discarded – undo
361 383
  * @return bool Suppression reussie.
362 384
  */
363 385
 function supprimer_repertoire($dir) {
364
-	if (!file_exists($dir)) return true;
365
-	if (!is_dir($dir) || is_link($dir)) return @unlink($dir);
386
+	if (!file_exists($dir)) {
387
+	    return true;
388
+	}
389
+	if (!is_dir($dir) || is_link($dir)) {
390
+	    return @unlink($dir);
391
+	}
366 392
 	
367 393
 	foreach (scandir($dir) as $item) {
368
-		if ($item == '.' || $item == '..') continue;
394
+		if ($item == '.' || $item == '..') {
395
+		    continue;
396
+		}
369 397
 		if (!supprimer_repertoire($dir . "/" . $item)) {
370 398
 			@chmod($dir . "/" . $item, 0777);
371
-			if (!supprimer_repertoire($dir . "/" . $item)) return false;
399
+			if (!supprimer_repertoire($dir . "/" . $item)) {
400
+			    return false;
401
+			}
372 402
 		};
373 403
 	}
374 404
 	
@@ -393,7 +423,9 @@  discard block
 block discarded – undo
393 423
 
394 424
 	if (!strlen($subdir)) {
395 425
 		$n = strrpos($base, "/");
396
-		if ($n === false) return $nobase ? '' : ($base .'/');
426
+		if ($n === false) {
427
+		    return $nobase ? '' : ($base .'/');
428
+		}
397 429
 		$subdir = substr($base, $n+1);
398 430
 		$base = substr($base, 0, $n+1);
399 431
 	} else {
@@ -402,17 +434,20 @@  discard block
 block discarded – undo
402 434
 	}
403 435
 
404 436
 	$baseaff = $nobase ? '' : $base;
405
-	if (isset($dirs[$base.$subdir]))
406
-		return $baseaff.$dirs[$base.$subdir];
437
+	if (isset($dirs[$base.$subdir])) {
438
+			return $baseaff.$dirs[$base.$subdir];
439
+	}
407 440
 
408 441
 
409
-	if (_CREER_DIR_PLAT AND @file_exists("$base${subdir}.plat"))
410
-		return $baseaff.($dirs[$base.$subdir] = "${subdir}_");
442
+	if (_CREER_DIR_PLAT AND @file_exists("$base${subdir}.plat")) {
443
+			return $baseaff.($dirs[$base.$subdir] = "${subdir}_");
444
+	}
411 445
 
412 446
 	$path = $base.$subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf'
413 447
 
414
-	if (file_exists("$path/.ok"))
415
-		return $baseaff.($dirs[$base.$subdir] = "$subdir/");
448
+	if (file_exists("$path/.ok")) {
449
+			return $baseaff.($dirs[$base.$subdir] = "$subdir/");
450
+	}
416 451
 
417 452
 	@mkdir($path, _SPIP_CHMOD);
418 453
 	@chmod($path, _SPIP_CHMOD);
@@ -427,13 +462,16 @@  discard block
 block discarded – undo
427 462
 	// l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu
428 463
 	// => sauf besoin express (define dans mes_options), ne pas creer le .plat
429 464
 	if (_CREER_DIR_PLAT
430
-	AND $f = @fopen("$base${subdir}.plat", "w"))
431
-		fclose($f);
432
-	else {
465
+	AND $f = @fopen("$base${subdir}.plat", "w")) {
466
+			fclose($f);
467
+	} else {
433 468
 		spip_log("echec creation $base${subdir}");
434
-		if ($tantpis) return '';
435
-		if (!_DIR_RESTREINT)
436
-			$base = preg_replace(',^' . _DIR_RACINE .',', '',$base);
469
+		if ($tantpis) {
470
+		    return '';
471
+		}
472
+		if (!_DIR_RESTREINT) {
473
+					$base = preg_replace(',^' . _DIR_RACINE .',', '',$base);
474
+		}
437 475
 		$base .= $subdir;
438 476
 		raler_fichier($base . '/.plat');
439 477
 	}
@@ -456,13 +494,16 @@  discard block
 block discarded – undo
456 494
 // http://doc.spip.org/@preg_files
457 495
 function preg_files($dir, $pattern=-1 /* AUTO */, $maxfiles = 10000, $recurs=array()) {
458 496
 	$nbfiles = 0;
459
-	if ($pattern == -1)
460
-		$pattern = "^$dir";
497
+	if ($pattern == -1) {
498
+			$pattern = "^$dir";
499
+	}
461 500
 	$fichiers = array();
462 501
 	// revenir au repertoire racine si on a recu dossier/truc
463 502
 	// pour regarder dossier/truc/ ne pas oublier le / final
464 503
 	$dir = preg_replace(',/[^/]*$,', '', $dir);
465
-	if ($dir == '') $dir = '.';
504
+	if ($dir == '') {
505
+	    $dir = '.';
506
+	}
466 507
 
467 508
 	if (@is_dir($dir) AND is_readable($dir) AND $d = @opendir($dir)) {
468 509
 		while (($f = readdir($d)) !== false && ($nbfiles<$maxfiles)) {
@@ -476,10 +517,12 @@  discard block
 block discarded – undo
476 517
 						$fichiers[] = $f;
477 518
 						$nbfiles++;
478 519
 					}
479
-				} 
480
-				else if (is_dir($f) AND is_array($recurs)){
520
+				} else if (is_dir($f) AND is_array($recurs)){
481 521
 					$rp = @realpath($f);
482
-					if (!is_string($rp) OR !strlen($rp)) $rp=$f; # realpath n'est peut etre pas autorise
522
+					if (!is_string($rp) OR !strlen($rp)) {
523
+					    $rp=$f;
524
+					}
525
+					# realpath n'est peut etre pas autorise
483 526
 					if (!isset($recurs[$rp])) {
484 527
 						$recurs[$rp] = true;
485 528
 						$beginning = $fichiers;
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -21,34 +21,34 @@  discard block
 block discarded – undo
21 21
 #define('_SPIP_LOCK_MODE',1); // utiliser le flock php
22 22
 #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip
23 23
 
24
-if (_SPIP_LOCK_MODE==2)
24
+if (_SPIP_LOCK_MODE == 2)
25 25
 	include_spip('inc/nfslock');
26 26
 
27 27
 $GLOBALS['liste_verrous'] = array();
28 28
 // http://doc.spip.org/@spip_fopen_lock
29
-function spip_fopen_lock($fichier,$mode,$verrou){
30
-	if (_SPIP_LOCK_MODE==1){
31
-		if ($fl = @fopen($fichier,$mode))
29
+function spip_fopen_lock($fichier, $mode, $verrou) {
30
+	if (_SPIP_LOCK_MODE == 1) {
31
+		if ($fl = @fopen($fichier, $mode))
32 32
 			// verrou
33 33
 			@flock($fl, $verrou);
34 34
 		return $fl;
35 35
 	}
36
-	elseif(_SPIP_LOCK_MODE==2) {
37
-		if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier,$mode))){
38
-			$GLOBALS['liste_verrous'][$fl] = array($fichier,$verrou);
36
+	elseif (_SPIP_LOCK_MODE == 2) {
37
+		if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) {
38
+			$GLOBALS['liste_verrous'][$fl] = array($fichier, $verrou);
39 39
 			return $fl;
40 40
 		}
41 41
 		else return false;
42 42
 	}
43
-	return @fopen($fichier,$mode);
43
+	return @fopen($fichier, $mode);
44 44
 }
45 45
 // http://doc.spip.org/@spip_fclose_unlock
46
-function spip_fclose_unlock($handle){
47
-	if (_SPIP_LOCK_MODE==1){
46
+function spip_fclose_unlock($handle) {
47
+	if (_SPIP_LOCK_MODE == 1) {
48 48
 		@flock($handle, LOCK_UN);
49 49
 	}
50
-	elseif(_SPIP_LOCK_MODE==2) {
51
-		spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]),end($GLOBALS['liste_verrous'][$handle]));
50
+	elseif (_SPIP_LOCK_MODE == 2) {
51
+		spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle]));
52 52
 		unset($GLOBALS['liste_verrous'][$handle]);
53 53
 	}
54 54
 	return @fclose($handle);
@@ -56,14 +56,14 @@  discard block
 block discarded – undo
56 56
 
57 57
 
58 58
 // http://doc.spip.org/@spip_file_get_contents
59
-function spip_file_get_contents ($fichier) {
59
+function spip_file_get_contents($fichier) {
60 60
 	if (substr($fichier, -3) != '.gz') {
61 61
 		if (function_exists('file_get_contents')
62 62
 		AND ( 
63 63
 			// quand on est sous window on ne sait pas si file_get_contents marche
64 64
 			// on essaye : si ca retourne du contenu alors c'est bon
65 65
 			// sinon on fait un file() pour avoir le coeur net
66
-		  ($contenu = @file_get_contents ($fichier))
66
+		  ($contenu = @file_get_contents($fichier))
67 67
 		  OR _OS_SERVEUR != 'windows')
68 68
 		)
69 69
 			return $contenu;
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
 			$contenu = @file($fichier);
72 72
 	} else
73 73
 			$contenu = @gzfile($fichier);
74
-	return is_array($contenu)?join('', $contenu):(string)$contenu;
74
+	return is_array($contenu) ?join('', $contenu) : (string) $contenu;
75 75
 }
76 76
 
77 77
 // options = array(
78 78
 // 'phpcheck' => 'oui' # verifier qu'on a bien du php
79 79
 // dezippe automatiquement les fichiers .gz
80 80
 // http://doc.spip.org/@lire_fichier
81
-function lire_fichier ($fichier, &$contenu, $options=false) {
81
+function lire_fichier($fichier, &$contenu, $options = false) {
82 82
 	$contenu = '';
83 83
 	// inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres
84 84
 	// economisons donc les acces disque, sauf chez free qui rale pour un rien
@@ -123,12 +123,12 @@  discard block
 block discarded – undo
123 123
 //
124 124
 // zippe les fichiers .gz
125 125
 // http://doc.spip.org/@ecrire_fichier
126
-function ecrire_fichier ($fichier, $contenu, $ignorer_echec = false, $truncate=true) {
126
+function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) {
127 127
 
128 128
 	#spip_timer('ecrire_fichier');
129 129
 
130 130
 	// verrouiller le fichier destination
131
-	if ($fp = spip_fopen_lock($fichier, 'a',LOCK_EX)) {
131
+	if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
132 132
 	// ecrire les donnees, compressees le cas echeant
133 133
 	// (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage
134 134
 	// de le recreer si le locker qui nous precede l'avait supprime...)
@@ -139,12 +139,12 @@  discard block
 block discarded – undo
139 139
 		// y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt
140 140
 		// sauf sous wintruc ou ca ne marche pas
141 141
 		$ok = false;
142
-		if ($truncate AND _OS_SERVEUR != 'windows'){
142
+		if ($truncate AND _OS_SERVEUR != 'windows') {
143 143
 			if (!function_exists('creer_uniqid'))
144 144
 				include_spip('inc/acces');
145 145
 			$id = creer_uniqid();
146 146
 			// on ouvre un pointeur sur un fichier temporaire en ecriture +raz
147
-			if ($fp2 = spip_fopen_lock("$fichier.$id", 'w',LOCK_EX)) {
147
+			if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) {
148 148
 				$s = @fputs($fp2, $contenu, $a = strlen($contenu));
149 149
 				$ok = ($s == $a);
150 150
 				spip_fclose_unlock($fp2);
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 				// le rename aussitot, atomique quand on est pas sous windows
156 156
 				// au pire on arrive en second en cas de concourance, et le rename echoue
157 157
 				// --> on a la version de l'autre process qui doit etre identique
158
-				@rename("$fichier.$id",$fichier);
158
+				@rename("$fichier.$id", $fichier);
159 159
 				// precaution en cas d'echec du rename
160 160
 				if (!_TEST_FILE_EXISTS OR @file_exists("$fichier.$id"))
161 161
 					@unlink("$fichier.$id");
@@ -168,10 +168,10 @@  discard block
 block discarded – undo
168 168
 		}
169 169
 		// sinon ou si methode precedente a echoueee
170 170
 		// on se rabat sur la methode ancienne
171
-		if (!$ok){
171
+		if (!$ok) {
172 172
 			// ici on est en ajout ou sous windows, cas desespere
173 173
 			if ($truncate)
174
-				@ftruncate($fp,0);
174
+				@ftruncate($fp, 0);
175 175
 			$s = @fputs($fp, $contenu, $a = strlen($contenu));
176 176
 
177 177
 			$ok = ($s == $a);
@@ -181,20 +181,20 @@  discard block
 block discarded – undo
181 181
 		// liberer le verrou et fermer le fichier
182 182
 		@chmod($fichier, _SPIP_CHMOD & 0666);
183 183
 		if ($ok) {
184
-			if (strpos($fichier,".php")!==false){
184
+			if (strpos($fichier, ".php") !== false) {
185 185
 				spip_clear_opcode_cache(realpath($fichier));
186 186
 			}
187 187
 			return $ok;
188 188
 		}
189 189
 	}
190 190
 
191
-	if (!$ignorer_echec){
191
+	if (!$ignorer_echec) {
192 192
 		include_spip('inc/autoriser');
193 193
 		if (autoriser('chargerftp'))
194 194
 			raler_fichier($fichier);
195 195
 		spip_unlink($fichier);
196 196
 	}
197
-	spip_log("Ecriture fichier $fichier impossible",_LOG_INFO_IMPORTANTE);
197
+	spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE);
198 198
 	return false;
199 199
 }
200 200
 
@@ -206,10 +206,10 @@  discard block
 block discarded – undo
206 206
  * @param <type> $ecrire_quand_meme
207 207
  * @param <type> $truncate 
208 208
  */
209
-function ecrire_fichier_securise ($fichier, $contenu, $ecrire_quand_meme = false, $truncate=true) {
210
-	if (substr($fichier,-4) !== '.php')
209
+function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) {
210
+	if (substr($fichier, -4) !== '.php')
211 211
 		spip_log('Erreur de programmation: '.$fichier.' doit finir par .php');
212
-	$contenu = "<"."?php die ('Acces interdit'); ?".">\n" . $contenu;
212
+	$contenu = "<"."?php die ('Acces interdit'); ?".">\n".$contenu;
213 213
 	return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate);
214 214
 }
215 215
 
@@ -219,9 +219,9 @@  discard block
 block discarded – undo
219 219
  * @param <type> $contenu
220 220
  * @param <type> $options 
221 221
  */
222
-function lire_fichier_securise ($fichier, &$contenu, $options=false) {
223
-	if ($res = lire_fichier($fichier,$contenu,$options)){
224
-		$contenu = substr($contenu,strlen("<"."?php die ('Acces interdit'); ?".">\n"));
222
+function lire_fichier_securise($fichier, &$contenu, $options = false) {
223
+	if ($res = lire_fichier($fichier, $contenu, $options)) {
224
+		$contenu = substr($contenu, strlen("<"."?php die ('Acces interdit'); ?".">\n"));
225 225
 	}
226 226
 	return $res;
227 227
 }
@@ -254,14 +254,14 @@  discard block
 block discarded – undo
254 254
 {
255 255
 	if (!file_exists($fichier)) return false;
256 256
 	if (!$c = @filemtime($fichier)) return false;
257
-	return (time()-$n <= $c);
257
+	return (time() - $n <= $c);
258 258
 }
259 259
 
260 260
 //
261 261
 // Supprimer le fichier de maniere sympa (flock)
262 262
 //
263 263
 // http://doc.spip.org/@supprimer_fichier
264
-function supprimer_fichier($fichier, $lock=true) {
264
+function supprimer_fichier($fichier, $lock = true) {
265 265
 	if (!@file_exists($fichier))
266 266
 		return true;
267 267
 
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 // http://doc.spip.org/@spip_unlink
283 283
 function spip_unlink($f) {
284 284
 	if (!is_dir($f))
285
-		supprimer_fichier($f,false);
285
+		supprimer_fichier($f, false);
286 286
 	else {
287 287
 		@unlink("$f/.ok");
288 288
 		@rmdir($f);
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
  * @param bool $clear_realpath_cache
295 295
  * @param null $filename
296 296
  */
297
-function spip_clearstatcache($clear_realpath_cache = false, $filename=null){
297
+function spip_clearstatcache($clear_realpath_cache = false, $filename = null) {
298 298
 	if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) {
299 299
    // Below PHP 5.3, clearstatcache does not accept any function parameters.
300 300
    return clearstatcache();
@@ -343,12 +343,12 @@  discard block
 block discarded – undo
343 343
  * Ne fait rien en dehors de ce cas
344 344
  *
345 345
  */
346
-function spip_attend_invalidation_opcode_cache(){
346
+function spip_attend_invalidation_opcode_cache() {
347 347
 	if (function_exists('opcache_get_configuration')
348 348
 	  AND @ini_get('opcache.enable')
349 349
 	  AND @ini_get('opcache.validate_timestamps')
350
-	  AND $duree = @ini_get('opcache.revalidate_freq') ) {
351
-		sleep($duree+1);
350
+	  AND $duree = @ini_get('opcache.revalidate_freq')) {
351
+		sleep($duree + 1);
352 352
 	}
353 353
 }
354 354
 
@@ -366,9 +366,9 @@  discard block
 block discarded – undo
366 366
 	
367 367
 	foreach (scandir($dir) as $item) {
368 368
 		if ($item == '.' || $item == '..') continue;
369
-		if (!supprimer_repertoire($dir . "/" . $item)) {
370
-			@chmod($dir . "/" . $item, 0777);
371
-			if (!supprimer_repertoire($dir . "/" . $item)) return false;
369
+		if (!supprimer_repertoire($dir."/".$item)) {
370
+			@chmod($dir."/".$item, 0777);
371
+			if (!supprimer_repertoire($dir."/".$item)) return false;
372 372
 		};
373 373
 	}
374 374
 	
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 // subdir valant alors ce qui suit le dernier / dans $base
384 384
 //
385 385
 // http://doc.spip.org/@sous_repertoire
386
-function sous_repertoire($base, $subdir='', $nobase = false, $tantpis=false) {
386
+function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) {
387 387
 	static $dirs = array();
388 388
 
389 389
 	$base = str_replace("//", "/", $base);
@@ -393,9 +393,9 @@  discard block
 block discarded – undo
393 393
 
394 394
 	if (!strlen($subdir)) {
395 395
 		$n = strrpos($base, "/");
396
-		if ($n === false) return $nobase ? '' : ($base .'/');
397
-		$subdir = substr($base, $n+1);
398
-		$base = substr($base, 0, $n+1);
396
+		if ($n === false) return $nobase ? '' : ($base.'/');
397
+		$subdir = substr($base, $n + 1);
398
+		$base = substr($base, 0, $n + 1);
399 399
 	} else {
400 400
 		$base .= '/';
401 401
 		$subdir = str_replace("/", "", $subdir);
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 	@chmod($path, _SPIP_CHMOD);
419 419
 
420 420
 	if (is_dir($path) && is_writable($path)) {
421
-		@touch ("$path/.ok");
421
+		@touch("$path/.ok");
422 422
 		spip_log("creation $base$subdir/");
423 423
 		return $baseaff.($dirs[$base.$subdir] = "$subdir/");
424 424
 	}
@@ -433,9 +433,9 @@  discard block
 block discarded – undo
433 433
 		spip_log("echec creation $base${subdir}");
434 434
 		if ($tantpis) return '';
435 435
 		if (!_DIR_RESTREINT)
436
-			$base = preg_replace(',^' . _DIR_RACINE .',', '',$base);
436
+			$base = preg_replace(',^'._DIR_RACINE.',', '', $base);
437 437
 		$base .= $subdir;
438
-		raler_fichier($base . '/.plat');
438
+		raler_fichier($base.'/.plat');
439 439
 	}
440 440
 	spip_log("faux sous-repertoire $base${subdir}");
441 441
 	return $baseaff.($dirs[$base.$subdir] = "${subdir}_");
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 // si $recurs vaut false, la fonction ne descend pas dans les sus repertoires
455 455
 //
456 456
 // http://doc.spip.org/@preg_files
457
-function preg_files($dir, $pattern=-1 /* AUTO */, $maxfiles = 10000, $recurs=array()) {
457
+function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = array()) {
458 458
 	$nbfiles = 0;
459 459
 	if ($pattern == -1)
460 460
 		$pattern = "^$dir";
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
 	if ($dir == '') $dir = '.';
466 466
 
467 467
 	if (@is_dir($dir) AND is_readable($dir) AND $d = @opendir($dir)) {
468
-		while (($f = readdir($d)) !== false && ($nbfiles<$maxfiles)) {
468
+		while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) {
469 469
 			if ($f[0] != '.' # ignorer . .. .svn etc
470 470
 			AND $f != 'CVS'
471 471
 			AND $f != 'remove.txt'
@@ -477,15 +477,15 @@  discard block
 block discarded – undo
477 477
 						$nbfiles++;
478 478
 					}
479 479
 				} 
480
-				else if (is_dir($f) AND is_array($recurs)){
480
+				else if (is_dir($f) AND is_array($recurs)) {
481 481
 					$rp = @realpath($f);
482
-					if (!is_string($rp) OR !strlen($rp)) $rp=$f; # realpath n'est peut etre pas autorise
482
+					if (!is_string($rp) OR !strlen($rp)) $rp = $f; # realpath n'est peut etre pas autorise
483 483
 					if (!isset($recurs[$rp])) {
484 484
 						$recurs[$rp] = true;
485 485
 						$beginning = $fichiers;
486 486
 						$end = preg_files("$f/", $pattern,
487
-							$maxfiles-$nbfiles, $recurs);
488
-						$fichiers = array_merge((array)$beginning, (array)$end);
487
+							$maxfiles - $nbfiles, $recurs);
488
+						$fichiers = array_merge((array) $beginning, (array) $end);
489 489
 						$nbfiles = count($fichiers);
490 490
 					}
491 491
 				}
Please login to merge, or discard this patch.
ecrire/inc/install.php 4 patches
Doc Comments   +11 added lines patch added patch discarded remove patch
@@ -252,6 +252,11 @@  discard block
 block discarded – undo
252 252
 }
253 253
 
254 254
 // http://doc.spip.org/@info_progression_etape
255
+/**
256
+ * @param integer $en_cours
257
+ * @param string $phase
258
+ * @param string $dir
259
+ */
255 260
 function info_progression_etape($en_cours,$phase,$dir, $erreur = false){
256 261
 	//$en_cours = _request('etape')?_request('etape'):"";
257 262
 	$liste = find_all_in_path($dir,$phase.'(([0-9])+|fin)[.]php$');
@@ -361,6 +366,9 @@  discard block
 block discarded – undo
361 366
 }
362 367
 
363 368
 // http://doc.spip.org/@install_connexion_form
369
+/**
370
+ * @param integer $etape
371
+ */
364 372
 function install_connexion_form($db, $login, $pass, $predef, $hidden, $etape, $jquery=true)
365 373
 {
366 374
 	$server_db = (is_string($predef[0])) ? $predef[0] : '';
@@ -521,6 +529,9 @@  discard block
 block discarded – undo
521 529
 	return array($checked, $bases);
522 530
 }
523 531
 
532
+/**
533
+ * @param string[] $hidden
534
+ */
524 535
 function install_propager($hidden)
525 536
 {
526 537
 	$res = '';
Please login to merge, or discard this patch.
Indentation   +333 added lines, -333 removed lines patch added patch discarded remove patch
@@ -40,12 +40,12 @@  discard block
 block discarded – undo
40 40
 **/
41 41
 function install_fichier_connexion($nom, $texte)
42 42
 {
43
-	$texte = "<"."?php\n"
44
-	. "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n"
45
-	. $texte
46
-	. "?".">";
43
+    $texte = "<"."?php\n"
44
+    . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n"
45
+    . $texte
46
+    . "?".">";
47 47
 
48
-	ecrire_fichier($nom, $texte);
48
+    ecrire_fichier($nom, $texte);
49 49
 }
50 50
 
51 51
 
@@ -74,18 +74,18 @@  discard block
 block discarded – undo
74 74
 **/
75 75
 function install_connexion($adr, $port, $login, $pass, $base, $type, $pref, $ldap='')
76 76
 {
77
-	$adr = addcslashes($adr,"'\\");
78
-	$port = addcslashes($port,"'\\");
79
-	$login = addcslashes($login,"'\\");
80
-	$pass = addcslashes($pass,"'\\");
81
-	$base = addcslashes($base,"'\\");
82
-	$type = addcslashes($type,"'\\");
83
-	$pref = addcslashes($pref,"'\\");
84
-	$ldap = addcslashes($ldap,"'\\");
85
-	return "\$GLOBALS['spip_connect_version'] = 0.7;\n"
86
-	. "spip_connect_db("
87
-	. "'$adr','$port','$login','$pass','$base'"
88
-	. ",'$type', '$pref','$ldap');\n";
77
+    $adr = addcslashes($adr,"'\\");
78
+    $port = addcslashes($port,"'\\");
79
+    $login = addcslashes($login,"'\\");
80
+    $pass = addcslashes($pass,"'\\");
81
+    $base = addcslashes($base,"'\\");
82
+    $type = addcslashes($type,"'\\");
83
+    $pref = addcslashes($pref,"'\\");
84
+    $ldap = addcslashes($ldap,"'\\");
85
+    return "\$GLOBALS['spip_connect_version'] = 0.7;\n"
86
+    . "spip_connect_db("
87
+    . "'$adr','$port','$login','$pass','$base'"
88
+    . ",'$type', '$pref','$ldap');\n";
89 89
 }
90 90
 
91 91
 
@@ -102,23 +102,23 @@  discard block
 block discarded – undo
102 102
 **/
103 103
 function analyse_fichier_connection($file)
104 104
 {
105
-	$s = @join('', file($file));
106
-	if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) {
107
-		array_shift($regs);
108
-		return $regs;
109
-	} else {
110
-		$ar = '\s*\'([^\']*)\'';
111
-		$r = '\s*,' . $ar;
112
-		$r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r)?)?)?#";
113
-		if (preg_match($r, $s, $regs)) {
114
-			$regs[2] = $regs[1] . (!$regs[2] ? '' : ":$port_db;");
115
-			array_shift($regs);
116
-			array_shift($regs);
117
-			return $regs;
118
-		}
119
-	}
120
-	spip_log("$file n'est pas un fichier de connexion");
121
-	return array();
105
+    $s = @join('', file($file));
106
+    if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) {
107
+        array_shift($regs);
108
+        return $regs;
109
+    } else {
110
+        $ar = '\s*\'([^\']*)\'';
111
+        $r = '\s*,' . $ar;
112
+        $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r)?)?)?#";
113
+        if (preg_match($r, $s, $regs)) {
114
+            $regs[2] = $regs[1] . (!$regs[2] ? '' : ":$port_db;");
115
+            array_shift($regs);
116
+            array_shift($regs);
117
+            return $regs;
118
+        }
119
+    }
120
+    spip_log("$file n'est pas un fichier de connexion");
121
+    return array();
122 122
 }
123 123
 
124 124
 /**
@@ -136,20 +136,20 @@  discard block
 block discarded – undo
136 136
 **/
137 137
 function bases_referencees($exclu='')
138 138
 {
139
-	$tables = array();
140
-	foreach(preg_files(_DIR_CONNECT, '.php$') as $f) {
141
-		if ($f != $exclu AND analyse_fichier_connection($f))
142
-			$tables[]= basename($f, '.php');
143
-	}
144
-	return $tables;
139
+    $tables = array();
140
+    foreach(preg_files(_DIR_CONNECT, '.php$') as $f) {
141
+        if ($f != $exclu AND analyse_fichier_connection($f))
142
+            $tables[]= basename($f, '.php');
143
+    }
144
+    return $tables;
145 145
 }
146 146
 
147 147
 
148 148
 function install_mode_appel($server_db, $tout=true)
149 149
 {
150
-	return ($server_db != 'mysql') ? ''
151
-	: (($tout  ? test_rappel_nom_base_mysql($server_db) : '')
152
-		. test_sql_mode_mysql($server_db)	);
150
+    return ($server_db != 'mysql') ? ''
151
+    : (($tout  ? test_rappel_nom_base_mysql($server_db) : '')
152
+        . test_sql_mode_mysql($server_db)	);
153 153
 }
154 154
 
155 155
 //
@@ -157,224 +157,224 @@  discard block
 block discarded – undo
157 157
 // (sert a l'etape 1 de l'installation)
158 158
 // http://doc.spip.org/@tester_compatibilite_hebergement
159 159
 function tester_compatibilite_hebergement() {
160
-	$err = array();
161
-
162
-	$p = phpversion();
163
-	if (preg_match(',^([0-9]+)\.([0-9]+)\.([0-9]+),', $p, $regs)) {
164
-		$php = array($regs[1], $regs[2], $regs[3]);
165
-		$m = '5.1.0';
166
-		$min = explode('.', $m);
167
-		if ($php[0]<$min[0]
168
-		OR ($php[0]==$min[0] AND $php[1]<$min[1])
169
-		OR ($php[0]==$min[0] AND $php[1]==$min[1] AND $php[2]<$min[2]))
170
-			$err[] = _T('install_php_version', array('version' => $p,  'minimum' => $m));
171
-	}
172
-
173
-	// Si on n'a pas la bonne version de PHP, c'est la fin
174
-	if ($err) 
175
-		die("<div class='error'>" 
176
-		. "<h3>"._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>"
177
-		. "<li><strong>{$err[0]}</strong></li>\n</ul></div>");
178
-
179
-	// Il faut une base de donnees tout de meme ...
180
-	$serveurs = install_select_serveur();
181
-	if (!$serveurs)
182
-		$err[] = _T('install_extension_php_obligatoire')
183
-		. " <a href='http://www.php.net/mysql'>MYSQL</a>"
184
-		. "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>"
185
-		. "| <a href='http://www.php.net/sqlite'>SQLite</a>";
186
-
187
-	// et il faut preg
188
-	if (!function_exists('preg_match_all'))
189
-		$err[] = _T('install_extension_php_obligatoire')
190
-		. " <a href='http://se.php.net/pcre'>PCRE</a>";
191
-
192
-	// et surtout pas ce mbstring.overload
193
-	if ($a = @ini_get('mbstring.func_overload'))
194
-		$err[] = _T('install_extension_mbstring')
195
-		. "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>";
196
-
197
-	if ($err) {
198
-			echo "<div class='error'>"
199
-				."<h3>"._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>";
200
-			foreach($err as $e)
201
-				echo "<li><strong>$e</strong></li>\n";
202
-
203
-		# a priori ici on pourrait die(), mais il faut laisser la possibilite
204
-		# de forcer malgre tout (pour tester, ou si bug de detection)
205
-		echo "</ul></div>\n";
206
-	}
160
+    $err = array();
161
+
162
+    $p = phpversion();
163
+    if (preg_match(',^([0-9]+)\.([0-9]+)\.([0-9]+),', $p, $regs)) {
164
+        $php = array($regs[1], $regs[2], $regs[3]);
165
+        $m = '5.1.0';
166
+        $min = explode('.', $m);
167
+        if ($php[0]<$min[0]
168
+        OR ($php[0]==$min[0] AND $php[1]<$min[1])
169
+        OR ($php[0]==$min[0] AND $php[1]==$min[1] AND $php[2]<$min[2]))
170
+            $err[] = _T('install_php_version', array('version' => $p,  'minimum' => $m));
171
+    }
172
+
173
+    // Si on n'a pas la bonne version de PHP, c'est la fin
174
+    if ($err) 
175
+        die("<div class='error'>" 
176
+        . "<h3>"._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>"
177
+        . "<li><strong>{$err[0]}</strong></li>\n</ul></div>");
178
+
179
+    // Il faut une base de donnees tout de meme ...
180
+    $serveurs = install_select_serveur();
181
+    if (!$serveurs)
182
+        $err[] = _T('install_extension_php_obligatoire')
183
+        . " <a href='http://www.php.net/mysql'>MYSQL</a>"
184
+        . "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>"
185
+        . "| <a href='http://www.php.net/sqlite'>SQLite</a>";
186
+
187
+    // et il faut preg
188
+    if (!function_exists('preg_match_all'))
189
+        $err[] = _T('install_extension_php_obligatoire')
190
+        . " <a href='http://se.php.net/pcre'>PCRE</a>";
191
+
192
+    // et surtout pas ce mbstring.overload
193
+    if ($a = @ini_get('mbstring.func_overload'))
194
+        $err[] = _T('install_extension_mbstring')
195
+        . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>";
196
+
197
+    if ($err) {
198
+            echo "<div class='error'>"
199
+                ."<h3>"._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>";
200
+            foreach($err as $e)
201
+                echo "<li><strong>$e</strong></li>\n";
202
+
203
+        # a priori ici on pourrait die(), mais il faut laisser la possibilite
204
+        # de forcer malgre tout (pour tester, ou si bug de detection)
205
+        echo "</ul></div>\n";
206
+    }
207 207
 }
208 208
 
209 209
 
210 210
 // Une fonction pour faciliter la recherche du login (superflu ?)
211 211
 // http://doc.spip.org/@login_hebergeur
212 212
 function login_hebergeur() {
213
-	global $HTTP_X_HOST, $REQUEST_URI, $SERVER_NAME, $HTTP_HOST;
214
-
215
-	$base_hebergeur = 'localhost'; # par defaut
216
-
217
-	// Lycos (ex-Multimachin)
218
-	if ($HTTP_X_HOST == 'membres.lycos.fr') {
219
-		preg_match(',^/([^/]*),', $REQUEST_URI, $regs);
220
-		$login_hebergeur = $regs[1];
221
-	}
222
-	// Altern
223
-	else if (preg_match(',altern\.com$,', $SERVER_NAME)) {
224
-		preg_match(',([^.]*\.[^.]*)$,', $HTTP_HOST, $regs);
225
-		$login_hebergeur = preg_replace('[^\w\d]', '_', $regs[1]);
226
-	}
227
-	// Free
228
-	else if (preg_match(',(.*)\.free\.fr$,', $SERVER_NAME, $regs)) {
229
-		$base_hebergeur = 'sql.free.fr';
230
-		$login_hebergeur = $regs[1];
231
-	} else $login_hebergeur = '';
232
-
233
-	return array($base_hebergeur, $login_hebergeur);
213
+    global $HTTP_X_HOST, $REQUEST_URI, $SERVER_NAME, $HTTP_HOST;
214
+
215
+    $base_hebergeur = 'localhost'; # par defaut
216
+
217
+    // Lycos (ex-Multimachin)
218
+    if ($HTTP_X_HOST == 'membres.lycos.fr') {
219
+        preg_match(',^/([^/]*),', $REQUEST_URI, $regs);
220
+        $login_hebergeur = $regs[1];
221
+    }
222
+    // Altern
223
+    else if (preg_match(',altern\.com$,', $SERVER_NAME)) {
224
+        preg_match(',([^.]*\.[^.]*)$,', $HTTP_HOST, $regs);
225
+        $login_hebergeur = preg_replace('[^\w\d]', '_', $regs[1]);
226
+    }
227
+    // Free
228
+    else if (preg_match(',(.*)\.free\.fr$,', $SERVER_NAME, $regs)) {
229
+        $base_hebergeur = 'sql.free.fr';
230
+        $login_hebergeur = $regs[1];
231
+    } else $login_hebergeur = '';
232
+
233
+    return array($base_hebergeur, $login_hebergeur);
234 234
 }
235 235
 
236 236
 
237 237
 // http://doc.spip.org/@info_etape
238 238
 function info_etape($titre, $complement = ''){
239
-	return "<h2>".$titre."</h2>\n" .
240
-	($complement ? "".$complement."\n":'');
239
+    return "<h2>".$titre."</h2>\n" .
240
+    ($complement ? "".$complement."\n":'');
241 241
 }
242 242
 
243 243
 // http://doc.spip.org/@bouton_suivant
244 244
 function bouton_suivant($code = '') {
245
-	if($code=='') $code = _T('bouton_suivant');
246
-	static $suivant = 0;
247
-	$id = 'suivant'.(($suivant>0)?strval($suivant):'');
248
-	$suivant +=1;
249
-	return "\n<p class='boutons suivant'><input id='".$id."' type='submit'\nvalue=\"" .
250
-		$code .
251
-		" >>\" /></p>\n";
245
+    if($code=='') $code = _T('bouton_suivant');
246
+    static $suivant = 0;
247
+    $id = 'suivant'.(($suivant>0)?strval($suivant):'');
248
+    $suivant +=1;
249
+    return "\n<p class='boutons suivant'><input id='".$id."' type='submit'\nvalue=\"" .
250
+        $code .
251
+        " >>\" /></p>\n";
252 252
 }
253 253
 
254 254
 // http://doc.spip.org/@info_progression_etape
255 255
 function info_progression_etape($en_cours,$phase,$dir, $erreur = false){
256
-	//$en_cours = _request('etape')?_request('etape'):"";
257
-	$liste = find_all_in_path($dir,$phase.'(([0-9])+|fin)[.]php$');
258
-	$debut = 1; $etat = "ok";
259
-	$last = count($liste);
256
+    //$en_cours = _request('etape')?_request('etape'):"";
257
+    $liste = find_all_in_path($dir,$phase.'(([0-9])+|fin)[.]php$');
258
+    $debut = 1; $etat = "ok";
259
+    $last = count($liste);
260 260
 //	$texte_etat = array('ok'=>'OK','encours'=>_T('en_cours'),'todo'=>_T('todo'));
261 261
 
262
-	$intitule_etat["etape_"][1] = typo(_T('info_connexion_base_donnee'));
263
-	$intitule_etat["etape_"][2] = typo(_T('menu_aide_installation_choix_base'));
264
-	$intitule_etat["etape_"][3] = typo(_T('info_informations_personnelles'));
265
-	$intitule_etat["etape_"][4] = typo(_T('info_derniere_etape'));
262
+    $intitule_etat["etape_"][1] = typo(_T('info_connexion_base_donnee'));
263
+    $intitule_etat["etape_"][2] = typo(_T('menu_aide_installation_choix_base'));
264
+    $intitule_etat["etape_"][3] = typo(_T('info_informations_personnelles'));
265
+    $intitule_etat["etape_"][4] = typo(_T('info_derniere_etape'));
266 266
 
267
-	$intitule_etat["etape_ldap"][1] = typo(_T('titre_connexion_ldap'));
268
-	$intitule_etat["etape_ldap"][2] = typo(_T('titre_connexion_ldap'));
269
-	$intitule_etat["etape_ldap"][3] = typo(_T('info_chemin_acces_1'));
270
-	$intitule_etat["etape_ldap"][4] = typo(_T('info_reglage_ldap'));
271
-	$intitule_etat["etape_ldap"][5] = typo(_T('info_ldap_ok'));
267
+    $intitule_etat["etape_ldap"][1] = typo(_T('titre_connexion_ldap'));
268
+    $intitule_etat["etape_ldap"][2] = typo(_T('titre_connexion_ldap'));
269
+    $intitule_etat["etape_ldap"][3] = typo(_T('info_chemin_acces_1'));
270
+    $intitule_etat["etape_ldap"][4] = typo(_T('info_reglage_ldap'));
271
+    $intitule_etat["etape_ldap"][5] = typo(_T('info_ldap_ok'));
272 272
 
273 273
 //	$aff_etapes = "<span id='etapes'>";
274 274
 
275
-	$aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>";
276
-
277
-	foreach($liste as $etape=>$fichier){
278
-		if ($debut < $last) {
279
-			if ($debut == $en_cours && $erreur) $class = "on erreur";
280
-			else if ($debut == $en_cours) $class = "on";
281
-			else if ($debut > $en_cours) $class = "prochains";
282
-			else $class = "valides";
283
-
284
-			$aff_etapes .= "<li class='$class'><div class='fond'>";
285
-			$aff_etapes .= ($debut == $en_cours)?"<strong>":'';
286
-			$aff_etapes .= "<em>"._T('etape')." </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
287
-			$aff_etapes .= $intitule_etat["$phase"][$debut];
288
-			$aff_etapes .= ($debut == $en_cours)?"</strong>":'';
289
-			$aff_etapes .= "</div></li>";
290
-		}
291
-		$debut++;
292
-	}
293
-	$aff_etapes .= "</ul>";
294
-	$aff_etapes .= "<br class='nettoyeur' />\n";
295
-	return $aff_etapes;
275
+    $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>";
276
+
277
+    foreach($liste as $etape=>$fichier){
278
+        if ($debut < $last) {
279
+            if ($debut == $en_cours && $erreur) $class = "on erreur";
280
+            else if ($debut == $en_cours) $class = "on";
281
+            else if ($debut > $en_cours) $class = "prochains";
282
+            else $class = "valides";
283
+
284
+            $aff_etapes .= "<li class='$class'><div class='fond'>";
285
+            $aff_etapes .= ($debut == $en_cours)?"<strong>":'';
286
+            $aff_etapes .= "<em>"._T('etape')." </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
287
+            $aff_etapes .= $intitule_etat["$phase"][$debut];
288
+            $aff_etapes .= ($debut == $en_cours)?"</strong>":'';
289
+            $aff_etapes .= "</div></li>";
290
+        }
291
+        $debut++;
292
+    }
293
+    $aff_etapes .= "</ul>";
294
+    $aff_etapes .= "<br class='nettoyeur' />\n";
295
+    return $aff_etapes;
296 296
 }
297 297
 
298 298
 
299 299
 // http://doc.spip.org/@fieldset
300 300
 function fieldset($legend,  $champs = array(), $apres='', $avant='') {
301
-	return "<fieldset>\n" .
302
-	  $avant .
303
-	  ($legend ? "<legend>".$legend."</legend>\n" : '') .
304
-	  fieldset_champs($champs) .
305
-	  $apres .
306
-	  "</fieldset>\n";
301
+    return "<fieldset>\n" .
302
+        $avant .
303
+        ($legend ? "<legend>".$legend."</legend>\n" : '') .
304
+        fieldset_champs($champs) .
305
+        $apres .
306
+        "</fieldset>\n";
307 307
 }
308 308
 
309 309
 function fieldset_champs($champs = array())
310
-  {
311
-	$fieldset = '';
312
-	foreach ($champs as $nom => $contenu) {
313
-		$type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text');
314
-		$class = isset($contenu['hidden']) ? '' : "class='formo' size='40' ";
315
-		if(isset($contenu['alternatives'])) {
316
-			$fieldset .= $contenu['label'] ."\n";
317
-			foreach($contenu['alternatives'] as $valeur => $label) {
318
-				$fieldset .= "<input type='radio' name='".$nom .
319
-				"' id='$nom-$valeur' value='$valeur'"
320
-				  .(($valeur==$contenu['valeur'])?"\nchecked='checked'":'')
321
-				  ."/>\n";
322
-				$fieldset .= "<label for='$nom-$valeur'>".$label."</label>\n";
323
-			}
324
-			$fieldset .= "<br />\n";
325
-		}
326
-		else {
327
-			$fieldset .= "<label for='".$nom."'>".$contenu['label']."</label>\n";
328
-			$fieldset .= "<input ".$class."type='".$type."' id='" . $nom . "' name='".$nom."'\nvalue='".$contenu['valeur']."'"
329
-							  .(preg_match(',^(pass|login),', $nom)?" autocomplete='off'":'')
330
-			          . ((isset($contenu['required']) AND $contenu['required'])?" required='required'":"")
331
-			          .	" />\n";
332
-		}
333
-	}
334
-	return $fieldset;
310
+    {
311
+    $fieldset = '';
312
+    foreach ($champs as $nom => $contenu) {
313
+        $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text');
314
+        $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' ";
315
+        if(isset($contenu['alternatives'])) {
316
+            $fieldset .= $contenu['label'] ."\n";
317
+            foreach($contenu['alternatives'] as $valeur => $label) {
318
+                $fieldset .= "<input type='radio' name='".$nom .
319
+                "' id='$nom-$valeur' value='$valeur'"
320
+                    .(($valeur==$contenu['valeur'])?"\nchecked='checked'":'')
321
+                    ."/>\n";
322
+                $fieldset .= "<label for='$nom-$valeur'>".$label."</label>\n";
323
+            }
324
+            $fieldset .= "<br />\n";
325
+        }
326
+        else {
327
+            $fieldset .= "<label for='".$nom."'>".$contenu['label']."</label>\n";
328
+            $fieldset .= "<input ".$class."type='".$type."' id='" . $nom . "' name='".$nom."'\nvalue='".$contenu['valeur']."'"
329
+                                .(preg_match(',^(pass|login),', $nom)?" autocomplete='off'":'')
330
+                        . ((isset($contenu['required']) AND $contenu['required'])?" required='required'":"")
331
+                        .	" />\n";
332
+        }
333
+    }
334
+    return $fieldset;
335 335
 }
336 336
 
337 337
 function install_select_serveur()
338 338
 {
339
-	$options = array();
340
-	$dir = _DIR_RESTREINT . 'req/';
341
-	$d = @opendir($dir);
342
-	if (!$d) return array();
343
-	while ($f = readdir($d)) {
344
-		if ((preg_match('/^(.*)[.]php$/', $f, $s))
345
-		AND is_readable($f = $dir . $f)) {
346
-			require_once($f);
347
-			$s = $s[1];
348
-			$v = 'spip_versions_' . $s;
349
-			if (function_exists($v) AND $v()) {
350
-			  $titre = _T("install_select_type_$s");
351
-				// proposer sqlite3 par defaut si dispo
352
-				$selected = ($s=='sqlite3'?" selected='selected'":"");
353
-			  $options[$s] =  "<option value='$s'$selected>"
354
-			    . ($titre ? $titre : $s)
355
-			    ."</option>";
356
-			} else spip_log("$s: portage indisponible");
357
-		}
358
-	}
359
-	sort($options);
360
-	return $options;
339
+    $options = array();
340
+    $dir = _DIR_RESTREINT . 'req/';
341
+    $d = @opendir($dir);
342
+    if (!$d) return array();
343
+    while ($f = readdir($d)) {
344
+        if ((preg_match('/^(.*)[.]php$/', $f, $s))
345
+        AND is_readable($f = $dir . $f)) {
346
+            require_once($f);
347
+            $s = $s[1];
348
+            $v = 'spip_versions_' . $s;
349
+            if (function_exists($v) AND $v()) {
350
+                $titre = _T("install_select_type_$s");
351
+                // proposer sqlite3 par defaut si dispo
352
+                $selected = ($s=='sqlite3'?" selected='selected'":"");
353
+                $options[$s] =  "<option value='$s'$selected>"
354
+                . ($titre ? $titre : $s)
355
+                ."</option>";
356
+            } else spip_log("$s: portage indisponible");
357
+        }
358
+    }
359
+    sort($options);
360
+    return $options;
361 361
 }
362 362
 
363 363
 // http://doc.spip.org/@install_connexion_form
364 364
 function install_connexion_form($db, $login, $pass, $predef, $hidden, $etape, $jquery=true)
365 365
 {
366
-	$server_db = (is_string($predef[0])) ? $predef[0] : '';
367
-
368
-	return generer_form_ecrire('install', (
369
-	  "\n<input type='hidden' name='etape' value='$etape' />"
370
-	. $hidden
371
-	. (_request('echec')?
372
-			("<p><b>"._T('avis_connexion_echec_1').
373
-			"</b></p><p>"._T('avis_connexion_echec_2')."</p><p style='font-size: small;'>"._T('avis_connexion_echec_3')."</p>")
374
-			:"")
375
-
376
-	. ($jquery?http_script('',  'jquery.js'):'')
377
-	. http_script('
366
+    $server_db = (is_string($predef[0])) ? $predef[0] : '';
367
+
368
+    return generer_form_ecrire('install', (
369
+        "\n<input type='hidden' name='etape' value='$etape' />"
370
+    . $hidden
371
+    . (_request('echec')?
372
+            ("<p><b>"._T('avis_connexion_echec_1').
373
+            "</b></p><p>"._T('avis_connexion_echec_2')."</p><p style='font-size: small;'>"._T('avis_connexion_echec_3')."</p>")
374
+            :"")
375
+
376
+    . ($jquery?http_script('',  'jquery.js'):'')
377
+    . http_script('
378 378
 		$(document).ready(function() {
379 379
 			$("input[type=hidden][name=server_db]").each(function(){
380 380
 				if ($(this).attr("value").match("sqlite*")){
@@ -395,67 +395,67 @@  discard block
 block discarded – undo
395 395
 			}
396 396
 		});')
397 397
 
398
-	. ($server_db
399
-		? '<input type="hidden" name="server_db" value="'.$server_db.'" />'
400
-			. (($predef[0])
401
-			   ?('<h3>'._T('install_serveur_hebergeur').'</h3>')
402
-				:'')
403
-		: ('<fieldset><legend>'
404
-		   ._T('install_select_type_db')
405
-		. "</legend>"
406
-			.'<label for="sql_serveur_db" class="p">'
407
-			. _T('install_types_db_connus')
408
-			// Passer l'avertissement SQLIte en  commentaire, on pourra facilement le supprimer par la suite sans changer les traductions.
409
-			. "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>'
410
-			.'</label>'
411
-		. "\n<div class='p center'><select name='server_db' id='sql_serveur_db' >\n"
412
-		.   join("\n", install_select_serveur())
413
-		. "\n</select></div></fieldset>")
414
-	)
415
-	. '<div id="install_adresse_base_hebergeur">'
416
-	. '<p>'. _T('texte_connexion_mysql').'</p>'
417
-	. ($predef[1]
418
-	? '<h3>'._T('install_adresse_base_hebergeur').'</h3>'
419
-	: fieldset(_T('entree_base_donnee_1'),
420
-		array(
421
-			'adresse_db' => array(
422
-				'label' => $db[1],
423
-				'valeur' => $db[0]
424
-			),
425
-		)
426
-	)
427
-	)
428
-	. '</div>'
429
-
430
-	. '<div id="install_login_base_hebergeur">'
431
-	. ($predef[2]
432
-	? '<h3>'._T('install_login_base_hebergeur').'</h3>'
433
-	: fieldset(_T('entree_login_connexion_1'),
434
-		array(
435
-			'login_db' => array(
436
-					'label' => $login[1],
437
-					'valeur' => $login[0]
438
-			),
439
-		)
440
-	)
441
-	)
442
-	. '</div>'
443
-
444
-	. '<div id="install_pass_base_hebergeur">'
445
-	. ($predef[3]
446
-	? '<h3>'._T('install_pass_base_hebergeur').'</h3>'
447
-	: fieldset(_T('entree_mot_passe_1'),
448
-		array(
449
-			'pass_db' => array(
450
-				'label' => $pass[1],
451
-				'valeur' => $pass[0]
452
-			),
453
-		)
454
-	)
455
-	)
456
-	. '</div>'
457
-
458
-	. bouton_suivant()));
398
+    . ($server_db
399
+        ? '<input type="hidden" name="server_db" value="'.$server_db.'" />'
400
+            . (($predef[0])
401
+               ?('<h3>'._T('install_serveur_hebergeur').'</h3>')
402
+                :'')
403
+        : ('<fieldset><legend>'
404
+            ._T('install_select_type_db')
405
+        . "</legend>"
406
+            .'<label for="sql_serveur_db" class="p">'
407
+            . _T('install_types_db_connus')
408
+            // Passer l'avertissement SQLIte en  commentaire, on pourra facilement le supprimer par la suite sans changer les traductions.
409
+            . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>'
410
+            .'</label>'
411
+        . "\n<div class='p center'><select name='server_db' id='sql_serveur_db' >\n"
412
+        .   join("\n", install_select_serveur())
413
+        . "\n</select></div></fieldset>")
414
+    )
415
+    . '<div id="install_adresse_base_hebergeur">'
416
+    . '<p>'. _T('texte_connexion_mysql').'</p>'
417
+    . ($predef[1]
418
+    ? '<h3>'._T('install_adresse_base_hebergeur').'</h3>'
419
+    : fieldset(_T('entree_base_donnee_1'),
420
+        array(
421
+            'adresse_db' => array(
422
+                'label' => $db[1],
423
+                'valeur' => $db[0]
424
+            ),
425
+        )
426
+    )
427
+    )
428
+    . '</div>'
429
+
430
+    . '<div id="install_login_base_hebergeur">'
431
+    . ($predef[2]
432
+    ? '<h3>'._T('install_login_base_hebergeur').'</h3>'
433
+    : fieldset(_T('entree_login_connexion_1'),
434
+        array(
435
+            'login_db' => array(
436
+                    'label' => $login[1],
437
+                    'valeur' => $login[0]
438
+            ),
439
+        )
440
+    )
441
+    )
442
+    . '</div>'
443
+
444
+    . '<div id="install_pass_base_hebergeur">'
445
+    . ($predef[3]
446
+    ? '<h3>'._T('install_pass_base_hebergeur').'</h3>'
447
+    : fieldset(_T('entree_mot_passe_1'),
448
+        array(
449
+            'pass_db' => array(
450
+                'label' => $pass[1],
451
+                'valeur' => $pass[0]
452
+            ),
453
+        )
454
+    )
455
+    )
456
+    . '</div>'
457
+
458
+    . bouton_suivant()));
459 459
 
460 460
 }
461 461
 
@@ -465,23 +465,23 @@  discard block
 block discarded – undo
465 465
 // http://doc.spip.org/@predef_ou_cache
466 466
 function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db)
467 467
 {
468
-	return ((defined('_INSTALL_HOST_DB'))
469
-		? ''
470
-		: "\n<input type='hidden' name='adresse_db'  value=\"".spip_htmlspecialchars($adresse_db)."\" />"
471
-	)
472
-	. ((defined('_INSTALL_USER_DB'))
473
-		? ''
474
-		: "\n<input type='hidden' name='login_db' value=\"".spip_htmlspecialchars($login_db)."\" />"
475
-	)
476
-	. ((defined('_INSTALL_PASS_DB'))
477
-		? ''
478
-		: "\n<input type='hidden' name='pass_db' value=\"".spip_htmlspecialchars($pass_db)."\" />"
479
-	)
480
-
481
-	. ((defined('_INSTALL_SERVER_DB'))
482
-		? ''
483
-		: "\n<input type='hidden' name='server_db' value=\"".spip_htmlspecialchars($server_db)."\" />"
484
-	   );
468
+    return ((defined('_INSTALL_HOST_DB'))
469
+        ? ''
470
+        : "\n<input type='hidden' name='adresse_db'  value=\"".spip_htmlspecialchars($adresse_db)."\" />"
471
+    )
472
+    . ((defined('_INSTALL_USER_DB'))
473
+        ? ''
474
+        : "\n<input type='hidden' name='login_db' value=\"".spip_htmlspecialchars($login_db)."\" />"
475
+    )
476
+    . ((defined('_INSTALL_PASS_DB'))
477
+        ? ''
478
+        : "\n<input type='hidden' name='pass_db' value=\"".spip_htmlspecialchars($pass_db)."\" />"
479
+    )
480
+
481
+    . ((defined('_INSTALL_SERVER_DB'))
482
+        ? ''
483
+        : "\n<input type='hidden' name='server_db' value=\"".spip_htmlspecialchars($server_db)."\" />"
484
+        );
485 485
 }
486 486
 
487 487
 // presentation des bases existantes
@@ -489,45 +489,45 @@  discard block
 block discarded – undo
489 489
 // http://doc.spip.org/@install_etape_liste_bases
490 490
 function install_etape_liste_bases($server_db, $login_db, $disabled=array())
491 491
 {
492
-	$bases = $checked = array();
493
-	$noms = sql_listdbs($server_db);
494
-	if (!$noms) return '';
495
-
496
-	foreach ($noms as $nom){
497
-		$id = spip_htmlspecialchars($nom);
498
-		$dis = in_array($nom, $disabled) ? " disabled='disabled'" : '';
499
-		$base = " name=\"choix_db\" value=\""
500
-		  . $nom
501
-		  . '"'
502
-		  . $dis
503
-		  . " type='radio' id='$id'";
504
-		$label = "<label for='$id'>"
505
-		. ($dis ? "<i>$nom</i>" : $nom)
506
-		. "</label>";
507
-
508
-		if (!$checked AND !$dis AND
509
-		    (($nom == $login_db) OR
510
-			($GLOBALS['table_prefix'] == $nom))) {
511
-			$checked = "<input$base checked='checked' />\n$label";
512
-		} else {
513
-			$bases[]= "<input$base />\n$label";
514
-		}
515
-	}
516
-
517
-	if (!$bases && !$checked) return false;
518
-
519
-	if ($checked) {array_unshift($bases, $checked); $checked = true;}
520
-
521
-	return array($checked, $bases);
492
+    $bases = $checked = array();
493
+    $noms = sql_listdbs($server_db);
494
+    if (!$noms) return '';
495
+
496
+    foreach ($noms as $nom){
497
+        $id = spip_htmlspecialchars($nom);
498
+        $dis = in_array($nom, $disabled) ? " disabled='disabled'" : '';
499
+        $base = " name=\"choix_db\" value=\""
500
+            . $nom
501
+            . '"'
502
+            . $dis
503
+            . " type='radio' id='$id'";
504
+        $label = "<label for='$id'>"
505
+        . ($dis ? "<i>$nom</i>" : $nom)
506
+        . "</label>";
507
+
508
+        if (!$checked AND !$dis AND
509
+            (($nom == $login_db) OR
510
+            ($GLOBALS['table_prefix'] == $nom))) {
511
+            $checked = "<input$base checked='checked' />\n$label";
512
+        } else {
513
+            $bases[]= "<input$base />\n$label";
514
+        }
515
+    }
516
+
517
+    if (!$bases && !$checked) return false;
518
+
519
+    if ($checked) {array_unshift($bases, $checked); $checked = true;}
520
+
521
+    return array($checked, $bases);
522 522
 }
523 523
 
524 524
 function install_propager($hidden)
525 525
 {
526
-	$res = '';
527
-	foreach($hidden as $k) {
528
-		$v = spip_htmlentities(_request($k));
529
-		$res .= "<input type='hidden' name='$k' value='$v' />";
530
-	}
531
-	return $res;
526
+    $res = '';
527
+    foreach($hidden as $k) {
528
+        $v = spip_htmlentities(_request($k));
529
+        $res .= "<input type='hidden' name='$k' value='$v' />";
530
+    }
531
+    return $res;
532 532
 }
533 533
 ?>
Please login to merge, or discard this patch.
Braces   +52 added lines, -27 removed lines patch added patch discarded remove patch
@@ -16,7 +16,9 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Installation
17 17
 **/
18 18
 
19
-if (!defined('_ECRIRE_INC_VERSION')) return;
19
+if (!defined('_ECRIRE_INC_VERSION')) {
20
+    return;
21
+}
20 22
 
21 23
 
22 24
 /**
@@ -138,8 +140,9 @@  discard block
 block discarded – undo
138 140
 {
139 141
 	$tables = array();
140 142
 	foreach(preg_files(_DIR_CONNECT, '.php$') as $f) {
141
-		if ($f != $exclu AND analyse_fichier_connection($f))
142
-			$tables[]= basename($f, '.php');
143
+		if ($f != $exclu AND analyse_fichier_connection($f)) {
144
+					$tables[]= basename($f, '.php');
145
+		}
143 146
 	}
144 147
 	return $tables;
145 148
 }
@@ -166,39 +169,45 @@  discard block
 block discarded – undo
166 169
 		$min = explode('.', $m);
167 170
 		if ($php[0]<$min[0]
168 171
 		OR ($php[0]==$min[0] AND $php[1]<$min[1])
169
-		OR ($php[0]==$min[0] AND $php[1]==$min[1] AND $php[2]<$min[2]))
170
-			$err[] = _T('install_php_version', array('version' => $p,  'minimum' => $m));
172
+		OR ($php[0]==$min[0] AND $php[1]==$min[1] AND $php[2]<$min[2])) {
173
+					$err[] = _T('install_php_version', array('version' => $p,  'minimum' => $m));
174
+		}
171 175
 	}
172 176
 
173 177
 	// Si on n'a pas la bonne version de PHP, c'est la fin
174
-	if ($err) 
175
-		die("<div class='error'>" 
178
+	if ($err) {
179
+			die("<div class='error'>" 
176 180
 		. "<h3>"._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>"
177 181
 		. "<li><strong>{$err[0]}</strong></li>\n</ul></div>");
182
+	}
178 183
 
179 184
 	// Il faut une base de donnees tout de meme ...
180 185
 	$serveurs = install_select_serveur();
181
-	if (!$serveurs)
182
-		$err[] = _T('install_extension_php_obligatoire')
186
+	if (!$serveurs) {
187
+			$err[] = _T('install_extension_php_obligatoire')
183 188
 		. " <a href='http://www.php.net/mysql'>MYSQL</a>"
184 189
 		. "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>"
185 190
 		. "| <a href='http://www.php.net/sqlite'>SQLite</a>";
191
+	}
186 192
 
187 193
 	// et il faut preg
188
-	if (!function_exists('preg_match_all'))
189
-		$err[] = _T('install_extension_php_obligatoire')
194
+	if (!function_exists('preg_match_all')) {
195
+			$err[] = _T('install_extension_php_obligatoire')
190 196
 		. " <a href='http://se.php.net/pcre'>PCRE</a>";
197
+	}
191 198
 
192 199
 	// et surtout pas ce mbstring.overload
193
-	if ($a = @ini_get('mbstring.func_overload'))
194
-		$err[] = _T('install_extension_mbstring')
200
+	if ($a = @ini_get('mbstring.func_overload')) {
201
+			$err[] = _T('install_extension_mbstring')
195 202
 		. "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>";
203
+	}
196 204
 
197 205
 	if ($err) {
198 206
 			echo "<div class='error'>"
199 207
 				."<h3>"._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>";
200
-			foreach($err as $e)
201
-				echo "<li><strong>$e</strong></li>\n";
208
+			foreach($err as $e) {
209
+							echo "<li><strong>$e</strong></li>\n";
210
+			}
202 211
 
203 212
 		# a priori ici on pourrait die(), mais il faut laisser la possibilite
204 213
 		# de forcer malgre tout (pour tester, ou si bug de detection)
@@ -228,7 +237,9 @@  discard block
 block discarded – undo
228 237
 	else if (preg_match(',(.*)\.free\.fr$,', $SERVER_NAME, $regs)) {
229 238
 		$base_hebergeur = 'sql.free.fr';
230 239
 		$login_hebergeur = $regs[1];
231
-	} else $login_hebergeur = '';
240
+	} else {
241
+	    $login_hebergeur = '';
242
+	}
232 243
 
233 244
 	return array($base_hebergeur, $login_hebergeur);
234 245
 }
@@ -242,7 +253,9 @@  discard block
 block discarded – undo
242 253
 
243 254
 // http://doc.spip.org/@bouton_suivant
244 255
 function bouton_suivant($code = '') {
245
-	if($code=='') $code = _T('bouton_suivant');
256
+	if($code=='') {
257
+	    $code = _T('bouton_suivant');
258
+	}
246 259
 	static $suivant = 0;
247 260
 	$id = 'suivant'.(($suivant>0)?strval($suivant):'');
248 261
 	$suivant +=1;
@@ -276,10 +289,15 @@  discard block
 block discarded – undo
276 289
 
277 290
 	foreach($liste as $etape=>$fichier){
278 291
 		if ($debut < $last) {
279
-			if ($debut == $en_cours && $erreur) $class = "on erreur";
280
-			else if ($debut == $en_cours) $class = "on";
281
-			else if ($debut > $en_cours) $class = "prochains";
282
-			else $class = "valides";
292
+			if ($debut == $en_cours && $erreur) {
293
+			    $class = "on erreur";
294
+			} else if ($debut == $en_cours) {
295
+			    $class = "on";
296
+			} else if ($debut > $en_cours) {
297
+			    $class = "prochains";
298
+			} else {
299
+			    $class = "valides";
300
+			}
283 301
 
284 302
 			$aff_etapes .= "<li class='$class'><div class='fond'>";
285 303
 			$aff_etapes .= ($debut == $en_cours)?"<strong>":'';
@@ -322,8 +340,7 @@  discard block
 block discarded – undo
322 340
 				$fieldset .= "<label for='$nom-$valeur'>".$label."</label>\n";
323 341
 			}
324 342
 			$fieldset .= "<br />\n";
325
-		}
326
-		else {
343
+		} else {
327 344
 			$fieldset .= "<label for='".$nom."'>".$contenu['label']."</label>\n";
328 345
 			$fieldset .= "<input ".$class."type='".$type."' id='" . $nom . "' name='".$nom."'\nvalue='".$contenu['valeur']."'"
329 346
 							  .(preg_match(',^(pass|login),', $nom)?" autocomplete='off'":'')
@@ -339,7 +356,9 @@  discard block
 block discarded – undo
339 356
 	$options = array();
340 357
 	$dir = _DIR_RESTREINT . 'req/';
341 358
 	$d = @opendir($dir);
342
-	if (!$d) return array();
359
+	if (!$d) {
360
+	    return array();
361
+	}
343 362
 	while ($f = readdir($d)) {
344 363
 		if ((preg_match('/^(.*)[.]php$/', $f, $s))
345 364
 		AND is_readable($f = $dir . $f)) {
@@ -353,7 +372,9 @@  discard block
 block discarded – undo
353 372
 			  $options[$s] =  "<option value='$s'$selected>"
354 373
 			    . ($titre ? $titre : $s)
355 374
 			    ."</option>";
356
-			} else spip_log("$s: portage indisponible");
375
+			} else {
376
+			    spip_log("$s: portage indisponible");
377
+			}
357 378
 		}
358 379
 	}
359 380
 	sort($options);
@@ -491,7 +512,9 @@  discard block
 block discarded – undo
491 512
 {
492 513
 	$bases = $checked = array();
493 514
 	$noms = sql_listdbs($server_db);
494
-	if (!$noms) return '';
515
+	if (!$noms) {
516
+	    return '';
517
+	}
495 518
 
496 519
 	foreach ($noms as $nom){
497 520
 		$id = spip_htmlspecialchars($nom);
@@ -514,7 +537,9 @@  discard block
 block discarded – undo
514 537
 		}
515 538
 	}
516 539
 
517
-	if (!$bases && !$checked) return false;
540
+	if (!$bases && !$checked) {
541
+	    return false;
542
+	}
518 543
 
519 544
 	if ($checked) {array_unshift($bases, $checked); $checked = true;}
520 545
 
Please login to merge, or discard this patch.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -72,16 +72,16 @@  discard block
 block discarded – undo
72 72
  *     Texte du fichier de connexion
73 73
  * 
74 74
 **/
75
-function install_connexion($adr, $port, $login, $pass, $base, $type, $pref, $ldap='')
75
+function install_connexion($adr, $port, $login, $pass, $base, $type, $pref, $ldap = '')
76 76
 {
77
-	$adr = addcslashes($adr,"'\\");
78
-	$port = addcslashes($port,"'\\");
79
-	$login = addcslashes($login,"'\\");
80
-	$pass = addcslashes($pass,"'\\");
81
-	$base = addcslashes($base,"'\\");
82
-	$type = addcslashes($type,"'\\");
83
-	$pref = addcslashes($pref,"'\\");
84
-	$ldap = addcslashes($ldap,"'\\");
77
+	$adr = addcslashes($adr, "'\\");
78
+	$port = addcslashes($port, "'\\");
79
+	$login = addcslashes($login, "'\\");
80
+	$pass = addcslashes($pass, "'\\");
81
+	$base = addcslashes($base, "'\\");
82
+	$type = addcslashes($type, "'\\");
83
+	$pref = addcslashes($pref, "'\\");
84
+	$ldap = addcslashes($ldap, "'\\");
85 85
 	return "\$GLOBALS['spip_connect_version'] = 0.7;\n"
86 86
 	. "spip_connect_db("
87 87
 	. "'$adr','$port','$login','$pass','$base'"
@@ -108,10 +108,10 @@  discard block
 block discarded – undo
108 108
 		return $regs;
109 109
 	} else {
110 110
 		$ar = '\s*\'([^\']*)\'';
111
-		$r = '\s*,' . $ar;
111
+		$r = '\s*,'.$ar;
112 112
 		$r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r)?)?)?#";
113 113
 		if (preg_match($r, $s, $regs)) {
114
-			$regs[2] = $regs[1] . (!$regs[2] ? '' : ":$port_db;");
114
+			$regs[2] = $regs[1].(!$regs[2] ? '' : ":$port_db;");
115 115
 			array_shift($regs);
116 116
 			array_shift($regs);
117 117
 			return $regs;
@@ -134,22 +134,22 @@  discard block
 block discarded – undo
134 134
  * @return array
135 135
  *     Liste des noms de connecteurs
136 136
 **/
137
-function bases_referencees($exclu='')
137
+function bases_referencees($exclu = '')
138 138
 {
139 139
 	$tables = array();
140
-	foreach(preg_files(_DIR_CONNECT, '.php$') as $f) {
140
+	foreach (preg_files(_DIR_CONNECT, '.php$') as $f) {
141 141
 		if ($f != $exclu AND analyse_fichier_connection($f))
142
-			$tables[]= basename($f, '.php');
142
+			$tables[] = basename($f, '.php');
143 143
 	}
144 144
 	return $tables;
145 145
 }
146 146
 
147 147
 
148
-function install_mode_appel($server_db, $tout=true)
148
+function install_mode_appel($server_db, $tout = true)
149 149
 {
150 150
 	return ($server_db != 'mysql') ? ''
151
-	: (($tout  ? test_rappel_nom_base_mysql($server_db) : '')
152
-		. test_sql_mode_mysql($server_db)	);
151
+	: (($tout ? test_rappel_nom_base_mysql($server_db) : '')
152
+		. test_sql_mode_mysql($server_db));
153 153
 }
154 154
 
155 155
 //
@@ -164,10 +164,10 @@  discard block
 block discarded – undo
164 164
 		$php = array($regs[1], $regs[2], $regs[3]);
165 165
 		$m = '5.1.0';
166 166
 		$min = explode('.', $m);
167
-		if ($php[0]<$min[0]
168
-		OR ($php[0]==$min[0] AND $php[1]<$min[1])
169
-		OR ($php[0]==$min[0] AND $php[1]==$min[1] AND $php[2]<$min[2]))
170
-			$err[] = _T('install_php_version', array('version' => $p,  'minimum' => $m));
167
+		if ($php[0] < $min[0]
168
+		OR ($php[0] == $min[0] AND $php[1] < $min[1])
169
+		OR ($php[0] == $min[0] AND $php[1] == $min[1] AND $php[2] < $min[2]))
170
+			$err[] = _T('install_php_version', array('version' => $p, 'minimum' => $m));
171 171
 	}
172 172
 
173 173
 	// Si on n'a pas la bonne version de PHP, c'est la fin
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	if ($err) {
198 198
 			echo "<div class='error'>"
199 199
 				."<h3>"._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>";
200
-			foreach($err as $e)
200
+			foreach ($err as $e)
201 201
 				echo "<li><strong>$e</strong></li>\n";
202 202
 
203 203
 		# a priori ici on pourrait die(), mais il faut laisser la possibilite
@@ -235,26 +235,26 @@  discard block
 block discarded – undo
235 235
 
236 236
 
237 237
 // http://doc.spip.org/@info_etape
238
-function info_etape($titre, $complement = ''){
239
-	return "<h2>".$titre."</h2>\n" .
240
-	($complement ? "".$complement."\n":'');
238
+function info_etape($titre, $complement = '') {
239
+	return "<h2>".$titre."</h2>\n".
240
+	($complement ? "".$complement."\n" : '');
241 241
 }
242 242
 
243 243
 // http://doc.spip.org/@bouton_suivant
244 244
 function bouton_suivant($code = '') {
245
-	if($code=='') $code = _T('bouton_suivant');
245
+	if ($code == '') $code = _T('bouton_suivant');
246 246
 	static $suivant = 0;
247
-	$id = 'suivant'.(($suivant>0)?strval($suivant):'');
248
-	$suivant +=1;
249
-	return "\n<p class='boutons suivant'><input id='".$id."' type='submit'\nvalue=\"" .
250
-		$code .
247
+	$id = 'suivant'.(($suivant > 0) ?strval($suivant) : '');
248
+	$suivant += 1;
249
+	return "\n<p class='boutons suivant'><input id='".$id."' type='submit'\nvalue=\"".
250
+		$code.
251 251
 		" >>\" /></p>\n";
252 252
 }
253 253
 
254 254
 // http://doc.spip.org/@info_progression_etape
255
-function info_progression_etape($en_cours,$phase,$dir, $erreur = false){
255
+function info_progression_etape($en_cours, $phase, $dir, $erreur = false) {
256 256
 	//$en_cours = _request('etape')?_request('etape'):"";
257
-	$liste = find_all_in_path($dir,$phase.'(([0-9])+|fin)[.]php$');
257
+	$liste = find_all_in_path($dir, $phase.'(([0-9])+|fin)[.]php$');
258 258
 	$debut = 1; $etat = "ok";
259 259
 	$last = count($liste);
260 260
 //	$texte_etat = array('ok'=>'OK','encours'=>_T('en_cours'),'todo'=>_T('todo'));
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 
275 275
 	$aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>";
276 276
 
277
-	foreach($liste as $etape=>$fichier){
277
+	foreach ($liste as $etape=>$fichier) {
278 278
 		if ($debut < $last) {
279 279
 			if ($debut == $en_cours && $erreur) $class = "on erreur";
280 280
 			else if ($debut == $en_cours) $class = "on";
@@ -282,10 +282,10 @@  discard block
 block discarded – undo
282 282
 			else $class = "valides";
283 283
 
284 284
 			$aff_etapes .= "<li class='$class'><div class='fond'>";
285
-			$aff_etapes .= ($debut == $en_cours)?"<strong>":'';
285
+			$aff_etapes .= ($debut == $en_cours) ? "<strong>" : '';
286 286
 			$aff_etapes .= "<em>"._T('etape')." </em><span class='numero_etape'>$debut</span><em>&nbsp;: </em>";
287 287
 			$aff_etapes .= $intitule_etat["$phase"][$debut];
288
-			$aff_etapes .= ($debut == $en_cours)?"</strong>":'';
288
+			$aff_etapes .= ($debut == $en_cours) ? "</strong>" : '';
289 289
 			$aff_etapes .= "</div></li>";
290 290
 		}
291 291
 		$debut++;
@@ -297,12 +297,12 @@  discard block
 block discarded – undo
297 297
 
298 298
 
299 299
 // http://doc.spip.org/@fieldset
300
-function fieldset($legend,  $champs = array(), $apres='', $avant='') {
301
-	return "<fieldset>\n" .
302
-	  $avant .
303
-	  ($legend ? "<legend>".$legend."</legend>\n" : '') .
304
-	  fieldset_champs($champs) .
305
-	  $apres .
300
+function fieldset($legend, $champs = array(), $apres = '', $avant = '') {
301
+	return "<fieldset>\n".
302
+	  $avant.
303
+	  ($legend ? "<legend>".$legend."</legend>\n" : '').
304
+	  fieldset_champs($champs).
305
+	  $apres.
306 306
 	  "</fieldset>\n";
307 307
 }
308 308
 
@@ -312,12 +312,12 @@  discard block
 block discarded – undo
312 312
 	foreach ($champs as $nom => $contenu) {
313 313
 		$type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text');
314 314
 		$class = isset($contenu['hidden']) ? '' : "class='formo' size='40' ";
315
-		if(isset($contenu['alternatives'])) {
316
-			$fieldset .= $contenu['label'] ."\n";
317
-			foreach($contenu['alternatives'] as $valeur => $label) {
318
-				$fieldset .= "<input type='radio' name='".$nom .
315
+		if (isset($contenu['alternatives'])) {
316
+			$fieldset .= $contenu['label']."\n";
317
+			foreach ($contenu['alternatives'] as $valeur => $label) {
318
+				$fieldset .= "<input type='radio' name='".$nom.
319 319
 				"' id='$nom-$valeur' value='$valeur'"
320
-				  .(($valeur==$contenu['valeur'])?"\nchecked='checked'":'')
320
+				  .(($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '')
321 321
 				  ."/>\n";
322 322
 				$fieldset .= "<label for='$nom-$valeur'>".$label."</label>\n";
323 323
 			}
@@ -325,9 +325,9 @@  discard block
 block discarded – undo
325 325
 		}
326 326
 		else {
327 327
 			$fieldset .= "<label for='".$nom."'>".$contenu['label']."</label>\n";
328
-			$fieldset .= "<input ".$class."type='".$type."' id='" . $nom . "' name='".$nom."'\nvalue='".$contenu['valeur']."'"
329
-							  .(preg_match(',^(pass|login),', $nom)?" autocomplete='off'":'')
330
-			          . ((isset($contenu['required']) AND $contenu['required'])?" required='required'":"")
328
+			$fieldset .= "<input ".$class."type='".$type."' id='".$nom."' name='".$nom."'\nvalue='".$contenu['valeur']."'"
329
+							  .(preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '')
330
+			          . ((isset($contenu['required']) AND $contenu['required']) ? " required='required'" : "")
331 331
 			          .	" />\n";
332 332
 		}
333 333
 	}
@@ -337,20 +337,20 @@  discard block
 block discarded – undo
337 337
 function install_select_serveur()
338 338
 {
339 339
 	$options = array();
340
-	$dir = _DIR_RESTREINT . 'req/';
340
+	$dir = _DIR_RESTREINT.'req/';
341 341
 	$d = @opendir($dir);
342 342
 	if (!$d) return array();
343 343
 	while ($f = readdir($d)) {
344 344
 		if ((preg_match('/^(.*)[.]php$/', $f, $s))
345
-		AND is_readable($f = $dir . $f)) {
345
+		AND is_readable($f = $dir.$f)) {
346 346
 			require_once($f);
347 347
 			$s = $s[1];
348
-			$v = 'spip_versions_' . $s;
348
+			$v = 'spip_versions_'.$s;
349 349
 			if (function_exists($v) AND $v()) {
350 350
 			  $titre = _T("install_select_type_$s");
351 351
 				// proposer sqlite3 par defaut si dispo
352
-				$selected = ($s=='sqlite3'?" selected='selected'":"");
353
-			  $options[$s] =  "<option value='$s'$selected>"
352
+				$selected = ($s == 'sqlite3' ? " selected='selected'" : "");
353
+			  $options[$s] = "<option value='$s'$selected>"
354 354
 			    . ($titre ? $titre : $s)
355 355
 			    ."</option>";
356 356
 			} else spip_log("$s: portage indisponible");
@@ -361,19 +361,19 @@  discard block
 block discarded – undo
361 361
 }
362 362
 
363 363
 // http://doc.spip.org/@install_connexion_form
364
-function install_connexion_form($db, $login, $pass, $predef, $hidden, $etape, $jquery=true)
364
+function install_connexion_form($db, $login, $pass, $predef, $hidden, $etape, $jquery = true)
365 365
 {
366 366
 	$server_db = (is_string($predef[0])) ? $predef[0] : '';
367 367
 
368 368
 	return generer_form_ecrire('install', (
369 369
 	  "\n<input type='hidden' name='etape' value='$etape' />"
370 370
 	. $hidden
371
-	. (_request('echec')?
371
+	. (_request('echec') ?
372 372
 			("<p><b>"._T('avis_connexion_echec_1').
373 373
 			"</b></p><p>"._T('avis_connexion_echec_2')."</p><p style='font-size: small;'>"._T('avis_connexion_echec_3')."</p>")
374 374
 			:"")
375 375
 
376
-	. ($jquery?http_script('',  'jquery.js'):'')
376
+	. ($jquery ?http_script('', 'jquery.js') : '')
377 377
 	. http_script('
378 378
 		$(document).ready(function() {
379 379
 			$("input[type=hidden][name=server_db]").each(function(){
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 	. ($server_db
399 399
 		? '<input type="hidden" name="server_db" value="'.$server_db.'" />'
400 400
 			. (($predef[0])
401
-			   ?('<h3>'._T('install_serveur_hebergeur').'</h3>')
401
+			   ? ('<h3>'._T('install_serveur_hebergeur').'</h3>')
402 402
 				:'')
403 403
 		: ('<fieldset><legend>'
404 404
 		   ._T('install_select_type_db')
@@ -406,14 +406,14 @@  discard block
 block discarded – undo
406 406
 			.'<label for="sql_serveur_db" class="p">'
407 407
 			. _T('install_types_db_connus')
408 408
 			// Passer l'avertissement SQLIte en  commentaire, on pourra facilement le supprimer par la suite sans changer les traductions.
409
-			. "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>'
409
+			. "<br /><small>("._T('install_types_db_connus_avertissement').')</small>'
410 410
 			.'</label>'
411 411
 		. "\n<div class='p center'><select name='server_db' id='sql_serveur_db' >\n"
412 412
 		.   join("\n", install_select_serveur())
413 413
 		. "\n</select></div></fieldset>")
414 414
 	)
415 415
 	. '<div id="install_adresse_base_hebergeur">'
416
-	. '<p>'. _T('texte_connexion_mysql').'</p>'
416
+	. '<p>'._T('texte_connexion_mysql').'</p>'
417 417
 	. ($predef[1]
418 418
 	? '<h3>'._T('install_adresse_base_hebergeur').'</h3>'
419 419
 	: fieldset(_T('entree_base_donnee_1'),
@@ -487,13 +487,13 @@  discard block
 block discarded – undo
487 487
 // presentation des bases existantes
488 488
 
489 489
 // http://doc.spip.org/@install_etape_liste_bases
490
-function install_etape_liste_bases($server_db, $login_db, $disabled=array())
490
+function install_etape_liste_bases($server_db, $login_db, $disabled = array())
491 491
 {
492 492
 	$bases = $checked = array();
493 493
 	$noms = sql_listdbs($server_db);
494 494
 	if (!$noms) return '';
495 495
 
496
-	foreach ($noms as $nom){
496
+	foreach ($noms as $nom) {
497 497
 		$id = spip_htmlspecialchars($nom);
498 498
 		$dis = in_array($nom, $disabled) ? " disabled='disabled'" : '';
499 499
 		$base = " name=\"choix_db\" value=\""
@@ -510,13 +510,13 @@  discard block
 block discarded – undo
510 510
 			($GLOBALS['table_prefix'] == $nom))) {
511 511
 			$checked = "<input$base checked='checked' />\n$label";
512 512
 		} else {
513
-			$bases[]= "<input$base />\n$label";
513
+			$bases[] = "<input$base />\n$label";
514 514
 		}
515 515
 	}
516 516
 
517 517
 	if (!$bases && !$checked) return false;
518 518
 
519
-	if ($checked) {array_unshift($bases, $checked); $checked = true;}
519
+	if ($checked) {array_unshift($bases, $checked); $checked = true; }
520 520
 
521 521
 	return array($checked, $bases);
522 522
 }
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
 function install_propager($hidden)
525 525
 {
526 526
 	$res = '';
527
-	foreach($hidden as $k) {
527
+	foreach ($hidden as $k) {
528 528
 		$v = spip_htmlentities(_request($k));
529 529
 		$res .= "<input type='hidden' name='$k' value='$v' />";
530 530
 	}
Please login to merge, or discard this patch.
ecrire/inc/invalideur.php 4 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -24,6 +24,9 @@  discard block
 block discarded – undo
24 24
 // Donne le nombre de fichiers dans un repertoire (plat, pour aller vite)
25 25
 // false si erreur
26 26
 // http://doc.spip.org/@nombre_de_fichiers_repertoire
27
+/**
28
+ * @param string $dir
29
+ */
27 30
 function nombre_de_fichiers_repertoire($dir,$nb_estim_taille = 20) {
28 31
 	$taille = 0; // mesurer la taille de N fichiers au hasard dans le repertoire
29 32
 	$nb = $nb_estim_taille;
@@ -249,6 +252,9 @@  discard block
 block discarded – undo
249 252
 
250 253
 // Calcul des pages : noter dans la base les liens d'invalidation
251 254
 // http://doc.spip.org/@maj_invalideurs
255
+/**
256
+ * @param string $fichier
257
+ */
252 258
 function maj_invalideurs ($fichier, &$page) { }
253 259
 
254 260
 // les invalideurs sont de la forme "objet/id_objet"
Please login to merge, or discard this patch.
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -25,36 +25,36 @@  discard block
 block discarded – undo
25 25
 // false si erreur
26 26
 // http://doc.spip.org/@nombre_de_fichiers_repertoire
27 27
 function nombre_de_fichiers_repertoire($dir,$nb_estim_taille = 20) {
28
-	$taille = 0; // mesurer la taille de N fichiers au hasard dans le repertoire
29
-	$nb = $nb_estim_taille;
30
-	if (!$h = @opendir($dir)) return false;
31
-	$total = 0;
32
-	while (($fichier = @readdir($h)) !== false)
33
-		if ($fichier[0]!='.' AND !is_dir("$dir/$fichier")){
34
-			$total++;
35
-			if ($nb AND rand(1,10)==1){
36
-				$taille += filesize("$dir/$fichier");
37
-				$nb--;
38
-			}
39
-		}
40
-	closedir($h);
41
-	return array($total,$taille?$taille/($nb_estim_taille-$nb):_TAILLE_MOYENNE_FICHIER_CACHE);
28
+    $taille = 0; // mesurer la taille de N fichiers au hasard dans le repertoire
29
+    $nb = $nb_estim_taille;
30
+    if (!$h = @opendir($dir)) return false;
31
+    $total = 0;
32
+    while (($fichier = @readdir($h)) !== false)
33
+        if ($fichier[0]!='.' AND !is_dir("$dir/$fichier")){
34
+            $total++;
35
+            if ($nb AND rand(1,10)==1){
36
+                $taille += filesize("$dir/$fichier");
37
+                $nb--;
38
+            }
39
+        }
40
+    closedir($h);
41
+    return array($total,$taille?$taille/($nb_estim_taille-$nb):_TAILLE_MOYENNE_FICHIER_CACHE);
42 42
 }
43 43
 
44 44
 // Indique la taille du repertoire cache ; pour de gros volumes,
45 45
 // impossible d'ouvrir chaque fichier, on y va donc a l'estime
46 46
 // http://doc.spip.org/@taille_du_cache
47 47
 function taille_du_cache() {
48
-	$total = 0;
49
-	$taille = 0;
50
-	for ($i=0;$i<16;$i++) {
51
-		$l = dechex($i);
52
-		$dir = sous_repertoire(_DIR_CACHE, $l);
53
-		list($n,$s) = nombre_de_fichiers_repertoire($dir);
54
-		$total += $n;
55
-		$taille += $s;
56
-	}
57
-	return $total * $taille / 16;
48
+    $total = 0;
49
+    $taille = 0;
50
+    for ($i=0;$i<16;$i++) {
51
+        $l = dechex($i);
52
+        $dir = sous_repertoire(_DIR_CACHE, $l);
53
+        list($n,$s) = nombre_de_fichiers_repertoire($dir);
54
+        $total += $n;
55
+        $taille += $s;
56
+    }
57
+    return $total * $taille / 16;
58 58
 }
59 59
 
60 60
 // Invalider les caches lies a telle condition
@@ -63,26 +63,26 @@  discard block
 block discarded – undo
63 63
 // ici on se contente de noter la date de mise a jour dans les metas
64 64
 // http://doc.spip.org/@suivre_invalideur
65 65
 function suivre_invalideur($cond, $modif=true) {
66
-	if (!$modif)
67
-		return;
68
-
69
-	// determiner l'objet modifie : forum, article, etc
70
-	if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r))
71
-		$objet = objet_type($r[1]);
72
-
73
-	// stocker la date_modif_$objet (ne sert a rien pour le moment)
74
-	if (isset($objet))
75
-		ecrire_meta('derniere_modif_'.$objet, time());
76
-
77
-	// si $derniere_modif_invalide est un array('article', 'rubrique')
78
-	// n'affecter la meta que si un de ces objets est modifie
79
-	if (is_array($GLOBALS['derniere_modif_invalide'])) {
80
-		if (in_array($objet, $GLOBALS['derniere_modif_invalide']))
81
-			ecrire_meta('derniere_modif', time());
82
-	}
83
-	// sinon, cas standard, toujours affecter la meta
84
-	else
85
-		ecrire_meta('derniere_modif', time());
66
+    if (!$modif)
67
+        return;
68
+
69
+    // determiner l'objet modifie : forum, article, etc
70
+    if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r))
71
+        $objet = objet_type($r[1]);
72
+
73
+    // stocker la date_modif_$objet (ne sert a rien pour le moment)
74
+    if (isset($objet))
75
+        ecrire_meta('derniere_modif_'.$objet, time());
76
+
77
+    // si $derniere_modif_invalide est un array('article', 'rubrique')
78
+    // n'affecter la meta que si un de ces objets est modifie
79
+    if (is_array($GLOBALS['derniere_modif_invalide'])) {
80
+        if (in_array($objet, $GLOBALS['derniere_modif_invalide']))
81
+            ecrire_meta('derniere_modif', time());
82
+    }
83
+    // sinon, cas standard, toujours affecter la meta
84
+    else
85
+        ecrire_meta('derniere_modif', time());
86 86
 
87 87
 }
88 88
 
@@ -109,38 +109,38 @@  discard block
 block discarded – undo
109 109
  *     Nombre de fichiers supprimés
110 110
 **/
111 111
 function purger_repertoire($dir, $options=array()) {
112
-	$handle = @opendir($dir);
113
-	if (!$handle) return;
114
-
115
-	$total = 0;
116
-
117
-	while (($fichier = @readdir($handle)) !== false) {
118
-		// Eviter ".", "..", ".htaccess", ".svn" etc.
119
-		if ($fichier[0] == '.') continue;
120
-		$chemin = "$dir/$fichier";
121
-		if (is_file($chemin)) {
122
-			if (  (!isset($options['atime']) OR (@fileatime($chemin) < $options['atime']))
123
-				AND (!isset($options['mtime']) OR (@filemtime($chemin) < $options['mtime']))
124
-			  ) {
125
-				supprimer_fichier($chemin);
126
-				$total ++;
127
-			}
128
-		}
129
-		else if (is_dir($chemin)){
130
-			$opts = $options;
131
-			if (isset($otpions['limit']))
132
-				$otps['limit'] = $otpions['limit'] - $total;
133
-			$total += purger_repertoire($chemin, $opts);
134
-			if (isset($options['subdir']) && $options['subdir'])
135
-				spip_unlink($chemin);
136
-		}
137
-
138
-		if (isset($options['limit']) AND $total>=$options['limit'])
139
-			break;
140
-	}
141
-	closedir($handle);
142
-
143
-	return $total;
112
+    $handle = @opendir($dir);
113
+    if (!$handle) return;
114
+
115
+    $total = 0;
116
+
117
+    while (($fichier = @readdir($handle)) !== false) {
118
+        // Eviter ".", "..", ".htaccess", ".svn" etc.
119
+        if ($fichier[0] == '.') continue;
120
+        $chemin = "$dir/$fichier";
121
+        if (is_file($chemin)) {
122
+            if (  (!isset($options['atime']) OR (@fileatime($chemin) < $options['atime']))
123
+                AND (!isset($options['mtime']) OR (@filemtime($chemin) < $options['mtime']))
124
+                ) {
125
+                supprimer_fichier($chemin);
126
+                $total ++;
127
+            }
128
+        }
129
+        else if (is_dir($chemin)){
130
+            $opts = $options;
131
+            if (isset($otpions['limit']))
132
+                $otps['limit'] = $otpions['limit'] - $total;
133
+            $total += purger_repertoire($chemin, $opts);
134
+            if (isset($options['subdir']) && $options['subdir'])
135
+                spip_unlink($chemin);
136
+        }
137
+
138
+        if (isset($options['limit']) AND $total>=$options['limit'])
139
+            break;
140
+    }
141
+    closedir($handle);
142
+
143
+    return $total;
144 144
 }
145 145
 
146 146
 
@@ -152,47 +152,47 @@  discard block
 block discarded – undo
152 152
 //
153 153
 // http://doc.spip.org/@appliquer_quota_cache
154 154
 function appliquer_quota_cache() {
155
-	global $quota_cache;
156
-	$encore = false;
157
-
158
-	$tour_quota_cache = intval(1+$GLOBALS['meta']['tour_quota_cache'])%16;
159
-	ecrire_meta('tour_quota_cache', $tour_quota_cache);
160
-
161
-	$l = dechex($tour_quota_cache);
162
-	$dir = sous_repertoire(_DIR_CACHE, $l);
163
-	list($nombre,$taille) = nombre_de_fichiers_repertoire($dir);
164
-	$total_cache = $taille * $nombre;
165
-	spip_log("Taille du CACHE estimee ($l): "
166
-		.(intval(16*$total_cache/(1024*1024/10))/10)." Mo","invalideur");
167
-
168
-	// Nombre max de fichiers a supprimer
169
-	if ($quota_cache > 0
170
-	AND $taille > 0) {
171
-		$trop = $total_cache - ($quota_cache/16)*1024*1024;
172
-		$trop = 3 * intval($trop / $taille);
173
-		if ($trop > 0) {
174
-			$n = purger_repertoire($dir,
175
-				array(
176
-					'atime' => time() - _AGE_CACHE_ATIME,
177
-					'limit' => $trop,
178
-					'subdir' => true // supprimer les vieux sous repertoire de session (avant [15851])
179
-				)
180
-			);
181
-			spip_log("$dir : $n/$trop caches supprimes [taille moyenne $taille]","invalideur");
182
-			$total_cache = intval(max(0,(16*$total_cache) - $n*$taille)/(1024*1024)*10)/10;
183
-			spip_log("cache restant estime : $total_cache Mo, ratio ".$total_cache/$quota_cache,"invalideur");
184
-
185
-			// redemander la main pour eviter que le cache ne gonfle trop
186
-			// mais pas si on ne peut pas purger car les fichiers sont trops recents
187
-			if (
188
-			  $total_cache/$quota_cache>1.5
189
-			  AND $n*50>$trop) {
190
-				$encore = true;
191
-				spip_log("Il faut encore purger","invalideur");
192
-			}
193
-		}
194
-	}
195
-	return $encore;
155
+    global $quota_cache;
156
+    $encore = false;
157
+
158
+    $tour_quota_cache = intval(1+$GLOBALS['meta']['tour_quota_cache'])%16;
159
+    ecrire_meta('tour_quota_cache', $tour_quota_cache);
160
+
161
+    $l = dechex($tour_quota_cache);
162
+    $dir = sous_repertoire(_DIR_CACHE, $l);
163
+    list($nombre,$taille) = nombre_de_fichiers_repertoire($dir);
164
+    $total_cache = $taille * $nombre;
165
+    spip_log("Taille du CACHE estimee ($l): "
166
+        .(intval(16*$total_cache/(1024*1024/10))/10)." Mo","invalideur");
167
+
168
+    // Nombre max de fichiers a supprimer
169
+    if ($quota_cache > 0
170
+    AND $taille > 0) {
171
+        $trop = $total_cache - ($quota_cache/16)*1024*1024;
172
+        $trop = 3 * intval($trop / $taille);
173
+        if ($trop > 0) {
174
+            $n = purger_repertoire($dir,
175
+                array(
176
+                    'atime' => time() - _AGE_CACHE_ATIME,
177
+                    'limit' => $trop,
178
+                    'subdir' => true // supprimer les vieux sous repertoire de session (avant [15851])
179
+                )
180
+            );
181
+            spip_log("$dir : $n/$trop caches supprimes [taille moyenne $taille]","invalideur");
182
+            $total_cache = intval(max(0,(16*$total_cache) - $n*$taille)/(1024*1024)*10)/10;
183
+            spip_log("cache restant estime : $total_cache Mo, ratio ".$total_cache/$quota_cache,"invalideur");
184
+
185
+            // redemander la main pour eviter que le cache ne gonfle trop
186
+            // mais pas si on ne peut pas purger car les fichiers sont trops recents
187
+            if (
188
+                $total_cache/$quota_cache>1.5
189
+              AND $n*50>$trop) {
190
+                $encore = true;
191
+                spip_log("Il faut encore purger","invalideur");
192
+            }
193
+        }
194
+    }
195
+    return $encore;
196 196
 }
197 197
 
198 198
 
@@ -204,13 +204,13 @@  discard block
 block discarded – undo
204 204
 // http://doc.spip.org/@retire_cache
205 205
 function retire_cache($cache) {
206 206
 
207
-	if (preg_match(
208
-	"|^([0-9a-f]/)?([0-9]+/)?[^.][\-_\%0-9a-z]+--[0-9a-f]+(\.gz)?$|i",
209
-	$cache)) {
210
-		// supprimer le fichier (de facon propre)
211
-		supprimer_fichier(_DIR_CACHE . $cache);
212
-	} else
213
-		spip_log("Nom de fichier cache incorrect : $cache");
207
+    if (preg_match(
208
+    "|^([0-9a-f]/)?([0-9]+/)?[^.][\-_\%0-9a-z]+--[0-9a-f]+(\.gz)?$|i",
209
+    $cache)) {
210
+        // supprimer le fichier (de facon propre)
211
+        supprimer_fichier(_DIR_CACHE . $cache);
212
+    } else
213
+        spip_log("Nom de fichier cache incorrect : $cache");
214 214
 }
215 215
 
216 216
 #######################################################################
@@ -225,8 +225,8 @@  discard block
 block discarded – undo
225 225
 // la meta est toujours false ; mais evitons un bug si elle est appellee
226 226
 // http://doc.spip.org/@retire_caches
227 227
 function retire_caches($chemin = '') {
228
-	if (isset($GLOBALS['meta']['invalider_caches']))
229
-		effacer_meta('invalider_caches'); # concurrence
228
+    if (isset($GLOBALS['meta']['invalider_caches']))
229
+        effacer_meta('invalider_caches'); # concurrence
230 230
 }
231 231
 
232 232
 
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -24,21 +24,21 @@  discard block
 block discarded – undo
24 24
 // Donne le nombre de fichiers dans un repertoire (plat, pour aller vite)
25 25
 // false si erreur
26 26
 // http://doc.spip.org/@nombre_de_fichiers_repertoire
27
-function nombre_de_fichiers_repertoire($dir,$nb_estim_taille = 20) {
27
+function nombre_de_fichiers_repertoire($dir, $nb_estim_taille = 20) {
28 28
 	$taille = 0; // mesurer la taille de N fichiers au hasard dans le repertoire
29 29
 	$nb = $nb_estim_taille;
30 30
 	if (!$h = @opendir($dir)) return false;
31 31
 	$total = 0;
32 32
 	while (($fichier = @readdir($h)) !== false)
33
-		if ($fichier[0]!='.' AND !is_dir("$dir/$fichier")){
33
+		if ($fichier[0] != '.' AND !is_dir("$dir/$fichier")) {
34 34
 			$total++;
35
-			if ($nb AND rand(1,10)==1){
35
+			if ($nb AND rand(1, 10) == 1) {
36 36
 				$taille += filesize("$dir/$fichier");
37 37
 				$nb--;
38 38
 			}
39 39
 		}
40 40
 	closedir($h);
41
-	return array($total,$taille?$taille/($nb_estim_taille-$nb):_TAILLE_MOYENNE_FICHIER_CACHE);
41
+	return array($total, $taille ? $taille / ($nb_estim_taille - $nb) : _TAILLE_MOYENNE_FICHIER_CACHE);
42 42
 }
43 43
 
44 44
 // Indique la taille du repertoire cache ; pour de gros volumes,
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
 function taille_du_cache() {
48 48
 	$total = 0;
49 49
 	$taille = 0;
50
-	for ($i=0;$i<16;$i++) {
50
+	for ($i = 0; $i < 16; $i++) {
51 51
 		$l = dechex($i);
52 52
 		$dir = sous_repertoire(_DIR_CACHE, $l);
53
-		list($n,$s) = nombre_de_fichiers_repertoire($dir);
53
+		list($n, $s) = nombre_de_fichiers_repertoire($dir);
54 54
 		$total += $n;
55 55
 		$taille += $s;
56 56
 	}
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 // la condition est generalement "id='objet/id_objet'"
63 63
 // ici on se contente de noter la date de mise a jour dans les metas
64 64
 // http://doc.spip.org/@suivre_invalideur
65
-function suivre_invalideur($cond, $modif=true) {
65
+function suivre_invalideur($cond, $modif = true) {
66 66
 	if (!$modif)
67 67
 		return;
68 68
 
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
  * @return int
109 109
  *     Nombre de fichiers supprimés
110 110
 **/
111
-function purger_repertoire($dir, $options=array()) {
111
+function purger_repertoire($dir, $options = array()) {
112 112
 	$handle = @opendir($dir);
113 113
 	if (!$handle) return;
114 114
 
@@ -119,14 +119,14 @@  discard block
 block discarded – undo
119 119
 		if ($fichier[0] == '.') continue;
120 120
 		$chemin = "$dir/$fichier";
121 121
 		if (is_file($chemin)) {
122
-			if (  (!isset($options['atime']) OR (@fileatime($chemin) < $options['atime']))
122
+			if ((!isset($options['atime']) OR (@fileatime($chemin) < $options['atime']))
123 123
 				AND (!isset($options['mtime']) OR (@filemtime($chemin) < $options['mtime']))
124 124
 			  ) {
125 125
 				supprimer_fichier($chemin);
126
-				$total ++;
126
+				$total++;
127 127
 			}
128 128
 		}
129
-		else if (is_dir($chemin)){
129
+		else if (is_dir($chemin)) {
130 130
 			$opts = $options;
131 131
 			if (isset($otpions['limit']))
132 132
 				$otps['limit'] = $otpions['limit'] - $total;
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 				spip_unlink($chemin);
136 136
 		}
137 137
 
138
-		if (isset($options['limit']) AND $total>=$options['limit'])
138
+		if (isset($options['limit']) AND $total >= $options['limit'])
139 139
 			break;
140 140
 	}
141 141
 	closedir($handle);
@@ -155,20 +155,20 @@  discard block
 block discarded – undo
155 155
 	global $quota_cache;
156 156
 	$encore = false;
157 157
 
158
-	$tour_quota_cache = intval(1+$GLOBALS['meta']['tour_quota_cache'])%16;
158
+	$tour_quota_cache = intval(1 + $GLOBALS['meta']['tour_quota_cache']) % 16;
159 159
 	ecrire_meta('tour_quota_cache', $tour_quota_cache);
160 160
 
161 161
 	$l = dechex($tour_quota_cache);
162 162
 	$dir = sous_repertoire(_DIR_CACHE, $l);
163
-	list($nombre,$taille) = nombre_de_fichiers_repertoire($dir);
163
+	list($nombre, $taille) = nombre_de_fichiers_repertoire($dir);
164 164
 	$total_cache = $taille * $nombre;
165 165
 	spip_log("Taille du CACHE estimee ($l): "
166
-		.(intval(16*$total_cache/(1024*1024/10))/10)." Mo","invalideur");
166
+		.(intval(16 * $total_cache / (1024 * 1024 / 10)) / 10)." Mo", "invalideur");
167 167
 
168 168
 	// Nombre max de fichiers a supprimer
169 169
 	if ($quota_cache > 0
170 170
 	AND $taille > 0) {
171
-		$trop = $total_cache - ($quota_cache/16)*1024*1024;
171
+		$trop = $total_cache - ($quota_cache / 16) * 1024 * 1024;
172 172
 		$trop = 3 * intval($trop / $taille);
173 173
 		if ($trop > 0) {
174 174
 			$n = purger_repertoire($dir,
@@ -178,17 +178,17 @@  discard block
 block discarded – undo
178 178
 					'subdir' => true // supprimer les vieux sous repertoire de session (avant [15851])
179 179
 				)
180 180
 			);
181
-			spip_log("$dir : $n/$trop caches supprimes [taille moyenne $taille]","invalideur");
182
-			$total_cache = intval(max(0,(16*$total_cache) - $n*$taille)/(1024*1024)*10)/10;
183
-			spip_log("cache restant estime : $total_cache Mo, ratio ".$total_cache/$quota_cache,"invalideur");
181
+			spip_log("$dir : $n/$trop caches supprimes [taille moyenne $taille]", "invalideur");
182
+			$total_cache = intval(max(0, (16 * $total_cache) - $n * $taille) / (1024 * 1024) * 10) / 10;
183
+			spip_log("cache restant estime : $total_cache Mo, ratio ".$total_cache / $quota_cache, "invalideur");
184 184
 
185 185
 			// redemander la main pour eviter que le cache ne gonfle trop
186 186
 			// mais pas si on ne peut pas purger car les fichiers sont trops recents
187 187
 			if (
188
-			  $total_cache/$quota_cache>1.5
189
-			  AND $n*50>$trop) {
188
+			  $total_cache / $quota_cache > 1.5
189
+			  AND $n * 50 > $trop) {
190 190
 				$encore = true;
191
-				spip_log("Il faut encore purger","invalideur");
191
+				spip_log("Il faut encore purger", "invalideur");
192 192
 			}
193 193
 		}
194 194
 	}
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 	"|^([0-9a-f]/)?([0-9]+/)?[^.][\-_\%0-9a-z]+--[0-9a-f]+(\.gz)?$|i",
209 209
 	$cache)) {
210 210
 		// supprimer le fichier (de facon propre)
211
-		supprimer_fichier(_DIR_CACHE . $cache);
211
+		supprimer_fichier(_DIR_CACHE.$cache);
212 212
 	} else
213 213
 		spip_log("Nom de fichier cache incorrect : $cache");
214 214
 }
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 
250 250
 // Calcul des pages : noter dans la base les liens d'invalidation
251 251
 // http://doc.spip.org/@maj_invalideurs
252
-function maj_invalideurs ($fichier, &$page) { }
252
+function maj_invalideurs($fichier, &$page) { }
253 253
 
254 254
 // les invalideurs sont de la forme "objet/id_objet"
255 255
 // http://doc.spip.org/@insere_invalideur
Please login to merge, or discard this patch.
Braces   +48 added lines, -29 removed lines patch added patch discarded remove patch
@@ -11,7 +11,9 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 
14
-if (!defined('_ECRIRE_INC_VERSION')) return;
14
+if (!defined('_ECRIRE_INC_VERSION')) {
15
+    return;
16
+}
15 17
 
16 18
 include_spip('base/serial');
17 19
 
@@ -27,11 +29,14 @@  discard block
 block discarded – undo
27 29
 function nombre_de_fichiers_repertoire($dir,$nb_estim_taille = 20) {
28 30
 	$taille = 0; // mesurer la taille de N fichiers au hasard dans le repertoire
29 31
 	$nb = $nb_estim_taille;
30
-	if (!$h = @opendir($dir)) return false;
32
+	if (!$h = @opendir($dir)) {
33
+	    return false;
34
+	}
31 35
 	$total = 0;
32
-	while (($fichier = @readdir($h)) !== false)
33
-		if ($fichier[0]!='.' AND !is_dir("$dir/$fichier")){
36
+	while (($fichier = @readdir($h)) !== false) {
37
+			if ($fichier[0]!='.' AND !is_dir("$dir/$fichier")){
34 38
 			$total++;
39
+	}
35 40
 			if ($nb AND rand(1,10)==1){
36 41
 				$taille += filesize("$dir/$fichier");
37 42
 				$nb--;
@@ -63,26 +68,31 @@  discard block
 block discarded – undo
63 68
 // ici on se contente de noter la date de mise a jour dans les metas
64 69
 // http://doc.spip.org/@suivre_invalideur
65 70
 function suivre_invalideur($cond, $modif=true) {
66
-	if (!$modif)
67
-		return;
71
+	if (!$modif) {
72
+			return;
73
+	}
68 74
 
69 75
 	// determiner l'objet modifie : forum, article, etc
70
-	if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r))
71
-		$objet = objet_type($r[1]);
76
+	if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) {
77
+			$objet = objet_type($r[1]);
78
+	}
72 79
 
73 80
 	// stocker la date_modif_$objet (ne sert a rien pour le moment)
74
-	if (isset($objet))
75
-		ecrire_meta('derniere_modif_'.$objet, time());
81
+	if (isset($objet)) {
82
+			ecrire_meta('derniere_modif_'.$objet, time());
83
+	}
76 84
 
77 85
 	// si $derniere_modif_invalide est un array('article', 'rubrique')
78 86
 	// n'affecter la meta que si un de ces objets est modifie
79 87
 	if (is_array($GLOBALS['derniere_modif_invalide'])) {
80
-		if (in_array($objet, $GLOBALS['derniere_modif_invalide']))
81
-			ecrire_meta('derniere_modif', time());
88
+		if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) {
89
+					ecrire_meta('derniere_modif', time());
90
+		}
82 91
 	}
83 92
 	// sinon, cas standard, toujours affecter la meta
84
-	else
85
-		ecrire_meta('derniere_modif', time());
93
+	else {
94
+			ecrire_meta('derniere_modif', time());
95
+	}
86 96
 
87 97
 }
88 98
 
@@ -110,13 +120,17 @@  discard block
 block discarded – undo
110 120
 **/
111 121
 function purger_repertoire($dir, $options=array()) {
112 122
 	$handle = @opendir($dir);
113
-	if (!$handle) return;
123
+	if (!$handle) {
124
+	    return;
125
+	}
114 126
 
115 127
 	$total = 0;
116 128
 
117 129
 	while (($fichier = @readdir($handle)) !== false) {
118 130
 		// Eviter ".", "..", ".htaccess", ".svn" etc.
119
-		if ($fichier[0] == '.') continue;
131
+		if ($fichier[0] == '.') {
132
+		    continue;
133
+		}
120 134
 		$chemin = "$dir/$fichier";
121 135
 		if (is_file($chemin)) {
122 136
 			if (  (!isset($options['atime']) OR (@fileatime($chemin) < $options['atime']))
@@ -125,18 +139,20 @@  discard block
 block discarded – undo
125 139
 				supprimer_fichier($chemin);
126 140
 				$total ++;
127 141
 			}
128
-		}
129
-		else if (is_dir($chemin)){
142
+		} else if (is_dir($chemin)){
130 143
 			$opts = $options;
131
-			if (isset($otpions['limit']))
132
-				$otps['limit'] = $otpions['limit'] - $total;
144
+			if (isset($otpions['limit'])) {
145
+							$otps['limit'] = $otpions['limit'] - $total;
146
+			}
133 147
 			$total += purger_repertoire($chemin, $opts);
134
-			if (isset($options['subdir']) && $options['subdir'])
135
-				spip_unlink($chemin);
148
+			if (isset($options['subdir']) && $options['subdir']) {
149
+							spip_unlink($chemin);
150
+			}
136 151
 		}
137 152
 
138
-		if (isset($options['limit']) AND $total>=$options['limit'])
139
-			break;
153
+		if (isset($options['limit']) AND $total>=$options['limit']) {
154
+					break;
155
+		}
140 156
 	}
141 157
 	closedir($handle);
142 158
 
@@ -209,9 +225,10 @@  discard block
 block discarded – undo
209 225
 	$cache)) {
210 226
 		// supprimer le fichier (de facon propre)
211 227
 		supprimer_fichier(_DIR_CACHE . $cache);
212
-	} else
213
-		spip_log("Nom de fichier cache incorrect : $cache");
214
-}
228
+	} else {
229
+			spip_log("Nom de fichier cache incorrect : $cache");
230
+	}
231
+	}
215 232
 
216 233
 #######################################################################
217 234
 ##
@@ -225,8 +242,10 @@  discard block
 block discarded – undo
225 242
 // la meta est toujours false ; mais evitons un bug si elle est appellee
226 243
 // http://doc.spip.org/@retire_caches
227 244
 function retire_caches($chemin = '') {
228
-	if (isset($GLOBALS['meta']['invalider_caches']))
229
-		effacer_meta('invalider_caches'); # concurrence
245
+	if (isset($GLOBALS['meta']['invalider_caches'])) {
246
+			effacer_meta('invalider_caches');
247
+	}
248
+	# concurrence
230 249
 }
231 250
 
232 251
 
Please login to merge, or discard this patch.
ecrire/inc/lien.php 4 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -45,6 +45,9 @@  discard block
 block discarded – undo
45 45
 // Meme analyse mais pour eliminer les liens
46 46
 // et ne laisser que leur titre, a expliciter si ce n'est fait
47 47
 // http://doc.spip.org/@nettoyer_raccourcis_typo
48
+/**
49
+ * @param string|null $texte
50
+ */
48 51
 function nettoyer_raccourcis_typo($texte, $connect='')
49 52
 {
50 53
 
@@ -199,6 +202,9 @@  discard block
 block discarded – undo
199 202
 }
200 203
 
201 204
 // Retourne le champ textuel associe a une cle primaire, et sa langue
205
+/**
206
+ * @param string $connect
207
+ */
202 208
 function traiter_raccourci_titre($id, $type, $connect=NULL)
203 209
 {
204 210
 	$trouver_table = charger_fonction('trouver_table', 'base');
Please login to merge, or discard this patch.
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 function inc_lien_dist($lien, $texte='', $class='', $title='', $hlang='', $rel='', $connect='', $env=array()) {
24 24
 
25
-	return $lien;
25
+    return $lien;
26 26
 }
27 27
 
28 28
 // Regexp des raccourcis, aussi utilisee pour la fusion de sauvegarde Spip
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
 // http://doc.spip.org/@expanser_liens
35 35
 function expanser_liens($t, $connect='', $env=array()){
36 36
 
37
-	$t = pipeline('pre_liens', $t);
37
+    $t = pipeline('pre_liens', $t);
38 38
 
39
-	// on passe a traiter_modeles la liste des liens reperes pour lui permettre
40
-	// de remettre le texte d'origine dans les parametres du modele
41
-	$t = traiter_modeles($t, false, false, $connect);
42
-	return $t;
39
+    // on passe a traiter_modeles la liste des liens reperes pour lui permettre
40
+    // de remettre le texte d'origine dans les parametres du modele
41
+    $t = traiter_modeles($t, false, false, $connect);
42
+    return $t;
43 43
 }
44 44
 
45 45
 // Meme analyse mais pour eliminer les liens
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 {
50 50
 
51 51
 
52
-	return $texte;
52
+    return $texte;
53 53
 }
54 54
 
55 55
 
@@ -58,9 +58,9 @@  discard block
 block discarded – undo
58 58
 // la langue et la bulle eventuelles
59 59
 // http://doc.spip.org/@traiter_raccourci_lien_atts
60 60
 function traiter_raccourci_lien_atts($texte) {
61
-	$bulle='';
62
-	$hlang='';
63
-	return array(trim($texte), $bulle, $hlang);
61
+    $bulle='';
62
+    $hlang='';
63
+    return array(trim($texte), $bulle, $hlang);
64 64
 }
65 65
 
66 66
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
  * @return string
80 80
  */
81 81
 function virtuel_redirige($virtuel, $url=false){
82
-	return $virtuel;
82
+    return $virtuel;
83 83
 }
84 84
 
85 85
 
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
 
95 95
 // http://doc.spip.org/@calculer_url
96 96
 function calculer_url ($ref, $texte='', $pour='url', $connect='', $echappe_typo = true) {
97
-	$r = traiter_lien_implicite($ref, $texte, $pour, $connect, $echappe_typo);
98
-	return $r ? $r : traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo);
97
+    $r = traiter_lien_implicite($ref, $texte, $pour, $connect, $echappe_typo);
98
+    return $r ? $r : traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo);
99 99
 }
100 100
 
101 101
 define('_EXTRAIRE_LIEN', ',^\s*(?:' . _PROTOCOLES_STD . '):?/?/?\s*$,iS');
@@ -103,78 +103,78 @@  discard block
 block discarded – undo
103 103
 // http://doc.spip.org/@traiter_lien_explicite
104 104
 function traiter_lien_explicite ($ref, $texte='', $pour='url', $connect='', $echappe_typo = true)
105 105
 {
106
-	if (preg_match(_EXTRAIRE_LIEN, $ref))
107
-		return ($pour != 'tout') ? '' : array('','','','');
108
-
109
-	$lien = entites_html(trim($ref));
110
-
111
-	// Liens explicites
112
-	if (!$texte) {
113
-		$texte = str_replace('"', '', $lien);
114
-		// evite l'affichage de trops longues urls.
115
-		$lien_court = charger_fonction('lien_court', 'inc');
116
-		$texte = $lien_court($texte);
117
-		if ($echappe_typo){
118
-			$texte = "<html>".quote_amp($texte)."</html>";
119
-		}
120
-	}
121
-
122
-	// petites corrections d'URL
123
-	if (preg_match('/^www\.[^@]+$/S',$lien))
124
-		$lien = "http://".$lien;
125
-	else if (strpos($lien, "@") && email_valide($lien)) {
126
-		if (!$texte) $texte = $lien;
127
-		$lien = "mailto:".$lien;
128
-	}
106
+    if (preg_match(_EXTRAIRE_LIEN, $ref))
107
+        return ($pour != 'tout') ? '' : array('','','','');
108
+
109
+    $lien = entites_html(trim($ref));
110
+
111
+    // Liens explicites
112
+    if (!$texte) {
113
+        $texte = str_replace('"', '', $lien);
114
+        // evite l'affichage de trops longues urls.
115
+        $lien_court = charger_fonction('lien_court', 'inc');
116
+        $texte = $lien_court($texte);
117
+        if ($echappe_typo){
118
+            $texte = "<html>".quote_amp($texte)."</html>";
119
+        }
120
+    }
121
+
122
+    // petites corrections d'URL
123
+    if (preg_match('/^www\.[^@]+$/S',$lien))
124
+        $lien = "http://".$lien;
125
+    else if (strpos($lien, "@") && email_valide($lien)) {
126
+        if (!$texte) $texte = $lien;
127
+        $lien = "mailto:".$lien;
128
+    }
129 129
 	
130
-	if ($pour == 'url') return $lien;
130
+    if ($pour == 'url') return $lien;
131 131
 
132
-	if ($pour == 'titre') return $texte;
132
+    if ($pour == 'titre') return $texte;
133 133
 
134
-	return array('url' => $lien, 'titre' => $texte);
134
+    return array('url' => $lien, 'titre' => $texte);
135 135
 }
136 136
 
137 137
 function liens_implicite_glose_dist($texte,$id,$type,$args,$ancre,$connect=''){
138
-	if (function_exists($f = 'glossaire_' . $ancre))
139
-		$url = $f($texte, $id);
140
-	else
141
-		$url = glossaire_std($texte);
142
-	return $url;
138
+    if (function_exists($f = 'glossaire_' . $ancre))
139
+        $url = $f($texte, $id);
140
+    else
141
+        $url = glossaire_std($texte);
142
+    return $url;
143 143
 }
144 144
 
145 145
 // http://doc.spip.org/@traiter_lien_implicite
146 146
 function traiter_lien_implicite ($ref, $texte='', $pour='url', $connect='')
147 147
 {
148
-	if (!($match = typer_raccourci($ref))) return false;
149
-	@list($type,,$id,,$args,,$ancre) = $match;
148
+    if (!($match = typer_raccourci($ref))) return false;
149
+    @list($type,,$id,,$args,,$ancre) = $match;
150 150
 # attention dans le cas des sites le lien doit pointer non pas sur
151 151
 # la page locale du site, mais directement sur le site lui-meme
152
-	if ($f = charger_fonction("implicite_$type","liens",true))
153
-		$url = $f($texte,$id,$type,$args,$ancre,$connect);
154
-	if (!$url)
155
-		$url = generer_url_entite($id,$type,$args,$ancre,$connect ? $connect : NULL);
156
-	if (!$url) return false;
157
-	if (is_array($url)) {
158
-		@list($type,$id) = $url;
159
-		$url = generer_url_entite($id,$type,$args,$ancre,$connect ? $connect : NULL);
160
-	}
161
-	if ($pour === 'url') return $url;
162
-	$r = traiter_raccourci_titre($id, $type, $connect);
163
-	if ($r) $r['class'] =  ($type == 'site')?'spip_out':'spip_in';
164
-	if ($texte = trim($texte)) $r['titre'] = $texte;
165
-	if (!@$r['titre']) $r['titre'] =  _T($type) . " $id";
166
-	if ($pour=='titre') return $r['titre'];
167
-	$r['url'] = $url;
168
-
169
-	// dans le cas d'un lien vers un doc, ajouter le type='mime/type'
170
-	if ($type == 'document'
171
-	AND $mime = sql_getfetsel('mime_type', 'spip_types_documents',
172
-			"extension IN (".sql_get_select("extension","spip_documents","id_document=".sql_quote($id)).")",
173
-			'','','','',$connect)
174
-	)
175
-		$r['mime'] = $mime;
176
-
177
-	return $r;
152
+    if ($f = charger_fonction("implicite_$type","liens",true))
153
+        $url = $f($texte,$id,$type,$args,$ancre,$connect);
154
+    if (!$url)
155
+        $url = generer_url_entite($id,$type,$args,$ancre,$connect ? $connect : NULL);
156
+    if (!$url) return false;
157
+    if (is_array($url)) {
158
+        @list($type,$id) = $url;
159
+        $url = generer_url_entite($id,$type,$args,$ancre,$connect ? $connect : NULL);
160
+    }
161
+    if ($pour === 'url') return $url;
162
+    $r = traiter_raccourci_titre($id, $type, $connect);
163
+    if ($r) $r['class'] =  ($type == 'site')?'spip_out':'spip_in';
164
+    if ($texte = trim($texte)) $r['titre'] = $texte;
165
+    if (!@$r['titre']) $r['titre'] =  _T($type) . " $id";
166
+    if ($pour=='titre') return $r['titre'];
167
+    $r['url'] = $url;
168
+
169
+    // dans le cas d'un lien vers un doc, ajouter le type='mime/type'
170
+    if ($type == 'document'
171
+    AND $mime = sql_getfetsel('mime_type', 'spip_types_documents',
172
+            "extension IN (".sql_get_select("extension","spip_documents","id_document=".sql_quote($id)).")",
173
+            '','','','',$connect)
174
+    )
175
+        $r['mime'] = $mime;
176
+
177
+    return $r;
178 178
 }
179 179
 
180 180
 // analyse des raccourcis issus de [TITRE->RACCOURCInnn] et connexes
@@ -183,34 +183,34 @@  discard block
 block discarded – undo
183 183
 
184 184
 // http://doc.spip.org/@typer_raccourci
185 185
 function typer_raccourci ($lien) {
186
-	if (!preg_match(_RACCOURCI_URL, $lien, $match)) return array();
187
-	$f = $match[1];
188
-	// valeur par defaut et alias historiques
189
-	if (!$f) $f = 'article';
190
-	else if ($f == 'art') $f = 'article';
191
-	else if ($f == 'br') $f = 'breve';
192
-	else if ($f == 'rub') $f = 'rubrique';
193
-	else if ($f == 'aut') $f = 'auteur';
194
-	else if ($f == 'doc' OR $f == 'im' OR $f == 'img' OR $f == 'image' OR $f == 'emb')
195
-		$f = 'document';
196
-	else if (preg_match('/^br..?ve$/S', $f)) $f = 'breve'; # accents :(
197
-	$match[0] = $f;
198
-	return $match;
186
+    if (!preg_match(_RACCOURCI_URL, $lien, $match)) return array();
187
+    $f = $match[1];
188
+    // valeur par defaut et alias historiques
189
+    if (!$f) $f = 'article';
190
+    else if ($f == 'art') $f = 'article';
191
+    else if ($f == 'br') $f = 'breve';
192
+    else if ($f == 'rub') $f = 'rubrique';
193
+    else if ($f == 'aut') $f = 'auteur';
194
+    else if ($f == 'doc' OR $f == 'im' OR $f == 'img' OR $f == 'image' OR $f == 'emb')
195
+        $f = 'document';
196
+    else if (preg_match('/^br..?ve$/S', $f)) $f = 'breve'; # accents :(
197
+    $match[0] = $f;
198
+    return $match;
199 199
 }
200 200
 
201 201
 // Retourne le champ textuel associe a une cle primaire, et sa langue
202 202
 function traiter_raccourci_titre($id, $type, $connect=NULL)
203 203
 {
204
-	$trouver_table = charger_fonction('trouver_table', 'base');
205
-	$desc = $trouver_table(table_objet($type));
206
-	if (!($desc AND $s = $desc['titre'])) return array();
207
-	$_id = $desc['key']['PRIMARY KEY'];
208
-	$r = sql_fetsel($s, $desc['table'], "$_id=$id", '','','','',$connect);
209
-	if (!$r) return array();
210
-	$r['titre'] = supprimer_numero($r['titre']);
211
-	if (!$r['titre']) $r['titre'] = $r['surnom'];
212
-	if (!isset($r['lang'])) $r['lang'] = '';
213
-	return $r;
204
+    $trouver_table = charger_fonction('trouver_table', 'base');
205
+    $desc = $trouver_table(table_objet($type));
206
+    if (!($desc AND $s = $desc['titre'])) return array();
207
+    $_id = $desc['key']['PRIMARY KEY'];
208
+    $r = sql_fetsel($s, $desc['table'], "$_id=$id", '','','','',$connect);
209
+    if (!$r) return array();
210
+    $r['titre'] = supprimer_numero($r['titre']);
211
+    if (!$r['titre']) $r['titre'] = $r['surnom'];
212
+    if (!isset($r['lang'])) $r['lang'] = '';
213
+    return $r;
214 214
 }
215 215
 
216 216
 // traite les modeles (dans la fonction typo), en remplacant
@@ -222,107 +222,107 @@  discard block
 block discarded – undo
222 222
 // http://doc.spip.org/@traiter_modeles
223 223
 
224 224
 define('_RACCOURCI_MODELE', 
225
-	 '(<([a-z_-]{3,})' # <modele
226
-	.'\s*([0-9]*)\s*' # id
227
-	.'([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>)
228
-	.'\s*/?'.'>)' # fin du modele >
229
-	.'\s*(<\/a>)?' # eventuel </a>
230
-       );
225
+        '(<([a-z_-]{3,})' # <modele
226
+    .'\s*([0-9]*)\s*' # id
227
+    .'([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>)
228
+    .'\s*/?'.'>)' # fin du modele >
229
+    .'\s*(<\/a>)?' # eventuel </a>
230
+        );
231 231
 
232 232
 define('_RACCOURCI_MODELE_DEBUT', '@^' . _RACCOURCI_MODELE .'@isS');
233 233
 
234 234
 // http://doc.spip.org/@traiter_modeles
235 235
 function traiter_modeles($texte, $doublons=false, $echap='', $connect='', $liens = null, $env = array()) {
236
-	// preserver la compatibilite : true = recherche des documents
237
-	if ($doublons===true)
238
-		$doublons = array('documents'=>array('doc','emb','img'));
239
-	// detecter les modeles (rapide)
240
-	if (strpos($texte,"<")!==false AND
241
-	  preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER)) {
242
-		include_spip('public/assembler');
243
-		$wrap_embed_html = charger_fonction("wrap_embed_html","inc",true);
244
-		foreach ($matches as $match) {
245
-			// Recuperer l'appel complet (y compris un eventuel lien)
246
-
247
-			$a = strpos($texte,$match[0]);
248
-			preg_match(_RACCOURCI_MODELE_DEBUT,
249
-			substr($texte, $a), $regs);
250
-			$regs[]=""; // s'assurer qu'il y a toujours un 5e arg, eventuellement vide
251
-			list(,$mod, $type, $id, $params, $fin) = $regs;
252
-			if ($fin AND
253
-			preg_match('/<a\s[^<>]*>\s*$/i',
254
-					substr($texte, 0, $a), $r)) {
255
-				$lien = array(
256
-					'href' => extraire_attribut($r[0],'href'),
257
-					'class' => extraire_attribut($r[0],'class'),
258
-					'mime' => extraire_attribut($r[0],'type'),
259
-					'title' => extraire_attribut($r[0],'title'),
260
-					'hreflang' => extraire_attribut($r[0],'hreflang')
261
-				);
262
-				$n = strlen($r[0]);
263
-				$a -= $n;
264
-				$cherche = $n + strlen($regs[0]);
265
-			} else {
266
-				$lien = false;
267
-				$cherche = strlen($mod);
268
-			}
269
-
270
-			// calculer le modele
271
-			# hack indexation
272
-			if ($doublons)
273
-				$texte .= preg_replace(',[|][^|=]*,s',' ',$params);
274
-			# version normale
275
-			else {
276
-				// si un tableau de liens a ete passe, reinjecter le contenu d'origine
277
-				// dans les parametres, plutot que les liens echappes
278
-				if (!is_null($liens))
279
-					$params = str_replace($liens[0], $liens[1], $params);
280
-				$modele = inclure_modele($type, $id, $params, $lien, $connect, $env);
281
-				// en cas d'echec, 
282
-				// si l'objet demande a une url, 
283
-				// creer un petit encadre vers elle
284
-				if ($modele === false) {
285
-					if (!$lien)
286
-						$lien = traiter_lien_implicite("$type$id", '', 'tout', $connect);
287
-					if ($lien)
288
-						$modele = '<a href="'
289
-						  .$lien['url']
290
-						  .'" class="spip_modele'
291
-						  . '">'
292
-						  .sinon($lien['titre'], _T('ecrire:info_sans_titre'))
293
-						  ."</a>";
294
-					else {
295
-						$modele = "";
296
-						if (test_espace_prive()) {
297
-							$modele = entites_html(substr($texte,$a,$cherche));
298
-							if (!is_null($liens))
299
-								$modele = "<pre>".str_replace($liens[0], $liens[1], $modele)."</pre>";
300
-						}
301
-					}
302
-				}
303
-				// le remplacer dans le texte
304
-				if ($modele !== false) {
305
-					$modele = protege_js_modeles($modele);
306
-					if ($wrap_embed_html){
307
-						$modele = $wrap_embed_html($mod,$modele);
308
-					}
309
-					$rempl = code_echappement($modele, $echap);
310
-					$texte = substr($texte, 0, $a)
311
-						. $rempl
312
-						. substr($texte, $a+$cherche);
313
-				}
314
-			}
315
-
316
-			// hack pour tout l'espace prive
317
-			if (((!_DIR_RESTREINT) OR ($doublons)) AND ($id)){
318
-				foreach($doublons?$doublons:array('documents'=>array('doc','emb','img')) as $quoi=>$modeles)
319
-					if (in_array($type,$modeles))
320
-						$GLOBALS["doublons_{$quoi}_inclus"][] = $id;
321
-			}
322
-		}
323
-	}
324
-
325
-	return $texte;
236
+    // preserver la compatibilite : true = recherche des documents
237
+    if ($doublons===true)
238
+        $doublons = array('documents'=>array('doc','emb','img'));
239
+    // detecter les modeles (rapide)
240
+    if (strpos($texte,"<")!==false AND
241
+      preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER)) {
242
+        include_spip('public/assembler');
243
+        $wrap_embed_html = charger_fonction("wrap_embed_html","inc",true);
244
+        foreach ($matches as $match) {
245
+            // Recuperer l'appel complet (y compris un eventuel lien)
246
+
247
+            $a = strpos($texte,$match[0]);
248
+            preg_match(_RACCOURCI_MODELE_DEBUT,
249
+            substr($texte, $a), $regs);
250
+            $regs[]=""; // s'assurer qu'il y a toujours un 5e arg, eventuellement vide
251
+            list(,$mod, $type, $id, $params, $fin) = $regs;
252
+            if ($fin AND
253
+            preg_match('/<a\s[^<>]*>\s*$/i',
254
+                    substr($texte, 0, $a), $r)) {
255
+                $lien = array(
256
+                    'href' => extraire_attribut($r[0],'href'),
257
+                    'class' => extraire_attribut($r[0],'class'),
258
+                    'mime' => extraire_attribut($r[0],'type'),
259
+                    'title' => extraire_attribut($r[0],'title'),
260
+                    'hreflang' => extraire_attribut($r[0],'hreflang')
261
+                );
262
+                $n = strlen($r[0]);
263
+                $a -= $n;
264
+                $cherche = $n + strlen($regs[0]);
265
+            } else {
266
+                $lien = false;
267
+                $cherche = strlen($mod);
268
+            }
269
+
270
+            // calculer le modele
271
+            # hack indexation
272
+            if ($doublons)
273
+                $texte .= preg_replace(',[|][^|=]*,s',' ',$params);
274
+            # version normale
275
+            else {
276
+                // si un tableau de liens a ete passe, reinjecter le contenu d'origine
277
+                // dans les parametres, plutot que les liens echappes
278
+                if (!is_null($liens))
279
+                    $params = str_replace($liens[0], $liens[1], $params);
280
+                $modele = inclure_modele($type, $id, $params, $lien, $connect, $env);
281
+                // en cas d'echec, 
282
+                // si l'objet demande a une url, 
283
+                // creer un petit encadre vers elle
284
+                if ($modele === false) {
285
+                    if (!$lien)
286
+                        $lien = traiter_lien_implicite("$type$id", '', 'tout', $connect);
287
+                    if ($lien)
288
+                        $modele = '<a href="'
289
+                            .$lien['url']
290
+                            .'" class="spip_modele'
291
+                            . '">'
292
+                            .sinon($lien['titre'], _T('ecrire:info_sans_titre'))
293
+                            ."</a>";
294
+                    else {
295
+                        $modele = "";
296
+                        if (test_espace_prive()) {
297
+                            $modele = entites_html(substr($texte,$a,$cherche));
298
+                            if (!is_null($liens))
299
+                                $modele = "<pre>".str_replace($liens[0], $liens[1], $modele)."</pre>";
300
+                        }
301
+                    }
302
+                }
303
+                // le remplacer dans le texte
304
+                if ($modele !== false) {
305
+                    $modele = protege_js_modeles($modele);
306
+                    if ($wrap_embed_html){
307
+                        $modele = $wrap_embed_html($mod,$modele);
308
+                    }
309
+                    $rempl = code_echappement($modele, $echap);
310
+                    $texte = substr($texte, 0, $a)
311
+                        . $rempl
312
+                        . substr($texte, $a+$cherche);
313
+                }
314
+            }
315
+
316
+            // hack pour tout l'espace prive
317
+            if (((!_DIR_RESTREINT) OR ($doublons)) AND ($id)){
318
+                foreach($doublons?$doublons:array('documents'=>array('doc','emb','img')) as $quoi=>$modeles)
319
+                    if (in_array($type,$modeles))
320
+                        $GLOBALS["doublons_{$quoi}_inclus"][] = $id;
321
+            }
322
+        }
323
+    }
324
+
325
+    return $texte;
326 326
 }
327 327
 
328 328
 //
@@ -331,19 +331,19 @@  discard block
 block discarded – undo
331 331
 // http://doc.spip.org/@traiter_raccourci_ancre
332 332
 function traiter_raccourci_ancre($letexte)
333 333
 {
334
-	return $letexte;
334
+    return $letexte;
335 335
 }
336 336
 
337 337
 // http://doc.spip.org/@traiter_raccourci_glossaire
338 338
 function traiter_raccourci_glossaire($texte)
339 339
 {
340
-	return $texte;
340
+    return $texte;
341 341
 }
342 342
 
343 343
 // http://doc.spip.org/@glossaire_std
344 344
 function glossaire_std($terme)
345 345
 {
346
-	return  $terme;
346
+    return  $terme;
347 347
 }
348 348
 
349 349
 ?>
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 // et en plus on veut pouvoir les passer en pipeline
21 21
 //
22 22
 
23
-function inc_lien_dist($lien, $texte='', $class='', $title='', $hlang='', $rel='', $connect='', $env=array()) {
23
+function inc_lien_dist($lien, $texte = '', $class = '', $title = '', $hlang = '', $rel = '', $connect = '', $env = array()) {
24 24
 
25 25
 	return $lien;
26 26
 }
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 define('_RACCOURCI_LIEN', "/\[([^][]*?([[]\w*[]][^][]*)*)->(>?)([^]]*)\]/msS");
33 33
 
34 34
 // http://doc.spip.org/@expanser_liens
35
-function expanser_liens($t, $connect='', $env=array()){
35
+function expanser_liens($t, $connect = '', $env = array()) {
36 36
 
37 37
 	$t = pipeline('pre_liens', $t);
38 38
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 // Meme analyse mais pour eliminer les liens
46 46
 // et ne laisser que leur titre, a expliciter si ce n'est fait
47 47
 // http://doc.spip.org/@nettoyer_raccourcis_typo
48
-function nettoyer_raccourcis_typo($texte, $connect='')
48
+function nettoyer_raccourcis_typo($texte, $connect = '')
49 49
 {
50 50
 
51 51
 
@@ -58,8 +58,8 @@  discard block
 block discarded – undo
58 58
 // la langue et la bulle eventuelles
59 59
 // http://doc.spip.org/@traiter_raccourci_lien_atts
60 60
 function traiter_raccourci_lien_atts($texte) {
61
-	$bulle='';
62
-	$hlang='';
61
+	$bulle = '';
62
+	$hlang = '';
63 63
 	return array(trim($texte), $bulle, $hlang);
64 64
 }
65 65
 
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
  * @param bool $url
79 79
  * @return string
80 80
  */
81
-function virtuel_redirige($virtuel, $url=false){
81
+function virtuel_redirige($virtuel, $url = false) {
82 82
 	return $virtuel;
83 83
 }
84 84
 
@@ -93,18 +93,18 @@  discard block
 block discarded – undo
93 93
 // 'url':   seulement U  (i.e. generer_url_RACCOURCI)
94 94
 
95 95
 // http://doc.spip.org/@calculer_url
96
-function calculer_url ($ref, $texte='', $pour='url', $connect='', $echappe_typo = true) {
96
+function calculer_url($ref, $texte = '', $pour = 'url', $connect = '', $echappe_typo = true) {
97 97
 	$r = traiter_lien_implicite($ref, $texte, $pour, $connect, $echappe_typo);
98 98
 	return $r ? $r : traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo);
99 99
 }
100 100
 
101
-define('_EXTRAIRE_LIEN', ',^\s*(?:' . _PROTOCOLES_STD . '):?/?/?\s*$,iS');
101
+define('_EXTRAIRE_LIEN', ',^\s*(?:'._PROTOCOLES_STD.'):?/?/?\s*$,iS');
102 102
 
103 103
 // http://doc.spip.org/@traiter_lien_explicite
104
-function traiter_lien_explicite ($ref, $texte='', $pour='url', $connect='', $echappe_typo = true)
104
+function traiter_lien_explicite($ref, $texte = '', $pour = 'url', $connect = '', $echappe_typo = true)
105 105
 {
106 106
 	if (preg_match(_EXTRAIRE_LIEN, $ref))
107
-		return ($pour != 'tout') ? '' : array('','','','');
107
+		return ($pour != 'tout') ? '' : array('', '', '', '');
108 108
 
109 109
 	$lien = entites_html(trim($ref));
110 110
 
@@ -114,13 +114,13 @@  discard block
 block discarded – undo
114 114
 		// evite l'affichage de trops longues urls.
115 115
 		$lien_court = charger_fonction('lien_court', 'inc');
116 116
 		$texte = $lien_court($texte);
117
-		if ($echappe_typo){
117
+		if ($echappe_typo) {
118 118
 			$texte = "<html>".quote_amp($texte)."</html>";
119 119
 		}
120 120
 	}
121 121
 
122 122
 	// petites corrections d'URL
123
-	if (preg_match('/^www\.[^@]+$/S',$lien))
123
+	if (preg_match('/^www\.[^@]+$/S', $lien))
124 124
 		$lien = "http://".$lien;
125 125
 	else if (strpos($lien, "@") && email_valide($lien)) {
126 126
 		if (!$texte) $texte = $lien;
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
 	return array('url' => $lien, 'titre' => $texte);
135 135
 }
136 136
 
137
-function liens_implicite_glose_dist($texte,$id,$type,$args,$ancre,$connect=''){
138
-	if (function_exists($f = 'glossaire_' . $ancre))
137
+function liens_implicite_glose_dist($texte, $id, $type, $args, $ancre, $connect = '') {
138
+	if (function_exists($f = 'glossaire_'.$ancre))
139 139
 		$url = $f($texte, $id);
140 140
 	else
141 141
 		$url = glossaire_std($texte);
@@ -143,34 +143,34 @@  discard block
 block discarded – undo
143 143
 }
144 144
 
145 145
 // http://doc.spip.org/@traiter_lien_implicite
146
-function traiter_lien_implicite ($ref, $texte='', $pour='url', $connect='')
146
+function traiter_lien_implicite($ref, $texte = '', $pour = 'url', $connect = '')
147 147
 {
148 148
 	if (!($match = typer_raccourci($ref))) return false;
149 149
 	@list($type,,$id,,$args,,$ancre) = $match;
150 150
 # attention dans le cas des sites le lien doit pointer non pas sur
151 151
 # la page locale du site, mais directement sur le site lui-meme
152
-	if ($f = charger_fonction("implicite_$type","liens",true))
153
-		$url = $f($texte,$id,$type,$args,$ancre,$connect);
152
+	if ($f = charger_fonction("implicite_$type", "liens", true))
153
+		$url = $f($texte, $id, $type, $args, $ancre, $connect);
154 154
 	if (!$url)
155
-		$url = generer_url_entite($id,$type,$args,$ancre,$connect ? $connect : NULL);
155
+		$url = generer_url_entite($id, $type, $args, $ancre, $connect ? $connect : NULL);
156 156
 	if (!$url) return false;
157 157
 	if (is_array($url)) {
158
-		@list($type,$id) = $url;
159
-		$url = generer_url_entite($id,$type,$args,$ancre,$connect ? $connect : NULL);
158
+		@list($type, $id) = $url;
159
+		$url = generer_url_entite($id, $type, $args, $ancre, $connect ? $connect : NULL);
160 160
 	}
161 161
 	if ($pour === 'url') return $url;
162 162
 	$r = traiter_raccourci_titre($id, $type, $connect);
163
-	if ($r) $r['class'] =  ($type == 'site')?'spip_out':'spip_in';
163
+	if ($r) $r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in';
164 164
 	if ($texte = trim($texte)) $r['titre'] = $texte;
165
-	if (!@$r['titre']) $r['titre'] =  _T($type) . " $id";
166
-	if ($pour=='titre') return $r['titre'];
165
+	if (!@$r['titre']) $r['titre'] = _T($type)." $id";
166
+	if ($pour == 'titre') return $r['titre'];
167 167
 	$r['url'] = $url;
168 168
 
169 169
 	// dans le cas d'un lien vers un doc, ajouter le type='mime/type'
170 170
 	if ($type == 'document'
171 171
 	AND $mime = sql_getfetsel('mime_type', 'spip_types_documents',
172
-			"extension IN (".sql_get_select("extension","spip_documents","id_document=".sql_quote($id)).")",
173
-			'','','','',$connect)
172
+			"extension IN (".sql_get_select("extension", "spip_documents", "id_document=".sql_quote($id)).")",
173
+			'', '', '', '', $connect)
174 174
 	)
175 175
 		$r['mime'] = $mime;
176 176
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 define('_RACCOURCI_URL', '/^\s*(\w*?)\s*(\d+)(\?(.*?))?(#([^\s]*))?\s*$/S');
183 183
 
184 184
 // http://doc.spip.org/@typer_raccourci
185
-function typer_raccourci ($lien) {
185
+function typer_raccourci($lien) {
186 186
 	if (!preg_match(_RACCOURCI_URL, $lien, $match)) return array();
187 187
 	$f = $match[1];
188 188
 	// valeur par defaut et alias historiques
@@ -199,13 +199,13 @@  discard block
 block discarded – undo
199 199
 }
200 200
 
201 201
 // Retourne le champ textuel associe a une cle primaire, et sa langue
202
-function traiter_raccourci_titre($id, $type, $connect=NULL)
202
+function traiter_raccourci_titre($id, $type, $connect = NULL)
203 203
 {
204 204
 	$trouver_table = charger_fonction('trouver_table', 'base');
205 205
 	$desc = $trouver_table(table_objet($type));
206 206
 	if (!($desc AND $s = $desc['titre'])) return array();
207 207
 	$_id = $desc['key']['PRIMARY KEY'];
208
-	$r = sql_fetsel($s, $desc['table'], "$_id=$id", '','','','',$connect);
208
+	$r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect);
209 209
 	if (!$r) return array();
210 210
 	$r['titre'] = supprimer_numero($r['titre']);
211 211
 	if (!$r['titre']) $r['titre'] = $r['surnom'];
@@ -229,35 +229,35 @@  discard block
 block discarded – undo
229 229
 	.'\s*(<\/a>)?' # eventuel </a>
230 230
        );
231 231
 
232
-define('_RACCOURCI_MODELE_DEBUT', '@^' . _RACCOURCI_MODELE .'@isS');
232
+define('_RACCOURCI_MODELE_DEBUT', '@^'._RACCOURCI_MODELE.'@isS');
233 233
 
234 234
 // http://doc.spip.org/@traiter_modeles
235
-function traiter_modeles($texte, $doublons=false, $echap='', $connect='', $liens = null, $env = array()) {
235
+function traiter_modeles($texte, $doublons = false, $echap = '', $connect = '', $liens = null, $env = array()) {
236 236
 	// preserver la compatibilite : true = recherche des documents
237
-	if ($doublons===true)
238
-		$doublons = array('documents'=>array('doc','emb','img'));
237
+	if ($doublons === true)
238
+		$doublons = array('documents'=>array('doc', 'emb', 'img'));
239 239
 	// detecter les modeles (rapide)
240
-	if (strpos($texte,"<")!==false AND
240
+	if (strpos($texte, "<") !== false AND
241 241
 	  preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER)) {
242 242
 		include_spip('public/assembler');
243
-		$wrap_embed_html = charger_fonction("wrap_embed_html","inc",true);
243
+		$wrap_embed_html = charger_fonction("wrap_embed_html", "inc", true);
244 244
 		foreach ($matches as $match) {
245 245
 			// Recuperer l'appel complet (y compris un eventuel lien)
246 246
 
247
-			$a = strpos($texte,$match[0]);
247
+			$a = strpos($texte, $match[0]);
248 248
 			preg_match(_RACCOURCI_MODELE_DEBUT,
249 249
 			substr($texte, $a), $regs);
250
-			$regs[]=""; // s'assurer qu'il y a toujours un 5e arg, eventuellement vide
250
+			$regs[] = ""; // s'assurer qu'il y a toujours un 5e arg, eventuellement vide
251 251
 			list(,$mod, $type, $id, $params, $fin) = $regs;
252 252
 			if ($fin AND
253 253
 			preg_match('/<a\s[^<>]*>\s*$/i',
254 254
 					substr($texte, 0, $a), $r)) {
255 255
 				$lien = array(
256
-					'href' => extraire_attribut($r[0],'href'),
257
-					'class' => extraire_attribut($r[0],'class'),
258
-					'mime' => extraire_attribut($r[0],'type'),
259
-					'title' => extraire_attribut($r[0],'title'),
260
-					'hreflang' => extraire_attribut($r[0],'hreflang')
256
+					'href' => extraire_attribut($r[0], 'href'),
257
+					'class' => extraire_attribut($r[0], 'class'),
258
+					'mime' => extraire_attribut($r[0], 'type'),
259
+					'title' => extraire_attribut($r[0], 'title'),
260
+					'hreflang' => extraire_attribut($r[0], 'hreflang')
261 261
 				);
262 262
 				$n = strlen($r[0]);
263 263
 				$a -= $n;
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 			// calculer le modele
271 271
 			# hack indexation
272 272
 			if ($doublons)
273
-				$texte .= preg_replace(',[|][^|=]*,s',' ',$params);
273
+				$texte .= preg_replace(',[|][^|=]*,s', ' ', $params);
274 274
 			# version normale
275 275
 			else {
276 276
 				// si un tableau de liens a ete passe, reinjecter le contenu d'origine
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 					else {
295 295
 						$modele = "";
296 296
 						if (test_espace_prive()) {
297
-							$modele = entites_html(substr($texte,$a,$cherche));
297
+							$modele = entites_html(substr($texte, $a, $cherche));
298 298
 							if (!is_null($liens))
299 299
 								$modele = "<pre>".str_replace($liens[0], $liens[1], $modele)."</pre>";
300 300
 						}
@@ -303,20 +303,20 @@  discard block
 block discarded – undo
303 303
 				// le remplacer dans le texte
304 304
 				if ($modele !== false) {
305 305
 					$modele = protege_js_modeles($modele);
306
-					if ($wrap_embed_html){
307
-						$modele = $wrap_embed_html($mod,$modele);
306
+					if ($wrap_embed_html) {
307
+						$modele = $wrap_embed_html($mod, $modele);
308 308
 					}
309 309
 					$rempl = code_echappement($modele, $echap);
310 310
 					$texte = substr($texte, 0, $a)
311 311
 						. $rempl
312
-						. substr($texte, $a+$cherche);
312
+						. substr($texte, $a + $cherche);
313 313
 				}
314 314
 			}
315 315
 
316 316
 			// hack pour tout l'espace prive
317
-			if (((!_DIR_RESTREINT) OR ($doublons)) AND ($id)){
318
-				foreach($doublons?$doublons:array('documents'=>array('doc','emb','img')) as $quoi=>$modeles)
319
-					if (in_array($type,$modeles))
317
+			if (((!_DIR_RESTREINT) OR ($doublons)) AND ($id)) {
318
+				foreach ($doublons ? $doublons : array('documents'=>array('doc', 'emb', 'img')) as $quoi=>$modeles)
319
+					if (in_array($type, $modeles))
320 320
 						$GLOBALS["doublons_{$quoi}_inclus"][] = $id;
321 321
 			}
322 322
 		}
Please login to merge, or discard this patch.
Braces   +105 added lines, -54 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 include_spip('base/abstract_sql');
16 18
 
@@ -103,8 +105,9 @@  discard block
 block discarded – undo
103 105
 // http://doc.spip.org/@traiter_lien_explicite
104 106
 function traiter_lien_explicite ($ref, $texte='', $pour='url', $connect='', $echappe_typo = true)
105 107
 {
106
-	if (preg_match(_EXTRAIRE_LIEN, $ref))
107
-		return ($pour != 'tout') ? '' : array('','','','');
108
+	if (preg_match(_EXTRAIRE_LIEN, $ref)) {
109
+			return ($pour != 'tout') ? '' : array('','','','');
110
+	}
108 111
 
109 112
 	$lien = entites_html(trim($ref));
110 113
 
@@ -120,50 +123,73 @@  discard block
 block discarded – undo
120 123
 	}
121 124
 
122 125
 	// petites corrections d'URL
123
-	if (preg_match('/^www\.[^@]+$/S',$lien))
124
-		$lien = "http://".$lien;
125
-	else if (strpos($lien, "@") && email_valide($lien)) {
126
-		if (!$texte) $texte = $lien;
126
+	if (preg_match('/^www\.[^@]+$/S',$lien)) {
127
+			$lien = "http://".$lien;
128
+	} else if (strpos($lien, "@") && email_valide($lien)) {
129
+		if (!$texte) {
130
+		    $texte = $lien;
131
+		}
127 132
 		$lien = "mailto:".$lien;
128 133
 	}
129 134
 	
130
-	if ($pour == 'url') return $lien;
135
+	if ($pour == 'url') {
136
+	    return $lien;
137
+	}
131 138
 
132
-	if ($pour == 'titre') return $texte;
139
+	if ($pour == 'titre') {
140
+	    return $texte;
141
+	}
133 142
 
134 143
 	return array('url' => $lien, 'titre' => $texte);
135 144
 }
136 145
 
137 146
 function liens_implicite_glose_dist($texte,$id,$type,$args,$ancre,$connect=''){
138
-	if (function_exists($f = 'glossaire_' . $ancre))
139
-		$url = $f($texte, $id);
140
-	else
141
-		$url = glossaire_std($texte);
147
+	if (function_exists($f = 'glossaire_' . $ancre)) {
148
+			$url = $f($texte, $id);
149
+	} else {
150
+			$url = glossaire_std($texte);
151
+	}
142 152
 	return $url;
143 153
 }
144 154
 
145 155
 // http://doc.spip.org/@traiter_lien_implicite
146 156
 function traiter_lien_implicite ($ref, $texte='', $pour='url', $connect='')
147 157
 {
148
-	if (!($match = typer_raccourci($ref))) return false;
158
+	if (!($match = typer_raccourci($ref))) {
159
+	    return false;
160
+	}
149 161
 	@list($type,,$id,,$args,,$ancre) = $match;
150 162
 # attention dans le cas des sites le lien doit pointer non pas sur
151 163
 # la page locale du site, mais directement sur le site lui-meme
152
-	if ($f = charger_fonction("implicite_$type","liens",true))
153
-		$url = $f($texte,$id,$type,$args,$ancre,$connect);
154
-	if (!$url)
155
-		$url = generer_url_entite($id,$type,$args,$ancre,$connect ? $connect : NULL);
156
-	if (!$url) return false;
164
+	if ($f = charger_fonction("implicite_$type","liens",true)) {
165
+			$url = $f($texte,$id,$type,$args,$ancre,$connect);
166
+	}
167
+	if (!$url) {
168
+			$url = generer_url_entite($id,$type,$args,$ancre,$connect ? $connect : NULL);
169
+	}
170
+	if (!$url) {
171
+	    return false;
172
+	}
157 173
 	if (is_array($url)) {
158 174
 		@list($type,$id) = $url;
159 175
 		$url = generer_url_entite($id,$type,$args,$ancre,$connect ? $connect : NULL);
160 176
 	}
161
-	if ($pour === 'url') return $url;
177
+	if ($pour === 'url') {
178
+	    return $url;
179
+	}
162 180
 	$r = traiter_raccourci_titre($id, $type, $connect);
163
-	if ($r) $r['class'] =  ($type == 'site')?'spip_out':'spip_in';
164
-	if ($texte = trim($texte)) $r['titre'] = $texte;
165
-	if (!@$r['titre']) $r['titre'] =  _T($type) . " $id";
166
-	if ($pour=='titre') return $r['titre'];
181
+	if ($r) {
182
+	    $r['class'] =  ($type == 'site')?'spip_out':'spip_in';
183
+	}
184
+	if ($texte = trim($texte)) {
185
+	    $r['titre'] = $texte;
186
+	}
187
+	if (!@$r['titre']) {
188
+	    $r['titre'] =  _T($type) . " $id";
189
+	}
190
+	if ($pour=='titre') {
191
+	    return $r['titre'];
192
+	}
167 193
 	$r['url'] = $url;
168 194
 
169 195
 	// dans le cas d'un lien vers un doc, ajouter le type='mime/type'
@@ -171,8 +197,9 @@  discard block
 block discarded – undo
171 197
 	AND $mime = sql_getfetsel('mime_type', 'spip_types_documents',
172 198
 			"extension IN (".sql_get_select("extension","spip_documents","id_document=".sql_quote($id)).")",
173 199
 			'','','','',$connect)
174
-	)
175
-		$r['mime'] = $mime;
200
+	) {
201
+			$r['mime'] = $mime;
202
+	}
176 203
 
177 204
 	return $r;
178 205
 }
@@ -183,17 +210,27 @@  discard block
 block discarded – undo
183 210
 
184 211
 // http://doc.spip.org/@typer_raccourci
185 212
 function typer_raccourci ($lien) {
186
-	if (!preg_match(_RACCOURCI_URL, $lien, $match)) return array();
213
+	if (!preg_match(_RACCOURCI_URL, $lien, $match)) {
214
+	    return array();
215
+	}
187 216
 	$f = $match[1];
188 217
 	// valeur par defaut et alias historiques
189
-	if (!$f) $f = 'article';
190
-	else if ($f == 'art') $f = 'article';
191
-	else if ($f == 'br') $f = 'breve';
192
-	else if ($f == 'rub') $f = 'rubrique';
193
-	else if ($f == 'aut') $f = 'auteur';
194
-	else if ($f == 'doc' OR $f == 'im' OR $f == 'img' OR $f == 'image' OR $f == 'emb')
195
-		$f = 'document';
196
-	else if (preg_match('/^br..?ve$/S', $f)) $f = 'breve'; # accents :(
218
+	if (!$f) {
219
+	    $f = 'article';
220
+	} else if ($f == 'art') {
221
+	    $f = 'article';
222
+	} else if ($f == 'br') {
223
+	    $f = 'breve';
224
+	} else if ($f == 'rub') {
225
+	    $f = 'rubrique';
226
+	} else if ($f == 'aut') {
227
+	    $f = 'auteur';
228
+	} else if ($f == 'doc' OR $f == 'im' OR $f == 'img' OR $f == 'image' OR $f == 'emb') {
229
+			$f = 'document';
230
+	} else if (preg_match('/^br..?ve$/S', $f)) {
231
+	    $f = 'breve';
232
+	}
233
+	# accents :(
197 234
 	$match[0] = $f;
198 235
 	return $match;
199 236
 }
@@ -203,13 +240,21 @@  discard block
 block discarded – undo
203 240
 {
204 241
 	$trouver_table = charger_fonction('trouver_table', 'base');
205 242
 	$desc = $trouver_table(table_objet($type));
206
-	if (!($desc AND $s = $desc['titre'])) return array();
243
+	if (!($desc AND $s = $desc['titre'])) {
244
+	    return array();
245
+	}
207 246
 	$_id = $desc['key']['PRIMARY KEY'];
208 247
 	$r = sql_fetsel($s, $desc['table'], "$_id=$id", '','','','',$connect);
209
-	if (!$r) return array();
248
+	if (!$r) {
249
+	    return array();
250
+	}
210 251
 	$r['titre'] = supprimer_numero($r['titre']);
211
-	if (!$r['titre']) $r['titre'] = $r['surnom'];
212
-	if (!isset($r['lang'])) $r['lang'] = '';
252
+	if (!$r['titre']) {
253
+	    $r['titre'] = $r['surnom'];
254
+	}
255
+	if (!isset($r['lang'])) {
256
+	    $r['lang'] = '';
257
+	}
213 258
 	return $r;
214 259
 }
215 260
 
@@ -234,8 +279,9 @@  discard block
 block discarded – undo
234 279
 // http://doc.spip.org/@traiter_modeles
235 280
 function traiter_modeles($texte, $doublons=false, $echap='', $connect='', $liens = null, $env = array()) {
236 281
 	// preserver la compatibilite : true = recherche des documents
237
-	if ($doublons===true)
238
-		$doublons = array('documents'=>array('doc','emb','img'));
282
+	if ($doublons===true) {
283
+			$doublons = array('documents'=>array('doc','emb','img'));
284
+	}
239 285
 	// detecter les modeles (rapide)
240 286
 	if (strpos($texte,"<")!==false AND
241 287
 	  preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER)) {
@@ -269,34 +315,38 @@  discard block
 block discarded – undo
269 315
 
270 316
 			// calculer le modele
271 317
 			# hack indexation
272
-			if ($doublons)
273
-				$texte .= preg_replace(',[|][^|=]*,s',' ',$params);
318
+			if ($doublons) {
319
+							$texte .= preg_replace(',[|][^|=]*,s',' ',$params);
320
+			}
274 321
 			# version normale
275 322
 			else {
276 323
 				// si un tableau de liens a ete passe, reinjecter le contenu d'origine
277 324
 				// dans les parametres, plutot que les liens echappes
278
-				if (!is_null($liens))
279
-					$params = str_replace($liens[0], $liens[1], $params);
325
+				if (!is_null($liens)) {
326
+									$params = str_replace($liens[0], $liens[1], $params);
327
+				}
280 328
 				$modele = inclure_modele($type, $id, $params, $lien, $connect, $env);
281 329
 				// en cas d'echec, 
282 330
 				// si l'objet demande a une url, 
283 331
 				// creer un petit encadre vers elle
284 332
 				if ($modele === false) {
285
-					if (!$lien)
286
-						$lien = traiter_lien_implicite("$type$id", '', 'tout', $connect);
287
-					if ($lien)
288
-						$modele = '<a href="'
333
+					if (!$lien) {
334
+											$lien = traiter_lien_implicite("$type$id", '', 'tout', $connect);
335
+					}
336
+					if ($lien) {
337
+											$modele = '<a href="'
289 338
 						  .$lien['url']
290 339
 						  .'" class="spip_modele'
291 340
 						  . '">'
292 341
 						  .sinon($lien['titre'], _T('ecrire:info_sans_titre'))
293 342
 						  ."</a>";
294
-					else {
343
+					} else {
295 344
 						$modele = "";
296 345
 						if (test_espace_prive()) {
297 346
 							$modele = entites_html(substr($texte,$a,$cherche));
298
-							if (!is_null($liens))
299
-								$modele = "<pre>".str_replace($liens[0], $liens[1], $modele)."</pre>";
347
+							if (!is_null($liens)) {
348
+															$modele = "<pre>".str_replace($liens[0], $liens[1], $modele)."</pre>";
349
+							}
300 350
 						}
301 351
 					}
302 352
 				}
@@ -315,9 +365,10 @@  discard block
 block discarded – undo
315 365
 
316 366
 			// hack pour tout l'espace prive
317 367
 			if (((!_DIR_RESTREINT) OR ($doublons)) AND ($id)){
318
-				foreach($doublons?$doublons:array('documents'=>array('doc','emb','img')) as $quoi=>$modeles)
319
-					if (in_array($type,$modeles))
368
+				foreach($doublons?$doublons:array('documents'=>array('doc','emb','img')) as $quoi=>$modeles) {
369
+									if (in_array($type,$modeles))
320 370
 						$GLOBALS["doublons_{$quoi}_inclus"][] = $id;
371
+				}
321 372
 			}
322 373
 		}
323 374
 	}
Please login to merge, or discard this patch.
ecrire/inc/lister_objets.php 4 patches
Doc Comments   -3 removed lines patch added patch discarded remove patch
@@ -19,9 +19,6 @@
 block discarded – undo
19 19
  * surcharge pour aiguiller vers la mise en skel
20 20
  *
21 21
  * @param string $vue
22
- * @param string $titre
23
- * @param array $requete
24
- * @param string $formater
25 22
  * @param bool $force
26 23
  * @return string
27 24
  */
Please login to merge, or discard this patch.
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -26,28 +26,28 @@
 block discarded – undo
26 26
  * @return string
27 27
  */
28 28
 function inc_lister_objets_dist($vue, $contexte=array(), $force=false){
29
-	$res = ""; // debug
30
-	if (!is_array($contexte))
31
-		return _L('$contexte doit etre un tableau dans inc/lister_objets');
32
-
33
-	$fond = "prive/objets/liste/$vue";
34
-	if (!find_in_path($fond."."._EXTENSION_SQUELETTES)) {
35
-		// traiter les cas particuliers
36
-		include_spip('base/connect_sql');
37
-		$vue = table_objet($vue);
38
-		$fond = "prive/objets/liste/$vue";
39
-		if (!find_in_path($fond."."._EXTENSION_SQUELETTES))
40
-			return _L("vue $vue introuvable pour lister les objets");
41
-	}
29
+    $res = ""; // debug
30
+    if (!is_array($contexte))
31
+        return _L('$contexte doit etre un tableau dans inc/lister_objets');
32
+
33
+    $fond = "prive/objets/liste/$vue";
34
+    if (!find_in_path($fond."."._EXTENSION_SQUELETTES)) {
35
+        // traiter les cas particuliers
36
+        include_spip('base/connect_sql');
37
+        $vue = table_objet($vue);
38
+        $fond = "prive/objets/liste/$vue";
39
+        if (!find_in_path($fond."."._EXTENSION_SQUELETTES))
40
+            return _L("vue $vue introuvable pour lister les objets");
41
+    }
42 42
 		
43 43
 	
44
-	$contexte['sinon']=($force ? $contexte['titre']:'');
44
+    $contexte['sinon']=($force ? $contexte['titre']:'');
45 45
 
46
-	$res = recuperer_fond($fond,$contexte,array('ajax'=>true));
47
-	if (_request('var_liste'))
48
-		echo var_export($contexte, true);
46
+    $res = recuperer_fond($fond,$contexte,array('ajax'=>true));
47
+    if (_request('var_liste'))
48
+        echo var_export($contexte, true);
49 49
 		
50
-	return $res;
50
+    return $res;
51 51
 }
52 52
 
53 53
 ?>
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  * @param bool $force
26 26
  * @return string
27 27
  */
28
-function inc_lister_objets_dist($vue, $contexte=array(), $force=false){
28
+function inc_lister_objets_dist($vue, $contexte = array(), $force = false) {
29 29
 	$res = ""; // debug
30 30
 	if (!is_array($contexte))
31 31
 		return _L('$contexte doit etre un tableau dans inc/lister_objets');
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
 	}
42 42
 		
43 43
 	
44
-	$contexte['sinon']=($force ? $contexte['titre']:'');
44
+	$contexte['sinon'] = ($force ? $contexte['titre'] : '');
45 45
 
46
-	$res = recuperer_fond($fond,$contexte,array('ajax'=>true));
46
+	$res = recuperer_fond($fond, $contexte, array('ajax'=>true));
47 47
 	if (_request('var_liste'))
48 48
 		echo var_export($contexte, true);
49 49
 		
Please login to merge, or discard this patch.
Braces   +12 added lines, -7 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 
16 18
 
@@ -27,8 +29,9 @@  discard block
 block discarded – undo
27 29
  */
28 30
 function inc_lister_objets_dist($vue, $contexte=array(), $force=false){
29 31
 	$res = ""; // debug
30
-	if (!is_array($contexte))
31
-		return _L('$contexte doit etre un tableau dans inc/lister_objets');
32
+	if (!is_array($contexte)) {
33
+			return _L('$contexte doit etre un tableau dans inc/lister_objets');
34
+	}
32 35
 
33 36
 	$fond = "prive/objets/liste/$vue";
34 37
 	if (!find_in_path($fond."."._EXTENSION_SQUELETTES)) {
@@ -36,16 +39,18 @@  discard block
 block discarded – undo
36 39
 		include_spip('base/connect_sql');
37 40
 		$vue = table_objet($vue);
38 41
 		$fond = "prive/objets/liste/$vue";
39
-		if (!find_in_path($fond."."._EXTENSION_SQUELETTES))
40
-			return _L("vue $vue introuvable pour lister les objets");
42
+		if (!find_in_path($fond."."._EXTENSION_SQUELETTES)) {
43
+					return _L("vue $vue introuvable pour lister les objets");
44
+		}
41 45
 	}
42 46
 		
43 47
 	
44 48
 	$contexte['sinon']=($force ? $contexte['titre']:'');
45 49
 
46 50
 	$res = recuperer_fond($fond,$contexte,array('ajax'=>true));
47
-	if (_request('var_liste'))
48
-		echo var_export($contexte, true);
51
+	if (_request('var_liste')) {
52
+			echo var_export($contexte, true);
53
+	}
49 54
 		
50 55
 	return $res;
51 56
 }
Please login to merge, or discard this patch.
ecrire/inc/plugin.php 4 patches
Doc Comments   +10 added lines, -1 removed lines patch added patch discarded remove patch
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
  *
441 441
  * @param $liste
442 442
  * 		Liste de description des plugins
443
- * @param $nom
443
+ * @param string $nom
444 444
  * 		Le plugin donc on cherche la presence
445 445
  * @param $version
446 446
  * 		L'éventuelle intervalle de compatibilité de la dependance. ex: [1.1.0;]
@@ -681,6 +681,9 @@  discard block
 block discarded – undo
681 681
 	ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']);
682 682
 }
683 683
 
684
+/**
685
+ * @param string $nom
686
+ */
684 687
 function plugin_ongletbouton($nom, $val)
685 688
 {
686 689
 	if (!$val) $val = array();
@@ -698,6 +701,9 @@  discard block
 block discarded – undo
698 701
 // $GLOBALS['spip_pipeline']
699 702
 // $GLOBALS['spip_matrice']
700 703
 
704
+/**
705
+ * @param boolean $pipe_recherche
706
+ */
701 707
 function pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche)
702 708
 {
703 709
 	static $liste_pipe_manquants=array();
@@ -837,6 +843,9 @@  discard block
 block discarded – undo
837 843
 	ecrire_meta('plugin_installes',serialize($meta_plug_installes),'non');
838 844
 }
839 845
 
846
+/**
847
+ * @param string $nom
848
+ */
840 849
 function ecrire_fichier_php($nom, $contenu, $comment='')
841 850
 {
842 851
 	ecrire_fichier($nom, 
Please login to merge, or discard this patch.
Indentation   +601 added lines, -601 removed lines patch added patch discarded remove patch
@@ -24,76 +24,76 @@  discard block
 block discarded – undo
24 24
 // (chemins relatifs a la racine du site, separes par des ":")
25 25
 // http://doc.spip.org/@liste_plugin_files
26 26
 function liste_plugin_files($dir_plugins = null){
27
-	static $plugin_files=array();
28
-	if (is_null($dir_plugins))
29
-		$dir_plugins = _DIR_PLUGINS;
30
-	if (!isset($plugin_files[$dir_plugins])
31
-	OR count($plugin_files[$dir_plugins]) == 0){
32
-		$plugin_files[$dir_plugins] = array();
33
-		foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) {
34
-			$plugin_files[$dir_plugins][] = substr($plugin,strlen($dir_plugins));
35
-		}
27
+    static $plugin_files=array();
28
+    if (is_null($dir_plugins))
29
+        $dir_plugins = _DIR_PLUGINS;
30
+    if (!isset($plugin_files[$dir_plugins])
31
+    OR count($plugin_files[$dir_plugins]) == 0){
32
+        $plugin_files[$dir_plugins] = array();
33
+        foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) {
34
+            $plugin_files[$dir_plugins][] = substr($plugin,strlen($dir_plugins));
35
+        }
36 36
 		
37
-		sort($plugin_files[$dir_plugins]);
38
-		// et on lit le XML de tous les plugins pour le mettre en cache
39
-		// et en profiter pour nettoyer ceux qui n'existent plus du cache
40
-		$get_infos = charger_fonction('get_infos','plugins');
41
-		$get_infos($plugin_files[$dir_plugins],false,$dir_plugins,true);
42
-	}
43
-	return $plugin_files[$dir_plugins];
37
+        sort($plugin_files[$dir_plugins]);
38
+        // et on lit le XML de tous les plugins pour le mettre en cache
39
+        // et en profiter pour nettoyer ceux qui n'existent plus du cache
40
+        $get_infos = charger_fonction('get_infos','plugins');
41
+        $get_infos($plugin_files[$dir_plugins],false,$dir_plugins,true);
42
+    }
43
+    return $plugin_files[$dir_plugins];
44 44
 }
45 45
 
46 46
 function fast_find_plugin_dirs($dir, $max_prof=100) {
47
-	$fichiers = array();
48
-	// revenir au repertoire racine si on a recu dossier/truc
49
-	// pour regarder dossier/truc/ ne pas oublier le / final
50
-	$dir = preg_replace(',/[^/]*$,', '', $dir);
51
-	if ($dir == '') $dir = '.';
52
-
53
-	if (!is_dir($dir))
54
-		return $fichiers;
55
-	if (is_plugin_dir($dir,'')) {
56
-		$fichiers[] = $dir;
57
-		return $fichiers;
58
-	}
59
-	if ($max_prof<=0)
60
-		return $fichiers;
61
-
62
-	$subdirs = array();
63
-	if (@is_dir($dir) AND is_readable($dir) AND $d = @opendir($dir)) {
64
-		while (($f = readdir($d)) !== false) {
65
-			if ($f[0] != '.' # ignorer . .. .svn etc
66
-			AND $f != 'CVS'
67
-			AND is_dir($f = "$dir/$f"))
68
-				$subdirs[] = $f;
69
-		}
70
-		closedir($d);
71
-	}
72
-
73
-	foreach($subdirs as $d){
74
-		$fichiers = array_merge($fichiers,fast_find_plugin_dirs("$d/",$max_prof-1));
75
-	}
76
-	return $fichiers;
47
+    $fichiers = array();
48
+    // revenir au repertoire racine si on a recu dossier/truc
49
+    // pour regarder dossier/truc/ ne pas oublier le / final
50
+    $dir = preg_replace(',/[^/]*$,', '', $dir);
51
+    if ($dir == '') $dir = '.';
52
+
53
+    if (!is_dir($dir))
54
+        return $fichiers;
55
+    if (is_plugin_dir($dir,'')) {
56
+        $fichiers[] = $dir;
57
+        return $fichiers;
58
+    }
59
+    if ($max_prof<=0)
60
+        return $fichiers;
61
+
62
+    $subdirs = array();
63
+    if (@is_dir($dir) AND is_readable($dir) AND $d = @opendir($dir)) {
64
+        while (($f = readdir($d)) !== false) {
65
+            if ($f[0] != '.' # ignorer . .. .svn etc
66
+            AND $f != 'CVS'
67
+            AND is_dir($f = "$dir/$f"))
68
+                $subdirs[] = $f;
69
+        }
70
+        closedir($d);
71
+    }
72
+
73
+    foreach($subdirs as $d){
74
+        $fichiers = array_merge($fichiers,fast_find_plugin_dirs("$d/",$max_prof-1));
75
+    }
76
+    return $fichiers;
77 77
 }
78 78
 
79 79
 function is_plugin_dir($dir,$dir_plugins = null){
80
-	if (is_array($dir)){
81
-		foreach($dir as $k=>$d){
82
-			if (!is_plugin_dir($d,$dir_plugins))
83
-				unset($dir[$k]);
84
-		}
85
-		return $dir;
86
-	}
87
-	if (is_null($dir_plugins))
88
-		$dir_plugins = _DIR_PLUGINS;
89
-	$search = array("$dir_plugins$dir/plugin.xml","$dir_plugins$dir/paquet.xml");
80
+    if (is_array($dir)){
81
+        foreach($dir as $k=>$d){
82
+            if (!is_plugin_dir($d,$dir_plugins))
83
+                unset($dir[$k]);
84
+        }
85
+        return $dir;
86
+    }
87
+    if (is_null($dir_plugins))
88
+        $dir_plugins = _DIR_PLUGINS;
89
+    $search = array("$dir_plugins$dir/plugin.xml","$dir_plugins$dir/paquet.xml");
90 90
 	
91
-	foreach($search as $s){
92
-		if (file_exists($s)){
93
-			return $dir;
94
-		}
95
-	}
96
-	return '';
91
+    foreach($search as $s){
92
+        if (file_exists($s)){
93
+            return $dir;
94
+        }
95
+    }
96
+    return '';
97 97
 }
98 98
 
99 99
 // Regexp d'extraction des informations d'un intervalle de compatibilité
@@ -118,34 +118,34 @@  discard block
 block discarded – undo
118 118
 **/
119 119
 function plugin_version_compatible($intervalle, $version, $avec_quoi = '') {
120 120
 
121
-	if (!strlen($intervalle)) return true;
122
-	if (!preg_match(_EXTRAIRE_INTERVALLE,$intervalle,$regs)) return false;
123
-	// Extraction des bornes et traitement de * pour la borne sup :
124
-	// -- on autorise uniquement les ecritures 3.0.*, 3.*
125
-	$minimum = $regs[1];
126
-	$maximum = $regs[2];
127
-
128
-	//  si une borne de compatibilité supérieure a été définie (dans
129
-	//  mes_options.php, sous la forme : define('_DEV_PLUGINS', '3.1.99');
130
-	//  on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison
131
-	//  avec la version de SPIP (ne nuit donc pas aux tests de necessite
132
-	//  entre plugins)
133
-	if (defined('_DEV_PLUGINS') && $avec_quoi == 'spip') {
134
-		$maximum = _DEV_PLUGINS.']';
135
-	}
136
-
137
-	$minimum_inc = $intervalle{0}=="[";
138
-	$maximum_inc = substr($intervalle,-1)=="]";
139
-
140
-	if (strlen($minimum)){
141
-		if ($minimum_inc AND spip_version_compare($version,$minimum,'<')) return false;
142
-		if (!$minimum_inc AND spip_version_compare($version,$minimum,'<=')) return false;
143
-	}
144
-	if (strlen($maximum)){
145
-		if ($maximum_inc AND spip_version_compare($version,$maximum,'>')) return false;
146
-		if (!$maximum_inc AND spip_version_compare($version,$maximum,'>=')) return false;
147
-	}
148
-	return true;
121
+    if (!strlen($intervalle)) return true;
122
+    if (!preg_match(_EXTRAIRE_INTERVALLE,$intervalle,$regs)) return false;
123
+    // Extraction des bornes et traitement de * pour la borne sup :
124
+    // -- on autorise uniquement les ecritures 3.0.*, 3.*
125
+    $minimum = $regs[1];
126
+    $maximum = $regs[2];
127
+
128
+    //  si une borne de compatibilité supérieure a été définie (dans
129
+    //  mes_options.php, sous la forme : define('_DEV_PLUGINS', '3.1.99');
130
+    //  on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison
131
+    //  avec la version de SPIP (ne nuit donc pas aux tests de necessite
132
+    //  entre plugins)
133
+    if (defined('_DEV_PLUGINS') && $avec_quoi == 'spip') {
134
+        $maximum = _DEV_PLUGINS.']';
135
+    }
136
+
137
+    $minimum_inc = $intervalle{0}=="[";
138
+    $maximum_inc = substr($intervalle,-1)=="]";
139
+
140
+    if (strlen($minimum)){
141
+        if ($minimum_inc AND spip_version_compare($version,$minimum,'<')) return false;
142
+        if (!$minimum_inc AND spip_version_compare($version,$minimum,'<=')) return false;
143
+    }
144
+    if (strlen($maximum)){
145
+        if ($maximum_inc AND spip_version_compare($version,$maximum,'>')) return false;
146
+        if (!$maximum_inc AND spip_version_compare($version,$maximum,'>=')) return false;
147
+    }
148
+    return true;
149 149
 }
150 150
 
151 151
 
@@ -159,48 +159,48 @@  discard block
 block discarded – undo
159 159
  * @return array
160 160
  */
161 161
 function liste_plugin_valides($liste_plug, $force = false){
162
-	$liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST);
163
-	$get_infos = charger_fonction('get_infos', 'plugins');
164
-	$infos = array(
165
-		// lister les extensions qui sont automatiquement actives
166
-		'_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST),
167
-		'_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS)
168
-	);
169
-
170
-	// creer une premiere liste non ordonnee mais qui ne retient
171
-	// que les plugins valides, et dans leur derniere version en cas de doublon
172
-	$infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT);
173
-	$infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche'];
174
-	$infos['_DIR_RESTREINT']['SPIP']['chemin'] = array();
175
-	$liste_non_classee = array('SPIP' => array(
176
-		'nom' => 'SPIP',
177
-		'etat' => 'stable',
178
-		'version' => $GLOBALS['spip_version_branche'],
179
-		'dir_type' => '_DIR_RESTREINT',
180
-		'dir' => '',
181
-	)
182
-	);
183
-
184
-	foreach ($liste_ext as $plug){
185
-		if (isset($infos['_DIR_PLUGINS_DIST'][$plug]))
186
-			plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST');
187
-	}
188
-	foreach ($liste_plug as $plug){
189
-		if (isset($infos['_DIR_PLUGINS'][$plug]))
190
-			plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS');
191
-	}
162
+    $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST);
163
+    $get_infos = charger_fonction('get_infos', 'plugins');
164
+    $infos = array(
165
+        // lister les extensions qui sont automatiquement actives
166
+        '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST),
167
+        '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS)
168
+    );
169
+
170
+    // creer une premiere liste non ordonnee mais qui ne retient
171
+    // que les plugins valides, et dans leur derniere version en cas de doublon
172
+    $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT);
173
+    $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche'];
174
+    $infos['_DIR_RESTREINT']['SPIP']['chemin'] = array();
175
+    $liste_non_classee = array('SPIP' => array(
176
+        'nom' => 'SPIP',
177
+        'etat' => 'stable',
178
+        'version' => $GLOBALS['spip_version_branche'],
179
+        'dir_type' => '_DIR_RESTREINT',
180
+        'dir' => '',
181
+    )
182
+    );
183
+
184
+    foreach ($liste_ext as $plug){
185
+        if (isset($infos['_DIR_PLUGINS_DIST'][$plug]))
186
+            plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST');
187
+    }
188
+    foreach ($liste_plug as $plug){
189
+        if (isset($infos['_DIR_PLUGINS'][$plug]))
190
+            plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS');
191
+    }
192 192
 	
193
-	if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL){
194
-		$infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL);
195
-		foreach ($liste_plug as $plug){
196
-			if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug]))
197
-				plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL');
198
-		}
199
-	}
193
+    if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL){
194
+        $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL);
195
+        foreach ($liste_plug as $plug){
196
+            if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug]))
197
+                plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL');
198
+        }
199
+    }
200 200
 	
201
-	plugin_fixer_procure($liste_non_classee, $infos);
201
+    plugin_fixer_procure($liste_non_classee, $infos);
202 202
 
203
-	return array($infos, $liste_non_classee);
203
+    return array($infos, $liste_non_classee);
204 204
 }
205 205
 
206 206
 /**
@@ -214,23 +214,23 @@  discard block
 block discarded – undo
214 214
  * @param string $dir_type
215 215
  */
216 216
 function plugin_valide_resume(&$liste, $plug, $infos, $dir_type){
217
-	$i = $infos[$dir_type][$plug];
218
-	if (isset($i['erreur']) AND $i['erreur'])
219
-		return;
220
-	if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip'))
221
-		return;
222
-	$p = strtoupper($i['prefix']);
223
-	if (!isset($liste[$p]) 
224
-		OR spip_version_compare($i['version'], $liste[$p]['version'], '>')
225
-	  ){
226
-		$liste[$p] = array(
227
-			'nom' => $i['nom'],
228
-			'etat' => $i['etat'],
229
-			'version' => $i['version'],
230
-			'dir' => $plug,
231
-			'dir_type' => $dir_type
232
-		);
233
-	}
217
+    $i = $infos[$dir_type][$plug];
218
+    if (isset($i['erreur']) AND $i['erreur'])
219
+        return;
220
+    if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip'))
221
+        return;
222
+    $p = strtoupper($i['prefix']);
223
+    if (!isset($liste[$p]) 
224
+        OR spip_version_compare($i['version'], $liste[$p]['version'], '>')
225
+        ){
226
+        $liste[$p] = array(
227
+            'nom' => $i['nom'],
228
+            'etat' => $i['etat'],
229
+            'version' => $i['version'],
230
+            'dir' => $plug,
231
+            'dir_type' => $dir_type
232
+        );
233
+    }
234 234
 }
235 235
 
236 236
 /**
@@ -244,44 +244,44 @@  discard block
 block discarded – undo
244 244
  * @param array $infos
245 245
  */
246 246
 function plugin_fixer_procure(&$liste, &$infos){
247
-	foreach($liste as $p=>$resume){
248
-		$i = $infos[$resume['dir_type']][$resume['dir']];
249
-		if (isset($i['procure']) AND $i['procure']){
250
-			foreach($i['procure'] as $procure){
251
-				$p = strtoupper($procure['nom']);
252
-				$dir = $resume['dir'];
253
-				if ($dir) $dir .= "/";
254
-				$dir .= "procure:".$procure['nom'];
255
-
256
-				$procure['etat'] = '?';
257
-				$procure['dir_type'] = $resume['dir_type'];
258
-				$procure['dir'] = $dir;
259
-
260
-				// si ce plugin n'est pas deja procure, ou dans une version plus ancienne
261
-				// on ajoute cette version a la liste
262
-				if (!isset($liste[$p])
263
-					OR spip_version_compare($procure['version'], $liste[$p]['version'], '>')
264
-				  ){
265
-					$liste[$p] = $procure;
266
-
267
-					// on fournit une information minimale pour ne pas perturber la compilation
268
-					$infos[$resume['dir_type']][$dir] = array(
269
-						'prefix' => $procure['nom'],
270
-						'nom' => $procure['nom'],
271
-						'etat' => $procure['etat'],
272
-						'version' => $procure['version'],
273
-						'chemin' => array(),
274
-						'necessite' => array(),
275
-						'utilise' => array(),
276
-						'lib' => array(),
277
-						'menu' => array(),
278
-						'onglet' => array(),
279
-						'procure' => array(),
280
-					);
281
-				}
282
-			}
283
-		}
284
-	}
247
+    foreach($liste as $p=>$resume){
248
+        $i = $infos[$resume['dir_type']][$resume['dir']];
249
+        if (isset($i['procure']) AND $i['procure']){
250
+            foreach($i['procure'] as $procure){
251
+                $p = strtoupper($procure['nom']);
252
+                $dir = $resume['dir'];
253
+                if ($dir) $dir .= "/";
254
+                $dir .= "procure:".$procure['nom'];
255
+
256
+                $procure['etat'] = '?';
257
+                $procure['dir_type'] = $resume['dir_type'];
258
+                $procure['dir'] = $dir;
259
+
260
+                // si ce plugin n'est pas deja procure, ou dans une version plus ancienne
261
+                // on ajoute cette version a la liste
262
+                if (!isset($liste[$p])
263
+                    OR spip_version_compare($procure['version'], $liste[$p]['version'], '>')
264
+                    ){
265
+                    $liste[$p] = $procure;
266
+
267
+                    // on fournit une information minimale pour ne pas perturber la compilation
268
+                    $infos[$resume['dir_type']][$dir] = array(
269
+                        'prefix' => $procure['nom'],
270
+                        'nom' => $procure['nom'],
271
+                        'etat' => $procure['etat'],
272
+                        'version' => $procure['version'],
273
+                        'chemin' => array(),
274
+                        'necessite' => array(),
275
+                        'utilise' => array(),
276
+                        'lib' => array(),
277
+                        'menu' => array(),
278
+                        'onglet' => array(),
279
+                        'procure' => array(),
280
+                    );
281
+                }
282
+            }
283
+        }
284
+    }
285 285
 }
286 286
 
287 287
 /**
@@ -294,16 +294,16 @@  discard block
 block discarded – undo
294 294
  * @return array
295 295
  */
296 296
 function liste_chemin_plugin($liste, $dir_plugins=_DIR_PLUGINS){
297
-	foreach ($liste as $prefix=>$infos) {
298
-		if (!$dir_plugins
299
-			OR (
300
-				defined($infos['dir_type'])
301
-		    AND constant($infos['dir_type'])==$dir_plugins))
302
-			$liste[$prefix] = $infos['dir'];
303
-		else
304
-			unset($liste[$prefix]);
305
-	}
306
-	return $liste;
297
+    foreach ($liste as $prefix=>$infos) {
298
+        if (!$dir_plugins
299
+            OR (
300
+                defined($infos['dir_type'])
301
+            AND constant($infos['dir_type'])==$dir_plugins))
302
+            $liste[$prefix] = $infos['dir'];
303
+        else
304
+            unset($liste[$prefix]);
305
+    }
306
+    return $liste;
307 307
 }
308 308
 
309 309
 /**
@@ -314,8 +314,8 @@  discard block
 block discarded – undo
314 314
  */
315 315
 // http://doc.spip.org/@liste_chemin_plugin_actifs
316 316
 function liste_chemin_plugin_actifs($dir_plugins=_DIR_PLUGINS){
317
-	include_spip('plugins/installer');
318
-	return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins);
317
+    include_spip('plugins/installer');
318
+    return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins);
319 319
 }
320 320
 
321 321
 // Pour tester utilise, il faut connaitre tous les plugins 
@@ -328,87 +328,87 @@  discard block
 block discarded – undo
328 328
 
329 329
 function plugin_trier($infos, $liste_non_classee)
330 330
 {
331
-	$toute_la_liste = $liste_non_classee;
332
-	$liste = $ordre = array();
333
-	$count = 0;
334
-	while ($c=count($liste_non_classee) AND $c!=$count){ // tant qu'il reste des plugins a classer, et qu'on ne stagne pas
335
-	  #echo "tour::";var_dump($liste_non_classee);
336
-		$count = $c;
337
-		foreach($liste_non_classee as $p=>$resume) {
338
-			$plug = $resume['dir'];
339
-			$dir_type = $resume['dir_type'];
340
-			$info1 = $infos[$dir_type][$plug];
341
-			// si des plugins sont necessaires,
342
-			// on ne peut inserer qu'apres eux
343
-			foreach($info1['necessite'] as $need){
344
-			  $nom = strtoupper($need['nom']);
345
-			  $compat = isset($need['compatibilite']) ? $need['compatibilite'] : '';
346
-			  if (!isset($liste[$nom]) OR !plugin_version_compatible($compat,$liste[$nom]['version'])) {
347
-			      $info1 = false;
348
-			      break;
349
-			  }
350
-			}
351
-			if (!$info1) continue;
352
-			// idem si des plugins sont utiles,
353
-			// sauf si ils sont de toute facon absents de la liste
354
-			foreach($info1['utilise'] as $need){
355
-			  $nom = strtoupper($need['nom']);
356
-			  $compat = isset($need['compatibilite']) ? $need['compatibilite'] : '';
357
-			  if (isset($toute_la_liste[$nom])) {
358
-			    if (!isset($liste[$nom]) OR 
359
-				!plugin_version_compatible($compat, $liste[$nom]['version'])) {
360
-			      $info1 = false;
361
-			      break;
362
-			    }
363
-			  }
364
-			}
365
-			if ($info1) {
366
-			  $ordre[$p] = $info1;
367
-			  $liste[$p] = $liste_non_classee[$p];
368
-			  unset($liste_non_classee[$p]);
369
-			}
370
-		}
371
-	}
372
-	return array($liste, $ordre, $liste_non_classee);
331
+    $toute_la_liste = $liste_non_classee;
332
+    $liste = $ordre = array();
333
+    $count = 0;
334
+    while ($c=count($liste_non_classee) AND $c!=$count){ // tant qu'il reste des plugins a classer, et qu'on ne stagne pas
335
+        #echo "tour::";var_dump($liste_non_classee);
336
+        $count = $c;
337
+        foreach($liste_non_classee as $p=>$resume) {
338
+            $plug = $resume['dir'];
339
+            $dir_type = $resume['dir_type'];
340
+            $info1 = $infos[$dir_type][$plug];
341
+            // si des plugins sont necessaires,
342
+            // on ne peut inserer qu'apres eux
343
+            foreach($info1['necessite'] as $need){
344
+                $nom = strtoupper($need['nom']);
345
+                $compat = isset($need['compatibilite']) ? $need['compatibilite'] : '';
346
+                if (!isset($liste[$nom]) OR !plugin_version_compatible($compat,$liste[$nom]['version'])) {
347
+                    $info1 = false;
348
+                    break;
349
+                }
350
+            }
351
+            if (!$info1) continue;
352
+            // idem si des plugins sont utiles,
353
+            // sauf si ils sont de toute facon absents de la liste
354
+            foreach($info1['utilise'] as $need){
355
+                $nom = strtoupper($need['nom']);
356
+                $compat = isset($need['compatibilite']) ? $need['compatibilite'] : '';
357
+                if (isset($toute_la_liste[$nom])) {
358
+                if (!isset($liste[$nom]) OR 
359
+                !plugin_version_compatible($compat, $liste[$nom]['version'])) {
360
+                    $info1 = false;
361
+                    break;
362
+                }
363
+                }
364
+            }
365
+            if ($info1) {
366
+                $ordre[$p] = $info1;
367
+                $liste[$p] = $liste_non_classee[$p];
368
+                unset($liste_non_classee[$p]);
369
+            }
370
+        }
371
+    }
372
+    return array($liste, $ordre, $liste_non_classee);
373 373
 }
374 374
 
375 375
 // Collecte les erreurs dans la meta 
376 376
 
377 377
 function plugins_erreurs($liste_non_classee, $liste, $infos, $msg=array())
378 378
 {
379
-	static $erreurs = array();
380
-	foreach($liste_non_classee as $p=>$resume){
381
-		$dir_type = $resume['dir_type'];
382
-		$plug = $resume['dir'];
383
-		$k = $infos[$dir_type][$plug];
384
-		$plug = constant($dir_type) . $plug;
385
-		if (!isset($msg[$p])) {
386
-		  if (!$msg[$p] = plugin_necessite($k['necessite'], $liste))
387
-		    $msg[$p] = plugin_necessite($k['utilise'], $liste);
388
-		} else {
389
-		  foreach($msg[$p] as $c => $l)
390
-		    $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']);
391
-		}
392
-		$erreurs[$plug] = $msg[$p];
393
-	}
394
-	ecrire_meta('plugin_erreur_activation',	serialize($erreurs));
379
+    static $erreurs = array();
380
+    foreach($liste_non_classee as $p=>$resume){
381
+        $dir_type = $resume['dir_type'];
382
+        $plug = $resume['dir'];
383
+        $k = $infos[$dir_type][$plug];
384
+        $plug = constant($dir_type) . $plug;
385
+        if (!isset($msg[$p])) {
386
+            if (!$msg[$p] = plugin_necessite($k['necessite'], $liste))
387
+            $msg[$p] = plugin_necessite($k['utilise'], $liste);
388
+        } else {
389
+            foreach($msg[$p] as $c => $l)
390
+            $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']);
391
+        }
392
+        $erreurs[$plug] = $msg[$p];
393
+    }
394
+    ecrire_meta('plugin_erreur_activation',	serialize($erreurs));
395 395
 }
396 396
 
397 397
 function plugin_donne_erreurs($raw=false, $raz=true) {
398
-	if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) return $raw?array():'';
399
-	$list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']);
400
-	// Compat ancienne version
401
-	if (!$list)
402
-	  $list = $raw?array():$GLOBALS['meta']['plugin_erreur_activation'];
403
-	elseif(!$raw) {
404
-	  foreach($list as $plug => $msg)
405
-	    $list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug))
406
-		  . "<ul><li>" . implode("</li><li>", $msg) . "</li></ul></li>";
407
-	  $list ="<ul>" . join("\n", $list) . "</ul>";
408
-	}
409
-	if ($raz)
410
-		effacer_meta('plugin_erreur_activation');
411
-	return $list;
398
+    if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) return $raw?array():'';
399
+    $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']);
400
+    // Compat ancienne version
401
+    if (!$list)
402
+        $list = $raw?array():$GLOBALS['meta']['plugin_erreur_activation'];
403
+    elseif(!$raw) {
404
+        foreach($list as $plug => $msg)
405
+        $list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug))
406
+            . "<ul><li>" . implode("</li><li>", $msg) . "</li></ul></li>";
407
+        $list ="<ul>" . join("\n", $list) . "</ul>";
408
+    }
409
+    if ($raz)
410
+        effacer_meta('plugin_erreur_activation');
411
+    return $list;
412 412
 }
413 413
 
414 414
 /**
@@ -425,14 +425,14 @@  discard block
 block discarded – undo
425 425
  * 
426 426
 **/
427 427
 function plugin_necessite($n, $liste) {
428
-	$msg = array();
429
-	foreach($n as $need){
430
-		$id = strtoupper($need['nom']);
431
-		if ($r = plugin_controler_necessite($liste, $id, $need['compatibilite'])) {
432
-			$msg[] = $r;
433
-		}
434
-	}
435
-	return $msg;
428
+    $msg = array();
429
+    foreach($n as $need){
430
+        $id = strtoupper($need['nom']);
431
+        if ($r = plugin_controler_necessite($liste, $id, $need['compatibilite'])) {
432
+            $msg[] = $r;
433
+        }
434
+    }
435
+    return $msg;
436 436
 }
437 437
 
438 438
 /**
@@ -450,34 +450,34 @@  discard block
 block discarded – undo
450 450
 **/
451 451
 function plugin_controler_necessite($liste, $nom, $version)
452 452
 {
453
-	if (isset($liste[$nom]) AND plugin_version_compatible($version,$liste[$nom]['version'])) {
454
-		return '';
455
-	}
456
-	// retrouver le minimum
457
-	if (preg_match(_EXTRAIRE_INTERVALLE, $version, $regs)) {
458
-		$minimum = $regs[1];
459
-		if ($minimum) {
460
-			return _T('plugin_necessite_plugin', array(
461
-				'plugin' => $nom,
462
-				'version' => $minimum));
463
-		}
464
-	}
465
-	return _T('plugin_necessite_plugin_sans_version', array('plugin' => $nom));
453
+    if (isset($liste[$nom]) AND plugin_version_compatible($version,$liste[$nom]['version'])) {
454
+        return '';
455
+    }
456
+    // retrouver le minimum
457
+    if (preg_match(_EXTRAIRE_INTERVALLE, $version, $regs)) {
458
+        $minimum = $regs[1];
459
+        if ($minimum) {
460
+            return _T('plugin_necessite_plugin', array(
461
+                'plugin' => $nom,
462
+                'version' => $minimum));
463
+        }
464
+    }
465
+    return _T('plugin_necessite_plugin_sans_version', array('plugin' => $nom));
466 466
 }
467 467
 
468 468
 function plugin_controler_lib($lib, $url)
469 469
 {
470
-	/* Feature sortie du core, voir STP
470
+    /* Feature sortie du core, voir STP
471 471
 	 * if ($url) {
472 472
 		include_spip('inc/charger_plugin');
473 473
 		$url = '<br />'	. bouton_telechargement_plugin($url, 'lib');
474 474
 	}*/
475
-	return _T('plugin_necessite_lib', array('lib'=>$lib)) . " <a href='$url'>$url</a>";
475
+    return _T('plugin_necessite_lib', array('lib'=>$lib)) . " <a href='$url'>$url</a>";
476 476
 }
477 477
 
478 478
 // Pour compatibilite et lisibilite du code
479 479
 function actualise_plugins_actifs($pipe_recherche = false){
480
-	return ecrire_plugin_actifs('', $pipe_recherche, 'force');
480
+    return ecrire_plugin_actifs('', $pipe_recherche, 'force');
481 481
 }
482 482
 
483 483
 // mise a jour du meta en fonction de l'etat du repertoire
@@ -488,210 +488,210 @@  discard block
 block discarded – undo
488 488
 // http://doc.spip.org/@ecrire_plugin_actifs
489 489
 function ecrire_plugin_actifs($plugin,$pipe_recherche=false,$operation='raz') {
490 490
 
491
-	// creer le repertoire cache/ si necessaire ! (installation notamment)
492
-	sous_repertoire(_DIR_CACHE, '', false,true);
491
+    // creer le repertoire cache/ si necessaire ! (installation notamment)
492
+    sous_repertoire(_DIR_CACHE, '', false,true);
493 493
 	
494
-	if (!spip_connect()) return false;
495
-	if ($operation!='raz') {
496
-		$plugin_valides = liste_chemin_plugin_actifs();
497
-		$plugin_valides = is_plugin_dir($plugin_valides);
498
-		if(defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL){
499
-			$plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL);
500
-			$plugin_valides_supp = is_plugin_dir($plugin_valides_supp,_DIR_PLUGINS_SUPPL);
501
-			$plugin_valides = array_merge($plugin_valides,$plugin_valides_supp);
502
-		}
503
-		// si des plugins sont en attentes (coches mais impossible a activer)
504
-		// on les reinjecte ici
505
-		if (isset($GLOBALS['meta']['plugin_attente'])
506
-		  AND $a = unserialize($GLOBALS['meta']['plugin_attente']))
507
-		$plugin_valides = $plugin_valides + liste_chemin_plugin($a);
494
+    if (!spip_connect()) return false;
495
+    if ($operation!='raz') {
496
+        $plugin_valides = liste_chemin_plugin_actifs();
497
+        $plugin_valides = is_plugin_dir($plugin_valides);
498
+        if(defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL){
499
+            $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL);
500
+            $plugin_valides_supp = is_plugin_dir($plugin_valides_supp,_DIR_PLUGINS_SUPPL);
501
+            $plugin_valides = array_merge($plugin_valides,$plugin_valides_supp);
502
+        }
503
+        // si des plugins sont en attentes (coches mais impossible a activer)
504
+        // on les reinjecte ici
505
+        if (isset($GLOBALS['meta']['plugin_attente'])
506
+          AND $a = unserialize($GLOBALS['meta']['plugin_attente']))
507
+        $plugin_valides = $plugin_valides + liste_chemin_plugin($a);
508 508
 		
509
-		if ($operation=='ajoute')
510
-			$plugin = array_merge($plugin_valides,$plugin);
511
-		elseif ($operation=='enleve')
512
-			$plugin = array_diff($plugin_valides,$plugin);
513
-		else $plugin = $plugin_valides;
514
-	}
515
-	$actifs_avant = $GLOBALS['meta']['plugin'];
516
-
517
-	// si une fonction de gestion de dependances existe, l'appeler ici
518
-	if ($ajouter_dependances = charger_fonction("ajouter_dependances","plugins",true)){
519
-		$plugin = $ajouter_dependances($plugin);
520
-	}
521
-
522
-	// recharger le xml des plugins a activer
523
-	// on forcer le reload ici, meme si le fichier xml n'a pas change
524
-	// pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations
525
-	// pourra etre evite quand on ne supportera plus les plugin.xml
526
-	// en deplacant la detection de ces fichiers dans la compilation ci dessous
527
-	list($infos,$liste) = liste_plugin_valides($plugin,true);
528
-	// trouver l'ordre d'activation
529
-	list($plugin_valides,$ordre,$reste) = plugin_trier($infos, $liste);
530
-	if ($reste) plugins_erreurs($reste, $liste, $infos);
531
-	// Ignorer les plugins necessitant une lib absente
532
-	// et preparer la meta d'entete Http
533
-	$err = $msg = $header = array();
534
-	foreach($plugin_valides as $p => $resume) {
535
-		$header[]= $p.($resume['version']?"(".$resume['version'].")":"");
536
-		if ($resume['dir']){ 
537
-			foreach($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) {
538
-				if (!find_in_path($l['nom'], 'lib/')) {
539
-					$err[$p] = $resume;
540
-					$msg[$p][] = $l;
541
-					unset($plugin_valides[$p]);
542
-				}
543
-			}
544
-		}
545
-	}
546
-	if ($err) plugins_erreurs($err, '', $infos, $msg);
547
-
548
-	if (isset($GLOBALS['meta']['message_crash_plugins']))
549
-		effacer_meta('message_crash_plugins');
550
-	ecrire_meta('plugin',serialize($plugin_valides));
551
-	$liste = array_diff_key($liste,$plugin_valides);
552
-	ecrire_meta('plugin_attente',serialize($liste));
553
-	$header = strtolower(implode(",",$header));
554
-	ecrire_meta('plugin_header',substr($header,0,900));
555
-	if (!isset($GLOBALS['spip_header_silencieux']) OR !$GLOBALS['spip_header_silencieux'])
556
-		ecrire_fichier(_DIR_VAR."config.txt", (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY:"Composed-By: SPIP") . ' '. $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header);
557
-	else
558
-		@unlink(_DIR_VAR."config.txt");
559
-	// generer charger_plugins_chemin.php
560
-	plugins_precompile_chemin($plugin_valides, $ordre);
561
-	// generer les fichiers
562
-	// 	charger_plugins_options.php
563
-	// 	charger_plugins_fonctions.php
564
-	// et retourner les fichiers a verifier
565
-	plugins_precompile_xxxtions($plugin_valides, $ordre);
566
-	// mise a jour de la matrice des pipelines
567
-	pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche);
568
-	// generer le fichier _CACHE_PIPELINE
569
-	pipeline_precompile();
570
-
571
-	// attendre eventuellement l'invalidation du cache opcode
572
-	spip_attend_invalidation_opcode_cache();
573
-
574
-	if (spip_connect()) {
575
-		// lancer et initialiser les nouveaux crons !
576
-		include_spip('inc/genie');
577
-		genie_queue_watch_dist();
578
-	}
579
-
580
-	return ($GLOBALS['meta']['plugin'] != $actifs_avant);
509
+        if ($operation=='ajoute')
510
+            $plugin = array_merge($plugin_valides,$plugin);
511
+        elseif ($operation=='enleve')
512
+            $plugin = array_diff($plugin_valides,$plugin);
513
+        else $plugin = $plugin_valides;
514
+    }
515
+    $actifs_avant = $GLOBALS['meta']['plugin'];
516
+
517
+    // si une fonction de gestion de dependances existe, l'appeler ici
518
+    if ($ajouter_dependances = charger_fonction("ajouter_dependances","plugins",true)){
519
+        $plugin = $ajouter_dependances($plugin);
520
+    }
521
+
522
+    // recharger le xml des plugins a activer
523
+    // on forcer le reload ici, meme si le fichier xml n'a pas change
524
+    // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations
525
+    // pourra etre evite quand on ne supportera plus les plugin.xml
526
+    // en deplacant la detection de ces fichiers dans la compilation ci dessous
527
+    list($infos,$liste) = liste_plugin_valides($plugin,true);
528
+    // trouver l'ordre d'activation
529
+    list($plugin_valides,$ordre,$reste) = plugin_trier($infos, $liste);
530
+    if ($reste) plugins_erreurs($reste, $liste, $infos);
531
+    // Ignorer les plugins necessitant une lib absente
532
+    // et preparer la meta d'entete Http
533
+    $err = $msg = $header = array();
534
+    foreach($plugin_valides as $p => $resume) {
535
+        $header[]= $p.($resume['version']?"(".$resume['version'].")":"");
536
+        if ($resume['dir']){ 
537
+            foreach($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) {
538
+                if (!find_in_path($l['nom'], 'lib/')) {
539
+                    $err[$p] = $resume;
540
+                    $msg[$p][] = $l;
541
+                    unset($plugin_valides[$p]);
542
+                }
543
+            }
544
+        }
545
+    }
546
+    if ($err) plugins_erreurs($err, '', $infos, $msg);
547
+
548
+    if (isset($GLOBALS['meta']['message_crash_plugins']))
549
+        effacer_meta('message_crash_plugins');
550
+    ecrire_meta('plugin',serialize($plugin_valides));
551
+    $liste = array_diff_key($liste,$plugin_valides);
552
+    ecrire_meta('plugin_attente',serialize($liste));
553
+    $header = strtolower(implode(",",$header));
554
+    ecrire_meta('plugin_header',substr($header,0,900));
555
+    if (!isset($GLOBALS['spip_header_silencieux']) OR !$GLOBALS['spip_header_silencieux'])
556
+        ecrire_fichier(_DIR_VAR."config.txt", (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY:"Composed-By: SPIP") . ' '. $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header);
557
+    else
558
+        @unlink(_DIR_VAR."config.txt");
559
+    // generer charger_plugins_chemin.php
560
+    plugins_precompile_chemin($plugin_valides, $ordre);
561
+    // generer les fichiers
562
+    // 	charger_plugins_options.php
563
+    // 	charger_plugins_fonctions.php
564
+    // et retourner les fichiers a verifier
565
+    plugins_precompile_xxxtions($plugin_valides, $ordre);
566
+    // mise a jour de la matrice des pipelines
567
+    pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche);
568
+    // generer le fichier _CACHE_PIPELINE
569
+    pipeline_precompile();
570
+
571
+    // attendre eventuellement l'invalidation du cache opcode
572
+    spip_attend_invalidation_opcode_cache();
573
+
574
+    if (spip_connect()) {
575
+        // lancer et initialiser les nouveaux crons !
576
+        include_spip('inc/genie');
577
+        genie_queue_watch_dist();
578
+    }
579
+
580
+    return ($GLOBALS['meta']['plugin'] != $actifs_avant);
581 581
 }
582 582
 
583 583
 function plugins_precompile_chemin($plugin_valides, $ordre)
584 584
 {
585
-	$chemins = array();
586
-	$contenu = "";
587
-	foreach($ordre as $p => $info){
588
-		// $ordre peur contenir des plugins en attente et non valides pour ce hit
589
-		if (isset($plugin_valides[$p])){
590
-			$dir_type = $plugin_valides[$p]['dir_type'];
591
-			$plug = $plugin_valides[$p]['dir'];
592
-			// definir le plugin, donc le path avant l'include du fichier options
593
-			// permet de faire des include_spip pour attraper un inc_ du plugin
594
-
595
-			$dir = $dir_type.".'" . $plug ."/'";
585
+    $chemins = array();
586
+    $contenu = "";
587
+    foreach($ordre as $p => $info){
588
+        // $ordre peur contenir des plugins en attente et non valides pour ce hit
589
+        if (isset($plugin_valides[$p])){
590
+            $dir_type = $plugin_valides[$p]['dir_type'];
591
+            $plug = $plugin_valides[$p]['dir'];
592
+            // definir le plugin, donc le path avant l'include du fichier options
593
+            // permet de faire des include_spip pour attraper un inc_ du plugin
594
+
595
+            $dir = $dir_type.".'" . $plug ."/'";
596 596
 			
597
-			$prefix = strtoupper(preg_replace(',\W,','_',$info['prefix']));
598
-			if ($prefix!=="SPIP"){
599
-				$contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n";
600
-				foreach($info['chemin'] as $chemin){
601
-					if (!isset($chemin['version']) OR plugin_version_compatible($chemin['version'],$GLOBALS['spip_version_branche'],'spip')){
602
-						$dir = $chemin['path'];
603
-						if (strlen($dir) AND $dir{0}=="/") $dir = substr($dir,1);
604
-						if (strlen($dir) AND $dir=="./") $dir = '';
605
-						if (strlen($dir)) $dir = rtrim($dir,'/').'/';
606
-						if (!isset($chemin['type']) OR $chemin['type']=='public')
607
-							$chemins['public'][]="_DIR_PLUGIN_$prefix".(strlen($dir)?".'$dir'":"");
608
-						if (!isset($chemin['type']) OR $chemin['type']=='prive')
609
-							$chemins['prive'][]="_DIR_PLUGIN_$prefix".(strlen($dir)?".'$dir'":"");
610
-					}
611
-				}
612
-			}
613
-		}
614
-	}
615
-	if (count($chemins)){
616
-		$contenu .= "if (_DIR_RESTREINT) _chemin(implode(':',array(".implode(',',array_reverse($chemins['public'])).")));\n"
617
-		  . "else _chemin(implode(':',array(".implode(',',array_reverse($chemins['prive'])).")));\n";
618
-	}
619
-
620
-	ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu);
597
+            $prefix = strtoupper(preg_replace(',\W,','_',$info['prefix']));
598
+            if ($prefix!=="SPIP"){
599
+                $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n";
600
+                foreach($info['chemin'] as $chemin){
601
+                    if (!isset($chemin['version']) OR plugin_version_compatible($chemin['version'],$GLOBALS['spip_version_branche'],'spip')){
602
+                        $dir = $chemin['path'];
603
+                        if (strlen($dir) AND $dir{0}=="/") $dir = substr($dir,1);
604
+                        if (strlen($dir) AND $dir=="./") $dir = '';
605
+                        if (strlen($dir)) $dir = rtrim($dir,'/').'/';
606
+                        if (!isset($chemin['type']) OR $chemin['type']=='public')
607
+                            $chemins['public'][]="_DIR_PLUGIN_$prefix".(strlen($dir)?".'$dir'":"");
608
+                        if (!isset($chemin['type']) OR $chemin['type']=='prive')
609
+                            $chemins['prive'][]="_DIR_PLUGIN_$prefix".(strlen($dir)?".'$dir'":"");
610
+                    }
611
+                }
612
+            }
613
+        }
614
+    }
615
+    if (count($chemins)){
616
+        $contenu .= "if (_DIR_RESTREINT) _chemin(implode(':',array(".implode(',',array_reverse($chemins['public'])).")));\n"
617
+            . "else _chemin(implode(':',array(".implode(',',array_reverse($chemins['prive'])).")));\n";
618
+    }
619
+
620
+    ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu);
621 621
 }
622 622
 
623 623
 function plugins_precompile_xxxtions($plugin_valides, $ordre)
624 624
 {
625
-	$contenu = array('options' => '', 'fonctions' =>'');
626
-	$boutons = array();
627
-	$onglets = array();
628
-	$sign = "";
629
-
630
-	foreach($ordre as $p => $info){
631
-		// $ordre peur contenir des plugins en attente et non valides pour ce hit
632
-		if (isset($plugin_valides[$p])){
633
-			$dir_type = $plugin_valides[$p]['dir_type'];
634
-			$plug = $plugin_valides[$p]['dir'];
635
-			$dir = constant($dir_type);
636
-			$root_dir_type = str_replace('_DIR_','_ROOT_',$dir_type);
637
-			if ($info['menu'])
638
-				$boutons = array_merge($boutons,$info['menu']);
639
-			if ($info['onglet'])
640
-				$onglets = array_merge($onglets,$info['onglet']);
641
-			foreach($contenu as $charge => $v){
642
-				// si pas declare/detecte a la lecture du paquet.xml,
643
-				// detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml
644
-				// donc ni sa relecture, ni sa detection
645
-				if (!isset($info[$charge])
646
-					AND $dir // exclure le cas du plugin "SPIP"
647
-					AND strpos($dir,":")===false // exclure le cas des procure:
648
-					AND file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml
649
-					){
650
-					if (is_readable("$dir$plug/".($file=$info['prefix']."_".$charge.".php"))){
651
-						$info[$charge] = array($file);
652
-					}
653
-				}
654
-				if (isset($info[$charge])){
655
-					$files = $info[$charge];
656
-					foreach($files as $k=>$file){
657
-						// on genere un if file_exists devant chaque include
658
-						// pour pouvoir garder le meme niveau d'erreur general
659
-						$file = trim($file);
660
-						if (!is_readable("$dir$plug/$file")
661
-							// uniquement pour les paquet.xml
662
-							AND file_exists("$dir$plug/paquet.xml")){
663
-							unset($info[$charge][$k]);
664
-						}
665
-						else {
666
-							$_file = $root_dir_type . ".'$plug/$file'";
667
-							$contenu[$charge] .= "include_once_check($_file);\n";
668
-						}
669
-					}
670
-				}
671
-			}
672
-			$sign .= md5(serialize($info));
673
-		}
674
-	}
675
-
676
-	$contenu['options'] = "define('_PLUGINS_HASH','".md5($sign)."');\n" . $contenu['options'];
677
-	$contenu['fonctions'] .= plugin_ongletbouton("boutons_plugins", $boutons)
678
-	. plugin_ongletbouton("onglets_plugins", $onglets);
679
-
680
-	ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']);
681
-	ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']);
625
+    $contenu = array('options' => '', 'fonctions' =>'');
626
+    $boutons = array();
627
+    $onglets = array();
628
+    $sign = "";
629
+
630
+    foreach($ordre as $p => $info){
631
+        // $ordre peur contenir des plugins en attente et non valides pour ce hit
632
+        if (isset($plugin_valides[$p])){
633
+            $dir_type = $plugin_valides[$p]['dir_type'];
634
+            $plug = $plugin_valides[$p]['dir'];
635
+            $dir = constant($dir_type);
636
+            $root_dir_type = str_replace('_DIR_','_ROOT_',$dir_type);
637
+            if ($info['menu'])
638
+                $boutons = array_merge($boutons,$info['menu']);
639
+            if ($info['onglet'])
640
+                $onglets = array_merge($onglets,$info['onglet']);
641
+            foreach($contenu as $charge => $v){
642
+                // si pas declare/detecte a la lecture du paquet.xml,
643
+                // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml
644
+                // donc ni sa relecture, ni sa detection
645
+                if (!isset($info[$charge])
646
+                    AND $dir // exclure le cas du plugin "SPIP"
647
+                    AND strpos($dir,":")===false // exclure le cas des procure:
648
+                    AND file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml
649
+                    ){
650
+                    if (is_readable("$dir$plug/".($file=$info['prefix']."_".$charge.".php"))){
651
+                        $info[$charge] = array($file);
652
+                    }
653
+                }
654
+                if (isset($info[$charge])){
655
+                    $files = $info[$charge];
656
+                    foreach($files as $k=>$file){
657
+                        // on genere un if file_exists devant chaque include
658
+                        // pour pouvoir garder le meme niveau d'erreur general
659
+                        $file = trim($file);
660
+                        if (!is_readable("$dir$plug/$file")
661
+                            // uniquement pour les paquet.xml
662
+                            AND file_exists("$dir$plug/paquet.xml")){
663
+                            unset($info[$charge][$k]);
664
+                        }
665
+                        else {
666
+                            $_file = $root_dir_type . ".'$plug/$file'";
667
+                            $contenu[$charge] .= "include_once_check($_file);\n";
668
+                        }
669
+                    }
670
+                }
671
+            }
672
+            $sign .= md5(serialize($info));
673
+        }
674
+    }
675
+
676
+    $contenu['options'] = "define('_PLUGINS_HASH','".md5($sign)."');\n" . $contenu['options'];
677
+    $contenu['fonctions'] .= plugin_ongletbouton("boutons_plugins", $boutons)
678
+    . plugin_ongletbouton("onglets_plugins", $onglets);
679
+
680
+    ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']);
681
+    ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']);
682 682
 }
683 683
 
684 684
 function plugin_ongletbouton($nom, $val)
685 685
 {
686
-	if (!$val) $val = array();
687
-	define("_UPDATED_$nom",$val = serialize($val));
688
-	define("_UPDATED_md5_$nom",$md5=md5($val));
689
-	$val = "unserialize('".str_replace("'","\'",$val)."')";
690
-	return
691
-		"if (!function_exists('$nom')) {\n"
692
-	 ."function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n"
693
-		."function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'".$md5."';}\n"
694
-	 ."}\n";
686
+    if (!$val) $val = array();
687
+    define("_UPDATED_$nom",$val = serialize($val));
688
+    define("_UPDATED_md5_$nom",$md5=md5($val));
689
+    $val = "unserialize('".str_replace("'","\'",$val)."')";
690
+    return
691
+        "if (!function_exists('$nom')) {\n"
692
+        ."function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n"
693
+        ."function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'".$md5."';}\n"
694
+        ."}\n";
695 695
 }
696 696
 
697 697
 // creer le fichier CACHE_PLUGIN_VERIF a partir de
@@ -700,146 +700,146 @@  discard block
 block discarded – undo
700 700
 
701 701
 function pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche)
702 702
 {
703
-	static $liste_pipe_manquants=array();
704
-	if (($pipe_recherche)&&(!in_array($pipe_recherche,$liste_pipe_manquants)))
705
-		$liste_pipe_manquants[]=$pipe_recherche;
706
-
707
-	foreach($ordre as $p => $info){
708
-		// $ordre peur contenir des plugins en attente et non valides pour ce hit
709
-		if (isset($plugin_valides[$p])){
710
-			$dir_type = $plugin_valides[$p]['dir_type'];
711
-			$root_dir_type = str_replace('_DIR_','_ROOT_',$dir_type);
712
-			$plug = $plugin_valides[$p]['dir'];
713
-			$prefix = (($info['prefix']=="spip")?"":$info['prefix']."_");
714
-			if (isset($info['pipeline']) AND is_array($info['pipeline'])){
715
-				foreach($info['pipeline'] as $pipe){
716
-					$nom = $pipe['nom'];
717
-					if (isset($pipe['action']))
718
-							$action = $pipe['action'];
719
-					else
720
-							$action = $nom;
721
-					$nomlower = strtolower($nom);
722
-					if ($nomlower!=$nom
723
-					AND isset($GLOBALS['spip_pipeline'][$nom])
724
-					AND !isset($GLOBALS['spip_pipeline'][$nomlower])){
725
-						$GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom];
726
-						unset($GLOBALS['spip_pipeline'][$nom]);
727
-					}
728
-					$nom = $nomlower;
729
-					// une action vide est une declaration qui ne doit pas etre compilee !
730
-					if (!isset($GLOBALS['spip_pipeline'][$nom])) // creer le pipeline eventuel
731
-						$GLOBALS['spip_pipeline'][$nom]="";
732
-					if ($action){
733
-						if (strpos($GLOBALS['spip_pipeline'][$nom],"|$prefix$action")===FALSE)
734
-							$GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),","|$prefix$action\\1",$GLOBALS['spip_pipeline'][$nom],1);
735
-						if (isset($pipe['inclure'])){
736
-							$GLOBALS['spip_matrice']["$prefix$action"] =
737
-								"$root_dir_type:$plug/".$pipe['inclure'];
738
-						}
739
-					}
740
-				}
741
-			}
742
-		}
743
-	}
703
+    static $liste_pipe_manquants=array();
704
+    if (($pipe_recherche)&&(!in_array($pipe_recherche,$liste_pipe_manquants)))
705
+        $liste_pipe_manquants[]=$pipe_recherche;
706
+
707
+    foreach($ordre as $p => $info){
708
+        // $ordre peur contenir des plugins en attente et non valides pour ce hit
709
+        if (isset($plugin_valides[$p])){
710
+            $dir_type = $plugin_valides[$p]['dir_type'];
711
+            $root_dir_type = str_replace('_DIR_','_ROOT_',$dir_type);
712
+            $plug = $plugin_valides[$p]['dir'];
713
+            $prefix = (($info['prefix']=="spip")?"":$info['prefix']."_");
714
+            if (isset($info['pipeline']) AND is_array($info['pipeline'])){
715
+                foreach($info['pipeline'] as $pipe){
716
+                    $nom = $pipe['nom'];
717
+                    if (isset($pipe['action']))
718
+                            $action = $pipe['action'];
719
+                    else
720
+                            $action = $nom;
721
+                    $nomlower = strtolower($nom);
722
+                    if ($nomlower!=$nom
723
+                    AND isset($GLOBALS['spip_pipeline'][$nom])
724
+                    AND !isset($GLOBALS['spip_pipeline'][$nomlower])){
725
+                        $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom];
726
+                        unset($GLOBALS['spip_pipeline'][$nom]);
727
+                    }
728
+                    $nom = $nomlower;
729
+                    // une action vide est une declaration qui ne doit pas etre compilee !
730
+                    if (!isset($GLOBALS['spip_pipeline'][$nom])) // creer le pipeline eventuel
731
+                        $GLOBALS['spip_pipeline'][$nom]="";
732
+                    if ($action){
733
+                        if (strpos($GLOBALS['spip_pipeline'][$nom],"|$prefix$action")===FALSE)
734
+                            $GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),","|$prefix$action\\1",$GLOBALS['spip_pipeline'][$nom],1);
735
+                        if (isset($pipe['inclure'])){
736
+                            $GLOBALS['spip_matrice']["$prefix$action"] =
737
+                                "$root_dir_type:$plug/".$pipe['inclure'];
738
+                        }
739
+                    }
740
+                }
741
+            }
742
+        }
743
+    }
744 744
 	
745
-	// on charge les fichiers d'options qui peuvent completer 
746
-	// la globale spip_pipeline egalement
747
-	if (@is_readable(_CACHE_PLUGINS_PATH))
748
-		include_once(_CACHE_PLUGINS_PATH); // securite : a priori n'a pu etre fait plus tot 
749
-	if (@is_readable(_CACHE_PLUGINS_OPT)) {
750
-		include_once(_CACHE_PLUGINS_OPT);
751
-	} else {
752
-		spip_log("pipelines desactives: impossible de produire " . _CACHE_PLUGINS_OPT);
753
-	}
745
+    // on charge les fichiers d'options qui peuvent completer 
746
+    // la globale spip_pipeline egalement
747
+    if (@is_readable(_CACHE_PLUGINS_PATH))
748
+        include_once(_CACHE_PLUGINS_PATH); // securite : a priori n'a pu etre fait plus tot 
749
+    if (@is_readable(_CACHE_PLUGINS_OPT)) {
750
+        include_once(_CACHE_PLUGINS_OPT);
751
+    } else {
752
+        spip_log("pipelines desactives: impossible de produire " . _CACHE_PLUGINS_OPT);
753
+    }
754 754
 	
755
-	// on ajoute les pipe qui ont ete recenses manquants
756
-	foreach($liste_pipe_manquants as $add_pipe)
757
-		if (!isset($GLOBALS['spip_pipeline'][$add_pipe]))
758
-			$GLOBALS['spip_pipeline'][$add_pipe]= '';
755
+    // on ajoute les pipe qui ont ete recenses manquants
756
+    foreach($liste_pipe_manquants as $add_pipe)
757
+        if (!isset($GLOBALS['spip_pipeline'][$add_pipe]))
758
+            $GLOBALS['spip_pipeline'][$add_pipe]= '';
759 759
 }
760 760
 
761 761
 // precompilation des pipelines
762 762
 // http://doc.spip.org/@pipeline_precompile
763 763
 function pipeline_precompile(){
764
-	global $spip_pipeline, $spip_matrice;
765
-
766
-	$content = "";
767
-	foreach($spip_pipeline as $action=>$pipeline){
768
-		$s_inc = "";
769
-		$s_call = "";
770
-		$pipe = array_filter(explode('|',$pipeline));
771
-		// Eclater le pipeline en filtres et appliquer chaque filtre
772
-		foreach ($pipe as $fonc) {
773
-			$fonc = trim($fonc);
774
-			$s_call .= '$val = minipipe(\''.$fonc.'\', $val);'."\n";
775
-			if (isset($spip_matrice[$fonc])){
776
-				$file = $spip_matrice[$fonc];
777
-				$file = "'$file'";
778
-				// si un _DIR_XXX: est dans la chaine, on extrait la constante
779
-				if (preg_match(",(_(DIR|ROOT)_[A-Z_]+):,Ums",$file,$regs)){
780
-					$dir = $regs[1];
781
-					$root_dir = str_replace('_DIR_','_ROOT_',$dir);
782
-					if (defined($root_dir))
783
-						$dir = $root_dir;
784
-					$file = str_replace($regs[0],"'.".$dir.".'",$file);
785
-					$file = str_replace("''.","",$file);
786
-					$file = str_replace(constant($dir), '', $file);
787
-				}
788
-				$s_inc .= "include_once_check($file);\n";
789
-			}
790
-		}
791
-		if (strlen($s_inc))
792
-			$s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n";
793
-		$content .= "// Pipeline $action \n"
794
-		.	"function execute_pipeline_$action(&\$val){\n"
795
-		. $s_inc
796
-		. $s_call
797
-		. "return \$val;\n}\n";
798
-	}
799
-	ecrire_fichier_php(_CACHE_PIPELINES, $content);
800
-	clear_path_cache();
764
+    global $spip_pipeline, $spip_matrice;
765
+
766
+    $content = "";
767
+    foreach($spip_pipeline as $action=>$pipeline){
768
+        $s_inc = "";
769
+        $s_call = "";
770
+        $pipe = array_filter(explode('|',$pipeline));
771
+        // Eclater le pipeline en filtres et appliquer chaque filtre
772
+        foreach ($pipe as $fonc) {
773
+            $fonc = trim($fonc);
774
+            $s_call .= '$val = minipipe(\''.$fonc.'\', $val);'."\n";
775
+            if (isset($spip_matrice[$fonc])){
776
+                $file = $spip_matrice[$fonc];
777
+                $file = "'$file'";
778
+                // si un _DIR_XXX: est dans la chaine, on extrait la constante
779
+                if (preg_match(",(_(DIR|ROOT)_[A-Z_]+):,Ums",$file,$regs)){
780
+                    $dir = $regs[1];
781
+                    $root_dir = str_replace('_DIR_','_ROOT_',$dir);
782
+                    if (defined($root_dir))
783
+                        $dir = $root_dir;
784
+                    $file = str_replace($regs[0],"'.".$dir.".'",$file);
785
+                    $file = str_replace("''.","",$file);
786
+                    $file = str_replace(constant($dir), '', $file);
787
+                }
788
+                $s_inc .= "include_once_check($file);\n";
789
+            }
790
+        }
791
+        if (strlen($s_inc))
792
+            $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n";
793
+        $content .= "// Pipeline $action \n"
794
+        .	"function execute_pipeline_$action(&\$val){\n"
795
+        . $s_inc
796
+        . $s_call
797
+        . "return \$val;\n}\n";
798
+    }
799
+    ecrire_fichier_php(_CACHE_PIPELINES, $content);
800
+    clear_path_cache();
801 801
 }
802 802
 
803 803
 
804 804
 // http://doc.spip.org/@plugin_est_installe
805 805
 function plugin_est_installe($plug_path){
806
-	$plugin_installes = isset($GLOBALS['meta']['plugin_installes'])?unserialize($GLOBALS['meta']['plugin_installes']):array();
807
-	if (!$plugin_installes) return false;
808
-	return in_array($plug_path,$plugin_installes);
806
+    $plugin_installes = isset($GLOBALS['meta']['plugin_installes'])?unserialize($GLOBALS['meta']['plugin_installes']):array();
807
+    if (!$plugin_installes) return false;
808
+    return in_array($plug_path,$plugin_installes);
809 809
 }
810 810
 
811 811
 
812 812
 function plugin_installes_meta()
813 813
 {
814
-	$installer_plugins = charger_fonction('installer', 'plugins');
815
-	$meta_plug_installes = array();
816
-	foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix=>$resume) {
817
-		if ($plug = $resume['dir']){
818
-			$infos = $installer_plugins($plug, 'install', $resume['dir_type']);
819
-			if ($infos){
820
-				if (!is_array($infos) OR $infos['install_test'][0])
821
-					$meta_plug_installes[] = $plug;
822
-				if (is_array($infos)){
823
-					list($ok, $trace) = $infos['install_test'];
824
-					include_spip('inc/filtres_boites');
825
-					echo  "<div class='install-plugins svp_retour'>"
826
-						  .boite_ouvrir(_T('plugin_titre_installation', array('plugin' => typo($infos['nom']))), ($ok ? 'success' : 'error'))
827
-					      .$trace
828
-					      ."<div class='result'>"
829
-					      .($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T("plugin_info_upgrade_ok") : _T("plugin_info_install_ok")) : _T("avis_operation_echec"))
830
-					      ."</div>"
831
-					      .boite_fermer()
832
-					      ."</div>";
833
-				}
834
-			}
835
-		}
836
-	}
837
-	ecrire_meta('plugin_installes',serialize($meta_plug_installes),'non');
814
+    $installer_plugins = charger_fonction('installer', 'plugins');
815
+    $meta_plug_installes = array();
816
+    foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix=>$resume) {
817
+        if ($plug = $resume['dir']){
818
+            $infos = $installer_plugins($plug, 'install', $resume['dir_type']);
819
+            if ($infos){
820
+                if (!is_array($infos) OR $infos['install_test'][0])
821
+                    $meta_plug_installes[] = $plug;
822
+                if (is_array($infos)){
823
+                    list($ok, $trace) = $infos['install_test'];
824
+                    include_spip('inc/filtres_boites');
825
+                    echo  "<div class='install-plugins svp_retour'>"
826
+                            .boite_ouvrir(_T('plugin_titre_installation', array('plugin' => typo($infos['nom']))), ($ok ? 'success' : 'error'))
827
+                            .$trace
828
+                            ."<div class='result'>"
829
+                            .($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T("plugin_info_upgrade_ok") : _T("plugin_info_install_ok")) : _T("avis_operation_echec"))
830
+                            ."</div>"
831
+                            .boite_fermer()
832
+                            ."</div>";
833
+                }
834
+            }
835
+        }
836
+    }
837
+    ecrire_meta('plugin_installes',serialize($meta_plug_installes),'non');
838 838
 }
839 839
 
840 840
 function ecrire_fichier_php($nom, $contenu, $comment='')
841 841
 {
842
-	ecrire_fichier($nom, 
843
-		       '<'.'?php' . "\n" . $comment ."\nif (defined('_ECRIRE_INC_VERSION')) {\n". $contenu . "}\n?".'>');
842
+    ecrire_fichier($nom, 
843
+                '<'.'?php' . "\n" . $comment ."\nif (defined('_ECRIRE_INC_VERSION')) {\n". $contenu . "}\n?".'>');
844 844
 }
845 845
 
Please login to merge, or discard this patch.
Braces   +172 added lines, -99 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 // l'adresse du repertoire de telechargement et de decompactage des plugins
16 18
 define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS.'auto/');
@@ -25,8 +27,9 @@  discard block
 block discarded – undo
25 27
 // http://doc.spip.org/@liste_plugin_files
26 28
 function liste_plugin_files($dir_plugins = null){
27 29
 	static $plugin_files=array();
28
-	if (is_null($dir_plugins))
29
-		$dir_plugins = _DIR_PLUGINS;
30
+	if (is_null($dir_plugins)) {
31
+			$dir_plugins = _DIR_PLUGINS;
32
+	}
30 33
 	if (!isset($plugin_files[$dir_plugins])
31 34
 	OR count($plugin_files[$dir_plugins]) == 0){
32 35
 		$plugin_files[$dir_plugins] = array();
@@ -48,24 +51,29 @@  discard block
 block discarded – undo
48 51
 	// revenir au repertoire racine si on a recu dossier/truc
49 52
 	// pour regarder dossier/truc/ ne pas oublier le / final
50 53
 	$dir = preg_replace(',/[^/]*$,', '', $dir);
51
-	if ($dir == '') $dir = '.';
54
+	if ($dir == '') {
55
+	    $dir = '.';
56
+	}
52 57
 
53
-	if (!is_dir($dir))
54
-		return $fichiers;
58
+	if (!is_dir($dir)) {
59
+			return $fichiers;
60
+	}
55 61
 	if (is_plugin_dir($dir,'')) {
56 62
 		$fichiers[] = $dir;
57 63
 		return $fichiers;
58 64
 	}
59
-	if ($max_prof<=0)
60
-		return $fichiers;
65
+	if ($max_prof<=0) {
66
+			return $fichiers;
67
+	}
61 68
 
62 69
 	$subdirs = array();
63 70
 	if (@is_dir($dir) AND is_readable($dir) AND $d = @opendir($dir)) {
64 71
 		while (($f = readdir($d)) !== false) {
65 72
 			if ($f[0] != '.' # ignorer . .. .svn etc
66 73
 			AND $f != 'CVS'
67
-			AND is_dir($f = "$dir/$f"))
68
-				$subdirs[] = $f;
74
+			AND is_dir($f = "$dir/$f")) {
75
+							$subdirs[] = $f;
76
+			}
69 77
 		}
70 78
 		closedir($d);
71 79
 	}
@@ -79,13 +87,15 @@  discard block
 block discarded – undo
79 87
 function is_plugin_dir($dir,$dir_plugins = null){
80 88
 	if (is_array($dir)){
81 89
 		foreach($dir as $k=>$d){
82
-			if (!is_plugin_dir($d,$dir_plugins))
83
-				unset($dir[$k]);
90
+			if (!is_plugin_dir($d,$dir_plugins)) {
91
+							unset($dir[$k]);
92
+			}
84 93
 		}
85 94
 		return $dir;
86 95
 	}
87
-	if (is_null($dir_plugins))
88
-		$dir_plugins = _DIR_PLUGINS;
96
+	if (is_null($dir_plugins)) {
97
+			$dir_plugins = _DIR_PLUGINS;
98
+	}
89 99
 	$search = array("$dir_plugins$dir/plugin.xml","$dir_plugins$dir/paquet.xml");
90 100
 	
91 101
 	foreach($search as $s){
@@ -118,8 +128,12 @@  discard block
 block discarded – undo
118 128
 **/
119 129
 function plugin_version_compatible($intervalle, $version, $avec_quoi = '') {
120 130
 
121
-	if (!strlen($intervalle)) return true;
122
-	if (!preg_match(_EXTRAIRE_INTERVALLE,$intervalle,$regs)) return false;
131
+	if (!strlen($intervalle)) {
132
+	    return true;
133
+	}
134
+	if (!preg_match(_EXTRAIRE_INTERVALLE,$intervalle,$regs)) {
135
+	    return false;
136
+	}
123 137
 	// Extraction des bornes et traitement de * pour la borne sup :
124 138
 	// -- on autorise uniquement les ecritures 3.0.*, 3.*
125 139
 	$minimum = $regs[1];
@@ -138,12 +152,20 @@  discard block
 block discarded – undo
138 152
 	$maximum_inc = substr($intervalle,-1)=="]";
139 153
 
140 154
 	if (strlen($minimum)){
141
-		if ($minimum_inc AND spip_version_compare($version,$minimum,'<')) return false;
142
-		if (!$minimum_inc AND spip_version_compare($version,$minimum,'<=')) return false;
155
+		if ($minimum_inc AND spip_version_compare($version,$minimum,'<')) {
156
+		    return false;
157
+		}
158
+		if (!$minimum_inc AND spip_version_compare($version,$minimum,'<=')) {
159
+		    return false;
160
+		}
143 161
 	}
144 162
 	if (strlen($maximum)){
145
-		if ($maximum_inc AND spip_version_compare($version,$maximum,'>')) return false;
146
-		if (!$maximum_inc AND spip_version_compare($version,$maximum,'>=')) return false;
163
+		if ($maximum_inc AND spip_version_compare($version,$maximum,'>')) {
164
+		    return false;
165
+		}
166
+		if (!$maximum_inc AND spip_version_compare($version,$maximum,'>=')) {
167
+		    return false;
168
+		}
147 169
 	}
148 170
 	return true;
149 171
 }
@@ -182,19 +204,22 @@  discard block
 block discarded – undo
182 204
 	);
183 205
 
184 206
 	foreach ($liste_ext as $plug){
185
-		if (isset($infos['_DIR_PLUGINS_DIST'][$plug]))
186
-			plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST');
207
+		if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) {
208
+					plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST');
209
+		}
187 210
 	}
188 211
 	foreach ($liste_plug as $plug){
189
-		if (isset($infos['_DIR_PLUGINS'][$plug]))
190
-			plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS');
212
+		if (isset($infos['_DIR_PLUGINS'][$plug])) {
213
+					plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS');
214
+		}
191 215
 	}
192 216
 	
193 217
 	if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL){
194 218
 		$infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL);
195 219
 		foreach ($liste_plug as $plug){
196
-			if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug]))
197
-				plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL');
220
+			if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) {
221
+							plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL');
222
+			}
198 223
 		}
199 224
 	}
200 225
 	
@@ -215,10 +240,12 @@  discard block
 block discarded – undo
215 240
  */
216 241
 function plugin_valide_resume(&$liste, $plug, $infos, $dir_type){
217 242
 	$i = $infos[$dir_type][$plug];
218
-	if (isset($i['erreur']) AND $i['erreur'])
219
-		return;
220
-	if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip'))
221
-		return;
243
+	if (isset($i['erreur']) AND $i['erreur']) {
244
+			return;
245
+	}
246
+	if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) {
247
+			return;
248
+	}
222 249
 	$p = strtoupper($i['prefix']);
223 250
 	if (!isset($liste[$p]) 
224 251
 		OR spip_version_compare($i['version'], $liste[$p]['version'], '>')
@@ -250,7 +277,9 @@  discard block
 block discarded – undo
250 277
 			foreach($i['procure'] as $procure){
251 278
 				$p = strtoupper($procure['nom']);
252 279
 				$dir = $resume['dir'];
253
-				if ($dir) $dir .= "/";
280
+				if ($dir) {
281
+				    $dir .= "/";
282
+				}
254 283
 				$dir .= "procure:".$procure['nom'];
255 284
 
256 285
 				$procure['etat'] = '?';
@@ -298,10 +327,11 @@  discard block
 block discarded – undo
298 327
 		if (!$dir_plugins
299 328
 			OR (
300 329
 				defined($infos['dir_type'])
301
-		    AND constant($infos['dir_type'])==$dir_plugins))
302
-			$liste[$prefix] = $infos['dir'];
303
-		else
304
-			unset($liste[$prefix]);
330
+		    AND constant($infos['dir_type'])==$dir_plugins)) {
331
+					$liste[$prefix] = $infos['dir'];
332
+		} else {
333
+					unset($liste[$prefix]);
334
+		}
305 335
 	}
306 336
 	return $liste;
307 337
 }
@@ -348,7 +378,9 @@  discard block
 block discarded – undo
348 378
 			      break;
349 379
 			  }
350 380
 			}
351
-			if (!$info1) continue;
381
+			if (!$info1) {
382
+			    continue;
383
+			}
352 384
 			// idem si des plugins sont utiles,
353 385
 			// sauf si ils sont de toute facon absents de la liste
354 386
 			foreach($info1['utilise'] as $need){
@@ -383,11 +415,13 @@  discard block
 block discarded – undo
383 415
 		$k = $infos[$dir_type][$plug];
384 416
 		$plug = constant($dir_type) . $plug;
385 417
 		if (!isset($msg[$p])) {
386
-		  if (!$msg[$p] = plugin_necessite($k['necessite'], $liste))
387
-		    $msg[$p] = plugin_necessite($k['utilise'], $liste);
418
+		  if (!$msg[$p] = plugin_necessite($k['necessite'], $liste)) {
419
+		  		    $msg[$p] = plugin_necessite($k['utilise'], $liste);
420
+		  }
388 421
 		} else {
389
-		  foreach($msg[$p] as $c => $l)
390
-		    $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']);
422
+		  foreach($msg[$p] as $c => $l) {
423
+		  		    $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']);
424
+		  }
391 425
 		}
392 426
 		$erreurs[$plug] = $msg[$p];
393 427
 	}
@@ -395,19 +429,23 @@  discard block
 block discarded – undo
395 429
 }
396 430
 
397 431
 function plugin_donne_erreurs($raw=false, $raz=true) {
398
-	if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) return $raw?array():'';
432
+	if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) {
433
+	    return $raw?array():'';
434
+	}
399 435
 	$list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']);
400 436
 	// Compat ancienne version
401
-	if (!$list)
402
-	  $list = $raw?array():$GLOBALS['meta']['plugin_erreur_activation'];
403
-	elseif(!$raw) {
404
-	  foreach($list as $plug => $msg)
405
-	    $list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug))
437
+	if (!$list) {
438
+		  $list = $raw?array():$GLOBALS['meta']['plugin_erreur_activation'];
439
+	} elseif(!$raw) {
440
+	  foreach($list as $plug => $msg) {
441
+	  	    $list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug))
406 442
 		  . "<ul><li>" . implode("</li><li>", $msg) . "</li></ul></li>";
443
+	  }
407 444
 	  $list ="<ul>" . join("\n", $list) . "</ul>";
408 445
 	}
409
-	if ($raz)
410
-		effacer_meta('plugin_erreur_activation');
446
+	if ($raz) {
447
+			effacer_meta('plugin_erreur_activation');
448
+	}
411 449
 	return $list;
412 450
 }
413 451
 
@@ -491,7 +529,9 @@  discard block
 block discarded – undo
491 529
 	// creer le repertoire cache/ si necessaire ! (installation notamment)
492 530
 	sous_repertoire(_DIR_CACHE, '', false,true);
493 531
 	
494
-	if (!spip_connect()) return false;
532
+	if (!spip_connect()) {
533
+	    return false;
534
+	}
495 535
 	if ($operation!='raz') {
496 536
 		$plugin_valides = liste_chemin_plugin_actifs();
497 537
 		$plugin_valides = is_plugin_dir($plugin_valides);
@@ -503,14 +543,17 @@  discard block
 block discarded – undo
503 543
 		// si des plugins sont en attentes (coches mais impossible a activer)
504 544
 		// on les reinjecte ici
505 545
 		if (isset($GLOBALS['meta']['plugin_attente'])
506
-		  AND $a = unserialize($GLOBALS['meta']['plugin_attente']))
507
-		$plugin_valides = $plugin_valides + liste_chemin_plugin($a);
546
+		  AND $a = unserialize($GLOBALS['meta']['plugin_attente'])) {
547
+				$plugin_valides = $plugin_valides + liste_chemin_plugin($a);
548
+		}
508 549
 		
509
-		if ($operation=='ajoute')
510
-			$plugin = array_merge($plugin_valides,$plugin);
511
-		elseif ($operation=='enleve')
512
-			$plugin = array_diff($plugin_valides,$plugin);
513
-		else $plugin = $plugin_valides;
550
+		if ($operation=='ajoute') {
551
+					$plugin = array_merge($plugin_valides,$plugin);
552
+		} elseif ($operation=='enleve') {
553
+					$plugin = array_diff($plugin_valides,$plugin);
554
+		} else {
555
+		    $plugin = $plugin_valides;
556
+		}
514 557
 	}
515 558
 	$actifs_avant = $GLOBALS['meta']['plugin'];
516 559
 
@@ -527,7 +570,9 @@  discard block
 block discarded – undo
527 570
 	list($infos,$liste) = liste_plugin_valides($plugin,true);
528 571
 	// trouver l'ordre d'activation
529 572
 	list($plugin_valides,$ordre,$reste) = plugin_trier($infos, $liste);
530
-	if ($reste) plugins_erreurs($reste, $liste, $infos);
573
+	if ($reste) {
574
+	    plugins_erreurs($reste, $liste, $infos);
575
+	}
531 576
 	// Ignorer les plugins necessitant une lib absente
532 577
 	// et preparer la meta d'entete Http
533 578
 	$err = $msg = $header = array();
@@ -543,19 +588,23 @@  discard block
 block discarded – undo
543 588
 			}
544 589
 		}
545 590
 	}
546
-	if ($err) plugins_erreurs($err, '', $infos, $msg);
591
+	if ($err) {
592
+	    plugins_erreurs($err, '', $infos, $msg);
593
+	}
547 594
 
548
-	if (isset($GLOBALS['meta']['message_crash_plugins']))
549
-		effacer_meta('message_crash_plugins');
595
+	if (isset($GLOBALS['meta']['message_crash_plugins'])) {
596
+			effacer_meta('message_crash_plugins');
597
+	}
550 598
 	ecrire_meta('plugin',serialize($plugin_valides));
551 599
 	$liste = array_diff_key($liste,$plugin_valides);
552 600
 	ecrire_meta('plugin_attente',serialize($liste));
553 601
 	$header = strtolower(implode(",",$header));
554 602
 	ecrire_meta('plugin_header',substr($header,0,900));
555
-	if (!isset($GLOBALS['spip_header_silencieux']) OR !$GLOBALS['spip_header_silencieux'])
556
-		ecrire_fichier(_DIR_VAR."config.txt", (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY:"Composed-By: SPIP") . ' '. $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header);
557
-	else
558
-		@unlink(_DIR_VAR."config.txt");
603
+	if (!isset($GLOBALS['spip_header_silencieux']) OR !$GLOBALS['spip_header_silencieux']) {
604
+			ecrire_fichier(_DIR_VAR."config.txt", (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY:"Composed-By: SPIP") . ' '. $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header);
605
+	} else {
606
+			@unlink(_DIR_VAR."config.txt");
607
+	}
559 608
 	// generer charger_plugins_chemin.php
560 609
 	plugins_precompile_chemin($plugin_valides, $ordre);
561 610
 	// generer les fichiers
@@ -600,13 +649,21 @@  discard block
 block discarded – undo
600 649
 				foreach($info['chemin'] as $chemin){
601 650
 					if (!isset($chemin['version']) OR plugin_version_compatible($chemin['version'],$GLOBALS['spip_version_branche'],'spip')){
602 651
 						$dir = $chemin['path'];
603
-						if (strlen($dir) AND $dir{0}=="/") $dir = substr($dir,1);
604
-						if (strlen($dir) AND $dir=="./") $dir = '';
605
-						if (strlen($dir)) $dir = rtrim($dir,'/').'/';
606
-						if (!isset($chemin['type']) OR $chemin['type']=='public')
607
-							$chemins['public'][]="_DIR_PLUGIN_$prefix".(strlen($dir)?".'$dir'":"");
608
-						if (!isset($chemin['type']) OR $chemin['type']=='prive')
609
-							$chemins['prive'][]="_DIR_PLUGIN_$prefix".(strlen($dir)?".'$dir'":"");
652
+						if (strlen($dir) AND $dir{0}=="/") {
653
+						    $dir = substr($dir,1);
654
+						}
655
+						if (strlen($dir) AND $dir=="./") {
656
+						    $dir = '';
657
+						}
658
+						if (strlen($dir)) {
659
+						    $dir = rtrim($dir,'/').'/';
660
+						}
661
+						if (!isset($chemin['type']) OR $chemin['type']=='public') {
662
+													$chemins['public'][]="_DIR_PLUGIN_$prefix".(strlen($dir)?".'$dir'":"");
663
+						}
664
+						if (!isset($chemin['type']) OR $chemin['type']=='prive') {
665
+													$chemins['prive'][]="_DIR_PLUGIN_$prefix".(strlen($dir)?".'$dir'":"");
666
+						}
610 667
 					}
611 668
 				}
612 669
 			}
@@ -634,10 +691,12 @@  discard block
 block discarded – undo
634 691
 			$plug = $plugin_valides[$p]['dir'];
635 692
 			$dir = constant($dir_type);
636 693
 			$root_dir_type = str_replace('_DIR_','_ROOT_',$dir_type);
637
-			if ($info['menu'])
638
-				$boutons = array_merge($boutons,$info['menu']);
639
-			if ($info['onglet'])
640
-				$onglets = array_merge($onglets,$info['onglet']);
694
+			if ($info['menu']) {
695
+							$boutons = array_merge($boutons,$info['menu']);
696
+			}
697
+			if ($info['onglet']) {
698
+							$onglets = array_merge($onglets,$info['onglet']);
699
+			}
641 700
 			foreach($contenu as $charge => $v){
642 701
 				// si pas declare/detecte a la lecture du paquet.xml,
643 702
 				// detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml
@@ -661,8 +720,7 @@  discard block
 block discarded – undo
661 720
 							// uniquement pour les paquet.xml
662 721
 							AND file_exists("$dir$plug/paquet.xml")){
663 722
 							unset($info[$charge][$k]);
664
-						}
665
-						else {
723
+						} else {
666 724
 							$_file = $root_dir_type . ".'$plug/$file'";
667 725
 							$contenu[$charge] .= "include_once_check($_file);\n";
668 726
 						}
@@ -683,7 +741,9 @@  discard block
 block discarded – undo
683 741
 
684 742
 function plugin_ongletbouton($nom, $val)
685 743
 {
686
-	if (!$val) $val = array();
744
+	if (!$val) {
745
+	    $val = array();
746
+	}
687 747
 	define("_UPDATED_$nom",$val = serialize($val));
688 748
 	define("_UPDATED_md5_$nom",$md5=md5($val));
689 749
 	$val = "unserialize('".str_replace("'","\'",$val)."')";
@@ -701,8 +761,9 @@  discard block
 block discarded – undo
701 761
 function pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche)
702 762
 {
703 763
 	static $liste_pipe_manquants=array();
704
-	if (($pipe_recherche)&&(!in_array($pipe_recherche,$liste_pipe_manquants)))
705
-		$liste_pipe_manquants[]=$pipe_recherche;
764
+	if (($pipe_recherche)&&(!in_array($pipe_recherche,$liste_pipe_manquants))) {
765
+			$liste_pipe_manquants[]=$pipe_recherche;
766
+	}
706 767
 
707 768
 	foreach($ordre as $p => $info){
708 769
 		// $ordre peur contenir des plugins en attente et non valides pour ce hit
@@ -714,10 +775,11 @@  discard block
 block discarded – undo
714 775
 			if (isset($info['pipeline']) AND is_array($info['pipeline'])){
715 776
 				foreach($info['pipeline'] as $pipe){
716 777
 					$nom = $pipe['nom'];
717
-					if (isset($pipe['action']))
718
-							$action = $pipe['action'];
719
-					else
720
-							$action = $nom;
778
+					if (isset($pipe['action'])) {
779
+												$action = $pipe['action'];
780
+					} else {
781
+												$action = $nom;
782
+					}
721 783
 					$nomlower = strtolower($nom);
722 784
 					if ($nomlower!=$nom
723 785
 					AND isset($GLOBALS['spip_pipeline'][$nom])
@@ -727,11 +789,14 @@  discard block
 block discarded – undo
727 789
 					}
728 790
 					$nom = $nomlower;
729 791
 					// une action vide est une declaration qui ne doit pas etre compilee !
730
-					if (!isset($GLOBALS['spip_pipeline'][$nom])) // creer le pipeline eventuel
792
+					if (!isset($GLOBALS['spip_pipeline'][$nom])) {
793
+					    // creer le pipeline eventuel
731 794
 						$GLOBALS['spip_pipeline'][$nom]="";
795
+					}
732 796
 					if ($action){
733
-						if (strpos($GLOBALS['spip_pipeline'][$nom],"|$prefix$action")===FALSE)
734
-							$GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),","|$prefix$action\\1",$GLOBALS['spip_pipeline'][$nom],1);
797
+						if (strpos($GLOBALS['spip_pipeline'][$nom],"|$prefix$action")===FALSE) {
798
+													$GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),","|$prefix$action\\1",$GLOBALS['spip_pipeline'][$nom],1);
799
+						}
735 800
 						if (isset($pipe['inclure'])){
736 801
 							$GLOBALS['spip_matrice']["$prefix$action"] =
737 802
 								"$root_dir_type:$plug/".$pipe['inclure'];
@@ -744,8 +809,10 @@  discard block
 block discarded – undo
744 809
 	
745 810
 	// on charge les fichiers d'options qui peuvent completer 
746 811
 	// la globale spip_pipeline egalement
747
-	if (@is_readable(_CACHE_PLUGINS_PATH))
748
-		include_once(_CACHE_PLUGINS_PATH); // securite : a priori n'a pu etre fait plus tot 
812
+	if (@is_readable(_CACHE_PLUGINS_PATH)) {
813
+			include_once(_CACHE_PLUGINS_PATH);
814
+	}
815
+	// securite : a priori n'a pu etre fait plus tot 
749 816
 	if (@is_readable(_CACHE_PLUGINS_OPT)) {
750 817
 		include_once(_CACHE_PLUGINS_OPT);
751 818
 	} else {
@@ -753,10 +820,11 @@  discard block
 block discarded – undo
753 820
 	}
754 821
 	
755 822
 	// on ajoute les pipe qui ont ete recenses manquants
756
-	foreach($liste_pipe_manquants as $add_pipe)
757
-		if (!isset($GLOBALS['spip_pipeline'][$add_pipe]))
823
+	foreach($liste_pipe_manquants as $add_pipe) {
824
+			if (!isset($GLOBALS['spip_pipeline'][$add_pipe]))
758 825
 			$GLOBALS['spip_pipeline'][$add_pipe]= '';
759
-}
826
+	}
827
+	}
760 828
 
761 829
 // precompilation des pipelines
762 830
 // http://doc.spip.org/@pipeline_precompile
@@ -779,8 +847,9 @@  discard block
 block discarded – undo
779 847
 				if (preg_match(",(_(DIR|ROOT)_[A-Z_]+):,Ums",$file,$regs)){
780 848
 					$dir = $regs[1];
781 849
 					$root_dir = str_replace('_DIR_','_ROOT_',$dir);
782
-					if (defined($root_dir))
783
-						$dir = $root_dir;
850
+					if (defined($root_dir)) {
851
+											$dir = $root_dir;
852
+					}
784 853
 					$file = str_replace($regs[0],"'.".$dir.".'",$file);
785 854
 					$file = str_replace("''.","",$file);
786 855
 					$file = str_replace(constant($dir), '', $file);
@@ -788,8 +857,9 @@  discard block
 block discarded – undo
788 857
 				$s_inc .= "include_once_check($file);\n";
789 858
 			}
790 859
 		}
791
-		if (strlen($s_inc))
792
-			$s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n";
860
+		if (strlen($s_inc)) {
861
+					$s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n";
862
+		}
793 863
 		$content .= "// Pipeline $action \n"
794 864
 		.	"function execute_pipeline_$action(&\$val){\n"
795 865
 		. $s_inc
@@ -804,7 +874,9 @@  discard block
 block discarded – undo
804 874
 // http://doc.spip.org/@plugin_est_installe
805 875
 function plugin_est_installe($plug_path){
806 876
 	$plugin_installes = isset($GLOBALS['meta']['plugin_installes'])?unserialize($GLOBALS['meta']['plugin_installes']):array();
807
-	if (!$plugin_installes) return false;
877
+	if (!$plugin_installes) {
878
+	    return false;
879
+	}
808 880
 	return in_array($plug_path,$plugin_installes);
809 881
 }
810 882
 
@@ -817,8 +889,9 @@  discard block
 block discarded – undo
817 889
 		if ($plug = $resume['dir']){
818 890
 			$infos = $installer_plugins($plug, 'install', $resume['dir_type']);
819 891
 			if ($infos){
820
-				if (!is_array($infos) OR $infos['install_test'][0])
821
-					$meta_plug_installes[] = $plug;
892
+				if (!is_array($infos) OR $infos['install_test'][0]) {
893
+									$meta_plug_installes[] = $plug;
894
+				}
822 895
 				if (is_array($infos)){
823 896
 					list($ok, $trace) = $infos['install_test'];
824 897
 					include_spip('inc/filtres_boites');
Please login to merge, or discard this patch.
Spacing   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -23,27 +23,27 @@  discard block
 block discarded – undo
23 23
 // _DIR_PLUGINS_SUPPL pour aller en chercher ailleurs
24 24
 // (chemins relatifs a la racine du site, separes par des ":")
25 25
 // http://doc.spip.org/@liste_plugin_files
26
-function liste_plugin_files($dir_plugins = null){
27
-	static $plugin_files=array();
26
+function liste_plugin_files($dir_plugins = null) {
27
+	static $plugin_files = array();
28 28
 	if (is_null($dir_plugins))
29 29
 		$dir_plugins = _DIR_PLUGINS;
30 30
 	if (!isset($plugin_files[$dir_plugins])
31
-	OR count($plugin_files[$dir_plugins]) == 0){
31
+	OR count($plugin_files[$dir_plugins]) == 0) {
32 32
 		$plugin_files[$dir_plugins] = array();
33 33
 		foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) {
34
-			$plugin_files[$dir_plugins][] = substr($plugin,strlen($dir_plugins));
34
+			$plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins));
35 35
 		}
36 36
 		
37 37
 		sort($plugin_files[$dir_plugins]);
38 38
 		// et on lit le XML de tous les plugins pour le mettre en cache
39 39
 		// et en profiter pour nettoyer ceux qui n'existent plus du cache
40
-		$get_infos = charger_fonction('get_infos','plugins');
41
-		$get_infos($plugin_files[$dir_plugins],false,$dir_plugins,true);
40
+		$get_infos = charger_fonction('get_infos', 'plugins');
41
+		$get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true);
42 42
 	}
43 43
 	return $plugin_files[$dir_plugins];
44 44
 }
45 45
 
46
-function fast_find_plugin_dirs($dir, $max_prof=100) {
46
+function fast_find_plugin_dirs($dir, $max_prof = 100) {
47 47
 	$fichiers = array();
48 48
 	// revenir au repertoire racine si on a recu dossier/truc
49 49
 	// pour regarder dossier/truc/ ne pas oublier le / final
@@ -52,11 +52,11 @@  discard block
 block discarded – undo
52 52
 
53 53
 	if (!is_dir($dir))
54 54
 		return $fichiers;
55
-	if (is_plugin_dir($dir,'')) {
55
+	if (is_plugin_dir($dir, '')) {
56 56
 		$fichiers[] = $dir;
57 57
 		return $fichiers;
58 58
 	}
59
-	if ($max_prof<=0)
59
+	if ($max_prof <= 0)
60 60
 		return $fichiers;
61 61
 
62 62
 	$subdirs = array();
@@ -70,26 +70,26 @@  discard block
 block discarded – undo
70 70
 		closedir($d);
71 71
 	}
72 72
 
73
-	foreach($subdirs as $d){
74
-		$fichiers = array_merge($fichiers,fast_find_plugin_dirs("$d/",$max_prof-1));
73
+	foreach ($subdirs as $d) {
74
+		$fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1));
75 75
 	}
76 76
 	return $fichiers;
77 77
 }
78 78
 
79
-function is_plugin_dir($dir,$dir_plugins = null){
80
-	if (is_array($dir)){
81
-		foreach($dir as $k=>$d){
82
-			if (!is_plugin_dir($d,$dir_plugins))
79
+function is_plugin_dir($dir, $dir_plugins = null) {
80
+	if (is_array($dir)) {
81
+		foreach ($dir as $k=>$d) {
82
+			if (!is_plugin_dir($d, $dir_plugins))
83 83
 				unset($dir[$k]);
84 84
 		}
85 85
 		return $dir;
86 86
 	}
87 87
 	if (is_null($dir_plugins))
88 88
 		$dir_plugins = _DIR_PLUGINS;
89
-	$search = array("$dir_plugins$dir/plugin.xml","$dir_plugins$dir/paquet.xml");
89
+	$search = array("$dir_plugins$dir/plugin.xml", "$dir_plugins$dir/paquet.xml");
90 90
 	
91
-	foreach($search as $s){
92
-		if (file_exists($s)){
91
+	foreach ($search as $s) {
92
+		if (file_exists($s)) {
93 93
 			return $dir;
94 94
 		}
95 95
 	}
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 function plugin_version_compatible($intervalle, $version, $avec_quoi = '') {
120 120
 
121 121
 	if (!strlen($intervalle)) return true;
122
-	if (!preg_match(_EXTRAIRE_INTERVALLE,$intervalle,$regs)) return false;
122
+	if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) return false;
123 123
 	// Extraction des bornes et traitement de * pour la borne sup :
124 124
 	// -- on autorise uniquement les ecritures 3.0.*, 3.*
125 125
 	$minimum = $regs[1];
@@ -134,16 +134,16 @@  discard block
 block discarded – undo
134 134
 		$maximum = _DEV_PLUGINS.']';
135 135
 	}
136 136
 
137
-	$minimum_inc = $intervalle{0}=="[";
138
-	$maximum_inc = substr($intervalle,-1)=="]";
137
+	$minimum_inc = $intervalle{0} == "[";
138
+	$maximum_inc = substr($intervalle, -1) == "]";
139 139
 
140
-	if (strlen($minimum)){
141
-		if ($minimum_inc AND spip_version_compare($version,$minimum,'<')) return false;
142
-		if (!$minimum_inc AND spip_version_compare($version,$minimum,'<=')) return false;
140
+	if (strlen($minimum)) {
141
+		if ($minimum_inc AND spip_version_compare($version, $minimum, '<')) return false;
142
+		if (!$minimum_inc AND spip_version_compare($version, $minimum, '<=')) return false;
143 143
 	}
144
-	if (strlen($maximum)){
145
-		if ($maximum_inc AND spip_version_compare($version,$maximum,'>')) return false;
146
-		if (!$maximum_inc AND spip_version_compare($version,$maximum,'>=')) return false;
144
+	if (strlen($maximum)) {
145
+		if ($maximum_inc AND spip_version_compare($version, $maximum, '>')) return false;
146
+		if (!$maximum_inc AND spip_version_compare($version, $maximum, '>=')) return false;
147 147
 	}
148 148
 	return true;
149 149
 }
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
  * @param bool $force
159 159
  * @return array
160 160
  */
161
-function liste_plugin_valides($liste_plug, $force = false){
161
+function liste_plugin_valides($liste_plug, $force = false) {
162 162
 	$liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST);
163 163
 	$get_infos = charger_fonction('get_infos', 'plugins');
164 164
 	$infos = array(
@@ -181,18 +181,18 @@  discard block
 block discarded – undo
181 181
 	)
182 182
 	);
183 183
 
184
-	foreach ($liste_ext as $plug){
184
+	foreach ($liste_ext as $plug) {
185 185
 		if (isset($infos['_DIR_PLUGINS_DIST'][$plug]))
186 186
 			plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST');
187 187
 	}
188
-	foreach ($liste_plug as $plug){
188
+	foreach ($liste_plug as $plug) {
189 189
 		if (isset($infos['_DIR_PLUGINS'][$plug]))
190 190
 			plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS');
191 191
 	}
192 192
 	
193
-	if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL){
193
+	if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL) {
194 194
 		$infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL);
195
-		foreach ($liste_plug as $plug){
195
+		foreach ($liste_plug as $plug) {
196 196
 			if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug]))
197 197
 				plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL');
198 198
 		}
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
  * @param array $infos
214 214
  * @param string $dir_type
215 215
  */
216
-function plugin_valide_resume(&$liste, $plug, $infos, $dir_type){
216
+function plugin_valide_resume(&$liste, $plug, $infos, $dir_type) {
217 217
 	$i = $infos[$dir_type][$plug];
218 218
 	if (isset($i['erreur']) AND $i['erreur'])
219 219
 		return;
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 	$p = strtoupper($i['prefix']);
223 223
 	if (!isset($liste[$p]) 
224 224
 		OR spip_version_compare($i['version'], $liste[$p]['version'], '>')
225
-	  ){
225
+	  ) {
226 226
 		$liste[$p] = array(
227 227
 			'nom' => $i['nom'],
228 228
 			'etat' => $i['etat'],
@@ -243,11 +243,11 @@  discard block
 block discarded – undo
243 243
  * @param array $liste
244 244
  * @param array $infos
245 245
  */
246
-function plugin_fixer_procure(&$liste, &$infos){
247
-	foreach($liste as $p=>$resume){
246
+function plugin_fixer_procure(&$liste, &$infos) {
247
+	foreach ($liste as $p=>$resume) {
248 248
 		$i = $infos[$resume['dir_type']][$resume['dir']];
249
-		if (isset($i['procure']) AND $i['procure']){
250
-			foreach($i['procure'] as $procure){
249
+		if (isset($i['procure']) AND $i['procure']) {
250
+			foreach ($i['procure'] as $procure) {
251 251
 				$p = strtoupper($procure['nom']);
252 252
 				$dir = $resume['dir'];
253 253
 				if ($dir) $dir .= "/";
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 				// on ajoute cette version a la liste
262 262
 				if (!isset($liste[$p])
263 263
 					OR spip_version_compare($procure['version'], $liste[$p]['version'], '>')
264
-				  ){
264
+				  ) {
265 265
 					$liste[$p] = $procure;
266 266
 
267 267
 					// on fournit une information minimale pour ne pas perturber la compilation
@@ -293,12 +293,12 @@  discard block
 block discarded – undo
293 293
  * @param string $dir_plugins
294 294
  * @return array
295 295
  */
296
-function liste_chemin_plugin($liste, $dir_plugins=_DIR_PLUGINS){
296
+function liste_chemin_plugin($liste, $dir_plugins = _DIR_PLUGINS) {
297 297
 	foreach ($liste as $prefix=>$infos) {
298 298
 		if (!$dir_plugins
299 299
 			OR (
300 300
 				defined($infos['dir_type'])
301
-		    AND constant($infos['dir_type'])==$dir_plugins))
301
+		    AND constant($infos['dir_type']) == $dir_plugins))
302 302
 			$liste[$prefix] = $infos['dir'];
303 303
 		else
304 304
 			unset($liste[$prefix]);
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
  * @return array
314 314
  */
315 315
 // http://doc.spip.org/@liste_chemin_plugin_actifs
316
-function liste_chemin_plugin_actifs($dir_plugins=_DIR_PLUGINS){
316
+function liste_chemin_plugin_actifs($dir_plugins = _DIR_PLUGINS) {
317 317
 	include_spip('plugins/installer');
318 318
 	return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins);
319 319
 }
@@ -331,19 +331,19 @@  discard block
 block discarded – undo
331 331
 	$toute_la_liste = $liste_non_classee;
332 332
 	$liste = $ordre = array();
333 333
 	$count = 0;
334
-	while ($c=count($liste_non_classee) AND $c!=$count){ // tant qu'il reste des plugins a classer, et qu'on ne stagne pas
334
+	while ($c = count($liste_non_classee) AND $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas
335 335
 	  #echo "tour::";var_dump($liste_non_classee);
336 336
 		$count = $c;
337
-		foreach($liste_non_classee as $p=>$resume) {
337
+		foreach ($liste_non_classee as $p=>$resume) {
338 338
 			$plug = $resume['dir'];
339 339
 			$dir_type = $resume['dir_type'];
340 340
 			$info1 = $infos[$dir_type][$plug];
341 341
 			// si des plugins sont necessaires,
342 342
 			// on ne peut inserer qu'apres eux
343
-			foreach($info1['necessite'] as $need){
343
+			foreach ($info1['necessite'] as $need) {
344 344
 			  $nom = strtoupper($need['nom']);
345 345
 			  $compat = isset($need['compatibilite']) ? $need['compatibilite'] : '';
346
-			  if (!isset($liste[$nom]) OR !plugin_version_compatible($compat,$liste[$nom]['version'])) {
346
+			  if (!isset($liste[$nom]) OR !plugin_version_compatible($compat, $liste[$nom]['version'])) {
347 347
 			      $info1 = false;
348 348
 			      break;
349 349
 			  }
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 			if (!$info1) continue;
352 352
 			// idem si des plugins sont utiles,
353 353
 			// sauf si ils sont de toute facon absents de la liste
354
-			foreach($info1['utilise'] as $need){
354
+			foreach ($info1['utilise'] as $need) {
355 355
 			  $nom = strtoupper($need['nom']);
356 356
 			  $compat = isset($need['compatibilite']) ? $need['compatibilite'] : '';
357 357
 			  if (isset($toute_la_liste[$nom])) {
@@ -374,37 +374,37 @@  discard block
 block discarded – undo
374 374
 
375 375
 // Collecte les erreurs dans la meta 
376 376
 
377
-function plugins_erreurs($liste_non_classee, $liste, $infos, $msg=array())
377
+function plugins_erreurs($liste_non_classee, $liste, $infos, $msg = array())
378 378
 {
379 379
 	static $erreurs = array();
380
-	foreach($liste_non_classee as $p=>$resume){
380
+	foreach ($liste_non_classee as $p=>$resume) {
381 381
 		$dir_type = $resume['dir_type'];
382 382
 		$plug = $resume['dir'];
383 383
 		$k = $infos[$dir_type][$plug];
384
-		$plug = constant($dir_type) . $plug;
384
+		$plug = constant($dir_type).$plug;
385 385
 		if (!isset($msg[$p])) {
386 386
 		  if (!$msg[$p] = plugin_necessite($k['necessite'], $liste))
387 387
 		    $msg[$p] = plugin_necessite($k['utilise'], $liste);
388 388
 		} else {
389
-		  foreach($msg[$p] as $c => $l)
389
+		  foreach ($msg[$p] as $c => $l)
390 390
 		    $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']);
391 391
 		}
392 392
 		$erreurs[$plug] = $msg[$p];
393 393
 	}
394
-	ecrire_meta('plugin_erreur_activation',	serialize($erreurs));
394
+	ecrire_meta('plugin_erreur_activation', serialize($erreurs));
395 395
 }
396 396
 
397
-function plugin_donne_erreurs($raw=false, $raz=true) {
398
-	if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) return $raw?array():'';
397
+function plugin_donne_erreurs($raw = false, $raz = true) {
398
+	if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) return $raw ? array() : '';
399 399
 	$list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']);
400 400
 	// Compat ancienne version
401 401
 	if (!$list)
402
-	  $list = $raw?array():$GLOBALS['meta']['plugin_erreur_activation'];
403
-	elseif(!$raw) {
404
-	  foreach($list as $plug => $msg)
405
-	    $list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug))
406
-		  . "<ul><li>" . implode("</li><li>", $msg) . "</li></ul></li>";
407
-	  $list ="<ul>" . join("\n", $list) . "</ul>";
402
+	  $list = $raw ? array() : $GLOBALS['meta']['plugin_erreur_activation'];
403
+	elseif (!$raw) {
404
+	  foreach ($list as $plug => $msg)
405
+	    $list[$plug] = "<li>"._T('plugin_impossible_activer', array('plugin' => $plug))
406
+		  . "<ul><li>".implode("</li><li>", $msg)."</li></ul></li>";
407
+	  $list = "<ul>".join("\n", $list)."</ul>";
408 408
 	}
409 409
 	if ($raz)
410 410
 		effacer_meta('plugin_erreur_activation');
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 **/
427 427
 function plugin_necessite($n, $liste) {
428 428
 	$msg = array();
429
-	foreach($n as $need){
429
+	foreach ($n as $need) {
430 430
 		$id = strtoupper($need['nom']);
431 431
 		if ($r = plugin_controler_necessite($liste, $id, $need['compatibilite'])) {
432 432
 			$msg[] = $r;
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
 **/
451 451
 function plugin_controler_necessite($liste, $nom, $version)
452 452
 {
453
-	if (isset($liste[$nom]) AND plugin_version_compatible($version,$liste[$nom]['version'])) {
453
+	if (isset($liste[$nom]) AND plugin_version_compatible($version, $liste[$nom]['version'])) {
454 454
 		return '';
455 455
 	}
456 456
 	// retrouver le minimum
@@ -472,11 +472,11 @@  discard block
 block discarded – undo
472 472
 		include_spip('inc/charger_plugin');
473 473
 		$url = '<br />'	. bouton_telechargement_plugin($url, 'lib');
474 474
 	}*/
475
-	return _T('plugin_necessite_lib', array('lib'=>$lib)) . " <a href='$url'>$url</a>";
475
+	return _T('plugin_necessite_lib', array('lib'=>$lib))." <a href='$url'>$url</a>";
476 476
 }
477 477
 
478 478
 // Pour compatibilite et lisibilite du code
479
-function actualise_plugins_actifs($pipe_recherche = false){
479
+function actualise_plugins_actifs($pipe_recherche = false) {
480 480
 	return ecrire_plugin_actifs('', $pipe_recherche, 'force');
481 481
 }
482 482
 
@@ -486,19 +486,19 @@  discard block
 block discarded – undo
486 486
 // risque de pb en php5 a cause du typage ou de null (verifier dans la doc php)
487 487
 // @return true/false si il y a du nouveau
488 488
 // http://doc.spip.org/@ecrire_plugin_actifs
489
-function ecrire_plugin_actifs($plugin,$pipe_recherche=false,$operation='raz') {
489
+function ecrire_plugin_actifs($plugin, $pipe_recherche = false, $operation = 'raz') {
490 490
 
491 491
 	// creer le repertoire cache/ si necessaire ! (installation notamment)
492
-	sous_repertoire(_DIR_CACHE, '', false,true);
492
+	sous_repertoire(_DIR_CACHE, '', false, true);
493 493
 	
494 494
 	if (!spip_connect()) return false;
495
-	if ($operation!='raz') {
495
+	if ($operation != 'raz') {
496 496
 		$plugin_valides = liste_chemin_plugin_actifs();
497 497
 		$plugin_valides = is_plugin_dir($plugin_valides);
498
-		if(defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL){
498
+		if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
499 499
 			$plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL);
500
-			$plugin_valides_supp = is_plugin_dir($plugin_valides_supp,_DIR_PLUGINS_SUPPL);
501
-			$plugin_valides = array_merge($plugin_valides,$plugin_valides_supp);
500
+			$plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL);
501
+			$plugin_valides = array_merge($plugin_valides, $plugin_valides_supp);
502 502
 		}
503 503
 		// si des plugins sont en attentes (coches mais impossible a activer)
504 504
 		// on les reinjecte ici
@@ -506,16 +506,16 @@  discard block
 block discarded – undo
506 506
 		  AND $a = unserialize($GLOBALS['meta']['plugin_attente']))
507 507
 		$plugin_valides = $plugin_valides + liste_chemin_plugin($a);
508 508
 		
509
-		if ($operation=='ajoute')
510
-			$plugin = array_merge($plugin_valides,$plugin);
511
-		elseif ($operation=='enleve')
512
-			$plugin = array_diff($plugin_valides,$plugin);
509
+		if ($operation == 'ajoute')
510
+			$plugin = array_merge($plugin_valides, $plugin);
511
+		elseif ($operation == 'enleve')
512
+			$plugin = array_diff($plugin_valides, $plugin);
513 513
 		else $plugin = $plugin_valides;
514 514
 	}
515 515
 	$actifs_avant = $GLOBALS['meta']['plugin'];
516 516
 
517 517
 	// si une fonction de gestion de dependances existe, l'appeler ici
518
-	if ($ajouter_dependances = charger_fonction("ajouter_dependances","plugins",true)){
518
+	if ($ajouter_dependances = charger_fonction("ajouter_dependances", "plugins", true)) {
519 519
 		$plugin = $ajouter_dependances($plugin);
520 520
 	}
521 521
 
@@ -524,17 +524,17 @@  discard block
 block discarded – undo
524 524
 	// pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations
525 525
 	// pourra etre evite quand on ne supportera plus les plugin.xml
526 526
 	// en deplacant la detection de ces fichiers dans la compilation ci dessous
527
-	list($infos,$liste) = liste_plugin_valides($plugin,true);
527
+	list($infos, $liste) = liste_plugin_valides($plugin, true);
528 528
 	// trouver l'ordre d'activation
529
-	list($plugin_valides,$ordre,$reste) = plugin_trier($infos, $liste);
529
+	list($plugin_valides, $ordre, $reste) = plugin_trier($infos, $liste);
530 530
 	if ($reste) plugins_erreurs($reste, $liste, $infos);
531 531
 	// Ignorer les plugins necessitant une lib absente
532 532
 	// et preparer la meta d'entete Http
533 533
 	$err = $msg = $header = array();
534
-	foreach($plugin_valides as $p => $resume) {
535
-		$header[]= $p.($resume['version']?"(".$resume['version'].")":"");
536
-		if ($resume['dir']){ 
537
-			foreach($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) {
534
+	foreach ($plugin_valides as $p => $resume) {
535
+		$header[] = $p.($resume['version'] ? "(".$resume['version'].")" : "");
536
+		if ($resume['dir']) { 
537
+			foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) {
538 538
 				if (!find_in_path($l['nom'], 'lib/')) {
539 539
 					$err[$p] = $resume;
540 540
 					$msg[$p][] = $l;
@@ -547,13 +547,13 @@  discard block
 block discarded – undo
547 547
 
548 548
 	if (isset($GLOBALS['meta']['message_crash_plugins']))
549 549
 		effacer_meta('message_crash_plugins');
550
-	ecrire_meta('plugin',serialize($plugin_valides));
551
-	$liste = array_diff_key($liste,$plugin_valides);
552
-	ecrire_meta('plugin_attente',serialize($liste));
553
-	$header = strtolower(implode(",",$header));
554
-	ecrire_meta('plugin_header',substr($header,0,900));
550
+	ecrire_meta('plugin', serialize($plugin_valides));
551
+	$liste = array_diff_key($liste, $plugin_valides);
552
+	ecrire_meta('plugin_attente', serialize($liste));
553
+	$header = strtolower(implode(",", $header));
554
+	ecrire_meta('plugin_header', substr($header, 0, 900));
555 555
 	if (!isset($GLOBALS['spip_header_silencieux']) OR !$GLOBALS['spip_header_silencieux'])
556
-		ecrire_fichier(_DIR_VAR."config.txt", (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY:"Composed-By: SPIP") . ' '. $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header);
556
+		ecrire_fichier(_DIR_VAR."config.txt", (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY:"Composed-By: SPIP").' '.$GLOBALS['spip_version_affichee']." @ www.spip.net + ".$header);
557 557
 	else
558 558
 		@unlink(_DIR_VAR."config.txt");
559 559
 	// generer charger_plugins_chemin.php
@@ -584,37 +584,37 @@  discard block
 block discarded – undo
584 584
 {
585 585
 	$chemins = array();
586 586
 	$contenu = "";
587
-	foreach($ordre as $p => $info){
587
+	foreach ($ordre as $p => $info) {
588 588
 		// $ordre peur contenir des plugins en attente et non valides pour ce hit
589
-		if (isset($plugin_valides[$p])){
589
+		if (isset($plugin_valides[$p])) {
590 590
 			$dir_type = $plugin_valides[$p]['dir_type'];
591 591
 			$plug = $plugin_valides[$p]['dir'];
592 592
 			// definir le plugin, donc le path avant l'include du fichier options
593 593
 			// permet de faire des include_spip pour attraper un inc_ du plugin
594 594
 
595
-			$dir = $dir_type.".'" . $plug ."/'";
595
+			$dir = $dir_type.".'".$plug."/'";
596 596
 			
597
-			$prefix = strtoupper(preg_replace(',\W,','_',$info['prefix']));
598
-			if ($prefix!=="SPIP"){
597
+			$prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix']));
598
+			if ($prefix !== "SPIP") {
599 599
 				$contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n";
600
-				foreach($info['chemin'] as $chemin){
601
-					if (!isset($chemin['version']) OR plugin_version_compatible($chemin['version'],$GLOBALS['spip_version_branche'],'spip')){
600
+				foreach ($info['chemin'] as $chemin) {
601
+					if (!isset($chemin['version']) OR plugin_version_compatible($chemin['version'], $GLOBALS['spip_version_branche'], 'spip')) {
602 602
 						$dir = $chemin['path'];
603
-						if (strlen($dir) AND $dir{0}=="/") $dir = substr($dir,1);
604
-						if (strlen($dir) AND $dir=="./") $dir = '';
605
-						if (strlen($dir)) $dir = rtrim($dir,'/').'/';
606
-						if (!isset($chemin['type']) OR $chemin['type']=='public')
607
-							$chemins['public'][]="_DIR_PLUGIN_$prefix".(strlen($dir)?".'$dir'":"");
608
-						if (!isset($chemin['type']) OR $chemin['type']=='prive')
609
-							$chemins['prive'][]="_DIR_PLUGIN_$prefix".(strlen($dir)?".'$dir'":"");
603
+						if (strlen($dir) AND $dir{0} == "/") $dir = substr($dir, 1);
604
+						if (strlen($dir) AND $dir == "./") $dir = '';
605
+						if (strlen($dir)) $dir = rtrim($dir, '/').'/';
606
+						if (!isset($chemin['type']) OR $chemin['type'] == 'public')
607
+							$chemins['public'][] = "_DIR_PLUGIN_$prefix".(strlen($dir) ? ".'$dir'" : "");
608
+						if (!isset($chemin['type']) OR $chemin['type'] == 'prive')
609
+							$chemins['prive'][] = "_DIR_PLUGIN_$prefix".(strlen($dir) ? ".'$dir'" : "");
610 610
 					}
611 611
 				}
612 612
 			}
613 613
 		}
614 614
 	}
615
-	if (count($chemins)){
616
-		$contenu .= "if (_DIR_RESTREINT) _chemin(implode(':',array(".implode(',',array_reverse($chemins['public'])).")));\n"
617
-		  . "else _chemin(implode(':',array(".implode(',',array_reverse($chemins['prive'])).")));\n";
615
+	if (count($chemins)) {
616
+		$contenu .= "if (_DIR_RESTREINT) _chemin(implode(':',array(".implode(',', array_reverse($chemins['public'])).")));\n"
617
+		  . "else _chemin(implode(':',array(".implode(',', array_reverse($chemins['prive'])).")));\n";
618 618
 	}
619 619
 
620 620
 	ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu);
@@ -627,43 +627,43 @@  discard block
 block discarded – undo
627 627
 	$onglets = array();
628 628
 	$sign = "";
629 629
 
630
-	foreach($ordre as $p => $info){
630
+	foreach ($ordre as $p => $info) {
631 631
 		// $ordre peur contenir des plugins en attente et non valides pour ce hit
632
-		if (isset($plugin_valides[$p])){
632
+		if (isset($plugin_valides[$p])) {
633 633
 			$dir_type = $plugin_valides[$p]['dir_type'];
634 634
 			$plug = $plugin_valides[$p]['dir'];
635 635
 			$dir = constant($dir_type);
636
-			$root_dir_type = str_replace('_DIR_','_ROOT_',$dir_type);
636
+			$root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type);
637 637
 			if ($info['menu'])
638
-				$boutons = array_merge($boutons,$info['menu']);
638
+				$boutons = array_merge($boutons, $info['menu']);
639 639
 			if ($info['onglet'])
640
-				$onglets = array_merge($onglets,$info['onglet']);
641
-			foreach($contenu as $charge => $v){
640
+				$onglets = array_merge($onglets, $info['onglet']);
641
+			foreach ($contenu as $charge => $v) {
642 642
 				// si pas declare/detecte a la lecture du paquet.xml,
643 643
 				// detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml
644 644
 				// donc ni sa relecture, ni sa detection
645 645
 				if (!isset($info[$charge])
646 646
 					AND $dir // exclure le cas du plugin "SPIP"
647
-					AND strpos($dir,":")===false // exclure le cas des procure:
647
+					AND strpos($dir, ":") === false // exclure le cas des procure:
648 648
 					AND file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml
649
-					){
650
-					if (is_readable("$dir$plug/".($file=$info['prefix']."_".$charge.".php"))){
649
+					) {
650
+					if (is_readable("$dir$plug/".($file = $info['prefix']."_".$charge.".php"))) {
651 651
 						$info[$charge] = array($file);
652 652
 					}
653 653
 				}
654
-				if (isset($info[$charge])){
654
+				if (isset($info[$charge])) {
655 655
 					$files = $info[$charge];
656
-					foreach($files as $k=>$file){
656
+					foreach ($files as $k=>$file) {
657 657
 						// on genere un if file_exists devant chaque include
658 658
 						// pour pouvoir garder le meme niveau d'erreur general
659 659
 						$file = trim($file);
660 660
 						if (!is_readable("$dir$plug/$file")
661 661
 							// uniquement pour les paquet.xml
662
-							AND file_exists("$dir$plug/paquet.xml")){
662
+							AND file_exists("$dir$plug/paquet.xml")) {
663 663
 							unset($info[$charge][$k]);
664 664
 						}
665 665
 						else {
666
-							$_file = $root_dir_type . ".'$plug/$file'";
666
+							$_file = $root_dir_type.".'$plug/$file'";
667 667
 							$contenu[$charge] .= "include_once_check($_file);\n";
668 668
 						}
669 669
 					}
@@ -673,7 +673,7 @@  discard block
 block discarded – undo
673 673
 		}
674 674
 	}
675 675
 
676
-	$contenu['options'] = "define('_PLUGINS_HASH','".md5($sign)."');\n" . $contenu['options'];
676
+	$contenu['options'] = "define('_PLUGINS_HASH','".md5($sign)."');\n".$contenu['options'];
677 677
 	$contenu['fonctions'] .= plugin_ongletbouton("boutons_plugins", $boutons)
678 678
 	. plugin_ongletbouton("onglets_plugins", $onglets);
679 679
 
@@ -684,9 +684,9 @@  discard block
 block discarded – undo
684 684
 function plugin_ongletbouton($nom, $val)
685 685
 {
686 686
 	if (!$val) $val = array();
687
-	define("_UPDATED_$nom",$val = serialize($val));
688
-	define("_UPDATED_md5_$nom",$md5=md5($val));
689
-	$val = "unserialize('".str_replace("'","\'",$val)."')";
687
+	define("_UPDATED_$nom", $val = serialize($val));
688
+	define("_UPDATED_md5_$nom", $md5 = md5($val));
689
+	$val = "unserialize('".str_replace("'", "\'", $val)."')";
690 690
 	return
691 691
 		"if (!function_exists('$nom')) {\n"
692 692
 	 ."function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n"
@@ -700,39 +700,39 @@  discard block
 block discarded – undo
700 700
 
701 701
 function pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche)
702 702
 {
703
-	static $liste_pipe_manquants=array();
704
-	if (($pipe_recherche)&&(!in_array($pipe_recherche,$liste_pipe_manquants)))
705
-		$liste_pipe_manquants[]=$pipe_recherche;
703
+	static $liste_pipe_manquants = array();
704
+	if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants)))
705
+		$liste_pipe_manquants[] = $pipe_recherche;
706 706
 
707
-	foreach($ordre as $p => $info){
707
+	foreach ($ordre as $p => $info) {
708 708
 		// $ordre peur contenir des plugins en attente et non valides pour ce hit
709
-		if (isset($plugin_valides[$p])){
709
+		if (isset($plugin_valides[$p])) {
710 710
 			$dir_type = $plugin_valides[$p]['dir_type'];
711
-			$root_dir_type = str_replace('_DIR_','_ROOT_',$dir_type);
711
+			$root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type);
712 712
 			$plug = $plugin_valides[$p]['dir'];
713
-			$prefix = (($info['prefix']=="spip")?"":$info['prefix']."_");
714
-			if (isset($info['pipeline']) AND is_array($info['pipeline'])){
715
-				foreach($info['pipeline'] as $pipe){
713
+			$prefix = (($info['prefix'] == "spip") ? "" : $info['prefix']."_");
714
+			if (isset($info['pipeline']) AND is_array($info['pipeline'])) {
715
+				foreach ($info['pipeline'] as $pipe) {
716 716
 					$nom = $pipe['nom'];
717 717
 					if (isset($pipe['action']))
718 718
 							$action = $pipe['action'];
719 719
 					else
720 720
 							$action = $nom;
721 721
 					$nomlower = strtolower($nom);
722
-					if ($nomlower!=$nom
722
+					if ($nomlower != $nom
723 723
 					AND isset($GLOBALS['spip_pipeline'][$nom])
724
-					AND !isset($GLOBALS['spip_pipeline'][$nomlower])){
724
+					AND !isset($GLOBALS['spip_pipeline'][$nomlower])) {
725 725
 						$GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom];
726 726
 						unset($GLOBALS['spip_pipeline'][$nom]);
727 727
 					}
728 728
 					$nom = $nomlower;
729 729
 					// une action vide est une declaration qui ne doit pas etre compilee !
730 730
 					if (!isset($GLOBALS['spip_pipeline'][$nom])) // creer le pipeline eventuel
731
-						$GLOBALS['spip_pipeline'][$nom]="";
732
-					if ($action){
733
-						if (strpos($GLOBALS['spip_pipeline'][$nom],"|$prefix$action")===FALSE)
734
-							$GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),","|$prefix$action\\1",$GLOBALS['spip_pipeline'][$nom],1);
735
-						if (isset($pipe['inclure'])){
731
+						$GLOBALS['spip_pipeline'][$nom] = "";
732
+					if ($action) {
733
+						if (strpos($GLOBALS['spip_pipeline'][$nom], "|$prefix$action") === FALSE)
734
+							$GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),", "|$prefix$action\\1", $GLOBALS['spip_pipeline'][$nom], 1);
735
+						if (isset($pipe['inclure'])) {
736 736
 							$GLOBALS['spip_matrice']["$prefix$action"] =
737 737
 								"$root_dir_type:$plug/".$pipe['inclure'];
738 738
 						}
@@ -749,40 +749,40 @@  discard block
 block discarded – undo
749 749
 	if (@is_readable(_CACHE_PLUGINS_OPT)) {
750 750
 		include_once(_CACHE_PLUGINS_OPT);
751 751
 	} else {
752
-		spip_log("pipelines desactives: impossible de produire " . _CACHE_PLUGINS_OPT);
752
+		spip_log("pipelines desactives: impossible de produire "._CACHE_PLUGINS_OPT);
753 753
 	}
754 754
 	
755 755
 	// on ajoute les pipe qui ont ete recenses manquants
756
-	foreach($liste_pipe_manquants as $add_pipe)
756
+	foreach ($liste_pipe_manquants as $add_pipe)
757 757
 		if (!isset($GLOBALS['spip_pipeline'][$add_pipe]))
758
-			$GLOBALS['spip_pipeline'][$add_pipe]= '';
758
+			$GLOBALS['spip_pipeline'][$add_pipe] = '';
759 759
 }
760 760
 
761 761
 // precompilation des pipelines
762 762
 // http://doc.spip.org/@pipeline_precompile
763
-function pipeline_precompile(){
763
+function pipeline_precompile() {
764 764
 	global $spip_pipeline, $spip_matrice;
765 765
 
766 766
 	$content = "";
767
-	foreach($spip_pipeline as $action=>$pipeline){
767
+	foreach ($spip_pipeline as $action=>$pipeline) {
768 768
 		$s_inc = "";
769 769
 		$s_call = "";
770
-		$pipe = array_filter(explode('|',$pipeline));
770
+		$pipe = array_filter(explode('|', $pipeline));
771 771
 		// Eclater le pipeline en filtres et appliquer chaque filtre
772 772
 		foreach ($pipe as $fonc) {
773 773
 			$fonc = trim($fonc);
774 774
 			$s_call .= '$val = minipipe(\''.$fonc.'\', $val);'."\n";
775
-			if (isset($spip_matrice[$fonc])){
775
+			if (isset($spip_matrice[$fonc])) {
776 776
 				$file = $spip_matrice[$fonc];
777 777
 				$file = "'$file'";
778 778
 				// si un _DIR_XXX: est dans la chaine, on extrait la constante
779
-				if (preg_match(",(_(DIR|ROOT)_[A-Z_]+):,Ums",$file,$regs)){
779
+				if (preg_match(",(_(DIR|ROOT)_[A-Z_]+):,Ums", $file, $regs)) {
780 780
 					$dir = $regs[1];
781
-					$root_dir = str_replace('_DIR_','_ROOT_',$dir);
781
+					$root_dir = str_replace('_DIR_', '_ROOT_', $dir);
782 782
 					if (defined($root_dir))
783 783
 						$dir = $root_dir;
784
-					$file = str_replace($regs[0],"'.".$dir.".'",$file);
785
-					$file = str_replace("''.","",$file);
784
+					$file = str_replace($regs[0], "'.".$dir.".'", $file);
785
+					$file = str_replace("''.", "", $file);
786 786
 					$file = str_replace(constant($dir), '', $file);
787 787
 				}
788 788
 				$s_inc .= "include_once_check($file);\n";
@@ -802,10 +802,10 @@  discard block
 block discarded – undo
802 802
 
803 803
 
804 804
 // http://doc.spip.org/@plugin_est_installe
805
-function plugin_est_installe($plug_path){
806
-	$plugin_installes = isset($GLOBALS['meta']['plugin_installes'])?unserialize($GLOBALS['meta']['plugin_installes']):array();
805
+function plugin_est_installe($plug_path) {
806
+	$plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ?unserialize($GLOBALS['meta']['plugin_installes']) : array();
807 807
 	if (!$plugin_installes) return false;
808
-	return in_array($plug_path,$plugin_installes);
808
+	return in_array($plug_path, $plugin_installes);
809 809
 }
810 810
 
811 811
 
@@ -814,12 +814,12 @@  discard block
 block discarded – undo
814 814
 	$installer_plugins = charger_fonction('installer', 'plugins');
815 815
 	$meta_plug_installes = array();
816 816
 	foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix=>$resume) {
817
-		if ($plug = $resume['dir']){
817
+		if ($plug = $resume['dir']) {
818 818
 			$infos = $installer_plugins($plug, 'install', $resume['dir_type']);
819
-			if ($infos){
819
+			if ($infos) {
820 820
 				if (!is_array($infos) OR $infos['install_test'][0])
821 821
 					$meta_plug_installes[] = $plug;
822
-				if (is_array($infos)){
822
+				if (is_array($infos)) {
823 823
 					list($ok, $trace) = $infos['install_test'];
824 824
 					include_spip('inc/filtres_boites');
825 825
 					echo  "<div class='install-plugins svp_retour'>"
@@ -834,12 +834,12 @@  discard block
 block discarded – undo
834 834
 			}
835 835
 		}
836 836
 	}
837
-	ecrire_meta('plugin_installes',serialize($meta_plug_installes),'non');
837
+	ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non');
838 838
 }
839 839
 
840
-function ecrire_fichier_php($nom, $contenu, $comment='')
840
+function ecrire_fichier_php($nom, $contenu, $comment = '')
841 841
 {
842 842
 	ecrire_fichier($nom, 
843
-		       '<'.'?php' . "\n" . $comment ."\nif (defined('_ECRIRE_INC_VERSION')) {\n". $contenu . "}\n?".'>');
843
+		       '<'.'?php'."\n".$comment."\nif (defined('_ECRIRE_INC_VERSION')) {\n".$contenu."}\n?".'>');
844 844
 }
845 845
 
Please login to merge, or discard this patch.
ecrire/inc/presentation.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -23,6 +23,9 @@
 block discarded – undo
23 23
 include_spip('inc/filtres_boites');
24 24
 
25 25
 // http://doc.spip.org/@debut_cadre
26
+/**
27
+ * @param string $style
28
+ */
26 29
 function debut_cadre($style, $icone = "", $fonction = "", $titre = "", $id="", $class="", $padding=true) {
27 30
 	$style_mapping=array('r'=>'simple','e'=>'raccourcis','couleur'=>'basic highlight','couleur-foncee'=>'basic highlight','trait-couleur'=>'important','alerte'=>'notice','info'=>'info','sous_rub'=>'simple sous-rub');
28 31
 	$style_titre_mapping=array('couleur'=>'topper','trait-couleur'=>'section');
Please login to merge, or discard this patch.
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -24,32 +24,32 @@  discard block
 block discarded – undo
24 24
 
25 25
 // http://doc.spip.org/@debut_cadre
26 26
 function debut_cadre($style, $icone = "", $fonction = "", $titre = "", $id="", $class="", $padding=true) {
27
-	$style_mapping=array('r'=>'simple','e'=>'raccourcis','couleur'=>'basic highlight','couleur-foncee'=>'basic highlight','trait-couleur'=>'important','alerte'=>'notice','info'=>'info','sous_rub'=>'simple sous-rub');
28
-	$style_titre_mapping=array('couleur'=>'topper','trait-couleur'=>'section');
29
-	$c = isset($style_mapping[$style])?$style_mapping[$style]:'simple';
30
-	$class = $c . ($class?" $class":"");
31
-	if (!$padding)
32
-		$class .= ($class?" ":"")."no-padding";
33
-
34
-	//($id?"id='$id' ":"")
35
-	if (strlen($icone) > 1) {
36
-		if ($icone_renommer = charger_fonction('icone_renommer','inc',true))
37
-			list($fond,$fonction) = $icone_renommer($icone,$fonction);
38
-		$size = 24;
39
-		if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i",$fond,$match))
40
-			$size = $match[1];
41
-		if ($fonction){
42
-			// 2 images pour composer l'icone : le fond (article) en background,
43
-			// la fonction (new) en image
44
-			$icone = http_img_pack($fonction, "", "class='cadre-icone' width='$size' height='$size'\n" .
45
-						http_style_background($fond, "no-repeat center center"));
46
-		}
47
-		else {
48
-			$icone = http_img_pack($fond, "", "class='cadre-icone' width='$size' height='$size'");
49
-		}
50
-		$titre = $icone . $titre;
51
-	}
52
-	return boite_ouvrir($titre, $class,isset($style_titre_mapping[$style])?$style_titre_mapping[$style]:'',$id);
27
+    $style_mapping=array('r'=>'simple','e'=>'raccourcis','couleur'=>'basic highlight','couleur-foncee'=>'basic highlight','trait-couleur'=>'important','alerte'=>'notice','info'=>'info','sous_rub'=>'simple sous-rub');
28
+    $style_titre_mapping=array('couleur'=>'topper','trait-couleur'=>'section');
29
+    $c = isset($style_mapping[$style])?$style_mapping[$style]:'simple';
30
+    $class = $c . ($class?" $class":"");
31
+    if (!$padding)
32
+        $class .= ($class?" ":"")."no-padding";
33
+
34
+    //($id?"id='$id' ":"")
35
+    if (strlen($icone) > 1) {
36
+        if ($icone_renommer = charger_fonction('icone_renommer','inc',true))
37
+            list($fond,$fonction) = $icone_renommer($icone,$fonction);
38
+        $size = 24;
39
+        if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i",$fond,$match))
40
+            $size = $match[1];
41
+        if ($fonction){
42
+            // 2 images pour composer l'icone : le fond (article) en background,
43
+            // la fonction (new) en image
44
+            $icone = http_img_pack($fonction, "", "class='cadre-icone' width='$size' height='$size'\n" .
45
+                        http_style_background($fond, "no-repeat center center"));
46
+        }
47
+        else {
48
+            $icone = http_img_pack($fond, "", "class='cadre-icone' width='$size' height='$size'");
49
+        }
50
+        $titre = $icone . $titre;
51
+    }
52
+    return boite_ouvrir($titre, $class,isset($style_titre_mapping[$style])?$style_titre_mapping[$style]:'',$id);
53 53
 }
54 54
 
55 55
 // http://doc.spip.org/@fin_cadre
@@ -80,8 +80,8 @@  discard block
 block discarded – undo
80 80
 // Se place a droite si l'ecran est en mode panoramique.
81 81
 // http://doc.spip.org/@bloc_des_raccourcis
82 82
 function bloc_des_raccourcis($bloc) {
83
-	return creer_colonne_droite()
84
-	  . boite_ouvrir(_T('titre_cadre_raccourcis'),'raccourcis') . $bloc . boite_fermer();
83
+    return creer_colonne_droite()
84
+        . boite_ouvrir(_T('titre_cadre_raccourcis'),'raccourcis') . $bloc . boite_fermer();
85 85
 }
86 86
 
87 87
 // Compatibilite
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
 
97 97
 // http://doc.spip.org/@afficher_objets
98 98
 function afficher_objets($type, $titre_table,$requete,$formater='',$force=false){
99
-	$afficher_objets = charger_fonction('afficher_objets','inc');
100
-	return $afficher_objets($type, $titre_table,$requete,$formater,$force);
99
+    $afficher_objets = charger_fonction('afficher_objets','inc');
100
+    return $afficher_objets($type, $titre_table,$requete,$formater,$force);
101 101
 }
102 102
 
103 103
 // Fonctions onglets
@@ -108,36 +108,36 @@  discard block
 block discarded – undo
108 108
 function fin_onglet(){return "</ul></div>\n";}
109 109
 // http://doc.spip.org/@onglet
110 110
 function onglet($texte, $lien, $onglet_ref, $onglet, $icone=""){
111
-	return "<li>"
112
- 	 . ($icone?http_img_pack($icone, '', " class='cadre-icone'"):'')
113
-	 . lien_ou_expose($lien,$texte,$onglet == $onglet_ref)
114
-	 . "</li>";
111
+    return "<li>"
112
+        . ($icone?http_img_pack($icone, '', " class='cadre-icone'"):'')
113
+        . lien_ou_expose($lien,$texte,$onglet == $onglet_ref)
114
+        . "</li>";
115 115
 }
116 116
 
117 117
 // http://doc.spip.org/@icone_inline
118 118
 function icone_verticale($texte, $lien, $fond, $fonction="", $align="", $javascript=""){
119
-	// cas d'ajax_action_auteur: faut defaire le boulot
120
-	// (il faudrait fusionner avec le cas $javascript)
121
-	if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i",$lien,$r)) {
122
-		list($x,$lien,$atts,$texte)= $r;
123
-		$javascript .= $atts;
124
-	}
125
-
126
-	return icone_base($lien, $texte, $fond, $fonction,"verticale $align",$javascript);
119
+    // cas d'ajax_action_auteur: faut defaire le boulot
120
+    // (il faudrait fusionner avec le cas $javascript)
121
+    if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i",$lien,$r)) {
122
+        list($x,$lien,$atts,$texte)= $r;
123
+        $javascript .= $atts;
124
+    }
125
+
126
+    return icone_base($lien, $texte, $fond, $fonction,"verticale $align",$javascript);
127 127
 }
128 128
 
129 129
 // http://doc.spip.org/@icone_horizontale
130 130
 function icone_horizontale($texte, $lien, $fond, $fonction="", $dummy="", $javascript="") {
131
-	$retour = '';
132
-	// cas d'ajax_action_auteur: faut defaire le boulot
133
-	// (il faudrait fusionner avec le cas $javascript)
134
-	if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i",$lien,$r)) {
135
-		list($x,$lien,$atts,$texte)= $r;
136
-		$javascript .= $atts;
137
-	}
138
-
139
-	$retour = icone_base($lien, $texte, $fond, $fonction,"horizontale",$javascript);
140
-	return $retour;
131
+    $retour = '';
132
+    // cas d'ajax_action_auteur: faut defaire le boulot
133
+    // (il faudrait fusionner avec le cas $javascript)
134
+    if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i",$lien,$r)) {
135
+        list($x,$lien,$atts,$texte)= $r;
136
+        $javascript .= $atts;
137
+    }
138
+
139
+    $retour = icone_base($lien, $texte, $fond, $fonction,"horizontale",$javascript);
140
+    return $retour;
141 141
 }
142 142
 
143 143
 ?>
144 144
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +13 added lines, -9 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
11 11
 \***************************************************************************/
12 12
 
13
-if (!defined('_ECRIRE_INC_VERSION')) return;
13
+if (!defined('_ECRIRE_INC_VERSION')) {
14
+    return;
15
+}
14 16
 
15 17
 include_spip('inc/presentation_mini');
16 18
 include_spip('inc/layer');
@@ -28,23 +30,25 @@  discard block
 block discarded – undo
28 30
 	$style_titre_mapping=array('couleur'=>'topper','trait-couleur'=>'section');
29 31
 	$c = isset($style_mapping[$style])?$style_mapping[$style]:'simple';
30 32
 	$class = $c . ($class?" $class":"");
31
-	if (!$padding)
32
-		$class .= ($class?" ":"")."no-padding";
33
+	if (!$padding) {
34
+			$class .= ($class?" ":"")."no-padding";
35
+	}
33 36
 
34 37
 	//($id?"id='$id' ":"")
35 38
 	if (strlen($icone) > 1) {
36
-		if ($icone_renommer = charger_fonction('icone_renommer','inc',true))
37
-			list($fond,$fonction) = $icone_renommer($icone,$fonction);
39
+		if ($icone_renommer = charger_fonction('icone_renommer','inc',true)) {
40
+					list($fond,$fonction) = $icone_renommer($icone,$fonction);
41
+		}
38 42
 		$size = 24;
39
-		if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i",$fond,$match))
40
-			$size = $match[1];
43
+		if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i",$fond,$match)) {
44
+					$size = $match[1];
45
+		}
41 46
 		if ($fonction){
42 47
 			// 2 images pour composer l'icone : le fond (article) en background,
43 48
 			// la fonction (new) en image
44 49
 			$icone = http_img_pack($fonction, "", "class='cadre-icone' width='$size' height='$size'\n" .
45 50
 						http_style_background($fond, "no-repeat center center"));
46
-		}
47
-		else {
51
+		} else {
48 52
 			$icone = http_img_pack($fond, "", "class='cadre-icone' width='$size' height='$size'");
49 53
 		}
50 54
 		$titre = $icone . $titre;
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -23,70 +23,70 @@  discard block
 block discarded – undo
23 23
 include_spip('inc/filtres_boites');
24 24
 
25 25
 // http://doc.spip.org/@debut_cadre
26
-function debut_cadre($style, $icone = "", $fonction = "", $titre = "", $id="", $class="", $padding=true) {
27
-	$style_mapping=array('r'=>'simple','e'=>'raccourcis','couleur'=>'basic highlight','couleur-foncee'=>'basic highlight','trait-couleur'=>'important','alerte'=>'notice','info'=>'info','sous_rub'=>'simple sous-rub');
28
-	$style_titre_mapping=array('couleur'=>'topper','trait-couleur'=>'section');
29
-	$c = isset($style_mapping[$style])?$style_mapping[$style]:'simple';
30
-	$class = $c . ($class?" $class":"");
26
+function debut_cadre($style, $icone = "", $fonction = "", $titre = "", $id = "", $class = "", $padding = true) {
27
+	$style_mapping = array('r'=>'simple', 'e'=>'raccourcis', 'couleur'=>'basic highlight', 'couleur-foncee'=>'basic highlight', 'trait-couleur'=>'important', 'alerte'=>'notice', 'info'=>'info', 'sous_rub'=>'simple sous-rub');
28
+	$style_titre_mapping = array('couleur'=>'topper', 'trait-couleur'=>'section');
29
+	$c = isset($style_mapping[$style]) ? $style_mapping[$style] : 'simple';
30
+	$class = $c.($class ? " $class" : "");
31 31
 	if (!$padding)
32
-		$class .= ($class?" ":"")."no-padding";
32
+		$class .= ($class ? " " : "")."no-padding";
33 33
 
34 34
 	//($id?"id='$id' ":"")
35 35
 	if (strlen($icone) > 1) {
36
-		if ($icone_renommer = charger_fonction('icone_renommer','inc',true))
37
-			list($fond,$fonction) = $icone_renommer($icone,$fonction);
36
+		if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true))
37
+			list($fond, $fonction) = $icone_renommer($icone, $fonction);
38 38
 		$size = 24;
39
-		if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i",$fond,$match))
39
+		if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i", $fond, $match))
40 40
 			$size = $match[1];
41
-		if ($fonction){
41
+		if ($fonction) {
42 42
 			// 2 images pour composer l'icone : le fond (article) en background,
43 43
 			// la fonction (new) en image
44
-			$icone = http_img_pack($fonction, "", "class='cadre-icone' width='$size' height='$size'\n" .
44
+			$icone = http_img_pack($fonction, "", "class='cadre-icone' width='$size' height='$size'\n".
45 45
 						http_style_background($fond, "no-repeat center center"));
46 46
 		}
47 47
 		else {
48 48
 			$icone = http_img_pack($fond, "", "class='cadre-icone' width='$size' height='$size'");
49 49
 		}
50
-		$titre = $icone . $titre;
50
+		$titre = $icone.$titre;
51 51
 	}
52
-	return boite_ouvrir($titre, $class,isset($style_titre_mapping[$style])?$style_titre_mapping[$style]:'',$id);
52
+	return boite_ouvrir($titre, $class, isset($style_titre_mapping[$style]) ? $style_titre_mapping[$style] : '', $id);
53 53
 }
54 54
 
55 55
 // http://doc.spip.org/@fin_cadre
56
-function fin_cadre() {return boite_fermer();}
57
-
58
-
59
-function debut_cadre_relief($icone='', $dummy='', $fonction='', $titre = '', $id="", $class=""){return debut_cadre('r', $icone, $fonction, $titre, $id, $class);}
60
-function fin_cadre_relief(){return fin_cadre('r');}
61
-function debut_cadre_enfonce($icone='', $dummy='', $fonction='', $titre = '', $id="", $class=""){return debut_cadre('e', $icone, $fonction, $titre, $id, $class);}
62
-function fin_cadre_enfonce(){return fin_cadre('e');}
63
-function debut_cadre_sous_rub($icone='', $dummy='', $fonction='', $titre = '', $id="", $class=""){return debut_cadre('sous_rub', $icone, $fonction, $titre, $id, $class);}
64
-function fin_cadre_sous_rub(){return fin_cadre('sous_rub');}
65
-function debut_cadre_couleur($icone='', $dummy='', $fonction='', $titre='', $id="", $class=""){return debut_cadre('couleur', $icone, $fonction, $titre, $id, $class);}
66
-function fin_cadre_couleur(){return fin_cadre('couleur');}
67
-function debut_cadre_couleur_foncee($icone='', $dummy='', $fonction='', $titre='', $id="", $class=""){return debut_cadre('couleur-foncee', $icone, $fonction, $titre, $id, $class);}
68
-function fin_cadre_couleur_foncee(){return fin_cadre('couleur-foncee');}
69
-function debut_cadre_trait_couleur($icone='', $dummy='', $fonction='', $titre='', $id="", $class=""){return debut_cadre('trait-couleur', $icone, $fonction, $titre, $id, $class);}
70
-function fin_cadre_trait_couleur(){return fin_cadre('trait-couleur');}
71
-function debut_boite_alerte() {return debut_cadre('alerte', '', '', '', '', '');}
72
-function fin_boite_alerte() {return fin_cadre('alerte');}
73
-function debut_boite_info() {return debut_cadre('info', '', '', '', '', '');}
74
-function fin_boite_info() {return fin_cadre('info');}
56
+function fin_cadre() {return boite_fermer(); }
57
+
58
+
59
+function debut_cadre_relief($icone = '', $dummy = '', $fonction = '', $titre = '', $id = "", $class = "") {return debut_cadre('r', $icone, $fonction, $titre, $id, $class); }
60
+function fin_cadre_relief() {return fin_cadre('r'); }
61
+function debut_cadre_enfonce($icone = '', $dummy = '', $fonction = '', $titre = '', $id = "", $class = "") {return debut_cadre('e', $icone, $fonction, $titre, $id, $class); }
62
+function fin_cadre_enfonce() {return fin_cadre('e'); }
63
+function debut_cadre_sous_rub($icone = '', $dummy = '', $fonction = '', $titre = '', $id = "", $class = "") {return debut_cadre('sous_rub', $icone, $fonction, $titre, $id, $class); }
64
+function fin_cadre_sous_rub() {return fin_cadre('sous_rub'); }
65
+function debut_cadre_couleur($icone = '', $dummy = '', $fonction = '', $titre = '', $id = "", $class = "") {return debut_cadre('couleur', $icone, $fonction, $titre, $id, $class); }
66
+function fin_cadre_couleur() {return fin_cadre('couleur'); }
67
+function debut_cadre_couleur_foncee($icone = '', $dummy = '', $fonction = '', $titre = '', $id = "", $class = "") {return debut_cadre('couleur-foncee', $icone, $fonction, $titre, $id, $class); }
68
+function fin_cadre_couleur_foncee() {return fin_cadre('couleur-foncee'); }
69
+function debut_cadre_trait_couleur($icone = '', $dummy = '', $fonction = '', $titre = '', $id = "", $class = "") {return debut_cadre('trait-couleur', $icone, $fonction, $titre, $id, $class); }
70
+function fin_cadre_trait_couleur() {return fin_cadre('trait-couleur'); }
71
+function debut_boite_alerte() {return debut_cadre('alerte', '', '', '', '', ''); }
72
+function fin_boite_alerte() {return fin_cadre('alerte'); }
73
+function debut_boite_info() {return debut_cadre('info', '', '', '', '', ''); }
74
+function fin_boite_info() {return fin_cadre('info'); }
75 75
 
76 76
 // http://doc.spip.org/@gros_titre
77
-function gros_titre($titre, $ze_logo=''){return "<h1 class='grostitre'>" . $ze_logo.' ' . typo($titre)."</h1>\n";}
77
+function gros_titre($titre, $ze_logo = '') {return "<h1 class='grostitre'>".$ze_logo.' '.typo($titre)."</h1>\n"; }
78 78
 
79 79
 // La boite des raccourcis
80 80
 // Se place a droite si l'ecran est en mode panoramique.
81 81
 // http://doc.spip.org/@bloc_des_raccourcis
82 82
 function bloc_des_raccourcis($bloc) {
83 83
 	return creer_colonne_droite()
84
-	  . boite_ouvrir(_T('titre_cadre_raccourcis'),'raccourcis') . $bloc . boite_fermer();
84
+	  . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis').$bloc.boite_fermer();
85 85
 }
86 86
 
87 87
 // Compatibilite
88 88
 // http://doc.spip.org/@afficher_plus
89
-function afficher_plus($lien) {include_spip('inc/filtres_ecrire');afficher_plus_info($lien);}
89
+function afficher_plus($lien) {include_spip('inc/filtres_ecrire'); afficher_plus_info($lien); }
90 90
 
91 91
 
92 92
 
@@ -95,48 +95,48 @@  discard block
 block discarded – undo
95 95
 //
96 96
 
97 97
 // http://doc.spip.org/@afficher_objets
98
-function afficher_objets($type, $titre_table,$requete,$formater='',$force=false){
99
-	$afficher_objets = charger_fonction('afficher_objets','inc');
100
-	return $afficher_objets($type, $titre_table,$requete,$formater,$force);
98
+function afficher_objets($type, $titre_table, $requete, $formater = '', $force = false) {
99
+	$afficher_objets = charger_fonction('afficher_objets', 'inc');
100
+	return $afficher_objets($type, $titre_table, $requete, $formater, $force);
101 101
 }
102 102
 
103 103
 // Fonctions onglets
104 104
 // http://doc.spip.org/@debut_onglet
105 105
 // @param string $sous_classe	prend la valeur second pour definir les onglet de deuxieme niveau
106
-function debut_onglet($classe="barre_onglet"){return "<div class='$classe clearfix'><ul>\n";}
106
+function debut_onglet($classe = "barre_onglet") {return "<div class='$classe clearfix'><ul>\n"; }
107 107
 // http://doc.spip.org/@fin_onglet
108
-function fin_onglet(){return "</ul></div>\n";}
108
+function fin_onglet() {return "</ul></div>\n"; }
109 109
 // http://doc.spip.org/@onglet
110
-function onglet($texte, $lien, $onglet_ref, $onglet, $icone=""){
110
+function onglet($texte, $lien, $onglet_ref, $onglet, $icone = "") {
111 111
 	return "<li>"
112
- 	 . ($icone?http_img_pack($icone, '', " class='cadre-icone'"):'')
113
-	 . lien_ou_expose($lien,$texte,$onglet == $onglet_ref)
112
+ 	 . ($icone ?http_img_pack($icone, '', " class='cadre-icone'") : '')
113
+	 . lien_ou_expose($lien, $texte, $onglet == $onglet_ref)
114 114
 	 . "</li>";
115 115
 }
116 116
 
117 117
 // http://doc.spip.org/@icone_inline
118
-function icone_verticale($texte, $lien, $fond, $fonction="", $align="", $javascript=""){
118
+function icone_verticale($texte, $lien, $fond, $fonction = "", $align = "", $javascript = "") {
119 119
 	// cas d'ajax_action_auteur: faut defaire le boulot
120 120
 	// (il faudrait fusionner avec le cas $javascript)
121
-	if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i",$lien,$r)) {
122
-		list($x,$lien,$atts,$texte)= $r;
121
+	if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) {
122
+		list($x, $lien, $atts, $texte) = $r;
123 123
 		$javascript .= $atts;
124 124
 	}
125 125
 
126
-	return icone_base($lien, $texte, $fond, $fonction,"verticale $align",$javascript);
126
+	return icone_base($lien, $texte, $fond, $fonction, "verticale $align", $javascript);
127 127
 }
128 128
 
129 129
 // http://doc.spip.org/@icone_horizontale
130
-function icone_horizontale($texte, $lien, $fond, $fonction="", $dummy="", $javascript="") {
130
+function icone_horizontale($texte, $lien, $fond, $fonction = "", $dummy = "", $javascript = "") {
131 131
 	$retour = '';
132 132
 	// cas d'ajax_action_auteur: faut defaire le boulot
133 133
 	// (il faudrait fusionner avec le cas $javascript)
134
-	if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i",$lien,$r)) {
135
-		list($x,$lien,$atts,$texte)= $r;
134
+	if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) {
135
+		list($x, $lien, $atts, $texte) = $r;
136 136
 		$javascript .= $atts;
137 137
 	}
138 138
 
139
-	$retour = icone_base($lien, $texte, $fond, $fonction,"horizontale",$javascript);
139
+	$retour = icone_base($lien, $texte, $fond, $fonction, "horizontale", $javascript);
140 140
 	return $retour;
141 141
 }
142 142
 
Please login to merge, or discard this patch.