Completed
Push — master ( 29934e...e51ea9 )
by cam
04:15
created
ecrire/xml/analyser_dtd.php 1 patch
Indentation   +313 added lines, -313 removed lines patch added patch discarded remove patch
@@ -11,59 +11,59 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 include_spip('xml/interfaces');
18 18
 
19 19
 // https://code.spip.net/@charger_dtd
20 20
 function charger_dtd($grammaire, $avail, $rotlvl) {
21
-	static $dtd = array(); # cache bien utile pour le validateur en boucle
22
-
23
-	if (isset($dtd[$grammaire])) {
24
-		return $dtd[$grammaire];
25
-	}
26
-
27
-	if ($avail == 'SYSTEM') {
28
-		$grammaire = find_in_path($grammaire);
29
-	}
30
-
31
-	$file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz';
32
-
33
-	if (lire_fichier($file, $r)) {
34
-		if (!$grammaire) {
35
-			return array();
36
-		}
37
-		if (($avail == 'SYSTEM') and filemtime($file) < filemtime($grammaire)) {
38
-			$r = false;
39
-		}
40
-	}
41
-
42
-	if ($r) {
43
-		$dtc = unserialize($r);
44
-	} else {
45
-		spip_timer('dtd');
46
-		$dtc = new DTC;
47
-		// L'analyseur retourne un booleen de reussite et modifie $dtc.
48
-		// Retourner vide en cas d'echec
49
-		if (!analyser_dtd($grammaire, $avail, $dtc)) {
50
-			$dtc = array();
51
-		} else {
52
-			// tri final pour presenter les suggestions de corrections
53
-			foreach ($dtc->peres as $k => $v) {
54
-				asort($v);
55
-				$dtc->peres[$k] = $v;
56
-			}
57
-
58
-			spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ") " . count($dtc->macros) . ' macros, ' . count($dtc->elements) . ' elements, ' . count($dtc->attributs) . " listes d'attributs, " . count($dtc->entites) . " entites");
59
-			#	$r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit;
60
-			ecrire_fichier($file, serialize($dtc), true);
61
-		}
62
-
63
-	}
64
-	$dtd[$grammaire] = $dtc;
65
-
66
-	return $dtc;
21
+    static $dtd = array(); # cache bien utile pour le validateur en boucle
22
+
23
+    if (isset($dtd[$grammaire])) {
24
+        return $dtd[$grammaire];
25
+    }
26
+
27
+    if ($avail == 'SYSTEM') {
28
+        $grammaire = find_in_path($grammaire);
29
+    }
30
+
31
+    $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz';
32
+
33
+    if (lire_fichier($file, $r)) {
34
+        if (!$grammaire) {
35
+            return array();
36
+        }
37
+        if (($avail == 'SYSTEM') and filemtime($file) < filemtime($grammaire)) {
38
+            $r = false;
39
+        }
40
+    }
41
+
42
+    if ($r) {
43
+        $dtc = unserialize($r);
44
+    } else {
45
+        spip_timer('dtd');
46
+        $dtc = new DTC;
47
+        // L'analyseur retourne un booleen de reussite et modifie $dtc.
48
+        // Retourner vide en cas d'echec
49
+        if (!analyser_dtd($grammaire, $avail, $dtc)) {
50
+            $dtc = array();
51
+        } else {
52
+            // tri final pour presenter les suggestions de corrections
53
+            foreach ($dtc->peres as $k => $v) {
54
+                asort($v);
55
+                $dtc->peres[$k] = $v;
56
+            }
57
+
58
+            spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ") " . count($dtc->macros) . ' macros, ' . count($dtc->elements) . ' elements, ' . count($dtc->attributs) . " listes d'attributs, " . count($dtc->entites) . " entites");
59
+            #	$r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit;
60
+            ecrire_fichier($file, serialize($dtc), true);
61
+        }
62
+
63
+    }
64
+    $dtd[$grammaire] = $dtc;
65
+
66
+    return $dtc;
67 67
 }
68 68
 
69 69
 // Compiler une regle de production en une Regexp qu'on appliquera sur la
@@ -76,141 +76,141 @@  discard block
 block discarded – undo
76 76
 
77 77
 // https://code.spip.net/@compilerRegle
78 78
 function compilerRegle($val) {
79
-	$x = str_replace('()', '',
80
-		preg_replace('/\s*,\s*/', '',
81
-			preg_replace('/(\w+)\s*/', '(?:\1 )',
82
-				preg_replace('/\s*\)/', ')',
83
-					preg_replace('/\s*([(+*|?])\s*/', '\1',
84
-						preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val))))));
85
-
86
-	return $x;
79
+    $x = str_replace('()', '',
80
+        preg_replace('/\s*,\s*/', '',
81
+            preg_replace('/(\w+)\s*/', '(?:\1 )',
82
+                preg_replace('/\s*\)/', ')',
83
+                    preg_replace('/\s*([(+*|?])\s*/', '\1',
84
+                        preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val))))));
85
+
86
+    return $x;
87 87
 }
88 88
 
89 89
 
90 90
 // https://code.spip.net/@analyser_dtd
91 91
 function analyser_dtd($loc, $avail, &$dtc) {
92
-	// creer le repertoire de cache si ce n'est fait
93
-	// (utile aussi pour le resultat de la compil)
94
-	$file = sous_repertoire(_DIR_CACHE_XML);
95
-	// si DTD locale, ignorer ce repertoire pour le moment
96
-	if ($avail == 'SYSTEM') {
97
-		$file = $loc;
98
-		if (_DIR_RACINE and strncmp($file, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) {
99
-			$file = substr($file, strlen(_DIR_RACINE));
100
-		}
101
-		$file = find_in_path($file);
102
-	} else {
103
-		$file .= preg_replace('/[^\w.]/', '_', $loc);
104
-	}
105
-
106
-	$dtd = '';
107
-	if (@is_readable($file)) {
108
-		lire_fichier($file, $dtd);
109
-	} else {
110
-		if ($avail == 'PUBLIC') {
111
-			include_spip('inc/distant');
112
-			$dtd = recuperer_url($loc);
113
-			$dtd = trim($dtd['page'] ?? '');
114
-			if ($dtd) {
115
-				ecrire_fichier($file, $dtd, true);
116
-			}
117
-		}
118
-	}
119
-
120
-	$dtd = ltrim($dtd);
121
-	if (!$dtd) {
122
-		spip_log("DTD '$loc' ($file) inaccessible");
123
-
124
-		return false;
125
-	} else {
126
-		spip_log("analyse de la DTD $loc ");
127
-	}
128
-
129
-	while ($dtd) {
130
-		if ($dtd[0] != '<') {
131
-			$r = analyser_dtd_lexeme($dtd, $dtc, $loc);
132
-		} elseif ($dtd[1] != '!') {
133
-			$r = analyser_dtd_pi($dtd, $dtc, $loc);
134
-		} elseif ($dtd[2] == '[') {
135
-			$r = analyser_dtd_data($dtd, $dtc, $loc);
136
-		} else {
137
-			switch ($dtd[3]) {
138
-				case '%' :
139
-					$r = analyser_dtd_data($dtd, $dtc, $loc);
140
-					break;
141
-				case 'T' :
142
-					$r = analyser_dtd_attlist($dtd, $dtc, $loc);
143
-					break;
144
-				case 'L' :
145
-					$r = analyser_dtd_element($dtd, $dtc, $loc);
146
-					break;
147
-				case 'N' :
148
-					$r = analyser_dtd_entity($dtd, $dtc, $loc);
149
-					break;
150
-				case 'O' :
151
-					$r = analyser_dtd_notation($dtd, $dtc, $loc);
152
-					break;
153
-				case '-' :
154
-					$r = analyser_dtd_comment($dtd, $dtc, $loc);
155
-					break;
156
-				default:
157
-					$r = -1;
158
-			}
159
-		}
160
-		if (!is_string($r)) {
161
-			spip_log("erreur $r dans la DTD  " . substr($dtd, 0, 80) . ".....");
162
-
163
-			return false;
164
-		}
165
-		$dtd = $r;
166
-	}
167
-
168
-	return true;
92
+    // creer le repertoire de cache si ce n'est fait
93
+    // (utile aussi pour le resultat de la compil)
94
+    $file = sous_repertoire(_DIR_CACHE_XML);
95
+    // si DTD locale, ignorer ce repertoire pour le moment
96
+    if ($avail == 'SYSTEM') {
97
+        $file = $loc;
98
+        if (_DIR_RACINE and strncmp($file, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) {
99
+            $file = substr($file, strlen(_DIR_RACINE));
100
+        }
101
+        $file = find_in_path($file);
102
+    } else {
103
+        $file .= preg_replace('/[^\w.]/', '_', $loc);
104
+    }
105
+
106
+    $dtd = '';
107
+    if (@is_readable($file)) {
108
+        lire_fichier($file, $dtd);
109
+    } else {
110
+        if ($avail == 'PUBLIC') {
111
+            include_spip('inc/distant');
112
+            $dtd = recuperer_url($loc);
113
+            $dtd = trim($dtd['page'] ?? '');
114
+            if ($dtd) {
115
+                ecrire_fichier($file, $dtd, true);
116
+            }
117
+        }
118
+    }
119
+
120
+    $dtd = ltrim($dtd);
121
+    if (!$dtd) {
122
+        spip_log("DTD '$loc' ($file) inaccessible");
123
+
124
+        return false;
125
+    } else {
126
+        spip_log("analyse de la DTD $loc ");
127
+    }
128
+
129
+    while ($dtd) {
130
+        if ($dtd[0] != '<') {
131
+            $r = analyser_dtd_lexeme($dtd, $dtc, $loc);
132
+        } elseif ($dtd[1] != '!') {
133
+            $r = analyser_dtd_pi($dtd, $dtc, $loc);
134
+        } elseif ($dtd[2] == '[') {
135
+            $r = analyser_dtd_data($dtd, $dtc, $loc);
136
+        } else {
137
+            switch ($dtd[3]) {
138
+                case '%' :
139
+                    $r = analyser_dtd_data($dtd, $dtc, $loc);
140
+                    break;
141
+                case 'T' :
142
+                    $r = analyser_dtd_attlist($dtd, $dtc, $loc);
143
+                    break;
144
+                case 'L' :
145
+                    $r = analyser_dtd_element($dtd, $dtc, $loc);
146
+                    break;
147
+                case 'N' :
148
+                    $r = analyser_dtd_entity($dtd, $dtc, $loc);
149
+                    break;
150
+                case 'O' :
151
+                    $r = analyser_dtd_notation($dtd, $dtc, $loc);
152
+                    break;
153
+                case '-' :
154
+                    $r = analyser_dtd_comment($dtd, $dtc, $loc);
155
+                    break;
156
+                default:
157
+                    $r = -1;
158
+            }
159
+        }
160
+        if (!is_string($r)) {
161
+            spip_log("erreur $r dans la DTD  " . substr($dtd, 0, 80) . ".....");
162
+
163
+            return false;
164
+        }
165
+        $dtd = $r;
166
+    }
167
+
168
+    return true;
169 169
 }
170 170
 
171 171
 // https://code.spip.net/@analyser_dtd_comment
172 172
 function analyser_dtd_comment($dtd, &$dtc, $grammaire) {
173
-	// ejecter les commentaires, surtout quand ils contiennent du code.
174
-	// Option /s car sur plusieurs lignes parfois
173
+    // ejecter les commentaires, surtout quand ils contiennent du code.
174
+    // Option /s car sur plusieurs lignes parfois
175 175
 
176
-	if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) {
177
-		return -6;
178
-	}
176
+    if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) {
177
+        return -6;
178
+    }
179 179
 
180
-	return $m[1];
180
+    return $m[1];
181 181
 }
182 182
 
183 183
 // https://code.spip.net/@analyser_dtd_pi
184 184
 function analyser_dtd_pi($dtd, &$dtc, $grammaire) {
185
-	if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) {
186
-		return -10;
187
-	}
185
+    if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) {
186
+        return -10;
187
+    }
188 188
 
189
-	return $m[1];
189
+    return $m[1];
190 190
 }
191 191
 
192 192
 // https://code.spip.net/@analyser_dtd_lexeme
193 193
 function analyser_dtd_lexeme($dtd, &$dtc, $grammaire) {
194 194
 
195
-	if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) {
196
-		return -9;
197
-	}
198
-
199
-	list(, $s) = $m;
200
-	$n = $dtc->macros[$s];
201
-
202
-	if (is_array($n)) {
203
-		// en cas d'inclusion, l'espace de nom est le meme
204
-		// mais gaffe aux DTD dont l'URL est relative a l'engloblante
205
-		if (($n[0] == 'PUBLIC')
206
-			and !tester_url_absolue($n[1])
207
-		) {
208
-			$n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1];
209
-		}
210
-		analyser_dtd($n[1], $n[0], $dtc);
211
-	}
212
-
213
-	return ltrim(substr($dtd, strlen($m[0])));
195
+    if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) {
196
+        return -9;
197
+    }
198
+
199
+    list(, $s) = $m;
200
+    $n = $dtc->macros[$s];
201
+
202
+    if (is_array($n)) {
203
+        // en cas d'inclusion, l'espace de nom est le meme
204
+        // mais gaffe aux DTD dont l'URL est relative a l'engloblante
205
+        if (($n[0] == 'PUBLIC')
206
+            and !tester_url_absolue($n[1])
207
+        ) {
208
+            $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1];
209
+        }
210
+        analyser_dtd($n[1], $n[0], $dtc);
211
+    }
212
+
213
+    return ltrim(substr($dtd, strlen($m[0])));
214 214
 }
215 215
 
216 216
 // il faudrait gerer plus proprement les niveaux d'inclusion:
@@ -219,80 +219,80 @@  discard block
 block discarded – undo
219 219
 // https://code.spip.net/@analyser_dtd_data
220 220
 function analyser_dtd_data($dtd, &$dtc, $grammaire) {
221 221
 
222
-	if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) {
223
-		return -11;
224
-	}
225
-	if (!preg_match('/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s', $m[2],
226
-		$r)
227
-	) {
228
-		return -12;
229
-	}
230
-
231
-	if ($dtc->macros[$m[1]] == 'INCLUDE') {
232
-		$retour = $r[1] . substr($m[2], strlen($r[0]));
233
-	} else {
234
-		$retour = substr($m[2], strlen($r[0]));
235
-	}
236
-
237
-	return $retour;
222
+    if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) {
223
+        return -11;
224
+    }
225
+    if (!preg_match('/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s', $m[2],
226
+        $r)
227
+    ) {
228
+        return -12;
229
+    }
230
+
231
+    if ($dtc->macros[$m[1]] == 'INCLUDE') {
232
+        $retour = $r[1] . substr($m[2], strlen($r[0]));
233
+    } else {
234
+        $retour = substr($m[2], strlen($r[0]));
235
+    }
236
+
237
+    return $retour;
238 238
 }
239 239
 
240 240
 // https://code.spip.net/@analyser_dtd_notation
241 241
 function analyser_dtd_notation($dtd, &$dtc, $grammaire) {
242
-	if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) {
243
-		return -8;
244
-	}
245
-	spip_log("analyser_dtd_notation a ecrire");
242
+    if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) {
243
+        return -8;
244
+    }
245
+    spip_log("analyser_dtd_notation a ecrire");
246 246
 
247
-	return $m[1];
247
+    return $m[1];
248 248
 }
249 249
 
250 250
 // https://code.spip.net/@analyser_dtd_entity
251 251
 function analyser_dtd_entity($dtd, &$dtc, $grammaire) {
252
-	if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) {
253
-		return -2;
254
-	}
255
-
256
-	list($t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd) = $m;
257
-
258
-	if (isset($dtc->macros[$nom]) and $dtc->macros[$nom]) {
259
-		return $dtd;
260
-	}
261
-	if (isset($dtc->entites[$nom])) {
262
-		spip_log("redefinition de l'entite $nom");
263
-	}
264
-	if ($k6) {
265
-		return $k6 . $dtd;
266
-	} // cas du synonyme complet
267
-	$val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros);
268
-
269
-	// cas particulier double evaluation: 'PUBLIC "..." "...."' 
270
-	if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) {
271
-		list($t, $type, $val, $q, $alt) = $r;
272
-	}
273
-
274
-	if (!$term) {
275
-		$dtc->entites[$nom] = $val;
276
-	} elseif (!$type) {
277
-		$dtc->macros[$nom] = $val;
278
-	} else {
279
-		if (($type == 'SYSTEM') and !$alt) {
280
-			$alt = $val;
281
-		}
282
-		if (!$alt) {
283
-			$dtc->macros[$nom] = $val;
284
-		} else {
285
-			if (($type == 'PUBLIC')
286
-				and (strpos($alt, '/') === false)
287
-			) {
288
-				$alt = preg_replace(',/[^/]+$,', '/', $grammaire)
289
-					. $alt;
290
-			}
291
-			$dtc->macros[$nom] = array($type, $alt);
292
-		}
293
-	}
294
-
295
-	return $dtd;
252
+    if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) {
253
+        return -2;
254
+    }
255
+
256
+    list($t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd) = $m;
257
+
258
+    if (isset($dtc->macros[$nom]) and $dtc->macros[$nom]) {
259
+        return $dtd;
260
+    }
261
+    if (isset($dtc->entites[$nom])) {
262
+        spip_log("redefinition de l'entite $nom");
263
+    }
264
+    if ($k6) {
265
+        return $k6 . $dtd;
266
+    } // cas du synonyme complet
267
+    $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros);
268
+
269
+    // cas particulier double evaluation: 'PUBLIC "..." "...."' 
270
+    if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) {
271
+        list($t, $type, $val, $q, $alt) = $r;
272
+    }
273
+
274
+    if (!$term) {
275
+        $dtc->entites[$nom] = $val;
276
+    } elseif (!$type) {
277
+        $dtc->macros[$nom] = $val;
278
+    } else {
279
+        if (($type == 'SYSTEM') and !$alt) {
280
+            $alt = $val;
281
+        }
282
+        if (!$alt) {
283
+            $dtc->macros[$nom] = $val;
284
+        } else {
285
+            if (($type == 'PUBLIC')
286
+                and (strpos($alt, '/') === false)
287
+            ) {
288
+                $alt = preg_replace(',/[^/]+$,', '/', $grammaire)
289
+                    . $alt;
290
+            }
291
+            $dtc->macros[$nom] = array($type, $alt);
292
+        }
293
+    }
294
+
295
+    return $dtd;
296 296
 }
297 297
 
298 298
 // Dresser le tableau des filles potentielles de l'element
@@ -306,76 +306,76 @@  discard block
 block discarded – undo
306 306
 
307 307
 // https://code.spip.net/@analyser_dtd_element
308 308
 function analyser_dtd_element($dtd, &$dtc, $grammaire) {
309
-	if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) {
310
-		return -3;
311
-	}
312
-
313
-	list(, $nom, $contenu, $dtd) = $m;
314
-	$nom = expanserEntite($nom, $dtc->macros);
315
-
316
-	if (isset($dtc->elements[$nom])) {
317
-		spip_log("redefinition de l'element $nom dans la DTD");
318
-
319
-		return -4;
320
-	}
321
-	$filles = array();
322
-	$contenu = expanserEntite($contenu, $dtc->macros);
323
-	$val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )';
324
-	if ($val == '(?:EMPTY )') {
325
-		$dtc->regles[$nom] = 'EMPTY';
326
-	} elseif ($val == '(?:ANY )') {
327
-		$dtc->regles[$nom] = 'ANY';
328
-	} else {
329
-		$last = substr($val, -1);
330
-		if (preg_match('/ \w/', $val)
331
-			or (!empty($last) and strpos('*+?', $last) === false)
332
-		) {
333
-			$dtc->regles[$nom] = "/^$val$/";
334
-		} else {
335
-			$dtc->regles[$nom] = $last;
336
-		}
337
-		$filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY));
338
-
339
-		foreach ($filles as $k) {
340
-			if (!isset($dtc->peres[$k])) {
341
-				$dtc->peres[$k] = array();
342
-			}
343
-			if (!in_array($nom, $dtc->peres[$k])) {
344
-				$dtc->peres[$k][] = $nom;
345
-			}
346
-		}
347
-	}
348
-	$dtc->pcdata[$nom] = (strpos($contenu, '#PCDATA') === false);
349
-	$dtc->elements[$nom] = $filles;
350
-
351
-	return $dtd;
309
+    if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) {
310
+        return -3;
311
+    }
312
+
313
+    list(, $nom, $contenu, $dtd) = $m;
314
+    $nom = expanserEntite($nom, $dtc->macros);
315
+
316
+    if (isset($dtc->elements[$nom])) {
317
+        spip_log("redefinition de l'element $nom dans la DTD");
318
+
319
+        return -4;
320
+    }
321
+    $filles = array();
322
+    $contenu = expanserEntite($contenu, $dtc->macros);
323
+    $val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )';
324
+    if ($val == '(?:EMPTY )') {
325
+        $dtc->regles[$nom] = 'EMPTY';
326
+    } elseif ($val == '(?:ANY )') {
327
+        $dtc->regles[$nom] = 'ANY';
328
+    } else {
329
+        $last = substr($val, -1);
330
+        if (preg_match('/ \w/', $val)
331
+            or (!empty($last) and strpos('*+?', $last) === false)
332
+        ) {
333
+            $dtc->regles[$nom] = "/^$val$/";
334
+        } else {
335
+            $dtc->regles[$nom] = $last;
336
+        }
337
+        $filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY));
338
+
339
+        foreach ($filles as $k) {
340
+            if (!isset($dtc->peres[$k])) {
341
+                $dtc->peres[$k] = array();
342
+            }
343
+            if (!in_array($nom, $dtc->peres[$k])) {
344
+                $dtc->peres[$k][] = $nom;
345
+            }
346
+        }
347
+    }
348
+    $dtc->pcdata[$nom] = (strpos($contenu, '#PCDATA') === false);
349
+    $dtc->elements[$nom] = $filles;
350
+
351
+    return $dtd;
352 352
 }
353 353
 
354 354
 
355 355
 // https://code.spip.net/@analyser_dtd_attlist
356 356
 function analyser_dtd_attlist($dtd, &$dtc, $grammaire) {
357
-	if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) {
358
-		return -5;
359
-	}
360
-
361
-	list(, $nom, $val, $dtd) = $m;
362
-	$nom = expanserEntite($nom, $dtc->macros);
363
-	$val = expanserEntite($val, $dtc->macros);
364
-	if (!isset($dtc->attributs[$nom])) {
365
-		$dtc->attributs[$nom] = array();
366
-	}
367
-
368
-	if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) {
369
-		foreach ($r2 as $m2) {
370
-			$v = preg_match('/^\w+$/', $m2[2]) ? $m2[2]
371
-				: ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/');
372
-			$m21 = expanserEntite($m2[1], $dtc->macros);
373
-			$m25 = expanserEntite($m2[5], $dtc->macros);
374
-			$dtc->attributs[$nom][$m21] = array($v, $m25);
375
-		}
376
-	}
377
-
378
-	return $dtd;
357
+    if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) {
358
+        return -5;
359
+    }
360
+
361
+    list(, $nom, $val, $dtd) = $m;
362
+    $nom = expanserEntite($nom, $dtc->macros);
363
+    $val = expanserEntite($val, $dtc->macros);
364
+    if (!isset($dtc->attributs[$nom])) {
365
+        $dtc->attributs[$nom] = array();
366
+    }
367
+
368
+    if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) {
369
+        foreach ($r2 as $m2) {
370
+            $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2]
371
+                : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/');
372
+            $m21 = expanserEntite($m2[1], $dtc->macros);
373
+            $m25 = expanserEntite($m2[5], $dtc->macros);
374
+            $dtc->attributs[$nom][$m21] = array($v, $m25);
375
+        }
376
+    }
377
+
378
+    return $dtd;
379 379
 }
380 380
 
381 381
 
@@ -391,26 +391,26 @@  discard block
 block discarded – undo
391 391
  * @return string|array
392 392
  **/
393 393
 function expanserEntite($val, $macros = array()) {
394
-	static $vu = array();
395
-	if (!is_string($val)) {
396
-		return $vu;
397
-	}
398
-
399
-	if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) {
400
-		foreach ($r as $m) {
401
-			$ent = $m[1];
402
-			// il peut valoir ""
403
-			if (!isset($macros[$ent])) {
404
-				spip_log("Entite $ent inconnu");
405
-			} else {
406
-				if (!isset($vu[$ent])) {
407
-					$vu[$ent] = 0;
408
-				}
409
-				++$vu[$ent];
410
-				$val = str_replace($m[0], $macros[$ent], $val);
411
-			}
412
-		}
413
-	}
414
-
415
-	return trim(preg_replace('/\s+/', ' ', $val));
394
+    static $vu = array();
395
+    if (!is_string($val)) {
396
+        return $vu;
397
+    }
398
+
399
+    if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) {
400
+        foreach ($r as $m) {
401
+            $ent = $m[1];
402
+            // il peut valoir ""
403
+            if (!isset($macros[$ent])) {
404
+                spip_log("Entite $ent inconnu");
405
+            } else {
406
+                if (!isset($vu[$ent])) {
407
+                    $vu[$ent] = 0;
408
+                }
409
+                ++$vu[$ent];
410
+                $val = str_replace($m[0], $macros[$ent], $val);
411
+            }
412
+        }
413
+    }
414
+
415
+    return trim(preg_replace('/\s+/', ' ', $val));
416 416
 }
Please login to merge, or discard this patch.
ecrire/inc/math.php 2 patches
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 
14 14
 //
15 15
 if (!defined('_ECRIRE_INC_VERSION')) {
16
-	return;
16
+    return;
17 17
 }
18 18
 
19 19
 //
@@ -23,56 +23,56 @@  discard block
 block discarded – undo
23 23
 // https://code.spip.net/@image_math
24 24
 function produire_image_math($tex) {
25 25
 
26
-	switch ($GLOBALS['traiter_math']) {
27
-		// Attention: mathml desactiv'e pour l'instant
28
-		case 'mathml':
29
-			$ext = '.xhtml';
30
-			$server = $GLOBALS['mathml_server'];
31
-			break;
32
-		case 'tex':
33
-			$ext = '.png';
34
-			$server = $GLOBALS['tex_server'];
35
-			break;
36
-		default:
37
-			return $tex;
38
-	}
39
-
40
-	// Regarder dans le repertoire local des images TeX et blocs MathML
41
-	if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) {
42
-		@mkdir($dir_tex, _SPIP_CHMOD);
43
-	}
44
-	$fichier = $dir_tex . md5(trim($tex)) . $ext;
45
-
46
-
47
-	if (!@file_exists($fichier)) {
48
-		// Aller chercher l'image sur le serveur
49
-		if ($server) {
50
-			spip_log($url = $server . '?' . rawurlencode($tex));
51
-			include_spip('inc/distant');
52
-			recuperer_url($url, ['file' => $fichier]);
53
-		}
54
-	}
55
-
56
-
57
-	// Composer la reponse selon presence ou non de l'image
58
-	$tex = entites_html($tex);
59
-	if (@file_exists($fichier)) {
60
-
61
-		// MathML
62
-		if ($GLOBALS['traiter_math'] == 'mathml') {
63
-			return implode("", file($fichier));
64
-		} // TeX
65
-		else {
66
-			list(, , , $size) = @spip_getimagesize($fichier);
67
-			$alt = "alt=\"$tex\" title=\"$tex\"";
68
-
69
-			return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />";
70
-		}
71
-
72
-	} else // pas de fichier
73
-	{
74
-		return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>";
75
-	}
26
+    switch ($GLOBALS['traiter_math']) {
27
+        // Attention: mathml desactiv'e pour l'instant
28
+        case 'mathml':
29
+            $ext = '.xhtml';
30
+            $server = $GLOBALS['mathml_server'];
31
+            break;
32
+        case 'tex':
33
+            $ext = '.png';
34
+            $server = $GLOBALS['tex_server'];
35
+            break;
36
+        default:
37
+            return $tex;
38
+    }
39
+
40
+    // Regarder dans le repertoire local des images TeX et blocs MathML
41
+    if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) {
42
+        @mkdir($dir_tex, _SPIP_CHMOD);
43
+    }
44
+    $fichier = $dir_tex . md5(trim($tex)) . $ext;
45
+
46
+
47
+    if (!@file_exists($fichier)) {
48
+        // Aller chercher l'image sur le serveur
49
+        if ($server) {
50
+            spip_log($url = $server . '?' . rawurlencode($tex));
51
+            include_spip('inc/distant');
52
+            recuperer_url($url, ['file' => $fichier]);
53
+        }
54
+    }
55
+
56
+
57
+    // Composer la reponse selon presence ou non de l'image
58
+    $tex = entites_html($tex);
59
+    if (@file_exists($fichier)) {
60
+
61
+        // MathML
62
+        if ($GLOBALS['traiter_math'] == 'mathml') {
63
+            return implode("", file($fichier));
64
+        } // TeX
65
+        else {
66
+            list(, , , $size) = @spip_getimagesize($fichier);
67
+            $alt = "alt=\"$tex\" title=\"$tex\"";
68
+
69
+            return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />";
70
+        }
71
+
72
+    } else // pas de fichier
73
+    {
74
+        return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>";
75
+    }
76 76
 
77 77
 }
78 78
 
@@ -108,46 +108,46 @@  discard block
 block discarded – undo
108 108
  */
109 109
 function traiter_math($letexte, $source = '', $defaire_amp = false) {
110 110
 
111
-	$texte_a_voir = $letexte;
112
-	while (($debut = strpos($texte_a_voir, "<math>")) !== false) {
113
-		if (!$fin = strpos($texte_a_voir, "</math>")) {
114
-			$fin = strlen($texte_a_voir);
115
-		}
116
-
117
-		$texte_debut = substr($texte_a_voir, 0, $debut);
118
-		$texte_milieu = substr($texte_a_voir,
119
-			$debut + strlen("<math>"), $fin - $debut - strlen("<math>"));
120
-		$texte_fin = substr($texte_a_voir,
121
-			$fin + strlen("</math>"), strlen($texte_a_voir));
122
-
123
-		// Les doubles $$x^2$$ en mode 'div'
124
-		while ((preg_match(",[$][$]([^$]+)[$][$],", $texte_milieu, $regs))) {
125
-			$expression = $regs[1];
126
-			if ($defaire_amp) {
127
-				$expression = str_replace('&amp;', '&', $expression);
128
-			}
129
-			$echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n";
130
-			$pos = strpos($texte_milieu, $regs[0]);
131
-			$texte_milieu = substr($texte_milieu, 0, $pos)
132
-				. code_echappement($echap, $source)
133
-				. substr($texte_milieu, $pos + strlen($regs[0]));
134
-		}
135
-
136
-		// Les simples $x^2$ en mode 'span'
137
-		while ((preg_match(",[$]([^$]+)[$],", $texte_milieu, $regs))) {
138
-			$expression = $regs[1];
139
-			if ($defaire_amp) {
140
-				$expression = str_replace('&amp;', '&', $expression);
141
-			}
142
-			$echap = produire_image_math($expression);
143
-			$pos = strpos($texte_milieu, $regs[0]);
144
-			$texte_milieu = substr($texte_milieu, 0, $pos)
145
-				. code_echappement($echap, $source)
146
-				. substr($texte_milieu, $pos + strlen($regs[0]));
147
-		}
148
-
149
-		$texte_a_voir = $texte_debut . $texte_milieu . $texte_fin;
150
-	}
151
-
152
-	return $texte_a_voir;
111
+    $texte_a_voir = $letexte;
112
+    while (($debut = strpos($texte_a_voir, "<math>")) !== false) {
113
+        if (!$fin = strpos($texte_a_voir, "</math>")) {
114
+            $fin = strlen($texte_a_voir);
115
+        }
116
+
117
+        $texte_debut = substr($texte_a_voir, 0, $debut);
118
+        $texte_milieu = substr($texte_a_voir,
119
+            $debut + strlen("<math>"), $fin - $debut - strlen("<math>"));
120
+        $texte_fin = substr($texte_a_voir,
121
+            $fin + strlen("</math>"), strlen($texte_a_voir));
122
+
123
+        // Les doubles $$x^2$$ en mode 'div'
124
+        while ((preg_match(",[$][$]([^$]+)[$][$],", $texte_milieu, $regs))) {
125
+            $expression = $regs[1];
126
+            if ($defaire_amp) {
127
+                $expression = str_replace('&amp;', '&', $expression);
128
+            }
129
+            $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n";
130
+            $pos = strpos($texte_milieu, $regs[0]);
131
+            $texte_milieu = substr($texte_milieu, 0, $pos)
132
+                . code_echappement($echap, $source)
133
+                . substr($texte_milieu, $pos + strlen($regs[0]));
134
+        }
135
+
136
+        // Les simples $x^2$ en mode 'span'
137
+        while ((preg_match(",[$]([^$]+)[$],", $texte_milieu, $regs))) {
138
+            $expression = $regs[1];
139
+            if ($defaire_amp) {
140
+                $expression = str_replace('&amp;', '&', $expression);
141
+            }
142
+            $echap = produire_image_math($expression);
143
+            $pos = strpos($texte_milieu, $regs[0]);
144
+            $texte_milieu = substr($texte_milieu, 0, $pos)
145
+                . code_echappement($echap, $source)
146
+                . substr($texte_milieu, $pos + strlen($regs[0]));
147
+        }
148
+
149
+        $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin;
150
+    }
151
+
152
+    return $texte_a_voir;
153 153
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -38,16 +38,16 @@  discard block
 block discarded – undo
38 38
 	}
39 39
 
40 40
 	// Regarder dans le repertoire local des images TeX et blocs MathML
41
-	if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) {
41
+	if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/')) {
42 42
 		@mkdir($dir_tex, _SPIP_CHMOD);
43 43
 	}
44
-	$fichier = $dir_tex . md5(trim($tex)) . $ext;
44
+	$fichier = $dir_tex.md5(trim($tex)).$ext;
45 45
 
46 46
 
47 47
 	if (!@file_exists($fichier)) {
48 48
 		// Aller chercher l'image sur le serveur
49 49
 		if ($server) {
50
-			spip_log($url = $server . '?' . rawurlencode($tex));
50
+			spip_log($url = $server.'?'.rawurlencode($tex));
51 51
 			include_spip('inc/distant');
52 52
 			recuperer_url($url, ['file' => $fichier]);
53 53
 		}
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 			return implode("", file($fichier));
64 64
 		} // TeX
65 65
 		else {
66
-			list(, , , $size) = @spip_getimagesize($fichier);
66
+			list(,,, $size) = @spip_getimagesize($fichier);
67 67
 			$alt = "alt=\"$tex\" title=\"$tex\"";
68 68
 
69 69
 			return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />";
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 			if ($defaire_amp) {
127 127
 				$expression = str_replace('&amp;', '&', $expression);
128 128
 			}
129
-			$echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n";
129
+			$echap = "\n<p class=\"spip\" style=\"text-align: center;\">".produire_image_math($expression)."</p>\n";
130 130
 			$pos = strpos($texte_milieu, $regs[0]);
131 131
 			$texte_milieu = substr($texte_milieu, 0, $pos)
132 132
 				. code_echappement($echap, $source)
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 				. substr($texte_milieu, $pos + strlen($regs[0]));
147 147
 		}
148 148
 
149
-		$texte_a_voir = $texte_debut . $texte_milieu . $texte_fin;
149
+		$texte_a_voir = $texte_debut.$texte_milieu.$texte_fin;
150 150
 	}
151 151
 
152 152
 	return $texte_a_voir;
Please login to merge, or discard this patch.
ecrire/inc/distant.php 1 patch
Indentation   +1062 added lines, -1062 removed lines patch added patch discarded remove patch
@@ -16,32 +16,32 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Distant
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 if (!defined('_INC_DISTANT_VERSION_HTTP')) {
23
-	define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
23
+    define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
24 24
 }
25 25
 if (!defined('_INC_DISTANT_CONTENT_ENCODING')) {
26
-	define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
26
+    define('_INC_DISTANT_CONTENT_ENCODING', 'gzip');
27 27
 }
28 28
 if (!defined('_INC_DISTANT_USER_AGENT')) {
29
-	define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
29
+    define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')');
30 30
 }
31 31
 if (!defined('_INC_DISTANT_MAX_SIZE')) {
32
-	define('_INC_DISTANT_MAX_SIZE', 2097152);
32
+    define('_INC_DISTANT_MAX_SIZE', 2097152);
33 33
 }
34 34
 if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) {
35
-	define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
35
+    define('_INC_DISTANT_CONNECT_TIMEOUT', 10);
36 36
 }
37 37
 
38 38
 define('_REGEXP_COPIE_LOCALE', ',' 	.
39
-	preg_replace(
40
-		'@^https?:@',
41
-		'https?:',
42
-		(isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '')
43
-	)
44
-	. '/?spip.php[?]action=acceder_document.*file=(.*)$,');
39
+    preg_replace(
40
+        '@^https?:@',
41
+        'https?:',
42
+        (isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '')
43
+    )
44
+    . '/?spip.php[?]action=acceder_document.*file=(.*)$,');
45 45
 
46 46
 //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait)
47 47
 
@@ -68,77 +68,77 @@  discard block
 block discarded – undo
68 68
  */
69 69
 function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null) {
70 70
 
71
-	// si c'est la protection de soi-meme, retourner le path
72
-	if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
73
-		$source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
74
-
75
-		return @file_exists($source) ? $source : false;
76
-	}
77
-
78
-	if (is_null($local)) {
79
-		$local = fichier_copie_locale($source);
80
-	} else {
81
-		if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) {
82
-			$local = substr($local, strlen(_DIR_RACINE));
83
-		}
84
-	}
85
-
86
-	// si $local = '' c'est un fichier refuse par fichier_copie_locale(),
87
-	// par exemple un fichier qui ne figure pas dans nos documents ;
88
-	// dans ce cas on n'essaie pas de le telecharger pour ensuite echouer
89
-	if (!$local) {
90
-		return false;
91
-	}
92
-
93
-	$localrac = _DIR_RACINE . $local;
94
-	$t = ($mode == 'force') ? false : @file_exists($localrac);
95
-
96
-	// test d'existence du fichier
97
-	if ($mode == 'test') {
98
-		return $t ? $local : '';
99
-	}
100
-
101
-	// sinon voir si on doit/peut le telecharger
102
-	if ($local == $source or !tester_url_absolue($source)) {
103
-		return $local;
104
-	}
105
-
106
-	if ($mode == 'modif' or !$t) {
107
-		// passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
108
-		// et des eventuelles recuperations concurantes
109
-		include_spip('inc/acces');
110
-		if (!$taille_max) {
111
-			$taille_max = _COPIE_LOCALE_MAX_SIZE;
112
-		}
113
-		$res = recuperer_url(
114
-			$source,
115
-			array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '')
116
-		);
117
-		if (!$res or (!$res['length'] and $res['status'] != 304)) {
118
-			spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE);
119
-		}
120
-		if (!$res['length']) {
121
-			// si $t c'est sans doute juste un not-modified-since
122
-			return $t ? $local : false;
123
-		}
124
-		spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant');
125
-
126
-		// pour une eventuelle indexation
127
-		pipeline(
128
-			'post_edition',
129
-			array(
130
-				'args' => array(
131
-					'operation' => 'copie_locale',
132
-					'source' => $source,
133
-					'fichier' => $local,
134
-					'http_res' => $res['length'],
135
-				),
136
-				'data' => null
137
-			)
138
-		);
139
-	}
140
-
141
-	return $local;
71
+    // si c'est la protection de soi-meme, retourner le path
72
+    if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
73
+        $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]);
74
+
75
+        return @file_exists($source) ? $source : false;
76
+    }
77
+
78
+    if (is_null($local)) {
79
+        $local = fichier_copie_locale($source);
80
+    } else {
81
+        if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) {
82
+            $local = substr($local, strlen(_DIR_RACINE));
83
+        }
84
+    }
85
+
86
+    // si $local = '' c'est un fichier refuse par fichier_copie_locale(),
87
+    // par exemple un fichier qui ne figure pas dans nos documents ;
88
+    // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer
89
+    if (!$local) {
90
+        return false;
91
+    }
92
+
93
+    $localrac = _DIR_RACINE . $local;
94
+    $t = ($mode == 'force') ? false : @file_exists($localrac);
95
+
96
+    // test d'existence du fichier
97
+    if ($mode == 'test') {
98
+        return $t ? $local : '';
99
+    }
100
+
101
+    // sinon voir si on doit/peut le telecharger
102
+    if ($local == $source or !tester_url_absolue($source)) {
103
+        return $local;
104
+    }
105
+
106
+    if ($mode == 'modif' or !$t) {
107
+        // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
108
+        // et des eventuelles recuperations concurantes
109
+        include_spip('inc/acces');
110
+        if (!$taille_max) {
111
+            $taille_max = _COPIE_LOCALE_MAX_SIZE;
112
+        }
113
+        $res = recuperer_url(
114
+            $source,
115
+            array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '')
116
+        );
117
+        if (!$res or (!$res['length'] and $res['status'] != 304)) {
118
+            spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], 'distant' . _LOG_INFO_IMPORTANTE);
119
+        }
120
+        if (!$res['length']) {
121
+            // si $t c'est sans doute juste un not-modified-since
122
+            return $t ? $local : false;
123
+        }
124
+        spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK', 'distant');
125
+
126
+        // pour une eventuelle indexation
127
+        pipeline(
128
+            'post_edition',
129
+            array(
130
+                'args' => array(
131
+                    'operation' => 'copie_locale',
132
+                    'source' => $source,
133
+                    'fichier' => $local,
134
+                    'http_res' => $res['length'],
135
+                ),
136
+                'data' => null
137
+            )
138
+        );
139
+    }
140
+
141
+    return $local;
142 142
 }
143 143
 
144 144
 /**
@@ -153,88 +153,88 @@  discard block
 block discarded – undo
153 153
  *   url ou false en cas d'echec
154 154
  */
155 155
 function valider_url_distante($url, $known_hosts = array()) {
156
-	if (!function_exists('protocole_verifier')){
157
-		include_spip('inc/filtres_mini');
158
-	}
156
+    if (!function_exists('protocole_verifier')){
157
+        include_spip('inc/filtres_mini');
158
+    }
159 159
 
160
-	if (!protocole_verifier($url, array('http', 'https'))) {
161
-		return false;
162
-	}
160
+    if (!protocole_verifier($url, array('http', 'https'))) {
161
+        return false;
162
+    }
163 163
 	
164
-	$parsed_url = parse_url($url);
165
-	if (!$parsed_url or empty($parsed_url['host']) ) {
166
-		return false;
167
-	}
168
-
169
-	if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
170
-		return false;
171
-	}
172
-
173
-	if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
174
-		return false;
175
-	}
176
-
177
-	if (!is_array($known_hosts)) {
178
-		$known_hosts = array($known_hosts);
179
-	}
180
-	$known_hosts[] = $GLOBALS['meta']['adresse_site'];
181
-	$known_hosts[] = url_de_base();
182
-	$known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
183
-
184
-	$is_known_host = false;
185
-	foreach ($known_hosts as $known_host) {
186
-		$parse_known = parse_url($known_host);
187
-		if ($parse_known
188
-		  and strtolower($parse_known['host']) === strtolower($parsed_url['host'])) {
189
-			$is_known_host = true;
190
-			break;
191
-		}
192
-	}
193
-
194
-	if (!$is_known_host) {
195
-		$host = trim($parsed_url['host'], '.');
196
-		if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) {
197
-			$ip = $host;
198
-		} else {
199
-			$ip = gethostbyname($host);
200
-			if ($ip === $host) {
201
-				// Error condition for gethostbyname()
202
-				$ip = false;
203
-			}
204
-		}
205
-		if ($ip) {
206
-			$parts = array_map('intval', explode( '.', $ip ));
207
-			if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0]
208
-			  or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] )
209
-			  or ( 192 === $parts[0] && 168 === $parts[1] )
210
-			) {
211
-				return false;
212
-			}
213
-		}
214
-	}
215
-
216
-	if (empty($parsed_url['port'])) {
217
-		return $url;
218
-	}
219
-
220
-	$port = $parsed_url['port'];
221
-	if ($port === 80  or $port === 443  or $port === 8080) {
222
-		return $url;
223
-	}
224
-
225
-	if ($is_known_host) {
226
-		foreach ($known_hosts as $known_host) {
227
-			$parse_known = parse_url($known_host);
228
-			if ($parse_known
229
-				and !empty($parse_known['port'])
230
-			  and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
231
-			  and $parse_known['port'] == $port) {
232
-				return $url;
233
-			}
234
-		}
235
-	}
236
-
237
-	return false;
164
+    $parsed_url = parse_url($url);
165
+    if (!$parsed_url or empty($parsed_url['host']) ) {
166
+        return false;
167
+    }
168
+
169
+    if (isset($parsed_url['user']) or isset($parsed_url['pass'])) {
170
+        return false;
171
+    }
172
+
173
+    if (false !== strpbrk($parsed_url['host'], ':#?[]')) {
174
+        return false;
175
+    }
176
+
177
+    if (!is_array($known_hosts)) {
178
+        $known_hosts = array($known_hosts);
179
+    }
180
+    $known_hosts[] = $GLOBALS['meta']['adresse_site'];
181
+    $known_hosts[] = url_de_base();
182
+    $known_hosts = pipeline('declarer_hosts_distants', $known_hosts);
183
+
184
+    $is_known_host = false;
185
+    foreach ($known_hosts as $known_host) {
186
+        $parse_known = parse_url($known_host);
187
+        if ($parse_known
188
+          and strtolower($parse_known['host']) === strtolower($parsed_url['host'])) {
189
+            $is_known_host = true;
190
+            break;
191
+        }
192
+    }
193
+
194
+    if (!$is_known_host) {
195
+        $host = trim($parsed_url['host'], '.');
196
+        if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) {
197
+            $ip = $host;
198
+        } else {
199
+            $ip = gethostbyname($host);
200
+            if ($ip === $host) {
201
+                // Error condition for gethostbyname()
202
+                $ip = false;
203
+            }
204
+        }
205
+        if ($ip) {
206
+            $parts = array_map('intval', explode( '.', $ip ));
207
+            if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0]
208
+              or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] )
209
+              or ( 192 === $parts[0] && 168 === $parts[1] )
210
+            ) {
211
+                return false;
212
+            }
213
+        }
214
+    }
215
+
216
+    if (empty($parsed_url['port'])) {
217
+        return $url;
218
+    }
219
+
220
+    $port = $parsed_url['port'];
221
+    if ($port === 80  or $port === 443  or $port === 8080) {
222
+        return $url;
223
+    }
224
+
225
+    if ($is_known_host) {
226
+        foreach ($known_hosts as $known_host) {
227
+            $parse_known = parse_url($known_host);
228
+            if ($parse_known
229
+                and !empty($parse_known['port'])
230
+              and strtolower($parse_known['host']) === strtolower($parsed_url['host'])
231
+              and $parse_known['port'] == $port) {
232
+                return $url;
233
+            }
234
+        }
235
+    }
236
+
237
+    return false;
238 238
 }
239 239
 
240 240
 /**
@@ -254,86 +254,86 @@  discard block
 block discarded – undo
254 254
  */
255 255
 function prepare_donnees_post($donnees, $boundary = '') {
256 256
 
257
-	// permettre a la fonction qui a demande le post de formater elle meme ses donnees
258
-	// pour un appel soap par exemple
259
-	// l'entete est separe des donnees par un double retour a la ligne
260
-	// on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
261
-	if (is_string($donnees) && strlen($donnees)) {
262
-		$entete = '';
263
-		// on repasse tous les \r\n et \r en simples \n
264
-		$donnees = str_replace("\r\n", "\n", $donnees);
265
-		$donnees = str_replace("\r", "\n", $donnees);
266
-		// un double retour a la ligne signifie la fin de l'entete et le debut des donnees
267
-		$p = strpos($donnees, "\n\n");
268
-		if ($p !== false) {
269
-			$entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
270
-			$donnees = substr($donnees, $p + 2);
271
-		}
272
-		$chaine = str_replace("\n", "\r\n", $donnees);
273
-	} else {
274
-		/* boundary automatique */
275
-		// Si on a plus de 500 octects de donnees, on "boundarise"
276
-		if ($boundary === '') {
277
-			$taille = 0;
278
-			foreach ($donnees as $cle => $valeur) {
279
-				if (is_array($valeur)) {
280
-					foreach ($valeur as $val2) {
281
-						$taille += strlen($val2);
282
-					}
283
-				} else {
284
-					// faut-il utiliser spip_strlen() dans inc/charsets ?
285
-					$taille += strlen($valeur);
286
-				}
287
-			}
288
-			if ($taille > 500) {
289
-				$boundary = substr(md5(rand() . 'spip'), 0, 8);
290
-			}
291
-		}
292
-
293
-		if (is_string($boundary) and strlen($boundary)) {
294
-			// fabrique une chaine HTTP pour un POST avec boundary
295
-			$entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
296
-			$chaine = '';
297
-			if (is_array($donnees)) {
298
-				foreach ($donnees as $cle => $valeur) {
299
-					if (is_array($valeur)) {
300
-						foreach ($valeur as $val2) {
301
-							$chaine .= "\r\n--$boundary\r\n";
302
-							$chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
303
-							$chaine .= "\r\n";
304
-							$chaine .= $val2;
305
-						}
306
-					} else {
307
-						$chaine .= "\r\n--$boundary\r\n";
308
-						$chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
309
-						$chaine .= "\r\n";
310
-						$chaine .= $valeur;
311
-					}
312
-				}
313
-				$chaine .= "\r\n--$boundary\r\n";
314
-			}
315
-		} else {
316
-			// fabrique une chaine HTTP simple pour un POST
317
-			$entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
318
-			$chaine = array();
319
-			if (is_array($donnees)) {
320
-				foreach ($donnees as $cle => $valeur) {
321
-					if (is_array($valeur)) {
322
-						foreach ($valeur as $val2) {
323
-							$chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
324
-						}
325
-					} else {
326
-						$chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
327
-					}
328
-				}
329
-				$chaine = implode('&', $chaine);
330
-			} else {
331
-				$chaine = $donnees;
332
-			}
333
-		}
334
-	}
335
-
336
-	return array($entete, $chaine);
257
+    // permettre a la fonction qui a demande le post de formater elle meme ses donnees
258
+    // pour un appel soap par exemple
259
+    // l'entete est separe des donnees par un double retour a la ligne
260
+    // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n
261
+    if (is_string($donnees) && strlen($donnees)) {
262
+        $entete = '';
263
+        // on repasse tous les \r\n et \r en simples \n
264
+        $donnees = str_replace("\r\n", "\n", $donnees);
265
+        $donnees = str_replace("\r", "\n", $donnees);
266
+        // un double retour a la ligne signifie la fin de l'entete et le debut des donnees
267
+        $p = strpos($donnees, "\n\n");
268
+        if ($p !== false) {
269
+            $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1));
270
+            $donnees = substr($donnees, $p + 2);
271
+        }
272
+        $chaine = str_replace("\n", "\r\n", $donnees);
273
+    } else {
274
+        /* boundary automatique */
275
+        // Si on a plus de 500 octects de donnees, on "boundarise"
276
+        if ($boundary === '') {
277
+            $taille = 0;
278
+            foreach ($donnees as $cle => $valeur) {
279
+                if (is_array($valeur)) {
280
+                    foreach ($valeur as $val2) {
281
+                        $taille += strlen($val2);
282
+                    }
283
+                } else {
284
+                    // faut-il utiliser spip_strlen() dans inc/charsets ?
285
+                    $taille += strlen($valeur);
286
+                }
287
+            }
288
+            if ($taille > 500) {
289
+                $boundary = substr(md5(rand() . 'spip'), 0, 8);
290
+            }
291
+        }
292
+
293
+        if (is_string($boundary) and strlen($boundary)) {
294
+            // fabrique une chaine HTTP pour un POST avec boundary
295
+            $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n";
296
+            $chaine = '';
297
+            if (is_array($donnees)) {
298
+                foreach ($donnees as $cle => $valeur) {
299
+                    if (is_array($valeur)) {
300
+                        foreach ($valeur as $val2) {
301
+                            $chaine .= "\r\n--$boundary\r\n";
302
+                            $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n";
303
+                            $chaine .= "\r\n";
304
+                            $chaine .= $val2;
305
+                        }
306
+                    } else {
307
+                        $chaine .= "\r\n--$boundary\r\n";
308
+                        $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n";
309
+                        $chaine .= "\r\n";
310
+                        $chaine .= $valeur;
311
+                    }
312
+                }
313
+                $chaine .= "\r\n--$boundary\r\n";
314
+            }
315
+        } else {
316
+            // fabrique une chaine HTTP simple pour un POST
317
+            $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
318
+            $chaine = array();
319
+            if (is_array($donnees)) {
320
+                foreach ($donnees as $cle => $valeur) {
321
+                    if (is_array($valeur)) {
322
+                        foreach ($valeur as $val2) {
323
+                            $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2);
324
+                        }
325
+                    } else {
326
+                        $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur);
327
+                    }
328
+                }
329
+                $chaine = implode('&', $chaine);
330
+            } else {
331
+                $chaine = $donnees;
332
+            }
333
+        }
334
+    }
335
+
336
+    return array($entete, $chaine);
337 337
 }
338 338
 
339 339
 /**
@@ -347,20 +347,20 @@  discard block
 block discarded – undo
347 347
  */
348 348
 function url_to_ascii($url_idn) {
349 349
 
350
-	if ($parts = parse_url($url_idn)) {
351
-		$host = $parts['host'];
352
-		if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
353
-			include_spip('inc/idna_convert.class');
354
-			$IDN = new idna_convert();
355
-			$host_ascii = $IDN->encode($host);
356
-			$url_idn = explode($host, $url_idn, 2);
357
-			$url_idn = implode($host_ascii, $url_idn);
358
-		}
359
-		// et on urlencode les char utf si besoin dans le path
360
-		$url_idn = preg_replace_callback('/[^\x20-\x7f]/', function($match) { return urlencode($match[0]); }, $url_idn);
361
-	}
362
-
363
-	return $url_idn;
350
+    if ($parts = parse_url($url_idn)) {
351
+        $host = $parts['host'];
352
+        if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
353
+            include_spip('inc/idna_convert.class');
354
+            $IDN = new idna_convert();
355
+            $host_ascii = $IDN->encode($host);
356
+            $url_idn = explode($host, $url_idn, 2);
357
+            $url_idn = implode($host_ascii, $url_idn);
358
+        }
359
+        // et on urlencode les char utf si besoin dans le path
360
+        $url_idn = preg_replace_callback('/[^\x20-\x7f]/', function($match) { return urlencode($match[0]); }, $url_idn);
361
+    }
362
+
363
+    return $url_idn;
364 364
 }
365 365
 
366 366
 /**
@@ -400,176 +400,176 @@  discard block
 block discarded – undo
400 400
  *     string file : nom du fichier si enregistre dans un fichier
401 401
  */
402 402
 function recuperer_url($url, $options = array()) {
403
-	$default = array(
404
-		'transcoder' => false,
405
-		'methode' => 'GET',
406
-		'taille_max' => null,
407
-		'datas' => '',
408
-		'boundary' => '',
409
-		'refuser_gz' => false,
410
-		'if_modified_since' => '',
411
-		'uri_referer' => '',
412
-		'file' => '',
413
-		'follow_location' => 10,
414
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
415
-	);
416
-	$options = array_merge($default, $options);
417
-	// copier directement dans un fichier ?
418
-	$copy = $options['file'];
419
-
420
-	if ($options['methode'] == 'HEAD') {
421
-		$options['taille_max'] = 0;
422
-	}
423
-	if (is_null($options['taille_max'])) {
424
-		$options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
425
-	}
426
-
427
-	if (!empty($options['datas'])) {
428
-		list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
429
-		if (stripos($head, 'Content-Length:') === false) {
430
-			$head .= 'Content-Length: ' . strlen($postdata);
431
-		}
432
-		$options['datas'] = $head . "\r\n\r\n" . $postdata;
433
-		if (strlen($postdata)) {
434
-			$options['methode'] = 'POST';
435
-		}
436
-	}
437
-
438
-	// Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
439
-	$url = preg_replace(',^feed://,i', 'http://', $url);
440
-	if (!tester_url_absolue($url)) {
441
-		$url = 'http://' . $url;
442
-	} elseif (strncmp($url, '//', 2) == 0) {
443
-		$url = 'http:' . $url;
444
-	}
445
-
446
-	$url = url_to_ascii($url);
447
-
448
-	$result = array(
449
-		'status' => 0,
450
-		'headers' => '',
451
-		'page' => '',
452
-		'length' => 0,
453
-		'last_modified' => '',
454
-		'location' => '',
455
-		'url' => $url
456
-	);
457
-
458
-	// si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
459
-	$refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
460
-
461
-	// ouvrir la connexion et envoyer la requete et ses en-tetes
462
-	list($handle, $fopen) = init_http(
463
-		$options['methode'],
464
-		$url,
465
-		$refuser_gz,
466
-		$options['uri_referer'],
467
-		$options['datas'],
468
-		$options['version_http'],
469
-		$options['if_modified_since']
470
-	);
471
-	if (!$handle) {
472
-		spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
473
-
474
-		return false;
475
-	}
476
-
477
-	// Sauf en fopen, envoyer le flux d'entree
478
-	// et recuperer les en-tetes de reponses
479
-	if (!$fopen) {
480
-		$res = recuperer_entetes_complets($handle, $options['if_modified_since']);
481
-		if (!$res) {
482
-			fclose($handle);
483
-			$t = @parse_url($url);
484
-			$host = $t['host'];
485
-			// Chinoisierie inexplicable pour contrer
486
-			// les actions liberticides de l'empire du milieu
487
-			if (!need_proxy($host)
488
-				and $res = @file_get_contents($url)
489
-			) {
490
-				$result['length'] = strlen($res);
491
-				if ($copy) {
492
-					ecrire_fichier($copy, $res);
493
-					$result['file'] = $copy;
494
-				} else {
495
-					$result['page'] = $res;
496
-				}
497
-				$res = array(
498
-					'status' => 200,
499
-				);
500
-			} else {
501
-				spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
502
-				return false;
503
-			}
504
-		} elseif ($res['location'] and $options['follow_location']) {
505
-			$options['follow_location']--;
506
-			fclose($handle);
507
-			include_spip('inc/filtres');
508
-			$url = suivre_lien($url, $res['location']);
509
-			spip_log("recuperer_url recommence sur $url", 'distant');
510
-
511
-			return recuperer_url($url, $options);
512
-		} elseif ($res['status'] !== 200) {
513
-			spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
514
-		}
515
-		$result['status'] = $res['status'];
516
-		if (isset($res['headers'])) {
517
-			$result['headers'] = $res['headers'];
518
-		}
519
-		if (isset($res['last_modified'])) {
520
-			$result['last_modified'] = $res['last_modified'];
521
-		}
522
-		if (isset($res['location'])) {
523
-			$result['location'] = $res['location'];
524
-		}
525
-	}
526
-
527
-	// on ne veut que les entetes
528
-	if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
529
-		return $result;
530
-	}
531
-
532
-
533
-	// s'il faut deballer, le faire via un fichier temporaire
534
-	// sinon la memoire explose pour les gros flux
535
-
536
-	$gz = false;
537
-	if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
538
-		$gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
539
-	}
540
-
541
-	// si on a pas deja recuperer le contenu par une methode detournee
542
-	if (!$result['length']) {
543
-		$res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy);
544
-		fclose($handle);
545
-		if ($copy) {
546
-			$result['length'] = $res;
547
-			$result['file'] = $copy;
548
-		} elseif ($res) {
549
-			$result['page'] = &$res;
550
-			$result['length'] = strlen($result['page']);
551
-		}
552
-		if (!$result['status']) {
553
-			$result['status'] = 200; // on a reussi, donc !
554
-		}
555
-	}
556
-	if (!$result['page']) {
557
-		return $result;
558
-	}
559
-
560
-	// Decompresser au besoin
561
-	if ($gz) {
562
-		$result['page'] = implode('', gzfile($gz));
563
-		supprimer_fichier($gz);
564
-	}
565
-
566
-	// Faut-il l'importer dans notre charset local ?
567
-	if ($options['transcoder']) {
568
-		include_spip('inc/charsets');
569
-		$result['page'] = transcoder_page($result['page'], $result['headers']);
570
-	}
571
-
572
-	return $result;
403
+    $default = array(
404
+        'transcoder' => false,
405
+        'methode' => 'GET',
406
+        'taille_max' => null,
407
+        'datas' => '',
408
+        'boundary' => '',
409
+        'refuser_gz' => false,
410
+        'if_modified_since' => '',
411
+        'uri_referer' => '',
412
+        'file' => '',
413
+        'follow_location' => 10,
414
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
415
+    );
416
+    $options = array_merge($default, $options);
417
+    // copier directement dans un fichier ?
418
+    $copy = $options['file'];
419
+
420
+    if ($options['methode'] == 'HEAD') {
421
+        $options['taille_max'] = 0;
422
+    }
423
+    if (is_null($options['taille_max'])) {
424
+        $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE;
425
+    }
426
+
427
+    if (!empty($options['datas'])) {
428
+        list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']);
429
+        if (stripos($head, 'Content-Length:') === false) {
430
+            $head .= 'Content-Length: ' . strlen($postdata);
431
+        }
432
+        $options['datas'] = $head . "\r\n\r\n" . $postdata;
433
+        if (strlen($postdata)) {
434
+            $options['methode'] = 'POST';
435
+        }
436
+    }
437
+
438
+    // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole
439
+    $url = preg_replace(',^feed://,i', 'http://', $url);
440
+    if (!tester_url_absolue($url)) {
441
+        $url = 'http://' . $url;
442
+    } elseif (strncmp($url, '//', 2) == 0) {
443
+        $url = 'http:' . $url;
444
+    }
445
+
446
+    $url = url_to_ascii($url);
447
+
448
+    $result = array(
449
+        'status' => 0,
450
+        'headers' => '',
451
+        'page' => '',
452
+        'length' => 0,
453
+        'last_modified' => '',
454
+        'location' => '',
455
+        'url' => $url
456
+    );
457
+
458
+    // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz
459
+    $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false);
460
+
461
+    // ouvrir la connexion et envoyer la requete et ses en-tetes
462
+    list($handle, $fopen) = init_http(
463
+        $options['methode'],
464
+        $url,
465
+        $refuser_gz,
466
+        $options['uri_referer'],
467
+        $options['datas'],
468
+        $options['version_http'],
469
+        $options['if_modified_since']
470
+    );
471
+    if (!$handle) {
472
+        spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR);
473
+
474
+        return false;
475
+    }
476
+
477
+    // Sauf en fopen, envoyer le flux d'entree
478
+    // et recuperer les en-tetes de reponses
479
+    if (!$fopen) {
480
+        $res = recuperer_entetes_complets($handle, $options['if_modified_since']);
481
+        if (!$res) {
482
+            fclose($handle);
483
+            $t = @parse_url($url);
484
+            $host = $t['host'];
485
+            // Chinoisierie inexplicable pour contrer
486
+            // les actions liberticides de l'empire du milieu
487
+            if (!need_proxy($host)
488
+                and $res = @file_get_contents($url)
489
+            ) {
490
+                $result['length'] = strlen($res);
491
+                if ($copy) {
492
+                    ecrire_fichier($copy, $res);
493
+                    $result['file'] = $copy;
494
+                } else {
495
+                    $result['page'] = $res;
496
+                }
497
+                $res = array(
498
+                    'status' => 200,
499
+                );
500
+            } else {
501
+                spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR);
502
+                return false;
503
+            }
504
+        } elseif ($res['location'] and $options['follow_location']) {
505
+            $options['follow_location']--;
506
+            fclose($handle);
507
+            include_spip('inc/filtres');
508
+            $url = suivre_lien($url, $res['location']);
509
+            spip_log("recuperer_url recommence sur $url", 'distant');
510
+
511
+            return recuperer_url($url, $options);
512
+        } elseif ($res['status'] !== 200) {
513
+            spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant');
514
+        }
515
+        $result['status'] = $res['status'];
516
+        if (isset($res['headers'])) {
517
+            $result['headers'] = $res['headers'];
518
+        }
519
+        if (isset($res['last_modified'])) {
520
+            $result['last_modified'] = $res['last_modified'];
521
+        }
522
+        if (isset($res['location'])) {
523
+            $result['location'] = $res['location'];
524
+        }
525
+    }
526
+
527
+    // on ne veut que les entetes
528
+    if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') {
529
+        return $result;
530
+    }
531
+
532
+
533
+    // s'il faut deballer, le faire via un fichier temporaire
534
+    // sinon la memoire explose pour les gros flux
535
+
536
+    $gz = false;
537
+    if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) {
538
+        $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz');
539
+    }
540
+
541
+    // si on a pas deja recuperer le contenu par une methode detournee
542
+    if (!$result['length']) {
543
+        $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy);
544
+        fclose($handle);
545
+        if ($copy) {
546
+            $result['length'] = $res;
547
+            $result['file'] = $copy;
548
+        } elseif ($res) {
549
+            $result['page'] = &$res;
550
+            $result['length'] = strlen($result['page']);
551
+        }
552
+        if (!$result['status']) {
553
+            $result['status'] = 200; // on a reussi, donc !
554
+        }
555
+    }
556
+    if (!$result['page']) {
557
+        return $result;
558
+    }
559
+
560
+    // Decompresser au besoin
561
+    if ($gz) {
562
+        $result['page'] = implode('', gzfile($gz));
563
+        supprimer_fichier($gz);
564
+    }
565
+
566
+    // Faut-il l'importer dans notre charset local ?
567
+    if ($options['transcoder']) {
568
+        include_spip('inc/charsets');
569
+        $result['page'] = transcoder_page($result['page'], $result['headers']);
570
+    }
571
+
572
+    return $result;
573 573
 }
574 574
 
575 575
 /**
@@ -585,72 +585,72 @@  discard block
 block discarded – undo
585 585
  * @return array|bool|mixed
586 586
  */
587 587
 function recuperer_url_cache($url, $options = array()) {
588
-	if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
589
-		define('_DELAI_RECUPERER_URL_CACHE', 3600);
590
-	}
591
-	$default = array(
592
-		'transcoder' => false,
593
-		'methode' => 'GET',
594
-		'taille_max' => null,
595
-		'datas' => '',
596
-		'boundary' => '',
597
-		'refuser_gz' => false,
598
-		'if_modified_since' => '',
599
-		'uri_referer' => '',
600
-		'file' => '',
601
-		'follow_location' => 10,
602
-		'version_http' => _INC_DISTANT_VERSION_HTTP,
603
-		'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE,
604
-	);
605
-	$options = array_merge($default, $options);
606
-
607
-	// cas ou il n'est pas possible de cacher
608
-	if (!empty($options['data']) or $options['methode'] == 'POST') {
609
-		return recuperer_url($url, $options);
610
-	}
611
-
612
-	// ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
613
-	static $errors = array();
614
-	if (isset($errors[$url])) {
615
-		return $errors[$url];
616
-	}
617
-
618
-	$sig = $options;
619
-	unset($sig['if_modified_since']);
620
-	unset($sig['delai_cache']);
621
-	$sig['url'] = $url;
622
-
623
-	$dir = sous_repertoire(_DIR_CACHE, 'curl');
624
-	$cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
625
-	$sub = sous_repertoire($dir, substr($cache, 0, 2));
626
-	$cache = "$sub$cache";
627
-
628
-	$res = false;
629
-	$is_cached = file_exists($cache);
630
-	if ($is_cached
631
-		and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
632
-	) {
633
-		lire_fichier($cache, $res);
634
-		if ($res = unserialize($res)) {
635
-			// mettre le last_modified et le status=304 ?
636
-		}
637
-	}
638
-	if (!$res) {
639
-		$res = recuperer_url($url, $options);
640
-		// ne pas recharger cette url non cachee dans le meme hit puisque non disponible
641
-		if (!$res) {
642
-			if ($is_cached) {
643
-				// on a pas reussi a recuperer mais on avait un cache : l'utiliser
644
-				lire_fichier($cache, $res);
645
-				$res = unserialize($res);
646
-			}
647
-
648
-			return $errors[$url] = $res;
649
-		}
650
-		ecrire_fichier($cache, serialize($res));
651
-	}
652
-
653
-	return $res;
588
+    if (!defined('_DELAI_RECUPERER_URL_CACHE')) {
589
+        define('_DELAI_RECUPERER_URL_CACHE', 3600);
590
+    }
591
+    $default = array(
592
+        'transcoder' => false,
593
+        'methode' => 'GET',
594
+        'taille_max' => null,
595
+        'datas' => '',
596
+        'boundary' => '',
597
+        'refuser_gz' => false,
598
+        'if_modified_since' => '',
599
+        'uri_referer' => '',
600
+        'file' => '',
601
+        'follow_location' => 10,
602
+        'version_http' => _INC_DISTANT_VERSION_HTTP,
603
+        'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE,
604
+    );
605
+    $options = array_merge($default, $options);
606
+
607
+    // cas ou il n'est pas possible de cacher
608
+    if (!empty($options['data']) or $options['methode'] == 'POST') {
609
+        return recuperer_url($url, $options);
610
+    }
611
+
612
+    // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc)
613
+    static $errors = array();
614
+    if (isset($errors[$url])) {
615
+        return $errors[$url];
616
+    }
617
+
618
+    $sig = $options;
619
+    unset($sig['if_modified_since']);
620
+    unset($sig['delai_cache']);
621
+    $sig['url'] = $url;
622
+
623
+    $dir = sous_repertoire(_DIR_CACHE, 'curl');
624
+    $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80);
625
+    $sub = sous_repertoire($dir, substr($cache, 0, 2));
626
+    $cache = "$sub$cache";
627
+
628
+    $res = false;
629
+    $is_cached = file_exists($cache);
630
+    if ($is_cached
631
+        and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache'])
632
+    ) {
633
+        lire_fichier($cache, $res);
634
+        if ($res = unserialize($res)) {
635
+            // mettre le last_modified et le status=304 ?
636
+        }
637
+    }
638
+    if (!$res) {
639
+        $res = recuperer_url($url, $options);
640
+        // ne pas recharger cette url non cachee dans le meme hit puisque non disponible
641
+        if (!$res) {
642
+            if ($is_cached) {
643
+                // on a pas reussi a recuperer mais on avait un cache : l'utiliser
644
+                lire_fichier($cache, $res);
645
+                $res = unserialize($res);
646
+            }
647
+
648
+            return $errors[$url] = $res;
649
+        }
650
+        ecrire_fichier($cache, serialize($res));
651
+    }
652
+
653
+    return $res;
654 654
 }
655 655
 
656 656
 /**
@@ -689,52 +689,52 @@  discard block
 block discarded – undo
689 689
  *     - false si la page n'a pu être récupérée (status different de 200)
690 690
  **/
691 691
 function recuperer_page(
692
-	$url,
693
-	$trans = false,
694
-	$get_headers = false,
695
-	$taille_max = null,
696
-	$datas = '',
697
-	$boundary = '',
698
-	$refuser_gz = false,
699
-	$date_verif = '',
700
-	$uri_referer = ''
692
+    $url,
693
+    $trans = false,
694
+    $get_headers = false,
695
+    $taille_max = null,
696
+    $datas = '',
697
+    $boundary = '',
698
+    $refuser_gz = false,
699
+    $date_verif = '',
700
+    $uri_referer = ''
701 701
 ) {
702
-	// $copy = copier le fichier ?
703
-	$copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
704
-
705
-	if (!is_null($taille_max) and ($taille_max == 0)) {
706
-		$get = 'HEAD';
707
-	} else {
708
-		$get = 'GET';
709
-	}
710
-
711
-	$options = array(
712
-		'transcoder' => $trans === true,
713
-		'methode' => $get,
714
-		'datas' => $datas,
715
-		'boundary' => $boundary,
716
-		'refuser_gz' => $refuser_gz,
717
-		'if_modified_since' => $date_verif,
718
-		'uri_referer' => $uri_referer,
719
-		'file' => $copy ? $trans : '',
720
-		'follow_location' => 10,
721
-	);
722
-	if (!is_null($taille_max)) {
723
-		$options['taille_max'] = $taille_max;
724
-	}
725
-	// dix tentatives maximum en cas d'entetes 301...
726
-	$res = recuperer_url($url, $options);
727
-	if (!$res) {
728
-		return false;
729
-	}
730
-	if ($res['status'] !== 200) {
731
-		return false;
732
-	}
733
-	if ($get_headers) {
734
-		return $res['headers'] . "\n" . $res['page'];
735
-	}
736
-
737
-	return $res['page'];
702
+    // $copy = copier le fichier ?
703
+    $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
704
+
705
+    if (!is_null($taille_max) and ($taille_max == 0)) {
706
+        $get = 'HEAD';
707
+    } else {
708
+        $get = 'GET';
709
+    }
710
+
711
+    $options = array(
712
+        'transcoder' => $trans === true,
713
+        'methode' => $get,
714
+        'datas' => $datas,
715
+        'boundary' => $boundary,
716
+        'refuser_gz' => $refuser_gz,
717
+        'if_modified_since' => $date_verif,
718
+        'uri_referer' => $uri_referer,
719
+        'file' => $copy ? $trans : '',
720
+        'follow_location' => 10,
721
+    );
722
+    if (!is_null($taille_max)) {
723
+        $options['taille_max'] = $taille_max;
724
+    }
725
+    // dix tentatives maximum en cas d'entetes 301...
726
+    $res = recuperer_url($url, $options);
727
+    if (!$res) {
728
+        return false;
729
+    }
730
+    if ($res['status'] !== 200) {
731
+        return false;
732
+    }
733
+    if ($get_headers) {
734
+        return $res['headers'] . "\n" . $res['page'];
735
+    }
736
+
737
+    return $res['page'];
738 738
 }
739 739
 
740 740
 
@@ -771,48 +771,48 @@  discard block
 block discarded – undo
771 771
  *     - false sinon
772 772
  **/
773 773
 function recuperer_lapage(
774
-	$url,
775
-	$trans = false,
776
-	$get = 'GET',
777
-	$taille_max = 1048576,
778
-	$datas = '',
779
-	$refuser_gz = false,
780
-	$date_verif = '',
781
-	$uri_referer = ''
774
+    $url,
775
+    $trans = false,
776
+    $get = 'GET',
777
+    $taille_max = 1048576,
778
+    $datas = '',
779
+    $refuser_gz = false,
780
+    $date_verif = '',
781
+    $uri_referer = ''
782 782
 ) {
783
-	// $copy = copier le fichier ?
784
-	$copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
785
-
786
-	// si on ecrit directement dans un fichier, pour ne pas manipuler
787
-	// en memoire refuser gz
788
-	if ($copy) {
789
-		$refuser_gz = true;
790
-	}
791
-
792
-	$options = array(
793
-		'transcoder' => $trans === true,
794
-		'methode' => $get,
795
-		'datas' => $datas,
796
-		'refuser_gz' => $refuser_gz,
797
-		'if_modified_since' => $date_verif,
798
-		'uri_referer' => $uri_referer,
799
-		'file' => $copy ? $trans : '',
800
-		'follow_location' => false,
801
-	);
802
-	if (!is_null($taille_max)) {
803
-		$options['taille_max'] = $taille_max;
804
-	}
805
-	// dix tentatives maximum en cas d'entetes 301...
806
-	$res = recuperer_url($url, $options);
807
-
808
-	if (!$res) {
809
-		return false;
810
-	}
811
-	if ($res['status'] !== 200) {
812
-		return false;
813
-	}
814
-
815
-	return array($res['headers'], $res['page']);
783
+    // $copy = copier le fichier ?
784
+    $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-)
785
+
786
+    // si on ecrit directement dans un fichier, pour ne pas manipuler
787
+    // en memoire refuser gz
788
+    if ($copy) {
789
+        $refuser_gz = true;
790
+    }
791
+
792
+    $options = array(
793
+        'transcoder' => $trans === true,
794
+        'methode' => $get,
795
+        'datas' => $datas,
796
+        'refuser_gz' => $refuser_gz,
797
+        'if_modified_since' => $date_verif,
798
+        'uri_referer' => $uri_referer,
799
+        'file' => $copy ? $trans : '',
800
+        'follow_location' => false,
801
+    );
802
+    if (!is_null($taille_max)) {
803
+        $options['taille_max'] = $taille_max;
804
+    }
805
+    // dix tentatives maximum en cas d'entetes 301...
806
+    $res = recuperer_url($url, $options);
807
+
808
+    if (!$res) {
809
+        return false;
810
+    }
811
+    if ($res['status'] !== 200) {
812
+        return false;
813
+    }
814
+
815
+    return array($res['headers'], $res['page']);
816 816
 }
817 817
 
818 818
 /**
@@ -830,41 +830,41 @@  discard block
 block discarded – undo
830 830
  *   string contenu de la resource
831 831
  */
832 832
 function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') {
833
-	$taille = 0;
834
-	$result = '';
835
-	$fp = false;
836
-	if ($fichier) {
837
-		include_spip('inc/acces');
838
-		$tmpfile = "$fichier." . creer_uniqid() . '.tmp';
839
-		$fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
840
-		if (!$fp and file_exists($fichier)) {
841
-			return filesize($fichier);
842
-		}
843
-		if (!$fp) {
844
-			return false;
845
-		}
846
-		$result = 0; // on renvoie la taille du fichier
847
-	}
848
-	while (!feof($handle) and $taille < $taille_max) {
849
-		$res = fread($handle, 16384);
850
-		$taille += strlen($res);
851
-		if ($fp) {
852
-			fwrite($fp, $res);
853
-			$result = $taille;
854
-		} else {
855
-			$result .= $res;
856
-		}
857
-	}
858
-	if ($fp) {
859
-		spip_fclose_unlock($fp);
860
-		spip_unlink($fichier);
861
-		@rename($tmpfile, $fichier);
862
-		if (!file_exists($fichier)) {
863
-			return false;
864
-		}
865
-	}
866
-
867
-	return $result;
833
+    $taille = 0;
834
+    $result = '';
835
+    $fp = false;
836
+    if ($fichier) {
837
+        include_spip('inc/acces');
838
+        $tmpfile = "$fichier." . creer_uniqid() . '.tmp';
839
+        $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX);
840
+        if (!$fp and file_exists($fichier)) {
841
+            return filesize($fichier);
842
+        }
843
+        if (!$fp) {
844
+            return false;
845
+        }
846
+        $result = 0; // on renvoie la taille du fichier
847
+    }
848
+    while (!feof($handle) and $taille < $taille_max) {
849
+        $res = fread($handle, 16384);
850
+        $taille += strlen($res);
851
+        if ($fp) {
852
+            fwrite($fp, $res);
853
+            $result = $taille;
854
+        } else {
855
+            $result .= $res;
856
+        }
857
+    }
858
+    if ($fp) {
859
+        spip_fclose_unlock($fp);
860
+        spip_unlink($fichier);
861
+        @rename($tmpfile, $fichier);
862
+        if (!file_exists($fichier)) {
863
+            return false;
864
+        }
865
+    }
866
+
867
+    return $result;
868 868
 }
869 869
 
870 870
 /**
@@ -886,34 +886,34 @@  discard block
 block discarded – undo
886 886
  *   string location
887 887
  */
888 888
 function recuperer_entetes_complets($handle, $if_modified_since = false) {
889
-	$result = array('status' => 0, 'headers' => array(), 'last_modified' => 0, 'location' => '');
890
-
891
-	$s = @trim(fgets($handle, 16384));
892
-	if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
893
-		return false;
894
-	}
895
-	$result['status'] = intval($r[1]);
896
-	while ($s = trim(fgets($handle, 16384))) {
897
-		$result['headers'][] = $s . "\n";
898
-		preg_match(',^([^:]*): *(.*)$,i', $s, $r);
899
-		list(, $d, $v) = $r;
900
-		if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
901
-			$result['location'] = $v;
902
-		} elseif ($d == 'Last-Modified') {
903
-			$result['last_modified'] = strtotime($v);
904
-		}
905
-	}
906
-	if ($if_modified_since
907
-		and $result['last_modified']
908
-		and $if_modified_since > $result['last_modified']
909
-		and $result['status'] == 200
910
-	) {
911
-		$result['status'] = 304;
912
-	}
913
-
914
-	$result['headers'] = implode('', $result['headers']);
915
-
916
-	return $result;
889
+    $result = array('status' => 0, 'headers' => array(), 'last_modified' => 0, 'location' => '');
890
+
891
+    $s = @trim(fgets($handle, 16384));
892
+    if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) {
893
+        return false;
894
+    }
895
+    $result['status'] = intval($r[1]);
896
+    while ($s = trim(fgets($handle, 16384))) {
897
+        $result['headers'][] = $s . "\n";
898
+        preg_match(',^([^:]*): *(.*)$,i', $s, $r);
899
+        list(, $d, $v) = $r;
900
+        if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) {
901
+            $result['location'] = $v;
902
+        } elseif ($d == 'Last-Modified') {
903
+            $result['last_modified'] = strtotime($v);
904
+        }
905
+    }
906
+    if ($if_modified_since
907
+        and $result['last_modified']
908
+        and $if_modified_since > $result['last_modified']
909
+        and $result['status'] == 200
910
+    ) {
911
+        $result['status'] = 304;
912
+    }
913
+
914
+    $result['headers'] = implode('', $result['headers']);
915
+
916
+    return $result;
917 917
 }
918 918
 
919 919
 /**
@@ -935,22 +935,22 @@  discard block
 block discarded – undo
935 935
  *     Nom du fichier pour copie locale
936 936
  **/
937 937
 function nom_fichier_copie_locale($source, $extension) {
938
-	include_spip('inc/documents');
938
+    include_spip('inc/documents');
939 939
 
940
-	$d = creer_repertoire_documents('distant'); # IMG/distant/
941
-	$d = sous_repertoire($d, $extension); # IMG/distant/pdf/
940
+    $d = creer_repertoire_documents('distant'); # IMG/distant/
941
+    $d = sous_repertoire($d, $extension); # IMG/distant/pdf/
942 942
 
943
-	// on se place tout le temps comme si on etait a la racine
944
-	if (_DIR_RACINE) {
945
-		$d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
946
-	}
943
+    // on se place tout le temps comme si on etait a la racine
944
+    if (_DIR_RACINE) {
945
+        $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d);
946
+    }
947 947
 
948
-	$m = md5($source);
948
+    $m = md5($source);
949 949
 
950
-	return $d
951
-	. substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
952
-	. substr($m, 0, 4)
953
-	. ".$extension";
950
+    return $d
951
+    . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12)
952
+    . substr($m, 0, 4)
953
+    . ".$extension";
954 954
 }
955 955
 
956 956
 /**
@@ -968,68 +968,68 @@  discard block
 block discarded – undo
968 968
  *      Nom du fichier calculé
969 969
  **/
970 970
 function fichier_copie_locale($source) {
971
-	// Si c'est deja local pas de souci
972
-	if (!tester_url_absolue($source)) {
973
-		if (_DIR_RACINE) {
974
-			$source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
975
-		}
976
-
977
-		return $source;
978
-	}
979
-
980
-	// optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
981
-	// a deja ete copie en local avec cette extension
982
-	// dans ce cas elle est fiable, pas la peine de requeter en base
983
-	$path_parts = pathinfo($source);
984
-	if (!isset($path_parts['extension'])) {
985
-		$path_parts['extension'] = '';
986
-	}
987
-	$ext = $path_parts ? $path_parts['extension'] : '';
988
-	if ($ext
989
-		and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
990
-		and $f = nom_fichier_copie_locale($source, $ext)
991
-		and file_exists(_DIR_RACINE . $f)
992
-	) {
993
-		return $f;
994
-	}
995
-
996
-
997
-	// Si c'est deja dans la table des documents,
998
-	// ramener le nom de sa copie potentielle
999
-	$ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
1000
-
1001
-	if ($ext) {
1002
-		return nom_fichier_copie_locale($source, $ext);
1003
-	}
1004
-
1005
-	// voir si l'extension indiquee dans le nom du fichier est ok
1006
-	// et si il n'aurait pas deja ete rapatrie
1007
-
1008
-	$ext = $path_parts ? $path_parts['extension'] : '';
1009
-
1010
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1011
-		$f = nom_fichier_copie_locale($source, $ext);
1012
-		if (file_exists(_DIR_RACINE . $f)) {
1013
-			return $f;
1014
-		}
1015
-	}
1016
-
1017
-	// Ping  pour voir si son extension est connue et autorisee
1018
-	// avec mise en cache du resultat du ping
1019
-
1020
-	$cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
1021
-	if (!@file_exists($cache)
1022
-		or !$path_parts = @unserialize(spip_file_get_contents($cache))
1023
-		or _request('var_mode') == 'recalcul'
1024
-	) {
1025
-		$path_parts = recuperer_infos_distantes($source, 0, false);
1026
-		ecrire_fichier($cache, serialize($path_parts));
1027
-	}
1028
-	$ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
1029
-	if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1030
-		return nom_fichier_copie_locale($source, $ext);
1031
-	}
1032
-	spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
971
+    // Si c'est deja local pas de souci
972
+    if (!tester_url_absolue($source)) {
973
+        if (_DIR_RACINE) {
974
+            $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source);
975
+        }
976
+
977
+        return $source;
978
+    }
979
+
980
+    // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier
981
+    // a deja ete copie en local avec cette extension
982
+    // dans ce cas elle est fiable, pas la peine de requeter en base
983
+    $path_parts = pathinfo($source);
984
+    if (!isset($path_parts['extension'])) {
985
+        $path_parts['extension'] = '';
986
+    }
987
+    $ext = $path_parts ? $path_parts['extension'] : '';
988
+    if ($ext
989
+        and preg_match(',^\w+$,', $ext) // pas de php?truc=1&...
990
+        and $f = nom_fichier_copie_locale($source, $ext)
991
+        and file_exists(_DIR_RACINE . $f)
992
+    ) {
993
+        return $f;
994
+    }
995
+
996
+
997
+    // Si c'est deja dans la table des documents,
998
+    // ramener le nom de sa copie potentielle
999
+    $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''");
1000
+
1001
+    if ($ext) {
1002
+        return nom_fichier_copie_locale($source, $ext);
1003
+    }
1004
+
1005
+    // voir si l'extension indiquee dans le nom du fichier est ok
1006
+    // et si il n'aurait pas deja ete rapatrie
1007
+
1008
+    $ext = $path_parts ? $path_parts['extension'] : '';
1009
+
1010
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1011
+        $f = nom_fichier_copie_locale($source, $ext);
1012
+        if (file_exists(_DIR_RACINE . $f)) {
1013
+            return $f;
1014
+        }
1015
+    }
1016
+
1017
+    // Ping  pour voir si son extension est connue et autorisee
1018
+    // avec mise en cache du resultat du ping
1019
+
1020
+    $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source);
1021
+    if (!@file_exists($cache)
1022
+        or !$path_parts = @unserialize(spip_file_get_contents($cache))
1023
+        or _request('var_mode') == 'recalcul'
1024
+    ) {
1025
+        $path_parts = recuperer_infos_distantes($source, 0, false);
1026
+        ecrire_fichier($cache, serialize($path_parts));
1027
+    }
1028
+    $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : '';
1029
+    if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) {
1030
+        return nom_fichier_copie_locale($source, $ext);
1031
+    }
1032
+    spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR);
1033 1033
 }
1034 1034
 
1035 1035
 
@@ -1057,146 +1057,146 @@  discard block
 block discarded – undo
1057 1057
  **/
1058 1058
 function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true) {
1059 1059
 
1060
-	// pas la peine de perdre son temps
1061
-	if (!tester_url_absolue($source)) {
1062
-		return false;
1063
-	}
1064
-
1065
-	# charger les alias des types mime
1066
-	include_spip('base/typedoc');
1067
-
1068
-	$a = array();
1069
-	$mime_type = '';
1070
-	// On va directement charger le debut des images et des fichiers html,
1071
-	// de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
1072
-	// ca echoue l'utilisateur devra les entrer...
1073
-	$reponse = recuperer_url($source, ['taille_max' => $max, 'refuser_gz' => true]);
1074
-	$headers = $reponse['headers'] ?? '';
1075
-	$a['body'] = $reponse['page'] ?? '';
1076
-	if ($headers) {
1077
-		if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1078
-			$mime_type = (trim($regs[1]));
1079
-		} else {
1080
-			$mime_type = '';
1081
-		} // inconnu
1082
-
1083
-		// Appliquer les alias
1084
-		while (isset($GLOBALS['mime_alias'][$mime_type])) {
1085
-			$mime_type = $GLOBALS['mime_alias'][$mime_type];
1086
-		}
1087
-
1088
-		// Si on a un mime-type insignifiant
1089
-		// text/plain,application/octet-stream ou vide
1090
-		// c'est peut-etre que le serveur ne sait pas
1091
-		// ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1092
-		// ou le Content-Disposition: attachment; filename=...
1093
-		$t = null;
1094
-		if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) {
1095
-			if (!$t
1096
-				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1097
-			) {
1098
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1099
-			}
1100
-			if (!$t
1101
-				and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1102
-				and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1103
-			) {
1104
-				$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1105
-			}
1106
-		}
1107
-
1108
-		// Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1109
-		if (!$t) {
1110
-			$t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1111
-		}
1112
-
1113
-		// Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1114
-		// On essaie de nouveau avec l'extension
1115
-		if (!$t
1116
-			and $mime_type != 'text/plain'
1117
-			and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1118
-		) {
1119
-			# eviter xxx.3 => 3gp (> SPIP 3)
1120
-			$t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1121
-		}
1122
-
1123
-		if ($t) {
1124
-			spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1125
-			$a['extension'] = $t['extension'];
1126
-		} else {
1127
-			# par defaut on retombe sur '.bin' si c'est autorise
1128
-			spip_log("mime-type $mime_type inconnu", 'distant');
1129
-			$t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1130
-			if (!$t) {
1131
-				return false;
1132
-			}
1133
-			$a['extension'] = $t['extension'];
1134
-		}
1135
-
1136
-		if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
1137
-			$a['taille'] = intval($regs[1]);
1138
-		}
1139
-	}
1140
-
1141
-	// Echec avec HEAD, on tente avec GET
1142
-	if (!$a and !$max) {
1143
-		spip_log("tenter GET $source", 'distant');
1144
-		$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1145
-	}
1146
-
1147
-	// si on a rien trouve pas la peine d'insister
1148
-	if (!$a) {
1149
-		return false;
1150
-	}
1151
-
1152
-	// S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1153
-	// recharger le document en GET et recuperer des donnees supplementaires...
1154
-	include_spip('inc/filtres_images_lib_mini');
1155
-	if (strpos($mime_type, "image/") === 0
1156
-	  and $extension = _image_trouver_extension_depuis_mime($mime_type)) {
1157
-		if ($max == 0
1158
-			and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1159
-			and in_array($extension, formats_image_acceptables())
1160
-			and $charger_si_petite_image
1161
-		) {
1162
-			$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1163
-		} else {
1164
-			if ($a['body']) {
1165
-				$a['extension'] = $extension;
1166
-				$a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1167
-				ecrire_fichier($a['fichier'], $a['body']);
1168
-				$size_image = @spip_getimagesize($a['fichier']);
1169
-				$a['largeur'] = intval($size_image[0]);
1170
-				$a['hauteur'] = intval($size_image[1]);
1171
-				$a['type_image'] = true;
1172
-			}
1173
-		}
1174
-	}
1175
-
1176
-	// Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1177
-	// ce sera mieux que 0x0
1178
-	// Flash is dead!
1179
-	if ($a and isset($a['extension']) and $a['extension'] == 'swf'
1180
-		and empty($a['largeur'])
1181
-	) {
1182
-		$a['largeur'] = 425;
1183
-		$a['hauteur'] = 350;
1184
-	}
1185
-
1186
-	if ($mime_type == 'text/html') {
1187
-		include_spip('inc/filtres');
1188
-		$page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]);
1189
-		$page = $page['page'] ?? '';
1190
-		if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1191
-			$a['titre'] = corriger_caracteres(trim($regs[1]));
1192
-		}
1193
-		if (!isset($a['taille']) or !$a['taille']) {
1194
-			$a['taille'] = strlen($page); # a peu pres
1195
-		}
1196
-	}
1197
-	$a['mime_type'] = $mime_type;
1198
-
1199
-	return $a;
1060
+    // pas la peine de perdre son temps
1061
+    if (!tester_url_absolue($source)) {
1062
+        return false;
1063
+    }
1064
+
1065
+    # charger les alias des types mime
1066
+    include_spip('base/typedoc');
1067
+
1068
+    $a = array();
1069
+    $mime_type = '';
1070
+    // On va directement charger le debut des images et des fichiers html,
1071
+    // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
1072
+    // ca echoue l'utilisateur devra les entrer...
1073
+    $reponse = recuperer_url($source, ['taille_max' => $max, 'refuser_gz' => true]);
1074
+    $headers = $reponse['headers'] ?? '';
1075
+    $a['body'] = $reponse['page'] ?? '';
1076
+    if ($headers) {
1077
+        if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
1078
+            $mime_type = (trim($regs[1]));
1079
+        } else {
1080
+            $mime_type = '';
1081
+        } // inconnu
1082
+
1083
+        // Appliquer les alias
1084
+        while (isset($GLOBALS['mime_alias'][$mime_type])) {
1085
+            $mime_type = $GLOBALS['mime_alias'][$mime_type];
1086
+        }
1087
+
1088
+        // Si on a un mime-type insignifiant
1089
+        // text/plain,application/octet-stream ou vide
1090
+        // c'est peut-etre que le serveur ne sait pas
1091
+        // ce qu'il sert ; on va tenter de detecter via l'extension de l'url
1092
+        // ou le Content-Disposition: attachment; filename=...
1093
+        $t = null;
1094
+        if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) {
1095
+            if (!$t
1096
+                and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1097
+            ) {
1098
+                $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1099
+            }
1100
+            if (!$t
1101
+                and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m)
1102
+                and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext)
1103
+            ) {
1104
+                $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1105
+            }
1106
+        }
1107
+
1108
+        // Autre mime/type (ou text/plain avec fichier d'extension inconnue)
1109
+        if (!$t) {
1110
+            $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type));
1111
+        }
1112
+
1113
+        // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg)
1114
+        // On essaie de nouveau avec l'extension
1115
+        if (!$t
1116
+            and $mime_type != 'text/plain'
1117
+            and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext)
1118
+        ) {
1119
+            # eviter xxx.3 => 3gp (> SPIP 3)
1120
+            $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text'));
1121
+        }
1122
+
1123
+        if ($t) {
1124
+            spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant');
1125
+            $a['extension'] = $t['extension'];
1126
+        } else {
1127
+            # par defaut on retombe sur '.bin' si c'est autorise
1128
+            spip_log("mime-type $mime_type inconnu", 'distant');
1129
+            $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'");
1130
+            if (!$t) {
1131
+                return false;
1132
+            }
1133
+            $a['extension'] = $t['extension'];
1134
+        }
1135
+
1136
+        if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) {
1137
+            $a['taille'] = intval($regs[1]);
1138
+        }
1139
+    }
1140
+
1141
+    // Echec avec HEAD, on tente avec GET
1142
+    if (!$a and !$max) {
1143
+        spip_log("tenter GET $source", 'distant');
1144
+        $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1145
+    }
1146
+
1147
+    // si on a rien trouve pas la peine d'insister
1148
+    if (!$a) {
1149
+        return false;
1150
+    }
1151
+
1152
+    // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
1153
+    // recharger le document en GET et recuperer des donnees supplementaires...
1154
+    include_spip('inc/filtres_images_lib_mini');
1155
+    if (strpos($mime_type, "image/") === 0
1156
+      and $extension = _image_trouver_extension_depuis_mime($mime_type)) {
1157
+        if ($max == 0
1158
+            and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE)
1159
+            and in_array($extension, formats_image_acceptables())
1160
+            and $charger_si_petite_image
1161
+        ) {
1162
+            $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
1163
+        } else {
1164
+            if ($a['body']) {
1165
+                $a['extension'] = $extension;
1166
+                $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension);
1167
+                ecrire_fichier($a['fichier'], $a['body']);
1168
+                $size_image = @spip_getimagesize($a['fichier']);
1169
+                $a['largeur'] = intval($size_image[0]);
1170
+                $a['hauteur'] = intval($size_image[1]);
1171
+                $a['type_image'] = true;
1172
+            }
1173
+        }
1174
+    }
1175
+
1176
+    // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut
1177
+    // ce sera mieux que 0x0
1178
+    // Flash is dead!
1179
+    if ($a and isset($a['extension']) and $a['extension'] == 'swf'
1180
+        and empty($a['largeur'])
1181
+    ) {
1182
+        $a['largeur'] = 425;
1183
+        $a['hauteur'] = 350;
1184
+    }
1185
+
1186
+    if ($mime_type == 'text/html') {
1187
+        include_spip('inc/filtres');
1188
+        $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]);
1189
+        $page = $page['page'] ?? '';
1190
+        if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
1191
+            $a['titre'] = corriger_caracteres(trim($regs[1]));
1192
+        }
1193
+        if (!isset($a['taille']) or !$a['taille']) {
1194
+            $a['taille'] = strlen($page); # a peu pres
1195
+        }
1196
+    }
1197
+    $a['mime_type'] = $mime_type;
1198
+
1199
+    return $a;
1200 1200
 }
1201 1201
 
1202 1202
 
@@ -1212,45 +1212,45 @@  discard block
 block discarded – undo
1212 1212
  * @return string
1213 1213
  */
1214 1214
 function need_proxy($host, $http_proxy = null, $http_noproxy = null) {
1215
-	if (is_null($http_proxy)) {
1216
-		$http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null;
1217
-	}
1218
-	// rien a faire si pas de proxy :)
1219
-	if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1220
-		return '';
1221
-	}
1222
-
1223
-	if (is_null($http_noproxy)) {
1224
-		$http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null;
1225
-	}
1226
-	// si pas d'exception, on retourne le proxy
1227
-	if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1228
-		return $http_proxy;
1229
-	}
1230
-
1231
-	// si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1232
-	// $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1233
-	$http_noproxy = str_replace("\n", " ", $http_noproxy);
1234
-	$http_noproxy = str_replace("\r", " ", $http_noproxy);
1235
-	$http_noproxy = " $http_noproxy ";
1236
-	$domain = $host;
1237
-	// si le domaine exact www.example.org est dans les exceptions
1238
-	if (strpos($http_noproxy, " $domain ") !== false)
1239
-		return '';
1240
-
1241
-	while (strpos($domain, '.') !== false) {
1242
-		$domain = explode('.', $domain);
1243
-		array_shift($domain);
1244
-		$domain = implode('.', $domain);
1245
-
1246
-		// ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1247
-		if (strpos($http_noproxy, " .$domain ") !== false) {
1248
-			return '';
1249
-		}
1250
-	}
1251
-
1252
-	// ok c'est pas une exception
1253
-	return $http_proxy;
1215
+    if (is_null($http_proxy)) {
1216
+        $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null;
1217
+    }
1218
+    // rien a faire si pas de proxy :)
1219
+    if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) {
1220
+        return '';
1221
+    }
1222
+
1223
+    if (is_null($http_noproxy)) {
1224
+        $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null;
1225
+    }
1226
+    // si pas d'exception, on retourne le proxy
1227
+    if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) {
1228
+        return $http_proxy;
1229
+    }
1230
+
1231
+    // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception
1232
+    // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne
1233
+    $http_noproxy = str_replace("\n", " ", $http_noproxy);
1234
+    $http_noproxy = str_replace("\r", " ", $http_noproxy);
1235
+    $http_noproxy = " $http_noproxy ";
1236
+    $domain = $host;
1237
+    // si le domaine exact www.example.org est dans les exceptions
1238
+    if (strpos($http_noproxy, " $domain ") !== false)
1239
+        return '';
1240
+
1241
+    while (strpos($domain, '.') !== false) {
1242
+        $domain = explode('.', $domain);
1243
+        array_shift($domain);
1244
+        $domain = implode('.', $domain);
1245
+
1246
+        // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines)
1247
+        if (strpos($http_noproxy, " .$domain ") !== false) {
1248
+            return '';
1249
+        }
1250
+    }
1251
+
1252
+    // ok c'est pas une exception
1253
+    return $http_proxy;
1254 1254
 }
1255 1255
 
1256 1256
 
@@ -1273,58 +1273,58 @@  discard block
 block discarded – undo
1273 1273
  * @return array
1274 1274
  */
1275 1275
 function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') {
1276
-	$user = $via_proxy = $proxy_user = '';
1277
-	$fopen = false;
1278
-
1279
-	$t = @parse_url($url);
1280
-	$host = $t['host'];
1281
-	if ($t['scheme'] == 'http') {
1282
-		$scheme = 'http';
1283
-		$noproxy = '';
1284
-	} elseif ($t['scheme'] == 'https') {
1285
-		$scheme = 'ssl';
1286
-		$noproxy = 'ssl://';
1287
-		if (!isset($t['port']) || !($port = $t['port'])) {
1288
-			$t['port'] = 443;
1289
-		}
1290
-	} else {
1291
-		$scheme = $t['scheme'];
1292
-		$noproxy = $scheme . '://';
1293
-	}
1294
-	if (isset($t['user'])) {
1295
-		$user = array($t['user'], $t['pass']);
1296
-	}
1297
-
1298
-	if (!isset($t['port']) || !($port = $t['port'])) {
1299
-		$port = 80;
1300
-	}
1301
-	if (!isset($t['path']) || !($path = $t['path'])) {
1302
-		$path = '/';
1303
-	}
1304
-
1305
-	if (!empty($t['query'])) {
1306
-		$path .= '?' . $t['query'];
1307
-	}
1308
-
1309
-	$f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1310
-	if (!$f or !is_resource($f)) {
1311
-		// fallback : fopen si on a pas fait timeout dans lance_requete
1312
-		// ce qui correspond a $f===110
1313
-		if ($f !== 110
1314
-			and !need_proxy($host)
1315
-			and !_request('tester_proxy')
1316
-			and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1317
-		) {
1318
-			$f = @fopen($url, 'rb');
1319
-			spip_log("connexion vers $url par simple fopen", 'distant');
1320
-			$fopen = true;
1321
-		} else {
1322
-			// echec total
1323
-			$f = false;
1324
-		}
1325
-	}
1326
-
1327
-	return array($f, $fopen);
1276
+    $user = $via_proxy = $proxy_user = '';
1277
+    $fopen = false;
1278
+
1279
+    $t = @parse_url($url);
1280
+    $host = $t['host'];
1281
+    if ($t['scheme'] == 'http') {
1282
+        $scheme = 'http';
1283
+        $noproxy = '';
1284
+    } elseif ($t['scheme'] == 'https') {
1285
+        $scheme = 'ssl';
1286
+        $noproxy = 'ssl://';
1287
+        if (!isset($t['port']) || !($port = $t['port'])) {
1288
+            $t['port'] = 443;
1289
+        }
1290
+    } else {
1291
+        $scheme = $t['scheme'];
1292
+        $noproxy = $scheme . '://';
1293
+    }
1294
+    if (isset($t['user'])) {
1295
+        $user = array($t['user'], $t['pass']);
1296
+    }
1297
+
1298
+    if (!isset($t['port']) || !($port = $t['port'])) {
1299
+        $port = 80;
1300
+    }
1301
+    if (!isset($t['path']) || !($path = $t['path'])) {
1302
+        $path = '/';
1303
+    }
1304
+
1305
+    if (!empty($t['query'])) {
1306
+        $path .= '?' . $t['query'];
1307
+    }
1308
+
1309
+    $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date);
1310
+    if (!$f or !is_resource($f)) {
1311
+        // fallback : fopen si on a pas fait timeout dans lance_requete
1312
+        // ce qui correspond a $f===110
1313
+        if ($f !== 110
1314
+            and !need_proxy($host)
1315
+            and !_request('tester_proxy')
1316
+            and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen'])
1317
+        ) {
1318
+            $f = @fopen($url, 'rb');
1319
+            spip_log("connexion vers $url par simple fopen", 'distant');
1320
+            $fopen = true;
1321
+        } else {
1322
+            // echec total
1323
+            $f = false;
1324
+        }
1325
+    }
1326
+
1327
+    return array($f, $fopen);
1328 1328
 }
1329 1329
 
1330 1330
 /**
@@ -1359,124 +1359,124 @@  discard block
 block discarded – undo
1359 1359
  *   resource socket vers l'url demandee
1360 1360
  */
1361 1361
 function lance_requete(
1362
-	$method,
1363
-	$scheme,
1364
-	$user,
1365
-	$host,
1366
-	$path,
1367
-	$port,
1368
-	$noproxy,
1369
-	$refuse_gz = false,
1370
-	$referer = '',
1371
-	$datas = '',
1372
-	$vers = 'HTTP/1.0',
1373
-	$date = ''
1362
+    $method,
1363
+    $scheme,
1364
+    $user,
1365
+    $host,
1366
+    $path,
1367
+    $port,
1368
+    $noproxy,
1369
+    $refuse_gz = false,
1370
+    $referer = '',
1371
+    $datas = '',
1372
+    $vers = 'HTTP/1.0',
1373
+    $date = ''
1374 1374
 ) {
1375 1375
 
1376
-	$proxy_user = '';
1377
-	$http_proxy = need_proxy($host);
1378
-	if ($user) {
1379
-		$user = urlencode($user[0]) . ':' . urlencode($user[1]);
1380
-	}
1381
-
1382
-	$connect = '';
1383
-	if ($http_proxy) {
1384
-		if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) {
1385
-			$path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1386
-			$connect = 'CONNECT ' . $path_host . " $vers\r\n"
1387
-				. "Host: $path_host\r\n"
1388
-				. "Proxy-Connection: Keep-Alive\r\n";
1389
-		} else {
1390
-			$path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://")
1391
-				. (!$user ? '' : "$user@")
1392
-				. "$host" . (($port != 80) ? ":$port" : '') . $path;
1393
-		}
1394
-		$t2 = @parse_url($http_proxy);
1395
-		$first_host = $t2['host'];
1396
-		if (!($port = $t2['port'])) {
1397
-			$port = 80;
1398
-		}
1399
-		if ($t2['user']) {
1400
-			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1401
-		}
1402
-	} else {
1403
-		$first_host = $noproxy . $host;
1404
-	}
1405
-
1406
-	if ($connect) {
1407
-		$streamContext = stream_context_create(array(
1408
-			'ssl' => array(
1409
-				'verify_peer' => false,
1410
-				'allow_self_signed' => true,
1411
-				'SNI_enabled' => true,
1412
-				'peer_name' => $host,
1413
-			)
1414
-		));
1415
-		$f = @stream_socket_client(
1416
-			"tcp://$first_host:$port",
1417
-			$errno,
1418
-			$errstr,
1419
-			_INC_DISTANT_CONNECT_TIMEOUT,
1420
-			STREAM_CLIENT_CONNECT,
1421
-			$streamContext
1422
-		);
1423
-		spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1424
-		if (!$f) {
1425
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1426
-			return $errno;
1427
-		}
1428
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1429
-
1430
-		fputs($f, $connect);
1431
-		fputs($f, "\r\n");
1432
-		$res = fread($f, 1024);
1433
-		if (!$res
1434
-			or !count($res = explode(' ', $res))
1435
-			or $res[1] !== '200'
1436
-		) {
1437
-			spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1438
-			fclose($f);
1439
-
1440
-			return false;
1441
-		}
1442
-		// important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1443
-		stream_set_blocking($f, true);
1444
-		// envoyer le handshake
1445
-		stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1446
-		spip_log("OK CONNECT sur $first_host:$port", 'connect');
1447
-	} else {
1448
-		$ntry = 3;
1449
-		do {
1450
-			$f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1451
-		} while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1452
-		spip_log("Recuperer $path sur $first_host:$port par $f");
1453
-		if (!$f) {
1454
-			spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1455
-
1456
-			return $errno;
1457
-		}
1458
-		stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1459
-	}
1460
-
1461
-	$site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1462
-
1463
-	$host_port = $host;
1464
-	if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) {
1465
-		$host_port .= ":$port";
1466
-	}
1467
-	$req = "$method $path $vers\r\n"
1468
-		. "Host: $host_port\r\n"
1469
-		. 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1470
-		. ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1471
-		. (!$site ? '' : "Referer: $site/$referer\r\n")
1472
-		. (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1473
-		. (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1474
-		. (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1475
-		. (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1376
+    $proxy_user = '';
1377
+    $http_proxy = need_proxy($host);
1378
+    if ($user) {
1379
+        $user = urlencode($user[0]) . ':' . urlencode($user[1]);
1380
+    }
1381
+
1382
+    $connect = '';
1383
+    if ($http_proxy) {
1384
+        if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) {
1385
+            $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : '');
1386
+            $connect = 'CONNECT ' . $path_host . " $vers\r\n"
1387
+                . "Host: $path_host\r\n"
1388
+                . "Proxy-Connection: Keep-Alive\r\n";
1389
+        } else {
1390
+            $path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://")
1391
+                . (!$user ? '' : "$user@")
1392
+                . "$host" . (($port != 80) ? ":$port" : '') . $path;
1393
+        }
1394
+        $t2 = @parse_url($http_proxy);
1395
+        $first_host = $t2['host'];
1396
+        if (!($port = $t2['port'])) {
1397
+            $port = 80;
1398
+        }
1399
+        if ($t2['user']) {
1400
+            $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
1401
+        }
1402
+    } else {
1403
+        $first_host = $noproxy . $host;
1404
+    }
1405
+
1406
+    if ($connect) {
1407
+        $streamContext = stream_context_create(array(
1408
+            'ssl' => array(
1409
+                'verify_peer' => false,
1410
+                'allow_self_signed' => true,
1411
+                'SNI_enabled' => true,
1412
+                'peer_name' => $host,
1413
+            )
1414
+        ));
1415
+        $f = @stream_socket_client(
1416
+            "tcp://$first_host:$port",
1417
+            $errno,
1418
+            $errstr,
1419
+            _INC_DISTANT_CONNECT_TIMEOUT,
1420
+            STREAM_CLIENT_CONNECT,
1421
+            $streamContext
1422
+        );
1423
+        spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect');
1424
+        if (!$f) {
1425
+            spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1426
+            return $errno;
1427
+        }
1428
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1429
+
1430
+        fputs($f, $connect);
1431
+        fputs($f, "\r\n");
1432
+        $res = fread($f, 1024);
1433
+        if (!$res
1434
+            or !count($res = explode(' ', $res))
1435
+            or $res[1] !== '200'
1436
+        ) {
1437
+            spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE);
1438
+            fclose($f);
1439
+
1440
+            return false;
1441
+        }
1442
+        // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo
1443
+        stream_set_blocking($f, true);
1444
+        // envoyer le handshake
1445
+        stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
1446
+        spip_log("OK CONNECT sur $first_host:$port", 'connect');
1447
+    } else {
1448
+        $ntry = 3;
1449
+        do {
1450
+            $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT);
1451
+        } while (!$f and $ntry-- and $errno !== 110 and sleep(1));
1452
+        spip_log("Recuperer $path sur $first_host:$port par $f");
1453
+        if (!$f) {
1454
+            spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR);
1455
+
1456
+            return $errno;
1457
+        }
1458
+        stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT);
1459
+    }
1460
+
1461
+    $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '';
1462
+
1463
+    $host_port = $host;
1464
+    if ($port != (in_array($scheme , array('tls','ssl')) ? 443 : 80)) {
1465
+        $host_port .= ":$port";
1466
+    }
1467
+    $req = "$method $path $vers\r\n"
1468
+        . "Host: $host_port\r\n"
1469
+        . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n"
1470
+        . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n"))
1471
+        . (!$site ? '' : "Referer: $site/$referer\r\n")
1472
+        . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n"))
1473
+        . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n"))
1474
+        . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n")
1475
+        . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n");
1476 1476
 
1477 1477
 #	spip_log("Requete\n$req", 'distant');
1478
-	fputs($f, $req);
1479
-	fputs($f, $datas ? $datas : "\r\n");
1478
+    fputs($f, $req);
1479
+    fputs($f, $datas ? $datas : "\r\n");
1480 1480
 
1481
-	return $f;
1481
+    return $f;
1482 1482
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres.php 2 patches
Indentation   +2235 added lines, -2235 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Filtres
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/charsets');
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
  * @return string Fonction PHP correspondante du filtre
43 43
  */
44 44
 function charger_filtre($fonc, $default = 'filtre_identite_dist') {
45
-	include_fichiers_fonctions(); // inclure les fichiers fonctions
46
-	return chercher_filtre($fonc, $default);
45
+    include_fichiers_fonctions(); // inclure les fichiers fonctions
46
+    return chercher_filtre($fonc, $default);
47 47
 }
48 48
 
49 49
 /**
@@ -75,38 +75,38 @@  discard block
 block discarded – undo
75 75
  *     Fonction PHP correspondante du filtre demandé
76 76
  */
77 77
 function chercher_filtre($fonc, $default = null) {
78
-	if (!$fonc) {
79
-		return $default;
80
-	}
81
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
82
-	// Foo::Bar
83
-	// qui peuvent etre avec un namespace : space\Foo::Bar
84
-	if (preg_match(',^[\w]+/,', $fonc)) {
85
-		$nom = preg_replace(',\W,', '_', $fonc);
86
-		$f = chercher_filtre($nom);
87
-		// cas du sous-type MIME sans filtre associe, passer au type:
88
-		// si filtre_text_plain pas defini, passe a filtre_text
89
-		if (!$f and $nom !== $fonc) {
90
-			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
91
-		}
92
-
93
-		return $f;
94
-	}
95
-
96
-	include_fichiers_fonctions();
97
-	foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
98
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
99
-		// fonction ou name\space\fonction
100
-		if (is_callable($f)) {
101
-			return $f;
102
-		}
103
-		// méthode statique d'une classe Classe::methode ou name\space\Classe::methode
104
-		elseif (false === strpos($f, '::') and is_callable(array($f))) {
105
-			return $f;
106
-		}
107
-	}
108
-
109
-	return $default;
78
+    if (!$fonc) {
79
+        return $default;
80
+    }
81
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
82
+    // Foo::Bar
83
+    // qui peuvent etre avec un namespace : space\Foo::Bar
84
+    if (preg_match(',^[\w]+/,', $fonc)) {
85
+        $nom = preg_replace(',\W,', '_', $fonc);
86
+        $f = chercher_filtre($nom);
87
+        // cas du sous-type MIME sans filtre associe, passer au type:
88
+        // si filtre_text_plain pas defini, passe a filtre_text
89
+        if (!$f and $nom !== $fonc) {
90
+            $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
91
+        }
92
+
93
+        return $f;
94
+    }
95
+
96
+    include_fichiers_fonctions();
97
+    foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
98
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
99
+        // fonction ou name\space\fonction
100
+        if (is_callable($f)) {
101
+            return $f;
102
+        }
103
+        // méthode statique d'une classe Classe::methode ou name\space\Classe::methode
104
+        elseif (false === strpos($f, '::') and is_callable(array($f))) {
105
+            return $f;
106
+        }
107
+    }
108
+
109
+    return $default;
110 110
 }
111 111
 
112 112
 /**
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
  *     Chaîne vide sinon.
151 151
  **/
152 152
 function appliquer_filtre($arg, $filtre) {
153
-	$args = func_get_args();
154
-	return appliquer_filtre_sinon($arg, $filtre, $args, '');
153
+    $args = func_get_args();
154
+    return appliquer_filtre_sinon($arg, $filtre, $args, '');
155 155
 }
156 156
 
157 157
 /**
@@ -176,8 +176,8 @@  discard block
 block discarded – undo
176 176
  *     Texte d'origine sinon
177 177
  **/
178 178
 function appliquer_si_filtre($arg, $filtre) {
179
-	$args = func_get_args();
180
-	return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
179
+    $args = func_get_args();
180
+    return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
181 181
 }
182 182
 
183 183
 /**
@@ -193,12 +193,12 @@  discard block
 block discarded – undo
193 193
  *     Version de SPIP
194 194
  **/
195 195
 function spip_version() {
196
-	$version = $GLOBALS['spip_version_affichee'];
197
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
198
-		$version .= " $vcs_version";
199
-	}
196
+    $version = $GLOBALS['spip_version_affichee'];
197
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
198
+        $version .= " $vcs_version";
199
+    }
200 200
 
201
-	return $version;
201
+    return $version;
202 202
 }
203 203
 
204 204
 /**
@@ -211,19 +211,19 @@  discard block
 block discarded – undo
211 211
  *    - string|null si $raw = false
212 212
  */
213 213
 function version_vcs_courante($dir, $raw = false) {
214
-	$desc = decrire_version_git($dir);
215
-	if ($desc === null) {
216
-		$desc = decrire_version_svn($dir);
217
-	}
218
-	if ($desc === null or $raw) {
219
-		return $desc;
220
-	}
221
-	// affichage "GIT [master: abcdef]"
222
-	$commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
223
-	if ($desc['branch']) {
224
-		$commit = $desc['branch'] . ': ' . $commit;
225
-	}
226
-	return "{$desc['vcs']} [$commit]";
214
+    $desc = decrire_version_git($dir);
215
+    if ($desc === null) {
216
+        $desc = decrire_version_svn($dir);
217
+    }
218
+    if ($desc === null or $raw) {
219
+        return $desc;
220
+    }
221
+    // affichage "GIT [master: abcdef]"
222
+    $commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
223
+    if ($desc['branch']) {
224
+        $commit = $desc['branch'] . ': ' . $commit;
225
+    }
226
+    return "{$desc['vcs']} [$commit]";
227 227
 }
228 228
 
229 229
 /**
@@ -235,24 +235,24 @@  discard block
 block discarded – undo
235 235
  *      array ['branch' => xx, 'commit' => yy] sinon.
236 236
  **/
237 237
 function decrire_version_git($dir) {
238
-	if (!$dir) {
239
-		$dir = '.';
240
-	}
238
+    if (!$dir) {
239
+        $dir = '.';
240
+    }
241 241
 
242
-	// version installee par GIT
243
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
244
-		$currentHead = trim(substr($c, 4));
245
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
246
-			return [
247
-				'vcs' => 'GIT',
248
-				'branch' => basename($currentHead),
249
-				'commit' => trim($hash),
250
-				'commit_short' => substr(trim($hash), 0, 8),
251
-			];
252
-		}
253
-	}
242
+    // version installee par GIT
243
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
244
+        $currentHead = trim(substr($c, 4));
245
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
246
+            return [
247
+                'vcs' => 'GIT',
248
+                'branch' => basename($currentHead),
249
+                'commit' => trim($hash),
250
+                'commit_short' => substr(trim($hash), 0, 8),
251
+            ];
252
+        }
253
+    }
254 254
 
255
-	return null;
255
+    return null;
256 256
 }
257 257
 
258 258
 
@@ -265,25 +265,25 @@  discard block
 block discarded – undo
265 265
  *      array ['commit' => yy, 'date' => xx, 'author' => xx] sinon.
266 266
  **/
267 267
 function decrire_version_svn($dir) {
268
-	if (!$dir) {
269
-		$dir = '.';
270
-	}
271
-	// version installee par SVN
272
-	if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
273
-		$db = new SQLite3($dir . '/.svn/wc.db');
274
-		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
275
-		if ($result) {
276
-			$row = $result->fetchArray();
277
-			if ($row['changed_revision'] != "") {
278
-				return [
279
-					'vcs' => 'SVN',
280
-					'branch' => '',
281
-					'commit' => $row['changed_revision'],
282
-				];
283
-			}
284
-		}
285
-	}
286
-	return null;
268
+    if (!$dir) {
269
+        $dir = '.';
270
+    }
271
+    // version installee par SVN
272
+    if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
273
+        $db = new SQLite3($dir . '/.svn/wc.db');
274
+        $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
275
+        if ($result) {
276
+            $row = $result->fetchArray();
277
+            if ($row['changed_revision'] != "") {
278
+                return [
279
+                    'vcs' => 'SVN',
280
+                    'branch' => '',
281
+                    'commit' => $row['changed_revision'],
282
+                ];
283
+            }
284
+        }
285
+    }
286
+    return null;
287 287
 }
288 288
 
289 289
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -330,18 +330,18 @@  discard block
 block discarded – undo
330 330
  *     Code HTML retourné par le filtre
331 331
  **/
332 332
 function filtrer($filtre) {
333
-	$tous = func_get_args();
334
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
335
-		return image_filtrer($tous);
336
-	} elseif ($f = chercher_filtre($filtre)) {
337
-		array_shift($tous);
338
-		return call_user_func_array($f, $tous);
339
-	} else {
340
-		// le filtre n'existe pas, on provoque une erreur
341
-		$msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre)));
342
-		erreur_squelette($msg);
343
-		return '';
344
-	}
333
+    $tous = func_get_args();
334
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
335
+        return image_filtrer($tous);
336
+    } elseif ($f = chercher_filtre($filtre)) {
337
+        array_shift($tous);
338
+        return call_user_func_array($f, $tous);
339
+    } else {
340
+        // le filtre n'existe pas, on provoque une erreur
341
+        $msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre)));
342
+        erreur_squelette($msg);
343
+        return '';
344
+    }
345 345
 }
346 346
 
347 347
 /**
@@ -358,11 +358,11 @@  discard block
 block discarded – undo
358 358
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
359 359
  */
360 360
 function trouver_filtre_matrice($filtre) {
361
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
362
-		find_in_path($f, '', true);
363
-		$GLOBALS['spip_matrice'][$filtre] = true;
364
-	}
365
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
361
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
362
+        find_in_path($f, '', true);
363
+        $GLOBALS['spip_matrice'][$filtre] = true;
364
+    }
365
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
366 366
 }
367 367
 
368 368
 
@@ -390,8 +390,8 @@  discard block
 block discarded – undo
390 390
  * @return mixed
391 391
  */
392 392
 function filtre_set(&$Pile, $val, $key, $continue = null) {
393
-	$Pile['vars'][$key] = $val;
394
-	return $continue ? $val : '';
393
+    $Pile['vars'][$key] = $val;
394
+    return $continue ? $val : '';
395 395
 }
396 396
 
397 397
 /**
@@ -417,8 +417,8 @@  discard block
 block discarded – undo
417 417
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
418 418
  */
419 419
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
420
-	$Pile[0][$key] = $val;
421
-	return $continue ? $val : '';
420
+    $Pile[0][$key] = $val;
421
+    return $continue ? $val : '';
422 422
 }
423 423
 
424 424
 /**
@@ -427,8 +427,8 @@  discard block
 block discarded – undo
427 427
  * @return string
428 428
  */
429 429
 function filtre_sanitize_env(&$Pile, $keys) {
430
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
431
-	return '';
430
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
431
+    return '';
432 432
 }
433 433
 
434 434
 
@@ -451,18 +451,18 @@  discard block
 block discarded – undo
451 451
  * @return mixed Retourne la valeur (sans la modifier).
452 452
  */
453 453
 function filtre_debug($val, $key = null) {
454
-	$debug = (
455
-		is_null($key) ? '' : (var_export($key, true) . " = ")
456
-		) . var_export($val, true);
454
+    $debug = (
455
+        is_null($key) ? '' : (var_export($key, true) . " = ")
456
+        ) . var_export($val, true);
457 457
 
458
-	include_spip('inc/autoriser');
459
-	if (autoriser('webmestre')) {
460
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
461
-	}
458
+    include_spip('inc/autoriser');
459
+    if (autoriser('webmestre')) {
460
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
461
+    }
462 462
 
463
-	spip_log($debug, 'debug');
463
+    spip_log($debug, 'debug');
464 464
 
465
-	return $val;
465
+    return $val;
466 466
 }
467 467
 
468 468
 
@@ -490,82 +490,82 @@  discard block
 block discarded – undo
490 490
  *     Texte qui a reçu les filtres
491 491
  **/
492 492
 function image_filtrer($args) {
493
-	$filtre = array_shift($args); # enlever $filtre
494
-	$texte = array_shift($args);
495
-	if (!strlen($texte)) {
496
-		return;
497
-	}
498
-	find_in_path('filtres_images_mini.php', 'inc/', true);
499
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
500
-	// Cas du nom de fichier local
501
-	$is_file = trim($texte);
502
-	if (strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
503
-		  or strpbrk($is_file, "<>\n\r\t") !== false
504
-		  or strpos($is_file, '/') === 0
505
-	) {
506
-		$is_file = false;
507
-	}
508
-	if ($is_file) {
509
-		$is_local_file = function($path) {
510
-			if (strpos($path, "?") !== false) {
511
-				$path = supprimer_timestamp($path);
512
-				// remove ?24px added by find_in_theme on .svg files
513
-				$path = preg_replace(",\?[[:digit:]]+(px)$,", "", $path);
514
-			}
515
-			return file_exists($path);
516
-		};
517
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
518
-			array_unshift($args, "<img src='$is_file' />");
519
-			$res = call_user_func_array($filtre, $args);
520
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
521
-			return $res;
522
-		}
523
-	}
524
-
525
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
526
-	if (preg_match_all(
527
-		',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
528
-		$texte, $tags, PREG_SET_ORDER)) {
529
-		foreach ($tags as $tag) {
530
-			$class = extraire_attribut($tag[3], 'class');
531
-			if (!$class or
532
-				(strpos($class, 'filtre_inactif') === false
533
-					// compat historique a virer en 3.2
534
-					and strpos($class, 'no_image_filtrer') === false)
535
-			) {
536
-				array_unshift($args, $tag[3]);
537
-				if ($reduit = call_user_func_array($filtre, $args)) {
538
-					// En cas de span spip_documents, modifier le style=...width:
539
-					if ($tag[1]) {
540
-						$w = extraire_attribut($reduit, 'width');
541
-						if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) {
542
-							$w = $regs[1];
543
-						}
544
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
545
-							$style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
546
-							$replace = inserer_attribut($tag[1], 'style', $style);
547
-							$texte = str_replace($tag[1], $replace, $texte);
548
-						}
549
-					}
550
-					// traiter aussi un eventuel mouseover
551
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
552
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
553
-							$srcover = $match[1];
554
-							array_shift($args);
555
-							array_unshift($args, "<img src='" . $match[1] . "' />");
556
-							$srcover_filter = call_user_func_array($filtre, $args);
557
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
558
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
559
-						}
560
-					}
561
-					$texte = str_replace($tag[3], $reduit, $texte);
562
-				}
563
-				array_shift($args);
564
-			}
565
-		}
566
-	}
567
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
568
-	return $texte;
493
+    $filtre = array_shift($args); # enlever $filtre
494
+    $texte = array_shift($args);
495
+    if (!strlen($texte)) {
496
+        return;
497
+    }
498
+    find_in_path('filtres_images_mini.php', 'inc/', true);
499
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
500
+    // Cas du nom de fichier local
501
+    $is_file = trim($texte);
502
+    if (strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
503
+          or strpbrk($is_file, "<>\n\r\t") !== false
504
+          or strpos($is_file, '/') === 0
505
+    ) {
506
+        $is_file = false;
507
+    }
508
+    if ($is_file) {
509
+        $is_local_file = function($path) {
510
+            if (strpos($path, "?") !== false) {
511
+                $path = supprimer_timestamp($path);
512
+                // remove ?24px added by find_in_theme on .svg files
513
+                $path = preg_replace(",\?[[:digit:]]+(px)$,", "", $path);
514
+            }
515
+            return file_exists($path);
516
+        };
517
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
518
+            array_unshift($args, "<img src='$is_file' />");
519
+            $res = call_user_func_array($filtre, $args);
520
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
521
+            return $res;
522
+        }
523
+    }
524
+
525
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
526
+    if (preg_match_all(
527
+        ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
528
+        $texte, $tags, PREG_SET_ORDER)) {
529
+        foreach ($tags as $tag) {
530
+            $class = extraire_attribut($tag[3], 'class');
531
+            if (!$class or
532
+                (strpos($class, 'filtre_inactif') === false
533
+                    // compat historique a virer en 3.2
534
+                    and strpos($class, 'no_image_filtrer') === false)
535
+            ) {
536
+                array_unshift($args, $tag[3]);
537
+                if ($reduit = call_user_func_array($filtre, $args)) {
538
+                    // En cas de span spip_documents, modifier le style=...width:
539
+                    if ($tag[1]) {
540
+                        $w = extraire_attribut($reduit, 'width');
541
+                        if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) {
542
+                            $w = $regs[1];
543
+                        }
544
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
545
+                            $style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style);
546
+                            $replace = inserer_attribut($tag[1], 'style', $style);
547
+                            $texte = str_replace($tag[1], $replace, $texte);
548
+                        }
549
+                    }
550
+                    // traiter aussi un eventuel mouseover
551
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
552
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
553
+                            $srcover = $match[1];
554
+                            array_shift($args);
555
+                            array_unshift($args, "<img src='" . $match[1] . "' />");
556
+                            $srcover_filter = call_user_func_array($filtre, $args);
557
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
558
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
559
+                        }
560
+                    }
561
+                    $texte = str_replace($tag[3], $reduit, $texte);
562
+                }
563
+                array_shift($args);
564
+            }
565
+        }
566
+    }
567
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
568
+    return $texte;
569 569
 }
570 570
 
571 571
 /**
@@ -580,77 +580,77 @@  discard block
 block discarded – undo
580 580
  **/
581 581
 function taille_image($img, $force_refresh = false) {
582 582
 
583
-	static $largeur_img = array(), $hauteur_img = array();
584
-	$srcWidth = 0;
585
-	$srcHeight = 0;
586
-
587
-	$src = extraire_attribut($img, 'src');
588
-
589
-	if (!$src) {
590
-		$src = $img;
591
-	} else {
592
-		$srcWidth = extraire_attribut($img, 'width');
593
-		$srcHeight = extraire_attribut($img, 'height');
594
-	}
595
-
596
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
597
-	// la copie locale a toutes les chances d'etre la ou de resservir
598
-	if (tester_url_absolue($src)) {
599
-		include_spip('inc/distant');
600
-		$fichier = copie_locale($src);
601
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
602
-	}
603
-	if (($p = strpos($src, '?')) !== false) {
604
-		$src = substr($src, 0, $p);
605
-	}
606
-
607
-	$srcsize = false;
608
-	if (isset($largeur_img[$src]) and !$force_refresh) {
609
-		$srcWidth = $largeur_img[$src];
610
-	}
611
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
612
-		$srcHeight = $hauteur_img[$src];
613
-	}
614
-	if (!$srcWidth or !$srcHeight) {
615
-
616
-		if (file_exists($src)
617
-			and $srcsize = spip_getimagesize($src)
618
-		) {
619
-			if (!$srcWidth) {
620
-				$largeur_img[$src] = $srcWidth = $srcsize[0];
621
-			}
622
-			if (!$srcHeight) {
623
-				$hauteur_img[$src] = $srcHeight = $srcsize[1];
624
-			}
625
-		}
626
-		elseif(strpos($src, "<svg") !== false) {
627
-			include_spip('inc/svg');
628
-			if ($attrs = svg_lire_attributs($src)){
629
-				list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
630
-				if (!$srcWidth){
631
-					$largeur_img[$src] = $srcWidth = $width;
632
-				}
633
-				if (!$srcHeight){
634
-					$hauteur_img[$src] = $srcHeight = $height;
635
-				}
636
-			}
637
-		}
638
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
639
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
640
-		elseif (@file_exists($f = "$src.src")
641
-			and lire_fichier($f, $valeurs)
642
-			and $valeurs = unserialize($valeurs)
643
-		) {
644
-			if (!$srcWidth) {
645
-				$largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"];
646
-			}
647
-			if (!$srcHeight) {
648
-				$hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"];
649
-			}
650
-		}
651
-	}
652
-
653
-	return array($srcHeight, $srcWidth);
583
+    static $largeur_img = array(), $hauteur_img = array();
584
+    $srcWidth = 0;
585
+    $srcHeight = 0;
586
+
587
+    $src = extraire_attribut($img, 'src');
588
+
589
+    if (!$src) {
590
+        $src = $img;
591
+    } else {
592
+        $srcWidth = extraire_attribut($img, 'width');
593
+        $srcHeight = extraire_attribut($img, 'height');
594
+    }
595
+
596
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
597
+    // la copie locale a toutes les chances d'etre la ou de resservir
598
+    if (tester_url_absolue($src)) {
599
+        include_spip('inc/distant');
600
+        $fichier = copie_locale($src);
601
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
602
+    }
603
+    if (($p = strpos($src, '?')) !== false) {
604
+        $src = substr($src, 0, $p);
605
+    }
606
+
607
+    $srcsize = false;
608
+    if (isset($largeur_img[$src]) and !$force_refresh) {
609
+        $srcWidth = $largeur_img[$src];
610
+    }
611
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
612
+        $srcHeight = $hauteur_img[$src];
613
+    }
614
+    if (!$srcWidth or !$srcHeight) {
615
+
616
+        if (file_exists($src)
617
+            and $srcsize = spip_getimagesize($src)
618
+        ) {
619
+            if (!$srcWidth) {
620
+                $largeur_img[$src] = $srcWidth = $srcsize[0];
621
+            }
622
+            if (!$srcHeight) {
623
+                $hauteur_img[$src] = $srcHeight = $srcsize[1];
624
+            }
625
+        }
626
+        elseif(strpos($src, "<svg") !== false) {
627
+            include_spip('inc/svg');
628
+            if ($attrs = svg_lire_attributs($src)){
629
+                list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
630
+                if (!$srcWidth){
631
+                    $largeur_img[$src] = $srcWidth = $width;
632
+                }
633
+                if (!$srcHeight){
634
+                    $hauteur_img[$src] = $srcHeight = $height;
635
+                }
636
+            }
637
+        }
638
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
639
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
640
+        elseif (@file_exists($f = "$src.src")
641
+            and lire_fichier($f, $valeurs)
642
+            and $valeurs = unserialize($valeurs)
643
+        ) {
644
+            if (!$srcWidth) {
645
+                $largeur_img[$src] = $srcWidth = $valeurs["largeur_dest"];
646
+            }
647
+            if (!$srcHeight) {
648
+                $hauteur_img[$src] = $srcHeight = $valeurs["hauteur_dest"];
649
+            }
650
+        }
651
+    }
652
+
653
+    return array($srcHeight, $srcWidth);
654 654
 }
655 655
 
656 656
 
@@ -668,12 +668,12 @@  discard block
 block discarded – undo
668 668
  *     Largeur en pixels, NULL ou 0 si aucune image.
669 669
  **/
670 670
 function largeur($img) {
671
-	if (!$img) {
672
-		return;
673
-	}
674
-	list($h, $l) = taille_image($img);
671
+    if (!$img) {
672
+        return;
673
+    }
674
+    list($h, $l) = taille_image($img);
675 675
 
676
-	return $l;
676
+    return $l;
677 677
 }
678 678
 
679 679
 /**
@@ -690,12 +690,12 @@  discard block
 block discarded – undo
690 690
  *     Hauteur en pixels, NULL ou 0 si aucune image.
691 691
  **/
692 692
 function hauteur($img) {
693
-	if (!$img) {
694
-		return;
695
-	}
696
-	list($h, $l) = taille_image($img);
693
+    if (!$img) {
694
+        return;
695
+    }
696
+    list($h, $l) = taille_image($img);
697 697
 
698
-	return $h;
698
+    return $h;
699 699
 }
700 700
 
701 701
 
@@ -715,11 +715,11 @@  discard block
 block discarded – undo
715 715
  * @return string
716 716
  **/
717 717
 function corriger_entites_html($texte) {
718
-	if (strpos($texte, '&amp;') === false) {
719
-		return $texte;
720
-	}
718
+    if (strpos($texte, '&amp;') === false) {
719
+        return $texte;
720
+    }
721 721
 
722
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
722
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
723 723
 }
724 724
 
725 725
 /**
@@ -734,11 +734,11 @@  discard block
 block discarded – undo
734 734
  * @return string
735 735
  **/
736 736
 function corriger_toutes_entites_html($texte) {
737
-	if (strpos($texte, '&amp;') === false) {
738
-		return $texte;
739
-	}
737
+    if (strpos($texte, '&amp;') === false) {
738
+        return $texte;
739
+    }
740 740
 
741
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
741
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
742 742
 }
743 743
 
744 744
 /**
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
  * @return string
749 749
  **/
750 750
 function proteger_amp($texte) {
751
-	return str_replace('&', '&amp;', $texte);
751
+    return str_replace('&', '&amp;', $texte);
752 752
 }
753 753
 
754 754
 
@@ -779,20 +779,20 @@  discard block
 block discarded – undo
779 779
  * @return mixed|string
780 780
  */
781 781
 function entites_html($texte, $tout = false, $quote = true) {
782
-	if (!is_string($texte) or !$texte
783
-		or strpbrk($texte, "&\"'<>") == false
784
-	) {
785
-		return $texte;
786
-	}
787
-	include_spip('inc/texte');
788
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
789
-	$flags |= ENT_HTML401;
790
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
791
-	if ($tout) {
792
-		return corriger_toutes_entites_html($texte);
793
-	} else {
794
-		return corriger_entites_html($texte);
795
-	}
782
+    if (!is_string($texte) or !$texte
783
+        or strpbrk($texte, "&\"'<>") == false
784
+    ) {
785
+        return $texte;
786
+    }
787
+    include_spip('inc/texte');
788
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
789
+    $flags |= ENT_HTML401;
790
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
791
+    if ($tout) {
792
+        return corriger_toutes_entites_html($texte);
793
+    } else {
794
+        return corriger_entites_html($texte);
795
+    }
796 796
 }
797 797
 
798 798
 /**
@@ -811,37 +811,37 @@  discard block
 block discarded – undo
811 811
  *     Texte converti
812 812
  **/
813 813
 function filtrer_entites($texte) {
814
-	if (strpos($texte, '&') === false) {
815
-		return $texte;
816
-	}
817
-	// filtrer
818
-	$texte = html2unicode($texte);
819
-	// remettre le tout dans le charset cible
820
-	$texte = unicode2charset($texte);
821
-	// cas particulier des " et ' qu'il faut filtrer aussi
822
-	// (on le faisait deja avec un &quot;)
823
-	if (strpos($texte, "&#") !== false) {
824
-		$texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
825
-	}
814
+    if (strpos($texte, '&') === false) {
815
+        return $texte;
816
+    }
817
+    // filtrer
818
+    $texte = html2unicode($texte);
819
+    // remettre le tout dans le charset cible
820
+    $texte = unicode2charset($texte);
821
+    // cas particulier des " et ' qu'il faut filtrer aussi
822
+    // (on le faisait deja avec un &quot;)
823
+    if (strpos($texte, "&#") !== false) {
824
+        $texte = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $texte);
825
+    }
826 826
 
827
-	return $texte;
827
+    return $texte;
828 828
 }
829 829
 
830 830
 
831 831
 if (!function_exists('filtre_filtrer_entites_dist')) {
832
-	/**
833
-	 * Version sécurisée de filtrer_entites
834
-	 * 
835
-	 * @uses interdire_scripts()
836
-	 * @uses filtrer_entites()
837
-	 * 
838
-	 * @param string $t
839
-	 * @return string
840
-	 */
841
-	function filtre_filtrer_entites_dist($t) {
842
-		include_spip('inc/texte');
843
-		return interdire_scripts(filtrer_entites($t));
844
-	}
832
+    /**
833
+     * Version sécurisée de filtrer_entites
834
+     * 
835
+     * @uses interdire_scripts()
836
+     * @uses filtrer_entites()
837
+     * 
838
+     * @param string $t
839
+     * @return string
840
+     */
841
+    function filtre_filtrer_entites_dist($t) {
842
+        include_spip('inc/texte');
843
+        return interdire_scripts(filtrer_entites($t));
844
+    }
845 845
 }
846 846
 
847 847
 
@@ -856,18 +856,18 @@  discard block
 block discarded – undo
856 856
  * @return string|array
857 857
  **/
858 858
 function supprimer_caracteres_illegaux($texte) {
859
-	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";
860
-	static $to = null;
859
+    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";
860
+    static $to = null;
861 861
 
862
-	if (is_array($texte)) {
863
-		return array_map('supprimer_caracteres_illegaux', $texte);
864
-	}
862
+    if (is_array($texte)) {
863
+        return array_map('supprimer_caracteres_illegaux', $texte);
864
+    }
865 865
 
866
-	if (!$to) {
867
-		$to = str_repeat('-', strlen($from));
868
-	}
866
+    if (!$to) {
867
+        $to = str_repeat('-', strlen($from));
868
+    }
869 869
 
870
-	return strtr($texte, $from, $to);
870
+    return strtr($texte, $from, $to);
871 871
 }
872 872
 
873 873
 /**
@@ -879,10 +879,10 @@  discard block
 block discarded – undo
879 879
  * @return string|array
880 880
  **/
881 881
 function corriger_caracteres($texte) {
882
-	$texte = corriger_caracteres_windows($texte);
883
-	$texte = supprimer_caracteres_illegaux($texte);
882
+    $texte = corriger_caracteres_windows($texte);
883
+    $texte = supprimer_caracteres_illegaux($texte);
884 884
 
885
-	return $texte;
885
+    return $texte;
886 886
 }
887 887
 
888 888
 /**
@@ -900,40 +900,40 @@  discard block
 block discarded – undo
900 900
  */
901 901
 function texte_backend($texte) {
902 902
 
903
-	static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
903
+    static $apostrophe = array("&#8217;", "'"); # n'allouer qu'une fois
904 904
 
905
-	// si on a des liens ou des images, les passer en absolu
906
-	$texte = liens_absolus($texte);
905
+    // si on a des liens ou des images, les passer en absolu
906
+    $texte = liens_absolus($texte);
907 907
 
908
-	// echapper les tags &gt; &lt;
909
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
908
+    // echapper les tags &gt; &lt;
909
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
910 910
 
911
-	// importer les &eacute;
912
-	$texte = filtrer_entites($texte);
911
+    // importer les &eacute;
912
+    $texte = filtrer_entites($texte);
913 913
 
914
-	// " -> &quot; et tout ce genre de choses
915
-	$u = $GLOBALS['meta']['pcre_u'];
916
-	$texte = str_replace("&nbsp;", " ", $texte);
917
-	$texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
918
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
919
-	$texte = entites_html($texte, false, false);
920
-	// mais bien echapper les double quotes !
921
-	$texte = str_replace('"', '&#034;', $texte);
914
+    // " -> &quot; et tout ce genre de choses
915
+    $u = $GLOBALS['meta']['pcre_u'];
916
+    $texte = str_replace("&nbsp;", " ", $texte);
917
+    $texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
918
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
919
+    $texte = entites_html($texte, false, false);
920
+    // mais bien echapper les double quotes !
921
+    $texte = str_replace('"', '&#034;', $texte);
922 922
 
923
-	// verifier le charset
924
-	$texte = charset2unicode($texte);
923
+    // verifier le charset
924
+    $texte = charset2unicode($texte);
925 925
 
926
-	// Caracteres problematiques en iso-latin 1
927
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
928
-		$texte = str_replace(chr(156), '&#156;', $texte);
929
-		$texte = str_replace(chr(140), '&#140;', $texte);
930
-		$texte = str_replace(chr(159), '&#159;', $texte);
931
-	}
926
+    // Caracteres problematiques en iso-latin 1
927
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
928
+        $texte = str_replace(chr(156), '&#156;', $texte);
929
+        $texte = str_replace(chr(140), '&#140;', $texte);
930
+        $texte = str_replace(chr(159), '&#159;', $texte);
931
+    }
932 932
 
933
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
934
-	// et le caractere apostrophe alourdit les squelettes avec PHP
935
-	// ==> on les remplace par l'entite HTML
936
-	return str_replace($apostrophe, "'", $texte);
933
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
934
+    // et le caractere apostrophe alourdit les squelettes avec PHP
935
+    // ==> on les remplace par l'entite HTML
936
+    return str_replace($apostrophe, "'", $texte);
937 937
 }
938 938
 
939 939
 /**
@@ -950,7 +950,7 @@  discard block
 block discarded – undo
950 950
  *     Texte encodé et quote pour XML
951 951
  */
952 952
 function texte_backendq($texte) {
953
-	return addslashes(texte_backend($texte));
953
+    return addslashes(texte_backend($texte));
954 954
 }
955 955
 
956 956
 
@@ -973,9 +973,9 @@  discard block
 block discarded – undo
973 973
  *     Numéro de titre, sinon chaîne vide
974 974
  **/
975 975
 function supprimer_numero($texte) {
976
-	return preg_replace(
977
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
978
-		"", $texte);
976
+    return preg_replace(
977
+        ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
978
+        "", $texte);
979 979
 }
980 980
 
981 981
 /**
@@ -998,13 +998,13 @@  discard block
 block discarded – undo
998 998
  *     Numéro de titre, sinon chaîne vide
999 999
  **/
1000 1000
 function recuperer_numero($texte) {
1001
-	if (preg_match(
1002
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
1003
-		$texte, $regs)) {
1004
-		return strval($regs[1]);
1005
-	} else {
1006
-		return '';
1007
-	}
1001
+    if (preg_match(
1002
+        ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
1003
+        $texte, $regs)) {
1004
+        return strval($regs[1]);
1005
+    } else {
1006
+        return '';
1007
+    }
1008 1008
 }
1009 1009
 
1010 1010
 /**
@@ -1031,13 +1031,13 @@  discard block
 block discarded – undo
1031 1031
  *     Texte converti
1032 1032
  **/
1033 1033
 function supprimer_tags($texte, $rempl = "") {
1034
-	$texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte);
1035
-	// ne pas oublier un < final non ferme car coupe
1036
-	$texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte);
1037
-	// mais qui peut aussi etre un simple signe plus petit que
1038
-	$texte = str_replace('<', '&lt;', $texte);
1034
+    $texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte);
1035
+    // ne pas oublier un < final non ferme car coupe
1036
+    $texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte);
1037
+    // mais qui peut aussi etre un simple signe plus petit que
1038
+    $texte = str_replace('<', '&lt;', $texte);
1039 1039
 
1040
-	return $texte;
1040
+    return $texte;
1041 1041
 }
1042 1042
 
1043 1043
 /**
@@ -1060,9 +1060,9 @@  discard block
 block discarded – undo
1060 1060
  *     Texte converti
1061 1061
  **/
1062 1062
 function echapper_tags($texte, $rempl = "") {
1063
-	$texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
1063
+    $texte = preg_replace("/<([^>]*)>/", "&lt;\\1&gt;", $texte);
1064 1064
 
1065
-	return $texte;
1065
+    return $texte;
1066 1066
 }
1067 1067
 
1068 1068
 /**
@@ -1083,18 +1083,18 @@  discard block
 block discarded – undo
1083 1083
  *     Texte converti
1084 1084
  **/
1085 1085
 function textebrut($texte) {
1086
-	$u = $GLOBALS['meta']['pcre_u'];
1087
-	$texte = preg_replace('/\s+/S' . $u, " ", $texte);
1088
-	$texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
1089
-	$texte = preg_replace("/^\n+/", "", $texte);
1090
-	$texte = preg_replace("/\n+$/", "", $texte);
1091
-	$texte = preg_replace("/\n +/", "\n", $texte);
1092
-	$texte = supprimer_tags($texte);
1093
-	$texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
1094
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1095
-	$texte = str_replace("&#8217;", "'", $texte);
1086
+    $u = $GLOBALS['meta']['pcre_u'];
1087
+    $texte = preg_replace('/\s+/S' . $u, " ", $texte);
1088
+    $texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
1089
+    $texte = preg_replace("/^\n+/", "", $texte);
1090
+    $texte = preg_replace("/\n+$/", "", $texte);
1091
+    $texte = preg_replace("/\n +/", "\n", $texte);
1092
+    $texte = supprimer_tags($texte);
1093
+    $texte = preg_replace("/(&nbsp;| )+/S", " ", $texte);
1094
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1095
+    $texte = str_replace("&#8217;", "'", $texte);
1096 1096
 
1097
-	return $texte;
1097
+    return $texte;
1098 1098
 }
1099 1099
 
1100 1100
 
@@ -1110,17 +1110,17 @@  discard block
 block discarded – undo
1110 1110
  *     Texte avec liens ouvrants
1111 1111
  **/
1112 1112
 function liens_ouvrants($texte) {
1113
-	if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1114
-		$texte, $liens, PREG_PATTERN_ORDER)) {
1115
-		foreach ($liens[0] as $a) {
1116
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1117
-			$ablank = inserer_attribut($a, 'rel', $rel);
1118
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1119
-			$texte = str_replace($a, $ablank, $texte);
1120
-		}
1121
-	}
1113
+    if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1114
+        $texte, $liens, PREG_PATTERN_ORDER)) {
1115
+        foreach ($liens[0] as $a) {
1116
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1117
+            $ablank = inserer_attribut($a, 'rel', $rel);
1118
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1119
+            $texte = str_replace($a, $ablank, $texte);
1120
+        }
1121
+    }
1122 1122
 
1123
-	return $texte;
1123
+    return $texte;
1124 1124
 }
1125 1125
 
1126 1126
 /**
@@ -1130,22 +1130,22 @@  discard block
 block discarded – undo
1130 1130
  * @return string
1131 1131
  */
1132 1132
 function liens_nofollow($texte) {
1133
-	if (stripos($texte, "<a") === false) {
1134
-		return $texte;
1135
-	}
1133
+    if (stripos($texte, "<a") === false) {
1134
+        return $texte;
1135
+    }
1136 1136
 
1137
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1138
-		foreach ($regs[0] as $a) {
1139
-			$rel = extraire_attribut($a, "rel");
1140
-			if (strpos($rel, "nofollow") === false) {
1141
-				$rel = "nofollow" . ($rel ? " $rel" : "");
1142
-				$anofollow = inserer_attribut($a, "rel", $rel);
1143
-				$texte = str_replace($a, $anofollow, $texte);
1144
-			}
1145
-		}
1146
-	}
1137
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1138
+        foreach ($regs[0] as $a) {
1139
+            $rel = extraire_attribut($a, "rel");
1140
+            if (strpos($rel, "nofollow") === false) {
1141
+                $rel = "nofollow" . ($rel ? " $rel" : "");
1142
+                $anofollow = inserer_attribut($a, "rel", $rel);
1143
+                $texte = str_replace($a, $anofollow, $texte);
1144
+            }
1145
+        }
1146
+    }
1147 1147
 
1148
-	return $texte;
1148
+    return $texte;
1149 1149
 }
1150 1150
 
1151 1151
 /**
@@ -1164,12 +1164,12 @@  discard block
 block discarded – undo
1164 1164
  *     Texte sans paraghaphes
1165 1165
  **/
1166 1166
 function PtoBR($texte) {
1167
-	$u = $GLOBALS['meta']['pcre_u'];
1168
-	$texte = preg_replace("@</p>@iS", "\n", $texte);
1169
-	$texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1170
-	$texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1167
+    $u = $GLOBALS['meta']['pcre_u'];
1168
+    $texte = preg_replace("@</p>@iS", "\n", $texte);
1169
+    $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1170
+    $texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1171 1171
 
1172
-	return $texte;
1172
+    return $texte;
1173 1173
 }
1174 1174
 
1175 1175
 
@@ -1194,14 +1194,14 @@  discard block
 block discarded – undo
1194 1194
  * @return string Texte encadré du style CSS
1195 1195
  */
1196 1196
 function lignes_longues($texte) {
1197
-	if (!strlen(trim($texte))) {
1198
-		return $texte;
1199
-	}
1200
-	include_spip('inc/texte');
1201
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1202
-		'div' : 'span';
1197
+    if (!strlen(trim($texte))) {
1198
+        return $texte;
1199
+    }
1200
+    include_spip('inc/texte');
1201
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1202
+        'div' : 'span';
1203 1203
 
1204
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1204
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1205 1205
 }
1206 1206
 
1207 1207
 /**
@@ -1220,30 +1220,30 @@  discard block
 block discarded – undo
1220 1220
  * @return string Texte en majuscule
1221 1221
  */
1222 1222
 function majuscules($texte) {
1223
-	if (!strlen($texte)) {
1224
-		return '';
1225
-	}
1223
+    if (!strlen($texte)) {
1224
+        return '';
1225
+    }
1226 1226
 
1227
-	// Cas du turc
1228
-	if ($GLOBALS['spip_lang'] == 'tr') {
1229
-		# remplacer hors des tags et des entites
1230
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1231
-			foreach ($regs as $n => $match) {
1232
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1233
-			}
1234
-		}
1227
+    // Cas du turc
1228
+    if ($GLOBALS['spip_lang'] == 'tr') {
1229
+        # remplacer hors des tags et des entites
1230
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1231
+            foreach ($regs as $n => $match) {
1232
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1233
+            }
1234
+        }
1235 1235
 
1236
-		$texte = str_replace('i', '&#304;', $texte);
1236
+        $texte = str_replace('i', '&#304;', $texte);
1237 1237
 
1238
-		if ($regs) {
1239
-			foreach ($regs as $n => $match) {
1240
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1241
-			}
1242
-		}
1243
-	}
1238
+        if ($regs) {
1239
+            foreach ($regs as $n => $match) {
1240
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1241
+            }
1242
+        }
1243
+    }
1244 1244
 
1245
-	// Cas general
1246
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1245
+    // Cas general
1246
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1247 1247
 }
1248 1248
 
1249 1249
 /**
@@ -1261,29 +1261,29 @@  discard block
 block discarded – undo
1261 1261
  * @return string
1262 1262
  **/
1263 1263
 function taille_en_octets($taille) {
1264
-	if (!defined('_KILOBYTE')) {
1265
-		/**
1266
-		 * Définit le nombre d'octets dans un Kilobyte
1267
-		 *
1268
-		 * @var int
1269
-		 **/
1270
-		define('_KILOBYTE', 1024);
1271
-	}
1264
+    if (!defined('_KILOBYTE')) {
1265
+        /**
1266
+         * Définit le nombre d'octets dans un Kilobyte
1267
+         *
1268
+         * @var int
1269
+         **/
1270
+        define('_KILOBYTE', 1024);
1271
+    }
1272 1272
 
1273
-	if ($taille < 1) {
1274
-		return '';
1275
-	}
1276
-	if ($taille < _KILOBYTE) {
1277
-		$taille = _T('taille_octets', array('taille' => $taille));
1278
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1279
-		$taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1)));
1280
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1281
-		$taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)));
1282
-	} else {
1283
-		$taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)));
1284
-	}
1273
+    if ($taille < 1) {
1274
+        return '';
1275
+    }
1276
+    if ($taille < _KILOBYTE) {
1277
+        $taille = _T('taille_octets', array('taille' => $taille));
1278
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1279
+        $taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1)));
1280
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1281
+        $taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)));
1282
+    } else {
1283
+        $taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)));
1284
+    }
1285 1285
 
1286
-	return $taille;
1286
+    return $taille;
1287 1287
 }
1288 1288
 
1289 1289
 
@@ -1305,15 +1305,15 @@  discard block
 block discarded – undo
1305 1305
  *     Texte prêt pour être utilisé en attribut HTML
1306 1306
  **/
1307 1307
 function attribut_html($texte, $textebrut = true) {
1308
-	$u = $GLOBALS['meta']['pcre_u'];
1309
-	if ($textebrut) {
1310
-		$texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1311
-	}
1312
-	$texte = texte_backend($texte);
1313
-	$texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
1308
+    $u = $GLOBALS['meta']['pcre_u'];
1309
+    if ($textebrut) {
1310
+        $texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1311
+    }
1312
+    $texte = texte_backend($texte);
1313
+    $texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
1314 1314
 
1315
-	return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"),
1316
-		$texte);
1315
+    return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&#38;"),
1316
+        $texte);
1317 1317
 }
1318 1318
 
1319 1319
 
@@ -1333,12 +1333,12 @@  discard block
 block discarded – undo
1333 1333
  *     URL ou chaîne vide
1334 1334
  **/
1335 1335
 function vider_url($url, $entites = true) {
1336
-	# un message pour abs_url
1337
-	$GLOBALS['mode_abs_url'] = 'url';
1338
-	$url = trim($url);
1339
-	$r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1336
+    # un message pour abs_url
1337
+    $GLOBALS['mode_abs_url'] = 'url';
1338
+    $url = trim($url);
1339
+    $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1340 1340
 
1341
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1341
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1342 1342
 }
1343 1343
 
1344 1344
 
@@ -1353,10 +1353,10 @@  discard block
 block discarded – undo
1353 1353
  * @return string Adresse email maquillée
1354 1354
  **/
1355 1355
 function antispam($texte) {
1356
-	include_spip('inc/acces');
1357
-	$masque = creer_pass_aleatoire(3);
1356
+    include_spip('inc/acces');
1357
+    $masque = creer_pass_aleatoire(3);
1358 1358
 
1359
-	return preg_replace("/@/", " $masque ", $texte);
1359
+    return preg_replace("/@/", " $masque ", $texte);
1360 1360
 }
1361 1361
 
1362 1362
 /**
@@ -1388,12 +1388,12 @@  discard block
 block discarded – undo
1388 1388
  *     True si on a le droit d'accès, false sinon.
1389 1389
  **/
1390 1390
 function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') {
1391
-	include_spip('inc/acces');
1392
-	if ($op) {
1393
-		$dir .= " $op $args";
1394
-	}
1391
+    include_spip('inc/acces');
1392
+    if ($op) {
1393
+        $dir .= " $op $args";
1394
+    }
1395 1395
 
1396
-	return verifier_low_sec($id_auteur, $cle, $dir);
1396
+    return verifier_low_sec($id_auteur, $cle, $dir);
1397 1397
 }
1398 1398
 
1399 1399
 /**
@@ -1418,11 +1418,11 @@  discard block
 block discarded – undo
1418 1418
  *     Retourne $texte, sinon $sinon.
1419 1419
  **/
1420 1420
 function sinon($texte, $sinon = '') {
1421
-	if ($texte or (!is_array($texte) and strlen($texte))) {
1422
-		return $texte;
1423
-	} else {
1424
-		return $sinon;
1425
-	}
1421
+    if ($texte or (!is_array($texte) and strlen($texte))) {
1422
+        return $texte;
1423
+    } else {
1424
+        return $sinon;
1425
+    }
1426 1426
 }
1427 1427
 
1428 1428
 /**
@@ -1446,7 +1446,7 @@  discard block
 block discarded – undo
1446 1446
  * @return mixed
1447 1447
  **/
1448 1448
 function choixsivide($a, $vide, $pasvide) {
1449
-	return $a ? $pasvide : $vide;
1449
+    return $a ? $pasvide : $vide;
1450 1450
 }
1451 1451
 
1452 1452
 /**
@@ -1470,7 +1470,7 @@  discard block
 block discarded – undo
1470 1470
  * @return mixed
1471 1471
  **/
1472 1472
 function choixsiegal($a1, $a2, $v, $f) {
1473
-	return ($a1 == $a2) ? $v : $f;
1473
+    return ($a1 == $a2) ? $v : $f;
1474 1474
 }
1475 1475
 
1476 1476
 //
@@ -1489,13 +1489,13 @@  discard block
 block discarded – undo
1489 1489
  * @return string
1490 1490
  **/
1491 1491
 function filtrer_ical($texte) {
1492
-	#include_spip('inc/charsets');
1493
-	$texte = html2unicode($texte);
1494
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1495
-	$texte = preg_replace("/\n/", " ", $texte);
1496
-	$texte = preg_replace("/,/", "\,", $texte);
1492
+    #include_spip('inc/charsets');
1493
+    $texte = html2unicode($texte);
1494
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8');
1495
+    $texte = preg_replace("/\n/", " ", $texte);
1496
+    $texte = preg_replace("/,/", "\,", $texte);
1497 1497
 
1498
-	return $texte;
1498
+    return $texte;
1499 1499
 }
1500 1500
 
1501 1501
 
@@ -1520,53 +1520,53 @@  discard block
 block discarded – undo
1520 1520
  * @return string
1521 1521
  **/
1522 1522
 function post_autobr($texte, $delim = "\n_ ") {
1523
-	if (!function_exists('echappe_html')) {
1524
-		include_spip('inc/texte_mini');
1525
-	}
1526
-	$texte = str_replace("\r\n", "\r", $texte);
1527
-	$texte = str_replace("\r", "\n", $texte);
1528
-
1529
-	if (preg_match(",\n+$,", $texte, $fin)) {
1530
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1531
-	} else {
1532
-		$fin = '';
1533
-	}
1534
-
1535
-	$texte = echappe_html($texte, '', true);
1536
-
1537
-	// echapper les modeles
1538
-	if (strpos($texte, "<") !== false) {
1539
-		include_spip('inc/lien');
1540
-		if (defined('_PREG_MODELE')) {
1541
-			$preg_modeles = "@" . _PREG_MODELE . "@imsS";
1542
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1543
-		}
1544
-	}
1545
-
1546
-	$debut = '';
1547
-	$suite = $texte;
1548
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1549
-		$debut .= substr($suite, 0, $t - 1);
1550
-		$suite = substr($suite, $t);
1551
-		$car = substr($suite, 0, 1);
1552
-		if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}")
1553
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1554
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1555
-		) {
1556
-			$debut .= $delim;
1557
-		} else {
1558
-			$debut .= "\n";
1559
-		}
1560
-		if (preg_match(",^\n+,", $suite, $regs)) {
1561
-			$debut .= $regs[0];
1562
-			$suite = substr($suite, strlen($regs[0]));
1563
-		}
1564
-	}
1565
-	$texte = $debut . $suite;
1566
-
1567
-	$texte = echappe_retour($texte);
1568
-
1569
-	return $texte . $fin;
1523
+    if (!function_exists('echappe_html')) {
1524
+        include_spip('inc/texte_mini');
1525
+    }
1526
+    $texte = str_replace("\r\n", "\r", $texte);
1527
+    $texte = str_replace("\r", "\n", $texte);
1528
+
1529
+    if (preg_match(",\n+$,", $texte, $fin)) {
1530
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1531
+    } else {
1532
+        $fin = '';
1533
+    }
1534
+
1535
+    $texte = echappe_html($texte, '', true);
1536
+
1537
+    // echapper les modeles
1538
+    if (strpos($texte, "<") !== false) {
1539
+        include_spip('inc/lien');
1540
+        if (defined('_PREG_MODELE')) {
1541
+            $preg_modeles = "@" . _PREG_MODELE . "@imsS";
1542
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1543
+        }
1544
+    }
1545
+
1546
+    $debut = '';
1547
+    $suite = $texte;
1548
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1549
+        $debut .= substr($suite, 0, $t - 1);
1550
+        $suite = substr($suite, $t);
1551
+        $car = substr($suite, 0, 1);
1552
+        if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}")
1553
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1554
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1555
+        ) {
1556
+            $debut .= $delim;
1557
+        } else {
1558
+            $debut .= "\n";
1559
+        }
1560
+        if (preg_match(",^\n+,", $suite, $regs)) {
1561
+            $debut .= $regs[0];
1562
+            $suite = substr($suite, strlen($regs[0]));
1563
+        }
1564
+    }
1565
+    $texte = $debut . $suite;
1566
+
1567
+    $texte = echappe_retour($texte);
1568
+
1569
+    return $texte . $fin;
1570 1570
 }
1571 1571
 
1572 1572
 
@@ -1607,46 +1607,46 @@  discard block
 block discarded – undo
1607 1607
  * @return string
1608 1608
  **/
1609 1609
 function extraire_idiome($letexte, $lang = null, $options = array()) {
1610
-	static $traduire = false;
1611
-	if ($letexte
1612
-		and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1613
-	) {
1614
-		if (!$traduire) {
1615
-			$traduire = charger_fonction('traduire', 'inc');
1616
-			include_spip('inc/lang');
1617
-		}
1618
-		if (!$lang) {
1619
-			$lang = $GLOBALS['spip_lang'];
1620
-		}
1621
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1622
-		if (is_bool($options)) {
1623
-			$options = array('echappe_span' => $options);
1624
-		}
1625
-		if (!isset($options['echappe_span'])) {
1626
-			$options = array_merge($options, array('echappe_span' => false));
1627
-		}
1628
-
1629
-		foreach ($regs as $reg) {
1630
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1631
-			$desc = $traduire($cle, $lang, true);
1632
-			$l = $desc->langue;
1633
-			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1634
-			if (strlen($desc->texte)) {
1635
-				$trad = code_echappement($desc->texte, 'idiome', false);
1636
-				if ($l !== $lang) {
1637
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1638
-				}
1639
-				if (lang_dir($l) !== lang_dir($lang)) {
1640
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1641
-				}
1642
-				if (!$options['echappe_span']) {
1643
-					$trad = echappe_retour($trad, 'idiome');
1644
-				}
1645
-				$letexte = str_replace($reg[0], $trad, $letexte);
1646
-			}
1647
-		}
1648
-	}
1649
-	return $letexte;
1610
+    static $traduire = false;
1611
+    if ($letexte
1612
+        and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1613
+    ) {
1614
+        if (!$traduire) {
1615
+            $traduire = charger_fonction('traduire', 'inc');
1616
+            include_spip('inc/lang');
1617
+        }
1618
+        if (!$lang) {
1619
+            $lang = $GLOBALS['spip_lang'];
1620
+        }
1621
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1622
+        if (is_bool($options)) {
1623
+            $options = array('echappe_span' => $options);
1624
+        }
1625
+        if (!isset($options['echappe_span'])) {
1626
+            $options = array_merge($options, array('echappe_span' => false));
1627
+        }
1628
+
1629
+        foreach ($regs as $reg) {
1630
+            $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1631
+            $desc = $traduire($cle, $lang, true);
1632
+            $l = $desc->langue;
1633
+            // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1634
+            if (strlen($desc->texte)) {
1635
+                $trad = code_echappement($desc->texte, 'idiome', false);
1636
+                if ($l !== $lang) {
1637
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1638
+                }
1639
+                if (lang_dir($l) !== lang_dir($lang)) {
1640
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1641
+                }
1642
+                if (!$options['echappe_span']) {
1643
+                    $trad = echappe_retour($trad, 'idiome');
1644
+                }
1645
+                $letexte = str_replace($reg[0], $trad, $letexte);
1646
+            }
1647
+        }
1648
+    }
1649
+    return $letexte;
1650 1650
 }
1651 1651
 
1652 1652
 /**
@@ -1698,67 +1698,67 @@  discard block
 block discarded – undo
1698 1698
  **/
1699 1699
 function extraire_multi($letexte, $lang = null, $options = array()) {
1700 1700
 
1701
-	if ($letexte
1702
-		and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1703
-	) {
1704
-		if (!$lang) {
1705
-			$lang = $GLOBALS['spip_lang'];
1706
-		}
1707
-
1708
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1709
-		if (is_bool($options)) {
1710
-			$options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
1711
-		}
1712
-		if (!isset($options['echappe_span'])) {
1713
-			$options = array_merge($options, array('echappe_span' => false));
1714
-		}
1715
-		if (!isset($options['lang_defaut'])) {
1716
-			$options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
1717
-		}
1718
-
1719
-		include_spip('inc/lang');
1720
-		foreach ($regs as $reg) {
1721
-			// chercher la version de la langue courante
1722
-			$trads = extraire_trads($reg[1]);
1723
-			if ($l = approcher_langue($trads, $lang)) {
1724
-				$trad = $trads[$l];
1725
-			} else {
1726
-				if ($options['lang_defaut'] == 'aucune') {
1727
-					$trad = '';
1728
-				} else {
1729
-					// langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1730
-					// ou la premiere dispo
1731
-					// mais typographier le texte selon les regles de celle-ci
1732
-					// Attention aux blocs multi sur plusieurs lignes
1733
-					if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1734
-						$l = key($trads);
1735
-					}
1736
-					$trad = $trads[$l];
1737
-					$typographie = charger_fonction(lang_typo($l), 'typographie');
1738
-					$trad = $typographie($trad);
1739
-					// Tester si on echappe en span ou en div
1740
-					// il ne faut pas echapper en div si propre produit un seul paragraphe
1741
-					include_spip('inc/texte');
1742
-					$trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1743
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1744
-					if ($mode === 'div') {
1745
-						$trad = rtrim($trad) . "\n\n";
1746
-					}
1747
-					$trad = code_echappement($trad, 'multi', false, $mode);
1748
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1749
-					if (lang_dir($l) !== lang_dir($lang)) {
1750
-						$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1751
-					}
1752
-					if (!$options['echappe_span']) {
1753
-						$trad = echappe_retour($trad, 'multi');
1754
-					}
1755
-				}
1756
-			}
1757
-			$letexte = str_replace($reg[0], $trad, $letexte);
1758
-		}
1759
-	}
1760
-
1761
-	return $letexte;
1701
+    if ($letexte
1702
+        and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1703
+    ) {
1704
+        if (!$lang) {
1705
+            $lang = $GLOBALS['spip_lang'];
1706
+        }
1707
+
1708
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1709
+        if (is_bool($options)) {
1710
+            $options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
1711
+        }
1712
+        if (!isset($options['echappe_span'])) {
1713
+            $options = array_merge($options, array('echappe_span' => false));
1714
+        }
1715
+        if (!isset($options['lang_defaut'])) {
1716
+            $options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
1717
+        }
1718
+
1719
+        include_spip('inc/lang');
1720
+        foreach ($regs as $reg) {
1721
+            // chercher la version de la langue courante
1722
+            $trads = extraire_trads($reg[1]);
1723
+            if ($l = approcher_langue($trads, $lang)) {
1724
+                $trad = $trads[$l];
1725
+            } else {
1726
+                if ($options['lang_defaut'] == 'aucune') {
1727
+                    $trad = '';
1728
+                } else {
1729
+                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1730
+                    // ou la premiere dispo
1731
+                    // mais typographier le texte selon les regles de celle-ci
1732
+                    // Attention aux blocs multi sur plusieurs lignes
1733
+                    if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1734
+                        $l = key($trads);
1735
+                    }
1736
+                    $trad = $trads[$l];
1737
+                    $typographie = charger_fonction(lang_typo($l), 'typographie');
1738
+                    $trad = $typographie($trad);
1739
+                    // Tester si on echappe en span ou en div
1740
+                    // il ne faut pas echapper en div si propre produit un seul paragraphe
1741
+                    include_spip('inc/texte');
1742
+                    $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1743
+                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1744
+                    if ($mode === 'div') {
1745
+                        $trad = rtrim($trad) . "\n\n";
1746
+                    }
1747
+                    $trad = code_echappement($trad, 'multi', false, $mode);
1748
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1749
+                    if (lang_dir($l) !== lang_dir($lang)) {
1750
+                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1751
+                    }
1752
+                    if (!$options['echappe_span']) {
1753
+                        $trad = echappe_retour($trad, 'multi');
1754
+                    }
1755
+                }
1756
+            }
1757
+            $letexte = str_replace($reg[0], $trad, $letexte);
1758
+        }
1759
+    }
1760
+
1761
+    return $letexte;
1762 1762
 }
1763 1763
 
1764 1764
 /**
@@ -1774,20 +1774,20 @@  discard block
 block discarded – undo
1774 1774
  *     Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué.
1775 1775
  **/
1776 1776
 function extraire_trads($bloc) {
1777
-	$lang = '';
1777
+    $lang = '';
1778 1778
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1779 1779
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1780
-	while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1781
-		$texte = trim($regs[1]);
1782
-		if ($texte or $lang) {
1783
-			$trads[$lang] = $texte;
1784
-		}
1785
-		$bloc = substr($bloc, strlen($regs[0]));
1786
-		$lang = $regs[2];
1787
-	}
1788
-	$trads[$lang] = $bloc;
1780
+    while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) {
1781
+        $texte = trim($regs[1]);
1782
+        if ($texte or $lang) {
1783
+            $trads[$lang] = $texte;
1784
+        }
1785
+        $bloc = substr($bloc, strlen($regs[0]));
1786
+        $lang = $regs[2];
1787
+    }
1788
+    $trads[$lang] = $bloc;
1789 1789
 
1790
-	return $trads;
1790
+    return $trads;
1791 1791
 }
1792 1792
 
1793 1793
 
@@ -1798,7 +1798,7 @@  discard block
 block discarded – undo
1798 1798
  * @return string L'initiale en majuscule
1799 1799
  */
1800 1800
 function filtre_initiale($nom) {
1801
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1801
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1802 1802
 }
1803 1803
 
1804 1804
 
@@ -1843,33 +1843,33 @@  discard block
 block discarded – undo
1843 1843
  *      - null (interne) : si on empile
1844 1844
  **/
1845 1845
 function unique($donnee, $famille = '', $cpt = false) {
1846
-	static $mem = array();
1847
-	// permettre de vider la pile et de la restaurer
1848
-	// pour le calcul de introduction...
1849
-	if ($famille == '_spip_raz_') {
1850
-		$tmp = $mem;
1851
-		$mem = array();
1852
-
1853
-		return $tmp;
1854
-	} elseif ($famille == '_spip_set_') {
1855
-		$mem = $donnee;
1856
-
1857
-		return;
1858
-	}
1859
-	// eviter une notice
1860
-	if (!isset($mem[$famille])) {
1861
-		$mem[$famille] = array();
1862
-	}
1863
-	if ($cpt) {
1864
-		return count($mem[$famille]);
1865
-	}
1866
-	// eviter une notice
1867
-	if (!isset($mem[$famille][$donnee])) {
1868
-		$mem[$famille][$donnee] = 0;
1869
-	}
1870
-	if (!($mem[$famille][$donnee]++)) {
1871
-		return $donnee;
1872
-	}
1846
+    static $mem = array();
1847
+    // permettre de vider la pile et de la restaurer
1848
+    // pour le calcul de introduction...
1849
+    if ($famille == '_spip_raz_') {
1850
+        $tmp = $mem;
1851
+        $mem = array();
1852
+
1853
+        return $tmp;
1854
+    } elseif ($famille == '_spip_set_') {
1855
+        $mem = $donnee;
1856
+
1857
+        return;
1858
+    }
1859
+    // eviter une notice
1860
+    if (!isset($mem[$famille])) {
1861
+        $mem[$famille] = array();
1862
+    }
1863
+    if ($cpt) {
1864
+        return count($mem[$famille]);
1865
+    }
1866
+    // eviter une notice
1867
+    if (!isset($mem[$famille][$donnee])) {
1868
+        $mem[$famille][$donnee] = 0;
1869
+    }
1870
+    if (!($mem[$famille][$donnee]++)) {
1871
+        return $donnee;
1872
+    }
1873 1873
 }
1874 1874
 
1875 1875
 
@@ -1899,16 +1899,16 @@  discard block
 block discarded – undo
1899 1899
  *     Une des valeurs en fonction du compteur.
1900 1900
  **/
1901 1901
 function alterner($i, ...$args) {
1902
-	// recuperer les arguments (attention fonctions un peu space)
1903
-	$num = count($args);
1902
+    // recuperer les arguments (attention fonctions un peu space)
1903
+    $num = count($args);
1904 1904
 
1905
-	if ($num === 1 && is_array($args[0])) {
1906
-		$args = $args[0];
1907
-		$num = count($args);
1908
-	}
1905
+    if ($num === 1 && is_array($args[0])) {
1906
+        $args = $args[0];
1907
+        $num = count($args);
1908
+    }
1909 1909
 
1910
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1911
-	return $args[(intval($i) - 1) % $num];
1910
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1911
+    return $args[(intval($i) - 1) % $num];
1912 1912
 }
1913 1913
 
1914 1914
 
@@ -1933,46 +1933,46 @@  discard block
 block discarded – undo
1933 1933
  *     - Tableau complet (si 2e argument)
1934 1934
  **/
1935 1935
 function extraire_attribut($balise, $attribut, $complet = false) {
1936
-	if (is_array($balise)) {
1937
-		array_walk(
1938
-			$balise,
1939
-			function(&$a, $key, $t){
1940
-				$a = extraire_attribut($a, $t);
1941
-			},
1942
-			$attribut
1943
-		);
1944
-
1945
-		return $balise;
1946
-	}
1947
-	if (preg_match(
1948
-		',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1949
-		. $attribut
1950
-		. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1951
-
1952
-		$balise, $r)) {
1953
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1954
-			$r[4] = substr($r[3], 1, -1);
1955
-			$r[3] = $r[3][0];
1956
-		} elseif ($r[3] !== '') {
1957
-			$r[4] = $r[3];
1958
-			$r[3] = '';
1959
-		} else {
1960
-			$r[4] = trim($r[2]);
1961
-		}
1962
-		$att = $r[4];
1963
-		if (strpos($att, "&#") !== false) {
1964
-			$att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1965
-		}
1966
-		$att = filtrer_entites($att);
1967
-	} else {
1968
-		$att = null;
1969
-	}
1970
-
1971
-	if ($complet) {
1972
-		return array($att, $r);
1973
-	} else {
1974
-		return $att;
1975
-	}
1936
+    if (is_array($balise)) {
1937
+        array_walk(
1938
+            $balise,
1939
+            function(&$a, $key, $t){
1940
+                $a = extraire_attribut($a, $t);
1941
+            },
1942
+            $attribut
1943
+        );
1944
+
1945
+        return $balise;
1946
+    }
1947
+    if (preg_match(
1948
+        ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1949
+        . $attribut
1950
+        . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1951
+
1952
+        $balise, $r)) {
1953
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1954
+            $r[4] = substr($r[3], 1, -1);
1955
+            $r[3] = $r[3][0];
1956
+        } elseif ($r[3] !== '') {
1957
+            $r[4] = $r[3];
1958
+            $r[3] = '';
1959
+        } else {
1960
+            $r[4] = trim($r[2]);
1961
+        }
1962
+        $att = $r[4];
1963
+        if (strpos($att, "&#") !== false) {
1964
+            $att = str_replace(array("&#039;", "&#39;", "&#034;", "&#34;"), array("'", "'", '"', '"'), $att);
1965
+        }
1966
+        $att = filtrer_entites($att);
1967
+    } else {
1968
+        $att = null;
1969
+    }
1970
+
1971
+    if ($complet) {
1972
+        return array($att, $r);
1973
+    } else {
1974
+        return $att;
1975
+    }
1976 1976
 }
1977 1977
 
1978 1978
 /**
@@ -2004,37 +2004,37 @@  discard block
 block discarded – undo
2004 2004
  *     Code html modifié
2005 2005
  **/
2006 2006
 function inserer_attribut($balise, $attribut, $val, $proteger = true, $vider = false) {
2007
-	// preparer l'attribut
2008
-	// supprimer les &nbsp; etc mais pas les balises html
2009
-	// qui ont un sens dans un attribut value d'un input
2010
-	if ($proteger) {
2011
-		$val = attribut_html($val, false);
2012
-	}
2013
-
2014
-	// echapper les ' pour eviter tout bug
2015
-	$val = str_replace("'", "&#039;", $val);
2016
-	if ($vider and strlen($val) == 0) {
2017
-		$insert = '';
2018
-	} else {
2019
-		$insert = " $attribut='$val'";
2020
-	}
2021
-
2022
-	list($old, $r) = extraire_attribut($balise, $attribut, true);
2023
-
2024
-	if ($old !== null) {
2025
-		// Remplacer l'ancien attribut du meme nom
2026
-		$balise = $r[1] . $insert . $r[5];
2027
-	} else {
2028
-		// preferer une balise " />" (comme <img />)
2029
-		if (preg_match(',/>,', $balise)) {
2030
-			$balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
2031
-		} // sinon une balise <a ...> ... </a>
2032
-		else {
2033
-			$balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
2034
-		}
2035
-	}
2036
-
2037
-	return $balise;
2007
+    // preparer l'attribut
2008
+    // supprimer les &nbsp; etc mais pas les balises html
2009
+    // qui ont un sens dans un attribut value d'un input
2010
+    if ($proteger) {
2011
+        $val = attribut_html($val, false);
2012
+    }
2013
+
2014
+    // echapper les ' pour eviter tout bug
2015
+    $val = str_replace("'", "&#039;", $val);
2016
+    if ($vider and strlen($val) == 0) {
2017
+        $insert = '';
2018
+    } else {
2019
+        $insert = " $attribut='$val'";
2020
+    }
2021
+
2022
+    list($old, $r) = extraire_attribut($balise, $attribut, true);
2023
+
2024
+    if ($old !== null) {
2025
+        // Remplacer l'ancien attribut du meme nom
2026
+        $balise = $r[1] . $insert . $r[5];
2027
+    } else {
2028
+        // preferer une balise " />" (comme <img />)
2029
+        if (preg_match(',/>,', $balise)) {
2030
+            $balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
2031
+        } // sinon une balise <a ...> ... </a>
2032
+        else {
2033
+            $balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
2034
+        }
2035
+    }
2036
+
2037
+    return $balise;
2038 2038
 }
2039 2039
 
2040 2040
 /**
@@ -2052,7 +2052,7 @@  discard block
 block discarded – undo
2052 2052
  * @return string Code HTML sans l'attribut
2053 2053
  **/
2054 2054
 function vider_attribut($balise, $attribut) {
2055
-	return inserer_attribut($balise, $attribut, '', false, true);
2055
+    return inserer_attribut($balise, $attribut, '', false, true);
2056 2056
 }
2057 2057
 
2058 2058
 /**
@@ -2064,50 +2064,50 @@  discard block
 block discarded – undo
2064 2064
  * @return string
2065 2065
  */
2066 2066
 function modifier_class($balise, $class, $operation='ajouter') {
2067
-	if (is_string($class)) {
2068
-		$class = explode(' ', trim($class));
2069
-	}
2070
-	$class = array_filter($class);
2071
-
2072
-	// si la ou les classes ont des caracteres invalides on ne fait rien
2073
-	if (preg_match(",[^\w-],", implode('', $class))) {
2074
-		return $balise;
2075
-	}
2076
-
2077
-	if ($class) {
2078
-		$class = array_unique($class);
2079
-		$class_courante = extraire_attribut($balise, 'class');
2080
-
2081
-		$class_new = $class_courante;
2082
-		foreach ($class as $c) {
2083
-			if ($c) {
2084
-				$is_class_presente = false;
2085
-				if (strpos($class_courante, $c) !== false
2086
-					and preg_match("/(^|\s)".preg_quote($c)."($|\s)/", $class_courante)) {
2087
-					$is_class_presente = true;
2088
-				}
2089
-				if (in_array($operation, ['ajouter', 'commuter'])
2090
-					and !$is_class_presente) {
2091
-					$class_new = rtrim($class_new) . " " . $c;
2092
-				}
2093
-				elseif (in_array($operation, ['supprimer', 'commuter'])
2094
-					and $is_class_presente) {
2095
-					$class_new = trim(preg_replace("/(^|\s)".preg_quote($c)."($|\s)/", "\\1", $class_new));
2096
-				}
2097
-			}
2098
-		}
2099
-
2100
-		if ($class_new !== $class_courante) {
2101
-			if (strlen($class_new)) {
2102
-				$balise = inserer_attribut($balise, 'class', $class_new);
2103
-			}
2104
-			elseif ($class_courante) {
2105
-				$balise = vider_attribut($balise, 'class');
2106
-			}
2107
-		}
2108
-	}
2109
-
2110
-	return $balise;
2067
+    if (is_string($class)) {
2068
+        $class = explode(' ', trim($class));
2069
+    }
2070
+    $class = array_filter($class);
2071
+
2072
+    // si la ou les classes ont des caracteres invalides on ne fait rien
2073
+    if (preg_match(",[^\w-],", implode('', $class))) {
2074
+        return $balise;
2075
+    }
2076
+
2077
+    if ($class) {
2078
+        $class = array_unique($class);
2079
+        $class_courante = extraire_attribut($balise, 'class');
2080
+
2081
+        $class_new = $class_courante;
2082
+        foreach ($class as $c) {
2083
+            if ($c) {
2084
+                $is_class_presente = false;
2085
+                if (strpos($class_courante, $c) !== false
2086
+                    and preg_match("/(^|\s)".preg_quote($c)."($|\s)/", $class_courante)) {
2087
+                    $is_class_presente = true;
2088
+                }
2089
+                if (in_array($operation, ['ajouter', 'commuter'])
2090
+                    and !$is_class_presente) {
2091
+                    $class_new = rtrim($class_new) . " " . $c;
2092
+                }
2093
+                elseif (in_array($operation, ['supprimer', 'commuter'])
2094
+                    and $is_class_presente) {
2095
+                    $class_new = trim(preg_replace("/(^|\s)".preg_quote($c)."($|\s)/", "\\1", $class_new));
2096
+                }
2097
+            }
2098
+        }
2099
+
2100
+        if ($class_new !== $class_courante) {
2101
+            if (strlen($class_new)) {
2102
+                $balise = inserer_attribut($balise, 'class', $class_new);
2103
+            }
2104
+            elseif ($class_courante) {
2105
+                $balise = vider_attribut($balise, 'class');
2106
+            }
2107
+        }
2108
+    }
2109
+
2110
+    return $balise;
2111 2111
 }
2112 2112
 
2113 2113
 /**
@@ -2117,7 +2117,7 @@  discard block
 block discarded – undo
2117 2117
  * @return string
2118 2118
  */
2119 2119
 function ajouter_class($balise, $class){
2120
-	return modifier_class($balise, $class, 'ajouter');
2120
+    return modifier_class($balise, $class, 'ajouter');
2121 2121
 }
2122 2122
 
2123 2123
 /**
@@ -2127,7 +2127,7 @@  discard block
 block discarded – undo
2127 2127
  * @return string
2128 2128
  */
2129 2129
 function supprimer_class($balise, $class){
2130
-	return modifier_class($balise, $class, 'supprimer');
2130
+    return modifier_class($balise, $class, 'supprimer');
2131 2131
 }
2132 2132
 
2133 2133
 /**
@@ -2138,7 +2138,7 @@  discard block
 block discarded – undo
2138 2138
  * @return string
2139 2139
  */
2140 2140
 function commuter_class($balise, $class){
2141
-	return modifier_class($balise, $class, 'commuter');
2141
+    return modifier_class($balise, $class, 'commuter');
2142 2142
 }
2143 2143
 
2144 2144
 /**
@@ -2149,9 +2149,9 @@  discard block
 block discarded – undo
2149 2149
  * @return string
2150 2150
  */
2151 2151
 function tester_config($id, $mode = '') {
2152
-	include_spip('action/inscrire_auteur');
2152
+    include_spip('action/inscrire_auteur');
2153 2153
 
2154
-	return tester_statut_inscription($mode, $id);
2154
+    return tester_statut_inscription($mode, $id);
2155 2155
 }
2156 2156
 
2157 2157
 //
@@ -2176,7 +2176,7 @@  discard block
 block discarded – undo
2176 2176
  * @return int $a+$b
2177 2177
  **/
2178 2178
 function plus($a, $b) {
2179
-	return $a + $b;
2179
+    return $a + $b;
2180 2180
 }
2181 2181
 function strplus($a, $b) {return strize('plus', $a, $b);}
2182 2182
 /**
@@ -2195,7 +2195,7 @@  discard block
 block discarded – undo
2195 2195
  * @return int $a-$b
2196 2196
  **/
2197 2197
 function moins($a, $b) {
2198
-	return $a - $b;
2198
+    return $a - $b;
2199 2199
 }
2200 2200
 function strmoins($a, $b) {return strize('moins', $a, $b);}
2201 2201
 
@@ -2216,7 +2216,7 @@  discard block
 block discarded – undo
2216 2216
  * @return int $a*$b
2217 2217
  **/
2218 2218
 function mult($a, $b) {
2219
-	return $a * $b;
2219
+    return $a * $b;
2220 2220
 }
2221 2221
 function strmult($a, $b) {return strize('mult', $a, $b);}
2222 2222
 
@@ -2237,7 +2237,7 @@  discard block
 block discarded – undo
2237 2237
  * @return int $a/$b (ou 0 si $b est nul)
2238 2238
  **/
2239 2239
 function div($a, $b) {
2240
-	return $b ? $a / $b : 0;
2240
+    return $b ? $a / $b : 0;
2241 2241
 }
2242 2242
 function strdiv($a, $b) {return strize('div', $a, $b);}
2243 2243
 
@@ -2259,7 +2259,7 @@  discard block
 block discarded – undo
2259 2259
  * @return int ($nb % $mod) + $add
2260 2260
  **/
2261 2261
 function modulo($nb, $mod, $add = 0) {
2262
-	return ($mod ? $nb % $mod : 0) + $add;
2262
+    return ($mod ? $nb % $mod : 0) + $add;
2263 2263
 }
2264 2264
 
2265 2265
 
@@ -2274,24 +2274,24 @@  discard block
 block discarded – undo
2274 2274
  *      - true sinon
2275 2275
  **/
2276 2276
 function nom_acceptable($nom) {
2277
-	if (!is_string($nom)) {
2278
-		return false;
2279
-	}
2280
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2281
-		define('_TAGS_NOM_AUTEUR', '');
2282
-	}
2283
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2284
-	foreach ($tags_acceptes as $tag) {
2285
-		if (strlen($tag)) {
2286
-			$remp1[] = '<' . trim($tag) . '>';
2287
-			$remp1[] = '</' . trim($tag) . '>';
2288
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2289
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2290
-		}
2291
-	}
2292
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2277
+    if (!is_string($nom)) {
2278
+        return false;
2279
+    }
2280
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2281
+        define('_TAGS_NOM_AUTEUR', '');
2282
+    }
2283
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2284
+    foreach ($tags_acceptes as $tag) {
2285
+        if (strlen($tag)) {
2286
+            $remp1[] = '<' . trim($tag) . '>';
2287
+            $remp1[] = '</' . trim($tag) . '>';
2288
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2289
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2290
+        }
2291
+    }
2292
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2293 2293
 
2294
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2294
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2295 2295
 }
2296 2296
 
2297 2297
 
@@ -2307,14 +2307,14 @@  discard block
 block discarded – undo
2307 2307
  *      - renvoie un tableau si l'entree est un tableau
2308 2308
  **/
2309 2309
 function email_valide($adresses) {
2310
-	if (is_array($adresses)) {
2311
-		$adresses = array_map('email_valide', $adresses);
2312
-		$adresses = array_filter($adresses);
2313
-		return $adresses;
2314
-	}
2310
+    if (is_array($adresses)) {
2311
+        $adresses = array_map('email_valide', $adresses);
2312
+        $adresses = array_filter($adresses);
2313
+        return $adresses;
2314
+    }
2315 2315
 
2316
-	$email_valide = charger_fonction('email_valide', 'inc');
2317
-	return $email_valide($adresses);
2316
+    $email_valide = charger_fonction('email_valide', 'inc');
2317
+    return $email_valide($adresses);
2318 2318
 }
2319 2319
 
2320 2320
 /**
@@ -2328,20 +2328,20 @@  discard block
 block discarded – undo
2328 2328
  * @return string Texte
2329 2329
  **/
2330 2330
 function afficher_enclosures($tags) {
2331
-	$s = array();
2332
-	foreach (extraire_balises($tags, 'a') as $tag) {
2333
-		if (extraire_attribut($tag, 'rel') == 'enclosure'
2334
-			and $t = extraire_attribut($tag, 'href')
2335
-		) {
2336
-			$s[] = preg_replace(',>[^<]+</a>,S',
2337
-				'>'
2338
-				. http_img_pack('attachment-16.png', $t,
2339
-					'title="' . attribut_html($t) . '"')
2340
-				. '</a>', $tag);
2341
-		}
2342
-	}
2331
+    $s = array();
2332
+    foreach (extraire_balises($tags, 'a') as $tag) {
2333
+        if (extraire_attribut($tag, 'rel') == 'enclosure'
2334
+            and $t = extraire_attribut($tag, 'href')
2335
+        ) {
2336
+            $s[] = preg_replace(',>[^<]+</a>,S',
2337
+                '>'
2338
+                . http_img_pack('attachment-16.png', $t,
2339
+                    'title="' . attribut_html($t) . '"')
2340
+                . '</a>', $tag);
2341
+        }
2342
+    }
2343 2343
 
2344
-	return join('&nbsp;', $s);
2344
+    return join('&nbsp;', $s);
2345 2345
 }
2346 2346
 
2347 2347
 /**
@@ -2356,15 +2356,15 @@  discard block
 block discarded – undo
2356 2356
  * @return string Liens trouvés
2357 2357
  **/
2358 2358
 function afficher_tags($tags, $rels = 'tag,directory') {
2359
-	$s = array();
2360
-	foreach (extraire_balises($tags, 'a') as $tag) {
2361
-		$rel = extraire_attribut($tag, 'rel');
2362
-		if (strstr(",$rels,", ",$rel,")) {
2363
-			$s[] = $tag;
2364
-		}
2365
-	}
2359
+    $s = array();
2360
+    foreach (extraire_balises($tags, 'a') as $tag) {
2361
+        $rel = extraire_attribut($tag, 'rel');
2362
+        if (strstr(",$rels,", ",$rel,")) {
2363
+            $s[] = $tag;
2364
+        }
2365
+    }
2366 2366
 
2367
-	return join(', ', $s);
2367
+    return join(', ', $s);
2368 2368
 }
2369 2369
 
2370 2370
 
@@ -2386,21 +2386,21 @@  discard block
 block discarded – undo
2386 2386
  * @return string Tag HTML `<a>` avec microformat.
2387 2387
  **/
2388 2388
 function enclosure2microformat($e) {
2389
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2390
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2391
-	}
2392
-	$type = extraire_attribut($e, 'type');
2393
-	if (!$length = extraire_attribut($e, 'length')) {
2394
-		# <media:content : longeur dans fileSize. On tente.
2395
-		$length = extraire_attribut($e, 'fileSize');
2396
-	}
2397
-	$fichier = basename($url);
2389
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2390
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2391
+    }
2392
+    $type = extraire_attribut($e, 'type');
2393
+    if (!$length = extraire_attribut($e, 'length')) {
2394
+        # <media:content : longeur dans fileSize. On tente.
2395
+        $length = extraire_attribut($e, 'fileSize');
2396
+    }
2397
+    $fichier = basename($url);
2398 2398
 
2399
-	return '<a rel="enclosure"'
2400
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2401
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2402
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2403
-	. '>' . $fichier . '</a>';
2399
+    return '<a rel="enclosure"'
2400
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2401
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2402
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2403
+    . '>' . $fichier . '</a>';
2404 2404
 }
2405 2405
 
2406 2406
 /**
@@ -2418,24 +2418,24 @@  discard block
 block discarded – undo
2418 2418
  * @return string Tags RSS `<enclosure>`.
2419 2419
  **/
2420 2420
 function microformat2enclosure($tags) {
2421
-	$enclosures = array();
2422
-	foreach (extraire_balises($tags, 'a') as $e) {
2423
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2424
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2425
-			$type = extraire_attribut($e, 'type');
2426
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2427
-				$length = intval(extraire_attribut($e, 'length'));
2428
-			} # vieux data
2429
-			$fichier = basename($url);
2430
-			$enclosures[] = '<enclosure'
2431
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2432
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2433
-				. ($length ? ' length="' . $length . '"' : '')
2434
-				. ' />';
2435
-		}
2436
-	}
2421
+    $enclosures = array();
2422
+    foreach (extraire_balises($tags, 'a') as $e) {
2423
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2424
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2425
+            $type = extraire_attribut($e, 'type');
2426
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2427
+                $length = intval(extraire_attribut($e, 'length'));
2428
+            } # vieux data
2429
+            $fichier = basename($url);
2430
+            $enclosures[] = '<enclosure'
2431
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2432
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2433
+                . ($length ? ' length="' . $length . '"' : '')
2434
+                . ' />';
2435
+        }
2436
+    }
2437 2437
 
2438
-	return join("\n", $enclosures);
2438
+    return join("\n", $enclosures);
2439 2439
 }
2440 2440
 
2441 2441
 
@@ -2451,16 +2451,16 @@  discard block
 block discarded – undo
2451 2451
  * @return string Tags RSS Atom `<dc:subject>`.
2452 2452
  **/
2453 2453
 function tags2dcsubject($tags) {
2454
-	$subjects = '';
2455
-	foreach (extraire_balises($tags, 'a') as $e) {
2456
-		if (extraire_attribut($e, 'rel') == 'tag') {
2457
-			$subjects .= '<dc:subject>'
2458
-				. texte_backend(textebrut($e))
2459
-				. '</dc:subject>' . "\n";
2460
-		}
2461
-	}
2454
+    $subjects = '';
2455
+    foreach (extraire_balises($tags, 'a') as $e) {
2456
+        if (extraire_attribut($e, 'rel') == 'tag') {
2457
+            $subjects .= '<dc:subject>'
2458
+                . texte_backend(textebrut($e))
2459
+                . '</dc:subject>' . "\n";
2460
+        }
2461
+    }
2462 2462
 
2463
-	return $subjects;
2463
+    return $subjects;
2464 2464
 }
2465 2465
 
2466 2466
 /**
@@ -2489,23 +2489,23 @@  discard block
 block discarded – undo
2489 2489
  *     - Tableau de résultats, si tableau en entrée.
2490 2490
  **/
2491 2491
 function extraire_balise($texte, $tag = 'a') {
2492
-	if (is_array($texte)) {
2493
-		array_walk(
2494
-			$texte,
2495
-			function(&$a, $key, $t){
2496
-				$a = extraire_balise($a, $t);
2497
-			},
2498
-			$tag
2499
-		);
2492
+    if (is_array($texte)) {
2493
+        array_walk(
2494
+            $texte,
2495
+            function(&$a, $key, $t){
2496
+                $a = extraire_balise($a, $t);
2497
+            },
2498
+            $tag
2499
+        );
2500 2500
 
2501
-		return $texte;
2502
-	}
2501
+        return $texte;
2502
+    }
2503 2503
 
2504
-	if (preg_match(
2505
-		",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2506
-		$texte, $regs)) {
2507
-		return $regs[0];
2508
-	}
2504
+    if (preg_match(
2505
+        ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2506
+        $texte, $regs)) {
2507
+        return $regs[0];
2508
+    }
2509 2509
 }
2510 2510
 
2511 2511
 /**
@@ -2533,25 +2533,25 @@  discard block
 block discarded – undo
2533 2533
  *     - Tableau de résultats, si tableau en entrée.
2534 2534
  **/
2535 2535
 function extraire_balises($texte, $tag = 'a') {
2536
-	if (is_array($texte)) {
2537
-		array_walk(
2538
-			$texte,
2539
-			function(&$a, $key, $t){
2540
-				$a = extraire_balises($a, $t);
2541
-			},
2542
-			$tag
2543
-		);
2536
+    if (is_array($texte)) {
2537
+        array_walk(
2538
+            $texte,
2539
+            function(&$a, $key, $t){
2540
+                $a = extraire_balises($a, $t);
2541
+            },
2542
+            $tag
2543
+        );
2544 2544
 
2545
-		return $texte;
2546
-	}
2545
+        return $texte;
2546
+    }
2547 2547
 
2548
-	if (preg_match_all(
2549
-		",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2550
-		$texte, $regs, PREG_PATTERN_ORDER)) {
2551
-		return $regs[0];
2552
-	} else {
2553
-		return array();
2554
-	}
2548
+    if (preg_match_all(
2549
+        ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2550
+        $texte, $regs, PREG_PATTERN_ORDER)) {
2551
+        return $regs[0];
2552
+    } else {
2553
+        return array();
2554
+    }
2555 2555
 }
2556 2556
 
2557 2557
 /**
@@ -2580,11 +2580,11 @@  discard block
 block discarded – undo
2580 2580
  *     - `$def` si on n'a pas transmis de tableau
2581 2581
  **/
2582 2582
 function in_any($val, $vals, $def = '') {
2583
-	if (!is_array($vals) and $v = unserialize($vals)) {
2584
-		$vals = $v;
2585
-	}
2583
+    if (!is_array($vals) and $v = unserialize($vals)) {
2584
+        $vals = $v;
2585
+    }
2586 2586
 
2587
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2587
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2588 2588
 }
2589 2589
 
2590 2590
 
@@ -2605,12 +2605,12 @@  discard block
 block discarded – undo
2605 2605
  *     Résultat du calcul
2606 2606
  **/
2607 2607
 function valeur_numerique($expr) {
2608
-	$a = 0;
2609
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2610
-		eval("\$a = $expr;");
2611
-	}
2608
+    $a = 0;
2609
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2610
+        eval("\$a = $expr;");
2611
+    }
2612 2612
 
2613
-	return intval($a);
2613
+    return intval($a);
2614 2614
 }
2615 2615
 
2616 2616
 /**
@@ -2629,7 +2629,7 @@  discard block
 block discarded – undo
2629 2629
  *      Retourne `$a*$b/$c`
2630 2630
  **/
2631 2631
 function regledetrois($a, $b, $c) {
2632
-	return round($a * $b / $c);
2632
+    return round($a * $b / $c);
2633 2633
 }
2634 2634
 
2635 2635
 
@@ -2653,76 +2653,76 @@  discard block
 block discarded – undo
2653 2653
  **/
2654 2654
 function form_hidden($action) {
2655 2655
 
2656
-	$contexte = array();
2657
-	include_spip('inc/urls');
2658
-	if ($p = urls_decoder_url($action, '')
2659
-		and reset($p)
2660
-	) {
2661
-		$fond = array_shift($p);
2662
-		if ($fond != '404') {
2663
-			$contexte = array_shift($p);
2664
-			$contexte['page'] = $fond;
2665
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2666
-		}
2667
-	}
2668
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2669
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2670
-		unset($contexte['type']);
2671
-	}
2672
-	if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) {
2673
-		unset($contexte['type-page']);
2674
-	}
2675
-
2676
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2677
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2678
-	$values = array();
2679
-
2680
-	// d'abord avec celles de l'url
2681
-	if (false !== ($p = strpos($action, '?'))) {
2682
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2683
-			$c = explode('=', $c, 2);
2684
-			$var = array_shift($c);
2685
-			$val = array_shift($c);
2686
-			if ($var) {
2687
-				$val = rawurldecode($val);
2688
-				$var = rawurldecode($var); // decoder les [] eventuels
2689
-				if (preg_match(',\[\]$,S', $var)) {
2690
-					$values[] = array($var, $val);
2691
-				} else {
2692
-					if (!isset($values[$var])) {
2693
-						$values[$var] = array($var, $val);
2694
-					}
2695
-				}
2696
-			}
2697
-		}
2698
-	}
2699
-
2700
-	// ensuite avec celles du contexte, sans doublonner !
2701
-	foreach ($contexte as $var => $val) {
2702
-		if (preg_match(',\[\]$,S', $var)) {
2703
-			$values[] = array($var, $val);
2704
-		} else {
2705
-			if (!isset($values[$var])) {
2706
-				$values[$var] = array($var, $val);
2707
-			}
2708
-		}
2709
-	}
2710
-
2711
-	// puis on rassemble le tout
2712
-	$hidden = array();
2713
-	foreach ($values as $value) {
2714
-		list($var, $val) = $value;
2715
-		$hidden[] = '<input name="'
2716
-			. entites_html($var)
2717
-			. '"'
2718
-			. (is_null($val)
2719
-				? ''
2720
-				: ' value="' . entites_html($val) . '"'
2721
-			)
2722
-			. ' type="hidden"' . "\n/>";
2723
-	}
2724
-
2725
-	return join("", $hidden);
2656
+    $contexte = array();
2657
+    include_spip('inc/urls');
2658
+    if ($p = urls_decoder_url($action, '')
2659
+        and reset($p)
2660
+    ) {
2661
+        $fond = array_shift($p);
2662
+        if ($fond != '404') {
2663
+            $contexte = array_shift($p);
2664
+            $contexte['page'] = $fond;
2665
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2666
+        }
2667
+    }
2668
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2669
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2670
+        unset($contexte['type']);
2671
+    }
2672
+    if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) {
2673
+        unset($contexte['type-page']);
2674
+    }
2675
+
2676
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2677
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2678
+    $values = array();
2679
+
2680
+    // d'abord avec celles de l'url
2681
+    if (false !== ($p = strpos($action, '?'))) {
2682
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2683
+            $c = explode('=', $c, 2);
2684
+            $var = array_shift($c);
2685
+            $val = array_shift($c);
2686
+            if ($var) {
2687
+                $val = rawurldecode($val);
2688
+                $var = rawurldecode($var); // decoder les [] eventuels
2689
+                if (preg_match(',\[\]$,S', $var)) {
2690
+                    $values[] = array($var, $val);
2691
+                } else {
2692
+                    if (!isset($values[$var])) {
2693
+                        $values[$var] = array($var, $val);
2694
+                    }
2695
+                }
2696
+            }
2697
+        }
2698
+    }
2699
+
2700
+    // ensuite avec celles du contexte, sans doublonner !
2701
+    foreach ($contexte as $var => $val) {
2702
+        if (preg_match(',\[\]$,S', $var)) {
2703
+            $values[] = array($var, $val);
2704
+        } else {
2705
+            if (!isset($values[$var])) {
2706
+                $values[$var] = array($var, $val);
2707
+            }
2708
+        }
2709
+    }
2710
+
2711
+    // puis on rassemble le tout
2712
+    $hidden = array();
2713
+    foreach ($values as $value) {
2714
+        list($var, $val) = $value;
2715
+        $hidden[] = '<input name="'
2716
+            . entites_html($var)
2717
+            . '"'
2718
+            . (is_null($val)
2719
+                ? ''
2720
+                : ' value="' . entites_html($val) . '"'
2721
+            )
2722
+            . ' type="hidden"' . "\n/>";
2723
+    }
2724
+
2725
+    return join("", $hidden);
2726 2726
 }
2727 2727
 
2728 2728
 
@@ -2744,7 +2744,7 @@  discard block
 block discarded – undo
2744 2744
  *    - la première valeur du tableau sinon.
2745 2745
  **/
2746 2746
 function filtre_reset($array) {
2747
-	return !is_array($array) ? null : reset($array);
2747
+    return !is_array($array) ? null : reset($array);
2748 2748
 }
2749 2749
 
2750 2750
 /**
@@ -2765,7 +2765,7 @@  discard block
 block discarded – undo
2765 2765
  *    - la dernière valeur du tableau sinon.
2766 2766
  **/
2767 2767
 function filtre_end($array) {
2768
-	return !is_array($array) ? null : end($array);
2768
+    return !is_array($array) ? null : end($array);
2769 2769
 }
2770 2770
 
2771 2771
 /**
@@ -2785,11 +2785,11 @@  discard block
 block discarded – undo
2785 2785
  *
2786 2786
  **/
2787 2787
 function filtre_push($array, $val) {
2788
-	if (!is_array($array) or !array_push($array, $val)) {
2789
-		return '';
2790
-	}
2788
+    if (!is_array($array) or !array_push($array, $val)) {
2789
+        return '';
2790
+    }
2791 2791
 
2792
-	return $array;
2792
+    return $array;
2793 2793
 }
2794 2794
 
2795 2795
 /**
@@ -2808,7 +2808,7 @@  discard block
 block discarded – undo
2808 2808
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2809 2809
  **/
2810 2810
 function filtre_find($array, $val) {
2811
-	return (is_array($array) and in_array($val, $array));
2811
+    return (is_array($array) and in_array($val, $array));
2812 2812
 }
2813 2813
 
2814 2814
 
@@ -2825,15 +2825,15 @@  discard block
 block discarded – undo
2825 2825
  *     Contenu avec urls en absolus
2826 2826
  **/
2827 2827
 function urls_absolues_css($contenu, $source) {
2828
-	$path = suivre_lien(url_absolue($source), './');
2828
+    $path = suivre_lien(url_absolue($source), './');
2829 2829
 
2830
-	return preg_replace_callback(
2831
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2832
-		function($x) use ($path) {
2833
-			return "url('" . suivre_lien($path, $x[1]) . "')";
2834
-		},
2835
-		$contenu
2836
-	);
2830
+    return preg_replace_callback(
2831
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2832
+        function($x) use ($path) {
2833
+            return "url('" . suivre_lien($path, $x[1]) . "')";
2834
+        },
2835
+        $contenu
2836
+    );
2837 2837
 }
2838 2838
 
2839 2839
 
@@ -2862,118 +2862,118 @@  discard block
 block discarded – undo
2862 2862
  *     Chemin du fichier CSS inversé
2863 2863
  **/
2864 2864
 function direction_css($css, $voulue = '') {
2865
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2866
-		return $css;
2867
-	}
2868
-	include_spip("inc/lang");
2869
-	// si on a precise le sens voulu en argument, le prendre en compte
2870
-	if ($voulue = strtolower($voulue)) {
2871
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2872
-			$voulue = lang_dir($voulue);
2873
-		}
2874
-	} else {
2875
-		$voulue = lang_dir();
2876
-	}
2877
-
2878
-	$r = count($r) > 1;
2879
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2880
-	$dir = $r ? 'rtl' : 'ltr';
2881
-	$ndir = $r ? 'ltr' : 'rtl';
2882
-
2883
-	if ($voulue == $dir) {
2884
-		return $css;
2885
-	}
2886
-
2887
-	if (
2888
-		// url absolue
2889
-		preg_match(",^https?:,i", $css)
2890
-		// ou qui contient un ?
2891
-		or (($p = strpos($css, '?')) !== false)
2892
-	) {
2893
-		$distant = true;
2894
-		$cssf = parse_url($css);
2895
-		$cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2896
-		$cssf = preg_replace(',[?:&=],', "_", $cssf);
2897
-	} else {
2898
-		$distant = false;
2899
-		$cssf = $css;
2900
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2901
-		//propose (rien a faire dans ce cas)
2902
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2903
-		if (@file_exists($f)) {
2904
-			return $f;
2905
-		}
2906
-	}
2907
-
2908
-	// 2.
2909
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2910
-	$f = $dir_var
2911
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2912
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2913
-
2914
-	// la css peut etre distante (url absolue !)
2915
-	if ($distant) {
2916
-		include_spip('inc/distant');
2917
-		$res = recuperer_url($css);
2918
-		if (!$res or !$contenu = $res['page']) {
2919
-			return $css;
2920
-		}
2921
-	} else {
2922
-		if ((@filemtime($f) > @filemtime($css))
2923
-			and (_VAR_MODE != 'recalcul')
2924
-		) {
2925
-			return $f;
2926
-		}
2927
-		if (!lire_fichier($css, $contenu)) {
2928
-			return $css;
2929
-		}
2930
-	}
2931
-
2932
-
2933
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2934
-	include_spip("lib/csstidy/class.csstidy");
2935
-	$parser = new csstidy();
2936
-	$parser->set_cfg('optimise_shorthands', 0);
2937
-	$parser->set_cfg('reverse_left_and_right', true);
2938
-	$parser->parse($contenu);
2939
-
2940
-	$contenu = $parser->print->plain();
2941
-
2942
-
2943
-	// reperer les @import auxquels il faut propager le direction_css
2944
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2945
-	$src = array();
2946
-	$src_direction_css = array();
2947
-	$src_faux_abs = array();
2948
-	$d = dirname($css);
2949
-	foreach ($regs[1] as $k => $import_css) {
2950
-		$css_direction = direction_css("$d/$import_css", $voulue);
2951
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2952
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2953
-			$css_direction = substr($css_direction, strlen($d) + 1);
2954
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2955
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2956
-			$css_direction = substr($css_direction, strlen($dir_var));
2957
-			$src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2958
-			$css_direction = "/@@@@@@/" . $css_direction;
2959
-		}
2960
-		$src[] = $regs[0][$k];
2961
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2962
-	}
2963
-	$contenu = str_replace($src, $src_direction_css, $contenu);
2964
-
2965
-	$contenu = urls_absolues_css($contenu, $css);
2966
-
2967
-	// virer les fausses url absolues que l'on a mis dans les import
2968
-	if (count($src_faux_abs)) {
2969
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2970
-	}
2971
-
2972
-	if (!ecrire_fichier($f, $contenu)) {
2973
-		return $css;
2974
-	}
2975
-
2976
-	return $f;
2865
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2866
+        return $css;
2867
+    }
2868
+    include_spip("inc/lang");
2869
+    // si on a precise le sens voulu en argument, le prendre en compte
2870
+    if ($voulue = strtolower($voulue)) {
2871
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2872
+            $voulue = lang_dir($voulue);
2873
+        }
2874
+    } else {
2875
+        $voulue = lang_dir();
2876
+    }
2877
+
2878
+    $r = count($r) > 1;
2879
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2880
+    $dir = $r ? 'rtl' : 'ltr';
2881
+    $ndir = $r ? 'ltr' : 'rtl';
2882
+
2883
+    if ($voulue == $dir) {
2884
+        return $css;
2885
+    }
2886
+
2887
+    if (
2888
+        // url absolue
2889
+        preg_match(",^https?:,i", $css)
2890
+        // ou qui contient un ?
2891
+        or (($p = strpos($css, '?')) !== false)
2892
+    ) {
2893
+        $distant = true;
2894
+        $cssf = parse_url($css);
2895
+        $cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2896
+        $cssf = preg_replace(',[?:&=],', "_", $cssf);
2897
+    } else {
2898
+        $distant = false;
2899
+        $cssf = $css;
2900
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2901
+        //propose (rien a faire dans ce cas)
2902
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2903
+        if (@file_exists($f)) {
2904
+            return $f;
2905
+        }
2906
+    }
2907
+
2908
+    // 2.
2909
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2910
+    $f = $dir_var
2911
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2912
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2913
+
2914
+    // la css peut etre distante (url absolue !)
2915
+    if ($distant) {
2916
+        include_spip('inc/distant');
2917
+        $res = recuperer_url($css);
2918
+        if (!$res or !$contenu = $res['page']) {
2919
+            return $css;
2920
+        }
2921
+    } else {
2922
+        if ((@filemtime($f) > @filemtime($css))
2923
+            and (_VAR_MODE != 'recalcul')
2924
+        ) {
2925
+            return $f;
2926
+        }
2927
+        if (!lire_fichier($css, $contenu)) {
2928
+            return $css;
2929
+        }
2930
+    }
2931
+
2932
+
2933
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2934
+    include_spip("lib/csstidy/class.csstidy");
2935
+    $parser = new csstidy();
2936
+    $parser->set_cfg('optimise_shorthands', 0);
2937
+    $parser->set_cfg('reverse_left_and_right', true);
2938
+    $parser->parse($contenu);
2939
+
2940
+    $contenu = $parser->print->plain();
2941
+
2942
+
2943
+    // reperer les @import auxquels il faut propager le direction_css
2944
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2945
+    $src = array();
2946
+    $src_direction_css = array();
2947
+    $src_faux_abs = array();
2948
+    $d = dirname($css);
2949
+    foreach ($regs[1] as $k => $import_css) {
2950
+        $css_direction = direction_css("$d/$import_css", $voulue);
2951
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2952
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2953
+            $css_direction = substr($css_direction, strlen($d) + 1);
2954
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
2955
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2956
+            $css_direction = substr($css_direction, strlen($dir_var));
2957
+            $src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2958
+            $css_direction = "/@@@@@@/" . $css_direction;
2959
+        }
2960
+        $src[] = $regs[0][$k];
2961
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2962
+    }
2963
+    $contenu = str_replace($src, $src_direction_css, $contenu);
2964
+
2965
+    $contenu = urls_absolues_css($contenu, $css);
2966
+
2967
+    // virer les fausses url absolues que l'on a mis dans les import
2968
+    if (count($src_faux_abs)) {
2969
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2970
+    }
2971
+
2972
+    if (!ecrire_fichier($f, $contenu)) {
2973
+        return $css;
2974
+    }
2975
+
2976
+    return $f;
2977 2977
 }
2978 2978
 
2979 2979
 
@@ -2996,45 +2996,45 @@  discard block
 block discarded – undo
2996 2996
  *     - Chemin ou URL du fichier CSS source sinon.
2997 2997
  **/
2998 2998
 function url_absolue_css($css) {
2999
-	if (!preg_match(',\.css$,i', $css, $r)) {
3000
-		return $css;
3001
-	}
2999
+    if (!preg_match(',\.css$,i', $css, $r)) {
3000
+        return $css;
3001
+    }
3002 3002
 
3003
-	$url_absolue_css = url_absolue($css);
3003
+    $url_absolue_css = url_absolue($css);
3004 3004
 
3005
-	$f = basename($css, '.css');
3006
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3007
-		. preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3008
-		. '.css';
3005
+    $f = basename($css, '.css');
3006
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3007
+        . preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3008
+        . '.css';
3009 3009
 
3010
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3011
-		return $f;
3012
-	}
3010
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3011
+        return $f;
3012
+    }
3013 3013
 
3014
-	if ($url_absolue_css == $css) {
3015
-		if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3016
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3017
-		) {
3018
-			include_spip('inc/distant');
3019
-			$contenu = recuperer_url($css);
3020
-			$contenu = $contenu['page'] ?? '';
3021
-			if (!$contenu) {
3022
-				return $css;
3023
-			}
3024
-		}
3025
-	} elseif (!lire_fichier($css, $contenu)) {
3026
-		return $css;
3027
-	}
3014
+    if ($url_absolue_css == $css) {
3015
+        if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3016
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3017
+        ) {
3018
+            include_spip('inc/distant');
3019
+            $contenu = recuperer_url($css);
3020
+            $contenu = $contenu['page'] ?? '';
3021
+            if (!$contenu) {
3022
+                return $css;
3023
+            }
3024
+        }
3025
+    } elseif (!lire_fichier($css, $contenu)) {
3026
+        return $css;
3027
+    }
3028 3028
 
3029
-	// passer les url relatives a la css d'origine en url absolues
3030
-	$contenu = urls_absolues_css($contenu, $css);
3029
+    // passer les url relatives a la css d'origine en url absolues
3030
+    $contenu = urls_absolues_css($contenu, $css);
3031 3031
 
3032
-	// ecrire la css
3033
-	if (!ecrire_fichier($f, $contenu)) {
3034
-		return $css;
3035
-	}
3032
+    // ecrire la css
3033
+    if (!ecrire_fichier($f, $contenu)) {
3034
+        return $css;
3035
+    }
3036 3036
 
3037
-	return $f;
3037
+    return $f;
3038 3038
 }
3039 3039
 
3040 3040
 
@@ -3068,24 +3068,24 @@  discard block
 block discarded – undo
3068 3068
  *     Valeur trouvée ou valeur par défaut.
3069 3069
  **/
3070 3070
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3071
-	foreach (explode('/', $cle) as $k) {
3071
+    foreach (explode('/', $cle) as $k) {
3072 3072
 
3073
-		$table = is_string($table) ? @unserialize($table) : $table;
3073
+        $table = is_string($table) ? @unserialize($table) : $table;
3074 3074
 
3075
-		if (is_object($table)) {
3076
-			$table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
3077
-		} elseif (is_array($table)) {
3078
-			if ($conserver_null) {
3079
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3080
-			} else {
3081
-				$table = isset($table[$k]) ? $table[$k] : $defaut;
3082
-			}
3083
-		} else {
3084
-			$table = $defaut;
3085
-		}
3086
-	}
3075
+        if (is_object($table)) {
3076
+            $table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut;
3077
+        } elseif (is_array($table)) {
3078
+            if ($conserver_null) {
3079
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3080
+            } else {
3081
+                $table = isset($table[$k]) ? $table[$k] : $defaut;
3082
+            }
3083
+        } else {
3084
+            $table = $defaut;
3085
+        }
3086
+    }
3087 3087
 
3088
-	return $table;
3088
+    return $table;
3089 3089
 }
3090 3090
 
3091 3091
 /**
@@ -3118,22 +3118,22 @@  discard block
 block discarded – undo
3118 3118
  *     - string : expression trouvée.
3119 3119
  **/
3120 3120
 function filtre_match_dist($texte, $expression, $modif = "UimsS", $capte = 0) {
3121
-	if (intval($modif) and $capte == 0) {
3122
-		$capte = $modif;
3123
-		$modif = "UimsS";
3124
-	}
3125
-	$expression = str_replace("\/", "/", $expression);
3126
-	$expression = str_replace("/", "\/", $expression);
3121
+    if (intval($modif) and $capte == 0) {
3122
+        $capte = $modif;
3123
+        $modif = "UimsS";
3124
+    }
3125
+    $expression = str_replace("\/", "/", $expression);
3126
+    $expression = str_replace("/", "\/", $expression);
3127 3127
 
3128
-	if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3129
-		if (isset($r[$capte])) {
3130
-			return $r[$capte];
3131
-		} else {
3132
-			return true;
3133
-		}
3134
-	}
3128
+    if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3129
+        if (isset($r[$capte])) {
3130
+            return $r[$capte];
3131
+        } else {
3132
+            return true;
3133
+        }
3134
+    }
3135 3135
 
3136
-	return false;
3136
+    return false;
3137 3137
 }
3138 3138
 
3139 3139
 
@@ -3160,10 +3160,10 @@  discard block
 block discarded – undo
3160 3160
  *     Texte
3161 3161
  **/
3162 3162
 function replace($texte, $expression, $replace = '', $modif = "UimsS") {
3163
-	$expression = str_replace("\/", "/", $expression);
3164
-	$expression = str_replace("/", "\/", $expression);
3163
+    $expression = str_replace("\/", "/", $expression);
3164
+    $expression = str_replace("/", "\/", $expression);
3165 3165
 
3166
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3166
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3167 3167
 }
3168 3168
 
3169 3169
 
@@ -3181,21 +3181,21 @@  discard block
 block discarded – undo
3181 3181
  **/
3182 3182
 function traiter_doublons_documents(&$doublons, $letexte) {
3183 3183
 
3184
-	// Verifier dans le texte & les notes (pas beau, helas)
3185
-	$t = $letexte . $GLOBALS['les_notes'];
3184
+    // Verifier dans le texte & les notes (pas beau, helas)
3185
+    $t = $letexte . $GLOBALS['les_notes'];
3186 3186
 
3187
-	if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3188
-		and preg_match_all(
3189
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3190
-			$t, $matches, PREG_PATTERN_ORDER)
3191
-	) {
3192
-		if (!isset($doublons['documents'])) {
3193
-			$doublons['documents'] = "";
3194
-		}
3195
-		$doublons['documents'] .= "," . join(',', $matches[1]);
3196
-	}
3187
+    if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3188
+        and preg_match_all(
3189
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3190
+            $t, $matches, PREG_PATTERN_ORDER)
3191
+    ) {
3192
+        if (!isset($doublons['documents'])) {
3193
+            $doublons['documents'] = "";
3194
+        }
3195
+        $doublons['documents'] .= "," . join(',', $matches[1]);
3196
+    }
3197 3197
 
3198
-	return $letexte;
3198
+    return $letexte;
3199 3199
 }
3200 3200
 
3201 3201
 /**
@@ -3209,7 +3209,7 @@  discard block
 block discarded – undo
3209 3209
  * @return string Chaîne vide
3210 3210
  **/
3211 3211
 function vide($texte) {
3212
-	return "";
3212
+    return "";
3213 3213
 }
3214 3214
 
3215 3215
 //
@@ -3238,23 +3238,23 @@  discard block
 block discarded – undo
3238 3238
  *      Code HTML résultant
3239 3239
  **/
3240 3240
 function env_to_params($env, $ignore_params = array()) {
3241
-	$ignore_params = array_merge(
3242
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3243
-		$ignore_params
3244
-	);
3245
-	if (!is_array($env)) {
3246
-		$env = unserialize($env);
3247
-	}
3248
-	$texte = "";
3249
-	if ($env) {
3250
-		foreach ($env as $i => $j) {
3251
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3252
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3253
-			}
3254
-		}
3255
-	}
3256
-
3257
-	return $texte;
3241
+    $ignore_params = array_merge(
3242
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3243
+        $ignore_params
3244
+    );
3245
+    if (!is_array($env)) {
3246
+        $env = unserialize($env);
3247
+    }
3248
+    $texte = "";
3249
+    if ($env) {
3250
+        foreach ($env as $i => $j) {
3251
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3252
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3253
+            }
3254
+        }
3255
+    }
3256
+
3257
+    return $texte;
3258 3258
 }
3259 3259
 
3260 3260
 /**
@@ -3277,23 +3277,23 @@  discard block
 block discarded – undo
3277 3277
  *      Code HTML résultant
3278 3278
  **/
3279 3279
 function env_to_attributs($env, $ignore_params = array()) {
3280
-	$ignore_params = array_merge(
3281
-		array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3282
-		$ignore_params
3283
-	);
3284
-	if (!is_array($env)) {
3285
-		$env = unserialize($env);
3286
-	}
3287
-	$texte = "";
3288
-	if ($env) {
3289
-		foreach ($env as $i => $j) {
3290
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3291
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3292
-			}
3293
-		}
3294
-	}
3280
+    $ignore_params = array_merge(
3281
+        array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'),
3282
+        $ignore_params
3283
+    );
3284
+    if (!is_array($env)) {
3285
+        $env = unserialize($env);
3286
+    }
3287
+    $texte = "";
3288
+    if ($env) {
3289
+        foreach ($env as $i => $j) {
3290
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3291
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3292
+            }
3293
+        }
3294
+    }
3295 3295
 
3296
-	return $texte;
3296
+    return $texte;
3297 3297
 }
3298 3298
 
3299 3299
 
@@ -3311,7 +3311,7 @@  discard block
 block discarded – undo
3311 3311
  * @return string Chaînes concaténés
3312 3312
  **/
3313 3313
 function concat(...$args) : string {
3314
-	return join('', $args);
3314
+    return join('', $args);
3315 3315
 }
3316 3316
 
3317 3317
 
@@ -3331,23 +3331,23 @@  discard block
 block discarded – undo
3331 3331
  *     Contenu du ou des fichiers, concaténé
3332 3332
  **/
3333 3333
 function charge_scripts($files, $script = true) {
3334
-	$flux = "";
3335
-	foreach (is_array($files) ? $files : explode("|", $files) as $file) {
3336
-		if (!is_string($file)) {
3337
-			continue;
3338
-		}
3339
-		if ($script) {
3340
-			$file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
3341
-		}
3342
-		if ($file) {
3343
-			$path = find_in_path($file);
3344
-			if ($path) {
3345
-				$flux .= spip_file_get_contents($path);
3346
-			}
3347
-		}
3348
-	}
3334
+    $flux = "";
3335
+    foreach (is_array($files) ? $files : explode("|", $files) as $file) {
3336
+        if (!is_string($file)) {
3337
+            continue;
3338
+        }
3339
+        if ($script) {
3340
+            $file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : '';
3341
+        }
3342
+        if ($file) {
3343
+            $path = find_in_path($file);
3344
+            if ($path) {
3345
+                $flux .= spip_file_get_contents($path);
3346
+            }
3347
+        }
3348
+    }
3349 3349
 
3350
-	return $flux;
3350
+    return $flux;
3351 3351
 }
3352 3352
 
3353 3353
 
@@ -3369,64 +3369,64 @@  discard block
 block discarded – undo
3369 3369
  */
3370 3370
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = array()) {
3371 3371
 
3372
-	$img_file = $img;
3373
-	if ($p = strpos($img_file, '?')) {
3374
-		$img_file = substr($img_file,0, $p);
3375
-	}
3376
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3377
-		$img_file = chemin_image($img);
3378
-	}
3379
-	else {
3380
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3381
-			// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3382
-			// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3383
-			if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3384
-			  and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3385
-			  and file_exists($variante_svg_generique)) {
3386
-				if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3387
-					$img_file = $variante_svg_size;
3388
-				}
3389
-				else {
3390
-					$img_file = $variante_svg_generique;
3391
-				}
3392
-			}
3393
-		}
3394
-	}
3395
-	if (stripos($atts, 'width') === false) {
3396
-		// utiliser directement l'info de taille presente dans le nom
3397
-		if ((!isset($options['utiliser_suffixe_size'])
3398
-				or $options['utiliser_suffixe_size'] == true
3399
-			  or strpos($img_file, '-xx.svg') !== false)
3400
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3401
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3402
-		) {
3403
-			$largeur = $hauteur = intval($regs[1]);
3404
-		} else {
3405
-			$taille = taille_image($img_file);
3406
-			list($hauteur, $largeur) = $taille;
3407
-			if (!$hauteur or !$largeur) {
3408
-				return "";
3409
-			}
3410
-		}
3411
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3412
-	}
3413
-
3414
-	if (file_exists($img_file)) {
3415
-		$img_file = timestamp($img_file);
3416
-	}
3417
-	if ($alt === false) {
3418
-		$alt = '';
3419
-	}
3420
-	elseif($alt or $alt==='') {
3421
-		$alt = " alt='".attribut_html($alt)."'";
3422
-	}
3423
-	else {
3424
-		$alt = " alt='".attribut_html($title)."'";
3425
-	}
3426
-	return "<img src='$img_file'$alt"
3427
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3428
-	. " " . ltrim($atts)
3429
-	. " />";
3372
+    $img_file = $img;
3373
+    if ($p = strpos($img_file, '?')) {
3374
+        $img_file = substr($img_file,0, $p);
3375
+    }
3376
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3377
+        $img_file = chemin_image($img);
3378
+    }
3379
+    else {
3380
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3381
+            // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3382
+            // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3383
+            if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3384
+              and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3385
+              and file_exists($variante_svg_generique)) {
3386
+                if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3387
+                    $img_file = $variante_svg_size;
3388
+                }
3389
+                else {
3390
+                    $img_file = $variante_svg_generique;
3391
+                }
3392
+            }
3393
+        }
3394
+    }
3395
+    if (stripos($atts, 'width') === false) {
3396
+        // utiliser directement l'info de taille presente dans le nom
3397
+        if ((!isset($options['utiliser_suffixe_size'])
3398
+                or $options['utiliser_suffixe_size'] == true
3399
+              or strpos($img_file, '-xx.svg') !== false)
3400
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3401
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3402
+        ) {
3403
+            $largeur = $hauteur = intval($regs[1]);
3404
+        } else {
3405
+            $taille = taille_image($img_file);
3406
+            list($hauteur, $largeur) = $taille;
3407
+            if (!$hauteur or !$largeur) {
3408
+                return "";
3409
+            }
3410
+        }
3411
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3412
+    }
3413
+
3414
+    if (file_exists($img_file)) {
3415
+        $img_file = timestamp($img_file);
3416
+    }
3417
+    if ($alt === false) {
3418
+        $alt = '';
3419
+    }
3420
+    elseif($alt or $alt==='') {
3421
+        $alt = " alt='".attribut_html($alt)."'";
3422
+    }
3423
+    else {
3424
+        $alt = " alt='".attribut_html($title)."'";
3425
+    }
3426
+    return "<img src='$img_file'$alt"
3427
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3428
+    . " " . ltrim($atts)
3429
+    . " />";
3430 3430
 }
3431 3431
 
3432 3432
 /**
@@ -3438,68 +3438,68 @@  discard block
 block discarded – undo
3438 3438
  * @return string
3439 3439
  */
3440 3440
 function http_style_background($img, $att = '', $size=null) {
3441
-	if ($size and is_numeric($size)){
3442
-		$size = trim($size) . "px";
3443
-	}
3444
-	return " style='background" .
3445
-		($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3446
-		. ($size ? "background-size:{$size};" : '')
3447
-		. "'";
3441
+    if ($size and is_numeric($size)){
3442
+        $size = trim($size) . "px";
3443
+    }
3444
+    return " style='background" .
3445
+        ($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3446
+        . ($size ? "background-size:{$size};" : '')
3447
+        . "'";
3448 3448
 }
3449 3449
 
3450 3450
 
3451 3451
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3452
-	$args = [$alt_or_size, $class_or_size, $size];
3453
-	while (is_null(end($args)) and count($args)) {
3454
-		array_pop($args);
3455
-	}
3456
-	if (!count($args)) {
3457
-		return [null, null, null];
3458
-	}
3459
-	if (count($args) < 3) {
3460
-		$maybe_size = array_pop($args);
3461
-		// @2x
3462
-		// @1.5x
3463
-		// 512
3464
-		// 512x*
3465
-		// 512x300
3466
-		if (!strlen($maybe_size)
3467
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))) {
3468
-			$args[] = $maybe_size;
3469
-			$maybe_size = null;
3470
-		}
3471
-		while (count($args)<2) {
3472
-			$args[] = null; // default alt or class
3473
-		}
3474
-		$args[] = $maybe_size;
3475
-	}
3476
-	return $args;
3452
+    $args = [$alt_or_size, $class_or_size, $size];
3453
+    while (is_null(end($args)) and count($args)) {
3454
+        array_pop($args);
3455
+    }
3456
+    if (!count($args)) {
3457
+        return [null, null, null];
3458
+    }
3459
+    if (count($args) < 3) {
3460
+        $maybe_size = array_pop($args);
3461
+        // @2x
3462
+        // @1.5x
3463
+        // 512
3464
+        // 512x*
3465
+        // 512x300
3466
+        if (!strlen($maybe_size)
3467
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))) {
3468
+            $args[] = $maybe_size;
3469
+            $maybe_size = null;
3470
+        }
3471
+        while (count($args)<2) {
3472
+            $args[] = null; // default alt or class
3473
+        }
3474
+        $args[] = $maybe_size;
3475
+    }
3476
+    return $args;
3477 3477
 }
3478 3478
 
3479 3479
 function helper_filtre_balise_img_svg_size($img, $size) {
3480
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3481
-	if (strpos($size, '@') === 0 and substr($size,-1) === 'x') {
3482
-		$coef = floatval(substr($size, 1, -1));
3483
-		list($h, $w) = taille_image($img);
3484
-		$height = intval(round($h / $coef));
3485
-		$width = intval(round($w / $coef));
3486
-	}
3487
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3488
-	else {
3489
-		$size = explode('x', $size, 2);
3490
-		$size = array_map('trim', $size);
3491
-		$height = $width = intval(array_shift($size));
3492
-
3493
-		if (count($size) and reset($size)) {
3494
-			$height = array_shift($size);
3495
-			if ($height === '*') {
3496
-				list($h, $w) = taille_image($img);
3497
-				$height = intval(round($h * $width / $w));
3498
-			}
3499
-		}
3500
-	}
3501
-
3502
-	return [$width, $height];
3480
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3481
+    if (strpos($size, '@') === 0 and substr($size,-1) === 'x') {
3482
+        $coef = floatval(substr($size, 1, -1));
3483
+        list($h, $w) = taille_image($img);
3484
+        $height = intval(round($h / $coef));
3485
+        $width = intval(round($w / $coef));
3486
+    }
3487
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3488
+    else {
3489
+        $size = explode('x', $size, 2);
3490
+        $size = array_map('trim', $size);
3491
+        $height = $width = intval(array_shift($size));
3492
+
3493
+        if (count($size) and reset($size)) {
3494
+            $height = array_shift($size);
3495
+            if ($height === '*') {
3496
+                list($h, $w) = taille_image($img);
3497
+                $height = intval(round($h * $width / $w));
3498
+            }
3499
+        }
3500
+    }
3501
+
3502
+    return [$width, $height];
3503 3503
 }
3504 3504
 
3505 3505
 /**
@@ -3535,38 +3535,38 @@  discard block
 block discarded – undo
3535 3535
  */
3536 3536
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size=null) {
3537 3537
 
3538
-	list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3538
+    list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3539 3539
 
3540
-	$img = trim($img);
3541
-	if (strpos($img, '<img') === 0) {
3542
-		if (!is_null($alt)) {
3543
-			$img = inserer_attribut($img, 'alt', $alt);
3544
-		}
3545
-		if (!is_null($class)) {
3546
-			if (strlen($class)) {
3547
-				$img = inserer_attribut($img, 'class', $class);
3548
-			}
3549
-			else {
3550
-				$img = vider_attribut($img, 'class');
3551
-			}
3552
-		}
3553
-	}
3554
-	else {
3555
-		$img = http_img_pack($img, $alt, $class ? " class='" . attribut_html($class) . "'" : '', '',
3556
-				array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3557
-		if (is_null($alt)) {
3558
-			$img = vider_attribut($img, 'alt');
3559
-		}
3560
-	}
3540
+    $img = trim($img);
3541
+    if (strpos($img, '<img') === 0) {
3542
+        if (!is_null($alt)) {
3543
+            $img = inserer_attribut($img, 'alt', $alt);
3544
+        }
3545
+        if (!is_null($class)) {
3546
+            if (strlen($class)) {
3547
+                $img = inserer_attribut($img, 'class', $class);
3548
+            }
3549
+            else {
3550
+                $img = vider_attribut($img, 'class');
3551
+            }
3552
+        }
3553
+    }
3554
+    else {
3555
+        $img = http_img_pack($img, $alt, $class ? " class='" . attribut_html($class) . "'" : '', '',
3556
+                array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3557
+        if (is_null($alt)) {
3558
+            $img = vider_attribut($img, 'alt');
3559
+        }
3560
+    }
3561 3561
 
3562
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3563
-		list($width, $height) = helper_filtre_balise_img_svg_size($img, $size);
3562
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3563
+        list($width, $height) = helper_filtre_balise_img_svg_size($img, $size);
3564 3564
 
3565
-		$img = inserer_attribut($img, 'width', $width);
3566
-		$img = inserer_attribut($img, 'height', $height);
3567
-	}
3565
+        $img = inserer_attribut($img, 'width', $width);
3566
+        $img = inserer_attribut($img, 'height', $height);
3567
+    }
3568 3568
 
3569
-	return $img;
3569
+    return $img;
3570 3570
 }
3571 3571
 
3572 3572
 
@@ -3600,67 +3600,67 @@  discard block
 block discarded – undo
3600 3600
  */
3601 3601
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size=null) {
3602 3602
 
3603
-	$img = trim($img);
3604
-	$img_file = $img;
3605
-	if (strpos($img, '<svg') === false){
3606
-		if ($p = strpos($img_file, '?')){
3607
-			$img_file = substr($img_file, 0, $p);
3608
-		}
3603
+    $img = trim($img);
3604
+    $img_file = $img;
3605
+    if (strpos($img, '<svg') === false){
3606
+        if ($p = strpos($img_file, '?')){
3607
+            $img_file = substr($img_file, 0, $p);
3608
+        }
3609 3609
 
3610
-		if (!$img_file or !$svg = file_get_contents($img_file)){
3611
-			return '';
3612
-		}
3613
-	}
3610
+        if (!$img_file or !$svg = file_get_contents($img_file)){
3611
+            return '';
3612
+        }
3613
+    }
3614 3614
 
3615
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3616
-		return '';
3617
-	}
3615
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3616
+        return '';
3617
+    }
3618 3618
 
3619
-	list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3619
+    list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3620 3620
 
3621
-	$balise_svg = $match[0];
3622
-	$balise_svg_source = $balise_svg;
3621
+    $balise_svg = $match[0];
3622
+    $balise_svg_source = $balise_svg;
3623 3623
 
3624
-	// entete XML à supprimer
3625
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3624
+    // entete XML à supprimer
3625
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3626 3626
 
3627
-	// IE est toujours mon ami
3628
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3627
+    // IE est toujours mon ami
3628
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3629 3629
 
3630
-	// regler la classe
3631
-	if (!is_null($class)) {
3632
-		if (strlen($class)) {
3633
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3634
-		}
3635
-		else {
3636
-			$balise_svg = vider_attribut($balise_svg, 'class');
3637
-		}
3638
-	}
3630
+    // regler la classe
3631
+    if (!is_null($class)) {
3632
+        if (strlen($class)) {
3633
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3634
+        }
3635
+        else {
3636
+            $balise_svg = vider_attribut($balise_svg, 'class');
3637
+        }
3638
+    }
3639 3639
 
3640
-	// regler le alt
3641
-	if ($alt){
3642
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3643
-		$id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3644
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3645
-		$title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3646
-		$balise_svg .= $title;
3647
-	}
3648
-	else {
3649
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3650
-	}
3640
+    // regler le alt
3641
+    if ($alt){
3642
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3643
+        $id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3644
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3645
+        $title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3646
+        $balise_svg .= $title;
3647
+    }
3648
+    else {
3649
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3650
+    }
3651 3651
 
3652
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3652
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3653 3653
 
3654
-	if (!is_null($size) and strlen($size = trim($size))) {
3655
-		list($width, $height) = helper_filtre_balise_img_svg_size($svg, $size);
3654
+    if (!is_null($size) and strlen($size = trim($size))) {
3655
+        list($width, $height) = helper_filtre_balise_img_svg_size($svg, $size);
3656 3656
 
3657
-		if (!function_exists('svg_redimensionner')) {
3658
-			include_spip('inc/svg');
3659
-		}
3660
-		$svg = svg_redimensionner($svg, $width, $height);
3661
-	}
3657
+        if (!function_exists('svg_redimensionner')) {
3658
+            include_spip('inc/svg');
3659
+        }
3660
+        $svg = svg_redimensionner($svg, $width, $height);
3661
+    }
3662 3662
 
3663
-	return $svg;
3663
+    return $svg;
3664 3664
 }
3665 3665
 
3666 3666
 
@@ -3686,17 +3686,17 @@  discard block
 block discarded – undo
3686 3686
  *     Code HTML résultant
3687 3687
  **/
3688 3688
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3689
-	$texte = '';
3690
-	if (is_array($tableau)) {
3691
-		foreach ($tableau as $k => $v) {
3692
-			$res = recuperer_fond('modeles/' . $modele,
3693
-				array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3694
-			);
3695
-			$texte .= $res;
3696
-		}
3697
-	}
3689
+    $texte = '';
3690
+    if (is_array($tableau)) {
3691
+        foreach ($tableau as $k => $v) {
3692
+            $res = recuperer_fond('modeles/' . $modele,
3693
+                array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3694
+            );
3695
+            $texte .= $res;
3696
+        }
3697
+    }
3698 3698
 
3699
-	return $texte;
3699
+    return $texte;
3700 3700
 }
3701 3701
 
3702 3702
 
@@ -3721,37 +3721,37 @@  discard block
 block discarded – undo
3721 3721
  *         - tout : retourne toutes les informations du plugin actif
3722 3722
  **/
3723 3723
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3724
-	include_spip('inc/plugin');
3725
-	$plugin = strtoupper($plugin);
3726
-	$plugins_actifs = liste_plugin_actifs();
3727
-
3728
-	if (!$plugin) {
3729
-		return serialize(array_keys($plugins_actifs));
3730
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3731
-		return '';
3732
-	} elseif (($type_info == 'est_actif') and !$reload) {
3733
-		return $plugins_actifs[$plugin] ? 1 : 0;
3734
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3735
-		return $plugins_actifs[$plugin][$type_info];
3736
-	} else {
3737
-		$get_infos = charger_fonction('get_infos', 'plugins');
3738
-		// On prend en compte les extensions
3739
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3740
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3741
-		} else {
3742
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3743
-		}
3744
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3745
-			return '';
3746
-		}
3747
-		if ($type_info == 'tout') {
3748
-			return $infos;
3749
-		} elseif ($type_info == 'est_actif') {
3750
-			return $infos ? 1 : 0;
3751
-		} else {
3752
-			return strval($infos[$type_info]);
3753
-		}
3754
-	}
3724
+    include_spip('inc/plugin');
3725
+    $plugin = strtoupper($plugin);
3726
+    $plugins_actifs = liste_plugin_actifs();
3727
+
3728
+    if (!$plugin) {
3729
+        return serialize(array_keys($plugins_actifs));
3730
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3731
+        return '';
3732
+    } elseif (($type_info == 'est_actif') and !$reload) {
3733
+        return $plugins_actifs[$plugin] ? 1 : 0;
3734
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3735
+        return $plugins_actifs[$plugin][$type_info];
3736
+    } else {
3737
+        $get_infos = charger_fonction('get_infos', 'plugins');
3738
+        // On prend en compte les extensions
3739
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3740
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3741
+        } else {
3742
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3743
+        }
3744
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3745
+            return '';
3746
+        }
3747
+        if ($type_info == 'tout') {
3748
+            return $infos;
3749
+        } elseif ($type_info == 'est_actif') {
3750
+            return $infos ? 1 : 0;
3751
+        } else {
3752
+            return strval($infos[$type_info]);
3753
+        }
3754
+    }
3755 3755
 }
3756 3756
 
3757 3757
 
@@ -3778,9 +3778,9 @@  discard block
 block discarded – undo
3778 3778
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3779 3779
  */
3780 3780
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3781
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3781
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3782 3782
 
3783
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3783
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3784 3784
 }
3785 3785
 
3786 3786
 
@@ -3810,13 +3810,13 @@  discard block
 block discarded – undo
3810 3810
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3811 3811
  */
3812 3812
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3813
-	static $puce_statut = null;
3814
-	if (!$puce_statut) {
3815
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3816
-	}
3813
+    static $puce_statut = null;
3814
+    if (!$puce_statut) {
3815
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3816
+    }
3817 3817
 
3818
-	return $puce_statut($id_objet, $statut, $id_parent, $objet, false,
3819
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false);
3818
+    return $puce_statut($id_objet, $statut, $id_parent, $objet, false,
3819
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false);
3820 3820
 }
3821 3821
 
3822 3822
 
@@ -3843,95 +3843,95 @@  discard block
 block discarded – undo
3843 3843
  *   hash du contexte
3844 3844
  */
3845 3845
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3846
-	if (is_string($c)
3847
-		and @unserialize($c) !== false
3848
-	) {
3849
-		$c = unserialize($c);
3850
-	}
3851
-
3852
-	// supprimer les parametres debut_x
3853
-	// pour que la pagination ajax ne soit pas plantee
3854
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3855
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3856
-	if (is_array($c)) {
3857
-		foreach ($c as $k => $v) {
3858
-			if (strpos($k, 'debut_') === 0) {
3859
-				unset($c[$k]);
3860
-			}
3861
-		}
3862
-	}
3863
-
3864
-	if (!function_exists('calculer_cle_action')) {
3865
-		include_spip("inc/securiser_action");
3866
-	}
3867
-
3868
-	$c = serialize($c);
3869
-	$cle = calculer_cle_action($form . $c);
3870
-	$c = "$cle:$c";
3871
-
3872
-	// on ne stocke pas les contextes dans des fichiers en cache
3873
-	// par defaut, sauf si cette configuration a été forcée
3874
-	// OU que la longueur de l’argument géneré est plus long
3875
-	// que ce qui est toléré.
3876
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3877
-	if (!$cache_contextes_ajax) {
3878
-		$env = $c;
3879
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3880
-			$env = gzdeflate($env);
3881
-		}
3882
-		$env = _xor($env);
3883
-		$env = base64_encode($env);
3884
-		$len = strlen($env);
3885
-		// Si l’url est trop longue pour le navigateur
3886
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3887
-		if ($len > $max_len) {
3888
-			$cache_contextes_ajax = true;
3889
-			spip_log("Contextes AJAX forces en fichiers !"
3890
-				. " Cela arrive lorsque la valeur du contexte" 
3891
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len."
3892
-				, _LOG_AVERTISSEMENT);
3893
-		}
3894
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3895
-		elseif (
3896
-			$max_len = @ini_get('suhosin.get.max_value_length')
3897
-			and $max_len < $len
3898
-		) {
3899
-			$cache_contextes_ajax = true;
3900
-			spip_log("Contextes AJAX forces en fichiers !"
3901
-				. " Cela arrive lorsque la valeur du contexte"
3902
-				. " depasse la longueur maximale autorisee par Suhosin"
3903
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3904
-				. " Vous devriez modifier les parametres de Suhosin"
3905
-				. " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
3906
-		} 
3907
-
3908
-	}
3909
-
3910
-	if ($cache_contextes_ajax) {
3911
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
3912
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
3913
-		$md5 = md5($c);
3914
-		ecrire_fichier("$dir/c$md5", $c);
3915
-		$env = $md5;
3916
-	}
3917
-
3918
-	if ($emboite === null) {
3919
-		return $env;
3920
-	}
3921
-	if (!trim($emboite)) {
3922
-		return "";
3923
-	}
3924
-	// toujours encoder l'url source dans le bloc ajax
3925
-	$r = self();
3926
-	$r = ' data-origin="' . $r . '"';
3927
-	$class = 'ajaxbloc';
3928
-	if ($ajaxid and is_string($ajaxid)) {
3929
-		// ajaxid est normalement conforme a un nom de classe css
3930
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3931
-		$class .= ' ajax-id-' . entites_html($ajaxid);
3932
-	}
3933
-
3934
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3846
+    if (is_string($c)
3847
+        and @unserialize($c) !== false
3848
+    ) {
3849
+        $c = unserialize($c);
3850
+    }
3851
+
3852
+    // supprimer les parametres debut_x
3853
+    // pour que la pagination ajax ne soit pas plantee
3854
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3855
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3856
+    if (is_array($c)) {
3857
+        foreach ($c as $k => $v) {
3858
+            if (strpos($k, 'debut_') === 0) {
3859
+                unset($c[$k]);
3860
+            }
3861
+        }
3862
+    }
3863
+
3864
+    if (!function_exists('calculer_cle_action')) {
3865
+        include_spip("inc/securiser_action");
3866
+    }
3867
+
3868
+    $c = serialize($c);
3869
+    $cle = calculer_cle_action($form . $c);
3870
+    $c = "$cle:$c";
3871
+
3872
+    // on ne stocke pas les contextes dans des fichiers en cache
3873
+    // par defaut, sauf si cette configuration a été forcée
3874
+    // OU que la longueur de l’argument géneré est plus long
3875
+    // que ce qui est toléré.
3876
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3877
+    if (!$cache_contextes_ajax) {
3878
+        $env = $c;
3879
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3880
+            $env = gzdeflate($env);
3881
+        }
3882
+        $env = _xor($env);
3883
+        $env = base64_encode($env);
3884
+        $len = strlen($env);
3885
+        // Si l’url est trop longue pour le navigateur
3886
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3887
+        if ($len > $max_len) {
3888
+            $cache_contextes_ajax = true;
3889
+            spip_log("Contextes AJAX forces en fichiers !"
3890
+                . " Cela arrive lorsque la valeur du contexte" 
3891
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len."
3892
+                , _LOG_AVERTISSEMENT);
3893
+        }
3894
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3895
+        elseif (
3896
+            $max_len = @ini_get('suhosin.get.max_value_length')
3897
+            and $max_len < $len
3898
+        ) {
3899
+            $cache_contextes_ajax = true;
3900
+            spip_log("Contextes AJAX forces en fichiers !"
3901
+                . " Cela arrive lorsque la valeur du contexte"
3902
+                . " depasse la longueur maximale autorisee par Suhosin"
3903
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3904
+                . " Vous devriez modifier les parametres de Suhosin"
3905
+                . " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT);
3906
+        } 
3907
+
3908
+    }
3909
+
3910
+    if ($cache_contextes_ajax) {
3911
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
3912
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
3913
+        $md5 = md5($c);
3914
+        ecrire_fichier("$dir/c$md5", $c);
3915
+        $env = $md5;
3916
+    }
3917
+
3918
+    if ($emboite === null) {
3919
+        return $env;
3920
+    }
3921
+    if (!trim($emboite)) {
3922
+        return "";
3923
+    }
3924
+    // toujours encoder l'url source dans le bloc ajax
3925
+    $r = self();
3926
+    $r = ' data-origin="' . $r . '"';
3927
+    $class = 'ajaxbloc';
3928
+    if ($ajaxid and is_string($ajaxid)) {
3929
+        // ajaxid est normalement conforme a un nom de classe css
3930
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3931
+        $class .= ' ajax-id-' . entites_html($ajaxid);
3932
+    }
3933
+
3934
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3935 3935
 }
3936 3936
 
3937 3937
 /**
@@ -3951,36 +3951,36 @@  discard block
 block discarded – undo
3951 3951
  *   - false : erreur de décodage
3952 3952
  */
3953 3953
 function decoder_contexte_ajax($c, $form = '') {
3954
-	if (!function_exists('calculer_cle_action')) {
3955
-		include_spip("inc/securiser_action");
3956
-	}
3957
-	if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
3958
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
3959
-		and lire_fichier("$dir/c$c", $contexte)
3960
-	) {
3961
-		$c = $contexte;
3962
-	} else {
3963
-		$c = @base64_decode($c);
3964
-		$c = _xor($c);
3965
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3966
-			$c = @gzinflate($c);
3967
-		}
3968
-	}
3969
-
3970
-	// extraire la signature en debut de contexte
3971
-	// et la verifier avant de deserializer
3972
-	// format : signature:donneesserializees
3973
-	if ($p = strpos($c,":")){
3974
-		$cle = substr($c,0,$p);
3975
-		$c = substr($c,$p+1);
3976
-
3977
-		if ($cle == calculer_cle_action($form . $c)) {
3978
-			$env = @unserialize($c);
3979
-			return $env;
3980
-		}
3981
-	}
3982
-
3983
-	return false;
3954
+    if (!function_exists('calculer_cle_action')) {
3955
+        include_spip("inc/securiser_action");
3956
+    }
3957
+    if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
3958
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
3959
+        and lire_fichier("$dir/c$c", $contexte)
3960
+    ) {
3961
+        $c = $contexte;
3962
+    } else {
3963
+        $c = @base64_decode($c);
3964
+        $c = _xor($c);
3965
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3966
+            $c = @gzinflate($c);
3967
+        }
3968
+    }
3969
+
3970
+    // extraire la signature en debut de contexte
3971
+    // et la verifier avant de deserializer
3972
+    // format : signature:donneesserializees
3973
+    if ($p = strpos($c,":")){
3974
+        $cle = substr($c,0,$p);
3975
+        $c = substr($c,$p+1);
3976
+
3977
+        if ($cle == calculer_cle_action($form . $c)) {
3978
+            $env = @unserialize($c);
3979
+            return $env;
3980
+        }
3981
+    }
3982
+
3983
+    return false;
3984 3984
 }
3985 3985
 
3986 3986
 
@@ -3998,20 +3998,20 @@  discard block
 block discarded – undo
3998 3998
  *    Message décrypté ou encrypté
3999 3999
  **/
4000 4000
 function _xor($message, $key = null) {
4001
-	if (is_null($key)) {
4002
-		if (!function_exists('calculer_cle_action')) {
4003
-			include_spip("inc/securiser_action");
4004
-		}
4005
-		$key = pack("H*", calculer_cle_action('_xor'));
4006
-	}
4001
+    if (is_null($key)) {
4002
+        if (!function_exists('calculer_cle_action')) {
4003
+            include_spip("inc/securiser_action");
4004
+        }
4005
+        $key = pack("H*", calculer_cle_action('_xor'));
4006
+    }
4007 4007
 
4008
-	$keylen = strlen($key);
4009
-	$messagelen = strlen($message);
4010
-	for ($i = 0; $i < $messagelen; $i++) {
4011
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4012
-	}
4008
+    $keylen = strlen($key);
4009
+    $messagelen = strlen($message);
4010
+    for ($i = 0; $i < $messagelen; $i++) {
4011
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4012
+    }
4013 4013
 
4014
-	return $message;
4014
+    return $message;
4015 4015
 }
4016 4016
 
4017 4017
 /**
@@ -4074,37 +4074,37 @@  discard block
 block discarded – undo
4074 4074
  *   Code HTML
4075 4075
  */
4076 4076
 function lien_ou_expose($url, $libelle = null, $on = false, $class = "", $title = "", $rel = "", $evt = '') {
4077
-	if ($on) {
4078
-		$bal = 'strong';
4079
-		$class = "";
4080
-		$att = "";
4081
-		// si $on passe la balise et optionnelement une ou ++classe
4082
-		// a.active span.selected.active etc....
4083
-		if (is_string($on) and (strncmp($on, 'a', 1)==0 or strncmp($on, 'span', 4)==0 or strncmp($on, 'strong', 6)==0)){
4084
-			$on = explode(".", $on);
4085
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4086
-			if (in_array(reset($on), array('a', 'span', 'strong'))){
4087
-				$bal = array_shift($on);
4088
-				$class = implode(" ", $on);
4089
-				if ($bal=="a"){
4090
-					$att = 'href="#" ';
4091
-				}
4092
-			}
4093
-		}
4094
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4095
-	} else {
4096
-		$bal = 'a';
4097
-		$att = "href='$url'"
4098
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4099
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4100
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4101
-			. $evt;
4102
-	}
4103
-	if ($libelle === null) {
4104
-		$libelle = $url;
4105
-	}
4106
-
4107
-	return "<$bal $att>$libelle</$bal>";
4077
+    if ($on) {
4078
+        $bal = 'strong';
4079
+        $class = "";
4080
+        $att = "";
4081
+        // si $on passe la balise et optionnelement une ou ++classe
4082
+        // a.active span.selected.active etc....
4083
+        if (is_string($on) and (strncmp($on, 'a', 1)==0 or strncmp($on, 'span', 4)==0 or strncmp($on, 'strong', 6)==0)){
4084
+            $on = explode(".", $on);
4085
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4086
+            if (in_array(reset($on), array('a', 'span', 'strong'))){
4087
+                $bal = array_shift($on);
4088
+                $class = implode(" ", $on);
4089
+                if ($bal=="a"){
4090
+                    $att = 'href="#" ';
4091
+                }
4092
+            }
4093
+        }
4094
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4095
+    } else {
4096
+        $bal = 'a';
4097
+        $att = "href='$url'"
4098
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4099
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4100
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4101
+            . $evt;
4102
+    }
4103
+    if ($libelle === null) {
4104
+        $libelle = $url;
4105
+    }
4106
+
4107
+    return "<$bal $att>$libelle</$bal>";
4108 4108
 }
4109 4109
 
4110 4110
 
@@ -4121,37 +4121,37 @@  discard block
 block discarded – undo
4121 4121
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4122 4122
  */
4123 4123
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = array()) {
4124
-	static $local_singulier_ou_pluriel = array();
4124
+    static $local_singulier_ou_pluriel = array();
4125 4125
 
4126
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4127
-	if (!is_numeric($nb) or $nb == 0) {
4128
-		return "";
4129
-	}
4130
-	if (!is_array($vars)) {
4131
-		return "";
4132
-	}
4126
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4127
+    if (!is_numeric($nb) or $nb == 0) {
4128
+        return "";
4129
+    }
4130
+    if (!is_array($vars)) {
4131
+        return "";
4132
+    }
4133 4133
 
4134
-	$langue = $GLOBALS['spip_lang'];
4135
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4136
-		$local_singulier_ou_pluriel[$langue] = false;
4137
-		if ($f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4138
-		  or $f = charger_fonction("singulier_ou_pluriel", 'inc', true)) {
4139
-			$local_singulier_ou_pluriel[$langue] = $f;
4140
-		}
4141
-	}
4134
+    $langue = $GLOBALS['spip_lang'];
4135
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4136
+        $local_singulier_ou_pluriel[$langue] = false;
4137
+        if ($f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4138
+          or $f = charger_fonction("singulier_ou_pluriel", 'inc', true)) {
4139
+            $local_singulier_ou_pluriel[$langue] = $f;
4140
+        }
4141
+    }
4142 4142
 
4143
-	// si on a une surcharge on l'utilise
4144
-	if ($local_singulier_ou_pluriel[$langue]) {
4145
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4146
-	}
4143
+    // si on a une surcharge on l'utilise
4144
+    if ($local_singulier_ou_pluriel[$langue]) {
4145
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4146
+    }
4147 4147
 
4148
-	// sinon traitement par defaut
4149
-	$vars[$var] = $nb;
4150
-	if ($nb >= 2) {
4151
-		return _T($chaine_plusieurs, $vars);
4152
-	} else {
4153
-		return _T($chaine_un, $vars);
4154
-	}
4148
+    // sinon traitement par defaut
4149
+    $vars[$var] = $nb;
4150
+    if ($nb >= 2) {
4151
+        return _T($chaine_plusieurs, $vars);
4152
+    } else {
4153
+        return _T($chaine_un, $vars);
4154
+    }
4155 4155
 }
4156 4156
 
4157 4157
 
@@ -4179,71 +4179,71 @@  discard block
 block discarded – undo
4179 4179
  */
4180 4180
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4181 4181
 
4182
-	$class_lien = $class_bouton = $class;
4183
-
4184
-	// Normaliser la fonction et compléter la classe en fonction
4185
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4186
-		$class_lien .= ' danger';
4187
-		$class_bouton .= ' btn_danger';
4188
-	} elseif ($fonction == 'rien.gif') {
4189
-		$fonction = '';
4190
-	} elseif ($fonction == 'delsafe') {
4191
-		$fonction = 'del';
4192
-	}
4193
-
4194
-	$fond_origine = $fond;
4195
-	// Remappage des icone : article-24.png+new => article-new-24.png
4196
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4197
-		list($fond, $fonction) = $icone_renommer($fond, $fonction);
4198
-	}
4199
-
4200
-	// Ajouter le type d'objet dans la classe
4201
-	$objet_type = substr(basename($fond), 0, -4);
4202
-	$class_lien .= " $objet_type";
4203
-	$class_bouton .= " $objet_type";
4204
-
4205
-	// Texte
4206
-	$alt = attribut_html($texte);
4207
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4208
-
4209
-	// Liens : préparer les classes ajax
4210
-	$ajax = '';
4211
-	if ($type === 'lien') {
4212
-		if (strpos($class_lien, 'ajax') !== false) {
4213
-			$ajax = 'ajax';
4214
-			if (strpos($class_lien, 'preload') !== false) {
4215
-				$ajax .= ' preload';
4216
-			}
4217
-			if (strpos($class_lien, 'nocache') !== false) {
4218
-				$ajax .= ' nocache';
4219
-			}
4220
-			$ajax = " class='$ajax'";
4221
-		}
4222
-	}
4223
-
4224
-	// Repérer la taille et l'ajouter dans la classe
4225
-	$size = 24;
4226
-	if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match)
4227
-	  or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) {
4228
-		$size = $match[1];
4229
-	}
4230
-	$class_lien .= " s$size";
4231
-	$class_bouton .= " s$size";
4232
-
4233
-	// Icône
4234
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4235
-	$icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
4236
-
4237
-	// Markup final
4238
-	if ($type == 'lien') {
4239
-		return "<span class='icone $class_lien'>"
4240
-		. "<a href='$lien'$title$ajax$javascript>"
4241
-		. $icone
4242
-		. "<b>$texte</b>"
4243
-		. "</a></span>\n";
4244
-	} else {
4245
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4246
-	}
4182
+    $class_lien = $class_bouton = $class;
4183
+
4184
+    // Normaliser la fonction et compléter la classe en fonction
4185
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4186
+        $class_lien .= ' danger';
4187
+        $class_bouton .= ' btn_danger';
4188
+    } elseif ($fonction == 'rien.gif') {
4189
+        $fonction = '';
4190
+    } elseif ($fonction == 'delsafe') {
4191
+        $fonction = 'del';
4192
+    }
4193
+
4194
+    $fond_origine = $fond;
4195
+    // Remappage des icone : article-24.png+new => article-new-24.png
4196
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4197
+        list($fond, $fonction) = $icone_renommer($fond, $fonction);
4198
+    }
4199
+
4200
+    // Ajouter le type d'objet dans la classe
4201
+    $objet_type = substr(basename($fond), 0, -4);
4202
+    $class_lien .= " $objet_type";
4203
+    $class_bouton .= " $objet_type";
4204
+
4205
+    // Texte
4206
+    $alt = attribut_html($texte);
4207
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4208
+
4209
+    // Liens : préparer les classes ajax
4210
+    $ajax = '';
4211
+    if ($type === 'lien') {
4212
+        if (strpos($class_lien, 'ajax') !== false) {
4213
+            $ajax = 'ajax';
4214
+            if (strpos($class_lien, 'preload') !== false) {
4215
+                $ajax .= ' preload';
4216
+            }
4217
+            if (strpos($class_lien, 'nocache') !== false) {
4218
+                $ajax .= ' nocache';
4219
+            }
4220
+            $ajax = " class='$ajax'";
4221
+        }
4222
+    }
4223
+
4224
+    // Repérer la taille et l'ajouter dans la classe
4225
+    $size = 24;
4226
+    if (preg_match("/-([0-9]{1,3})[.](gif|png|svg)$/i", $fond, $match)
4227
+      or preg_match("/-([0-9]{1,3})([.](gif|png|svg))?$/i", $fond_origine, $match)) {
4228
+        $size = $match[1];
4229
+    }
4230
+    $class_lien .= " s$size";
4231
+    $class_bouton .= " s$size";
4232
+
4233
+    // Icône
4234
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4235
+    $icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
4236
+
4237
+    // Markup final
4238
+    if ($type == 'lien') {
4239
+        return "<span class='icone $class_lien'>"
4240
+        . "<a href='$lien'$title$ajax$javascript>"
4241
+        . $icone
4242
+        . "<b>$texte</b>"
4243
+        . "</a></span>\n";
4244
+    } else {
4245
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4246
+    }
4247 4247
 }
4248 4248
 
4249 4249
 /**
@@ -4267,7 +4267,7 @@  discard block
 block discarded – undo
4267 4267
  *     Code HTML du lien
4268 4268
  **/
4269 4269
 function icone_base($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4270
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4270
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4271 4271
 }
4272 4272
 
4273 4273
 /**
@@ -4302,7 +4302,7 @@  discard block
 block discarded – undo
4302 4302
  *     Code HTML du lien
4303 4303
  **/
4304 4304
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4305
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4305
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4306 4306
 }
4307 4307
 
4308 4308
 /**
@@ -4347,7 +4347,7 @@  discard block
 block discarded – undo
4347 4347
  *     Code HTML du lien
4348 4348
  **/
4349 4349
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") {
4350
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4350
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4351 4351
 }
4352 4352
 
4353 4353
 /**
@@ -4378,7 +4378,7 @@  discard block
 block discarded – undo
4378 4378
  *     Code HTML du lien
4379 4379
  **/
4380 4380
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = "", $class = "", $confirm = "") {
4381
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4381
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4382 4382
 }
4383 4383
 
4384 4384
 /**
@@ -4409,7 +4409,7 @@  discard block
 block discarded – undo
4409 4409
  *     Code HTML du lien
4410 4410
  */
4411 4411
 function filtre_icone_dist($lien, $texte, $fond, $align = "", $fonction = "", $class = "", $javascript = "") {
4412
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4412
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4413 4413
 }
4414 4414
 
4415 4415
 
@@ -4457,23 +4457,23 @@  discard block
 block discarded – undo
4457 4457
  * @return string Code CSS
4458 4458
  */
4459 4459
 function bando_images_background() {
4460
-	include_spip('inc/bandeau');
4461
-	// recuperer tous les boutons et leurs images
4462
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4460
+    include_spip('inc/bandeau');
4461
+    // recuperer tous les boutons et leurs images
4462
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4463 4463
 
4464
-	$res = "";
4465
-	foreach ($boutons as $page => $detail) {
4466
-		$selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4467
-		if (is_array($detail->sousmenu)) {
4468
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4469
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4470
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4471
-				}
4472
-			}
4473
-		}
4474
-	}
4464
+    $res = "";
4465
+    foreach ($boutons as $page => $detail) {
4466
+        $selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones ");
4467
+        if (is_array($detail->sousmenu)) {
4468
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4469
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4470
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4471
+                }
4472
+            }
4473
+        }
4474
+    }
4475 4475
 
4476
-	return $res;
4476
+    return $res;
4477 4477
 }
4478 4478
 
4479 4479
 /**
@@ -4498,27 +4498,27 @@  discard block
 block discarded – undo
4498 4498
  */
4499 4499
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4500 4500
 
4501
-	// Classes : dispatcher `ajax` sur le formulaire
4502
-	$class_form = '';
4503
-	if (strpos($class, 'ajax') !== false) {
4504
-		$class_form = 'ajax';
4505
-		$class = str_replace('ajax', '', $class);
4506
-	}
4507
-	$class_btn = 'submit ' . trim($class);
4501
+    // Classes : dispatcher `ajax` sur le formulaire
4502
+    $class_form = '';
4503
+    if (strpos($class, 'ajax') !== false) {
4504
+        $class_form = 'ajax';
4505
+        $class = str_replace('ajax', '', $class);
4506
+    }
4507
+    $class_btn = 'submit ' . trim($class);
4508 4508
 
4509
-	if ($confirm) {
4510
-		$confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4511
-		if ($callback) {
4512
-			$callback = "$confirm?($callback):false";
4513
-		} else {
4514
-			$callback = $confirm;
4515
-		}
4516
-	}
4517
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4518
-	$title = $title ? " title='$title'" : '';
4509
+    if ($confirm) {
4510
+        $confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4511
+        if ($callback) {
4512
+            $callback = "$confirm?($callback):false";
4513
+        } else {
4514
+            $callback = $confirm;
4515
+        }
4516
+    }
4517
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4518
+    $title = $title ? " title='$title'" : '';
4519 4519
 
4520
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4521
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4520
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4521
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4522 4522
 }
4523 4523
 
4524 4524
 /**
@@ -4539,78 +4539,78 @@  discard block
 block discarded – undo
4539 4539
  * @return string
4540 4540
  */
4541 4541
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = "") {
4542
-	static $trouver_table = null;
4543
-	static $objets;
4544
-
4545
-	// On verifie qu'on a tout ce qu'il faut
4546
-	$id_objet = intval($id_objet);
4547
-	if (!($id_objet and $type_objet and $info)) {
4548
-		return '';
4549
-	}
4550
-
4551
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4552
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4553
-		return '';
4554
-	}
4555
-
4556
-	// Si on demande l'url, on retourne direct la fonction
4557
-	if ($info == 'url') {
4558
-		return generer_url_entite($id_objet, $type_objet);
4559
-	}
4560
-
4561
-	// Sinon on va tout chercher dans la table et on garde en memoire
4562
-	$demande_titre = ($info == 'titre');
4563
-
4564
-	// 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
4565
-	if (!isset($objets[$type_objet][$id_objet])
4566
-		or
4567
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4568
-	) {
4569
-		if (!$trouver_table) {
4570
-			$trouver_table = charger_fonction('trouver_table', 'base');
4571
-		}
4572
-		$desc = $trouver_table(table_objet_sql($type_objet));
4573
-		if (!$desc) {
4574
-			return $objets[$type_objet] = false;
4575
-		}
4576
-
4577
-		// Si on demande le titre, on le gere en interne
4578
-		$champ_titre = "";
4579
-		if ($demande_titre) {
4580
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4581
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4582
-		}
4583
-		include_spip('base/abstract_sql');
4584
-		include_spip('base/connect_sql');
4585
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4586
-			'*' . $champ_titre,
4587
-			$desc['table_sql'],
4588
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4589
-		);
4590
-	}
4591
-
4592
-	// Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4593
-	if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4594
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
4595
-	} // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4596
-	else {
4597
-		if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4598
-			$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
4599
-		} // Sinon on prend directement le champ SQL tel quel
4600
-		else {
4601
-			$info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4602
-		}
4603
-	}
4604
-
4605
-	// On va ensuite appliquer les traitements automatiques si besoin
4606
-	if (!$etoile) {
4607
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4608
-		// mais ce fonctionnement est a ameliorer !
4609
-		$info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet),
4610
-			array('id_objet' => $id_objet, 'objet' => $type_objet, ''));
4611
-	}
4612
-
4613
-	return $info_generee;
4542
+    static $trouver_table = null;
4543
+    static $objets;
4544
+
4545
+    // On verifie qu'on a tout ce qu'il faut
4546
+    $id_objet = intval($id_objet);
4547
+    if (!($id_objet and $type_objet and $info)) {
4548
+        return '';
4549
+    }
4550
+
4551
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4552
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4553
+        return '';
4554
+    }
4555
+
4556
+    // Si on demande l'url, on retourne direct la fonction
4557
+    if ($info == 'url') {
4558
+        return generer_url_entite($id_objet, $type_objet);
4559
+    }
4560
+
4561
+    // Sinon on va tout chercher dans la table et on garde en memoire
4562
+    $demande_titre = ($info == 'titre');
4563
+
4564
+    // 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
4565
+    if (!isset($objets[$type_objet][$id_objet])
4566
+        or
4567
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4568
+    ) {
4569
+        if (!$trouver_table) {
4570
+            $trouver_table = charger_fonction('trouver_table', 'base');
4571
+        }
4572
+        $desc = $trouver_table(table_objet_sql($type_objet));
4573
+        if (!$desc) {
4574
+            return $objets[$type_objet] = false;
4575
+        }
4576
+
4577
+        // Si on demande le titre, on le gere en interne
4578
+        $champ_titre = "";
4579
+        if ($demande_titre) {
4580
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4581
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4582
+        }
4583
+        include_spip('base/abstract_sql');
4584
+        include_spip('base/connect_sql');
4585
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4586
+            '*' . $champ_titre,
4587
+            $desc['table_sql'],
4588
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4589
+        );
4590
+    }
4591
+
4592
+    // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4593
+    if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4594
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]);
4595
+    } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4596
+    else {
4597
+        if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4598
+            $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]);
4599
+        } // Sinon on prend directement le champ SQL tel quel
4600
+        else {
4601
+            $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : '');
4602
+        }
4603
+    }
4604
+
4605
+    // On va ensuite appliquer les traitements automatiques si besoin
4606
+    if (!$etoile) {
4607
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4608
+        // mais ce fonctionnement est a ameliorer !
4609
+        $info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet),
4610
+            array('id_objet' => $id_objet, 'objet' => $type_objet, ''));
4611
+    }
4612
+
4613
+    return $info_generee;
4614 4614
 }
4615 4615
 
4616 4616
 /**
@@ -4624,44 +4624,44 @@  discard block
 block discarded – undo
4624 4624
  * @return string
4625 4625
  */
4626 4626
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = array(), $connect = '') {
4627
-	if (!$champ) {
4628
-		return $texte;
4629
-	}
4627
+    if (!$champ) {
4628
+        return $texte;
4629
+    }
4630 4630
 	
4631
-	// On charge toujours les filtres de texte car la majorité des traitements les utilisent
4632
-	// et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4633
-	include_spip('inc/texte');
4631
+    // On charge toujours les filtres de texte car la majorité des traitements les utilisent
4632
+    // et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4633
+    include_spip('inc/texte');
4634 4634
 	
4635
-	$champ = strtoupper($champ);
4636
-	$traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4637
-	if (!$traitements or !is_array($traitements)) {
4638
-		return $texte;
4639
-	}
4635
+    $champ = strtoupper($champ);
4636
+    $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false;
4637
+    if (!$traitements or !is_array($traitements)) {
4638
+        return $texte;
4639
+    }
4640 4640
 
4641
-	$traitement = '';
4642
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4643
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4644
-		$table_objet = table_objet($table_objet);
4645
-		if (isset($traitements[$table_objet])) {
4646
-			$traitement = $traitements[$table_objet];
4647
-		}
4648
-	}
4649
-	if (!$traitement and isset($traitements[0])) {
4650
-		$traitement = $traitements[0];
4651
-	}
4652
-	// (sinon prendre le premier de la liste par defaut ?)
4641
+    $traitement = '';
4642
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4643
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4644
+        $table_objet = table_objet($table_objet);
4645
+        if (isset($traitements[$table_objet])) {
4646
+            $traitement = $traitements[$table_objet];
4647
+        }
4648
+    }
4649
+    if (!$traitement and isset($traitements[0])) {
4650
+        $traitement = $traitements[0];
4651
+    }
4652
+    // (sinon prendre le premier de la liste par defaut ?)
4653 4653
 
4654
-	if (!$traitement) {
4655
-		return $texte;
4656
-	}
4654
+    if (!$traitement) {
4655
+        return $texte;
4656
+    }
4657 4657
 
4658
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4658
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4659 4659
 
4660
-	// Fournir $connect et $Pile[0] au traitement si besoin
4661
-	$Pile = array(0 => $env);
4662
-	eval("\$texte = $traitement;");
4660
+    // Fournir $connect et $Pile[0] au traitement si besoin
4661
+    $Pile = array(0 => $env);
4662
+    eval("\$texte = $traitement;");
4663 4663
 
4664
-	return $texte;
4664
+    return $texte;
4665 4665
 }
4666 4666
 
4667 4667
 
@@ -4675,21 +4675,21 @@  discard block
 block discarded – undo
4675 4675
  * @return string
4676 4676
  */
4677 4677
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4678
-	include_spip('inc/liens');
4679
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4680
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4681
-	// le raccourcis n'est plus valide
4682
-	$titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4683
-	// on essaye avec generer_info_entite ?
4684
-	if (!strlen($titre) and !$connect) {
4685
-		$titre = generer_info_entite($id_objet, $objet, 'titre');
4686
-	}
4687
-	if (!strlen($titre)) {
4688
-		$titre = _T('info_sans_titre');
4689
-	}
4690
-	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4678
+    include_spip('inc/liens');
4679
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4680
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4681
+    // le raccourcis n'est plus valide
4682
+    $titre = isset($titre['titre']) ? typo($titre['titre']) : '';
4683
+    // on essaye avec generer_info_entite ?
4684
+    if (!strlen($titre) and !$connect) {
4685
+        $titre = generer_info_entite($id_objet, $objet, 'titre');
4686
+    }
4687
+    if (!strlen($titre)) {
4688
+        $titre = _T('info_sans_titre');
4689
+    }
4690
+    $url = generer_url_entite($id_objet, $objet, '', '', $connect);
4691 4691
 
4692
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4692
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4693 4693
 }
4694 4694
 
4695 4695
 
@@ -4706,15 +4706,15 @@  discard block
 block discarded – undo
4706 4706
  * @return string
4707 4707
  */
4708 4708
 function wrap($texte, $wrap) {
4709
-	$balises = extraire_balises($wrap);
4710
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4711
-		$texte = $wrap . $texte;
4712
-		$regs = array_reverse($regs[1]);
4713
-		$wrap = "</" . implode("></", $regs) . ">";
4714
-		$texte = $texte . $wrap;
4715
-	}
4709
+    $balises = extraire_balises($wrap);
4710
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4711
+        $texte = $wrap . $texte;
4712
+        $regs = array_reverse($regs[1]);
4713
+        $wrap = "</" . implode("></", $regs) . ">";
4714
+        $texte = $texte . $wrap;
4715
+    }
4716 4716
 
4717
-	return $texte;
4717
+    return $texte;
4718 4718
 }
4719 4719
 
4720 4720
 
@@ -4734,43 +4734,43 @@  discard block
 block discarded – undo
4734 4734
  * @return array|mixed|string
4735 4735
  */
4736 4736
 function filtre_print_dist($u, $join = "<br />", $indent = 0) {
4737
-	if (is_string($u)) {
4738
-		$u = typo($u);
4737
+    if (is_string($u)) {
4738
+        $u = typo($u);
4739 4739
 
4740
-		return $u;
4741
-	}
4740
+        return $u;
4741
+    }
4742 4742
 
4743
-	// caster $u en array si besoin
4744
-	if (is_object($u)) {
4745
-		$u = (array)$u;
4746
-	}
4743
+    // caster $u en array si besoin
4744
+    if (is_object($u)) {
4745
+        $u = (array)$u;
4746
+    }
4747 4747
 
4748
-	if (is_array($u)) {
4749
-		$out = "";
4750
-		// toutes les cles sont numeriques ?
4751
-		// et aucun enfant n'est un tableau
4752
-		// liste simple separee par des virgules
4753
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4754
-		$array_values = array_map('is_array', $u);
4755
-		$object_values = array_map('is_object', $u);
4756
-		if (array_sum($numeric_keys) == count($numeric_keys)
4757
-			and !array_sum($array_values)
4758
-			and !array_sum($object_values)
4759
-		) {
4760
-			return join(", ", array_map('filtre_print_dist', $u));
4761
-		}
4748
+    if (is_array($u)) {
4749
+        $out = "";
4750
+        // toutes les cles sont numeriques ?
4751
+        // et aucun enfant n'est un tableau
4752
+        // liste simple separee par des virgules
4753
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4754
+        $array_values = array_map('is_array', $u);
4755
+        $object_values = array_map('is_object', $u);
4756
+        if (array_sum($numeric_keys) == count($numeric_keys)
4757
+            and !array_sum($array_values)
4758
+            and !array_sum($object_values)
4759
+        ) {
4760
+            return join(", ", array_map('filtre_print_dist', $u));
4761
+        }
4762 4762
 
4763
-		// sinon on passe a la ligne et on indente
4764
-		$i_str = str_pad("", $indent, " ");
4765
-		foreach ($u as $k => $v) {
4766
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4767
-		}
4763
+        // sinon on passe a la ligne et on indente
4764
+        $i_str = str_pad("", $indent, " ");
4765
+        foreach ($u as $k => $v) {
4766
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4767
+        }
4768 4768
 
4769
-		return $out;
4770
-	}
4769
+        return $out;
4770
+    }
4771 4771
 
4772
-	// on sait pas quoi faire...
4773
-	return $u;
4772
+    // on sait pas quoi faire...
4773
+    return $u;
4774 4774
 }
4775 4775
 
4776 4776
 
@@ -4783,10 +4783,10 @@  discard block
 block discarded – undo
4783 4783
  * @return string|array
4784 4784
  */
4785 4785
 function objet_info($objet, $info) {
4786
-	$table = table_objet_sql($objet);
4787
-	$infos = lister_tables_objets_sql($table);
4786
+    $table = table_objet_sql($objet);
4787
+    $infos = lister_tables_objets_sql($table);
4788 4788
 
4789
-	return (isset($infos[$info]) ? $infos[$info] : '');
4789
+    return (isset($infos[$info]) ? $infos[$info] : '');
4790 4790
 }
4791 4791
 
4792 4792
 /**
@@ -4801,11 +4801,11 @@  discard block
 block discarded – undo
4801 4801
  *     Texte traduit du comptage, tel que '3 articles'
4802 4802
  */
4803 4803
 function objet_afficher_nb($nb, $objet) {
4804
-	if (!$nb) {
4805
-		return _T(objet_info($objet, 'info_aucun_objet'));
4806
-	} else {
4807
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb));
4808
-	}
4804
+    if (!$nb) {
4805
+        return _T(objet_info($objet, 'info_aucun_objet'));
4806
+    } else {
4807
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb));
4808
+    }
4809 4809
 }
4810 4810
 
4811 4811
 /**
@@ -4817,11 +4817,11 @@  discard block
 block discarded – undo
4817 4817
  * @return string
4818 4818
  */
4819 4819
 function objet_icone($objet, $taille = 24, $class='') {
4820
-	$icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4821
-	$icone = chemin_image($icone);
4822
-	$balise_img = charger_filtre('balise_img');
4820
+    $icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4821
+    $icone = chemin_image($icone);
4822
+    $balise_img = charger_filtre('balise_img');
4823 4823
 
4824
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4824
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4825 4825
 }
4826 4826
 
4827 4827
 /**
@@ -4842,12 +4842,12 @@  discard block
 block discarded – undo
4842 4842
  * @return string
4843 4843
  */
4844 4844
 function objet_T($objet, $chaine, $args = array(), $options = array()){
4845
-	$chaine = explode(':',$chaine);
4846
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4847
-		return $t;
4848
-	}
4849
-	$chaine = implode(':',$chaine);
4850
-	return _T($chaine, $args, $options);
4845
+    $chaine = explode(':',$chaine);
4846
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4847
+        return $t;
4848
+    }
4849
+    $chaine = implode(':',$chaine);
4850
+    return _T($chaine, $args, $options);
4851 4851
 }
4852 4852
 
4853 4853
 /**
@@ -4861,17 +4861,17 @@  discard block
 block discarded – undo
4861 4861
  * @return string      Code HTML
4862 4862
  */
4863 4863
 function insert_head_css_conditionnel($flux) {
4864
-	if (strpos($flux, '<!-- insert_head_css -->') === false
4865
-		and $p = strpos($flux, '<!-- insert_head -->')
4866
-	) {
4867
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
4868
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
4869
-			$p = $p1;
4870
-		}
4871
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4872
-	}
4864
+    if (strpos($flux, '<!-- insert_head_css -->') === false
4865
+        and $p = strpos($flux, '<!-- insert_head -->')
4866
+    ) {
4867
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
4868
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
4869
+            $p = $p1;
4870
+        }
4871
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4872
+    }
4873 4873
 
4874
-	return $flux;
4874
+    return $flux;
4875 4875
 }
4876 4876
 
4877 4877
 /**
@@ -4892,69 +4892,69 @@  discard block
 block discarded – undo
4892 4892
  * @return string
4893 4893
  */
4894 4894
 function produire_fond_statique($fond, $contexte = array(), $options = array(), $connect = '') {
4895
-	if (isset($contexte['format'])) {
4896
-		$extension = $contexte['format'];
4897
-		unset($contexte['format']);
4898
-	} else {
4899
-		$extension = "html";
4900
-		if (preg_match(',[.](css|js|json)$,', $fond, $m)) {
4901
-			$extension = $m[1];
4902
-		}
4903
-	}
4904
-	// recuperer le contenu produit par le squelette
4905
-	$options['raw'] = true;
4906
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
4907
-
4908
-	// calculer le nom de la css
4909
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4910
-	$nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4911
-	$contexte_implicite = calculer_contexte_implicite();
4912
-
4913
-	// par defaut on hash selon les contextes qui sont a priori moins variables
4914
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4915
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4916
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
4917
-		$hash = md5($contexte_implicite['host'] . '::'. $cache);
4918
-	}
4919
-	else {
4920
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4921
-		ksort($contexte);
4922
-		$hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
4923
-	}
4924
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4925
-
4926
-	// mettre a jour le fichier si il n'existe pas
4927
-	// ou trop ancien
4928
-	// le dernier fichier produit est toujours suffixe par .last
4929
-	// et recopie sur le fichier cible uniquement si il change
4930
-	if (!file_exists($filename)
4931
-		or !file_exists($filename . ".last")
4932
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4933
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4934
-	) {
4935
-		$contenu = $cache['texte'];
4936
-		// passer les urls en absolu si c'est une css
4937
-		if ($extension == "css") {
4938
-			$contenu = urls_absolues_css($contenu,
4939
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond));
4940
-		}
4941
-
4942
-		$comment = '';
4943
-		// ne pas insérer de commentaire si c'est du json
4944
-		if ($extension != "json") {
4945
-			$comment = "/* #PRODUIRE{fond=$fond";
4946
-			foreach ($contexte as $k => $v) {
4947
-				$comment .= ",$k=$v";
4948
-			}
4949
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4950
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4951
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
4952
-		}
4953
-		// et ecrire le fichier si il change
4954
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
4955
-	}
4956
-
4957
-	return timestamp($filename);
4895
+    if (isset($contexte['format'])) {
4896
+        $extension = $contexte['format'];
4897
+        unset($contexte['format']);
4898
+    } else {
4899
+        $extension = "html";
4900
+        if (preg_match(',[.](css|js|json)$,', $fond, $m)) {
4901
+            $extension = $m[1];
4902
+        }
4903
+    }
4904
+    // recuperer le contenu produit par le squelette
4905
+    $options['raw'] = true;
4906
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
4907
+
4908
+    // calculer le nom de la css
4909
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4910
+    $nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4911
+    $contexte_implicite = calculer_contexte_implicite();
4912
+
4913
+    // par defaut on hash selon les contextes qui sont a priori moins variables
4914
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4915
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4916
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
4917
+        $hash = md5($contexte_implicite['host'] . '::'. $cache);
4918
+    }
4919
+    else {
4920
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4921
+        ksort($contexte);
4922
+        $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
4923
+    }
4924
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4925
+
4926
+    // mettre a jour le fichier si il n'existe pas
4927
+    // ou trop ancien
4928
+    // le dernier fichier produit est toujours suffixe par .last
4929
+    // et recopie sur le fichier cible uniquement si il change
4930
+    if (!file_exists($filename)
4931
+        or !file_exists($filename . ".last")
4932
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4933
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4934
+    ) {
4935
+        $contenu = $cache['texte'];
4936
+        // passer les urls en absolu si c'est une css
4937
+        if ($extension == "css") {
4938
+            $contenu = urls_absolues_css($contenu,
4939
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond));
4940
+        }
4941
+
4942
+        $comment = '';
4943
+        // ne pas insérer de commentaire si c'est du json
4944
+        if ($extension != "json") {
4945
+            $comment = "/* #PRODUIRE{fond=$fond";
4946
+            foreach ($contexte as $k => $v) {
4947
+                $comment .= ",$k=$v";
4948
+            }
4949
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4950
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4951
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
4952
+        }
4953
+        // et ecrire le fichier si il change
4954
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
4955
+    }
4956
+
4957
+    return timestamp($filename);
4958 4958
 }
4959 4959
 
4960 4960
 /**
@@ -4967,14 +4967,14 @@  discard block
 block discarded – undo
4967 4967
  *    $fichier auquel on a ajouté le timestamp
4968 4968
  */
4969 4969
 function timestamp($fichier) {
4970
-	if (!$fichier
4971
-		or !file_exists($fichier)
4972
-		or !$m = filemtime($fichier)
4973
-	) {
4974
-		return $fichier;
4975
-	}
4970
+    if (!$fichier
4971
+        or !file_exists($fichier)
4972
+        or !$m = filemtime($fichier)
4973
+    ) {
4974
+        return $fichier;
4975
+    }
4976 4976
 
4977
-	return "$fichier?$m";
4977
+    return "$fichier?$m";
4978 4978
 }
4979 4979
 
4980 4980
 /**
@@ -4984,11 +4984,11 @@  discard block
 block discarded – undo
4984 4984
  * @return string
4985 4985
  */
4986 4986
 function supprimer_timestamp($url) {
4987
-	if (strpos($url, "?") === false) {
4988
-		return $url;
4989
-	}
4987
+    if (strpos($url, "?") === false) {
4988
+        return $url;
4989
+    }
4990 4990
 
4991
-	return preg_replace(",\?[[:digit:]]+$,", "", $url);
4991
+    return preg_replace(",\?[[:digit:]]+$,", "", $url);
4992 4992
 }
4993 4993
 
4994 4994
 /**
@@ -5003,9 +5003,9 @@  discard block
 block discarded – undo
5003 5003
  * @return string
5004 5004
  */
5005 5005
 function filtre_nettoyer_titre_email_dist($titre) {
5006
-	include_spip('inc/envoyer_mail');
5006
+    include_spip('inc/envoyer_mail');
5007 5007
 
5008
-	return nettoyer_titre_email($titre);
5008
+    return nettoyer_titre_email($titre);
5009 5009
 }
5010 5010
 
5011 5011
 /**
@@ -5027,19 +5027,19 @@  discard block
 block discarded – undo
5027 5027
  * @return string
5028 5028
  */
5029 5029
 function filtre_chercher_rubrique_dist(
5030
-	$titre,
5031
-	$id_objet,
5032
-	$id_parent,
5033
-	$objet,
5034
-	$id_secteur,
5035
-	$restreint,
5036
-	$actionable = false,
5037
-	$retour_sans_cadre = false
5030
+    $titre,
5031
+    $id_objet,
5032
+    $id_parent,
5033
+    $objet,
5034
+    $id_secteur,
5035
+    $restreint,
5036
+    $actionable = false,
5037
+    $retour_sans_cadre = false
5038 5038
 ) {
5039
-	include_spip('inc/filtres_ecrire');
5039
+    include_spip('inc/filtres_ecrire');
5040 5040
 
5041
-	return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable,
5042
-		$retour_sans_cadre);
5041
+    return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable,
5042
+        $retour_sans_cadre);
5043 5043
 }
5044 5044
 
5045 5045
 /**
@@ -5068,56 +5068,56 @@  discard block
 block discarded – undo
5068 5068
  *     Chaîne vide si l'accès est autorisé
5069 5069
  */
5070 5070
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5071
-	if ($ok) {
5072
-		return '';
5073
-	}
5074
-
5075
-	// Vider tous les tampons
5076
-	$level = @ob_get_level();
5077
-	while ($level--) {
5078
-		@ob_end_clean();
5079
-	}
5080
-
5081
-	include_spip('inc/headers');
5082
-
5083
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5084
-	if ($url) {
5085
-		redirige_par_entete($url, '', $statut);
5086
-	}
5087
-
5088
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5089
-	if (!is_numeric($statut) and is_null($message)) {
5090
-		$message = $statut;
5091
-		$statut = 0;
5092
-	}
5093
-	if (!$message) {
5094
-		$message = '';
5095
-	}
5096
-	$statut = intval($statut);
5097
-
5098
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5099
-	if (test_espace_prive()) {
5100
-		if (!$statut or !in_array($statut, array(404, 403))) {
5101
-			$statut = 403;
5102
-		}
5103
-		http_status(403);
5104
-		$echec = charger_fonction('403', 'exec');
5105
-		$echec($message);
5106
-	} else {
5107
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5108
-		if (!$statut) {
5109
-			$statut = 404;
5110
-		}
5111
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5112
-		http_status($statut);
5113
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5114
-		if ($statut >= 400) {
5115
-			echo recuperer_fond("$statut", array('erreur' => $message));
5116
-		}
5117
-	}
5118
-
5119
-
5120
-	exit;
5071
+    if ($ok) {
5072
+        return '';
5073
+    }
5074
+
5075
+    // Vider tous les tampons
5076
+    $level = @ob_get_level();
5077
+    while ($level--) {
5078
+        @ob_end_clean();
5079
+    }
5080
+
5081
+    include_spip('inc/headers');
5082
+
5083
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5084
+    if ($url) {
5085
+        redirige_par_entete($url, '', $statut);
5086
+    }
5087
+
5088
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5089
+    if (!is_numeric($statut) and is_null($message)) {
5090
+        $message = $statut;
5091
+        $statut = 0;
5092
+    }
5093
+    if (!$message) {
5094
+        $message = '';
5095
+    }
5096
+    $statut = intval($statut);
5097
+
5098
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5099
+    if (test_espace_prive()) {
5100
+        if (!$statut or !in_array($statut, array(404, 403))) {
5101
+            $statut = 403;
5102
+        }
5103
+        http_status(403);
5104
+        $echec = charger_fonction('403', 'exec');
5105
+        $echec($message);
5106
+    } else {
5107
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5108
+        if (!$statut) {
5109
+            $statut = 404;
5110
+        }
5111
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5112
+        http_status($statut);
5113
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5114
+        if ($statut >= 400) {
5115
+            echo recuperer_fond("$statut", array('erreur' => $message));
5116
+        }
5117
+    }
5118
+
5119
+
5120
+    exit;
5121 5121
 }
5122 5122
 
5123 5123
 /**
@@ -5128,11 +5128,11 @@  discard block
 block discarded – undo
5128 5128
  * @return string
5129 5129
  */
5130 5130
 function filtre_compacte_dist($source, $format = null) {
5131
-	if (function_exists('compacte')) {
5132
-		return compacte($source, $format);
5133
-	}
5131
+    if (function_exists('compacte')) {
5132
+        return compacte($source, $format);
5133
+    }
5134 5134
 
5135
-	return $source;
5135
+    return $source;
5136 5136
 }
5137 5137
 
5138 5138
 
@@ -5144,31 +5144,31 @@  discard block
 block discarded – undo
5144 5144
  * @return string
5145 5145
  */
5146 5146
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
5147
-	$l = strlen($passe);
5148
-
5149
-	if ($l<=8 or !$afficher_partiellement){
5150
-		if (!$l) {
5151
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5152
-		}
5153
-		return str_pad('',$afficher_partiellement ? $l : 16,'*');
5154
-	}
5155
-
5156
-	if (is_null($portion_pourcent)) {
5157
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5158
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5159
-		}
5160
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5161
-	}
5162
-	if ($portion_pourcent >= 100) {
5163
-		return $passe;
5164
-	}
5165
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5166
-	$e = max($e, 0);
5167
-	$mid = str_pad('',$l-2*$e,'*');
5168
-	if ($e>0 and strlen($mid)>8){
5169
-		$mid = '***...***';
5170
-	}
5171
-	return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : '');
5147
+    $l = strlen($passe);
5148
+
5149
+    if ($l<=8 or !$afficher_partiellement){
5150
+        if (!$l) {
5151
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5152
+        }
5153
+        return str_pad('',$afficher_partiellement ? $l : 16,'*');
5154
+    }
5155
+
5156
+    if (is_null($portion_pourcent)) {
5157
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5158
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5159
+        }
5160
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5161
+    }
5162
+    if ($portion_pourcent >= 100) {
5163
+        return $passe;
5164
+    }
5165
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5166
+    $e = max($e, 0);
5167
+    $mid = str_pad('',$l-2*$e,'*');
5168
+    if ($e>0 and strlen($mid)>8){
5169
+        $mid = '***...***';
5170
+    }
5171
+    return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : '');
5172 5172
 }
5173 5173
 
5174 5174
 
@@ -5189,64 +5189,64 @@  discard block
 block discarded – undo
5189 5189
  */
5190 5190
 function identifiant_slug($texte, $type = '', $options = array()) {
5191 5191
 
5192
-	$original = $texte;
5193
-	$separateur = (isset($options['separateur'])?$options['separateur']:'_');
5194
-	$longueur_maxi = (isset($options['longueur_maxi'])?$options['longueur_maxi']:60);
5195
-	$longueur_mini = (isset($options['longueur_mini'])?$options['longueur_mini']:0);
5192
+    $original = $texte;
5193
+    $separateur = (isset($options['separateur'])?$options['separateur']:'_');
5194
+    $longueur_maxi = (isset($options['longueur_maxi'])?$options['longueur_maxi']:60);
5195
+    $longueur_mini = (isset($options['longueur_mini'])?$options['longueur_mini']:0);
5196 5196
 
5197
-	if (!function_exists('translitteration')) {
5198
-		include_spip('inc/charsets');
5199
-	}
5197
+    if (!function_exists('translitteration')) {
5198
+        include_spip('inc/charsets');
5199
+    }
5200 5200
 
5201
-	// pas de balise html
5202
-	if (strpos($texte, '<') !== false) {
5203
-		$texte = strip_tags($texte);
5204
-	}
5205
-	if (strpos($texte, '&') !== false) {
5206
-		$texte = unicode2charset($texte);
5207
-	}
5208
-	// On enlève les espaces indésirables
5209
-	$texte = trim($texte);
5201
+    // pas de balise html
5202
+    if (strpos($texte, '<') !== false) {
5203
+        $texte = strip_tags($texte);
5204
+    }
5205
+    if (strpos($texte, '&') !== false) {
5206
+        $texte = unicode2charset($texte);
5207
+    }
5208
+    // On enlève les espaces indésirables
5209
+    $texte = trim($texte);
5210 5210
 
5211
-	// On enlève les accents et cie
5212
-	$texte = translitteration($texte);
5211
+    // On enlève les accents et cie
5212
+    $texte = translitteration($texte);
5213 5213
 
5214
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5215
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5214
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5215
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5216 5216
 
5217
-	// nettoyer les doubles occurences du separateur si besoin
5218
-	while (strpos($texte, "$separateur$separateur") !== false) {
5219
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5220
-	}
5217
+    // nettoyer les doubles occurences du separateur si besoin
5218
+    while (strpos($texte, "$separateur$separateur") !== false) {
5219
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5220
+    }
5221 5221
 
5222
-	// pas de separateur au debut ni a la fin
5223
-	$texte = trim($texte, $separateur);
5222
+    // pas de separateur au debut ni a la fin
5223
+    $texte = trim($texte, $separateur);
5224 5224
 
5225
-	// en minuscules
5226
-	$texte = strtolower($texte);
5225
+    // en minuscules
5226
+    $texte = strtolower($texte);
5227 5227
 
5228
-	switch ($type) {
5229
-		case 'class':
5230
-		case 'id':
5231
-		case 'anchor':
5232
-			if (preg_match(',^\d,', $texte)) {
5233
-				$texte = substr($type, 0, 1).$texte;
5234
-			}
5235
-	}
5228
+    switch ($type) {
5229
+        case 'class':
5230
+        case 'id':
5231
+        case 'anchor':
5232
+            if (preg_match(',^\d,', $texte)) {
5233
+                $texte = substr($type, 0, 1).$texte;
5234
+            }
5235
+    }
5236 5236
 
5237
-	if (strlen($texte)>$longueur_maxi) {
5238
-		$texte = substr($texte, 0, $longueur_maxi);
5239
-	}
5237
+    if (strlen($texte)>$longueur_maxi) {
5238
+        $texte = substr($texte, 0, $longueur_maxi);
5239
+    }
5240 5240
 
5241
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5242
-		if (preg_match(',^\d,', $texte)) {
5243
-			$texte = ($type ? substr($type,0,1) : "s") . $texte;
5244
-		}
5245
-		$texte .= $separateur . md5($original);
5246
-		$texte = substr($texte, 0, $longueur_mini);
5247
-	}
5241
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5242
+        if (preg_match(',^\d,', $texte)) {
5243
+            $texte = ($type ? substr($type,0,1) : "s") . $texte;
5244
+        }
5245
+        $texte .= $separateur . md5($original);
5246
+        $texte = substr($texte, 0, $longueur_mini);
5247
+    }
5248 5248
 
5249
-	return $texte;
5249
+    return $texte;
5250 5250
 }
5251 5251
 
5252 5252
 
@@ -5261,14 +5261,14 @@  discard block
 block discarded – undo
5261 5261
  * @exemple `<:info_maximum|uniformiser_label:>`
5262 5262
  */
5263 5263
 function uniformiser_label(string $text, bool $ucfirst = true) : string {
5264
-	$label = rtrim($text, " : \t\n\r\0\x0B\xc2\xa0");
5265
-	if ($label and $label[-1] === ';') {
5266
-		$label = preg_replace("#(\&nbsp;)+$#", "", $label);
5267
-	}
5268
-	if ($ucfirst) {
5269
-		$label = spip_ucfirst($label);
5270
-	}
5271
-	return $label;
5264
+    $label = rtrim($text, " : \t\n\r\0\x0B\xc2\xa0");
5265
+    if ($label and $label[-1] === ';') {
5266
+        $label = preg_replace("#(\&nbsp;)+$#", "", $label);
5267
+    }
5268
+    if ($ucfirst) {
5269
+        $label = spip_ucfirst($label);
5270
+    }
5271
+    return $label;
5272 5272
 }
5273 5273
 
5274 5274
 
@@ -5280,19 +5280,19 @@  discard block
 block discarded – undo
5280 5280
  * @return array
5281 5281
  */
5282 5282
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5283
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5284
-		return [];
5285
-	}
5283
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5284
+        return [];
5285
+    }
5286 5286
 
5287
-	// compatibilite signature inversee
5288
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5289
-		list($objet, $id_objet) = [$id_objet, $objet];
5290
-	}
5287
+    // compatibilite signature inversee
5288
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5289
+        list($objet, $id_objet) = [$id_objet, $objet];
5290
+    }
5291 5291
 
5292
-	if (!function_exists($fonction)) {
5293
-		include_spip('base/objets');
5294
-	}
5295
-	return $fonction($objet, $id_objet);
5292
+    if (!function_exists($fonction)) {
5293
+        include_spip('base/objets');
5294
+    }
5295
+    return $fonction($objet, $id_objet);
5296 5296
 }
5297 5297
 
5298 5298
 
@@ -5307,7 +5307,7 @@  discard block
 block discarded – undo
5307 5307
  * @return array
5308 5308
  */
5309 5309
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5310
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5310
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5311 5311
 }
5312 5312
 
5313 5313
 /**
@@ -5321,7 +5321,7 @@  discard block
 block discarded – undo
5321 5321
  * @return array
5322 5322
  */
5323 5323
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5324
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5324
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5325 5325
 }
5326 5326
 
5327 5327
 /**
@@ -5335,7 +5335,7 @@  discard block
 block discarded – undo
5335 5335
  * @return array
5336 5336
  */
5337 5337
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5338
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5338
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5339 5339
 }
5340 5340
 
5341 5341
 /**
@@ -5349,6 +5349,6 @@  discard block
 block discarded – undo
5349 5349
  * @return array
5350 5350
  */
5351 5351
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5352
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5352
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5353 5353
 }
5354 5354
 
Please login to merge, or discard this patch.
Spacing   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	}
95 95
 
96 96
 	include_fichiers_fonctions();
97
-	foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) {
97
+	foreach (array('filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc) as $f) {
98 98
 		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
99 99
 		// fonction ou name\space\fonction
100 100
 		if (is_callable($f)) {
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 	// affichage "GIT [master: abcdef]"
222 222
 	$commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit'];
223 223
 	if ($desc['branch']) {
224
-		$commit = $desc['branch'] . ': ' . $commit;
224
+		$commit = $desc['branch'].': '.$commit;
225 225
 	}
226 226
 	return "{$desc['vcs']} [$commit]";
227 227
 }
@@ -240,9 +240,9 @@  discard block
 block discarded – undo
240 240
 	}
241 241
 
242 242
 	// version installee par GIT
243
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
243
+	if (lire_fichier($dir.'/.git/HEAD', $c)) {
244 244
 		$currentHead = trim(substr($c, 4));
245
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
245
+		if (lire_fichier($dir.'/.git/'.$currentHead, $hash)) {
246 246
 			return [
247 247
 				'vcs' => 'GIT',
248 248
 				'branch' => basename($currentHead),
@@ -269,8 +269,8 @@  discard block
 block discarded – undo
269 269
 		$dir = '.';
270 270
 	}
271 271
 	// version installee par SVN
272
-	if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) {
273
-		$db = new SQLite3($dir . '/.svn/wc.db');
272
+	if (file_exists($dir.'/.svn/wc.db') && class_exists('SQLite3')) {
273
+		$db = new SQLite3($dir.'/.svn/wc.db');
274 274
 		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
275 275
 		if ($result) {
276 276
 			$row = $result->fetchArray();
@@ -288,12 +288,12 @@  discard block
 block discarded – undo
288 288
 
289 289
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
290 290
 // et laisser passer les fonctions personnelles baptisees image_...
291
-$GLOBALS['spip_matrice']['image_graver'] = true;//'inc/filtres_images_mini.php';
292
-$GLOBALS['spip_matrice']['image_select'] = true;//'inc/filtres_images_mini.php';
293
-$GLOBALS['spip_matrice']['image_reduire'] = true;//'inc/filtres_images_mini.php';
294
-$GLOBALS['spip_matrice']['image_reduire_par'] = true;//'inc/filtres_images_mini.php';
295
-$GLOBALS['spip_matrice']['image_passe_partout'] = true;//'inc/filtres_images_mini.php';
296
-$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true;//'inc/filtres_images_mini.php';
291
+$GLOBALS['spip_matrice']['image_graver'] = true; //'inc/filtres_images_mini.php';
292
+$GLOBALS['spip_matrice']['image_select'] = true; //'inc/filtres_images_mini.php';
293
+$GLOBALS['spip_matrice']['image_reduire'] = true; //'inc/filtres_images_mini.php';
294
+$GLOBALS['spip_matrice']['image_reduire_par'] = true; //'inc/filtres_images_mini.php';
295
+$GLOBALS['spip_matrice']['image_passe_partout'] = true; //'inc/filtres_images_mini.php';
296
+$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true; //'inc/filtres_images_mini.php';
297 297
 
298 298
 $GLOBALS['spip_matrice']['couleur_html_to_hex'] = 'inc/filtres_images_mini.php';
299 299
 $GLOBALS['spip_matrice']['couleur_hex_to_hsl'] = 'inc/filtres_images_mini.php';
@@ -452,8 +452,8 @@  discard block
 block discarded – undo
452 452
  */
453 453
 function filtre_debug($val, $key = null) {
454 454
 	$debug = (
455
-		is_null($key) ? '' : (var_export($key, true) . " = ")
456
-		) . var_export($val, true);
455
+		is_null($key) ? '' : (var_export($key, true)." = ")
456
+		).var_export($val, true);
457 457
 
458 458
 	include_spip('inc/autoriser');
459 459
 	if (autoriser('webmestre')) {
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
 						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
553 553
 							$srcover = $match[1];
554 554
 							array_shift($args);
555
-							array_unshift($args, "<img src='" . $match[1] . "' />");
555
+							array_unshift($args, "<img src='".$match[1]."' />");
556 556
 							$srcover_filter = call_user_func_array($filtre, $args);
557 557
 							$srcover_filter = extraire_attribut($srcover_filter, 'src');
558 558
 							$reduit = str_replace($srcover, $srcover_filter, $reduit);
@@ -623,14 +623,14 @@  discard block
 block discarded – undo
623 623
 				$hauteur_img[$src] = $srcHeight = $srcsize[1];
624 624
 			}
625 625
 		}
626
-		elseif(strpos($src, "<svg") !== false) {
626
+		elseif (strpos($src, "<svg") !== false) {
627 627
 			include_spip('inc/svg');
628
-			if ($attrs = svg_lire_attributs($src)){
628
+			if ($attrs = svg_lire_attributs($src)) {
629 629
 				list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs);
630
-				if (!$srcWidth){
630
+				if (!$srcWidth) {
631 631
 					$largeur_img[$src] = $srcWidth = $width;
632 632
 				}
633
-				if (!$srcHeight){
633
+				if (!$srcHeight) {
634 634
 					$hauteur_img[$src] = $srcHeight = $height;
635 635
 				}
636 636
 			}
@@ -914,7 +914,7 @@  discard block
 block discarded – undo
914 914
 	// " -> &quot; et tout ce genre de choses
915 915
 	$u = $GLOBALS['meta']['pcre_u'];
916 916
 	$texte = str_replace("&nbsp;", " ", $texte);
917
-	$texte = preg_replace('/\s{2,}/S' . $u, " ", $texte);
917
+	$texte = preg_replace('/\s{2,}/S'.$u, " ", $texte);
918 918
 	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
919 919
 	$texte = entites_html($texte, false, false);
920 920
 	// mais bien echapper les double quotes !
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
  **/
975 975
 function supprimer_numero($texte) {
976 976
 	return preg_replace(
977
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
977
+		",^[[:space:]]*([0-9]+)([.)]|".chr(194).'?'.chr(176).")[[:space:]]+,S",
978 978
 		"", $texte);
979 979
 }
980 980
 
@@ -999,7 +999,7 @@  discard block
 block discarded – undo
999 999
  **/
1000 1000
 function recuperer_numero($texte) {
1001 1001
 	if (preg_match(
1002
-		",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S",
1002
+		",^[[:space:]]*([0-9]+)([.)]|".chr(194).'?'.chr(176).")[[:space:]]+,S",
1003 1003
 		$texte, $regs)) {
1004 1004
 		return strval($regs[1]);
1005 1005
 	} else {
@@ -1084,8 +1084,8 @@  discard block
 block discarded – undo
1084 1084
  **/
1085 1085
 function textebrut($texte) {
1086 1086
 	$u = $GLOBALS['meta']['pcre_u'];
1087
-	$texte = preg_replace('/\s+/S' . $u, " ", $texte);
1088
-	$texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte);
1087
+	$texte = preg_replace('/\s+/S'.$u, " ", $texte);
1088
+	$texte = preg_replace("/<(p|br)( [^>]*)?".">/iS", "\n\n", $texte);
1089 1089
 	$texte = preg_replace("/^\n+/", "", $texte);
1090 1090
 	$texte = preg_replace("/\n+$/", "", $texte);
1091 1091
 	$texte = preg_replace("/\n +/", "\n", $texte);
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
 	if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1114 1114
 		$texte, $liens, PREG_PATTERN_ORDER)) {
1115 1115
 		foreach ($liens[0] as $a) {
1116
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1116
+			$rel = 'noopener noreferrer '.extraire_attribut($a, 'rel');
1117 1117
 			$ablank = inserer_attribut($a, 'rel', $rel);
1118 1118
 			$ablank = inserer_attribut($ablank, 'target', '_blank');
1119 1119
 			$texte = str_replace($a, $ablank, $texte);
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
 		foreach ($regs[0] as $a) {
1139 1139
 			$rel = extraire_attribut($a, "rel");
1140 1140
 			if (strpos($rel, "nofollow") === false) {
1141
-				$rel = "nofollow" . ($rel ? " $rel" : "");
1141
+				$rel = "nofollow".($rel ? " $rel" : "");
1142 1142
 				$anofollow = inserer_attribut($a, "rel", $rel);
1143 1143
 				$texte = str_replace($a, $anofollow, $texte);
1144 1144
 			}
@@ -1167,7 +1167,7 @@  discard block
 block discarded – undo
1167 1167
 	$u = $GLOBALS['meta']['pcre_u'];
1168 1168
 	$texte = preg_replace("@</p>@iS", "\n", $texte);
1169 1169
 	$texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte);
1170
-	$texte = preg_replace("@^\s*<br />@S" . $u, "", $texte);
1170
+	$texte = preg_replace("@^\s*<br />@S".$u, "", $texte);
1171 1171
 
1172 1172
 	return $texte;
1173 1173
 }
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
 		return $texte;
1199 1199
 	}
1200 1200
 	include_spip('inc/texte');
1201
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1201
+	$tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ?
1202 1202
 		'div' : 'span';
1203 1203
 
1204 1204
 	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
@@ -1307,7 +1307,7 @@  discard block
 block discarded – undo
1307 1307
 function attribut_html($texte, $textebrut = true) {
1308 1308
 	$u = $GLOBALS['meta']['pcre_u'];
1309 1309
 	if ($textebrut) {
1310
-		$texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte));
1310
+		$texte = preg_replace(array(",\n,", ",\s(?=\s),msS".$u), array(" ", ""), textebrut($texte));
1311 1311
 	}
1312 1312
 	$texte = texte_backend($texte);
1313 1313
 	$texte = str_replace(array("'", '"'), array('&#039;', '&#034;'), $texte);
@@ -1336,7 +1336,7 @@  discard block
 block discarded – undo
1336 1336
 	# un message pour abs_url
1337 1337
 	$GLOBALS['mode_abs_url'] = 'url';
1338 1338
 	$url = trim($url);
1339
-	$r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS';
1339
+	$r = ",^(?:"._PROTOCOLES_STD.'):?/?/?$,iS';
1340 1340
 
1341 1341
 	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1342 1342
 }
@@ -1538,14 +1538,14 @@  discard block
 block discarded – undo
1538 1538
 	if (strpos($texte, "<") !== false) {
1539 1539
 		include_spip('inc/lien');
1540 1540
 		if (defined('_PREG_MODELE')) {
1541
-			$preg_modeles = "@" . _PREG_MODELE . "@imsS";
1541
+			$preg_modeles = "@"._PREG_MODELE."@imsS";
1542 1542
 			$texte = echappe_html($texte, '', true, $preg_modeles);
1543 1543
 		}
1544 1544
 	}
1545 1545
 
1546 1546
 	$debut = '';
1547 1547
 	$suite = $texte;
1548
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1548
+	while ($t = strpos('-'.$suite, "\n", 1)) {
1549 1549
 		$debut .= substr($suite, 0, $t - 1);
1550 1550
 		$suite = substr($suite, $t);
1551 1551
 		$car = substr($suite, 0, 1);
@@ -1562,11 +1562,11 @@  discard block
 block discarded – undo
1562 1562
 			$suite = substr($suite, strlen($regs[0]));
1563 1563
 		}
1564 1564
 	}
1565
-	$texte = $debut . $suite;
1565
+	$texte = $debut.$suite;
1566 1566
 
1567 1567
 	$texte = echappe_retour($texte);
1568 1568
 
1569
-	return $texte . $fin;
1569
+	return $texte.$fin;
1570 1570
 }
1571 1571
 
1572 1572
 
@@ -1627,7 +1627,7 @@  discard block
 block discarded – undo
1627 1627
 		}
1628 1628
 
1629 1629
 		foreach ($regs as $reg) {
1630
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1630
+			$cle = ($reg[1] ? $reg[1].':' : '').$reg[2];
1631 1631
 			$desc = $traduire($cle, $lang, true);
1632 1632
 			$l = $desc->langue;
1633 1633
 			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
@@ -1740,9 +1740,9 @@  discard block
 block discarded – undo
1740 1740
 					// il ne faut pas echapper en div si propre produit un seul paragraphe
1741 1741
 					include_spip('inc/texte');
1742 1742
 					$trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad));
1743
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1743
+					$mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1744 1744
 					if ($mode === 'div') {
1745
-						$trad = rtrim($trad) . "\n\n";
1745
+						$trad = rtrim($trad)."\n\n";
1746 1746
 					}
1747 1747
 					$trad = code_echappement($trad, 'multi', false, $mode);
1748 1748
 					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
@@ -1936,7 +1936,7 @@  discard block
 block discarded – undo
1936 1936
 	if (is_array($balise)) {
1937 1937
 		array_walk(
1938 1938
 			$balise,
1939
-			function(&$a, $key, $t){
1939
+			function(&$a, $key, $t) {
1940 1940
 				$a = extraire_attribut($a, $t);
1941 1941
 			},
1942 1942
 			$attribut
@@ -2023,14 +2023,14 @@  discard block
 block discarded – undo
2023 2023
 
2024 2024
 	if ($old !== null) {
2025 2025
 		// Remplacer l'ancien attribut du meme nom
2026
-		$balise = $r[1] . $insert . $r[5];
2026
+		$balise = $r[1].$insert.$r[5];
2027 2027
 	} else {
2028 2028
 		// preferer une balise " />" (comme <img />)
2029 2029
 		if (preg_match(',/>,', $balise)) {
2030
-			$balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1);
2030
+			$balise = preg_replace(",\s?/>,S", $insert." />", $balise, 1);
2031 2031
 		} // sinon une balise <a ...> ... </a>
2032 2032
 		else {
2033
-			$balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1);
2033
+			$balise = preg_replace(",\s?>,S", $insert.">", $balise, 1);
2034 2034
 		}
2035 2035
 	}
2036 2036
 
@@ -2063,7 +2063,7 @@  discard block
 block discarded – undo
2063 2063
  * @param string $operation
2064 2064
  * @return string
2065 2065
  */
2066
-function modifier_class($balise, $class, $operation='ajouter') {
2066
+function modifier_class($balise, $class, $operation = 'ajouter') {
2067 2067
 	if (is_string($class)) {
2068 2068
 		$class = explode(' ', trim($class));
2069 2069
 	}
@@ -2088,7 +2088,7 @@  discard block
 block discarded – undo
2088 2088
 				}
2089 2089
 				if (in_array($operation, ['ajouter', 'commuter'])
2090 2090
 					and !$is_class_presente) {
2091
-					$class_new = rtrim($class_new) . " " . $c;
2091
+					$class_new = rtrim($class_new)." ".$c;
2092 2092
 				}
2093 2093
 				elseif (in_array($operation, ['supprimer', 'commuter'])
2094 2094
 					and $is_class_presente) {
@@ -2116,7 +2116,7 @@  discard block
 block discarded – undo
2116 2116
  * @param string|array $class
2117 2117
  * @return string
2118 2118
  */
2119
-function ajouter_class($balise, $class){
2119
+function ajouter_class($balise, $class) {
2120 2120
 	return modifier_class($balise, $class, 'ajouter');
2121 2121
 }
2122 2122
 
@@ -2126,7 +2126,7 @@  discard block
 block discarded – undo
2126 2126
  * @param string|array $class
2127 2127
  * @return string
2128 2128
  */
2129
-function supprimer_class($balise, $class){
2129
+function supprimer_class($balise, $class) {
2130 2130
 	return modifier_class($balise, $class, 'supprimer');
2131 2131
 }
2132 2132
 
@@ -2137,7 +2137,7 @@  discard block
 block discarded – undo
2137 2137
  * @param string|array $class
2138 2138
  * @return string
2139 2139
  */
2140
-function commuter_class($balise, $class){
2140
+function commuter_class($balise, $class) {
2141 2141
 	return modifier_class($balise, $class, 'commuter');
2142 2142
 }
2143 2143
 
@@ -2157,8 +2157,8 @@  discard block
 block discarded – undo
2157 2157
 //
2158 2158
 // Quelques fonctions de calcul arithmetique
2159 2159
 //
2160
-function floatstr($a) { return str_replace(',','.',(string)floatval($a)); }
2161
-function strize($f, $a, $b) { return floatstr($f(floatstr($a),floatstr($b))); }
2160
+function floatstr($a) { return str_replace(',', '.', (string) floatval($a)); }
2161
+function strize($f, $a, $b) { return floatstr($f(floatstr($a), floatstr($b))); }
2162 2162
 
2163 2163
 /**
2164 2164
  * Additionne 2 nombres
@@ -2178,7 +2178,7 @@  discard block
 block discarded – undo
2178 2178
 function plus($a, $b) {
2179 2179
 	return $a + $b;
2180 2180
 }
2181
-function strplus($a, $b) {return strize('plus', $a, $b);}
2181
+function strplus($a, $b) {return strize('plus', $a, $b); }
2182 2182
 /**
2183 2183
  * Soustrait 2 nombres
2184 2184
  *
@@ -2197,7 +2197,7 @@  discard block
 block discarded – undo
2197 2197
 function moins($a, $b) {
2198 2198
 	return $a - $b;
2199 2199
 }
2200
-function strmoins($a, $b) {return strize('moins', $a, $b);}
2200
+function strmoins($a, $b) {return strize('moins', $a, $b); }
2201 2201
 
2202 2202
 /**
2203 2203
  * Multiplie 2 nombres
@@ -2218,7 +2218,7 @@  discard block
 block discarded – undo
2218 2218
 function mult($a, $b) {
2219 2219
 	return $a * $b;
2220 2220
 }
2221
-function strmult($a, $b) {return strize('mult', $a, $b);}
2221
+function strmult($a, $b) {return strize('mult', $a, $b); }
2222 2222
 
2223 2223
 /**
2224 2224
  * Divise 2 nombres
@@ -2239,7 +2239,7 @@  discard block
 block discarded – undo
2239 2239
 function div($a, $b) {
2240 2240
 	return $b ? $a / $b : 0;
2241 2241
 }
2242
-function strdiv($a, $b) {return strize('div', $a, $b);}
2242
+function strdiv($a, $b) {return strize('div', $a, $b); }
2243 2243
 
2244 2244
 /**
2245 2245
  * Retourne le modulo 2 nombres
@@ -2280,13 +2280,13 @@  discard block
 block discarded – undo
2280 2280
 	if (!defined('_TAGS_NOM_AUTEUR')) {
2281 2281
 		define('_TAGS_NOM_AUTEUR', '');
2282 2282
 	}
2283
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2283
+	$tags_acceptes = array_unique(explode(',', 'multi,'._TAGS_NOM_AUTEUR));
2284 2284
 	foreach ($tags_acceptes as $tag) {
2285 2285
 		if (strlen($tag)) {
2286
-			$remp1[] = '<' . trim($tag) . '>';
2287
-			$remp1[] = '</' . trim($tag) . '>';
2288
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2289
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2286
+			$remp1[] = '<'.trim($tag).'>';
2287
+			$remp1[] = '</'.trim($tag).'>';
2288
+			$remp2[] = '\x60'.trim($tag).'\x61';
2289
+			$remp2[] = '\x60/'.trim($tag).'\x61';
2290 2290
 		}
2291 2291
 	}
2292 2292
 	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
@@ -2336,7 +2336,7 @@  discard block
 block discarded – undo
2336 2336
 			$s[] = preg_replace(',>[^<]+</a>,S',
2337 2337
 				'>'
2338 2338
 				. http_img_pack('attachment-16.png', $t,
2339
-					'title="' . attribut_html($t) . '"')
2339
+					'title="'.attribut_html($t).'"')
2340 2340
 				. '</a>', $tag);
2341 2341
 		}
2342 2342
 	}
@@ -2397,10 +2397,10 @@  discard block
 block discarded – undo
2397 2397
 	$fichier = basename($url);
2398 2398
 
2399 2399
 	return '<a rel="enclosure"'
2400
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2401
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2402
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2403
-	. '>' . $fichier . '</a>';
2400
+	. ($url ? ' href="'.spip_htmlspecialchars($url).'"' : '')
2401
+	. ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '')
2402
+	. ($length ? ' title="'.spip_htmlspecialchars($length).'"' : '')
2403
+	. '>'.$fichier.'</a>';
2404 2404
 }
2405 2405
 
2406 2406
 /**
@@ -2428,9 +2428,9 @@  discard block
 block discarded – undo
2428 2428
 			} # vieux data
2429 2429
 			$fichier = basename($url);
2430 2430
 			$enclosures[] = '<enclosure'
2431
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2432
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2433
-				. ($length ? ' length="' . $length . '"' : '')
2431
+				. ($url ? ' url="'.spip_htmlspecialchars($url).'"' : '')
2432
+				. ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '')
2433
+				. ($length ? ' length="'.$length.'"' : '')
2434 2434
 				. ' />';
2435 2435
 		}
2436 2436
 	}
@@ -2456,7 +2456,7 @@  discard block
 block discarded – undo
2456 2456
 		if (extraire_attribut($e, 'rel') == 'tag') {
2457 2457
 			$subjects .= '<dc:subject>'
2458 2458
 				. texte_backend(textebrut($e))
2459
-				. '</dc:subject>' . "\n";
2459
+				. '</dc:subject>'."\n";
2460 2460
 		}
2461 2461
 	}
2462 2462
 
@@ -2492,7 +2492,7 @@  discard block
 block discarded – undo
2492 2492
 	if (is_array($texte)) {
2493 2493
 		array_walk(
2494 2494
 			$texte,
2495
-			function(&$a, $key, $t){
2495
+			function(&$a, $key, $t) {
2496 2496
 				$a = extraire_balise($a, $t);
2497 2497
 			},
2498 2498
 			$tag
@@ -2536,7 +2536,7 @@  discard block
 block discarded – undo
2536 2536
 	if (is_array($texte)) {
2537 2537
 		array_walk(
2538 2538
 			$texte,
2539
-			function(&$a, $key, $t){
2539
+			function(&$a, $key, $t) {
2540 2540
 				$a = extraire_balises($a, $t);
2541 2541
 			},
2542 2542
 			$tag
@@ -2662,7 +2662,7 @@  discard block
 block discarded – undo
2662 2662
 		if ($fond != '404') {
2663 2663
 			$contexte = array_shift($p);
2664 2664
 			$contexte['page'] = $fond;
2665
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2665
+			$action = preg_replace('/([?]'.preg_quote($fond).'[^&=]*[0-9]+)(&|$)/', '?&', $action);
2666 2666
 		}
2667 2667
 	}
2668 2668
 	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
@@ -2717,9 +2717,9 @@  discard block
 block discarded – undo
2717 2717
 			. '"'
2718 2718
 			. (is_null($val)
2719 2719
 				? ''
2720
-				: ' value="' . entites_html($val) . '"'
2720
+				: ' value="'.entites_html($val).'"'
2721 2721
 			)
2722
-			. ' type="hidden"' . "\n/>";
2722
+			. ' type="hidden"'."\n/>";
2723 2723
 	}
2724 2724
 
2725 2725
 	return join("", $hidden);
@@ -2830,7 +2830,7 @@  discard block
 block discarded – undo
2830 2830
 	return preg_replace_callback(
2831 2831
 		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2832 2832
 		function($x) use ($path) {
2833
-			return "url('" . suivre_lien($path, $x[1]) . "')";
2833
+			return "url('".suivre_lien($path, $x[1])."')";
2834 2834
 		},
2835 2835
 		$contenu
2836 2836
 	);
@@ -2892,14 +2892,14 @@  discard block
 block discarded – undo
2892 2892
 	) {
2893 2893
 		$distant = true;
2894 2894
 		$cssf = parse_url($css);
2895
-		$cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : "");
2895
+		$cssf = $cssf['path'].($cssf['query'] ? "?".$cssf['query'] : "");
2896 2896
 		$cssf = preg_replace(',[?:&=],', "_", $cssf);
2897 2897
 	} else {
2898 2898
 		$distant = false;
2899 2899
 		$cssf = $css;
2900 2900
 		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2901 2901
 		//propose (rien a faire dans ce cas)
2902
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2902
+		$f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css);
2903 2903
 		if (@file_exists($f)) {
2904 2904
 			return $f;
2905 2905
 		}
@@ -2909,7 +2909,7 @@  discard block
 block discarded – undo
2909 2909
 	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2910 2910
 	$f = $dir_var
2911 2911
 		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2912
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2912
+		. '.'.substr(md5($cssf), 0, 4).'_'.$ndir.'.css';
2913 2913
 
2914 2914
 	// la css peut etre distante (url absolue !)
2915 2915
 	if ($distant) {
@@ -2954,8 +2954,8 @@  discard block
 block discarded – undo
2954 2954
 		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2955 2955
 		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2956 2956
 			$css_direction = substr($css_direction, strlen($dir_var));
2957
-			$src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction;
2958
-			$css_direction = "/@@@@@@/" . $css_direction;
2957
+			$src_faux_abs["/@@@@@@/".$css_direction] = $css_direction;
2958
+			$css_direction = "/@@@@@@/".$css_direction;
2959 2959
 		}
2960 2960
 		$src[] = $regs[0][$k];
2961 2961
 		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
@@ -3004,7 +3004,7 @@  discard block
 block discarded – undo
3004 3004
 
3005 3005
 	$f = basename($css, '.css');
3006 3006
 	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3007
-		. preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3007
+		. preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-".substr(md5("$css-urlabs"), 0, 4)."\\2", $f)
3008 3008
 		. '.css';
3009 3009
 
3010 3010
 	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
@@ -3013,7 +3013,7 @@  discard block
 block discarded – undo
3013 3013
 
3014 3014
 	if ($url_absolue_css == $css) {
3015 3015
 		if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3016
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3016
+			or !lire_fichier(_DIR_RACINE.substr($css, $l), $contenu)
3017 3017
 		) {
3018 3018
 			include_spip('inc/distant');
3019 3019
 			$contenu = recuperer_url($css);
@@ -3125,7 +3125,7 @@  discard block
 block discarded – undo
3125 3125
 	$expression = str_replace("\/", "/", $expression);
3126 3126
 	$expression = str_replace("/", "\/", $expression);
3127 3127
 
3128
-	if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) {
3128
+	if (preg_match('/'.$expression.'/'.$modif, $texte, $r)) {
3129 3129
 		if (isset($r[$capte])) {
3130 3130
 			return $r[$capte];
3131 3131
 		} else {
@@ -3163,7 +3163,7 @@  discard block
 block discarded – undo
3163 3163
 	$expression = str_replace("\/", "/", $expression);
3164 3164
 	$expression = str_replace("/", "\/", $expression);
3165 3165
 
3166
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3166
+	return preg_replace('/'.$expression.'/'.$modif, $replace, $texte);
3167 3167
 }
3168 3168
 
3169 3169
 
@@ -3182,7 +3182,7 @@  discard block
 block discarded – undo
3182 3182
 function traiter_doublons_documents(&$doublons, $letexte) {
3183 3183
 
3184 3184
 	// Verifier dans le texte & les notes (pas beau, helas)
3185
-	$t = $letexte . $GLOBALS['les_notes'];
3185
+	$t = $letexte.$GLOBALS['les_notes'];
3186 3186
 
3187 3187
 	if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3188 3188
 		and preg_match_all(
@@ -3192,7 +3192,7 @@  discard block
 block discarded – undo
3192 3192
 		if (!isset($doublons['documents'])) {
3193 3193
 			$doublons['documents'] = "";
3194 3194
 		}
3195
-		$doublons['documents'] .= "," . join(',', $matches[1]);
3195
+		$doublons['documents'] .= ",".join(',', $matches[1]);
3196 3196
 	}
3197 3197
 
3198 3198
 	return $letexte;
@@ -3249,7 +3249,7 @@  discard block
 block discarded – undo
3249 3249
 	if ($env) {
3250 3250
 		foreach ($env as $i => $j) {
3251 3251
 			if (is_string($j) and !in_array($i, $ignore_params)) {
3252
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3252
+				$texte .= "<param name='".attribut_html($i)."'\n\tvalue='".attribut_html($j)."' />";
3253 3253
 			}
3254 3254
 		}
3255 3255
 	}
@@ -3288,7 +3288,7 @@  discard block
 block discarded – undo
3288 3288
 	if ($env) {
3289 3289
 		foreach ($env as $i => $j) {
3290 3290
 			if (is_string($j) and !in_array($i, $ignore_params)) {
3291
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3291
+				$texte .= attribut_html($i)."='".attribut_html($j)."' ";
3292 3292
 			}
3293 3293
 		}
3294 3294
 	}
@@ -3371,19 +3371,19 @@  discard block
 block discarded – undo
3371 3371
 
3372 3372
 	$img_file = $img;
3373 3373
 	if ($p = strpos($img_file, '?')) {
3374
-		$img_file = substr($img_file,0, $p);
3374
+		$img_file = substr($img_file, 0, $p);
3375 3375
 	}
3376 3376
 	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3377 3377
 		$img_file = chemin_image($img);
3378 3378
 	}
3379 3379
 	else {
3380
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true){
3380
+		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3381 3381
 			// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3382 3382
 			// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3383 3383
 			if (preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3384
-			  and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . "-xx.svg"
3384
+			  and $variante_svg_generique = substr($img_file, 0, -strlen($m[0]))."-xx.svg"
3385 3385
 			  and file_exists($variante_svg_generique)) {
3386
-				if ($variante_svg_size = substr($variante_svg_generique,0,-6) . $m[1] . ".svg" and file_exists($variante_svg_size)) {
3386
+				if ($variante_svg_size = substr($variante_svg_generique, 0, -6).$m[1].".svg" and file_exists($variante_svg_size)) {
3387 3387
 					$img_file = $variante_svg_size;
3388 3388
 				}
3389 3389
 				else {
@@ -3408,7 +3408,7 @@  discard block
 block discarded – undo
3408 3408
 				return "";
3409 3409
 			}
3410 3410
 		}
3411
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3411
+		$atts .= " width='".$largeur."' height='".$hauteur."'";
3412 3412
 	}
3413 3413
 
3414 3414
 	if (file_exists($img_file)) {
@@ -3417,15 +3417,15 @@  discard block
 block discarded – undo
3417 3417
 	if ($alt === false) {
3418 3418
 		$alt = '';
3419 3419
 	}
3420
-	elseif($alt or $alt==='') {
3420
+	elseif ($alt or $alt === '') {
3421 3421
 		$alt = " alt='".attribut_html($alt)."'";
3422 3422
 	}
3423 3423
 	else {
3424 3424
 		$alt = " alt='".attribut_html($title)."'";
3425 3425
 	}
3426 3426
 	return "<img src='$img_file'$alt"
3427
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3428
-	. " " . ltrim($atts)
3427
+	. ($title ? ' title="'.attribut_html($title).'"' : '')
3428
+	. " ".ltrim($atts)
3429 3429
 	. " />";
3430 3430
 }
3431 3431
 
@@ -3437,12 +3437,12 @@  discard block
 block discarded – undo
3437 3437
  * @param string $size
3438 3438
  * @return string
3439 3439
  */
3440
-function http_style_background($img, $att = '', $size=null) {
3441
-	if ($size and is_numeric($size)){
3442
-		$size = trim($size) . "px";
3440
+function http_style_background($img, $att = '', $size = null) {
3441
+	if ($size and is_numeric($size)) {
3442
+		$size = trim($size)."px";
3443 3443
 	}
3444
-	return " style='background" .
3445
-		($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";"
3444
+	return " style='background".
3445
+		($att ? "" : "-image").": url(\"".chemin_image($img)."\")".($att ? (' '.$att) : '').";"
3446 3446
 		. ($size ? "background-size:{$size};" : '')
3447 3447
 		. "'";
3448 3448
 }
@@ -3468,7 +3468,7 @@  discard block
 block discarded – undo
3468 3468
 			$args[] = $maybe_size;
3469 3469
 			$maybe_size = null;
3470 3470
 		}
3471
-		while (count($args)<2) {
3471
+		while (count($args) < 2) {
3472 3472
 			$args[] = null; // default alt or class
3473 3473
 		}
3474 3474
 		$args[] = $maybe_size;
@@ -3478,7 +3478,7 @@  discard block
 block discarded – undo
3478 3478
 
3479 3479
 function helper_filtre_balise_img_svg_size($img, $size) {
3480 3480
 	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3481
-	if (strpos($size, '@') === 0 and substr($size,-1) === 'x') {
3481
+	if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3482 3482
 		$coef = floatval(substr($size, 1, -1));
3483 3483
 		list($h, $w) = taille_image($img);
3484 3484
 		$height = intval(round($h / $coef));
@@ -3533,7 +3533,7 @@  discard block
 block discarded – undo
3533 3533
  * @return string
3534 3534
  *     Code HTML de la balise IMG
3535 3535
  */
3536
-function filtre_balise_img_dist($img, $alt = '', $class = null, $size=null) {
3536
+function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3537 3537
 
3538 3538
 	list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3539 3539
 
@@ -3552,7 +3552,7 @@  discard block
 block discarded – undo
3552 3552
 		}
3553 3553
 	}
3554 3554
 	else {
3555
-		$img = http_img_pack($img, $alt, $class ? " class='" . attribut_html($class) . "'" : '', '',
3555
+		$img = http_img_pack($img, $alt, $class ? " class='".attribut_html($class)."'" : '', '',
3556 3556
 				array('chemin_image' => false, 'utiliser_suffixe_size' => false));
3557 3557
 		if (is_null($alt)) {
3558 3558
 			$img = vider_attribut($img, 'alt');
@@ -3598,16 +3598,16 @@  discard block
 block discarded – undo
3598 3598
  * @return string
3599 3599
  *     Code HTML de la balise SVG
3600 3600
  */
3601
-function filtre_balise_svg_dist($img, $alt = '', $class = null, $size=null) {
3601
+function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3602 3602
 
3603 3603
 	$img = trim($img);
3604 3604
 	$img_file = $img;
3605
-	if (strpos($img, '<svg') === false){
3606
-		if ($p = strpos($img_file, '?')){
3605
+	if (strpos($img, '<svg') === false) {
3606
+		if ($p = strpos($img_file, '?')) {
3607 3607
 			$img_file = substr($img_file, 0, $p);
3608 3608
 		}
3609 3609
 
3610
-		if (!$img_file or !$svg = file_get_contents($img_file)){
3610
+		if (!$img_file or !$svg = file_get_contents($img_file)) {
3611 3611
 			return '';
3612 3612
 		}
3613 3613
 	}
@@ -3622,7 +3622,7 @@  discard block
 block discarded – undo
3622 3622
 	$balise_svg_source = $balise_svg;
3623 3623
 
3624 3624
 	// entete XML à supprimer
3625
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3625
+	$svg = preg_replace(',^\s*<\?xml[^>]*\?'.'>,', '', $svg);
3626 3626
 
3627 3627
 	// IE est toujours mon ami
3628 3628
 	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
@@ -3638,11 +3638,11 @@  discard block
 block discarded – undo
3638 3638
 	}
3639 3639
 
3640 3640
 	// regler le alt
3641
-	if ($alt){
3641
+	if ($alt) {
3642 3642
 		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3643
-		$id = "img-svg-title-" . substr(md5("$img_file:$svg:$alt"),0,4);
3643
+		$id = "img-svg-title-".substr(md5("$img_file:$svg:$alt"), 0, 4);
3644 3644
 		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3645
-		$title = "<title id=\"$id\">" . entites_html($alt)."</title>\n";
3645
+		$title = "<title id=\"$id\">".entites_html($alt)."</title>\n";
3646 3646
 		$balise_svg .= $title;
3647 3647
 	}
3648 3648
 	else {
@@ -3689,7 +3689,7 @@  discard block
 block discarded – undo
3689 3689
 	$texte = '';
3690 3690
 	if (is_array($tableau)) {
3691 3691
 		foreach ($tableau as $k => $v) {
3692
-			$res = recuperer_fond('modeles/' . $modele,
3692
+			$res = recuperer_fond('modeles/'.$modele,
3693 3693
 				array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v)))
3694 3694
 			);
3695 3695
 			$texte .= $res;
@@ -3866,7 +3866,7 @@  discard block
 block discarded – undo
3866 3866
 	}
3867 3867
 
3868 3868
 	$c = serialize($c);
3869
-	$cle = calculer_cle_action($form . $c);
3869
+	$cle = calculer_cle_action($form.$c);
3870 3870
 	$c = "$cle:$c";
3871 3871
 
3872 3872
 	// on ne stocke pas les contextes dans des fichiers en cache
@@ -3923,15 +3923,15 @@  discard block
 block discarded – undo
3923 3923
 	}
3924 3924
 	// toujours encoder l'url source dans le bloc ajax
3925 3925
 	$r = self();
3926
-	$r = ' data-origin="' . $r . '"';
3926
+	$r = ' data-origin="'.$r.'"';
3927 3927
 	$class = 'ajaxbloc';
3928 3928
 	if ($ajaxid and is_string($ajaxid)) {
3929 3929
 		// ajaxid est normalement conforme a un nom de classe css
3930 3930
 		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3931
-		$class .= ' ajax-id-' . entites_html($ajaxid);
3931
+		$class .= ' ajax-id-'.entites_html($ajaxid);
3932 3932
 	}
3933 3933
 
3934
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3934
+	return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3935 3935
 }
3936 3936
 
3937 3937
 /**
@@ -3970,11 +3970,11 @@  discard block
 block discarded – undo
3970 3970
 	// extraire la signature en debut de contexte
3971 3971
 	// et la verifier avant de deserializer
3972 3972
 	// format : signature:donneesserializees
3973
-	if ($p = strpos($c,":")){
3974
-		$cle = substr($c,0,$p);
3975
-		$c = substr($c,$p+1);
3973
+	if ($p = strpos($c, ":")) {
3974
+		$cle = substr($c, 0, $p);
3975
+		$c = substr($c, $p + 1);
3976 3976
 
3977
-		if ($cle == calculer_cle_action($form . $c)) {
3977
+		if ($cle == calculer_cle_action($form.$c)) {
3978 3978
 			$env = @unserialize($c);
3979 3979
 			return $env;
3980 3980
 		}
@@ -4080,24 +4080,24 @@  discard block
 block discarded – undo
4080 4080
 		$att = "";
4081 4081
 		// si $on passe la balise et optionnelement une ou ++classe
4082 4082
 		// a.active span.selected.active etc....
4083
-		if (is_string($on) and (strncmp($on, 'a', 1)==0 or strncmp($on, 'span', 4)==0 or strncmp($on, 'strong', 6)==0)){
4083
+		if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4084 4084
 			$on = explode(".", $on);
4085 4085
 			// on verifie que c'est exactement une des 3 balises a, span ou strong
4086
-			if (in_array(reset($on), array('a', 'span', 'strong'))){
4086
+			if (in_array(reset($on), array('a', 'span', 'strong'))) {
4087 4087
 				$bal = array_shift($on);
4088 4088
 				$class = implode(" ", $on);
4089
-				if ($bal=="a"){
4089
+				if ($bal == "a") {
4090 4090
 					$att = 'href="#" ';
4091 4091
 				}
4092 4092
 			}
4093 4093
 		}
4094
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4094
+		$att .= 'class="'.($class ? attribut_html($class).' ' : '').(defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on').'"';
4095 4095
 	} else {
4096 4096
 		$bal = 'a';
4097 4097
 		$att = "href='$url'"
4098
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4099
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4100
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4098
+			. ($title ? " title='".attribut_html($title)."'" : '')
4099
+			. ($class ? " class='".attribut_html($class)."'" : '')
4100
+			. ($rel ? " rel='".attribut_html($rel)."'" : '')
4101 4101
 			. $evt;
4102 4102
 	}
4103 4103
 	if ($libelle === null) {
@@ -4232,7 +4232,7 @@  discard block
 block discarded – undo
4232 4232
 
4233 4233
 	// Icône
4234 4234
 	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4235
-	$icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "") . "\">$icone</span>";
4235
+	$icone = "<span class=\"icone-image".($fonction ? " icone-fonction icone-fonction-$fonction" : "")."\">$icone</span>";
4236 4236
 
4237 4237
 	// Markup final
4238 4238
 	if ($type == 'lien') {
@@ -4467,7 +4467,7 @@  discard block
 block discarded – undo
4467 4467
 		if (is_array($detail->sousmenu)) {
4468 4468
 			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4469 4469
 				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4470
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}";
4470
+					$res .= "\n$selecteur.bando2_$souspage {background-image:url(".$sousdetail->icone.");}";
4471 4471
 				}
4472 4472
 			}
4473 4473
 		}
@@ -4504,20 +4504,20 @@  discard block
 block discarded – undo
4504 4504
 		$class_form = 'ajax';
4505 4505
 		$class = str_replace('ajax', '', $class);
4506 4506
 	}
4507
-	$class_btn = 'submit ' . trim($class);
4507
+	$class_btn = 'submit '.trim($class);
4508 4508
 
4509 4509
 	if ($confirm) {
4510
-		$confirm = "confirm(\"" . attribut_html($confirm) . "\")";
4510
+		$confirm = "confirm(\"".attribut_html($confirm)."\")";
4511 4511
 		if ($callback) {
4512 4512
 			$callback = "$confirm?($callback):false";
4513 4513
 		} else {
4514 4514
 			$callback = $confirm;
4515 4515
 		}
4516 4516
 	}
4517
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : "";
4517
+	$onclick = $callback ? " onclick='return ".addcslashes($callback, "'")."'" : "";
4518 4518
 	$title = $title ? " title='$title'" : '';
4519 4519
 
4520
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4520
+	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>".form_hidden($url)
4521 4521
 	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4522 4522
 }
4523 4523
 
@@ -4578,14 +4578,14 @@  discard block
 block discarded – undo
4578 4578
 		$champ_titre = "";
4579 4579
 		if ($demande_titre) {
4580 4580
 			// si pas de titre declare mais champ titre, il sera peuple par le select *
4581
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4581
+			$champ_titre = (!empty($desc['titre'])) ? ', '.$desc['titre'] : '';
4582 4582
 		}
4583 4583
 		include_spip('base/abstract_sql');
4584 4584
 		include_spip('base/connect_sql');
4585 4585
 		$objets[$type_objet][$id_objet] = sql_fetsel(
4586
-			'*' . $champ_titre,
4586
+			'*'.$champ_titre,
4587 4587
 			$desc['table_sql'],
4588
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4588
+			id_table_objet($type_objet).' = '.intval($id_objet)
4589 4589
 		);
4590 4590
 	}
4591 4591
 
@@ -4655,7 +4655,7 @@  discard block
 block discarded – undo
4655 4655
 		return $texte;
4656 4656
 	}
4657 4657
 
4658
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4658
+	$traitement = str_replace('%s', "'".texte_script($texte)."'", $traitement);
4659 4659
 
4660 4660
 	// Fournir $connect et $Pile[0] au traitement si besoin
4661 4661
 	$Pile = array(0 => $env);
@@ -4689,7 +4689,7 @@  discard block
 block discarded – undo
4689 4689
 	}
4690 4690
 	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4691 4691
 
4692
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>";
4692
+	return "<a href='$url' class='$objet'>".couper($titre, $longueur)."</a>";
4693 4693
 }
4694 4694
 
4695 4695
 
@@ -4708,10 +4708,10 @@  discard block
 block discarded – undo
4708 4708
 function wrap($texte, $wrap) {
4709 4709
 	$balises = extraire_balises($wrap);
4710 4710
 	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4711
-		$texte = $wrap . $texte;
4711
+		$texte = $wrap.$texte;
4712 4712
 		$regs = array_reverse($regs[1]);
4713
-		$wrap = "</" . implode("></", $regs) . ">";
4714
-		$texte = $texte . $wrap;
4713
+		$wrap = "</".implode("></", $regs).">";
4714
+		$texte = $texte.$wrap;
4715 4715
 	}
4716 4716
 
4717 4717
 	return $texte;
@@ -4742,7 +4742,7 @@  discard block
 block discarded – undo
4742 4742
 
4743 4743
 	// caster $u en array si besoin
4744 4744
 	if (is_object($u)) {
4745
-		$u = (array)$u;
4745
+		$u = (array) $u;
4746 4746
 	}
4747 4747
 
4748 4748
 	if (is_array($u)) {
@@ -4763,7 +4763,7 @@  discard block
 block discarded – undo
4763 4763
 		// sinon on passe a la ligne et on indente
4764 4764
 		$i_str = str_pad("", $indent, " ");
4765 4765
 		foreach ($u as $k => $v) {
4766
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4766
+			$out .= $join.$i_str."$k: ".filtre_print_dist($v, $join, $indent + 2);
4767 4767
 		}
4768 4768
 
4769 4769
 		return $out;
@@ -4816,8 +4816,8 @@  discard block
 block discarded – undo
4816 4816
  * @param string $class
4817 4817
  * @return string
4818 4818
  */
4819
-function objet_icone($objet, $taille = 24, $class='') {
4820
-	$icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png";
4819
+function objet_icone($objet, $taille = 24, $class = '') {
4820
+	$icone = objet_info($objet, 'icone_objet')."-".$taille.".png";
4821 4821
 	$icone = chemin_image($icone);
4822 4822
 	$balise_img = charger_filtre('balise_img');
4823 4823
 
@@ -4841,12 +4841,12 @@  discard block
 block discarded – undo
4841 4841
  * @param array $options
4842 4842
  * @return string
4843 4843
  */
4844
-function objet_T($objet, $chaine, $args = array(), $options = array()){
4845
-	$chaine = explode(':',$chaine);
4846
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) {
4844
+function objet_T($objet, $chaine, $args = array(), $options = array()) {
4845
+	$chaine = explode(':', $chaine);
4846
+	if ($t = _T($objet.':'.end($chaine), $args, array_merge($options, array('force'=>false)))) {
4847 4847
 		return $t;
4848 4848
 	}
4849
-	$chaine = implode(':',$chaine);
4849
+	$chaine = implode(':', $chaine);
4850 4850
 	return _T($chaine, $args, $options);
4851 4851
 }
4852 4852
 
@@ -4906,7 +4906,7 @@  discard block
 block discarded – undo
4906 4906
 	$cache = recuperer_fond($fond, $contexte, $options, $connect);
4907 4907
 
4908 4908
 	// calculer le nom de la css
4909
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4909
+	$dir_var = sous_repertoire(_DIR_VAR, 'cache-'.$extension);
4910 4910
 	$nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond));
4911 4911
 	$contexte_implicite = calculer_contexte_implicite();
4912 4912
 
@@ -4914,22 +4914,22 @@  discard block
 block discarded – undo
4914 4914
 	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4915 4915
 	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4916 4916
 	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
4917
-		$hash = md5($contexte_implicite['host'] . '::'. $cache);
4917
+		$hash = md5($contexte_implicite['host'].'::'.$cache);
4918 4918
 	}
4919 4919
 	else {
4920 4920
 		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4921 4921
 		ksort($contexte);
4922
-		$hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect);
4922
+		$hash = md5($fond.json_encode($contexte_implicite).json_encode($contexte).$connect);
4923 4923
 	}
4924
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4924
+	$filename = $dir_var.$extension."dyn-$nom_safe-".substr($hash, 0, 8).".$extension";
4925 4925
 
4926 4926
 	// mettre a jour le fichier si il n'existe pas
4927 4927
 	// ou trop ancien
4928 4928
 	// le dernier fichier produit est toujours suffixe par .last
4929 4929
 	// et recopie sur le fichier cible uniquement si il change
4930 4930
 	if (!file_exists($filename)
4931
-		or !file_exists($filename . ".last")
4932
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified'])
4931
+		or !file_exists($filename.".last")
4932
+		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename.".last") < $cache['lastmodified'])
4933 4933
 		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
4934 4934
 	) {
4935 4935
 		$contenu = $cache['texte'];
@@ -4948,10 +4948,10 @@  discard block
 block discarded – undo
4948 4948
 			}
4949 4949
 			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
4950 4950
 			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
4951
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
4951
+			$comment .= "}\n   md5:".md5($contenu)." */\n";
4952 4952
 		}
4953 4953
 		// et ecrire le fichier si il change
4954
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
4954
+		ecrire_fichier_calcule_si_modifie($filename, $comment.$contenu, false, true);
4955 4955
 	}
4956 4956
 
4957 4957
 	return timestamp($filename);
@@ -5146,11 +5146,11 @@  discard block
 block discarded – undo
5146 5146
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
5147 5147
 	$l = strlen($passe);
5148 5148
 
5149
-	if ($l<=8 or !$afficher_partiellement){
5149
+	if ($l <= 8 or !$afficher_partiellement) {
5150 5150
 		if (!$l) {
5151 5151
 			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5152 5152
 		}
5153
-		return str_pad('',$afficher_partiellement ? $l : 16,'*');
5153
+		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5154 5154
 	}
5155 5155
 
5156 5156
 	if (is_null($portion_pourcent)) {
@@ -5164,11 +5164,11 @@  discard block
 block discarded – undo
5164 5164
 	}
5165 5165
 	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5166 5166
 	$e = max($e, 0);
5167
-	$mid = str_pad('',$l-2*$e,'*');
5168
-	if ($e>0 and strlen($mid)>8){
5167
+	$mid = str_pad('', $l - 2 * $e, '*');
5168
+	if ($e > 0 and strlen($mid) > 8) {
5169 5169
 		$mid = '***...***';
5170 5170
 	}
5171
-	return substr($passe,0,$e) . $mid . ($e > 0 ? substr($passe,-$e) : '');
5171
+	return substr($passe, 0, $e).$mid.($e > 0 ? substr($passe, -$e) : '');
5172 5172
 }
5173 5173
 
5174 5174
 
@@ -5190,9 +5190,9 @@  discard block
 block discarded – undo
5190 5190
 function identifiant_slug($texte, $type = '', $options = array()) {
5191 5191
 
5192 5192
 	$original = $texte;
5193
-	$separateur = (isset($options['separateur'])?$options['separateur']:'_');
5194
-	$longueur_maxi = (isset($options['longueur_maxi'])?$options['longueur_maxi']:60);
5195
-	$longueur_mini = (isset($options['longueur_mini'])?$options['longueur_mini']:0);
5193
+	$separateur = (isset($options['separateur']) ? $options['separateur'] : '_');
5194
+	$longueur_maxi = (isset($options['longueur_maxi']) ? $options['longueur_maxi'] : 60);
5195
+	$longueur_mini = (isset($options['longueur_mini']) ? $options['longueur_mini'] : 0);
5196 5196
 
5197 5197
 	if (!function_exists('translitteration')) {
5198 5198
 		include_spip('inc/charsets');
@@ -5234,15 +5234,15 @@  discard block
 block discarded – undo
5234 5234
 			}
5235 5235
 	}
5236 5236
 
5237
-	if (strlen($texte)>$longueur_maxi) {
5237
+	if (strlen($texte) > $longueur_maxi) {
5238 5238
 		$texte = substr($texte, 0, $longueur_maxi);
5239 5239
 	}
5240 5240
 
5241 5241
 	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5242 5242
 		if (preg_match(',^\d,', $texte)) {
5243
-			$texte = ($type ? substr($type,0,1) : "s") . $texte;
5243
+			$texte = ($type ? substr($type, 0, 1) : "s").$texte;
5244 5244
 		}
5245
-		$texte .= $separateur . md5($original);
5245
+		$texte .= $separateur.md5($original);
5246 5246
 		$texte = substr($texte, 0, $longueur_mini);
5247 5247
 	}
5248 5248
 
Please login to merge, or discard this patch.
ecrire/inc/filtres_mime.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
  **/
23 23
 
24 24
 if (!defined('_ECRIRE_INC_VERSION')) {
25
-	return;
25
+    return;
26 26
 }
27 27
 include_spip('inc/filtres');
28 28
 
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
  * @return string Rien.
40 40
  **/
41 41
 function filtre_image_dist($t) {
42
-	return '';
42
+    return '';
43 43
 }
44 44
 
45 45
 /**
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
  * @return string Rien.
53 53
  **/
54 54
 function filtre_audio_dist($t) {
55
-	return '';
55
+    return '';
56 56
 }
57 57
 
58 58
 /**
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
  * @return string Rien.
66 66
  **/
67 67
 function filtre_video_dist($t) {
68
-	return '';
68
+    return '';
69 69
 }
70 70
 
71 71
 /**
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
  * @return string Rien.
79 79
  **/
80 80
 function filtre_application_dist($t) {
81
-	return '';
81
+    return '';
82 82
 }
83 83
 
84 84
 /**
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
  * @return string Rien.
92 92
  **/
93 93
 function filtre_message_dist($t) {
94
-	return '';
94
+    return '';
95 95
 }
96 96
 
97 97
 /**
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
  * @return string Rien.
105 105
  **/
106 106
 function filtre_multipart_dist($t) {
107
-	return '';
107
+    return '';
108 108
 }
109 109
 
110 110
 /**
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
  * @return string Contenu échappé.
118 118
  **/
119 119
 function filtre_text_dist($t) {
120
-	static $t1 = array('&', '<', '>');
121
-	static $t2 = array('&amp;', '&lt;', '&gt;');
120
+    static $t1 = array('&', '<', '>');
121
+    static $t2 = array('&amp;', '&lt;', '&gt;');
122 122
 
123
-	return '<pre>' . str_replace($t1, $t2, $t) . '</pre>';
123
+    return '<pre>' . str_replace($t1, $t2, $t) . '</pre>';
124 124
 }
125 125
 
126 126
 /**
@@ -135,21 +135,21 @@  discard block
 block discarded – undo
135 135
  *     Tableau (formaté en SPIP)
136 136
  **/
137 137
 function filtre_text_csv_dist($t) {
138
-	include_spip('inc/csv');
139
-	list($entete, $lignes, $caption) = analyse_csv($t);
140
-	foreach ($lignes as &$l) {
141
-		$l = join('|', $l);
142
-	}
143
-	$corps = join("\n", $lignes) . "\n";
144
-	$corps = $caption .
145
-		"\n|{{" .
146
-		join('}}|{{', $entete) .
147
-		'}}|' .
148
-		"\n|" .
149
-		str_replace("\n", "|\n|", $corps);
150
-	include_spip('inc/texte');
151
-
152
-	return propre($corps);
138
+    include_spip('inc/csv');
139
+    list($entete, $lignes, $caption) = analyse_csv($t);
140
+    foreach ($lignes as &$l) {
141
+        $l = join('|', $l);
142
+    }
143
+    $corps = join("\n", $lignes) . "\n";
144
+    $corps = $caption .
145
+        "\n|{{" .
146
+        join('}}|{{', $entete) .
147
+        '}}|' .
148
+        "\n|" .
149
+        str_replace("\n", "|\n|", $corps);
150
+    include_spip('inc/texte');
151
+
152
+    return propre($corps);
153 153
 }
154 154
 
155 155
 /**
@@ -163,33 +163,33 @@  discard block
 block discarded – undo
163 163
  * @return string Code html sécurisé ou texte échappé
164 164
  **/
165 165
 function filtre_text_html_dist($t) {
166
-	if (!preg_match(',^(.*?)<body[^>]*>(.*)</body>,is', $t, $r)) {
167
-		return appliquer_filtre($t, 'text/plain');
168
-	}
169
-
170
-	list(, $h, $t) = $r;
171
-
172
-	$style = '';
173
-	// recuperer les styles internes
174
-	if (preg_match_all(',<style>(.*?)</style>,is', $h, $r, PREG_PATTERN_ORDER)) {
175
-		$style = join("\n", $r[1]);
176
-	}
177
-	// ... et externes
178
-
179
-	include_spip('inc/distant');
180
-	if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) {
181
-		foreach ($r[0] as $l) {
182
-			preg_match("/href='([^']*)'/", str_replace('"', "'", $l), $m);
183
-			$page = recuperer_url($m[1]);
184
-			$page = $page['page'] ?? '';
185
-			$style .= "\n/* $l */\n"
186
-				. str_replace('<', '', $page);
187
-		}
188
-	}
189
-	// Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ?
190
-	$t = safehtml(preg_replace(',<script' . '.*?</script>,is', '', $t));
191
-
192
-	return (!$style ? '' : "\n<style>" . $style . '</style>') . $t;
166
+    if (!preg_match(',^(.*?)<body[^>]*>(.*)</body>,is', $t, $r)) {
167
+        return appliquer_filtre($t, 'text/plain');
168
+    }
169
+
170
+    list(, $h, $t) = $r;
171
+
172
+    $style = '';
173
+    // recuperer les styles internes
174
+    if (preg_match_all(',<style>(.*?)</style>,is', $h, $r, PREG_PATTERN_ORDER)) {
175
+        $style = join("\n", $r[1]);
176
+    }
177
+    // ... et externes
178
+
179
+    include_spip('inc/distant');
180
+    if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) {
181
+        foreach ($r[0] as $l) {
182
+            preg_match("/href='([^']*)'/", str_replace('"', "'", $l), $m);
183
+            $page = recuperer_url($m[1]);
184
+            $page = $page['page'] ?? '';
185
+            $style .= "\n/* $l */\n"
186
+                . str_replace('<', '', $page);
187
+        }
188
+    }
189
+    // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ?
190
+    $t = safehtml(preg_replace(',<script' . '.*?</script>,is', '', $t));
191
+
192
+    return (!$style ? '' : "\n<style>" . $style . '</style>') . $t;
193 193
 }
194 194
 
195 195
 /**
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
  * @return string Code HTML des balises `<param>`
203 203
  **/
204 204
 function filtre_audio_x_pn_realaudio($id) {
205
-	return "
205
+    return "
206 206
 	<param name='controls' value='PositionSlider' />
207 207
 	<param name='controls' value='ImageWindow' />
208 208
 	<param name='controls' value='PlayButton' />
Please login to merge, or discard this patch.
ecrire/inc/xml.php 1 patch
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -47,24 +47,24 @@  discard block
 block discarded – undo
47 47
  *     - false si l'arbre xml ne peut être créé ou est vide
48 48
  **/
49 49
 function spip_xml_load($fichier, $strict = true, $clean = true, $taille_max = 1048576, $datas = '', $profondeur = -1) {
50
-	$contenu = "";
51
-	if (tester_url_absolue($fichier)) {
52
-		include_spip('inc/distant');
53
-		$contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]);
54
-		$contenu = $contenu['page'] ?? '';
55
-	} else {
56
-		lire_fichier($fichier, $contenu);
57
-	}
58
-	$arbre = array();
59
-	if ($contenu) {
60
-		$arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur);
61
-	}
50
+    $contenu = "";
51
+    if (tester_url_absolue($fichier)) {
52
+        include_spip('inc/distant');
53
+        $contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]);
54
+        $contenu = $contenu['page'] ?? '';
55
+    } else {
56
+        lire_fichier($fichier, $contenu);
57
+    }
58
+    $arbre = array();
59
+    if ($contenu) {
60
+        $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur);
61
+    }
62 62
 
63
-	return count($arbre) ? $arbre : false;
63
+    return count($arbre) ? $arbre : false;
64 64
 }
65 65
 
66 66
 if (!defined('_SPIP_XML_TAG_SPLIT')) {
67
-	define('_SPIP_XML_TAG_SPLIT', "{<([^:>][^>]*?)>}sS");
67
+    define('_SPIP_XML_TAG_SPLIT', "{<([^:>][^>]*?)>}sS");
68 68
 }
69 69
 
70 70
 /**
@@ -83,150 +83,150 @@  discard block
 block discarded – undo
83 83
  *     - false si l'arbre xml ne peut être créé ou est vide
84 84
  **/
85 85
 function spip_xml_parse(&$texte, $strict = true, $clean = true, $profondeur = -1) {
86
-	$out = array();
87
-	// enlever les commentaires
88
-	$charset = 'AUTO';
89
-	if ($clean === true) {
90
-		if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) {
91
-			$charset = $regs[2];
92
-		}
93
-		$texte = preg_replace(',<!--(.*?)-->,is', '', $texte);
94
-		$texte = preg_replace(',<\?(.*?)\?>,is', '', $texte);
95
-		include_spip('inc/charsets');
96
-		$clean = $charset;
97
-		//$texte = importer_charset($texte,$charset);
98
-	}
99
-	if (is_string($clean)) {
100
-		$charset = $clean;
101
-	}
102
-	$txt = $texte;
86
+    $out = array();
87
+    // enlever les commentaires
88
+    $charset = 'AUTO';
89
+    if ($clean === true) {
90
+        if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) {
91
+            $charset = $regs[2];
92
+        }
93
+        $texte = preg_replace(',<!--(.*?)-->,is', '', $texte);
94
+        $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte);
95
+        include_spip('inc/charsets');
96
+        $clean = $charset;
97
+        //$texte = importer_charset($texte,$charset);
98
+    }
99
+    if (is_string($clean)) {
100
+        $charset = $clean;
101
+    }
102
+    $txt = $texte;
103 103
 
104
-	// tant qu'il y a des tags
105
-	$chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE);
106
-	while (count($chars) >= 2) {
107
-		// tag ouvrant
108
-		//$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE);
104
+    // tant qu'il y a des tags
105
+    $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE);
106
+    while (count($chars) >= 2) {
107
+        // tag ouvrant
108
+        //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE);
109 109
 
110
-		// $before doit etre vide ou des espaces uniquements!
111
-		$before = trim($chars[0]);
110
+        // $before doit etre vide ou des espaces uniquements!
111
+        $before = trim($chars[0]);
112 112
 
113
-		if (strlen($before) > 0) {
114
-			return importer_charset($texte, $charset);
115
-		}//$texte; // before non vide, donc on est dans du texte
113
+        if (strlen($before) > 0) {
114
+            return importer_charset($texte, $charset);
115
+        }//$texte; // before non vide, donc on est dans du texte
116 116
 
117
-		$tag = rtrim($chars[1]);
118
-		$txt = $chars[2];
117
+        $tag = rtrim($chars[1]);
118
+        $txt = $chars[2];
119 119
 
120
-		if (strncmp($tag, '![CDATA[', 8) == 0) {
121
-			return importer_charset($texte, $charset);
122
-		}//$texte;
123
-		if (substr($tag, -1) == '/') { // self closing tag
124
-			$tag = rtrim(substr($tag, 0, strlen($tag) - 1));
125
-			$out[$tag][] = "";
126
-		} else {
127
-			$closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag));
128
-			$closing_tag = reset($closing_tag);
129
-			// tag fermant
130
-			$ncclos = strlen("</$closing_tag>");
131
-			$p = strpos($txt, "</$closing_tag>");
132
-			if ($p !== false and (strpos($txt, "<") < $p)) {
133
-				$nclose = 0;
134
-				$nopen = 0;
135
-				$d = 0;
136
-				while (
137
-					$p !== false
138
-					and ($morceau = substr($txt, $d, $p - $d))
139
-					and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau,
140
-							$matches, PREG_SET_ORDER)) > $nclose)
141
-				) {
142
-					$nclose++;
143
-					$d = $p + $ncclos;
144
-					$p = strpos($txt, "</$closing_tag>", $d);
145
-				}
146
-			}
147
-			if ($p === false) {
148
-				if ($strict) {
149
-					$out[$tag][] = "erreur : tag fermant $tag manquant::$txt";
120
+        if (strncmp($tag, '![CDATA[', 8) == 0) {
121
+            return importer_charset($texte, $charset);
122
+        }//$texte;
123
+        if (substr($tag, -1) == '/') { // self closing tag
124
+            $tag = rtrim(substr($tag, 0, strlen($tag) - 1));
125
+            $out[$tag][] = "";
126
+        } else {
127
+            $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag));
128
+            $closing_tag = reset($closing_tag);
129
+            // tag fermant
130
+            $ncclos = strlen("</$closing_tag>");
131
+            $p = strpos($txt, "</$closing_tag>");
132
+            if ($p !== false and (strpos($txt, "<") < $p)) {
133
+                $nclose = 0;
134
+                $nopen = 0;
135
+                $d = 0;
136
+                while (
137
+                    $p !== false
138
+                    and ($morceau = substr($txt, $d, $p - $d))
139
+                    and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau,
140
+                            $matches, PREG_SET_ORDER)) > $nclose)
141
+                ) {
142
+                    $nclose++;
143
+                    $d = $p + $ncclos;
144
+                    $p = strpos($txt, "</$closing_tag>", $d);
145
+                }
146
+            }
147
+            if ($p === false) {
148
+                if ($strict) {
149
+                    $out[$tag][] = "erreur : tag fermant $tag manquant::$txt";
150 150
 
151
-					return $out;
152
-				} else {
153
-					return importer_charset($texte, $charset);
154
-				}//$texte // un tag qui constitue du texte a reporter dans $before
155
-			}
156
-			$content = substr($txt, 0, $p);
157
-			$txt = substr($txt, $p + $ncclos);
158
-			if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile
159
-			{
160
-				$out[$tag][] = importer_charset($content, $charset);
161
-			}//$content;
162
-			else {
163
-				$out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1);
164
-			}
165
-		}
166
-		$chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE);
167
-	}
168
-	if (count($out) && (strlen(trim($txt)) == 0)) {
169
-		return $out;
170
-	} else {
171
-		return importer_charset($texte, $charset);
172
-	}//$texte;
151
+                    return $out;
152
+                } else {
153
+                    return importer_charset($texte, $charset);
154
+                }//$texte // un tag qui constitue du texte a reporter dans $before
155
+            }
156
+            $content = substr($txt, 0, $p);
157
+            $txt = substr($txt, $p + $ncclos);
158
+            if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile
159
+            {
160
+                $out[$tag][] = importer_charset($content, $charset);
161
+            }//$content;
162
+            else {
163
+                $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1);
164
+            }
165
+        }
166
+        $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE);
167
+    }
168
+    if (count($out) && (strlen(trim($txt)) == 0)) {
169
+        return $out;
170
+    } else {
171
+        return importer_charset($texte, $charset);
172
+    }//$texte;
173 173
 }
174 174
 
175 175
 // https://code.spip.net/@spip_xml_aplatit
176 176
 function spip_xml_aplatit($arbre, $separateur = " ") {
177
-	$s = "";
178
-	if (is_array($arbre)) {
179
-		foreach ($arbre as $tag => $feuille) {
180
-			if (is_array($feuille)) {
181
-				if ($tag !== intval($tag)) {
182
-					$f = spip_xml_aplatit($feuille, $separateur);
183
-					if (strlen($f)) {
184
-						$tagf = explode(" ", $tag);
185
-						$tagf = $tagf[0];
186
-						$s .= "<$tag>$f</$tagf>";
187
-					} else {
188
-						$s .= "<$tag />";
189
-					}
190
-				} else {
191
-					$s .= spip_xml_aplatit($feuille);
192
-				}
193
-				$s .= $separateur;
194
-			} else {
195
-				$s .= "$feuille$separateur";
196
-			}
197
-		}
198
-	}
177
+    $s = "";
178
+    if (is_array($arbre)) {
179
+        foreach ($arbre as $tag => $feuille) {
180
+            if (is_array($feuille)) {
181
+                if ($tag !== intval($tag)) {
182
+                    $f = spip_xml_aplatit($feuille, $separateur);
183
+                    if (strlen($f)) {
184
+                        $tagf = explode(" ", $tag);
185
+                        $tagf = $tagf[0];
186
+                        $s .= "<$tag>$f</$tagf>";
187
+                    } else {
188
+                        $s .= "<$tag />";
189
+                    }
190
+                } else {
191
+                    $s .= spip_xml_aplatit($feuille);
192
+                }
193
+                $s .= $separateur;
194
+            } else {
195
+                $s .= "$feuille$separateur";
196
+            }
197
+        }
198
+    }
199 199
 
200
-	return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s;
200
+    return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s;
201 201
 }
202 202
 
203 203
 // https://code.spip.net/@spip_xml_tagname
204 204
 function spip_xml_tagname($tag) {
205
-	if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) {
206
-		return $reg[1];
207
-	}
205
+    if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) {
206
+        return $reg[1];
207
+    }
208 208
 
209
-	return "";
209
+    return "";
210 210
 }
211 211
 
212 212
 // https://code.spip.net/@spip_xml_decompose_tag
213 213
 function spip_xml_decompose_tag($tag) {
214
-	$tagname = spip_xml_tagname($tag);
215
-	$liste = array();
216
-	$tag = ltrim(strpbrk($tag, " \n\t"));
217
-	$p = strpos($tag, '=');
218
-	while ($p !== false) {
219
-		$attr = trim(substr($tag, 0, $p));
220
-		$tag = ltrim(substr($tag, $p + 1));
221
-		$quote = $tag[0];
222
-		$p = strpos($tag, $quote, 1);
223
-		$cont = substr($tag, 1, $p - 1);
224
-		$liste[$attr] = $cont;
225
-		$tag = substr($tag, $p + 1);
226
-		$p = strpos($tag, '=');
227
-	}
214
+    $tagname = spip_xml_tagname($tag);
215
+    $liste = array();
216
+    $tag = ltrim(strpbrk($tag, " \n\t"));
217
+    $p = strpos($tag, '=');
218
+    while ($p !== false) {
219
+        $attr = trim(substr($tag, 0, $p));
220
+        $tag = ltrim(substr($tag, $p + 1));
221
+        $quote = $tag[0];
222
+        $p = strpos($tag, $quote, 1);
223
+        $cont = substr($tag, 1, $p - 1);
224
+        $liste[$attr] = $cont;
225
+        $tag = substr($tag, $p + 1);
226
+        $p = strpos($tag, '=');
227
+    }
228 228
 
229
-	return array($tagname, $liste);
229
+    return array($tagname, $liste);
230 230
 }
231 231
 
232 232
 /**
@@ -249,21 +249,21 @@  discard block
 block discarded – undo
249 249
  *     false si aucun élément ne valide l'expression régulière, true sinon.
250 250
  **/
251 251
 function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) {
252
-	if ($init) {
253
-		$matches = array();
254
-	}
255
-	if (is_array($arbre) && count($arbre)) {
256
-		foreach (array_keys($arbre) as $tag) {
257
-			if (preg_match($regexp, $tag)) {
258
-				$matches[$tag] = &$arbre[$tag];
259
-			}
260
-			if (is_array($arbre[$tag])) {
261
-				foreach (array_keys($arbre[$tag]) as $occurences) {
262
-					spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false);
263
-				}
264
-			}
265
-		}
266
-	}
252
+    if ($init) {
253
+        $matches = array();
254
+    }
255
+    if (is_array($arbre) && count($arbre)) {
256
+        foreach (array_keys($arbre) as $tag) {
257
+            if (preg_match($regexp, $tag)) {
258
+                $matches[$tag] = &$arbre[$tag];
259
+            }
260
+            if (is_array($arbre[$tag])) {
261
+                foreach (array_keys($arbre[$tag]) as $occurences) {
262
+                    spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false);
263
+                }
264
+            }
265
+        }
266
+    }
267 267
 
268
-	return (count($matches));
268
+    return (count($matches));
269 269
 }
Please login to merge, or discard this patch.
ecrire/iterateur/data.php 1 patch
Indentation   +617 added lines, -617 removed lines patch added patch discarded remove patch
@@ -17,11 +17,11 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 if (!defined('_DATA_SOURCE_MAX_SIZE')) {
24
-	define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576);
24
+    define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576);
25 25
 }
26 26
 
27 27
 
@@ -42,17 +42,17 @@  discard block
 block discarded – undo
42 42
  *     Description de la boucle complétée des champs
43 43
  */
44 44
 function iterateur_DATA_dist($b) {
45
-	$b->iterateur = 'DATA'; # designe la classe d'iterateur
46
-	$b->show = array(
47
-		'field' => array(
48
-			'cle' => 'STRING',
49
-			'valeur' => 'STRING',
50
-			'*' => 'ALL' // Champ joker *
51
-		)
52
-	);
53
-	$b->select[] = '.valeur';
54
-
55
-	return $b;
45
+    $b->iterateur = 'DATA'; # designe la classe d'iterateur
46
+    $b->show = array(
47
+        'field' => array(
48
+            'cle' => 'STRING',
49
+            'valeur' => 'STRING',
50
+            '*' => 'ALL' // Champ joker *
51
+        )
52
+    );
53
+    $b->select[] = '.valeur';
54
+
55
+    return $b;
56 56
 }
57 57
 
58 58
 
@@ -62,506 +62,506 @@  discard block
 block discarded – undo
62 62
  * Pour itérer sur des données quelconques (transformables en tableau)
63 63
  */
64 64
 class IterateurDATA implements Iterator {
65
-	/**
66
-	 * tableau de donnees
67
-	 *
68
-	 * @var array
69
-	 */
70
-	protected $tableau = array();
71
-
72
-	/**
73
-	 * Conditions de filtrage
74
-	 * ie criteres de selection
75
-	 *
76
-	 * @var array
77
-	 */
78
-	protected $filtre = array();
79
-
80
-
81
-	/**
82
-	 * Cle courante
83
-	 *
84
-	 * @var null
85
-	 */
86
-	protected $cle = null;
87
-
88
-	/**
89
-	 * Valeur courante
90
-	 *
91
-	 * @var null
92
-	 */
93
-	protected $valeur = null;
94
-
95
-	/**
96
-	 * Erreur presente ?
97
-	 *
98
-	 * @var bool
99
-	 **/
100
-	public $err = false;
101
-
102
-	/**
103
-	 * Calcul du total des elements
104
-	 *
105
-	 * @var int|null
106
-	 **/
107
-	public $total = null;
108
-
109
-	/**
110
-	 * Constructeur
111
-	 *
112
-	 * @param  $command
113
-	 * @param array $info
114
-	 */
115
-	public function __construct($command, $info = array()) {
116
-		$this->type = 'DATA';
117
-		$this->command = $command;
118
-		$this->info = $info;
119
-
120
-		$this->select($command);
121
-	}
122
-
123
-	/**
124
-	 * Revenir au depart
125
-	 *
126
-	 * @return void
127
-	 */
128
-	public function rewind() {
129
-		reset($this->tableau);
130
-		$this->cle = key($this->tableau);
131
-		$this->valeur = current($this->tableau);
132
-		next($this->tableau);
133
-	}
134
-
135
-	/**
136
-	 * Déclarer les critères exceptions
137
-	 *
138
-	 * @return array
139
-	 */
140
-	public function exception_des_criteres() {
141
-		return array('tableau');
142
-	}
143
-
144
-	/**
145
-	 * Récupérer depuis le cache si possible
146
-	 *
147
-	 * @param string $cle
148
-	 * @return mixed
149
-	 */
150
-	protected function cache_get($cle) {
151
-		if (!$cle) {
152
-			return;
153
-		}
154
-		# utiliser memoization si dispo
155
-		if (!function_exists('cache_get')) {
156
-			return;
157
-		}
158
-
159
-		return cache_get($cle);
160
-	}
161
-
162
-	/**
163
-	 * Stocker en cache si possible
164
-	 *
165
-	 * @param string $cle
166
-	 * @param int $ttl
167
-	 * @param null|mixed $valeur
168
-	 * @return bool
169
-	 */
170
-	protected function cache_set($cle, $ttl, $valeur = null) {
171
-		if (!$cle) {
172
-			return;
173
-		}
174
-		if (is_null($valeur)) {
175
-			$valeur = $this->tableau;
176
-		}
177
-		# utiliser memoization si dispo
178
-		if (!function_exists('cache_set')) {
179
-			return;
180
-		}
181
-
182
-		return cache_set($cle,
183
-			array(
184
-				'data' => $valeur,
185
-				'time' => time(),
186
-				'ttl' => $ttl
187
-			),
188
-			3600 + $ttl);
189
-		# conserver le cache 1h de plus que la validite demandee,
190
-		# pour le cas ou le serveur distant ne reponde plus
191
-	}
192
-
193
-	/**
194
-	 * Aller chercher les données de la boucle DATA
195
-	 *
196
-	 * @throws Exception
197
-	 * @param array $command
198
-	 * @return void
199
-	 */
200
-	protected function select($command) {
201
-
202
-		// l'iterateur DATA peut etre appele en passant (data:type)
203
-		// le type se retrouve dans la commande 'from'
204
-		// dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument
205
-		if (isset($this->command['from'][0])) {
206
-			if (isset($this->command['source']) and is_array($this->command['source'])) {
207
-				array_unshift($this->command['source'], $this->command['sourcemode']);
208
-			}
209
-			$this->command['sourcemode'] = $this->command['from'][0];
210
-		}
211
-
212
-		// cherchons differents moyens de creer le tableau de donnees
213
-		// les commandes connues pour l'iterateur DATA
214
-		// sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...}
215
-
216
-		// {source format, [URL], [arg2]...}
217
-		if (isset($this->command['source'])
218
-			and isset($this->command['sourcemode'])
219
-		) {
220
-			$this->select_source();
221
-		}
222
-
223
-		// Critere {liste X1, X2, X3}
224
-		if (isset($this->command['liste'])) {
225
-			$this->select_liste();
226
-		}
227
-		if (isset($this->command['enum'])) {
228
-			$this->select_enum();
229
-		}
230
-
231
-		// Si a ce stade on n'a pas de table, il y a un bug
232
-		if (!is_array($this->tableau)) {
233
-			$this->err = true;
234
-			spip_log("erreur datasource " . var_export($command, true));
235
-		}
236
-
237
-		// {datapath query.results}
238
-		// extraire le chemin "query.results" du tableau de donnees
239
-		if (!$this->err
240
-			and isset($this->command['datapath'])
241
-			and is_array($this->command['datapath'])
242
-		) {
243
-			$this->select_datapath();
244
-		}
245
-
246
-		// tri {par x}
247
-		if ($this->command['orderby']) {
248
-			$this->select_orderby();
249
-		}
250
-
251
-		// grouper les resultats {fusion /x/y/z} ;
252
-		if ($this->command['groupby']) {
253
-			$this->select_groupby();
254
-		}
255
-
256
-		$this->rewind();
257
-		#var_dump($this->tableau);
258
-	}
259
-
260
-
261
-	/**
262
-	 * Aller chercher les donnees de la boucle DATA
263
-	 * depuis une source
264
-	 * {source format, [URL], [arg2]...}
265
-	 */
266
-	protected function select_source() {
267
-		# un peu crado : avant de charger le cache il faut charger
268
-		# les class indispensables, sinon PHP ne saura pas gerer
269
-		# l'objet en cache ; cf plugins/icalendar
270
-		# perf : pas de fonction table_to_array ! (table est deja un array)
271
-		if (isset($this->command['sourcemode'])
272
-			and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau'))
273
-		) {
274
-			charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true);
275
-		}
276
-
277
-		# le premier argument peut etre un array, une URL etc.
278
-		$src = $this->command['source'][0];
279
-
280
-		# avons-nous un cache dispo ?
281
-		$cle = null;
282
-		if (is_string($src)) {
283
-			$cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true));
284
-		}
285
-
286
-		$cache = $this->cache_get($cle);
287
-		if (isset($this->command['datacache'])) {
288
-			$ttl = intval($this->command['datacache']);
289
-		}
290
-		if ($cache
291
-			and ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl'])
292
-				> time())
293
-			and !(_request('var_mode') === 'recalcul'
294
-				and include_spip('inc/autoriser')
295
-				and autoriser('recalcul')
296
-			)
297
-		) {
298
-			$this->tableau = $cache['data'];
299
-		} else {
300
-			try {
301
-				if (isset($this->command['sourcemode'])
302
-					and in_array($this->command['sourcemode'],
303
-						array('table', 'array', 'tableau'))
304
-				) {
305
-					if (is_array($a = $src)
306
-						or (is_string($a)
307
-							and $a = str_replace('&quot;', '"', $a) # fragile!
308
-							and is_array($a = @unserialize($a)))
309
-					) {
310
-						$this->tableau = $a;
311
-					}
312
-				} else {
313
-					$data = $src;
314
-					if (is_string($src)) { 
315
-						if (tester_url_absolue($src)) {
316
-							include_spip('inc/distant');
317
-							$data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]);
318
-							$data = $data['page'] ?? '';
319
-							if (!$data) {
320
-								throw new Exception("404");
321
-							}
322
-							if (!isset($ttl)) {
323
-								$ttl = 24 * 3600;
324
-							}
325
-						} elseif (@is_dir($src)) {
326
-							$data = $src;
327
-						} elseif (@is_readable($src) && @is_file($src)) {
328
-							$data = spip_file_get_contents($src);
329
-						}
330
-						if (!isset($ttl)) {
331
-							$ttl = 10;
332
-						}
333
-					}
334
-
335
-					if (!$this->err
336
-						and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)
337
-					) {
338
-						$args = $this->command['source'];
339
-						$args[0] = $data;
340
-						if (is_array($a = $data_to_array(...$args))) {
341
-							$this->tableau = $a;
342
-						}
343
-					}
344
-				}
345
-
346
-				if (!is_array($this->tableau)) {
347
-					$this->err = true;
348
-				}
349
-
350
-				if (!$this->err and isset($ttl) and $ttl > 0) {
351
-					$this->cache_set($cle, $ttl);
352
-				}
353
-
354
-			} catch (Exception $e) {
355
-				$e = $e->getMessage();
356
-				$err = sprintf("[%s, %s] $e",
357
-					$src,
358
-					$this->command['sourcemode']);
359
-				erreur_squelette(array($err, array()));
360
-				$this->err = true;
361
-			}
362
-		}
363
-
364
-		# en cas d'erreur, utiliser le cache si encore dispo
365
-		if ($this->err
366
-			and $cache
367
-		) {
368
-			$this->tableau = $cache['data'];
369
-			$this->err = false;
370
-		}
371
-	}
372
-
373
-
374
-	/**
375
-	 * Retourne un tableau donne depuis un critère liste
376
-	 *
377
-	 * Critère `{liste X1, X2, X3}`
378
-	 *
379
-	 * @see critere_DATA_liste_dist()
380
-	 *
381
-	 **/
382
-	protected function select_liste() {
383
-		# s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
384
-		if (!isset($this->command['liste'][1])) {
385
-			if (!is_array($this->command['liste'][0])) {
386
-				$this->command['liste'] = explode(',', $this->command['liste'][0]);
387
-			} else {
388
-				$this->command['liste'] = $this->command['liste'][0];
389
-			}
390
-		}
391
-		$this->tableau = $this->command['liste'];
392
-	}
393
-
394
-	/**
395
-	 * Retourne un tableau donne depuis un critere liste
396
-	 * Critere {enum Xmin, Xmax}
397
-	 *
398
-	 **/
399
-	protected function select_enum() {
400
-		# s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
401
-		if (!isset($this->command['enum'][1])) {
402
-			if (!is_array($this->command['enum'][0])) {
403
-				$this->command['enum'] = explode(',', $this->command['enum'][0]);
404
-			} else {
405
-				$this->command['enum'] = $this->command['enum'][0];
406
-			}
407
-		}
408
-		if (count($this->command['enum']) >= 3) {
409
-			$enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']),
410
-				array_shift($this->command['enum']));
411
-		} else {
412
-			$enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']));
413
-		}
414
-		$this->tableau = $enum;
415
-	}
416
-
417
-
418
-	/**
419
-	 * extraire le chemin "query.results" du tableau de donnees
420
-	 * {datapath query.results}
421
-	 *
422
-	 **/
423
-	protected function select_datapath() {
424
-		$base = reset($this->command['datapath']);
425
-		if (strlen($base = ltrim(trim($base), "/"))) {
426
-			$this->tableau = table_valeur($this->tableau, $base);
427
-			if (!is_array($this->tableau)) {
428
-				$this->tableau = array();
429
-				$this->err = true;
430
-				spip_log("datapath '$base' absent");
431
-			}
432
-		}
433
-	}
434
-
435
-	/**
436
-	 * Ordonner les resultats
437
-	 * {par x}
438
-	 *
439
-	 **/
440
-	protected function select_orderby() {
441
-		$sortfunc = '';
442
-		$aleas = 0;
443
-		foreach ($this->command['orderby'] as $tri) {
444
-			// virer le / initial pour les criteres de la forme {par /xx}
445
-			if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) {
446
-				$r = array_pad($r, 3, null);
447
-
448
-				// tri par cle
449
-				if ($r[1] == 'cle') {
450
-					if (isset($r[2]) and $r[2]) {
451
-						krsort($this->tableau);
452
-					} else {
453
-						ksort($this->tableau);
454
-					}
455
-				} # {par hasard}
456
-				else {
457
-					if ($r[1] == 'hasard') {
458
-						$k = array_keys($this->tableau);
459
-						shuffle($k);
460
-						$v = array();
461
-						foreach ($k as $cle) {
462
-							$v[$cle] = $this->tableau[$cle];
463
-						}
464
-						$this->tableau = $v;
465
-					} else {
466
-						# {par valeur}
467
-						if ($r[1] == 'valeur') {
468
-							$tv = '%s';
469
-						} # {par valeur/xx/yy} ??
470
-						else {
471
-							$tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')';
472
-						}
473
-						$sortfunc .= '
65
+    /**
66
+     * tableau de donnees
67
+     *
68
+     * @var array
69
+     */
70
+    protected $tableau = array();
71
+
72
+    /**
73
+     * Conditions de filtrage
74
+     * ie criteres de selection
75
+     *
76
+     * @var array
77
+     */
78
+    protected $filtre = array();
79
+
80
+
81
+    /**
82
+     * Cle courante
83
+     *
84
+     * @var null
85
+     */
86
+    protected $cle = null;
87
+
88
+    /**
89
+     * Valeur courante
90
+     *
91
+     * @var null
92
+     */
93
+    protected $valeur = null;
94
+
95
+    /**
96
+     * Erreur presente ?
97
+     *
98
+     * @var bool
99
+     **/
100
+    public $err = false;
101
+
102
+    /**
103
+     * Calcul du total des elements
104
+     *
105
+     * @var int|null
106
+     **/
107
+    public $total = null;
108
+
109
+    /**
110
+     * Constructeur
111
+     *
112
+     * @param  $command
113
+     * @param array $info
114
+     */
115
+    public function __construct($command, $info = array()) {
116
+        $this->type = 'DATA';
117
+        $this->command = $command;
118
+        $this->info = $info;
119
+
120
+        $this->select($command);
121
+    }
122
+
123
+    /**
124
+     * Revenir au depart
125
+     *
126
+     * @return void
127
+     */
128
+    public function rewind() {
129
+        reset($this->tableau);
130
+        $this->cle = key($this->tableau);
131
+        $this->valeur = current($this->tableau);
132
+        next($this->tableau);
133
+    }
134
+
135
+    /**
136
+     * Déclarer les critères exceptions
137
+     *
138
+     * @return array
139
+     */
140
+    public function exception_des_criteres() {
141
+        return array('tableau');
142
+    }
143
+
144
+    /**
145
+     * Récupérer depuis le cache si possible
146
+     *
147
+     * @param string $cle
148
+     * @return mixed
149
+     */
150
+    protected function cache_get($cle) {
151
+        if (!$cle) {
152
+            return;
153
+        }
154
+        # utiliser memoization si dispo
155
+        if (!function_exists('cache_get')) {
156
+            return;
157
+        }
158
+
159
+        return cache_get($cle);
160
+    }
161
+
162
+    /**
163
+     * Stocker en cache si possible
164
+     *
165
+     * @param string $cle
166
+     * @param int $ttl
167
+     * @param null|mixed $valeur
168
+     * @return bool
169
+     */
170
+    protected function cache_set($cle, $ttl, $valeur = null) {
171
+        if (!$cle) {
172
+            return;
173
+        }
174
+        if (is_null($valeur)) {
175
+            $valeur = $this->tableau;
176
+        }
177
+        # utiliser memoization si dispo
178
+        if (!function_exists('cache_set')) {
179
+            return;
180
+        }
181
+
182
+        return cache_set($cle,
183
+            array(
184
+                'data' => $valeur,
185
+                'time' => time(),
186
+                'ttl' => $ttl
187
+            ),
188
+            3600 + $ttl);
189
+        # conserver le cache 1h de plus que la validite demandee,
190
+        # pour le cas ou le serveur distant ne reponde plus
191
+    }
192
+
193
+    /**
194
+     * Aller chercher les données de la boucle DATA
195
+     *
196
+     * @throws Exception
197
+     * @param array $command
198
+     * @return void
199
+     */
200
+    protected function select($command) {
201
+
202
+        // l'iterateur DATA peut etre appele en passant (data:type)
203
+        // le type se retrouve dans la commande 'from'
204
+        // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument
205
+        if (isset($this->command['from'][0])) {
206
+            if (isset($this->command['source']) and is_array($this->command['source'])) {
207
+                array_unshift($this->command['source'], $this->command['sourcemode']);
208
+            }
209
+            $this->command['sourcemode'] = $this->command['from'][0];
210
+        }
211
+
212
+        // cherchons differents moyens de creer le tableau de donnees
213
+        // les commandes connues pour l'iterateur DATA
214
+        // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...}
215
+
216
+        // {source format, [URL], [arg2]...}
217
+        if (isset($this->command['source'])
218
+            and isset($this->command['sourcemode'])
219
+        ) {
220
+            $this->select_source();
221
+        }
222
+
223
+        // Critere {liste X1, X2, X3}
224
+        if (isset($this->command['liste'])) {
225
+            $this->select_liste();
226
+        }
227
+        if (isset($this->command['enum'])) {
228
+            $this->select_enum();
229
+        }
230
+
231
+        // Si a ce stade on n'a pas de table, il y a un bug
232
+        if (!is_array($this->tableau)) {
233
+            $this->err = true;
234
+            spip_log("erreur datasource " . var_export($command, true));
235
+        }
236
+
237
+        // {datapath query.results}
238
+        // extraire le chemin "query.results" du tableau de donnees
239
+        if (!$this->err
240
+            and isset($this->command['datapath'])
241
+            and is_array($this->command['datapath'])
242
+        ) {
243
+            $this->select_datapath();
244
+        }
245
+
246
+        // tri {par x}
247
+        if ($this->command['orderby']) {
248
+            $this->select_orderby();
249
+        }
250
+
251
+        // grouper les resultats {fusion /x/y/z} ;
252
+        if ($this->command['groupby']) {
253
+            $this->select_groupby();
254
+        }
255
+
256
+        $this->rewind();
257
+        #var_dump($this->tableau);
258
+    }
259
+
260
+
261
+    /**
262
+     * Aller chercher les donnees de la boucle DATA
263
+     * depuis une source
264
+     * {source format, [URL], [arg2]...}
265
+     */
266
+    protected function select_source() {
267
+        # un peu crado : avant de charger le cache il faut charger
268
+        # les class indispensables, sinon PHP ne saura pas gerer
269
+        # l'objet en cache ; cf plugins/icalendar
270
+        # perf : pas de fonction table_to_array ! (table est deja un array)
271
+        if (isset($this->command['sourcemode'])
272
+            and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau'))
273
+        ) {
274
+            charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true);
275
+        }
276
+
277
+        # le premier argument peut etre un array, une URL etc.
278
+        $src = $this->command['source'][0];
279
+
280
+        # avons-nous un cache dispo ?
281
+        $cle = null;
282
+        if (is_string($src)) {
283
+            $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true));
284
+        }
285
+
286
+        $cache = $this->cache_get($cle);
287
+        if (isset($this->command['datacache'])) {
288
+            $ttl = intval($this->command['datacache']);
289
+        }
290
+        if ($cache
291
+            and ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl'])
292
+                > time())
293
+            and !(_request('var_mode') === 'recalcul'
294
+                and include_spip('inc/autoriser')
295
+                and autoriser('recalcul')
296
+            )
297
+        ) {
298
+            $this->tableau = $cache['data'];
299
+        } else {
300
+            try {
301
+                if (isset($this->command['sourcemode'])
302
+                    and in_array($this->command['sourcemode'],
303
+                        array('table', 'array', 'tableau'))
304
+                ) {
305
+                    if (is_array($a = $src)
306
+                        or (is_string($a)
307
+                            and $a = str_replace('&quot;', '"', $a) # fragile!
308
+                            and is_array($a = @unserialize($a)))
309
+                    ) {
310
+                        $this->tableau = $a;
311
+                    }
312
+                } else {
313
+                    $data = $src;
314
+                    if (is_string($src)) { 
315
+                        if (tester_url_absolue($src)) {
316
+                            include_spip('inc/distant');
317
+                            $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]);
318
+                            $data = $data['page'] ?? '';
319
+                            if (!$data) {
320
+                                throw new Exception("404");
321
+                            }
322
+                            if (!isset($ttl)) {
323
+                                $ttl = 24 * 3600;
324
+                            }
325
+                        } elseif (@is_dir($src)) {
326
+                            $data = $src;
327
+                        } elseif (@is_readable($src) && @is_file($src)) {
328
+                            $data = spip_file_get_contents($src);
329
+                        }
330
+                        if (!isset($ttl)) {
331
+                            $ttl = 10;
332
+                        }
333
+                    }
334
+
335
+                    if (!$this->err
336
+                        and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)
337
+                    ) {
338
+                        $args = $this->command['source'];
339
+                        $args[0] = $data;
340
+                        if (is_array($a = $data_to_array(...$args))) {
341
+                            $this->tableau = $a;
342
+                        }
343
+                    }
344
+                }
345
+
346
+                if (!is_array($this->tableau)) {
347
+                    $this->err = true;
348
+                }
349
+
350
+                if (!$this->err and isset($ttl) and $ttl > 0) {
351
+                    $this->cache_set($cle, $ttl);
352
+                }
353
+
354
+            } catch (Exception $e) {
355
+                $e = $e->getMessage();
356
+                $err = sprintf("[%s, %s] $e",
357
+                    $src,
358
+                    $this->command['sourcemode']);
359
+                erreur_squelette(array($err, array()));
360
+                $this->err = true;
361
+            }
362
+        }
363
+
364
+        # en cas d'erreur, utiliser le cache si encore dispo
365
+        if ($this->err
366
+            and $cache
367
+        ) {
368
+            $this->tableau = $cache['data'];
369
+            $this->err = false;
370
+        }
371
+    }
372
+
373
+
374
+    /**
375
+     * Retourne un tableau donne depuis un critère liste
376
+     *
377
+     * Critère `{liste X1, X2, X3}`
378
+     *
379
+     * @see critere_DATA_liste_dist()
380
+     *
381
+     **/
382
+    protected function select_liste() {
383
+        # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
384
+        if (!isset($this->command['liste'][1])) {
385
+            if (!is_array($this->command['liste'][0])) {
386
+                $this->command['liste'] = explode(',', $this->command['liste'][0]);
387
+            } else {
388
+                $this->command['liste'] = $this->command['liste'][0];
389
+            }
390
+        }
391
+        $this->tableau = $this->command['liste'];
392
+    }
393
+
394
+    /**
395
+     * Retourne un tableau donne depuis un critere liste
396
+     * Critere {enum Xmin, Xmax}
397
+     *
398
+     **/
399
+    protected function select_enum() {
400
+        # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE
401
+        if (!isset($this->command['enum'][1])) {
402
+            if (!is_array($this->command['enum'][0])) {
403
+                $this->command['enum'] = explode(',', $this->command['enum'][0]);
404
+            } else {
405
+                $this->command['enum'] = $this->command['enum'][0];
406
+            }
407
+        }
408
+        if (count($this->command['enum']) >= 3) {
409
+            $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']),
410
+                array_shift($this->command['enum']));
411
+        } else {
412
+            $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']));
413
+        }
414
+        $this->tableau = $enum;
415
+    }
416
+
417
+
418
+    /**
419
+     * extraire le chemin "query.results" du tableau de donnees
420
+     * {datapath query.results}
421
+     *
422
+     **/
423
+    protected function select_datapath() {
424
+        $base = reset($this->command['datapath']);
425
+        if (strlen($base = ltrim(trim($base), "/"))) {
426
+            $this->tableau = table_valeur($this->tableau, $base);
427
+            if (!is_array($this->tableau)) {
428
+                $this->tableau = array();
429
+                $this->err = true;
430
+                spip_log("datapath '$base' absent");
431
+            }
432
+        }
433
+    }
434
+
435
+    /**
436
+     * Ordonner les resultats
437
+     * {par x}
438
+     *
439
+     **/
440
+    protected function select_orderby() {
441
+        $sortfunc = '';
442
+        $aleas = 0;
443
+        foreach ($this->command['orderby'] as $tri) {
444
+            // virer le / initial pour les criteres de la forme {par /xx}
445
+            if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) {
446
+                $r = array_pad($r, 3, null);
447
+
448
+                // tri par cle
449
+                if ($r[1] == 'cle') {
450
+                    if (isset($r[2]) and $r[2]) {
451
+                        krsort($this->tableau);
452
+                    } else {
453
+                        ksort($this->tableau);
454
+                    }
455
+                } # {par hasard}
456
+                else {
457
+                    if ($r[1] == 'hasard') {
458
+                        $k = array_keys($this->tableau);
459
+                        shuffle($k);
460
+                        $v = array();
461
+                        foreach ($k as $cle) {
462
+                            $v[$cle] = $this->tableau[$cle];
463
+                        }
464
+                        $this->tableau = $v;
465
+                    } else {
466
+                        # {par valeur}
467
+                        if ($r[1] == 'valeur') {
468
+                            $tv = '%s';
469
+                        } # {par valeur/xx/yy} ??
470
+                        else {
471
+                            $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')';
472
+                        }
473
+                        $sortfunc .= '
474 474
 					$a = ' . sprintf($tv, '$aa') . ';
475 475
 					$b = ' . sprintf($tv, '$bb') . ';
476 476
 					if ($a <> $b)
477 477
 						return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;';
478
-					}
479
-				}
480
-			}
481
-		}
482
-
483
-		if ($sortfunc) {
484
-			$sortfunc .= "\n return 0;";
485
-			uasort($this->tableau, function($aa, $bb) use ($sortfunc) {
486
-				return eval($sortfunc);
487
-			});
488
-		}
489
-	}
490
-
491
-
492
-	/**
493
-	 * Grouper les resultats
494
-	 * {fusion /x/y/z}
495
-	 *
496
-	 **/
497
-	protected function select_groupby() {
498
-		// virer le / initial pour les criteres de la forme {fusion /xx}
499
-		if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) {
500
-			$vu = array();
501
-			foreach ($this->tableau as $k => $v) {
502
-				$val = table_valeur($v, $fusion);
503
-				if (isset($vu[$val])) {
504
-					unset($this->tableau[$k]);
505
-				} else {
506
-					$vu[$val] = true;
507
-				}
508
-			}
509
-		}
510
-	}
511
-
512
-
513
-	/**
514
-	 * L'iterateur est-il encore valide ?
515
-	 *
516
-	 * @return bool
517
-	 */
518
-	public function valid() {
519
-		return !is_null($this->cle);
520
-	}
521
-
522
-	/**
523
-	 * Retourner la valeur
524
-	 *
525
-	 * @return null
526
-	 */
527
-	public function current() {
528
-		return $this->valeur;
529
-	}
530
-
531
-	/**
532
-	 * Retourner la cle
533
-	 *
534
-	 * @return null
535
-	 */
536
-	public function key() {
537
-		return $this->cle;
538
-	}
539
-
540
-	/**
541
-	 * Passer a la valeur suivante
542
-	 *
543
-	 * @return void
544
-	 */
545
-	public function next() {
546
-		if ($this->valid()) {
547
-			$this->cle = key($this->tableau);
548
-			$this->valeur = current($this->tableau);
549
-			next($this->tableau);
550
-		}
551
-	}
552
-
553
-	/**
554
-	 * Compter le nombre total de resultats
555
-	 *
556
-	 * @return int
557
-	 */
558
-	public function count() {
559
-		if (is_null($this->total)) {
560
-			$this->total = count($this->tableau);
561
-		}
562
-
563
-		return $this->total;
564
-	}
478
+                    }
479
+                }
480
+            }
481
+        }
482
+
483
+        if ($sortfunc) {
484
+            $sortfunc .= "\n return 0;";
485
+            uasort($this->tableau, function($aa, $bb) use ($sortfunc) {
486
+                return eval($sortfunc);
487
+            });
488
+        }
489
+    }
490
+
491
+
492
+    /**
493
+     * Grouper les resultats
494
+     * {fusion /x/y/z}
495
+     *
496
+     **/
497
+    protected function select_groupby() {
498
+        // virer le / initial pour les criteres de la forme {fusion /xx}
499
+        if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) {
500
+            $vu = array();
501
+            foreach ($this->tableau as $k => $v) {
502
+                $val = table_valeur($v, $fusion);
503
+                if (isset($vu[$val])) {
504
+                    unset($this->tableau[$k]);
505
+                } else {
506
+                    $vu[$val] = true;
507
+                }
508
+            }
509
+        }
510
+    }
511
+
512
+
513
+    /**
514
+     * L'iterateur est-il encore valide ?
515
+     *
516
+     * @return bool
517
+     */
518
+    public function valid() {
519
+        return !is_null($this->cle);
520
+    }
521
+
522
+    /**
523
+     * Retourner la valeur
524
+     *
525
+     * @return null
526
+     */
527
+    public function current() {
528
+        return $this->valeur;
529
+    }
530
+
531
+    /**
532
+     * Retourner la cle
533
+     *
534
+     * @return null
535
+     */
536
+    public function key() {
537
+        return $this->cle;
538
+    }
539
+
540
+    /**
541
+     * Passer a la valeur suivante
542
+     *
543
+     * @return void
544
+     */
545
+    public function next() {
546
+        if ($this->valid()) {
547
+            $this->cle = key($this->tableau);
548
+            $this->valeur = current($this->tableau);
549
+            next($this->tableau);
550
+        }
551
+    }
552
+
553
+    /**
554
+     * Compter le nombre total de resultats
555
+     *
556
+     * @return int
557
+     */
558
+    public function count() {
559
+        if (is_null($this->total)) {
560
+            $this->total = count($this->tableau);
561
+        }
562
+
563
+        return $this->total;
564
+    }
565 565
 }
566 566
 
567 567
 /*
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
  * @return array
576 576
  */
577 577
 function inc_file_to_array_dist($data) {
578
-	return preg_split('/\r?\n/', $data);
578
+    return preg_split('/\r?\n/', $data);
579 579
 }
580 580
 
581 581
 /**
@@ -584,9 +584,9 @@  discard block
 block discarded – undo
584 584
  * @return array
585 585
  */
586 586
 function inc_plugins_to_array_dist() {
587
-	include_spip('inc/plugin');
587
+    include_spip('inc/plugin');
588 588
 
589
-	return liste_chemin_plugin_actifs();
589
+    return liste_chemin_plugin_actifs();
590 590
 }
591 591
 
592 592
 /**
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
  * @return array
597 597
  */
598 598
 function inc_xml_to_array_dist($data) {
599
-	return @XMLObjectToArray(new SimpleXmlIterator($data));
599
+    return @XMLObjectToArray(new SimpleXmlIterator($data));
600 600
 }
601 601
 
602 602
 /**
@@ -608,14 +608,14 @@  discard block
 block discarded – undo
608 608
  *
609 609
  */
610 610
 function inc_object_to_array($object) {
611
-	if (!is_object($object) && !is_array($object)) {
612
-		return $object;
613
-	}
614
-	if (is_object($object)) {
615
-		$object = get_object_vars($object);
616
-	}
617
-
618
-	return array_map('inc_object_to_array', $object);
611
+    if (!is_object($object) && !is_array($object)) {
612
+        return $object;
613
+    }
614
+    if (is_object($object)) {
615
+        $object = get_object_vars($object);
616
+    }
617
+
618
+    return array_map('inc_object_to_array', $object);
619 619
 }
620 620
 
621 621
 /**
@@ -625,20 +625,20 @@  discard block
 block discarded – undo
625 625
  * @return array|bool
626 626
  */
627 627
 function inc_sql_to_array_dist($data) {
628
-	# sortir le connecteur de $data
629
-	preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v);
630
-	$serveur = (string)$v[1];
631
-	$req = trim($v[2]);
632
-	if ($s = sql_query($req, $serveur)) {
633
-		$r = array();
634
-		while ($t = sql_fetch($s)) {
635
-			$r[] = $t;
636
-		}
637
-
638
-		return $r;
639
-	}
640
-
641
-	return false;
628
+    # sortir le connecteur de $data
629
+    preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v);
630
+    $serveur = (string)$v[1];
631
+    $req = trim($v[2]);
632
+    if ($s = sql_query($req, $serveur)) {
633
+        $r = array();
634
+        while ($t = sql_fetch($s)) {
635
+            $r[] = $t;
636
+        }
637
+
638
+        return $r;
639
+    }
640
+
641
+    return false;
642 642
 }
643 643
 
644 644
 /**
@@ -648,9 +648,9 @@  discard block
 block discarded – undo
648 648
  * @return array|bool
649 649
  */
650 650
 function inc_json_to_array_dist($data) {
651
-	if (is_array($json = json_decode($data, true))) {
652
-		return (array)$json;
653
-	}
651
+    if (is_array($json = json_decode($data, true))) {
652
+        return (array)$json;
653
+    }
654 654
 }
655 655
 
656 656
 /**
@@ -660,30 +660,30 @@  discard block
 block discarded – undo
660 660
  * @return array|bool
661 661
  */
662 662
 function inc_csv_to_array_dist($data) {
663
-	include_spip('inc/csv');
664
-	list($entete, $csv) = analyse_csv($data);
665
-	array_unshift($csv, $entete);
666
-
667
-	include_spip('inc/charsets');
668
-	$i = 1;
669
-	foreach ($entete as $k => $v) {
670
-		if (trim($v) == "") {
671
-			$v = "col" . $i;
672
-		} // reperer des eventuelles cases vides
673
-		if (is_numeric($v) and $v < 0) {
674
-			$v = "__" . $v;
675
-		} // ne pas risquer d'ecraser une cle numerique
676
-		if (is_numeric($v)) {
677
-			$v = "_" . $v;
678
-		} // ne pas risquer d'ecraser une cle numerique
679
-		$v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
680
-		foreach ($csv as &$item) {
681
-			$item[$v] = &$item[$k];
682
-		}
683
-		$i++;
684
-	}
685
-
686
-	return $csv;
663
+    include_spip('inc/csv');
664
+    list($entete, $csv) = analyse_csv($data);
665
+    array_unshift($csv, $entete);
666
+
667
+    include_spip('inc/charsets');
668
+    $i = 1;
669
+    foreach ($entete as $k => $v) {
670
+        if (trim($v) == "") {
671
+            $v = "col" . $i;
672
+        } // reperer des eventuelles cases vides
673
+        if (is_numeric($v) and $v < 0) {
674
+            $v = "__" . $v;
675
+        } // ne pas risquer d'ecraser une cle numerique
676
+        if (is_numeric($v)) {
677
+            $v = "_" . $v;
678
+        } // ne pas risquer d'ecraser une cle numerique
679
+        $v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
680
+        foreach ($csv as &$item) {
681
+            $item[$v] = &$item[$k];
682
+        }
683
+        $i++;
684
+    }
685
+
686
+    return $csv;
687 687
 }
688 688
 
689 689
 /**
@@ -693,12 +693,12 @@  discard block
 block discarded – undo
693 693
  * @return array|bool
694 694
  */
695 695
 function inc_rss_to_array_dist($data) {
696
-	include_spip('inc/syndic');
697
-	if (is_array($rss = analyser_backend($data))) {
698
-		$tableau = $rss;
699
-	}
696
+    include_spip('inc/syndic');
697
+    if (is_array($rss = analyser_backend($data))) {
698
+        $tableau = $rss;
699
+    }
700 700
 
701
-	return $tableau;
701
+    return $tableau;
702 702
 }
703 703
 
704 704
 /**
@@ -708,9 +708,9 @@  discard block
 block discarded – undo
708 708
  * @return array|bool
709 709
  */
710 710
 function inc_atom_to_array_dist($data) {
711
-	$rss_to_array = charger_fonction('rss_to_array', 'inc');
711
+    $rss_to_array = charger_fonction('rss_to_array', 'inc');
712 712
 
713
-	return $rss_to_array($data);
713
+    return $rss_to_array($data);
714 714
 }
715 715
 
716 716
 /**
@@ -721,11 +721,11 @@  discard block
 block discarded – undo
721 721
  * @return array|bool
722 722
  */
723 723
 function inc_glob_to_array_dist($data) {
724
-	$a = glob($data,
725
-		GLOB_MARK | GLOB_NOSORT | GLOB_BRACE
726
-	);
724
+    $a = glob($data,
725
+        GLOB_MARK | GLOB_NOSORT | GLOB_BRACE
726
+    );
727 727
 
728
-	return $a ? $a : array();
728
+    return $a ? $a : array();
729 729
 }
730 730
 
731 731
 /**
@@ -736,14 +736,14 @@  discard block
 block discarded – undo
736 736
  * @throws Exception
737 737
  */
738 738
 function inc_yaml_to_array_dist($data) {
739
-	include_spip('inc/yaml-mini');
740
-	if (!function_exists("yaml_decode")) {
741
-		throw new Exception('YAML: impossible de trouver la fonction yaml_decode');
739
+    include_spip('inc/yaml-mini');
740
+    if (!function_exists("yaml_decode")) {
741
+        throw new Exception('YAML: impossible de trouver la fonction yaml_decode');
742 742
 
743
-		return false;
744
-	}
743
+        return false;
744
+    }
745 745
 
746
-	return yaml_decode($data);
746
+    return yaml_decode($data);
747 747
 }
748 748
 
749 749
 
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
  * @return array|bool
759 759
  */
760 760
 function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) {
761
-	return (array)preg_files($dir, $regexp, $limit);
761
+    return (array)preg_files($dir, $regexp, $limit);
762 762
 }
763 763
 
764 764
 /**
@@ -770,23 +770,23 @@  discard block
 block discarded – undo
770 770
  * @return array|bool
771 771
  */
772 772
 function inc_ls_to_array_dist($data) {
773
-	$glob_to_array = charger_fonction('glob_to_array', 'inc');
774
-	$a = $glob_to_array($data);
775
-	foreach ($a as &$v) {
776
-		$b = (array)@stat($v);
777
-		foreach ($b as $k => $ignore) {
778
-			if (is_numeric($k)) {
779
-				unset($b[$k]);
780
-			}
781
-		}
782
-		$b['file'] = preg_replace('`/$`','',$v) ;
783
-		$v = array_merge(
784
-			pathinfo($v),
785
-			$b
786
-		);
787
-	}
788
-
789
-	return $a;
773
+    $glob_to_array = charger_fonction('glob_to_array', 'inc');
774
+    $a = $glob_to_array($data);
775
+    foreach ($a as &$v) {
776
+        $b = (array)@stat($v);
777
+        foreach ($b as $k => $ignore) {
778
+            if (is_numeric($k)) {
779
+                unset($b[$k]);
780
+            }
781
+        }
782
+        $b['file'] = preg_replace('`/$`','',$v) ;
783
+        $v = array_merge(
784
+            pathinfo($v),
785
+            $b
786
+        );
787
+    }
788
+
789
+    return $a;
790 790
 }
791 791
 
792 792
 /**
@@ -796,24 +796,24 @@  discard block
 block discarded – undo
796 796
  * @return array|bool
797 797
  */
798 798
 function XMLObjectToArray($object) {
799
-	$xml_array = array();
800
-	for ($object->rewind(); $object->valid(); $object->next()) {
801
-		if (array_key_exists($key = $object->key(), $xml_array)) {
802
-			$key .= '-' . uniqid();
803
-		}
804
-		$vars = get_object_vars($object->current());
805
-		if (isset($vars['@attributes'])) {
806
-			foreach ($vars['@attributes'] as $k => $v) {
807
-				$xml_array[$key][$k] = $v;
808
-			}
809
-		}
810
-		if ($object->hasChildren()) {
811
-			$xml_array[$key][] = XMLObjectToArray(
812
-				$object->current());
813
-		} else {
814
-			$xml_array[$key][] = strval($object->current());
815
-		}
816
-	}
817
-
818
-	return $xml_array;
799
+    $xml_array = array();
800
+    for ($object->rewind(); $object->valid(); $object->next()) {
801
+        if (array_key_exists($key = $object->key(), $xml_array)) {
802
+            $key .= '-' . uniqid();
803
+        }
804
+        $vars = get_object_vars($object->current());
805
+        if (isset($vars['@attributes'])) {
806
+            foreach ($vars['@attributes'] as $k => $v) {
807
+                $xml_array[$key][$k] = $v;
808
+            }
809
+        }
810
+        if ($object->hasChildren()) {
811
+            $xml_array[$key][] = XMLObjectToArray(
812
+                $object->current());
813
+        } else {
814
+            $xml_array[$key][] = strval($object->current());
815
+        }
816
+    }
817
+
818
+    return $xml_array;
819 819
 }
Please login to merge, or discard this patch.
prive/formulaires/configurer_relayeur.php 1 patch
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -11,141 +11,141 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 include_spip('inc/presentation');
17 17
 include_spip('inc/config');
18 18
 
19 19
 function formulaires_configurer_relayeur_charger_dist() {
20
-	$valeurs = array(
21
-		'http_proxy' => no_password_proxy_url(lire_config('http_proxy', '')),
22
-		'http_noproxy' => lire_config('http_noproxy', ''),
23
-		'test_proxy' => 'https://www.spip.net/',
24
-	);
20
+    $valeurs = array(
21
+        'http_proxy' => no_password_proxy_url(lire_config('http_proxy', '')),
22
+        'http_noproxy' => lire_config('http_noproxy', ''),
23
+        'test_proxy' => 'https://www.spip.net/',
24
+    );
25 25
 
26
-	return $valeurs;
26
+    return $valeurs;
27 27
 }
28 28
 
29 29
 function formulaires_configurer_relayeur_verifier_dist() {
30
-	$erreurs = array();
31
-	$http_proxy = relayeur_saisie_ou_config(_request('http_proxy'), lire_config('http_proxy', ''));
32
-	$http_noproxy = _request('http_noproxy');
33
-
34
-	if ($http_proxy and !tester_url_absolue($http_proxy)) {
35
-		$erreurs['http_proxy'] = _T('info_url_proxy_pas_conforme');
36
-	}
37
-
38
-	if (!isset($erreurs['http_proxy']) and _request('tester_proxy')) {
39
-		if (!$http_proxy) {
40
-			$erreurs['http_proxy'] = _T('info_obligatoire');
41
-		} else {
42
-			include_spip('inc/distant');
43
-			$test_proxy = _request('test_proxy');
44
-			$t = parse_url($test_proxy);
45
-			if (!@$t['host']) {
46
-				$erreurs['test_proxy'] = _T('info_adresse_non_indiquee');
47
-			} else {
48
-				include_spip('inc/texte'); // pour aide, couper, lang
49
-				$info = '';
50
-				if (!need_proxy($t['host'], $http_proxy, $http_noproxy)) {
51
-					$info = '<strong>' . _T('page_pas_proxy') . '</strong><br />';
52
-				}
53
-
54
-				// il faut fausser le proxy actuel pour faire le test !
55
-				$cur_http_proxy = $GLOBALS['meta']['http_proxy'];
56
-				$cur_http_noproxy = $GLOBALS['meta']['http_noproxy'];
57
-				$GLOBALS['meta']['http_proxy'] = $http_proxy;
58
-				$GLOBALS['meta']['http_noproxy'] = $http_noproxy;
59
-				$page = recuperer_url($test_proxy, ['transcoder' => true]);
60
-				$page = $page['page'] ?? '';
61
-				$GLOBALS['meta']['http_proxy'] = $cur_http_proxy;
62
-				$GLOBALS['meta']['http_noproxy'] = $cur_http_noproxy;
63
-				if ($page) {
64
-					$erreurs['message_ok'] = _T('info_proxy_ok') . "<br />$info\n<tt>" . couper(entites_html($page), 300) . '</tt>';
65
-					$erreurs['message_erreur'] = '';
66
-				} else {
67
-					$erreurs['message_erreur'] = $info . _T(
68
-						'info_impossible_lire_page',
69
-						array('test_proxy' => "<tt>$test_proxy</tt>")
70
-					)
71
-						. ' <b><tt>' . no_password_proxy_url($http_proxy) . '</tt></b>.'
72
-						. aider('confhttpproxy');
73
-				}
74
-			}
75
-		}
76
-	}
77
-
78
-	return $erreurs;
30
+    $erreurs = array();
31
+    $http_proxy = relayeur_saisie_ou_config(_request('http_proxy'), lire_config('http_proxy', ''));
32
+    $http_noproxy = _request('http_noproxy');
33
+
34
+    if ($http_proxy and !tester_url_absolue($http_proxy)) {
35
+        $erreurs['http_proxy'] = _T('info_url_proxy_pas_conforme');
36
+    }
37
+
38
+    if (!isset($erreurs['http_proxy']) and _request('tester_proxy')) {
39
+        if (!$http_proxy) {
40
+            $erreurs['http_proxy'] = _T('info_obligatoire');
41
+        } else {
42
+            include_spip('inc/distant');
43
+            $test_proxy = _request('test_proxy');
44
+            $t = parse_url($test_proxy);
45
+            if (!@$t['host']) {
46
+                $erreurs['test_proxy'] = _T('info_adresse_non_indiquee');
47
+            } else {
48
+                include_spip('inc/texte'); // pour aide, couper, lang
49
+                $info = '';
50
+                if (!need_proxy($t['host'], $http_proxy, $http_noproxy)) {
51
+                    $info = '<strong>' . _T('page_pas_proxy') . '</strong><br />';
52
+                }
53
+
54
+                // il faut fausser le proxy actuel pour faire le test !
55
+                $cur_http_proxy = $GLOBALS['meta']['http_proxy'];
56
+                $cur_http_noproxy = $GLOBALS['meta']['http_noproxy'];
57
+                $GLOBALS['meta']['http_proxy'] = $http_proxy;
58
+                $GLOBALS['meta']['http_noproxy'] = $http_noproxy;
59
+                $page = recuperer_url($test_proxy, ['transcoder' => true]);
60
+                $page = $page['page'] ?? '';
61
+                $GLOBALS['meta']['http_proxy'] = $cur_http_proxy;
62
+                $GLOBALS['meta']['http_noproxy'] = $cur_http_noproxy;
63
+                if ($page) {
64
+                    $erreurs['message_ok'] = _T('info_proxy_ok') . "<br />$info\n<tt>" . couper(entites_html($page), 300) . '</tt>';
65
+                    $erreurs['message_erreur'] = '';
66
+                } else {
67
+                    $erreurs['message_erreur'] = $info . _T(
68
+                        'info_impossible_lire_page',
69
+                        array('test_proxy' => "<tt>$test_proxy</tt>")
70
+                    )
71
+                        . ' <b><tt>' . no_password_proxy_url($http_proxy) . '</tt></b>.'
72
+                        . aider('confhttpproxy');
73
+                }
74
+            }
75
+        }
76
+    }
77
+
78
+    return $erreurs;
79 79
 }
80 80
 
81 81
 function formulaires_configurer_relayeur_traiter_dist() {
82
-	$res = array('editable' => true);
82
+    $res = array('editable' => true);
83 83
 
84
-	$http_proxy = relayeur_saisie_ou_config(_request('http_proxy'), lire_config('http_proxy', ''));
85
-	$http_noproxy = _request('http_noproxy');
86
-	if ($http_proxy !== null) {
87
-		ecrire_meta('http_proxy', $http_proxy);
88
-	}
84
+    $http_proxy = relayeur_saisie_ou_config(_request('http_proxy'), lire_config('http_proxy', ''));
85
+    $http_noproxy = _request('http_noproxy');
86
+    if ($http_proxy !== null) {
87
+        ecrire_meta('http_proxy', $http_proxy);
88
+    }
89 89
 
90
-	if ($http_noproxy !== null) {
91
-		ecrire_meta('http_noproxy', $http_noproxy);
92
-	}
90
+    if ($http_noproxy !== null) {
91
+        ecrire_meta('http_noproxy', $http_noproxy);
92
+    }
93 93
 
94
-	$res['message_ok'] = _T('config_info_enregistree');
94
+    $res['message_ok'] = _T('config_info_enregistree');
95 95
 
96
-	return $res;
96
+    return $res;
97 97
 }
98 98
 
99 99
 function relayeur_saisie_ou_config($http_proxy, $default) {
100
-	// http_proxy : ne pas prendre en compte la modif si le password est '****'
101
-	if (preg_match(',:\*\*\*\*@,', $http_proxy)) {
102
-		$http_proxy = $default;
103
-	}
100
+    // http_proxy : ne pas prendre en compte la modif si le password est '****'
101
+    if (preg_match(',:\*\*\*\*@,', $http_proxy)) {
102
+        $http_proxy = $default;
103
+    }
104 104
 
105
-	return $http_proxy;
105
+    return $http_proxy;
106 106
 }
107 107
 
108 108
 // Function glue_url : le pendant de parse_url
109 109
 // https://code.spip.net/@glue_url
110 110
 function glue_url($url) {
111
-	if (!is_array($url)) {
112
-		return false;
113
-	}
114
-	// scheme
115
-	$uri = (!empty($url['scheme'])) ? $url['scheme'] . '://' : '';
116
-	// user & pass
117
-	if (!empty($url['user'])) {
118
-		$uri .= $url['user'] . ':' . $url['pass'] . '@';
119
-	}
120
-	// host
121
-	$uri .= $url['host'];
122
-	// port
123
-	$port = (!empty($url['port'])) ? ':' . $url['port'] : '';
124
-	$uri .= $port;
125
-	// path
126
-	$uri .= $url['path'];
111
+    if (!is_array($url)) {
112
+        return false;
113
+    }
114
+    // scheme
115
+    $uri = (!empty($url['scheme'])) ? $url['scheme'] . '://' : '';
116
+    // user & pass
117
+    if (!empty($url['user'])) {
118
+        $uri .= $url['user'] . ':' . $url['pass'] . '@';
119
+    }
120
+    // host
121
+    $uri .= $url['host'];
122
+    // port
123
+    $port = (!empty($url['port'])) ? ':' . $url['port'] : '';
124
+    $uri .= $port;
125
+    // path
126
+    $uri .= $url['path'];
127 127
 // fragment or query
128
-	if (isset($url['fragment'])) {
129
-		$uri .= '#' . $url['fragment'];
130
-	} elseif (isset($url['query'])) {
131
-		$uri .= '?' . $url['query'];
132
-	}
128
+    if (isset($url['fragment'])) {
129
+        $uri .= '#' . $url['fragment'];
130
+    } elseif (isset($url['query'])) {
131
+        $uri .= '?' . $url['query'];
132
+    }
133 133
 
134
-	return $uri;
134
+    return $uri;
135 135
 }
136 136
 
137 137
 
138 138
 // Ne pas afficher la partie 'password' du proxy
139 139
 // https://code.spip.net/@no_password_proxy_url
140 140
 function no_password_proxy_url($http_proxy) {
141
-	if ($http_proxy
142
-		and $p = @parse_url($http_proxy)
143
-		and isset($p['pass'])
144
-		and $p['pass']
145
-	) {
146
-		$p['pass'] = '****';
147
-		$http_proxy = glue_url($p);
148
-	}
149
-
150
-	return $http_proxy;
141
+    if ($http_proxy
142
+        and $p = @parse_url($http_proxy)
143
+        and isset($p['pass'])
144
+        and $p['pass']
145
+    ) {
146
+        $p['pass'] = '****';
147
+        $http_proxy = glue_url($p);
148
+    }
149
+
150
+    return $http_proxy;
151 151
 }
Please login to merge, or discard this patch.